akhauriyash/Code-Regression huggingface dataset:
/* Don't try to hack it :|
 
            _/﹋\_
            (҂`_´)
            <,︻╦╤─҉- - - - - - - - - - - - - - -
            _/﹋\_
*/

#include <bits/stdc++.h>
#define ll long long 
#define all(v) v.begin() , v.end()
#define pb push_back
#define F first
#define S second
#define mp make_pair
#define tr(con) for(auto it = con.begin(); it!= con.end() ; it++)
#define INF 1e9+7   // 1 * 10^9+ 7
#define rep(i,l,r) for(ll i=l;i<=r;i++)
#define fo(i,n) for(ll i=0;i<n;i++)
using namespace std;

int main(){
	
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int a[3];
	int sum = 0;
	for(int i=0;i<3;i++){
		cin >> a[i] ;
		sum += a[i];
	}
	if(sum>=22) cout << "bust";
	else cout << "win";
	return 0;
}


Measured memory_bytes: 256
// #include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <iomanip>
#include <utility>
#include <tuple>
#include <functional>
#include <bitset>
#include <cassert>
#include <complex>
#include <stdio.h>
#include <time.h>
#include <numeric>
#include <unordered_map>
#include <unordered_set>

using namespace std;

#define vv vector< vector< int > >
#define ll long long
#define ALL(a) (a).begin(), (a).end()
const long long mod = 1000000000 + 7;
const long long INF = 9e18;
const double PI = 3.14159265358979323846;

ll gcd(ll a, ll b){if (b == 0) return a;return gcd(b, a % b);}
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }


int main(){
    ll int N, A, B, ans;
    cin >> N >> A >> B;
    ans = N / (A + B) * A;
    ll int r = N % (A + B);
    ans += min(r, A);
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <map>
#include <set>
#include <list>
#include <cstdio>
#include <cmath>
#include <deque>
#include <stack>
#include <bitset>
#include <cctype>
#include <string>
#include <vector>
#include <cstdlib>
#include <cstring>
#include <iomanip>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <functional>

using namespace std;

#define fr first
#define sc second
#define mp make_pair

typedef long long int64;
typedef pair< int, int > iP;
typedef pair< iP, int > iiP;

const int INF = 2 << 28;
const double EPS = 1e-10;

#define MAX 300000

int main() {
    
    vector< int > msp;
    vector< bool > pf(MAX, true);
    for(int i = 2; i < MAX; i++) {
        if(i % 7 == 1 || i % 7 == 6) msp.push_back(i);
        else pf[i] = false;
    }
    
    for(int i = 0; i < msp.size(); i++) {
        if(pf[msp[i]]) {
            for(int j = msp[i] * 2; j < MAX; j += msp[i]) {
                pf[j] = false;
            }
        }
    }
    
    int N;
    while(cin >> N, N != 1) {
        cout << N << ": ";
        vector< int > res;
        for(int i = 2; i <= N; i++)
            if(!(N % i) && pf[i]) res.push_back(i);
        for(int i = 0; i < res.size(); i++)
            cout << res[i] << (res.size()  - 1 != i ? " " : "\n");
    }
}

Measured memory_bytes: 1628
#include <bits/stdc++.h>
#define ii pair <int , int>
#define is pair <int, string>
#define ll long long
#define pf printf
using namespace std;
vector <int> v,vv;

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

    while(n--){
        int a;
        cin>>a;
        v.push_back(a);
        vv.push_back(0);
    }
    int len=v.size();
    for(int i=0; i<m; i++){
        int a,b;
        cin>>a>>b;

        vv[a-1]=max(vv[a-1],v[b-1]);
        vv[b-1]=max(vv[b-1],v[a-1]);
    }

    int cnt=0;
    for(int i=0; i<len; i++){
        if(v[i]>vv[i]) cnt++;
    }
    cout<<cnt<<endl;

    return 0;
}


Measured memory_bytes: 4268
N=int(input())
n=N
c=1
while True:
  if n-26**c >0:
    n=n-26**c
    c+=1
  else:
    break
for i in range(1,c):
  N=N-26**i
Z=[]
N=N-1
for i in range(c-1):
  tmp = N // 26**(c-1-i)
  Z+=[tmp]
  N = N % 26**(c-1-i)
Z+=[N]
ans=""
for i in range(len(Z)):
  ans+=chr(97+Z[i])
print(ans)

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

using namespace std;

int main() {
    long long len,x=0,maxx=0;
    string s;
    cin >> len>>s;
    for(int i =0; i<len;i++){
        if(s[i]=='I') x++;
        else if(s[i]=='D') x--;
        if(x>maxx){
            maxx=x;
        }
    }
    cout << maxx;
    return 0;
}

Measured memory_bytes: 256
num = int(input())
member = list(map(int, input().split()))
min_num = min(member)
max_num = max(member)
min_hp = 10000000
for i in range(min_num, max_num + 1):
    hp = 0
    for j in member:
        hp += (j - i) ** 2
    
    if hp < min_hp:
        min_hp = hp
print(min_hp)

Measured memory_bytes: 3060
#include <algorithm>
#include <iostream>
#include <vector>
#define REP(i, n) for (int i = 0; i < (n); i++)
using namespace std;

void solve(long long N, long long x, std::vector<long long> a){
    sort(a.begin(), a.end());
    int ans = 0;
    if (a[0] > x) ans = 0;
    else {
        while (x > 0) {
            x -= a[ans];
            if (x >= 0)
                ans++;
            if (ans == N && x > 0) {
                ans--;
                break ;
            }
        }
    }

    cout << ans << '\n';
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    long long N;
    scanf("%lld",&N);
    long long x;
    scanf("%lld",&x);
    std::vector<long long> a(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&a[i]);
    }
    solve(N, x, std::move(a));
    return 0;
}


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

int main(){
        
    int n;
    vector<pair<int,int> > score;
    
    
    while(cin >> n, n!=0 ){
        
        score.clear();
        
        for(int i=0; i<n; i++){
            int id,m,s,sum=0;
            cin >> id;
            for(int j=0; j<4; j++){
                cin >> m >> s;
                sum += m*60 + s;
            }
            score.push_back(make_pair(sum,id));
        }
        
        sort(score.begin(),score.end());
        
        cout << score[0].second << endl;
        cout << score[1].second << endl;
        cout << score[score.size()-2].second << endl;
    }
    return 0;
}


Measured memory_bytes: 3100
#C  judge whether its place is even or odd 
n = int(input())
a = []
for i in range(n):
    a.append(int(input()))
b = a[::]
b.sort()

dic = dict()
for i,v in enumerate(b):
    dic[v]=i

num = 0    
for i,v in enumerate(a):
    ind = dic[v]
    num += ((i-ind)%2)
print(num//2)    




Measured memory_bytes: 19876
#include<iostream>
#include<cstring>
#include<string>
using namespace std;
int main(){
  int h,w,cnt[50][50]={0};
  char mas[50][50];
  cin >> h >> w;
  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++){
      cin >> mas[i][j];
      mas[i][j]-='0';
    }
  }
  for(int i=1;i<h;i++)cnt[i][0]=cnt[i-1][0]+mas[i][0];
  for(int j=1;j<w;j++)cnt[0][j]=cnt[0][j-1]+mas[0][j];
  for(int i=1;i<h;i++){
    for(int j=1;j<w;j++){
      cnt[i][j]=min(cnt[i-1][j],cnt[i][j-1])+mas[i][j];
    }
  }
  cout << cnt[h-1][w-1] << endl;
}

Measured memory_bytes: 1180
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mp make_pair
#define pb push_back
#define flash ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define lb lower_bound
#define ub upper_bound
#define endl '\n'
ll dp[2][2][100];
ll mod=1e9+7;ll d;
ll mo(ll x)
{
    if(x>=0)
    return(x%d);
    else
    return(x%d+d)%d;
}
int main()
{
    flash
    string s;
    cin>>s;ll n=s.size();ll a[n];
    for(ll i=0;i<n;i++)
    {
        a[i]=s[i]-'0';
    }
cin>>d;
  dp[1][0][0] = 1;dp[1][1][0] = 1;
 
    for(ll i = n-1; i >=0 ; i--) {
        for(ll state = 0; state < 2 ; state++) {
            for(ll sum = 0; sum < d; sum++) {
                if(state) {
                    for(ll x = 0; x <= a[i] ; x++) {
                        dp[0][1][sum] += (x== a[i]) ? dp[1][1][mo(sum-x)]%mod:dp[1][0][mo(sum-x)]%mod;
                    }
                }
                else {
                    for(ll x = 0; x < 10 ; x++) {
                        dp[0][0][sum] += dp[1][0][mo(sum-x)]%mod;
                    }
                }
            }
          }
          if(i!=0)
          {
         for(ll sum=0;sum<d;sum++)
            {
                dp[1][1][sum]=dp[0][1][sum];
                dp[1][0][sum]=dp[0][0][sum];
                dp[0][1][sum]=0;
                dp[0][0][sum]=0;
            }
          }
    }
    dp[0][1][0]--;
    dp[0][1][0]=dp[0][1][0]%mod;
    cout<<dp[0][1][0]<<endl;
}

Measured memory_bytes: 3744
#include <iostream>

int main(){
   int N;
   std::cin >> N;
   int A;
   bool flag = true;
   for(int i=0; i<N; ++i){
      std::cin >> A;
      if(A%2==0){
	 if(!(A%3==0 || A%5==0)) flag = false;
      }
   }
   if(flag) std::cout << "APPROVED" << std::endl;
   else std::cout << "DENIED" << std::endl;

   return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;++i)
#define all(x) (x).begin(),(x).end()
using namespace std;
const int INF=1145141919,MOD=1e9+7;
const int64_t LINF=8931145141919364364,LMOD=998244353;
// const int dy[]={0,-1,0,1,1,-1,-1,1};
// const int dx[]={1,0,-1,0,1,1,-1,-1};

int main() {
	int64_t a, v; cin >> a >> v;
	int64_t b, w; cin >> b >> w;
	int64_t t; cin >> t;
	if(v <= w) {
		cout << "NO" << '\n';
		return 0;
	}
	int64_t d = abs(a - b);
	int64_t s = abs(v - w);
	if(d <= t * s) {
		cout << "YES" << '\n';
	} else {
		cout << "NO" << '\n';
	}
	return 0;
}

Measured memory_bytes: 3636
H,W,M=map(int,input().split())

DX={}
DY={}
D={}
for i in range(M):
    a,b=map(int,input().split())
    D[(a,b)]=1
    if a not in DX:
        DX[a]=1
    else:
        DX[a]+=1
    if b not in DY:
        DY[b]=1
    else:
        DY[b]+=1

MAXX=0
MXL=[]
for k,v in DX.items():
    if MAXX==v:
        MXL.append(k)
    elif MAXX<v:
        MAXX=v
        MXL=[k]
MAXY=0
MYL=[]
for k,v in DY.items():
    if MAXY==v:
        MYL.append(k)
    elif MAXY<v:
        MAXY=v
        MYL=[k]

ans=MAXX+MAXY-1
for x in MXL:
    for y in MYL:
        if (x,y) not in D:
            print(MAXX+MAXY)
            exit()
print(ans)


Measured memory_bytes: 181312
#include <iostream>
#include <vector>
#include <queue>
#include <set>
#include <functional>
#include <algorithm>
#include <climits>

using namespace std;

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

struct Edge
{
	int to;
	int cost;
};

struct Node
{
	int city_index;
	int total_cost;
	int current_life;

	bool operator >(const Node &a) const
	{
		return total_cost > a.total_cost;
	}
};

int main()
{
	int city_count, initial_life, cooler_count, road_count, start_index, goal_index;
	while (cin >> city_count >> initial_life >> cooler_count >> road_count >> start_index >> goal_index,
		city_count)
	{
		// input
		vector<int> is_cooler(city_count, false);
		REP(i, cooler_count)
		{
			int cooler_index;
			cin >> cooler_index;
			is_cooler[cooler_index] = true;
		}
		vector<vector<Edge>> roads(city_count);
		REP(i, road_count)
		{
			int from, to, cost;
			cin >> from >> to >> cost;
			roads[from].push_back({ to, cost });
			roads[to].push_back({ from, cost });
		}

		// dijkstra
		vector<vector<int>> d(city_count, vector<int>(initial_life + 1, INT_MAX)); // [city_index][current_life] => total_cost
		d[start_index][initial_life] = 0;
		priority_queue<Node, vector<Node>, greater<Node> > pq;
		pq.push({ start_index, 0, initial_life });
		while (true)
		{
			if (pq.empty())
			{
				cout << "Help!" << endl;
				break;
			}
			auto current_node = pq.top(); pq.pop();
			if (current_node.city_index == goal_index)
			{
				cout << current_node.total_cost << endl;
				break;
			}
			for (auto &road : roads[current_node.city_index])
			{
				if (is_cooler[current_node.city_index])
				{
					REP(i, initial_life - current_node.current_life + 1)
					{
						int life = current_node.current_life + i - road.cost;
						if (life < 0)
						{
							continue;
						}
						int cost = current_node.total_cost + road.cost + i;
						if (cost < d[road.to][life])
						{
							d[road.to][life] = cost;
							pq.push({ road.to, cost, life });
						}
					}
				}
				else
				{
					int life = current_node.current_life - road.cost;
					if (life < 0)
					{
						continue;
					}
					int cost = current_node.total_cost + road.cost;
					if (cost < d[road.to][life])
					{
						d[road.to][life] = cost;
						pq.push({ road.to, cost, life });
					}
				}
			}
		}
	}

	return 0;
}

Measured memory_bytes: 1600
import java.util.*;
 
public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        Scanner sc = new Scanner(System.in);
        int X = sc.nextInt();
        if(X >= 30){
            System.out.println("Yes");
        }else{
            System.out.println("No");
        }
    }
}

Measured memory_bytes: 35676
<<NOTE.!
チェスボードの描画

  以下のような、たてH cm よこ W cm のチェック柄の長方形を描くプログラムを作成して下さい。

  #.#.#.#.#.
  .#.#.#.#.#
  #.#.#.#.#.
  .#.#.#.#.#
  #.#.#.#.#.
  .#.#.#.#.#

  上図は、たて 6 cm よこ 10 cm の長方形を表しています。

  長方形の左上が "#" となるように描いて下さい。

Input
  入力は複数のデータセットから構成されています。各データセットの形式は以下のとおりです：

  H W

  H, W がともに 0 のとき、入力の終わりとします。

Output
  各データセットについて、たて H cm よこ W cm の枠を出力して下さい。

  各データセットの後に、１つの空行を入れて下さい。
  Constraints

  H, W ? 300
NOTE

def draw_board(h, w, black: "#", white: ".")
  str = "#{black}#{white}".reverse!
  h.times do
    puts (str.reverse! * w)[0..(w-1)]
  end
  puts
end

ARGF.each_line do |line|
  height, width = line.split.map(&:to_i)
  break if line =~ /^0 0/
  draw_board(height, width)
end

Measured memory_bytes: 6172
/*  -*- coding: utf-8 -*-
 *
 * d.cc: D - Maxflow
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>

using namespace std;

/* constant */

const int MAX_H = 100;
const int MAX_W = 100;
const int MAX_N = MAX_H * MAX_W;

/* typedef */

typedef vector<int> vi;
typedef vector<bool> vb;

/* global variables */

char fs[MAX_H][MAX_W];
int ids[MAX_H][MAX_W];
vi nbrs[MAX_N];
int xs[MAX_N], ys[MAX_N];

/* subroutines */

bool max_match_rec(const vi *nbrs, int u, vi &matches, vb &visited) {
  if (u < 0) return true;
  const vi &nbru = nbrs[u];
  for (vi::const_iterator vit = nbru.begin(); vit != nbru.end(); vit++) {
    const int &v = *vit;
    if (! visited[v]) {
      visited[v] = true;
      if (max_match_rec(nbrs, matches[v], matches, visited)) {
	matches[u] = v;
	matches[v] = u;
	return true;
      }
    }
  }
  return false;
}

int max_match(const int n, int l, const vi *nbrs, vi &matches) {
  matches.assign(n, -1);
  int count = 0;
  
  for (int u = 0; u < l; u++) {
    vb visited(n, false);
    if (max_match_rec(nbrs, u, matches, visited)) count++;
  }

  return count;
}

/* main */

int main() {
  int h, w;
  scanf("%d%d", &h, &w);
  for (int y = 0; y < h; y++) scanf("%s", fs[y]);

  memset(ids, -1, sizeof(ids));
  int en = 0, on = 0;

  for (int y = 0; y < h; y++)
    for (int x = 0; x < w; x++)
      if (fs[y][x] == '.')
	ids[y][x] = ((x + y) & 1) ? on++ : en++;

  for (int y = 0; y < h; y++)
    for (int x = 0; x < w; x++)
      if (ids[y][x] >= 0) {
	if ((x + y) & 1) ids[y][x] += en;
	xs[ids[y][x]] = x, ys[ids[y][x]] = y;
      }

  int n = en + on;

  for (int y = 0; y < h; y++)
    for (int x = 0; x < w; x++) {
      int u = ids[y][x], v;
      if (u >= 0) {
	if (x + 1 < w && (v = ids[y][x + 1]) >= 0) {
	  nbrs[u].push_back(v);
	  nbrs[v].push_back(u);
	}
	if (y + 1 < h && (v = ids[y + 1][x]) >= 0) {
	  nbrs[u].push_back(v);
	  nbrs[v].push_back(u);
	}
      }
    }

  vi ms;
  int c = max_match(n, en, nbrs, ms);

  printf("%d\n", c);
  for (int y = 0; y < h; y++) {
    for (int x = 0; x < w; x++) {
      int u = ids[y][x], v;
      if (u >= 0 && (v = ms[u]) >= 0) {
	if (xs[u] < xs[v]) putchar('>');
	else if (xs[u] > xs[v]) putchar('<');
	else if (ys[u] < ys[v]) putchar('v');
	else if (ys[u] > ys[v]) putchar('^');
      }
      else
	putchar(fs[y][x]);
    }
    putchar('\n');
  }

  return 0;
}


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

int N,A,B;
vector<int> ans;

vector<int> dfs(int start,int goal,int len){
    if(len==1) return (vector<int>) {start,goal};
    int x = 0;
    for(int i=0;i<len;i++){
        if((start^goal)&(1<<i)){
            x = i;
            break;
        }
    }
    int a = 0,b = 0;
    for(int i=0;i<len;i++){
        if(i<x){
            if(start&(1<<i)) a += (1<<i);
            if(goal&(1<<i)) b += (1<<i);
        }
        if(i>x){
            if(start&(1<<i)) a += (1<<(i-1));
            if(goal&(1<<i)) b += (1<<(i-1));
        }
    }
    int c = -1;
    for(int i=0;i<len-1;i++){
        if((a^(1<<i))!=b){
            c = a^(1<<i);
            break;
        }
    }
    assert(c!=-1);
    vector<int> q = dfs(a,c,len-1),r = dfs(c,b,len-1),res;
    for(auto n:q){
        int now = (start&(1<<x)? (1<<x):0);
        for(int i=0;i<len-1;i++){
            if(i<x && (n&(1<<i))) now += (1<<i);
            if(i>=x && (n&(1<<i))) now += (1<<(i+1));
        }
        res.push_back(now);
    }
    for(auto n:r){
        int now = (goal&(1<<x)? (1<<x):0);
        for(int i=0;i<len-1;i++){
            if(i<x && (n&(1<<i))) now += (1<<i);
            if(i>=x && (n&(1<<i))) now += (1<<(i+1));
        }
        res.push_back(now);
    }
    return res;
}

int main(){
    cin >> N >> A >> B;
    if(__builtin_popcount(A)%2==__builtin_popcount(B)%2){
        cout << "NO" << endl;
        return 0;
    }
    vector<int> ans = dfs(A,B,N);
    cout << "YES" << endl;
    for(auto x:ans) cout << x << " ";
    cout << endl;
}

Measured memory_bytes: 1628
#include <iostream>
#include <string>
#include <vector>
#include <map>

using namespace std;
int main (){
    int n;cin >> n;
    
    map<string,int> list;
    string key;
    for(int i = 0;i < n;i++){
        cin >> key;
    	list[key] = 0;
    }
  	
    cout << list.size() << endl;
    return 0;
}

Measured memory_bytes: 19252
#include<iostream>
#include<stdio.h>
#include<string>
#include <algorithm>
#include<cstring>
#include <math.h>
#include <iomanip>
using namespace std;


int main()
{
  unsigned long long a,b,k;

  cin>>a>>b>>k;
 
  if(a>=k){
    a-=k;
  }else{
    k=k-a;
    a=0;
    if(b>k)
      b-=k;
    else 
      b=0;
  }


  cout<<a<<" "<<b<<endl;

  return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
// Custom Header {{{
#define ALL(x) x.begin(), x.end()
#define rep(i, s, n)      for(int i(s); i < int(n); ++i)
#define endl '\n'
#ifndef YDK
#define eprintf(...)
#endif
using namespace std;
using i64 = long long;
using pii = pair<i64, i64>;
template<class A, class B>inline bool chmax(A &a, const B &b){return b>a ? a=b,1 : 0;}
template<class A, class B>inline bool chmin(A &a, const B &b){return b<a ? a=b,1 : 0;}
constexpr const int INF  = 0x3f3f3f3f;
constexpr const i64 LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr const int MOD  = int(1e9) + 7;
// }}}

// Library {{{
inline vector<int> digits(unsigned long long n) {
    vector<int> ret;
    do { ret.push_back(n % 10); n /= 10; } while(n > 0);
    return ret;
}
// }}}

unordered_set<int> d {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};

int N, K;

int slv(int cnt, int val)
{
    if (val >= N) return val;
    if (cnt > 6) return INF;

    int ret = INF;
    for (int e : d) {
        chmin(ret, slv(cnt + 1, val * 10 + e));
    }

    return ret;
}

signed main()
{
    cin >> N >> K;
    rep(i, 0, K) {
        int ng; cin >> ng;
        d.erase(ng);
    }

    cout << slv(0, 0) << endl;

    return 0;
}


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

# define ll long long
# define mod 1000000007
# define MAX 100005
# define PI 3.141592653589793238                                                                                  //shortcut keys

# define pb push_back
# define mp make_pair
# define all(x) x.begin(),x.end()
# define fr(i,a,b) for(int i=a;i<=b;i++)

# define decimal(k) fixed<<setprecision(k)
# define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);        //---------------------------------------------------------------
using namespace std;

int main()
{
	
	int n;cin>>n;
	ll a[n+1];fr(i,1,n)cin>>a[i];
	ll sum=0;
	//fr(i,1,n)sum+=a[i];
	ll ans=0;
	for(int i=n;i>=1;i--){
		ans=(ans+(a[i]*(sum%mod))%mod)%mod;
		sum+=a[i];
	}
	cout<<ans<<"\n";

	return 0;
}



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

using namespace std;
int X,N;
int A[2000010]{};
bool B[2000010]{};
vector <int> C;
int main()
{
  cin>>N;
  cout<<N+N*N+N*N*N;
  
  return 0;
}





Measured memory_bytes: 3596
import heapq
n,m=map(int,input().split())
ab=[[] for _ in range(m+1)]
for i in range(n):
  a,b=map(int,input().split())
  if a<=m:
    ab[a].append(-b)

cand=[]
heapq.heapify(cand)
ans=0
for i in range(1,m+1):
  for j in range(len(ab[i])):
    heapq.heappush(cand,ab[i][j])
  if len(cand)>0:
    ans-=heapq.heappop(cand)

print(ans)

Measured memory_bytes: 17604
#include <cassert>
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <cwchar>
#include <cwctype>
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <array>
#include <atomic>
#include <chrono>
#include <codecvt>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
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; }
#define all(x) (x).begin(),(x).end()
#pragma GCC optimize("Ofast")
using namespace std;
typedef long long int ll;
typedef long double ld;
const ll INF=(1LL<<62);
const ld pi=acosl((ld)-1);
// const ll mod = 1000000007;
const ll mod = 1234567;
const int dx[4]={0,1,0,-1};
const int dy[4]={1,0,-1,0};
const int ddx[8]={1,0,-1,-1,-1,0,1,1};
const int ddy[8]={1,1,1,0,-1,-1,-1,0};
#define endn "\n"

ll xorsum(ll x,vector<ll>&A){
    ll ret=0;
    rep(i,A.size())ret+=(x xor A[i]);
    return ret;
}

bool solve(){
    ll N,K;cin>>N>>K;
    vector<ll>A(N);
    rep(i,N)cin>>A[i];
    ll ans=0;
    for(int i=50;i>=0;i--){
        ll num1=ans+(1LL<<i);
        ll num2=ans;
        if(num1>K)continue;
        if(xorsum(num1,A)>xorsum(num2,A))ans=num1;
    }
    cout<<xorsum(ans,A)<<endl;
    return false;
}

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout<<fixed<<setprecision(30);
    solve();
}


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

int main() {

  int i,j,k,n;
  char str[3];
  int a,b,count;


  while(1) {
    a = b = -1;
    count = 0;

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

    for(i=0;i<n;i++) {
      scanf("%s",str);
      if(str[0] == 'l' && str[1] == 'u') {
	a = 1;
	if(b == 0) b = -1;
      } else if(str[0] == 'r' && str[1] == 'u') {
	b = 1;
	if(a == 0) a = -1;
      } else if(str[0] == 'l' && str[1] == 'd') {
	a = 0;
	if(b == 1) b = -2;
      } else if(str[0] == 'r' && str[1] == 'd') {
	b = 0;
      if(a == 1) a = -2;
      }

      if(a == b) count++;
    
    }

    printf("%d\n",count);

  }

  return 0;

}

Measured memory_bytes: 604
n,l = map(int,input().split())
a = list(map(int,input().split()))
x = -1
for i in range(n-1):
  if a[i]+a[i+1] >= l:
    x = i
    break
if x == -1:
  print('Impossible')
else:
  print('Possible')
  for i in range(x):
    print(i+1)
  for i in range(n-2,x,-1):
    print(i+1)
  print(x+1)


Measured memory_bytes: 14076
N = int(input())
a = [int(i) for i in input().split()]
max_num = max(a)
diff = max_num / 2
a.remove(max_num)
min_num = [abs(i - diff) for i in a]
min_num = a[min_num.index(min(min_num))]
print(max_num, min_num)

Measured memory_bytes: 14052
package main

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

const kMax = 1000000000000000000

func main() {
	var n int
	fmt.Scan(&n)
	ans := int64(1)
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	for i := 0; i < n; i++ {
		sc.Scan()
		v, _ := strconv.Atoi(sc.Text())
		x := int64(v)
		if x == 0 {
			ans = 0
			break
		}
		if x <= kMax/ans {
			ans *= x
		} else {
			ans = kMax + 1
		}
	}
	if ans > kMax {
		ans = -1
	}
	fmt.Println(ans)
}


Measured memory_bytes: 5108
#include <bits/stdc++.h>
#define ll long long int
#define ld long double
#define mp make_pair
#define pi pair<int,int>
#define pl pair<long long int,int>
#define pb push_back
#define fi first
#define se second
#define len(a) (int)(a).length()
#define sz(a) (int)(a).size()

using namespace std;

ll N, h[200000], a[200000], st[1000000] = {0};
vector <pl> v;

void update(int x, int y, int k, int ind, ll val) {
	if (x == y) {
		st[k] = val;
		return;
	}
	else {
		int m = x + (y - x) / 2;
		if (ind <= m) update(x, m, 2*k+1, ind, val);
		else update(m+1, y, 2*k+2, ind, val);
		st[k] = max(st[2*k+1], st[2*k+2]);
	}
}

ll query(int l, int r, int x, int y, int k) {
	if (r < 0) return 0LL;
	if (l <= x && r >= y) {
		return st[k];
	}
	else {
		int m = x + (y - x) / 2;
		if (r <= m) return query(l, r, x, m, 2*k+1);
		else if (l > m) return query(l, r, m+1, y, 2*k+2);
		else return max(query(l, m, x, m, 2*k+1), query(m+1, r, m+1, y, 2*k+2));
	}
}

int main ()
{
	ios_base::sync_with_stdio(false); cin.tie(NULL);
	cin >> N;
	for (int i=0; i<N; ++i) {
		cin >> h[i];
		v.pb(pl(h[i], i));
	}
	for (int i=0; i<N; ++i)
		cin >> a[i];
	sort(v.begin(), v.end());
	for (int i=0; i<N; ++i)
		update(0, N-1, 0, v[i].se, a[v[i].se] + query(0, v[i].se-1, 0, N-1, 0));
	cout << st[0] << endl;
	return 0;
}


Measured memory_bytes: 15340
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cassert>
using namespace std;
#define N 10000100
const int mod=1e9+7;
inline int read(){
	int x=0,f=1;
	char c=getchar();
	while(c<'0'||c>'9'){
		if(c=='-')f=-1;
		c=getchar();
	}
	while(c>='0'&&c<='9'){
		x=(x<<1)+(x<<3)+c-'0';
		c=getchar();
	}
	return x*f;
}
int n,A,fac[N],inv[N],ans;
int qpow(int a,int b){
	int ans=1;
	while(b){
		if(b&1)ans=1LL*ans*a%mod;
		a=1LL*a*a%mod;
		b>>=1;
	}
	return ans;
}
void init(int n){
	fac[0]=1;
	for(int i=1;i<=n;++i){
		fac[i]=1LL*fac[i-1]*i%mod;
	}
	inv[n]=qpow(fac[n],mod-2);
	for(int i=n-1;i>=0;--i){
		inv[i]=1LL*inv[i+1]*(i+1)%mod;
	}
}
inline int C(int n,int m){
	return 1LL*fac[n]*inv[m]%mod*inv[n-m]%mod;
}
inline int calc(int a,int b,int c){
	return !(a+b)?0:1LL*fac[a+b+c]*a%mod*inv[a+b]%mod*fac[a+b-1]%mod;
}
int main(){
	n=read(),A=read();
	init(n);
	for(int i=1;i<=A+1;++i){
		for(int j=0;j<i;++j){
			ans=(ans+(j&1?-1:1)*1LL*C(i-1,j)*calc(i-j-1,n-A,max(0,A-i))%mod+mod)%mod;
		}
	}
	printf("%d\n",ans);
	return 0;
}


Measured memory_bytes: 81840
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
ll ans[10001] = {};
int main()
{
    int n_max;
    cin >> n_max;
    for (int x = 1; x * x <= n_max; ++x)
    {
        for (int y = 1; x * x + y * y + x * y <= n_max; ++y)
        {
            for (int z = 1; x * x + y * (x + y) + z * (x + y + z) <= n_max; ++z)
            {
                ans[x * x + y * (x + y) + z * (x + y + z)]++;
            }
        }
    }
    for (int i = 1; i <= n_max; ++i)
    {
        cout << ans[i] << endl;
    }
    return 0;
}


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

using namespace std;

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

  int sum=0;
  vector<int> w(n);
  for(int i=0;i<n;i++)
  {
      cin >> w.at(i);
      sum+=w.at(i);
  }

  int rsum=0;
  int ans=sum;

  for(int i=0;i<n;i++)
  {
    rsum+=w.at(i);
    ans=min(ans,abs((sum-rsum)-rsum));
  }
  cout << ans << endl;
  
}

Measured memory_bytes: 256
n=int(input())
hs=list(map(int,input().split()))
ans=0
tmp=0
for h,x in zip(hs,hs[1:]+[10**9+1]):
    if h>=x:
        tmp+=1
    elif tmp>ans:
        ans=tmp
        tmp=0
    else:
        tmp=0
print(ans)


Measured memory_bytes: 14252
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;

namespace AtCoder
{
	public class ABC
	{
		static readonly int mod = 1000000007;  // 10^9+7

		static void Main(string[] args)
		{
			Console.SetOut(new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false });


			//string s = Console.ReadLine();
			//int n = int.Parse(Console.ReadLine());
			//long x = long.Parse(Console.ReadLine());
			int[] vs = Console.ReadLine().Split().Select(int.Parse).ToArray();
			//long[] vs = Console.ReadLine().Split().Select(long.Parse).ToArray();
			int h = vs[0];
			int n = vs[1];
			int[] a = Console.ReadLine().Split().Select(int.Parse).ToArray();
			for (int i = 0; i < n; i++) {
				h -= a[i];
				if (h <= 0) {
					break;
				}
			}
			if (h <= 0) {
				Console.WriteLine("Yes");
			} else {
				Console.WriteLine("No");
			}


			Console.Out.Flush();
		}
	}
}


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

struct Card{
  char suit;
  int number;
  // bool operator<(const Card& another) const {
  //   return number < another.number;
  // }
};

// bool asc(const Card& left, const Card& right) {
//   return left.number < right.number;
// }

int n;

int partition(vector<Card> &A, int p, int r) {
  int x = A[r].number;
  int i = p-1;
  for(int j = p; j < r; ++j) {
    if(A[j].number <= x) {
      i++;
      Card tmp = A[i]; A[i] = A[j]; A[j] = tmp;
    }
  }
  Card tmp = A[i+1]; A[i+1] = A[r]; A[r] = tmp;
  return i+1;
}

void quicksort(vector<Card> &A, int p, int r) {
  if(p < r) {
    int q = partition(A, p, r);
    quicksort(A, p, q-1);
    quicksort(A, q+1, r);
  }
}

int main() {
  cin >> n;
  vector<Card> cards(n), cards_copy(n);
  REP(i, n) cin >> cards[i].suit >> cards[i].number;
  REP(i, n) cards_copy[i] = cards[i];

  quicksort(cards, 0, n-1);
  stable_sort(cards_copy.begin(), cards_copy.end(), [](const Card &a, const Card &b){return a.number < b.number;});

  int isStable = 1;
  REP(i, n) {
    if(cards[i].suit != cards_copy[i].suit) {
      isStable = 0;
      break;
    }
  }
  cout << (isStable ? "Stable" : "Not stable") << endl;
  REP(i, n) cout << cards[i].suit << " " << cards[i].number << endl;  

  return 0;
}


Measured memory_bytes: 4744
// 単純に考えると
// 消す文字 N それぞれに対してヒストグラムを計算して ~ ってやって O(N**2)
// 間に合わなそうだからO(N) もしくは O(NlogN)で済ます方法を考える
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;

const char wall = '#';
vector<vector<char>> fields;
vector<vector<bool>> used;
vector<vector<ll>> dist;
const int dx[4] = {0, -1, 0, 1};
const int dy[4] = {1, 0, -1, 0};

ll N;
vector<ll> A;

ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return b/gcd(a,b)*b;}

ll choose2(ll n){
  return n * (n-1)/2;
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  // Globalなvectorのリサイズ
  //A.resize(N);
  
  cin >> N;
  
  vector<ll> a(N);
  rep(i, N) {
    cin >> a[i];
  }
  rep(i, N) {
    a[i]--;
  }
  vector<ll> cnt(N);
  rep(i, N) cnt[a[i]]++;
  
  ll tot = 0;
  // 何も削除しないとき答え
  rep(i, N) {
    tot += choose2(cnt[i]);
  }
  rep(i, N) {
    ll ans = tot;
    // i番目の数が減る
    // いったんa[i]をなかったことにして
    ans -= choose2(cnt[a[i]]);
    // 減った後の数で再計算
    ans += choose2(cnt[a[i]]-1);
    cout << ans << endl;
  }

  return 0;
}


Measured memory_bytes: 5760
#include<stdio.h>

int main(){
  int a,b,d;
  int r=0,l=0;

  while(scanf("%d,%d,%d",&a,&b,&d)!=EOF){
    if(d*d==a*a+b*b){
      r++;
    }
    if(a==b){
      l++;
    }
  }

  printf("%d\n%d\n",r,l);

  return 0;
}

Measured memory_bytes: 596
<?php
    fscanf(STDIN, "%d %d %d %d %d", $W, $H, $x, $y, $r);
    $yes = "Yes" . "\n";
    $no = "No" . "\n";
    // echo $W . $H . $x . $y . $r;
    // 水平方向の判定と垂直方向の判定
    if(($x-$r) < 0){
        echo $no;
    }else if(($x+$r) > $W){
        echo $no;
    }else if(($y-$r) < 0){
        echo $no;
    }else if($y+$r > $H){
        echo $no;
    }else{
        echo $yes;
    }
?>


Measured memory_bytes: 9188
#include <cstdio>

int main() {
  int N;
  scanf("%d", &N);

  int res=0;
  for (int i=3; i<=N; i+=2) {
    int divs=0;
    for (int j=1; j<=i; ++j)
      if (i % j == 0) ++divs;

    if (divs == 8) ++res;
  }
  printf("%d\n", res);
}


Measured memory_bytes: 128
fun judge(m: Int, f: Int, r: Int): Char {
    var result: Char
    val mf = m + f

    result = when {
        mf < 30 -> 'F'
        mf < 50 -> 'D'
        mf < 65 -> 'C'
        mf < 80 -> 'B'
        else -> 'A'
    }
    if (result == 'D' && r >= 50) {
        result = 'C'
    }
    if (Math.min(m, f) == -1) {
        result = 'F'
    }
    return result
}

fun main(args: Array<String>) {
    val ans = mutableListOf<Char>()
    while (true) {
        val (m, f, r) = readLine()!!.split(" ").map { it.toInt() }
        if (listOf(m, f, r).sum() == -3) {
            break
        }
        ans.add(judge(m, f, r))
    }
    println(ans.joinToString("\n"))
}



Measured memory_bytes: 31988
#include <iostream>
#include <cmath>
#define llong long long
#define For(i,a,b) for(int i=(a);i<(b);i++)
#define Rep(i,n) for(int i=0;i<(n);i++)
using namespace std;


int main(){
  int N, M;
  cin >> N >> M;
  int t = 1900*M + 100*(N-M);
  llong total = t * pow(2, M);
  cout << total << endl;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();    
    int ans = 0;
    for (int i = 0; i < N; i++) {
      int a = sc.nextInt();
      ans += powNum(a);
    }
    
    System.out.println(ans);
  }
  
  private static int powNum(int a) {
    if (a % 2 == 1) {
      return 0;
    }
    return 1 + powNum(a/2);
  }
}

Measured memory_bytes: 32332
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;

public class Main {

    public static void main(String[] args) throws Exception {

        InputStreamReader is = new InputStreamReader(System.in);
        BufferedReader reader = new BufferedReader(is);

        List<String> mylist = new ArrayList<>();

        // 標準入力からの値を変数strinputに代入
        String strinput = reader.readLine();

        while (strinput != null) {

            mylist.add(strinput);
            strinput = reader.readLine();

        }

        String arr_temp[] = mylist.get(0).split(" ");

        String s = arr_temp[0];

        System.out.println(s.matches("^([h][i])+") ? "Yes" : "No");

    }

}


Measured memory_bytes: 23252
#include <iostream>
#include <vector>
using namespace std;
int main(){
    string a[5];
    for(int i = 0;i < 5;i++){
        a[i] ="";
    }
    int k = 0;
    while(1){
        int n;
        cin >> n;
        if(n == 0){
            break;
        }
        vector<char>in(n);
        vector<char>out(n);
        for(int i = 0;i < n;i++){
            cin >> in[i] >> out[i];

        }
        //cout << out[1] <<endl;
        int m;
        cin >> m;
        vector<char>scr(m);
        for(int i = 0;i < m;i++){
            cin >> scr[i];
            //cout << scr[i];
            for(int j = 0;j < n;j++){
                
                if(in[j] == scr[i]){
                    scr[i] = out[j];
                    break;
                    //cout << scr[i] << " " <<out[j] <<endl;
                }
            }
            //cout << " "<< scr[i] <<endl;
            a[k] += scr[i];
        }
        k++;
    }
    for(int i = 0;i < k;i++){
        cout << a[i] <<endl;
    }
    return 0;
}


Measured memory_bytes: 3264
#include <stdio.h>

int main() {
  int n, k;
  scanf("%d %d", &n, &k);

  int num[n];
  for(int i = 0; i < n; i++) {
    scanf("%d", &num[i]);
  }

  for(int i = 0; i < n - k; i++) {
    if(num[i] < num[i + k]) {
      puts("Yes");
    }
    else {
      puts("No");
    }
  }
  return 0;
}


Measured memory_bytes: 2424
require 'prime'

# 約数リスト
def divisors(n)
  n.prime_division.inject([1]) do |array, (k, v)|
    (0..v).map{ |i| k ** i }.product(array).map{ |a, b| a * b }
  end.sort
end

n = gets.to_i
divisors_of_75 = divisors(75)

hash = Hash.new(0)
(2..n).each do |i|
  Prime.prime_division(i).each do |pr, n|
    hash[pr] += n
  end
end

nums = hash.values.map { |num| num + 1 }
possible_divisors = []
nums.each do |num|
  possible_divisors << (2..num).select{ |num| divisors_of_75.include?(num) }
end

ans = [1]
possible_divisors.each do |divs|
  tmp = []
  divs.each do |div|
    ans.each do |a|
      next if div * a > 75
      tmp << div * a
    end
  end
  ans += tmp
end

puts ans.count(75)


Measured memory_bytes: 2300
import time

start_time = time.time()

#input
D = int(input())
c_list = list(map(int, input().split()))

s_grid = []
for i in range(D):
    array = list(map(int, input().strip().split(' ')))
    s_grid.append(array)

t_list = [(i%26) for i in range(D)] #task_list

def calculate_score(t_list,score_list,last_grid,change_query_number):
    score_list = score_list[:change_query_number]
    last_grid = last_grid[:change_query_number]

    if len(score_list) > 1:
        score = score_list[change_query_number-1]
        last_list = last_grid[change_query_number-1]
    else:
        score = 0
        last_list = [0 for i in range(26)]

    for d in range(change_query_number,D):
        score += s_grid[d][t_list[d]]
        last_list = [n+1 for n in last_list]
        last_list[t_list[d]] = 0
        for i in range(26):
            score -= c_list[i]*last_list[i]
        score_list.append(score)
        last_grid.append(last_list)
    return score_list, last_grid

#first cal.
previous_s, previous_l = calculate_score(t_list,[],[[0 for i in range(26)]],0)
score = previous_s[-1]

for k in range(1,D):
    X = -1  # k-日目に変える番号を探す
    t_list_loop = t_list
    for i in range(26):  # 26通り試す
        t_list_loop[k] = i
        score_list_k, last_grid_k = calculate_score(t_list_loop, previous_s, previous_l, k)
        if score_list_k[-1] > score:
            X = i
            score = score_list_k[-1]
            score_list_t = score_list_k
            last_grid_t = last_grid_k

    if X != -1:
        t_list[k] = X
        previous_s = score_list_t
        previous_l = last_grid_t

    # print(k,X,score)

    if time.time() - start_time > 1.9:
        break

#final result
for j in range(len(t_list)):
    print(int(t_list[j]) + 1)

Measured memory_bytes: 10048
def main():
    n = int(input())

    ans = 0
    for num in range(1, n + 1, 2):
        cnt = 0
        for i in range(1, num + 1):
            if num % i == 0:
                cnt += 1
        if cnt == 8:
            ans += 1

    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 62956
#include <stdio.h>
int a,b,c;
int k;
int main(void){
    int a1=scanf("%d",&a);
    int b1=scanf("%d",&b);
    int c1=scanf("%d",&c);
    int k1=scanf("%d",&k);
 int i=0;   
    while(i<k){
        if(a>=b&&a>=c){
            a=a*2;
        }else if(b>=a&&b>=c){
            b=b*2;
        }else{
            c=c*2;
        }
        i++;
    }
    int sum=a+b+c;
    printf("%d",sum);
}

Measured memory_bytes: 128
import Data.List
import Data.Ord
import Data.Char
import Data.Ratio
import Data.Maybe

main = do
  [a,b,c,x] <- map (read::String->Int) . lines <$> getContents
  print $sum [1|s<-[0..a], t<-[0..b], u<-[0..c], 500*s+100*t+50*u==x]

Measured memory_bytes: 3960
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(obj) (obj).begin(),(obj).end()
long cnt=0;

void merge(vector<int> &A,int left, int mid,int right){
      int n1=mid-left;
      int n2=right-mid;
      vector<int> L(n1),R(n2);
      for(int i=0;i<n1;i++)  L.at(i)=A.at(left+i);
      for(int i=0;i<n2;i++) R.at(i)=A.at(mid+i);
      L.push_back(1e9);
      R.push_back(1e9);
      int i=0,j=0;
      for(int k=left;k<right;k++){
          if(L.at(i)<=R.at(j)) {
              A.at(k)=L.at(i);
              i++;
          }
          else{
              A.at(k)=R.at(j);
              j++;
              cnt+=n1-i;
          }
      }
      return;
    }

void mergeSort(vector<int> &A,int left,int right){
      if(left+1<right){
          int mid=(left+right)/2;
          mergeSort(A,left,mid);
          mergeSort(A,mid,right);
          merge(A,left,mid,right);
      }
      return;
      }

  int main(){
      cin.tie(0);
      ios::sync_with_stdio(false);
      int n;
      cin>>n;
      vector<int> A(n);
      rep(i,n) cin>>A.at(i);
      mergeSort(A,0,n);
      cout<<cnt<<endl;
      return 0;
  }



Measured memory_bytes: 5172
//
//  main.cpp
//  Chokudai_Contest_004
//
//  Created by tolemy on 2019/08/31.
//  Copyright © 2019 tolemy. All rights reserved.
//

#include <algorithm>
#include <functional>
#include <iostream>
#include <queue>
#include <vector>

using namespace std;

#define rep(i, start, end) for (int i = (int)(start); i < (int)(end); i++)

class Item
{
public:
    int value;
    int discountValue;
    Item(int p_value)
    {
        value = p_value;
        int discount = value / 2;
        discountValue = value - discount;
    }
};

int main(int argc, const char *argv[])
{

    int n, m;
    cin >> n >> m;

    auto a = [](Item x, Item y) { return x.discountValue < y.discountValue; };
    priority_queue<Item, vector<Item>, function<bool(Item, Item)>> pq(a);

    rep(i, 0, n)
    {
        int v;
        cin >> v;

        Item a(v);
        pq.push(v);
    }

    rep(i, 0, m)
    {
        Item a = pq.top();
        pq.pop();

        Item b(a.value - a.discountValue);
        pq.push(b);
    }

    long long int sum = 0;
    while (!pq.empty())
    {
        Item a = pq.top();
        pq.pop();

        sum += a.value;
    }

    cout << sum << endl;

    return 0;
}


Measured memory_bytes: 1400
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <utility>
#include <functional>
#include <climits>
#include <cstring>

using namespace std;

#define int long long
#define rep(i, n) for (int i=0;i<(int)(n);++i)
#define rep1(i, n) for (int i=1;i<=(int)(n);++i)
#define range(i, l, r) for (int i=l;i<(int)(r);++i)
#define rrange(i, l, r) for (int i=r-1;i>=(int)(l);--i)
#define unless(a) if(!(a))
#define all(a) begin(a),end(a)
#define fst first
#define scd second
#define PB emplace_back
#define PPB pop_back

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

bool chmin(int&a,int b){return a>b?(a=b,true):false;}
bool chmax(int&a,int b){return a<b?(a=b,true):false;}
int read(){int a;scanf("%lld",&a);return a;}

const int mod = 1e9 + 7;

signed main()
{
	int N; cin >> N;
	vector<double> v(N);
	rep(i, N) cin >> v[i];

	sort(all(v));

	double ans = v[0];

	rep(i, N - 1) {
		ans = (ans + v[i + 1]) / 2.0;
	}

	printf("%.10f\n", ans);
}



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

using namespace std;

#define REP(i,n)	for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REPS(i,s,n)	for(int i=(s), i##_len=(n); i<i##_len; ++i)

#define ALL(obj)	(obj).begin(),(obj).end()
#define sz(x) (int)(x).size()
#define v(T) vector<T>
#define VEC vector

typedef unsigned int 			uint;
typedef unsigned long long int	ull;
typedef long long int 			ll;

typedef pair<int,int>			P;
typedef vector<int>				Vint;
typedef vector<Vint>			VV;

template<typename T>string join(const v(T)&v)
{stringstream s;REP(i,sz(v))s<<' '<<v[i];return s.str().substr(1);}
template<typename T>inline ostream& operator<<(ostream&o,const v(T)&v)
{if(sz(v))o<<join(v);return o;}

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define MAX 		100010

const ll LINF = (ll)9e18+7;		//
const int INF = 100100100;			//2,147,483,647 (Max int)
const ll MOD = 1e9+7;
// テンプレ終了
//====================================================================//

// int DP[MAX];

//
int main(){
	int N,M,Q;cin >> N >> M >> Q;
	vector<vector<int>> abcd(Q,vector<int>(4,0));
	REP(i,Q){cin >> abcd[i][0] >> abcd[i][1] >> abcd[i][2] >> abcd[i][3];}

	int maxl = 0;
	Vint t(M+N,0);
	REPS(i,1,N+1)t[i]=1;

	do {
		Vint A;
		int suml = 0;
		REP(i,M+N)
			if(t[i]==1){
				A.push_back(suml);
			}else{
				suml ++;
			}
		// cout <<"t : "<< t << endl;
		// cout <<"A : "<< A << endl;
		int cnt = 0;
		REP(i,Q){
			if( (A[abcd[i][1]-1] - A[abcd[i][0]-1]) == abcd[i][2]){
				cnt += abcd[i][3];
				// cout << abcd[i] << " " << cnt << endl;
			}
		}
		// cout << cnt << endl;
		maxl = max(maxl,cnt);
	} while( prev_permutation(t.begin(), t.end()) ); 


	cout << maxl << endl;	

	return 0;
}
 



Measured memory_bytes: 3576
#include<bits/stdc++.h>
#define MOD 1000000007
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3f
#define EPS (1e-10)
#define rep(i,n)for(int i=0;i<n;i++)
using namespace std;
typedef long long ll;
typedef pair<int, int>P;

struct food {
	string f; int w, s;
};
int main() {
	int n;
	while (scanf("%d", &n), n) {
		vector<food>v(n);
		int sum = 0;
		rep(i, n) {
			string f; int w, s; cin >> f >> w >> s;
			v[i] = { f,w,s }; sum += w;
		}
		sort(v.begin(), v.end(), [](food a, food b) {return a.w > b.w; });
		while (!v.empty()) {
			int i = 0;
			while (v[i].s < sum - v[i].w)i++;
			sum -= v[i].w;
			cout << v[i].f << endl;
			v.erase(v.begin() + i);
		}
	}
}

Measured memory_bytes: 3128
#include <iostream>
#include <queue>
#include <stack>
#include <vector>
#include <stdio.h>
#include <algorithm>
#include <string.h>
#include <string>
#include <cmath>
#include <complex>
#include <map>
using namespace std;

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

static const double PI=6*asin(0.5);
typedef complex<double> P;
typedef long long ll;


int n;
ll a[6000];

ll sum(int i,int j){
	ll s=0;
	rep(k,j){
		s+=a[i+k];
	}
	return s;
}

int main(){
	while(cin>>n,n!=0){
		int c=0;
		ll MAX=-1000000000000000000;
		rep(i,n) a[i]=0;
		/*
		int cou=0;
		rep(i,n){
			cou++;
			cin>>a[0];
			if(a[0]!=0){
				break;
			}
			
		}
		n-=cou;
		*/	
		
		rep(i,n) cin>>a[i];
		c=n;
		MAX=a[0];
		rep(i,n){
			ll sum=0;
			for(int j=i;j<n;j++){
				sum+=a[j];
				MAX=max(MAX,sum);
			}
		}
		
		
		/*
		rep(i,n){
			int t;
			cin>>t;
			if(a[c]*t<0){
				a[++c]=t;
			}
			else a[c]+=t;
		}
		
		
		c++;
		for(int i=1;i<=c;i++){
			rep(j,c+1-i){
				MAX=max(MAX,sum(j,i));
			}
		}
		*/
		cout<<MAX<<endl;
	}
	return 0;
}

Measured memory_bytes: 1192
#include <stdio.h>

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

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

int main(void) {
	int a1,m1,a2,m2,a3,m3;
	long long xn,yn,zn;
	long long i;
	while(1) {
		scanf("%d%d%d%d%d%d",&a1,&m1,&a2,&m2,&a3,&m3);
		if((a1|m1|a2|m2|a3|m3)==0)break;
		xn=yn=zn=1;
		for(i=a1%m1;i!=1;i=(i*a1)%m1)xn++;
		for(i=a2%m2;i!=1;i=(i*a2)%m2)yn++;
		for(i=a3%m3;i!=1;i=(i*a3)%m3)zn++;
		printf("%lld\n",lcm(lcm(xn,yn),zn));
	}
	return 0;
}

Measured memory_bytes: 0
import java.util.Scanner;

public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int x = sc.nextInt();
        int sum = 0;
        for (int i = 0; i < n; i++) {
            sum += sc.nextInt();
            if (sum > x) {
                System.out.println(i + 1);
                break;
            }
        }
        if (sum <= x) {
            System.out.println(n + 1);
        }
    }
}


Measured memory_bytes: 21972