akhauriyash/Code-Regression huggingface dataset:
import java.util.*;

public class Main {
    public static void main(String args[]) {
        
        Scanner sc = new Scanner(System.in);
        
        int h = Integer.parseInt(sc.next());
        int n = Integer.parseInt(sc.next());
        
        int sum = 0;
        
        Integer[] array = new Integer[n];
        for(int i = 0; i < n; ++i) {
            int num = Integer.parseInt(sc.next());
            array[i] = num;
            sum += num;
        }
        
        if(sum >= h) System.out.println("Yes");
        else System.out.println("No");
    }
}

Measured memory_bytes: 49200
#include <iostream>
#include <iomanip>
#include <vector>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <cstring>
#include <map>

#define rep(i, N) for (int i = 0; i < (int)N; i++)
using namespace std;
typedef long long ll;
const ll LLINF = 9223372036854775807;
const int MOD = 1000000007;

int main() {
  string s; cin >> s;
  vector<char> result;
  for (auto i: s) {
    if (i=='B') { if(!result.empty()) result.pop_back(); }
    else result.push_back(i);
  }
  for (auto x: result) cout << x; cout << endl;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  cin.tie(NULL);
  ios::sync_with_stdio(false);
  int n,sum[5];
  cin>>n;
  for(int i=0;i<4;i++){
    sum[i]=n%10;
    n/=10;
  }
  if(sum[0]==sum[1] && sum[1]==sum[2]) cout<<"Yes"<<'\n';
  else if(sum[1]==sum[2] && sum[2]==sum[3]) cout<<"Yes"<<'\n';
  else cout<<"No"<<'\n';
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
//NOT TO SUBMIT IN WRONG PLACE OR IN WRONG COMPILER
//ABC, task, 2020/04/29
//ms,
/*
*/

int main(void){
  string S;
  vector<int> rmnd(2019);
  int digit;
  int tmp_rmnd;

  cin >>S;

  //initialize
  tmp_rmnd = 0;
  digit = 1;
  for(int i=0;i<2019;i++) rmnd.at(i)=0;
  rmnd.at(0) = 1;

  //dp
  for(int i=S.size()-1; 0<=i; i--){
    //calculate mod(law:2019)
    tmp_rmnd += ((S.at(i)-'0')*digit)%2019;
    tmp_rmnd %= 2019;
    rmnd.at(tmp_rmnd)++;

    //renew digit
    digit *= 10;
    digit %= 2019;
  }

  //count
  int ans = 0;
  for(int i=0;i<2019;i++){
    ans += (rmnd.at(i)*(rmnd.at(i)-1))/2;
  }

  cout <<ans <<endl;
  return 0;
}
/*
10と2019は互いに素。
動的計画法。
10^200000はさすがに整数として計算機で扱えないことに注意。

*/


Measured memory_bytes: 3776
#include<stdio.h>
int main() { 
int a , b; 
scanf("%d%d",&a,&b);
int r = 0; 
for(int i = a ; i <= b; i++) { 
int s = i % 10 , t = i / 10000 % 10;
int u = i / 10 % 10 , v = i / 1000 % 10; 
if( s == t&&u == v) r++;
} 
printf("%d\n" , r );
}

Measured memory_bytes: 128
n, k = map(int, input().split())
A = list(map(int, input().split()))
ikisaki = {}
for i in range(1, n+1):
    ikisaki[i] = A[i-1]

head = [1]
visited = set([1])
next_visit = ikisaki[1]

#print(ikisaki)

while next_visit not in visited:
    visited.add(next_visit)
    head.append(next_visit)
    next_visit = ikisaki[next_visit]

roop_back_to = next_visit
for idx, num in enumerate(head):
    if num == roop_back_to:
        roop = head[idx:]

#print(roop_back_to)
#print(head)
#print(roop)


syuki = len(roop)
if k < len(head):
    print(head[k])
else:
    k -= len(head)
    print(roop[k % syuki])

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

int main() {
  long long a,b,c;
  cin >> a >> b >> c;
  
  long long eaten = 0;
  
  if(a + b + 1 >= c){
    eaten = b + c;
  } else {
    eaten = (a + b + 1) + b;
  }
  cout << eaten << endl;
}



Measured memory_bytes: 256
#include<iostream>
 
using namespace std;
 
int main(){
        int n, x;
		int count;
 
        while(1){
			cin>>n>>x;
			count = 0;
            if(n==0 && x==0)
				break;
            for(int i=1;i<=n;i++){
                    for(int j=i+1;j<=n;j++){
                            for(int k=j+1;k<=n;k++){
                                    if(i+j+k==x)
										count++;
                            }
                    }
            }
            cout<<count<<endl;
        }
	return 0;
}

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

const int MAX = 1000001;
int b[MAX]{};

int main(){
    int N;
    cin >> N;
    int A[N];
    set<int> s;
    for(int i = 0; i < N;i++){
        cin >> A[i];
        b[A[i]]++;
        s.insert(A[i]);
    }
    bool flag[MAX]{};
    for(int i:s){
        for(int j = 2; j < MAX; j++){
            if(i * j >= MAX)break;
            flag[i*j] = true;
        }
    }
    int ans = 0;
    for(int i  = 0; i < N;i++){
        if(b[A[i]]==1 && !flag[A[i]])ans++;
    }
    cout << ans << endl;
    return 0;
    
}


Measured memory_bytes: 17700
#include <bits/stdc++.h>
#ifdef HIRO
#define d(f_, ...) printf((f_), ##__VA_ARGS__)
#else
#define d(f_, ...)
#endif

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<long long> vll;
typedef queue<int> qi;
typedef queue< pair<int, int> > qp;
#define mp make_pair
#define pi 3.14159265358979323846
#define MAX max_element
#define MIN min_element
#define all(v) v.begin(), v.end()
#define gt(T) greater<T>()
#define sum(v) accumulate(v.begin(), v.end(), 0)
#define uni(v) do{ \
  sort(v.begin(), v.end()); \
  decltype(v)::iterator result = unique(v.begin(), v.end()); \
  v.erase(result, v.end()); \
}while(0)
#define fi(init, n) for(int i = init; i < n; ++i)
#define fj(init, n) for(int j = init; j < n; ++j)
#define fk(init, n) for(int k = init; k < n; ++k)
#define zero(x) memset(x, 0, sizeof(x))
#define negative(x) memset(x, ~0, sizeof(x))
const ll MOD = 1e9 + 7;
const int INF = 1e9;
const int di[] = { 0, 1, 0, -1 };
const int dj[] = { 1, 0, -1, 0 };

template<typename T>
T gcd(T a, T b) {
	return b ? gcd(b, a % b) : a;
}
template<typename T>
T lcm(T a, T b) {
	return a * b / gcd(a, b);
}
template<typename T>
int finder(vector<T> vec, T number) {
	auto itr = find(vec.begin(), vec.end(), number);
	size_t index = distance(vec.begin(), itr);
	if (index != vec.size()) return 1;
	else return 0;
}
ll frac(ll n){
	if (n == 0) return 1;
	return (n * frac(n - 1)) % MOD;
}
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;
}

ll dp[101][100001];
int main(int argc, char** argv) {
#ifdef HIRO
  string quiz(argv[1]);
  string id(argv[2]);
  string filename("input/" + quiz + "/" + id + ".txt");
  ifstream fin(filename);
  if (fin.peek() == ifstream::traits_type::eof()) {
    cout << "No input.";
    return 0;
  }
  ifstream cin(filename);
  std::cin.rdbuf(cin.rdbuf());
#endif
  ll ans = 0;
  // ll n;
  // cin >> n;
  ll n, w;
  cin >> n >> w;
  // ll n, m, k;
  // cin >> n >> m >> k;
  ll wei[n], v[n];
  fi(0, n)
    cin >> wei[i] >> v[i];
  fi(0, n)
    fj(0, w + 1) {
      // if(wei[i] > w) continue;
      if(wei[i] <= j) {
        chmax(dp[i + 1][j], dp[i][j - wei[i]] + v[i]);
      }
      // chmax(dp[i + 1][w], max(dp[i][w], dp[i][w - wei[i]] + v[i]));
      chmax(dp[i + 1][j], dp[i][j]);
    }
  cout << dp[n][w] << endl;
  // cout << ans << endl;
  return 0;
}



Measured memory_bytes: 78336
import sys
for line in sys.stdin:
    a,b,c = line.split()
    a,c = int(a), int(c)
    p = '+-*/?'.index(b)
    if p == 0: a += c
    elif p == 1: a -= c
    elif p == 2: a *= c 
    elif p == 3: a /= c
    elif p == 4: break
    print a

Measured memory_bytes: 4224
import java.util.*;

public class Main{
  public static void main(String[]args){
    Scanner sc = new Scanner(System.in);
    int A = Integer.parseInt(sc.next());
    int B = Integer.parseInt(sc.next());
    
    int ans = 0;
    for(int i = A; i <= B; i++){
      int n = i;
      int j =0 ;
      j += (n%10) * 10000;
      n /= 10;
      j += (n%10) * 1000;
      n /= 10;
      j += (n%10) * 100;
      n /= 10;
      j += (n%10) * 10;
      n /= 10;
      j += n%10;
      
      if(i == j){
        ans++;
      }
    }
    System.out.println(ans);
  }
}

Measured memory_bytes: 23892
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <vector>
#include <algorithm>
#include <map>
using namespace std;
#define N 200005

pair<int, int> in[N], tmp[N];

int per[N];
bool vis[N];
char s[N];

void solve() {
	scanf(" %s", s + 1);
	int n = strlen(s+1);
	map<int, int> minBitDp;
	minBitDp[0] = 0;
	int curBit = 0;
	for (int i = 1; i <= n; ++i) {
		curBit ^= (1 << (s[i] - 'a'));
		int mini = 1e9;
		if (minBitDp.count(curBit)) {
			mini = minBitDp[curBit];
		}
		for (int b = 0; b < 26; ++b) {
			int tbit = curBit ^ (1 << b);
			if (minBitDp.count(tbit)) {
				mini = min(mini, minBitDp[tbit]);
			}
		}
		++mini;
		if (i == n) {
			printf("%d\n", mini);
			return;
		}
		if (!minBitDp.count(curBit)) {
			minBitDp[curBit] = mini;
		}
		else {
			minBitDp[curBit] = min(minBitDp[curBit], mini);
		}
	}
}
int main() {
	//freopen("input.txt", "r", stdin);
	solve();
	return 0;
}

Measured memory_bytes: 9856
dxy = [[0, 1], [1, 0], [0, -1], [-1, 0]]

def solve():
    H, W = map(int, raw_input().split())
    s = [raw_input() for i in xrange(H)]
    for y in xrange(H):
        for x in xrange(W):
            if s[y][x] == "#":
                for dx, dy in dxy:
                    nx, ny = x + dx, y + dy
                    if not (0 <= nx < W and 0 <= ny < H):
                        continue
                    if s[ny][nx] == "#":
                        break
                else:
                    return False
    return True

print "Yes" if solve() else "No"


Measured memory_bytes: 2568
#include <bits/stdc++.h>
using namespace std;
using ll = long long int;
using str = string;
using P = pair<int, int>;
using Pll = pair<ll, ll>;
const double PI = 3.141592653589793238;
const ll mod = 1000000007;
#define rep(i, n) for (int i = 0; i < (int)n; i++)
#define REP(i, m, n) for (int i = m; i < (int)n; i++)
#define all(a) (a).begin(), (a).end()
#define allg(a) (a).begin(), (a).end(), greator<>()
#define d20 std::setprecision(20)
#define veci vector<int>
#define vecll vector<long long int>
#define vecb vector<bool>
#define vecd vector<double>
template <typename T>
T lcm(T a, T b)
{
	return a / __gcd(a, b) * b;
}

int main()
{
	int h, w, k;
	cin >> h >> w >> k;
	vector<vector<char>> graph(h, vector<char>(w));
	rep(i, h)
	{
		rep(j, w)
		{
			cin >> graph[i][j];
		}
	}
	ll ans = 0;
	for (int bit = 0; bit < (1 << h); ++bit)
	{
		for (int nbit = 0; nbit < (1 << w); ++nbit)
		{
			ll tmp_sum = 0;
			for (int i = 0; i < h; i++)
			{
				for (int j = 0; j < w; j++)
				{
					if (!(bit & (1 << i)) && !(nbit & (1 << j)))
					{
						if (graph[i][j] == '#')
							tmp_sum++;
					}
				}
			}
			if (tmp_sum == k)
			{
				ans++;
			}
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3628
#include<iostream>
#include<cstring>
#include<algorithm>
using namespace std;
int main()
{
	//freopen("tt.txt","r",stdin);
	string a;
	cin>>a;
	int b;
	b=a.length();
	for(int i=0;i<b;i++)
	{
		if(a[i]==',')
		{
			a[i]=' ';
		}
	}
	cout<<a;
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void) {
  int x1, y1, x2, y2, xp, yp;
  scanf("%d%d%d%d", &x1, &y1, &x2, &y2);
  x2 -= x1, y2 -= y1;
  int q, i;
  scanf("%d", &q);
  for(i = 0; i < q; ++i) {
    scanf("%d%d", &xp, &yp);
    xp -= x1, yp -= y1;
    int op = xp * y2 - yp * x2;
    if(op > 0) printf("CLOCKWISE\n");
    else if(op < 0) printf("COUNTER_CLOCKWISE\n");
    else {
      if(xp * x2 < 0 || yp * y2 < 0) printf("ONLINE_BACK\n");
      else if((x2 > 0 && x2 >= xp) || (y2 > 0 && y2 >= yp) || (y2 < 0 && y2 <= yp) || (x2 < 0 && x2 <= xp)) printf("ON_SEGMENT\n");
      else printf("ONLINE_FRONT\n");
    }
  }
  return 0;
}


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

using namespace std;

typedef long long int ll;

const int MAX = 5e3+7, P = 1e9+7 , I2 = 5e8+4;

int dp[MAX][MAX];
char s[MAX];

int fpow(int b, int p)
{
	ll r = 1ll;
	while(p)
	{
		if(p&1)r *= b, r%=P;
		b = 1ll*b*b%P;
		p>>=1;
	}
	return r;
}

int main()
{
	dp[0][0] = 1;
	for(int i = 1; i<MAX; ++i)
		for(int j = 0; j<=i; ++j)
		{	
			if(j)dp[i][j] = (dp[i][j] + dp[i-1][j-1]%P)%P;
			else dp[i][j] = (dp[i][j] + dp[i-1][j]%P)%P; 
			
			if(j<i)dp[i][j] = (dp[i][j] + 2ll*dp[i-1][j+1]%P)%P;
		}	
	int n;scanf("%d", &n);
	scanf("%s", s);int l = strlen(s);
	//cerr << dp[n][l] << endl;
	printf("%d\n", dp[n][l]);
	
  	return 0;
}


Measured memory_bytes: 96640
import java.util.*;
import java.io.*;
import java.lang.*;
public class Main{
public static void main(String[] args) throws FileNotFoundException, IOException{
       Scanner s=new Scanner(System.in);
      String ss=s.nextLine();
      int i=0,j=ss.length()-1;
      int re=0;
      while(i<j){
      	if(ss.charAt(i)!=ss.charAt(j)){re++;}
      	i++;j--;
      }
      System.out.println(re);
      	
      }
        }
    


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

int main() {
  int n,l; cin >> n >> l;

  int sum = 0;
  vector<int> azi(n);
  rep(i,n){
    int x = ((i+1) + l) - 1;
    sum += x;
    azi.at(i) = x;
  }

  int ans = 0;

  rep(i,n){
    int konkai = sum - azi.at(i);

    if(i == 0){
      ans = konkai;
      continue;
    } else {
      int sakonkai = max(sum,konkai) - min(sum,konkai);
      int sazenkai = max(sum,ans) - min(sum,ans);

      if(sazenkai > sakonkai){
        ans = konkai;
      }
    }
  }

  cout << ans << endl;
}

Measured memory_bytes: 256
import sys

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

in_n = lambda: int(readline())
in_nn = lambda: map(int, readline().split())
in_s = lambda: readline().rstrip().decode('utf-8')
in_nl = lambda: list(map(int, readline().split()))
in_nl2 = lambda H: [in_nl() for _ in range(H)]
in_map = lambda: [s == ord('.') for s in readline() if s != ord('\n')]
in_map2 = lambda H: [in_map() for _ in range(H)]
in_all = lambda: map(int, read().split())


def main():
    N, M = in_nn()
    S = in_s()

    ans = []
    now = N
    while now > 0:
        next = -1
        end = max(0, now - M)
        for i in range(now - 1, end - 1, -1):
            if S[i] == '0':
                next = i
        if next == -1:
            print(-1)
            exit()
        else:
            ans.append(now - next)
            now = next

    ans = ans[::-1]
    print(' '.join(map(str, ans)))


if __name__ == '__main__':
    main()


Measured memory_bytes: 17548
#include <bits/stdc++.h>
using namespace std;  
#define rep(i, a, b) for(ll i = a; i < b; i++)
#define Rep(i, a, b) for(ll i = a; i <= b; i++)
#define repr(i, a, b) for(ll i = b-1; i >= a; i--)
#define _GLIBCXX_DEBUG
#define Vl vector<ll>
#define Vs vector<string>
#define Vp vector<pair<ll, ll>>
using ll = long long;
#define ALL(v) (v).begin(),(v).end()
#define endl "\n"
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define co(x) cout << x << endl
#define coel cout << endl
#define pb push_back
#define sz(v) ((ll)(v).size())
const double pi = acos(-1.0);
const ll MOD = 1e9 + 7;
// const ll INF = 1LL << 60;
const ll INF = 100000000000;
#define pp pair<ll, pair<ll, ll>> 
// #define fi first
// #define se second
 
/*--------------------------------------------------------------------------------

--------------------------------------------------------------------------------*/
priority_queue<ll> pq;
Vl adj[10005];
int col[10005];
ll ans[10005];
ll n; 
#define white 0
#define black 1
ll sum = 0;

void bfs(){
    queue<ll> qu;
    qu.push(1);
    col[1] = black;
    while(!qu.empty()){
        ll u = qu.front(); qu.pop();
        // cout << "now : " <<  u << endl;
        ans[u] = pq.top(); pq.pop();
        rep(i, 0, sz(adj[u])){
            if(col[adj[u][i]]==black) continue;
            qu.push(adj[u][i]);
            col[adj[u][i]] = black;
        }
    }
    sum -= ans[1];
    co(sum);
    Rep(i, 1, n) cout << ans[i] << " \n"[i==n];
}

int main(){
    cin >> n;
    // 隣接リスト
    rep(i, 0, n-1){
        ll a, b; cin >> a >> b;
        adj[a].push_back(b);
        adj[b].push_back(a);
    }
    rep(i, 0, n){
        ll c; cin >> c;
        sum += c;
        pq.push(c);
    }
    // 隣接リストチェック
    // Rep(i, 1, n){
    //     cout << i << ": ";
    //     rep(j, 0, sz(adj[i])){
    //         cout << adj[i][j] << " ";
    //     }
    //     coel;
    // }
    bfs();

    return 0;
}


Measured memory_bytes: 4456
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <math.h>
#include <list>
#include <string>
#include <map>
#include <vector>
#include <stack>
#include <queue>
using namespace std;
#define REPD(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) REPD(i, 0, n)
typedef long long ll;
#define fin(ans) cout << (ans) << '\n'
/*

*/
int main()
{
    ll N,M;
    cin >> N >> M;
    ll H[100100];
    ll cnt = 0;
    int flags[100100];
    ll first, second;
    //フラグの初期化。最初はすべていい景色
    REPD(i, 1, N + 1) 
        flags[i] = 1;

    //1~Nまでに入れた
    REPD(i, 1, N + 1)
        cin >> H[i];
    /*
    どっちかがどっちかより小さかったら小さい方のフラグを0に
    同じ場合は両方のフラグを0に
    */
        REP(i, M)
        {
            cin >> first >> second;
            if (H[first] < H[second])
                flags[first] = 0;
            else if (H[second] < H[first])
                flags[second] = 0;
            else
                flags[first] = flags[second] = 0;
    }

    //数える
    REPD(i,1,N+1) 
        if(flags[i]) 
            cnt++;
    fin(cnt);
    return 0;
}

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

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

  int k;
  string s;

  cin >> k;
  cin >> s;

  if (s.length() <= k) cout << s;
  else {
    s[k] = '\0';
    cout << s.c_str() << "...\n";
  }

  return 0;
}

Measured memory_bytes: 3628
#include"bits/stdc++.h"

using namespace std; 

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef vector<PII> VPII;
typedef long long LL;
typedef priority_queue<int> PQ_DESC;
typedef priority_queue<int, vector<int>, greater<int>> PQ_ASC;
typedef priority_queue<PII> PQ_DESC_PII;
typedef priority_queue<PII, vector<PII>, greater<PII>> PQ_ASC_PII;

#define ALL(c) (c).begin(),(c).end()
#define PB push_back
#define MP make_pair
#define SORT_ASC(c) sort(ALL(c))
#define SORT_DESC(c) sort(ALL(c), greater<typeof(*((c).begin()))>())
#define SIZE(a) int((a).size())

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define ROF(i,a,b) for(int i=(b-1);i>=(a);--i)
#define REP(i,n) FOR(i,0,n)
#define REP(i,n) FOR(i,0,n)
#define PER(i,n) ROF(i,0,n)

const double EPS = 1e-10;
const double PI  = acos(-1.0);
const int LARGE_INT = 1e9+100;
const int INF = 2e9+100;
const LL INF_LL = (LL)INF * 300 * 300;

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

void Main()
{
	string s; cin >> s;

	VI c(26,0);
	REP(i,4){
		c[s[i]-'A']++;
	}
	REP(i,26){
		//dump(i)
		//dump(c[i])
		if(c[i] != 0 && c[i] != 2){
			cout << "No" << endl;
			return;
		}
	}

	cout << "Yes" << endl;

	return;
}

int main()
{
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	Main();
    return 0;
}

Measured memory_bytes: 256
//https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8 より
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};
    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };
    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };
    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };
    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };
    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

//

fn run() {
    input! {
        n: usize,
        k: usize,
        p: [(f64, f64); n],
    }
    let calc = |x: f64, y: f64| -> f64 {
        let mut a = vec![];
        for p in p.iter() {
            let dx = x - p.0;
            let dy = y - p.1;
            let d = (dx * dx + dy * dy).sqrt();
            a.push(d);
        }
        a.sort_by(|a, b| a.partial_cmp(&b).unwrap());
        let mut res = 0f64;
        for _ in 0..k {
            res += a.pop().unwrap();
        }
        res
    };
    let f = |x: f64| -> f64 {
        let mut d = -1000f64;
        let mut u = 1000f64;
        for _ in 0..60 {
            let dd = (2.0 * d + u) / 3f64;
            let uu = (d + 2.0 * u) / 3f64;
            if calc(x, dd) > calc(x, uu) {
                d = dd;
            } else {
                u = uu;
            }
        }
        (u + d) * 0.5
    };
    let mut l = -1000f64;
    let mut r = 1000f64;
    for _ in 0..60 {
        let ll = (2.0 * l + r) / 3.0;
        let rr = (l + 2.0 * r) / 3.0;
        let ly = f(ll);
        let ry = f(rr);
        if calc(ll, ly) > calc(rr, ry) {
            l = ll;
        } else {
            r = rr;
        }
    }
    let y = f((l + r) * 0.5);
    let ans = calc(l, y);
    println!("{:.4}", ans);
}

fn main() {
    run();
}



Measured memory_bytes: 1156
#include<iostream>
#include<cstdio>
#include<cstring>
#include<queue>
using namespace std;
const int sj=110;
const int inf=0x7fffffff;
int n,h[sj<<1],s,t,dep[sj<<1],ans,e;
queue<int> q;
struct point 
{
	int xi,yi;
	void in()
	{  scanf("%d%d",&xi,&yi);  }
}p1[sj],p2[sj];
struct B
{
	int ne,v,w;
}b[30000];
void add(int x,int y,int z)
{
	b[e].v=y,b[e].ne=h[x],b[e].w=1,h[x]=e++;
	b[e].v=x,b[e].ne=h[y],b[e].w=0,h[y]=e++;
}
bool bfs(int x)
{
	while(!q.empty())  q.pop();
	memset(dep,0,sizeof(dep));
	q.push(x),dep[x]=1;
	while(!q.empty())
	{
		x=q.front(),q.pop();
		for(int i=h[x];i!=-1;i=b[i].ne)
		    if(b[i].w&&!dep[b[i].v])
		    {
		    	dep[b[i].v]=dep[x]+1;
		    	if(b[i].v==t)  return 1;
		    	q.push(b[i].v);
			}
	}
	return 0;
}
inline int minn(int x,int y)
{
	return x<y?x:y;
}
int dfs(int x,int f)
{
	if(x==t)  return f;
	int ret=0,d;
	for(int i=h[x];i!=-1;i=b[i].ne)
	    if(b[i].w&&dep[b[i].v]==dep[x]+1)
	    {
	    	d=dfs(b[i].v,minn(f,b[i].w));
	    	ret+=d,f-=d;
	    	b[i].w-=d,b[i^1].w+=d;
	    	if(!f)  break;
		}
	if(!ret)  dep[x]=-1;
	return ret;
}
int main()
{
    //freopen("t1.txt","r",stdin);
    scanf("%d",&n);
    t=2*n+1;
    memset(h,-1,sizeof(h));
    for(int i=1;i<=n;i++)  p1[i].in(),add(s,i,1);
    for(int i=1;i<=n;i++)  p2[i].in(),add(i+n,t,1);
    for(int i=1;i<=n;i++)
        for(int j=1;j<=n;j++)
            if(p1[i].xi<p2[j].xi&&p1[i].yi<p2[j].yi)
                add(i,j+n,1);
    while(bfs(s))  ans+=dfs(s,inf);
    printf("%d",ans);
    return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
int main(int argc, char const *argv[])
{
	int a,b,c;
	cin>>a>>b>>c;
	if (a==b && b==c)
	{
		cout<<"Yes"<<endl;
	}
	else {
		cout<<"No"<<endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include<algorithm>
#include<array>
#include<cmath>
#include<iostream>
#include<iomanip>
#include<iso646.h>
#include<queue>
#include<stack>
#include<string>
#include<vector>

#define FOR(counter,initial_value,condition) for(int counter = initial_value; counter < condition;counter++)

int main()
{
	int a, b ,c;
	std::cin >> a >> b >> c;
	std::cout << ((b-a==c-b)?"YES":"NO") << std::endl;
}

Measured memory_bytes: 256
n, m, q = map(int, input().split())
alist = list(map(int, input().split()))
qlist = list(map(int, input().split()))

student = list(range(n))
num = 0

for a in alist:
    if a % 2 == 1:
        num = (num - a) % n
    else:
        num = (num + a) % n
    del student[num]
    n -= 1

for q in qlist:
    if q in student:
        print(1)
    else:
        print(0)



Measured memory_bytes: 20392
#include<bits/stdc++.h>
using ll = long long;
using P = std::pair<ll,ll>;

bool cmp(P a, P b){
        return a.second>b.second;
}

int main(){
        ll n, m;
        scanf("%lld %lld", &n, &m);
        std::priority_queue<ll, std::vector<ll>, std::greater<ll>> que;
        for(ll i=0; i<n; i++){
                ll tmp;
                scanf("%lld", &tmp);
                que.push(tmp);
        }

        std::vector<P> bc(m);
        for(ll i=0; i<m; i++) scanf("%lld %lld", &bc[i].first, &bc[i].second);
        std::sort(bc.begin(), bc.end(), cmp);

        ll ans = 0;
        for(ll i=0; i<m; i++){
                for(ll j=0; j<bc[i].first; j++){
                        ll tmp = que.top(); que.pop();
                        if(tmp>bc[i].second){
                                ans += tmp;
                                goto outer;
                        }
                        ans += bc[i].second;
                        if(que.empty()) goto outer;
                }
        }

        outer:
        while(!que.empty()){
                ans += que.top();
                que.pop();
        }
        printf("%lld\n", ans);
        return 0;
}

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

int main() {
  int N; cin >> N;
  int visible,unvisible;
  vector<int> height(N);
  
  for( int i = 0; i < N; i++ )
    cin >> height.at(i);
  
  for( int i = 1; i < N + 1; i++ ) {
    for( int j = 1; j < i; j++ ) {
      unvisible = 0;
      if( height.at(i-1) < height.at(j-1) ) {
        unvisible++;
        break;
      }
    }
    if( unvisible == 0 )
      visible++;
  }
  cout << visible << endl;
}

Measured memory_bytes: 256
N, K = map(int, input().split())
h = list(map(int, input().split()))
 
DP = [0]
for i in range(N-1):
    act = float("inf")
    for k in range(K):
        if i-k < 0 : continue
        act = min(DP[-1-k] + abs(h[i-k]-h[i+1]) , act)
    DP += [act]
 
print(DP[-1])

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

using namespace std;

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

typedef pair<int, int> P;
int n;

bool ok(vector<int> ts, vector<int> tp, vector<int> tc, vector<int> r) {

	vector<P> s(n), p(n), c(n);

	rep(i, n) {
		s[i] = P(ts[i], i);
	}
	rep(i, n) {
		p[i] = P(tp[i], i);
	}
	rep(i, n) {
		c[i] = P(tc[i], i);
	}

	sort(s.begin(), s.end()); reverse(s.begin(), s.end());
	sort(p.begin(), p.end()); reverse(p.begin(), p.end());
	sort(c.begin(), c.end()); reverse(c.begin(), c.end());

	vector<int> score(n, 0);
	int sk = 0;
	int st = 0;
	rep(i, n) {
		int id = s[i].second;
		if (i == 0) {
			score[id] += r[sk++];
		}
		else {
			if (s[i].first == s[i - 1].first) {
				score[id] += r[sk - 1]; st++;
			}
			else {
				if (st) { sk += st; st = 0; }
				score[id] += r[sk++];
			}
		}
	}
	int pk = 0;
	int pt = 0;
	rep(i, n) {
		int id = p[i].second;
		if (i == 0) {
			score[id] += r[pk++];
		}
		else {
			if (p[i].first == p[i - 1].first) {
				score[id] += r[pk - 1]; pt++;
			}
			else {
				if (pt) { pk += pt; pt = 0; }
				score[id] += r[pk++];
			}
		}
	}
	int ck = 0;
	int ct = 0;
	rep(i, n) {
		int id = c[i].second;
		if (i == 0) {
			score[id] += r[ck++];
		}
		else {
			if (c[i].first == c[i - 1].first) {
				score[id] += r[ck - 1]; ct++;
			}
			else {
				if (ct) { ck += ct; ct = 0; }
				score[id] += r[ck++ + ct];
			}
		}
	}

	vector<P> rank(n);
	rep(i, n) {
		rank[i] = P(score[i], i);
	}
	sort(rank.begin(), rank.end());
	reverse(rank.begin(), rank.end());

	int rt = 0; int rtm = 0;
	for (int i = 0; i < n;i++) {
		if (i == 0) {
			rt = 1;
		}
		else {
			if (rank[i].first == rank[i - 1].first) {
				rtm++;
			}
			else {
				if (rtm) { rt += rtm; rtm = 0; }
				rt++;
			}
		}
		if (rank[i].second == 0) {
			return rt <= 8;
		}
	}
	

}


int main() {

	cin >> n;
	vector<int> r(n);
	rep(i, n) {
		cin >> r[i];
	}

	vector<int> s(n), p(n), c(n);
	rep(i, n) {
		cin >> s[i] >> p[i] >> c[i];
	}
	int ans = 1e9;

	for (int i = 0; i + s[0] <= 101; i++) {
		int ns = i + s[0];
		swap(s[0], ns);
		if (ok(s, p, c, r)) {
			ans = min(i, ans);
		}
		swap(s[0], ns);
	}
	for (int i = 0; i + p[0] <= 101; i++) {
		int ns = i + p[0];
		swap(p[0], ns);
		if (ok(s, p, c, r)) {
			ans = min(i, ans);
		}
		swap(p[0], ns);
	}
	for (int i = 0; i + c[0] <= 101; i++) {
		int ns = i + c[0];
		swap(c[0], ns);
		if (ok(s, p, c, r)) {
			ans = min(i, ans);
		}
		swap(c[0], ns);
	}

	if (ans == 1e9) {
		cout << "Saiko" << endl;
	}
	else {
		cout << ans << endl;
	}

	return 0;
}

Measured memory_bytes: 3100
import java.util.*;

public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int x = N * 800;
    int y = 200 * ((N - (N % 15)) / 15);
    int total = x - y;
    System.out.println(total);
    }
}


Measured memory_bytes: 22608
#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 <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

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();}

//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}

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

//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 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())

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

//constant
//--------------------------------------------
const double PI  = acos(-1.0);

//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
int main(){
    int a , b, c, x, cnt=0;
    cin >> a >> b >> c;
    cnt=a+b+c;
    if(cnt<=21) cout << "win" << endl;
    else cout << "bust" << endl;
    
}

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

int m;
int d;
string days[] = {"Monday","Tuesday","Wednesday","Thursday","Friday","Saturday","Sunday"};

int GetNumDay(int m) {
  switch (m) {
  case 2:
    return 29;
  case 4:
  case 6:
  case 9:
  case 11:
    return 30;
  default:
    return 31;
  }
}

int main() {
  while (1) {
    scanf("%d%d", &m, &d);
    if (m == 0 && d == 0) return 0;

    int tot = d-1;
    for (int i=1; i<m; i++) {
      tot += GetNumDay(i);
    }

    puts(days[(3+tot)%7].c_str());
  }
}

Measured memory_bytes: 2620
#include<stdio.h>
int main()
{	int n,x=1,h[20],i,j,f=1;
	scanf("%d",&n);
	for(i=0;i<n;i++){
		scanf("%d",&h[i]);}
			for(i=n-1;i>0;i--){
				for(j=i-1;j>=0;j--){
				if(h[i]<h[j]){
				f=-1;}
			}
	if(0<f){
	x++;}
	f=1;
	}
	printf("%d",x);
return 0;
} 

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll,string>;
using Map = map<string,ll>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;

ll MOD=1000000007;
ll MAX=200005;

vector<ll> F(MAX,1);
 
void fact(){
    for(ll i=1;i<MAX;i++){
    F[i]=F[i-1]*i%MOD;
    }
return;
}

// mod. m での a の逆元 a^{-1} を計算する
//ただしmとaが互いにその時のみ
long long modinv(long long a, long long m) {
    long long b = m, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}

// a^n mod を計算する
//ただしmとaが互いにその時のみ
long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

int main(){
    fact();
    ll n;
    cin >> n;
    ll a;
    cin >> a;
    ll b;
    cin >> b;

    ll sum=modpow(2,n,MOD);


    ll ans=sum-1+MOD*3;

    ll aa,bb;aa=1;bb=1;
    for(ll i=n;i>n-a;i--){
        aa*=i;
        aa%=MOD;
    ;}
    for(ll i=n;i>n-b;i--){
        bb*=i;
        bb%=MOD;
    ;}

    ll A=aa*modinv(F[a],MOD)%MOD;
    ll B=bb*modinv(F[b],MOD)%MOD;

    cout<<(ans-A-B)%MOD<<endl;

return 0;
}


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

int main(){
	int a, b;
	int answer;
	string op;

	while (true){
		cin >> a >> op >> b;

		if (op == "+"){
			answer = a + b;
		}else if(op == "-"){
			answer = a - b;
		}else if(op == "*"){
			answer = a * b;
		}else if(op == "/"){
			answer = a / b;
		}else if(op == "?"){
			return 0;
		}

		cout << answer << endl;
	}
}

Measured memory_bytes: 3084
#include<iostream>
#include <algorithm>
#include <functional>
#include<vector>
#include<math.h>
#include <assert.h>
#include<bitset>
#include<string>
#include <deque>
#include<queue>
#include <iomanip>
#include<map>
#include <random>
#include<type_traits>
#include<stack>
#include <sstream> 
#include <limits>
#include <numeric>
#include<string.h>
#include<set>
#include <climits>
using namespace std;
typedef unsigned long long ull;
#define ll long long int
static const double PI = 3.141592653589793;
const ll INF = 100000000000000;
ll mod = 1000000007;
//typedef vector<int> V;
//typedef vector<V> VV;
//typedef vector<VV> VVV;


ll  a[1005][1005],cou[1050],used[1030],fin[1030];
int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll n,s,t;
	cin >> n;
	ll ind = 1;
	queue<ll> q;
	for (int i = 1; i <= n; i++)cou[i]++;
	for (int i = 1; i <= n; i++) {
		for (int j = 1; j < n; j++) {
			cin >>a[i][j];
			q.push(i);
		}
	}
	ll u =0;
	//ind
	while (!q.empty()) {
		ll p = q.front();
		q.pop();
		ll q2 = a[p][cou[p]];
		if (fin[p] != 0 || fin[q2] != 0)continue;
		if (a[q2][cou[q2]] == p) {
			ll point = max(used[p], used[q2])+1;
			used[p] = point,used[q2]=point;
			u = max(u, point);

			if (cou[p]<n-1)q.push(p)	,cou[p]++;
			else fin[p]++;
			if (cou[q2]<n - 1)q.push(q2),cou[q2]++;
			else fin[q2]++;
		}
	}
	for (int i = 1; i <= n; i++) {
		if (fin[i] == 0) {
			cout << -1 << endl;
			return 0;
		}
	}
	cout << u << endl;
}


Measured memory_bytes: 16272
#include <bits/stdc++.h>
using namespace std;
//const int MOD = 1e9 + 7;

int main() {
	int d, t, s;
	scanf("%d %d %d", &d, &t, &s);
	if((double)d / s <= (double)t) printf("Yes\n");
	else printf("No\n");
	return 0;
}
//ios_base::sync_with_stdio(false);
//cin.tie(0);
//tod-ngen


Measured memory_bytes: 3756
#include <bits/stdc++.h>
using namespace std;
long long n, W;

long long dp[110][100010];

int main() {
    cin >> n >> W;
    vector<long long> w(n, 0);
    vector<long long> v(n, 0);
    for(int i = 0; i < n; ++i) {
        cin >> w.at(i) >> v.at(i);
    }

    for(int i = 0; i <= n; ++i) {
        for(int j = 0; j <= W; ++j) {
            dp[i][j] = 0;
        }
    }

    for(int i = 0; i < n; ++i) {
        for(int j = 0; j <= W; ++j) {
            if(j+w.at(i) <= W) {
                dp[i+1][j+w.at(i)] = dp[i][j] + v.at(i);
            }

            dp[i+1][j] = max(dp[i+1][j], dp[i][j]);
        }
    }

    cout << dp[n][W] << endl;
}

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

int main() {
  int N;
  cin >> N;
  for (int i{9}; i >= 1; --i) {
    if (N % i == 0 & N / i <= 9) {
      cout << "Yes" << endl;
      return 0;
    }
  }
  cout << "No" << endl;
  return 0;
}


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


#define fs first
#define sc second

using namespace std;

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

ll a[101000];
ll s[101000];
map<ll, ll> m;

int main(){
    int N, M;
    cin >> N >> M;
    for(int i = 0; i < N; i++){
        cin >> a[i];
    }
    s[0] = 0;
    for(int i = 1; i <= N; i++){
        s[i] = s[i-1] + a[i-1];
    }

    ll res = 0;
    for(int i = 0; i <= N; i++){
        ll r = s[i] % M;
        if(m.find(r) == m.end()){
            m[r] = 1;
        }
        else{
            res += m[r];
            m[r]++;
        }
    }

    cout << res << endl;


    return 0;

}


Measured memory_bytes: 5760
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,m,n) for(int i=(m);i<(n);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
using ll = long long;
template <typename T> using posteriority_queue = priority_queue<T, vector<T>, greater<T> >;
const int INF = 0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3f3fLL;
const double EPS = 1e-8;
const int MOD = 1000000007;
// const int MOD = 998244353;
const int dy[] = {1, 0, -1, 0}, dx[] = {0, -1, 0, 1};
const int dy8[] = {1, 1, 0, -1, -1, -1, 0, 1}, dx8[] = {0, -1, -1, -1, 0, 1, 1, 1};
template <typename T, typename U> inline bool chmax(T &a, U b) { return a < b ? (a = b, true) : false; }
template <typename T, typename U> inline bool chmin(T &a, U b) { return a > b ? (a = b, true) : false; }
template <typename T> void unique(vector<T> &a) { a.erase(unique(ALL(a)), a.end()); }
struct IOSetup {
  IOSetup() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(20);
  }
} iosetup;

template <typename Monoid>
struct RMQ {
  RMQ(int sz, const Monoid UNITY) : UNITY(UNITY) {
    init(sz);
    dat.assign((n << 1) - 1, UNITY);
  }

  RMQ(const vector<Monoid> &a, const Monoid UNITY) : UNITY(UNITY) {
    int a_sz = a.size();
    init(a_sz);
    dat.resize((n << 1) - 1);
    REP(i, a_sz) dat[n - 1 + i] = a[i];
    for (int i = n - 2; i >= 0; --i) dat[i] = min(dat[(i << 1) + 1], dat[(i << 1) + 2]);
  }

  void update(int node, Monoid val) {
    node += n - 1;
    dat[node] = val;
    while (node > 0) {
      node = (node - 1) >> 1;
      dat[node] = min(dat[(node << 1) + 1], dat[(node << 1) + 2]);
    }
  }

  Monoid query(int a, int b) { return query(a, b, 0, 0, n); }

  int find(int a, int b, Monoid val) { return find(a, b, val, 0, 0, n); }

  Monoid operator[](const int idx) const { return dat[idx + n - 1]; }

private:
  int n = 1;
  const Monoid UNITY;
  vector<Monoid> dat;

  void init(int sz) { while (n < sz) n <<= 1; }

  Monoid query(int a, int b, int node, int left, int right) {
    if (right <= a || b <= left) return UNITY;
    if (a <= left && right <= b) return dat[node];
    return min(query(a, b, (node << 1) + 1, left, (left + right) >> 1), query(a, b, (node << 1) + 2, (left + right) >> 1, right));
  }

  int find(int a, int b, Monoid val, int node, int left, int right) {
    if (dat[node] > val || right <= a || b <= left) return -1;
    if (right - left == 1) return node - (n - 1);
    int res_l = find(a, b, val, (node << 1) + 1, left, (left + right) >> 1);
    if (res_l != -1) return res_l;
    return find(a, b, val, (node << 1) + 2, (left + right) >> 1, right);
  }
};

int main() {
  int n, x; cin >> n >> x;
  vector<int> a(n); REP(i, n) cin >> a[i];
  RMQ<int> rmq(n * 2, INF);
  REP(i, n) {
    rmq.update(i, a[i]);
    rmq.update(n + i, a[i]);
  }
  ll ans = LINF;
  REP(spell, n) {
    ll now = 1LL * x * spell;
    REP(i, n) now += rmq.query(n + i - spell, n + i + 1);
    chmin(ans, now);
  }
  cout << ans << '\n';
  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;
 
public class Main {
    public static void main(String[] args)
    {
        Scanner stdIn = new Scanner(System.in);
         
        while(true)
        {
            int n = stdIn.nextInt();
            int x = stdIn.nextInt();
             
            if(n==0 && x==0)
            {
                break;
            }
             
            int count = 0;
             
            for(int i=n;i>=3;i--)
            {
                for(int j=i-1;j>=2;j--)
                {
                    for(int k=j-1;k>=1;k--)
                    {
                        if((i+j+k)==x)
                        {
                            count++;
                        }
                    }
                }
            }
             
            System.out.println(count);
        }
    }
}


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

int main(){
    int n,m;
    cin >> n >> m;
    ll ans=0ll;
    priority_queue<int> prices;
    rp(i,n){
        int a;
        cin >> a;
        prices.push(a);
        ans += (ll)a;
    }
    rp(i,m){
        int b=prices.top(); prices.pop();
        ans -= (ll)b-b/2;
        prices.push(b/2);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 892
#include <stdio.h>

int		min(int *pab, int AB)
{
	int		a;

	a = pab[0];
	if (AB == 1)
		return (pab[0]);
	for (int i = 0; i < AB - 1; i++)
	{
		if (pab[i] < pab[i + 1])
			a = pab[i];
	}
	return (a);
}

int		main(void)
{
	int		A;
	int		B;
	int		M;
	int		i;

	scanf("%d%d%d", &A, &B, &M);
	int		pA[A];
	int		pB[B];
	int		xyc[M][3];
	i = -1;
	while (++i < A)
		scanf("%d", &pA[i]);
	i = -1;
	while (++i < B)
		scanf("%d", &pB[i]);
	i = -1;
	while (++i < M)
	{
		scanf("%d", &xyc[i][0]);//Aの割引対象
		scanf("%d", &xyc[i][1]);//Bの割引対象
		scanf("%d", &xyc[i][2]);//割引額
	}
	int		minAB = min(pA, A) + min(pB, B);
	int		minxyc;
	i = 0;
	while (i < M)
	{
		minxyc = pA[xyc[i][0] - 1] + pB[xyc[i][1] - 1] - xyc[i][2];
		if (minxyc < minAB)
			minAB = minxyc;
		i++;
	}
	printf("%d", minAB);
	return (0);
}


Measured memory_bytes: 2176
#include<stdio.h>
int main(viud) {
    int N, n[200], k, m, i, j, l, keyn[200];
    scanf("%d %d", &N, &m);
    for ( i = 0; i < 2 * N; i++ ) n[i] = i + 1; 
    for ( i = 0; i < m; i++ ) {
        scanf("%d", &k);
        for ( j = 0; j < 2 * N; j++ ) keyn[j] = n[j];
        /*for ( j = 0; j < 2 * N; j++ ) printf("%d\n", n[j]);*/
        if ( k == 0 ) {
            l = 0;
            for ( j = 0; j < 2 * N; j+=2 ) {
                n[j] = keyn[l];
                n[j + 1] = keyn[N + l];
                l++;
            }
            /*for ( j = 0; j < 2 * N; j++ ) printf("%d\n", n[j]);*/
        }
        else {
            j = 0;
            for ( l = 0; l < 2 * N - k; l++ ) n[l] = keyn[k + l];
            for ( l ; l < 2 * N; l++ ) {n[l] = keyn[j]; j++;}
            /*for ( l = 0; l < 2 * N; l++ ) printf("%d\n", n[l]);*/
        }
    }
    for ( i = 0; i < 2 * N; i++ ) printf("%d\n", n[i]);
    return 0;
}

Measured memory_bytes: 1856
#include <iostream>
#include <algorithm>
#include <utility>
#include <vector>
#include <string>

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define REP(i, n) for (int i = 0; i < (n); i++)
#define RREP(i, n) for (int i = (n) - 1; i >= 0; i--)
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define RFOR(i, a, b) for (int i = (a); i > (b); i--)
#define ALL(a) (a).begin(), (a).end()

int main() {
    int a, b, c;
    cin >> a >> b >> c;
    cout << a + b + c - max(a, max(b, c)) << endl;
    return 0;
}

Measured memory_bytes: 256
import Control.Applicative

type Data = (Int, Int, Int, Int)

type Floor = [Int]

type Building = [Floor]

type Problem = [Data]

type Result = [Building]

calcValue :: Problem -> Int -> Int -> Int -> Int

calcValue xs b f r
    = sum $ [vx | (bx, fx, rx, vx) <- xs, bx == b, fx == f, rx == r]

solve :: Problem -> Result

solve xs
    = [[[calcValue xs b f r | r <- [1..10]] | f <- [1..3]] | b <- [1..4]]

input :: IO Problem

input
    = do
        n <- read <$> getLine
        xs <- inputData n []
        return xs
        
inputData :: Int -> Problem -> IO Problem

inputData 0 xs
    = return xs
    
inputData n xs
    = do
        [b, f, r, v] <- words <$> getLine
        inputData (n - 1) $ (read b, read f, read r, read v) : xs
    
output :: Result -> IO ()

output xs
    = putStr $ concat $ init $ concat [[out] ++ [separate] | out <- [outputBuilding b | b <- xs]]
    
outputBuilding :: Building -> String

outputBuilding b
    = concat [concat [" " ++ show r | r <- f] ++ "\n" | f <- b]
    
separate :: String

separate
    = replicate 20 '#' ++ "\n" 
    
main :: IO ()

main = output =<< solve <$> input

Measured memory_bytes: 4264
#include <iostream>
#include <iomanip>
#include <cmath>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <memory>
#include <cstring>
#include <cassert>
#include <numeric>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <cctype>
#include <unordered_map>
#include <unordered_set>
using namespace std;

#define REP2(i, m, n) for (int i = (int)(m); i < (int)(n); i++)
#define REP(i, n) REP2(i, 0, n)
#define ALL(S) (S).begin(), (S).end()

template <typename T, typename E>
ostream &operator<<(std::ostream &os, const std::pair<T, E> &p){
  return os << "(" << p.first << ", " << p.second << ")";
}

typedef long long ll;

const int RMAX = 200010;
ll BIT[RMAX];

void add(int pos, ll x){
  while (pos < RMAX){
    BIT[pos] += x;
    pos += -pos & pos;
  }
}

ll sum(int pos){
  ll res = 0;
  while (pos > 0){
    res += BIT[pos];
    pos -= -pos & pos;
  }
  return res;
}
int main(){
  ios::sync_with_stdio(false);
  ll A, B, P;
  while (cin >> A>> B >> P && A + B + P){
    memset(BIT, 0, sizeof(BIT));
    vector<string> numbers;
    for (ll i = A; i <= B; i++) numbers.push_back(to_string(i));
    sort(ALL(numbers));

    ll res = 0;

    REP(i, numbers.size()){
      ll offset = atoi(numbers[i].c_str()) - A;
      ll dp_value = (sum(offset + 1) + 1) % P;
      add(offset + 1, dp_value);
      
      res += dp_value;
      res %= P;
    }
    cout << res << endl;
  }
  return 0;
}

Measured memory_bytes: 8288
#include <iostream>
//#include <iomanip>
//#include <string>
#include <vector>
//#include <algorithm>
//#include <utility>
//#include <set>
//#include <map>
#include <queue>
//#include <deque>
//#include <bitset>
//#include <math.h>
using namespace std ;
using ll = long long ;
//using ld = long double ;
using vll = vector<ll> ;
//using vvll = vector<vll> ;
//using vc = vector<char> ;
//using vvc = vector<vc> ;
//using vb = vector<bool> ;
//using vvb = vector<vb> ;
//using pll = pair<ll,ll> ;
//#define all(v) v.begin(),v.end()
//ll mod = 1000000007 ;
//long double pie = acos(-1) ;
ll INF = 1000000000000 ;

//void yorn(bool a){if(a) cout << "Yes" << endl ; else cout << "No" << endl ;}
//void YorN(bool a){if(a) cout << "YES" << endl ; else cout << "NO" << endl ;}
//ll gcd(long long a,long long b){if(b==0) return a ; return gcd(b,a%b) ;}
//ll lcm(long long a,long long b){return a/gcd(a,b)*b ;}
//ll sa(long long a,long long b){if(a>b) return a-b ; return b-a ;}
//void fix_cout(){cout << fixed << setprecision(20) ;}

int main(){
	ll n ; cin >> n ;
	vll cnt(n+1,INF) ;
	cnt.at(0) = 0 ;
	vll six(11,1) ; for(int i=1;i<11;i++) six.at(i) = six.at(i-1)*6 ;
	vll nine(11,1) ; for(int i=1;i<11;i++) nine.at(i) = nine.at(i-1)*9 ;
	queue<ll> q ;
	q.push(0) ;
	ll a ;
	while(!q.empty()){
		a = q.front() ;
		ll d = cnt.at(a) ;
		q.pop() ;
		for(int i=0;i<11;i++){
			if(a+six.at(i)>n) break ;
			if(cnt.at(a+six.at(i))>d+1){
				cnt.at(a+six.at(i)) = d+1 ;
				q.push(a+six.at(i)) ;
			}
		}
		for(int i=0;i<11;i++){
			if(a+nine.at(i)>n) break ;
			if(cnt.at(a+nine.at(i))>d+1){
				cnt.at(a+nine.at(i)) = d+1 ;
				q.push(a+nine.at(i)) ;
			}
		}
//		cout << a << endl ;
	}
	cout << cnt.at(n) << endl ;
}


Measured memory_bytes: 1152