akhauriyash/Code-Regression huggingface dataset:
def rec(N,X):
    if N==0:
        return 1
    if X==0:
        return 0
    if 1<=X and X<=a[N-1]:
        return rec(N-1,X-1)
    if X==a[N-1]+1:
        return p[N-1]+1
    if a[N-1]+1<X:
        return rec(N-1,X-a[N-1]-2)+p[N-1]+1

N,X=map(int,input().split())
A,P=1,1
a,p=[],[]
for i in range(51):
    a.append(A);p.append(P)
    A=A*2+3;P=P*2+1
print(rec(N,X-1))

Measured memory_bytes: 61880
def readinput():
    n=int(input())
    return n

def main(n):
    x7=int(n/1.07)
    x8=int(n/1.08)
    x9=int(n/1.09)
    n100=n*100
    for x in range(max(1,x9-1),x7+1+1):
        xx=x*108//100
        #print(x,xx)
        if xx==n:
            print(x)
            break
    else:
        print(':(')

        

if __name__=='__main__':
    n=readinput()
    main(n)


Measured memory_bytes: 9188
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rep_ll(i,n) for(ll i = 0; i < (ll)(n); i++)
using namespace std;
typedef long long ll;
typedef unsigned long long u_ll;
typedef pair<int, int> pair_;
const long double PI = (acos(-1));
const int INF = 1001001001;
const int dx[] = {-1, 0, 1, 0}; const int dy[] = {0, -1, 0, 1};
ll mod = 1000000007;
int main(){
    int k;
    cin >> k;
    vector<ll> a;
    int keta = 1;
    for(int i=1; i<10; i++) a.push_back(i);
    while(1){
        if(k<=a.size()){
            cout << a[k-1];    
            return 0;//プログラム終了
        }
        k-=a.size();
        vector<ll> old;
        swap(a, old);//oldとaを入れ替え, aが空, oldが桁毎の値になる
        for(ll x: old){//toproop
            for(int j=-1; j<=1; j++){
                int d = x%10 + j;
                if(d<0||d>9) continue;
                ll num = x*10 + d;
                a.push_back(num);
            }
        }
    }
}

Measured memory_bytes: 4668
def has_duplicates(seq):
    return len(seq) != len(set(seq))
import sys

s = int(input())
a = []
a.append(s)

for i in range(0,10**6):
    if a[i] % 2 == 0:
        a.append(a[i]/2)
    else:
        a.append(3*a[i]+1)
    
    if has_duplicates(a) == True:
        print(i+2)
        sys.exit()

Measured memory_bytes: 3060
//ssenseeeeeeeeeeeeeeeeeeeeeeeeeeeee
#include<bits/stdc++.h>
#define startt ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
typedef unsigned long long ull;
typedef long long  ll;
#define MOD 1000000007
#define MX 1000000000
#define NMAX 100005
#define MXL 1000000000000000000
#define PI 3.14159265
#define pb push_back
using namespace std;
#define sc second
#define endl '\n'
#define fr first
//read contraints to make sure its not brute force

int main()
{
    ll n;
    cin >> n;
    ll ans = 0;
    for(int i = 1; i <= n;i++)
    {
        ll a = n/i;
        if(i*a >= n)
        {
            a--;
        }
        ans += max(0LL, a);
    }
    cout << ans << endl;
}



Measured memory_bytes: 3592
#pragma GCC optimize(2)
#pragma GCC optimize(3)
#pragma GCC optimize(4)
#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define pi acos(-1.0)
#define LL long long
//#define mp make_pair
#define pb push_back
#define ls rt<<1, l, m
#define rs rt<<1|1, m+1, r
#define ULL unsigned LL
#define pll pair<LL, LL>
#define pli pair<LL, int>
#define pii pair<int, int>
#define piii pair<pii, int>
#define mem(a, b) memset(a, b, sizeof(a))
#define fio ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define fopen freopen("in.txt", "r", stdin);freopen("out.txt", "w", stout);
//head

const int N = 105;
int a[N];
int main() {
    int n;
    scanf("%d", &n);
    int s = 0;
    for (int i = 1; i <= n; i++) scanf("%d", &a[i]), s += a[i];
    int ans = 0;
    int mx = INT_MAX;
    for (int i = 1; i <= n; i++) {
        if(abs(a[i]*n - s) < mx) {
            mx = abs(a[i]*n - s);
            ans = i;
        }
    }
    printf("%d\n", ans-1);
    return 0;
}


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

int main() {
    int a,n,mx=-1e9+5, mn=1e9+5;
    cin>>n;
    for(int i=0;i<n;++i) {
        cin>>a;
        if(a>mx) mx = a;
        if(a<mn) mn = a;
    }
    cout<<mx-mn;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
    int a,b,k;
    scanf("%d %d %d",&a,&b,&k);

    if(b-a+1<k*2){
        for(int i=a;i<=b;i++)
            printf("%d\n",i);
    }
    else{
        for(int i=0;i<k;i++)
            printf("%d\n",a+i);
        for(int i=b-k+1;i<=b;i++)
            printf("%d\n",i);
    }
}

Measured memory_bytes: 256
use std::io;
use std::str::FromStr;

fn input<T:FromStr>() -> T {
    let mut line: String = String::new();
    io::stdin().read_line(&mut line);
    line.trim().parse().ok().unwrap()
}

fn input_tuple() -> (i64, i64) {
    let mut line: String = String::new();
    io::stdin().read_line(&mut line);
    let vec: Vec<i64> = line.split_whitespace().map(|s| s.parse().unwrap()).collect();
    (vec[0], vec[1])
}

fn input_vec() -> Vec<i64> {
    let mut line: String = String::new();
    io::stdin().read_line(&mut line);
    line.split_whitespace().map(|s| s.parse().unwrap()).collect()
}

fn main() {
    let n: i64 = input();
    let (t, a) = input_tuple();
    let h_vec = input_vec();
    let mut min = std::i64::MAX;
    let mut ans = 0;
    for i in 0..h_vec.len() {
        if (t * 1000 - h_vec[i] * 6 - a * 1000).abs() < min {
            min = (t * 1000 - h_vec[i] * 6 - a * 1000).abs();
            ans = i;
        }
    }
    println!("{}", ans + 1);
}


Measured memory_bytes: 2080
#include <stdio.h>

#include <algorithm>
#include <cmath>
#include <functional>
#include <iostream>
#include <numeric>
#include <queue>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
typedef long long ll;
const ll BIGMOD = 1e9 + 7;
using namespace std;

int main() {
  char a;
  scanf("%c", &a);
  printf("%c\n", a + 1);
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<tuple>
#include<cassert>
using namespace std;
typedef long long ll;
typedef unsigned int ui;
const ll mod = 1000000007;
const ll INF = (ll)1000000007 * 1000000007;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define Per(i,sta,n) for(int i=n-1;i>=sta;i--)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef long double ld;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<ll, ll> LP;
int dx[4]={1,-1,0,0};
int dy[4]={0,0,1,-1};

int n,x,t;

void solve(){
    cin >> n >> x >> t;
    int s=0,ans=0;
    while(s<n){
        s+=x;
        ans+=t;
    }
    cout << ans << endl;
}

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

Measured memory_bytes: 3648
#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp> // Common file
//#include <ext/pb_ds/tree_policy.hpp> // Including seg_tree_order_statistics_node_update
#include <stdio.h>
#include <cassert>
using namespace std;
//using namespace __gnu_pbds;
typedef long long lo;
typedef pair<lo,lo> ll;//pair
typedef vector<lo> vl;  //vector of long
typedef vector<ll > vll;   //vector of pair
typedef priority_queue<lo>p_q;
typedef vector< vl > vvl;  //vector of vectors
#define X first
#define Y second
#define mp(a,b) make_pair((a),(b))
#define REP(a,b) for(lo i=(a);i<(lo)b;i++)//no need to declare variable i
#define REPE(a,b,c,d) REP(a,b)for(lo j=(c);j<(lo)d;j++)//no need to declare vaiables i,j
#define REPV(a,b,c) for(lo(a)=b;(a)<(c);(a)++)//a is the variable
#define IREP(a,b) for(lo i=(a);i>=(b);i--)
#define IREPV(a,b,c) for(lo(a)=b;(a)>=(c);(a)--)
#define all(v) (v).begin(),(v).end()
#define TRV(a) for(auto it : a)
#define INF 100001
//#define MOD lo(1e17)
#define M 1000000007
#define CHECK_BIT(var,pos) ((var) & (1<<(pos)))
#define pb(a) push_back((a))
#define endl "\n"
#define eps 1e-9
#define PI 3.141592653589793
template<typename T> ostream& operator<< ( ostream &o,vector<T> v ) {
    if ( v.size() >0 )o<<v[0];
    for ( unsigned   i=1; i<v.size(); i++ )o<<" "<<v[i];
    return o<<endl;
}
template<typename U,typename V> ostream& operator<< ( ostream &o,pair<U,V> p ) {
    return o<<"("<<p.first<<", "<<p.second<<") ";
}
template<typename T> istream& operator>> ( istream &in,vector<T> &v ) {
    for ( unsigned   i=0; i<v.size(); i++ )in>>v[i];
    return in;
}
template<typename T> istream& operator>> ( istream &in,pair <T,T> &p ) {
    in>>p.X;
    in>>p.Y;
    return in;
}


int main(){
        lo h,n,w,t,temp;
        cin>>t;
        lo t1,t2;
        REPE(1,3501,1,3501){
                t1=(t*i*j);
                t2=4*i*j-(t*j)-t*i;
                if(t2<1)continue;
                if(t1%t2==0)
                        {cout<<i<<" "<<j<< " "<<t1/t2<<endl;return 0;}
        }
        return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
#define M 20000000
#define L 14
int getChar(char ch);
long long getKey(char str[L]);
//int h1(int key);
//int h2(int key);
int find(char str[L]);
void insert(char str[L]);
char H[M][L];
int getChar(char ch){
  if ( ch == 'A') return 1;
  else if ( ch == 'C') return 2;
  else if ( ch == 'G') return 3;
  else if ( ch == 'T') return 4;
  return 0;
}
/* convert a string into an integer value */
long long getKey(char str[L]){
  long long sum = 0, p = 1, i;
  for ( i = 0; i < strlen(str); i++ ){
    sum += p*(getChar(str[i]));
    p *= 5;
  }
  return sum;
}
//int h1(int key){ return /* your task */; }
//int h2(int key){ return /* your task */; }

int find(char str[L]){
  int key;
  key=getKey(str);
  if(H[key][0]=='\0') return 0;
  else return 1;
}

void insert(char str[]){
  strcpy(H[getKey(str)],str);
}

int main(){
    int i, n, h;
    char str[L], com[9];
    //for ( i = 0; i < M; i++ ) H[i][0] = '\0';
    
    scanf("%d", &n);
    
    for ( i = 0; i < n; i++ ){
	scanf("%s %s", com, str);
	
	if ( com[0] == 'i' ){
	    insert(str);
	} else {
	    if (find(str)){
		printf("yes\n");
	    } else {
		printf("no\n");
	    }
	}
    }
    return 0;
}

Measured memory_bytes: 118548
#include<iostream>
#include<string>
#include<vector>
#include<unordered_map>
#include<algorithm>
#include<cmath>
#include<climits>
#include<iomanip>
#include<bitset>
#include<cstdlib>
#include<queue>
#include<utility>
using namespace std;

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)

typedef long long ll;
typedef vector<vector<int>> Graph;

int main() {
	//入力;
	ll N;
	cin >> N;

	ll ans = 0;
	if(!(N%2)){
		ll pow5 = 5;
		do{
			ans += N / (pow5*2);
			pow5 *= 5;
		} while (N / pow5);
	}
	cout << ans << endl;


	//小数点以下の桁数表示;
	//cout << fixed << setprecision(15);

	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<functional>
#include<math.h>

#define rep(i,n) for(int i=0;i<(n);i++)
typedef long long ll;
using namespace std;

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

	int cnt = 0;
	double m4 = 1.0 / 4 / m;
	m4 *= sum;
	rep(i, n) {
		if (a[i] >= m4) cnt++;
	}

	puts(cnt >= m ? "Yes" : "No");

	return 0;
}


Measured memory_bytes: 256
import java.util.*;

class Main{

    public static void main(String args[]) throws Exception{
        Main main = new Main();
    }

    public Main(){
        Scanner scanner = new Scanner(System.in);
        String S = scanner.next();
        int L = S.length();

        for(int i=0;i<L;i++){
            System.out.print("x");
        }

        System.out.println("");
    }
}


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

using namespace std;




deque<int> q;
int v[100001];

int main()
{
    int k;
    v[1]=1;
    cin>>k;
    q.push_back(1);

    while(!q.empty()){
        int d=q.front();
        q.pop_front();


        if(d==0) {
            cout<<v[d];
            return 0;
        }

        int i=(d*10)%k;

        if(v[i]==0||v[i]>v[d]){
           v[i]=v[d];
            q.push_front(i);

        }
        i++;
        i=i%k;

        if(v[i]==0||v[i]>v[d]+1){
           v[i]=v[d]+1;
            q.push_back(i);

        }
    }
    return 0;
}


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

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define ITR(x,c) for(__typeof(c.begin() x=c.begin();x!=c.end();x++)
#define RITR(x,c) for(__typeof(c.rbegin() x=c.rbegin();x!=c.rend();x++)
#define setp(n) fixed << setprecision(n)

#define lf double
#define ll long long
#define vll vector<ll>
#define vi vector<int>
#define pll pair<ll,ll>
#define pi pair<int,int>

#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define ins insert

using namespace std;

ll n;
ll ans=0;

void dfs(ll x, int mask)
{
	if (x>n) return;
	if (mask==7) ans++;
	dfs(10*x+7, mask|1);
	dfs(10*x+5, mask|2);
	dfs(10*x+3, mask|4);
}

int main(void)
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	cin>>n;
	dfs(0, 0);
	cout << ans << "\n";
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

int main(){
	int a,b,i;
	char s[15];
	scanf("%d%d%s",&a,&b,s);
	if(s[a]!='-'){
		puts("No");
		return 0;
	}
	for(i=0;i<a+b+1;i++){
		if(i!=a){
			if(s[i]!='0'&&s[i]!='1'&&s[i]!='2'&&
			s[i]!='3'&&s[i]!='4'&&s[i]!='5'&&
			s[i]!='6'&&s[i]!='7'&&s[i]!='8'&&
			s[i]!='9'){
				puts("No");
				return 0;
			}
		}
	}
	puts("Yes");
	return 0;
}

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

int main(){
  char s[100],p[100];
  unsigned int i,k;
  
  scanf("%s\n%s",s,p);

  for(i=0;i<strlen(s);++i){
    for(k=0;k<strlen(p);++k){
      if(i+k >= strlen(s)){
	if(p[k] != s[i + k - strlen(s)]) break;
      }
      else if(p[k] != s[i + k]) break;

      if(k == strlen(p)-1){
	printf("Yes\n");
	return 0;
      }
    }
  }

  printf("No\n");
  return 0;
}



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

using namespace std;

int main() {
	string S, T,a;
	cin >> S >> T;
	int i;
	i = T.length();
		if (S == T.substr(0,i-1)) {
			cout << "Yes" << endl;
	}
		else {
			cout << "No" << endl;
		}

}

Measured memory_bytes: 3632
def run(K):
    n_max = 500
    '''
    K <= 500の場合は、n = Kとして1行につき1色を塗ればよい
        111
        222
        333
    Kが4の倍数の場合は、n = K/2以下の塗り方ができる
        1234
        5678
        3412
        7856
    上記でn+i+1色をi色に塗り替えても条件を満たす
        1234
        5178
        3412
        7851
    K = 1000の時は、n = 500で満たし、塗り替え操作で501～999まで表現できる
    '''
    n = 0
    trouts = []
    if K <= n_max:
        n = K
        for i in range(K):
            trouts.append([i+1]*K)
    else:
        n = n_max
        change = n_max*2 - K
        c1 = [i for i in range(1, n_max+1)]
        # c - 1 + n_max - c + 1 (c>0)
        # 0 + n_max (c==0)
        c2 = [i for i in range(2, change+1)] + [i for i in range(n_max+1, n_max*2+1-change)]
        if change > 0:
            c2 += [1]
        for i in range(n_max):
            shift = (i//2) * 2
            if i % 2 == 0:
                trouts.append(c1[shift:] + c1[:shift])
            else:
                trouts.append(c2[shift:] + c2[:shift])
    return (n, trouts)


def main():
    K = int(input())
    n, trouts = run(K)
    print(n)
    for i in range(len(trouts)):
        print(' '.join(map(str, trouts[i])))


if __name__ == '__main__':
    main()


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

long long mod = 1000000007;

class UnionFind
{
public:
   vector<int> parent;
   UnionFind(int N)
   {
      for (int i = 0; i < N; i++)
      {
         parent.push_back(-1);
      }
   }
   int root(int A)
   {
      if (parent[A] < 0)
         return A;
      return parent[A] = root(parent[A]);
   }
   int size(int A)
   {
      return -parent[root(A)];
   }

   bool unite(int A, int B)
   {
      A = root(A);
      B = root(B);
      if (A == B)
         return false;
      if (size(A) < size(B))
         swap(A, B);
      parent[A] += parent[B];
      parent[B] = A;
      return true;
   }
};

int main(void)
{
   int N;
   cin >> N;
   vector<int> X(N), L(N);
   vector<pair<int, int>> robot;
   for (int i = 0; i < N; i++)
   {
      cin >> X[i] >> L[i];
      robot.push_back({X[i] + L[i], X[i] - L[i]});
   }
   sort(robot.begin(), robot.end());
   int now = -1000000007;
   int ans = 0;
   for (int i = 0; i < N; i++)
   {
      if (robot[i].second >= now)
      {
         ans++;
         now = robot[i].first;
      }
   }
   cout << ans << endl;
   return 0;
}


Measured memory_bytes: 5056
#include<iostream>
#include<algorithm>
#include<string.h>
#include<map>
#include<string>
#include<math.h>
#include<stdio.h>
#pragma GCC optimize(2)
#define Swap(a,b)  a ^= b ^= a ^= b
using namespace std;
typedef long long ll;
inline ll read() {
	ll c = getchar(), Nig = 1, x = 0;
	while (!isdigit(c) && c != '-')c = getchar();
	if (c == '-')Nig = -1, c = getchar();
	while (isdigit(c))x = ((x << 1) + (x << 3)) + (c ^ '0'), c = getchar();
	return Nig * x;
}
inline void Out(ll a)
{
	if (a < 0)putchar('-'), a = -a;
	if (a >= 10)Out(a / 10);
	putchar(a % 10 + '0');
}
int main() {
	ll a, b;
	cin >> a >> b;
	if (abs(a) == abs(b)) {//测试已过
		Out(1);
		return 0;
	}
	if (a == 0) {//对了
		if (b > 0) {//测试完了
			Out(b);
		}
		else {//测试已过
			Out(1 - b);
		}
	}
	if (b == 0) {//对了
		if (a > 0) {
			Out(a + 1);//过了
		}
		else {
			Out(-a);
		}
	}
	if (a * b > 0) {//同号
		if (a < b) {
			Out(b - a);//对了
		}
		else {
			Out(2 + a - b);
		}
	}
	if (a * b < 0) {
		if (a < 0) {
			if (abs(a) < abs(b))//对了(-1,23)
				Out(b + a + 1);
			else
				Out(1 - b - a);
		}
		if (a > 0) {
			if (abs(a) > abs(b)) {
				Out(1 + b + a);//对了
			}
			else {
				Out(1 - b - a);//对了
			}
		}
	}

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include<numeric>
#include<cmath>
#include<map>
#include<iomanip>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
using ll = long long;
using P = pair<int,int>;
using pll = pair<ll,ll>;
using vvi = vector<vector<int> >;
using vvll =  vector<vector<ll> >;

const ll inf = 1LL << 60;

int main(){
    cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	//cout << fixed << setprecision(15);
    int N,M;cin >>N>>M;
    vector<int> pena(N,0);
    vector<bool> AC(N,false);
    REP(i,M){
        int p; cin >> p;
        p--;
        string S; cin >>S;
        if(S == "WA"){
            if(AC[p] == false){
                pena[p]++;
            }
        }
        else{
            AC[p] = true;
        }

    }
    int ansp = 0;
    int ansac = 0;
    REP(i,N){
        if(AC[i]){
            ansac++;
            ansp += pena[i];
        }
        
    }
    cout << ansac << " " << ansp <<endl;
}

Measured memory_bytes: 3700
from collections import deque
H, W = map(int, input().split())
a = []
for _ in range(H):
    a.append(input())
queue = deque([])
dist = [[-1 for j in range(W)] for i in range(H)]
for i in range(H):
    for j in range(W):
        if a[i][j] == "#":
            queue.append([i, j])
            dist[i][j] = 0
dh = [0, 0, 1, -1]
dw = [1, -1, 0, 0]
while queue:
    now = queue.popleft()
    h = now[0]
    w = now[1]
    for i in range(4):
        nh = h + dh[i]
        nw = w + dw[i]
        if nh < 0 or nw < 0 or nh >= H or nw >= W:
            continue
        if dist[nh][nw] == -1:
            dist[nh][nw] = dist[h][w] + 1
            queue.append([nh, nw])
ans = 0
for i in range(H):
    for j in range(W):
        ans = max(ans, dist[i][j])
print(ans)

Measured memory_bytes: 166828
n = int(input())
t = n
k = 0
i = 0
ans = []
if n == 0:
    print(0)
else:
    while k != n:
        if i % 2 == 0:
            if t % 2 == 0:
                ans += "0"
            else:
                ans += "1"
                t -= 1
                k += (-2)**i
        else:
            if t % 2 == 0:
                ans += "0"
            else:
                ans += "1"
                t += 1
                k += (-2)**i
        t = int(t / 2)
        i += 1
    ans.reverse()
    print("".join(ans))

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

using namespace std;

#define INF 1000000007
#define LINF (1LL << 60)

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

inline i64 mod(i64 a, i64 m) { return (a % m + m) % m; }

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 (b<a) { a=b; return 1; } return 0; }



string s;
void solve(){
	cin >> s;
	int n = s.size();
	
	string t = "hi";
	for(int i = 0; i < n; i++){
		if(s == t){
			cout << "Yes" << endl;
			return;
		}
		t += "hi";
		
	}
	cout <<"No" << endl; 
}

int main(){
	std::cin.tie(0);
	std::ios::sync_with_stdio(false);
	int t = 1;
	//cin >> t;
	while(t--){
		solve();
	}
	
	return 0;
}


Measured memory_bytes: 256
package main

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

func main() {
	x := readI()
	p := getPrimes(1e6)

	i := 0
	for ; p[i] < x; i++ {

	}
	fmt.Println(p[i])
}

func getPrimes(upperLimit int) (primes []int) {
	//Sieve of Eratosthenes
	fl := make([]bool, upperLimit+1)
	sqrtUpperLimit := sqrt(upperLimit)
	for i := 2; i <= sqrtUpperLimit; i++ {
		if fl[i] != true {
			primes = append(primes, i)
			for j := i; j <= upperLimit; j += i {
				fl[j] = true
			}
		} else {
			continue
		}
	}
	for i := sqrtUpperLimit + 1; i <= upperLimit; i++ {
		if fl[i] != true {
			primes = append(primes, i)
		}
	}
	return
}

func sqrt(n int) int {
	return int(math.Sqrt(float64(n)))
}

/*-----------Input utils-----------*/

var sc = bufio.NewScanner(os.Stdin)

func init() {
	if len(os.Args) >= 2 {
		if os.Args[1] == "debug" {
			debug()
		}
	}
	const buf = 200100
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, buf), buf)
}

func debug() {
	testFile, err := os.Open("./test/sample-1.in")
	if err != nil {
		fmt.Fprintln(os.Stderr, "There is no testfile.")
		os.Exit(1)
	}
	sc = bufio.NewScanner(testFile)
}

func readS() string {
	sc.Scan()
	return sc.Text()
}

func readR() []rune {
	return []rune(readS())
}

func readI() int {
	i, _ := strconv.Atoi(readS())
	return i
}

func readF() float64 {
	f, _ := strconv.ParseFloat(readS(), 64)
	return f
}


Measured memory_bytes: 5844
#define _USE_MATH_DEFINES
#include <iostream>
#include <fstream>
#include <sstream>
#include <string>
#include <cstring>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <queue>
#include <deque>
#include <stack>
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <numeric>
#include <functional>
#include <cctype>
#include <list>
#include <limits>
#include <cassert>
#include <random>
#include <time.h>
//#include <boost/multiprecision/cpp_int.hpp>



using namespace std;
using Int = long long;
//using namespace boost::multiprecision;

const double EPS = 1e-10;
long long const MOD = 1000000007;

long long mod_pow(long long x, long long n) {
    long long res = 1;
    for (int i = 0;i < 60; i++) {
        if (n >> i & 1) res = res * x % MOD;
        x = x * x % MOD;
    }
    return res;
}

template<typename T>
T gcd(T a, T b) {
    return b != 0 ? gcd(b, a % b) : a;
}

template<typename T>
T lcm(T a, T b) {
    return a * b / gcd(a, b);
}

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


int main(void) {
    string s, t; cin >> s >> t;
    int ans = 0;
    for (int i = 0; i < 3; i++) {
        if (s[i] == t[i]) ans++;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 888
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using db = double;
using ld = long double;
template<typename T> using V = vector<T>;
template<typename T> using VV = vector<vector<T>>;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define eb emplace_back
#define lb lower_bound
#define ub upper_bound
#define all(v) (v).begin(),(v).end()
#define siz(v) (ll)(v).size()
#define rep(i,a,n) for(ll i=a;i<(ll)(n);++i)
#define repr(i,a,n) for(ll i=n-1;(ll)a<=i;--i)
#define ENDL '\n'
typedef pair<int,int> Pi;
typedef pair<ll,ll> PL;
constexpr ll mod = 1000000007;
constexpr ll INF = 1000000099;
constexpr ll LINF = (ll)(1e18 +99);
const vector<ll> dx={-1,1,0,0},dy={0,0,-1,1};
template<typename T,typename U> inline bool chmin(T& t, const U& u){if(t>u){t=u;return 1;}return 0;}
template<typename T,typename U> inline bool chmax(T& t, const U& u){if(t<u){t=u;return 1;}return 0;}
template<typename T> inline T gcd(T a,T b){return b?gcd(b,a%b):a;}
template<typename T,typename Y> inline T mpow(T a, Y n) {
  T res = 1;
  for(;n;n>>=1) {
    if (n & 1) res = res * a;
    a = a * a;
  }
  return res;
}



signed main(){
  cin.tie(0);ios::sync_with_stdio(false);
  cout<<fixed<<setprecision(20);
  ll n,a,b;cin>>n>>a>>b;
  ll ans=0;
  ans+=(n/(a+b))*a;

  if(n%(a+b)>0)ans+=min(a,n%(a+b));
  cout<<ans<<ENDL;
}
//! ( . _ . ) ! 
//CHECK overflow,vector_size,what to output?

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>
#include <ctype.h>

#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <sstream>
#include <stack>
#include <queue>
#include <bitset>

using namespace std;

#define deb(a)    cout<<__LINE__<<"# "<<#a<<" -> "<<a<<endl;
#define pb push_back
#define OO 2e9+10

#define ConPnt(a)   {for(auto it: a){cout<<it<<", ";}cout<<endl;}
#define MapPnt(a)   {for(auto it: a){cout<<it.first<<": "<<it.second<<", ";}cout<<endl;}

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

template<class T> T abs(T x){
    if(x<0) return -x;
    return x;
}
template<class T>T sqr(T a){
    return a*a;
}

const double pi = acos(-1.0);
const double eps = 1e-8;


int main()
{
//    freopen("in.txt","r",stdin);
//    freopen("output.txt","w",stdout);

    ll ar[200010];
    int i;
    ll n,b,ans;
    while(1==scanf("%lld",&n))
    {
        ans = 0;
        for(i=0;i<n;i++)
        {
            scanf("%lld",&ar[i]);
            ar[i]=ar[i]-i;
        }
        sort(&ar[0],&ar[n]);
        b = ar[n/2];
        for(i=0;i<n;i++)
            ans+=abs(ar[i]-b);
        printf("%lld\n",ans);
    }

    return 0;
}


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

struct rect{
	int h;
	int w;
};

int main()
{
	rect rec;

	for (int k = 0;; k++){

		cin >> rec.h >> rec.w;

		if (rec.h == 0 && rec.w == 0)
			break;

		for (int i = 0; i < rec.h; i++){
			for (int j = 0; j < rec.w; j++){
				cout << '#';

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

Measured memory_bytes: 3092
# pragma GCC optimize("Ofast")
# include <bits/stdc++.h>
# define rep(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
# define reps(i, n) for(int i=1, i##_len=(n); i<=i##_len; ++i)
# define rrep(i, n) for(int i=((int)(n)-1); i>=0; --i)
# define rreps(i, n) for(int i=((int)(n)); i>0; --i)
# define ALL(x) (x).begin(), (x).end()
# define SZ(x) ((int)(x).size)
# define pb push_back
# define optimize_cin() cin.tie(0); ios::sync_with_stdio(false)
using namespace std;
using lint = long long;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }


int main(){
    int n, k; cin >> n >> k;
    vector<int> len(n,0);
    rep(i,n) cin >> len[i];
    sort(ALL(len),greater<int>());
    int sum = 0;
    rep(i,k) sum += len[i];
    cout << sum;
    return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace _0163
{
    public class Program

    {
        public static int[,] tolls = new int[,]
        {
              {  0, 300, 500, 600, 700, 1350, 1650 }
            , {  6,   0, 350, 450, 600, 1150, 1500 }
            , { 13,   7,   0, 250, 400, 1000, 1350 }
            , { 18,  12,   5,   0, 250,  850, 1300 }
            , { 23,  17,  10,   5,   0,  600, 1150 }
            , { 43,  37,  30,  25,  20,    0,  500 }
            , { 58,  52,  45,  40,  35,   15,    0 }
        };

        const int D_START = 1050;
        const int D_END = 1170;
        const int D_DIST = 40;

        public static void Main(string[] args)
        {
            while (true)
            {
                int d = RInt() - 1; if (d == -1) break;
                int mD = GetMinute(RIntAr());
                int a = RInt() - 1;
                int mA = GetMinute(RIntAr());

                int from = Math.Min(d, a);
                int to = Math.Max(d, a);
                int toll = tolls[from, to];

                bool discountD = tolls[to, from] <= D_DIST ? true : false;
                bool discountT = (D_START <= mD && mD <= D_END) || (D_START <= mA && mA <= D_END) ? true : false;
                Console.WriteLine(discountD && discountT ? GetHalf(toll) : toll);
            }

        }

        private static int GetHalf(int toll)
        {
            int half = toll / 2;
            if (half % 50 == 0) return half;
            else return((half / 50) + 1) * 50;
        }

        private static int GetMinute(int[] v) { return v[0] * 60 + v[1]; }

        static string RSt() { return Console.ReadLine(); }
        static int RInt() { return int.Parse(Console.ReadLine().Trim()); }
        static long RLong() { return long.Parse(Console.ReadLine().Trim()); }
        static double RDouble() { return double.Parse(Console.ReadLine()); }
        static string[] RStAr(char sep = ' ') { return Console.ReadLine().Trim().Split(sep); }
        static int[] RIntAr(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Trim().Split(sep), e => int.Parse(e)); }
        static long[] RLongAr(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Trim().Split(sep), e => long.Parse(e)); }
        static double[] RDoubleAr(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Trim().Split(sep), e => double.Parse(e)); }
        static string WAr<T>(IEnumerable<T> array, string sep = " ") { return string.Join(sep, array.Select(x => x.ToString()).ToArray()); }
    }

}



Measured memory_bytes: 15744
#include <iostream>
#include <fstream>

#include <stack>

using namespace std;

typedef stack<int> si_t;
class MyStack{
public:
    MyStack(){
        _s = NULL;
        _n = 0;
    }

    MyStack(int n){
        _s = new si_t[n];
        _n = n;
    }

    ~MyStack(){
        delete [] _s;
    }

    void push(int t, int x){
        _s[t].push(x);
        return;
    }

    void top(int t){
        if(_s[t].empty()){
            return;
        }else{
            cout << _s[t].top() << endl;
            return;
        }
    }

    void pop(int t){
        if(_s[t].empty()){
            return;
        }else{
            _s[t].pop();
            return;
        }
    }
private:
    si_t *_s;
    int _n;
};

int main(){
    int n,q;
    cin >> n >> q;
    MyStack s(n);
    for(int i=0;i<q;i++){
        int query,t;
        cin >> query >> t;
        switch(query){
        case 0:
            int x;cin >> x;
            s.push(t,x);
            break;
        case 1:
            s.top(t);
            break;
        case 2:
            s.pop(t);
            break;
        default: break;    
        }
    }
}


Measured memory_bytes: 4376
n,a,b = gets.split(" ").map!{|i| i.to_i}
sum = 0
1.upto(n) do |j|
  d = 0
  c = j.to_s.split("").map!{|k| k.to_i}
  c.length.times do |l|
    d += c[l]
  end
  if d >= a and b >= d
    sum += j
  end
end
puts sum


Measured memory_bytes: 2044
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n
        self.group_count = n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        self.group_count -= 1

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

def int_(num_str):
    return int(num_str) - 1

N, M = map(int, input().split())
uf = UnionFind(N)
ablist = [list(map(int_, input().split())) for _ in range(M)]
ans = [(N*(N-1))//2]
for a, b in ablist[:0:-1]:
    if not uf.same(a, b):
        ans.append(ans[-1]-uf.size(a)*uf.size(b))
    else:
        ans.append(ans[-1])
    uf.union(a, b)
print(*ans[::-1], sep="\n")

Measured memory_bytes: 35628
n,k=[int(i) for i in raw_input().split()]
a=[int(i) for i in raw_input().split()]
l=[]
for i in range(k,n):
    if(a[i]>a[i-k]):
        l.append("Yes")
    else:
        l.append("No")
for i in l:
    print i


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

signed main() {
  int n, k;
  cin >> n >> k;
  vector<int> v(n);
  for (auto&& u : v) cin >> u;
  int tmp , ans = 0ll;
  vector<int> val;
  for (int i = min(k,n); i >= 0; i--) {
    for (int r = 0; r <= i; r++) {
      val.clear();
      rep(j,r) val.push_back(v[j]);
      rep(j,i-r) val.push_back(v[n - 1 - j]);
      sort(begin(val), end(val), greater<int>());
 //     for (auto&& u : val) cerr << u << ((&u < &val.back()) ? " " : "\n");
      int cnt = k - i;
      while (cnt--) {
        if (val.back() < 0ll) val.pop_back();
      }
//      for (auto&& u : val) tmp += u;
	tmp=accumulate(begin(val),end(val),0ll);	
 //     for (auto&& u : val) cerr << u << " ";
 //     cerr << endl;
      ans = max(ans, tmp);
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cstring>
#include <cmath>
#include <climits>
#include <deque>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <array>
#include <bitset>
#include <cstring>
#include <deque>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
using namespace std;
#define io() ios_base::sync_with_stdio(false); cin.tie(nullptr)
#define ll long long
#define ull unsigned long long
#define ui unsigned int
#define us unsigned short
#define fi first
#define se second
#define IN(i,l,r) (l<i&&i<r)
#define LINR(i,l,r) (l<=i&&i<=r)
#define LIN(i,l,r) (l<=i&&i<r)
#define INR(i,l,r) (l<i&&i<=r)
#define v(T) vector<T>
#define p(T, N) pair<T, N>
#define ii p(int, int)
#define vi v(int)
#define vii v(p(int, int))
#define vvi v(v(int))
#define vl v(long long)
#define vll v(p(long long, long long))
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define qsort(a) sort(all(a))
#define qsortd(a) sort(all(a), greater<>())
#define qsortf(a, f) sort(all(a), f)
#define qsortsi(v) sort(v.begin(), v.end(), [](pair<int, int> aoeui, pair<int, int> boeui){return aoeui.se < boeui.se;})
#define pb(n) push_back(n)
#define eb(n) emplace_back(n)
#define pp(a, b) emplace_back(make_pair(a, b))
#define elif else if
#define fori(i, n) for(ll i = 0; i < n; i++)
#define foris(i, a, b) for(ll i = a; i < b; i++)
#define forise(i, a, b) for(ll i = a; i <= b; i++)
#define ford(i, n) for(ll i = n; i >= 0; i--)
#define fords(i, a, b) for(ll i = a; i >= b; i--)
#define fordse(i, a, b) for(ll i = a; i > b; i--)
#define forr(i, a) for (auto &i: a)
#define rev(a) reverse(a.begin(), a.end())
#define revf(a, b, c) (reverse(a.begin() + b, a.begin() + c))
#define digits(i) (int)((log(i)/(log(10))+1)
#define umap unordered_map
#define nl '\n'
#define fileio(in, out) freopen(in, "r", stdin); freopen(out, "w", stdout)
const int mod = 1000000007;

int N, L;

int main() {
  io();
  
  cin >> N >> L;
  v(string) arr;
  fori(i, N) {
    string inp;
    cin >> inp;
    arr.pb(inp);
  }
  qsort(arr);
  string ret = "";
  fori(i, N) {
    ret += arr[i];
  }
  
  cout << ret;
  
  return 0;
}

Measured memory_bytes: 256
n, k, q = gets.split.map(&:to_i)
a = q.times.map{gets.to_i}
arr = Array.new(n, k-q)
a.each do |num|
  arr[num-1] += 1
end
arr.each do |ans|
  if ans > 0
    puts 'Yes'
  else
    puts 'No'
  end
end


Measured memory_bytes: 4148
import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();
		sc.close();

		System.out.println(Math.min(b / a, c));
	}
}


Measured memory_bytes: 21972
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Map;
import java.util.StringTokenizer;
import java.util.TreeMap;

//http://codeforces.com/contest/1095/problem/B
public class Main {

	public static void main(String[] args) throws Exception {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		InputReader in = new InputReader(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		XeniaAndBitOperations solver = new XeniaAndBitOperations();
		// int test = in.nextInt();
		// while (test-- > 0)
		solver.solve(1, in, out);
		out.close();
	}

	static class XeniaAndBitOperations {
		
		int a[];
		int b[];
		int c[];
		
		public void solve(int testNumber, InputReader in, PrintWriter out) throws Exception {

			int n = in.nextInt();
			a = new int[n];
			b = new int[n];
			c = new int[n];
			int dp[][] = new int[n][4];
			
			for(int i=0; i<n; i++){
				a[i] = in.nextInt();
				b[i] = in.nextInt();
				c[i] = in.nextInt();
			}
			
//			int total = totalhappy(n-1, -1);
//			System.out.println(total);
			dp[0][0] = a[0];
			dp[0][1] = b[0];
			dp[0][2] = c[0];
			
			for(int i=1; i<n; i++){
				dp[i][0] = a[i] + Math.max(dp[i-1][1], dp[i-1][2]);
				dp[i][1] = b[i] + Math.max(dp[i-1][0], dp[i-1][2]);
				dp[i][2] = c[i] + Math.max(dp[i-1][0], dp[i-1][1]);
			}
			
			System.out.println(Math.max(dp[n-1][2],Math.max(dp[n-1][0], dp[n-1][1])));
			
		}

		private int totalhappy(int i, int prev) {
			
			int h1=0,h2=0,h3=0;
			
			if(i>=0){
				if(prev!=0 || prev==-1)
					h1 = a[i] + totalhappy(i-1, 0);
				if(prev!=1 || prev==-1)
					h2 = b[i] + totalhappy(i-1, 1);
				if(prev!=2 || prev==-1)
					h3 = c[i] + totalhappy(i-1, 2);
				
				return Math.max(h3, Math.max(h1, h2));
			}
			
			return 0;
		}

	}

	static class InputReader {
		public BufferedReader reader;
		public StringTokenizer tokenizer;

		public InputReader(InputStream stream) {
			reader = new BufferedReader(new InputStreamReader(stream), 32768);
			tokenizer = null;
		}

		public String next() {
			while (tokenizer == null || !tokenizer.hasMoreTokens()) {
				try {
					tokenizer = new StringTokenizer(reader.readLine());
				} catch (IOException e) {
					throw new RuntimeException(e);
				}
			}
			return tokenizer.nextToken();
		}

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

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

	}
}

Measured memory_bytes: 51752
<?php
$n = trim(fgets(STDIN));
$trampCheckList = createTrampCheckList();
 
for ($i = 0; $i < $n; $i++) {
    list($mark, $num) = getSpacesByExplodeTrimInput();
    $trampCheckList[$mark][$num] = 'check';
}
 
foreach ($trampCheckList as $key => $nullTramp) {
    for ($i = 1; $i <= 13; $i++) {
        if (! isset($trampCheckList[$key][$i])) {
            echo "$key".' '.$i, PHP_EOL;
        }
    }
}
 
function getSpacesByExplodeTrimInput()
{
    return explode(' ', trim(fgets(STDIN)));
}
 
function createTrampCheckList()
{
    return array(
        "S" => array_fill(1, 13, null),
        "H" => array_fill(1, 13, null),
        "C" => array_fill(1, 13, null),
        "D" => array_fill(1, 13, null)
    );
}

Measured memory_bytes: 15260
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll inf = 100100100100100100;
const ll V = 10;
ll D[V][V];
void WarshallFloyd(){
  ll i,j,k;
  for(i=0;i<V;i++){
    for(j=0;j<V;j++) scanf("%lld",&D[i][j]);
  }
  for(k=0;k<V;k++){
    for(i=0;i<V;i++){
      for(j=0;j<V;j++) D[i][j] = min(D[i][j],D[i][k]+D[k][j]);
    }
  }
}
int main(){
  ll h,w,i,a,ans = 0;scanf("%lld%lld",&h,&w);
  WarshallFloyd();
  for(i=0;i<h*w;i++){
    scanf("%lld",&a);
    if(a!=-1) ans += D[a][1];
  }
  printf("%lld\n",ans);
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int n,z,w,a[2005];
int vi[2][2005];
int dfs(int b,int k) {
	if (k!=1&&vi[b][k]) return vi[b][k];
	int re=abs((k!=1?a[k-1]:w)-a[n]);
	for (int i=k;i<n;++i) {
		if (!b) re=max(re,dfs(1,i+1));
		else re=min(re,dfs(0,i+1));
	}
	//printf("vi[%d][%d]=%d\n",b,k,re);
	return vi[b][k]=re;
}
int main() {
	scanf("%d%d%d",&n,&z,&w);
	for (int i=1;i<=n;++i) scanf("%d",a+i);
	printf("%d\n",dfs(0,1));
}

Measured memory_bytes: 384
#include <iostream>
#include <vector>
#include <string>

using namespace std;

int ctoi(char ch)
{
	if ('0' <= ch && ch <= '9')
	{
		return ch - '0';
	}
	else
	{
		return 0;
	}
}

int main()
{
	string x_s;
	vector<int> sum_digits(1001, 0);
	int digit_i;
	int n = 0;
	while (cin >> x_s, x_s != "0")
	{
		for (int i = 0; i < x_s.length(); i++)
		{
			digit_i = ctoi(x_s[i]);
			sum_digits[n] += digit_i;
		}
		n++;
	}
	n = 0;
	while (sum_digits[n] != 0)
	{
		if (sum_digits[n] < 0)
		{
			sum_digits[n] *= -1;
		}
		cout << sum_digits[n++] << endl;
	}
}


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

int main(){
    int N, K, d;
    cin >> N >> K;
    vector<bool> sunuke(N, false);
    int sunuke_num = 0;
    int fooled = 0;
    for (int i = 0; i < K; i++){
        cin >> d;
        for (int j = 0; j < d; j++){
            cin >> sunuke_num;
            sunuke[sunuke_num - 1] = true;
        }
    }
    for (int i = 0; i < N; i++){
        if(!sunuke[i]) fooled++;
    }
    cout << fooled << endl;
}

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

#define ALL(v) v.begin(), v.end()
#define V vector
#define P pair
using ll = long long;

int n;

void dfs(string s, char mc){
    if(s.size() == n){
        cout << s << endl;
    }else{
        for(char c = 'a'; c <= mc; c++){
            char nc = c == mc ? (char)(mc + 1) : mc;
            dfs(s + c, nc);
        }
    }
}

int main() {
    cin >> n;
    dfs("", 'a');

    return 0;
}


Measured memory_bytes: 3628
#include<iostream>
#include<vector>
#include<string>
#include<cmath>
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define reep(i,n) for(int i=0;i<=(int)(n);++i)
#define repp(i,n) for(int i=(int)(n);i>0;--i)
//マクロ関数
#define N 100005
typedef long long ll;
//変数定義　初期値設定
using namespace std;
int main(){
  int n;
  cin>>n;
  vector<int> a(n),b(n-1);
  int y=0,x=0;
  for(int i=0;i<n-1;++i){
    cin>>b[i];
  }
  for(int i=0;i<n-2;++i){
    a[i+1]=min(b[i],b[i+1]);
  }
  a[0]=b[0];
  a[n-1]=b[n-2];
  int ans=0;
  for(int i=0;i<n;++i){
    //cout<<a[i]<<' ';
    ans+=a[i];
  }
  cout<<ans<<endl;
}

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

public class Main{
	public static void main(String args[]){
		Scanner sc = new Scanner(System.in);
		int x = sc.nextInt();
		int a = sc.nextInt();
		int b = sc.nextInt();
		
		if(Math.abs(x-a) < Math.abs(x-b) )
			System.out.println("A");
		else
			System.out.println("B");
	}
}

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

using namespace std;

typedef long double ld;
typedef long long ll;

#define sz(x) (int)(x).size()
#define pb push_back
#define mp make_pair
#define f first
#define s second

template<typename T, typename U> bool ckmin(T &a, U b){ return b < a ? a = b, true : false; }
template<typename T, typename U> bool ckmax(T &a, U b){ return b > a ? a = b, true : false; }

int res = 0;
string s;
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin >> s;
    for(auto i : s) res += (i - '0');
    cout << (res%9 ? "No" : "Yes");
    return 0;
}

Measured memory_bytes: 3780
#include<bits/stdc++.h>
using namespace std;
const int N=2e5+5;
typedef long long LL;
int a[N],b[N];
LL k,s1,s2,s3;
bool check(LL x){
	LL ans=0;
	if(x>=0){
		ans+=s3*(s1+s2)+s3*(s3-1)/2+s1*s2;
		int r=s1-1;
		for(int i=0;i<r;i++){
			while(1ll*a[i]*a[r]>x)r--;
			if(i>=r)break;
			ans+=r-i; 
		}
		r=s2-1;
		for(int i=0;i<r;i++){
			while(1ll*b[i]*b[r]>x)r--;
			if(i>=r)break;
			ans+=r-i;
		}
	}
	else{
		x=-x;
		int l=0;
		for(int i=s2-1;i>=0;i--){
			while(1ll*a[l]*b[i]<x&&l<s1)l++;
			ans+=s1-l;
		}
	}
	return ans>=k;
}
int main(){
	int n,x;LL l=-2e18,r=2e18,mid;scanf("%d%lld",&n,&k);
	for(int i=0;i<n;i++){
		scanf("%d",&x);
		if(x>0)a[s1++]=x;
		else if(x<0)b[s2++]=-x;
		else s3++;
	}
	sort(a,a+s1),sort(b,b+s2);
	while(l<=r){
		mid=(l+r)>>1;
		if(check(mid))r=mid-1;
		else l=mid+1;
	}
	printf("%lld",l);
	return 0;
}

Measured memory_bytes: 896
#include <iostream>
#include <string>
#include <cstring>
#include <algorithm>
#include <functional>
#include <cmath>
#include <set>
#include <queue>
#include <vector>
#include <climits>
#include <sstream>
#include <iomanip>
#include <map>
#include <stack>
using namespace std;

long long d[1001];

int main()
{
	string A, B, C;
	cin >> A >> B >> C;
	if (A[A.length() - 1] == B[0] && B[B.length() - 1] == C[0])
	{
		cout << "YES" << endl;
	}
	else
	{
		cout << "NO" << endl;
	}

	return 0;
}

Measured memory_bytes: 256
N = int(input())
X1 = list(map(int, input().split()))
ans = []
if N == 1:
    print(0)
    exit()
    
if min(X1) == max(X1):
    print(0)
    exit()
    
for p in range(min(X1), max(X1)):
    num = 0
    for i in range(N):
        num += (X1[i] - p)*(X1[i] - p)
        
    ans.append(int(num))

print(min(ans))

Measured memory_bytes: 9176
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <stack>
#include <queue>
#include <set>
#include <map>
using namespace std;
typedef long long int LL;
typedef vector<int> ivec;
typedef vector<string> svec;

LL a[100010],b[100010];
const int mod=1000000007;
int main(){
	LL n,m;
	LL ansi=0,ansj=0,ans=0;
	cin>>n>>m;	
	for(int i=0;i<n;i++)cin>>a[i];
	for(int i=0;i<m;i++)cin>>b[i];
	int A=a[0],B=b[0];
	for(int i=0;i<n;i++)a[i]-=A;
	for(int i=0;i<m;i++)b[i]-=B;
	
        for(LL i=1;i<n;i++)ansi=(ansi+(LL)(i*(n-i)%mod)*(a[i]-a[i-1]))%mod;
	for(LL i=1;i<m;i++)ansj=(ansj+(LL)(i*(m-i)%mod)*(b[i]-b[i-1]))%mod;
	
	
	cout<<(ansi*ansj)%mod<<endl;
	return 0;
}

Measured memory_bytes: 1792
import datetime
h1, m1, h2, m2, k = map(int, input().split())
one = datetime.timedelta(hours=h1, minutes=m1)
two = datetime.timedelta(hours=h2, minutes=m2)
study = datetime.timedelta(minutes=k)

diff_one_two_seconds = (two.total_seconds() - one.total_seconds()) / 60
study_seconds = study.total_seconds()/60
print(int(diff_one_two_seconds - study_seconds))

Measured memory_bytes: 9320
import java.util.*

val ans = mutableListOf<Int>()

fun main(args: Array<String>) {
	val sc = Scanner(System.`in`)
	val x = sc.nextInt()
	val y = sc.nextInt()

	for (i in 0 until 4) {
		solve(i, x, y)
	}
	println(ans.min())
}

fun solve(i: Int, x0: Int, y0: Int) {
	var x = x0
	var y = y0
	var t = 0

	if (i % 2 == 0) {
		x *= -1
		t++
	}
	if (i < 2) {
		y *= -1
		t++
	}
	if (x <= y) {
		t += y - x
		ans.add(t)
	}
}


Measured memory_bytes: 31520