akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

using namespace std;

int n, m;

vector<int> inv(vector<int> a) {
  vector<int> b(n);
  for (int i = 0; i < n; i++) {
    b[a[i]] = i;
  }
  return b;
}

vector<int>& operator*=(vector<int>& a, vector<int> b) {
  vector<int> c(n);
  for (int i = 0; i < n; i++) {
    c[i] = a[b[i]];
  }
  a = c;
  return a;
}

vector<int> operator*(vector<int> a, vector<int> b) {
  return a *= b;
}

void output(vector<int> a) {
  for (int i = 0; i < n; i++) {
    printf("%d%c", a[i] + 1, " \n"[i == n - 1]);
  }
}

vector<int> power(vector<int> a, int k) {
  vector<int> res(n);
  for (int i = 0; i < n; i++) {
    res[i] = i;
  }
  while (k > 0) {
    if (k & 1) {
      res *= a;
    }
    a *= a;
    k >>= 1;
  }
  return res;
}

int main() {
  scanf("%d %d", &n, &m);
  vector<int> a(n);
  for (int i = 0; i < n; i++) {
    scanf("%d", &a[i]);
    a[i]--;
  }
  vector<int> b(n);
  for (int i = 0; i < n; i++) {
    scanf("%d", &b[i]);
    b[i]--;
  }
  if (m == 1) {
    output(a);
  } else if (m == 2) {
    output(b);
  } else {
    m -= 2;
    vector<int> A = inv(a);
    vector<int> B = inv(b);
    vector<int> res = power(b * A * B * a, m / 6);
    int rm = m % 6;
    if (rm == 0) res *= b;
    if (rm == 1) res *= b * A;
    if (rm == 2) res *= b * A * B;
    if (rm == 3) res *= b * A * B * a * B;
    if (rm == 4) res *= b * A * B * a * a * B;
    if (rm == 5) res *= b * A * B * a * b * a * B;
    res *= power(A * b * a * B, m / 6);
    output(res);
  }
  return 0;
}


Measured memory_bytes: 7216
package main

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

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Scan()

	parts := strings.Split(scanner.Text(), " ")
	x, _ := strconv.Atoi(parts[0])
	y, _ := strconv.Atoi(parts[1])

	fmt.Println(x + y/2)
}

Measured memory_bytes: 640
N, M, K=map(int,input().split())
A=list(map(int,input().split()))
B=list(map(int,input().split()))

a,b=[0] ,[0]
for i in range(N):
    a.append(a[i] + A[i])
for i in range(M):
    b.append(b[i] + B[i])
    
ans, j=0, M
for i in range(N+1):
    if a[i]>K:
        break
    while b[j]>K-a[i]:
        j-=1
    ans=max(ans, i+j)
print(ans)    


Measured memory_bytes: 47540
import java.util.Arrays;
import java.util.Scanner;

public class Main {
    public static void main(String[] arg) {
        Scanner scanner = new Scanner(System.in);
        int N = scanner.nextInt();
        int ma = scanner.nextInt();
        int mb = scanner.nextInt();
        int[] a = new int[N];
        int[] b = new int[N];
        int[] c = new int[N];

        for (int i = 0; i < N; i++) {
            a[i] = scanner.nextInt();
            b[i] = scanner.nextInt();
            c[i] = scanner.nextInt();
        }

        int[][][] dp = new int[N+1][401][401];
        boolean[][][] visible = new boolean[N+1][401][401];

        for (int i = 0; i < N+1; i++) {
            for (int j = 0; j < 401; j++) {
                Arrays.fill(dp[i][j], 0);
                Arrays.fill(visible[i][j], false);
            }
        }
        visible[0][0][0] = true;

        for (int i = 0; i < N; i++) {
            for (int j = 400; j > -1; j--) {
                for (int k = 400;k > -1; k--) {
                    if (visible[i][j][k]) {
                        if (visible[i + 1][j][k]) {
                            dp[i + 1][j][k] = Math.min( dp[i + 1][j][k],  dp[i][j][k]);
                        } else {
                            visible[i + 1][j][k] = true;
                            dp[i + 1][j][k] = dp[i][j][k];
                        }
                        if (visible[i + 1][j + a[i]][k + b[i]]) {
                            dp[i + 1][j + a[i]][k + b[i]] = Math.min(dp[i + 1][j + a[i]][k + b[i]], dp[i][j][k] + c[i]);
                        } else {
                            visible[i + 1][j + a[i]][k + b[i]] = true;
                            dp[i + 1][j + a[i]][k + b[i]] = dp[i][j][k] + c[i];
                        }
                    }
                }
            }
        }

        int ans = Integer.MAX_VALUE;
        for (int i = 0; i < 401; i++) {
            for (int j = 0; j < 401; j++) {
                if (i/(j*1.0) == ma/(mb*1.0) && visible[N][i][j]) {
                    ans = Math.min(ans, dp[N][i][j]);
                }
            }
        }
        if (ans == Integer.MAX_VALUE) {
            System.out.println(-1);
        } else {
            System.out.println(ans);
        }
    }
}


Measured memory_bytes: 82864
#include <iostream>
#include <vector>
#include <algorithm>
#define N 1000000

using namespace std;
typedef long long ll;

int main(void) {
	ll i, j, num, k, ans, a = 0;
	cin >> num >> k;
	if (num == 1)
		ans = k;
	else {
		while (!(k & 1)) {
			a++;
			k >>= 1;
		}
		ans = max(1ll, 1ll << (a / num));
		for (i = 3; i < N; i += 2) {
			a = 0;
			while (k % i == 0) {
				a++;
				k /= i;
			}
			for(j = 0; j < a / num; j++)
				ans *= i;
			if (k == 1)
				break;
		}
	}
	cout << ans << "\n";
	return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize ("O3")
#include <bits/stdc++.h>
#define abdelrahman010 ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
typedef long long ll;
using namespace std;
ll n , arr[100005] , memo[100005];
ll solve(ll i)
{
	if(i == n - 1)
		return 0;
	ll &ans = memo[i];
	if(~ans)
		return ans;
	ans = abs(arr[i] - arr[i + 1]) + solve(i + 1);
	if(i < n - 2)
		ans = min(ans , abs(arr[i] - arr[i + 2]) + solve(i + 2));
	return ans;
}
int main()
{
	abdelrahman010
	cin >> n;
	memset(memo , -1 , sizeof memo);
	for(int i = 0;i < n;i++)
		cin >> arr[i];
	cout << solve(0);
	return 0;
}


Measured memory_bytes: 4224
/*
    Don't practice until you get it right. Practice until you can't get it wrong.
*/

#include<bits/stdc++.h>
using namespace std;

#define ll long long
#define ld double
#define pii pair<ll,ll>
#define vl vector<ll>
#define vb vector<bool>
#define vs vector<string>
#define vp vector<pii>
#define pb push_back
#define mp make_pair
#define sc(a) scanf("%lld",&a);
#define sd(a) scanf("%lf",&a);
#define test() ll tt;cin>>tt;for(ll testcase=1;testcase<=tt;testcase++)
#define all(v) v.begin(),v.end()
#define vivek_ghosh ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define MAX 1000055
#define mod 1000000007
#define ff first
#define ss second
const int INF=0x3f3f3f3f;
const ll int inf = LLONG_MAX;

ll power(ll x,ll n,ll M)
{
    if(n==0)
        return 1;
    else if(n%2 == 0)
        return power((x*x)%M,n/2,M);
    else
        return (x*power((x*x)%M,(n-1)/2,M))%M;
}

ll modinv(ll a,ll m)
{
    ll g =__gcd(a, m);
    ll res=power(a, m-2, m);
    return res;
}

vb prime(MAX,true);
vl prm;
void sieve()
{
	prime[0] = prime[1] = false;
	for(ll p=2;p*p<MAX;p++)
	{
		if(prime[p])
		{
			for(ll i=p*p;i<MAX;i+=p)
				prime[i] = false;
		}
	}
	for(ll p=2;p<MAX;p++)
	{
		if(prime[p])
			prm.pb(p);
	}
}

ll n,m,t,i,j,k,q,x,y,ans=0,cnt=0,sum=0,mx=-1,mn=INT_MAX;
string s;

int main()
{
	vivek_ghosh;
	ll n = 1^2^3;
	cin>>m>>t;
	cout<<(n^m^t)<<endl;
	




	
	return 0;
}

Measured memory_bytes: 384
S = input()
C = []
ans = 0
for s in S:
    len_c = len(C)
    if len_c == 0:
        C.append(s)
    else:
        if C[len_c-1] != s:
            ans += 2
            C.pop()
        else:
            C.append(s)
print(ans)

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

using namespace std;
using ll = long long;

int gcd(int a, int b) { return (b == 0) ? a : gcd(b, a % b); }

#define CIN(T, x) T x; cin >> x;
#define CINS(T, x, N) vector<T> x(N); for(int i = 0; i < (N); i++) { cin >> x[i]; }
#define SHOW(x) for(int i = 0; i < x.size(); i++) { cout << x[i] << " "; } cout << "\n";
#define SHOW2(x) for(int j = 0; j < x.size(); j++) { SHOW(x[j]); } cout << "\n";


int main() {

    CIN(int, N);
    CIN(int, M);
    vector<int> L(N + 1, 0);
    vector<int> R(N + 1, 0);

    for (int i = 0; i < M; i++) {
        int l, r;
        cin >> l >> r;
        L[l - 1]++;
        R[r]++;
    }

    int ans = 0;
    int check = 0;
    for (int i = 0; i <= N; i++) {
        check += (L[i]-R[i]);
        if (check == M) ans++;
    }

    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 1024
def cin():  return list(map(int,input().split()))

N = cin()[0]
a = cin()
b = [0 for _ in range(9)]
for i in range(N):
    ind = min(8, a[i] // 400)
    if ind <= 7:  b[ind] = 1
    else:  b[ind] += 1
ma = sum(b)
if b[ind] < N:  mi = sum(b[:-1])
else:  mi = 1
print(mi, ma)

Measured memory_bytes: 61776
def gcd(x, d):
    if x < d:
        x, d = d, x
    if x % d == 0:
        return d
    return gcd(d, x % d)


n, m = [int(x) for x in input().split()]
s = input()
t = input()

lcm = (n * m) // gcd(n, m)
sSub = [s[i] for i in range(0, n, lcm // m)]
tSub = [t[j] for j in range(0, m, lcm // n)]

if sSub == tSub:
    print(lcm)
else:
    print(-1)

# print(*data, sep='\n')


Measured memory_bytes: 40944
#include <stdio.h>
int main(void){
	int n, sum = 0, tmp;
	scanf("%d",&n);
	tmp = n;
	while(tmp != 0){
		sum += tmp % 10;
		tmp /= 10;
	}
	if(n%sum==0){
		printf("Yes\n");
	}else{
		printf("No\n");
	}
	return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <string>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <stdio.h>
using namespace std;
#define int long long
int MOD = 1000000007;
void solve(vector<double> &A) {
	sort(A.rbegin(), A.rend());
	double a = A.back(); A.pop_back();
	double b = A.back(); A.pop_back();
	A.push_back((a + b) * 0.5);
}
signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int N;
	cin >> N;
	vector<double> A(N);
	int res = 0;
	for (int i = 0; i < N; i++) {
		cin >> A[i];
	}
	for (int i = 0; i < N - 1; i++) {
		solve(A);
	}


	cout << fixed << setprecision(15) << A[0] << endl;
}

Measured memory_bytes: 256
S = [int(i) for i in list(input())]
s = ["", ""]
c = 0
for v in S:
    s.append(v)
    # print(s)
    if (s[-1], s[-2])==(0, 1) or (s[-1], s[-2])==(1, 0):
        s.pop()
        s.pop()
        c += 2

print(c)

Measured memory_bytes: 4652
#include<bits/stdc++.h>
#define F first
#define S second
#define pb push_back
#define mp make_pair
#define full(a) a.begin(),a.end()
#define rfull(a) a.rbegin(),a.rend()

using namespace std;
const double pi=acos(-1.0);
const double pii=2*pi;
const double eps=1e-6;
const long long MOD=1e9+7;

bool tf(int ln, int n,int m, vector<long long>& a, vector<long long>& b, long long k){
    for(int i=ln;i>=0;i--)
        if(i<=m && (ln-i)<=n)
            if((i-1>=0?b[i-1]:0ll)+(ln-i-1>=0?a[ln-i-1]:0ll)<=k) return true;
    return false;
}

void solve(){
    int n,m;
    long long k;
    cin>>n>>m>>k;
    vector<long long> a(n,0),b(m,0);
    for(int i=0;i<n;i++) cin>>a[i];
    for(int i=0;i<m;i++) cin>>b[i];
    int l=0,r=m+n,mid;
    for(int i=0;i<n;i++) a[i]+=(i>0?a[i-1]:0ll);
    for(int i=0;i<m;i++) b[i]+=(i>0?b[i-1]:0ll);
    while(r-l>1){
        mid=(r+l)/2;
        if(tf(mid,n,m,a,b,k)) l=mid;
        else r=mid;
    }
    if(tf(r,n,m,a,b,k)) l=r;
    cout<<l<<"\n";
}

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

    solve();
    return 0;
}

Measured memory_bytes: 6368
#include <algorithm>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
typedef long long ll;
#define all(x) (x).begin(), (x).end()  // sortなどの引数を省略
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define max3(x, y, z) max(x, max(y, z))

#ifdef _MSC_FULL_VER  //デバッグ出力
#define dout cout
#define debug() if (true)
#define check(x) std::cout << "★" << #x << "の値:" << (x) << endl
#define pass(x) std::cout << "☆" << x << endl
#else
#define dout \
  if (false) cout
#define debug() if (false)
#define check(x) \
  if (false) cout << "★" << #x << "の値:" << (x) << endl
#define pass(x) \
  if (false) cout << "☆" << x << endl
#endif
using namespace std;
int main() {
  int a;
  cin >>a;
  string b,c;
  cin >> b >> c;
  for (int i = 0; i < a; i++) {
    cout << b[i] << c[i];
  }
}
/*
//よく使うやつ
int N;
cin >> N;
vector<int> list(N);
for (int i = 0; i < N; i++) {
  cin >> list[i];
}
// for文
for (int i = 0; i < N; i++) {
}
//配列
vector<int> vec;
vec.at(i)
vector<vector<int>> vec(10, vector<int>(10));
sort(all(vec));
sort(all(vec), greater<int>());
    //配列の内容表示
dout << "====vecの内容====\n";
for (int i = 0; i < N; i++) dout << vec[i] << endl;
dout << "====ここまで====\n";
*/


Measured memory_bytes: 256
import java.util.*;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int[] ham = new int[1000001];
		for(int i=1;i<=1000000;i*=3){
			for(int j=1;j*i<=1000000;j*=2){
				for(int k=1;k*j*i<=1000000;k*=5) ham[k*j*i]=1;
			}
		}

		while(true){
			int n = sc.nextInt();
			if(n==0) break;
			int m = sc.nextInt();
			int sum = 0;
			for(int i=n;i<=m;i++){
				if(ham[i]==1) sum++;
			}
			System.out.println(sum);
		}	
	}	
}

Measured memory_bytes: 21784
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <cfloat>
#include <stack>
#include <queue>
#include <vector>
#include <string>
#include <iostream>
#include <set>
#include <map>
#include <time.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;



int main(){

	int year_1,year_2,month_1,month_2,day_1,day_2;
	scanf("%d %d %d",&year_1,&month_1,&day_1);
	scanf("%d %d %d",&year_2,&month_2,&day_2);

	if(month_1 == month_2){

		if(day_1 == day_2){
			printf("%d\n",abs(year_1-year_2));
		}else if(day_1 < day_2){

			if(year_1 < year_2){
				printf("%d\n",abs(year_1-year_2)+1);
			}else if(year_1 == year_2){
				printf("1\n");
			}else{ //year_1 > year_2
				printf("%d\n",abs(year_1-year_2));
			}
		}else{ //day_1 > day_2

			if(year_1 < year_2){
				printf("%d\n",abs(year_1-year_2));
			}else{ //year_1 >= year_2
				printf("%d\n",abs(year_1-year_2)+1);
			}
		}
	}else if(month_1 < month_2){

		if(year_1 <= year_2){
			printf("%d\n",abs(year_1-year_2)+1);
		}else{ //year_1 >= year_2
			printf("%d\n",abs(year_1-year_2));
		}

	}else{ //month_1 > month_2
		if(year_1 < year_2){
			printf("%d\n",abs(year_1-year_2));
		}else{ //year_1 >= year_2
			printf("%d\n",abs(year_1-year_2)+1);
		}
	}

	return 0;
}

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

int main()
{
	string s;
	int a,b;
	
	cin>>a>>b;
	cin>>s;
	
	if(s.size()!=a+b+1)
	{
		cout<<"No"<<endl;
		return 0;
	}
	
	for(int i=0; i<s.size(); i++)
	{
		if(i!=a)
		  {
		  if(!isdigit(s[i]))
		  {
		  	cout<<"No"<<endl;
		  	return 0;
		  }
	      }
		  else
		  {
		  	if(s[i]!='-')
		  	{
		  		cout<<"No"<<endl;
		  		return 0;
		  	}
		  }
	}
	
	cout<<"Yes"<<endl;
	return 0;
}

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

#define int long long
#define itn int
#define For(i, a, b) for (int i = (a); i <= static_cast<int>(b); i++)
#define Forr(i, a, b) for (int i = (a); i >= static_cast<int>(b); i--)
#define rep(i, n) For(i, 0, n - 1)
#define repall(i, arr) for (auto& i : (arr))
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define dump(x) cerr << #x << " = " << (x) << '\n'
#define dump2(x, y) \
    cerr << #x << " = " << (x) << " " << #y << " = " << (y) << '\n'
#define SZ(x) ((int)(x).size())
#define bit(n) (1LL << (n))
constexpr int MOD = 1e9 + 7;

// clang-format off
template<typename T>
bool chmax(T& a, const T& b) {if (a<b){a=b;return true;}return false;}
template<typename T>
bool chmin(T& a, const T& b) {if (a>b){a=b;return true;}return false;}
// clang-format on

template <typename T>
using pq = priority_queue<T>;
template <typename T>
using pqr = priority_queue<T, vector<T>, greater<T>>;
const int INF = LLONG_MAX / 2;
using P = pair<int, int>;
using vec = vector<int>;
using mat = vector<vec>;

template <typename T1, typename T2>
ostream& operator<<(ostream& stream, const pair<T1, T2>& p) {
    return stream << p.first << " " << p.second;
}
template <typename T>
void print(const vector<T> vec) {
    unsigned int len = vec.size();
    rep (i, len - 1)
        cout << vec[i] << ' ';
    cout << vec[len - 1] << '\n';
}
template <typename Arg>
void print(const Arg arg) {
    cout << arg << '\n';
}
template <typename Head, typename... Args>
void print(const Head head, const Args... args) {
    cout << head << " ";
    print(args...);
}
template <typename T>
T sum_(vector<T> vec, T init = 0) {
    return std::accumulate(all(vec), T(init));
}

void yn(bool tf) { print(tf ? "Yes" : "No"); }
void YN(bool tf) { print(tf ? "YES" : "NO"); }

template <typename T>
void init(vector<T>& v) {
    rep (i, v.size())
        cin >> v[i];
}

template <typename T, typename U>
void init(vector<T>& v, vector<U>& w) {
    assert(v.size() == w.size());
    rep (i, v.size())
        cin >> v[i] >> w[i];
}

int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }

// -------------------------------------------------------------------
// sort 1 2 3 4
// pqr 1 2 3 must impl >

signed main() {
    cin.tie(0), cout.tie(0), ios::sync_with_stdio(false);
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    yn(abs(a - c) <= d or (abs(a - b) <= d and abs(b - c) <= d));

    return 0;
}


Measured memory_bytes: 256
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
#define INF 100000000
#define rep(i,s,n) for (int i = (int)(s); i < (int)(n); i++)
ll mod = 1000000007;

int main(){
    string s;cin>>s;
    string x = to_string(s[0]);
    vector<string> a;
    int ans = 1;
    int cnt = 1;
    while (cnt<s.size()){
       if (x==to_string(s[cnt])){
           if (cnt+2<s.size()) {
               x = to_string(s[cnt+2]);
               ans+=2;
           }else if(cnt+2==s.size()) ans++;
           cnt+=3;
       }else{
           x = to_string(s[cnt]);
           cnt++;
           ans++;
       }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 640
#include <iostream>
using namespace std;
#define MAX_N 123456
bool is_prime[2*MAX_N+1];
int acc[2*MAX_N+1];
void init() {
    is_prime[0] = false;
    is_prime[1] = false;
    for (int i = 2; i < 2*MAX_N+1; ++i) {
        is_prime[i] = true;
    }
    for (int i = 2; i < 2*MAX_N+1; ++i) {
        if (is_prime[i]) {
            for (int j = 2*i; j < 2*MAX_N+1; j += i) {
                is_prime[j] = false;
            }
        }
    }
    acc[0] = 0;
    for (int i = 1; i < 2*MAX_N+1; ++i) {
        acc[i] = acc[i-1];
        if (is_prime[i]) acc[i] += 1;
    }
}
int solve(int n) {
    return acc[2*n] - acc[n];
}
int main() {
    init();
    while (true) {
        int n; cin >> n;
        if (not n) break;
        cout << solve(n) << endl;
    }
    return 0;
}

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


int main() {
    int n,m;
    cin>>n>>m;
    int s[m], c[m];

    rep(i,m) cin>>s[i]>>c[i];

    rep(i,1000){
        string a = to_string(i);
        bool flag = false;
        if(a.size() == n){
            flag = true;
            rep(j,m){
                if(a[s[j]-1] != '0'+c[j]) flag = false;
            }
        }
        if(flag == true){
            cout<<i<<endl;
            return 0;
        }
    }
    cout<<-1<<endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define fbo find_by_order
#define ook order_of_key

typedef long long ll;
typedef pair<ll,ll> ii;
typedef vector<ll> vi;
typedef long double ld; 
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;
typedef set<int>::iterator sit;
typedef map<int,int>::iterator mit;
typedef vector<int>::iterator vit;

int main()
{
	ios_base::sync_with_stdio(0); cin.tie(0);
	ll a,b,c;
	cin>>a>>b>>c;
	for(ll i = 0; i < 10000000; i++)
	{
		if((a&1)||(b&1)||(c&1))
		{
			cout<<i<<'\n';
			return 0;
		}
		else
		{
			ll a2 = (b+c)>>1;
			ll b2 = (a+c)>>1;
			ll c2 = (a+b)>>1;
			a=a2;b=b2;c=c2;
		}
	}
	cout<<-1<<'\n';
}


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

using ll = long long;
using ull = unsigned long long;
using st = string;
using db = double;
using vll = vector<long long>;
using vvll = vector<vll>;
using vst = vector<st>;
using vchar = vector<char>;
#define rep(i, m, n) for (int i = (int)(m); i < (int)(n); i++)
#define vrep(i, vec) for(auto& i : vec)
#define vin(vec) for(auto& i : vec) cin >> i
#define all(v) v.begin(), v.end()
ll mod = 1000000007;


int main(){
  ll n;
  cin >> n;
  vll a1(n), a2(n);
  vin(a1);
  vin(a2);

  vll sum1(n), sum2(n);
  rep(i, 0, n){
    sum1.at(i) = accumulate(a1.begin(), a1.begin() + i + 1, 0);
    sum2.at(i) = accumulate(a2.begin(), a2.begin() + i + 1, 0);
  }
  ll ans = sum1.at(0) + sum2.at(n - 1);
  rep(i, 1, n){
    ll candy = sum1.at(i) + sum2.at(n - 1) - sum2.at(i - 1);
    if(ans < candy) ans = candy;
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
use proconio::input;
#[allow(unused_imports)]
use proconio::marker::{Bytes, Chars};
#[allow(unused_imports)]
use std::cmp::{min, max};

fn main() {
	input! {
		n: usize,
		k: usize,
	}

	let mut num = 1;
	for _i in 0..n {
		let a1 = num * 2;
		let a2 = num + k;
		num = min(a1, a2);
	}
	println!("{}", num);
}



Measured memory_bytes: 2108
#pragma region header
#include <bits/stdc++.h>
using namespace std;

#define CPP_CAT(x,y) CPP_CAT_I(x,y)
#define CPP_CAT_I(x,y) x ## y
//#define CPP_STR(x) CPP_STR_I(x)
//#define CPP_STR_I(args...) #args
//#define ASSERT(expr...) assert((expr))

using i8 = int8_t;
using u8 = uint8_t;
using i16 = int16_t;
using u16 = uint16_t;
using i32 = int32_t;
using u32 = uint32_t;
using i64 = int64_t;
using u64 = uint64_t;
using f32 = float;
using f64 = double;
//using f80 = __float80;

constexpr i64 INF = 1'010'000'000'000'000'017LL;
constexpr i64 MOD = 1'000'000'007LL;
constexpr f64 EPS = 1e-12;
constexpr f64 PI = 3.14159265358979323846;
constexpr char EL[] = "\n";

#define FOR(i, start, end) for(i64 i = (start), CPP_CAT(i,xxxx_end)=(end); i < CPP_CAT(i,xxxx_end); ++i)
#define REP(i, n) FOR(i, 0, n)
#define all(x) (x).begin(),(x).end()
#define ALL(f,c,...) (([&](decltype((c)) cccc) { return (f)(std::begin(cccc), std::end(cccc), ## __VA_ARGS__); })(c))
#define UNIQUE(x) (x).erase(unique(all(x)), (x).end());
#define REPIT(x) for(auto it=(x).begin(), end=(x).end(); it!=end; ++it)
#define perm(c) sort(all(c)); for(bool c##p=1;c##p;c##p=next_permutation(all(c)))

template<typename T = i64>
T IN() { T x; cin >> x; return (x); }

template<typename C>
i64 SIZE(const C& c) { return static_cast<i64>(c.size()); }
template<typename T, size_t N>
i64 SIZE(const T(&)[N]) { return static_cast<i64>(N); }

template<typename T, typename U, typename Comp = less<>>
bool chmax(T& xmax, const U& x, Comp comp = {}) {
	if (comp(xmax, x)) {
		xmax = x;
		return true;
	}
	return false;
}
template<typename T, typename U, typename Comp = less<>>
bool chmin(T& xmin, const U& x, Comp comp = {}) {
	if (comp(x, xmin)) {
		xmin = x;
		return true;
	}
	return false;
}

void print() {
  cout << EL;
}
template <class Head, class... Tail>
void print(Head&& head, Tail&&... tail) {
  cout << head;
  if (sizeof...(tail) != 0) cout << " ";
  print(forward<Tail>(tail)...);
}
template <class T>
void print(vector<T> &vec) {
  for (auto& a : vec) {
	cout << a;
	if (&a != &vec.back()) cout << " ";
  }
  cout << EL;
}
template <class T>
void print(vector<vector<T>> &df) {
  for (auto& vec : df) {
	print(vec);
  }
}

struct ProconInit {
	static constexpr int IOS_PREC = 15;
	static constexpr bool AUTOFLUSH = false;

	ProconInit() {
		cin.tie(nullptr);
		ios::sync_with_stdio(false);
		cout << fixed << setprecision(IOS_PREC);
		if (AUTOFLUSH)
			cout << unitbuf;
	}
} PROCON_INIT;
#pragma endregion

signed solve()
{
	int n, k;
	cin >> n >> k;
	int ans = 0;
	REP(i, n)
	{
		int h;
		cin >> h;
		if (h >= k)
			ans++;
	}
	print(ans);
	return 0;
}

#ifndef LOCALCODE
signed main()
{
	return solve();
}
#endif


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define endl '\n'
using namespace std;
const int INF=10000007;
vector<ll>adj[INF];
vector<ll>dis;
vector<ll>visited;
vector<ll>sorted;
void toposort(ll b)
{
    ll i;
    for(i=0;i<adj[b].size();i++)
    {
        if(visited[adj[b][i]]==1)continue;
        visited[adj[b][i]]=1;
        toposort(adj[b][i]);
    }
    sorted.push_back(b);
}
void dfs(ll b)
{
    ll i;
    for(i=0;i<adj[b].size();i++)
    {
        if(dis[b]+1>dis[adj[b][i]])
        {dis[adj[b][i]]=dis[b]+1;}
        toposort(adj[b][i]);
    }
}
int main()
{
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ll n,m,i,j,x,y;
  cin>>n>>m;
  visited.assign(n,0);
  dis.assign(n,0);
  for(i=0;i<m;i++)
  {
      cin>>x>>y;
      adj[x-1].push_back(y-1);
  }
  for(i=0;i<n;i++)
  {
      if(visited[i]!=1)
      {visited[i]=1;toposort(i);}   
  }
  visited.assign(n,0);
  for(i=n-1;i>=0;i--)
  {
      dfs(sorted[i]);
  }
  cout<<*max_element(dis.begin(),dis.end())<<endl;

}

Measured memory_bytes: 251072
lines = readlines
len = lines[0].to_i
i = 1
flag = 0
count = 0
result = []

while i <= len
  line = lines[i].chomp.split(' ')
  res = line[0] == line[1]
  if res
    count = count + 1
  else
    count = 0
  end
  if count == 3
    puts "Yes"
    flag = 1
  end
  i += 1
end

if flag == 0
  puts "No"
end

Measured memory_bytes: 14280
package main

import (
  "fmt"
)

func sumInt(a ...int) int {s := 0; for _, v := range a {s += v}; return s}

func main() {
  var n int 
  fmt.Scan(&n)
  t := make([]int, n)
  for i := 0; i < n; i++ {
    fmt.Scan(&t[i])
  }
  tot := sumInt(t...)
  var m int 
  fmt.Scan(&m)
  for i := 0; i < m; i++ {
    var p, x int 
    fmt.Scan(&p, &x)
    fmt.Println(tot + (x - t[p-1]))
  }
  
}

Measured memory_bytes: 512
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<cassert>
#include<iterator>
#include<complex>
#include<stack>
using namespace std;
typedef  long long int lint;
typedef pair<int, int> P;
typedef pair<lint, lint> LLP;
typedef pair<char, char>CP;
#define rep(i, n) for (int i = 0; i < n; i++)
#define repr(i, n) for (int i = n; i >= 0; i--)
#define sort(v) sort((v).begin(), (v).end())
#define reverse(v) reverse((v).begin(), (v).end())
#define upper(v,hoge) upper_bound(v.begin(),v.end(),hoge)
#define lower(v,hoge) lower_bound(v.begin(),v.end(),hoge)
/*
vector<char>al(26);
al = {'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'};
vector<char>AL(26);
AL = {'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'};
vector<char>NUM(10);
	NUM = { '0','1','2' ,'3' ,'4' ,'5' ,'6' ,'7' ,'8' ,'9' };
*/



int main() {
	int N;
	cin >> N;
	int I;
	int K;
	vector<vector<int>>V(N, vector<int>(N));
	rep(i, N) {
		cin >> I >> K;
		rep(j, K) {
			cin >> V[i][j];
		}
	}
	vector<vector<int>>A(N, vector<int>(N));
	rep(i, N) {
		rep(j, N) {
			if (V[i][j] != 0) {
				A[i][V[i][j] - 1]++;
			}
		}
	}
	rep(i, N) {
		rep(j, N) {
			if (j < N - 1) {
				cout << A[i][j] << ' ';
			}
			else {
				cout << A[i][j];
			}
		}
		cout << endl;
	}
}





Measured memory_bytes: 3168
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int mod=1e9+7;

int n,m;
int a[2005],b[2005],dp[2005][2005];

signed main()
{
	cin>>n>>m;
	for (int i=1;i<=n;i++)  cin>>a[i];
	for (int i=1;i<=m;i++)  cin>>b[i];
	
	for (int i=0;i<=m;i++)  dp[0][i]=1;
	for (int i=0;i<=n;i++)  dp[i][0]=1;	
	
	for (int i=1;i<=n;i++)
	{
		for (int j=1;j<=m;j++)
		{
			if (i+j==0)  continue;
			else
			{
				dp[i][j]=((dp[i-1][j]+dp[i][j-1]-dp[i-1][j-1])%mod+mod)%mod;
				if (a[i]==b[j])  dp[i][j]=(dp[i][j]+dp[i-1][j-1])%mod;
			}
		}
	}
	cout<<dp[n][m]<<endl;
	
	return 0;
}

Measured memory_bytes: 31616
#include <bits/stdc++.h>
#define rep(i, n) for (int i=0; i<(int)(n); i++)
using namespace std;
using ll = long long;
using Graph = vector<vector<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;}
/*
void chmin(ll a, ll b){if (a>b){a = b; return true;}return false;}
void chmax(ll a, ll b){if (a<b){a = b; return true;}return false;}
*/

const ll MOD = 1000000007;
const ll INF = 9999999999;

int main() {
  int H,W; cin >>H >>W;
  vector<vector<int>> a(H, vector<int>(W,0));
  for (int i=0; i<H; i++){
    for (int j=0; j<W; j++){
      cin >>a[i][j];
    }
  }
  int K = 0;
  for (int i=0; i<H; i++){
    for (int j=0; j<W; j++){
      int buf; cin >>buf;
      a[i][j] -= buf;
      a[i][j] = abs(a[i][j]);
      K = max(K, a[i][j]);
    }
  }
  K *= H + W - 1;
  vector<vector<vector<bool>>> dp(H, vector<vector<bool>>(W, vector<bool>(K, false)));
  // dp[i][j][k]...(i,j)において偏りkでいけるか？
  dp[0][0][a[0][0]] = true;

  for (int i=0; i<H; i++){
    for (int j=0; j<W; j++){
      for (int k=0; k<K; k++){
        if (!dp[i][j][k]) continue;
        if (i<H-1){
          dp[i+1][j][k + a[i+1][j]] = true;
          dp[i+1][j][abs(k-a[i+1][j])] = true;
        }
        if (j<W-1){
          dp[i][j+1][k + a[i][j+1]] = true;
          dp[i][j+1][abs(k-a[i][j+1])] = true;
        }
      }
    }
  }

  int ans = 0;
  for (int k=0; k<K; k++){
    if (dp[H-1][W-1][k]){
      ans = k; break;
    }
  }
  cout <<ans <<endl;
  
}

Measured memory_bytes: 10752
S = list(input())
step = 0
ans = 0
for i, s in enumerate(reversed(S)):
    if s == 'W':
        step += 1
    if s == 'B':
        if step != 0:
            S[-(i-step)-1] = 'B'
            S[-i-1] = 'W'
            ans += step
print(ans)

Measured memory_bytes: 4840
n = int(input())
l = []
for i in range(n):
    s, p = map(str, input().split())
    l.append([s, int(p), i+1])
#print(l)

l = sorted(l, reverse=True, key=lambda x:x[1])
#name -> dneed reverse
l = sorted(l, key=lambda x:x[0])

for i in range(n):
    print(l[i][-1])


Measured memory_bytes: 3060
/////////////////////////////////////////////////////////////////////////
#include<bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define lint long long
#define ll long long
#define pq priority_queue
#define mp make_pair
#define pb push_back
#define vl vector<long long>
#define pii pair<long long,long long>
#define all(x) (x).begin(),(x).end()
#define rep(x) for(int i = 0;i < (x);i++)
#define repj(x) for(int j = 0;j < (x);j++)
#define REP(i,x) for(int (i) = 0;(i) < (x);(i)++)
#define rrep(x) for(int i = (x);i >= 0;i--)
#define mod 1000000007
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
#define uniq(x) (x).erase(unique(all(x)),(x).end())
int qp(int a, ll b) { int ans = 1; do { if (b & 1)ans = 1ll * ans*a; a = 1ll * a*a; } while (b >>= 1); return ans; }
int qp(int a, ll b, int mo) { int ans = 1; do { if (b & 1)ans = 1ll * ans*a%mo; a = 1ll * a*a%mo; } while (b >>= 1); return ans; }
int gcd(int a, int b) { return b ? gcd(b, a%b) : a; }
////////////////////////////// define /////////////////////////////////
int dx[4] = { 1,0,-1,0 };
int dy[4] = { 0,1,0,-1 };
long long INF = 1e16;
//const int MAX_N = 200001;

int main() {
	string s; cin >> s;
	int n = s.size();
	int k; cin >> k;
	vector<string> a;
	
	for(int length = 1;length <= k;length++){
		for(int start = 0;start <= n - length;start++){
			string t = "";
			for(int pick = start;pick < start + length;pick++) t += s[pick];
		    a.pb(t);
		   //debug(t);
		}
	}
	sort(all(a));
	//for(int i = 0;i < 10;i++) cout << a[i] << endl;
	k--;
	int j = 0;
	while(true){
		if((k == 0 && j == 0)||(k == 0 && a[j] != a[j-1])){ cout << a[j] << endl; return 0;}
		else if(j != 0 && a[j] == a[j-1]){j++; continue;}
		else{j++; k--; continue;}
	}
	
}


Measured memory_bytes: 1660
url = "https://atcoder.jp//contests/abc158/tasks/abc158_b"

def main():
    a, blue, red = list(map(int, input().split()))
    count, ab_count = divmod(a, blue + red)
    if ab_count > blue:
        ab_count = blue
    print(ab_count + count * blue)

if __name__ == '__main__':
    main()




Measured memory_bytes: 2940
use std::collections::VecDeque;

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")
    };
}

fn main() {
    input! {
        h: i32, w: i32,
        s: [chars; h]
    }
    let white: i32 = s
        .iter()
        .map(|v| v.iter().filter(|c| **c == '.').count() as i32)
        .sum();
    let mut way: Vec<Vec<i32>> = s.iter().map(|v| v.iter().map(|_| -1).collect()).collect();
    let wall: Vec<Vec<bool>> = s
        .into_iter()
        .map(|v| v.into_iter().map(|c| c == '#').collect())
        .collect();
    let mut queue: VecDeque<(i32, i32)> = VecDeque::new();
    let mut ans = -1;

    way[0][0] = 0;
    queue.push_back((0, 0));

    'looper: while !queue.is_empty() {
        let (px, py) = queue.pop_front().unwrap();
        let count = way[py as usize][px as usize];
        for (dx, dy) in vec![(1, 0), (0, 1), (-1, 0), (0, -1)] {
            let nx = px + dx;
            let ny = py + dy;
            if nx < 0 || nx >= w || ny < 0 || ny >= h {
                continue;
            }
            if nx == w - 1 && ny == h - 1 {
                ans = count + 1;
                break 'looper;
            }
            let nx = nx as usize;
            let ny = ny as usize;
            if wall[ny][nx] || way[ny][nx] != -1 {
                continue;
            }
            way[ny][nx] = count + 1;
            queue.push_back((nx as i32, ny as i32));
        }
    }

    println!("{}", if ans == -1 { -1 } else { white - ans - 1 });
}


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

#define rep(ver,n) rep2(ver,0,n)
#define rep2(ver,m,n) for(int ver=m;ver<(n);ver++)
#define loop while(true)
#define dup(x,y) (((x)+(y)-1)/(y))
#define all(v) (v).begin(), (v).end()
#define debug(x) std::cerr<<#x<<": "<<x<<"\n"
#define debug2(x,y) std::cerr<<#x<<": "<<x<<", "<<#y<<": "<<y<<"\n"
#define debug3(x,y,z) std::cerr<<#x<<": "<<x<<", "<<#y<<": "<<y<<", "<<#z<<": "<<z<<"\n"

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

int main(){
  int h=0,w=0,k=0;
  scanf("%d %d %d",&h,&w,&k);
  char mas[10][10];
  for(int i=0;i<h;i++){
    scanf("%s",&mas[i]);
  }
  
  int rep=1<<(h+w);
  
  int ans=0;
  
  for(int i=0;i<rep;i++){
    int sum=0;
    for(int h1=0;h1<h;h1++){
      for(int w1=0;w1<w;w1++){
        if(((i&(1<<(h1)))!=0)||((i&(1<<(w1+h)))!=0)){}
        else{
          if(mas[h1][w1]=='#')sum++;
        }
      }
    }
    
    if(sum==k)ans++;
  }
  
  printf("%d",ans);
  
  return 0;
}


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

int main()
{
	int n;
	cin >> n;
	while(n>0)
	{
		n -= 1000;
	}
	cout << abs(n);

	//////////////////////////////////
	//--------end--------
	//
	return 0;
}


Measured memory_bytes: 3628
import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class Main {

	FastScanner in;
	PrintWriter out;

	void solve() {
		int n = in.nextInt();

		String s = in.next();

		int answer = 1;
		for (int i = 0; i < s.length() - 1; i++) {
			if (s.charAt(i) != s.charAt(i + 1)) {
				answer++;
			}
		}

		out.println(answer);
	}

	void run() {
		try {
			in = new FastScanner(new File("Main.in"));
			out = new PrintWriter(new File("Main.out"));

			solve();

			out.close();
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		}
	}

	void runIO() {

		in = new FastScanner(System.in);
		out = new PrintWriter(System.out);

		solve();

		out.close();
	}

	class FastScanner {
		BufferedReader br;
		StringTokenizer st;

		public FastScanner(File f) {
			try {
				br = new BufferedReader(new FileReader(f));
			} catch (FileNotFoundException e) {
				e.printStackTrace();
			}
		}

		public FastScanner(InputStream f) {
			br = new BufferedReader(new InputStreamReader(f));
		}

		String next() {
			while (st == null || !st.hasMoreTokens()) {
				String s = null;
				try {
					s = br.readLine();
				} catch (IOException e) {
					e.printStackTrace();
				}
				if (s == null)
					return null;
				st = new StringTokenizer(s);
			}
			return st.nextToken();
		}

		boolean hasMoreTokens() {
			while (st == null || !st.hasMoreTokens()) {
				String s = null;
				try {
					s = br.readLine();
				} catch (IOException e) {
					e.printStackTrace();
				}
				if (s == null)
					return false;
				st = new StringTokenizer(s);
			}
			return true;
		}

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

		long nextLong() {
			return Long.parseLong(next());
		}

		double nextDouble() {
			return Double.parseDouble(next());
		}
	}

	public static void main(String[] args) {
		new Main().runIO();
	}
}


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

int main() {
    int N, K;
    cin >> N >> K;

    int l[60];
    for(int i = 0; i < N; i++) {
        cin >> l[i];
    }
    sort(l,l+N);
    reverse(l, l+N);
    int sum = 0;
    for(int i = 0; i < K; i++) {
        sum += l[i];
    }
    cout << sum << endl;
}

Measured memory_bytes: 3632
#include <iostream>
#include <cstdio>
#include <cctype>
#include <cstring>
#include <cmath>
#include <cstdarg>
#include <cstdlib>
#include <string>
#include <tuple>
#include <queue>
#include <algorithm>
using namespace std;

typedef pair<int, int> P;

int main(int argc, char const *argv[])
{
    int h, w;
    cin >> h >> w;

    int INF = h*w + 1;

    string s[h];
    int tmp[h][w];
    for (int i = 0; i < h; i ++) {
        cin >> s[i];
        for (int j = 0; j < w; j ++) {
            if (s[i][j] == '.') {
                tmp[i][j] = INF;
            } else {
                tmp[i][j] = 0;
            }
        }
    }

    queue<P> que;
    int x, y, nx, ny;
    P coor;
    int res = 0;

    for (int i = 0; i < h; i ++) {
        for (int j = 0; j < w; j ++) {
            if (s[i][j] == '#') {
                que.push(make_pair(i, j));
            }
        }
    }
    
    // bfs を黒ますスタート白ます辿りで行う
    while(!que.empty()) {
        coor = que.front();
        que.pop();
        x = coor.first;
        y = coor.second;

        for (int dx = -1; dx < 2; dx ++) {
            for (int dy = -1; dy < 2; dy ++) {
                if (dx * dy != 0 || dx == dy) {
                    continue;
                }
                nx = x + dx;
                ny = y + dy;
                if (
                    0 <= nx && nx < h &&
                    0 <= ny && ny < w &&
                    s[nx][ny] == '.' &&
                    tmp[x][y] + 1 < tmp[nx][ny]
                ) {
                    tmp[nx][ny] = tmp[x][y] + 1;
                    que.push(make_pair(nx, ny));
                }
            }
        }
    }

    for (int i = 0; i < h; i ++) {
        for (int j = 0; j < w; j ++) {
            if (tmp[i][j] > res) {
                res = tmp[i][j];
            }
        }
    }
    cout << res << endl;
    return 0;
}


Measured memory_bytes: 13456
#include <stdio.h>

int main()
{
	int a, b, c;
	int k;
	int n;

	scanf("%d%d%d", &a, &b, &c);
	n = 0;
	for (k = a; k <= b; k++) {
		if (c % k == 0) n++;
	}
	printf("%d\n", n);
	return 0;
}


Measured memory_bytes: 2112
#include<cstdio>
#include<cstring>
#include<vector>
#include<queue>
#include<algorithm>
#include<cmath>
#include<climits>
#include<string>
#include<set>
#include<numeric>
#include<map>
#include<iostream>
using namespace std;
#define rep(i,n) for(int i = 0;i<((int)(n));i++)
#define reg(i,a,b) for(int i = ((int)(a));i<=((int)(b));i++)
#define irep(i,n) for(int i = ((int)(n)-1);i>=0;i--)
#define ireg(i,a,b) for(int i = ((int)(b));i>=((int)(a));i--)
typedef long long ll;
typedef pair<ll, ll> mp;

int main(void){
	int X,Y;
	cin>>X>>Y;
	if(X%Y==0){
		printf("-1\n");
	}else{
		printf("%d\n",X);
	}
	return 0;
}

Measured memory_bytes: 256
N = int(input())
ans = 0

for i in range(2, int(N ** 0.5) + 1):
    if N % i == 0:
        m1 = i - 1
        m2 = N // i - 1
        if N // m1 == N % m1:
            ans += m1
        elif m1 != m2 and N // m2 == N % m2:
            ans += m2

ans += N - 1
if N == 2:
    ans = 0

print(ans)


Measured memory_bytes: 3060
#include<iostream>
#include<cstdio>
#include<vector>
#include<map>
#include<string>
#include<algorithm>
#include<math.h>
#include<numeric>
#include<iomanip>

using namespace std;

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

const ll INF = 1e9;
const ll MOD = 1e9 + 7;

ll dp[51][51][2501];

int main(){
	int N, A;
	cin >> N >> A;
	vi X;
	int i, j, k;
	X.push_back(0);
	for (i = 0; i < N; i++){
		int x;
		cin >> x;
		X.push_back(x);
	}
	int xsum = accumulate(X.begin(), X.end(), 0);
	for (i = 0; i <= N; i++){
		for (j = 0; j <= N; j++){
			for (k = 0; k <= xsum; k++){
				dp[i][j][k] = 0;
			}
		}
	}
	for (i = 0; i <= N; i++){
		dp[i][0][0] = 1;
	}
	dp[1][1][X[1]] = 1;
	for (i = 2; i <= N; i++){
		for (j = 1; j <= i; j++){
			for (k = 1; k <= xsum; k++){
				if (k >= X[i]){
					dp[i][j][k] = dp[i - 1][j][k] + dp[i - 1][j - 1][k - X[i]];
				}
				else{
					dp[i][j][k] = dp[i - 1][j][k];
				}
			}
		}
	}
	ll ans = 0;
	for (j = 1; j <= N; j++){
		ans += dp[N][j][A*j];
	}
	cout << ans << endl;
}

Measured memory_bytes: 51072
/*
  GOOD is not Enough
  You've got to be GREAT.
*/
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
// #include<boost/multiprecision/cpp_int.hpp>
// using namespace boost::multiprecision;
using namespace __gnu_pbds;
using namespace std;
#define int long long
#define mod 1000000007
#define FAST ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define f(i,n) for(int i=0;i<n;i++)
#define fp(i,k,n) for(int i=k;i<=n;i++)
#define fr(i,k,n) for(int i=k;i>=n;i--)
#define pb push_back
#define pii pair<int,int>
#define dbg(x) cout << (#x) << " is " << (x) << '\n' 
#define F first
#define S second
#define sz(x) (int)(x).size()
#define lb lower_bound
#define ub upper_bound
#define all(a) a.begin(),a.end()
typedef tree<int,null_type,less_equal<int>,rb_tree_tag,tree_order_statistics_node_update>ordered_set;

void solve()
{
   string s;
   cin >> s;
   f(i,s.length())
   if(s[i]=='?')
    s[i]='D';
    cout << s << '\n';
    return;
} 

signed main()
{
  FAST
  int T=1;
//   cin >> T;
  while(T--)
  {
    solve();
  }
  return 0;
}

Measured memory_bytes: 3772
#include<stdio.h>
#include<string.h>
int main(void)
{
	char s[100];
	int i,len,cnt;
	scanf("%s",s);
	len=strlen(s);
	for(i=2;i<len;i++)	cnt++;
	printf("%c",s[0]);
	printf("%d",cnt);
	printf("%c",s[cnt+1]);
	return 0;
}


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

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

int main() {
  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

  string s, t;
  cin >> s >> t;
  int ans = 0;
  for(int i = 0; i < (int)s.length(); i++) {
    if(s[i] != t[i])
      ans++;
  }
  cout << ans << '\n';

  return 0;
}


Measured memory_bytes: 3792
#include <stdio.h>
int main(int argc, char const *argv[]){
	char a,b;
	int c;
	a=getchar();
	getchar();
	b=getchar();
	c=b-a;
	if(c>0)
		printf("<");
	else if(c==0)
		printf("=");
	else if(c<0)
		printf(">");
	return 0;
}

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

int main() {
  int a, b;
  
  cin >> a >> b;
  
  int X = a*b%2;

  if (X==1) {
    cout << "Odd" << endl;
  }
  else{
    cout << "Even" <<endl;
  }
  
}


Measured memory_bytes: 256
n, a, b, c, d = map(lambda x: int(x)-1, input().split())
s = input()


def can_reach(x, y):
    return 0 == s[x:y+1].count('##')


def can_reach_cross(x, y, a, b):
    t = s[x:y+1]
    if 0 != t.count('##'):
        return False
    if '...' in s[a-1:b+2]:
        return True
    return False


if c < d:
    # parallel
    if can_reach(a, c) and can_reach(b, d):
        print('Yes')
    else:
        print('No')
else:
    # cross
    if can_reach(b, d) and can_reach_cross(a, c, b, d):
        print('Yes')
    else:
        print('No')


Measured memory_bytes: 9444
import java.util.*;
public class Main {
	int INF = 1 << 24;
	int [] vx = {0,1,0,-1};
	int [] vy = {1,0,-1,0};
	int w, h;
	
	class C implements Comparable<C>{
		int x, y, cx, cy, step;
		public C(int nowx, int nowy, int cx, int cy, int step) {
			this.x = nowx;
			this.y = nowy;
			this.cx = cx;
			this.cy = cy;
			this.step = step;
		}
		@Override
		public String toString() {
			return "C [x=" + x + ", y=" + y + ", cx=" + cx + ", cy=" + cy
					+ ", step=" + step + "]";
		}
		@Override
		public int compareTo(C o) {
			if(this.step < o.step) return -1;
			if(this.step > o.step) return 1;
			return 0;
		}
		
	}
	
	private void doit(){
		Scanner sc = new Scanner(System.in);
		while(true){
			w = sc.nextInt();
			h = sc.nextInt();
			if((w|h) == 0) break;
			int [][] map = new int[h][w];
			int sx = -1, sy = -1, cx = -1, cy = -1;
			for(int i = 0; i < h; i++){
				for(int j = 0; j < w; j++){
					int input = sc.nextInt();
					if(input == 4){
						map[i][j] = 0;
						sx = j;
						sy = i;
					}
					else if(input == 2){
						map[i][j] = 0;
						cx = j;
						cy = i;
					}
					else{
						map[i][j] = input;
					}
				}
			}
			
			PriorityQueue<C> open = new PriorityQueue<C>();
			open.add(new C(sx, sy, cx, cy, 0));
			boolean [][][][] close = new boolean[h][w][h][w];
			close[sy][sx][cy][cx] = true;
			int ans = INF;
			
			while(! open.isEmpty()){
				C now = open.poll();
				
				for(int i = 0; i < 4; i++){
					int nextx = now.x + vx[i];
					int nexty = now.y + vy[i];
					if(isOUT(nextx, nexty)) continue;
					if(map[nexty][nextx] == 1) continue;
					
					if(nexty == now.cy && nextx == now.cx){
						int xx = nextx + vx[i];
						int yy = nexty + vy[i];
						if(isOUT(xx, yy)) continue;
						if(map[yy][xx] == 1) continue;
						
						if(map[yy][xx] == 3){
							ans = now.step + 1;
							continue;
						}
						if(close[nexty][nextx][yy][xx]) continue;
						close[nexty][nextx][yy][xx] = true;
						C next = new C(nextx, nexty, xx, yy, now.step + 1);
						open.add(next);
					}
					else{
						int xx = now.cx;
						int yy = now.cy;
						if(close[nexty][nextx][yy][xx]) continue;
						close[nexty][nextx][yy][xx] = true;
						C next = new C(nextx, nexty, now.cx, now.cy, now.step);
						open.add(next);
					}
				}
			}
			System.out.println(ans == INF ? -1 : ans);
		}
	}
	
	private boolean isOUT(int nextx, int nexty) {
		if(0 <= nextx && nextx < w && 0 <= nexty && nexty < h){
			return false;
		}
		return true;
	}

	public static void main(String[] args) {
		Main obj = new Main();
		obj.doit();
	}
}

Measured memory_bytes: 12000
X, N = map(int, input().split())
p = list(map(lambda x:int(x) - X, input().split()))

ans = X
for i in range(100):
    flag1 = -i in p
    if flag1 == False:
        ans = X - i
        break
    flag2 = i in p
    if flag2 == False:
        ans = X + i
        break

print(ans)
    










Measured memory_bytes: 9112