akhauriyash/Code-Regression huggingface dataset:
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define FOR(i,a,n) for(ll i=a;i<(ll)(n);i++)

#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define FOR(i,a,n) for(ll i=a;i<(ll)(n);i++)

int main(){
   int N; cin>>N;
   vector<int> count(4, 0);

   rep(i, N){
       string s; cin>>s;
       if(s == "AC") count[0]++;
       if(s == "WA") count[1]++;
       if(s == "TLE") count[2]++;
       if(s == "RE") count[3]++;
   }

   rep(i, 4){
       if(i == 0) cout << "AC x " << count[0] << endl;
       if(i == 1) cout << "WA x " << count[1] << endl;
       if(i == 2) cout << "TLE x " << count[2] << endl;
       if(i == 3) cout << "RE x " << count[3] << endl;
   }
}


Measured memory_bytes: 3628
#include <iostream>
#include <stack>
#include <string>

using namespace std;

int main(){
  string s;
  cin >> s;
  int n,ret=0;
  n = (int)s.size();
  stack<char> st;
  for(int i=0;i<n;i++){
    if(st.empty())st.push(s[i]);
    else{
      if(st.top()!=s[i]){
        ret+=2;
        st.pop();
      }else st.push(s[i]);
    }
  }
  cout << ret << endl;
  return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
#define x first
#define y second
#define mp make_pair
#define all(a) a.begin(), a.end()
#define pub push_back
#define ll long long
					  
using namespace std;

int n;
int a[111];
bool prime[10000007];
vector<int> g[222];
int dx[222], dy[222];

bool wasIn(int x){
	for (int i = 0; i < n; i++) if (a[i] == x) return 1;
	return 0;
}

bool check(int x){
	return wasIn(x) != wasIn(x + 1);
}

bool was[222];
bool dfs(int v){
	if (was[v]) return 0;
	was[v] = 1;
	for (int to : g[v]){
		if (dy[to] == -1){
			dx[v] = to;
			dy[to] = v;
			return 1;
		}
		if (dfs(dy[to])){
			dx[v] = to;
			dy[to] = v;
			return 1;
		}
	}
	return 0; 
}

int main(){
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	//freopen("seating.in", "r", stdin);
	//freopen("seating.out", "w", stdout);
	for (int i = 2; i < 10000007; i++){
		if (!prime[i]){	
			for (int j = 2 * i; j < 10000007; j += i) prime[j] = 1;
		}
	}

	prime[2] = 1;
	prime[1] = 1;
	prime[0] = 1;

	cin >> n;
	for (int i = 0; i < n; i++) cin >> a[i];

	vector<int> q, s, t;
	for (int i = 0; i < n; i++){
		if (check(a[i] - 1)) q.pub(a[i] - 1);
		if (check(a[i])) q.pub(a[i]);
	}

	for (int x : q) if (x % 2 == 0) s.pub(x); else t.pub(x);

	for (int i = 0; i < s.size(); i++) for (int j = 0; j < t.size(); j++) if (!prime[abs(s[i] - t[j])]){
		g[i].pub(j);
	}	

	for (int i = 0; i < 222; i++) dx[i] = -1, dy[i] = -1;

	for (int run = 1; run; ){
		run = 0;
		memset(was, 0, sizeof(was));
		for (int i = 0; i < s.size(); i++) if (dx[i] == -1 && dfs(i)) run = 1;
	}

	int dd = 0;

	for (int i = 0; i < s.size(); i++) if (dx[i] != -1) dd++;

	int ans = (int)s.size() + (int)t.size() - dd;

	if (((int)s.size() - dd) % 2 == 1) ans++;

	cout << ans;
}

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

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

ll X,Y;

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>X>>Y;
	if(X%Y==0) return _P("-1\n");
	for(ll a=X;a<=1000000000000000000LL;a+=X) {
		if(X%Y) {
			cout<<X<<endl;
			return;
		}
	}
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}


Measured memory_bytes: 256
n, k = [int(x) for x in input().split()]
V = [int(x) for x in input().split()]

ANS=[]
c = 0
for i in range(min(n, k) + 1):
    for j in range(min(n, k) - i + 1):
        c += 1
        ans1 = V[:i]
        if j == 0:
            ans2 = []
        else:
            ans2 = V[-j:]
        A = ans1 + ans2
        A.sort()
        for l in range(k-(i+j)):
            if A != [] and A[0] < 0:
                A = A[1:]
        ANS.append(sum(A))

print(max(ANS))


Measured memory_bytes: 3064
#include <iostream>
#include <iomanip>
#include <string>
#include <map>
#include <math.h>
using namespace std;

#define ll long long

int main(){
    int X;
    cin >> X;
    if(X == 3 || X == 5 || X == 7)cout << "YES" << endl;
    else cout << "NO" << endl;
    return 0;
}

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

int main() {
  ll N, M, X;
  cin >> N >> M >> X;
  vector<ll> C(N);
  vector<vector<ll>> A(N, vector<ll>(M));
  for (int i = 0; i < N; ++i) {
    cin >> C.at(i);
    for (int j = 0; j < M; ++j) {
      cin >> A.at(i).at(j);
    }
  }
  ll result = 1000000000;
  for (int bit = 0; bit < (1<<N); ++bit) {
        // bit の表す集合を求める
        vector<int> S;
        for (int i = 0; i < N; ++i) {
            if (bit & (1<<i)) { // i が bit に入るかどうか
                S.push_back(i);
            }
        }
    	vector<ll> sums(M, 0);
		ll sum = 0;
        for (int i = 0; i < (int)S.size(); ++i) {
          int si = S.at(i);
          sum += C.at(si);
          for (int j = 0; j < M; ++j) {
            sums.at(j) += A.at(si).at(j);
          }
          ll min_v = *min_element(sums.begin(), sums.end());
          if (min_v >= X) {
            result = min(result, sum);
          }
        }
  }
  if (result == 1000000000) {
    cout << "-1" << endl;
  } else {
    cout << result << endl;
  }
  return 0;
}

Measured memory_bytes: 3584
// 2020-06-05 18:03
#include <bits/stdc++.h>
using namespace std;

typedef pair<int, int> pii;

int main() {
    int N, M;
    cin >> N >> M;
    vector<vector<int>> G(N);
    for (int i = 0; i < M; ++i) {
        int A, B;
        cin >> A >> B;
        --A, --B;
        G[A].push_back(B);
        G[B].push_back(A);
    }

    vector<int> fa(N, -1);
    priority_queue<pii, vector<pii>, greater<pii>> que;
    que.emplace(0, 0);
    while (!que.empty()) {
        auto P = que.top();
        que.pop();
        if (fa[P.second] != -1) continue;
        fa[P.second] = P.first;
        for (int to : G[P.second]) {
            if (fa[to] == -1) {
                que.emplace(P.first + 1, to);
            }
        }
    }

    vector<int> ans(N, -1);
    for (int i = 1; i < N; ++i) {
        for (int to : G[i]) {
            if (fa[to] < fa[i]) {
                ans[i] = to + 1;
            }
        }
    }
    cout << "Yes" << endl;
    for (int i = 1; i < N; ++i) {
        cout << ans[i] << endl;
    }
    return 0;
}

Measured memory_bytes: 11080
#include <bits/stdc++.h>
using namespace std;
#define repr(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define reprrev(i,a,b) for(int i=b-1;i>=a;i--) // [a, b)
#define reprev(i,n) reprrev(i,0,n)
typedef long long ll;
typedef unsigned long long ull;
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; }

/* attention
    long longのシフト演算には気をつけよう
    タイポした時のデバッグが死ぬほどきつくなるので変数名は最低3字くらい使った方がいいかも
    sizeは(int)とキャストしよう
    ごちゃごちゃ場合分けを考える前に全探索は考えましたか？
    詰まった時に、別の分野の問題として考え直す（これdpでは？、グラフとしてみればいいのでは？）
    多くの問題はパターンマッチだが、パターンに落とし込むまでが難しく、そのための訓練としてわからない問題をあれこれ色々な角度から考察してみるのではないか
    cin.tie(0);
    ios::sync_with_stdio(false);<- これら、printfとかと併用しない方が良さそう

*/

const ll mod = 1e9+7;

void chmod(ll &M){
    if(M >= mod) M %= mod;
    else if(M < 0){
        M += (abs(M)/mod + 1)*mod;
        M %= mod;
    }
}

int getl(int i, int N) { return i==0? N-1:i-1; };
int getr(int i, int N) { return i==N-1? 0:i+1; };

/* <--------------------------------------------> */


const ll inf = 1LL<<60;
const int MAX_V = 5050;

struct Edge{ll from, to, cost; };

int V; // 頂点の数
int E; // 辺の数
vector<ll> d(MAX_V, inf); // 距離
vector<bool> negative(MAX_V, false); // 負の閉路検出
vector<Edge> edge;

void Bellman_Ford(){
    d[0] = 0; // 始点の初期化
    for(int loop=0; loop<V-1; ++loop){
        for(int i=0; i<E; ++i){
            if(d[edge[i].from] == inf) continue;

            if(d[edge[i].to] > d[edge[i].from]+edge[i].cost){
                d[edge[i].to] = d[edge[i].from]+edge[i].cost;
            }
        }
    }

    for(int loop=0; loop<2*V; ++loop){
        for(int i=0; i<E; ++i){
            if(d[edge[i].from] == inf) continue;

            if(d[edge[i].to] > d[edge[i].from]+edge[i].cost){
                d[edge[i].to] = d[edge[i].from]+edge[i].cost;
                negative[edge[i].to] = true;
            }

            if(negative[edge[i].from]) negative[edge[i].to] = true;
            
        }
    }
}


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

    cin >> V >> E;
    rep(i, E){
        ll a, b, c; cin >> a >> b >> c;
        --a; --b;
        Edge e;
        e.from=a; e.to=b; e.cost=-c;
        edge.push_back(e);
    }
    //for(auto e:edge) cout << e.from << e.to << e.cost << endl;

    Bellman_Ford();
    if(negative[V-1]){
        cout << "inf\n";
    }
    else{
        cout << -d[V-1] << '\n';
    }
    //rep(i, V) cout << d[i] << endl;

    return 0;
}


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

const int maxw = 100005;
typedef long long ll;
ll costo[maxw];
bool dp[maxw];

struct obj{
    int w;
    ll v;
    obj( int _w, ll _v ){
        w = _w, v = _v;
    }
};

int main()
{
    cin.tie(0);
    ios_base::sync_with_stdio(0);
    #ifdef acm
    freopen("a.in","r",stdin);
    #endif // acm

    int N, W;
    cin >> N >> W;

    int w, m;
    ll v;
    vector<obj>O;
    for( int i = 1; i <= N; i++ ){
        cin >> v >> w >> m;
        int p2 = 1;
        do{
            O.push_back( obj( w*p2, v*p2 ) );
            m -= p2;
            p2 *= 2;
        }while( p2 <= m );
        if( m ){
            O.push_back( obj( w*m, v*m ) );
        }
    }

    dp[0] = 1;
    ll sol = 0;
    for( int i = 0; i < (int)O.size(); i++ ){
        obj o = O[i];
        for( int j = W; j >= o.w; j-- ){
            if( dp[j-o.w] ){
                dp[j] = 1;
                if( costo[j-o.w] + o.v > costo[j] ){
                    costo[j] = costo[j-o.w] + o.v;
                    sol = max(sol, costo[j]);
                }
            }
        }
    }

    cout << sol << '\n';
    return 0;
}



Measured memory_bytes: 3376
#include<iostream>
#include<algorithm>
#define LL long long
int G, M;
int N, K;
int gcd(int a, int b) { return (a%b) ? gcd(b, a%b) : b; }
int main() {
	std::cin >> N >> K;
	std::cin >> G;
	M = G;
	for (int i = 1; i < N; i++) {
		int tmp;
		std::cin >> tmp;
		M = std::max(tmp, M);
		G = gcd(std::max(G, tmp),std::min(G,tmp));
	}
	std::cout << ((M >= K && !(K%G)) ? "POSSIBLE" : "IMPOSSIBLE") << std::endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(ri,n) for(int ri = (int)(n-1); ri >= 0; ri--)
#define rep2(i,x,n) for(int i = (int)(x); i < (int)(n); i++)
#define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++)
#define rrepit(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++)
#define ALL(n) begin(n), end(n)
using ll = long long;
using namespace std;

int main(){
	int n, m;
	cin >> n >> m;
	vector<int> a(n);
	ll sum = 0;
	rep(i, n){
		int in;
		cin >> in;
		a.at(i) = in;
	}
	sort(a.begin(), a.end());
	vector<pair<int, int>> q(m);
	rep(i, m){
		int b, c;
		cin >> b >> c;
		q.at(i) = make_pair(c, b);
	}
	sort(q.begin(), q.end(), greater<pair<int,int>>());
	int index = 0;
	bool end = false;
	for(auto p : q){
		rep(j, p.second){
			if(index < n && a.at(index) < p.first){
				a.at(index) = p.first;
				index++;
			}else{
				end = true;
				break;
			}
		}
		if(end == true) break;
	}
	rep(i, n){
		sum += a.at(i);
	}
	cout << sum << endl;
	
	return 0;
}

Measured memory_bytes: 1408
#include "bits/stdc++.h"
using namespace std;
//template <typename... T> void read(T& ... t){ ((cin >> t), ...); }
//template <typename... T> void write(T ... t){ ((cout << t), ...); }
//#define int long long
#define FAST ios::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define size(x) (int)x.size()
#define all(x) x.begin(),x.end()
#define ln '\n'
using LL = long long;
using pii = pair<int,int>;
const int INF = 2e9;
const int MAXN = 2e5 +3;
LL h;
LL answer(LL x){
	if(x == 1) return 1;
	return 2*answer(x/2) + 1;
}
int32_t main(){ FAST;
	cin >> h;
	cout << answer(h) << ln;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define IFOR(i,a,b) for(int i=(b-1);i>=(a);--i)
#define RPT(i,a,b) for(int i=(a);i<((a)+(b));++i)
#define IRPT(i,a,b) for(int i=((a)+(b)-1);i>=(a);--i)
#define BITBOOL(x,a) (((x)>>(a))&1)
int main(){
  int N; string S;
  cin >> N >> S;
  for(auto &x : S){
    x = 'A'+(x-'A'+N)%26;
  }
  cout << S << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <cstring>
#include <iomanip>
#include <numeric>
#include <cmath>
#include <cassert>
#include <map>
#include <set>
using namespace std;
using ll = long long;
const int INF = 1<<30;
const int MOD = (int)1e9 + 7;
const int MAX_N = (int)1e5 + 5;
#define debug(x) cout << #x << ": " << x << endl
template<typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2>& p) { os << p.first << " " << p.second; return os; }
template<typename T>
ostream &operator<<(ostream &os, const vector<T> &v) { for(int i = 0; i < (int) v.size(); i++) os << v[i] << (i + 1 != v.size() ? " " : ""); return os; }

set<char> st[5];
bool check(const string& s)
{
    string res = "";
    for(int i = 0; i < s.size(); i++)
    {
        if(st[i + 1].size() == 0) continue;
        if(st[i + 1].count(s[i]) == 0) return false;
    }
    return true;
}

void solve()
{
    int n, m; cin >> n >> m;
    for(int i = 0; i < m; i++)
    {
        int s;
        char c;
        cin >> s >> c;
        st[s].insert(c);
    }
    for(int i = 0; i < 5; i++)
    {
        if(st[i].size() >= 2)
        {
            cout << -1 << endl;
            return;
        }
    }
    for(int i = 0; i <= 999; i++)
    {
        string t = to_string(i);
        if((int)t.size() != n) continue;
        bool ok = true;
        if(check(t))
        {
            cout << t << endl;
            return;
        }
    }
    cout << -1 << endl;
}

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

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define ALL(c) (c).begin(),(c).end()
using namespace std;
using ll = long long;
using P = pair<int,int>;
#define chmax(x,y) x = max(x,y)
#define chmin(x,y) x = min(x,y)

const int INF = 1e9 + 10;

int N;
ll res = 0;

int main() {
    cin >> N;
    for (int i = 1; i <= N; ++i) {
        if (i%3!=0 && i%5!=0) res += i;
    }
    cout << res << endl;
}


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

vector<string> split(const string &str, char sep)
{
    std::vector<std::string> v;
    std::stringstream ss(str);
    std::string buffer;
    while( std::getline(ss, buffer, sep) ) {
        v.push_back(buffer);
    }
    return v;
}

//counter[a+center][b+center] = #{2^a 5^b ... }
//求めるのは \sum { counter[a][b] * counter[c][d] | a + c >= 18, b + d >= 18 }
constexpr size_t csize = 40;
ll counter[csize][csize] = {};
ll counter_cumsum[csize][csize] = {};
constexpr ll INTEGER = 1000000000LL;

int main()
{
    int n;
    cin >> n;
    ll num_integer = 0;
    for(int i=0; i<n; ++i){
        string s;
        cin >> s;
        auto vs = split(s, '.');
        if (vs.size() == 1){
            // 整数
            vs.push_back("000000000");
        }else{
            // 小数
            string s1 = "";
            for (const auto &si: vs[1]){
                s1.push_back(si);
            }
            for(int i=0; i<9-vs[1].size(); ++i)s1.push_back('0');
            vs[1] = s1;
        }
        if (stoll(vs[1]) == 0){
            num_integer++;
        }
        const ll a = stoll(vs[0]) * INTEGER + stoll(vs[1]);
        
        size_t mul2 = 0;
        ll a_tmp = a;
        while(a_tmp % 2 == 0){
            a_tmp /= 2;
            mul2++;
        }
        size_t mul5 = 0;
        a_tmp = a;
        while(a_tmp % 5 == 0){
            a_tmp /= 5;
            mul5++;
        }

        counter[mul2][mul5]++;
    }

    for(int a=csize-2; a>=0; --a){
        for(int b=csize-2; b>=0; --b){
            counter_cumsum[a][b] = counter[a][b] + counter_cumsum[a][b+1] + counter_cumsum[a+1][b] - counter_cumsum[a+1][b+1];
        }
    }

    ll ans = 0;
    for(int a=0; a<csize; ++a){
        for(int b=0; b<csize; ++b){
            ans += counter[a][b] * counter_cumsum[max(0, 18-a)][max(0, 18-b)];
        }
    }

    cout << (ans-num_integer) / 2;

    return 0;
}


Measured memory_bytes: 3664
using System;
using System.Linq;
using System.Collections.Generic;


class Program
{
    static void Main(string[] args)
    {
        string S = Console.ReadLine();

        if(S=="hi" || S=="hihi" || S=="hihihi" || S=="hihihihi" || S=="hihihihihi"){
            Console.WriteLine("Yes");
        }else{
            Console.WriteLine("No");
        }
    }
}

Measured memory_bytes: 11092
#ifdef _MSC_VER
#include <__msvc_all_public_headers.hpp>
#undef min
#undef max
#else
#define NDEBUG
#include <bits/stdc++.h>
#endif

using namespace std;
using large = long long;

struct UnionFind {
    vector<int> data;

    UnionFind(int size) : data(size, -1) {}
    void unite(int x, int y) {
        auto rx = root(x);
        auto ry = root(y);
        if (rx == ry)
            return;

        auto x_size = -data[rx];
        auto y_size = -data[ry];
        if (x_size > y_size) {
            data[rx] = ry;
            data[ry] = -(x_size + y_size);
        } else {
            data[ry] = rx;
            data[rx] = -(x_size + y_size);
        }
    }

    int root(int x) {
        if (data[x] < 0)
            return x;
        data[x] = root(data[x]);
        return data[x];
    }
};

int main() {
    int n, m; // 100'000;
    cin >> n >> m;

    auto uf = UnionFind(n);
    for (auto i = 0; i < m; ++i) {
        int x, y, z;
        cin >> x >> y >> z;
        --x, --y;
        uf.unite(x, y);
    }

    auto group_count = 0;
    auto remains = n;
    for (auto i = 0; i < n; ++i) {
        if (uf.root(i) == i) {
            group_count++;
            remains -= -(uf.data[i]);
        }
    }

    cout << group_count + remains << endl;
    return 0;
}


Measured memory_bytes: 4832
#include <bits/stdc++.h>
using namespace std;
#define ALL(a) (a).begin(), (a).end()
#define FOR(i, s, n) for (int i = (s); i < (n); i++)
#define rep(i, n) FOR(i, 0, n)
#define repi(i, n) FOR(i, 1, n + 1)
#define pp(v) cout << #v "=" << (v) << endl;
#define ppa(v) cout << "----\n"; rep(i,v.size()) cout << #v << "[" << i << "] = " << v[i] << endl;
#define div_ceil(a,b) ((a) + ((b) - 1)) / (b)

int main() {
  string s;cin>>s;
  int ans = 0;
  rep(i,4) if (s[i]=='+') {
    ans++;
  } else {
    ans--;
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
import numpy

N, M, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

acc_a = [0]
for i in range(N):
    acc_a.append(acc_a[i] + A[i])

acc_b = [0]
for i in range(M):
    acc_b.append(acc_b[i] + B[i])

acc_a = numpy.array(acc_a)
acc_b = numpy.array(acc_b)

currentMax = 0
bnum = M
for anum in range(N + 1):
    if acc_a[anum] > K:
        break

    while True:
        if acc_b[bnum] > K - acc_a[anum]:
            bnum = bnum - 1 
        else:
            break

    currentMax = max(currentMax, anum + bnum)


print(currentMax)

Measured memory_bytes: 66612
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
sum=0


for i in range(0, n):
	if (a[i] >= b[i]): sum += b[i]
	else:
		if(a[i+1] >= b[i]-a[i]):
			sum += b[i]
			a[i+1] = a[i+1] - (b[i]-a[i])
		else:
			sum += a[i]+a[i+1]
			a[i+1] = 0

print(sum)


Measured memory_bytes: 18624
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		long p = 1;
		for(int i = 1; i <= n; i++) {
			p = (p * i)%1000000007;
		}
		System.out.println(p);
	}
}

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

using ll = long long;
#define FOR(i, m, n) for (int i = (m); i < (n); i++)
#define REP(i, n) FOR(i, 0, n)
#define ALL(c) (c).begin(), (c).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;}
const int MOD = 1000000007;

int main() {
    int n;
    cin >> n;
    vector<int> a(n);
    int t = 0;
    REP(i, n) {
        cin >> a[i];
        t += a[i];
    }
    double ave = (double)t / n;
    double d = 100100.0;
    int r = -1;
    REP(i, n) {
        if (d > abs(ave - a[i])) {
            d = abs(ave - a[i]);
            r = i;
        }
    }

    cout << r << endl;
}


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

using namespace std;
#define all(a)a.begin(),a.end()
using ll=long long;
const int INF = 1<<30;
const ll INFll =1LL<<62;
const int mod =(1e9)+7;
using P = pair<ll,ll>;

int main(){
   ll n,k;cin >>n>>k;
    vector<ll>h(n);
    for (int i = 0; i < n; ++i) {
        cin >>h[i];
    }
    sort(all(h));
    reverse(all(h));
    ll ans=0;
    for (int i = 0; i < n; ++i) {
        if(i<k)continue;
        ans+=h[i];
    }
    cout <<ans <<endl;
    return 0;
}



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

//隣接リストの書き方
typedef long long ll;
typedef pair<int, int> P;

const int INF = 1000000007;
const ll INF2 = 1000000000000000;

vector<P> G[100010];
ll cost[100010];

void dfs(int V, ll c) {
	cost[V] = c;
	for(int i=0;i<G[V].size();i++){
		if(cost[G[V][i].first] == INF2){
			dfs(G[V][i].first, c + G[V][i].second);
		}
	}
}

int main(void){
	
	int n; cin>>n;
	for(int i=0;i<n-1;i++){
		int a,b,c;
		cin>>a>>b>>c;
		G[a].push_back({b, c}); //c++11以降でコンパイル可能 G[a].push_back(make_pair(b,c));
		G[b].push_back({a, c});
	}

	int q,k;
	cin>>q>>k;

	for(int i=0;i<100010;i++) cost[i] = INF2;

	dfs(k, 0);
	for(int i=0;i<q;i++) {
		int x,y;
		cin>>x>>y;
		cout<<cost[x]+cost[y]<<endl;
	}

	return 0;
}

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

using namespace std;

#define forn(i, x, n) for (int i = int(x); i <= int(n); ++i)
#define for1(i, n, x) for (int i = int(n); i >= int(x); --i)
#define F first
#define S second
#define pb push_back

typedef long long ll;
typedef pair <int, int> pii;
typedef long double ld;
typedef vector <ll> vi;

const int N = 2e6 + 1;
const ll INF = 1e18 + 9;
const int B = 1e9 + 7;

int n, m;
vi g[N];
int shit, cnt;
int u[N], c[N];

void dfs(int x) {
    u[x] = 1;
    ++cnt;
    for (auto to : g[x]) {
        if (u[to] && c[to] == c[x]) shit = 1;
        if (!u[to]) {
            c[to] = c[x] ^ 1;
            dfs(to);
        }
    }
}

int main() {
    #ifdef black
    freopen("in", "r", stdin);
    #endif // black
    ios_base :: sync_with_stdio(0);
    cin.tie(0);

    cin >> n >> m;
    forn(i, 1, m) {
        int f, t;
        cin >> f >> t;
        g[f].pb(t);
        g[t].pb(f);
    }

    ll a = 0, b = 0, c = 0;
    forn(i, 1, n) {
        if (u[i]) continue;
        if (g[i].size() == 0) {
            ++c;
            continue;
        }
        shit = 0;
        dfs(i);
        if (!shit) ++a;
        else ++b;
    }
    cout << 2 * a * a + 2 * a * b + b * b + (2 * c * n - c * c) << "\n";

    return 0;
}


Measured memory_bytes: 61056
#include<bits/stdc++.h>
using namespace std;
 
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif
 
#define fi first
#define se second
#define FIO {ios::sync_with_stdio(0);cin.tie(nullptr);cout.tie(nullptr);}
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ford(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
 
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpi;
typedef vector<vi> vvi;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef long double ld;

int main(){
    FIO
    int n,m;
    cin>>n>>m;
    int a[n+1],s,t,fl=0;
    memset(a,-1,sizeof(a));
    for(int i=0;i<m;i++)
    {
        cin>>s>>t;
        if(a[s]==-1)a[s]=t;
        else if(a[s]!=t) {fl=1;}
    }
            if(fl==1){cout<<-1;return 0;}
    if(n==1)
        {
            if(a[1]==-1){cout<<0;return 0;}
            else {cout<<a[1];return 0;}
        }
        if(a[1]==0){cout<<-1;return 0;}
        if(a[1]==-1)a[1]=1;
        string str=to_string(a[1]);
        for(int i=2;i<=n;i++)
        {
           // cout<<i<<a[i];
            if(a[i] == -1)str+= '0';
        else  str+= a[i] + '0';
        }
        cout<<str;
        }


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define FORD(i,a,b) for(int i=a;i>=b;i--)
#define FORL(i,x) for(int i=head[x];i;i=nxt[i])
#define ALL(a)  (a).begin(),(a).end()
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define PB push_back
#define MP make_pair
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 a,b,c,d;
    cin >> a >> b >> c >> d;

    if(a!=c) cout << 1 << endl;
    else cout << 0 << endl;
}



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

namespace _018_SortingFiveNumbers
{
	class Program
	{
		static void Main ( string[] args )
		{
			int[] inputArray = Console.ReadLine ().Split (' ').Select (str => int.Parse (str)).ToArray ();

			Array.Sort (inputArray, ( item, item2 ) => item2 - item);

			Console.WriteLine (inputArray[0] + " " + inputArray[1] + " " + inputArray[2] + " " + inputArray[3] + " " + inputArray[4]);
		}
	}
}

Measured memory_bytes: 9516
N = input()
if N[-1] == '2' or N[-1] == '4' or N[-1] == '5' or N[-1] == '7' or N[-1] == '9':
    print('hon')
elif N[-1] == '0' or N[-1] == '1' or N[-1] == '6' or N[-1] == '8':
    print('pon')
else:
    print('bon')


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

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

  int n;cin>>n;
  vector<int> tr(n);
  vector<int> fa(n);
  for(int i=0;i<n;i++){
    int a;cin>>a;
    int t1=0, t2=0;
    for(int j=0;j<a;j++){
      int x, y;cin>>x>>y;x--;
      if(y) t1= (t1 | (1 << x));
      else  t2 = (t2 | (1 << x));
    }
    tr[i] = t1;
    fa[i] = t2;
  }
  int res=0;
  for(int i=0;i<(1<<n);i++){
    if(res >= __builtin_popcount(i)){
      continue;
    }
    bool ok = true;
    for(int j = 0;j < n;j++){
      if(i & (1<<j)){
        if ((i | tr[j]) != i)ok=false;
        if((i & fa[j])>0)ok=false;
      }
    }
    if(ok){
      res = __builtin_popcount(i);
    }
  }

  cout<<res<<endl;

  return 0;
}


Measured memory_bytes: 256
n,t=map(int,raw_input().split())
a=map(int,raw_input().split())
pos={}
mx=[0]*(n+1)
for i in xrange(n-1,-1,-1):
    mx[i]=max(mx[i+1],a[i])
for i in xrange(n):
    pos[a[i]]=i
a.sort()
ans=0
b=0
for i in xrange(n):
    idx=pos[a[i]]
    if b<mx[idx]-a[i]:
        b=mx[idx]-a[i]
        ans=1
    elif b==mx[idx]-a[i]:
        ans+=1
print ans


Measured memory_bytes: 17972
#pragma GCC optimize("Ofast")
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <iomanip> // setprecision
#include <complex> // complex
#include <functional>
#include <math.h> 
#define enld '\n'
using namespace std;
using ll = long long;
using P = pair<int,int>;
constexpr ll INF = 1e18;
constexpr int inf = 1e9;
// constexpr ll mod = 1000000007;
constexpr ll mod2 = 998244353;
const int dx[8] = {1, 0, -1, 0,1,1,-1,-1};
const int dy[8] = {0, 1, 0, -1,1,-1,1,-1};
template<class T> 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(){
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int N;
  cin >> N;
  int A=0,B=0,AB=0;
  int cnt = 0;
  for(int i=0; i<N; i++){
    string S;
    cin >> S;
    if(S[0]=='B' && S.back()=='A'){
      AB++;
    }else if(S[0] == 'B'){
      B++;
    }else if(S.back() == 'A'){
      A++;
    }
    for(int j=1; j<S.size(); j++){
      if(S.substr(j-1,2) == "AB"){
        cnt++;
      }
    }
  }
  if(A && B){
    A--;
    B--;
    cnt += AB;
    cnt++;
    cnt += min(A,B);
  }else if(A){
    cnt += AB;
  }else if(B){
    cnt += AB;
  }else{
    cnt += max(0,AB-1);
  }
  cout << cnt << "\n";
  return 0;
}

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

ll gcd(ll a, ll b){ 
    if (a == 0) 
        return b;  
    return gcd(b % a, a);  
 } 
  
   
// Function to return LCM of two numbers  
  ll lcm(ll a, ll b)  
 {  
    return (a*b)/gcd(a, b);  
 }  
int main(){
		ll n;cin>>n;
		ll a[n+1];for(int i=1;i<=n;i++)cin>>a[i];
		ll count=0;
		ll mx=0;
		for(int i=1;i<n;i++)
		{
			if(a[i]>=a[i+1])count++;
			else
			count=0;
			
			mx=max(count,mx);
		}
		cout<<mx<<endl;
		
		
	}

Measured memory_bytes: 1024
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    //optimize
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    //---------
    int N,A,B,c;
    cin >> N >> A >> B; 
    c = N*A;
    if (c >B) cout << B << endl;
    else if (c <B) cout << c << endl;
    else if (c == B) cout << c << endl;
}
// vim: set fileencoding=utf-8


Measured memory_bytes: 3648
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>

using namespace std;

int main(void) {
	int noq,num;
	char temp;
	string str;
	while (cin >> str, str != "-") {
		queue<char> q;
		for (int i = 0; i < str.length(); ++i) {
			q.push(str[i]);
		}
		cin >> noq;
		for (int i = 0; i < noq; ++i) {
			cin >> num;
			for (int j = 0; j < num; ++j) {
				temp = q.front();
				q.pop();
				q.push(temp);
			}
		}
		while (!q.empty()) {
			cout << q.front();
			q.pop();
		}
		cout << endl;
	}
	return 0;
}



Measured memory_bytes: 3152
void main() {
    int[] tmp = readln.split.to!(int[]);
    int x = tmp[0], a = tmp[1], b = tmp[2];
    writeln(abs(x-a) < abs(x-b) ? 'A' : 'B');
}

import std.stdio;
import std.string;
import std.array;
import std.conv;
import std.algorithm;
import std.range;
import std.math;
import std.numeric;
import std.container;
import std.typecons;
import std.ascii;
import std.uni;

Measured memory_bytes: 256
def md(n):
    d=[]
    da=d.append
    for i in range(1,int(n**0.5)+1):
        if n%i==0:
            da(i)
            if i!=n//i:da(n//i)
    d.sort()
    return d
n = int(input())
t=md(n)
u=len(t)
midopen = 0
mini = 999999999999999
#print(t)
if u%2==1:midopen=u//2
else:midopen=u//2+1
for i in range(min(u-1,midopen+1)):
    x = t[i]
    y = n//x
    #print(x,y)
    mini = min(mini,x+y-2)
print(mini)

Measured memory_bytes: 3272
N=gets.chomp.to_i
x=[]
y=[]
h=[]

N.times do |i|
  x[i],y[i],h[i]=gets.chomp.split(" ").map { |e| e.to_i }
end

def abs(n)
  return -n if n<0
  return n
end

def max(a,b)
  return a > b ? a : b
end

for indx in 0..N-1 do
for i in 0..100 do
  for j in 0..100 do
    cx = i
    cy = j
    hight = h[indx] + abs(cx-x[indx]) + abs(cy-y[indx])
    for k in 0..N-1 do
      is_break = false
      if h[k] != max(hight-abs(cx-x[k])-abs(cy-y[k]),0)
        is_break = true
        break
      end
    end
    next if is_break
    printf("%d %d %d\n",cx,cy,hight)
    exit
  end
end
end


Measured memory_bytes: 1788
l = map(int, input().split())
l = list(l)
l.sort()
cnt = 0
tmp = [l[1] - l[0] ,l[2]-l[1]]
if tmp[0] % 2 == 0:
    cnt += tmp[0] // 2 + tmp[1]
else:
    if tmp[0] == 1:
        cnt += tmp[1] + 2
    else :
        cnt += (tmp[0] - 1 )//2 + tmp[1] + 2
print(cnt)


Measured memory_bytes: 3060
def hcf(x, y):
    if x > y:
       smaller = y
    else:
       smaller = x
    for i in range(1,smaller + 1):
       if((x % i == 0) and (y % i == 0)):
           hcf = i
    return hcf

n = input().split()
a = hcf(int(n[0]), int(n[1]))
c = 0
d = a
for i in range(a):
  if (a%d) == 0:
    c = c + 1
  if c == int(n[2]):
    print(d)
    break
  d = d - 1
 
 


Measured memory_bytes: 3064
#include<stdio.h>
#include<string.h>

int main(void) {
  char weather[10];
  scanf("%s", weather);
  if ( !strcmp(weather, "Sunny") ) {
    printf("Cloudy\n");
  } else if ( !strcmp(weather, "Cloudy") ) {
    printf("Rainy\n");
  } else {
    printf("Sunny\n");
  }
  return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
#define ll long long
 
int main() {
  int n;
  cin>>n;
  string s;
  cin>>s;
  int ans=0;
  for(int i=0;i+2<n;i++) { 
    if(s[i]=='A'&&s[i+1]=='B'&&s[i+2]=='C') ans++;
  } cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 3592
#include <bits/stdc++.h>
 
using namespace std;
 
#define MAX 150
typedef pair<int,int> pii;
 
int N,T,L,B;
int arr[MAX];
 
double solve(){
    double dp[MAX][MAX]; //dp[???????????°][????????????????????????]
    memset(dp,0,sizeof(dp));
    dp[0][0] = 1;
    for(int i = 1 ; i <= T ; i++){
	for(int j = 0 ; j < N ; j++){
	    for(int k = 0 ; k < 6 ; k++){
		if(dp[i-1][j] == 0) continue;
		int next = j+(k+1);
		if(next > N){
		    next = next - 2*(next-N);
		}
		switch(arr[next]){
		case 0:
		    dp[i][next] += dp[i-1][j]/6;
		    break;
		case 1:
		    dp[i+1][next] += dp[i-1][j]/6;
		    break;
		case 2:
		    dp[i][0] += dp[i-1][j]/6;
		    break;
		}
	    }
	}
    }
    double res = 0;
    for(int i = 1 ; i <= T ; i++){
	res += dp[i][N];
    }
    return res;
}
 
int main(){
    int in;
    while(cin >> N >> T >> L >> B, N){
	memset(arr,0,sizeof(arr));
	for(int i = 0 ; i < L ; i++){
	    cin >> in;
	    arr[in] = 1;
	}
	for(int i = 0 ; i < B ; i++){
	    cin >> in;
	    arr[in] = 2;
	}
	printf("%.8f\n",solve());
    }
    return 0;
}

Measured memory_bytes: 3288
#include<stdio.h>

int main(){
	
	int a,b,c,d,S,e,f,g,h,T;
	
	scanf("%d %d %d %d",&a ,&b ,&c ,&d);
	scanf("%d %d %d %d",&e ,&f ,&g ,&h);
	
	S=a+b+c+d;
	T=e+f+g+h;
	
	if(S>=T){
		printf("%d\n",S);
	}
	else if(S<T){
		printf("%d\n",T);
	}
	
return 0;
}

Measured memory_bytes: 592
import java.util.*;

public class Main {
    private static final Scanner scn = new Scanner(System.in);
    
    public static void main(String[] args) {
        System.out.println(factorial(scn.nextInt()));
    }
    
    private static long factorial(int n) {
        return n > 1 ? n * factorial(n - 1) : 1;
    }
}

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

const int mod=998244353;

vector<int>getketa(long k){
  vector<int>ret;
  while(k>0){
    ret.push_back(k%2);
    k/=2;
  }
  return ret;
}

long getrev(long k){
  vector<int>modm2 = getketa(mod-2);
  vector<long>powk(32); // k^(2^i)
  powk[0]=k;
  for(int i=1; i<32; i++){
    powk[i]=(powk[i-1]*powk[i-1])%mod;
  }
  long ret = 1;
  for(int i=0; i<modm2.size(); i++){
    if(modm2[i]){
      ret*=powk[i];
      ret%=mod;
    }
  }
  return ret;
}

int main(){
  long n, m, k;
  cin >> n >> m >> k;
  vector<long>rev(n, 0);
  for(int i=1; i<n; i++){
    rev[i]=getrev(i);
  }
  vector<long>powm1(n+1);
  powm1[0]=1;
  for(int i=1; i<=n; i++){
    powm1[i]=((m-1)*powm1[i-1])%mod;
  }
  vector<long>n1ci(n);
  n1ci[0]=1;
  for(int i=1; i<n; i++){
    n1ci[i]=((n1ci[i-1]*(n-i))%mod*rev[i])%mod;
  }
  long ret=0;
  for(int i=n-k-1; i<n; i++){
    ret += n1ci[i]*((powm1[i]+powm1[i+1])%mod)%mod;
    ret %= mod;
  }
  cout << ret;
  return 0;
}

Measured memory_bytes: 7500
#include <stack>
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <cmath>
#include <iomanip>
using namespace std;
int gcd(int a, int b)
{
   if (a%b == 0)
   {
       return(b);
   }
   else
   {
       return(gcd(b, a%b));
   }
}
int mod = 1000000000 + 7;
int main(){
    //std::stack<int> stack;
    
    int n,q;
    cin >> n;
    vector<int> t(n);
    for(int i = 0; i < n; i++){
        cin >> t[i];
    }
    cin >> q;
    int ans = 0;
    for(int i = 0; i < q; i++){
        int tmp;
        cin >> tmp;
        int left = 0;
        int right = n;
        while(left < right){
            int mid = (left+right)/2;
            if(t[mid] == tmp){
                ans ++;
                break;
            }else if(t[mid] < tmp){
                left = mid + 1;
            }else if(t[mid] > tmp){
                right = mid;
            }
        }
    }
    cout << ans << endl;
}






Measured memory_bytes: 3108
package main

import (
	"fmt"
	"os"
	"strconv"
	"bufio"
	"strings"
)

// define
var (
	sc = bufio.NewScanner(os.Stdin)
)

func scanIntLine(len int) []int{
	arr := make([]int, len)
	for i:=0; i<len; i++{
		sc.Scan()
		tmp, err := strconv.Atoi(sc.Text())
		if err == nil{
			arr[i] = tmp
		}
	}
	return arr
}

func scanStringLine(len int) []string{
	arr := make([]string, len)
	for i:=0; i<len; i++{
		sc.Scan()
		arr[i] = sc.Text()
	}
	return arr
}

func scanIntSplit(len int) []int{
	arr := make([]int, len)
	sc.Scan()
	for i, v := range strings.Split(sc.Text(), " "){
		tmp, err := strconv.Atoi(v)
		if err == nil{
			arr[i] = tmp
		}
	}
	return arr
}

func main(){
	nk := scanIntSplit(2)
	ans := nk[1]
	for i:=1; i<nk[0]; i++{
		ans *= nk[1]-1
	}
	fmt.Println(ans)
}

Measured memory_bytes: 640
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>
#include <limits.h>


int main()
{
	int i,j,k;
	int n,m;
	int sa,sb; //a,bの合計
	int a[100],b[100];
	int ans[3];

	while(1){

		scanf("%d %d",&n,&m);
		if((n==0)&&(m==0))
			break;

		//初期化
		sa=0;
		sb=0;
		ans[0]=0;ans[1]=0;ans[2]=201;
		for(i=0;i<100;i++){a[i]=0;b[i]=0;}

		//入力
		for(i=0;i<n;i++){scanf("%d",&a[i]);sa+=a[i];}
		for(i=0;i<m;i++){scanf("%d",&b[i]);sb+=b[i];}

		for(i=0;i<n;i++){
			for(j=0;j<m;j++){
				if((sa-sb)==2*(a[i]-b[j])){
					if(ans[2]>(a[i]+b[j])){
					ans[0]=a[i];
					ans[1]=b[j];
					ans[2]=(a[i]+b[j]);
					}
				}
			}
		}
		
		if(ans[2]==201){
			printf("-1\n");
		}
		else{
			printf("%d %d\n",ans[0],ans[1]);
		}
	}

	return 0;
}

Measured memory_bytes: 1040
import bisect
N = int(input())
A = sorted(list(map(int,input().split())))
B = sorted(list(map(int,input().split())))
C = sorted(list(map(int,input().split())))
print(sum(bisect.bisect_left(A, i)*(N-bisect.bisect_right(C, i)) for i in B))

Measured memory_bytes: 23092
N = int(input())
F = [list(map(int,input().split())) for _ in range(N)]
P = [list(map(int,input().split())) for _ in range(N)]
ans = -10**9

for i in range(1,2**10):
    bit = format(i,"010b")
    C = [0]*(N)
    temp = 0
    for b in range(10):
        if bit[b] == "1":
            for j in range(N):
                if F[j][b] == 1:
                    C[j] += 1
    for p,c in zip(P,C):
        temp += p[c]
    if temp > ans:
        ans = temp
print(ans)


Measured memory_bytes: 41968
X, N = map(int,input().split())
P = list(map(int,input().split()))
Q =[]
for i in range(-1,102):
    Q.append(i)
A = list(set(Q) - set(P))
min = 200
ans = 1000
for i in range(len(A)):
    if abs(X - A[i]) < min:
        min = X - A[i]
        ans = A[i]
print(ans)


Measured memory_bytes: 9096
#include<stdio.h>

int main(void)
{
  int tosi = 0;
  scanf("%d",&tosi);
  
  switch(tosi)
  {
    case 7:
    case 5:
    case 3:
      printf("YES");
      break;
    default:
      printf("NO");
      break;
  }
  
  return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;
typedef long long ll;
typedef vector<ll> vi;

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

	int N;
	const int M = 1e6+5;
	cin >> N;
	vi count(M, 0);
	vector<bool> div(M, false);
	for(int i = 0; i < N; ++i) {
		int x;
		cin >> x;
		++ count[x];
	}
	int ans = 0;
	for(int i = 1; i < M; ++i) {
		if(div[i] || count[i] == 0) continue;
		if(count[i] == 1) ++ ans;
		for(int j = 2*i; j < M; j += i) div[j] = true;
	}
	cout << ans << "\n";

	return 0;
}

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

int main(){
  string s;
  cin >> s;
  if(s=="SUN"){
    cout << 7 << endl;
  }else if(s=="MON"){
    cout << 6 << endl;
  }else if(s=="TUE"){
    cout << 5 << endl;
  }else if(s=="WED"){
    cout << 4 << endl;
  }else if(s=="THU"){
    cout << 3 << endl;
  }else if(s=="FRI"){
    cout << 2 << endl;
  }else if(s=="SAT"){
    cout << 1 << endl;
  }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define int long long 
using namespace std;
inline int read()
{
    int s=0;
    char ch=getchar();
    while(ch<'0'||ch>'9') ch=getchar();
    while(ch>='0'&&ch<='9') s=s*10+ch-'0',ch=getchar();
    return s;
}
const int N=1010100,INF=2e9;
int n,q,b[N],tot,mx[N];
long long ans;
void gmi(int &x,int y){x=min(x,y);}
struct pr{int l,r,w;}e[N];
bool operator < (pr x,pr y){return x.w<y.w;}
int find(int x){return b[x]==x?b[x]:b[x]=find(b[x]);}
void mst()
{
    sort(e+1,e+tot+1);
    for(int i=0;i<n;i++) b[i]=i;
    for(int i=1;i<=tot;i++) {
	int l=e[i].l,r=e[i].r,w=e[i].w;
	int tx=find(l),ty=find(r);
	if(tx==ty) continue;
	b[tx]=ty;
	ans+=w;
    }
}
signed main()
{
    n=read();q=read();
    for(int i=0;i<n;i++) mx[i]=INF;
    for(int i=1;i<=q;i++) {
	int l=read(),r=read(),w=read();
	e[++tot]=(pr){l,r,w};
	gmi(mx[l],w+1);gmi(mx[r],w+2);
    }
    int d=INF,t=INF,be=0;
    for(int i=0;i<n;i++) if(mx[i]<t) be=i,t=mx[i];
    for(int i=1;i<=n;i++){
	d=min(d,mx[be]);
	e[++tot]=(pr){be,(be+1)%n,d};
	be=(be+1)%n;d+=2;
    }
    mst();
    cout<<ans<<'\n';
}


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

int main(){
  long long a,b,c,d;
  cin >> a >>b >>c >> d;
  long long ans = a * c;
  long long buf = b * d;
  if(buf > ans){
    ans = buf;
  }
  buf = a*d;
  if(buf > ans){
    ans = buf;
  }
  buf = b*c;
  if(buf > ans){
    ans = buf;
  }
  cout << ans << endl;
}



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

int main() {
	int N,A,B;
	int res = 0;
	int tmp,sum=0;

	cin >> N >> A >> B;

	for (int i = 1;i <= N;i++) {
		tmp = i;
		sum = 0;
		while (tmp > 0){
			sum += tmp % 10;
			tmp /= 10;
		}

		if (sum >= A && sum <= B) {
			res+=i;
		}

	}
	cout << res << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, a, n) for (int i = a; i < n; i++)
#define repr(i, a, n) for (int i = n - 1; i >= a; i--)
using namespace std;
using ll = long long;
using P = pair<int, int>;
template <typename T> void chmin(T &a, T b) { a = min(a, b); }
template <typename T> void chmax(T &a, T b) { a = max(a, b); }

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

  int a, b, k;
  cin >> a >> b >> k;
  int ans = 0;
  repr(i, 1, min(a, b) + 1) {
    if (a % i == 0 && b % i == 0)
      ans++;
    if (ans == k) {
      cout << i << endl;
      return 0;
    }
  }
}


Measured memory_bytes: 256
s=input()
q=int(input())
dp=[' ']*(len(s))
for i in range(len(s)):
    dp[i]=s[i]
index=[0]*(len(s))
for i in range(len(s)):
    index[i]=i
flag=0
head=-1
tail=len(s)
for i in range(q):
    t=input()
    if t[0]=='1':
        flag=1-flag
    else:
        _,f,c=map(str,t.split())
        dp.append(c)
        if f=='1':
            if flag==1:
                index.append(tail)
                tail+=1
            else:
                index.append(head)
                head-=1
        else:
            if flag==0:
                index.append(tail)
                tail+=1
            else:
                index.append(head)
                head-=1
index2=[]
for i in range(len(dp)):
    index2.append((index[i],dp[i]))
index2.sort(reverse=flag)
#print(index2)
for i in range(len(index)):
    print(index2[i][1],end='')

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

int main(void){
    int h, w;
    std::cin >> h >> w;

    std::vector< std::vector<char>> aTable(h+2,std::vector<char>(w+2,'#'));

    for(int i = 1; i < h+1; i++){
        for(int j = 1; j < w+1; j++){
            std::cin >> aTable[i][j];
        }
    }

    for(int i = 0; i < h+2; i++){
        for(int j = 0; j < w+2; j++){
            std::cout << aTable[i][j];
        }
        std::cout << std::endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
ll p=pow(10,9)+7;
ll phi(ll n) {
    ll result = n;
    for (ll i = 2; i * i <= n; i++) {
        if(n % i == 0) {
            while(n % i == 0)
                n /= i;
            result -= result / i;
        }
    }
    if(n > 1)
        result -= result / n;
    return result;
}
ll power(ll x, ll y, ll p) 
{ 
    ll res = 1;      
    x = x % p;  
   while (y > 0) 
    { 
        if (y & 1) 
            res = (res*x) % p; 
        y = y>>1; 
        x = (x*x) % p; 
    } 
    return res; 
} 
 
ll modInverse(ll n, ll p) 
{ 
    return power(n, p-2, p); 
}
 
 
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll t,n,k,i,j,m,a,b;
    cin>>k>>n;
    ll a1[n],a2[n];
    for(i=0;i<n;i++)
    {
        cin>>a;
        a1[i]=a;
        
    }
    sort(a1,a1+n);
   ll max=0;
   for(i=1;i<n;i++)
   {
       max=std::max(max,a1[i]-a1[i-1]);
   }
    ll ans=std::min(k-max,a1[n-1]-a1[0]);
    cout<<ans;
    return 0;
 
    
}
    


Measured memory_bytes: 1920
#include <stdio.h>

int
main(int argc, char *argv[])
{
        int a, b;

        scanf("%d %d", &a, &b);
        if (a < b)
                printf("a < b\n");
        else if (a > b)
                printf("a > b\n");
        else
                printf("a == b\n");

        return 0;
}

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

int gcd(int,int);

int main(){
	int a,b;
	cin >> a >> b;
	if(a<b){
		int w=a;
		a= b;
		b = w;
	}
	cout << gcd(a,b)<<endl;
	return 0;
}

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

Measured memory_bytes: 1160