akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <iostream>
#include <string.h>
#include <limits.h>
#include <string>
#include <vector>
#include <algorithm>

#ifndef ULLONG
typedef unsigned long long ULLONG;
#endif
#ifndef LLONG
typedef long long LLONG;
#endif
template <class _T> static _T tp_abs(const _T& a) {
	return ((a < 0) ? (a * -1) : a);
}
template <class _T> static _T tp_min(_T a, _T b) {
	return a < b ? a : b;
}
template <class _T> static _T tp_max(_T a, _T b) {
	return a > b ? a : b;
}
template<class _T> static void get1int(_T& a) {
	const char* fmt = " %d";
	if (sizeof(_T) == sizeof(long long)) {
		fmt = " %lld";
}

	if (scanf(fmt, &a) < 0) {
		printf("g1int Error\n");
	}
}
template<class _T> static void get2int(_T& a, _T& b) {
	const char* fmt = " %d %d";
	if (sizeof(_T) == sizeof(long long)) {
		fmt = " %lld %lld";
	}

	if (scanf(fmt, &a, &b) < 0) {
		printf("g2int Error\n");
	}
}
template<class _T> static void get3int(_T& a, _T& b, _T& c) {
	const char* fmt = " %d %d %d";
	if (sizeof(_T) == sizeof(long long)) {
		fmt = " %lld %lld %lld";
	}

	if (scanf(fmt, &a, &b, &c) < 0) {
		printf("g3int Error\n");
	}
}
static void getstring(char* buff) {
	if (scanf(" %s", buff) < 0) {
		printf("getstr error!\n");
	}
}
static void get1char(char& c) {
	if (scanf(" %c", &c) < 0) {
		printf("get1char error\n");
	}
}

static const LLONG LL_HUGE_NUM = 1000000007LL;

static void D_task();

#if 1
int main()
{
	D_task();
	fflush(stdout);
	return 0;
}
#endif

class D_data {
public:
	int wdir = -1;
	int hdir = -1;
	static bool dsc_ttl(const D_data& a, const D_data& b) {
		return((a.wdir + a.hdir) > (b.wdir + b.hdir));
	}
};

static void D_task()
{
	int H, W;
	get2int(H, W);

	std::vector<std::vector<int>> bar(H);
	for (int i = 0; i < H; i++) {
		int b = 0;
		for (int j = 0; j < W; j++) {
			char g;
			get1char(g);
			if (g == '#') {
				bar[i].push_back(j);
			}
		}
		bar[i].push_back(W);
	}

	auto cnt = new D_data[H][2001];

	//	w方向
	for (int h = 0; h < H; h++) {
		int stt = 0, end = 0;
		int barCnt = bar[h].size();
		for (int i = 0; i < barCnt; i++) {
			end = bar[h][i];
			int block = end - stt;
			for (int j = stt; j < end; j++) {
				cnt[h][j].wdir = block;
			}
			stt = end + 1;
		}
	}
	//	h方向
	for (int w = 0; w < W; w++) {
		int stt = 0, end;
		int block = 0;
		for (int h = 0; h < H; h++) {
			if (cnt[h][w].wdir > 0) {
				block++;
			}

			if ((cnt[h][w].wdir < 0) || (h == H - 1)) {
				end = h;
				if ((h == H - 1) && (cnt[h][w].wdir > 0)) end++;
				for (int i = stt; i < end; i++) {
					cnt[i][w].hdir = block;
				}
				stt = h + 1;
				block = 0;
			}
		}
	}
	std::sort(&cnt[0][0], &cnt[H - 1][2000], D_data::dsc_ttl);
	printf("%d\n", cnt[0][0].wdir + cnt[0][0].hdir - 1);

	delete[] cnt;
}


Measured memory_bytes: 47616
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
#define SIZE 200005
#define INF 1000000005LL
#define MOD 1000000007

using namespace std;
typedef long long int ll;
typedef pair <int,int> P;

int k;
vector<P> rc;
int u[10];

int main(){

  cin >> k;
  rep(i,0,8) u[i] = i;
  rep(i,0,k){
    int b,c;
    cin >> b >> c;
    rc.push_back(P(b,c));
  }

  do{
    bool a = true;
    rep(i,0,k) a &= (u[rc[i].first] == rc[i].second);
    if(!a) continue;

    rep(i,0,8) rep(j,0,8) if(i != j){
      if(abs(i-j) == abs(u[i]-u[j])) a = false;
    }
    if(a){
      rep(i,0,8){
        rep(j,0,8){
          cout << (u[i]==j ? "Q" : ".") ;
        }
        cout << endl;
      }
      break;
    }

  }while(next_permutation(u,u+8));

  return 0;
}



Measured memory_bytes: 3104
#include <iostream>

#define N_LARGE 1000000007
#define N_MAX 100000

typedef long long ll;

int x[N_MAX];

using namespace std;

int main(){
    int n, m;
    int count = 0;
    ll ans = 1;
    cin >> n;
    for(int i = 0; i < n; i++){
        count++;
        cin >> x[i];
        if(x[i]%2 == 0 && x[i]/2 < count){
            ans *= count;
            ans = ans%N_LARGE;
            //cout << i << endl;
            count--;
        }
    }
    for(int i = 1; i <= count; i++){
        ans = (ans*i)%N_LARGE;
    }
    cout << ans << endl;
}

Measured memory_bytes: 640
# -*- coding: utf-8 -*-

def main():

    N = int(input())

    case1 = [2, 4, 5, 7, 9]
    case2 = [0, 1, 6, 8]
    case3 = [3]

    num = N % 10

    if num in case1:
        ans = 'hon'

    elif num in case2:
        ans = 'pon'

    elif num in case3:
        ans = 'bon'

    print(ans)


if __name__ == "__main__":
    main()

Measured memory_bytes: 9188
#include<iostream>
using namespace std;
int main (){
  string s,t;
  cin >> s >>t;
  int x = stoi(s+t);
  for(int i=0; i<1000; i++){
    if(i*i==x){
      puts("Yes");
      return 0;
    }
  }
  puts("No");
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair < ll , ll > Pi;
typedef pair < ll , Pi > Ti;
const ll INF = 1LL << 60;
ll W, H, K;
vector < Pi > rc[2][100005];
ll YX[2][200005], P[2][200005], mc[2][200005];
priority_queue < Ti , vector < Ti > , greater < Ti > > pq;
int main()
{
    cin >> W >> H >> K;
    for(int i = 0; i < K; i++) {
        cin >> YX[1][i] >> YX[0][i]; --YX[0][i], --YX[1][i];
        rc[0][YX[0][i]].push_back(Pi(YX[1][i], i));
        rc[1][YX[1][i]].push_back(Pi(YX[0][i], i));
    }
    YX[0][K] = H - 1, YX[1][K] = W - 1;
    rc[0][H - 1].push_back(Pi(W - 1, K));
    rc[1][W - 1].push_back(Pi(H - 1, K));
    for(int i = 0; i < 2; i++) {
        for(int j = 0; j < 100005; j++) {
            sort(rc[i][j].begin(), rc[i][j].end());
            for(int k = 0; k < rc[i][j].size(); k++) {
                P[i][rc[i][j][k].second] = k;
            }
        }
    }
    fill_n(*mc, 2 * 200005, INF);
    if(rc[1][0].empty()) { cout << -1 << endl; return (0); }
    mc[1][rc[1][0][0].second] = rc[1][0][0].first;
    mc[0][rc[1][0][0].second] = rc[1][0][0].first + 1;
    pq.push(Ti(rc[1][0][0].first, Pi(rc[1][0][0].second, 1)));
    pq.push(Ti(rc[1][0][0].first + 1, Pi(rc[1][0][0].second, 0)));
    while(!pq.empty()) {
        Ti d = pq.top(); pq.pop();
        ll v = d.second.first, w = d.first, ang = d.second.second, pos = P[ang][v];
        if(v == K) continue;
        if(pos > 0) {
            ll u = rc[ang][YX[ang][v]][pos - 1].second;
            ll nw = w + YX[1 - ang][v] - YX[1 - ang][u];
            if(nw < mc[ang][u]) {
                mc[ang][u] = nw; pq.push(Ti(nw, Pi(u, ang)));
            }
            if(nw + 1 < mc[1 - ang][u]) {
                mc[1 - ang][u] = nw + 1; pq.push(Ti(nw + 1, Pi(u, 1 - ang)));
            }
        }
        if(pos < rc[ang][YX[ang][v]].size() - 1) {
            ll u = rc[ang][YX[ang][v]][pos + 1].second;
            ll nw = w + YX[1 - ang][u] - YX[1 - ang][v];
            if(nw < mc[ang][u]) {
                mc[ang][u] = nw; pq.push(Ti(nw, Pi(u, ang)));
            }
            if(nw + 1 < mc[1 - ang][u]) {
                mc[1 - ang][u] = nw + 1; pq.push(Ti(nw + 1, Pi(u, 1 - ang)));
            }
        }
    }
    ll minv = min(mc[0][K], mc[1][K]);
    if(minv == INF) cout << -1 << endl;
    else cout << minv << endl;
    return (0);
}


Measured memory_bytes: 30172
#include <stdio.h>
int main(){
	int a,b,c;
	scanf("%d %d %d",&a,&b,&c);
	if(a>=0 && a<=100 && b>=0 && b<=100 && c>=0 && c<=100){
		if(a<b && b<c){
			printf("Yes\n");
		}else{
			printf("No\n");
		}
	}
	return 0;
}

Measured memory_bytes: 1820
#include<bits/stdc++.h>
#define fast ios::sync_with_stdio(false), cin.tie(0);
#define ll long long
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define endl '\n'

const int N = 210; 
const ll INF = 1e8;

using namespace std;

ll adj[N][N];

main()
{
    fast;
    int n,m,R,i,j,k;
    cin>>n>>m>>R;
    int r[R];
    for (i=0;i<R;i++)
        cin>>r[i];
    int a,b;
    ll c;
    for (i=1;i<=n;i++)
    {
        for (j=1;j<=n;j++)
        {
            if (i==j)
                adj[i][j]=0;
            else
                adj[i][j]=INF;
        }
    }
    for (i=0;i<m;i++)
    {
        cin>>a>>b>>c;
        adj[a][b]=min(adj[a][b],c);
        adj[b][a]=min(adj[b][a],c);
    }
    //Floyd-Warshall Algorithm: O(n^3) - All pairs shortest paths
    //Edges can be negative - DP approach (uses adjacency matrix)
    //dp[i][j]=min(dp[i][j],dp[i][k]+dp[k][j])
    for (k=1;k<=n;k++)
    {
        for (i=1;i<=n;i++)
        {
            for (j=1;j<=n;j++)
                adj[i][j]=min(adj[i][j],adj[i][k]+adj[k][j]);
        }
    }
    ll ans=INF,temp;
    sort(r,r+R);
    do{
        temp=0;
        for (i=0;i<R-1;i++)
            temp+=adj[r[i]][r[i+1]];
        ans=min(ans,temp);
    } while (next_permutation(r,r+R));
    cout<<ans<<endl;
}

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

 int main() {
   int a,b,c,d;
   cin >> a >> b >> c >> d;
   //cout << a << b << c << d << endl;
   
   if(max(a,b) - min(a,b) <= d && max(b,c) - min(b,c)<= d || max(a,c) - min(a,c) <= d){
     cout << "Yes" << endl;
   }else{
     cout << "No" << endl;
   }
   
 }

Measured memory_bytes: 256
import sys
import io, os
#input = sys.stdin.buffer.readline
input = io.BytesIO(os.read(0,os.fstat(0).st_size)).readline

h, w, m = map(int, input().split())
R = [0]*h
C = [0]*w
YX = []
for i in range(m):
    y, x = map(int, input().split())
    y, x = y-1, x-1
    R[y] +=1
    C[x] +=1
    YX.append((y, x))

max_r = max(R)
max_c = max(C)
cr = 0
cc = 0
for i in range(h):
    if R[i] == max_r:
        cr += 1
for i in range(w):
    if C[i] == max_c:
        cc +=1
c = 0
for y, x in YX:
    if R[y] == max_r and C[x] == max_c:
        c += 1
if c < cr*cc:
    print(max_r+max_c)
else:
    print(max_r+max_c-1)


Measured memory_bytes: 104100
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func Scan() string {
	sc.Scan()
	return sc.Text()
}

func iScan() int {
	n, _ := strconv.Atoi(Scan())
	return n
}

func fScan() float64 {
	n, _ := strconv.ParseFloat(Scan(), 64)
	return n
}
func stringToInt(s string) int {
	n, _ := strconv.Atoi(s)
	return n
}
func SScan(n int) []string {
	a := make([]string, n)
	for i := 0; i < n; i++ {
		a[i] = Scan()
	}
	return a
}
func iSScan(n int) []int {
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = iScan()
	}
	return a
}
func abs(x int) int {
	if x < 0 {
		x = -x
	}
	return x
}
func larger(a, b int) int {
	if a < b {
		return b
	} else {
		return a
	}
}
func smaller(a, b int) int {
	if a > b {
		return b
	} else {
		return a
	}
}
func max(a []int) int {
	x := a[0]
	for i := 0; i < len(a); i++ {
		if x < a[i] {
			x = a[i]
		}
	}
	return x
}
func min(a []int) int {
	x := a[0]
	for i := 0; i < len(a); i++ {
		if x > a[i] {
			x = a[i]
		}
	}
	return x
}
func sum(a []int) int {
	x := 0
	for _, v := range a {
		x += v
	}
	return x
}

var mod int = 1000000007

func main() {
	buf := make([]byte, 0)
	sc.Buffer(buf, mod)
	sc.Split(bufio.ScanWords)
	n := iScan()
	m := iScan()
	ans := make([]int, n)
	for i := 0; i < m; i++ {
		ans[iScan()-1]++
		ans[iScan()-1]++
	}
	for _, v := range ans {
		fmt.Println(v)
	}
}


Measured memory_bytes: 1772
#include<bits/stdc++.h>
typedef long long int ll;
using namespace std;
#define sz 200009
ll n,m,i,j,k,l,t,arr[sz],brr[sz],crr[sz];
char c[sz];
int main()
{
    scanf("%lld %s",&n,&c);
    for(i=1;i<=n;i++)
    {
        if(c[i-1]=='W')
            arr[i]=1;
        else
            arr[i]=0;
    brr[i]=brr[i-1]+arr[i];
    }
    ll ans=min(brr[n],n-brr[n]);
    for(i=1;i<n;i++)
    {
        l=brr[i];
        j=n-i-brr[n]+brr[i];
        k=min(l,j);
        l=brr[i]+n-i-brr[n]+brr[i]-k;
        ans=min(ans,l);
    }
    printf("%lld\n",ans);
    return 0;
}


Measured memory_bytes: 7140
#include<bits/stdc++.h>
using namespace std;
int main(){
	long long x;
	cin>>x;
	vector<char>arr;
	while(x>0){
		x--;
		arr.push_back((char)('a'+x%26));
		x/=26;
	}
	for(int i=arr.size()-1; i>=0; i--) cout<<arr[i];
	
}

Measured memory_bytes: 3596
#include<bits/stdc++.h>
#include<unordered_set>
#include<unordered_map>
using namespace std;
#define REP(i,m,n) for(int i=(m);i<(n);i++)
#define rep(i,n) REP(i,0,n)
#define pb push_back
#define all(a) a.begin(),a.end()
#define rall(c) (c).rbegin(),(c).rend()
#define mp make_pair
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const ll inf=1e9+7;
const ll mod=998244353;
int main(){
    ll n;cin>>n;
    ll a;cin>>a;
    ll mi=a;
    ll ans=1;
    rep(i,n-1){
        cin>>a;
        if(mi>=a){
            ans++;
            mi=a;
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
extern crate itertools;

use itertools::Itertools;
use std::io::*;
use std::str::FromStr;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("Failed to read bytes") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let n:usize = read();
    let v:Vec<usize> =(0..n).map(|_| read()).collect();
    println!("{}", v.into_iter().combinations(2).fold(0, |acc, x| acc + (x[0] * x[1])));
}


Measured memory_bytes: 2080
#include <cstdio>
#include<iostream>

#define NMAX 50000
using namespace std;
   
int main(void){
  
	int hurui[NMAX]={0};
   int prime[NMAX]={0};
   int dp[NMAX*3]={0};
   int cnt=0;

   hurui[0]=1,hurui[1]=1;

   for(int i=2;i<NMAX;i++){
	   if(hurui[i]==0){
		   prime[cnt]=i;
		   cnt++;
		   for(int j=i*2;j<NMAX;j+=i){
			   hurui[j]=1;
		   }
	   }
   }

   for(int i=0;i<cnt;i++){
	   for(int j=i;j<cnt;j++){
		   dp[prime[i]+prime[j]]++;
	   }
   }

   int n;

   while(1){
	   cin>>n;
	   if(n==0) break;
	   cout<<dp[n]<<endl;
   }

    return 0;
}

Measured memory_bytes: 2140
#include "bits/stdc++.h"
using namespace std;
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
#define cool ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	#define int  long long int
	#define pb push_back
	#define fe first
    #define lb lower_bound 
    #define ub upper_bound
    #define pii pair<pair<int,int>,pair<int,int> >
	#define se second
	#define endl "\n"
	#define pi pair<int, int>
	#define vi vector<int> 
	#define vvi vector<vi>
    #define bs   binary_search
	#define rep(i,a,b) for(int i=a;i<b;i++)
	#define rep1(i,a,b) for(int i=a;i<=b;i++)	
    #define all(c) (c).begin(),(c).end()
    #define sz(x)       (int)x.size() 
	#define PI 3.14159265358979323846
    
	const int N =1e6;
    
     int mod= 1e9+7;
     
     int dx[4]={0,0,+1,-1};
     int dy[4]={+1,-1,0,0};
   
     void solve(){
          
           int k,x;
           cin>>k>>x;
           int l1=x-k+1;
           rep(i,l1,l1+k)
             cout<<i<<" ";
            
           rep(i,x+1,x+k)
             cout<<i<<" ";         
          
           
     }
   
   
   
   
      int32_t main() {
	    cool;
	    int t=1;
        //cin>>t;
	    while(t--)
	       solve();
	       
	       
	       return 0;	   
	   }


Measured memory_bytes: 256
using System;
using System.Linq;
using System.Collections.Generic;

class Program
{
    static void Main()
    {
        int[] S = Utils.ReadInts();
        int result = Solve(S[0], S[1]);
        Utils.Return(result);
    }
    private static int Solve(int a, int b )
    {
        List<int> list = new List<int>() { a + b, a - b, a * b };
        return list.Max();
    }
}

static class Utils
{
    /// <summary>
    /// int入力を取得する
    /// </summary>
    /// <returns></returns>
    public static int[] ReadInts()
    {
        return Console.ReadLine().Split().Select(int.Parse).ToArray();
    }
    /// <summary>
    /// 最初に条件ヒットした配列のindexを取得する
    /// </summary>
    /// <typeparam name="T"></typeparam>
    /// <param name="source"></param>
    /// <param name="func"></param>
    /// <param name="start"></param>
    /// <returns></returns>
    public static int FindFirstIndex<T>(IList<T> source, Func<T, bool> func, int start)
    {
        for(int i = start; i < source.Count; i++)
        {
            if (func(source[i]))
            {
                return i;
            }
        }
        return -1;
    }
    /// <summary>
    /// Yes or Noの文字列を返却する
    /// </summary>
    /// <param name="result"></param>
    public static void ReturnYesOrNo(bool result)
    {
        Console.WriteLine(result ? "Yes" : "No");
        Console.ReadLine();
    }

    internal static void Return(int result)
    {
        Console.WriteLine(result);
    }
}
/// <summary>
/// ソートクラス
/// </summary>
class IntDisComparetor : IComparer<int>
{
    public static IComparer<int> Instance { get; } = new IntDisComparetor();
    private IntDisComparetor() { }
    public int Compare(int x, int y)
    {
        return Comparer<int>.Default.Compare(y, x);
    }
}
/// <summary>
/// ソートクラス
/// </summary>
class IntComparetor : IComparer<int>
{
    public static IComparer<int> Instance { get; } = new IntComparetor();
    private IntComparetor() { }
    public int Compare(int x, int y)
    {
        return Comparer<int>.Default.Compare(x, y);
    }
}

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

using namespace std;

int main()
{
  int n,k;
  cin>>n>>k;
  vector<int> vec(n);
  for(int i=0;i<n;i++)
    cin>>vec[i];
  
  vector<int> ans(n+1,INT_MAX);
  for(int i=0;i<n;i++)
  {
    if(i<k)
    {
      ans[i]=abs(vec[i]-vec[0]);
      continue;
    }
    for(int j=i-1;j>=i-k;j--)
    {
      ans[i]=min(abs(vec[i]-vec[j])+ans[j],ans[i]);
    }
  }
  cout<<ans[n-1]<<endl;
  return 0;
}

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

using namespace std;

int main(){

	int n;

	cin>> n;

	if (n < 1200) {
		cout << "ABC" << endl;
	}
	else if (n < 2800) {
		cout << "ARC" << endl;
	}
	else {
		cout << "AGC" << endl;
	}

}


Measured memory_bytes: 256
def input_int_list():
    return [int(thing) for thing in input().split(" ")]

def int_input():
    return int(input())


def print_ans(string):
    print(string)
    exit()

def yes():
    print("Yes")
    exit()

def no():
    print("No")
    exit()

if __name__ == '__main__':
    N,D = input_int_list()
    points = [input_int_list() for i  in range(N)]
    distance = [p[0]**2 + p[1]**2 for p in points]
    print(len([d for d in distance if d <= D**2]))


Measured memory_bytes: 54456
#include<iostream>
#include<algorithm>
#include<vector>
#include<map>
#include<string>

using namespace std;
int main(){
    
string s;
cin >>s;
int answer=0;
for(int i=0;i<3;i++){
    if(s[i]==s[i+1]){
        answer=-1;
    }
}
if(answer==0){
    cout <<"Good"<<endl;
}
else{
    cout <<"Bad"<<endl;
}
 return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <unordered_map>
#include <bitset>
#include <stack>

using namespace std;

template<typename T> 
void show(T a){
  for(auto i : a){ cout << i << " "; }
  cout << endl;
}

long long sum = 0;
long long count = 0;

void add_num(string& s, bitset<12>&b ){
  int j = 0;
  //cout << "str: " << s << endl;
  for(int i = 0; i < s.size()-1; i++){
    if(b[i] == 1) {
      string num = s.substr(j, i-j+1);
      sum += stoll(num);
      //cout << num << " " ;
      j = i + 1;
    }
  }
  string num = s.substr(j, s.size()-j);
  sum += stoll(num);
  //cout << sum << endl; //debug
}

void dfs(int pos, string& s, bitset<12>& b){
  //cout << "pos:" << pos << endl;
  if(pos >= s.size()) return;
  if(pos == s.size()-1){
    add_num(s, b);
    //cout << b.to_string() << endl;
    //cout << ++count << endl;
    //cout << num << endl; //debug
  }
  b[pos] = 1;
  dfs(pos+1, s, b);
  b[pos] = 0;
  dfs(pos+1, s, b);
}

int main(int argc, char *argv[]){
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  string s;
  long long num;
  cin >> num;
  s = to_string(num);
  bitset<12> b(0);
  //dfs(0, s, b);  
  long long int count = 0;
  long long int end = 1 << (s.size() - 1);
  
  while(count != end){
    //cout << b.to_string() << endl;
    add_num(s, b);
    b = bitset<12>(++count);
  }
  cout << sum << endl;
}


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

using namespace std;

int main() {
  int H, W;
  cin >> H >> W;

  vector<vector<int>> A(H, vector<int>(W, 0));
  vector<vector<int>> B(H, vector<int>(W, 0));
  for (int h = 0; h < H; h++) {
    for (int w = 0; w < W; w++) {
      cin >> A[h][w];
    }
  }
  for (int h = 0; h < H; h++) {
    for (int w = 0; w < W; w++) {
      cin >> B[h][w];
    }
  }

  vector<vector<vector<bool>>> dp(H, vector<vector<bool>>(W, vector<bool>(80 * (H + W), false)));
  dp[0][0][abs(A[0][0] - B[0][0])] = true;
  for (int h = 0; h < H; h++) {
    for (int w = 0; w < W; w++) {
      if (h == 0 && w == 0) continue;

      int cur = abs(A[h][w] - B[h][w]);

      for (int i = 0; i < 80 * (H + W); i++) {
        if ((h > 0 && dp[h-1][w][i]) || (w > 0 && dp[h][w-1][i])) {
          dp[h][w][i+cur] = true;
          dp[h][w][abs(i - cur)] = true;
        }
      }
    }
  }

  int ans = 80 * (H + W);
  for (int i = 0; i < 80 * (H + W); i++) {
    if (dp[H-1][W-1][i]) {
      ans = i;
      break;
    }
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 12800
#define _CRT_SECURE_NO_WARNINGS
#pragma comment(linker, "/STACK:16777216")
#include <iostream>
#include <algorithm>
#include <cstring>
#include <vector>
#include <map>
#include <string>
#include <cmath>
#include <stack>
#include <iomanip>
#include <set>
#include <queue>
#include <unordered_map>

using namespace std;

#define ff first
#define ss second

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;

const int maxn = 2e5 + 7;
const int inf = 2e9 + 7;
const ll infl = 1e18 + 7;
const long double eps = 1e-9;
const ll mod = 998244353;

int main() {
#ifdef _DEBUG
	freopen("in.txt", "r", stdin);
	freopen("out.txt", "w", stdout);
#endif // _DEBUG

	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);

	int n, k;
	cin >> n >> k;
	vector<int> a(n);
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	vector<int> dp(n);
	for (int i = 1; i < n; i++) {
		dp[i] = dp[i - 1] + abs(a[i] - a[i - 1]);
		for (int j = i - 2; j >= max(i - k, 0); j--) {
			dp[i] = min(dp[i], dp[j] + abs(a[i] - a[j]));
		}
	}
	cout << dp[n - 1];
	return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <cassert>
#include <climits>
#include <bitset>
#include <stack>
#include <queue>
#include <iomanip>
#include <limits>
#include <string>
#include <cmath>
#include <set>
#include <map>
#include <math.h>
#include <algorithm>
#include <vector>
#include <string.h>
 
using namespace std;
typedef long long ll;
 
 
typedef pair<ll,ll> P;
long long int INF = 1e18;
double Pi = 3.141592653589;
long long int mod = 1000000007;
// memset(a,0,sizeof(a)); →全部０にする
 
vector<ll> G[100005];
vector<P> tree[100010];
priority_queue <ll> pql;
priority_queue <P> pqp;
//big priority queue
priority_queue <ll,vector<ll>,greater<ll> > pqls;
priority_queue <P,vector<P>,greater<P> > pqps;
//small priority queue
//top pop

int dx[8]={1,0,-1,0,1,1,-1,-1};
int dy[8]={0,1,0,-1,1,-1,-1,1};
//↓,→,↑,←
 
#define p(x) cout<<x<<endl;
#define el cout<<endl;
#define pe(x) cout<<x<<" ";
#define ps(x) cout<<fixed<<setprecision(25)<<x<<endl;
#define pu(x) cout<<x;
#define re(i,a,b) for(i=a;i<=b;i++);
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define deba(x) cout<< #x << " = " << x <<endl

ll rui(ll abc,ll bed){
	//aのb乗を計算する
	if(bed==0){return 1;}
	else{
		ll ced = rui(abc,bed/2);
		ced *= ced;
		ced %= mod;
		if(bed%2==1){ced*=abc; ced%=mod;}
		return ced;
	}
} 

ll i,j,k,ii,jj;
ll n,m,num,sum;
ll ans;
ll a,b,c,d,e,f,g,h,w,v;
char s[500][500];
ll x[800005],y[800005],z[900005];
ll timee[500005];
ll color[500005];
ll kyori[500005];

void paint(ll v,ll d,ll c,ll t){
	//p("結果");
	//pe(v);pe(d);p(c);
	if(color[v]==0){
		//pe(c);p(v);
		color[v] = c;
		num++;
	}
	if(num==n)return;
	timee[v] = t;
	kyori[v] = d;
	if(d==0)return ;
	for(int i=0;i<G[v].size();i++){
		if(timee[G[v][i]] == t && kyori[G[v][i]] >= d)continue;
		paint(G[v][i],d-1,c,t);
	}
}

int main(){	
	cin>>n>>m;
	for(i=0;i<m;i++){
		cin>>a>>b;
		G[a].pb(b);
		G[b].pb(a);
	}
	cin>>k;
	for(i=0;i<k;i++){
		cin>>x[i]>>y[i]>>z[i];
	}
	reverse(x,x+k);
	reverse(y,y+k);
	reverse(z,z+k);
	for(a=0;a<k;a++){
		paint(x[a],y[a],z[a],a+5);
	}
	for(i=1;i<=n;i++){
		p(color[i]);
	}	
	return 0;
}

Measured memory_bytes: 27124
fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>().split_whitespace()
        .map(|e| e.parse().ok().unwrap()).collect()
}

#[allow(dead_code)]
fn read_vec2<T: std::str::FromStr>(n: u32) -> Vec<Vec<T>> {
    (0..n).map(|_| read_vec()).collect()
}

fn main() {
    let an = read::<i32>();
    let bn = read::<i32>();
    let cn = read::<i32>();
    let x  = read::<i32>();

    let mut pat = 0;
    for a in 0 .. (x/500)+1 {
        if a > an { break; }
        for b in 0 .. ((x-a)/100)+1 {
            if b > bn { break; }
            for c in 0 .. ((x-a-b)/50)+1 {
                if c > cn { break; }
                if (x - a*500 - b*100 - c*50) == 0 {
                    pat += 1;
                }
            }
        }
    }
    println!("{}", pat);
}


Measured memory_bytes: 4352
#include <iostream>
#include <cstdio>
#include <algorithm>

using namespace std;

int main(){
	
	int team, score;
	
	int p[1000], rank[1000];
	
	for(int i = 0; i < 1000; i++){
		p[i] = 0;
	}
	
	scanf("%d,%d", &team, &score);
	
	while(team != 0 || score != 0){
		p[team] = score;
		scanf("%d,%d", &team, &score);
	}
	
	bool checker;
	int ranking;
	
	ranking = 1;
	
	for(int i = 30; i >= 0; i--){
		checker = false;
		for(int j = 0; j < 1000; j++){
			if(p[j] == i){
				checker = true;
				rank[j] = ranking;
			}
		}
		if(checker){
			ranking++;
		}
	}
	
	while(true){
		int num;
		cin >> num;
		if(cin.eof()){
			break;
		}
		printf("%d\n", rank[num]);
	}
	
	return 0;
}

Measured memory_bytes: 1232
from sys import stdin
f_i = stdin

import numpy as np

N, K = map(int, f_i.readline().split())
A = np.array(f_i.read().split(), dtype=int)

A = np.sort(A)
zero_left = A.searchsorted(0, side='left')
zero_right = A.searchsorted(0, side='right')
zero_cnt = zero_right - zero_left
pos = A[zero_right:]
neg = A[:zero_left]

def f(x):
    cnt = 0
    
    if x >= 0:
        cnt += zero_cnt * N
    
    cnt += np.searchsorted(A, x // pos, side='right').sum()
    cnt += (N - np.searchsorted(A, (-x - 1) // (-neg), side='right')).sum()
    
    cnt -= np.count_nonzero(A ** 2 <= x)
    return cnt // 2


left = -10 ** 18
right = 10 ** 18
while left + 1 < right:
    x = (left + right) // 2
    if f(x) >= K:
        right = x
    else:
        left = x

print(right)

Measured memory_bytes: 34320
#include <iostream>
#include <string.h>
#include <algorithm>
using namespace std;

int main()
{	
	int n, m = 0;
	int a[101];

	memset(a, 0, sizeof(a));

	while (cin >> n)
		a[n]++;			

	for (int i = 1; i <= 100; i++)
		m = max(m, a[i]);

	for (int i = 1; i <= 100; i++)
		if (a[i] == m)
			cout << i << endl;

	return 0;
}



Measured memory_bytes: 2992
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <cmath>
#define rep(i,n) for (int i = 0; i < n; ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;

int main() {
  ll A, B, C, K;
  cin >> A >> B >> C >> K;
  ll ans = 0;
  if (A >= K) ans = K;
  else if (A + B >= K) ans = A;
  else ans = A - (K - A - B);
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3136
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LINF = 1e18;
inline ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
inline ll lcm(ll a, ll b) { return a / gcd(a, b)*b; }
template<class S,class T> ostream& operator << (ostream& out,const pair<S,T>& o){ out << "(" << o.first << "," << o.second << ")"; return out; }
template<class T> ostream& operator << (ostream& out,const vector<T> V){ for(int i = 0; i < V.size(); i++){ out << V[i]; if(i!=V.size()-1) out << " ";} return out; }
template<class T> ostream& operator << (ostream& out,const vector<vector<T> > Mat){ for(int i = 0; i < Mat.size(); i++) { if(i != 0) out << endl; out << Mat[i];} return out; }
template<class S,class T> ostream& operator << (ostream& out,const map<S,T> mp){ out << "{ "; for(auto it = mp.begin(); it != mp.end(); it++){ out << it->first << ":" << it->second; if(mp.size()-1 != distance(mp.begin(),it)) out << ", "; } out << " }"; return out; }

/*
 <url:https://atcoder.jp/contests/dp/tasks/dp_h>
 問題文============================================================
 =================================================================
 解説=============================================================
 典型
 
 組み合わせ数をdpで求めるやり方を応用
 ================================================================
 */

const ll MOD = 1e9+7;
template<class Type>
Type solve(Type res = Type()){
    int H,W; cin >> H >> W;
    vector<vector<char>> a(H,vector<char>(W));
    for(auto& vec:a) for(auto& in:vec) cin >> in;
    vector<vector<ll>> dp(H+1,vector<ll>(W+1));
    dp[0][0] = 1;
    for(int i = 0; i < H;i++){
        for(int j = 0; j < W;j++){
            if(a[i][j]=='#') continue;
            (dp[i+1][j] += dp[i][j])%=MOD;
            (dp[i][j+1] += dp[i][j])%=MOD;
        }
    }
    res = dp[H-1][W-1];
    return res;
}
int main(void) {
    cin.tie(0); ios_base::sync_with_stdio(false);
    // solve(0);
    cout << fixed << setprecision(15) << solve<ll>() << endl;
    return 0;
}


Measured memory_bytes: 9088
#include <stdio.h>

int main(int argc, char const *argv[]) {
  int N,count=0,countA=0,countB=0,i,countBA=0;
  char array[12];
  scanf("%d", &N);
  while (N > 0) {
    scanf("%s",array);
    for (i = 0; array[i+1] != '\0'; i++) {
      if (array[i] == 'A') {
        if (array[i+1] == 'B') {
          count++;
        }
      }
    }
    if (array[0] == 'B') {
      countB++;
    }
    if (array[i] == 'A') {
      countA++;
    }
    if (array[i] == 'A') {
      if (array[0] == 'B') {
        countB--;
        countA--;
        countBA++;
      }
    }
    for (i = 0; array[i] != '\0'; i++) {
      array[i] = '\0';
    }
    N--;
  }
  if (countA > countB) {
    count += countB + countBA;
  } else {
    if (countA == 0 && countB == 0) {
      if (countBA > 0) {
        countBA--;
      }
    }
    count += countA + countBA;
  }
  printf("%d\n",count);
  return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
#define FOR0(i,n) for(ll i=0;i<n;i++)
#define FOR1(i,n) for(ll i=1;i<=n;i++)
#define FORl(i,l,n) for(ll i=l;i<n;i++)
using namespace std;
#define pi pair<ll,ll>
#define pb push_back
#define ll long long
#define ld long double
#define ff first
#define ss second
#define mp make_pair
#define mst0(x) memset(x,0,sizeof(x));
#define vi vector<ll>
#define sync ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl '\n'
#define sp <<" "<<
#define intmax 1e14
ll power(ll num,ll g,ll mod){
  if(g==0)return 1;
  if(g%2==1)return (num*power((num*num)%mod,g/2,mod))%mod;
  return power((num*num)%mod,g/2,mod);
}
 
int main(){
	int n, k;
	cin>>n>>k;
	int arr[n];
	FOR0(i, n) cin>>arr[i];
	vector<int> minval(n, INT_MAX);
	minval[0] = 0;
	FOR0(i, n){
		for(int j = i+1; j <= i+k and j < n; j++){
			int val = minval[i] + abs(arr[i] - arr[j]);
			minval[j] = min(minval[j], val);
		}
	}	
	cout<<minval[n-1];
}

Measured memory_bytes: 1024
A, B = gets.chomp.split(" ").map{|s| s.to_i}

if A > B
  ltmp = A
  stmp = B
else
  ltmp = B
  stmp = A
end

r = ltmp % stmp
[A, B].max.times do
  break if r <= 0
  ltmp = stmp
  stmp = r
  r = ltmp % stmp
end

puts A * B / [stmp, 1].max

Measured memory_bytes: 1788
#include <stdio.h>
#include <ctype.h>

int main()
{
  char input_st;
  int i;
  int counter[26];
  for(i = 0 ; i <= 26 ; i++)
    counter[i] = 0;

  while(scanf("%c", &input_st) != EOF)
  {
    if(isupper(input_st))
    {
      i = input_st - 'A';
      counter[i]++;
    }
    else if(islower(input_st))
    {
      i = input_st - 'a';
      counter[i]++;
    }
  }

  for(i = 0 ; i < 26 ; i++)
    printf("%c : %d\n", 'a' + i, counter[i]);
}



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

int main() {
	int n,k;
	cin >> n >> k;
	int h[n];
	int count = 0;
	for(int i=0;i<n;i++){
		cin >> h[i];
		if(h[i]>=k){
			count ++;
		}
	}
	cout << count << endl;
	return 0;
}

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


int main()
{

  
        
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    
    ll n,i;
    cin>>n;
    map <ll,ll> freq;
    for(i=0;i<n-1;i++)
    {
        ll x;
        cin>>x;
        freq[x]++;
    }
    for(i=1;i<=n;i++)
        cout<<freq[i]<<endl;
    return 0;
}

Measured memory_bytes: 16144
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define pi 3.141592653589793238
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define pb push_back
#define bg begin()
#define end end()
#define sz size()
#define vi vector<int>
#define vl vector<long long int>
int main(){
	fast;
	int arr[5];
	for(int i=0;i<5;i++)
		cin>>arr[i];
	for(int i=0;i<5;i++)
		if(arr[i]==0)
			{
				cout<<i+1;
				return 0;
			}
  	return 0;
}

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

int main(){
  string s;
  cin>>s;
  int n = s.size();
  int count = 0;
  for (int i=0;i<n;++i){
    if (s[i]!=s[n-1-i]){
      count++;
    }
  }
  cout<<count/2;
}

Measured memory_bytes: 256
def main():
    import sys
    input = sys.stdin.buffer.readline

    N = int(input())
    win = 0
    for _ in range(N):
        a, k = map(int, input().split())
        while True:
            if a < k:
                g = 0
                break
            elif a % k == 0:
                g = a // k
                break
            else:
                d = (a//k) + 1
                a -= d * ((a - k * (a//k))//d)
                if a < k:
                    g = 0
                    break
                elif a % k == 0:
                    g = a // k
                    break
                else:
                    a -= d

        win ^= g
    if win:
        print('Takahashi')
    else:
        print('Aoki')


if __name__ == '__main__':
    main()


Measured memory_bytes: 40560
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
    ll n,m,sum=0,cnt=0,i,j;
    cin>>n;
    string s;
    cin>>s;
    m=s.size();
    for(i=1;i<=m;i++)
    {
        if(s[i-2]=='A'&&s[i-1]=='B'&&s[i]=='C')
            cnt++;
    }
    cout<<cnt<<endl;

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 int main (){
 int D;
 cin >> D;
 string op;
 int B = 0;
 for ( int i = 0 ; i < D; i++){
   cin >> op;
   if (op == "Y"){
   B = 1;
   break;
   }
 }
 if ( B == 0){
   cout << "Three" << endl;
 }else{
   cout << "Four"  << endl;
 }

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define INF LLONG_MAX
#define ll  long long
#define ull unsigned long long
#define rep(i,n) for(ull i=0; i<n; ++i)
#define MOD 1000000007
using namespace std;
template<class T> inline bool chmin(T& a, T b) { if(a>b) {a=b; return true;} return false;}
template<class T> inline bool chmax(T& a, T b) { if(a<b) {a=b; return true;} return false;}

int main() {
  ull N, K; cin >> N >> K;
  vector<ull> A(N); rep(i, N) cin >> A[i];
  ull cnt = 0;
  rep(i, N){for(ull j=i+1; j<N; ++j){ if(A[i] > A[j]) {++cnt;}}}
  ull cnt2 = 0;
  if(K >= 2){rep(i,N){rep(j,N){if(A[i]>A[j]){++cnt2;}}}}
  ull ans = cnt*K+cnt2*((K*(K-1)/2)%MOD);
  cout << ans%MOD << endl;
}


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

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

    long double ans = 0;
    long double tmp;
    string s;

    for(int i = 0;i < n;i++){
        cin >> tmp >> s;
        if(s == "JPY"){
            ans += tmp;
        }else{
            ans += 380000*tmp;
        }
    }

    printf("%.9llf\n", ans);

    return 0;
}



Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<map>
#include<set>
#include<cstdio>
#include<cmath>
#include<deque>
#include<numeric>
#include<queue>
#include<stack>
#include<cstring>
#include<limits>
#include<functional>
#include<unordered_set>
#include<iomanip>
#include<cassert>
#include<regex>
#include<bitset>
#include<complex>
#include<chrono>
#define rep(i,a) for(int i=(int)0;i<(int)a;++i)
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(),x.end()
using ll=long long;
constexpr ll mod = 1e9 + 7;
constexpr ll INF = 1LL << 60;

ll gcd(ll n, ll m) {
	ll tmp;
	while (m!=0) {
		tmp = n % m;
		n = m;
		m = tmp;
	}
	return n;
}

ll lcm(ll n, ll m) {
	return abs(n * m) / gcd(n, m);//gl=xy
}
 
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;
}
 
using namespace std;
//ここから

void solve(){
  int n;
  cin>>n;
  vector<int>c(n-1),s(n-1),f(n-1);
  rep(i,n-1)cin>>c[i]>>s[i]>>f[i];
  rep(x,n){
    int ans=0;
    int t=0;
    for(int i=x;i<n-1;++i){
      if(t<=s[i])t=s[i];
      else t=(t-s[i]+f[i]-1)/f[i]*f[i]+s[i];
      t+=c[i];
      ans=t;
    }
    cout<<ans<<"\n";
  }
}

int main(){
	ios::sync_with_stdio(false);
  cin.tie(0);
	//cout<<fixed<<setprecision(15);
  solve();
	return 0;
}


Measured memory_bytes: 256
input()
T, A = map(int, input().split())
H = list(map(int, input().split()))
d = None
x = None
for i, h in enumerate(H):
    a = T - h * 0.006
    if d is None or d > abs(A - a):
        d = abs(A - a)
        x = i + 1
print(x)


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

int main() {
  int N,A;
  
  cin >> N >> A;
  
  int R = N % 500;
    
  if (R <= A) {
    cout << "Yes" << endl;
  }
  
  else {
    cout << "No" << endl;
  }
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.AbstractMap;
import java.util.StringTokenizer;

public class Main {

	public static void main(String[] args) {
		FastScanner sc = new FastScanner(System.in);
		PrintWriter out = new PrintWriter(System.out);
		
		solve(sc, out);
		
		out.flush();
	}
	
	public static void solve(FastScanner sc, PrintWriter out){
		int a = sc.nextInt();
		int b = sc.nextInt();
		
		out.println(a <= b ? a : a - 1);
	}

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

class Pair<K, V> extends AbstractMap.SimpleEntry<K, V> {

    public Pair(final K key, final V value) {
        super(key, value);
    }
 }

class FastScanner {
    private BufferedReader reader = null;
    private StringTokenizer tokenizer = null;

    public FastScanner(InputStream in) {
        reader = new BufferedReader(new InputStreamReader(in));
        tokenizer = null;
    }

    public String next() {
        if (tokenizer == null || !tokenizer.hasMoreTokens()) {
            try {
                tokenizer = new StringTokenizer(reader.readLine());
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return tokenizer.nextToken();
    }

    public String nextLine() {
        if (tokenizer == null || !tokenizer.hasMoreTokens()) {
            try {
                return reader.readLine();
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }

        return tokenizer.nextToken("\n");
    }

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

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

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

    public int[] nextIntArray(int n) {
        int[] a = new int[n];
        for (int i = 0; i < n; i++)
            a[i] = nextInt();
        return a;
    }

    public long[] nextLongArray(int n) {
        long[] a = new long[n];
        for (int i = 0; i < n; i++)
            a[i] = nextLong();
        return a;
    }
}

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

int calculation(char a, char b, int c){
    int na, nb;
    na = (int) (a-'0');
    nb = (int) (b-'0');
    return na*nb+c;
}

int calculation2(char a, char b, int c){
    int na, nb;
    na = (int) (a-'0');
    nb = (int) (b-'0');
    return na+nb+c;
}

int main(){
    string A,B;
    cin >> A >> B;
    B.erase(B.begin()+1);
    int c=0;
    string ans;
    string anstmp[B.size()];
    string anstmp2="00000000000000000000000";
    for(int j=(int) B.size()-1; j>=0; j--){
        c=0;
        for(int i=A.size()-1; i>=0; i--){
            int tmp = calculation(A[i],B[j],c);
            c = tmp/10;
            string stmp = to_string(tmp%10);
            anstmp[j].insert(0,stmp);
        }
        anstmp[j].insert(0,to_string(c));
        //cout << "j anstmp[j] " << j << " " << anstmp[j] << endl;
    }

    string ins;
    for(int i=(int) B.size()-2; i>=0; i--){
        ins.insert(0,"0");
        anstmp[i].insert(anstmp[i].size(),ins);
        //cout << "i anstmp[i] " << i << " " << anstmp[i] << endl;
    }
    int c1=0;
    for(int i=1; i<=(int) anstmp2.size(); i++){
        int c=0;
        for(int j=0; j< (int) B.size(); j++){
            //cout << "num: " << anstmp[j].size() << endl;
            if( (int) anstmp[j].size()-i<0){
                //cout << "continue" << endl;
                continue;
            }
            //cout << "a b " << anstmp2[(int) anstmp2.size()-i] << " " << anstmp[j][(int) anstmp[j].size()-i] << endl;
            int tmp = calculation2(anstmp2[(int) anstmp2.size()-i],anstmp[j][(int) anstmp[j].size()-i],c1);
            c1=0;
            c += tmp/10;
            string stmp=to_string(tmp%10);
            anstmp2[(int) anstmp2.size()-i] = stmp[0];
            //cout << "i j tmp stmp anstmp2 " << i << " " << j << " " << tmp << " " << stmp << " " << anstmp2 << endl;
        }
        c1=c;
    }

    //cout << "anstmp2 " << anstmp2 << endl;

    bool zero=true;
    for(int i=0; i<(int) anstmp2.size()-2; i++){
        if(anstmp2[i]!='0') zero=false;
        if(zero && i!=(int) anstmp2.size()-3) continue;
        cout << anstmp2[i];
    }
    cout << endl;

    return 0;
}

Measured memory_bytes: 3692
import sys
from heapq import heappush, heappop

input = sys.stdin.readline
n, m = map(int, input().split())
heap = []

for i in map(int, input().split()):
  heappush(heap, i)

bc = [list(map(int, input().split())) for _ in range(m)]
bc.sort(key = lambda x: -x[1])#cが大きいものから順に操作を加える

for b,c in bc:
  for j in range(b):
    a = heappop(heap)
    if a < c:
      heappush(heap, c)
    else:
      heappush(heap, a)
      break
print(sum(heap))

Measured memory_bytes: 36120
from collections import deque
import sys
input = sys.stdin.readline

w = []
h = []
dataset = []
while True:
    wt, ht = map(int, input().split())
    if wt==0 and ht==0:
        break
    w.append(wt)
    h.append(ht)
    subset = [[0]*(wt+2) for _ in range(ht+2)]
    for i in range(1, ht + 1):
        inls = [0] + list(map(int, input().split())) + [0]
        for j in range(1, wt + 1):
            subset[i][j] = inls[j]
    dataset.append(subset)

for i in range(len(dataset)):
    subset = dataset[i]
    w_ = w[i]
    h_ = h[i]
    idxs = []
    for row in range(1, h_+1):
        for col in range(1, w_+1):
            if subset[row][col] == 1:
                idxs.append((row, col))
    
    graph = {idx: deque() for idx in idxs}
    for idx in idxs:
        x = idx[0]
        y = idx[1]
        surroundings = [(x+1, y), (x+1, y+1), (x, y+1), (x-1, y+1)
                         ,(x-1, y), (x-1, y-1), (x, y-1), (x+1, y-1)]
        for surrounding in surroundings:
            if subset[surrounding[0]][surrounding[1]] == 1:
                graph[idx].append(surrounding)
    
    seen = [[0]*(w_+2) for _ in range(h_+2)]
    stack = []
    def dfs(idx):
        seen[idx[0]][idx[1]] = 1
        stack.append(idx)
        while stack:
            s = stack[-1]
            if not graph[s]:
                stack.pop()
                continue
            
            g = graph[s].popleft()
            if seen[g[0]][g[1]]:
                continue
            seen[g[0]][g[1]] = 1
            stack.append(g)

    island_count = 0
    for idx in idxs:
        if not seen[idx[0]][idx[1]]:
            dfs(idx)
            island_count += 1
    print(island_count)


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

int main()
{
    int n;
    cin>>n;
    vector<double> prob(n);
    for(int i=0;i<n;i++)
    cin>>prob[i];
    
    vector<vector<double> > ans(n+1,vector<double> (n));
    //calculating for head
    ans[0][0]=1-prob[0];
    //0 number of heads
    for(int i=1;i<n;i++)
    {
        ans[0][i]= (double) ans[0][i-1]*((double)(1-prob[i]));
    }
    ans[1][0]=prob[0];
    for(int i=2;i<=n;i++)
    {
        ans[i][0]=(double)0;
    }
    for(int i=1;i<=n;i++)
    {
        for(int j=1;j<n;j++)
        {
            ans[i][j]=ans[i][j-1]*(1-prob[j]) + ans[i-1][j-1]*prob[j];
        }
    }
    /*for(int i=0;i<=n;i++)
    {
        for(int j=0;j<n;j++)
        cout<<ans[i][j]<<" ";
        cout<<"\n";
    }*/
    int start=(n/2)+1;
    double a=0;
    for(int i=start;i<=n;i++)
    a+=ans[i][n-1];
    cout<<setprecision(9)<<a;
    return 0;
}

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

typedef long long ll;
typedef pair<ll, ll> pll;

#define m0(x) memset(x, 0, sizeof(x))
#define all(x) x.begin(), x.end()
#define rep(i, n) for(int i = 0; i < (n); i++)
#define asort(x) sort(all(x));
#define dsort(x, t) sort(x.begin(), x.end(), greater<t>());
#define vuni(v) v.erase(unique(v.begin(), v.end()), v.end());
#define mins(m, s) m.insert(make_pair(s, 1));
#define mfin(m, s) m.find(s) != m.end()

#define dump(x)  cout << #x << " = " << (x) << endl
#define YES(n) cout << ((n) ? "YES" : "NO" ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No" ) << endl

const int INF = 1e9;
const ll LINF = 1e18;
const int mod = 1e9+7;

int main(){
    int x;
    cin >> x;
    if(x == 0){
        cout << 1 << endl;
    }else{
        cout << 0 << endl;
    }
    return 0;
}

Measured memory_bytes: 3592
#### import ####
import sys
import math
from collections import defaultdict

#### 設定 ####
sys.setrecursionlimit(10**7)
def input():
    return sys.stdin.readline()[:-1]

#### 定数 ####
mod = 10**9 + 7

#### 読み込み ####
def I(): return int(input())
def II(): return map(int, input().split())
def III(): return list(map(int, input().split()))
def Line(N):
    read_all = [tuple(map(int, input().split())) for _ in range(N)]
    return map(list,zip(*read_all))

#################

N = I()
v = III()

v.sort()

ans = (v[0]+v[1])/2
for i in range(2,N):
    ans = (ans + v[i])/2

print(ans)

Measured memory_bytes: 38384
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i <= (int)(n); i++)
typedef int64_t Int;


vector<vector<Int>> G(10010);
vector<Int> c1(10010), c2(10010);
Int cnt = 0;

void dfs(int i, int j = -1) {
    c2[i] = c1[cnt];
    cnt++;
    for(int k = 0; k < G[i].size(); k++) {
        if(G[i][k] != j) {
            dfs(G[i][k],i);
        }
    }
    return;
}


int main() {
    Int N;
    cin >> N;
    rep(i,N-1) {
        Int a, b;
        cin >> a >> b;
        a--;
        b--;
        G[a].push_back(b);
        G[b].push_back(a);
    }
    vector<Int> c(N);
    rep(i,N) cin >> c[i];
    sort(c.begin(),c.end());
    reverse(c.begin(),c.end());

    rep(i,N) c1[i] = c[i];

    dfs(0);

    Int sum = 0;
    rep1(i,N-1) sum += c1[i];

    cout << sum << endl;
    rep(i,N-1) cout << c2[i] << " ";
    cout << c2[N-1] << endl;
}

Measured memory_bytes: 1536