akhauriyash/Code-Regression huggingface dataset:
import java.util.Arrays;
import java.util.Comparator;
import java.util.PriorityQueue;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        int[] A = new int[n];
        for (int i = 0; i < n; i++) A[i] = sc.nextInt();
        int[] B = new int[m], C = new int[m];
        for (int i = 0; i < m; i++) {
            B[i] = sc.nextInt();
            C[i] = sc.nextInt();
        }
        System.out.println(sln(n, m, A, B, C));
    }

    public static long sln(int n, int m, int[] A, int[] B, int[] C) {
        PriorityQueue<Integer> pq = new PriorityQueue<>();
        for (int a : A) pq.offer(a);
        int[][] D = new int[m][2];
        for (int i = 0; i < m; i++) {
            D[i][0] = B[i];
            D[i][1] = C[i];
        }
        Arrays.sort(D, new Comparator<int[]>() {
            @Override
            public int compare(int[] a, int[] b) {
                return b[1] - a[1];
            }
        });
        for (int i = 0; i < m; i++) {
            int k = D[i][0], v = D[i][1];
            for (int j = 0; j < k; j++) {
                int p = pq.peek();
                if (p < v) {
                    pq.poll();
                    pq.offer(v);
                } else break;
            }
        }
        long sum = 0;
        while (!pq.isEmpty()) {
            sum += (long) pq.poll();
        }
        return sum;
    }
}


Measured memory_bytes: 91304
#include <stdio.h>
#include <assert.h>
#include <fstream>
#include <iostream>
#include <algorithm>
#include <array>
#include <vector>
#include <queue>
#include <set>
#include <cmath>
//#include <unordered_map>
//#include <unordered_set>
//#include <boost/container/static_vector.hpp>
//#include <boost/unordered_set.hpp>
//#include <boost/unordered_map.hpp>
//#include <unistd.h>

//#include <cv.h>
//#include <highgui.h>
#include <stdlib.h>
#include <string>

#include <stdio.h>
#include <assert.h>
#include <fstream>
#include <iostream>
#include <algorithm>
#include <array>
#include <vector>
#include <queue>
#include <set>
#include <cmath>
//#include <unordered_map>
//#include <unordered_set>
//#include <boost/container/static_vector.hpp>
//#include <boost/unordered_set.hpp>
//#include <boost/unordered_map.hpp>
//#include <unistd.h>

//#include <cv.h>
//#include <highgui.h>
#include <stdlib.h>
#include <time.h>

#include <string>

const int MAX_N = 100050;
int N, K;

int main(int argc, char **argv) {
    std::cin >> N >> K;
    long long ret = 0;
    /*
    for (int b = K + 1; b <= N; b++) {
        int n = (N - K) / b;
        ret += n + 1;
    }
    std::cout << ret << std::endl;
    */
    if (K == 0) {
        std::cout << (long long) N * N << std::endl;
        return 0;
    }

    for (long long b = 1; b <= N; b++) {
        if (K >= b) { continue; }
        long long n = (N - K) / b;
        ret += n * (b - K);
        //std::cout << b << " " << n << " " << n * (b - K) << std::endl;
        if (n*b < N) {
            for (long long res = K; res < b; res++) {
                if (n*b + res <= N) { 
                    ret++;
                }
                else { break; }
            }
        }
    }

    std::cout << ret << std::endl;
    
    return 0;

}

Measured memory_bytes: 256
#include <stdio.h>
#include <math.h>

int main(){
    int i,n;
    int c = 0;
    int sum = 0;
    int ave = 0;
    double k;
    
    while(scanf("%d,%d", &i, &n) != EOF){
        sum += i * n;
        k += n;
        c++;
    }
    
    ave = floor(k /c +0.5);
    
    printf("%d\n%d\n", sum, ave);
    return 0;
}

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

using namespace std;

#define fi first
#define se second
#define eb emplace_back
#define mt make_tuple
#define all(x) (x).begin(), (x).end() 
#define MOD 1000000007

typedef long long ll;
typedef pair <int, int> ii;
typedef pair <ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef long double ld;

const ll INF=LLONG_MAX;
const int mxn = 5e4;
bool isComposite[mxn];
vi primes;

ll ans = 0ll;

void seive(){
	isComposite[0]=isComposite[1]=1;
	for(int i=2; i<mxn; i++){
		if(!isComposite[i]){
			primes.eb(i);
			for(int j=2*i; j<mxn; j+=i)isComposite[j]=1;
		}
	}
}

ll pf(int n){
	ll res = 1ll;
	for(auto x:primes){
		if(x*x>n)break;
		int cnt = 0;
		while(n%x==0){
			n/=x;
			cnt++;
		}
		if(cnt){
			res *= cnt+1;
		}
	}
	if(n!=1)res *= 2;
	return res;
}

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);
    //freopen("input.txt","r",stdin); freopen("output.txt","w",stdout);
	int n; cin >> n;
	seive();
	for(int i=1; i<=n; i++){
		ans += (ll)i*pf(i);
	}
	cout << ans << '\n';
}
	
// READ & UNDERSTAND
// ll, int overflow, array bounds, memset(0)
// special cases (n=1?), n+1 (1-index)
// do smth instead of nothing & stay organized
// WRITE STUFF DOWN


Measured memory_bytes: 3756
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define INF 1<<30
#define LINF 1LL<<60

struct Rectangle {
	ll h;
	ll p;  // position from left
};

ll max_area_of_histgram(ll n, vector<ll>& height) {
	stack<Rectangle> S;
	ll maxv = 0;

	for (int i = 0; i <= n; i++) {
		Rectangle rect;
		rect.h = height[i];
		rect.p = i;

		if (S.empty()) {
			S.push(rect);
		}
		else if (S.top().h < rect.h) {
			S.push(rect);
		}
		else if (S.top().h > rect.h) {
			ll now = i;
			while ((!S.empty()) && (S.top().h >= rect.h)) {
				Rectangle pre = S.top(); S.pop();
				ll area = 1LL * pre.h * (i - pre.p);
				maxv = max(maxv, area);
				now = pre.p;
			}
			rect.p = now;
			S.push(rect);
		}
	}
	return maxv;
}

int main() {
	cin.tie(0); ios::sync_with_stdio(false);
	ll N; cin >> N;
	vector<ll> dp(N + 1, 0);
	for (int i = 0; i < N;i++) cin >> dp[i];
	cout << max_area_of_histgram(N, dp) << endl;
	return 0;
}

Measured memory_bytes: 5344
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<string.h>
#include<math.h>
#include<utility>
#include<map>
using namespace std;
typedef long long int ll;
typedef long double ld;
typedef vector<ll> vi;
typedef vector<string> vs;
typedef pair<ll,ll> P;
typedef vector<P> vp;
#define REP(i,n) for(ll i=0;i<n;i++)
#define FOR(i,m,n) for(ll i=m;i<n;i++)
#define REPR(i,n) for(ll i=n-1;i>=0;i--)
#define FORR(i,n,m) for(ll i=n-1;i>=m;i--)
#define all(in) in.begin(),in.end()
#define ALL(in,K) in,in+K

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

    ll ans=0;
    for(int i=1;i<=K;i++){
        for(int j=i+1;j<=K;j+=2){
            //cout << i << ":" << j << endl;
            ans++;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <string.h>
#include <map>
#include <set>
#include <vector>
#include <stdio.h>
#include <math.h>
#include <algorithm>
#include <queue>
#include <cmath>
#include <cstdio>
using namespace std;
int main(){
int a,b;
cin>>a>>b;
if(b>a)
cout<<'0';
else
cout<<a-b;
system("pause");
return 0;
}

Measured memory_bytes: 504
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int x1, y1, x2, y2;
    cin >> x1 >> y1 >> x2 >> y2;
    int dx = x2 - x1;
    int dy = y2 - y1;
    int x3 = x2 - dy;
    int y3 = y2 + dx;
    int x4 = x3 - dx;
    int y4 = y3 - dy;
    cout << x3 << " " << y3 << " " << x4 << " " << y4 << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <math.h>
#include <cmath>
#include <limits.h>
#include <map>
#include <unordered_map>
#include <set>
#include <queue>
#include <algorithm>
#include <functional>
#include <stdio.h>
using namespace std;

long long MOD = 1000000007;


int main() {
    
    int N;
    cin >> N;    
    vector<int> D(N+1,INT_MAX);
    D[0] = 0;
    for ( int i = 0; i < N; i++ ) {

        int x = 1;
        for ( int j = 0; j < 7; j++ ) {
            if ( i+x > N ) { break; }
            D[i+x] = min( D[i+x], D[i]+1 );
            x *= 6;
        }
        x = 1;
        for ( int j = 0; j < 6; j++ ) {
            if ( i+x > N ) { break; }
            D[i+x] = min( D[i+x], D[i]+1 );
            x *= 9;
        }

    }

    cout << D[N] << endl;


    return 0;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
# ifdef DEB
# define debug(...) fprintf(stderr, __VA_ARGS__)
# else
# define debug(...)
#endif
#define F first
#define S second
#define MP make_pair
#define PB push_back
#define LL long long
#define LD long double
#define PII pair<int, int>
#define PLL pair<LL, LL>
#define pb pop_back
#define VI vector<int> 
#define VPI vector<PII> 
#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 RE(i,n) FOR(i,1,n)
#define REP(i,n) FOR(i,0,(int)(n)-1)
#define ALL(x) (x).begin(), (x).end()
#define siz(V) ((int)V.size())
const int inf = 1e9 + 7;
const int M = 200005;

int n;
PLL T[M];
LL mini = inf, maxi, rmini = inf, lmaxi;
LL res;
vector<PLL> V;
set<PLL> secik;

int main()
{
  //ios_base::sync_with_stdio(0);
  scanf("%d", &n);
  for (int i = 0; i < n; i++)
  {
    LL x, y;
    scanf("%lld%lld", &x, &y);
    if (x > y)
    {
      swap(x, y);
    }
    mini = min(mini, x);
    maxi = max(maxi, y);
    rmini = min(rmini, y);
    lmaxi =max(lmaxi, x);
    V.PB(MP(x, i));
    T[i] = MP(x, y);
    secik.insert(MP(-x, i));
  }
  //debug("%d %d %d %d\n", mini, maxi, lmaxi, rmini);
  sort(ALL(V));
  res = (lmaxi - mini) * (maxi - rmini);
 // printf("%lld\n", res);
  LL red = maxi - mini;
  PLL blue = MP(min(rmini, lmaxi), max(rmini, lmaxi));
  for (int i = 0; i < n; i++)
  {
    LL rig = blue.S;
    if (!secik.empty())
    {
      rig = max(rig, -secik.begin()->F);
    }
    LL blue2 = rig - min(blue.F, V[i].F);
    res = min(res, red * blue2);
    blue.S = max(blue.S, T[V[i].S].S);
    secik.erase(MP(-T[V[i].S].F, V[i].S));
  }
  printf("%lld\n", res);
  return 0;
}

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

using namespace std;


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

    int n, x;
    cin>> n;
    int a[n];
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
    }
    for (int i = 0; i < n; ++i) {
        if(a[i] % 2 == 0 && a[i] % 3 && a[i] % 5){
            cout << "DENIED\n";
            return 0;
        }
    }
    cout << "APPROVED\n";
}

Measured memory_bytes: 3616
# encoding:utf-8
import copy
import numpy as np
import random
import bisect #bisect_left　これで二部探索の大小検索が行える
import math


N = int(input())
H = [int(i) for i in input().split()]


ans = 0
for i in range(N):
    base = H[i]
    check = True
    for j in range(N):
        if i<=j:
            pass
        else:
            if H[i]>=H[j]:
                pass
            else:
                check = False
                break
    if check:
        ans += 1

print(ans)


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

int bo[10][10][10];
int n,m,p;
int dt[2][13]={{ 1, 0, 0,  1, 1, 1, 1,  0, 0, 1, 1, 1, 1},
             {  -1, 0, 0, -1,-1,-1,-1,  0, 0,-1,-1,-1,-1}};
int da[2][13]={{ 0, 1, 0,  1,-1, 1,-1,  1,-1, 0, 0, 1,-1},
             {   0,-1, 0, -1, 1,-1, 1, -1, 1, 0, 0,-1, 1}};
int db[2][13]={{ 0, 0, 1,  1, 1,-1,-1,  1, 1, 1,-1, 0, 0},
             {   0, 0,-1, -1,-1, 1, 1, -1,-1,-1, 1, 0, 0}};
bool cc(int t,int a,int b){
    if(!(0<=t&&t<n)) return false;
    if(!(0<=a&&a<n)) return false;
    if(!(0<=b&&b<n)) return false;
    return true;
}
bool check(int t,int a,int b){
    bool ret=false;
    int col=bo[t][a][b];
    int cnt=0;
    int tt,ta,tb;
    rep(i,13){
        cnt=0;
        rep(j,2){
            tt=t;ta=a;tb=b;
            while(cc(tt,ta,tb)){
                if(col==bo[tt][ta][tb]) cnt++;
                else break;
                tt+=dt[j][i];ta+=da[j][i];tb+=db[j][i];
            }
        }
        if(cnt-1>=m) return true;
    }
    return false;
}
int main(){
    while(cin>>n>>m>>p,n||m||p){
        rep(i,10) rep(j,10) rep(k,10) bo[i][j][k]=-1;
        int ans=-1;
        rep(i,p){
            int a,b;
            cin>>a>>b;
            a--;
            b--;
            int t;
            for(int j=9;j>=0;j--){
                if(bo[j][a][b]!=-1){
                    bo[j+1][a][b]=i%2;
                    t=j+1;
                    break;
                }
                if(j==0){
                    bo[0][a][b]=i%2;
                    t=0;
                }
            }
            if(ans<0&&check(t,a,b)){
                ans=i;
            }
        }
        if(ans>=0) cout<<(ans%2==0?"Black":"White")<<" "<<ans+1<<endl;
        else cout<<"Draw"<<endl;
    }
}

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

int main() {
  int a, b, k;
  cin >> a >> b >> k;
  vector<int> div;
  for (int i = 1; i <= 100; i++) {
    if (a % i == 0 && b % i == 0) {
      div.push_back(i);
    }
  }
  cout << div.at(div.size() - k) << endl;
}


Measured memory_bytes: 256
n,k=map(int,input().split())
a=list(map(int,input().split()))
l=0
r=max(a)+1
while r-l>1:
	cnt=0
	mid=(l+r+1)//2
	if mid==0:
		print(1)
		exit()
	for x in a:
		if x>1:
			cnt+=(x-1)//mid
	if cnt<=k:
		r=mid
	else:
		l=mid
print(r)


Measured memory_bytes: 104404
#include <bits/stdc++.h>
#define ll long long
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define repi(i, a, b) for (ll i = (ll)(a); i < (ll)(b); i++)
#define repm(i, a, b) for (ll i = (ll)(a); i > (ll)(b); i--)
#define all(v) v.begin(), v.end()
#define rall(x) (x).rbegin(), (x).rend()
#define pll pair<long long, long long>
#define pb emplace_back
#define mp make_pair
#define mt make_tuple
#define vc vector<char>
#define vvc vector<vc>
using namespace std;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<long long>;
using vvll = vector<vll>;
using vb = vector<bool>;
using vvb = vector<vb>;
template <class T>bool chmax(T &a, const T &b){if (a < b){a = b;return 1;}return 0;}
template <class T>bool chmin(T &a, const T &b){if (b < a){a = b;return 1;}return 0;}
//snippets:tmp,cl,cvl,cs,co,coy,con,cov,setp

ll modPow(long long a, long long n, long long p) {
  if (n == 0) return 1; // 0乗にも対応する場合
  if (n == 1) return a % p;
  if (n % 2 == 1) return (a * modPow(a, n - 1, p)) % p;
  long long t = modPow(a, n / 2, p);
  return (t * t) % p;
}



int main(){
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  ll n;
  cin >> n;
  ll mod=1e9+7;
  ll ans=1;
  cout<<(modPow(10,n,mod)-modPow(9,n,mod)*2+modPow(8,n,mod)+mod*10)%mod<<endl;
}


Measured memory_bytes: 3644
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <algorithm>
using namespace std;
 
#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()
 
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VL> VVL;
typedef vector<VI> VVI;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

int main() {
    int n;
    cin >> n;
    VVI a(2, VI(n));

    REP(i,2) REP(j,n) cin >> a[i][j];

    int ans = 0;

    REP(i,n){
        int s = 0;
        FOR(j,0,i) s += a[0][j];
        FOR(j,i,n-1) s += a[1][j];
        ans = max(ans, s);
    }
    cout << ans << endl;
    
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int A = sc.nextInt();
		int B = sc.nextInt();
		int C = sc.nextInt();
		int D = sc.nextInt();
		String S = sc.next();
		sc.close();

		S = S.substring(A-1,Math.max(C,D));
		String ans = "";
		if(S.contains("##")) {
			ans = "No";
		}else if(C < D) {
			ans = "Yes";
		}else {
			if(S.substring(B-2,D+1).contains("...")) {
				ans = "Yes";
			}else {
				ans = "No";
			}
		}
		System.out.println(ans);
	}
}

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

int main() {
	string s;
	cin >> s;
	if (s.back() == 's') s += "es";
	else s += "s";
	cout << s << '\n';
	return 0;
}

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

#define ll long long
#define ull unsigned long long
#define db long double
#define pb push_back
#define ppb pop_back
#define F first
#define S second
#define mp make_pair
#define all(x) (x).begin(), (x).end()

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;



int main() {
	ios_base::sync_with_stdio(false), cin.tie(NULL);
	#ifdef LOCAL
		freopen("input.txt", "r", stdin);
	#endif
	
	string s;
	cin >> s;
	if (s[2] == s[3] && s[4] == s[5]) {
		cout << "Yes";
	}	else {
		cout << "No";
	}
}


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

void solve(long long N, std::string S)
{
    int ans = 0;
    for (int i = 0; i < N - 2; i++)
    {
        if (S.substr(i, 3) == "ABC")
            ans++;
    }
    cout << ans << endl;
}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main()
{
    long long N;
    scanf("%lld", &N);
    std::string S;
    std::cin >> S;
    solve(N, S);
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
using pint = pair<int, int>;
using vi = vector<int>;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define endl "\n"

const int MOD = 1000000007;
const int INF = 1 << 30;

int main() {
    int r, d, x;
    cin >> r >> d >> x;
    rep(i, 10) {
        x = r * x - d;
        cout << x << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cmath>
#include <iostream>
#include <iomanip>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stdio.h>
#include <string>
#include <vector>

#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;
using LP = pair<ll, ll>;
const double PI = 3.1415926535897932;

int main()
{
	int N, K;
	int score[3];
	string T;

	cin >> N >> K;
	cin >> score[0] >> score[1] >> score[2];
	cin >> T;

	vector<int> restrict(N, 0);
	ll ans = 0;
	for (int i = 0; i < N; ++i)
	{
		if (restrict[i] != 0) continue;
		if ((i + K) < N)
		{
			if (T[i] == T[i + K]) T[i + K] = 1;
		}

		switch (T[i]) {
		case 'r':
			ans += score[2];
			break;
		case's':
			ans += score[0];
			break;
		case 'p':
			ans += score[1];
			break;
		}
	}

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


Measured memory_bytes: 3844
import sys
stdin = sys.stdin
 
sys.setrecursionlimit(10**5) 
 
def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x)-1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())

n = ni()
f = [int("".join(ls()), 2) for _ in range(n)]      
p = [list(li()) for _ in range(n)]

# bit全探索
ans = -float("inf")
for bit in range(1, 1<<10):
    profit = 0
    
    for i,fi in enumerate(f):
        both = bin(bit&fi).count("1")
        profit += p[i][both]
    
    ans = max(ans, profit)
    
print(ans)

Measured memory_bytes: 3064
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <queue>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <fstream>
#include <complex>
#include <cstdint>
#include <tuple>
#include <numeric>
#define M_PI       3.14159265358979323846
#ifdef LOCAL
#include <sys/types.h>
#include <sys/timeb.h>
#include <intrin.h> 
#include <thread>
#else
#include <sys/time.h>
#endif

using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; }
template<class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str(); }

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
typedef unsigned long long ULL;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define MT make_tuple
#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 FILL(a, x) memset(a, x, sizeof(a))

//repetition
//------------------------------------------
#define FOR(i,s,n) for(int i=s;i<(int)n;++i)
#define REP(i,n) FOR(i,0,n)

int a[4];
int main(){
	REP(i, 4) {
		cin >> a[i];
	}
	sort(a, a + 4);
	if (a[0] == 1 && a[1] == 4 && a[2] == 7 && a[3] == 9)cout << "YES" << endl;
	else cout << "NO" << endl;
	

	
	return 0;
}

Measured memory_bytes: 256
A, B, C, D = map(int, input().split())

A_count = 0
while A > 0:
    A = A - D
    A_count += 1

B_count = 0
while C > 0:
    C = C - B
    B_count += 1

if A_count < B_count:
    print("No")
else:
    print("Yes")



Measured memory_bytes: 9176
#include<iostream>
#include<vector>
#include<map>
#include<queue>
#include<functional>
#define pb push_back
#define MAX_V 2000//場合によって変更
#define INF 1000000000
using namespace std;
typedef pair<int,int> P;//firstは最短距離,secondは頂点番号
struct edge{
	int to,cost;
};
int V;//頂点の数
vector<vector<edge> > G;
//-----------
vector<vector<edge> > G2;
//-----------
int dijkstra(int s,int g){
	priority_queue<P,vector<P> , greater<P> > que;
	vector<int> d(V,INF);
	d[s]=0;
	que.push(P(0,s));
	while(!que.empty()){
		P p=que.top();
		que.pop();
		int v=p.second;
		if(d[v]<p.first)
			continue;
		for(int i=0;i<G[v].size();i++){
			edge e=G[v][i];
			if(d[e.to]>d[v]+e.cost){
				d[e.to]=d[v]+e.cost;
				que.push(P(d[e.to],e.to));
			}
		}
	}
	
	return d[g];
}
//-----------
int dijkstra2(int s,int g){
	priority_queue<P,vector<P> , greater<P> > que;
	vector<int> d(V,INF);
	d[s]=0;
	que.push(P(0,s));
	while(!que.empty()){
		P p=que.top();
		que.pop();
		int v=p.second;
		if(d[v]<p.first)
			continue;
		for(int i=0;i<G2[v].size();i++){
			edge e=G2[v][i];
			if(d[e.to]>d[v]+e.cost){
				d[e.to]=d[v]+e.cost;
				que.push(P(d[e.to],e.to));
			}
		}
	}
	
	return d[g];
}
//--------------
int main(){
	int E;
	while(cin>>E>>V,E){
		G.clear();
		G.resize(V);
		//------------
		G2.clear();
		G2.resize(V);
		//---------------
		for(int i=0;i<E;i++){
			int x,y,c,t;
			cin>>x>>y>>c>>t;x--;y--;
			edge e;
			e.cost=c;
			e.to=y;
			G[x].pb(e);
			e.to=x;
			G[y].pb(e);
			//--------------
			e.cost=t;
			e.to=y;
			G2[x].pb(e);
			e.to=x;
			G2[y].pb(e);
			//---------------
		}
		int n;
		cin>>n;
		for(int i=0;i<n;i++){
			int s,t,q;
			cin>>s>>t>>q;
			if(q==0)
			cout<<dijkstra(s-1,t-1)<<endl;
			else
			cout<<dijkstra2(s-1,t-1)<<endl;
		}
	}
	
	return 0;
}

Measured memory_bytes: 1032
#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>
#include <numeric>
#include <string.h>
#include <sys/time.h>
#include <random>


#define fs first
#define sc second
#define endl "\n"

using namespace std;

typedef long long ll;
typedef unsigned int uint;
typedef pair<ll, ll> P;

class modInt{
    ll value;
    static const ll mod = 998244353;

public:
    modInt(ll x=0): value{x % mod}{}

    inline modInt& operator+=(modInt x){
        value = (value + x.value) % mod;
        return *this;
    }

    inline modInt& operator-=(modInt x){
        value = (value + mod - x.value) % mod;
        return *this;
    }

    inline modInt& operator*=(modInt x){
        value = (value * x.value) % mod;
        return *this;
    }


    inline modInt operator/=(modInt x){
        *this *= x.inv();
        return *this;
    }

    inline modInt pow(ll n){
        modInt res = modInt(1LL);
        modInt x{value};
        while(n > 0){
            if(n & 1)   res *= x;
            x *= x;
            n >>= 1;
        }
        return res;
    }

    inline modInt inv(){
        modInt res = pow(mod-2);
        return res;
    }

    inline ll get(){
        return value;
    }
};

modInt operator+(modInt x, modInt y){
    return x += y;
}

modInt operator-(modInt x, modInt y){
    return x -= y;
}

modInt operator*(modInt x, modInt y){
    return x *= y;
}

modInt operator/(modInt x, modInt y){
    return x /= y;
}

ostream& operator<<(ostream& os, modInt x){
    return os << x.get();
}


class modIntCombinations{
    vector<modInt> factArray;

    void make_fact(ll x){
        for(auto i = factArray.size(); i <= x+1; i++){
            modInt y = factArray[i-1] * i;
            factArray.push_back(y);
        }
    }

public:
    modIntCombinations(){
        factArray.emplace_back(1);
    }

    modInt fact(ll x){
        if(factArray.size() < x+1){
            make_fact(x);
        }
        return factArray[x];
    }

    modInt comb(ll n, ll k){
        if(n < k){
            return modInt{0};
        }
        else{
            return fact(n) / fact(k) / fact(n - k);
        }
    }

    modInt perm(ll n, ll k){
        if(n < k){
            return modInt{0};
        }
        else{
            return fact(n) / fact(k);
        }
    }
};


int main(){
    ll n, a, b, k;  cin >> n >> a >> b >> k;
    modIntCombinations mic;
    modInt res = 0;
    for(ll aNum = 0; aNum * a <= k && (aNum <= n); aNum++){
        ll remain = k - aNum * a;
        if(remain % b != 0) continue;
        ll bNum = remain / b;
        if(bNum > n)    continue;
        res += mic.comb(n, aNum) * mic.comb(n, bNum);
    }

    cout << res << endl;


    return 0;
}


Measured memory_bytes: 6128
#include <iostream>
#include <iomanip>
using namespace std;
int main() {
	int n,k;

	cin >> n >> k;

	double ret = 0;	
	double eachP = 1 / (double) n;

	for (int i = 1; i <= n; i++) {
		int cur = i;
		double p = 1.0;
		while(cur < k) {
			cur *= 2;
			p *= 0.5;
		}
		ret += p * eachP;
	}
	cout <<  std::fixed << std::setprecision(10);
	cout << ret << endl;

	return 0;
}

Measured memory_bytes: 888
#include <algorithm>
#include <cassert>
#include <climits>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  long N, M;
  cin >> N >> M;
  vector<long> sums(N + 1, 0);
  for (long i = 1; i <= N; ++i) {
    long a;
    cin >> a;
    sums[i] += sums[i - 1] + a;
  }

  map<long, long> rems;
  for (long i = 0; i <= N; ++i) {
    ++rems[sums[i] % M];
  }

  long ans = 0;
  for (auto &e : rems) {
    long n = e.second;
    ans += (n * (n - 1) / 2);
  }

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

Measured memory_bytes: 4992
#include<bits/stdc++.h>
using namespace std;
int a[222222];
int main()
{
  int K,N,last=0;cin>>N>>K;
  for(int i=1;i<=K;i++)
  {
  		int now;
  		cin>>now;
  		a[i]=now-last;
  		last=now;
  		}
  int maxn=a[1]+N-last;
  for(int i=2;i<=K;i++)
  {	
  		maxn=max(maxn,a[i]);
  }
  cout<<N-maxn;
  return 0;
}

Measured memory_bytes: 1024
// http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0002

#include <iostream>
using namespace std;

int number_of_digits(int n) {
	int result = 0;
	while (n != 0) {
		result++;
		n /= 10;
	}
	return result;
}

int main() {
	int a, b;
	
	while (cin >> a >> b)
		cout << number_of_digits(a+b)
		     << endl;
	return 0;
}

Measured memory_bytes: 3028
#include <bits/stdc++.h>
using namespace std;
#define Maxn 107
int last[Maxn],pre[Maxn],other[Maxn],val[Maxn],cnt=1;
int n,m;
long long f[2][1500007];
int path[Maxn],tot=0;
void insert(int u,int v)
{
    other[++cnt]=v,pre[cnt]=last[u],last[u]=cnt;
}
void dfs(int u,int fa,int t,int id)
{
    if (u!=t)
    {
        for (int q=last[u];q;q=pre[q])
        {
            int v=other[q];
            if (v!=fa)
            {
                path[++tot]=q;
                dfs(v,u,t,id);
                --tot;
            }
        }
    } else
    {
        for (int i=1;i<=tot;i++)
        {
            val[path[i]]|=(1<<(id-1));
            val[path[i]^1]|=(1<<(id-1));
        }
    }
}
int main()
{
    scanf("%d",&n);
    for (int i=1;i<n;i++)
    {
        int u,v;
        scanf("%d%d",&u,&v);
        insert(u,v),insert(v,u);
    }
    scanf("%d",&m);
    for (int i=1;i<=m;i++)
    {
        int a,b;
        scanf("%d%d",&a,&b);
        dfs(a,-1,b,i);
    }
    for (int i=1;i<=cnt/2;i++)
        val[i]=val[i*2];
    memset(f,0,sizeof(f));
    int now=0;
    f[0][0]=1;
    for (int i=1;i<n;i++)
    {
        now^=1;
        memset(f[now],0,sizeof(f[now]));
        for (int j=0;j<(1<<m);j++)
        {
            f[now][j]+=f[now^1][j];
            f[now][j|val[i]]+=f[now^1][j];
        }
    }
    printf("%lld\n",f[now][(1<<m)-1]);
    return 0;
}

Measured memory_bytes: 23680
#include <iostream>
#include <string>

using namespace std;

int main(int argc, char const *argv[])
{
    string S, T;
    cin >> S >> T;
    T.pop_back();
    if (S == T)
    {
        cout << "Yes" << endl;
    }else
    {
        cout << "No" << endl;
    }
    
    return 0;
}

Measured memory_bytes: 3132
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.AbstractMap;
import java.util.StringTokenizer;

public class Main {

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

		solve(sc,out);

		out.flush();
	}

	public static void solve(FastScanner sc, PrintWriter out) {
		int R = sc.nextInt();
		int G = sc.nextInt();
		int B = sc.nextInt();
		int n = sc.nextInt();
		
		int res = 0;
		
		for(int r = 0; r <= 3000; r++) {
			for(int g = 0; g <= 3000; g++) {
				int b = (n-(r*R)-(g*G))/B;
				
				if(b >= 0 && r*R+g*G+b*B==n) {
					res++;
				}
			}
		}
		
		out.println(res);
	}

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

	public static long gcd(long a, long b) {
		if(a < b) return gcd(b, a);
		if(b == 0) return a;
		return gcd(b, a % b);
	}

	public static int lcm(int a, int b) {
		return a / gcd(a, b) * b;
	}
	
	public static long lcm(long a, long b) {
		return a / gcd(a, b) * b;
	}
}

class Pair<K, V> extends AbstractMap.SimpleEntry<K, V> {

    public Pair(final K key, final V value) {
        super(key, value);
    }

    public Pair<V, K> swap() {
    	return new Pair<V, K>(getValue(), getKey());
    }
 }

class FastScanner {
    private BufferedReader reader = null;
    private StringTokenizer tokenizer = null;

    public FastScanner(InputStream in) {
        reader = new BufferedReader(new InputStreamReader(in));
        tokenizer = null;
    }

    public String next() {
        if (tokenizer == null || !tokenizer.hasMoreTokens()) {
            try {
                tokenizer = new StringTokenizer(reader.readLine());
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return tokenizer.nextToken();
    }

    public String nextLine() {
        if (tokenizer == null || !tokenizer.hasMoreTokens()) {
            try {
                return reader.readLine();
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }

        return tokenizer.nextToken("\n");
    }

    public long nextLong() {
        return Long.parseLong(next());
    }

    public int nextInt() {
        return Integer.parseInt(next());
    }

    public double nextDouble() {
         return Double.parseDouble(next());
     }

    public int[] nextIntArray(int n) {
        int[] a = new int[n];
        for (int i = 0; i < n; i++)
            a[i] = nextInt();
        return a;
    }

    public long[] nextLongArray(int n) {
        long[] a = new long[n];
        for (int i = 0; i < n; i++)
            a[i] = nextLong();
        return a;
    }
}

Measured memory_bytes: 21204
#include <bits/stdc++.h>
using namespace std;
int ctoi(char c) {
	if (c >= '0' && c <= '9') {
		return c - '0';
	}
	return 0;
}
int main() {
  int a, b, c, d;
  string n;
  cin >> n;
  a = ctoi(n[0]);
  b = ctoi(n[1]);
  c = ctoi(n[2]);
  d = ctoi(n[3]);
  vector<char> vec(2);
  vec = {'+', '-'};
  for (int i = 0; i < 2; i++) {
    for (int ii = 0; ii < 2; ii++) {
      for (int iii = 0; iii < 2; iii++) {
        signed int ans = a;
        if (i == 0) ans += b;
        else if (i == 1) ans -= b; 
        
        if (ii == 0) ans += c;
        else if (ii == 1) ans -= c;
        
        if (iii == 0) ans += d;
        else if (iii == 1) ans -= d;
        if (ans == 7) {
          cout << a << vec[i] << b << vec[ii] << c << vec[iii] << d << "=7" << endl;
          return 0;
        }
      }
    }
  }
}

Measured memory_bytes: 256
#include<iostream>
#include<climits>
#include<math.h>
#include<vector>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<stdio.h>
#include <string>
#include <complex>
#include <functional>
#include <map>
#include <queue>
#include <cctype>
using namespace std;
using ll = long long;
//typedef pair<string,string> P;
//double dat[100][100];
//int dp[6][1010];//動的計画法
//int prime[100001];
//char str[1010][1010];
//typedef pair<ll,ll> A;
//vector<A> pc;
//int ABS(int a){return max(a,-a);}
int main() {
  int n,k;
  string s;
  cin>>n>>k;
  cin>>s;
  vector<char> ans;
  for(int i=0;i<n;i++){
    if(i==k-1){
      ans.push_back(tolower(s[i]));
    }else{
      ans.push_back(s[i]);
    }
  }
  for(int i=0;i<n;i++) cout<<ans[i];
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<string>
using namespace std;
int main(){
int a,b,c,k;
cin>>a>>b>>c>>k;
if(k<=a)
cout<<k<<"\n";
else if(k<=a+b){
	cout<<a<<"\n";
}
else if(k<=a+b+c){
	int ans=a;
	ans=ans+(k-a-b)*-1;
	cout<<ans<<"\n";
}
 
}

Measured memory_bytes: 3636
import java.util.*;
import java.text.*;

public class Main {

    Scanner sc = new Scanner(System.in);

    int n = sc.nextInt();
    int m = sc.nextInt();

    List<Integer>[] lists = new ArrayList[n+1];

    //        2 ... n
    int[] res = new int[n+1];


    public static void main(String[] args) {
        new Main().run();
    }

    void run() {

        for (int i=0; i<n+1; i++) lists[i] = new ArrayList<>();

        for (int i=0; i<m; i++) {
            int s = sc.nextInt();
            int t = sc.nextInt();
            lists[s].add(t);
            lists[t].add(s);
        }

//        System.out.println(lists[1]);

        bfs(1);

        int cnt = 0;

        for (int i=2; i<=n; i++) {
            if (res[i] != 0) cnt++;
        }

        if (cnt != n-1) {
            System.out.println("No");
        } else {
            System.out.println("Yes");
            for (int i=2; i<=n; i++) {
                System.out.println(res[i]);
            }
        }



    }

    void bfs(int s) {
        Queue<Integer> queue = new ArrayDeque<>();
        queue.add(s);
        while (!queue.isEmpty()) {
            int t = queue.peek();
            for (int u: lists[t]) {
                if (res[u] == 0) {
                    res[u] = t;
                    queue.add(u);
                }
            }
            queue.poll();
        }
    }
}



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


int main(void)
{
  int n,m,i;
  scanf("%d %d",&n,&m);
  int a[m],b[n + 1];
  for(i = 0;i < n + 1;i++) {
    b[i] = 1;  
  }
  b[0] = 1;
  b[1] = 1;
  
  for(i = 0;i < m;i++) {
    scanf("%d\n",&a[i]);
    b[a[i]] = 0;
  }
  

  for(i = 2;i < n + 1;i++) {
    if(b[i] == 0) continue;
    b[i] = (b[i - 2] + b[i - 1]) % 1000000007;
    //printf("%d\n",b[i]);
  }
  
  printf("%d\n",b[n]);
  
  return 0;
}

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

const long long MOD = 1000000007;

const int MAX = 100001;
long long fac[MAX], finv[MAX], inv[MAX];

void comb_init() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

long long mod_perm(int n, int k) {
    if (k < 0 || n < k) return 0;
    return fac[n] * finv[n - k] % MOD;
}

long long k;
long long ans = 1;
vector<bool> done(100000);
vector<vector<int>> graph(100000);
void dfs(int par, int now, int depth) {
    if (par == -1 || !done.at(par)) {
        if (depth == 0) {
        ans *= k;
        ans %= MOD;
        }
        else if (depth == 1) {
            ans *= mod_perm(k - 1, (int)graph.at(par).size());
            ans %= MOD;
        }
        else {
            ans *= mod_perm(k - 2, (int)graph.at(par).size() - 1);
            ans %= MOD;
        }
    }
    if (par != -1) done.at(par) = true;
    
    for (auto v: graph.at(now)) {
        if (v == par) continue;
        dfs(now, v, depth + 1);
    }
}

int main() {
    int n;
    cin >> n >> k;
    for (int i = 0; i < n - 1; i++) {
        int a, b;
        cin >> a >> b;
        a--; b--;
        graph.at(a).push_back(b);
        graph.at(b).push_back(a);
    }
    comb_init();
    
    dfs(-1, 0, 0);
    cout << ans << endl;
}

Measured memory_bytes: 11520
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define fi first
#define se second
template<typename A, typename B> inline bool chmax(A &a, B b) { if (a<b) { a=b; return 1 ; } return 0; }
template<typename A, typename B> inline bool chmin(A &a, B b) { if (a>b) { a=b; return 1 ; } return 0; }
typedef long long ll;
typedef pair<int, int> pii;
const ll INF = 1e9+100;
const bool debug = 0;
/***************************************/

int N;
int p[100];
int dp[101][25001]; // 500円の枚数, 所持金(100円以下の小銭) = 最小購入金額

int main() {
	while (cin >> N, N) {
		REP(i, N) scanf("%d", p + i);
		
		fill(dp[0], dp[N + 1], INF);
		dp[0][0] = 0;
		
		int lim[101] = {};
		for (int i = N - 1; i >= 0; i--) {
			int chg = (1000 - (p[i] % 1000)) % 1000;
			if (chg >= 500) chg = 500;
			lim[i] = 500 - chg + lim[i + 1];
		}
		REP(t, N) {
			int chg = 1000 - (p[t] % 1000);
			chg %= 1000;
			
			for (int i = N; i >= 0; i--) {
				for (int j = min(25000, lim[i] + 1000); j >= 0; j--) {
					if (i) { // 購入して500円玉が増えた場合
						if (chg >= 500) {
							int cur = chg - 500; // 増加
							if (j - cur >= 0 && dp[i - 1][j - cur] != INF) chmin(dp[i][j], dp[i - 1][j - cur] + p[t]);
						}
						else {
							int cur = 500 - chg; // 減少
							if (j + cur <= 25000 && dp[i - 1][j + cur] != INF) chmin(dp[i][j], dp[i - 1][j + cur] + p[t]);
						}
					}
					// 購入して500円玉が増えなかった場合
					if (chg < 500 && j - chg >= 0 && dp[i][j - chg] != INF) chmin(dp[i][j], dp[i][j - chg] + p[t]);
					
					//小銭j円が多すぎて困ることはない
					if (j) chmin(dp[i][j-1], dp[i][j]);
				}
			}
		}
		pii ans;
		for (int i = N; i >= 0; i--) {
			if (dp[i][0] == INF) continue;
			ans = pii(i, dp[i][0]);
			break;
		}
		
		if (debug) printf("@ ");
		printf("%d %d\n", ans.fi, ans.se);
	}
	return 0;
}


Measured memory_bytes: 13004
#include <iostream>
#include <cmath>

using namespace std;

int main(){
  double d,w,h;
  int x[3];
  int n;
  double r;
  while(1){
    cin >> d >> w >> h;
    if(d==0&&w==0&&h==0){
      return 0;
    }
    cin >> n;
    x[0]=pow((pow(d,2)+pow(w,2)),0.5)/2;
    x[1]=pow((pow(w,2)+pow(h,2)),0.5)/2;
    x[2]=pow((pow(d,2)+pow(h,2)),0.5)/2;
    int min=100000000;
    for(int i=0;i<3;i++){
      if(min>=x[i]){
        min=x[i];
      }
    }
    
    for(int i=0;i<n;i++){
      cin >> r;
      if(r>min){
        cout << "OK" <<endl;
      }else{
        cout << "NA" <<endl;
      }
    }
  }
}
  

Measured memory_bytes: 3300
N,A,B = gets.split.map(&:to_i)

begin
  fail if A*B < N
  ss = [B]
  nn = N - B
  fail if nn < 0
  if A == 1
    fail if nn > 0
  else
    fail if nn == 0
    a = A-1
    while a > 0
      fail if nn < a
      if nn % a == 0 && nn/a<= B
        ss += Array.new(a, nn/a)
        break
      end
      r = [B, nn - (a-1)].min
      ss << r
      nn -= r
      a -= 1
    end
    #p [ss.size, ss.inject(:+), ss[-3..-1]]

    
  end
  #p ss.inject(:+)
  arr = (1..N).to_a
  t = 0
  ss.each{ |s|
    if s > 1
      arr[t,s] = arr[t,s].reverse
    end
    t += s
  }
  puts arr.join(" ")
rescue => e
  $stderr.puts e
  p -1; exit
end



Measured memory_bytes: 78032
module maze_master;

import std.stdio;
import std.algorithm;
import std.container.dlist;
import std.typecons;

alias Vector2 = Tuple!(int, "x", int, "y");
alias V2List = DList!Vector2;

int h, w;
char[20][20] maze;
int[Vector2[2]] moves;
bool[20][20] visited;

void bfs(Vector2 start, V2List ps, int depth = 1)
{
    if (ps.empty)
        return;
    V2List vs;
    foreach (p; ps)
    {
        foreach (d; [[0, -1], [1, 0], [0, 1], [-1, 0]])
        {
            auto dx = d[0], dy = d[1];
            auto cx = p.x + dx, cy = p.y + dy;
            if (cx < 0 || cx >= w || cy < 0 || cy >= h || maze[cy][cx] == '#' || visited[cy][cx])
                continue;
            visited[cy][cx] = true;
            auto to = Vector2(cx, cy);
            Vector2[2] key = [start, to];
            moves[key] = depth;
            vs.insertBack(to);
        }
    }
    bfs(start, vs, depth + 1);
}

void main(string[] args)
{
    readf("%d %d\n", &h, &w);
    foreach (y; 0 .. h)
    {
        foreach (x; 0 .. w)
        {
            readf("%c", &maze[y][x]);
        }
        readln();
    }

    foreach (y; 0 .. h)
    {
        foreach (x; 0 .. w)
        {
            if (maze[y][x] == '#')
                continue;
            visited = visited.init;
            visited[y][x] = true;
            auto start = Vector2(x, y);
            bfs(start, V2List(start));
        }
    }

    debug
    {
        maze.each!(writefln);
        foreach (entry; moves.byKeyValue)
        {
            writeln(entry.key);
            writeln(entry.value);
        }
    }

    writefln("%d", moves.byValue.maxElement);
}


Measured memory_bytes: 28124
package main

import (
	"fmt"
)

func main() {

	var dice = make([]int, 7)

	fmt.Scan(&dice[1], &dice[2], &dice[3], &dice[4], &dice[5], &dice[6])

	var throw string

	fmt.Scan(&throw)

	for _, v := range throw {
		tmp := 0

		switch v {
		case 'N':
			tmp = dice[6]
			dice[6] = dice[5]
			dice[5] = dice[1]
			dice[1] = dice[2]
			dice[2] = tmp
			break
		case 'E':
			tmp = dice[6]
			dice[6] = dice[3]
			dice[3] = dice[1]
			dice[1] = dice[4]
			dice[4] = tmp
			break
		case 'S':
			tmp = dice[6]
			dice[6] = dice[2]
			dice[2] = dice[1]
			dice[1] = dice[5]
			dice[5] = tmp
			break
		default:
			tmp = dice[6]
			dice[6] = dice[4]
			dice[4] = dice[1]
			dice[1] = dice[3]
			dice[3] = tmp
			break
		}
	}

	fmt.Println(dice[1])
}



Measured memory_bytes: 1148
//#define _USE_MATH_DEFINES
//#pragma comment(linker, "/stack:200000000")
//#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
using namespace std;
#pragma GCC diagnostic ignored "-Wmissing-declarations"
#define FINAL_OUT(x) {cout << (x) << '\n'; exit(0); }
inline int safe_mul(const int x, const int y) __attribute__ ((warn_unused_result));


int main()
{
//    freopen("in.txt","r", stdin);
//    freopen("out.txt", "w", stdout);
//    cout << fixed << setprecision(20);
    ios_base::sync_with_stdio(false);
    cin.tie(0);

    int n,a,b;
    cin >> n >> a >> b;
    cout << min(n * a, b) << endl;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int ans,cnt;
int N,M;
int used[1<<17];
main()
{
	cin>>N>>M;
	for(int i=0;i<M;i++)
	{
		int p;string s;
		cin>>p>>s;
		if(s=="AC")
		{
			if(used[p]>=0)
			{
				cnt+=used[p];
				used[p]=-1;
				ans++;
			}
		}
		else
		{
			if(used[p]>=0)
			{
				used[p]++;
			}
		}
	}
	cout<<ans<<" "<<cnt<<endl;
}


Measured memory_bytes: 640
from collections import deque
h, w = map(int, input().split())
s = []
for _ in range(h):
    s.append(input())
dist = [[-1 for i in range(w)] for j in range(h)]
dist[0][0] = 0
queue = deque([[0, 0]])
while len(queue) != 0:
    now = queue.popleft()
    if now[1] != w-1:
        if dist[now[0]][now[1]+1] == -1 and s[now[0]][now[1]+1] == ".":
            dist[now[0]][now[1]+1] = dist[now[0]][now[1]] + 1
            queue.append([now[0],now[1] + 1])
    if now[0] != h-1:
        if dist[now[0] + 1][now[1]] == -1 and s[now[0]+1][now[1]] == ".":
            dist[now[0]+1][now[1]] = dist[now[0]][now[1]] + 1
            queue.append([now[0] + 1,now[1]])
    if now[1] != 0:
        if dist[now[0]][now[1]-1] == -1 and s[now[0]][now[1]-1] == ".":
            dist[now[0]][now[1]-1] = dist[now[0]][now[1]] + 1
            queue.append([now[0],now[1] - 1])
    if now[0] != 0:
        if dist[now[0]-1][now[1]] == -1 and s[now[0]-1][now[1]] == ".":
            dist[now[0]-1][now[1]] = dist[now[0]][now[1]] + 1
            queue.append([now[0] -1 ,now[1]])


if dist[h-1][w-1] == -1:
    print(-1)
else:
    length = dist[h-1][w-1] + 1
    ans = 0
    for i in range(h):
        for j in range(w):
            if s[i][j] == ".":
                ans += 1
    ans -= length
    print(ans)

Measured memory_bytes: 3316
#include <stdio.h>
int main() {
	int box[3][3];
	for (int i = 0; i < 3; i++)
	{
		for (int j = 0; j < 3; j++)
		{
			scanf("%d",&box[i][j]);
		}
	}
	int tc;
	scanf("%d",&tc);
	int bingo[10];
	for (int i = 0; i < tc; i++)
	{
		scanf("%d",&bingo[i]);	
	}
	int ctr[3][3] = {0};
	for (int i = 0; i < tc; i++)
	{
		for (int j = 0; j < 3; j++)
		{
			for (int k = 0; k < 3; k++)
			{
				if (bingo[i] == box[j][k])
				{
					ctr[j][k]++;
				}
			}	
		}
	}
	if (ctr[0][0] > 0 && ctr[0][1] > 0 && ctr[0][2])
	{
		printf("Yes\n");
	}
	else if (ctr[1][0] > 0 && ctr[1][1] > 0 && ctr[1][2])
	{
		printf("Yes\n");
	}
	else if (ctr[2][0] > 0 && ctr[2][1] > 0 && ctr[2][2])
	{
		printf("Yes\n");
	}
	else if (ctr[0][0] > 0 && ctr[1][0] > 0 && ctr[2][0])
	{
		printf("Yes\n");
	}
	else if (ctr[0][1] > 0 && ctr[1][1] > 0 && ctr[2][1])
	{
		printf("Yes\n");
	}
	else if (ctr[0][2] > 0 && ctr[1][2] > 0 && ctr[2][2])
	{
		printf("Yes\n");
	}
	else if (ctr[0][0] > 0 && ctr[1][1] > 0 && ctr[2][2])
	{
		printf("Yes\n");
	}
	else if (ctr[0][2] > 0 && ctr[1][1] > 0 && ctr[2][0])
	{
		printf("Yes\n");
	}
	else
	{
		printf("No\n");
	}
	return 0;
}

Measured memory_bytes: 1636
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define cinf(n,x) for(int i=0;i<(n);i++)cin>>x[i];
#define max3(a,b,c) max(max(a,b),c)
#define min3(a,b,c) min(min(a,b),c)
#define ft first
#define sc second
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define all(v) (v).begin(),(v).end()
#define mod 1000000007
using namespace std;
typedef long long ll;
template<class T> using V=vector<T>;
using Graph = vector<vector<int>>;
using P=pair<ll,ll>;
typedef unsigned long long ull;
typedef long double ldouble;
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; }
//V,P(大文字)使用不可

const ll INF=1e18;

signed main(){
    int n;
    cin>>n;
    vector<double> x(n),y(n);
    rep(i,n) cin>>x[i]>>y[i];
    vector<int> a(n);
    rep(i,n) a[i]=i;
    double ans=0;
    do{
        for(int i=0;i<n-1;i++){
            ans+=sqrt((x[a[i]]-x[a[i+1]])*(x[a[i]]-x[a[i+1]])+(y[a[i]]-y[a[i+1]])*(y[a[i]]-y[a[i+1]]));
        }
    }while(next_permutation(all(a)));
    int v=1;
    for(int u=1;u<=n;u++) v*=u;
    cout<<fixed<<setprecision(10)<<(double)ans/v<<endl;
}

Measured memory_bytes: 256