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

int max(int a,int b);
int max(int a, int b) {
	if (a < b) { return b; }
	else { return a; }
}

int main() {
	
	vector<int> a(5),b(5);
	cin >> a.at(0) >> a.at(1) >> a.at(2) >> a.at(3) >> a.at(4);
	int min = 9;
	int j=0;

	for (int i = 0;i < 5;i++) {
		if (a.at(i) % 10 != 0 && a.at(i) % 10 <= min) {
			j = i;
			min = a.at(i)%10;
		}
		b.at(i) = a.at(i);
	}

	b.at(j) = 0;
	int time;
	time =10 * ((b.at(0) - 1) / 10 + (b.at(1) - 1) / 10 + (b.at(2) - 1) / 10
		+ (b.at(3) - 1) / 10 + (b.at(4) - 1) / 10) + a.at(j) + 40;

	cout << time << endl;

	return 0;
}

Measured memory_bytes: 256
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<iostream>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<sstream>
#include<unordered_map>
#include<unordered_set>
#include<vector>
using namespace std;
using uint = unsigned int;
using ll = long long;
const int M = 1e9 + 7;
const ll MLL = 1e18L + 9;
#pragma unused(M)
#pragma unused(MLL)
#ifdef LOCAL
#include"rprint.hpp"
#else
template <ostream& out = cout, class... T> void prints(T&&...){ }
template <ostream& out = cout, class... T> void printd(T&&...){ }
template <ostream& out = cout, class... T> void printb(T&&...){ }
template <ostream& out = cout, class... T> void printArr(T&&...){ }
#endif

int main(){
    int r, g, b;
    cin >> r >> g >> b;
    cout << ((r * 100 + g * 10 + b) % 4 == 0 ? "YES" : "NO") << '\n';
    return 0;
}


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

int n;

int main()
{
    scanf("%d",&n);
    int ans = 0;
    for(int i = 1;i <= n;i++)
    {
        for(int j = 1;j<=n;j++)
        {
            int temp = __gcd(i,j);
            for(int k = 1;k<=n;k++)
            {

                ans+=__gcd(k,temp);
            }
        }
    }
    cout<<ans<<endl;
    return 0;
}


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

#define endl '\n'
#define fi first
#define se second
#define MOD(n,k) ( ( ((n) % (k)) + (k) ) % (k))
#define forn(i,n) for (int i = 0; i < n; i++)
#define forr(i,a,b) for (int i = a; i <= b; i++)
#define all(v) v.begin(), v.end()
#define pb(x) push_back(x)

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> ii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ii> vii;

const int MX = 200005, mod = 998244353;
int n, m, k;
ll fac[MX], inv[MX], res;

ll pot (ll b, int p) {
	ll res = 1;
	while (p) {
		if (p & 1) (res *= b) %= mod;
		(b *= b) %= mod;
		p /= 2;
	}
	return res;
}

ll comb (int n, int k) {
	return fac[n] * inv[n - k] % mod * inv[k] % mod;
}

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

	fac[0] = inv[0] = 1;
	for (int i = 1; i < MX; i++) {
		fac[i] = fac[i - 1] * i % mod;
		inv[i] = pot(fac[i], mod - 2);
	}

	cin >> n >> m >> k;

	for (int i = 0; i <= k; i++) {
		res += m * comb(n - 1, i) % mod * pot(m - 1, n - 1 - i);
		res %= mod;
	}

	cout << res << endl;

	return 0;
}

Measured memory_bytes: 6776
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#define maxn 100000+5
using namespace std;
int main(){
   int n,k;
   cin>>n>>k;
   int ans=1;
   while(n>0){
    if(ans>k)
        ans=ans+k;
    else ans=ans*2;
    n--;
   }
   cout<<ans<<endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int n,k,arr[200001];

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

    for(int i=0;i<n;i++)
    {
    	cin>>arr[i+1];
    	arr[i+1]+=arr[i];
	}
	int sum=0;
	for(int i=k;i<=n;i++)
	{ sum=max(sum,arr[i]-arr[i-k]);
		}
	  
		cout << fixed << setprecision(9) << (double)(sum+k)/2.0;
 
}

Measured memory_bytes: 4460
#include <iostream>
#include <vector>
#include <numeric>
#include <algorithm>
#include <cmath>
#include <climits>
#include <unordered_set>

constexpr int SINT_MAX = std::numeric_limits<int>::max();
constexpr int SINT_MIN = std::numeric_limits<int>::min();

#define YesNo(b) ((b) ? "Yes" : "No")
#define YESNO(b) ((b) ? "YES" : "NO")

using namespace std;
using vi = vector<int>;
using vvi = vector<vi>;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vll>;



int main()
{
    int N;
    cin >> N;
    unordered_set<string> bucket;
    string bufS;
    for (int i = 0; i < N; i++)
    {
        cin >> bufS;
        bucket.insert(bufS);
    }
    
    size_t ans = bucket.size();
    cout << ans << endl;
}

Measured memory_bytes: 17788
import std.stdio, std.conv, std.functional, std.string;
import std.algorithm, std.array, std.container, std.range, std.typecons;
import std.bigint, std.numeric, std.math, std.random;
import core.bitop;

string FMT_F = "%.10f";

static File _f;
void file_io(string fn) { _f = File(fn, "r"); }
static string[] s_rd;
T _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
T _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
T[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }
T[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }
T RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }
T[] RDA(T = long)(T fix = 0) { if (_f.isOpen)  return _RDA!T(_f, fix); else return _RDA!T(fix); }

size_t[] MAKE_IDX(alias less = "a < b", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}
size_t MIN_POS(alias less = "a < b", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }

void chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }
bool inside(T)(T x, T b, T e) { return x >= b && x < e; }
long lcm(long x, long y) { return x * (y / gcd(x, y)); }

long mod = 10^^9 + 7;
//long mod = 998244353;
//long mod = 1_000_003;
void moda(ref long x, long y) { x = (x + y) % mod; }
void mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }
void modm(ref long x, long y) { x = (x * y) % mod; }

void main()
{
	auto N = RD;
	auto K = RD;
	auto R = RD;
	auto S = RD;
	auto P = RD;
	auto T = RD!string;

	long ans;
	auto hand = ['r':'p', 's':'r', 'p':'s'];
	auto point = ['r':R, 's':S, 'p':P];
	auto a = new char[](N);
	foreach_reverse (i; 0..N)
	{
		if (i+K >= N)
		{
			a[i] = hand[T[i]];
			ans += point[a[i]];
		}
		else
		{
			auto h = hand[T[i]];
			if (a[i+K] != h)
			{
				a[i] = h;
				ans += point[h];
			}
		}
	}

	writeln(ans);
	stdout.flush;
	debug readln;
}

Measured memory_bytes: 2556
#include<bits/stdc++.h>
using namespace std;
typedef complex<double> P;
typedef vector<P> vec;

double eps=1e-8;
double PI=acos(-1);

bool eq(double a,double b){return (b-a<eps&&a-b<eps);}
double dot(P a,P b){return real(b*conj(a));}
double cross(P a,P b){return imag(b*conj(a));}
P project(P a,P b,P c){b-=a;c-=a;return a+b*real(c/b);}
P reflect(P a,P b,P c){b-=a;c-=a;return a+conj(c/b)*b;}
int ccw(P a,P b,P c){
  b-=a,c-=a,a=c*conj(b);
  if(a.imag()>eps)return 1;//ccw
  if(a.imag()<-eps)return -1;//cw
  if(a.real()<-eps)return 2;//ob
  if(abs(b)+eps<abs(c))return -2;//of
  return 0;//os
}

//segment ab , point c
double dist(P a,P b,P c){
  if(dot(b-a,c-a)<0)return abs(c-a);
  if(dot(a-b,c-b)<0)return abs(c-b);
  return abs(cross(b-a,c-a))/abs(b-a);
}

bool isintersect(P a,P b,P c,P d){
  return ((ccw(a,b,c)*ccw(a,b,d)<=0)&&(ccw(c,d,a)*ccw(c,d,b)<=0));
}

//segment ab , segment cd
P intersect(P a,P b,P c,P d){
  a-=d;b-=d;c-=d;
  return d+a+(b-a)*imag(a/c)/imag(a/c-b/c);
}

double dist(P a,P b,P c,P d){
  if(isintersect(a,b,c,d))return 0;
  double ab=min(dist(a,b,c),dist(a,b,d));
  double cd=min(dist(c,d,a),dist(c,d,b));
  return min(ab,cd);
}

double calcArea(vec &t){
  double res=0;
  int n=t.size();
  for(int i=0;i<n;i++)res+=cross(t[i],t[(i+1==n?0:i+1)]);
  return abs(res/2.0);
}

double Arg(P a,P b,P c){
  b-=a,c-=a;
  return arg(c*conj(b));
}

int inPolygon(vec &t,P p){
  int n=t.size();
  double sum=0;
  for(int i=0;i<n;i++){
    P a=t[i],b=t[(i+1==n?0:i+1)];
    if( ccw(a,b,p) == 0 )return 1;
    sum+= Arg(p,a,b);
  }
  if( abs(sum) < eps )return 0;
  else  return 2;
}

int main(){
  int n;
  cin>>n;
  vec t;
  double x,y;
  for(int i=0;i<n;i++){
    cin>>x>>y;
    t.push_back(P(x,y));
  }
  int q;
  cin>>q;
  while(q--){
    cin>>x>>y;
    cout<<inPolygon(t,P(x,y))<<endl;
  }

  return 0;
}

Measured memory_bytes: 1336
// include
// ------------------------------------------------
#include <bits/stdc++.h>
#include <vector>
#include <algorithm>
#include <math.h>

using namespace std;

// func
// ------------------------------------------------
int CalcSumOfDigit(int n);      // 各桁の和を計算する。
string upper(string str);       // 英字を大文字に変換する。
string lower(string str);       // 英字を小文字に変換する。

// define
// ------------------------------------------------
#define all(a)        (a).begin(),(a).end()
#define rall(a)       (a).rbegin(),(a).rend()
#define pb            push_back
#define sz(a)         int((a).size())
#define rep(i,n)      for(int(i)=0;(i)<(n);(i)++)
#define repe(i,n)     for(int(i)=0;(i)<=(n);(i)++)
#define vsort(v)      sort((v).begin(),(v).end())
#define rvsort(v)     sort(rall((v)))
#define vi            vector<int>

const int INF = 1e9;

// code
// ------------------------------------------------
int main() {

  int r,g;

  cin >> r >> g;

  cout << 2 * g - r;

  return 0;
}

// funcの実体
// ------------------------------------------------
int CalcSumOfDigit(int n)
{
  int s = 0;
  while(n)
  {
    s += n % 10;
    n = n / 10;
  }
  return s;
}

string upper(string str)
{
  for(auto itr = str.begin();itr != str.end() ; itr++)
  {
    if(97 <= *itr && *itr <= 122)
    {
      *itr = *itr - 32;
    }
  }
  return str;
}

string lower(string str)
{
  for(auto itr = str.begin();itr != str.end() ; itr++)
  {
    if(65 <= *itr && *itr <= 90)
    {
      *itr = *itr + 32;
    }
  }
  return str;
}


Measured memory_bytes: 256
S = str(input())

# 桁数
N = len(S)
MOD = 10**9 + 7

# dp[i][j] := Sの上からi桁目までを考えた時、それを13で割った余りがjになる方法の数
dp = [[0 for _ in range(13)]for _ in range(N + 1)]

# １桁目について
if S[0] == "?":
    # ?に0, 1, ..., 9を入れることができる
    for i in range(10):
        dp[1][i] = 1
else:
    dp[1][int(S[0])] = 1

# 1, 2, ..., N-1桁から、
# 2, 3, ..., N桁についての遷移を考える
for i in range(1, N):
    for j in range(13):
        if S[i] == "?":
            for k in range(10):
                dp[i + 1][(j * 10 + k) % 13] += dp[i][j]
                dp[i + 1][(j * 10 + k) % 13] %= MOD
        else:
            dp[i + 1][(j * 10 + int(S[i])) % 13] += dp[i][j]
            dp[i + 1][(j * 10 + int(S[i])) % 13] %= MOD

print(dp[N][5] % MOD)


Measured memory_bytes: 96316
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
int main() {
  ll a;
  cin>>a;
  ll b=0;
  for(ll i=1;i<a;i++){
    for(ll j=1;j<a;j++){
      if(a>i*j){
        b+=1;
      }
      else{
        break;
      }
    }
  }
  cout<<b<<endl;
  
  return 0;
}

Measured memory_bytes: 3632
#include "bits/stdc++.h"

using namespace std;

using ll = long long;
using ld = long double;

const int INF = (1 << 30) - 1;
const ll INF64 = ((ll)1 << 62) - 1;
const double PI = 3.1415926535897932384626433832795;

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

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

	int a, b;
	cin >> a >> b;

	cout << (a > 8 || b > 8 ? ":(" : "Yay!") << endl;
	return 0;
}


Measured memory_bytes: 256
import std.stdio, std.conv, std.functional, std.string;
import std.algorithm, std.array, std.container, std.range, std.typecons;
import std.numeric, std.math, std.random;
import core.bitop;

string FMT_F = "%.10f";

static string[] s_rd;
T RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
string RDR()() { return readln.chomp; }
T[] ARR(T = long)(in string str, T fix = 0) { auto r = str.split.to!(T[]); r[] += fix; return r; }
size_t[] MAKE_IDX(alias less = "a < b", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}
size_t MIN_POS(alias less = "a < b", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }

bool inside(T)(T x, T b, T e) { return x >= b && x < e; }
bool minimize(T)(ref T x, T y) { if (x > y) { x = y; return true; } else { return false; } }
bool maximize(T)(ref T x, T y) { if (x < y) { x = y; return true; } else { return false; } }
long lcm(long x, long y) { return x * y / gcd(x, y); }

long mod = 10^^9 + 7;
void moda(ref long x, long y) { x = (x + y) % mod; }
void mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }
void modm(ref long x, long y) { x = (x * y) % mod; }

void main()
{
	auto N = RD;
	auto s = new string[](N);

	foreach (i; 0..N)
	{
		s[i] = RD!string;
	}

	long cnt_ab;
	long cnt_a, cnt_b, cnt_a_b;
	foreach (i; 0..N)
	{
		foreach (j; 1..s[i].length)
		{
			if (s[i][j-1] == 'A' && s[i][j] == 'B')
			{
				++cnt_ab;
			}
		}
		if (s[i][$-1] == 'A' && s[i][0] == 'B')
		{
			++cnt_a_b;
		}
		else
		{
			if (s[i][$-1] == 'A')
				++cnt_a;
			if (s[i][0] == 'B')
				++cnt_b;
		}
	}
	auto ans = max(0, cnt_a_b - 1);
	if (cnt_a_b != 0)
	{
		if (cnt_a != 0)
		{
			++ans;
			--cnt_a;
		}
		if (cnt_b != 0)
		{
			++ans;
			--cnt_b;
		}
	}
	ans += min(cnt_a, cnt_b);
	ans += cnt_ab;

	writeln(ans);
	stdout.flush();
	debug readln();
}

Measured memory_bytes: 2940
from itertools import product

N, M = [int(elem) for elem in input().split(' ')]
coord_list = [[int(elem) for elem in input().split(' ')] for _ in range(N)]
assert len(coord_list) == N
assert len(coord_list[0]) == 3

max_total = 0
for f_x, f_y, f_z in product([-1, 1], repeat=3):
    sum_list = [(f_x * x + f_y * y + f_z * z, i) for i, (x, y, z) in enumerate(coord_list)]
    # sort with index
    sum_list = sorted(sum_list, key=lambda x: x[0])[::-1]
    total_x, total_y, total_z = 0, 0, 0
    for _, idx in sum_list[:M]:
        total_x += coord_list[idx][0]
        total_y += coord_list[idx][1]
        total_z += coord_list[idx][2]
    total = abs(total_x) + abs(total_y) + abs(total_z)
    max_total = max(total, max_total)

print(max_total)


Measured memory_bytes: 3564
#include<iostream>
#include<string>
#include <algorithm>
using namespace std;
int main()
{
	string s;
	string ma;
	int pl = 0;
	bool flag = false;
	getline(cin, s);
	replace(s.begin(), s.end(), ',', ' ');
	replace(s.begin(), s.end(), '.', ' ');
	for (int i = 0; i < s.size(); i++){
		if (s[i] == ' ' || s[i] == '\n'){
			if (ma.size() >= 3 && ma.size() <= 6){
				if (flag){
					cout << " ";
				}
				flag = true;
				cout << ma;
			}
		ma.clear();
		}
		else{
			ma += s[i];
		}
	}
	cout << endl;
}

Measured memory_bytes: 1168
#include <iostream>
#include <algorithm>
#include <queue>
#include <utility>

int h, w;
bool s[55][55];
int black;

int d[55][55];
bool used[55][55];
constexpr int dx[] = { 1,0,-1,0 };
constexpr int dy[] = { 0,1,0,-1 };
constexpr int inf = 999999999;
using P = std::pair<int, std::pair<int, int>>;
int main() {
	std::cin >> h >> w;
	for (int i = 0; i < h; ++i)
		for (int j = 0; j < w; ++j) {
			char c;
			std::cin >> c;
			s[i][j] = (c == '.');
			if (!s[i][j])
				++black;
		}
	for (int i = 0; i < h; ++i)
		for (int j = 0; j < w; ++j)
			d[i][j] = inf;
	std::priority_queue<P, std::vector<P>, std::greater<P>> que;
	d[0][0] = 0;
	que.emplace(0, std::pair<int, int>(0, 0));
	while (!que.empty()) {
		auto p = que.top();
		que.pop();
		auto v = p.second;
		if (d[v.first][v.second] < p.first)
			continue;
		for (int i = 0; i < 4; ++i) {
			auto ex = v.first + dx[i], ey = v.second + dy[i];
			if (ex < 0 || ex >= h || ey < 0 || ey >= w || !s[ex][ey])
				continue;
			if (d[ex][ey] > d[v.first][v.second] + 1) {
				d[ex][ey] = d[v.first][v.second] + 1;
				que.emplace(d[ex][ey], std::pair<int, int>(ex, ey));
			}
		}
	}
	if (d[h - 1][w - 1] == inf)
		std::cout << -1 << std::endl;
	else
		std::cout << h * w - d[h - 1][w - 1] - 1 - black << std::endl;
	return 0;
}


Measured memory_bytes: 256
# key not available ""
n = int(input())
matrix = []
for _ in range(n):
    matrix.append([int(i) for i in input().split()])
dp = [[0 for i in range(3)] for j in range(n)]
for i in range(3):
    dp[0][i] = matrix[0][i]
for i in range(1,n):
    for j in range(3):
        if j == 0:
            dp[i][j] = max(dp[i-1][j+1],dp[i-1][j+2])+matrix[i][j]
        elif j == 1:
            dp[i][j] = max(dp[i-1][j+1],dp[i-1][j-1])+matrix[i][j]
        else:
            dp[i][j] = max(dp[i-1][j-1], dp[i-1][j-2]) + matrix[i][j]
print(max(dp[-1]))



Measured memory_bytes: 75736
n = int(input())
M = [[0 for i in range(n)] for j in range(n)]

for i in range(n):
    _ = list(map(int, input().split()))
    u = _[0] - 1  # 0オリジンに変換

    degree = _[1]
    for j in range(degree):
        v = _[j+2] - 1  # 0オリジンに変換
        M[u][v] = 1

for row in M:
    print(' '.join(map(str, row)))



Measured memory_bytes: 5680
def fib(n):
    if n == 1 or n == 2:
        return 1
    else:
        a = 1
        b = 0
        for _ in range(n-1):
            (a, b) = (a+b, a)
        return a % (10 ** 9 + 7)


def counter(n):
    if n == 0:
        return 0
    else:
#        f = round(phi**(n) / math.sqrt(5)) % (10**9+7)
        return fib(n)


N, M = map(int, input().split())
a = [int(input()) for _ in range(M)]
if M == 0:
    print(counter(N+1))
    exit()
a.append(N+1)
ans = counter(a[0])
for i in range(1,M+1):
    ans = (ans * counter(a[i]-a[i-1]-1)) % (10**9+7)
print(ans)

Measured memory_bytes: 7080
#include <iostream>
#include <cctype>
#include <algorithm>
#include <vector>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <utility>
#include <string>
#include <functional>
#include <cctype>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <iomanip>
#define pb push_back 
#define YES cout<<"YES"<<endl
#define Yes cout<<"Yes"<<endl
#define NO cout<<"NO"<<endl
#define No cout<<"No"<<endl
#define INF (1<<30)
#define MOD 1000000007
using ll = long long;
using namespace std;

int main() {
    int n;
    cin >> n;
    if (n % 2 == 0)cout << n << endl;
    else cout << n * 2 << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <cassert>
#include <climits>
#include <string>
#include <bitset>
#include <cfloat>
#include <unordered_set>
#include <iomanip>
//#pragma GCC optimize("Ofast")  //デバッグ時にoptimized-outされて邪魔だった
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef vector<pair<int,int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<string> > vvs;
typedef vector<vector<ll> > vvll;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define irep(it, stl) for(auto it = stl.begin(); it != stl.end(); it++)
#define drep(i,n) for(int i = (n) - 1; i >= 0; --i)
#define fin(ans) cout << (ans) << '\n'
#define mp(p,q) make_pair(p, q)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define floatprec(dig) fixed << setprecision(dig)
#define Sort(a) sort(a.begin(), a.end())
#define Rort(a) sort(a.rbegin(), a.rend())
#define MATHPI acos(-1)
#define itn int;
#define invar(typ, var) typ var; cin >> var;
int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
template <class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;} return 0;}
template <class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;} return 0;}
struct io{io(){ios::sync_with_stdio(false);cin.tie(0);}};
const int INF = INT_MAX;
const ll LLINF = 1LL<<60;
const ll MOD = 1000000007;
const double EPS = 1e-9;

signed main(void) {
  cin.tie(0); ios::sync_with_stdio(false);
  
  invar(int, N);invar(int, M);
  
  ll res = (N >= 0 ? N * (N-1) / 2 : 0) +
    (M >= 0 ? M * (M-1) / 2 : 0);
    
  fin(res);
}

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

using namespace std;

long long dp[108][100008];

long long getKnapsack(vector<long long> &W, vector<long long> &V, long long weight, long long i)
{
    if(i < 0)
        return 0;
    if(dp[i][weight] != -1)
        return dp[i][weight];
    if(W[i] > weight)
        dp[i][weight] = getKnapsack(W, V, weight, i - 1);
    else
        dp[i][weight] = max(V[i] + getKnapsack(W, V, weight - W[i], i - 1), getKnapsack(W, V, weight, i - 1));
    return dp[i][weight];
}

int main()
{
	long long n, w;
    cin>>n>>w;
    memset(dp, -1, sizeof(dp));
    vector<long long> W(n), V(n);
    for(int i = 0; i < n; ++i)
        cin>>W[i]>>V[i];
    cout<<getKnapsack(W, V, w, n - 1);
    return 0;
}

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

using namespace std;
using llong = long long int;

#define rep(i, n) for (int i = 0; i < n; ++i)
#define stl_rep(itr, x) for (auto itr = x.begin(); itr != x.end(); ++itr)
#define all(x) x.begin(), x.end()
#define allr(x) x.rbegin(), x.rend()

const static int MOD = 1000000007;
const static int INF = 1000000000;
const static int dx[4] = {1, 0, -1, 0};
const static int dy[4] = {0, 1, 0, -1};

int main (int argc, char *argv[]) {
    cin.tie(0);
    ios::sync_with_stdio(false);

    int x, n;
    cin >> x >> n;
    vector<int> P(n);
    rep(i, n) cin >> P[i];

    vector<int> num(103, 1);
    rep(i, n) {
        num[P[i] + 1] = 0;
    }

    int l = x + 1, r = x + 1;
    int ans;
    while (1) {
        if (num[l]) {
            ans = l - 1;
            break;
        }
        if (num[r]) {
            ans = r - 1;
            break;
        }
        l = max(0, l - 1);
        r = min(102, r + 1);
    }

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

Measured memory_bytes: 3672
from scipy.sparse.csgraph import shortest_path, floyd_warshall, dijkstra, bellman_ford, johnson, minimum_spanning_tree
from scipy.sparse import csr_matrix, coo_matrix, lil_matrix
import numpy as np
from functools import reduce

from collections import deque, Counter, defaultdict
from itertools import product, permutations,combinations
from operator import itemgetter
from heapq import heappop, heappush
from bisect import bisect_left, bisect_right, bisect
from fractions import gcd
from math import ceil,floor, sqrt, cos, sin, pi, factorial
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10**8)
INF = float('inf')
MOD = 10**9+7

def main():
  n, k = map(int, readline().split())
  if k&1:
    ans = (n//k)**3
  else:
    kk = k//2
    even = n//k
    odd = n//kk -even
    ans = even**3 + odd**3
  print(ans)
  
  
  
  
  
if __name__ == '__main__':
  main()

Measured memory_bytes: 14548
//
//  main.cpp
//  ProgrammingContestChallengeBook2
//
//  Created by Hisaki Kobayashi on 2020/04/04.
//  Copyright © 2020 Hisaki Kobayashi. All rights reserved.
//

#include <iostream>
#include <stdio.h>
#include <string>
#include <bits/stdc++.h>
#include <stdlib.h>


using namespace std;

int main(){
    string S;
    cin >> S ;
    if(S[2]==S[3] && S[4]==S[5])
        cout << "Yes" << endl;
    else{
        cout << "No" << endl;
    }
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main{
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        int a = Integer.parseInt(sc.next());
        int b = Integer.parseInt(sc.next());
        int result = 0;
        int sum;
        for(int i=1;i<=n;i++){
            sum = sum(i);
            if(a<=sum && sum<=b){result+=i;}
        }
        System.out.println(result);
        // System.out.println(sum(12123));
    }

    private static int sum(int a){
        int sum = 0;
        do {
            sum += (a%10);
            a = a/10;
        } while (a>0);
        return sum;
    }
}

Measured memory_bytes: 21844
import java.util.Scanner;

public class Main {
		public static void main(String[] args) {
			Scanner sc = new Scanner(System.in);
			int a = sc.nextInt();
			int b = sc.nextInt();
			int c = sc.nextInt();
			if (a <= b && b <= c)
				System.out.printf("%d %d %d\n", a, b, c);
			else if (a <= c && c <= b)
				System.out.printf("%d %d %d\n", a, c, b);
			else if (b <= a && a <= c)
				System.out.printf("%d %d %d\n", b, a, c);
			else if (b <= c && c <= a)
				System.out.printf("%d %d %d\n", b, c, a);
			else if (c <= a && a <= b)
				System.out.printf("%d %d %d\n", c, a, b);
			else if (c <= b && b <= a)
				System.out.printf("%d %d %d\n", c, b, a);
		}
}

Measured memory_bytes: 26248
#include <iostream>
#include <vector>
#include <stack>
#include <queue>
#include <algorithm>
#include <string>
#include <bitset>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <sstream>
#include <fstream>
#include <tuple>
#include <set>
#include <functional> 
#include <string.h>

#define X first
#define Y second
#define MP make_pair
#define MT make_tuple
#define FOR(i, n) for(int (i) = 0; (i) < (n); (i)++)
#define REP(i, a, n) for(int (i) = (a); (i) < (n); (i)++)
typedef long long ll;
typedef std::pair<int, int> pii;
typedef std::pair<ll, ll > pll;
using namespace std;
const int MAX = 101;
const double PI = 3.1415926535897932384;

template<class T, class U>
void convert(T &t, U &u){
	stringstream ss;
	ss << t;
	ss >> u;
}

bool edge[31][11][11]; //[段数][from][to]

bool isCorrect(int n, int m, int d, int target){
	FOR(i, d){
		bool f = false;
		if (m > 0){
			if (edge[i][m][m - 1]){
				m--;
				f = true;
			}
		}
		if (m < n - 1){
			if (edge[i][m][m + 1] && !f){
				m++;
			}
		}
	}

	return (m == target) ? true : false;
}

int main(){
	int n;
	while (cin >> n && n != 0){
		memset(edge, false, sizeof(edge));

		int m; cin >> m; --m;
		int target; cin >> target; --target;
		int d; cin >> d;

		if (n > 1){
			FOR(i, d){
				string t; cin >> t;
				FOR(j, n - 1){
					if (t[j] == '1'){
						edge[i][j][j + 1] = true;
						edge[i][j + 1][j] = true;
					}
				}
			}
		}

		if (isCorrect(n, m, d, target)){
			cout << 0 << endl;
			continue;
		}

		bool f = false;
		FOR(i, d){
			FOR(j, n - 1){
				if (!edge[i][j][j + 1]){
					if (j > 0 && edge[i][j - 1][j]) continue;
					if (j < n - 2 && edge[i][j + 1][j + 2]) continue;

					edge[i][j][j + 1] = true;
					edge[i][j + 1][j] = true;

					if (isCorrect(n, m, d, target)){
						cout << i + 1 << " " << j + 1 << endl;
						f = true;
						break;
					}

					edge[i][j][j + 1] = false;
					edge[i][j + 1][j] = false;
				}
			}
			if (f) break;
		}

		if(!f) cout << 1 << endl;
	}
	return 0;
}

Measured memory_bytes: 1212
#include <bits/stdc++.h>
#include<string>
using namespace std;
#define ll long long
#define ld long double
#define endl '\n'
#define FAST ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
const int maxn=2*1e5+5;

int main()
{
    FAST
int x;
cin>>x;

    string a,b;
    cin>>a>>b;
    string h;
    for(int i=0;i<x;i++)
    {
      h.push_back(a[i]);
      h.push_back(b[i]);

    }
    cout<<h<<endl;
    return 0;
}


Measured memory_bytes: 256
n = int(input())
data = list(map(int, input().split()))
counter = 0
for i in range(n-1, 0, -1):
    for j in range(i):
        if data[j] > data[j+1]:
            tmp = data[j]
            data[j] = data[j+1]
            data[j+1] = tmp
            counter += 1
print(*data)
print(counter)



Measured memory_bytes: 5604
#include <bits/stdc++.h>
using namespace std;
/* typedef */
typedef long long ll;
/* constant */
const int INF = 1 << 30;
const int NIL = -1;
const int MAX = 10000;
const int mod = 1000000007;
const double pi = 3.141592653589;
struct mint {
    ll x;
    mint(ll x = 0):x((x % mod + mod) % mod) {}
    mint operator-() const { return mint(-x); }
    mint& operator+=(const mint a) {
        if ((x += a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator-=(const mint a) {
        if ((x += mod - a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator*=(const mint a) {
        (x *= a.x) %= mod;
        return *this;
    }
    mint operator+(const mint a) const {
        mint res(*this);
        return res += a;
    }
    mint operator-(const mint a) const {
        mint res(*this);
        return res -= a;
    }
    mint operator*(const mint a) const {
        mint res(*this);
        return res *= a;
    }
    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t >> 1);
        a *= a;
        if (t & 1) a *= *this;
        return a;
    }

    // for prime mod
    mint inv() const {
        return pow(mod - 2);
    }
    mint& operator/=(const mint a) {
        return (*this) *= a.inv();
    }
    mint operator/(const mint a) const {
        mint res(*this);
        return res /= a;
    }
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}
struct combination {
    // vector size : n + 1
    vector<mint> fact, ifact;
    // precaliculation O(n)
    combination(int n):fact(n+1), ifact(n+1) {
        assert(n < mod);
        // 0! = 1;
        fact[0] = 1;
        // 1! = 0! * 1 ... n! = (n-1)! * n
        for (int i = 1; i <= n; i++) fact[i] = fact[i-1] * i;
        // 1/n! = n!^(-1)
        ifact[n] = fact[n].inv();
        // (n-1)!^(-1) = n!^(-1) * n ... 0!^(-1) = 1!^(-1) * 1
        for (int i = n; i >= 1; --i) ifact[i-1] = ifact[i] * i;
    }
    // combination O(1)
    // nCk = n! / (k! * (n-k)!)
    //     = n! * k!^(-1) * (n-k)!^(-1)
    mint operator()(int n, int k) {
        if (k < 0 || k > n) return 0;
        return fact[n] * ifact[k] * ifact[n-k];
    }
};
/* global variables */
/* function */
/* main */
int main() {
    int n, k;
    cin >> n >> k;
    if (n > k) {
        cout << 0 << '\n';
    }
    else {
        cout << 1 << '\n';
    }
}


Measured memory_bytes: 3092
#include <iostream>
#include <algorithm>
#include <queue>
//#define _DEBUG
using namespace std;

const int kNext[20][3] = {
  {5, 1, 4},    // 0
  {6, 2, 0},    // 1
  {7, 3, 1},    // 2
  {8, 4, 2},    // 3
  {9, 0, 3},    // 4
  {0, 10, 11},  // 5
  {1, 11, 12},  // 6
  {2, 12, 13},  // 7
  {3, 13, 14},  // 8
  {4, 14, 10},  // 9
  {15, 5, 9},   // 10
  {16, 6, 5},   // 11
  {17, 7, 6},   // 12
  {18, 8, 7},   // 13
  {19, 9, 8},   // 14
  {10, 19, 16}, // 15
  {11, 15, 17}, // 16
  {12, 16, 18}, // 17
  {13, 17, 19}, // 18
  {14, 18, 15}  // 19
};

struct QNode {
  int x, y, s, stp;
  int c[3];

  QNode(int _x, int _y, int _s, const int _c[], int _stp) {
    x = _x, y = _y, s = _s, stp = _stp;
    for (int i = 0; i < 3; ++i) c[i] = _c[i];
  }
};

int X, Y, N;
int f[220][220][20][3], vst_cnt;

int bfs(void);

inline void shift(int c[]) {
  int tmp[3];
  copy(&c[0], &c[3], &tmp[0]);
  for (int i = 0; i < 3; ++i)
    c[(i + 1) % 3] = tmp[i];
}

int main() {
  while (cin >> X >> Y >> N) {
    if (X == 0 && Y == 0 && N == 0) break;
    X += 110, Y += 110;
    cout << bfs() << "\n";
  }

  return 0;
}

int bfs(void) {
  deque< QNode > que;

  f[110][110][0][0] = ++vst_cnt;
  que.push_back(QNode(110, 110, 0, kNext[0], 0));
  while (!que.empty()) {
    QNode frn(que.front()); que.pop_front();

#ifdef _DEBUG
  if (frn.stp <= 1)
    cout << "x = " << frn.x - 110 << ", y = " << frn.y - 110
      << ", s = " << frn.s << endl;
#endif

    for (int di = 0; di < 3; ++di) {
      bool is_upside = (frn.x + frn.y) % 2 == 0;
      int nx, ny, ns, nc[3], nstp, r = 0;

      if (di == 0) {
        nx = frn.x - 1, ny = frn.y, nstp = frn.stp + 1;
        ns = is_upside ? frn.c[2] : frn.c[1];
        copy(&kNext[ns][0], &kNext[ns][3], &nc[0]);
        if (is_upside) {
          while (nc[2] != frn.s)
            ++r, shift(nc);
        }
        else {
          while (nc[1] != frn.s)
            ++r, shift(nc);
        }
      }
      else if (di == 1) {
        nx = frn.x + 1, ny = frn.y, nstp = frn.stp + 1;
        ns = is_upside ? frn.c[1] : frn.c[2];
        copy(&kNext[ns][0], &kNext[ns][3], &nc[0]);
        if (is_upside) {
          while (nc[1] != frn.s)
            ++r, shift(nc);
        }
        else {
          while (nc[2] != frn.s)
            ++r, shift(nc);
        }
      }
      else {
        nx = frn.x, ny = is_upside ? frn.y + 1 : frn.y - 1, nstp = frn.stp + 1;
        ns = frn.c[0];
        copy(&kNext[ns][0], &kNext[ns][3], &nc[0]);
        while (nc[0] != frn.s)
          ++r, shift(nc);
      }

#ifdef _DEBUG
  if (frn.stp <= 1) {
    cout << "nx = " << nx - 110 << ", ny = " << ny - 110
      << ", ns = " << ns << ",";
    for (int o = 0; o < 3; ++o)
      cout << " " << nc[o];
    cout << ", r = " << r << endl;
  }
#endif

      if (nx == X && ny == Y && ns == N)  return nstp;

      if (f[nx][ny][ns][r] != vst_cnt) {
        f[nx][ny][ns][r] = vst_cnt;
        que.push_back(QNode(nx, ny, ns, nc, nstp));
      }
    }
  }

  return -1;
}

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

int main(){
  long long a,b,c;
  long long a_, b_, c_;
  cin >> a_ >> b_ >> c_;
  long long ans = 0;
  if(a_==b_ && b_==c_) {
    if(a_%2==0){
      cout<< -1 << endl;
    }
    else cout<< 0 << endl;
    return 0;
  }
  else{
    while (a_%2 == 0 && b_%2==0 && c_%2==0){
      a = a_;
      b = b_;
      c = c_;
      a_ = b/2+c/2;
      b_=a/2+c/2;
      c_=a/2+b/2;
      ans +=1;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main() {
    int a, b, n;
    cin >> a >> b >> n;

    bool ret = true;
    for (int i = 0; i < n; i++) {
        int x, y;
        cin >> x >> y;
        if (y > a && b > x)ret = false;
    }

    cout << (ret ? 0 : 1) << endl;
    return 0;
}


Measured memory_bytes: 3108
import sys
m=166666;s=[1]*m;t=[1]*m
for i in range(m):
 for j in range(2):
  if (s[i],t[i])[j]:
   k=6*i+[5,7][j];n=[i+k,k-i-2]
   s[n[j]::k]=[0]*len(s[n[j]::k])
   t[n[1-j]::k]=[0]*len(t[n[1-j]::k])
for e in map(int,sys.stdin):
 print([e-1,sum(s[:(e+1)//6])+sum(t[:(e-1)//6])+2][e>3])


Measured memory_bytes: 9880
#include<cstdio>
const int mod=1000000007;
int N,M,f[1<<15],g[15][2];
bool G[15][15];
int dfs(int s,int i){
	while(i>=0&&!(s>>i&1))--i;
	if(i<0)return f[s];
	for(int j=0;j<i;j++)if(G[j][i])++g[j][0];
	long long res=dfs(s,i-1);
	res=(res<<g[i][1])-res;
	for(int j=0;j<i;j++)if(G[j][i])--g[j][0],++g[j][1];
	res+=1ll*dfs(s^1<<i,i-1)<<g[i][0];
	for(int j=0;j<i;j++)if(G[j][i])--g[j][1];
	return res%mod;
}
int main(){
	scanf("%d%d",&N,&M);
	for(int i=0,a,b;i<M;i++)scanf("%d%d",&a,&b),G[--a][--b]=1;
	f[0]=1;
	for(int i=0;i<N;i++){
		for(int s=0;s<1<<i;s++)if(((s|1<<i)&1)==((s|1<<i)>>1&1)){
			for(int j=0;j<i;j++)g[j][0]=0,g[j][1]=G[j][i];
			f[s|1<<i]=dfs(s,i);
		}
	}
	int s=1;
	while(M--)s=s*2%mod;
	s=(s+mod-f[(1<<N)-1])%mod;
	printf("%d\n",s);
}


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

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

    int n = (int)s.size();
    vector<vector<vector<int>>> dp(n + 1, vector<vector<int>>(K + 1, vector<int>(2)));
    dp[0][0][0] = 1;
    for (int i = 0; i < n; i++) {
        for (int j = 0; j <= K; j++) {
            for (int k = 0; k < 2; k++) {
                int nd = s[i] - '0';
                for (int d = 0; d <= 9; d++) {
                    int ni = i + 1, nj = j, nk = k;
                    if (d != 0) nj++;
                    if (nj > K) continue;
                    if (k == 0) {
                        if (d > nd) continue;
                        if (d < nd) nk = 1;
                    }
                    dp[ni][nj][nk] += dp[i][j][k];
                }
            }
        }
    }

    int res = dp[n][K][0] + dp[n][K][1];
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 256
def main():
    n = int(input())
    s = ["".join(sorted(input())) for _ in range(n)]
    ans = 0
    dic = {}
    for i in s:
        if i not in dic:
            dic[i] = 0
        else:
            dic[i] += 1
            ans += dic[i]
        # print(ans)
    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 19400
#include <stdio.h>
#include <iostream>
#include <vector>
#include <string>
#include <sstream>
#include <tuple>
#include <algorithm>
#include <map>
#include <cmath>
using namespace std;
long long int MOD = 1000000000 + 7;
using ll = long long;
ll LARGE = 1000000;


int main() {
	ll h, n;
	cin >> h >> n;
	ll sum = 0;
	for (ll i = 0; i < n; ++i) {
		ll t;
		cin >> t;
		sum += t;
	}
	if (h <= sum) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
}


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

int main() {
  int n;
  cin>>n;
  vector<string> s(n);
  for(int i=0;i<n;i++){
    cin>>s.at(i);
  }
  int m;
  cin>>m;
  vector<string> t(m);
  for(int i=0;i<m;i++){
    cin>>t.at(i);
  }
  
  string word;
  int ans=0;
  for(int i=0;i<n;i++){
    word=s.at(i);
    int count=0;
    for(int j=0;j<n;j++){
      if(word==s.at(j)){
        count++;
      }
    }
    for(int j=0;j<m;j++){
      if(word==t.at(j)){
        count--;
      }
    }
    if(ans<count){
      ans=count;
    }
  }
  cout<<ans<<endl;
}

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

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

  vector<tuple<string,int,int> > t(n);

  for(int i=0;i<n;i++){
      string s; 
      cin >> s;
      int a;
      cin >> a;

      t.at(i) = make_tuple(s,100-a,i);
  }

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

  for(int i=0;i<n;i++){
      int b;
      tie(ignore,ignore,b) = t.at(i);

      cout << b+1 << endl;
  }
}

Measured memory_bytes: 256
Sa = list(raw_input())
Sb = list(raw_input())
Sc = list(raw_input())

def choise(t):
    if t == "a":
        if Sa == []:
            print "A"
        else:
            choise(Sa.pop(0))
    elif t== "b":
        if Sb == []:
            print "B"
        else:
            choise(Sb.pop(0))
    else:
        if Sc == []:
            print "C"
        else:
            choise(Sc.pop(0))

choise(Sa.pop(0))

Measured memory_bytes: 2820
import java.util.Scanner;

class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int a, b, ms, ns;
        a = in.nextInt();
        b = in.nextInt();
        ms = a*b;
        ns = (a+b)*2;
        System.out.println(ms + " " + ns);
    }
}


Measured memory_bytes: 26112
#include <bits/stdc++.h>
using namespace std;
 
int main(){

int N, n, cnt = 0, bacnt = 0, acnt = 0, bcnt = 0;
string s;
  cin >> N;
  
  for(int i = 0;i < N;i++){
    cin >> s;
    n = s.size();
    for(int j = 0;j < n - 1;j++){
    if((s.at(j) == 'A') && (s.at(j+1) == 'B')) cnt++;
    }
    
    if((s.at(0) == 'B') && (s.at(n-1) == 'A')) bacnt++;      
    if((s.at(n-1) == 'A') && (s.at(0) != 'B')) acnt++;
    if((s.at(0) == 'B') && (s.at(n-1) != 'A')) bcnt++;
  }
  
  if((acnt == 0) && (bcnt == 0) && (bacnt > 0)) cout << cnt + bacnt - 1 << endl;
  else if((acnt == 0) && (bcnt == 0) && (bacnt == 0)) cout << cnt << endl;
  else if(bacnt == 0) cout << cnt + min(acnt, bcnt) << endl;
  else cout << cnt + bacnt + 1 + min(acnt - 1, bcnt - 1) << endl;
  return 0;
  
}

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

using namespace std;

#define ll long long

const ll INF = (1e18) + 10;

int main(void)
{
	ios_base::sync_with_stdio(NULL);
	cin.tie(0);
	
	int n, m, q; cin >> n >> m >> q;
	ll a[n + 2], b[m + 2];
	
	for(int i = 1; i <= n; i++)
		cin >> a[i];
	for(int i = 1; i <= m; i++)
		cin >> b[i];

	a[0] = -INF;
	b[0] = -INF;
	a[n + 1] = INF;
	b[m + 1] = INF;
	
	int l, r, la, lb, ra, rb, mid;
	ll x, dla, dlb, dra, drb;
	while(q--)
	{
		cin >> x;
		
		l = 0;
		r = n + 1;
		
		la = -1;
		l = 0;
		r = n + 1;
		while(l <= r)
		{
			mid = l + (r - l) / 2;
			if(a[mid] <= x)
			{
				la = mid;
				l = mid + 1;
			}
			else
			{
				r = mid - 1;
			}
		}
		
		lb = -1;
		l = 0;
		r = m + 1;
		while(l <= r)
		{
			mid = l + (r - l) / 2;
			if(b[mid] <= x)
			{
				lb = mid;
				l = mid + 1;
			}
			else
			{
				r = mid - 1;
			}
		}
		
		ra = la + 1;
		rb = lb + 1;
		
		dla = x - a[la];
		dlb = x - b[lb];
		dra = a[ra] - x;
		drb = b[rb] - x;
		
		// cout << la << " " << lb << " " << ra << " " << rb << endl;
		
		cout << min({2*dla + drb, 2*dlb + dra, 2*dra + dlb, 2*drb + dla, max(dla, dlb), max(dra, drb)}) << "\n";
	}
	
	return 0;
}

Measured memory_bytes: 5176
#include <iostream>
#include <string>

using namespace std;

int main() {
    int a,b;
    string s;
    cin >> a >> b >> s;
    bool ans = true;
    for (int i=0; i<a; i++) {
        if (s[i] < '0' || '9' < s[i])
            ans = false;
    }

    if (s[a] != '-') ans = false;

    for (int i=a+1; i<=a+b; i++) {
        if (s[i] < '0' || '9' < s[i])
            ans = false;
    }

    cout << (ans? "Yes" : "No") << endl;
}

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

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

  int n;
  cin >> n;
  int a[4] = {0};
  int b;
  rep(i, n) {
    cin >> b;
    a[b%4]++;
  }

  if (a[2] >= 2) {
    if (n-a[2] <= a[0]*2) {
      cout << "Yes" << endl;
    } else {
      cout << "No" << endl;
    }
  } else {
    if (n <= a[0]*2+1) {
      cout << "Yes" << endl;
    } else {
      cout << "No" << endl;
    }
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ref(i,x,y)for(int i=x;i<=y;++i)
#define def(i,x,y)for(int i=x;i>=y;--i)
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define SZ(x) ((int)x.size())
const int N=100010;
const int mod=1e9+7;
int n;char a[N];
int ct[26];
int main(){
	cin>>n;
	scanf("%s",a+1);
	ref(i,1,n)ct[a[i]-'a']++;
	ref(i,0,25)ct[i]++;
	int ans=1;
	ref(i,0,25)ans=1LL*ans*ct[i]%mod;
	(ans+=mod-1)%=mod;
	cout<<ans<<endl;
}

Measured memory_bytes: 384
#!/usr/bin/env python3
def solve(s):
    if len(s) == 2 and s[0] == s[1]:
        return 1, 2
    for l in range(len(s) - 2):
        a, b, c = sorted(s[l : l + 3])
        if a == b or b == c:
            return l + 1, l + 3
    return -1, -1
print(*solve(input()))


Measured memory_bytes: 3316
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
typedef long long ll;
using namespace std;

int main(){
  int a[3];
  for(int i=0;i<3;i++) cin >> a[i];
  sort(a, a+3);

  if(a[2] == a[0] + a[1]) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}


Measured memory_bytes: 256
n=int(input())
a=list(map(int,input().split()))
b=[]
for i in a:
    b.append(i)
b.sort()
sum1=0
for i in range(n):
    if a[i]!=b[i]:
        sum1+=1
if sum1==0 or sum1==2:
    print("YES")
else:
    print("NO")

Measured memory_bytes: 3060
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <string>
#include <cmath>
#include <iomanip>
#include <numeric>

using namespace std;

#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
#define SORT(c) sort((c).begin(), (c).end())

typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> V;
typedef map<int, int> M;

const ll INF = 1e18;
const ll MOD = 1e9 + 7;

int main()
{
    string s;
    cin >> s;
    int ans = 0;
    char cur = s[0];
    REP(i, s.size())
    {
        if (s[i] != cur)
        {
            cur = s[i];
            ans++;
        }
    }

    cout << ans << endl;

    return 0;
}

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

int main() {
  long long f[100000 + 1];
  int n;
  cin >> n;
  f[0] = 1;
  const long long m = int(1e9) + 7;
  for (int i = 1; i <= n; ++i) {
    f[i] = (i * f[i - 1]) % m;
  }
  cout << f[n] << '\n';
  return 0;
}

Measured memory_bytes: 1024
#!/usr/bin/env python3
import sys


def solve(N: int, A: "List[int]"):

    X = [0] * N
    X[0] = 0
    for j in range(1,N):
        X[j] = 2*A[j-1] - X[j-1]
    T = (A[-1]*2 - (X[0]+X[-1])) // 2

    for i,x in enumerate(X):
        print(x + T if i % 2 == 0 else x - T, end="")
        if i != len(X) - 1:
            print(" ", end="")
        else:
            print("")
    return


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    A = [ int(next(tokens)) for _ in range(N) ]  # type: "List[int]"
    solve(N, A)

if __name__ == '__main__':
    main()


Measured memory_bytes: 20828
#include <stdio.h>
#include <stdlib.h>

typedef struct{
    int p;
    int l;
    int r;
}Node;

Node node[28];

void getDep(int n){
    int depth = 0;
    while(node[n].p!=-1){
      depth++;
      n = node[n].p;
    }
    printf("depth = %d, ",depth);
}


int getHeight(int i){
    int p1 = 0;
    int p2 = 0;
    if(node[i].l==-1 && node[i].r==-1) return 0;
    if(node[i].l!=-1){
        p1=getHeight(node[i].l)+1;
    }
    if(node[i].r!=-1){
        p2=getHeight(node[i].r)+1;
    }
    if(p1>p2){
        return p1;
   }
    else{
        return p2;
    }

}

void judge(int i){
    if(node[i].p==-1){
        printf(" root\n");
    }
    else if(node[i].l==-1 && node[i].r==-1){
            printf(" leaf\n");
        }
    else printf(" internal node\n");
}

int main()
{
    int n;
    scanf("%d", &n);

    for(int i=0; i<n; i++){
        node[i].p = -1;
    }

    int id;
    for(int i=0; i<n; i++){
        scanf("%d", &id);
        scanf("%d %d", &node[id].l, &node[id].r);
        if(node[id].l!=-1 && node[id].r!=-1){
            node[node[id].l].p = id;
            node[node[id].r].p = id;
        }
        else{
            if(node[id].l!=-1 && node[id].r==-1){
                node[node[id].l].p = id;
            }
            if(node[id].l==-1 && node[id].r!=-1){
                node[node[id].r].p = id;
            }
        }
    }

    for(int i=0; i<n; i++){
        printf("node %d: parent = %d, ", i, node[i].p);
        if(node[i].p == -1){
            printf("sibling = -1, ");
        }
        else if(node[node[i].p].l == i){
                printf("sibling = %d, ",node[node[i].p].r);
        }
        else printf("sibling = %d, ",node[node[i].p].l);

        printf("degree = ");
        if(node[i].l!=-1 && node[i].r!=-1){
            printf("2, ");
        }
        else if(node[i].l==-1 && node[i].r==-1){
            printf("0, ");
            }
        else printf("1, ");

        getDep(i);
        printf("height = ");
        int h = getHeight(i);
        printf("%d,", h);
        judge(i);
    }
    return 0;
}



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

#include <iostream>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)

struct Point {
  double x, y;
};

void printPoint(Point p) { printf("%.8f %.8f\n", p.x, p.y); }

void koch(int d, Point p1, Point p2) {
  if (d == 0) return;

  Point diff = {p2.x - p1.x, p2.y - p1.y};
  Point s, t, u;

  s.x = p1.x + diff.x / 3;
  s.y = p1.y + diff.y / 3;

  t.x = p1.x + diff.x * 2 / 3;
  t.y = p1.y + diff.y * 2 / 3;

  u.x = s.x + diff.x / 2 / 3 - sqrt(3) / 2 * diff.y / 3;
  u.y = s.y + diff.x * sqrt(3) / 2 / 3 + diff.y / 2 / 3;

  koch(d - 1, p1, s);
  printPoint(s);
  koch(d - 1, s, u);
  printPoint(u);
  koch(d - 1, u, t);
  printPoint(t);
  koch(d - 1, t, p2);
}

int main() {
  int n;
  cin >> n;
  Point p1 = {0., 0.}, p2 = {100., 0.};

  printPoint(p1);
  koch(n, p1, p2);
  printPoint(p2);
  return 0;
}



Measured memory_bytes: 3224
#include<bits/stdc++.h>
using namespace std;
long long n,k,a[200005],p[200005],m,d;
bool vis[200005];
int main()
{
	cin>>n>>k;
	for(int i=1;i<=n;++i)
	 	cin>>a[i];
	int i=a[1];
	p[0]=1;
	vis[1]=1;
	while(!vis[i])
	{
		vis[i]=1;
		++d;
		p[d]=i;
		i=a[i];
	}
	++d;
	for(int j=0;j<=d;++j)
	{
		if(p[j]==i)
		{
			m=j;
			break;
		}
	}
	if(k<=m)
	{
		cout<<p[k];
		return 0;
	}
	d-=m;
	k=(k-m)%d;
	cout<<p[k+m];
	return 0;
}

Measured memory_bytes: 6736