akhauriyash/Code-Regression huggingface dataset:
# -*- coding: utf-8 -*-
"""
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=DSL_2_A&lang=jp

"""
import sys
from sys import stdin
input = stdin.readline


class RMQ(object):
    INT_MAX = 2**31 - 1

    def __init__(self, nn):
        self.n = 1
        while self.n < nn:
            self.n *= 2
        self.dat = [RMQ.INT_MAX] * ((2 * self.n)-1)

    def update(self, k, a):
        # A[k]???a?????´??°?????????????????°???????????¨?????´??°
        k += (self.n - 1)
        self.dat[k] = a

        while k > 0:
            k = (k - 1) // 2        #  ??????index??????
            self.dat[k] = min(self.dat[k * 2 + 1], self.dat[k * 2 + 2]) #  ???????????¨??????????????????????°?????????????????????´??°

    def query(self, a, b, k, l, r):
        # [a, b)???????°????????±??????? (0????????§b???????????????)
        # ??????????????¨?????????query(a, b, 0, 0, n)?????¢??§??????????????????k, l, r???????????????????????´??°?????????
        if r <= a or b <= l:        #  ?????????????????§??¨??????????????????
            return RMQ.INT_MAX
        if a <=l and r <= b:
            return self.dat[k]           #  ???????????°???????????????????????§????????°????????¨??????????????????????°?????????????????????????
        else:
            vl = self.query(a, b, k*2+1, l, (l+r)//2) #  ????????°????????????????°????
            vr = self.query(a, b, k*2+2, (l+r)//2, r) #  ????????°????????????????°????
            return min(vl, vr)

    def find(self, s, t):
        return self.query(s, t+1, 0, 0, self.n)


def main(args):
    n, q = map(int, input().split(' '))

    rq = RMQ(n)
    for _ in range(q):
        com, x, y = map(int, input().split(' '))
        if com == 0:
            rq.update(x, y)
        elif com == 1:
            res = rq.find(x, y)
            print(res)


if __name__ == '__main__':
    main(sys.argv[1:])
    

Measured memory_bytes: 11636
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		
		int H = scan.nextInt();
		int W = scan.nextInt();
	        scan.nextLine();

		String[] cell = new String[H];
		for(int i = 0 ; i < H ; i++) {
			cell[i] = scan.nextLine();
		}
		
		scan.close();
		
		int[] hCell = new int[H];
 		int[] wCell = new int[W];
		
 		for(int j = 0 ; j < H ; j++) {
 			for(int k = 0 ; k < W ; k++) {
 				if(cell[j].charAt(k) == '#') {
 					hCell[j]++;
 					wCell[k]++;
 				}
 			}
 		}
 		
 		String str;
 		for(int l = 0 ; l < H ; l++) {
 			str = "";
 			if(hCell[l] > 0){
	 			for(int m = 0 ; m < W ; m++) {
	 				if(wCell[m] > 0) {
	 					str = str + cell[l].charAt(m);
	 				}
	 			}
 			}
 			if(str != "") {
 				System.out.println(str);
 			}
 		}
	}
}


Measured memory_bytes: 28756
#include "bits/stdc++.h"
using namespace std;
#define int long long
#define pb push_back
#define fi first
#define se second
#define FF first
#define SS second
#define INF 2e18;
#define mp make_pair
#define ll long long
#define pii pair<int,int>
#define sd(x) scanf("%d",&x)
#define slld(x) scanf("%lld",&x)
#define pd(x) printf("%d\n",x)
#define plld(x) printf("%lld\n",x)
#define endl '\n'
#define fr(i, a, b) for(int i = a; i <= b; i++)
#define sz(s) (int)s.size()
#define all(x) x.begin(), x.end()
typedef long double ld;

const int N = 2e5 + 5;
vector<int> v[40];
int lol[40];
int a[N], b[N];

signed main()
{
    //freopen("inp.txt","r",stdin);
    //freopen("out.txt","w",stdout);
    srand(time(NULL));
 
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    cout.tie(NULL);
    int n;
    cin >> n;
    // n = 25;
    int c1 = 0, c2 = 0;
    int c3 = 0, c4 = 0;
    fr(i, 1, n) {
        cin >> a[i];
        // a[i] = ((ll)rand() * rand()) % (1 << 28);
    }
    fr(i, 1, n) {
        cin >> b[i];
        // b[i] = ((ll)rand() * rand()) % (1 << 28);
        for(int j = 0; j <= 35; j++) {
            int val = b[i] % (1LL << (j + 1));
            v[j + 1].pb(val);
        }
    }
    fr(i, 1, 36) {
        sort(all(v[i]));
    }
    int ans = 0;
    fr(i, 1, n) {
        for(int j = 0; j <= 35; j++) {
            int val = a[i] % (1LL << (j + 1));
            val = (1LL << (j + 1)) - val;
            int x = v[j + 1].end() - lower_bound(all(v[j + 1]), val);
            x &= 1;
            lol[j + 1] ^= x;
        }
    }
    fr(j, 0, 35) {
        c1 = c2 = c3 = c4 = 0;
        fr(i, 1, n){
            if(a[i] & (1LL << j)) c1++;
            else c2++;
            if(b[i] & (1LL << j)) c3++;
            else c4++;
        }
        if((c1 * c4 + c2 * c3) & 1) lol[j] ^= 1;
    }
    fr(i, 0, 36) {
        if(lol[i]) ans ^= (1LL << i);
    }
    cout << ans << endl;
    // int brute = 0;
    // fr(i, 1, n) {
    //     fr(j, 1, n) {
    //         brute ^= (a[i] + b[j]);
    //     }
    // }
    // cout << brute << endl;
    return 0;
}

Measured memory_bytes: 61324
#include <bits/stdc++.h>
#define F first
#define S second

using namespace std;
typedef long long ll;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    vector<int> a(3);
    cin >> a[0] >> a[1] >> a[2];
    sort(a.begin(), a.end());
    if (a[0] + a[1] == a[2]) cout << "Yes";
    else cout << "No";
    
}

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

#define fastio() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define loop(i,a,b) for(ll i=a;i<b;i++)
#define test() ll t;cin>>t;for(ll test = 1;test<=t;test++)
#define f first
#define s second
#define pb push_back
#define ins insert
#define nl cout<<"\n"
#define P 1000000007
#define N 100005
#define MOD(x) ((x%P)+P)%P
#define show(x) cout<<x<<" "
#define vec(v) loop(i,0,v.size()) show(v[i]); nl

int main()
{
	fastio();

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

	ll dp[n+1][m+1] = {};

	string gr[n+1];

	loop(i,1,n+1)
		cin>>gr[i];

	loop(i,1,n+1)
	{
		loop(j,1,m+1)
		{
			if(i==1 && j==1)
				dp[i][j] = 1;
			else if(gr[i][j-1]=='.')
					dp[i][j] = dp[i-1][j] + dp[i][j-1];
			dp[i][j] = MOD(dp[i][j]);
		}
	}

	cout<<dp[n][m],nl;

	//cerr << "\nTime elapsed : " << 1000 * clock() / CLOCKS_PER_SEC << " ms\n";
	return 0;
}

Measured memory_bytes: 9216
import numpy as np
a = list(map(int,input().split()))
b = a[0]/0.08
c = (a[0]+1)/0.08
d = a[1]/0.1
e = (a[1]+1)/0.1
f=20000
if b<d:
    min=b
else :
    min =d
g=int(np.floor(min))
for i in range(g,10001):
    if i>=b and i<c:
        if i>=d and i<e:
            f = i
            break
if f==20000:
    print(-1)
else:
    print(f)

Measured memory_bytes: 12508
import sys
import heapq
import math
import fractions
import bisect
import itertools
from collections import Counter
from collections import deque
from operator import itemgetter
def input(): return sys.stdin.readline().strip()
def mp(): return map(int,input().split())
def lmp(): return list(map(int,input().split()))

n=int(input())
a=lmp()
a.insert(0,10000)
a.append(0)
i=0
m=len(a)
while i<m-1:
    if a[i]==a[i+1]:
        del a[i]
        i-=1
    i+=1
    m=len(a)

n=len(a)-2

l=[0]*(n+2)
for i in range(1,n+1):
    if a[i-1]<a[i]>a[i+1]:
        l[i]=1
    elif a[i-1]>a[i]<a[i+1]:
        l[i]=-1
sto=[0,1000]
for i in range(n+2):
    if l[n+1-i]==-1:
        l[n+1-i]=0
        break
    elif l[n+1-i]==1:
        break
for i in range(n+2):
    if l[i]==-1:
        sto[0],sto[1]=divmod(sto[1],a[i])
    if l[i]==1:
        sto[1]+=sto[0]*a[i]
        sto[0]=0
print(sto[1])


Measured memory_bytes: 72880
/* {{{ Definitions */
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <ios>
#include <utility>
#ifdef _WIN32
#include "debug.hpp"
#endif
using namespace std;

#define rep(i, N)  for(int i = 0; i < (N); i++)
#define reps(i, N) for(int i = 1; i <= (N); i++)
#define repr(i, N) for(int i = (N) - 1; i >= 0; i--)
#define pub push_back

template<typename T> 
void chmax(T &a, T b){ a = max(a, b); };
template<typename T> 
void chmin(T &a, T b){ a = min(a, b); };

typedef long long ll;
typedef pair<int, int> P;
const int INF = 100000000;
const ll LINF = 10000000000000000;
const int MOD = 1000000007;
/* }}}------------------------------------------- */
char c;
void solve(){
	
	if(c == 'A')
		cout << 'T' << endl;
	if(c == 'T')
		cout << 'A' << endl;
	if(c == 'C')
		cout << 'G' << endl;
	if(c == 'G')
		cout << 'C' << endl;
}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cin >> c;
	solve();
	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void){
  unsigned int L, R;
  scanf("%u %u",&L, &R);

  if(R-L >= 2018)
    printf("0\n");
  else{
    L %= 2019;  R %= 2019;
    // printf("L=%u R=%u\n",L, R);
    if(L < R){
      int i, j, min = 2018;
      for(i=L ; i<=R ; i++)
	for(j=i+1 ; j<=R ; j++)
	  if(min > (i*j)%2019)
	    min = (i*j)%2019;
      printf("%d\n", min);
    }
    else
      printf("0\n");
  }
  return 0;
}


Measured memory_bytes: 128
#include <stdio.h>
int main(){
	int S, h, m, s;
	scanf("%d", &S);
	h = S / 3600;
	m = (S % 3600)/60;
	s = (S % 3600) % 60;
	printf("%d:%d:%d\n", h, m, s);
	return 0;
}

Measured memory_bytes: 592
n1, n2  = [int(i) for i in input().split()]

na3 = []

for i4 in range(n1):
    na3.append([int(j) for j in input().split()])

na5 = [0] * (n2 + 1)

for i6 in range(n1):
    for i7 in range(na3[i6][0] + 1):
        if i7 != 0:
            na5[na3[i6][i7]] += 1

r8 = 0
for i9 in range(n2 + 1):
    if na5[i9] == n1:
        r8 += 1

print(r8)

Measured memory_bytes: 3188
using namespace std;
#include<bits/stdc++.h>
#define int long long
#define pb push_back 
#define IOS ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define ff first
#define ss second
#define all(x) x.begin(), x.end()
#define repa(i,a,b) for (int i=a; i<=b; i++)
#define repd(i,b,a) for (int i=b; i>=a; i--)
#define endl "\n"
//debugging
#define debug1(a) cout<<#a<<" = "<<(a)<<endl;
#define debug2(a,b) cout<<#a<<" = "<<(a)<<", "<<#b<<" = "<<(b)<<endl;
#define debug3(a,b,c) cout<<#a<<" = "<<(a)<<", "<<#b<<" = "<<(b)<<", "<<#c<<" = "<<(c)<<endl;
#define debug4(a,b,c,d) cout<<#a<<" = "<<(a)<<", "<<#b<<" = "<<(b)<<", "<<#c<<" = "<<(c)<<", "<<#d<<" = "<<(d)<<endl;

const int N = 1e+6+5;
int big = 1e+18+3;
int mod = 1e+9+7;

signed main()
{
    IOS;
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    #endif
    int h,w;
    cin>>h>>w;

    int row[h+1]={0};
    int col[w+1]={0};
    map<pair<int,int>,int>at;

    int m; cin>>m; while(m--)
    {
        int r,c;
        cin>>r>>c;
        row[r]++;
        col[c]++;
        at[{r,c}] = 1;
        
    }

    vector<int>finr,finc;
    repa(i,1,h)
        finr.pb(row[i]);
    repa(i,1,w)
        finc.pb(col[i]);

    sort(all(finr),greater<int>());
    sort(all(finc),greater<int>());

    int cntr = 0, cntc = 0;

    for (auto it:finr)
    {

        if (it==finr[0])
            cntr++;
        else
            break;
    }

    for (auto it:finc)
        if (it==finc[0])
            cntc++;
        else
            break;
    
    int rem = cntr*cntc;
   // debug3(cntr,cntc,rem);

    for (auto it:at)
        if ( row[it.ff.ff]==finr[0] && col[it.ff.ss]==finc[0] )
        {
     //       debug2(it.ff.ff,it.ff.ss);
            rem--;
        }
    
    if (rem)
        cout<<finr[0] + finc[0]<<endl;
    else
        cout<<finr[0] + finc[0]-1<<endl;
}

Measured memory_bytes: 35052
#include <bits/stdc++.h>
using namespace std;
using int64 = long long;
#define int int64
#define rep(i, n) for(int i=0; i<n; i++)
#define FOR(i, a, b) for(int i=a; i<b; i++)
#define SORT(x) sort(x.begin(), x.end())
#define GSORT(x) sort(x.begin(), x.end(), greater<int>())
#define mk make_pair
#define fi first
#define se second
#define pb push_back
#define ALL(x) x.begin(), x.end()
#define V(T) vector<T>
typedef pair<int, int> P;
typedef pair<P, P> PP;
typedef vector<int> vi;
typedef vector<vi> vvi;
int max(int a, int b) {if(b>a) return b; else return a;}
int min(int a, int b) {if(b<a) return b; else return a;}

const int INF = 1e15;

signed main() {
    int N, M;
    cin >> N >> M;
    vi A(N), B(N);
    vi sums(N+1, 0);
    rep(i, N) {
        cin >> A[i];
        B[i] = A[i];
    }
    SORT(A); GSORT(B);
    rep(i, N) sums[i+1] = sums[i] + B[i];
    

    int l=INF, r=0, mid;
    while(abs(l-r) > 1) {
        mid = (l+r)/2;
        int cnt = 0;
        int j = 0;
        rep(i, N) {
            while(j<A.size() && A[i]+B[j] >= mid) j++;
            cnt += j;
        }
        //cout << mid << " " << cnt << endl;
        if(cnt < M) l = mid;
        else r = mid;
    }
    //cout << endl << l << " " << r << endl;

    int res = 0, j=0, cnt=0;
    rep(i, N) {
        res += A[i]*j + sums[j];
        cnt += j; 
        while(j<A.size() && A[i]+B[j] >= r) {
            res += A[i]+B[j];
            //cout << r << " " << A[i]+B[j] << endl;
            j++;
            cnt++;
        }
    }
    //cout << cnt << endl;

    cout << res-(cnt-M)*r << endl;

    
    return 0;
}

Measured memory_bytes: 2560
using System;

class Program
{
  static void Main(String[] args)
  {
    var firstLine = Console.ReadLine().Split(' '); 
    int x = int.Parse(firstLine[0]) + 2;
    int y = int.Parse(firstLine[1]) + 2;
    int cnt1,cnt2,cnt3 = 0;
    String strBuff;
    char[,] mass = new char[x,y];
    bool result = true;

    for( cnt1 = 1; cnt1 < (x-1); cnt1++ )
    {
      strBuff = Console.ReadLine();
      
      for( cnt2 = 1; cnt2 < (y-1); cnt2++ )
      {
        mass[cnt1,cnt2] = strBuff[cnt2-1];
      }
    }
    
    for( cnt1 = 1; cnt1 < (x-1); cnt1++ )
    {
      for( cnt2 = 1; cnt2 < (y-1); cnt2++ )
      {
        if( mass[cnt1,cnt2] == '#' )
        {
          if( mass[(cnt1-1),cnt2] == '#' )
          {
            continue;
          }
          if( mass[cnt1,cnt2-1] == '#' )
          {
            continue;
          }
          if( mass[cnt1,cnt2+1] == '#' )
          {
            continue;
          }
          if( mass[(cnt1+1),cnt2] == '#' )
          {
            continue;
          }
          
          result = false;
          break;
        }
        else
        {
         /* 無処理 */ 
        }
      }
      
      if( result == false )
      {
        break;
      }
    }
    
    Console.WriteLine("{0}",(result?"Yes":"No"));
  }
}

Measured memory_bytes: 13140
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define repr(i, n) for (int i = n-1; i >= 0; i--)
#define ALL(x) x.begin(), x.end()
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;
const int mod = 1e9+7;
const int INF = 1e9;
const int MAX = 1e6;

int main() {
    int n, m;
    cin >> n >> m;
    int t = 1900 * m + 100 * (n - m);
    double p = pow(1.0 / 2, m);
    double ans = 0.0;
    rep(i, (int)1e5) {
        ans += (i + 1) * t * pow(1 - p, i) * p;
    }
    cout << (int)(ans + 0.0001) << endl;
}

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

int main(){
    int N, X, tmp=0, ans=1, dis=0;
    cin >> N >> X;
    vector<int> L(N), y(N), xDif(100000, 0), yDif(100000, 0);

    for(int i=0; i<N; i++){
	cin >> L[i];
    }

    for(int i=0; i<N; i++){
	if(dis + L[i] <= X){
	    ans ++;
	    dis += L[i];
	}
	else{
	    break;
	}
    }
    
    
    cout << ans<< endl;

}


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

int main() {
	string S;
	int ans = 0,count=0;
	cin >> S;
	for (int i = 0; i < S.size(); i++)
	{
		if (S.at(i)=='A'|| S.at(i) == 'C' || S.at(i) == 'G' || S.at(i) == 'T')
		{
			count++;
			ans = max(ans, count);
		}
		else {
			count = 0;
		}
	}
	cout << ans << endl;
}

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

int main() {
  string a,b,c;
  cin>>a>>b>>c;
  char A=a[0]-0x20;
  char B=b[0]-0x20;
  char C=c[0]-0x20;
  cout<<A<<B<<C<<endl;
}


Measured memory_bytes: 256
import os
import sys

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(10 ** 9)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7
# MOD = 998244353

H, W, N = list(map(int, sys.stdin.buffer.readline().split()))
h, w = list(map(int, sys.stdin.buffer.readline().split()))
S = sys.stdin.buffer.readline().decode().rstrip()
T = sys.stdin.buffer.readline().decode().rstrip()


def solve():
    # 縦横は独立に考えられる
    # これより左右にいたらダメ
    l = 0
    r = W + 1
    if S[-1] == 'L':
        l += 1
    if S[-1] == 'R':
        r -= 1
    for i in reversed(range(N - 1)):
        if T[i] == 'L':
            r += 1
            r = min(r, W + 1)
        if T[i] == 'R':
            l -= 1
            l = max(l, 0)

        if S[i] == 'L':
            l += 1
            l = max(l, 0)
        if S[i] == 'R':
            r -= 1
            r = min(r, W + 1)

        if W <= l:
            return False
        if r <= 1:
            return False
    if not l < w < r:
        return False

    u = 0
    d = H + 1
    if S[-1] == 'U':
        u += 1
    if S[-1] == 'D':
        d -= 1
    for i in reversed(range(N - 1)):
        if T[i] == 'U':
            d += 1
            d = min(d, H + 1)
        if T[i] == 'D':
            u -= 1
            u = max(u, 0)

        if S[i] == 'U':
            u += 1
            u = max(u, 0)
        if S[i] == 'D':
            d -= 1
            d = min(d, H + 1)

        if H <= u:
            return False
        if d <= 1:
            return False
    if not u < h < d:
        return False

    return True


ok = solve()
if ok:
    print('YES')
else:
    print('NO')


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

int main ()
{
	string s;  cin>>s;
	int ans=0;
	for(int i=0;i<4;i++){
		
		if(s[i]=='+') ++ans;
		else --ans;
		
		
		
	}
	
	cout<<ans<<endl;


}



Measured memory_bytes: 3572
#include <iostream>
#include <vector>
#include <algorithm>
#include <cassert>
#include <cmath>

using ll = long long;
#define MIN(a, b) (((a) < (b)) ? (a) : (b))
#define MAX(a, b) (((a) < (b)) ? (b) : (a))

int const nmax = 50;
int a[1 + nmax], b[1 + nmax];
int dp[1 + nmax][1 + nmax];

bool solve(int n, ll cost) {
  for(int i = 0;i <= nmax; i++)
    for(int j = 0;j <= nmax; j++)
      dp[i][j] = 0;
  for(int i = 0;i <= nmax; i++) {
    dp[i][i] = 1;
    for(int j = i; 0 <= j; j--) 
      for(int h = 1; h <= nmax; h++)
        if(0 < ((1LL << h) & cost))
          dp[i][j % h] |= dp[i][j];
  }
  for(int i = 1;i <= n; i++)
    if(dp[a[i]][b[i]] == 0)
      return false;
  return true;
}

int main() {
  int n;
  std::cin >> n;
  for(int i = 1;i <= n; i++) 
    std::cin >> a[i];
  for(int i = 1;i <= n; i++)
    std::cin >> b[i];
  ll result = (1LL << (nmax + 1)) - 2;
  if(solve(n, result) == 0) {
    std::cout << -1;
    return 0;
  }
  for(ll i = (1LL << nmax); 1 < i; i /= 2) {
    if(solve(n, result - i) == 1)
      result -= i;
  }
  std::cout << result;
  return 0;
}


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

typedef long long LL;
typedef long double LD;
typedef pair < int, int > PII;
typedef pair < LL, LL > PLL;
typedef pair < LD, LD > PDD;

#define _upgrade ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x).size()
template < typename _T > inline void _DBG(const char *s, _T x) { cerr << s << " = " << x << "\n"; }
template < typename _T, typename... args > void _DBG(const char *s, _T x, args... a) { while(*s != ',') cerr << *s++; cerr << " = " << x << ','; _DBG(s + 1, a...); }

#ifdef LOCAL
#define DBG(...) _DBG(#__VA_ARGS__, __VA_ARGS__)
#else
#define DBG(...) (__VA_ARGS__)
#define cerr if(0) cout
#endif

// ********************** CODE ********************** //

const int N = 101;

int n, m, p[] = {1, 0, 0, 1, -1, 0, 0, -1, 1, -1, -1, 1, -1, -1, 1, 1};
char s[N][N];

int main()
{
    _upgrade
    cin >> n >> m;
    for(int i = 1; i <= n; i++)
        cin >> (s[i] + 1);
    for(int i = 1; i <= n; i++)
    {
        for(int j = 1; j <= m; j++)
        {
            if(s[i][j] == '#') continue;
            char l = '0';
            for(int k = 0; k < 16; k += 2)
            {
                int ui = i + p[k], uj = j + p[k + 1];
                if(s[ui][uj] == '#') l++;
            }
            s[i][j] = l;
        }
    }
    for(int i = 1; i <= n; i++)
        cout << (s[i] + 1) << "\n";
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
typedef long long ll;
typedef long double ld;
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define mod 1000000007
#define inf 1000000000000000
#define bpc(x) __builtin_parityll(x)
#define autoit(x,it) for(auto it = x.begin(); it != x.end(); it++)
#define rep(n) for(ll i = 0; i < n; i++)
#define repi(i,n) for(ll i = 0; i < n; i++)

#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 

#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update> 

using namespace std;

int main()
{
   FAST/**/
   
   ll n,a,b;
   cin>>n>>a>>b;
   
   ll ans = 0;
   ans = n/(a+b);
   ans*=a;
   if(n%(a+b)<=a)
        ans+=(n%(a+b));
   else ans+=a;
   cout<<ans;
   
   
   
   return 0;        
}  
   

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

template <class T>
inline void read(T &x) {
    x = 0;
    char c = getchar();
    bool f = 0;
    for (; !isdigit(c); c = getchar()) f ^= c == '-';
    for (; isdigit(c); c = getchar()) x = x * 10 + (c ^ 48);
    x = f ? -x : x;
}

template <class T>
inline void write(T x) {
    if (x < 0) {
        putchar('-');
        x = -x;
    }
    T y = 1;
	int len = 1;
    for (; y <= x / 10; y *= 10) ++len;
    for (; len; --len, x %= y, y /= 10) putchar(x / y + 48);
}

const int MAXN = (1 << 18) + 5;
int n, m, k, maxn, ans[MAXN + 5];

int main() {
	read(m), read(k);
	maxn = (1 << m) - 1, n = 1 << (m + 1);
	if (m == 1) {//特判 m = 1 
		if (k == 0) puts("0 0 1 1");
		else puts("-1");
		return 0;
	}
	if (k > maxn) {//无解 
		puts("-1");
		return 0;
	}
	ans[n / 2] = ans[n] = k;
	for (int p = 0, i = 1; i <= maxn; ++i, ++p) {
		if (p == k) ++p;
		ans[i] = ans[n - i] = p;
	}
	for (int i = 1; i <= n; ++i) {
		write(ans[i]);
		putchar(' ');
	}
	putchar('\n');
	return 0;
}

Measured memory_bytes: 2816
fun main(args: Array<String>) {

    val n = readLine()!!.toInt()

    val nodes = mutableListOf<MutableList<Int>>()
    for (i in 0 until n) {
        nodes.add(mutableListOf())
    }

    for (i in 0 until n-1) {
        val (a, b) = readLine()!!.split(" ").map { it.toInt() }
        nodes[a-1].add(b-1)
        nodes[b-1].add(a-1)
    }

    val inputs = readLine()!!.split(" ").map { it.toInt() }.toMutableList()
    inputs.sortDescending()

    val iter = inputs.iterator()
    val attr = IntArray(n) {0}

    attr[0] = iter.next()

    var color = IntArray(n) {0}

    fun paint(now: Int) {
        color[now] = 1

        if (!iter.hasNext()){
            return
        }

        for(i in 0 until nodes[now].size){

            if(color[nodes[now][i]] == 1){
                continue
            }

            // 各ノードへ割当
            attr[nodes[now][i]] = iter.next()

            // 次のノードをペイント
            paint(nodes[now][i])
        }
    }

    var ans = 0L
    fun calc(now: Int) {
        color[now] = 1

        for(i in 0 until nodes[now].size){

            if(color[nodes[now][i]] == 1){
                continue
            }
            // スコアを計算
            ans+=attr[nodes[now][i]]

            // 次のノードで計算
            calc(nodes[now][i])
        }
    }

    paint(0)

    color = IntArray(n) {0}
    calc(0)

    println(ans)
    println(attr.toList().joinToString(" "))
}

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

#define repi(i, a, b) for(int i = (int)(a); i < (int)(b); ++i)
#define rep(i, n) repi(i, 0, n)
#define all(x) (x).begin(), (x).end()

const int MAX_N = 1e5;
const long long INF = 10e10;
int N, M;
long long DP[MAX_N + 10];

inline void Main() {
  // code
  cin >> N >> M;
  rep(i, N+1) DP[i] = INF;
  DP[0] = 1;
  DP[1] = 1;
  rep(i, M) {
    int x;
    cin >> x;
    DP[x] = 0;
  }
  repi(i, 2, N+1) {
    if(DP[i] == INF) {
      DP[i] = (DP[i-1] + DP[i-2]) % 1000000007;
    }
  }
  cout << DP[N] << endl;
}

int main() {
  std::cin.tie(0);
  std::ios::sync_with_stdio(false);
  std::cout << std::fixed << std::setprecision(20);
  Main();
  return 0;
}


Measured memory_bytes: 1024
n,m,x=map(int,input().split())
l=[]

for i in range(n):
    a=list(map(int,input().split()))
    l.append(a)
ans=99999999
for i in range(2 ** n):
    bag = []
    for j in range(n):  #bit全探索
        if ((i >> j) & 1): 
            bag.append(l[j])  
    skill=[0]*m
    enough=[0]*m #各スキルにつき、xを超えているかどうかを判断
    money=0
    for sub in bag:
        money+=sub[0]
        for kk in range(1,m+1):
            skill[kk-1]+=sub[kk]
            if skill[kk-1]>=x:
                enough[kk-1]+=1
    if 0 not in enough: #全てのスキルがxを超えていたら価格を計算
        if ans>money:
            ans=money#最低価格を下回っていたら更新
if ans==99999999: #初期値からの変更がなければ-1を、そうでなければ最低価格を出力
    print(-1)
else:
    print(ans)

Measured memory_bytes: 9184
#include <bits/stdc++.h>
using namespace std;
int main(){
	//freopen("","r",stdin);
	//freopen("","w",stdout);
	int a,b;
	cin>>a>>b;
	if(a>=10){
		cout<<b;
		return 0;
	}
	cout<<b+100*(10-a);

}


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

int p,q,r;

char perse(string x){
  string tmp;
  int n,c;
  char op,a,b;
  if(x[0] == '-'){
    x.erase(x.begin());
    return '0' + '2' - perse(x);
  }
  if(x[0] == '('){
    tmp.clear();
    n = 1;
    c = 0;
    while( c || (x[n] != '+' && x[n] != '*') ){
      if(x[n] == '(')c++;
      if(x[n] == ')')c--;
      tmp.push_back(x[n]);
      n++;
    }
    a = perse(tmp);
    op = x[n];

    tmp.clear();
    n++;
    while( c || x[n] != ')' ){
      if(x[n] == '(')c++;
      if(x[n] == ')')c--;
      tmp.push_back(x[n]);
      n++;
    }
    b = perse(tmp);

    if(op == '+'){
      if(a=='2' || b=='2')return '2';
      else if(a=='1' || b=='1')return '1';
      else return '0';
    }else if(op == '*'){
      if(a=='0' || b=='0')return '0';
      else if(a=='1' || b=='1')return '1';
      else return '2';
    }
  }

  if(x[0] == 'P')return '0' + p;
  if(x[0] == 'Q')return '0' + q;
  if(x[0] == 'R')return '0' + r;

  return x[0];
}
 
int main(){

  int c;
  string s;

  while(1){
    cin >> s;
    if(s==".")break;

    c = 0;
    for(p=0;p<3;p++){
      for(q=0;q<3;q++){
	for(r=0;r<3;r++){
	  if(perse(s) == '2')c++;
	}
      }
    }

    cout << c << endl;
  }
}

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


    int dp[3001][3001];

int main(){
    string a,b;
    cin >> a >> b;
    a=' '+a;
    b=' '+b;
    int n= a.size();
    int m= b.size();
    for(int i=1;i<n;i++){
        for(int j=1;j<m;j++){
            dp[i][j]= max(dp[i-1][j], dp[i][j-1]);
            if(a[i]==b[j])
            dp[i][j]= max(dp[i][j], dp[i-1][j-1]+1);
        }
    }
    
    int i=n-1;
    int j=m-1;
    stack<char> st;
    while(i!=0 && j!=0){
        if(dp[i][j]==dp[i-1][j]){
            i-=1;
        }
        else if(dp[i][j]==dp[i][j-1]){
            j-=1;
        }else{
            st.push(a[i]);
            i-=1; j-=1;
        };
       // cout << i << " " << j << endl;
    }
    while(!st.empty()){
    cout << st.top(); st.pop();}
}

Measured memory_bytes: 35456
#include<stdio.h>
#include<algorithm>
#include<functional>
using namespace std;
int main(void)
{
	int a, b, c;
	char s, k;
	scanf("%d%c%d%c%d", &a, &s, &b, &k, &c);
	if (a <= 2019) {
		if (b <= 4) {
			if (c <= 30) {
				printf("Heisei");
				return 0;
			}
		}
	}
	printf("TBD");
	return 0;
}


Measured memory_bytes: 128
K, N = map(int, input().split())
A = list(map(int, input().split()))
li = []
for i in range(N):
    if i == 1:
        cadA = A[N-1] - A[0]
    else:
        cadA = K - A[i] + A[i-1]
    if i == N-1:
        cadB = A[N-1] - A[0]
    else:
        cadB = A[i] + (K - A[i+1])
    li.append(min(cadA, cadB))
print(min(li))


Measured memory_bytes: 32284
#include <bits/stdc++.h>
#define infll (1ll<<60)
#define mod 1000000007
#define prev meow
#define l_ength size
using ll = long long;
using namespace std;

ll dist[310][310];
ll mr[310][310];

int main(){
	int n, m; ll l;
	cin >> n >> m; cin >> l;
	// init
	for( int i = 0; i < n; ++i ){
		for( int j = 0; j < n; ++j ){
			dist[i][j] = infll;
			mr[i][j] = infll;
		}
		dist[i][i] = 0;
		mr[i][i] = 0;
	}
	for( int i = 0; i < m; ++i ){
		int a, b; ll c; cin >> a >> b >> c; --a; --b;
		if( c <= l ) dist[a][b] = dist[b][a] = c;
	}
	for( int k = 0; k < n; ++k ){
		for( int i = 0; i < n; ++i ){
			for( int j = 0; j < n; ++j ){
				dist[i][j] = min(dist[i][j], dist[i][k]+dist[k][j]);
			}
		}
	}
	for( int i = 0; i < n; ++i ){
		for( int j = 0; j < n; ++j ){
			if( dist[i][j] <= l ){
				mr[i][j] = 1;
			}
		}
	}
	for( int k = 0; k < n; ++k ){
		for( int i = 0; i < n; ++i ){
			for( int j = 0; j < n; ++j ){
				mr[i][j] = min(mr[i][j], mr[i][k]+mr[k][j]);
			}
		}
	}
	int q; cin >> q;
	while( q-- ){
		int s, t; cin >> s >> t; --s; --t;
		if( mr[s][t] == infll ) cout << -1 << endl;
		else cout << mr[s][t]-1 << endl;
	}
}

Measured memory_bytes: 2048
#include <algorithm>
#include <bitset>
#include <cmath>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <vector>
#define ll long long
using namespace std;
const int MOD = 1000000007;
const long long INF = 1LL << 60;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll d, t, s;
  cin >> d >> t >> s;
  if (d <= t * s) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}

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

typedef long long int LL;
#define ED return 0;
#define UP(a,b) ((a+(b-1))/b)
#define SORT(vec) sort(vec.begin(),vec.end());
#define DOUBLECHANGE(count) cout << setprecision(count);
#define REV(vec) reverse(vec.begin(),vec.end());
#define ipow(x) LL(pow(x))
#define EQUAL(vec1,vec2) equal((vec1).cbegin(), (vec1).cend(), (vec2).cbegin());
const int INF = 999999999;
const long long int mod = 1000000007;

int ans = 0;
void roop(int now,vector<vector<bool>> vec,vector<bool> leave,int N){
    bool end = true;
    for(int i = 0;i < N;i++){
        if(vec[now][i] && !leave[i]){
            leave[i] = true;
            roop(i,vec,leave,N);
            leave[i] = false;
        }
        if(!leave[i])end = false;
    }
    if(end){
        ans++;
    }
    return;
}

int main() {
   int N, M;
   cin >> N >> M;
   vector<vector<bool>> vec (N, vector<bool>(N,false));
   vector<bool> leave (N,false);
//   cout << "N = " << N << ",M = " << M << endl;
   for(int i = 0;i < M;i++){
//       cout << "I = " << i << endl;
       int a, b;
       cin >> a >> b;
       vec[a-1][b-1] = true;
       vec[b-1][a-1] = true;
   }
//   cout << "CIN END" << endl << "------------------------------------" << endl;
   leave[0] = true;
   roop(0,vec,leave,N);
   cout << ans << endl;
}


Measured memory_bytes: 256
n = int(input())
if n >= 64:
    print(64)
elif n >= 32:
    print(32)
elif n >= 16:
    print(16)
elif n >= 8:
    print(8)
elif n >= 4:
    print(4)
elif n >= 2:
    print(2)
else:
    print(1)


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

using namespace std;

typedef long long ll;

const int mod = 1e9 + 7;
const int N = 2e5 + 10;
int fact[N];
int factInv[N];
int inv[N];

int mul(int a, int b)
{
  a = (a + mod) % mod;
  b = (b + mod) % mod;
  return ((ll)a * b) % mod;
}

int add(int a, int b)
{
  a = (a + mod) % mod;
  b = (b + mod) % mod;
  return (a + b) % mod;
}

int fastpow(int base, int power)
{
  if(!power)
    return 1;
  int ret = fastpow(base, power / 2);
  ret = mul(ret, ret);
  if(power & 1)
    ret = mul(ret, base);
  return ret;
}

void init()
{
  fact[0] = 1;
  for(int i = 1; i < N; i++)
    fact[i] = mul(fact[i - 1], i);
  inv[1] = 1;
  for(int i = 2; i < N; i++)
    inv[i] = mul(-mod / i, inv[mod % i]);
  factInv[1] = factInv[0] = 1;
  for(int i = 2; i < N; i++){
     factInv[i] = mul(factInv[i - 1], inv[i]);
   }
}

int ncr(int n, int r)
{
  return mul(fact[n], mul(factInv[r], factInv[n - r]));
}

int ways(int x1, int y1, int x2, int y2)
{
  int n = (x2 - x1);
  int m = (y2 - y1);
  return ncr(n + m, n);
}

int h, w;
int n;
vector<pair<int, int>> obs;
int dp[3005][3005];

int solve(int idx, int prev)
{
    if(idx == n){
        return add(-ways(obs[prev].first, obs[prev].second, h, w), 0);
    }
    int &ans = dp[idx][prev];
    if(~ans)
      return ans;
    ans = solve(idx + 1, prev);
    if(obs[prev].second <= obs[idx].second)
    {
      ans = add(ans, mul(-ways(obs[prev].first, obs[prev].second, obs[idx].first, obs[idx].second),
                          solve(idx + 1, idx)));
    }
    return ans;
}

int main()
{
  init();
  cin >> h >> w >> n;
  for(int i = 0; i < n; i++)
  {
    int x, y;
    cin >> x >> y;
    obs.push_back({x, y});
  }
  sort(obs.begin(), obs.end());
  int ans = ways(1, 1, h, w);
  memset(dp, -1, sizeof dp);
  for(int i = 0; i < n; i++)
  {
    ans = add(ans, mul(ways(1, 1, obs[i].first, obs[i].second), solve(i + 1, i)));
  }
  cout << ans;
  return 0;
}


Measured memory_bytes: 38016
def d_friend_suggestions():
    N, M, K = [int(i) for i in input().split()]
    Friends = [[int(i) - 1 for i in input().split()] for j in range(M)]
    Blocked = [[int(i) - 1 for i in input().split()] for j in range(K)]

    class UnionFind(object):
        def __init__(self, n):
            """要素番号は 0 スタートを前提とする"""
            self.num_element = n
            self.parents = [-1] * n  # 要素が根の場合は、-(グループの要素数) を格納

        def find(self, x):
            """要素 x が属するグループの根を返す"""
            if self.parents[x] < 0:
                return x
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

        def union(self, x, y):
            """要素 x が属するグループと要素 y が属するグループとを併合する"""
            u, v = self.find(x), self.find(y)

            if u == v:
                return

            # u のグループの方が要素数が少なかった (parents の 定義より)
            if self.parents[u] > self.parents[v]:
                u, v = v, u

            self.parents[u] += self.parents[v]  # u と同グループの要素数を増やす
            self.parents[v] = u  # v は u に繋げる

        def get_size(self, x):
            """要素 x が属するグループの要素数を返す"""
            return -self.parents[self.find(x)]

        def is_same(self, x, y):
            """要素 x, y は同じグループに属するか？"""
            return self.find(x) == self.find(y)

    uf = UnionFind(N)
    degree = [0] * N
    for a, b in Friends:
        uf.union(a, b)
        degree[a] += 1
        degree[b] += 1
    for c, d in Blocked:
        if uf.is_same(c, d):
            degree[c] += 1
            degree[d] += 1

    ans = [uf.get_size(i) - 1 - degree[i] for i in range(N)]
    return ' '.join(map(str, ans))

print(d_friend_suggestions())

Measured memory_bytes: 51940
class UnionFind:
    def __init__(self, n):
        self.par = [i for i in range(n+1)]
        self.rank = [0] * (n+1)

    # 検索
    def find(self, x):
        if self.par[x] == x:
            return x
        else:
            self.par[x] = self.find(self.par[x])
            return self.par[x]

    # 併合
    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if self.rank[x] < self.rank[y]:
            self.par[x] = y
        else:
            self.par[y] = x
            if self.rank[x] == self.rank[y]:
                self.rank[x] += 1

    # 同じ集合に属するか判定
    def same_check(self, x, y):
        return self.find(x) == self.find(y)

N, M = map(int, input().split())

bridge = [list(map(int, input().split())) for i in range(M)]
ans = 0
for i in range(M):
    UF = UnionFind(N)
    for j in range(M):
         if i == j:
              continue
         a, b = bridge[j]
         if not UF.same_check(a, b):
            UF.union(a, b)
    flag = 0
    for k in range(1, N+1):
        if UF.par[k] == k:
            flag += 1
    if flag != 1:
        ans += 1
print(ans)
        
            


Measured memory_bytes: 43116
#include <bits/stdc++.h>
#define loop(n, i) for(int i=0;i<n;i++)
#define HERE cout << "HERE: " << __LINE__ << endl;
#define INSP(v) cout << v << " at " << __LINE__ << endl;
using namespace std;
using ll = long long;
template <class T>
using V = vector<T>;
using P = pair<ll, ll>;


void solve(std::string b){
    if (b == "A") cout << "T" << endl;
    else if (b == "T") cout << "A" << endl;
    else if (b == "G") cout << "C" << endl;
    else if (b == "C") cout << "G" << endl;
}

int main(){
    std::string b;
    std::cin >> b;
    solve(b);
    return 0;
}



Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<queue>
#include<vector>
#include<string.h>
#include<algorithm>
#include <cmath>
#include<map>

using namespace std;

long long A,B,K,i,j,k,X;

int main()
{
  cin>>X;
  
  A=100;
  i=0;
  while(A<X)
  {
    A=A+A/100;
    i++;
  }
  
  cout<<i;
  
}

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

int n, a[200200], c[200200]; long long r;

int main()
{
	cin >> n;
	for (int i = 0; i < n; i++){
		cin >> a[i];
		r += c[a[i]]++;
	}

	for (int i = 0; i < n; i++){
		r -= --c[a[i]];
		cout << r << endl;
		r += c[a[i]]++;
	}

	return 0;
}

Measured memory_bytes: 4724
#include<iostream>
#include<algorithm>
#include<cmath>
#include<string>
#include<array>
#include<vector>
#include<functional>
#include<unordered_map>
#include<map>
#include<numeric>
#include<limits>
#include<utility>
#include<queue>
#include<random>
using namespace std;

int main(){
 
    string s;
   int N[4];
    
    cin >> s ;
    for(int i = 0;i<=3;i++){
    N[i] = s[i];
    }    
    if((N[0] == N[1] && N[1] == N[2]) || (N[1]==N[2] && N[2]==N[3])){
    cout << "Yes" << endl;}
    else {cout << "No" << endl;}
    
    return 0;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <cctype>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <functional>
using namespace std; 
#define DEBUG(x) cout << '>' << #x << ':' << x << endl;
#define REP(i,n) for(int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<=(b);i++)
#define FORD(i,a,b) for(int i=(a);i>=(b);i--)
inline bool EQ(double a, double b) { return fabs(a-b) < 1e-9; }
const int INF = 1<<29;
typedef long long int ll;
inline int two(int n) { return 1 << n; }
inline int test(int n, int b) { return (n>>b)&1; }
inline void set_bit(int & n, int b) { n |= two(b); }
inline void unset_bit(int & n, int b) { n &= ~two(b); }
inline int last_bit(int n) { return n & (-n); }
inline int ones(int n) { int res = 0; while(n && ++res) n-=n&(-n); return res; }
template<class T> void chmax(T & a, const T & b) { a = max(a, b); }
template<class T> void chmin(T & a, const T & b) { a = min(a, b); }
const int MOD=1000000007;

bool isPowerOfTwo (ll x)  
{  
    return x && (!(x&(x-1)));  
}
bool isPrime(int n) 
{ 
    if (n <= 1)  return false; 
    if (n <= 3)  return true; 
    if (n%2 == 0 || n%3 == 0) return false; 
  
    for (int i=5; i*i<=n; i=i+6) 
        if (n%i == 0 || n%(i+2) == 0) 
           return false; 
  
    return true; 
}
int highestPowerof2(unsigned int n) 
{ 
    // Invalid input 
    if (n < 1) 
        return 0; 
  
    int res = 1;
    for (int i=0; i<8*sizeof(unsigned int); i++) 
    { 
        int curr = 1 << i; 
        if (curr > n) 
           break; 
  
        res = curr; 
    } 
  
    return res; 
} 
long long binpow(long long a, long long b) {
    long long res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a;
        a = a * a;
        b >>= 1;
    }
    return res;
}       
////////////////////////////////////////////////////////////////////

int main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);  
  cout.tie(NULL);
  ll t=1;
  while(t--)
  {
    int n,k;
    cin>>n>>k;
    cout<<k*binpow(k-1,n-1)<<"\n";
  }  
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define f(i, x, n) for(int i = x; i < (int)(n); ++i)
#define speed ios::sync_with_stdio(0); cin.tie(0);
int const N = 2 * 1e6 + 2;
int main(){
	int n, mx = -1, sum = 0;
	cin >> n;
	f(i, 0, n){
		int x;
		cin >> x;
		mx = max(mx, x);
		sum += x;
	}
	sum-=mx;
	cout << sum + (mx / 2) << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdlib>
#include <cmath>
#include <iomanip>
using namespace std;
int main(void){
  double N,K;
  cin >> N >> K;

  double ans = 0;

  for(int i=1;i<=N;i++){
    //cout << "i=" << i << endl;
    int a = i;
    int count = 0;
    double rate = 1.0;
    while(a < K){
      a *= 2;
      count++;
    }
    for(int j=0;j<count;j++){
      rate /= 2.0;
      //cout << rate << endl;
    }
    ans += 1 / N * rate;
  //  cout << ans << endl;
  }

  cout << setprecision(15) << ans << endl;

  return 0;
}


Measured memory_bytes: 256
# 0や1のケースに注意
# index out of range
# 貪欲

def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**7)
    from collections import Counter, deque
    from itertools import combinations, permutations, accumulate, groupby, product
    from bisect import bisect_left,bisect_right
    from heapq import heapify, heappop, heappush
    import math
    #from math import gcd

    #inf = 10**17
    #mod = 10**9 + 7

    t = input().rstrip()
    res = []
    for i in range(len(t)):
        if t[i] != '?':
            res.append(t[i])
        else:
            res.append('D')
    print(''.join(res))

if __name__ == '__main__':
    main()

Measured memory_bytes: 82344
require 'set'

class Hash
  def push(key, value)
    self[key] = [] if self[key] == nil
    self[key].push(value)
  end
end

def get_ints
  gets.split.map(&:to_i)
end

def get_ints_minus_one
  get_ints.map { |x| x - 1 }
end

def get_int
  gets.chomp.to_i
end

N = get_int
A = get_ints

threshold = 10**18

if A.include?(0)
  puts 0
else
  result = 1

  N.times do |i|
    result *= A[i]
    if result > threshold
      result = -1
      break
    end
  end

  puts result
end


Measured memory_bytes: 21656
#include <iostream>
#include <vector>
#include <cstring>
#include <climits>
using namespace std;

typedef pair<int,int> P;

int n, m, ans;
int used[102];
vector<P> t[102];

int calcCost(){
  int res = 0;

  for(int i = 0; i < n; i++){
    if(used[i] == 0) continue;

    int minCost = INT_MAX;

    for(int j = 0; j < t[i].size(); j++){
      P p = t[i][j];
      if(used[p.first] == 0) continue;
      minCost = min(minCost, p.second);
    }

    if(minCost != INT_MAX){
      res += minCost;
    }
  }

  return res;
}

bool check(int id, int cnt){
  for(int i = 0; i < t[id].size(); i++){
    int to = t[id][i].first;
    if(used[to] != 0) cnt--;
  }

  return cnt == 0;
}

void dfs(int id, int cnt){
  if(id == n){
    ans = max(ans, calcCost());
    return;
  }

  dfs(id + 1, cnt);

  if(check(id, cnt)){
    used[id] = true;
    dfs(id + 1, cnt + 1);
    used[id] = false;
  }

  ans = max(ans, calcCost());
}

void solve(){
  memset(used, 0, sizeof(used));
  ans = INT_MIN;
  dfs(0, 0);
  cout << ans << endl;
}

int main(){
  while(cin >> n >> m){
    for(int i = 0; i < n; i++){
      t[i].clear();
    }

    for(int i = 0; i < m; i++){
      int a, b, c;
      cin >> a >> b >> c;
      a--;
      b--;
      t[a].push_back(P(b, c));
      t[b].push_back(P(a, c));
    }

    solve();
  }
}

Measured memory_bytes: 868
#include <stdio.h>

int main(void)
{
    char a;
    int b, k;
    //表を用意する。
    int card[4][13] = {{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}};

    //持っている枚数を聞く。
    int n;
    scanf("%d", &n);

    //カードの記号と数字をn回聞く。
    int i;

    for (i = 0; i < n; i++)
    {

        scanf(" %c %d", &a, &k);
        //表の0の部分を持っているカードのところだけ１に変える。

        if (a == 'S')
        {
            b = 0;
        }
        else if (a == 'H')
        {
            b = 1;
        }
        else if (a == 'C')
        {
            b = 2;
        }
        else if (a == 'D')
        {
            b = 3;
        }

        card[b][k - 1] = 1;
    }

    //０のそれぞれ記号と数字の間に空白を挟み一行ずつに並べる。
    int j, q;
    char r;

    for (q = 0; q < 4; q++)
    {

        if (q == 0)
        {
            r = 'S';
        }
        else if (q == 1)
        {
            r = 'H';
        }
        else if (q == 2)
        {
            r = 'C';
        }
        else if (q == 3)
        {
            r = 'D';
        }
        for (j = 0; j < 13; j++)

            if (card[q][j] == 0)
                printf("%c %d\n", r, j + 1);
    }
    return 0;
}


Measured memory_bytes: 2700
N,K=map(int,input().split())
A=list(map(int,input().split()))
L=[0 for i in range(40)]
for i in range(N):
    A[i]+=2**40
    A[i]=bin(A[i])
    A[i]=A[i][3:]
    A[i]=list(A[i])
#print(len(A[0]))
for i in range(len(A)):
    for j in range(len(A[0])):
        L[j]+=int(A[i][j])
#print(L)

ans=0
for i in range(40):
    if K>=2**(39-i):
        if L[i]<=(N/2):
            ans+=(2**(39-i))*(N-L[i])
            K-=2**(39-i)
        else:
            ans+=(2**(39-i))*(L[i])
    else:
        ans+=(2**(39-i))*(L[i])
print(ans)

Measured memory_bytes: 52852
#include <bits/stdc++.h>
     
        using namespace std;
        #define sd(x) scanf("%d",&x);
        #define sdl(x) scanf("%lld",&x);
        #define pr(x) printf("%d\n",x);
        #define prl(x) printf("%lld\n",x);

    void solve()
    {
        int a,b,c,d;
        cin >> a >> b >> c >> d;

        if (ceil((c*1.0)/b)<=ceil((1.0*a)/d))
            cout << "Yes" << endl;
            else cout << "No" << endl;
    }

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

     for (int tt=1;tt<=t;tt++)
     {
         solve();
     }

    return 0;
     
     
     
     
        }


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

//#define int long long
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<n;++i)
#define exrep(i, a, b) for(ll i = a; i < b; i++)
#define out(x) cout << x << endl
#define EPS (1e-7)
#define gearup ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<pair<int,int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<bool> > vvb;
typedef vector<vector<double> > vvd;
typedef vector<vector<string> > vvs;
typedef vector<ll> vl;
typedef vector<vector<ll> > vvl;
typedef vector<vector<vector<ll> > > vvvl;
ll MOD = 1000000007;
const long long L_INF = 1LL << 60;
const int INF = 2147483647; // 2^31-1
const double PI = acos(-1);
//cout<<fixed<<setprecision(10);

template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b;return true;}return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b;return true;}return false;}
template<class T> void debug(T v){rep(i,v.size()) cout<<v[i]<<" ";cout<<endl;}
const ll dx[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll dy[8] = {0, 1, 1, 1, 0, -1, -1, -1};

signed main()
{   
  gearup;
  int k;
  string s;cin>>k>>s;
  int n = s.size();
  if(k >= n)out(s);
  else{
    cout << s.substr(0,k) << "..." << endl;
  }
}

Measured memory_bytes: 3656
#include<bits/stdc++.h>
/************************************************/
#define rep(i,n) for(int i=0;i<n;i++)
#define m_p make_pair
#define pb push_back
#define fr first
#define se second
#define forn(i,a,n) for(int i=a;i<n;i++)
#define foreach(i,c) for(__typeof(c.begin())i=(c.begin());i!=(c).end();i++)
#define pii pair<int,int>
#define vi vector<int>
#define ll long long
#define sz(s) s.size()
#define all(s) s.begin(),s.end()
#define zero(x) memset(x,0,sizeof(x))
#define vii vector<pair<int,int> >
#define mpis map<int,string>
#define mpii map<int,int>
#define mpsi map<string,int>
#define re return
#define mod 1000000007
/************************************************/
using namespace std;

long long get(){
	char c=getchar();
	long long x=0LL;
	while(c<'0'||c>'9')
	c=getchar();
	while(c>='0'&&c<='9'){
		x*=10LL;
		x+=(c-'0');
		c=getchar();
	}
	return x;
}
ll m[100],h;
int c;
int main(){
	ll now=1;
	rep(i,41){
		m[i]=now;
		now*=2ll;
	} 
	cin>>h;
	while(h){
		h/=2ll;
		c++;
	}
	ll ans=0ll;
	rep(i,c)
	ans+=m[i];
	cout<<ans;
	re 0;
}


Measured memory_bytes: 256