akhauriyash/Code-Regression huggingface dataset:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using static System.Console;
using static System.Math;
using static MyIO;
using static MyUtil;

public class D
{
	public static void Main() => (new Solver()).Solve();
}

public class Solver
{
	public void Solve()
	{
		var N = GetLong();
		var K = GetLong();
		var A = GetLongs(N);
		Array.Sort(A);

		var B = A.Where(x => x != 0).ToArray();
		long L = B.Length;
		
		var AA = A.Select(x => x * x).ToArray();
		Array.Sort(AA);

		long low = -(long)1e18;
		long high = (long)1e18;
		while(high - low > 1)
		{
			long mid = (low + high) >> 1;
			long cnt = (mid >= 0) ? N * (N - L) : 0;
			for(int i = 0; i < L; i++)
			{				
				if(B[i] > 0)
					cnt += count1(N, A, floor(mid, B[i]));

				else if(B[i] < 0)
					cnt += count2(N, A, ceil(-mid, -B[i]));
			}
			cnt -= count1(N, AA, mid);

			if(cnt / 2 >= K)
				high = mid;
			else
				low = mid;
		}
		WriteLine(high);
	}

	private long ceil(long x, long y) => (x >= 0) ? (x + y - 1) / y : x / y;
	private long floor(long x, long y) => (x < 0) ? (x - y + 1) / y : x / y;

	private long count1(long N, long[] A, long key)
	{
		long ok = -1;
		long ng = N;
		while(ng - ok > 1)
		{
			long mid = (ok + ng) >> 1;
			if(A[mid] <= key)
				ok = mid;
			else
				ng = mid;
		}
		return ok + 1;
	}

	private long count2(long N, long[] A, long key)
	{
		long ok = N;
		long ng = -1;
		while(ok - ng > 1)
		{
			long mid = (ok + ng) >> 1;
			if(A[mid] >= key)
				ok = mid;
			else
				ng = mid;
		}
		return N - ok;
	}
}

public static class MyIO
{
	private static string[] args = null;
	private static int num = -1;
	private static int used = -1;

	private static string getArg()
	{
		if(used == num)
		{
			args = Console.ReadLine().Split(' ');
			num = args.Length;
			used = 0;
		}
		return args[used++];
	}

	public static int GetInt() => int.Parse(getArg());
	public static long GetLong() => long.Parse(getArg());
	public static double GetDouble() => double.Parse(getArg());
	public static decimal GetDecimal() => decimal.Parse(getArg());
	public static string GetString() => getArg();
	public static char GetChar() => getArg()[0];
	public static int[] GetInts(long N) => Enumerable.Range(0, (int)N).Select(_ => GetInt()).ToArray();
	public static long[] GetLongs(long N) => Enumerable.Range(0, (int)N).Select(_ => GetLong()).ToArray();
	public static double[] GetDoubles(long N) => Enumerable.Range(0, (int)N).Select(_ => GetDouble()).ToArray();
	public static decimal[] GetDecimals(long N) => Enumerable.Range(0, (int)N).Select(_ => GetDecimal()).ToArray();
	public static string[] GetStrings(long N) => Enumerable.Range(0, (int)N).Select(_ => GetString()).ToArray();
}

public static class MyUtil
{
	public static void chmax<T>(ref T x, T y) where T : IComparable<T>
	{
		if(x.CompareTo(y) < 0)
			x = y;
	}

	public static void chmin<T>(ref T x, T y) where T : IComparable<T>
	{
		if(x.CompareTo(y) > 0)
			x = y;
	}

	public static void swap<T>(ref T x, ref T y)
	{
		T tmp = x;
		x = y;
		y = tmp;
	}
}

Measured memory_bytes: 46028
import sys
def input():
    return sys.stdin.readline()[:-1]
def gcd(a,b):
    if b == 0:
        return a
    return gcd(b,a%b)

def main():
    N = int(input())
    A = list(map(int,input().split()))
    ans = A[0]
    for e in A[1:]:
        ans = gcd(ans,e)
    print(ans)
if __name__ == '__main__':
    main()


Measured memory_bytes: 14480
#include <iostream>
#include <string>
#include <map>
#include <vector>
#include <set>
#include <iomanip>
#include <stack>
#include <fstream>
#include <cstdint>
#include <cmath>
#include <algorithm>
#include <utility>
#include <numeric>
#include <functional>
using namespace std;
typedef int64_t ll;
typedef uint64_t ull;
constexpr uint64_t L1 = 1ull;
constexpr ull bit(int n){ return 1ull << n;}

constexpr ll INF       = 1000000000;/* 1e+9a */

void solve(istream& cin) {
    string t;
    while(cin >> t){
        for (int i = 0; i < t.size(); ++i) {
            if(t[i] != t[t.size() - i - 1]){
                cout << "No\n";
                return;
            }
        }// i
        cout << "Yes\n";
    }
}

int main(int argc, char *argv[]) {
    string FileName("A"), Modifier("_MEPH");
    string ExecutionName = FileName + Modifier;
    string sub(argv[0]);
    // pass消去
    if(sub.size() > ExecutionName.size())
        sub = sub.substr(sub.size()-ExecutionName.size(), ExecutionName.size());

	// 数値計算もの用
    cout << setprecision(16) << scientific;
    if (sub != ExecutionName) {
        cin.tie(0);
        ios::sync_with_stdio(false);
        solve(cin);
    }
    else {    
	    cerr << sub << endl;
        string inFile = "A_sample.txt";
        auto fs = fstream(inFile, fstream::in);
        solve(fs);
    }
}


Measured memory_bytes: 256
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
typedef unsigned long long ULL;

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

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

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

//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))

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

int main() {
  int a[4], b[4];

  while(cin >> a[0] >> a[1] >> a[2] >> a[3]) {
    cin >> b[0] >> b[1] >> b[2] >> b[3];
    int hit = 0, blow = 0;

    for(int i = 0; i < 4; i++) {
      if(a[i] == b[i]) {
	hit++;
	continue;
      }
      for(int j = 0; j < 4; j++) {
	if(a[i] == b[j])blow++;
      }
    }
    cout << hit << ' ' << blow << endl;
  }
}

Measured memory_bytes: 1160
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <array>
#include <queue>
#include <map>
#include <set>
#include <sstream>
#include <stdio.h>
#include <cstdio>
#include <cstring>
#include <math.h>
#include <list>
#include <numeric>

using namespace std;

#define Rep(i,a,b) for(int i = a; i < b; i++)
#define rep(i,b) Rep(i,0,b)
#define rrep(i,a) for(int i = a; i >= 0; i--)
#define allof(a) (a).begin(), (a).end()

typedef long long ll;
const int inf = 1e9 + 7;
const ll infll = 1ll << 60ll;
const ll mod = 1e9 + 7;
// 0~3までは右左下上 4~7までは斜め
constexpr int dx[] = { 1, 0, -1, 0, 1, 1, -1, -1 };
constexpr int dy[] = { 0, -1, 0, 1, 1, -1, -1, 1 };

/*
// 最大公約数
ll gcd(ll a, ll b) {
	if (b == 0) return a;
	return gcd(b, a % b);
}

// 最小公倍数
ll lcm(ll a, ll b) {
	return a / gcd(a, b) * b;
}*/

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

	ll r, d, x;
	cin >> r >> d >> x;

	rep(i, 10) {
		x = r * x - d;
		cout << x << endl;
	}

	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0;i<(n);i++)
#define REP2(i,a,b) for(int i=(a);i<(b);i++)
#define ALL(v) (v).begin(),(v).end()
#define INF 2e9
typedef long long ll;

int main()
{
  int n,k;
  cin>>n>>k;
  vector<int> d(k);
  REP(i,k) cin>>d[i];

  REP2(i,n,1e9){
    int x=i;
    bool f=1;
    while(x>0){
      int temp=x%10;
      REP(j,k){
        if(temp==d[j]) f=0;
      }
      x/=10;
      if(f==0) x=0;
    }
    if(f==0) continue;
    cout<<i<<endl;
    return 0;
  }

  return 0;
}

Measured memory_bytes: 256
# coding: utf-8
# Your code here!
# coding: utf-8
from fractions import gcd 
from functools import reduce
import sys
sys.setrecursionlimit(200000000)
from inspect import currentframe


# my functions here!
#標準エラー出力
def printargs2err(*args):
    names = {id(v):k for k,v in currentframe().f_back.f_locals.items()}
    print(', '.join(names.get(id(arg),'???')+' : '+repr(arg) for arg in args),file=sys.stderr)
def debug(*args):
    print(*args,file=sys.stderr)

def printglobals():
    for (symbol, value) in globals().items():
        print('symbol="%s"、value=%s' % (symbol, value),file=sys.stderr)
def printlocals():
    for (symbol, value) in locals().items():
        print('symbol="%s"、value=%s' % (symbol, value),file=sys.stderr)
#入力（後でいじる）
def pin(type=int):
    return map(type,input().split())
     
#input

def resolve2():
    N,A,B=pin()
    ans=0
    cycle=A+B
    ans+=A*(N//cycle)
    t=N%cycle
    if t <= A:
        ans+=t
    else:
        ans+=A
    print(ans)
def resolve():
    N=input()
    cond= N=="AAA" or N=="BBB"
    print(["No","Yes"][1-cond])
    #print(N//cycle)
    #print(ans)
    #print([["NA","YYMM"],["MMYY","AMBIGUOUS"]][cMMYY][cYYMM])
#if __name__=="__main__":resolve()

"""
#printデバッグ消した？
#前の問題の結果見てないのに次の問題に行くの？
"""
"""
お前カッコ閉じるの忘れてるだろ
"""
import sys
from io import StringIO
import unittest

class TestClass(unittest.TestCase):
    def assertIO(self, input, output):
        stdout, stdin = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(input)
        resolve()
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, stdin
        self.assertEqual(out, output)
    def test_入力例_1(self):
        input = """ABA"""
        output = """Yes"""
        self.assertIO(input, output)
    def test_入力例_2(self):
        input = """BBA"""
        output = """Yes"""
        self.assertIO(input, output)
    def test_入力例_3(self):
        input = """BBB"""
        output = """No"""
        self.assertIO(input, output)

if __name__=="__main__":resolve()

Measured memory_bytes: 84844
/*************************************************************
     File Name: A.cpp
     Created Time: Sat 07 Apr 2018 08:00:14 PM CST
 ************************************************************/

#include <iostream>
#include <set>
using namespace std;

int a, b, k;
set<int> ans;
int main() {
    cin >> a >> b >> k;

    for (int i = 0; i < k && i+a<=b; ++i) {
        ans.insert(i+a);
    }
    for (int i = k-1; i >= 0 && b-i>=a; --i) {
        ans.insert(b-i);
    }
    for (auto it : ans) {
        cout << it << endl;
    }
}


Measured memory_bytes: 256
object Main {
  def main(args: Array[String]) {
    val sc = new java.util.Scanner(System.in)
    val base = sc.next()
    val baseLen = base.length

    def iter(s: String): Int = {
      if (s.length <= 1) {
        return 0
      }
      val subString = s.substring(s.length/2, s.length)
      if (subString*2 == s) {
        return s.length
      }
      iter(s.substring(0, s.length-1))
    }

    println(iter(base.substring(0, base.length-1)))
  }
}



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

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc=new Scanner(System.in);
        double m;
        double v;
        while(true){
            int n=sc.nextInt();
            if(n==0) break;
            m=0;
            double s[];
            s=new double[n];
            for(int i=0;i<n;i++){
                s[i]=sc.nextDouble();
                m+=s[i];
            }
            m/=n;
            v=0;
            for(int i=0;i<n;i++){
                v+=(s[i]-m)*(s[i]-m);
            }
            v/=n;
            System.out.println(Math.sqrt(v));
        }
    }
}


Measured memory_bytes: 41000
using System;
using System.Linq;
using System.Collections.Generic;
using System.IO;

namespace atcorder2
{
    class Program
    {
        public static long Read()
        {
            return long.Parse(Console.ReadLine());
        }

        public static long[] Reads()
        {

            return Console.ReadLine().Split().Select(long.Parse).ToArray();
        }


      



        static void Main(string[] args)
        {
            var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);

            var n = Read();
            var a = Reads();
            var b = Reads();
            long max = 0;
            for (int i = 0; i < n; i++)
            {
                long sum =0;
                for (int k = 0;  k <=i ;  k++)
                {
                    sum += a[k];
                }
                for (int j = i; j < n; j++)
                {
                    sum += b[j];
                }
                if (max < sum) max = sum;
            }

            Console.WriteLine(max);

            Console.Out.Flush();
        }
    }
}




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

typedef struct{
  int id;
  int p;
  int s;
  int c;
  int r;
  int l;
} Tree;
 
int n;
Tree *T;
 
int getdepth(int u){
 
  int a = 0;
 
  while(T[u].p >= 0){
    u = T[u].p;
    a++;
  }
  return a;
}

int getheight(int x, int y){

  int a=0, b=0;
   
  if(T[x].r != -1){
    a = getheight(T[x].r, y+1);
  }  
  if(T[x].l != -1){
    b = getheight(T[x].l, y+1);
  } 
  if(T[x].l == -1 && T[x].r == -1){
    return y;
  }
  if(a>=b){
    return a;
  }
  else return b;
}
 
void print(void){
 
  int i;
 
  for(i=0;i<n;i++){
 
    printf("node %d: parent = %d, sibling = %d, degree = %d, depth = %d, height = %d, ",T[i].id,T[i].p,T[i].s,T[i].c,getdepth(i),getheight(i,0));

    if(T[i].c == 0 && T[i].p != -1)
      printf("leaf");
    else if(T[i].c != 0 && T[i].p != -1)
      printf("internal node");
    else
      printf("root");
    printf("\n");
  }
}
 
 
int main(void){
 
  int i,node,c,l,r;

  scanf("%d",&n);
 
  T = malloc(n * sizeof(Tree));
 
  for(i=0;i<n;i++){
    T[i].id = T[i].p = T[i].s = T[i].l = T[i].r = -1;
    T[i].c = 0;
  }
 
  for(i=0;i<n;i++){
    c = 0;
    scanf("%d",&node);
    scanf("%d %d",&T[node].l,&T[node].r);
    T[node].id = node;

    if(T[node].l != -1){
      T[T[node].l].p = node;
      T[T[node].l].s = T[node].r;
    }

    if(T[node].r != -1){
      T[T[node].r].p = node;
      T[T[node].r].s = T[node].l;
    }



    if(T[node].l == -1) c++;
    if(T[node].r == -1) c++;

    if(c == 0) T[node].c = 2;
    else if(c == 1) T[node].c = 1;
    else T[node].c = 0;

  }
  print();
  free(T);
  return 0;
}

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

int main() {
    int n;
    cin >> n;
    vector<P> v(n);
    rep(i, n) {
        int a; cin >> a;
        v[i] = P(a, i);
    }
    sort(v.begin(), v.end());
    rep(i, n) cout << v[i].second+1 << " ";

    return 0;
}

Measured memory_bytes: 1536
line = gets
prices = gets.split(' ').map(&:to_i)

have_money = 1000
kabu_num = 0

last_sell = false
prices.each_with_index do |price,i|
  break if prices[i+1].nil?

  if price < prices[i+1]
    # puts '買い'
    last_sell = true
    next if kabu_num != 0 # 株を保持してて買いの時はそのまま保持なので
    kabu_num = (have_money / price)
    have_money = have_money - (kabu_num * price)
  end
  
  if price > prices[i+1]
    # puts '売り'
    last_sell = false
    have_money = have_money + (kabu_num * price)
    kabu_num = 0
  end
end

# 最後
if last_sell
  have_money = have_money + (kabu_num * prices[-1])
end

puts have_money


Measured memory_bytes: 14328
#include <iostream>
#include <algorithm>
#include <functional>
#include <string>
#include <vector>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <map>
#include <set>
#include <list>
#include <unordered_set>
#include <unordered_map>
#include <iomanip>
#include <limits>

using namespace std;

using i64 = long long int;
using P = pair<i64, i64>;

struct edge {
    i64 from, to, cost;
    edge(i64 from, i64 to) : from(from), to(to), cost(1) {}
    edge(i64 from, i64 to, i64 cost) : from(from), to(to), cost(cost) {}
};
using Graph = vector<vector<edge>>;

constexpr i64 SINF = std::numeric_limits<i64>::max() / 10;
const i64 MOD = 1000000007;
const i64 dx[4] = { 0,1,0,-1 }, dy[4] = { -1,0,1,0 };
//const i64 dx[5] = {-1,0,0,0,1}, dy[5] = {0,-1,0,1,0};
//const i64 dx[8] = {-1,0,1,1,1,0,-1,-1}, dy[8] = {1,1,1,0,-1,-1,-1,0};
//const i64 dx[9] = {-1,0,1,1,1,0,-1,-1,0}, dy[9] = {1,1,1,0,-1,-1,-1,0,0};

// http://beet-aizu.hatenablog.com/entry/2018/04/08/145516
template<typename T>
vector<T> make_v(size_t a) { return vector<T>(a); }

template<typename T, typename... Ts>
auto make_v(size_t a, Ts... ts) {
    return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}

template<typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type
fill_v(T& t, const V& v) { t = v; }

template<typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type
fill_v(T& t, const V& v) {
    for (auto& e : t) fill_v(e, v);
}

struct IoSetup {
    IoSetup() {
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(10);
        cerr << fixed << setprecision(10);
    }
} iosetup;

int main() {
    int x, a;
    cin >> x >> a;
    if(x < a) cout << 0 << endl;
    else cout << 10 << endl;
 }

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <math.h>

int main(int argc, const char * argv[]){
    int num,num2,num3;
//    int i;
    int count = 1;

    while(scanf("%d %d",&num,&num2) != -1){
        num3 = num + num2;
//        printf("%d\n",num3);
//        printf("%d\n",count);
        while((num3 / 10) >= 1){
            num3 =  num3 / 10;
            count++;
//            printf("%d\n",count);
//            printf("debug\n");
        }
        printf("%d\n",count);
        count = 1;
    }
    
//    int i,j;
//    char num[256];
//    char *temp;
//    int num1,num2,num3;
//    int count = 1;
//    
//    for(i = 0; i < 200; i++){
//        gets(num);
//        temp = strtok(num," ");
//        num1 = atoi(temp);
//        
//        if(0 >= num1 || num1 >=1000000)
//            exit(0);
//        temp = strtok(NULL," ");
//        num2 = atoi(temp);
//        
//        if(0 >= num2 || num2 >=1000000)
//            exit(0);
//        num3 = num1 + num2;
//        printf("%d",num3);
////        for(j = 1; j < 7;j++){
////            if(num3 % 10 < 10)
////                break;
////            count++;
////        }
    return 0;
}

Measured memory_bytes: 600
n = int(input())

if (n+1)/1.08-n/1.08>=1:
    print(int(n/1.08))
elif n/1.08==int(n/1.08) or int(n/1.08+1)<(n+1)/1.08:
    print(int((n+1)/1.08))
else:
    print(":(")

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

#define REP(i, n) for(int i=0;i<n;i++)
#define REPR(i, n) for(int i=n;i>0;i--)
#define FOR(i, j, n) for(int i=j;i<n;i++)
#define COUT(n) cout<<(n)<<"\n"

typedef long long ll;
const int INF = 1e9;

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

    int r; cin >> r;
    COUT(r*r);

    return 0;
} 

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cassert>
#include <functional>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
using namespace std;
using llong = long long;

llong n;
llong ans = 1ll << 60ll;

int main() {
    cin >> n;

    for (llong i = 1; i * i <= n; i++) {
        if (n % i == 0) {
            ans = min(ans, i + (n / i) - 2);
        }
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <climits>
#include <cfloat>
#include <functional>
using namespace std;

int main()
{
    const int value[] = {6000, 4000, 3000, 2000};

    for(int i=0; i<4; ++i){
        int t, n;
        cin >> t >> n;
        cout << (value[t-1] * n) << endl;
    }

    return 0;
}

Measured memory_bytes: 1160
def func(b, n):
    res = 0
    while n > 0:
        res += n % b
        n //= b
    return res


def solve():
    n = int(input())
    s = int(input())

    if n == s:
        return n + 1
    elif n < s:
        return -1

    for b in range(2, n + 1):
        if b**2 > n:
            break
        if func(b, n) == s:
            return b

    b_cand = []
    for p in range(1, n + 1):
        if p**2 > n:
            break
        b = (n - s) // p + 1
        if b > 1:
            b_cand.append(b)
    b_cand = b_cand[::-1]

    for b in b_cand:
        # print(b)
        if func(b, n) == s:
            return b

    return -1


ans = solve()
print(ans)


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

using namespace std;

int gcd(int a, int b, int c)
{
  int m = __gcd(a, b), n = __gcd(b, c);
  return __gcd(m, n);
}

int main(void)
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  int N, sum = 0;
  cin >> N;
  for (int i = 1; i <= N; i++)
    for (int j = i; j <= N; j++)
      for (int k = j; k <= N; k++){
	if (i == j && j == k)
	  sum += gcd(i, j, k);
	else if (i != j && j != k && k != i)
	  sum += (gcd(i, j, k) * 6);
	else
	  sum += (gcd(i, j, k) * 3);
      }
  cout << sum << '\n';
  return 0;
}


Measured memory_bytes: 3576
#!/usr/bin/env python3
import sys
input = sys.stdin.readline

n = int(input())
x = [int(item) for item in input().split()]

ans = 10**12 
for i in range(101):
    val = 0
    for item in x:
        val += (item - i) * (item - i)
    ans = min(ans, val)
print(ans)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
#define Set(a,b) memset(a,b,sizeof(a))
template<class T>inline void init(T&x){
	x=0;char ch=getchar();bool t=0;
	for(;ch>'9'||ch<'0';ch=getchar()) if(ch=='-') t=1;
	for(;ch>='0'&&ch<='9';ch=getchar()) x=(x<<1)+(x<<3)+(ch-48);
	if(t) x=-x;return;
}typedef long long ll;
const int N=1e5+10;
const int mod=1e9+7;
template<class T>inline void Inc(T&x,int y){x+=y;if(x>=mod) x-=mod;}
int f[N];
int main()
{
	int n;
	f[0]=1;int m;init(n),init(m);
	for(int i=1;i<=m;++i) {int x;init(x);f[x]=-1;}
	for(int i=1;i<=n;++i) {
		if(f[i]==-1) continue;
		if(f[i-1]!=-1) Inc(f[i],f[i-1]);
		if(f[i-2]!=-1) Inc(f[i],f[i-2]);
	}
	if(f[n]==-1) f[n]=0;
	cout<<f[n]<<endl;
	return 0;
}


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

struct edge {
    int u, v, cost;
};

struct point {
    int x, y, num;
};

bool comp(const edge& e1, const edge& e2) {
    return e1.cost < e2.cost;
}

bool comp1(const point& p1, const point& p2) {
    return p1.x < p2.x;
}

bool comp2(const point& p1, const point& p2) {
    return p1.y < p2.y;
}

struct UnionFind {
    vector<int> Parent;
    UnionFind(int N) { Parent = vector<int>(N, -1); }
    int root(int A) {
        if (Parent[A] < 0) return A;
        return Parent[A] = root(Parent[A]);
    }
    int size(int A) { return -Parent[root(A)]; }
    bool connect(int A, int B) {
        A = root(A);
        B = root(B);
        if (A == B) {
            return false;
        }

        if (size(A) < size(B)) swap(A, B);

        Parent[A] += Parent[B];
        Parent[B] = A;

        return true;
    }
    bool same(int A, int B) { return root(A) == root(B); }
};

vector<edge> es;
int N;

int kruskal() {
    sort(es.begin(), es.end(), comp);
    UnionFind Uni(N);

    int res = 0;
    for (int i = 0; i < es.size(); i++) {
        edge e = es[i];
        if (!Uni.same(e.u, e.v)) {
            Uni.connect(e.u, e.v);
            res += e.cost;
        }
    }
    return res;
}

int main() {
    cin >> N;
    vector<point> town(N);
    for (int i = 0; i < N; i++) {
        int x, y;
        cin >> x >> y;
        town[i] = {x, y, i};
    }

    sort(town.begin(), town.end(), comp1);
    for (int i = 1; i < N - 1; i++) {
        es.push_back(
            {town[i].num, town[i + 1].num, abs(town[i].x - town[i + 1].x)});
        es.push_back(
            {town[i].num, town[i - 1].num, abs(town[i - 1].x - town[i].x)});
    }

    sort(town.begin(), town.end(), comp2);
    for (int i = 1; i < N; i++) {
        es.push_back(
            {town[i].num, town[i + 1].num, abs(town[i].y - town[i + 1].y)});
        es.push_back(
            {town[i].num, town[i - 1].num, abs(town[i - 1].y - town[i].y)});
    }

    cout << kruskal() << endl;
}

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

# define FOR(i,a,b) for (int i=(a);i<(b);i++)
# define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
# define REP(i, n) for (int i = 0; i < (int)(n); i++)
# define RREP(i,n) for (int i=(n)-1;i>=0;i--)

# define int(x) int x; scanf("%d",&x);
# define vint(v,n) vector<int> v(n); REP(i,n) scanf("%d", &v[i]);
# define string(x) string x; cin >> x;

using namespace std;

namespace utils{
  template <typename T> void print(vector<vector<T>> mat) {
    REP (i, mat.size()) {
      REP (j, mat[0].size()) cout << mat[i][j] << ' ';
      cout << endl;
    }
  }

  template <typename T> void print(vector<T> v) {
    REP (i, v.size())
      if (i >= v.size()-1)
	cout << v[i];
      else
	cout << v[i] << ' ';
    
    cout << endl;
  }

  template <typename T> pair<T, T> shape(vector<vector<T>> mat) {
    int d1, d2;

    d1 = mat.size();
    if (d1 > 0) d2 = mat[0].size();
    else int d2 = 0;
    cout << "(" << d1 << ", " << d2 << ")" << endl;
    return make_pair(0, 0);
  }

  template <typename T> vector<vector<T>> empty(int n, int m) {
    vector<vector<T>> mat(n, vector<T>(m));
    return mat;
  }
}
#define MOD 1000000007
long long fact(long long k){
  long long sum = 1;
  for (long long i = 1; i <=k;i++){
    sum *= i;
    sum %= MOD;
  }
  return (sum);
}

int main() {
  vint(A,2);

  if(abs(A[0]-A[1])<=1){
    long long ans = 1;
    ans = (fact(A[0]) * fact(A[1])) % MOD;
    if(A[0] == A[1])
      ans = (ans*2)%MOD;
    cout << ans << endl;
  }else{
    cout << 0 << endl;
  }

}


Measured memory_bytes: 256
#include <vector>
#include <string>
#include <iostream>
#include <queue>
#include <algorithm>
#include <functional>
#include <map>
#include <array>
#include <cmath>

long long PRIME = 1e9 + 7;
using namespace std;

vector<vector<int>> E;

int search(int N, int node, bool passed[8], int prev){
    passed[node - 1] = true;

    bool check = true;
    for(int i = 0; i < N; ++i){
        check = check & passed[i];
    }
    if(check){
        passed[node - 1] = false;
        return 1;
    }

    int count = 0;
    for(int next : E[node]){
        if(passed[next - 1]){
            continue;
        }

        count += search(N, next, passed, node);
    }
    passed[node - 1] = false;

    return count;
}


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

    E.resize(N+1);
    int a, b;

    for(int i = 0; i < M; ++i){
        cin >> a >> b;
        E[a].push_back(b);
        E[b].push_back(a);
    }

    bool passed[8];
    for(int i = 0; i < 8; ++i){
        passed[i] = false;
    }

    cout << search(N, 1, passed, -1);
}



Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <vector>

#define len(X) ((int)(X).size())

#ifdef __LOCAL
#define DBG(X) cout << #X << "=" << (X) << '\n';
#define SAY(X) cout << (X) << '\n';
#else
#define DBG(X)
#define SAY(X)
#endif

#define M_PI       3.14159265358979323846

using namespace std;

using ll = long long int;
using ull = unsigned long long int;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

const int INT_INF = (int)(2e9);
const ll  LL_INF = (ll)(2e18);

const int NIL = -1;
static mt19937 _g(time(nullptr));

inline ll randint(ll a, ll b) { ll w = (_g() << 31LL) ^ _g(); return a + w % (b - a + 1); }
inline void fast_io() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); };
template<typename T> inline T sign(T x) { return T(x > 0) - T(x < 0); }
template<typename T, typename S> inline ostream& operator<<(ostream& os, const pair<T, S> p) { cout << "[" << p.first << ";" << p.second << "]"; return os; }
template<typename T> inline ostream& operator<<(ostream& os, const vector<T>& v) { for (auto el : v) cout << el << " "; return os; }
template<typename T> inline T fetch() { T ret; cin >> ret; return ret; }
template<typename T> inline vector<T> fetch_vec(int sz) { vector<T> ret(sz); for (auto& elem : ret) cin >> elem; return ret; }

int solve()
{
    int N;

    std::cin >> N;

    string s;
    cin >> s;

    if (N >= 3200)
        cout << s << endl;
    else
        cout << "red" << endl;

    return 0;
}

int main()
{
    solve();

    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String s = sc.next();
		//System.out.println(s);
		int count = 0;

		for(int i = 0; i < s.length(); i++) {
			if (s.charAt(i) == '1') {
				count++;
			}
		}		
		System.out.println(count);		
	}
}


Measured memory_bytes: 21588
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define For(n) for(int i = 0; i < n; i++)
#define FOR(i, r, k) for(int i = r; i < k; i ++)
#define pb push_back
#define X first
#define Y second
#define mp make_pair
const ll maxn = 1e5 + 244;
const ll mod = 1e9 + 7;
const ll inf = 1e18 + 500;
ll l[maxn];

int main()
{
    ll n, m;
    cin >> n >> m;
    For(m)
    {
        int u, v;
        cin >> u >> v;
        l[u] ++;
        l[v] ++;
    }
    For(n)
    {
        if(l[i + 1] & 1)
        {
            cout << "NO";
            return 0;
        }
    }
    cout << "YES";
    return 0;
}


Measured memory_bytes: 1024
// #define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define Graph vector<vector<int>>
typedef long long ll;
typedef pair<int, int> P;
const ll INF = 1000000007;

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

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

int main(){
    int N, M;
    cin >> N >> M;
    vector<int> A(N);
    rep(i, N){
        cin >> A[i];
        A[i] /= 2;
    }

    int div2 = 0;
    bool flag = true;

    rep(i, N){
        int count = 0, tmp = A[i];
        while(tmp % 2 == 0){
            count++;
            tmp /= 2;
        }
        if(i == 0) div2 = count;
        else if(div2 != count){
            flag = false;
            break;
        }
    }

    if(flag){
        ll lcm_cal = A[0];
        bool flag2 = true;
        for(int i = 1; i < N; i++){
            lcm_cal = lcm(lcm_cal, A[i]);
            if(lcm_cal > M){
                flag2 = false;
                break;
            }
        }
        if(flag2){
            int sum = 0;
            for(ll i = 1; i * lcm_cal <= M; i += 2) sum++;
            cout << sum << endl;
            return 0;
        }
    }
    
    cout << 0 << endl;
}

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

int main() {
  int K;
  cin>>K;
  int64_t N;
  vector<int64_t> vec(K+1);
  vec[0]=2;
  vec[1]=1;
  for(int i=2;i<K+1;i++){
    vec[i]=vec[i-1]+vec[i-2];
  }
  N=vec[K];
  cout<<N<<endl;
}

Measured memory_bytes: 256
import math
from decimal import Decimal
n,k=map(int,input().split())
a=[0]*(n+1)
for x in range(1,n+1):
  a[x] = max(0, math.ceil(math.log(k,2)- math.log(x,2)))
bunsi = 0
for x in range(1,n+1):
  bunsi += 2**(a[1]-a[x])
print(Decimal(bunsi/(n*2**a[1])))

Measured memory_bytes: 10292
#include <algorithm> //STLÍ¨ÓÃËã·¨
#include <cmath> //¶¨ÒåÊýÑ§º¯Êý
#include <cstdio> //¶¨ÒåÊäÈë/Êä³öº¯Êý
#include <iostream> //Êý¾ÝÁ÷ÊäÈë/Êä³ö
#include <cstring> //×Ö·û´®´¦Àí
#include <string> //×Ö·û´®Àà
#include <ctime> //¶¨Òå¹ØÓÚÊ±¼äµÄº¯Êý
#define itn int
#define fro for
#define ll long long
#define reg register
#define inf 1234567890
#define rep(i,a,b,c) for (int i=a;i<=b;i+=c)
/*#include <bitset> //STLÎ»¼¯ÈÝÆ÷
#include <cstype> //×Ö·û´¦Àí
#include <cerrno> //¶¨Òå´íÎóÂë
#include <complex> //¸´ÊýÀà
#include <clocale> //¶¨Òå±¾µØ»¯º¯Êý
#include <cstdlib> //¶¨ÒåÔÓÏîº¯Êý¼°ÄÚ´æ·ÖÅäº¯Êý
#include <deque> //STLË«¶Ë¶ÓÁÐÈÝÆ÷
#include <exception> //Òì³£´¦ÀíÀà
#include <fstream> //ÎÄ¼þÊäÈë/Êä³ö
#include <functional> //STL¶¨ÒåÔËËãº¯Êý(´úÌæÔËËã·û)
#include <limits> //¶¨Òå¸÷ÖÖÊý¾ÝÀàÐÍ×îÖµ³£Á¿
#include <list> //STLÏßÐÔÁÐ±íÈÝÆ÷
#include <map> //STLÓ³ÉäÈÝÆ÷
#include <iomanip> //²ÎÊý»¯ÊäÈë/Êä³ö
#include <ios> //»ù±¾ÊäÈë/Êä³öÖ§³Ö
#include <iosfwd> //ÊäÈë/Êä³öÏµÍ³Ê¹ÓÃµÄÇ°ÖÃÉùÃ÷
#include <istream> //»ù±¾ÊäÈëÁ÷
#include <ostream> //»ù±¾Êä³öÁ÷
#include <queue> //STL¶ÓÁÐÈÝÆ÷
#include <set> //STL¼¯ºÏÈÝÆ÷
#include <sstream> //»ùÓÚ×Ö·û´®µÄÁ÷
#include <stack> //STL¶ÑÕ»ÈÝÆ÷
#include <stdexcept> //±ê×¼Òì³£Àà
#include <streambuf> //µ×²ãÊäÈë/Êä³öÖ§³Ö
#include <utility> //STLÍ¨ÓÃÄ£°åÀà
#include <vector> //STL¶¯Ì¬Êý×éÈÝÆ÷
#include <cwchar.h>//¿í×Ö·û´¦Àí¼°ÊäÈë/Êä³ö
#include <cwctype.h> //¿í×Ö·û·ÖÀà*/

using namespace std;

int ans;

int max(int x,int y){return x>y?x:y;}

int min(int x,int y){return x<y?x:y;}

int abs(int x){return x>0?x:-x;}

int gcd(int x,int y){return (!y)?x:gcd(y,x%y);}

void exgcd(int a,int b,int &d,int &x,int &y){if (!b){d=a,x=1,y=0;}else{exgcd(b,a%b,d,y,x);y-=x*(a/b);}}

int quick_power(ll a,int b){ll r=1;for (;b;b>>=1,a=a*a)if (b&1) r=r*a;return r;}

inline char read() {
	static const int IN_LEN=1000000;
	static char buf[IN_LEN],*s,*t;
	return (s==t ? t=(s=buf)+fread(buf,1,IN_LEN,stdin),(s==t ? -1 : *s++) : *s++);
}
template<class T>
inline void read(T &x) {
	static bool iosig;
	static char c;
	for (iosig=false,c=read();!isdigit(c);c=read()) {
		if (c=='-') iosig=true;
		if (c==-1) return;
	}
	for (x=0;isdigit(c);c=read()) x=x * 10+(c ^ '0');
	if (iosig) x=-x;
}

char sr[10000000],z[20];int C=-1,Z=0;
void Ot(){fwrite(sr,1,C+1,stdout),C=-1;}
void print(int x){
	if (x<0) sr[++C]='-',x=-x;
	while(z[++Z]=x%10+48,x/=10);
	while(sr[++C]=z[Z],--Z);sr[++C]='\n';
}
//int find(int x){return fa[x]=fa[x]==x?x:find(fa[x]);}

//void add(int x,int y,int z){to[++cnt]=y;v[cnt]=z;Next[cnt]=head[x];head[x]=cnt;}

const int N=1010;

int a[N],b[N];
int n,m,c,fg;
char s[45];

int main()
{
	read(n);
	c=0;
	for (int i=1;i<=n;i++)
	{
		read(a[i]);read(b[i]);
		if ((a[i]+b[i])&1) c++;
		else c--;
	}

	if (abs(c)!=n) return 0*puts("-1");

	m=31+(c<0);

	printf("%d\n",m);
	for (int i=0;i<=30;i++) printf("%d ",1<<i);
	if (c<0) putchar(49);
	putchar(10);

	for (int i=1;i<=n;i++)
	{
		int x=a[i],y=b[i];
		if (c<0) s[31]='R',x--;
		fg=0;
		for (int j=30;j>=0;j--)
		{
			if (abs(x)<abs(y)) swap(x,y),fg^=1;
			if (x>0) x-=1<<j,s[j]=fg?'U':'R';
			else x+=1<<j,s[j]=fg?'D':'L';
		}
		puts(s);
	}
	return 0;
}








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

int n,m,d[100111],eu[100111],ev[100111],f[100111];
int gf(int x){return x==f[x]?x:f[x]=gf(f[x]);}
int main()
{
	scanf("%d%d",&n,&m);
	for(int i=1;i<=m;i++)
	{
		scanf("%d%d",eu+i,ev+i);
		d[eu[i]]++;d[ev[i]]++;
	}
	for(int i=1;i<=n;i++)if(d[i]%2==1){puts("No");return 0;}
	int v=max_element(d+1,d+n+1)-d;
	if(d[v]>=6){puts("Yes");return 0;}
	if(d[v]==2){puts("No");return 0;}
	int cnt=0;for(int i=1;i<=n;i++)if(d[i]==d[v])cnt++;if(cnt>=3){puts("Yes");return 0;}
	if(cnt==1){puts("No");return 0;}
	for(int i=1;i<=n;i++)f[i]=i;for(int i=1;i<=m;i++)if(eu[i]!=v&&ev[i]!=v)f[gf(eu[i])]=gf(ev[i]);
	for(int i=1;i<=n;i++)if(i!=v&&gf(i)!=gf(v%n+1)){puts("Yes");return 0;}
	puts("No");
	return 0;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
#define FORD(i,a,b) for(int i=(a);i>=b;i--)
#define FOR(i,a,b) for(int i=(a);(i)<=(b);(i)++)
#define ll long long
using namespace std;
int a[40005],b[40005];
ll num[40005];
int main()
{
	int h,n;
	ll ans=1e17;
	cin>>h>>n;
	FOR(i,1,n) cin>>a[i]>>b[i];
	FOR(i,1,40005) num[i]=1e17;
	FOR(i,1,n) FOR(j,a[i],40005) {
		num[j]=min(num[j],num[j-a[i]]+b[i]);
		if(j>=h)ans=min(ans,num[j]);
	}
	cout<<ans;
	return 0;
}


Measured memory_bytes: 512
let rec ext_euclid a b =
  if b = 0 then (1, 0, a)
  else
    let (x, y, d) = ext_euclid b (a mod b) in
    (y, x - (a / b) * y, d)

let () =
  let (a, b) = Scanf.scanf "%d %d\n" (fun a b -> (a, b)) in
  let (x, y, _) = ext_euclid a b in
  Printf.printf "%d %d\n" x y

Measured memory_bytes: 2420
import heapq
import copy
N = input()
A = [-int(input()) for _ in range(int(N))]
A_heap = copy.deepcopy(A)
heapq.heapify(A_heap)
for idx, a in enumerate(A):
    pop_A = heapq.heappop(A_heap)
    pop_A_list = []
    pop_A_list.append(pop_A)
    if pop_A == a:
        pop_A2 = heapq.heappop(A_heap)
        print(-(pop_A2))
        heapq.heappush(A_heap, pop_A)
        heapq.heappush(A_heap, pop_A2)
        continue

    print(-(pop_A))
    heapq.heappush(A_heap, pop_A)

Measured memory_bytes: 125912
#include <bits/stdc++.h>
using namespace std;
#define rep(i, m, n) for (int i = m; i < n; ++i)

int main() {
    int N; cin >> N;
    N--;
    vector<int> B(N);
    rep(i, 0, N) cin >> B[i];
    int ans = B[0] + B[N - 1];
    rep(i, 0, N - 1) ans += min(B[i], B[i + 1]);
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>	
#include<map>
#include<set>
#include<utility>
#include<cmath>
#include<cstring>
#include<queue>
#include<cstdio>
#include<sstream>
#include<iomanip>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define mp make_pair
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
using namespace std;
//kaewasuretyuui
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef pair<int,pii> pip;
typedef vector<pip>vip;
const double PI=acos(-1);
const double EPS=1e-8;
const int inf=1<<30;
vector<string>in;
vi visit;
set<string>out;
int n,m;
void f(int b){
	if(b==m){
		string s="";
		rep(i,m)rep(j,n)if(visit[j]==i)s+=in[j];
		out.insert(s);
	}else{
		rep(i,n)if(visit[i]==inf){
			visit[i]=b;
			f(b+1);
			visit[i]=inf;
		}
	}
}
int main(){
	while(cin>>n,n){
		cin>>m;
		in=vector<string>(n);
		rep(i,n)cin>>in[i];
		out.erase(all(out));
		visit=vi(n,inf);
		f(0);
		cout<<out.size()<<endl;
	}
}

Measured memory_bytes: 1484
input = input()

nums = input.split(" ")

animals = int(nums[0])
legs = int(nums[1])

turu = (4*animals -legs)/2.0
kame = (legs-2*animals)/2.0

if turu.is_integer() and kame.is_integer() and turu>=0 and kame>=0:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 9188
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vin=vector<int>;
using vll=vector<long long>;
using vvin=vector<vector<int>>;
using vvll=vector<vector<long long>>;
using vstr=vector<string>;
using vvstr=vector<vector<string>>;
using vch=vector<char>;
using vvch=vector<vector<char>>;
using vbo=vector<bool>;
using vvbo=vector<vector<bool>>;
using vpii=vector<pair<int,int>>;
using pqsin=priority_queue<int,vector<int>,greater<int>>;
#define mp make_pair
#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++)
#define all(v) v.begin(),v.end()
#define decp(n) cout<<fixed<<setprecision((int)n)
#define _GLIBCXX_DEBUG
const int inf=1e9+7;

int main(){
    int n;cin>>n;
    vin b(n);
    rep(i,n-1)cin>>b[i];
    b[n-1]=inf;
    int sum=b[0];
    rep(i,n-1)sum+=min(b[i],b[i+1]);
    cout<<sum<<endl;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<map>
#include<queue>
#include<stack>
#include<vector>
#include<iostream>
#include<string>
#include<set>
#include<list>
using namespace std;
typedef long long ll;
const int N = 2e5+10;
const int INF = 0x3f3f3f3f;
int max(int a,int b) {return a>b?a:b;}
int min(int a,int b) {return a>b?b:a;}
const double eps = 1e-7;
#define endl '\n'
#define pb(a) push_back(a)
#define ALL(x) x.begin(),x.end()

int n;
map<ll,ll>a,b;
int main() {
    //ios::sync_with_stdio(false);
    scanf("%d",&n);
    for(int i=1;i<=n;++i) {
    	ll x;
    	scanf("%lld",&x);
    	a[x+i]++;
    	b[i-x]++;
    }
    ll ans=0;
    for(auto &x:a) ans+=b[x.first]*x.second;
    cout<<ans<<endl;
    return 0;
}

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

using namespace std;

struct point {
	double x, y;
	point() {}
	point(double _x, double _y) : x(_x), y(_y) {}
};

point operator + (const point &P, const point &Q) {
	return point(P.x + Q.x, P.y + Q.y);
}

point operator - (const point &P, const point &Q) {
	return point(P.x - Q.x, P.y - Q.y);
}

point operator * (const point &P, const double k) {
	return point(P.x * k, P.y * k);
}

inline double dot(const point &P, const point &Q) {
	return P.x * Q.x + P.y * Q.y;
}

inline double norm2(const point &P) {
	return dot(P, P);
}

inline double norm(const point &P) {
	return sqrt(dot(P, P));
}

inline point project(const point &P, const point &P1, const point &P2) {
	return P1 + (P2 - P1) * (dot(P2 - P1, P - P1) / norm2(P2 - P1));
}

inline point reflect(const point &P, const point &P1, const point &P2) {
	return project(P, P1, P2) * 2.0 - P;
}

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

	point P1, P2;
	cin >> P1.x >> P1.y >> P2.x >> P2.y;

	int q;
	cin >> q;
	while (q--) {
		point P;
		cin >> P.x >> P.y;
		point answer = reflect(P, P1, P2);
		cout << fixed << answer.x << " " << fixed << answer.y << "\n";
	}
}

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

public class Main {

	final static long MOD = 1000000007L;
	public static String[] Ws = null;
	public static int wsIndx = 0;
	public static BufferedReader in = null;
	public static ArrayList<int[]> list = new ArrayList<>();
	public static void main(String[] args) throws Exception {

		int N = nextInt();
		int M = nextInt();

		long[][] p = new long[N][];
		for(int i=0;i<N;i++){
			p[i]=nextLongs();
		}

		Arrays.sort(p,(a,b)->{return (int) (a[0]-b[0]);});
		long ans = 0;
		for(long[] a:p){
			if(M==0){
				break;
			}
			long buy = Math.min(Math.max(M-a[1],M),a[1]);
			ans+=buy*a[0];
			M-=buy;
		}
		System.out.println(ans);
	}

	public static String[] toStringArray(String s) {
		String[] tmp = new String[s.length()];
		char[] c = s.toCharArray();
		for (int i = 0; i < tmp.length; i++) {
			tmp[i] = String.valueOf(c[i]);
		}
		return tmp;
	}

	public static void check() throws Exception{
		if(in == null){
			in = new BufferedReader(new InputStreamReader(System.in));
		}
		if(Ws==null || Ws.length<=wsIndx){
			Ws = in.readLine().split(" ");
			wsIndx=0;
		}
	}
	public static int nextInt()throws Exception{
		check();
		return Integer.parseInt(Ws[wsIndx++]);
	}

	public static long nextLong()throws Exception{
		check();
		return Long.parseLong(Ws[wsIndx++]);
	}

	public static String nextString()throws Exception{
		check();
		return Ws[wsIndx++];
	}

	public static int[] nextInts()throws Exception{
		check();
		int[] tmp = new int[Ws.length];
		for(int i=0;i<tmp.length;i++){
			tmp[i]=Integer.parseInt(Ws[i]);
		}
		wsIndx=Ws.length;
		return tmp;
	}

	public static long[] nextLongs()throws Exception{
		check();
		long[] tmp = new long[Ws.length];
		for(int i=0;i<tmp.length;i++){
			tmp[i]=Long.parseLong(Ws[i]);
		}
		wsIndx=Ws.length;
		return tmp;
	}

	public static String[] nextStrings()throws Exception{
		check();
		wsIndx=Ws.length;
		return Ws;
	}


}


Measured memory_bytes: 49072
#include <stdio.h>

char G[2000][2000];
static int X[2000][2000];
static int Y[2000][2000];

int main(void) {
  int H, W;
  scanf("%d%d", &H, &W);

  for(int i = 0; i < H; i++) {
    for(int j = 0; j < W; j++) {
      scanf(" %c", &G[i][j]);
    }
  }

  int MaxL = 0;
  for(int i = 0; i < H; i++) {
    for(int j = 0; j < W; j++) {
      if(G[i][j] == '#') continue;

      if(X[i][j] == 0) {
	int lp = j;
	int rp = j;
	while(lp != 0 && G[i][lp-1] == '.') lp--;
	while(rp != (W-1) && G[i][rp+1] == '.') rp++;
	for(int x = lp; x <= rp; x++) {
	  int num = rp - lp + 1;
	  X[i][x] = num;
	  //printf("X[%d][%d] = %d\n", i, x, num);
	}
      }
      if(Y[i][j] == 0) {
	int tp = i;
	int bp = i;
	while(tp != 0 && G[tp-1][j] == '.') tp--;
	while(bp != (H-1) && G[bp+1][j] == '.') bp++;
	for(int y = tp; y <= bp; y++) {
	  int num = (bp - tp) + 1;
	  Y[y][j] = num;
	  //printf("Y[%d][%d] = %d\n", y, j, num);
	}
      }
      int Light = X[i][j] + Y[i][j] - 1;
      MaxL = (MaxL > Light) ? MaxL : Light;
    }
  }
  printf("%d\n", MaxL);
  return 0;
}


Measured memory_bytes: 35328
#define _USE_MATH_DEFINES

#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <utility>
#include <climits>
#include <vector>
#include <map>
#include <queue>
using namespace std;

#define ll long long
const int MOD = 1000000007;//10^9+7

ll max(ll a, ll b) {

	if (a > b)return a;
	else return b;

}
double max(double a, double b) {

	if (a > b)return a;
	else return b;

}
//a??¨b?????§?????????

ll min(ll a, ll b) {

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

}
//a??¨b????°??????????

ll avd_i(ll a, ll b) {

	if (a > b)return a - b;
	else return b - a;

}
double avd_d(double a, double b) {

	double re;
	if (a > b)re = a - b;
	else re = b - a;
	return re;

}
//a??¨b???????????¶??????

ll powsur(ll a, ll b, ll p) {

	if (b == 0) {

		return 1;

	}
	else if (b % 2 == 0) {

		ll d = powsur(a, b / 2, p);
		return ((d%p)*(d%p)) % p;

	}
	else {

		return ((a%p)*powsur(a, b - 1, p) % p) % p;

	}

}
//p????´???°,a???b??????p??§?????£?????????

ll CMOD(ll n, ll r, ll p) {

	ll a = 1, b = 1, c = 1, re;
	for (int i = 1; i <= n; i++) {

		a *= i;
		a = a%p;

	}
	for (int i = 1; i <= r; i++) {

		b *= i;
		b = b%p;

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

		c *= i;
		c = c%p;

	}
	b = powsur(b, p - 2, p);
	c = powsur(c, p - 2, p);
	re = ((a%p)*(b%p)) % p;
	re = ((re%p)*c%p) % p;

	return re;

}
//p????´???°,(nCr)%p

ll gcd(ll a, ll b) {

	if (a > b) {

		ll tmp = a;
		a = b;
		b = tmp;

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

}
//?????§??¬?´???°

ll lcm(ll a, ll b) {

	return (a / gcd(a, b))*b;

}
//????°???¬?????°

int main() {
	
	int a, b;
	char c;

	while (1) {

		cin >> a >> c >> b;

		if (c == '?')break;
		if (c == '+')cout << a + b << endl;
		if (c == '-')cout << a - b << endl;
		if (c == '*')cout << a * b << endl;
		if (c == '/')cout << a / b << endl;

	}

	return 0;
}

Measured memory_bytes: 3088