akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cmath>
#include <algorithm>
#include <cstring>
#include <string>
#include <cstdio>
using namespace std;

const double g = 9.8, eps = 1e-10;
const int maxn = 50;

int N, V, X, Y;
int L[maxn], B[maxn], R[maxn], T[maxn];

//计算以vy的速度竖直向上射出t秒后的位置
double calc(double vy, double t)
{
    return vy * t - g * t * t / 2;
}

//a相对于lb和ub的位置
int cmp(double lb, double ub, double a)
{
    return a < lb + eps ? -1 : a > ub - eps ? 1 : 0;
}

//判断当射出路线经过点（gx，gy）时，卵是否能击中猪
bool check(double gx, double gy)
{
    //设初速度在x方向和y方向的分量分别为vx和vy，设通过(gx, gy)的时间为t
    //求解联立方程式vx^2 + vy^2 = V^2，vx * t = gx，vy * t - 1/2 g t^2 = gy
    double a = g * g / 4, b = g * gy - V * V, c = gx * gx + gy * gy;
    double D = b * b - 4 * a * c;
    if (D < 0 && D > -eps) D = 0;
    if (D < 0) return false;
    for (int d=-1; d<=1; d+=2)
    {//验证联立方程式的两个解的循环
        double t2 = (-b + d * sqrt(D)) / (2 * a);
        if (t2 <= 0) continue;
        double t = sqrt(t2);
        double vx = gx / t, vy = (gy + g * t * t / 2) / t;
        
        //判断是否通过猪的正上方
        double yt = calc(vy, X / vx);
        if (yt < Y - eps) continue;
        
        bool ok = true;
        for (int i=0; i<N; ++i)
        {
            if (L[i] >= X) continue;
            //判断在猪正上方的鸟和猪之间是否有障碍物
            if (R[i] == X && Y <= T[i] && B[i] <= yt) ok = false;
            //判断在飞到猪正上方之前是否会撞到障碍物
            int yL = cmp(B[i], T[i], calc(vy, L[i] / vx));//左侧的相对位置
            int yR = cmp(B[i], T[i], calc(vy, R[i] / vx));//右侧的相对位置
            int xH = cmp(L[i], R[i], vx * (vy / g));//最高点的相对位置
            int yH = cmp(B[i], T[i], calc(vy, vy / g));
            if (xH == 0 && yH >= 0 && yL < 0) ok = false;
            if (yL * yR <= 0) ok = false;
        }
        if (ok) return true;
    }
    return false;
}

void solve()
{//裁掉猪以右的障碍物
    for (int i=0; i<N; ++i) R[i] = min(R[i], X);
    bool ok = check(X, Y);//直接撞上猪的情况
    for (int i=0; i<N; ++i)
    {
        ok |= check(L[i], T[i]);//经过左上角的情况
        ok |= check(R[i], T[i]);//经过右上角的情况
    }
    puts(ok ? "Yes" : "No");
    return;
}

int main()
{
    while (~scanf("%d %d %d %d", &N, &V, &X, &Y))
    {
        for (int i=0; i<N; ++i)
        {
            scanf("%d %d %d %d", &L[i], &B[i], &R[i], &T[i]);
        }
        solve();
    }
    return 0;
}




Measured memory_bytes: 3172
N,W=map(int,input().split())
weight=[0]*N
value=[0]*N
sumv=0
for i in range(N):
    weight[i],value[i]=map(int,input().split())
    sumv+=value[i]
dp=[[1000000000000]*(sumv+1) for i in range(N+1)]
dp[0][0]=0
for i in range(N):
    for j in range(sumv+1):
        if(value[i]<=j):
            dp[i+1][j]=min(dp[i][j-value[i]]+weight[i],dp[i][j])
        else:
            dp[i+1][j]=min(dp[i+1][j],dp[i][j])
res=0
for i in range(sumv+1):
    if(dp[N][i]<=W):
        res=max(res,i)
print(res)

Measured memory_bytes: 120044
import sys
N=int(input())
A=list(map(int,input().split()))
A.sort()
ans=0
current=A.pop()
num=1
if len(A)==0:
  if num<current: ans+=num
  else: ans+=num-current
while A:
  if A[-1]==current:
    num+=1
    current=A.pop()
    if len(A)==0:
      if num<current: ans+=num
      else: ans+=num-current
  else:
    if num<current: ans+=num
    else: ans+=num-current
    current=A.pop()
    num=1
    if len(A)==0:
      if num<current: ans+=num
      else: ans+=num-current
print(ans)

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

                //1  2  3  4  5  6  7  8  9 10 11 12
int mdays[12] = {31,28,31,30,31,30,31,31,30,31,30,31};

int main(void) {
  int x;

  std::string str;

  std::cin >> str;
  x = std::stoi(str);

  for (int X = x; X > 0; X--) {
    for (int i = 2; i <= 31 && i < X; i++) {
      for (int k = X; k >= i; k = k / i) {
        if (k % i != 0) {
          break;
        }
        if (k / i == k || k / i == 1) {
          //std::cout << k << std::endl;
          //std::cout << i << std::endl;
          std::cout << X << std::endl;
          return 0;
        }
      }
    }
  }

  std::cout << 1 << std::endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <cstdlib>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <map>
#include <stack>
#include <queue>
#include <set>
#include <cstring>

using namespace std;
// ascending order
#define vsort(v) sort(v.begin(), v.end())
// descending order
#define vsort_r(v) sort(v.begin(), v.end(), greater<int>())
#define vunique(v) unique(v.begin(), v.end())
#define mp make_pair
#define ts(x) to_string(x)
#define rep(i, a, b) for(int i = (int)a; i < (int)b; i++)
#define repm(i, a, b) for(int i = (int)a; i > (int)b; i--)
#define bit(a) bitset<8>(a)
#define des_priority_queue priority_queue<int, vector<int>, greater<int> >
#define all(v) (v).begin(), (v).end()
typedef long long ll;
typedef pair<int, int> P;
const ll INF = 1e18;

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int H, W;
	cin >> H >> W;
	string s[H];
	rep(i, 0, H) cin >> s[i];

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

	rep(i, 0, H) rep(j, 0, W) {
		if(s[i][j] == '#') {
			bool flag = true;
			rep(k, 0, 4) {
				int nx = j + dx[k];
				int ny = i + dy[k];
				if(0 <= nx and nx < W and 0 <= ny and ny < H) {
					if(s[ny][nx] == '#') flag = false;
				}
			}

			if(flag) {
				cout << "No" << endl;
				return 0;
			}
		}
	}

	cout << "Yes" << endl;
}


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

using namespace std;

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;

#define endl '\n'
#define MAX

typedef long long ll;
typedef pair<int,int> pii;
//typedef tree<int,null_type,less<int>,rb_tree_tag, tree_order_statistics_node_update> indexed_set;


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

	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	
	const ll oo = 0x3f3f3f3f3f3f3f3f;
	
	int n;
	cin >> n;
	vector<ll> a(n), dp(n, oo);

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

	dp[n - 1] = 0;
	for(int i = n - 2; i >= 0; i--)
		for(int k = 1; k < 3; k++)
			if(i + k < n)
				dp[i] = min(dp[i], dp[i + k] + abs(a[i] - a[i + k]));
	
	cout << dp[0] << endl;

	return 0;
}

Measured memory_bytes: 1792
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<cstring>
#include<vector>
#include<algorithm>
#include<functional>
#include<set>
#include<map>
#include<queue>
#include<stack>
#include<deque>
#include<tuple>
#include<iostream>
#include<string>
#include<unordered_map>
#include<unordered_set>
using namespace std;
#define REP(i,x) for (int i=0;i<x;i++)
#define REPP(i,x,y) for (int i=x;i<=y;i++)
#define SI(x) scanf("%d",&x)
#define SL(x) scanf("%lld",&x)
#define MX3(x,y,z) max(x,max(y,z))
#define MX4(x,y,z,p) max(x,max(y,max(z,p)))
#define MX5(x,y,z,p,q) max(x,max(y,max(z,max(p,q))))
#define MN3(x,y,z) min(x,min(y,z))
#define MN4(x,y,z,p) min(x,min(y,min(z,p)))
#define MN5(x,y,z,p,q) min(x,min(y,min(z,min(p,q))))
#define amax(x,y) x=max(x,y)
#define amin(x,y) x=min(x,y)
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<bool> vb;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef vector<vb> vvb;
typedef long double ld;
typedef pair<int,int> pi;
typedef pair<ll,ll> pl;
typedef tuple<int,int,int> ti;
typedef tuple<ll,ll,ll> tl;
// #####################################################################
const ll MOD = 1000000007;

void solve() {

    int n;
    SI(n);
    vi rec(n);
    vl dp(n);
    REP(i, n) {
        SI(rec[i]);
    }
    unordered_map<int,int> mp;
    ll ans = 0;
    REP(i, n) {
        if(i == 0) dp[i] = mp[rec[i]] = 1;
        else if (rec[i-1] != rec[i]) {
            dp[i] = (dp[i-1] + mp[rec[i]]) % MOD;
            mp[rec[i]] += dp[i-1];
            mp[rec[i]] %= MOD;
        } else {
            dp[i] = dp[i-1];
        }
    }
    ans += dp[n-1];
    ans %= MOD;
    printf("%lld\n", ans);
}

void init() {
    


}

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




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

typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> PII;
typedef pair<ll, int> PILL;
typedef pair<ll, ll> PLL;

const int MAX_N = 1e5+5;
const int M = 1e6;
const ll INF = (ll)(1e18);
const int inf = 1e9;
const ll MOD = 1000000007LL;

void solve() {

}



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

    int a, b, c;
    cin >> a >> b >> c;

    if (a+b+c >= 22) {
        cout << "bust";
    } else {
        cout << "win";
    }




    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(int argc, char const *argv[]) {
  int a[60], b[60], s[60], count, i, j, tmp, ans;
  scanf("%d", &count);
  for (i = 0; i < count; i++) {
    scanf("%d", &a[i]);
  }
  for (i = 0; i < count; i++) {
    scanf("%d", &b[i]);
  }
  for (i = 0; i < count; i++) {
    s[i] = a[i] - b[i];
    if(s[i] > 0)
    ans = ans + s[i];
  }
  printf("%d\n", ans);
  return 0;
}


Measured memory_bytes: 128
#define _USE_MATH_DEFINES
#define INF 10000000
#include <iostream>
#include <sstream>
#include <cmath>
#include <algorithm>
#include <queue>
#include <stack>
#include <limits>
#include <map>
#include <string>
#include <cstring>
#include <set>
#include <deque>
#include <bitset>
#include <list>

using namespace std;

typedef long long ll;
typedef pair <int,int> P;
typedef pair <int,P > PP;

static const double eps = 1e-8;

bool check(int i,string str){

	string ans;
	if(i%15==0) ans = "FizzBuzz";
	else if(i%3==0) ans = "Fizz";
	else if(i%5==0) ans = "Buzz";
	else{
		char buf[128];
		sprintf(buf,"%d",i);
		ans = buf;
	}

	return (ans == str);
}

int main(){
	int m,n;
	while(~scanf("%d %d",&m,&n)){
		if(m==n && n==0) break;
		list<int> player;
		for(int i=1;i<=m;i++) player.push_back(i);

		int alive = m;
		for(int i=0,j=0;i<n;i++){		
			string str;
			cin >> str;
			if(alive>1 && !check(i+1,str)){
				list<int>::iterator it = player.begin();
				advance(it,j);
				player.erase(it);
				alive--;
			}
			else j++;

			j %= alive;
		}

		for(list<int>::iterator it = player.begin(); it != player.end(); it++){
			printf("%s%d",it == player.begin() ? "" : " ",*it);
		}
		printf("\n");
	}
}

Measured memory_bytes: 972
#include <algorithm>
#include <iostream>
#include <set>
#include <vector>
#include <map>
#include <climits>
#include <bitset>
#include <cmath>

template <typename C>
void print_container(const C &c, const std::string &name)
{
  std::cout << name << ": ";
  std::for_each(c.cbegin(), c.cend(),
                [](auto &x) { std::cout << x << ", "; });
  std::cout << std::endl;
}

template <typename Container, class T>
bool contains(const Container& c, T v)
{
  return std::find(c.begin(), c.end(), v) != c.end();
}

int main()
{
  const int64_t INF = std::pow(10, 5 + 3 + 1); // larger than max(a) * M
  int N, M;
  std::cin >> N >> M;

  const int n_ptn = std::pow(2, N);
  std::vector<std::vector<int64_t>> dp(M);
  for(int i=0; i<M; i++) {
    dp[i].assign(n_ptn, INF);
  }
  dp[0][0] = 0;

  for(int i=0; i<M; i++) {
    // read a, b
    int64_t a, b;
    std::cin >> a >> b;

    // read c[i] and update dp
    int s = 0;
    for(int j=0; j<b; j++) {
      int c;
      std::cin >> c;
      c--;  // 0-orient, 0-N

      s += 1 << c;
    }

    if(i==0) {
      dp[i][s] = a;
      continue;
    }

    for(int k=0; k<n_ptn; k++) {
      dp[i][k] = std::min(dp[i][k], dp[i-1][k]);
      dp[i][k|s] = std::min(dp[i][k|s], dp[i-1][k] + a);
    }
  }

  // for(int i=0 ;i<M; i++) {
  //   std::string name = "dp[" + std::to_string(i) + "]";
  //   print_container(dp[i], name);
  // }

  int64_t ret = dp[M-1][n_ptn-1];
  if(ret == INF) {
    ret = -1;
  }

  std::cout << ret << std::endl;
  return 0;
}


Measured memory_bytes: 35992
# :20
import sys


def input(): return sys.stdin.readline().strip()
def I(): return int(input())
def LI(): return list(map(int, input().split()))
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def S(): return input()
def LS(): return input().split()


INF = float('inf')


x, y, a, b, c = LI()
p = sorted(LI())[::-1][:x]
q = sorted(LI())[::-1][:y]
r = sorted(LI())[::-1][:x+y]
# print(p, q, r)
bucket = []
bucket += [[i, 'p'] for i in p]
bucket += [[i, 'q'] for i in q]
bucket += [[i, 'r'] for i in r]
bucket = sorted(bucket, key=lambda x: x[0])
# print(bucket)
d = {'p': 0, 'q': 0}
ans = 0
cnt = 0
while cnt < x + y:
    if bucket[-1][1] == 'p' and d[bucket[-1][1]] < x:
        ans += bucket.pop()[0]
        d['p'] += 1
        cnt += 1
    elif bucket[-1][1] == 'q' and d[bucket[-1][1]] < y:
        ans += bucket.pop()[0]
        d['q'] += 1
        cnt += 1
    else:
        ans += bucket.pop()[0]
        cnt += 1
print(ans)


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

using namespace std;

using ll = long long;
using vi = vector<int>;
using vll = vector<ll>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<ll>>;

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  string s, t;
  cin >> s >> t;
  string si = s, ti = t;
  reverse(si.begin(), si.end());
  reverse(ti.begin(), ti.end());
  if (s == ti && t == si) cout << "YES" << endl;
  else cout << "NO" << endl;
  return 0;
}


Measured memory_bytes: 256
#!/usr/bin/env python3
import sys
N, K = map(int, input().split())
H = sorted(list(map(int, input().split())), reverse=True)
if K != 0:
    if len(H) <= K:
        print(0)
    else:
        print(sum(H[K:]))
else:
    print(sum(H))

Measured memory_bytes: 26024
#include<bits/stdc++.h>
using namespace std;
int main(){
  
  int A,B,C,D;
  cin >> A >> B >> C >> D;
  
  if (A + B < C + D){
    cout << "Right" << endl;
  }
  else if (A + B > C + D){
    cout << "Left" << endl;
  }
  else{
    cout << "Balanced" << endl;
  }
}
  

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll  long long
#define FASTINOUT ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
const ll mod = 1e9+7;
const int N=2e5+9;
int main()
{
    FASTINOUT;
    ll x,k;
    cin>>x>>k;
    ll y[x],sum=0;
    for (int i=0;i<x;i++){
        cin>>y[i];
        sum+=y[i];
    }
    sort(y,y+x);
    reverse(y,y+x);
    for (int i=0;i<k;i++){
        if (y[i]*4*k<sum){
            cout<<"No";
            return 0;
        }
    }
    cout<<"Yes";
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>  
#include <algorithm>  
#include <assert.h>
#include <bitset>
#include <cmath>  
#include <complex>  
#include <deque>  
#include <functional>  
#include <iostream>  
#include <limits.h>  
#include <map>  
#include <math.h>  
#include <queue>  
#include <set>  
#include <stdlib.h>  
#include <string.h>  
#include <string>  
#include <time.h>  
#include <unordered_map>  
#include <unordered_set>  
#include <vector>  

#pragma warning(disable:4996)  
#pragma comment(linker, "/STACK:336777216")  
using namespace std;

#define mp make_pair  
#define Fi first  
#define Se second  
#define pb(x) push_back(x)  
#define szz(x) ((int)(x).size())  
#define rep(i, n) for(int i=0;i<n;i++)  
#define all(x) (x).begin(), (x).end()  
#define ldb ldouble  

typedef tuple<int, int, int> t3;
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ldb;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef pair <ll, int> pli;
typedef pair <db, db> pdd;

int IT_MAX = 1 << 17;
const ll MOD = 998244353;
const int INF = 0x3f3f3f3f;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
const db PI = acos(-1);
const db ERR = 1e-10;


ll dp[90050];
ll dp2[90050];

int in[305];
int main() {
	int N, i, j;
	scanf("%d", &N);

	dp[0] = 1;
	for (i = 1; i <= N; i++) {
		scanf("%d", &in[i]);
		for (j = 90000; j >= in[i]; j--) {
			dp[j] += dp[j - in[i]];
			dp[j] %= MOD;
		}
	}

	dp2[0] = 1;
	for (i = 1; i <= N; i++) {
		for (j = 90000; j >= in[i]; j--) {
			dp2[j] = (2 * dp2[j] + dp2[j - in[i]]) % MOD;
		}
		for (j = in[i] - 1; j >= 0; j--) dp2[j] = (2 * dp2[j]) % MOD;
	}

	ll ans = 1;
	for (i = 1; i <= N; i++) ans = (ans * 3) % MOD;

	int sum = 0;
	for (i = 1; i <= N; i++) sum += in[i];
	for (i = 1; i <= 90000; i++) {
		if (!dp2[i]) continue;
		if (i * 2 < sum) continue;

		ans -= dp2[i] * 3;
		ans %= MOD;
	}

	if (sum % 2 == 0) ans = (ans + dp[sum / 2] * 3) % MOD;
	return !printf("%lld\n", (ans + MOD) % MOD);
}

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

using namespace std;

mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count());
typedef long long ll;
typedef long double ld;


int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int r;
  cin >> r;
  cout << fixed << setprecision(2) << 4.0 * acos(0.0) * r << "\n";
  return 0;
}


Measured memory_bytes: 3816
//PCK2018本選-9問目 メイズ＆アイテム
//AOJが停止したためここに提出
//21:15~25:15
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
using namespace std;
typedef long long ll;
#define mod 1000000007
#define chmin(a,b) a=min(a,b)
ll w,h;
ll mas[1010][1010];
bool vis[1010][1010];
ll cost[10][10];
ll dist[32][32];
int main(){
  cin>>w>>h;
  for(int i=0;i<h;i++){
      string s; cin>>s;
      for(int j=0;j<w;j++){
	  if(s[j]=='.')mas[i][j]=-1;
	  if(s[j]=='#')mas[i][j]=-2;
	  if('0'<=s[j]&&s[j]<='9')mas[i][j]=s[j]-'0';
	  if('A'<=s[j]&&s[j]<='J')mas[i][j]=s[j]-'A'+10;
	  if('a'<=s[j]&&s[j]<='j')mas[i][j]=s[j]-'a'+20;
	  if(s[j]=='S')mas[i][j]=30;
	  if(s[j]=='T')mas[i][j]=31;
      }
  }
  for(int i=0;i<10;i++)for(int j=0;j<10;j++)cin>>cost[i][j];
  for(int k=0;k<32;k++){
      ll x=-1,y;
      for(int i=0;i<h;i++)for(int j=0;j<w;j++){
	  if(mas[i][j]==k)x=i,y=j;
	  vis[i][j]=0;
      }
      for(int r=0;r<32;r++)dist[k][r]=1e17;
      if(x==-1){
	  continue;
      }
      queue<pair<ll,pair<ll,ll> > > Q;
      Q.push(make_pair(0,make_pair(x,y)));
      while(!Q.empty()){
	  ll cos=Q.front().first;
	  ll xx=Q.front().second.first;
	  ll yy=Q.front().second.second;
	  Q.pop();
	  if(vis[xx][yy])continue;
	  vis[xx][yy]=1;
	  if(mas[xx][yy]>=0){
	      dist[k][mas[xx][yy]]=cos;
	      if(cos>0)continue;
	  }
	  if(mas[xx][yy]==-2)continue;
	  ll dx[]={0,1,0,-1},dy[]={1,0,-1,0};
	  for(int t=0;t<4;t++){
	      ll xxx=xx+dx[t],yyy=yy+dy[t];
	      if(xxx<0||xxx==h||yyy<0||yyy==w)continue;
	      Q.push(make_pair(cos+1,make_pair(xxx,yyy)));
	  }
      }
  }
  
  pair<ll,ll> dp[32][1024];
  for(int i=0;i<32;i++)for(int s=0;s<1024;s++){
      dp[i][s]=make_pair((ll)1e17,(ll)0);
  }
  dp[30][0]=make_pair(0,0);
  for(ll s=0;s<1024;s++){
      ll wf[32][32];
      for(int i=0;i<32;i++)for(int j=0;j<32;j++){
	  bool vl=1;
	  if(10<=i&&i<20&&(s&(1LL<<(i-10)))>0)vl=0;
	  if(20<=i&&i<30&&(s&(1LL<<(i-20)))==0)vl=0;
	  bool vr=1;
	  if(10<=j&&j<20&&(s&(1LL<<(j-10)))>0)vr=0;
	  if(20<=j&&j<30&&(s&(1LL<<(j-20)))==0)vr=0;
	  if(vl&vr){
	      wf[i][j]=dist[i][j];
	  }
	  else{
	      wf[i][j]=1e17;
	  }
      }
      for(int k=0;k<32;k++){
	  for(int i=0;i<32;i++)for(int j=0;j<32;j++){
	      chmin(wf[i][j],wf[i][k]+wf[k][j]);
	      chmin(wf[i][j],(ll)1e17);
	  }
      }
      
      for(int i=0;i<12;i++){
	  for(int j=0;j<12;j++){
	      if(i==j)continue;
	      ll x=i; if(x>=10)x+=20;
	      ll y=j; if(y>=10)y+=20;
	      if(x==31)continue;
	      if(y==30)continue;
	      ll len=dp[x][s].first+wf[x][y];
	      if(len>=1e17)continue;
	      if(y<10){
		  if(s&(1LL<<j))continue;
		  ll ss=s+(1LL<<j);
		  ll cos=dp[x][s].second;
		  if(x<10)cos-=cost[x][y];
		  chmin(dp[y][ss],make_pair(len,cos));
	      }
	      else{
		  if(s!=1023)continue;
		  ll cos=dp[x][s].second;
		  chmin(dp[31][1023],make_pair(len,cos));
	      }
	  }
      }
  }
  if(dp[31][1023].first>=1e17){
      cout<<-1<<endl;
  }
  else{
      cout<<dp[31][1023].first<<" "<<-dp[31][1023].second<<endl;
  }
  return 0;
}



Measured memory_bytes: 12632
#include <iostream>


int main() {
  int a, b, k;
  std::cin >> a >> b >> k;
  // [a, a+k)
  int range_a_max = a + k;
  b++;
  // [b-k, b)
  int range_b_min = b - k;
  if (range_a_max >= range_b_min) {
    for (int i = a; i < b; i++) {
      std::cout << i << std::endl;
    }
    return 0;
  }
  for (int i = a; i < range_a_max; i++)
    std::cout << i << std::endl;
  for (int i = range_b_min; i < b; i++)
    std::cout << i << std::endl;

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define mod 1000000007
#define MAX 1000000000000000
#define all(v) v.begin(),v.end()
#define rep(i,a,b) for(i=(ll)a;i<(ll)b;i++)
#define revrep(i,a,b) for(i=(ll)a;i>=(ll)b;i--)
#define ii pair<ll,pair<ll,ll> >
#define MP make_pair
#define pb push_back
#define f first
#define se second
#define ll long long int
#define vi vector<ll>
ll modexp(ll a,ll b){ ll res = 1; while(b > 0){  if(b & 1) res = (res * a)%mod;  a = (a * a)%mod;  b/=2;  }  return res; }
#define rs resize
typedef tree< ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update > OST;
#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
    template <typename Arg1>
    void __f(const char* name, Arg1&& arg1){
        cout << name << " : " << arg1 << endl;
    }
    template <typename Arg1, typename... Args>
    void __f(const char* names, Arg1&& arg1, Args&&... args){
        const char* comma = strchr(names + 1, ','); cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
    }
#else
#define trace(...)
#endif

const ll N = 100009;
ll a,b,c;
int main()
{
    std::ios_base::sync_with_stdio(false); cin.tie(NULL);
    cin>>a>>b>>c;
    cout<<(a - b)%c;
    return 0;
}

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

int main(){
  string s, t;
  cin >> s >> t;
  string tmp = s;
  for (int i = 0 ; i < s.size(); i++){
    char a = *(tmp.end()-1);
    tmp.erase(tmp.end()-1);
    tmp = a + tmp;
    if (tmp == t){
      cout << "Yes" << endl;
      return 0;
    }
  }
  cout << "No" << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a,b) for(int (i)=(a);(i)<=(b);++i)
#define PER(i,a,b) for(int (i)=(a);(i)>=(b);--i)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define lb lower_bound
#define ub upper_bound
#define SZ(x) ((int)((x).size()))
#define ALL(t) t.begin(),t.end()
#define CLR(x) memset(x,0,sizeof(x))
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef long double ld;
#define DBG(vari) cout<<"["<<__LINE__<<"] "<<#vari<<" = "<<(vari)<<endl;
#define FLASH ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
inline void rwFile(string file) {freopen((file+".in").c_str(),"r",stdin); freopen((file+".out").c_str(),"w",stdout);}
inline bool EQ(ld a,ld b) {return fabs(a-b)<=(1e-7);}
ll powmod(ll a,ll b,ll mod) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;} return res;}
ll inv(ll a,ll mod) {return powmod(a,mod-2,mod);}
void clk() {cout<<" Execution Time = "<<(int)(clock()*1000./CLOCKS_PER_SEC)<<" ms\n";}
const ll inf=1000000007;
const ld pi=3.141592653589;
//==============================================CUT_BEGINS==========================================================//

int main() {
	int h, w; 
	cin >> h >> w;
	ll a[h + 5][w + 5];
	ll dist[12][12];
	REP(i, 0, 9) REP(j, 0, 9) dist[i][j] = inf;
	REP(i, 0, 9) REP(j, 0, 9) {
		ll data; cin >> data;
		dist[i][j] = data;
	}
	REP(k, 0, 9) REP(i, 0, 9) REP(j, 0, 9) {
		dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);
	}
	ll ans = 0;
//	REP(i,0,9) REP(j,0,9) cout << dist[i][j] << " ";
	REP(i, 1, h) REP(j, 1, w) {
		cin >> a[i][j];
		if (a[i][j] != -1)
			ans += dist[a[i][j]][1];
	}
	cout << ans << '\n';
	return 0;
}

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

struct UnionFind{
  vector<int> p;
  UnionFind(int n){
    p.resize(n+1);
    for(int i=0; i<=n; i++)
      p[i] = i;
  }
  int find(int x){
    if(p[x] == x)  return x;
    return p[x] = find(p[x]);
  }
  void unite(int x, int y){
    x = find(x);
    y = find(y);
    if(x == y)  return;
    p[x] = y;
  }
};

int main(){
  int n, m;  cin >> n >> m;
  vector<pair<int, int>> edge(m);

  for(int i=0; i<m; i++)
    cin >> edge[i].first >> edge[i].second;

  long ans = 0;
  for(int i=0; i<m; i++){
    UnionFind uf(n);
    for(int j=0; j<m; j++){
      if(j == i)  continue;
      uf.unite(edge[j].first, edge[j].second);
    }
    bool ok = false;
    for(int i=2; i<=n; i++)
      if(uf.find(1) != uf.find(i)){
	ok = true;
	break;
      }
    if(ok)  ans++;
  }
  
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3524
#include <stdio.h>
int main(void){
   int n,i,j,k,l;
   int dice[24][6];
   int label[24][6]={{1,2,3,4,5,6},{1,3,5,2,4,6},{1,4,2,5,3,6},{1,5,4,3,2,6},{2,1,4,3,6,5},{2,3,1,6,4,5},
   {2,4,6,1,3,5},{2,6,3,4,1,5},{3,1,2,5,6,4},{3,2,6,1,5,4},{3,5,1,6,2,4},{3,6,5,2,1,4},{4,1,5,2,6,3},
   {4,2,1,6,5,3},{4,5,6,1,2,3},{4,6,2,5,1,3},{5,1,3,4,6,2},{5,3,6,1,4,2},{5,4,1,6,3,2},{5,6,4,3,1,2},
   {6,2,4,3,5,1},{6,3,2,5,4,1},{6,4,5,2,3,1},{6,5,3,4,2,1}};
   
   scanf("%d",&n);
   int dices[n][6];
   
   for(i=0;i<n;i++){
       for(j=0;j<6;j++) scanf("%d",&dices[i][j]);
   }
   
   /*for(i=0;i<n;i++){
       for(j=0;j<6;j++) {
           printf("%d",dices[i][j]);
       }
       putchar('\n');
   }*/
   
   for(i=0;i<n-1;i++){
       for(j=i+1;j<n;j++){
           
           for(k=0;k<24;k++){
               for(l=0;l<6;l++) dice[k][l]=dices[j][label[k][l]-1];
           }
           
          /* for(k=0;k<24;k++){
               for(l=0;l<6;l++) {
                   printf("%d",dice[k][l]);
               }
               putchar('\n');
           }*/
           
           for(k=0;k<24;k++){
               for(l=0;l<6;l++) {
                   if(dice[k][l]!=dices[i][l]) {
                       break;
                   }
               }
               if(l==6){
                    printf("No\n");
                    return 0;
               }
           }
       }
   }
   
   printf("Yes\n");
   return 0;
}



Measured memory_bytes: 2104
#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define MOD 998244353
#define INF 1000000010
#define EPS 1e-9
#define F first
#define S second

#define debug(x) cout<<x<<endl;
#define repi(i,x,n) for(int i=x;i<n;i++)
#define rep(i,n) repi(i,0,n)
#define lp(i,n) repi(i,0,n)
#define repn(i,n) for(int i=n;i>=0;i--)
//#define int long long
#define endl "\n"

typedef pair<int,int> PII;
typedef pair<int,string> PIS;
typedef pair<string,int> PSI;


signed main(){
  //cin.tie(0);	
  //ios::sync_with_stdio(false);
  int n;
  string x;
  cin>>n>>x;
  int totalpop=0;
  int modlow,modhigh;
  int lowsum=0,highsum=0;
  repn(i,n-1){
    if(x[i]=='1'){
      totalpop++;
    }
  }
  modlow=totalpop-1;
  modhigh=totalpop+1;
  //if(totalpop==1) modlow=1;
  int table[totalpop+5];
  table[0]=0;
  repi(i,1,totalpop+5){
    int xx=0,X=i;
    while(X!=0){
      if(X%2==1) xx++;
      X/=2;
    }
    table[i]=i%xx;
  }
  int lownow=1,highnow=1;
  //cout<<x<<endl;
  repn(i,n-1){
    if(x[i]=='1'){
      if(modlow!=0){
	lowsum+=(lownow%modlow);
	lowsum%=modlow;
      }
      highsum+=(highnow%modhigh);
      highsum%=modhigh;
      // cout<<lowsum<<" "<<highsum<<endl;
    }
   
    lownow*=2;
    highnow*=2;
    if(modlow!=0) lownow%=modlow;
    highnow%=modhigh;
  }
  // cout<<lowsum<<" "<<highsum<<endl;
  lownow=1,highnow=1;
  int now=1;
  vector<int> anss;
  repn(i,n-1){
    int num=0;
    if(x[i]=='0'){
      num=highsum;
      num+=(highnow%modhigh);
      num%=modhigh;
    }else{
      num=lowsum;
      if(modlow!=0){
	num-=(lownow%modlow);
	while(num<0){
	  
	  num+=modlow;
	}
	num%=modlow;
      }
    }
    //cout<<num<<endl;
    int ans=0,nextmod=0;
    while(num!=0){
      // cout<<'a'<<endl;
      num=table[num];
      ans++;
    }
    if(x[i]=='1' && modlow==0) ans=-1;
    anss.push_back(ans+1);
    
    lownow*=2;
    highnow*=2;
    if(modlow!=0) lownow%=modlow;
    highnow%=modhigh;
    
  }
  repn(i,n-1){
    cout<<anss[i]<<endl;
  }

  return 0;
}


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

typedef long long ll;
typedef pair<int,int> P;

#define p_ary(ary,a,b,i) do { cout << "["; for (int (i) = (a);(i) < (b);++(i)) cout << ary[(i)] << ((b)-1 == (i) ? "" : ", "); cout << "]\n"; } while(0)
#define p_map(map,it) do {cout << "{";for (auto (it) = map.begin();;++(it)) {if ((it) == map.end()) {cout << "}\n";break;}else cout << "" << (it)->first << "=>" << (it)->second << ", ";}}while(0)

struct interval {
    int s,t,x;
    bool operator<(const interval& a) const {
        return x < a.x;
    }
};

int main() {
    int n,q;
    cin >> n >> q;
    vector<int> ans(q,-1);
    vector<interval> a(n);
    set<P> st;
    for (int i = 0;i < n;++i) cin >> a[i].s >> a[i].t >> a[i].x;
    sort(a.begin(),a.end());
    for (int i = 0;i < q;++i) {
        int d;
        cin >> d;
        st.insert(P(d,i));
    }
    st.insert(P(INT_MAX,0));
    for (int i = 0;i < n;++i) {
        auto it = st.lower_bound(P(a[i].s-a[i].x,-1));
        while (it->first < a[i].t-a[i].x) {
            ans[it->second] = a[i].x;
            it = st.erase(it);
        }
    }
    for (int i = 0;i < q;++i) cout << ans[i] << "\n";
    return 0;
}

Measured memory_bytes: 14464
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
typedef unsigned long long ULL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);

//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

bool field[8][8];
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

void bomb(int x, int y) {
  field[x][y] = false;
  REP(i, 4) {
    for(int j = 1; j <= 3; j++) {
      int tx = x+dx[i]*j;
      int ty = y+dy[i]*j;
      if(tx < 0 || ty < 0 || tx > 7 || ty > 7) continue; 
      if(field[tx][ty])bomb(tx, ty);
    }
  }
}

int main() {
  int n, x, y;
  string str;

  cin >> n;
  REP(i, n) {
    getline(cin, str);
    REP(j, 8) {
      cin >> str;
      REP(k, 8) {
	if(str[k] == '0') field[j][k] = false;
	else field[j][k] = true;
      }
    }
    cin >> y >> x;
    bomb(x-1, y-1);

    cout << "Data " << i+1 << ":\n";
    REP(j, 8) {
      REP(k, 8) {
	cout << field[j][k];
      }
      cout << endl;
    }
  }
}

Measured memory_bytes: 1204
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define mod 1000000007
#define fi first
#define sc second
#define rep(i,x) for(long long i=0;i<x;i++)
#define repn(i,x) for(long long i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
vector<pair<string,P> >vec;


void solve(long long S){
	ll X2 = 0, Y2 = 0, X3 = 0, Y3 = 0, c = 1000000000;
	Y2 = (S+(c-1))/c;
	X2 = c-S%c;
	if (X2 == c) X2 = 0;
	cout << "0 0 " << X2 << " " << Y2 << " 1000000000 1" << endl;
}

int main(){	
	long long S;
	scanf("%lld",&S);
	solve(S);
	return 0;
}

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

using namespace std;

const int N = 100100;

vector<int> g[N];
bool used[N];

int Dfs(int v, vector<int> &path) {
  path.push_back(v);
  for (int to : g[v]) {
    if (!used[to]) {
      used[to] = true;
      return Dfs(to, path);
    }
  }
  return v;
}

int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  int s0 = -1, s1;
  for (int it = 0; it < m; ++it) {
    int x, y;
    scanf("%d%d", &x, &y);
    --x, --y;
    g[x].push_back(y);
    g[y].push_back(x);
    if (s0 == -1) {
      s0 = x;
      s1 = y;
    }
  }
  used[s0] = used[s1] = true;
  vector<int> path;
  s0 = Dfs(s0, path);
  reverse(path.begin(), path.end());
  s1 = Dfs(s1, path);
  printf("%d\n", int(path.size()));
  for (int v : path) {
    printf("%d ", v + 1);
  }
  puts("");
  return 0;
}

Measured memory_bytes: 9464
import java.util.*;

public class Main {
    private static final Scanner scn = new Scanner(System.in);
    
    public static void main(String[] args) {
        int[] num = new int[6];
        for(int i = 0; i < 6; i++) {
            num[i] = scn.nextInt();
        }
        Dice dice = new Dice(num);
        dice.move(scn.next());
        System.out.println(dice.show(Dice.TOP));
    }
}

class Dice {
    int[] num_ = new int[6];
    public static final int
      TOP = 0, SOUTH = 1, EAST = 2,
      WEST = 3, NORTH = 4, BOTTOM = 5;
    
    public Dice(int... num) {
        for(int i = 0; i < 6; i++) {
            num_[i] = num[i];
        }
    }
    
    public int show(int side) {
        return num_[side];
    }
    
    public void move(String str) {
        char[] ary = str.toCharArray();
        for(char elm : ary) {
            move(elm);
        }
    }
    
    public void move(char dir) {
        if(dir == 'S') {
            toSouth();
        } else if(dir == 'E') {
            toEast();
        } else if(dir == 'W') {
            toWest();
        } else if(dir == 'N') {
            toNorth();
        }
    }
    
    private void toSouth() {
        int tmp      = num_[TOP];
        num_[TOP]    = num_[NORTH];
        num_[NORTH]  = num_[BOTTOM];
        num_[BOTTOM] = num_[SOUTH];
        num_[SOUTH]  = tmp;
    }
    
    private void toEast() {
        int tmp      = num_[TOP];
        num_[TOP]    = num_[WEST];
        num_[WEST]   = num_[BOTTOM];
        num_[BOTTOM] = num_[EAST];
        num_[EAST]   = tmp;
    }
    
    private void toWest() {
        int tmp      = num_[TOP];
        num_[TOP]    = num_[EAST];
        num_[EAST]   = num_[BOTTOM];
        num_[BOTTOM] = num_[WEST];
        num_[WEST]   = tmp;
    }
    
    private void toNorth() {
        int tmp      = num_[TOP];
        num_[TOP]    = num_[SOUTH];
        num_[SOUTH]  = num_[BOTTOM];
        num_[BOTTOM] = num_[NORTH];
        num_[NORTH]  = tmp;
    }
}

Measured memory_bytes: 26352
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <iostream>
#include <iostream>
#include <fstream>
#include <numeric>
#include <cstring>
#include <cassert>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <cmath>
#include <set>
#include <map>
#include <functional>
#include <bitset>
#include <iomanip>
#include <stack>
#include <list>
using namespace std;
#define ll           long long
#define all(v)       (v).begin() , (v).end()
#define vi           vector <ll>
#define vii          vector <pair<ll,ll>>
#define ii           pair<ll,ll>
#define sz(v)	     ((int)((v).size()))
#define lp(i,a,b)    for(int i=a;i<b;i++)
#define pb           push_back
#define pf           push_front
#define F            first
#define S            second
#define endl         "\n"
#define IOS          ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
const double PI = 3.14159265358979323846;
const ll inf=2e9,MOD=998244353,MAX=1e7+2;

int main() {
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    IOS;
    ll a;
    string b;
    cin>>a>>b;
    ll x=0,f=0,y=0;
    lp(i,0,sz(b)){
        if(b[i]=='.')
            f=1;
        if(f&&b[i]!='.'){
            y*=10;
            y+=b[i]-'0';
        }
        else if(!f) {
            x*=10;
            x+=b[i]-'0';
        }
    }
    ll z=a*y;
    z/=10;
    z/=10;
    cout<<x*a+z;

}

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

// {U}{INT,LONG,LLONG}_{MAX,MIN}
#define INF         INT_MAX/3
#define LLINF       LLONG_MAX/3
#define MOD         (1000000007LL)
#define MODA(a, b)  a=((a)+(b))%MOD
#define MODP(a, b)  a=((a)*(b))%MOD
#define inc(i, l, r)   for(int i=(l);i<(r);i++)
#define dec(i, l, r)   for(int i=(r)-1;i>=(l);i--)
#define pb          push_back
#define se          second
#define fi          first
#define mset(a, b)  memset(a, b, sizeof(a))

using LL  = long long;
using G   = vector<vector<int>>;

int di[] = {0, -1, 0, 1};
int dj[] = {1, 0, -1, 0};
// }}}

int main() {
    cin.tie(0);ios::sync_with_stdio(false);
    int n;cin >> n;
    inc(i, n, 1000){
        if(i%111 == 0){
            cout << i << endl;
            break;
        }
    }
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
typedef long long ll;
ll gi(){
	ll x=0,f=1;
	char ch=getchar();
	while(!isdigit(ch))f^=ch=='-',ch=getchar();
	while(isdigit(ch))x=x*10+ch-'0',ch=getchar();
	return f?x:-x;
}
bool yes[200010];
int ans[200010];
int main(){
#ifdef XZZSB
	freopen("in.in","r",stdin);
	freopen("out.out","w",stdout);
#endif
	int n=gi(),X=gi();
	if(X==1||X==2*n-1)return puts("No"),0;
	puts("Yes");
	if(n==2)puts("1\n2\n3");
	else{
		bool flg=0;
		if(X==2)flg=1,X=2*n-2;
		yes[X]=yes[X-1]=yes[X-2]=yes[X+1]=1;
		ans[n-1]=X-1,ans[n]=X,ans[n+1]=X+1,ans[n+2]=X-2;
		for(int i=1,j=1;i<2*n;++i){
			while(yes[j])++j;
			if(ans[i])continue;
			ans[i]=j,yes[j]=1;
		}
		if(flg)for(int i=1;i<2*n;++i)ans[i]=2*n-ans[i];
		for(int i=1;i<2*n;++i)printf("%d\n",ans[i]);
	}
	return 0;
}


Measured memory_bytes: 2432
import java.util.*;

class Main{
 public static void main(String args[]){
   Scanner scn = new Scanner(System.in);
   int n = scn.nextInt();
   List<Integer> li = new ArrayList<>();
   for(int i = 0; i<n; i++){
	 li.add(scn.nextInt());
   }
   if(!li.contains(1)){
     System.out.println(-1);
     return;
   }
   int breaking = 0;
   int currentNo = 1;
   while(li.contains(currentNo)){
     breaking += li.indexOf(currentNo);
	 li = li.subList(li.indexOf(currentNo)+1, li.size());
     currentNo++;
   }
   breaking += li.size();
   System.out.println(breaking);
 }
}

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

int main() {
	map<string, int> ms;
	string s, ans, ans2;
	int max = 0, max2 = 0;
	
	while (cin >> s) {
		ms[s]++;
		if (max2 < ms[s]) {
			max2 = ms[s];
			ans2 = s;
		}
		if (max < s.size()) {
			max = s.size();
			ans = s;
		}
		
	}
	cout << ans2 << " " << ans << endl;
}


Measured memory_bytes: 3172
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
using namespace std;
#pragma warning (disable: 4996)

int N, M, A[1 << 17], P[1 << 17], Q[1 << 17], pre[1 << 17], low[1 << 17], col[1 << 17], R[1 << 17], dp[1 << 17], dp2[1 << 17], cnts, cntw;
vector<int>X[1 << 17], Y[1 << 17], Z[1 << 17], W[1 << 17];
map<pair<int, int>, int>Map;
bool used[1 << 17];

void dfs(int pos, int prevs) {
	cnts++; pre[pos] = cnts;
	low[pos] = cnts;

	for (int i = 0; i < X[pos].size(); i++) {
		int to = X[pos][i];
		if (pre[to] != 0) {
			if (prevs != to) low[pos] = min(low[pos], low[to]);
			continue;
		}

		dfs(to, pos); low[pos] = min(low[pos], low[to]);

		if (low[to] == pre[to]) {
			Map[make_pair(pos, to)] = 1;
			Map[make_pair(to, pos)] = 1;
		}
	}
}

void dfs2(int pos) {
	if (col[pos] >= 1) return;
	col[pos] = cntw; if (R[cntw] != 0) used[cntw] = true; R[cntw] += A[pos];
	for (int i = 0; i < Y[pos].size(); i++) {
		dfs2(Y[pos][i]);
	}
}

void dfs3(int pos) {
	dp[pos] = 0; int maxn = 0;
	for (int i = 0; i < Z[pos].size(); i++) {
		int to = Z[pos][i];
		if (dp[to] != -1) continue;
		dfs3(to); if (used[to] == true) used[pos] = true;
		W[pos].push_back(to);
		maxn = max(maxn, dp[to]);
	}
	dp[pos] = maxn;
	dp[pos] += R[pos];
}
void dfs4(int pos) {
	dp2[pos] = 0; int maxn = 0;
	for (int i = 0; i < Z[pos].size(); i++) {
		int to = Z[pos][i];
		if (dp2[to] != -1 || used[to] == false) continue;
		dfs4(to);
		maxn = max(maxn, dp2[to]);
	}
	dp2[pos] = maxn;
	dp2[pos] += R[pos];
}

int main() {
	//FILE *in = freopen("in1.txt", "r", stdin);
	cin >> N >> M;
	for (int i = 1; i <= N; i++) { cin >> A[i]; low[i] = (1 << 30); dp[i] = -1; dp2[i] = -1; }
	for (int i = 0; i < M; i++) {
		cin >> P[i] >> Q[i];
		X[P[i]].push_back(Q[i]);
		X[Q[i]].push_back(P[i]);
	}
	dfs(1, -1);

	for (int i = 0; i < M; i++) {
		if (Map[make_pair(P[i], Q[i])] == 0) {
			Y[P[i]].push_back(Q[i]);
			Y[Q[i]].push_back(P[i]);
		}
	}
	for (int i = 1; i <= N; i++) {
		if (col[i] >= 1) continue;
		cntw++;
		dfs2(i);
	}
	for (int i = 0; i < M; i++) {
		if (col[P[i]] != col[Q[i]]) {
			Z[col[P[i]]].push_back(col[Q[i]]);
			Z[col[Q[i]]].push_back(col[P[i]]);
		}
	}
	dfs3(col[1]);
	dfs4(col[1]);

	int ans = 0, maxn = 0; used[1] = true;
	for (int i = 1; i <= N; i++) { if (used[i] == true) ans += R[i]; }
	for (int i = 1; i <= N; i++) { if (used[i] == false) maxn = max(maxn, dp[i]); }
	ans += maxn;
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 54876
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <queue>
#include <map>
#include <numeric>
#include <unordered_map>
#include <iomanip>
#include <functional>
#include <bitset>
#include <complex>
#include <stack>



#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define all(x) (x).begin(),(x).end()

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

typedef long long ll;

using namespace std;


int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  int a,b;
  cin>>a>>b;
  cout<<a-(a>b)<<endl;

  return 0;

}


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

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

	for (int i = 0; i < n.length(); i++)
	{
		if (n[i] == '1')
		{
			cout << 9;
		}
		else
		{
			cout << 1;
		}
	}

	cout << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
	int n,m;
	while(true){
		cin>>n>>m;
		if(n==0)	return 0;
		vector<int> p(n);
		for(int i=0;i<n;i++)	cin>>p[i];
		p.push_back(0);	n++;
		vector<int> s;
		for(int i=0;i<n;i++){
			for(int j=0;j<n;j++)	if(p[i]+p[j]<m)	s.push_back(p[i]+p[j]);
		}
		sort(s.begin(),s.end());
		int ans=0,fw=0,en=s.size()-1;
		while(true){
			if(s[fw]+s[en]>ans&&s[fw]+s[en]<=m)	ans=s[fw]+s[en];
			if(s[fw]+s[en]<=m)	fw++;
			else 	en--;
			if(fw>en)	break;
		}
		cout<<ans<<endl;
	}
}

Measured memory_bytes: 9196
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <map>
#include <unordered_map>
#include <set>
#include <queue>
using namespace std;
#define ALL(x) (x).begin(),(x).end()
#define SZ(x) long long((x).size())
#define OUT(x) cout << (x) << endl
typedef long long ll;
typedef vector<ll> V;
typedef vector<vector<ll>> VV;
typedef pair<ll, ll> P;
typedef map<string, ll> M;
typedef unordered_map<ll, ll> HM;
typedef set<ll> S;
typedef multiset<ll> MS;
typedef queue<ll> Q;

int main(){
    ll n; cin>>n;
    ll a[n];
    for(ll i=0; i<n; i++)
        cin>>a[i];
    ll m = 0;
    ll b[n];
    for(ll i=n-1; i>=0; i--){
        if((i+1)*2 > n)
            b[i] = a[i];
        else{
            ll cnt = 0;
            for(ll j=(i+1)*2-1; j<n; j=(j+1)+(i+1)-1){
                if(b[j]) cnt++;
            }
            b[i] = (a[i] != (ll)cnt%2);
        }
    }
    for(ll i=0; i<n; i++)
        if(b[i]) m++;
    OUT(m);
    for(ll i=0; i<n; i++)
        if(b[i]) cout << i+1 <<" ";
    cout << endl;
}

Measured memory_bytes: 3968
n = gets.to_i
a = gets.split(" ").map(&:to_i)

count = 0
flg = 0
while flg == 0 do
    n.times do |i|
        flg = 1 if a[i].odd?
        a[i] = a[i]/2
    end
    count = count + 1 if flg == 0
end

puts count

Measured memory_bytes: 1788
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<utility>
#include<map>
#include<set>
#include<queue>
#include<math.h>
#include<stdio.h>
using namespace std;
#define mod (1000000000+7)
#define N (10007)
#define INF 1e16
typedef long long ll;
typedef pair<ll,ll> P;
int h,w;
int board[100][100];

bool check(int i, int j) {
	return (i >= 0) && (i < h) && (j >= 0) && (j < w) && (board[i][j] == 1);
}

void dfs(int i,int j){
	for(int dx=i-1;dx<=i+1;dx++){
		for(int dy=j-1;dy<=j+1;dy++){
			if(check(dx,dy)){
				board[dx][dy]=0;
				dfs(dx,dy);
			}
		}
	}
}

int main(void){
	while(true){
		cin>>w>>h;
		if(w==0&&h==0)break;
		for(int i=0;i<h;i++){
			for(int j=0;j<w;j++){
				cin>>board[i][j];
			}
		}
		int ans=0;
		for(int i=0;i<h;i++){
			for(int j=0;j<w;j++){
				if(board[i][j]){
					dfs(i,j);
					ans++;
				}
			}
		}
		cout<<ans<<endl;
	}
    return 0;
}


Measured memory_bytes: 3316
#[allow(unused_imports)]
use itertools::Itertools;
#[allow(unused_imports)]
use itertools_num::ItertoolsNum;
#[allow(unused_imports)]
use std::cmp;
use std::collections::BTreeMap;
#[allow(unused_imports)]
use std::iter;
#[allow(unused_imports)]
use superslice::*;

fn run() {
    let (r, w) = (std::io::stdin(), std::io::stdout());
    let mut sc = IO::new(r.lock(), w.lock());

    let n: usize = sc.read();
    let s = sc.read_vec::<String>(n);

    let mut bmap = BTreeMap::new();
    for s in s.into_iter() {
        bmap.entry(s).and_modify(|x| *x += 1).or_insert(1);
    }
    for s in ["AC", "WA", "TLE", "RE"].into_iter() {
        if let Some(ans) = bmap.get(&s.to_string()) {
            println!("{} x {}", s, ans);
        } else {
            println!("{} x {}", s, 0);
        }
    }
}

fn main() {
    std::thread::Builder::new()
        .name("run".into())
        .stack_size(256 * 1024 * 1024)
        .spawn(run)
        .unwrap()
        .join()
        .unwrap();
}

pub struct IO<R, W: std::io::Write>(R, std::io::BufWriter<W>);

impl<R: std::io::Read, W: std::io::Write> IO<R, W> {
    pub fn new(r: R, w: W) -> IO<R, W> {
        IO(r, std::io::BufWriter::new(w))
    }
    pub fn write<S: std::ops::Deref<Target = str>>(&mut self, s: S) {
        use std::io::Write;
        self.1.write(s.as_bytes()).unwrap();
    }
    pub fn read<T: std::str::FromStr>(&mut self) -> T {
        use std::io::Read;
        let buf = self
            .0
            .by_ref()
            .bytes()
            .map(|b| b.unwrap())
            .skip_while(|&b| b == b' ' || b == b'\n' || b == b'\r' || b == b'\t')
            .take_while(|&b| b != b' ' && b != b'\n' && b != b'\r' && b != b'\t')
            .collect::<Vec<_>>();
        unsafe { std::str::from_utf8_unchecked(&buf) }
            .parse()
            .ok()
            .expect("Parse error.")
    }
    pub fn read_vec<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read()).collect()
    }
    pub fn read_pairs<T: std::str::FromStr>(&mut self, n: usize) -> Vec<(T, T)> {
        (0..n).map(|_| (self.read(), self.read())).collect()
    }
    pub fn read_pairs_1_indexed(&mut self, n: usize) -> Vec<(usize, usize)> {
        (0..n)
            .map(|_| (self.read::<usize>() - 1, self.read::<usize>() - 1))
            .collect()
    }
    pub fn read_chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
    pub fn read_char_grid(&mut self, n: usize) -> Vec<Vec<char>> {
        (0..n).map(|_| self.read_chars()).collect()
    }
    pub fn read_matrix<T: std::str::FromStr>(&mut self, n: usize, m: usize) -> Vec<Vec<T>> {
        (0..n)
            .map(|_| (0..m).map(|_| self.read()).collect())
            .collect()
    }
}


Measured memory_bytes: 6372