akhauriyash/Code-Regression huggingface dataset:
#include "bits/stdc++.h"
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define all(s) s.begin(), s.end()
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
const int MX = 100005, INF = 1001001001;
const ll LINF = 1e18;
const double eps = 1e-10;
const ll mod = 1e9+7;

int n,k;
vi d;

int main()
{
    cin >> n >> k;
    d.resize(k); rep(i,k) cin >> d[i];
    vi suki;

    int val = n;
    bool fl;
    while(1){
        fl = true;
        int tmp = val;
        while(tmp != 0){
            if(find(all(d), tmp%10) != d.end()) fl = false;
            tmp /= 10;
        }
        if(fl){
            cout << val << endl;
            return 0;
        }
        val++;
    }
}



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

int main() {
	ios_base :: sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	long long n, a[5];
	cin>>n>>a[0]>>a[1]>>a[2]>>a[3]>>a[4];
	int idx = min_element(a,a+5)-a;
	long long m = a[idx];
	long long ans = (n+a[idx]-1)/a[idx]+4;
	cout<<ans;
	return 0;
}

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

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    cin >> N;
    vector<ll> A(N);
    ll all_xor = 0;
    vector<ll> diff(N);
    for (int i = 0; i < N; ++i) {
        cin >> A[i];
        all_xor ^= A[i];
        diff[i] = A[i] ^ (A[i] - 1);
    }
    int ans = 0;
    for (int i = 32; i >= 0; --i) {
        if (all_xor & (1LL << i)) {
            for (int j = 0; j < N; ++j) {
                if (diff[j] + 1 == (1LL << (i + 1))) {
                    all_xor ^= diff[j];
                    ans++;
                    break;
                }
            }
        }
    }
    if (all_xor == 0) cout << ans << endl;
    else cout << -1 << endl;
    return 0;
}

Measured memory_bytes: 1792
#include <stdio.h>

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

int main(void)
{
	float a, b, c, d, e, f;
	float x, y;

	while ((scanf("%f %f %f %f %f %f", &a, &b, &c, &d, &e, &f)) != EOF){
		y = (c * d - a * f) / (b * d - a * e);
		if (a != 0){
			x = (c - b * y) / a;
		} else {
			x = (f - e * y) / d;
		}

		printf("%.3f %.3f\n", x, y);
	}

	return 0;
}


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

int main()
{
	char x, y; cin >> x >> y;
	
	char ans;
	
	if (x == y) ans = '=';
	else if (x < y) ans = '<';
	else ans = '>';
	
	cout << ans << endl;
	
	return 0;
		
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

     static Scanner scanner;

     public static void main(String[] args) {
         scanner = new Scanner(System.in);

         int N=gi();
         long[] a=new long[N];
         long minabs=Long.MAX_VALUE;
         long max=0;
         long mc=0;
         for(int i=0; i<N;i++) {
        	 a[i]=gi();
        	 if(a[i]<0)mc++;
        	 long abs=Math.abs(a[i]);
        	 minabs=Math.min(abs, minabs);
        	 max+=abs;
         }

         if(mc%2==0) {
        	 System.out.print(max);
         } else {
        	 System.out.print(max-minabs*2);
         }

         //System.out.print(a^b);



         //System.out.print(sb);
     }

     public static long f(long n) {
    	 if(n<=0)return 0;
    	 if(n==1)return 1;
    	 if(n==2)return 3;
    	 if(n==3)return 0;
    	 int i=2;
    	 while(i<=n) {
    		 i=i*2;
    	 }
    	 i=i/2;

    	 long ret=0;
    	 if((n-i)%2==0) {
    		 ret+=i;
    	 }
    	 ret= ret + f(n-i);
    	 return ret;
     }

     // 文字列として入力を取得
     public static String gs() {
          return scanner.next();
     }

     // intとして入力を取得
     public static int gi() {
          return Integer.parseInt(scanner.next());
     }

     // longとして入力を取得
     public static long gl() {
          return Long.parseLong(scanner.next());
     }

     // doubleとして入力を取得
     public static double gd() {
          return Double.parseDouble(scanner.next());
     }
}

Measured memory_bytes: 60852
#include<iostream>
#include<set>
#include <bitset>
#include<queue>
#include<vector>
#include<map>
#include<stack>
#include <cstdio>
#include<algorithm>
#include <sstream>
#include<string>
#include<string.h>
#include <cmath>
#include <iomanip>
#include <string>
#include<list>
#include <limits>
#include <numeric>
#include <type_traits>
#define int long long
#define ll long long
#define mod  1000000007
#define inf 1e17
#define rep(i,j,n) for(int i=j;i<n;i++)
#define P pair<int,int>
double pi = 3.141592653589793;
using namespace std;
//ここから始めよう
signed main(){
    int n,c;cin>>n>>c;
    int x[114514],v[114514];
    int l[114514];int r[114514];
    l[0]=0,r[n]=0;
    rep(i,0,n){
        cin>>x[i]>>v[i];
    }
    int point=0;
    rep(i,1,n+1){
        point+=v[i-1];
        l[i]=point-x[i-1];
    }
    rep(i,1,n+1){
        l[i]=max(l[i-1],l[i]);
    }
    point=0;
    for(int i=n-1;i>=0;i--){
        point+=v[i];
        r[i]=point-c+x[i];
    }
    for(int i=n-1;i>=0;i--){
        r[i]=max(r[i+1],r[i]);
    }int ans=max(l[n],r[0]);
    for(int i=n;i>=0;i--){
        if(i==0){
            x[i]=0,v[i]=0;
        }
        else {
            x[i]=x[i-1]; v[i]=v[i-1];
        }
    }
    rep(i,0,n){
        ans=max(ans,l[i]+r[i]-min(x[i],c-x[i+1]));
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 3712
#include<bits/stdc++.h>
#define rep(i,a,...) for(int i = (a)*(strlen(#__VA_ARGS__)!=0);i<(int)(strlen(#__VA_ARGS__)?__VA_ARGS__:(a));++i)
#define per(i,a,...) for(int i = (strlen(#__VA_ARGS__)?__VA_ARGS__:(a))-1;i>=(int)(strlen(#__VA_ARGS__)?(a):0);--i)
#define foreach(i, n) for(auto &i:(n))
#define pii pair<int, int>
#define pll pair<long long, long long>
#define all(x) (x).begin(), (x).end()
#define bit(x) (1ll << (x))
using ll = long long;
//const ll MOD = (ll)1e9+7;
const ll MOD = 998244353;
const int INF = (ll)1e9+7;
const ll INFLL = (ll)1e18;
using namespace std;
template<class t>
using vvector = vector<vector<t>>;
template<class t>
using vvvector = vector<vector<vector<t>>>;
template<class t>
using priority_queuer = priority_queue<t, vector<t>, greater<t>>;
template<class t, class u> bool chmax(t &a, u b){if(a<b){a=b;return true;}return false;}
template<class t, class u> bool chmin(t &a, u b){if(a>b){a=b;return true;}return false;}
#ifdef DEBUG
#define debug(x) cout<<"LINE "<<__LINE__<<": "<<#x<<" = "<<x<<endl;
#else
#define debug(x) (void)0
#endif

ll modpow(ll x, ll b){
  ll res = 1;
  while(b){
    if(b&1)res = res * x % MOD;
    x = x * x % MOD;
    b>>=1;
  }
  return res;
}

ll modinv(ll x){
  return modpow(x, MOD-2);
}

bool was_output = false;
template<class t>
void output(t a){
  if(was_output)cout << " ";
  cout << a;
  was_output = true;
}
void outendl(){
  was_output = false;
  cout << endl;
}
ll in(){
  ll res;
  scanf("%lld", &res);
  return res;
}

template<class t>
istream& operator>>(istream&is, vector<t>&x){
  for(auto &i:x)is >> i;
  return is;
}

template<class t, class u>
istream& operator>>(istream&is, pair<t, u>&x){
  is >> x.first >> x.second;
  return is;
}

template<class t>
void in(t&x){
  cin >> x;
}

int n;
vector<int> win;
vector<int> player;

void setup(){
  n = in();
  win.resize(bit(n)-1);
  player.resize(bit(n));
  foreach(i,win){
    char d;
    in(d);
    i = d-'0';
  }
  foreach(i,player){
    i = in();
  }
}

int winner(int a,int b){
  if(a>b)swap(a,b);
  return win[b-a-1]?b:a;
}

int func(int place,int k){
  static vvector<int> dp(bit(n),vector<int>(n+1,-1));
  if(k==1){
    return winner(player[place],player[(place+1)%bit(n)]);
  }
  int &it = dp[place][k];
  if(it>=0)return it;
  return it = winner(func(place,k-1),
                     func((place+bit(k-1))%bit(n),k-1));
}

int main(){
  setup();

  rep(i,bit(n)){
    cout << func(i,n) << endl;
  }
  return 0;
}



Measured memory_bytes: 35684
//ABC078B
#include <bits/stdc++.h>
#include <iostream>
#include <iomanip>
#include <numeric>
#include <math.h>
#include <stdio.h>
#include <climits>
#include <cfloat>
#include <string>
using namespace std;

int main(){
	int x, y, z;
	cin >> x >> y >> z;
	cout << (x-2*z-y)/(y+z)+1 << endl;
	return 0;
}

Measured memory_bytes: 256
<?php
list($n) = ints();
$a = ints();
sort($a);
$ok = 0;
$sum = 0;
for ($i = 0; $i < $n - 1; ++$i) {
    $sum += $a[$i];
    if ($sum * 2 < $a[$i + 1]) $ok = $i + 1;
}
echo $n - $ok;
function ints()
{
    return array_map('intval', explode(' ', trim(fgets(STDIN))));
}


Measured memory_bytes: 27264
<?php
   fscanf(STDIN, "%d", $n);
     $ans=1;
   $arr = array_map('intval', explode(' ', trim(fgets(STDIN))));
   if (in_array('0', $arr)){
     $ans= 0;
   }else{
     for($i=0;$i<$n;++$i){
      $ans=bcmul($ans,$arr[$i]);
      if($ans>1000000000000000000){
        $ans= -1;
        break;
       }
     }
    }
   echo $ans;
?>

Measured memory_bytes: 28684
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <string>
#include <vector>
#include <math.h>
#include <queue>
#include <deque>
#include <map>
const int MOD = 1e9+7;
typedef long long ll;
using namespace std;


ll modpow(ll a, ll n){
	ll res = 1;
	while(n > 0){
		if (n & 1) res = res*a%MOD;
		a = a*a%MOD;
		n >>= 1;
	}
	return res;
}



int main(){
	int n, k;
	ll ans[100001];
	cin >> n >> k;
	for (int i = k; i >= 2; i--){
		ans[i] = (modpow(k/i, n))%MOD;
		for (int j = 2*i; j <= k; j+= i){
			ans[i] -= ans[j];
		}
	}
	ll true_ans = modpow(k, n);
	for (int i = 2; i <= k; i++){
		true_ans += ((i-1)*ans[i])%MOD;
	}
	cout << true_ans%MOD << endl;
	return 0;
}

Measured memory_bytes: 4352
#include <iostream>
#include<string>
#include<cmath>
#include<algorithm>
#include<cctype>
#include<queue>
#include<stack>
#include<stdio.h>
#include<vector>
#include<set>
#include<map>
#include<iomanip>
#define rep(i,n) for(int long long i=0;i<n;i++)
using namespace std;
char t[7];
int main(){
    int n;
    cin>>n;
    while(n>0){
    vector<int> v(3);
    rep(i,3){
        int x;
        cin>>x;
        v.push_back(x);
    }
    sort(v.begin(),v.end(),greater<int>());
    if(v[0]==sqrt(v[1]*v[1]+v[2]*v[2])){
        cout<<"YES";
    }else{
        cout<<"NO";
    }
        if(n!=0){
            cout<<endl;
        }
        n--;
    }
    
    return 0;
}



Measured memory_bytes: 3136
#![allow(unused_imports)]
#![allow(non_snake_case)]

use std::cell::RefCell;
use std::cmp::{max, min, Ordering};
use std::collections::*;
use std::fmt::{Debug, Formatter, Write as FmtWrite};
use std::io::{stderr, stdin, BufRead, Write};
use std::mem::{replace, swap};
use std::ops::*;
use std::rc::Rc;

// -----------------------------------------------
// Framework <https://github.com/vain0x/procon>
// -----------------------------------------------

#[allow(unused_macros)]
macro_rules! read {
    ([$t:ty] ; $n:expr) =>
        ((0..$n).map(|_| read!([$t])).collect::<Vec<_>>());
    ($($t:ty),+ ; $n:expr) =>
        ((0..$n).map(|_| read!($($t),+)).collect::<Vec<_>>());
    ([$t:ty]) =>
        (rl().split_whitespace().map(|w| w.parse().unwrap()).collect::<Vec<$t>>());
    ($t:ty) =>
        (rl().parse::<$t>().unwrap());
    ($($t:ty),*) => {{
        let buf = rl();
        let mut w = buf.split_whitespace();
        ($(w.next().unwrap().parse::<$t>().unwrap()),*)
    }};
}

#[allow(unused_macros)]
macro_rules! debug {
    ($($arg:expr),*) => {
        #[cfg(debug_assertions)]
        $(writeln!(stderr(), "{} = {:?}", stringify!($arg), $arg).unwrap());*
    };
}

#[allow(dead_code)]
fn rl() -> String {
    let mut buf = String::new();
    stdin().read_line(&mut buf).unwrap();
    buf.trim_right().to_owned()
}

trait IteratorExt: Iterator + Sized {
    fn vec(self) -> Vec<Self::Item> {
        self.collect()
    }
}

impl<T: Iterator> IteratorExt for T {}

// -----------------------------------------------
// Solution
// -----------------------------------------------

fn check(S: &Vec<u8>, T: &Vec<u8>) -> bool {
    let mut m = BTreeMap::new();

    for i in 0..S.len() {
        if let Some(&u) = m.get(&S[i]) {
            if u != T[i] {
                return false;
            }
            continue;
        }

        m.insert(S[i], T[i]);
    }

    true
}

fn main() {
    let S = rl().bytes().vec();
    let T = rl().bytes().vec();

    let ok = check(&S, &T) && check(&T, &S);

    println!("{}", if ok { "Yes" } else { "No" })
}


Measured memory_bytes: 4352
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {

        Scanner sc = new Scanner(System.in);
        
        long N = sc.nextInt();
        long K = sc.nextInt();
        long ans = K;
        
        for(int i = 0; i < N-1; i++)ans *= K-1;
        
        System.out.println(ans);
    }
}


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

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x).size()
#define foru(i, n) for(int i = 1; i <= n; i++)
#define foru0(i, n) for(int i = 0; i < n; i++)
#define ford(i, n) for(int i = n; i >= 1; i--)
#define ford0(i, n) for(int i = n - 1; i >= 0; i--)
#define fors(i, a, b) for(int i = a; i <= b; i++)

using namespace std;

typedef long long ll;
typedef double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<pii> vii;
typedef vector<pll> v2l;
typedef pair<char, int> pci;
typedef vector<pci> vci;

const int N = 1e6 + 1;
const int NN = 1e3 + 1;
const ll MOD = 1e9 + 7;
const ll oo = 1e18 + 7;

vector<vi> g;
vi f;

void DFS(int u) {
    int t = 0;
    for (int i = 0; i < g[u].size(); i++) {
        int v = g[u][i];
        if (!f[v]) {
            DFS(v);
            t = max(t, f[v]);
        } else {
            t = max(t, f[v]);
        }
    }  
    f[u] = t + 1;
    // cout << u << " " << f[u] << endl;
}

void solve() {
    int n, m;
    cin >> n >> m;
    g = vector<vi>(n + 1);
    vi cnt(n + 1);
    for (int i = 1; i <= m; i++) {
        int u, v;
        cin >> u >> v;    
        g[u].push_back(v);
        cnt[v]++; 
    }
    int res = 0;
    f = vi(n + 1);
    for (int i = 1; i <= n; i++) {
        if (!cnt[i]) {
            DFS(i);
            res = max(res, f[i]);
        }
    }
    // for (int i = 1; i <= n; i++) {
    //     cout << f[i] << " ";
    // }
    // cout << endl;
    cout << res - 1;
}

int main() {
    #ifdef DEBUG
        freopen("solve.inp", "r", stdin);
        freopen("solve.out", "w", stdout);
    #endif
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    cout.tie(NULL);
    cout.precision(10);
    solve();
    cerr << "Time elapsed: " << 1.0 * clock() << " ms.\n";
}


Measured memory_bytes: 12800
import java.util.Scanner;

public class Main {
  public static void main(String[] args) {
    Scanner scanner = new Scanner(System.in);

    // 標準入力から色（整数）a, b, cを取得
    int a = scanner.nextInt();
    int b = scanner.nextInt();
    int c = scanner.nextInt();

    // 3色を比較して全て同じ色だった場合1を出力
    if(a == b && a == c) {
      System.out.println(1);

    // 3色中2色が同じ色だった場合2を出力
    } else if(a == b || b == c || c == a) {
      System.out.println(2);

    // 3色全てが異なる色だった場合3を出力
    } else {
      System.out.println(3);
    }
  }
}


Measured memory_bytes: 35600
package main

import (
	"fmt"
	"strconv"
)

func main() {
	var n int
	fmt.Scan(&n)
	ans := 0
	for i := 1; i < n+1; i++ {
		if len(strconv.Itoa(i))%2 == 1 {
			ans++
		}
	}
	fmt.Println(ans)
}


Measured memory_bytes: 1024
using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.Linq;
using static MyIO;


public class A
{
	public static void Main()
	{
		int N = GetInt();
		int A = GetInt();
		int B = GetInt();
		Console.WriteLine((((B - A + 1) % 2) == 1) ? "Alice" : "Borys");
	}
}


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(){ return int.Parse(getArg()); }
	public static long GetLong(){ return long.Parse(getArg()); }
	public static double GetDouble(){ return double.Parse(getArg()); }
	public static string GetString(){ return getArg(); }
}

Measured memory_bytes: 13140
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
typedef vector<int> vec1;
typedef vector<string> vec2;
typedef vector<double> vec3;

int main() {
  
  string s;
  cin >> s;
  string a = "abcdefghijklmnopqrstuvwxyz";
  
  for(int i = 0; i < s.size(); i++) {
    for(int j = 0; j < a.size(); j++) {
      if(s.at(i) == a.at(j)){
        a.erase(a.begin() + j);
      }
    }
  }
  if(a.size() >= 1) {
    cout << a.at(0) << endl;
    return 0;
  } else {
    cout << "None" << endl;
  }
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
typedef pair<ll,ll> p2;
void solve(){
	ll n;
	cin>>n;
	cout<<n+n*n+n*n*n;
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll qc=1;
    //cin>>qc;
    for(ll i=1;i<=qc;i++)
    solve();		
}


Measured memory_bytes: 3648
#E ランレングス法
s = input()
n = len(s)

ans = [0] * n

cnt = 0
for i,moji in enumerate(s):
    if moji =='R':
        cnt += 1
        continue
        
    else:
        even_num = cnt // 2
        odd_num = cnt - even_num
        ans[i] += even_num
        ans[i-1] += odd_num
        cnt = 0
        
cnt = 0
for i in range(n-1,-1,-1):
    if s[i] == 'L':
        cnt += 1
        continue
        
    else:
        even_num = cnt // 2
        odd_num = cnt - even_num
        ans[i] += even_num
        ans[i+1] += odd_num
        cnt = 0
        
print(*ans)

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

int main(){
    int n;
    cin >> n;
    int a;
    bool tmp = false;
    rep(i, n){
        cin >> a;
        if(a%2==0&&a%3!=0&&a%5!=0)
            tmp = true;
    }
    if(tmp){
        cout << "DENIED" << endl;
    }
    else{
        cout << "APPROVED" << endl;
    }
}

Measured memory_bytes: 3636
import java.util.*;
class P
{
	String str;
	int price;
	P(String str, int price)
	{
		this.str = str;
		this.price = price;
	}
}
public class Main 
{
	public static void main(String[] args) 
	{
		Scanner stdIn = new Scanner(System.in);
		while(stdIn.hasNext())
		{
			int n = stdIn.nextInt();
			int m = stdIn.nextInt();
			if(n == 0 && m == 0)
			{
				break;
			}
			List<P> lottery = new ArrayList<P>();
			for(int i = 0; i < n; ++i)
			{
				String str = stdIn.next();
				int price = stdIn.nextInt();
				lottery.add(new P(str, price));
			}
			int sum = 0;
			for(int i = 0; i < m; ++i)
			{
				String ticket = stdIn.next();
				for(int j = 0; j < n; ++j)
				{
					boolean flag = true;
					for(int k = 0; k < ticket.length(); ++k)
					{
						if(lottery.get(j).str.charAt(k) == '*')
						{
							continue;
						}	
						else if(ticket.charAt(k) != lottery.get(j).str.charAt(k))
						{
							flag = false;
							break;
						}
					}
					if(flag)
					{
						sum += lottery.get(j).price;
						break;
					}
				}
			}
			System.out.println(sum);
		}
	}
}

Measured memory_bytes: 12000
from math import ceil,floor,comb,factorial,gcd,pow,sqrt,log2,cos,sin,tan,acos,asin,atan,degrees,radians,pi,inf
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from collections import deque,defaultdict,Counter
from bisect import bisect_left,bisect_right
from operator import itemgetter
from heapq import heapify,heappop,heappush
from copy import deepcopy
from time import time
import string
import sys
sys.setrecursionlimit(10 ** 7)
def input() : return sys.stdin.readline().strip()
def INT()   : return int(input())
def MAP()   : return map(int,input().split())
def LIST()  : return list(MAP())

def bfs():
    que = deque()
    que.append([0, 0])
    if s[0][0] == '#':
        d[0][0] = 1
    else:
        d[0][0] = 0

    while que:
        p = que.popleft()
        if p[0] == h-1 and p[1] == w-1:
            break

        for i in range(2):
            ny = p[0] + dy[i]
            nx = p[1] + dx[i]
            if 0 <= ny < h and 0 <= nx < w:
                if s[p[0]][p[1]] == '.' and  s[ny][nx] == '#':
                    if d[ny][nx] > d[p[0]][p[1]]+1:
                        d[ny][nx] = d[p[0]][p[1]]+1
                        que.append([ny, nx])
                else:
                    if d[ny][nx] > d[p[0]][p[1]]:
                        d[ny][nx] = d[p[0]][p[1]]
                        que.append([ny, nx])

    return d[h-1][w-1]

h, w = MAP()
s = [input() for i in range(h)]
d = [[inf]*w for i in range(h)]

dy = [1, 0]
dx = [0, 1]

print(bfs())

Measured memory_bytes: 10232
sub f{
	$$_=my$t=pop;
	grep$$_?$$_&$t:f(3-$t),@$_;
}
map{map{push@{-$_},-$a[--$|]for@a=split$"}<>;$$_||${@$_?f(1)?b:a:c}++}@n=-<>..-1;
print@n*2*$c-$c*$c+($a+$b)**2+$a*$a

Measured memory_bytes: 135012
import java.util.*;
class Main{
    public static void main(String argv[]) {
        Scanner sc = new Scanner(System.in);
        int mod = 2019;
        int L = sc.nextInt();
        int R = sc.nextInt();
        int l = L%mod;
        int r = R%mod;
        int result = 2019;
        if(R-L>=mod){
            System.out.println(0);
            return;
        }
        if(l>r){
            System.out.println(0);
            return;
        }
        for(int i=l;i<=r;i++){
            for(int j=i+1;j<=r;j++){
                result = Math.min((i*j)%mod, result);
            }
        }
        result = result%mod;
        System.out.println(result);
    }
}

Measured memory_bytes: 23764
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define rep1(i,n) for(int i=1;i<=(int)n;i++)
#define sp(n) cout << fixed << setprecision(n)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
typedef long long ll;
using namespace std;
int main(void){
    int n;cin>>n;
    string s,t;cin>>s>>t;
    int res=s.size()+t.size();
    rep(i,s.size()){
        bool ok=true;
        if(s.size()-i>t.size())continue;
        for(int j=0;j<s.size()-i;j++){
            if(s[i+j]!=t[j]){
                ok=false;
                break;
            }
        }
        if(ok){
            int buf=t.size()+i;
            chmin(res,buf);
        }
    }
    cout<<res<<endl;
}

Measured memory_bytes: 3588
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
void Say(bool say, string a = "Yes", string b = "No"){cout << (say ? a : b) << endl;};

int main(){

    ll N;
    cin >> N;
    vector<ll>v(N);
    for(ll i = 0; i < N; i++)cin >> v[i];
    sort(v.begin(), v.end());
    cout << v[N / 2] - v[N / 2 - 1] << endl;

    return 0;
}

Measured memory_bytes: 1024
import queue

q = queue.Queue()

H,W = map(int,input().split())
S = [list(input()) for i in range(H)]
ans = 0
vec_x = [1,0,-1,0]
vec_y = [0,1,0,-1]

def bfs(sx,sy):
    #最短距離を格納する配列
    d = [[-1 for i in range(W)] for j in range(H)]
    d[sy][sx] = 0
    q.put([sx,sy])
    while not q.empty():
        current_xy = q.get()
        #4方向のループ
        for i in range(4):
            nx = current_xy[0] + vec_x[i]
            ny = current_xy[1] + vec_y[i]

            #移動が可能か
            if( (nx >= 0 and nx < W ) and (ny >= 0 and ny < H ) ):
                if S[ny][nx] != "#":
                    #すでにおとずれていないか
                    if d[ny][nx] == -1:
                        q.put([nx,ny])
                        d[ny][nx] = d[current_xy[1]][current_xy[0]] + 1
    return d[current_xy[1]][current_xy[0]]

for sx in range(W):
    for sy in range(H):
        if S[sy][sx] == "#":
            continue
        if ans <= bfs(sx,sy):
            ans = bfs(sx,sy)

print(ans)

Measured memory_bytes: 3948
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.InputMismatchException;
import java.util.Map;
import java.util.StringTokenizer;
import java.util.TreeMap;


public class Main {

	public static void main(String[] args) throws IOException {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		InputReader in = new InputReader(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		TaskX solver = new TaskX();
		solver.solve(1, in, out);
		out.close();
	}

	static int maxQ = 100010;
	static class TaskX {
		public void solve(int testNumber, InputReader in, PrintWriter out) {

			boolean[] isPrime = new boolean[maxQ];
			getPrimes(isPrime);
			int[] a = new int[maxQ];
			for (int i = 0; i < maxQ; i++) {
				if (i % 2 == 1 && isPrime[i] && isPrime[(i+1)/2]) a[i] = 1;
			}
			int[] sum = new int[maxQ];
			for (int i = 0; i < maxQ - 1; i++) {
				sum[i+1] = sum[i] + a[i+1];
			}

			int q = in.nextInt();
			for (int i = 0; i < q; i++) {
				int l = in.nextInt();
				int r = in.nextInt();
				out.println(sum[r]-sum[l-1]);
			}

		}
	}

	public static void getPrimes(boolean[] isPrime) {
		Arrays.fill(isPrime, true);
		isPrime[0] = isPrime[1] = false;
		for (int i = 2; i <= Math.sqrt(isPrime.length); i++) {
			if (!isPrime[i])
				continue;
			for (int j = i + i; j < isPrime.length; j += i) {
				isPrime[j] = false;
			}
		}
	}

	static class ArrayUtils {
		public static Map<Integer, Integer> getCountMap(int[] array) {
			Map<Integer, Integer> map = new TreeMap<>();
			for (int x : array)
				map.merge(x, 1, Integer::sum);
			return map;
		}
	}

	static class InputReader {
		BufferedReader in;
		StringTokenizer tok;

		public String nextString() {
			while (!tok.hasMoreTokens()) {
				try {
					tok = new StringTokenizer(in.readLine(), " ");
				} catch (IOException e) {
					throw new InputMismatchException();
				}
			}
			return tok.nextToken();
		}

		public int nextInt() {
			return Integer.parseInt(nextString());
		}

		public long nextLong() {
			return Long.parseLong(nextString());
		}

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

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

		public InputReader(InputStream inputStream) {
			in = new BufferedReader(new InputStreamReader(inputStream));
			tok = new StringTokenizer("");
		}

	}

}


Measured memory_bytes: 45524
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll N=3e5+5;

int main(){
    ios_base:: sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    ll n;cin>>n;
    n*=2;
    ll a[n];
    for(ll i=0;i<n;i++)cin>>a[i];
    ll ans=0;sort(a,a+n);
    for(ll i=0;i<n;i+=2)ans+=a[i];
    cout<<ans;
}



Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <string>
#include <algorithm>
#include <set>
#include <vector>
#include <map>
#include <list>
#include <stack>
#define REP(i, n) for(i=0; i<n; i++)
#define REPR(i, n) for(i=n; i>=0; i--)
#define FOR(i, m, n) for(i=m; i<n; i++)
#define max(a, b) ((a)>(b) ? (a):(b))
#define min(a, b) ((a)<(b) ? (a):(b))
#define INF 10000000000
#define MOD 1000000007LL
using namespace std;
typedef long long ll;
typedef pair<ll, ll> p;
typedef pair<double, double> doup;

int main(void) {
    ll a[3];
    ll i;
    for(i=0; i<3; i++)
        cin >> a[i];
    sort(a, a+3);
    
    cout << a[1]-a[0]+a[2]-a[1] << endl;
    
    
    
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
//ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<pii,int> ppii;
typedef pair<int,pii> pipi;
typedef pair<ll,ll> pll;
typedef pair<pll,ll> ppll;
typedef pair<ll,pll> plpl;
typedef tuple<ll,ll,ll> tl;
ll mod=1000000007;
ll mod2=998244353;
ll mod3=1000003;
ll mod4=998244853;
ll inf=1000000000000000000;
double pi=2*acos(0);
#define rep(i,m,n) for(ll i=m;i<n;i++)
#define rrep(i,n,m) for(ll i=n;i>=m;i--)
int dh[4]={1,-1,0,0};
int dw[4]={0,0,1,-1};
int ddh[8]={-1,-1,-1,0,0,1,1,1};
int ddw[8]={-1,0,1,-1,1,-1,0,1};
ll lmax(ll a,ll b){
    if(a<b)return b;
    else return a;
}
ll lmin(ll a,ll b){
    if(a<b)return a;
    else return b;
}
ll gcd(ll a,ll b){
    if(a<b)swap(a,b);
    if(b==0)return a;
    if(a%b==0)return b;
    return gcd(b,a%b);
}
ll Pow(ll n,ll k){
    ll ret=1;
    ll now=n;
    while(k>0){
        if(k&1)ret*=now;
        now*=now;
        k/=2;
    }
    return ret;
}

int main(){
    ios::sync_with_stdio(false);cin.tie(0);
    string s,t;cin>>s>>t;
    cout<<t<<s<<endl;
}


Measured memory_bytes: 256
#include <string>
#include <queue>
#include <stack>
#include <vector>
#include <sstream>
#include <algorithm>
#include <deque>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <list>
#include <cstdio>
#include <iostream>
#include <cmath>
#include <climits>
#include <bitset>
#include <functional>
#include <numeric>
#include <ctime>
#include <cassert>
#include <cstring>
#include <fstream>
#include <iomanip>

using namespace std;

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

using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

template<class T>
void print_container(T &container, string delim=" ") {
    bool first = true;
    for(auto &t: container){
        if(!first){
            cout << delim;
        }
        first = false;
        cout << t;
    }
    cout << endl;
}

int main() {
    int a, b, c, k;
    cin >> a >> b >> c >> k;
    if(k < a){
        cout << k << endl;
    }
    else if(k<a+b)
        cout << a << endl;
    else 
        cout << a - (k-a-b) << endl;;

    return 0;
}

Measured memory_bytes: 3156
#include<bits/stdc++.h>
using namespace std;
#define forn(i, n)             for(int i = 0; i < n; i ++)
#define forn1(i, n)            for(int i = 1; i <= n; i ++)
#define pb push_back
#define ll long long int
#define fi first
#define se second
#define ii  pair<long long int, long long int>
#define vi  vector <long long int>
#define vii vector <pair <long long int, long long int > >
#define all(cont)  cont.begin(), cont.end()
#define EPS 1e-9
#define MOD 1000000007
#define range 
#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#pragma GCC optimize ("Ofast")
int main(){

//    freopen("input.txt","r",stdin);
    IOS;
    clock_t clk = clock();
	int n;cin>>n;
	int ans = 0;
	int a[n];
	forn(i,n)cin>>a[i];        

	int curr = 0;
	forn(i,n-1){
		if(a[i] >= a[i+1] )curr++;
		else{
			curr = 0;
		}
		ans = max(ans, curr);
	}

	cout<<ans;

    cerr << endl << setprecision(10) << fixed << (double)(clock() - clk) / CLOCKS_PER_SEC;
    return 0;
}


Measured memory_bytes: 640
#include <iostream>
#include <math.h>
#include <stdio.h>
using namespace std;

int main() {
    int a, b, C;
    cin >> a >> b >> C;
    double theta;
    theta = C * M_PI / 180;

    double S, L, h;
    S = a * b * sin(theta) / 2;
    //cout << S << endl;
    printf("%.4f\n", S);
    
    double c;
    c = sqrt(a * a + b * b - 2 * a * b * cos(theta));
    L = a + b + c;
    //cout << L << endl;
    printf("%.4f\n", L);

    h = S / a * 2;
    //cout << h << endl;
    printf("%.4f\n", h);
    
	return 0;
}



Measured memory_bytes: 3360
//define LOCAL
#include <iostream>
#include <fstream>
#include <cmath>
#include <iomanip>
#include <stdio.h>
#include <cstring>
#include <string.h>
#define maxn 105
using namespace std;

int main()
{
#ifdef LOCAL
    ifstream cin("input.txt");
    ofstream cout("output.txt");
#endif // LOCAL
    int A,X;
    cin>>X>>A;
    if(X<A)
        cout<<0;
    if(A<=X)
        cout<<10;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ALL(A) (A).begin(), (A).end()
#define ll long long
#define rep(i, n) for (int i = 0; i < (n); i++)

const ll mod = 1e9 + 7;
const ll INF = -1 * ((1LL << 63) + 1);
const int inf = -1 * ((1 << 31) + 1);

using namespace std;

int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);

    ll N, M, L;
    cin >> N >> M;
    string S, T;
    cin >> S >> T;
    L = N / __gcd(N, M) * M;
    bool ok = 1;
    // L の長さが決まると,Xの特定の場所の文字が決まる
    map<ll, char> mp;
    for (int i = 0; i < N; i++)
    {
        mp[1 + (i)*(L / N)] = S[i];
    }
    for (int i = 0; i < M; i++)
    {
        if (mp.count((1 + (i)* (L / M))))
        {
            if (mp[1 + (i)*(L / M)] != T[i])
                ok = 0;
        }
    }
    if (ok)
        cout << L << endl;
    else
        cout << -1 << endl;
}

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

int x;

signed main() {
	scanf("%lld", &x);
	for (int a = 0; ; a++) {
		int b = a * a * a * a * a + x;
		int tmp = (int) pow(b, 0.2);
		if (tmp * tmp * tmp * tmp * tmp == b) {
			printf("%lld %lld\n", (int) pow(b, 0.2), a);
			return 0;
		}
		b = (-a) * (-a) * (-a) * (-a) * (-a) + x;
		tmp = (int) pow(b, 0.2);
		if (tmp * tmp * tmp * tmp * tmp == b) {
			printf("%lld %lld\n", (int) pow(b, 0.2), -a);
			return 0;
		}
	}
}

Measured memory_bytes: 4260
//#define LOCAL
#include<stdio.h>
#include<algorithm>
#include<vector>
#include<string>
#include<math.h>
#include<map>
#include<random>
using namespace std;
using lld = long long int;
using llu = unsigned long long int;
using pii = pair<int, int>;
using pli = pair<lld, int>;
using pil = pair<int, lld>;
using pll = pair<lld, lld>;
lld n, m;
int main() {
	int i, j, k, l;
	int t = 1, tv = 0;
	while (t--) {
		lld n = 100;
		scanf("%lld", &m);
		lld time = 0;
		while (1) {
			n += n / 100;
			time++;
			if (n >= m)
				break;
		}
		printf("%lld\n", time);
	}
}

Measured memory_bytes: 1732
s = input()

dp_prev = [1, 0, 0, 0]

MOD_BASE = 1000000007

for c in s:
    dp_new = [dp_prev[i] for i in range(0, 4)]
    for i in range(0, 4):
        if c == "A":
            dp_new[1] = dp_prev[0] + dp_prev[1]

        elif c == "B":
            dp_new[2] = dp_prev[1] + dp_prev[2]

        elif c == "C":
            dp_new[3] = dp_prev[2] + dp_prev[3]

        else:
            dp_new[0] = dp_prev[0] * 3
            dp_new[1] = dp_prev[0] + dp_prev[1] * 3
            dp_new[2] = dp_prev[1] + dp_prev[2] * 3
            dp_new[3] = dp_prev[2] + dp_prev[3] * 3
            
    dp_prev = [x % MOD_BASE for x in dp_new]

ans = dp_prev[3]
print(ans)


Measured memory_bytes: 3188
def insertionSort(N,A): 
    for i in range(0,N):
        innum = A[i]
        j = i - 1
        while j>=0 and innum < A[j]:
            A[j+1] = A[j]
            j = j -1
        A[j+1] = innum
        for j in range(0,N):
            if j < N-1:
                print(A[j], end=" ")
            else:
                print(A[j])

    
    return A

if __name__ == "__main__":
    N = input()
    N = int(N)
    A = input()
    A = A.split()
    for i in range(0,N):
        A[i] = int(A[i])
    insertionSort(N,A)

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

long long int A[100001];
int n;
long long int res[100001];

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

    cin >> n;

    for(int i=1;i<=n;i++)
    {
    	cin >> A[i];
    }

    long long int val = A[1];
    for(int i=2;i<n;i++)
    {
    	val = A[i] - val;
    }

    res[n] = val + A[n];
    for(int i=n-1;i>=1;i--)
    {
    	res[i] = 2*A[i] - res[i+1];
    }

    for(int i=1;i<=n;i++)
    {
    	cout << res[i] << ' ';
    }
    cout << '\n';
    
    return 0;
}

Measured memory_bytes: 2944
def c_pyramid(N, Pos):
    from itertools import product
    # 中心座標を全探索
    for cx, cy in product(range(101), repeat=2):
        # ピラミッドの高さを求める
        for x, y, h in Pos:
            if h > 0:
                height = h + abs(cx - x) + abs(cy - y)
        # ピラミッドの高さが得られた情報に適合するか調べる
        for x, y, h in Pos:
            if h != max((height - abs(cx - x) - abs(cy - y)), 0):
                break
        else:
            ans = [cx, cy, height]
            break
    ans = '{0} {1} {2}'.format(*ans)
    return ans

N = int(input())
Pos = [[int(i) for i in input().split()] for j in range(N)]
print(c_pyramid(N, Pos))

Measured memory_bytes: 3064
use std::io::*;
use std::str::FromStr;

#[test]
fn test() {
}

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
            .bytes()
            .map(|c| c.expect("failed to read char") as char)
            .skip_while(|c| c.is_whitespace())
            .take_while(|c| !c.is_whitespace())
            .collect();
    token.parse().ok().expect("failed to parse token")
}

fn alchemist(n: usize, mut v: Vec<u32>) -> f32 {
    v.sort();
    let mut ans = v[0] as f32;
    for i in 1..n {
        ans = (ans + v[i] as f32) / 2.0
    }
    ans 
}

fn main() {
    let n: usize = read();
    let mut v = Vec::new();
    for _i in 0..n {
        v.push(read::<u32>());
    }
    println!("{}", alchemist(n, v));
//    println!("{:?}", v);

}



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

int N, M, X;
int main(){
	cin>>N>>M>>X;
	int toll[1][M];
	int kecil, besar;
	kecil=0;
	besar=0;
	for(int i=0;i<M;i++){
		cin>>toll[0][i];
	}
	for(int i=0;i<M;i++){
		if(toll[0][i]<X){
			kecil++;
		}else{
			besar++;
		}
	}
	if(kecil>besar){
		cout<<besar;
	}else{
		cout<<kecil;
	}
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
  
using namespace std;
   
long long dp[1000000];
 
int main(){
   
  long long h,n;
  long long num =0;
  cin >> h >> n;
  long long a[n],b[n];
  for(long long i=0;i<n;i++) cin >> a[i]>>b[i];
  
  for(long long j=0;j<=100000;j++)dp[j] = 100000000;
  
  for(long long m=0;m<n;m++){
    if(num < a[m]) num = a[m];
  }
 
  dp[0] = 0;
  
  for(long long k=0;k<h;k++){
    for(long long i=0;i<n;i++){
      dp[k+a[i]] = min(dp[k+a[i]],dp[k]+b[i]);
    }
  }
  
  long long sum = 100000000;
  for(long long l=h;l<h+num;l++){
      if(sum > dp[l]) sum = dp[l];
  }
  
  cout << sum << endl;
  
  return 0;
  
}

Measured memory_bytes: 1656
import sys
import bisect
readline = sys.stdin.readline

N = int(readline())
a = [int(readline())]
append = a.append
for _ in [None]*(N-1):
    n = int(readline())
    if a[-1] < n:
        append(n)
    else:
        a[bisect.bisect_left(a, n)] = n

print(len(a))

Measured memory_bytes: 12188
/******************************************************************************

Welcome to GDB Online.
GDB online is an online compiler and debugger tool for C, C++, Python, PHP, Ruby, 
C#, VB, Perl, Swift, Prolog, Javascript, Pascal, HTML, CSS, JS
Code, Compile, Run and Debug online from anywhere in world.

*******************************************************************************/
#include <stdio.h>
#include <string.h>

int main()
{
    char a[10];
    char b[10];
    int ac, bc;
    char u[10];
    int i;
    
    scanf("%s %s\n",a,b);
    scanf("%d %d",&ac,&bc);
    scanf("%s",u);
    
    for (i=0;i<=strlen(a);i++)
    {
        if (i == strlen(a))
        {
            ac--;
        }
        else if (u[i] != a[i])
        {
            break;
        }
    }
    for (i=0;i<=strlen(b);i++)
    {
        if (i == strlen(b))
        {
            bc--;
        }
        else if (u[i] != b[i])
        {
            break;
        }
    }
    
    
    
    printf("%d %d",ac,bc);
}


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

const int Mod=1e9+7,N=3e3+10;

int n,m,dp[N][N],summ[N];
char s[N];

void Init() {
	scanf("%d%d",&n,&m);
	scanf("%s",s+1);
	for (int i=1;i<=n;++i) summ[i]=summ[i-1]+(s[i]=='0'); 
}

void Solve() {
	int nowr=0,l,r,cnt=0;
	scanf("%d%d",&l,&r); ++cnt;
	dp[0][0]=1;
	for (int i=0;i<n;++i) {
		int sum=0; 
		while (i+1==l && cnt<=m) {
			if (r>nowr) sum+=summ[r]-summ[nowr],nowr=r;
			if (cnt<m) { scanf("%d%d",&l,&r); ++cnt; }
			else break; 
		}
		if (nowr>i){
			for (int j=0;j<=nowr-i;++j) {
				if (j+sum) dp[i+1][j+sum-1]=(dp[i+1][j+sum-1]+dp[i][j])%Mod;
				if (nowr-i-j-sum) dp[i+1][j+sum]=(dp[i+1][j+sum]+dp[i][j])%Mod; 
			}
		}else dp[i+1][0]=dp[i][0],nowr=i+1;
	}
	printf("%d\n",dp[n][0]);
} 

int main() {
	Init();
	Solve();
	return 0;
}

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

using namespace std;

using ll = long long;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    deque<ll> a(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }

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

    deque<ll> b;

    bool flag = true;
    ll ans = 0;
    while (a.size() > 1) {
        if (flag) {
            if (b.size() > 1) {
                ans += abs(a.front() - b.front());
                ans += abs(a.back() - b.back());
            } else {
                ans += abs(a.front() - a.back());
            }
            b.push_front(a.front());
            b.push_back(a.back());
            a.pop_front();
            a.pop_back();
        } else {
            if (b.size() > 1) {
                ans += abs(a.back() - b.front());
                ans += abs(a.front() - b.back());
            }
            b.push_back(a.front());
            b.push_front(a.back());
            a.pop_front();
            a.pop_back();
        }
        flag = !flag;
    }
    //for (ll x : b) cout << x << endl;
    //cout << ans << endl;
    if (a.size() == 1) {
        ans += max(abs(a[0] - b.front()), abs(a[0] - b.back()));
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1152
#include <bits/stdc++.h>
#define ll long long int
#define ld long double
#define yorn(f) cout<<((f)?"Yes":"No")<<endl;
#define YORN(f) cout<<((f)?"YES":"NO")<<endl;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repi(i, n) for (int i = 1; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define put(x) cout << x << endl;
#define println(x) cout << x << endl;
using namespace std;

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



int main()
{
    ll a, b, c, d;
    cin >> a >> b >> c >> d;

    ll v = b - a + 1;
    v -= b / c - (a - 1) / c;
    v -= b / d - (a - 1) / d;
    ll cd = c * d / gcd(c, d);
    v += b / cd - (a - 1) / cd;

// 6 3 2 1
// 31 (6 -1) (5-1) ()

    put(v);

    return 0;
}

Measured memory_bytes: 3600
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.InputMismatchException;
import java.util.StringTokenizer;

public class Main {

	public static void main(String[] args) throws IOException {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		InputReader in = new InputReader(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		TaskX solver = new TaskX();
		solver.solve(1, in, out);
		out.close();
	}

	static int INF = 1 << 30;
	static int MOD = 1000000007;
	static int[] mh4 = { 0, -1, 1, 0 };
	static int[] mw4 = { -1, 0, 0, 1 };

	static class TaskX {
		public void solve(int testNumber, InputReader in, PrintWriter out) {

			int n = in.nextInt();
			String s = in.nextString(), t = in.nextString();

			for (int i = 0; i <= n; i++) {
				String ts = s.substring(i, n);
				String tt = t.substring(0, n-i);

				if (ts.equals(tt)) {
					out.println(n+i);
					return;
				}

			}

		}
	}

	static class InputReader {
		BufferedReader in;
		StringTokenizer tok;

		public String nextString() {
			while (!tok.hasMoreTokens()) {
				try {
					tok = new StringTokenizer(in.readLine(), " ");
				} catch (IOException e) {
					throw new InputMismatchException();
				}
			}
			return tok.nextToken();
		}

		public int nextInt() {
			return Integer.parseInt(nextString());
		}

		public long nextLong() {
			return Long.parseLong(nextString());
		}

		public double nextDouble() {
			return Double.parseDouble(nextString());
		}

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

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

		public InputReader(InputStream inputStream) {
			in = new BufferedReader(new InputStreamReader(inputStream));
			tok = new StringTokenizer("");
		}

	}

}


Measured memory_bytes: 21460
// #define _GLIBCXX_DEBUG
#include <bits/stdc++.h>

#define FOR(i, a, b) for (int i = (a); i < int(b); ++i)
#define RFOR(i, a, b) for (int i = (b)-1; i >= int(a); --i)
#define REP(i, n) FOR(i, 0, n)
#define REP1(i, n) FOR(i, 1, int(n) + 1)
#define RREP(i, n) RFOR(i, 0, n)
#define RREP1(i, n) RFOR(i, 1, int(n) + 1)
#define ALL(c) begin(c), end(c)

int _ = (
#ifndef LOCAL
    std::cin.tie(nullptr), std::ios::sync_with_stdio(false),
#endif
    std::cout.precision(10), std::cout.setf(std::ios::fixed));

using ll = long long;
using ld = long double;
// constexpr auto mod = 1000000007;
using namespace std;

int main() {
  ll N, K;
  cin >> N >> K;
  vector<ll> h(N);
  REP(i, N) { cin >> h[i]; }

  constexpr ll INF = numeric_limits<ll>::max() / 3;
  vector<ll> dp(N, INF);
  dp[0] = 0;
  dp[1] = dp[0] + abs(h[0] - h[1]);
  REP(i, N) {
    REP1(j, K) { dp[i + j] = min(dp[i + j], dp[i] + abs(h[i] - h[i + j])); }
  }
  cout << dp[N - 1] << endl;
  return 0;
}


Measured memory_bytes: 1792
import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		int L = sc.nextInt();
		int R = sc.nextInt();
		int min = 2018;
		if (R - L > 2019) {
			System.out.print(0);
		} else {
			int LMod = Math.floorMod(L, 2019);
			int RMod = Math.floorMod(R, 2019);
			if (LMod < RMod) {
				for (int i = LMod; i < RMod; i++) {
					for (int j = i + 1; j <= RMod; j++) {
						int surPlus = (i * j) % 2019;
						if (surPlus < min) {
							min = surPlus;
						}
					}
				}
				System.out.print(min);
			} else {
				System.out.print(0);
			}
		}
	}
}


Measured memory_bytes: 22100
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <string>
#include <vector>
#include <math.h>
#include <queue>
#include <deque>
#include <map>
const int MOD = 1e9+7;
typedef long long ll;
using namespace std;

ll dp[100001][2];


int main(){
	string s;
	cin >> s;


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

	for (int i = 1; i < s.length(); i++){
		if (s[i] == '0'){
			dp[i][0] += dp[i-1][0]*3;
			dp[i][1] += dp[i-1][1];
		}else{
			dp[i][0] += dp[i-1][0]*3;
			dp[i][0] += dp[i-1][1];
			dp[i][1] += dp[i-1][1]*2;
		}
		dp[i][0] %= MOD;
		dp[i][1] %= MOD;
	}
	cout << (dp[s.length()-1][0] + dp[s.length()-1][1])%MOD << endl;
	return 0;
}

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

int main() {
  
  int N, A, B;
  cin >> N >> A >> B;
  int pl1 = A * N;
  int pl2 = B;

  if (pl1 > pl2) {
    cout << pl2 << endl;
  }
  else{
  	cout << pl1 << endl;
  }
}

Measured memory_bytes: 3516
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

res = 0
tmp = 0
for i in range(N):
    res += min(A[i], B[i]+tmp)
    tmp = max(B[i] - max(A[i] - tmp, 0), 0)

res += min(tmp, A[N])

print(res)


Measured memory_bytes: 19244