akhauriyash/Code-Regression huggingface dataset:
// Author : Rifayat Samee (Sanzee)
// Problem :
// Algorithm:

/*

*/
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll Mod = 1e9+7;
//Matrix class
struct matrix{
    int row,col;
    ll det[55][55];
    void init(){
        row = 0;
        col = 0;
    }
    void clear(){
        for(int i=0; i<row; i++){
            for(int j=0; j<col; j++){
                det[i][j] = 0;
            }
        }
    }
    void make_it_indentity(){
        for(int i=0; i<row; i++){
            for(int j=0; j<col; j++){
                if(i==j)
                    det[i][j] = 1;
                else
                    det[i][j] = 0;
            }
        }
    }
    matrix operator*(matrix M){
        int c,r;
        r = M.row;
        c = M.col;
        matrix R;
        R.row = row;
        R.col = M.col;
        for(int i=0; i<row; i++){
            for(int j=0; j<M.col; j++){
                R.det[i][j] = 0;
                for(int k=0; k<col; k++){
                    ll sum = ((det[i][k]%Mod) * (M.det[k][j]%Mod))%Mod;
                    R.det[i][j] = (R.det[i][j]%Mod + sum%Mod)%Mod;
                }
            }
        }
        return R;
    }
};

matrix matrix_exp(matrix ma,ll P){
    double d;
    matrix res,x;
    x = ma;
    res.row = ma.row;
    res.col = ma.col;
    res.make_it_indentity();
    int mb,i;
    d = log10(P)/log10(2)+1;
    mb = (int)d;
    for(i=0; i<mb; i++){
       if(P&((ll)1<<i))
            res = res*x;
        x = x*x;
    }
    return res;
}

int main(){

	//freopen("in.txt","r",stdin);
	//freopen("out.txt","w",stdout);
    ll n,k;
    scanf("%lld %lld",&n,&k);
    matrix A;
    A.row = n;
    A.col = n;
    for(int i=0;i<n;i++){
        for(int j=0;j<n;j++){
            scanf("%lld",&A.det[i][j]);
        }
    }
    matrix R = matrix_exp(A,k);
    ll res = 0;
    for(int i=0;i<n;i++){
        for(int j=0;j<n;j++){
            res = (res + R.det[i][j])%Mod;
        }
    }
    printf("%lld\n",res);

	return 0;
}


Measured memory_bytes: 384
for i in range(1,51):
    m,f,r=map(int,input().split())
    if m==-1 and f==-1 and r==-1:
        break
    elif m==-1 or f==-1:
        print("F")
    elif m+f>=80:
        print("A")
    elif m+f>=65 and m+f<80:
        print("B")
    elif m+f>=50 and m+f<65:
        print("C")
    elif m+f>=30 and m+f<50:
        if r>=50:
            print("C")
        else:
            print("D")
    elif m+f<30:
        print("F")


Measured memory_bytes: 5592
#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef long long ll;
typedef pair<int,int> pii;
#define ITR(v,c) for(auto v=begin(c);v!=end(c);v++)
#define FOR(v,a,n) for(int v=a;v<(int)(n);v++)
#define FORE(x,arr) for(auto &x:arr)
#define REP(v,n) FOR(v,0,n)
#define RREP(v,n) for(int v=(int)(n);v>=0;v--)
#define ALL(c) begin(c),end(c)
const int DX[4]={0,1,0,-1}, DY[4]={-1,0,1,0};
const int DX9[9]={0,1,1,1,0,-1,-1,-1,0}, DY9[9]={-1,-1,0,1,1,1,0,-1,0};
const int INF = 1e9;
const ll INFLL = 1e18;
template<class T,class U>ostream&operator<<(ostream &os,const pair<T,U> &p){
    os<<"("<<p.first<<","<<p.second<<")";return os;}
template<class T>ostream&operator<<(ostream &os,const vector<T> &v){
    ITR(i,v)os<<*i<<(i==end(v)-1?"":"\n");return os;}
//------------------------------------------------------------------------------

signed main() {
    int H,W,N;
    cin>>H>>W>>N;
    vector<int> ans(10);
    set<pii> c;
    ans[0]=(H-2)*(W-2);
    REP(i,N) {
        int a,b;
        cin>>a>>b;
        a--; b--;
        REP(j,9) {
            int x=b+DX9[j],y=a+DY9[j];
            if(x<1 || y<1 || x>=W-1 || y>=H-1) continue;
            int black=0;
            REP(k,9) {
                int nx=x+DX9[k], ny=y+DY9[k];
                if(c.find(pii(ny,nx))!=end(c)) black++;
            }
            ans[black]--;
            ans[black+1]++;
        }
        c.insert(pii(a,b));
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 6528
#include<bits/stdc++.h>
using namespace std;
#define rep(i, a, b) for(register int i = (a), i##_end_ = (b); i <= i##_end_ ; ++i)
#define drep(i, a, b) for(register int i = (a), i##_end_ = (b); i >= i##_end_ ; --i)
#define clear(a, b) memset((a), (b), sizeof(a))
typedef long long LL;
int read() {
	int x = 0, flag = 1;
	char ch = getchar();
	while(!isdigit(ch)) {
		if(ch == '-') flag = -1;
		ch = getchar();
	}
	while(isdigit(ch)) {
		x = (x << 3) + (x << 1) + (ch - 0x30);
		ch = getchar();
	}
	return flag * x;
}

#define Maxn 100009
int n, a[Maxn];
int pos[Maxn];
LL dis[Maxn];
int m, base[Maxn], r[Maxn], tmp[Maxn];
LL k;
void Permutation_FPower(LL b) {
	rep(i, 1, n) r[i] = i;
	rep(i, 1, n) base[i] = pos[i];
	while(b) {
		if(b & 1) {
			rep(i, 1, n) tmp[i] = r[base[i]];
			rep(i, 1, n) r[i] = tmp[i];
		}
		rep(i, 1, n) tmp[i] = base[base[i]];
		rep(i, 1, n) base[i] = tmp[i];
		b >>= 1;
	}
}
int main() {
#ifdef Qrsikno
	freopen("h.in","r",stdin);
	freopen("h.out","w",stdout);
#endif
	n = read();
	rep(i, 1, n) a[i] = read(), dis[i] = a[i] - a[i - 1], pos[i] = i;
	scanf("%d %lld\n", &m, &k);
	rep(i, 1, m) {
		int x = read();	
		swap(pos[x], pos[x + 1]);
	}
	Permutation_FPower(k);
	rep(i, 1, n) tmp[i] = dis[r[i]];
	rep(i, 1, n) dis[i] = tmp[i];
	LL now_Position = 0;
	rep(i, 1, n) {
		now_Position += dis[i];
		printf("%.1lf\n", now_Position * 1.0);
	}
	return 0;
}


Measured memory_bytes: 4224
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <functional>
#include <queue>
#include <string>
#include <cstring>
#include <numeric>
#include <cstdlib>
#include <cmath>
using namespace std;

typedef long long ll;

#define INF 10e10
#define rep(i,n) for(int i=0; i<n; i++)
#define rep_r(i,n,m) for(int i=m; i<n; i++)
#define MAX 100
#define MOD 1000000007
#define pb push_back

/* add vars here */

string s;
int c;

/* add your algorithm here */

int main() {
  cin >> c;
  cin >> s;
  int lb, rb;
  lb = rb = 0;
  int mmax = 0;

  rep(i,s.size()) {
    if (s[i] == ')') {
      mmax--;
    } else {
      mmax++;
    }

    if (mmax < 0) {
      lb++;
      mmax = 0;
    }
  }

  if (mmax > 0) {
    rb = mmax;
  }

  string l,r;
  rep(i,lb) {
    l += '(';
  }

  rep(i,rb) {
    r += ')';
  }

  string ans = l + s + r;

  cout << ans << endl;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int n,a[200001],b[6]={1,10,100,1000,10000,100000};
int main()
{
	int i,j,x,wei,fir,las;
	cin>>n;
	a[1]=1;
	for(i=2;i<=n;i++)
	{
		x=i;wei=0;a[i]=a[i-1];
		las=x%10;
		if(las==0)
			continue;
		while(x!=0)
		{
			wei++;
			if(x<10)
				fir=x;
			x=x/10;
		}
		if(fir==las)
		{
			if(wei==1)
				a[i]++;
			else
			{
				x=0;
				for(j=0;j<=wei-3;j++)
					x+=b[j];
				a[i]+=x*2+3+((i/10)%b[wei-2])*2;
			}
		}
		else if(fir<las)
		{
			if(wei==1)
				continue;
			else if(wei==2)
				continue;
			else
			{
				x=0;
				for(j=0;j<=wei-3;j++)
					x+=b[j];
				a[i]+=x*2;
			}
		}
		else if(fir>las)
		{
			if(wei==1)
				continue;
			else if(wei==2)
				a[i]+=2;
			else
			{
				x=0;
				for(j=0;j<=wei-2;j++)
					x+=b[j];
				a[i]+=x*2;
			}
		}
	}
	cout<<a[n]<<endl;
	return 0;
}

Measured memory_bytes: 1024
N = int(input())
rate = list(map(int,input().split()))
lst = [i*400 for i in range(9)]
lstc = [0]*9

for i in rate:
    for j in range(len(lst)-1):
        #print((400*j),400*(j+1))
        if (400*j) <= i < 400*(j+1):
            lstc[j] += 1
            break
        
    if i >= 3200:
        lstc[-1] += 1
            
#print(lstc)
n = 0
for i in lstc:
    if i > 0:
        n += 1
nx = n-1

if lstc[-1] == 0:
    print(n,n)
elif nx == 0:
    print(1,lstc[-1])
else:
    print(nx,nx+lstc[-1])
            
    
    

Measured memory_bytes: 9192
using System;

namespace ITP1_3_D
{
    class Program
    {
        static void Main()
        {
            //a~bを数え上げる→cで一つ一つ割る→割れた数をカウントして出力
            
            string[] x = Console.ReadLine().Split(' ');
            
            var a = int.Parse(x[0]);
            var b = int.Parse(x[1]);
            var c = int.Parse(x[2]);
            
            var count = 0;
            
            for (int i = a; i <= b; i++)
                if (c % i == 0) count++;
            Console.WriteLine(count);
        }
    }
}


Measured memory_bytes: 17920
n = int(input())

s = [input() for i in range(n)]

order = "MARCH"

initial_array = [name[0] for name in s]
nums = [initial_array.count(order[i]) for i in range(len(order))]

ans = 0
for i in range(0, 5):
    for j in range(i+1, 5):
        for k in range(j+1, 5):
            ans += nums[i] * nums[j] * nums[k]
            
print(ans)



Measured memory_bytes: 10520
import java.util.*;

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

        for(int i=1;i<50;i++){
            int m = sc.nextInt();
            int f = sc.nextInt();
            int r = sc.nextInt();

            if(m == -1 || f == -1){
                if(m == -1 && f == -1 && r == -1){
                    break;
                }else{
                    System.out.println("F");
                }
            }else{
                if(m+f < 30){
                    System.out.println("F");
                }else if(m+f < 50){
                    if(r < 50){
                        System.out.println("D");
                    }else{
                        System.out.println("C");
                    }
                }else if(m+f < 65){
                    System.out.println("C");
                }else if(m+f < 80){
                    System.out.println("B");
                }else{
                    System.out.println("A");
                }
            }
        }
    }
}


Measured memory_bytes: 26276
#include<bits/stdc++.h>
#define forn(i,n) for(int i = 0; i < n; i++)
#define fi first
#define se second
#define lli long long int
using namespace std;
lli n, a, b;
int main(){
	cin >> n >> a >> b;
	lli num = n / (a+b);
	lli fal = n % (a+b);
	num *= a;
	if(fal >= a) num += a;
	else num += fal;
	cout << num << '\n';
	return 0;
}


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

#define pb push_back
#define mp make_pair
#define sz(x) (int)(x).size()
#define li long long
#define ld long double
#define x first
#define y second
#define pt pair<int, int>
#define pll pair<ll, ll>
#define forn(i, t) for(int i = 0; i < (t); i++)
#define fore(i, f, t) for(int i = (f); i < (t); i++)
#define forr(i, f, t) for(int i = (f) - 1; i >= (t); i--)
#define all(x) (x).begin(), (x).end()
#define ins insert

using namespace std;


const int INF = 1e9;
const int MOD = 1e9 + 7;
const li INF64 = 1e18;
const ld EPS = 1e-7;

mt19937 myrand(time(NULL));

li a, b;


bool read(){
	if(scanf("%lld%lld", &a, &b) != 2)
		return 0;
	return 1;
}


li f(li k){
	return INF64 - (a + k) - (b - k / 2) / 2;
}


void solve(){
	li l = 0, r = b / 2;
	while (l < r - 1){
		li m = (l + r) / 2;
		if ((a + m) > (b - m * 2) / 2)
			r = m;
		else
			l = m;
	}
	printf("%lld\n", min(l + a, (b - l * 2) / 2));
}


int main(){
	#ifdef _DEBUG
		freopen("input.txt", "r", stdin);
	#endif
	while(read())
		solve();
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

using namespace std;
using ll = long long;
using vpii = vector<pair<int, int>>;
using vpll = vector<pair<ll, ll>>;
// ceil() 切り上げ, floor() 切り捨て
// next_permutation(all(x))

int		main(void)
{
	string S;
	cin >> S;

	int size = (S.size() - 2) / 2;
	while (S.substr(0, size) != S.substr(size, size))
		size--;
	cout << size*2 << endl;
}



Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <numeric>

using namespace std;

int main(int argc, char const *argv[])
{
    int N;
    cin >> N;
    int tmp;
    vector<int> B;
    for (int i = 0; i < N - 1; i++)
    {
        cin >> tmp;
        B.emplace_back(tmp);
    }

    vector<int> A;
    A.emplace_back(B[0]);
    for (int i = 1; i < N; i++)
    {
        if (A[i - 1] > B[i - 1]) A[i - 1] = B[i - 1];
        A.emplace_back(B[i - 1]);
    }
    
    int sum = accumulate(A.begin(), A.end(), 0);
    cout << sum << endl;
    
    return 0;
}

Measured memory_bytes: 256
#pragma region include
#include <iostream>
#include <iomanip>
#include <stdio.h>

#include <sstream>
#include <algorithm>
#include <iterator>
#include <cmath>
#include <complex>

#include <string>
#include <cstring>
#include <vector>
#include <tuple>
#include <bitset>

#include <queue>
#include <complex>
#include <set>
#include <map>
#include <stack>
#include <list>

#include <fstream>
#include <random>
//#include <time.h>
#include <ctime>
#pragma endregion //#include
/////////
#define REP(i, x, n) for(int i = x; i < n; ++i)
#define rep(i,n) REP(i,0,n)
#define ALL(X) X.begin(), X.end()
/////////
#pragma region typedef
typedef long long LL;
typedef long double LD;
typedef unsigned long long ULL;
typedef std::pair<LL,LL> PLL;//
typedef std::pair<int,int> PII;//
#pragma endregion //typedef
////定数
const int INF = (int)1e9;
const LL MOD = (LL)1e9+7;
const LL LINF = (LL)1e18+20;
const LD PI = acos(-1.0);
const double EPS = 1e-9;
/////////
using namespace::std;

void solve(){
	int N;
	cin >> N;
	vector<int> A(32,0),B(32,0);

	for(int i=0;i<N;++i){
		LL a;
		cin >> a;
		bool flag = false;
		int pos = 0;
		while(a){
			if( a & 1 ){
				if( flag == false ){
					B[pos]++;
					flag = true;
				}else{
					A[pos] ^= 1;
				}
			}
			a >>= 1;
			++pos;
		}
	}
	int ans = 0;
	for(int i=31;i>=0;--i){
		if( A[i] == 0 ){
			if( B[i]&1 ){//奇数
				++ans;
				for(int j=i-1;j>=0;--j){
					A[j] ^= 1;
				}
			}
		}else{//(A[i] == 1)
			if( B[i] == 0 ){
				cout << "-1" << endl;
				return;
			}
			B[i] -= A[i];//:=-1
			if( B[i] & 1 ){//奇数個残るなら
				++ans;
				for(int j=i-1;j>=0;--j){
					A[j] ^= 1;
				}
			}
		}
	}
	cout << ans << endl;
}

#pragma region main
signed main(void){
	std::cin.tie(0);
	std::ios::sync_with_stdio(false);
	std::cout << std::fixed;//小数を10進数表示
	cout << setprecision(16);//小数点以下の桁数を指定//coutとcerrで別	

	solve();
}
#pragma endregion //main()

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

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int r, d, x;cin>>r>>d>>x;
	for(int i = 1; i <=10; ++i){
		x = r*x - d;
		cout<<x<<endl;
	}
	return 0;
}



Measured memory_bytes: 256
N=int(input())
work=[None]*N
for i in range(N):
    work[i]= list(map(int, input().split()))
work=sorted(work,key=lambda work:work[1])
time=0
flag=0
for i,j in work:
    time += i
    if time > j:
        print("No")
        flag=1
        break
if flag==0:
    print("Yes")

Measured memory_bytes: 55252
#include<stdio.h>
#include<string>
#include<stdlib.h>
#include<math.h>
#include<iostream>
#include<vector>
#include<algorithm>
#include<numeric>
#include<string.h>
#include<map>
#include<queue>

using namespace std;

typedef pair<int,int> pii;

#define rep(i,j) for(int i=0;i<(j);i++)
#define reps(i,j,k) for(int i=j;i<=k;i++)
#define in(i,j,k) ((i)>=(j)&&(i)<=(k))


int main(){
	int d[17];
	int n[100]={0};
	int cnt=0,t=0;
	queue<int> q;
	rep(i,17)d[i]=0;
	for(;cnt<100;t++){
		if(t%5==0 && t<500)q.push(t/5);
		while(!q.empty()){
			int v=q.front();
			int num=v%5==1?5:2;
			int g=0;
			rep(j,18-num){
				if(d[j]<1 && !g){
					g=1;
					reps(k,1,num-1){
						if(d[j+k]>0)g=0;
					}
					if(g){
						rep(k,num)d[j+k]=17*(v%2)+3*(v%3)+19;
					}
				}
			}
			if(!g)break;
			q.pop();
			n[v]=t-v*5;
			cnt++;
		}
		rep(i,17)if(d[i]>0)d[i]--;
	}
	while(~scanf("%d",&t))printf("%d\n",n[t]);
	return 0;
}

Measured memory_bytes: 1192
#include <bits/stdc++.h>
#define watch(x) cout << (#x) << " is " << (x) << endl
#define max3(a, b, c) max(a, max(b, c))
#define min3(a, b, c) min(a, min(b, c))
#define gcd(x,y) __gcd(x,y)
#define PI 3.14159265
#define endl "\n"
#define count_ones __builtin_popcountl
#define piii pair<int,pair<int,int>>
const int N=1e5+20,MOD=(int)(1e9)+7;
const int oo = 0x3f3f3f3f;
typedef long long ll;
using namespace std;
ll modPower(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;
}
void boost(){
	ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
}
ll GCD(ll a, ll b){
	if(a==0)return b;
	return GCD(b%a,a);
}
/* -------------------------------------- */

/* -------------------------------------- */
int main() {
	boost();
	ll n;cin>>n;vector<ll> a(n);
	for(ll i=0;i<n;i++) {
		cin>>a[i];
//		if(first < a[i]){
//			second = first;
//			first = a[i];
//		}
//		else if(a[i]>second && a[i]!=first){
//			second = a[i];
//		}
	}
	 vector<ll> b = a;
	 sort(b.begin(), b.end());
	for(ll i=0;i<n;i++){
		if(a[i]!=b[n-1])cout<<b[n-1]<<endl;
		else cout<<b[n-2]<<endl;
	}
//	watch(first);watch(second);
	
//	sort(a,a+n);
//	ll maxm= a[n-1];
//	ll secondmaxm = a[n-2];
//	for(int i=0;i<)
}

Measured memory_bytes: 4736
// ABC042
// A - 和風いろはちゃんイージー
#include<bits/stdc++.h>

using namespace std;

int main(){
    int a,b,c;
    cin >> a >> b >> c;
    if((a==7 && b==5 && c==5) || (a==5 && b==7 && c==5) || (a==5 && b==5 && c==7)) cout << "YES" << endl;
    else cout << "NO" << endl;
    return 0;
}


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


long long int  func(long long int n, long long int r) 
{ 

 
  long long int p = 1, k = 1; 

  
  if (n - r < r) 
    r = n - r; 

  if (r != 0) { 
    while (r) { 
      p = 1LL*p*n; 
      k = 1LL*k*r; 

      // gcd of p, k 
      long long int m = __gcd(p, k); 

      // dividing by gcd, to simplify product 
      // division by their gcd saves from the overflow 
      p /= m; 
      k /= m; 

      n--; 
      r--; 
    } 
  } 

  else
    p = 1; 

   return p;
} 


int main()
{


     ios_base::sync_with_stdio(false);
     cin.tie(NULL);
   

    long long int ans;
    long double ans1;
    cin>>ans>>ans1;
    long long int ans2=round(ans1*100);
    cout<<(ans*ans2)/100<<endl;

    //cout<<ans2<<endl;
    return 0;
}


Measured memory_bytes: 3808
import java.io.*
import java.util.*
import java.lang.*
import java.lang.Math.*


fun minCost(D: Array<IntPair>, N: Int): Int {
    val M = D.size

    val dp = IntArray(0b01 shl N){INF}
    dp[0] = 0  // dp[s] := 開放状態 s を作るための最小コスト

    for (i in 1 .. M) {
        val ds = D[i-1].first
        val cost = D[i-1].second
        for (s in 0 until (0b01 shl N)) {
            dp[s or ds] = min(dp[s or ds], dp[s] + cost)
        }
    }

    val ans = dp[(0b01 shl N) - 1]
    return if (ans >= INF) -1 else ans
}

fun solve() {
    val (N, M) = rd.readIntArray()
    val A = IntArray(M); val B = IntArray(M)
    val C = Array(M){ArrayList<Int>()}
    for (i in 0 until M) {
        val (a, b) = rd.readIntArray()
        A[i] = a; B[i] = b
        C[i].addAll(rd.readIntArray().toList())
    }

    val D = Array(M){IntPair(0, INF)}
    for (i in 0 until M) {
        var s = 0
        for (c in C[i]) {
            s = s or (0b01 shl (c-1))
        }
        D[i] = IntPair(s, A[i])
    }

    val ans = minCost(D, N)

    print(ans)
}


//val rd = debug.Reader("abc", "142", "e", "sample-1")
val rd = Reader()


fun main(args: Array<String>) {
    try {
        var exception: Throwable? = null
        val sth = Thread(null, SolveThread(), "solveThread", 128 * 1024 * 1024)
        sth.setUncaughtExceptionHandler { _, e -> exception = e }
        sth.start(); sth.join()
        if (exception != null) throw exception!!
    } catch (e: Exception) { throw e }
}
const val MOD = 1_000_000_007L; const val INF = Int.MAX_VALUE/2; const val LINF = Long.MAX_VALUE/2
const val EPS = 1e-9; fun DBLEQ(a: Double, b: Double): Boolean {return abs(a - b) < EPS}
data class IntPair(val first: Int, val second: Int)
data class To(val idx: Int, val cost: Long)
fun <T>edge(V: Int): Array<ArrayList<T>> { return Array(V){ArrayList<T>()} }
val errPrintln: (Any) -> Unit = { msg -> System.err.println(msg) }
fun rAssert(exp: Boolean, lazyMsg: () -> String = {""}) {
    if (!exp) { val msg = lazyMsg(); errPrintln("EAssert Error: $msg"); throw Error(msg) }
}
fun tAssert(exp: Boolean, lazyMsg: () -> String = {""}) {
    if (!exp) { val msg = lazyMsg(); errPrintln("TAssert Error: $msg"); Thread.sleep(3000) }
}
class SolveThread : Runnable {
    override fun run() { solve() }
}
class Reader {
    private val br = BufferedReader(InputStreamReader(System.`in`))
    val readString: () -> String = { br.readLine() }
    val readInt: () -> Int = { br.readLine().toInt() }
    val readLong: () -> Long = { br.readLine().toLong() }
    val readIntArray: () -> IntArray = { br.readLine().split(' ').map { it.toInt() }.toIntArray() }
    val readLongArray: () -> LongArray = { br.readLine().split(' ').map { it.toLong() }.toLongArray() }
    val readListInt: () -> List<Int> = { br.readLine().split(' ').map { it.toInt() } }
    val readListLong: () -> List<Long> = { br.readLine().split(' ').map { it.toLong() } }
}


Measured memory_bytes: 42452
import java.util.Scanner;

public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int x = sc.nextInt();
        int y = sc.nextInt();
        System.out.println(gcd(x, y));
    }

    public static int gcd(int x, int y){
        if(x < y){
            return gcd(y, x);
        }
        if(y == 0){
            return x;
        }
        return gcd(y, x % y);
    }
}


Measured memory_bytes: 26276
#include <iostream>
#include <cstdio>
#include <cmath>
#include <complex>

using namespace std;
typedef complex<double> P;

double cross(P a,P b){return (conj(a)*b).imag();}

int main(){
  int n;
  scanf("%d",&n);
  while(n--){
    P a,b,c;
    cin >> a.real() >> a.imag() >> b.real() >> b.imag() >> c.real() >> c.imag();
    P m = (a+b)/P(2,0);
    P n = (a+c)/P(2,0);
    P s = (a-b)*P(0,1);
    P t = (a-c)*P(0,1);
    //    cout << " m: "<< m << " n: " << n << " s: " << s << " t: " <<  t << endl;
    double e = cross(n-m,t)/cross(s,t);
    //    cout << " e: " << e << endl;
    P o = m+s*P(e,0);
    double r = abs(a-o);
    printf("%.3f %.3f %.3f\n",o.real(),o.imag(),r);
  }
}

Measured memory_bytes: 0
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<queue>
#include<stack>
#include<cassert>
#include<numeric>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
using namespace std;
const int INF = 1001001001;
const long long LINF = 1001002003004005006ll;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
typedef long long ll;
typedef pair<int,int> P;

int main(){
    int h,w,k;
    cin >> h >> w >> k;
    vector<string> c(h);
    rep(i,h)cin >> c[i];
    int ans = 0;
    rep(bh,1<<h){
        rep(bw,1<<w){
            int res = 0;
            rep(i,h)rep(j,w){
                if(((bh>>i)&1)&&((bw>>j)&1)){
                    if(c[i][j]=='#')res++;
                }
            }
            if(res==k)ans++;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 3192
/*#include <iostream>
#include <cmath>
#include <vector>
#include <algorithm>
#include <array>
#include <vector>
#include <deque>
#include <set>
#include <map>
#include <string>
#include <stack>
#include <queue>
#include <unordered_map>
#include <unordered_set>
*/

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

#define int long long
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define FOR(i,a,b) for(int (i)=(a);(i)<(b);(i)++)
#define REP(i,n) FOR(i,0,n)
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define SORT(c) sort((c).begin(),(c).end())

typedef long long ll;
const ll inf = 2e9 + 7;
const int MAX_N = 5e5 + 5;
int dx[] = { -1,0,1,0 }, dy[] = { 0,1,0,-1 };
vector<ll> prime;

ll inv[MAX_N], fac[MAX_N];

template <class T = int> T in() { T x; cin >> x; return (x); }
inline ll GCD(ll a, ll b) { ll c; while (b != 0) { c = a % b; a = b; b = c; }return a; }
inline ll LCM(ll a, ll b) { return a * b / GCD(a, b); }
inline ll POW(ll a, ll b) { ll c = 1; while (b > 0) { if (b & 1) { c = a * c%inf; }a = a * a%inf; b >>= 1; }return c; }
inline void _nCr() { fac[0] = 1; for (int i = 1; i < MAX_N; i++) { fac[i] = fac[i - 1] * i%inf; }for (int i = 0; i < MAX_N; i++) { inv[i] = POW(fac[i], inf - 2); } }
inline ll nCr(ll n, ll r) { return (fac[n] * inv[r] % inf)*inv[n - r] % inf; }
inline void PRI(ll n) { bool a[n + 1]; for (int i = 0; i < n + 1; i++) { a[i] = 1; }for (int i = 2; i < n + 1; i++) { if (a[i]) { prime.pb(i); ll b = i; while (b <= n) { a[b] = 0; b += i; } } } }

typedef pair<int, pair<int, int>> edge;

class UnionFind {
private:
	vector<int> par;
public:
	UnionFind(int N) { par = vector<int>(N, -1); }
	int find(int x);
	ll size(int x);
	void unite(int x, int y);
	bool same(int x, int y);
};



class Kruskal {
private:
	UnionFind *uf;
	vector<edge> e;
public:
	vector<edge> mst;
	Kruskal(int N) { uf = new UnionFind(N); }
	void add(int x, int y, ll z);
	void run();
};



//----UnionFind-------------------------------
int UnionFind::find(int x) {
	if (par[x] < 0) return x;
	else return par[x] = find(par[x]);
}

ll UnionFind::size(int x) {
	return -par[find(x)];
}

void UnionFind::unite(int x, int y) {
	x = find(x);
	y = find(y);

	//大きい方に小さい方をくっ付ける
	if (size(x) < size(y)) swap(x, y);
	par[x] += par[y];
	par[y] = x;
}

bool UnionFind::same(int x, int y) {
	x = find(x);
	y = find(y);
	return x == y;
}



//----Kruskal-------------------------------
void Kruskal::add(int x, int y, ll z) {
	//x < y
	if (x > y) swap(x, y);
	e.push_back({ z,{x,y} });
}

void Kruskal::run() {
	sort(e.begin(), e.end());
	e.erase(unique(e.begin(), e.end()), e.end());
	for (auto x : e) {
		if (uf->same(x.second.first, x.second.second)) {
			continue;
		}
		else {
			mst.push_back(x);
			uf->unite(x.second.first, x.second.second);
		}
	}
}

signed main() {
	int n;cin >> n;
	int con[n+1];
	REP (i,n+1) {con[i] = 0;}
	int ma = 1;
	REP (i,n) {
		int a;
		cin >> a;
		con[a] = con[a - 1] + 1;
		ma = max(con[a],ma);
	}
	cout << n - ma << endl;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
        using namespace std;
        #define mod 1000000000000000000
        #define MOD 		1000000007
        #define ll long long
        #define ull unsigned ll
        #define mp 		make_pair
        #define pb 		push_back
        #define forn(i,n) 	for(ll i=0;i<n;i++)
        #define for1(i,n) 	for(ll i=1;i<=n;i++)
        #define forn1(i,n) 	for(int i=1;i<n;i++)
        #define rep(i,x,n)  for(ll i=x;i<=n;i++)
        #define repr(i,x,j) for(ll i=x;i>=j;i--)
        #define vi vector<ll>
        #define mii map<ll,ll>
        #define vii vector<pair<ll,ll>>
        #define vvi vector<vector<ll>>
        #define pii pair<ll,ll>
        #define F first
        #define S second
        #define fill(a,x) memset(a,x,sizeof a);
        #define all(x) x.begin(),x.end()
        #define test ll t;cin>>t;while(t--)
        #define yes cout<<"YES"<<endl
        #define no cout<<"NO"<<endl
        #define IOS ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
        ll flag[1000];
        #define R return 0
        int main()
        {
            IOS;
            ll x;
            cin>>x;
            cout<<!x<<endl;
            R;
        }
        
        /// Happy coding ):

Measured memory_bytes: 3608
//koch curve
//問題はhttp://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_5_C&lang=jp
//席、右・中央
//再帰関数の書き方を学んだ

#include <iostream>
#include <cstdio>
#include <cmath>
using namespace std;
//use struct
struct Point {double x,y;};

void koch (Point s, Point t, int n){
  //basecase
  if (n == 0){
  }
  //stepcase
  else{
    Point a, b, c;
    a.x = s.x + (t.x - s.x)/3;
    a.y = s.y + (t.y - s.y)/3;
    b.x = (s.x + t.x)/2 - (sqrt(3) * (t.y - s.y))/6;
    b.y = (s.y + t.y)/2 + (sqrt(3) * (t.x - s.x))/6;
    c.x = s.x + (2 * (t.x - s.x))/3;
    c.y = s.y + (2 * (t.y - s.y))/3;

    koch (s,a,n-1);
    printf("%8f %8f\n",a.x,a.y);
    koch (a,b,n-1);
    printf("%8f %8f\n",b.x,b.y);
    koch (b,c,n-1);
    printf("%8f %8f\n",c.x,c.y);
    koch (c,t,n-1);
  }
}

int main(int argc, char const *argv[]) {
  int num;
  cin >> num;
  Point d,e;
  d.x = 0;
  d.y = 0;
  e.x = 100;
  e.y = 0;
  //最初の一の表示
  printf("%8f %8f\n",d.x,d.y);
  koch (d,e,num);
  //最後の一の表示
  printf("%8f %8f\n",e.x,e.y);


  return 0;
}



Measured memory_bytes: 3220
import heapq

def main():
    n,m = map(int,input().split())
    pq = [[] for _ in range(n)]
    for i in range(n):heapq.heapify(pq[i])
    for _ in range(m):
        q = input().split()
        if   q[0] == '0'  :heapq.heappush(pq[int(q[1])],-int(q[2]))
        elif pq[int(q[1])]:
            if q[0] == '1'  :print (-pq[(int(q[1]))][0])
            else            :heapq.heappop(pq[int(q[1])])


if __name__ == '__main__':
    main()




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

#define int long long
typedef vector<int> vint;
typedef pair<int, int> pint;
int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};

/*
ifstream ifs("in.txt");
ofstream ofs("out.txt");
#define cin ifs
#define cout ofs
//*/

int N;
int A[220000];
signed main() {
    cin >> N;
    for (int i = 0; i < N; i++) {
        cin >> A[i];
    }
    int cur = 0;
    int ans = 0, l = 0;
    for (int r = 0; r < N; r++) {
        while (cur + A[r] != (cur ^ A[r])) {
            cur ^= A[l];
            l++;
        }
        cur ^= A[r];
        ans += r - l + 1;
    }
    cout << ans << endl;
}

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

using namespace std;
using ll = long long;
using ull = unsigned long long;
using P = pair<int,int>;
using Pl = pair<ll,ll>;
#define REP(i,n) for(ll i = 0;i < (ll)n;i++)
#define REPD(i,n) for(ll i = (ll)n - 1;i >= 0;i--)
#define ALL(x) (x).begin(),(x).end()
#define FILLl(n,first_dimension_size,value) fill((ll*)n,(ll*)(n+first_dimension_size),value)
#define FILL(n,first_dimension_size,value) fill((int*)n,(int*)(n+first_dimension_size),value)
#define INF (1 << 30)
#define MOD 1000000007
//int dy[4] = {-1,0,0,1};
//int dx[4] = {0,1,-1,0};


int main(){

  int n;
  cin >> n;
  ll k = 1;
  bool flag = true;
  while(flag){
    k *= 10;
    for(int i = 1;i < 10;i++){
      int a = (k-1)/9*i;
      if(a >= n){
        cout << a << endl;
        flag = false;
        break;
      }
    }
  }

  

  return 0;
}


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


#define ms(a,b) memset(a,b,sizeof(a))
#define inf 1<<30
#define mp make_pair
#define pi acos(-1)
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pli pair<ll,int>
#define pil pair<int,ll>
#define fs first
#define sc second
#define cffi ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define make_flush  cout << flush; //    fflush(stdout);
#define pob pop_back
#define vec_ vector
#define clr(a) a.clear()
#define pb push_back
#define eps 1E-7
#define all(a) a.begin(),a.end()
#define allr(a) a.rbegin(),a.rend()
#define sz(a) (int)a.size()
#define ll long long
#define ull unsigned long long
#define dd double
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define repa(i,n) for(auto i: n)
#define fop freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
using namespace std;

template<class T1> void deb(T1 e)
{
    cout<<e<<endl;
}
template<class T1,class T2> void deb(T1 e1,T2 e2)
{
    cout<<e1<<" "<<e2<<endl;
}
template<class T1,class T2,class T3> void deb(T1 e1,T2 e2,T3 e3)
{
    cout<<e1<<" "<<e2<<" "<<e3<<endl;
}
template<class T1,class T2,class T3,class T4> void deb(T1 e1,T2 e2,T3 e3,T4 e4)
{
    cout<<e1<<" "<<e2<<" "<<e3<<" "<<e4<<endl;
}
template<class T1,class T2,class T3,class T4,class T5> void deb(T1 e1,T2 e2,T3 e3,T4 e4,T5 e5)
{
    cout<<e1<<" "<<e2<<" "<<e3<<" "<<e4<<" "<<e5<<endl;
}
template<class T1,class T2,class T3,class T4,class T5,class T6> void deb(T1 e1,T2 e2,T3 e3,T4 e4,T5 e5,T6 e6)
{
    cout<<e1<<" "<<e2<<" "<<e3<<" "<<e4<<" "<<e5<<" "<<e6<<endl;
}


//double dur(int x1,int y1,int x2,int y2)
//{
//    return sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));
//}
//template<class T> string toString(T n){ostringstream oss;oss<<n;oss.flush();return oss.str();}
//int toInt(string s){int r=0;istringstream sin(s);sin>>r;return r;}
//template <class T> T lcm(T a, T b){return (a/__gcd(a,b)) * b;}
//ll bigmod(ll B,ll P,ll M){ll R=1;while(P>0){if(P%2==1){R=(R*B)%M;}P/=2;B=(B*B)%M;}return R;}
//int X[]={0,-1,-1,-1,0,1,1,1};
//int Y[]={-1,-1,0,1,1,1,0,-1};
//int X[]={-1,0,1,0};
//int Y[]={0,1,0,-1};


#define mt
#define mod

ll solve(ll num)
{
    ll l=1,h=1000000,mid;
    ll ret=1;
    while(l<=h)
    {
        mid=l+h >> 1ll;
        if(mid*(mid+1)/2 <=num)
        {
            ret=max(ret,mid);
            l=mid+1;
        }
        else
            h=mid-1;
    }
    return ret;
}

void go1(ll a,ll b)
{
    rep(i,a)
    cout<<")";
    rep(i,a)
    cout<<"(";

    cout<<endl;
}

void go2(ll a,ll b)
{
//    deb(a,b);
    string res="";
    res=")(";
    rep(i,a)
    res+=")";
    rep(i,a)
    res+="(";
    ll d=b-(a*(a+1)/2)-1;
    int pos=1;
    while(d>0)
    {
        d--;
        swap(res[pos],res[pos+1]);
        pos++;
    }
    deb(res);
}

int main ()
{
    cffi;
    ll i,j,test,n,t=1,maan;
    cin>>maan;
    n=solve(maan);
    if(n*(n+1)/2 ==maan)
    go1(n,maan);
    else
        go2(n,maan);
    return 0;
}

Measured memory_bytes: 3360
import heapq
def solve(V,E,r,adjlist):
    cost=[float('inf')]*V
    used=[False]*V
    cost[r]=0
    used[r]=True
    h=[]
    for v in adjlist[r]:
        heapq.heappush(h,v)
    while(len(h)>0):
        u=heapq.heappop(h)
        if used[u[1]]:
            continue
        used[u[1]]=True
        cost[u[1]]=u[0]
        for d,t in adjlist[u[1]]:
            if cost[t]>u[0]+d:
                cost[t]=u[0]+d
                heapq.heappush(h,tuple((cost[t],t)))
    return cost





V,E,r=map(int,input().split())
adjlist=[[] for _ in range(V)]
for _ in range(E):
    s,t,d=map(int,input().split())
    adjlist[s].append(tuple((d,t)))
ans=solve(V,E,r,adjlist)
for i in range(V):
    if ans[i]==float('inf'):
        print("INF")
    else:
        print(ans[i])


Measured memory_bytes: 90052
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
int main(){
    int h,w,a,b;
    cin >> h >> w >> a >> b;
    for(int x = 0; x<h; x++){
        for(int y = 0; y< w; y++){
            if(x < b && y < a){
                cout << 1;
            }else if(x < b || y < a){
                cout << 0;
            }else{
                cout << 1;
            }
        }
        cout << endl;
    }
}

Measured memory_bytes: 1280
#include<stdio.h>

int main()
{
	int x1, x2, y1, y2;
	scanf("%d%d%d%d", &x1, &y1, &x2, &y2);
	printf("%d %d %d %d\n", x2 - (y2 - y1), y2 + (x2 - x1),
		x1 - (y2 - y1), y1 + (x2 - x1));

	return 0;
}

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

ll gcd(ll x,ll y) {return y ? gcd(y,x%y) : x;} 
ll lcm(ll x,ll y) {return x/gcd(x,y)*y;}

int main(){
    int n,total=0,total2=0,ans=100100100;
    cin >> n;
    vector<int> w(n);
    rep(i,n){
        cin >> w[i];
        total+=w[i];
    }
    rep(i,n){
        total2+=w[i];
        ans=min(ans,abs((total-total2)-total2));
    }
    cout << ans << endl;
    return 0;
}











Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<math.h>
#include<stdio.h>
#include<string>

using namespace std;

int main(void)
{
	int a, b, c;
	cin >> a >> b >> c;
	long long int ans;
	ans = a * b / 2;
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
S=list(input())
if "k" and "e" and "y" and "e" and "n" and "c" and "e" in S:
    if S[-1]=="e" and S[-2]=="c" and S[-3]=="n" and S[-4]=="e" and S[-5]=="y" and S[-6]=="e" and S[-7]=="k":
        print("YES")
    else:
        if S[0]=="k":
            if S[1]=="e":
                if S[2]=="y":
                    if S[3]=="e":
                        if S[4]=="n":
                            if S[5]=="c":
                                if S[6]=="e":
                                    print("YES")
                                else:
                                    if S[-1]=="e":
                                        print("YES")
                                    else:
                                        print("NO")
                            else:
                                if S[-1]=="e" and S[-2]=="c":
                                    print("YES")
                                else:
                                    print("NO")
                        else:
                            if S[-1]=="e" and S[-2]=="c" and S[-3]=="n":
                                print("YES")
                            else:
                                print("NO")
                    else:
                        if S[-1]=="e" and S[-2]=="c" and S[-3]=="n" and S[-4]=="e":
                            print("YES")
                        else:
                            print("NO")
                else:
                    if S[-1]=="e" and S[-2]=="c" and S[-3]=="n" and S[-4]=="e" and S[-5]=="y":
                        print("YES")
                    else:
                        print("NO")
            else:
                if S[-1]=="e" and S[-2]=="c" and S[-3]=="n" and S[-4]=="e" and S[-5]=="y" and S[-6]=="e":
                    print("YES")
                else:
                    print("NO")
        else:
            print("NO")
else:
    print("NO")

Measured memory_bytes: 3188
#include<bits/stdc++.h>
using namespace std;
const int INF = 1e9 + 5;
int main(){
   int n;
   cin>>n;
   int arr[n]={0};
   for(int i=0;i<n;i++){
	   cin>>arr[i];
   }
    vector<int> dp(n,INF);
    dp[0]=0;
    for(int i=0;i<n;i++){
        for(int j : {i+1,i+2}){
            if(j<n){
                dp[j] = min(dp[j] , abs(arr[j]-arr[i])+dp[i]);
            }
        }
    }
    cout<<dp[n-1];
	return 0;
}

Measured memory_bytes: 1024
from collections import deque
import math

def solve3(s_flag,h,w,goal_h,goal_w,que):
    while True:
        visited=set()
        while que:
            ch,cw=que.popleft()
            visited.add((ch,cw))
            ## 現在地のコスト
            now=s_flag[ch][cw]
            for d_h,d_w in [(1,0),(0,1),(0,-1),(-1,0)]:
                ## 迷路の外に出ない
                if ch+d_h<0 or h-1<ch+d_h:
                    continue
                if cw+d_w<0 or w-1<cw+d_w:
                    continue
                ## 進行方向のコスト
                dest=s_flag[ch+d_h][cw+d_w]
                if dest!='#': ## 道
                    if dest>now:
                        s_flag[ch+d_h][cw+d_w]=now
                        que.append([ch+d_h,cw+d_w])
        jumping=set()
        for ch,cw in visited:
            now=s_flag[ch][cw]
            for d_h,d_w in [(1,0),(0,1),(0,-1),(-1,0)]:
                jump=[  (d_h+d_w,d_w+d_h),
                        (d_h-d_w,d_w-d_h),
                        (d_h*2,d_w*2),
                        (d_h*2+d_w,d_w*2+d_h),
                        (d_h*2-d_w,d_w*2-d_h),
                        (d_h*2+d_w*2,d_w*2+d_h*2),
                        (d_h*2-d_w*2,d_w*2-d_h*2)]
                for jump_h,jump_w in jump:
                    if ch+jump_h<0 or h-1<ch+jump_h:
                        continue
                    if cw+jump_w<0 or w-1<cw+jump_w:
                        continue
                    jumping.add((ch+jump_h,cw+jump_w))
        if len(jumping)==0:
            break
        for d_jump_h,d_jump_w in jumping:
            ## ワープ先のコスト
            dest_jump=s_flag[d_jump_h][d_jump_w]
            if dest_jump!='#' and dest_jump>now+1:
                s_flag[d_jump_h][d_jump_w]=now+1
                que.append([d_jump_h,d_jump_w])

    # for i in range(h):
    #     print(s_flag[i])
    return s_flag[goal_h][goal_w]

def main():
    h,w=map(int,input().split())
    ch,cw=map(int,input().split())
    ch,cw=ch-1,cw-1
    dh,dw=map(int,input().split())
    dh,dw=dh-1,dw-1
    s=[input() for i in range(h)]
    ## .=0 #=2 visited=1 goal=-1
    # s_flag=[[0 if s[i][j]=='.' else 2 for j in range(w)] for i in range(h)]
    # s_flag[ch][cw]=1
    # s_flag[dh][dw]=-1
    # ans=solve(s_flag,h,w,ch,cw,0)
    # if not ans:
    #     ans=-1
    # else:
    #     ans=ans[-1][2]
    # return ans
    ## .=inf #=# visited=cost
    s_flag=[[math.inf if s[i][j]=='.' else '#' for j in range(w)] for i in range(h)]
    s_flag[ch][cw]=0
    que=deque([[ch,cw]])
    ans=solve3(s_flag,h,w,dh,dw,que)
    if ans==math.inf:
        ans=-1
    return ans

if __name__=='__main__':
    ans=main()
    print(ans)


Measured memory_bytes: 204448
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees, log2, gcd
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from heapq import heappush, heappop
from functools import reduce, lru_cache
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def TUPLE(): return tuple(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7 
#mod = 998244353
from decimal import *
#import numpy as np
#decimal.getcontext().prec = 10

X, Y, Z, K = MAP()
A = sorted(LIST(), reverse = True)
B = sorted(LIST(), reverse = True)
C = sorted(LIST(), reverse = True)

AB = []
for i in range(X):
	for j in range(Y):
		AB.append(A[i]+B[j])

AB.sort(reverse = True)
AB = AB[:3000]
ABC = sorted([C[0]+AB[i] for i in range(min(3000, X*Y))], reverse = True)

for j in range(1, Z):
	ABC_tmp = sorted([C[j]+AB[i] for i in range(min(3000, X*Y))])
	ABC += ABC_tmp
	ABC.sort(reverse = True)
	ABC = ABC[:3000]

print(*ABC[:K], sep= "\n")



Measured memory_bytes: 163688
num = int(input() )
sum = 0
min = 1000000
max = -1000000
li = list(map(int, input().split() ))
for i in range(num):
  tmp = li[i]
  sum += tmp
  if tmp > max:
    max = tmp
  if tmp < min:
    min = tmp
print(min, max, sum)



Measured memory_bytes: 6588
#include <bits/stdc++.h> 
 
using namespace std;
 
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

 
//typedef
//------------------------------------------
typedef pair<int, int> PII;
typedef pair<long, long> PLL;
typedef long long LL;

//container util
//------------------------------------------
#define PB emplace_back
#define MP make_pair 
#define SZ(a) int((a).size())
//repetition
//------------------------------------------
#define FOR(i,a,b) for(LL i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define SORT(c) sort((c).begin(),(c).end())
//constant
//--------------------------------------------
//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))
 
const LL INF=LONG_MAX;
const double EPS=0.00001;
const long double PI = acos(-1.0);

const int MAX_N=2e5+2;

int main(){
    int N,K;
    cin>>N>>K;
    vector<int>bs;
    int nK=K;
    while(nK!=0){
        bs.PB(nK%2);
        nK/=2LL;
    }
    reverse(bs.begin(),bs.end());
    vector<int>vec;
    vec.PB(K);
    REP(i,SZ(bs)){
        if(bs[i]!=1)continue;
        int r=i;
        //cout<<"!"<<r<<endl;
        LL tmp=0;
        REP(j,r){
            tmp=tmp*2+bs[j];
        }
        tmp*=2;
        FOR(j,r+1,SZ(bs)){
            tmp=tmp*2+1;
        }
        vec.PB(tmp);
        //cout<<tmp<<endl;
    }
    vector<PII>pi;
    REP(i,N){
        int A,B;
        cin>>A>>B;
        pi.PB(MP(A,B));
    }
    LL maxi=0;
    REP(t,SZ(vec)){
        LL sum=0;
        REP(i,N){
            int A=pi[i].first;
            int B=pi[i].second;
            bool f=0;
            //cout<<"!"<<(int)(vec[t]|A)<<" "<<vec[t]<<endl;
            if((int)(A|vec[t])<=vec[t]){
                f=1;
            }
            if(f)sum+=B;
        }
        maxi=max(maxi,sum);
    }
    cout<<maxi<<endl;
    return 0;
}


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

map<int,vector<int>> P;
set<string> RT;
vector<bool> ans;

void prog(int a,string r,vector<bool>T){
    T.at(a-1)=true;
    if(T==ans){
        RT.insert(r);
        return;
    }
    for(int i:P.at(a)){
        if(T.at(i-1))continue;
          r.push_back(i+'0');
        prog(i,r,T);
        r.pop_back();
    }
}

int main (){
    int N,M;
    cin >> N >> M;
    for(int i=0;i<M;i++){
        int j,k;
        cin >> j >> k;
        P[j].push_back(k);
        P[k].push_back(j);
    }
    
    
    ans=vector<bool>(N,true);
    
    prog(1,"1",vector<bool>(N,false));
    
    
    cout << RT.size() << endl;
    
}


Measured memory_bytes: 3904
#include<bits/stdc++.h>
using namespace std;
#define IO {ios_base::sync_with_stdio(false); cin.tie(0);}
#define ll  long long
#define pi pair<ll,ll>
ll vs[2000], a[2000], b[2000], c[30000];

string s;
int main()
{
    IO;
    ll i, j, k, cnt=0, n, m, mod=1e9, t, mx=0, mn=INT_MAX, l, h, r=0, w=0, ovr=0;
    // cin>>t;
        //while(t--){
            cin>>s;
            if(s[0]==s[1]&&s[1]==s[2]&&s[0]=='R') cout<<3<<endl;
            else if(s[0]==s[1] && s[0]=='R') cout<<2<<endl;
            else if(s[2]==s[1] && s[2]=='R') cout<<2<<endl;
            else if(s[0]=='R' || s[1]=='R' || s[2]=='R') cout<<1<<endl;
            else cout<<0<<endl;
        //}
    return 0;
}


Measured memory_bytes: 3660
import java.util.Scanner;

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

    private void run() {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        String s = scanner.next();
        int sum = 1;
        char prev = s.charAt(0);
        for(int i = 1; i < s.length(); i++) {
            if (prev != s.charAt(i)) {
                sum++;
                prev = s.charAt(i);
            }
        }
        System.out.println(sum);
    }
}

Measured memory_bytes: 24428
def q3():
    import math
    N, K = (int(i) for i in input().split())

    ans = 0
    for n in range(1, N+1):
        if n >= K:
            ans += 1/N  # K以上ならば、確率は1/N
            continue
            
        c = math.ceil(math.log2(K/n))  # 小数繰り上げ
        # print(n, c)
        ans += 1/N * (1/2)**c

    print('{:.9f}'.format(ans))


if __name__ == '__main__':
    q3()


Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
typedef unsigned long long ll;
#define vi vector<int>
#define vll vector<ll>
#define pll pair<ll,ll>
#define pii pair<int,int>
#define pb  push_back
#define ppb pop_back
#define mp  make_pair
#define SIZE 300005
#define M 1000000007
ll power(ll a,ll b){
	if(b==0)
		return 1;
	ll p=power(a,b/2)%M;
	p=(p*p)%M;
	if(b%2==1){
		p=((a%M)*p)%M;
	}
	return p;
}
ll arr[SIZE];
int main(){
	// #ifndef ONLINE_JUDGE
	// freopen("input.txt", "r", stdin);
	// freopen("output.txt", "w", stdout);
	// #endif
	ios_base::sync_with_stdio(false); 
	cin.tie(NULL);
	ll n;
	cin>>n;
	for(ll i=0;i<n;++i){
		cin>>arr[i];
	}
	ll ans=0;
	for(ll i=0;i<61;++i){
		ll num0=0,num1=0;
		for(ll j=0;j<n;++j){
			// cout<<arr[j]<<","<<(arr[j]>>i)<<" ";
			if((arr[j]>>i)&1){
				num1++;
			}
			else{
				num0++;
			}
		}
		// cout<<num0<<" "<<num1<<endl;
		ans=(ans+(((num0*num1)%M)*power(2,i))%M)%M;
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 2560
#!/usr/bin/env python3
import sys


def solve(W: int, H: int, x: int, y: int):
    many = 0
    if x*2 == W and y*2 == H:
        many = 1
    print(W*H/2,many)


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    W = int(next(tokens))  # type: int
    H = int(next(tokens))  # type: int
    x = int(next(tokens))  # type: int
    y = int(next(tokens))  # type: int
    solve(W, H, x, y)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3064