akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<string>
#include<string.h>
#include<math.h>
#include<stdlib.h>
#include<vector>
#include<queue>
#include<map>
#include<iomanip>
#include<set>
#define rep(index,num) for(int index=0;index<num;index++)
#define rep1(index,num) for(int index=1;index<=num;index++)
#define scan(argument) cin>>argument
#define prin(argument) cout<<argument<<endl
#define kaigyo cout<<endl
#define eps 1e-7
#define mp(a1,a2) make_pair(a1,a2)
typedef long long ll;
typedef long double ld;
using namespace std;
typedef pair<ll,ll> pll;
typedef pair<int,int> pint;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<pint> vpint;
typedef vector<pll> vpll;
ll INFl=1e+18+1;
int INF=1e+9+1;
int main(){
	int N,Q;
	string S;
	char t[200001],d[200001];
	vint iti[26];
	scan(N>>Q);scan(S);
	rep(i,N) iti[S[i]-'A'].push_back(i);
	rep(i,Q){
		string T,D;
		scan(T>>D);
		t[i]=T[0],d[i]=D[0];
	}
	int ln=0,rn=N-1;
	char la='1',ra='1';
	int oti=0;
	for(int i=Q-1;i>=0;i--){
		if(ln<N&&t[i]==S[ln]&&d[i]=='L'){
			la=S[ln];
			ln++;
		}
		else if(t[i]==la&&d[i]=='R'){
			ln--;
			la=(ln==0 ? '1' : S[ln-1]);
		}
		//printf("i:%d ln:%d la:%c\n",Q,ln,la);
	}
	for(int i=Q-1;i>=0;i--){
		if(rn>=0&&t[i]==S[rn]&&d[i]=='R'){
			ra=S[rn];
			rn--;
		}
		else if(t[i]==ra&&d[i]=='L'){
			rn++;
			ra=(rn==N-1 ? '1' : S[rn+1]);
		}
		//printf("i:%d rn:%d ra:%c\n",Q,rn,ra);
	}
	oti=ln+(N-1-rn);
	prin(N-oti);
	return 0;
}


Measured memory_bytes: 1908
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <deque>
#include <queue>
#include <string.h>
#include <stack>
using namespace std;
#define rep(i, a, b) for(int i = a; i < (b); ++i)
typedef long long ll;
typedef pair<int,int> P;
int main() {
    int a,b;
    cin >> a >> b;
    ll ans = b;
    rep(i, 0, a-1){
        ans *= b-1;
    }
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 3612
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rrep(i,n) for(int (i)=((n)-1);(i)>=0;(i)--)
#define itn int
#define all(x) (x).begin(),(x).end()
#define F first
#define S second
const long long INF = 1LL << 60;
const int MOD = 1000000007;
signed main(void){
    int n; cin>>n;
    vector <int> a(n); 
    vector <int> b(n); 
    priority_queue <pair<int,int>> pq;
    rep(i,n) cin>>a[i];
    rep(i,n) {cin>>b[i]; pq.push({b[i], i});}
    int ans = 0;
    while(!pq.empty()){
        auto now = pq.top(); pq.pop();
        int i = now.S;
        int mid = now.F, r = b[(i-1 <0) ? n-1: i-1], l = b[(i+1)%n];
        if(a[now.S] == mid) continue;
        if(mid < a[i]) {cout<<-1<<endl; return 0;}
        int k = (b[i]-a[i])/(r+l);
        if(k==0) {cout<<-1<<endl; return 0;}
        ans += k;
        mid -= k*(r+l);
        b[i] = mid;
        pq.push({b[i], i});
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 9328
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N = INT()
H = LIST()

MAX = H[0]
ans = 1
for i in range(1, N):
	if H[i] >= MAX:
		MAX = H[i]
		ans += 1

print(ans)

Measured memory_bytes: 5148
#pragma GCC optimize("O3", "unroll-loops")

#define _USE_MATH_DEFINES
#include <bits/stdc++.h>

using namespace std;

#define ll long long
#define ld long double

struct edge {
	int l, r; ll c;
};

signed main() {
	int n, m; cin >> n >> m;
	vector<edge> g(m);
	for (int i = 0; i < m; ++i)
		cin >> g[i].l >> g[i].r >> g[i].c;
	vector<vector<edge>> fin(n + 1);
	for (int i = 0; i < m; ++i) {
		fin[g[i].r].push_back(g[i]);
	}
	for (int i = 0; i < n; ++i) {
		sort(
			fin[i].begin(), fin[i].end(),
			[](edge e1, edge e2) {
				if (e1.l != e2.l)
					return e1.l < e2.l;
				return e1.c < e2.c;
			}
		);
	}
	vector<ll> dp(n + 1, 1000000000000000LL);
	dp[1] = 0;
	int ptr = 2;
	for (int i = 2; i <= n; ++i) {
		if (fin[i].size() == 0) continue;
		for (int j = 0; j < fin[i].size(); ++j) {
			int mx = i + 1, nx = j + 1;
			while (nx < fin[i].size() && dp[fin[i][nx].l] + fin[i][nx].c >= dp[fin[i][j].l] + fin[i][j].c)
				++nx;
			if (nx != fin[i].size()) mx = fin[i][nx].l;
			ptr = fin[i][j].l + 1;
			while (ptr < mx) {
				dp[ptr] = min(dp[ptr], dp[fin[i][j].l] + fin[i][j].c);
				++ptr;
			}
			j = nx - 1;
		}
	}
	cout << (dp[n] >= 1000000000000000LL ? -1 : dp[n]) << endl;
	return 0;
}

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

int main() {
	int N;
	cin >> N;
	vector<long long> B(N);
	for (int i = 1; i <= N; i++) {
		long long A;
		cin >> A;
		B[i - 1] = A - i;
	}
	sort(B.begin(), B.end());
	int median = B[N / 2];
	long long ans = 0;
	for (int i = 0; i < N; i++) ans += abs(B[i] - median);
	cout << ans << endl;

}

Measured memory_bytes: 1792
//----------------------------------------------------------------
//A-別2


#include <iostream>
using namespace std;

const long long INF = 1LL << 60;

// 入力
int N;
long long h[100010];

// メモ用の DP テーブル
long long dp[100010];

long long rec(int i) {
    // DP の値が更新されていたらそのままリターン
    if (dp[i] < INF) return dp[i];

    // 足場 0 のコストは 0
    if (i == 0) return 0;

    // i-1, i-2 それぞれ試す
    long long res = INF;
    res = min(res, rec(i-1) + abs(h[i] - h[i - 1])); // 足場 i-1 から来た場合
    if (i > 1) res = min(res, rec(i-2) + abs(h[i] - h[i - 2])); // 足場 i-2 から来た場合

    // 結果をメモしながら、返す
    return dp[i] = res;
}

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

    // 初期化 (最小化問題なので INF に初期化)
    for (int i = 0; i < 100010; ++i) dp[i] = INF;

    // 答え
    cout << rec(N-1) << endl;
}


Measured memory_bytes: 9876
#include<iostream>
#include<stdio.h>
#include<math.h>
using namespace std;
main(){
  double x1,y1,x2,y2,x=0,y=0;
  double kekka;
  cin >> x1 >> y1 >> x2 >> y2;
  x=x2-x1;
  y=y2-y1;
  kekka=sqrt(x*x+y*y);
  printf("%.8f\n",kekka);
}

Measured memory_bytes: 1236
#include <iostream>

using namespace std;

int main(int argc, const char * argv[]) {
    int l,r,d;
    cin>>l>>r>>d;
    
    int a,b,c1,c2;
    a=l/d;
    b=r/d;
    c1=l%d;
    c2=r%d;
    
    if(c1==0 && c2==0){
        cout<<(b-a+1);
    }
    else cout<<(b-a)<<endl;
    
    return 0;
}


Measured memory_bytes: 3588
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <map>
#include <unordered_map>
#include <utility>
#include <algorithm>
#include <cmath>
#include <array>
#include <bitset>
using namespace std;

typedef long long ll;
const ll mod=1000000007;
#define rep(i,n) for(int i=0;i<n;i++)
#define Rep(i,n) for(int i=1;i<n+1;i++)
int main(){
    int N,K;
    int v[50];
    cin>>N>>K;
    rep(i,N) cin>>v[i];
    vector<int> vec;
    ll ans=0,num;
    rep(k,min(K+1,N+1)){
        if(k==N){
            vec.clear();
            rep(i,N) vec.push_back(v[i]);
            sort(vec.begin(),vec.end());
            num=0;
            rep(i,N){
                if((i<K-N) && vec[i]<0) continue;
                else num+=vec[i];
            }
            ans=max(ans,num);
        }else{
            rep(i,k+1){
                vec.clear();
                rep(j,i) vec.push_back(v[j]);
                rep(j,k-i) vec.push_back(v[N-1-j]);
                sort(vec.begin(),vec.end());
                // rep(i,vec.size()) cout<<vec[i]<<" ";
                // cout<<endl;
                num=0;
                rep(i,vec.size()){
                    if((i<K-k) && vec[i]<0) continue;
                    else num+=vec[i]; 
                }
                ans=max(ans,num);
            }
        }
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

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

		long[][] keisu={
				{0,0,0,0,0,0,0,0,0,0},
				{0,0,0,0,0,0,0,0,0,1},
				{0,0,0,0,0,0,0,0,11,2},
				{0,0,0,0,0,0,0,112,22,4},
				{0,0,0,0,0,0,1124,224,44,8},
				{0,0,0,0,0,11248,2248,448,88,16},
				{0,0,0,0,112496,22496,4496,896,176,32},
				{0,0,0,1124992,224992,44992,8992,1792,352,64},
				{0,0,11249984,2249984,449984,89984,17984,3584,704,128},
				{0,112499968,22499968,4499968,899968,179968,35968,7168,1408,256},
				{1124999936,224999936,44999936,8999936,1799936,359936,71936,14336,2816,512}
		};

		int keta=a.length();
		long src=Long.parseLong(a);
		long[] suuji=new long[10];

		for(int i=0; i<10; i++) {
			suuji[9-i]=src%10;
			src/=10;
		}

		long res=0;

		for(int i=0; i<10; i++) {
			res+=suuji[i]*keisu[keta][i];
		}
		System.out.println(res);
	}
}

Measured memory_bytes: 21844
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
// #include<ext/pb_ds/assoc_container.hpp>
// #include<ext/pb_ds/tree_policy.hpp>
// #include<ext/pb_ds/tag_and_trait.hpp>
// using namespace __gnu_pbds;
// #include<boost/multiprecision/cpp_int.hpp>
// namespace multiprecisioninteger = boost::multiprecision;
// using cint=multiprecisioninteger::cpp_int;
using namespace std;
using ll=long long;
#define double long double
using datas=pair<ll,ll>;
using ddatas=pair<double,double>;
using tdata=pair<ll,datas>;
using vec=vector<ll>;
using mat=vector<vec>;
using pvec=vector<datas>;
using pmat=vector<pvec>;
// using llset=tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update>;
#define For(i,a,b) for(i=a;i<(ll)b;++i)
#define bFor(i,b,a) for(i=b,--i;i>=(ll)a;--i)
#define rep(i,N) For(i,0,N)
#define rep1(i,N) For(i,1,N)
#define brep(i,N) bFor(i,N,0)
#define brep1(i,N) bFor(i,N,1)
#define all(v) (v).begin(),(v).end()
#define allr(v) (v).rbegin(),(v).rend()
#define vsort(v) sort(all(v))
#define vrsort(v) sort(allr(v))
#define endl "\n"
#define eb emplace_back
#define print(v) cout<<v<<endl
#define printyes cout<<"Yes"<<endl
#define printno cout<<"No"<<endl
#define printYES cout<<"YES"<<endl
#define printNO cout<<"NO"<<endl
#define output(v) do{bool f=0;for(auto outi:v){cout<<(f?" ":"")<<outi;f=1;}cout<<endl;}while(0)
#define matoutput(v) do{for(auto outimat:v)output(outimat);}while(0)
// const ll mod=1000000007;
const ll mod=998244353;
const ll inf=1LL<<60;
const double PI = acos(-1);
const double eps = 1e-9;
template<class T> inline bool chmax(T& a,T b){bool x=a<b;if(x)a=b;return x;} 
template<class T> inline bool chmin(T& a,T b){bool x=a>b;if(x)a=b;return x;} 

int main(){
  int i,j=1,N,x;
  cin>>N>>x;
  if(x==1||x==N*2-1){
    printno;
    return 0;
  }
  printyes;
  if(N==2){
    puts("1 2 3");
    return 0;
  }
  vector<int> ans(2*N-1,0),used(2*N,0);
  if(x!=2){
    ans[N-2]=x-2;
    ans[N-1]=x;
    ans[N]=x+1;
    ans[N+1]=x-1;
    rep(i,4)used[x-2+i]=1;
  }else{
    ans[N-2]=x+2;
    ans[N-1]=x;
    ans[N]=x-1;
    ans[N+1]=x+1;
    rep(i,4)used[x-1+i]=1;
  }
  rep(i,N*2-1){
    if(!ans[i]){
      while(used[j])++j;
      ans[i]=j;
      used[j]=1;
    }
    print(ans[i]);
  }
}

Measured memory_bytes: 3072
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
typedef long long ll;
using namespace std;

int main(){
  int R,G,B,N;
  cin >> R >> G >> B >> N;
  int ans = 0;
  for(int i=0;i<=3000;i++){
    for(int j=0;j<=3000;j++){
      int rest = N - R * i - G * j;
      if(rest >= 0 && rest % B == 0) ans++;
    }
  }

  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#define rep(i,N) for(int i=0;i<(N);i++)
using namespace std;

int main(){
	int K,N;
	long long sum=0;
	cin>>N>>K;
	vector<int> p(N);
	rep(i,N)cin>>p[i];
	sort(p.begin(),p.end());
	rep(i,K){
		sum+=p[i];
	}
	cout<<sum<<endl;
}

Measured memory_bytes: 3636
#include <iostream>
#include <cmath>

using namespace std;

int main() {
	int n;
	double xa, ya, ra, xb, yb, rb;
	double kyori;
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> xa >> ya >> ra >> xb >> yb >> rb; 
		kyori = sqrt(pow(xb-xa, 2)+pow(yb-ya, 2));
		if (ra + rb < kyori) {
			cout << 0 << endl;
		} else if (kyori + rb < ra){
			cout << 2 << endl;
		} else if (kyori + ra < rb) {
			cout << -2 << endl;
		} else {
			cout << 1 << endl;
		}
	}
	return 0;
} 

Measured memory_bytes: 1232
package main

import (
	"bufio"
	"flag"
	"fmt"
	"io/ioutil"
	"log"
	"os"
	"strconv"
	"strings"
)

func (p *problem) solve() {
	X := p.NextInt()

	if X == 1 {
		p.PrintInt(1)
		return
	}

	ans := 1
	for p := 2; ; p++ {
		v := p * p
		if v > X {
			break
		}
		for v <= X {
			ans = max(v, ans)
			v *= p
		}
	}
	p.PrintInt(ans)
}

func max(x, y int) int {
	if x > y {
		return x
	}
	return y
}

var (
	debug  bool
	output string
)

func main() {
	flag.BoolVar(&debug, "debug", false, "Print debug logs")
	flag.BoolVar(&debug, "d", false, "Print debug logs")
	flag.StringVar(&output, "output", "stdout", "Specify output target (Default: stdout)")
	flag.StringVar(&output, "o", "stdout", "Specify output target (Default: stdout)")
	flag.Parse()

	if debug {
		out := os.Stdout
		if output != "stdout" {
			logfile, err := os.OpenFile(output, os.O_CREATE|os.O_WRONLY, 0666)
			if err != nil {
				panic(err)
			}
			defer logfile.Close()
			out = logfile
		}
		log.SetOutput(out)
	} else {
		log.SetOutput(ioutil.Discard)
	}

	p := problem{
		in:  bufio.NewReader(os.Stdin),
		out: bufio.NewWriter(os.Stdout),
	}
	p.solve()

	if err := p.out.Flush(); err != nil {
		panic(err)
	}
}

type problem struct {
	in  *bufio.Reader
	out *bufio.Writer
}

func (p *problem) PrintInt(d int) {
	p.Printf("%d\n", d)
}

func (p *problem) Printf(format string, a ...interface{}) {
	if _, err := fmt.Fprintf(p.out, format, a...); err != nil {
		panic(err)
	}
}

func (p *problem) Printfln(format string, a ...interface{}) {
	if _, err := fmt.Fprintf(p.out, fmt.Sprintf("%v\n", format), a...); err != nil {
		panic(err)
	}
}

func (p *problem) NextInt() int {
	return stoi(p.Next())
}

func (p *problem) NextInts() []int {
	line := p.NextSSLine()
	ds := make([]int, len(line))
	for i, s := range line {
		ds[i] = stoi(s)
	}
	return ds
}

func (p *problem) NextSSLine() []string {
	return strings.Split(p.Next(), " ")
}

// Next reads line and return string.
func (p *problem) Next() string {
	var b []byte
	for {
		l, pre, err := p.in.ReadLine()
		if err != nil {
			panic(err)
		}
		b = append(b, l...)
		if !pre {
			break
		}
	}
	return string(b)
}

func stoi(s string) int {
	i, err := strconv.Atoi(s)
	if err != nil {
		fmt.Println(i)
		fmt.Println(err)
	}
	return i
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int 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; }

ll h,w;
ll inf=1001001001;

void bfs(ll i,ll j, vector<string> s, vector<vector<ll>> &steps,queue<pair<ll,ll>> &tmp){
    ll step=steps[i][j];
    vector<int> x={1,-1,0,0},y={0,0,1,-1};
    rep(k,4){
        if(i+x[k]>=0 && i+x[k]<h && j+y[k]>=0 && j+y[k]<w){
            if(s[i+x[k]][j+y[k]]!='#' && steps[i+x[k]][j+y[k]]>step+1){
                tmp.push({i+x[k],j+y[k]});
                chmin(steps[i+x[k]][j+y[k]],step+1);
            }
        }
    }
}

int main(){
    cin>>h>>w;
    ll white=0;
    vector<string> s(h);
    rep(i,h){
        string t; cin>>t; s[i]=t;
        rep(j,w) if(t[j]=='.') white++;
    }
    vector<vector<ll>> steps(h,vector<ll>(w,inf));
    steps[0][0]=1;
    queue<pair<ll,ll>> tmp;
    tmp.push({0,0});
    while(!tmp.empty()){
        pair<ll,ll> t=tmp.front();
        tmp.pop();
        bfs(t.first,t.second,s,steps,tmp);
    }
    if(steps[h-1][w-1]==inf || s[0][0]=='#'){
        cout<<-1<<endl;
    }else{
        cout<<white-steps[h-1][w-1]<<endl;
    }
}

Measured memory_bytes: 256
import java.util.*;

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

        if(n%2 == 0){
            if(n/2 >= k){
                System.out.println("YES");
            }else{
                System.out.println("NO");
            }
        }else{
            if((n+1)/2 >= k){
                System.out.println("YES");
            }else{
                System.out.println("NO");
            }
        }
    }
}

Measured memory_bytes: 22740
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define pb push_back
void solve(){
    ll  n;
    cin>>n;
    ll ans = 0;
    for(ll i=1;i*i<n;i++){
        if(n%i==0 and n/i>i+1)ans+=(n/i)-1ll;
    }
    cout<<ans<<endl;
}
int main(){
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    int t=1;
//    cin>>t;
    while(t--)solve();
    return 0;
}


Measured memory_bytes: 3576
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define reps(i,s,n) for(int i=(s); i<(n); i++)
#define all(v) v.begin(),v.end()
#define outve(v) for(auto i : v) cout << i << " ";cout << endl
#define outmat(v) for(auto i : v){for(auto j : i) cout << j << " ";cout << endl;}
#define in(n,v) for(int i=0; i<(n); i++){cin >> v[i];}
#define out(n) cout << (n) << endl
#define fi first
#define se second
#define pb push_back
#define mod 1000000007
#define infi 1900000000
#define infl 1100000000000000000
#define cyes cout << "Yes" << endl
#define cno cout << "No" << endl
#define csp << " " <<
#define outset(n) cout << fixed << setprecision(n);
using namespace std;
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vs = vector<string>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
using vvp = vector<vector<pair<int,int>>>;
template<typename T> using ve = vector<T>;
template<typename T> using pq2 = priority_queue<T>;
template<typename T> using pq1 = priority_queue<T,vector<T>,greater<T>>;
template<typename T> bool chmax(T &a, T b) {if(a < b) {a = b;return 1;}return 0;}
template<typename T> bool chmin(T &a, T b) {if(a > b) {a = b;return 1;}return 0;}




int main(){
    
    ll K;
    cin >> K;
    
    vl a;
    rep(i,10) a.pb(i);
    ll n = 9,m = 9;
    int kk = 0;
    
    while (a.size() <= K+4) {
        vl b;
        kk++;
        for (ll p : a) {
            string pp = to_string(p);
            if(pp == "0"){
                string aa = "1" + string(kk,'0');
                b.pb(stol(aa));
                continue;
            }
            
            if(pp.length() <= kk-1){
                if(pp[0] == '1'){
                    string aa = to_string(1) + string(kk-pp.length(),'0') + pp;
                    b.pb(stol(aa));
                }
            }
         
            if(pp.length() != kk) continue;
            int c = pp[0]-'0';
            if(c-1 > 0){
                string aa = to_string(c-1) + pp;
                b.pb(stol(aa));
            }
            if(c != 0){
                string aa = to_string(c) + pp;
                b.pb(stol(aa));
            }
            
            if(c+1 <= 9){
                string aa = to_string(c+1) + pp;
                b.pb(stol(aa));
            }
            
        }
        sort(all(b));
        rep(i,b.size()) a.pb(b[i]);
        sort(all(a));
        m *= 9;
        n += m;
    }
    
    //outve(a);
    
    cout << a[K] << endl;

    
    
    
    

    return 0;
}


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

using namespace std;

typedef long long int ll;

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

  int n, K;
  cin >> n >> K;
  vector < ll > a(n + 1);
  for(int i = 1; i <= n; i++) cin >> a[i];

  int ans = 0;
  for(int k = 1; k <= K; k++){
    for(int i = 0; i <= k; i++){
      vector < int > v;
      for(int j = 1; j <= i && j <= n; j++) v.push_back(a[j]);
      for(int j = n; j >= 1 && j > n - (k - i) && j > i; j--) v.push_back(a[j]);
      int left = K - k, sum = 0;
      sort(v.begin(), v.end());
      for(int j = 0; j < v.size(); j++){
        sum += v[j];
        if(left > 0 && v[j] < 0){
          sum -= v[j];
          left--;
        }
      }
      ans = max(ans, sum);
    }
  }

  cout << ans << '\n';
}


Measured memory_bytes: 256
//#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define trav(x,a) for (const auto& x: a)
#define sz(x) (int)(x).size()
#define all(x) (x).begin(), x.end()
#define mem(a,v) memset((a), (v), sizeof (a))
#define enl printf("\n")
#define case(t) printf("Case #%d: ", (t))
#define ni(n) scanf("%d", &(n))
#define nl(n) scanf("%lld", &(n))
#define nai(a, n) for (int _i = 0; _i < (n); _i++) ni(a[_i])
#define nal(a, n) for (int _i = 0; _i < (n); _i++) nl(a[_i])
#define pri(n) printf("%d\n", (n))
#define prl(n) printf("%lld\n", (n))
#define pii pair<int, int>
#define pll pair<long long, long long>
#define vii vector<pii>
#define vll vector<pll>
#define vi vector<int>
#define vl vector<long long>
#define pb push_back
#define mp make_pair
#define st first
#define nd second
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef cc_hash_table<int,int,hash<int>> ht;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> oset;
const double pi = acos(-1);
const int mod = 1e9 + 7;
const int inf = 1e9 + 7;
const int N = 1e6 + 5;
const double eps = 1e-9;
int p[N], par[N], vis[505][505], pd[505][505];
int dx[4] = {0, 1, 0, -1};
int dy[4] = {1, 0, -1, 0};
int n;

pii getP(int v) { return mp((v - 1) / n + 1, (v - 1) % n + 1); }

int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n * n; i++) {
    scanf("%d", &p[i]);
    // p[i] = i;
    par[i] = i;
  }
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= n; j++) {
      pd[i][j] = min({i - 1, j - 1, n - i, n - j}) + 1;
      vis[i][j] = 1;
    }
  int ret = 0;
  for (int i = 1; i <= n * n; i++) {
    int x, y; tie(x, y) = getP(p[i]);
    vis[x][y] = 0;
    deque<pii> pq; pq.pb(mp(x,y));
    ret += --pd[x][y];
    while (sz(pq)) {
      auto cur = pq.front(); pq.pop_front();
      for (int k = 0; k < 4; k++) {
        int nx = cur.st + dx[k], ny = cur.nd + dy[k];
        if (pd[nx][ny] <= pd[cur.st][cur.nd] + vis[nx][ny] || nx < 1 || nx > n || ny < 1 || ny > n)
          continue;
        pd[nx][ny] = pd[cur.st][cur.nd] + vis[nx][ny];
        if (!vis[nx][ny])
          pq.push_front(mp(nx, ny));
        else
          pq.push_back(mp(nx, ny));
      }
    }
  }
  printf("%d\n", ret);
  return 0;
}


Measured memory_bytes: 8228
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<cmath>
#include<queue>
#include<vector>
#include<ctime>
#include<map>
#include<bitset>
#include<set>
#include<assert.h>
#define LL long long
#define mp(x,y) make_pair(x,y)
#define pll pair<long long,long long>
#define pii pair<int,int>
#define SZ(x) ((int)x.size())
using namespace std;
inline LL read()
{
	LL f=1,x=0;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
	return x*f;
}
int stack[20];
template<typename T>inline void write(T x)
{
	if(x<0){putchar('-');x=-x;}
    if(!x){putchar('0');return;}
    int top=0;
    while(x)stack[++top]=x%10,x/=10;
    while(top)putchar(stack[top--]+'0');
}
template<typename T>inline void pr1(T x){write(x);putchar(' ');}
template<typename T>inline void pr2(T x){write(x);putchar('\n');}
template<typename T>inline void chkmin(T &x,T y){x=x<y?x:y;}
template<typename T>inline void chkmax(T &x,T y){x=x>y?x:y;}
const int MAXN=1000005;
const int mod=1e9+7;
int pow_mod(int a,int b)
{
	int ret=1;
	for(;b;b>>=1,a=1LL*a*a%mod)if(b&1)ret=1LL*ret*a%mod;
	return ret;
}
int pre[MAXN],inv[MAXN],n;
int C(int n,int m){return n<m?0:1LL*pre[n]*inv[m]%mod*inv[n-m]%mod;}
void ad(int &x,int y){x+=y;if(x>=mod)x-=mod;}
void dl(int &x,int y){x-=y;if(x<0)x+=mod;}
int main()
{
	pre[0]=1;for(int i=1;i<MAXN;i++)pre[i]=1LL*pre[i-1]*i%mod;
	inv[MAXN-1]=pow_mod(pre[MAXN-1],mod-2);
	for(int i=MAXN-2;i>=0;i--)inv[i]=1LL*inv[i+1]*(i+1)%mod;
	n=read();int ans=0;
	for(int i=(n+1)/2;i<n;i++)
	{
		int val=C(n-3-(n-1-(i-1)-1),n-1-(i-1));
		val=1LL*val*pre[i-1]%mod*pre[n-i]%mod;
		ad(ans,(pre[n-1]-val+mod)%mod);
	}ad(ans,1LL*((n+1)/2-1)*pre[n-1]%mod);
	pr2(ans);
	return 0;
}


Measured memory_bytes: 7936
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD = 1000000007;

#define REP(i,n) for((i)=0;(i)<(int)(n);(i)++)

typedef pair<int, int> P;

int main(){
    int n;
    cin >> n;
    vector<P> red(n), blue(n);
    for (int i = 0; i < n; i++){
        int a, b;
        cin >> a >> b;
        red[i] = P(a, b);
    }
    for (int i = 0; i < n; i++){
        int c, d;
        cin >> c >> d;
        blue[i] = P(c, d);
    }
    
    sort(red.begin(), red.end());
    sort(blue.begin(), blue.end());

    bool used[110];
    fill(used, used + 110, false);
    int ans = 0;
    for (int i = 0; i < n; i++){
        int maxy = -1, index = -1;
        for(int j = 0; j < n; j++){
            if (red[j].first >= blue[i].first) break;

            if (red[j].second < blue[i].second && !used[j]){
                if (red[j].second > maxy){
                    maxy = red[j].second;
                    index = j;
                }
            }
        }
        if (index != -1){
            ans++;
            used[index] = true;
        }
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
int main(){
  int n,num,i=0,j,flag=0,total=0,odd=0;
  scanf("%d",&n);
  if(n>=1&&n<=10000){
    while(i<n){
      scanf("%d",&num);
      if(num<=2&&num>=10E8){
	exit(1);
      }
      odd=num%2;
      if(num==2)total++;
      else if(odd !=0){
	for(j=3;j*j<=num;j+=2){
	  if(num%j==0){
	    flag=1;
	    break;
	  }
	}
	if(flag==0)total++;
	flag=0;
      }
      i++;
    }
  }
  printf("%d\n",total);

return 0;
}




Measured memory_bytes: 2072
#include <bits/stdc++.h>
#include <iostream>
#include <string>
#include <limits.h>
#include <algorithm>
#include <iomanip>
using namespace std;

int lenght(char* str){
  int i=0;
 while(str[i]){
     i++;
 }
 return i;
}

int main(){
  char S[11], T[11] ;
  int N, M, ans = 1, point=1, len ;
  cin >> S >> T ;
  len = lenght(S) ;
  for(int i=0;i<len;i++){
    if(S[i] != T[i]) ans = 0 ;
  }
  if(ans){
    cout << "Yes" << endl ;
  }  
  else{
    cout << "No" << endl ;
  }  
  return 0 ;
}  

Measured memory_bytes: 3600
#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
const int INF=1e9,MOD=1e9+7,ohara=1e6+10;
const ll LINF=1e18;
using namespace std;

#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define rrep(i,a,b) for(int i=(a);i<(b);i++)
#define rrrep(i,a,b) for(int i=(a);i>=(b);i--)
#define all(v) (v).begin(), (v).end()
#define Size(n) (n).size()
#define Cout(x) cout<<(x)<<endl
#define Cerr(x) cerr<<(x)<<endl
#define fi first
#define se second
#define P pair<ll,ll> 
#define m_p make_pair

ll n,cnt,ans,a,b,c,d,tmp,tmpp,m,h,w,x,y,sum,pos,k;
ld doua;
int dy[]={1,0,-1,0};
int dx[]={0,1,0,-1};
//int dy[]={-1,0,1,-1,1,-1,0,1};
//int dx[]={-1,-1,-1,0,0,1,1,1};
string alph("abcdefghijklmnopqrstuvwxyz"),s;
bool fl;
struct edge{int to,cost;};

//-------------------------↓↓↓↓↓↓------------------------

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

    cin>>a>>b>>c;
    ans=b/a;
    Cout(min(ans,c));
    return 0;
}


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

#define MOD 1000000007

using namespace std;

string replace_with_str(string str, string str_from, string str_to) {
    string::size_type pos = 0;
    while (pos = str.find(str_from, pos), pos != string::npos) {
        str.replace(pos, str_from.length(), str_to);
        pos += str_to.length();
    }
    return str;
}

int main(int argc, char const *argv[]){
    int W, H, N;
    cin >> W >> H >> N;
    int x1 = 0, x2 = W, y1 = 0, y2 = H;
    for(int i=0; i<N; i++){
        int x, y, a;
        cin >> x >> y >> a;
        switch(a){
            case 1:
                x1 = max(x1, x);
                break;
            case 2:
                x2 = min(x2, x);
                break;
            case 3:
                y1 = max(y1, y);
                break;
            case 4:
                y2 = min(y2, y);
                break;
        }
    }

    if((x2-x1) < 0 || (y2-y1) < 0){
        printf("0\n");
        return 0;
    }
    printf("%d\n", (x2-x1)*(y2-y1));
    return 0;
}

Measured memory_bytes: 256
def main():
    from collections import defaultdict,deque
    from itertools import count
    (n,),*a=[list(map(int,t.split()))for t in open(0)]
    d=defaultdict(count().__next__)
    es=[]
    for i,b in enumerate(a,1):
        for j,k in zip(b,b[1:]):
            x,y=i,j
            if y<x:x,y=y,x
            v,w=i,k
            if w<v:v,w=w,v
            es+=(d[x*n+y],d[v*n+w]),
    s=len(d)
    outs=[[]for _ in range(s)]
    ins=[0]*s
    f=set(range(s))
    for i,j in es:
        outs[i]+=j,
        f-={j}
        ins[j]+=1
    q=deque(f)
    l=0
    data=[0]*s
    m=0
    while q:
        i=q.popleft()
        l+=1
        t=data[i]+1
        if t>m:m=t
        for j in outs[i]:
            ins[j]-=1
            if ins[j]<1:q+=j,
            if t>data[j]:data[j]=t
    print(-(l<s)or m)
main()

Measured memory_bytes: 208480
// A. 

#include <iostream>
#include <algorithm>
#include <sstream>
#include <cstdio>
#include <cstring>

using namespace std;

int main(int argc, char *argv[])
{
	string s;
	cin >> s;
	int ans = 1 << 30, n = (int)s.length();
	for (char c = 'a'; c <= 'z'; ++c) {
		if (s.find(c) != string::npos) {
			string t = s;
			for (int i = 0; ; ++i) {
				if (count(t.begin(), t.end(), c) == t.length()) {
					ans = min(ans, i);
					break;
				}
				string next;
				for (int j = 0; next.length() < (t.length() - 1); ++j) {
					if (t[j] == c || t[j + 1] == c) {
						next += c;
					} else {
						next += t[j];
					}
				}
				t = next;
			}
		}
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
typedef vector<int> vec1;
typedef vector<string> vec2;
typedef vector<double> vec3;
#define rep(i,n) for(int i=0;i<(n);i++)
const int MOD = 1000000007;

int main() {
  int W, a, b;
  cin >> W >> a >> b;
  
  if(a < b) {
    if((b - (a + W)) <= 0) {
      cout << 0 << endl;
    } else {
      cout << b - (a + W) << endl;
    }
  } else if(a > b) {
    if((a - (b + W)) <= 0) {
      cout << 0 << endl;
    } else {
      cout << a - (b + W) << endl;
    }
  } else {
    cout << 0 << endl;
  }
}

Measured memory_bytes: 256
s = input()
q = int(input())
head = []
tail = []
rev=False
for _ in range(q):
  tmp = list(input().split())
  if tmp[0] == '1':
    if rev == False:
      rev = True
    else:
      rev = False
  if tmp[0] == '2':
    if tmp[1] == '1':
      if rev == False:
        head.append(tmp[2])
      if rev == True:
        tail.append(tmp[2])
    if tmp[1] == '2':
      if rev == False:
        tail.append(tmp[2])
      if rev == True:
        head.append(tmp[2])
head = ''.join(map(str,head))
tail = ''.join(map(str,tail))

ans = head[::-1]+s+tail
if rev == True:
  ans = ans[::-1]
print(ans)

Measured memory_bytes: 6272
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(a) (a).begin(), (a).end()
using namespace std;
using ll = long long;
using P = pair<int, int>;

void solve()
{
    int n;
    cin >> n;
    vector<int> a(n);
    rep(i, n) cin >> a[i];
    sort(all(a));
    reverse(all(a));
    int ans = 0;
    rep(i, n)
    {
        if (i % 2 == 0)
            ans += a[i];
        else
            ans -= a[i];
    }
    cout << ans << endl;
}

int main()
{
    solve();
    return 0;
}

Measured memory_bytes: 3688
use proconio::{fastout, input};
//use proconio::marker::Chars;
//use proconio::marker::Usize1;

#[fastout]
fn main() {
    input! {
        d: usize,
        t: usize,
        s: usize,
    };
    let ans = if t * s >= d {"Yes"} else {"No"};
    println!("{}",ans);
}


Measured memory_bytes: 2192
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
const ll MOD=(ll)1e9+7;
//const ll MOD=(ll)998244353;
const ll INF=(ll)1e18+10;
const double PI = 2.0*acos(0);
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
int dy[]={-1,1,0,0};
int dx[]={0,0,-1,1};

void solve(int ca){
    string S; cin>>S;
    int N=S.length();
    ll ans=(ll)N*(N-1)/2+1;
    vector<int> cnt(26,0);
    for (int i = 0; i < N; ++i) {
        cnt[S[i]-'a'] ++;
    }
    for (int i = 0; i < 26; ++i) {
        ans-=(ll)cnt[i]*(cnt[i]-1)/2;
    }

    cout<<ans<<endl;
}

//#define MULTI
int main() {
#ifdef MULTI
    int N; cin>>N;
    for (int i = 0; i < N; ++i) {
        solve(i+1);
    }
#else
    solve(0);
#endif
    return 0;
}


Measured memory_bytes: 3732
using System;
using System.Linq;
using System.Collections.Generic;
using static System.Console;
using System.Text;
using System.IO;
using static System.Math;
namespace AtCoder
{
    class Program
    {
        static public long[] Sarray() { return ReadLine().Split().Select(long.Parse).ToArray(); }
        static public List<long> Slist() { return ReadLine().Split().Select(long.Parse).ToList(); }

        static readonly long Mod = 1000000000 + 7;

        static void Main(string[] args)
        {
            //SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
            var X = Sarray()[0];

            var delta = X - 1;
            for (var i = 2L; i*i <= X; ++i)
            {
                var cnt = i;
                while (cnt <= X)
                {
                    delta = Min(delta, X - cnt);
                    cnt *= i;
                }
            }
            WriteLine(X - delta);
            //Out.Flush();
        }
    }
}

Measured memory_bytes: 13396
import java.util.*;

public class Main {
  public static void main(String[] args) {
    @SuppressWarnings("resource")
    Scanner sc = new Scanner(System.in);
    String r = sc.next();
    String g = sc.next();
    String b = sc.next();

    System.out.println(Integer.parseInt(r+g+b) % 4 == 0 ? "YES" : "NO");
  }
}


Measured memory_bytes: 23124
N, M = map(int, input().split())
S = list(map(int, input().split()))
T = list(map(int, input().split()))
dp = [1] * (M+1)
dpleft = [0] * (M)
MOD = 10 ** 9 + 7
ndp = [1] * (M+1)
for n in range(N):
    for m in range(M):
        if S[n] == T[m]:
            ndp[m+1] = ndp[m] + dp[m+1]
            dpleft[m] = dp[m+1]
        else:
            ndp[m+1] = ndp[m] + dpleft[m]
        dp[m] = ndp[m]
    dp[M] = ndp[M]
print(dp[-1] % MOD)

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

int main(){
  int n,ma,mb,inf = 1000000007;
  int abmax = 400;
  cin >> n >> ma >> mb;
  int a[n],b[n],c[n],dp[n+1][abmax + 50][abmax + 50];
  for(int i = 0;i < n;i++){
    cin >> a[i] >> b[i] >> c[i];
  }
  for(int i = 0;i <= n;i++){
    for(int j = 0;j < abmax + 50;j++){
      for(int k = 0;k < abmax + 50;k++){
        dp[i][j][k] = inf;
      }
    }
  }
  dp[0][0][0] = 0;
  for(int i = 0;i < n;i++){
    for(int j = 0;j <= abmax;j++){
      for(int k = 0;k <= abmax;k++){
        if(dp[i][j][k] == inf){
          continue;
        }
        dp[i+1][j][k] = min(dp[i+1][j][k],dp[i][j][k]);
        dp[i+1][j+a[i]][k+b[i]] = min(dp[i+1][j+a[i]][k+b[i]],dp[i][j][k] + c[i]);
      }
    }
  }
  bool possible = false;
  int result = inf;
  for(int j = 1;j <= abmax;j++){
    for(int k = 1;k <= abmax;k++){
      if(dp[n][j][k] != inf && j*mb == k*ma){
        possible = true;
        result = min(result,dp[n][j][k]);
      }
    }
  }
  if(possible == true){
    cout << result << endl;
  }
  else{
    cout << -1 << endl;
  }
}

Measured memory_bytes: 32640
import math
N, M = map(int, input().split())


def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp % i == 0:
            cnt = 0
            while temp % i == 0:
                cnt += 1
                temp //= i
            arr.append([i, cnt])
    if temp != 1:
        arr.append([temp, 1])

    if arr == [] and n != 1:
        arr.append([n, 1])

    return arr


mod = 10**9 + 7


def cmb(n, r, mod):
    if (r < 0 or r > n):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod


g1 = [1, 1]
g2 = [1, 1]
inverse = [0, 1]
for i in range(2, 2*10**5 + 1):
    g1.append((g1[-1] * i) % mod)
    inverse.append((-inverse[mod % i] * (mod//i)) % mod)
    g2.append((g2[-1] * inverse[-1]) % mod)


primes = factorization(M)
# 何箇所に分けるか（cnt以下）,その中でどう分けるか（しきりをどこにおくか（振り分けられないものが出ると選べれないのとおなじになるので、cnt - 選んだ数））

ans = 1

for p, cnt in primes:
    tmp = cmb(N+cnt-1, N-1, mod)
    ans *= tmp
    ans %= mod

print(ans)


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

using namespace std;
#define X first
#define Y second
#define rev(a) reverse(a+1,a+n+1)
typedef long long ll;
typedef pair<int,int> P;
const int N=3e5+5,inf=1e9;
int n,i,a[N];
ll s[N],g[N],l[N],r[N],f[N];
ll sum(int n){return (ll)n*(n+1)/2;}
int t,q[N],x,k;

double cal(int x,int y){return (double)(g[x]-g[y])/(x-y);}
void pop(int x){for (;t>1&&cal(q[t-1],q[t])<=x;t--);}
void push(int x)
{
	for (;t>1&&cal(q[t-1],q[t])<=cal(q[t],x);t--);q[++t]=x;
}
void init_s(){for (int i=1;i<=n;i++) s[i]=s[i-1]+a[i];}
void init(ll *f)
{
	int i;q[t=1]=0;init_s();
	for (i=1;i<=n;i++)
	{
		pop(i);f[i]=max(f[i-1],f[q[t]]+sum(i-q[t])-s[i]+s[q[t]]);
		g[i]=f[i]+sum(i-1)+s[i];push(i);
	}
}
ll w[N];
void work(int x,int y){
	if (x==y) return;int i,m=x+y>>1;t=0;
	for (i=x;i<=m;i++) g[i]=l[i]+sum(i-1)+s[i],push(i);
	for (;i<=y;i++) pop(i),
		w[i]=l[q[t]]+r[i+1]+sum(i-q[t])-s[i]+s[q[t]];
	for (f[y]=max(f[y],w[y]),i=y-1;i>m;i--)
		f[i]=max(f[i],w[i]=max(w[i],w[i+1]));
	work(x,m);work(m+1,y);
}

int main()
{
	for (scanf("%d",&n),i=1;i<=n;i++) scanf("%d",&a[i]),f[i]=-inf;
	init(l);rev(a);init(r);rev(a);rev(r);
	init_s();work(0,n);rev(a);rev(f);rev(l);rev(r);swap(l,r);
	init_s();work(0,n);rev(a);rev(f);rev(l);rev(r);swap(l,r);
	
	for (scanf("%d",&i);i;i--)
	{
		scanf("%d%d",&x,&k);
		printf("%d\n",max(l[x-1]+r[x+1],f[x]+a[x]-k));
	}	
}

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

using Val=bitset<(1<<4)>;

Val Primitive(int i){
    Val x;
    for(int j=0;j<(1<<4);j++){
        if((j>>i)&1) x[j]=true;
    }
    return x;
}
Val Exp(int &p,string s){
    if(s[p]=='-'){
        p++;
        return ~Exp(p,s);
    }
    if(s[p]=='('){
        p++;
        Val lhs=Exp(p,s);
        char op=s[p++];
        Val rhs=Exp(p,s);
        assert(s[p++]==')');
        if(op=='*') return lhs&rhs;
        else return lhs^rhs;
    }
    if(isdigit(s[p])){
        Val res;
        for(int i=0;i<(1<<4);i++) res[i]=s[p]-'0';
        p++;
        return res;
    }
    return Primitive(s[p++]-'a');
}
struct P{
    int len;
    Val v;
};
bool operator<(P lhs,P rhs){
    return lhs.len>rhs.len;
}
int solve(string s){
    int p=0;
    Val org=Exp(p,s);
    priority_queue<P> que;
    que.push(P{1,0});
    que.push(P{1,(1<<(1<<4))-1});
    for(int i=0;i<4;i++) que.push(P{1,Primitive(i)});
    unordered_map<Val,int> mp;
    while(!que.empty()){
        auto tmp=que.top(); que.pop();
        Val v=tmp.v;
        int len=tmp.len;
        if(mp.count(v)) continue;
        if(org==v) return len;
        mp[v]=len;
        que.push(P{len+1,~v});
        for(auto &e:mp){
            que.push(P{len+e.second+3,v&e.first});
            que.push(P{len+e.second+3,v^e.first});
        }
    }
    assert(false);
}
int main(){
    string s;
    while(cin>>s,s!="."){
        cout<<solve(s)<<endl;
    }
    return 0;
}


Measured memory_bytes: 68696
#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>
#include <cmath>
using namespace std;


int main(int argc, const char * argv[]) {
    int n, k, x, y;
    cin >> n >> k >> x >> y;
    int total = (n>k) ? (n-k)*y : 0;

    total += (n>k) ?  k*x: n*x;
    cout << total << endl;
    return 0;
}


Measured memory_bytes: 256
/*
ID: learnin7
TASK: test
LANG: C++                 
*/
/* LANG can be C++11 or C++14 for those more recent releases */
#include<bits/stdc++.h>

/*  Macros from Endagorion */
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ford(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)

using namespace std;

typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpi;
typedef vector<vi> vvi;
typedef long long i64;
typedef vector<i64> vi64;
typedef vector<vi64> vvi64;
typedef pair<i64, i64> pi64;
typedef double ld;


int main(){
        
    ios_base::sync_with_stdio(0);
    
    //ofstream fout ("test.out");
    //ifstream fin ("test.in");
    //fin >> a >> b;
    //fout << a+b << endl;
    i64 a,b,c;
    cin>>a>>b>>c;
    if(c<(a+b)){
        cout<<"No\n";
        return 0;
    }
    i64 l = 4*a*b;
    i64 r = (c-a-b)*(c-a-b);
    //cout<<l<<" "<<""<<c-a-b<<" "<<pow((c-a-b),2)<<" "<<r<<endl;
    if(l<r) cout<<"Yes\n";
    else    cout<<"No\n";
    return 0;
}



Measured memory_bytes: 256
#include<iostream>
#include<map>
#include<algorithm>
#include <iomanip>
#include <cmath>
#include <sstream>
#include <unordered_map>
#include <unordered_set>
#include <deque>
#include <vector>
#include <bitset>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <cstring>

#define INF 1050000000
#define MOD 1000000007

using namespace std;

int main() {
	long long int n, a, b; cin >> n >> a >> b;
	long long int x[n];
	
	for (int i = 0; i < n; i++) {
		cin >> x[i];
	}

	long long int ans = 0;

	for (int i = 1; i < n; i++) {
		long long int tmp = x[i] - x[i - 1];
		ans += min(tmp*a, b);
	}

	cout << ans << endl;

}

Measured memory_bytes: 1024
L, R = map(int, input().split())

# 例：L=3000, R=10000 で考える
# (i,j)=(3000,3001)から始まり、(3000,5018)で最小(=0)

# R-L>=2019 のとき、(L,L+1),...,(L,L+2019)の間で最小値0を取れるので、高々2018回の探索
# 全探索しても break すれば間に合う！
m = 2019
flag = False
for i in range(L, R):
  for j in range(i+1, R+1):
    m = min(m, i*j % 2019)
    if m == 0: 
      flag = True
      break
  if flag: break

print(m)

Measured memory_bytes: 9176
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<cmath>
#include<queue>
#include<stack>
#include<map>

using namespace std;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)

template<typename A, typename B> bool chmin(A &a, const B &b){ return b < a && (a = b, true); }
template<typename A, typename B> bool chmax(A &a, const B &b){ return a < b && (a = b, true); }

int main(){
  int a,b;
  cin >> a >> b;
  cout << a * b << '\n';
  return 0;
}

Measured memory_bytes: 3640
#include<bits/stdc++.h>
using namespace std;
int main(){
  int A, B;
  cin >> A >> B;
  int max = 0;
  for(int i = A; i<=B; i++){
    int m5 = i/10000;
    int m4 = (i%10000)/1000;
    int m2 = (i%100)/10;
    int m1 = i%10;
    if(m5==m1 && m4==m2){
      max++;
    }
  }
  cout << max;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<iomanip>
using namespace std;
#define double long double
#define two (double)2.0/(double)3.0
#define one (double)1.0/(double)3.0
#define EPS (double)0.000000001
double p[2001][2001]={};

int n,m;
double point[]={5.0000000,3.0000000,2.000000};
double g[2001][3]={};
double dfs(int sss, int k,vector<int> &s,vector<vector<int> >&v){
    if(k==2){
        s[k] = sss;
        return g[s[0]][0]+g[s[1]][1]+g[s[2]][2];
    }else{
        double mx = -1000.0;
        for(int i=0;i<=sss;i++){
            s[k] = i;
            mx = max(mx,dfs(sss-i,k+1,s,v));
        }
        return mx;
    }
}


int main(){
    cin >> n >> m;
    vector<vector<int> > v(n,vector<int>(3));
    for(int i=0;i<n;i++){
        cin >> v[i][0] >> v[i][1] >> v[i][2];
    }
    p[0][0] = 1.0;
    for(int i=1;i<=m;i++){
        p[i][0] = p[i-1][0]*two;
        p[i][i] = p[i-1][i-1]*one;
    }
    for(int i=2;i<=m;i++){
        for(int j=1;j<i;j++){
            p[i][j] = p[i-1][j]*two + p[i-1][j-1]*one;
        }
    }
    
    for(int i=m-1;i>=0;i--){
        p[m][i] += p[m][i+1];
    }
    for(int sq = 0;sq<=m;sq++){
        for(int q=0;q<3;q++){
            double ans = 0.0;
            int x = v[0][q] * sq;
            vector<double> pr(n);
            for(int i=1;i<n;i++){
                int y = (x-1)/v[i][q] + 1;
                if(x==0) y = 0;
                if(y<=m)pr[i] = p[m][y];
                else pr[i] = 0.0;
            }
            double p1=1.0;
            for(int i=1;i<n;i++){
                p1 *= pr[i];
            }
            ans += -1.0*p1;
            vector<vector<double> > vd(n,vector<double>(3));
            vd[0][0] = 1.0;
            for(int i=1;i<n;i++){
                for(int j=0;j<3;j++){
                    if(j!=0)vd[i][j] = vd[i-1][j]*(1.0-pr[i])+vd[i-1][j-1]*(pr[i]);
                    else vd[i][j] = vd[i-1][j]*(1.0-pr[i]);
                }
            }
            ans += point[q]*(vd[n-1][0]+vd[n-1][1]+vd[n-1][2]);
            g[sq][q] = ans;
        }
    }

    vector<int> s(3);
    double ans = dfs(m,0,s,v);
    cout << fixed << setprecision(12) << ans << endl;
    return 0;
}


Measured memory_bytes: 42400
#include <bits/stdc++.h>
using namespace std;
#define N_MAX 1000000

int main(){
    //入力
int a[N_MAX];
int n;
long long sum=0;
long long ans=0;
int med=0;

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

    for(int i=0;i<n;++i){
        a[i]-=(i+1);
    }

    sort(a,a+n);
    if(n%2==0){
        med=round(double(a[n/2-1]+a[n/2])/2);
    }else{
        med=a[(n-1)/2];
    }

    for(int i=0;i<n;i++){
        ans+=abs(a[i]-med);
    }
    cout << ans <<endl;

    return 0;
}

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

namespace ALDS1_6_D {
    public static class Problem {
        public static int GetMinCost(this int[] source) {
            int n = source.Length;
            int minCost = 0;
            bool[] used = new bool[n];

            int[] sorted = (int[])source.Clone();
            Array.Sort(sorted);
            int minValue = sorted[0];

            Dictionary<int, int> valueToIndex = Enumerable.Range(0, n)
                .ToDictionary(i => source[i], i => i);
            
            for(int i = 0; i < n; i++) {
                if (used[i] || valueToIndex[sorted[i]] == i)
                    continue;

                int minValueInGroup = sorted[i];
                int curPosition = valueToIndex[minValueInGroup];
                int sumOriginal = 0;
                int sumReplace = (minValue + minValueInGroup) * 2;

                while (curPosition != i) {
                    used[curPosition] = true;
                    int nextValue = sorted[curPosition];
                    sumOriginal += nextValue + minValueInGroup;
                    sumReplace += nextValue + minValue;
                    curPosition = valueToIndex[nextValue];
                }
                minCost += Math.Min(sumOriginal, sumReplace);
            }
            return minCost;
        }
    }

    class Program {
        static void Main(string[] args) {
            Console.ReadLine();
            int[] input = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
            Console.WriteLine(input.GetMinCost());
        }
    }
}

Measured memory_bytes: 10312