akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
 
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vvvi = vector<vector<vector<int>>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using vvvl = vector<vector<vector<ll>>>;
#define FOR(i, m, n) for (int i = (m); i < (n); i++)
#define FORR(i, m, n) for (int i = (m); i >= (n); i--)
#define REP(i, n) FOR(i, 0, (n))
#define REPR(i, n) FORR(i, (n) - 1, 0)
#define REP1(i, n) FOR(i, 1, (n) + 1)
#define REPS(c, s) for (char c : s)
#define ALL(c) (c).begin(), (c).end()
#define SORT(c) sort(ALL(c))
#define REV(c) reverse(ALL(c))
#define sz(v) (int)v.size()
#define endl '\n'
template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return false;}
template<class T> inline void prn(vector<T>& v) {int n = sz(v); REP(i, n) cout << v[i] << ' ';}
template<class T> inline void printv(vector<T>& v) {int n = sz(v); REP(i, n) cout << v[i] << (i == n - 1 ? endl : ' ');}
template<class T> inline void printvv(vector<vector<T>>& v) {for (auto u : v) printv(u);}
template<class T> inline void printlnv(vector<T>& v) {int n = sz(v); REP(i, n) cout << v[i] << endl;}
const int MOD = 1000000007;
const int INF = 1000000001;
const ll LINF = 1000000001000000001LL;
 
void solve();
 
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(numeric_limits<double>::max_digits10);
    solve();
    return 0;
}

void solve() {
    char c;
    cin >> c;
    if (c >= 'A' and c <= 'Z') cout << "A" << endl;
    else cout << "a" << endl;
}


Measured memory_bytes: 3644
N, M = map(int,input().split()) 
P = [list(map(int,input().split())) for i in range(N)]
P.sort()
a = 0
for i in range(N):
    if M <= P[i][1]:
        break
    M = M-P[i][1]
    a += 1


print(P[a][0])

Measured memory_bytes: 27872
import os
import sys
from collections import deque

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

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


class Dinic:
    def __init__(self, graph=None, residual=None):
        """
        :param list of (list of (int, int)) graph: (to, cap) の隣接リスト
        :param list of (list of (list of (int|list))) residual: (to, cap, rev) の残余グラフ
        """
        assert (graph and not residual) or (not graph and residual)
        if graph:
            self.graph = self.residual_graph(graph)
        else:
            self.graph = residual

    @staticmethod
    def residual_graph(graph):
        """
        残余グラフ構築
        :param list of (list of (int, int)) graph: (to, cap) の隣接リスト
        :rtype: list of (list of (list of (int|list)))
        :return: (to, cap, rev) の残余グラフ
        """
        ret = [[] for _ in range(len(graph))]
        for v in range(len(graph)):
            for u, cap in graph[v]:
                rev = [v, 0]
                edge = [u, cap, rev]
                rev.append(edge)
                ret[v].append(edge)
                ret[u].append(rev)
        return ret

    def _dist(self, s):
        """
        :param int s:
        :rtype: list of int
        :return: s からの距離。残余グラフ上で到達できない場合は -1
        """
        ret = [-1] * len(self.graph)
        ret[s] = 0
        que = deque([(s, 0)])
        while que:
            v, d = que.popleft()
            for u, cap, _ in self.graph[v]:
                if ret[u] < 0 < cap:
                    ret[u] = d + 1
                    que.append((u, d + 1))
        return ret

    def _dfs(self, s, t, dist, iter, flow=float('inf')):
        """
        :param int s:
        :param int t:
        :param list of int dist:
        :param list of int iter:
        :param int flow:
        """
        if s == t:
            return flow
        while iter[s] < len(self.graph[s]):
            edge = self.graph[s][iter[s]]
            to, cap, rev = edge
            if dist[s] < dist[to] and cap > 0:
                f = self._dfs(to, t, dist, iter, min(flow, cap))
                if f > 0:
                    edge[1] -= f
                    rev[1] += f
                    return f
            iter[s] += 1
        return 0

    def maximum_flow(self, from_v, to_v):
        """
        :param int from_v:
        :param int to_v:
        :return: from_v から to_v への最大流
        """
        ret = 0
        while True:
            dist = self._dist(from_v)
            if dist[to_v] < 0:
                break
            iter = [0] * len(self.graph)
            while True:
                flow = self._dfs(from_v, to_v, dist, iter)
                if flow == 0:
                    break
                ret += flow
        return ret


V, E = list(map(int, sys.stdin.readline().split()))
UVC = [list(map(int, sys.stdin.readline().split())) for _ in range(E)]

graph = [[] for _ in range(V)]
for u, v, c in UVC:
    graph[u].append((v, c))
print(Dinic(graph=graph).maximum_flow(0, V - 1))



Measured memory_bytes: 6352
#include <iostream>
#include <string>

using namespace std;

int main()
{
    int n, k;
    string str;

    cin >> n >> k;
    cin >> str;

    if (str[k-1] == 'A') {
        str[k-1] = 'a';
    }
    else if (str[k-1] == 'B') {
        str[k-1] = 'b';
    }
    else {
        str[k-1] = 'c';
    }

    cout << str << endl;

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define LL long long
#define Max 100005
#define Mod 1e9+7
const LL mod=1e9+7;
const LL inf=0x3f3f3f3f;
using namespace std;
int n,a[Max],m;
int ma[Max],t=0;
int main()
{
	scanf("%d%d",&n,&m);
	if(n>=m)
	{
		printf("0\n");
		return 0;
	}
	for(int i=0;i<m;i++)
		scanf("%d",&a[i]);
	sort(a,a+m);
	int sum=0;
	for(int i=1;i<m;i++)
	{
		ma[t++]=abs(a[i]-a[i-1]);
		sum+=abs(a[i]-a[i-1]);
	}
	sort(ma,ma+t);
	for(int i=0;i<n-1;i++)
		sum-=ma[t-1-i];
	printf("%d\n",sum);
    return 0;
}


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

using namespace std;

using ll = long long;

const ll infll = (ll)1e18;
const int N = 25;
int n, a[N];
map<pair<int, int>, ll> f[N][N];

ll solve (int l, int r, int mul_l, int mul_r) {
    if (f[l][r].count( { mul_l, mul_r } ) ) return f[l][r][ { mul_l, mul_r } ];
    ll ret = infll;
    if (l + 1 == r) ret = 0;
    else {
        for (int m = l + 1; m < r; ++m) ret = min(ret, solve(l, m, mul_l, mul_l + mul_r) + solve(m, r, mul_l + mul_r, mul_r)
                                                  + 1LL * a[m] * (mul_l + mul_r) );
    }
    return (f[l][r][ { mul_l, mul_r } ] = ret);
}

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

    cin >> n;
    for (int i = 1; i <= n; ++i) cin >> a[i];

    cout << solve(1, n, 1, 1) + a[1] + a[n];

    return 0;
}


Measured memory_bytes: 33024
import kotlin.math.min

fun main() {
    val n = readLine()!!.toInt()
    val s = readLine()!!
    val rc = s.count { it == 'R' }
    val ans = min(
            s.slice(0 until rc).count { it == 'W' },
            s.slice(rc until n).count { it == 'R' }
    )
    println(ans)
}


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

int ri() {
	int n;
	scanf("%d", &n);
	return n;
}
int main() {
	std::string s;
	std::cin >> s;
	int cnt = 0;
	int n = s.size();
	for (int i = 0; i < n; ) {
		int j = i + 1;
		for (; j < n && s[j] == s[j - 1]; ) j++;
		cnt++;
		i = j;
	}
	printf("%d\n", cnt - 1);
	return 0;
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
int main(){
    string s;
    cin >> s;
    if(s == "Sunny") cout << "Cloudy" << endl;
    if(s == "Cloudy") cout << "Rainy" << endl;
    if(s == "Rainy") cout << "Sunny" << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <queue>
using namespace std;
typedef long long int ll;

int h,w,k;
char fi[31][31];
int cp[31][31];
int epy[31][31];

void fall(){
	for(int i=0;i<h;i++){
		for(int j=0;j<w;j++){
			epy[i][j]=0;
		}
	}
	for(int i=0;i<w;i++){
		for(int j=h-1;j>=0;j--){
			epy[j][i]=epy[j+1][i];
			if(cp[j][i]==0)epy[j][i]++;
		}
		for(int j=h-1;j>=0;j--){
			if(cp[j][i]!=0&&epy[j][i]!=0){
				cp[j+epy[j][i]][i]=cp[j][i];
				cp[j][i]=0;
			}
		}
	}
}

int rensa(int p){
	bool ok=false;
	int res=0;
	for(int i=0;i<h;i++){
		int cnt=0;
		for(int j=0;j<w;j++){
			int m=cp[i][j];
			while(j<w&&m==cp[i][j]){
				j++;
				cnt++;
			}
			j--;
			if(cnt>=k){
				ok=true;
				res+=cnt*m;
				for(int u=0;u<cnt;u++){
					cp[i][j-u]=0;
				}
			}
			cnt=0;
		}
	}
	if(!ok||res==0)return res;
	else{
		fall();
		return rensa(2*p)+res*p;
	}
}

int solve(int x,int y){
	for(int i=0;i<h;i++){
		for(int j=0;j<w;j++){
			cp[i][j]=(int)(fi[i][j]-'0');
		}
	}
	cp[x][y]=0;
	fall();
	return rensa(1);
}

int main(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	cin >> h >> w >> k;
	for(int i=0;i<h;i++){
		for(int j=0;j<w;j++){
			cin >> fi[i][j];
		}
	}
	int score=0;
	for(int i=0;i<h;i++){
		for(int j=0;j<w;j++){
			score=max(score,solve(i,j));
		}
	}
	cout << score << endl;
	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();
    LinkedList<Double> material = new LinkedList<Double>();
    for(int i = 0; i < n; i++){
      material.add(sc.nextDouble());
    }
    
    while(material.size() > 1){
      //降順にソートしてから前2つを取り出し生成物を1つプッシュ
      Collections.sort(material);
      material.add((material.pollFirst() + material.pollFirst()) / 2);
    }
    
    System.out.println(material.peek());
  }
  
}

Measured memory_bytes: 25300
n=int(input())
xx=list(map(int,input().split()))
yy=list(map(int,input().split()))

p1 = 0
p2 = 0
p3 = 0
p8 = []

for idx in range(n):
    s = abs(xx[idx]-yy[idx])
    p1 += s
    p2 += s**2
    p3 += s**3
    p8.append(s)

print(p1)
print(p2**(1/2))
print(p3**(1/3))
print(max(p8))



Measured memory_bytes: 5644
//#define _CRT_SECURE_NO_WARNINGS
#include "bits/stdc++.h"

#define rep(i,n) for(ll (i)=0;(i)<(n);(i)++)
#define all(x) (x).begin(),(x).end()
#define MOD 1000000007
typedef long long ll;

using namespace std;

int main() {
	ll n;
	cin >> n;
	vector<ll> v(n);
	rep(i, n) {
		cin >> v[i];
	}
	sort(all(v));
	ll ans = n;
	rep(i, n - 1) {
		//cout << i << " " << v[i] << endl;
		if (v[i] == v[i + 1]) {
			ans -= 1;
		}
	}
	if (ans % 2 == 0) ans -= 1;
	cout << ans << endl;

}

Measured memory_bytes: 1024
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<utility>
#include<set>
#include<stack>
#include<list>
#include<deque>
#include<bitset>
#include<iomanip>
#include<cstring>
#include<sstream>
#include<cstdio>
#include<cstdlib>
#include<climits>
#include<cmath>
#include<cctype>


#define pb push_back
#define mp make_pair
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define ren(i,a,b) for(int i=a;i>=b;i--)
#define ff first
#define ss second
#define pll pair<long long int,long long int>
#define pii pair<int,int>
#define vll vector<long long int>
#define vii vector<int>
#define gi(n) scanf("%d",&n)
#define gll(n) scanf("%lld",&n)
#define gstr(n) scanf("%s",n)
#define gl(n) cin >> n
#define oi(n) printf("%d",n)
#define oll(n) printf("%lld",n)
#define ostr(n) printf("%s",n)
#define ol(n) cout << n
#define os cout<<" "
#define on cout<<"\n"
#define o2(a,b) cout<<a<<" "<<b
#define all(n) n.begin(),n.end()
#define present(s,x) (s.find(x) != s.end())
#define cpresent(s,x) (find(all(s),x) != s.end())
#define tr(container, it) for(__typeof(container.begin()) it = container.begin(); it != container.end(); it++)
using namespace std;

typedef unsigned long long int ull;
typedef long long int ll;
typedef vector<vector<ll> > mat;

int main()
{ios_base::sync_with_stdio(false);
ll a,b;
cin>>a>>b;
if(a<=0&&b>=0)
ol("Zero");
else if(a<0)
{
	if((min((ll)-1,b)-a+1)%2==0)
	ol("Positive");
	else
	ol("Negative");
}
else 
ol("Positive");
return 0;
}


Measured memory_bytes: 256
A, B, M = map(int,input().split())
val_m = [[0] * 3 for i in range(M)]

val_a = list(map(int, input().split()))
val_b = list(map(int, input().split()))

for i in range(M):
  val_m[i][0], val_m[i][1], val_m[i][2] = map(int, input().split())

dis_val = []
for i in range(M):
  dis_val.append(val_a[val_m[i][0]-1] + val_b[val_m[i][1]-1] - val_m[i][2])

val_a = list(set(val_a))
val_b = list(set(val_b))

val_a.sort()
val_b.sort()
dis_val.sort()

sum_val = val_a[0] + val_b[0]
if(sum_val <= dis_val[0]):
  print(sum_val)
else:
  print(dis_val[0])

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

int main(){
	long long a[3],k;
	cin>>a[0]>>a[1]>>a[2]>>k;
	sort(a,a+3);
	cout<<a[0]+a[1]+(a[2]<<k);
	return 0;
}


Measured memory_bytes: 256
//To debug :  g++ -g file.cpp -o code
//to flush output : fflush(stdout) or cout.flush()
//cout<<setprecision(p)<<fixed<<var
//use 1LL<<i to for 64 bit shifting , (ll)2 because by default 2 is ll
 
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i,a,n) for(i=a;i<n;++i)
#define irep(i,n,a) for(i=n;i>a;--i)
#define mod 1000000007
#define pb push_back
#define big 9223372036854775807
#define big1 LONG_MAX
#define big2 ll_MAX
#define big3 1000000000
#define sma1 LONG_MIN
#define sma2 ll_MIN
#define sma3 -1000000000
#define mp make_pair
#define dub double
#define ivec vector<ll>
#define lvec vector<long long>
#define cvec vector<char>
#define svec vector<string>
#define mt make_tuple
#define MOD 998244353
#define ld long double
#define pi acos(-1.0)

#define SZ(x)  (ll)(x.size())

#define ss second.second
#define ff first.first
#define f first
#define s second
#define sf second.first
#define fs first.second
#define IOS std::ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)


int main()
{

    ll n,m,t,i,j,c,sum,ans;

    cin>>n>>m>>t;

    ll a[n+1]={0},b[m+1]={0},*it;

    rep(i,1,n+1)
        cin>>a[i];
    rep(i,1,m+1)
    {
        cin>>b[i];
        b[i]+=b[i-1];
    }
    
    c = 0;


    rep(i,0,n+1)
    {
        t = t-a[i];
        
        it = upper_bound(b+1,b+1+m,t);

        if(t>=0)
        {
            
            c = max(c,i+(ll)(it-(b+1)));

        }

    }

    cout<<c;

    return 0;
}

Measured memory_bytes: 6612
#include "bits/stdc++.h"

#define REP(i,n) for(ll i=0;i<ll(n);++i)
#define RREP(i,n) for(ll i=ll(n)-1;i>=0;--i)
#define FOR(i,m,n) for(ll i=m;i<ll(n);++i)
#define RFOR(i,m,n) for(ll i=ll(n)-1;i>=ll(m);--i)
#define ALL(v) (v).begin(),(v).end()
#define UNIQUE(v) v.erase(unique(ALL(v)),v.end());
#define DUMP(v) REP(aa, (v).size()) { cout << v[aa]; if (aa != v.size() - 1)cout << " "; else cout << endl; }
#define INF 1000000001ll
#define MOD 1000000007ll
#define EPS 1e-9

const int dx[8] = { 1,1,0,-1,-1,-1,0,1 };
const int dy[8] = { 0,1,1,1,0,-1,-1,-1 };


using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
ll max(ll a, int b) { return max(a, ll(b)); }
ll max(int a, ll b) { return max(ll(a), b); }
ll min(ll a, int b) { return min(a, ll(b)); }
ll min(int a, ll b) { return min(ll(a), b); }


int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll n, x;
	cin >> n >> x;
	vl v(n);
	REP(i, n)cin >> v[i];
	vvl val(n, vl(n));
	REP(i, n) {

		REP(j, n) {
			val[i][(n-j)%n] = v[(i + j) % n];
		}
	}
	ll ans = INF * INF;
	REP(i, n) {
		REP(j, n-1) {
			val[i][j + 1] = min(val[i][j + 1], val[i][j]);
		}
	}
	REP(j, n) {
		ll tmp = 0;
		REP(i, n) {
			tmp += val[i][j];
		}
		ans = min(ans, tmp+x*j);
	}
	cout << ans << endl;
}


Measured memory_bytes: 31616
//
//  atcoder.cpp
//
//
///
#include <bits/stdc++.h>
#include <boost/optional.hpp>
#include <boost/range/irange.hpp>
#include <boost/range/algorithm.hpp>
#include <boost/range/numeric.hpp>
#include <boost/bimap/bimap.hpp>
#include <boost/bimap/multiset_of.hpp>
#include <boost/multi_array.hpp>
#include <boost/math/common_factor.hpp>
#include <boost/algorithm/string.hpp>

#define REP(i, N) for(int i=0; i<(N); i++)
#define REC(f, ...) (void)0; const auto f = [&](const auto f, __VA_ARGS__)
using namespace std;
using namespace boost::math;

using ll = long long;
namespace bst = boost;
template<typename T> class in {
    T value;
public:
    in() { cin >> value; }
    operator const T&() const { return value; }
    operator T&() { return value; }
    in& operator=(T source) { value = source; return *this; }
};
template<> class in<string> : public string {
public:
    in() { cin >> *this; }
};
template<class T> class inseq : public T {
public:
    template<typename... Arg> inseq(Arg... arg) : T(forward<Arg>(arg)...) { for (auto&& i : *this) cin >> i; }
};
template<class T> using invec = inseq<vector<T>>;

auto solve() {
  in<int> A, B, M;
  invec<int> a(A), b(B);
  vector<int> x(M), y(M),m(M) ;
  
  REP(i,M) {
    cin >> x[i] >> y[i] >> m[i];
  }
  
  int minst = *bst::min_element(a) + *bst::min_element(b);
  
  REP(i, M) {
    int wari = a[x[i]-1] + b[y[i]-1] - m[i];
    minst = min(minst, wari);
  }


  return minst;
}

template<typename T> void plot(const T& func) { cout << func() << endl; }
template<> void plot<void()>(void(&func)()) { func(); }
template<> void plot<double()>(double(&func)()) { cout << setprecision(9) << func() << endl; }

int main() {
  plot(solve);

  return 0;
}



Measured memory_bytes: 2176
// AOJ - ALDS1
// ALDS1_3_B - Queue
// https://onlinejudge.u-aizu.ac.jp/courses/lesson/1/ALDS1/3/ALDS1_3_B
package main

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

// node, list 構造体とメソッドはALDS1_3_Aで使ったものをそのまま使う
// この課題ではpopFront(v *int)を追加する
type node struct {
	v          proc
	prev, next *node
}
type list struct {
	head, tail node
}

func newList() *list {
	nl := new(list)
	nl.head.next = &nl.tail
	nl.tail.prev = &nl.head
	return nl
}
func (ll *list) pushBack(v proc) {
	nn := new(node)
	nn.v = v
	nn.next = &ll.tail
	nn.prev = ll.tail.prev
	ll.tail.prev.next = nn
	ll.tail.prev = nn
}
func (ll *list) popBack(v *proc) (ret bool) {
	if ll.head.next == &ll.tail {
		ret = false
		return
	}
	ret = true
	*v = ll.tail.prev.v
	ll.tail.prev = ll.tail.prev.prev
	ll.tail.prev.next = &ll.tail
	return
}
func (ll *list) popFront(v *proc) (ret bool) {
	if ll.head.next == &ll.tail {
		ret = false
		return
	}
	ret = true
	*v = ll.head.next.v
	ll.head.next = ll.head.next.next
	ll.head.next.prev = &ll.head
	return
}

// ----------------------------------------
// process 構造体(proc)
// ----------------------------------------
type proc struct {
	name  string
	ptime int
}

func main() {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	n := nextInt(sc)
	Q := nextInt(sc)
	l := newList()
	var p proc
	for i := 0; i < n; i++ {
		sc.Scan()
		p.name = sc.Text()
		p.ptime = nextInt(sc)
		l.pushBack(p) // キューに追加する
	}
	t := 0
	fprocs := make([]proc, 0)
	for l.popFront(&p) { //　キュー（先頭から取り出す）
		rt := min(Q, p.ptime) // ラインタイム(実行可能時間)を計算する(Qかp.ptimeの小さい方)
		t += rt               // 時計をランタイム分進める
		p.ptime -= rt         // p.ptimeからランタイムを引く
		if p.ptime == 0 {     // 実行完了?
			fprocs = append(fprocs, proc{p.name, t})
		} else {
			l.pushBack(p) // まだ処理が終わっていないので、キューの最後に追加
		}
	}
	wtr := bufio.NewWriter(os.Stdout)
	for i := 0; i < len(fprocs); i++ {
		fmt.Fprintf(wtr, "%s %d\n", fprocs[i].name, fprocs[i].ptime)
	}
	wtr.Flush()
}

func nextInt(sc *bufio.Scanner) int {
	sc.Scan()
	t, _ := strconv.Atoi(sc.Text())
	return t
}
func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}



Measured memory_bytes: 10704
n,k = map(int, input().split())
ans = 0
for p in range(k+1, n+1):
    if (n//p * p) + k <= n:
        ans += n - (n//p) * p - k + 1
    ans += n//p * (p-k)
if k == 0:
    ans -= n
print(ans)


Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define ll long long
#define INF 1000000005
#define MOD 1000000007
#define EPS 1e-10
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define rrep(i,n) for(int i=(int)(n)-1;i>=0;--i)
#define srep(i,s,t) for(int i=(int)(s);i<(int)(t);++i)
#define each(a,b) for(auto& (a): (b))
#define all(v) (v).begin(),(v).end()
#define len(v) (int)(v).size()
#define zip(v) sort(all(v)),v.erase(unique(all(v)),v.end())
#define cmx(x,y) x=max(x,y)
#define cmn(x,y) x=min(x,y)
#define fi first
#define se second
#define pb push_back
#define show(x) cout<<#x<<" = "<<(x)<<endl
#define spair(p) cout<<#p<<": "<<p.fi<<" "<<p.se<<endl
#define sar(a,n) cout<<#a<<":";rep(pachico,n)cout<<" "<<a[pachico];cout<<endl
#define svec(v) cout<<#v<<":";rep(pachico,v.size())cout<<" "<<v[pachico];cout<<endl
#define svecp(v) cout<<#v<<":";each(pachico,v)cout<<" {"<<pachico.first<<":"<<pachico.second<<"}";cout<<endl
#define sset(s) cout<<#s<<":";each(pachico,s)cout<<" "<<pachico;cout<<endl
#define smap(m) cout<<#m<<":";each(pachico,m)cout<<" {"<<pachico.first<<":"<<pachico.second<<"}";cout<<endl

using namespace std;

typedef pair<int,int> P;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<double> vd;
typedef vector<P> vp;
typedef vector<string> vs;

const int MAX_N = 100005;

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vi a(n);
    rep(i,n){
        cin >> a[i];
    }
    sort(all(a));
    vi b(n,-1), c(n,-1);
    if(n % 2){
        b[0] = a[n/2], b[n-1] = a[n/2-1];
        for(int i = 2; i < n-1; i += 2){
            b[i] = a[i/2-1];
        }
        for(int i = 1; i < n; i += 2){
            b[i] = a[n/2+i/2+1];
        }
        c[0] = a[n/2], c[n-1] = a[n/2+1];
        for(int i = 1; i < n-1; i += 2){
            c[i] = a[i/2];
        }
        for(int i = 2; i < n-1; i += 2){
            c[i] = a[n/2+1+i/2];
        }
    }else{
        for(int i = 0; i < n; i += 2){
            b[i] = a[n/2-1-i/2];
        }
        for(int i = n-1; i >= 0; i -= 2){
            b[i] = a[n/2+(n-1-i)/2];
        }
    }
    ll ans = 0, ans2 = 0;
    rep(i,n-1){
        ans += abs(b[i+1]-b[i]);
    }
    rep(i,n-1){
        ans2 += abs(c[i+1]-c[i]);
    }
    cout << max(ans,ans2) << "\n";
    return 0;
}


Measured memory_bytes: 1408
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define fastio ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
const int m=1e9+7;
int main(){
    #ifndef ONLINE_JUDGE
        freopen("input.txt","r",stdin);
        freopen("output.txt","w",stdout);
    #endif
    fastio
 	int a[3];
 	cin>>a[0]>>a[1]>>a[2];
 	sort(a,a+3,greater<int>());
 	cout<<a[0]*10+a[1]+a[2];
	return 0;
}

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

int main(){
  int n;
  cin >> n;
  vi a(n);
  rep(i,n) cin >> a[i];
  sort(a.rbegin(),a.rend());
  ll ans=0;
  rep(i,n-1) ans+=a[(i+1)/2];
  cout << ans;
  return 0;
}

Measured memory_bytes: 3992
L, R = map(int, input().split())

if R - L >= 2019:
    ans = 0
else:
    l, r = L % 2019, R % 2019
    ans = 2018 ** 2
    for i in range(l, r+1):
        for j in range(i+1, r+1):
            x = (i*j) % 2019
            ans = min(ans, x)

print(ans)

Measured memory_bytes: 3060
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp66 {
    class Program {
        static void Main(string[] args) {
            int N = int.Parse(Console.ReadLine());

            Console.WriteLine((int)Math.Sqrt(N) * (int)Math.Sqrt(N));

        }
    }
}


Measured memory_bytes: 11092
#include <bits/stdc++.h>
using namespace std;
char s[15];
int n, i, j, l, ok, lmax;
int main()
{
    cin>>s;
    int n=strlen(s);
    l=1;
    lmax=1;
    i=0;
    if(s[i]=='A'||s[i]=='C'||s[i]=='G'||s[i]=='T')
        ok=1;
    for(i=1;i<n;i++)
    {
        //cout <<l<<' ';
        if((s[i]=='A'||s[i]=='C'||s[i]=='G'||s[i]=='T')&&(s[i-1]=='A'||s[i-1]=='C'||s[i-1]=='G'||s[i-1]=='T'))
            l++;
        else if(s[i]=='A'||s[i]=='C'||s[i]=='G'||s[i]=='T')
        {
            ok=1;
            lmax=max(lmax,l);
            l=1;
        }
    }
    lmax=max(lmax,l);
    if(!ok)
    {
        cout<<0;
        return 0;
    }
    if((s[i]=='A'||s[i]=='C'||s[i]=='G'||s[i]=='T'))
            l++;
    lmax=max(lmax,l);
    cout<<lmax;
    return 0;
}

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

using namespace std;
using ll = long long;
using ld = long double;


#define int long long
signed main(){
//int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int h,w,m;
    cin >> h >> w >> m;
    vector<int> rcnt(h,0);
    vector<int> ccnt(w,0);
    map<int,int> fld;
    for(int i = 0; i < m; i++) {
        int th,tw;
        cin >> th >> tw;
        th--;
        tw--;
        fld[th*w+tw]++;
        rcnt[th]++;
        ccnt[tw]++;
    }

    vector<pair<int,int>> rst(h);
    vector<pair<int,int>> cst(w);
    for(int i = 0; i < h; i++) rst[i]=make_pair(rcnt[i],i);
    for(int i = 0; i < w; i++) cst[i]=make_pair(ccnt[i],i);
    sort(rst.rbegin(),rst.rend());
    sort(cst.rbegin(),cst.rend());
    int r=0;
    while(rst[r].first==rst[0].first) {
        int c=0;
        while(cst[c].first==cst[0].first) {
            int tr=rst[r].second;
            int tc=cst[c].second;
            if(fld.count(tr*w+tc)==0){
                cout << rst[0].first+cst[0].first << "\n";
                return 0;
            }
            c++;
        }
        r++;
    }
    int ans=rst[0].first+cst[0].first-1;
    cout << ans << "\n";
    return 0;
}

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

// int/long:		-2147483648 - 2147483648 (-2^31 <= int < 2^31)
// long/long long:	-9223372036854775808 - 9223372036854775807 (-2^63 <= long < 2^63)
#define	INF (1<<29)
//536870912

#define	MOD 1000000007

int	main() {
	int X;
	cin >>X;
	int x=sqrt(X+X);
	while (x*(x+1)/2<X)
		x++;
	cout <<x <<endl;
	return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <string>
using namespace std;
#define ll long long
#define endl "\n"
#define print_array(name,n) for(ll o=0;o<n;o++) cout<<name[o]<<" "
#define fr(i,f,t) for(ll i=(f);i<t;i++)
#define fb(i,f,t) for(ll i=(f);i>=t;i--)
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define inf 2e18
bool sortbysecond(const pair<int,int> &a,const pair<int,int> &b){
	return (a.ss>b.ss);
}
template <typename T>
string NumberTostring(T Number )
{
	ostringstream ss;
	ss<<Number;
	return ss.str();
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
    int n,m,x;
    cin>>n>>m>>x;
    pair<int,vector<int>> ele;
    vector<pair<int,vector<int>>> vec;
    for(int i=0;i<n;i++){
    	vector<int> temp(m,0);
    	int c;
    	cin>>c;

    	for(int j=0;j<m;j++){
    		cin>>temp[j];
    	}
    	ele = make_pair(c,temp);
    	vec.pb(ele);
    }
    int mn = 1000000000;
    int flag = 0;
    for(int i=0;i<pow(2,n);i++){
    	// cout<<endl;
    	int sum = 0;
    	vector<int> data(m,0);
    	// cout<<i<<"+++"<<endl;
    	for(int j=0;j<n;j++){
    		// cout<<j<<" --"<<endl;
    		int k = i>>j;
    		// cout<<k<<" ";
    		if(k&1){
    			// cout<<j<<endl;
    			for(int l=0;l<m;l++){
    				data[l]+=vec[j].ss[l];
    				// sum+=vec[j].ff;
    				// cout<<sum<<" sum"<<endl;
    			}
    			sum+=vec[j].ff;
    		}

    	}
    	int temp = 0;
    	for(int j=0;j<m;j++){
    		if(data[j]<x){
    			temp = 1;
    			break;
    		}
    	}
    	if(temp==0){
    		flag=1;
    		if(sum<mn){
    			// cout<<i<<endl;
    			mn = sum;
    		}
    	}
    	
    }
    if(flag==1){
    	cout<<mn<<endl;
    }
    else{
    	cout<<-1<<endl;
    }
    return 0;
}

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

template<typename T, typename U>
using pv=vector<pair<T,U>>;
template<typename T>
using matrix=vector<vector<T>>;
template<typename T>
using pque=priority_queue<T>;
template<typename T>
using lpque=priority_queue<T,vector<T>,greater<T>>;

using ll=long long;
using intpair=pair<int,int>;
using llpair=pair<ll,ll>;
using ilpair=pair<int,ll>;
using lipair=pair<ll,int>;
using intvec=vector<int>;
using llvec=vector<ll>;
using intq=queue<int>;
using llq=queue<ll>;
using intmat=vector<intvec>;
using llmat=vector<llvec>;

#define PI 3.141592653589793
#define INTINF ((1<<30)-1)
#define LLINF ((1LL<<62)-1)
#define MPRIME 1000000007
#define MPRIME9 998244353
#define MMPRIME ((1ll<<61)-1)

#define len length()
#define pushb push_back
#define fi first
#define se second

#define all(name) name.begin(),name.end()
#define rall(name) name.rbegin(),name.rend()
#define gsort(vbeg,vend) sort(vbeg,vend,greater<>())

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

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

template<class T>
inline void init(T& v) {
	for(auto &a: v) cin>>a;
}
template<class T, class U>
inline void init(vector<pair<T,U>>& v) {
	for(auto &a: v) cin>>a.first>>a.second;
}
template<class T, class N>
inline void init(T& v, N n) {
	v.resize(n);
	for(auto &a: v) cin>>a;
}
template<class T, class U, class N>
inline void init(vector<pair<T,U>>& v, N n) {
	v.resize(n);
	for(auto &a: v) cin>>a.first>>a.second;
}

template<class T>
inline void out(T a) {
	cout<<a<<endl;
}
template<class T, class... U>
inline void out(T a, U... alist) {
	cout<<a<<" ";
	out(forward<U>(alist)...);
}

template<class N>
void resiz(N n) {
	//empty
}
template<class N, class T, class... U>
void resiz(N n, T&& hd, U&&... tl) {
	hd.resize(n);
	resiz(n,forward<U>(tl)...);
}

ll binpow(ll a, ll ex, ll p) {
	ll result=1;
	while(ex>0) {
		if(ex&1) result=result*a%p;
		ex>>=1;
		a=a*a%p;
	}
	return result;
}


int K,ans;
ll now=0,mod10=1;
intvec mods(1000001,-1);

void input() {
	cin>>K;
}

void solve() {
	for(ans=1; ; ans++) {
		now = (mod10*7%K + now) % K;
		if(now==0) {
			cout<<ans<<endl;
			return;
		}
		if(mods[now]>0) {
			cout<<-1<<endl;
			return;
		}
		mods[now]=1;
		mod10 = mod10*10%K;
	}
}

int main() {
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout<<fixed<<setprecision(15);
	int t=1;
	while(t) {
		input();
		solve();
		t--;
	}
}


Measured memory_bytes: 7032
import java.io.IOException;
import java.util.InputMismatchException;

public class Main {
	void run() {
		MyScanner sc = new MyScanner();

		while (true) {
			int n = sc.nextInt();
			int w = sc.nextInt();
			if ((n | w) == 0) {
				break;
			}

			int max = 0;
			int[] a = new int[n];
			for (int i = 0; i < n; i++) {
				a[i] = sc.nextInt();
				max = Math.max(max, a[i]);
			}
			int k = max / w + 1;
			int[] value = new int[max];
			for (int i = 0; i < n; i++) {
				value[a[i] / w]++;
			}

			max = 0;
			for (int i = 0; i < k; i++) {
				max = Math.max(max, value[i]);
			}

			double ans = 0.01;

			for (int i = 0; i < k; i++) {
				double tmp = 0;
				tmp = ((1.0 * k - 1 - i) / (1.0 * k - 1)) * ((1.0 * value[i]) / (1.0 * max));
				ans += tmp;
			}

			System.out.println(ans);
		}
	}

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

	public void mapDebug(int[][] a) {
		System.out.println("--------map display---------");
		for (int i = 0; i < a.length; i++) {
			for (int j = 0; j < a[i].length; j++) {
				System.out.printf("%3d ", a[i][j]);
			}
			System.out.println();
		}
		System.out.println("----------------------------" + '\n');
	}

	class MyScanner {
		int read() {
			try {
				return System.in.read();
			} catch (IOException e) {
				throw new InputMismatchException();
			}
		}

		boolean isSpaceChar(int c) {
			return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
		}

		boolean isEndline(int c) {
			return c == '\n' || c == '\r' || c == -1;
		}

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

		int[] nextIntArray(int n) {
			int[] array = new int[n];
			for (int i = 0; i < n; i++)
				array[i] = nextInt();
			return array;
		}

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

		long[] nextLongArray(int n) {
			long[] array = new long[n];
			for (int i = 0; i < n; i++)
				array[i] = nextLong();
			return array;
		}

		double nextDouble() {
			return Double.parseDouble(next());
		}

		double[] nextDoubleArray(int n) {
			double[] array = new double[n];
			for (int i = 0; i < n; i++)
				array[i] = nextDouble();
			return array;
		}

		String next() {
			int c = read();
			while (isSpaceChar(c))
				c = read();
			StringBuilder res = new StringBuilder();
			do {
				res.appendCodePoint(c);
				c = read();
			} while (!isSpaceChar(c));
			return res.toString();
		}

		String[] nextStringArray(int n) {
			String[] array = new String[n];
			for (int i = 0; i < n; i++)
				array[i] = next();

			return array;
		}

		String nextLine() {
			int c = read();
			while (isEndline(c))
				c = read();
			StringBuilder res = new StringBuilder();
			do {
				res.appendCodePoint(c);
				c = read();
			} while (!isEndline(c));
			return res.toString();
		}
	}

}

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

using namespace std;
using ll =long long;
typedef pair<int,int> P;
#define SORT(a) sort((a).begin(),(a).end())
#define rSORT(a) reverse((a).begin(),(a).end())
#define For(i, a, b)    for(int i = (a) ; i < (b) ; ++i)
#define rep(i, n)       For(i, 0, n)
#define debug(x)  cerr << #x << " = " << (x) << endl;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
//Write From this Line

int N, M;
vector<vector<int>> G;
vector<int> dp(100100,-1);

int rec(int v){
	int res = 0;
	if(dp[v] != -1){
		return dp[v];
	} else {
		for(auto nv:G[v]){
			chmax(res, rec(nv) + 1);
			// res = rec(nv) + 1; // これだと、最後に寄った頂点に依存してしまう。
		}
	}
	return dp[v] = res; 
}
int main()
{
	cin >> N >> M;
	G.assign(N,vector<int>());
	rep(i,M){
		int x, y;
		cin >> x >> y;
		--x, --y;
		G[x].push_back(y);
	}

	rep(v,N) rec(v);
	int ans = 0;
	rep(v,N) chmax(ans,dp[v]);
	cout << ans << endl;
}


Measured memory_bytes: 8192
#include<bits/stdc++.h>
#define ll long long 
#define mod (ll)1000000007
using namespace std;

ll n,k,ans;
int a;
ll dizi[100][100][100];
// map<pair<ll,int>,int>m;
ll m[70][70];
ll logla(ll a){
	int say=0;
	while(a>1){
		a/=2;
		say++;
	}
	return say;
}
ll coz(long long int kalan,int bas,int logu){
    /*if(m.find({kalan,bas})!=m.end()){
        return m[{kalan,bas}];
    }*/
    // printf("%lld %d\n",kalan,bas );
    if(m[logu][bas]!=-1){
    	return m[logu][bas];
    }
	ll ans=0;

	if(kalan==0){
		return 1;	
	}
	ll jump=logla(kalan);
	// printf("%d %d %d\n",kalan,bas,jump );
	for(int i=1;i<=n;i++){
		if((kalan-((ll)1<<jump))!=0)
			ans+=(dizi[bas][i][jump]*coz((kalan-(ll)((ll)1<<jump)),i,logu+1))%mod;
		else
			ans+=(dizi[bas][i][jump])%mod;
		ans%=mod;
	}
	m[logu][bas]=ans;
    // m[{kalan,bas}]=ans;
	return ans;
}
int main(){
	// freopen("a.gir","r",stdin);
 //    freopen("a.cik","w",stdout);
	memset(m,-1,sizeof(m));
    scanf("%lld %lld",&n,&k);
    for(int i=1;i<=n;i++){
    	for(int j=1;j<=n;j++){
    		scanf("%d",&a);
    		dizi[i][j][0]=a;
    	}
    }
    for(int i=1;i<=65;i++){
    	// printf("%d\n", i);
    	for(int j=1;j<=n;j++){
    		for(int s=1;s<=n;s++){
    			for(int l=1;l<=n;l++){
    				dizi[j][s][i]+=(dizi[j][l][i-1]*dizi[l][s][i-1])%mod;
    				dizi[j][s][i]%=mod;
    			}
    		}
    	}
    }
    // printf("a\n");
    for(int i=1;i<=n;i++){
    	ans+=coz(k,i,0);
    	ans%=mod;
        // printf("b\n");
    }
    printf("%lld\n", ans);
}


Measured memory_bytes: 3456
# 頂点を3回ずつに持つ (x歩目の着地）
# 最短路

import sys
input = sys.stdin.readline
N,M = map(int,input().split())
if M == 0:
  print(-1)
  exit()
edge = [[] for _ in range(N+1)]
for _ in range(M):
  u,v = map(int,input().split())
  edge[u].append(v)
S,T = map(int,input().split())

INF = 10 ** 9
dist = [[INF,INF,INF] for _ in range(N+1)]

d = 0
q = [S]
while q:
  d += 1
  r = d % 3
  qq = []
  for u in q:
    for v in edge[u]:
      if dist[v][r] == INF:
        dist[v][r] = d
        qq.append(v)
  q = qq

d = dist[T][0]
answer = -1 if d == INF else d // 3
print(answer)

Measured memory_bytes: 37788
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vl = vector<ll>;
using vvl = vector<vl>;
using pl = pair<ll, ll>;
const ll INF = ll(1e18);
const ll mod = ll(1e9 + 7);
const double pi = acos(-1);
#define rep0(i,n) for(ll (i) = 0; (i) < (n); ++(i))
#define rrep0(i,n) for(ll (i) = (n) - 1; (i) >= 0; --(i))
#define rep1(i,n) for(ll (i) = 1; (i) <= (n); ++(i))
#define rrep1(i,n) for(ll (i) = (n); (i) >= 1; --(i))
#define nfor(i,a,b) for(ll (i) = (a); (i) < (b); ++(i))
#define rnfor(i,a,b) for(ll (i) = (b) - 1; (i) >= (a); --(i))
#define pf(x) cout << (x) << endl
#define all(x) (x).begin(),(x).end()
#define yes pf("Yes")
#define no pf("No")
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const int dx[8]={1,0,-1,0,1,1,-1,-1};
const int dy[8]={0,1,0,-1,1,-1,1,-1};

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

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

ll factorial(ll n){
    ll ans = 1;
    rep1(i, n){
        ans *= i;
        ans %= mod;
    }
    return ans;
}

ll power(ll a, ll b){
    ll ans = 1;
    a %= mod;
    while(b) {
        if(b & 1LL) ans = ans * a % mod;
        a = a * a % mod;
        b >>= 1;
    }
    return ans % mod;
}

//modの値の確認をすること
int main(){
    ll l,r,d;
    cin >> l >> r >> d;
    pf(r / d - (l - 1) / d);
    return 0;
}


Measured memory_bytes: 3632
S = gets.chomp

ans = 0
(2 ** (S.length - 1)).times do |bit|
  sum = 0
  buffer = 0
  S.length.times do |i|
    str_n = S[i]
    int_n = str_n.to_i
    buffer += int_n
    if bit[i] == 0
      sum += buffer
      buffer = 0
    else
      buffer *= 10
    end
  end
  sum += buffer
  ans += sum
end
p ans


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

int main(){
    int N, K;
    cin >> N >> K;
    double p = 0;
    for(int i=1; i<=N; i++){
        double x = pow(0.5, ceil(log2((double)K/i)));
        if(x > 0.5){
            x = 1;
        }
        p += x/N;
    }
    cout << std::setprecision(20);
    cout << p;
    return 0;
}

Measured memory_bytes: 256
A,B = map(int,input().split())
#X_list = list(map(int,input().split()))
#X1_list = [int(input()) for i in range(N)]
#X2_list = [list(map(int,input().split())) for i in range(N)]
if A - (2 * B ) >=0 :
    print(A - (2 * B ))
else:
    print(0)

Measured memory_bytes: 2940
#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
#include<unordered_map>
using namespace std;
//<DEFINE>
void Fast() {
	ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
}
void File() {
#ifndef ONLINE_JUDGE
	freopen("Input.txt", "r", stdin);
	freopen("Output.txt", "w", stdout);
#endif
}
#define ll long long
#define ull unsigned long long
#define mod 1000000007
ll gcd(ll a, ll b) {
	return!b ? a : gcd(b, a % b);
}
#define fix(n) cout << fixed << setprecision(n);
#define numOfOnes(n) __builtin_popcount(n)
#define all(a) a.begin(), a.end()
#define skip continue
#define stop(n) return cout<<n,0
#define pi  acos(-1)
#define endl "\n"
#define ceil(x,y) (x+y-1)/y
//</DEFINE>
int n;
vector<int>v;
int res[100001];
//<FUNCTIONS>
ll solve(int idx = 0) {
	ll res1, res2;
	if (idx == n - 1)return 0;
	if (~(res[idx]))return res[idx];
	res1 = 1e18;
	if (idx + 2 < n)res1 = solve(idx + 2) + abs(v[idx] - v[idx+2]);
	res2 = solve(idx + 1) + abs(v[idx] - v[idx+1]);
	return res[idx] = min(res1, res2);
}
//</FUNCTIONS>	
int main() {
	Fast();//, File();
	cin >> n;
	for (int i = 0; i <= n; i++)
		res[i] = -1;
	v.resize(n);
	for (int i = 0; i < n; i++)cin >> v[i];
	cout << solve();
}


Measured memory_bytes: 3328
#include <cassert>
#include <cctype>
#include <cfloat>
#include <climits>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#if __cplusplus >= 201103L
#include <cfenv>
#include <cinttypes>
#include <cstdint>
#endif
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#if __cplusplus >= 201103L
#include <array>
#include <chrono>
#include <forward_list>
#include <initializer_list>
#include <random>
#include <ratio>
#include <regex>
#include <system_error>
#include <tuple>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif
#if __cplusplus >= 201402L
#include <shared_mutex>
#endif

#define rep(i,n) for(ll i = 0;i < n;++i)
#define all(v) v.begin(),v.end()
using namespace std;
using ll = long long;
typedef pair<int,int> P;

const int INF = 1001001001;
const long double PI = (acos(-1));
const int mod = 1e9+7;
const int vx[4] = {0,1,0,-1};
const int vy[4] = {1,0,-1,0};

ll gcd(ll x,ll y){
    x = x%y;
    return x == 0 ? y : gcd(y,x);
}
ll lcm(ll x, ll y){
    return x*y/gcd(x,y);
}



int main(){
 
    int n;
    cin >> n;
    priority_queue<pair<int,int>,vector<pair<int,int>>,greater<pair<int,int>>> q;
    int m = 0;
    rep(i,n){
        int a,b;
        cin >> a >> b;
        q.emplace(make_pair(b,a));
        m = max(m,b);
    }
    int now = 0;
    while(now <= m){
        if(q.empty()) break;
        pair<int,int> t = q.top(); q.pop();
        now += t.second;
        if(now > t.first){
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;


    return 0;
}


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

#define REP(i, l, n) for(ll i=(l), i##_len=(n); i<i##_len; ++i)
#define ALL(x) (x).begin(),(x).end()
#define pb push_back

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

char alpha[26] = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'};

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


/*
// 二項係数計算
long long COM(ll n, ll k){
    //cout << n << k << endl;
    map<ll, ll> mp;
    REP(i, 0, k){
        ll l = 2;
        ll nn = n;
        while(nn >= l * l){
            if(nn % l == 0){
                mp[l]++;
                nn /= l;
            }else{
                l++;
            }
        }
        mp[nn]++;
        n--;
    }
    for(ll i = k; i >= 1; i--){
        ll l = 2;
        ll nn = i;
        while(nn >= l * l){
            if(nn % l == 0){
                mp[l]--;
                nn /= l;
            }else{
                l++;
            }
        }
        mp[nn]--;
    }
    ll ans = 1;
    for(auto &x: mp){
        //ans *= (x.first * x.second);
        if(x.first == 1 || x.second == 0)
            continue;
        ans *= (x.first * x.second);
    }
    return ans;
}
*/


const ll MAX = 150; //テーブルの数
const ll MOD = 1e9+7; //mod宣言

long long fac[MAX], finv[MAX], inv[MAX];
// finv ->階乗割り算
// fac ->階乗掛け算

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(ll n, ll k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}


int main(){
    COMinit();
    ll n, p; cin >> n >> p;
    ll a1 = 0, a0 = 0;
    vector<ll> lis(n);
    REP(i, 0, n){
        ll a; cin >> a; 
        if(a % 2 == 1){
            a1++;
        }else{
            a0++;
        }
    }
    ll ans = 0;
    //cout << a1 << a0 << endl;
    if(p == 0){
        for(ll i = 0; i <= a1; i+=2){
            ans += COM(a1, i);
        }
        ans *= (ll)pow(2, a0);
    }else{
        for(ll i = 1; i <= a1; i+=2){
            ans += COM(a1, i);
            //cout << COM(a1, i) << endl;
        }
        ans *= (ll)pow(2, a0);
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
n, m, x = map(int, input().split())
a = []
b = []
for i in range(n):
    ca = list(map(int,input().split()))
    a.append(ca[0])
    b.append(ca[1:])

ans = 10**9
for i in range(1 << n):
    money = 0
    ex = [0]*m
    for j in range(n):
        if (i >> j) & 1 == 0: continue
        money += a[j]
        for k in range(m):
            ex[k] += b[j][k]
    if all(x <= l for l in ex):
        ans = min(ans,money)
if ans == 10**9:
    print(-1)
else:
    print(ans)

Measured memory_bytes: 9232
#include<bits/stdc++.h>
#define mem(a,x) memset(a,x,sizeof(a))
using namespace std;
typedef long long ll;
const int maxn = 1e5 + 7;
const double pi = acos(-1);
const int mod = 1e9 + 7;
const double eps = 1e-6;
const int inf = 0x3f3f3f3f;

int main()
{	
	ll a;
	cin >> a;
	cout << a+a*a+a*a*a << "\n";
	return 0;
}

Measured memory_bytes: 3632
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        
        Scanner scan = new Scanner(System.in);
        String str = scan.next();
 
        String fast = str.substring(0,1);
        String end = str.substring(str.length() - 1);
        
        int count = str.length() - 2;
        
        String ans = fast + count + end;
        
        System.out.println(ans); 
        
    }
}

Measured memory_bytes: 22612
#include<iostream>
using namespace std;
int main(){
  for (int i=0;;i++){
	int x,y;
	cin >> x >> y ;
	if ( x == 0 && y == 0 ) break;
	if ( x > y ) {
		swap(x,y);
		}
	cout << x << " " << y <<endl;
    }
      

    return 0;
}


Measured memory_bytes: 3000
import sys
S=input()
K=1

if len(S)==1:
    print(K)
    sys.exit
elif len(S)==2:
    if S[0]==S[1]:
        print(1)
        sys.exit
    else:
        print(2)
        sys.exit
else:
    pass
l=len(S)

S1=[]
S2=[]

S1.append(1)
if S[0]!=S[1]:
    S1.append(2)
else:
    S1.append(1)
S2.append(0)
S2.append(1)
for i in range(2,l):
    if S[i]!=S[i-1]:
        S1.append(max(S1[i-1]+1,S2[i-1]+1))
    else:
        S1.append(S2[i-1]+1)
    try:
        if S2[i]==S2[i-2] and S2[i-1]==S2[i-3]:
            S2.append(S1[i-2]+1)
    except:
        S2.append(max(S1[i-2]+1,S2[i-2]+1))

print(max(S2[l-1],S1[l-1]))


Measured memory_bytes: 19160
N = int(input())
b = [int(i) for i in input().split()]

def solve() :
    ret = []
    while len(b) != 0 :
        M = -1
        for i in range(len(b)) :
            if i + 1 == b[i] :
                M = i
        
        if M == -1 :
            print(-1)
            return 
        
        ret.append(b.pop(M))
    
    for r in ret[::-1] :
        print(r)
        
solve()

Measured memory_bytes: 38512
n = int(input())
XYH = []

for _ in range(n):
    x,y,h = map(int,input().split())
    if h != 0:
        XYH.append([x,y,h])

flag = False
ans = XYH[0]
for i in range(101):
    for j in range(101):
        tempH = abs(XYH[0][0] - i) + abs(XYH[0][1] - j) + XYH[0][2]
        for x,y,h in XYH[1:]:
            if abs(x - i) + abs(y - j) + h != tempH:
                flag = False
                break
            else:
                flag = True
        if flag:
            ans = [i,j,tempH]
            break
    if flag:
        break

print(*ans,sep = " ")

Measured memory_bytes: 3064
#include<cstdio>

using namespace std;

int main(void){
	
	int l[10];
	int v1,v2;
	
	while(scanf("%d,", &l[0]) != EOF){
		
		int tl = 0;
		int v1l = 0,v2l = 0;
		for(int i = 1; i < 10; i++){
			scanf("%d,", &l[i]);
		}
		scanf("%d,%d", &v1, &v2);
		
		for(int i = 0; i < 10; i++){
			l[i]*=100;
		}
		for(int i = 0; i < 10; i++){
			tl += l[i];
		}
		
		int cnt = 0;
		
		while(v1*cnt+v2*cnt < tl)cnt++;
		
		tl = 0;
		
		for(int i = 0;; i++){
			if(tl+l[i] >= v1*cnt){
				printf("%d\n",i+1);
				break;
			}else{
				tl+=l[i];
			}
		}
	}
	return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
#define Int int64_t

using namespace std;

int main() {
	int N;
	cin >> N;
	set<int> st;
	bool ok = true;
	for (int i = 0; i < N; ++i) {
		int a;
		cin >> a;
		if (st.count(a) > 0) { ok = false; }
		st.insert(a);
	}

	cout << (ok ? "YES" : "NO") << endl;

	return 0;
}


Measured memory_bytes: 9600