akhauriyash/Code-Regression huggingface dataset:
#include <stdlib.h>
#include <cstdio>
#include <cstring>
#include <iostream>

using namespace std;

struct Node {
	int key;
	Node* p;
	Node* l;
	Node* r;
};

Node* root;
Node* NIL;
//	insert(T, z)
//	    y = NIL // x ??????
//	    x = 'T ??????'
//	    while x ??? NIL
//	        y = x // ???????¨????
//	        if z.key < x.key
//	            x = x.left // ?????????????§????
//	        else
//	            x = x.right // ?????????????§????
//	    z.p = y
//
//	    if y == NIL // T ???????????´???
//	        'T ??????' = z
//	    else if z.key < y.key
//	        y.left = z // z ??? y ?????????????????????
//	    else
//	        y.right = z // z ??? y ?????????????????????

void insert(int z) {

	Node* y = NIL;
	Node* x = root;

	Node* zn = (Node *) malloc(sizeof(Node));
	zn->key = z;
	zn->l = NIL;
	zn->r = NIL;

	while (x != NIL) {
		y = x;
		if (zn->key < x->key)
			x = x->l;
		else
			x = x->r;
	}

	if (y == NIL)
		root = zn;
	else if (zn->key < y->key)
		y->l = zn;
	else
		y->r = zn;

}

void printInOrder(Node* n) {
	if (n == NIL)
		return;

	printInOrder(n->l);
	cout << " " << n->key;
	printInOrder(n->r);
}

void printPreOrder(Node* n) {
	if (n == NIL)
		return;
	cout << " " << n->key;
	printPreOrder(n->l);
	printPreOrder(n->r);
}

int main() {

	int n;
	scanf("%d", &n);

	string s;
	int k;
	for (int i = 0; i < n; ++i) {
		cin >> s;
		if (s == "insert") {
			scanf("%d", &k);
			insert(k);
		} else {
			printInOrder(root);
			cout << endl;
			printPreOrder (root);
			cout << endl;
		}
	}

	return 0;
}

Measured memory_bytes: 26592
#include<iostream>
#include <algorithm>
#include <vector>
#include <string>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
ll D = 1000000007;

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

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

  ll k=0;
  int i=0;
  while(k<K){
    k += ins[i].second;
    i++;
  }
  cout << ins[i-1].first <<endl;

  return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <iomanip>
#include <string>
#include <algorithm>
#include <functional>
#include <set>
#include <map>
#include <unordered_map>
#include <queue>
#include <deque>
#include <cmath>
#include <cstdio>

using namespace std;

typedef long long ll;

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

int main(int argc, char **argv)
{
    ll N;
    cin >> N;
    if (N == 1) {
        cout << 0 << endl;
    }
    else {
        ll ans = 0;
        FOR(i, 2, 1000001) {
            if (N == 1) break;
            if (N < i) break;
            if (N % i == 0) {
                ll count = 0;
                while (N % i == 0) {
                    count++;
                    N = N / i;
                }
                ll c = count;
                REP(j, c) {
                    if (count > j) {
                        ans++;
                        count = count - (j + 1);
                    }
                }
            }
        }
        if (N == 1) cout << ans << endl;
        else cout << ans + 1 << endl;
    }
    return 0;
}


Measured memory_bytes: 3596
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<stdio.h>
#include<utility>//swapでaとbの値を入れ替える
#define rep(i,n) for(int i=0;i<(n);i++)
#define ll long long
#define sort(s) sort(s.begin(),s.end())
#define r(s) reverse(s.begin(),s.end())
using namespace std;

int main(){
	int a;
	string s;
	cin >> a>>s;
	if (a >= 3200)cout << s << endl;
	else cout << "red" << endl;
	return 0;
}

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

inline int read()
{
	int sum=0,ff=1; char ch=getchar();
	while(!isdigit(ch))
	{
		if(ch=='-') ff=-1;
		ch=getchar();
	}
	while(isdigit(ch))
		sum=sum*10+(ch^48),ch=getchar();
	return sum*ff;
}

int n,m;

int main()
{
	n=read();
	m=read();
	for ( int i=1;i<=m;i++ )
	{
		int x=read();
		n-=x;
	}
	if(n<0) printf("-1\n");
	else printf("%d\n",n);
}


Measured memory_bytes: 3724
#import<bits/stdc++.h>
using namespace std;long h,w,a,b,c,d,D[10]={0,1,1,0,-1,1,-1,-1},t[10],i;map<long,int>m;main(){cin>>h>>w>>a;for(*t=(h-2)*(w-2);cin>>a>>b;i=0)for(;i<9;)if((c=a+D[i])>1&(d=b+D[++i])>1&c<h&d<w)t[c=m[c*w+d]++]--,t[c+1]++;for(;i<10;)cout<<t[i++]<<" ";}

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

#define MOD 1000000007
#define rep(i, n) for(ll i=0; i < (n); i++)
#define ALL(v) v.begin(),v.end()
#define DUMP(i, v)for(ll i=0;i<v.size();i++)cout<<v[i]<<" "

using namespace std;
typedef long long int ll;
typedef vector<ll> llvec;
typedef vector<double> dvec;
typedef pair<ll, ll> P;
struct Edge{ll from, to, cost;};
struct node{ll cost, to;
  bool friend operator>(node a, node b){
    return a.cost>b.cost;
  }
};

ll mod(ll a, ll mod){
  ll res = a%mod;
  if(res<0)res=res + mod;
  return res;
}

ll modpow(ll a, ll n, ll mod){
  ll res=1;
  while(n>0){
    if(n&1) res=res*a%mod;
    a=a*a%mod;
    n>>=1;
  }
  return res;
}

ll modinv(ll a, ll mod){
  return modpow(a, mod-2, mod);
}

ll gcd(ll a, ll b){
  ll r = a%b;
  if(r==0) return b;
  else return gcd(b, a%b);
}

bool is_prime(ll n){
  ll i = 2;
  if(n==1)return false;
  if(n==2)return true;
  bool res = true;
  while(i*i <n){
    if(n%i==0){
      res = false;
    }
    i = i+1;
  }

  //if(i==1)res = false;
  if(n%i==0)res=false;
  return res;
}


/**************************************
** A main function starts from here  **
***************************************/
int main(){
  ll N, M;

  cin >> N >> M;
  llvec A(M);
  ll sum = 0;
  rep(i, M){cin >> A[i];
    sum += A[i];
  }

  cout <<(N - sum>=0?N-sum:-1);
  return 0;
}


Measured memory_bytes: 3632
#include <stdio.h>
int main()
{
  int kls[4][13],n,h,w,kn,cou,hw,kcn;
  char kc[2],hh;
  for(h=0;h<4;h++){
    for(w=0;w<13;w++){
      kls[h][w]=0;
    }
  }
  scanf("%d",&n);
  for(cou=0;cou<n;cou++){
    scanf("%s %d",kc,&kn);
    if(kc[0]=='S'){
      kcn=0;
    }else
      if(kc[0]=='H'){
	kcn=1;
      }else
	if(kc[0]=='C'){
	  kcn=2;
	}else
	  if(kc[0]=='D'){
	    kcn=3;
	  }
    kn=kn-1;
    kls[kcn][kn]=1;
  }
  for(h=0;h<4;h++){
    for(w=0;w<13;w++){
      if(kls[h][w]==0){
	if(h==0){
	  hh='S';
	}else
	  if(h==1){
	    hh='H';
	  }else
	    if(h==2){
	      hh='C';
	    }else
	      if(h==3){
		hh='D';
	      }
	hw=w+1;
	printf("%c %d\n",hh,hw);
      }
    }
  }
  return 0;
}

Measured memory_bytes: 1024
# https://atcoder.jp/contests/arc097/tasks/arc097_b
# union-findらしい

n, m = map(int, input().split())
P = list(map(lambda x: int(x) - 1, input().split()))

# xの根を求める
def find(x):
    if par[x] < 0:
        return x
    else:
        par[x] = find(par[x])
        return par[x]
#xとyの属する集合の併合
def unite(x,y):
    x = find(x)
    y = find(y)
    
    if x == y:
        return False
    else:
        #sizeの大きいほうがx
        if par[x] > par[y]:
            x,y = y,x
        par[x] += par[y]
        par[y] = x
        return True

#xとyが同じ集合に属するかの判定
def same(x,y):
    return find(x) == find(y)

#xが属する集合の個数
def size(x):
    return -par[find(x)]

#初期化
#根なら-size,子なら親の頂点
par = [-1] * n

for _ in range(m):
    ai, bi = map(int, input().split())
    ai, bi = ai - 1 , bi - 1
    unite(ai, bi)

# print(par)
# print(P)

count = 0
for i in range(n):
    if same(i, P[i]):
        count += 1

print(count)

Measured memory_bytes: 90604
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using pint = pair<int,  int>;
using pll = pair<ll, ll>;
using edge = pair<int, ll>;
using Graph = vector<vector<int>>; 
using WeightedGraph = vector<vector<edge>>;
const ll INF = 1LL << 60;
const int INF32 = 1 << 29;
const ll MOD = 1000000007;

int main(){
  int a,b,c;
  cin >> a >> b >> c;
  string ans = "No";
  if(a<=c&&c<=b)ans = "Yes";
  cout << ans << endl;
}


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

int main() {
  string s, t;
  cin >> s >> t;

  int count = 0;
  repi(i,s.size()) {
    if(s.at(i)!=t.at(i)) count++;
  }
  cout << count << endl;
  return 0;
}

Measured memory_bytes: 3900
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
const int maxn=100+5;
int n,x,a[maxn];
int main(){
	scanf("%d%d",&n,&x);
	for(int i=1;i<=n;i++)scanf("%d",&a[i]);
	sort(a+1,a+n+1);
	int i,ans=0;
	for(i=1;i<=n;i++)
	if(x>=a[i])x-=a[i],ans++;else break;
	if(i>n&&x)ans--;
	printf("%d",ans);
	return 0;
}

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

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define FOR(i,n,m) for(int i=(int)(n); i<=(int)(m); i++)
#define RFOR(i,n,m) for(int i=(int)(n); i>=(int)(m); i--)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define RITR(x,c) for(__typeof(c.rbegin()) x=c.rbegin();x!=c.rend();x++)
#define setp(n) fixed << setprecision(n)

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 (a>b) { a=b; return 1; } return 0; }

#define ll long long
#define vll vector<ll>
#define vi vector<int>
#define pll pair<ll,ll>
#define pi pair<int,int>

#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define ins insert

using namespace std;

/* Some Libraries */

//-------------------------------------------------

int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int X; cin>>X;
    int g = __gcd(360,X);
    int L = X*360/g;
    cout<<L/X<<endl;
    return 0;
}


Measured memory_bytes: 3608
using System;

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            var nk = Console.ReadLine().Split(' ');
            var n = int.Parse(nk[0]);
            var k = int.Parse(nk[1]);
            var a = Console.ReadLine().Split(' ');
            int[] b = new int[n];

            for(var i = 0; i < a.Length; i++)
            {
                b[i] = int.Parse(a[i]);
            }

            Array.Sort(b);

            int ans = 0;

            for(var y = 0; y < k; y++)
            {
                ans += b[y];
            }

            Console.WriteLine(ans);
        }
    }
}


Measured memory_bytes: 27876
#include<bits/stdc++.h>
typedef long long ll;
typedef unsigned long long ull;
using namespace std;
#define pb push_back
int dy[]={0, 0, 1, -1, 1, 1, -1, -1};
int dx[]={1, -1, 0, 0, 1, -1, -1, 1};

#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
#define mp make_pair
#define fi first
#define sc second
int n;
int a[3][100000];
ll dp[3][100000];
int main(){
	cin >> n;
	REP(i,3) {
		REP(j,n) {
			cin >> a[i][j];
		}
	}

	REP(i,3) {
		sort(&a[i][0],&a[i][0] + n);
	}

	REP(i,n) {
		dp[2][i] = 1;
	}

	RREP(i,2)  {
		int last = n - 1;
		RREP(j,n) {
			ll sum = 0;

			if(j + 1 < n) {
				sum += dp[i][j + 1];
			}
			while(last >= 0 && a[i + 1][last] > a[i][j]) {
				sum += dp[i + 1][last];
				last--;
			}
			dp[i][j] = sum;
		}
	}
	ll ans = 0;
	REP(i,n) {
		ans += dp[0][i];
	}
	cout << ans << endl;
	return 0;
}


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

int n,ans=0,ans1=0;
int a[500005];

bool cmp(int a,int b)
{
	return a>b;
}

signed main()
{
	cin>>n;
	for (int i=1;i<=3*n;i++)  cin>>a[i];
	
	stable_sort(a+1,a+3*n+1,cmp);
	
	for (int i=n+1;i<=2*n;i++)  ans+=a[i];
	for (int i=2;i<=2*n;i+=2)  ans1+=a[i];//8 5 5 5 2 1
	cout<<max(ans,ans1)<<endl;
	
	return 0;
}

Measured memory_bytes: 3712
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
#define f(i,a,n) for(int i=a ; i<n ; i++)
#define inf 1e17
#define MAX_SIZE 1000005 

void pr(int arr[], int size) 
{ for (ll i=0; i < size; i++) {printf("%d ", arr[i]); }cout << endl;}

int main () {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  
   ll t=1;
    // cin>>t;
    while(t--){
        ll n;
        string s;
        cin >> n >> s;
        ll x = s.length();
        if(x <= n){cout << s;}
        else{
            for(ll i = 0;i < n;i++){cout << s[i];}
            cout << "...";
        }
    }
  return 0;
}


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

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

  vector<string> s(n);
  map<string, ll> cnt;
  ll mx = 0;
  vector<string> mxvec;
  for(int i=0; i<n; i++){
    cin >> s[i];
    cnt[s[i]]++;
    if(cnt[s[i]] > mx){
      mx = cnt[s[i]];
    }
  }
  
  for(auto p : cnt){
  	if(p.second == mx) mxvec.push_back(p.first);
  }
  //cout << mxvec.size() << endl;
  sort(mxvec.begin(), mxvec.end());
  for(auto p : mxvec){
  	cout << p << endl;
  }
  
}

Measured memory_bytes: 28404
import math
from functools import reduce
from collections import deque
import sys
sys.setrecursionlimit(10**7)
from decimal import Decimal

def input():
    return sys.stdin.readline().strip()

# スペース区切りの入力を読み込んで数値リストにして返します。
def get_nums_l():
    return [ int(s) for s in input().split(" ")]

# 改行区切りの入力をn行読み込んで数値リストにして返します。
def get_nums_n(n):
    return [ int(input()) for _ in range(n)]

# 改行またはスペース区切りの入力をすべて読み込んでイテレータを返します。
def get_all_int():
    return map(int, open(0).read().split())

def rangeI(it, l, r):
    for i, e in enumerate(it):
        if l <= i < r:
            yield e
        elif l >= r:
            break

def log(*args):
    print("DEBUG:", *args, file=sys.stderr)

INF = 999999999999999999999999
MOD = 10**9+7

S = input().split()
a = Decimal(S[0])
b = Decimal(S[1])

print(int(a*b))


Measured memory_bytes: 71512
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>	
#include<map>
#include<set>
#include<utility>
#include<cmath>
#include<cstring>
#include<queue>
#include<stack>
#include<cstdio>
#include<sstream>
#include<iomanip>
#include<assert.h>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
//#define mt make_tuple
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
using namespace std;
//kaewasuretyuui
typedef long long ll;
typedef int Def;
typedef pair<Def,Def> pii;
typedef vector<Def> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
//typedef tuple<int,int,int> tp;
//typedef vector<tp> vt;
typedef vector<vd> vvd;
typedef pair<Def,pii> pip;
typedef vector<pip>vip;
const double PI=acos(-1);
const double EPS=1e-7;
const int inf=1e9;
const ll INF=2e18;
int dx[]={0,1,0,-1};
int dy[]={1,0,-1,0};
int main(){
	int n;
	while(cin>>n,n){
		vvi in(n,vi(n));
		rep(i,n){
			int a;
			cin>>a;
			rep(j,a){
				int b;
				cin>>b;
				in[i][b-1]=1;
			}
		}
		vi out;
		int a;
		cin>>a;
		vi m(a);
		rep(i,a)cin>>m[i];
		rep(i,n){
			bool h=true;
			rep(j,a)if(in[i][m[j]-1]==0)h=false;
			if(h)out.pb(i+1);
		}
		if(out.size()==1)cout<<out[0]<<endl;
		else cout<<-1<<endl;
	}
}

Measured memory_bytes: 3148
#include<iostream>
#include<unordered_map>
#include<bitset>
#include<math.h>
#include<vector>
#include<set>
#include<algorithm>
#include<ctype.h>
#include<unordered_set>
#include<string>
#include<iomanip>
#include<queue>
#include<climits>
#include<map>
#include<stack>
#include<iterator>
#include<cstring>
#include<deque>
#include<chrono>
using namespace std;
#define pi 3.141592653589793238


#define MOD 1000000007
#define INF 999999999999999999 
#define pb push_back
#define ff first
#define ss second
#define mt make_tuple
#define ll long long
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define f0 get<0>
#define f1 get<1>
#define f2 get<2>
typedef vector<ll> vi;
typedef vector<vi> vvi;


////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
int main() {
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    fast;
    ll T = 1, i, j;
    
    
    //cin >> T;
    while (T--) {
        ll n;
        cin >> n;
        vector<ll> v(n);
        for(i = 0; i < n; i++){
            cin >> v[i];
        }
        sort(v.begin(), v.end());
        ll cnt = 2;
        ll ans = v[n - 1];
        ll k = 2;
        while(cnt < n){
            if(cnt == n - 1){
                ans += v[n - k];
                break;
            }
            ans += v[n - k] * 2;
          	k++;
            cnt += 2;
        }
        cout << ans;
    }

    return 0;
}


Measured memory_bytes: 4776
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
#define all(x) (x).begin(),(x).end()
#define pll pair<ll,ll>
#define rep(i,n) for(int i=0;i<n;i++) 
const ll INF = 1LL<<60;
const ll mod = (int)1e9 + 7;

int main() {
    //ll N; cin >> N;
    //ll N,M; cin >> N >> M;
    //string S; cin >> S;
    //ll H,W; cin >> H >> W;
    int N;
    cin >> N;
    int K;
    cin >> K;
    string S;
    cin >> S;
    int now=0;
    rep(i,N){
        if(S[i]=='L'){
            if(i!=0 && S[i-1]=='L')now++;
        }
        else if(i!=N-1 && S[i+1]=='R')now++;
    }
    cout << min(N-1,now+2*K);


}

/*



 */



Measured memory_bytes: 512
#include <stdio.h>
int main(void){
    int N;
    scanf("%d", &N);
    int l;
    int max = 0;
    int sum = 0;
    for(int i = 0; i < N; i++){
        scanf("%d", &l);
        sum += l;
        if(l > max){max = l;}
    }
    if(max * 2 < sum) printf("%s", "Yes\n");
    else printf("%s", "No\n");
    return 0; 
}

Measured memory_bytes: 128
#include <algorithm>
#include <iostream>
#include <string.h>
#include <stdio.h>
#include <string>

using namespace std;

int main() {
	string s;
	cin >> s;

	int k = s.size() - 1;
	if ((k + 1) % 2 == 0) {
		puts("No");
		return 0;
	}

	k = k / 2;
	for (int i = 0, j = k - 1; i <= j; i++, j--) {
		if (s[i] != s[j] || s[i] != s[2 * k - j] || s[i] != s[2 * k - i]) {
			puts("No");
			return 0;
		}
	}

	puts("Yes");

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define FOR(i,a,n) for(int i=(a); i<(n); i++)
#define all(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9+7;

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

    int n; cin >> n;
    rep(i, n) {
        string s; cin >> s;
        set<string> st;
        FOR(j, 1, s.size()) rep(p, 4) rep(q, 2){
            // 分割パート
            string x, y;
            rep(k, s.size()) {
                if (k<j) x += s[k];
                else y += s[k];
            }
            // 反転パート
            if (p==1) reverse(all(x));
            else if (p==2) reverse(all(y));
            else if (p==3) {reverse(all(x));reverse(all(y));}
            // 連結パート
            if (q==0) {
                x += y;
                st.insert(x);
            } else {
                y += x;
                st.insert(y);
            }
        }
        cout << st.size() << endl;
    }
}


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

int main() {

  int H, W; //マスメ
  int h, w; //選んだ行列

  cin >> H  >> W >> h >> w;

  int ans;
  ans = (H*W) - (h*W) - (H*w) + (h*w);

  cout << ans << endl;

}


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

using namespace std;

int a, b, c;

int main() {
    cin >> a >> b >> c;

    if (a == 7) {
        swap(a, b);
    }

    if (c == 7) {
        swap(c, b);
    }

    if (a == 5 && b == 7 && c == 5) {
        cout << "YES" << '\n';
    } else {
        cout << "NO" << '\n';
    }

    return 0;
}


Measured memory_bytes: 256
N = int(input())
T = list(map(int, input().split()))
M = int(input())

ans = []
for _ in range(M):
    tmp_T = T[:]
    p, x = map(int, input().split())
    tmp_T[p-1] = x
    ans.append(sum(tmp_T))

for a in ans:
    print(a)




Measured memory_bytes: 38384
#include <iostream>
#include <utility>
#include <map>
#include <vector>
#include <algorithm>
#include <queue>
#include <math.h>
#include <stack>
#include <set>
#include <deque>
#include <cmath>
#include <cassert>

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

int main() {
    int w, h, n;
    cin >> w >> h >> n;
    int max_x = 0;
    int min_x = w;
    int max_y = 0;
    int min_y = h;
    rep(i, n) {
        int x, y, a;
        cin >> x >> y >> a;
        if (a == 1) {
            max_x = max(max_x, x);
        }
        if (a == 2) {
            min_x = min(min_x, x);
        }
        if (a == 3) {
            max_y = max(max_y, y);
        }
        if (a == 4) {
            min_y = min(min_y, y);
        }
    }
    //cout << max_x << " " << min_x << " " << min_y << " " << max_y << endl;
    cout << max(0, min_x - max_x) * max(0, min_y - max_y) << endl;
    return 0;
}


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

def gcd(a,b):
    if a<b:
        a, b = b, a
    if b == 0:
        return a
    return gcd(b,a%b)
    
lcm = C*D//gcd(C,D)

bDivC = B // C
bDivD = B // D
bDivCD = B // lcm
numBDividable = bDivC + bDivD - bDivCD
numB = B - numBDividable

aDivC = (A-1) // C
aDivD = (A-1) // D
aDivCD = (A-1) // lcm
numADividable = aDivC + aDivD - aDivCD
numA = A-1 - numADividable

answer = numB - numA
print(answer)


Measured memory_bytes: 3064
import java.util.*;

class Main{

    void play(String line, int N){
        int[] C = new int[N];
        int B = 0;
        for (int i = 0; i < N; i++ ) C[i] = 0;

        for ( int i = 0; i < line.length(); i++ ){
            int p = i%N;
            if ( line.charAt(i) == 'M' ){
                C[p]++;
            } else if ( line.charAt(i) == 'S' ){
                C[p]++;
                B += C[p];
                C[p] = 0;
            } else if ( line.charAt(i) == 'L' ){
                C[p] += B + 1;
                B = 0;
            }
        }

        Arrays.sort(C);

        for ( int i = 0; i < N; i++ ) System.out.print(C[i] + " ");
        System.out.println(B);
    }

    void solve(){
        int N;
        String line;
        Scanner sc = new Scanner(System.in);
        while(true){
            N = sc.nextInt();
            if ( N == 0 ) break;
            line = sc.next();
            play(line, N);
        }
    }

    public static void main(String[] args){ new Main().solve(); }
}



Measured memory_bytes: 29296
package main

import (
	"fmt"
)

func AizuITP12B() {
	var a, b, c int
	fmt.Scan(&a, &b, &c)
	if a < b && b < c {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}
}

func main(){
AizuITP12B()
}


Measured memory_bytes: 1124
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<vector>
#include<algorithm>

using namespace std;

struct DATA{
  int l_l, l_r;
  int n_l, n_r;
};

vector<DATA> data;

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

int search_miss_num(vector<int>& num){
  sort(num.begin(), num.end());
  for(int i=0; i<num.size(); ++i){
    if(num[i] != i+1) return i;
  }
  return num.size();
}

int solve(int n){
  //  cout << n << endl;
  int GCD, g_l, g_r;

  if(data[n].n_l == 0) g_l = 1;
  else g_l = solve(data[n].n_l -1);

  if(data[n].n_r == 0) g_r = 1;
  else g_r = solve(data[n].n_r -1);

  GCD = gcd(g_l * data[n].l_l, g_r * data[n].l_r);
  return g_l * ((g_r * data[n].l_r)/GCD) + g_r * ((g_l * data[n].l_l)/GCD);
}

int main(){
  int n, GCD;
  DATA data_;
  vector<int> num;

  while(1){
    cin >> n;
    if(n == 0) break;

    num.clear();
    data.clear();

    for(int i=0; i<n; ++i){
      cin >> data_.l_l >> data_.l_r >> data_.n_l >> data_.n_r;
      GCD = gcd(data_.l_l, data_.l_r);
      data_.l_l /= GCD;
      data_.l_r /= GCD;
      if(data_.n_l != 0) num.push_back(data_.n_l);
      if(data_.n_r != 0) num.push_back(data_.n_r);
      data.push_back(data_);
    }
    cout << solve(search_miss_num(num)) << endl;
  }
  return 0;
}

Measured memory_bytes: 1224
#include <bits/stdc++.h>//Carefully Crafted by hetp111
using namespace std;
//#define int long long
#define double long double
#define all(v) (v).begin(),(v).end()
#define vi vector<int>
#define vvi vector<vi>
#define pii pair<int,int>
#define vii vector<pii>
#define MOD (1000000007)
#define MOD2 (998244353)
#define MOD3 (1000000009)
#define PI acos(-1)
#define eps (1e-8)
#define INF (1e18)
#define FASTER ios_base::sync_with_stdio(0);cin.tie(0)
template<class A,class B>ostream&operator<<(ostream&out,const pair<A,B>&a){return out<<"("<<a.first<<","<<a.second<<")";}
template<class A>ostream&operator<<(ostream&out,const vector<A>&a){for(const A &it:a)out<<it<<" ";return out;}
template<class A,class B>istream&operator>>(istream&in,pair<A,B>&a){return in>>a.first>>a.second;}
template<class A>istream&operator>>(istream&in,vector<A>&a){for(A &i:a)in>>i;return in;}
ifstream cinn("ride.in");ofstream coutt("ride.out");
int poww(const int &a,int b,const int &m=MOD){if(b==0)return 1;int x=poww(a,b/2,m);x=x*x%m;if(b&1)x=x*a%m;return x;}
int ceil(const int &a,const int &b){return (a+b-1)/b;}
////Read:
//Check corner cases, n==1;
//
////Some function:
//__builtin_popcountll(), 

char v[2000][2000];
int Rnext[2000][2000];
int Rprev[2000][2000];
int Cnext[2000][2000];
int Cprev[2000][2000];
int dpR[2000][2000];
int dpC[2000][2000];

signed main(){
    FASTER;
    int n,m;cin>>n>>m;
    
    for(int i=0;i<n;i++){
        for(int j=0;j<m;j++){
            cin>>v[i][j];
        }
    }
    
    for(int i=0;i<n;i++){
        int last=m-1;
        for(int j=m-1;j>=0;j--){
            if(v[i][j]=='.')Rnext[i][j]=last;
            else last=j-1;
        }
    }
    for(int i=0;i<n;i++){
        int last=0;
        for(int j=0;j<m;j++){
            if(v[i][j]=='.')Rprev[i][j]=last;
            else last=j+1;
        }
    }
    
    
    for(int j=0;j<m;j++){
        int last=n-1;
        for(int i=n-1;i>=0;i--){
            if(v[i][j]=='.')Cnext[i][j]=last;
            else last=i-1;
        }
    }
    for(int j=0;j<m;j++){
        int last=0;
        for(int i=0;i<n;i++){
            if(v[i][j]=='.')Cprev[i][j]=last;
            else last=i+1;
        }
    }
    
    
    for(int i=0;i<n;i++){
        dpR[i][0]=(v[i][0]=='.');
        for(int j=1;j<m;j++){
            dpR[i][j]=dpR[i][j-1]+(v[i][j]=='.');
        }
    }
    for(int j=0;j<m;j++){
        dpC[0][j]=(v[0][j]=='.');
        for(int i=1;i<n;i++){
            dpC[i][j]=dpC[i-1][j]+(v[i][j]=='.');
        }
    }
    
    int ans=1;
    for(int i=0;i<n;i++){
        for(int j=0;j<m;j++){
            if(v[i][j]=='#')continue;
            int r=Rnext[i][j];
            int l=Rprev[i][j];
            int d=Cnext[i][j];
            int u=Cprev[i][j];
            int mx=-1;
            mx+=dpR[i][r]-(l?dpR[i][l-1]:0);
            mx+=dpC[d][j]-(u?dpC[u-1][j]:0);
            ans=max(ans,mx);
        }
    }
    
    cout<<ans;
}

Measured memory_bytes: 101320
#include <bits/stdc++.h>
using namespace std;
#define ll long long 
#define endl "\n"
#define pb push_back
#define f(i,n) for(i=0;i<n;i++)
#define F(i,a,b) for(i=a;a<=b;i++)
#define arr(a,n) for( i=0;i<n;i++)cin>>a[i];
#define fi first
#define se second
#define mp make_pair
#define mod 1000000007
#define YES cout<<"YES"<<endl;
#define Yes cout<<"Yes"<<endl;
#define NO cout<<"NO"<<endl;
#define No cout<<"No"<<endl;
#define yes cout<<"yes"<<endl;
#define no cout<<"no"<<endl;
#define vi vector<ll>
#define ed end()
#define bg begin()
#define sz size()
#define ln length()
#define s() sort(a,a+n);
#define sr() sort(a,a+n,greater<ll>());
#define v()  sort(v.begin(),v.end());
#define vr() sort(v.begin(),v.end(),greater<ll>());
#define mod 1000000007
#define fast() ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
ll gcd(ll a, ll b){if(!b)return a;return gcd(b, a % b);}
ll power(ll x,ll y,ll p){ll res=1;x%=p;while(y>0){if(y&1)res=(res*x)%p;y=y>>1;x=(x*x)%p;}return res;}
int main() {
  /* #ifndef ONLINE_JUDGE
      // for getting input from input.txt
      freopen("input.txt", "r", stdin);
      // for writing output to output.txt
      freopen("output.txt", "w", stdout);
  #endif*/
fast();
//ll  t;cin>>t;while(t--)
{
  ll n,k,x,y,s=0;
  cin>>n>>k>>x>>y;
  ll ans=min(n,k)*x;
  ll temp=(n-k)>0?((n-k)*y):0;
  cout<<ans+temp<<endl;
  

}
return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <list>
#include <map>
#include <set>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <utility>
#include <vector>
using namespace std;

int main() {
  long long N;
  cin >> N;
  vector<long long> A(N);
  bool f = false;
  for (int i = 0; i < N; ++i) {
    cin >> A[i];
    if (A[i] % 2 != 0)
      f = true;
  }
  cout << (f ? "first" : "second") << endl;
  return 0;
}


Measured memory_bytes: 1024
import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		double A = sc.nextDouble();
		int B = sc.nextInt();
		double T = sc.nextDouble();

		int a = (int) ((int)(T+0.5)/A);

		System.out.println(a*B);

	}
}


Measured memory_bytes: 24788
a = input()
b = int(a[:2])
c = int(a[2:])
 
if b > 12 and c > 12:
  print("NA")
elif b > 12 or b == 0: # bがYY
  if c < 1:
    print("NA")
  else:
    print("YYMM")
elif c > 12 or c == 0: # cがYY
  if b < 1:
    print("NA")
  else:
    print("MMYY")
else:
  print("AMBIGUOUS")

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
const int maxN = (int)1e5 + 100;
int gcd(int a, int b) {
    while (a > 0 && b > 0) {
        if (a < b) swap(a, b);
        a %= b;
    }
    return (a + b);
}
int pref[maxN], suf[maxN];
int n;
int v[maxN], c[maxN];
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    srand(228);
    //freopen("input.txt", "r", stdin);
    int a, b, t;
    cin >> a >> b >> t;
    cout << (t / a) * b;
    return 0;
}

Measured memory_bytes: 256
import copy
n = int(input())
a = list(map(int,input().split()))
a_2 = copy.copy(a)
a_2.reverse()
sinu = [0] * n
t = 0
for i in range(n):
    t += a_2[i]
    sinu[i] += t
sinu.reverse()

ans = 0
for i in range(n-1):
    #print(a[i],sinu[i+1])
    ans += a[i] * sinu[i+1]

    
print(ans%(10**9+7))


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

#define rep(i, n) for (int i = 0; i < int(n); i++)
#define rrep(i, n) for (int i = int(n) - 1; i >= 0; i--)
#define reps(i, n) for (int i = 1; i <= int(n); i++)
#define rreps(i, n) for (int i = int(n); i >= 1; i--)
#define repc(i, n) for (int i = 0; i <= int(n); i++)
#define rrepc(i, n) for (int i = int(n); i >= 0; i--)
#define repi(i, a, b) for (int i = int(a); i < int(b); i++)
#define repic(i, a, b) for (int i = int(a); i <= int(b); i++)
#define each(x, y) for (auto &x : y)
#define all(a) (a).begin(), (a).end()
#define bit32(x) (1 << (x))
#define bit64(x) (1ll << (x))

using namespace std;

using i32 = int;
using i64 = long long;
using u64 = unsigned long long;
using f80 = long double;
using vi32 = vector<i32>;
using vi64 = vector<i64>;
using vu64 = vector<u64>;
using vf80 = vector<f80>;
using vstr = vector<string>;

inline void yes() { cout << "Yes" << '\n'; exit(0); }
inline void no() { cout << "No" << '\n'; exit(0); }
inline i64 gcd(i64 a, i64 b) { if (min(a, b) == 0) return max(a, b); if (a % b == 0) return b; return gcd(b, a % b); }
inline i64 lcm(i64 a, i64 b) { if (min(a, b) == 0) return max(a, b); return a / gcd(a, b) * b; }
inline u64 xorshift() { static u64 x = 88172645463325252ull; x = x ^ (x << 7); return x = x ^ (x >> 9); }
template <typename T> class pqasc : public priority_queue<T, vector<T>, greater<T>> {};
template <typename T> class pqdesc : public priority_queue<T, vector<T>, less<T>> {};
template <typename T> inline void amax(T &x, T y) { if (x < y) x = y; }
template <typename T> inline void amin(T &x, T y) { if (x > y) x = y; }
template <typename T> inline T exp(T x, i64 n, T e = 1) { T r = e; while (n > 0) { if (n & 1) r *= x; x *= x; n >>= 1; } return r; }
template <typename T> inline T bis(T ok, T ng, function<bool(T)> f, T eps = 1) { while (abs(ok - ng) > eps) { T mi = (ok + ng) / 2; (f(mi) ? ok : ng) = mi; } return ok; }
template <typename T> istream& operator>>(istream &is, vector<T> &v) { each(x, v) is >> x; return is; }
template <typename T> ostream& operator<<(ostream &os, vector<T> &v) { rep(i, v.size()) { if (i) os << ' '; os << v[i]; } return os; }
void solve(); int main() { ios::sync_with_stdio(0); cin.tie(0); cout << fixed << setprecision(16); solve(); return 0; }

void solve() {
  int n;
  cin >> n;
  map<string, int> mp;
  rep(i, n) {
    string s;
    cin >> s;
    mp[s]++;
  }
  int ma = 0;
  each(m, mp) amax(ma, m.second);
  each(m, mp) {
    if (m.second == ma) {
      cout << m.first << endl;
    }
  }
}


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

char S[100005][4];

int memo[100005][8][8][8];
char next1[100005][8][8][8];

int N, A, B, C;

int dp(int i, int a, int b, int c){
    if(a > 7 || b > 7 || c > 7){
        return 0;
    }else if(i == N){
        return 1;
    }else if(memo[i][a][b][c] != -1){
        return memo[i][a][b][c];
    }

    if(S[i][0] == 'A' && S[i][1] == 'C'){
        int ans = 0;
        if(a > 0){
            if(dp(i+1, a-1, b, c+1)){
                ans = 1;
                next1[i][a][b][c] = 'C';
            }
        }
        if(c > 0){
            if(dp(i+1, a+1, b, c-1)){
                ans = 1;
                next1[i][a][b][c] = 'A';
            }
        }
        return memo[i][a][b][c] = ans;
    }
    if(S[i][0] == 'A' && S[i][1] == 'B'){
        int ans = 0;
        if(a > 0){
            if(dp(i+1, a-1, b+1, c)){
                ans = 1;
                next1[i][a][b][c] = 'B';
            }
        }
        if(b > 0){
            if(dp(i+1, a+1, b-1, c)){
                ans = 1;
                next1[i][a][b][c] = 'A';
            }
        }
        return memo[i][a][b][c] = ans;
    }
    if(S[i][0] == 'B' && S[i][1] == 'C'){
        int ans = 0;
        if(b > 0){
            if(dp(i+1, a, b-1, c+1)){
                ans = 1;
                next1[i][a][b][c] = 'C';
            }
        }
        if(c > 0){
            if(dp(i+1, a, b+1, c-1)){
                ans = 1;
                next1[i][a][b][c] = 'B';
            }
        }
        return memo[i][a][b][c] = ans;
    }
}

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

    for(int i = 0; i < N; i ++){
        scanf(" %s", S[i]);
    }

    memset(memo, -1, sizeof(memo));
    int a = min(A, 2);
    int b = min(B, 2);
    int c = min(C, 2);
    int ans = dp(0, a, b, c);

    if(ans == 0){
        printf("No");
        return 0;
    }else{
        printf("Yes\n");
        for(int i = 0; i < N; i ++){
            char temp = next1[i][a][b][c];
            printf("%c\n", temp);
            if(S[i][0] == 'A' && S[i][1] == 'C'){
                if(temp == 'A'){
                    a++;
                    c--;
                }
                if(temp == 'C'){
                    a--;
                    c++;
                }
            }
            if(S[i][0] == 'A' && S[i][1] == 'B'){
                if(temp == 'A'){
                    a++;
                    b--;
                }
                if(temp == 'B'){
                    a--;
                    b++;
                }
            }
            if(S[i][0] == 'B' && S[i][1] == 'C'){
                if(temp == 'B'){
                    b++;
                    c--;
                }
                if(temp == 'C'){
                    b--;
                    c++;
                }
            }
        }
    }

    return 0;
}


Measured memory_bytes: 263600
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <cctype>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <bitset>
#include <queue>
#include <stack>
#include <algorithm>
#include <functional>
using namespace std;
typedef long long ll;

#define mem(dp,a)           memset(dp,a,sizeof dp)
#define rep(i,a,b)          for(ll i=a;i<b;i++)
#define pb(x)               push_back(x)
#define mp(x,y)             make_pair(x,y)
#define fastio              ios_base::sync_with_stdio(false);cin.tie(NULL)
#define F                   first
#define S                   second
#define all(v)              (v).begin(),(v).end()
#define pi                  3.14159265359
ll INF=1e18+10;
ll MOD=998244353;

int main()
{
    int x,a;cin>>x>>a;
    if(x<a)
        cout<<0;
    else
        cout<<10;
}

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

const int64_t MOD = 998244353;
void add(int64_t& a, int64_t b){
    a = (a+b) % MOD;
}
void mul(int64_t& a, int64_t b){
    a = a*b % MOD;
}

int64_t power_mod(int64_t num, int64_t power){
    int64_t prod = 1;
    num %= MOD;
    while(power > 0){
        if(power&1) prod = prod * num % MOD;
        num = num * num % MOD;
        power >>= 1;
    }
    return prod;
}

bool online(int x1, int y1, int x2, int y2, int x3, int y3){
    return (y2-y1)*(x3-x1) == (y3-y1)*(x2-x1);
}

int main(){
    int N;
    cin >> N;
    vector<int> X(N), Y(N);
    for(int i=0; i<N; i++) cin >> X[i] >> Y[i];

    int64_t ans = power_mod(2, N);
    add(ans, MOD - 1 - N);

    for(int i=0; i<N; i++) for(int j=i+1; j<N; j++){
        bool bef = false;
        for(int k=0; k<j; k++) if(k!=i && online(X[i], Y[i], X[j], Y[j], X[k], Y[k])) bef = true;
        if(bef) continue;
        int num = 2;
        for(int k=j+1; k<N; k++) num += online(X[i], Y[i], X[j], Y[j], X[k], Y[k]);
        int64_t res = power_mod(2, num) - 1 - num;
        add(ans, MOD - res);
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
N, L = map(int, input().split())
if L >= 0:
    A = L * N + int((N * (N + 1))/2) - N - L
    print(A)
else:
    if abs(L) > (N - 1):
        A = L * N + int((N * (N + 1))/2) - L + 1 - (2 * N)
        print(A)
    else:
        A = L * N + int((N * (N + 1))/2) - N - L - abs(L)
        print(A)

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



int main(){
	
	int c[3][3];
	for(int i = 0; i < 3; i++)
	{
		cin >> c[i][0] >> c[i][1] >> c[i][2];
	}
	
	string ans = "Yes";
	for(int i = 0; i < 2; i++)
	{	
		for(int j = 0; j < 2; j++)
		{
			
		
			if(c[i][j] - c[i][j+1] != c[i+1][j] - c[i+1][j+1]) ans = "No";
			if(c[j][i] - c[j+1][i] != c[j][i+1] - c[j+1][i+1]) ans = "No";
		}
	}
	
	
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
// https://atcoder.jp/contests/abc143/tasks/abc143_b
// Q.数値配列から任意の2つを取り出した総和

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

int main()
{
  int n;
  cin >> n;
  vector<int> d(n);
  int ans = 0;
  for (int i = 0; i < n; i++)
  {
    cin >> d[i];
  }
  for (int i = 0; i < n; i++)
  {
    for (int j = i + 1; j < n; j++)
    {
      ans += d.at(i) * d.at(j);
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 3632
import sys

def main():
    N = int(input())
    lines = sys.stdin.read().strip().split('\n')
    AB = list(map(lambda l: list(tuple(map(int, l))), map(str.split, lines)))
    AB_by_A = sorted(AB)
    AB_by_B = sorted(AB, key=lambda t: (t[1], t[0]))
    if N % 2 == 1:
        mn = AB_by_A[N//2][0]
        mx = AB_by_B[N//2][1]
        print(mx - mn + 1)
        return
    mn1 = AB_by_A[N//2 - 1][0]
    mn2 = AB_by_A[N//2][0]
    mx1 = AB_by_B[N//2 - 1][1]
    mx2 = AB_by_B[N//2][1]
    mn = mn1 + mn2
    mx = mx1 + mx2
    print(mx - mn + 1)
    return

if __name__ == '__main__':
    main()


Measured memory_bytes: 75488
#include <iostream>
#include <sstream>
#include <queue>
#include <map>
#include <set>
#include <vector>
#include <numeric>
#include <algorithm>
#include <string>
#include <complex>

#include <cassert>
#include <cstdlib>
#include <cmath>
#include <cstdio>
#include <cstring>

#define REP(i,e) for(int i=0;i<(int)(e);i++)
#define FOR(i,b,e) for(int i=(int)(b);i<(int)(e);i++)
#define ALL(c) (c).begin(), (c).end()
#define EACH(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();++it)
#define RALL(c) (c).rbegin(), (c).rend()
#define ALLA(a,n) ((a)+0), ((a)+n)

using namespace std;

typedef long long ll;
typedef vector<int> vint;
typedef vector<long long> vll;
typedef vector<string> vstring;
typedef vector<double> vdouble;

template<class T>void pp(T v,int n){ REP(i,n)cout<<v[i]<< ' ' ; cout << endl; }
template<class T>void pp(T v){ EACH(it,v) cout << *it << ' ' ; cout << endl;  }
template<class T>T& ls(T& a,T b){ if(b<a) a=b; return a; }
template<class T>T& gs(T& a,T b){ if(b>a) a=b; return a; }
inline ll to_i(const string& s){ll n;sscanf(s.c_str(),"%lld",&n);return n;}
inline string to_s(ll n){char buf[32];sprintf(buf,"%lld",n);return string(buf);}

int main() {
  int n,k;
  while (cin >> n >> k) {
    double result = 0;
    REP(i,n) {
      int s = i + 1;
      double p = 1.0;
      while (s < k) {
	p /= 2;
	s *= 2;
      }
      result += p * (1.0 / n);
    }
    printf("%.12lf\n", result);
  }
}


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

int main() {
	int n;
	cin >> n;
	vector<int> a(n);
	long long s = 0;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		s += a[i];
	}
	long long s1 = 0, res = LONG_MAX;
	for (int i = 0; i < n - 1; i++) {
		s1 += a[i];
		res = min(res, abs(s1 - (s - s1)));
	}
	cout << res;
	return 0;
}

Measured memory_bytes: 3956
import math
N, K = map(int, input().split())
ans = 0
for n in range(1,N+1):
  if n>=K:
    ans += 1/N
  else:
    a = math.ceil(math.log2(K/n))
    #print(n,a)
    ans += 1/2**a/N
print(ans)

Measured memory_bytes: 3444
#include<bits/stdc++.h>
#define ll long long

using namespace std;

const int N = 2e5+1;

int n;
int a[N];
ll k;
int fst[N], lst[N], nxt[N];
int cnt;
int used[N];
vector<int> s;

int rgt(int i){
    return (i == n-1 ? 0 : i+1);
}

bool has[N];
vector<int> ans;
void iterate(int p){
    if(p == -1)
        return;
    for(int i = p; i < n; ++i){
        if(has[a[i]]){
            while(has[a[i]]){
                has[ans.back()] = false;
                ans.pop_back();
            }
        }
        else{
            has[a[i]] = true;
            ans.push_back(a[i]);
        }
    }
}

int main(){
    ios_base::sync_with_stdio(false);
    cout.tie(0);
    cin.tie(0);
    cin >> n >> k;
    for(int i = 0; i < N; ++i)
        fst[i] = lst[i] = -1;
    for(int i = 0; i < n; ++i)
        cin >> a[i];
    for(int i = 0; i < n; ++i){
        if(fst[a[i]] == -1)
            fst[a[i]] = i;
        else nxt[lst[a[i]]] = i;
        lst[a[i]] = i;
    }
    for(int i = 0; i < N; ++i)
        if(lst[i] != -1)
            nxt[lst[i]] = fst[i];
    s.push_back(0);
    used[0] = ++cnt;
    int i = 0;
    while(true){
        int j = rgt(nxt[i]);
        if(j <= i+1){
            if(j == 0 && i == n-1)
                s.push_back(-1);
            if(used[j])
                break;
            s.push_back(j);
            used[j] = ++cnt;
        }
        i = j;
    }
    --k;
    iterate(s[k%s.size()]);
    for(int el : ans)
        cout << el << ' ';
    cout << '\n';
}


Measured memory_bytes: 7284
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <deque>
#include <queue>
#include <string>
#include <string.h>
#include <math.h>
#include <iomanip>
#include <stdio.h>
using namespace std;

#define int64 long long
#define pii pair <int64, int64>
#define fr first
#define sc second
#define heap priority_queue
struct piii{
    int64 fr, sc, th;
    bool operator < (const piii &b){
        if (fr != b.fr) return fr < b.fr;
        if (sc != b.sc) return sc < b.sc;
        return th < b.th;
    }
};
///////////////////////////////////////////////
///////////////////////////////////////////////

const int maxval = 1e6 + 6;
int cnt[maxval], dd[maxval];
int n;
int a[200005];

int main(){
    cout << setprecision(2) << fixed;
    ios::sync_with_stdio(false), cin.tie(0);
    //freopen("input.txt", "r", stdin);
    cin >> n;
    for (int i = 0; i < n; i++){
        cin >> a[i];
        cnt[a[i]]++;
    }
    for (int i = 1; i < maxval; i++)
    if (cnt[i]){
        for (int j = i * 2; j < maxval; j += i)
            dd[j] = true;
    }
    int res = 0;
    for (int i = 0; i < n; i++)
        if (cnt[a[i]] < 2 && !dd[a[i]])
            res++;
    cout << res;
    return 0;
}


Measured memory_bytes: 12196
#include <iostream>
#include <complex>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <numeric>
#include <cstring>
#include <ctime>
#include <cstdlib>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <cmath>
#include <bitset>
#include <cassert>
#include <queue>
#include <stack>
#include <deque>
#include <random>
#include <iomanip>
typedef long long int ll;
typedef long double ld;
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
const ll MOD=1000000007;
const ll MAX_N=500010;
const ll INF=999999999999;

int main(){
    int n,m;
    cin>>n>>m;
    vector<vector<int> > G(n);
    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);
    }
    queue<int> q;
    vector<int> ans(n,-1);
    q.push(0);
    ans[0]=0;
    while(!q.empty()){
        int u=q.front(); q.pop();
        for(int v:G[u]){
            if(ans[v]>0) continue;
            ans[v]=u+1;
            q.push(v);
        }
    }
    cout<<"Yes"<<endl;
    for(int i=1;i<n;i++){
        cout<<ans[i]<<endl;
    }
}

Measured memory_bytes: 10068
#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() {
  int N, a;
  cin >> N;
  int max = 0;
  ll ans = 0;
  rep(i, N) {
    cin >> a;
    if (a > max) {
      max = a;
      continue;
    }
    ans += max - a;
  };
  cout << ans << endl;
}


Measured memory_bytes: 3632
#define _USE_MATH_DEFINES
#include <cmath>
#include <string>
#include <vector>
#include <utility>
#include <iostream>
#include <algorithm>
#include <unordered_map>
#include <numeric>
#include <array>
#include <float.h>
#include <memory>
#include <functional>
#include <iomanip>
#include <queue>
#include <random>
#include <map>
#include <set>

#pragma warning(disable:4996)

using namespace std;

int main() {
  while (true) {
    int size;
    cin >> size;
    if (size == 0) {
      break;
    }
    vector<int> v(size);
    for (auto&& vv : v) {
      cin >> vv;
    }
    sort(v.begin(), v.end());
    cout << accumulate(v.begin() + 1, v.end() - 1, 0) / (v.size() - 2) << endl;
  }
  return 0;
}

Measured memory_bytes: 3080