akhauriyash/Code-Regression huggingface dataset:
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;

namespace AtCoder.D
{
    public class Program
    {
        public static void Main() { var r = GetResult(); Debug.WriteLine(r); Console.Write(r); }

        private static object GetResult()
        {
            var (H, W, D) = Read3Longs();
            var dicPoint = new Dictionary<long, Point>();
            var A = new long[H, W];
            for (int i = 0; i < H; i++)
            {
                var l = ReadLongs();
                for (int j = 0; j < W; j++)
                {
                    A[i, j] = l[j];
                    dicPoint.Add(l[j], new Point(i, j));
                }
            }

            var ruiseki = new long[H * W + 1];
            for (int point = 1; point <= H * W; point++)
            {
                // 計算済みのルート
                if (ruiseki[point] != 0) continue;

                for (int x = 1; ; x++)
                {
                    var to = point + x * D;
                    if (to > H * W)
                    {
                        break;
                    }
                    var pre = point + (x - 1) * D;
                    var prePoint = dicPoint[pre];
                    var toPoint = dicPoint[to];
                    var cost = Math.Abs(prePoint.X - toPoint.X) + Math.Abs(prePoint.Y - toPoint.Y);
                    ruiseki[to] = ruiseki[pre] + cost;
                }
            }

            var Q = ReadLong();
            var sb = new StringBuilder();
            for (int i = 0; i < Q; i++)
            {
                var (L, R) = Read2Longs();
                if (L == R)
                {
                    sb.AppendLine("0");
                    continue;
                }
                sb.AppendLine((ruiseki[R] - ruiseki[L]).ToString());
            }

            return sb.ToString().Trim();
        }

        class Point
        {
            public int X { get; set; }
            public int Y { get; set; }

            public Point(int x, int y)
            {
                X = x;
                Y = y;
            }
        }

        #region Console.Read

        public static string ReadText() { return Console.ReadLine(); }
        public static List<string> ReadTexts() { return Console.ReadLine().Split(' ').ToList(); }
        public static long ReadLong() { return long.Parse(Console.ReadLine()); }
        public static (long, long) Read2Longs() { var ls = ReadLongs(); return (ls[0], ls[1]); }
        public static (long, long, long) Read3Longs() { var ls = ReadLongs(); return (ls[0], ls[1], ls[2]); }
        public static (long, long, long, long) Read4Longs() { var ls = ReadLongs(); return (ls[0], ls[1], ls[2], ls[3]); }
        public static (long, long, long, long, long) Read5Longs() { var ls = ReadLongs(); return (ls[0], ls[1], ls[2], ls[3], ls[4]); }
        public static List<long> ReadLongs() { return Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToList(); }

        #endregion
    }
}


Measured memory_bytes: 57524
import java.util.*;
import java.util.ArrayList;
public class Main{
    public static void main(String[]args){  
    Scanner sc=new Scanner(System.in);
    String O=sc.next();
    String E=sc.next();
    char[]OO=O.toCharArray();
    char[]EE=E.toCharArray();
    for(int i=0;i<O.length();i++){
            System.out.print(OO[i]);
            if((i==O.length()-1)&&(O.length()>E.length())){
                break;
            }
        
    
    
        System.out.print(EE[i]);
    }
    
    
    }
}

Measured memory_bytes: 21844
N = int(input())
v = list(map(int, input().split()))
v.sort(reverse=True)
while len(v) > 1:
  num1 = v.pop()
  num2 = v.pop()
  result = (num1 + num2) / 2
  v.append(result)
  v.sort(reverse=True)
print(v[0])

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

signed main(void)
{
	int a, b, c;
	cin >> a >> b >> c;
	if (a > b)
		cout << 0 << endl;
	else if (a * c <= b)
		cout << c << endl;
	else
		cout << b / a << endl;
	return 0;
}


Measured memory_bytes: 256
N = int(input())
S = input()

cumw = [0]
for c in S:
    cumw.append(cumw[-1] + int(c=='W'))

ans = N
for i in range(N):
    tmp = cumw[i]
    tmp += (N-i-1) - (cumw[-1]-cumw[i+1])
    ans = min(ans,tmp)
print(ans)

Measured memory_bytes: 15520
#include <bits/stdc++.h>
#include <string>
#include <cstring>
#include <algorithm>
#include <math.h>
#include <map>
#include <bitset>
#include <cmath>
#include <set>
#include <utility>

#define INF 1000000000000
#define MOD 1000000007 //10^9+7:合同式の法

using namespace std;
typedef long long ll;

//マクロ
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)

int main(){
    string s;
    cin >> s;
    char kai;
    bool fla = false;

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

    for(char c = 97;c <= 122;c++){
        for(int i = 0;i < s.size();i++){
            if(s.at(i) == c)
                break;
            else if(s.at(i) != c and i == s.size() -1){
                kai = c;
                fla =true;
                break;
            }
        }
        if(fla)
            break;
    }

    if(fla)
        cout << kai << endl;
    else
    {
        cout << "None" << endl;
    }
    




    
    
}

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

#define fr first
#define sc second
#define mk make_pair
#define pb push_back

using namespace std;

long long x, y;

int main()
{
    cin >> x >> y;
    if(x < y)
        swap(x, y);
    if(abs(x - y) <= 1)
    {
        cout << "Brown";
    }else
    {
        cout << "Alice";
    }
    return 0;
}


Measured memory_bytes: 256
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"
#include "numeric"
#include "cassert"
#include "ctime"

using namespace std;

//constexpr long long int MOD = 1000000007;
//constexpr int MOD = 1000000007;
//constexpr int MOD = 998244353;
constexpr long long int MOD = 998244353;
constexpr double EPS = 1e-9;

//int N, M, K, H, W, L, R;
long long int N, M, K, H, W, L, R;

long long int power(long long int x, long long int n, long long int M) {
	long long int ret = 1;
	long long int by = x;
	while (n) {
		if (n & 1) {
			ret *= by;
			ret %= M;
		}
		by *= by;
		by %= M;
		n >>= 1;
	}
	return ret;
}

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

	cin >> N >> M >> K;
	vector<long long int>by(400001, 1);
	vector<long long int>rev(400001, 1);
	for (int i = 2; i <= 400000; i++) {
		by[i] = by[i - 1] * i%MOD;
		rev[i] = power(by[i], MOD - 2, MOD);
	}
	long long int ans = 0;
	for (int i = 0; i <= K; i++) {
		ans += by[N - 1] * rev[i] % MOD*rev[N - 1 - i] % MOD * power(M - 1, N - 1 - i, MOD) % MOD*M%MOD;
		ans %= MOD;
	}
	cout << ans << endl;
}

Measured memory_bytes: 9516
#include<iostream>
using namespace std;
#include<cmath>
long long A,B,C;
long long mm;
long long box1,box2,ans;
int main()
{
	cin>>A>>B>>C;
	mm=A>>1;
	box1=mm*B*C;
	box2=(A-mm)*B*C;
	ans=abs(box1-box2);
	
	mm=B>>1;
	box1=mm*A*C;
	box2=(B-mm)*A*C;
	if(abs(box1-box2)<ans)
	ans=abs(box1-box2);
	
	
	mm=C>>1;
	box1=mm*B*A;
	box2=(C-mm)*B*A;
		if(abs(box1-box2)<ans)
	ans=abs(box1-box2);
	
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 888
import numpy as np

n = int(input())
a = list(map(int, input().split()))

a = np.array(a)
a = np.diff(a)
b = []
for i in range(n-1):
    if a[i] != 0:
        b.append(i)
if len(b)>1:
    b = np.array(b)
    b1 = np.diff(b)
    b1 = b1.tolist()
    c = [b1[i]//2 for i in range(len(b1))]
    sum = sum(c) - (-b[0]//2) - (b[-1] - n + 2)//2
elif len(b)==1:
    sum = - (-b[0] // 2) - (b[0] - n + 2)//2
else:
    sum = n//2
print(sum)

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

using namespace std;
using ll = long long;

//container util
#define SORT(c) sort((c).begin(),(c).end())

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

const int INF = 1e9;

int main(void){


	ll A, B; cin >> A >> B;
	ll ans;
	if(min(A, B) == 1) ans = 1;
	else{
		ans = (A*B+1)/2;
	}

	cout << ans << endl;



	return 0;

}


Measured memory_bytes: 256
n,k=map(int,input().split())
l=[]
mod=998244353
for i in range(k):
  l.append(tuple(map(int,input().split())))

s=[0,1]
for i in range(1,n):
  t=0
  for j in range(k):
    t+=s[max(0,i-l[j][0]+1)]-s[max(0,i-l[j][1])]
  s.append((s[-1]+t)%mod)
print(t%mod)

Measured memory_bytes: 87060
#include <cassert>
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <cwchar>
#include <cwctype>
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <array>
#include <atomic>
#include <chrono>
#include <codecvt>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define rrep(i, n) for(ll i = n-1; i > 0; i--)
#define all(x) (x).begin(),(x).end()
#pragma GCC optimize("Ofast")
using namespace std;
typedef int64_t ll;
typedef long double ld;
const ll INF=(1LL<<60);
const ld pi=acosl((ld)1);
const ll mod = 1000000007;
const int dx[4]={0,1,0,-1};
const int dy[4]={1,0,-1,0};
const int ddx[8]={1,0,-1,-1,-1,0,1,1};
const int ddy[8]={1,1,1,0,-1,-1,-1,0};

bool solve(){
  ll N,Q;cin>>N>>Q;
  vector<pair<ll,pair<ll,ll>>>v;
  rep(i,N){
    ll s,t,x;cin>>s>>t>>x;
    v.push_back(make_pair(s-x,make_pair(0,x)));
    v.push_back(make_pair(t-x,make_pair(-1,x)));
  }
  rep(i,Q){
    ll D;cin>>D;
    v.push_back(make_pair(D,make_pair(1,0)));
  }
  sort(all(v));
  multiset<ll>set;
  rep(i,v.size()){
    ll t=v[i].first;
    ll type=v[i].second.first;
    ll x=v[i].second.second;
    // cout<<t<<" "<<type<<" "<<x<<endl;;
    if(type==0)set.insert(x);
    if(type==-1)set.erase(set.find(x));
    if(type==1){
      if(set.size()==0)cout<<-1<<endl;
      else cout<<*set.begin()<<endl;
    }
  }
  return false;
}

signed main(){  
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout<<fixed;
	cout<<setprecision(30);
	return solve();
}


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

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

int main() {

	ll n, m;
	cin >> n >> m;
	vector<pair<ll, ll>> a;
	rep(i, n) {
		ll x, y;
		cin >> x >> y;
		a.push_back(make_pair(x, y));
	}

	sort(a.begin(), a.end());
	//reverse(a.begin(), a.end());
	ll ans = 0;

	for (int i = 0; m > 0; i++) {
		if (m > a[i].second) {
			ans += a[i].first * a[i].second;
		}
		else {
			ans += a[i].first * m;
		}
		m -= a[i].second;
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 2420
import * as fs from 'fs';

function Picker(input) {
  var lines = input.split('\n');
  var fields = lines.reduce(function(all, line) { return all.concat(line.split(' ')); }, []);
  var p = 0;

  return {
    int: function() {
      return parseInt(fields[p++], 10);
    },
    float: function() {
      return parseFloat(fields[p++]);
    },
    str: function() {
      return fields[p++];
    }
  };
}

const input = fs.readFileSync("/dev/stdin", "utf8");
const pick = Picker(input);

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

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

const n = pick.int();
const a = new Array(n).fill(0).map(() => pick.int());

const l = [0];
for (let i = 0; i < n; ++i) {
  l.push(gcd(l[i], a[i]));
}
const r = [0];
for (let i = 0; i < n; ++i) {
  r.push(gcd(r[i], a[n - i - 1]));
}

let max = 0;
for (let i = 0; i < n; ++i) {
  const v = gcd(l[i], r[n - i - 1]);
  if (v > max) max = v;
}

console.log(max);


Measured memory_bytes: 29708
import sys

s = input()
kisu = ['R','U','D']
gusu = ['L','U','D']
for i in range(len(s)):
    if(i%2==0):
        if not(s[i] in kisu):
            print('No')
            sys.exit()
    else:
        if not(s[i] in gusu):
            print('No')
            sys.exit()
print('Yes')

Measured memory_bytes: 3060
#include <iostream>
#include <vector>
#include <string>
#include <deque>

using namespace std;

int main(){
    int H, W;
    while(cin >> H >> W){
        vector<string> vs(H);
        for(auto& s : vs) cin >> s;
        deque<pair<int,int>> qu;
        qu.emplace_front(0, 0);
        vector<vector<int>> dist(H, vector<int>(W, H*W+1));
        dist[0][0] = (vs[0][0] == '.' ? 0 : 1);
        while(!qu.empty()){
            auto pos = qu.front(); qu.pop_front();
            int dx[] = {0, 1};
            int dy[] = {1, 0};
            int x = pos.first;
            int y = pos.second;
            for(int i=0;i<2;i++){
                int nx = x + dx[i];
                int ny = y + dy[i];
                if(nx >= H || ny >= W) continue;
                int add = (vs[x][y] == '.' && vs[nx][ny] == '#' ? 1 : 0);
                int nc = dist[x][y] + add;
                if(nc < dist[nx][ny]){
                    dist[nx][ny] = nc;
                    if(add) qu.emplace_back(nx, ny);
                    else qu.emplace_front(nx, ny);
                }
            }
        }
        cout << dist[H-1][W-1] << endl;
    }
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <queue>
#include <vector>
#include <set>
#include <map>
#include <numeric>

using namespace std;


int main(){
    int n;
    string s;
    cin>>n>>s;
    int ans=0;
    for(int i=1;i<n;i++){
        int cnt=0;
        vector<bool> x(26),y(26);
        for(int j=0;j<i;j++)x[s[j]-'a'] =true;
        for(int j=i;j<n;j++)y[s[j]-'a'] =true;
        for(int j=0;j<26;j++){
            if(x[j] && y[j])cnt++;
        }
        ans=max(ans,cnt);
    }
    cout<<ans<<endl;
}

   


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        @SuppressWarnings("resource")
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();
        System.out.println(Math.max(0, c - (a - b)) );
    }

}


Measured memory_bytes: 23764
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a) for(int i = 0; i < (a); i++)
#define ALL(a) (a).begin(),(a).end()
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1e9;
const long long LINF = 1e18;
const long long MOD = 1e9 + 7;

signed main(){
    string s;
    int w;
    cin >> s;
    cin >> w;
    string ans;
    int n = s.size();
    REP(i,n){
        if(i % w == 0) ans.push_back(s[i]);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<cmath>
#include<cstdio>
#include<algorithm>
using namespace std;
const int MAXN=100005;
int N,H[MAXN];
int main(){
	scanf("%d",&N);
	for(int i=1;i<=N;i++)
		scanf("%d",&H[i]);
	for(int i=1;i<=N;i++){
		if(H[i-1]+1<=H[i])H[i]--;
		else if(H[i-1]>H[i]){
			printf("No\n");
			return 0;
		}
	}
	printf("Yes\n");
}

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

class Program {
    static void Main() {
        Scanner cin = new Scanner();
        int N = cin.Int();
        long x = cin.Long();
        var a = cin.ArrayLong(N);

        long ans = 0;
        for (int i = 0; i < N - 1; i++) {
            if(a[i] + a[i + 1] > x) {
                ans += a[i] + a[i + 1] - x;
                if(a[i + 1] >= a[i] + a[i + 1] - x) a[i + 1] -= a[i] + a[i + 1] - x;
                else {
                    a[i + 1] = 0;
                    a[i] -= a[i] - x;
                }
            }
        }

        Console.WriteLine(ans);
        Console.ReadLine();
    }
}

class Scanner //標準入力
{
    string[] s;
    int i;

    char[] cs = new char[] { ' ' };

    public Scanner()
    {
        s = new string[0];
        i = 0;
    }

    public string next()
    {
        if (i < s.Length) return s[i++];
        string st = Console.ReadLine();
        while (st == "") st = Console.ReadLine();
        s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
        if (s.Length == 0) return next();
        i = 0;
        return s[i++];
    }

    public int Int()
    {
        return int.Parse(next());
    }
    public int[] ArrayInt(int N, int add = 0)
    {
        int[] Array = new int[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = Int() + add;
        }
        return Array;
    }

    public long Long()
    {
        return long.Parse(next());
    }

    public long[] ArrayLong(int N, long add = 0)
    {
        long[] Array = new long[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = Long() + add;
        }
        return Array;
    }

    public double Double()
    {
        return double.Parse(next());
    }


    public double[] ArrayDouble(int N, double add = 0)
    {
        double[] Array = new double[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = Double() + add;
        }
        return Array;
    }
}


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

int main(){
  // Inputs
  int N, M, X;
  std::cin >> N >> M >> X;
  int* C = new int[N];
  int* A = new int[N*M];
  for (int n=0; n < N; n++){
    std::cin >> C[n];
    for (int m=0; m < M; m++){
      std::cin >> A[M*n + m];
    }
  }
  //Combination
  int min_cost = 1e+5 * 12+1;
  //Enumerate all patterns
  for (int bit=0; bit < (1<<N); bit++){     
    int cost = 0;
    bool OK = true;//if all algorithm can be learned sufficiently
    //Enumerate all algorithm
    for (int m=0; m<M; m++){
      int sum_An = 0;
      for (int n=0; n<N; n++){
        if (bit & (1<<n)) sum_An += A[M*n + m];
      }
      OK &= (sum_An >= X);
    }
    //Compute costs 
    if (OK==true){
      for (int n=0; n<N; n++){
        if (bit & (1<<n)) cost += C[n];
      }
      min_cost = std::min(min_cost, cost);
    }
  }
  if (min_cost < (1e+5)*12+1)//if updated
    std::cout << min_cost << std::endl;
  else
    std::cout << -1 << std::endl;
  delete C;
  delete A;
  return 0; 
}


Measured memory_bytes: 3640
#from statistics import median
#import collections
#aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
from fractions import gcd
from itertools import combinations,permutations,accumulate # (string,3) 3回
#from collections import deque
from collections import deque,defaultdict,Counter
import decimal
import re
#import bisect
#
#    d = m - k[i] - k[j]
#    if kk[bisect.bisect_right(kk,d) - 1] == d:
#
#
#
# pythonで無理なときは、pypyでやると正解するかも！！
#
#
# my_round_int = lambda x:np.round((x*2 + 1)//2)
# 四捨五入
import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7
#mod = 9982443453
def readInts():
  return list(map(int,input().split()))
def I():
  return int(input())
n,m = readInts()
def yaku(m):
        ans = []
        i = 1
        while i*i <= m:
            if m % i == 0:
                j = m // i
                ans.append(i)
                if j != i:
                    ans.append(j)
            i += 1
        ans = sorted(ans)
        return ans
a = yaku(m)
for i in range(len(a)):
    if n*a[i] <= m:
        ans = a[i]
    else:
        break
print(ans)


Measured memory_bytes: 10340
A, B, K = map(int, input().split())
X = []

for x in range(K):
    if B >= A+x or B-x >= A:
        X.append(A+x)
        X.append(B-x)

sortX = sorted(set(X))
# print(" ".join(sortX))
for x in sortX:
    print(x)


Measured memory_bytes: 3060
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        #[warn(unused_mut)]
        let mut s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input!{
        n:usize, k:i64, q:usize,
        a:[i64; n]
    };
    let ia = a.iter().enumerate().collect::<Vec<(usize, &i64)>>();
    let mut ord = ia.clone();
    ord.sort_by_key(|&(_, ai)| ai);
    let mut res = 100_000_000_000_000_000;
    for i in 0..n + 1 {
        let mut r = ord[0..i].iter().map(|&(i, _)| i).collect::<Vec<usize>>();
        r.sort();
        let sp = ia.split(|&(i, _)| r.binary_search(&i).is_ok());
        let sp = sp.map(|x| x.iter().map(|&(_, &ai)| ai));
        let mut aq = sp
            .flat_map(|x| {
                let mut s: Vec<i64> = x.collect();
                s.sort();
                let m = s.len() as i64 + 1 - k;
                let m = if m < 0 { 0 } else { m as usize };
                s[0..m].to_vec()
            }).collect::<Vec<i64>>();
        if aq.len() < q {
            break;
        }
        aq.sort();
        let r = aq[q - 1] - aq[0];
        if r < res {
            res = r
        };
    }
    println!("{}", res);
}


Measured memory_bytes: 4352
#include<stdio.h>
#include<stdlib.h>
#include<iostream>
#include<string>
#include<algorithm>
#include<vector> 
#include<limits>
#include<numeric>
#include<type_traits>
#include<math.h>
using namespace std;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repi(i,a,b) for(int i = (int)(a); i < (int)(b); i++)
#define in(x) cin >> x
#define out(str) cout << str << endl

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; }

string S;
int ans=0;

int main(){
    cin>>S;
    rep(i,4){
        if(S[i]=='+'){
            ans++;
        }
        else ans--;
    }
    out(ans);
}


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

int main() {
  int N;
  cin >> N;
  vector<int> numList(N);
  for (int i=0; i<N; i++){
    cin >> numList.at(i);
  }

  sort(numList.begin(), numList.end());
  
  int point = 0;
  for (int i=N-1; i>=0; i--){
    if (i % 2 != N % 2) {
      point += numList.at(i);
    } else {
      point -= numList.at(i);
    }
  }
  cout << point << endl;
}

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

int main() {
    int n;
    cin >> n;
    int a[n];
    int min = std::numeric_limits<int>::max();
    int max = std::numeric_limits<int>::min();
    for (int i=0; i<n;++i) {
        cin >> a[i];
        a[i] = abs(a[i]);
        if (min > a[i]) min = a[i];
        if (max < a[i]) max = a[i];
    }

    cout << max - min << endl;
    return 0;
}

Measured memory_bytes: 384
#pragma GCC optimize("Ofast,unroll-loops,no-stack-protector,fast-math")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//#pragma comment(linker, "/stack:200000000")

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pdd;

#define X first
#define Y second

//#include <boost/unordered_map.hpp>
//using namespace boost;

/*
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> rbtree;
rbtree T;
*/

namespace io{
	const int L = (1 << 20) + 1;

	char buf[L], *S , *T, c;

	char getchar() {
		if(__builtin_expect(S == T, 0)) {
			T = (S = buf) + fread(buf, 1, L, stdin);
			return (S == T ? EOF : *S++);
		}
		return *S++;
	}

	int inp() {
		int x = 0, f = 1; char ch;
		for(ch = getchar(); !isdigit(ch); ch = getchar())
			if(ch == '-') f = -1;
		for(; isdigit(ch); x = x * 10 + ch - '0', ch = getchar());
		return x * f;
	}

	unsigned inpu()
	{
		unsigned x = 0; char ch;
		for(ch = getchar(); !isdigit(ch); ch = getchar());
		for(; isdigit(ch); x = x * 10 + ch - '0', ch = getchar());
		return x;
	}

	ll inp_ll() {
		ll x = 0; int f = 1; char ch;
		for(ch = getchar(); !isdigit(ch); ch = getchar())
			if(ch == '-') f = -1;
		for(; isdigit(ch); x = x * 10 + ch - '0', ch = getchar());
		return x * f;
	}

	char B[45], *outs=B+40, *outr=B+40;
	template<class T>
	inline void print(register T a,register char x=0){
		if(x) *--outs = x, x = 0;

		if(!a)*--outs = '0';
		else
			while(a)
				*--outs = (a % 10) + 48, a /= 10;

		if(x)
			*--outs = x;

		fwrite(outs, outr - outs , 1, stdout);
		outs = outr;
	}
};

using io :: print;
using io :: inp;
using io :: inpu;
using io :: inp_ll;

using i32 = int;
using i64 = long long;
using u8 = unsigned char;
using u32 = unsigned;
using u64 = unsigned long long;
using f64 = double;
using f80 = long double;
//using i128 = __int128_t;
//using u128 = __uint128_t;
using i128 = i64;
using u128 = u64;

ll power(ll a, ll b, ll p)
{
	if (!b) return 1;
	ll t = power(a, b/2, p);
	t = t*t%p;
	if (b&1) t = t*a%p;
	return t;
}

ll exgcd(ll a, ll b, ll &x, ll &y)
{
	if (b == 0)
	{
		x = 1;
		y = 0;
		return a;
	}
	ll px, py;
	ll d = exgcd(b, a%b, px, py);
	x = py;
	y = px-a/b*py;
	return d;
}

template<class T>
inline void freshmin(T &a, const T &b)
{
	if (a > b) a = b;
}

template<class T>
inline void freshmax(T &a, const T &b)
{
	if (a < b) a = b;
}

const int MOD = 1000000007;
const int INF = 1000000000;
const int MAXN = 100010;

int main()
{
	
	string s;
	cin >> s;
	puts(s[0] == s[1] || s[1] == s[2] || s[2] == s[3] ? "Bad" : "Good");
	
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
	string s,t;
	getline(cin,s);
	getline(cin,t);
	int flag=1;
	for(int i=0;i<s.size();i++)
	{
		if(s[i]!=t[i])
		{
			flag=0;
			break;
		}
	}
	if(s.size()+1!=t.size())flag=0;
	if(flag)cout<<"Yes";
	else cout<<"No";
 } 

Measured memory_bytes: 3620
#include <bits/stdc++.h>
#define ios ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define debug  freopen("in.txt","r",stdin),freopen("out.txt","w",stdout);
#define pb push_back
#define all(x) x.begin(),x.end()
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int maxn = 1e6+10;
const int maxM = 1e6+10;
const int inf = 0x3f3f3f3f;

int N,K;
int a[maxn];

bool judge(double x){
	ll cnt = 0;
	for(int i =1;i<=N;i++){
		cnt += ceil(a[i]/x)-1;
	}
	return cnt<=K;
}
void solve(){
	double l = 1,r = 1e9+10;
	for(int i = 1;i<=50;i++){
		double mid = (l+r)/2;
		if(judge(mid)) r = mid;
		else l = mid;
	}
	int ans = ceil(l);
	cout<<ans<<'\n';
}
int main(){
	// debug;
	ios;

	cin>>N>>K;
	for(int i =1;i<=N;i++) cin>>a[i];
	solve();
	
	return 0;
}


Measured memory_bytes: 4448
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <deque>
#include <fstream>
#include <functional>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <vector>
using namespace std;
using ll = long long;
#define fst first
#define snd second

/* clang-format off */
template <class T, size_t D> struct _vec { using type = vector<typename _vec<T, D - 1>::type>; };
template <class T> struct _vec<T, 0> { using type = T; };
template <class T, size_t D> using vec = typename _vec<T, D>::type;
template <class T> vector<T> make_v(size_t size, const T& init) { return vector<T>(size, init); }
template <class... Ts> auto make_v(size_t size, Ts... rest) { return vector<decltype(make_v(rest...))>(size, make_v(rest...)); }
template <class T> inline void chmin(T &a, const T& b) { if (b < a) a = b; }
template <class T> inline void chmax(T &a, const T& b) { if (b > a) a = b; }
/* clang-format on */

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

int main() {
#ifdef DEBUG
  ifstream cin("in.txt");
#endif
  int N;
  while (cin >> N) {
    ll g = 0;
    for (int i = 0; i < N; i++) {
      ll A;
      cin >> A;
      g = gcd(g, A);
    }
    cout << g << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<vector>
#include<queue>
#define Lens 100005
#define Nil -1

using namespace std;
int n, m, q;
queue<int> Q;
vector<int> A[Lens];
int c[Lens], d[Lens];

void bns(int k, int v)
{
	Q.push(k);
	c[k] = v;
	while (!Q.empty())
	{
		k = Q.front();
		Q.pop();
		c[k] = v;
		for (int i = 0; i < A[k].size(); i++)
		{
			int tmp = A[k][i];
			if (c[tmp] == Nil)
			{
				Q.push(tmp);
			}
		}
	}
}

int main()
{
	int v = 1;
	cin >> n >> m;
	for (int i = 0; i < m; i++)
	{
		int s, t;
		cin >> s >> t;
		c[s] = c[t] = Nil;
		A[s].push_back(t);
		A[t].push_back(s);
	}
	for (int i = 0; i < n; i++)
	{
		if (c[i] == Nil)
		{
			bns(i, v);
			v++;
		}

	}
	cin >> q;
	for (int i = 0; i < q; i++)
	{
		int s, t;
		cin >> s >> t;

		if (c[s] == c[t]&&c[s]!=Nil&&c[s]!=0)
			cout << "yes" << endl;
		else
			cout << "no" << endl;
	}
	return 0;
}



Measured memory_bytes: 8888
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int INF = INT32_MAX;
const ll INFL = INT64_MAX;
const int mod = 1e9 + 7;

template <typename T>
void print_vec(vector<T> v) {
  for (T i : v) cout << i << " ";
  cout << endl;
}

int main() {
  double n, k;
  cin >> n >> k;
  vector<int> num(18);
  num[0] = 1;
  rep(i, 17) num[i + 1] = num[i] * 2;
  double ans = 0;
  rep(i, n) {
    int j = i + 1;
    int num_a = lower_bound(num.begin(), num.end(), k / j) - num.begin();
    ans += 1.0 / n * pow(0.5, num_a);
  }
  printf("%.10f\n", ans);
  return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main()
{
    int n,x=1,a=0;
    int i = 1;
    scanf("%d",&n);

    do{
        x = i;
        if (x % 3 == 0){
            printf(" %d",i);
            a = 1;
        }
        if (a==0){
            do{
                if (x % 10 == 3){
                	printf(" %d",i);
                    break;
                }
                x /= 10;

            } while (x);
        }
        else{
            a = 0;
        }
    } while (++i<=n);
    printf("\n");
    return 0;
}



Measured memory_bytes: 2684
#include <algorithm>
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define ll long long
#define INF 1000000000000000000

vector<pair<ll, ll>> prime_factorize(ll N) {
    vector<pair<ll, ll>> res;
    for (ll a = 2; a * a <= N; a++) {
        if (N % a != 0)
            continue;
        ll ex = 0;
        while (N % a == 0) {
            ++ex;
            N /= a;
        }

        res.push_back({a, ex});
    }
    if (N != 1)
        res.push_back({N, 1});
    return res;
}

int main() {
    ll N, P;
    cin >> N >> P;
    ll res = 1;
    vector<pair<ll, ll>> pv = prime_factorize(P);
    for (auto p : pv) {
        if (p.second >= N)
            rep(i, p.second / N) { res *= p.first; }
    }

    cout << res << endl;
}

Measured memory_bytes: 256
n = gets.chars
odd = []
even = []
n.each_with_index do |h, i|
  odd << h if (i + 1) % 2 != 0
  even << h if (i + 1) % 2 == 0
end
odd.include?('L') || even.include?('R') ? (puts 'No') : (puts 'Yes')


Measured memory_bytes: 1916
from collections import deque
n,Q = map(int,input().split())
ki = [[] for i in range(n)]
for _ in range(n-1):
    a,b = map(int,input().split())
    ki[a-1].append(b-1)
    ki[b-1].append(a-1)
q = deque()
cnt = [0] * n
for _ in range(Q):
    p,x = map(int,input().split())
    cnt[p-1] += x
vis = [-1] * n
q.append(0)
vis[0] = 1
while q:
    a = q.popleft()
    a_ = ki[a]
    for i in a_:
        if vis[i] == -1:
            q.append(i)
            vis[i] = 1
            cnt[i] += cnt[a]
print(*cnt)

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

int main(void){
    int x ;
    cin >> x ;
    while(1){
        for (int i=2; i<=x; i++){
            if (i==x){
                cout << x <<endl ;
                return 0 ;
            } else  if (x%i==0){
                break ;
            }
        }
        x++ ;
    }
}

Measured memory_bytes: 256
import sys


def len_lcs(s1, s2):
    """Find length of the longest common sequence(LCS) of strings s1 and s2.
    The complexity is ~MN.

    >>> len_lcs("abc", "abc")
    3
    >>> len_lcs("abcbdaba", "bdcaba")
    5
    """
    results = [0] * len(s1)

    for i, c2 in enumerate(s2):
        sec1, pr1 = 0, 0
        for j, c1 in enumerate(s1):
            pr2 = results[j]
            if c1 == c2:
                mval = pr1 + 1
            elif sec1 > pr2:
                mval = sec1
            else:
                mval = pr2

            results[j] = mval
            sec1, pr1 = mval, pr2

    return results[-1]


def run():
    n = int(input())
    s = []
    for line in sys.stdin:
        s.append(line.strip())
    for i in range(0, 2*n, 2):
        print(len_lcs(s[i], s[i+1]))

run()


Measured memory_bytes: 5644
#include<stdio.h>
int main(){
  int P,Q,R;
  scanf("%d %d %d",&P,&Q,&R);

  if(P+Q < Q+R){
    if(P+R <P+Q)
      printf("%d\n",P+R);
    else
      printf("%d\n",P+Q);
  }else{
    if(P+R <Q+R)
      printf("%d\n",P+R);
    else
      printf("%d\n",Q+R);
  }
  return 0;
}

Measured memory_bytes: 128
import sys
sys.setrecursionlimit(10**5)

H, W, D = map(int, input().split())
A = [[int(i) - 1 for i in input().split()] for _ in range(H)]
Q = int(input())
LR = [[int(i) for i in input().split()] for _ in range(Q)]

place = [0] * (H * W)
for i in range(H) :
    for j in range(W) :
        place[A[i][j]] = (i, j)

cost = [0] * (H * W)
def dfs(i, px, py) :
    if i + D >= H * W :
        return 0
        
    cx, cy = place[i + D]
    cost[i] = dfs(i + D, cx, cy) + abs(cx - px) + abs(cy - py)
    return cost[i]
    
for i in range(D) :
    dfs(i, place[i][0], place[i][1])
    
for l, r in LR :
    print(cost[l-1] - cost[r-1])

Measured memory_bytes: 132700
#include<bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define forn(i,a,b) for(int i =a;i<b;i++)
#define fi first
#define se second
#define fast ios_base::sync_with_stdio(false);
using namespace std;

//for debugging 
/*
g++ -D_GLIBCXX_ASSERTIONS -DDEBUG -ggdb3 -std=c++14 
*/
int recur_depth = 0;
#ifdef DEBUG
#define dbg(x) {++recur_depth; auto x_=x; --recur_depth; cerr<<string(recur_depth, '\t')<<"\e[91m"<<__func__<<":"<<__LINE__<<"\t"<<#x<<" = "<<x_<<"\e[39m"<<endl;}
#else
#define dbg(x)
#endif
template<typename Ostream, typename Cont>
typename enable_if<is_same<Ostream,ostream>::value, Ostream&>::type operator<<(Ostream& os,  const Cont& v){
	os<<"[";
	for(auto& x:v){os<<x<<", ";}
	return os<<"]";
}
template<typename Ostream, typename ...Ts>
Ostream& operator<<(Ostream& os,  const pair<Ts...>& p){
	return os<<"{"<<p.first<<", "<<p.second<<"}";
}
// debugging ends here

typedef long long int ll;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const int modi = 1e9+7;
void add_self(int &a, int b){
	a+=b;
	if(a>=modi)
		a-=modi;
}

	

void solve(){
	int s;
	cin >> s;
	// int n = (s+3-1)/3;
	// int dp[s+1];
	// memset(dp,0,sizeof(dp));
	// for()
	// memset(dp,0,sizeof(dp));
	vi dp(s+1,0);
	dp[0] = 1;
	for(int i =3;i<=s;i++){
		for(int j = 3;j<=s;j++){
			if(i-j>=0)
				add_self(dp[i],dp[i-j]);
		}
		// dbg(dp);

	}
	cout << dp[s] << endl;

}

int main(){
	fast;
	#ifndef ONLINE_JUDGE
		freopen("input.txt","r",stdin);
		freopen("output.txt","w",stdout);
	#endif

	// int t;cin >> t;while(t--)
		solve();
}


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

int main()
{
	int k,n,y;
	cin>>n>>y;
	for (int i=0; i<=y/10000; i++)
	{
		for (int j=0; j<=y/5000; j++)
			{
				k=n-i-j;
				if(k>=0 && i*10000+j*5000+k*1000==y)
				{
					cout<<i<<' '<<j<<' '<<k;
					return 0;
				}
			}	
	}
		
	cout<<"-1 "<<"-1 "<<"-1";
	return 0;
}

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

int main(){
  string S;
  cin >> S;
  int D=S.size();
  bool A=true;
  if(S.at(0)!='A'){
    A=false;
  }
  int count=0;
  for(int i=2;i<D-1;i++){
    if(S.at(i)=='C'){
      count++;
    }
  }
  if(count!=1){
    A=false;
  }
  count=0;
  for(int i=0;i<D;i++){
    if(isupper(S.at(i))){
      count++;
    }
  }
  if(count!=2){
    A=false;
  }
  if(A){
    cout << "AC" << endl;
  }
  else{
    cout << "WA" << endl;
  }
}

Measured memory_bytes: 3632
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
#include <cmath>
#include <stdio.h>
#include <list>
#include <numeric>
#include <stack>
#include <queue>
#include <tuple>
#include <bitset>
#include <map>
#include <math.h>
//　ceil(a/b)   (a + (b - 1))/ b
using namespace std;
#define rep(i,n) for(int i = 0; i < (n); i++)
typedef long long ll;
typedef pair<int,int> P;
const int inf=1000000007;
const int mod=1000000007;
const double PI=3.14159265358979323846;
int dx[] = {1,-1,0,0};
int dy[] = {0,0,1,-1};

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


// ll memo[2020][2020];
// int pascal_triangle(){
//   for(int i = 0; i < 2020; i++){
//     for(int j = 0; j < i+1; j++){
//       if(j == 0 || j == i) memo[i][j] = 1;
//       else{
// 	memo[i][j] = (memo[i-1][j-1]+memo[i-1][j]);
//       }
//     }
//   }
//   return 0;
// }


int factorial(int n){
  if(n == 0) return 1;
  return n*factorial(n-1);
}

int divisor(int a){
  int cnt = 0;
  for(int i=1; i <= a; i++) if(a%i == 0) cnt++;
  return cnt;
}

int comb(int n, int k){
  return factorial(n) / (factorial(n-k)*factorial(k));
}

int cans(bool f){
  if(f) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}



int main(){
  int N;
  cin >> N;
  vector<pair<double,double>> v;
  int array[] = {0,1,2,3,4,5,6,7};
  rep(i,N){
    double a,b;
    cin >> a >> b;
    v.push_back(make_pair(a,b));
  }
  double ans = 0;
  do{
    double ave = 0;
    for(int i = 1; i < N; i++){
      ave += sqrt(pow((v[array[i]].first - v[array[i-1]].first),2)+pow((v[array[i]].second - v[array[i-1]].second),2));
    }
    ans += ave;
  }while(next_permutation(array,array+N));
  ans /= factorial(N);
  printf("%.12lf\n",ans);
}




Measured memory_bytes: 256
// モジャさんの写経
#include <bits/stdc++.h>

using namespace std;
using ll =long long;
#define For(i, a, b)    for(int i = (a) ; i < (b) ; ++i)
#define rep(i, n)       For(i, 0, n)
#define debug(x)  cerr << #x << " = " << (x) << endl;
#define leftunique(a) {sort((a).begin(),(a).end());(a).erase(unique((a).begin(),(a).end()),(a).end());}
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
static const ll INF = 1LL << 60;
//Write From this Line

int main()
{
	int k, n;
	cin >> k >> n;
	vector<int> a(n);
	rep(i, n) cin >> a[i];
	int mx = 0;
	rep(i, n - 1) {
		mx = max(mx, a[i + 1] - a[i]);
	}
	mx = max(mx,a[0] + k - a[n - 1]);
	cout << k - mx << endl; // わざわざ a[i+1]-a[i]の和を求めなくても、kからmxを引くだけでいい　
}


Measured memory_bytes: 1024
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <algorithm>
using namespace std;
typedef long long LL;

LL A, B, C;

bool Check(LL A, LL B, LL C)
{
	if (A & 1) return true;
	if (B & 1) return true;
	if (C & 1) return true;
	return false;
}

int main()
{
	while (~scanf("%lld%lld%lld", &A, &B, &C)) {
		if (Check(A, B, C)) printf("0\n");
		else {
			int ans = -1;
			for (int i = 1; i <= 1000000; i++) {
				LL pA, pB, pC;
				pA = (B + C) / 2;
				pB = (A + C) / 2;
				pC = (A + B) / 2;
				A = pA; B = pB; C = pC;
				if (Check(A, B, C)) {
					ans = i;
					break;
				}
			}
			printf("%d\n", ans);
		}
	}
	return 0;
}

Measured memory_bytes: 128
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# 問題：https://atcoder.jp/contests/abc126/tasks/abc133_c

l, r = map(int, input().strip().split())

res = 2019

if r - l >= 2019 or r % 2019 < l % 2019:
    res = 0
else:
    for i in range(l, r+1):
        for j in range(l, i):
            x = i % 2019
            y = j % 2019
            z = (x * y) % 2019
            if z < res:
                res = z

print(res)


Measured memory_bytes: 9176
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main(){
    long long N, a;
    cin >> N;
    long long minLimit;
    vector<long long> limit(5);
    for(int i = 0; i < 5; i++){
        cin >> a;
        limit[i] = a;
    }
    minLimit = *min_element(limit.begin(), limit.end());

    long long ans = 0;
    long long teamNum = N/minLimit;
    if(N%minLimit != 0) teamNum += 1;
    if(minLimit >= N)
        teamNum = 1;
    ans += teamNum+4;
    cout << ans << endl;

    

    return 0;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <complex>
#include <string>
#include <vector>
#include <array>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
#include <iterator>
#include <memory>
#include <regex>
using namespace std;

int main()
{
    vector<int> cnt(5);
    for(int i=0; i<6; ++i){
        int a;
        cin >> a;
        ++ cnt[a];
    }

    if(*max_element(cnt.begin(), cnt.end()) <= 2)
        cout << "YES" << endl;
    else
        cout << "NO" << endl;

    return 0;
}


Measured memory_bytes: 256
def selection_sort(numbers, n):
    """selection sort method

    Args:
        numbers: a list of numbers to be sorted
        n: len(numbers)

    Returns:
        sorted numberd, number of swapped times
    """
    counter = 0
    for i in range(0, n - 1):
        min_j = i
        for j in range(i + 1, n):
            if numbers[j] < numbers[min_j]:
                min_j = j
        if min_j != i:
            numbers[min_j], numbers[i] = numbers[i], numbers[min_j]
            counter += 1
    return numbers, counter


length = int(raw_input())
numbers = [int(x) for x in raw_input().split()]

numbers, number_of_swapped_times = selection_sort(numbers, length)
print(" ".join([str(x) for x in numbers]))
print(number_of_swapped_times)

Measured memory_bytes: 6436
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <unordered_map>

using namespace std;
using ll = long long;

void _cin(){} template <class Head, class... Tail> void _cin(Head&& head, Tail&&... tail){ cin >> head; _cin(forward<Tail>(tail)...); }
void _cout(){ cout << "\n"; } template <class Head, class... Tail> void _cout(Head&& head, Tail&&... tail){ cout << head; _cout(forward<Tail>(tail)...); }
int gcd(int a, int b){ return (b == 0) ? a : gcd(b, a % b); }

#define Sq(x) (x)*(x)
#define For(i, n) for(int i = 0; i < (n); i ++)
#define Rep(n) For(_, n)
#define Range(c) c.begin(), c.end()
#define RevRange(c) c.rbegin(), c.rend()
#define Contains(c, x) (find(Range(c), x) != c.end())
#define Search(rb, re, x) distance(rb, find(rb, re, x))
#define Sort(a) sort(Range(a))
#define DeSort(a) sort(RevRange(a))
#define Reverse(c) reverse(Range(c))
#define Unique(a) a.erase(unique(Range(a)), a.end())
#define Cusum(T, xs, sxs) vector<T> sxs(xs.size()+1); For(i, (int)xs.size()) sxs[i+1] = sxs[i] + xs[i]
#define Cin(T, ...) T __VA_ARGS__; _cin(__VA_ARGS__)
#define Cins(T, n, xs) vector<T> xs(n); For(i, n) cin >> xs[i]
#define Cins2(T, n, xs, ys) vector<T> xs(n), ys(n); For(i, n) cin >> xs[i] >> ys[i]
#define Cins3(T, n, xs, ys, zs) vector<T> xs(n), ys(n), zs(n); For(i, n) cin >> xs[i] >> ys[i] >> zs[i]
#define Cinss(T, n, m, xs) Vec2(T, n, m, xs); For(i, n) For(j, m) cin >> xs[i][j]
#define Cinm(T, n, map) unordered_map<T, int> map; Rep(n){ Cin(T, x); map[x] ++; }
#define Cout(...) _cout(__VA_ARGS__)
#define Couts(xs) { for(const auto &e : xs) cout << e << " "; cout << "\n"; }
#define Coutyn(cond) Cout((cond) ? "yes" : "no")
#define CoutYn(cond) Cout((cond) ? "Yes" : "No")
#define CoutYN(cond) Cout((cond) ? "YES" : "NO")
#define vc vector
#define Mini(a, x) a = min(a, x)
#define Maxi(a, x) a = max(a, x)

// constexpr int MOD = 1e9+7;
#include <queue>

int main(void){
    Cin(int, n);
    Cins(int, n, a);
    auto b = a;
    DeSort(b);
    
    For(i, n){
        Cout(a[i] == b[0] ? b[1] : b[0]);
    }
}





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

int main()
{
  string s;
  cin>>s;
  int a=0,b=1,a1=0,a2=0;
  for(auto i:s)
  {
    char c1=a?'1':'0';
    char c2 = b?'1':'0';
    if(c1!=i)
      a1++;
    if(c2!=i)
      a2++;
    a^=1;
    b^=1;
  }
  cout<<min(a1,a2);
  
  return 0;
}

Measured memory_bytes: 512
import java.util.Scanner;

public class Main {

	public static void main(String[] args) 
	{
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		
		long[] a = new long[n];
		for(int i = 0; i < n; i++)
			a[i] = sc.nextLong();
		
		long sum1 = 0; //start with neg
		long pay1 = 0;
		long last1 = 0;
		int sign1;
		long sum2 = 0; //start with neg
		long pay2 = 0;
		long last2 = 0;
		int sign2;
		
		for(int i = 0; i < n; i++)
		{
			sign1=i%2==0?-1:1;
			sign2=i%2==0?1:-1;
			long cur = a[i];
			//1
			{
				if(sign1 == -1 && sum1+cur >= 0)
				{
					pay1 += (sum1+cur) + 1;
					last1 = 1;
					sum1 = -1;
				}
				else if(sign1 == 1 && sum1+cur <= 0)
				{
					pay1 += 1 - (sum1+cur);
					sum1 = 1;
				}
				else
				{
					sum1 += cur;
				}
			}
			//2
			{
				if(sign2 == -1 && sum2+cur >= 0)
				{
					pay2 += (sum2+cur) + 1;
					last2 = 1;
					sum2 = -1;
				}
				else if(sign2 == 1 && sum2+cur <= 0)
				{
					pay2 += 1 - (sum2+cur);
					sum2 = 1;
				}
				else
				{
					sum2 += cur;
				}
			}
		}
		
		System.out.println(Math.min(pay1, pay2));
	}

}


Measured memory_bytes: 60724