akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i, n) for (int i=0; i<(n); ++i)
#define repr(i, a, b) for (int i=a; i<(b); ++i)
#define reprev(i, n) for (int i=n-1; i>=0; --i)
#define reprrev(i, a, b) for (int i=b-1; i>=(a); --i)
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main() {
    cout << fixed << setprecision(10);
    
    int N; cin >> N;
    vector<int> A(N);
    rep(i, N) cin >> A[i];
    double m = 0;
    rep(i, N) {
        m += A[i];
    }
    m /= A.size();
    int mi = round(m);
    int ans = 0;
    rep(i, N) {
        ans += pow((A[i] - mi), 2);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int num[100005];
bool done[100005];
int main(){
    int n,m;
    cin >> n >> m;
    int ans1 = 0, ans2 = 0;
    for (int i = 0; i < m; i++){
        int x;
        string s;
        cin >> x >> s;
        if (s == "AC"){
            if (!done[x]){
                ans1++; ans2 += num[x];
                done[x] = true;
            }
        }
        else{
            num[x]++;
        }
    }
    printf("%d %d\n",ans1,ans2);
}


Measured memory_bytes: 768
main(){
	int n,q;
	for(;scanf("%d%d",&n,&q)*n;){
		int c[101]={0},m,d,b=0;
		for(;n--;){
			scanf("%d",&m);
			for(;m--;){
				scanf("%d",&d);
				c[d]++;
				if(c[d]>=q&&(c[d]>c[b]||c[d]==c[b]&&d<b))
					b=d;
			}
		}
		printf("%d\n",b);
	}
}

Measured memory_bytes: 0
#include <cstdio>
#include <algorithm>
#include <queue>
#define Min(A, B) std::min(A, B)
const int MaxN = 1e5 + 10;
const int Inf = 1 << 30;
std::priority_queue <int> Que;
int N, K, Q, A[MaxN];
int Cnt = 1, B[MaxN];

bool Cmp(int A, int B) {
	return A < B;
}
int C[MaxN];

void Debug() {
	for(int i = 1; i <= N; i++) printf("%d ", C[i]);
	puts("");
}

int main() {
	scanf("%d%d%d", &N, &K, &Q);
	for(int i = 1; i <= N; i++) scanf("%d", &A[i]);
	int Ans = Inf;
	int Count = 0;
	for(int x = 1; x <= N; x++) {
		int L, R, Count = 0; 
		for(int i = 1, L = 1; i <= N; i = R + 1, L = i) { 
			while(L <= N && A[L] < A[x]) L += 1; R = L;
			while(R <= N && A[R] >= A[x]) R += 1;
			R -= 1; Cnt = 0;
			for(int j = L; j <= R; j++) B[++Cnt] = A[j];
			std::sort(B + 1, B + 1 + Cnt);
			if(Cnt < K) continue;
			for(int k = 1; k <= Cnt - K + 1; k++) C[++Count] = B[k];
		}
		
		if(Count >= Q) {
			std::sort(C + 1, C + 1 + Count);
			Ans = Min(Ans, C[Q] - A[x]);
		} 
	}
	printf("%d", Ans);
} 

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <assert.h>
#define rep(i,n) for(ll i = 0; i < (ll)(n); ++i)
using namespace std;
using ll = long long;
const int mod = 1e9+7;


int maxElement(const int* array, size_t size)
{
    assert(array != NULL);
    assert(size >= 1);

    int max = array[0];
    for (size_t i = 1; i < size; ++i) {
        if (max < array[i]) {
            max = array[i];
        }
    }

    return max;
}

int minElement(const int* array, size_t size)
{
    assert(array != NULL);
    assert(size >= 1);

    int min = array[0];
    for (size_t i = 1; i < size; ++i) {
        if (min > array[i]) {
            min = array[i];
        }
    }

    return min;
}

int main()
{
    int n,m;
    cin >> n >> m ;
    int l[m]={0};
    int r[m]={0};
    rep(i,m) cin >> l[i] >> r[i];

    /*
    int id[n+1]={0};
    for( int i = 0; i < n; i++ ){
        id[l[i]:r[i]]++;
    }

    int ans = 0;
    for( int i = 1; i < n+1; i++ ){
        if( id[i] == n ) ans++;
    }
    */
    
    if( minElement( r, m ) >= maxElement( l, m ) ){
        cout << minElement( r, m ) - maxElement( l, m ) + 1 << endl;
    }
    else{
        cout << 0 << endl;
    }

    return 0;
}


Measured memory_bytes: 1024
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class Main {
    public static void main(String[] args) {
        FastReader sc = new FastReader();
        PrintWriter out = new PrintWriter(System.out);
        int p = sc.nextInt();
        int q = sc.nextInt();
        int r = sc.nextInt();

        int[] aa = new int[]{p,q,r};
        int min = Integer.MAX_VALUE;
        for (int i = 0; i<aa.length; i++) {
            for (int j = 0; j < aa.length; j++) {
                if (i == j) continue;
                min = Math.min(min, aa[i]+aa[j]);
            }
        }
        out.println(min);
        out.flush();

    }

    static class Toi {
        public int x;
        public int y;

        public Toi(int x, int y) {
            this.x = x;
            this.y = y;
        }

        @Override public boolean equals(Object obj) {
            if (obj == null) {
                return false;
            }

            if (this == obj) {
                return true;
            }

            if (this.getClass() != obj.getClass()) {
                return false;
            }

            Toi toi = (Toi) obj;
            return x == toi.x && y == toi.y;
        }
    }

    static class FastReader {
        BufferedReader br;
        StringTokenizer st;

        public FastReader() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        long nextLong() {
            return Long.parseLong(next());
        }

        double nextDouble() {
            return Double.parseDouble(next());
        }

        String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }
    }
}

Measured memory_bytes: 21332
def check(number)
  dfs(number.dup) == 4
end

def dfs(number)
  count = 0

  for i in 0...9 do
    next if number[i] < 3
    number[i] -= 3
    count = [count, 1 + dfs(number.dup)].max
    number[i] += 3
  end

  for i in 0...9-2 do
    next if number[i, 3].find {|e| e == 0}
    for j in i...i+3 do
      number[j] -= 1
    end
    count = [count, 1 + dfs(number.dup)].max
    for j in i...i+3 do
      number[j] += 1
    end
  end

  count
end

while line=gets do
  number = Array.new(9, 0)
  line.chop.chars.map{|e| e.to_i - 1}.each do |e|
    number[e] += 1
  end
  answer = Array.new
  for add in 0...9 do
    next if number[add] >= 4
    number[add] += 1
    for i in 0...9 do
      next if number[i] < 2
      number[i] -= 2
      answer.push(add + 1) if check(number.dup)
      number[i] += 2
    end
    number[add] -= 1
  end
  puts answer.empty? ? 0 : answer.uniq.join(" ")
end

Measured memory_bytes: 6124
# -*- coding: utf-8 -*-
import sys
import math
import os
import itertools
import string
import heapq
import _collections
from collections import Counter
from collections import defaultdict
from functools import lru_cache
import bisect
import re
import queue
from decimal import *


class Scanner():
    @staticmethod
    def int():
        return int(sys.stdin.readline().rstrip())

    @staticmethod
    def string():
        return sys.stdin.readline().rstrip()

    @staticmethod
    def map_int():
        return [int(x) for x in Scanner.string().split()]

    @staticmethod
    def string_list(n):
        return [input() for i in range(n)]

    @staticmethod
    def int_list_list(n):
        return [Scanner.map_int() for i in range(n)]

    @staticmethod
    def int_cols_list(n):
        return [int(input()) for i in range(n)]


class Math():
    @staticmethod
    def gcd(a, b):
        if b == 0:
            return a
        return Math.gcd(b, a % b)

    @staticmethod
    def lcm(a, b):
        return (a * b) // Math.gcd(a, b)

    @staticmethod
    def divisor(n):
        res = []
        i = 1
        for i in range(1, int(n ** 0.5) + 1):
            if n % i == 0:
                res.append(i)
                if i != n // i:
                    res.append(n // i)
        return res

    @staticmethod
    def round_up(a, b):
        return -(-a // b)

    @staticmethod
    def is_prime(n):
        if n < 2:
            return False
        if n == 2:
            return True
        if n % 2 == 0:
            return False
        d = int(n ** 0.5) + 1
        for i in range(3, d + 1, 2):
            if n % i == 0:
                return False
        return True


def pop_count(x):
    x = x - ((x >> 1) & 0x5555555555555555)
    x = (x & 0x3333333333333333) + ((x >> 2) & 0x3333333333333333)
    x = (x + (x >> 4)) & 0x0f0f0f0f0f0f0f0f
    x = x + (x >> 8)
    x = x + (x >> 16)
    x = x + (x >> 32)
    return x & 0x0000007f


MOD = int(1e09) + 7
INF = int(1e15)


def main():
    # sys.stdin = open("sample.txt")
    A, B = Scanner.map_int()
    A = Math.divisor(A)
    B = Math.divisor(B)
    ans = set(A) & set(B)
    print(sum(a == 1 or Math.is_prime(a) for a in ans))


if __name__ == "__main__":
    main()


Measured memory_bytes: 62700
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}

//INSERT ABOVE HERE
Int mlcm(Int x,Int y){
  return x/__gcd(x,y)*y;
}
signed main(){
  Int n;
  cin>>n;
  vector<Int> ps(n);
  for(Int i=0;i<n;i++) cin>>ps[i];
  Int s=1<<n;
  Int ans=0;
  for(Int b=1;b<s;b++){
    Int res=1;
    for(Int i=0;i<n;i++)
      if((b>>i)&1) res=mlcm(res,ps[i]);
    Int flg=0;
    for(Int i=0;i<n;i++)
      if((~b>>i)&1) flg|=(res%ps[i])==0;
    if(!flg) ans++;
  }
  cout<<ans<<endl;
  return 0;
}



Measured memory_bytes: 3108
#include<cstdio>
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
#define REP(i,b,n) for(int i=b;i<n;i++)
#define rep(i,n)   REP(i,0,n)
#define pb push_back
#define mp make_pair
#define DIR 6

typedef pair<int,int> pii;
typedef vector<pii>   vpii;
typedef vector<int> vint;


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

vpii make_path(string & path,int stride){
  vpii ret;
  pii now(0,0);
  ret.pb(now);
  rep(i,path.size()){
    now.first = now.first + dx[((int)path[i] + stride) % DIR];
    now.second = now.second + dy[((int)path[i] + stride) % DIR];
    ret.pb(now);
  }
  return ret;
}

bool cmp(vpii *path){
  rep(k,path[1].size()){
    bool flag = true;
    pii dif = path[1][k];
    rep(i,path[0].size()){
      path[1][i].first -= dif.first;
      path[1][i].second -= dif.second;
      if (path[0][i] != path[1][i]){
	flag  = false;
      }
      path[1][i].first += dif.first;
      path[1][i].second += dif.second;
    }
    if (flag)return true;
  }
  return false;
}


bool solve(string *in){
  if (in[0].size() != in[1].size())return false;
  rep(i,in[0].size()){
    in[0][i] -= 'a';
    in[1][i] -= 'a';
  }

  vpii path[2];
  path[0] = make_path(in[0],0);
  sort(path[0].begin(),path[0].end());

  rep(i,DIR){
    path[1] = make_path(in[1],i);
    sort(path[1].begin(),path[1].end());
    if (cmp(path))return true;
  }
  return false;
}

main(){
  int te;
  string in[2];
  cin>>te;
  getline(cin,in[1]);
  while(te--){
    getline(cin,in[0]);
    getline(cin,in[1]);
    if (solve(in))puts("true");
    else puts("false");
    getline(cin,in[0]);
  }
}

Measured memory_bytes: 912
#include <iostream>
#include <array>
#include <cmath>
#include <algorithm>
#include <limits>

typedef unsigned int ui;
ui T[50001] = {};
ui C[21];

int main()
{
    std::fill( T + 1, T + 50001, std::numeric_limits<ui>::max() );

    int n, m;
    std::cin >> n >> m;

    for( int i=0; i<m; ++i ) {
        std::cin >> C[i];
    }

    for( int i=0; i<m; ++i ) {
        for( int j=C[i]; j<=n; ++j ) {
            T[j] = std::min( T[j], T[j - C[i]] + 1 );
        }
    }

    std::cout << T[n] << std::endl;
}

Measured memory_bytes: 1360
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <utility>
#include <ctime>
#define INF 999999999
#define mod 1000000007

#define rep(i,n) for(int i=0;i<int(n);i++)
#define rrep(i,n) for(int i=(n);i>=0;i--)
#define REP(i,a,b) for(int i=(a);i<int(b);i++)
#define all(x) (x).begin(),x.end()
#define pb push_back
#define MOD(x) (x%(mod))
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef pair<int,int> pi;

bool debug=false;
/*---------------------------------------------------*/

bool prime[1000000];
int ans[1000000];

void is_prime(){
  rep(i,1000000)prime[i]=true;
  prime[0]=prime[1]=false;
  REP(i,2,1000000){
    if(prime[i]==true){
      for(int j=i+i;j<1000000;j+=i)prime[j]=false;
    }
  }
  if(debug)rep(i,1000)if(prime[i])cout<<i<<endl;
}

void calc(){
  ans[0]=0;
  REP(i,1,1000000){
    ans[i]=ans[i-1]+prime[i];
  }
}

int main(){
  int n;
  is_prime();
  calc();
  while(cin>>n){
    cout<<ans[n]<<endl;
  }
  return 0;
}

Measured memory_bytes: 7892
#include<iostream>
#include<algorithm>
#include<cstdio>

using namespace std;

int main(void)
{
	int  n;
	
	while(cin >> n){
		int a = 0;
		long long int ans = 0;
		int time[100];
		for(int i = 0; i < n; i++){
			cin >> time[i];
		}
		
		sort(time, time + n);
		int temp = n;
		for(int j = 0; j < n; j++){
			a = 0;
			for(int ii = 0; ii < temp; ii++){
				a += time[ii];
			}
			ans += a;
			temp--;
		}
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 1172
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repp(i, a, b) for (int i = a; i <= (b); ++i)
#define repr(i, a, b) for (int i = a; i >= (b); --i)
#define bit(n) (1LL << (n))
typedef long long ll;
const int INF = 1001001001;
const ll LINF = 1001001001001001001ll;
const int MOD = 1000000007;

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

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

int main() {
  int N, K;
  cin >> N >> K;
  vector<int> h(N);
  int cnt = 0;
  rep(i, N) {
    cin >> h[i];
    if (h[i] >= K)
      cnt++;
  }
  cout << cnt << endl;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
/*******  All Required define Pre-Processors and Constants    *******/

#define int long long
#define ull unsigned long long 
#define ld long double
#define mem(a, b) memset(a, (b), sizeof(a))
#define rep(i, j, k) for (int i = j ; i < k ; ++i)
#define rrep(i, j, k) for (int i = j; i > k; --i)
#define all(cont) cont.begin(), cont.end()
#define rall(cont) cont.end(), cont.begin()
#define foreach(i, a) for(auto i: a)
#define forEach(it, l) for (auto it = l.begin(); it != l.end(); it++)
#define in(A, B, C) assert( B <= A && A <= C)
#define debug(a) cout << #a << ": " << a << endl
#define Flag(n) cout << "here " << n << endl
#define w(x) int x;cin>>x;while(t--)
#define mp make_pair
#define pb push_back

#define endl '\n';
#define io ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

 

#define TRACE
#ifdef TRACE
#define see(...) __f(#__VA_ARGS__,__VA_ARGS__);
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    cerr<<name<<" : "<<arg1<<endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma=strchr(names+1,',');cerr.write(names,comma-names)<<" : "<<arg1<<" | ";__f(comma+1, args...);
}
#else
#endif

const int POSITIVE_INFINITY = 9223372036854775807;
const int NEGATIVE_INFINITY = -9223372036854775807;
const int MOD = 1000000007;
const ld PI = acos(-1.0);
const int INF = 1e18;
const int MX = 1000001;

int pow(int a, int n , int m){
    int res = 1;
    while(n){
        if(n%2){
            res=(res*a)%m;
            n--;
        }
        a=(a*a)%m;
        n/=2;
    }
    return res;
}

int32_t main() {
    io;
    // freopen("input.txt","r",stdin); 
    // freopen("output.txt","w",stdout);
    int n;
    cin>>n;
    int total = pow(10,n,MOD);
    int wo9 = (2*pow(9,n,MOD))%MOD;
    int wob = pow(8,n,MOD);
    int res =( total -wo9+wob)%MOD;
    res= (res+MOD)%MOD;
    cout<<res<<endl;
 
    
 
    return 0;
}


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

#define pb push_back
#define eb emplace_back
#define mk make_pair
#define fi first
#define se second
#define mset(a, b) memset(a, b, sizeof(a))
#define DBG(x) cout << "[" << #x << "]: " << x << endl
using ll = long long;
using pii = pair<int, int>;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#ifdef _WIN32
#define getchar_unlocked _getchar_nolock
#endif

template<class Ty> Ty randint(Ty a, Ty b) { return uniform_int_distribution<Ty>(a, b)(rng); }
template<class num> inline void rd(num& x) {
	char c, neg = 0; while(isspace(c = getchar_unlocked()));
	if(!isdigit(c)) neg = (c == '-'), x = 0;
	else x = c - '0';
	while(isdigit(c = getchar_unlocked())) x = (x << 3) + (x << 1) + c - '0';
	x = neg ? -x : x; }
template <class... Args> inline void rd(Args&... args) { (rd(args), ...); }

const int MAXN = 2e5 + 5, INF = 0x3f3f3f3f;
const int MOD = 1e9 + 7;

int memo[2001];
int solve(int s) {
	if (s == 0) return 0;
	if (~memo[s]) return memo[s];
	memo[s] = s >= 3;
	for (int i = 3; i <= s; i++) {
		memo[s] = (memo[s] + solve(s - i)) % MOD;
	}
	return memo[s];
}

int main() {
	int s; rd(s);
	mset(memo, -1);
	printf("%d\n", solve(s));
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
#define MAX 100007
    
#define REP(i, N) for(int i=0; i < N; i++)
#define REPP(i, N) for(int i=1; i <= N; i++)
#define PER(i, N) for(int i=N-1; i >= 0; i--)
    
using namespace std;
typedef long long ll;
typedef pair<ll, int> pii;

int sum[3][MAX], abc[26];
int main(){
    int n; cin >> n;
    string s; cin >> s;

    abc['R'-'A'] = 0;
    abc['G'-'A'] = 1;
    abc['B'-'A'] = 2;
    REPP(i, n){
        REP(j, 3) sum[j][i] += sum[j][i-1];

        sum[abc[s[i-1]-'A']][i]++;
    }
    ll ans = 0LL;
    REPP(i, n){
        for(int j = i; j <= n; j++){
			if(s[i-1] == s[j-1]) continue;
            REP(k, 3){
                if(abc[s[i-1]-'A'] == k || abc[s[j-1]-'A'] == k) continue;
                  //cout << i << " " << j << " = " << k << " " << (sum[k][j]-sum[k][i-1]) << endl;
                  ans += sum[k][j-1]-sum[k][i];
            }
            if((j-i+1)%2 == 1) {
                int md = (j-i+1)/2;
                if(md != 0) ans -= (s[i-1] != s[i-1+md] && s[j-1] != s[j-1-md]);
            }
        }
    }

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

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

int main()
{
  int n;
  cin >> n;
  vector<ll> a(n+1), as(n+1);
  rep(i,n+1) cin >> a[i];
  
  if(n != 0 && a[0] != 0)
  {
    cout << -1 << endl;
    return 0;
  }
  if(n == 0 && a[0] != 1)
  {
    cout << -1 << endl;
    return 0;
  }
  
  //as:深さiにおける葉でないノードの個数の上限
  rep(i,n) as[i] = a[i+1];
  for(int i = n; i > 0; i--) as[i-1] += as[i];
  //rep(i,n+1) cout << as[i] << " "; cout <<endl;
  
  //v:深さiにおいて葉でないノードの個数
  ll res = 1, v = 1;
  for(int i = 1; i <= n; i++)
  {
    v = min(v * 2 - a[i], as[i]);
    if(i == n && v != 0)
    {
      cout << -1 << endl;
      return 0;
    }
    if(i != n && v <= 0)
    {
      cout << -1 << endl;
      return 0;
    }
    //cout << v << endl;
    
    res += v + a[i];
  }
  
  cout << res << endl;
    
  
  return 0;
}

Measured memory_bytes: 4780
/*
このコード、と～おれ!
Be accepted!
∧＿∧　
（｡･ω･｡)つ━☆・*。
⊂　　 ノ 　　　・゜+.
　しーＪ　　　°。+ *´¨)
 　　　　　　　　　.· ´¸.·*´¨) ¸.·*¨)
		  　　　　　　　　　　(¸.·´ (¸.·'* ☆
					*/

#include <stdio.h>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstring>
#include <vector>
#include <numeric>
#include <iostream>
#include <random>
#include <map>
#include <unordered_map>
#include <queue>
#include <regex>

#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define rep1(i, n) for(int i = 1; i <= (n); ++i)
#define rep2(i, n) for(int i = 2; i < (n); ++i)
#define repr(i, n) for(int i = n; i >= 0; --i)
#define reprm(i, n) for(int i = n - 1; i >= 0; --i)
#define printynl(a) printf(a ? "yes\n" : "no\n")
#define printyn(a) printf(a ? "Yes\n" : "No\n")
#define printYN(a) printf(a ? "YES\n" : "NO\n")
#define printin(a) printf(a ? "possible\n" : "inposible\n")
#define printdb(a) printf("%.50lf\n", a)//少数出力
#define printdbd(a) printf("%.16lf\n", a)//少数出力(桁少なめ)
#define prints(s) printf("%s\n", s.c_str())//string出力
#define all(x) (x).begin(), (x).end()
#define allsum(a, b, c) ((a + b) * c / 2)//等差数列の和、初項,末項,項数
#define pb push_back
#define priq priority_queue
#define rpriq priq<int, vector<int>, greater<int>>
#define deg_to_rad(deg) (((deg)/360.0)*2.0*PI)
#define rad_to_deg(rad) (((rad)/2.0/PI)*360.0)
#define Please return
#define AC 0
#define debug(aa, a) fprintf(stderr, aa, a)

using ll = long long;

constexpr int INF = 1073741823;
constexpr int MINF = -1073741823;
constexpr ll LINF = ll(4661686018427387903);
constexpr ll MOD = 1000000007;
const double PI = acos(-1);

using namespace std;

void scans(string& str) {
	char c;
	str = "";
	scanf("%c", &c);
	if (c == '\n')scanf("%c", &c);//最初の改行対策
	while (c != '\n' && c != -1) {
		str += c;
		scanf("%c", &c);
	}
}

void scanc(char& str) {
	char c;
	scanf("%c", &c);
	if (c == -1)return;
	while (c == '\n') {
		scanf("%c", &c);
	}
	str = c;
}

double acot(double x) {
	return PI / 2 - atan(x);
}

/*-----------------------------------------ここからコード-----------------------------------------*/


int main() {

	string s, t;
	scans(s);
	scans(t);
	unordered_map<char, int> a;
	for (auto aa : s) {
		++a[aa];
	}
	vector<int> sa, ta;
	for (auto aa : a) {
		sa.pb(aa.second);
	}
	a.clear();
	for (auto aa : t) {
		++a[aa];
	}
	for (auto aa : a) {
		ta.pb(aa.second);
	}
	sort(all(sa));
	sort(all(ta));
	printyn(sa == ta);

	Please AC;
}

Measured memory_bytes: 1020
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
int gcd(int a, int b){
	if(a<b){int tmp=a;a=b;b=tmp;}
	if(b==0) return a;
	if(a%b==0)return b;
	return gcd(b, a-b);
}
int main() {
	cin.tie(0);
   	ios::sync_with_stdio(false);
	int N;
	cin >> N;
	int A[N];
	for (int i = 0; i < N; i++)
	{
		cin >> A[i];
	}
	int ans = 0;
	for (int i = 0; i < N; i++)
	{
		ans = gcd(ans, A[i]);
	}
	cout << ans << endl;
}

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

#define pb(n) push_back(n)
#define fi first
#define se second
#define X real()
#define Y imag()
#define value(x,y,w,h) (x >= 0 && x < w && y >= 0 && y < h)
#define all(r) (r).begin(),(r).end()
#define gsort(st,en) sort((st),(en),greater<int>())
#define vmax(ary) *max_element(all(ary))
#define vmin(ary) *min_element(all(ary))
#define debug(x) cout<<#x<<": "<<x<<endl
#define fcout(n) cout<<fixed<<setprecision((n))
#define scout(n) cout<<setw(n)
#define vary(type,name,size,init) vector< type> name(size,init)

#define rep(i,n) for(int i = 0; i < (int)(n);++i)
#define REP(i,a,b) for(int i = (a);i < (int)(b);++i)
#define repi(it,array) for(auto it = array.begin(),end = array.end(); it != end;++it)
#define repa(n,array) for(auto &n :(array))

using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using dict = map<string,int>;
using comd = complex<double>;
using pii = pair<int,int> ;

constexpr int imax = ((1<<30)-1)*2+1 ;
constexpr int inf = 100000000;
constexpr double PI = acos(-1.0) ;
double eps = 1e-10 ;
const int dy[] = {-1,0,1,0};
const int dx[] = {0,-1,0,1};

double CalcDist(comd p1, comd p2){
  return sqrt(pow(p1.X - p2.X,2.0) + pow(p1.Y -p2.Y,2.0));
}

template <typename T>
void out(deque < T > d)
{
  for(size_t i = 0; i < d.size(); i++)
  {
    debug(d[i]);
  }
}

template<typename T>
T ston(string& str, T n){
  istringstream sin(str) ;
  T num ;
  sin >> num ;
  return num ;
}

int arr[100001];
void Eratosthenes(int N){
  for(int i = 0; i < N; i++){
    arr[i] = 1;
  }
  arr[1] = 0;
  for(int i = 2; i*i < N ; i++){
    if(arr[i]){
      for(int j = 0; i * (j + 2) < N; j++){
        arr[i *(j + 2)] = 0;
      }
    }
  }
}


int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N = 50100;
  Eratosthenes(N);
  int n;
  while(cin >> n){
    for(int i = n-1; i > 1; --i){
      if(arr[i] == 1){
        cout << i ;
        break;
      }
    }
    for(int i = n+1; i < N; ++i){
      if(arr[i] == 1){
        cout << " " << i << endl;
        break;
      }
    }
  }
  return 0;
}

Measured memory_bytes: 3316
#include <iostream>
#include <algorithm>
#include <math.h>
#include <vector>
#include <string>
#include <queue>
#include <map>
#include <utility>
#include <iomanip>  // std::setprecision()
using namespace std;
using ll = long long;
#define rep(i,a,b) for(int i=(a); i<(b); i++)
#define YES cout << "YES" << endl;
#define NO cout << "NO" << endl;
#define yes cout << "Yes" << endl;
#define no cout << "No" << endl;
#define pai 3.14159265358979323846
ll gcd(ll a, ll b){if (a%b == 0)  return(b);else  return(gcd(b, a%b));}
ll lcm(ll a, ll b){return a * b / gcd(a, b);}
/* map<string,int> */
/* 大文字を小文字に変換 tolower*/
/* 小文字を大文字に変換 toupper*/
/* 辞書順 next_permutation(a.begin(),a.end()) */
 
int main() {
    ll l,r;
    cin >> l >> r;
    if (r-l > 2100) {
        cout << 0 << endl;
        return 0;
    }
    int mi = 2100;
    for (ll i = l; i < r; i++) {
        for(ll j = i + 1 ; j<=r; j++) {
            int tmp = (i*j) % 2019;
            mi = min(mi, tmp);
        }
    }
    cout <<  mi << endl;

}

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

using namespace std;

long long a[250000];
long long f[250000];
long long n, k;
bool cmp(int a, int b)
{
    return (a > b);
}

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

bool is_possible(long long target)
{
    long long ex = 0;
    for (int i = 0; i < n; i++)
    {
        long long need = target / f[i];
        ex += max(0, (a[i] - need));
    }
    return ex <= k;
}

int main()
{

    cin >> n >> k;
    for (int i = 0; i < n; i++)
    {
        scanf("%lld", &a[i]);
    }
    for (int i = 0; i < n; i++)
    {
        scanf("%lld", &f[i]);
    }
    sort(a, a + n);
    sort(f, f + n, cmp);
    long long left = 0;
    long long right = (long long)1e12;
    while (left < right)
    {
        long long mid = (right + left) / 2;
        if(is_possible(mid)){
            right = mid;
        }else{
            left = mid + 1;
        }
    }
    cout << right << endl;

    return 0;
}

Measured memory_bytes: 3328
def main():
    N = int(input())
    a = list(map(int, input().split()))

    color = [False] * 8

    cnt = 0
    for i in a:
        if 1 <= i <= 399:
            color[0] = True
        elif 400 <= i <= 799:
            color[1] = True
        elif 800 <= i <= 1199:
            color[2] = True
        elif 1200 <= i <= 1599:
            color[3] = True
        elif 1600 <= i <= 1999:
            color[4] = True
        elif 2000 <= i <= 2399:
            color[5] = True
        elif 2400 <= i <= 2799:
            color[6] = True
        elif 2800 <= i <= 3199:
            color[7] = True
        elif 3200 <= i:
            cnt += 1
    if color.count(True) == 0:
        print(1, color.count(True) + cnt)
    else:
        print(color.count(True), color.count(True) + cnt)
    

main()


Measured memory_bytes: 3064
def input(f):
    global v, e, s, t, w
    
    v, e = map(int, f.readline().split())
    s = []
    t = []
    w = []
    for _ in range(e):
        s_, t_, w_ = map(int, f.readline().split())
        s.append(s_)
        t.append(t_)
        w.append(w_)

import os

if os.environ.get('ZEPPELIN_HOME'):
    import networkx as nx
    import matplotlib.pyplot as plt
    
    def visualize():
        G = nx.MultiDiGraph()
        for i in range(v):
            G.add_node(i, node_color='b')
        for i in range(e):
            G.add_edge(s[i], t[i], t=w[i])

        plt.figure()
        plt.style.use('seaborn')
        plt.axis("off")
        pos = nx.spring_layout(G)
        nodes = nx.draw_networkx_nodes(G, pos, node_color='w', linewidths=2)
        nodes.set_edgecolor('black')
        nx.draw_networkx_labels(G, pos)
        nx.draw_networkx_edges(G, pos)

        edge_labels = dict([((a, b), c['t']) for a, b, c in G.edges(data=True)])
        nx.draw_networkx_edge_labels(G, pos, edge_labels=edge_labels, label_pos=0.25, font_size=16)

        plt.show()

if os.environ.get('ZEPPELIN_HOME'):
    with open('/tmp/input1') as f:
        print('Example #1')
        input(f)
        visualize()

if os.environ.get('ZEPPELIN_HOME'):
    with open('/tmp/input2') as f:
        print('Example #2')
        input(f)
        visualize()

import sys
import heapq


class UnionFind:
    def __init__(self, v):
        self.parent = [-1] * v
    
    def find(self, x):
        if self.parent[x] == -1:
            return x
        else:
            self.parent[x] = self.find(self.parent[x])
            return self.parent[x]
    
    def merge(self, x, y):
        px = self.find(x)
        py = self.find(y)
        if px != py:
            self.parent[py] = px
    
    def is_same(self, x, y):
        return self.find(x) == self.find(y)


def init():
    global inf
    inf = sys.maxsize


def solve():
    q = []
    for i in range(e):
        heapq.heappush(q, (w[i], i))
    
    res = 0
    uf = UnionFind(v)
    while len(q) > 0:
        wi, i = heapq.heappop(q)
        if not uf.is_same(s[i], t[i]):
            uf.merge(s[i], t[i])
            res += wi
    
    print(res)

if os.environ.get('ZEPPELIN_HOME'):
    os.environ['INPUT'] = '/tmp/input1'

with open(os.environ.get('INPUT') or '/dev/stdin') as f:
    input(f)
    init()
    solve()

if os.environ.get('ZEPPELIN_HOME'):
    os.environ['INPUT'] = '/tmp/input2'

    with open(os.environ.get('INPUT') or '/dev/stdin') as f:
        input(f)
        init()
        solve()

if os.environ.get('ZEPPELIN_HOME'):
    os.environ['INPUT'] = '/tmp/input3'

    with open(os.environ.get('INPUT') or '/dev/stdin') as f:
        input(f)
        init()
        solve()

if os.environ.get('ZEPPELIN_HOME'):
    os.environ['INPUT'] = '/tmp/input3'

    with open(os.environ.get('INPUT') or '/dev/stdin') as f:
        input(f)
        init()
        solve()



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

int main() {
	int n,k=0;
	cin>>n;
	if(n>=105) k++;
		if(n>=135) k++;
	if(n>=165) k++;
		if(n>=195) k++;
		if(n>=189) k++;
		
		cout<<k<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <bitset>
#include <vector>
#include <string>
#include <algorithm>
#include <set>
#include <map>
#include <cmath>
#include <regex>
#include <iomanip>
#include <climits>
#include <utility>
#include <queue>
using namespace std;
using ll = long long int;
using dd = long double;
const ll MOD = 1e9 + 7;

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

ll fact(ll n)
{
    if (n == 0)
    {
        return 1;
    }
    if (n == 1)
    {
        return 1;
    }
    return n * fact(n - 1) % MOD;
}

ll pow_fast(ll n, ll k)
{
    if (k == 0)
    {
        return 1;
    }
    if (k == 1)
    {
        return n;
    }

    if (k % 2 == 0)
    {
        ll tmp = pow_fast(n, k / 2LL);
        return tmp * tmp % MOD;
    }
    else
    {
        ll tmp = pow_fast(n, k / 2LL);
        tmp *= tmp;
        tmp %= MOD;
        return tmp * n % MOD;
    }
}

map<ll, ll> sosuu(ll n)
{
    map<ll, ll> res;
    for (ll i = 2; i * i <= n; i++)
    {
        while (n % i == 0)
        {
            res[i] += 1;
            n /= i;
        }
    }
    if (n != 1)
    {
        res[n] += 1;
    }
    return res;
}

int main()
{
    ll X;
    cin >> X;

    // ll cur = 0;
    // ll time = 0;
    // while (cur < X)
    // {
    //     time += 1;
    //     cur += time;
    // }
    // cout << time << endl;

    ll l = 0;
    ll r = 1e9;
    while (r - l > 0)
    {
        ll mid = (l + r) / 2;
        ll cur = mid * (mid + 1) / 2;
        if (cur < X) {
            l = mid + 1;
        } else {
            r = mid;
        }
    }
    cout << l << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
using namespace std;
int main(){
    int n; cin >> n;
    string S; cin >> S;
    if(n % 2 == 1)cout << "No" << endl;
    else {
        string left_S, right_S;
        left_S = S.substr(0, n/2);
        right_S = S.substr(n/2, n/2);
        if(left_S == right_S) cout << "Yes" << endl;
        else cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
int main()
{
	int i,t,a=753;
	char s[11];

	scanf("%s",s);
	for(i=0;i<strlen(s)-2;i++){
		t=abs((s[i]-'0')*100+(s[i+1]-'0')*10+(s[i+2]-'0')-753);
		if(a>t)
			a=t;
	}
	printf("%d",a);
	return 0;
}

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

int main() {
  ios::sync_with_stdio(false);
  int N, K, R, S, P;
  string T;
  cin >> N >> K >> R >> S >> P >> T;

  vector<int> win(N);
  int ans = 0;

  for (int i = 0; i < N; i++) {
    if (i < K || T.at(i) != T.at(i - K) || !win.at(i - K)) {
      ans += (T.at(i) == 'r') ? P : (T.at(i) == 's') ? R : S;
      win.at(i) = 1;
    }
  }

  cout << ans << "\n";
}

Measured memory_bytes: 848
import sys
from collections import defaultdict
from itertools import accumulate
from operator import xor


def solve_0(acc):
    MOD = 10 ** 9 + 7
    cnt_0 = 0
    counts = defaultdict(list)
    last_0 = {}
    for a in acc:
        if a == 0:
            cnt_0 += 1
        else:
            cnt = counts[a]
            if len(cnt) == 0:
                cnt.append(1)
                last_0[a] = cnt_0
            else:
                btw_0 = cnt_0 - last_0[a]
                if btw_0 > 0:
                    cnt.append(btw_0)
                    cnt.append(1)
                    last_0[a] = cnt_0
                else:
                    cnt[-1] += 1

    ans = pow(2, cnt_0 - 1, MOD)
    for i, cnt in counts.items():
        dp0 = 1
        dp1 = cnt[0]
        for c0, c1 in zip(cnt[1::2], cnt[2::2]):
            dp0 = (dp0 + dp1 * c0) % MOD
            dp1 = (dp1 + dp0 * c1) % MOD
        ans = (ans + dp1) % MOD

    return ans


def solve_1(acc):
    MOD = 10 ** 9 + 7
    common = acc[-1]
    dp0 = 1
    dp1 = 0
    for a in acc:
        if a == 0:
            dp0 = (dp0 + dp1) % MOD
        elif a == common:
            dp1 = (dp1 + dp0) % MOD
    return dp0


n = int(input())
aaa = list(map(int, input().split()))
if 'PyPy' in sys.version:
    acc = [0] * n
    t = 0
    for i in range(n):
        t = acc[i] = t ^ aaa[i]
else:
    acc = list(accumulate(aaa, func=xor))
# print(acc)
if acc[-1] == 0:
    print(solve_0(acc))
else:
    print(solve_1(acc))


Measured memory_bytes: 97272
//#pragma GCC optimize "trapv"
#include <bits/stdc++.h>
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define rand rng
#define fios ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define DEBUG(x) cout << '>' << #x << ':' << x << endl;
#define M_PI 3.14159265358979323846
typedef long long ll;



int main() {
	//fios;
	string s, t;
	cin >> s >> t;

	int ans = 0;

	for(int i = 0; i < (int) s.length(); i++) {
		if(s[i] != t[i]) ans++;
	}
	cout << ans << endl;
}

Measured memory_bytes: 3900
/* ABC104: B
Sの先頭の文字は大文字の A である。
Sの先頭から 3 文字目と末尾から 2 文字目の間（両端含む）に大文字の C がちょうど 1
個含まれる。
以上の A, C を除く Sのすべての文字は小文字である。
	*/

#include <stdio.h>
#include <string.h>
#include <stdlib.h>

void wa(void){
	printf("WA\n");
	exit(0);
}

int main(void){
	char str[12];
	int sl;
	int i;
	int count=0;
	int apos=0;
	int cpos=0;
	
	scanf("%s", str);
	
	sl = strlen(str); // abcde\n => 6 - 1 => 5
	///  cd を調べる　2- (sl-1)
	
	if (str[0] != 'A') wa();
	for(i=2; i<sl-1; i++) {
	    if (str[i] == 'C') { count++; cpos=i; }
	}
	if (count!=1) wa();
	count=0;
	for(i=0; i<sl; i++){
		if (i != apos && i != cpos) {
		    if ('a' <= str[i] && str[i] <= 'z') {
			    count++;
	        }
		}
	}
	if (count != sl-2) wa();
	printf("AC\n");
	
	return 0;
}


Measured memory_bytes: 128
#include <iostream>

int f(int a,int b,int c){
    if(a<=b&&a<=c){
        return a;
    }else if(b<c){
    return b;
    }
    else {
        return c;
    }
}
int i(int x,int y){
    if(x<=y){
    return x;
    }else {
        return y;
    }
}
int main(){
    int a,b,c,d,e;
    std::cin>>a>>b>>c>>d>>e;
    std::cout<<f(a,b,c)+i(d,e)-50<<std::endl;
    return 0;
}


Measured memory_bytes: 3092
#include <iostream>
#include <vector>
#include <cstring>
#include <set>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <queue>
#include <deque>
#include <map>
#include <stack>
using namespace std;
#define ll long long
#define pb push_back
#define pp pair<long long,long long>
#define ppp pair<pair<long long,long long>,long long>
#define f firsta
#define s second
#define pd pair<double,long long>
int main() {
	ll t,n,i,j,k,l,m;
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	ll p;
	t=1;
	//cin>>t;
	while (t--) {
		cin>>i>>j>>k>>l;
		ll op1 = i*k;
		ll op2 = i*l;
		ll op3 = j*k;
		ll op4 = j*l;
		cout<<max(op1,max(op2,max(op3,op4)))<<'\n';
	}
	return 0;
}

Measured memory_bytes: 3648
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#define setbits(x)      __builtin_popcountll(x)
#define mod             1000000007
#define FIO             ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define ll              long long 
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
using namespace std;

//int a[307][307];
int main()
{
    FIO;
//    ll t; cin>>t;
//	while(t--)
//	{
    int x,y; cin>>x>>y;
    int flag =1;
    int b;
    for(int i=0;i<=x;i++){
    b = x - i;
    if(4*i + 2*b == y){
    	cout<<"Yes"; flag = 0; break;
	}
    }
    
	
	if(flag)cout<<"No";
//	cout<<ans;
return 0; 
}

Measured memory_bytes: 3648
import itertools

n = int(input())
a = tuple([int(i) for i in input().split()])
b = tuple([int(i) for i in input().split()])
ai = 0
bi = 0
i = 1
val = [None] * n

for i in range(n):
    val[i] = i+1
for v in itertools.permutations(val, n):
    if v == a: ai = i-1
    if v == b: bi = i-1
    i += 1

print(abs(ai-bi))

Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main(){
int w,h,x,y;
cin>>w>>h>>x>>y;
cout<<1.0*w*h/2.0<<" ";
if(1.0*x==w/2.0&&1.0*y==h/2.0)cout<<1;
//else if(1.0*x==w/2.0||1.0*y==h/2.0)cout<<0;
//else if(x==w||h==y)cout<<0;
//else if(x*h==y*w||h*x+w*y-h*w==0);
else cout<<0;
}

Measured memory_bytes: 888
#include<iostream>
#include<vector>
#include<map>
#include<algorithm>
#include<string>
#include<iomanip>
#include<cstdio>

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)   FOR(i,0,n)
#define MOD 1000000007
#define MAXS(x,y) (x = max(x,y))
#define MINS(x,y) (x = min(x,y))

using namespace std;

typedef long long int ll;

const ll INF=(ll)1e18;


int N, K;

int b[2002][2002];
int s[4002][4002];

int get(int x , int y){
	return s[x+K-1][y+K-1] + s[x-1][y-1] - s[x-1][y+K-1] - s[x+K-1][y-1];
}

int main(){
  cin >> N >> K;

  REP(i,N){
    ll xx,yy;
    char cc;
    cin >> xx >> yy >> cc;
    if(cc == 'W')yy += K;
    ++b[xx%(2*K) + 1][yy% (2*K) + 1];
  }

  FOR(i,1,4*K+1)FOR(j,1,4*K+1){
    s[i][j] += s[i][j-1] + b[(i-1)%(2*K)+1][(j-1)%(2*K)+1];;
  }
  FOR(i,1,4*K+1)FOR(j,1,4*K+1){
    s[j][i] += s[j-1][i];
  }

  int ans = 0;
	FOR(i,1,2*K+1){
		FOR(j,1,2*K+1){
			ans = max(ans , get(i,j) + get(i+K,j+K));
		}
	}

  cout << ans << endl;
}

Measured memory_bytes: 78464
n, k = [int(t) for t in input().split()]
w = [int(input()) for i in range(n)]

hi = sum(w)
lo = max(w)

def canMove(w, P, k):
    s = 0
    for i in range(len(w)):
        if s + w[i] > P:
            s = 0
            k -= 1
            if k <= 0: return False
        s += w[i]
    return True

P = hi
while lo < hi:
    m = (lo + hi) // 2
    if canMove(w, m, k):
        P = m
        hi = m
    else:
        lo = m + 1

print(P)



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

#define int long long
#define vvi vector<vector<int>>
#define vec vector
#define pq priority_queue
#define all(v) (v).begin(), (v).end()
#define uniqueV(x) sort(x.begin(), x.end()); x.erase(unique(x.begin(), x.end()), x.end());
#define rep(i, n) for (int (i) = (0); (i) < (n); ++(i))
#define repp(i, m, n) for (int (i) = (m); (i) < (n); ++(i))
#define dbg(x) cerr << #x << ": " << x << endl;
#define dbg2(x, y) cerr<<"("<<#x<<", "<<#y<<") = "<<"("<<x<<", "<<y<<")"<<endl;
#define dbg3(x, y, z) cerr<<"("<<#x<<", "<<#y<<", "<<#z<<") = "<<"("<<x<<", "<<y<<", "<<z<<")"<<endl;
#define dbgB(value, size) cerr<<#value<<": "<<bitset<size>(value) << endl;
#define line() cerr << "---------------" << endl;

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

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }

template<typename T>
void print1(T begin, T end) {
  while (begin != end) {
    cout << (*begin) << " ";
    *begin++;
  }
  cout << endl;
}

template<typename T>
void print2(T Array, int height, int width) {
  for (int i = 0; i < height; i++) {
    for (int j = 0; j < width; j++) {
      cout << " " << Array[i][j];
    }
    cout << endl;
  }
}

void print() { std::cerr << endl; }
template <class Head, class... Tail>
void print(Head&& head, Tail&&... tail) {
  std::cerr << head << " ";
  print(std::forward<Tail>(tail)...);
}

template<class T>
void Add(T &a, const T &b, const T &mod=1000000007) {
  int val = ((a % mod) + (b % mod)) % mod;
  if (val < 0) { val += mod; }
  a = val;
}

template <typename X, typename T> auto vectors(X x, T a) { return vector<T>(x, a); }
template <typename X, typename Y, typename Z, typename... Zs> auto vectors(X x, Y y, Z z, Zs... zs) { auto cont = vectors(y, z, zs...); return vector<decltype(cont)>(x, cont); }

// ------------------------------------------------------------------------------------------

const int INF = 1e18;

int A, B, Q;
vector<int> s, t;

int solve(int x) {
  vector<int> S(2), T(2);
  S[0] = *lower_bound(all(s), x);
  S[1] = *prev(upper_bound(all(s), x));
  T[0] = *lower_bound(all(t), x);
  T[1] = *prev(upper_bound(all(t), x));

  int ans = 8e18;
  for (int i = 0; i < 2; i++) {
    for (int j = 0; j < 2; j++) {
      chmin(ans, abs(x - S[i]) + abs(S[i] - T[j]));
      chmin(ans, abs(x - T[j]) + abs(S[i] - T[j]));
    }
  }

  return ans;
}

signed main() {
  cin >> A >> B >> Q;
  s.resize(A);
  t.resize(B);
  rep (i, A) { cin >> s[i]; }
  rep (i, B) { cin >> t[i]; }
  s.push_back(INF);
  s.push_back(-INF);
  t.push_back(INF);
  t.push_back(-INF);
  sort(all(s));
  sort(all(t));

  while (Q--) {
    int x;
    cin >> x;
    int ans = solve(x);
    cout << ans << endl;
  }

  return 0;
}

Measured memory_bytes: 2912
import java.util.Scanner;
public class Main {
	
	static void Increment_Array(int[] array, int idx) {
		array[idx]++;
	}
	
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner stdIn = new Scanner(System.in);
		
		int[] mem = new int[31];
		
		for(int r = 0; r < 28; r++) {
			int buf = stdIn.nextInt();
			Increment_Array(mem, buf);
		}
		
		for(int idx = 1; idx < 31; idx++) {
			if(mem[idx] == 0) System.out.println(idx);
		}
	}
}

Measured memory_bytes: 17200
import sys
from collections import defaultdict, Counter, deque
from itertools import accumulate, permutations, combinations
from operator import itemgetter
from bisect import bisect_left, bisect_right, bisect
from heapq import heappop, heappush
from fractions import gcd
from math import ceil, floor, sqrt, cos, sin, pi
from copy import deepcopy

# If you use recursive call, uncomment this code
#sys.setrecursionlimit(10**6)

def main():
    sx,sy,tx,ty = map(int, input().split())
    dx = ("R","L") if sx <= tx else ("L","R")
    dy = ("U","D") if sy <= ty else ("D","U")
    lx = abs(sx-tx)
    ly = abs(sy-ty)

    ans = ""
    for i in range(2):
        ans += dy[i]*ly
        ans += dx[i]*lx
   
    for i in range(2):
        inv = (i+1)%2
        ans += dx[inv]
        ans += dy[i]*(ly+1)
        ans += dx[i]*(lx+1)
        ans += dy[inv]

    print(ans)
    #print(len(ans))
    
if __name__ == '__main__':
    main()

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

int main() {
    int N;
    cin >> N;
    vector<int> val(N);
    for(int i = 0;i<N;i++){
        cin >> val.at(i);
    }
    
    sort(val.begin(),val.end());
    reverse(val.begin(),val.end());

    val.at(0) = val.at(0)/2;

    int value = 0;

    for(int j = 0;j<N;j++){
        value = value + val.at(j);
    }

    cout << value << endl;
}

Measured memory_bytes: 256
#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;
 
  int count = 0;
  for (int i = A; i < B + 1; i++) {
    if (i % 10 == i / 10000)
      if (i % 100 / 10 == i / 1000 % 10)
        count++;
  }
  
  cout << count << endl;
}

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

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

	int n;
	list<long> l;
	cin >> n;
	for (int i = 0; i<n; i++) {
		string command;
		int value;
		cin >> command;
		if (command == "insert" || command == "delete")
			cin >> value;
		if (command == "deleteFirst") {
			l.pop_front();
		} else if (command == "deleteLast")	{
			l.pop_back();
		} else if (command == "insert") {
			l.push_front(value);
		} else if (command == "delete") {
			list<long>::iterator itr;
			bool found = false;
			for (itr = l.begin();itr != l.end(); itr++) {
				if (*itr == value) {
					found = true;
					break;
				}
			}
			if (found)
				l.erase(itr);
		}
	}

	int count = 0;
	for (auto itr = l.begin();itr != l.end();itr++) {
		if (count != 0)
			cout << " ";
		cout << *itr;
		count++;
	}
	cout << endl;
}




Measured memory_bytes: 34448