akhauriyash/Code-Regression huggingface dataset:
# 22-Math_Functions-Distance_II.py

# ??????????????????????????¢
# ???????????????????????????????????????????????????????????????????????¢??§??¬???????????????
# ????????????????????°???????????????????§?????????¨????????§????????????????????????
# ????????§??????????????? n ?¬????????????????
#  x={x1,x2,...,xn} ??¨
#  y={y1,y2,...,yn} 
# ????????¢????¨????????????????????????????

# ????????????????????????????????¢?????¬???????¨?????????¨?????¨??????????¬??????????????????????????????¢?????\????????????????????? 
# Dxy=(???{i=1n}|xi???yi|^p)1/p

# p=1 ?????¨??? 
# Dxy=|x1???y1|+|x2???y2|+...+|xn???yn|

# ??¨?????????????????????????????????????????¢??¨?????°???????????? 

# p=2 ?????¨??? 
# Dxy=(|x1???y1|)2+(|x2???y2|)2+...+(|xn???yn|)2?????????????????????????????????????????????????????????????????????????????????????????????????????????
# ??¨???????????????????????¬?????????????????????????????????????????¢?????????????????? 

# p=??? ?????¨??? 
# Dxy=maxni=1(|xi???yi|)
# ??¨???????????????????????§????????§????????¢??¨?????°????????????

# ????????? n ?¬???????????????????????????????????????§???
# p ??????????????? 1???2???3?????? ?????????????????????????????¢????±???????????????°????????????????????????????????????

# Input
# ??????????????´??° n ????????????????????????
# ???????????????????????? x ???????´? {x1,x2,...xn}{x1,x2,...xn}???
# ???????????????????????? y ???????´? {y1,y2,...yn}{y1,y2,...yn} 
# ????????????????????§???????????????????????\?????????????????´??°?????§??????

# Output
# p ??????????????? 1???2???3?????? ??????????????????????????????????????¢??????????????????????????????
# ????????????0.00001 ??\????????????????????£????????????????????¨????????????

# Constraints
# 1???n???100
# 0???xi,yi???1000
# Sample Input
# 3
# 1 2 3
# 2 0 4
# Sample Output
# 4.000000
# 2.449490
# 2.154435
# 2.000000

n = int(input())
x = list( map(int, input().split()) )
y = list( map(int, input().split()) )
pp=[1.0, 2.0, 3.0, 500.0]


for p in pp:
	if p==500.0:
		print( "{0:.8f}".format( max( [abs(x[i]-y[i]) for i in range(n)] )  ))
	else:
		print( "{0:.8f}".format( sum( [abs(x[i]-y[i])**p for i in range(n)] )**(1./p)  ))

Measured memory_bytes: 7812
import java.io.*;

public class Main {
  public static void main(String[] args){

    try {
      BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
      String line = reader.readLine();
      int x = Integer.parseInt(line);
      int cubedX = x * x * x;
      System.out.println(cubedX);
    } catch (IOException e) {
      System.out.println(e);
    } catch (NumberFormatException e) {
      System.out.println("数字が正しくありません");
    }
  }
}



Measured memory_bytes: 24352
n, m, k = map(int, input().split())
mod = 998244353

ans = 0
comb = 1
for i in range(k+1):
   ans += m * pow(m-1, n-(i+1), mod) * comb
   ans %= mod
   comb *= (n-(i+1)) * pow(i+1, mod-2, mod)
   comb %= mod
print(ans)


Measured memory_bytes: 9192
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include <stdio.h>
#include <queue>
#include <deque>
#include <cstdio>
#include <set>
#include <map>
#include <bitset>
#include <stack>
#include <cctype>
using namespace std;
int main(){
	int n, k;
	int co = 0;
	cin >> n >> k;
	for (int i = 0; i < n; i++) {
		int h;
		cin >> h;
		if (h >= k) {
			co++;
		}
	}
	cout << co << endl;
	return 0;
}

Measured memory_bytes: 384
/**
 * @author torith
 * @date 2018-10-24
 */

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

int main(){

    cin.tie(0);
    ios::sync_with_stdio(false);

    int N;
    cin >> N;
    bool ans = true;
    int t=0,x=0,y=0;
    for (int i = 0; i < N; ++i) {
        int a,b,c;
        cin >> a >> b >> c;
        int diffxy = abs(b - x) + abs(c  - y);
        int difft = a - t;
        if( diffxy > difft || (diffxy - difft) % 2 != 0){
            ans = false;
        }
        t = a; x = b; y = c;
    }

    if (ans) {
        cout << "Yes" << "\n";
    }else{
        cout << "No" << "\n";
    }

    return 0;
}



Measured memory_bytes: 256
import java.util.*;
import java.lang.Math;

public class Main{
	public static void main(String ards[]){
    	Scanner sc = new Scanner(System.in);
 		int N = sc.nextInt();
      	String S1 = sc.next();
      	String S2 = sc.next();
      
      	long ans = 0;
      	int[] dom = new int[N+10];
      	int index=0;
      	for(int i = 0;i<N;i++){
        	if(S1.charAt(i)==S2.charAt(i)){
            	dom[index] = 1;
            }else{
            	dom[index] = 2;
                i++;
            }
        	index++;
        }
      	
      	if(dom[0]==1){
        	ans=3;
        }else if(dom[0]==2){
        	ans=6;
        }
      	for(int i =1;dom[i]!=0;i++){
        	if(dom[i-1]==1){
				ans = ans*2;
            }else if(dom[i-1]==2){
            	if(dom[i]==2){
                	ans = ans*3;
                }
            }
      	ans = ans%1000000007;
        }
      	System.out.println(ans);
    }
}

Measured memory_bytes: 23764
#include <bits/stdc++.h>
#define INF 1e18
#define int long long
#define Rep(i, a, n) for (int i = (a); i < (n); i++)
#define Repr(i, n, a) for (int i = (n); i >= (a); i--)
#define rep(i, n) Rep(i, 0, n)
#define repr(i, n) Repr(i, n, 0)
#define all(a) a.begin(), a.end()
using namespace std;
typedef pair<int, int> P;
typedef pair<int, P> PP;
const int mod = 1000000007;

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

    int n;
    cin >> n;
    vector<int> v;
    for (int i = 2; i <= n; i++)
    {
        bool f = true;
        rep(j, v.size())
        {
            if (i % v[j] == 0)
                f = false;
        }
        if (f)
            v.push_back(i);
    }
    int m = v.size();
    vector<int> cnt(m);
    for (int i = 2; i <= n; i++)
    {
        int num = i;
        rep(j, m)
        {
            while (num % v[j] == 0)
            {
                cnt[j]++;
                num /= v[j];
            }
        }
    }
    //rep(i, m) cout << v[i] << " " << cnt[i] << endl;
    int ans = 1;
    rep(i, m) ans = (ans * (cnt[i] + 1)) % mod;
    cout << ans << endl;
}

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

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

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

    for(int i = 0; i < N; i++) {
        int t; scanf("%d", &t);
        if(t < 0) A.push_back(-t);
        else B.push_back(t);
    }
    reverse(A.begin(), A.end());

    int ans = 1e9;
    for(int i = max(0, K - (int)B.size()); i <= min(K, (int)A.size()); i++) {
        int a = i? A[i - 1] : 0;
        int b = (K - i)? B[K - i - 1] : 0;

        if(a > b) swap(a, b);
        ans = min(ans, 2 * a + b);
    }
    printf("%d", ans);
}


Measured memory_bytes: 1020
#include <bits/stdc++.h>
#define PB push_back
using namespace std;
const int N=200005,M=600005;
int n,rt1,rt2,sz[N],bo[M],re[N],ct=0,vis[N];
struct rec{int to,id;};
vector<rec>e[M];
inline void dfs(int x,int fa)
{
	int i,yy; for(i=0;i<e[x].size();i++){yy=e[x][i].to; if(yy==fa)continue; dfs(yy,x); sz[x]++;}
}
inline void sol(int x)
{
	int i; rec tmp;
	for(i=vis[x];i<e[x].size();i=vis[x])
	{
		tmp=e[x][i]; vis[x]=i+1; if(bo[tmp.id])continue; bo[tmp.id]=1; if(tmp.to==x-n)re[tmp.to]=-1;else if(tmp.to==x+n)re[x]=1; sol(tmp.to);
	}
}
int main()
{
	int i,x; scanf("%d",&n);
	for(i=1;i<=n;i++)
	{
		scanf("%d",&x); if(x==-1)rt1=i; else {e[i].PB((rec){x,++ct}); e[x].PB((rec){i,ct});}
	}dfs(rt1,0);
	for(i=1;i<=n;i++)
	{
		scanf("%d",&x); if(x==-1)rt2=i; else {e[i+n].PB((rec){x+n,++ct}); e[x+n].PB((rec){i+n,ct});}
	}dfs(rt2+n,0);
	for(i=1;i<=n;i++)
	{
		if((sz[i]&1)^(sz[i+n]&1))return 0*printf("IMPOSSIBLE\n"); if(!(sz[i]&1)){e[i].PB((rec){i+n,++ct});e[i+n].PB((rec){i,ct});}
	}e[rt1].PB((rec){2*n+1,++ct}); e[2*n+1].PB((rec){rt1,ct}); e[rt2+n].PB((rec){n*2+1,++ct}); e[n*2+1].PB((rec){rt2+n,ct});
	sol(n*2+1); printf("POSSIBLE\n"); for(i=1;i<=n;i++)printf("%d ",re[i]);
}

Measured memory_bytes: 35572
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0;i < (n);i++)
using ll = long long;
const ll MOD=1000000007;
const long long INF = 1LL << 60;
const double pi=acos(-1.0);

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



int main() 
{
  ll N; cin>>N;
  string c; cin>>c;
  
  vector<ll> white(N+1,0);
  vector<ll> red(N+1,0);
  rep(i,N){
    if(c.at(i)=='W') white.at(i+1)++;
    else red.at(i+1)++;
    white.at(i+1)+=white.at(i);
    red.at(i+1)+=red.at(i);
  }
  
  ll ans=INF;
  rep(k,N){
    chmin(ans,max(white.at(k)-white.at(0),red.at(N)-red.at(k)));
  }
  chmin(ans,white.at(N));
  
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 6824
//ABC064B
#include <bits/stdc++.h>
#include <iostream>
#include <iomanip>
#include <numeric>
#include <math.h>
#include <stdio.h>
#include <climits>
#include <cfloat>
#include <string>
#include <unordered_map>
using namespace std;

int main(){
	int n;
	cin >> n;
	vector<int> a(n);
	for(int i=0;i<n;i++){
		cin >> a.at(i);
	}
	sort(a.begin(),a.end());
	int ans = a.at(n-1)-a.at(0);
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <iomanip>
#include <vector>
#include <deque>
#include <list>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <bitset>
#include <string>
#include <numeric>
#include <algorithm>
#include <functional>
#include <iterator>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <complex>
#include <ctime>
#define ll long long
using namespace std;

int main(){
	int n;
	cin >> n ;
	if(n%1000==0)
    {
        printf("0\n");
        return 0;
    }
	n-=(n/1000)*1000;
	cout << 1000-n << endl ;
	return 0;
}


Measured memory_bytes: 3644
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
signed main() {
  ios::sync_with_stdio(false); cin.tie(0);
  int n, m;
  cin >> n >> m;
  vector<vector<int>> g(n);
  for (int i = 0; i < m; i++) {
    int u, v;
    cin >> u >> v;
    u--;
    v--;
    g[u].push_back(v);
  }
  double ans = 1e18;
  for (int erase = -1; erase < n; erase++) {
    vector<double> dp(n);
    for (int cur = n - 2; cur >= 0; cur--) {
      double sum = 0, mx = 0;
      for (int nxt : g[cur]) {
        sum += dp[nxt];
        mx = max(mx, dp[nxt]);
      }
      if (cur == erase && (int) g[cur].size() > 1) {
        dp[cur] += (sum - mx) / ((int) g[cur].size() - 1) + 1;
      } else {
        dp[cur] += sum / ((int) g[cur].size()) + 1;
      }
    }
    ans = min(ans, dp[0]);
  }
  cout << setprecision(20) << fixed << ans << '\n';
  return 0;
}

Measured memory_bytes: 1408
n = gets.to_i

ary = gets.split(' ').map(&:to_i)

sorted_ary = ary.sort

diff_count = 0;

ary.each_with_index do |n, idx|
  diff_count += 1 if n != sorted_ary[idx]
  break if diff_count > 2
end

if diff_count <= 2
  puts 'YES'
else
  puts 'NO'
end


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

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

using namespace std;

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

	int ans=0;
	rep(_,q){
		int a,k; scanf("%d%d",&a,&k);
		while(a%k!=0){
			int d=a/k+1;
			a-=max((a%k)/d,1)*d;
		}
		ans^=a/k;
	}
	puts(ans>0?"Takahashi":"Aoki");

	return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<iostream>
#include<vector>
#include <algorithm>
using namespace std;

int main(){
    char s;
    cin >> s;
    if (s == 'A'){
        cout << 'T' << endl;
    }
    if (s == 'T'){
        cout << 'A' << endl;
    }
    if (s == 'C'){
        cout << 'G' << endl;
    }
    if (s == 'G'){
        cout << 'C' << endl;
    }
}





Measured memory_bytes: 256
n, k = map(int, input().split())
a = list(map(int, input().split()))

def ok(d):
    m = sorted(a % d for a in a)
    s, e, plus, minus = 0, len(m) - 1, 0, 0
    while True:
        if s > e:
            return (plus == minus)
        if plus <= minus:
            plus += m[s]
            if plus > k:
                return False
            s += 1
        else:
            minus += d - m[e]
            if minus > k:
                return False
            e -= 1
    return False

b = sum(a)
ret = 1
d = 1
while d * d <= b:
    if b % d == 0:
        if ok(d):
            ret = max(ret, d)
        if ok(b // d):
            ret = max(ret, b //d)
    d += 1
print(ret)

Measured memory_bytes: 3064
#define _USE_MATH_DEFINES
#include <iostream>
#include <stdlib.h>
#include <stdio.h>
#include <vector>
#include <algorithm>
#include <functional>
#include <string>
#include <string.h>
#include <math.h>

using namespace std;

int main(){
	int N, Y, x = -1, y = -1, z = -1;
	cin >> N >> Y;

	for (int i = 0; i <= N; ++i){
		if (i * 10000 > Y)
			break;
		for (int j = 0; j <= N - i; ++j){
			if (i * 10000 + j * 5000 + (N - i - j) * 1000 == Y){
				x = i;
				y = j;
				z = N - i - j;
				break;
			}
		}
	}

	cout << x << " " << y << " " << z << endl;

	return 0;
}

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

typedef long long  ll;
int fac[200005], finv[200005];
int mod = 1000000007;

int quick_pow(int a, int b) {
    int res = 1;
    while (b) {
        if (b & 1) res = (ll)res * a % mod;
        a = (ll)a * a % mod;
        b >>= 1;
    }
    return res;
}

ll c(int n, int m){
    return (ll)((ll)fac[n] * finv[m] % mod) * finv[n - m] % mod;
}

int main(){
#ifdef LOCAL
    freopen("./input.txt", "r", stdin);
#endif
    ios_base::sync_with_stdio(false);
    cin.tie(0);

    
    int H,W,A,B;
    cin>>H>>W>>A>>B;
    
    fac[0]=finv[0]=1;
    int n = H+W;
    for(int i=1;i<=n;++i)fac[i]=(ll)fac[i-1]*i%mod;
    finv[n]=quick_pow(fac[n],mod-2);
    for(int i=n-1;i;--i)finv[i]=(ll)finv[i+1]*(i+1)%mod;
    
    ll ans = 0ll;
    for(int i = B+1; i<= W;i++){
        ans = (ans + ((ll)c(H+i-A-2,i-1)*c(A+W-i-1,A-1))%mod)%mod;
    }
    cout<<ans<<endl;
    
    return 0;
}



Measured memory_bytes: 1792
#include<iostream>
#include<vector>
#include<assert.h>
#include<algorithm>

using namespace std;

#define ll long long int

ll gcd(ll a, ll b) {
    ll tmp,r;
    if (a < b) {
        tmp = a;
        a = b;
        b = tmp;
    }
    ll c=a;
    ll d=b;
    r = a % b;
    while(r!=0) {
        a = b;
        b = r;
        r = a % b;
    }
    return (c/b)*(d);
}

int main(void) {
    ll i;
    ll n;
    cin >> n;
    ll T[n];
    for (i=0; i<n; i++) {
        cin >> T[i];
    }
    for (i=1; i<n; i++) {
        T[i] = gcd(T[i],T[i-1]);
    }
    cout << T[n-1] << endl;
    return 0;
}


Measured memory_bytes: 256
n, a, b = map(int, input().split())
def mod_comb(n, r, mod):
    ans = 1
    for i in range(1, r + 1):
        ans *= n - (i - 1)
        ans %= mod
        ans *= inv[i]
        ans %= mod
    return int(ans)
p = 10 ** 9 + 7
N = 10 ** 6  # N は必要分だけ用意する
fact = [1, 1]
factinv = [1, 1]
inv = [0, 1]
 
for i in range(2, N + 1):
    fact.append((fact[-1] * i) % p)
    inv.append((-inv[p % i] * (p // i)) % p)
    factinv.append((factinv[-1] * inv[-1]) % p)
import math
mod = 10 ** 9 + 7
res = pow(2, n, mod) - 1 - mod_comb(n, a, mod) - mod_comb(n, b, mod)
print(res % mod)


Measured memory_bytes: 122064
#include <iostream>
#include <string>
#include <cmath>
#include <cstdlib>
#include <vector>
#include <algorithm>

using namespace std;

int main()
{
	int n;
	cin >> n;
	int data[101];
	for (int i = 0; i < n; i++) {
		cin >> data[i];
	}

	sort(data,data + n, greater<>());
	int sumA = 0;
	int sumB = 0;
	for (int i = 0; i < n; i++) {
		if (i % 2 == 0) {
			sumA += data[i];
		}
		else {
			sumB += data[i];
		}
	}
	cout << sumA - sumB << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int x[1180][118][118],n,m,p,a,b,c;
int main(){
	while(true){
		memset(x,0,sizeof(x));
		cin>>n>>m>>p;if(!n){break;}
		for(int i=0;i<m;i++){
			cin>>a>>b>>c;
			x[a][b][c]=1;x[a][c][b]=1;
		}
		for(int i=1000;i>0;i--){
			for(int j=1;j<=n;j++){
				if(x[i][p][j]==1){
					p=j;
					break;
				}
			}
		}
		cout<<p<<endl;
	}
}

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


ll gcd(ll A, ll B) {
  if (A < B) {
    swap(A, B);
  }
  if (B == 0) {
    return A;
  }
  return gcd(B, A % B);
}

int main() {
  int N;
  cin >> N;
  vector<ll> A(N);
  bool zero_in_A = false;
  int minus_count = 0;
  ll min_v = pow(10, 9) + 1;
  for (int i = 0; i < N; ++i) {
    cin >> A.at(i);
    if (A.at(i) == 0) {
      zero_in_A = true;
    } else {
      min_v = min(min_v, abs(A.at(i)));
    }
    
    if (A.at(i) < 0) {
      ++minus_count;
    }
  }
  
  ll result = 0;
  for (int i = 0; i < N; ++i) {
    result += abs(A.at(i));
  }
  if (!zero_in_A && minus_count % 2 == 1) {
    result -= min_v * 2;
  }
  cout << result << endl;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (int) n; i++)
using ll = long long;
template <class T>
using vt = vector<T>;
using vvi = vector<vector<int>>;

int main() {
  int n,a,b;
  cin >> n >> a >> b;

  cout << min(a*n,b);
  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <algorithm>
#include <iostream>
#include <map>
#define maxn 100005
using namespace std;
map<string,int>q;
int main()
{
    int n;
    long long ans=0;
    char a[maxn][11];
    scanf("%d",&n);getchar();
    for(int i=0;i<n;i++)
    {
        scanf("%s",a[i]);
        sort(&a[i][0],&a[i][10]);
        if(q[a[i]]>=1) ans+=q[a[i]];
        q[a[i]]+=1;
    }
    printf("%lld\n",ans);
    return 0;
}


Measured memory_bytes: 12288
#include<iostream>
#include<math.h>
#include<vector>
#include<algorithm>
#include<numeric>
#include<map>
#include<queue>
#include<deque>
#include<set>
#include<cstdio>
#include<cstring>
#include<string>
using namespace std;

int main(){
    int N;cin>>N;
    int K;cin>>K;
    int h[100010];
    for(int i=1;i<=N;i++)cin>>h[i];

    int dp[100010];
    dp[1]=0;

    //漸化式
    for(int i=2;i<=N;i++){
        dp[i]=pow(10,9);
        for(int k=1;k<=K;k++){
            if(i-k>0)
                dp[i]=min(dp[i],dp[i-k]+abs(h[i]-h[i-k]));
            else break;
        }
    }

    cout<<dp[N]<<endl;
    return 0;

}


Measured memory_bytes: 1024
fun main(args: Array<String>) {
    val s = readLine()!!
    var max = 0
    var tmp = 0
    for (i in s) {
        if (i == 'A' || i == 'C' || i == 'G' || i == 'T') {
            tmp++
        } else {
            max = Math.max(tmp, max)
            tmp = 0
        }
    }
    println(Math.max(tmp, max))
}


Measured memory_bytes: 33696
#include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <iostream>
#include <sstream>
#include <functional>
#include <map>
#include <string>
#include <cstring>
#include <vector>
#include <queue>
#include <stack>
#include <deque>
#include <set>
#include <list>
#include <numeric>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll> P;
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const ll INF = 1LL<<29;
const ll mod = 1e9+7;
#define rep(i,n) for(int (i)=0;(i)<(ll)(n);++(i))
#define repd(i,n,d) for(ll (i)=0;(i)<(ll)(n);(i)+=(d))
#define all(v) (v).begin(), (v).end()
#define pb(x) push_back(x)
#define mp(x,y) make_pair((x),(y))
#define mset(m,v) memset((m),(v),sizeof(m))
#define chmin(x,y) (x=min(x,y))
#define chmax(x,y) (x=max(x,y))
#define fst first
#define snd second
#define UNIQUE(x) (x).erase(unique(all(x)),(x).end())
template<class T> ostream &operator<<(ostream &os, const vector<T> &v){int n=v.size();rep(i,n)os<<v[i]<<(i==n-1?"":" ");return os;}
#define N 110
#define M 1100
ll g[N][N], n, m;
ll a[M], b[M], c[M];
int main(){
	cin>>n>>m;
  rep(i, N) fill(g[i], g[i]+N, INF);
  rep(i, n) g[i][i] = 0;
  rep(i, m){
    cin>>a[i]>>b[i]>>c[i]; a[i]--; b[i]--;
    g[a[i]][b[i]] = g[b[i]][a[i]] = c[i];
  }
  rep(k, n) rep(i, n) rep(j, n) chmin(g[i][j], g[i][k]+g[k][j]);
  int res = 0;
  rep(i, m){
    int r = 1;
    rep(j, n) if(g[a[i]][j]==c[i]+g[b[i]][j] || g[b[i]][j]==c[i]+g[a[i]][j]) r = 0;
    res += r;
  }
  cout<<res<<endl;
	return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;

int main()
{	
	int n,m,ans=0;
	string s;
	map<string,int>mp;
	cin>>n;
	for(int i=0;i<n;i++)
	{
		cin>>s;
		mp[s]++;
	}
	cin>>m;
	for(int i=0;i<m;i++)
	{
		cin>>s;
		mp[s]--;
	}
	for(auto i=mp.begin();i!=mp.end();i++) 
	{
		ans=max(i->second,ans);
	}
	cout<<ans<<endl;
	return 0;	
}

Measured memory_bytes: 256
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <algorithm>
#include <numeric>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <functional>
#define _USE_MATH_DEFINES
#include <cmath>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <cfloat>
#include <cmath>
#include <ctime>
#include <cstdio>
#include <cassert>
using namespace std;

#define EPS 1e-12
#define ull unsigned long long
#define ll long long
#define VI vector<ll>
#define PII pair<ll, ll> 
#define VVI vector<vector<ll> >
#define REP(i,n) for(int i=0,_n=(n);(i)<(int)_n;++i)
#define RANGE(i,a,b) for(int i=(int)a,_b=(int)(b);(i)<_b;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
#define ALLR(c) (c).rbegin(), (c).rend()
#define PB push_back
#define MP(a, b) make_pair(a, b)
#define POPCOUNT __builtin_popcount
#define POPCOUNTLL __builtin_popcountll
#define CLEAR(table, v) memset(table, v, sizeof(table));
#define PRINT1(table, D0) REP(d0, D0) cout<<table[d0]<<" "; cout<<"\n";
#define PRINT2(table, D0, D1) REP(d0, D0) { REP(d1, D1) cout<<table[d0][d1]<<" "; cout<<"\n"; }
#define PRINT3(table, D0, D1, D2) REP(d0, D0) { REP(d1, D1) { REP(d2, D2) cout<<table[d0][d1][d2]<<" "; cout<<"\n"; } cout<<"\n"; }
#define UNIFORM_DOUBLE(a, b) (((b-a)*(double)rand()/RAND_MAX)+a) // [a, b) 
#define UNIFORM_LL(a, b) (ll)UNIFORM_DOUBLE(a, b) // [a, b) 
#define IN(v, lo, hi) ((lo)<=(v) && (v)<(hi))
#define DD(v) cout<<#v<<": "<<v<<endl
template <typename T0, typename T1> std::ostream& operator<<(std::ostream& os, const map<T0, T1>& v) { for( typename map<T0, T1>::const_iterator p = v.begin(); p!=v.end(); p++ ){os << p->first << ": " << p->second << " ";} return os; }
template <typename T0, typename T1> std::ostream& operator<<(std::ostream& os, const pair<T0, T1>& v) { os << v.first << ": " << v.second << " "; return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const vector<T>& v) { for( int i = 0; i < (int)v.size(); i++ ) { os << v[i] << " "; } return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const vector<vector<T> >& v) { for( int i = 0; i < (int)v.size(); i++ ) { os << v[i] << endl; } return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const set<T>& v) { vector<T> tmp(v.begin(), v.end()); os << tmp; return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const deque<T>& v) { vector<T> tmp(v.begin(), v.end()); os << tmp; return os; }

#define MOD 1000000007LL
#define INF (1LL<<60)

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll N,A,B;
	while(cin>>N) {
		VI A(N), B(N);
		vector<pair<ll, pair<ll, ll>>> d(N);
		REP(i, N) {
			cin>>A[i]>>B[i];
			d[i] = MP(A[i]+B[i], MP(A[i], i));
		}
		sort(ALLR(d));
//		DD(d);
		ll ans = 0;
		REP(i, N) {
			ll idx = d[i].second.second;
			ans += (i&1)==0 ? A[idx] : -B[idx];
		}
		
		cout<<ans<<endl;
	}
	
	return 0;
}


Measured memory_bytes: 4224
#pragma comment(linker, "/stack:247474112")
#pragma GCC optimize("Ofast")

#include <bits/stdc++.h>
#define REP(i, n) for(ll i = 0; i < n; ++i)
#define RANGE(i, x, n) for(ll i = x; i < n; ++i)
using namespace std;
typedef long long ll;
const int INF = 0x3f3f3f3f;

void accelerate()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
}

int main()
{
    accelerate();

    ll N;
    cin >> N;
    ll ans = 0;
    for(ll x = 2; x*x <= N; ++x) {
        if(N%x == 0) {
            ll m = x-1;
            if(N/(m+1) == N/m) ans += m;

            if(x*x != N) {
                ll m = N/x-1;
                if(N/(m+1) == N/m) ans += m;
            }
        }
    }
    if(N != 1 && N/(N-1) == 1) ans += N-1;
    cout << ans << endl;
}


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

#define int long long
#define ll long long
#define f1(i,a,b) for(int i=a;i<b;i++)
#define f2(i,a,b) for(int i=a;i>=b;i--)
#define endl '\n'
#define pb push_back
#define gp " "
#define ff first
#define ss second
#define mp make_pair

const int mod=1000000007;
ll temp;

int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    
    int n, x, y;
    cin>>n>>x>>y;
    
    int ans[n];
    memset(ans,0,sizeof(ans));

    f1(i,1,n+1)
    {
        f1(j,i+1,n+1)
        {
            temp = min( j-i, abs(x-i)+abs(y-j)+1 );
            ans[temp]++;
        }
    }

    f1(i,1,n)
    cout<<ans[i]<<endl;

    return 0;
}

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

int main(){
    //入力
    int d;
    cin>>d;
    vector<int> c;
    int all_c=0;
    int tmp;
    rep(i,26){
        cin>>tmp;
        c.push_back(tmp);
        all_c+=tmp;
    }
    vector<vector<int>> s(d, vector<int>(26));
    rep(i,d){
        rep(j,26){
            cin>>s.at(i).at(j);
        }
    }

    //初期化
    vector<int> last;
    rep(i,26){
        last.push_back(0);
    }

    //コンテスト入力
    int score=0;
    int contest;
    int complain;
    rep(i,d){
        cin>>contest;
        complain=0;
        rep(j,26){
            if(j!=(contest-1)){
                last[j]+=1;
                complain+=c[j]*last[j];
            }else{
                last[j]=0;
            }
        }
        score = score + s[i][contest-1] - complain;
        cout<<score<<endl;
    }


   return 0;

}


Measured memory_bytes: 3684
#include<iostream>
#include<vector>
#include<algorithm>
#include<set>
using namespace std;

int A,B,C,D,E,F;
vector<int> water,sugar;
set<int> st;
set<int> ::iterator it;

int main () {
    cin >> A >> B >> C >> D >> E >> F;
    for(int i=0; i<F; i+= 100*A) {
        for(int j=0; j<F; j+=100*B) {
            if( i+j > F || i+j <= 0 ) continue;
            st.insert(i + j);
        }
    }
    for(it=st.begin();it!=st.end();it++) water.push_back((*it));
    st.clear();
    for(int i=0; i<F; i+=C) {
        for(int j=0; j<F; j+=D) {
            if( i+j > F || i+j <= 0) continue;
            st.insert(i + j);
        }
    }
    for(it=st.begin();it!=st.end();it++) sugar.push_back((*it));

    int x=0;
    int y=0;
    double prev = 0;
    for(int i=0; i<water.size(); i++) {
        for(int j=0; j<sugar.size(); j++) {
            double sum = sugar[j] + water[i];
            if(sum > F ||  sugar[j] > water[i] / 100 * E) continue;
            double node = sugar[j] / sum ;
            if( node > prev ) {
                prev = node;
                x = sum;
                y = sugar[j];
            }
        }
    }
    if(x==0) x=100 * min(A,B);
    cout << x << " " << y << endl;
    return 0;
}

Measured memory_bytes: 384
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.*;

public class Main {
    public static void main(String[] args) {
        PrintWriter out = new PrintWriter(System.out);
        InputStreamScanner in = new InputStreamScanner(System.in);
        new Main().solve(in, out);
        out.flush();
    }

    private void solve(InputStreamScanner in, PrintWriter out) {
        out.println("aeiou".contains(in.next()) ? "vowel" : "consonant");
    }

    static class InputStreamScanner {

        private InputStream in;

        private byte[] buf = new byte[1024];
        private int len = 0;
        private int off = 0;

        InputStreamScanner(InputStream in)	{
            this.in = in;
        }

        String next() {
            StringBuilder sb = new StringBuilder();
            for (int b = skip(); !isSpace(b);){
                sb.appendCodePoint(b);
                b = read();
            }
            return sb.toString();
        }

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

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

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

        char nextChar() {
            return (char)skip();
        }

        int skip() {
            for (int b; (b = read()) != -1;) {
                if (!isSpace(b)) {
                    return b;
                }
            }
            return -1;
        }

        private boolean isSpace(int c) {
            return c < 33 || c > 126;
        }

        private int read() {
            if (len == -1) {
                throw new InputMismatchException("End of Input");
            }
            if (off >= len){
                off = 0;
                try {
                    len = in.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException(e.getMessage());
                }
                if (len <= 0) {
                    return -1;
                }
            }
            return buf[off++];
        }
    }
}

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

#define rep(i,a,b) for(auto i=(a); i<(b); ++i)
#define trav(a,x) for(auto& a: x)
#define all(x) begin(x),end(x)
#define sz(x) (int)size(x)
#define PB push_back
using ll = long long;
using ld = long double;
using pii = pair<int,int>;
using vi = vector<int>;

struct edge{int to;};
using graph = vector<vector<edge>>;

const int INF = 1031231234;

struct ST {
  int s;
  vi v;
  ST() = default;
  ST(int n, int init) : s{n}, v(2 * n, init) {}
  auto query(int p) {
    auto res = INF;
    for (p += s; p; p >>= 1)
      res = min(res, v[p]);
    return res;
  }
  auto update(int l, int r, int val) {
    for (l += s, r += s; l <= r; (++l) >>= 1, (--r) >>= 1) {
      if (l & 1) v[l] = min(val, v[l]);
      if (~r & 1) v[r] = min(val, v[r]);
    }
  }
};

int main() {
  cin.sync_with_stdio(0); cin.tie(0);
  cin.exceptions(cin.failbit);

  int n, q;
  cin >> n >> q;

  ll res = (ll)(n - 2) * (n - 2);
  vector<ST> st(2);
  rep(t, 0, 2) st[t] = ST(n + 1, n - 1);
  rep(it, 0, q) {
    int t, p;
    cin >> t >> p;
    --t; --p;
    auto t2 = 1 - t;
    auto upto = st[t].query(p);
    res -= upto - 1;
    st[t2].update(0, upto, p);
  }
  cout << res << '\n';
}


Measured memory_bytes: 6332
import std.stdio;
import std.conv;
import std.string;
import std.typecons;
import std.algorithm;
import std.array;
import std.range;
import std.math;
import std.regex : regex;
import std.container;
import std.bigint;


void main()
{
  readln;
  auto p = readln.chomp.split.map!(to!int).array;
 
 int cnt;
  foreach (i; 0..p.length-1) {
    if (i+1 == p[i]) {
      swap(p[i], p[i+1]);
      cnt++;
    }
  }

  if (p.length == p[$-1]) {
    swap(p[$-2], p[$-1]);
    cnt++;
  }

  cnt.writeln;
}


Measured memory_bytes: 4156
n=int(input())+1
u=[0 for i in range(n)]
for i in range(2,n):
  for j in range(2,n):
    while i%j==0:
      i=i//j
      u[j]+=1
a=1
for i in range(n):
  a*=u[i]+1
print(a%(10**9+7))

Measured memory_bytes: 3060
#include <iostream>
#include <math.h>
using namespace std;

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

  if(x == 1){
    cout << 1 << endl;
    return 0;
  }

  for(int i = x; i >= 1; i--){
    for(int j = 2; j <= sqrt(x); j++){
      if(i % j == 0){
        int y = i / j;
        while(y % j == 0){
          y /= j;
          if(y == 1){
            cout << i << endl;
            return 0;
          }
        }
      }
    }
  }

  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <string>
#include <stack>
#include <vector>
#include <math.h>
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <map>
#include <set>
#include <queue>
#include <list>
#include <regex>
using namespace std;
using pii  = pair<int,int>;
using ll=long long;
using ld=long double;
#define pb push_back
#define mp make_pair
#define stpr setprecision
#define cYES cout<<"YES"<<endl
#define cNO cout<<"NO"<<endl
#define cYes cout<<"Yes"<<endl
#define cNo cout<<"No"<<endl
#define rep(i,n) for(ll i=0;i<(n);++i)
#define Rep(i,a,b) for(ll i=(a);i<(b);++i)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define rRep(i,a,b) for(int i=a;i>=b;i--)
#define crep(i) for(char i='a';i<='z';++i)
#define psortsecond(A,N) sort(A,A+N,[](const pii &a, const pii &b){return a.second<b.second;});
#define ALL(x) (x).begin(),(x).end()
#define debug(v) cout<<#v<<":";for(auto x:v){cout<<x<<' ';}cout<<endl;
#define endl '\n'
int ctoi(const char c){
  if('0' <= c && c <= '9') return (c-'0');
  return -1;
}
ll gcd(ll a,ll b){return (b == 0 ? a : gcd(b, a%b));}
ll lcm(ll a,ll b){return a*b/gcd(a,b);}
constexpr ll MOD=1000000007;
constexpr ll INF=1000000011;
constexpr ll MOD2=998244353;
constexpr ll LINF = 1001002003004005006ll;
constexpr ld EPS=10e-8;
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; }
template<typename T> istream& operator>>(istream& is,vector<T>& v){for(auto&& x:v)is >> x;return is;}
template<typename T,typename U> istream& operator>>(istream& is, pair<T,U>& p){ is >> p.first; is >> p.second; return is;}
template<typename T,typename U> ostream& operator>>(ostream& os, const pair<T,U>& p){ os << p.first << ' ' << p.second; return os;}
template<class T> ostream& operator<<(ostream& os, vector<T>& v){
    for(auto i=begin(v); i != end(v); ++i){
        if(i !=begin(v)) os << ' ';
        os << *i;
    }
    return os;
}

int main(){
  ll A,B;
  cin >> A >> B;
  cout << (A+B)%24 << endl;
}

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

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

    int n;
    cin >> n;

    int a[n];
    rep(i, n) cin >> a[i];

    int ptr = 0;
    int res = 0;
    bool flg = false;

    rep(i, 2*n){
        if(a[ptr]==2){
            ++res;
            flg = true;
            break;
        }
        ptr = a[ptr]-1;
        ++res;
    }

    if(flg) cout << res << endl;
    else cout << -1 << endl;
}

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

int main() {
    ll x, k, d;
    cin >> x >> k >> d;
    ll ans;
    
    if (k <= abs(x/d)) {
        ans = abs(x) - (k * d);
    } else {
        if ((k - abs(x/d)) % 2 == 0) {
            ans = abs(x) - (d * abs(x/d));
        } else {
            ans = abs(x) - (d * abs(x/d))-d;
            ans = abs(ans);
        }
    }
    cout << abs(ans) << endl;
    
    return 0;
    
    
}

Measured memory_bytes: 3640
#include <iostream>
#include <vector>
#include <list>
#include <algorithm>
#include <set>
#include <queue>
#include <stack>
#include <string>
#include <sstream>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>

#define rep(i, n) for(int i = 0; i < n; i ++)
#define COUNT(i, n) for(int i = 1; i <= n; i ++)
#define ITER(c) __typeof((c).begin())
#define each(c, it) for(ITER(c) it =(c).begin(); it!=(c).end(); it++)
#define ALL(c) c.begin(), c.end()
#define mp make_pair
#define pb push_back
#define MEMSET(v, h) memset((v), h, sizeof(v))
#define X first
#define Y second

using namespace std; 

typedef pair<int, int> pii;
typedef long long ll;
typedef vector<int> vi;
typedef vector<string> vs;

const int INF = 1 << 24;
const string p = "<v>^";
const int dx[4] = {-1,  0,  1,  0};
const int dy[4] = { 0,  1,  0, -1};

char m[101][101];

int main(void){
    map<char, pii> dir;
    rep(i, 4) dir[p.at(i)] = mp(dx[i], dy[i]);

    for(int h, w; cin >> h >> w, h;){
        rep(y, h) cin >> m[y];

        pii curP = mp(0, 0);
        char cur; int cnt = 0;
        while((cur = m[curP.Y][curP.X]) != '.'){
            curP.X += dir[cur].X;
            curP.Y += dir[cur].Y;

            if(w * h < ++cnt){
                cout << "LOOP" << endl;
                cnt = -1;
                break;
            }
        }
        if(~cnt) cout << curP.X << ' ' << curP.Y << endl;
    }
 
    return 0;
}

Measured memory_bytes: 1216
import bisect
n=int(input())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
sumA = sum(A)
sumB = sum(B)
if sumA<sumB:exit(print(-1))
surplus = [0]*n
for i in range(n):
    surplus[i] = A[i]-B[i]
surplus.sort()

index_zero = bisect.bisect_left(surplus,0)
reqt = sum(surplus[:index_zero])
ans = index_zero
index_ = n-1
#print(surplus, index_zero, reqt)
while reqt < 0:
    reqt += surplus[index_]
    index_ -= 1
    ans += 1
print(ans)


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

#define vec(v) vector<int>(v)
#define be(v) (v).begin(), (v).end()
#define pb(q) push_back(q)
#define mapci(mp) map<char*,int>(mp)
#define mapcc(mp) map<char*,char*>(mp)
typedef long long ll;
using namespace std;

int main(){
	string s;
	int g=0,p=0;
	cin>>s;
	int n=s.length();
	for(int i=0;i<n;i++){
		if(s[i]=='g'){
			g++;
		}
		else{
			p++;
		}
	}
	if(n%2==0){
		cout <<(g-p)/2<<endl;
	}
	else{
		cout << (g-p-1)/2<<endl;
	}
	return 0;
}

Measured memory_bytes: 512
n = int(input())
A_list = [int(i) for i in input().split()]
S = 0
ans = ""
for i, a in enumerate(A_list):
  S += a*(-1)**i
ans += str(S) + " "
for i, a in enumerate(A_list[:-1]):
  S = -S + 2*a
  ans += str(S) + " "
print(ans[:-1])

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

int main() {
    
    int n;
    cin >> n;
    int s = 0;
    for (int i=0; i<n; i++) {
		int a, b;
		cin >> a >> b;
		s += (b - a + 1);
	}
	cout << s << endl;
    
}


Measured memory_bytes: 256
/*********************
*  Author: xuziyuan  * 
*********************/
 
#include <bits/stdc++.h>
 
#define rep(i,n) for(int i=0;i<n;i++)
#define repn(i,n) for(int i=1;i<=n;i++)
#define LL long long
#define pii pair <LL,LL>
#define fi first
#define se second
#define pb push_back
#define mpr make_pair
 
using namespace std;
 
LL n,m,x,y,re[60],ans=0;
vector <pii> g[60];
bool vis[60];
 
bool dfs(LL pos,LL to,LL k)
{
  vis[pos]=true;
  if(pos==to) return true;
  rep(i,g[pos].size())
  {
    if(vis[g[pos][i].fi]) continue;
    if(dfs(g[pos][i].fi,to,k))
    {
      re[k]|=(1LL<<g[pos][i].se);
      return true;
    }
  }
  return false;
}
 
int main()
{
  cin>>n;
  rep(i,n-1)
  {
    cin>>x>>y;
    g[x].pb(mpr(y,i+1));
    g[y].pb(mpr(x,i+1));
  }
  cin>>m;
  rep(i,m)
  {
    cin>>x>>y;
    memset(vis,0,sizeof(vis));
    dfs(x,y,i);
  }
  repn(i,(1<<m)-1)
  {
    LL num=0,now=0;
    rep(j,m)
    {
      if((i&(1<<j))==0) continue;
      now|=re[j];
      num++;
    }
    LL c=0;
    while(now>0)
    {
      c+=now%2;
      now/=2;
    }
    LL res=(LL)pow(2,n-1-c);
    if(num%2==1) ans+=res;
    else ans-=res;
  }
  cout<<(LL)pow(2,n-1)-ans<<endl;
  return 0;
}

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

int main(){
  int N;
  cin >> N;
  vector<int64_t> A(N),B(N),C(N);
  for(int i=0;i<N;i++){
    cin >> A.at(i);
  }
  for(int i=0;i<N;i++){
    cin >> B.at(i);
  }
  for(int i=0;i<N;i++){
    cin >> C.at(i);
  }
  sort(A.begin(),A.end());
  sort(B.begin(),B.end());
  sort(C.begin(),C.end());
  vector<int64_t> sum(N+1);
  sum.at(0)=0;
  int j=0;
  for(int i=0;i<N;i++){
    sum.at(i+1)=sum.at(i);
    for(;j<N;j++){
      if(B.at(i)<C.at(j)){
        sum.at(i+1)+=C.size()-j;
        break;
      }
    }
  }
  int64_t ans=0;
  j=0;
  for(int i=0;i<N;i++){
    for(;j<N;j++){
      if(A.at(i)<B.at(j)){
        ans+=sum.at(N)-sum.at(j);
        break;
      }
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 6404
#include<bits/stdc++.h>
#include<numeric>
#include<cassert>
//#include <boost/multiprecision/cpp_int.hpp>
#define ll long long int
#define CON 100010
const long long mod=1e9+7;
const int INF=1001001001;
const int inf=100000;
//const ll inf=1e9+7;
//const ll ful=1e18;
using namespace std;
//namespace mp = boost::multiprecision;
int main() 
{
	int n;
	cin>>n;
	vector<double> v(n);
	for(int i=0;i<n;i++)
	{
		cin>>v[i];
	}
	sort(v.begin(),v.end());
	for(int i=0;i<n-1;i++)
	{
		v[i+1]=(v[i]+v[i+1])/2;
	}
	printf("%.10f",v[n-1]);
	return 0;
}

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

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


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

#define ul unsigned long int
#define ull unsigned long long
#define li long long int

int main()
{
  string w,t;

  cin>>w;

  ul ct=0;
  cin >> t;
  while (t != "END_OF_TEXT")
  {
    for (ul i=0;i<t.length();i++) t[i]=tolower(t[i]);
    //std::transform(t.begin(), t.end(), t.begin(), tolower);
    ct+=t==w;
    cin >> t;
  }

  cout << ct<<endl;


  return 0;
}



Measured memory_bytes: 3176
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using vl = vector<ll>;
using Map = map<ll,ll>;
using T = tuple<ll,ll,ll>;
using vvl = vector<vector<ll>>;
#define all(v) v.begin(), v.end()
#define print(v) cout<<v<<endl;
#define fi(v) get<0>(v)
#define se(v) get<1>(v)
#define th(v) get<2>(v)
template <typename T> bool chmax(T &a, const T &b){if (a<b){a=b;return 1;}return 0;}
template <typename T> bool chmin(T &a, const T &b){if (a>b){a=b;return 1;}return 0;}
const ll INF=1LL<<60;
const ll MOD=1000000007;


int main(){
    ll N;
    cin >> N;
    vector<ll> A(N+1,0);
    for(ll i=0;i<N;i++)cin>>A[i+1];
    vector<ll> until(N+1,0);
    for(ll i=1;i<=N;i++)until[i]=until[i-1]+A[i];
    Map M;
    for(ll i=0;i<=N;i++)M[until[i]]++;
    ll ans=0;
    for(auto p: M){
        ll x=p.second;
        ans+=x*(x-1)/2;
    }
    print(ans)
    return 0;
}

Measured memory_bytes: 15872
#include <stdio.h>

int main(){
  int n, s, ten, i;
  scanf("%d", &n);
  for(i = 1;i <= n;i++){
    scanf("%d", &s);
    printf("Case %d:\n", i);
    ten = 10;
    while(ten--)
      printf("%d\n", s = s*s / 100 % 10000);
  }
  return 0;
}

Measured memory_bytes: 592
#include <bits/stdc++.h>
typedef long long int ll;
using namespace std;
const ll mod=1e9+7;
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int n;
    cin>>n;
    vector<int>v1,v2;
    for(int i=0;i<n;i++){
        int a;
        cin>>a;
        v1.push_back(a);
    }
    v2=v1;
    sort(v2.rbegin(),v2.rend());
    for(int i=0;i<n;i++){
        if(v1[i]==v2[0])cout<<v2[1]<<endl;
        else cout<<v2[0]<<endl;
    }
    return 0;
    }


Measured memory_bytes: 3444
#include<iostream>
#include<cmath>
#include<algorithm>
#include <cassert>
#include<string>
using namespace std;
int main() {
	int a = 0, b = 0, c = 0, d[100000], e[100000], f = 0, g = 0, h = 0, count = 0;
	char rikka, toka[100000];
	string saya, homu, kyok, mami,mado[100];
	int manji;
	cin >> saya >> homu >> kyok;
	manji = 'A' - 'a';
	saya[0] += manji;
	homu[0] += manji;
	kyok[0] += manji;
	cout << saya[0]<< homu[0]<< kyok[0] ;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define im 2147483647
#define lm 9223372036854775807
#define ll long long
#define vb vector<bool>
#define vi vector<int>
#define vl vector<long long>
#define vvi vector<vector<int>>
#define ii pair<int, int>
#define lower_str(s) transform(s.begin(), s.end(), s.begin(), ::tolower)
#define upper_str(s) transform(s.begin(), s.end(), s.begin(), ::toupper)
#define debug(index, num) cout << "Case #" << index << ": " << num << endl
#define mx(an, na) an = max(an, na)
#define mn(an, na) an = min(an, na)
#define rep(i, a, b) for (long long i = a; i < b; i++)
#define rep2(i, a, b) for (long long i = a; i <= b; i++)
#define repp(i, a, b) for (long long i = a; i >= b; i--)
#define repp2(i, a, b) for (long long i = a - 1; i >= b; i--)
#define be(x) x.begin(), x.end()
#define rbe(x) x.rbegin(), x.rend()
#define pb push_back   

int main () {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int n;
    cin >> n;
    vi v1(n), v2(n), v(n);
    rep(i, 0, n) {
        cin >> v1[i];
        v[i] = i+1;
    }
    rep(i, 0, n) {
        cin >> v2[i];
    }
    int a = 0, b = 0, i = 1;
    do{
        if(v == v1) a = i;
        if(v == v2) b = i;
        i++;
    }while(next_permutation(v.begin(), v.end()));
    cout << abs(a - b);
    return 0;
}

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

#define ll long long
#define pb push_back
#define mp make_pair
#define all(s) s.begin(),s.end()
#define ld long double

using namespace std;

const int maxn = 1e5 + 7;
const ld eps = 1e-6;
const ll inf = 1e9 + 7;

int n;
map<ll,int> m;
ll a[maxn], ans;
set<ll>se;
set<ll>ss;

int main() {
	cin >> n;
	for (int i = 1; i <= n; i++) {
		cin >> a[i];
		m[a[i]] ++;
		if (m[a[i]] == 2) se.insert(a[i]);
		if (m[a[i]] == 4) ss.insert(a[i]);
		if (ss.size() > 1) ss.erase(ss.begin());
		if (se.size() > 2) se.erase(se.begin());
	}
	ll ans1 = 0, ans2 = 0;
	if (se.size() == 2) {
		ans1 = *se.begin();
		se.erase (se.begin());
		ans1 *= *se.begin();
		se.erase (se.begin());
	}
	if (ss.size() == 1) {
		ans2 = *ss.begin();
		ans2 *= *ss.begin();
	}
	cout << max(ans1, ans2);
	return 0;
}


Measured memory_bytes: 7296
def main():
    N = int(input())
    strings = []
    for i in range(N):
        strings.append(input())
    
    ab = 0
    back_a = 0
    front_b = 0
    back_a_front_b = 0
    others = 0
    for i in strings:
        tmp = i
        ret = tmp.find("AB")
        while ret>=0:
            ab += 1
            tmp = tmp[ret+1:]
            ret = tmp.find("AB")
        
        if i[0] =="B" and i[-1]=="A":
            back_a_front_b += 1
        elif i[0] == "B":
            front_b += 1
        elif i[-1] == "A":
            back_a += 1
        else:
            others += 1

    if back_a_front_b == 0:
        print(ab + min([front_b,back_a]))
    elif back_a_front_b == N:
        print(ab + back_a_front_b -1)
    elif  min([front_b,back_a]) > 0:
        print(ab + back_a_front_b + 1 + min([front_b-1,back_a-1]))
    else:
        if back_a == 0 and front_b == 0:
            print(ab + max([back_a_front_b -1, 0]))
        elif back_a == 1 and front_b == 1:
            print(ab + back_a_front_b + 1)
        else:
            print(ab + back_a_front_b)

    #print("\n" + str(ab))
    #print(back_a_front_b)
    #print(back_a)
    #print(front_b)

if __name__ == "__main__":
    main()


Measured memory_bytes: 3700
#include <bits/stdc++.h>
#define mset(a, b) memset(a, b, sizeof(a))
#define mpcy(a, b) memcpy(a, b, sizeof(a))
using namespace std;
typedef long long LL;
const int MAXN = 300005;

template <typename T> inline void read(T &AKNOI) {
	T x = 0, flag = 1;
	char ch = getchar();
	while (!isdigit(ch)) {
		if (ch == '-') flag = - 1;
		ch = getchar();
	}
	while (isdigit(ch)) {
		x = x * 10 + ch - '0';
		ch = getchar();
	}
	AKNOI = flag * x;
}

namespace ModCalculator {
	const int MOD = 1e9 + 7;
	inline void Inc(int &x, int y) {
		x += y; if (x >= MOD) x -= MOD;
	}
	inline void Dec(int &x, int y) {
		x -= y; if (x < 0) x += MOD;
	}
	inline int Add(int x, int y) {
		Inc(x, y); return x;
	}
	inline int Sub(int x, int y) {
		Dec(x, y); return x;
	}
	inline int Mul(int x, int y) {
		return 1LL * x * y % MOD;
	}
	inline int Ksm(int x, int y) {
		int ret = 1;
		for (; y; y >>= 1) {
			if (y & 1) ret = Mul(ret, x);
			x = Mul(x, x);
		}
		return ret;
	}
	inline int Inv(int x) {
		return Ksm(x, MOD - 2);
	}
}
using namespace ModCalculator;

const int ch0[8] = {1, 3, 5, 1, 1, 7, 6, 5};
const int ch1[8] = {2, 4, 6, 1, 2, 2, 6, 5};

char s[MAXN];
int n, dp[MAXN][8];

void solve() {
	scanf("%s", s + 1);
	n = strlen(s + 1);
	dp[0][0] = 1;
	for (int i = 1; i <= n; ++i) {
		for (int j = 0; j < 8; ++j) {
			if (s[i] != '1') {
				Inc(dp[i][ch0[j]], dp[i - 1][j]);
			}
			if (s[i] != '0') {
				Inc(dp[i][ch1[j]], dp[i - 1][j]);
			}
		}
	}
	printf("%d\n", Add(dp[n][2], dp[n][6]));
}

int main() {
	solve();
	return 0;
}


Measured memory_bytes: 13500