akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>

int memo_v[3000][3000] = {0};
int memo_h[3000][3000] = {0};

// int f2(std::vector<std::string>& s, int y, int x) {
//     if (s[y][x] == '#') {
//         return 0;
//     }
//     int v = 0;
//     int i = 1;
//     while (y + i < s.size() && s[y + i][x] != '#') {
//         v++;
//         i++;
//     }
//     i = 1;
//     while (y - i >= 0 && s[y - i][x] != '#') {
//         v++;
//         i++;
//     }
//     int h = 0;
//     i = 1;
//     while (x + i < s[y].size() && s[y][x + i] != '#') {
//         h++;
//         i++;
//     }
//     i = 1;
//     while (x - i >= 0 && s[y][x - i] != '#') {
//         h++;
//         i++;
//     }
//     return v + h + 1;
// }

void f2(std::vector<std::string>& s, int y, int x) {
    if (s[y][x] == '#') {
        return;
    }
    if (memo_v[y][x] > 0) {
        return;
    }

    // count vertically
    int cnt = 0;
    int i = 1;
    while (y + i < s.size() && s[y + i][x] != '#') {
        cnt++;
        i++;
    }
    i = 1;
    while (y - i >= 0 && s[y - i][x] != '#') {
        cnt++;
        i++;
    }

    // memoize
    i = 0;
    while (y + i < s.size() && s[y + i][x] != '#') {
        memo_v[y + i][x] = cnt;
        i++;
    }
    i = 0;
    while (y - i >= 0 && s[y - i][x] != '#') {
        memo_v[y - i][x] = cnt;
        i++;
    }    
}

void f3(std::vector<std::string>& s, int y, int x) {
    if (s[y][x] == '#') {
        return;
    }
    if (memo_h[y][x] > 0) {
        return;
    }

    // count horizontally
    int cnt = 0;
    int i = 1;
    while (x + i < s[y].size() && s[y][x + i] != '#') {
        cnt++;
        i++;
    }
    i = 1;
    while (x - i >= 0 && s[y][x - i] != '#') {
        cnt++;
        i++;
    }

    // memoize
    i = 0;
    while (x + i < s[y].size() && s[y][x + i] != '#') {
        memo_h[y][x + i] = cnt;
        i++;
    }
    i = 0;
    while (x - i >= 0 && s[y][x - i] != '#') {
        memo_h[y][x - i] = cnt;
        i++;
    }
}

int f(int h, int w, std::vector<std::string> s) {
    for (int i = 0; i < 3000; i++) {
        for (int j = 0; j < 3000; j++) {
            memo_v[i][j] = 0;
            memo_h[i][j] = 0;
        }
    }
    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            f2(s, i, j);
            f3(s, i, j);
        }
    }
    int mx = 0;
    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            if (mx < memo_v[i][j] + memo_h[i][j]) {
                // std::cout << "i: " << i << ", j: " << j << std::endl;
                // std::cout << memo_v[i][j] << std::endl;
                // std::cout << memo_h[i][j] << std::endl;
                mx = memo_v[i][j] + memo_h[i][j];
            }
        }
    }
    return mx + 1;
}

int main() {

    int h, w;
    std::cin >> h >> w;
    std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');

    std::vector<std::string> s;
    for (int i = 0; i < h; i++) {
        std::string tmp;
        std::getline(std::cin, tmp);
        s.push_back(tmp);
    }

    int result = f(h, w, s);
    std::cout << result << std::endl;

    return 0;
}


Measured memory_bytes: 78592
import sys
input = sys.stdin.readline
# sys.setrecursionlimit(10 ** 6)
# MOD = 10 ** 9 + 7
# INF = float("inf")


def main():
    a, b, c, x, y = map(int, input().split())
    case1 = a * x + b * y
    if x - y > 0:
        case2 = c * 2 * y + a * (x - y)
    else:
        case2 = c * 2 * y
    if y - x > 0:
        case3 = c * 2 * x + b * (y - x)
    else:
        case3 = c * 2 * x
    print(min(case1, case2, case3))


if __name__ == '__main__':
    main()

Measured memory_bytes: 3064
// Problem : One Quadrillion and One Dalmatians
// Contest : Virtual Judge - AtCoder
// URL : https://vjudge.net/problem/AtCoder-abc171_c
// Memory Limit : 1048 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include <bits/stdc++.h>
#pragma GCC target("avx,avx2,fma")
//#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("Ofast")  // disable
using namespace std;
#define ll long long
#define ull unsigned long long
#define ld long double
#define lll __int128
#define lp(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define vec(v, type, sz) vector<type> v(sz)
#define in(v) \
    for (auto &i : v) cin >> i
#define all(v) v.begin(), v.end()
#define prv(v)                         \
    for (auto i : v) cout << i << " "; \
    cout << "\n"
#define MOD 1000000007
#define INF 1000000000
#define INFL 1000000000000000000ll
#define fast_io                       \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL);                    \
    cout.tie(NULL);
#define vi vector<int>
#define vl vector<ll>
#define vii(v, n, m, val) vector<vector<int>> v(n, vector<int>(m, val))
#define viii(v, i, j, k, val)        \
    vector<vector<vector<int>>> v(i, \
                                  vector<vector<int>>(j, vector<int>(k, val)))
#define pii pair<int, int>
#define pb push_back
#define file_io                       \
    freopen("input.txt", "r", stdin); \
    freopen("output.txt", "w", stdout);
#define testcases \
    int tcc;      \
    cin >> tcc;   \
    for (int tc = 1; tc <= tcc; tc++)
vector<string> vec_splitter(string s) {
    s += ',';
    vector<string> res;
    while (!s.empty()) {
        res.push_back(s.substr(0, s.find(',')));
        s = s.substr(s.find(',') + 1);
    }
    return res;
}
void debug_out(vector<string> __attribute__((unused)) args,
               __attribute__((unused)) int idx,
               __attribute__((unused)) int LINE_NUM) {
    cerr << endl;
}
template <typename Head, typename... Tail>
void debug_out(vector<string> args, int idx, int LINE_NUM, Head H, Tail... T) {
    if (idx > 0)
        cerr << ", ";
    else
        cerr << "Line(" << LINE_NUM << ") ";
    stringstream ss;
    ss << H;
    cerr << args[idx] << " = " << ss.str();
    debug_out(args, idx + 1, LINE_NUM, T...);
}
#ifdef DB
#define debug(...) \
    debug_out(vec_splitter(#__VA_ARGS__), 0, __LINE__, __VA_ARGS__)
#else
#define debug(...) 42
#endif

/*logic
i find of faltered even on this simple one
condsider it like decimal
aa=26^1*(val of a)+26^0(val of a)
it should be similar to base coversion
explaining the -1
consider above example
n%26 nulls the tens part, the possible valies for rem is 1 to 26 and rem will be 1 to 0
this can be dealt with if but then if z then /26 will bring in a 1 that too need to be
handles so the best and easiest way is -1.
*/

int main() {
    fast_io;
    ll n; cin>>n;
    string ans;
    while(n){
    	n--;
    	ans=string(1,'a'+n%26)+ans;
    	n/=26;
    }
    cout<<ans;
}

Measured memory_bytes: 3596
import numpy
na = lambda: list(map(int, input().split()))

n, k = na()
x = na()
l = []
m, p = 0, 0
for i in range(n-1):
    hoge = x[i]
    if hoge < 0:
        m += 1
    l.append(abs(x[i+1] - hoge))
p = n-m
l = numpy.cumsum([0]+l)

ans = 10 ** 10

for i in range(max(0, m-k), min(n-p+1, n-k+1)):
    ans = min(ans, min(abs(x[i]), abs(x[i+k-1]))+abs(l[k-1+i]) - abs(l[i]))

print(ans)

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

int main(){
    int N;
    string S;
    cin >> N >> S;

    if(S.size() <= N){
        cout << S << endl;
        return 0;
    } else if(N < S.size()) {
        S.erase(N);
        cout << S << "..." << endl;
        return 0;
    }
}

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

#define F first
#define S second
#define int long long
#define inf 1000000000
#define mod 1000000007

using namespace std;

signed main(){
    int n, k;
    cin >> n >> k;
    int ans = 0;
    for (int i = k; i <= n+1; i++){
        int mx = (n-i)*i+i*(i+1)/2;
        int mn = i*(i-1)/2;
        ans += mx-mn+1;
        ans %= mod;
    }
    cout << ans << endl;
}























Measured memory_bytes: 3632
#include <stdio.h>

int even_odd(int num){
	if(num % 2 == 0) return 0;
	else return 1 ;
}

int main (void){
	int n = 0;
	

	int i = 0;
	int cnt = 0;

	scanf("%d", &n);
	for(i = 0; i < n; i++){
		int num = 0;
		scanf("%d", &num);
		if(even_odd(num)) cnt++;  
	}

	if(even_odd(cnt) == 0) printf("YES\n");
	else printf("NO\n");

	return 0;

}

Measured memory_bytes: 128
#include<bits/stdc++.h>
//#include<iostream>
//#include<cstdio>
//#include<cstring>
//#include<string>
//#include<queue>
//#include<cmath>
//#include<algorithm>
#define debug1 cout<<"?"<<endl;
#define debug2 cout<<"?"<<i<<endl;
#define PII pair<int,int>
typedef long long ll;
const int maxn=2e5+9;
const double pi=acos(-1);
const int mod=1e9+7;
const int INF=0x3f3f3f3f;
const double ep=1e-7;
using namespace std;
int main()
{
	ll n,i,k,h[maxn]={0};
	scanf("%lld%lld",&n,&k);
	for(i=1;i<=n;i++)scanf("%lld",&h[i]);
	ll ans=0;
	sort(h+1,h+1+n);
	for(i=1;i<=n-k;i++)ans+=h[i];
	printf("%lld\n",ans);
}

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

// ABCテンプレート

#define rep(i,n) for (int i = 0; i<(n); i++)
#define in(n) cin >> (n)
#define out(ans) cout << (ans) << endl;
#define keta(n) cout << fixed << setprecision((n));
using ll = int64_t;
using v = vector<int>;


int main() {
  int L, R, d, ans=0;
  cin >> L >> R >> d;
  for (int i = L; i<=R; i++) {
    if(i%d==0) {
      ans++;
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 3620
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  vector<vector<int>> c(3, vector<int>(3));
  for (int i = 0; i < 3; i++) {
    for (int j = 0; j < 3; j++) {
      cin >> c.at(i).at(j);
    }
  }
  bool ok = true;
  if ((c.at(0).at(1) - c.at(0).at(0)) != (c.at(1).at(1) - c.at(1).at(0))) {
    ok = false;
  }
  if ((c.at(0).at(1) - c.at(0).at(0)) != (c.at(2).at(1) - c.at(2).at(0))) {
    ok = false;
  }
  if ((c.at(0).at(2) - c.at(0).at(1)) != (c.at(1).at(2) - c.at(1).at(1))) {
    ok = false;
  }  
  if ((c.at(0).at(2) - c.at(0).at(1)) != (c.at(2).at(2) - c.at(2).at(1))) {
    ok = false;
  }  
  if ((c.at(1).at(0) - c.at(0).at(0)) != (c.at(1).at(1) - c.at(0).at(1))) {
    ok = false;
  }
  if ((c.at(1).at(0) - c.at(0).at(0)) != (c.at(1).at(2) - c.at(0).at(2))) {
    ok = false;
  }
  if ((c.at(2).at(0) - c.at(1).at(0)) != (c.at(2).at(1) - c.at(1).at(1))) {
    ok = false;
  }  
  if ((c.at(2).at(0) - c.at(1).at(0)) != (c.at(2).at(2) - c.at(1).at(2))) {
    ok = false;
  }  
  if (ok) {
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
}

Measured memory_bytes: 3644
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define snuke srand((unsigned)clock()+(unsigned)time(NULL));
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
inline int in() { int x; scanf("%d",&x); return x;}
template<typename T>inline istream& operator>>(istream&i,v(T)&v)
{rep(j,sz(v))i>>v[j];return i;}
template<typename T>string join(const v(T)&v)
{stringstream s;rep(i,sz(v))s<<' '<<v[i];return s.str().substr(1);}
template<typename T>inline ostream& operator<<(ostream&o,const v(T)&v)
{if(sz(v))o<<join(v);return o;}
template<typename T1,typename T2>inline istream& operator>>(istream&i,pair<T1,T2>&v)
{return i>>v.fi>>v.se;}
template<typename T1,typename T2>inline ostream& operator<<(ostream&o,const pair<T1,T2>&v)
{return o<<v.fi<<","<<v.se;}
template<typename T>inline ll suma(const v(T)& a) { ll res(0); for (auto&& x : a) res += x; return res;}
const double eps = 1e-10;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
#define dame { puts("-1"); return 0;}
#define yn {puts("YES");}else{puts("NO");}
const int MX = 200005;

// 整数スキャン（複数）
/*
int x;
scanf("%d",&x);
int y;
scanf("%d",&y);
int z;
scanf("%d",&y);

// n個の整数のスキャン
/*
ll a[n] = {};
rep(i,n){
    scanf("%lld",&a[i]);
}
*/

// 文字列スキャン
/*
string s;
cin >> s;
*/


int main() {
    int n;
    scanf("%d",&n);

    if(n == 1){
        puts("Hello World");
    }else{
        int a;
        int b;
        scanf("%d",&a);
        scanf("%d",&b);
        int ans = 0;
        ans = a + b;
        cout << ans << endl;
    }



   
    return 0;
}
 
 


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep1(i, n) for (int i = 1; i < (n); ++i)
using namespace std;
typedef long long ll;
const ll INF = 1LL << 60;

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

    int a, b, k;
    cin >> a >> b >> k;

    int cnt = 1;
    for(int i = min(a, b); i > 0; --i){
        if(a%i==0 && b%i==0){
            if(cnt==k){
                cout << i << endl;
                return 0;
            }

            ++cnt;
        }
    }

    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void){
  int a,b,c;
  scanf("%d %d %d",&a,&b,&c);
  
  int temp=a;
  a=b;
  b=temp;
  
  temp=a;
  a=c;
  c=temp;
  
  printf("%d %d %d\n",a,b,c);
  
  return 0;
}

Measured memory_bytes: 1736
#include <iostream>

using namespace std;


int main(){
     
    int N, a;
    int rate[10] = {0};
    
    cin >> N ;

    for(int i = 0; i < N; i++){

        cin >> a;

        for(int j = 1;j <=8; j++){
        
            if((j - 1)*400 <= a && a < 400*j)
                rate[j-1]++;
        }
        
        if(a >= 3200)
            rate[8]++;
    }
    
    int ans = 0;
    

    for(int i = 0; i <=7; i++)
        if(rate[i])
            ans++;
    

    int ans_min = ans;
    int ans_max = ans;

    if(rate[8]){
        ans_max += rate[8];
        if(!ans_min)
            ans_min++;
    }

    
    cout << ans_min << ' ' << ans_max << '\n';

}



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

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

  int n;
  cin >> n;
  vector<vector<int>> cnt(n, vector<int>(26));
  for (int i = 0; i < n; i++) {
    string s;
    cin >> s;
    for (auto &c : s) {
      cnt[i][c - 'a']++;
    }
  }
  for (int i = 0; i < n - 1; i++) {
    for (int j = 0; j < 26; j++) {
      cnt[i+1][j] = min(cnt[i+1][j], cnt[i][j]);
    }
  }
  string ans = "";
  for (int i = 0; i < 26; i++) {
    for (int j = 0; j < cnt[n-1][i]; j++) {
      ans += (char)('a' + i);
    }
  }
  cout << ans << '\n';
  return 0;
}

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

long long a, b, c;
int main() {
	cin >> a >> b >> c;
	if(a%2 or b%2 or c%2) cout << 0, exit(0);
	for(int i = 0; i < 32; i++) {
		long long curr = 1ll << i+1;
		if((a%curr != b%curr) or (b%curr != c%curr) or (a%curr != c%curr)) cout << i, exit(0);
	}
	cout << -1;
}


Measured memory_bytes: 256
A, B = map(int, input().split())

AB = []
AB += [A, B]

def push(AB):
  if AB[0] >= AB[1]:
    i = 0
  else:
    i = 1
  ret = AB[i]
  AB[i] -= 1
  return ret

s = 0
for _ in range(2):
	s += push(AB)

print(s)


Measured memory_bytes: 3060
import java.util.*;
import static java.lang.System.*;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		
		if (a < 6)
			out.println(0);
		else if (a < 13)
			out.println(b / 2);
		else
			out.println(b);
	}
}

Measured memory_bytes: 21844
import java.util.Scanner;

public class Main {
	public static void main(String[] args){
		try(Scanner sc = new Scanner(System.in)) {
			
			String alpha = sc.next();
			
			if ( alpha.toLowerCase().contentEquals(alpha)) {
				System.out.println("a");
			}
			else {
				System.out.println("A");
			}
				
		}
	}

}

Measured memory_bytes: 35728
#include<iostream>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#include<algorithm>
#include<functional>
#include<vector>
#include<queue>
#include<stack>
#include<set>
#include<map>
using namespace std;
#define f(i,n) for(int i=0;i<int(n);i++)
#define MOD 1000000007
#define N 200000

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

    cout<<(a+b)*(c/2);
}

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

using namespace std;

int main(){
  set<pair<int,int>> st;
  int N,h,m;
  cin >> N;
  for(int i = 0 ; i < N ; i++){
    cin >> h >> m;
    st.insert(make_pair(h,m));
  }
  cin >> N;
  for(int i = 0 ; i < N ; i++){
    cin >> h >> m;
    st.insert(make_pair(h,m));
  }
  bool blank = false;
  for(auto x : st){
    if(blank){ cout << " "; }
    blank = true;
    printf("%d:%02d",x.first,x.second);
  }
  cout << endl;
  return 0;
}

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

count_dists = {}
for s in range(1,10):
    count_dists[s] = {}
    for t in range(1,10):
        count_dists[s][t] = 0

for i in range(1,n+1):
    lead_num = int(str(i)[0])
    end_num = int(str(i)[-1])

    if end_num == 0:
        continue

    count_dists[lead_num][end_num] = count_dists[lead_num][end_num] + 1

answer_count = 0

for u in range(1,10):
    for v in range(1,10):
        num1 = count_dists[u][v]
        num2 = count_dists[v][u]

        if u == v:
            answer_count += num1 ** 2
        else:
            answer_count += num1 * num2

# print(count_dists)
print(answer_count)


Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
int n = 0, lst[100500];
int gcd(int x, int y) { return y? gcd(y, x % y): x; }
bool sol()
{
	int tot = 0;
	bool hav_1 = false;
	for(int i = 1; i <= n; i++)
	{
		if(lst[i] & 1) tot++;
		if(lst[i] == 1) hav_1 = true;
	}
	if(tot > 1 or hav_1) return (n - tot) & 1; //不会再除偶数了 
	else
	{
		if(not ((n - tot - 1) & 1)) return true; //增加一个奇数 
		int g = 0;
		for(int i = 1; i <= n; i++)
		{
			if(lst[i] & 1) lst[i]--;
			g = gcd(g, lst[i]);
		}
		for(int i = 1; i <= n; i++)
			lst[i] /= g;
		if(not sol()) return true; //除一个偶数 
		else return false;
	}
}
signed main()
{
	scanf("%d", &n);
	if(n == 1)
	{
		puts("Second");
		return 0;
	}
	for(int i = 1; i <= n; i++)
		scanf("%d", &lst[i]);
	puts(sol()? "First": "Second");
	return 0;
}

Measured memory_bytes: 640
#include<iostream>
#include<algorithm>
#include<stack>
#include<list>
using namespace std;

int main(){
	int cnt,flag=1;
	string s;
	cin >> s;
	for (char c = 'a'; c <= 'z'; c++) {
		cnt = 0;
		for (int i = 0; i < s.length(); i++) {
			if (s[i] == c)cnt++;
		}
		if (cnt % 2) flag = -1;
	}

	if (flag == -1)cout << "No" << endl;
	else cout << "Yes" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int A, B;
  cin >> A >>  B;
 
  if (A>9||B>9) {
    cout << -1 << endl;
  }
  else if (A<10&&B<10) {
    cout << A * B << endl;
  }
}

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

int main() {
  //n=頂点数, m=辺数
  int n, m;
  cin >> n >> m;

  //graph
  vector<vector<int>> g(n+1);
  for (int i = 0; i < m; i++) {
    int a, b;
    cin >> a >> b;
    g[a].push_back(b);

    //無向グラフの場合は以下を追加
    g[b].push_back(a);
  }

  //BFS
  vector<int> depth(n+1, -1);
  vector<int> adj(n+1, -1);
  queue<int> que;
  depth[1] = 1;
  que.push(1);
  
  while (!que.empty()) {
    int v = que.front();
    que.pop();

    for (int nv : g[v]) {
      if (depth[nv] != -1) continue; //すでに発見済みの頂点は探索しない

      //新たな頂点をキューに追加
      depth[nv] = depth[v] + 1;
      adj[nv] = v;
      que.push(nv);
    }
  }

  cout << "Yes" << endl;
  for (int i = 2; i < n+1; i++) {
    cout << adj[i] << endl;
  }
}

Measured memory_bytes: 10676
#include <bits/stdc++.h>
using namespace std;
int main() {
  string s;
  cin >> s;
  for (char c = 'a'; c <= 'z'; c++) {
    int left[s.length()], right[s.length()], x, a = 1, b = s.length();
    left[0] = INT_MIN;
    right[s.length()-1] = INT_MIN;
    for (int i = 1; i < s.length(); i++) {
      if (s[i-1] == c) {
        left[i] = 1;
      } else {
        left[i] = left[i-1]+1;
      }
    }
    x = s.back() == c;
    for (int i = s.length()-2; i+1; i--) {
      x += s[i] == c;
      if (s[i+1] == c) {
        right[i] = 1;
      } else {
        right[i] = right[i+1]+1;
      }
    }
    while (a < b) {
      if (2*x > b-a+1) {
        cout << a << ' ' << b;
        return 0;
      } else if (s[a-1] == c && s[b-1] != c) {
        b--;
      } else if (s[a-1] != c && s[b-1] == c) {
        a++;
      } else if (s[a-1] != c && s[b-1] != c) {
        a++;
        b--;
      } else if (left[b-1] > right[a-1]) {
        b--;
        x--;
      } else {
        a++;
        x--;
      }
    }
  }
  cout << "-1 -1";
}

Measured memory_bytes: 1280
S = str(input())

tmp = '0'
ans1 = 0
for iro in S:
    if iro != tmp:
        ans1 += 1
    tmp = str(int(tmp)^1)

tmp = '1'
ans2 = 0
for iro in S:
    if iro != tmp:
        ans2 += 1
    tmp = str(int(tmp)^1)

print(min(ans1,ans2))

Measured memory_bytes: 41436
#include <bits/stdc++.h>
using namespace std;
int main()
{
	long int i,t,ac=0,wa=0,tle=0,re=0;
	cin>>t;
	string s[t];
	for(i=0;i<t;i++)
	{
		cin>>s[i];
	}
	for(i=0;i<t;i++)
	{
		if(s[i]=="AC")
		{
			ac++;
		}
		if(s[i]=="WA")
		{
			wa++;
		}
		if(s[i]=="TLE")
		{
			tle++;
		}
		if(s[i]=="RE")
		{
			re++;
		}
	}
	cout<<"AC x "<<ac<<endl;
	cout<<"WA x "<<wa<<endl;
	cout<<"TLE x "<<tle<<endl;
	cout<<"RE x "<<re<<endl;
	
}

Measured memory_bytes: 6720
#include <bits/stdc++.h>
        using namespace std;
        #define int long long
const int MAX = 2000003;
const int MOD = 1000000007;

        signed main() {
    cout<<fixed<<setprecision(15);
    int n,r;
    cin>>n>>r;
   int ans=0;
   while(n){
           ans++;
           n/=r;
   }
   cout<<ans;
   

    
      }

        


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

int main()
{
    std::string S;
    std::cin >> S;
    bool flag = 0;
    for (size_t i = 0; i < S.size() - 1; i++)
    {
        if (S[i] == S[i + 1]) {
            flag = 1;
            break;
        } else {
            continue;
        }  
    }

    if (flag) {
        std::cout << "Bad";
    } else {
        std::cout << "Good";
    }

    return 0;
}


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

using namespace std;

const int maxn = 2e5 + 20, mod = 1e9 + 7;
long long n, c[maxn], dp[maxn], p[maxn];

int main () {
	cin >> n;
	for (int i = 1; i <= n; i++)
		cin >> c[i];
	dp[1] = 1;
	p[c[1]] += 1;
	for (int i = 2; i <= n; i++) {
		if (c[i] != c[i - 1]) 
			p[c[i]] = (p[c[i]] + dp[i - 1]) % mod;
		dp[i] = p[c[i]] % mod;
	}
	cout << dp[n];
	return 0;
}

Measured memory_bytes: 4992
n=int(input())
a=list(map(int,input().split()))

s=[0]*(n+1)
for i in range(n):
  s[i+1] = s[i] + a[i]

MOD = 10**9+7
result = 0
for i in range(n):
  result += a[i]*(s[n] - s[i+1])%MOD
print(result%MOD)



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

using namespace std;

#define TRACE
#ifndef ONLINE_JUDGE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif


typedef long long ll;
int hash_1[999999];
int main(){
	int n;
	cin >> n;
	int array[n+2];
	for(int i = 1; i <= n; i++){
		cin >> array[i];
	}
	
	for(int i = 1; i <= n; i++){
		hash_1[array[i]] = i;
	}
	int max_tot = 0;
	int cnt = 1;
	for(int i = 1; i <= 2*pow(10,5); i++){
		while(hash_1[i+1] > hash_1[i]){
			i++;
			cnt++;
			trace(i);
		}
		if(cnt > max_tot){
			max_tot = cnt;
		}
		cnt = 1;

	}

	cout << n - max_tot << endl;
}

Measured memory_bytes: 1792
#include "bits/stdc++.h"

using namespace std;
using ll = long long;

const ll MOD = 1e9 + 7;

inline void normal(ll &a) { if (a >= MOD) a %= MOD; (a < 0) && (a += MOD); }
inline ll modMul(ll a, ll b) {normal(a), normal(b); return (a*b)%MOD; }
inline ll modAdd(ll a, ll b) {normal(a), normal(b); return (a+b)%MOD; }
inline ll modSub(ll a, ll b) {normal(a), normal(b); a -= b; normal(a); return a; }
inline ll modPow(ll b, ll p) { ll r = 1; while(p) { if(p&1) r = modMul(r, b); b = modMul(b, b); p >>= 1; } return r; } //if MOD is prime, modPow(b, p % (MOD-1))
inline ll modInverse(ll a) { return modPow(a, MOD-2); }
inline ll modDiv(ll a, ll b) { return modMul(a, modInverse(b)); }

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

    ll ttl = modPow(10, n);
    ll temp = modPow(9, n);

    ttl = modSub(ttl, 2 * temp);
    temp = modPow(8, n);
    ttl = modAdd(ttl, temp);

    cout << ttl << endl;
}

Measured memory_bytes: 3636
#define rep(i, a, b) for(int i = a; i < (int)(b); i++)
#include <bits/stdc++.h>

typedef long long ll;
using namespace std;
template<class T> inline void chmax(T &a, const T &b) {if(a < b) a = b;}
template<class T> inline void chmin(T &a, const T &b) {if(a > b) a = b;}
const long long INF = 1LL<<60;
const long long MOD = (ll)1e9+7;
const long long MAX = (ll)420;

int main(void) {
   string S;
   cin>>S;
   ll ans = 0;
   if (S.size()%2==0) {
      rep(i,0,S.size()/2) {
         if (S[i] != S[S.size()-1-i]) ans++;
      }
   } else {
      rep(i,0,(S.size()-1)/2) {
         if (S[i] != S[S.size()-1-i]) ans++;
      }
   }
   cout<<ans<<endl;


   return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define mod 1000000007
#define fi first
#define sc second
#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
int n,m;
int main(){
	cin >> n >> m;
	int ans = 0;
	if(n <= 3) ans += 100000 * (4-n);
	if(m <= 3) ans += 100000 * (4-m);
	if(n+m == 2){
		//yosupo
		ans += 400000;
	}
	cout << ans << endl;
}

Measured memory_bytes: 764
N = int(input())
A = list(map(int, input().split())) 
s = [0]*(N-1)
 
for n in range(N-1):
  t = A[n] - A[n+1]
  if t <= 0: 
    continue
  else:
    A[n+1] += t
    s[n] = t

print(sum(s))


Measured memory_bytes: 32220
n=input()

a=[0 for i in range(n)]
def gcd(num1,num2):
    if num2 == 0:
        return num1
    else:
        return gcd(num2,num1%num2)

def lcm(num1,num2):
    tmp = gcd(num1,num2)
    return num1*num2/tmp

for i in range(n):
    a[i]=input()
ans=a[0]
for i in range(1,n):
    ans=lcm(ans,a[i])
print ans

Measured memory_bytes: 2568
package main

import (
	"fmt"
)

func main() {
	var a int
	fmt.Scan(&a)

	for a > 0{
		a = a - 1000
	}
	fmt.Println(abs(a))
}

// http://cavaliercoder.com/blog/optimized-abs-for-int64-in-go.html
func abs(n int) int {
	y := n >> 63
	return (n ^ y) - y
}


Measured memory_bytes: 1772
#include <iostream>
#define rep(i, n) for(int i=0; i<n; i++)

using namespace std;

int main(){
  int N, A, B;
  cin >> N >> A >> B;
  int X[N];
  rep(i, N)
    cin >> X[i];
  //入力終わり

  long long ans = 0;

  //歩くときとテレポートするときのそれぞれのコスト
  long long costA, costB = B;
  rep(i, N-1){
    costA = (long long)(X[i+1]-X[i] )*A;
    //隣町に行くのにコストの小さい選択を順次していけばよい
    ans += min(costA, costB);
  }

  //解答
  cout << ans << endl;
  
  return 0;
}


Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <algorithm>
#include <cfenv>
#include <cmath>
#include <cstdlib>
#include <limits>
#include <numeric>
#include <type_traits>
using namespace std;
#define rep(i,n) for(int i = 0;i < n;i++)
#define INF 0x3f //plus infinite

typedef struct item{
  string name;
  int number;
  int money;
}item;

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

int main(){
  int K;
  cin >> K;
  long long int sum = 0;
  for(int i = 1;i <= K;i++){
    for(int j = 1;j <= K;j++){
      for(int k = 1;k <= K;k++){
	sum += gcd(gcd(i,j),k);
      }
    }
  }
  cout << sum << endl;

  return 0;
}

/*文字列の辞書順について
 *C++の順序では'0'～'9'→'A'～'Z'→'a'～'z'の順に
 *                       なっていることに注意しましょう。
 */

/*行単位での入力
 * getline(cin,文字列変数);
 */


Measured memory_bytes: 3636
/*-------------------------------"ANJAN AGARWALA"-----------------------------

         _/_/_/_/    _/_/    _/   _/_/_/_/   _/_/_/_/    _/_/    _/   
        _/    _/    _/ _/   _/         _/   _/    _/    _/ _/   _/        
       _/_/_/_/    _/   _/ _/         _/   _/_/_/_/    _/  _/  _/         
      _/    _/    _/    _/_/   _/    _/   _/    _/    _/    _/_/  
     _/    _/    _/      _/   _/_/_/_/   _/    _/    _/      _/   

-------------------------------------@anjn98---------------------------------*/

//#define opti
#ifdef opti
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast,unroll-loops,fast-math")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native")
#endif

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

typedef long long int ll;
typedef long long int LL;
typedef unsigned long long int ull;
ll power(ll x,ll y,ll p){ll r=1; x=x%p; while(y){ if(y&1) r= r*x%p; y=y>>1; x=x*x%p; } return r; }
/*
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;*/


#define IO              ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define FILEIO          freopen("input.txt", "r", stdin);freopen("output.txt", "w", stdout);
#define all(v)          v.begin(),v.end()
#define PR(a)           cout<<"("<<a<<")";
#define ED              cout<<'\n';
//#define endl            '\n'
#define loop(j,a,n)     for(int j=a;j<=n;j++)
#define loop1(j,a,n)    for(int j=a;j>=n;j--)
#define fr1(j,n)        for(int j=0;j<n;j++)
#define fr(n)           for(int i=0;i<n;i++)
#define trav(x,s)       for(auto x:s)
#define SC(n)           scanf("%d",&n)
#define PB              push_back
#define MP              make_pair
#define pii             pair<int,int>
#define pll             pair<long long int,long long int>
#define F               first
#define S               second 
#define binf            2000000000000000001
#define mod             1000000007

const int N=1e5+99;
int indeg[N],len[N],n,m;
bool vis[N];
std::vector<int> g[N];

void dfs(int v)
{
    vis[v]=1;
    if(g[v].size()==0) {len[v]=0; return ;}
    trav(x,g[v])
    {
        if(!vis[x]) dfs(x);
        len[v]=max(len[v],1+len[x]);
    }   
}

int main() 
{
    
    IO
   /* #ifndef ONLINE_JUDGE
    FILEIO
    #endif*/
    cin>>n>>m;
    fr(m)
    {
        int x,y;
        cin>>x>>y;
        g[x].PB(y);
        indeg[y]++;
    }
    for(int i=1;i<=n;i++)
        if(!indeg[i]){
                dfs(i); 
        }

    ll ans=0;
    for(int i=1;i<=n;i++) ans=max(ans,(ll)len[i]);
    cout<<ans<<endl;


}

Measured memory_bytes: 11264
#include <iostream>
#include <algorithm>
#include <string>
#include <cmath>
using namespace std;

long GCD(long m,long n){
	long remain;
	if((remain = m % n) == 0)return n;
	else return GCD(n,remain);
}

int main(){
	long a,b;
	while(cin >> a >> b){
		cout << GCD(a, b) << " " << a * b / GCD(a, b) << endl;
	}
}


Measured memory_bytes: 3016
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<long long> vll;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef pair<int, int> pii;
struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star;
#define all(c) (c).begin(), (c).end()
#define rall(c) (c).rbegin(), (c).rend()
#define vv(type, c, m, n, i) vector<vector<type>> c(m, vector<type>(n, i))
#define mat(type, c, m, n) vector<vector<type>> c(m, vector<type>(n));for(auto& r:c)for(auto& i:r)cin>>i;
#define rep(i,a,n) for(int i=(a), i##_len=(n); i<i##_len; ++i)
#define rrep(i,a,n) for(int i=(a), i##_len=(n); i>i##_len; --i)
#define each(x,y) for(auto &(x):(y))
#define var(type, ...)type __VA_ARGS__;Scan(__VA_ARGS__);
template<typename T> void Scan(T& t) { cin >> t; }
template<typename First, typename...Rest>void Scan(First& first, Rest&...rest) { cin >> first; Scan(rest...); }
#define vec(type, c, n) vector<type> c(n);for(auto& i:c) cin>>i;
#define len(x) ((int)(x).size())
#define mp make_pair
#define eb emplace_back
#define em emplace
#define pb pop_back
#define fi first
#define se second
#define get(a, i) get<i>(a)
#define bit_count __builtin_popcount
#define mt make_tuple
inline string zero(int a,string s,char c='0'){return string(a-len(s),c)+s;}
inline string zero(int a,int t,char c='0'){return zero(a, to_string(t), c);}
inline string zero(int a,ll t,char c='0'){return zero(a, to_string(t), c);}
#define mini min_element
#define maxi max_element
#define sum accumulate
#define chmax(a,b) if(a<b)a=b
#define chmin(a,b) if(a>b)a=b
template <class T> inline void print(T t){cout << t << '\n';}
template <class H, class... T> inline void print(H h, T... t){cout << h << " ";print(t...);}
string mode[2] = {"LR", "DU"};
vi m;
char move(int& a, int b, int c) {
	int op = a < 0 ? -1 : 1;
	char s = mode[c][a >= 0];
	a = (abs(a) - b) * op;
	return s;
}
void solve() {
	var(int, n);
	mat(int, yx, n, 2);
	bool odd = (abs(yx[0][0]) + abs(yx[0][1])) % 2;
	rep(i, 1, n) {
		if (((abs(yx[i][0]) + abs(yx[i][1])) % 2) != odd) {
			print(-1);
			return;
		}
	}
	rrep(i, 30, -1) {
		m.eb(1 << i);
	}
	if (!odd) m.eb(1);
	print(len(m));
	rep(i, 0, len(m) - 1)
		cout << m[i] << " ";
	print(m.back());
	each(a, yx) {
		string s = "";
		each(b, m) {
			if (abs(a[0]) > abs(a[1])) {
				s += move(a[0], b, 0);
			} else {
				s += move(a[1], b, 1);
			}
		}
		print(s);
	}
}
int main() {
	solve();
	return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
typedef long long ll;
constexpr ll mod = 998244353;
ll dp[301][301][301] = {},dp2[301][301] = {},dp3[301][301] = {};
vector<int> v;
int main(){
    int i,j,k,l,r;
    string s; cin >> s >> k;
    s.push_back('0');
    int n = s.size();
    for(i=0;i<n;i++){
        if(s[i]=='0'){
            int cnt = 0;
            if(i==0) v.push_back(0);
            for(j=i - 1;j>=0;j--){
                if(j!=0 && s[j]=='1'){
                    cnt++;
                }else{
                    v.push_back(cnt);
                    break;
                }
            }
        }
    }
    int m = v.size(),sum = 300;
    dp[m][0][0] = 1;
    for(i=m - 1;i>=0;i--){
        for(l=0;l<=sum;l++){
            dp2[sum][l] = dp[i + 1][sum][l];
            for(j=sum - 1;j>=0;j--){
                dp2[j][l] = dp2[j + 1][l];
                (dp2[j][l] += dp[i + 1][j][l]);
            }
        }
        for(j=0;j<=sum;j++){
            for(l=0;l<=sum;l++){
                (dp[i][j][l] += dp2[j][l]) %= mod;
                for(r=1;r<=min({j,l,v[i]});r++){
                    (dp[i][j][l] += dp[i + 1][j - r][l - r]) %= mod;
                }
            }
        }
    }
    ll ans = 0;
    for(i=0;i<=min(300,k);i++){
        (ans += dp[0][0][i]) %= mod;
    }
    cout << ans << endl;
}

Measured memory_bytes: 216636
#include <stdio.h>
#include <ctype.h>
#include <string.h>

int main(void)
{
	char str[500];
	int wordLong,i;
	
	gets(str);
	wordLong=strlen(str);
	for(i=0;i<wordLong;i++)
		str[i]=toupper(str[i]);
	
	printf("%s\n",str);
	return 0;
}

Measured memory_bytes: 524
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,s,n) for(int i = (s); i < (n); i++)
#define all(v) v.begin(), v.end()

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  ll n;
  cin >> n;
  int ans=0;
  for(int k = 1; k <= n; k += 2){
    int cc = 0;
    rep(i, 1, k+1){
      if(k % i ==0) cc++;
    }
    if(cc == 8) ans++;
  }
  cout << ans << "\n";

}


Measured memory_bytes: 256
#from statistics import median
#import collections
#aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
from fractions import gcd
from itertools import combinations,permutations,accumulate, product # (string,3) 3回
#from collections import deque
from collections import deque,defaultdict,Counter
import decimal
import re
#import bisect
#
#    d = m - k[i] - k[j]
#    if kk[bisect.bisect_right(kk,d) - 1] == d:
#
#
#
# pythonで無理なときは、pypyでやると正解するかも！！
#
#
# my_round_int = lambda x:np.round((x*2 + 1)//2)
# 四捨五入g
import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7
#mod = 9982443453
def readInts():
  return list(map(int,input().split()))
def I():
  return int(input())
n = I()
A = readInts()
ans = 0
for v in A:
    while v%2 == 0:
        ans += 1
        v//=2
print(ans)


Measured memory_bytes: 11364
import sys
def input(): return sys.stdin.readline().strip()
def mapint(): return map(int, input().split())
sys.setrecursionlimit(10**9)

N, K = mapint()
As = sorted(list(mapint()))
Fs = sorted(list(mapint()))[::-1]
from math import ceil

L, R = -1, 10**12
while L+1<R:
    half = (L+R)//2
    k = 0
    for a, f in zip(As, Fs):
        k += max(0, ceil(((a*f)-half)/f))
        if k>K:
            L = half
            break
    else:
        R = half

print(R)

Measured memory_bytes: 117868
use std::io::Read;

pub fn read_stdin() -> String {
    let mut s = String::new();
    ::std::io::stdin().read_to_string(&mut s).unwrap();
    s
}

pub trait Parse {
    fn to<T>(&mut self) -> T
    where
        T: std::str::FromStr;
}

impl<'a> Parse for std::str::SplitWhitespace<'a> {
    fn to<T>(&mut self) -> T
    where
        T: std::str::FromStr,
    {
        let word = self.next().unwrap();
        word.parse().ok().unwrap()
    }
}

// Warshall-Floyd Algorithm
fn find_shortest_path_between_all_points(
    n: usize,
    edges: Vec<(usize, usize, i64)>,
) -> Vec<Vec<Option<i64>>> {
    let mut m = vec![vec![None; n]; n];
    for u in 0..n {
        m[u][u] = Some(0);
    }
    for (u, v, weight) in edges {
        m[u][v] = Some(weight);
    }

    for k in 0..n {
        for i in 0..n {
            for j in 0..n {
                if let Some(i_k) = m[i][k] {
                    if let Some(k_j) = m[k][j] {
                        if let Some(i_j) = m[i][j] {
                            m[i][j] = Some(std::cmp::min(i_j, i_k + k_j));
                        } else {
                            m[i][j] = Some(i_k + k_j);
                        }
                    }
                }
            }
        }
    }
    m
}

fn main() {
    let source = read_stdin();
    let mut iter = source.split_whitespace();
    let n = iter.to();
    let m = iter.to();
    let l = iter.to();
    let paths: Vec<(usize, usize, i64)> = (0..m)
        .map(|_| {
            (iter.to::<usize>() - 1, iter.to::<usize>() - 1, iter.to())
        })
        .collect();
    let q_n = iter.to();
    let queries: Vec<(usize, usize)> = (0..q_n)
        .map(|_| (iter.to::<usize>() - 1, iter.to::<usize>() - 1))
        .collect();

    let mut edges0 = Vec::new();
    for path in paths {
        edges0.push((path.0, path.1, path.2));
        edges0.push((path.1, path.0, path.2));
    }

    let m0 = find_shortest_path_between_all_points(n, edges0);

    let mut edges1 = Vec::new();
    for i in 0..n {
        for j in 0..n {
            if i == j {
                continue;
            }
            if let Some(len) = m0[i][j] {
                if len <= l {
                    edges1.push((i, j, 1));
                }
            }
        }
    }

    let m1 = find_shortest_path_between_all_points(n, edges1);

    let mut ans = Vec::new();
    for (s, t) in queries {
        if let Some(count) = m1[s][t] {
            ans.push(count - 1);
        } else {
            ans.push(-1);
        }
    }

    println!(
        "{}",
        ans.into_iter()
            .map(|x| x.to_string())
            .collect::<Vec<_>>()
            .join("\n")
    );
}

Measured memory_bytes: 15120
n = int(input())
a = []
if n ==0:
  print(0)
else:
  while n != 0:
    if n%2 ==0:
      n = n/(-2)
      a.append("0")
    else:
      n = (n-1)/(-2)
      a.append("1")
    
  b = ""
  for i in range(len(a)):
    b += a[len(a)-i-1]

  print(b)

  
  

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

int main(){
  int a[3];
  cin >> a[0] >> a[1] >> a[2];
  sort(a, a+3);
  printf("%d %d %d\n", a[0], a[1], a[2]);
  return 0;
}



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

using ll = long long;
const int mod = 1e9 + 7;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int K, N;
    cin >> K >> N;
    vector<int> A(N);
    for (int i = 0; i < N; i++) {
        cin >> A[i];
    }
    int ans = K;
    for (int i = 0; i < N; i++) {
        int nxt = (i + 1) % N;
        int prev = (i + N - 1) % N;
        ans = min(ans, K - (A[nxt] - A[i] + K) % K);
        ans = min(ans, K - (A[i] - A[prev] + K) % K);
    }
    cout << ans << endl;
}

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

template<typename T> T in() { abort(); return T(); }
template<> std::string in() { std::string str; std::cin >> str; return str; }
template<> int in() { int x; scanf("%d", &x); return x; }

template<typename T> void out(T x) { abort(); }
template<> void out(const char* x) { printf("%s\n", x); }
template<> void out(std::string x) { std::cout << x << std::endl; }
template<> void out(int x) { printf("%d\n", x); }
template<> void out(long x) { printf("%ld\n", x); }

template<typename T>
T pow(T x, long n) {
  T res = 1;
  T p = x;
  while( n != 0 ) {
    if( n & 0x01 ) res *= p;
    p *= p;
    n >>= 1;
  }
  return res;
}

template<long P = 1000000007>
class Mod {
public:
  Mod() : a(0) {}
  Mod(long x) : a(x) {}
  long get() { return a; }
  Mod operator + (Mod x) { return Mod<P>((a + x.get()) % P); }
  Mod operator += (Mod x) { a = (a + x.get()) % P; return *this; }
  Mod operator - (Mod x) { return Mod<P>((a + P - x.get()) % P); }
  Mod operator -= (Mod x) { a = (a + P - x.a) % P; return *this; }
  Mod operator * (Mod x) { return Mod<P>((a * x.get()) % P); }
  Mod operator *= (Mod x) { a = (a * x.a) % P; return *this; }
  Mod operator / (Mod x) { return *this * pow(x, P - 2); }
  Mod operator /= (Mod x) { a = (*this * pow(x, P - 2)); return *this; }
private:
  long a;
};



std::string str;

Mod<> dp[512][512];
Mod<> power[512][512]; // x ^ k
Mod<> powersum[512][512];
long xs[512];
long ys[512];

int main() {
  int n = in<int>();
  int c = in<int>();

  for(int i = 0; i < n; ++i) xs[i] = in<int>();
  for(int i = 0; i < n; ++i) ys[i] = in<int>();

  for(int i = 1; i < 512; ++i) {
    Mod<> t = 1;
    for(int j = 0; j < 512; ++j) {
      power[i][j] = t;
      t *= i;
    }
  }

  for(int j = 0; j < 512; ++j) {
    Mod<> sum = 0;
    powersum[j][0] = 0;
    for(int i = 1; i < 512; ++i) {
      powersum[j][i] = sum;
      sum += power[i][j];
    }
  }

  for(int j = 0; j <= c; ++j) {
    dp[0][j] = powersum[j][ys[0] + 1] - powersum[j][xs[0]];
  }

  for(int i = 1; i < n; ++i) {
    for(int j = 0; j <= c; ++j) {
      Mod<> sum = 0;
      for(int k = 0; k <= j; ++k) {
        sum += (powersum[j-k][ys[i] + 1] - powersum[j-k][xs[i]]) * dp[i-1][k];
      }
      dp[i][j] = sum;
    }
  }

  out(dp[n-1][c].get());
  
  return 0;
}


Measured memory_bytes: 6400
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef vector<int> VI;

template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()

int main() {
    ll n;
    cin >> n;
    vector<ll> a(n+2, 0);
    ll sum = 0;
    rep (i, n+1) {
        cin >> a[i];
        sum += a[i];
    }
    vector<ll> b(n+1);
    if (a[0] > 0) {
        if (a[0] > 1) {
            cout << -1 << endl;
            exit(0);
        } else {
            if (sum == 1) {
                cout << 1 << endl;
                exit(0);
            } else {
                cout << -1 << endl;
                exit(0);
            }
        }
    }
    b[0] = 1;
    sum -= a[0] + a[1];
    rep (i, n-1) {
        if (2 * b[i] - a[i+1] < 0) {
            cout << -1 << endl;
            exit(0);
        } else {
            ll x = min(2 * b[i] - a[i+1], sum);
            b[i+1] = x;
            sum -= a[i+2];
        }
    }
    if (2 * b[n-1] - a[n] < 0) {
        cout << -1 << endl;
        exit(0);
    }
    b[n] = 0;
    cout << accumulate(all(a), 0ll) + accumulate(all(b), 0ll) << endl;
}

Measured memory_bytes: 5084
N = int(input())
M = []

type = ['root','internal node','leaf']

class node:
    def __init__(self,idx,parent,left,right):
        self.idx = idx
        self.parent = parent
        self.left = left
        self.right= right
        
        self.sibling = -1
        self.degree= 0
        self.depth = 0
        self.height = 0
        self.type=-1

    def tostr(self):
        print('node %d: parent = %d, sibling = %d, degree = %d, depth = %d, height = %d, %s' % (self.idx, self.parent, self.sibling, self.degree, self.depth, self.height, type[self.type])) 
tree = [[] for x in range(N)]


#'idx, parent, sibling, degree, depth, height, type'

for a in range(N):
    idx,left,right = map(int,input().strip().split(' '))
    tree[idx] = node(idx, -1, left,right)

for a in range(N):
    nd = tree[a]
    if nd.left != -1:
        tree[nd.left].parent = a
    if nd.right != -1:
        tree[nd.right].parent = a
    if nd.left !=  -1:
        tree[nd.left].sibling = nd.right
    if nd.right !=  -1:
        tree[nd.right].sibling = nd.left

    if nd.left == nd.right :
        nd.type=2
        nd.degree=0
    else:
        nd.type=1
        if nd.left == -1 or nd.right == -1:
            nd.degree = 1
        else:
            nd.degree = 2

root = ''
for a in range(N):
    if tree[a].parent == -1:
        root = a
        tree[root].type=0
    
def search(root,depth):
    root = tree[root]
    root.depth = depth
    if root.type ==  2:
        return
    else:
        if root.right == -1 and root.left == -1:
            return
        if root.right != -1:
            search(root.right,depth+1)
        if root.left != -1:
            search(root.left,depth+1)

search(root,0)

def height(root,hei):
    root = tree[root]
    if root.type==2 or (root.right == -1 and root.left == -1):
        root.height=0
        return hei
    else:
        if root.left == -1:
            return height(root.right,hei+1)
        elif root.right == -1:
            return height(root.left,hei+1)
        else:
            return max(height(root.left,hei+1),height(root.right,hei+1))
for i in range(N):
    tree[i].height=height(i,0)

for a in range(N):
    tree[a].tostr()






    

Measured memory_bytes: 7912