akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
using namespace std;
typedef long long ll;
typedef unsigned int ui;
const ll mod = 1000000007;
const ll INF = (ll)1000000007 * 1000000007;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef long double ld;
typedef complex<ld> Point;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<ll, ll> LP;
typedef pair<ll,LP> PP;

ll n,x,B=0;
vector<PP> t;
vector<LP> p_sort;
vector<ll> p;
LP seg;
bool calc(ll k){
    ll p_ = k/x,q_ = k%x;
    ll res=0;
    vector<bool> used;
    used.resize(n,false);
    rep(i,p_){
        res+=p_sort[i].first;
        used[p_sort[i].second]=true;
        //cout << p_sort[i].first << " " << p_sort[i].second << endl;
        }
    //cout << p_sort[p_].first << " " << p_sort[p_].second << endl;
    ll a=0;
    rep(i,n){
        ll b=t[i].first,l=t[i].second.first,r=t[i].second.second,m=0;
        if (q_<b) m+=l*q_;
        else m+=l*b+r*(q_-b);

        if (used[i]) m+=p_sort[p_].first-p[i];
        //cout << i << " " << res+m << endl;
        a=max(a,m);
    }
    //cout << k << " " << p_ << " " << q_ << " " << a+res << endl; 
    if (a+res>=B) return true;
    return false;
}

void solve(){
    cin >> n >> x;
    rep(i,n){
        ll b,l,r;
        cin >> b >> l >> r;
        B+=l*b;
        t.push_back(PP(b,LP(l,r)));
        p.push_back(b*l+(x-b)*r);
        p_sort.push_back(LP(b*l+(x-b)*r,i));
    }
    //cout << B << endl;
    sort(p_sort.begin(),p_sort.end(),greater<LP>());
    seg=LP(-1,n*x);
    while (seg.first+1<seg.second){
        ll l=seg.first,r=seg.second;
        //cout << l << " " << r << endl;
        if (calc((l+r)/2)) seg=LP(l,(l+r)/2);
        else seg=LP((l+r)/2,r);
        
    }
    cout << seg.second << endl;
}

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

Measured memory_bytes: 6952
#include <iostream>
#include <vector>
 
using ull = unsigned long long;
using ll = long long;
 
// 1になっている最上位ビットを求める
ull getmsb( ull x )
{
	x |= ( x >> 1  );
	x |= ( x >> 2  );
	x |= ( x >> 4  );
	x |= ( x >> 8  );
	x |= ( x >> 16 );
	x |= ( x >> 32 );
 
	return ( x ^ ( x >> 1 ) );
}
 
// 1の数を求める
ull popcnt( ull x )
{
    ull t = 0;
    t = ( x & 0x5555555555555555 ) + ( ( x >> 1  ) & 0x5555555555555555 );
    t = ( t & 0x3333333333333333 ) + ( ( t >> 2  ) & 0x3333333333333333 );
    t = ( t & 0x0f0f0f0f0f0f0f0f ) + ( ( t >> 4  ) & 0x0f0f0f0f0f0f0f0f );
    t = ( t & 0x00ff00ff00ff00ff ) + ( ( t >> 8  ) & 0x00ff00ff00ff00ff );
    t = ( t & 0x0000ffff0000ffff ) + ( ( t >> 16 ) & 0x0000ffff0000ffff );
    t = ( t & 0x00000000ffffffff ) + ( ( t >> 32 ) & 0x00000000ffffffff );
 
    return ( t );
}
 
// 1になったビットがLSB側から何ビット目かを求める
ull tzcnt( ull x )
{
	return ( popcnt( ~x & ( x - 1 ) ) );
}

template<typename T> bool chmax( T &a, T b ) { if ( a < b ) { a = b; return ( true ); } else { return ( false ); } }
 
int main()
{
	ll N, K;
	std::cin >> N >> K;
 
	std::vector<ll> v( N );
	for ( int i = 0; i < N; i++ )
	{
		std::cin >> v[i];
	}

	std::vector<std::vector<ll> > dp( 128, std::vector<ll>( 2, -1 ) );
	dp[0][0] = 0;

	for ( int i = 0; i < 64; i++ )	//	上からi桁目の0/1を決める
	{
		ll d = 64 - ( i + 1 );
		ll num = 0;
		for ( int j = 0; j < N; j++ )
		{
			if ( v[j] & ( 1LL << d ) )
			{
				num++;
			}
		}

		// d桁目が0の場合、1の場合それぞれの結果
		ll cost0 = num * ( 1LL << d );
		ll cost1 = ( N - num ) * ( 1LL << d );

		if ( dp[i][1] != -1 )
		{
			// 0/1をGreedyに決めて良い
			chmax( dp[i + 1][1], dp[i][1] + std::max( cost0, cost1 ) );
		}

		if ( dp[i][0] != -1 )
		{
			// Kのiビット目が1だったら、Xのiビット目は0にする
			if ( K & ( 1LL << d ) )
			{
				chmax( dp[i + 1][1], dp[i][0] + cost0 );
			}
		}

		if ( dp[i][0] != -1 )
		{
			// KとXのiビット目を合わせる
			if ( K & ( 1LL << d ) )
			{
				chmax( dp[i + 1][0], dp[i][0] + cost1 );
			}
			else
			{
				chmax( dp[i + 1][0], dp[i][0] + cost0 );
			}
		}
	}

	std::cout << std::max( dp[64][0], dp[64][1] ) << std::endl;

	return ( 0 );
}


Measured memory_bytes: 1400
#include<cstdio>
#include <iostream>
#include<algorithm>
#include<string>
#include<queue>
#include<vector>
#include<functional>
#include<cmath>
#include<map>
#include<stack>
#include<list>
#include<set>
#include<numeric>

#define MOD 1000000007

using namespace std;
typedef long long ll;

const ll INF = 100000000;
int N, M;
char field[100][100];

int check(int x, int y) {
	int cnt=0;
	for (int i = 0; i < x; i++) {
		for (int j = 0; j < M; j++) 
			if (field[i][j] != 'W')cnt++;
	}
	for (int i = x; i < x+y; i++) {
		for (int j = 0; j < M; j++) 
			if (field[i][j] != 'B')cnt++;
	}
	for (int i = x+y; i < N; i++) {
		for (int j = 0; j < M; j++) 
			if (field[i][j] != 'R')cnt++;
	}
	return cnt;
}

int main() {
	cin >> N >> M;

	for (int i = 0; i < N; i++)
		cin >> field[i];

	int ans = INF;
	for (int i = 1; i <= N-2; i++) {
		for (int j = 1; j <= N-2; j++) {
			if(i+j < N)
			ans = min(ans,check(i, j));
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3040
// Author: Vamsi Krishna Reddy Satti
// With love for Competitive Programming!
 
#include <bits/stdc++.h>
using namespace std;
 
#define fast_io ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
#define cout_precision cout.setf(ios::fixed); cout.precision(32);
 
using ll = int64_t; using vll = vector<ll>; using vvll = vector<vll>;
using pll = pair<ll, ll>; using vpll = vector<pll>; using vvpll = vector<vpll>;
using ld = long double;
 
// ------------------------------------------------------------------------------------------------

ll a, b;
string s;

int main() {
    fast_io; cout_precision;
    cin >> s;
    a = 0, b = s[0] - '0';
    for (ll i = 1, p = 2; i < ll(s.length()); i++, p <<= 1) {
        a = 2 * a + b;
        b = 10 * b + p * (s[i] - '0');
    }
    cout << a + b << endl;
}

Measured memory_bytes: 256
#![allow(unused_imports)]
use std::cmp::*;
use std::collections::*;
use itertools::Itertools;
use num_traits::clamp;
use ordered_float::OrderedFloat;
use proconio::{input, marker::*, fastout};
use superslice::*;

#[fastout()]
fn main() {
    input! {
        n: usize, a: [usize; n]
    }

    let mut ans = 0;
    for i in 0..n {
        let ii = i + 1;
        if ii % 2 == 1 && a[i] %2 == 1 {
            ans += 1;
        }
    }
    println!("{}", ans);
}


Measured memory_bytes: 2200
process.stdin.resume();
process.stdin.setEncoding('utf8');
process.stdin.on('data',function(chunk){

var inputs = chunk.toString().trim();
var data = inputs.toString().split(' ').map(Number);

var a = data[0];
var b = data[1];
var c = data[2];
var count = 0;

for(var i = a; i < b+1 ; i++){

if(c % i === 0){
    count++;
  }
 }
console.log(count);
});

Measured memory_bytes: 15592
#include<stdio.h>
int main (){
  int a,b,x;
  scanf(" %d",&x);
  scanf(" %d",&a);
  scanf(" %d",&b);
  int sum=x-a;
  int i=0;

  do {
    i++;
    if(sum-b*i<0)break;
  } while(1);

  printf("%d\n",sum-b*(i-1));




  return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define lper(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9+10;
const ll INF=4e18;
const ll dy[4]={1,0,-1,0};
const ll dx[4]={0,-1,0,1};
int main(){
    ll A,B,M;cin>>A>>B>>M;
    vl a(A),b(B),nb(B);
    rep(i,A)cin>>a[i];
    rep(i,B){
        cin>>b[i];
        nb[i]=b[i];
    }
    sort(all(nb));
    map<ll,pl> info;
    rep(i,M){
        ll x,y,c;cin>>x>>y>>c;
        x--,y--;
        if(info.count(x)){
            if(b[info[x].fi]-info[x].se>b[y]-c)info[x]={y,c};
        }
        else{
            info[x]={y,c};
        }
    }
    ll ans=INF;
    rep(i,A){
        ll now=0;
        now+=a[i];
        if(info.count(i))now+=min(nb[0],b[info[i].fi]-info[i].se);
        else now+=nb[0];
        ans=min(ans,now);
    }
    cout<<ans<<endl;
    return 0;
}

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

int main() {
  string S;
  map<string, int> M;
  M["MON"] = 6;
   M["TUE"] = 5;
  M["WED"] = 4;
    M["THU"] = 3;
    M["FRI"] = 2;
    M["SAT"] = 1;
    M["SUN"] = 7;
  cin >> S;
  cout << M[S] << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>

using namespace std;

int main()
{
	
	while (1)
	{
		string x;
		getline(cin, x);
		if (x == "0")
			break;
		
		int sum = 0;
		for (int i = 0; i < x.size(); i++)
		{
			sum += (x[i] - '0');
		}
		cout << sum << endl;

	}
	
	return 0;
}

Measured memory_bytes: 1184
import bisect
import sys

sys.setrecursionlimit(200000)


def input():
    return sys.stdin.readline()[:-1]


def ii(t: type = int):
    return t(input())


def il(t: type = int):
    return list(map(t, input().split()))


def imi(N: int, t: type = int):
    return [ii(t) for _ in range(N)]


def iml(N: int, t: type = int):
    return [il(t) for _ in range(N)]


def solve():
    N, a, b = il()
    return "{} {}".format(min(a, b), max(0, a - (N - b)))


if __name__ == "__main__":
    print(solve())


Measured memory_bytes: 3188
#include<cstdio>
#include<iostream>
#define maxn 1000000
using namespace std;

int n; 
int bucket[maxn],maxx,ans,cnt;

int main(){
	scanf("%d",&n);
	
	if(n == 1){
		printf("1");
		return 0;
	}
	for(int i = 1;i <= n;i++){
		scanf("%d",&cnt);
		if(cnt == 0) bucket[0]++,bucket[2]--;
		else bucket[cnt-1]++,bucket[cnt+2]--;
		maxx = max(cnt+2,maxx);
	}
	
	cnt = 0,ans = 0;
	for(int i = 0;i <= maxx;i++){
		cnt += bucket[i];
//		printf("%d ",bucket[i]);
		ans = max(cnt,ans);
	}
	
	
	
	printf("%d",ans);
	
	return 0;
} 

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

int main() {
    string stations;
    cin >> stations;
    char station = 's';
    string ans;
    for(char c: stations){
        if(station != 's' && station != c)
        {
            ans = "Yes";
            break;
        };
        station = c;
        ans = "No";
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cmath>
#include<algorithm>
#define cq(i,s,n) for(int i=s;i<=n;i++)
using namespace std;
const double eps=1e-12;
struct Point{
    double x,y;
}a[500005];
Point o;
int n; 
double ri;
double dis(Point a,Point b){
    return sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y)); 
}

void tt(Point p1,Point p2,Point p3){
    double a,b,c,d,e,f;
    a=p2.y-p1.y;
    b=p3.y-p1.y;
    c=p2.x-p1.x;
    d=p3.x-p1.x;
    f=p3.x*p3.x+p3.y*p3.y-p1.x*p1.x-p1.y*p1.y;
    e=p2.x*p2.x+p2.y*p2.y-p1.x*p1.x-p1.y*p1.y;
    o.x=(a*f-b*e)/(2*a*d-2*b*c);
    o.y=(d*e-c*f)/(2*a*d-2*b*c);
    ri=dis(o,p1);
}

int main(){
    scanf("%d",&n);
    cq(i,1,n){
        scanf("%lf%lf",&a[i].x,&a[i].y);
    }
    random_shuffle(a+1,a+n+1);
    o=a[1];ri=0;
    cq(i,2,n){
        if(dis(a[i],o)>ri+eps){
            o=a[i];ri=0;
            cq(j,1,i-1){
                if(dis(o,a[j])>ri+eps){
                    o.x=(a[i].x+a[j].x)/2;
                    o.y=(a[i].y+a[j].y)/2;
                    ri=dis(o,a[j]);
                    cq(k,1,j-1){
                        if(dis(o,a[k])>ri+eps){
                            tt(a[i],a[j],a[k]);
                        }
                    }
                }
            }
        }
    }
    printf("%.10lf\n",ri);
    return 0;
}

Measured memory_bytes: 256
package main

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

var reader = bufio.NewReaderSize(os.Stdin, 1000000)
var writer = bufio.NewWriter(os.Stdout)
func NextLine() string {
  var line, buffer []byte
  var isPrefix bool = true
  var err error
  for isPrefix {
    line, isPrefix, err = reader.ReadLine()
    if err != nil { panic(err) }
    buffer = append(buffer, line...)
  }
  return string(buffer)
}
func NextInt() int {
  var n int
  n, _ = strconv.Atoi(NextLine())
  return n
}
func Write(s interface{}) {
  fmt.Fprintln(writer, s)
}
func Output() {
  _ = writer.Flush()
}

func main() {
  N := NextInt()
  S := make([]string, N + 1)
  Write(0)
  Output()
  ret := NextLine()
  if ret != "Vacant" {
    S[0] = ret
    S[N] = ret
    high := N + 1
    low := 0
    for i := 0; i < 20; i++ {
      m := (high + low) / 2
      Write(m)
      Output()
      ret = NextLine()
      if ret == "Vacant" { break }
      S[m] = ret
      if (m - low) % 2 == 1 {
        if S[m] == S[low] {
          high = m
        } else {
          low = m
        }
      } else {
        if S[m] == S[low] {
          low = m
        } else {
          high = m
        }
      }
    }
  }
}

Measured memory_bytes: 1236
local par={}
local rank={}

local function init(n)
    for i=1,n do
        par[i]=i
        rank[i]=1
    end
end

local function root(x)
    return par[x]==x and x or root(par[x])
end

local function same(x,y)
    return root(x)==root(y)
end

local function unite(x,y)
    x=root(x)
    y=root(y)
    if x==y then
        return
    end
    if rank[x]>rank[y] then
        x,y=y,x
    end
    par[x]=y
    rank[y]=rank[y]+rank[x]
end

local function size(x)
    return rank[root(x)]
end

local n,m,k=io.read("n","n","n")

init(n)

local graph={}
for i=1,n do
    graph[i]={}
end
for i=1,m do
    local a,b=io.read("n","n")
    table.insert(graph[a],b)
    table.insert(graph[b],a)
    unite(a,b)
end
for i=1,k do
    local c,d=io.read("n","n")
    if same(c,d) then
        table.insert(graph[c],d)
        table.insert(graph[d],c)
    end
end

for i=1,n do
    local kouho=size(i)-#graph[i]-1
    io.write(kouho.." ")
end
print()

Measured memory_bytes: 15976
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#define MAX_LEN 1001

int dataset;
char str_X[MAX_LEN];
char str_Y[MAX_LEN];

void LCSLength(char *X, char *Y){
  int m,n;
  int **c;
  int i,j;

  m = strlen(X);
  c = malloc(sizeof(int*) * (m+1));
  n = strlen(Y);
  for(i=0; i<=m; i++){
    c[i] = malloc(sizeof(int) * (n+1));
  }
  for(i=1; i<=m; i++){
    c[i][0] = 0;
  }
  for(j=0; j<=n; j++){
    c[0][j] = 0;
  }
  for(i=1; i<=m; i++){
    for(j=1; j<=n; j++){
      if(X[i-1]==Y[j-1]){
        c[i][j] = c[i-1][j-1] + 1;
      }else if(c[i-1][j] >= c[i][j-1]){
        c[i][j] = c[i-1][j];
      }else{
        c[i][j] = c[i][j-1];
      }
    }
  }
  printf("%d\n",c[m][n]);
}

int main() {
  int i;

  scanf("%d",&dataset);
  for(i=0; i<dataset; i++){
    scanf("%s",str_X);
    scanf("%s",str_Y);
    LCSLength(str_X, str_Y);
  }
  return 0;
}



Measured memory_bytes: 80380
/*
	  - - 
这次如果Ac我吃土 
*/ 
#include <iostream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <stack>
#include <queue>
#include <algorithm>
#include <set>
#include <map>
#define pb push_back
#define mp make_pair
#define INF 9999999
#define LINF 9999999999999999
#define SINF "%"
#define uint unsigned int
#define msn(a,v) memset(a,v,sizeof(a))
#define ms(a) msn(a,0)
#define NONE -1
#define ll long long
#define ull unsigned ll
#define uchar unsigned char
#define sint short int
#define usint unsigned sint
#define xsize(a) sizeof(a)/1024/1024
#define fr(aaaaa,bbbbb) for(aaaaa = 1;aaaaa <= bbbbb;aaaaa++)
#define frr(aaaaa,bbbbb,ccccc) for(aaaaa = ccccc;aaaaa <= bbbbb;aaaaa++)
using namespace std;
#define MAXN 100100
#define MOD 1000000007

ll n,a,b;
ll data[MAXN];
ll dp[MAXN]; 

int main(){
	//freopen("C.txt","r",stdin);
	data[0] = -1000000000000000000;
	
	scanf("%lld %lld %lld",&n,&a,&b);
	if(a > b) swap(a,b);
	for(int i = 1;i <= n;i++)
		scanf("%lld",&data[i]);
	
	for(int i = 1;i <= n-2;i++)
		if(data[i+2] - data[i] < a){
			printf("0\n");
			return 0;
		}
	ms(dp);
	dp[0] = 1;
	ll now = 0;
	ll lastpos = 0;
	for(int i = 1;i <= n;i++){
		//在 (0,i] 之间找到最小的lastpos,使data[i]和data[lastpos]不可以被同时放到Y中 
		for(;lastpos < i  &&  data[i] - data[lastpos] >= b;lastpos++){
			now += dp[lastpos];
			if(now >= MOD) now -= MOD;
		}
		dp[i] = now;
		if(data[i] - data[i-1] < a){
			now = 0;
			lastpos = i-1;
		}
	}
	
	for(int i = lastpos;i <= n;i++){
		now += dp[i];
		if(now >= MOD) now -= MOD;
	}
	
	printf("%lld\n",now);
	
	return 0;
}

Measured memory_bytes: 1792
import os
import sys

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

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

N, M = list(map(int, sys.stdin.buffer.readline().split()))
SC = [list(map(int, sys.stdin.buffer.readline().split())) for _ in range(M)]

ans = 10 ** (N - 1)
E = 10 ** N


def test(n):
    if len(str(n)) != N:
        return False
    ok = True
    for s, c in SC:
        ok &= str(n)[s - 1] == str(c)
    return ok


i = 0
for i in range( 10 ** N):
    if test(i):
        print(i)
        exit()
print(-1)


Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
#define int long long
int n,e[100001][3],max_happiness[100001][3],k;
int maxhappiness(int i, int d)
{
    if(i==n) return 0;
    if(max_happiness[i][d]==-1) max_happiness[i][d]=max(e[i][d]+maxhappiness(i+1,(d+1)%3),e[i][d]+maxhappiness(i+1,(d+2)%3));
    return max_happiness[i][d];
}
int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    /*#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif*/
    cin>>n;
    for(int i=0;i<n;i++) for(int j=0;j<3;j++) cin>>e[i][j];
    for(int i=0;i<n;i++) for(int j=0;j<3;j++) max_happiness[i][j]=-1;
    int a=maxhappiness(0,0);
    for(int i=0;i<n;i++) for(int j=0;j<3;j++) max_happiness[i][j]=-1;
    int b=maxhappiness(0,1);
    for(int i=0;i<n;i++) for(int j=0;j<3;j++) max_happiness[i][j]=-1;
    int c=maxhappiness(0,2);
    cout<<max(a,max(b,c));
    return 0;
}

Measured memory_bytes: 11264
#include <bits/stdc++.h>
using namespace std;
 
int skor[100005], n, q, k, a;
int main()
{
    cin >> n >> k >> q;
    for (int i = 1; i <= n; i++){
        skor[i] = k - q;
    }
    for (int i = 1; i <= q; i++){
        cin >> a;
        skor[a]++;
    }
    for (int i = 1; i <= n; i++){
        if (skor[i] > 0)
        {
            cout << "Yes" << endl;
        }
        else
        {
            cout << "No" << endl;
        }
    }
}
//hia

Measured memory_bytes: 1024
import java.util.Scanner;

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

	int N = scan.nextInt();

	int min = Integer.MAX_VALUE;

	for(int i = 1; i < N; i++){
	    int A = i;
	    int B = N-i;
	    int num = 0;
	    while(A > 0){
		num += A%10;
		A /= 10;
	    }
	    while(B > 0){
		num += B%10;
		B /= 10;
	    }

	    if(num < min){
		min = num;
	    }
	}

	System.out.println(min);
    }
}


Measured memory_bytes: 21844
{-# LANGUAGE MultiParamTypeClasses,FlexibleContexts,FlexibleInstances,TypeSynonymInstances,BangPatterns,RankNTypes,TupleSections #-}
import Control.Monad
import Control.Monad.ST
import Control.Applicative
import Control.Arrow
import Debug.Trace
import Text.Printf

import Data.List
import Data.Int
import Data.Bits
import Data.Maybe
import Data.Monoid
import Data.Array.Unboxed
import Data.Array.ST
import Data.Array.Base
import Data.Function(on)
import Data.Tuple(swap)
import qualified Data.Map as M
import qualified Data.Set as S
import qualified Data.ByteString.Char8 as B

main :: IO ()
main = do
    (a,b) <- readIntPair
    if inRange (a,b) 0 then
        putStrLn "Zero"
    else if a > 0 || odd (b - a) then
        putStrLn "Positive"
    else
        putStrLn "Negative"

-- IO
readInt :: B.ByteString -> Int
readInt = fromJust . fmap fst . B.readInt
readInts :: IO [Int]
readInts = map readInt . B.words <$> B.getLine
readIntPair :: IO (Int,Int)
readIntPair = l2p . map readInt . take 2 . B.words <$> B.getLine
readAllInts :: IO [[Int]]
readAllInts = map (map readInt . B.words) . B.lines <$> B.getContents
readLns :: Read a => IO [a]
readLns = map read . words <$> getLine

-- Utilities
l2p :: [a] -> (a,a)
l2p (a:b:_) = (a,b)
l2p _ = error "l2p: the input list is too short"
p2l :: (a,a) -> [a]
p2l (a,b) = [a,b]
itof :: Int -> Double
itof = fromIntegral
inf :: Int
inf = maxBound `div` 2

-- Monad
stepM_ :: Monad m => a -> (a -> Bool) -> (a -> a) -> (a -> m ()) -> m ()
stepM_ i0 judge incr step = sub i0 where 
    sub i | judge i = step i >> sub (incr i) 
          | otherwise = return ()
rep_ :: Monad m => Int -> (Int -> m ()) -> m ()
rep_ n = stepM_ 0 (<n) (+1)
thru :: Monad m => (v -> m ()) -> v -> m v
thru m v = m v >> return v
memoize :: (Monad m) => (k -> m (Maybe v)) -> (k -> v -> m ()) -> k -> m v -> m v
memoize getter setter key action = do
    mv <- getter key
    case mv of
        Just v -> return v
        Nothing -> action >>= thru (setter key)

-- Array
newUArray :: (MArray (STUArray s) e (ST s),Ix i) => 
             (i,i) -> e -> ST s (STUArray s i e)
newUArray = newArray
newBArray :: (Ix i) => (i,i) -> e -> ST s (STArray s i e)
newBArray = newArray
defaultArray :: (IArray a e,Ix i) => e -> (i,i) -> [(i,e)] -> a i e
defaultArray = accumArray $ curry snd
fromEdges :: Ix i => (i,i) -> [(i,e)] -> Array i [e]
fromEdges = accumArray (flip (:)) []


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

using namespace std;
typedef long long int ll;
typedef pair<ll, ll > pi;  
typedef pair<pair<ll, ll >, ll > pii;  
vector<ll > vec;
vector<vector<ll > > vec2;
ll MOD = 1000000007;
ll INF = 1145141919454519;

//気持ち偶数奇数で分けるとわかる気がしたが証明がわらず...
int main() {

    ll N, M;
    cin >> N >> M;

    map<ll, ll> mp;
    for(ll i = 0; i < M; i++){
        ll a, b; cin >> a >> b;
        mp[a]++;
        mp[b]++;
    }

    auto begin = mp.begin(), end = mp.end();
    for (auto iter = begin; iter != end; iter++) {
        if(iter -> second % 2 == 1){
            cout << "NO" << endl;
            return 0;
        }
    }

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

}

Measured memory_bytes: 5632
s=input()
t=[]
c=200
f=0
for i in range(len(s)):
  if s[i]=="C" and c>i:
    c=i
  elif s[i]=="F" and f<i:
    f=i

if c<f:
  print("Yes")
else:
  print("No")
    
    

  

Measured memory_bytes: 2940
n, m = map(int, input().split())
a = [int(input()) for i in range(m)]

cnt = 0
dp_table = [0 for i in range(n + 10)]
dp_table[0] = 1
dp_table[1] = 1

for i in range(m):
    dp_table[a[i]] = -10 ** 9 + 7

for i in range(2, n + 10):
    if dp_table[i] > -1:
        dp_table[i] = (max(dp_table[i - 1], 0) + max(dp_table[i - 2], 0)) % (10 ** 9 + 7)

print(dp_table[n])

Measured memory_bytes: 7856
using System;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using static System.Console;
class Program
{
    static void Main()
    {
        //入力
        //int[] input = Console.ReadLine().Split().Select(i => int.Parse(i)).ToArray();
        //string input= Console.ReadLine();
        int input =int.Parse(Console.ReadLine());
        Console.WriteLine(Math.Ceiling((double)input/2)*Math.Floor((double)input/2));


        /*
        //処理速度計測
        var sw = new System.Diagnostics.Stopwatch();
        sw.Start();
        //解法
 
        //処理速度表示
        sw.Stop();
        TimeSpan ts = sw.Elapsed;
        Console.WriteLine((int)(Math.Floor((ts).TotalMilliseconds))+"ms");
        */
        Console.ReadLine();

    }
}

Measured memory_bytes: 11092
#include<bits/stdc++.h>
using namespace std;
void pre(){}
void solve(){
    long long int k,n;cin>>k>>n;
    long long int arr[n];
    for(long long int i=0;i<n;i++)
        cin>>arr[i];
    long long int dp[n];
    for(long long int i=0;i<n-1;i++){
        dp[i]=arr[i+1]-arr[i];
    }    
    dp[n-1]=k-arr[n-1]+arr[0];
    sort(dp,dp+n);
    long long int ans =0;
    for(long long int i=0;i<n-1;i++){
        ans+=dp[i];
    }
    cout<<ans<<"\n";
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    pre();
    long long int num = 1;
    //cin>>num;
    for(long long int i=0;i<num;i++){
       	solve();
    }   
}


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

using namespace std;
#define ll long long
#define r(i, n) for(int i=0;i<n;i++)

int main() {
    ll n;
    cin >> n;
    vector<ll> v(n);
    r(i, n)cin >> v[i];
    if (prev_permutation(v.begin(), v.end())) {
        r(i, n) {
            cout << v[i] << " \n"[i == n - 1];
        }
    }
    next_permutation(v.begin(), v.end());
    r(i, n) {
        cout << v[i] << " \n"[i == n - 1];
    }
    if (next_permutation(v.begin(), v.end())) {
        r(i, n) {
            cout << v[i] << " \n"[i == n - 1];
        }
    }

    return 0;
}


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

int main(void) {
    int A1,A2,A3;cin>>A1>>A2>>A3;
    vector<int> vc;
    vc.push_back(abs(A1 - A2) + abs(A2 - A3));
    vc.push_back(abs(A1 - A3) + abs(A2 - A3));
    vc.push_back(abs(A2 - A3) + abs(A3 - A1));
    vc.push_back(abs(A2 - A1) + abs(A3 - A1));
    vc.push_back(abs(A3 - A1) + abs(A1 - A2));
    vc.push_back(abs(A3 - A2) + abs(A2 - A1));
    sort(vc.begin(), vc.end());
    cout << vc.at(0) << endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<set>
using lint=int64_t;
using namespace std;


int64_t pow(int64_t a,int64_t b,int64_t p)
{
	if(b==0)return 1;
	if(b%2==0)
	{
		int64_t d=pow(a,b/2,p);
		return (d*d)%p;
	}else//if(b%2==1)
	{
		return (a*pow(a,b-1,p))%p;
	}
}

/* combination */
// nCr mod p
int64_t comb(int64_t n,int64_t r,int64_t p)
{
	int64_t ret=1;
	for(int64_t i=0;i<r;i++)
	{
		ret*=(n-i);
		ret%=p;
	}
	for(int64_t i=2;i<=r;i++)
	{
		ret*=pow(i,p-2,p);
		ret%=p;
	}
	return ret;
}

#include<vector>
template<typename T>
class UnionFind
{
	public:
	vector<T> parent;
	
	UnionFind(T n):parent(n)
	{
		for(int i=0;i<n;i++)
			parent[i]=i;
	}
	
	void unite(T a,T b)
	{
		a=root(a);
		b=root(b);
		if(a==b)return;
		if(a>b)swap(a,b);
		parent[b]=a;
		return;
	}
	
	T root(T n)
	{
		if(parent[n]==n)
			return n;
		else
		{
			T ret=root(parent[n]);
			parent[n]=ret;
			return ret;
		}
	}
};

const lint mod=1e9;

int main()
{
	lint N,M;
	lint A[100010]={};
	lint B[100010]={};
	
	cin >> N >> M;
	for(lint i=M;i>0;i--)
	{
		cin >> A[i] >> B[i];
		A[i]--;
		B[i]--;
	}
	
	UnionFind<lint> uf(N);
	lint ans[100010]={};
	ans[0]=(N*(N-1))/2;
	lint rsum[100010]={};
	
	for(lint i=0;i<N;i++)
		rsum[i]=1;
	for(lint i=1;i<=M;i++)
	{
		ans[i]=ans[i-1];
		if(uf.root(A[i])==uf.root(B[i]))
			continue;
		
		lint x=max(rsum[uf.root(A[i])],rsum[uf.root(B[i])]);
		x=rsum[uf.root(A[i])]*rsum[uf.root(B[i])];
		lint Minrt=min(uf.root(A[i]),uf.root(B[i]));
		lint Maxrt=max(uf.root(A[i]),uf.root(B[i]));
		
		rsum[Minrt]+=rsum[Maxrt];
		rsum[Maxrt]=0;
		uf.unite(A[i],B[i]);
		ans[i]-=max(x,(lint)0);
	}
	
	for(int i=M-1;i>=0;i--)
	{
		cout << ans[i] << endl;
	}
	return 0;
}



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


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


	string s;
	cin>>s;

	vector<int> a,b;


	for(int i=0;i<n;i++)
	{
		if(s[i]=='o')
		{
			a.push_back(i);
			i=i+c;
		}
	}

	for(int i=n-1;i>=0;i--)
	{
		if(s[i]=='o')
		{
			b.push_back(i);
			i=i-c;
		}
	}

	
	for(int i=0;i<k;i++)
	{
		if(a[i]==b[k-i-1])
			cout<<a[i]+1<<endl;
	}

	return 0;
}

Measured memory_bytes: 5728
#include<bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
#define ll long long
#define ld long double
#define mk make_pair
#define fi first
#define se second
#define vll vector<ll>
#define pii pair<ll,ll>
#define vvll vector< vector<ll> >
#define pb push_back
#define sz(v) (v).size()
#define inf 1e18
#define md 1000000007
#define all(v) (v).begin(),(v).end()
#define rep(i,a,b) for(ll i=a;i<b;++i)
#define tel(a){cout<<a<<"\n";}
#define tell(a,b){cout<<a<<" | "<<b<<"\n";}
#define telll(a,b,c){cout<<a<<" | "<<b<<" | "<<c<<"\n";}
#define teln(v,n){cout<<"v- ";rep(i,0,n)cout<<v[i]<<" ";cout<<"\n";}
#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define tihs if(fopen("inp.txt","r"))freopen("inp.txt", "r", stdin),freopen("out.txt", "w", stdout);
using namespace std;
#define TRACE
 
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif
 

#define M 200010


int main(){
	IOS;
	tihs;
	
	
	ll a[5];
	ll n;cin>>n;
	ll mn=inf;
	rep(i,0,5)cin>>a[i],mn=min(mn,a[i]);
	ll ans=ceil(n/(ld)mn)+4;
	cout<<ans;
	return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h> 
using namespace std;
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define sz(x) (int)(x).size()
typedef vector<int> vi;
// #define ll long long 
#define int long long
#define ld long double
#define fi first
#define se second
#define pb push_back
#define pii pair<int,int>
#define all(x) (x).begin(), (x).end()
const int MOD = 1e9+7;
int mpow(int a,int b,int p=MOD){a=a%p;int res=1;while(b>0){if(b&1)res=(res*a)%p;a=(a*a)%p;b=b>>1;}return res%p;}
const int N=1e5+2;

int32_t main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	int n,m;
	cin>>n>>m;
	if(n==m)
	{
		cout<<"Yes\n";
	}
	else cout<<"No\n";
}
// I never lose. I either win or I learn

Measured memory_bytes: 256
n=int(input())
x=[0]*(n+1)
a=[int(input()) for _ in range(n)]
if a[0]!=0:
  print(-1)
  exit()
for i in range(1,n):
  if a[i]-a[i-1]>1:
    print(-1)
    exit()
res=0
for i in range(1,n):
  if a[i]==a[i-1]+1:
    res+=1
  else:
    res+=a[i]
print(res)

Measured memory_bytes: 12588
#include <bits/stdc++.h>
using namespace std;
template<class t> inline t read(t &x){
	char c=getchar();bool f=0;x=0;
	while(!isdigit(c)) f|=c=='-',c=getchar();
	while(isdigit(c)) x=(x<<1)+(x<<3)+(c^48),c=getchar();
	if(f) x=-x;return x;
}
template<class t> inline void write(t x){
	if(x<0) putchar('-'),write(-x);
	else{if(x>9) write(x/10);putchar('0'+x%10);}
}





char s[1444];

signed main(){
	scanf("%s",s);
	if(s[2]==s[3]&&s[4]==s[5]) puts("Yes");
	else puts("No");
}

Measured memory_bytes: 256
#include <algorithm>
#include <array>
#include <bitset>
#include <complex>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <queue>

using namespace std;

struct Initializer {
  Initializer() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout << fixed << setprecision(15);
  }
} initializer;

template<typename T> istream& operator>>(istream &s, vector<T> &v) {
  for (T &t : v) s >> t;
  return s;
}

template<typename T> ostream& operator<<(ostream &s, const vector<T> &v) {
  for (const T &t : v) s << t << endl;
  return s;
}

int main() {
  string s;
  cin >> s;
  if (s[0] == '0' || s.back() == '1') {
    cout << -1 << endl;
    return 0;
  }
  int n = s.size(), a = 1, b = n;
  for (int i = 0; i < n - 1; ++i) {
    if (s[i] != s[n - 2 - i]) {
      cout << -1 << endl;
      return 0;
    }
  }
  for (int i = 0; i < n - 1; ++i) {
    if (s[i] == '0') {
      cout << a << " " << b << endl;
      --b;
    } else {
      cout << a << " " << a + 1 << endl;
      ++a;
    }
  }
}



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

char F[102][102];

void DFS(int Y,int X,char key){
  if(F[Y][X]!=key)
    return;

  F[Y][X] = '.';

  DFS(Y-1,X,key); //???
  DFS(Y,X+1,key); //???
  DFS(Y+1,X,key); //???
  DFS(Y,X-1,key); //???
}

int main(){
  while(true){
  int N,M;
  cin >> N >> M;
    if(N==0 && M==0)
      break;
  for(int y=1; y<=N; y++)
    for(int x=1; x<=M; x++)
      cin >> F[y][x];

  int count = 0;
  for(int y=1; y<=N; y++){
    for(int x=1; x<=M; x++){
      if(F[y][x]=='@'){
        DFS(y,x,'@');
        count++;
      }else if(F[y][x]=='#'){
        DFS(y,x,'#');
        count++;
      }else if(F[y][x]=='*'){
        DFS(y,x,'*');
        count++;
      }
    }
  }

  cout << count << endl;
  }
  return 0;
}

Measured memory_bytes: 3376
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <numeric>
#include <utility>
#include <tuple>

#define REP(i, a, b) for (int i = int(a); i < int(b); i++)
using namespace std;
using ll = long long int;
using P = pair<ll, ll>;

// clang-format off
#ifdef _DEBUG_
#define dump(...) do{ cerr << __LINE__ << ":\t" << #__VA_ARGS__ << " = "; PPPPP(__VA_ARGS__); cerr << endl; } while(false)
template<typename T> void PPPPP(T t) { cerr << t; }
template<typename T, typename... S> void PPPPP(T t, S... s) { cerr << t << ", "; PPPPP(s...); }
#else
#define dump(...) do{ } while(false)
#endif
template<typename T> vector<T> make_v(size_t a, T b) { return vector<T>(a, b); }
template<typename... Ts> auto make_v(size_t a, Ts... ts) { return vector<decltype(make_v(ts...))>(a, make_v(ts...)); }
template<typename T> bool chmin(T &a, T b) { if (a > b) {a = b; return true; } return false; }
template<typename T> bool chmax(T &a, T b) { if (a < b) {a = b; return true; } return false; }
template<typename T> void print(T a) { cout << a << endl; }
template<typename T, typename... Ts> void print(T a, Ts... ts) { cout << a << ' '; print(ts...); }
template<typename T> istream &operator,(istream &in, T &t) { return in >> t; }
// clang-format on

#include <map>

const int N = 3;
using ARR = array<ll, N>;

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n;
    cin, n;
    ll ans = -n;
    ARR MOD = {{1000000007, 1000000009, 1234567891}};
    ARR Base = {{1007, 1009, 1013}};

    auto nxt = [&](const ARR &arr, char c) {
        ARR a;
        REP(i, 0, N) {
            a[i] = (arr[i] * Base[i] + c) % MOD[i];
        }
        return a;
    };

    map<ARR, vector<ll>> m;
    vector<string> v(n);
    REP(i, 0, n) {
        cin, v[i];
        reverse(v[i].begin(), v[i].end());
    }

    REP(i, 0, n) {
        ARR arr = {0, 0, 0};
        REP(j, 0, v[i].size() - 1) {
            arr = nxt(arr, v[i][j]);
        }
        int last = v[i].back() - 'a';
        if (!m.count(arr)) {
            m[arr] = vector<ll>(26, 0);
        }
        m[arr][last]++;
    }

    REP(_, 0, n) {
        string s = v[_];
        vector<int> mp(26, 0);
        int sz = s.size();
        REP(i, 0, sz) {
            mp[s[i] - 'a']++;
        }
        ARR a = {0, 0, 0};
        REP(i, 0, sz + 1) {
            if (m.count(a)) {
                auto &mcp = m[a];
                REP(j, 0, 26) {
                    if (mcp[j] && mp[j]) {
                        ans += mcp[j];
                    }
                }
            }
            if (i != sz) {
                mp[s[i] - 'a']--;
                a = nxt(a, s[i]);
            }
        }
    }
    print(ans);

    return 0;
}


Measured memory_bytes: 52752
#include "bits/stdc++.h"
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000


int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int A, B, C;
    cin >> A >> B >> C;
    if (A + B + C >= 22) {
        cout << "bust" << endl;
    } else {
        cout << "win" << endl;
    }

    return 0;
}


Measured memory_bytes: 256
import sys, bisect, math, itertools, string, queue, copy
# import numpy as np
# import scipy
from collections import Counter,defaultdict,deque
from itertools import permutations, combinations
from heapq import heappop, heappush
input = sys.stdin.readline
sys.setrecursionlimit(10**8)
mod = 10**9+7
def inp(): return int(input()) # n=1
def inpm(): return map(int,input().split()) # x=1,y=2
def inpl(): return list(map(int, input().split())) # a=[1,2,3,4,5,...,n]
def inpls(): return list(input().split())  # a=['1','2','3',...,'n']
def inplm(n): return list(int(input()) for _ in range(n)) # x=[] 複数行
def inplL(n): return [list(input()) for _ in range(n)]
def inplT(n): return [tuple(input()) for _ in range(n)]
def inpll(n): return [list(map(int, input().split())) for _ in range(n)] # [[2,2,2,2],[1,1,1,1],[3,3,3,3]] 
def inplls(n): return sorted([list(map(int, input().split())) for _ in range(n)]) # [[1,1,1,1],[2,2,2,2],[3,3,3,3]] 
def graph():
    n=inp()
    g=[[] for _ in range(n)]
    for i in range(n):
        a = inp()
        a -= 1
        g[i].append(a)
        g[a].append(i)
    return n,g

def f(n):
    sumation = 0
    while n > 0:
        sumation += n%10
        n //= 10
    return sumation

def main():
    k = inp()
    a = inpl()
    a.reverse()
    x,y = 2,2
    for i in range(k):
        pair = a[i]
        if y < pair:
            print(-1)
            return
        if (y//pair)*pair < x:
            print(-1)
            return
        if pair >= x:
            x = pair
        elif x%pair != 0:
            s = x//pair + 1
            x = s*pair
        y = (y//pair+1) * pair - 1
        if y < x:
            print(-1)
            return
    print(x,y)
    
if __name__ == "__main__":
    main()

Measured memory_bytes: 62312
def topological_sort(V,E_from,E_in):
    IN = [-1]*V
    n = [-1]*V
    for v in range(V):
        IN[v] = len(E_in[v])
        if IN[v] == 0:
            q = [v]
    count = 0
    while q:
        v = q.pop()
        n[v] =  count
        count += 1
        for u in E_from[v]:
            IN[u] -= 1
            if IN[u] == 0:
                q.append(u)
    return n
import heapq
n,m = map(int,input().split())
edge_from = [[] for _ in range(n)]
edge_in = [[] for _ in range(n)]
E = []
for i in range(n+m-1):
    go,to = map(int,input().split())
    go -= 1
    to -= 1
    E.append([go,to])
    edge_from[go].append(to)
    edge_in[to].append(go)
res = topological_sort(n,edge_from,edge_in)
rev = [0]*n
for i in range(n):
    rev[res[i]] = i
reve_from = [[] for _ in range(n)]
reve_in = [[] for _ in range(n)]
for go,to in E:
    resgo = res[go]
    resto = res[to]
    heapq.heappush(reve_from[resgo],-resto)
    heapq.heappush(reve_in[resto],-resgo)
ans = [-1]*n
for i in range(n):
    ans[rev[i]] = rev[-reve_in[i][0]] + 1 if reve_in[i] else 0
for i in ans:
    print(i)

Measured memory_bytes: 85988
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(long long i=0; i<(n); i++)
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(){
    ll h,w; cin>>h>>w;
    vector<string> a(h);
    rep(i,h) cin>>a[i];
    vector<ll> row(h,0), column(w,0);
    rep(i,h){
        bool ifwhite=true;
        rep(j,w){
            if(a[i][j]=='#') ifwhite=false;
        }
        if(ifwhite) row[i]=1;
    }

    rep(j,w){
        bool ifwhite=true;
        rep(i,h){
            if(a[i][j]=='#') ifwhite=false;
        }
        if(ifwhite) column[j]=1;
    }

    rep(i,h){
        if(row[i]==1) continue;
        rep(j,w){
            if(column[j]==1) continue;
            cout<<a[i][j];
        }
        cout<<endl;
    }
    return 0;
}

Measured memory_bytes: 256
n,x,y=map(int,input().split())

x-=1
y-=1
ans=[0]*(n-1)

for i in range(n-1):
    for j in range(i+1,n):
        saisho=j-i
        #x_made=[i-x,j-x]
        #y_made=[i-y,j-y]

        x_kyori=abs(i-x)
        y_kyori=abs(j-y)
        #print(i,j)
        #print(x_kyori+y_kyori+1)
        #print("")
        tikamiti=x_kyori+y_kyori+1
        saisho=min(saisho,tikamiti)
        ans[saisho-1]+=1



for a in ans:
    print(a)

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

using namespace std;

int main(){
  int n;
  cin>>n;
  string ans ="";
  if(n == 0){
    cout<<0<<endl;
    return 0;
  }
  while(true){
    if(n % 2 != 0){
      ans = "1" + ans;
      n--;
      //cout<<n<<endl;
    }else{
      ans = "0" + ans;
    }
    n = n / -2;
    //cout<<n<<endl;
    if(n == 0)
      break;
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 256
import sys
input = sys.stdin.readline

def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))

def main():
    mod=10**9+7
    N=I()
    A=LI()
    S=[0]*(N+1)
    for i in range(N):
        S[i+1]=(S[i]+A[i])%mod
        
    ans=0
    for i in range(N):
        a=A[i]
        s=S[-1]-S[i+1]
        ans=(ans+a*s)%mod
        
    print(ans)
        
        

main()


Measured memory_bytes: 91988
#include <bits/stdc++.h>
using namespace std;
#define ll                 long long
#define ull                unsigned long long
#define ld                 long double
#define fastio             ios_base::sync_with_stdio(false);cin.tie(NULL);
#define NO                 cout << "NO" << endl
#define YES                cout << "YES" << endl
#define vec                vector<ll>
#define pi                 pair<ll, ll>
#define intarr(arr, n)     ll arr[n]; for (ll i = 0; i < n; i++) cin >> arr[i]
#define intvec(v, n)       for (ll i = 0; i < n; i++) { ll x;cin >> x; v.pb(x);}
#define loop(i, a, b, c)   for (ll i = a; i < b; i += c)
#define pb                 push_back
#define mkp                make_pair
#define printarr(a, n, m)  for (ll i = n; i < m; i++) {  cout << a[i] << " "; }  cout << endl
#define printvec(a, n, m)  for (ll i = n; i < m; i++) {   cout << a[i] << " ";   } cout << endl
#define endl               "\n"
#define mod2               998244353
#define mod                1000000007
#define mem(dp, a)         memset(dp, a, sizeof(dp));
#define all(v)             v.begin(), v.end()
#define ump                unordered_map<ll, ll>
#define pair               pair<ll, ll>
#define F                  first
#define S                  second
#define PI                 3.14159265358979323846
#define minh               priority_queue<ll>
#define maxh               priority_queue<ll,vector<ll>,greater<ll>>
#define flush              cout<<flush


ll Ceil(ll a, ll b)
{
  if (a % b == 0)
    return a / b;
  else
    return a / b + 1;
}

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

ll inv(ll a)
{
  ll p = mod;
  ll b = p - 2, ans = 1;
  for (; b > 0; a = a * a % p, b >>= 1)
    if (b & 1)
      ans = ans * a % p;
  return ans;
}

ll ncrmod(ll n, ll m)
{
  ll p = mod;
  if (m > n)
    return 0;
  ll up = 1, down = 1;
  for (ll i = n - m + 1; i < n + 1; i++)
    up *= i, up %= p;
  for (ll i = 1; i < m + 1; i++)
    down *= i, down %= p;
  return up * inv(down) % p;
}

ll powmod(ll a, ll n)
{
  if (!n)
    return 1;
  ll pt = powmod(a, n / 2);
  pt *= pt, pt %= mod;
  if (n & 1)
    pt *= a, pt %= mod;
  return pt;
}

bool SieveOfEratosthenes(ll n)
{
  bool prime[n + 1];
  memset(prime, true, sizeof(prime));

  for (ll p = 2; p * p <= n; p++)
  {
    if (prime[p] == true)
    {
      for (ll i = p * p; i <= n; i += p)
        prime[i] = false;
    }
  }
  return prime[n];
  // for (int p=2; p<=n; p++)
  //    if (prime[p])
  //       cout << p << " ";
}

void solve()
{
   ll n;
   cin>>n;
   n=n%10;
   if(n==2 or n==4 or n==5 or n==7 or n==9){
    cout<<"hon";
   }
   else if(n==0  or n==1 or n==6 or n==8){
    cout<<"pon";
   }
   else if(n==3){
    cout<<"bon";
   }
   return;
 
}


int main()
{
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif

  fastio;
  ll t;
  t = 1;
  //cin >> t;
  while (t--)
  {
    solve();
  }

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

  return 0;
}

Measured memory_bytes: 3656
#include <iostream>
#include <cmath>
int main(){
        int N,A,B,P[100];
        std::cin>> N >> A >> B;
        for(int i=0; i<N; i++) {
                std::cin >> P[i];
        }
        int p1=0,p2=0,p3=0;
        for(int i=0; i<N; i++) {
                if(P[i]<=A) p1++;
                else if(P[i]<=B) p2++;
                else p3++;
        }
        std::cout << std::min(p1,std::min(p2,p3));
        return 0;
}


Measured memory_bytes: 256
#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdio>
#include<cmath>
#define LL long long
#define mod 998244353
#define inv2 499122177
#define M 1000020
using namespace std;
namespace IO{
	int Top=0; char SS[20];
	void write(int x){
		if(!x){putchar('0');return;} if(x<0) x=-x,putchar('-');
		while(x) SS[++Top]=x%10,x/=10;
		while(Top) putchar(SS[Top]+'0'),--Top;
	}
	int read(){
		int nm=0,fh=1; char cw=getchar();
		for(;!isdigit(cw);cw=getchar()) if(cw=='-') fh=-fh;
		for(;isdigit(cw);cw=getchar()) nm=nm*10+(cw-'0');
		return nm*fh;
	}
}using namespace IO;
int mul(int x,int y){return (LL)x*(LL)y%mod;}
int add(int x,int y){return (x+y>=mod)?x+y-mod:x+y;}
int mus(int x,int y){return (x-y<0)?x-y+mod:x-y;}
int qpow(int x,int sq){
	int res=1;
	for(;sq;sq>>=1,x=mul(x,x)) if(sq&1) res=mul(res,x);
	return res;
}
int n,m,fac[M],ifac[M],ans;
int C(int tot,int tk){return mul(fac[tot],mul(ifac[tot-tk],ifac[tk]));}
int main(){
	n=read(),m=read(),fac[0]=1; if(n>m) swap(n,m);
	for(int i=1;i<=n+m;i++) fac[i]=mul(fac[i-1],i); ifac[n+m]=qpow(fac[n+m],mod-2);
	for(int i=n+m;i;i--) ifac[i-1]=mul(ifac[i],i); 
	for(int i=1;i<=n;i++) ans=add(ans,mul(C(i<<1,i),C(n+m-(i<<1),n-i)));
	write(add(mul(ans,mul(inv2,qpow(C(n+m,m),mod-2))),m)),putchar('\n'); return 0;
}

Measured memory_bytes: 8064
s = input()
s = s.replace("BC","D")
count_Sum = 0
countA = 0
countD = 0

for i in range(len(s)):
    if s[i] == "A" and countD == 0:
        countA += 1
    elif s[i] == "D":
        countD += 1
        if i+1 == len(s):
            count_Sum += countA*countD
    else:
        count_Sum += countA*countD
        if s[i] == "B" or s[i] =="C":
            countA = 0
            countD = 0
        else:
            countA += 1
            countD = 0
print(count_Sum)

Measured memory_bytes: 3500