akhauriyash/Code-Regression huggingface dataset:
package main

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

var (
	ans string
)

func main() {
	s := readString()
	t := readString()

	if includes(s, t) {
		fmt.Println(strings.Replace(ans, "?", "a", -1))
	} else {
		fmt.Println("UNRESTORABLE")
	}
}

func includes(s, t string) bool {
	for i := len(s) - len(t); i >= 0; i-- {
		c := 0
		for ii := 0; ii < len(t); ii++ {
			if s[i+ii] == t[ii] || string(s[i+ii]) == "?" {
				c++
			}
			if c == len(t) {
				ans = s[:i] + t + s[i+len(t):]
				return true
			}
		}
	}
	return false
}

/*-------------------utilities-------------------*/

func abs(x int) int {
	if x < 0 {
		return -x
	}
	return x
}

func min(x, y int) int {
	if x < y {
		return x
	}
	return y
}

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

func chmin(x *int, y int) bool {
	if *x > y {
		*x = y
		return true
	}
	return false
}

func chmax(x *int, y int) bool {
	if *x < y {
		*x = y
		return true
	}
	return false
}

// 最大公約数
func gcd(a, b int) int {
	if b == 0 {
		return a
	}
	return gcd(b, a%b)
}

// 最小公倍数
func lcm(a, b int) int {
	return (a * b) / gcd(a, b)
}

func comb(n, k int) int {
	if n < k {
		return 0
	}
	if n < 0 || k < 0 {
		return 0
	}
	return fac[n] * (finv[k] * finv[n-k] % MOD) % MOD
}

func factorical(n int) int {
	if n > 0 {
		return n * factorical(n-1)
	}
	return 1
}

/*-------------------init-------------------*/

const (
	INF = 1000000000000000000
	MOD = 1e9 + 7

	COMB_MAX = 510000
)

var (
	readString func() string
)

var (
	fac  = [COMB_MAX]int{}
	finv = [COMB_MAX]int{}
	inv  = [COMB_MAX]int{}
)

func init() {
	readString = newReadString(os.Stdin)
}

func combInit() {
	fac[0] = 1
	fac[1] = 1
	finv[0] = 1
	finv[1] = 1
	inv[1] = 1
	for i := 2; i < COMB_MAX; i++ {
		fac[i] = fac[i-1] * i % MOD
		inv[i] = MOD - inv[MOD%i]*(MOD/i)%MOD
		finv[i] = finv[i-1] * inv[i] % MOD
	}
}

/*-------------------inputs-------------------*/

func readi() int {
	return int(readi64())
}

func readi64() int64 {
	i, err := strconv.ParseInt(readString(), 0, 64)
	if err != nil {
		panic(err.Error())
	}
	return i
}

func readf() float64 {
	f, err := strconv.ParseFloat(readString(), 64)
	if err != nil {
		panic(err.Error())
	}
	return f
}

func newReadString(ior io.Reader) func() string {
	r := bufio.NewScanner(ior)
	r.Buffer(make([]byte, 1024), int(1e+11))
	r.Split(bufio.ScanWords)

	return func() string {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Text()
	}
}


Measured memory_bytes: 640
#include<stdio.h>
int main(void){
    int n,i;
    double x;
    double sum = 0;

    scanf("%d",&n);

    for (i = 0; i < n; i++){
        scanf("%lf",&x);
        x=1/x;
        sum += x;
    }
    double result;
    result = 1/sum;
    printf("%f",result);

    return 0;
}

Measured memory_bytes: 128
var GET=(function(){function f(s){return new g(s);}function g(s){this._s=s.trim().split("\n");this._y=0;}g.prototype.a=function(f){var s=this._s, y=this._y, r;if(typeof s[y]==="string")s[y]=s[y].split(" ").reverse();r=s[y].pop();if(!s[y].length)this._y++;return f?r:+r;};g.prototype.l=function(f){var s=this._s[this._y++].split(" ");return f?s:s.map(a=>+a);};g.prototype.m=function(n,f){var r=this._s.slice(this._y,this._y+=n).map(a=>a.split(" "));return f?r:r.map(a=>a.map(a=>+a));};g.prototype.r=function(n,f){var r=this._s.slice(this._y,this._y+=n);return f?r:r.map(a=>+a);};return f;})();
var o=GET(require("fs").readFileSync("/dev/stdin","utf8"));

console.log(main());
function main(){
  var n = o.a();
  var k = o.a();
  var a = o.l();
  var b = [];
  for(var i = 0; i < n; i++)b[i] = [a[i], i+1];
  b.sort((a,b)=>b[0]-a[0]);
  var ans = [];
  for(i = 0; i < n; i++){
    b[i][0]--;
    ans.push(b[i][1]);
  }
  var f = b[n-1][1];
  for(;k > 0; k--){
    b.sort((a,b)=>b[0]-a[0]);
    for(i = 0; i < n; i++){
      if(f === b[i][1])continue;
      if(b[i][0] <= 0)return -1;
      b[i][0]--;
      ans.push(b[i][1]);
    }
    if(f === b[n-1][1])f = b[n-2][1];
    else f = b[n-1][1];
  }
  console.log(ans.length);
  return ans.join(" ");
}

Measured memory_bytes: 21192
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define VSORT(v) sort(v.begin(), v.end())
#define VRSORT(v) sort(v.rbegin(), v.rend())
#define ll long long
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;
//typedef vector<unsigned int>vec;
typedef vector<ll>vec;
typedef vector<vec> mat;
typedef vector<vector<int>> Graph;

const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
const int INF = 1000000000;
const ll LINF = 1000000000000000000;//1e18
const ll  MOD = 1000000007;
//const ll MOD = 998244353;
const double PI = acos(-1.0);
const double EPS = 1e-10;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline void add(T &a, T b){a = ((a+b) % MOD + MOD) % MOD;};


int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll T1, T2, A1, A2, B1, B2;
    cin >> T1 >> T2 >> A1 >> A2 >> B1 >> B2;

    ll A = T1*A1 - T1*B1;
    ll B = T2*A2 - T2*B2;
    if(A > 0){
        A *= -1;
        B *= -1;
    }

    if(A + B < 0){
        cout << 0 << endl;
    }
    else if(A + B == 0){
        cout << "infinity" << endl;
    }
    else{
        ll S = -A / (A+B);
        ll T = -A % (A + B);
        if(T == 0) cout << S * 2 << endl;
        else cout << S * 2 + 1 << endl;
    }
}


Measured memory_bytes: 256
N = int(input())
s = input()
t = input()

res = 2* N
k = 0
a = 0
for i in range(N):
    flag = True
    tmp = 0
    for j in range(N-i):
        if s[i+j] == t[j] and flag == True:
            tmp += 1
        else:
            flag = False
    a = max(a, tmp)

        
print(res - a)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n)   for(signed i=0; i<n; i++)
#define yn(b)   cout << ((b)?"Yes":"No") << endl
#define YN(b)   cout << ((b)?"YES":"No") << endl
#define pr(r)   cout << r << endl
#define min(x,y)    (x<y)?x:y
#define ll  long long

int main(void){
    ll n, m;
    cin >> n >> m;
    ll r;
    if(n>1 && m>1) r=(n-2)*(m-2);
    else if(n==1 && m==1) r=1;
    else if(n==1) r = m-2;
    else if(m==1) r = n-2;
    pr(r);
}

Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <limits>
#include <set>
#include <sstream>
#include <vector>
using namespace std;

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

    string S;
    cin >> S;

    string ans = S.substr(0, 3);

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


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

#define ll long long
#define ar array

ll n, d;

void solve() {
    cin >> n >> d;
    ll ans=0;
    for(int i=0; i<n; ++i) {
        ll a, b;
        cin >> a >> b;
        long double x=sqrt(a*a+b*b);
        if(x<=d)
            ans++;
    }
    cout << ans << "\n";
}

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

    solve();
    return 0;
}

Measured memory_bytes: 3684
#pragma GCC optimize ("-O3")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#include<cmath>
#include<cstdio>
#include<algorithm>
#include<bitset>
#include<complex>
#include<deque>
#include<fstream>
#include<functional>
#include<iomanip>
#include<iostream>
#include<iterator>
#include<limits>
#include<list>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<sstream>
#include<stack>
#include<utility>
#include<valarray>
#include<vector>
#include<array>
#include<forward_list>
#include<random>
#include<ratio>
#include<tuple>
#include<unordered_map>
#include<unordered_set>
#include<cstring>

using namespace std;
using Int = long long; using uint = unsigned int; using uInt = unsigned long long;
typedef pair<int,int> Pi; typedef pair<Int,Int> Pl;
constexpr int mod = 1e9+7;
constexpr int INF32 = numeric_limits<int>::max();
constexpr Int INF64 = numeric_limits<Int>::max();
#define END {cout<<ans<<'\n'; return 0;}
#define ALL(v) (v).begin(),(v).end()
#define fi first
#define se second
#define mp make_pair
#define Pr(t) priority_queue<t>
#define gPr(t) priority_queue<t,vector<t>,greater<t>>
#define V(t) vector<t>
#define rep(i,n) for(int(i)=0; i<n; ++i)
#define rer(i,l,r) for(int i=l; i<=r; ++i)
#define gnr(i,l,r) for(int i=r; i>=l; --i)
#define eb emplace_back
#define pri1(a) cout<<(a)<<'\n'
#define pri2(a,n) {rep(i,n-1)cout<<a[i]<<' '; if(n)cout<<a[n-1]<<'\n';}
#define prip(p) cout<<p.fi<<' '<<p.se<<'\n'
#define priend(a) {cout<<(a)<<'\n'; return 0;}
template<class T> inline bool cmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool cmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int n,m,_,x,y,q;
string s,sb;
bool ok;
char ch;

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

  cin>>n>>m; Int dp[n]; pair<Pi,Int> ed[m]; fill(dp,dp+n,INF64); dp[n-1]=0;
  rep(i,m){
    cin>>x>>y>>q;
    ed[i]={Pi(--y,--x),q};
  }
  sort(ed,ed+m);
  gnr(i,0,m-1){
    if(i!=m-1&&ed[i+1].fi.fi==ed[i].fi.fi&&ed[i].fi.se>ed[i+1].fi.se&&ed[i].se>ed[i].se)continue;
    x=ed[i].fi.fi,y=ed[i].fi.se,q=ed[i].se;
    if(dp[x]==INF64)continue;
    for(int j=y; j<x; j++){
      if(!cmin(dp[j],dp[x]+q))break;
    }
  }
  pri1(dp[0]==INF64?-1:dp[0]);
}

Measured memory_bytes: 2560
#include <bits/stdc++.h>
#define repz(i, z, n) for (decltype(n) i = (z); i < (n); i++)
#define rep(i, n) for (decltype(n) i = 0; i < (n); i++)

#define REPZ(i, z, n) for (decltype(n) i = (z); i <= (n); i++)
#define REP(i, n) for (decltype(n) i = 0; i <= (n); i++)
#define ALL(v) v.begin(), v.end()
#define SIZE(v) ((ll)(v).size())
#define MAX(v) (*max_element(ALL(v)))
#define MIN(v) (*min_element(ALL(v)))
#define INF 1000000000000  // 1E+12

// 略
#define PB push_back
#define F first
#define S second
#define MP make_pair
#define READ cin >>
#define PRINT cout <<
#define PYES cout << "Yes" << endl;
#define POK cout << "OK" << endl;
#define PNO cout << "No" << endl;
#define PNG cout << "NG" << endl;

using namespace std;

// デバッグ用
void debug_out() { cout << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cout << H << " ";
  debug_out(T...);
}

template <class T>
bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T>
bool chmin(T &a, const T &b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}

#ifdef _DEBUG
#define debug(...) debug_out(__VA_ARGS__)
#else
#define debug(...)
#endif

// typedef
typedef long long ll;
typedef unsigned long long ul;
typedef long double ld;
typedef pair<ll, ll> pl;

// const
// 円周率
const ld pi = acos(-1);
// mod用
// 1E+9 +7
const ll mod = (int)1e+9 + 7;
// 1s間で可能なループ回数2E+8回
// int        最大値2147483647         〜2E+9
// long long  最大値9223372036854775807〜9E+18
// 総和accumulate
// 単純リストvector<type> push_back
// 連想配列map<key,value> insert,
// 集合set<type>
// pair キーとバリューを格納 firstとsecondでアクセス
// 小数点指定 cout << fixed << setprecision(15) << endl;
// to_string<->stoi
// stoll(longlong)
// stod(double)
// deep copy v1->v2 copy(v1.begin(), v1.end(), back_inserter(v2) );
// 大文字65-90(-32)
// 小文字97-122(+32)
//  priority_queue<pair<ll, ll>, vector<pair<ll, ll>>, greater<pair<ll, ll>>>
//  ba;
signed main() {
  // faster
  // C言語流の入出力は使用できない
  ios::sync_with_stdio(false);
  std::cin.tie(nullptr);
  int n, d;
  cin >> n >> d;
  cout << (n+d*2) / (2 * d + 1) << endl;
  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#define REP(i, a, b)for(i=a;i<b;++i)
#define rep(i,n) REP(i,0,n)
int i, j, n, m, k, a[256], s[256];
int main(void)
{
    scanf("%d%d", &n, &m);
    rep(i, 2*n) a[i] = i + 1;
    while (m--){
        scanf("%d", &k);
        memcpy(s, a, 800);
        if (!k) {
            rep(j, n){ a[2*j]=s[j]; a[2*j+1]=s[j+n]; }
        }
        else {
            REP(j, k, 2*n) a[j-k] = s[j];
            rep(j, k) a[2*n-k+j] = s[j];
        }
    }
    rep(i, 2*n) printf("%d\n", a[i]);
    return 0;
}

Measured memory_bytes: 0
#include <stdio.h>
int main(){
	char cl[20];
	int i,am,pm,yen;
	for(i=0;i<9;i++){
	scanf("%s%d%d",&cl,&am,&pm);
	printf("%s %d %d\n",cl,am+pm,am*200+pm*300);
	}
return 0;
}

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

using namespace std;

#define int long long
const double PI = 3.14159265358979323846;
typedef vector<int> vint;
typedef pair<int, int> pint;
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
// cout << fixed << setprecision(20);

// ベルマンフォード法
template<typename T>
class BellmanFord {
    struct edge {
        int from, to;
        T cost;
    };
    const int n;
    const T ZERO, INF;
    std::vector<edge> es;
public:
    // 頂点数と零元と十分大きな値を指定して初期化
    BellmanFord(int n, T ZERO, T INF) : n(n), ZERO(ZERO), INF(INF) {}

    // 始点、終点、コストを指定して辺を追加
    void addEdge(int from, int to, T cost) { es.push_back({from, to, cost}); }

    // 頂点sからの最短距離列を取得 (負閉路がある場合、空列を返す)
    std::vector<T> getDist(int s) {
        std::vector<T> d(n);
        std::fill(d.begin(), d.end(), INF);
        d[s] = ZERO;
        for (int i = 0; i < n; i++) {
            bool update = false;
            for (int j = 0; j < es.size(); j++) {
                edge e = es[j];
                if (d[e.from] != INF && d[e.to] > d[e.from] + e.cost) {
                    d[e.to] = d[e.from] + e.cost;
                    update = true;
                }
            }
            if (!update) return d;
        }
        return std::vector<T>();
    }
};


int N, M, P;
int A[110000], B[110000], C[110000];
vector<pint> G[110000];
bool visited[110000];
BellmanFord<int> bf(5500, 0, 1e11);

void dfs(int v) {
    visited[v] = true;
    for (int i = 0; i < G[v].size(); i++) {
        bf.addEdge(G[v][i].first, v, G[v][i].second);
        if (!visited[G[v][i].first])dfs(G[v][i].first);
    }
}

signed main() {
    cin >> N >> M >> P;
    for (int i = 0; i < M; i++) {
        cin >> A[i] >> B[i] >> C[i];
        G[B[i]].push_back(pint(A[i], P - C[i]));
    }
    dfs(N);
    vint d = bf.getDist(1);
    if (d.empty())cout << -1 << endl;
    else cout << max(0LL, -d[N]) << endl;
}

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

int a(string s, vector<string> blue, vector<string> red) {
	int a = 0;
	for (string t : blue) {
		if (t == s) a++;
	}
	for (string t : red) {
		if (t == s) a--;
	}
	return a;
}

int main() {
	int n, m, ans=0;
	cin >> n;
	vector<string> blue(n);
	for (int i=0; i<n; i++) cin >> blue.at(i);
	cin >> m;
	vector<string> red(m);
	for (int i=0; i<m; i++) cin >> red.at(i);

	for (string s : blue) {
		ans = max(ans, a(s, blue, red));
	}

	cout << ans << endl;

	return 0;

}

Measured memory_bytes: 256
s = input()

d = {}
for x in list(s):
    if x in d:
        d[x] += 1
    else:
        d[x] = 1

if len(d.keys()) == 2:
    t = True
    for e in d:
        if d[e] != 2:
            t = False
    if t:
        print("Yes")
    else:
        print("No")
else:
    print("No")


Measured memory_bytes: 2940
# -*- coding: utf-8 -*-
A = int(input())
B = int(input())
C = int(input())
X = int(input())
cnt = 0

for i in range(A + 1):
	for j in range(B + 1):
		for k in range(C + 1):
			if 500 * i + 100 * j + 50 * k == X:
				cnt += 1

print(cnt)

Measured memory_bytes: 3060
///
// File:  cgl_2_a.cpp
// Author: ymiyamoto
//
// Created on Sun Oct 22 18:40:44 2017
//

#include <cmath>
#include <cstdint>
#include <iostream>

using namespace std;

struct point_t {
  double x;
  double y;
};

struct vector_t {
  double x;
  double y;

  vector_t(point_t a) : x(a.x), y(a.y)
  {
  }

  vector_t(point_t a, point_t b) : x(a.x - b.x), y(a.y - b.y)
  {
  }

  double dot(const vector_t &b)
  {
    return x * b.x + y * b.y;
  }

  double cross(const vector_t &b)
  {
    return x * b.y - y * b.x;
  }
};

struct line_t {
  point_t a;
  point_t b;

  line_t(point_t a, point_t b) : a(a), b(b)
  {
  }

  vector_t vector()
  {
    return vector_t(a, b);
  }

  double dot(line_t &l)
  {
    return vector().dot(l.vector());
  }

  double cross(line_t &l)
  {
    return vector().cross(l.vector());
  }
};

#define EPS (1e-10)
#define equals(x, y) (fabs(x - y) < EPS)

int32_t main()
{
  uint32_t q;
  cin >> q;

  for (uint32_t i = 0; i < q; i++) {
    double x0, y0, x1, y1;
    cin >> x0 >> y0 >> x1 >> y1;
    line_t l1 = line_t(point_t({x0, y0}), point_t({x1, y1}));
    cin >> x0 >> y0 >> x1 >> y1;
    line_t l2 = line_t(point_t({x0, y0}), point_t({x1, y1}));
    if (equals(l1.dot(l2), 0.0)) {
      cout << 1 << endl;
    } else if (equals(l1.cross(l2), 0.0)) {
      cout << 2 << endl;
    } else {
      cout << 0 << endl;
    }
  }

  return 0;
}

Measured memory_bytes: 3232
#include <iostream>
#include <sstream>
#include <array>

using data_t = std::array<std::array<char, 100>, 100>;

bool isBlankRow(data_t& a, int H, int W, int row)
{
	for (int w = 0; w < W; ++w)
		if ('#' == a[row][w])
			return false;

	return true;
}

bool isBlankCol(data_t& a, int H, int W, int col)
{
	for (int h = 0; h < H; ++h)
		if ('#' == a[h][col])
			return false;

	return true;
}

void deleteRow(data_t& a, int H, int W, int row)
{
	for (int h = row; h < H - 1; ++h)
	{
		a[h] = a[h + 1];
	}
}

void deleteCol(data_t& a, int H, int W, int col)
{
	for (int h = 0; h < H; ++h)
		for (int w = col; w < W - 1; ++w)
		{
			a[h][w] = a[h][w + 1];
		}
}

void print(data_t& a, int H, int W)
{
	std::stringstream ss;
	for (int h = 0; h < H; ++h)
	{
		for (int w = 0; w < W; ++w)
		{
			ss << a[h][w];
		}
		ss << std::endl;
	}

	std::cout << ss.str();
}

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

	data_t a;
	for (int h = 0; h < H; ++h)
		for (int w = 0; w < W; ++w)
		{
			std::cin >> a[h][w];
		}

	for (int h = 0; h < H; ++h)
	{
		if (isBlankRow(a, H, W, h))
		{
			deleteRow(a, H, W, h);
			--H;
			--h; //現在の行をもう一度チェックする
		}
	}

	for (int w = 0; w < W; ++w)
	{
		if (isBlankCol(a, H, W, w))
		{
			deleteCol(a, H, W, w);
			--W;
			--w; //現在の列をもう一度チェックする
		}
	}

	print(a, H, W);
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using lint = long long int;
using pint = pair<int, int>;
using plint = pair<lint, lint>;
struct fast_ios { fast_ios(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;
#define FOR(i, begin, end) for(int i=(begin),i##_end_=(end);i<i##_end_;i++)
#define IFOR(i, begin, end) for(int i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--)
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
template<typename T> istream &operator>>(istream &is, vector<T> &vec){ for (auto &v : vec) is >> v; return is; }
template<typename T> ostream &operator<<(ostream &os, const vector<T> &vec){ os << "["; for (auto v : vec) os << v << ","; os << "]"; return os; }
template<typename T> ostream &operator<<(ostream &os, const deque<T> &vec){ os << "deq["; for (auto v : vec) os << v << ","; os << "]"; return os; }
template<typename T> ostream &operator<<(ostream &os, const set<T> &vec){ os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; }
template<typename T> ostream &operator<<(ostream &os, const unordered_set<T> &vec){ os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; }
template<typename T> ostream &operator<<(ostream &os, const multiset<T> &vec){ os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; }
template<typename T> ostream &operator<<(ostream &os, const unordered_multiset<T> &vec){ os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; }
template<typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &pa){ os << "(" << pa.first << "," << pa.second << ")"; return os; }
template<typename TK, typename TV> ostream &operator<<(ostream &os, const map<TK, TV> &mp){ os << "{"; for (auto v : mp) os << v.first << "=>" << v.second << ","; os << "}"; return os; }
template<typename TK, typename TV> ostream &operator<<(ostream &os, const unordered_map<TK, TV> &mp){ os << "{"; for (auto v : mp) os << v.first << "=>" << v.second << ","; os << "}"; return os; }
template<typename T> void ndarray(vector<T> &vec, int len) { vec.resize(len); }
template<typename T, typename... Args> void ndarray(vector<T> &vec, int len, Args... args) { vec.resize(len); for (auto &v : vec) ndarray(v, args...); }
template<typename T> void Max(T &m, const T q) { if (m < q) m = q; }
template<typename T> void Min(T &m, const T q) { if (m > q) m = q; }
template<typename T1, typename T2> pair<T1, T2> operator+(pair<T1, T2> &l, pair<T1, T2> &r) { return make_pair(l.first + r.first, l.second + r.second); }
template<typename T1, typename T2> pair<T1, T2> operator-(pair<T1, T2> &l, pair<T1, T2> &r) { return make_pair(l.first - r.first, l.second - r.second); }
#define dbg(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ") " << __FILE__ << endl;

constexpr lint MOD = 1000000007;
int H, W;
vector<string> a;

int main()
{
    cin >> H >> W;
    a.resize(H);
    cin >> a;

    vector<vector<lint>> dp;
    ndarray(dp, H + 1, W + 1);
    dp[1][1] = 1;
    REP(h, H) REP(w, W) if ((h or w) and a[h][w] == '.') dp[h + 1][w + 1] = (dp[h][w + 1] + dp[h + 1][w]) % MOD;
    cout << dp[H][W] << endl;
}


Measured memory_bytes: 9216
#include <algorithm>
#include <cassert>
#include <cfloat>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <deque>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>
 
#define FOR(i,k,n) for (int (i)=(k); (i)<(n); ++(i))
#define rep(i,n) FOR(i,0,n)
#define all(v) begin(v), end(v)
#define debug(x) //cerr<< #x <<": "<<x<<endl
#define debug2(x,y) cerr<< #x <<": "<< x <<", "<< #y <<": "<< y <<endl
 
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vector<int> > vvi;
typedef vector<ll> vll;
typedef vector<vector<ll> > vvll;
typedef deque<bool> db;
template<class T> using vv=vector<vector< T > >;

// cout vector
template<typename T> ostream& operator<<(ostream& s, const vector<T>& v) {
  int len = v.size(); s << "\n";
  for (int i = 0; i < len; ++i) {
    s << v[i]; if (i < len - 1) s << "\t";
  }
  s << "\n"; return s;
}

// cout 2-dimentional vector
template<typename T> ostream& operator<<(ostream& s, const vector< vector<T> >& vv) {
  int len = vv.size();
  for (int i = 0; i < len; ++i) { s << vv[i]; }
  return s;
}


int n, m;
vvi g;
vector<bool> arrived;

vi dfs(int start) {
  arrived[start] = true;
  vector<bool> used_local(n, false);
  used_local[start] = true;
  vi color(n, -1);
  color[start] = 0;
  deque<int> st = {start};
  while (!st.empty()) {
    int u = st.front();
    st.pop_front();
    rep (v, n) {
      if (g[u][v] == 0) {
        continue;
      }
      if (arrived[v]) {
        if (color[v] == color[u]) {
          printf("-1\n");
          exit(0);
        }
        continue;
      }
      arrived[v] = true;
      used_local[v] = true;
      if (color[v] == -1) {
        color[v] = 1 - color[u];
      } else if (color[v] == color[u]) {
        printf("-1\n");
        exit(0);
      }
      st.push_back(v);
    }
  }
  vi ret = {0, 0};
  rep (i, n) {
    if (!used_local[i]) {
      continue;
    }
    ret[color[i]] += 1;
  }
  return ret;
}

int main() {
  scanf("%d %d", &n, &m);
  g.assign(n, vi(n, 0));
  rep (i, m) {
    int a, b;
    scanf("%d %d", &a, &b);
    a -= 1; b -= 1;
    g[a][b] = g[b][a] = 1;
  }
  rep (i, n) {
    g[i][i] = 1;
  }
  rep (i, n) {
    rep (j, n) {
      g[i][j] = 1 - g[i][j];
    }
  }

  arrived.assign(n, false);
  vvi sts;
  rep (i, n) {
    if (arrived[i]) {
      continue;
    }
    sts.push_back(dfs(i));
  }

  debug(sts);
  int sz = sts.size();
  rep (i, sz) {
    if (sts[i][0] > sts[i][1]) {
      swap(sts[i][0], sts[i][1]);
    }
  }
  sort(all(sts), [](vi x, vi y) {
      return (x[1] - x[0]) > (y[1] - y[0]);
      });
  debug(sts);
  vi gr = {0, 0};
  rep (i, sz) {
    gr[0] += sts[i][0];
    gr[1] += sts[i][1];
    if (gr[0] < gr[1]) {
      swap(gr[0], gr[1]);
    }
  }

  int ans = gr[0] * (gr[0]-1) / 2 + gr[1] * (gr[1]-1) / 2;
  printf("%d\n", ans);

  return 0;
}


Measured memory_bytes: 2304
/*
    Problem 14
    https://atcoder.jp/contests/s8pc-4/tasks/s8pc_4_b
*/
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <map>
#include <numeric>
#include <string>
#include <cmath>
#include <iomanip>
#include <queue>
#include <list>
#include <set>
#include <stack>
#include <cctype>
#include <cmath>
#include <bitset>

using namespace std;
/* typedef */
typedef long long ll;
/* constant */
const int MAX = 15;
const ll INF = 1e18;
/* global variables */
/* function */
/* main */
int main(){
    int N, K, upper;
    ll ans, tmp, pre;
    cin >> N >> K;

    vector<ll> building(N);
    for (int i = 0; i < N; i++) cin >> building[i];

    upper = pow(2, N);
    ans = INF;
    for (int b = 0; b < upper; b++) {
        bitset<MAX> bs(b);
        vector<int> v(MAX, 0);
        if (bs.count() != K or !bs[0]) continue;
        for (int i = 0; i < N; i++)
            if ((bs >> i)[0]) v[i] = 1;
        tmp = 0;
        pre = building[0];
        for (int i = 1; i < N; i++) {
            if (v[i] && pre >= building[i]) {
                tmp += pre - building[i] + 1;
                pre++;
            }
            pre = max(pre, building[i]);
        }
        ans = min(ans, tmp);
    }
    cout << ans << '\n';
}

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

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

    vector<int> A(9, 0);

    for (int i = 0; i < 3; ++i){
        cin >> A[(i*3)+0] >> A[(i*3)+1] >> A[(i*3)+2];
    }

    int N;
    cin >> N;
    vector<int> b(N, 0);
    for (int i = 0; i < N; ++i){
        cin >> b[i];
    } 

    vector<bool> bingo(9, 0);
    for (int i = 0; i < N; ++i){
        for (int j = 0; j < 9; ++j){
            if (b[i] == A[j]){
                bingo[j] = true;
            }
        }
    } 

    bool isBingo = false;
    for (int i = 0; i < N; ++i){
        if (bingo[(i*3)+0] && bingo[(i*3)+1] && bingo[(i*3)+2]){
            isBingo = true;
        }
    }
    for (int i = 0; i < N; ++i){
        if (bingo[i] && bingo[i + 3] && bingo[i + 6]){
            isBingo = true;
        }
    }
    if (bingo[0] && bingo[4] && bingo[8]){
        isBingo = true;
    }
    if (bingo[2] && bingo[4] && bingo[6]){
        isBingo = true;
    }
    if (isBingo){
        cout << "Yes\n";
    } 
    else {
        cout << "No\n";
    }

    return 0;
}

Measured memory_bytes: 256
/// hi_im_manh :D
#include <bits/stdc++.h>
#define reset(a,n) memset(a,0,(n+1)*sizeof(int))
#define endl "\n"
#define llmin LLONG_MIN
#define llmax LLONG_MAX
#define intmax INT_MAX
#define intmin INT_MIN
#define ll long long
#define fast ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)

#define duckman "TASK"

#define input freopen(duckman".inp", "r", stdin);
#define output freopen(duckman".out", "w", stdout);

#define nmax 22000
using namespace std;

void min_self(ll &a, ll b) {
    a = min(a, b);
}

int main()
{
    fast;
//    input;
//    output;

    ll n;
    cin >> n;
    ll sum[n+1];
    ll dp[n+1][n+1];
    sum[0] = 0;
    for (ll r = 1; r <= n; ++r) {
        ll x;
        cin >> x;
        sum[r] = x + sum[r-1];
        for (ll l = r; l >= 1; --l) {
            if (l == r) {
                dp[l][r] = 0;
            }
            else {
                dp[l][r] = llmax;
                for (ll i = l; i < r; ++i) {
                    min_self(dp[l][r], dp[l][i] + dp[i+1][r] + sum[r] - sum[l-1]);
                }
            }
        }
    }
    cout << dp[1][n];
    return 0;
}
/*

*/


Measured memory_bytes: 1536
// g++ -std=c++11 a.cpp
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>	
#include<map>
#include<set>
#include<unordered_map>
#include<utility>
#include<cmath>
#include<random>
#include<cstring>
#include<queue>
#include<stack>
#include<bitset>
#include<cstdio>
#include<sstream>
#include<iomanip>
#include<assert.h>
#include<typeinfo>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define FOR(i,a) for(auto i:a)
#define pb push_back
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
#define show1d(v) rep(_,v.size())cout<<" "<<v[_];cout<<endl;
#define show2d(v) rep(_,v.size()){rep(__,v[_].size())cout<<" "<<v[_][__];cout<<endl;}cout<<endl;
using namespace std;
//kaewasuretyuui
typedef long long ll;
#define int ll
typedef int Def;
typedef pair<Def,Def> pii;
typedef vector<Def> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<Def,pii> pip;
typedef vector<pip>vip;
#define mt make_tuple
typedef tuple<int,int,int> tp;
typedef vector<tp> vt;
template<typename A,typename B>bool cmin(A &a,const B &b){return a>b?(a=b,true):false;}
template<typename A,typename B>bool cmax(A &a,const B &b){return a<b?(a=b,true):false;}
//template<class C>constexpr int size(const C &c){return (int)c.size();}
//template<class T,size_t N> constexpr int size(const T (&xs)[N])noexcept{return (int)N;}
const double PI=acos(-1);
const double EPS=1e-9;
Def inf = sizeof(Def) == sizeof(long long) ? 1e18+10 : 1e9+10;
int dx[]={0,1,0,-1,1,1,-1,-1};
int dy[]={1,0,-1,0,1,-1,1,-1};//RDLU
signed main(){
	int n;
	while(cin>>n,n){
		vvi dp(366,vi(366,-inf));
		dp[0][0]=0;
		vvp G(366);
		rep(i,n){
			int a,b,c;
			cin>>a>>b>>c;
			a--;
			G[a].pb({b,c});
		}
		rep(i,366){
			rep(k,G[i].size())for(int j=366-1;j>=i;j--){
				if(dp[i][j]+inf){
					int s=G[i][k].first,t=j;
					if(s>t)swap(s,t);
					cmax(dp[s][t],dp[i][j]+G[i][k].second);
					t++;
					if(t<366)cmax(dp[s][t],dp[i][j]+G[i][k].second);
				}
			}
			rep(j,366){
				if(i+1<365&&i!=j)cmax(dp[i+1][j],dp[i][j]);
				if(i+1<365&&i==j)cmax(dp[i+1][j+1],dp[i][j]);
			}
		}
//		rep(i,10){rep(j,6)cout<<" "<<dp[i][j];cout<<endl;}
		int out=-inf;
		rep(i,366)rep(j,366)cmax(out,dp[i][j]);
		cout<<out<<endl;
	}
}









Measured memory_bytes: 3856
A, B, C, D, E, F = map(int, input().split())

x = set()

for i in range(F):
  for j in range(F):
    water = 100 * A * i + 100 * B * j
    if F >=  water:
      x.add(water)
    else:
      break

sugar = water / 100 * E

y = set()

for i in range(F):
  for j in range(F):
    sugar = C * i + D * j
    if F >= sugar:
      y.add(sugar)
    else:
      break

x = list(x) # water
y = list(y) # sugar
percentage = 0
sugarWater = 0
ansSugar = 0

for i in range(len(x)):
  for j in range(len(y)):
    if x[i] + y[j] == 0:
      pass
    elif F >= x[i] + y[j]:
      if y[j] <= E * x[i] / 100:
        p = 100 * y[j] / ( x[i] + y[j] )
        if p >= percentage:
          percentage = p
          sugarWater = x[i] + y[j]
          ansSugar = y[j]

print(str(sugarWater) + " " + str(ansSugar))

Measured memory_bytes: 9068
#include<iostream>
#include <bits/stdc++.h>  
using namespace std;
int main(){
      int n;
    cin >> n;
    string s;
    cin >> s;
    int i = 0;
    int j = n - 1;
    int cnt = 0;
    while (i < n && j >= 0 && i < j) {
    	while (i < n && s[i] == 'R') {
    		++i;
    	}
    	while (j >= 0 && s[j] == 'W') {
    		--j;
    	}
    	if (i < n && j >= 0 && i < j) {
    		swap(s[i], s[j]);
    		cnt++;
    	}
    }
    cout << cnt << endl;
  return 0;
}


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

#define int long long
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define rep(i, n) for (int i = 0; i < n; ++i)
#define REP(i, n) for (int i = 0; i < n; ++i)
#define range(i,a,b) ((a)<=(i) && (i)<(b))
#define debug(x) cout << #x << " = " << (x) << endl;
#define fs first
#define sc second
#define pb push_back
#define eb emplace_back
#define SP << " " <<

typedef long long ll;
typedef pair<int, int> P;
typedef tuple<int, int, int> T;
typedef vector<int> vec;
typedef vector<P> pvec;
typedef vector<vector<int>> vvec;
typedef vector<vector<P>> pvvec;
typedef priority_queue<int> PQI;
typedef priority_queue<P> PQP;
typedef priority_queue<int,vector<int>,greater<int>> PQIG;
typedef priority_queue<P,vector<P>,greater<P>> PQPG;

const vector<int> DX = {0, -1, 0, 1, 1, 1, -1, -1};
const vector<int> DY = {1, 0, -1, 0, 1, -1, 1, -1};
constexpr int MOD = (1000000007);
// const int MOD = (998244353);
// const int INF = (1 << 30); // 1073741824
const ll INF = (1LL << 60); // 1152921504606846976
const double PI = (3.141592653589794);
const double EPS = (0.0000000001); // 10^(-10)

template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b; return 1;} return 0;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b; return 1;} return 0;}
template<class T> inline T ceil(T a, T b) {return T((a + b - 1) / b);}
template<class T> inline T round(T a, T b) {return T(a / b);}
template< typename T1, typename T2 > istream &operator>>(istream &is, pair< T1, T2 > &p) { is >> p.first >> p.second; return is; }
template <class T> inline void out(T &a) { bool flag=true; for(auto&x:a){if(flag) {flag=false;} else{ cout << ' '; } cout<<x; } cout << endl; }



//----------------------------------------------------------------
int nmax=200000; // 2*(10^5)
vvec G(nmax);





void solve4ts()
{
  
  
  int n;
  cin>>n;
  vector<int> a(n);
  rep(i,n) cin >> a[i];
  
  int ans=0;
  sort(rall(a));
  
  ans+=a[0];
  int idx=1;
  int cnt=0;
  rep(i,n-2){
    ans+=a[idx];
    cnt++;
    if(cnt%2==0) idx++;
  }
  cout<<ans<<endl;
  
  
}
//-----------------------------------------------------------------

signed main(){ ios::sync_with_stdio(false); cin.tie(0); cout << fixed << setprecision(15);
    int repeat = 1;
    // cin >> repeat;
    while(repeat--) solve4ts();
}

Measured memory_bytes: 9536
#include <iostream>
#include <stack>
using namespace std;
string s = "";
int n, p;

main()
{
    cin >> n;
    int c = 1;
    stack<int> st;
    for (int i = 0; i < n; i++)
    {
        cin >> p;
        while (c <= p)
        {
            st.push(c);
            s += '(';
            c++;
        }
        if (!st.empty() && st.top() == p)
        {
            s += ')';
            st.pop();
        }
        else
        {
            cout << ":(" << endl;
            return 0;
        }
    }
    cout << s << endl;
}



Measured memory_bytes: 3496
#include <bits/stdc++.h>
using namespace std;
int main(){
    int X;
    cin >> X;
    double largestPower = 1;
    int i = 0;
    double perfectpower;
    for(double i = 2; i < sqrt(X); i++) {
        for(double j = 2; j < sqrt(X); j++) {
            perfectpower = pow(i, j);
            if(perfectpower <= X) {
                largestPower = max(perfectpower, largestPower);
            }
        }
    }
    cout << largestPower << endl;
}

Measured memory_bytes: 512
#include <iostream>
#include <string>
#include <vector>

using namespace std;
int n;
vector<int> a(10);
int count = 0;
void dfs(int kind, int index, int total)
{
    if(kind == 0)
    {
       total *= a[index];
    }else if(kind == 1)
    {
       total *= a[index] + 1;
    }else if(kind == -1)
    {
       total *= a[index] -1;
    }
    if(index == n - 1)
    {
        if(total % 2 == 0) count++;
        return;
    }
    dfs(0, index + 1, total);
    dfs(1, index + 1, total);
    dfs(-1, index + 1, total);
}


int main() {
    cin >> n;
    for(int i = 0; i < n; i++)
    {
        cin >> a[i];
    }
    dfs(0, 0, 1);
    dfs(1, 0, 1);
    dfs(-1, 0, 1);
    cout << count << endl;
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;
public class Main{

	public static void main(String[] args) {
		Scanner stdIn = new Scanner(System.in);
		int n = stdIn.nextInt(); //宮殿の候補地点
		int t = stdIn.nextInt(); //気温の定数
		int a = stdIn.nextInt(); //この温度に近い場所を探す
		int [] place = new int[n]; //宮殿の標高
		for(int i = 0; i < n; i++) {
			place[i] = stdIn.nextInt();
		}
		
		double ans = Double.MAX_VALUE; //宮殿の地点１が答えにしておく
		int j = 0;
		for(int i = 0; i < n; i++) {
			double ave = t-(place[i] * 0.006);
			double an = (ave-a)>0?ave-a:a-ave;
			if(ans>an) {
				j = i+1;
				ans = an;
			}
		}
		
		System.out.println(j);
		
		
	}

}


Measured memory_bytes: 24020
# util functions
class UnionFind
  def initialize(n) # n: number of elements in the forest
    @par  = []
    @rank = []
    @vs   = []
    @num  = n
    n.times do |i|
      @par[i] = i
      @rank[i] = 0
      @vs[i] = 1
    end
  end
  attr_accessor :par, :rank, :vs, :num

  def find(x)
    raise "x = #{x} is out of range 0..#{@par.size - 1}" unless @par[x]
    if @par[x] == x
      return x
    else
      return find( @par[x] )
    end
  end

  def unite( x, y )
    xrt = find(x)
    yrt = find(y)
    return if xrt == yrt

    @num -= 1
    
    if @rank[xrt] > @rank[yrt]
      @par[yrt] = xrt
      @vs[xrt] += @vs[yrt]
    else
      @par[xrt] = yrt
      @vs[yrt] += @vs[xrt]
      @rank[yrt] += 1 if @rank[xrt] == @rank[yrt]
    end
  end

  def same( x, y ) # returns true/false
    return find( x ) == find( y )
  end

end # UnionFind


# debug
$debugFlag = ( ARGV[0] != nil )
p "==== DEBUG MODE ====" if $debugFlag

def pd(str)
  p str if $debugFlag
end

def printd(str)
  print str if $debugFlag
end

# input
inputs = []
lc = 0
while l = $stdin.gets do
  if false
    inputs << l.chomp.split(" ").map(&:to_s)
  else
    inputs << l.chomp.split(" ").map(&:to_i)
  end
  lc += 1
end

# input check
if $debugFlag
  p "--- INPUT (begin) ---"
  inputs.each do |l_i|
    p l_i
  end
  p "--- INPUT (end) ---"
  print "\n"
end

nn = inputs[0][0]
#mm = inputs[0][1]
elist = inputs[1..-1]

# body
if $debugFlag
end

pd elist

cnt = 0
elist.length.times do |i|
  uf = UnionFind.new(nn)
  elist.length.times do |j|
    next if i == j
    uf.unite(elist[j][0] - 1, elist[j][1] - 1)
  end
  cnt += 1 if uf.num > 1
end

puts cnt


Measured memory_bytes: 1916
#include<bits/stdc++.h>
# define mod 1000000007
using namespace std;
int x[2]={0,1};
int y[2]={1,0};

int fun(vector<vector<int>>&a,vector<vector<int>>&dp,int i,int j,int m,int n)
{
    if(i==m-1&&j==n-1)
    {
      
        //dp[i][j]+=1;
        return 1;
    }
    if(dp[i][j]!=-1)
    return dp[i][j];
   
    int ans=0;
    for(int k=0;k<2;k++)
    {
        int rs=i+x[k];int cs=j+y[k];
        if(rs>=0&&rs<m&&cs>=0&&cs<n&&a[rs][cs]==1)
        {
            ans+=fun(a,dp,rs,cs,m,n)%mod;
            dp[i][j]=ans%mod;//cout<<ans<<" ";
        }
    }
    return dp[i][j]=ans%mod;
}
int main()
{
  int m,n,i,j;
  cin>>m>>n;char ch;
  vector<vector<int>>a(m,vector<int>(n,1));
  vector<vector<int>>dp(m,vector<int>(n,-1));
  for(i=0;i<m;i++)
  {
      for(j=0;j<n;j++)
      {
          cin>>ch;
          if(ch=='#')
          a[i][j]=0;
      }
  }cout<<fun(a,dp,0,0,m,n)<<endl;;
  
}

Measured memory_bytes: 8320
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
using namespace std;
int a,b,c;
int main()
{
	cin>>a>>b>>c;
 if(a>b) swap(a,b);
 if(b>c) swap(b,c);
 if(a>b) swap(a,b);
cout<<a<<' '<<b<<' '<<c<<endl;
}

Measured memory_bytes: 1160
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>
//  配列の最大の大きさ
#define MAX_LENGTH  200010

typedef struct{
    int array[MAX_LENGTH];
    int first;
    int last;
}QUEUE;

void init(QUEUE*);
int enqueue(QUEUE*,int);
int dequeue(QUEUE*,int*);
struct touple { int a; int b; };
int cmp_touple(const void*n1, const void*n2);
int bisect_left(int x,struct touple a[],int left,int right);

int main(void){
    int N,M;
    scanf("%d%d", &N,&M);
    struct touple *ts = (struct touple *)malloc((M*2)*sizeof(struct touple));
    for (int i = 0; i < M; i++) {
        int x,y;
        scanf("%d%d", &x,&y);
        ts[i].a = x;ts[i].b = y;
        //逆辺も入れとく
        ts[i+M].a = y;ts[i+M].b = x;
    }
    //ts[i][0] の値(toupleの左側の値でソート)
    qsort(ts,2*M,sizeof (ts), cmp_touple);
    // その部屋が指し示してる方向
    int *direction = (int *)malloc((N+1) * sizeof(int));
    //全部　-1 にセット, -1なら未到達　それ以外は到達の意味
    memset(direction,0xFF,sizeof(int)*(N+1));
    //以下bfs やる
    //queueには処理する部屋の順(頂点)が詰まってる
    QUEUE q;
    //初期設定
    init(&q);
    enqueue(&q,1);
    //1番目の部屋には到達した
    direction[1] = 0;
    while (q.first != q.last){
        //queueの頭から一個取り出す
        int v;
        dequeue(&q,&v);
        //tsから 左側が vとなっているindexをサーチして下のforで使う
        int index1 = bisect_left(v,ts,0,(2*M)-1); 
        int index2 = bisect_left(v+1,ts,0,(2*M)-1); 
        //printf("%d %d index\n",index1,index2);
        // 計算量は一番深いのがこの一個したのネストでO(Mlog(M)+N)
        for (int index = index1; index < index2; index++) {
            int nv = ts[index].b;
            // nvは新しい頂点(行ける頂点)
            if (direction[nv] != -1) continue;//到達しているのでいらん
            direction[nv] = v;//普通 direction[nv] = direction[v] + 1で距離見る
            enqueue(&q,nv);
        }
    }
    // direction をうまいこと出力
    printf("Yes\n");
    for (int i = 2; i <= N; i++) {
        printf("%d\n",direction[i]);
    }
}

int bisect_left(int x,struct touple a[],int left,int right){
    //二分して挿入点を ts[i].a  から探す, できるだけ左のindexを返す
    // 1,2,2,3,4 に2をいれるなら 1,here,2,2,3,4 と挿入点を見つける.
    int mid; right++;
    while (left < right) {
        mid = (left + right) / 2;
        if (a[mid].a < x) {
            left = mid + 1;
        } else {
            right = mid;
        }
    }
    return left;
}

int cmp_touple(const void*n1, const void*n2){
    return ((struct touple*)n1)->a - ((struct touple*)n2)->a;
}

//  スタックの初期化
void init(QUEUE* pQueue)
{
    int i;
    for(i = 0; i < MAX_LENGTH; i++){
        pQueue->array[i] = 0;
    }
    //  最初と最後の位置を先頭に。
    pQueue->first = 0;
    pQueue->last = 0;
}
//  値のプッシュ
int enqueue(QUEUE* pQueue,int value)
{
    pQueue->array[pQueue->last] = value;          // キューに新しい値を入れる
    pQueue->last = (pQueue->last + 1) % MAX_LENGTH;   // lastの更新
    //  データを格納しきれなかった
    return 1;
}
//  値のポップ
int dequeue(QUEUE* pQueue,int* pValue)
{
    *pValue = pQueue->array[pQueue->first];           // いちばん先頭のキューを返す準備
    pQueue->first = (pQueue->first+1) % MAX_LENGTH;   // キューの先頭を次に移動する
    return 1;
}



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

def aaa(a, b):
    if a % 10 == 3:
        print(f' {b}', end='')
    
    elif (a // 10 > 0):
        aaa(a // 10, b)

for i in range(1, n + 1):
    if i % 3 == 0:
        print(f' {i}', end='')
    
    else:
        aaa(i, i)
        
print()


Measured memory_bytes: 5884
#include <cstdio>
#include <algorithm>
using namespace std;

int main() {
  int N, K;
  scanf("%d %d", &N, &K);
  int h[N];
  for (int i=0; i<N; i++) {
    scanf("%d", &h[i]);
  }
  sort(h, h+N);

  int ans = 1000000000;
  for (int i=0; i<N-K+1; i++) {
    int diff = h[i+K-1] - h[i];
    if (diff < ans) ans = diff;
  }
  printf("%d\n", ans);
}


Measured memory_bytes: 512
#include <vector>
#include <string>
#include <iostream>
#include <queue>
#include <algorithm>
#include <functional>
#include <map>
#include <array>
#include <cmath>
#include <set>
#include <numeric>

using namespace std;

template <typename T>
using TABLE = vector<vector<T>>;

using LONG = long long;
using LVEC = vector<long long>;

long long PRIME = 1e9 + 7;
long long PRIME2 = 998244353;


LONG check(TABLE<LONG>& A, LVEC& C, LONG flags, LONG N, LONG M, LONG X, LVEC& M_buf){
    for(int i = 0; i < M; ++i){
        M_buf[i] = 0;
    }

    LONG sum = 0;

    for(int i = 0; i < N; ++i){
        if(flags & 1 << i){
            sum += C[i];
            for(int j = 0; j < M; ++j){
                M_buf[j] += A[i][j];
            }
        }
    }

    for(int i = 0; i < M; ++i){
        if(M_buf[i] < X){
            return 1e8;
        }
    }

    return sum;
}



int main(){
    LONG N, M , X;
    cin >> N >> M >> X;

    LVEC C(N);
    TABLE<LONG> A(N, LVEC(M, 0));

    for(int i = 0; i < N; ++i){
        cin >> C[i];
        for(int j = 0; j < M; ++j){
            cin >> A[i][j];
        }
    }

    LONG flags_max = 1 << N;
    LONG min_val = 1e8;
    LVEC M_buf(M);

    for(LONG flag = 1; flag < flags_max; ++flag){
        LONG val = check(A, C, flag, N, M, X, M_buf);
        if(val < min_val){
            min_val = val;
        }
    }

    if(min_val != 1e8){
        cout << min_val;
    }
    else{
        cout << -1;
    }

}


Measured memory_bytes: 3628
from fractions import gcd
from collections import Counter, deque, defaultdict
from heapq import heappush, heappop, heappushpop, heapify, heapreplace, merge
from bisect import bisect_left, bisect_right, bisect, insort_left, insort_right, insort
from itertools import product, combinations,permutations
from copy import deepcopy
import sys
import numpy as np
sys.setrecursionlimit(4100000)

day = ['SUN', 'MON', 'TUE', 'WED', 'THU', 'FRI', 'SAT']

if __name__ == '__main__':
    S = input()
    for i, d in enumerate(day):
        if S==d:
            print(7-i)

Measured memory_bytes: 27124
#include<bits/stdc++.h>
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define sz(x)  (long long)(x).size()
#define sqr(x) (x)*(x)
#define sof sizeof
#define resz resize
#define ins insert
#define lowerB lower_bound
#define upperB upper_bound
#define mkp make_pair
#define mkt make_tuple
#define act(a,v) (get<(long long)a>(v))
#define mod 1000000007
#define mod1 998244353
#define N 100003
#define inf 1e18
#define minf -1e18
#define min3(a,b,c) min(a,min(b,c));
#define max3(a,b,c) max(a,max(b,c));
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define sumall(v) accumulate(all(v),(ll)0)
#define sum accumulate
#define FastIO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define PRECISION(n) std::cout.unsetf ( std::ios::floatfield );std::cout.precision((ll)n)
#define PI M_PI
#define fi first
#define se second
#define here cout<<"RSSB"<<endl
#define showzero cout<<std::showpoint
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) (a*b)/gcd(a,b)
#define br "\n"
#define sp " "
#define zero (ll)0
using namespace  std ;
typedef double db;
typedef long long ll ;
typedef vector<int>vi ;
//typedef vector<l>vl ;
typedef vector<ll>vll ;
typedef vector<vector<ll> >vvl ;
typedef pair<int,int> pii ;
typedef pair<ll,ll> pll ;
typedef vector<pll>vpll;
typedef vector<string>vstr;
typedef vector<bool>vbool ;
void READ(vll &v, ll n){ll a ;for(ll i=0 ; i<n ; i=i+1){cin>>a ;v.pb(a);}}
void PRINT(vll &v , ll a = 0){for(ll i=a ; i<v.size() ; i=i+1){/*v[i] = max((ll)0,v[i]);*/cout<<v[i]<<" " ;}cout<<"\n" ;}
double logy(ll n , ll b){if(b==0){return(-1);}if(n==1){return(0);}return((db)log10(n)/log10(b));}
long long power(long long k , long long n , long long m=mod){long long res = 1;while(n){if(n%2!=0){res = (res*k)%m ;}k = (k*k)%m ;n = n/2 ;}return(res) ;}
ll n,m,k,ko;
bool ok = false;
int main()
{
    FastIO ;
    PRECISION(10) ;
    ll a,b,c,d,i,j,t,x,y,z;//,x1,y1,z1,e,f;
    ll p,q,r,u,w ;
    char ch,chr ;
    //string str,st,str1,str2,str3,str4;
    //ll a1=0,a2=0,b1=0,b2=0,c1=0 ;
    //cin>>str>>str1;
    cin>>a>>b>>n;
    c = 0;
    d = n;
    ll ans = 0;
    while(d-c>=3)
    {
        //cout<<c<<" "<<d<<endl;
        ll mid1 = c + (d-c)/3;
        ll mid2 = d - (d-c)/3;
        x = (a*mid1)/b - a*(mid1/b);
        y = (a*mid2)/b - a*(mid2/b);
        ans = max(ans,x);
        ans = max(ans,y);
        if(x>y)
        {
            d = mid2;
        }
        else
        {
            c = mid1;
        }
    }
    for(i=c ; i<=d  ; i++)
    {
        ll mid1 = i;
        x = (a*mid1)/b - a*(mid1/b);
        ans = max(ans,x);
    }
    cout<<ans;
}

Measured memory_bytes: 3696
#include<bits/stdc++.h>
using namespace std;
int main(){
int a,b,c,x;
cin>>a>>b>>c>>x;
int count=0;
for(int i=0;i<=a;i++){
	for(int j=0;j<=b;j++){
		for(int k=0;k<=c;k++){
			if(i*500+j*100+k*50==x){
				count++;
			}
		}
	}
}
cout<<count;
}

Measured memory_bytes: 256