akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

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

long long int lcm(long long int a, long long int b) {
    return a / gcd(a,b) * b;// divide first to avoid overflow
}

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

    vector<int> a(n);
    set<int> a_set;
    for(int i=0; i<n; i++){
        cin >> a[i];
        a[i] /= 2;
        a_set.insert(a[i]);
    }

    int ans = 0;
    int x = a[0];
    for(int i=1; i<n; i++){
        x = gcd(x, a[i]);
    }

    long long int y = 1;
    for(int z : a_set){
        y = lcm(y,z);
        if(y > m){
            cout << 0 << endl;
            return 0;
        }
    }

    bool flag = true;
    long long int first = y;
    for(int i=0; i<n; i++){
        if((first / a[i]) % 2 == 0) flag = false;
    }
    
    if(flag == false) cout << 0 << endl;
    if(flag == true) cout << 1 + (m - (int)y) / (2*y) << endl;
    return 0;
}

Measured memory_bytes: 640
def bfs(field, start_i, start_j, w, h):
    OFFSETS = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

    queue = [(start_i,start_j)]

    while len(queue) > 0:
        i, j = queue.pop()
        field[i][j] = "0"

        for di, dj in OFFSETS:
            if i+di < 0 or i+di >= h:
                continue
            if j+dj < 0 or j+dj >= w:
                continue
            if field[i+di][j+dj] == "1":
                queue.append((i+di, j+dj))


def main():
    while True:
        w, h = [int(s) for s in input().strip().split()]

        if w == 0 and h == 0:
            break

        num_island = 0
    
        field = []
        for _ in range(h):
            field.append(input().strip().split())
       
        #print(field) 
        for i in range(h):
            for j in range(w):
                if field[i][j] == "1":
                    num_island += 1
                    bfs(field, i, j, w, h)
        
        print(num_island)


if __name__ == "__main__":
    main()



Measured memory_bytes: 6040
#include<bits/stdc++.h>
using namespace std;
 
typedef long long int ll;
typedef unsigned long long int ull;
typedef long double ld;
#define f0(i,a,b) for(int i=a;i<b;i++)
#define f1(i,a,b) for(int i=a;i<=b;i++)
#define f2(i,a,b) for(int i=a;i>b;i--)
#define f3(i,a,b) for(int i=a;i>=b;i--)
#define pb push_back
#define mp make_pair
#define pii pair<int,int>
#define int long long
#define fi first
#define se second
#define mod 1000000007
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);


signed main(){
    fast

    int n;cin>>n;
    int a[n+5][3];
    f0(i,0,n) {cin>>a[i][0]>>a[i][1]>>a[i][2];}

    int dp[n+5][3]={{0}};
    
    dp[0][0]=a[0][0],dp[0][1]=a[0][1],dp[0][2]=a[0][2];
    f0(i,1,n){
        f0(j,0,3){
            dp[i][j]=max(dp[i-1][(j+1)%3]+a[i][j],dp[i-1][(j+2)%3]+a[i][j]);
        }
    }
    cout<<max(max(dp[n-1][0],dp[n-1][1]),dp[n-1][2]);
}

Measured memory_bytes: 4992
#include <iomanip>
#include <iostream>
using namespace std;
int main(void) {
  int n;
  cin >> n;
  int a[n];
  for(int i = 0; i < n; i++) {
    cin >> a[i];
  }
  for(int i = 0; i < n - 1; i++) {
    cout << a[n - i - 1] << " ";
  }
  cout << a[0] << endl;

  return 0;
}



Measured memory_bytes: 3040
N, U, V = gets.split.map(&:to_i)

E = Hash.new { |h, k| h[k] = [] }

(N - 1).times do
  a, b = gets.split.map(&:to_i)

  E[a] << b
  E[b] << a
end

aoki_min = Hash.new(Float::INFINITY)
queue = [[V, 0]]

until queue.empty?
  v, dist = queue.shift

  next if aoki_min[v] <= dist
  aoki_min[v] = dist

  E[v].each do |u|
    queue << [u, dist + 1]
  end
end

takahashi_min = Hash.new(Float::INFINITY)
queue = [[U, 0]]

until queue.empty?
  v, dist = queue.shift

  next if takahashi_min[v] <= dist
  takahashi_min[v] = dist

  E[v].each do |u|
    queue << [u, dist + 1]
  end
end

max_v = -1
max_d = -1

(1..N).each do |v|
  ad = aoki_min[v]
  td = takahashi_min[v]

  next if ad <= td

  if max_d < ad
    max_d = ad
  end
end

ans = max_d - 1

def f(x)
  a = 1
  b = x + 1
  cnt = 0

  loop do
    if a == 1
      a += 1
    else
      a -= 1
    end

    break if a == b

    b -= 1
    cnt += 1

    break if a == b
  end

  cnt
end

puts ans


Measured memory_bytes: 36252
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define square(x) pow(x 2.0)
#define all(x) (x).begin(),(x).end()
#define F first
#define S second
#define max_queue(x) priority_queue<x>
#define min_queue(x) priority_queue<x, vector<x>, greater<x>>
#define big_sort(v) sort(all(v), [](int a, int b) { return a > b; })//大きい順にソート
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vs = vector<string>;
#define co(x) cout << x << endl;
#define cins(n,v) rep(i,n){cin >> v.at(i);}
#define couts(v) rep(i,v.size()){cout << v.at(i) << endl;}
// aよりもbが大きいならばaをbで更新する
// (更新されたならばtrueを返す)
template <typename T>
bool chmax(T &a, const T& b) {
  if (a < b) {
    a = b;  // aをbで更新
    return true;
  }
  return false;
}
// aよりもbが小さいならばaをbで更新する
// (更新されたならばtrueを返す)
template <typename T>
bool chmin(T &a, const T& b) {
  if (a > b) {
    a = b;  // aをbで更新
    return true;
  }
  return false;
}
/*
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
*/
int main() {
  string t;
  cin >> t;
  rep(i,t.size()){
    if(t[i]=='?'){t[i]='D';}
    cout << t[i];
  }
  cout << endl;
  return 0;
}


Measured memory_bytes: 3648
//abc169_f.cpp
//Mon Jun  1 21:59:25 2020

#include <iostream>
#include <string>
#include <queue>
#include <map>
#include <unordered_map>
#include <vector>
#include <algorithm>
#include <math.h>
#include <set>
#define INTINF 2147483647
#define LLINF 9223372036854775807
#define MOD 998244353

using namespace std;
using ll=long long;
typedef pair<int,int> P;

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

	ll a[n];
	for (int i=0;i<n;i++){
		cin >> a[i];
	}

	ll dp[n+1][s+100];
	for (int i=0;i<n+1;i++){
		for (int j=0;j<s+100;j++){
			dp[i][j] = 0;
		}
	}

	dp[0][0] = 1;

	for (int i=1;i<n+1;i++){
		for (int j=0;j<s+100;j++){
			if (j-a[i-1]>=0){
				dp[i][j] = (dp[i][j]+dp[i-1][j-a[i-1]])%MOD;
				// cout << i << " " << j << " " << dp[i] << endl;
			}
			dp[i][j] = (dp[i][j]+dp[i-1][j]*2)%MOD;
		}
	}

	// for (int i=0;i<s+1;i++){
	// 	cout << dp[n][i] << endl;
	// }


	cout << dp[n][s] << endl;
//	printf("%.4f\n",ans);
}

Measured memory_bytes: 76276
n = gets.to_i
as = []
sums = [0]
gets.split(" ").each_with_index{|v, i|
  v = v.to_i
  as << v
  sums << sums[-1] + v
}

def get_sums(start_index, count, sums)
  return sums[start_index + count] - sums[start_index]
end

def adjust_dp(as, range_begin, range_count, current)
  ls = current[:ls]
  rs = current[:rs]
  dp = current[:dp]
  diff = (ls - rs).abs
  while(dp + 1 < range_begin + range_count)
    ni = dp + 1
    nls = ls + as[ni - 1]
    nrs = rs - as[ni - 1]
    ndiff = (nls - nrs).abs
    break if ndiff > diff
    dp = ni
    ls = nls
    rs = nrs
    diff = ndiff
  end

  return {
    :dp => dp,
    :ls => ls,
    :rs => rs
  }
end

def calc_diff(lp, rp)
  t = [lp[:ls], lp[:rs], rp[:ls], rp[:rs]].sort
  return (t.max - t.min).abs
end

lp = {
  :dp => 1,
  :ls => as[0],
  :rs => as[1],
}

rp = {
  :dp => 3,
  :ls => as[2],
  :rs => get_sums(3, n - 3, sums)
}

lps = Array.new(n)
rps = Array.new(n)
min = nil
(n - 3).times{|i|
  i += 2
  if i == 2
    lps[i] = adjust_dp(as, 0, i, lp)
    rps[i] = adjust_dp(as, i, n - i, rp)
    min = calc_diff(lps[i], rps[i])
  else
    lps[i] = adjust_dp(as, 0, i, {
      :ls => lps[i - 1][:ls],
      :rs => lps[i - 1][:rs] + as[i - 1],
      :dp => lps[i - 1][:dp],
    })
    rps[i] = adjust_dp(as, i, n - i, {
      :ls => rps[i - 1][:ls] - as[i - 1],
      :rs => rps[i - 1][:rs],
      :dp => rps[i - 1][:dp],
    })
    min = [min, calc_diff(lps[i], rps[i])].min
  end
}

puts min


Measured memory_bytes: 156196
import math

n = int(input())

t_, a_ = 1, 1
for i in range(n):
    t, a =[int(n) for n in input().split()]

    if t_ % t == 0:
        pt = 0
    else:
        pt = 1
    
    if a_ % a == 0:
        pa = 0
    else:
        pa = 1

    m = max((t_//t + pt), (a_//a + pa))
    t_, a_ = t * m, a * m
    
ans = t_ + a_
print(ans)

Measured memory_bytes: 3064
import Data.List

calc w h x y r
  | r <= x && x + r <= w &&
    r <= y && y + r <= h = "Yes"
  | otherwise = "No"

main = do
  s <- getLine
  let [w, h, x, y, r] = map read $ words s :: [Int]
  putStrLn $ calc w h x y r

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

typedef long long ll;
typedef pair<ll,ll> P;
typedef pair<P,ll> PLL;
typedef pair<P,P> PP;
typedef vector<ll> VECLL;
typedef vector<P> VECP;
typedef priority_queue<P,VECP,greater<P> > PQP;
typedef priority_queue<ll, VECLL, greater<ll> > PQll;

#define rep(i,a,n) for(ll i = a;i < n;i++)   
#define rrep(i,a,n) for(ll i = n; i >= a;i--)
#define index_check(i,n) if(i > n-1 || i < 0) continue; 
#define LINF (ll)1e18
#define INF (int)1e9
#define fs first
#define sc second



int main(){
    ll n;
    cin >> n;
    rep(i,1,3501){
        rep(j,1,3501){
            ll temp = 4*i*j-n*i-n*j;
            if( temp > 0){
                if(n*i*j % temp == 0){
                    cout << i << " " << j << " " << n*i*j/temp << endl;
                    return 0;
                }
            }
        }
    } 
}




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

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

// 参考
// http://drken1215.hatenablog.com/entry/2019/01/13/033500

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

	int N, Q;
	cin >> N >> Q;

	vector<ll> A(N);
	rep(i, N) cin >> A[i];
	reverse(A.begin(), A.end());

	vector<ll> sum(N+1), evensum(N+1);
	rep(i, N){
		sum[i+1] = sum[i] + A[i];
		evensum[i+1] = evensum[i] + (i % 2 == 0 ? A[i] : 0);
	}

	vector<ll> ths, vals;
	for(int i = 0; i < (N-1) / 2; i++){
		ll th = (A[i+1] + A[i*2 + 2]) / 2 + 1;
		ll val = (sum[i+1] - sum[0]) + (evensum[N] - evensum[i*2+2]);
		ths.push_back(th);
		vals.push_back(val);
	}

	reverse(ths.begin(), ths.end());
	reverse(vals.begin(), vals.end());

	rep(i, Q){
		ll x;
		cin >> x;

		int it = upper_bound(ths.begin(), ths.end(), x) - ths.begin();
		if(it == 0) cout << sum[(N+1) / 2] - sum[0] << endl;
		else cout << vals[it-1] << endl;
	}
}


Measured memory_bytes: 5108
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n);i++)
typedef long long ll;
//a % b >= K
// bを固定
int main(){
    ll N,K;
    cin >> N >> K;
    if(K == 0){
        cout << N*N << endl;
        return 0;
    }
    ll res = 0;
    for(int i = 1; i <= N; i++){
        if(i - 1 >= K ) {
            res += N/i*(i-K);
            res += max(0LL,(N%i) - K + 1);
        }
    }
    cout << res << endl;
    return 0;
}

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

int main(){
	ll n,m;
	cin>>n>>m;
	ll a[n],b[n];
	//vector<ll>ab[100001];
	vector<pair<ll, ll> > ab(n);
	for(ll i=0;i<n;i++)cin>>a[i]>>b[i];
	/*for(ll i=0;i<n;i++){
		ab[a[i]].push_back(b[i]);
	}
	for(int i=0;i<n;i++)sort(ab[a[i]].begin(),ab[a[i]].end());
	int buy=0;
	for(int i=0;i<100001;i++){

	}*/
	for(int i=0;i<n;i++){
		ab[i] = make_pair(a[i],b[i]);
	}
	sort(ab.begin(),ab.end());
	ll tmp=0;
	ll res=0;
	for(int i=0;i<n;i++){
		tmp+=ab[i].second;
		res+=(ab[i].first)*ab[i].second;
		if(m==tmp){
			break;
		}else if(tmp>m){
			res-=ab[i].first*(tmp-m);
			break;
		}
	}
	cout<<res<<endl;

	  /*for (int i = 0; i < n; i++) {
	    printf("(%d,%d) ", ab[i].first, ab[i].second);
	  }*/
}


Measured memory_bytes: 3328
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
class Program
{
    static void Main(string[] args)
    {
            // 入力
            string sS = Console.ReadLine().Trim();

            System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch();
            sw.Start();

            // 解析
            string sOut = "";
            for (int i = 0; i < sS.Length; i += 2)
            {
                sOut += sS.Substring(i, 1);
            }

            //出力
            Console.WriteLine("{0}", sOut.ToString().Trim());

            sw.Stop();
#if DEBUG
            Console.WriteLine();
            Console.WriteLine("{0}", sw.Elapsed.ToString());
            Console.WriteLine("続行するには何かキーを押してください．．．");
            Console.ReadKey();
#endif
    }
}


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

int main()
{
    using pr = pair<int, int>;
    int N;
    cin >> N;
    vector<vector<pr>> graph(N + 1);

    // 未探索...-1,白...偶数,黒...奇数
    vector<int> color(N + 1, -1);

    for (int i = 0; i < N - 1; i++)
    {
        int u, v, w;
        cin >> u >> v >> w;
        graph[u].push_back(make_pair(v, w));
        graph[v].push_back(make_pair(u, w));
    }

    color[1] = 0;
    queue<int> bfs;
    bfs.push(1);

    while (!bfs.empty())
    {
        int v = bfs.front();
        bfs.pop();
        for (auto x : graph[v])
        {
            // 未探索の場合
            if (color[x.first] == -1)
            {
                bfs.push(x.first);

                // 距離が偶数なら同じ色、奇数なら違う色
                if (x.second % 2 == 0)
                {
                    color[x.first] = color[v];
                }

                else
                {
                    color[x.first] = color[v] + 1;
                }
            }
        }
    }

    for (int i = 1; i <= N; i++)
    {
        cout << color[i] % 2 << endl;
    }
}

Measured memory_bytes: 6784
package main

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

func main() {
	sc := newInputScanner(true, 1024)
	N := sc.nextInt()
	A := make([]int, N)
	mapping := make(map[int]int)
	var number, count int
	var ok bool
	for i := 0; i < N; i++ {
		number = sc.nextInt()
		A[i] = number
		count, ok = mapping[number]
		if ok {
			mapping[number] = count + 1
		} else {
			mapping[number] = 1
		}
	}
	totalSum := 0
	for _, v := range mapping {
		if v > 1 {
			totalSum += v * (v - 1) / 2
		}
	}
	// fmt.Println(totalSum)
	currentAnswer := 0
	for _, n := range A {
		count = mapping[n]
		if count == 1 {
			currentAnswer = totalSum
		} else {
			currentAnswer = totalSum - (count - 1)
		}
		fmt.Println(currentAnswer)
	}
}

type inputScanner struct {
	*bufio.Scanner
}

func newInputScanner(enabledScanWords bool, sizeInKB int) *inputScanner {
	scanner := bufio.NewScanner(os.Stdin)
	if enabledScanWords {
		scanner.Split(bufio.ScanWords)
	}
	capacity := sizeInKB * 1024
	buf := make([]byte, capacity)
	scanner.Buffer(buf, capacity)
	return &inputScanner{
		Scanner: scanner,
	}
}

func (inputSc *inputScanner) nextInt() int {
	i, e := strconv.Atoi(inputSc.nextStr())
	if e != nil {
		panic(e)
	}
	return i
}

func (inputSc *inputScanner) nextUInt64() uint64 {
	i, e := strconv.ParseUint(inputSc.nextStr(), 10, 64)
	if e != nil {
		panic(e)
	}
	return i
}

func (inputSc *inputScanner) nextStr() string {
	inputSc.Scan()
	return inputSc.Text()
}

type debuggable struct {
}

const (
	DEBUG_ON = false
)

func (d *debuggable) debug(f func()) {
	if DEBUG_ON {
		f()
	}
}


Measured memory_bytes: 15744
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <stdio.h>
#include <sstream>
#include <math.h>
#include <map>
#include <set>
#include <ios>     // std::left, std::right
#include <iomanip> // std::setw(int), std::setfill(char)
using namespace std;


int main(){
  int A,B,C;
  cin>>A>>B>>C;
  if(A*C<=B){
    cout<<C<<"\n";
  }
  else{
    cout<<B/A<<"\n";
  }
return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<stdio.h>
#include<algorithm>
#include<math.h>
#include<numeric>
#include<iomanip>
#include<deque>
#include<tuple>
#include<queue>
#include<stack>
#include<map>
#include<cstdint>
#include<unordered_map>
#include<boost/multiprecision/cpp_int.hpp>


#define rep(i, n) for(int i = 0; i < ( int)(n); i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define vi vector<int>
#define vll vector<ll>
#define all(x) (x).begin(),(x).end()
#define F first
#define S second


namespace mp = boost::multiprecision;

using cpp_int = mp::cpp_int;
using ll = long long;
using namespace std;

std::vector<int> enum_div(int n)//nの約数を列挙
{
	std::vector<int> ret;
	for (int i = 1; i * i <= n; ++i)
	{
		if (n % i == 0)
		{
			ret.push_back(i);
			if ( i * i != n)
			{
				ret.push_back(n / i);
			}
		}
	}
	return ret;
}

int main() {
	int n;
	cin >> n;
	vector<int>a(n);
	rep(i, n) {
		cin >> a[i];
	}
	sort(all(a));

	int b = a[0];
	int c = a[1];
	deque<int>devisor;
	FOR(i,1, pow(b,0.5)+1) {
		if (b % i == 0) {
			devisor.push_back(i);
			devisor.push_back(b / i);

		}
	}
	FOR(i, 1, pow(c, 0.5) + 1) {
		if (c % i == 0) {
			devisor.push_back(i);
			devisor.push_back(c / i);
		}
	}
	sort(all(devisor));
	reverse(all(devisor));
	bool flag = true;
	int i = 0;
	int gcd = 1;

	while(flag) {
		int count = 0;
		//cout << devisor[i] << endl;
		rep(j, n) {
			if (a[j] % devisor[i] != 0) {
				count++;
			}
			if (count >= 2) {
				break;
			}
		}
		if (count <= 1) {
			gcd = max(gcd, devisor[i]);
			flag = false;
		}
		else {
			i++;
		}
	}
	cout << gcd << endl;

}


Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
using uint = unsigned int;
using ull = unsigned long long;

int main() {

	string S, T;
	cin >> S;
	cin >> T;

	vector<vector<uint>> dp(S.length() + 1, vector<uint>(T.length() + 1));

	for(uint i=0; i<S.length(); i++) {
		for(uint j=0; j<	T.length(); j++) {
			dp[i+1][j+1] = max(dp[i+1][j], dp[i][j+1]);
			dp[i+1][j+1] = (S[i]==T[j]) ? max(dp[i+1][j+1], dp[i][j] + 1) : dp[i+1][j+1];
			//cout << dp[i+1][j+1] << " ";
		}
		//cout << endl;
	}

	string ans = "";
	uint s = S.length();
	uint t = T.length();
	while(s > 0 && t > 0) {
		if(dp[s][t] == dp[s-1][t]) {
			s--;
		} else if(dp[s][t] == dp[s][t-1]) {
			t--;
		} else {
			ans += S[s-1];
			s--;
			t--;
		}
	}

	reverse(ans.begin(), ans.end());
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 35584
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <cstring>
using namespace std;

typedef pair<int,int>P;
typedef pair<P,int>PP;
#define Cost first.first
#define Pass first.second
#define Pos second





int main(){
	int n,m;
	while(cin>>n>>m,n){
		int cst[101][101];
		for(int i=0;i<=100;i++){
			for(int j=0;j<=100;j++){
				cst[i][j]=9999;
			}
		}
		vector<int>V[101];
		int flg[101][2]={0};
		
		priority_queue<PP , vector<PP>,greater<PP> >Q;
		Q.push(PP(P(0,1),1));
		
		for(int i=0;i<m;i++){
			int a,b,c;
			cin>>a>>b>>c;
			
			if(cst[a][b]==9999){
				cst[a][b]=cst[b][a]=c;
				V[a].push_back(b);
				V[b].push_back(a);
				
			}
			else{
				cst[a][b]=cst[b][a]=min(cst[a][b],c);
			}
		}
		
		while(!Q.empty()){
			PP p=Q.top();Q.pop();
			if(p.Pos==n){
				cout<<p.Cost<<endl;
				break;
			}
			if(flg[p.Pos][p.Pass]==1){
				continue;
			}
			flg[p.Pos][p.Pass]=1;
			for(int i=0;i<V[p.Pos].size();i++){
				if(flg[V[p.Pos][i]][p.Pass]==0){
					Q.push(PP(P(p.Cost+cst[p.Pos][V[p.Pos][i]],p.Pass),V[p.Pos][i]));
				}
				if(p.Pass){
					for(int j=0;j<V[V[p.Pos][i]].size();j++){
						if(flg[V[V[p.Pos][i]][j]][0]==0){
							Q.push(PP(P(p.Cost,0),V[V[p.Pos][i]][j]));
						}
					}
				}
			}
		}
		
		
	}
	
	return 0;
}


Measured memory_bytes: 1272
#include <bits/stdc++.h>
#define For(i,a,b) for(int i=a;i<=b;i++)
#define F first
#define S second
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;

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

int fpow(int b,int e)
{
	if(e==0) return 1;
	if(e==1) return b;
	int tmp=fpow(b,e/2);
	if(e%2) return b*tmp*tmp;
	else return tmp*tmp;
}

int fpowm(int b,int e,int mod)
{
	if(e==0) return 1;
	if(e==1) return b;
	int tmp=fpow(b,e/2)%mod;
	if(e%2) return b*tmp%mod*tmp%mod;
	else return tmp*tmp%mod;
}

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	
	int a,b,c;
	cin>>a>>b>>c;
	int n1=abs(a-b),n2=abs(b-c),n3=abs(c-a);
	cout<<(n1+n2+n3-max(n1,max(n2,n3)))<<"\n";
	return 0;
}








Measured memory_bytes: 256
S=input()
l=[]
for s in S:
  if not s in l:
    l.append(s)
if len(l) == 2:
  p = 2
  for s in S:
    if l[0] == s:
      p-=1
  if not p:
    print("Yes")
  else:
    print("No")
else:
  print("No")

Measured memory_bytes: 9132
#include<bits/stdc++.h>
using namespace std;
const int maxn=510;
int n,m,x[maxn][maxn];
int ou_t[maxn*maxn][4],cnt;
int main(){
    scanf("%d%d",&n,&m);
    for(register int i=1;i<=n;i++) for(register int j=1;j<=m;j++) scanf("%d",&x[i][j]);
    for(register int i=1;i<=n;i++) for(register int j=1;j<m;j++) if(x[i][j]&1){
        x[i][j]--;x[i][j+1]++;cnt++;
        ou_t[cnt][0]=ou_t[cnt][2]=i;
        ou_t[cnt][1]=j;ou_t[cnt][3]=j+1;
    }
    for(register int i=1;i<n;i++) if(x[i][m]&1){
        x[i][m]--;x[i+1][m]++;cnt++;
        ou_t[cnt][0]=i;ou_t[cnt][2]=i+1;
        ou_t[cnt][1]=m;ou_t[cnt][3]=m;
    }
    printf("%d\n",cnt);
    for(register int i=1;i<=cnt;i++) printf("%d %d %d %d\n",ou_t[i][0],ou_t[i][1],ou_t[i][2],ou_t[i][3]);
    return 0;
}

Measured memory_bytes: 7040
#include <bits/stdc++.h>
#define ALL(v) v.begin(), v.end()
#define MOD 1000000007
#define INF 1000000007
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define req(i, j, n) for(int i = j; i <= (int)(n); i++)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;

int main() {
 ll n;
  cin>>n;
  ll p[n+1];
  for(int i=1;i<=n;i++){
    cin>>p[i];}
  
  ll cnt=0;
  ll minv=1000000000;
  for(int i=1;i<=n;i++){
    if(minv>p[i]){
      cnt++;
      minv=p[i];}
  }
  
  cout<<cnt<<endl;


}

Measured memory_bytes: 1792
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <math.h>
#include <cmath>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <cassert>
#include <random>
#include <deque>
#include <bitset>
#include <string>
#include <queue>
#include <complex>
 
//#define int long long
 
#define mp(a, b) make_pair(a, b)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
 
#define endl '\n'
 
using namespace std;
typedef long long ll;
typedef long double ld;
 
mt19937 mrand(random_device{}());
 
double PI = acos((double)-1);
const ld eps = 1e-7;
const ll inf0 = 1023 * 1024 * 1024;
const ll inf = inf0 * inf0;
const ll mod = 1e9 + 7;
//const ll mod = 998244353;
 
void solve();
void scan();
 
signed main() {
#ifdef _DEBUG
	freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
#endif
	cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(false);
	cout << fixed; cout.precision(15);
	solve();
	return 0;
}

bool good(string s) {
	int n = s.size();
	for (int i = 0; i < n; i++) {
		if (s[i] != s[n - i - 1]) return false;
	}
	return true;
}

void solve() {
	string s; cin >> s;
	string f1 = "";
	string f2 = "";
	int n = s.size();
	for (int i = 1; i <= (n - 1) / 2; i++)
		f1 += s[i - 1];
	for (int i = (n + 3) / 2; i <= n; i++)
		f2 += s[i - 1];
	if (good(f1) && good(f2) && good(s)) cout << "Yes\n";
	else cout << "No\n";	
    return;
}

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

using namespace std;

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

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;

#define all(a)  (a).begin(),(a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define pb push_back
#define mp make_pair
#define each(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define exist(s,e) ((s).find(e)!=(s).end())
#define range(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)  range(i,0,n)
#define clr(a,b) memset((a), (b) ,sizeof(a))
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

const double eps = 1e-10;
const double pi  = acos(-1.0);
const ll INF =1LL << 62;
const int inf =1 << 29;

int n,m;
string donut[15];
set<string> check;

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

void longest(string &res,string in){
	if(in.size()>res.size())
		res=in;
	if(in.size()==res.size()&&in<res)
		res=in;
}

string solve(){
	string res="";
	rep(i,n)rep(j,m)rep(k,8){
		string cur="";
		cur+=donut[i][j];
		int ci=(i+dx[k]+n)%n,cj=(j+dy[k]+m)%m;
		while(ci!=i||cj!=j){
			cur+=donut[ci][cj];
			if(check.find(cur)!=check.end())
				longest(res,cur);
			else
				check.insert(cur);
			ci=(ci+dx[k]+n)%n,cj=(cj+dy[k]+m)%m;
		}
	}
	return res;
}

int main(void){
	while(cin >> n >> m){
		rep(i,n) cin >> donut[i];
		if(n==0)
			break;
		check.clear();
		string ans=solve();
		if(ans=="")
			cout << 0 << endl;
		else
			cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 33776
import java.util.Scanner;

public class Main{
	static final Scanner s=new Scanner(System.in);
	static int getInt(){
		return Integer.parseInt(s.next());
	}
	public static void main(String[]__){
		int n=getInt();
		boolean[]dp=new boolean[114514];
		dp[0]=true;
		for(int i=0;i<n;i++) {
			int v=getInt();
			for(int j=114513;j>=0;j--) {
				if(dp[j]&&j+v<114514)
					dp[j+v]=true;
			}
		}
		for(int i=114513;i>0;i--)
			if(i%10!=0&&dp[i]) {
				System.out.println(i);
				return;
			}
		System.out.println(0);
	}
}


Measured memory_bytes: 23892
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <bitset>
#include <cassert>
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define srep(i,n,m) for(int i=n;i<m;i++)
#define elif else if
#define INF 1000000007
#define pi 3.141592653589793
using namespace std;
int saidaikouyakusuu(int a,int b){
    if(b==0) return a;
    return saidaikouyakusuu(b,a%b);
}
int saisyoukoubaisuu(int a,int b){
    return a*b/saidaikouyakusuu(a,b);
}
int n,m,cnt=0,aa[220000];
pair<int,int> pp[220000];
string s,ss[220000];
char c;
queue<int> que;
signed main(){
    cin>>n;
    rep(i,n){
        cnt+=(n/(i+1))*(n/(i+1)+1)*(i+1)/2;
    }
    cout<<cnt;
}


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

using namespace std;

typedef long long ll;

int f(ll N) {
	if (N == 1) return 0;
	if (N <= 3) return 1;
	return f((N+2)/3) + 1;
}

int main() {
	ll N; cin >> N;
	cout << f(N) << endl;
}

Measured memory_bytes: 1164
#include <stdio.h>

#define m (100)

static const int MAXNUMOFINPUT = 1000000;
long long cnt;
int size;
int G[m];

int insertionSort(int A[], int n, int g);
int shellSort(int A[], int n);

int main()
{
    int i;
    int n;
    int A[MAXNUMOFINPUT];

    scanf("%d", &n);
    for (i = 0; i < n; i++)
    {
        scanf("%d", &A[i]);
    }
    cnt = 0;

    shellSort(A, n);

    printf("%d\n", size);

    for (i = size - 1; i >= 0; i--)
    {
        printf("%d", G[i]);
        if(i)
        {
            printf(" ");
        }
    }
    printf("\n");
    printf("%lld\n", cnt);

    for (i = 0; i < n; i++)
    {
        printf("%d\n", A[i]);
    }

    return 0;
}

int insertionSort(int A[], int n, int g)
{
    int i, j;
    int v;

    for (i = g; i < n; i++)
    {
        v = A[i];
        j = i - g;
        while (j >= 0 && A[j] > v)
        {
            A[j + g] = A[j];
            j -= g;
            cnt++;
        }
        A[j + g] = v;
    }
}

int shellSort(int A[], int n)
{
    int i, j;
    int g = 1;

    for (i = 0; i < m; i++)
    {
        if(g > n || g > MAXNUMOFINPUT)
        {
            break;
        }
        G[i] = g;
        g = 3 * g + 1;
    }

    size = i;

    for (j = size - 1; j >= 0; j--)
    {
        insertionSort(A, n, G[j]);
    }

    return 0;
}



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

typedef long long   signed int LL;
typedef long long unsigned int LU;

#define incID(i, l, r) for(int i = (l)    ; i <  (r); i++)
#define incII(i, l, r) for(int i = (l)    ; i <= (r); i++)
#define decID(i, l, r) for(int i = (r) - 1; i >= (l); i--)
#define decII(i, l, r) for(int i = (r)    ; i >= (l); i--)
#define  inc(i, n) incID(i, 0, n)
#define inc1(i, n) incII(i, 1, n)
#define  dec(i, n) decID(i, 0, n)
#define dec1(i, n) decII(i, 1, n)

#define inII(v, l, r) ((l) <= (v) && (v) <= (r))
#define inID(v, l, r) ((l) <= (v) && (v) <  (r))

#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define PQ priority_queue

#define  ALL(v)  v.begin(),  v.end()
#define RALL(v) v.rbegin(), v.rend()
#define  FOR(it, v) for(auto it =  v.begin(); it !=  v.end(); ++it)
#define RFOR(it, v) for(auto it = v.rbegin(); it != v.rend(); ++it)

template<typename T> bool   setmin(T & a, T b) { if(b <  a) { a = b; return true; } else { return false; } }
template<typename T> bool   setmax(T & a, T b) { if(b >  a) { a = b; return true; } else { return false; } }
template<typename T> bool setmineq(T & a, T b) { if(b <= a) { a = b; return true; } else { return false; } }
template<typename T> bool setmaxeq(T & a, T b) { if(b >= a) { a = b; return true; } else { return false; } }
template<typename T> T gcd(T a, T b) { return (b == 0 ? a : gcd(b, a % b)); }
template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }

// ---- ----

#define bit(b, i) (((b) >> (i)) & 1)

LL n, a[16][16], dp[1 << 16], INF = 1e12;

int main() {
	cin >> n;
	inc(i, n) {
	inc(j, n) {
		cin >> a[i][j];
	}
	}
	
	inc(b, 1 << n) {
		inc(i, n) { if(! bit(b, i)) { continue; }
		inc(j, n) { if(! bit(b, j)) { continue; }
			dp[b] += a[i][j];
		}
		}
	}
	
	inc(s, 1 << n) {
		for(int t = s; true; t = (t - 1) & s) {
			int u = s ^ t;
			setmax(dp[s], dp[t] + dp[u]);
			if(t == 0) { break; }
		}
	}
	
	cout << dp[(1 << n) - 1] / 2 << endl;
	
	return 0;
}


Measured memory_bytes: 768
#include <bits/stdc++.h>
using namespace std;
#define fastt ios_base::sync_with_stdio(false);cin.tie(NULL);
#define enl "\n"
#define ll long long
#define pb push_back
#define fi first
#define se second
#define vvi vector<vector<ll>> 
#define vi vector<ll> 
#define vpii vector<pair<ll,ll>>
#define all(x) x.begin(),x.end()
#define ffor(i,n) for(ll i = 0; i < n; ++i)
 
int main() {
    fastt;
    int a,b;
    cin>>a>>b;
    if(a>9||b>9){
        cout<<-1<<enl;
    }
    else{
        cout<<a*b<<enl;
    }
    return 0;
}

Measured memory_bytes: 256
import math
(_,), a  = [list(map(int, s.split())) for s in open(0)]

def fast_factorize(num):
    min_factor_list = list(range(num + 1))
    for i in range(int(math.sqrt(num) + 1), 1, -1):
        for j in range(i, num+1, i):
            min_factor_list[j] = i
    return min_factor_list

min_factor_list = fast_factorize(max(a))

prime_factor_sets = []
for x in a:
    prime_factor_set = set()
    while min_factor_list[x] != 1:
        prime_factor_set.add(min_factor_list[x])
        x //= min_factor_list[x]
    prime_factor_sets.append(prime_factor_set)

g = prime_factor_sets[0].copy()
l = prime_factor_sets[0].copy()
s = 0
for x in prime_factor_sets:
    g &= x
    l |= x
    s += len(x)

if len(g) != 0:
    ans = 'not coprime'
elif len(l) != s:
    ans = 'setwise coprime'
else:
    ans = 'pairwise coprime'
print(ans)

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

int main() {
    int n,q,i,j; cin >> n >> q;
    string s;cin >> s;
    vector<int> l(n,0);
    vector<int> r(n,0);
    map<int,int> mp;
    int cnt = 0;
    rep(i,q) cin >> l[i] >> r[i];
    rep(i,n+1) (s[i]=='A' && s[i+1]=='C')?cnt++,mp[i+1]=cnt:mp[i+1]=cnt;
    rep(i,q) cout << mp[r[i]-1] - mp[l[i]-1] << endl;
}

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

Measured memory_bytes: 1212
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees#, log2
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10**9 + 7

def main():
	H, N = MAP()
	A, B = [0]*N, [0]*N
	for i in range(N):
		A[i], B[i] = MAP()

	dp = [INF]*(H+1)
	dp[0] = 0


	for i in range(N):
		for j in range(H+1):
			if j < A[i]:
				dp[j] = min(dp[j], B[i])
			if j>= A[i]:
				dp[j] = min(dp[j], dp[j-A[i]]+B[i])

	print(dp[H])

if __name__ == '__main__':
	main()





Measured memory_bytes: 65496
#include <bits/stdc++.h>
#define endl "\n"
using namespace std;
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
template<class T>
inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}

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

const long long INF = 1e18;
//const ll mod = 1000000007;
ll N;
vector<ll> V, W;
ll K = 10;
vector<l_l> mid[1 << 18];

vector<l_l> f(vector<l_l> a) {
    vector<l_l> tmp;
    int n = a.size();
    for(int i = 0; i < (1 << n); i++) {
        l_l now;
        for(int j = 0; j < n; j++) {
            if(!(i & (1 << j))) continue;
            now.first += a[j].second;
            now.second += a[j].first;
        }
        tmp.push_back(now);
    }
    sort(tmp.begin(), tmp.end(), [](l_l a, l_l b) {
        if(a.first != b.first) return a.first < b.first;
        return a.second > b.second;
    });
    vector<l_l> ret;
    for(auto a : tmp) {
        if(ret.size() and ret.back().second >= a.second) continue;
        ret.push_back(a);
    }
    return ret;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> N;
    V.resize(N + 1);
    W.resize(N + 1);
    for(int i = 1; i <= N; i++) {
        cin >> V[i] >> W[i];
    }
    for(int i = 1; i <= N; i++) {
        if(i >= (1 << (K - 1)) and i < (1 << (K))) {
            //cerr << "---" << i << "---" << endl;
            vector<l_l> v;
            ll copy = i;
            while(copy != 0) {
                v.push_back({V[copy], W[copy]});
                copy /= 2;
            }
            mid[i] = f(v);
            for(auto tmp : mid[i]) {
                //cerr << tmp.first << " " << tmp.second << endl;
            }
        }
    }
    int Q;
    cin >> Q;
    while(Q--) {
        ll x, L;
        cin >> x >> L;
        if(x < (1 << K)) {
            ll copy = x;
            vector<l_l> v;
            while(copy != 0) {
                v.push_back({V[copy], W[copy]});
                copy /= 2;
            }
            vector<l_l> w = f(v);
            ll ans = 0;
            for(auto tmp : w) {
                if(tmp.first <= L) chmax(ans, tmp.second);
            }
            cout << ans << endl;
        } else {
            ll copy = x;
            vector<l_l> v;
            while(copy >= (1 << K)) {
                v.push_back({V[copy], W[copy]});
                copy /= 2;
            }
            auto w = f(v);
            auto q = mid[copy];
            ll ans = 0;
            for(auto tmp : w) {
                l_l s = {L - tmp.first + 1, -INF};
                auto itr = lower_bound(q.begin(), q.end(), s);
                if(itr == q.begin()) continue;
                itr--;
                chmax(ans, tmp.second + (*itr).second);
            }
            cout << ans << endl;
        }
    }
    return 0;
}

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

int main()
{
    ll n, m, k;
    int res = 0;
    cin >> n >> m >> k;

    vector<ll> a(n + 1, 0), b(m + 1, 0);
    
    for(int i = 1; i <= n; ++i)
    {
        cin >> a[i];
        a[i] += a[i - 1];
    }

    for(int i = 1; i <= m; ++i)
    {
        cin >> b[i];
        b[i] += b[i - 1];
    }

    int j = m;
    for(int i = 0; i <= n; ++i)
    {
        if(a[i] > k) break; 
        while(a[i] + b[j] > k)
        {
            j--;
        }
        res = max(res, i + j);
    }

    cout << res << "\n";
    return 0;
}


Measured memory_bytes: 6420
import java.util.*;
  
public class Main{
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int H = sc.nextInt();
		int W = sc.nextInt();
		String a[] = new String [H];
		String x = "";
  
		for(int i=0; i<H; i++) {
			a[i] = sc.next();
		}

		for(int i=0; i<W; i++){
			x += "#"; 
		}


		System.out.println("#"+x+"#");
		for(String j:a){
            System.out.println("#"+j+"#");       
		}
		System.out.println("#"+x+"#");
	

		
	}
}





Measured memory_bytes: 23764
#include <bits/stdc++.h>
//#include <boost/multiprecision/cpp_int.hpp>
//namespace mp = boost::multiprecision;

using namespace std;

const double PI = 3.14159265358979323846;
typedef long long ll;
const double EPS = 1e-9;
#define rep(i, n) for (int i = 0; i < (n); ++i)
//#define rep(i, n) for (ll i = 0; i < (n); ++i)
typedef pair<ll, ll> P;
const ll INF = 10e17;
#define cmin(x, y) x = min(x, y)
#define cmax(x, y) x = max(x, y)
#define ret() return 0;

double equal(double a, double b) {
    return fabs(a - b) < DBL_EPSILON;
}

std::istream &operator>>(std::istream &in, set<int> &o) {
    int a;
    in >> a;
    o.insert(a);
    return in;
}

std::istream &operator>>(std::istream &in, queue<int> &o) {
    ll a;
    in >> a;
    o.push(a);
    return in;
}

bool contain(set<int> &s, int a) { return s.find(a) != s.end(); }

//ofstream outfile("log.txt");
//outfile << setw(6) << setfill('0') << prefecture << setw(6) << setfill('0') << rank << endl;
// std::cout << std::bitset<8>(9);
//const ll mod = 1e10;

typedef priority_queue<ll, vector<ll>, greater<ll> > PQ_ASK;

int main() {
    int sx, sy, tx, ty;
    cin >> sx >> sy >> tx >> ty;

    for (int y = sy; y < ty; y++) {
        cout << 'U';
    }
    for (int x = sx; x < tx; x++) {
        cout << 'R';
    }
    for (int y = ty; y > sy; y--) {
        cout << 'D';
    }
    for (int x = tx; x > sx; x--) {
        cout << 'L';
    }
    cout << 'L';
    for (int y = sy; y <= ty; y++) {
        cout << 'U';
    }
    cout << 'R';
    for (int x = sx; x < tx; x++) {
        cout << 'R';
    }
    cout << 'D';
    cout << 'R';
    for (int y = ty; y > sy; y--) {
        cout << 'D';
    }
    cout << 'D';
    cout << 'L';
    for (int x = tx; x > sx; x--) {
        cout << 'L';
    }
    cout << 'U';
    cout << endl;
}


Measured memory_bytes: 3608
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
#define valid(y,x,h,w) (0<=y&&y<h&&0<=x&&x<w)
#define tpl(...) make_tuple(__VA_ARGS__)
const int INF = 0x3f3f3f3f;
const double EPS = 1e-8;
const double PI = acos(-1);
typedef long long ll;
typedef pair<int,int> pii;
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 (a>b) { a=b; return 1; } return 0; }
template<class T>ostream&operator<<(ostream &o,const vector<T>&t){o<<'[';FOR(i,t){if(i!=t.begin())o<<',';o<<*i;}return o<<']';}
template<class S,class T>ostream&operator<<(ostream &o,const pair<S,T>&t){return o<<'('<<t.first<<','<<t.second<<')';}
template<int N,class Tp>void output(ostream&,const Tp&){}
template<int N,class Tp,class,class ...Ts>void output(ostream &o,const Tp&t){if(N)o<<',';o<<get<N>(t);output<N+1,Tp,Ts...>(o,t);}
template<class ...Ts>ostream&operator<<(ostream&o,const tuple<Ts...>&t){o<<'(';output<0,tuple<Ts...>,Ts...>(o,t);return o<<')';}
template<class T>void output(T t,char z=10){if(t<0)t=-t,putchar(45);int c[20];
int k=0;while(t)c[k++]=t%10,t/=10;for(k||(c[k++]=0);k;)putchar(c[--k]^48);putchar(z);}
template<class T>void outputs(T t){output(t);}
template<class S,class ...T>void outputs(S a,T...t){output(a,32);outputs(t...);}
template<class T>void output(T *a,int n){REP(i,n)output(a[i],i!=n-1?',':10);}
template<class T>void output(T *a,int n,int m){REP(i,n)output(a[i],m);}
template<class T>bool input(T &t){int n=1,c;for(t=0;!isdigit(c=getchar())&&~c&&c-45;);
if(!~c)return 0;for(c-45&&(n=0,t=c^48);isdigit(c=getchar());)t=10*t+c-48;t=n?-t:t;return 1;}
template<class S,class ...T>bool input(S&a,T&...t){input(a);return input(t...);}

struct Book {
  string title,author;
  string date;
  void in() {
    cin >> title >> author >> date;
    // int y,m,d;
    // scanf("%d:%d:%d", &y, &m, &d);
    // date = (ll)y*12*31 + (m-1)*31 + (d-1);
  }
} book[100];
bool contain(const string &s, const string&t) {
  for (int i=0; i<=(int)s.size()-(int)t.size(); ++i) {
    if (s.substr(i,t.size()) == t) return 1;
  }
  return 0;
}
int main() {
  int n;
  while(cin>>n) {
    REP(i,n) {
      book[i].in();
    }
    int q;
    cin >> q;
    REP(i,q) {
      string title, author, from, to;
      cin >> title >> author >> from >> to;
      if (i) cout << endl;
      REP(j,n) {
        if ((title == "*" || contain(book[j].title,title)) &&
            (author == "*" || contain(book[j].author,author)) &&
            (from == "*" || from <= book[j].date) &&
            (to == "*" || to >= book[j].date)) {
          cout << book[j].title << endl;
            }
      }
    }
  }
}

Measured memory_bytes: 1240
import java.util.Scanner;

public class Main {
   public static void main(String[] args) {
       Scanner s = new Scanner(System.in);
       String st = s.next();
       char c = st.charAt(0);
       if(Character.isUpperCase(c)) {
           System.out.println("A");
       }
       else {
           System.out.println("a");
       }
   }
}


Measured memory_bytes: 26924
#include <iostream>

using namespace std;

int main(){

  int N,available=1;

  cin >> N;
  
  int x,y,t,x_old=0,y_old=0,t_old=0;
  for(int i = 1; i <= N; i++){
	cin >> t >> x >> y;

	int x_diff,y_diff,t_diff;
	x_diff = x - x_old;
	y_diff = y - y_old;
	t_diff = t - t_old;

	if(x_diff < 0){
	  x_diff = -x_diff;
	}
	if(y_diff < 0){
	  y_diff = -y_diff;
	}

	if(t_diff == x_diff + y_diff){
	  //available
	}
	else if(t_diff > x_diff + y_diff){
	  if((t_diff - (x_diff + y_diff))%2 == 1){
		available = 0;
	  }
	}
	else{
	  available = 0;
	}
	  	
	x_old = x;
	y_old = y;
	t_old = t;
  }

  if(available){
	cout << "Yes" << "\n";
  }
  else{
	cout << "No" << "\n";
  }
  
  return 0;
}


Measured memory_bytes: 256
sa = input()
sb = input()
sc = input()
turn = sa[0]
sa = sa[1:]
while True:
    if turn == 'a':
        if not sa:
            win = 'A'
            break
        else:
            turn = sa[0]
            sa = sa[1:]
    if turn == 'b':
        if not sb:
            win = 'B'
            break
        else:
            turn = sb[0]
            sb = sb[1:]
    if turn == 'c':
        if not sc:
            win = 'C'
            break
        else:
            turn = sc[0]
            sc = sc[1:]
print(win)

Measured memory_bytes: 3064
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <map>
#include <numeric>
#include <type_traits>
#include <limits>

using namespace std;

using ll = long long;

unsigned gcd(unsigned a, unsigned b) {
	while (1) {
		if (a < b) swap(a, b);
		if (!b) break;
		a %= b;
	}
	return a;
}

int H, W;
ll X, N;
ll a[100000];
ll ans;

int main() {
	cin >> N >> X;
	for (int i = 0; i < N; i++) {
		cin >> a[i];
	}
	sort(a, a + N);
	ans = abs(a[0] - X);
	for (int i = 0; i < N; i++) {
		ans = gcd(abs(a[i] - X), abs(ans));
	}

	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
struct pss
{
	string s;
	int id,p;
}o[105];
bool cmp(pss a,pss b)
{
	if(a.s!=b.s)
		return a.s<b.s;
	return a.p>b.p;
}
int main()
{
	int n;
	cin>>n;
	for(int i=0;i<n;i++)
	{
		cin>>o[i].s>>o[i].p;
		o[i].id=i+1;
	}
	sort(o,o+n,cmp);
	for(int i=0;i<n;i++)
	{
		cout<<o[i].id<<endl;
	}
	return 0;
}

Measured memory_bytes: 256
import java.util.*;

class Main{
 public static void main(String[] args){
   Scanner sc = new Scanner(System.in);
   int N = sc.nextInt();
   int X = sc.nextInt();
   int place = 0;
   int cnt = 1;
   for(int i=0;i<N;i++){
     place += sc.nextInt();
     if (place<=X){
       cnt++;
     }
     
   }
   System.out.println(cnt);
 }
}


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

int main()
{
    int n;
    cin >> n;
    vector<int> r(n);
    for(int i = 0;i < n;i++){
        cin >> r[i];
    }

    if(n == 1){
        cout << 0;

        return 0;
    }

    int ans = r[1] - r[0];
    int minv = r[0];
    for(int i = 1;i < n;i++){
        if(ans < r[i] - minv){
            ans = r[i] - minv;
        }
        if(minv > r[i]){
            minv = r[i];
        }
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3600
#include <iostream>
#include <cstring>

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

int h,w;

int board[100][100];

bool used[100][100];

void dfs(int x,int y) {
	used[y][x]=true;

	if(!board[y][x]){
		std::cout<<x<<' '<<y<<std::endl;
		return;
	}

	int nx=dx[board[y][x]]+x,ny=dy[board[y][x]]+y;

	if(used[ny][nx]){
		std::cout<<"LOOP"<<std::endl;
		return;
	}

	dfs(nx,ny);

	used[y][x]=false;
}

int main() {
	while(1){
		std::cin>>h>>w;
		if(h+w==0)
			break;
		std::memset(board,0,sizeof(board));
		std::memset(used,0,sizeof(used));
		char ch;
		for(int i=0;i<h;++i){
			for(int j=0;j<w;++j){
				std::cin>>ch;
				if(ch=='<')
					board[i][j]=1;
				else if(ch=='^')
					board[i][j]=2;
				else if(ch=='>')
					board[i][j]=3;
				else if(ch=='v')
					board[i][j]=4;
			}
		}
		dfs(0,0);
	}
	return 0;
}

Measured memory_bytes: 3092
/***************************************
    codeforces = topcoder = sahedsohel
    IIT,Jahangirnagar University(42)
****************************************/
#include <bits/stdc++.h>
using namespace std;

#define ll long long int

ll A, B, C, D, E,F;


int main()
{
    ll t,i,j,k,l;
    
    cin>>A>>B>>C>>D>>E>>F;
    
    double rs=-1;
    ll r1,r2;
    r1=r2=0;
    for(i=0;i<=F;i+=100*A)
    {
		for(j=0;i+j<=F;j+=100*B)
		{
			ll mx=min(((i+j)/100)*E,F-i-j);
			
			for(k=0;k<=mx;k+=C)
			{
				for(l=0;k+l<=mx;l+=D)
				{
					ll x=l+k;
					ll y=i+j+k+l;
					//if(x==0||y==0)continue;
					
					double q=(x*100.0)/y;
					
					if(q>rs)
					{
						rs=q;
						r1=y;
						r2=x;
					}
				}
			}
		}
	}
	if(r1==0&&r2==0)assert(0);
    
    cout<<r1<<" "<<r2<<endl;
    
	return 0;
}




Measured memory_bytes: 256