akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
 
#define int long long
#define ull unsigned long long
#define ld long double
#define rep(a) rep1(i,a)
#define rep1(i,a) rep2(i,0,a)
#define rep2(i,b,a) for(int i=(b); i<((int)(a)); i++)
#define rep3(i,b,a) for(int i=(b); i>=((int)(a)); i--)
#define all(a) a.begin(),a.end()
#define pii pair<int,int>
#define pb push_back
#define mp make_pair
#define eps 1e-9
#define sz(a) ((int)a.size())
#define pow2(x) (1ll<<(x))
#define ceiling(a,b) (((a)+(b)-1)/(b))
#define print0(a) cout << (a) << ' '
#define print1(a) cout << (a) << '\n'
#define print2(a,b) cout << (a) << ' ',print1(b)
#define print3(a,b,c) cout << (a) << ' ',print2(b,c)
#define print4(a,b,c,d) cout << (a) << ' ',print3(b,c,d)
#ifdef i_am_noob
#define debug(a) print2(#a,a)
#else
#define debug(a) 
#endif
#define ordered_set tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>
 
using namespace std;
using namespace __gnu_pbds;
 
const int Mod=1000000007,Mod2=998244353;
const int MOD=Mod;
 
inline int add(int a, int b){return (a+b>=MOD?a+b-MOD:a+b);}
inline int sub(int a, int b){return (a+MOD-b>=MOD?a-b:a+MOD-b);}
int Pow(int a, int b){
	if(!b) return 1;
	int tmp=Pow(a*a%MOD,b>>1);
	return (b&1?tmp*a%MOD:tmp);
}
inline int inverse(int n){return Pow(n,MOD-2);}
 
const int maxn=100005;
//i_am_noob
int dp[12][10],n,x=0;
vector<pii> ans;
bool ok;

signed main(){
	ios_base::sync_with_stdio(0),cin.tie(0);
	rep(10) dp[1][i]=1;
	rep2(i,2,12) rep1(j,10){
		dp[i][j]=dp[i-1][j];
		if(j>0) dp[i][j]+=dp[i-1][j-1];
		if(j<9) dp[i][j]+=dp[i-1][j+1];
	}
	cin >> n;
	if(n<10){
		print1(n);
		return 0;
	}
	ok=false;
	rep2(i,1,12){
		rep2(j,1,10){
			x+=dp[i][j];
			if(x>=n){
				ans.pb(mp(i,j));
				n-=x-dp[i][j];
				ok=true;
				break;
			}
		}
		if(ok) break;
	}
	rep(ans[0].first-1){
		x=0;
		if(ans.back().second>0) x+=dp[ans.back().first-1][ans.back().second-1];
		if(x>=n){
			n-=x-dp[ans.back().first-1][ans.back().second-1];
			ans.pb(mp(ans.back().first-1,ans.back().second-1));
			continue;
		}
		x+=dp[ans.back().first-1][ans.back().second];
		if(x>=n){
			n-=x-dp[ans.back().first-1][ans.back().second];
			ans.pb(mp(ans.back().first-1,ans.back().second));
			continue;
		}
		if(ans.back().second<9) x+=dp[ans.back().first-1][ans.back().second+1];
		if(x>=n){
			n-=x-dp[ans.back().first-1][ans.back().second+1];
			ans.pb(mp(ans.back().first-1,ans.back().second+1));
			continue;
		}
	}
	rep(sz(ans)) cout << ans[i].second;
	cout << '\n';
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
int main(void){
	int m,d; cin>>m>>d;
	int ans=0;
	for(int i=1;i<=m;i++){
		for(int j=1;j<=d;j++){
			int d_1=j%10,d_2=j/10;
			//cout<<d_1<<" "<<d_2<<" "<<i<<endl;
			if(d_1*d_2==i&&d_1>=2&&d_2>=2) ans++;
		}
	}
	cout<<ans<<endl;
	
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner s = new Scanner(System.in);
		int n = s.nextInt();
		for (int i = 0; i < n; ++i) {
			int count = 1;
			int y = s.nextInt(), m = s.nextInt(), d = s.nextInt();
			count += ((y % 3 < 1 || m % 2 > 0) ? 20 : 19) - d;

			count += 20 * ((10 - m) / 2);
			count += (y % 3 < 1 ? 20 : 19) * ((10 - m + 1)/ 2);

			for (++y; y < 1000; ++y) {
				count += (y % 3 < 1) ? 200 : 195;
			}
			System.out.println(count);
		}
	}
}

Measured memory_bytes: 20688
#include <iostream>
#include <vector>
#include <utility>
#include <algorithm>
#include <cmath>
#include <string>
#include <map>
#include <cstring>

#define pb push_back
#define mp make_pair

using namespace std;

typedef vector<int> vi;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef unsigned long long ull;
typedef long long ll;


int main() {
  string s;
  cin >> s;

  vector<string> res;

  string last = s.substr(0, 1);
  res.pb(last);
  s = s.substr(1);

  while (s.size() > 0) {
    string now = s.substr(0, 1);

    if (now == last) {
      if(s.size() == 1) {
	break;
      } else {
        last = s.substr(0, 2);
	s = s.substr(2);
	res.pb(last);
      }
    } else {
      last = now;
      s = s.substr(1);
      res.pb(last);
    }
  }

  cout << res.size() << endl;
  return 0;
}


Measured memory_bytes: 10736
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define P pair<ll,ll>
#define FOR(I,A,B) for(ll I = (A); I < (B); ++I)
#define FORR(I,A,B) for(ll I = (B-1); I >= (A); --I)
#define SORT(x) (sort(x.begin(),x.end())) // 0 2 2 3 4 5 8 9
#define REV(x) (reverse(x.begin(),x.end())) //reverse
ll gcd(ll a,ll b){if(a<b)swap(a,b);if(a%b==0)return b;else return gcd(b,a%b);}
ll lcm(ll a,ll b){ll c=gcd(a,b);return ((a/c)*(b/c)*c);}//saisyo kobaisu
#define NEXTP(x) next_permutation(x.begin(),x.end())
const ll INF=1e18+7;
const ll MOD=1e9+7;


int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	string S,T;
	cin >> S >> T;
	map<char,char> s,t;
	ll k=0;
	FOR(i,0,S.size()){
		if(int(s[S[i]])==0){
			s[S[i]] = 'a'+k;
			k++;
		}
		S[i] = s[S[i]];
	}
	k=0;
	FOR(i,0,T.size()){
		if(int(t[T[i]])==0){
			t[T[i]] = 'a'+k;
			k++;
		}
		T[i] = t[T[i]];
	}
	if(S==T)cout << "Yes" << endl;
	else cout << "No" << endl;
}

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

int A, B, K; vector<int>vec;

int main() {
	cin >> A >> B >> K;
	for (int i = A; i < A + K; i++) { if (A <= i && i <= B) vec.push_back(i); }
	for (int i = B - K + 1; i <= B; i++) { if (A <= i && i <= B) vec.push_back(i); }
	sort(vec.begin(), vec.end());
	vec.erase(unique(vec.begin(), vec.end()), vec.end());
	for (int i = 0; i < vec.size(); i++) cout << vec[i] << endl;
	return 0;
}

Measured memory_bytes: 256
package main

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

const (
	frameSymbol = "#"
	innerSymbol = "."
)

var scan = bufio.NewScanner(os.Stdin)

func main() {
	scanWords()

	for {
		height := readNextInt()
		width := readNextInt()

		if height == 0 && width == 0 {
			break
		}

		printFrame(height, width)
		fmt.Println()
	}
}

func scanWords() {
	scan.Split(bufio.ScanWords)
}

func readNextInt() int {
	scan.Scan()

	input, err := strconv.Atoi(scan.Text())
	if err != nil {
		panic(err)
	}
	return input
}

func printFrame(height, width int) {
	for h := 0; h < height; h++ {
		for w := 0; w < width; w++ {
			if h == 0 || h == height-1 {
				fmt.Print(frameSymbol)
			} else if w == 0 || w == width-1 {
				fmt.Print(frameSymbol)
			} else {
				fmt.Print(innerSymbol)
			}
		}
		fmt.Println()
	}
}



Measured memory_bytes: 1092
#include <bits/stdc++.h>
#define sz(arr) (int)arr.size()
#define all(arr) arr.begin(), arr.end()

using namespace std;
typedef long long ll;

void _cin() {}
template <class Head, class... Tail>
void _cin(Head&& head, Tail&&... tail) {
  cin >> head;
  _cin(forward<Tail>(tail)...);
}

#define Cin(T, ...) \
  T __VA_ARGS__;    \
  _cin(__VA_ARGS__)

int main() {
  Cin(int, n, d, x);
  vector<int> a(n);
  for (int i = 0; i < n; ++i) cin >> a[i];

  int ans = 0;
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j * a[i] + 1 <= d; ++j) {
      ans++;
    }
  }

  cout << ans + x << endl;

  return 0;
}

Measured memory_bytes: 256
#include <iostream>

static const int MAX_WEIGHT = 50;
static const int MAX_HEIGHT = 50;

static int total_cicada[MAX_WEIGHT][MAX_HEIGHT];

void set_total_cicada(int weight, int height)
{
	char in;
	int  cicada;
	
	for (int h = 0; h < height; h++)
	{
		for (int w = 0; w < weight; w++)
		{
			std::cin >> in;
            cicada = in - '0';
            
			if (w == 0 && h == 0)
			{
				total_cicada[w][h] = 0;
			}
			else if (w == 0)
			{
				total_cicada[w][h] = total_cicada[0][h - 1] + cicada;
			}
			else if (h == 0)
			{
				total_cicada[w][h] = total_cicada[w - 1][0] + cicada;
			}
			else
			{
				total_cicada[w][h] = std::min( total_cicada[w - 1][h], total_cicada[w][h - 1]) + cicada;
			}
		}
	}

	return;
}

int main()
{
	using namespace std;

	int weight,height;
	
	cin >> height >> weight;
	
	set_total_cicada(weight, height);
	
	cout << total_cicada[weight - 1][height - 1] << endl;
	
	return 0;
}

Measured memory_bytes: 3104
n,k = gets.split.map!(&:to_i)

count = Array.new(10**5+1,0)
n.times do
    a,b = gets.split.map!(&:to_i)
    count[a] += b
end

min_k = 0
i = 0
while min_k < k
    min_k += count[i]
    i += 1
end

puts i-1

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

int main()
{
    long long n, m;
    cin >> n >> m;
    if(2*n >= m) {
        cout << m / 2 << endl;
    }else {
        if(m % 2 != 0) {
            --m;
        }
        cout << (m + 2*n) / 4 << endl;
    }
}


Measured memory_bytes: 256
import static java.lang.System.*;
import java.util.*;

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

		int l = sc.nextInt();
        int n = sc.nextInt();
		
		int[] x = new int[n];
		for(int i=0; i<n; i++) x[i] = sc.nextInt();
		
		//ゴールを決めた時、全部最後にジグザグしたの方が経路が長くなる
		long ans = Math.max(x[n-1], l-x[0]); //ジグザグなし
		
		long now = x[n-1]; //最初に正方向に移動
		for(int i=2; i<=n; i++) {
			now += l;
			now -= (x[n-i/2] - x[n-i]) * 2;
			if(i%2==1) now += (x[n-i/2]-x[n-i/2-1]);
			
			ans = Math.max(ans, now);
		}

		now = l - x[0]; //最初に負方向に移動
		for(int i=0; i<n-1; i++) {
			now += l;
			now -= (x[i+1] - x[i/2]) * 2;
			if(i%2==1) now += (x[i/2+1]-x[i/2]);
			
			ans = Math.max(ans, now);
		}
		
        out.println(ans);
    }
}

Measured memory_bytes: 80912
/*
	B - Varied
*/
#define _USE_MATH_DEFINES
#include <algorithm>
#include <cstdio>
#include <functional>
#include <iostream>
#include <cfloat>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <vector>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> i_i;
typedef pair<ll, int> ll_i;
typedef pair<double, int> d_i;
typedef pair<ll, ll> ll_ll;
typedef pair<double, double> d_d;

double EPS = 1e-10;

#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
#define int(x) int x; cin >> x;
#define lint(x) long long x; cin >> x;
#define vint(v,n) vector<int> v(n); REP(i,n) cin >> v[i];
#define vlint(v,n) vector<lint> v(n); REP(i,n) cin >> v[i];
#define double(x) double x; cin >> x[i];
#define vdouble(v,n) vector<double> v(n); REP(i,n) cin >> v[i];
#define string(x) string x; cin >> x;

int main()
{
	string(s);
	int *array = new int[26];
	for (int i = 0; i < 26; i++)
	{
		array[i] = 0;
	}

	for (int i = 0; i < s.length(); i++)
	{
		if (array[(int)s[i] - 97])
		{
			cout << "no" << endl;
			return 0;
		}
		else
		{
			array[(int)s[i] - 97]++;
		}
	}

	cout << "yes" << endl;
	return 0;
}

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

#define ll long long
#define ull unsigned long long
#define inf 0x3f3f3f3f
#define met(a, x) memset(a,x,sizeof(a))
#define mp make_pair;

using namespace std;
const int mod = 19e+7;
const int N = 1e5 + 10;
const int M = 1e6 + 10;
int a[N];

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int n;
    cin>>n;
    for (int i = 1; i <= n; i++) {
        cin >> a[i];
    }
    int flag = 0;
    int cnt = 1;
    for (int i = 2; i <= n; i++) {
        if (a[i] > a[i - 1]) {
            if (flag == 1) {
                cnt++;
                flag=0;
            }
            else
            flag = 2;
        } else if (a[i] < a[i - 1]) {
            if (flag == 2) {
                cnt++;
                flag=0;
            }
            else
            flag = 1;
        }
    }
    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <cstdlib>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#define MAXS 100000;
#define p pair <int,int>
using namespace std;
int main(int argc,char const* argv[])
{
  int n,x;
  cin >> n >> x;
  vector<long long> a(n,0);
  long long int count=0;
  for(int i=0;i<n;i++)
    {
      cin >> a[i];
    }
  for(int i=0;i<n-1;i++)
    {
      while(a[i]+a[i+1]>x)
	{
	  if(a[i+1]>=0 && a[i+1]>=a[i]+a[i+1]-x)
	    {
	      count+=(a[i]+a[i+1]-x);
	      a[i+1]-=(a[i]+a[i+1]-x);
	    }
	  else  if(a[i+1]>=0 && a[i+1]<a[i]+a[i+1]-x)
	    {
	      count+=a[i+1];
	      count+=(a[i]-x);
	      a[i]-=(a[i]-x);
	      a[i+1]=0;
	    }
	}
    }
  cout << count << endl;
  return 0;
}

Measured memory_bytes: 1024
package main

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

func getScanner(fp *os.File) *bufio.Scanner {
	scanner := bufio.NewScanner(fp)
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 500001), 500000)
	return scanner
}

func getNextString(scanner *bufio.Scanner) string {
	scanner.Scan()
	return scanner.Text()
}

func getNextInt(scanner *bufio.Scanner) int {
	i, _ := strconv.Atoi(getNextString(scanner))
	return i
}

func getNextInt64(scanner *bufio.Scanner) int64 {
	i, _ := strconv.ParseInt(getNextString(scanner), 10, 64)
	return i
}

func getNextUint64(scanner *bufio.Scanner) uint64 {
	i, _ := strconv.ParseUint(getNextString(scanner), 10, 64)
	return i
}

func getNextFloat64(scanner *bufio.Scanner) float64 {
	i, _ := strconv.ParseFloat(getNextString(scanner), 64)
	return i
}

func main() {
	fp := os.Stdin
	wfp := os.Stdout

	if os.Getenv("MASPY") == "ますピ" {
		fp, _ = os.Open(os.Getenv("BEET_THE_HARMONY_OF_PERFECT"))
	}
	if os.Getenv("MASPYPY") == "ますピッピ" {
		wfp, _ = os.Create(os.Getenv("NGTKANA_IS_GENIUS10"))
	}

	scanner := getScanner(fp)
	writer := bufio.NewWriter(wfp)

	n := getNextInt64(scanner)
	a := getNextInt64(scanner)
	b := getNextInt64(scanner)

	ans := (b - a) * (n - 2)
	if ans < 0 {
		ans = -1
	}
	fmt.Println(ans + 1)
	writer.Flush()
}


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

int main() {

	int n; cin>>n;
	int mx = 0;
	for(int i = 1; i<=n; i++){
		int a; cin>>a;
		
		if((mx - a) > 1){
			cout<<"No\n";
			return 0;
		}
		
		mx = max(mx, a);
		
	}
	
	cout<<"Yes\n";
	
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>

int main(){
  int b;
  int i,k,num,v;

  scanf("%d",&num);
  int a[num];
 for(i=0; i<num; i++){
   scanf("%d",&a[i]);
 }

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

   v = a[i];
   b = i - 1;

   while(b>=0 && a[b] > v){
     a[b+1] = a[b];
     b--;
     a[b+1] =v;
   }
   for(k=0; k<num; k++){
     if(k!=num-1)printf("%d ",a[k]);
     else{
       printf("%d",a[k]);
     }
   }
 printf("\n");
}
return 0;
}



Measured memory_bytes: 2084
use std::io::{self, Read, Write};

#[rustfmt::skip] #[macro_use] #[allow(unused_macros)]
mod rwc {
    macro_rules! rd { ($buf:ident, $t:ty)       => { $buf.next().unwrap().parse::<$t>().ok().unwrap() }; }
    macro_rules! wt { ($out:ident, $($arg:tt)*) => { write!($out, $($arg)*).ok()                      }; }
    macro_rules! cv { ($n:expr, $fn:expr)       => { (0..$n).map($fn).collect::<Vec<_>>()             }; }
}

fn main() {
    let (mut _buf, mut _out) = (String::new(), io::stdout());
    let (mut _buf, mut _out) = {
        io::stdin().read_to_string(&mut _buf).ok();
        (_buf.split_whitespace(), io::BufWriter::new(_out.lock()))
    };

    let r = rd!(_buf, f64);
    wt!(_out, "{:.10}\n", 2.0 * 3.1415 * r);
}


Measured memory_bytes: 2212
#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <stack>
#include <string>
#include <unordered_set>
#include <vector>

using namespace std;
using LLONG = long long;
const LLONG MOD = 998244353;

// d[i][s][t] = i番目まで考えたとき和がsになる場合の数
LLONG dp[3001][3001][3];

int main()
{
    int N, S;  cin >> N >> S;
    vector<int> As(N);
    for (auto &Ai : As) cin >> Ai;
    dp[0][0][0] = 1;
    // i番目まで考えたとき和がsになる場合の数を全て計算:O(NS)
    for (int i = 0; i < N; ++i)
    {
        for (int s = 0; s <= S; ++s)
        {    
            // --- Aiを和に加えない場合 --------
            // t = 0 : L, Rともに未定
            (dp[i + 1][s][0] += dp[i][s][0]) %= MOD;
            // t = 1 : Lのみ確定
            (dp[i + 1][s][1] += dp[i][s][0] + dp[i][s][1]) %= MOD;
            // t = 2 : L, Rともに確定
            (dp[i + 1][s][2] += dp[i][s][0] + dp[i][s][1] + dp[i][s][2]) %= MOD;
            // --- Aiを和に加える場合 --------
            // 和がS以下になる場合の数を全て記録していく
            int tmpSum = s + As[i];
            if (tmpSum <= S)
            {
                (dp[i + 1][tmpSum][1] += dp[i][s][0] + dp[i][s][1]) %= MOD;
                (dp[i + 1][tmpSum][2] += dp[i][s][0] + dp[i][s][1]) %= MOD;
            }
        }
    }
    cout << dp[N][S][2] << endl;
}


Measured memory_bytes: 211328
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <complex>
#include <cstring>
#include <cstdlib>
#include <string>
#include <cmath>
#include <cassert>
#include <queue>
#include <set>
#include <map>
#include <valarray>
#include <bitset>
#include <stack>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
const int INF = 1<<29;

const double EPS = 1e-8;
typedef complex<double> P;
namespace std {
  bool operator < (const P& a, const P& b) {
    return real(a) != real(b) ? real(a) < real(b) : imag(a) < imag(b);
  }
}
double cross(const P& a, const P& b) {
  return imag(conj(a)*b);
}
double dot(const P& a, const P& b) {
  return real(conj(a)*b);
}

struct L : public vector<P> {
  L(const P &a, const P &b) {
    push_back(a); push_back(b);
  }
  L() {}
};

typedef vector<P> G;

#define curr(P, i) P[i]
#define next(P, i) P[(i+1)%P.size()]
struct C {
  P p; double r;
  C(const P &p, double r) : p(p), r(r) { }
};

int ccw(P a, P b, P c) {
  b -= a; c -= a;
  if (cross(b, c) > 0)   return +1;       // counter clockwise
  if (cross(b, c) < 0)   return -1;       // clockwise
  if (dot(b, c) < 0)     return +2;       // c--a--b on line
  if (norm(b) < norm(c)) return -2;       // a--b--c on line
  return 0;
}
double area(const G& g) {
  double A = 0;
  for (int i = 0; i < g.size(); ++i) {
    A += cross(g[i], next(g, i));
  }
  return A/2;
}
P crosspoint(const L &l, const L &m) {
  double A = cross(l[1] - l[0], m[1] - m[0]);
  double B = cross(l[1] - l[0], l[1] - m[0]);
  if (abs(A) < EPS && abs(B) < EPS) return m[0]; // same line
  if (abs(A) < EPS) assert(false); // !!!PRECONDITION NOT SATISFIED!!!
  return m[0] + B / A * (m[1] - m[0]);
}

G convex_cut(const G& g, const L& l) {
  G Q;
  REP(i, g.size()) {
    P A = curr(g, i), B = next(g, i);
    if (ccw(l[0], l[1], A) != -1) Q.push_back(A);
    if (ccw(l[0], l[1], A)*ccw(l[0], l[1], B) < 0)
      Q.push_back(crosspoint(L(A, B), l));
  }
  return Q;
}
// Cð½·àÌªlb¤É èACð½·ÅålðßéÆ«BCð½·àÌª³¢Æ«ÌÉÓB
template<class T> T upper_search(T lb, T ub, bool (*C)(T)) {
  REP(i,100) { // ±±ÍKÉ
    T mid = (lb+ub)/2;
    if (C(mid)) lb = mid;       // Å¬lðßéÈçlbÆubðüêÖ¦é
    else ub = mid;
  }
  return lb;
}
const double PI = acos(-1);
P rotate(P p, double ang) {
  return p*P(cos(ang), sin(ang));
}
G g;
bool C(double x) {
  G hoge(g);
  REP(i, g.size()) {
    L l(g[i], next(g, i));
    P p = rotate(l[1]-l[0], PI/2);
    p *= x/abs(p);
    l = L(l[0]+p, l[1]+p);
    hoge = convex_cut(hoge, l);
    if (hoge.size() == 0) return 0;
  }
  // printf("%.6f", x);
  // cout  << " " << area(hoge) << endl;
  return 1;
}
int main() {
    int n;
  while(cin>>n,n) {
    g.clear();
    REP(i, n) {
      int a, b;
      cin >> a >> b;
      g.push_back(P(a,b));
    }
    double ans = upper_search<double>(0, INF, C);
    printf("%.6f\n", ans);
  }
}

Measured memory_bytes: 976
S = input()
table = {
    'S':'0',
    'R':'1'
}
b_S = ''.join(table.get(c, c) for c in S)

r_1 = 0
r_2 = 0
result = 0
for s in b_S:
# 連続フラグ
    if int(s) == 1 and r_1 == 1:
        r_2 = 1
    else:
        r_2 = 0
# 1出現フラグ
    if int(s) == 1:
        r_1 = 1
    else:
        r_1 = 0
# 結果を更新
    if r_2 == 1:
        result = result + 1

# '1'が出現していれば1を追加する
if '1' in b_S:
    result = result + 1
print(result)

Measured memory_bytes: 9072
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main(void){
char s[100];
int count,flg=0,counthoji;
char tmp;
char ans[]="KIHBR";
scanf("%s",s);
for(count=0;s[count]!='\0';count++){
if(s[count]=='A'&&s[count+1]=='A'){
    printf("NO");
    return 0;
}
  if(s[count-1]=='I'&&s[count]=='A'&&s[count+1]=='H'){
    printf("NO");
    return 0;
}
  if(s[count-1]=='K'&&s[count]=='A'&&s[count+1]=='I'){
    printf("NO");
    return 0;
}
}
for(;;){
flg=0;
for(count=0;s[count]!='\0';count++){
if(s[count]=='A'){s[count]='0';flg=1;counthoji=count;break;}
}
if(flg==0){break;}
for(count=counthoji;;count++){
s[count]=s[count+1];
if(s[count]=='\0'){break;}
}
 
}
if(strcmp(s,ans) == 0){printf("YES");}
else{printf("NO");}
 
 
return 0;
}

Measured memory_bytes: 128
import java.util.Scanner

object Main extends App {
  val sc = new Scanner(System.in)
  val x = sc.nextInt()
  val y = sc.nextInt()

  val a = Set(1, 3, 5, 7, 8, 10, 12)
  val b = Set(4, 6, 9, 11)

  println(if (x != 2 && y != 2 && (a.contains(x) && a.contains(y) || b.contains(x) && b.contains(y))) "Yes" else "No")
}

Measured memory_bytes: 26944
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define FORR(i, m, n) for (int i = m; i >= n; i--)
#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define ll long long
#define ull unsigned long long
#define pb(a) push_back(a)
#define INF 999999999
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

int dy[] = {0, 0, 1, -1, 0};
int dx[] = {1, -1, 0, 0, 0};

int main()
{
    int a, p;
    cin >> a >> p;

    cout << ((a * 3) + p) / 2 << endl;
}


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


#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define RFOR(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep1(i, n) for (int i = 1; i < (n); i++)
#define rrep(i, n) for (int i = (n)-1; i >= 0; i--)
#define all(i) (i).begin(), (i).end()
#define rall(i) (i).begin(), (i).end(), greater<int>()

#define int long long

#define elif else if
#define eb emplace_back
#define pb push_back
#define mp make_pair
#define fst first
#define sec second

#define mod 1000000007

template <typename T>
void print(T x)
{
	std::cout << x <<" " ;
}


template <typename T>
void println(T x)
{
	std::cout << x << "\n";
}

int RepeatSquaring(int n,int x) {
	if (x == 0) return 1;
	else if (x % 2 == 0) {
		int div = RepeatSquaring(n, x / 2);
		return div*div%mod;
	}
	return n*RepeatSquaring(n,x-1)%mod;
}

int c(int n, int a) {
	int x = 1;
	int y = 1;
	rep(i, a) {
		y *= a - i;
		x *= n - i;
		y %= mod;
		x %= mod;
	}
	return (x*RepeatSquaring(y,mod-2))%mod;
}


signed main(void) {
	int N,a,b;
	cin >> N >>a>>b;
	int ans = RepeatSquaring(2, N) - 1;
	ans -= c(N, a);
	if (ans < 0)ans += mod;
	ans -= c(N, b);
	if (ans < 0)ans += mod;
	print((ans%mod));
}

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

using namespace std;

#define int long long

const int mod = 1e9 + 7;

int n;

int f[1000001][4], g[1000001][4];

int dp(int pos, int mask)
{
	if (pos > n)
		return (mask == 3);
	if (g[pos][mask])
		return f[pos][mask];
	int cur = 0;
	(cur += dp(pos + 1, mask | 1)) %= mod;
	(cur += dp(pos + 1, mask | 2)) %= mod;
	(cur += 8 * dp(pos + 1, mask)) %= mod;			
	g[pos][mask] = 1;
	return f[pos][mask] = cur;
}

int32_t main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);

	cin >> n;
	cout << dp(1, 0);
}

Measured memory_bytes: 113004
#include<bits/stdc++.h>				//edit by thidailoc
using namespace std;				//team three wolves
typedef long long ll;
typedef vector<ll> vi;
#define fu(i,a,b)   for(ll i=a;i<b;i++)
#define fd(i,b,a)   for(ll i=b;i>=a;i--)
#define pb(i)	    push_back(i)
#define popb()    	pop_back()
#define sc(a) 	    scanf("%lld",&a)
#define sc2(a,b)    scanf("%lld%lld",&a,&b)
#define pr(a)	    printf("%lld ",a)
#define pr2(a,b)    printf("%lld %lld",a,b)
#define lowb(a,n,x) lower_bound(a,a+n,x) -a
#define lowb2(a,x)	lower_bound(a.begin(),a.end(),x) -a.begin()
#define all(x) 		(x).begin(), (x).end()
#define sz(a) 		(ll)a.size()
#define le			length()						
#define re 			return 	
#define debug(x)    cerr << #x << " = " << x << endl
#define INPUT       freopen("locin.txt", "r", stdin)
#define OUTPUT      freopen("locout.txt", "w", stdout)

double const eps = 1e-6;	//dung trong sai so
ll const Base=1e9+7;
ll mark[1000][1000];
class Info{
	public: ll v,cnt;
};
bool cmp_v(Info a,Info b){
	return a.v<b.v;
}
Info arr[100005];
ll Solves(){
//	INPUT;
	ll n,m,k,cnt=0,ans=0,x,a,b,c;
	// PROCESSING IN HERE
	sc2(n,k);
	fu(i,0,n){
		sc2(arr[i].v,arr[i].cnt);
	}
	sort(arr,arr+n,cmp_v);
	x=0;
	while(k>arr[x].cnt){
		k-=arr[x++].cnt;
	}
	pr(arr[x].v);
	re 0;
}


int main(){
	Solves();
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef long double ld;
using pll=pair<ll,ll>;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define rep2(i,l,r) for(ll i = (l); i <= (ll)(r); i++)
#define rep3(i,l,r) for(ll i = (l); i >= (ll)(r); i--)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const int inf = 1001001001;
const ll INF = 1LL << 60;
const ll mod = 1000000007;
const ld pi = acos(-1);
 
// union by size + path having
class UnionFind {
public:
   vector <ll> par; // 各元の親を表す配列
   vector <ll> siz; // 素集合のサイズを表す配列(1 で初期化)
 
   // Constructor
   UnionFind(ll sz_): par(sz_),siz(sz_, 1LL){
       for (ll i=0; i<sz_; i++) par[i]=i; // 初期では親は自分自身
   }
   void init(ll sz_){
       par.resize(sz_);
       siz.assign(sz_, 1LL);  // resize だとなぜか初期化されなかった
       for (ll i=0; i<sz_; i++) par[i]=i; // 初期では親は自分自身
  }
 
   // Member Function
   // Find
   ll root(ll x){ // 根の検索
      while (par[x]!=x){
           x=par[x]=par[par[x]]; // x の親の親を x の親とする
       }
       return x;
  }
 
   // Union(Unite, Merge)
   bool unite(ll x, ll y){
       x=root(x);
       y=root(y);
       if (x==y) return false;
       // merge technique（データ構造をマージするテク．小を大にくっつける)
       if (siz[x]<siz[y]) swap(x, y);
       siz[x]+=siz[y];
       par[y]=x;
       return true;
  }
 
  bool same(ll x, ll y){ // 連結判定
       return root(x)==root(y);
  }
 
  ll size(ll x){ // 素集合のサイズ
      return siz[root(x)];
  }
};
 
ll modpow(ll x, ll n){
   x=x%mod;
   if(n==0) return 1;  //再帰の終了条件
 
   else if(n%2==1){
       return (x*modpow(x, n-1))%mod;  //nが奇数ならnを1ずらす
   }
   else return modpow((x*x)%mod, n/2)%mod;  //nが偶数ならnが半分になる
}
 
ll com(ll n, ll k){
   ll x=1;
   for(int i=n-k+1; i<=n; i++){
      x=x*i%mod;
   }
 
   ll y=1;
   for(int i=1; i<=k; i++){
       y=y*i%mod;
   }
   y=modpow(y, mod-2);
 
   return x*y%mod;
}
 
bool is_prime(const unsigned n){
   switch(n){
       case 0: // fall-through
       case 1: return false;
       case 2: // fall-through
       case 3: return true;
  } // n>3 が保証された
 
   if(n%2==0 || n%3==0) return false;
   // nは2と3のいずれの倍数でもないことが保証された
   // これよりnは(6の倍数)-1か(6の倍数)+1である
 
   // 6の倍数前後の数を使って試し割りをする
   for(unsigned i = 5; i*i<=n; i+=6) {
       if(n%i==0) return false; // (6の倍数)-1
       if(n%(i+2)==0) return false; // (6の倍数)+1
   }
 
   return true;
}
 
int digsum(int n){
   int res=0;
   while(n > 0) {
       res+=n%10; //ここをres++;に変えたら桁数を求める関数になる,res+=n%10;なら格桁の和
       n/=10;
   }
   return res;
}
vector<ll> divisor(ll n){
   vector<ll> ret;
   for(ll i=1; i*i<=n; i++){
       if(n%i==0){
           ret.push_back(i);
           if(i*i!=n) ret.push_back(n/i);
       }
   }
   sort(ret.begin(),ret.end());
   return ret;
}
 
int main(){

    ll x,y;
    cin >> x >> y;
    rep(i,x+1){
        if(i*2+(x-i)*4==y){
            cout << "Yes" << endl;
            return 0;
        }
        else{
            continue;
        }
    }

    cout << "No" << endl;
 
}

Measured memory_bytes: 3624
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskB solver = new TaskB();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskB {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int n = in.nextInt();
            int m = in.nextInt();
            int[] count = new int[n];
            Arrays.fill(count, 1);
            boolean[] canHaveRed = new boolean[n];
            canHaveRed[0] = true;
            int numCanHaveRed = 1;
            for (int i = 0; i < m; ++i) {
                int a = in.nextInt() - 1;
                int b = in.nextInt() - 1;
                if (canHaveRed[a] && !canHaveRed[b]) {
                    canHaveRed[b] = true;
                    ++numCanHaveRed;
                }
                if (count[a] == 1 && canHaveRed[a]) {
                    canHaveRed[a] = false;
                    --numCanHaveRed;
                }
                --count[a];
                ++count[b];
            }
            out.println(numCanHaveRed);
        }

    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

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

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

    }
}



Measured memory_bytes: 21080
import bisect

n, d, a = map(int, input().split())
XB = []
X = []
for _ in range(n):
    x, h = map(int, input().split())
    bomb = int(-(-h//a))
    XB.append([x, bomb])
    X.append(x)

XB = sorted(XB, key=lambda x:x[0])
X = sorted(X)

# x1+dがx2-d以上のときに、まとめてダメージを与えられる
# x2がダメージを受けうる、x1を二分探索する

X_range = [[-1]]

for i in range(1,n):
    now = X[i]
    # X[x_ind]以上の爆弾ダメージをX[i]は受ける
    x_ind = bisect.bisect_left(X, X[i]-2*d)
    if x_ind == i:
        X_range.append([-1])
    else:
        X_range.append([x_ind, i-1])

# print(X)

# 各箇所で何回爆弾を使用したのかを保持 -> 累積しておく
# X[i]を見るときに、X[i-1]~X[ind]間で使用した爆弾の個数を求める
# 足りない文はX[i]で爆発させる

Bomb = [XB[0][1]]
Bomb_rui = [0, XB[0][1]]

for i in range(1,n):
    need_bomb = XB[i][1]
    if X_range[i][0] == -1:
        Bomb.append(need_bomb)
        Bomb_rui.append(Bomb_rui[-1]+need_bomb)
    else:
        before_bomb = Bomb_rui[X_range[i][1]+1] - Bomb_rui[X_range[i][0]]
        if before_bomb >= need_bomb:
            Bomb.append(0)
            Bomb_rui.append(Bomb_rui[-1])
        else:
            need_bomb -= before_bomb
            Bomb.append(need_bomb)
            Bomb_rui.append(Bomb_rui[-1]+need_bomb)

ans = Bomb_rui[-1]
# print(Bomb)
# print(Bomb_rui)
# print(X_range)
print(ans)

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

int main() {
  long long D,T,S;
  cin >> D >> T >> S;
  if (D>T*S) {
    cout << "No" << endl;
  }
  if (D<=T*S) {
    cout << "Yes" << endl;
  }
}

Measured memory_bytes: 3672
#include<iostream>
#include<string>
#include<vector>
#include<list>
#include<cmath>
#include<algorithm>
#include<cstdio>
#include<set>
#include<map>
#include<queue>
#include<cstring>
#include<sstream>
using namespace std;

typedef long long ll;

int main() {
  int N; cin >> N;
  int T[1001],A[1001];
  ll a = 1,b = 1;
  for ( int i = 0; i < N; i++ ) cin >> T[i] >> A[i];
  for ( int i = 0; i < N; i++ ) {
    ll n = max((a-1)/T[i],(b-1)/A[i])+1;
    a = n*T[i];
    b = n*A[i];
  }
  cout << a+b << endl;
  return 0;
}


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

int main(){
    int n,x;
    cin>>n>>x;
    vector<int>a(n),b(n);
    rep(i,n)cin>>a[i];
    a.push_back(x);
    sort(a.begin(),a.end());
    rep(i,n)b[i]=abs(a[i]-a[i+1]);
    int ans=0;
    rep(i,n)ans=__gcd(ans,b[i]);
    cout<<ans<<endl;
}

Measured memory_bytes: 1408
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <functional>
#include <vector>
#include <map>
#include <stack>
#include <string>
#include <list>
#include <math.h>
using namespace std;

typedef pair<int, int> P;
#define ll long long
#define mod 1000000007


int main(){

	ll N, a[300000];
	cin >> N;
	for (int i = 0; i < 3 * N; i++)
		cin >> a[i];

	sort(a, a + 3 * N, greater<ll>());

	ll r = 0;
	for (int i = 0; i < N; i++)
		r += a[i * 2 + 1];

	cout << r << endl;


	return 0;
}

Measured memory_bytes: 2560
#include <bits/stdc++.h>
#include <math.h>
#define _GLIBCXX_DEBUG
using namespace std;
int main() {
  
  int N;
  cin>>N;
  
  vector<int> A(N);
  for(int i=0;i<N;i++){
    cin>>A[i];
  }
  sort(A.begin(),A.end());
  
  bool res=true;
  
  
  for(int i=0;i<N-1;i++){
    if(A[i]==A[i+1]){
      res=false;
    }
  }
  
  
  if(res){
    cout<<"YES"<<endl;
  }
  else{
    cout<<"NO"<<endl;
  }
}

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

int numEven[100010], numOdd[100010];

int main(){
    int n, v[100010];
    cin >> n;
    for(int i = 0; i < n; i++){
        cin >> v[i];
        if(i%2==0){
            numEven[v[i]]++;
        }else{
            numOdd[v[i]]++;
        }
    }
    
    int numEvenMax = 0, numOddMax = 0;
    int numEvenMax2 = 0, numOddMax2 = 0;
    int numEvenMaxI = 0, numOddMaxI = 0;
    int numEvenMaxI2 = 0, numOddMaxI2 = 0;
    for(int i = 1; i < 100001; i++){
        if(numEvenMax < numEven[i]){
            numEvenMax2 = numEvenMax;
            numEvenMaxI2 = numEvenMaxI;
            numEvenMax = numEven[i];
            numEvenMaxI = i;
        }else if(numEvenMax2 < numEven[i]){
            numEvenMax2 = numEven[i];
            numEvenMaxI2 = i;
        }
        if(numOddMax < numOdd[i]){
            numOddMax2 = numOddMax;
            numOddMaxI2 = numOddMaxI;
            numOddMax = numOdd[i];
            numOddMaxI = i;
        }else if(numOddMax2 < numOdd[i]){
            numOddMax2 = numOdd[i];
            numOddMaxI2 = i;
        }
    }
    
    int ret;
    if(numEvenMaxI != numOddMaxI){
        ret = n/2 - numEvenMax + n/2 - numOddMax;
        // cout << n/2 - numEvenMax <<','<< n/2 - numOddMax;
    }else{
        int ret1 = n/2 - numEvenMax + n/2 - numOddMax2;
        int ret2 = n/2 - numEvenMax2 + n/2 - numOddMax;
        // cout << n/2 - numEvenMax <<','<< n/2 - numOddMax << endl;
        // cout << numEvenMax << "," << numOddMax << endl;
        // cout << numEvenMax2 << "," << numOddMax2 << endl;
        ret = min(ret1, ret2);
    }
    
    cout << ret << '\n';
    
    
    return 0;
}

Measured memory_bytes: 4772
#include<bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize ("-ffloat-store") // to restrict undesirable precision
#pragma GCC optimize ("-fno-defer-pop")// to pop argument of function as soon as it returns
#define all(a) a.begin(),a.end()
#define ll long long int
#define ld long double
ll power(ll a,ll b,ll m){ if(b==0) return 1; if(b==1) return a%m; ll t=power(a,b/2,m)%m; t=(t*t)%m; if(b&1) t=((t%m)*(a%m))%m; return t;}
ll modInverse(ll a, ll m) { return power(a, m-2, m); }
#define ps push_back
#define fs first
#define sc second
#define takeline cin.ignore();
#define iactive cout.flush();
#define N 3000005
#define endl "\n"
#define mod 1000000007
//((1.0l)*BIG MULTIPLY MAGIC?)
// string to integer stoi()
// string to long long stoll()
// string.substr(position,length);
// integer to string to_string();
//-----------------------------------------------
int main(){

	ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
	
	ll ar[]={1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
	ll k;
	cin>>k;
	cout<<ar[k-1];
	
	return 0;
}

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

int main()
{
    int table[] = { 0, 6000, 4000, 3000, 2000 };
    for ( int i = 0; i < 4; i++ ) {
        int t, n;
        cin >> t >> n;
        cout << table[t] * n << endl;
    }
    return ( 0 );
}



Measured memory_bytes: 3108
#include <iostream>
#include <cstring>
#include <stdlib.h>
#include <vector>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <math.h>

using namespace std;
int dp[101][4][4][4];

int main()
{
    int n;
    cin >> n;
    int mod=1000000007;

    dp[0][3][3][3]=1;

    //len:文字数,c1c2c3:最後から1,2,3文字目,a:新しく追加する文字
    for(int len=0; len<n; len++){
        for(int c1=0; c1<4; c1++){
            for(int c2=0; c2<4; c2++){
                for(int c3=0; c3<4; c3++){
                    if(dp[len][c1][c2][c3]==0) continue;

                    for(int a=0; a<4; a++){
						if (a == 2 && c1 == 1 && c2 == 0) continue;
						if (a == 2 && c1 == 0 && c2 == 1) continue;
						if (a == 1 && c1 == 2 && c2 == 0) continue;
						if (a == 2 && c1 == 1 && c3 == 0) continue;
						if (a == 2 && c2 == 1 && c3 == 0) continue;

                        dp[len+1][a][c1][c2]+=dp[len][c1][c2][c3];
                        dp[len+1][a][c1][c2]%=mod;
                    }
                }
            }
        }
    }

    int ans=0;
    for(int c1=0; c1<4; c1++){
        for(int c2=0; c2<4; c2++){
            for(int c3=0; c3<4; c3++){
                    ans+=dp[n][c1][c2][c3];
                    ans%=mod;
            }
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
	static final int INF = Integer.MAX_VALUE/2;
	static final int mod = (int)1e9+7;
	static int n, c[], cnt, ans[], score;
	static List<Integer>[] graph;
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		graph = new ArrayList[n];
		for(int i=0;i<n;i++) graph[i] = new ArrayList<>();
		for(int i=0;i<n-1;i++) {
			int a = sc.nextInt()-1, b = sc.nextInt()-1;
			graph[a].add(b);
			graph[b].add(a);
		}
		c = new int[n];
		for(int i=0;i<n;i++)c[i] = sc.nextInt();
		sc.close();
		Arrays.sort(c);
		cnt = 0;
		ans = new int[n];
		dfs(0,-1);
		StringBuilder sb = new StringBuilder();
		for(int i=0;i<n;i++) {
			sb.append(ans[i] + " ");
		}
		score -= c[n-1];
		System.out.println(score);
		System.out.println(sb.toString());
	}
	
	static void dfs(int v, int p) {
		for(int to:graph[v]) {
			if(to==p)continue;
			dfs(to, v);
		}
		ans[v] = c[cnt++];
		score += ans[v];
	}	
}



Measured memory_bytes: 45952
#include<iostream>
#include<string>
#include <algorithm>

using namespace std;
int main(){
    string str,cmd,p;
    int n,a,b;
    cin >> str;
    cin >> n;
    for(int i = 1;i <= n;i++){
        cin >> cmd >> a >> b ;
        if(cmd == "print"){
           cout << str.substr(a,b - a + 1) << endl;
        } else if(cmd == "reverse"){
            reverse(str.begin() + a,str.begin() + b + 1);
        } else if(cmd == "replace"){
            cin >> p;
            str.replace(a,b - a + 1,p);
        }
    }
    
    return 0;    
}





Measured memory_bytes: 3216
N, K = map(int, input().split())
*V, = map(int, input().split())
ans = 0

for l in range(K + 1):
	for r in range(K - l + 1):
		inHand = []
		if l + r > N:  # Nを超えてしまうありえない場合を処理
			break

		# inHandに左からl個、右からr個の要素を追加
		inHand = V[: l]
		inHand.extend(V[N - r:])
		tmp = sum(inHand)  # 現時点でのinHandの和をtmpとして負の要素をtmpから引いていく

		# inHand中の負の要素を消せるだけ消す
		inHand.sort()
		for i in range(min(K - l - r, l + r)):
			if inHand[i] >= 0:
				break
			tmp -= inHand[i]

		ans = max(ans, tmp)

print(ans)


Measured memory_bytes: 3064
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
using namespace std;
const int mol = 1e9 + 7;
typedef long long LL;

int main()
{
    LL n = 1 , m;
    scanf("%I64d",&m);
    for(int i = 1;  i <= m ; i++){
        n = (n * i)%mol;
    }
    printf("%I64d\n",n);
    return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
using namespace std;
 
#define mod 1000000007
#define FOR(x,to) for(int x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
#define long long long
inline int rei(){int x;cin>>x;return x;}
inline long rel(){long x;cin>>x;return x;}
inline string res(){string x;cin>>x;return x;}
//------------------------------------------------------- 
long DP[100000];
int H[100000];
void Calc(){
	int N = rei();
	int K = rei();
	for(int i=0;i<N;i++){
		H[i] = rei();
	}
	for(int i=1;i<N;i++){
		long minval = 100000000000000;
		for(int j=max(0,i-K);j<i;j++){
			minval = min(minval,max(H[i]-H[j],H[j]-H[i])+DP[j]);
		}
		DP[i] = minval;
	}
	cout << DP[N-1] << endl;
}
int main(int argc,char** argv){
	ios::sync_with_stdio(false), cin.tie(0);
	cout.tie(0); Calc(); return 0;
}

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

int main(){
	int n, x, w = 0;
	while (1){
		cin >> n >> x;
		if (n == 0 && x == 0)
			break;
		w = 0;
		for (int i = 1; i <= n; i++){
			for (int j = 1; j < i; j++){
				if (x - (i + j) >= 1 && x - (i + j) <j){
						w++;
				}
			}
		}
		cout << w<<endl;
	}
	return 0;
}

Measured memory_bytes: 1160
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int [] a = {0,1,3,1,2,1,2,1,1,2,1,2,1};
		int x = sc.nextInt();
		int y = sc.nextInt();
		if (a[x] == a[y]) {
			System.out.println("Yes");		
		} else {
			System.out.println("No");
		}
		}
	}

Measured memory_bytes: 21716
import sys

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def combmod(n, r):
    res = 1

    for i in range(r):
        res *= (n - i)
        res %= MOD
        res *= pow((r - i), MOD - 2, MOD)

    nextdiv = n
    nextmul = n - r

    while res > 0:
        yield res
        res *= pow(nextdiv, MOD - 2, MOD)
        res %= MOD
        res *= nextmul
        res %= MOD
        nextdiv -= 1
        nextmul -= 1


def main():
    n0, k0 = list(map(int, readline().split()))
    a0 = list(map(int, readline().split()))

    a0.sort()

    ans = 0

    for i, com in enumerate(combmod(n0 - 1, k0 - 1)):
        ans += a0[-i - 1] * com
        ans %= MOD
        ans -= a0[i] * com
        ans %= MOD

    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 14164
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
	ll a,b;
	cin>>a>>b;
	ll c = __gcd(a,b);
	int numprime = 0;
	for(ll i=2;i*i<=c;++i) {
		if(c%i == 0) {
			numprime++;
			while(c%i==0) {
				c/=i;
			}
		}
	}
	if(c>1) {
		numprime++;
	}
	cout<<numprime+1<<endl;
}

Measured memory_bytes: 256
/*
 * @Author: Kaizyn
 * @Date: 2020-05-07 10:19:05
 * @LastEditTime: 2020-05-07 12:45:57
 */
#include <bits/stdc++.h>

// #define DEBUG

using namespace std;

const int N = 1e5+7;

int n;
long long a[3];
string s[N], res;

int main()
{
    cin >> n >> a[0] >> a[1] >> a[2];
    for (int i = 1; i <= n; ++i) cin >> s[i];
    for (int i = 1; i <= n; ++i) {
        int x = s[i][0]-'A', y = s[i][1]-'A';
        if (a[x]+a[y] == 0) return cout << "No\n", 0;
        if (a[y] == 0) swap(x, y);
        if (a[x] && a[y] && i < n && s[i] != s[i+1]) {
            if (s[i+1][0]-'A' == y || s[i+1][1]-'A' == y) swap(x, y);
        }
        ++a[x]; --a[y];
        res += char(x+'A'); res += '\n';
    }
    cout << "Yes\n" << res;
    return 0;
}

Measured memory_bytes: 6904
#include <bits/stdc++.h>
#define nl ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define ll long long
#define all(v) (v).begin(), (v).end()
#define allr(v) (v).rbegin(), (v).rend()

using namespace std;

int main() {
    nl // NIKI - lowkey
    
    int a, b, t;
    cin >> a >> b >> t;

    cout << t/a*b;
    return 0;
}

Measured memory_bytes: 3652
N,M = map(int,input().split())
A = [list(map(int,input().split())) for _ in range(N)]

s_A = sorted(A)

cost = 0
bought = 0
for n in range(N):
  if bought + s_A[n][1] < M:
    bought += s_A[n][1]
    cost += s_A[n][0]*s_A[n][1]
  else:
    cost += s_A[n][0]*(M-bought)
    break
    
print(cost)

Measured memory_bytes: 28652
def main():
    n = int(raw_input())
    c = [0] * (n-1)
    s = [0] * (n-1)
    f = [0] * (n-1)
 
    for i in range(n-1):
        c[i], s[i], f[i] = map(int, raw_input().split())
 
    for i in range(n):
        t = 0
        for j in range(i, n-1):
            if t < s[j]:
                t = s[j]
            elif t % f[j] == 0:
                pass
            else:
                t += f[j] - t % f[j]
 
            t += c[j]
            
        print t
 

 
if __name__=="__main__":
    main()

    


Measured memory_bytes: 2696
def main():
    N, M = map(int, input().split())
    l = []
    for i in range(M):
        l.append(list(map(int, input().split())))
    s = [1 for i in range(N)]
    r = [0 for i in range(N)]
    r[0] = 1
    for i in range(M):
        x = l[i][0] - 1
        y = l[i][1] - 1
        if r[x] == 1:
            if s[x] == 1:
                r[x] = 0
            r[y] = 1
        s[x] -= 1
        s[y] += 1
    print(sum(r))

main()


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

typedef long long ll;
typedef pair<int, int> P;
#define MOD 1000000007
#define INF (1 << 30)
#define REP(i, m, n) for(int i = (int)m; i < (int)n; ++i)
#define rep(i, n) REP(i, 0, n)


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

    int n, m, k; cin >> n >> m >> k;
    bool flag = false;
    rep(i, n+1) rep(j, m+1) {
        if(i*m + j*n - 2*i*j == k) flag = true; 
    }
    cout << (flag ? "Yes" : "No") << '\n';
    return 0;
}

Measured memory_bytes: 256
from sys import stdin


if __name__ == "__main__":
    _in = [_.rstrip() for _ in stdin.readlines()]
    N = int(_in[0])  # type:int
    a_arr = list(map(int,_in[1].split(' ')))
    # vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
    a_arr.sort(reverse=True)
    cnt = sum(a_arr[1:2*N:2])
    ## ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    print(cnt)


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

int main(){
    int n, k;
    string s;
    cin >> n >> k;
    cin >> s;

    s[k-1] = s[k-1] - 'A' + 'a';
    cout << s << endl;

    return 0;
}




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

using namespace std;

void FAST_IO() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
}

#define REP(_i, _a) for(int _i = 0; _i < _a; ++_i)
#define FOR(_i, _a, _b) for(int _i = _a; _i <= _b; ++_i)
#define FORD(_i, _a, _b) for(int _i = _a; _i >= _b; --_i)
#define RESET(_a, _value) memset(_a, _value, sizeof(_a))
#define ALL(_a) _a.begin(), _a.end()
#define SIZE(_a) _a.size()
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define newline '\n';

typedef long long ll;
typedef pair<int, int> ii;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ii> vii;

const double PI = acos(-1.0);
const int MOD = 1e9 + 7;
const int INF = 2e9;

const int MAX_N = 1e5 + 5;

int suffix_count[MAX_N + 5];

string s;
int n;

int main() {
	FAST_IO();
	
	cin >> s;
	n = s.length();
	
	int ans = n;

	REP(i, n-1) {
		if (s[i] != s[i+1]) {
			ans = min(ans, max(n - i - 1, i + 1));
		}
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 512