akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define REP(i, m, n) for(int i = m; i < n; i++)
#define rep(i, n) REP(i, 0, n)
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define dup(x, y) (((x) + (y)-1) / (y))
#define PI 3.14159265359
typedef long long LL;
typedef vector<vector<int>> Graph;
const LL MOD = 1e9 + 7;
const LL LLINF = 1LL << 60;
const int INF = 1 << 30;
template <class T> inline void chmax(T &a, T b) {
    if(a < b) {
        a = b;
    }
}
template <class T> inline void chmin(T &a, T b) {
    if(a > b) {
        a = b;
    }
}
template <class T> inline T gcd(T x, T y) {
    if(y == 0) {
        return x;
    } else if(x == 0) {
        return y;
    }
    return gcd(y, x % y);
}
template <class T> inline T lcm(T x, T y) { return (x * y) / gcd(x, y); }
template <class T> inline void print_vector(vector<T> vec) {
    for(int i = 0; i < vec.size(); i++) {
        cout << vec[i] << " ";
    }
    cout << endl;
}
template <class T> inline T mpower(T x, T n) {
    if(n == 0) {
        return 1;
    } else if(n % 2 == 0) {
        return mpower(x * x % MOD, n / 2);
    } else {
        return x * mpower(x, n - 1) % MOD;
    }
}
LL mfrac(LL x) {
    LL res = 1;
    for(LL i = x; i >= 1; i--) {
        res *= i;
        res %= MOD;
    }
    return res;
}
LL mcomb(LL n, LL r) {

    if(n == 0 and r == 0) {
        return 1;
    } else if(n < r || n < 0) {
        return 0;
    }

    LL res = mfrac(n) * mpower(mfrac(r), MOD - 2) % MOD;
    res *= mpower(mfrac(n - r), MOD - 2) % MOD;

    return res;
}

int main(void) {
    int N;
    cin >> N;

    vector<int> A(N + 2);
    for(int i = 1; i <= N; i++) {
        cin >> A[i];
    }

    vector<int> adjacent_distance(N + 1);
    for(int i = 1; i <= N + 1; i++) {
        adjacent_distance[i - 1] = A[i] - A[i - 1];
    }

    int all_cost = 0;
    rep(i, N + 1) all_cost += abs(adjacent_distance[i]);

    // answer
    for(int i = 1; i <= N; i++) {
        cout << all_cost - abs(adjacent_distance[i - 1]) -
                    abs(adjacent_distance[i]) +
                    abs(adjacent_distance[i] + adjacent_distance[i - 1])
             << endl;
    }

    return 0;
}


Measured memory_bytes: 2048
#include<stdio.h>
#define N 100
int main(){
  int n,i,j,k,data[N];
  scanf("%d",&n);
  for(i=0;i<n;i++)
    scanf("%d",&data[i]);
   for(k=0;k<n-1;k++)
    printf("%d ",data[k]);
   printf("%d",data[n-1]);
  printf("\n");
  for(j=1;j<n;j++){
    k = data[j];
    i = j - 1;
    while(i >= 0 && data[i] > k){
      data[i+1] = data[i];
      i--;
	}
      data[i+1] = k;
      for(k=0;k<n-1;k++)
    printf("%d ",data[k]);
      printf("%d",data[n-1]);
  printf("\n");
  }
  return 0;
}


Measured memory_bytes: 2756
#include <cstdio>
#include <stack>
#include <queue>
#include <vector>
#include <algorithm>
#include <stdio.h>
#include <iostream>
#include <bits/stdc++.h> 
using namespace std;
typedef long long ll;
typedef pair<int,int> Pint;
typedef pair<ll, ll> P;
//typedef pair<int, pair<int, int>> P;
//typedef tuple<int,int,int> T;
ll INFL = 1000000000000000010;//10^18 = 2^60
int INF = 2147483600;//10^9
ll MOD  = 1000000007;
//vector<int> dy = {0,0,1,-1, 0, 1, 1, -1, -1}, dx = {1,-1,0,0, 0, 1, -1, 1, -1};
//vector<int> dy = {0, 0, 1, -1}, dx = {1, -1, 0, 0};

ll N, H;
ll d[100010], h[100010];

ll Seg[262143], Whole[262143];

void add(int a, int b, ll c, int k, int l, int r){
    if(a <= l && r <= b) Whole[k] += c;
    else if(b <= l || r <= a) ;
    else{
        add(a, b, c, 2*k+1, l, (l+r)/2);
        add(a, b, c, 2*k+2, (l+r)/2, r);
        Seg[k] = max(Seg[2*k+1] + Whole[2*k+1], Seg[2*k+2] + Whole[2*k+2]);
    }
}

ll query(int a, int b, int k, int l, int r){//最大値
    if(a <= l && r <= b) return Seg[k] + Whole[k];
    else if(b <= l || r <= a) return -LLONG_MAX;
    else{
        return max(query(a, b, 2*k+1, l, (l+r)/2), query(a, b, 2*k+2, (l+r)/2, r)) + Whole[k];
    }
}

int main(void){
    cin >> N >> H;
    N--;
    for(int i = 0; i < N; i++){
        cin >> d[i] >> h[i];
    }
    
    ll now_H = H;
    priority_queue<pair<ll, int>> pque;
    ll ans = 0;
    
    for(int i = 0; i < N; i++){
        add(i, i+1, now_H, 0, 0, N);
        now_H -= d[i];
        pque.push({h[i], i});
        while(now_H <= 0){
            ll cost = pque.top().first;
            int at = pque.top().second;
            pque.pop();
            ll m = query(at, i+1, 0, 0, N);
            if(m + cost > H){
                pque.push({H - m, at});
                continue;
            }
            int maxnum = min((H-m)/cost, (-now_H)/cost + 1);
            ans += maxnum;
            add(at, i+1, maxnum * cost, 0, 0, N);
            now_H += maxnum * cost;
            pque.push({cost,at});
        }
    }
    cout << ans << endl;
}



Measured memory_bytes: 9024
import java.util.*;

class Main {
	public static void main(String[] arg){
		Scanner in = new Scanner(System.in);
		while(true){
			int count = 0;
			int n = Integer.parseInt(in.next());
			int x = Integer.parseInt(in.next());
			if(n==0 && x==0)
				break;
		  
			for(int i=1;i<n+1;i++){
				for(int j=i+1;j<n+1;j++){
					for(int k=j+1;k<n+1;k++){
						if(i!=j && j!=k && i+j+k==x){
							count++;
						}
					}
				}
			}
			System.out.println(count);	
		}
	}	
}

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

#define REP(i, a, b) for (int i = (a); i < (b); i++)
#define REPR(i, a, b) for (int i = (a); i >= (b); i--)
#define ALL(container) (container).begin(), (container).end()

using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int, int> pi;
typedef pair<ll, ll> pll;

const int INF = 1e9;

int main() {
  int A, B, C;
  cin >> A >> B >> C;
  int max;
  if (A == B && B == C && C == A) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }

  return 0;
}


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

#define ll long long
typedef pair <int, int> ii;
typedef pair <ll, int> lli;
#define ar array
#define pb push_back
#define fi first
#define se second
#define sz size
#define mp make_pair
#define nl '\n'
#define all(x) (x).begin(), (x).end()
#define int_max numeric_limits<int>::max()
#define int_min numeric_limits<int>::min()
#define ll_max numeric_limits<ll>::max()
#define ll_min numeric_limits<ll>::min()

#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define im(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

// custom sort example
//sort(all(a), [ ]( const auto& c, const auto& d) {
	//if (c.fi.se != d.fi.se) {
		//return c.fi.se < d.fi.se; // lower first
	//}
	//if (c.fi.fi != d.fi.fi) {
		//return c.fi.fi > d.fi.fi; // higher first
	//}
	//return c.se > d.se; // higher first
//});

struct chash {
    static uint64_t splitmix64(uint64_t x) {
        // http://xorshift.di.unimi.it/splitmix64.c
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};

template <class T>
auto lbf(const std::set<std::pair<T, T>>& s, T first)
{
   static constexpr T min = std::numeric_limits<T>::min();

   return s.lower_bound({first, min});
}

int MOD = 1000000007;

ll pw(ll n, ll k) {
	ll r = 1;
	for(; k; k >>= 1) {
		if(k&1) r = r * n % MOD;
		n = n * n % MOD;
	}
	return r;
}
ll inv(ll n) { return pw(n, MOD-2); }

int main () {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	#ifdef LOCAL
		freopen("input.txt", "r", stdin);
	#endif
	int n;
	cin >> n;
	ll res = 0;
	for (int i = 1; i < n; i++) {
		int a = n / i;
		if (a * i == n) {
			a--;
		}
		res = res + a;
		//debug() << im(i) im(a) im(res);
	}
	cout << res << nl;
}


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

#define REP(i,s,n) for(int i=s;i<n;++i)
#define rep(i,n) REP(i,0,n)
#define fst first
#define snd second
#define pb push_back
#define ALL(x) x.begin(),x.end()
#define EPS (1e-9)
#define equals(a,b) (fabs((a)-(b))<EPS)

using namespace std;

bool LT(double a,double b) { return !equals(a,b) && a < b; }
bool LTE(double a,double b) { return equals(a,b) || a < b; }

const string YES = "";
const string NO  = "";

typedef long long ll;

void solve() {

}

int main() {
  vector<int> vec(3);
  map<int,int> mp;
  rep(i,3) {
    cin >> vec[i];
    mp[vec[i]]++;
  }
  map<int,int> rmp;
  for(auto v : mp) {
    rmp[v.snd]++;
  }
  if( rmp[2] == 1 && rmp[1] == 1 ) puts("Yes");
  else puts("No");


  return 0;
}


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

#define int long long

typedef long long ll;
typedef pair<int,int>pint;
typedef vector<int>vint;
typedef vector<pint>vpint;
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,f,n) for(int i=(f);i<(n);i++)
#define each(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++)
template<class T,class U>void chmin(T &t,U f){if(t>f)t=f;}
template<class T,class U>void chmax(T &t,U f){if(t<f)t=f;}

int W,H;
int N;

vpint pr;

signed main(){
    cin>>W>>H;
    cin>>N;

    rep(i,W-1)pr.pb(pint(i,i));
    rep(i,H-2)pr.pb(pint(W-2+i,W+i));
    rep(i,W)pr.pb(pint(W-2+H-3+i,W+H-1+i));


    int a=0,b=0;
    int cnt=0;
    rep(i,N){
        int p;cin>>p;
        if(p==0)b++;
        else a++;
        bool ok=false;
        rep(j,pr.size())ok|=pr[j].fi==a&&pr[j].se==b;
        cnt+=ok;
    }

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

Measured memory_bytes: 1200
#include<bits/stdc++.h>
#include<iostream>
#include<algorithm>
// #include<vor>
using namespace std;
typedef long long int ll;
#define pb push_back
ll mod = 1e9+7;

ll powm(ll a , ll b , ll mod)
{
  ll res = 1;
  while(b)
  {
    if(b & 1)
    res = (res *a)%mod;
    a = (a*a)%mod;
    b>>1;
  }
  return res;
}
ll gcd(ll a , ll b);
ll power(ll x , ll y , ll m);

ll modInverse(ll a , ll m)
{
  ll g = gcd(a,m);
  if(g != 1)
  return 1;
  else
  return power(a,m-2,m);

}

ll power(ll x , ll y , ll m)
{
  if(y == 0)
  return 1;
  ll p = power(x , y/2 , m)%m;
  p = (p*p)%m;

  return (y%2 == 0) ? p : (x *p) % m;
}

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

vector<int>adj[1000001] , ans;
int dis[1000001] , cnt[1000001];
bool vis[1000001];



int freq[1000001];
void solve()
{
  ll n , m;
  cin>>n>>m;
  ll sum = 0 , sum1 = 0 , sum2 = 0;
  for(int i = 0;i<m-1;i++)
  sum1 += i;
  for(int i = n-m+2 ; i<n+1;i++)
  sum2 += i;
  for(int i = m-1 ; i<n+1;i++)
  {
    sum1 += i, sum2+= n-i ;
    sum = (sum +sum2-sum1+1)%mod;
  }
  cout<<sum<<"\n";

}

int main()
{
  int tc;
  // cin>>tc;
  tc = 1;
  while(tc--)
  {
    solve();
  }
}


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

long long D, G, c[15], p[15], dp[1210];

int main(){
  fill(dp, dp + 1010, -1);
  *dp = 0;
  scanf("%lld%lld", &D, &G);
  G /= 100;
  for(int i = 1; i <= D; ++i){
    scanf("%lld%lld", p + i, c + i);
    c[i] /= 100;
    for(int j = 1000; j >= 0; --j){
      if(dp[j] >= 0){
  	    for(int k = 1; k < p[i]; ++k){
          dp[j + k] = max(dp[j + k], dp[j] + i * k);
        }
        dp[j + p[i]] = max(dp[j + p[i]], dp[j] + i * p[i] + c[i]);
      }
    }
  }
  partial_sum(dp, dp + 1010, dp, [](auto& a, auto& b){return max(a, b);});
  cout << lower_bound(dp, dp + 1010, G) - dp << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i,n) for(int i=0;i<(n);++i)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define all(x) (x).begin(), (x).end()
#define PI 3.14159265358979323846264338327950L
using namespace std;
typedef long long ll;
typedef long double ld;
int main() {
    int n,k;
    cin>>n>>k;
    vector<int> p(n);
    rep(i,n) cin>>p[i];
    sort(all(p));
    int ans=0;
    rep(i,k) ans+=p[i];
    cout<<ans;
}

Measured memory_bytes: 3632
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <climits>

#define rep(i, m, n) for(int i=int(m);i<int(n);i++)
#define all(c) begin(c),end(c)

template<typename T1, typename T2>
inline void chmin(T1 &a, T2 b) { if (a > b) a = b; }

template<typename T1, typename T2>
inline void chmax(T1 &a, T2 b) { if (a < b) a = b; }

//改造
typedef long long int ll;
using namespace std;
#define INF (1 << 30) - 1
#define INFl (ll)5e15
#define DEBUG 0 //デバッグする時1にしてね
#define dump(x)  cerr << #x << " = " << (x) << endl
#define MOD 1000000007


//ここから編集する


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

    int D, G;
    cin >> D >> G;
    vector<vector<int> > score;
    rep(i, 1, D + 1) {
        int p, c;
        cin >> p >> c;
        vector<int> tmp(3);
        tmp[0] = p * i * 100 + c;
        tmp[1] = i * 100;
        tmp[2] = p;
        score.push_back(tmp);
    }


    int ans = INF;
    for (int bit = 0; bit < 1 << D; ++bit) {
        vector<vector<int> > usesc;
        vector<vector<int> > nosc;
        for (int i = 0; i < D; ++i) {
            if (bit >> i & 1) {
                usesc.push_back(score[i]);
            } else {

                nosc.push_back(score[i]);
            }
        }
        int tmp_ans = 0;
        int tmp_sum = 0;
        rep(i, 0, usesc.size()) {
            tmp_sum += usesc[i][0];
            tmp_ans += usesc[i][2];
        }

        sort(all(usesc));
        reverse(all(usesc));
        reverse(all(nosc));

        if (tmp_sum >= G) {
            chmin(ans, tmp_ans);
        } else if (tmp_sum + nosc[0][1] * nosc[0][2] > G) {
            int diff = (G - tmp_sum) / nosc[0][1] + ((G - tmp_sum) % nosc[0][1] != 0);
            tmp_ans += diff;
            chmin(ans, tmp_ans);
        }
    }

    cout << ans << endl;


    return 0;
}


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

int main() {
  int N; cin >> N;
  vector<long long> A(N+1), B(N);
  for (int i = 0; i < N + 1; i++) cin >> A[i];
  for (int i = 0; i < N; i++) cin >> B[i];
  long long ans = 0;

  for (int i = 0; i < N; i++) {
    int j = min(A[i], B[i]);
    A[i] -= j;
    B[i] -= j;
    ans += j;
    int k = min(A[i+1], B[i]);
    A[i+1] -= k;
    ans += k;
  }
  
  cout << ans << endl;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
int main(){
  unsigned long long a;
  string b;
  cin>>a>>b;
  istringstream i,z;
  i=istringstream(b.substr(0,1));
  z=istringstream(b.substr(2,3));
  int c;
  int d;
  i>>c;
  z>>d;
  int e;
  e=c*100+d;
  cout<<a*e/100<<endl;
  return 0;
}

Measured memory_bytes: 3612
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    String S = sc.next();
    sc.close();

    Map<Character, Integer> cnt = new HashMap<>();
    long ans = 0;
    for (int i = 0; i < N; i++) {
      cnt.clear();
      cnt.put('R', 0);
      cnt.put('G', 0);
      cnt.put('B', 0);

      char a = S.charAt(i);
      cnt.compute(a, (k, v) -> v + 1);

      int ng = 0;
      for (int j = i + 1; j < N; j++) {
        char b = S.charAt(j);
        if (a == b) continue;

        if (j + (j - i) < N) {
          char c = S.charAt(j + (j - i));
          if (a != b && b != c && a != c) ng++;;
        }
        cnt.compute(b, (k, v) -> v + 1);
      }

      long sum = 1;
      for (Character c : cnt.keySet()) sum *= cnt.get(c);

      ans += sum;
      ans -= ng;
    }
    System.out.println(ans);
  }
}

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

int main()
{
	int ans = 0;
	string a,b;
	cin >> a >> b;
	for(int i = 0;i < a.size();i++){
		if(a[i] == b[i]) ans++;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define N 100005
#define ll long long
#define inf 0x3f3f3f3f
#define m0(x) memset(x,0,sizeof(x))
#define m1(x) memset(x,-1,sizeof(x))
using namespace std;
int n,l,r,ans[2005];
int main()
{
	cin>>n>>l>>r;
	for(int i=1;i<=n;i++)
	for(int j=i+1;j<=n;j++)
	{
		int dis=j-i;
		dis=min(dis,abs(l-i)+abs(r-j)+1);
		dis=min(dis,abs(r-i)+abs(l-j)+1);
		ans[dis]++;
	}
	for(int i=1;i<n;i++)
	cout<<ans[i]<<endl;
	return 0;
}

Measured memory_bytes: 764
#include <iostream>
#include <string>
#include <vector>
#include <valarray>
#include <algorithm>
#include <utility>
#include <functional>

using namespace std;

int main() {
	long long n, x, temp = 0, i;
	cin >> n >> x;
	valarray<int>a(n);
	for (auto& i : a)
	{
		cin >> i;
	}
	sort(begin(a), end(a));
	for (i = 0; i < n; i++) {
		if (temp + a[i] <= x) {
			temp += a[i];
		}
		else {
			break;
		}
	}
	if (i == n && x > temp)
		i--;
	cout << i << endl;
}

Measured memory_bytes: 256
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools

sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()


def main():
    n,t = LI()
    a = LI()
    s = 0
    c = 0
    r = 0
    for b in a:
        if c < b:
            r += c - s
            s = b
            c = b+t
        else:
            c = b+t
    r += c-s

    return r


print(main())


Measured memory_bytes: 27948
#include <cstdio>

int main(){
    int x, y, t;
    for (int i = 1; i <= 3000; i++){
        scanf("%d %d", &x, &y);
        if (x == 0 && y == 0){
            break;
        }
        if(y < x){
            t = y;
            y = x;
            x = t;
        }
        printf("%d %d\n", x, y);
    }
    return 0;
}



Measured memory_bytes: 2568
#include<iostream>
#include<vector>
#include<algorithm>
#include<set>
#include<deque>
#include<string>
using namespace std;
#define ll long long
#define pb push_back
#define end "\n"
#define lar 1000000007;
int main()
{
    ll n,k;
    cin>>n>>k;
    ll a[n];
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    sort(a,a+n);
    ll sum=0;
    for(int i=0;i<k;i++){
        sum+=a[i];
    }
    cout<<sum;
}

Measured memory_bytes: 3656
import java.util.*;
public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        // 文字列の入力                                                         
        String s = sc.next();
        if(s.length() < 4) System.out.println("No");
        else if(s.substring(0,4).equals("YAKI")) System.out.println("Yes");
        else System.out.println("No");

    }
}



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

int main() {
  int H, W;
  cin >> H >> W;
  vector<char> a((H+2)*(W+2), '#');
  
  for (int i = 0; i < (H+2)*(W+2); i++) {
    if (i > W+2 && i%(W+2) != 0 && i%(W+2) != W + 1) {
      cin >> a.at(i);
    }
  }

  for (int i = 0; i < (H+2)*(W+2); i++) {
    cout << a.at(i);
    if (i%(W+2) == W + 1)
      cout << endl;
    else
      continue;
  }
}

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

int main()

{
   int N,L1,L2,L,sum;
   cin>>N;
    
    for(int i=0;i<N;i++){
        cin>>L1>>L2;
         L=L2-L1+1;
         sum += L;
        
    }
   cout<<sum<<endl;
}


Measured memory_bytes: 256
def main():
	k = int(input())
	a,b = map(int,input().split())
	
	av = 0
	for i in range(a,b+1):
		if i % k == 0:
			print("OK")
			av = 1
			break
	if av == 0:	
		print("NG")


if __name__ == '__main__':
	main()

Measured memory_bytes: 61660
from collections import deque
S = deque(list(input()))
T = deque(list(input()))
count = 0
if S==T:
    print("Yes")
else:
    for _ in range(len(S)-1):
        s = S.pop()
        S.appendleft(s)
        if S==T:
            count += 1
    if count>0:
        print("Yes")
    else:
        print("No")

Measured memory_bytes: 3572
#include <bits/stdc++.h>
using namespace std;
int main(){
  cin.tie(NULL);
  ios::sync_with_stdio(false);
  int a,b;
  while(true){
    cin>>a>>b;
    if(a==0 && b==0) break;
    for(int i=0;i<a;i++){
      for(int j=0;j<b;j++){
	cout<<"#";
      }
      cout<<"\n";
    }
    cout<<"\n";
  }

  return 0;
}



Measured memory_bytes: 3124
# -*- coding: utf-8 -*-
import numpy as np
N = input()
A1 = np.array(map(int, raw_input().split()))
A2 = np.array(map(int, raw_input().split()))
A = np.array([A1, A2], dtype=np.int32)

# df = - 1 * np.diff(A, axis=0)[0]
# # print A.shape, len(df)
# max_col = np.zeros(len(df))
# all_sum = np.sum(df)

# for i in range(0, len(df)):
#     sum_i = np.sum(df[:i + 1])
#     # rest_i = all_sum - sum_i
#     rest_i = np.sum(df[i:])
#     max_col[i] = sum_i - rest_i
#     # print df, sum_i, rest_i

# down = np.argmax(max_col)
# # print max_col, down, np.sum(A[0, :down + 1]) + np.sum(A[1, down:])
# print np.sum(A[0, :down + 1]) + np.sum(A[1, down:])

max_sum = 0
for i in range(0, len(A[0])):
    # print A[0, :i + 1], A[1, i:]
    max_sum = np.max([max_sum, np.sum(A[0, :i + 1]) + np.sum(A[1, i:])])

print max_sum



Measured memory_bytes: 12468
#include<iostream>
#include<vector>
#include<cmath>
#include<algorithm>
#include<string>
#include<utility>
#include<array>
#include<set>
#include <numeric>
#include <stdio.h>
#include <map>
#include <iomanip>
#include <sstream>
//#include <boost/math/common_factor_rt.hpp>
#include<fstream>
#define EPS (1e-7)
using namespace std;
#define ll long long



class Employee {
public:
	int id;
	int parent;
	vector<int> children;
	int salary;

	Employee() {
		
	}

	Employee(int num, int nparent) {
		id = num;
		parent = nparent;
		salary = -1;
	}



};



template<class T> inline bool chmin(T& a, T b) {
	if (a > b) {
		a = b;
		return true;
	}
	return false;
}
template<class T> inline bool chmax(T& a, T b) {
	if (a < b) {
		a = b;
		return true;
	}
	return false;
}



int main() {

	int N, K;
	cin >> N >> K;
	vector<int> cost(N, 2000000000);
	vector<int> h(N);

	for (auto i = 0; i < N; i++) {
		cin >> h[i];

	}
	cost[0] = 0;
		for (auto i = 0; i < N; i++) {
		for (auto  j = 1;  j < K+1;  j++)
		{
			if (i + j < N)chmin(cost[i + j], cost[i] + abs(h[i] - h[i + j]));
			else break;
		}
		

	}

	cout << cost[N - 1] << endl;
	return 0;
}

Measured memory_bytes: 1024
from collections import deque

def Topologicalsort(v):
    start=deque()
    for i in xrange(v):
        if indeg[i]==0 :
            start.append(i)
    if len(start)>1:
        flag=True
    else:
        flag=False

    while len(start)>0:
        i=start.popleft()
        ans.append(i)
        tmp=[]
        for j in g[i]:
            indeg[j]-=1
            if indeg[j]==0:
                tmp.append(j)
                start.append(j)
                if len(tmp)>1:
                    flag=True
    return ans,flag

def solve(n,m):
    for i in xrange(m):
        wt,lt=map(int,raw_input().split())
        wt-=1;lt-=1
        g[wt].append(lt)
        indeg[lt]+=1
    ans,flag=Topologicalsort(n)
    return ans,flag

n=int(raw_input())
m=int(raw_input())
indeg=[0]*n
g=[[] for _ in xrange(n)]
ans=[]

ans,flag=solve(n,m)

if flag:
    for  i in xrange(len(ans)):
        print(ans[i]+1)
    print(1)
else:
    for i in xrange(n):
        print(ans[i]+1)
    print(0)

Measured memory_bytes: 10348
/*Author - Shubham Gupta (@shubham107)*/
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef vector<ll> vl;      typedef vector<int> vi;
typedef vector<vl> vvl;     typedef vector<vi> vvi;
typedef pair<ll, ll> pll;   typedef pair<int, int> pii;
#define forn(i,n) for(int i=0;i<n;i++)
#define rforn(i,n) for(int i=n-1;i>=0;i--)
#define forne(i,n) for(int i=1;i<=n;i++)
#define forse(i,s,e) for(int i=s;i<e;i++)
#define rforse(i,s,e) for(int i=e-1;i>=s;i--)
#define all(x) x.begin(),x.end()
#define sz(x) (int)x.size()
#define MOD 1000000007
#define F first
#define S second
#define pb push_back
#define mp make_pair
#define fill(a,x) memset(a,x,sizeof a);
#define trav(a,x) for(auto &a:x)
#define INF ll(1e18)
#ifdef SHUBHAM107
#include "../trace.h"
#else
#define trace(args...)
#endif
void solve() {
    int n;
    cin >> n;
    ll sum = 0;
    vi arr(n);
    forn(i, n) cin >> arr[i];
    sort(arr.rbegin(), arr.rend());
    sum += arr[0];
    int i = 0;
    n -= 2;
    while(n > 1) {
        sum += 2 * arr[++i];
        n -= 2;
    }
    if(n == 1)
        sum += arr[++i];
    cout << sum;
}
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
#ifdef SHUBHAM107
    freopen("inp.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
    freopen("err.txt", "w", stderr);
#endif
    int t = 1;
    // cin >> t;
    while (t--) {
        solve();
    }
}


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

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

    int n,k;
    cin>>n>>k;
    int a[n];
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    sort(a,a+n);
    int low=-1,up=n,mid;
    while(up-low>1){
        mid=(up+low)/2;
        bool dp[k+500]={};
        dp[0]=true;
        for(int i=0;i<n;i++){
            if(i==mid) continue;
            for(int j=k;j>=0;j--){
                if(j-a[i]>=0) dp[j] |= dp[j-a[i]];
            }
        }
        bool need=false;
        for(int i=k-1;i>=max(0,k-a[mid]);i--){
            if(dp[i]==1) need=true;
        }
        if(need){
            up=mid;
        }
        else low=mid;
    }
    cout<< low+1 <<endl;
    
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL_DEBUG
  #include "LOCAL_DEBUG.hpp"
#endif
#define int long long
const int INF = 1LL << 60;

signed main(){

  int n, m, x; cin >> n >> m >> x;
  vector<int> c(n);
  vector<vector<int>> a(n, vector<int>(m));
  for(int i = 0; i < n; i++){
    cin >> c[i];
    for(int j = 0; j < m; j++){
      cin >> a[i][j];
    }
  }

  int ans = INF;
  for(int i = 0; i < 1 << n; i++){
    vector<int> v(m, 0);
    int cost = 0;
    for(int j = 0; j < n; j++){
      if(i >> j & 1){
        for(int k = 0; k < m; k++){
          v[k] += a[j][k];
        }
        cost += c[j];
      }
    }
    bool judge = true;
    for(int j = 0; j < m; j++){
      if(v[j] < x) judge = false;
    }
    if(judge) ans = min(ans, cost);
  }
  if(ans == INF) ans = -1;
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 3568
def count(x1,y1,x2,y2):
  ret=acum[y2][x2]
  if x1!=0:
    ret-=acum[y2][x1-1]
  if y1!=0:
    ret-=acum[y1-1][x2]
  if x1!=0 and y1!=0:
    ret+=acum[y1-1][x1-1]
  return ret

h,w,k=map(int,input().split())
board=[list(input()) for _ in range(h)]
acum=[[0]*w for _ in range(h)]
for i in range(h):
  for j in range(w):
    if board[i][j]=='1':
      acum[i][j]+=1
    if i!=0:
      acum[i][j]+=acum[i-1][j]
    if j!=0:
      acum[i][j]+=acum[i][j-1]
    if i!=0 and j!=0:
      acum[i][j]-=acum[i-1][j-1]
ans=10**18
for rows in range(2**(h-1)):
  cnt=0
  hlist=[]
  flag=format(rows,'b')[::-1]
  for i in range(len(flag)):
    if flag[i]=='1':
      cnt+=1
      hlist.append(i)
  hlist.append(h-1)
  x1=0
  for x2 in range(w-1):
    y1=0
    for y2 in hlist:
      if count(x1,y1,x2,y2)>k:
        cnt+=10**18
      if count(x1,y1,x2,y2)<=k and count(x1,y1,x2+1,y2)>k:
        cnt+=1
        x1=x2+1
        break
      y1=y2+1
  y1=0
  for y2 in hlist:
    if count(x1,y1,w-1,y2)>k:
      cnt+=10**18
    y1=y2+1
  ans=min(ans,cnt)
print(ans)

Measured memory_bytes: 50396
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
using std::cerr;
using std::cin;
using std::cout;
using std::endl;

struct Path{
  int node, times;
  Path(int n,int t){
    node=n;
    times=t;
  }
};

struct State{
  int node,times,depth;
  State(int n,int t,int d){
    node=n;
    times=t;
    depth=d;
  }
};

int main(void) {
  cout << std::fixed << std::setprecision(10);
  cin.tie(0);
  std::ios::sync_with_stdio(false);

  int n,m;
  cin>>n>>m;

  std::vector<Path> node[100001][3];
  for(int i=0;i<m;i++){
    int u,v;
    cin>>u>>v;
    node[u][0].push_back(Path(v,1));
    node[u][1].push_back(Path(v,2));
    node[u][2].push_back(Path(v,0));

  }
  int s,t;
  cin>>s>>t;

  bool visited[100001][3]={};
  visited[s][0]=true;
  std::queue<State> bfs;
  bfs.push(State(s,0,0));
  while(!bfs.empty()){
    State curr=bfs.front();
    bfs.pop();

    if(curr.node==t&&curr.times==0){
      assert(curr.depth%3==0);
      cout<<curr.depth/3<<endl;
      return 0;
    }
    for(auto x:node[curr.node][curr.times]){
      if(!visited[x.node][x.times]){
        visited[x.node][x.times]=true;
        bfs.push(State(x.node,x.times,curr.depth+1));
      }

    }
  }

  cout<<-1<<endl;


  return 0;
}


Measured memory_bytes: 17024
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll INF = 1e16;
const ll mod = 1000000007;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

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 ctoi(char c) {
  if (c >= '0' && c <= '9') {
    return c - '0';
  }
  return 0;
}
ll factorial(ll n) {
  if (n == 1) {
    return 1;
  }
  ll ans = factorial(n-1);
  return ans*n;
}
ll gcd(ll a, ll b) {
  if (b == 0) return a;
  return gcd(b, a%b);
}
ll lcm(ll a, ll b) {
  return (a/gcd(a, b))*b;
}
bool is_prime(ll n) {
  for (ll i = 2; i*i <= n; i++) {
    if (n%i == 0) return false;
  }
  return n != 1;
}
ll mod_pow(ll x, ll n, ll mod) {
  if (n == 0) return 1;
  ll res = mod_pow(x*x%mod, n/2, mod);
  if (n & 1) res = res * x % mod;
  return res;
}

int main() {
  int a, b, c;
  cin >> a >> b >> c;
  cout << c << ' ' <<  a << ' ' << b << endl;
}

Measured memory_bytes: 3592
import java.util.*;
import java.io.*;
public class Main{
    public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		PrintWriter ou = new PrintWriter(System.out);
		int h = Integer.parseInt(sc.next());
		int w = Integer.parseInt(sc.next());
		int n = Integer.parseInt(sc.next());
		int[] s = new int[h * w];
		int cou = 0 , a , co = 1;
		for(int i = 0 ; i < n ; i++){
			a = Integer.parseInt(sc.next());
			for(int j = 0 ; j < a ; j++){
				s[cou + j] = co;
			}
			cou += a;
			co++;
		}
		sc.close();
		for(int i = 0 ; i < h ; i++){
			if(i % 2 == 0){
				for(int j = 0 ; j < w ; j++){
					ou.print(s[i * w + j]);
					if(j != w - 1) ou.print(" ");
				}
			}else{
				for(int j = w - 1 ; j >= 0 ; j--){
					ou.print(s[i * w + j]);
					if(j != 0) ou.print(" ");
				}
			}
			ou.print("\n");
		}
		ou.flush();
    }
}

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

string X, Y;
int q, lx, ly;
int dp[1010][1010];

int main() {
    cin >> q;
    
    for (int i=0; i<q; ++i) {
        cin >> X >> Y;
        lx = X.size();
        ly = Y.size();
        for (int i=0; i<=ly; ++i) dp[i][0] = 0;
        for (int i=0; i<=lx; ++i) dp[0][i] = 0;

        for (int j=1; j<=ly; ++j) {
            for (int k=1; k<=lx; ++k) {
                if (Y[j-1]==X[k-1]) dp[j][k] = dp[j-1][k-1] + 1;
                else dp[j][k] = max(dp[j-1][k], dp[j][k-1]);
            }
        }
        cout << dp[ly][lx] << endl;
    }

    return 0;
}


Measured memory_bytes: 7096
import java.util.Scanner;

public class Main {
    public static void main(String[] args){
        Scanner scan = new Scanner(System.in);
        int x = scan.nextInt();
        int f;
        int check;

        for(int i = 1; i <= x; i++){
            check = 0;
            if(i%3 == 0){
                System.out.print(" " + i);
                check = 1;
            }
            if(i%10 == 3 && check == 0){
                System.out.print(" " + i);
                check = 1;
            }

            f = i/10;
            String str = String.valueOf(f);
            if(str.contains("3") && check == 0){
                System.out.print(" " + i);
            }

        }

        System.out.print("\n");
    }
}




Measured memory_bytes: 30052
#include <iostream>
using namespace std;
const long long nine = 1000000007;

int main() 
{
	int n;
	cin >> n;
	int sum = 0, temp, max = 0;
	for (int i = 0; i < n; i++)
	{
		cin >> temp;
		sum += temp;
		if (max < temp) max = temp;
	}
	
	if (sum > 2*max) cout << "Yes";
	else cout << "No";
	
}

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

int main() {
  int N,M,C;
  cin >> N >> M >> C;
  
  vector<int> B(M);
  for (int i = 0; i < M; i++) {
    cin >> B.at(i);
  }
  
  int count = 0;
  vector<int> A(M);
  for (int k = 0; k < N; k++) {
    int shiki = C;
    
   for (int i = 0; i < M; i++) {
     cin >> A.at(i);
     shiki += A.at(i) * B.at(i);
   }
    
    if (shiki > 0){
      count++;
    }
  }
  
  cout << count << endl;
}

Measured memory_bytes: 256
using System;

public class Hello
{
    public static void Main()
    {
        var n = int.Parse(Console.ReadLine().Trim());
        string[] line = Console.ReadLine().Trim().Split(' ');
        var a = Array.ConvertAll(line, int.Parse);
        var b = new int[n];
        for (int i = 0; i < n; i++)
            b[a[i] - 1] = i + 1;
        Console.WriteLine(string.Join(" ", b));
    }
}


Measured memory_bytes: 26588
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
#include <bitset>
#define M 1000000007
#define M1 998244353

#define tr(container, it) \
for(typeof(container.begin()) it = container.begin(); it != container.end(); it++)

#define fast                        \
  ios_base::sync_with_stdio(false); \
  cin.tie(NULL);

#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()

ll power(ll x, ll n)
{
    ll result = 1;
    while (n)
    {
        if (n % 2 == 1)
            result = result * x;
        n = n / 2;
        x = x * x;
    }
    return result;
}

ll gcd(ll a, ll b)
{
    if (!b)
        return a;
    return gcd(b, a % b);
}

ll lcm(ll a, ll b) {
    return (a * b) / gcd(a, b);
}

inline ll mul(ll x, ll y, ll m)
{
    ll z = 1LL * x * y;
    if (z >= m)
    {
        z %= m;
    }
    return z;
}

ll powmod(ll x, ll y, ll m)
{
    ll r = 1;
    while (y)
    {
        if (y & 1)
        {
            r = mul(r, x, m);
        }
        y >>= 1;
        x = mul(x, x, m);
    }
    return r;
}



void start()
{
    fast;
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
}
/***********************************************************************************************************/

int main()
{
    start();
    int n=5;
    int a[n];
    for (int i=0;i<n;i++)
    {
        cin>>a[i];
    }
    int b=-1, c=0;

    for (int i=0;i<n;i++)
    {
        if (a[i]%10!=0)
        {
            if (b<10-(a[i]%10))
            {
                b=10-a[i]%10;
                c=i;
            }
        }
    }
    int ans=0;
    for (int i=0;i<n;i++)
    {
        if (i==c)
        {
            continue;
        }
        if (a[i]%10==0)
        {
            ans+=a[i];
        }
        else
        {
            ans+=((a[i]/10)+1)*10;
        }
    }
    ans+=a[c];
    cout<<ans;

    return 0;
}

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

int f[10][10], x[23], y[23], dat[10][10], dx[]{ 1,-1,0,0 }, dy[]{ 0,0,1,-1 };

int main() {
	int m, n;
	while (scanf("%d%d", &m, &n), m) {
		int p = 0, sx, sy;
		rep(i, n)rep(j, m) {
			scanf("%d", &f[i][j]);
			if (f[i][j] == 1)x[p] = i, y[p] = j, dat[i][j] = p++;
			if (f[i][j] == 2)sx = i, sy = j;
		}
		map<P, int>dp;
		rep(k, 4) {
			for (int nx = sx, ny = sy; 0 <= nx&&nx < n && 0 <= ny&&ny < m; nx += dx[k], ny += dy[k]) {
				if (f[nx][ny] == 1) {
					dp[{1 << dat[nx][ny], dat[nx][ny]}] = 1;
					break;
				}
			}
		}
		int ans = 0, o = 0;
		rep(i, 1 << p)rep(j, p) {
			if (dp.find({ i,j }) == dp.end())continue;
			if (i == (1 << p) - 1) {
				if (x[j] == sx || y[j] == sy)ans += dp[{i, j}];
				continue;
			}
			rep(k, 4) {
				for (int nx = x[j], ny = y[j]; 0 <= nx&&nx < n && 0 <= ny&&ny < m; nx += dx[k], ny += dy[k]) {
					if (f[nx][ny] == 1 && !(i >> dat[nx][ny] & 1)) {
						dp[{i | 1 << dat[nx][ny], dat[nx][ny]}] += dp[{i, j}];
						break;
					}
				}
			}
			if (++o >= 100000)dp.erase({ i,j });
		}
		printf("%d\n", ans);
	}
}

Measured memory_bytes: 14680
#include<bits/stdc++.h>
// Begin Header {{{
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
using Graph = vector<vector<ll>>;
#define rep(i,n) for(ll i=0; i<n; i++)
#define loop(i, j, n) for(ll i=j; i<n; i++)
#define all(x) (x).begin(), (x).end()
constexpr int INF  = 0x3f3f3f3f;
const long long mod=1e9+7;
const long double PI = acos(-1);
// }}} End Header

int main() {
	int a, b, k, t =100;
	cin >> a >> b >> k;
	int cnt =0;
	while(1){
		if(a%t == 0 && b%t == 0){
			cnt++;
			if(cnt == k) break;
		}
		t--;
	}
	cout << t << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <queue>
#include <vector>
#define INF 1e+9
#define mp make_pair
using namespace std;

struct edge{ int to,cost; };
typedef pair<int,int> RV;//remain,vertex
typedef pair<int,RV> P;//cost

int main(){
	int n,m,k,a,l,h;
	while(cin >> n >> m >> l >> k >> a >> h,n){
		bool freeze[100] = {};
		int d[100][101];
		vector<edge> G[100];
		freeze[a] = true;
		freeze[h] = true;
		for(int i = 0;i < n;i++){
			for(int j = 0;j <= m;j++) d[i][j] = INF; 
		}
		for(int i = 0;i < l;i++) {
			int t;
			cin >> t;
			freeze[t] = true;
		}
		for(int i = 0;i < k;i++){
			int a,b,c;
			cin >> a >> b >> c;
			G[a].push_back({b,c});
			G[b].push_back({a,c});
		}
		d[a][m] = 0;
		priority_queue<P,vector<P>,greater<P> > que;
		que.push(mp(0,mp(m,a)));
		while(!que.empty()){
			P p = que.top();que.pop();
			int cost = p.first,remain = p.second.first,v = p.second.second;
			if(d[v][remain] < cost) continue;
			for(int i = 0;i < G[v].size();i++){
				edge e = G[v][i];
				if(!freeze[v]){
					if(remain - e.cost < 0) continue;
					if(d[e.to][remain - e.cost] > d[v][remain] + e.cost){
						d[e.to][remain - e.cost] = d[v][remain] + e.cost;
						que.push(mp(d[e.to][remain - e.cost],mp(remain - e.cost,e.to)));
					}
				}else{
					for(int j = m;j >= remain;j--){
						if(j - e.cost < 0) break;
						if(d[e.to][j - e.cost] > d[v][remain] + e.cost + j - remain){
							d[e.to][j - e.cost] = d[v][remain] + e.cost + j - remain;
							que.push(mp(d[e.to][j - e.cost],mp(j - e.cost,e.to)));
						}
					}
				}
			}
		}
		int mi = INF;
		for(int i = 0;i <= m;i++){
			mi = min(mi,d[h][i]);
		}
		if(mi != INF) cout << mi << endl;
		else cout << "Help!" << endl;
	}
	return 0;
}

Measured memory_bytes: 3352
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
	public static void main(String[] args) {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		FastScanner in = new FastScanner(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		TaskD solver = new TaskD();
		solver.solve(1, in, out);
		out.close();
	}

	static class TaskD {
		final int MOD = (int) (1e9 + 7);

		public void solve(int testNumber, FastScanner in, PrintWriter out) {
			int n = in.nextInt();
			int m = in.nextInt();
			int[] x = new int[n];
			for (int i = 0; i < x.length; i++) {
				x[i] = in.nextInt();
			}
			int[] y = new int[m];
			for (int i = 0; i < y.length; i++) {
				y[i] = in.nextInt();
			}
			int s = f(x, 1);
			int ans = f(y, s);
			out.println(ans);
		}

		private int f(int[] x, int s) {
			long res = 0;
			long sum = 0;
			for (int i = 0; i < x.length; i++) {
				long cx = x[i] % MOD;
				if (cx < 0) {
					cx += MOD;
				}
				long cur = i * cx % MOD;
				cur -= sum;
				if (cur < 0) {
					cur += MOD;
				}
				res = (res + cur * s) % MOD;
				sum += cx;
				if (sum >= MOD) {
					sum -= MOD;
				}
			}
			return (int) res;
		}

	}

	static class FastScanner {
		private BufferedReader in;
		private StringTokenizer st;

		public FastScanner(InputStream stream) {
			in = new BufferedReader(new InputStreamReader(stream));
		}

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

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

	}
}



Measured memory_bytes: 45320
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

int main() {
    ll n, a, b;
    scanf("%lld%lld%lld", &n, &a, &b);
    if (a == 0) {
        printf("0\n");
    } else {
        ll d = n / (a + b), r = n % (a + b);
        ll ans = d * a;
        if (r > a)
            ans += a;
        else
            ans += r;
        printf("%lld\n", ans);
    }
    return 0;
}


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

int	main(void)
{
  	int	N;
  	int *x;
  	int num;
  	int	i;
  	int	sum;
  	double ave;
  	int	av;
  	int	sta;
  
  	num = scanf("%d", &N);
  	if (num != 1)
    	return (0);
  
  	x = (int *)malloc(sizeof(int) * N);
  	
  	sum = 0;
  	for (i=0; i<N; i++)
    {
      	num = scanf("%d", &x[i]);
      	if (num != 1)
          	return (0);
      	sum += x[i];
    }
  
 	ave = (double)sum / (double)N;
  
  	if (ceil(ave) - ave < ave - floor(ave))
      	av = (int)ceil(ave);
  	else
      	av = (int)floor(ave);
  
  	sta = 0;
  	for (i=0; i<N; i++)
    {
      	sta += (x[i] - av) * (x[i] - av);
    }
  
  	printf("%d", sta);
  	return (0);
}

Measured memory_bytes: 128
import sys

sys.setrecursionlimit(10 ** 8)

input = sys.stdin.readline


def main():
    N = int(input())
    A = [int(x) for x in input().split()]

    A.sort()
    ans = 0
    for i in range(N, 3 * N, 2):
        ans += A[i]

    print(ans)


    

if __name__ == '__main__':
    main()



Measured memory_bytes: 37212
#ifdef debug
#define _GLIBCXX_DEBUG
#endif

#include <bits/stdc++.h>
//#include "optimization.h"

using namespace std;

#define vec vector
#define ALL(x) begin(x), end(x)

typedef unsigned int ui;
typedef long long ll;
typedef long double ld;
typedef pair< int, int > pii;
typedef pair< long long, long long > pll;

const int inf = 1e9;
const ll inf64 = 1e18;

const int N = 2e5 + 5;

int n;
int a[N];

int main() {

#ifdef debug
    freopen("input.txt", "r", stdin);
#endif

    scanf("%d", &n);

    for(int i = 1;i <= n;i++) {
        scanf("%d", &a[i]);
    }

    sort(a + 1, a + n + 1);

    int res = -1;

    for(int i = 1;i < n;i++) {
        if(res == -1) {
            res = a[i];
            continue;
        }
        if(a[n] % 2) {
            int d1 = min(abs(res - a[n] / 2), abs(res - a[n] / 2 - 1));
            int d2 = min(abs(a[i] - a[n] / 2), abs(a[i] - a[n] / 2 - 1));
            if(d2 < d1) {
                res = a[i];
            }
        }else {
            if(abs(res - a[n] / 2) > abs(a[i] - a[n] / 2)) {
                res = a[i];
            }
        }
    }

    printf("%d %d\n", a[n], res);

    return 0;
}


Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <cstdio>
using namespace std;
int main(){
  int N, T, L, B;
  while(cin >> N >> T >> L >> B, N){
    string board(N+1,'.');
    int l;
    for(int i = 0; i < L; ++i){
      cin >> l;
      board[l] = 'l';
    }
    int b;
    for(int i = 0; i < B; ++i){
      cin >> b;
      board[b] = 'b';
    }

    vector< vector<double> > prob(T+1,vector<double>(N+1,0.0));
    prob[0][0] = 1.0;
    double ans = 0.0;
    for(int i = 1; i <= T; ++i){
      for(int j = 0; j < N; ++j){
	for(int k = 1; k <= 6; ++k){
	  int next = j + k - 2*max(0,j+k-N);
	  //cout << "j = " << j << ", k = " << k << " " << next << endl;
	  if(board[j] == 'l'){
	    if(i > 1){
	      if(board[next] == 'b')
		prob[i][0] += prob[i-2][j]/6.0;
	      else
		prob[i][next] += prob[i-2][j]/6.0;
	    }
	  }else if(board[next] == 'b'){
	    prob[i][0] += prob[i-1][j]/6.0;
	  }else{
	    prob[i][next] += prob[i-1][j]/6.0;
	  }
	}
      }
      ans += prob[i][N];
    }
    printf("%.10f\n",ans);
  }
  return 0;
}

Measured memory_bytes: 3204
#include <algorithm>
#include <cassert>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>

#include <limits.h>

using namespace std;

typedef long long ll;

template<class T>
inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}

template<class T>
inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
}

vector<int> ls;
vector<int> rs;

int main(void) {
    string S;
    cin >> S;
    const int slen = (int) S.size();

    for (int i = 0; i < slen; i++) {
        if (S[i] == 'L') {
            ls.push_back(i);
        } else {
            rs.push_back(i);
        }
    }

    vector<int> ans(slen, 0);

    for (auto r : rs) {
        auto it = upper_bound(ls.begin(), ls.end(), r);
        const int l = *it;

        if ((l - r) % 2 == 0) {
            ans[l]++;
            // printf("R %d to %d\n",r, l);
        } else {
            ans[l - 1]++;
            // printf("R %d to %d\n",r, l - 1);
        }
    }

    for (auto l : ls) {
        // int left = -1, right = (int) rs.size(), mid;
        // while (right - left > 1) {
        //     mid = left + (right - left) / 2;
        //     if (rs[mid] > l) {
        //         right = mid;
        //     } else {
        //         left = mid;
        //     }
        // }
        // const int r = mid;

        auto it = upper_bound(rs.begin(), rs.end(), l);
        it--;
        const int r = *it;
        if ((l - r) % 2 == 0) {
            ans[r]++;
            // printf("L %d to %d\n", l, r);
        } else {
            ans[r + 1]++;
            // printf("L %d to %d\n", l, r + 1);
        }
    }

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

    return 0;
}


Measured memory_bytes: 4260
function Main(input) {

	// 1行目がinput[0], 2行目がinput[1], …に入る
	input = input.split("\n");
    
    let x = Number(input[0]);
    if(x) console.log(0);
    else console.log(1);
    
}

Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 29692
K,N = map(int, input().split())
A = list(map(int, input().split()))
dist = []
bef = A[0]
for i in A:
    if i == A[0]:
        continue
    dist.append(i - bef)
    bef = i
dist.append(K - bef + A[0])
print(sum(dist)-max(dist))


Measured memory_bytes: 25840