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

namespace AtCorder
{
    class Program
    {
        static void Main(string[] args)
        {
            new Program().Solve(new ConsoleInput(Console.In, ' '));
        }
        public void Solve(ConsoleInput cin)
        {
            var a = cin.ReadLong;
            var b = cin.ReadLong;
            var c = cin.ReadInt;
            var d = cin.ReadInt;
            WriteLine(isNum(b, c, d) - isNum(a - 1, c, d));
        }
        public long isNum(long x, int c, int d)
        {
            var isC = (long)(x / c);
            var isD = (long)(x / d);
            var isCD = (long)(x / Lcm(c, d));
            return x - isC - isD + isCD;
        }
        // 最小公倍数
        public static long Lcm(long a, long b)
        {
            return (a * b) / Gcd(a, b);
        }

        // ユークリッドの互除法 
        public static long Gcd(long a, long b)
        {
            if (a < b)
                // 引数を入替えて自分を呼び出す
                return Gcd(b, a);
            while (b != 0)
            {
                var remainder = a % b;
                a = b;
                b = remainder;
            }
            return a;
        }
    }

    public class ConsoleInput
    {
        private readonly System.IO.TextReader _stream;
        private char _separator = ' ';
        private Queue<string> inputStream;
        public ConsoleInput(System.IO.TextReader stream, char separator = ' ')
        {
            this._separator = separator;
            this._stream = stream;
            inputStream = new Queue<string>();
        }
        public string Read
        {
            get
            {
                if (inputStream.Count != 0) return inputStream.Dequeue();
                string[] tmp = _stream.ReadLine().Split(_separator);
                for (int i = 0; i < tmp.Length; ++i)
                    inputStream.Enqueue(tmp[i]);
                return inputStream.Dequeue();
            }
        }
        public string ReadLine { get { return _stream.ReadLine(); } }
        public int ReadInt { get { return int.Parse(Read); } }
        public long ReadLong { get { return long.Parse(Read); } }
        public double ReadDouble { get { return double.Parse(Read); } }
        public string[] ReadStrArray(long N) { var ret = new string[N]; for (long i = 0; i < N; ++i) ret[i] = Read; return ret; }
        public int[] ReadIntArray(long N) { var ret = new int[N]; for (long i = 0; i < N; ++i) ret[i] = ReadInt; return ret; }
        public long[] ReadLongArray(long N) { var ret = new long[N]; for (long i = 0; i < N; ++i) ret[i] = ReadLong; return ret; }
    }
}

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

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

    static class FFrogJump {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int n = in.nextInt();
            long[] arr = new long[n];
            for (int i = 0; i < n; i++)
                arr[i] = in.nextLong();
            //long res = solveSimple(n, arr);
            long res = solveMeOk(n, arr);
            out.println(res);
        }

        private long solveMeOk(int n, long[] arr) {
            HashSet<Integer> used = new HashSet<>();
            long res = 0;
            //n-1 = a+(k-1)c
            for (int c = 1; c < n; c++) {
                used = new HashSet<>();
                long score = 0;
                res = Math.max(res, score);
                for (int k = 1; (k + 1) * c < n; k++) {
                    if (k * c == n - 1 - k * c)
                        break;
                    if (used.contains(k * c) || used.contains(n - 1 - k * c))
                        break;
                    score += arr[k * c] + arr[n - 1 - k * c];
                    used.add(k * c);
                    used.add(n - 1 - k * c);
                    res = Math.max(score, res);
                }
            }
            return res;
        }

    }
}



Measured memory_bytes: 101584
#include<bits/stdc++.h>
using namespace std;
inline void rd(int &x){
  int k, m=0;
  x=0;
  for(;;){
    k = getchar_unlocked();
    if(k=='-'){
      m=1;
      break;
    }
    if('0'<=k&&k<='9'){
      x=k-'0';
      break;
    }
  }
  for(;;){
    k = getchar_unlocked();
    if(k<'0'||k>'9'){
      break;
    }
    x=x*10+k-'0';
  }
  if(m){
    x=-x;
  }
}
inline void wt_L(char a){
  putchar_unlocked(a);
}
inline void wt_L(int x){
  char f[10];
  int m=0, s=0;
  if(x<0){
    m=1;
    x=-x;
  }
  while(x){
    f[s++]=x%10;
    x/=10;
  }
  if(!s){
    f[s++]=0;
  }
  if(m){
    putchar_unlocked('-');
  }
  while(s--){
    putchar_unlocked(f[s]+'0');
  }
}
int A[5];
int r[5];
int main(){
  int i, res;
  {
    int Lj4PdHRW;
    for(Lj4PdHRW=0;Lj4PdHRW<5;Lj4PdHRW++){
      rd(A[Lj4PdHRW]);
    }
  }
  for(i=0;i<5;i++){
    if(A[i]%10==0){
      A[i] -= (r[i] =10);
    }
    else{
      A[i] -= (r[i] =A[i]%10);
    }
  }
  sort(r, r+5);
  for(i=1;i<5;i++){
    r[i] = 10;
  }
  {
    int KL2GvlyY, Q5VJL1cS;
    if(5==0){
      Q5VJL1cS = 0;
    }
    else{
      Q5VJL1cS = A[0];
      for(KL2GvlyY=1;KL2GvlyY<5;KL2GvlyY++){
        Q5VJL1cS += A[KL2GvlyY];
      }
    }
    {
      int cTE1_r3A, e98WHCEY;
      if(5==0){
        cTE1_r3A = 0;
      }
      else{
        cTE1_r3A = r[0];
        for(e98WHCEY=1;e98WHCEY<5;e98WHCEY++){
          cTE1_r3A += r[e98WHCEY];
        }
      }
      res =Q5VJL1cS+cTE1_r3A;
    }
  }
  wt_L(res);
  wt_L('\n');
  return 0;
}
// cLay varsion 20190706-1

// --- original code ---
// int A[5], r[5];
// {
//   int i, res;
//   rd(A(5));
// 
//   rep(i,5) A[i] -= (r[i] = if[A[i]%10==0, 10, A[i]%10]);
//   sort(r, r+5);
//   rep(i,1,5) r[i] = 10;
// 
//   res = sum(A(5)) + sum(r(5));
//   wt(res);
// }


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int A,B,Ans;
int main(){
	scanf("%d%d",&A,&B);
	Ans=max(Ans,A+A-1);
	Ans=max(Ans,B+B-1);
	Ans=max(Ans,A+B);
	printf("%d\n",Ans);
	return 0;
}

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

#define rep2(x,fr,to) for(int x=(fr);x<(to);x++)
#define rep(x,to) for(int x=0;x<(to);x++)
#define repr(x,fr,to) for(int x=(fr);x>=(to);x--)
#define all(c) c.begin(),c.end()
#define sz(v) (int)v.size()

using namespace std;
typedef long long ll; typedef vector<int> VI; typedef pair<int,int> pii;
typedef vector<ll> VL; const int MD = 1e9 + 7;
void dbg(){cerr<<"\n";} template <typename T,typename ...T2> void dbg(const T& fst, const T2&...rst){ cerr << fst << ": "; dbg(rst...); }
	ll gcd(ll x, ll y){ return y? gcd(y, x%y): x; }
	ll lcm(ll x, ll y){ return (x  / gcd(x, y) * y ); }

int main()
{
	cin.tie(0); ios_base::sync_with_stdio(false);
	int n, m;
	cin >>n >>m;
	VI a(n), b(n);
	rep(i, n) cin >>a[i];
	rep(i, n) b[i] = a[i] / 2;
	ll zz=b[0], ng= 0;
	rep(i, n){
		zz = lcm(zz, b[i]);
		if(zz > m) ng=1;
	}
	ll ans = 0;
	if(m >= zz) ans = 1 + (m-zz)/(2*zz);
	VI ck2(n);
	rep(i ,n){
		int c=0;
		for(int w=a[i]; w>0 && w%2==0; w/=2) c++;
		ck2[i]=c;
	}
	int zm =-1;
	rep(i, n){
		if(ck2[i] >0&& zm==-1) zm=ck2[i];
		if(ck2[i]>0 && zm != ck2[i]) ng=1;
	}
	if(ng) ans =0;
	cout << ans <<"\n";
	/*{
		const int MX=m;
		map<int, int> mp;
		rep(i, n){
			rep(j, MX){
				if(a[i] * j + a[i]/2 > MX) break;
				mp[a[i] * j + a[i]/2]++;
			}
		}
		int as=0;
		for(auto x: mp) if(x.second==n){ as++; }
		dbg("sm=", as);
	}
	*/
	return 0;
}


Measured memory_bytes: 1408
#include <iostream>

int main()
{
    int A, B, C, K;
    std::cin >> A >> B >> C;
    std::cin >> K;

    int cnt=0;
    for(int i=1; i<=K; i++)
    {
        cnt=i;
        if( !(B>A))
        {
            B *= 2;
        }
        else
        {
            cnt--;
            break;
        }
    }
    
//    printf("[2nd = %d]\n", K-cnt);

    for(int i=1; i<=K-cnt; i++)
    {
        if( !(C>B))
        {
            C *= 2;
        }
        else
        {
            break;
        }
    }

//    printf("%d:%d:%d\n", A, B, C);

    bool isOk = false;
    if((B>A) && (C>B))
    {
        isOk = true;
    }

    if(isOk == true)
    {
        std::cout << "Yes" << std::endl;
    }
    else
    {
        std::cout << "No" << std::endl;
    }
    

    return 0;
}

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

int main()
{
    int a, b;
    string s;
    cin >> a >> b >> s;
    bool res = true;

    for(int i = 0; i < s.size(); ++i)
    {
        if(i < a && !isdigit(s[i]))
        {
            res = false;
        }
        if(i == a && s[i] != '-')
        {
            res = false;
        }
        if(i > a + 1 && !isdigit(s[i]))
        {
            res = false;
        }
    }

    cout << (res ? "Yes" : "No") << "\n";
    return 0;
}


Measured memory_bytes: 3624
#include<iostream>
#include<cmath>
#include<algorithm>
#include<map>
#include<vector>
#include<queue>
#include<cassert>
using namespace std;
#define REP(i, b, n) for(int i = b; i<(int)n; i++)
#define rep(i, n) REP(i, 0, n)
const int N = 100;
typedef pair<int,int> pii;
const int inf = (1<<21);
const int LIM = 3000;
int cost[N][N];
int getdist(int y,int x){
  return abs(y)+abs(x);
}

int solve(int r,int c,int sy,int sx,int gy,int gx,vector<pii> *in,int lim){
  rep(i,r)rep(j,c)cost[i][j]=inf;
  cost[sy][sx]=0;
  rep(i,in[1].size()){
    int y=in[1][i].first,x=in[1][i].second;
    cost[y][x]=min(cost[y][x],cost[sy][sx]+getdist(y-sy,x-sx));
    //cout << cost[y][x] <<" " << cost[sy][sx]+getdist(y-sy,x-sx) << endl;
  }
  REP(i,2,lim){
    rep(j,in[i-1].size()){
      int &py=in[i-1][j].first,&px=in[i-1][j].second;
      //cout << py <<" " << px << " " << cost[py][px] << endl;
      rep(k,in[i].size()){
	int &y=in[i][k].first,&x=in[i][k].second;
	cost[y][x]=min(cost[y][x],cost[py][px]+getdist(py-y,px-x));
      }
    }
  }
  return cost[gy][gx];
}

main(){
  int r,c;
  while(cin>>c>>r && r){
    vector<pii> in[LIM];
    int lim=0,sy,sx,gy,gx;
    rep(i,r){
      rep(j,c){
	string tmp;
	cin>>tmp;
	if (tmp == ".")continue;
	if (tmp == "S"){
	  sy=i;sx=j;
	}else if (tmp == "G"){
	  gy=i;gx=j;
	}else {
	  int val=atoi(tmp.c_str());
	  in[val].push_back(make_pair(i,j));
	  lim=max(lim,val);
	}
      }
    }
    lim++;
    in[lim].push_back(make_pair(gy,gx));
    lim++;
    cout << solve(r,c,sy,sx,gy,gx,in,lim) << endl;
  }
}

Measured memory_bytes: 1032
#include <stdio.h>

#include <algorithm>
#include <deque>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <utility>
#include <vector>

using namespace std;
typedef long long llong;

void CGoToSchool(std::istream& in, std::ostream& out) {
  int n;
  vector<pair<int, int>> v;
  in >> n;
  for (int i = 0; i < n; ++i) {
    int x;
    in >> x;
    v.push_back(make_pair(x, i));
  }
  sort(v.begin(), v.end());
  for (int i = 0; i < v.size(); ++i) {
    out << v[i].second + 1 << " ";
  }
  out << endl;
}

int main(int argc, char** argv) { CGoToSchool(cin, cout); return 0; }


Measured memory_bytes: 1780
#![allow(unused, non_snake_case, dead_code, non_upper_case_globals)]
use {
    proconio::{marker::*, *},
    std::{cmp::*, collections::*, mem::*},
};
fn main() {
    input! {//
        mut s:Chars,
    }
    if s.len() == 3 {
        s.reverse();
    }
    for &x in s.iter() {
        print!("{}", x);
    }
}


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

int main(){
    string str,ans;
    int h,w;

    cin >> h >> w;

    for(int i = 0; i < h; i++){
        cin >> str;
        ans += str;
        ans += '\n';
        ans += str;
        ans += '\n';
    }

    cout << ans;

    return 0;
}

Measured memory_bytes: 256
# def find_next(number, p, q, x, y, load, max)
#   max_load = Array.new
#   number.times do |n|
#     next if load.include?(n)
#     # puts "load.last: #{load.last}"
#     # puts "#{x[load.last]}, #{y[load.last]}"
#     # puts "#{x[n]}, #{y[n]}"
#     if((x[load.last] - p == x[n]) && (y[load.last] - q == y[n]))
#       load.push(n)
#       # puts "find next"
#       # puts n
#       if max < load.length
#         max = load.length
#         max_load = load.dup
#       end
#       # puts "max: #{max}"
#       if max >= find_next(number, p, q, x, y, load, max)[0]
#         # puts("pop")
#         load.pop
#       end
#     end
#   end
#   return [max, max_load]
# end

N = gets.to_i
x, y = N.times.map{gets.split.map(&:to_i)}.transpose

hash = Hash.new

N.times do |i|
  N.times do |j|
    next if i == j
    # puts "compare #{i} and #{j}"
    new_x = x[i] - x[j]
    new_y = y[i] - y[j]
    hash["#{new_x} #{new_y}"] ||= 0
    hash["#{new_x} #{new_y}"] += 1
  end
end

# hash.sort{|a, b| b[1] <=> a[1]}
# puts hash
# max = 0
# hash.each do |key, value|
#   p, q = key.split.map(&:to_i)
#   N.times do |i|
#     # puts "i:#{i}"
#     # i からスタート
#     load = Array.new
#     load.push(i)
#     tmp_max = 0
#     tmp_max, tmp_load = find_next(N, p, q, x, y, load, tmp_max)
#
#     if max < tmp_max
#       # puts "p: #{p}, q: #{q}"
#       # puts "tmp_load"
#       # puts tmp_load
#       # puts "ここまで"
#       # puts "tmp_max #{tmp_max}"
#       max = tmp_max
#     end
#   end
# end
puts N - (hash.values.max || 0)


Measured memory_bytes: 2172
#include<stdio.h>
#include<string.h>
#include<iostream>
#include<string>
#include<complex>
#include<algorithm>
#include<vector>
#include<math.h>
#include<set>
#include<map>

bool used[3][30]{};
int n, all_color, d[500][500]{}, c[500][500]{}, table[3][30]{};

void calc_diff(int, int);

int main()
{
	long long min = 1000000000000;
	scanf("%d%d", &n, &all_color);
	for (int i = 0; i < all_color; i++)
	{
		for (int j = 0; j < all_color; j++)
		{
			scanf("%d", d[i] + j);
		}
	}
	for (int i = 0; i < n; i++)
	{
		for (int j = 0; j < n; j++)
		{
			scanf("%d", c[i] + j);
			c[i][j]--;
			used[(i + j) % 3][c[i][j]] = true;
		}
	}
	for (int i = 0; i < 3; i++)
	{
		for (int j = 0; j < all_color; j++)
		{
			calc_diff(i, j);
		}
	}

	for (int one = 0; one < all_color; one++)
	{
		for (int two = 0; two < all_color; two++)
		{
			if (two == one) continue;
			for (int three = 0; three < all_color; three++)
			{
				if (three == two || three == one) continue;
				long long min_tmp = table[0][one] + table[1][two] + table[2][three];
				if (min_tmp < min) min = min_tmp;
			}
		}
	}
	printf("%lld\n", min);
	return 0;
}

void calc_diff(int pos, int color)
{
	for (int i = 0; i < n; i++)
	{
		for (int j = (pos + 3 - (i % 3)) % 3; j < n; j += 3)
		{
			table[pos][color] += d[c[i][j]][color];
		}
	}
}

Measured memory_bytes: 1280
package main

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

func out(x ...interface{}) {
	fmt.Println(x...)
}

var sc = bufio.NewScanner(os.Stdin)

func getInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func getString() string {
	sc.Scan()
	return sc.Text()
}

// min, max, asub, absなど基本関数
func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func asub(a, b int) int {
	if a > b {
		return a - b
	}
	return b - a
}

func abs(a int) int {
	if a >= 0 {
		return a
	}
	return -a
}

func lowerBound(a []int, x int) int {
	idx := sort.Search(len(a), func(i int) bool {
		return a[i] >= x
	})
	return idx
}

func upperBound(a []int, x int) int {
	idx := sort.Search(len(a), func(i int) bool {
		return a[i] > x
	})
	return idx
}

func main() {
	sc.Split(bufio.ScanWords)
	N := getInt()

	cx, cy, ct := 0, 0, 0
	for i := 0; i < N; i++ {
		t, x, y := getInt(), getInt(), getInt()
		dt := t - ct
		dx := abs(cx - x)
		dy := abs(cy - y)

		d := dt - (dx + dy)
		// out(dt, dx, dy, d)

		if d < 0 || d%2 != 0 {
			out("No")
			return
		}

		ct, cx, cy = t, x, y
	}
	out("Yes")
	return
}


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

int main() {
	ll n, m, k;
	cin >> n >> m >> k;
	vector<ll>a(n);
	for (int i = 0; i < n; i++)cin >> a.at(i);
	vector<ll>b(m);
	for (int i = 0; i < m; i++)cin >> b.at(i);
	vector<ll>asig(n+1);
	vector<ll>bsig(m+1);
	asig.at(0) = 0;
	bsig.at(0) = 0;
	for (int i = 1; i <= n; i++) {
		asig.at(i) = asig.at(i - 1) + a.at(i - 1);
	}
	for (int i = 1; i <= m; i++) {
		bsig.at(i) = bsig.at(i - 1) + b.at(i - 1);
	}
	ll ans = 0;
	for (int i = 0; i < n + 1; i++) {
		ll x = upper_bound(bsig.begin(), bsig.end(), k - asig.at(i)) - bsig.begin() - 1;
		if (x < 0)continue;
		ans = max(ans, x + i);
	}
	cout << ans << endl;
}

Measured memory_bytes: 9516
#include<bits/stdc++.h>
using namespace std;
const int N=100100;
typedef long long ll;
vector<int>L[N],R[N];
int cnt,n,m,a[N];
ll ans=LLONG_MAX,sum;
int main(){
	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	cin>>n>>m;
	for(int i=1;i<=n;++i)cin>>a[i];
	cnt=0;sum=0;
	for(int i=1;i<n;++i){
		R[a[i]].push_back(a[i+1]);
		L[a[i+1]].push_back(a[i]);
		if(a[i+1]<a[i])sum+=a[i+1],cnt++;
		else sum+=a[i+1]-a[i];
	}
	for(int i=1;i<=m;++i){
		ans=min(ans,sum);
		for(int j:L[i])sum--,sum+=(i-j+m)%m,--cnt;
		sum-=cnt;cnt+=R[i].size();
	}
	cout<<ans<<'\n';
	return 0;
}


Measured memory_bytes: 9984
#include <iostream>
#include <cassert>
#include <vector>

struct UnionFind {
  std::vector<int> data;
  UnionFind(const int size) : data(size, -1) {}
  int root(const int x) { return data[x] < 0 ? x : data[x] = root(data[x]); }
  int size(const int x) { return -data[root(x)]; }
  bool same(const int x, const int y) { return root(x) == root(y); }
  bool unite(int x, int y) {
    x = root(x);
    y = root(y);
    if (x == y)
      return false;
    else {
      if (data[y] < data[x])
        std::swap(x, y);
      data[x] += data[y];
      data[y] = x;
      return true;
    }
  }
};

int main()
{
  int n, q;
  std::cin >> n >> q;

  UnionFind uf(n);

  for (int i = 0; i < q; ++i) {
    int com, x, y;
    std::cin >> com >> x >> y;
    if (com == 0)
      uf.unite(x, y);
    else
      std::cout << uf.same(x, y) << std::endl;;
  }

  return 0;
}



Measured memory_bytes: 3152
#include<stdio.h>
int main (){
	int a,b,S,L;
	scanf("%d%d",&a, &b);
	if(1<=a && b<=100){
	S=a*b;
	L=a*2+b*2;
	printf("%d ",a*b);
	printf("%d\n",a*2+b*2);
	}else{
	printf("NOT\n");
	}
	return 0;
}
	

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

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

using namespace std;

int main() {
	string s;
	cin >> s;
	cout << s.rfind('Z') - s.find('A') + 1 << endl;
	return 0;
}

Measured memory_bytes: 640
object Main {
  def solve(): Seq[List[Int]] = {
    val rectangles = scala.collection.mutable.Map[List[Int], Int]()
    for(r <- 1 to 150; c <- 1 to 150 if r < c) {
      rectangles += List(r, c) -> (r * r + c * c)
    }
    rectangles.toSeq.sortWith((p, q) =>
      if(p._2 == q._2) p._1(0) < q._1(0) else p._2 < q._2).map(p => p._1)
  }
  def main(args:Array[String]) = {
    val ans = solve
    val sc = new java.util.Scanner(System.in)
    var r = sc.nextInt
    var c = sc.nextInt
    while(r != 0 || c != 0) {
      println(ans(ans.indexOf(List(r, c)) + 1).mkString(" "))
      r = sc.nextInt
      c = sc.nextInt
    }
  }
}

Measured memory_bytes: 54452
#include<bits/stdc++.h>
#define mod 1000000007
using namespace std;
int dy[4]={1,0,-1,0};
int dx[4]={0,1,0,-1};
vector<vector<int>> graph;

bool sort_sec(const pair<int,int> &a,const pair<int,int> &b){
   if(a.second<b.second){
      return true;
   }
   return false;
}

void swap(int *a,int *b){
   int temp=*a;
   *a=*b;
   *b=temp;
}

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

int main(void){
   long long A,B,C;
   cin>>A>>B>>C;
   cout<<min(min(A*B*(C%2),(A%2)*B*C),(B%2)*C*A)<<endl;
   return 0;
}


Measured memory_bytes: 256
a,b=gets.split.map(&:to_i)
s=gets.to_s
if s[a]=='-'
  if s[0..a-1] =~ /[0-9]+/ && s[a+1,b] =~ /[0-9]+/
    puts :Yes
  else
    puts :No
  end
else
  puts :No
end

Measured memory_bytes: 1788
#include<iostream>
#include<string>
#include<ctype.h>
using namespace std;
int main(){
	int n;
    cin >> n;
    string ta, ha;
    int ptt = 0;
    int pth = 0;
    for (int i =0; i<n; i++){
        cin >> ta >> ha;
        int ans = ta.compare(ha);
        if (ans ==0){
            ptt +=1 ;
            pth +=1 ;
        }
        else if (ans > 0 ) ptt += 3;
        else pth +=3;
    }
	cout << ptt << " "<< pth << endl;
	return 0;
}



Measured memory_bytes: 3128
use v5.18; # strict say state
use warnings;
use List::Util qw(reduce first max min sum0);

chomp (my $n = <STDIN>);
my (@a, @b);
for my $i (0..$n-1) {
  chomp (($a[$i], $b[$i]) = split / /, <STDIN>);
}
my $ans = 0;
for my $i (0..($n-1)) {
  $ans += ($b[$n-$i-1] - ($a[$n-$i-1]+$ans) % $b[$n-$i-1]) % $b[$n-$i-1];
}
say $ans;

Measured memory_bytes: 21376
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using pi = pair<int, int>;
using vi = vector<int>;
using vii = vector<pi>;
#define endl '\n'
#define fast_io ios_base::sync_with_stdio(0); cin.tie(NULL);
#define all(a) (a).begin(),(a).end()
#define sz(a) int((a).size())
#define clr(a,x) memset((a),(x)sz(a))
#define present(t, x) (t.find(x) != t.end())
#define uni(a) (a).erase(unique(all(a)), (a).end())
#define rep(i, x, y) for(decltype(y) i = (x) - ((x) > (y)); i != (y) - ((x) > (y)); i += 1 - 2 * ((x) > (y)))
#define forall(it, a) for(decltype((a).begin()) it = (a).begin(); it != (a).end(); it++)
#define what_is(x) cerr << #x << " is " << (x) << endl;
#define db(x) cerr << __LINE__ << ": " << #x << " = " << (x) << endl
#define debug(...) fprintf(stderr, __VA_ARGS__), fflush(stderr)
#define time__(d) \
	for(long blockTime=(long)NULL;(blockTime==(long)NULL?(blockTime=clock())!=(long)NULL:false); \
	debug("%s:%.4fs\n",(d),(double)(clock()-blockTime)/CLOCKS_PER_SEC))
const int MOD = (int) 1e9 + 7;
const int FFTMOD = 1007681537;
const int INF = (int) 1e9;
const ll LINF = (ll) 1e18;
const ld PI = acos((ld) -1); // pi
const ld EPS = 1e-9; // epsilon
#define eb emplace_back
#define ef emplace_front
#define mp make_pair
#define fi first
#define se second
#define prec(n) fixed<<setprecision(n)
#define bit(n, i) (((n) >> (i)) & 1)
#define bitcount(n) __builtin_popcountll(n)
inline ll gcd(ll a, ll b) {ll r; while (b) {r = a % b; a = b; b = r;} return a;}
inline ll lcm(ll a, ll b) {return a / gcd(a, b) * b;}
inline ll fpow(ll n, ll k, int p = MOD) {ll r = 1; for (; k; k >>= 1) {if (k & 1) r = r * n % p; n = n * n % p;} return r;}
template<class T> inline int imin(T& a, const T& val) {return val < a ? a = val, 1 : 0;}
template<class T> inline int imax(T& a, const T& val) {return a < val ? a = val, 1 : 0;}
inline ll isqrt(ll k) {ll r = sqrt(k) + 1; while (r * r > k) r--; return r;}
inline ll icbrt(ll k) {ll r = cbrt(k) + 1; while (r * r * r > k) r--; return r;}
inline void addmod(int& a, int val, int p = MOD) {if ((a = (a + val)) >= p) a -= p;}
inline void submod(int& a, int val, int p = MOD) {if ((a = (a - val)) < 0) a += p;}
inline int mult(int a, int b, int p = MOD) {return (ll) a * b % p;}
inline int inv(int a, int p = MOD) {return fpow(a, p - 2, p);}
inline int sign(ld x) {return x < -EPS ? -1 : x > +EPS;}
inline int sign(ld x, ld y) {return sign(x - y);}

//time__("program time")

void solve(){

}

int main(){

	fast_io;
	//solve();
	string s;
	int w;
	cin >> s >> w;

	int n = sz(s);
	string ans = "";
	for(int i = 0;i < n;i += w){

		ans += s[i];
	}

	cout << ans << "\n";


return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <vector>
#include <string>
#include <queue>
#include <deque>
#include <list>
#include <stack>
#include <set>
#include <map>
#include <algorithm>

#define int long long

using namespace std;

signed main() {
    int N, X;
    cin >> N >> X;

    int ret = N;
    int left1 = N - X;
    int left2 = X;
    int st = 0;

    while (left1 != 0 && left2 != 0) {
	if (left1 == left2) {
	    ret += left1;
	    break;
	}
	if (left1 > left2) {
	    int times = left1 / left2;
	    ret += 2 * left2 * times;
	    if (left1 % left2 == 0) {
		ret -= left2;
		break;
	    }
	    left1 %= left2;
	} else {
	    int times = left2 / left1;
	    ret += 2 * left1 * times;
	    if (left2 % left1 == 0) {
		ret -= left1;
		break;
	    }
	    left2 %= left1;
	}
    }
    cout << ret << endl;

    return 0;
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayDeque;

public class Main {

	public static void main(String[] args) throws NumberFormatException, IOException {
		// TODO Auto-generated method stub
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String[] s = br.readLine().split(" ");
		int h = Integer.parseInt(s[0]);
		int w = Integer.parseInt(s[1]);
		String[][] maze = new String[h][w];
		for(int i = 0; i < h ; i++) {
			String height = br.readLine();
			for(int j = 0 ; j < w ; j++) {
				maze[i][j] = height.substring(j,j+1);
			}
		}
		
		int result = 0; 
		for(int i = 0; i < h ; i++) {
			for(int j = 0 ; j < w ; j++) {
				if(maze[i][j].equals(".")) {
					result = Math.max(result, bfs(maze,new Point(i,j),h,w));
				}
			}
		}
		System.out.println(result);
		
	}
	public static int bfs(String[][] maze,Point start,int h , int w) {
		int[][] moves = new int[h][w];
		for(int i = 0; i < h;i++) {
			for(int j = 0; j < w; j++) {
				moves[i][j] = Integer.MAX_VALUE;
			}
		}
		moves[start.getX()][start.getY()] =0;
		ArrayDeque dq = new ArrayDeque();
		Point[] dir = {new Point(0,1),new Point(1,0),new Point(-1,0),new Point(0,-1)}; 
		dq.add(start);
		
		while(dq.size() > 0) {
			Point p = (Point) dq.removeFirst();
			for(int i = 0 ; i < 4 ; i++) {
				
				if(canGo(maze,p.getX(),p.getY(),dir[i].getX(),dir[i].getY()) && 
						moves[p.getX()+dir[i].getX()][p.getY()+dir[i].getY()] == Integer.MAX_VALUE) {
					int nx = p.getX()+dir[i].getX();
					int ny = p.getY()+dir[i].getY();
					moves[nx][ny] = moves[p.getX()][p.getY()]+1;
					dq.add(new Point(nx,ny));
				}
			}
		}
		
		return getMax(moves, h, w);
	}
	public static boolean canGo(String[][] maze,int x,int y,int dx,int dy) {
		if (x +dx >= 0 && y + dy >= 0 && x +dx < maze.length && y+dy < maze[0].length) {
			return maze[x+dx][y+dy].equals(".");
		}
		return false;
	}
	public static int getMax(int[][] moves,int h,int w) {
		int result = -1;
		for(int i = 0 ; i < h ; i++) {
			for(int j = 0; j < w ; j++) {
				if(moves[i][j] != Integer.MAX_VALUE) {
					result = Math.max(result, moves[i][j]);
				}
			}
		}
		return result;
	}
}

class Point {
	private int x;
	private int y;

	Point(int a, int b) {x=a; y=b;}

	int getX() {return x;}
	int getY() {return y;}
	void setX(int n) {x = n;}
	void setY(int n) {y = n;}
}


Measured memory_bytes: 24400
#include <algorithm>
#include <bitset>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#define MOD (1000000007l)
#define ll long long
#define rep(i, n) for (ll i = 0; i < (n); i++)

using namespace std;

void solve() {
  ll N;
  cin >> N;

  map<pair<ll, ll>, ll> count;

  for (ll i = 1; i <= N; i++) {
    ll tail = i % 10;
    ll head = i;
    while (head / 10) head /= 10;
    count[make_pair(head, tail)]++;
  }

  ll ans = 0;

  for (auto it: count) {
    if (count.count(make_pair(it.first.second, it.first.first))) {
      ans += it.second * count[make_pair(it.first.second, it.first.first)];
    }
  }

  cout << ans << endl;
}

int main(void) {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout.precision(12);
  cout << fixed;
  solve();
  return 0;
}


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

int main () {

    int A, B;
    cin >> A >> B;

    if (A >= 13) {
        cout << B << endl;
    }
    else if (A >= 6) {
        cout << B/2 << endl;
    }
    else {
        cout << "0" << endl;
    }

    return 0;
}

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

#define REP(i,s,n) for(int i=s;i<n;++i)
#define rep(i,n) REP(i,0,n)
#define ALL(x) x.begin(),x.end()
#define EPS (1e-8)
#define equals(a,b) (fabs((a)-(b))<EPS)

using namespace std;

typedef long long ll;
const int IINF = INT_MAX;
const ll LLINF = LLONG_MAX;

inline bool LT(double a,double b) { return !equals(a,b) && a < b; }
inline bool LTE(double a,double b) { return equals(a,b) || a < b; }

int gx,gy;

void compute() {

}

bool debug = false;

void to_seq(string s,int ptr,vector<int> &dx,vector<int> &dy) {
  bool f = false;
  REP(i,ptr,(int)s.size()) {
    assert( s[i] == 'T' );
    int j = i + 1;
    int cost = 0;
    while( j < (int)s.size() && s[j] == 'F' ) {
      ++j, ++cost;
    }
    --j;
    i = j;
    if( !f ) {      // y
      dy.push_back(cost);
    } else { // x
      dx.push_back(cost);
    }
    f = !f;
  }
}

#define MAX 100000
bool dp[2][MAX];
bool can_reach(vector<int> &d,int p,int g) {
  memset(dp,false,sizeof dp);
  const int BASE = MAX / 2;
  dp[0][BASE+p] = true;
  rep(i,(int)d.size()) {
    int cur = i & 1;
    int nex = ( cur + 1 ) & 1;
    rep(j,MAX) {
      if( dp[cur][j] ) {
	if( j + d[i] < MAX ) {
	  dp[nex][j+d[i]] = true;
	}
	if( j - d[i] > 0 ) {
	  dp[nex][j-d[i]] = true;
	}
      }
    }
    rep(j,MAX) dp[cur][j] = false;
  }
  return dp[(int)d.size()&1][BASE+g];
}

int main() {
  string s;
  cin >> s;
  cin >> gx >> gy;
  int ptr = 0,x=0,y=0;
  while( ptr < (int)s.size() && s[ptr] == 'F' ) {
    ++x;
    ++ptr;
  }
  if( debug ) {
    cout << x << " " << y << endl;
  }
  vector<int> dx,dy;
  to_seq(s,ptr,dx,dy);
  if( debug ) {
    cout << "dx--" << endl;
    rep(i,(int)dx.size())  {
      cout << dx[i] << " ";
    } puts("");puts("");
    cout << "dy--" << endl;
    rep(i,(int)dy.size())  {
      cout << dy[i] << " ";
    } puts("");
  }
  
  if( can_reach(dx,x,gx) && can_reach(dy,y,gy) ) {
    puts("Yes");
  } else {
    puts("No");
  }
  compute();
  return 0;
}


Measured memory_bytes: 512
n = int(input())
tmp = []
for _ in range(n):
    tmp.append(int(input()))

max = max(tmp)

unk = sorted(tmp, reverse=True)
unk2 = unk[1]

counter = 0
for i in tmp:
    if i == max:
        counter += 1

if counter > 1:
    for i in range(n):
        print(max)
else:
    for i in tmp:
        if i == max:
            print(unk2)
        else:
            print(max)

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

using namespace std;

typedef long long ll;

ll MOD = 1e9 + 7;

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

	int n, m;
	cin >> n >> m;

	vector<ll> a(m+1);
	rep(i, m) cin >> a[i];

	vector<ll> dp(n+1, 0);
	dp[0] = 1;
	if(m == 0 || a[0] != 1) dp[1] = 1;
	int j = 0;
	for(int i = 2; i <= n; i++){
		while(j < m && a[j] < i) {
			j++;
		}

		if(j >= m || i != a[j]){
			dp[i] = dp[i-1] + dp[i-2];
			dp[i] %= MOD;
			// cout << i << "," << dp[i] << endl;
		}
	}

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


Measured memory_bytes: 1792
#include <stdio.h>
#include <stdlib.h>
long long max(long long a,long long b)
{
	if(a>b)	return a;
	return b; 
}
int main()
{
	int i,n,j,W;
	scanf("%d %d",&n,&W);
	long long *dp=(long long*)malloc(sizeof(long long)*W);
	dp[0]=0;
	for(i=1;i<=W;i++) dp[i]=-1;
	for(i=1;i<=n;i++)
	{
		int w1,v1;
		scanf("%d %d",&w1,&v1);
		for(j=W;j>=0;j--)
		{
			if(dp[j]==-1)	continue;
			if(j+w1<=W) dp[j+w1] = max(dp[j+w1],dp[j]+v1);
		}	
	}
	long long ans=-1;
	for(i=0;i<=W;i++)	
	ans=max(ans,dp[i]);
	printf("%lld",ans);
}

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

int main() {
    ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	string s;
	cin>>s;
	int l=s.length();
	if(s.at(l-1)=='s')
	s=s+"es";
	else
	s=s+"s";
	cout<<s;
	return 0;
}

Measured memory_bytes: 3664
package main

import (
	"bufio"
	"container/list"
	"fmt"
	"os"
	"strconv"
)

func main() {
	scn := newScanner()
	X := scn.nextLine()
	stack := list.New()
	for i := 0; i < len(X); i++ {
		if X[i] == 'S' {
			stack.PushFront(X[i])
		} else if X[i] == 'T' && (stack.Len() == 0 || stack.Front().Value.(byte) == 'T') {
			stack.PushFront(X[i])
		} else if X[i] == 'T' && stack.Front().Value.(byte) == 'S' {
			_ = stack.Remove(stack.Front())
		}
	}
	fmt.Println(stack.Len())
}

type scanner struct {
	r   *bufio.Reader
	buf []byte
	p   int
}

func newScanner() *scanner {
	rdr := bufio.NewReaderSize(os.Stdin, 10000)
	return &scanner{r: rdr}
}
func (s *scanner) next() string {
	s.pre()
	start := s.p
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			break
		}
	}
	result := string(s.buf[start:s.p])
	s.p++
	return result
}
func (s *scanner) nextLine() string {
	s.pre()
	start := s.p
	s.p = len(s.buf)
	return string(s.buf[start:])
}
func (s *scanner) nextInt() int {
	v, _ := strconv.Atoi(s.next())
	return v
}
func (s *scanner) nextInt64() int64 {
	v, _ := strconv.ParseInt(s.next(), 10, 64)
	return v
}
func (s *scanner) pre() {
	if s.p >= len(s.buf) {
		s.readLine()
		s.p = 0
	}
}
func (s *scanner) readLine() {
	s.buf = make([]byte, 0)
	for {
		l, p, e := s.r.ReadLine()
		if e != nil {
			panic(e)
		}
		s.buf = append(s.buf, l...)
		if !p {
			break
		}
	}
}


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

int main(){
	int n, m, p;
	int x[100];
	while(1){
		float ans = 0;
		for(int i=0; i < 100; i++) x[i] = 0;

		cin >> n >> m >> p;

		if((n | m | p) == 0) break;

		for(int i=0; i < n; i++){
			cin >> x[i];
			ans+= x[i];
		}
		if(x[m-1] == 0){
			cout << 0 << endl;
			continue;
		}

		ans *= (100.0 - p) / x[m-1];

		cout << (int)ans << endl;
	}

}

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

int main()
{
    int a,b;

    cin >> a >> b;
    if (a > b)
        cout << "a > b" << endl;
    else if ( a < b)
        cout << "a < b" << endl;
    else
        cout << "a == b" << endl;
	
}



Measured memory_bytes: 3100
def main():
    S = str(input())
    K = int(input())
    N = len(S)

    tmp = [[] for _ in range(26)]
    for i in range(N):
        tmp[ord(S[i]) - ord('a')].append(i)

    lst = []
    lst_append = lst.append
    s = set()
    s_add = s.add
    for num in tmp:
        for i in num:
            for j in range(i + 1, min(N, i + K) + 1):
                if S[i:j] in s:
                    continue
                else:
                    s_add(S[i:j])
                    lst_append(S[i:j])
        if len(s) >= K:
            lst.sort()
            print (lst[K - 1])
            # print (lst)
            return

if __name__ == '__main__':
    main()

Measured memory_bytes: 3316
#include<bits/stdc++.h>
using namespace std;
const int maxn = 5e5;
int a[maxn];
int main(){
    int n,m;
    while(~scanf("%d",&n)){
        memset(a,0,sizeof(a));
        for(int i=2;i<=n;i++){
            scanf("%d",&m);
            a[m]++;
        }
        for(int i=1;i<=n;i++){
            printf("%d\n",a[i]);
        }
    }
    return 0;
}




Measured memory_bytes: 5780
#include <iostream>

using namespace std;

int main (){
	int x, a, b;
	cin >> x >> a >> b;
	if(a >= b){
		cout << "delicious"<< endl;
	}else if(a+x>=b){
		cout << "safe" << endl;}
		else {
			cout << "dangerous"<< endl;
		}
	
	
	
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		boolean[] ans = new boolean[3];
		for(int i = 0 ; i < 3 ; i++) {
			ans[i] = true;
		}
		int a = Integer.parseInt(sc.next());
		int b = Integer.parseInt(sc.next());
		
		ans[a-1] = false;
		ans[b-1] = false;
		
		for(int i = 0 ; i < 3 ; i++) {
			if(ans[i]) {
				System.out.println(i+1);
			}
		}
	}



}


Measured memory_bytes: 23380
from collections import Counter
def main():
    n = int(input())
    S = input()
    C = Counter([s for s in S]).items()
    ans = 1
    if len (C) < 3:
        ans = 0
    for c in C:
        ans *= c[1]
    for i in range(n):
        mid = i + 1
        last = i + 2
        while last < n:
            if S[i] != S[mid] and S[mid] != S[last] and S[last] != S[i]:
                ans -= 1
            mid += 1
            last += 2
    print(ans)
main()

Measured memory_bytes: 9504
#入力
A, B, C, D = map(int, input().split())


#高橋の攻撃何発分か
if C % B == 0:
    aokiDeath = C // B
else:
    aokiDeath = C // B + 1 

#青木の攻撃何回分か
if A % D == 0:
    takahashiDeath = A // D
else:
    takahashiDeath = A // D + 1

if aokiDeath <= takahashiDeath:
    print("Yes")
else:
    print("No")


Measured memory_bytes: 9164
#include "bits/stdc++.h"
#define REP(i,n) for(int i=0;i< (n);i++)
#define REPR(i, n) for(int i = (n);i >= 0;i--)
#define FOR(i, m, n) for(int i = (m);i < (n);i++)
#define FORR(i, m, n) for(int i = (m);i >= (n);i--)
#define SORT(v, n) std::sort(v, v+n);
#define VSORT(v) std::sort(v.begin(), v.end());
#define VRSORT(v) std::sort(v.rbegin(), v.rend());
#define ll long long
#define pb(a) push_back(a)
#define ALL(obj) (obj).begin(),(obj).end()

using namespace std;

const int INF = 99999999;
const ll LINF = 9999999999999;

typedef pair<int, int> P;
typedef pair<ll, ll> LP;
int dx[4] = { 1,0,-1,0 };
int dy[4] = { 0,1,0,-1 };

//ll dfs(int n,ll count) {
//	ll a=99999;
//	ll roku = 1;
//	ll kyu = 1;
//	rokuが最大いくつ引けるか
//	while (pow(6, roku) < n) {
//		roku++;
//	}
//	roku--;
//	kyuが最大いくつ引けるか
//	while (pow(9, kyu) < n) {
//		kyu++;
//	}
//	kyu--;
//	if (roku != 0) {
//		a=min( dfs(n-pow(6,roku),count+1),a);
//	}
//	if (kyu != 0) {
//		a=min(dfs(n - pow(9, kyu), count + 1),a);
//
//	}
//	if (roku == 0 && kyu == 0) {
//		a=min(count + n,a);
//	}
//	return a;
//
//}

int main() {
	ll n;
	

	std::ios::sync_with_stdio(false);
	std::cin.tie(0);
	cin >> n;
	ll count = INF;
	REP(i, 20000) {
		REP(j, 20000) {
			ll kari = 0;
			if (6 * i + 9 * j > n)break;
			//n以下なら
			ll c = n - (6 * i + 9 * j);
			//cout << c << endl;
			if (c > 30)continue;
			//iとjから必要な引き出し回数を考える。
			ll start = 6;
			ll ix = i;
			while (start!=-1) {
			
				if (ix >= pow(6, start)) {
					ix -= pow(6, start);
					kari++;
				}
				else {
					start--;
				}
			}
			start = 6;
			ll jx = j;
			while (start != -1) {
				
				if (jx >= pow(9, start)) {
					jx -= pow(9, start);
					kari++;
				}
				else {
					start--;
				}
			}
			kari += c;

			//暫定最低値を出す
			count = min(kari, count);
		}
	}

	cout << count << endl;
	return 0;
}



Measured memory_bytes: 256
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<iostream>
#include<queue>
#include<vector>
#include <bitset>
using namespace std;
#define INF 110000000000
#define MOD 1000000007
typedef long long ll;
typedef pair<ll,int> P;



int main(){
  int A,B,Q;
  cin>>A>>B>>Q;
  vector<ll> s,t,x;
  ll temp;
  //cout<<"unko"<<endl;

  for(int i=0;i<A;i++){
    cin>>temp;
    s.push_back(temp);
  }
  //cout<<"unko"<<endl;

  for(int i=0;i<B;i++){
    cin>>temp;
    t.push_back(temp);
  }

  for(int i=0;i<Q;i++){
    cin>>temp;
    x.push_back(temp);
  }
  s.push_back(-20000000000);
  t.push_back(-20000000000);
  sort(s.begin(),s.end()); sort(t.begin(),t.end());
  //cout<<s[0]<<" "<<s[1]<<" "<<s[2]<<endl;
  s.push_back(20000000000);
  t.push_back(20000000000);
  for(int i=0;i<Q;i++){
    auto snum=lower_bound(s.begin(),s.end(),x[i]);
    auto tnum=lower_bound(t.begin(),t.end(),x[i]);
    
    ll s1=*snum,s2=*(snum-1),t1=*tnum,t2=*(tnum-1),ans;
    //cout<<s1<<" "<<s2<<endl;
    //cout<<t1<<" "<<t2<<endl;
    ans=max(s1,t1)-x[i];
    ans=min(ans,x[i]-min(s2,t2));
    ans=min(ans,min(x[i]-s2,t1-x[i])*2+max(x[i]-s2,t1-x[i]));
    ans=min(ans,min(x[i]-t2,s1-x[i])*2+max(x[i]-t2,s1-x[i]));
    cout<<ans<<endl;
  }
}


Measured memory_bytes: 3828
N, K = map(int, input().split())
A = list(map(int, input().split()))


# 上からi桁(0-indexed)のbitが立っているものがいくつあるか
bit_stand_counts = [0] * 40
for a in A:
    a = bin(a)[2:].zfill(40)
    for i in range(40):
        if a[i] == '1':
            bit_stand_counts[i] += 1


# 上からi番目のbitまでみたときに、dp[i][0]: K以下であることが未確定 dp[i][1]: K以下であることが確定 のときの最大値
dp = [[-1, -1] for i in range(41)]
dp[0][0] = 0


# Kをbitで表したもの
K_bit = bin(K)[2:].zfill(40)


for i in range(40):
    value_0 = (2 ** (39 - i)) * bit_stand_counts[i]  # i桁目を0にした時の報酬
    value_1 = (2 ** (39 - i)) * (N - bit_stand_counts[i])  # i桁目を1にした時の報酬
    
    if K_bit[i] == '0':  # Kの上からiビット目が0なら、K以下か未確定のほうは合わせるしかない
        dp[i + 1][0] = dp[i][0] + value_0
    else:
        dp[i + 1][0] = dp[i][0] + value_1
        dp[i + 1][1] = max(dp[i + 1][1], dp[i][0] + value_0)  # Kの上からiビット目が1ならK以下確定に飛べる

    if dp[i][1] != -1:  # K以下であることが確定しているなら、あとは貪欲にとれる
        dp[i + 1][1] = max(dp[i + 1][1], dp[i][1] + max(value_0, value_1))


print(max(dp[-1]))


Measured memory_bytes: 14464
#include<bits/stdc++.h>
using namespace std;
#define ar array
#define endl '\n'
#define ll long long
#define in insert
#define pb push_back
#define vt vector
#define P_Q(x) priority_queue<x>
#define p_q(x) priority_queue<x, vector<x>, greater<x>>
#define Rep(i,a,b) for(int i=a;i<=b;i++)
#define Rev(i,a,b) for(ll i=a;i>=b;i--)
#define FOR(m) Rep(i,1,m)
#define For(m) Rep(i,0,m-1)
#define Rbl(x,a) for(auto &x : a)
#define FIO ios::sync_with_stdio(0);   cin.tie(0);
#define F first
#define S second
#define pii pair<int,int>
#define pll pair<ll,ll>
#define mp make_pair
#define vpii vector<pii>
#define vpll vector<pll>
#define all(x) (x).begin(),(x).end()
#define sz(x) (int) (x).size()
const ll INF = 0x3f3f3f3f3f3f3f3fll;
#define mod 1000000007

ll n;
vector<ll> pre;
vector<ll> dp;

void rec(int i, const vector<int>& not_taken, ll score_so_far, int mask, int group) {
    if(i == (int) not_taken.size()) {
        dp[mask] = max(dp[mask], score_so_far + pre[group]);
        return;
    }
    rec(i + 1, not_taken, score_so_far, mask, group);
    rec(i + 1, not_taken, score_so_far, mask ^ (1 << not_taken[i]),
        group ^ (1 << not_taken[i]));
}


int main() 
{
FIO

    cin >> n;
    vector<vector<ll>> in(n, vector<ll>(n));
    for(int i = 0; i < n; ++i) {
        for(int j = 0; j < n; ++j) {
            cin >> in[i][j];
        }
    }
    pre.resize(1 << n);
    for(int mask = 0; mask < (1 << n); ++mask) {
        for(int i = 0; i < n; ++i) {
            if(mask & (1 << i)) {
                for(int j = i + 1; j < n; ++j) {
                    if(mask & (1 << j)) {
                        pre[mask] += in[i][j];
                    }
                }
            }
        }
    }

    dp.resize(1 << n, -INF);
    dp[0] = 0;

    for(int mask = 0; mask < (1 << n); ++mask) {
        vector<int> not_taken;
        for(int i = 0; i < n; ++i) {
            if(!(mask & (1 << i))) {
                not_taken.push_back(i);
            }
        }
        rec(0, not_taken, dp[mask], mask, 0);
    }
    cout <<  dp[(1<<n)-1] << endl;
}


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

const int mod = 1000000007;

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int n,k;
    cin >> n >> k;

    int sum = 0;
    vector<int> sum_front(n + 1), sum_back(n + 1);
    sum_front[0] = 0;
    sum_back[n] = n;
    for (int i = 1; i <= n; i++) {
        sum += i;
        sum_front[i] += sum_front[i - 1];
        sum_front[i] += i;
    }

    for (int i = n - 1; i >= 0; i--) {
        sum_back[i] += sum_back[i + 1];
        sum_back[i] += i;
    }

    int ans = 0;
    for (int i = k; i <= n + 1; i++) {
        int minv = sum_front[i - 1];
        int maxv = sum_back[n + 1 - i];

        int diff = maxv - minv + 1;
        ans += diff;
        ans %= mod;
    }

    cout << ans << endl;
}

Measured memory_bytes: 6336
#include<bits/stdc++.h>
using namespace std;
///Welcome to Nasif's Code
#define bug printf("bug\n");
#define bug2(var) cout<<#var<<" "<<var<<endl;
#define co(q) cout<<q<<endl;
#define all(q) (q).begin(),(q).end()
typedef long long int ll;
typedef unsigned long long int ull;
const int MOD = (int)1e9+7;
const int MAX = 1e6;
#define pi acos(-1)
#define inf 1000000000000000LL
#define FastRead    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int main()
{
    FastRead
    //freopen("output.txt", "w", stdout);
    int t;
    cin>>t;
    if(t==1)
        cout<<"Hello World"<<endl;
    else
    {
        int a,b;
        cin>>a>>b;
        cout<<a+b<<endl;
    }

    return 0;
}


Measured memory_bytes: 3656
#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long A,B,C,K,sum=0;
    cin>>A>>B>>C>>K;
    if(A>=K){
        cout << K ;
        return 0;
    }
    else
    {
        K-=A;
        sum+=A;
    }
    if(B>=K){
        cout << sum ;
        return 0;
    }
    else{
        K-=B;
    }
    if(C>=K){
        cout << sum-K ;
        return 0;
    }


    cout << sum;
    return 0;
}


Measured memory_bytes: 3588
#include <bits/stdc++.h>
#define int long long
#define endl '\n'
#define FOR(i, a, n) for (int i = (a); i < (n); ++i)
#define REP(i, n) FOR(i, 0, n)
using namespace std;

int dy[9] = {2, 1, 1, 0, 0, 0, -1, -1, -2};
int dx[9] = {1, 1, 2, 1, 2, 3, 1, 2, 1};
const int INF = 1 << 30;
int w, h;
int dis[60][30][2];
char s[60][30];

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    while (cin >> w >> h, w) {
        REP (i, h) REP (j, w) cin >> s[i][j];
        fill_n((int*)dis, 60 * 30 * 2, INF);
        using P = tuple<int, int, int, int>;
        priority_queue<P, vector<P>, greater<P>> que;
        vector<pair<int, int>> ts;
        REP (i, h) REP (j, w) {
            if (s[i][j] == 'S') {
                dis[i][j][0] = dis[i][j][1] = 0;
                que.emplace(0, i, j, 0);
                que.emplace(0, i, j, 1);
                s[i][j] = '0';
            } else if (s[i][j] == 'T') {
                s[i][j] = '0';
                ts.emplace_back(i, j);
            }
        }
        while (!que.empty()) {
            int dd, y, x, f;
            tie(dd, y, x, f) = que.top(); que.pop();
            if (dis[y][x][f] < dd) continue;
            REP (i, 9) {
                int ny = y + dy[i];
                int nx = x + dx[i] * (f == 0 ? 1 : -1);
                if (ny >= 0 && ny < h && nx >= 0 && nx < w && s[ny][nx] != 'X') {
                    if (dis[ny][nx][f ^ 1] > dis[y][x][f] + (s[y][x] - '0')) {
                        dis[ny][nx][f ^ 1] = dis[y][x][f] + (s[y][x] - '0');
                        que.emplace(dis[ny][nx][f ^ 1], ny, nx, f ^ 1);
                    }
                }
            }
        }
        int ans = INF;
        for (auto t : ts) ans = min({ans, dis[t.first][t.second][0], dis[t.first][t.second][1]});
        cout << (ans == INF ? -1 : ans) << endl;
    }
}


Measured memory_bytes: 3248
#include<iostream>
#include<cstdio>
using namespace std;
int mod=1000000007;
int main()
{
	long long n;
	scanf("%lld",&n);
	long long ans=1%mod;
	long long sum=1%mod;
	long long tot=1%mod;
	for(int i=1;i<=n;i++)
	{
		ans=ans*10%mod;
	}
	for(int i=1;i<=n;i++)
	{
		sum=sum*9%mod;
	}
	for(int i=1;i<=n;i++)
	{
		tot=tot*8%mod;
	}
	printf("%lld",(ans+mod-(sum*2%mod-tot)%mod)%mod);
	return 0;
}

Measured memory_bytes: 3784
s= list(input())
s=set(s)
if len(s)%2==1:
    print('No')
else:
    if len(s) == 2:
        if "W" in s and "E" in s or "S" in s and "N" in s:
            print("Yes")
        else:
            print('No')
    else:
        print('Yes')


Measured memory_bytes: 61764
n,m=map(int,input().split())
s=[list(map(int,input().split())) for _ in range(n)]
m=[list(map(int,input().split())) for _ in range(m)]
for i in s:
  a,b=i[0],i[1]
  md=[abs(c[0]-a)+abs(c[1]-b) for c in m]
  print(md.index(min(md))+1)

Measured memory_bytes: 3064
N,M = map(int, input().split())
ng = set()
for i in range(M):
  ng.add(int(input()))
  
dp = [0] * (N + 5)
dp[0] = 1

for i in range(N):
  if i + 1 not in ng:
    dp[i + 1] += dp[i]
    dp[i + 1] %= 1000000007
  if i + 2 not in ng:
    dp[i + 2] += dp[i]
    dp[i + 2] %= 1000000007

print(dp[N])

Measured memory_bytes: 17188