akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
    using namespace std;
    typedef long long ll;
    //--<for debugging>
    #define whatis(x) cout << #x << " is " << x<<" ";
    #define whatisl(x) cout << #x << " is " << x<<"\n";
    #define parr(array,end)for(ll loop=0;loop<end;loop++)cout<<array[loop]<<" ";cout<<"\n";
    #define lline cout<<"\n";
    #define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args);cout<<"\n";}
     
    void err(istream_iterator<string> it) {}
    template<typename T, typename... Args>
    void err(istream_iterator<string> it, T a, Args... args) {
    	cout << *it << " = " << a <<" , ";
    	err(++it, args...);
    }
    //--</for debugging> 
    #define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
    #define testcase ll tt; cin >> tt; while(tt--)
    #define cina ll num,loop;cin>>num;ll a[num];rep(loop,0,num)cin>>a[loop];
    #define boost ios_base::sync_with_stdio(false);cin.tie(NULL);
    #define pb push_back 
    #define vars ll h,i,j,k,d,l,r,x,y,b,c,v,var,n,m,z,s,ans,ind1,ind2,flag,limit1,limit2,limit3,mod;
    #define vll vector<ll>
    #define pll pair<ll,ll>
    #define sll set<ll>
    #define pint pair<int,int>
    const ll INF=1e9+7;
    const ll MOD=1e9+7;
    int main()
    {
        boost vars 
        cin>>k>>n;
        ll arr[n];
        for(i=0;i<n;i++)
        {
            cin>>arr[i];
        }
        sort(arr,arr+n);
        ans=0;
        for(i=1;i<n;i++)
        {
            ans=max(ans,arr[i]-arr[i-1]);
        }
        ans=max(ans,k-arr[n-1]+arr[0]);
        cout<<k-ans;
    }

Measured memory_bytes: 1792
#include<iostream>
#include<algorithm>
#include<string>
#include<cstdlib>
#include<vector>
#include<queue>
#include<cmath>
using namespace std;

int main()
{
    int n, m;
    int i;
    
    cin >> n >> m;
    
    int a[m];
    int sum = 0;
    
    for(i = 0; i < m; i++) {
        cin >> a[i];
        sum += a[i];
    }
    
    if(sum > n) {
        cout << -1 << endl;
    } else {
        cout << n - sum << endl;
    }
    
    return 0;
}

Measured memory_bytes: 3672
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<queue>
#include<deque>
#include<stack>
#include<string>
#include<string.h>
#include<vector>
#include<set>
#include<map>
#include<bitset>
#include<stdlib.h>
#include<cassert>
#include<time.h>
#include<bitset>
using namespace std;
const long long mod=1000000007;
const long long inf=mod*mod;
const long long d2=(mod+1)/2;
const long double EPS=1e-9;
const long double PI=acos(-1.0);
int ABS(int a){return max(a,-a);}
long long ABS(long long a){return max(a,-a);}
long double ABS(long double a){return max(a,-a);}
int main(){
	int a;scanf("%d",&a);
	for(int i=0;i<a;i++){
		int p;scanf("%d",&p);if(p%2){
			printf("first\n");return 0;
		}
	}
	printf("second\n");
}


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

using namespace std;
int n, m, k;
char a[200010];
int dp1[200010] = {0}, vis1[200010] = {0}, dp2[200010] = {0}, vis2[200010] = {0};
int main() {
	scanf("%d%d%d", &n, &m, &k);
	scanf("%s", a+1);
	int u = 0;
	for (int i = 1; i <= n; i++) {
		vis1[i] = max(vis1[i-1]-1, 0);
		if (a[i] == 'o' && vis1[i] == 0) {
			vis1[i] = k+1;
			dp1[i] = dp1[i-1] + 1;
		}
		else {
			dp1[i] = dp1[i-1];
		}
	}
	for (int i = n; i >= 1; i--) {
		vis2[i] = max(vis2[i+1]-1, 0);
		if (a[i] == 'o' && vis2[i] == 0) {
			vis2[i] = k+1;
			dp2[i] = dp2[i+1] + 1;
		}
		else {
			dp2[i] = dp2[i+1];
		}
	}
	for (int i = 1; i <= n; i++) {
		if (vis1[i] == k+1 && vis2[i] == k+1 && a[i] == 'o' && dp1[i] + dp2[i+1] == m) {
			printf("%d\n", i);
		}
	}
	return 0;
}

Measured memory_bytes: 4864
while True:
    num = int(input())
    if num == 0: break
    ans = 0
    for i in range(1,num+1):
        for j in range(i+1,num+1):
            i += j
            if i == num: 
                ans += 1 
                break
            elif i>num: break
    print(ans)


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

int main(){
	int w,h;
	cin>>w>>h;
	
	int x,y;
	cin>>x>>y;
	
	printf("%f %d\n",(double)w*h/2,2*x==w&&2*y==h);
}//解説参考.


Measured memory_bytes: 256
n,a,b = map(int,input().split())
if a == 0:
  print(0)
elif a+b <= n and n%(a+b) < a:
  print((n//(a+b))*a + n%(a+b))
elif a+b <= n and n%(a+b) >= a:
  print((n//(a+b))*a + a)
elif n < a+b and n < a:
  print(n)
elif n < a+b and a <= n:
  print(a)
  


Measured memory_bytes: 8988
#include <algorithm>
#include <cmath>
#include <cstring>
#include <deque>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stdlib.h>
#include <string>
#include <utility>
#include <vector>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define loop(i, x, n) for (int i = (x); i < (n); i++)
#define all(v) (v).begin(), (v).end()
#define int long long
using namespace std;
const int MOD = 1e9 + 7;
const int INF = 1e18;
template<typename T> void cmax(T &a, T b) { a = max(a, b); }
template<typename T> void cmin(T &a, T b) { a = min(a, b); }

signed main() {
  int h, w, k;
  cin >> h >> w >> k;
  vector<vector<int>> dp(h + 1, vector<int>(w, 0));
  dp[0][0] = 1;

  rep(i, h) {
    rep(j, w) {
      for (int mask = 0; mask < (1 << (w - 1)); mask++) {
        bool f = true;
        rep(l, w - 2) if (((mask >> l) & 1) && ((mask >> (l + 1)) & 1)) f = false;
        if (!f) continue;

        if (1 <= j && ((mask >> (j - 1)) & 1)) {
          (dp[i + 1][j - 1] += dp[i][j]) %= MOD;
        } else if (j <= w - 2 && ((mask >> j) & 1)) {
          (dp[i + 1][j + 1] += dp[i][j]) %= MOD;
        } else {
          (dp[i + 1][j] += dp[i][j]) %= MOD;
        }
      }
    }
  }

  cout << dp[h][k - 1] << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n;
    cin>>n;
    int a[n - 1];
    for (int i = 0; i < n - 1; i++) {
        cin>>a[i];
    }
    int b[n + 1] = {0};
    for (int i = 0; i < n - 1; i++) {
        b[a[i]]++;
    }
    for (int i = 1; i <= n; i++) {
        cout<<b[i]<<endl;
    }
	return 0;
}

Measured memory_bytes: 5216
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        A solver = new A();
        solver.solve(1, in, out);
        out.close();
    }

    static class A {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            // 入力
            String S = in.next();

            if (S.length() == 2) {
                out.println(S);
            } else {
                StringBuilder sb = new StringBuilder();
                out.println(sb.append(S).reverse());
            }

        }

    }
}



Measured memory_bytes: 21844
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower

using namespace std;
 
int main(){
    int A,B;
    cin >> A >> B;
    if(A - B  <= 0){
        cout << "0" << endl;
    }
    else cout << A-B << endl;
}

Measured memory_bytes: 3568
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repr(i, n) for (int i = (n); i >= 0; --i)
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define FORR(i, m, n) for (int i = (m); i >= (n); --i)
using namespace std;
typedef long long ll;
const ll mod = 1000000007;
const ll mod2 = 998244353;

struct Node {
  int key;
  Node *next, *prev;
};

Node *nil;

Node* listSearch(int key) {
  Node *cur = nil->next;
  while (cur != nil && cur->key != key) {
    cur = cur->next;
  }
  return cur;
}

void init() {
  nil = (Node *)malloc(sizeof(Node));
  nil->next = nil;
  nil->prev = nil;
}

void printList() {
  Node *cur = nil->next;
  int isf = 0;
  while (1) {
    if (cur == nil) break;
    if (isf++ > 0) printf(" ");
    printf("%d", cur->key);
    cur = cur->next;
  }
  printf("\n");
}

void deleteNode(Node *t) {
  if (t == nil) return;
  t->prev->next = t->next;
  t->next->prev = t->prev;
  free(t);
}

void deleteFirst() {
  deleteNode(nil->next);
}

void deleteLast() {
  deleteNode(nil->prev);
}

void deleteKey(int key) {
  deleteNode(listSearch(key));
}

void insert(int key) {
  Node *x = (Node *)malloc(sizeof(Node));
  x->key = key;
  x->next = nil->next;
  nil->next->prev = x;
  nil->next = x;
  x->prev = nil;
}

int main() {
  int key, n, i;
  int size = 0;
  char com[20];
  int np = 0, nd = 0;
  scanf("%d", &n);
  init();
  rep(i, n) {
    scanf("%s%d", com, &key);
    if (com[0] == 'i') {
      insert(key);
      np++;
      size++;
    }
    else if (com[0] == 'd') {
      if (strlen(com) > 6) {
        if (com[6] == 'F') deleteFirst();
        else if (com[6] == 'L') deleteLast();
      }
      else {
        deleteKey(key);
        nd++;
      }
      size--;
    }
  }
  printList();

  return 0;
}


Measured memory_bytes: 34480
#include<iostream>
#include<cstdio>
#include<stack>
#include<queue>
#include<algorithm>
#include<string>
#include<set>
#include<map>
#include<vector>
#include<math.h>
#include<tuple>
#include<string.h>
#include <numeric> 
#include<unordered_map>
using namespace std; 
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define pp(...) "\033[94m [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "]\033[0m"
#define pp1(...) "\033[1;47;35m" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "]\033[0m"
#define dg(x) debug() << pp1(x)
#define dg1(x) debug() << pp(x)
#define dg2(x,y) debug() << pp(x) pp(y)
#define dg3(x,y,z) debug() << pp(x) pp(y) pp(z)
#define dg4(w,x,y,z) debug() << pp(w) pp(x) pp(y) pp(z)
#define int long long
#define all(x) x.begin() , x.end()
#define clr(x) memset(x , 0 , sizeof x);
#define sz(x) (int)x.size()
template<typename T> void db(T x ){ debug() <<">>> " <<  x; }
template<typename T> void db(T x , T y){ debug() <<">>> " <<  x <<" , "<< y; }
template<typename T> void db(T x , T y , T z){ debug() <<">>> "<< x <<" , "<< y <<" , "<< z; }
template<typename T> void db(T x , T y , T z , T a){ debug() <<">>> "<< x <<" , " << y <<" , "<< z <<" , "<< a; }
const int xx = 2e6;
const int Mod = 1e9 + 7;
const int inf = 1e18;
const int Maxn = 20010;
signed main(){
  ios::sync_with_stdio(false);cin.tie(0);

  int n , d;
  cin >> n >> d;

  int ans = 0;
  long double D = (long double)d;
  for(int i = 0; i < n; i++) {
    int x , y;
    cin >> x >> y;
    long double ds = (x * x) + (y * y);
    long double dst = sqrt(ds);
    if(dst <= D) ans++;
  }
  cout << ans << '\n';
} 

Measured memory_bytes: 3604
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;cin>>N;
  vector<int> d(N);
  for(int i=0;i<N;i++)cin>>d[i];
  sort(d.begin(),d.end());
  cout<<d[N/2]-d[N/2-1]<<endl;
}

Measured memory_bytes: 640
x = int(input())

num = x // 3
rem = x % 3

if rem == 1:
    res = (num+1)*(num**2)

elif rem == 2:
    res = ((num + 1) ** 2) * num

else:
    res = num ** 3

res2 = (x/3)**3
if res > res2:
    print(res)
else:
    print(res2)


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n,k;
  cin>>n>>k;
  vector<int> p(n);
  for(int i=0;i<n;i++)cin>>p[i];
  sort(p.begin(),p.end());
  int ans=0;
  for(int i=0;i<k;i++)ans+=p[i];
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 3588
/*Saurav Paul*/
#include<bits/stdc++.h>
using namespace std;

#define ll 					  long long int
#define boost		          ios_base::sync_with_stdio(0);
#pragma GCC optimize("O3")
#define loop(i,a,b)           for(ll i=a;i<=b;++i)
#define eb                    emplace_back
#define itoc(c)               ((char)(((int)'0')+c))
#define ctoi(c)               ((int)(((int)c)-'0'))
#define all(p)                p.begin(),p.end()
#define bug()				  debug() <<

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

#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef PAUL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define dbg(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

#ifdef ONLINE_JUDGE
#define cerr if (false) cerr
#endif
int main() ;
void file(){
	#ifdef PAUL
		freopen("in.txt","r",stdin);
		//freopen("out.txt","w",stdout);
	#endif
}
void time(){
	#ifdef PAUL
		cerr << "\nTime elapsed: " << (double)(1.0 * (double)clock() / CLOCKS_PER_SEC) << " s.\n";
	#endif
}
///////////////////////
const int INF = 1e9 + 90;
const ll LINF = 1e18 + 90 ;
using pii = pair<int,int >;
using vec = vector<int> ;

int main()
{
	int n ;
	string s ;
	cin >> n >> s;
	int cnt = 0;
	for(int i = 2 ; i < n ; i++){
		if(s[i-2]=='A' && s[i-1]=='B' && s[i]=='C') cnt ++;
	}
	cout << cnt << endl;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <limits.h>
#include <algorithm>
#include <math.h>
#include <time.h>
#include <vector>
#include <map>
#include <queue>
#include <string>
using namespace std;
typedef long long ll;

int main(void){
    int n, a, b, c, l[10];
    cin >> n >> a >> b >> c;
    for (int i = 0; i < n; i++) cin >> l[i];
    
    int t, ans = 1e9, tri[8];
    for (int i = 0; i < pow(4, n); i++) {
        t = i;
        for (int j = 0; j < n; j++) {
            tri[j] = t % 4;
            t /= 4;
        }
        
        int mp = 0, al = 0, bl = 0, cl = 0;
        for (int j = 0; j < n; j++) {
            if (tri[j] == 0) {
                if (al > 0) mp += 10;
                al += l[j];
            }
            if (tri[j] == 1) {
                if (bl > 0) mp += 10;
                bl += l[j];
            }
            if (tri[j] == 2) {
                if (cl > 0) mp += 10;
                cl += l[j];
            }
        }
        
        if (al * bl * cl != 0) {
            mp += (abs(a - al) + abs(bl - b) + abs(c - cl));
            ans = min(mp, ans);
        }
    }
    
    cout << ans << endl;
}


Measured memory_bytes: 384
package main

import (
  "fmt"
)


func maxInt(a ...int) int {m := a[0]; for _, x := range a {if x > m {m = x}}; return m}
func minInt(a ...int) int {m := a[0]; for _, x := range a {if x < m {m = x}}; return m}

func main() {
  var x, t int
  fmt.Scan(&x, &t)
  fmt.Println(maxInt(0, x - t))
}

Measured memory_bytes: 512
#include<stdio.h>
int main(){
    int i,a[3],tmp;
    for(i=0;i<3;i++){
        scanf("%d",&a[i]);
    }
    if(a[0]>a[1]){
    tmp=a[1];
    a[1]=a[0];
    a[0]=tmp;
    }
    if(a[1]>a[2]){
    tmp=a[2];
    a[2]=a[1];
    a[1]=tmp;
    }
    if(a[0]>a[1]){
    tmp=a[1];
    a[1]=a[0];
    a[0]=tmp;
    }
    printf("%d %d %d\n",a[0],a[1],a[2]);
    
    return 0;

}

Measured memory_bytes: 596
using namespace std;
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <set>
#include <map>
#include <assert.h>
#include <functional>
#include <math.h>
#include <ctime>

typedef long long ll;


//point update, range query, 0-indexed
template <class T>
struct bit {
	vector<T> b;
	void init(int n) { b.resize(n + 1); }
	bit() {}
	bit(int n) { init(n); }
	inline void update(int i, T v) {
		for (++i; i < (int)b.size(); i += i & -i)
			b[i] = max(b[i], v);
	}
	//sum of the first i values
	T prefix(int i) const {
		T a = 0;
		for (; i; i ^= i & -i)
			a = max(b[i], a);
		return a;
	}
	inline T query(int l, int r) const {
		return prefix(r + 1) - prefix(l);
	}
};



int main() {
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    //srand(time(NULL));
    ll r, c, k;
    cin >> r >> c >> k;
    vector<vector<pair<int, ll> >> ks(3001);
    for (int i = 0; i < k; i++) {
        ll x, y, v;
        cin >> x >> y >> v;
        x--;
        y--;
        ks[x].push_back({  y , v});
    }
    for (int i = 0; i < r; i++) {
        sort(ks[i].begin(), ks[i].end());
    }
    bit<long long>ans0(3005);
    bit<long long>ans1(3005);
    bit<long long>ans2(3005);
    bit<long long>ans3(3005);
    for (int i = 0; i < r; i++) {
        
        for (auto p : ks[i]) {
            int j = p.first;
                //if there is a thing at i,j of value v
            ans0.update(j, max(((long long) max(ans1.prefix(j+1), ans2.prefix(j+1))), ans3.prefix(j+1)));
        }
        for (auto p : ks[i]) {
            int j = p.first;
            ll v = p.second;
            //if there is a thing at i,j of value v
            ans3.update(j, ans2.prefix(j+1)+v);
            ans2.update(j, ans1.prefix(j+1)+v);
            ans1.update(j, ans0.prefix(j+1)+v);
        }
    }
    cout << max(max(ans0.prefix(c+1), ans1.prefix(c+1)), max(ans2.prefix(c+1), ans3.prefix(c+1))) << endl;


}

Measured memory_bytes: 9188
N,X = map(int,input().split())
m = []
for i in range(N):
    m.append(int(input()))
    

D = sum(m)
x = X - D
dmin = min(m)
ans = N
while(1):
    if x < dmin:
        break
    x -= dmin
    ans += 1

print(ans)


Measured memory_bytes: 3060
n = int(input())
d = {}
for _ in range(n):
  s = input()
  if s not in d:
    d[s] = 0
  d[s] += 1
m  =int(input())
for _ in range(m):
  s = input()
  if s not in d:
    d[s] = 0
  d[s] -= 1
  
ans = 0
for key in d:
  ans = max(d[key], ans)
print(ans)



Measured memory_bytes: 3060
n,m = map(int,input().split())
import copy
k = [0 for i in range(m)]
ans = 0
import copy
for i in range(m):
    k[i] = list(map(int,input().split()))
p = list(map(int,input().split()))
for i in range(2**n):
    v = 1
    d = [0 for i in range(n)]
    q = copy.deepcopy(i)
    for j in range(n):
        if q &1:
            d[j] = 1
        q = q >> 1
    for g in range(m):
        u = 0
        for c in range(1,k[g][0]+1):
            u += d[k[g][c]-1]
        if u%2 == p[g]:
            continue
        else:
            v = 0
            break
    if v:
        ans += 1
print(ans)

Measured memory_bytes: 44892
var
	A,B,C,K:Longint;
begin
	read(A,B,C,K);
	while A>=B do begin
		dec(K);
		B:=B*2;
	end;
	while B>=C do begin
		dec(K);
		C:=C*2;
	end;
	if K<0 then writeln('No')else writeln('Yes');
end.

Measured memory_bytes: 1332
#include<bits/stdc++.h>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
 
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define int long long int
#define mod 1000000007
#define inf 1e18+42
#define endl "\n"

#define out1(a) cout<<#a<<" "<<a<<endl
#define out2(a,b) cout<<#a<<" "<<a<<" "<<#b<<" "<<b<<endl
#define out3(a,b,c) cout<<#a<<" "<<a<<" "<<#b<<" "<<b<<" "<<#c<<" "<<c<<endl

#define rep(i,a,b) for(int i=a;i<b;i++)
#define repr(i,a,b) for(int i=a;i>=b;i--)
#define fori(it,A) for(auto it=A.begin();it!=A.end();it++)

#define ft first
#define sd second
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define zero(x) memset(x,0,sizeof(x));
 
using namespace std;

int binpow(int a, int b) {
    int res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a;
        a = a * a;
        b >>= 1;
    }
    return res;
}

//START OF CODE ->->->->->->->

void solve()
{
    int n;
    cin>>n;

    vector<int> a(n);

    rep(i,0,a.size())
    {
        cin>>a[i];
    }

    sort(all(a));
    double v = (a[0]+a[1])/(float)2;
    rep(i,2,a.size())
    {
        v = (v+a[i])/(float)2;
    }

    cout<<setprecision(20)<<v<<endl;
}

//END OF CODE ->->->->->->->->

signed main()
{
    fast;
    int t = 1;
    // cin>>t;

    while(t--)
    {
        solve();
    }
    return 0;
}



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

int main(){

int a,b,c,k,maior=0,soma=0,n=0;

cin >> a >> b >> c ;
cin >> k;

while(k>0){
        k--;
        soma = a+b+2*c;
        maior = soma;
        if(2*a+b+c>maior){maior=2*a+b+c;n=1;}
        if (a+2*b+c>maior){maior=a+2*b+c;n=2;}

        if (n==0){c=2*c;}
        if (n==1){a=2*a;}
        if (n==2){b=2*b;}

}



cout<<maior<<endl;



return 0;
}


Measured memory_bytes: 256
// ヨセフのおいも
import java.util.*;
public class Main{
    public static void main(String[] args){
	new Main().run();
    }

    Scanner kbd = new Scanner(System.in);

    void run(){
	while(kbd.hasNext()){
	    boolean[] p = new boolean[kbd.nextInt()]; // 0 = 最後の番号
	    int t = kbd.nextInt();
	    if(p.length==0 && t==0) break;

	    
	    Arrays.fill(p, true);
	    int tcnt = p.length; // いる人の数
	    int remove = 0; // 抜ける人の番号
	    while(tcnt!=1){
		int i=0;
		while(i<t){
		    remove++;
		    remove = remove%p.length;
		    if(p[remove]){
			i++;
		    }
		}		
		//System.out.println(remove);
		p[remove] = false;
		tcnt--;
	    }
	    int ans = 0;
	    while(!p[ans]) ans++;
	    if(ans==0) ans = p.length;
	    System.out.println(ans);
	}
    }
}

Measured memory_bytes: 19596
def divisor(n):
    ass = []
    for i in range(1, int(n**0.5)+1):
        if n%i == 0:
            ass.append(i)
            ass.append(n//i)
    return sorted(ass)

n = int(input())
p = divisor(n)
ans = n + 10
for x in p:
  if x*x > n:
    break
  y = n//x
  if ans > y+x:
    ans = y+x
print(ans - 2)

Measured memory_bytes: 3296
N = int(input())
S = input()

S=S +"1"
state=0
bonus_sum=0
gokei=0
bonus=0

for i in range(N):
    #print("gokei",gokei)
    #print("bonus", bonus)
    #print("bonus_sum", bonus_sum)
    #print(S[i],S[i+1])
    
    if S[i] != S[i +1 ]:
        gokei=gokei+1
        bonus_sum=bonus_sum +bonus
        bonus=0
    else:
        gokei=gokei +1
        bonus = bonus +1

        
print(gokei - bonus_sum)
        

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

#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
const int INF = 1e9;

int main() {
  ll n, ans = 0, a, b, c;
  cin >> n;
  for (int i = 1; i < n; ++i) {
    int x = n - i, j = 2;
    map<int, int> mp;
    if (x == 1)
      ans++;
    else {
      while (x > 1 && j * j <= n - i) {
        if (x % j == 0)
          x /= j, mp[j]++;
        else
          j++;
      }
      if (x > 1) mp[x]++;
      ll t = 1;
      for (auto m : mp)t *= (m.second + 1);
      ans += t;
    }
  }

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

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


int main() {
string N,K;

int c=0;
vector<int> d;
vector<int> count;
vector<vector<int>> A;

cin >> N  >>K;

if(N==K.erase((K.size()-1))){
    cout << "Yes";
}
else
{
    cout << "No";
}


}

Measured memory_bytes: 3592
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#include<algorithm>
#include<queue>
#include<set>
#include<map>
#include<iostream>
using namespace std;
#define re register
#define ll long long
inline int gi()
{
	int f=1,sum=0;char ch=getchar();
	while(ch>'9' || ch<'0'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0' && ch<='9'){sum=(sum<<3)+(sum<<1)+ch-'0';ch=getchar();}
	return f*sum;
}
int main()
{
	int a=gi(),b=gi();
	if(a<b)swap(a,b);
	printf("%d\n",a+max(a-1,b));
	return 0;
}


Measured memory_bytes: 256
/*
 * swq.cpp
 *
 *  Created on: 5/09/2017
 *      Author: cristhian
 */
#include<bits/stdc++.h>


using namespace std;


int main(){

	int n;

	cin >> n;

	vector<int> vec;
	for(int i = 0; i < n; i++){
		int aux;
		cin >> aux;
		vec.push_back(aux);
	}
	long long sumA =0;
	long long sumB = 0;

	long long auxA = vec[0];
	long long auxB;
	if(auxA > 0){
		auxB = -1;
		sumB += auxA + 1;
	}else if(auxA < 0){
		auxB = 1;
		sumB += abs(auxA) + 1;
	}else{
		auxA = 1;
		auxB = -1;
		sumA++;
		sumB++;
	}

	long long sumAuxA = auxA;
	long long sumAuxB = auxB;
	for(int i = 1; i < n; i++){
		if(sumAuxA > 0){
			sumAuxA += vec[i];
			sumAuxB += vec[i];
			if(sumAuxA >= 0){
				sumA += sumAuxA+1;
				sumAuxA = -1;
			}

			if(sumAuxB <= 0){
							sumB += abs(sumAuxB)+1;
							sumAuxB = 1;
						}
		}else{
			sumAuxA += vec[i];
			sumAuxB += vec[i];
			if(sumAuxA <= 0){
				sumA += abs(sumAuxA)+1;
				sumAuxA = 1;
			}

			if(sumAuxB >= 0){
				sumB += sumAuxB+1;
				sumAuxB = -1;
			}
		}
	}


	cout << min(sumA, sumB);

}

Measured memory_bytes: 892
n,x=list(map(int,input().split()))
a=sorted(list(map(int,input().split())))
i=0
num=0
for i in a:
    x=x-i
    num+=1
    if x==0:
        break
    if x<=0:
        num-=1
        break
if x>0:
    num-=1
print(num)

Measured memory_bytes: 3064
//#include <bits/stdc++.h>
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <queue>
#include <deque>
#include <set>
#include <stack>
#include <time.h>
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef pair<int, int> Pii;
typedef pair<int, ll> Pil;
typedef pair<ll, ll> Pll;
typedef pair<ll, int> Pli;

const ll nmax = 1e9 + 7;
const ll Mod = 998244353;
const double PI = 2 * asin(1);

ll Pow(ll A, ll B, ll mod){
  if (B == 0) return 1;
  else{
    if (B % 2 == 0){
      return Pow(A * A % mod, B / 2, mod) % mod;
    }else{
      return A * Pow(A * A % mod, B / 2, mod) % mod;
    }
  }
}

ll nCr(ll N, ll R, ll mod){
  ll ans = 1; R = min(R, N - R);
  for (ll i = 1; i <= R; i++){
    ans *= N - i + 1; ans %= mod;
    ans *= Pow(i, mod - 2, mod); ans %= mod;
  }
  return ans;
}

int main(){
  string S; cin >> S;
  int ans = 0;
  for (int i = 0; i < S.length() - 1; i++){
    if (S[i] != S[i + 1]) ans++;
  }
  cout << ans << endl;
  return 0;
}


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

int n;
int a[300000];

class UnionFind {
public:
	vector<int>par, sz;
public:
	UnionFind() {}
	UnionFind(int n) {
		par = sz = vector<int>(n);
		for (int i = 0; i < n; i++) {
			par[i] = i;
			sz[i] = 1;
		}
	}
	int find(int x) {
		if (par[x] == x)return x;
		return par[x] = find(par[x]);
	}
	void unite(int x, int y) {
		x = find(x); y = find(y);
		if (x == y)return;
		par[x]=y;
	}
	bool same(int x, int y) {
		return find(x) == find(y);
	}
	int size(int x) {
		return sz[find(x)];
	}
};
bool C(int t){
	unordered_map<int,int>mp,id,id_rev;
	set<int>se;
	UnionFind uf(n*2);
	int cnt=0;
	for(int i=1;i<n;i++){
		if(a[i]>a[i-1])continue;
		if(!id.count(a[i])){
			id[a[i]]=cnt++;
			id_rev[id[a[i]]]=a[i];
		}
		int d=id_rev[uf.find(id[a[i]])];
		if(d==0||++mp[d]>t)return false;
		if(mp[d]==t){
			if(!id.count(d-1)){
				id[d-1]=cnt++;
				id_rev[id[d-1]]=d-1;
			}
			uf.unite(id[d],id[d-1]);
		}
		se.insert(d);
		auto it=se.lower_bound(d+1);
		while(it!=se.end()){
			mp[*it]=0;
			uf.par[id[*it]]=id[*it];
			it=se.erase(it);
		}
	}
	return true;
}
int main(){
	scanf("%d",&n);
	bool flag=false;
	rep(i,n){
		scanf("%d",&a[i]);
		if(i&&a[i-1]>=a[i])flag=true;
	}
	if(!flag){
		puts("1");return 0;
	}
	int ok=n*2,ng=0;
	while(ok-ng>1){
		int t=(ok+ng)/2;
		if(C(t))ok=t;
		else ng=t;
	}
	cout<<ok+1<<endl;
}


Measured memory_bytes: 27820
#include <iostream>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
using namespace std;
int main(){
	int a,b;
	cin>>a>>b;
	int x[100000];
	for(int i=0;i<a;i++){
		cin>>x[i];
	}
	int ans;
	ans=(a-1)/(b-1);
	if((a-1)%(b-1)!=0){
		ans++;
	}
	cout<<ans;
	return 0;
} 

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

    using namespace std;
    typedef long long ll;
    # define M_PI  3.14159265358979323846
    const int MOD=1e9+7;

    void solve(){
        vector<int>cnt(1000005);
        int n;
        cin>>n;
        for(int i=0;i<n;i++){
            int k;
            cin>>k;
            cnt[k]++;
        }
        int ans=0;
        vector<int>vis(1000005,0);
        for(int i=1;i<=1000000;i++){
            if(cnt[i]==0 || vis[i])
                continue;
            if(cnt[i]==1 && !vis[i])
                ans++;
            for(int j=i;j<=1000000;j+=i)
                vis[j]=1;
        }
        cout<<ans;
    }
    int main(){
        ios::sync_with_stdio(0);
        cin.tie(0);
        cout.tie(0);
        cout<<fixed;
        cout<<setprecision(10);
        int t=1;
//        cin>>t;
        for(int i=1;i<=t;i++){
            solve();
        }
        return 0;
    }


Measured memory_bytes: 11080
#include <bits/stdc++.h>
#define x first
#define y second
#define gcd(x, y) __gcd((x), (y))
using namespace std;

using i64 = long long;
using f64 = double;
using pii = pair<int, int>;

int main() {
#ifdef HOME
	freopen("atc.in", "r", stdin);
	freopen("atc.out", "w", stdout);
#endif
	ios::sync_with_stdio(false);
	cin.tie(0), cout.tie(0);
	i64 x, y, t, g;

	cin >> x >> y;
	if (x % y == 0)
		cout << "-1" << endl;
	else {
		cout << x << endl; }

	return 0; }


Measured memory_bytes: 764
#include <cstdio>
#include <algorithm>

#define MAX_N 51

/* -----------------------------------------------------------------------------
	大域データ
----------------------------------------------------------------------------- */
int N;
double v[MAX_N];

int main () {


	// 文字列数の読込み
	scanf("%d", &N);

	for(int i = 0; i < N; i++) {
		scanf("%lf", v + i);
	}

	std::sort(v, v + N);

	for(int i = 1; i < N; i++) {
		v[i] = (v[i-1] + v[i]) / 2;
	}

	printf("%.6lf\n", v[N-1]);

	return 0;
}


Measured memory_bytes: 128
"use strict";
function I(t,i){this._s=t.split("\n"),this._c=0,this._l=0,this._f=i||Number}I.prototype.a=function(t){var i=this._s[this._l];if(i){var s=i.trim().split(" "),h=s[this._c];return this._c++,s.length===this._c&&(this._c=0,this._l++),t?t(h):this._f(h)}},I.prototype.l=function(t){var i=this._s[this._l];if(i)return this._c=0,this._l++,i.split(" ").map(t||this._f)},module.exports=I;

function main(input) {
  var o = new I(input);

  var n = o.a();
  var k = o.a();

  var v = o.l();

  var leftV;
  var rightV;

  var max = 0;
  for (var left = 0; left <= k; left++) {
    leftV = v.slice(0, left);
    for (var right = 0; right <= k - left; right++) {
      rightV = v.slice(Math.max(left, v.length - right), v.length);

      // console.log({leftV, rightV});
      var maxK = k - left - right;
      var curV = leftV.concat(rightV);
      curV.sort((a, b) => a - b);

      var value = 0;
      for (var i = 0; i < curV.length; i++) {
        if (i < maxK && curV[i] < 0) continue;
        value += curV[i];
      }
      // console.log({left, right, value})
      if (value > max) max = value;
    }
  }

  console.log(max);
}


main(require("fs").readFileSync("/dev/stdin", "utf8"));


Measured memory_bytes: 14376
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<cstring>
#include<string>
#include<algorithm>
#define N 505
#define ll long long
using namespace std;
int n;
int s[N][N];
ll sum[N][N][2],f[N][N];
ll get(int x,int y,int z){return sum[y][z+1][0]-sum[x][z+1][0]+sum[y+1][z][1];}
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
		for(int j=1;j<=n;j++){
			if(i==j) continue;
			scanf("%d",&s[i][j]);
		}
	for(int i=1;i<=n;i++)
		for(int j=i+1;j<=n;j++)
			sum[i][j][0]=s[j][i],sum[i][j][1]=s[i][j];
	for(int i=1;i<=n+1;i++)
		for(int j=1;j<=n+1;j++)
			sum[i][j][1]+=sum[i][j-1][1];
	for(int i=1;i<=n+1;i++)
		for(int j=1;j<=n+1;j++)
			sum[i][j][0]+=sum[i-1][j][0];
	for(int i=n+1;i>=0;i--)
		for(int j=n+1;j>=0;j--)
			sum[i][j][0]+=sum[i][j+1][0];
	for(int i=n+1;i>=0;i--)
		for(int j=n+1;j>=0;j--)
			sum[i][j][1]+=sum[i+1][j][1];
	for(int i=0;i<=n;i++)
		for(int j=0;j<=n;j++)
			f[i][j]=1e17;
	f[0][0]=0;
	for(int i=0;i<=n;i++)
		for(int j=0;j<=max(0,i-1);j++)
			for(int k=i+1;k<=n;k++)
				f[k][i]=min(f[k][i],f[i][j]+get(j,i,k));
	ll mi=get(0,0,n);
	for(int i=0;i<n;i++)
		for(int j=i+1;j<n;j++)
			mi=min(mi,f[j][i]+get(i,j,n));
	printf("%lld\n",mi);
	return 0;
}

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

class Program
{
    static void Main(string[] args)
    {
        var input = Console.ReadLine().Split();
        var A = int.Parse(input[0]);
        var B = int.Parse(input[1]);

        Console.WriteLine(Math.Max(A - B * 2, 0));
    }
}


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

using namespace std;

int main(){

  long long N, L;
  cin >> N >> L;
  vector<pair<long long, long long>> LR(N);

  long long a, b;
  for(int i = 0; i < N; i++){
    cin >> a >> b;
    LR[i] = make_pair(a, b);
  }

  sort(LR.begin(), LR.end());

  int index = 0;
  long long endPoint = 0;
  int ansX = 0;
  priority_queue<long long> pq;

  // X
  while(endPoint != L){
    bool isAppend = false;
    if(index != N){
      auto temp = LR[index];
      if(temp.first <= endPoint){
	index++;
	isAppend = true;
	pq.push(temp.second);
      }
    }

    if(!isAppend){
      long long temp = pq.top();
      pq.pop();

      ansX++;
      endPoint = temp;
    }
  }

  // Y
  vector<pair<long long, int>> eventList(2 * N);
  for(int i = 0; i < N; i++){
    auto temp = LR[i];
    eventList[2 * i] = make_pair(temp.first, 1);
    eventList[2 * i + 1] = make_pair(temp.second, -1);
  }

  sort(eventList.begin(), eventList.end());

  int cnt = 0;
  int minCnt = N;
  long long before = 0;
  index = 0;

  while(index != 2 * N){
    auto temp = eventList[index];
    while(temp.first == before){
      cnt += temp.second;
      index++;
      if(index == 2 * N){
	break;
      }
      temp = eventList[index];
    }
    before = temp.first;

    if(index == 2 * N){
      break;
    }
    minCnt = min(minCnt, cnt);
  }

  int ansY = N - minCnt + 1;

  cout << ansX << " " << ansY << endl;
  
  return 0;
}



Measured memory_bytes: 13488
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		while (true) {
			int n = sc.nextInt();
			int p = sc.nextInt();
			if (n == 0 && p == 0)
				break;
			int[] s = new int[n];
			for (int i = 0; i < n; i++)
				s[i] = 0;
			int i = 0;
			int np = p;
			while (np != s[i]) {
				if (p != 0) {
					p--;
					s[i]++;
				}
				else if (p == 0) {
					p += s[i];
					s[i] = 0;
				}
				i++;
				if(i >= n) i -= n;
			}
			System.out.println(i);
		}
		sc.close();
	}
}

Measured memory_bytes: 20552
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define fi first
#define se second

//添え字が素数ならtrve、そうでないならfalseにする
void eratosthenes(vector<bool> &v,int N){//０もとってある
    for(int i=2;i < N+1;i++){
        if(v.at(i)==true){
            for(int j=2*i;j < N+1;j += i){//Nを宣言してなかった、注意
                v.at(j) = false;
            }
        }
    }
}//エラトステネスの篩 添え字が素数ならtrue

int main(){
    int q;
    cin >> q;
    vector<bool> v(pow(10,5)+1,true);
    vector<int> e(pow(10,5)+1);
    eratosthenes(v,pow(10,5));
    v.at(1)=false;
    e.at(0)=0;

for(int i=1;i <= pow(10,5);i++)//奇数のみ
{
            if(i==3){
                e.at(3)=e.at(2)+1;
                continue;
            }
            if(i%4!=1){
                e.at(i)=e.at(i-1);
                continue;
            }

            if(v.at(i)==true && v.at((i+1)/2)==true){
                e.at(i)=e.at(i-1)+1;
            }else{
                e.at(i)=e.at(i-1);
            }
}

    for(int k=0;k < q;k++)
    {
        int l,r;
        cin >> l >> r;
        cout << e.at(r)-e.at(l-1) << endl;
    }
}

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

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

    vector<double> x(N);
    vector<double> y(N);
    for (int i = 0; i < N; i++)
    {
        cin >> x[i] >> y[i];
    }

    double ans = 0;
    for (int i = 0; i < N; i++)
    {
        for (int j = 0; j < N; j++)
        {
            ans += sqrt(pow(x[i] - x[j], 2) + pow(y[i] - y[j], 2));
        }
    }

    cout << fixed << setprecision(6) << ans / N << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int vmax = 55555;
vector<bool> prime(vmax + 1, true);

int main() {
  int n;
  cin >> n;
  prime[1] = false;
  for (int i = 2; i * i <= vmax; i++) {
    if (prime[i]) {
      for (int j = 2 * i; j <= vmax; j += i) {
        prime[j] = false;
      }
    }
  }
  int cnt = 0;
  int idx = 11;
  while (true) {
    if (prime[idx]) {
      cout << idx << " ";
      cnt++;
      if (cnt >= n) break;
    }
    idx += 10;
  }
}

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

int main() {
  int64_t N;
  int64_t A;
  int64_t B;
  cin >> N >> A >> B;
  int64_t C = N/(A+B);
  int64_t k = min(A,N-(A+B)*C);
  cout << A*C + k << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
using namespace std;
#define rep(i,n) for(int i=0; i<(int)(n); ++i)

int main(){
	string s;
	cin >> s;
	int n = s.length();
	
	rep(bit, (1<<(n-1)) ){
		int sum = s[0] - '0';
		rep(j, n-1){
			if( bit & (1<<j)){
				sum += (s[j+1] - '0');
			}
			else{
				sum -= (s[j+1] - '0');
			}
		}
		if (sum == 7){
			cout << s[0];
			rep(j,n-1){
				if(bit&(1<<j)){
					cout << '+' << s[j+1];
				}
				else{
					cout << '-' << s[j+1];
				}
			}
			cout << "=7" << endl;
			break;
		}
	}

	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<array>
#include<utility>
#include<set>
#include<algorithm>

using namespace std;

typedef array<char,9> P;

void cw(P &p){
  P n;
  for(int i=0;i<3;i++){
    for(int j=0;j<3;j++){
      n[j*3+2-i]=p[i*3+j];
    }
  }
  p=n;
}

void ccw(P &p){
  cw(p);
  cw(p);
  cw(p);
}

P lr(P p){
  P n=p;
  for(int i=0;i<3;i++){
    swap(n[0+i*3],n[2+i*3]);
  }
  return n;
}

P inv(P p){
  ccw(p);
  ccw(p);
  return p;
}

P nccw(P p){
  ccw(p);
  return p;
}

struct Dice{
  P p[6];
  Dice(){
    for(int i=0;i<6;i++){
      for(int j=0;j<9;j++){
	cin>>p[i][j];
      }
    }
    // auto d=Dice(*this).l();
    // cout<<"=---"<<endl;
    // for(auto e:d.p){
    //   for(int i=0;i<3;i++){
    // 	for(int j=0;j<3;j++){
    // 	  cout<<e[i*3+j];
    // 	}
    // 	cout<<endl;
    //   }
    // }
    // cout<<"=---"<<endl;
  }
  bool operator<(Dice d)const{
    return lexicographical_compare(begin(p),end(p),begin(d.p),end(d.p));
  }
  Dice &u(){
    auto t=p[4];
    p[4]=p[0];
    p[0]=p[5];
    p[5]=inv(p[2]);
    p[2]=inv(t);
    cw(p[1]);
    ccw(p[3]);
    return *this;
  }
  Dice &d(){
    u();
    u();
    u();
    return *this;
  }
  Dice &l(){
    auto t=p[4];
    p[4]=nccw(p[1]);
    p[1]=nccw(p[5]);
    p[5]=nccw(p[3]);
    p[3]=lr(nccw(t));
    cw(p[2]);
    ccw(p[0]);
    return *this;
  }
  Dice &r(){
    l();
    l();
    l();
    return *this;
  }
};

int main(){
  for(;;){
    Dice d;
    if(!cin)break;
    set<pair<int,Dice> >s{{0,d}};
    for(auto e:s){
      auto cd=e.second;
      if(count(begin(cd.p[0])+6,begin(cd.p[0])+9,'*')&&count(begin(cd.p[2])+6,begin(cd.p[2])+9,'*')){
	cout<<e.first<<endl;
	goto next;
      }
      s.insert({e.first+1,Dice(cd).u()});
      s.insert({e.first+1,Dice(cd).r()});
      s.insert({e.first+1,Dice(cd).d()});
      s.insert({e.first+1,Dice(cd).l()});
    }
  next:
    ;
  }
}

Measured memory_bytes: 1188
#include <bits/stdc++.h>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<string> vs;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<int,P> pip;
typedef vector<pip> vip;
const int inf=1<<29;
const ll INF=1ll<<60;
const double pi=acos(-1);
const double eps=1e-9;
const ll mod=1e9+7;
const int dx[4]={-1,0,1,0},dy[4]={0,-1,0,1};

class Graph{
	private:
	int n;
	vvp g;
	public:
	vi DIJ(int s){
		priority_queue<P> q;
		vi d(n,inf);
		d[s]=0;
		q.push({0,s});
		while(!q.empty()){
			P p=q.top();
			q.pop();
			int v=p.second;
			if(d[v]<-p.first) continue;
			for(auto i:g[v]){
				int u=i.first,D=d[v]+i.second;
				if(d[u]>D){
					d[u]=D;
					q.push({-D,u});
				}
			}
		}
		return d;
	}
	Graph(int v){
		n=v;
		g=vvp(v);
	}
	void add_edge(int s,int t,int c){
		g[s].push_back({t,c});
		g[t].push_back({s,c});
	}
};

set<int> used;

void dfs(int v,vvi& a,map<int,int> &nx,vi& b){
	used.insert(v);
	for(auto i:a[v]) if(i!=a[v][0]){
		if(nx.find(i)==nx.end()){
			b[i]=1;
		}
		else if(used.find(nx[i])==used.end()){
			dfs(nx[i],a,nx,b);
		}
	}
}

int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	while(1){
		int n;
		cin>>n;
		if(n==0) break;
		vvi a(n);
		map<string,int> mp;
		map<int,int> nx;
		int id=0;
		for(int i=0;i<n;i++){
			string s,t;
			cin>>s;
			for(auto c:s){
				if(isalpha(c)) t+=c;
				else{
					if(mp.find(t)==mp.end()) mp[t]=id++;
					a[i].push_back(mp[t]);
					t="";
				}
			}
			nx[a[i][0]]=i;
		}
		vi b(id);
		used.clear();
		dfs(0,a,nx,b);
		int res=0;
		for(auto i:b) res+=i;
		cout<<res<<endl;
	}
}


Measured memory_bytes: 3392
import java.util.*;
public class Main{
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		int n = sc.nextInt();
		String data[] = new String[n];

		for (int i = 0;i<n ;i++ ) {
			data[i] = sc.next();
		}

		for (int i = 0;i<n ;i++ ) {
			for (int j = i+1;j<n ;j++ ) {
				if (data[i].equals(data[j])) {
					System.out.println("No");
					System.exit(0);
				}
			}
		}

		for (int i = 0;i<n-1 ;i++ ) {
			if (data[i].charAt(data[i].length()-1)==data[i+1].charAt(0)) {

			}else{
				System.out.println("No");
				System.exit(0);
			}
		}
		System.out.println("Yes");

	}
}


Measured memory_bytes: 22228
#include<bits/stdc++.h>
#define fast ios_base::sync_with_stdio(false),cin.tie(NULL)
#define frr(i,s,n) for(int i=s;i<=n;i++)
#define fr(i,s,n) for(int i=s;i<n;i++)
#define lli long long int
#define llu unsigned long long int
#define vi vector <int>
#define vii vector <long long int>
#define pb push_back
#define eb emplace_back
#define pi pair<int,int>
#define mk make_pair
#define mpp map<int,int>
#define ff first
#define ss second
#define mod 1000000007

using namespace std;

vector <int> v[100001];
vector <int> vis(100001);
int dp[100001];
int dfs(int node)
{
	if(vis[node])
		return dp[node];
	vis[node] = 1;
	int mx = 0;
	for(auto child : v[node])
		mx = max(mx,dfs(child) + 1);
	return dp[node] = mx;
}

void loop()
{
	int n;
	cin>>n;
	int a[n+1],b[n+1];
	for(int i=1;i<=n;i++)
	{
		cin>>a[i]>>b[i];
	}
	int cnt = 1,f=0;
	for(int i=1;i<=n-2;i++)
	{
		cnt = 1;
		if(a[i]==b[i])
		{
			i++;
			while(a[i] == b[i])
			{
				cnt++;
				i++;
			}
			//i--;
		}
		if(cnt >= 3)
		{
			f=1;
			break;
		}
	}
	if(f)
		cout<<"Yes\n";
	else
		cout<<"No\n";
}
int main()
{
	#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
	#endif
	fast;
    int t=1;
    //cin>>t;
    while(t--)
    	loop();
}


Measured memory_bytes: 5964
#include <stdio.h>
int main(){
    int n,m;
    scanf("%d%d",&n,&m);
    int k[n],a[n][m];
    for (int i=0;i<n;i++){
        scanf("%d",&k[i]);
        for (int j=0;j<k[i];j++){
            scanf("%d",&a[i][j]);
        }
    }
    int count=0,flag[k[0]];
    for (int i=0;i<k[0];i++){
        flag[i]=0;
        for (int j=0;j<n;j++){
            for (int l=0;l<k[j];l++){
                if (a[0][i]==a[j][l]){
                    flag[i]++;
                    break;
                }
            }
        }
        if (flag[i]==n){
            count++;
        }
    }
    printf("%d",count);
    return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=(int)a, i##_len=(b); i<i##_len; i++)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define int long long
using namespace std;
using P = pair<int, int>;
using ll = long long;
using prique = priority_queue<int>;
const ll INF = LLONG_MAX/3;

/*-----Library-----*/

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

struct UnionFind {
    vector<int> par; // 親ノード
    vector<int> rank; // ランク
    vector<int> sizeuf; //要素数
    UnionFind(int n = 1) {
        init(n);
    }

    void init(int n = 1) {
        par.resize(n); rank.resize(n); sizeuf.resize(n);
        for (int i = 0; i < n; ++i) {
            par[i] = i;
            rank[i] = 0;
            sizeuf[i]=1;
        }
    }

    int root(int x) {
        if (par[x] == x) {
            return x;
        }
        else {
            int r = root(par[x]);
            return par[x] = r;
        }
    }

    bool issame(int x, int y) {
        return root(x) == root(y);
    }

    bool merge(int x, int y) {
        x = root(x); y = root(y);
        if (x == y) return false;
        if (rank[x] < rank[y]) swap(x, y);
        if (rank[x] == rank[y]) ++rank[x];
        par[y] = x;
        sizeuf[x]+=sizeuf[y];
        return true;
    }

    int size(int x){
        return sizeuf[root(x)];
    }
};

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

long long lcm(long long i,long long j){
    return i*(j/gcd(i,j));
}
//コンビネーション
/*
long long fac[MAX], finv[MAX], inv[MAX];
// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
 */
/*-----Library-----*/
const int MOD=1234567;
signed main(){
	int n;
	cin>>n;
	if(n%2==1)cout<<0<<endl;
	else {
		int ans=0;
		int mod=10;
		while(1){
			ans+=n/mod;
			mod*=5;
			if(n/mod==0)break;
		}
		cout<<ans<<endl;
	}
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ll long long
#define pp pair<ll,ll>
#define ld long double
#define all(a) (a).begin(),(a).end()
#define mk make_pair
ll MOD=998244353;
int inf=1000001000;
ll INF=1e18+5;
ll mod=INF;


int main() {
    int n,k;
    cin >> n >> k;
    vector<int> a(n);
    rep(i,n) cin >> a[i];
    sort(all(a));
    int ans=0;
    rep(i,k){
      ans+=a[i];
    }
    cout << ans << endl;
}


Measured memory_bytes: 3624