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

using namespace std;

#define rep(i, n) for (int i = 0; i < (n); ++i)

using ll = long long;
using pint = pair<int, int>;
using mint = map<int, int>;

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

const char sp = ' ';
const char cmm = ',';
const int MOD = 1e9+7;
const int INF = 1e9;
const ll LINF = 1e18;

ll mod(ll a, ll b){return (a%b+b)%b;}
ll gcd(ll a, ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b){return a*b/gcd(a,b);}
void Yes(){cout << "Yes" << endl;}
void No(){cout << "No" << endl;}
void Judge(bool b){b?Yes():No();}
void YES(){cout << "YES" << endl;}
void NO(){cout << "NO" << endl;}
void JUDGE(bool b){b?YES():NO();}
ll powMod(ll b, ll e, ll m){ll r=1;while(e>0){if(e&1)r=(r%m)*(b%m)%m;b=(b%m)*(b%m)%m;e>>=1;}return r;}
double distance(ll x1, ll y1, ll x2, ll y2){return sqrt((x1-x2)*(x1-x2) + (y1-y2)*(y1-y2));}

template<typename T>
void ppp(T n){cout << n << endl;}
template<typename T1, typename T2> ostream& operator<<(ostream& s, const pair<T1, T2>& p) {return s << "(" << p.first << ", " << p.second << ")";}
template<typename T> ostream& operator<<(ostream& s, const vector<T>& v) {
    int len = v.size();
    s << '[';
    for (int i = 0; i < len; ++i) {
        s << v[i]; if (i < len-1) s << ", ";
    }
    s << ']';
    return s;
}

int n, k;
vector<int> d(10);
bool hate(int x){
    while(x > 0){
        rep(i, k){
            if(d[i] == x%10) return true;
        }
        x /= 10;
    }
    return false;
}

int main(){

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

    cin >> n >> k;
    d.resize(k);
    rep(i, k) cin >> d[i];

    for(int i = n; i <= 100000; ++i){
        if(hate(i)) continue;
        ppp(i);
        break;
    }

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for (long long i = 0; i < (long long)n; i++)
//#define _GLIBCXX_DEBUG
using namespace std;
using ll = long long;
using Pi = pair<int, int>;
using Pl = pair<ll, ll>;
using Vl = vector<ll>;
using vi = vector<int>;
using Graph = vector<vi>;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  // std::cout << std::fixed << std::setprecision(15); //"for float-base
  // problem"
  string S, T;
  cin >> S >> T;
  int ans = 0;
  REP(i, S.size()) {
    if (S.at(i) != T.at(i)) ans++;
  }
  cout << ans << endl;
}

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

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

const long long INF = 1LL << 60;

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

  if(a+b > c+d) cout << "Left" << endl;
  else if(a+b < c+d) cout << "Right" << endl;
  else cout << "Balanced" << endl;

  return 0;
}


Measured memory_bytes: 256
import java.io._
import java.util.StringTokenizer
import scala.util.control.Breaks.{breakable,break}
import scala.collection.mutable.{Map, Queue, PriorityQueue}

object Main extends App {
  val in = new InputReader(System.in)
  val pw = new PrintWriter(System.out)

  val N, M = in.next().toInt
  val A = new Array[Long](N+1)
  for (i <- 1 to N)
    A(i) = in.next().toLong

  ///
  def check(n: Long): Boolean = {
    var rest = M
    var flag = true
    breakable {
      for (i <- 1 to N) {
        var div = 1L
        while (A(i) >= (n+1) * div) {
          rest -= 1
          div *= 2L
        }

        if (rest < 0){
          flag = false
          break
        }
      }
    }

    flag
  }

  // 条件を満たす最小の値を返す
  def binarySearch(min: Long, max: Long): Long = {
    val mid: Long = (max + min) / 2
      (max - min) match{
      case 0 | 1 =>
        check(min) match{
          case true  => min
          case false => max
        }
      case _ =>
        (check(mid)) match{
          case true  => binarySearch(min, mid)
          case false => binarySearch(mid, max)
        }
    }
  }


  /** */
  val base = binarySearch(0L, 1e9.toLong)

  var ans = 0L
  var rest = M
  for (i <- 1 to N) {
    var div = 1L
    while (A(i) >= (base+1) * div) {
      rest -= 1
      div *= 2L
    }

    A(i) = A(i) / div
  }

  val B = A.sorted

  breakable {
    for (i <- (1 to N).reverse) {
      if (rest == 0)
        break
      else {
        rest -= 1
        B(i) = B(i) / 2
      }
    }
  }
  ans = B.sum
  println(ans)

}


class InputReader(stream: InputStream) {
  private val reader = new BufferedReader(new InputStreamReader(stream))
  private var tokenizer: StringTokenizer = new StringTokenizer(reader.readLine())
  def next(): String = {
    while (!tokenizer.hasMoreTokens()) {
      tokenizer = new StringTokenizer(reader.readLine())
    }
    tokenizer.nextToken()
  }
}


Measured memory_bytes: 46612
#include<bits/stdc++.h>
using namespace std;
int main()
{
	char a[101],b[101],c[101],i,j,n;
	scanf("%s %s",a,b);
	n=strlen(a);
	for(i=1;i<=n;i++)
	{
		if(strcmp(a,b)==0)
		{
			printf("Yes");
			return 0;	
		}
		strcpy(c,a);
		a[0]=a[n-1];
		for(j=1;j<n;j++)
		{
			a[j]=c[j-1];
		}
	}
	printf("No");
	return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<iostream>
#include<algorithm>
void solve(void);

int a,b,c,sum;
int n;
int date[1000][4]={0};
int at[1002];

using namespace std;

int main(){
  
  int i,j;
      
  while(1){
    
    scanf("%d %d %d",&a,&b,&c);
    
    if(a==0 && b==0 && c==0){
      break;
    }
    
    sum=a+b+c;

    for(i=0;i<sum;i++){
      at[i]=2;
    }
    
    scanf("%d",&n);
    
    for(i=0;i<n;i++){
      scanf("%d %d %d %d",&date[i][0],&date[i][1],&date[i][2],&date[i][3]);
    }
    
    solve();
	
    for(i=1;i<=sum;i++){
      printf("%d\n",at[i]);
    }
    
  }
  return 0;
}

void solve(){

  int i,j,k,cnt;

  for(i=0;i<n;i++){
    if(date[i][3]==1){
      for(j=0;j<3;j++){
	at[date[i][j]]=1;
      }
    }
  }

  for(i=0;i<n;i++){
    cnt=0;
    if(date[i][3]==0){
      for(k=0;k<3;k++){
	if(at[date[i][k]]==1){
	  cnt++;
	}
      }
    }
    if(cnt==2){
      for(j=0;j<3;j++){
	if(at[date[i][j]]!=1){
	  at[date[i][j]]=0;
	}
      }
    }
    if(cnt==1){
      for(j=0;j<3;j++){
      if(at[date[i][j]]!=1 && at[date[i][j]]!=0){
	at[date[i][j]]=2;
      }
      }
    }
  }
  
}

Measured memory_bytes: 1208
#include <stdio.h>

int main(void) {
	// your code goes here
	long long int n,s=0;
	scanf("%lld",&n);
	long long int r=n;
	while(n!=0){
		s=s+(n%10);
		n=n/10;
	}

	
	if(r%s==0)printf("Yes\n");
	else printf("No\n");
	//printf("%lld\n",);
	return 0;
}


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

int main() {
    string s;
    cin >> s;
    vector<string> words = {"dream", "dreamer", "erase", "eraser"};

    int right = (int)s.size();
    while (right > 0) {
        bool ok = false;
        for (int i = 0; i < 4; i++) {
            int len = (int)words.at(i).size();
            
            if (len > right) continue;

            for (int j = 0; j < len; j++) {
                if (words.at(i).at(j) != s.at(right - len + j)) break;
                
                if (j == len - 1) ok = true;
            }

            if (ok) {
                right -= len;
                break;
            }
        }

        if (!ok) {
            cout << "NO" << endl;
            return 0;
        }
    }

    cout << "YES" << endl;
}   

Measured memory_bytes: 512
#include<iostream>
using namespace std;
int main(){
    int a,b,c,d,e;
    cin >> a >> b >> c >> d >> e;
    int ans = 0;
    if(a < 0){
        ans += c * (-a);
        a = 0;
    }
    if(a == 0){
        ans += d;
    }
    ans += e * (b-a);
    cout << ans << endl;
}



Measured memory_bytes: 3096
#nはりんごの数　りんごiの味はl＋i-1

n,l = map(int,input().split())

each_taste = []
for x in range(1,n+1):
  each_taste.append(l+x-1)
  
if min(each_taste) >= 0:
  print(sum(each_taste[1:]))
  
elif max(each_taste) >= 0:
  print(sum(each_taste))

else:
  print(sum(each_taste[:-1]))

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

#define mod      1e9+7;
#define INF      1e9+9;
#define ps(x,y)  fixed<<setprecision(y)<<x
# define PI 3.14159265358979323846264338327950 L
typedef long long ll;
typedef unsigned long long ull;
int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
#ifndef ONLINE_JUDGE
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
#endif
	int l,r,d,c=0;
	cin>>l>>r>>d;
	for(int i=l;i<=r;i++){
		if(i%d==0)
			c++;
	}
	cout<<c<<endl;
	return 0;
}

Measured memory_bytes: 3652
MAX = 300000001

N, K = map(int, input().split())
xn = [int(i) for i in input().split()]


def main():
    if 0 <= xn[0]:
        print(xn[K - 1])
        return

    if xn[N - 1] < 0:
        print(abs(xn[N - K]))
        return

    ans = MAX

    for i in range(N - K + 1):
        if xn[i + K - 1] < 0 and i + K <= N - 1 and 0 < xn[i + K]:
            ans = min(ans, abs(xn[i]))

        elif 0 <= xn[i + K - 1]:
            ans = min(ans,
                      2 * abs(xn[i]) + abs(xn[i + K - 1]),
                      abs(xn[i]) + 2 * abs(xn[i + K - 1]))

    print(ans)
    return


main()


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

int main() {
    string S, T;
    cin >> S >> T;
    sort(S.begin(), S.end());
    sort(T.begin(), T.end());
    reverse(T.begin(), T.end());
    if (S < T) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 256
main(f){
  float w;
  char*p[]={"light fly","fly","bantam","feather","light","light welter",
	    "welter","light middle","middle","light heavy","heavy"};
  for(;~scanf("%f",&w);)
    //    f=w>48?w>51?w>54?w>57?w>60?w>64?w>69?w>75?w>81?w>91?10:9:8:7:6:5:4:3:2:1:0;
    //    puts(p[f]);
    //  }
    puts(w>48?w>51?w>54?w>57?w>60?w>64?w>69?w>75?w>81?w>91?"heavy":"light heavy":"middle":"light middle":"welter"
	 :"light welter":"light":"feather":"bantam":"fly":"light fly");
  return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
typedef pair<ll,ll> P;
struct edge{ll to, cost;};
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define INF 1000000000000
#define ALL(a)  (a).begin(),(a).end()
#define large 1000000000000000000

vector<pair<long long, long long> > prime_factorize(long long N) {
    vector<pair<long long, long long> > res;
    for (long long a = 2; a * a <= N; ++a) {
        if (N % a != 0) continue;
        long long ex = 0;
        while (N % a == 0) {
            ++ex;
            N /= a;
        }
        res.push_back({a, ex});
    }
    if (N != 1) res.push_back({N, 1});
    return res;
}


int main(){
    ll n; 
    cin >> n;

  ll ref[41];
  ll piyo = 0;
  for(int i = 1; i < 40;i++){
      ll hoge = 0;
    ll temp = 0;
      for(ll j = 1; j <= i; j++){
            hoge++;
            temp += j;
            if(i - temp <= j){
                break;
            }
        }
        ref[i] = hoge;
  }
  const auto &pf = prime_factorize(n);
    long long res = 0;
    for (auto p : pf) res += ref[p.second];
	cout << res << endl;
	return 0;

}

Measured memory_bytes: 3632
#include<set>
#include<map>
#include<cmath>
#include<queue>
#include<vector>
#include<cstdio>
#include<string>
#include<cstring>
#include<iostream>
#include<algorithm>
#define LL long long
using namespace std;
const int maxn = 1e5 + 5;
const int inf = 0x3f3f3f3f;
const LL mod = 1e9 + 7;
const double EPS = 1e-8;

int n,m;
int h[maxn],u,v,fa[maxn];
vector<int>G[maxn];

bool jj(int x){
	for(int i = 0; i < G[x].size(); i++){
		if(h[x] <= h[G[x][i]]) return 0;
	}
	return 1;
}

int main(){
	scanf("%d %d", &n, &m);
	for(int i = 1; i <= n; i++) fa[i] = i;
	for(int i = 1; i <= n; i++) scanf("%d", &h[i]);
	for(int i = 1; i <= m; i++){
		scanf("%d %d", &u, &v);
		G[u].push_back(v);
		G[v].push_back(u);
	}
	int ans = 0;
	for(int i = 1; i <= n; i++){
		if(jj(i)) ans++;
	}
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 9676
#include <iostream>
#include <vector>

using namespace std;
using ll = long long;

int main(){
  vector<vector<ll>> a(3, vector<ll>(3, 0));
  vector<vector<ll>> c(3, vector<ll>(3, 0));
  for(ll i = 0; i < 3; ++i){
    for(ll j = 0; j < 3; ++j){
      cin >> a[i][j];
    }
  }

  ll N;
  cin >> N;
  ll b;
  for(ll i = 0; i < N; ++i){
    cin >> b;
    for(ll i = 0; i < 3; ++i){
      for(ll j = 0; j < 3; ++j){
        if(a[i][j] == b){
          c[i][j] = 1;
        }
      }
    }
  }

  for(ll i = 0; i < 3; ++i){
    if(c[i][0] && c[i][1] && c[i][2]){
      cout << "Yes" << endl;
      return 0;
    }
    if(c[0][i] && c[1][i] && c[2][i]){
      cout << "Yes" << endl;
      return 0;
    }
  }

  if(c[0][0] && c[1][1] && c[2][2]){
    cout << "Yes" << endl;
    return 0;
  }

  if(c[0][2] && c[1][1] && c[2][0]){
    cout << "Yes" << endl;
    return 0;
  }
  
  cout << "No" << endl;

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <math.h>
using namespace std;

int main(void){
    int n,k;
    cin>>n>>k;
    int a[n];
    for(int i=0;i<n;i++) cin>>a[i];

    for(int i=0;i<k;i++){
        int newa[n] = {};
        if(a[0]==n && a[n-1]==n) break;

        for(int j=0;j<n;j++){
            newa[max(j-a[j],0)] ++;
            if(j+a[j]+1 < n) newa[j+a[j]+1] --;
        }
        for(int j=1;j<n;j++) newa[j] += newa[j-1];
        for(int j=0;j<n;j++) a[j] = newa[j];
    }

    for(int i=0;i<n;i++){
        cout<<a[i]<<" ";
    }
    cout<<endl;
}

Measured memory_bytes: 5132
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using System.Net.WebSockets;

class Test
{

    // Driver code 
    public static void Main()
    {
        ///var t = int.Parse(Console.ReadLine());

        //while (t > 0)
        {
          //  t--;

            var ii = Console.ReadLine().Split(' ').Where(xx => !string.IsNullOrEmpty(xx)).Select(xx => int.Parse(xx)).ToArray();

            var n = ii[0];
            var x = ii[1];
            var tt = ii[2];

            // var arr = Console.ReadLine().Split(' ').Where(x => !string.IsNullOrEmpty(x)).Select(xx => int.Parse(xx)).ToList();
            //var str = Console.ReadLine();
            var ans1 = n / x;
            var nas2 = n % x;
            var final = ans1 * tt + (nas2>0?tt:0);
            Console.WriteLine(final);
        }
    }

}




Measured memory_bytes: 18920
#include "bits/stdc++.h"
using namespace std;

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

    for (int dif = 3; dif <= 999; dif++){
        if (dif == b - a) cout << (1 + b - a) * (b - a) / 2 - b << endl;
    }
}

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

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define rep(i,n) FOR(i,0,n)
#define RFOR(i,a,b) for(int i=(a)-1;i>=(b);i--)
#define rrep(i,n) RFOR(i,n,0)

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

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

	ll n;
	cin >> n;

	ll a[n];
	rep(i,n) cin >> a[i];

	ll ans = 0;
	bool upd = true;
	while(upd){
		upd = false;
		rep(i,n){
			if(a[i] >= n){
				upd = true;
				ll b = a[i] / n;
				ans += b;
				rep(j,n){
					if(j == i) a[j] %= n;
					else a[j] += b;
				}
			}
		}
	}

	cout << ans << endl;
}

Measured memory_bytes: 256
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ALL(v) v.begin(), v.end()
typedef long long ll;

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

int f(int a){
  int ans=1;
  for (int i = 2; i <= sqrt(a); i++) {
    int cnt = 0;
    while (a % i == 0) {
      cnt++;
      a /= i;
    }
    ans *= (cnt + 1);
    if (a == 1) break;
  }
  if (a != 1) ans *= 2;
  return ans;
}

int main(){
  int n;
  cin>>n;
  
  ll sum=0;
  for(int i=1;i<=n-1;i++){
    sum+=f(i);
  }
  cout<<sum<<endl;
 
  return 0; 
}

Measured memory_bytes: 3668
#pragma GCC optimize(2)

#include <cmath>
#include <cstdio>
#include <cctype>
#include <cstring>

#include <set>
#include <queue>
#include <complex>
#include <algorithm>

int read(void){
	int res = 0, sign = 1;
	char ch = std::getchar();
	while(!std::isdigit(ch)){
		if(ch == '-')
			sign = -1;
		ch = std::getchar();
	}
	while(std::isdigit(ch))
		res = res * 10 + ch - 48, ch = std::getchar();
	return sign * res;
}

template<class Tp>
	void write(const Tp &x){
		if(x > 9)
			write(x / 10);
		std::putchar(x % 10 + 48);
	}

typedef long long ll;
typedef unsigned long long ull;
typedef double rl;
typedef long double RL;

const rl PI = 3.1415926535898, E = 2.71828182845904;

const int MAXN = 2e5 + 19;

int n, x[MAXN], y[MAXN], d[MAXN];
std::vector<int> pie[MAXN * 2], naa[MAXN * 2], hen[MAXN * 2], shu[MAXN * 2];

inline bool cmpx(int a, int b){
	return x[a] < x[b];
}

inline bool cmpy(int a, int b){
	return y[a] < y[b];
}

int m[5];
int ans = 0x3f3f3f3f;

int main(){
	n = read();
	for(int i = 1; i <= n; ++i){
		x[i] = read(), y[i] = read();
		pie[x[i] - y[i] + 200000].push_back(i);
		naa[x[i] + y[i]].push_back(i);
		char c = std::getchar();
		if(c == 'U')
			d[i] = 1;
		else if(c == 'R')
			d[i] = 2;
		else if(c == 'D')
			d[i] = 3;
		else if(c == 'L')
			d[i] = 4;
		if(d[i] == 1 || d[i] == 3)
			shu[x[i]].push_back(i);
		else
			hen[y[i]].push_back(i);
	}
	for(int i = 0; i <= 400000; ++i){
		if(pie[i].size()){
			std::sort(pie[i].begin(), pie[i].end(), cmpx);
			m[1] = m[2] = -1;
			for(int j = 0; j < pie[i].size(); ++j){
				if(d[pie[i][j]] == 1 || d[pie[i][j]] == 2)
					m[d[pie[i][j]]] = x[pie[i][j]];
				else if(d[pie[i][j]] == 3){
					if(m[2] != -1)
						ans = std::min(ans, (x[pie[i][j]] - m[2]) * 2);
				}
				else{
					if(m[1] != -1)
						ans = std::min(ans, (x[pie[i][j]] - m[1]) * 2);
				}
			}
		}
		if(naa[i].size()){
			std::sort(naa[i].begin(), naa[i].end(), cmpx);
			m[2] = m[3] = -1;
			for(int j = 0; j < naa[i].size(); ++j){
				if(d[naa[i][j]] == 2 || d[naa[i][j]] == 3)
					m[d[naa[i][j]]] = x[naa[i][j]];
				else if(d[naa[i][j]] == 1){
					if(m[2] != -1)
						ans = std::min(ans, (x[naa[i][j]] - m[2]) * 2);
				}
				else{
					if(m[3] != -1)
						ans = std::min(ans, (x[naa[i][j]] - m[3]) * 2);
				}
			}
		}
	}
	for(int i = 0; i <= 200000; ++i){
		std::sort(hen[i].begin(), hen[i].end(), cmpx);
		int mx = -1;
		for(int j = 0; j < hen[i].size(); ++j)
			if(d[hen[i][j]] == 2)
				mx = x[hen[i][j]];
			else if(mx != -1)
				ans = std::min(ans, x[hen[i][j]] - mx);
		std::sort(shu[i].begin(), shu[i].end(), cmpy);
		int my = -1;
		for(int j = 0; j < shu[i].size(); ++j)
			if(d[shu[i][j]] == 1)
				my = y[shu[i][j]];
			else if(my != -1)
				ans = std::min(ans, y[shu[i][j]] - my);
	}
	if(ans == 0x3f3f3f3f)
		std::puts("SAFE");
	else
		write((ll)ans * 5);
	return 0;
}

Measured memory_bytes: 61208
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n,k;
    cin>>n>>k;
    long ans;
    if(k%2!=0){
        long count = n/k;
        ans =count*count*count;
        cout<<ans<<endl;
        return 0;
    }
    else{
        long count1 = n/k;
        ans = count1*count1*count1;
        long count2 = 0;
        for(int i=1;i<=n;i++){
            if(i%k==k/2)count2++;
        }
        ans+= count2*count2*count2;
        cout<<ans<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <sstream>
#include <string>
#include <cstdio>
#include <stack>
#include <queue>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cstring>
#include <tuple>
#include <utility>

using namespace std;

typedef long long LL;
typedef vector<int> Array;
typedef pair<int, int> P;

const LL LINF = 1LL << 60;
const LL MOD = 1000000009;
#define rep(i,n) for(int i=0;i<(int)n;++i)
#define all(c) (c).begin(), (c).end()

struct edge{ LL to, cost; edge(int t, LL c) :to(t), cost(c){} };

vector<LL> dijk(vector<vector<edge>> graph, int s)
{
	vector<LL> costs(graph.size(), LINF);
	priority_queue<pair<LL, int>, vector<pair<LL, int>>, greater<pair<LL, int>>> que;
	que.emplace(0, s);
	costs[s] = 0;
	while (!que.empty())
	{
		auto top = que.top(); que.pop();
		int v = top.second; LL dist = top.first;
		if (dist > costs[v]) continue;

		for (const auto& e : graph[v])
		{
			if (costs[v] + e.cost < costs[e.to])
			{
				costs[e.to] = costs[v] + e.cost;
				que.emplace(costs[e.to], e.to);
			}
		}
	}
	return move(costs);
}

int main()
{
	int n;
	while (cin >> n && n)
	{
		int k; cin >> k;
		vector<vector<edge>> graph(n);
		vector<LL> dists(n, LINF);
		for (int i = 0; i < k; i++)
		{
			int com; cin >> com;
			if (com == 0)
			{
				int a, b;
				cin >> a >> b;
				a--; b--;
				dists = dijk(graph, a);
				LL ans = dists[b];
				cout << (ans == LINF ? -1 : ans) << endl;
			}
			else
			{
				int c, d, e; cin >> c >> d >> e;
				c--; d--;
				edge e1(d, e), e2(c, e);
				graph[c].push_back(e1);
				graph[d].push_back(e2);
			}
		}
	}
	return 0;
}

Measured memory_bytes: 1288
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		new Main().run();
	}

	private void run() {
		Scanner scanner = new Scanner(System.in);
		while (true) {
			int e = scanner.nextInt();
			if (e == 0)
				break;
			int ans = e;
			for (int z = 0; z * z * z <= e; z++) {
				int k = e - z * z * z;
				int y = (int) Math.sqrt(k);
				int x = k - y * y;
				ans = Math.min(ans, x + y + z);
			}
			System.out.println(ans);
		}
	}
}

Measured memory_bytes: 26688
#include<bits/stdc++.h>
using namespace std;
#define lli long long int
#define pii pair<int,int>
#define pll pair<lli,lli>
#define vi  vector<int>
#define vii vector<pair<int,int>>
#define vll vector<lli>
#define pb  push_back
#define mpr  make_pair
#define ff  first
#define ss  second
#define mod 1000000007
#define pie 3.14159265358979323846264338327950L
#define all(x) x.begin(),x.end()
#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define testcase() int t;cin>>t;while(t--)
#define clean(x) memset(x,0,sizeof(x))
#define FOR(x,y) for(int i=x;i<=y;i++)
const lli maxn = 2e5+9;
vector<lli> catlan(int n) {
    vector<lli> dp(n + 1, 0);
    dp[0] = 1;
    dp[1] = 1;
    for (int i = 2; i <= n; i ++) {
        for (int j = 0; j < i; ++ j) {
            dp[i] += dp[j] * dp[i - j - 1];
        }
    }
    return dp;
}
lli b_ex(lli n,lli a){lli res=1;while(n){if(n%2==1)res*=a;n>>=1;a=a*a;}return res;}
lli ncr(lli n,lli k){lli ans=1;if(k>n-k)k=n-k;for(lli i=1;i<=k;i++){ans*=(n-i+1),ans=ans/i;}return ans;}
lli power(lli a , lli n){lli ans = 1;while(n){if(n % 2)ans = (ans * a) % mod;n /= 2;a = (a * a) % mod;}return ans;}
lli lcm(lli a,lli b){lli ans=(a*b)/(__gcd(a,b));return ans;}
lli set_bits(lli n)
{
    int c=0;
    if(n==0)return 0;
    while(n)
    {
        if((n&1)==1)
        {
           cout<<c<<" ";
        }
        c++;
        n=n>>1;
    }
    return c;
}

string X="IF THE CONSTRAINTS ARE LOW JUST BRUTE FORCE IT!!!!!!!!!!!!!!!!!!!!!";
///------------------ALWAYS lli-----TEMP TSF99--------------------------------------------------------------------------------------///


void solve()
{
    lli a,b;
    char c;
    cin>>a>>c>>b;
    if(c=='+')cout<<(a+b)*1LL<<endl;
    else cout<<(a-b)*1LL<<endl;

}
int main()
{
    solve();
}


Measured memory_bytes: 3604
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N=sc.nextInt(),M=sc.nextInt(),C=sc.nextInt(),ans=0;
		int[]b = new int[M];
		for(int i=0; i<M; i++) b[i]=sc.nextInt();

		int num=0;
		for(int i=0; i<N; i++) {
			for(int j=0; j<M; j++) {
				num += sc.nextInt()*b[j];
			}
			if(num+C > 0) ans++;
			num=0;
		}
		System.out.println(ans);
	}
}


Measured memory_bytes: 22100
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
//#define int long long

template <class T>
bool INRANGE(T x, T a, T b) { return a <= x && x <= b; }
template <class T>
bool chmax(T &a, const T &b) {if (a < b){ a = b; return 1;} return 0;}
template <class T>
bool chmin(T &a, const T &b) {if (a > b){ a = b; return 1;}return 0;}
template <class T>
void printv(vector<T> v) {for (T t : v) {cout << t << " ";}cout << '\n';}

#define REP(i, n) for (int i = 0; i < (n); ++i)
#define RREP(i, n) for (int i = (n); i >= 0; --i)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define RFOR(i, a, b) for (int i = (a); i >= (b); --i)
#define ALL(v) (v).begin(), (v).end()
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" \
                      << " " << __FILE__ << endl;

typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<vi> vvi;
typedef pair<int, int> pii;

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

    int N;
    cin >> N;

    vector<pii> ba(N);

    REP(i,N){
        int a, b;
        cin >> a >> b;
        ba[i] = {b,a};
    }

    sort(ALL(ba));

    ll now= 0, lim = 0;

    REP(i,N){
        now += ba[i].second;
        if (lim != ba[i].first) lim = ba[i].first;

        //cout << now << " " << lim << endl;

        if (now > lim) {
            cout << "No" << endl;
            return 0;
        }
    }

    cout << "Yes" << endl;

    return 0;
}


Measured memory_bytes: 1792
#include<iostream>
#include<cmath>
using namespace std;
int main(){
int a,b;
  cin >> a >> b;
  if ( a == b){
   cout << 2 * a << endl;
  }
  else
  {
    a = max(a,b);
    cout << a + a - 1 << endl;
  }
}

Measured memory_bytes: 256
a = gets.to_i + 1
b = gets.to_i + 1
c = gets.to_i + 1
x = gets.to_i
count = 0
a.times do |i|
	b.times do |j|
		c.times do |k|
			sum = i * 500 + j * 100 + k * 50
			if sum == x
				count += 1
			end
		end
	end
end



puts count

Measured memory_bytes: 1788
edges=[]
N,M,Q=map(int,input().split())
conditions=[]
for i in range(Q):
    a,b,c,d=map(int,input().split())
    conditions.append([a,b,c,d])
for i in range(M):
    edges.append(list(range(i+1,M+1)))
A=[]
score=0
score_list=[]
def dfs(x,N,M):
    A.append(x)
    score=0
    if len(A)<N:
        for i in edges[x-1]:
            dfs(i,N,M)
            if i==edges[x-1][-1]:
                A.pop()
    elif len(A)==N:
        for i in range(Q):
            if A[conditions[i][1]-1]-A[conditions[i][0]-1]==conditions[i][2]:
                score+=conditions[i][3]
            if i==Q-1:
                score_list.append(score)                
        A.pop()
dfs(1,N,M)


print(max(score_list))

Measured memory_bytes: 10788
open Batteries
let rec solve acc = function
  | (x::y::ys) ->
      let acc' = acc + if x = y then 0 else 1 in
      solve acc' (y::ys)
  | _ -> acc
let () =
  Scanf.scanf "%s" String.to_list |> solve 0 |> Printf.printf "%d\n"

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

int main() {
  int c[3][3];
  for ( int i = 0; i < 3; i++ ) {
    for ( int j = 0; j < 3; j++ ) {
      cin >> c[i][j];
    }
  }

  string ans = "No";
  for ( int k = -100; k <= 100; k++ ) {
    int a[3], b[3];
    a[0] = k;
    b[0] = c[0][0] - a[0];
    for ( int i = 1; i < 3; i++ ) { a[i] = c[i][0] - b[0]; }
    for ( int j = 1; j < 3; j++ ) { b[j] = c[0][j] - a[0]; }
    if ( a[1]+b[1] == c[1][1] && a[1]+b[2] == c[1][2] && a[2]+b[1] == c[2][1] && a[2]+b[2] == c[2][2] ) {
      ans = "Yes";
      break;
    }
  }

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


Measured memory_bytes: 3560
import numpy as np
n, m = map(int, input().split())
k = [0] * n
for i in range(n):
    k[i] = list(map(int, input().split()))

b = np.zeros((n, m))
for i in range(n):
    w = k[i]
    for j in range(1, len(w)):
        b[i, int(w[j])-1] = 1
print(sum(b.sum(axis=0) == n))


Measured memory_bytes: 12408
#pragma GCC optimize ("O3")
#pragma GCC optimize ("unroll-loops")

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

#define pb push_back
#define F first
#define S second
#define f(i,a,b)  for(int i = a; i < b; i++)
//#define endl '\n'

using ll = long long;
using db = long double;
using row = vector<int>;
using ii = pair<int, int>;

const int N = 1e5 + 5, M = 1e6 + 5, LG = 17, MOD = 1e9 + 7;
const int BLOCK = 1900;
const int BLOCKN = N / BLOCK + 1;
const long double EPS = 1e-7;
int A[N], n, m, v, p;

ll sum[N];
int count(int L, int R){
  if(L>R)return 0;
  return upper_bound(A+1,A+n+1,R)
  -lower_bound(A+1,A+n+1,L);
}
int main(){
#ifdef ONLINE_JUDGE
  ios_base::sync_with_stdio(0);
  cin.tie(0);
#endif // ONLINE_JUDGE


  cin >> n >> m >> v >> p;

  f(i,1,n+1){
    cin >> A[i];
  }

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

  f(i,1,n+1)
    sum[i] = sum[i-1]+A[i];

  int ans =0;
  f(i,1,n+1){
    ///check this
    int val = A[i] + m;
    int lft = v - 1;
    int x = count(val+1,A[n]);
    if(x>p-1)continue;
    lft -= x;
    lft -= (count(0,A[i])-1);  /// i can add to those
    if(lft<=0){
      ans++;
      continue;
    }
    int canBeMore = (p-1)-x;
    ///those who i can't add m to those between A[i] + 1 and A[i] + m
    int l = upper_bound(A+1,A+n+1,A[i]) - A;  ///first element > A[i]
    int r = upper_bound(A+1,A+n+1,val)-A;  --r; ///last element <= A[i] + m
    lft -= canBeMore;
    r -= canBeMore;
    if(lft<=0){
      ans++;
      continue;
    }
    if(1ll*lft*m<=1ll*val*(r-l+1)-(sum[r]-sum[l-1])){
      ans++;
    }

  }

  cout<<ans<<endl;



  return 0;
}


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

int main(){

  	string s1,s2;
  	cin >> s1 >> s2;
  	
  	if(s1.size() > s2.size()){
      cout << "GREATER" << endl;
    }
  	else if(s1.size() < s2.size()){
      cout << "LESS" << endl;
    }
  	else{
      	if(s1 > s2){
          	cout << "GREATER" << endl;
        }
      	else if(s1 < s2){
         	cout << "LESS" << endl; 
        }
      	else{
         	cout << "EQUAL" << endl; 
        }
    }
  	
  	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
bool comp(int a,int b)
{
	a=a%10?a%10:10;
	b=b%10?b%10:10;
	return a>b;
}
int main()
{
	int a[5];
	for(int i=0;i<5;i++)cin>>a[i];
	sort(a,a+5,comp);
	int ans=0;
	for(int i=0;i<4;i++)ans+=ceil(a[i]/10.0)*10;
	ans+=a[4];
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i,b,e) for(int i=(b);i<(e);++i)
#define rep(i,e) for(int i=0;i<(e);++i)
int main() {
  int h, w;
  while(cin >> h >> w){
    if(h==0) return 0;
    int l = h*h+w*w;
    int hh=1e9, ww=1e9, ll=1e9;
    for(int i=150; i>0; i--){
      for(int j=150; j>i; j--){
        int tmp = i*i+j*j;
        if(tmp>l){
          if(ll>tmp || (ll==tmp && hh>i)){
            ll = tmp;
            hh = i;
            ww = j;
          }
        }
        else if(tmp==l && i>h){
          if(ll>tmp || (ll==tmp && hh>i)){
            ll = tmp;
            hh = i;
            ww = j;
          }
        }
      }
    }
    cout << hh << " " << ww << endl;
  }
  return 0;
}


Measured memory_bytes: 3080
#include<stdio.h>
long long N;
int i;
int main()
{
	for(;~scanf("%ld",&N);)
	{
		for(i=0;N>2;i++)
			N=N/3+N%3/2+N%3%2;
		printf("%d\n",N==2?i+1:i);
	}
	return 0;
}

Measured memory_bytes: 596
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int r,d,x;
    cin>>r>>d>>x;
    for(int i=0; i<10; i++)
    {
        int x1;
        x1=x*r-d;
        cout<<x1<<endl;
        x=x1;
    }
}


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

using namespace std;
int main(){
	int n,k;
	string s;
	cin>>n>>s>>k;
	k--;
	for(int i=0;i<s.size();i++){
		if(s[i]!=s[k])s[i]='*';
	}
	cout<<s<<endl;
	return 0;
}

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

class Main {

    public static void main(String[] args) {

	final Scanner stdin = new Scanner(System.in);
	Map<String, Integer> map = new HashMap<String, Integer>();

	String longStr = "";

	while ( stdin.hasNext() ) {
	    final String key = stdin.next();
	    if ( map.containsKey( key ) ) {
		map.put( key, map.get( key ) + 1 );
	    } else {
		map.put( key, 1 );
	    }
	    if ( longStr.length() < key.length() ) {
		longStr = key;
	    }
	}

	String maxFreqStr = "";
	int maxFreq = 0;
	for ( String str : map.keySet() ) {
	    if ( maxFreq < map.get( str ) ) {
		maxFreqStr = str;
		maxFreq = map.get( str );
	    }
	}
	System.out.printf("%s %s\n", maxFreqStr, longStr);
	
    }    
}

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

int main() {
	int n; 
	cin>>n;
    pair<pair<string,int>,int> a[101];
    for(int i=0;i<n;i++){
        string s;
        int x;
        cin>>s>>x;
        a[i]=make_pair(make_pair(s,-1*x),i+1);
    }
    sort(a,a+n);
     for(int i=0;i<n;i++){
         cout<<a[i].second<<"\n";
     }
}


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

int main(){
  int a,b;
  cin >> a >> b ;
  for(int n=0;n<10000;n++){
  	int za = n*8/100;
    int zb = n*10/100;
      if( a==za && b==zb){
      cout << n << endl;
      return 0;
      }
  }
  cout << -1 << endl;
  return 0;
}  	
    


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

int main()
{
  int a,b,c,d,e;
  int h;

  cin >> a >> b >> c >> d >> e;

  if(a < 40)
    {
      a = 40;
    }
  if(b < 40)
    {
      b = 40;
    }
  if(c < 40)
    {
      c = 40;
    }
  if(d < 40)
    {
      d = 40;
    }
  if(e < 40)
    {
      e = 40;
    }
  
  cout << (a+b+c+d+e)/5 << endl;

}



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

int main(){
    string s;
    cin >> s;

    long long count_x = 0;
    long long l = 0;
    long long r = s.size()-1;
    while(l < r){
        if(s[l] == s[r]){
            l++;
            r--;
        }
        else if(s[l] == 'x'){
            l++;
            count_x++;
        }
        else if(s[r] == 'x'){
            r--;
            count_x++;
        }
        else{
            count_x = -1;
            break;
        }
    }
    cout << count_x << endl;

    return 0;
}

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

int main(){
 int N;
 cin >> N;
 int S = 1;
  
 for (int i = 0; i < N; i++){
  int A;
  cin >> A;
  
  if (A % 2 == 0){
   
   if (A % 3 != 0 && A % 5 != 0){
    cout << "DENIED" << endl;
    S = 1;
    break;
   }
   else{
    S = 0;
   }
  }
  else{
   S = 0;
  } 
 }
  
 if(S == 0){
  cout << "APPROVED" << endl;
 }
}
  


Measured memory_bytes: 256
#include <iostream>
using namespace std;
#define MOD 1000000007

int main()
{
	int N,f=0,b=0;
	long long int K,ans=0;
	cin >> N >>K;
	int A[N];
	long long int x=(K*(K-1)/2)%MOD,y=(K*(K-1)/2+K)%MOD;
	for(int i=0;i<N;i++) cin >> A[i];
	for(int i=0;i<N;i++)
	{
		b=0;
		f=0;
		for(int j=0;j<i;j++)
			if(A[j]<A[i]) f++;
		for(int j=i+1;j<N;j++)
			if(A[j]<A[i]) b++;
		ans+=f*x+b*y;
		ans%=MOD;
	}
	cout << ans <<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <math.h>
using namespace std;

int main() {
    int n, k;
    cin >> n >> k;
    int num = 1;
    for (int i = 0; i < n; i++) {
        if (num * 2 < num + k)
            num *= 2;
        else 
            num += k;
    }
    cout << num << endl;
    return 0;
}

Measured memory_bytes: 256
import java.io.BufferedInputStream;
        import java.util.Scanner;

/**
 *
 */
public class Main {

    public static void solve(){
        Scanner sc = new Scanner(new BufferedInputStream(System.in));
        String[] str = sc.nextLine().split(" ");
        if (str[0].charAt(str[0].length()-1) == str[1].charAt(0) &&
                str[1].charAt(str[1].length()-1) ==
                        str[2].charAt(0)) {
            System.out.println("YES");
        } else {
            System.out.println("NO");
        }

    }
    public static void main(String[] argc) {
        solve();
    }
}


Measured memory_bytes: 23892
#include <bits/stdc++.h>
using namespace std;
#define rep(i, m, n) for (int i = m; i < n; ++i)
#define rem(i, m, n) for (int i = m; i > n; --i)
typedef long long ll;
#define mod 1000000007

int main() {
  string a, b, c;
  cin >> a >> b >> c;
  int d = 'A' - 'a';
  a[0] += d, b[0] += d, c[0] += d;
  printf("%c%c%c\n",a[0],b[0],c[0]);
  return 0;
}


Measured memory_bytes: 256
#![allow(unused_imports)]
#![allow(non_snake_case)]
use std::cmp::*;
use std::collections::*;
use std::io::Write;

#[allow(unused_macros)]
macro_rules! debug {
    ($($e:expr),*) => {
        #[cfg(debug_assertions)]
        $({
            let (e, mut err) = (stringify!($e), std::io::stderr());
            writeln!(err, "{} = {:?}", e, $e).unwrap()
        })*
    };
}

fn main() {
    let v = read_vec::<usize>();
    let (a, b, c, d) = (v[0], v[1], v[2], v[3]);

    if a + b > c + d {
        println!("Left");
    } else if a + b == c + d {
        println!("Balanced");
    } else {
        println!("Right");
    }
}
fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}


Measured memory_bytes: 4352
#include<bits/stdc++.h>
#define maxn 400010
using namespace std;
char s[maxn];
int out[maxn][2], used[maxn], dl[maxn], head[maxn], nxt[maxn * 2], a[maxn * 2], edge;
void create(int u, int v)
{
	edge++; a[edge] = v; nxt[edge] = head[u]; head[u] = edge;
}
int main()
{
	int n, m;
	scanf("%d%d", &n, &m);
	scanf("%s", s + 1);
	for (int i = 1; i <= m; i++)
	{
		int u, v;
		scanf("%d%d", &u, &v);
		create(u, v); create(v, u);
		if (s[v] == 'A') out[u][0]++; else out[u][1]++;
		if (s[u] == 'A') out[v][0]++; else out[v][1]++;
	}
	int lef = 1, righ = 0;
	for (int i = 1; i <= n; i++)
		if (out[i][0] == 0 || out[i][1] == 0) {used[i] = 1; dl[++righ] = i;}
	while (lef <= righ)
	{
		int u = dl[lef];
		for (int i = head[u]; i; i = nxt[i])
		{
			int v = a[i];
			if (s[u] == 'A') out[v][0]--; else out[v][1]--;
			if (used[v] == 0 && (out[v][0] == 0 || out[v][1] == 0))
			{
				used[v] = 1;
				dl[++righ] = v;
			}
		}
		lef++;
	}
	for (int i = 1; i <= n; i++)
		if (used[i] == 0) {puts("Yes"); return 0;}
	puts("No");
	return 0;
}

Measured memory_bytes: 14080
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define countof(array) (sizeof(array) / sizeof(array[0]))
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,n,s) for(int i = s; i < (n); ++i)
#define rsrep(i,n,s) for(int i = (n)-1; i >= s; --i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define aall(a) (a), (a)+countof(a)//for array sorting
#define raall(a) (a), (a)+countof(a), greater<>()
#define show(x) cout<<#x<<" = "<<x<<endl;
#define vfind(v, a) find(all(v), a) != v.end()
#define yn(f) { if (f) puts("YES"); else puts("NO"); }
#define yns(f) { if (f) puts("Yes"); else puts("No"); }
#define show_ary(...) { cout<<#__VA_ARGS__<<" = "; for (const auto& x : (__VA_ARGS__)) { cout<<x<<" "; } cout<<endl; }
#define show_pair(...) cout<<#__VA_ARGS__<<" = "<<endl; for (const auto& x : (__VA_ARGS__)) { cout<<"  "<<x.fi<<" : "<<x.se<<endl; }
#define out_ary(...) { for (const auto& x : (__VA_ARGS__)) { cout<<x<<" "; } cout<<endl; }
#define argmax(v) distance((v).begin(), max_element(all(v)))
#define argmin(v) distance((v).begin(), min_element(all(v)))
#define vmax(v) *max_element(all(v))
#define vmin(v) *min_element(all(v))
typedef long long int ll;
typedef pair<int, int> P;
typedef vector<P> vpair;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<double> vdouble;
typedef vector<string> vstr;
typedef vector<bool> vbool;
typedef vector<vint> vvint;
typedef vector<vll> vvll;
typedef vector<vstr> vvstr;
typedef vector<vbool> vvbool;
const ll LINF = 2000000000000000000ll;
const int INF = 1000000100;
const ll MOD = 1e9+7;

int main() {
    int n, k;
    cin >> n >> k;
    vint x(n);
    int b = INF;
    int b_just = INF;
    rep(i, n) {
        cin >> x[i];
        if (x[i] == 0) b_just = i;
        if (i > 0) {
            if (x[i-1] < 0 && x[i] > 0) {
                b = i-1;
            }
        }
    }
    ll ans = INF;
    rep(i, n-(k-1)) {
        if (b_just != INF && (i > b_just || b_just > i+k-1)) continue;
        if (b != INF && (i > b || b+1 > i+k-1)) continue;
        ll dist = x[i+k-1] - x[i];
        if (b != INF) {
            dist += min(abs(x[i]), abs(x[i+k-1]));
        }
        if (b == INF && b_just == INF) {
            if (x[i] > 0) dist += x[i];
            else dist -= x[i+k-1];
        }
        ans = min(ans, dist);
    }

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

Measured memory_bytes: 768
X,Y,A,B,C = map(int,input().split())
p = list(map(int,input().split()))
q = list(map(int,input().split()))
r = list(map(int,input().split()))

p.sort(reverse=True)
q.sort(reverse=True)
r.sort(reverse=True)

a = [10**10]*(10**5)
a.extend(p[:X])
b = [10**10]*(10**5)
b.extend(q[:Y])
p_c = -1
q_c = -1
r_c = 0
k = 0

ans = sum(p[:X])+sum(q[:Y])
while(True):
    if a[p_c] >= b[q_c]:
        if b[q_c] < r[r_c] and q_c >= - Y:
            ans += ( r[r_c] - b[q_c] )
            r_c += 1
            q_c -= 1
        else:
            k = 1

    else:
        if a[p_c] < r[r_c]:
            ans += (r[r_c] - a[p_c])
            r_c += 1
            p_c -= 1
        else:
            k = 1

    if k == 1 or r_c >= C:
        break

print(ans)

Measured memory_bytes: 108268
q,h,s,d=map(int,input().split())
n=int(input())
if n==1:
    print(min([4*q,2*h,s]))
elif n%2==0:
    print(min([4*n*q,2*n*h,n*s,n//2*d]))
else:
    print(min([4*q,2*h,s])+min([4*(n-1)*q,2*(n-1)*h,(n-1)*s,(n-1)//2*d]))

Measured memory_bytes: 3064
#include <stdio.h>
#include <math.h>

#define SQ(x) (x)*(x)

int main(void){
    
    int i,j=0,l=0;
    int n;
    int judge;
    double xa,xb,ra,ya,yb,rb;
    double rc;
    
    scanf("%d",&n);
    for(i=0;i<n;i++){
        scanf("%lf %lf %lf %lf %lf %lf",&xa,&ya,&ra,&xb,&yb,&rb);
        rc=sqrt(SQ(xa-xb)+SQ(ya-yb));
        
        if(ra>rb+rc)judge=2;
        else if(rb>ra+rc)judge=-2;
        else if(rc<=ra+rb)judge=1;
        else judge=0;
        
        printf("%d\n",judge);
    }
    return(0);
}

Measured memory_bytes: 640
n = gets.to_i
$c = Array.new(n)
n.times{ |i| $c[i] = gets.split.map(&:to_i)[1..-1] }
$depth = Array.new(n)
$max = (Math.log(n) / Math.log(2)).ceil
$dp = Array.new(n){ Array.new($max) }
 
def bfs
  arr = []
  arr << [0,-1,0]
  until arr.empty?
    a,pre,dep = arr.shift
    $depth[a] = dep
    $dp[a][0] = pre
    (1...$max).each do |i|
      if $dp[a][i-1] != -1 then $dp[a][i] = $dp[$dp[a][i-1]][i-1]
      else $dp[a][i] = -1
      end
    end
    $c[a].each do |i|
      next if i == pre
      arr << [i, a, dep+1]
    end
  end
end
 
def lca(a, b)
  a, b = b, a if $depth[a] > $depth[b]
  dh = $depth[b] - $depth[a]
  i = 0
  while (1 << i) <= dh
    b = $dp[b][i] if (dh>>i) % 2 == 1
    i += 1
  end
  return a if a == b
  ($max-1).downto(0) do |i|
    if $dp[a][i] != $dp[b][i]
      a = $dp[a][i]; b = $dp[b][i] 
    end
  end
  $dp[a][0]
end
 
bfs
gets.to_i.times do
  a, b = gets.split.map(&:to_i)
  p lca a, b
end

Measured memory_bytes: 58328
#include <iostream>
#include <stdio.h>
#include <cstring>
using namespace std;
int a[100010]={0};

int judge(int i)
{
    int n;
    for(n=2;n<=i/2;n++) if(i%n==0) return 0;
    return 1;
}

void dabiao()
{
    int i;
    for(i=3;i<=100000;i+=2)
    {
        a[i]=a[i-2];
        if(judge(i)==1&&judge((i+1)/2)==1) a[i]++;
    }
}

int main()
{
    int i,j,n;
    scanf("%d",&n);
    dabiao();
    //for(i=1;i<=20;i++) printf("a[%d]=%d\n",i,a[i]);
    while(n--)
    {
        scanf("%d %d",&i,&j);
        printf("%d\n",a[j]-a[i-2]);
    }
    return 0;
}


Measured memory_bytes: 1024
//abc122_d.cpp
//Sat Jun 15 11:35:29 2019

#include <iostream>
#include <string>
#include <queue>
#include <map>
#include <unordered_map>
#include <vector>
#include <algorithm>
#include <math.h>
#include <set>
#define INTINF 2147483647
#define LLINF 9223372036854775807
using namespace std;
using ll=long long;
typedef pair<int,int> P;

int main(){
	int n;
	cin >> n;

	string dna[4];
	dna[0] = "A";
	dna[1] = "T";
	dna[2] = "G";
	dna[3] = "C";

	string triplet[64];
	unordered_map <string,int> dict;
	int count = 0;
	for (int i=0;i<4;i++){
		for (int j=0;j<4;j++){
			for (int k=0;k<4;k++){
				triplet[count] = dna[i]+dna[j]+dna[k];
				dict[triplet[count]] = count;
				count++;
			}
		}
	}

	ll dp[n+1][64];
	for (int i=0;i<64;i++){
		dp[0][i] = 1;
		dp[1][i] = 1;
		dp[2][i] = 1;
		if (triplet[i]!="AGC" && triplet[i]!="ACG" && triplet[i]!="GAC"){
			dp[3][i] = 1;
		}else{
			dp[3][i] = 0;
		}
	}

	for (int i=4;i<n+1;i++){
		for (int j=0;j<64;j++){
			dp[i][j]=0;
		}
		for (int j=0;j<64;j++){
			for (int k=0;k<4;k++){
				string newtriplet = triplet[j].substr(1,2)+dna[k];
				string twolet = triplet[j].substr(0,2)+dna[k];
				string anotwolet = triplet[j].substr(0,1)+triplet[j].substr(2,1)+dna[k];
				int flag = 0;
				if (newtriplet != "AGC" &&
					newtriplet != "ACG" &&
					newtriplet != "GAC" &&
					twolet != "AGC" &&
					anotwolet != "AGC"){
					dp[i][dict[newtriplet]] = (dp[i][dict[newtriplet]]+dp[i-1][j])%1000000007;
					flag = 1;
				}
				if (i==n){
//					cout << triplet[j] << " " << dp[i-1][j] << " " << dna[k] << " " <<newtriplet << " " << twolet << " " << anotwolet << " " << flag << endl;
				}
			}
		}
	}

	ll ans = 0;
	for (int i=0;i<64;i++){
		ans = (ans + dp[n][i])%1000000007;
//		cout << dp[n][i] << endl;
	}

	cout << ans << endl;
}

Measured memory_bytes: 256
// B - Simplified mahjong

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
// const int INF = 2147483647;
// const ll INF = 9223372036854775807;
// const ll MOD = 1e9 + 7;

ll A[100000];

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

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

	ll ans = A[0] / 2;
	A[0] -= (A[0] / 2) * 2;

	for (int i=1; i<N; i++) {
		ll p1 = min(A[i-1], A[i]);
		A[i] -= p1;

		ll p2 = A[i] / 2;
		A[i] -= p2 * 2;

		ans += p1 + p2;
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 4384
#include <vector>
#include <iostream>
#include <algorithm>

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

int main() {
	int x,hantei=0,a,b;
	cin >> x;

	if (x >= 2000) hantei = 1;
	else {
		a = x % 100;
		b = x / 100;
		if (b * 5 >= a) hantei = 1;
	}

	cout << hantei << endl;

	return 0;
}

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

int main() {
	int N;
	string S;
	cin >> N >> S;
	
	REP(i, S.size()) {
		int c = S[i] - 'A';
		S[i] = (c + N) % 26 + 'A';
	}
	cout << S << endl;
	
	return 0;
}


Measured memory_bytes: 256
c = [list(map(int,input().split())) for _ in range(3)]

a1 = 0
b1 = c[0][0]

a2 = c[1][0]-c[0][0]
a3 = c[2][0]-c[0][0]

b2 = c[0][1]
b3 = c[0][2]

A = [[a1,a1,a1],[a2,a2,a2],[a3,a3,a3]]
B = [[b1,b2,b3],[b1,b2,b3],[b1,b2,b3]]

C = c

ans = "Yes"

for x in range(3):
  for y in range(3):
    if A[x][y] + B[x][y] != C[x][y]:
      ans = "No"
      break
print(ans)

Measured memory_bytes: 9244
#include <iostream>

using namespace std;

int main() {
	int x, y;
	cin >> x >> y;
	if (x < y) {
		cout << "a < b" << endl;
	} else if (x == y) {
		cout << "a == b" << endl;
	} else if(x > y) {
		cout << "a > b" << endl;
	}
}


Measured memory_bytes: 3116
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N;
  cin >> N;
  vector<int> ans(N);
  int count=0;
  vector<int> vec={0};
  for(int i=0; i<N;i++){
    cin >> ans.at(i);
    count += ans.at(i);
  }
  for(int k=0; k<N;k++){
    int countA=0;
    int countB;
    for(int j=0;j<=k;j++){
      countA += ans.at(j);
    }
    countB = count - countA;
    if(countA-countB>=0){
      vec.push_back(countA-countB);
    }
    else{
      vec.push_back(countB-countA);
    }
  }
  sort(vec.begin(), vec.end());
  cout << vec.at(1) << endl;
}

Measured memory_bytes: 256