akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>

int main(){
        int a,b,c,i,j,k,x,N;
        int tri[3];
        scanf("%d", &N);
        for(i = 0; i < N; i++){
                scanf("%d %d %d", &tri[0], &tri[1], &tri[2]);
                                if(tri[0] > tri [1]){
                                        x = tri[0];
                                        tri[0] = tri[1];
                                        tri[1] = x;
                                }
                                if(tri[1] > tri[2]){
                                        x = tri[1];
                                        tri[1] = tri[2];
                                        tri[2] = x;
                                }
                                if(tri[0] > tri [1]){
                                        x = tri[0];
                                        tri[0] = tri[1];
                                        tri[1] = x;
                                }
                if(tri[0]*tri[0] + tri[1]*tri[1] == tri[2]*tri[2]){
                        printf("YES\n");
                }else{
                        printf("NO\n");
                }
        }
return 0;
}

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

#define int long long
#define form2(i, a, b) for (int i = (a); i < (b); ++i)
#define ford2(i, a, b) for (int i = (a-1); i >= (b); --i)
#define form(i, n) form2(i, 0, n)
#define ford(i, n) ford2(i, n, 0)

#define chmax(x, v) x = max(x, (v))
#define chmin(x, v) x = min(x, (v))
#define fi first
#define se second
#define all(v) v.begin(), v.end()
#define vsz(v) (int)(v.size())

const long long BIG = 1000000000000000000LL;

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;

void solve();
signed main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	solve();
	return 0;
}

void solve()
{
	int x; cin >> x;
	int s = 0;
	int c = 0;
	while (s < x) {
		c++; s += c;
	}
	cout << c << "\n";
}


Measured memory_bytes: 256
var lines = [];

var readline = require('readline');
var NQ; var S; var td
var rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout,
});

rl.on('line', function (x) {
    lines.push(x);
})

rl.on('close', function () {
    NQ = lines[0].split(" ").map(i => Number(i));
    S = lines[1];

    lines.shift(); lines.shift();

    td = lines.map(i => i.split(" "));

    // ゴーレムが落ちる時は，ゴーレムの座標が-1 or S.length+1のとき
    var x = Math.floor(binary_search(-1, S.length, "L"));
    var y = Math.ceil(binary_search(-1, S.length, "R"));
    
    console.log(NQ[0] - (x + 1) - (NQ[0] - y));
});

// direct : 右から落ちる or 左から落ちる
function binary_search(left, right, direct) {

    var center = (left + right) / 2;

    while (left + 1 < right) {

        var N = NQ[0], Q = NQ[1]
        var flag = false;

        center = Math.floor(center);


        for (var i = 0; i < Q; i++) {
            var t = td[i][0], d = td[i][1];

            // 一致したらcenter座標のゴーレムを動かす
            if (S[center] === t) { d === "L" ? center-- : center++; }

            // 左から落ちる
            if (center === -1) {
                left = Math.floor((left + right) / 2);
                center = (left + right) / 2;
                flag = true; break;
            }

            // 右から落ちる
            if (N === center) {
                right = Math.floor((left + right) / 2);
                center = (left + right) / 2;
                flag = true; break;
            }
        }

        // どちらからも落ちない
        if (flag === false) {
            // 左から落ちるゴーレムを探索したい時
            if (direct === "L") {
                right = Math.floor((left + right) / 2);
                center = (left + right) / 2;
            }

            // 右から落ちるゴーレムを探索したい時
            else {
                left = Math.floor((left + right) / 2);
                center = (left + right) / 2;
            }
        }
    }
    
    return (center)
}

Measured memory_bytes: 58824
//author : raghav_0901

#include <bits/stdc++.h>
using namespace std; 
#define int long long int

int n;
int m;
signed main()
{
    cin>>n>>m;
    vector<int> h(n);
    for(int &x:h) cin>>x;
    vector<vector<int>> arr(n+1, vector<int>());
    for(int i=0;i<m;i++)
    {
        int u,v;cin>>u>>v;
        arr[u].push_back(v);
        arr[v].push_back(u);
    }
    int ans=0;
    for(int i=1;i<=n;i++)
    {
        bool fl=1;
        for(int x:arr[i])
        {
            if(!fl) break;
            fl=(h[i-1]>h[x-1]);
        }
        ans+=fl;
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 9796
parseInt(x) = parse(Int, x)

function main()
  n = parseInt(readline())
  a = Array{Int}(n)
  for i in 1:n
    a[i] = parseInt(readline())
  end
  mmm = maximum(a)
  sss = sum(a)
  print(sss-+div(mmm,2))
end

main()

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

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using ii = pair<int, int>;
using vii = vector<ii>;

#define rep(i, n)   for (int i = 0; i < (n); i++)
#define sz(x)       (int)x.size()
#define eb          emplace_back
#define pb          push_back
#define all(x)      x.begin(), x.end()
#define rall(x)     x.rbegin(), x.rend()
#define fi          first
#define se          second

signed main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
#ifdef LOCAL
    freopen("io\\in.txt", "r", stdin);
    freopen("io\\out.txt", "w", stdout);
#endif

    int n;
    cin >> n;
    vi f(1001);
    rep(i, n) {
        int x;
        cin >> x;
        f[x]++;
    }

    ll cnt = 0;
    for (int i = 1; i <= 1000; i++) {
        ll cur = f[i];
        f[i]--;

        for (int j = i / 2 + 1; j <= i; j++) {
            ll cur2 = cur * f[j];
            if (i == j) cur2 /= 2;
            f[j]--;

            for (int k = i - j + 1; k <= j; k++) {
                ll cur3 = cur2 * f[k];
                if (i == k) cur3 /= 3;
                else if (j == k) cur3 /= 2;
                cnt += cur3;
            }

            f[j]++;
        }

        f[i]++;
    }
    
    cout << cnt;

    return 0;
}


Measured memory_bytes: 3556
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using vll = vector<ll> ;
#define all(v) v.begin(),v.end()

int main(){
  ll N;cin>>N;
  vll A(N);rep(i,N)cin>>A[i];
  ll Q;cin>>Q;
  map<int,int> m;
  rep(i,N){
    m[A[i]]++;
  }
  ll ans=accumulate(all(A),0ll);
  rep(i,Q){
    ll b,c;cin>>b>>c;
    ll tmp = m[b];
    m[b]=0;m[c]+=tmp;
    ans = ans - tmp * b + tmp * c;
    cout << ans << endl;
  }
}

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

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

using VS = vector<string>;    using LL = long long;
using VI = vector<int>;       using VVI = vector<VI>;
using PII = pair<int, int>;   using PLL = pair<LL, LL>;
using VL = vector<LL>;        using VVL = vector<VL>;

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))
#define FOR(i, s, e) for (int(i) = (s); (i) < (e); (i)++)
#define FORR(i, s, e) for (int(i) = (s); (i) > (e); (i)--)
#define debug(x) cerr << #x << ": " << x << endl
const int INF = 1e9;                          const LL LINF = 1e16;
const LL MOD = 1000000007;                    const double PI = acos(-1.0);
int DX[8] = { 0, 0, 1, -1, 1, 1, -1, -1 };    int DY[8] = { 1, -1, 0, 0, 1, -1, 1, -1 };

/* -----  2018/03/02  Problem: 087_arc_b / Link: https://abc082.contest.atcoder.jp/tasks/arc087_b?lang=en  ----- */
/* ------問題------

二次元平面の原点にロボットが置かれています。 最初、ロボットは x 軸の正の向きを向いています。
このロボットに命令列 s が与えられます。 s は次の 2 文字のみからなり、先頭から末尾まで順に実行されます。

F : 今向いている向きに長さ 1 だけ移動する。
T : 時計回りまたは反時計回りの好きな方向に 90 度だけ向きを変える。
ロボットの目標は、命令列をすべて実行し終わった後に座標 (x,y) にいることです。 この目標が達成可能か判定してください。

-----問題ここまで----- */
/* -----解説等-----

列を成分ごとに分解するとこれは典型DP
dp(i,j):=i個終えたときに値jが存在する
負の値も存在するけどこれは下駄をはかせればよい。
自分の入力生成が間違ってそう…

----解説ここまで---- */

LL N;

LL ans = 0LL;

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

	string s; cin >> s;
	int x, y;
	cin >> x >> y;
	VI xs(SZ(s)), ys(SZ(s));
	int xp = 0, yp = 0;
	int mode = 0;
	FOR(i, 0, SZ(s)) {

		if (mode == 0) {// x
			if (s[i] == 'T') { mode = 1; xp++; continue; }
			else {
				xs[xp]++;
			}
		}
		else {//y
			if (s[i] == 'T') { mode = 0; yp++; continue; }
			else {
				ys[yp]++;
			}

		}
	}
	if (mode == 0) {// x
		{ mode = 1; xp++; }
	}
	else {//y
		{ mode = 0; yp++; }
	}

	//FOR(i, 0, xp) {
	//	cout << xs[i] << " ";
	//}cout << endl;
	//FOR(i, 0, yp) {
	//	cout << ys[i] << " ";
	//}cout << endl;

	// dp
	vector<vector<bool>> dpx(8000, vector<bool>(20000));
	vector<vector<bool>> dpy(8000, vector<bool>(20000));
	dpx[0][xs[0] + 10000] = 1;
	dpy[0][ys[0] + 10000] = 1;
	dpy[0][-ys[0] + 10000] = 1;

	FOR(i, 0, xp) {
		FOR(j, 0, 20000) {//10000 base
			if (dpx[i][j]) {
				dpx[i + 1][j - xs[i + 1]] = 1;
				dpx[i + 1][j + xs[i + 1]] = 1;
			}
		}
	}
	FOR(i, 0, yp) {
		FOR(j, 0, 20000) {//10000 base
			if (dpy[i][j]) {
				dpy[i + 1][j - ys[i + 1]] = 1;
				dpy[i + 1][j + ys[i + 1]] = 1;
			}
		}
	}
	if (dpx[xp][10000 + x] && dpy[yp][10000 + y]) {
		cout << "Yes" << endl;
	}
	else cout << "No" << "\n";

	return 0;
}


Measured memory_bytes: 40320
X = int(input())
ans = []
if X == 1:
    print(1)
    exit()
for b in range(1, X):
    for p in range(1, X):
        if b ** p <= X:
            ans.append(b ** p)
        elif p == 2:
            print(max(ans))
            exit()
        else:
            break



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

int dh[4] = {0, 1, 0, -1};
int dw[4] = {1, 0, -1, 0};
vector<string> field;

int main() {
  int H,W,i,j,w=0;
  pair<int,int> p;
  cin >> H >> W;
  field.resize(H);
  for(i=0; i<H; i++)
    cin >> field.at(i);
  
  for(i=0; i<H; i++)
    for(j=0; j<W; j++)
      if(field.at(i).at(j) == '.')
        w++;

  vector<vector<int>> d(H, vector<int>(W,-1));
  queue<pair<int,int>> q;

  d.at(0).at(0) = 0;
  q.push(make_pair(0,0));

  while(!q.empty()) {
    p = q.front();
    q.pop();

    for(i=0; i<4; i++) {
      int nh=p.first+dh[i], nw=p.second+dw[i];
      if(nh>=0 && nw>=0 && nh<H && nw<W &&
         field.at(nh).at(nw)=='.' && d.at(nh).at(nw)==-1) {
        d.at(nh).at(nw) = d.at(p.first).at(p.second)+1;
        q.push(make_pair(nh, nw));
      }
    }
  }
  
  if(d.at(H-1).at(W-1) == -1)
    cout << -1;
  else
    cout << w-1-d.at(H-1).at(W-1);
  cout << endl;
}

Measured memory_bytes: 256
import collections

n=int(input())
l=list(map(int,input().split()))
#print(l)
e=[None]*(n//2)
o=[None]*(n//2)
for i in range(n//2):
    e[i]=l[2*i]
    o[i]=l[2*i+1]
#print(e,o)
ce=collections.Counter(e)
co=collections.Counter(o)
ce=ce.most_common()
co=co.most_common()
#print(co)
ce.append((0,0))
co.append((0,0))
if ce[0][0]!=co[0][0]:
    print(n-co[0][1]-ce[0][1])
else:
    print(min(n-ce[1][1]-co[0][1],n-ce[0][1]-co[1][1]))

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

int main() {
	int N;
	cin >> N;
	int ans = 0;
	int num = 0;

	for (int i = 1; i <= N; i++) {
		if (i % 2 == 0) {
			continue;
		}
		num = 0;
		for (int j = 1; j <= i; j++) {
			if (i%j == 0) {
				num++;
			}
		}
		if (num == 8) {
			ans++;
		}
	}

	cout << ans << endl;


	return 0;
}

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

a,b,c,k = li()

if k%2:
    print(b-a)
else:
    print(a-b)

Measured memory_bytes: 3064
n,m = map(int, input().split())
edge = [[] for _ in range(n)]
for i in range(m):
    a,b = map(int, input().split())
    edge[a-1].append(b-1)
    edge[b-1].append(a-1)
#print(edge)

import itertools
l = []
for i in range(1,n):
    l.append(i)
llist = list(itertools.permutations(l))
#print(llist)

ans = 0
for i in range(len(llist)):
    x = [0] + list(llist[i])
    tnp = 0
    for j in range(n-1):
        if not x[j+1] in edge[x[j]]:
            tnp += 1
            break
    if (tnp==0):
        ans += 1
print(ans)
            

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

const int N = 1010;
typedef long long ll;

int n;
ll f[N][N * 30];
struct Node { int w, s; ll v; } a[N];
/*
 设f[i][j]表示前i个，然后总重量为j的最大答案。
 */

bool operator < (Node a, Node b) {
	if(a.s + a.w == b.s + b.w) return a.s < b.s; 
	return a.s + a.w < b.s + b.w; 
}

int main() {
	scanf("%d", &n);
	for(int i = 1; i <= n; ++i) {
		scanf("%d%d%lld", &a[i].w, &a[i].s, &a[i].v);
	}
	sort(a + 1, a + n + 1);
	for(int i = 1; i <= n; ++i) {
		for(int j = 0; j <= a[n].s + a[n].w; ++j) f[i][j] = max(f[i][j], f[i - 1][j]);
		for(int j = 0; j <= a[i].s; ++j) f[i][j + a[i].w] = max(f[i][j + a[i].w], f[i - 1][j] + a[i].v);
	}
	ll ans = 0;
	for(int i = 0; i <= a[n].s + a[n].w; ++i) ans = max(ans, f[n][i]);
	printf("%lld\n", ans);
/*	for(int i = 1; i <= n; ++i) {
		for(int j = 0; j <= a[n].s; ++j) printf("%d ", f[i][j]);
			puts("");
	}*/
}

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

int main () {
    int n;
    cin >> n;
    float total =0;

    for (int i=1; i<=n; i++) {
        int a;
        cin >>a;
        total = total + 1.0/a;
    }

    cout << 1/total << '\n';

}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include <stdio.h>
#include<algorithm>
#include<cstring>
#include <string>
#include<cmath>
#include<cstdlib>
#include<queue>
#include<map>
#include<vector>
#include<bits/stdc++.h>
#include <set>
#define ll   long long
#define IO ios::sync_with_stdio(false);cin.tie();cout.tie(0)
#define inf 0x3f3f3f
#define pi 3.1415926535898
using namespace std;
const int N=2e5+10;
const int mod=1e9+7;
char s[N];
int dp[100050][13];
int main()
{
    cin>>(s+1);
    int n=strlen(s+1);
    dp[0][0]=1;
    for(int i=1;i<=n;i++)
    {
        if(s[i]=='?')
        {
            for(int k=0;k<10;k++)
            {
                for(int j=0;j<13;j++)
                {
                    dp[i][(j*10+k)%13]=(dp[i][(j*10+k)%13]+dp[i-1][j])%mod;
                }
            }
        }
        else
        {
            int k=s[i]-'0';
            for(int j=0;j<13;j++)
            {
                dp[i][(j*10+k)%13]=(dp[i][(j*10+k)%13]+dp[i-1][j])%mod;
            }
        }
    }
    cout<<dp[n][5];
    return 0;
}


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

int main(){
    int N, M;
    cin >> N >> M;
    vector<vector<int>> edge(3*N, vector<int>());
    for (int i = 0; i < M; i++) {
        int u, v;
        cin >> u >> v;
        u--;v--;
        edge[u].push_back(v+N);
        edge[u+N].push_back(v+2*N);
        edge[u+2*N].push_back(v);
    }
    int S, T;
    cin >> S >> T;
    S--;T--;
    int inf = 10*N;
    vector<int> dist(3*N, inf);
    queue<int> q;
    q.push(S);
    dist[S] = 0;
    while (!q.empty()) {
        int now = q.front();
        q.pop();
        for (int nxt : edge[now]) {
            if (dist[nxt] <= dist[now] + 1) continue;
            dist[nxt] = dist[now] + 1;
            q.push(nxt);
        }
    }
    if (dist[T] == inf) cout << -1 << endl;
    else cout << dist[T]/3 << endl;
    return 0;
}

Measured memory_bytes: 17792
#include<bits/stdc++.h>
using namespace std;
int a[1003][1003],b[1003][1003];
int n,k,ans,x,y;
char t;
int s1[1003][1003],s2[1003][1003];
int query(int x,int y)
{
	int ans1=0,ans2=0;
	ans1+=s1[k][k]-s1[x][k]-s1[k][y]+s1[x][y]+s1[x][y];
	ans1+=s2[x][k]+s2[k][y]-s2[x][y]-s2[x][y];
	ans2+=s2[k][k]-s2[x][k]-s2[k][y]+s2[x][y]+s2[x][y];
	ans2+=s1[x][k]+s1[k][y]-s1[x][y]-s1[x][y];
	return max(ans2,ans1);
}
int main()
{
	cin>>n>>k;
	for (int i=1;i<=n;i++)
	{
		cin>>x>>y>>t;
		int tx=x,ty=y;
		x%=k;y%=k;
		if (x==0)x=k;
		if (y==0)y=k;
		if (((abs(tx-x)+abs(ty-y))/k)%2==1)
		{
			if (t=='W')t='B';else t='W';
		}
		if (t=='W')b[x][y]++;else a[x][y]++;
	}
	for (int i=1;i<=k;i++)
	{
		for (int j=1;j<=k;j++)
		{
			s1[i][j]=s1[i-1][j]+s1[i][j-1]-s1[i-1][j-1]+a[i][j];
			s2[i][j]=s2[i-1][j]+s2[i][j-1]-s2[i-1][j-1]+b[i][j];
		}
	}
	for (int i=0;i<=k+1;i++)
	{
		for (int j=0;j<=k+1;j++)
		{
			ans=max(ans,query(i,j));
		}
	}
	cout<<ans;
	return 0;
}


Measured memory_bytes: 16000
import sys
readline = sys.stdin.buffer.readline
n = int(readline())
a = list(map(int, readline().split()))
a.sort()
v = 1
for i in a:
  v *= i
  if v > 1000000000000000000:
    print(-1)
    break
  elif v == 0:
    print(0)
    break
else:
  print(v)

Measured memory_bytes: 20148
n=int(input())
S=list(map(int,input().split()))
q=int(input())
T=list(map(int,input().split()))
ans=0
for t in T:
    num_l=0
    num_r=n-1
    if not S[0]<= t <=S[-1]:
        continue
    while (num_r-num_l)>1:
        num_m=(num_r-num_l)//2+num_l
        if t>S[num_m]:
            num_l=num_m
        elif t<S[num_m]:
            num_r=num_m
        if t in [S[num_l],S[num_m],S[num_r]]:
            ans+=1
            break
print(ans)


Measured memory_bytes: 16708
#include<iostream>
#include<vector>
#include<algorithm>
#include<tuple>
#include<utility>

using namespace std;

typedef long long int64;

int main(void){
    int64 A,B,K;
    cin>>A>>B>>K;
    if (A >= K) {
        cout<<A-K<<" "<<B<<endl;
    } else if (A + B > K ){
        cout<<0<<" "<<B-K+A<<endl;
    } else {
        cout << 0 <<" "<< 0 <<endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define debug(x) cerr << #x << ": " << x << '\n';
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int INF = (int)1e9;
const int MOD = (int)1e9 + 7;

// graph template
template<typename T>
class Edge{
    public:
        int src, to; T cost;

        Edge(int to, T cost): src(-1), to(to), cost(cost){}
        Edge(int src, int to, T cost): src(src), to(to), cost(cost){}

        bool operator==(const Edge &e)const{
            return src==e.src and to==e.to and cost==e.cost;
        }
};
template<typename T>
using Edges = vector<Edge<T>>;
template<typename T>
using AdjacencyList = vector<Edges<T>>;
template<typename T>
using Matrix = vector<vector<T>>;

template<typename T>
vector<T> bellman_ford(Edges<T> &edges, int V, int s){
    const auto INF = numeric_limits<T>::max();
    vector<T> dist(V, INF);
    dist[s] = 0;

    for(int i = 0; i < V - 1; i++){
        for(auto &e: edges){
            if(dist[e.src] == INF) continue;
            dist[e.to] = min(dist[e.to], dist[e.src] + e.cost);
        }
    }

    // for(auto &e: edges){
    //     if(dist[e.src] == INF) continue;
    //     if(dist[e.to] > dist[e.src] + e.cost) return vector<T>();
    // }

    vector<bool> negative(V, false);
    for(int i = 0; i < V; i++){
        for(auto &e: edges){
            if(dist[e.src] == INF) continue;
            if(dist[e.to] > dist[e.src] + e.cost){
                dist[e.to] = dist[e.src] + e.cost;
                negative[e.to] = true;
            }
            if(negative[e.src]) negative[e.to] = true;
        }
    }
    if(negative[V-1]) return vector<T>();

    return dist;
}

int main(void){
    int N, M;
    cin >> N >> M;
    Edges<ll> es;
    for(int i = 0; i < M; i++){
        int a, b, c;
        cin >> a >> b >> c;
        a--; b--;
        es.push_back(Edge<ll>(a, b, (ll)-c));
    }
    
    vector<ll> vec = bellman_ford(es, N, 0);
    if(vec.empty()) cout << "inf" << '\n';
    else cout << -vec[N-1] << '\n';

    return 0;
}

Measured memory_bytes: 256
var lines = []; var result = 0;
var readline = require('readline');

var rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout,
});

rl.on('line', function (x) {
    lines.push(x);
});

rl.on('close', function () {
    var N = Number(lines[0]);
    var a = lines[1].split(" ").map(value => Number(value));

    for (var i = 0; i < N; i++) {
        if (i < a[i]) {
            if (a[a[i] - 1] === i + 1) { result++; }
        }
    }
    console.log(result);
});

Measured memory_bytes: 17228
#include<bits/stdc++.h>
using namespace std;
const int INF = 1 << 30;

int main(){
  int N, M, C[16], x[20000];
  int dp[2][256];
  
  while(scanf("%d %d", &N, &M), N){
    for(int i = 0; i < M; i++){
      scanf("%d", &C[i]);
    }
    for(int i = 0; i < N; i++){
      scanf("%d", &x[i]);
    }
    fill_n( *dp, 2 * 256, INF);
    dp[0][128] = 0;
    for(int i = 0; i < N; i++){
      for(int j = 0; j < 256; j++){
        if(dp[i & 1][j] == INF) continue;
        for(int k = 0; k < M; k++){
          int value = min( 255, max( 0, j + C[k]));
          dp[(i + 1) & 1][value] = min( dp[(i + 1) & 1][value], dp[i & 1][j] + (x[i] - value) * (x[i] - value));
        }
      }
      for(int j = 0; j < 256; j++) dp[i & 1][j] = INF;
    }
    int ret = INF;
    for(int i = 0; i < 256; i++){
      ret = min( ret, dp[N & 1][i]);
    }
    cout << ret << endl;
  }
}

Measured memory_bytes: 1288
/*=====================================
 * Author : ylsoi
 * Problem : ARC97E
 * Algorithm : Inversion_Pair and DP
 * Time : 2018.5.14
 * ==================================*/
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<climits>
using namespace std;
void File(){
	freopen("ARC97E.in","r",stdin);
	freopen("ARC97E.out","w",stdout);
}
#define REP(i,a,b) for(register int i = a;i <= b;++i)
#define DREP(i,a,b) for(register int i = a;i >= b;--i)
#define MREP(i,x) for(register int i = beg[x];i;i = E[i].last)
#define mem(a) memset(a,0,sizeof(a))
#define ll long long
#define inf INT_MAX
const int maxn = 2000 + 10;
int n,c[maxn << 1],a[maxn << 1],pos0[maxn],pos1[maxn];
int dp[maxn][maxn],cost0[maxn << 1][maxn],cost1[maxn << 1][maxn];
int main(){
	//File();
	scanf("%d",&n);
	REP(i,1,n * 2){
		char s[5];
		scanf("%s%d",s,&a[i]);
		c[i]= s[0] == 'W' ? 0 : 1;
		if(c[i] == 0)pos0[a[i]] = i;
		else pos1[a[i]] = i;
	}
	REP(i,1,n * 2)
		REP(j,0,n){
			cost0[i][j] = cost0[i - 1][j] + (a[i - 1] > j && c[i - 1] == 0);
			cost1[i][j] = cost1[i - 1][j] + (a[i - 1] > j && c[i - 1] == 1);
		}
	REP(i,0,n)
		REP(j,0,n){
			if(i == 0 && j == 0)continue;
			int p0 = pos0[i],p1 = pos1[j];
			dp[i][j] = inf;
			if(i)dp[i][j] = min(dp[i][j],dp[i - 1][j] + cost0[p0][i - 1] + cost1[p0][j]);
			if(j)dp[i][j] = min(dp[i][j],dp[i][j - 1] + cost1[p1][j - 1] + cost0[p1][i]);
		}
	printf("%d\n",dp[n][n]);
	return 0;
}

Measured memory_bytes: 79104
#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 (ll i = (ll)(a); i < (ll)(b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
#define ll long long
#define lld long double
#define ALL(x) x.begin(), x.end()
using namespace std;

const double EPS = 1e-3;
const double PI = 3.1415926535897932384626433832795028841971;
const int IINF = 1 << 30;
const ll INF = 1ll << 60;
const ll MOD = 1e9 + 7;
int main()
{
    int n;
    cin >> n;
    vector<ll> v(n);
    rep(i, n)
    {
        cin >> v[i];
    }
    ll ans = 1000;
    ll stock = 0;
    rep(i, n - 1)
    {
        ans += stock * v[i];
        stock = 0;
        if (v[i] < v[i + 1])
        {
            stock = ans / v[i];
            ans %= v[i];
        }
    }
    ans += stock * v[n - 1];
    cout << ans << endl;
    return 0;
}

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

using namespace std;
typedef long long ll;
typedef pair<ll, ll> p_ll;

template<class T>
void debug(T itr1, T itr2) { auto now = itr1; while(now<itr2) { cout << *now << " "; now++; } cout << endl; }
#define repr(i,from,to) for (int i=(int)from; i<(int)to; i++)
#define all(vec) vec.begin(), vec.end()
#define rep(i,N) repr(i,0,N)
#define per(i,N) for (int i=(int)N-1; i>=0; i--)

const ll MOD = pow(10,9)+7;
const ll LLINF = pow(2,61)-1;
const int INF = pow(2,30)-1;

vector<ll> fac;
void c_fac(int x=pow(10,6)+10) { fac.resize(x,true); rep(i,x) fac[i] = i ? (fac[i-1]*i)%MOD : 1; }
ll inv(ll a, ll m=MOD) { ll b = m, x = 1, y = 0; while (b!=0) { int d = a/b; a -= b*d; swap(a,b); x -= y*d; swap(x,y); } return (x+m)%m; }
ll nck(ll n, ll k) { return fac[n]*inv(fac[k]*fac[n-k]%MOD)%MOD; }
ll gcd(ll a, ll b) { if (a<b) swap(a,b); return b==0 ? a : gcd(b, a%b); }
ll lcm(ll a, ll b) { return a/gcd(a,b)*b; }

struct query { ll l, r, x; };
vector<vector<query>> q;

bool check(int r, int g, int b, int to) {
  bool ok = true;
  for (auto x: q[to]) {
    int count = 0;
    if (x.l<=r) count++;
    if (x.l<=g) count++;
    if (x.l<=b) count++;
    ok &= x.x==count;
  }
  // cout << r << "," << g << "," << b << "->" << ok << endl;
  return ok;
}

int main() {
  int N, M; cin >> N >> M;
  q.resize(N);
  rep(i,M) { 
    query tq; cin >> tq.l >> tq.r >> tq.x; tq.l--; tq.r--;
    q[tq.r].push_back(tq);
  }

  int dp[N+1][N+1][N+1] = {}; dp[0][0][0] = 1;
  rep(r,N) rep(g,N) rep(b,N) {
    int to = max(r, max(g,b)) + 1;
    if (check(to-1,g-1,b-1,to-1)) dp[to][g][b] = (dp[to][g][b]+dp[r][g][b]) % MOD;
    if (check(r-1,to-1,b-1,to-1)) dp[r][to][b] = (dp[r][to][b]+dp[r][g][b]) % MOD;
    if (check(r-1,g-1,to-1,to-1)) dp[r][g][to] = (dp[r][g][to]+dp[r][g][b]) % MOD;
  }
  // rep(r,N+1) { rep(g,N+1) debug(dp[r][g],dp[r][g]+N+1); cout << endl; }

  ll result = 0;
  rep(r,N+1) rep(g,N+1) result = (result+dp[r][g][N]) % MOD;
  rep(r,N+1) rep(b,N+1) result = (result+dp[r][N][b]) % MOD;
  rep(g,N+1) rep(b,N+1) result = (result+dp[N][g][b]) % MOD;
  cout << result << endl;
  return 0;
}

Measured memory_bytes: 106752
//g++ -std=c++14 test.cpp -o test.out
//問題URL
//https://atcoder.jp/contests/panasonic2020/tasks/panasonic2020_e
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <iomanip>
#include <vector>
#include <queue>
#include <map> 
#include <utility>
#include <limits.h>
#include <bitset>
#include <set>
using namespace std;
 
#define LL long long int
const LL INF = (LL)(1e18)+1;
const int INF_INT = 2147483647-1e6;
const LL mod = 1000000007ll;

LL N,K;
LL a[100];

LL ans = 0;

void solve(){
	sort(a,a+N);
	//配列の前から見てi人でj個の飴を分け合う方法の数をdp[i][j]とおく
	vector<vector<LL>> dp(N+1,vector<LL>(K+1,0));
	//前から見てi人で0個分け合う方法は絶対に一個しかない
	for(int i=0;i<=N;i++) dp[i][0] = 1;
	LL a_sum = 0;
	for(int i=1;i<=N;i++){
		a_sum += a[i-1];
		for(int j=1;j<=K;j++){
			if(a_sum<j) continue;
			//dp[i-1][j]の後ろには0を追加
			//dp[i][j-1]の一番後ろの要素をインクリメント
			dp[i][j] = (dp[i-1][j] + dp[i][j-1])%mod;
			if(j-a[i-1]-1>=0){
				dp[i][j] = (dp[i][j] - dp[i-1][j-a[i-1]-1] + mod)%mod;
			}
		}
	}
	ans = dp[N][K];
}
 
int main(){
	cin >> N >> K;
	for(int i=0;i<N;i++) cin >> a[i];
 
	solve();

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

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

#define int long long

#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;

template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

struct BinaryIndexedTree{
	int n;
	vector<int>dat;
	BinaryIndexedTree(int n=0):n(n){
		dat.resize(n+1);
	}
	void add(int k,int x){
		for(k++;k<=n;k+=k&-k)dat[k]+=x;
	}
	int sum(int k){
		int ret=0;
		for(k++;k;k-=k&-k)ret+=dat[k];
		return ret;
	}
};

string S;
int N;
int L[111111],R[111111];

int A[111111];

set<int>st[111111];

signed main(){
    cin>>S;
    cin>>N;
    rep(i,N)cin>>L[i]>>R[i];

    int l=S.size()/2;
    rep(i,l){
        A[i]=(S[S.size()-1-i]-S[i]+26)%26;
    }
    rep(i,N){
        L[i]--;
        if(L[i]>S.size()-R[i]){
            L[i]=S.size()-L[i];
            R[i]=S.size()-R[i];
            swap(L[i],R[i]);
        }

        if(R[i]>=(S.size())/2){
            if(S.size()&1){
                int d=R[i]-l;
                R[i]-=d*2-1;
            }
            else{
                int d=R[i]-l;
                R[i]-=d*2;
            }
        }
    }

    rep(i,N)st[L[i]].insert(R[i]);

    BinaryIndexedTree bit(111111);
    rep(i,l){
        int x=A[i]+bit.sum(i);
        x%=26;
        while(st[i].size()&&*st[i].begin()<=i)st[i].erase(st[i].begin());

        if(x!=0&&st[i].size()==0){
            cout<<"NO"<<endl;
            return 0;
        }

        if(st[i].size()==0)continue;
        int r=*st[i].begin();
        bit.add(i,26-x);
        bit.add(r,x-26);

        if(st[i].size()>st[r].size())swap(st[i],st[r]);
        for(auto &w:st[i])st[r].insert(w);
    }

    cout<<"YES"<<endl;
    return 0;
}


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

int main()
{
	char date[10];
	for (int i = 0; i < 10; i++)
	{
		cin >> date[i];
	}
	date[3] = '8';
	for (int i = 0; i < 10; i++)
	{
		cout << date[i];
	}
	return 0;
}

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

int main(){
    int A,B,M;
    cin >> A >> B >> M;
    vector<int> a(A);
    vector<int> b(B);
    vector<int> x(M);
    vector<int> y(M);
    vector<int> c(M);
    vector<int> sum(M);
    for (int i = 0; i < A; i++){
        cin >> a.at(i);
    }
    for (int i = 0; i < B; i++){
        cin >> b.at(i);
    }
    for (int i = 0; i < M; i++){
        cin >> x.at(i) >> y.at(i) >> c.at(i);
        sum.at(i) = a.at(x.at(i) - 1) + b.at(y.at(i) - 1) - c.at(i);
    }
    sort(sum.begin(),sum.end());
    sort(a.begin(),a.end());
    sort(b.begin(),b.end());
    cout << min(a.at(0) + b.at(0),sum.at(0)) << endl;
}

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

#define debug(x) cout << #x << " = " << x << endl
#define fori(i, ini, lim) for(int i = int(ini); i < int(lim); i++)
#define ford(i, ini, lim) for(int i = int(ini); i >= int(lim); i--)

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int, int> ii;

const int MAX = 1e5 + 5;
const int MOD = 1e9 + 7;
int arr[MAX], fat[MAX], pref[MAX];
int n;

inline int add(int a, int b) {
    a += b;
    if(a >= MOD) {
        a -= MOD;
    }
    return a;
}

inline int sub(int a, int b) {
    a -= b;
    if(0 > a) {
        a += MOD;
    }
    return a;
}

inline int mult(int a, int b) {
    return (1LL * a * b) % MOD;
}

int f_exp(int x, int exp) {
    if(exp == 0) {
        return 1;
    }
    else if(exp & 1) {
        return mult(x, f_exp(x, exp - 1));
    }
    return f_exp(mult(x, x), exp / 2);
}

inline int inv(int x) {
    return f_exp(x, MOD - 2);
}

inline int comb(int a, int b) {
    return mult(fat[a], mult(inv(fat[b]), inv(fat[a - b])));
}

int calc(int size) {
    return mult(fat[n - (size + 1)], mult(comb(n, size + 1), fat[size]));
}

int main() {
    fat[0] = 1;
    fori(i, 1, MAX) {
        fat[i] = mult(fat[i - 1], i);
    }
    scanf("%d", &n);
    fori(i, 1, n + 1) {
        scanf("%d", arr + i);
    }
    pref[0] = calc(0);
    fori(i, 1, n) {
        pref[i] = add(pref[i - 1], calc(i));
    }
    int ans = 0;
    fori(i, 1, n + 1) {
        int ls = i - 1;
        int rs = n - i;
        ans = add(ans, mult(arr[i], pref[ls]));
        ans = add(ans, mult(arr[i], pref[rs]));
        ans = sub(ans, mult(arr[i], calc(0)));
    }
    printf("%d\n", ans);
    return 0;
}


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

def gcd(x, y):
    while y > 0:
        x, y = y, x%y
    return x

def lcm(x, y):
    return int(x/gcd(x, y)*y)
  
E = lcm(C,D)

C_min = int(A-1) // C
C_max = B // C
D_min = int(A-1) // D
D_max = B // D
E_min = int(A-1) // E
E_max = B // E
min_num = C_min + D_min - E_min
max_num = C_max + D_max - E_max
ans = B - (A-1) - (max_num - min_num)
print(ans)

Measured memory_bytes: 3064
n = int(input())
h = [int(x) for x in input().split()]
seq,ans = 0,0
for i in range(1,n-1):
    if h[i-1] >= h[i]:
        seq +=1
    else:
        ans = max(ans,seq)
        seq = 0
print(max(ans,seq+1) if seq else ans)

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

void solve(int arr[], int n, int x)
{
  int i=0;
  int m=x,p=x;
while(i<n)
{
if(m == arr[i])
{
  m--;
  i=0;
}
else
  i++;
}
int j = 0;
while(j<n)
{
  if(p == arr[j])
  {
    p++;
    j=0;
  }
  else
    j++;
}
  int a,b;
  a = (x-m);
  b = (p-x);
  if(a<=b)
    cout<<m;
  else if(a>b)
    cout<<p;
}

int main()
{
int x, n;
cin>>x>>n;
int arr[n];
for(int i=0; i<n; i++)  cin>>arr[i];
solve(arr, n, x);
  return 0;
}


Measured memory_bytes: 3636
<?php
$n=trim(fgets(STDIN));
$check=(int)ceil(sqrt($n));
$i=1;
$ans=0;
while($i<$check){
  if((int)$n%$i==0){
    $m=(int)$n/$i-1;
    if((int)$n%$m==$i){
      $ans+=$m;
    }
  }
  ++$i;
}
echo $ans;


Measured memory_bytes: 4728
import java.util.Scanner;
import java.util.stream.IntStream;

public class Main {
    static final int[] FACTORS = { -1, 1 };

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

        int N = sc.nextInt();
        int M = sc.nextInt();
        long[] x = new long[N];
        long[] y = new long[N];
        long[] z = new long[N];
        for (int i = 0; i < N; ++i) {
            x[i] = sc.nextLong();
            y[i] = sc.nextLong();
            z[i] = sc.nextLong();
        }

        System.out.println(solve(x, y, z, M));

        sc.close();
    }

    static long solve(long[] x, long[] y, long[] z, int M) {
        long result = Long.MIN_VALUE;
        for (int factorX : FACTORS) {
            for (int factorY : FACTORS) {
                for (int factorZ : FACTORS) {
                    result = Math.max(result,
                            IntStream.range(0, x.length)
                                    .mapToLong(i -> x[i] * factorX + y[i] * factorY + z[i] * factorZ).sorted()
                                    .skip(x.length - M).sum());
                }
            }
        }

        return result;
    }
}

Measured memory_bytes: 31944
#include <bits/stdc++.h>
#define itn int
#define REP(i, n) for (int i = 0; i < n; i++)
#define IREP(i, n) for (int i = n - 1; i >= 0; i--)
#define REPEACH(i,k) for(auto& i:k)
#define all(a) a.begin(),a.end()
#define MOD 1000000007
#define int long long
using namespace std;
typedef long long ll;

const ll INF = 1LL << 60;

vector<int> v(200001,0);
map<int,vector<int>> m;

int ne(int a){
	REP(i,m[a].size()){
		v[m[a][i]]+=v[a];
		ne(m[a][i]);
	}
}
signed main() {
	int n,q;
	cin >> n >> q;
	REP(i,n-1){
		int a,b;
		cin >> a >> b;
		m[a].push_back(b);
	}
	REP(i,q){
		int p,x;
		cin >> p >> x;
		v[p]+=x;
	}
	ne(1);
	for(int i=1;i!=n+1;i++){
		cout << v[i];
		if(i!=n){
			cout << " ";
		}
		else{
			cout << endl;
		}
	}
}

Measured memory_bytes: 44544
import java.util.Scanner;

public class Main {
    int n;
    int y;
    public static void main(String[] args) {
        Main m = new Main();
        m.read();
        m.solve();
    }

    private void read() {
        Scanner sc = new Scanner(System.in);
        n = sc.nextInt();
        y = (int) (sc.nextLong() / 1000);
    }

    private void solve() {
        boolean flg = false;
        int i, j, k;
        i = j = k = 0;
        for (i = n; i >= 0; i--) {
            int sum = 10 * i;
            for (j = n - i; j >= 0; j--) {
                k = n - (i + j);
                sum += 5 * j + k;
                if (y == sum) {
                    flg = true;
                    break;
                }
                sum -= 5 * j + k;
            }
            if(flg)
                break;
        }
        if (!flg) {
            i = j = k = -1;
        }
        System.out.printf("%d %d %d\n", i, j, k);
    }
}


Measured memory_bytes: 23380
<?php
$n = trim(fgets(STDIN));
$a = explode(" ", trim(fgets(STDIN)));
$b = explode(" ", trim(fgets(STDIN)));
$c = explode(" ", trim(fgets(STDIN)));

$satisfy = 0;
$pre = -1;
foreach ($a as $value) {
    $satisfy += $b[$value-1];
    if($pre !== -1) {
        if($value == $pre+1) {
            $satisfy += $c[$value-2];
        }
    }
    $pre = $value;
}

echo $satisfy;

Measured memory_bytes: 4728
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<vector>
#include<queue>

using namespace std;

#define pii pair<int,int>
#define LL long long
#define fir first
#define sec second
#define makr(a,b) make_pair(a,b)
#define PQ priority_queue<pii,vector<pii>,Cmp>

const int N=200000+10;

int n,v[N];

vector<int> G[N];

struct Cmp
{
	bool operator()(const pii& a,const pii& b)
	{
		return (LL)a.fir*b.sec>(LL)a.sec*b.fir;
	}
};

bool cmp(const pii& a,const pii& b)
{
	return (LL)a.fir*b.sec>(LL)a.sec*b.fir;
}

LL ans;

pii operator+(const pii& a,const pii& b)
{
	ans+=(LL)a.fir*b.sec;
	return makr(a.fir+b.fir,a.sec+b.sec);
}

PQ Q[N];

void merge(PQ& a,PQ& b)
{
	if(a.size()<b.size())
		swap(a,b);
	while(!b.empty())
	{
		a.push(b.top());
		b.pop();
	}
}

void dfs(int u)
{
	PQ& S=Q[u];
	for(int v:G[u])
	{
		dfs(v);
		merge(S,Q[v]);
	}
	pii p(v[u],!v[u]);
	while(!S.empty()&&cmp(p,S.top()))
	{
		p=p+S.top();
		S.pop();
	}
	S.push(p);
}

int main()
{
	cin>>n;
	for(int i=2,f;i<=n;++i)
	{
		cin>>f;
		G[f].push_back(i);
	}
	for(int i=1;i<=n;++i)
		cin>>v[i];
	dfs(1);
	PQ& S=Q[1];
	pii p;
	while(!S.empty())
	{
		p=p+S.top();
		S.pop();
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 34940
#include "bits/stdc++.h"
#define MAXN 100009
#define INF 1000000007
#define mp(x,y) make_pair(x,y)
#define all(v) v.begin(),v.end()
#define pb(x) push_back(x)
#define wr cout<<"----------------"<<endl;
#define ppb() pop_back()
#define tr(ii,c) for(__typeof((c).begin()) ii=(c).begin();ii!=(c).end();ii++)
#define ff first
#define ss second
#define my_little_dodge 46
#define debug(x)  cerr<< #x <<" = "<< x<<endl;
using namespace std;

typedef long long ll;
typedef pair<int,int> PII;
template<class T>bool umin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
template<class T>bool umax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
const int N=303;
char tmp[N][N],s[N][N];
int main(){
    //~ freopen("file.in", "r", stdin);
    int n,ans=0;
    scanf("%d",&n);
    for(int i=0;i<n;i++)
		scanf("%s",s[i]);
	for(int i=0;i<n;i++){
		for(int j=0;j<n;j++)
			for(int k=0;k<n;k++)
				tmp[j][(k+i)%n]=s[j][k];
		bool flag=1;
		for(int i=0;i<n;i++)
			for(int j=0;j<n;j++)
				flag&=(tmp[i][j]==tmp[j][i]);
		if(flag)
			ans+=n;
	}printf("%d\n",ans);
	return 0;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
typedef long double ld;

int main(){
    ld n,k; cin >> n >> k;
    int i=1,pos1=n+1;
    ld ans=0;
    while(1<=ceil(k/i)){
        int pos2=ceil(k/i);
        if(pos1-pos2<=0){
            i*=2;
            continue;
        }
        //cout << pos2 << " " << pos1 << endl;
        ans+=ld(1.0)/ld(i)*ld(pos1-pos2);
        pos1=pos2;
        i*=2;
    }
    cout << setprecision(16) << ans/ld(n) << endl;
    return 0;
}

Measured memory_bytes: 256
import copy
n=int(input())
t=list(map(int,input().split()))
m=int(input())
drink=[list(map(int,input().split())) for i in range(m)]
for i in range(m):
	list=copy.deepcopy(t)
	index=drink[i][0]
	list[index-1]=drink[i][1]
	print(sum(list))

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

int main(){
  char x[1000];
  int i,sum;
  while(1){
    sum = 0;
    scanf("%s",x);
    if(strcmp(x,"0")==0)
      break;
    for(i=0; x[i]!='\0'; i++){
      sum+=x[i]-'0';
    }
    printf("%d\n",sum);
  }
  return 0;
}


Measured memory_bytes: 2064
n,h=map(int,input().split())
A,B=[],[]
for _ in range(n):
    a,b=map(int,input().split())
    A.append(a)
    B.append(b)
a=max(A)
B=sorted(list(filter(lambda x:x>a,B)),reverse=True)
ans=0
while h>0 and B:
    h-=B[0]
    B.pop(0)
    ans+=1
if h>0:
    if h%a==0:
        ans+=h//a
    else:
        ans+=(h//a+1)
print(ans)

Measured memory_bytes: 12848
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
  ll N, M; cin >> N >> M;
  vector<ll> H(N);
  for(int i=0;i<N;i++){
    cin >> H[i];
  }
  vector<pair<int,int>> A(M);
  for(int i=0;i<M;i++){
    cin >> A[i].first >> A[i].second;
  }
  vector<int> ans(N,1);
  for(int i=0;i<M;i++){
    if(H[A[i].first-1]>=H[A[i].second-1]){
      ans[A[i].second-1]=0;
    }
    if(H[A[i].first-1]<=H[A[i].second-1]){
      ans[A[i].first-1]=0;
    }
  }
  int count=0;
  for(int i=0;i<N;i++){
    if(ans[i]==1){
      count++;
    }
  }
  cout << count << endl;
  return 0;
}

Measured memory_bytes: 5108
#include <stdio.h>

int main(){
    int i;
    char str[1000];
    scanf("%s", str);
    
    while (1) {
        if (str[i] == '\0') break;
        printf("%c",str[i] >= 68 ?str[i] - 3: str[i] + 23);
        i++;
    }
    printf("\n");
    return 0;
}

Measured memory_bytes: 520
// https://atcoder.jp/contests/abc060/tasks/abc060_a

#include <bits/stdc++.h>
#include <string>
using namespace std;

int main() {
    string a,b,c;
    cin >> a >> b >> c;
    if (a[a.size()-1] == b[0] and b[b.size()-1] == c[0]) {
        cout << "YES" << endl;
    }else{
        cout << "NO" << endl;
    }
}


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

vector<vector<int>> g;
vector<int> vis;
int dfs(int v) {
	if (vis[v]) {
		return 0;
	}

	vis[v] = 1;

	int x = 1;
	for (int u : g[v]) {
		x += dfs(u);
	}

	return x;
}

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

	g = vector<vector<int>>(n);
	vis = vector<int>(n, 0);

	for (int i = 0; i < m; ++i) {
		int a, b;
		cin >> a >> b;
		--a;
		--b;

		g[a].push_back(b);
		g[b].push_back(a);
	}

	int ans = 1;
	for (int i = 0; i < n; ++i) {
		ans = max(ans, dfs(i));
	}

	cout << ans;

	return 0;
}


Measured memory_bytes: 21068
a,b=map(int, input().split())
ans=1
if a <= 0 and b >= 0:
  print('Zero')
  exit(0)
if a>0 and b > 0:
  print('Positive')
  exit(0)
if a <0 and b<0:
  d=abs(b-a)+1
  if d %2==0:
    print('Positive')
    exit(0)
  else:
    print('Negative')
    exit(0)

Measured memory_bytes: 3060
#include <iostream>
#include <algorithm>
#include <vector>
#include <iterator>

using namespace std;

vector<vector<int>> p, f;
vector<bool> b;
int n;
bool done;
vector<int> ans;
vector<int>::iterator a_i;

void dp(int depth);

int main(){
    done = false;
    cin >> n;
    f.resize(n);

    generate(f.begin(), f.end(), [](){
        vector<int> a;
        a.resize(10);
        copy_n(istream_iterator<int>(cin), 10, a.begin());
        return a;
     });

    p.resize(n);

    generate(p.begin(), p.end(), [](){
        vector<int> a;
        a.resize(11);
        copy_n(istream_iterator<int>(cin), 11, a.begin());
        return a;
     });

    b.resize(10);
    ans.resize(1023);
    a_i = ans.begin();
    dp(0);
    sort(ans.begin(), ans.end(), [](int a, int b){ return b < a; });
    cout << ans[0] << endl;
    return 0;
}

void dp(int depth){
    if(depth < 10){
        b[depth] = true;
        dp(depth + 1);
        b[depth] = false;
        dp(depth + 1);
        return;
    }
    int res = 0;
    if(all_of(b.begin(), b.end(), [](bool a){ return (not a); })) return;

    for(int i = 0; i < n; i++){
        int sum = 0;
        for(int j = 0; j < 10; j++){
            if(!b[j]) continue;
            sum += f[i][j];
        }
        res += p[i][sum];
    }
    *a_i = res;
    a_i++;
}


Measured memory_bytes: 256
# -*- coding: utf-8 -*-
from sys import stdin

d_in = lambda: int(stdin.readline())  # N = d_in()


MAX = 30000
N = d_in()

base = [3, 25, 2, 35, 55]
cand = []
for i in range(4, MAX // 2, 2):
    cand.append(i)
    cand.append(MAX - i)

for i in range(9, MAX // 2, 6):
    cand.append(i)
    cand.append(MAX - i)

ans = []
if N < 5:
    ans.extend(base[:3])
    if N == 4:
        ans.append(MAX)
elif N % 2 == 1:
    ans.extend(base)
    ans.extend(cand[:N-5])
else:
    ans.extend(base)
    ans.append(MAX)
    ans.extend(cand[:N-6])
print(*ans)


Measured memory_bytes: 4696
#include<iostream>
#include<algorithm>

using namespace std;

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

    int a[n], b[n];
    for(int i=0;i<n;i++){
        cin >> a[i];
        b[i] = 0;
    }

    for(int i=0;i<n;i++)b[a[i]-1]++;
    sort(b, b+n, greater<int>());
    
    int ans = 0;
    for(int i=0;i<k;i++)ans += b[i];
    cout << max(n-ans, 0) << endl;
}


Measured memory_bytes: 1792
#include<iostream>
#include<vector>
#include<string>

using ll = long long;

int main(){
    int n;
    std::cin >> n;
    std::vector<ll> x(n), y(n), h(n);
    ll tmpX, tmpY, tmpH = -1;
    for(int i = 0; i < n; i++){
        std::cin >> x[i] >> y[i] >> h[i];
        if(h[i] != 0 && tmpH == -1){
            tmpH = h[i]; tmpX = x[i]; tmpY = y[i];
        }
    }

    for(int cx = 0; cx <= 100; cx++){
        for(int cy = 0; cy <= 100; cy++){
            ll hh = tmpH + std::abs(tmpX - cx) + std::abs(tmpY - cy);
            // 他が満たすかどうか
            bool ok = true;
            for(int i = 0; i < n; i++){
                if(h[i] == 0){
                    if(hh - std::abs(x[i] - cx) - std::abs(y[i] - cy) > 0){
                        ok = false;
                        break;
                    }
                }else if(hh - h[i] != std::abs(x[i] - cx) + std::abs(y[i] - cy)){
                    ok = false;
                    break;
                }
            }

            if(ok){
                printf("%d %d %lld\n", cx, cy, hh);
                return 0;
            }
        }
    }


    return 0;
}


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

int main() {
    string a;
    std::cin >> a;
    ll n = a.length();
    
    vector<vector<ll>> sum(n+1,vector<ll>(28,0));
    
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < 28; j++) {
            sum[i+1][j] = sum[i][j];
            if( a[i]-'a' == j ) sum[i+1][j]++;
        }
    }
    
    ll res = 0;
    
    for (int i = 0; i < n; i++) {
        res += n-1-i-(sum[n][a[i]-'a']-sum[i+1][a[i]-'a']);
    }
    
    std::cout << res+1 << std::endl;
}


Measured memory_bytes: 51972
#include <iostream>
#include <algorithm>
#include <string>
#include <cmath>
#include <vector>
#include <regex>
#include <map>
#include <set>
#include <iomanip>

using namespace std;
using ll = long long;

int main() {
    int N,M;
    cin >> N >> M;
    
    vector<pair<string,pair<int,int>>> A(M);
    for(int i=0;i<M;i++){
        cin >> A[i].first >> A[i].second.first;
        A[i].second.second = i;
    }
    sort(A.begin(),A.end());
    vector<pair<int,pair<string,string>>> ans(M);
    
    A[0].second.first = 1;
    for(int i=1;i<M;i++){
        if(A[i-1].first == A[i].first){
            A[i].second.first = A[i-1].second.first + 1;
        }else{
            A[i].second.first = 1;
        }
    }

    for(int i=0;i<M;i++){
        ans[i].first = A[i].second.second;
        ans[i].second.first = A[i].first;
        ans[i].second.second = to_string(A[i].second.first);
    }
    sort(ans.begin(),ans.end());
    
    for(int i=0;i<M;i++){
        cout << setfill('0') << setw(6) << ans[i].second.first;
        cout << setfill('0') << setw(6) << ans[i].second.second << endl;
    }
        
        return 0;
    }
    
    


Measured memory_bytes: 14848
n,k=map(int,input().split())
r,s,p=map(int,input().split())
t = input()
te = {"r":"p", "s":"r", "p":"s"}
win_hand = [te[t[i]] for i in range(len(t))]
ans = "".join(win_hand)
for i in range(k, len(t)):
    if ans[i] == ans[i-k]:
        ans = ans[:i] + "x" + ans[i+1:]

cnt = ans.count('r')*r + ans.count('s')*s + ans.count('p')*p
print(cnt) 

Measured memory_bytes: 4444
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rrep(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define ALL(x) (x).begin(),(x).end()
#define pb push_back
#define mp make_pair
#define INF9 1000000000 //10^9
#define MOD 1000000007 //10^9+7
#define fi first
#define sc second
using ll=long long;
using pii=pair<ll,ll>;
using vi=vector<int>;

int main() {
    int n; cin >> n;
    double ans = 0;
    rep(i,n) {
        double m; string s; cin >> m >> s;
        ans += s=="JPY"?m:m*380000.0;
    }
    printf("%f\n", ans);
    return 0;
}


Measured memory_bytes: 256