akhauriyash/Code-Regression huggingface dataset:
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

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

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

int main(){
    int K;
    cin >> K;
    if(K % 2 == 1) {
        cout << (K / 2) * (K / 2 + 1) << endl;
    } else {
        cout << (K / 2) * (K / 2) << endl;
    }
    return 0;
}


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

class Program
{
    static void Main(string[] args)
    {
        while (true)
        {
            string s = io.r<string>();
            if (s == "-") { break; }
            int n = io.r<int>();
            int c = 0;
            for (int i = 0; i < n; i++)
            {
                c += io.r<int>();
            }
            c %= s.Count();
            io.w(s.Substring(c, s.Count() - c) + s.Substring(0, c));
        }
        io.wflush();
    }
}

namespace LIB
{
    public class io
    {
        private const int WMAX = 1000;
        private static StringBuilder S = new StringBuilder();
        public static T r<T>() { return util.parse<T>(r()); }
        public static T[] r<T>(char s = ' ') { return r().Split(s).Select(util.parse<T>).ToArray(); }
        public static T[] r<T>(int l) { T[] r = new T[l]; for (int i = 0; i < l; i++) { r[i] = r<T>(); } return r; }
        public static T[][] r<T>(int l, char s = ' ') { T[][] r = new T[l][]; for (int i = 0; i < l; i++) { r[i] = r<T>(s); } return r; }
        private static string r() { return Console.ReadLine(); }
        public static void w(object v, bool lf = true) { S.Append(util.parse<string>(v)); if (lf == true) { S.Append('\n'); } if (S.Length >= WMAX) { wflush(); } }
        public static void wflush() { Console.Write(S.ToString()); S.Length = 0; }
    }
    public class util
    {
        public static T parse<T>(object value) { return (T)(Convert.ChangeType(value, typeof(T))); }
    }
    public class memo<Key, Result>
    {
        private Dictionary<Key, Result> R;
        public memo() { R = new Dictionary<Key, Result>(); }
        public Result exec(Key k, Func<Key, Result> f) { Result r; if (R.ContainsKey(k)) { r = R[k]; } else { r = f(k); R.Add(k, r); } return r; }
    }
}

Measured memory_bytes: 10256
#include<bits/stdc++.h>
using namespace std;
#define int long long

int32_t main()
{
    int n;
    cin >> n;
    int a[n], b[n], c[n];
    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; i++) cin >> c[i];
    sort(a, a + n);
    sort(b, b + n);
    sort(c, c + n);

    int amo[n];
    for (int i = 0; i < n; i++) {
        int k = lower_bound(c, c + n, b[i] + 1) - c;
        amo[i] = n - k;
    }
    int suf[n];
    suf[n - 1] = amo[n - 1];
    for (int i = n - 2; i >= 0; i--) {
        suf[i] = suf[i + 1] + amo[i];
    }
    int ans = 0;
    for (int i = 0; i < n; i++) {
        int k = lower_bound(b, b + n, a[i] + 1) - b;
        if (k == n) break;
        ans += suf[k];
    }
    cout << ans << "\n";
}


Measured memory_bytes: 7512
n = int(input())
s = list(input())

def search(s, c, left):
  for idx in range(left, len(s)):
    if s[idx] == c:
      return idx
  return -1

total = 0
for keta1 in range(10):
  first_keta1 = search(s, str(keta1), 0)
  if first_keta1 == -1 or first_keta1 >= n-2:
    continue
  for keta2 in range(10):
    first_keta2 = search(s, str(keta2), first_keta1 + 1)
    if first_keta2 == -1 or first_keta2 >= n-1:
      continue
    for keta3 in range(10):
      first_keta3 = search(s, str(keta3), first_keta2 + 1)
      if first_keta3 != -1:
        total += 1
print(total)

Measured memory_bytes: 40816
#![allow(non_snake_case, unused_imports)]

// Input
macro_rules! input { (source = $s:expr, $($r:tt)*) => { let mut iter = $s.split_whitespace(); let mut next = || { iter.next().unwrap() }; input_inner!{next, $($r)*} }; ($($r:tt)*) => { let stdin = std::io::stdin(); let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock())); let mut next = move || -> String{ bytes.by_ref().map(|r|r.unwrap() as char).skip_while(|c|c.is_whitespace()).take_while(|c|!c.is_whitespace()).collect() }; input_inner!{next, $($r)*} }; }
macro_rules! input_inner { ($next:expr) => {}; ($next:expr, ) => {}; ($next:expr, $var:ident : $t:tt $($r:tt)*) => { let $var = read_value!($next, $t); input_inner!{$next $($r)*} };}
macro_rules! read_value { ($next:expr, ( $($t:tt),* )) => { ( $(read_value!($next, $t)),* ) }; ($next:expr, [ $t:tt ; $len:expr ]) => { (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>() }; ($next:expr, chars) => { read_value!($next, String).chars().collect::<Vec<char>>() }; ($next:expr, bytes) => { read_value!($next, String).into_bytes() }; ($next:expr, usize1) => { read_value!($next, usize) - 1 }; ($next:expr, $t:ty) => { $next().parse::<$t>().expect("Parse error") }; }

// Module
use std::cmp::{min,max};
use std::collections::{HashSet,BTreeMap,VecDeque};

// Functions

// Main
fn main(){
    input!{
        S: chars,
    }
    let mut ans:u64 = 0;
    let mut white:u64 = 0;
    let N = S.len();
    for i in 0..N{
        if S[N-1-i]=='B'{
            ans += white;
        }else{
            white += 1;
        }
    }

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


Measured memory_bytes: 4352
#include<iostream>
#include<stdio.h>
using namespace std;
typedef long long ll;
ll  a[1111111];
int main()
{
	ll n,k,q,x;
	cin>>n>>k>>q;
	for(int i =0;i<n;++i)
	{
		a[i] = k;
	 } 
	 
	 for(ll i =0;i<q;++i)
	 {
	 	
	 	scanf("%lld",&x);
	 	a[x-1]++;
	 }
	 
	 for(ll i=0;i<n;++i)
	 {
	 	if(a[i]-q>0)
	 		cout<<"Yes"<<endl;
	 	else	
		 	cout<<"No"<<endl; 
	 }
	 return 0;
 } 

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

#ifdef DEBUG
#include "../include/debug.hpp"
#else
#define debug(...) 42
#endif

const int MAX = 36;
long long pow2[40];

void init() {
    pow2[0] = 1;
    for (int i=1; i<=MAX; ++i) {
        pow2[i] = pow2[i-1] * 2;
    }
}

string solve(long long X, long long Y, bool odd) {
    string s = "";
    for (int i=MAX; i>=0; --i) {
        long long parm = odd ? pow2[i] : pow2[max(0, i-1)];
        long long ph = odd ? parm-1 : (i == 0 ? 0 : parm);

        if (abs(X+parm) + abs(Y) <= ph) {
            X += parm;
            s = "L" + s;
        } else if (abs(X-parm) + abs(Y) <= ph) {
            X -= parm;
            s = "R" + s;
        } else if (abs(X) + abs(Y+parm) <= ph) {
            Y += parm;
            s = "D" + s;
        } else if (abs(X) + abs(Y-parm) <= ph) {
            Y -= parm;
            s = "U" + s;
        }
    }
    return s;
}

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

    init();

    int N;
    cin >> N;

    vector<int> X(N), Y(N);
    int odd = 0, even = 0;
    for (int i=0; i<N; ++i) {
        cin >> X[i] >> Y[i];
        if (abs(X[i]+Y[i]) % 2 == 0) {
            even ++;
        } else {
            odd ++;
        }
    }

    if (even > 0 && odd > 0) {
        cout << -1 << endl;
        return 0;
    }

    vector<long long> v;
    for (int i=0; i<=MAX; ++i) {
        if (odd > 0) {
            v.push_back(pow2[i]);
        } else {
            v.push_back(pow2[max(0, i-1)]);
        }
    }

    cout << MAX+1 << endl;
    for (int i=0; i<=MAX; ++i) {
        cout << v[i] << endl;
    }

    for (int i=0; i<N; ++i) {
        string s = solve(X[i], Y[i], odd > 0);
        cout << s << endl;

        long long x = 0, y = 0;
        for (int j=0; j<s.size(); ++j) {
            if (s[j] == 'L') x -= v[j];
            if (s[j] == 'R') x += v[j];
            if (s[j] == 'U') y += v[j];
            if (s[j] == 'D') y -= v[j];
        }
    }

    return 0;
}

Measured memory_bytes: 256
//高知能系Vtuberの高井茅乃です。
//Twitter: https://twitter.com/takaichino
//YouTube: https://www.youtube.com/channel/UCTOxnI3eOI_o1HRgzq-LEZw

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

#define INF 1999999999
#define REP(i,n) for(int i=0;i<n;i++)
#define REP1(i,n) for(int i=1;i<=n;i++)
#define MODA 1000000007 

int main() {
    ll ans = 0;
    int tmp;
    int n;
    cin >> n;
    REP1(i, n){
        if(i%3 != 0 && i%5 !=0) ans += (ll) i;
    }
    cout << ans << endl;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin >> N;
  if(pow(10,0) <= N && N < pow(10,1)){
  	cout << N << endl;
  }else if(pow(10,1) <= N && N < pow(10,2)){
  	cout << 9 << endl;
  }else if(pow(10,2) <= N && N < pow(10,3)){
  	cout << 9 + (N - 100 + 1) << endl; 
  }else if(pow(10,3) <= N && N < pow(10,4)){
  	cout << 9 + 900 << endl;
  }else if(pow(10,4) <= N && N < pow(10,5)){
  	cout << 9 + 900 + (N - 10000 + 1) << endl;
  }else if(pow(10,5) <= N && N < pow(10,6)){
  	cout << 9 + 900 + 90000 << endl; 
  }
  
}

Measured memory_bytes: 256
from sys import setrecursionlimit, getrecursionlimit
setrecursionlimit(getrecursionlimit()*10000)
from collections import defaultdict
g = defaultdict(list)
visited = defaultdict(bool)
N = int(input())
ans = [0] * N

def dfs(v, d=0):
    if visited[v]:
        return
    visited[v] = True
    if d % 2:
        ans[v-1] = 1
    for c,w in g[v]:
        dfs(c, d+w)

for j in range(N-1):
    u,v,w = map(int, input().split())
    g[u].append((v, w))
    g[v].append((u, w))

dfs(1)

for a in ans:
    print(a)

Measured memory_bytes: 102552
from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt
from collections import deque
from bisect import bisect, bisect_left, bisect_right
from string import ascii_lowercase
from functools import lru_cache
import sys
sys.setrecursionlimit(10000)
INF = float("inf")
YES, Yes, yes, NO, No, no = "YES", "Yes", "yes", "NO", "No", "no"
dy4, dx4 = [0, 1, 0, -1], [1, 0, -1, 0]


def inside(y, x, H, W):
    return 0 <= y < H and 0 <= x < W


def ceil(a, b):
    return (a + b - 1) // b


def main():
    N = int(input())
    T = list(map(int, input().split()))
    V = list(map(int, input().split()))
    base = 2
    end = base * sum(T)

    H = [INF] * (end + 10)
    now = 0
    for i, t in enumerate(T):
        for j in range(now, (now + t * base) + 1):
            H[j] = min(H[j], V[i])
        now = now + t * base

    H[0] = 0.0
    H[end] = 0.0
    H[end + 1] = 0.0
    for i in range(end + 1):
        H[i + 1] = min(H[i + 1], H[i] + 1 / base)
    for i in range(end, 0, -1):
        H[i - 1] = min(H[i - 1], H[i] + 1 / base)

    # for i in range(len(H)):
    #     print(i, H[i])
    ans = 0
    pre_i, pre_mode = 0, 1
    for i in range(end + 1):
        if H[i] < H[i + 1]:
            mode = 0
        elif H[i] == H[i + 1]:
            mode = 1
        else:
            mode = 2

        if mode != pre_mode:
            # print(pre_i, i, (H[pre_i] + H[i]) * ((i - pre_i) / base) * (1/2))
            ans += (H[pre_i] + H[i]) * ((i - pre_i) / base) * (1/2)
            pre_i, pre_mode = i, mode

    print(ans)


if __name__ == '__main__':
    main()


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

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int, int> ii;
typedef pair<ll, int> li;
typedef pair<int, ll> il;
typedef vector<ii> vii;
typedef vector<il> vil;
typedef vector<li> vli;

#define ff first
#define PI acos(-1.0)
#define ss second
#define pb push_back
#define mp make_pair
#define sz size()
#define MOD 1000000007
#define MOD1 1000000005
int dx8[] = {0, 0, 1, 1, 1, -1, -1, -1};
int dy8[] = {1,-1, 1, -1, 0, 0, -1, 1};
int dx4[] = {0, 0, 1, 1};
int dy4[] = {1, -1, 1, -1};
//#define fio() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)

int main()
{
    #ifndef ONLINE_JUDGE
    freopen ("in.txt", "r", stdin);
    freopen ("out.txt", "w", stdout);
    #endif
    int red, green, blue, k, c=0;
    cin>>red>>green>>blue>>k;
    if(green>red && blue>green)cout<<"Yes"<<endl;
    else {
        while(green<=red){
            green*=2;
            c++;
        }
        while(blue<=green){
            blue*=2;
            c++;
        }
        if(c<=k)cout<<"Yes"<<endl;
        else cout<<"No"<<endl;
    }
    return 0;
}


Measured memory_bytes: 3632
N, K = map(int, input().split())
S = [input().split() for _ in range(K*2)]
new_list = []
for i in range(5):
    S.append([])
S.append([])
for i in range(1,len(S)-2,2):
    for j in S[i]:
        new_list.append(j)

new_list = set(new_list)
print(N - len(new_list))


Measured memory_bytes: 9528
#include <bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define REP(i,a,b) for(int i=a; i<=b; i++)
using namespace std;

typedef long long int ll;

int main() {
    int a;
    cin >> a;
    int ans=(a*360/__gcd(a,360))/a;
    cout << ans;
    return 0;
}


Measured memory_bytes: 3624
#include <stdio.h>
int main(){
  int n,r,p,c,i,j,k,l,nh[51],s[51];
  while(1){
    scanf("%d%d",&n,&r);
    if(n==0&&r==0) break;
 
    for(i=n;i>=1;i--){
      nh[n-i+1]=i;
    }
  
    for(i=0;i<r;i++){
      scanf("%d%d",&p,&c);
      for(j=p;j<=p+c-1;j++){
        s[j]=nh[j];
      }
    l=0;
      for(j=1;j<=c;j++){
    for(k=p-1+l;k>=1+l;k--){
          nh[k+1]=nh[k];
    }
        l++;
      }
     
      for(j=p;j<=p+c-1;j++){
        nh[j-p+1]=s[j];
      }
    }
 
    printf("%d\n",nh[1]);
  }
    return 0;
}

Measured memory_bytes: 1028
using System;
using System.Collections.Generic;
using System.Linq;

class J
{
	static int[] Read() => Console.ReadLine().Split().Select(int.Parse).ToArray();
	static void Main()
	{
		var r = new List<long>();
		var h = Read();
		var n = h[0];
		var a = Read();

		var st = new ST_Max(n + 2);
		for (int i = 0; i < n; i++)
			st.Set(i + 1, a[i]);
		st.Set(n + 1, 1 << 30);

		for (int k = 0; k < h[1]; k++)
		{
			var q = Read();
			if (q[0] == 1)
				st.Set(q[1], q[2]);
			else if (q[0] == 2)
				r.Add(st.Submax(q[1], q[2] + 1));
			else
				r.Add(st.FirstArg(q[1], n + 2, q[2]));
		}
		Console.WriteLine(string.Join("\n", r));
	}
}

class ST
{
	public struct Node
	{
		public int k, i;
		public Node(int _k, int _i) { k = _k; i = _i; }

		public Node Parent => new Node(k - 1, i >> 1);
		public Node Child0 => new Node(k + 1, i << 1);
		public Node Child1 => new Node(k + 1, (i << 1) + 1);
	}

	protected int kMax;
	List<long[]> vs = new List<long[]> { new long[1] };

	public ST(int n)
	{
		for (int c = 1; c < n; vs.Add(new long[c <<= 1])) ;
		kMax = vs.Count - 1;
	}

	public virtual long this[int i] => vs[kMax][i];
	public long this[Node n]
	{
		get { return vs[n.k][n.i]; }
		set { vs[n.k][n.i] = value; }
	}

	public void ForLevels(int i, Action<Node> action)
	{
		for (int k = kMax; k >= 0; --k, i >>= 1) action(new Node(k, i));
	}

	public void ForRange(int minIn, int maxEx, Action<Node> action)
	{
		for (int k = kMax, f = 1; k >= 0 && minIn < maxEx; --k, f <<= 1)
		{
			if ((minIn & f) != 0) action(new Node(k, (minIn += f) / f - 1));
			if ((maxEx & f) != 0) action(new Node(k, (maxEx -= f) / f));
		}
	}
}

class ST_Max : ST
{
	public ST_Max(int n) : base(n) { }

	public void Set(int i, long v) => ForLevels(i, n => this[n] = n.k == kMax ? v : Math.Max(this[n.Child0], this[n.Child1]));

	public long Submax(int minIn, int maxEx)
	{
		var r = long.MinValue;
		ForRange(minIn, maxEx, n => r = Math.Max(r, this[n]));
		return r;
	}

	// v 以上の値を持つインデックス
	public int FirstArg(int minIn, int maxEx, long v)
	{
		var mn = new Node(kMax, 1 << 30);
		ForRange(minIn, maxEx, n =>
		{
			if (this[n] >= v && n.i << (kMax - n.k) < mn.i << (kMax - mn.k)) mn = n;
		});

		while (mn.k < kMax) mn = this[mn.Child0] >= v ? mn.Child0 : mn.Child1;
		return mn.i;
	}
}


Measured memory_bytes: 67180
#include <iostream>
#include <string>
#include <limits.h>
using namespace std;
int main(void){
    int n, a[100010], rem[100010];
    long long ans = 0;
    cin >> n;
    a[n + 1] = 0;
    for (int i = 1; i <= n + 1; i++) {
        cin >> a[i];
        ans += a[i] / 2;
        rem[i] = a[i] % 2;
    }
    
    int j = 1;
    while (j <= n) {
        if (rem[j] == 1) {
            int k = j + 1;
            while (rem[k] != 1 && k < n) {
                if (a[k] == 0) {
                    break;
                }
                else k++;
            }
            if (rem[k] == 1) {
                ans++;
                j = k + 1;
            }
            else j = k;
        }
        else j++;
    }
    
    cout << ans;
    return 0;
}


Measured memory_bytes: 1024
from collections import Counter

N=int(input())
v=list(map(int,input().split()))

v1=v[::2]
n1=len(set(v1))
v2=v[1::2]
n2=len(set(v2))

cnt1=Counter(v1)
cnt2=Counter(v2)

cnt1=cnt1.most_common()
cnt2=cnt2.most_common()

if cnt1[0][0]!=cnt2[0][0]:
  print(N-cnt1[0][1]-cnt2[0][1])
else:
  if n1==1 and n2==1:
    print(N-cnt1[0][1])
  elif n1==1:
    print(N-cnt1[0][1]-cnt2[1][1])
  elif n2==1:
    print(N-cnt1[1][1]-cnt2[0][1])
  else:
    print(N-max(cnt1[0][1]+cnt2[1][1],cnt1[1][1]+cnt2[0][1]))

Measured memory_bytes: 20692
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define Rep(i,a,b) for(int i=a;i<b;i++)
#define REP(i,a,b) for(int i=a;i<=b;i++)
#define rev(i,n) for(int i=n-1;i>=0;i--)
#define vi vector<int>
#define pb push_back
#define pi pair<int,int>
#define vp vector<pair<int,int>>
#define mp make_pair
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define MEMSET(a) memset(a,0,sizeof(a))
#define inf (1ll<<60)
#define Yes(f) cout<<(f?"Yes":"No")<<endl
#define yes(f) cout<<(f?"yes":"no")<<endl
#define YES(f) cout<<(f?"YES":"NO")<<endl

using namespace std;

const int mod=1e9+7;

void run();

void init() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout<<fixed<<setprecision(12);
}

signed main(){
    init();
    run();
    return 0;
}

int c[52][52];
void pascal(){
  Rep(i,1,51){
    c[i][0]=c[i][i]=1;
  }
  REP(i,2,50){
    Rep(j,1,i){
      c[i][j]=c[i-1][j-1]+c[i-1][j];
    }
  }
}

void run(){
  int n,a,b;
  pascal();
  cin>>n>>a>>b;
  vi v(n);
  rep(i,n)cin>>v[i];
  sort(all(v));
  reverse(all(v));
  int av=0;
  rep(i,a)av+=v[i];
  cout<<(double)av/a<<endl;
  int ans=0;
  int cnt=0;
  int use=0;
  rep(i,n){
    if(v[i]!=v[a-1])continue;
    if(i<a)use++;
    cnt++;
  }
  if(v[0]!=v[a-1]){
    cout<<c[cnt][use]<<endl;
    return;
  }
  REP(i,a,min(b,cnt)){
    ans+=c[cnt][i];
  }
  cout<<ans<<endl;
}

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

int main(void){
    string a;
    cin >> a;
    vector<long long> cnt(30);
    for(int i=0;i<30;++i){cnt[i] = 0;}
    for(int i=0;i<a.size();++i){
        ++cnt[a[i]-'a'];
    }
    long long kazu = 0;
    for(int i='a';i<='z';++i){
        kazu += (cnt[i-'a']*(cnt[i-'a']-1))/2;
    }
    long long ans = ((a.size()*(a.size()-1))/2 - kazu + 1);
    cout << ans << endl;
}

Measured memory_bytes: 640
#include<iostream>
using namespace std;
int n,x,m[100],minn=1001,ans;
int main(void){
	cin>>n>>x;
	for(int i=0;i<n;i++){
		cin>>m[i];
		minn=min(minn,m[i]);
		x-=m[i];
	}
	cout<<n+x/minn;
	return 0;
}

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

#define ld long double
#define ll long long
#define ALL(a)  (a).begin(),(a).end()
#define ALLR(a)  (a).rbegin(),(a).rend()
#define spa << " " <<
#define MP make_pair
ll MOD = 1e9+7;
//ll MOD = 998244353;
ll INF = 1e18;
void chmin(ll &a,ll b){if(a>b)a=b;}
void chmax(ll &a,ll b){if(a<b)a=b;}
void pmod(ll &a,ll b){a=(a+b)%MOD;}
void qmod(ll &a,ll b){a=(a*b)%MOD;}
void ans1(bool x){if(x) cout<<"Yes"<<endl;else cout<<"No"<<endl;}
void ans2(bool x){if(x) cout<<"YES"<<endl;else cout<<"NO"<<endl;}
void ans3(bool x){if(x) cout<<"Yay!"<<endl;else cout<<":("<<endl;}
void ans(bool x,ll y,ll z){if(x)cout<<y<<endl;else cout<<z<<endl;}
void anss(bool x,string y,string z){if(x)cout<<y<<endl;else cout<<z<<endl;}   
ll gcd(ll x,ll y){ll r;while((r=x%y)!=0){x=y;y=r;}return y;}

int main(){
  ll i,j,o;
  ll res=0,res1=0,res2=INF,buf=0,buf1=0,buf2=0,buf3=0,buf4=0;
  bool judge = true;
  ll n,m;cin>>n>>m;
  cout<<(n-1)*(m-1)<<endl;
  return 0;
}

Measured memory_bytes: 256
//CODEFORCES:-
//coded by AMAN BHARTI NIT PATNA
//ALL RIGHTS RESERVED
//ECE 2K18

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

//#define home
#define TASK "soln"
#define eprintf(...) fprintf(stderr, __VA_ARGS__),fflush(stderr)
#define pb push_back
#define ll long long int
#define br cout<<endl;
#define fo for(int i=0;i<n;i++)
#define foo for(int i=1;i<=n;i++)
#define mod 1000000007

ll dp[1000][100009];

ll cal(ll w[],ll v[],ll n,ll total){
    if(n==0||w==0)return 0;

    if(dp[n][total]!=-1)return dp[n][total];

    if(w[n]>total)return dp[n][total] = cal(w,v,n-1,total);

    return dp[n][total] = max(v[n]+cal(w,v,n-1,total-w[n]),cal(w,v,n-1,total));
}

void solve(){
    memset(dp,-1,sizeof(dp));
    ll n,w;
    cin>>n>>w;

    ll a[n+1],v[n+1];
    foo{cin>>a[i]>>v[i];}


    cout<<cal(a,v,n,w);

    br;    
}

int main(){
	#ifdef home
        assert(freopen(TASK".in","r",stdin));
        assert(freopen(TASK".out","w",stdout));
    #endif

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

    // int t;
    // cin>>t;
    // while(t-->0)
    solve();

    #ifdef home
        eprintf("Time: %d ms\n", (int)(clock() * 1000. / CLOCKS_PER_SEC));
    #endif

    return 0;
}

Measured memory_bytes: 784968
import java.util.Scanner;


public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt(); //??\??????????£??????°
		Integer[][][] building = new Integer[4][3][10];		
		int b;					//b?£?
		int f;					//f???
		int r;					//r???????????¨?±?
		int v;					//v?????\?±?
		
		//?????????
		for (int i = 0; i < 4; i++) {
			for (int j = 0; j < 3; j++) {
				for (int j2 = 0; j2 < 10; j2++) {
					building[i][j][j2]=0;
				}
			}
		}
		
		//??\???
		for (int i = 0; i < n; i++) {
			b=sc.nextInt()-1;
			f=sc.nextInt()-1;
			r=sc.nextInt()-1;
			v=sc.nextInt();
			
			building[b][f][r] += v;
		}
		
		for (int i = 0; i < 4; i++) {
			for (int j = 0; j < 3; j++) {
				for (int j2 = 0; j2 < 10; j2++) {
					System.out.print(" "+building[i][j][j2]);
				}
				//??????
				System.out.println();
			}
			//????£??????????????????????
			if(i!=3){
			System.out.println("####################");
			}
		}
	}
}

Measured memory_bytes: 21052
import bisect
import heapq
import itertools
import math
import operator
import os
import re
import string
import sys
from collections import Counter, deque, defaultdict
from copy import deepcopy
from decimal import Decimal
from fractions import gcd
from functools import lru_cache, reduce
from operator import itemgetter, mul, add, xor

import numpy as np

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(2147483647)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7

N = int(sys.stdin.readline())
B = list(map(int, sys.stdin.readline().split()))

ans = 0
for a, b in zip(B, B[1:]):
    ans += min(a, b)
print(ans + B[0] + B[-1])


Measured memory_bytes: 22968
#include <stdio.h>

#define N_MAX 1001

int main(){
  int n, a[N_MAX], min, m, i, j;

  while(1){
    scanf("%d", &n);
    if(n == 0) break;

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

    min = (a[0] - a[1]);
    if(min < 0) min *= -1;
    for(i = 0; i < n-1; i++){
      for(j = i+1; j < n; j++){
        m = (a[i] - a[j]);
        if(m < 0) m *= -1;
        if(m < min) min = m;
      }
    }
    printf("%d\n", min);
  }

  return 0;

}



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

const int MOD = 1000000007; // 今回使う余り
const int MAX = 100001;
const int64_t MIN = 0;
int main() {
	string S;
	cin >> S;
	int l = S.size();
	static int64_t three[MAX], A[MAX], C[MAX], Q[MAX];
	A[0] = S[0] == 'A' ? 1 : 0;
	C[0] = S[0] == 'C' ? 1 : 0;
	Q[0] = S[0] == '?' ? 1 : 0;
	for (int i = 0;i < l;i ++) {
		A[i] = A[i - 1] + (S[i] == 'A' ? 1 : 0);
		C[i] = C[i - 1] + (S[i] == 'C' ? 1 : 0);
		Q[i] = Q[i - 1] + (S[i] == '?' ? 1 : 0);
	}
	three[0] = 1;
	for (int i = 1;i < l;i ++) {
		three[i] = three[i - 1] * 3 % MOD;
	}

	int64_t ans = 0;
	for (int i = 1;i < l - 1;i ++) {
		if (S[i] == 'B' || S[i] == '?') {
			ans += A[i] * (C[l - 1] - C[i]) % MOD * three[max(MIN, Q[l - 1] - (S[i] == '?' ? 1 : 0))] % MOD; // AとCを選ぶ場合
			ans += Q[i - 1] * (C[l - 1] - C[i]) % MOD * three[max(MIN, Q[l - 1] - (S[i] == '?' ? 2 : 1))] % MOD; // ?とCを選ぶ場合
			ans += A[i] * (Q[l - 1] - Q[i]) % MOD * three[max(MIN, Q[l - 1] - (S[i] == '?' ? 2 : 1))] % MOD; // Aと?を選ぶ場合
			ans += Q[i - 1] * (Q[l - 1] - Q[i]) % MOD * three[max(MIN, Q[l - 1] - (S[i] == '?' ? 3 : 2))] % MOD; // ?と?を選ぶ場合
			ans %= MOD;
		}
	}
	cout << ans;
	return 0;
}
/*
31536000のコメント解説欄
ここテンプレで用意してるから、A問題とかだとこの先空欄の危険あり
また、コンテスト後に https://31536000.hatenablog.com/ で解説していると思うので、良かったら読んでねー

あるBについて着目すると、そのBを用いるABC数の数は自身の左側のAの数と右側のCの数の積に等しい
よって、各Bについて考えていくと良い
ここで?については自身の左側を全てA、右側を全てCと仮定して考えていくと楽
なお、ここで注意点として、用いた?以外は何を置いても良い
つまり、例えばA??CについてA?BCにすると?は3通り、AABCにすると更に1通りある
同様にAB?Cも?が3通り、ABCCで1通りなので
つまり、AAAA??????BCだと、Aが4個→4*3^6+各?を用いる→6*3^(6-1)となる
AA?B?CC

*/

Measured memory_bytes: 3584
n = int(input())
ball = []
for i in range(n):
    ball.append(list(map(int, input().split())))

ans = 1000
for i in range(n):
    for j in range(n):
        if i == j:
            continue
        temp = 0
        x0, y0 = ball[i]
        x1, y1 = ball[j]
        p, q = x1-x0, y1-y0
        used = [False]*(n)
        for k in range(n):
            if not used[k]:
                temp += 1
                x0, y0 = ball[k]
                used[k] = True

                x, y = x0, y0
                while True:
                    f = 0
                    for l in range(n):
                        if used[l]:
                            continue
                        if x + p == ball[l][0] and y + q == ball[l][1]:
                            used[l] = True
                            x += p
                            y += q
                            f = 1
                    if f == 0:
                        break

                x, y = x0, y0
                while True:
                    f = 0
                    for l in range(n):
                        if used[l]:
                            continue
                        if x - p == ball[l][0] and y - q == ball[l][1]:
                            used[l] = True
                            x -= p
                            y -= q
                            f = 1
                    if f == 0:
                        break

        ans = min(ans, temp)

if n == 1:
    print(1)
else:
    print(ans)


Measured memory_bytes: 47452
// #define _CRT_SECURE_NO_WARNINGS
// #define _USE_MATH_DEFINES	// M_PI=3.1415...
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <cmath>
#include <cstdlib>
#include <functional>
#include <locale>
#include <cctype>
#include <sstream>
#include <iomanip>	// 20桁出力 cout << setprecision(20) << double;
#include <queue>
#include <bitset>	// bitset<8> bs1(131uL); // 10000011 bs1[0]は1 01stringからビット集合生成可
#include <numeric>
#include <random>
#include <climits>  // A/Bを計算するときA==LLONG_MIN && B==-1のみ(1ull<<63)で代用
using namespace std;

typedef long long LL;
typedef pair<LL, LL> P;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<LL> VL;
typedef vector<VL> VVL;				// VVL v(100,VL(100,0));
typedef vector<pair<LL, LL> > VP;
typedef vector<string> VS;
typedef map<int, int> MAPII;
typedef multimap<int, char, greater<int> > MuMAPIC;
typedef multimap<int, string, greater<int> > MuMIS;
typedef pair<LL, pair<P, P> > PP;

#define INF 999999999999999997		// 少し加算したらオーバーフローする
#define MP make_pair
#define FAST_IO  cin.tie(0); ios::sync_with_stdio(false);
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define FORL(i,a,b) for(LL i=(a);i<(b);i++)
#define FOR_REV(i,a,b) for(int i=(a);i>=(b);i--)
#define foreach_it(type,it,c) for(type::iterator it=c.begin(),c_end=c.end();it!=c_end;++it)
#define FOR_ITR(d) for(auto itr=d.begin(),d_end=d.end();itr!=d_end;++itr)	// C++11
#define O(s) cout<<s<<endl;

#define DUMP_VVI(b) if(dbgF){FOR(i,0,b.size()){FOR(j,0,b[i].size())printf("%d ",b[i][j]);puts("");}}
#define D_OUT(str,value) if(dbgF){cout<<str<<" : "<<value<<endl;}

template<class T>T IN() { T d; cin >> d; return d; }

LL gcd(LL a, LL b) { return (b > 0) ? gcd(b, a%b) : a; } // 最大公約数（Greatest Common Divisor）
LL lcm(LL a, LL b) { return a / gcd(a, b) * b; } // 最小公倍数（Least Common Multiple）
bool uruu(LL Y) { return (((Y % 4 == 0 && Y % 100 != 0) || Y % 400 == 0) ? true : false); } // うるう年判定
string Replace(string S, string from, string to) { auto p = S.find(from); while (p != string::npos) { S.replace(p, from.size(), to); p = S.find(from, p + to.size()); }return S; }

//二項係数 nCk mod pを求める
const LL MAX = 510000, p = 998244353; LL fac[MAX], finv[MAX], inv[MAX];
/* 前処理 */void COM_init() { fac[0] = fac[1] = 1; finv[0] = finv[1] = 1; inv[1] = 1; FOR(i, 2, MAX) { fac[i] = fac[i - 1] * i % p; inv[i] = p - inv[p%i] * (p / i) % p; finv[i] = finv[i - 1] * inv[i] % p; } }
/* 主処理 */LL COM(int n, int k) { if (n < k) return 0; if (n < 0 || k < 0) return 0; return fac[n] * (finv[k] * finv[n - k] % p) % p; }

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

// -------------------------------------------------------------------------------

int main() {
	FAST_IO;
	bool dbgF = true; // for D_OUT(str, value)  ... cout<< str <<" : "<< value <<endl;

	LL K, N;
	cin >> N >> K;
	VL A;
	LL ans = 0;
	FOR(i, 0, N)
		A.push_back(IN<LL>());

	ans = ceil((double)(N - 1) / (K - 1));


	O(ans);

	return 0;
}

Measured memory_bytes: 1400
#include <iostream>
#include <algorithm>

using namespace std;

typedef long long ll;

ll gcd(ll x, ll y) {
    if (x > y) {
        ll tmp = x;
        x = y;
        y = tmp;
    }
    if (y % x == 0) {
        return x;
    }
    else {
        return gcd(x, y % x);
    }
}

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

int main() {
    ll n, *t;   cin >> n;   t = new ll[n];
    for (ll i = 0; i < n; i++)
        cin >> t[i];
    
    ll ans = 1LL;
    for (ll i = 0; i < n; i++) {
        ans = lcm(ans, t[i]);
    }

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

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS

#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <stack>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <utility>
#include <ctime>
#include <map>
#include <set>
#include <unordered_set>

using namespace std;

#define endl "\n"
#define X first
#define Y second
#define Z third
#define mp make_pair
#define mt make_triple

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;

const ld PI = 3.141592653589793;
const ld E = 2.71828182845904523;
const ll LLINF = 4000000009000000099;
const ll INF = 1009000099;
const ll MOD7 = 1000000007;
const ll MOD9 = 1000000009;

template<class A, class B, class C> struct triple { A first; B second; C third; triple(A, B, C); triple(); };
template<class A, class B, class C> triple<A, B, C>::triple(A a, B b, C c) { first = a; second = b; third = c; }
template<class A, class B, class C> triple<A, B, C>::triple() { }
template<class A, class B, class C> triple<A, B, C> make_triple(A a, B b, C c) { triple<A, B, C> t(a, b, c); return t; }
template<class A, class B, class C> bool operator<(triple<A, B, C> a, triple<A, B, C> b) { if (a.first != b.first) return a.first < b.first; if (a.second != b.second) return a.second < b.second; if (a.third != b.third) return a.third < b.third; }
template<class T> T inline sqr(T a) { return a * a; }

ll bpow(ll a, ll d, ll mod) { if (d == 0) return 1; ll t = bpow(a, d / 2, mod); t = (t * t) % mod; if (d & 1) t = (t * a) % mod; return t; }
ll bpow(ll a, ll d) { if (d == 0) return 1; ll t = bpow(a, d / 2); t = (t * t); if (d & 1) t = (t * a); return t; }
ll gcd(ll a, ll b) { while (a && b) if (a > b) a %= b; else b %= a; return a + b; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
ll C(ll n, ll k) { ll res = 1; for (int i = 1; i <= k; ++i) res = res * (n - k + i) / i; return res; }
ll C(ll n, ll k, ll mod) { ll u = 1, d = 1; for (int i = 2; i <= n; ++i) u = (u * i) % mod; int x = max(k, n - k), z = min(k, n - k); for (int i = 2; i <= x; ++i) { d = (d * i) % mod; if (i <= z) d = (d * i) % mod; } d = bpow(d, mod - 2, mod); ll res = (u * d) % mod; return res; }

bool cmp(string a, string b)
{
	for (int i = 0; i < min(a.length(), b.length()); ++i)
		if (a[i] != b[i])
			return a[i] < b[i];

	return a.length() < b.length();
}

void solve()
{
	string s; cin >> s;
	int n = s.length();
	int k; cin >> k;
	set<string> p;
	vector<string> v;
	string tmp = s;
	sort(tmp.begin(), tmp.end());

	for (int i = 0; i < n && p.size() <= 5; ++i)
		if (!i || tmp[i] != tmp[i - 1])
		{
			
			for (int j = 0; j < n; ++j)
				if (s[j] == tmp[i])
				{
					string cur = "";
					for (int k = j; k < n && k - j < 7; ++k)
					{
						cur += s[k];
						p.insert(cur);
					}
				}
		}

	for (auto it = p.begin(); it != p.end(); ++it)
		v.push_back(*it);

	sort(v.begin(), v.end(), cmp);

	cout << v[k - 1];
}


int main() {
	ios::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
#ifdef _DEBUG
	freopen("in.txt", "r", stdin);
#else
#endif
	solve();
	return 0;
}

Measured memory_bytes: 384
{-# LANGUAGE TypeApplications #-}
module Main where
import qualified Data.ByteString.Char8         as BS
import qualified Data.ByteString.Lazy.Char8    as BSL
import qualified Data.ByteString.Builder       as BSB
import           Data.Char                      ( isSpace )
import           Data.List
import qualified Data.Vector.Unboxed           as VU
import qualified Data.Vector.Unboxed.Mutable   as VUM
-- see: https://hackage.haskell.org/package/containers-0.6.2.1/docs/Data-Map-Strict.html
import Data.Map.Strict (Map)
import qualified Data.Map.Strict as Map
import Data.IntMap (IntMap)
import qualified Data.IntMap as IntMap

main :: IO ()
main = do
  n  <- readLn @Int
  as <- unfoldr (BS.readInt . BS.dropWhile isSpace) <$> BS.getLine
  let iMinusAi = hist $ zipWith (-) [1..n] as
  let jPlusAj = hist $ zipWith (+) [1..n] as
  -- let iMinusAi = histV $ VU.zipWith (-) (VU.enumFromN 1 n) as
  -- let jPlusAj = histV $ VU.zipWith (+) (VU.enumFromN 1 n) as
  print $ go 0 iMinusAi jPlusAj
 where
  go cnt [] _  = cnt
  go cnt _  [] = cnt
  go cnt xs'@((i, x) : xs) ys'@((j, y) : ys)
    | i < j     = go cnt xs ys'
    | i > j     = go cnt xs' ys
    | otherwise = go (cnt + x * y) xs ys

-- create histogram from list
hist :: [Int] -> [(Int, Int)]
hist xs = IntMap.toAscList $ IntMap.fromListWith (+) $ zip xs $ repeat 1

histV :: VU.Vector Int -> VU.Vector (Int, Int)
histV = VU.fromList . hist . VU.toList

Measured memory_bytes: 79392
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin >> n;
  map<string,long long int> m;
  while(n--){
    string str;
    cin >> str;
    sort(str.begin(),str.end());
    m[str]++;
  }
  long long int ans = 0;
for(auto it = m.begin(); it != m.end() ; it++){
  long long int x = it->second;
  ans = ans + (x)*(x-1)/2;
  
}
  
    cout << ans << endl;  
  
}

Measured memory_bytes: 11136
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>

#define repd(i, a, b) for (ll i = (a); i < (b); i++)
#define rep(i, n) repd(i, 0, n)

using namespace std;

namespace mp = boost::multiprecision;
using Bint = mp::cpp_int;

using ll = long long;
ll mod = pow(10, 9) + 7;

template <typename T> void output(T, ll);
ll gcd(ll, ll);
ll lcm(ll, ll);
Bint comb(Bint, Bint);
void prime_map(map<ll, ll> &, ll);

ll solve(ll a, ll b) {
    if (b % a == 0) {
        return (b / a * 2 - 1) * a;
    } else {
        ll num = b / a * 2;
        return num * a + solve(b % a, a);
    }
    return 0;
}

int main() {
    // source
    ll n, x;
    cin >> n >> x;
    ll ans = 0;
    ll a = x, b = n - x;

    ans = a + b + solve(a, b);
    cout << ans << endl;
    return 0;
}

Bint comb(Bint a, Bint b) {
    Bint ans = 1;

    if (a < b) {
        return 0;
    }

    rep(i, b) {
        ans *= a - i;
        ans /= i + 1;
    }

    return ans;
}

template <typename T> void output(T a, int precision) {
    if (precision > 0) {
        cout << setprecision(precision) << a << "\n";
    } else {
        cout << a << "\n";
    }
}

template <typename T> T min(T a, T b) {

    if (a < b) {
        return a;
    } else {
        return b;
    }
}

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

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

void prime_map(map<ll, ll> &m, ll num) {

    if (num == 1) {
        return;
    }
    ll cache = num;
    repd(i, 2, sqrt(num) + 2) {
        if (num % i == 0) {
            if (m[i] == 0) {
                m[i] = 1;
            } else {
                m[i]++;
            }

            num /= i;
            break;
        }
    }
    if (cache == num) {
        if (m[num] == 0) {
            m[num] = 1;
        } else {
            m[num]++;
        }

        return;
    }
    prime_map(m, num);
    return;
}


Measured memory_bytes: 256
#include <limits.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <algorithm>
#include <cfloat>
#include <complex>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;

int main() {
  ll N;

  cin >> N;

  vector<ll> lst(N, 0);

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

  ll ans = 0;
  bool done = false;
  for (int i = 0; i <= N - 2;) {
    ll tmp = 0;
    for (int j = i + 1; j <= N - 1; j++) {
      if (lst[j - 1] >= lst[j])
        tmp++;
      else {
        i = j;
        break;
      }
      if (j == N - 1) done = true;
    }
    ans = max(ans, tmp);
    if (done) break;
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 1024
a, b, ab, x, y = map(int, input().split())

min_value = a * x + b * y

max_num = max(x, y)

for i in range(2, max_num * 2 + 1, 2):
    # print(i)
    value = ab * i + a * max(0, x - i // 2) + b * max(0, y - i // 2)
    # print(value)
    min_value = min(min_value, value)

print(min_value)


Measured memory_bytes: 39280
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <complex>
#include <cstring>
#include <cstdlib>
#include <string>
#include <cmath>
#include <queue>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
const int INF = 1<<29;

int main() {
  int coins[] = {1,5,10,50,100,500};
  vector<int> dp(500,INF);
  dp[0] = 0;
  REP(i,500) {
    REP(j,6) {
      if (i+coins[j] >= 500) break;
      dp[i+coins[j]] = min(dp[i+coins[j]], dp[i] + 1);
    }
  }  
  while(1) {
    int p;
    cin >> p;
    int n[6];
    REP(i,6) cin >> n[i];
    if (p==0) break;
    int res = INF;
    REP(i,500) {
      int pp = p+i;
      int hoge = 0;
      
      for (int j=5; j>=0; j--) {
        REP(k, n[j]) {
//          printf("%d,%d\n",pp,n[j]);
          if (pp < coins[j]) break;

          pp -= coins[j];
          hoge++;
//          cout << pp << endl;
        }
      }
      if (pp==0)
        res = min(res, hoge + dp[i]);
      //    cout << hoge << " " << dp[i] << endl;
    }
    cout << res << endl;
  }
}

Measured memory_bytes: 908
n=input()
a=sorted([int(x) for x in input().split()])
b=0
c=0
for i in a:
    if i % 2 ==0:
        b+=1
        if i % 3 ==0 or i % 5 ==0:
            c+=1
if b==c:
    print("APPROVED")
else:
    print("DENIED")


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

//{ START
using namespace std;
#define int int64_t
#define rep(i, a, n) for (int i = (a); i < (n); ++i)
#define reps(i, a, n) for (int i = (a); i > (n); --i)
#define arep(i, x) for (auto &&i : (x))
#define irep(i, x) for (auto i = (x).begin(); i != (x).end(); ++i)
//降順はgreater<T>()
#define all(x) (x).begin(), (x).end()
#define rv(s) reverse((s).begin(), (s).end())
//gcd lcmはそのままok
#define gcd(a, b) __gcd(a, b)
#define bits(n) (1 << (n))
#define pcnt(x) __builtin_popcountll(x)
//配列内等要素削除
#define unique(x) (x).erase(unique(x).begin(),(x).end()),(x).end())
#define Fixed(n) fixed << setprecision(n)
//総和
#define sowa(n) ((n) * ((n) + 1)) / 2
#define pb(x, a) (x).push_back(a)
#define fb(x, a) (x).push_front(a)
#define eb(x, a) (x).emplace_back(a)
#define F first
#define S second
#define cauto const auto &
using P = pair<int, int>;
using Graph = vector<vector<P>>;
template <class T> //昇順
using min_heap = priority_queue<T, vector<T>, greater<T>>;
template <class T> //降順
using max_heap = priority_queue<T>;
template <class A, class B>
using umap = unordered_map<A, B>;
template <class A>
using uset = unordered_set<A>;
template <class T>
bool chmax(T &a, const T &b) //最大値更新 返り値はbool
{
    if (a < b)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T &a, const T &b) //最小値更新 返り値はbool
{
    if (b < a)
    {
        a = b;
        return 1;
    }
    return 0;
}
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
constexpr int INF = 0x3f3f3f3f;
constexpr int LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr int mod1 = 1e9 + 7;
constexpr int mod2 = 998244353;
//} END

signed main()
{
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);

    int x;
    cin >> x;
    int ans = 100, cnt = 0;
    while (x > ans)
    {
        ans += ans / 100;
        ++cnt;
    }
    cout << cnt << '\n';
    return 0;
}

Measured memory_bytes: 3668
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pi atan(1.0)*4
#define pb push_back
#define in(x) insert(x)
#define fl(x,y) for(ll i=x;i<y;i++)
#define vi vector<long long>
#define vs  vector<string>
#define vp(vi,x) cin>>x; vi.pb(x);
string en="\n";
string hlo="hello";
string Y="YES\n";
string Ys="Yes\n";
string N="NO\n";
string No="No\n";
string sp=" ";
#define E end()
#define B begin()
#define sz size()
#define EM empty()
#define fi first
#define se second
#define clr clear()
#define sqr(a) (a*a)
#define mk make_pair
#define mem(a,b) memset(a,b,sizeof(a))
#define all(cont) cont.begin(),cont.end()
bool isprm(ll a){for(ll i=2;i*i<=a;i++){if(a%i==0)return false;}return true;}
bool palin(string a){for(int i=0;i<a.sz;i++){if(a.at(i)!=a.at(a.sz-i-1))return 0;} return 1;}
bool isVowel(char ch){ ch=toupper(ch); if(ch=='A'||ch=='U'||ch=='I'||ch=='O'||ch=='E' ) return true; return false;}
/*int toInt(string s){int sm;stringstream ss(s);ss>>sm;return sm;}
LL bpow(LL a,LL b){if(b==0)return 1;LL r=bpow(a,b/2);if(b%2)return r*r*a;else return r*r;}
LL binpow(LL a,LL b){LL r=1;while(b>0){if(b&1)r=r*a;a=a*a;b>>=1;}return r;}
LL binpow(LL a,LL b,LL m){a%=m;LL r=1;while(b>0){if(b&1) r=r*a%m;a=a*a%m; b>>=1;}return r;}
template<typename T>inline T gcd(T a,T b){if(a<0)return gcd(-a,b);if(b<0)return gcd(a,-b);return (b==0)?a:gcd(b,a%b);}
template<typename T>inline T lcm(T a,T b) {if(a<0)return lcm(-a,b);if(b<0)return lcm(a,-b);return a*(b/gcd(a,b));}
*/
//bool isVowel(char ch){ ch=toupper(ch); if(ch=='A'||ch=='U'||ch=='I'||ch=='O'||ch=='E') return true; return false;}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll a,b,c,d,e,x,t,n,k,m,p,q,r,y,z,yy,sum=0,ct=0,flag=0;
    string s,s1,s2,s3,s4;
    char ch,ch1,ch2;
    deque<ll>d1,d2,d3;
    vector<string>vs1;
    string ss1;
    map<ll,ll>mp;
    //map<ll,ll>::iterator it;
    set<char>st1,st2;
    //set<ll>::iterator iter = st.begin();
    vector<pair<ll,ll> >v;
    double x1,y1,x2,y2,x3,y3,x4,y4;
    sum=0; ll mx=0,mn=3487327628458454875,cp=0;
    ll HR,MN,mnt,hrs,c1=0,c2=0; flag=0;
    ct=0; flag=0; cp=0;
    vector<ll>v1,v2,v3;
    //cin.ignore();
    //getline(cin,s);

         mn=3487327628458454875; flag=0,cp=0;
         cin>>n;
    ll v11[n+10];
         for(ll i=0;i<n;i++)
         {
             cin>>v11[i];
         }
         for(ll i=0;i+1<n;i++)
         {
             if(v11[i]>v11[i+1])
             {
                 cp+=abs(v11[i+1]-v11[i]);
                  v11[i+1]=v11[i];
             }
         }
         cout<<cp<<endl;

     return 0;
}


Measured memory_bytes: 5172
import java.util.Scanner;

fun main(args: Array<String>){
    val sc = Scanner(System.`in`)
   val charray = sc.next().toString().toCharArray()
    if(charray[0] == charray[1] && charray[1] == charray[3] && charray[2] == charray[1]){
        println("No")
    }else if(charray[0] == charray[1]) {
        if (charray[2] == charray[3]) {
            println("Yes")
        }else{
            println("No")
        }
    }else if(charray[0] == charray[2]){
        if(charray[1] == charray[3]){
           println("Yes")
        }else{
            println("No")
        }
    }else if(charray[0] == charray[3]){
        if(charray[1] == charray[2]){
            println("Yes")
        }else{
            println("No")
        }
    }else{
        println("No")
    }
}

Measured memory_bytes: 29604
from fractions import gcd
from collections import Counter, deque, defaultdict
from heapq import heappush, heappop, heappushpop, heapify, heapreplace, merge
from bisect import bisect_left, bisect_right, bisect, insort_left, insort_right, insort
from itertools import accumulate, product, permutations, combinations

def main():
    X = int(input())

    if X <= 599:
        print('8')
    elif X <= 799:
        print('7')
    elif X <= 999:
        print('6')
    elif X <= 1199:
        print('5')
    elif X <= 1399:
        print('4')
    elif X <= 1599:
        print('3')
    elif X <= 1799:
        print('2')
    else:
        print('1')

if __name__ == '__main__':
    main()

Measured memory_bytes: 10392
#include <iostream>

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

	int tTime = 0;
	if (a <= 0) {
		tTime += -1 * a * c;
		tTime += d;
		tTime += b * e;
	}
	else {
		tTime += (b - a) * e;
	}

	std::cout << tTime << std::endl;

	return 0;
}


Measured memory_bytes: 3076
N = int(input())
Nminus1 = N - 1
# lines = []

CSF = []
# S = [0 for _ in range(Nminus1)]
# F = [0 for _ in range(Nminus1)]

for i in range(Nminus1):
    c, s, f = input().split()
    CSF.append((int(c), int(s), int(f)))
    # C[i] = int(c)
    # S[i] = int(s)
    # F[i] = int(f)

# for line in lines:
#     c, s, f = line.split()
#     C.append(int(c))
#     S.append(int(s))
#     F.append(int(f))

for i in range(Nminus1):
    a = 0
    for j in range(i, Nminus1):
        C, S, F = CSF[j]
        if a <= S:
            n = S - a
        else:
            mod = a % F 
            n = F - mod if mod != 0 else 0
        a = a + C + n
    print(a)

print(0)

Measured memory_bytes: 3188