akhauriyash/Code-Regression huggingface dataset:
/*
author: Hayato Kawakita
date: 2020/05/18 17:40
vertict: AC
URL:http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=2182&lang=jp
所要時間：10分
左から見て行けば解ける。（類題を解いたことがあるので、そちらもあとで紹介として、載せます。
*/

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repr(i, n) for (int i = (n); i >= 0; --i)
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define FORR(i, m, n) for (int i = (m); i >= (n); --i)
#define equals(a, b) (fabs((a) - (b)) < EPS)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
const ll mod = 1000000007;
//const ll mod = 998244353;
const int inf = 1e9 + 10;
const ll INF = 1e18;
const ld EPS = 1e-10;
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }

string a, b, c;

void solve() {
  reverse(a.begin(), a.end());
  reverse(b.begin(), b.end());
  reverse(c.begin(), c.end());
  int n = a.length();

  vector<vector<ll>> dp(n + 1, vector<ll>(2, 0));
  dp[0][0] = 1;
  rep(i, n) {
    int xx = (a[i] == '?' ? -1 : a[i] - '0');
    int yy = (b[i] == '?' ? -1 : b[i] - '0');
    int zz = (c[i] == '?' ? -1 : c[i] - '0');
    rep(x, 10) {
      if (xx != -1 && xx != x) continue;
      if (i == n - 1 && x == 0) continue;
      rep(y, 10) {
        if (yy != -1 && yy != y) continue;
        if (i == n - 1 && y == 0) continue;
        rep(z, 10) {
          if (zz != -1 && zz != z) continue;
          if (i == n - 1 && z == 0) continue;
          rep(j, 2) {
            if (x + y + j == z) dp[i + 1][0] = (dp[i + 1][0] + dp[i][j]) % mod;
            if (x + y + j == z + 10) dp[i + 1][1] = (dp[i + 1][1] + dp[i][j]) % mod;
          }
        }
      }
    }
  }
  cout << dp[n][0] << '\n';
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout << fixed << setprecision(25);

  while (1) {
    cin >> a;
    if (a == "0") return 0;
    cin >> b >> c;

    solve();
  }




  
  return 0;
}


Measured memory_bytes: 3028
#define _CRT_SECURE_NO_WARNINGS

#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <set>
#include <map>
#include <vector>
#include <math.h>
#include <cmath>
#include <queue>
#include <stack>
#include <list>
#include <functional>
#include <numeric>
#include <iostream>
#include <string>
#include <time.h>

using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()
ll GCD(ll a, ll b) { return b ? GCD(b, a % b) : a; }

int N, M, u[312345], v[312345], S, T;
vector<vector<int>> edge;

int main() {

	scanf("%d%d", &N, &M);
	edge.resize(3 * N + 1);
	rep(i, M) {
		scanf("%d%d", &u[i], &v[i]);
		edge[u[i]].push_back(v[i] + N);
		edge[u[i] + N].push_back(v[i] + N + N);
		edge[u[i] + N + N].push_back(v[i]);
	}
	scanf("%d%d", &S, &T);


	priority_queue<pair<int, int>> pq;
	int cost[312345] = {};
	pq.push({ -1, S });
	while (!pq.empty()) {
		auto cur = pq.top();
		pq.pop();
		if (cur.second == T) {
			printf("%d\n", (-cur.first - 1) / 3);
			return 0;
		}
		for (auto e : edge[cur.second]) {
			if (!cost[e]) {
				cost[e] = cur.first;
				pq.push({ cur.first - 1, e });
			}
		}
	}

	printf("-1\n");

	return 0;
}


Measured memory_bytes: 18688
N,M = map(int,input().split())
src = [tuple(map(int,input().split())) for i in range(M)]

cities = [[] for i in range(N+1)]
for i,(p,y) in enumerate(src):
    cities[p].append((y,i))

anss = [None]*M
for p in range(N+1):
    for i,(y,_) in enumerate(sorted(cities[p])):
        ans = str(p).zfill(6) + str(i+1).zfill(6)
        anss[_] = ans

print(*anss, sep=('\n'))

Measured memory_bytes: 47848
#include<stdio.h>
int main(void)
{
  int atk,count=0,hp;
  
  scanf("%d%d",&hp,&atk);
  for(;;){
    hp=hp-atk;
    count++;
    if(hp<=0){
      break;
    }
  }
  printf("%d",count);
  return 0;
}
    


Measured memory_bytes: 128
#include<stdio.h>

int main(){
  int A,B,C,D;
  scanf("%d %d %d %d",&A,&B,&C,&D);
  if((A+B)==(C+D))puts("Balanced");
  else if((A+B)>(C+D))puts("Left");
  else puts("Right");
  return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <vector>
#include <iomanip>
#define ALL(x) (x).begin(), (x).end()
#define rt return
#define dll(x) scanf("%I64d",&x)
#define xll(x) printf("%I64d\n",x)
#define sz(a) int(a.size())
#define all(a) a.begin(), a.end()
#define rep(i,x,n) for(int i=x;i<n;i++)
#define repd(i,x,n) for(int i=x;i<=n;i++)
#define pii pair<int,int>
#define pll pair<long long ,long long>
#define gbtb ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define MS0(X) memset((X), 0, sizeof((X)))
#define MSC0(X) memset((X), '\0', sizeof((X)))
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define eps 1e-6
#define gg(x) getInt(&x)
#define db(x) cout<<"== [ "<<x<<" ] =="<<endl;
using namespace std;
typedef long long ll;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
ll powmod(ll a,ll b,ll MOD){ll ans=1;while(b){if(b%2)ans=ans*a%MOD;a=a*a%MOD;b/=2;}return ans;}
inline void getInt(int* p);
const int maxn=1000010;
// const int inf=0x3f3f3f3f;
/*** TEMPLATE CODE * * STARTS HERE ***/
int n;
char op[maxn];
int a[maxn];
ll dp[maxn/10][4];
const ll inf=(ll)(1e18);

int main()
{
    //freopen("D:\\common_text\\code_stream\\in.txt","r",stdin);
    //freopen("D:\\common_text\\code_stream\\out.txt","w",stdout);
    gbtb;
    cin>>n;
    cin>>a[1];
    repd(i,2,n)
    {
        cin>>op[i]>>a[i];
    }
    dp[1][0]=a[1];
    dp[1][1]=dp[1][2]=-inf;
    repd(i,2,n)
    {
        if(op[i]=='+')
        {
            dp[i][0]=max(dp[i-1][0],dp[i-1][1])+a[i];
            dp[i][1]=dp[i-1][1]-a[i];
            dp[i][2]=dp[i-1][2]+a[i];
        }else
        {
            dp[i][0]=-inf;
            dp[i][1]=max(dp[i-1][0],dp[i-1][1])-a[i];
            dp[i][2]=max(dp[i-1][2],dp[i-1][1])+a[i];
        }
    }
    cout<<max(dp[n][0],max(dp[n][1],dp[n][2]))<<endl;
    
    
    return 0;
}

inline void getInt(int* p) {
    char ch;
    do {
        ch = getchar();
    } while (ch == ' ' || ch == '\n');
    if (ch == '-') {
        *p = -(getchar() - '0');
        while ((ch = getchar()) >= '0' && ch <= '9') {
            *p = *p * 10 - ch + '0';
        }
    }
    else {
        *p = ch - '0';
        while ((ch = getchar()) >= '0' && ch <= '9') {
            *p = *p * 10 + ch - '0';
        }
    }
}



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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
using llint = long long;
using vint = vector<int>;

int main () {
    int n; cin >> n;
    vint x(n), y(n);
    rep(i, n) cin >> x[i] >> y[i];

    double ans = 0;

    for (int i = 0; i < n ; i++) {
        for (int j = i + 1; j < n; j++) {
            ans += sqrt(pow(x[i] - x[j], 2) + pow(y[i] - y[j], 2));
        }
    }
    ans = ans * 2 / n;

    printf("%.10f\n", ans);
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;

const ll INF64 = 1LL << 60;
const int INF32 = 1 << 29;
const ll MOD = 1000000007;


int main(){
	int n;string s; 
       cin>>n >>s;
	int m=0, M=0;
	int tmp=0;
    for(int i = 0; i < n; ++i){
    	if(s[i]=='('){++tmp;}
        else if(tmp>0){--tmp;}
        else{++m;}
    }
    string ans;
    for(int i = 0; i < m; ++i){
    	ans+='(';
    }
    ans+=s;
    for(int i = 0; i < tmp; ++i){
    	ans+=')';
    }
    cout << ans << endl;
    return 0;
}

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

int main() {
	string s;
	cin >> s;
	int ans;
	if (s == "SUN") ans=7;
	if (s == "MON") ans=6;
	if (s == "TUE") ans=5;
	if (s == "WED") ans=4;
	if (s == "THU") ans=3;
	if (s == "FRI") ans=2;
	if (s == "SAT") ans=1;
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
//https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8 より
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};
    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };
    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };
    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };
    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };
    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

// ここまで

use std::io::Write;

fn run() {
    let out = std::io::stdout();
    let mut out = std::io::BufWriter::new(out.lock());
    input! {
        s: chars,
    }
    let n = s.len();
    let mut ans = vec![0; n];
    let mut i = 0;
    while i < n {
        let mut j = i;
        while s[j] == 'R' {
            j += 1;
        }
        let mut k = j;
        while k < n && s[k] == 'L' {
            k += 1;
        }
        let mut x = j - 1;
        while i <= x && x < k {
            ans[j - 1] += 1;
            x -= 2;
        }
        let mut x = j + 1;
        while i <= x && x < k {
            ans[j - 1] += 1;
            x += 2;
        }
        let mut x = j;
        while i <= x && x < k {
            ans[j] += 1;
            x -= 2;
        }
        let mut x = j + 2;
        while i <= x && x < k {
            ans[j] += 1;
            x += 2;
        }
        i = k;
    }
    for i in 0..n {
        if i > 0 {
            write!(out, " ").unwrap();
        }
        write!(out, "{}", ans[i]).unwrap();
    }
    writeln!(out, "").unwrap();
}

fn main() {
    run();
}


Measured memory_bytes: 4476
#include <bits/stdc++.h>
#define fi first
#define se second
#define pii pair<int,int>
#define mp make_pair
#define pb push_back
#define space putchar(' ')
#define enter putchar('\n')
#define eps 1e-10
#define MAXN 200005
//#define ivorysi
using namespace std;
typedef long long int64;
typedef unsigned int u32;
typedef double db;
template<class T>
void read(T &res) {
    res = 0;T f = 1;char c = getchar();
    while(c < '0' || c > '9') {
    	if(c == '-') f = -1;
    	c = getchar();
    }
    while(c >= '0' && c <= '9') {
    	res = res * 10 +c - '0';
    	c = getchar();
    }
    res *= f;
}
template<class T>
void out(T x) {
    if(x < 0) {x = -x;putchar('-');}
    if(x >= 10) {
    	out(x / 10);
    }
    putchar('0' + x % 10);
}
const int MOD = 1000000007;
int fac[MAXN],invfac[MAXN],N,X,Y;
int vp[MAXN],fa[MAXN],id[MAXN];
pii c[MAXN];
int inc(int a,int b) {
    return a + b >= MOD ? a + b - MOD : a + b;
}
int mul(int a,int b) {
    return 1LL * a * b % MOD;
}
void update(int &x,int y) {
    x = inc(x,y);
}
int fpow(int x,int c) {
    int res = 1,t = x;
    while(c) {
        if(c & 1) res = mul(res,t);
        t = mul(t,t);
        c >>= 1;
    }
    return res;
}
int getfa(int x) {
    return fa[x] == x ? x : fa[x] = getfa(fa[x]);
}
void Solve() {
    read(N);read(X);read(Y);
    for(int i = 1 ; i <= N ; ++i) {
        read(c[i].se);read(c[i].fi);
    }
    sort(c + 1,c + N + 1);
    int sec = 2;
    while(sec <= N && c[sec].se == c[1].se) ++sec;
    if(sec > N) {puts("1");return;}
    for(int i = N ; i >= 1 ; --i) {
        vp[c[i].se] = i;
        fa[i] = i;
    }
    for(int i = N ; i >= 1 ; --i) {
        if(i != vp[c[i].se] && c[i].fi + c[vp[c[i].se]].fi <= X) {
            fa[getfa(i)] = getfa(vp[c[i].se]);
        }
        else if(c[i].se != c[1].se && c[i].fi + c[1].fi <= Y) {
            fa[getfa(i)] = getfa(1);
        }
        else if(c[i].se != c[sec].se && c[i].fi + c[sec].fi <= Y) {
            fa[getfa(i)] = getfa(sec);
        }
    }
    fac[0] = 1;
    for(int i = 1 ; i <= N ; ++i) fac[i] = mul(fac[i - 1],i);
    invfac[N] = fpow(fac[N],MOD - 2);
    for(int i = N - 1 ; i >= 0 ; --i) invfac[i] = mul(invfac[i + 1],i + 1);
    int siz = 0;
    for(int i = 1 ; i <= N ; ++i) {
        if(getfa(i) == getfa(1)) {
            id[c[i].se]++;
            ++siz;
        }
    }
    int ans = fac[siz];
    for(int i = 1 ; i <= N; ++i) {
        ans = mul(ans,invfac[id[i]]);
    }
    out(ans);enter;
}
int main() {
#ifdef ivorysi
    freopen("f1.in","r",stdin);
#endif
    Solve();
}


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

using namespace std;

int main()
{
  int i;
  int j;
  int n;
  int card [4][13]={0};
  char mark;
  int num;
  
  cin >> n;
  for(i=0;i<n;i++)
  {
    cin >> mark >> num;
    if(mark=='S')
      card[0][num-1]=1;
    if(mark=='H')
      card[1][num-1]=1;
    if(mark=='C')
      card[2][num-1]=1;
    if(mark=='D')
      card[3][num-1]=1;
  }
  for(i=0;i<4;i++)
  {
    for(j=0;j<13;j++)
    {
    if(card[i][j]==0)
      {
      if(i==0)
        cout << "S " << j+1 <<"\n";
      if(i==1)
        cout << "H " << j+1 <<"\n";
      if(i==2)
        cout << "C " << j+1 <<"\n";
      if(i==3)
        cout << "D " << j+1 <<"\n";
      }
    }
  }
}

Measured memory_bytes: 1160
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cassert>
#include <iostream>
#include <sstream>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <utility>
#include <numeric>
#include <algorithm>
#include <bitset>
#include <complex>
#include <array>
#include <list>
#include <stack>
#include <valarray>

using namespace std;

typedef unsigned uint;
typedef long long Int;
typedef unsigned long long UInt;

const int INF = 1001001001;
const Int INFLL = 1001001001001001001LL;

template<typename T> void pv(T a, T b) { for (T i = a; i != b; ++i) cout << *i << " "; cout << endl; }
template<typename T> void chmin(T& a, T b) { if (a > b) a = b; }
template<typename T> void chmax(T& a, T b) { if (a < b) a = b; }
int in() { int x; scanf("%d", &x); return x; }
double fin() { double x; scanf("%lf", &x); return x; }
Int lin() { Int x; scanf("%lld", &x); return x; }

char S[100050];

int main() {
  int N, A, B;
  N = in();
  A = in();
  B = in();
  scanf("%s", S);

  int passed = 0, passed_b = 0;
  for (int i = 0; i < N; ++i) {
    bool p = false;
    if (S[i] == 'a') {
      if (passed < A + B) {
        p = true;
        ++passed;
      }
    } else if (S[i] == 'b') {
      if (passed < A + B && passed_b < B) {
        p = true;
        ++passed;
        ++passed_b;
      }
    }
    puts(p ? "Yes" : "No");
  }

  return 0;
}


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

#define deb(x) cerr<<"["#x<<" : "<<x<<" ]\n";

int main()
{
	bool ok = true;
	string s;
	cin >> s;
	int n = s.length();
	
	int c = 0;
	for(int i = 0; i < n; i++) {
		if(i == 0 and s[i] != 'A') {
			ok = false;
			break;
		}
		
		if(s[i] == 'C') {
			c++;
			if(c > 1 or i < 2 or i > n-2) {
				ok = false;
				break;
			}
		}
		
		if(s[i] < 'a') {
			if(s[i] != 'A' and s[i] != 'C') {
				ok = false;
				break;
			}
		}
	}
	
	if(c == 0) ok = false;
	
	puts(ok ? "AC" : "WA");
}


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

int main(){
    int N,W;
    cin>>N>>W;
    long long w[101],v[101];
    for(int i=1;i<=N;++i){
        cin>>w[i]>>v[i];
    }
    vector<vector<long long>> dp(101,vector<long long>(100001,0));
    for(int i=1;i<=N;++i){
        for(int j=1;j<=W;++j){
            dp[i][j]=dp[i-1][j];
            if(j>=w[i])dp[i][j]=max(dp[i][j],dp[i-1][j-w[i]]+v[i]);
        }
    }
    cout<<dp[N][W]<<endl;
}


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

#define INF (1LL << 31 - 1)
#define MOD int(1e9+7)
#define repi(i,j,n) for(int i = (j); i < (n); ++i)
#define rep(i,n) repi(i,0,n)
#define fi first
#define se second

inline void init() {
    cin.tie(0);
    ios::sync_with_stdio(false);
}

string s;

int main() {
    cin >> s;
    cout << s.substr(0, s.size() - 8) << endl;
    return 0;
}

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

int main(void)
{
    int N, W;
    cin >> N >> W;
    vector<int> v(N), w(N);
    for(int i=0; i<N; i++) cin >> v[i] >> w[i];

    vector<vector<int>> V(N+1, vector<int>(W+1, 0));
    for(int i=0; i<N; i++){
        for(int j=0; j<W+1; j++){
            if(j < w[i]) V[i+1][j] = V[i][j];
            else V[i+1][j] = max(V[i][j], V[i][j - w[i]] + v[i]);
        }
    }
    
    cout << V[N][W] << endl;
    return 0;
}



Measured memory_bytes: 6848
#include <bits/stdc++.h>
	#include <cstdio>
	#include <cstring>
	#include <cmath>
	#include <cstring>
	#include <chrono>
	#include <complex>
	#define endl "\n"
	#define ll long long int
	#define vi vector<int>
	#define vll vector<ll>
	#define vvi vector < vi >
	#define pii pair<int,int>
	#define pll pair<long long, long long>
	#define mod 1000000007
	#define inf 1000000000000000001;
	#define all(c) c.begin(),c.end()
	#define mp(x,y) make_pair(x,y)
	#define mem(a,val) memset(a,val,sizeof(a))
	#define eb emplace_back
	#define f first
	#define s second
	
	using namespace std;
	int arr[100005][3];
	int n;

	int solve(int sum, int call, int step){
		if(step==n){
			if (call==1) return max(arr[n][0], arr[n][2]);
			else if (call==2) return max(arr[n][0], arr[n][1]);
			else return max(arr[n][1], arr[n][2]);
		}

		++step;
		if(call==0){
			return  sum + max(solve(arr[step][1], 1, step), solve(arr[step][2], 2, step));
		}
		if(call==1){
			
			return sum + max(solve(arr[step][0], 0, step), solve(arr[step][2], 2, step));
		}
		if(call==2){
			
			return sum + max(solve(arr[step][1], 1, step), solve(arr[step][0], 0, step));
		}
	}

	int main()
	{
		std::ios::sync_with_stdio(false);
		
		cin>>n;
		for(int i=1; i<=n; i++){
			cin>>arr[i][0]>>arr[i][1]>>arr[i][2];
		}

		//int a1 = solve(arr[1][0], 0, 1);
		//int a2 = solve(arr[1][1], 1, 1);
		//int a3 = solve(arr[1][2], 2, 1);
		//cout<<max(a1, max(a2, a3))<<endl;

		
		int dp[n+1][3];
		dp[1][0] = arr[1][0];
		dp[1][1] = arr[1][1];
		dp[1][2] = arr[1][2];
		for(int i=2; i<=n; i++){
			int A = arr[i][0] + max(dp[i-1][1], dp[i-1][2]);
			int B = arr[i][1] + max(dp[i-1][0], dp[i-1][2]);
			int C = arr[i][2] + max(dp[i-1][0], dp[i-1][1]);
			dp[i][0] = A;
			dp[i][1] = B;
			dp[i][2] = C;
		}

		cout<<max(dp[n][0], max(dp[n][1], dp[n][2]))<<endl;;
		return 0;
	}


Measured memory_bytes: 2560
#include<stdio.h>

#define max 8
#define Free -1
#define Not_Free 1

void initialize();
void printBoard();
void recursive(int);

int row[max];
int col[max];
int dpos[2 * max - 1];
int dneg[2 * max - 1];
int data[max][max];

int main(){
  int i,j,k,r,c;
  initialize();

  for(i = 0;i < max;i++){
    for(j = 0;j < max;j++){
      data[i][j] = 0;
    }
  }

  scanf("%d",&k);

  for(i = 0;i < k;i++){
    scanf("%d%d",&r,&c);
    data[r][c] = 1;
  }
  recursive(0);
  return 0;
}

void initialize(){
  int i;

  for(i = 0;i < max;i++){
    row[i] = Free;
    col[i] = Free;
  }

  for(i = 0;i < 2 * max - 1;i++){
    dpos[i] = Free;
    dneg[i] = Free;
  }
}

void printBoard(){
  int i,j;

  for(i = 0;i < max;i++){
    for(j = 0;j < max;j++){
      if(data[i][j]){
        if(row[i] != j){
          return;
        }
      }
    }
  }

  for(i = 0;i < max;i++){
    for(j = 0;j < max;j++){
      if(row[i] == j){
        printf("Q");
      }
      else{
        printf(".");
      }
    }
      printf("\n");
  }
}

void recursive(int i){
  int j;

  if(i == max){
    printBoard();
    return;
  }

  for(j = 0;j < max;j++){
    if(Not_Free == col[j] || Not_Free == dpos[i + j] || Not_Free == dneg[i - j + max - 1]){
      continue;
    }
    row[i] = j;
    col[j] = dpos[i + j] = dneg[i - j + max - 1] = Not_Free;
    recursive(i + 1);
    row[i] = col[j] = dpos[i + j] = dneg[i - j + max - 1] = Free;
  }
}



Measured memory_bytes: 2112
#include <stdio.h>

int main(void){
    int a,b,c;
    int k;
    int count=0;
    scanf("%d %d %d",&a,&b,&c);
    scanf("%d",&k);

    //check

    for(int i=0;;i++){
        if(a>=b){b=b*2;}
        else {break;}
        count++;
    }

    for(int i=0;;i++){
        if(b>=c){c=c*2;}
        else {break;}
        count++;
    }
    if(count>k){printf("No");return 0;}
    printf("Yes");
}


Measured memory_bytes: 1688
from collections import deque
from itertools import chain
ads = [(0, 1), (1, 0), (0, -1), (-1, 0)]

h, w = map(int, input().split(" "))
s = [list(input()) for _ in range(h)]

def find_shortest(m):
	q = deque([(0, 0)])
	i = 0
	while q:
		for j in range(len(q)):
			this_x, this_y = q.popleft()
			# this_square = m[this_y][this_x]
			if (this_x, this_y) == (w-1, h-1):
				return i
			m[this_y][this_x] = i

			for ad_x, ad_y in ads:
				x, y = this_x+ad_x, this_y+ad_y
				if not (0 <= x < w and 0 <= y < h):
					continue
				
				square = m[y][x]
				if square == "#" or type(square) == int:
					continue
					
				q.append((x, y))
				m[y][x] = "#"
		i += 1
	return None


white_num = "".join(chain(*s)).count(".")
shortest_lenght = find_shortest(s)
if shortest_lenght:
	print(white_num - 1 - shortest_lenght)
else:
	print(-1)
# しろます - 1 - 最短ルートの長さ

Measured memory_bytes: 3444
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#define MAXN 30
char buf[MAXN];
int n, vis[26];
int main() {
    scanf("%s", buf + 1), n = strlen(buf + 1);
    if (n < 26) {
        for (int i = 1; i <= n; i++) vis[buf[i] - 'a'] = 1;
        printf("%s", buf + 1);
        for (int i = 0; i < 26; i++)
            if (!vis[i]) {
                printf("%c\n", 'a' + i);
                break;
            }
    } else {
        int fir = n;
        for (int i = n - 1; i; i--)
            if (buf[i] > buf[i + 1])
                fir = i;
            else
                break;
        if (fir == 1) return puts("-1"), 0;
        for (int i = 1; i < fir - 1; i++) putchar(buf[i]);
        char min = 'z';
        for (int i = fir; i <= n; i++)
            if (buf[i] > buf[fir - 1] && buf[i] < min) min = buf[i];
        putchar(min);
        putchar(10);
    }
    return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
typedef  long long ll;
using vll=vector<ll>;
using vvll=vector<vll>;
using vi=vector<int>;
using vvi=vector<vector<int>>;
using vb=vector<bool>;
using pii=pair<int,int>;
using vpii=vector<pair<int,int>>;

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

//pow(llpow,modpow)
template<class T> ll llpow(ll x,T n){ll ans=1;if(x==0)ans=0;while(n){if(n&1)ans*=x;x*=x;n>>=1;}return ans;}
long long modpow(long long a, long long n, long long mod) {long long res = 1;while (n > 0) {if (n & 1) res = res * a % mod;a = a * a % mod;n >>= 1;}return res;}
//最大公約数
template<class T> inline T gcd(T x,T y){if(y==0)return x; else {return gcd(y,x%y);}}
//最小公倍数
template<class T> inline T lcm(T x,T y){return x/gcd(x,y)*y;}
//逆元
long long modinv(long long a, long long m) {long long b = m, u = 1, v = 0;while (b) {long long t = a / b;a -= t * b; swap(a, b);u -= t * v; swap(u, v);}u %= m;if (u < 0) u += m;return u;}

#define rep(i, begin_i, end_i) for (ll i = (ll)begin_i; i < (ll)end_i; i++)
//試験導入
#define irep(i, end_i, begin_i) for (ll i = (ll)begin_i-1; i >= (ll)end_i; i--)

long long INF = 1LL<<60;
int main( ){
    ll n,k;
    cin>>n>>k;
    ll mod=1e9+7;
    vll cnt(k+1,0);
    ll ans=0;
    irep(i,1,k+1){
        ll cpy=k;
        cnt[i]=modpow(k/i,n,mod);
        cpy/=i;
        rep(minus,2,cpy+1){
            cnt[i]-=cnt[minus*i];
            cnt[i]%=mod;
            if(cnt[i]<0)cnt[i]+=mod;
        }
        ll add=cnt[i]*i%mod;
        if(add<0)add+=mod;
        ans+=add;
        ans%=mod;
        if(ans<0)ans+=mod;
    }
    cout<<ans<<endl;
    return 0;
}




Measured memory_bytes: 4040
#include <iostream>
#include <algorithm>
#include <cassert>
#include <cctype>
#include <complex>
#include <cstdio>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;

int n,m;
pair<int,int> f[10000];
set<int> g,g2;

int main(){
	while(cin>>n>>m){
		if(!n)return 0;
		g.clear();g2.clear();
		for(int i=0;i<m;i++){
			cin>>f[i].first>>f[i].second;
			if(f[i].first==1)g.insert(f[i].second);
		}
		set<int>::iterator ite;
		for(ite=g.begin();ite!=g.end();ite++)g2.insert(*ite);
		for(ite=g2.begin();ite!=g2.end();ite++){
			for(int i=0;i<m;i++){
				if(f[i].first==*ite)g.insert(f[i].second);
				if(f[i].second==*ite)g.insert(f[i].first);
			}
		}
		g.erase(1);
		cout<<g.size()<<endl;
	}
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
#include <iostream>	
#define pb push_back
#define mp make_pair
#define Red ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define F first
#define S second
#define sz(x) (int)x.size()
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for(int i = 0; i < n; ++i)
#define repr(i,n) for(int i = n - 1; i >= 0; --i)
#define Rep(i, a, n) for(int i = (a); i <=(n); ++i)
#define repst(i, n) for(auto it = n.begin(); it != n.end(); ++it)
#define Repr(i, a, n) for(int i = (n); i >= (a); --i)
typedef long long ll;

const int inf = int(1e9);
const int mod = inf + 7;
using namespace std;
const int N = 10;
void solve()
{
	int n;
	cin >> n;
	int a[n];
	if(n == 1)
	set<int> st;
	for(int i = 0; i < n; ++i){
		cin >> a[i];
	}
	int pref[n], suff[n];
	pref[0] = a[0];
	suff[n - 1] = a[n - 1];
	for(int i = 1; i < n; ++i){
		pref[i] = __gcd(pref[i - 1], a[i]);
	}
	for(int i = n - 2; i >= 0; --i){
		suff[i] = __gcd(suff[i + 1], a[i]); 
	}
	int mx = 0;
	for(int i = 0; i < n; ++i){
		int cur = 0;
		if(i - 1 >= 0) cur = __gcd(cur, pref[i - 1]);
		if(i + 1 < n) cur = __gcd(cur, suff[i + 1]);

		mx = max(mx, cur); 
	}
	cout << mx;
}


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

Measured memory_bytes: 1408
// inputに入力データ全体が入る
function Main(input) {
    input = input.split("\n");
    var a = new Array(3)
    var b = new Array(3)
    var list = new Array(5)
    list[1] = list[2] = list[3] = list[4] = 0
    list[input[0].split(' ')[0]]++
    list[input[0].split(' ')[1]]++;
    list[input[1].split(' ')[0]]++;
    list[input[1].split(' ')[1]]++;
    list[input[2].split(' ')[0]]++;
    list[input[2].split(' ')[1]]++;
    var flg = list.filter(v => v === 1).length === 2 && list.filter(v => v === 2).length === 2
    console.log(flg ? 'YES' : 'NO')
}
//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 21064
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define For(i,n,k) for(ll i=(n);i<(k);i++)
#define ALL(a)  (a).begin(),(a).end()
const ll MOD = 1000000007;
ll ans=1;
void Main(){
    ll n,k;
    cin>>n>>k;
    vector<ll> a(n);
    ll cntm=0;
    For(i,0,n){
        cin>>a[i];
    }
    sort(ALL(a));
    if(k%2){
        ans = a[n-1];
        a.pop_back();
        k--;
        n--;
    }
    if(n==k){
        ans = (ans + MOD) % MOD;
        For(i,0,k){
            ans = (ans * ((a[i]+ MOD) % MOD)) % MOD;
        }
        cout << ans << endl;
        return;
    }
    else if(ans<0){
        ans = (ans + MOD) % MOD;
        reverse(ALL(a));
        For(i,0,k){
            ans = (ans * ((a[i]+ MOD) % MOD)) % MOD;
        }
        cout << ans << endl;
        return;
    }
    vector<ll> b(k,0);
    for(int i=0;i<n;i+=2){
        if(a[i+1]>0) break;
        b.push_back(a[i] * a[i+1]);
    }
    for(int i=n-2;i>-1;i-=2){
        if(a[i]<0) break;
        b.push_back(a[i] * a[i+1]);
    }
    sort(ALL(b));
    reverse(ALL(b));
    For(i,0,k/2){
        ans *= b[i] % MOD;
        ans = (ans + MOD) % MOD;
    }
    cout << ans << endl;
}
int main(){
    Main();
    /*
    東方風神録は神が出てくるので当然神ゲー
    */
    return 0;
}

Measured memory_bytes: 9388
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
#include <fstream>
#include <utility>
#include <functional>
#include <time.h>
#include <stack>
#include <array>
#include <list>

using namespace std;

typedef long long ll;
typedef long double ld;

#define vi vector<int>
#define vl vector<ll>
#define vii vector< vector<int> >
#define vll vector< vector<ll> >
#define vs vector<string>
#define pii pair<int,int>
#define pis pair<int,string>
#define psi pair<string,int>
#define pll pair<ll,ll>
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define rep1(i,n) for(int i=1; i<=(int)(n); i++)
#define all(c) c.begin(),c.end()
#define psb push_back
#define ppb pop_back

const int I_INF = 1001001001;
const ll LL_INF = 1001001001001001001;
const ld EPS = 0.001;

int main() {
    ll a,b,c;
    cin >> a >> b >> c;

    ll l = 4*a*b;
    ll r = (c-a-b)*(c-a-b);
    if (l<r && (c-a-b)>0) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
    int d, g; cin >> d >> g;
    int p[10], c[10], a[1025];
    int ans = 1 << 30;
    for (int i = 0; i < d; i++) cin >> p[i] >> c[i];
    for (int b = 0; b < (1<<d); b++) {
        int n = 0, r = g;
        for (int i = 0; i < d; i++)
            if ((b >> i) & 1) { n += p[i]; r -= (i+1)*100*p[i] + c[i]; }
        if (r <= 0) ans = min(ans, n);
        else {
            for (int i = d-1; i >= 0; i--) {
                if ((b >> i) & 1) continue;
                if (r <= (i+1)*100*(p[i]-1))
                    ans = min(ans, n + 1 + (r-1) / ((i+1)*100));
                break;
            }
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
x1,y1,x2,y2=map(int,input().split())

dx = x2 - x1
dy = y2 - y1

x3 = x2 - dy
y3 = y2 + dx

x4 = x3 - dx
y4 = y3 - dy

print(' '.join(list(map(str, [x3,y3,x4,y4]))))

Measured memory_bytes: 61712
/*
我的心脏怦怦跳，监管者就在附近
name:
Algorithm:
writer:Lxs(cdx)
place:
nothing is impossible
*/
#pragma GCC optimize(3,"Ofast","inline")
#include<bits/stdc++.h>
#include<string>
#include<iostream>
#include<cmath>
#include<set>
#include<stack>
#include<queue>
#include<unistd.h>
#include<stdio.h>
#include<cstring>
#define random(a,b) (rand()%(b-a+1)+a)
using namespace std;
bool prime(int x){
	 int i;
	 if(x<2) return 0;
	 for(i=2;i*i<=x;i++){
		if(x%i==0){return 0;}
	 }
	 return 1;
}
int main()
{
	double a,b,h,m;
	cin>>a>>b>>h>>m;
	double anm=360*m/60,anh=360*h/12,ans;
	ans=anm-anh-anm/12;
	double weij=ans;
	double c;
	c=sqrt(a*a+b*b-2*a*b*cos(acos(-1)/180*weij));
	cout<<fixed<<setprecision(20)<<c<<endl;
	return 0;
}


Measured memory_bytes: 4148
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < (n); i++)
#define REP1(i, n) for(int i = 1; i <= (n); i++)
#define REPD(i,a,b) for (int i=(a);i<=(b);i++)
#define ALL(v) (v).begin(), (v).end()
using namespace std;
typedef long long ll;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef set<int> si;
typedef vector<si> vsi;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef pair<int, int> pi;
typedef queue<int> qi;
typedef queue<pi> qpi;
typedef pair<ll, ll> pll;
typedef queue<pll> qpll;
typedef vector<pi> vpi;
typedef vector<pll> vpll;
const int mod = 1000000007;
const int INF = 1001001001;
// 小数点　<< fixed << setprecision(0) <<
// sort降順　sort(ALL(),greater<int>());
// 円周率　M_PI
// 文字判定　isupper islower
// 文字変換　
// 順列　do {} while(next_permutation(ALL(X)));
// 最大値　LLONG_MAX
// a内でx以上　auto iter = lower_bound(ALL(a), x);
// a内でxより大きい　auto iter = upper_bound(ALL(a), x);
int dx[8] = {1, 0, -1, 0, 1, 1, -1, -1};
int dy[8] = {0, 1, 0, -1, 1, -1, 1, -1};
struct edge {
    int from; //出発点
    int to;   //到達点
    int cost; //移動コスト
};
typedef struct edge se;
typedef vector<edge> ve;
unsigned Euclidean_gcd(unsigned a, unsigned b) {
  if(a < b) return Euclidean_gcd(b, a);
  unsigned r;
  while ((r=a%b)) {
    a = b;
    b = r;
  }
  return b;
}

int digit_sum(int n) {
  int sum=n%10;
  while(n!=0) {
    n/=10;
    sum+=n%10;
  }
  return sum;
}

vpll PrimeFactorization(ll n) {
  vpll res;
  for (ll i=2; i*i<=n; i++) {
    if(n%i!=0) continue;
    ll ex=0;
    while(n%i==0) {
      ex++;
      n/=i;
    }
    res.push_back(pll(i,ex));
  }
  if(n!=1) res.push_back(pll(n,1));
  return res;
}

int main() {
  int n;
  cin >> n;
  vi check(100001,0);
  REP(i,n) {
    int l,r;
    cin >> l >> r;
    REPD(j,l,r) {
      check[j]=1;
    }
  }
  int ans=count(ALL(check),1);
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3760
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <iomanip>
#include <queue>
#include <deque>
#include <map>
#include <unordered_map>
#define rep(i,n) for(int i=0;i<n;i++)
#define repn(i,n) for(int i=1;i<=n;i++)
#define repr(e,x) for(auto& e:x)
using namespace std;
typedef long long ll;
typedef long double ld;
//typedef pair<int,int> P;
double const PI=3.141592653589793;
int const INF=1001001001;
ll const LINF=1001001001001001001;
ll const MOD=1000000007;

int N;

int main(){
    cin>>N;

    int a;
    repn(i,N){
        int x=i*(i+1)/2;
        if(x==N){
            a=i;
            break;
        }
        if(N<x){
            cout<<"No"<<endl;
            return 0;
        }
    }

    vector<vector<int>> ans(a+1,vector<int>(0));
    int val=0;
    for(int n=a;n>=1;n--){
        repn(i,n){
            val++;
            ans[a-n].push_back(val);
            ans[a-n+i].push_back(val);
        }
    }

    cout<<"Yes\n"<<a+1<<endl;
    rep(i,a+1){
        cout<<a<<' ';
        rep(j,a){
            cout<<ans[i][j]<<' ';
        }
        cout<<endl;
    }
}

Measured memory_bytes: 4424
import java.util.*;

public class Main {
    static final int MOD = 1000000007;
	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		int x = sc.nextInt();
		int y = sc.nextInt();
		int sum = x + y;
		if (sum % 3 != 0) {
		    System.out.println(0);
		    return;
		}
		x -= sum / 3;
		y -= sum / 3;
		if (x < 0 || y < 0) {
		    System.out.println(0);
		    return;
		}
		Combination cmb = new Combination(x + y + 1);
		long ans = cmb.getComb(x + y, x);
		System.out.println(ans);
   }

}

class Combination {
    static final int MOD = 1000000007;
    long[] fac;
    long[] finv;
    long[] inv;
    
    public Combination (int size) {
        fac = new long [size];
        finv = new long [size];
        inv = new long [size];
        fac[0] = 1;
        fac[1] = 1;
        finv[0] = 1;
        finv[1] = 1;
        inv[1] = 1;
        for (int i = 2; i < size; 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;
        }
    }
    
    
    public long getComb(int n, int k) {
        if (n < k || n < 0 || k < 0) {
            return 0;
        }
        return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
    }
    
}



Measured memory_bytes: 57828
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>

using namespace std;

int main() {
	int n;
	cin >> n;
	vector<int> a(n), dp(n, 999999999);
	dp[0] = 0;
	for (int i = 0; i < n; ++i) {
		cin >> a[i];
	}
	for (int i = 1; i < n; ++i) {
		dp[i] = dp[i - 1] + abs(a[i] - a[i - 1]);
		if (i - 2 >= 0) dp[i] = min(dp[i], dp[i - 2] + abs(a[i] - a[i - 2]));
	}
	cout << dp[n - 1] << endl;
	cin >> n;

}

Measured memory_bytes: 1024
import math
import os
import random
import re
import sys

def solve(a, b, t):
	x = 0
	if t < a:
		return 0
	for i in range(t//a):
		x += b
	return x

if __name__ == '__main__':
    a, b, t =  map(int, input().split())
    print(solve(a,b,t))

Measured memory_bytes: 5476
#include<bits/stdc++.h>
using namespace std;
bool prime(long long n)
{
    if(n==1){return 0;}
    int sr=sqrt(n);
    if(n==2)
    {
        return 1;
    }
    if(n%2==0)
    {

        return 0;
    }

    for(int i=3;i<=sr;i++)
    {
        if(n%i==0)
             return 0;
    }

     return 1;
}
int main()
{
    long long n;
    cin>>n;
    if(prime(n)){cout<<n<<endl;return 0;}

    while(1)
    {
        n++;
        if(prime(n)){cout<<n<<endl;break;}
      }


    return 0;
}


Measured memory_bytes: 256
n = int(input())
f = [list(map(int,input().split())) for _ in range(n)]
p = [list(map(int,input().split())) for _ in range(n)]
ans = -10**10
for i in range(1,2**10):
    tmp_prof = 0
    test = bin(i)[2:].zfill(10)
    for j in range(n):
        tmp_c = 0
        for k in range(10):
            if (f[j][k]==1) & (test[k]=='1'):
                tmp_c+=1
        tmp_prof += p[j][tmp_c]
    if ans < tmp_prof:
        ans = tmp_prof
print(ans)

Measured memory_bytes: 3064
import java.util.Scanner;

class Watch {
    static void run() {
        Scanner sc = new Scanner(System.in);
        int s = sc.nextInt();
        int m = s / 60;
        int ss = s % 60;
        int h = m / 60;
        int mm = m % 60;
        System.out.printf("%d:%d:%d%n", h, mm, ss);
    }
}
public class Main {
    public static void main(String[] args) {
        Watch.run();
    }
}

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

int n;
map<long, long> mp;

int main() {
  cin >> n;
  long sum = 0;
  ++mp[0];
  
  while (n--) {
    long a;
    cin >> a;
    sum += a;
    ++mp[sum];
  }
  
  long ans = 0;
  for (auto&& p : mp) {
    ans += p.second * (p.second - 1) / 2;
  }
  cout << ans << endl;
}

Measured memory_bytes: 12800
import java.util.*;
public class Main {
    
    static void solve(){
        Scanner sc = new Scanner(System.in);
        StringBuilder s = new StringBuilder();
        for (char ch : sc.next().toCharArray()) {
            int len = s.length();
            if(ch!='B') s.append(ch); 
            else if(len>0) s=new StringBuilder(s.toString().substring(0,len-1));
        }
        System.out.println(s);
        sc.close();
    }
    
    public static void main(String args[]) {
        solve();
    }

}   


Measured memory_bytes: 35572
import numpy as np
A, B, K = list(map(int,input().split()))

ans_takahasi = A
ans_aoki = B
if A>K:
    ans_takahasi -= K
else:
    ans_takahasi = 0
    ans_aoki -= K-A
if ans_takahasi < 0 or ans_aoki < 0:
    ans_takahasi = 0
    ans_aoki = 0
    
print(ans_takahasi,ans_aoki)

Measured memory_bytes: 21404
from collections import deque
K=int(input())
dist=[10**15 for i in range(K)]
dist[1]=1
q=deque([1])
while(len(q)>0):
    r=q.popleft()
    s=(r+1)%K
    if dist[r]+1<dist[s]:
        dist[s]=dist[r]+1
        q.append(s)
    t=(r*10)%K
    if dist[r]<dist[t]:
        dist[t]=dist[r]
        q.appendleft(t)
print(dist[0])


Measured memory_bytes: 6060
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin>>n;
  vector<int>ans;
  for(int i=1;i<=n;i++){
    int a;
    cin>>a;
    if(a>i){cout<<-1;return 0;}
    else{ans.insert(ans.begin()+a-1,a);}
  }
  for(int i=0;i<n;i++){
    cout<<ans[i]<<endl;
  }
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <fstream>
#include <numeric>
using namespace std;
typedef long long int ll;

#define EPS (1e-7)
#define INF 1e18
#define max(p,q)((p)>(q)?(p):(q))
#define min(p,q)((p)<(q)?(p):(q))
#define PI (acos(-1))

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

int main() {
    int N;
    cin >> N;
    vector<ll> a(N);
    REP(i, N) cin >> a[i];
    a.push_back(N + 100);
    ll ans = 0;
    ll tmp = 0;
    REP(i, N+1){
        if(a[i] == i + 1){
            tmp++;
        }
        else{
            if(tmp == 1){
                ans++;
            }
            else if(tmp > 1){
                ans += (tmp % 2 == 0) ? tmp / 2 : tmp / 2 + 1;
            }
            tmp = 0;
        }
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

const int MAXN = 1e5 + 5;
const int MOD = 1e9 + 7;
const int INF = 0x3f3f3f3f;
const long long int LLINF = 0x3f3f3f3f3f3f3f3f;
const double EPS = 1e-9;
#define NMAX 100005
#define LAST 1000000000002
int main()
{      
    char tab1[12],tab2[12];
    cin>>tab1>>tab2;
    int l1 = strlen(tab1);
    for(int i=0 ; i<l1 ; ++i){
        if(tab1[i]!=tab2[i]){
            cout<<"No"<<endl;
            return 0;
        }
    }
    cout<<"Yes"<<endl;
   return 0;
}


Measured memory_bytes: 3604
#include<stdio.h>

int main(void) {
	int i,j,w[10],k[10];
	for (i = 0; i < 10; i++)scanf("%d",&w[i]);
	for (i = 0; i < 10; i++)scanf("%d", &k[i]);

	for (i = 0; i < 10; i++) {
		for (j = i + 1; j < 10; j++) {
			if (w[i] < w[j]) {
				int temp = w[i];
				w[i] = w[j];
				w[j] = temp;
			}
		}
	}
		for (i = 0; i < 10; i++) {
			for (j = i + 1; j < 10; j++) {
				if (k[i] < k[j]) {
					int temp = k[i];
					k[i] = k[j];
					k[j] = temp;
				}
			}
		}
		printf("%d %d\n",w[0]+w[1]+w[2],k[0]+k[1]+k[2]);
	return 0;
}

Measured memory_bytes: 596
#include <bits/stdc++.h>
#define rep(i, a, n) for (int i = (int)(a); i <= (int)(n); ++i)
#define rrep(i, a, n) for (int i = (int)(a); i >= (int)(n); --i)
#define debug(x) cerr << #x << " = " << x << "\n"
#define debugv(x) \
  rep(f, 0, (x.size() - 1)) cerr << x[f] << (f == (x.size() - 1) ? "\n" : " ")
#define debug2(x, y)                       \
  cerr << "(" << #x << "," << #y << ") = " \
       << "(" << x << "," << y << ")\n"
#define all(x) x.begin(), x.end()
#define each(a, x) for (auto& a : (x))
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define int long long
using namespace std;
typedef pair<int, int> pii;
typedef vector<int> vi;
const int MX = 1e5 + 5, INF = 5LL << 57, MOD = 1e9 + 7;

int N, M;
string S;
vi va, vb;

void input() {
  cin >> N;
  cout << N * N << endl;
  ;
  ;
}
void solve() {
  ;
  ;
}
signed main() {
  input();
  solve();
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define MOD 1000000007
using pi = pair<int, int>;
vector<int>g[100100];
int siz[100100];

vector<int> centroid;
int n;

int main()
{
    int t = 1;
    //cin >> t;
    while(t--)
    {
       ll a, b, c, d;
       cin >> a >> b >> c >> d;
       cout << max(a*c, max(a*d, max(b*c, b*d))) << endl;
    }
}


Measured memory_bytes: 5980
#define ll long long int
#include <bits/stdc++.h>
//#include <ext/pb_ds/tree_policy.hpp>
//#include <ext/pb_ds/assoc_container.hpp>
using namespace std;

//using namespace __gnu_pbds;

#define         ff               first
#define         ss               second
#define         mp               make_pair
#define         pb               push_back
#define         pf               push_front
#define         vi               vector<ll>
#define         pii              pair<ll,ll>
#define         qi               queue<ll>
#define         mem(a,b)         memset(a,b,sizeof(a))
#define         print(a)         cout<<a<<'\n'
#define         sorted(arr)      sort(arr.begin(),arr.end())
#define         gcd(a,b)         gcd((a),(b))
#define         lcm(a,b)         ((a)*(b))/gcd((a),(b))
#define         all(v)           v.begin(),v.end()
#define         read(a)          scanf("%d", &a)
#define         f(a,n)           for(ll i=a;i<n;i++)
#define         in2(n,m,arr)     for(ll i=0;i<n;i++){for(ll j=0;j<m;j++)cin>>arr[i][j];}
#define         debug(a)         cerr<<a<<" ";
#define         debug1(a)        cerr<<a<<'\n'
 
/*typedef tree<int, null_type, less<int>, rb_tree_tag , tree_order_statistics_node_update> Set;*/
 
 
const unsigned ll mod = 1e9 + 7 ;
const ll inf = (ll)1e18 + 2;
const ll N = (ll)2e5 + 2;

ll power( ll x , ll y)
{
    ll res = 1;
    while (y > 0)
    {
        if (y & 1)
            res = (res * x) ;
        y = y >> 1;
        x = (x * x) ;
    }
    return res  ;
}

//struct node{
//    ll x , y , z;
//};
//map<pair<ll, ll>,ll> c;
//vector<set<ll>> tree;
//vector<ll> ar ;
//set<ll> s;
//ll get(ll x)
//{
//    if(x == ar[x])
//        return x;
//    return ar[x] = get(ar[x]);
//}
//void merge(ll a ,ll b)
//{
//    a = get(a);
//    b = get(b);
//    if(a == b)
//    {
//        return ;
//    }
//    ar[b] = ar[a];
// }

//ll sev[100006];
//vector<ll> pri;
//void seive()
//{
//    for(ll i = 2 ; i < 100006 ; i ++)
//    {
//        if(!sev[i])
//        {
//            for(ll j = i ; j < 100006 ; j += i)
//            {
//                if(!sev[j])
//                    sev[j] = i;
//            }
//        }
//        if(sev[i] == i)
//            pri.pb(i);
//    }
//}

void solve()
{
    string s;
    cin >> s;
    ll f = 1;
    for(ll i = 0 ; i < s.size() ; i ++)
    {
        if(i % 2 == 0)
        {
            if(s[i] != 'h')f=0;
        }
        else{
            if(s[i] != 'i')f = 0;
        }
    }
    if(!f || s[s.size() - 1] != 'i')
        cout << "No\n";
    else
        cout << "Yes\n";
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    ll t ;
    t = 1;
    //cin >> t;
    //seive();
    while(t --)
    {
        solve();
    }
    cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
    return 0;
}
 


Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <string>
#include <vector>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main() {
  int a, b;
  cin >> a >> b;
  cout << a * b << " " << 2 * (a + b) << endl;
  return 0;
}


Measured memory_bytes: 3056
#include <functional>
#include <algorithm>
#include <iostream>
#include <numeric>
#include <iomanip>
#include <utility>
#include <cstdlib>
#include <sstream>
#include <bitset>
#include <vector>
#include <cstdio>
#include <ctime>
#include <queue>
#include <deque>
#include <cmath>
#include <stack>
#include <list>
#include <map>
#include <set>

using namespace std;

typedef vector<int> vi;
typedef pair<int,int> pii;
typedef long long ll;

#define dump(x)  cerr << #x << " = " << (x) << endl
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(a)  (a).begin(),(a).end()
#define pb push_back

int main() {
    int day;
    cin>>day;
    int math,jap;
    cin>>math>>jap;
    int dom,doj;
    cin>>dom>>doj;
    
    cout<<day-max( ceil((double)math/dom),ceil((double)jap/doj) )<<endl;
    
    
    
    return 0;
}

Measured memory_bytes: 1240
H,W = map(int,input().split())
a = ["" for i in range(H)]
h = [True for i in range(H)]
w = [False for i in range(W)]

for i in range(H):
	a[i] = input()
	if a[i] == "."*W:
		h[i] = False
	for j in range(W):
		if a[i][j] == "#":
			w[j] = True

for i in range(H):
	if h[i]:
		z = ""
		for j in range(W):
			if w[j]:
				z += a[i][j]
		print(z)


Measured memory_bytes: 3064
#include <queue>
#include <iostream>
#include <map>
#include <algorithm>
#include <string>
#include <cmath>
#include <vector>
#include <iomanip>
#include <cstdio>
#define rep(i, n) for(long long i = 0;(i) < (n);(i)++)
using namespace std;
using ll = long long;
const ll mod = 1000000007;

int main()
{
	ll a, b, c;
	cin >> a >> b >> c;
	if (b * 2 == a + c)
	{
		cout << "YES" << endl;
	}
	else
	{
		cout << "NO" << endl;
	}
	return 0;
}

Measured memory_bytes: 256