akhauriyash/Code-Regression huggingface dataset:
/*input
3 3
abc


*/
#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;
typedef tree<long long, null_type, less<long long>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;
#pragma GCC optimize("unroll-loops,no-stack-protector")
//order_of_key #of elements less than x
// find_by_order kth element
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
typedef long long int ll;
#define ld long double
#define pii pair<ll,ll>
#define f first
#define s second
#define pb push_back
#define REP(i,n) for(int i=0;i<n;i++)
#define sz(_a) (ll)(_a.size())
#define FILL(n,x) memset(n,x,sizeof(n))
#define ALL(_a) _a.begin(),_a.end()
const ll maxn=100005;
const ll maxlg=__lg(maxn)+2;
const ll INF64=8000000000000000000LL;
const int INF=0x3f3f3f3f;
const ll MOD=ll(1e9+7);
const ld PI=acos(-1);
const ld eps=1e-9;

ll mypow(ll a,ll b){
    if(b<=0) return 1;
    ll res=1LL;
    while(b){
        if(b&1) res=res*a%MOD;
        a=a*a%MOD;
        b>>=1;
    }
    return res;
}
char ss[maxn];
int main() {
	int n,k,i,d=0,s=0,ans;
	cin>>n>>k>>ss;
	for(i=1;i<n;i++){
		if(ss[i-1]==ss[i]) s++;
		else d++;
	}
	if(2*k>=d) cout << s+d << endl;
	else cout << s+2*k << endl;
	return 0;
}

Measured memory_bytes: 384
#!/usr/bin/env python3
import sys
input = sys.stdin.readline

n = int(input())
a = [int(item) for item in input().split()]
left_cnt = [0] * n
right_cnt = [0] * n
for i, item in enumerate(a):
    if i - item >= 0:
        right_cnt[i - item] += 1
    if i + item < n:
        left_cnt[i + item] += 1
ans = 0
for lc, rc in zip(left_cnt, right_cnt):
    ans += lc * rc
print(ans)

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

int n;

int a[2005];
int ans;

int main(){
	int n;
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
		scanf("%d",&a[i]);
	sort(a+1,a+n+1);
	for(int i=1;i<=n;i++)
		for(int j=i+1;j<=n;j++){
			int temp=a[i]+a[j];
			int biao=lower_bound(a+1+j,a+n+1,temp)-a;

			ans+=biao-j-1;
		}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 256
a = int(input())
b = int(input())
c = int(input())

x = int(input())

count = 0

for i in range(a + 1):
    for j in range(b + 1):
        for k in range(c + 1):
            total = 500 * i + 100 * j + 50 * k
            if total == x:
                count += 1

print(count)


Measured memory_bytes: 3064
#include <iostream>
#include <string>
#include <cmath>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <list>
#include <stack>
#include <queue>
#include <numeric>

#define FOR(i, b, e) for(int i = (int)(b); i < (int)(e); ++i)
#define RFOR(i, b, e) for(int i = (int)(e-1); i >= 0; --i)
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) RFOR(i, 0, n)
#define REPC(x,c) for(const auto& x:(c))
#define VS vector<string>
#define VI vector<int>
#define VVI vector<vector<int>>
#define ALL(x) (x).begin(),(x).end()
#define PAIR pair<int,int>
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

using  ll = long long;

using namespace std;

ll gcd(ll a, ll b) {
	if (a < b) { return gcd(b, a); }
	ll r;
	while ((r = a % b)!= 0) {
		a = b;
		b = r;
	}
	return b;
}

int main() {
	ll n, x;
	cin >> n >> x;
	VI v(n);
	REP(i, n) { cin >> v[i]; }

	for (auto& t : v) {
		t = abs(t - x);
	}

	ll ans = v[0];
	for (int i = 1; i < n; ++i) {
		ans = gcd(ans, v[i]);
	}

	cout << ans << endl;
}

Measured memory_bytes: 640
#include <assert.h>
#include <limits.h>
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <complex>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>
#include <random>
 
#define rep(i, a, b) for (long long (i) = (a); i < (b); i++)
#define all(i) i.begin(), i.end()
#define debug(i) std::cerr << "debug " <<"LINE:"<<__LINE__<<"  "<< #i <<":"<< i << std::endl

 
template <typename T1, typename T2>
std::ostream& operator<<(std::ostream& os, std::pair<T1, T2> pa) {
  return os << pa.first << " " << pa.second;
}
 
template <typename T>
std::ostream& operator<<(std::ostream& os, std::vector<T> vec) {
  for (int i = 0; i < vec.size(); i++)os << vec[i] << (i + 1 == vec.size() ? "" : " ");
  return os;
}
 
template<typename T1,typename T2>
inline bool chmax(T1& a,T2 b){return a<b && (a=b,true);}
 
template<typename T1,typename T2>
inline bool chmin(T1& a,T2 b){return a>b && (a=b,true);}
 
long long pow_mod(long long a, long long b, long long mod=-1) {
  if ((a == 0)||(mod!=-1&&a%mod==0)) {
    return 0;
  }
 
  long long x = 1;
 
  while (b > 0) {
    if (b & 1) {
      x = (mod!=-1)?(x * a) % mod:x*a;
    }
    a = (mod!=-1)?(a * a) % mod:a*a;
    b >>= 1;
  }
  return x;
}
 
// const long long MOD = 998244353;
const long long MOD = 1e9 + 7;

using ll = long long;
using P = std::pair<ll, ll>;

ll gcd(ll a,ll b){
  if(a%b==0)return b;
  else return gcd(b,a%b);
}

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

  ll h,w,k;
  std::cin>>h>>w>>k;

  std::vector<std::string> s(h);
  rep(i,0,h)std::cin>>s[i];

  std::vector<std::vector<ll>> ans(h,std::vector<ll>(w,0));

  ll now=1;

  rep(i,0,h){
    bool isthere=false;
    rep(j,0,w)if(s[i][j]=='#')isthere=true;

    if(isthere){
      rep(j,0,w){
        if(s[i][j]=='#'){
          ans[i][j]=now;
          now++;
        }
      }
      for(ll j=w-2;j>=0;j--){
        if(ans[i][j]==0)ans[i][j]=ans[i][j+1];
      }
      rep(j,1,w)if(ans[i][j]==0)ans[i][j]=ans[i][j-1];
    }else if(i>0){
      ans[i]=ans[i-1];
    }
  }

  for(ll j=h-2;j>=0;j--)if(ans[j][0]==0)ans[j]=ans[j+1];

  rep(i,0,h){
    rep(j,0,w)std::cout<<ans[i][j]<<" ";
    std::cout<<"\n";
  }

  return 0;
}

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

int main(){
  int n;
  cin >> n;
  vector<long long> a(n);
  for(int i = 0; i < n; i++) cin >> a[i];
  int ans = 0;
  for(int i = 0; i < n; i++){
    while(a[i] % 2 == 0){
      a[i] /= 2;
      ans++;
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 3676
N=int(input())
H=list(map(int,input().split()))
M=1
ans="Yes"

for i in range(N):
    if M<H[i]:
        M=H[i]
    elif M==H[i]:
        pass
    elif M-1==H[i]:
        pass
    else:
        ans="No"
        break

print(ans)


Measured memory_bytes: 14396
import java.util.*

fun main(args: Array<String>) {
    val sc = Scanner(System.`in`)
    val a = sc.nextInt()
    val b = sc.nextInt()
    val c = sc.nextInt()
    println(problem047a(a, b, c))
}

fun problem047a(a: Int, b: Int, c: Int): String {
    return if (a + b == c || a + c == b || a == b + c) "Yes" else "No"
}

Measured memory_bytes: 31388
a, b, c = map(int, input().split())
n = int(input())
for i in range(0, n+1):
    for j in range(0, n-i+1):
        k = n-i-j
        if a*(2**i) < b*(2**j) < c*(2**k):
            #print(i, j, k)
            print('Yes')
            exit()
        else:
            continue
print('No')


Measured memory_bytes: 9172
fn solve() {
    let a: usize = read();
    println!("{}", a + a * a + a * a * a);
}

fn main() {
    let stack_size = 104_857_600;
    let thd = std::thread::Builder::new().stack_size(stack_size);
    thd.spawn(|| solve()).unwrap().join().unwrap();
}

// =========
#[allow(unused_imports)]
use std::cmp::{max, min, Reverse};
#[allow(unused_imports)]
use std::collections::{BinaryHeap, HashMap, HashSet};
#[allow(unused_imports)]
use std::process::exit;

#[allow(dead_code)]
const MOD: usize = 1000000007;

fn read<T: std::str::FromStr>() -> T {
    use std::io::Read;
    let stdin = std::io::stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

// =========


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

int main(){
    int n, i, j;
    cin >> n;

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

    bool arr[a[n-1]+1] = {};

    int cnt=0;
    for(i=0;i<n-1;i++){
        if(!arr[a[i]]){
            if(a[i]!=a[i+1]) cnt++;
            for(j=a[i]; j<=a[n-1]; j+=a[i]){
                arr[j] = true;
            }
        }
    }
    if(!arr[a[n-1]]) cnt++;
    cout << cnt << endl;
}

Measured memory_bytes: 5268
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <utility>
#include <cmath>
#include <cstdlib>
#include <fstream>
#include <iomanip>
#include <ctime>
#include <cstring>
#include <unordered_map>
#include <cstdio>
 
#define gc getchar_unlocked
#define N 109
 
using namespace std;
 
int sug[3009],wat[3009];
 
int main(){	
	int i,j,t1,t2,t3,t4,a,b,c,d,e,f,a1,a2;
	double perc=0,temp;
	scanf("%d %d %d %d %d %d",&a,&b,&c,&d,&e,&f);
	sug[0]=wat[0]=1;
	a1=1; a2=0;
 
	for(i=1;i<=3000;i++){
		if(i-c>=0){
			sug[i]|=sug[i-c];
		}
		if(i-d>=0){
			sug[i]|=sug[i-d];
		}
		if(i-100*a>=0){
			wat[i]|=wat[i-100*a];
		}
		if(i-100*b>=0){
			wat[i]|=wat[i-100*b];
		}
	}
	for(i=1;i<=f;i++){
		//water used
		for(j=1;j<=i;j++){
			if(wat[j] && sug[i-j]){
				t1=e*j;
				t1/=100;
				if(i-j<=t1){
					temp=(100.0*(i-j))/i;
					if(temp>=perc){
						perc=temp;
						a1=i;
						a2=i-j;
					}
				}
			}
		}
	}
	printf("%d %d\n",a1,a2);
	return 0;
}

Measured memory_bytes: 256
def solve():

    N, A, B, C = map(int, input().split())
    llist = [int(input()) for i in range(N)]
    inf = 10**9

    def dfs(cursol, a, b, c):
        # すべての竹に対して合成魔法を試したら、不足分は延長 or 短縮魔法を使う
        if cursol == N:
            return abs(A-a)+abs(B-b)+abs(C-c)-30 if min(a, b, c) > 0 else inf

        return min(
            dfs(cursol+1, a, b, c),
            # 合成魔法を使っているので+10が必要
            dfs(cursol+1, a+llist[cursol], b, c)+10,
            dfs(cursol+1, a, b+llist[cursol], c)+10,
            dfs(cursol+1, a, b, c+llist[cursol])+10
        )

    print(dfs(0, 0, 0, 0))


if __name__ == "__main__":
    solve()


Measured memory_bytes: 44380
#include<stdio.h>
#include<string.h>

#define MAX 2000001
#define MAX_SCORE 10001

typedef struct {
  int id;
  int score;
  int rank;
} Info;

int n; // number of students
int counter[MAX_SCORE+1], maxi;
Info list[MAX+1], sortedList[MAX+1];


void CountingSort() {
  memset(counter,0,sizeof counter);
  int i;
  for(i=0;i<n;++i) ++counter[list[i].score];
  for(i=1;i<=maxi;++i) counter[i] += counter[i-1];
  for(i=n-1;i>=0;--i) {
    sortedList[--counter[list[i].score]] = list[i];
  }
}

int main() {
  int i, id, score;
  while( scanf("%d",&n) != EOF ) {
    maxi = 0;
    for(i=0;i<n;++i) {
      scanf("%d",&score);
      list[i].score = score;
      if( maxi < score ) maxi = score;
    }
    CountingSort();
    for(i=0;i<n;++i) {
      if( i ) printf(" ");
      printf("%d",sortedList[i].score);
    } puts("");
  }
  return 0;
}

Measured memory_bytes: 47536
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ld long double
#define fi first
#define se second
#define pb push_back
#define pii pair<int,int>
#define all(x) (x).begin(), (x).end()
#define forn(i,n) for(int i=0;i<(n);i++)
#define for1(i,n) for(int i=1;i<(n);i++)
const int MOD = 1e9 + 7 ;
int mpow(int a,int b,int p=MOD){a=a%p;int res=1;while(b>0){if(b&1)res=(res*a)%p;a=(a*a)%p;b=b>>1;}return res%p;}
const int N=5e5+3;

int32_t main(){
      ios_base::sync_with_stdio(false);
      cin.tie(NULL);

      int n,k;
      cin>>n>>k;
      ld ans=0;
      for(int i=1;i<=n;i++)
      {
            int x=i;
            int cnt=0;          
            while((1<<cnt)*x<k)
            {
                  cnt++;
            }
            //cout<<cnt<<" ";
            ans+=pow(0.5,(ld)cnt);
      }
      ans*=(1.0/(ld)n);
      cout<<fixed<<setprecision(12)<<ans;
}     



Measured memory_bytes: 384
import java.util.Scanner;

public class Main {

	static Scanner scan = new Scanner(System.in);
	public static void main(String[] args){
		int card_sum = scan.nextInt();
//		int card_sum = Integer.parseInt(args[0]);
		int judge,taro_score = 0,hanako_score = 0;
	for(int i = 0;i < card_sum;i++){

		String taro_card = scan.next();
		String hanako_card = scan.next();
//		String taro_card = args[k];
//		String hanako_card = args[k + 1];


		judge = taro_card.compareTo(hanako_card);
		if(judge > 0){
			taro_score += 3;
		}else if(judge < 0){
			hanako_score += 3;
		}else{
			taro_score += 1;
			hanako_score += 1;
		}

	}
	System.out.println(taro_score + " " + hanako_score);
	}


}


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

using namespace std;
typedef long long ll;
typedef long double ld;

const int N = 1e5 + 5;
int n, mod;
int dp[N], sol[N];
vector<int> g[N], pre[N], suf[N];

void dfs(int node, int parent)
{
	pre[node].resize(g[node].size());
	suf[node].resize(g[node].size());
	int cur = 1;
	for(int i = 0; i < g[node].size(); i++)
	{
		int &child = g[node][i];
		if(child != parent){
			dfs(child, node);
			cur = (1ll * cur * dp[child]) % mod;
		}
		pre[node][i] = cur;
	}
	cur = 1;
	for(int i = (int)g[node].size() - 1; i >= 0; i--)
	{
		int &child = g[node][i];
		if(child != parent){
			cur = (1ll * cur * dp[child]) % mod;
		}
		suf[node][i] = cur;
	}
	dp[node] = cur + 1;
	if(dp[node] >= mod)
		dp[node] -= mod;
}

void dfs2(int node, int parent, int val_parent)
{
	dp[node]--;
	if(dp[node] < 0)
		dp[node] += mod;
	dp[node] = (1ll * dp[node] * val_parent) % mod;
	dp[node]++;
	if(dp[node] >= mod)
		dp[node] -= mod;
	sol[node] = dp[node];
	for(int i = 0; i < g[node].size(); i++)
	{
		int &child = g[node][i];
		if(child != parent){
			int p = 1, s = 1;
			if(i)
				p = pre[node][i - 1];
			if(i + 1 < g[node].size())
				s = suf[node][i + 1];
			int v = (1ll * p * s) % mod;
			v = (1ll * v * val_parent) % mod;
			v++;
			if(v >= mod)
				v -= mod;
			dfs2(child, node, v);
		}
	}
}

int main()
{
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
#ifdef ONLINE_JUDGE
	// freopen("", "r", stdin);
	// freopen("", "w", stdout);
#endif
	cin >> n >> mod;
	for(int i = 0; i < n - 1; i++)
	{
		int u, v;
		cin >> u >> v;
		g[u].push_back(v);
		g[v].push_back(u);
	}
	dfs(1, 1);
	dfs2(1, 1, 1);
	for(int i = 1; i <= n; i++)
		cout << (sol[i] - 1 + mod) % mod << '\n';
	return 0;
}


Measured memory_bytes: 26240
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>

#define UPDATE 0
#define FIND 1

using namespace std;

vector<int> a;

void update(int index, int x) {
	a[index] = x;
}

void _find(int start, int end) {
	int minimam = a[start];

	for(int i = start + 1;i <= end;i++) {
		if(a[i] < minimam) {
			minimam = a[i];
		}
	}

	cout << minimam << endl;
}

int main() {
	int n, q;

	cin >> n >> q;

	int com, x, y;
	
	a.resize(n);
	fill(a.begin(), a.end(), pow(2, 31) - 1);

	for(int i = 0;i < q;i++) {
		cin >> com >> x >> y;

		switch(com) {
			case UPDATE:
				update(x, y);
				break;

			case FIND:
				_find(x, y);
				break;
		}
	}

	return 0;
}

Measured memory_bytes: 3120
import math

def func(b,n):
  if b > n:
    return n
  else:
    return func(b, math.floor(n/b)) + (n % b)

def _func(b,n):
  x = n
  ret = 0
  while True:
    if b > x:
      return ret + x
    else:
      ret += x % b
      x = math.floor(x/b)

def solve(n,s):
  if n == s:
    return n+1
  ans = float('inf')
  for b in range(2,math.floor(math.sqrt(n))+1):
    if _func(b,n) == s:
      return b

  for p in range(1,math.floor(math.sqrt(n))+1):
    if (n-s) % p == 0:
      b = int((n-s)/p)+1
      if b < 2:
        continue
      if _func(b, n) == s:
        ans = min(ans, b)

  if ans < float('inf'):
    return ans
  else:
    return -1

if __name__  == "__main__":
  n = int(input())
  s = int(input())
  ans = solve(n,s)
  print(ans)


Measured memory_bytes: 3188
#include<bits/stdc++.h>
using namespace std;
namespace io{
    const int l=1<<20;
    char buf[l],*s,*t,c;
    inline void gc(){
        if(s==t){
            t=(s=buf)+fread(buf,1,l,stdin);
            c=s==t?EOF:*s++;
        }else c=*s++;
    }
    template<class IT>inline void gi(IT &x){
        x=0;gc();while(c<'0'||c>'9')gc();
        while('0'<=c&&c<='9'){x=(x<<1)+(x<<3)+(c^48);gc();}
    }
    char buf0[20];int a;
    template<class IT>inline void pi(IT x){
        if(x<0){putchar('-');x=-x;}
        do buf0[++a]=x%10+48;while(x/=10);
        while(a)putchar(buf0[a--]);
        putchar('\n');
    }
};
using io::gi;
using io::pi;
typedef unsigned int ui;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<int,ll > pil;
typedef pair<ll ,int> pli;
typedef pair<ll ,ll > pll;
typedef vector<int> vi;
typedef vector<ll > vl;
#define pque priority_queue
#define rep(i,l,r) for(i=(l);i<=(r);++i)
#define per(i,l,r) for(i=(l);i>=(r);--i)
#define REP(i,l,r) for(i=(l);i< (r);++i)
#define PER(i,l,r) for(i=(l);i> (r);--i)
#define mp make_pair
#define pb push_back
#define pf push_front
#define pob pop_back
#define pof pop_front
#define fi first
#define se second
template<class IT>inline void cmax(IT &a,IT b){if(a<b)a=b;}
template<class IT>inline void cmin(IT &a,IT b){if(b<a)a=b;}
const int N=5005,M=15005;
int l[M],r[M];
char s[N];
inline int myabs(int a){return a<0?-a:a;}
int main(){
    //freopen("a.in","r",stdin);
    //freopen("a.out","w",stdout);
    int n,i,j,x,ans,t;
    scanf("%d%s",&n,s+1);ans=1000000000;
	x=(s[1]=='1')?n+1:n;
    REP(i,1,n)if(s[i]!=s[i+1])l[++x]=i;
	REP(x,x+1,M)l[x]=n;
    scanf("%s",s+1);
	x=(s[1]=='1')?n+1:n;
    REP(i,1,n)if(s[i]!=s[i+1])r[++x]=i;
	REP(x,x+1,M)r[x]=n;
	//rep(i,0,20)printf("%d ",l[i]);puts("");
	//rep(i,0,20)printf("%d ",r[i]);puts("");
	for(x=0;x<=n;x+=2){
		t=0;
		for(i=x,j=0;i!=M;++i,++j)t+=myabs(l[i]-r[j]);
		//printf("l<<%d t=%d\n",x,t);
		cmin(ans,t);
	}
	for(x=2;x<=n;x+=2){
		t=0;
		for(i=x,j=0;i!=M;++i,++j)t+=myabs(l[j]-r[i]);
		//printf("l>>%d t=%d\n",x,t);
		cmin(ans,t);
	}
	printf("%d",ans);
    return 0;
}

Measured memory_bytes: 512
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <map>
#include <queue>
#include <iomanip>
#include <set>
#include <tuple>
#define mkp make_pair
#define mkt make_tuple
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
const ll MOD=1e9+7;

int N;
vector<ll> X;
ll L;
int Q;

int nxt[20][100010];
const ll INF = 1e15;

int main(){
  cin>>N;
  X.resize(N);
  rep(i,N) cin>>X[i];
  cin>>L;

  X.push_back(INF);
  for(int i=0;i<N;i++) for(int j=0;j<20;j++) nxt[j][i]=-1;
  for(int i=0;i<N;i++){
      int z=upper_bound(X.begin(),X.end(),X[i]+L)-X.begin();
      z--;
      nxt[0][i]=z;
  }
  nxt[0][N-1]=-1;
  for(int k=0;k+1<20;k++){
      for(int i=0;i<N;i++){
          if(nxt[k][i]==-1) continue;
          nxt[k+1][i]=nxt[k][nxt[k][i]];
      }
  }

  cin>>Q;
  vector<int> ans(Q,0);
  for(int q=0;q<Q;q++){
      int a,b;
      cin>>a>>b;
      a--;
      b--;

      if(a>b) swap(a,b);

      int ok=N,ng=0;
      while(ok-ng>1){
          int mid=(ok+ng)/2;
          int now=a;
          for(int k=0;k<20;k++){
              if(mid&(1<<k)){
                  now=nxt[k][now];
                  if(now==-1) break;
              }
          }

          if(now>=b||now==-1) ok=mid;
          else ng=mid;
      }
      ans[q]=ok;
  }

  for(int i=0;i<Q;i++) cout<<ans[i]<<endl;
  

  return 0;
}


Measured memory_bytes: 9840
#include <bits/stdc++.h>
#define _ ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define int long long
#define pb push_back
#define sz(i) (int)(i.size())
#define F first
#define S second
#define L long double
#define P pair<int, int>
const int inf = 0x3f3f3f3f3f3f3f3LL;
const int mod = (int)1e9 + 7;
using namespace std;
#if LOCAL
#include "../../tr.h"
#else
#define tr(...)
#define endl '\n'
#endif
template<class T> void smin(T& a, T val) {if (a > val) a = val;}template<class T> void smax(T& a, T val) {if (a < val) a = val;}
const int N = 2*(int)1e5 + 10;

int n, a[N];
multiset<int> ms;

int32_t main(){_

   cin>>n;

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

   for (int i = 0; i < n; ++i)
   {
      ms.erase(ms.find(a[i]));
      cout<<*ms.rbegin()<<endl;
      ms.insert(a[i]);
   }
   

   return 0;
}

Measured memory_bytes: 12544
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
int main(){
  ll a;
  cin>>a;
  ll b;
  cin>>b;
  ll c;
  cin>>c;
  ll f=-1;
  vector<ll>vec(a);
  vector<ll>veco(0);
  for(ll i=0;i<a;i++){
    if(i==0){
      cin>>vec.at(i);
    }
    else{
      ll d;
      cin>>d;
      vec.at(i)=vec.at(i-1)+d;
      
      }
    if(vec.at(i)>c&&f==-1){
        f=max(f,i);
        
    }
    if(i==a-1&&f==-1&&vec.at(i)<=c){
      f=max(f,i+1);
    }
  }
  
  for(ll i=0;i<b;i++){
    if(i==0){
      ll e;
      cin>>e;
      veco.push_back(e);
    }
    else{
      ll e;
      cin>>e;
      veco.push_back(e+veco.at(i-1));
      
    }
    if(veco.at(i)>c){
        f=max(f,i);
        break;
      }
    if(i==b-1){
      f=max(f,i+1);
    }
  }
  
  ll x=veco.size()-1;
  for(ll i=0;i<vec.size()&&vec.at(i)<=c;i++){
    ll g=c-vec.at(i);
    if(f>i+2){
      if(f-2-i>=veco.size()){
        continue;
      }
      else if(veco.at(f-2-i)>g){
        continue;
      }
    }
      
    for(ll j=x;j>=0;j--){
      if(veco.at(j)<=g){
        f=max(i+j+2,f);
        x=j;
        break;
      }
      if(j==0){
        f=max(f,i+1);
      }
    }
  }
  cout<<f<<endl;
      
    
    
  return 0;
}



Measured memory_bytes: 6928
class InputLine
  def self.to_s
    gets.chomp
  end

  def self.to_i
    InputLine.to_s.to_i
  end
  
  def self.to_f
    InputLine.to_s.to_f
  end

  def self.to_sa
    InputLine.to_s.split(' ')
  end

  def self.to_ia
    InputLine.to_sa.map(&:to_i)
  end
  
  def self.to_fa
    InputLine.to_sa.map(&:to_f)
  end
end

def main(argv)
  (a, b, c, d) = InputLine.to_ia

  puts [a * c, a * d, b * c, b * d].max.to_s
end

if self.to_s == 'main' then
  main(ARGV)
end

Measured memory_bytes: 14336
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <queue>
#include <stack>
#include <map>
#include <algorithm>
#include <math.h>
#include <cassert>
#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 n;
  cin >> n;
  vector<int> w(n), l(n+1), r(n+1);
  rep(i,n) cin >> w[i];
  l[0] = 0; r[n] = 0;
  rep(i,n) l[i+1] = l[i] + w[i];
  rep(i,n) r[n-i-1] = r[n-i] + w[n-i-1];

  int ans = 1e9;
  rep(i,n+1){
    ans = min(ans,abs(l[i]-r[i]));
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
using namespace std;
int dp[1005][1005];
char mp[1005][1005];
int mod=1000000007;
int n,m;
int main()
{
	scanf("%d%d",&n,&m);
	for(int i=1;i<=n;i++)
	{
		scanf("%s",mp[i]+1);
	}
	dp[1][1]=1;
	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<=m;j++)
		{
			if(mp[i][j]=='#')
				continue;
			dp[i][j+1]+=dp[i][j];
			dp[i+1][j]+=dp[i][j]; 
			dp[i][j+1]%=mod;
			dp[i+1][j]%=mod;
		}
	}
	cout<<dp[n][m]<<endl;
	return 0;
} 


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

using namespace std;

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

#define each(i,a) for (auto&& i : a)
#define FOR(i,a,b) for (ll i=(a),__last_##i=(b);i<__last_##i;i++)
#define RFOR(i,a,b) for (ll i=(b)-1,__last_##i=(a);i>=__last_##i;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define __GET_MACRO3(_1, _2, _3, NAME, ...) NAME
#define rep(...) __GET_MACRO3(__VA_ARGS__, FOR, REP)(__VA_ARGS__)
#define rrep(...) __GET_MACRO3(__VA_ARGS__, RFOR, RREP)(__VA_ARGS__)
#define pb push_back
#define all(a) (a).begin(),(a).end()
#define chmin(x,v) x = min(x, v)
#define chmax(x,v) x = max(x, v)

const ll linf = 1e18;
const int inf = 1e9;
const double eps = 1e-12;
const double pi = acos(-1);

template<typename T>
istream& operator>>(istream& is, vector<T>& vec) {
    each(x,vec) is >> x;
    return is;
}
template<typename T>
ostream& operator<<(ostream& os, const vector<T>& vec) {
    rep(i,vec.size()) {
        if (i) os << " ";
        os << vec[i];
    }
    return os;
}
template<typename T>
ostream& operator<<(ostream& os, const vector< vector<T> >& vec) {
    rep(i,vec.size()) {
        if (i) os << endl;
        os << vec[i];
    }
    return os;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll n; cin >> n;
    ll cnt = 0;
    rep(i, n) {
        ll p; string c; ll t; cin >> p >> c >> t;
        if (c == ")") cnt += t;
        else cnt -= t;
        if (cnt == 0) cout << "Yes" << endl;
        else cout << "No" << endl;
    }
}

Measured memory_bytes: 3208
#include <stdio.h>
#include <stdlib.h>
int
main()
{
  int a, b, c;
  scanf("%d %d %d", &a, &b, &c);
  if ((a == b) && a != c)
    printf("Yes");
  else if ((a == c) && a != b)
    printf("Yes");
  else if ((b == c) && b != a)
    printf("Yes");
  else
    printf("No");
}

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

using namespace std;

#define w(x)    int x; cin>>x; while(x--)
#define endl 	"\n"
#define max(a, b) (a < b ? b : a)
#define min(a, b) ((a > b) ? b : a)
#define rep(i,n) for (i = 0; i < n; ++i)
#define REP(i,k,n) for (i = k; i <= n; ++i)
#define REPR(i,k,n) for (i = k; i >= n; --i)
typedef long long ll;
#define mk(arr,n,type)   type *arr=new type[n]
const int mod=1000000007;
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}

void b_v_r()
{
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
}

int main()
{
    b_v_r();
    int x,y;
    cin >> x >> y;
    // x = a + b
    // y = 2a + 4b
    int b = (y-(2*x))/2;
    int a = x - b;

    // 
    int flag = 0;
    if(y>(4*x)||(y<(2*x)))
    {
        cout << "No" << endl;
        flag = 1;
    }

    if((y-(2*x))%2==0 && flag!=1)
    {
        cout << "Yes" << endl;
    }
    else
    {
        if(flag!=1)
            cout << "No" << endl;
    }
    
        
    return 0;
}


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

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

  ll n = s.length();
  vector<ll> a(n);
  rep(i, 0, n) a[i] = s[i] - 'a';

  vector<vector<ll>> next(n + 1, vector<ll>(26, -1));
  for (ll i = n - 1; i >= 0; i--) {
    rep(j, 0, 26) {
      next[i][j] = a[i] == j ? i + 1 : next[i + 1][j];
    }
  }

  vector<pair<ll, ll>> prev(n, make_pair(-1, -1));

  struct state { ll v, p, c; };
  queue<state> q;
  q.push((state) { 0, -1, -1 });

  while (q.size()) {
    ll v = q.front().v;
    ll p = q.front().p;
    ll c = q.front().c;
    q.pop();

    if (v == -1) {
      string ans = "";
      ans += 'a' + c;
      for (ll i = p; prev[i].first != -1; i = prev[i].first) {
        ans += 'a' + prev[i].second;
      }
      reverse(ans.begin(), ans.end());
      cout << ans << endl;
      break;
    }

    if (prev[v].first != -1) continue;
    prev[v] = make_pair(p, c);

    rep(i, 0, 26) {
      q.push((state) { next[v][i], v, i });
    }
  }
}

Measured memory_bytes: 55428
// Daritys Morgho ban Rovegrie
// Math = ♥
// Sometimes it is people that no one imagines anything of who do things that no one can imagine
// After all this time? Always

#include <bits/stdc++.h>                        // uncomment before submission
//#include <ext/pb_ds/assoc_container.hpp>		// uncomment before submission
//#include <ext/pb_ds/tree_policy.hpp>			// uncomment before submission
//using namespace __gnu_pbds;					// uncomment before submission
using namespace std;
//<---------------------------------------------------Template----------------------------------------------------------->
#define int long long
#define ll long long
#define ld long double
const int INF = 1e15 + 7;
const int MAX = 1e5 + 7;
const int MOD = 1e9 + 7;
typedef pair<ll, ll> ii;
typedef vector<ll> vi;                  // Vector of long long
typedef vector<vi> vvi;                 // Vector of vi
typedef vector<ii> vii;                 // Vector of pairs
typedef vector<vii> vvii;               // Vector of Vector of pairs
typedef vector<bool> vb;                // Vector of bool
#define pq priority_queue               // Max heap (To convert to min heap, use negative sign before every value)
#define ff first                        // For pairs
#define ss second                       // For pairs
#define pb push_back                    // Push back to vector
#define mp make_pair                    // Makes pairs to be stored as pair
#define all(c) (c).begin(), (c).end()   // Mainly used by me in sorting
#define run(x, c) (x)=(c).begin(); (x)!=(c).end(); (x)++ // Mainly used by me for range based loops
// ordered_set adds two new functions to set - (set).find_by_order([kth element based on zero indexing]) and order_of_key()
// order_of_key returns number of elements less that parameter. If element exists, that order is its index
#define ordered_set tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update>
//<----------------------------------------------------------------------------------------------------------------------->

vi v;
vector<vvi> f(3005, vvi(3005, vi(2, -1)));

int solve(int l, int r, int flag)
{
    if (l > r) return 0;
    if (f[l][r][flag] != -1) return f[l][r][flag];

    if (flag)
        return f[l][r][flag] = max(solve(l + 1, r, flag ^ 1) + v[l], solve(l, r - 1, flag ^ 1) + v[r]);
    else
        return f[l][r][flag] = min(solve(l + 1, r, flag ^ 1) - v[l], solve(l, r - 1, flag ^ 1) - v[r]);
}

signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n;
    cin >> n, v.resize(n + 1);
    for (int i = 1; i <= n; i++) cin >> v[i];

    cout << solve(1, n, 1) << endl;
    return 0;
}



Measured memory_bytes: 496512
#include <iostream>
#include <vector>
#include <set>
#include <map>

#define rep(i,n) for(int i=0;i<(int)n;++i)
#define all(c) (c).begin(),(c).end()
#define mp make_pair
#define pb push_back
#define each(i,c) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();i++)
#define dbg(x) cerr<<__LINE__<<": "<<#x<<" = "<<(x)<<endl

using namespace std;

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

constexpr int inf = (int)1e9;
constexpr double INF = 1e12, EPS = 1e-9;
constexpr int MX = 2010;
constexpr int mod = inf + 7;

int n, m, q;
int L[MX][MX], R[MX][MX];
int memo[MX][MX];

int main() {
  cin >> n;
  int a[n];
  int sum{0};
  rep(i, n) { cin >> a[i]; sum += a[i]; }

  sort(a, a + n, greater<int>());

  bool re{sum - a[0] > a[0]};

  end:

  cout << (re ? "Yes" : "No") << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(){

  int a,n,max,min,i;
  long sum;
  
  	scanf("%d",&n);
  	scanf("%d",&a);
  	max = min = sum = a;
  	i = 1;
	
  while(i < n){
  	scanf("%d",&a);
	
	sum += a;
	if(max < a)
		max = a;
	if(min > a)
		min = a;
	i++;
  }
  	printf("%d %d %ld\n",min,max,sum);
return 0;
}



Measured memory_bytes: 2104
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <ios>
#include <iostream>
#include <vector>

#define ll long long

using namespace std;

int N;
bool exs[4] = {false, false, false, false};
char S;
char color[4] = {'P', 'W', 'G', 'Y'};

int main()
{
    cin >> N;
    for (int i = 0; i < N; i++) {
        cin >> S;
        for (size_t j = 0; j < 4; j++) {
            if (S == color[j]) {
                exs[j] = true;
            }
        }
    }

    int color_num = 0;
    for (size_t i = 0; i < 4; i++) {
        if (exs[i]) {
            color_num++;
        }
    }

    cout << (color_num == 3 ? "Three" : "Four") << endl;

    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

int main(void){
  int n,sum = 0;
  int a[100];
  scanf("%d", &n);
  for(int i = 0;i<n;i++){
    scanf("%d", &a[i]);
  }
  for(int i = 0;i<n;i+=2){
    if(a[i] % 2 == 1)
      sum++;
  }
  printf("%d", sum);
  return 0;
}

Measured memory_bytes: 1728
#include <algorithm>
#include <cctype>
#include <climits>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <locale>
#include <numeric>
#include <queue>
#include <stack>
#include <string>
#include <unordered_map>
#include <utility>
#include <vector>
 
using namespace std;

int main(void){
    char num[4];
    for(int i=0;i<4;i++){
        cin>>num[i];
    }
    for(int i=0;i<3;i++){
            if(num[i] == num[i+1]){
                cout<<"Bad"<<endl;
                return 0;
            }
        }
    cout<<"Good"<<endl;
}

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

H, A = MAP()

print(ceil(H/A))

Measured memory_bytes: 5144
import scala.io.StdIn.{readLine,readInt}

object Main {

  def main(args: Array[String]) = {
    val n = readInt
    val a = Array.ofDim[Int](4,3,10)

    1 to n foreach { _ =>
      val Array(b,f,r,v) = readLine.split(" ").map(_.toInt)
      a(b-1)(f-1)(r-1) += v
    }

    for(i <- 0 to 3) {
      for(j <- 0 to 2) {
        for(k <- 0 to 9) {
          print(" ")
          print(a(i)(j)(k))
        }
        println()
      }
      if(i<3) {
        println("####################")
      }
    }
  }
}

Measured memory_bytes: 44212
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define lvector vector<ll> 
#define rep(i,n) for(ll (i)=0; i<(n); ++(i))
#define print(a) cout << (a) << endl

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  ll n;cin>>n;
  lvector v(n,0);rep(i,n) cin>>v[i];
  lvector v_(v);sort(v_.begin(),v_.end());
  rep(i,n) {
    if(v[i]>=v_[n/2]) print(v_[n/2-1]);
    else print(v_[n/2]);
  }
  return 0;
}

Measured memory_bytes: 5376
#include<bits/stdc++.h>
 #include <ext/pb_ds/tree_policy.hpp>
 #include <ext/pb_ds/assoc_container.hpp>
 #include<chrono>
 using namespace std;
 using namespace std::chrono;      
 using namespace __gnu_pbds; 
 #define fastio     ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
 #define fi         first
 #define se         second
#define int         long long 
 #define pb         push_back
 #define emp        emplace_back
 #define vv(x)      vector<x>
 #define mp(x,y)    map<x,y>
 #define dq(x)      deque<x>
 #define pql(x)     priority_queue<x>
 #define pqs(x)     priority_queue<x,vv(x),greater<x> >
 #define M          1000000007
 #define forf(i,a,b) for(int i=a;i<b;i++)
 #define it(x)      x::iterator
 #define ll         long long 
 #define debug(...) fprintf(stderr, __VA_ARGS__), fflush(stderr)
 #define time__(d)  for(long blockTime = 0; (blockTime == 0 ? (blockTime=clock()) != 0 : false); debug("%s time : %.4fs", d, (double)(clock() - blockTime) / CLOCKS_PER_SEC))
 #define vii        vector<int>
 #define big        3e18
 #define sm         -2e9
 #define mkr        make_pair
 #define vpi        vector<pair<int,int> >
 #define pii        pair<int,int>
 #define rng        500005
 #define sz(x)      (int)x.size()
 #define rv(x)      reverse(x.begin(),x.end())
 #define out(x)     cout<<x.fi<<" "<<x.se<<endl;

//#define ordered_set tree<pii, null_type,less<pii>, rb_tree_tag,tree_order_statistics_node_update> 
  
void pr_init()
{
   
    #ifndef ONLINE_JUDGE
    freopen("gin.txt", "r", stdin);
    freopen("gout.txt", "w", stdout);
   
    #endif
}


void solve()
{
  int n;
  cin >> n;

  int a[n];

  forf(i,0,n) cin >> a[i];

  sort(a,a+n,greater<int>());
  
  int tg = n-2,an = a[0];
  
  for(int i=1;i<n;i++)
  {
    if(tg==0) break;
    if(tg >= 2)
    {
      tg-=2;
      an += 2*a[i];
    }
    else tg--,an+=a[i];
  }

  cout<<an;

}


int32_t main()
{
  pr_init();
  fastio;
  
  auto start = high_resolution_clock::now(); 
 
  solve();
  auto stop = high_resolution_clock::now();
  auto duration = duration_cast<microseconds>(stop - start); 
   // cout << "Time taken by function: "
   //       << duration.count() << " microseconds" << endl; 

 }
      
      

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

int main() {
    int n;
    cin >> n;
    vector<P> p(n);
    rep(i,n) cin >> p[i].second >> p[i].first;
    sort(p.begin(), p.end());
    ll t = 0;
    rep(i, n) {
        t += p[i].second;
        if (t > p[i].first) {
            puts("No");
            return 0;
        }
    }
    puts("Yes");
    return 0;
}


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

int main() {

  int i, A=1, N, K;
  
  cin >> N >> K;
  
  for (i = 0; i < N; i++) {
    if (A * 2 >= A + K) {
      A += K;
    } else {
      A *= 2;
    }
  }
  
  cout << A;
  

}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<string>
#include<stack>
#include<functional>
#include<queue>
#include<vector>
#include<algorithm>
#include<iomanip>
#include<utility>
#include<set>
#include<unordered_set>
#include<map>
#include<unordered_map>
typedef long long int ll;
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) for(int i=0;i<signed(n);i++)
#define EREP(i,n) for(int i=1;i<=signed(n);i++)
#define ALL(a) (a).begin(),(a).end()
using namespace std;
//#define EVEL 1
#ifdef EVEL
#define DEB(X) cout << #X <<":" <<X<<" " ;
#define TF(f) f ? cout<<"true  " : cout<<"false ";
#define END cout<<"\n";
#else
#define DEB(X) {}
#define TF(f) {}
#define END {}
#endif
const ll MOD = 1000000007;
const ll INF = 9e14;
typedef std::pair<ll,ll> P;
struct edge{ int to,cost; };
#define VMAX 100000

ll N,M,X,K,Q;
ll A,B,C,D;

ll ans;
bool F=false;
string S,T,U;
int main(){
    cin>>S>>T>>A>>B>>U;
    if(U==S)A--;
    else B--;


    cout<<A<<" "<<B<<endl;
}


Measured memory_bytes: 256
N=int(input())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
C=list(map(int,input().split()))
ans=sum(B)
for i,a in enumerate(A):
  if i>=len(A)-1:
    break
  if A[i+1]-a==1:
    ans+=C[a-1]
print(ans)

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

int mp[15000000];
int Hash(string s) {
	int cnt = 0, t = 1;
	rep(i, s.size()) {
		cnt += (int)(s[i] - '0')*t;
		t *= 3;
	}
	return cnt;
}
int main() {
	int n, m;
	while (scanf("%d%d", &n, &m), n) {
		memset(mp, 0, sizeof(mp));
		string in = "000000000000000";
		rep(i, 3) {
			int len; scanf("%d", &len);
			rep(j, len) {
				int a; scanf("%d", &a);
				in[--a] = i + '0';
			}
		}
		queue<string>que;
		mp[Hash(in)] = 1;
		que.push(in);
		while (!que.empty()) {
			string u = que.front(); que.pop();
			if (count(u.begin(), u.begin() + n, '0') == n ||
				count(u.begin(), u.begin() + n, '2') == n) {
				printf("%d\n", mp[Hash(u)] - 1);
				goto g;
			}
			if (mp[Hash(u)] > m)continue;
			rep(k, 2)rep(t, 2) {
				int i, j;
				if (t) { i = k, j = k + 1; }
				else { i = k + 1; j = k; }
				int fi = (int)u.rfind(i + '0', n - 1),
					fj = (int)u.rfind(j + '0', n - 1);
				if (fi == -1 || fi < fj)continue;
				string v = u;
				v[fi] = j + '0';
				if (!mp[Hash(v)]) {
					mp[Hash(v)] = mp[Hash(u)] + 1;
					que.push(v);
				}
			}
		}
		puts("-1");
	g:;
	}
}

Measured memory_bytes: 61764
#include <cassert>
#include <cctype>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <algorithm>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>
using namespace std;
#define REP(i, n) for(int i = 0; i < (int)(n); ++i)
typedef long long ll;

char buf[10];
int main(void) {
  scanf("%s", &buf);
  buf[3] = 0;
  cout << buf << endl;
  return 0;
}


Measured memory_bytes: 3188
w = str(input())
letter = ['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z']
A = 'Yes'
for letter in letter:
  if w.count(letter)%2 != 0:
    A = 'No'
    break
print(A)

Measured memory_bytes: 2940
#include<stdio.h>
#include<cstring>
char s[100005];
char f['z'];
int len;
int main(){
	f['b']='d';
	f['d']='b';
	f['p']='q';
	f['q']='p';
	scanf("%s",s+1);
	len=strlen(s+1);
	if (len&1){
		puts("No");
		return 0;
	}
	int p=len>>1;
	for (int i=1;i<=p;i++){
		if (f[s[i]]!=s[len-i+1]){
			puts("No");
			return 0;
		}
	}
	puts("Yes");
	return 0;
}

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

struct UnionFind
{
    vector<int> d;
    UnionFind(int n = 0) : d(n, -1){};

    // find
    int find(int x)
    {
        if (d[x] < 0)
        {
            return x;
        }

        return d[x] = find(d[x]);
    }

    // unite
    bool unite(int x, int y)
    {
        x = find(x);
        y = find(y);
        if (x == y)
            return false;

        if (x > y)
            swap(x, y);

        d[x] += d[y];
        d[y] = x;

        return true;
    }

    // same
    bool same(int x, int y)
    {
        return (find(x) == find(y));
    }

    // size
    int size(int x)
    {
        return -d[find(x)];
    }
};

int main()
{
    int n, m;
    cin >> n >> m;

    int a_list[m], b_list[m];
    for (int i = 0; i < m; i++)
    {
        int a, b;
        cin >> a >> b;
        a--;
        b--;
        a_list[i] = a;
        b_list[i] = b;
    }

    int ans = 0;
    for (int i = 0; i < m; i++)
    {
        UnionFind uf = UnionFind(n);
        for (int j = 0; j < m; j++)
        {
            if (i == j)
                continue;
            uf.unite(a_list[j], b_list[j]);
        }
        if (uf.size(0) != n)
        {
            ans++;
        }
    }

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

Measured memory_bytes: 256
from collections import deque
n, m = map(int, input().split())
G = [[] for _ in range(n)]
for _ in range(m):
    a, b = map(int, input().split())
    G[a - 1].append(b - 1)
    G[b - 1].append(a - 1)

que = deque([0])
seen = [-1] * n
seen[0] = 0

while len(que) > 0:
    now_v = que.popleft()
    now_board = seen[now_v]
    next_vs = G[now_v]
    for next_v in next_vs:
        if seen[next_v] == -1:
            seen[next_v] = now_v
            que.append(next_v)

print('Yes')
for x in seen[1:]:
    print(x + 1)

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

namespace ConsoleApp
{
    class Program
    {
        static void Main(string[] args)
        {
            var input1 = Console.ReadLine().Split().Select(long.Parse).ToList();
            var H = input1[0];
            var W = input1[1];

            var maze = new int[H, W];
            for (int i = 0; i < H; i++)
            {
                var S = Console.ReadLine().Select(s => s == '.' ? 0 : -1).ToList();
                for (int j = 0; j < W; j++)
                {
                    maze[i, j] = S[j];
                }
            }

            var ans = 0;
            for (int i = 0; i < H; i++)
            {
                for (int j = 0; j < W; j++)
                {
                    var count = Count(Copy(maze), i, j);
                    if (ans < count) ans = count;
                }
            }

            Console.WriteLine(ans);
        }

        private static int[,] Copy(int[,] source)
        {
            var ret = new int[source.GetLength(0), source.GetLength(1)];
            Array.Copy(source, ret, source.Length);
            return ret;
        }

        private static int Count(int[,] maze, int x, int y)
        {
            if (maze[x, y] == -1) return 0;

            var list = new List<Tuple<int, int>>() { new Tuple<int, int>(x, y) };
            maze[x, y] = 1;

            var count = -1;
            while (list.Any())
            {
                count++;
                list = FillAround(maze, list);
            }

            return count;
        }

        private static List<Tuple<int, int>> FillAround(int[,] maze, List<Tuple<int, int>> list)
        {
            var nextList = new List<Tuple<int, int>>();
            list.ForEach(s => nextList.AddRange(FillAround(maze, s)));
            return nextList;
        }

        private static List<Tuple<int, int>> FillAround(int[,] maze, Tuple<int, int> item)
        {
            var nextList = new List<Tuple<int, int>>();
            var x = item.Item1;
            var y = item.Item2;

            Fill(maze, nextList, x - 1, y);
            Fill(maze, nextList, x + 1, y);
            Fill(maze, nextList, x, y - 1);
            Fill(maze, nextList, x, y + 1);

            return nextList;
        }

        private static void Fill(int[,] maze, List<Tuple<int, int>> list, int x, int y)
        {
            if (x < 0 || x >= maze.GetLength(0) || y < 0 || y >= maze.GetLength(1)) return;
            if (maze[x, y] == 0)
            {
                maze[x, y] = 1;
                list.Add(new Tuple<int, int>(x, y));
            }
        }
    }
}


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

#pragma GCC optimize "O3"
#define rep(i,a,n) for(int i=a; i<n; i++)
typedef long long ll;
typedef pair<int,int> P;
const ll MOD = (int)1e9+7;
const ll INF = MOD*MOD;
const ll powll = 1LL<<1;


int main() {
    int k; string s; cin >> k >> s;
    rep(i,0,min((int)s.size(),k)) cout << s[i];
    if(s.size() > k){
        cout << "...";
    }
    cout << "\n";
}

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

int main(){
  long long int s,h;
  vector<long long int> x(3);
  for(int i=0;i<3;i++)cin >> x.at(i);
  sort(x.begin(),x.end());
  s=x.at(0)*x.at(1);
  h=x.at(2);
  if(h%2==0)cout << 0 << endl;
  else cout << s << endl;
}


Measured memory_bytes: 256
// 20
/****************************************************
https://searleser97.gitlab.io/algorithms/template.cpp
****************************************************/

#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define forr(_, x, n) for (int _ = x; _ > n; _--)
#define fos(_, x, n, s) for (int _ = x; _ < n; _ += s)
#define forn(_, x, n) fos(_, x, n, 1)
#define rep(_, n) forn(_, 0, n)
#define fi first
#define se second
#define pb push_back
#define pairii pair<int, int>
#define all(x) x.begin(), x.end()
#define cerr(s) cerr << "\033[48;5;196m\033[38;5;15m" << s << "\033[0m"
// typedef __int128_t lli;
typedef long long int li;
typedef long double ld;
// 12
void _main(int tc) {
  int n, l;
  cin >> n >> l;
  vector<string> strs(n);
  rep(i, n) {
    cin >> strs[i];
  }
  sort(all(strs));
  rep(i, n) {
    cout << strs[i];
  }
  cout << endl;
}

int main() {
  ios_base::sync_with_stdio(0), cin.tie(0);
  _main(0); return 0;
  int tc;
  cin >> tc;
  rep(i, tc) _main(i + 1);
}

Measured memory_bytes: 256
#include <stdio.h>
long long int gcd(long long int a, long long int b){
	if(a<b){
		long long int t;
		t=a;
		a=b;
		b=t;
	}
	long long int r;
	r=a%b;
	while(r>0){
		a=b;
		b=r;
		r=a%b;
	}
	return b;
}
int main(){
	long long int A,B,C,D;
	scanf("%lld %lld %lld %lld",&A,&B,&C,&D);
	long long int ans;
	ans=B-A+1;
	ans=ans-B/C+(A-1)/C;
	ans=ans-B/D+(A-1)/D;
	long long int E;
	E=C*D/gcd(C,D);
	ans=ans+B/E-(A-1)/E;
	printf("%lld",ans);
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
#define ll long long
#define ull unsigned long long
using namespace std;
ll n,k,a[100009],dp[100009];
	
int main (){
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	cin >> n >> k;
	for (int i=1; i<=n; i++){
		cin >> a[i];
	}
	for (int i=n; i>=1; i--){
		ll tmp=1e15;
		for (int j=1; j<=k; j++){
			if (i<=n-j)tmp=min(tmp,abs(a[i]-a[i+j])+dp[i+j]);
		}
		if (tmp!=1e15)dp[i]=tmp;
	}
	cout << dp[1] << endl;
}

Measured memory_bytes: 1792
import java.util.Scanner;
public class Main {
    public static void main(String[] args) {
	// 標準入力からデータを読み込む準備
	Scanner sc = new Scanner(System.in);
	int w = sc.nextInt();
	int n = sc.nextInt();
	int[] values = new int[w];
	for (int i = 0; i < values.length; i++) {
	    values[i] = i + 1;
	}
	for (int i = 0; i < n; i++) {
	    String str = sc.next();
	    String[] ab = str.split(",");
	    int a = Integer.parseInt(ab[0]) - 1;
	    int b = Integer.parseInt(ab[1]) - 1;
	    // aとbを使ってvaluesを操作しよう
	    int c;
	    c=values[a];
	    values[a]=values[b];
	    values[b]=c;
	}
	// valuesを出力しよう
	for (int k=0;k<n;k++){
	    System.out.println(values[k]);
	}
    }
}

Measured memory_bytes: 26012