akhauriyash/Code-Regression huggingface dataset:
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <cstdio>
#include <vector>
#include <cmath>
#include <cstring>
#include <numeric>
#include <algorithm>
#include <fstream>
#include <functional>
#include <array>
#include <map>
#include <queue>
#include <time.h>
#include <limits.h>
#include <set>
#include <stack>
#include <random>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#define rep(i,s,n) for(int i = (s); (n) > i; i++)
#define REP(i,n) rep(i,0,n)
#define RANGE(x,a,b) (min(a,b) <= (x) && (x) <= max(a,b)) //hei
#define DUPLE(a,b,c,d) (RANGE(a,c,d) || RANGE(b,c,d) || RANGE(c,a,b) || RANGE(d,a,b))
#define INCLU(a,b,c,d) (RANGE(a,c,d) && (b,c,d))
#define PW(x) ((x)*(x))
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define MODU 1000000007LL
#define bitcheck(a,b)   ((a >> b) & 1)
#define bitset(a,b)      ( a |= (1 << b))
#define bitunset(a,b)    (a &= ~(1 << b))
#define MP(a,b) make_pair((a),(b))
#define Manh(a,b) (abs((a).first-(b).first) + abs((a).second - ((b).second))
#define pritnf printf
#define scnaf scanf
#define itn int
#define PI 3.141592653589


#define izryt bool
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
template<typename A, size_t N, typename T>
void Fill(A(&array)[N], const T& val) {
	std::fill((T*)array, (T*)(array + N), val);
}
pll Dir[4] = {
	{ -1 ,0 },{ 0 , 1 },{ 1 ,0 },{ 0 ,-1 }
};

//[a, b)
#define Getsum(ar, a,b) (ar[b] - ar[a])
#define chmax(a,b) a = max(a,b)
#define chmin(a,b) a = min(a,b)

struct Edge {
	int from, to;
	ll w;
	bool operator<(const Edge& rhs) const {
		return MP(w, MP(from, to)) < MP(rhs.w, MP(rhs.from, rhs.to));
	}

};
typedef vector<vector<Edge>> Graph;

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

ll factorial(ll n) {//階乗
	ll ret = 1;
	rep(i, 1, n + 1)
		ret = (ret * i) % MODU;

	return ret;
}

ll mod_pow(ll x, ll n, ll mod) {
	ll res = 1;
	while (n > 0) {
		if (n & 1) res = res * x % mod;
		x = x * x % mod;
		n >>= 1;
	}
	return res;
}
ll divmod(ll a, ll b, ll m) { // a/b(mod m)
								  // a/b (mod m)
								  // a*b^-1
								  // b^-1 * b = 1
								  // b^(m-1) = 1 
								  // b^(m-2) * b = 1
								  // b^-1 = b^(m-2)

								  // a/b = a * b^(m-2)

	return (a * 1LL * mod_pow(b, m - 2, m)) % m;
}
ll ncr(ll n, ll r) {
	return divmod(factorial(n), (factorial(r) * (factorial(n - r))) % MODU, MODU);
}


signed main() {
	string bef, aft;
	cin >> aft;

	int n;
	cin >> n;
	bool a = 0;
	REP(i, n) {
		int t;
		cin >> t;
		if (t == 1) {
			a = !a;
		}
		else {
			int f;
			char c;
			cin >> f >> c;
			f--;
			f ^= a;
			if (f == 0) bef += c;
			else aft += c;
		}
	}
	
	reverse(bef.begin(), bef.end());
	bef += aft;

	if(a)
		reverse(bef.begin(), bef.end());
	cout << bef << endl;

	return 0;
}


Measured memory_bytes: 1128
(let* ((n (read))
    (k (read))
    (a (make-array n :initial-element 0))
    (hyoten (make-array k :initial-element 1)))

    (dotimes (i n)
        (setf (aref a i) (read))
    )

    (loop for i below (- n k) do
            (if (< (aref a i) (aref a (+ i k)))
                (format t "Yes~%")
                (format t "No~%")
            )
    )
)

Measured memory_bytes: 77928
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scan = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        long R = scan.nextLong();
        long D = scan.nextLong();
        long x = scan.nextLong();
        for (int i = 0; i < 10; i++) {
            x = R * x - D;
            System.out.println(x);
        }
    }
}


Measured memory_bytes: 22996
#include<bits/stdc++.h>
using namespace std;
long N,A,B,C,l[9],ans=LONG_MAX;

void dfs(int n,int a,int b,int c,int v){
  if(n==N){
    if(a&&b&&c)ans=min(ans,abs(a-A)+abs(b-B)+abs(c-C)+v);
    return;
  }
  dfs(n+1,a,b,c,v);
  dfs(n+1,a+l[n],b,c,v+10*(a>0));
  dfs(n+1,a,b+l[n],c,v+10*(b>0));
  dfs(n+1,a,b,c+l[n],v+10*(c>0));
}

int main(void){
  cin>>N>>A>>B>>C;
  for(int i=0;i<N;i++)cin>>l[i];
  dfs(0,0,0,0,0);
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 256
import sys, os, math, bisect, itertools, collections, heapq, queue
# from scipy.sparse.csgraph import csgraph_from_dense, floyd_warshall
from decimal import Decimal
from collections import defaultdict, deque

# import fractions

sys.setrecursionlimit(10000000)

ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
fl = lambda: list(map(float, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]

iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split()))
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]

lcm = lambda x, y: (x * y) // math.gcd(x, y)
# lcm = lambda x, y: (x * y) // fractions.gcd(x, y)

MOD = 10 ** 9 + 7
MAX = float('inf')


def calc_health(x, p):
    return (x - p) ** 2


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

    N = ii()
    X = il()

    ret = MAX
    for p in range(0, 101):
        sm = 0
        for x in X:
            sm += calc_health(x, p)
        ret = min(ret, sm)
    print(ret)


if __name__ == '__main__':
    main()


Measured memory_bytes: 10228
#include <bits/stdc++.h>
#define fastio (cin.tie(0), cout.tie(0), ios::sync_with_stdio(false))
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define precise(i) fixed << setprecision(i)
using namespace std;

int main() {
    fastio;
    int n, a;
    cin >> n >> a;
    n %= 500;
    if (n <= a)
        cout << "Yes";
    else
        cout << "No";
}

Measured memory_bytes: 3648
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll memo[3001][3001];

ll dequeMax(int i,int j, vector<ll>& arr){
	if(i == j){
		return arr[i];
	}
	if(memo[i][j] != -1) return memo[i][j];

	return memo[i][j] = max(arr[i] - dequeMax(i+1,j,arr), arr[j] - dequeMax(i,j-1,arr));
}


int main(){
	ll N;
	cin>>N;
	vector<ll>arr(N);

	for(ll i = 0; i < N; ++i){
		cin>>arr[i];
	}
	memset(memo, -1, sizeof(memo));
	cout<<dequeMax(0,arr.size()-1,arr);
}

Measured memory_bytes: 74244
import sys
import math
import itertools


def solv(n):
    fact = math.factorial(n)
    fact = list(str(fact))
    fact.reverse()
    r = 0
    for i in itertools.takewhile(lambda x: x == '0', fact):
        r += 1
    return r



while True:
    n = int(sys.stdin.readline())
    if n == 0:
        exit()
    print solv(n)

Measured memory_bytes: 4776
def main():
    n = int(input())
    friendliness = [int(x) for x in input().split()]
    friendliness.sort(reverse=True)
    ans = 0
    for i in range(1, n):
        ans += friendliness[i // 2]
    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 31436
#include<stdio.h>

int main(void){
  int i;
  int climbway[30];
  int stair;

  climbway[0]=1;
  climbway[1]=2;
  climbway[2]=4;
  for(i=3;i<30;i++){
    climbway[i]=
      climbway[i-1]
      +climbway[i-2]
      +climbway[i-3];
  }

  for(i=0;i<30;i++){
    if(climbway[i]%3650==0){
      climbway[i]/=3650;
    }else{
      climbway[i]/=3650;
      climbway[i]++;
    }
  }

  for(;;){
    scanf("%d",&stair);
    if(stair==0)
      break;

    printf("%d\n",climbway[stair-1]);
  }

  return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
#define endl "\n"
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
using ll = long long;
const int INF = 0x3f3f3f3f;
using namespace std;
const double PI = acos(-1);
const int N = 1e5+1;

int n;
ll arr[3001];
ll dp[3001][3001], sm;

ll solve(int i = 0, int j = n-1) {
    if (i > j) {
        return 0;
    }
    ll& ret = dp[i][j];
    if (~ret) {
        return ret;
    }
    return ret = max(arr[i] + min(solve(i+1, j-1), solve(i+2, j)), arr[j] + min(solve(i+1, j-1), solve(i, j-2)));
}
int main() {
    //freopen("lazy.in", "r", stdin);
    IOS
    cin >> n;
    for (int i = 0; i < n; ++i) {
        cin >> arr[i];
        sm += arr[i];
    }
    memset(dp, -1, sizeof dp);
    ll ans = solve();
    cout << ans-(sm-ans) << endl;
    return 0;


}


Measured memory_bytes: 70784
#include<bits/stdc++.h>
#define rep(i, n) for(int i = 0;i < (int)n;i++)
#define repb(i, n) for(int i = (int)n;i >= 0;i--)
#define reps(i, m, n) for(int i = (int)m;i < (int)n;i++)
#define repsb(i, m, n) for(int i = (int)m;i >= (int)n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define pb(a) push_back(a)
#define INF 999999999999999999

using namespace std;
int dy[]={0, 0, 1, -1, 0};
int dx[]={1, -1, 0, 0, 0};
using namespace std;
int main(int argc, char const *argv[]) {
  int t;
  cin>>t;
  if(t<1200){
      cout<<"ABC"<<endl;
      return  0;
    }
  if(t<2800){
     cout<<"ARC"<<endl;
     return 0;
   }
  else  cout<<"AGC"<<endl;
  return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<cmath>
#include<queue>
#include<vector>
#include<ctime>
#include<map>
#include<bitset>
#define LL long long
#define mp(x,y) make_pair(x,y)
#define pll pair<long long,long long>
#define pii pair<int,int>
using namespace std;
inline LL read()
{
	LL f=1,x=0;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;
}
int stack[20];
inline void write(int x)
{
	if(x<0){putchar('-');x=-x;}
    if(!x){putchar('0');return;}
    int top=0;
    while(x)stack[++top]=x%10,x/=10;
    while(top)putchar(stack[top--]+'0');
}
inline void pr1(int x){write(x);putchar(' ');}
inline void pr2(int x){write(x);putchar('\n');}
const int MAXN=1000005;
const int MAXM=21;
const int MAXMASK=(1<<16);
const LL mod=1e9+7;
int bin[MAXM];
LL pre[MAXN],inv[MAXN];
LL pow_mod(LL a,LL b)
{
	LL ret=1;
	while(b)
	{
		if(b&1)ret=ret*a%mod;
		a=a*a%mod;b>>=1;
	}
	return ret;
}
LL C(int n,int m){return pre[n]*inv[m]%mod*inv[n-m]%mod;}
int n,m,a[MAXM];
int f[MAXM][MAXMASK],ct[MAXMASK];
void ad(int &x,int y){x+=y;if(x>=mod)x-=mod;}
void dl(int &x,int y){x-=y;if(x<0)x+=mod;}
int main()
{
	pre[0]=1;for(int i=1;i<MAXN;i++)pre[i]=pre[i-1]*i%mod;
	inv[MAXN-1]=pow_mod(pre[MAXN-1],mod-2);
	for(int i=MAXN-2;i>=0;i--)inv[i]=inv[i+1]*(i+1)%mod;
	bin[1]=1;for(int i=2;i<=20;i++)bin[i]=bin[i-1]<<1;
	for(int i=0;i<MAXMASK;i++)
		for(int j=1;j<=16;j++)if(i&bin[j])ct[i]+=bin[j];
	
	n=read();m=read();
	for(int i=1;i<=m;i++)a[i]=read();
	sort(a+1,a+1+m);reverse(a+1,a+1+m);
	f[0][0]=1;
	for(int i=1;i<=m;i++)
		for(int k=0;k<bin[n+1];k++)
		{
			ad(f[i][k],f[i-1][k]);
			for(int j=1;j<=n;j++)if(!(k&bin[j]))
			{
				if(bin[n+1]-a[i]+1-k>=bin[j])
					ad(f[i][k|bin[j]],(LL)f[i-1][k]*C(bin[n+1]-a[i]-k,bin[j]-1)%mod*pre[bin[j]]%mod);
			}
		}
	int ans=0;
	for(int i=0;i<bin[n+1];i++)
	{
//		printf("%d ",f[m][i]);
		int u1=(LL)f[m][i]*pre[bin[n+1]-i-1]%mod,u2=0;
		for(int j=1;j<=n;j++)if(i&bin[j])u2++;
		if(u2&1)dl(ans,u1);
		else ad(ans,u1);
	}
	ans=(LL)ans*bin[n+1]%mod;
	pr2(ans);
	return 0;
}

Measured memory_bytes: 21120
#include <iostream>
#include <iomanip>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <queue>
#include <algorithm>
#include <functional>
#include <numeric>
#include <set>
#include <map>
#include <list>
#include <bitset>
#define debug(x) cout << #x << ": " << (x) << endl
using namespace std;

const double PI  = 3.141592653589793238463;
const int INF = 1000000007;

using ull = unsigned long long;
using ll = long long;

using Int = int;
using Double = double;

using P = pair<Int, Int>;
using V = vector<Int>;
using M = vector<V>;

int move(int now, int path, int m, V& ds, M& vss, V& ds_index){
    int next = 0;
    for(int r = 0; r < m; r++){
        if(now & (1 << r)){
            int d = ds_index[vss[ds[r]][path]];
            if(d != -1){
                next |= 1 << d;
            }
        }
    }
    return next;
}

int solve(int n, int m, int k, V& ds, M& vss){
    V ds_index(n, -1);
    for(int i = 0; i < m; i++){
        ds_index[ds[i]] = i;
    }
    V dp(1 << m, -1);
    dp[(1 << m) - 1] = 0;
    queue<int> rs;
    rs.push((1 << m) - 1);
    while(!rs.empty()){
        int now = rs.front();
        rs.pop();
        for(int i = 0; i < k; i++){
            int next = move(now, i, m, ds, vss, ds_index);
            if(dp[next] == -1){
                dp[next] = dp[now] + 1;
                rs.push(next);
            }
            if(next == 0){
                return dp[next];
            }
        }
    }
    return -1;
}


int main(int argc, char* argv[]){
    cin.tie(0);
    ios::sync_with_stdio(false);

    int n, m, k;
    cin >> n >> m >> k;
    V ds(m);
    for(int i = 0; i < m; i++){
        cin >> ds[i];
        ds[i]--;
    }
    M vss(n, V(k));
    for(int i = 0; i < n; i++){
        for(int j = 0; j < k; j++){
            cin >> vss[i][j];
            vss[i][j]--;
        }
    }

    cout << solve(n, m, k, ds, vss) << "\n";

    return 0;
}

Measured memory_bytes: 3456
import sys,math,collections,itertools
input = sys.stdin.readline

N,K=list(map(int,input().split()))
A =[0]+list(map(int,input().split()))
town = 1
town_list = [1]
towntown = [0]*(N+1)
towntown[1]=1
count = 0
while True:
    town = A[town]
    count +=1
    if count == K:
        print(town)
        exit()
    if towntown[town] == 0:
        town_list.append(town)
        towntown[town] =1
    else:
        roop_town_num = town
        break
    
l_ini_index = town_list.index(roop_town_num)
len_roop = len(town_list)-l_ini_index 

if K <= l_ini_index:
    print(town_list[K])
else:
    print(town_list[((K-l_ini_index)%len_roop+l_ini_index)])
    


Measured memory_bytes: 33928
#![allow(dead_code)]
fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}
fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>().split_whitespace()
        .map(|e| e.parse().ok().unwrap()).collect()
}
fn read_vec2<T: std::str::FromStr>(n: u32) -> Vec<Vec<T>> {
    (0..n).map(|_| read_vec()).collect()
}
fn main() {
    let k: usize = read();
    let s: String = read();
    if s.len() <= k { println!("{}", s); }
    else { println!("{}...", &s[..k]); }
}

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

namespace Competition
{
    class Program
    {
        static void Main(string[] args)
        {
            var s = Console.ReadLine();
            var t = Console.ReadLine();

            var can = new List<char[]>();
            for(var i = 0; i < s.Length - t.Length + 1; i++)
            {
                var ok = true;
                for(var j = 0; j < t.Length; j++)
                {
                    if (s[i + j] != '?' && s[i + j] != t[j]) ok = false;
                }
                if (ok)
                {
                    var ns = new char[s.Length];
                    for (var n = 0; n < s.Length; n++) ns[n] = s[n];
                    for (var n = 0; n < t.Length; n++) ns[i+n] = t[n];
                    can.Add(ns);
                }
            }
            if(can.Count == 1)
            {
                for(var i = 0; i < s.Length; i++)
                {
                    if (can[0][i] == '?') can[0][i] = 'a';
                }
                for (var i = 0; i < s.Length; i++)
                {
                    if (can[0][i] == '?') can[0][i] = 'a';
                }
                Console.WriteLine(can[0]);
            }
            else if(can.Count > 1)
            {
                for(var i = 0; i < s.Length; i++)
                {
                    var min = 1 << 29;
                    for(var j = 0;  j < can.Count; j++)
                    {
                        if(min >= can[j][i] || can[j][i] == '?')
                        {
                            min = can[j][i];
                        }
                    }
                    for (var j = 0; j < can.Count; j++)
                    {
                        if (min < can[j][i] && can[j][i] != '?')
                        {
                            can.RemoveAt(j);
                        }
                    }
                    if (can.Count == 1) break;
                }
                for (var i = 0; i < s.Length; i++)
                {
                    if (can[0][i] == '?') can[0][i] = 'a';
                }
                Console.WriteLine(can[0]);
            }
            else
            {
                Console.WriteLine("UNRESTORABLE");
            }
        }
    }
}


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

int main() {
    int N, M, A;
    cin >> N >> M;

    int sum = 0;
    for(int i = 0; i < M; i++) {
        cin >> A;
        sum += A;
    }

    if (sum > N) cout << -1 << endl;
    else cout << N - sum << endl;

}

Measured memory_bytes: 3636
#include<iostream>
#include<string>
#include<stdio.h>
#include<cctype>
#include<algorithm>
#include<climits>
#include<cmath>
#include<map>
#include<vector>
#define INF INT_MAX
using namespace std;

int ans;
int K, X;

int main() {
	cin >> K >> X;
	
	if (K == 1) {
		cout << X << endl;
		return 0;
	}

	for (int i = X - K + 1; i < K + X - 1; i++) {
		cout << i << " ";
	}

	cout << X + K - 1 << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long int
#define ull unsigned long long int
#define ld long double
#define mod 1000000007
#define FT() int t; scanf("%d",&t); while(t--)
#define pb push_back
#define nl printf("\n")
#define fi(i,start,end) for(int i=start; i < (int)end ; ++i)
#define ip(n)   scanf("%d",&n)
#define mz(a)   memset(a,0,sizeof(a))
#define inpArr(A,n) fi(i,0,n)   ip(A[i]);
#define print(a)  for(auto i : a)   cout<<i<<" "; nl;
#define Fastio ios_base::sync_with_stdio(false); cin.tie(NULL);
using namespace std;
ll max(ll a,ll b)   {return a>b?a:b;}
ll min(ll a,ll b)   {return a<b?a:b;}

int main() {
  
    //std::cout << std::fixed;
    //std::cout << std::setprecision(6);
    Fastio;
    int testcase = 1;
    //cin>>testcase;
    while(testcase--)
    {
        int n,x,t;
        cin>>n>>x>>t;
        ll s = (n/x + bool(n%x))*t;
        cout<<s;
    }

    
    return 0;
}

Measured memory_bytes: 3604
n = int(input())
arr = sorted([list(map(int, input().split())) for _ in range(n)])
d = {}

if n == 1:
  print(1)
  exit()
  
for i in range(n):
  for j in range(i+1, n):
    x = (arr[j][0]-arr[i][0], arr[j][1]-arr[i][1])
    if x in d:
      d[x] += 1
    else:
      d[x] = 1

print(n-max(d.values()))      

Measured memory_bytes: 3188
import sys


class Bit:
    def __init__(self, n):
        self.size = n
        self.tree = [0] * (n + 1)

    def sum(self, i):
        s = 0
        while i > 0:
            s += self.tree[i]
            i -= i & -i
        return s

    def add(self, i, x):
        while i <= self.size:
            self.tree[i] += x
            i += i & -i


def main():
    n, q = map(int, sys.stdin.buffer.readline().split())
    bit = Bit(n)
    a = list(map(int, sys.stdin.buffer.readline().split()))
    for i in range(n):
        bit.add(i+1, a[i])
    for x in sys.stdin.buffer.readlines():
        q, p, x = map(int, x.split())
        if q:
            print(bit.sum(x) - bit.sum(p))
        else:
            bit.add(p+1, x)


if __name__ == "__main__":
    main()


Measured memory_bytes: 170940
#include <bits/stdc++.h>
#define maxi 1000000 
#define INF 1000000007
using namespace std;

typedef long long ll;
typedef pair<int,int> P;

struct edge{
	int to,cap,cost,rev;
	edge(){}
	edge(int tt,int cc,int co,int rr){
		to=tt;
		cap=cc;
		cost=co;
		rev=rr;
	}
};

vector<edge> G[1000];
int V;
int h[1001];
int dist[1001];
int prevv[1001],preve[1001];

void add_edge(int from,int to,int cap,int cost){
	G[from].push_back(edge(to,cap,cost,G[to].size()));
	G[to].push_back(edge(from,0,-cost,G[from].size()-1));
}

int min_cost_flow(int s,int t,int f){
	int res=0;
	fill(h,h+V,0);
	while(f>0){
		priority_queue<P,vector<P>,greater<P> > que;
		fill(dist,dist+V,INF);
		dist[s]=0;
		que.push(P(0,s));
		while(que.size()){
			P p=que.top();
			que.pop();
			int v=p.second;
			if(dist[v]<p.first)continue;
			for(int i=0;i<G[v].size();i++){
				edge &e=G[v][i];
				if(e.cap>0 && dist[e.to]>dist[v]+e.cost+h[v]-h[e.to]){
					dist[e.to]=dist[v]+e.cost+h[v]-h[e.to];
					prevv[e.to]=v;
					preve[e.to]=i;
					que.push(P(dist[e.to],e.to));
				}
			}
		}
		if(dist[t]==INF)return -1;
		for(int v=0;v<V;v++){
			h[v]+=dist[v];
		}
		int d=f;
		for(int v=t;v!=s;v=prevv[v]){
			d=min(d,G[prevv[v]][preve[v]].cap);
		}
		f-=d;
		res+=d*h[t];
		for(int v=t;v!=s;v=prevv[v]){
			edge &e=G[prevv[v]][preve[v]];
			e.cap-=d;
			G[v][e.rev].cap+=d;
		}
	}
	return res;
}

int n;
int d[101][3];

int main(void){
	while(1){
		scanf("%d",&n);
		if(n==0)break;
		int all=0;
		for(int i=0;i<n;i++){
			scanf("%d%d%d",&d[i][0],&d[i][1],&d[i][2]);
			sort(d[i],d[i]+3);
			all+=d[i][0]*d[i][1]*d[i][2];
		}
		int s=n*2,t=s+1;
		V=t+1;
		for(int i=0;i<=t;i++){
			G[i].clear();
		}
		for(int i=0;i<n;i++){
			add_edge(s,i,1,0);
			add_edge(i+n,t,1,0);
			for(int j=0;j<n;j++){
				bool flag=true;
				for(int k=0;k<3;k++){
					if(d[i][k]<=d[j][k])flag=false;
				}
				if(flag){
					add_edge(i,n+j,1,maxi-d[j][0]*d[j][1]*d[j][2]);
				}
			}
		}
		int res=0;
		for(int i=0;i<n;i++){
			int v=min_cost_flow(s,t,1);
			if(v>=0){
				res+=maxi-v;
			}
		}
		printf("%d\n",all-res);
	}
	return 0;
}

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

int main(){
	ll n;
	cin >> n;
	vector<ll> a(n);
	vector<vector<ll>> idx(n);
	rep(i,n){
		cin >> a[i];
		idx[--a[i]].push_back(i);
	}
	
	
	bool isOK = false;
	rep(i,n){
		if(a[i] == 0){
			isOK = true;
			break;
		}
	}
	if(!isOK){
		cout << -1 << endl;
		return 0;
	}
	
	isOK = true;
	rep(i,n){
		if(a[i] != i){
			isOK = false;
			break;
		}
	}
	if(isOK){
		cout << 0 << endl;
		return 0;
	}
	
	// 1がある
	ll cnt = 0;
	ll now = idx[0][0]; // 最初の1の場所
	rep(i,n-1){
		cnt++;
		if(idx[i+1].size() == 0) break;
		auto next = lower_bound(idx[i+1].begin(), idx[i+1].end(), now);
		if(next == idx[i+1].end()) break;
		else now = *next;
	}
	
	
	cout << n-cnt << endl;
	return 0;
}

Measured memory_bytes: 12800
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

func scanInt() int {
	sc.Scan()
	i, _ := strconv.Atoi(sc.Text())
	return i
}

func scanInt64() int64 {
	sc.Scan()
	i, _ := strconv.ParseInt(sc.Text(), 10, 64)
	return i
}

func scanInts(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ {
		res[i] = scanInt()
	}
	return res
}

func scanInts64(n int) []int64 {
	res := make([]int64, n)
	for i := range res {
		res[i] = scanInt64()
	}
	return res
}

var sc = bufio.NewScanner(os.Stdin)

type graph struct {
	d map[int][]int
}

func main() {
	sc.Split(bufio.ScanWords)
	INF := 1000000000000

	n, m := scanInt(), scanInt()
	G := graph{map[int][]int{}}
	// ab := make([]int, 2)
	for i := 0; i < m; i++ {
		a, b := scanInt()-1, scanInt()-1
		G.d[a] = append(G.d[a], b)
		G.d[b] = append(G.d[b], a)
	}

	cost := make([]int, n)
	for i := 1; i < n; i++ {
		cost[i] = INF
	}

	queue := make([]int, 0)
	ans := make([]int, n)
	now := 0
	queue = append(queue, now)

	for len(queue) > 0 {
		now = queue[0]
		for _, next := range G.d[now] {
			if cost[next] == INF {
				queue = append(queue, next)
				cost[next] = cost[now] + 1
				ans[next] = now + 1
			}
		}
		queue = queue[1:]
	}

	for _, c := range cost {
		if c == INF {
			fmt.Println("No")
			return
		}
	}

	fmt.Println("Yes")
	for i := 1; i < n; i++ {
		fmt.Println(ans[i])
	}
}


Measured memory_bytes: 23692
import heapq as hq
d,g=map(int,input().split())
Q=[]
for i in range(d):
    p,c=map(int,input().split())
    Q.append([p,c])
    
ans=10000
for i in range(2**d):
    #print(bin(i))
    p=0 #取得ポイント
    cnt=0 #問題数
    R=[] #余った問題の点数と個数
    hq.heapify(R)
    for j in range(d):
        a=(j+1)*100
        if i>>j&1:
            p+=Q[j][0]*a+Q[j][1]
            cnt+=Q[j][0]
        else:
            for k in range(Q[j][0]-1):
                hq.heappush(R,-a)
        #print(p,cnt)
        if p>=g:
            break
    while p<g and R:
        p-=hq.heappop(R)
        cnt+=1
        #print(p,cnt)
    if p>=g:
        ans=min(cnt,ans)
    #print(ans)
print(ans)

Measured memory_bytes: 3064
n=int(input())
a=sorted(list(map(int,input().split())))
b=sorted(list(map(int,input().split())))
c=sorted(list(map(int,input().split())),reverse=True)
ul=[0]*n
ll=[0]*n
u=0
l=0
ans=0
for i in range(n):
  if u!=n:
    while a[u]<b[i]:
      u+=1
      if u==n:
        break
  ul[i]=u
b=b[::-1]
for i in range(n):
  if l!=n:
    while c[l]>b[i]:
      l+=1
      if l==n:
        break
  ll[i]=l
ll=ll[::-1]
for i in range(n):
  ans+=ul[i]*ll[i]
print(ans)

Measured memory_bytes: 24052
def gcd(a, b):
    if b == 0:
        return a
    else:
        return gcd(b, a % b)


A, B, C, D = list(map(int, input().split()))
Bc = B // C
Bd = B // D
Ac = (A - 1) // C
Ad = (A - 1) // D
lcm = C * D // gcd(C, D)
Blcm = B // lcm
Alcm = (A - 1) // lcm
print((B - A + 1) - ((Bc - Ac) + (Bd - Ad) - (Blcm - Alcm)))


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

int main()
{
    int H , A;
    cin>>H>>A;
    if(1<=H&&H<=pow(10,4)&&1<=A&&A<=pow(10,4))
    {
        int counter=0;
        while(H>0)
        {
            H=H-A;
            counter++;
        }
        cout<<counter<<endl;
    }

    return 0;
}


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

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

int main()
{
  int a[3];
  char del;

  int rect=0, loz=0;
  while(cin >> a[0] >> del >> a[1] >> del >> a[2]){
    if( abs(a[0]-a[1]) < a[2] && a[2] < a[0]+a[1] ){

      if( a[2]*a[2] == a[0]*a[0] + a[1]*a[1])
	rect++;
      else if(a[0] == a[1])
	loz++;
      
    }
  }
  cout << rect << endl;
  cout << loz << endl;
  return 0;
}

Measured memory_bytes: 1160
#include<iostream>
#include<vector>
#include<queue>
#include<stack>
#include<string>
#include<cmath>
#include<algorithm>
#include<bitset>
#include<map>
#include<functional>
#include<set>

#pragma region
using namespace std;
#define FOR(i,r,n) for(ll i = (ll)(r); i < (ll)(n); i++)
#define RFOR(i,r,n) for(ll i=(ll)(n-1);i>=r;i--)
#define ALL(x) x.begin(),x.end()
#define RALL(x) x.rbegin(),x.rend()
#define LOWER(a,x) lower_bound(ALL(a), x) - a.begin() - 1;
#define COUNT(a,x)  upper_bound(ALL(a), x) - lower_bound(ALL(a), x);
#define MCOUNT(a,x,y) upper_bound(ALL(a), y) - lower_bound(ALL(a), x);
#define SCAN(x) scanf("%lld",&x);
#define INF 5555555555555555555
#define MOD 1000000007
#define pb push_back
#define F first
#define S second
typedef long long int ll;
typedef long double ld;
typedef vector<ll> vll;
typedef pair<ll, ll> pll;
typedef map<ll, ll> MAP;
typedef set<ll> SET;
ll n = 0, m = 0, ans = 0, sum = 0, cnt = 0, tmp = 0, ma = 0, mi = 0;
string s;
bool flag, ok;
ll dx[4] = { 1,-1,0,0 }, dy[4] = { 0,0,1,-1 };
ll ddx[9] = { 1,-1,0,0,1,1,-1,-1,0 }, ddy[9] = { 0,0,1,-1,1,-1,1,-1,0 };
#pragma endregion
#define MAX 111111



int main(void) {
  queue<ll> q[333];
  ll c[333];
  MAP mp;
  cin >> n >> m;
  FOR(i, 0, n) {
	FOR(j, 0, m) {
	  cin >> tmp;
	  tmp--;
	  q[i].push(tmp);
	}
  }

  ans = INF;
  while(!q[0].empty()) {
	FOR(j, 0, 333) c[j] = 0;
	FOR(j, 0, n) c[q[j].front()]++;
	ma = 0;
	FOR(j, 0, 333) {
	  if (ma < c[j]) {
		ma = c[j];
		tmp = j;
	  }
	}
	mp[tmp]++;
	FOR(j, 0, n) {
	  while (!q[j].empty()) {
		if (mp[q[j].front()] == 0) break;
		q[j].pop();
	  }
	}
	ans = min(ans, ma);
	//cout << ans << " " << tmp << endl;
	if (q[0].empty()) break;
  }
  //FOR(i, 0, n) cout << q[i].size() << endl;
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 1152
#include <iostream>
#include <set>
using namespace std;
typedef long long ll;
ll n, a, pos[210000], res;
set<ll> s;
int main(void){
    // Your code here!
    cin >> n;
    for (ll i = 1; i <= n; i++) {
        cin >> a;
        pos[a] = i;
    }
    for (ll i = 1; i <= n; i++) {
        ll b, c;
        auto itr = s.upper_bound(pos[i]);
        if (itr == s.end()) {
            c = n + 1;
        } else{
            c = *itr;
        } if (itr == s.begin()) {
            b = 0;
        } else {
            b = *--itr;
        }
        res += (c - pos[i]) * (pos[i] - b) * i;
        s.insert(pos[i]);
    }
    cout << res << endl;
}


Measured memory_bytes: 11136
#include<stdio.h>

int main(){

  int n, in, i;
  double sum;

  sum = 0;

  scanf("%d",&n);

  for(i = 0; i < n; i++){
    scanf("%d",&in);
    sum += in;
  }

  printf("%.0f\n",sum/n);

  return 0;

}

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

int main(){
  ll H,W,K,i,j,count;
  ll ans = 0;
  char C[6][6],B[6][6];
  cin >> H >> W >> K;
  for(i=0;i<=H-1;i++)
      cin >> C[i];
  for(ll bith = 0;bith < (1<<H);bith++)
    for(ll bitw = 0;bitw < (1<<W);bitw++){
      count = 0;
      for(i=0;i<=H-1;i++)
        for(j=0;j<=W-1;j++)
          B[i][j] = C[i][j];
      for(i=0;i<=H-1;i++)
        for(j=0;j<=W-1;j++)
          if((bith & (1<<i)) || (bitw & (1<<j)))  B[i][j] = '.';
      for(i=0;i<=H-1;i++)
        for(j=0;j<=W-1;j++) 
          if(B[i][j] == '#') count++;
      if(count == K) ans++;
    }
  cout << ans << endl;
}

Measured memory_bytes: 3600
#include<iostream>
using namespace std;
int main(){
	string s;
	cin >> s;
	char c=s[0];
	int ans=0;
	for(int i=1;i<s.length();i++){
		if(s[i]!=c){
			ans++;
			c=s[i];
		}
	}
	cout << ans << endl;
}


Measured memory_bytes: 512
#include <stdio.h>
int main(){
    int A[100];
    int N;
    int i,x,flag;
    int cnt=0;
    
    scanf("%d",&N);
    for(i=0;i<N;i++) scanf("%d",&A[i]);

    while(flag){
        flag=0;
        for(i=N-1;i>0;i--){
            if(A[i]<A[i-1]){
                x=A[i];
                A[i]=A[i-1];
                A[i-1]=x;
                cnt++;
                flag=1;
                break;
            }
        }
    }
    
    for(i=0;i<N;i++){
        printf("%d",A[i]);
        if(i!=N-1) printf(" ");
    }
    printf("\n%d\n",cnt);
    
    return 0;
}



Measured memory_bytes: 2088
#include<bits/stdc++.h>
#define watch(x) cout << (#x) << " is " << (x) << endl
typedef long long ll;
using namespace std;
int static fast = [](){
  ios::sync_with_stdio(false);
  cin.tie(0); cout.tie(0); return 0;
}();


int main() {
    int n, val, ans = 0;
    set<int> s;
    cin >> n;
    for(int i = 0; i < n; i++) {
        cin >> val;
        if (s.lower_bound(val) == s.begin()) {
            ans += 1;
            // cout << "hit " << val << endl;
        }
        s.insert(val);
    }
    cout << ans << endl;
    return 0;
}




Measured memory_bytes: 9600
#include <bits/stdc++.h>
using namespace std;
//________
#define pb push_back
#define fi first
#define se second
#define mkp make_pair
#define rep(i,n) for(int i=0; i<(n); ++i)
#define reps(i,f,n) for(int i=(f); i<=(n); ++i)
#define show(x) cerr << #x << ':' << (x) << endl
#define outl(x) cout << (x) << '\n'
#define FAST() cin.tie(0), ios::sync_with_stdio(false)

typedef long long ll;
typedef pair<int,int> Pii;
template<class A, class B>inline bool chmax(A &a, B b){return b>a ? a=b,1 : 0;}
template<class A, class B>inline bool chmin(A &a, B b){return b<a ? a=b,1 : 0;}
inline bool inside(int y, int x, int H, int W){return(y>=0 && x>=0 && y<H && x<W);}
const int INF = 1 << 29;
const int dx[] = {0, 1, 0, -1, 1, -1, 1, -1};
const int dy[] = {1, 0, -1, 0, 1, -1, -1, 1};
#define Size 1000011
//________


signed main()
{
    FAST();
    string a,b;
    cin >> a >> b;
    sort(a.begin(), a.end());
    sort(b.begin(), b.end(), greater<char>());

    if(a < b){
        outl("Yes");

    }
    else {
        outl("No");
    }
}



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

#define rep(i, a, b) for (ll i = (a); i < (b); i++)
typedef uint64_t ull;
typedef int64_t ll;
typedef pair<ll, ll> PLL;

vector<bool> is_prime(100010, true);
vector<ll> v(100010, 0);

signed main() {
    is_prime[0] = is_prime[1] = false;
    rep(i,2,100010){
        if (!is_prime[i])
            continue;
        for (ll j=i*2; j<100010; j+=i) {
            is_prime[j] = false;
        }
    }
    // rep(i,0,100){
    //     printf("is_prime[%d]=%d\n", i, is_prime[i]==true);
    // }
    rep(i,2,100010){
        if (i%2==0)
            continue;
        if (is_prime[i] && is_prime[(i+1)/2])
            v[i]=1;
    }
    rep(i,1,100010){
        v[i] += v[i-1];
    }

    // rep(i,0,100){
    //     cout<<i<<" "<<v[i]<<endl;
    // }
    ll Q;
    cin>>Q;
    while(Q-->0){
        ll l,r;
        cin>>l>>r;
        cout<<v[r]-v[l-1]<<endl;
    }
    return 0;
}


Measured memory_bytes: 1408
import java.util.*;
public class Main
{
    public static void main(String [] args)
    {
        Scanner sc = new Scanner(System.in);
        String s = sc.next(); String t = sc.next();
        System.out.println(t.substring(0, t.length() - 1).equals(s) ? "Yes" : "No");
    }


}

Measured memory_bytes: 35648
MOD = 1000000007

N,M = map(int,input().split())
A=[int(input()) for i in range(M)]

T = [-1]*(N+1)

T[0] = 1
T[1] = 1

for i in (A):
    T[i] = 0

    


for i in range(2,N+1):
    if(T[i] == -1):
        T[i] = (T[i-1] + T[i-2])%MOD
        
print(T[N])

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

int main() {
  int a, b, c, x;
  cin >> a >> b >> c >> x;
  int res = 0;
  for (int ai = 0; ai <= a; ++ai) {
      for (int bi = 0; bi <= b; ++bi) {
          for (int ci = 0; ci <= c; ++ci) {
            int tot = 500 * ai + 100 * bi + 50 * ci;
            if (tot == x) res++;
          }
      }
  }
  cout << res << endl;
  return 0;
}


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

int main() {
  int a, b;
  cin >> a >> b;
  cout << ((a * b) & 1 ? "Odd" : "Even") << endl;
}


Measured memory_bytes: 256
fun main(args:Array<String>):Unit {
    var (r, c) = readLine()!!.split(' ').map(String::toInt)
    while (r != 0 && c != 0){
        val senbei = Array(r){readLine()!!.trim().split(' ').map(String::toInt).toIntArray()}.let{a ->
            (0 until c).map{x -> (0 until r).map{y -> a[y][x]}.fold(0){p, i -> p * 2 + i}}
        }
        var max = 0
        for (i in 0 until (1 shl r)){
            max = senbei.sumBy {
                countOne(it xor i).let{
                    if (it * 2 > r){
                        it
                    }else{
                        r - it
                    }
                }
            }.let{if (it > max) it else max}
        }
        println(max)
        val (nr, nc) = readLine()!!.split(' ').map(String::toInt)
        r = nr
        c = nc
    }
}
fun countOne(n:Int):Int {
    return when(n){
        0 -> 0
        else -> n % 2 + countOne(n / 2)
    }
}


Measured memory_bytes: 73612
#include<stdio.h>
#define MAX 100000

int partition(int X[],int n,int p,int r){
  int y,z;
  int i,tmp;
  y = X[r];
  z = p - 1;
  
  for (i=p; i<r; i++){
    if ( X[i] <= y ){
      
      z++;
      tmp = X[z];
      X[z] = X[i];
      X[i] = tmp;
      
    }
  }
  tmp = X[z+1];
  X[z+1] = X[r];
  X[r] = tmp;
  return z+1;
}


int main(){
  int x[MAX],n,number;
  int i;
  scanf("%d",&n);
  for ( i=0; i<n; i++ )
    scanf("%d",&x[i]);
  
  number=partition(x,n,0,n-1);

  for ( i=0; i<n; i++) {
    if (i!=0)
      printf(" ");
    
    if (i==number)
      printf("[");
    
    printf("%d",x[i]);
    
    if (i==number)
      printf("]");
  }
  printf("\n");

  return 0;
}



Measured memory_bytes: 2128
#include<iostream>
#include<string>
using sll = signed long long;

int main() {
	sll X, A, B;
	std::cin >> X >> A >> B;

	std::string s;
	
	s = B <= A ? "delicious" :
		B - A <= X ? "safe" : "dangerous";
	std::cout << s << "\n";

	return 0;
}


Measured memory_bytes: 384
<?php

fscanf(STDIN, "%d %d", $n, $l);
//$retsu = explode(" ", fgets(STDIN));

$sum = 0;
if ($l>=0) {
  for ($i=1; $i < $n ; $i++) {
    $sum += ($l + $i);
  }
}elseif ($l<0 && ($n > $l * (-1))) {
  for ($i=0; $i < $n ; $i++) {
    $sum += ($l + $i);
  }
}else {
  for ($i=0; $i < ($n - 1) ; $i++) {
    $sum += ($l + $i);
  }
}

echo $sum;

Measured memory_bytes: 4728
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
int main(){
  int n,p;
  cin>>n;
  int x[n],a[n*n],u[n];
  vector<P> v;
  for(int i=0;i<n*n;i++) a[i]=0;
  for(int i=0;i<n;i++){
    cin>>x[i];
    u[i]=1;
    a[x[i]-1]=i+1;
    v.push_back(P(x[i]-1,i+1));
  }
  sort(v.begin(),v.end());
  bool f=1;
  p=0;
  for(int i=0;i<n;i++){
    int c=v[i].second;
    while(u[c-1]<c){
      if(a[p]){
	p++;
	continue;
      }
      if(p>v[i].first){
	f=0;
	break;
      }
      a[p]=c;
      u[c-1]++;
    }
  }
  reverse(v.begin(),v.end());
  p=n*n-1;
  for(int i=0;i<n;i++){
    int c=v[i].second;
    while(u[c-1]<n){
      while(a[p]) p--;
      if(p<v[i].first){
	f=0;
	break;
      }
      a[p]=c;
      u[c-1]++;
    }
  }

  //assertion
  if(f){
    for(int i=1;i<=n;i++){
      int t=0;
      for(int j=0;j<n*n;j++){
	if(a[j]==i) t++;
	if(i==t) {
	  f&=(j+1==x[i-1]);
	  break;
	}
      }
    }
  }
  if(f){
    for(int i=1;i<=n;i++){
      int t=0;
      for(int j=0;j<n*n;j++){
	if(a[j]==i) t++;
      }
      //cout<<i<<" "<<t<<endl;
      assert(t==n);
    }
  }
  if(!f){
    cout<<"No"<<endl;
  }else{
    cout<<"Yes"<<endl;
    for(int i=0;i<n*n;i++) cout<<a[i]<<" \n"[i==n*n-1];
    //for(int i=0;i<n*n;i++) cout<<i<<":"<<a[i]<<endl;
  }
  return 0;
}


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

#ifdef LOCAL
#define debug(var) cerr << #var << " = " << var << endl;
#else
#define debug(var)
#endif

void init() {
	ios_base::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
}

int a[12][1234];

int reksum(int i, int j, int k, int l) {
	int x = a[k][l];
	if (i) x -= a[i-1][l];
	if (j) x -= a[k][j-1];
	if (i && j) x += a[i-1][j-1];
	return x;
}

void solve() {
	int h, w, K; scanf("%d%d%d", &h, &w, &K);
	for (int i = 0; i < h; ++i) {
		for (int j = 0; j < w; ++j) {
			char c; scanf(" %c", &c);
			a[i][j] = c-'0';
			if (i) a[i][j] += a[i-1][j];
			if (j) a[i][j] += a[i][j-1];
			if (i && j) a[i][j] -= a[i-1][j-1];
		}
	}
	int ans = h+w-2;
	for (int i = 0; i < 1<<(h-1); ++i) {
		int cur = __builtin_popcount(i);
		int prevj = 0;
		bool g = false;
		for (int j = 0; j < w; ++j) {
			bool f = false;
			int prevk = 0;
			for (int k = 0; k < h-1; ++k) {
				if ((i&(1 << k)) == 0) continue;
				if (reksum(prevk, prevj, k, j) > K) f = true;
				if (f && reksum(prevk, prevj, k, j-1) > K) g = true;
				prevk = k+1;
			}
			if (reksum(prevk, prevj, h-1, j) > K || f) {
				if (reksum(prevk, prevj, h-1, j-1) > K) g = true;
				prevj = j;
				++cur;
			}
		}
		if (!g) ans = min(ans, cur);
	}
	printf("%d", ans);
}

int main() {
	init();
	int t = 1; //scanf("%d", &t);
	while (t--) {
		solve();
	}
	return 0;
}


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

int ketasuu(long long n) {
  if (n < 10) {
    return 1;
  }
  else {
    return ketasuu(n/10) + 1;
  }
}

int main() {
  long long N;
  cin >> N;
  long long a = N;
  for (long long i = 2; i <= pow(N, 0.5); i++) {
    if (N % i == 0) {
      a = N / i;
    }
  }
  cout << ketasuu(a);
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
using namespace std;
int main()
{
	int n;//okyaku
	int k;//match
	int a = 0;
	int b = 0;
	priority_queue<int,vector<int>, greater<int> >v;
	cin >> n >> k;
	int ans = n;
	for (int i = 0; i < n; i++) {
		cin >> b;
		if (i > 0) {
			v.push(b - a - 1);//cout << b-a-1 << endl;
		}
		a = b;
	}
	//sort(v.begin(), v.end());
	while (n>k) {
		ans+=v.top();
		v.pop();
		n--;
		
	}

    cout << ans<<endl; 
}


Measured memory_bytes: 3512
#include <cstdio>
#include <numeric>

int prb[100000];
unsigned char done[100000];
int main()
{
	int n, m;
	scanf("%d%d", &n, &m);
	for (int i = 0; i < m; ++i)
	{
		int p;
		char s[3];
		scanf("%d%s", &p, s);
		--p;
		if (*s == 'A')
		{
			if (!done[p])
			{
				done[p] = 1;
			}
		}
		else
		{
			if (!done[p])
			{
				prb[p]++;
			}
		}
	}
	int ac = 0;
	int pn = 0;
	for (int i = 0; i < n; ++i)
	{
		ac += done[i];
		if (done[i])
		{
			pn += prb[i];
		}
	}
	printf("%lld %lld\n", ac, pn);
	return 0;
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
#define int long long
signed main(){
    int x;
    cin>>x;
    vector<int>vec(x);
    for(int i=0;i<x;i++){
        cin>>vec[i];
    }
    int y = vec.at(0);
    for(int i=1;i<x;++i){
        y = min(y,vec.at(i));
    }
    int z = vec.at(0);
    for(int i=1;i<x;++i){
        z = max(z,vec.at(i));         
    }
    int w = vec.at(0);
    for(int i=1;i<x;++i){
        w = w+vec.at(i);
    }
    cout<<y<<" "<<z<<" "<<w<<endl;
    
}





Measured memory_bytes: 3184
#include<iostream>
#include<algorithm>
#include<vector>
#include<set>
#include<iomanip>
#define rep(i, a, n) for(int i = a; i < n; i++)
using namespace std;
int main(){
  int a;
  cin >> a;
  if(a == 25){
    cout << "Christmas\n";
  }
  else if(a == 24){
    cout << "Christmas" << " " << "Eve" << "\n";
  }
  else if(a == 23){
    cout << "Christmas" << " " << "Eve"<< " " << "Eve"  << "\n";
  }
  else if(a == 22){
    cout << "Christmas" << " " << "Eve"<< " " << "Eve" << " " << "Eve" << "\n";
  }
}
  
  

Measured memory_bytes: 3600
#define _USE_MATH_DEFINES
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <complex>
#include <string>
#include <vector>
#include <array>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
#include <iterator>
#include <memory>
#include <regex>
using namespace std;

void solve(vector<int>& v, int i, int init)
{
    vector<int> x(2);
    x[0] = init & (1 << i);
    x[1] = x[0] ^ (1 << i);

    int n = v.size();
    vector<int> ans(2*n);
    for(int i=0; i<2*n; ++i){
        ans[i] = v[i/2];
        ans[i] |= x[(i+1)/2%2];
    }
    v = move(ans);
}

void solve(vector<int>& v, int i, int j, int init)
{
    vector<int> x(4);
    x[0] = init & ((1 << i) | (1 << j));
    x[1] = x[0] ^ (1 << i);
    x[2] = x[1] ^ (1 << j);
    x[3] = x[2] ^ (1 << i);

    int n = v.size();
    vector<int> ans(4*n);
    for(int i=0; i<4*n; ++i){
        ans[i] = v[i/4];
        if(i / 4 % 2 == 0)
            ans[i] |= x[i%4];
        else
            ans[i] |= x[3-i%4];
    }
    swap(ans[4*n-1], ans[4*n-3]);
    v = move(ans);
}

int main()
{
    int n, a, b;
    cin >> n >> a >> b;
    if(bitset<32>(a^b).count() % 2 == 0){
        cout << "NO" << endl;
        return 0;
    }

    vector<int> diff, same;
    for(int i=0; i<n; ++i){
        if((a ^ b) & (1 << i))
            diff.push_back(i);
        else
            same.push_back(i);
    }

    vector<int> ans(1, 0);
    solve(ans, diff[0], a);
    for(unsigned i=1; i<diff.size(); i+=2)
        solve(ans, diff[i], diff[i+1], a);
    for(unsigned i=0; i<same.size(); ++i)
        solve(ans, same[i], a);

    cout << "YES" << endl << ans[0];
    for(int i=1; i<(1<<n); ++i)
        cout << ' ' << ans[i];
    cout << endl;

    return 0;
}


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

#define x first
#define y second

#ifdef ONLINE_JUDGE
#define DEBUG(x)
#else
#define DEBUG(x) cerr << #x << ": " << x << endl;
#endif

using namespace std;

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> ii;
typedef pair<ll,ll> pll;

const int mod=1000000000+7;

int addm(int& a,int b) {return (a+=b)<mod?a:a-=mod;}

template<class T,class U> bool smin(T& a,U b) {return a>b?(a=b,1):0;}
template<class T,class U> bool smax(T& a,U b) {return a<b?(a=b,1):0;}
/*
void is(string& s) {//insert spaces
	int N=s.size();
	s.resize(2*N+1,' ');
	for (int c=N-1;c>=0;c--) {s[2*c+1]=s[c];s[2*c]=' ';}
}

vi lps(string s,string t) {
	int N=s.size();
	is(s);is(t);//Comment this out if only want odd length palindromes
	//and interpret the answer differently.
	N=2*N+1;
	vi r(N);
	
	int Mi=0;
	for (int c=1;c<N;c++) {
		int Mw=r[Mi]+Mi-c;
		int w=r[c]=(Mw>=0?min(Mw,r[2*Mi-c]):0);
		if (w>=Mw) {
			int i=c-w,j=c+w;
			while (++j<N && --i>=0 && s[i]==t[j] && s[j]==t[i]);//Only place where t used.
			r[Mi=c]=j-1-c;
		}
	}

	return r;
}
*/

string A;
int ct[256];

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

	cin >> A;
	ll ans=(ll)(A.size())*(A.size()-1)/2+1;
	for (int i=0;i<A.size();i++) ct[A[i]]++;
	for (char c='a';c<='z';c++) ans-=(ct[c]*(ll)(ct[c]-1))/2;

	//vi rad = lps(A,A);

	//for (int i:rad) ans-=i/2;

	cout << ans << endl;
}

Measured memory_bytes: 720
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        String s = in.nextLine();
        long[] array = new long[s.length() + 1];
        for (int j = 1; j <= s.length(); j++) {
            if (s.charAt(j - 1) == '<') {
                array[j] = array[j - 1] + 1L;
            }
        }
        long answer = array[s.length()];
        for (int j = s.length() - 1; j >= 0; j--) {
            if (s.charAt(j) == '>') {
                array[j] = Math.max(array[j], array[j + 1] + 1);
            }
            answer += array[j];
        }
        System.out.println(answer);
    }
}


Measured memory_bytes: 34888
#include<stdio.h>

int main(){
    char s[100001];
    scanf("%s", s);
    int n=0;
    while(s[n] != '\0'){
        n++;
    }
    int a[n];
    for(int i=0; i<n; i++){
        a[i] = 0;
    }
    int r=0;
    for(int i=0; i<n; i++){
        if(s[i] == 'L' && r != -1){
            a[i-1] += (i - r + 1)/2;
            a[i]   += (i - r)/2;
            r = -1;
        }
        if(s[i] == 'R' && r == -1){
            r = i;
        }
    }
    int l=n-1;
    for(int i=n-1; i>=0; i--){
        if(s[i] == 'R' && l != -1){
            a[i+1] += (l - i + 1)/2;
            a[i]   += (l - i)/2;
            l = -1;
        }
        if(s[i] == 'L' && l == -1){
            l = i;
        }
    }
    for(int i=0; i<n; i++){
        printf("%d ", a[i]);
    }

    return 0;
}

Measured memory_bytes: 896