akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

int main() {
  int n;
  cin >> n;
  vector<ll> a(n+1);
  vector<ll> b(n);
  for (int i=0; i<n+1; i++) {
  	cin >> a.at(i);
  }
  for (int i=0; i<n; i++) {
  	cin >> b.at(i);
  }
  
  ll ans = 0;
  ll m;
  
  for (int i=0; i<n; i++) {
  	m = min(a.at(i), b.at(i));
    ans += m;
    b.at(i) -= m;
    
    m = min(a.at(i+1), b.at(i));
    ans += m;
    a.at(i+1) -= m;
  }
  cout << ans << endl;
  
}

Measured memory_bytes: 1792
import java.util.*;
public class Main
{
	public static void main(String[] args)
	{
	Scanner s=new Scanner(System.in);
	int n=s.nextInt();
	int h[]=new int[n];
 	int k=s.nextInt();
	for(int i=0;i<n;i++)
	h[i]=s.nextInt();
	int dp[]=new int[n];
	dp[0]=0;
	int min=Integer.MAX_VALUE;
	int a1=0;
	for(int i=1;i<n;i++)
	{
	 if(i<=k)
	dp[i]=Math.abs(h[i]-h[0]);
	  else
	   {
	      
	    for(int j=i-k;j<i;j++)
		{
		if(dp[j]+Math.abs(h[j]-h[i])<min)
		min=dp[j]+Math.abs(h[i]-h[j]);
		
		}
	dp[i]=min;
	min=Integer.MAX_VALUE;
	   }
	}
	
	System.out.println(dp[n-1]);
	}
}

Measured memory_bytes: 51148
package main

import "fmt"

func main() {
	var n int64
	var t [5]int64

	fmt.Scan(&n)
	for i := 0; i < 5; i++ {
		fmt.Scan(&t[i])
	}

	// find bottle-neck
	neck := t[0]
	for i := 1; i < 5; i++ {
		if neck > t[i] {
			neck = t[i]
		}
	}

	var result = (n + neck - 1) / neck + 5 - 1
	fmt.Println(result)
}


Measured memory_bytes: 512
n, m = map(int, input().split())
cakes = [list(map(int, input().split())) for _ in range(n)]

each_r = [[0] * n for _ in range(8)]

for i in range(n):
    each_r[0][i] =  cakes[i][0] + cakes[i][1] + cakes[i][2]
    each_r[1][i] =  cakes[i][0] + cakes[i][1] - cakes[i][2]
    each_r[2][i] =  cakes[i][0] - cakes[i][1] + cakes[i][2]
    each_r[3][i] =  cakes[i][0] - cakes[i][1] - cakes[i][2]
    each_r[4][i] = -cakes[i][0] + cakes[i][1] + cakes[i][2]
    each_r[5][i] = -cakes[i][0] + cakes[i][1] - cakes[i][2]
    each_r[6][i] = -cakes[i][0] - cakes[i][1] + cakes[i][2]
    each_r[7][i] = -cakes[i][0] - cakes[i][1] - cakes[i][2]

results = [0] * 8
for i in range(8):
    each_r[i].sort(reverse=True)
    results[i] = sum(each_r[i][0:m])
print(max(results))


Measured memory_bytes: 39536
import java.util.*;

public class Main {
    public static void  main (String[] args) {
        Scanner sc = new Scanner(System.in);
        
        int x = sc.nextInt();
        int a = sc.nextInt();
        int b = sc.nextInt();
        
        int selA = Math.abs(x - a);
        int selB = Math.abs(x - b);
        
        if (selA > selB) {
            System.out.println("B");
        } else {
            System.out.println("A");
        }
    }
}

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

# 2分検索ライブラリを使う
import bisect

N = int(input())
A_list = list(map(int, input().split()))
B_list = list(map(int, input().split()))
C_list = list(map(int, input().split()))

# 昇順ソート
A_list.sort()
C_list.sort()

ans = 0
for i in range(N):
    # 同じ値があった時に、leftは先頭、rightは最後尾のindexを返す
    ab = bisect.bisect_left(A_list, B_list[i])
    bc = N - bisect.bisect_right(C_list, B_list[i])
    # 返されたindexから、候補となるABとBCの数が分かるので、合計していく
    ans += ab * bc
print(ans)

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

using namespace std;

typedef long long ll;
#define fi first
#define se second
#define pb push_back

int main() {
    //ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    string s, t;
    cin >> s >> t;
    cout << t << s;
    return 0;
}


Measured memory_bytes: 3592
{-# LANGUAGE TypeFamilies #-}

import           Control.Applicative
import           GHC.Exts

main :: IO ()
main = do
  [k, t] <- map read.words <$> getLine
  xs <- map read.words <$> getLine
  print $ solve k $ zip xs [0..]

solve :: Int -> [(Int, Int)] -> Int
solve k xis = go (-1) $ fromList xis
  where
    go :: Int -> Heap(Int, Int) -> Int
    go l heap
      | Just ((x, i), h') <- deleteFindMax heap
      , Just ((y, j), h'') <- deleteFindMax h' = go j $ ins (x-1, i) $ ins (y-1, j) h''
      | Just ((x, i), _) <- deleteFindMax heap = if i == l
          then x
          else max 0 $ x - 1
      | otherwise = 0


ins (0, _) heap = heap
ins x heap = insert x heap

data Heap a = Fork !a [Heap a] | Empty

singleton :: a -> Heap a
singleton x = Fork x []
{-# INLINE singleton #-}

isEmpty :: Heap a -> Bool
isEmpty Empty = True
isEmpty _ = False
{-# INLINE isEmpty #-}

insert :: Ord a => a -> Heap a -> Heap a
insert x = merge (Fork x [])
{-# INLINE insert #-}

maxElem :: Heap a -> Maybe a
maxElem (Fork x _) = Just x
maxElem _ = Nothing
{-# INLINE maxElem #-}

deleteMax :: Ord a => Heap a -> Maybe (Heap a)
deleteMax (Fork _ hs) = Just $ mergePairs hs
deleteMax _ = Nothing
{-# INLINE deleteMax #-}

deleteFindMax :: Ord a => Heap a -> Maybe (a, Heap a)
deleteFindMax (Fork x hs) = Just (x, mergePairs hs)
deleteFindMax _ = Nothing
{-# INLINE deleteFindMax #-}

merge :: Ord a => Heap a -> Heap a -> Heap a
merge hx@(Fork x hxs) hy@(Fork y hys)
  | x >= y    = Fork x (hy:hxs)
  | otherwise = Fork y (hx:hys)
merge Empty hy = hy
merge hx _ = hx
{-# INLINE merge #-}

mergePairs :: Ord a => [Heap a] -> Heap a
mergePairs (x:y:hs) = merge (merge x y) (mergePairs hs)
mergePairs [x]      = x
mergePairs []       = Empty
{-# INLINE mergePairs #-}

instance Ord a => IsList (Heap a) where
    type Item (Heap a) = a
    fromList xs = mergePairs $ map singleton xs
    toList (Fork x hs) = x : toList (mergePairs hs)
    toList Empty = []


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

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

using namespace std;

int main() {
  int n;
  std::cin >> n;
  std::vector<int> a(n);
  rep(i, n) { std::cin >> a[i]; }

  sort(a.begin(), a.end(), std::greater<int>());
  int ans = 0;
  rep(i, n) {
    ans += a[i] - a[i+1];
    ++i;
  }

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


Measured memory_bytes: 3588
# row = [int(x) for x in input().rstrip().split(" ")]
# n = int(input().rstrip())
# s = input().rstrip()

def resolve():
    import sys
    input = sys.stdin.readline

    n = int(input().rstrip())

    data = {}

    for i in range(n):
        row = [x for x in input().rstrip().split(" ")]
        s = row[0]
        p = int(row[1])

        if s not in data.keys():
            data[s] = {}

        data[s][p] = i+1

    for city, res in sorted(data.items()):
        for point, num in sorted(res.items(), reverse=True):
            print(num)





if __name__ == "__main__":
    resolve()


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

int main(){
  string S;
  string all = "abcdefghijklmnopqrstuvwxyz";
  cin >> S;
  set <char> a;
  for(int i = 0; i < S.size(); i++){
    a.insert(S.at(i));
  }
  vector<char> c;
  for(char b : all){
    if(!a.count(b)) c.push_back(b);
  }
  sort(c.begin(), c.end());
  if(c.size() > 0) cout << c.at(0) << endl;
  else cout << "None" << endl;
}


Measured memory_bytes: 3716
using System;

namespace A_Security
{
    class Program
    {
        static void Main(string[] args)
        {
            var pass = Console.ReadLine();
            if(pass[0]==pass[1])
            {
                Console.WriteLine("Bad");
            }
            else if(pass[1]==pass[2])
            {
                Console.WriteLine("Bad");
            }
            else if(pass[2]==pass[3])
            {
                Console.WriteLine("Bad");
            }
            else
            {
                Console.WriteLine("Good");
            }
        }
    }
}

Measured memory_bytes: 13140
def n0():return int(input())
def n1():return [int(x) for x in input().split()]
def n2(n):return [int(input()) for _ in range(n)]
def n3(n):return [[int(x) for x in input().split()] for _ in range(n)]

a,b=n1()

a2=a/0.08
a3=(a+1)/0.08
b2=b/0.1
b3=(b+1)/0.1
for x in range(1,1300):
    if a2<=x<a3 and b2<=x<b3:
        print(x)
        break;
else:
    print(-1)

Measured memory_bytes: 3064
#include <stdio.h>
#include <iostream>
using namespace std;

int main(void)
{		
	int a, b;
	cin >> a >> b;
	
	int d = a / b;
	int r = a % b;
	double f = a / (double)b;
	
	printf("%d %d %lf\n", d, r, f);
	
	return 0;
}

Measured memory_bytes: 3216
#include<iostream>
#include<string.h>
#include<string>
#include<stdio.h>
#include<algorithm>
#include<vector>
#include<math.h>
#include<queue>
#include<set>
#include<map>
using namespace std;
typedef long long ll;
typedef long double db;
typedef pair<int,int> pii;
const int N=10000;
const db pi=acos(-1.0);
#define lowbit(x) (x)&(-x)
#define sqr(x) (x)*(x)
#define rep(i,a,b) for (register int i=a;i<=b;i++)
#define per(i,a,b) for (register int i=a;i>=b;i--)
#define fir first
#define sec second
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define maxd 998244353
#define eps 1e-8
#define int long long 
struct node{int to,nxt,cost,col;}sq[200200];
int all=0,head[100100];
int n,q,dep[100100],fa[100100][20],cnt[100100];
struct qnode{int col,len,x,id;};
vector<qnode> ask[100100];
ll ans[100100],dis[100100],cdis[100100];

int read()
{
    int x=0,f=1;char ch=getchar();
    while ((ch<'0') || (ch>'9')) {if (ch=='-') f=-1;ch=getchar();}
    while ((ch>='0') && (ch<='9')) {x=x*10+(ch-'0');ch=getchar();}
    return x*f;
}

void add(int u,int v,int col,int w)
{
	all++;sq[all].to=v;sq[all].nxt=head[u];sq[all].col=col;sq[all].cost=w;head[u]=all;
}

void dfs(int u,int fu)
{
	dep[u]=dep[fu]+1;fa[u][0]=fu;
	rep(i,1,19)
		fa[u][i]=fa[fa[u][i-1]][i-1];
	for (int i=head[u];i;i=sq[i].nxt)
	{
		int v=sq[i].to;
		if (v==fu) continue;
		dis[v]=dis[u]+sq[i].cost;
		dfs(v,u);
	}
}

int LCA(int u,int v)
{
	if (dep[u]<dep[v]) swap(u,v);
	int tmp=dep[u]-dep[v];
	per(i,19,0)
		if ((tmp>>i)&1) u=fa[u][i];
	if (u==v) return u;
	per(i,19,0)
		if (fa[u][i]!=fa[v][i])
		{
			u=fa[u][i];v=fa[v][i];
		}
	return fa[u][0];
}

void dfs1(int u,int fu)
{
	int len=ask[u].size();
	rep(i,0,len-1)
	{
		ans[ask[u][i].id]+=1ll*ask[u][i].x*(dis[u]-cdis[ask[u][i].col]+1ll*ask[u][i].len*cnt[ask[u][i].col]);
	}
	for (int i=head[u];i;i=sq[i].nxt)
	{
		int v=sq[i].to;
		if (v==fu) continue;
		cnt[sq[i].col]++;cdis[sq[i].col]+=sq[i].cost;
		dfs1(v,u);
		cnt[sq[i].col]--;cdis[sq[i].col]-=sq[i].cost;
	}
}

signed main()
{
	n=read();q=read();
	rep(i,1,n-1)
	{
		int u=read(),v=read(),col=read(),w=read();
		add(u,v,col,w);add(v,u,col,w);
	}
	dfs(1,0);
	rep(i,1,q)
	{
		int col=read(),w=read(),u=read(),v=read(),l=LCA(u,v);
		ask[u].push_back((qnode){col,w,1,i});
		ask[v].push_back((qnode){col,w,1,i});
		ask[l].push_back((qnode){col,w,-2,i});
	}
	dfs1(1,0);
	rep(i,1,q) printf("%lld\n",ans[i]);
	return 0;
}

Measured memory_bytes: 46192
n = int(input())
s = input()

a = {}
for i in range(n):
    if s[i] not in a:
        a[s[i]] = 1
    else:
        a[s[i]] += 1
count = 1
for i in a.keys():
    count *= a[i] + 1
    count %= 10 ** 9 + 7
print(count-1)

Measured memory_bytes: 3188
n = int(input())
L = list(map(int, input().split()))
cnt = 1
state = None
i = 1
while i < n:
    if state is None:
        if L[i] > L[i - 1]:
            state = 'up'
        elif L[i] < L[i - 1]:
            state = 'down'
        i += 1
    else:
        if state == 'up':
            while L[i] >= L[i - 1]:
                i += 1
                if i >= n - 1:
                    print(cnt)
                    exit()
            cnt += 1
            i += 1
            state = None
        else:
            while L[i] <= L[i - 1]:
                i += 1
                if i >= n - 1:
                    print(cnt)
                    exit()
            cnt += 1
            i += 1
            state = None
print(cnt)

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

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

#define rep(i,n) for(int (i)=0,temp=(int)(n);(i)<temp;++(i))
#define repi(i,start,end) for(int (i)=(start),temp=(int)(end);i<(end);++(i))
#define rfor(x,v) for(const auto& (x) : (v))
#define all(x) (x).begin(),(x).end()
#define SORT(v, n) sort((v), (v)+(n))
#define vsort(v) sort((v).begin(), (v).end())
#define vfsort(v,lambda) sort(all((v)),(lambda))
#define vint vector<int>
#define vvint vector<vector<int>> //vvint v(n,vint(n))
#define vin(v) rep(i,(v).size()) {cin >> (v)[i];}
//最終奥義 #define int long long
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
//lambda: [&](int x, int y){return x<y;}

signed main(void){
  int n;cin>>n;
  vector<pint> lr(n);
  rep(i,n){
    int x,l;cin>>x>>l;
    lr[i].first=x-l;
    lr[i].second=x+l;
  }
  vfsort(lr,[](pint x,pint y){
      if(x.second!=y.second)return x.second<y.second;
      else return x.first<y.first;
      });
  int ans=1,pos=lr[0].second;
  repi(i,1,n){
    if(lr[i].first<pos)continue;
    pos=lr[i].second;
    ans++;
  }
  cout << ans << endl;

}


Measured memory_bytes: 1024
#include <algorithm>
#include<iostream>
#include<vector>
#include<map>
#include<set>
#include<string>

#include<stdlib.h>
#include<string.h>
#include<math.h>
#include<limits.h>
using lll = long long;
using ull = unsigned long long;
using namespace std;



int main(){

  lll ii,jj,kk;
  lll n;
  vector<lll> b;
  vector<lll> a;
  cin >> n;
  a.resize(n);
  b.resize(n);
  for(ii=0;ii<n-1;ii++){
    cin >> b[ii];
  }
  lll a1,a2;

  for(ii=0;ii<n;ii++){

    if(ii==0){
      a[0] = b[0];
    }
    
    else if(ii==n-1){
      a[n-1] = b[n-2];
    }

    else{
      a1 = b[ii-1];
      a2 = b[ii];

      if(a1 > a2){
        a[ii] = a2;
      }
      else{
        a[ii] = a1;
      }

    }
  }


  lll sum = 0;
  
  for(ii=0;ii<n;ii++){
    sum += a[ii];
  }
  cout << sum << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <assert.h>
#include <numeric>
#include <math.h>
#include <climits>
#include <stack>
#include <iomanip>
#include <sstream>

using namespace std;

template <typename T>
inline bool sign(T A) {
    return (A>0)-(A<0);
}
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define SREP(i,s,n) for(int i=s; (n-i)*sign(n-s)>0; i+=sign(n-s))
#define all(x) (x).begin(),(x).end()
typedef long long ll;
typedef unsigned long long ull;

template <typename T>
T gcd(T a, T b) {
    if(a < b) gcd(b, a);
    if (b == 1) return 1;
    T r;
    while ((r=a%b)) {
        a = b;
        b = r;
    }
    return b;
}

bool _less(pair<int, int> a, pair<int, int> b) {
    return a.second < b.second;
}

template <template<class,class,class...> class C, typename K, typename V, typename... Args>
V map_get(const C<K,V,Args...>& m, K const& key, const V & defval)
{
    typename C<K,V,Args...>::const_iterator it = m.find( key );
    if (it == m.end())
        return defval;
    return it->second;
}

#define MOD (1'000'000'000+7)

int main(void) {
    int N;
    cin >> N;
    vector<int> L(N);
    vector<int> R(N);
    REP(i, N) {
        cin >> L[i];
        R[i] = -L[i];
    }

    sort(L.begin(), L.end());
    sort(R.begin(), R.end());
    ll cnt = 0;

    REP(i, N) {
        SREP(j, i+1, N) {
            int a = L[i];
            int b = L[j];
            int lb = abs(a - b);
            int ub = a + b;

            int l = upper_bound(L.begin() + j+1, L.end(), lb) - L.begin();
            int r = upper_bound(R.begin(), R.end() - j-1, -ub) - R.begin();
        
            cnt += max(0, N - l - r);
        }
    }

    cout << cnt << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <climits>
#include <algorithm>
#include <vector>
#include <deque>
#include <queue>
#include <list>
#include <stack>
#include <string>
#include <functional>
#include <numeric>
#include <map>
#include <set>
#include <cstdlib>
#include <bitset>
#include <unordered_map>
#include <random>
#define _USE_MATH_DEFINES
#include <math.h>
#include <complex>

using namespace std;

#define INF (int)1e8
#define _INF (int)-1e8
#define INFLL (long long)1e15
#define _INFLL (long long)-1e15
#define Loop(i, n) for(int i = 0; i < (int)n; i++)
#define Loop1(i, n) for(int i = 1; i <= (int)n; i++)
#define Loopr(i, n) for(int i = (int)n - 1; i >= 0; i--)
#define Loopr1(i, n) for(int i = (int)n; i >= 1; i--)
#define bitmanip(m,val) static_cast<bitset<(int)m>>(val)
typedef long long int ll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef pair<int, int> P;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef vector<double> vd;
typedef vector<vector<double>> vvd;
typedef complex<double> cdouble;
typedef vector<complex<double>> vcd;
typedef vector<vector<complex<double>>> vvcd;

/*******************************************************/

void printv(vll a) {
  Loop(i, a.size()) cout << a[i] << endl;
  cout << endl;
}

void printmx(vvll A) {
  Loop(i, A.size()) {
    Loop(j, A[0].size()) {
      cout << A[i][j] << " ";
    }
    cout << endl;
  }
  cout << endl;
}

// ret[i] = a[i] + a[i + 1] + ... (for length times, with looping)
vll loop_vec_accumulate(vll a, ll length) {
  int n = a.size();
  vll ret(n, 0);
  if (n == 0) return ret;
  ll p = length / n;
  if (p > 0) {
    Loop(i, n) ret[0] += a[i];
    ret[0] *= p;
  }
  Loop(i, length % n) ret[0] += a[i];
  Loop1(i, n - 1) {
    ret[i] = ret[i - 1] - a[i - 1] + a[(i + length - 1) % n];
  }
  return ret;
}
 
vvll loop_mx_accumulate(vvll A, ll i_length, ll j_length) {
  int m = A.size();
  int n = A[0].size();
  Loop(i, m) A[i] = loop_vec_accumulate(A[i], j_length);
  vvll trans_A(n, vll(m, 0));
  Loop(i, n) {
    Loop(j, m) trans_A[i][j] = A[j][i];
  }
  Loop(i, n) trans_A[i] = loop_vec_accumulate(trans_A[i], i_length);
  Loop(i, m) {
    Loop(j, n) A[i][j] = trans_A[j][i];
  }
  return A;
}

int main() {
  int n, k; cin >> n >> k;
  vvll grid(k * 2, vll(k * 2, 0));
  Loop(i, n) {
    int x, y;
    char c;
    cin >> x >> y >> c;
    if (c == 'W') x += k;
    x %= (k * 2);
    y %= (k * 2);
    grid[x][y]++;
    grid[(x + k) % (k * 2)][(y + k) % (k * 2)]++;
  }
  grid = loop_mx_accumulate(grid, k, k);
  ll ans = 0;
  Loop(i, grid.size()) {
    Loop(j, grid[i].size()) {
      ans = max(ans, grid[i][j]);
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 94336
#include <stdio.h>
#include <stdlib.h>

int main(void) {
  int i;
  int N;
  int H[100];
  int num;
  int max;

  scanf("%d", &N);
  // printf("%d\n", N);
  for (i = 0; i < N; i++) {
    scanf("%d", H + i);
    // printf("%d\n", H[i]);
  }

  num = 1;
  max = H[0];
  for (i = 0; i < N - 1; i++) {
    if (max <= H[i + 1]) {
      num += 1;
      max = H[i + 1];
    } else {
      // break;
    }
  }

  printf("%d\n", num);
  fflush(stdout);
  return 0;
}


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

typedef long long ll;
typedef long double ld;
typedef double db; //
typedef string str; //
//
typedef pair<int,int> pi;
typedef pair<ll,ll> pl; //
typedef pair<db,db> pd; //
//
typedef vector<int> vi;
typedef vector<ll> vl; //
typedef vector<db> vd; //
typedef vector<str> vs; //
typedef vector<pi> vpi;
typedef vector<pl> vpl; //
typedef vector<pd> vpd; //

#define mp make_pair
#define f first
#define s second
#define sz(x) (int)x.size()
#define all(x) begin(x), end(x)
#define rall(x) (x).rbegin(), (x).rend() //
#define rsz resize
#define ins insert //
#define ft front() //
#define bk back()
#define pf push_front //
#define pb push_back
#define eb emplace_back //
#define lb lower_bound //
#define ub upper_bound //

#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define F0R(i,a) FOR(i,0,a)
#define ROF(i,a,b) for (int i = (b)-1; i >= (a); --i)
#define R0F(i,a) ROF(i,0,a)
#define trav(a,x) for (auto& a: x)

const int MOD = 1e9+7; // 998244353;
const int MX = 2e5+5; //
const ll INF = 1e18; //
const ld PI = acos((ld)-1);
const int xd[4] = {1,0,-1,0}, yd[4] = {0,1,0,-1}; //
mt19937 rng((uint32_t)chrono::steady_clock::now().time_since_epoch().count()); //
//
template<class T> bool ckmin(T& a, const T& b) {
	return b < a ? a = b, 1 : 0; }
template<class T> bool ckmax(T& a, const T& b) { //
	return a < b ? a = b, 1 : 0; } //
constexpr int pct(int x) { return __builtin_popcount(x); } //
constexpr int bits(int x) { return 31-__builtin_clz(x); } // floor(log2(x)) //
constexpr int cdiv(int a, int b) { return a/b+!(a<0||a%b == 0); } // division of a by b rounded up, assumes b > 0 //
// IGNORE
int fstTrue(function<bool(int)> f, int lo, int hi) {
	hi ++; assert(lo <= hi); // assuming f is increasing
	while (lo < hi) { // find first index such that f is true
		int mid = (lo+hi)/2;
		f(mid) ? hi = mid : lo = mid+1;
	}
	return lo;
}
template<class T> void remDup(vector<T>& v) {
	sort(all(v)); v.erase(unique(all(v)),end(v)); }

int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int N, M, K;
	cin >> N >> M >> K;
	int A[N];
	int B[M];
	for(int a = 0; a < N; a++){
		cin >> A[a];
	}
	for(int a = 0; a < M; a++){
		cin >> B[a];
	}
	ll preA[N + 1];
	ll preB[M + 1];
	preA[0] = preB[0] = 0;
	for(int a = 1; a <= N; a++)
		preA[a] = preA[a - 1] + A[a - 1];
	for(int a = 1; a <= M; a++)
		preB[a] = preB[a - 1] + B[a - 1];
	int j = M;
	ll mx = 0;
	for(ll a = 0; a <= N; a++){
		while(j >= 0 && preA[a] + preB[j] > K)
			j--;
		if(j == -1)
			break;
		mx = max(mx, a + j);
	}
	cout << mx << endl;
}

Measured memory_bytes: 8348
#include<iostream>
#include<vector>
#include<algorithm>
#include<climits>

const int MAX_N=1<<17;

typedef long long ll;

using namespace std;


ll n,dat[2*MAX_N-1];

void init(int n_){
	n=1;
	while(n<n_)n*=2;
}

void update(int k,ll a){
	k+=n-1;
	dat[k]=a;
	
	while(k>0){
		k=(k-1)/2;
		dat[k]=max(dat[2*k+1],dat[2*k+2]);
	}
}

ll query(int a,int b,int k,int l,int r){
	if(r<=a || b<=l)return 0;
	if(a<=l && r<=b)return dat[k];
	else {
		ll vl=query(a,b,k*2+1,l,(l+r)/2);
		ll vr=query(a,b,k*2+2,(l+r)/2,r);
		return max(vl,vr);
	}
}

int main(void){
	
	ll in,m,ans=0;
	
	cin >> m;
	
	init(m);
	
	for(int i=0;i<m;i++){
		cin >> in;
		update(in,in+query(1,in,0,0,n));
	}
	cout << m*(m+1)/2-query(1,m+1,0,0,n) << endl;
	
	return 0;
}

Measured memory_bytes: 2744
s = int(input())
a = []
i = 0
while True:
    if i == 0:
        a.append(s)
    elif a[i-1] % 2 == 0:
        a.append(a[i-1] / 2)
    else:
        a.append(a[i-1] * 3 + 1)
    if a[i] in a[:i]:
        print(i + 1)
        break
    i += 1


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
int n,m;
string A[101],B[101];

bool check(int x,int y){
  if(x+m-1>=n||y+m-1>=n) return 0;
  for(int i=0;i<m;i++)
    for(int j=0;j<m;j++)
      if(A[y+i][x+j] != B[i][j]) return 0;

      return 1;
}

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


  for(int i=0;i<n;i++) cin>>A[i];
  for(int i=0;i<m;i++) cin>>B[i];
  

  int ans=0;
  for(int i=0;i<n;i++)
    for(int j=0;j<n;j++)if(check(j,i)) ans=1;

  cout<<(ans?"Yes":"No")<<endl;
  return 0;
}


Measured memory_bytes: 256
from sys import stdin
import sys
import math
from functools import reduce
import functools
import itertools
from collections import deque,Counter,defaultdict
from operator import mul
import copy
# ! /usr/bin/env python
# -*- coding: utf-8 -*-
import heapq
sys.setrecursionlimit(10**6)
INF =  float("inf")
import bisect

N = int(input())
a = [0] + list(map(int, input().split()))

o = [a[2*i+1] for i in range(N//2)]
o = list(itertools.accumulate(o))

dp = [0 for i in range(N+1)]

dp[0] = dp[1] = 0
dp[2] = max(a[1], a[2])
if N > 2: dp[3] = max([a[1], a[2], a[3]])

if N > 3:
    for i in range(4, N+1):
        if i % 2 == 0:
            dp[i] = max(dp[i-2] + a[i], o[(i-3)//2] + a[i-1])
        else:
            dp[i] = max([dp[i-2] + a[i], dp[i-3] + a[i-1], o[(i-2)//2] ])

print(dp[N])




Measured memory_bytes: 125784
N=int(input())
F=[int(input().replace(" ",""),2) for _ in [0]*N]
P=[list(map(int,input().split())) for _ in [0]*N]
print(max([sum([P[j][bin(i&F[j]).count("1")] for j in range(N)]) for i in range(1,1024)]))

Measured memory_bytes: 3060
//In the Name of God
//Ya Ali

#include <bits/stdc++.h>

#define int long long

#define err(A) cout<<#A<<" = "<<(A)<<endl

using namespace std;

const int maxn=100100;

int n,x;

int a[maxn];

int ans;

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

  cin>>n>>x;

  for(int i=1;i<=n;i++)
    {
      cin>>a[i];
      int c=max(0ll,a[i-1]+a[i]-x);
      if(a[i]<c) a[i]-=0,a[i-1]-=c-a[i];
      else       a[i]-=c;
      ans+=c;
    }
  cout<<ans<<endl;
  
  return 0;
}


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

#define int long long

#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;

template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

const int INF=1001001001001001001ll;

int N;
int R[2222],A[2222],W[2222],T[2222];

int dp[4444];
int nex[4444];
signed main(){
	cin>>N;
	rep(i,N)cin>>R[i]>>A[i]>>W[i]>>T[i];

	vpint lis;
	rep(i,N)lis.pb({R[i]+T[i],i});
	sort(all(lis));reverse(all(lis));
	
	for(auto ukuku:lis){
		int i=ukuku.se;
		fill(nex,nex+4444,-INF);
		rep(j,4444){
			if(R[i]<=j)chmax(nex[min(j-R[i],T[i])],dp[j]+A[i]);
		}
		for(int j=4444-1;j>=0;j--)if(j+R[i]<4444)chmax(nex[j],nex[j+R[i]]+W[i]);
		rep(j,4444)chmax(dp[j],nex[j]);
	}
	cout<<*max_element(dp+1,dp+4444)<<endl;
	return 0;
}


Measured memory_bytes: 3308
#include <iostream>
#include <vector>
#include <limits.h>
#include <algorithm>
#include <string>
#include <math.h>
#include <limits.h>
#include <queue>
#include <map>
#include <set>
#include <iomanip>
#include <bitset>
#include <cassert>
#include <random>
#include <functional>
#include <stack>
using namespace std;

int N;

void solve() {
	vector<int> A, B, C;
	int ans = 0;
	cin >> N;
	A.resize(N);
	for (int n = 0; n < N; n++) {
		cin >> A[n];
		A[n]--;
	}
	B.resize(N);
	for (int n = 0; n < N; n++) {
		cin >> B[n];
		ans += B[n];
	}
	C.resize(N - 1);
	for (int n = 0; n < N - 1; n++)cin >> C[n];
	for (int n = 0; n < N - 1; n++) {
		if (A[n + 1] == A[n] + 1)ans += C[A[n]];
	}
	cout << ans << endl;
	return;
}

//////////////////////////////
//////////////////////////////

int main() {
#ifdef DEBUGTIME
	for (int time = 0; time < DEBUGTIME; time++) {
		solve();
		cout << "####################" << endl;
	}
#else
	solve();
#endif
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n, m, x;
    cin >> n >> m >> x;
    vector<int> carr(n);
    vector<vector<int>> aarr(n, vector<int>(m));
    for (int i = 0; i < n && (cin >> carr[i]); i++)
        for (int j = 0; j < m; j++)
            cin >> aarr[i][j];
    int min_cost = INT_MAX;
    int ss = (1 << n);
    while (ss--)
    {
        vector<int> algolvl(m, 0);
        int tmp_cost = 0;
        for (int i = 0; i < n; i++)
            if (((ss >> i) & 1) && (tmp_cost += carr[i]))
                for (int j = 0; j < m; j++)
                    algolvl[j] += aarr[i][j];
        bool fg = true;
        for (int j = 0; j < m; j++)
            if (algolvl[j] < x && !(fg = false))
                break;
        if (fg)
            min_cost = min(tmp_cost, min_cost);
    }
    if (min_cost == INT_MAX)
        cout << -1 << "\n";
    else
        cout << min_cost << "\n";
    return 0;
}

Measured memory_bytes: 3652
#pragma GCC optimize("Ofast")
#define _USE_MATH_DEFINES
#include "bits/stdc++.h"

using namespace std;

using u8 = uint8_t;
using u16 = uint16_t;
using u32 = uint32_t;
using u64 = uint64_t;
using i8 = int8_t;
using i16 = int16_t;
using i32 = int32_t;
using i64 = int64_t;

constexpr char newl = '\n';
constexpr double eps = 1e-10;

#define FOR(i,a,b) for (int i = (a); i < (b); i++)
#define F0R(i,b) FOR(i,0,b)
#define RFO(i,a,b) for (int i = ((b)-1); i >=(a); i--)
#define RF0(i,b) RFO(i,0,b)
#define fi first
#define se second
#define debug(x) cout << #x << ": " << x << '\n';
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()

template<typename T1, typename T2> inline void chmin(T1& a, T2 b) { if (a > b) a = b; }
template<typename T1, typename T2> inline void chmax(T1& a, T2 b) { if (a < b) a = b; }
template<class T> void Print(vector<T> v) {
  F0R(i, v.size()) {
    cout << v[i] << ' ';
  }
  cout << newl;
}

#if 1


// INSERT ABOVE HERE
signed main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);

  int N;
  cin >> N;
  vector<long double> vs(N);
  F0R(i, N) {
    cin >> vs[i];
  }
  sort(rng(vs));
  long double d = (vs[0] + vs[1]) / 2;

  FOR(i, 2, N) {
    d = (d + vs[i]) / 2;
  }

  cout << std::fixed << std::setprecision(15);
  cout << d;
}
#endif


Measured memory_bytes: 3820
#include <stdio.h>


int check(int a)
{
	int i;
	if(a < 2) return 0;
	else if(a == 2) return 1;
	if(a % 2 == 0)return 0;
	for( i = 3; i*i <= a; i++)
	{
		if( a % i == 0)
		{
			return 0;
		}
	}
	return 1;
}
int main(void)
{
	int n;
	scanf("%d",&n);
	int a[n] , i , count = 0;
	for( i = 0; i < n; i++)
	{
		scanf("%d",&a[i]);
		if(check(a[i])) count++;
	}
	printf("%d\n",count);
}


Measured memory_bytes: 2024
#include <bits/stdc++.h>
#include <vector>
#include <cstdint>
#define FOR(i,l,r) for(int i=(l);i<(r);++i)
#define RFOR(i,l,r) for(int i=(l);i>=(int)(r);i--)
#define rep(i,n)  FOR(i,0,n)
#define rrep(i,n)  RFOR(i,n-1,0)

#define int long long
using namespace std;
const int MX = 1e6;
const int inf = 1e9+5;
const int mod = 1e9+7;

signed main(){
    int n;
    cin >> n;
    rep(i,n) cout << "ACL" << flush;
    cout << "" << endl;

    return 0;
}


Measured memory_bytes: 3596
#include <iostream>
#include <string.h>
#include <vector>
#include <queue>
#include <algorithm>
#include <string>
#include <stack>
#include <set>
using namespace std;
typedef long long ll;
#define INF 1000000000 //1e9

int N;
int cnt[2][1000001];

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

	cin >> N;
	
	int a;
	for (int i = 1; i <= N; ++i) {
		cin >> a;
		cnt[i % 2][a]++;
	}

	int res = 0;
	int maxx[2][2] = { 0 }, maxxnum[2][2] = { 0 };
	for (int i = 0; i < 2; ++i) {
		for (int j = 1; j <= 1000000; ++j) {
			if (maxx[i][0] <= cnt[i][j]) {
				maxx[i][1] = maxx[i][0];
				maxxnum[i][1] = maxxnum[i][0];
				maxx[i][0] = cnt[i][j];
				maxxnum[i][0] = j;
			}
			else if (maxx[i][1] < cnt[i][j]){
				maxx[i][1] = cnt[i][j];
				maxxnum[i][1] = j;
			}
		}
	}

	if (maxxnum[0][0] == maxxnum[1][0]) {
		res = min(N - maxx[0][1] - maxx[1][0], N - maxx[0][0] - maxx[1][1]);
	}
	else res = N - maxx[0][0] - maxx[1][0];
	cout << res;
}


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

ll N;
bool test(ll n){
  string NN=to_string(N);
  string nn=to_string(n);
  bool flag=(n<=N&&nn<=NN);
  bool flag2=(n>N&&nn>NN);
  return (flag|flag2);
}

bool solve(ll x){
  //return test(x);
  cout<<"? "<<x<<endl;
  char c; cin>>c;
  return (c=='Y');
}

ll fact[12];
 
int main(){
  fact[0]=1;
  rep(i,11) fact[i+1]=fact[i]*10;
  //cin>>N;
  ll n=0;
  int keta=0;
  for(ll i=1;i<=1e10;i*=10){
    if(solve(i)) keta++;
    else break;
  }
  if(keta!=11){
    int first=1;
    rep(aaa,keta-1){
      int ok=first, ng=10;
      while(abs(ok-ng)>1){
        int mid=(ok+ng)/2;
        if(solve(n*10+mid)) ok=mid;
        else ng=mid;
      }
      n=n*10+ok;
      first=0;
    }
    int ok=0, ng=10;
    while(abs(ok-ng)>1){
      int mid=(ok+ng)/2;
      if(!solve(n*100+mid*10)) ok=mid;
      else ng=mid;
    }
    n=n*10+ng;
  }else{
    ll x=0;
    rep(i,11) x=x*10+9;
    keta=11;
    rep(i,11){
      if(solve(x)) keta--, x/=10;
      else break;
    }
    n=fact[keta];
  }
  cout<<"! "<<n<<endl;
  return 0;
}

Measured memory_bytes: 652
def main
  a, b = gets.chop.split.map(&:to_i)
  ans = 0
  if (b-1) % (a -1) == 0
    ans = (b - 1)/ (a - 1)
  else
    ans = (b -1 )/ (a - 1) + 1
  end
  puts ans
end

if __FILE__ == $0
  main
end



Measured memory_bytes: 1788
import java.util.Scanner;
 
class Main {
	int n;
	int[] d;
	
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		Main m = new Main(sc);
		m.solve();
		sc.close();
	}
	Main(Scanner sc){
		n = sc.nextInt();
		d = new int[n];
		for(int i=0;i<n;i++){
			d[i] = sc.nextInt();
		}
	}
	void solve(){
		boolean[] cnt = new boolean[100];
		for(int i=0;i<n;i++){
			cnt[d[i]-1] = true;
		}
		int dan = 0;
		for(boolean f : cnt){
			if(f) dan++;
		}
		System.out.println(dan);
	}
}

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

using namespace std;

int main(){
  	int n, x, actual=0, brick=0;
  	cin >> n;
  	
  	for(int i=0; i<n; i++){
    	cin >> x;
      	if(x==actual+1) actual++;
      	else brick++;
    }
  	
  	if(actual) cout << brick;
  	else cout << -1;
  
	return 0;
}

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


int main(){
  int N;
  vector<int> M(3);
  cin >> N >> M[0] >> M[1] >> M[2];
  vector<int> L(N);
  for(auto& l : L){
    cin >> l;
  }
  
  vector<int> P(N, 3);
  
  int ans = abs(M[0]-L[0]) + abs(M[1]-L[1]) + abs(M[2]-L[2]);
  int num = pow(4, N);
  for(int ii=0; ii<num; ii++){
    int tmp = ii;
    for(int jj=0; jj<N; jj++){
      P[jj] = tmp % 4;
      tmp /= 4;
    }
    int score = 0;
    vector<int> len(4, 0);
    for(int jj=0; jj<N; jj++){
      if(P[jj]!=3 && len[P[jj]]!=0){
        score += 10;
      }
      len[P[jj]] += L[jj];
    }
    if(len[0]==0 || len[1]==0 || len[2]==0){
      continue;
    }
    score += abs(len[0]-M[0]) + abs(len[1]-M[1]) + abs(len[2]-M[2]);
    ans = min(ans, score);
  }
  cout << ans << endl;
  
  return 0;
}

Measured memory_bytes: 256
while True:
	N= int(input())
	if N == 0:
		break
	D = {}
	di = []
	for n in range(N):
		e,p,q = input().split()
		p = int(p)
		q = int(q)
		if e not in di:
			di.append(e)
			D[e] = p * q
		else:
			D[e] = D[e] + p * q
	flag = 0
	for dj in di:
		if D[dj] >= 10**6:
			print(dj)
			flag = 1
	if flag == 0:
		print("NA")
	

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

typedef pair<int,vector<int>> P;

int main(){
	map<vector<int>,int> dist;
	priority_queue<P, vector<P>, greater<P>> q;
	
	vector<int> start(9),end = {1,2,3,4,5,6,7,8,0};
	for(int i=0; i<9; i++) cin>>start[i];
	
	dist[start] = 0;
	q.push(P(0,start));
	
	for(;q.size();){
		int cost = q.top().first;
		vector<int> now = q.top().second;
		q.pop();
		
		if(now==end){
			cout<<cost<<endl;
			break;
		}
		
		vector<vector<int>> next;
		int z = find(now.begin(), now.end(), 0) - now.begin();
		if(z > 2){
			vector<int> nx = now;
			swap(nx[z], nx[z-3]);
			next.push_back(nx);
		}
		if(z < 6){
			vector<int> nx = now;
			swap(nx[z], nx[z+3]);
			next.push_back(nx);
		}
		if(z % 3 > 0){
			vector<int> nx = now;
			swap(nx[z], nx[z-1]);
			next.push_back(nx);
		}
		if(z % 3 < 2){
			vector<int> nx = now;
			swap(nx[z], nx[z+1]);
			next.push_back(nx);
		}
		
		for(auto n : next){
			if(dist.find(n) == dist.end() || 1+cost < dist[n]){
				q.push(P(dist[n]=1+cost, n));
			}
		}
	}
}

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

namespace mp = boost::multiprecision;

using namespace std;

const double PI = 3.14159265358979323846;
typedef long long ll;
const double EPS = 1e-9;
#define rep(i, n) for (int i = 0; i < (n); ++i)
//#define rep(i, n) for (ll i = 0; i < (n); ++i)
//typedef pair<ll, ll> P;
typedef pair<double, double> P;
const ll INF = 10e17;
#define cmin(x, y) x = min(x, y)
#define cmax(x, y) x = max(x, y)
#define ret() return 0;

double equal(double a, double b) {
    return fabs(a - b) < DBL_EPSILON;
}

std::istream &operator>>(std::istream &in, set<int> &o) {
    int a;
    in >> a;
    o.insert(a);
    return in;
}

std::istream &operator>>(std::istream &in, queue<int> &o) {
    ll a;
    in >> a;
    o.push(a);
    return in;
}

bool contain(set<int> &s, int a) { return s.find(a) != s.end(); }

//ofstream outfile("log.txt");
//outfile << setw(6) << setfill('0') << prefecture << setw(6) << setfill('0') << rank << endl;
// std::cout << std::bitset<8>(9);
//const ll mod = 1e10;

typedef priority_queue<ll, vector<ll>, greater<ll> > PQ_ASK;

struct Sushi {
    ll t, d;
    bool first;
};


std::istream &operator>>(std::istream &in, Sushi &o) {
    cin >> o.t >> o.d;
    return in;
}

int gp(int i) {
    switch (i) {

        case 1:
            return 2;
        case 2:
            return 5;
        case 3:
            return 5;
        case 4:
            return 4;
        case 5:
            return 5;
        case 6:
            return 6;
        case 7:
            return 3;
        case 8:
            return 7;
        case 9:
            return 6;
    }
    __throw_runtime_error("konai");
}

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

    set<int> can;
    rep(i, m) cin >> can;

    vector<mp::cpp_int> dp(n + 100, -INF);
    dp[0] = 0;

    rep(i, n) {
        mp::cpp_int now = dp[i];

        for (int j : can) {
            int p = gp(j);
            int next_i = i + p;
            mp::cpp_int next_c = now;
            next_c *= 10;
            next_c += j;
            cmax(dp[next_i], next_c);
        }

    }
    cout << dp[n] << endl;

}

Measured memory_bytes: 14976
#include<bits/stdc++.h>
using namespace std;
#define AC ios::sync_with_stdio(false);cin.tie(0);
#define ll long long

int main(){
    AC
    int a,b,c,d;
    cin>>a>>b>>c>>d;
    int t=0;
    while(1)
    {
        c = c-b;
        if(c<=0)
        {
            t=1;
            break;
        }
        a = a-d;
        if(a<=0)
        {
            t=2;
            break;
        }
    }
    if(t==1) cout<<"Yes";
    if(t==2) cout<<"No";
}


Measured memory_bytes: 3624
<?php
$n=trim(fgets(STDIN));
$h=explode(" ",trim(fgets(STDIN)));
$ans=0;
$max=$h[0];
$i=1;
while($i<$n){
	if($h[$i]>=$max){
		$max=$h[$i];
	}else{
		$ans+=$max-$h[$i];
		$max=$h[$i];
	}
	$h[$i-1]=0;
	++$i;
}
echo $ans+$max;

Measured memory_bytes: 4728
#include<iostream>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<utility>
#include<vector>
#include<cmath>
#include<cstring>
#include<cstdio>
#include<time.h>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define mp make_pair
#define all(in) in.begin(),in.end()
const double PI=acos(-1);
const double EPS=1e-10;
using namespace std;
typedef long long ll;
typedef vector<int> vi;
int main(){
	int n,m;
	cin>>n>>m;
	vector<int>a(m);
	vector<int>out(n);
	rep(i,m)cin>>a[i];
	rep(i,m){
		int co=0;
		rep(j,n){
			int in;
			cin>>in;
			if(in==a[i])out[j]++;
			else co++;
		}
		out[a[i]-1]+=co;
	}
	rep(i,n)cout<<out[i]<<endl;
}

Measured memory_bytes: 1196
#include "bits/stdc++.h"
#include<unordered_map>
#include<unordered_set>
#pragma warning(disable:4996)
using namespace std;
using ld = long double;
const ld eps = 1e-9;

//// < "d:\d_download\visual studio 2015\projects\programing_contest_c++\debug\a.txt" > "d:\d_download\visual studio 2015\projects\programing_contest_c++\debug\b.txt"

map<long long int, int>soinnsuu(long long int a) {
	map<long long int, int>ans;
	for (long long i = 2; i*i <= a; ++i) {
		while (a%i == 0) {
			ans[i]++;
			a /= i;
		}
	}
	if (a != 1)ans[a]++;


	return ans;
}
int main() {
	while (1) {
		long long int L; cin >> L;
		if (!L)break;
		auto mp(soinnsuu(L));
		long long int ans = 1;
		for (auto m : mp) {
			ans *= (2 * m.second + 1);
		}
		cout << ans / 2 + 1 << endl;
	}
	return 0;
}

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

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

  ll x = min(a, b);
  ll y = max(a, b);
  for (int i=0; i<y; i++) {
    cout << x;
  }
  cout << endl;

  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

int main(void){
  int h[10],i,j,tmp;
  for(i=0;i<10;i++){
    scanf("%d",&h[i]);
  }
  for(j=0;j<9;j++){
    for(i=0;i<9-j;i++){
      if(h[i]<h[i+1]){
	tmp=h[i];
	h[i]=h[i+1];
	h[i+1]=tmp;
      }
    }
  }
  for(i=0;i<3;i++){
    printf("%d\n",h[i]);
  }
  return 0;
}

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

int main(){
  int n,m,a[10],tmp,nxt,dp[2][20];
  string id;

  cin >> n >> id >> m;
  for(int i=0;i<m;i++)cin >> a[i];
  reverse(id.begin(),id.end());

  for(int i=1;i<10;i++)dp[0][i] = 0;
  dp[0][0] = 1;

  for(int x=0;x<n;x++){
    int odd = x&1;
    for(int i=0;i<10;i++)dp[1-odd][i] = 0;
    if(id[x] == '*'){
      for(int i=0;i<m;i++){
	tmp = a[i];
	if(odd)tmp = (tmp*2)%10 + (tmp*2)/10;
	for(int j=0;j<10;j++){
	  nxt = (j+tmp)%10;
	  dp[1-odd][nxt] += dp[odd][j];
	}
      }
    }else{
      tmp = id[x] - '0';
      if(odd)tmp = (tmp*2)%10 + (tmp*2)/10;
      for(int j=0;j<10;j++){
	nxt = (j+tmp)%10;
	dp[1-odd][nxt] += dp[odd][j];
      }
    }
  }

  cout << dp[n&1][0] << endl;
}
      

Measured memory_bytes: 1332
while True:
    n = int(input())
    if not n:
        break

    puyos = []
    pre = int(input())
    cnt = 1
    for _ in range(n - 1):
        p = int(input())
        if pre != p:
            puyos.append((pre, cnt))
            pre = p
            cnt = 0
        cnt += 1
    puyos.append((pre, cnt))
    lp = len(puyos)

    min_puyo = n
    for i, puyo in enumerate(puyos):
        color, num = puyo
        if num == 2:
            continue
        tn, j = n, 1
        while True:
            if i - j < 0 or i + j >= lp:
                break

            tp_c, tp_n = puyos[i - j]
            up_c, up_n = puyos[i + j]
            if tp_c != up_c:
                break

            first_adjust = 0
            if j == 1:
                if num == 1:
                    first_adjust = 1
                else:
                    first_adjust = -1
                    tn -= 4

            dp = tp_n + up_n + first_adjust
            if dp < 4:
                break
            tn -= dp
            j += 1
        if min_puyo > tn:
            min_puyo = tn
    print(min_puyo)

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

using namespace std;
typedef long long ll;
typedef pair<ll, ll> p_ll;

template<class T>
void debug(T itr1, T itr2) { auto now = itr1; while(now<itr2) { cout << *now << " "; now++; } cout << endl; }
#define repr(i,from,to) for (ll i=(ll)from; i<(ll)to; i++)
#define all(vec) vec.begin(), vec.end()
#define rep(i,N) repr(i,0,N)
#define per(i,N) for (ll i=(ll)N-1; i>=0; i--)

const ll MOD = pow(10,9)+7;
const ll LLINF = pow(2,61)-1;
const ll INF = pow(2,30)-1;

vector<ll> fac;
void c_fac(ll x=pow(10,6)+10) { fac.resize(x,true); rep(i,x) fac[i] = i ? (fac[i-1]*i)%MOD : 1; }
ll inv(ll a, ll m=MOD) { ll b = m, x = 1, y = 0; while (b!=0) { ll d = a/b; a -= b*d; swap(a,b); x -= y*d; swap(x,y); } return (x+m)%m; }
ll nck(ll n, ll k) { return fac[n]*inv(fac[k]*fac[n-k]%MOD)%MOD; }
ll modpow(ll x, ll p) { ll result = 1, now = 1, pm = x; while (now<=p) { if (p&now) { result = result * pm % MOD; } now*=2; pm = pm*pm % MOD; } return result; }
ll gcd(ll a, ll b) { if (a<b) swap(a,b); return b==0 ? a : gcd(b, a%b); }
ll lcm(ll a, ll b) { return a/gcd(a,b)*b; }


int main() {
  ll K; cin >> K;
  string result; rep(i,K) result += "ACL";
  cout << result << endl;
  return 0;
}

Measured memory_bytes: 3624
#include <float.h>
#include <limits.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>

// 内部定数
#define D_PTN_MAX		50000									// 最大パターン数
#define D_SIZE_MAX		8										// 最大サイズ

// 内部変数
static FILE *szpFpI;											// 入力
static int siSize;												// サイズ
static int si2Ptn[D_PTN_MAX][D_SIZE_MAX];						// パターン
static int siPCnt;												// パターン数

// 内部変数 - テスト用
#ifdef D_TEST
	static int siRes;
	static FILE *szpFpA;
	static int siTNo;
#endif

// １行出力
int
fOutLine(
	char *pcpLine				// <I> １行
)
{
	char lc1Buf[1024];

#ifdef D_TEST
	lc1Buf[0] = '\0';
	fgets(lc1Buf, sizeof(lc1Buf), szpFpA);
	if (strcmp(lc1Buf, pcpLine)) {
		siRes = -1;
	}
#else
	printf("%s", pcpLine);
#endif

	return 0;
}

// パターン - 作成
int
fMakePtn(
	int *pipSel					// <I> 選択内容
	, int piSCnt				// <I> 選択数
)
{
	int i, j;

	// 選択終了
	if (piSCnt == siSize) {
		memcpy(si2Ptn[siPCnt], pipSel, sizeof(int) * siSize);
		siPCnt++;
		return 0;
	}

	// 選択
	for (i = 1; i <= siSize; i++) {

		// 選択済みかチェック
		for (j = 0; j < piSCnt; j++) {
			if (i == pipSel[j]) {
				break;
			}
		}
		if (j < piSCnt) {
			continue;
		}

		// 選択
		pipSel[piSCnt] = i;
		fMakePtn(pipSel, piSCnt + 1);
	}

	return 0;
}

// 位置 - 取得
int
fGetPos(
)
{
	int i;
	char lc1Buf[1024];

	// 数列 - 取得
	int li1Val[D_SIZE_MAX];
	for (i = 0; i < siSize; i++) {
		fscanf(szpFpI, "%d", &li1Val[i]);
	}
	fgets(lc1Buf, sizeof(lc1Buf), szpFpI);

	// 検索
	for (i = 0; i < siPCnt; i++) {
		if (!memcmp(li1Val, si2Ptn[i], sizeof(int) * siSize)) {
			return i;
		}
	}

	return -1;
}

// 実行メイン
int
fMain(
)
{
	char lc1Buf[1024];

	// サイズ - 取得
	fgets(lc1Buf, sizeof(lc1Buf), szpFpI);
	sscanf(lc1Buf, "%d", &siSize);

	// パターン - 作成
	int li1Sel[D_SIZE_MAX];
	fMakePtn(li1Sel, 0);

	// 位置 - 取得
	int liNo1 = fGetPos();
	int liNo2 = fGetPos();

	return abs(liNo1 - liNo2);
}

// １回実行
int
fOne(
)
{
	int liRet;
	char lc1Buf[1024];

	// データ - 初期化
	siPCnt = 0;													// パターン数

	// 入力 - セット
#ifdef D_TEST
	sprintf(lc1Buf, ".\\Test\\T%d.txt", siTNo);
	szpFpI = fopen(lc1Buf, "r");
	sprintf(lc1Buf, ".\\Test\\A%d.txt", siTNo);
	szpFpA = fopen(lc1Buf, "r");
	siRes = 0;
#else
	szpFpI = stdin;
#endif

	// 実行メイン
	liRet = fMain();

	// 出力
	sprintf(lc1Buf, "%d\n", liRet);
	fOutLine(lc1Buf);

	// 残データ有無
#ifdef D_TEST
	lc1Buf[0] = '\0';
	fgets(lc1Buf, sizeof(lc1Buf), szpFpA);
	if (strcmp(lc1Buf, "")) {
		siRes = -1;
	}
#endif

	// テストファイルクローズ
#ifdef D_TEST
	fclose(szpFpI);
	fclose(szpFpA);
#endif

	// テスト結果
#ifdef D_TEST
	if (siRes == 0) {
		printf("OK %d\n", siTNo);
	}
	else {
		printf("NG %d\n", siTNo);
	}
#endif

	return 0;
}

// プログラム開始
int
main()
{

#ifdef D_TEST
	int i;
	for (i = D_TEST_SNO; i <= D_TEST_ENO; i++) {
		siTNo = i;
		fOne();
	}
#else
	fOne();
#endif

	return 0;
}



Measured memory_bytes: 1408
#include<bits/stdc++.h>
using namespace std;
#define pii pair<int,int>
#define mp make_pair

int n,cnt;
int x[55],y[55];
vector<pii> v;

int main()
{
	
	cin>>n;
	for(int i=0;i<n;i++)
		cin>>x[i]>>y[i];
	for(int i=0;i<n;i++)
	for(int j=i+1;j<n;j++)
	{
		int a=x[i]-x[j];
		int b=y[i]-y[j];
		if(a<=0)
		{
			a=-a;
			b=-b;
			if(a==0) b=abs(b);
		}
		v.push_back(mp(a,b));
	}
	sort(v.begin(),v.end());
	//for(int i=0;i<v.size();i++)
	//	cout<<v[i].first<<" "<<v[i].second<<'\n';
	for(int i=0,sum=1;i<v.size();i++)
		if(v[i]!=v[i+1] || i==v.size()-1)
		{
			cnt=max(cnt,sum);
			sum=1; 
		}
		else sum++;
	cout<<n-cnt<<'\n'; 
	
	return 0;
}
/*
5
0 0
1 2
2 2
2 3
3 3
*/ 

Measured memory_bytes: 256
import math

def comb_count(n, r):
    return math.factorial(n) // math.factorial(r) // math.factorial(n - r)

S = input()[::-1]
ans = 0

mods = [0] * 2019 #余りが0~2018
mods[0] = 1
current = 0
tmp = 1

for i in range(len(S)):
    current = int(S[i]) * tmp + current
    mod = current % 2019
    mods[mod] += 1
    tmp = tmp * 10 % 2019

for mod in mods:
    if mod > 1:
        ans += comb_count(mod, 2)

print(ans)


Measured memory_bytes: 9544
#include <iostream>
#include <map>
#include <utility>
using namespace std;

int main() {
	int N, M;
	cin >> N >> M;
	map<int, pair<int, int>> ma;
	for (int i = 0; i < M; i++) {
		int p;
		string S;
		cin >> p >> S;
		if (S == "WA") {
			if (ma[p].first == 0) {
				ma[p].second++;
			}
		} else {
			if (ma[p].first == 1) continue;
			ma[p].first++;
		}
	}

	int AC_cnt = 0, WA_cnt = 0;
	for (auto x : ma) {
		int pre = AC_cnt;
		AC_cnt += x.second.first;
		if (pre != AC_cnt) {
			WA_cnt += x.second.second;
		}
	}

	printf("%d %d\n", AC_cnt, WA_cnt);
}

Measured memory_bytes: 6528
import java.util.Scanner;
import java.util.stream.IntStream;

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

        String S = sc.next();

        System.out.println(solve(S));

        sc.close();
    }

    static int solve(String S) {
        return Math.min(computeRepaintNum(S, '0'), computeRepaintNum(S, '1'));
    }

    static int computeRepaintNum(String S, char evenTarget) {
        return (int) IntStream.range(0, S.length()).filter(i -> (i % 2 == 0) == (S.charAt(i) != evenTarget)).count();
    }
}

Measured memory_bytes: 39860
#include<bits/stdc++.h> 
using namespace std;
long long n,i,j,ans,sum,num[100005];
string s[100005],now;
int main(){
	scanf("%lld\n",&n);
	for(i=0;i<n;i++){
		cin>>s[i];
		sort(s[i].begin(),s[i].end());
	}
	sort(s,s+n);
	for(i=0;i<n;i++){
		if(now!=s[i]){ 
			now=s[i];
			num[sum]=1;
			sum++;
		}
		else num[sum-1]++;
	}
	for(i=0;i<sum;i++)
		ans+=(num[i]*(num[i]-1))/2;
	printf("%lld",ans);
	return 0;
}

Measured memory_bytes: 8064