akhauriyash/Code-Regression huggingface dataset:
import heapq

def solve():
    N, T = tuple(map(int, input().split()))
    AS = tuple(map(int, input().split()))

    # print(N, T)
    # print(AS)

    lis = []
    D = {}

    m = -float('inf')
    c = 0
    for i in range(len(AS) - 1, -1, -1):
        x = AS[i]
        heapq.heappush(lis, -x)
        D[i] = -lis[0]

    for i in range(len(AS)):
        x = AS[i]

        d = D[i] - AS[i]
        if d > 0:
            if m < d:
                m = d
                c = 1
            elif m == d:  # max と同じ値なら counter を ++
                c += 1

    return c


if __name__ == '__main__':
    res = solve()
    print(res)


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

using namespace std;

int main(){
    int a;
    vector<pair<int, int> > As(5);
    for(int i = 0; i < 5; i++){
        cin >> a;
        int mod = a%10;
        if(a%10 == 0){
            mod = 10;
        }
        As[i] = make_pair(mod, a);
    }
    
    sort(As.begin(), As.end());
    int ans = 0;
    for(int i = 4; i >= 0; i--){
        if(i == 0){
            ans += As[i].second;
        }else{
            ans += As[i].second;
            if(As[i].second%10 != 0)
                ans += (10 - As[i].second%10);
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
n, m, x = map(int, input().split())
a = list(map(int, input().split()))
backward = 0
forward = 0

for i in range(x):
    if i in a:
        backward += 1

for i in range(x, n + 1):
    if i in a:
        forward += 1

print(min(forward, backward))


Measured memory_bytes: 3060
slist = list(input())
n=len(slist)

i = 0

while slist[i]==slist[int(n/2 - 3/2 - i)] and i < n/2-3/2:
  i += 1

if i < n/2 - 3/2:
  print("No")
else:
  if slist[0: int(n/2-1/2)] == slist[int(n/2+1/2):n]:
    print("Yes")
  else:
    print("No")

Measured memory_bytes: 3060
#include <stdio.h>
#include <algorithm>
#include <assert.h>
#include <bitset>
#include <cmath>
#include <complex>
#include <deque>
#include <functional>
#include <iostream>
#include <limits.h>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <time.h>
#include <unordered_map>
#include <unordered_set>
#include <vector>

#pragma warning(disable:4996)
#pragma comment(linker, "/STACK:336777216")
using namespace std;

#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define ldb ldouble

typedef tuple<int, int, int> t3;
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ldb;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef pair <ll, int> pli;
typedef pair <db, db> pdd;

int IT_MAX = 1 << 19;
int MOD = 1000000007;
const int INF = 0x3f3f3f3f;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
const db PI = acos(-1);
const db ERR = 1e-10;
#define szz(x) (int)(x).size()
#define rep(i, n) for(int i=0;i<n;i++)
#define Se second
#define Fi first

const int MX = 5005;
const int MM = 1000000007;

int D[MX];

vector<pii> O;

void OP(int x, int y){
	D[y] += D[x];
	O.emplace_back(x, y);
}

int main()
{
	int N;
	scanf("%d", &N);
	for(int i = 1; i <= N; i++) scanf("%d", D+i);
	int mx = 1, mn = 1;

	for(int i = 1; i <= N; i++){
		if( D[i] < D[mn] ) mn = i;
		if( D[i] > D[mx] ) mx = i;
	}
	if( D[mx] > -D[mn] ){
		for(int i = 1; i <= N; i++){
			if( i != mx ) OP(mx, i);
		}
		for(int i = 1; i < N; i++) OP(i, i+1);
	}
	else{
		for(int i = 1; i <= N; i++){
			if( i != mn ) OP(mn, i);
		}
		for(int i = N; i >= 2; i--) OP(i, i-1);
	}
//	for(int i = 1; i <= N; i++) printf("%d ", D[i]); printf("\n");
	printf("%d\n", O.size());
	for(pii c : O) printf("%d %d\n", c.first, c.second);
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define MOD 1000000007LL
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

int n,k;

int main(void){
	scanf("%d%d",&n,&k);
	ll ans=0;
	ll ls=0;
	ll rs=0;
	for(int i=0;i<k;i++){
		ls+=i;
		rs+=n-i;
	}
	for(int i=k;i<=n+1;i++){
		ans+=rs-ls+1LL;
		ans%=MOD;
		rs+=n-i;
		ls+=i;
	}
	printf("%lld\n",ans);
	return 0;
}


Measured memory_bytes: 3868
#include<bits/stdc++.h>
#define ll long long
using namespace std;
ll a[200005];
int main()
{
	int n,t=0,ans1=0,ans2=0;ll ans=0;
	scanf("%d",&n);
	for(int i=1;i<=n;i++)scanf("%lld",&a[i]);
	for(int i=1;i<=n;i++)
	{
		if(t>=i)
			ans+=t-i+1;
		for(int j=t+1;j<=n;j++)
		{
			ans1^=a[j],ans2+=a[j];
			if(ans1==ans2)
			{
				ans++;
				t=max(t,j);
			}else
			{
				ans1^=a[j];
				ans2-=a[j];
				break;
			}
		}
		ans1^=a[i];
		ans2-=a[i];
	}
	cout<<ans<<endl;
	return 0;
}

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

#define ll long long
#define pb push_back
#define mp make_pair
#define fr first
#define sc second
#define pii pair<int,int>
#define pll pair<ll,ll>
#define SPEED ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define sz size()
#define all(x) x.begin(),x.end()
#define OO 1e18
#define iOO INT_MAX
#define Mdp memset(dp,-1,sizeof dp)
#define R return
#define Test int TT;cin>>TT;for(int T=1;T<=TT;T++)
using namespace std;
int n,a[3001];
ll dp[3001][3001][3];


ll Solve(int i=0,int j=n-1,int Turn = 1)
{
    if(i > j)
        R 0;
    ll &Res = dp[i][j][Turn];
    if(Res != -1)
        R Res;

    Res = 0;
    if(Turn)
    {
        Res = Solve(i+1,j,1-Turn)+a[i];
        Res = max(Res,Solve(i,j-1,1-Turn)+a[j]);
    }
    else
    {
        Res = Solve(i+1,j,1-Turn)-a[i];
        Res = min(Res,Solve(i,j-1,1-Turn)-a[j]);
    }

    R Res;
}

int main()
{

    SPEED;
    cin >> n;
    for(int i=0;i<n;i++)
    {
        cin >> a[i];
    }

    Mdp;

    cout << Solve()  << endl;

    R 0;
}


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

#define int long long
#define ll long long
#define pb push_back
#define mp make_pair
#define f(i,a,n) for(int i=a ; i<(int)n ; i++)
#define rf(i,n,a) for(int i=n ; i>=a ; i--)
#define F first
#define S second
#define all(c) (c).begin(),(c).end()
#define sz(v) (int)(v).size()
#define fast ios:: sync_with_stdio(false),cin.tie(nullptr);

typedef long double ld;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef pair<pii,int> ppi;
typedef vector<pii> vpi;

const int inf = 1e9;
const int inf64 = 1e18;
const int MOD = inf + 7;

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

   int cur = 100;
   int cnt = 0 ; 
   while(cur < n) {
      cnt++;
      cur = cur + (cur)/100;
   }
   cout << cnt;
}

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

typedef long lint;
typedef long long llint;

// static const int MAX = 1e6;
// static const int NIL = -1;
// static const ll INF = 1<<21;
// static const ll MOD = 1e9 + 7;

bool compPair(const pair<int, int>& arg1, const pair<int, int>& arg2) { return arg1.first > arg2.first; }
template<class T> void chmax(T& a, T b) { if (a < b) { a = b; } }
template<class T> void chmin(T& a, T b) { if (a > b) { a = b; } }


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

    for(int i3=0;i3<3;i3++) {
        if(s.at(i3)=='1') cout << 9;
        else if(s.at(i3)=='9') cout << 1;
        else cout << s.at(i3);
    }

    return 0;
}


Measured memory_bytes: 256
// clang-format off
#include <bits/stdc++.h>
#define int long long
#define main signed main()
// #define main int main()
#define loop(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) loop(i, 0, n)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define prec(n) fixed << setprecision(n)
#define stlice(from, to) substr(from, (to) - (from) + 1)
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
using namespace std;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<string> vs;
typedef vector<pii> vpii;
typedef vector<vi> vvi;
typedef vector<vb> vvb;
typedef vector<vpii> vvpii;
const int INF = sizeof(int) == sizeof(long long) ? 1000000000000000000LL : 1000000000;
const int MOD = 1000000007;
const double PI = acos(-1);
template<typename A, typename B> bool cmin(A &a, const B &b) { return a > b ? (a = b, true) : false; }
template<typename A, typename B> bool cmax(A &a, const B &b) { return a < b ? (a = b, true) : false; }
bool odd(const int &n) { return n & 1; }
bool even(const int &n) { return !odd(n); }
void solve();
main { solve(); return 0; }
// clang-format on

vector<int> eratosthenes(const int &n) {
  vector<int> v(n);
  v[0] = v[1] = false;
  loop(i, 2, v.size()) v[i] = true;
  for (int i = 2; i * i < n; i++) {
    if (v[i]) {
      for (int j = i * 2; j < n; j += i) {
        v[j] = false;
      }
    }
  }
  return v;
}

void solve() {
  vi v = eratosthenes(1000000);
  int n;
  while (cin >> n, n) {
    int s = 0, i = 0;
    while (n--) {
      while (!v[i]) i++;
      s += i++;
    }
    cout << s << endl;
  }
}

Measured memory_bytes: 10588
input = gets.chomp.split.map(&:to_i)

betwen = input[1] - input[0]
count = 0
hako = []
(betwen+1).times do |i|
    sum = input[0] + i
    hako = sum.to_s.split(//)
    if hako == hako.reverse
        count += 1
    end
end

p count

Measured memory_bytes: 1916
object Main {
  def main(args: Array[String]): Unit = {
    solve
  }

  def solve(): Unit = {
    val sc = new java.util.Scanner(System.in)
    val n, k = sc.nextInt
    val h = new Array[Int](n)
    for (i <- 0 until n) {
      h(i) = sc.nextInt
    }

    // hiまでにかかるコスト
    val dp = Array.fill[Int](n)(Int.MaxValue)
    dp(0) = 0
    for (i <- 0 until n) {
      for (j <- 1 to k) {
        if (i + j < n) {
          dp(i + j) = math.min(dp(i + j), dp(i) + (h(i) - h(i + j)).abs)
        }
      }
    }
    println(dp(n - 1))
  }
}


Measured memory_bytes: 54180
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
#define all(x) (x).begin(),(x).end()
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define REP(i, m, n) for(int i = m; i < n; i++)
#define INF INT_MAX
#define MOD 1000000007
#define fcout cout << fixed << setprecision(15)
typedef long long ll;
typedef pair<int, int> P;
int gcd(int a,int b){return b?gcd(b,a%b):a;};
int lcm(int a,int b){return a * b / gcd(a, b);};
int mod(int a,int b){return (a+b-1)/b;};
int month[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
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;};



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

  int n;
  string s;
  cin >> n >> s;
  int res = 0;
  REP(i, 1, n) {
    if(s[i] != s[i - 1]) res++;
  }
  cout << res + 1 << endl;
  return 0;
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
#define ALL(obj) (obj).begin(),(obj).end()
#define RALL(obj) (obj).rbegin(),(obj).rend()
#define REP(i, n) for(int i=0;i<(n);++i)
#define RANGE(i, a, b) for(int i=(a);i<(b);++i)
#define RREP(i, n) for(int i=(n)-1;i>= 0;--i)

#define endl '\n'
#define pb push_back
#define eb emplace_back
#define pque priority_queue
#define umap unordered_map
#define uset unordered_set
#define BIG 2000000000
#define VERYBIG 1000000000000000ll
#define PI 3.141592653589793238
#define dcout cout<<fixed<<setprecision(50)
#define _popcnt __builtin_popcount

const long long dx[]={1,0,-1,0,1,1,-1,-1}, dy[]={0,-1,0,1,1,-1,1,-1};
const long long MOD = 1e9+7;

// typedef long long ll;
#define int long long
#define double long double

template<typename T> inline T GCD(T a,T b){T c;while(b!=0){c=a%b;a=b;b=c;}return a;}
template<typename T> inline T LCM(T a,T b){T c=GCD(a,b);a/=c;return a*b;}
template<typename T> inline T nCr(T a,T b){T i,r=1;for(i=1;i<=b;i++){r*=(a+1-i);r/=i;}return r;}
template<typename T> inline T nHr(T a,T b){return nCr(a+b-1,b);}
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;}

typedef pair<int, int> INTP;
typedef vector<int> INTV;
struct edge2 {int to, cost;};
struct edge3 {int from, to, cost;};

int dp[110][2][110];

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

  string N; int K; cin >> N >> K;
  dp[0][0][0] = 1;
  REP(i, N.size()) REP(smaller, 2) REP(k, N.size()){
    int d = N[i]-'0';
    REP(nxt, 10){
      if(nxt < d)
        dp[i+1][1][(nxt!=0)+k] += dp[i][smaller][k];
      else if(nxt == d)
        dp[i+1][smaller][(nxt!=0)+k] += dp[i][smaller][k];
      else
        if(smaller) dp[i+1][smaller][(nxt!=0)+k] += dp[i][smaller][k];
    }
  }
  cout << dp[N.size()][0][K] + dp[N.size()][1][K] << endl;
}

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

ll gcd(ll x, ll y) {
    if(x < y) swap(x, y);
    ll r;
    while(y > 0) {
        r = x % y;
        x = y;
        y = r;
    }
    return x;
}

ll lcm(ll x, ll y) {
    return ll(x / gcd(x, y)) * y;
}

int main() {
    ll A, B;
    cin >> A >> B;
    cout << (ll)lcm(A, B) << endl;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define FOR(i,a,n) for(int i=(a); i<(n); i++)
#define all(v) v.begin(), v.end()
#define fi first
#define se second
#define sz(x) int(x.size())
using namespace std;
// #include <atcoder/all>
// using namespace atcoder;
using ll = long long;
using P = pair<int ,int>;
const int INF = 1001001001;
const int MOD = 1000000007;
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 (b<a) {a=b; return 1;} return 0;}

#ifdef _DEBUG
#include "debug.h"
#else
#define debug(...)
#define print(...)
#endif

struct UnionFind {
	vector<int> data;

	UnionFind(int sz) {
		data.assign(sz, -1);
	}

	void unite(int x, int y) {
		x = find(x), y = find(y);
		if (x == y) return;
		if (data[x] > data[y]) swap(x, y);
		data[x] += data[y];
		data[y] = x;
	}

	int find(int k) {
		if(data[k] < 0) return(k);
		return data[k] = find(data[k]);
	}

	bool same(int x, int y)	{
		return find(x) == find(y);
	}

	int size(int k)	{
		return -data[find(k)];
	}
};

int main() {
    int n, m; cin >> n >> m;
    UnionFind uf(n);
    rep(i, m) {
        int a, b; cin >> a >> b;
        a--; b--;
        uf.unite(a, b);
    }
    int ans = 0;
    FOR(i, 1, n) {
        if (!uf.same(0, i)) {
            uf.unite(0, i);
            ans++;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 3792
L, R = map(int, input().split())
MOD = 10 ** 9 + 7
l = '{:060b}'.format(L)[::-1]
r = '{:060b}'.format(R)[::-1]
 
memo = [[[[-1 for l in range(2)] for k in range(2)] for j in range(2)] for i in range(60)]
 
def f(pos, flagX, flagY, flagZ):
    if pos == -1:
        return 1
    if memo[pos][flagX][flagY][flagZ] != -1:
        return memo[pos][flagX][flagY][flagZ]
    ret = 0
    # x 0, y 0
    if flagX or l[pos] == '0':
        ret += f(pos - 1, flagX, 1 if r[pos] == '1' else flagY, flagZ)
    # x 0, y 1
    if (flagX or l[pos] == '0') and (flagY or r[pos] == '1') and flagZ:
        ret += f(pos - 1, flagX, flagY, flagZ)
    # x 1, y 1
    if flagY or r[pos] == '1':
        ret += f(pos - 1, 1 if l[pos] == '0' else flagX, flagY, 1)
    ret %= MOD
    memo[pos][flagX][flagY][flagZ] = ret
    return ret
 
ans = f(59, 0, 0, 0)
print(ans)

Measured memory_bytes: 3064
import java.util.Scanner;
 
public class Main {
 
	public static void main(String[] args) {
 
		Scanner sc = new Scanner(System.in);
 
		String s1 = sc.next();
		String s2 = new StringBuffer(sc.next()).reverse().toString();
 
		System.out.println(s1.equals(s2) ? "YES" : "NO");
	}
}

Measured memory_bytes: 35592
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 7;
typedef long long ll;
char mp[10][10];
int main()
{
    int n, m, k;
    cin >> n>> m >> k;
    for (int i = 1; i <= n; i++) {
        cin >> mp[i] + 1;
    }
    int ans = 0;
    for (int x = 0; x < (1<<n) - 1; x++) {
        for (int y = 0; y < (1<<m) - 1; y++) {
            int cnt = 0;
            for (int i = 1; i <= n; i++) {
                if((((x>>(i - 1))&1))) continue;
                for (int j = 1; j <= m; j++) {
                    if((((y>>(j - 1))&1))) continue;
                    if(mp[i][j] == '#') cnt++;
                }
            }
            if(cnt == k) ans++;
        }
    }
    printf("%d\n", ans);
}


Measured memory_bytes: 3760
import sys
input = sys.stdin.readline
N = int(input())
t = [0] * N
x = [0] * N
y = [0] * N
for i in range(N):
    t[i],x[i],y[i] = [int(i) for i in input().split()]
t.insert(0,0)
x.insert(0,0)
y.insert(0,0)
for i in range(1,N+1):
    dt = t[i]-t[i-1]
    dx = abs(x[i]-x[i-1])
    dy = abs(y[i]- y[i-1])
    dl = dx + dy
    if dl > dt:
        print("No")
        exit()
    else :
        if (dt % 2) != (dl % 2):
            print("No")
            exit()
print("Yes")

Measured memory_bytes: 11636
var
  n,i,sum:longint;
  x,y:char;
begin
  readln(n);
  read(x);
  y:=x;
  sum:=1;
for i:=2 to n do
  begin
    read(x);
  if x<>y then inc(sum);
    y:=x;
  end;
  write(sum);
end.

Measured memory_bytes: 128
import scala.io.StdIn._

object Helpers {
  def readIntLine = readLine.split(" ").map(_.toInt)
  def readInts(n: Int) = Array.fill(n)(readInt)

  def splitDigits(i: Int): Seq[Int] = i.toString.map(_.asDigit)

  def log[A](x: A): A = {println(x); x}

  implicit class IntImplicits(val i: Int) {
    def isEven = i % 2 == 0
    def isOdd = !isEven

    def ** (exp: Int): Int = scala.math.pow(i, exp).intValue
  }

  implicit class LongImplicits(val i: Long) {
    def isEven = i % 2 == 0
    def isOdd = !isEven

    def ** (exp: Long): Long = scala.math.pow(i, exp).longValue
  }

  def mycomb[T](n: Int, l: List[T]): List[List[T]] =
    n match {
      case 0 => List(List())
      case _ => for(el <- l;
                sl <- mycomb(n-1, l dropWhile { _ != el } ))
                yield el :: sl
  }
  
  def comb[T](n: Int, l: List[T]): List[List[T]] = mycomb(n, l.distinct)
}

object Main extends App {
  import Helpers._

  val Array(a, b, c, d) = readIntLine

  println(if (scala.math.ceil(c.toDouble/b) <= scala.math.ceil(a.toDouble/d)) "Yes" else "No")
}



Measured memory_bytes: 54744
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define pb push_back
const ll maxn=100005;
vector <ll> adj[maxn];
bool mark[maxn];
void dfs(ll x)
{
	mark[x]=true;
	for (ll y:adj[x])
	{
		if (!mark[y])
		{
			dfs(y);
		}
	}
}
int main()
{
	ios_base::sync_with_stdio(false);
	ll q,h,s,d,n; cin>>q>>h>>s>>d; cin>>n;
	s=min(4*q,min(h*2,min(2*q+h,s)));
	cout<< min(n*s,(n/2)*d+(n%2)*s);
}

Measured memory_bytes: 2560
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);

		long mod = 1000000007L;

		int n = sc.nextInt();

		long x0x9 = 0;
		long x0o9 = 0;
		long o0x9 = 0;
		long o0o9 = 0;

		for ( int i=1; i<=n; i++ ) {

			if ( i==1 ) {
				x0x9 = 8;
				x0o9 = 1;
				o0x9 = 1;
				continue;
			}

			long pre_x0x9 = x0x9;
			long pre_x0o9 = x0o9;
			long pre_o0x9 = o0x9;
			long pre_o0o9 = o0o9;

			long wk_x0o9 = 0;
			long wk_o0x9 = 0;
			long wk_o0o9 = 0;

			x0x9 = (pre_x0x9*8)%mod;
			x0o9 = (pre_x0x9 + pre_x0o9*9)%mod;
			o0x9 = (pre_x0x9 + pre_o0x9*9)%mod;
			o0o9 = (pre_x0o9 + pre_o0x9 + pre_o0o9*10)%mod;

		}

		System.out.println(o0o9);
	}
}

Measured memory_bytes: 35844
#include<bits/stdc++.h>
#define pb push_back
#define all(x) x.begin(), x.end()
using namespace std;
using ll = long long;
using vi = vector<ll>;
const int maxn = 1<<20, mod = 924844033;
ll n, a[maxn], x;
int main() {
	cin.tie(0)->sync_with_stdio(0);
	cin >> n >> x;
	for(int i = 1; i <= n; i++) cin >> a[i];
	for(int i = 1; i <= n; i++) a[i+n] = a[i];
	ll ans = 1ll<<60;
	for(int d = 0; d < n; d++) {
		ll tans = x*d;
		multiset<ll> u;
		for(int i = 1; i <= 2*n; i++) {
			u.insert(a[i]);
			if(i-d-1 > 0) u.erase(u.find(a[i-d-1]));
			if(i > n) {
				tans += *u.begin();
			}
		}
		ans = min(ans, tans);
	}
	cout << ans;
}


Measured memory_bytes: 384
n = int(input())
h = list(map(int, input().split()))

a = [10**10] * n

a[0] = 0
for i in range(0,n):
    for x in range(1,3):
        j = i+x
        if j >= n:
            continue
        a[j] = min(a[j], a[i] + abs(h[i] - h[j]))

print(a[n-1])


Measured memory_bytes: 20516
n = int(input())
a = list(map(int,input().split()))
count4 = 0
count2 = 0
countelse = 0
for i in range(n):
	if a[i] % 4 == 0:
		count4 += 1
	if a[i] % 2 == 0:
		count2 += 1
	else:
		countelse += 1
count2 = count2 - count4
if n % 2 != 0:
	if count4 < (countelse - 1):
		print('No')
	else:
		print('Yes')
else:
	if count4 < countelse:
		print('No')
	else:
		print('Yes')

Measured memory_bytes: 14224
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);

        int[] pos = new int[5];

        int max = Integer.MIN_VALUE;
        int min = Integer.MAX_VALUE;

        for(int i=0; i<5; i++){
            int tmp = scanner.nextInt();
            max = Math.max(max, tmp);
            min = Math.min(min, tmp);
        }

        int k = scanner.nextInt();

        if(max - min > k){
            System.out.println(":(");
        }else {
            System.out.println("Yay!");
        }
    }
}


Measured memory_bytes: 21716
use std::io::*;
use std::str::*;

fn read<T: FromStr>(s: &mut StdinLock) -> Option<T> {
    let s = s.by_ref().bytes().map(|c| c.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect::<String>();
    s.parse::<T>().ok()
}

fn main() {
    let s = stdin();
    let mut s = s.lock();
    let s = &mut s;

    let n = read::<usize>(s).unwrap();
	let mut hh = Vec::<usize>::with_capacity(n);
	for _ in 0..n {
		hh.push(read::<usize>(s).unwrap());
	}

 
	let mut h :usize = hh[0];
	let mut th : usize = 0;
	for i in 1.. n {
		if h > hh[i] {
			th += h - hh[i];
		}
		else {
			h = hh[i];
		}
	}


	println!("{}", th);
}


Measured memory_bytes: 3556
from itertools import combinations as comb
n = int(input())
d = {'M':0,'A':0,'R':0,'C':0,'H':0}
for i in range(n):
  try:
    d[input()[0]] += 1
  except:
    continue
c = 0
l = d.values()
for i,j,k in comb(l,3):
  c += i*j*k
print(c)

Measured memory_bytes: 3060
H, W = map(int, input().split())

if ((H != 1) and (W != 1)):
    if W % 2 == 1:
        if H % 2 == 0:
            print((W) * int(H/2))
        else:
            print((W) * int((H-1)/2) + int((W + 1)/2))
    else:
        print(int(W/2) * H)
else:
    print(1)

Measured memory_bytes: 3060
#include <iostream>

int main(){
  int n;
  std::cin>>n;
  if(n<4)std::cout<<"No"<<std::endl;
  else{
    int n_ = n % 4;
    while(n_ < n){
      if(n_ % 7 == 0){
        std::cout<<"Yes"<<std::endl;
        return 0;
      }else{
        n_ += 4;
      }
    }
    int n2=n%7;
    while(n2 < n){
      if(n2 % 4 == 0){
        std::cout<<"Yes"<<std::endl;
        return 0;
      }else{
        n2 += 7;
      }
    }
    std::cout<<"No"<<std::endl;
  }
}


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

int main() {
  int a,b,c;
  vector<int> x(10);
  cin>>a>>b>>c;
  x[a]++, x[b]++, x[c]++;
  if (x[5]==2&&x[7]==1) cout<<"YES"<<endl;
  else cout<<"NO"<<endl;
}


Measured memory_bytes: 256
#include <stdio.h>

int main()
{
	int i, N;
	long long T[1001], A[1001];
	scanf("%d", &N);
	for (i = 1; i <= N; i++) scanf("%lld %lld", &(T[i]), &(A[i]));
	
	long long g[2];
	for (i = 2, T[0] = T[1], A[0] = A[1]; i <= N; i++) {
		g[0] = (T[0] - 1) / T[i] + 1;
		g[1] = (A[0] - 1) / A[i] + 1;
		if (g[0] > g[1]) {
			T[0] = T[i] * g[0];
			A[0] = A[i] * g[0];
		} else {
			T[0] = T[i] * g[1];
			A[0] = A[i] * g[1];
		}
	}
	
	printf("%lld\n", T[0] + A[0]);
	fflush(stdout);
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < n; ++i)
#define ll long long
#define P pair<int,int>
#define fast_io ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
const int MOD = 1000000007;
const int INF = 2002002002;
const ll LLINF = 9009009009009009009;
using namespace std;

int main() {
    fast_io
    string s;
    cin >> s;
    cout << s[0] << s[1] << s[2] << endl;
    return 0;
}

Measured memory_bytes: 3588
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define printVec(v) printf("{"); for (const auto& i : v) { std::cout << i << ", "; } printf("}\n");
#define degreeToRadian(deg) (((deg)/360)*2*M_PI)
#define radianTodegree(rad) (((rad)/2/M_PI)*360)
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; }
using namespace std;
using P = pair<int,int>;
using ll = long long;
const ll INF = 1LL<<60;
const int MOD = 1e9 + 7;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

//cin.tie(0);ios::sync_with_stdio(false);
//cout << fixed << setprecision(15) << y << endl;
int main() {
  ll n, a, b;
  cin >> n >> a >> b;
  ll ans = n / (a + b) * a;
  if (a > 0) {
    ans += min(n % (a + b), a);
  }

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


Measured memory_bytes: 3572
#include<bits/stdc++.h>
#define REP(i, n) for (int i=0; i<n; ++i)
#define print(x) cout << x << endl;
typedef long long ll;

using namespace std;

void solve() {
    ll N, K;
    cin >> N >> K;
    vector<pair<ll, ll> > data(N);
    REP(i, N) {
        ll a, b;
        cin >> a >> b;
        data[i].first = a;
        data[i].second = b;
    }
    sort(data.begin(), data.end());
    vector<ll> v(N);
    ll cnt = 0;
    REP(i, N) {
        cnt += data[i].second;
        v[i] = cnt;
    }
    ll index = distance(v.begin(), lower_bound(v.begin(), v.end(), K));
    print(data[index].first);
}

int main() {

    solve();
    return 0;
}


Measured memory_bytes: 2560
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int i,j,k,a,b,c;
  cin >> a >> b >> c;
  cin >> k;
  j=0;
  while(b<=a)
  {
  	b*=2;
    j++;
  }
  while(c<=b)
  {
    c*=2;
    j++;
  }
  if(j<=k)
  cout << "Yes" << endl;
  else
    cout << "No" << endl;
}
  

Measured memory_bytes: 3536
#include <bits/stdc++.h>
typedef long long ll;

using namespace std;
ll gcd(ll a,ll b){ return b==0?a:gcd(b,a%b); }
ll lcm(ll a,ll b){ return a*b/gcd(a,b);}

int main(){
	ll a,b;
	cin>>a>>b;
	
	if(a>b) swap(a,b);
	cout<<lcm(a,b)<<endl; 
	return 0;
} 

Measured memory_bytes: 256
def wantp(n):

    Q = []

    while True:

        if lis[n] == n:
            ans = n
            break

        else:
            Q.append(n)
            n = lis[n]

    for i in Q:
        lis[i] = ans

    return ans



N,M = map(int,input().split())

p = list(map(int,input().split()))


lis = [0] * (2 * N + 1)

rank = [0] * (2 * N + 1)

for i in range(2 * N + 1):

    i -= N

    lis[i] = i

for i in range(N):

    lis[-p[i]] = i + 1
    rank[i + 1] = 1

for i in range(M):

    x,y = map(int,input().split())

    if x > M and y > M:
        continue;

    xp = wantp(x)
    yp = wantp(y)

    if rank[xp] > rank[yp]:

        lis[yp] = lis[xp]

    elif rank[xp] < rank[yp]:

        lis[xp] = lis[yp]

    else:

        lis[yp] = lis[xp]
        rank[xp] += 1

answer = 0

for i in range(N):

    i += 1
    if wantp(i) == wantp(-i):
        answer += 1

print (answer)


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

using namespace std;

int main()
{
    while ( true )
    {
        int n, a, s, g;
        cin >> n >> a >> s >> g;
        if ( n == 0  &&  a == 0  &&  s == 0  &&  g == 0 )
            break;

        vector<int> x( a );
        vector<int> y( a );
        vector<string> lab( a );
        for ( int i=0; i<a; i++ )
            cin >> x[i] >> y[i] >> lab[i];

        int     N = 6*(n-1);    //  ツδ仰ーツプツつオツづ按つ「ツ偲エツ閉カツづ個催妥・ツ陳キ
        string  inf( N, 'z' );  //  "zzzzzz..."

        vector<vector<string> > spell( n, vector<string>( 2*N+1, inf ) );
        spell[s][0] = "";

        for ( int l=0; l<2*N; l++ )
        for ( int i=0; i<n; i++ )
        if ( spell[i][l] != inf )
        {
            for ( int j=0; j<a; j++ )
            if ( x[j] == i )
            {
                string sp = spell[i][l] + lab[j];
                int len = (int)sp.length();

                if ( len <= 2*N )
                    spell[y[j]][len] = min( spell[y[j]][len], sp );
            }
        }

        string ans = *min_element( spell[g].begin(), spell[g].end() );

        if ( ans != inf  &&
             (int)ans.length() <= N )
            cout << ans << endl;
        else
            cout << "NO" << endl;
    }
}

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

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

int n; ll k; 
vector<ll> a;
vector<ll> f;

bool OK(ll key)
{
    ll _k = k;
    for (int i = 0; i < n; i++) {
        ll t = a[i] * f[i];
        if (t > key) _k -= (t - key + f[i] - 1) / f[i];
    }
    return _k >= 0;
}

int main()
{
    cin >> n >> k;
    a.resize(n), f.resize(n);
    for (int i = 0; i < n; i++) cin >> a[i];
    for (int i = 0; i < n; i++) cin >> f[i];
    
    sort(a.begin(), a.end());
    sort(f.begin(), f.end(), greater<int>());

    ll maxx = 0;
    for (int i = 0; i < n; i++) maxx = max(maxx, a[i] * f[i]);

    ll left = -1, right = maxx;
    while (right - left > 1) {
        ll mid = (left + right) / 2;
        if (OK(mid)) right = mid;
        else left = mid;
    }

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

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

int main() {
  int n;
  cin >> n;
  vector<P> a(n);
  rep(i, n) {
    cin >> a[i].first;
    a[i].second = i + 1;
  }
  sort(a.begin(), a.end());
  rep(i, n) cout << a[i].second << endl;
  return 0;
}

Measured memory_bytes: 1664
import java.io.*;
import java.util.Arrays;
import java.util.StringTokenizer;

public class Main {

    public static void main(String[] args) throws IOException {
        init();
        int n = nextInt();
        int[] a = new int[n];
        for (int i = 0; i < a.length; i++) a[i] = nextInt();

        long possibilities = 1;
        int[] colors = new int[3];

        for (int i = 0; i < a.length; i++) {
            int finalI = i;
            int numColors = (int) Arrays.stream(colors).filter(num -> num == a[finalI]).count();
            possibilities = (possibilities * numColors) % 1000000007;
            for (int j = 0; j < colors.length; j++) {
                if (colors[j] == a[i]) {
                    colors[j]++;
                    break;
                }
            }
        }

        System.out.println(possibilities);
    }

    //Input Reader
    private static BufferedReader reader;
    private static StringTokenizer tokenizer;

    private static void init() {
        reader = new BufferedReader(new InputStreamReader(System.in));
        tokenizer = new StringTokenizer("");
    }

    private static String next() throws IOException {
        String read;
        while (!tokenizer.hasMoreTokens()) {
            read = reader.readLine();
            if (read == null || read.equals(""))
                return "-1";
            tokenizer = new StringTokenizer(read);
        }

        return tokenizer.nextToken();
    }

    private static int nextInt() throws IOException {
        return Integer.parseInt(next());
    }
}


Measured memory_bytes: 47676
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> P;
typedef pair<int,int> Pi;
#define rep(i,n) for(ll i=0;i<n;i++)
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define fi first
#define se second
#define endl "\n"

template<typename T> inline bool chmax(T &a, T b){if(a<b){a=b;return true;}return false;}
template<typename T> inline bool chmin(T &a, T b){if(a>b){a=b;return true;}return false;}
template<typename T> ostream& operator<<(ostream& s,const complex<T>& d) {return s<<"("<<d.real()<<", "<<d.imag()<< ")";}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const pair<T1,T2>& d) {return s<<"("<<d.first<<", "<<d.second<<")";}
template<typename T> ostream& operator<<(ostream& s, const vector<T>& d){int len=d.size();rep(i,len){s<<d[i];if(i<len-1) s<<" ";}return s;}
template<typename T> ostream& operator<<(ostream& s,const vector<vector<T>>& d){int len=d.size();rep(i,len){s<<d[i]<<endl;}return s;}
template<typename T> ostream& operator<<(ostream& s,const set<T>& v){s<<"{ ";for(auto itr=v.begin();itr!=v.end();++itr) {if (itr!=v.begin()) {s<< ", ";}s<<(*itr);}s<<" }";return s;}
template<typename T> ostream& operator<<(ostream& s,const multiset<T>& v){s<<"{ ";for(auto itr=v.begin();itr!=v.end();++itr) {if (itr!=v.begin()) {s<< ", ";}s<<(*itr);}s<<" }";return s;}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const map<T1,T2>& m){s<<"{"<<endl;for(auto itr=m.begin();itr!=m.end();++itr){s<<" "<<(*itr).first<<" : "<<(*itr).second<<endl;}s<<"}"<<endl;return s;}

const ll mod=1e9+7;
const ll inf=1e17;
const int INF=1e9;
const double EPS=1e-10;
const double PI=acos(-1);

int main(){
	cin.tie(0);ios::sync_with_stdio(false);
	ll n;
	cin>>n;
    ll ma=1000010;
	vector<ll> a(n),cnt(ma,0);
	rep(i,n){
		cin>>a[i];
	}
    sort(begin(a),end(a));
	rep(i,n){
        if(cnt[a[i]]){
            cnt[a[i]]=2;
            continue;
        }
		for(ll x=a[i];x<=a.back();x+=a[i]){
            cnt[x]++;
		}
	}
    ll ans=0;
	rep(i,n){
        if(cnt[a[i]]==1) ans++;
	}
	cout<<ans<<endl;
}

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

int main() {
  int N;
  int C[500];
  int S[500];
  int F[500];
  int x[500];
  cin >>N;
  for(int i=0;i<N-1;i++){
    cin >>C[i] >>S[i] >>F[i];
  }
  for(int k=0;k<N-1;k++){
    x[k]=S[k]+C[k];
    for(int l=1;k+l<N-1;l++){
      x[k]=x[k]<S[k+l]?S[k+l]:x[k];
      x[k]+=(x[k]-S[k+l])%F[k+l]==0?0:F[k+l]-(x[k]-S[k+l])%F[k+l];
      x[k]+=C[k+l];
    }
  }
  x[N-1]=0;
  for(int j=0;j<N;j++){
    cout <<x[j] <<endl;
  }
  return 0;
}

Measured memory_bytes: 256
n = input()



if n[0] == "1":
    a = 9
elif n[0] == "9":
    a = 1

if n[1] == "1":
    b = 9
elif n[1] == "9":
    b = 1

if n[2] == "1":
    c = 9
elif n[2] == "9":
    c = 1

d = a*100 + b*10 + c


print(d)

Measured memory_bytes: 9056
#include <iostream>
#include <cmath>

using namespace std;

const int sz = 1000000007;

int main() {
 	int n;
  	cin >> n;
  	long long arr[n];
    long long pref[n];
    
  	for (int i = 0; i < n; i++) {
     	cin >> arr[i];
    }
    
    pref[0] = arr[0];
    for (int i = 1; i < n; i++) {
        pref[i] = pref[i - 1] + arr[i];
    }
  
  	long long sum = 0;
  	for (int i = 1; i < n; i++) {
        sum += (((pref[i - 1] % sz) * (arr[i] % sz)) % sz); 
    }
  
  	cout << sum % sz << endl;
  	return 0;
}

Measured memory_bytes: 6724
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.*;

public class Main {
    final BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    final String LINE_SPR = System.getProperty("line.separator");
    final int BIG_MOD = 1000000007;

    void run() throws Exception {
        String line;
        while((line = br.readLine()) != null) {
            int n = Integer.parseInt(line);
            int c = 0;
            for(int ab = 0; ab <= 18; ab++) {
                for(int cd = 0; cd <= 18; cd++) {
                    if(ab + cd == n) {
                        c += count(ab) * count(cd);
                    }
                }
            }
            System.out.println(c);

        }
    }

    int count(int n) {
        int c = 0;
        for(int a = 0; a <= 9; a++) 
            for(int b = 0; b <= 9; b++) 
                if(a + b == n)
                    c++;
        return c;
    }


    /*
     * Templates
     */
    void dumpObjArr(Object[] arr, int n) {
        for(int i = 0; i < n; i++) {
            System.out.print(arr[i]);
            if(i < n - 1)
                System.out.print(" ");
        }
        System.out.println("");
    }

    void dumpObjArr2(Object[][] arr, int m, int n) {
        for(int j = 0; j < m; j++) 
            dumpObjArr(arr[j], n);
    }

    int ni() throws Exception {
        return Integer.parseInt(br.readLine().trim());
    }

    long nl() throws Exception {
        return Long.parseLong(br.readLine().trim());
    }

    String ns() throws Exception {
        return br.readLine();
    }

    boolean isPrime(int n) {
        for(int i=2;i<n;i++) {
            if(n%i==0)
                return false;
        }
        return true;
    }

    int getPrime(int n) {
        List<Integer> primes = new ArrayList<Integer>();
        primes.add(2);
        int count = 1;

        int x = 1;
        while(primes.size() < n) {
            x+=2;
            int m = (int)Math.sqrt(x);
            for(int p : primes) {
                if(p > m) {
                    primes.add(x);
                    break;
                }

                if(x % p == 0) 
                    break;
            }
        }

        return primes.get(primes.size() - 1);
    }

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

    long gcd(long a, long b) {
        if(a < b) {
            long tmp = a;
            a = b;
            b = tmp;
        }
        // a >= b
        long mod = a % b;
        if(mod == 0) 
            return b;
        else 
            return gcd(b, mod);
    }

    void gcjPrint(String str, int t) {
        System.out.println("Case #" + t + ": " + str);
    }

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

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

using namespace std;

unsigned long long int lcm(unsigned long long int a, unsigned long long int b){
  if(a > b){
    unsigned long long int t = a;
    a = b;
    b = t;
  }
  unsigned long long int A, B;
  A = a;
  B = b;
  unsigned long long int r = 1;
  while(r != 0){
    r = a % b;
    a = b;
    b = r;
  }
  return A/a * B;
}

int main(){
  int N;
  cin >> N;
  
  vector <unsigned long long int> V(N);
  for(int i = 0; i < N; i++) cin >> V[i];
  
  unsigned long long int tmp = lcm(V[0],V[1]);
  //cout << tmp << endl;
  for(int i = 2; i < N; i++){
    tmp = lcm(tmp,V[i]);
    //cout << tmp << endl;
  }
  if(N == 1) cout << V[0];
  else cout << tmp;

}


Measured memory_bytes: 256
#include<cstdio>
#include<cmath>
#include<limits>
int main() {
	double x1, x2, y1, y2;
	scanf("%lf%lf%lf%lf", &x1, &y1, &x2, &y2);
	printf("%f", std::sqrt((x2 - x1)*(x2 - x1) + (y2 - y1)*(y2 - y1)));
	return 0;
}


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

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int n, r;
    cin >> n >> r;

    if (n > 10)
        cout << r << '\n';
    else
        cout << r + 100 * (10 - n) << '\n';

    return 0;
}


Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        List<Integer> abc = new ArrayList<>();
        abc.add(sc.nextInt());
        abc.add(sc.nextInt());
        abc.add(sc.nextInt());
        Collections.sort(abc);
        System.out.println(abc.get(2) * 10 + abc.get(1) + abc.get(0));
    }

}


Measured memory_bytes: 23252
import java.io.*;
import java.math.BigInteger;
import java.util.*;


public class Main implements Runnable {

    private void solve() throws IOException {

        int N = nextInt();
        int x = nextInt();
        int[] arr = new int[N];
        for(int i = 0; i < N; ++i) arr[i] = nextInt();

        long ret = 0L;

        for(int i = 1; i < N; ++i) {
            if(arr[i] + arr[i-1] > x) {
                int diff = Math.abs((arr[i]+arr[i-1] - x));
                if(arr[i] >= diff) {
                    ret += diff;
                    arr[i] -= diff;
                } else {
                    ret += arr[i];
                    diff -= arr[i];
                    arr[i] = 0;
                    ret += diff;
                    arr[i-1] -= diff;
                }
            }
        }
        for(int i = 1; i < N; ++i) {
            if(arr[i] + arr[i-1] > x) {
                int diff = Math.abs((arr[i]+arr[i-1] - x));
                if(arr[i] >= diff) {
                    ret += diff;
                    arr[i] -= diff;
                } else {
                    ret += arr[i];
                    diff -= arr[i];
                    arr[i] = 0;
                    ret += diff;
                    arr[i-1] -= diff;
                }
            }
        }

        writer.println(ret);
    }


    public static void main(String[] args) {

        new Main().run();
    }

    BufferedReader reader;
    StringTokenizer tokenizer;
    PrintWriter writer;

    public void run() {
        try {
            reader = new BufferedReader(new InputStreamReader(System.in));
//             reader = new BufferedReader(new FileReader("input.txt"));
            tokenizer = null;
            writer = new PrintWriter(System.out);
            solve();
            reader.close();
            writer.close();
        } catch (Exception e) {
            e.printStackTrace();
            System.exit(1);
        }
    }

    int nextInt() throws IOException {
        return Integer.parseInt(nextToken());
    }

    long nextLong() throws IOException {
        return Long.parseLong(nextToken());
    }

    double nextDouble() throws IOException {
        return Double.parseDouble(nextToken());
    }

    String nextToken() throws IOException {
        while(tokenizer == null || !tokenizer.hasMoreTokens()) {
            tokenizer = new StringTokenizer(reader.readLine());
        }

        return tokenizer.nextToken();
    }
}


Measured memory_bytes: 29088
b = input()
nes = []
nowb = 0
noww = 0
counter = 0
for i in b:
	if i == 'B':
		if noww == 0:
			nowb += 1
		else:
			counter += nowb * noww
			nowb += 1
			noww = 0
	else:
		if nowb != 0:
			noww += 1
		
counter += nowb * noww

print(counter)

Measured memory_bytes: 41820
#include <bits/stdc++.h>
#define rep(i,n) for(ll i=0;i<(n);++i)
#define all(a) (a).begin(),(a).end()
#define dunk(a) cout << (a) << endl
const int INF = 2e9;
using namespace std;
using Graph = vector<vector<int>>;
typedef pair<int,int> P;
typedef long long ll;

int main(){
    int n, k, x, y;
    cin >> n >> k >> x >> y;
    int ans = 0;

    rep(i,min(n,k)) ans += x;

    rep(i,n-k) ans += y;

    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int n, m;
int main() {
	cin >> n >> m; n -= 2;
	int ret = n / 11 * 5;
	for(int i = 1; i <= n % 11; i++) {
		for(int j = 1; j <= 5; j++) {
			if(9 * (i * 7 + j + 1) % 11 == m) ret++;
		}
	}
	cout << ret << endl;
	return 0;
}

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

using namespace std;

int main(){

        int a,b,c;
        cin >> a >> b >> c;
        int result = 0;

        for(int i = a; i <= b; i++)
                if((c % i) == 0) result++;

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

Measured memory_bytes: 1164
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int M = sc.nextInt();
		Long[] X = new Long[M];
		for (int i = 0; i < M; i++) {
			X[i] = sc.nextLong();
		}
		sc.close();

		// corner case
		if (N >= M) {
			System.out.println(0);
			return;
		}

		Arrays.sort(X);
		long sum = 0;
		Long[] d = new Long[M - 1];
		for (int i = 0; i < M; i++) {
			if (i + 1 < M) {
				d[i] = X[i + 1] - X[i];
				sum += d[i];
			}
		}
		Arrays.sort(d, Collections.reverseOrder());

		long ans = sum;
		for (int i = 0; i < N - 1; i++) {
			ans -= d[i];
		}
		System.out.println(ans);

	}
}


Measured memory_bytes: 61748
#include <bits/stdc++.h>
using namespace std;
#define endl "\n"
#define MOD 1000000007
#define fo(i,s,e) for( i=s;i<e;i++)
#define rfo(i,s,e) for(i=s;i>e;i--)
#define LLI long long int
#define LI long int 
#define pb push_back
#define pob pop_back()
#define sp " "
#define ff first
#define ss second
//               When something is important enough, you do it even if the odds are not in your favor.

int main(){   
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);cout.tie(NULL);
    /*#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif*/
    // code goes here
    int t=1;//cin>>t;
    while(t--){
      LI n,k,i,j;cin>>n>>k;
      LI a[n];
      fo(i,0,n) cin>>a[i];
      bool dp[k+4];    // it is 0 when first wins, 1 when second wins
      dp[0]=1;     //  second player will win
      fo(i,1,k+1){  // number of stones
        dp[i]=1;
        fo(j,0,n){
          if(i-a[j]>=0&&dp[i-a[j]]) dp[i]=0;
        }
      }
      if(dp[k]) cout<<"Second";
      else cout<<"First";
    }
    return 0;
}

Measured memory_bytes: 384
import math

def sieve_of_eratosthenes(n):
    prime_nums = []
    lim = n ** 0.5
    data = [i + 1 for i in range(1, n + 1)]
    while True:
        p = data[0]
        if lim <= p:
            return prime_nums + data
        prime_nums.append(p)
        
        data = [d for d in data if d % p != 0]

X = int(input())

prime_nums = sieve_of_eratosthenes(X * 2)
tmp_nums = [prime_num for prime_num in prime_nums if prime_num >= X]
print(tmp_nums[0])

Measured memory_bytes: 11800
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"
#include "numeric"

using namespace std;

const long long int MOD = 1000000007;

long long int N, M, K, H, W, L, R;


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

	cin >> N >> K;
	vector<long long int>v(N + 1);
	for (int i = 1; i <= N; i++)cin >> v[i];
	for (int i = 1; i <= N; i++)v[i] += v[i - 1];
	unsigned long long int ans = ULLONG_MAX;
	for (int i = 1; i <= N; i++) {
		unsigned long long int box = K * N;
		box += K * i;
		unsigned long long int cnt = 2;
		for (int j = N; j >= 1; j -= i) {
			if (j == N)box += (v[j] - v[max(j - i, 0)])*(cnt*cnt+1);
			else box += (v[j] - v[max(j - i, 0)])*(cnt*cnt-(cnt-1)*(cnt-1));
			cnt ++;
		}
		ans = min(ans, box);
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 1792
{-# LANGUAGE TypeApplications #-}

module Main where

import Data.List (sortOn)
import Data.Ord (Down(Down))

main :: IO ()
main = do
  n <- readLn @Int
  as <- map (read @Int) . words <$> getLine
  let comfs@(mx : _) = take n $ replicate 2 =<< (sortOn Down as)
  print $ sum comfs - mx


Measured memory_bytes: 105084
#include<stdio.h>
#include<string.h>
int main(){
    int N;
    char S[10000+1];
    scanf("%d",&N);
    scanf("%s",S);
    int len=strlen(S);
    for(int i=0;i<len;i++){
        int x=S[i]-'A';
        x=(x+N)%26;
        putchar('A'+x);
    }
    putchar('\n');
}

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


int main(){

    string s;
    cin>>s;
    int n=s.size();
    int ans=0;
    for(int i=0;i<n/2;i++) {
            if(s[i]!=s[n-i-1]) ans++;
    }

    cout<<ans;

}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main()
{
    int N;
    cin >> N;
    int A[N], B[N], C[N];
    int point = 0;
    for (int i = 0; i < N; i++)
    {
        cin >> A[i];
    }
    for (int i = 0; i < N; i++)
    {
        cin >> B[i];
    }
    for (int i = 0; i < N - 1; i++)
    {
        cin >> C[i];
    }
    for (int i = 0; i < N; i++)
    {
        point += B[A[i] - 1];
        if (i > 0 && A[i - 1] + 1 == A[i])
        {
            point += C[A[i] - 2];
        }
    }
    cout << point << endl;
}


Measured memory_bytes: 256