akhauriyash/Code-Regression huggingface dataset:
from collections import defaultdict,deque
import sys,heapq,bisect,math,itertools,string,queue,copy,time
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpl_str(): return list(sys.stdin.readline().split())

N = inp()
xys = [inpl() for _ in range(N)]

if N == 2:
    x0,y0 = xys[0]
    x1,y1 = xys[1]
    print(math.sqrt((x1-x0)**2 + (y1-y0)**2)/2)
    sys.exit()


ans = INF
for i in range(N):
    for j in range(i+1,N):
        for k in range(j+1,N):
            a,b = xys[i]
            c,d = xys[j]
            e,f = xys[k]

            aa = a * a
            bb = b * b
            cc = c * c
            dd = d * d
            ee = e * e
            ff = f * f

            try:
                py = ((e - a) * (aa + bb - cc - dd) - (c - a) * (aa + bb - ee- ff)) / (2 * (e - a)*(b - d) - 2 * (c - a) * (b - f))
                px = (2 * (b - f) * py - aa - bb + ee + ff) / (2 * (e - a)) \
                    if (c == a) else (2 * (b - d) * py - aa - bb + cc + dd) / (2 * (c - a))
                r = math.hypot(px - a, py - b)
            except:
                if a == c == e:
                    px = a
                    py = (max(b,d,f) + min(b,d,f))/2
                    r = max(b,d,f) - min(b,d,f)
                elif b == d == f:
                    px = (max(a,c,e) + min(a,c,e))/2
                    py = b
                    r = max(a,c,e) - min(a,c,e)

            for x,y in xys:
                if (px-x)**2 +(py-y)**2 <= r**2 + eps:
                    continue
                else:
                    break
            else:
                ans = min(ans,r)


for i in range(N):
    for j in range(i+1,N):
        x0,y0 = xys[i]
        x1,y1 = xys[j]
        px = (x0+x1)/2
        py = (y0+y1)/2
        r = math.hypot(px - x0, py - y0)

        for x,y in xys:
            if (px-x)**2 +(py-y)**2 <= r**2 + eps:
                continue
            else:
                break
        else:
            ans = min(ans,r)

print(ans)


Measured memory_bytes: 4328
package main

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

type queue struct {
	p    []process
	head int
	tail int
	size int
}

type process struct {
	name string
	time int
}

func newQueue(n int) *queue {
	p := make([]process, n)
	return &queue{p, 0, 0, n - 1}
}

func (q *queue) enqueue(p process) {
	q.p[q.tail] = p
	if q.tail == q.size {
		q.tail = 0
	} else {
		q.tail++
	}
}

func (q *queue) dequeue() process {
	p := q.p[q.head]
	if q.head == q.size {
		q.head = 0
	} else {
		q.head++
	}
	return p
}

func main() {
	s := bufio.NewScanner(os.Stdin)
	e := []string{}
	if s.Scan() {
		e = strings.Fields(s.Text())
	}
	n, _ := strconv.Atoi(e[0])
	q, _ := strconv.Atoi(e[1])

	Q := newQueue(n)
	for i := 0; i < n; i++ {
		if !s.Scan() {
			break
		}
		tmp := strings.Fields(s.Text())
		t, _ := strconv.Atoi(tmp[1])
		p := process{tmp[0], t}
		Q.enqueue(p)
	}

	cnt := 0
	for n > 0 {
		p := Q.dequeue()
		t := p.time - q
		if t > 0 {
			p.time = t
			Q.enqueue(p)
			cnt = cnt + q
		} else {
			cnt = cnt + p.time
			n--
			fmt.Printf("%v %d\n", p.name, cnt)
		}
	}
}



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

const int MAX = 10010;
const int MAX_DP = 20020;
const long long INF = 1 << 30;

int main()
{
    int H, N, A[MAX], B[MAX];
    cin >> H >> N;

    for (int i = 0; i < N; i++)
    {
        cin >> A[i] >> B[i];
    }

    long long dp[H + 1];
    // long long dp[N + 1][H + 1];
    // memset(dp, INF, sizeof(dp));
    dp[0] = 0;
    for (int i = 1; i <= H; i++)
    {
        dp[i] = INF;
    }

    for (int i = 0; i < H; i++)
    {
        for (int j = 0; j < N; j++)
        {
            dp[min(i + A[j], H)] = min(dp[min(i + A[j], H)], dp[i] + B[j]);
        }
    }

    cout << dp[H] << endl;

    // for (int i = 0; i < N; i++)
    // {
    //     for (int j = 0; j < H; j++)
    //     {
    //         if (j == 0 || dp[i][j] != 0)
    //         {
    //             // int max_k = ((H - j) + 1) / A[i];
    //             // int max_k = ((H - j) + A[i] - 1) / A[i];
    //             for (int k = 0; j + k * B[i] <= H; k++)
    //             {
    //                 if (dp[i + 1][min(H, j + k * A[i])] != 0)
    //                 {
    //                     dp[i + 1][min(H, j + k * A[i])] = min(dp[i][min(H, j + k * A[i])], dp[i][j] + k * B[i]);
    //                 }
    //                 else
    //                 {
    //                     dp[i + 1][min(H, j + k * A[i])] = dp[i][j] + k * B[i];
    //                 }
    //             }
    //         }
    //     }
    // }

    // for (int i = 1; i <= N; i++)
    // {
    //     for (int j = 0; j <= H; j++)
    //     {
    //         cout << dp[i][j] << " ";
    //     }
    //     cout << endl;
    // }

    // cout << dp[N][H] << endl;
}


Measured memory_bytes: 384
//AUTHOR - NAVEEN KUMAR(@naveen19991124)
#include<bits/stdc++.h>
//#include<boost/multiprecision/cpp_int.hpp>
//#inlcude<boost/multiprecision/cpp_dec_float.hpp>
#define ll long long
#define pb push_back
#define f(a) for(ll i = 0;i<a;i++)
#define rep(i,a,b) for(ll i = a;i<b;i++)
#define rrep(i,a,b) for(ll i = a;i>b;i--)
#define v vector<ll>
#define mp make_pair
#define fir first
#define sec second
#define _fast_ ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace std;
//using boost :: multiprecision :: cpp_int;
//using boost :: multiprecision :: cpp_dec_float_50;
//using boost :: multiprecision :: cpp_dec_float_100;
ll power(ll a, ll n) {ll p = 1;while (n > 0) {if(n%2) {p = p * a;} n >>= 1; a *= a;} return p;}

ll power(ll a, ll n, ll mod) {ll p = 1;while (n > 0) {if(n%2) {p = p * a; p %= mod;} n >>= 1;
a *= a; a %= mod;} return p % mod;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a * (b / gcd(a, b)); }
ll dp[405][405];
ll n;
int main()
{
    _fast_
    ll t = 1;
   // cin>>t;
    while(t--){
    cin>>n;
    ll arr[n+1];
    ll prefix[n+1];
    rep(i,1,n+1)
    {
        cin>>arr[i];
    }
    memset(prefix,0,sizeof(prefix));
    memset(dp,0x3f,sizeof(dp));
    for(ll i = 1;i<=n;i++)
    {
        prefix[i] = arr[i]+prefix[i-1];
        dp[i][i] = 0;
    }
    for(ll len = 2;len<=n;len++)
    {
        for(ll left = 1;left<=n-len+1;left++)
        {
            ll right = left+len-1;
            for(ll i = left;i<right;i++)
            {
                dp[left][right] = min(dp[left][right],dp[left][i] + dp[i+1][right]);
            }
            dp[left][right] += prefix[right]-prefix[left-1];
        }
    }
    cout<<dp[1][n]<<"\n";
    }
    return 0;
}

Measured memory_bytes: 1536
#include<iostream>
#include<vector>
#include<climits>
#include<cmath>
#include<queue>

using namespace std;

struct edge {
  int to, cost;
};

struct state {
  int pos, cost;

  bool operator < (const state& s) const {
    return cost > s.cost;
  }
};

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

  vector< vector<edge> > edges(n, vector<edge>());
  for (int i = 0; i < n; i++) {
    int u, k; cin >> u >> k;

    while (k--) {
      int to, cost; cin >> to >> cost;
      edges[u].push_back((edge) { to, cost});
    }
  }

  priority_queue<state> queue;
  vector<int> costs(n, INT_MAX);
  costs[0] = 0;
  queue.push((state) {0, 0});

  while(!queue.empty()) {
    const state now = queue.top();
    queue.pop();

    if (costs[now.pos] < now.cost) continue;
    
    for (int i = 0; i < edges[now.pos].size(); i++) {
      state nex = now;
      nex.pos = edges[now.pos][i].to;
      nex.cost += edges[now.pos][i].cost;
      if (costs[nex.pos] > nex.cost) {
        costs[nex.pos] = nex.cost;
        queue.push(nex);
      }
    }
  }

  for (int i = 0; i < n; i++)
    cout << i << " " << costs[i] << endl;
  
  return 0;
}
 



Measured memory_bytes: 7932
N, X, Y = map(int,input().split())
X -= 1
Y -= 1
ls = [0]*(N)
for i in range(N):
    for j in range(i+1, N):
        d = min(j-i, abs(X-i)+1+abs(Y-j))
        ls[d] += 1
for i in range(1, N):
    print(ls[i])        

Measured memory_bytes: 3444
#![allow(dead_code)]
use std::io::*;

fn main(){
    let n: usize = read();
    let mut a: Vec<i32> = vec![0; 1];
    for _ in 0..n{
        a.push(read());
    }
    let mut m = 0;
    let mut b: Vec<usize> = vec![];
    let mut c: Vec<i32> = vec![0; n + 1];
    for i in (1..n + 1).rev(){
        let mut p = i * 2;
        let mut sum = 0;
        while p <= n{
            sum += c[p];
            p += i;
        }
        sum %= 2;
        if sum != a[i]{
            m += 1;
            b.push(i);
            c[i] = 1;
        }

    }
    println!("{}", m);
    if m > 0{
        print!("{}", b[0]);
        for i in 1..m{
            print!(" {}", b[i]);
        }
        println!("");
    }
}

fn read<T>() -> T
where
    T: std::str::FromStr,
{
    let stdin = std::io::stdin();
    let token: String = stdin
        .lock()
        .bytes()
        .map(|c| c.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().unwrap()
}


Measured memory_bytes: 9212
#include <bits/stdc++.h>
#define F first
#define S second
using namespace std;
typedef long long ll;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef pair<int, int> ii;
typedef vector<ii> vii;


int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    string s1, s2 , s3;
    cin >> s1 >> s2 >> s3;
    int ind1 = 0, ind2 = 0, ind3 = 0, cur = 0;
    while (true) {
        int aux;
        if (cur == 0) {
            if (ind1 == s1.size()) {
                cout << "A\n";
                return 0;
            }
            aux = s1[ind1++]-'a';
        } else if (cur == 1) {
            if (ind2 == s2.size()) {
                cout << "B\n";
                return 0;
            }
            aux = s2[ind2++]-'a';
        } else {
            if (ind3 == s3.size()) {
                cout << "C\n";
                return 0;
            }
            aux = s3[ind3++]-'a';
        }
        cur = aux;
    }
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#define _USE_MATH_DEFINES
#include<math.h>
#include<queue>
#include<deque>
#include<stack>
#include<cstdio>
#include<utility>
#include<set>
#include<list>
#include<cmath>
#include<stdio.h>
#include<string.h>
#include<iomanip>
#include<cstdio>
#include<cstdlib>
#include<cstring>
using namespace std;
#define FOR(i, a, b) for (ll i = (a); i <= (b); i++)
#define REP(i, n) FOR(i, 0, n - 1)
#define NREP(i, n) FOR(i, 1, n)
using ll = long long;
using pii = pair<int, int>;
using piii = pair<pii, pii>;
const ll dx[4] = { 0,1,0,-1 };
const ll dy[4] = { -1, 0, 1,0 };
const int INF = 1e9 + 7;
int gcd(int x, int y) {
	if (x < y)swap(x, y);
	if (y == 0)return x;
	return gcd(y, x%y);
}
void mul(ll a, ll b) {
	a = a * b % INF;
}
double mysqrt(double x) {
	double l = 0, r = x;
	for (int i = 0; i < 64; ++i) {
		double m = (l + r) / 2.0;
		if (m*m < x)l = m;
		else r = m;
	}
	return l;
}
///////////////////////////////////////


int main() {
	string s;
	cin >> s;
	if (s.size() == 2) {
		if (s[0] == s[1]) {
			cout << 1 << " " << 2 << endl;
			return 0;
		}
		else {
			cout << -1 << " " << -1 << endl;
			return 0;
		}
	}
	for (int i = 0; i < s.size()-2; ++i) {
		if (s[i] == s[i + 1]) {
			cout << i + 1 << " " << i + 2 << endl;
			return 0;
		}
		if (s[i] == s[i + 2]) {
			cout << i + 1 <<" "<< i + 3 << endl;
			return 0;
		}
	}
	if (s[s.size() - 2] == s[s.size() - 1]) {
		cout << s.size() - 1 << " " << s.size() - 1 << endl;
		return 0;
	}
	cout << -1 << " " << -1 << endl;
	return 0;
}


Measured memory_bytes: 512
#include <algorithm>
#include <iostream>
#include <numeric>
#include <vector>

using namespace std;

const vector<vector<int>> DivideGroup(const vector<int> origGroup)
{
    vector<vector<int>> divideds;
    vector<int> divided;
    for (const int member : origGroup)
    {
        if (member == 0)
        {
            if (!divided.empty())
            {
                divideds.push_back(divided);
                divided.clear();
            }
        }
        else
        {
            divided.push_back(member);
        }
    }
    if (!divided.empty())
    {
        divideds.push_back(divided);
    }
    return divideds;
}

int main()
{
    int N;
    cin >> N;
    vector<int> heights(N);
    for (int i = 0; i < N; ++i)
    {
        cin >> heights[i];
    }
    if (accumulate(heights.begin(), heights.end(), 0) == 0)
    {
        cout << 0 << endl;
        return 0;
    }

    vector<vector<int>> groups{ heights };
    int num = 0;
    for (;;)
    {
        if (groups.empty())
        {
            break;
        }

        // 0で各グループを分割
        vector<vector<int>> dividedGroups;
        for (auto itr = groups.begin(); itr != groups.end();)
        {
            const auto divideds = DivideGroup(*itr);
            if (!divideds.empty())
            {
                dividedGroups.insert(dividedGroups.end(),
                    divideds.begin(), divideds.end());
                itr = groups.erase(itr);
            }
            else
            {
                ++itr;
            }
        }
        groups.insert(groups.end(), dividedGroups.begin(), dividedGroups.end());

        // 各グループごとに１ずつ減らす
        for (auto &group : groups)
        {
            for (int &member : group)
            {
                --member;
            }
            ++num;
        }

        // グループ内がゼロのグループは削除
        for (auto itr = groups.begin(); itr != groups.end();)
        {
            if (accumulate(itr->begin(), itr->end(), 0) == 0)
            {
                itr = groups.erase(itr);
            }
            else
            {
                ++itr;
            }
        }
    }
    cout << num << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define pb          push_back
#define vi          vector<int>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define endl        "\n"
#define fast        ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define int         long long int
#define mod         1000000007
 
#define test        int tc;cin>>tc;while(tc--)
 
int32_t main(){
 
    fast;
    pair<int,int>p1,p2;
    cin>>p1.F>>p1.S;
    cin>>p2.F>>p2.S;
    int k;cin>>k;

    pair<int,int>p3;
    if(p2.S < p1.S)
    {
        p3.S=abs(p2.S+60-p1.S);
        p2.F--;
    }
    else
        p3.S=p2.S-p1.S;

    p3.F=p2.F-p1.F;

    int val=(p3.F*60+p3.S)-k;
    if(val<=0)
        cout<<0<<endl;
    else
        cout<<val<<endl;
    return 0;
}

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

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(a) (a).begin(), (a).end()
#define SZ(x) ((int)(x).size())

using namespace std;
using ll = long long;

template <class T>
bool chmax(T &a, const T &b)
{
    if (a < b)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T &a, const T &b)
{
    if (b < a)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <typename T>
constexpr T INF = numeric_limits<T>::max() / 2;

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

    int n;
    cin >> n;
    int l;
    cin >> l;
    int ans = -INF<int>;
    REP(i, n - 1)
    {
        int r;
        cin >> r;
        chmax(ans, r - l);
        chmin(l, r);
    }
    cout << ans << endl;

    return 0;
}


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

int main() {
  int N, M;
  cin >> N >> M;
  
  // N = 2,4,6...
  // M = 1,3,5...
  
  int J,K;
  for ( int i = 0; i < N; i++ ) {
    J += i;
  }
  for ( int i = 0; i < M; i++ ) {
    K += i;
  }
  
  cout << J + K << endl;
    
}


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

typedef long long ll;
#define INF 1e9
using namespace std;

int n;
ll posicao[100099];
ll dp[100099];
ll pd (int pos)
{

if (dp[pos]!=-1){return dp[pos];}

if(pos == n){return 0;}

    int pula1=abs(posicao[pos]-posicao[pos+1])+pd(pos+1);
    int pula2=INF;
 if(pos<=n-2){
    pula2=abs(posicao[pos]-posicao[pos+2])+pd(pos+2);
 }

    return dp[pos]=min(pula1,pula2);




}




int main()
{

cin>>n;
for (int i=1;i<=n;i++){
    cin>>posicao[i];
}
memset(dp,-1,sizeof(dp));

cout << pd(1) << endl;



return 0
;}

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

int main() {
  int n;
  cin >> n;
  int a[n * 3];
  for (int i = 0; i < n * 3; i++) {
    cin >> a[i];
  }
  sort(a, a + n * 3, greater<int>());
  long long ans = 0;
  for (int i = 0; i < n; i++) {
    ans += a[1 + 2 * i];
  }
  cout << ans << endl;
}

Measured memory_bytes: 1408
#include<iostream>
using namespace std;
int main(){
    int a,b,c,d,n,x=0;
    while(cin >> n){
    for(a=0;a<10;a++){
        for(b=0;b<10;b++){
            for(c=0;c<10;c++){
                for(d=0;d<10;d++){
                    if(n==a+b+c+d)x=x+1;
                }
            }
        }
    }
    cout << x << endl;
    x=0;
    }
 return 0;
}

Measured memory_bytes: 1160
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace A
{
    public class Program

    {
        public static void Main(string[] args)
        {
            int[] n = RIntAr();
            n = n.OrderBy(x => x).ToArray();
            Console.WriteLine(n[0] * n[1] / 2);
        }

        static string RSt() { return Console.ReadLine(); }
        static int RInt() { return int.Parse(Console.ReadLine().Trim()); }
        static long RLong() { return long.Parse(Console.ReadLine().Trim()); }
        static double RDouble() { return double.Parse(Console.ReadLine()); }
        static string[] RStAr(char sep = ' ') { return Console.ReadLine().Trim().Split(sep); }
        static int[] RIntAr(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Trim().Split(sep), e => int.Parse(e)); }
        static long[] RLongAr(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Trim().Split(sep), e => long.Parse(e)); }
        static double[] RDoubleAr(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Trim().Split(sep), e => double.Parse(e)); }
        static string WAr<T>(IEnumerable<T> array, string sep = " ") { return string.Join(sep, array.Select(x => x.ToString()).ToArray()); }
    }

}


Measured memory_bytes: 13396
#include <iostream>
#include <cmath>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;

int main() {
    int sx,sy,tx,ty;
    cin >> sx >> sy >> tx >> ty;
    int a=tx-sx,b=ty-sy;
    string t="";

    for(int i=0;i<a;i++) t += 'R';
    for(int i=0;i<b;i++) t += 'U';
    for(int i=0;i<a;i++) t += 'L';
    for(int i=0;i<b;i++) t += 'D';
    t += 'D';
    for(int i=0;i<a+1;i++) t += 'R';
    for(int i=0;i<b+1;i++) t += 'U';
    t += "LU";
    for(int i=0;i<a+1;i++) t += 'L';
    for(int i=0;i<b+1;i++) t += 'D';
    t += 'R';

    cout << t << endl;

}

Measured memory_bytes: 256
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskA solver = new TaskA();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskA {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int a = in.nextInt();
            out.println(a / 3);
        }

    }
}



Measured memory_bytes: 22996
#include <iostream>
#include <vector>
#include <cstdlib>  
#include <algorithm>
#include <string>

using namespace std;
 
int main() {
   long long  L,R;
   cin >> L>>R;
   long long min = 2019;
   for(long long i = L;i<=R;i++){
     for(long long j = L;j<=R;j++){
  		if(i==j) continue;
        if((i*j)%2019== 0){
          cout<<0;
          return 0;
        }
        if(min >= (i*j)%2019) min = (i*j)%2019;     
     }   
   }
   cout<<min;
    return 0;
}

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

int main() {
  
  int A, B;
  cin >> A >> B;
  
  if (A == 1 && B == 2 || A == 2 && B == 1) {
    cout << 3 << endl;
  }
  else if (A == 1 && B == 3 || A == 3 && B == 1) {
    cout << 2 << endl;
  }
  else {
    cout << 1 << endl;
  }
}

Measured memory_bytes: 3616
#include <bits/stdc++.h>
using namespace std;
int main(){
  string s;cin>>s;
  short a;cin>>a;
  set<string>S;
  for(int i=0;i<s.size();i++)
    for(int j=i+1;j<min(i+a+1,int(s.size()+1));j++){
      string T=s.substr(i,j-i);
      S.insert(T);
    }
  vector<string>A(S.size());
  for(int i=0;i<A.size();i++){
    A[i]=*S.begin();
    S.erase(S.begin());
  }
  sort(A.begin(),A.end());
  cout<<A[a-1]<<endl;
}

Measured memory_bytes: 4812
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0;i < (n);i++)
using ll = long long;
const ll MOD=1000000007;
const long long INF = 1LL << 60;
const double pi=acos(-1);

string S;

//dp
vector<ll> table;

ll dp(ll n){
  //cout<<"d"<<" "<<n<<endl;
  if(S.at(n)=='R'&&S.at(n+1)=='L') return n;
  if(S.at(n)=='L'&&S.at(n-1)=='R') return n;
  if(table.at(n)>-1) return table.at(n);
  
  if(S.at(n)=='R'){
    if(S.at(dp(n+1))=='R') table.at(n)=dp(n+1)+1;
    else table.at(n)=dp(n+1)-1;
  }
  else{
    if(S.at(dp(n-1))=='R') table.at(n)=dp(n-1)+1;
    else table.at(n)=dp(n-1)-1;
  }
  
  return table.at(n);
}


  
int main() 
{
  cin>>S;
  ll N=S.size();
  
  //dp
  table=vector<ll>(N,-1);

  /*
  rep(i,N){
    if(i!=0) cout<<" ";
    cout<<dp(i);
  }
  */
  vector<ll> vec(N,0);
  rep(i,N) vec.at(dp(i))++;
  
  rep(i,N){
    if(i!=0) cout<<" ";
    cout<<vec.at(i);
  }
  cout<<endl;

  return 0;
}

Measured memory_bytes: 8184
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define For(i,n,k) for(int i=(n);i<(k);i++)
#define ALL(a)  (a).begin(),(a).end()
ll ans=0;
ll calc(ll a,ll b,ll x){
    return a*x/b-x/b*a;
}
void Main(){
    ll a;cin>>a;
    ll b;cin>>b;
    ll n;cin>>n;
    for(ll i=min(b,n);i>0;i--) {
        ll t=calc(a,b,i);
        if(t>ans) ans=t;
        else if(t<ans) break;
    }
    cout<<ans<<endl;
}
int main(){
    Main();
    /*
    東方風神録は神が出てくるので当然神ゲー
    */
    return 0;
}

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

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

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

const int mod = 1000000007;
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
  mint operator+(const mint a) const { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const { return pow(mod-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}

struct combination {
  vector<mint> fact, ifact;
  combination(int n):fact(n+1),ifact(n+1) {
    assert(n < mod);
    fact[0] = 1;
    for (int i = 1; i <= n; ++i) fact[i] = fact[i-1]*i;
    ifact[n] = fact[n].inv();
    for (int i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i;
  }
  mint operator()(int n, int k) {
    if (k < 0 || k > n) return 0;
    return fact[n]*ifact[k]*ifact[n-k];
  }
};
struct permutation {
  vector<mint> fact, ifact;
  permutation(int n):fact(n+1),ifact(n+1) {
    assert(n < mod);
    fact[0] = 1;
    for (int i = 1; i <= n; ++i) fact[i] = fact[i-1]*i;
    ifact[n] = fact[n].inv();
    for (int i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i;
  }
  mint operator()(int n, int k) {
    if (k < 0 || k > n) return 0;
    return fact[n]*ifact[n-k];
  }
};
const int INF = 1001001001;

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

  combination cmb(n+1);
  permutation pmt(max(n,m)+1);

  mint ans;
  rep(i,n+1) {
    if (i % 2 == 0)
      ans += cmb(n,i) * pmt(m,i) * pmt(m-i, n-i) * pmt(m-i, n-i);
    else
      ans -= cmb(n,i) * pmt(m,i) * pmt(m-i, n-i) * pmt(m-i, n-i);
  }

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 18724
import itertools
import math
import sys

d, g = [int(x) for x in input()[:-2].split()]
pc = [[int(x) for x in input()[:-2].split()] for _ in range(d)]

def search(choice):
    total = sum(((i + 1) * p + c) * chosen for i, ((p, c), chosen) in enumerate(zip(pc, choice)))
    count = sum(p * chosen for (p, _), chosen in zip(pc, choice))

    if total < g:
        partial = d - list(reversed(choice)).index(0)
        partial_count = math.ceil((g - total) / partial)
        if partial_count <= pc[partial - 1][0]:
            count += partial_count
        else:
            count = sys.maxsize

    return count

print(min(search(choice) for choice in itertools.product(*([0, 1] for _ in range(d)))))


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) FOR(i, 0, (n))
#define FOR(i, a, b) for(int i=(a); i<(b); i++)
#define LAR(a, b) ((a)=max((a),(b)))
#define SML(a, b) ((a)=min((a),(b)))
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vl = vector<ll>;
using pii = pair<int, int>;
using vpii = vector<pair<int, int>>;
template<typename T>
using pque = priority_queue<T, vector<T>, greater<T>>;
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define ALL(a) (a).begin(), (a).end()
#ifdef LOCAL_DEBUG
#define DEBUG(...) printf(__VA_ARGS__)
#else
#define DEBUG(...)
#endif

map<string, int> mp;

int main(){
	int n; cin >> n;
	REP(i, n){
		string s; cin >> s;
		mp[s]++;
	}
	int mx = 0;
	for(auto &p : mp) LAR(mx, p.second);
	for(auto &p : mp) if(p.second == mx) cout << p.first << endl;
}


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

int main() {
  int A, B;
  cin >> A >> B;
  int sum = 0;
  for (int i = A; i <= B; i++){
    int a, b, c, d, e;
    a = i % 10;
    b = (i - a) / 10 % 10;
    c = (i - a - 10 * b) / 100 % 10;
    d = (i - a - 10 * b - 100 * c) / 1000 % 10;
    e = (i - a - 10 * b - 100 * c - 1000 * d) /10000;
    if (a == e && b == d){
      sum = sum + 1;
    }
  }
  cout << sum << endl;
}



Measured memory_bytes: 3616
import java.util.Arrays;
import java.util.Comparator;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

	    // 引数で標準入力System.inを指定する
	    Scanner scanner = new Scanner(System.in);
		try {

		    // 1行目を取得(a)
//		    int input_text１ = scanner.nextInt();
			String line = scanner.nextLine();
			int input_text１ = Integer.parseInt(line);

			line = scanner.nextLine();
			String[] input_text2Array = line.split(" ");

			Integer[] arr = new Integer[input_text2Array.length];

			for (int i = 0; i < input_text2Array.length; i++) {
				arr[i] = Integer.parseInt(input_text2Array[i]);
			}

//			Arrays.parallelSort(arr);
//
//			long answer = 0;
//			for (int i =  arr.length - 1; i > 0; i--) {
//				answer = answer + arr[i];
//			}

			Arrays.sort(arr, Comparator.reverseOrder());

			long answer = 0;
			for (int i = 1; i < arr.length; i++) {
				answer = answer + arr[i / 2];
			}

			System.out.printf("%d", answer);

		} finally {
		    // Scannerクラスのインスタンスをクローズ
		    scanner.close();
		}
	}
}

Measured memory_bytes: 83100
#include <bits/stdc++.h>
using namespace std;
int main()
{
    long long int i,n,j,l,t,r,d,ans=0,arr[1000000];
    string s;
    cin>>d>>n;
    for(i=0;i<n;i++)
        cin>>arr[i];
    ans=0;
    for(i=1;i<n;i++)
    {
        if(ans<arr[i]-arr[i-1])
            ans=arr[i]-arr[i-1];
    }
    // cout<<ans;
    ans=max(ans,arr[0]+d-arr[n-1]);
    
    ans=d-ans;
    cout<<ans;
}

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

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

    size_t ans = to_string(n).length();
    for (ll a = 1; a * a <= n; a++) {
        if (n % a != 0) continue;
        ans = min(ans, max(to_string(a).length(), to_string(n / a).length()));
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3672
#include <iostream>
#include <sstream>
#include <fstream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <utility>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <cstdio>

using namespace std;

const long long INF = 100000000;
const long long MOD = 1000000007;

std::vector<bool> IsPrime;

void sieve(size_t max)
{
  if (max + 1 > IsPrime.size())
  {                                // resizeで要素数が減らないように
    IsPrime.resize(max + 1, true); // IsPrimeに必要な要素数を確保
  }
  IsPrime[0] = false; // 0は素数ではない
  IsPrime[1] = false; // 1は素数ではない

  for (size_t i = 2; i * i <= max; ++i)     // 0からsqrt(max)まで調べる
    if (IsPrime[i])                         // iが素数ならば
      for (size_t j = 2; i * j <= max; ++j) // (max以下の)iの倍数は
        IsPrime[i * j] = false;             // 素数ではない
}

class Pointer{
public:
  long long p;
  long long w;
};

int main()
{
  string s;
  cin >> s;
  long long ans = 0;
  for (long long i = 1; i * 2 < s.length(); i++)
  {
    string s1 = s.substr(0, i);
    string s2 = s.substr(i, i);
    //cout << "iの時" << s1 << " " << s2 << endl;
    if(s1==s2)
      ans = max(ans, i * 2);
  }
  cout << ans << endl;
}


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


#include "boost/multiprecision/cpp_int.hpp"
#include "boost/multiprecision/cpp_dec_float.hpp"
namespace mp = boost::multiprecision;
typedef mp::cpp_int LL;
typedef mp::number<mp::cpp_dec_float<1024>> DD;// 仮数部が1024ビットの浮動小数点数型(TLEしたら小さくする)

 
typedef long double dd;
#define i_7 (ll)(1E9+7)
//#define i_7 998244353
#define i_5 i_7-2
ll mod(ll a){
    ll c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
typedef pair<ll,ll> l_l;
typedef pair<dd,dd> d_d;
ll inf=(ll)1E16;
#define rep(i,l,r) for(ll i=l;i<=r;i++)
#define rrep(i,r,l) for(ll i=r;i>=l;i--)
#define pb push_back
ll max(ll a,ll b){if(a<b)return b;else return a;}
ll min(ll a,ll b){if(a>b)return b;else return a;}
void Max(ll &pos,ll val){pos=max(pos,val);}//Max(dp[n],dp[n-1]);
void Min(ll &pos,ll val){pos=min(pos,val);}
void Add(ll &pos,ll val){pos=mod(pos+val);}
dd EPS=1E-9;
#define fastio ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define fi first
#define se second
#define endl "\n"  //インタラクティブで消す！！！！！！！！！！！！！！！！！！！！！
#define SORT(v) sort(v.begin(),v.end())
#define ERASE(v) v.erase(unique(v.begin(),v.end()),v.end())
#define POSL(v,x) (lower_bound(v.begin(),v.end(),x)-v.begin())
#define POSU(v,x) (upper_bound(v.begin(),v.end(),x)-v.begin())
template<class T,class S>
inline bool chmax(T &a, S b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}
template<class T,class S>
inline bool chmin(T &a, S b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
}

void mod_print(ll k){
    ll P=1000;
    rep(y,1,P){
        ll x=mod(y*k);
        if(x+P>=i_7){
            x-=i_7;
        }
        if(abs(x)<=P){
            //cout<<x<<"/"<<y;
            cout<<setprecision(5)<<(dd)x/(dd)y;
            return;
        }
    }
    cout<<"nun"<<endl;
}
#define all(c) c.begin(),c.end()
//////////////////////////

int main(){fastio
    ll n;cin>>n;
    n%=1000;
    if(n==0)n=1000;
    cout<<1000-n<<endl;
    
    return 0;
}


Measured memory_bytes: 3652
#include <iostream>
#include <cmath>
#include <vector>
#include <climits>
using namespace std;
int main()
{
    int n;
    cin >> n;
    vector<int> v;
    for(int i = 0;i < n;i++)
    {
        int t;
        cin >> t;
        v.push_back(t);
    }
    bool f = true;
    int c = 0;
    while(f)
    {
        f = false;
        for(int i = 1;i < v.size();i++)
        {
            if(v.at(i) < v.at(i - 1))
            {
                int t = v.at(i - 1);
                v.at(i -1) = v.at(i);
                v.at(i) = t;
                f = true;
                c++;
            }
        }
    }
    for(int i = 0;i < v.size();i++)
    {
        cout << v.at(i);
        if(i + 1 != v.size())
        {
            cout << " ";
        }
        else
        {
            cout << endl;
        }
    }
    cout << c << endl;
}

Measured memory_bytes: 1220
#include <iostream>
#include <string>
#include <cstring>
#include <fstream>
#include <cmath>
#include <iomanip>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <map>
#include <deque>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <list>
#include <unordered_map>
#include <bitset>
#include <sstream>

typedef  long long ll;
#define mop 1000000007
using namespace std;

int main() {
//    ifstream in("input.txt");
//    cin.rdbuf(in.rdbuf());

    ll x,y;
    cin >> x >> y;
    if(abs(x-y) <= 1){
        cout << "Brown" << endl;
    }else{
        cout << "Alice" << endl;
    }

}




Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cctype>
using namespace std;
int main()
{
	string s;
	int a,b;
	cin>>a>>b;
	cin>>s;
	for(int i=0;i<s.size();i++)
	{
		if(i==a)
		{
			if(s[i]!='-')
			{
				cout<<"No"<<endl;
				return 0;
			}
		}
		else if(!isdigit(s[i]))
		{
			cout<<"No"<<endl;
			return 0;
		}
		
	}
	cout<<"Yes"<<endl;
	return 0;
		
} 

Measured memory_bytes: 256
A, B, M = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
ans = min(a) + min(b)
for _ in range(M):
    x, y, c = map(int, input().split())
    temp = a[x-1] + b[y-1] - c
    if ans > temp:
        ans = temp
print(ans)

Measured memory_bytes: 18612
n, m = map(int, input().split())
ab = []
cnt = 0
ind = 0
for _ in range(n):
    aa = list(map(int, input().split()))
    ab.append(aa)
ab.sort(key=lambda x: x[0])
# print(ab)

for i in range(m):
    if ab[ind][1] > 0:
        cnt += ab[ind][0]
        ab[ind][1] -= 1
    else:
        ind += 1
        cnt += ab[ind][0]
        ab[ind][1] -= 1
print(cnt)

Measured memory_bytes: 29024
#include <cstdlib>
#include <climits>
#include <iostream>
#include <cstdint>
#include <vector>
#include <string>
#include <complex>
#include <bitset>
#include <queue>
#include <deque>
#include <stack>
#include <utility>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>

#include <boost/lexical_cast.hpp>
#include <boost/algorithm/string/predicate.hpp>
#include <boost/multi_array.hpp>

using namespace std;


int main()
{
    int N;

    std::cin >> N;

    using Point = std::pair<int, int>;

    std::vector<Point> R;
    for (size_t i = 0; i < N; ++i) {
        int a, b;
        std::cin >> a >> b;
        R.push_back({a, b});
    }

    std::vector<Point> B;
    for (size_t i = 0; i < N; ++i) {
        int c, d;
        std::cin >> c >> d;
        B.push_back({c, d});
    }

    // y軸で降順にソート
    std::sort(std::begin(R), std::end(R),
              [](const auto& a, const auto& b) {
                  return a.second > b.second;
              });

    // x軸で昇順にソート
    std::sort(std::begin(B), std::end(B),
              [](const auto& a, const auto& b) {
                  return a.first < b.first;
              });

    int count = 0;
    for (auto&& b: B) {
        // bのx軸的相方候補検索
        std::vector<std::vector<Point>::iterator> candItrs;
        for (auto redItr = R.begin(); redItr != R.end(); ++redItr) {
            if (redItr->first < b.first) {
               candItrs.push_back(redItr);
            }
        }
        /*
          そのなかからy軸的にマッチしていて、一番大きいものを探す
          Rはy軸降順にソートされているので、candsもy軸降順になっている
          最初に見つかった範囲内が相方
        */
        for (auto&& candItrsItr = candItrs.begin(); candItrsItr != candItrs.end(); ++candItrsItr) {
            if ((*candItrsItr)->second < b.second) {
                count++;
                R.erase(*candItrsItr);
                break;
            }
        }
    }

    std::cout << count << std::endl;

    return 0;
}


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

int checkTime(int currentTime, int currentStat, vector<int>& cv, vector<int>& sv, vector<int>& fv) {
	if (currentTime < sv[currentStat]) {
		currentTime = sv[currentStat];
	}

	int temp = (currentTime - sv[currentStat]) % fv[currentStat];
	if (temp != 0) {
		currentTime += fv[currentStat] - temp;
	}

	currentTime += cv[currentStat];
	return currentTime;
}

int main() {
	int n;
	cin >> n;
	vector<int> cv(n - 1);
	vector<int> sv(n - 1);
	vector<int> fv(n - 1);

	for (int i = 0; i < n - 1; ++i) {
		cin >> cv[i] >> sv[i] >> fv[i];
	}

	vector<int> ret(n, 0);
	for (int i = 0; i < n - 1; ++i) {
		for (int j = i; j < n - 1; ++j) {
			ret[i] = checkTime(ret[i], j, cv, sv, fv);
		}
	}

	for (auto& i : ret) {
		cout << i << endl;
	}

	return 0;
}

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

//--------------------------------------------
#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(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define LL long long
#define INF INT_MAX/3

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

//--------------------------------------------

int main(){
  int n;
  int a;

  scanf("%d",&n);

  int b[n];
  REP (i, n) {
    scanf("%d",&a);
    if (i % 2 == 0) b[(n + i) / 2] = a;
    else b[(n - i - 1) / 2] = a;
  }

  if (n % 2 == 0) {
    REP(i, n) {
      printf("%d",b[i]);
      i < (n - 1) ? printf(" ") : printf("\n");
    }
  } else {
    RREP(i, n) {
      printf("%d",b[i]);
      i > 0 ? printf(" ") : printf("\n");
    }
  }

}


Measured memory_bytes: 2944
#include <bits/stdc++.h>
#define ll long long
using namespace std;
 
ll gcd(ll a, ll b){
  if(b == 0){
    return a;
  }
  else{
    return gcd(b,(a%b));
  }
}
ll lcm(ll a,ll b){
  return a/gcd(a,b)*b;
}
 
int main(){
  int a,b;
  cin>>a>>b;
  cout<<(max(0,10-a))*100+b<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
vector<pair<pair<string,int>,int> >v;
int main()
{
	int n;
	cin>>n;
	for(int i=0;i<n;i++)
	{
		int x;
		string s;
		cin>>s>>x;
		v.push_back(make_pair(make_pair(s,-x),i+1));
	}
	sort(v.begin(),v.end());
	for(int i=0;i<v.size();i++)
	{
		cout<<v[i].second<<endl;
	}
	return 0;
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline


arph = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
d = {s: i for i, s in enumerate(arph)}

_n = int(input())
_s = input()[:-1]


def idx(s, n):
    rs = ''
    for si in s:
        i = d[si]
        i = (i + n) % 26
        si = arph[i]
        rs = rs + si

    print(rs)


idx(_s, _n)


Measured memory_bytes: 3060
n = int(input())
a = list(map(int,input().split()))
q = int(input())
m = list(map(int,input().split()))

def solve(i, m_i):
    if m_i == 0:
        return True
    if i >= n:
        return False
    res = solve(i + 1, m_i) or solve(i + 1, m_i - a[i])
    return res

for m_tmp in m:
    if sum(a) < m_tmp:
        print("no")
    elif solve(0, m_tmp):
        print("yes")
    else:
        print("no")

Measured memory_bytes: 7780
import java.util.*;
import java.io.*;
public class Main
{
    public static void main(String []args) throws IOException {
    	FastScanner in  = new FastScanner(System.in);
    	PrintWriter out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)), false);
    	solve(in, out);
    	in.close();
    	out.close();
    }
    static long gcd(long a, long b){ return (b==0) ? a : gcd(b, a%b); }
    static int gcd(int a, int b){ return (b==0) ? a : gcd(b, a%b); }
    private static int fact(int n) { int ans=1; for(int i=2;i<=n;i++) ans*=i; return ans; }
    static class FastScanner{
	BufferedReader reader;
	StringTokenizer st;
	FastScanner(InputStream stream){reader=new BufferedReader(new InputStreamReader(stream));st=null;}
	String next(){while(st == null || !st.hasMoreTokens()){try{String line = reader.readLine();if(line == null){return null;}
	     st = new StringTokenizer(line);}catch (Exception e){throw new RuntimeException();}}return st.nextToken();}
	String nextLine()  {String s=null;try{s=reader.readLine();}catch(IOException e){e.printStackTrace();}return s;}
	int    nextInt()   {return Integer.parseInt(next());}
	long   nextLong()  {return Long.parseLong(next());}
	double nextDouble(){return Double.parseDouble(next());}
	char   nextChar()  {return next().charAt(0);}
	int[]  nextIntArray(int n)         {int[] arr= new int[n];   int i=0;while(i<n){arr[i++]=nextInt();}  return arr;}
	long[] nextLongArray(int n)        {long[]arr= new long[n];  int i=0;while(i<n){arr[i++]=nextLong();} return arr;}
	int[]  nextIntArrayOneBased(int n) {int[] arr= new int[n+1]; int i=1;while(i<=n){arr[i++]=nextInt();} return arr;}
	long[] nextLongArrayOneBased(int n){long[]arr= new long[n+1];int i=1;while(i<=n){arr[i++]=nextLong();}return arr;}
	void   close(){try{reader.close();}catch(IOException e){e.printStackTrace();}}
    }
    
    /********* SOLUTION STARTS HERE ************/
    
    private static void solve(FastScanner in, PrintWriter out){
        long INF = (long)1e16;
        int n = in.nextInt();
        int k = in.nextInt();
        int a[] = new int[n];
        for(int i=0;i<n;i++){
            a[i] = in.nextInt();
        }
        long cost[] = new long[n];
        Arrays.fill(cost,INF);
        cost[0]=0;
        for(int i=1;i<n;i++){
            for(int j=i-1;j>=Math.max(0,i-k);--j){
                cost[i] = Math.min(cost[i],cost[j]+Math.abs(a[i]-a[j]));
            }
        }
        out.println(cost[n-1]);
        
    }
    
    /************* SOLUTION ENDS HERE **********/
}

Measured memory_bytes: 35748
#C問題
N = int(input())
A = list(map(int,input().split()))
B = list(map(int,input().split()))

ans = 0
div = 0
flag = 1
while flag == 1:
    flag = 0
    for i in range(N):
        if B[i]-B[i-1]-B[(i+1)%N] >= A[i]:
            div = (B[i]-A[i])//(B[i-1]+B[(i+1)%N])
            B[i] -= (B[i-1]+B[(i+1)%N])*div
            ans+=div
            flag = 1
            
print(ans if A == B else -1)

Measured memory_bytes: 118904
using System;
using System.IO;
using System.Linq;
using System.Collections.Generic;
using System.Text;
using System.Numerics;

namespace abc160
{
    class Program
    {
        static void Main(string[] args)
        {
            if (File.Exists("input.txt"))
            {
                Console.SetIn(new StreamReader("input.txt"));
            }
			solve_abc160B();
        }

        public static void solve_abc160B()
        {
            int x = Convert.ToInt32(Console.ReadLine());
            int a = x / 500;
            int r = x % 500;
            int b = r / 5;
            Console.WriteLine(a * 1000 + b * 5);
        }

        public static void solve_abc160A()
        {
            string s = Console.ReadLine();
            Console.WriteLine(s[2] == s[3] && s[4] == s[5] ? "Yes" : "No");
        }
    }
}


Measured memory_bytes: 13268
import java.io.*;
import java.util.*;
class Main{
	static final long MOD = 1_000_000_007; // 10^9+7
    static final int MAX = 2_147_483_646; // intMax 
    static final int INF = 1_000_000_000; // 10^9  
    public static void main(String[] args) throws Exception {
		hayami saori = new hayami();
		int[] n = new int[]{1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
		int k = saori.saori_hayami() - 1;
		System.out.println(n[k]);
		saori.close();
    }
}

class hayami implements Closeable {
	private final InputStream in = System.in;
	private final byte[] hayami = new byte[1024];
	private int Hayami = 0;
	private int saori = 0;
	private boolean HayamiSaori() {
		if (Hayami < saori) {
			return true;
		}else{
			Hayami = 0;
			try {
				saori = in.read(hayami);
			} catch (IOException e) {
				e.printStackTrace();
			}
			if (saori <= 0) {
				return false;
			}
		}
		return true;
	}
	private int SaoriHayami() { 
		if (HayamiSaori()) {
            return hayami[Hayami++];
         }else{
             return -1;
         }
	}
	private static boolean hayami_saori(int hayami) { 
		return 33 <= hayami && hayami <= 126;
	}
	public boolean hayamisaori() { 
		while(HayamiSaori() && !hayami_saori(hayami[Hayami])) Hayami++; return HayamiSaori();
	}
	public String nextHayami() {
		if (!hayamisaori()) throw new NoSuchElementException();
		StringBuilder hayamin = new StringBuilder();
		int saori = SaoriHayami();
		while(hayami_saori(saori)) {
			hayamin.appendCodePoint(saori);
			saori = SaoriHayami();
		}
		return hayamin.toString();
	}
	public long saorihayami() {//nextLong
		if (!hayamisaori()) throw new NoSuchElementException();
		long hayami = 0;
		boolean misao = false;
		int saori = SaoriHayami();
		if (saori == '-') {
			misao = true;
			saori = SaoriHayami();
		}
		if (saori < '0' || '9' < saori) {
			throw new NumberFormatException();
		}
		while(true){
			if ('0' <= saori && saori <= '9') {
				hayami *= 10;
				hayami += saori - '0';
			}else if(saori == -1 || !hayami_saori(saori)){
				return misao ? -hayami : hayami;
			}else{
				throw new NumberFormatException();
			}
			saori = SaoriHayami();
		}
	}
	public int saori_hayami() {//nextInt
		long hayami = saorihayami();
		if (hayami < Integer.MIN_VALUE || hayami > Integer.MAX_VALUE) throw new NumberFormatException();
		return (int) hayami;
	}
	public double Hayamin() { //nextDouble
		return Double.parseDouble(nextHayami());
	}
	public void close() {
		try {
			in.close();
		} catch (IOException e) {
		}
    }
    
}

Measured memory_bytes: 21844
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc=new Scanner(System.in);
    int a=sc.nextInt();
    int b=sc.nextInt();
    while(true){
	if(b>a){
	    int tmp=b;
	    b=a;
	    a=tmp;
	}
	if(a%b==0){
	    System.out.println(b);
	    break;
	}
	else{
	    a=a%b;
	}
    }
  }
}



Measured memory_bytes: 26408
#include <bits/stdc++.h>
#define MOD 1000000007
#define pb push_back
#define ll long long
using namespace std;
const int nmax=212345;

int a[nmax],b[nmax],c[nmax],dp[nmax][3];


int main()
{
    int n;
    scanf("%d",&n);
    for(int i=1;i<=n;++i){
        scanf("%d %d %d",&a[i],&b[i],&c[i]);
    }
     for(int i=1;i<=n;++i){
        dp[i][0]=max(dp[i-1][1],dp[i-1][2])+a[i];
        dp[i][1]=max(dp[i-1][0],dp[i-1][2])+b[i];
        dp[i][2]=max(dp[i-1][1],dp[i-1][0])+c[i];
    }
    printf("%d",max(dp[n][0],max(dp[n][1],dp[n][2])));
    return 0;
}


Measured memory_bytes: 3840
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;
import java.util.Scanner;
import java.util.ArrayDeque;
import java.util.Deque;

public class Main {
    public static void main(String[] args) throws Exception {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    	StringBuilder ans = new StringBuilder();

        int n = Integer.parseInt(br.readLine());
     	Deque<String> doubly_linked_list = new ArrayDeque<String>();
        for (int i = 0; i < n; i++) {
            String[] line = br.readLine().split(" ");
            if (line[0].equals("insert")) {
                doubly_linked_list.addFirst(line[1]);
            } else if (line[0].equals("delete")) {
                doubly_linked_list.remove(line[1]);
            } else if (line[0].equals("deleteFirst")) {
                doubly_linked_list.removeFirst();
            } else if (line[0].equals("deleteLast")) {
                doubly_linked_list.removeLast();
            }
        }
		if(!doubly_linked_list.isEmpty()){
			ans.append(doubly_linked_list.getFirst());
			doubly_linked_list.removeFirst();
		}
		
		while(!doubly_linked_list.isEmpty()){
			ans.append(" ").append(doubly_linked_list.getFirst());
			doubly_linked_list.removeFirst();
		}
        System.out.println(ans.toString());
    }
}


Measured memory_bytes: 228084