akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD=1000000007;
#define INF 1LL<<30
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()

int main(){
    int n,x,y;
    cin>>n>>x>>y;
    x--,y--;
    if(x>y) swap(x,y);

    vector<int> ans(n,0);

    for(int i=0;i<n;i++){
        for(int j=i+1;j<n;j++){
            int d=min(j-i,abs(i-x)+1+abs(y-j));
            ans[d]++;
        }
    }

    for(int i=1;i<n;i++){
        cout<<ans[i]<<endl;
    }
}


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

int main(){
  long N,Q;
  cin>>N>>Q;
  string s;
  cin>>s;
  long l[Q],r[Q];
  rep(i, Q){
    cin>>l[i]>>r[i];
  }

  vector<long> sum(N, 0);
  FOR(i, 1, N){
    if(s[i-1] == 'A' && s[i] == 'C'){
      sum[i-1] = 1;
    }
  }

  long a[N+1];
  a[0] = 0;
  FOR(i, 1, N){
    a[i] = a[i-1] + sum[i-1];
  }

  rep(i, Q){
    cout << a[r[i]-1]-a[l[i]-1]<<endl;
  }
}


Measured memory_bytes: 4224
A = int (input ())
B = int (input ())
N = int (input ())
if A < B:
  X = N//B
  if N%B == 0:
    print (X)
  else:
    print (X+1)
else:
  X = N//A
  if N%A == 0:
    print (X)
  else:
    print (X+1)

Measured memory_bytes: 9172
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
signed main() { 
  ios::sync_with_stdio(false); cin.tie(0);
  //c
  int x;
  cin >> x;
  vector<int> dp(x + 200);
  dp[0] = 1;
  for (int i = 100; i <= 105; i++) {
    for (int j = 0; j < x; j++) {
      if (dp[j]) dp[j + i] = 1;
    }
  }
  cout << (dp[x] == 1) << '\n';
  return 0;
}

Measured memory_bytes: 640
#pragma GCC optimize ("O3")
#pragma GCC optimize ("unroll-loops")
#pragma comment(linker, "/STACK:2000000")

#include "bits/stdc++.h"

using namespace std;

#define pb push_back
#define F first
#define S second
#define f(i,a,b)  for(int i = a; i < b; i++)
// #define endl '\n'
using ll = long long;
using db = long double;
using ii = pair<int, int>;

const int N = 2e5+5, LG = 19, MOD = 998244353;
const int SQ =320;
const long double EPS = 1e-7;
int n, m;

int32_t main(){
#ifdef ONLINE_JUDGE
    ios_base::sync_with_stdio(0);
    cin.tie(0);
#endif

  int n;
  cin >> n;

  if(!(n&(n-1))){
    ///power of two
    cout << "No\n";
  } else {
    cout << "Yes\n";

    cout << "1 2\n";
    cout << "2 3\n";
    cout << n + 1 << ' ' << n + 2 <<'\n';
    cout << n + 3 << ' ' << n + 2 <<'\n';
    cout << 3 <<  " " << n + 1 << '\n';
    for(int i = 4; i < n; i += 2){
      cout<< i << ' ' << i + 1 << '\n';
      cout<< n+i << ' ' << n+i + 1 << '\n';
      cout<<  1 << ' ' << i << '\n';
      cout<<  1 << ' ' << n+i+1 << '\n';
    }

    if(n&1^1){
      int lft = n-(n&-n);
      cout << n << ' ' << (lft+1+n) << '\n';
      cout << n+n<<' '<< (n&-n) << '\n';
    }

  }

  return 0;
}


Measured memory_bytes: 2304
#define _USE_MATH_DEFINES
#include<iostream>
#include<algorithm>
#include<cmath>
#include<string>
#include<set>
#include<map>
#include<vector>
#include<utility>
#include<queue>
#include<stdbool.h>
#include<math.h>
#include<sstream>
typedef long long ll;
#define N (1000000000+7)
#define INF (-1000000)
using namespace std;
typedef pair<int, int> P;

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

int d[55][55];

char board[55][55];
int h, w;

int bfs() {
	queue<P>q;
	for (int i = 1;i <= h;i++) {
		for (int j = 1;j <= w;j++) {
			d[i][j] = INF;
		}
	}
	q.push(P(1, 1));
	d[1][1] = 0;
	while (!q.empty()) {
		P p = q.front();q.pop();
		if ((p.first == h) && (p.second == w))break;
		for (int i = 0;i < 4;i++) {
			int nx = p.first + dx[i];
			int ny = p.second + dy[i];
			if ((1 <= nx) && (nx <= h) && (1 <= ny) && (ny <= w) && (board[nx][ny] != '#') && (d[nx][ny] == INF)) {
				q.push(P(nx, ny));
				d[nx][ny] = d[p.first][p.second] + 1;
			}
		}
	}
	return d[h][w];
}

int t[100010], x[100010], y[100010];

int main(void) {
	int a, b;
	cin >> a >> b;
	if ((a*b) % 2 == 0)cout << "Even" << endl;
	else cout << "Odd" << endl;
	return 0;
}

Measured memory_bytes: 256
"use strict";
var input = require("fs").readFileSync("/dev/stdin", "utf8");
var cin = input.trim().split(/ |\n/), cid = 0;

console.log(main().toString());

function main() {
    var a = BigInt(cin.shift());
    var b = BigInt(Math.round((+cin.shift()) * 100));
    return a * b / 100n;
}

Measured memory_bytes: 29628
#include <iostream>
#include <algorithm>
using namespace std;
 
int main() {
  const int MAX = 100002;
  int n, a, b;
  int dp[MAX+1] = {};
  
  cin >> n;
  for(int i=0; i<n; i++) {
    cin >> a >> b;
    dp[a] ++;
    dp[b+1] --;
  }
 
  for(int i=0; i<MAX; i++) {
    dp[i+1] += dp[i];
  }
  
  int mx = 0;
  for(int i=0; i<MAX; i++) {
    if(dp[i]+1>=i) mx = i-1;
  }
  cout << mx << endl;
   
  return 0;
}

Measured memory_bytes: 1560
#include<iostream>
#include<algorithm>
#include<vector>
#include<numeric>

using sll = signed long long;
using ull = unsigned long long;

int main() {

	ull n{}, k{};
	std::cin >> n >> k;

	std::vector<sll> v;
	v.reserve( static_cast<unsigned>(n) );
//	sl pre{};
//	std::cin >> pre;
//	v.emplace_back(0);
	for (int i{}; i < n; ++i) {
		sll tmp;
		std::cin >> tmp;
		v.push_back(tmp);
	}

//	for (auto&e : v)
//		std::cout << e << "\n";

//	auto sum = std::accumulate(std::begin(v), std::begin(v) + k, sl{});


	ull result = 1000'000'000;

	for (ull i{0}; i < n - k + 1; ++i) {

		const unsigned li = i;
		const unsigned ri = i + k - 1;
		auto d = v[ri] - v[li];
		ull ltor = std::abs(v[li]) ;
		ull rtol = std::abs(v[ri]) ;
		auto m = std::min(ltor, rtol) + d;
//		std::cout << li<<" " << ri <<":"<< ltor <<" "<< rtol << "\n";
		result = std::min(m, result);
	}

	std::cout << result << "\n";
	return 0;
}

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

using namespace std;
using namespace atcoder;
using usize = ::std::size_t;
using u64 = ::std::int_least64_t;
//using u64 = long long;
static constexpr u64 Inf = ::std::numeric_limits<u64>::max() / 2;


int main(int argc, char *argv[])
{
    
    
    cin.tie(0) ;
    ios::sync_with_stdio(false) ;
    
    int N, Q;
    cin >> N >> Q;
    fenwick_tree<u64> fw(N);
    for (int i = 0; i < N; i++) {
        int a;
        cin >> a;
        fw.add(i, (u64) a);
    }
    
    while (Q--) {
        int type, l, r;
        cin >> type >> l >> r;
        if(type) cout << fw.sum(l, r) << endl;
        else fw.add(l, (u64) r);
    }
    
    return 0;
    
}


Measured memory_bytes: 8260
#include <bits/stdc++.h>
using namespace std;
int n, m, i, j, k, a, b;
int main(){
	scanf("%d%d%d%d", &n, &a, &m, &b);
	for(i=1; ; i++){
		m=m-a;
		if(m<0||m==0){
			printf("Yes");
			return 0;
		}
		n=n-b;
		if(n<0||n==0){
			printf("No");
			return 0;
		}
	}
}

Measured memory_bytes: 3700
def solve(h):
    if len(h)<2:
        return h[0]
    s=[i for i in range(len(h))if h[i]<1]
    s=[-1]+s+[len(h)]
    a=0
    for l in[h[i+1:j]for i,j in zip(s,s[1:])]:
        if not l:continue
        v=min(l)
        l=[t-v for t in l]
        a+=v+solve(l)
    return a
input()
print(solve(list(map(int,input().split()))))

Measured memory_bytes: 38640
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(ll i = 0;i<((ll)(n));i++)
#define reg(i,a,b) for(ll i = ((ll)(a));i<=((ll)(b));i++)
#define irep(i,n) for(ll i = ((ll)(n)-1);i>=0;i--)
#define ireg(i,a,b) for(ll i = ((ll)(b));i>=((ll)(a));i--)
template<class T = int> using V = vector<T>;
template<class T = int> using VV = V< V<T> >;
template<class T = int> void print(vector<T> v){for(auto a:v)cout<<a<<" ";cout<<endl;}

/*
均等に分解したい。
*/

ll n,ans=1e18;

int main(void){
	cin>>n;
	for(ll i=1; i*i<=n; i++){
		if(n%i==0){
			ans = min(ans,i+n/i);
		}
	}
	cout<<ans-2<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string>
#include <algorithm>
#include <set>
#include <map>
#include <vector>
#include <iostream>
#include <math.h>
#include <bitset>
#include <iomanip>
#include <queue>
#include <cstring>
using namespace std;

const long long mod = pow(10, 9) + 7;

int main() {
	int H, W, K; cin >> H >> W >> K;
	vector<vector<char>> s(H, vector<char>(W));
	vector<vector<int>> x(H, vector<int>(W, 0));
	vector<bool> t(H,0);
	for (int i = 0; i < H; i++) {
		bool d = 0;
		for (int j = 0; j < W; j++) {
			cin >> s[i][j];
			if (s[i][j] == '#')d = 1;
		}
		t[i]=d;
	}
	int c = 1,e=0;
	for (int i = 0; i < H; i++) {
		bool z = 0;
		if (t[i] == 0) {
			e++; continue;
		}
		for (int j = 0; j < W; j++) {
			if (s[i][j] == '#'&&z == 1)c++;
			x[i][j] = c;
			for (int k = 1; k <= e; k++) x[i-k][j] = c;
			if (s[i][j] == '#'&&z == 0)z=1;
		}
		c++; e = 0;
	}
	if (e != 0) {
		for (int i = 0; i < W; i++) {
			for (int k = 0; k < e;k++)x[H - k - 1][i] = x[H - e-1][i];
		}
	}
	for (int i = 0; i < H; i++) {
		for (int j = 0; j < W; j++)cout << x[i][j]<<" ";
		cout << endl;
	}
}





Measured memory_bytes: 1280
def e_red_and_green_apples():
    from bisect import bisect_right
    X, Y, A, B, C = [int(i) for i in input().split()]
    P = sorted([int(i) for i in input().split()], reverse=True)
    Q = sorted([int(i) for i in input().split()], reverse=True)
    R = sorted([int(i) for i in input().split()], reverse=True)

    candidate = sorted(P[:X] + Q[:Y] + R, reverse=True)
    return sum(candidate[:X + Y])

print(e_red_and_green_apples())

Measured memory_bytes: 23200
N = int(input())
An1 = input().split(' ')
Bn = input().split(' ')

next_add = 0
attacked = 0
for i in range(N):
    me = int(Bn[i])
    enemy = int(An1[i])
    if next_add > 0:
        diff1 = next_add - enemy
        if diff1 < 0:
            attacked = attacked + next_add
            enemy = enemy -next_add
            next_add = 0
        else:
            attacked = attacked + enemy
            next_add = me
            continue
        
    diff2 = me - enemy
    if diff2 < 0:
        attacked = attacked + me
        next_add = 0
    else:
        attacked = attacked + enemy
        next_add = diff2

if next_add > 0:
    enemy = int(An1[N])
    diff1 = next_add - enemy
    if diff1 < 0:
        attacked = attacked + next_add
    else:
        attacked = attacked + enemy
print(attacked)

Measured memory_bytes: 19412
using System;
class Program
 {
   	static void Main(string[] args)
        {
    　　	string a = Console.ReadLine(); //標準入力
		string[] aa = a.Split(' ');

	       	int N = int.Parse(aa[0]);
       		int X = int.Parse(aa[1]);
	   		int T = int.Parse(aa[2]);
	
			int count = 0;
		
      count = (int)(Math.Ceiling((double)N/(double)X))*T;
  
     		Console.WriteLine("{0}", count);
        }
 
  	
	static void changev(int h){
    
  	}
 }

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

using namespace std;

using ll = long long;
using ull = unsigned long long;

int main(int argc, char const *argv[]) {
	int n,k;
	std::cin >> n >> k;
	k--;
	string s;
	std::cin >> s;
	s[k] = s[k] - 'A' + 'a';
	std::cout << s << '\n';
	return 0;
}


Measured memory_bytes: 256
#line 2 "header.hpp"

//%snippet.set('header')%
//%snippet.fold()%
#ifndef HEADER_H
#define HEADER_H

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

// varibable settings
const long long INF = 1e18;
template <class T> constexpr T inf = numeric_limits<T>::max() / 2.1;

#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for (ll i = (ll)(a); i < (ll)(b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
#define _rrep(i, n) rrepi(i, 0, n)
#define rrepi(i, a, b) for (ll i = (ll)((b)-1); i >= (ll)(a); --i)
#define r_rep(...) _overload3(__VA_ARGS__, rrepi, _rrep, )(__VA_ARGS__)
#define each(i, a) for (auto &&i : a)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
#define pb(a) push_back(a)
#define mp(a, b) make_pair(a, b)
#define mt(...) make_tuple(__VA_ARGS__)
#define ub upper_bound
#define lb lower_bound
#define lpos(A, x) (lower_bound(all(A), x) - A.begin())
#define upos(A, x) (upper_bound(all(A), x) - A.begin())
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); }
template <typename X, typename T> auto make_table(X x, T a) { return vector<T>(x, a); }
template <typename X, typename Y, typename Z, typename... Zs> auto make_table(X x, Y y, Z z, Zs... zs) { auto cont = make_table(y, z, zs...); return vector<decltype(cont)>(x, cont); }

#define cdiv(a, b) (((a) + (b)-1) / (b))
#define is_in(x, a, b) ((a) <= (x) && (x) < (b))
#define uni(x) sort(all(x)); x.erase(unique(all(x)), x.end())
#define slice(l, r) substr(l, r - l)

typedef long long ll;
typedef long double ld;
using vl = vector<ll>;
using vvl = vector<vl>;
using pll = pair<ll, ll>;

template <typename T>
using PQ = priority_queue<T, vector<T>, greater<T>>;
void check_input() { assert(cin.eof() == 0); int tmp; cin >> tmp; assert(cin.eof() == 1); }

#if defined(PCM) || defined(LOCAL)
#else
#define dump(...) ;
#define dump_1d(...) ;
#define dump_2d(...) ;
#define cerrendl ;
#endif

#endif /* HEADER_H */
//%snippet.end()%
#line 2 "solve.cpp"
template<class T=ll> using vec = vector<T>;
struct Fast { Fast() { std::cin.tie(0); ios::sync_with_stdio(false); } } fast;


int solve() {
    int x,y;cin>>x>>y;

    rep(t, 0, x+1){
        int d = (x - t) * 4 + 2*t;
        if (d==y){
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;

    return 0; 
}


int main(){/*{{{*/
    solve();
    check_input();
    return 0;
}/*}}}*/


Measured memory_bytes: 3620
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Security.Cryptography.X509Certificates;
using System.Text.RegularExpressions;
using Console = System.Console;

namespace Atcoder
{
    class Program
    {
        static void Main(string[] args)
        {
            var r = int.Parse(Console.ReadLine());  
            Console.WriteLine(r / 3);
        }
    }
}

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

ans = {
    'AC': 0,
    'WA': 0,
    'TLE': 0,
    'RE': 0
}

for _ in range(n):
    ans[input()] += 1

print('AC x {}'.format(ans['AC']))
print('WA x {}'.format(ans['WA']))
print('TLE x {}'.format(ans['TLE']))
print('RE x {}'.format(ans['RE']))


Measured memory_bytes: 9188
#include <bits/stdc++.h>
#define FOR(i, a, b) for(int i=(a); i<(b); i++)
#define REP(i, n) FOR(i, 0, n)
#define all(x) (x).begin(), (x).end()
#define bit(x) (1L << (x))
using ll = long long;
using namespace std;

int main() {
  int n; cin >> n;
  vector<int> a(n);
  REP(i, n){
    cin >> a[i];
    a[i] -= i+1;
  }

  sort(a.begin(), a.end());
  ll m = n / 2, sum = 0;

  REP(i, n){
    sum += abs(a[i] - a[m]);
  }

  cout << sum << endl;

  return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>

namespace mp = boost::multiprecision;
using i128 = mp::int128_t;
using cpi = mp::cpp_int;
using namespace std;
using lli = int_fast64_t;
using ulli = unsigned long long;
#define debug(x) cerr << #x << " : " << x << endl
#define debugv(x) cerr << #x << " : {";for(auto value_of_x:x){ cerr << value_of_x << ", ";}cerr << endl
#define debugst(x) auto xt = copy(x);cerr << #x << " : {";for(int i=0;i<x.size();i++){ cerr << xt.top() << ", ";xt.pop();}cerr << endl
#define debugvp(x) cerr << #x << " : {";for(auto value_of_x:x){ cerr << value_of_x.first << " : " << value_of_x.second << ", ";}cerr << endl

constexpr lli MOD = (lli)1e9 + 7;
constexpr lli LIMIT = 1000000000000000000 * 5;

int main() {
	cpi A;
  	double B;
  	cin >> A >> B;
  	cpi b = static_cast<cpi>(B*1000);
  	cpi ans = A*b;
  	ans /= 1000;
  	cout << ans << endl;
	return 0;
}



Measured memory_bytes: 3868
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define rep1(i, n) for (ll i = 1; i <= (n); ++i)
#define rrep(i, n) for (ll i = (n - 1); i >= 0; --i)
#define ALL(obj) (obj).begin(), (obj).end()
#define pb push_back
#define to_s to_string
#define len(v) (ll)v.size()
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
#define print(x) cout << (x) << '\n'
#define debug(x) cout << #x << ": " << (x) << '\n'
using namespace std;
using ll = long long;
typedef pair<ll, ll> P;
ll MOD = 1e9 + 7;
ll devc(ll x, ll y) { return 1 + (x - 1) / y; }

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

    ll N, K;
    cin >> N >> K;
    vector<ll> h(N), dp(N + 150, 1e18);
    rep(i,N) cin >> h[i];
    dp[0] = 0;
    rep(i,N) rep1(j, K) dp[i + j] = min(dp[i + j], dp[i] + abs(h[i + j] - h[i]));

    print(dp[N - 1]);
    return 0;
}

Measured memory_bytes: 1792
#include <stdio.h>
#define N 2000000

void CountingSort(int *, int *, int, int);

int main(){
  int A[N], B[N], A_len,k=0, i;

  scanf("%d",&A_len);
  for(i = 1; i <= A_len; i++){
    scanf("%d",&A[i]);
    if( A[i] > k ) k = A[i];
  }

  CountingSort( A, B, A_len, k);
  for(i = 1; i < A_len; i++) printf("%d ",B[i]);
  printf("%d\n",B[A_len]);
  
  return 0;
}

void CountingSort(int *A, int *B, int A_len, int k){
  int i, j, C[k+1];

  for(i = 0; i <= k; i++) C[i] = 0;
  for(j = 1; j <= A_len; j++) C[A[j]]++;
  for(i = 1; i <= k; i++) C[i] += C[i-1];
  for(j = A_len; j >= 1; j--){
    B[C[A[j]]] = A[j];
    C[A[j]]--;
  }
}



Measured memory_bytes: 17372
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define fi first
#define se second
template<typename A, typename B> inline bool chmax(A &a, B b) { if (a<b) { a=b; return 1; } return 0; }
template<typename A, typename B> inline bool chmin(A &a, B b) { if (a>b) { a=b; return 1; } return 0; }
typedef long long ll;
typedef pair<int, int> pii;
const ll INF = 1e9+100;
const ll MOD = 1e9+7;
const bool debug = 0;
//-----------------------------------------------//

int main() {
	int N;
	int d[100];
	
	cin >> N;
	REP(i, N) scanf("%d", d + i);
	
	sort(d, d + N);
	
	int ans = unique(d, d + N) - d;
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <ctype.h>
using namespace std;
int main(void){
  int N, K;
  cin >> N >> K;
  int P[N];
  for(int i = 0 ; i < N; i++ ){
    cin >> P[i];
  }
  sort(P,P+N);
  
  int A = 0;
  for(int i = 0 ; i < K; i++ ){
    A = A + P[i];
  }
  cout << A << endl;
}


Measured memory_bytes: 3160
//
// Created by ?????°?????? on 2016/05/19.
//

#include <iostream>
#include <algorithm>
#include <queue>
using namespace std;
const int MAX = 10000;
const int INFTY = (1<<20);
const int WHITE = 0;
const int GRAY = 1;
const int BLACK = 2;

int n;
vector<pair <int,int> > adj[MAX];

void dijkstra(){
    priority_queue< pair<int,int> > PQ;
    int color[MAX];
    int d[MAX];
    for (int i = 0; i < n ; ++i) {
        d[i] = INFTY ;
        color[i] = WHITE;
    }

    d[0] = 0;
    PQ.push(make_pair(0,0));
    color[0] = GRAY;

    while ( !PQ.empty() ){
        pair <int,int> f = PQ.top(); PQ.pop();
        int u = f.second;
        color[u] = BLACK;

        if(d[u] < f.first * -1) continue;

        for (int j = 0; j < adj[u].size() ; ++j) {
            int v = adj[u][j].first;
            if (color[v] == BLACK) continue;
            if (d[v] > d[u] + adj[u][j].second){
                d[v] = d[u] + adj[u][j].second;
                PQ.push(make_pair(d[v]*(-1),v));
                color[v] = GRAY;
            }
        }
    }


    for (int i = 0; i < n; ++i) {
        cout << i << " " << (d[i] == INFTY ? -1 : d[i]) << endl;
    }
}

int main (){
    cin >> n;
    int k,c,u,v;
    for (int i = 0; i < n ; ++i) {
        cin >> u >> k;
        for (int j = 0; j < k ; ++j) {
            cin >> v >> c;
            adj[u].push_back(make_pair(v,c));
        }
    }

    dijkstra();

    return 0;
}

Measured memory_bytes: 6308
#include <iostream>

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

#define ALL(x) begin(x), end(x)
#define REP(i, n) for (size_t i = 0, i##_len = (n); i < i##_len; ++i)

int a (ll rank) {
  switch(rank) {
    case 1:
      return 300000;
    case 2:
      return 200000;
    case 3:
      return 100000;
  }
  return 0;
}

void solve(ll X, ll Y) {
  auto award = a(X) + a(Y);
  if (X == 1 && Y == 1) {
    award += 400000;
  }
  cout << award << endl;
}

int main() {
  ll X;
  cin >> X;
  ll Y;
  cin >> Y;
  solve(X, Y);
  return 0;
}


Measured memory_bytes: 256
/*
 * URL 		: 	
 * DATE		: 
 */

#include<bits/stdc++.h>
#pragma GCC optimize("O3")
using namespace std;

#define rep(i,a,b)  for(int i=a; i<b; i++)
#define req(i,a,b)  for(int i=b-1; i>=a; i--)
#define trv(it,s)   for(auto it=s.begin(); it!=s.end(); it++)
#define trs(it,s)   for(auto &it : s)

#define endl        '\n'
#define pb          push_back
#define F           first
#define S           second
#define ll          long long
#define pii         pair<int,int>
#define vi          vector<int>
#define vii         vector<vi>
#define mi          map<int,int>
#define umap        unordered_map
#define uset        unordered_set
#define all(a)      (a).begin(),(a).end()
#define sz(x)       (int)x.size()
#define fill(a,x)   memset(a,x,sizeof(a))
#define num1(x)     __builtin_popcount(x)

#define db(a)       cout<<"---DEBUG : "<<a<<"\n"
#define wa(x)       cout << (#x) << " -------- " << (x) << endl
#define line1	    printf("---------------------------------------\n")
#define line2	    printf("_______________________________________\n")

#define mod(x, m)   ((((x)%(m)) + (m)) % (m))

#define MOD         1000000007 
#define PI          2 * acos(0.0)

//#define int 		long long
//#define printf      //

void pmap(auto l){
	trv(itt,l) printf("%d %d\n", itt->fi, itt->se);
	line1;
}

void pvi(vector<int> pvec, string name="") {
	if(name != "") cout<<"Output of "<<name<<" : ";
	for(int i=0;i<pvec.size();i++) cout<<pvec[i]<<" ";
	cout<<endl;
}

int gcd(int n,int m){
	return m==0?n:gcd(m,n%m);
}

ll mpow(ll base, ll power){
	if(power==0) return 1;
	if(power==1) return base;
	ll exp = mpow(base,power/2);
	exp = exp*exp;
	if(power%2==1) exp = exp * base;
	return exp;
}

//___________________________________________________________________________________________________________

int n,k;
vi a;
vi b;
 
int gt(int ind){
	// wa(ind);

	if(b[ind] != -1) return b[ind];

	vi d(k,0);

	rep(i,1,k+1){
		d[i-1] = abs(a[ind] - a[ind-i]) + gt(ind-i);
	}

	b[ind] = *min_element(all(d));

	// pvi(b);
	// line1;
	return b[ind];
}

void solve() {

	cin>>n>>k;

	k = min(k,n);

	rep(i,0,n){
		int t;
		cin>>t;
		a.pb(t);
		b.pb(-1);
	}

	// pvi(a);
	// line1;

	rep(i,1,k+1){
		b[i] = abs(a[i] - a[0]);
	}

	// pvi(b);

	int ans = gt(n-1);

	cout << ans << endl;
}

//___________________________________________________________________________________________________________
int32_t main() {

	//ios_base::sync_with_stdio(false); cin.tie(NULL);


	int notc = 1; 
//	cin>>notc;

	while(notc--) {
		solve();
		//printf("========================================================\n");
	}
}


Measured memory_bytes: 49396
N, M = map(int, input().split())
As = list(map(int, input().split()))

rd = 0
c = 1
N_ = N * c
while(N_ % M != 0):
    c += 1
    N_ = c * N 
rd = N_ // M

As = As * (N_//N + 1)

ls = []
cnt = 0
for i in range(rd):
    lstmp = []
    for j in range(M):
        lstmp.append(As[cnt])
        cnt += 1
    ls.append(lstmp)

s = 0
for i in ls:
    s += max(i)-min(i)
print(s)



Measured memory_bytes: 20408
#include<iostream>
using namespace std;
void insertion(int A[],int N){
        for(int k=0;k<N;k++){
                cout << A[k];
                if(k<N-1)
                        cout<< ' ';
        }
        cout << endl;
        for(int i=1;i<N;i++){
                int v=A[i];
                int j=i-1;
                while(j>=0 && A[j]>v){
                        A[j+1]=A[j];
                        j--;
                }
                A[j+1]=v;
        for(int k=0;k<N;k++){
                cout << A[k];
                if(k<N-1)
                        cout<< ' ';
        }
                cout << endl;
        }
}

int main(){
        int N;
        int A[100];
        cin >> N;
        for(int i=0;i<N;i++)
                cin >> A[i];
        insertion(A,N);
        return 0;
}


Measured memory_bytes: 3084
#include <iostream>
#include <algorithm>
typedef long long ll;
using namespace std;

int main() {
    ll n, a, b;
    cin >> n >> a >> b;
    ll count = n % (a + b);
    ll sum = a * (n / (a + b));
    sum += min(count, a);
    cout << sum << endl;
    return 0;
}


Measured memory_bytes: 256
import numpy as np
a, b, h, m = map(int, input().split())

w1 = 360 * ((h+m/60)/12)
w2 = 360 * (m/60)

s = min(abs(w1-w2), 360-abs(w1-w2))
rad = np.deg2rad(s)
d = np.cos(rad)

ans = (a**2 + b**2 - 2*a*b*d)**0.5

print(ans)




Measured memory_bytes: 27204
#include<bits/stdc++.h>
#define ll long long
#define ld long double
#define mk make_pair
#define fi first
#define se second
#define vll vector<ll>
#define pii pair<ll,ll>
#define vvll vector< vector<ll> >
#define pb push_back
#define sz(v) (ll)(v).size()
#define inf 1e18
#define md 1000000007
#define all(v) (v).begin(),(v).end()
#define rep(i,a,b) for(ll i=a;i<b;++i)
#define tel(a){cout<<a<<"\n";}
#define tell(a,b){cout<<a<<" | "<<b<<"\n";}
#define telll(a,b,c){cout<<a<<" | "<<b<<" | "<<c<<"\n";}
#define teln(v,n){cout<<"v- ";rep(o,0,n)cout<<v[o]<<" ";cout<<"\n";}
#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
#define TRACE
 
#ifdef TRACE
#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


#define M 100010


int main(){
    IOS;
 	
	ll n,m,k;cin>>n>>m>>k;
	ll a[n],b[m];
	rep(i,0,n)cin>>a[i];
	rep(i,0,m)cin>>b[i];
	ll aa[n]={0},bb[m]={0};
	aa[0]=a[0],bb[0]=b[0];
	vll v;v.pb(b[0]);
	rep(i,1,n)aa[i]=aa[i-1]+a[i];
	rep(i,1,m)bb[i]=bb[i-1]+b[i],v.pb(bb[i]);
	ll x=0;
	rep(i,0,m)if(bb[i]<=k)x=max(x,i+1);
	rep(i,0,n){
		if(aa[i]>k)continue;
		auto it=upper_bound(all(v),k-aa[i]);
		if(it==v.begin())x=max(x,i+1);
		else {
			it--;
			x=max(x,i+1+(it-v.begin())+1);
		}
	}
 	cout<<x;
 	
    return 0;
}


Measured memory_bytes: 11584
// INCLUDES
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <cctype>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <unordered_map>
#include <queue>
#include <stack>
#include <algorithm>
#include <functional>
#include<assert.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp>
//DEFINES
#define MAX 1000001
#define pii pair<int, int>
#define F first
#define S second
#define all(s) begin(s),end(s)
#define MIN3POS(a, b, c) (a) =< (b) ? ((a) =< (c) ? 1 : 3) : ((b) =< (c) ? 2 : 3)
#define MAX3POS(a,b,c) (a) >= (b) ? ((a) >= (c) ? 1 : 3) : ((b) >= (c) ? 2:3)
#define endl '\n'
#define int long long
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define FOR(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define what_is(x) cerr << #x << 'is' << x << endl;
#define IOS   ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args);}
//NAMESPACES
using namespace __gnu_pbds; 
using namespace std;
//HELPERS
void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
cerr << *it << '=' << a << endl;
err(++it, args...);
}
vector<int> powers2(32,0);void initialize(){ for(int i=1;i<powers2.size();i++) powers2[i] = powers2[i-1]*2;}
int32_t main()
{
IOS
int n,k;
cin>>n>>k;
vector<int> v(n);
for(int i=0;i<n;i++)
cin>>v[i];
sort(all(v));
int sum = 0;
if(n<k)
cout<<0;
else {
    int sum = 0;
    for(int i=0;i<n-k;i++)
    sum+=v[i];
    cout<<sum;
}
return 0;
}
// Use emplace back in place of pushback
// Use tie function , for object destructuring

Measured memory_bytes: 1792
use std::io;
use std::cmp;

fn read_line() -> String {
	let mut line = String::new();
	let _ = io::stdin().read_line(&mut line);
	line.trim().to_string()
}

fn rd() -> Vec<String> {
	let mut vs : Vec<String> = vec![];
	for s in read_line().as_str().split(' ') {
//		println!("A {}", s);
		vs.push(s.to_string())
	}
	vs
}

fn to_i(s : &str) -> Result<usize, std::num::ParseIntError> {
	s.parse::<usize>()
}

fn main() {
	loop {
		let nn = to_i(&rd()[0]);
		if nn.is_err() {
			break
		}

		let n = nn.unwrap();
		let s = read_line().as_bytes().to_vec();
		let mut t = s.clone();
		let mut cost = 0;
		for i in 1..n {
			if s[i]==b'E' {
				t[i] = b'W';
				cost+=1;
			}
		}
		let mut ans = cost;
		for i in 1..n {
			if s[i-1]==b'W' && s[i-1]==t[i-1] {
				t[i-1] = b'E';
				cost+=1;
			}
			if s[i]!=t[i] {
				t[i] = s[i];
				cost-=1;
			}
			ans = cmp::min(ans, cost);
		}
		println!("{}", ans);
//		println!("[{}] [{}] [{}]", n, String::from_utf8(s.to_vec()).unwrap(), String::from_utf8(t.to_vec()).unwrap());
	}
}



Measured memory_bytes: 4352
#include<iostream>
#include<iomanip>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<functional>
#include<map>
#include<cstdlib>
#include<complex>
#include<numeric>
#include<set>
#include<deque>
#include<queue>

using namespace std;
using Int = long long;
Int INF = 1LL << 60;
const Int MOD = 1000000000 + 7;

template <class T>
ostream& operator<<(ostream& os, const vector<T>& vec) {
	for (const auto& e : vec) os << e << (&e == &vec.back() ? "\n" : " ");
	return os;
}
template <class T>
ostream& operator<<(ostream& os, const set<T>& st) {
	for (const auto& e : st) os << e << " ";
	return os;
}
template <class T1, class T2>
ostream& operator<<(ostream& os, const pair<T1, T2>& p) {
	os << "(" << p.first << "," << p.second << ")";
	return os;
}
template <class T1, class T2>
ostream& operator<<(ostream& os, const map<T1, T2>& mp) {
	for (const auto& e : mp) os << e << " ";
	return os;
}

#ifdef _DEBUG
template <class T>
void dump(const char* str, T&& h) { cerr << str << " = " << h << "\n"; };
template <class Head, class... Tail>
void dump(const char* str, Head&& h, Tail&&... t) {
	while (*str != ',') cerr << *str++; cerr << " = " << h << "\n";
	dump(str + (*(str + 1) == ' ' ? 2 : 1), t...);
}
#define DMP(...) dump(#__VA_ARGS__, __VA_ARGS__)
#else 
#define DMP(...) ((void)0)
#endif

int main() {

	cin.tie(nullptr);
	ios::sync_with_stdio(false);

	string s;
	cin >> s;

	Int len = s.size();
	Int cnt = 0;

	if (len%2==0) {
		for (Int i = 0; i < len/2; i++) {
			if (s[len/2+i]!=s[len/2-1-i]) {
				cnt++;
			}
		}
	}
	else {
		for (Int i = 1; i <= len/2; i++) {
			if (s[len/2+i]!=s[len/2-i]) {
				cnt++;
			}
		}
	}

	cout << cnt << "\n";
}


Measured memory_bytes: 256
N=gets.to_i

def f(s,c,n,max)
    if n == 0
        puts s
        return
    end

    ('a'..c).each do |d|
        max = [max,d].max
        f(s+d,max.next,n-1,max)
    end
end

f('','a',N,'a')

Measured memory_bytes: 14396
import java.util.*;
public class Main {

  public static void main(String[] args) { 
      Scanner sc = new Scanner(System.in);
      long a = sc.nextLong();
      long b = sc.nextLong();
      long gcd = gcd(a, b);
      Map<Long, Long> factMap = new HashMap<>();
      primeFactor(gcd, factMap);

      System.out.println(1 + factMap.size());
  }

  private static void primeFactor(long num, Map<Long, Long> factMap) {
    for(long i = 2; i * i <= num; i++) {
      long cnt = 0;
      while(num % i == 0) {
        cnt++;
        num = num / i;
      }
      if(cnt > 0) factMap.put(i, cnt);
    }
    if(num != 1) factMap.put(num, 1L);
  }

  private static long gcd(long a, long b) {
    if(b == 0)
      return a;
    return gcd(b, a % b);
  }
}

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

int main(){
  	string s; cin >> s;
  	string ans;
  	if(s[0] == s[1] && s[0] != s[2] && s[2] == s[3]){
      	ans="Yes";
    }else if(s[0] != s[1] && s[0] == s[2] && s[1] == s[3]){
    	ans="Yes";
    }else if(s[0] != s[1] && s[1] == s[2] && s[0] == s[3]){
    	ans="Yes";
    }else{
    	ans="No";
    }
  
  	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 764
#include<cstdio>

using namespace std;

int main(){
	for(int n,q;scanf("%d%d",&n,&q),n;){
		int buc[101]={};
		for(int i=0;i<n;i++){
			int m;	scanf("%d",&m);
			for(int j=0;j<m;j++){
				int d;	scanf("%d",&d);
				buc[d]++;
			}
		}

		int ans=1;
		for(int i=1;i<=100;i++){
			if(buc[ans]<buc[i])	ans=i;
		}
		printf("%d\n",buc[ans]<q?0:ans);
	}

	return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define pb push_back
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) FOR(i, 0, n)
#define ll long long
using namespace std;

const ll P = 1000000007;
const long long INF = 1LL << 60;
int gcd(int a, int b) { return b != 0 ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a / gcd(a, b) * b; }

int main()
{
  cout << fixed << setprecision(10);
  int N;
  cin >> N;
  vector<ll> A(N);
  int count = 0;
  ll m = P;
  rep(i,N) 
  {
    cin >> A[i];
    if(A[i]<0)
    {
      count ++;
      A[i] = -1 * A[i];
    }
    m = min(m,A[i]);
  }
  ll sum = 0;
  rep(i,N) 
  {
    sum += A[i];
  }
  if(count%2==0)
  {
    cout << sum << endl;
  }
  else
  {
    cout << sum - m * 2 << endl;
  }
  return 0;
}


Measured memory_bytes: 4044
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i, a, b) for(ll i=(a); i<(b); i++)
#define PER(i, a, b) for(ll i=(a); i>=(b); i--)
#define rep(i, n) REP(i, 0, n)
#define per(i, n) PER(i, n, 0)
#define ALL(a)  (a).begin(),(a).end()
const ll INF = 1e18+18;
const ll MAX = 200000;
const ll MOD = 1000000007;
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl;
#define YES(n) cout << ((n) ? "YES" : "NO") << endl;
static const double pi = 3.141592653589793;



int main(){
    ll N;
    cin>>N;
    cout<<N/3<<endl;
}

Measured memory_bytes: 256
import java.util.*;
public class Main {
        static Scanner sc = new Scanner(System.in);
        static void myout(Object t){System.out.println(t);}
        static void myerr(Object t){System.err.println(t);}
        static String getStr(){return sc.next();}
        static int getInt(){return sc.nextInt();}
        static Long getLong(){return sc.nextLong();}
        static boolean isNext(){return sc.hasNext();}
  		static String[] splitSingle(String str){return str.split("");}
        public static void main(String[] args){
          String[] s = splitSingle(getStr());
          long k = getLong();
          if(k > s.length){
            k = s.length;
          }
          String output = "1";
          for(int i = 0; i < k; i++){
            String tmp = s[i];
            if(!tmp.equals("1")){
              output = s[i];
              break;
            }
          }
          myout(output);
        }
        //便利メソッド追加枠ここから

        //便利メソッド追加枠ここまで
}


Measured memory_bytes: 23380
import java.util.*;
import java.io.*;

public class Main {
    public static void main(String[] args) throws Exception {

        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out));
        
        String[] input = br.readLine().split(" ");
        int a = Integer.parseInt(input[0]);
        int b = Integer.parseInt(input[1]);
        
        StringBuilder sb1 = new StringBuilder();
        StringBuilder sb2 = new StringBuilder();
        
        for(int i = 0; i < b; i++){
            sb1.append(a);
        }
        
        for(int i = 0; i < a; i++){
            sb2.append(b);
        }
        
        out.println(sb1.compareTo(sb2) > 0 ? sb2 : sb1);
        out.close();
        
    }
}

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

int main() {
    //変数定義, 入力処理
    // vector<vector<int>> data(3, vector<int>(4)); //二次元配列
    int R;
    cin >> R;
    //処理

    //出力処理
    cout <<  R * 2 * 3.14159 << endl;
    return 0;
}


Measured memory_bytes: 3784
n=int(input())
xyh=[[int(i) for i in input().split()] for j in range(n)]
xyh.sort(key=lambda x:x[2],reverse=True)


for i in range(101):
    for j in range(101):
        h=xyh[0][2]+abs(xyh[0][0]-i)+abs(xyh[0][1]-j)
        for k in xyh:
            if k[2]==max(h-abs(k[0]-i)-abs(k[1]-j),0):
                continue
            else:
                break
        else:
            print(i,j,h)


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

int64_t cal(int n){
	return (int64_t)n*(n-1)/2;
}

int main(){
	cin.tie(0),ios::sync_with_stdio(false);
	int n;
	cin>>n;
	vector<int>a(n),c(n,0);
	for(auto&i:a){
		cin>>i;
		++c.at(--i);
	}
	int64_t ans=0;
	for(auto&i:c)ans+=cal(i);
	for(auto&i:a){
		cout<<ans-cal(c.at(i))+cal(c.at(i)-1)<<"\n"s;
	}
}

Measured memory_bytes: 4224
#include <iostream>
#include <stdio.h>
#include <string>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <math.h>
#include <vector>
#include <algorithm>

using namespace std;

int main(){
	long long n;
	cin >> n;
	int min=11;
	for(long long i=1; i*i<=n; i++){
		if(n%i==0){
			string a=to_string(i), b=to_string(n/i);
			int f=max(a.length(), b.length());
			if(f<min) min=f;
		}
	}
	cout << min << endl;
	return 0;
}

Measured memory_bytes: 256
import collections
n = int(input())
a = list(map(int, input().split()))
c = collections.Counter(a)
d = {}
m = 0
for e in c:
  m += (c[e] * (c[e] - 1) // 2)
  if c[e] == 1:
    d[e] = 0
  elif c[e] == 2:
    d[e] = 1
  else:
    d[e] = (c[e] * (c[e] - 1) // 2) - ((c[e] - 1) * (c[e] - 2) // 2)
for i in range(n):
  print(m - d[a[i]])

Measured memory_bytes: 34196
#include <iostream>
#include <vector>
#include <math.h>
#include <string>
#include <string.h>
#include <stack>
#include <algorithm>
#include <stdio.h>
#include <functional>
using namespace std;
 
int main()
{
	cout << 14 << endl << 266 << endl << 11162 << endl << 50240 << endl << 71084 << endl;
	return 0;
}

Measured memory_bytes: 1116
S = input()

odd = ['R', 'U', 'D']
even = ['L', 'U', 'D']

flag = True
for i, e in enumerate(S):
  if i % 2 == 0:
    if e not in odd:
      flag = False
  else:
    if e not in even:
      flag = False
      
if flag:
  print('Yes')
else:
  print('No')

Measured memory_bytes: 3064
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<string.h>
#include<vector>
#include<queue>
#include<math.h>
#define MAX_N 100000
using namespace std;

int s[MAX_N];
int n=0;

int chk(int x){
 int a[n];
 for (int i=0;i<n;i++) a[i]=s[i];
 int i=x-1;
 /*while (i+x<=n&&i>=0){
  if (a[i]==1){
   for (int j=0;j<x;j++){
    if (a[i+j]==0) a[i+j]=1;
    else if (a[i+j]==1) a[i+j]=0;
   }
  }
   
  for (int j=0;j<n;j++) cout <<a[j];
 cout <<endl;
  i--;
 }*/
 int y=a[0],c=0;
 for (int k=0;k+x-1<n;k++) {
  //cout <<a[k]<<" "<<k<<endl;
  if (y!=a[k]) {y=a[k]; c++;}
 }
 //cout <<"c="<<c<<endl;
 int res=1;
 //for (int k=n-x;k<x;k++)  {res*=(a[0]==((a[k]+c%2)%2)); /*cout <<"k="<<k<<endl;*/}
 for (int j=n-x;j<x;j++) res*=(a[j]==a[n-x]);

 
 return res;
}
  


int main(){
 char S[MAX_N];
 while (cin >>S[n]) {
  if (S[n]=='0') s[n]=0;
  else if (S[n]=='1') s[n]=1;
  n++;
 }
 

 /*for (int i=0;i<n;i++) cout <<s[i];
 cout <<endl;*/

 int i=0,j=0,k=0;
 while (s[i]==1&&i<n) i++;
 if (i==n) k=n;
 while (s[i+j]==0&&i+j<n) j++;
 k=j;
 j--;
 //右方向
 int r=0,rk=j+1;
 while(s[i+j+r+1]==1&&i+j+r<n) r++;
 if (i+j+r+k<n) rk+=r;
 rk=max(rk,r);
 k+=max(0,n-k-1);
 
 //左方向
 int l=0; 
 while (s[i-l-1]==1&&i-l>=0) l++;
 if (i-l-k>=0) k+=l;
  
 int a=n/2,b=n,c=(a+b)/2;
 while (b-a>1){
  //printf("a,b=%d,%d\n",a,b);
  c=(a+b)/2;
  if (chk(c)) a=c;
  else b=c;
 }
 if (chk(n)) a=n;
  cout <<a<<endl;






 /*printf("%d %d %d %d\n",i,j,r,l);
 cout <<k<<endl;
 cout <<max(j+1,max((n-1-i)/2+1,l))<<endl;*/
}

Measured memory_bytes: 1152
#include<bits/stdc++.h>
using namespace std;
int main(){
  int64_t n,k;
  cin >> n >>k;
  int64_t a[n]={};
  for(int64_t i=0;i<n;i++)cin >> a[i];
  for(int64_t j=k;j<n;j++){
    if(a[j-k]<a[j])cout << "Yes" << endl;
    else cout << "No" << endl;
  }
}


Measured memory_bytes: 5208
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cstring>
#include <stack>
#include <utility>
#include <map>
#include <cmath>
#include <stack>
#include <queue>
#include <deque>
#include <cstdlib>
#include <set>
#include <chrono>
#include <climits>
#include <unordered_map>
#include <iomanip> 

#define pii pair<int,int>
#define vi vector<int>
#define ll long long
#define pb push_back
#define mp make_pair
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL)
#define repf(i,st,end,inc) for(int i = st; i < end; i += inc)
#define repb(i,st,end,dec) for(int i = st; i >= end; i -= dec) 

#define MOD 1000000007

#define trace1(a) cout << a << endl;
#define trace2(a,b) cout << a << " | " << b << endl;
#define trace3(a,b,c) cout << a << " | " << b << " | " << c << endl;
#define trace4(a,b,c,d) cout << a << " | " << b << " | " << c << " | "<< d << endl;

using namespace std;
using namespace std::chrono;


int main(){
	fast;
	#ifdef LOCAL_PROJECT
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
	#endif

	auto start = high_resolution_clock::now(); 

	ll a, b;
	cin >> a >> b;
	if (a <= 9 && b <= 9)
		cout << a * b << endl;
	else
		cout << "-1" << endl;

	auto stop = high_resolution_clock::now(); 
	auto duration = duration_cast<microseconds>(stop - start);	
	// cout << endl;
	// cout << fixed << setprecision(9) << double(duration.count()) / 1000000 << endl; 

	return 0;
}


Measured memory_bytes: 256
object Main extends App {
	val pw = new java.io.PrintWriter(System.out)

	@scala.annotation.tailrec
	def loop(start: Int, end: Int)(f: Int => Unit): Unit =
		if (start < end) {
			f(start)
			loop(start + 1, end)(f)
		}

	val a, b, c, d = Scanner.nextLong

	pw.println(Seq(a * c, b * c, a * d, b * d).max)
	pw.flush()
}

object Scanner {
	private val buf = new Array[Byte](1024); private var ptr = 0; private var len = 0

	@inline private def isPrintableChar(c: Int): Boolean = 33 <= c && c <= 126
	@inline private def hasNextByte(): Boolean = if (ptr >= len) { ptr = 0; len = System.in.read(buf); len > 0 } else true
	@inline private def hasNext(): Boolean = {
		while (hasNextByte() && !isPrintableChar(buf(ptr))) ptr += 1
		hasNextByte()
	}
	@inline private def readByte(): Byte = if (hasNextByte()) { val res = buf(ptr); ptr += 1; res } else -1

	def next(): String = {
		if(!hasNext()) ???
		val sb = new StringBuilder; var b = readByte()
		while (isPrintableChar(b)) { sb.append(b.toChar); b = readByte() }
		sb.toString
	}

	def nextInt(): Int = {
		val n = nextLong()
		if (n < Int.MinValue || Int.MaxValue < n) ???
		n.toInt
	}

	def nextLong(): Long = {
		if(!hasNext()) ???
		var minus = false; var b = readByte()
		if (b == '-') { minus = true; b = readByte() }

		@scala.annotation.tailrec
		def go (b: Byte, n: Long = 0): Long = if ('0' <= b && b <= '9') go(readByte(), n * 10 + b - '0') else if (minus) -n else n

		go(b)
	}

	def nextDouble(): Double = next().toDouble
}


Measured memory_bytes: 54716
#include <algorithm>
#include <vector>
#include <array>
#include <set>
#include <map>
#include <cmath>
#include <iostream>
#include <iomanip>
#include <numeric>
#include <fstream>
#include <math.h>

using namespace std;

int main(void)
{
	int n;
	cin >> n;
	uint64_t x = 1, y = 1;
	for (int i = 0; i < n; i++) {
		int t, a;
		cin >> t >> a;
		uint64_t j = max(ceil((long double)x/t), ceil((long double)y/a));
		x = t*(j);
		y = a*(j);
	}
	cout << x+y << endl;

	return 0;
}


Measured memory_bytes: 256
import java.util.*;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int m = sc.nextInt();
		int[] a = new int[n], b = new int[n];
		int[] c = new int[m], d = new int[m];
		for(int i = 0; i < n; i++) {
			a[i] = sc.nextInt();
			b[i] = sc.nextInt();
		}
		for(int j = 0; j < m; j++) {
			c[j] = sc.nextInt();
			d[j] = sc.nextInt();
		}
		int dist, min_dist, checkpoint;
		for(int i = 0; i < n; i++) {
			min_dist = Math.abs(a[i] - c[0]) + Math.abs(b[i] - d[0]);
			checkpoint = 0;
			for(int j = 1; j < m; j++) {
				dist = Math.abs(a[i] - c[j]) + Math.abs(b[i] - d[j]);
				if(dist < min_dist) {
					min_dist = dist;
					checkpoint = j;
				}
			}
			System.out.println(checkpoint + 1);
		}
	}
}

Measured memory_bytes: 21844
n, y = gets.split(" ").map(&:to_i)
results = [-1, -1, -1]
# 大域脱出
catch(:break_loop) do
  break if 1000 * n > y
  break if 10000 * n < y
  (0..n).each do |t10|
    next if 5000 * (n - t10) + 10000 * t10 < y
    (0..(n - t10)).each do |t5|

      sabun = y - (10000 * t10 + 5000 * t5)
      t1, r = sabun.divmod(1000)
      next unless r.zero?

      if t10 + t5 + t1 == n
        results = [t10, t5, t1]
        throw :break_loop
      end
    end
  end
end
print results.join(' ')


Measured memory_bytes: 1788
import java.io.*;
import java.util.*;

class Main{
	public static void main(String[] args) throws IOException{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String[] str = br.readLine().split(" ");
		int q = Integer.parseInt(str[0]);
		SortedMap<String, ArrayList<Integer>> mpa = new TreeMap<String, ArrayList<Integer>>();
		for(int i = 0; i < q; i++){
			str = br.readLine().split(" ");
			int op = Integer.parseInt(str[0]);
			if(op == 0){
				String key = str[1];
				int x = Integer.parseInt(str[2]);
				if(mpa.get(key) == null){
					mpa.put(key, new ArrayList<Integer>());
				}
				mpa.get(key).add(x);
			}else if(op == 1){
				String key = str[1];
				if(mpa.get(key) == null) continue;
				Iterator<Integer> it = mpa.get(key).iterator();
				while(it.hasNext()) System.out.println(it.next());
			}else if(op == 2){
				String key = str[1];
				if(mpa.get(key) == null) continue;
				mpa.get(key).clear();
			}else{
				String L = str[1];
				String R = str[2] + "#";
				SortedMap<String, ArrayList<Integer>> mpb = mpa.subMap(L, R);
				for(String s : mpb.keySet()){
					for(Integer num : mpb.get(s)) System.out.println(s + " " + num);
				}
			}
		}
	}
}



Measured memory_bytes: 138232
#include <bits/stdc++.h>
using namespace std;
//const int MOD=1e9+7;
const int MOD=998244353;
const int INF=1e9;
const long long LINF=1e18;
#define int long long
//template
template <typename T>
void fin(T a){
  cout<<a<<endl;
  exit(0);
}
int pw(int n,int k){
  if(k<0)return pw(n,k+MOD-1);
  int res=1;
  while(k){
    if(k&1)res*=n;res%=MOD;
    n*=n;n%=MOD;
    k>>=1;
  }
  return res;
}
//main
signed main(){
  int N;cin>>N;
  std::vector<int> x(N);
  for(int i=0;i<N;i++)cin>>x[i];
  int ans=0;
  for(int i=0;i<N;i++){
    ans+=(x[i]*pw(1+x[i],i)%MOD)*pw(2,N-i-1)%MOD;
    ans%=MOD;
  }
  fin(ans);
}



Measured memory_bytes: 10816