akhauriyash/Code-Regression huggingface dataset:
#line 2 "/Users/kaage/Desktop/ProgrammingWorkspace/library/other/template.hpp"
#define _CRT_SECURE_NO_WARNINGS
#pragma target("avx2")
#pragma optimize("O3")
#pragma optimize("unroll-loops")
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <string.h>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,n) for(int i=1;i<=(n);i++)
#define all(V) V.begin(),V.end()
typedef unsigned int uint;
typedef long long lint;
typedef unsigned long long ulint;
typedef std::pair<int, int> P;
typedef std::pair<lint, lint> LP;
constexpr int INF = INT_MAX/2;
constexpr lint LINF = LLONG_MAX/2;
constexpr double eps = DBL_EPSILON;
constexpr double PI=3.141592653589793238462643383279;
template<class T>
class prique :public std::priority_queue<T, std::vector<T>, std::greater<T>> {};
template <class T, class U>
inline bool chmax(T& lhs, const U& rhs) {
	if (lhs < rhs) {
		lhs = rhs;
		return 1;
	}
	return 0;
}
template <class T, class U>
inline bool chmin(T& lhs, const U& rhs) {
	if (lhs > rhs) {
		lhs = rhs;
		return 1;
	}
	return 0;
}
inline lint gcd(lint a, lint b) {
	while (b) {
		lint c = a;
		a = b; b = c % b;
	}
	return a;
}
inline lint lcm(lint a, lint b) {
	return a / gcd(a, b) * b;
}
bool isprime(lint n) {
	if (n == 1)return false;
	for (int i = 2; i * i <= n; i++) {
		if (n % i == 0)return false;
	}
	return true;
}
template<typename T>
T mypow(T a, lint b) {
	T res(1);
	while(b){
		if(b&1)res*=a;
		a*=a;
		b>>=1;
	}
	return res;
}
lint modpow(lint a, lint b, lint m) {
	lint res(1);
	while(b){
		if(b&1){
			res*=a;res%=m;
		}
		a*=a;a%=m;
		b>>=1;
	}
	return res;
}
template<typename T>
void printArray(std::vector<T>& vec) {
	rep(i, vec.size()){
		std::cout << vec[i];
		std::cout<<(i==(int)vec.size()-1?"\n":" ");
	}
}
template<typename T>
void printArray(T l, T r) {
	T rprev = std::prev(r);
	for (T i = l; i != rprev; i++) {
		std::cout << *i << " ";
	}
	std::cout << *rprev << std::endl;
}
LP extGcd(lint a,lint b) {
	if(b==0)return {1,0};
	LP s=extGcd(b,a%b);
	std::swap(s.first,s.second);
	s.second-=a/b*s.first;
	return s;
}
LP ChineseRem(const lint& b1,const lint& m1,const lint& b2,const lint& m2) {
	lint p=extGcd(m1,m2).first;
	lint tmp=(b2-b1)*p%m2;
	lint r=(b1+m1*tmp+m1*m2)%(m1*m2);
	return std::make_pair(r,m1*m2);
}
template<typename F>
inline constexpr decltype(auto) lambda_fix(F&& f){
	return [f=std::forward<F>(f)](auto&&... args){
		return f(f,std::forward<decltype(args)>(args)...);
	};
}
#line 2 "main.cpp"
int n,k,h[100010],dp[100010];
int main(){
	std::cin>>n>>k;
	rep(i,n)std::cin>>h[i];
	std::fill(dp,dp+n,INF);
	dp[0]=0;
	rep(i,n){
		REP(j,k){
			if(n<=i+j)break;
			chmin(dp[i+j],dp[i]+std::abs(h[i]-h[i+j]));
		}
	}
	std::cout<<dp[n-1]<<std::endl;
	return 0;
}

Measured memory_bytes: 4396
#include <iostream>
#include <vector>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++);



int main() {
    int p, q, r; cin >> p >> q >> r;
    int a = min((p+q), (q+r));
    cout << min(a, (p+r));
}

Measured memory_bytes: 256
import java.util.*;
import java.io.*;

public class Main{

static BufferedReader s1;
static BufferedWriter out;
static String read() throws IOException{String line="";while(line.length()==0){line=s1.readLine();continue;}return line;}
static int int_v (String s1){return Integer.parseInt(s1);}
static long long_v(String s1){return Long.parseLong(s1);}
static int[] int_arr() throws IOException{String[] a=read().split("\\s+");int[] b=new int[a.length];for(int i=0;i<a.length;i++){b[i]=int_v(a[i]);}return b;}
static long[] long_arr() throws IOException{String[] a=read().split("\\s+");long[] b=new long[a.length];for(int i=0;i<a.length;i++){b[i]=long_v(a[i]);}return b;}
static void assign(){s1=new BufferedReader(new InputStreamReader(System.in));out=new BufferedWriter(new OutputStreamWriter(System.out));}
static int Modpow(int a,int p,int m){int res=1;while(p>0){if((p&1)!=0){res=(res*a)%m;}p >>=1;a=(a*a)%m;}return res;}
//......................................@uthor_Alx..............................................
static long mod=(long)1e9+7;
public static void main(String[] args) throws  IOException{
                assign();
                int n=int_v(read());
                int[] a=int_arr();
                long res=0; int pre=0;
                for(int i=0;i<n;i++){
                	if(pre>a[i]){
                		res+=pre-a[i];
                	}
                	else{
                		pre=a[i];
                	}
                }
              out.write(res+"");
                out.flush();

    }
}

Measured memory_bytes: 63664
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<utility>
#include<cmath>
#include<climits>
#include<queue>
#include<stack>
#include<numeric>
#include<set>
#include<iomanip>
#include<map>
#include<type_traits>
#include<tuple>
#include<deque>
#include<cassert>
using namespace std;
typedef long long ll;
typedef pair<ll,int> P;
#define rep(i,N) for(ll (i)=0;(i)<(N);(i)++)
const int mod = 1000000007;
const int INF = 1001001001;
struct edge {
  int to, cost;
};
vector<vector<edge>> graph;
vector<ll> dist;

void dfs(int v, ll d=0, int p=-1) {
  dist[v] = d;
  for(edge u : graph[v]) {
    if(u.to == p) continue;
    dfs(u.to, d + u.cost, v);
  }
}
int main() {
  int n;
  cin >> n;
  graph.resize(n);
  dist.resize(n);
  rep(i, n - 1) {
    int a, b, c;
    cin >> a >> b >> c;
    --a; --b;
    graph[a].push_back((edge){b, c});
    graph[b].push_back((edge){a, c});
  }
  int q, k;
  cin >> q >> k;
  --k;
  dfs(k);
  vector<ll> ans;

  rep(i, q) {
    int x, y;
    cin >> x >> y;
    --x; --y;
    ans.push_back(dist[x] + dist[y]);
  }
  
  rep(i, q) cout << ans[i] << endl;
}


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

signed main(){

    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    
    char a; cin >> a;
    cout << char(a+1) << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define speed_up    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define rep(i,a,b) for(ll i=a;i<b;i++)
#define pb push_back
#define MAX 100000000
using namespace std;
int main()
{
 	
	string s;cin>>s;sort(s.begin(),s.end());
	if((s[0]==s[1])&&(s[2]==s[3])&&(s[0]!=s[2]))
     cout<<"Yes";
	 else cout<<"No";	
	
	
	
 return 0;
}

Measured memory_bytes: 256
import std.stdio, std.conv, std.functional, std.string;
import std.algorithm, std.array, std.container, std.range, std.typecons;
import std.bigint, std.numeric, std.math, std.random;
import core.bitop;

string FMT_F = "%.10f";

static File _f;
void file_io(string fn) { _f = File(fn, "r"); }
static string[] s_rd;
T _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
T _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
T[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }
T[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }
T RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }
T[] RDA(T = long)(T fix = 0) { if (_f.isOpen)  return _RDA!T(_f, fix); else return _RDA!T(fix); }

size_t[] MAKE_IDX(alias less = "a < b", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}
size_t MIN_POS(alias less = "a < b", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }

void chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }
bool inside(T)(T x, T b, T e) { return x >= b && x < e; }
T lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }

//long mod = 10^^9 + 7;
long mod = 998_244_353;
//long mod = 1_000_003;
void moda(T)(ref T x, T y) { x = (x + y) % mod; }
void mods(T)(ref T x, T y) { x = ((x + mod) - (y % mod)) % mod; }
void modm(T)(ref T x, T y) { x = (x * y) % mod; }
void modpow(T)(ref T x, T y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }
void modd(T)(ref T x, T y) { x.modm(y.modpow(mod - 2)); }

void main()
{
	auto R = RD;

	writefln(FMT_F, 2*R*3.14159);
	stdout.flush;
	debug readln;
}

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

int n;
int x[10],y[10];

double kei(int i,int j){
    double dx = x[i] - x[j];
    double dy = y[i] - y[j];
    return pow(dx * dx + dy * dy,0.5);
}

void solve(){
    cin >> n;
    for(int i = 1;i <= n;i++) cin >> x[i] >> y[i];
    vector<int> a(n);
    rep(i,n) a[i] = i + 1;;
    double sum = 0.0;
    do{
        for(int i = 0;i < n - 1;i++) sum += kei(a[i],a[i+1]);
    }while(next_permutation(a.begin(),a.end()));
    
    int wari = 1;
    for(int i = 2;i <= n;i++) wari *= i;

    cout << fixed << setprecision(10) << sum / wari << endl;
    return;
}
int main(){
    solve();
    return 0;
}

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

int main(){
    using namespace std;
    constexpr unsigned long MOD = 998244353;
    const auto& modpow = [](unsigned long n, unsigned long b = 1, unsigned long a = 716070898) -> unsigned long {
        unsigned long r{b % MOD};
        while(n){
            if(n & 1)(r *= a) %= MOD;
            (a *= a) %= MOD;
            n >>= 1;
        }
        return r;
    };
    string al{string(500, '1')};
    unsigned long N;
    cin >> N;
    vector<unsigned long> indpX, indpY, indpZ;
    for(unsigned long _{0}; _ < 3; ++_){
        swap(indpX, indpY);
        swap(indpZ, indpY);
        unsigned long M;
        cin >> M;
        vector<vector<unsigned long>> edge(N);
        for(unsigned long i{0}, a, b; i < M; ++i){
            cin >> a >> b;
            if(a < b)swap(a, b);
            edge[--a].push_back(--b);
        }
        vector<unsigned long> id(N, N - 1);
        vector<bitset<500>> c(N, bitset<500>{al});
        map<unsigned long, unsigned long> m;
        for(unsigned long i{N}; i--; ){
            id[i] = c[i]._Find_first();
            m[id[i]] += modpow(i + 1);
            for(const auto& j : edge[i])c[j][id[i]] = false;
        }
        for(const auto& i : m)indpZ.emplace_back(i.second % MOD);
    }
    if(indpX.size() > indpZ.size())swap(indpX, indpZ);
    if(indpY.size() > indpZ.size())swap(indpY, indpZ);
    if(indpX.size() > indpY.size())swap(indpX, indpY);
    unsigned long MX{indpX.size()}, MY{indpY.size()};
    vector<bitset<500>> usedY(MY, bitset<500>(al));
    unsigned long ans{0};
    for(const auto& i : indpZ){
        bitset<500> used{al};
        unsigned long tmp{0};
        for(unsigned long j{0}; j < MY; ++j){
            unsigned long k{(usedY[j] & used)._Find_first()};
            if(k < MX){
                used[k] = false;
                usedY[j][k] = false;
                tmp += indpY[j] * indpX[k] % MOD;
            }
        }
        tmp %= MOD;
        ans += i * tmp % MOD;
    }
    cout << ans % MOD << endl;
    return 0;
}

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

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

int main(){
    string s, t;
    cin >> s >> t;
    int N = (int)s.size();
    int n = (int)t.size();

    //ヒントの文字列Tを入れることができる部分の、最初のインデックスを格納する配列
    vector<int> able;

    //tが、答えとなる文字列Sの中に入る余地があるかどうかチェックする
    bool is = false;
    rep(i, N-n+1){
        //ヒント文字列Tとの比較用に部分文字列を抜き出す
        string part = s.substr(i, n);
        //ヒント文字列Tと、部分文字列で条件1を満たすかを判定するための変数
        bool match = true;
        rep(j, n){
            if(part[j] == '?') continue;
            else if(part[j] != t[j]) match = false;
        }
        if(match) able.push_back(i);
    }
    //条件1を満たすような部分が存在しないならば、答えを出力
    if(able.empty()){
        cout << "UNRESTORABLE" << endl;
        return 0;
    }

    //条件1を満たすような部分が存在する時
    int len = (int)able.size();
    vector<string> variety(len);
    rep(j, len){
        string S = "";
        int key_index = able[j];
        rep(i, N){
            if(i == key_index){
                S += t;
                i += (n-1);
            }else if(s[i] == '?'){
                S.push_back('a');
            }else if(s[i] != '?'){
                S.push_back(s[i]);
            }
        }
        variety[j] = S;
    }
    sort(variety.begin(), variety.end());
    string ans = variety[0];
    cout << ans << endl;
    return 0;
}

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

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP0(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define REP1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; ++i)

typedef long long LL;
typedef pair<int, int> pii;

const int INTINF = int(1e9) + 1;
const LL LLINF = LL(1e18) + 1;
long double eps = 1.0E-14;
#define pow10(n) int(1e##n + n)

void solve()
{
    int K, N;
    cin >> K >> N;

    vector<int> A(N);
    REP0 (i, N)
    {
        cin >> A[i];
    }
    sort(A.begin(), A.end());

    int max_d = 0;
    REP0 (i, N - 1)
    {
        max_d = max(max_d, A[i + 1] - A[i]);
    }
    max_d = max(max_d, A[0] + K - A[N - 1]);

    cout << (K - max_d) << endl;
}

int main(int argc, char const *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    std::cout << std::fixed << std::setprecision(10);
    solve();
    return 0;
}


Measured memory_bytes: 1024
#include<cstdio>

int main(void){
	
	int i,j,n,c=0,x,m;
	char y;
	scanf("%d",&n);
	
	int a[n];
	char b[n];
	
	for(i=0;i<n;i++){
		scanf(" %c%d",&b[i],&a[i]);
		
	}
	char a1[n],a2[n],b1[n],b2[n];
	for(i=0;i<n;i++){
		a1[i]=a[i];
		a2[i]=a[i];
		b1[i]=b[i];
		b2[i]=b[i];
	
	}
	
	for(i=0;i<n;i++){
		for(j=n-1;j>i;j--){
			if(a1[j]<a1[j-1]){
				x=a1[j];
				a1[j]=a1[j-1];
				a1[j-1]=x;
				y=b1[j];
				b1[j]=b1[j-1];
				b1[j-1]=y;
			}
		}
	}
	
	for(i=0;i<n;i++){
		m=i;
		for(j=i;j<n;j++){
			if(a2[j]<a2[m]){
				m=j;
			}
		}
			x=a2[i];
			a2[i]=a2[m];
			a2[m]=x;
			y=b2[i];
			b2[i]=b2[m];
			b2[m]=y;
	}
	//for(i=0;i<n;i++){
	//	printf("%c ",b[i]);
	//}
	//printf("\n");
	
	char d[9][4]={'\0'},e[9][4]={'\0'};
	for(i=1;i<=9;i++){
		int k=0,l=0;
		for(j=0;j<n;j++){
			if(a[j]==i){
				d[i-1][k]=b[j];
				//printf("i=%d,j=%d,k=%d,%c\n",i,j,k,d[i-1][k]);
				k++;
			}
			if(a2[j]==i){
				e[i-1][l]=b2[j];
				//printf("i=%d,j=%d,l=%d,%c\n",i,j,l,e[i-1][l]);
				l++;
			}
			
				
		}
	}
	bool boo=true;
	for(i=0;i<9;i++){
		for(j=0;j<4;j++){
			if(d[i][j]!=e[i][j]){
				boo=false;
			}
		}
	}
	
	
	for(i=0;i<n-1;i++){
		printf("%c%d ",b1[i],a1[i]);
	}
	printf("%c%d\n",b1[n-1],a1[n-1]);
	printf("Stable\n");
		
	for(i=0;i<n-1;i++){
	printf("%c%d ",b2[i],a2[i]);
	}
	printf("%c%d\n",b2[n-1],a2[n-1]);
	if(boo==true){
		printf("Stable\n");
	}else {
		printf("Not stable\n");
	}
	 return 0;
}

Measured memory_bytes: 2700
#include <bits/stdc++.h>
 
#define scd second
#define fst first
#define pb push_back
#define mkp make_pair
#define all(x) x.begin(), x.end()
#define VT(T) vector<T>
 
using namespace std;
 
typedef long long int ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vint;
typedef vector<ll> vlong;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
typedef vector<vint> vvint;
typedef vector<vlong> vvlong;
typedef list<int> lint;
typedef list<ll> llong;
typedef list<pii> lpii;
typedef list<pll> lpll;
typedef list<lint> llint;
typedef list<llong> lllong;
 
ll const LINF=numeric_limits<long long int>::max();
int const INF=numeric_limits<int>::max();
 
ll gcd(ll a, ll b){
	return b ? gcd(b,a%b) : a;
}
 
ll pow_mod(ll a, ll e, ll m){
	ll res=1;
	while(e){
		if(e&1) res=res*a%m;
		a=a*a%m;
		e>>=1;
	}
	return res;
}
 
ll inv_mod(ll b, ll m){
	b%=m;
	ll x=0, y=1, r, q, a=m;
	while(b){
		q=a/b;
		r=a%b;
		a=b;
		b=r;
		r=x;
		x=y;
		y=r-q*y;
	}
	x+=m;
	return x%m;
}

double dist(double a, double b) {
	return a*a + b*b;
}

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	int n;
	cin>>n;
	int x[n], y[n];
	double X=0, Y=0;
	for(int i=0; i<n; i++){
		cin>>x[i]>>y[i];
		X+=x[i];
		Y+=y[i];
	}
	X /= n; Y /= n;
	double P = 0.1;
	double d=0, e;
	for (int i = 0; i < 30000; i++) {
		int f = 0;
		d = dist(X - x[0], Y - y[0]);
		for (int j = 1; j < n; j++) {
			e = dist(X - x[j], Y - y[j]);
			if (d < e) { d = e; f = j; }
		}
		X += (x[f] - X)*P;
		Y += (y[f] - Y)*P;
		P *= 0.999;
	}

	cout<<fixed<<setprecision(7)<<sqrt(d)<<endl;
}

Measured memory_bytes: 384
import sys
input = sys.stdin.readline
n = int(input())
s = list(str(input().rstrip()))
q = int(input())


class SSQ:
    def __init__(self, n, e):
        # 単位元
        self.e = e
        # num_min:n以上の最小の2のべき乗
        self.num_min = 2**(n-1).bit_length()
        self.seg_min = [self.e]*2*self.num_min

    def update(self, k, x):
        k += self.num_min-1
        self.seg_min[k] = x
        while k:
            k = (k-1)//2
            self.seg_min[k] = self.seg_min[k*2+1] or self.seg_min[k*2+2]

    def query(self, p, q):
        q += 1
        if q <= p:
            return self.e
        p += self.num_min-1
        q += self.num_min-2
        res = self.e
        while q-p > 1:
            if p & 1 == 0:
                res = res or self.seg_min[p]
            if q & 1 == 1:
                res = res or self.seg_min[q]
                q -= 1
            p = p//2
            q = (q-1)//2
        if p == q:
            res = res or self.seg_min[p]
        else:
            res = res or self.seg_min[p] or self.seg_min[q]
        return res

ssqs = [SSQ(n, False) for i in range(26)]

for i in range(n):
    ssqs[ord(s[i]) - ord('a')].update(i, True)

out = []
for i in range(q):
    com, x, y = list(input().split())
    if com == '1':
        idx = int(x) - 1
        pre_alph = ord(s[idx]) - ord('a')
        ssqs[pre_alph].update(idx, False)
        s[idx] = y
        alph = ord(y) - ord('a')
        ssqs[alph].update(idx, True)
    else:
        x, y = int(x) - 1, int(y) - 1
        cnt = 0
        for i in range(26):
            cnt += 1 if ssqs[i].query(x, y) else 0
        out.append(str(cnt))
print("\n".join(out))


Measured memory_bytes: 285608
use std::cmp;

fn main(){
  let nabc: Vec<usize> = read_vec();
  let n = nabc[0];
  let a = nabc[1];
  let b = nabc[2];
  let c = nabc[3];

  let mut vl: Vec<usize> = Vec::new();

  for _ in 0 .. n {
    vl.push(read());
  }

  let mut mpa: Vec<usize> = vec![0; 1 << n];
  let mut mpb: Vec<usize> = vec![0; 1 << n];
  let mut mpc: Vec<usize> = vec![0; 1 << n];

  for i in 1 .. 1 << n {
    let mut ct: usize = 0;
    let mut mp: usize = 0;
    for j in 0 .. n {
      if i & (1 << j) > 0 {
        ct += 1;
        mp += vl[j];
      }
    }
    mpa[i] = (ct - 1) * 10 + cmp::max(a, mp) - cmp::min(a, mp);
  }
  
  for i in 1 .. 1 << n {
    let mut ct: usize = 0;
    let mut mp: usize = 0;
    for j in 0 .. n {
      if i & (1 << j) > 0 {
        ct += 1;
        mp += vl[j];
      }
    }
    mpb[i] = (ct - 1) * 10 + cmp::max(b, mp) - cmp::min(b, mp);
  }

  for i in 1 .. 1 << n {
    let mut ct: usize = 0;
    let mut mp: usize = 0;
    for j in 0 .. n {
      if i & (1 << j) > 0 {
        ct += 1;
        mp += vl[j];
      }
    }
    mpc[i] = (ct - 1) * 10 + cmp::max(c, mp) - cmp::min(c, mp);
  }

  let mut ans: usize = 2000000000;
  
  for i in 1 .. 1 << n {
    for j in 1 .. 1 << n {
      for k in 1 .. 1 << n {
        if i & j == 0 && j & k == 0 && k & i == 0 {
          ans = cmp::min(ans, mpa[i] + mpb[j] + mpc[k]);
        }
      }
    }
  }

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

fn read<T>() -> T
  where T: std::str::FromStr,
        T::Err: std::fmt::Debug
{
  let mut buf = String::new();
  std::io::stdin().read_line(&mut buf).expect("failed to read");
  buf.trim().parse().unwrap()
}

fn read_vec<T>() -> Vec<T>
  where T: std::str::FromStr,
        T::Err: std::fmt::Debug
{
  let mut buf = String::new();
  std::io::stdin().read_line(&mut buf).expect("failed to read");
  buf.split_whitespace().map(|e| e.parse().unwrap()).collect()
}


Measured memory_bytes: 4476
#include <iostream>
#include <cstdio>
#include <map>
#include <vector>
#include <algorithm>
#include <string>
#define loop(i, N) for(int i=0; i<(N); ++i)
using namespace std;
int m[51][51], used[27], rf, a[27], b[27], c[27], d[27], h, w, t;
std::string st;
int main() {
	auto check = [&](int t) {
		for (int i = a[t]; i <= c[t]; ++i) {
			for (int n = d[t]; n <= b[t]; ++n) {
				if (m[i][n] != '.' && !used[m[i][n]-'A']) continue;
				if (m[i][n] != t + 'A') return 0;
			}
		}
		return 1;
	};
	int __t;
	cin >> __t;
	while (__t--) {
		loop(i, 27) {
			a[i] = d[i] = 50;
			b[i] = c[i] = 0;
			used[i] = 0;
		}
		cin >> h >> w;
		loop(i, h) {
			cin >> st;
			loop(n, w) {
				if ((m[i][n] = st[n]) != '.') {
					t = m[i][n] - 'A';
					used[t] = 1;
					a[t] = std::min(a[t], i);
					b[t] = std::max(b[t], n);
					c[t] = std::max(c[t], i);
					d[t] = std::min(d[t], n);
				}
			}
		}
		for (;;) {
			rf = 0;
			loop(i, 27) {
				if (!used[i]) continue;
				if (check(i)) {
					rf = 1;
					used[i] = 0;
					break;
				}
			}
			if (!rf) break;
		}
		rf = 0;
		loop(i, 27) rf |= used[i];
		cout << (rf ? "SUSPICIOUS" : "SAFE") << endl;
	}
	return 0;
}

Measured memory_bytes: 3172
#include<bits/stdc++.h>
using namespace std;
int main()
{

    long long int  n,k,mi,f1,a;
    scanf("%lld %lld",&n,&k);
    a=n%k;
    f1=abs(k-a);
    mi=min(a,f1);
    cout<<mi<<"\n";
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#define MAX 100000
#define VMAX 100000

int main(){
  unsigned short *A;
  int n, i, j,x,temp;

  scanf("%d", &n);

  A = malloc(sizeof(short)*n+1);

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

  x=A[n-1];
  i=-1;
  for(j=0; j<n-1; j++){
      if(A[j]<=x){
          i++;
          temp=A[j];
          A[j]=A[i];
          A[i]=temp;
      }
  }
  temp=A[i+1];
  A[i+1]=A[n-1];
  A[n-1]=temp;

  for(j=0; j<n; j++){
      if(j)printf(" ");
      if(j==i+1)printf("[");
      printf("%d",A[j]);
      if(j==i+1)printf("]");
  }
  printf("\n");


  return 0;
}




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

int main(){
    int n;
    cin>>n;
    vector<long long> a(n),b(n),c(n);
    for(int i=0;i<n;++i) cin>>a[i];
    for(int i=0;i<n;++i) cin>>b[i];
    for(int i=0;i<n;++i) cin>>c[i];

    sort(a.begin(),a.end());
    sort(b.begin(),b.end());
    sort(c.begin(),c.end());

    long long ans=0;
    for(int i=0;i<n;++i){
        long long l=lower_bound(a.begin(),a.end(),b[i])-a.begin();
        long long r=c.end()-upper_bound(c.begin(),c.end(),b[i]);
        ans+=l*r;
    }

    cout<<ans<<endl;
}

Measured memory_bytes: 5584
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int s;	// 入力
  
  // 入力の取り込み
  cin >> s;
  
  //　商＋余りを出力
  cout << ((s / 100) % 2) + ((s / 10) % 2) + (s % 2) << endl;
}

Measured memory_bytes: 256
//atcoder 151 DS
#include<stdio.h>
#include<string.h>
#include<iostream>
#include<math.h>
#include<string>
#include<vector>
#include<map>
#include<queue>
#include<cmath>
#include<algorithm>
using namespace std;
using ll = long long int;
//typedef pair<int,int> P;

int main(void){
	int x;
	cin >> x;
	x%=10;
	if(x==2 || x==4 ||x==5 || x==7 || x==9){cout << "hon"<<endl;
	}else if(x==3){cout << "bon"<<endl;
	}else{
		cout << "pon"<<endl;
	}
	return 0;
}


Measured memory_bytes: 3616
#include <stdio.h>
int main (void){
int N,K;
char S[100];
scanf("%d%d",&N,&K);
for(int i=0;i<N;i++){
    scanf("%s",&S[i]);
}
if(S[K-1]=='A'){
    S[K-1]='a';
}else if(S[K-1]=='B'){
    S[K-1]='b';
}else if(S[K-1]=='C'){
    S[K-1]='c';
}
 

for(int i=0;i<N;i++){
    printf("%c",S[i]);
}
}

Measured memory_bytes: 128
import java.util.Scanner;
public class Main{
 public static void main(String[] args){
   Scanner sc = new Scanner(System.in);
   int X = sc.nextInt();
   int Y = sc.nextInt();
   
   
   if(X!=1&&Y!=1)   System.out.println(1);
   else if(X!=2&&Y!=2)   System.out.println(2);
   else   System.out.println(3);

   
 }
}

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

using namespace std;
typedef long long ll;

#define INF (long long)(1e9+7)
#define REP(i,n) for(ll i = 0; i < n; i++)
#define REP1(i,n) for(ll i = 1; i <= n; i++)

int main(void)
{
  ll x;
  cin >> x;
  ll ans = 0;
  ans += x/500 * 1000;
  x = x % 500;
  ans += (x / 5) * 5;
  cout << ans << endl;

}


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

int     main() {
        long N;
        cin >>N;
        long h=0, hh, S=0;
        for (int i = 0; i < N; i++) {
                cin >> hh;
                if (hh>h) S += hh-h;
                h=hh;
        }
        cout << S << endl;
        return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#include <string>
#include <cstring>
#include <sstream>
#include <queue>
#include <iomanip>
#include <algorithm>
using namespace std;

const int Maxm = 200005;

int n, k;
int freq[Maxm];

int main()
{
	scanf("%d %d", &n, &k);
	for (int i = 0; i < n; i++) {
		int a; scanf("%d", &a);
		freq[a]++;
	}
	sort(freq, freq + Maxm);
	for (int i = 1; i <= k; i++)
		n -= freq[Maxm - i];
	printf("%d\n", n);
	return 0;
}

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

//typedef
//------------------------------------------
typedef long long LL;
typedef vector<LL> VL;
typedef vector<VL> VVL;
typedef vector<string> VS;
typedef pair<LL, LL> PLL;

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

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

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

//main code

int main(int argc, char const* argv[])
{
	int a,b;
	cin >> a >> b;
	int ans = 0;
	for (int i = a; i <= b; i++) {
		string s = to_string(i);
		if (s[0] == s[4] and s[1] == s[3]) {
			ans++;
		}
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cmath>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<iomanip>
#define _USE_MATH_DEFINES
#include <math.h>
#include <functional>
#include<complex>
using namespace std;

#define rep(i,x) for(ll i=0;i<x;i++)
#define repn(i,x) for(ll i=1;i<=x;i++)

typedef long long ll;
const ll INF = 1e17;
const ll MOD = 1000000007;
const ll MAX = 4000001;
const long double eps = 1E-14;

ll max(ll a, ll b) {
	if (a > b) { return a; }
	return b;
}

ll min(ll a, ll b) {
	if (a > b) { return b; }
	return a;
}

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

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

struct edge {
	ll ind;
	ll fr;
	ll to;
	ll d;
};

class mint {
	long long x;
public:
	mint(long long x = 0) : x((x% MOD + MOD) % MOD) {}
	mint operator-() const {
		return mint(-x);
	}
	mint& operator+=(const mint& a) {
		if ((x += a.x) >= MOD) x -= MOD;
		return *this;
	}
	mint& operator-=(const mint& a) {
		if ((x += MOD - a.x) >= MOD) x -= MOD;
		return *this;
	}
	mint& operator*=(const  mint& a) {
		(x *= a.x) %= MOD;
		return *this;
	}
	mint operator+(const mint& a) const {
		mint res(*this);
		return res += a;
	}
	mint operator-(const mint& a) const {
		mint res(*this);
		return res -= a;
	}
	mint operator*(const mint& a) const {
		mint res(*this);
		return res *= a;
	}

	mint pow(ll t) const {
		if (!t) return 1;
		mint a = pow(t >> 1);
		a *= a;
		if (t & 1) a *= *this;
		return a;
	}

	// for prime MOD
	mint inv() const {
		return pow(MOD - 2);
	}
	mint& operator/=(const mint& a) {
		return (*this) *= a.inv();
	}
	mint operator/(const mint& a) const {
		mint res(*this);
		return res /= a;
	}

	friend ostream& operator<<(ostream& os, const mint& m) {
		os << m.x;
		return os;
	}
};

mint pw(mint a, ll b) {
	if (b == 0) { return 1; }
	mint ret = pw(a, b >> 1);
	ret *= ret;
	if (b & 1) { ret *= a; }
	return ret;
}

typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef vector<vector<vector<ll>>> vvvll;

typedef vector<mint> vmint;
typedef vector<vector<mint>> vvmint;
typedef vector<vector<vector<mint>>> vvvmint;

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

int main() {
	ll N, Q;
	cin >> N >> Q;

	vector<pair<pair<ll, ll>, ll>> p(N + 1);
	repn(i, N) cin >> p[i].first.second >> p[i].second >> p[i].first.first;
	sort(++p.begin(), p.end());

	vll s(N + 1), t(N + 1), x(N + 1);
	repn(i, N) {
		s[i] = p[i].first.second;
		t[i] = p[i].second;
		x[i] = p[i].first.first;
	}

	vll D(Q + 1);
	repn(i, Q) cin >> D[i];

	set<ll> st;
	map<ll, ll> mp;
	repn(i, Q) {
		st.insert(D[i]);
		mp[D[i]] = i;
	}

	vll ans(Q + 1,-1);

	repn(i, N) {
		auto itr = st.lower_bound(s[i] - x[i]);
		auto itr2 = st.lower_bound(t[i] - x[i]);

		for (auto j = itr; j != itr2; ++j) {
			ans[mp[*j]] = x[i];
		}
		st.erase(itr, itr2);
	}
	repn(i, Q) { cout << ans[i] << endl; }

}

Measured memory_bytes: 37436
#include <algorithm>
#include <iostream>
#include <cstring>
#include <string>
#include <cstdio>
#include <vector>
#include <stack>
#include <cmath>
#include <queue>
#include <map>

template <typename T>
void read(T& x)
{
    x = 0;
    char c = getchar();
    for (; !isdigit(c); c = getchar());
    for (; isdigit(c); x = x * 10 + (c ^ 48), c = getchar());
}

int main()
{
    std::ios::sync_with_stdio(0);
    std::string s = "", t = "", u = "";
    int a = 0, b = 0;
    std::cin >> s >> t >> a >> b >> u;
    if (s == u)
        --a;
    else if (t == u)
        --b;
    std::cout << a << " " << b << std::endl;
    return 0;
}

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

int main(){
	int a, b, c, d;
	int in;
	cin >> in;
	a = in / 1000;
	b = (in / 100) % 10;
	c = (in / 10) % 10;
	d = in % 10;
	if (a+b+c+d == 7) cout << a << '+' << b << '+' << c << '+' << d << "=7";
	else if (a+b+c-d == 7) cout << a << '+' << b << '+' << c << '-' << d << "=7";
	else if (a+b-c+d == 7) cout << a << '+' << b << '-' << c << '+' << d << "=7";
	else if (a+b-c-d == 7) cout << a << '+' << b << '-' << c << '-' << d << "=7";
	else if (a-b+c+d == 7) cout << a << '-' << b << '+' << c << '+' << d << "=7";
	else if (a-b+c-d == 7) cout << a << '-' << b << '+' << c << '-' << d << "=7";
	else if (a-b-c+d == 7) cout << a << '-' << b << '-' << c << '+' << d << "=7";
	else if (a-b-c-d == 7) cout << a << '-' << b << '-' << c << '-' << d << "=7";
	return 0;
}






Measured memory_bytes: 256
import javax.print.DocFlavor;
import java.awt.*;
import java.io.PrintWriter;
import java.lang.reflect.Array;
import java.math.BigInteger;
import java.util.*;
import java.util.List;

public class Main {

    static String br = System.getProperty("line.separator");
    static Scanner sc = new Scanner(System.in);
    static PrintWriter out = new PrintWriter(System.out);

    public static void main(String[] args) {
        int L = nextInt();

        println(Math.pow(L/3.0, 3));
    }

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

    static Long nextLong() {
        return Long.parseLong(next());
    }

    static String next() {
        return sc.next();
    }

    static String nextLine(){
        return sc.nextLine();
    }

    static void println(Object o) {
        out.println(o);
        out.flush();
    }

    static void print(Object o) {
        PrintWriter out = new PrintWriter(System.out);
        out.print(o);
        out.flush();
    }
}


Measured memory_bytes: 23508
#include <bits/stdc++.h>
#define F first
#define S second
using namespace std;
typedef long long ll;
typedef pair<ll, ll>pll;
int main()
{
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    int n;
    cin >> n;
    set<char>st;
    while(n--)
    {
        char x;
        cin >> x;
        st.insert(x);
    }
    cout << (st.size() == 3 ? "Three" : "Four");
    return 0;
}


Measured memory_bytes: 3660
program sequence_sum
  implicit none
  integer(8) :: n, num, tmp, a(0:100000) = 0
  integer :: x, m, b(0:100000) = 0, period, offset, rem, i
  read(*,*) n, x, m
  tmp = m
  if (n <= 2 * m) then
    num = x
    rem = int(n)
    do i = 2, rem
      x = mod(int(x, 8) * x, tmp)
      if (x == 0) exit
      num = num + x
    end do
    write(*,'(i0)') num
    stop
  end if
  a(1) = x
  b(x) = 1
  do i = 2, m + 1
    x = int(mod(int(x, 8) * x, tmp))
    a(i) = a(i - 1) + x
    if (b(x) > 0) then
      offset = b(x) - 1
      period = i - offset - 1
      exit
    end if
    b(x) = i
  end do
  num = (n - offset) / period
  rem = int(n - offset - num * period)
  write(*,'(i0)') (a(offset + period) - a(offset)) * num + a(offset + rem)
end program sequence_sum

Measured memory_bytes: 3644
package main

import "fmt"

func main() {
	var n int
	fmt.Scan(&n)
	ret := solve(n)
	fmt.Println(ret)
}

func solve(n int) int {
	factors := make([]int, n+1)

	for i := 2; i <= n; i++ {
		curr := i
		for j := 2; j <= i; j++ {
			for curr%j == 0 {
				factors[j] += 1
				curr /= j
			}
		}
	}

	count := 0

	for i := 2; i <= n; i++ {
		for j := i + 1; j <= n; j++ {
			for k := j + 1; k <= n; k++ {
				if factors[i] >= 4 && factors[j] >= 4 && factors[k] >= 2 {
					count += 1
				}
				if factors[i] >= 4 && factors[j] >= 2 && factors[k] >= 4 {
					count += 1
				}
				if factors[i] >= 2 && factors[j] >= 4 && factors[k] >= 4 {
					count += 1
				}
			}
		}
	}
	for i := 2; i <= n; i++ {
		for j := i + 1; j <= n; j++ {
			if factors[i] >= 24 && factors[j] >= 2 {
				count += 1
			}
			if factors[i] >= 2 && factors[j] >= 24 {
				count += 1
			}
			if factors[i] >= 14 && factors[j] >= 4 {
				count += 1
			}
			if factors[i] >= 4 && factors[j] >= 14 {
				count += 1
			}
		}
	}
	for i := 2; i <= n; i++ {
		if factors[i] >= 74 {
			count += 1
		}
	}

	return count
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define rep(i, a, b) for(int i=(a); i<(b); i++)
#define sz(a) (int)a.size()
#define de(a) cout<<#a<<" = "<<a<<endl
#define dd(a) cout<<#a<<" = "<<a<<" "
#define all(a) a.begin(), a.end()
#define pw(x) (1ll<<(x))
typedef long long ll;
typedef double db;
typedef pair<int, int> pii;
typedef vector<int> vi;
const int P = 1e9 + 7;
inline int add(int a, int b) {if((a += b) >= P) a -= P; return a;}
inline int sub(int a, int b) {if((a -= b) < 0) a += P; return a;}
inline int mul(int a, int b) {return 1ll * a * b % P;}
inline int kpow(int a, int b) {int r=1;for(;b;b>>=1,a=mul(a,a)) {if(b&1)r=mul(r,a);}return r;}
//----
int n, m;
int main(){
	scanf("%d%d", &n, &m);
	vector<pii> a;
	rep(i, 0, n) a.pb({0, i});
	rep(i, 0, n) {
		int t;
		scanf("%d", &t);
		t--;
		a[t].fi++;
	}
	sort(all(a));
	int be = 0;
	while(be < n && a[be].fi == 0) be++;
	int ans = 0;
	if(n - be > m) {
		while(n - be > m) {
			ans += a[be].fi;
			be++;
		}
	}
	printf("%d\n", ans);
	return 0;
}


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

int main() {
  int N, total;
  cin >> N; bool ok = false;
  for (int a = 0; a <= N; ++a){
  for (int b = 0; b <= N; ++b){
      if ( 4*b + 7*a == N) ok = true;
    }
  }
  if ( ok == true ) cout << "Yes" << endl;
  else cout << "No" << endl;
      
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,a,b) for(ll i=ll(a);i<ll(b);i++)
#define irep(i,a,b) for(ll i=ll(a);i>=ll(b);i--)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
#define pb push_back
#define mp make_pair
#define F .first
#define S .second 
#define pll pair<ll,ll>
using ll=long long;
using ld=long double;
const ll INF = 1LL<<60;
const ll mod=1e9+7;
using namespace std;
ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }

ll a[10001];
int main(){
    ll n,ans=0;
    cin>>n;
    rep(i,1,101){
        rep(j,1,101){
            rep(k,1,101){
                ll p=i*i+j*j+k*k+i*j+j*k+k*i;
                if(p<=10000)a[p]++;
            }
        }
    }
    rep(i,1,n+1)cout<<a[i]<<endl;
}




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

██╗    ██╗██████╗ ██╗████████╗████████╗███████╗███╗   ██╗    ██████╗ ██╗   ██╗
██║    ██║██╔══██╗██║╚══██╔══╝╚══██╔══╝██╔════╝████╗  ██║    ██╔══██╗╚██╗ ██╔╝
██║ █╗ ██║██████╔╝██║   ██║      ██║   █████╗  ██╔██╗ ██║    ██████╔╝ ╚████╔╝
██║███╗██║██╔══██╗██║   ██║      ██║   ██╔══╝  ██║╚██╗██║    ██╔══██╗  ╚██╔╝
╚███╔███╔╝██║  ██║██║   ██║      ██║   ███████╗██║ ╚████║    ██████╔╝   ██║
 ╚══╝╚══╝ ╚═╝  ╚═╝╚═╝   ╚═╝      ╚═╝   ╚══════╝╚═╝  ╚═══╝    ╚═════╝    ╚═╝

     ███╗   ███╗   ██╗██████╗ ██████╗  █████╗ ██╗  ██╗██╗███╗   ███╗
     ████╗ ████║   ██║██╔══██╗██╔══██╗██╔══██╗██║  ██║██║████╗ ████║
     ██╔████╔██║   ██║██████╔╝██████╔╝███████║███████║██║██╔████╔██║
     ██║╚██╔╝██║   ██║██╔══██╗██╔══██╗██╔══██║██╔══██║██║██║╚██╔╝██║
     ██║ ╚═╝ ██║██╗██║██████╔╝██║  ██║██║  ██║██║  ██║██║██║ ╚═╝ ██║
     ╚═╝     ╚═╝╚═╝╚═╝╚═════╝ ╚═╝  ╚═╝╚═╝  ╚═╝╚═╝  ╚═╝╚═╝╚═╝     ╚═╝
*/
#define speed  ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define FOR(n) for(int i=0;i<n;i++)
#define For(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define E "\n"
#define all(e) e.begin(),e.end()
#define F first
#define S second
#define pi (acos(-1))
#define rad(x) ((x*pi)/(ld)(180))
#define perc(x) fixed<<setprecision(x)
/*****
#define cross(a, b) ((conj(a) * (b)).Y)
#define dot(a, b) ((conj(a) * (b)).X)
#define vec(a,b) ((b) - (a))
#define rot(p,angle) (p)*polar((double)(1),angle)
#define rot2(p,angle,a) ((p)-(a)) *(polar((ld)(1),angle)+ (a))
#define x real()
#define y imag()
*****/
typedef long long int ll; typedef unsigned long long ull; typedef long double ld;typedef complex<ld> point; typedef tuple<double,double,double> line;
ll gcd(ll x,ll y){if(!y)return x; return gcd(y,x%y);};   ll lcm(ll x,ll y){return (x*y)/__gcd(x,y);}

ll dp[100005][4],n,arr[100005][3];

ll solve(int i,int j)
{
    if(dp[i][j]!=-1 and i!=0)return dp[i][j];
    if(i==n)return 0;

    ll &ret = dp[i][j];

    if(j!=0)
    ret = max(ret,solve(i+1,0)+arr[i][0]);
    if(j!=1)
    ret = max(ret,solve(i+1,1)+arr[i][1]);
    if(j!=2)
    ret = max(ret,solve(i+1,2)+arr[i][2]);

    return ret;
}

int main(){ speed;
memset(dp,-1,sizeof dp);

cin>>n;

FOR(n)cin>>arr[i][0]>>arr[i][1]>>arr[i][2];

dp[0][0]=arr[0][0],
dp[0][1]=arr[0][1],
dp[0][2]=arr[0][2];

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

    for(int j=0;j<3;j++)
    {
        ll &ret = dp[i][j];
        if(!j)
        ret = max(dp[i-1][1]+arr[i][j],dp[i-1][2]+arr[i][j]);

        if(j==1)
        ret = max(dp[i-1][0]+arr[i][j],dp[i-1][2]+arr[i][j]);

        if(j==2)
        ret = max(dp[i-1][0]+arr[i][j],dp[i-1][1]+arr[i][j]);
    }

}

cout<<max(dp[n-1][0],max(dp[n-1][1],dp[n-1][2]));
return 0;}


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

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

    for(int i=1;i<=n;i++){
        int x=i;
        if(x%3==0)cout<<" "<<i;
        else{

            while(x!=0){
                if(x%10==3){
                    cout<<" "<<i;
                    break;
                }else x/=10;
            }
        }
    }
    cout<<endl;
    return 0;
}



Measured memory_bytes: 3104
import java.util.*

fun main(args: Array<String>) {
    try {

        val sc = Scanner(System.`in`)
        val n = Integer.parseInt(sc.nextLine())
        val s = sc.nextLine().split(" ").map { Integer.parseInt(it) }
        val q = Integer.parseInt(sc.nextLine())
        val t = sc.nextLine().split(" ").map { Integer.parseInt(it) }
        if (n > 100_000 || q > 50_000 || s.size > 1_000_000_000 || t.size > 1_000_000_000) {
            throw Exception("Illegal input.")
        }
        var c = 0
        val checked = mutableListOf<Int>()
        for (tt in t) {
            var left = 0
            var right = s.size
            while (left < right) {
                val mid: Int = (left + right) / 2
                if (s[mid] == tt) {
                    checked.add(tt)
                    c++
                    break
                } else if (tt < s[mid]) {
                    right = mid
                } else {
                    left = mid + 1
                }
            }
        }
        println(c)
    } catch (e: Exception) {
        println(e)
    }
}


Measured memory_bytes: 74556
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <string>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <deque>
#include <numeric>
#include <bitset>
#include <iomanip>
#include <cassert>
#include <chrono>
#include <random>
#include <limits>
#include <iterator>
#include <functional>
#include <sstream>
#include <complex>
using namespace std;

typedef long long ll;
typedef uint64_t ull;
typedef pair<int, int> P;
typedef pair<int, double> Pid;
typedef pair<double, int> Pdi;
typedef pair<ll, int> Pl;
typedef pair<ll, ll> Pll;
typedef pair<int, pair<int, int>> PP;
typedef pair<P, int> PPi;
constexpr double PI = 3.1415926535897932;   // acos(-1)
constexpr double EPS = 1e-9;
constexpr int INF = 1001001001;
constexpr int mod = 1000000007;
// constexpr int mod = 998244353;

#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define chadd(x, y) x = (x + y) % mod

int dp[1005][(1 << 12)];

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

    int n, m;
    cin >> n >> m;
    vector<int> a(m), b(m), c(m, 0);
    for(int i = 0; i < m; ++i){
        cin >> a[i] >> b[i];
        for(int j = 0; j < b[i]; ++j){
            int foo;
            cin >> foo;
            c[i] |= (1 << --foo);
        }
    }
    for(int i = 0; i <= m; ++i){
        for(int j = 0; j < (1 << n); ++j)   dp[i][j] = INF;
    }
    dp[0][0] = 0;
    for(int i = 0; i < m; ++i){
        for(int j = 0; j < (1 << n); ++j){
            if(dp[i][j] == INF) continue;
            chmin(dp[i + 1][j], dp[i][j]);
            chmin(dp[i + 1][j | c[i]], dp[i][j] + a[i]);
        }
    }
    int ans = dp[m][(1 << n) - 1];
    if(ans == INF)  ans = -1;
    cout << ans << endl; 
}

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

int main() {
	int W, a, b;
	cin >> W >> a >> b;
	if(a > b) swap(a, b);
	if (b <= a + W && b + W >= a + W) cout << '0' << endl;
	else {
		if(b > a) cout << b - a - W << endl;
		else cout << a - b - W << endl;
	}
}

Measured memory_bytes: 384
#include<stdio.h>
int main(void){
	int i,a[5],b[5],t=0,s=0;
	for(i=0;i<4;i++){
		scanf("%d",&a[i]);
		s+=a[i];
	}
	for(i=0;i<4;i++){
		scanf("%d",&b[i]);
		t+=b[i];
	}
	if(s<t)printf("%d\n",t);
	else if(s>t)printf("%d\n",s);
	else printf("%d\n",s);
	return 0;
}


Measured memory_bytes: 2136
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <math.h>

#define rep(i,n) for(int i = 0; i < n; i++)
using namespace std;
#define ll long long int

int main() {
	ll n,a,b;
	ll count = 0,ans = -1;
	cin >> n;
	rep(i,n){
		cin >> a >> b;
		if(a == b){
			count++;
			if(count == 3){
				ans = 1;
			}
		}
		else{
			count = 0;
		}
	}

	if (ans == 1){
		cout << "Yes";
	}
	else{
		cout << "No";
	}
	
	return 0;
}

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

int main() {


int n;
//int *num=new int[4];
//char *s=new char[3];
string s;
cin >> s;

if(s.size()==2){
cout << s[0]<<s[1] << endl;
}else{
//sort(s,s+3,greater<char>());
cout << s[2]<<s[1]<<s[0] << endl;
}


//cout << mi << endl;



}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin >> N;
  int sum = 0;
  
  int i = 0;
  for (; i < N;) {
    int l, r;
    cin >> l >> r;
    sum+=r-l+1;
    i++;
  }
    cout << sum << endl;
}


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

int main(){

 int h,m,s;
 
 while(cin>>h>>m>>s,h!=-1){
 	int rest=2*3600-(h*3600+m*60+s);
 	printf("%02d:%02d:%02d\n", rest/3600, rest%3600/60, rest%60);
  rest*=3;
  printf("%02d:%02d:%02d\n", rest/3600, rest%3600/60, rest%60);
 }
 return 0;
}

Measured memory_bytes: 1160
def gcd(i,j):
    a=max(i,j)
    b=min(i,j)
    if a%b==0:
        return b
    else:
        return gcd(b,a%b)
def lcm(i,j):
    return i*j//gcd(i,j)
N=int(input())
A=list(map(int,input().split()))
l=lcm(A[0],A[1])
for i in range(2,N):
    l=lcm(l,A[i])
ans=0
for i in A:
    ans+=(l-1)%i
print(ans)


Measured memory_bytes: 3316
def get_i() #空白区切の入力を数値(整数)の配列で返す
  return gets.chomp.split(" ").map(&:to_i)
end
def get_f() #空白区切の入力を数値(実数)の配列で返す
  return gets.chomp.split(" ").map(&:to_f)
end
def get() #空白区切の入力を文字列の配列で返す
  return gets.chomp.split(" ")
end
def get_nsp() #入力されたものを一文字ずつに区切った文字列の配列で返す
  return gets.chomp.split("")
end
def yn_judge(bool,y="Yes",n="No") #boolに真偽を投げることで、trueならy、falseならnの値を出力する
  return bool ? y : n 
end
def array(size,n=1,init=nil) #nに配列の次元数、sizeに配列の大きさ、initに初期値を投げることでその配列を返す
  if n==1
    return Array.new(size){init}
  else
    return Array.new(n).map{Array.new(size){init}}
  end
end

n=gets.to_i
s=get_nsp
cnt=0
ans=""
n.times do|i|
  case s[i]
  when "(" then
    cnt+=1
  when ")" then
    if cnt>0
      cnt-=1
    else
      ans+="("
    end
  end
end
ans+=s.join("")
cnt.times do
  ans+=")"
end
puts ans

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



signed main(){
    int n,m;
    cin >>n>>m;
    int t[10],y[8]={},a[m],k[10]={};
    t[1]=2;t[2]=5;t[3]=5;t[4]=4;t[5]=5;t[6]=6;t[7]=3;t[8]=7;t[9]=6;t[0]=0;
    int dp[n+1];
    fill(dp,dp+n+1,-1);
    dp[0]=0;
    for(int i=0;i<m;i++){
        cin >> a[i];
        if(y[t[a[i]]]<a[i])y[t[a[i]]]=a[i];
        k[a[i]]=1;
    }
    for(int i=0;i<n+1;i++){
        for(int j=2;j<8;j++){
            if(y[j]!=0){
                if(i>=j&&dp[i-j]>=0)dp[i]=max(dp[i],dp[i-j]+1);
                
            }
        }
    }
    dp[0]=0;
  
    int d =n;
   // cerr<<dp[n]<<endl;
    while(d!=0){
        for(int i=9;i>=0;i--){
            if(k[i]!=0&&d>=t[i]){
                if(dp[d]==dp[d-t[i]]+1){
                    d=d-t[i];
                    cout << i;
                    break;
                   
                }
                
            }
        }

    }



    
   
    return 0;
    
}

Measured memory_bytes: 256
import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] a = new int[n];
        for (int i = 0; i < n; i++) {
            a[i] = sc.nextInt();
        }
        int g = gcd(a[0], a[1]);
        for (int i = 2; i < n; i++) {
            g = gcd(g, a[i]);
        }
        Set<Integer> set = new HashSet<>();
        boolean pc = true;
        for (int i = 0; i < n; i++) {
            if(!pc) break;
            int tmp = a[i];
            for (int j = 2; j < Math.sqrt(a[i]); j++) {
                boolean hasj = false;
                while(tmp % j == 0){
                    hasj = true;
                    tmp /= j;
                }
                if(hasj && set.contains(j)){
                    pc = false; break;
                }
                if(hasj) set.add(j);
                if(tmp == 1) break;
            }
            if(tmp != 1){
                if(set.contains(tmp)) pc = false;
                else set.add(tmp);
            }
        }
        if(pc)  System.out.println("pairwise coprime");
        else if(g == 1) System.out.println("setwise coprime");
        else System.out.println("not coprime");
        sc.close();

    }

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


}


Measured memory_bytes: 62728