akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define st first
#define nd second
#define mp make_pair
#define pb push_back
#define mod 1000000007
#define N 1000005
using namespace std;

typedef long long ll;

ll n, m, ans, a[N], pre[N], suf[N];

void coz(){
	for(ll i = 1; i <= n; i++)
		pre[i] = pre[i - 1] + a[i];
	for(ll i = n; i >= 1; i--)
		suf[i] = suf[i + 1] + m - a[i];
	for(ll i = 0; i < n; i++){
		ll top = (pre[n - i + i/2] - pre[n - i - 1] + suf[n - i + i/2 + 1])*2;
		// cout << i << " " << top << endl;
		if(i%2 == 0)
			top -= a[n - i + i/2];
		else
			top -= m - a[n - i + i/2 + 1];
		// cout << i << " " << top << endl;
		ans = max(ans, top);
	}
}

int main() {
	// freopen("in.txt", "r", stdin);
	// freopen("out.txt", "w", stdout);
	scanf("%lld %lld",&m ,&n);
	for(ll i = 1; i <= n; i++)
		scanf("%lld",a + i);
	coz();
	for(ll i = 1; i <= n; i++)
		a[i] = m - a[i];
	reverse(a + 1, a + n + 1);
	coz();
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 9984
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int head=0;
int A[200];

void push(int x){

    head=head+1;
    A[head]=x;
}

int pop(){
    head=head-1;
    return A[head+1];
}
int main(int argc, const char * argv[]) {
    int a,b;
    char c[100];
    while(scanf("%s",c)!=EOF){
        if(c[0]=='+'){
            a=pop();
            b=pop();
            push(a+b);
        }
        else if(c[0]=='-'){
            a=pop();
            b=pop();
            push(b-a);
        }
        else if(c[0]=='*'){
            a=pop();
            b=pop();
            push(a*b);
            
        }
        else{
            push(atoi(c));
        }
    }
    printf("%d\n",pop());

    return 0;
}

Measured memory_bytes: 548
#!/usr/bin/env python3
import sys

input = sys.stdin.readline


def Y():
    print("Yes")


def N():
    print("No")


def S():
    return input().rstrip()


def I():
    return int(input())


def MI():
    return map(int, input().split())


x = I()
if x >= 30:
    Y()
else:
    N()


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

#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define REP(i, n)  for(int i=0;i<(n);++i)
#define REPr(i, n) for(int i=(n)-1;i>=0; --i)
#define FORq(i, m, n) for(int i = (m);i <= (n);++i)
#define FORqr(i, m, n) for(int i = (n);i >=(m);--i)
#define PB push_back
#define MP make_pair
#define DEBUG printf("%s\n","debug")
#define fst first
#define snd second
#define SIN(x, S) (S.count(x) != 0)
#define M0(x) memset(x,0,sizeof(x))
#define FILL(x, y) memset(x,y,sizeof(x))
#define MM(x) memset(x,-1,sizeof(x))
#define ALL(x) (x).begin(),(x).end()
#define SCD(n) scanf("%d",&n)
#define SCD2(m,n) scanf("%d%d",&m,&n)
#define SCD3(m,n,k) scanf("%d%d%d",&m,&n,&k)
#define SCLLD(n) scanf("%lld",&n)
#define SCLLD2(m,n) scanf("%lld%lld",&m,&n)
#define SCLLD3(m,n,k) scanf("%lld%lld%lld",&m,&n,&k)
using namespace std;
typedef pair<int, int> PII;
typedef pair<long long, long long> PLL;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<long long> VL;
typedef long long ll;
typedef long long integer;
///////////////////////////////////////////////
const ll MOD = 1e9+7;

ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }

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

template<class T>
inline bool chmax(T &a, T b) {
	if (a < b) {
		a = b;
		return true;
	}
	return false;
}
///////////////////////////////////////////////
/*🍈( '-'  🍈*/
long long powmod(ll x,ll y){
	ll ret = 1;
	while(y){
		if (y & 1) ret = ret * x % MOD;
		x = x * x % MOD;
		y>>=1;
	}
	return ret;
}

int main(){
	string L;
	cin >> L;
	int l = L.size();

	ll ans = 0;
	ll count = 0;
	REP(i,l){
		if (L[i] == '0') continue;
		ans += powmod(2,count) * powmod(3,(ll)l-(ll)i-1) % MOD; //1のl-1桁分
		++count;
	}

	ans += powmod(2,count); // l桁分
	cout << ans % MOD << "\n";
	return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(ll i = 0; i < (n); ++i)
#define repA(i, a, n) for(int  i = a; i <= (n); ++i)
#define all(x) x.begin(), x.end()
#define sz(x) (int) (x).size()
#define fill(a) memset(a, 0, sizeof(a))
#define fst first
#define snd second
#define mp make_pair
#define pb push_back
#define endl '\n'
#define init(n) int n;cin>>n;int a[n];rep(i,n)cin>>a[i];
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<long long int> vll;
typedef vector<pii> vii;
ll p1=1000000007;
int n;
int main() {
  
    cin.sync_with_stdio(0); cin.tie(0);
    cin.exceptions(cin.failbit);
    int T=1;
    // cin>>T;
    while(T--) {
        string s;cin>>s;
        rep(i,sz(s))s[i]='x';
        cout<<s;
    }   
    return 0;   
}

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

struct ruiseki {
	ll n;
	vector<ll>& a;
	vector<ll> sum;//区間[0,i)の総和
	vector<ll> xsum;//区間[0,i)の総xor
	ruiseki(vector<ll>& v) :a(v) {
		n = a.size();
		sum.resize(n + 1, 0);
		xsum.resize(n + 1, 0);
		for (ll i = 1; i <= n; ++i) {
			sum[i] = sum[i - 1] + a[i - 1];
			xsum[i] = xsum[i - 1] xor a[i - 1];
		}
	}

	//区間[l,r)の総和
	ll sumq(ll l, ll r) { return sum[r] - sum[l]; }

	//区間[l,r)の総xor
	ll xsumq(ll l, ll r) { return xsum[r] xor xsum[l]; }

	//区間[l,r)が問題文の条件を満たすか
	bool equal(ll l, ll r) { return sumq(l, r) == xsumq(l, r); }
};

int main() {
	ll n;
	cin >> n;
	vector<ll> a(n);
	for (ll i = 0; i < n; ++i) cin >> a[i];
	ruiseki r(a);
	ll ans = 0;
	for (ll i = 0; i < n; ++i) {
		ll Min = i + 1;
		ll Max = n + 1;
		while (Max - Min > 1) {
			ll Mid = (Min + Max) / 2;
			if (r.equal(i, Mid))Min = Mid;
			else Max = Mid;
		}
		ans += Min - i;
	}
	cout << ans << endl;
}


Measured memory_bytes: 8000
#include<iostream>
#include <fstream>
#include <stdio.h>
#include <stdlib.h>
#define _USE_MATH_DEFINES
#include <math.h>
#include<string>
#include<vector>
#include<cmath>
#include<stack>
#include<queue>
#include<sstream>
#include<algorithm>
#include<map>
#include<complex>
using namespace std;


#define li			long long int
#define rep(i,to)	for(int i=0;i<((int)(to));i++)
#define repp(i,start,to)	for(int i=(int)(start);i<((int)(to));i++)
#define pb			push_back
#define sz(v)		((li)(v).size())
#define bgn(v)		((v).begin())
#define eend(v)		((v).end())
#define allof(v)	(v).begin(), (v).end()
#define dodp(v,n)		memset(v,(li)n,sizeof(v))
#define bit(n)		(1ll<<(li)(n))
#define mp(a,b)		make_pair(a,b)
#define rin	rep(i,n)
#define EPS 1e-10
#define ETOL 1e-8
#define MOD 1000000007
#define F first
#define S second
#define p2(a,b)		cout<<a<<"\t"<<b<<endl
#define p3(a,b,c)		cout<<a<<"\t"<<b<<"\t"<<c<<endl

double a[6];

void solve(){
	double ab=sqrt((a[0]-a[3])*(a[0]-a[3])+(a[1]-a[4])*(a[1]-a[4]));
	if(ab>a[2]+a[5])cout<<0<<endl;
	else if(ab+a[5]<a[2])cout<<2<<endl;
	else if(ab+a[2]<a[5])cout<<-2<<endl;
	else cout<<1<<endl;
	
}

int main(){
	li n;
	cin>>n;
	rin{
		rep(j,6)cin>>a[j];
		solve();
	}
	
	return 0;
}

Measured memory_bytes: 1232
object Main {
  def main(args: Array[String]): Unit = {
    val input = io.Source.stdin.getLines().mkString("\n")
    println(solve(input).toString)
  }

  def solve(input:String): Int = {
    val str = input.split("\n")
    val xs = str(1).split(" ").map(_.toInt).toSeq

    def loop(xs:Seq[Int]): Int = {
      val ys = xs.map((x: Int) => x / 2)
      val b : Boolean = xs.forall(_ % 2 == 0)
      if (b) {
        1 + loop(ys)
      } else {
        0
      }
    }
    loop(xs)
  }
}

Measured memory_bytes: 27300
#include <bits/stdc++.h>
using namespace std;
typedef bool boool;
typedef long long ll;
#define vl vector<ll>
#define vb vector<boool>
#define vs vector<string>
#define vp vector<pair<ll, ll>>
#define vvl vector<vector<ll>>
#define vvp vector<vector<pair<ll, ll>>>
#define mod 1000000007
#define all(x) x.begin(), x.end()
#define rep1(i, n) for (long long i=0; i<(long long)(n); i++)
#define rep2(i, s, e) for (long long i=(s); i<(long long)(e); i++)
#define GET_MACRO(_1,_2,_3,NAME,...) NAME
#define rep(...) GET_MACRO(__VA_ARGS__, rep2, rep1)(__VA_ARGS__)

int main() {
  ll n;
  cin >> n;
  vl a(n), b(n);
  ll as=0, bs=0;
  rep(i, n){
    ll num;
    cin >> num;
    a[i] = num;
    as += num;
  }
  rep(i, n){
    ll num;
    cin >> num;
    b[i] = num;
    bs += num;
  }
  if(as<bs){
    cout << -1 << endl;
    return 0;
  }
  vl plus, minus;
  rep(i, n){
    if(a[i] >= b[i]) plus.push_back(a[i]-b[i]);
    else minus.push_back(b[i]-a[i]);
  }
  ll ans = 0;
  ans += minus.size();
  if(ans == 0){
    cout << 0 << endl;
    return 0;
  }
  ll ms = 0;
  for(auto e : minus) ms += e;
  ll ps = 0;
  sort(all(plus), greater<ll>());
  rep(i, plus.size()){
    ps += plus[i];
    if(ps >= ms){
      ans += i+1;
      cout << ans << endl;
      return 0;
    }
  }
  return 0;
}

Measured memory_bytes: 5860
#include <bits/stdc++.h>
#define ll long long
#define double long double
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,n) for(int i=1;i<=(n);i++)
#define mod (ll)(1e9+7)
#define inf (ll)(3e18+7)
#define pi (double) acos(-1)
#define P pair<int,int>
#define PiP pair<int,pair<int,int>>
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
using namespace std;

int main() {
    ll n;
    cin >> n;
    vector<ll> a(n), b(n);
    ll ans = 0;
    rep(i, n)cin >> a[i] >> b[i];
    reverse(all(a));
    reverse(all(b));
    rep(i, n){
        a[i] += ans;
        if(a[i] % b[i] != 0){
            ans += b[i] - a[i] % b[i];
        }
    }
    cout << ans << endl;
}      


Measured memory_bytes: 1792
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <cctype>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <limits>

using namespace std;
typedef long long int ll;
typedef long double ld;
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); };                      // 最小公倍数
ll getDigit(ll num) { return log10(num) + 1; }                         // 桁数
ll digitSum(ll n) { return (n < 10) ? n : digitSum(n / 10) + n % 10; } // 各桁の和
#define pb push_back
#define rep(i, n) for (ll i = 0; i < n; i++)
#define repn(i, n) for (ll i = 1; i <= n; i++)
#define repi(i, a, b) for (int i = int(a); i < int(b); ++i)
#define all(x) (x).begin(), (x).end()

void Main()
{
    int h, w;
    cin >> h >> w;
    vector<string> s(h);
    rep(i, h) cin >> s[i];

    rep(i, h)
    {
        cout << s[i] << "\r\n"
             << s[i] << endl;
    }
    return;
}

signed main(void)
{
    std::cin.tie(nullptr);
    std::ios_base::sync_with_stdio(false);
    std::cout << std::fixed << std::setprecision(15);
    Main();
    return 0;
}


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

typedef long long LL;
const int MAXN=1e5+5;

int ans,x[MAXN],y[MAXN];
int n,m,r; 

int main(){
	cin>>n;
	for(int i=1;i<=n;i++){
		cin>>x[i];
	}
	int ans=0;
	for(int i=1;i<=n;i++){
		if (x[i]!=i) continue;
		if (i!=n) swap(x[i],x[i+1]);
		else swap(x[i],x[i-1]);
		ans++;
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 640
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
 
int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	int array[5];
	for(int i = 0; i < 5; ++i){
		cin >> array[i];
	}
	
	sort(array, array + 5);
	
	for(int i = 4; i >= 0; --i){
		cout << array[i];
		if(i != 0)
			cout << ' ';
	}
	cout << endl;
	
	return 0;
}

Measured memory_bytes: 1204
#include <iostream>
#include <string>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <vector>
#include <cmath>
#include <cstdlib>
#include <queue>
#include <stack>
#include <iomanip>


using namespace std;

#define REP(i, n) for(ll i = 0;i < n;i++)
#define REPR(i, n) for(ll i = n;i >= 0;i--)
#define FOR(i, m, n) for(ll i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define REPO(i, n) for(ll i = 1;i <= n;i++)
#define ll long long
#define INF (ll)1 << 60
#define MINF (-1 * INF)
#define ALL(n) n.begin(),n.end()
#define MOD (ll)1000000007
#define P pair<ll, ll>

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

	

Measured memory_bytes: 256
// https://atcoder.jp/contests/abc047/tasks/arc063_a

#include <bits/stdc++.h>
#define REP(i, n) for (int(i) = 0; (i) < (n); (i)++)
#define REPR(i, n) for (int(i) = (n); (i) >= 0; (i)--)
#define FOR(i, m, n) for (int(i) = (m); (i) < (n); i++)
#define INF 1e9
#define ALL(v) (v).begin(), (v).end()
using namespace std;
typedef long long ll;

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

  int len = s.length(), cnt = 0;
  char l = s[0], c;
  REP(i, len - 1)
  {
    if (s[i + 1] == l)
      continue;
    l = s[i + 1];
    cnt++;
  }

  cout << cnt << '\n';

  return 0;
}


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

using namespace std;

constexpr int N = 1e5 + 10;
constexpr int MOD = 1e9 + 7;

long long t, n, a[N], mn, dp[N], e, en, ps[N];

void upd (int x) {
    if (!mn)
        mn = x;
    long long ghabli = 2 * a[mn] + a[mn + 1] + dp[mn + 1];
    long long jadid = 2 * a[x] + a[x + 1] + dp[x + 1];
    if (jadid < ghabli)
        mn = x;
}

int main() {
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    cin >> n >> e >> t;
    for (int i = 1; i <= n; i++)
        cin >> a[i];
    en = n;
    a[n + 1] = e;
    for (int i = n; i; i--) {
        while (2 * (a[en] - a[i]) > t) {
            upd (en);
            en--;
        }
        // ta en berim va bargardim
        dp[i] = t + a[en + 1] - a[i] + dp[en + 1];
        // ta min berim va bargardim
        if (mn)
            dp[i] = min (dp[i], 2 * a[mn] + a[mn + 1] + dp[mn + 1] - 3 * a[i]);
    }
    cout << dp[1] + a[1] << '\n';
    return 0;
}


Measured memory_bytes: 1792
N = int(input())
ans = True
k,x,y = 0,0,0
for i in range(N):
    t,p,q = map(int,input().split())
    d = abs(x-p)+abs(y-q)
    if d>(t-k):ans = False
    if ((t-k)-d)%2==1:ans = False
    k,x,y = t,p,q
print("Yes" if ans else "No")

Measured memory_bytes: 3064
# -*- coding:utf-8 -*-


def merge(lst, left, mid, right):
    L = lst[left: mid]
    R = lst[mid: right]
    l_len = len(L)
    r_len = len(R)
    i = 0
    j = 0
    cnt = 0
    for k in range(left, right):
        if l_len <= i:
            lst[k] = R[j]
            j += 1
        elif r_len <= j:
            lst[k] = L[i]
            i += 1
        elif L[i] <= R[j]:
            lst[k] = L[i]
            i += 1
        else:
            lst[k] = R[j]
            cnt += l_len - i
            j += 1
    return cnt


def mergeSort(lst, left, right):
    if left + 1 < right:
        mid = (left + right) >> 1
        cnt = mergeSort(lst, left, mid)
        cnt += mergeSort(lst, mid, right)
        return merge(lst, left, mid, right) + cnt
    else:
        return 0


def inversions(lst, n):
    return mergeSort(lst, 0, n)


def countingSort(lst, n):
    cnt_lst = [0] * (max(lst)+1)

    for i in range(0, n):
        cnt_lst[lst[i]] += 1

    i = 0
    result = []
    for j, cnt in enumerate(cnt_lst):
        for _ in range(0, cnt):
            result.append(j)
    return result


if __name__ == "__main__":
    n = int(input())
    lst = [int(val) for val in input().split()]
    print(inversions(lst, n))

Measured memory_bytes: 30284
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define FOR(i, m, n) for (ll i = m; i < n; i++)
#define IFOR(i, m, n) for (ll i = n - 1; i >= m; i--)
#define REP(i, n) FOR(i, 0, n)
#define IREP(i, n) IFOR(i, 0, n)
#define FOREACH(x, a) for (auto&(x) : (a))
#define ALL(v) (v).begin(), (v).end()
#define SZ(x) ll(x.size())

int main() {
  ll n, k;
  cin >> n >> k;
  vector<ll> p(n), c(n);
  REP(i, n) {
    cin >> p[i];
    p[i]--;
  }
  REP(i, n) { cin >> c[i]; }

  ll ans = -1e18;
  REP(i, n) {
    vector<ll> sum(n + 1, 0);
    ll syuki = -1;
    ll cur = i;
    REP(j, n) {
      cur = p[cur];
      if (cur == i && syuki == -1) {
        syuki = j + 1;
      }
      sum[j + 1] = sum[j] + c[cur];
    }

    if (syuki >= k) {
      FOR(j, 1, k + 1) { ans = max(ans, sum[j]); }
      continue;
    }

    if (sum[syuki] < 0) {
      FOR(j, 1, syuki + 1) { ans = max(ans, sum[j]); }
      continue;
    }

    ll syu = k % syuki == 0 ? k / syuki - 1 : k / syuki;
    ll t = sum[syuki] * syu;
    ll rem = k % syuki == 0 ? syuki : k % syuki;
    FOR(j, 1, rem + 1) { ans = max(ans, sum[j] + t); }
  }
  cout << ans << endl;
}

Measured memory_bytes: 3680
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<climits>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<stack>
#include<numeric>
#include<map>
#include<set>
using namespace std;
#define REP(i,m,n) for(int i = m; i < n; i++)
#define rep(i,n) REP(i,0,n)
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a)  (a).rbegin(),(a).rend()
#define LL long long
#define PI 3.14159265359
template<class T> inline void chmax(T & a, T b) { if (a < b) { a = b; } }
template<class T> inline void chmin(T& a, T b) { if (a > b) { a = b; } }
template<class T> void print_vector(vector<T> vec) {
	cout << "[ ";
	for (int i = 0; i < vec.size(); i++) {
		cout << vec[i] << " ";
	}
	cout << "]" << endl;
}
template<class T> void print_pair_vector(vector<pair<T, T> > vec) {
	cout << "[ ";
	for (int i = 0; i < vec.size(); i++) {
		cout << "(" << vec[i].first << "," << vec[i].second << ") ";
	}
	cout << "]" << endl;
}

int main(void) {
	string s1, s2, s3;
	cin >> s1 >> s2 >> s3;

	printf("%c%c%c\n", s1[0], s2[1], s3[2]);

	return 0;
}

Measured memory_bytes: 256
from sys import maxsize
from heapq import heappop, heappush


class Node:
    WHITE = 0
    GRAY = 1
    BLACK = 2

    def __init__(self):
        self.adjs = []
        self.color = Node.WHITE
        self.dist = maxsize

    def __lt__(self, other):
        return self.dist < other.dist

    def __repr__(self):
        return "Node({},{},{})".format(self.adjs, self.color, self.dist)


def read_adj():
    n = int(input())
    nodes = [Node() for _ in range(n)]

    for i in range(n):
        u, _, *rest = [int(x) for x in input().split()]
        for i in range(0, len(rest) - 1, 2):
            nodes[u].adjs.append((rest[i], rest[i+1]))

    return nodes


def shortest_path(nodes):
    h = []

    nodes[0].dist = 0
    nodes[0].color = Node.GRAY
    heappush(h, (0, 0))

    while len(h) > 0:
        min_node, min_dist = heappop(h)
        if nodes[min_node].dist < min_dist:
            continue

        nodes[min_node].color = Node.BLACK

        for adj, c in nodes[min_node].adjs:
            if nodes[min_node].dist + c < nodes[adj].dist:
                nodes[adj].dist = nodes[min_node].dist + c
                nodes[adj].color = Node.GRAY
                heappush(h, (adj, nodes[adj].dist))


def print_dist(nodes):
    for u, n in enumerate(nodes):
        print(u, n.dist)


def main():
    nodes = read_adj()
    shortest_path(nodes)
    print_dist(nodes)


if __name__ == '__main__':
    main()



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

using namespace std;

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

	int ans = 0;
	for (int i = 0; i < S.length(); i++)
	{
		char t = 'g';
		if (i % 2 == 1)
		{
			t = 'p';
		}
		if ((int)S[i] > (int)t)
		{
			ans--;
		}
		else if ((int)S[i] < (int)t)
		{
			ans++;
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 512
n = int(input())
csf = [list(map(int, input().split())) for _ in range(n-1)]
 
for i in range(n):
    current = 0
    for j in range(i, n-1):
        if current < csf[j][1]:
            current = csf[j][1]
        if current % csf[j][2] != 0:
            current += csf[j][2] - (current % csf[j][2])
        current += csf[j][0]
    print(current)

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

const ll MOD = 1e9 + 7;
const int MAX_H = 110;
const int MAX_W = 10;

ll dp[MAX_H][MAX_W];

int main() {
    int H, W, K;
    cin >> H >> W >> K;
    dp[0][1] = 1;
    for (int h = 1; h <= H; h++) {
        for (int w = 1; w <= W; w++) {
            for (int mask = 0; mask < (1 << (W - 1)); mask++) {
                // 横棒として正しいか確認
                bool is_ok = true;
                for (int i = 0; i < W - 2; i++) {
                    if (((mask >> i) & 1) && ((mask >> (i + 1)) & 1)) {
                        is_ok = false;
                    }
                }
                if (!is_ok) continue;
                // 現在見ている縦棒wの横に棒があるか確認
                if (w == 1 && mask & 1 && w + 1 <= W) {
                    dp[h][w] = (dp[h][w] + dp[h - 1][w + 1]) % MOD;
                }
                else if (w == W && (mask >> (w - 2)) & 1 && w - 1 >= 1) {
                    dp[h][w] = (dp[h][w] + dp[h - 1][w - 1]) % MOD;
                }
                else if (w > 1 && w < W && (mask >> (w - 1)) & 1) {
                    dp[h][w] = (dp[h][w] + dp[h - 1][w + 1]) % MOD;
                }
                else if (w > 1 && w < W && (mask >> (w - 2)) & 1) {
                    dp[h][w] = (dp[h][w] + dp[h - 1][w - 1]) % MOD;
                }
                else {
                    dp[h][w] = (dp[h][w] + dp[h - 1][w]) % MOD;
                }
            }
        }
    }
    cout << dp[H][K] << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#define ll long long
using namespace std;
int main(){
    int n,k;
    string s;
    cin>>n>>k>>s;
    int knum=k-1;
    if(s[knum]=='A'){
        s[knum]='a';
    }else if(s[knum]=='B'){
        s[knum]='b';
    }else{
        s[knum]='c';
    }
    cout<<s<<endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner input=new Scanner(System.in);
		
		int a[]=new int[2];
		
		for(int i=0;i<2;i++)
			a[i]=input.nextInt();
		
		System.out.println(a[1]*a[0]);
	}

}


Measured memory_bytes: 35664
#include <bits/stdc++.h>
using namespace std;
int main(){
    int n;
    cin>>n;
    int a[n];
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    int flag=1,j=0,c=0;
    while(flag){
        flag=0;
        for(int i=n-1;i>0;i--){
            if(a[i]<a[i-1]){
                swap(a[i],a[i-1]);
                c++;
                flag=1;
            }
        }
    }
    for(int i=0;i<n;i++){
        cout<<a[i]<<" \n"[i==n-1];
    }
    cout<<c<<endl;
    return 0;
}


Measured memory_bytes: 3116
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.PriorityQueue;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) throws IOException {

		new Main().run();
	}

	@SuppressWarnings("unchecked")
	private void run() throws IOException {
		Scanner scanner = new Scanner(System.in);
		loop: while (true) {
			int n = scanner.nextInt();
			if (n == 0)
				break;
			Map<String, Integer>[] supers = new Map[n];
			for (int i = 0; i < n; i++)
				supers[i] = new HashMap<String, Integer>();
			Map<String, Integer> min = new HashMap<String, Integer>();
			for (int i = 0; i < n; i++) {
				int k = scanner.nextInt();
				for (int j = 0; j < k; j++) {
					String name = scanner.next();
					int value = scanner.nextInt();
					supers[i].put(name, value);
					if (!min.containsKey(name) || min.get(name) > value)
						min.put(name, value);
				}
			}
			int q = scanner.nextInt();
			String[] name = new String[q];
			for (int i = 0; i < q; i++)
				name[i] = scanner.next();
			int m = scanner.nextInt();
			List<Point>[] lists = new List[n + 1];
			for (int i = 0; i <= n; i++)
				lists[i] = new ArrayList<Main.Point>();

			while (m-- > 0) {
				int s = scanner.nextInt();
				int t = scanner.nextInt();
				int d = scanner.nextInt();
				lists[s].add(new Point(t, d));
				lists[t].add(new Point(s, d));
			}
			int sum = 0;
			for (int i = 0; i < q; i++) {
				if (!min.containsKey(name[i])) {
					System.out.println("impossible");
					continue loop;
				}
				sum += min.get(name[i]);
			}
			int[][] dp = new int[n + 1][1 << q];
			for (int[] dp1 : dp)
				Arrays.fill(dp1, 1 << 20);
			PriorityQueue<Point> pq = new PriorityQueue<Point>();
			pq.offer(new Point(0, 0, 0));
			int ans = 0;
			int[] bits = new int[n];
			for (int i = 0; i < n; i++) {
				int bit = 0;
				for (int j = 0; j < q; j++) {
					if (supers[i].containsKey(name[j])
							&& supers[i].get(name[j]).equals(min.get(name[j])))
						bit |= 1 << j;
				}
				bits[i] = bit;
			}
			while (!pq.isEmpty()) {
				Point p = pq.poll();
				int t = p.t;
				int cost = p.cost;
				int bit = p.bit;
				if (t == 0 && Integer.bitCount(bit) == q) {
					ans = cost;
					break;
				}
				if (dp[t][bit] < cost)
					continue;
				dp[t][bit] = cost;
				if (t > 0)
					bit |= bits[t - 1];
				for (Point point : lists[t])
					pq.offer(new Point(point.t, cost + point.cost, bit));

			}
			System.out.println(sum + " " + ans);
		}
	}

	class Point implements Comparable<Point> {
		int t, cost, bit;

		@Override
		public String toString() {
			return "Point [t=" + t + ", cost=" + cost + ", bit=" + bit + "]";
		}

		public Point(int t, int cost, int bit) {
			super();
			this.t = t;
			this.cost = cost;
			this.bit = bit;
		}

		public Point(int t, int cost) {
			super();
			this.t = t;
			this.cost = cost;
		}

		@Override
		public int compareTo(Point o) {
			if (cost == o.cost)
				return o.bit - bit;
			return cost - o.cost;
		}
	}
}

Measured memory_bytes: 25400
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;

#define watch(x) cout<<(#x)<<"="<<(x)<<endl
#define mset(d,val) memset(d,val,sizeof(d))
#define setp(x) cout<<fixed<<setprecision(x)
#define forn(i,a,b) for(int i=a;i<b;i++)
#define fore(i,a,b) for(int i=a;i<=b;i++)
#define pb push_back
#define F first
#define S second
#define PI 3.14159265358979323846264338327
#define INF 2e14
#define MOD 998244353
#define pqueue priority_queue
#define fbo find_by_order
#define ook order_of_key
typedef long long ll;
typedef pair<ll,ll> ii;
typedef vector<ll> vi;
typedef vector<ii> vii;
typedef unsigned long long ull;
typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> pbds;

#define MAXN 100005

int main()
{
	ios_base::sync_with_stdio(0); cin.tie(0);
	
	string s; cin>>s;
	int n=s.length();
	
	int cnt=0;
	forn(i,0,n){
		if(s[i]=='o') cnt++;
	}
	
	if((15-n)+cnt>=8) cout<<"YES"<<'\n';
	else cout<<"NO"<<'\n';
	
	return 0;
}


Measured memory_bytes: 256
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0;i < (int)(n);i++)
using ll = long long;
const ll MOD=1000000007;
const long long INF = 1LL << 60;
const double pi=acos(-1.0);

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



int main()
{
  ll N; cin>>N;
  map<string,ll> mp;
  vector<string> vec(0);
  ll count=1;
  rep(i,N){
    string S; cin>>S;
    if(!mp.count(S)) mp[S]=1;
    else mp.at(S)++;
    
    if(count==mp.at(S)) vec.push_back(S);
    if(chmax(count,mp.at(S))) {vec=vector<string>(0); vec.push_back(S);}
  }
  
  sort(vec.begin(),vec.end());
  
  for(auto ans:vec) cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 25116
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int mod=1e9+7;
int main()
{
    int h,w;
    cin>>h>>w;
    char bd[h][w];
    for(int i=0;i<h;i++)
    for(int j=0;j<w;j++)
    cin>>bd[i][j];
    
    ll dp[h][w];
    memset(dp, 0, sizeof dp);
    dp[0][0]=1;
    for(int i=1;i<h;i++)
    {	if(bd[i][0]=='#')continue;
    	dp[i][0]+=dp[i-1][0];
    	dp[i][0]%=mod;
    }
    for(int i=1;i<w;i++)
    {
    	if(bd[0][i]=='#')continue;
    	dp[0][i]+=dp[0][i-1];
    	dp[0][i]%=mod;
    }
    
    for(int i=1;i<h;i++)
    for(int j=1;j<w;j++)
    {
    	if(bd[i][j]=='#')continue;
    	dp[i][j]=(dp[i-1][j]+dp[i][j-1])%mod;
    }
    cout<<dp[h-1][w-1];
    
    




}

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

template<typename T>
void rin(T &t)
{
	t=0;int k=1;char c=getchar();
	while(!isdigit(c)){if(c=='-')k=-1;c=getchar();}
	while(isdigit(c)){t=t*10+c-'0';c=getchar();}
	t*=k;
}

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

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

using namespace std;

#define ll long long
#define sint(a) scanf("%d",&a)
#define sint2(a,b) scanf("%d %d",&a,&b)
#define sll(a) scanf("%lld",&a)
#define sll2(a,b) scanf("%lld %lld",&a,&b)
#define mem(a,i) memset(a,i,sizeof(a))


int main()
{
    int a,h;
    cin>>h>>a;
    if(h%a==0)
    cout<<h/a;
    else
        cout<<h/a+1;

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i) 
#define PI acos(-1)

using namespace std;
using ll = long long;
using P = pair<int, int>;
using LP = pair<ll, ll>;

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

    int N, R;
    cin>>N>>R;
    if (N >= 10) cout<<R<<endl;
    else cout<<R + 100 * (10 - N)<<endl;
}


Measured memory_bytes: 256
import sys

readline = sys.stdin.readline
readall = sys.stdin.read
ns = lambda: readline().rstrip()
ni = lambda: int(readline().rstrip())
nm = lambda: map(int, readline().split())
nl = lambda: list(map(int, readline().split()))
prn = lambda x: print(*x, sep='\n')

def solve():
    n = ni()
    m = int((n+1)**.5)
    u = n // (m + 1)
    ans = 0
    for i in range(1, u+1):
        v = n // i
        ans += v * (v + 1) // 2 * i
    for i in range(m, 0, -1):
        v = n // i
        ans += (v * (v + 1) - u * (u + 1)) // 2 * i * (i + 1) // 2
        u = v
    print(ans)
    return

solve()


Measured memory_bytes: 9348
#include <bits/stdc++.h>
using namespace std;
int main() {
    int W,H,N;
    cin >> W >> H >> N;
    vector<int> x(N),y(N),a(N);
    for(int i = 0; i < N; i++) cin >> x[i] >> y[i] >> a[i];
    int x1,x2,y1,y2;
    x1 = 0;
    x2 = W;
    y1 = 0;
    y2 = H;
    for(int i = 0; i < N; i++){
        if(a[i] == 1) x1 = max(x1,x[i]);
        else if(a[i] == 2) x2 = min(x2,x[i]);
        else if(a[i] == 3) y1 = max(y1,y[i]);
        else if(a[i] == 4) y2 = min(y2,y[i]);
    }
    int BW,BH;
    //cout << x1 << " " << x2 << " " << y1 << " " << y2 << endl;
    BW = x1 + W - x2;
    BH = y1 + H - y2;
    int ans = W*H - BW*H - W*BH + BW*BH;
    if(x1 > x2 || y1 > y2) cout << 0 << endl;
    else cout << ans << endl;
}

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

vector <int> niz;
int n,a,b;
vector <int> mini;


int main(){
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>a;
		niz.push_back(a);
	}
	
	mini.insert(mini.begin(),niz.size(),1e5);
	mini[0]=0;
	for(int i=1;i<niz.size();i++){
		if(i-2<0){
			a=mini[i-1]+abs(niz[i-1]-niz[i]);
			mini[i]=a;
		}else{
			a=mini[i-1]+abs(niz[i-1]-niz[i]);
			b=mini[i-2]+abs(niz[i-2]-niz[i]);
			mini[i]=min(a,b);
		}
	}
	
	cout<<mini[n-1];
}


Measured memory_bytes: 1144
#include <iostream>
#include <fstream>
#include <deque>
//#define LOCAL
using namespace std;
typedef long long ll;
deque<ll>number;


int main() {
#ifdef LOCAL
ifstream fin("1.txt");
streambuf*p;
p=cin.rdbuf(fin.rdbuf());
#endif // LOCAL
ll q;
cin>>q;
for(ll i=1;i<=q;i++){
    int t;
    cin>>t;
    if(0==t){
        ll d, x;
        cin>>d>>x;
        (0==d)?number.push_front(x):number.push_back(x);
    }else if(1==t){
        ll pp;
        cin>>pp;
        cout<<number[pp]<<endl;
    }else if(2==t){
        ll d;
        cin>>d;
        (0==d)?number.pop_front():number.pop_back();
    }

}



#ifdef LOCAL
fin.close();
#endif // LOCAL
}










Measured memory_bytes: 6308
# -*- coding: utf-8 -*-

import sys

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 18
MOD = 10 ** 9 + 7

class BIT:
    """ Binary Indexed Tree """

    def __init__(self, n):
        # 0-indexed
        n += 1
        nv = 1
        while nv < n:
            nv *= 2
        self.size = nv
        self.tree = [0] * nv

    def sum(self, i):
        """ [0, i]を合計する """
        s = 0
        i += 1
        while i > 0:
            s += self.tree[i-1]
            i -= i & -i
        return s

    def add(self, i, x):
        """ 値の追加：添字i, 値x """
        i += 1
        while i <= self.size:
            self.tree[i-1] += x
            i += i & -i

    def get(self, l, r=None):
        """ 区間和の取得 [l, r) """
        # 引数が1つなら一点の値を取得
        if r is None: r = l + 1
        res = 0
        if r: res += self.sum(r-1)
        if l: res -= self.sum(l-1)
        return res

    def update(self, i, x):
        """ 値の更新：添字i, 値x """
        self.add(i, x - self.get(i))

N = INT()
S = [ord(c)-97 for c in input()]
BITs = [BIT(N+1) for i in range(26)]
for i, s in enumerate(S):
    BITs[s].add(i, 1)

Q = INT()
for _ in range(Q):
    q = list(input().split())
    if q[0] == '1':
        _, i, c = q
        i = int(i) - 1
        c = ord(c) - 97
        if S[i] != c:
            prev = S[i]
            S[i] = c
            BITs[prev].add(i, -1)
            BITs[c].add(i, 1)
    else:
        _, l, r = q
        l, r = int(l) - 1, int(r) - 1
        ans = 0
        for c in range(26):
            if BITs[c].get(l, r+1) > 0:
                ans += 1
        print(ans)


Measured memory_bytes: 151712
#include<iostream>
#include<vector>
#include<algorithm>
#include<functional>
#include<queue>
#include<stack>
#include<set>
#include<climits>
#include<cstdlib>
#include<cmath>
#include<string>

using namespace std;

#define INF 1 << 29
#define LL long long int

LL const MOD = 1000000007;

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

    string str;
    cin >> str;

    LL size = str.size();

    LL ans = (size*(size-1))/2 + 1;    

    vector<LL> countup(26,0);
    for(int i = 0; i < size; i++){
        countup[str[i]-'a']++;
    }

    for(int i = 0; i < 26; i++){
        ans -= (countup[i]*(countup[i]-1))/2;
    }

    cout << ans << endl;

    return 0;
}

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

#define M_PI       3.14159265358979323846

using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; }
template<class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str(); }
inline int readInt() { int x; scanf("%d", &x); return x; }

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<int, PII> TIII;
typedef long long LL;
typedef unsigned long long ULL;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;


//container util

//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SQ(a) ((a)*(a))
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,s,n) for(int i=s;i<(int)n;++i)
#define REP(i,n) FOR(i,0,n)
#define MOD 1000000007

#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define all(x) x.begin(), x.end()
#define sz(x) (int)(x).size()

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

#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)


struct Edge {
    int to, from;
    ll cost;
    Edge(int from, int to, ll cost): from(from), to(to), cost(cost) {}
};

typedef vector<vector<Edge>> AdjList;
AdjList graph;

int n, t;
int main() {
    //cin.tie(0);
    //ios::sync_with_stdio(false);
    //cout << fixed << setprecision(10);

    int N; cin >> N;
    int A[25], B[25], C[25];
    REP(i, N) {
        cin >> A[i];
        A[i]--;
    }
    REP(i, N) cin >> B[i];
    REP(i, N-1) cin >> C[i];

    int ans = 0;
    int prev = -1;
    for(int i=0; i<N; ++i){
        ans += B[A[i]];
        
        if(prev==-1) {
            prev=A[i];
            continue;
        
        }
        if(prev+1 == A[i]){
            ans += C[prev]; 
        }
        prev=A[i];
    }
    cout << ans << endl;
    return 0;

}

Measured memory_bytes: 256
// D - Grid Coloring
#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
using vvi = vector<vi>;
#define rp(i,s,e) for(int i=(s);i<(e);++i)

vvi solve(int H, int W, int N, vi &A){
	vi AA(H*W);
	int j = 0;
	rp(c, 0, N) rp(i, 0, A[c]) AA[j++] = c + 1;

	vvi V(H, vi(W));
	rp(i, 0, H*W){
		int h = i / W, w = i % W;
		if(h%2) w = W - 1 - w;// reverse direction
		V[h][w] = AA[i];
	}
	return V;
}

int main(){
	int H,W,N; cin>>H>>W>>N;
	vi A(N); rp(i, 0, N) cin>>A[i];
	vvi V = solve(H, W, N, A);
	rp(i, 0, H) rp(j, 0, W) printf("%d%c",V[i][j],j+1==W?'\n':' ');
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;

	typedef tree<
			int,
			null_type,
			less<int>,
			rb_tree_tag,
			tree_order_statistics_node_update>
	ordered_set;
	
#define ll long long 


int main(){
	ios::sync_with_stdio(false);cin.tie(0);
	ll a,b,c;cin>>a>>b>>c;
	cout<<(c/a)*b<<endl;
	return 0;
	
}


Measured memory_bytes: 3612
#include <bits/stdc++.h>
using namespace std;
#define inf 0x3f3f3f3f
#define mod 1000000007
#define pb push_back
#define mp make_pair
#define ll long long
#define vi vector <int>
#define pii pair <int, int>
#define rep(i,n) for (int i = 0; i < (int) (n); ++ i)
#define foreach(it,c) for (__typedef(c.begin()) it = c.begin(); it != c.end(); ++ it)

inline int read() {
	int x = 0, f = 1, c = getchar();
	for (;!(c >= 48); c = getchar()) if (c == 45) f ^= 1;
	for (; (c >= 48); c = getchar()) x = x * 10 + c - 48;
	return f ? x : -x;
}

const int N = 100005;
int a[N];
int main() {
	int n = read();
	rep(i, n) a[i] = read();
	sort(a, a + n);
	int mx = -inf;
	rep(i, n - 1) if (abs(a[i] - (a[n - 1] / 2.0)) < abs(mx - (a[n - 1] / 2.0))) mx = a[i];
	printf("%d %d\n", a[n - 1], mx);
	return 0;
}


Measured memory_bytes: 640
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
using ll = long long;
int main(){
    ll n,k;
    cin>>n>>k;
    vector<ll> h(n);
    for(int i=0;i<n;i++) cin>>h[i];
    sort(h.rbegin(),h.rend());
    ll ans=0;
    for(int i=0;i<n;i++){
        if(i>=k){
            ans+=h[i];
        }
    }
    cout<<ans<<endl;
    
    return 0;
}

Measured memory_bytes: 1792
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <stack>
#include <stdio.h>
#include <string>
#include <utility>
#include <vector>

using namespace std;

// conversion
//------------------------------------------
inline int toInt(string s) {
  int v;
  istringstream sin(s);
  sin >> v;
  return v;
}
template <class T> inline string toString(T x) {
  ostringstream sout;
  sout << x;
  return sout.str();
}

// math
//-------------------------------------------
template <class T> inline T sqr(T x) { return x * x; }

// typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

// container util
//------------------------------------------
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i, c)                                                             \
  for (typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define EXIST(s, e) ((s).find(e) != (s).end())
#define SORT(c) sort((c).begin(), (c).end())

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

// constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI = acos(-1.0);

// clear memory
#define CLR(a) memset((a), 0, sizeof(a))

// debug
#define dump(x) cerr << #x << " = " << (x) << endl;
#define debug(x)                                                               \
  cerr << #x << " = " << (x) << " (L" << __LINE__ << ")"                       \
       << " " << __FILE__ << endl;

void solve(long long A, long long B, long long C, long long D, long long E) {
  VI arr,wait;
  int time;
  int ans=1000000;
  arr.PB(A);
  arr.PB(B);
  arr.PB(C);
  arr.PB(E);
  arr.PB(D);
  SORT(arr);
  do {
    time=0;
    REP(i,5){
      if(arr[i]%10!=0 && i!=4){
        wait.PB(10*((arr[i]/10)+1));
        time+=10*((arr[i]/10)+1);
      }
      else time+=arr[i];
    } 
  ans=min(ans, time);
  }while (next_permutation(arr.begin(),arr.end()));
  cout<<ans<<endl;
}

int main() {
  long long A;
  scanf("%lld", &A);
  long long B;
  scanf("%lld", &B);
  long long C;
  scanf("%lld", &C);
  long long D;
  scanf("%lld", &D);
  long long E;
  scanf("%lld", &E);
  solve(A, B, C, D, E);
  return 0;
}


Measured memory_bytes: 256
import bisect

n,m = map(int, input().split())
a = [0]+list(map(int, input().split()))
n += 1
for i in range(1,n):
    a[i] += a[i-1]
    a[i] = a[i]%m
b = [0 for i in range(n)]
for i in range(n):
    b[i] = a[i]
b = list(set(b))
b.sort()
for i in range(n):
    a[i] = bisect.bisect_left(b,a[i])
dict = {}
flag = [False for i in range(max(a)+1)]
sum = 0
for i in a:
    if flag[i]:
        dict[i] += 1
    else:
        dict[i] = 1
        flag[i] = True
for i in dict.values():
    sum += i*(i-1)//2
print(sum)

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


int N, K;
vector<int> A;
const int MOD = 1e9+7;
const int MAX = 1e6;
ll fac[MAX], finv[MAX], inv[MAX];


void input() {
    cin >> N >> K;
    A = vector<int>(N);
    rep(i, N) cin >> A[i];
}


void comb_init() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}


ll comb(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}


int main() {
    input();
    comb_init();
    sort(A.begin(), A.end());
    ll mn = 0, mx = 0;
    for (int i = 0; i <= N-K; i++) {
        mn += (A[i] * comb(N-i-1, K-1)) % MOD;
    }
    for (int i = K-1; i < N; i++) {
        mx += (A[i] * comb(i, K-1)) % MOD;
    }
    ll ans = (mx - mn) % MOD;
    cout << ans << endl;
}


Measured memory_bytes: 24064
#include <bits/stdc++.h>
using namespace std;
int main(){
	int n;
	cin>>n;
	string a;
	cin>>a;
	int se[n],sw[n];
	for(int i=0;i<n;i++){
		se[i]=0;
		sw[i]=0;
	}
	if(a[0]=='E'){
		se[0]=1;
	}else{
		sw[0]=1;
	}
	for(int i=0;i<n;i++){
		if(a[i]=='E'){
			se[i]=se[i-1]+1;
			sw[i]=sw[i-1];
		}else{
			sw[i]=sw[i-1]+1;
			se[i]=se[i-1];
		}
	}
	int minv=3000000;
	for(int i=0;i<n;i++){
		int numl=0,numr=0,sum=0;
		if(i==0){
			sum=se[n-1]-se[i];
		}else if(i==n-1){
			sum=sw[n-2];
		}else{
			sum=sw[i-1]+(se[n-1]-se[i]);
		}
		minv=min(minv,sum);
	}
	cout<<minv<<endl;
	return 0;
}

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

using namespace std;

#define ll long long
#define fi first
#define se second

ll count(ll x){
	if(x==1)
		return 1;
	return 2*count(x/2)+1;
}

void test_case(){
	ll h;
	scanf("%lld",&h);
	printf("%lld\n",count(h));
}

int main(){
	int t=1;
	//scanf("%d",&t);
	
	while(t--)
		test_case();

}


Measured memory_bytes: 256
while True:
    data = input().split()
    m = int(data[0])
    f = int(data[1])
    r = int(data[2])
    if m == -1 and f == -1 and r == -1:
        break
    elif m == -1 or f == -1:
        print('F')
    else:
        if m + f >= 80:
            print('A')
        elif m + f >= 65:
            print('B')
        elif m + f >= 50:
            print('C')
        elif m + f >= 30:
            if r >= 50:
                print('C')
            else:
                print('D')
        else:
            print('F')

Measured memory_bytes: 7676
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 200005 ;
int dp[MAXN] ;
int h[MAXN] ;
int n , k ;
int main(){
    cin >> n >> k ;
    for ( int i = 1 ; i <= n ; i++ ){
        cin >> h[i] ;
    }
    dp[1] = 0 ;
    dp[2] = abs( h[2] - h[1] ) ;
    for ( int j = 3 ; j <= n ; j++ ){
        dp[j] = INT_MAX ;
        for ( int l = 1 ; l <= k ; l++ ){
            if ( j - l == 0 )
                break ;
            int t = dp[j-l] + abs( h[j] - h[j-l] ) ;
            dp[j] = min ( dp[j] , t ) ;
        }
    }
    cout << dp[n] ;
    return 0;
}


Measured memory_bytes: 1024
#include<iostream>
#include<algorithm>
#include<vector>
#include<numeric>
#include<string>
#include<cmath>
#include<set>
#include<queue>
#include<deque>
#include<bitset>
#include<iomanip>
#include<cctype>
#include<map>
#include<cstring>

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep2(i,a,b) for (int (i)=a;(i)<(b);(i)++)
#define all(x) (x).begin(),(x).end()

using namespace std;
using ll = long long int;

const int inf = 1001001000;
const long long int Inf = 1001001001001001000;



void print(vector<vector<int>> a){
	for (int i = 0; i < a.size(); i++)
	{
		for (int j=0;j<a[i].size();j++){
			cout << a[i][j] << " ";
		}
		cout << endl;
	}
}

void print(vector<vector<long long int>> a){
	for (int i=0;i<a.size();i++){
		for (int j=0;j<a[i].size();j++){
			cout << a[i][j] << " ";
		}
		cout << endl;
	}
}

void print(vector<int> a){
    int n = a.size();
    for (int j=0;j<n;j++) {
        if (j != n-1) cout << a[j] << " ";
        else cout << a[j] << endl;
    }
}

void print(vector<long long int> a){
    int n = a.size();
    for (int j=0;j<n;j++) {
        if (j != n-1) cout << a[j] << " ";
        else cout << a[j] << endl;
    }
}

void print(set<int> a){
	for (auto x:a)
		cout << x << " ";
	cout << endl;
}




int main() {
	ll n, w;
	cin >> n >> w;
	vector<ll> c(n), v(n);
	rep(i, n) cin >> c[i] >> v[i];
	int m = 100 * 300;
	m = accumulate(all(v), 0);
	vector<vector<ll>> dp(n, vector<ll>(m + 1, Inf));
	dp[0][v[0]] = c[0];
	dp[0][0] = 0;
	rep(i, n - 1)
	{
		rep(j,m+1){
			if (j - v[i+1] >= 0)
				dp[i + 1][j] = min(dp[i][j], dp[i][j - v[i + 1]] + c[i + 1]);
			else
				dp[i + 1][j] = dp[i][j];
		}
	}
	ll ans = 0;
	for (int i = m; i >= 0; i--)
	{
		if (dp[n - 1][i] <= w)
		{
			ans = i;
			break;
		}
	}
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 79360
import java.util.*;

public class Main{
    void solve(){
        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt();
        int[] l = new int[n];
        for(int i = 0; i < n; i++) l[i] = scan.nextInt();
        Arrays.sort(l);
        int out = 0;
        for(int i = 0; i < n - 2; i++){
            for(int j = i + 1; j < n - 1; j++){
                for(int k = j + 1; k < n; k++){
                    if(l[k] < l[i] + l[j]) out++;
                    else break;
                }
            }
        }
        System.out.println(out);
        scan.close();
    }

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


Measured memory_bytes: 40080