akhauriyash/Code-Regression huggingface dataset:
/*** akshaykumar99 ***/
 
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
 
using namespace std;
using namespace __gnu_pbds;
 
template<typename T> using id_set = tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update> ;
 
#define f(i,x,n) for(i=x;i<n;i++)
#define fr(i,x,n) for(i=x;i>=n;i--)
#define pu push_back           
#define pp pop_back
#define F first
#define S second
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define SP(x) fixed<<setprecision(x)
#define IOS() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
 
const long long MOD = 1e9+7;
const long double PI = acos(-1);
const long long INF = INT_MAX;
const long long LINF = LLONG_MAX;
const long long N = 2e6+1;
 
typedef long long ll;
typedef long double ld;  
 
void test_case()
{
    ll a, b = 0;
    cin >> a;
    b = a + a*a + a*a*a;
    cout << b <<'\n';
 
}
 
int32_t main()
{
    IOS(); 
    
    int tc=1;
    // cin>>tc;
    while(tc--)
        test_case();
    return 0;
}

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

int main(){
    int x, y, W, H, r;
    
    cin >> W >> H >> x >> y >> r;
    
    if((x - r) >= 0 && (x + r) <= W && (y - r) >= 0 && (y + r) <= H){
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }
}


Measured memory_bytes: 3116
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
#define fi first
#define se second
typedef pair<ll,ll> P;
using VP = vector<P>; using VVP = vector<VP>;
using VI = vector<ll>; using VVI = vector<VI>; using VVVI = vector<VVI>;
const int inf=1e9+7;
const ll INF=1LL<<58;
const ll mod=998244353;

int main(){
  int i,j;
  ll n;
  cin>>n;
  VI v(n,0);
  int d[n];
  for(i=0;i<n;i++){
    cin>>d[i];
    v[d[i]]++;
  }
  ll ans=1;
  if(d[0]!=0) {
    cout<<0<<endl;
    return 0;
  }
  if(v[0]!=1) {
    cout<<0<<endl;
    return 0;
  }
  for(i=2;i<n;i++){
    for(j=0;j<v[i];j++){
      ans*=v[i-1];
      ans%=mod;
    }
  }
  cout<<ans<<endl;
}


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

long long s(long long n){
    long long res = 0;
    for(; n > 0; n /= 10) res += n%10;
    return res;
}

bool comp(const long long &a, const long long &b){
    long long ta = a * s(b);
    long long tb = b * s(a);
    if(ta == tb) return a < b;
    return ta < tb;
}

long long f(long long n){
    vector<long long> v;
    for(long long i=1;i<=n;i*=10){
        v.push_back(n - n%i + i - 1);
    }
    sort(v.begin(), v.end(), comp);
    return v[0];
}

int main(void){
    int k;
    long long n = 1;
    cin >> k;
    for(int i=0;i<k;i++){
        cout << n << endl;
        n = f(n+1);
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; (i) < (int)(n); ++ (i))
#define REP3(i, m, n) for (int i = (m); (i) < (int)(n); ++ (i))
#define REP_R(i, n) for (int i = (int)(n) - 1; (i) >= 0; -- (i))
#define REP3R(i, m, n) for (int i = (int)(n) - 1; (i) >= (int)(m); -- (i))
#define ALL(x) std::begin(x), std::end(x)
using namespace std;
template <typename T> istream & operator >> (istream & in, vector<T> & xs) { REP (i, xs.size()) { in >> xs[i]; } return in; }

template <typename UnaryPredicate>
int64_t binsearch(int64_t l, int64_t r, UnaryPredicate p) {
    assert (l <= r);
    -- l;
    while (r - l > 1) {
        int64_t m = l + (r - l) / 2;
        (p(m) ? r : l) = m;
    }
    return r;
}

int64_t solve(int64_t n, int64_t k, const vector<int64_t> & a) {
    vector<int64_t> nonnegative, negative;
    for (int64_t a_i : a) {
        (a_i >= 0 ? nonnegative : negative).push_back(a_i);
    }
    sort(ALL(nonnegative));
    sort(ALL(negative));
    reverse(ALL(negative));

    auto count_lt = [&](int64_t x) {
        int64_t cnt = 0;
        for (int64_t a_i : nonnegative) {
            cnt += binsearch(0, nonnegative.size(), [&](int j) {
                return a_i * nonnegative[j] >= x;
            });
            cnt += negative.size() - binsearch(0, negative.size(), [&](int j) {
                return a_i * negative[j] < x;
            });
        }
        for (int64_t a_i : negative) {
            cnt += nonnegative.size() - binsearch(0, nonnegative.size(), [&](int j) {
                return a_i * nonnegative[j] < x;
            });
            cnt += binsearch(0, negative.size(), [&](int j) {
                return a_i * negative[j] >= x;
            });
        }
        for (int64_t a_i : a) {
            cnt -= (a_i * a_i < x);
        }
        return cnt / 2;
    };
    return binsearch(-2e18, 2e18, [&](int64_t x) {
        return count_lt(x + 1) >= k;
    });
}

int main() {
    int64_t n, k; cin >> n >> k;
    vector<int64_t> a(n); cin >> a;
    cout << solve(n, k, a) << endl;
    return 0;
}


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

int main() {
	int k;
	cin >> k;
	int x = 7 % k;
	set<int> s;
	int ans = -1;
	while (!s.count(x)) {
		if (x == 0) {
			ans = s.size() + 1;
			break;
		}
		s.insert(x);
		x = (x * 10 + 7) % k;
	}
	cout << ans << endl;
	return 0;
}

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


int N, M;

void Main() {
  cin >> N >> M;

  if (M >= N) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}

int main() {
  Main();
  return 0;
}


Measured memory_bytes: 256
from functools import reduce
from operator import xor
from sys import exit

def muri():
    print(-1)
    exit()

N = int(input())
A = [int(input()) for _ in range(N)]
X = reduce(xor, A)
T = [False]*33
for a in A:
    T[(a & -a).bit_length()-1] = True

ans = 0

for b in range(32, -1, -1):
    if X & 2**b:
        if not T[b]:
            muri()
        ans += 1
        X ^= 2**(b+1)-1

print(ans)

Measured memory_bytes: 50880
#include<iostream>
#include<math.h>

using namespace std;

int main (){
    int i, n;
    int debt = 100000;
    cin >> n;

    for(i=0; i<n; i++){
        debt = ceil( debt * 1.05 / 1000) * 1000;
    }

    cout << debt << endl;
}

Measured memory_bytes: 1164
import sys
import string
N = int(input())
S = input()
s = list(S)
array = string.ascii_uppercase

if not ( 0 <= N <= 26 ): sys.exit()
if not ( 1 <= len(s) <= 10**4 ): sys.exit()
if not S.isupper(): sys.exit()

for I in s:
    if array.index(I) + N <= 25:
        print(array[array.index(I) + N],end='')
    else:
        print(array[(array.index(I) + N) - 26],end='')

Measured memory_bytes: 10088
import sys
from collections import Counter


def main():
    H, W, M = map(int, sys.stdin.readline().rstrip().split())
    Mh = [0] * H
    Mw = [0] * W
    B = []
    for i in range(M):
        h, w = map(int, sys.stdin.readline().rstrip().split())
        Mh[h - 1] += 1
        Mw[w - 1] += 1
        B.append((h - 1, w - 1))

    nh = max(Mh)
    nw = max(Mw)

    # 交差する場所に置かれた処理物があるか？
    lh = Counter(Mh)[nh]
    lw = Counter(Mw)[nw]

    out = 0
    for (h, w) in B:
        if Mh[h] == nh and Mw[w] == nw:
            out += 1

    if out == lh * lw:
        print(nh + nw - 1)
    else:
        print(nh + nw)


main()


Measured memory_bytes: 54480
#include<iostream>
#include<cstdio>
#include<vector>
#include<algorithm>
#include<array>

using namespace std;
int main(){
    int a,b,ans=0;
    cin >> a >> b;
    vector<int> c(a);
    for(int i = 0;i < a;i++)
      cin >> c[i];

    sort(c.begin(),c.end());
    
    for(int i = 0;i< a;i++){
      if(c[i] <= b && i != a-1){
        b -= c[i];
        ans++;
      }
      else if(c[i] == b && i == a-1)
        ans++;
      else break;
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
s = list(input())
ll = len(s)
ans = 0
for i in range(len(s)):
    s = s[0: len(s)-1]
    if len(s)%2 == 0:
        r = s[0:len(s)//2]
        l = s[len(s)//2:]
        if r == l:
            ans = i + 1
            break
print(ll-ans)

Measured memory_bytes: 3064
//luckYrat written
//Twitter: @luckYrat_


//#include <bits/stdc++.h>

//def
#include <iostream>

#include <cmath>
#include <algorithm>
#include <iomanip>

//array
#include <vector>
#include <set>
#include <stack>
#include <map>

//god(強すぎるので使用禁止！！！！！！！)
//#include <tourist>

using namespace std;

typedef pair<int,int> Paint;

bool Pairsecond(const Paint& pf,Paint&ps){//sortCompare
  return pf.second < ps.second;
}

#define anyfill(n,s) setw(n) << setfill(s)
#define rep(i,q) for(int i = 0; (q) > i; i++)
#define MAX 1000000000
#define MOD 1000000007


/*
確認ポイント
to_string() はC++11以降の実装;
cout<< (char)数値 //数値にあった文字に置き換えられる
cout<< (double)int型/(2など)//小数になる
length(),size()に括弧をつけ忘れてないか;
sort()が使える型//vector,string...
大文字小文字間違えてないか
cout << fixed << 小数計算//正しい小数表記になる(基本6桁)(e記法回避にも使える)
cout << fixed << setprecision(n) << 小数計算//n桁の小数表記になる
sqrt(数値型)でrootが取れる
vector.unique()は隣接した同じ要素を削除するので先にソートをする
*/
int main(){
  long long n;cin>>n;
  long long a[n];
  long long sm = 0;
  for(int i = 0; n > i; i++){
    cin>>a[i];
    sm += a[i];//1,2...n-1,n
  }
  long long tmp = 0;
  long long ans;
  for(int i = 0; n > i; i++){
    if(i == 0){
      for(int j = 2; n > j; j+=2){
        tmp += a[j-1]*2;
      }
      cout << sm - tmp << " ";
      ans = sm-tmp;
    }else{
      ans = a[i-1]*2-ans;
      cout << ans;
      if(i+1 != n)cout << " ";
    }
  }
  cout << endl;
}







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


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

    vector<pair<int64_t, int64_t>> magic(n);
    for (int i=0; i<n; i++){
        int64_t a, b;
        cin >> a >> b;
        magic.at(i) = make_pair(a, b);
    }

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

    vector<int64_t> dp(h+1);
    for (int i=1; i<=h; i++){
        dp.at(i) = 100000000;
        for (int j=0; j<n; j++){
            dp.at(i) = min(dp.at(i), magic.at(j).second+dp.at(max((int64_t)0, i-magic.at(j).first)));
        }
    }

    cout << dp.at(h) << endl;

    return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
    
#define int long long

#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,m,n) for(int i=m;i<n;i++)
#define FORR(i,m,n) for(int i=m;i>=n;i--)
#define pb(x) push_back(x)
#define mp(x, y) make_pair(x, y) 
#define SORT(x) sort((x).begin(),(x).end())
#define INF 99999999999
#define MOD (int)(1e9)+7

using namespace std;

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

int32_t main(){
    int n, t;
    cin >> n >> t;
    vector<int> v(n);
    int sum=0;
    REP(i, n){
        cin >> v[i];
        if(i>0){
            int a = v[i] - v[i-1];
            if(a < t){
                sum+=a;
            }
            else{
                sum+=t;
            }
        }
    }
    sum+=t;

    cout << sum << endl;
}

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

using namespace std;

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
    string s;
    cin>>s;
    if(s[2]==s[3]&&s[4]==s[5])
        cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
constexpr auto MOD = 1000000007;
constexpr int INF = 1e9;
constexpr long long LINF = 1e18;
#define rep(i, n) for (int i = 0; i < (n); i++)
typedef long long ll;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
typedef vector<int> VI;
typedef vector<ll> VLL;

string s;
long long n, m;

int main()
{
  cin >> s;
  int ans = 0;
  for (int i = 0; i < s.size()/2; i++)
  {
    if(s[i]==s[s.size()-1-i])
      continue;
    ans++;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
int main()
{

	while (1) {
		int n;
		std::cin >> n;
		if (n == 0) {
			break;
		}
		char before[100000], after[100000];
		for (int i = 0; i < n; i++) {
			std::cin >> before[i] >> after[i];
		}
		int m;
		std::cin >> m;
		char s_before[100000];
		std::string s_after(m,' ');
		for (int i = 0; i < m; i++) {
			std::cin >> s_before[i];
			s_after[i] = s_before[i];
			for (int j = 0; j < n; j++) {
				if (s_before[i] == before[j]) {
					s_after[i] = after[j];
				}
			}
		}
		std::cout << s_after << std::endl;
	}
	return 0;
}

Measured memory_bytes: 3280
#include <iostream>      // cout, endl, cin
#include <string>        // string, to_string, stoi
#include <vector>        // vector
#include <algorithm>     // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility>       // pair, make_pair
#include <tuple>         // tuple, make_tuple
#include <cstdint>       // int64_t, int*_t
#include <cstdio>        // printf
#include <map>           // map
#include <queue>         // queue, priority_queue
#include <set>           // set
#include <stack>         // stack
#include <deque>         // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset>        // bitset
#include <cctype>        // isupper, islower, isdigit, toupper, tolower
#include <string.h>

using namespace std;

int main()
{
    //system("chcp 65001");

    char S[101];
    cin >> S;

    int i;
    int j = 0;
    
    int ans = 0;

    int n = strlen(S);
    
    if(n%2 == 0)
    {
        for (i = n / 2 - 1; i >= 0; i--)
        {
            j += 1;
            if(S[i] != S[n/2-1+j])
            {
                ans++;
            }
        }
    }

    if(n%2 == 1)
    {
        for (i = n / 2 - 1; i >= 0; i--)
        {
            j += 1;
            if (S[i] != S[n / 2  + j])
            {
                ans++;
            }
        }
    }

    cout << ans;
    return 0;
}

Measured memory_bytes: 256
import sys
def input(): return sys.stdin.readline().rstrip()
def main():
    n,a,b,c,d=map(int,input().split())
    s=input()
    for i in range(a,max(c,d)):
        if i+2<=n:
            if s[i:i+2]=='##':
                print("No")
                break
    else:
        if c<d:
            print("Yes")
        else:
            flag=False
            for i in range(b-1,d):    
                if s[i-1:i+2]=="...":
                    flag=True
            if flag==True:
                print("Yes")
            else:
                print("No")

if __name__=='__main__':
    main()

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

int main()
{
    int n;
    cin >> n;
    vector<string> s(n);
    rep(i, n) cin >> s[i];
    sort(s.begin(), s.end());
    int cnt=1;
    rep(i, n-1) if (s[i] != s[i+1]) cnt++;
    cout << cnt << endl;
    
    return 0;
}

Measured memory_bytes: 9604
#include <bits/stdc++.h>
#include <vector>
#include <algorithm>
#include <deque>
#include <numeric>
#include <utility>
#define sign(a) ((a>0)-(a<0))
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define LL long long
#define INF (LL)(1LL<<60)

using namespace std;

void solve(long long N, std::vector<long long> A){
    auto f = [N, &A](LL a0, bool p){
        LL tmp=a0;
        for(int i=0; i<N; i++){
            if(p)cout << 2*tmp << " ";
            tmp = A[i]-tmp;
        }
        return a0-tmp;
    };
    LL l=0,r=A[0]+1;
    while(r-l>1){
        LL med=(r+l)/2;
        LL ret=f(med, false);
        if(ret==0){
            l=med;
            break;
        }else if(ret>0)r=med;
        else l=med;
    }
    f(l, true);
}

int main(){
    long long N;
    scanf("%lld",&N);
    std::vector<long long> A(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&A[i]);
    }
    solve(N, std::move(A));
    return 0;
}


Measured memory_bytes: 2048
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int num[52];
int main()
{
	int mark[2];
	int pd=0;
	int count=0;
	int n;
	scanf("%d",&n);
	for(int i=0;i<n;i++)
	{
		scanf("%d",&num[i]);
		if(i>0)
		{
			
			if(num[i]<num[i-1])
			{
				if(pd==0)
				{
					mark[0]=i-1;
					pd=1;
				}
				else
				{
					mark[1]=i;
				}
				count++;
			}
		}
		
	}
//	printf("count=%d pd==%d m1=%d m2=%d \n",count,pd,mark[0],mark[1]);
	if(count==2&&pd==1)
	{
		//printf("test");
		
		swap(num[mark[0]],num[mark[1]]);
		//printf("%d %d \n",num[mark[0]],num[mark[1]]);
		if(num[mark[0]]<num[mark[0]+1]&&num[mark[1]]>num[mark[1]-1])
		printf("YES");
		else
		printf("NO");
	}
	else
	{
		if(pd==1)
		printf("NO");
		else
		printf("YES");
	}
	
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
typedef pair<int,int> pii;
queue<int>q;
int ver[5009*2],edge[5009*2],nxt[5009*2],head[3009],tot=0;
ll d[3009];int v[3009];
void add(int x,int y,int z)
{
    ver[++tot]=y;edge[tot]=z;nxt[tot]=head[x];head[x]=tot;
}
int ban[3009],cntru[3009];
int dfsv[3009];
int n,m,p;
void spfa()
{
    memset(d,0xcf, sizeof(d));
    memset(v,0, sizeof(v));
    d[1]=0;v[1]=1;
    q.push(1);
    while(q.size())
    {
        int x=q.front();q.pop();
        v[x]=0;
        for(int i=head[x];i;i=nxt[i])
        {
            int y=ver[i],z=edge[i];
            if(ban[y])continue;
            if(d[y]<d[x]+z){
                d[y]=d[x]+z;
                if(!v[y]){
                    ++cntru[y];
                    if(cntru[y]>=n){
                        puts("-1");
                        exit(0);
                    }
                    q.push(y),v[y]=1;
                }
            }
        }
    }
    cout<<max(0ll,d[n])<<endl;
}
int dfs(int x){
    if(dfsv[x])return 0;
    if(x==n)return 1;
    dfsv[x]=1;
    for(int i=head[x];i;i=nxt[i]){
        if(dfs(ver[i]))return 1;
    }
    return 0;
}
int main()
{
    scanf("%d%d%d",&n,&m,&p);
    for(int i=1;i<=m;i++){
        int u,vx,vv;scanf("%d%d%d",&u,&vx,&vv);
        add(u,vx,vv-p);
    }
    for(int i=1;i<=n;i++){
        memset(dfsv,0,sizeof(dfsv));
        if(!dfs(i))ban[i]=1;
    }
    spfa();
    return 0;
}



Measured memory_bytes: 512
n = int(input())
a = list(map(int, input().split()))

pre = a[0]
now = ""
cnt = 1
for i in a:
    if now == "":
        if i > pre:
            now = ">"
        elif i < pre:
            now = "<"
    else:
        if i > pre and now == "<":
            now = ""
            cnt += 1
        elif i < pre and now == ">":
            now = ""
            cnt += 1
    pre = i
print(cnt)

Measured memory_bytes: 14252
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using vi = vector<int>;
using vvi = vector<vi>;
int main () {
  int a, b;
  cin >> a >> b;
  cout << max({a+b, a*b, a-b});
}

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

//flag?????¨????????????????????????
int bubbleSort(int A[],int N){
	int sw = 0;
	bool flag = 1;
	for(int i=0;flag;i++){
		flag = 0;
		for(int j=N-1;j>i;j--){
			if(A[j]<A[j-1]){
				swap(A[j],A[j-1]);
				sw++;
				flag = 1;
			}
		}
	}
	return sw;
}

int main(){
	int N,A[100],sw;
	cin>>N;
	
	for(int i=0;i<N;i++){
		cin>>A[i];
	}
	
	sw = bubbleSort(A,N);
	
	for(int i=0;i<N;i++){
		if(i) cout<<" ";
		cout<<A[i];
	}
	
	cout<<endl;
	cout<<sw<<endl;
	
	return 0;
}

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

int n;
vector <int> x;

int MAIN()
{
	cin >> n;
	for(int i = 0; i < 2*n; i++)
	{
		int t;
		cin >> t;
		x.push_back(t);
	}
	int sum = 0;
	sort(x.begin(), x.end());
	for(int i = 0; i < x.size(); i+=2)
		sum += x[i];
	cout << sum << endl;
	return 0;
}

int main()
{
	int start = clock();
	#ifdef LOCAL_TEST
		freopen("in.txt", "r", stdin);
		freopen("out.txt", "w", stdout);
	#endif
	ios :: sync_with_stdio(false);
	cout << fixed << setprecision(16);
	int ret = MAIN();
	#ifdef LOCAL_TEST
		cout << "[Finished in " << clock() - start << " ms]" << endl;
	#endif
	return ret;
}


Measured memory_bytes: 256
using System;
    using System.Collections.Generic;
    using static System.Console;
    using System.Linq;


class Program
{
    static void Main(string[] Args) {
        int N = Int32.Parse(ReadLine());
        string stn = N.ToString();

        bool isten = true;
        if (stn[0] != '1') isten = false;
        for(int i = 1;i < stn.Length; i++) {
            if (stn[i] != '0') isten = false;
        }
        int Result = 0;
        if (isten) Result = 10;
        else {
            foreach(char c in stn) {
                Result += Int32.Parse(c.ToString());
            }
        }

        WriteLine(Result);

        ReadLine();
    }
}

Measured memory_bytes: 13140
#include<bits/stdc++.h>
using namespace std;
#define ALL(v) (v).begin(),(v).end()
#define REP(i,p,n) for(int i=p;i<(int)(n);++i)
#define rep(i,n) REP(i,0,n)
#define SZ(x) ((int)(x).size())
#define debug(x) cerr << #x << ": " << x << '\n'

typedef long long int Int;
typedef pair<int,int> P;
using ll = long long;
using VI = vector<int>;
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; }
const long long INF = 1LL<<60;

int main(){
    int s,w;cin >> s >> w;
    if(w>=s){
        cout << "unsafe" << endl;
    }else{
        cout << "safe" << endl;
    }
}

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

using namespace std;

int main(){
    int N; cin >> N; int A[N];
    cin >> A[0] >> A[1]; int gcd = __gcd(A[0], A[1]);
    for (int i = 2; i < N; i++){
        cin >> A[i];
        //if (gcd == 1) break;
        gcd = __gcd(gcd, A[i]);
    } cout << gcd << endl;

    return 0;
}


Measured memory_bytes: 640
import java.util.Scanner;
public class Main{
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		int[][][] count = new int[4][3][10];
		int[] vb = new int[4];

		for(int i=0;i<n;i++){
			for(int j=0;j<4;j++)
				vb[j]=scan.nextInt();
			count[vb[0]-1][vb[1]-1][vb[2]-1]+=vb[3];
		}
		for(int i=0;i<4;i++){
			for(int j=0;j<3;j++){
				for(int k=0;k<10;k++){
					System.out.print(" "+count[i][j][k]);
				}
				System.out.println("");
			}
			if(i!=3)
				System.out.println("####################");
		}
	}
}

Measured memory_bytes: 21208
#include <stdio.h>
#include <string>
#include <algorithm>
#include <iostream>
#include <cmath>
using namespace std;

int r, d, x, ans;

int main() {
    scanf("%d %d %d", &r, &d, &x);
    ans = x;
    
    for ( int i = 1; i <= 10; i++ ) {
        ans = r * ans - d;
        printf("%d\n", ans);
    }
    
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<bits/stdc++.h>
using namespace std;
int arr[100001][4];
int ans[100001];
int n;
/*int func(int a,int b)
{
    int p1;
    if(a==n+1)
    return 0;
    if(b==1)
    p1 = arr[a][b]+max(func(a+1,2),func(a+1,3));
    else if(b==2)
    p1 = arr[a][b]+max(func(a+1,1),func(a+1,3));
    //else
    else if(b==3)
    p1 = arr[a][b]+max(func(a+1,1),func(a+1,2));
    
    
    return p1;
    
}*/
int main()
{
    //int n;
    int i,j;
    memset(arr,0,sizeof(arr));
    cin>>n;
    for(i=1;i<=n;i++)
    for(j=1;j<=3;j++)
    cin>>arr[i][j];
    for(i=1;i<=n;i++)
    ans[i]=-1;
    
    int pre[n+1][4];
    memset(pre,0,sizeof(pre));
    pre[1][1] = arr[1][1];
    pre[1][2] = arr[1][2];
    pre[1][3] = arr[1][3];
    for(i=2;i<=n;i++)
    {
        pre[i][1] = arr[i][1]+max(pre[i-1][2],pre[i-1][3]);
        pre[i][2] = arr[i][2]+max(pre[i-1][1],pre[i-1][3]);
        pre[i][3] = arr[i][3]+max(pre[i-1][1],pre[i-1][2]);
    }
    
    cout<<max(pre[n][1],max(pre[n][2],pre[n][3]));
}

Measured memory_bytes: 3712
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=55,mod=1e9+7,inf=2000000000;
int n,a[N];
char s[N];
unordered_map<ll,int>vis[20][20];
int main()
{
    scanf("%d",&n);
    scanf("%s",s+1);
    int up=1<<n;
    for(int i=0;i<up;i++)
    {
        ll sum1=0,sum2=0,a=__builtin_popcount(i),b=n-a;
        for(int j=1;j<=n;j++)
            if(i>>j-1&1)
            sum1=(sum1*2333%mod+s[j]-'a')%mod;
            else sum2=(sum2*2333%mod+s[j]-'a')%mod;
        //cout<<a<<' '<<b<<' '<<sum1*inf+sum2<<endl;
        vis[a][b][sum1*inf+sum2]++;
    }
    reverse(s+1,s+1+n+n);
    ll ans=0;
    for(int i=0;i<up;i++)
    {
        ll sum1=0,sum2=0,a=__builtin_popcount(i),b=n-a;
        for(int j=1;j<=n;j++)
            if(i>>j-1&1)
            sum1=(sum1*2333%mod+s[j]-'a')%mod;
            else sum2=(sum2*2333%mod+s[j]-'a')%mod;
        //cout<<a<<' '<<b<<' '<<sum1*inf+sum2<<endl;
        ans+=vis[b][a][sum2*inf+sum1];
    }
    printf("%lld\n",ans);
}


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


signed main() {
  
  int H, W;
  cin >> H >> W;
  
  vector<string> A(H);
  for( int i = 0; i < H; i++ ){
    cin >> A.at(i);
  }
  
  vector<bool> yoko(W, false);
  vector<bool> tate(H, false);
  for( int i = 0; i < H; i++ ){
    for( int j = 0; j < W; j++ ){
      if( A.at(i).at(j) == '#' ){
        yoko.at(j) = true;
        tate.at(i) = true;
      }
    }
  }
  
  for( int i = 0; i < H; i++ ){
    if( tate.at(i) == true ){
      for( int j = 0; j < W; j++ ){
        if( yoko.at(j) == true ){
          cout << A.at(i).at(j);
        }
      }
      cout << endl;
    }
  }
  
}



Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		sc.useDelimiter(System.getProperty("line.separator"));
        int n = sc.nextInt();
        String data = sc.next();

        //String???Int????????????
        String[] datas = data.split(" ");
        int[] A = new int[n];
        for (int i = 0; i < A.length; i++) {
			A[i] = Integer.parseInt(datas[i]);
		}

    	bubble(A);
	}

	/**
	 * ??????????????????
	 * @param a
	 */
	private static void bubble(int[] A) {
		int cnt = 0;
		//??°???????????¢????????????????´?
		boolean flag = true;
		for(int i=0; flag==true; i++){
			flag = false;
			for(int j= A.length-1; j>=i+1; j--){
				if(A[j-1] > A[j]){
					int tmp = A[j-1];
					A[j-1] = A[j];
					A[j] = tmp;
					cnt++;
					flag = true;
				}
			}
		}
		disp(A);
		System.out.println(cnt);

	}

	private static void disp(int[] a) {
		for (int i = 0; i < a.length; i++) {
			System.out.print(a[i]);
			if(i!=a.length-1)System.out.print(" ");
		}
		System.out.println();
	}

}

Measured memory_bytes: 26128
#include<bits/stdc++.h>
using namespace std;
int a[810];
int main(){
    int N;
    cin>>N;
    int sum=0;
    for(int i=0;i<N;i++){
		cin>>a[i];
	}
	sort(a,a+N);
	for(int l=0;l<N;l++){
		if(a[l]==a[l+1]){
			sum++;
		}
	}
	cout<<N-sum<<endl;
}


Measured memory_bytes: 256
#include<cstdio>
#include<cstring>

int main(){
    char str[1001];
    
    while(1){
        scanf("%s",str);
        if (str[0] == '0') break;
        int sum=0;
        for (int i=0;i<strlen(str);i++){
            sum += (str[i]-'0');
        }
        
        printf("%d\n",sum);
    }
    
    return 0;
}


Measured memory_bytes: 2704
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
ll dp[100005][104],a[100005],b[100005];
ll knapsack(ll W,ll N)
{
    if(N<0) return 0;
    if(W<=0) return 0;
    if(dp[W][N]!=-1) return dp[W][N];
    if(W-a[N]>=0)
    return dp[W][N]=max(knapsack(W-a[N],N-1)+b[N],knapsack(W,N-1));
    else return dp[W][N]=knapsack(W,N-1);
}
int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    ll N,W,i,j;
    cin>>N>>W; memset(dp,-1,sizeof dp);
    for(i=0;i<N;i++) cin>>a[i]>>b[i];
    cout<<knapsack(W,N-1)<<endl;
	return 0;
}

Measured memory_bytes: 81536
n = int(input())
l = list(map(int,input().split()))
dp = [0]*n
dp[1] = abs(l[1]-l[0])
for i in range(2,n):
  dp[i] = min(dp[i-2]+abs(l[i]-l[i-2]),dp[i-1]+abs(l[i]-l[i-1]))
print(dp[n-1])

Measured memory_bytes: 13928
#include <bits/stdc++.h>
using namespace std;
#define all(x) x.begin(),x.end()
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
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;}
typedef long long ll;

int n,k,m,t;
string s;

int main() {
  cin >> n >> t;
  int a[n];
  rep(i,n) cin >> a[i];
  ll x=0;
  rep(i,n-1) x+=min(a[i+1]-a[i],t);
  cout << x+t << endl;
 }

Measured memory_bytes: 1024
N,M = map(int,input().split())
A = map(int,input().split())
 
B = {0: 1}
tmp = 0
ans = 0
 
for a in A:
        tmp = (tmp+a)%M
        ans += B.get(tmp,0)
        B[tmp] = B.get(tmp,0)+1
 
print(ans)

Measured memory_bytes: 16100
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <cmath>
#include <climits>
#include <iomanip>
#include <set>
#include <map>
using namespace std;
typedef long long ll;
int main(){
  ll n,d;
  cin >> n >> d;
  ll res = 0;
  for(int i = 0;i < n;i++){
    ll x,y,now;
    cin >> x >> y;
    now = x*x + y*y;
    if(now <= d*d)res++;
  }
  cout << res << endl;
}

Measured memory_bytes: 3628
#include <stdio.h>

int main(){
 long long i,x,p;
 int k=0;
 p=100;
 scanf("%lld",&x);
while(1) {
    p=p+(p/100);
    k++;
if(p>=x)break;
}
printf("%d\n",k);
    return 0;
}


Measured memory_bytes: 2132
n = 2000
mod = 10 ** 9 + 7

fact = [1]
fact_inv = [0] * (n+1)
for i in range(n):
    fact.append(fact[-1] * (i+1) % mod)
fact_inv[-1] = pow(fact[-1], mod-2, mod)
for i in range(n-1, -1, -1):
    fact_inv[i] = fact_inv[i+1] * (i+1) % mod

def mod_comb_k(n, k):
    return fact[n] * fact_inv[k] * fact_inv[n-k] % mod


N, K = map(int, input().split())

for i in range(1, K+1):
    if N - K + 1 < i:
        print(0)
    else:
        print(mod_comb_k(N-K+1, i) * mod_comb_k(K-1, i-1) % mod)

Measured memory_bytes: 42736
#include <bits/stdc++.h>
 
#define rep(i, n) for(int i = 0; i < n; i++)
 
using namespace std;
using ll = long long;
 
void solve();
 
int main(void){
    int N, Q;
    cin >> N >> Q;
    vector<int> edge[N];
    int val[N] = {0};
    int decide[N] = {0};
    rep(i, N-1){
        int a, b;
        cin >> a >> b;
        edge[a-1].push_back(b-1);
        edge[b-1].push_back(a-1);
    }
    rep(i, Q){
        int n, v;
        cin >> n >> v;
        val[n-1] += v;
    }
    queue<int> q;
    q.push(0);
    while(!q.empty()){
        int op = q.front();
        q.pop();
        while(!edge[op].empty()){
            auto a = edge[op].end();
            a--;
            edge[op].pop_back();
            if(decide[*a] == 0){
                val[*a] += val[op];
                q.push(*a);
            }
        }
        decide[op] = 1;
    }
    rep(i, N){
        if(i == N-1) printf("%d\n", val[i]);
        else printf("%d ", val[i]);
    }
    return 0;
}
 
void solve(){}

Measured memory_bytes: 16244
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <bitset>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <numeric>
#include <iostream>
#include <iomanip>
#include <string>
#include <chrono>
#include <random>
#include <cmath>
#include <cassert>
#include <climits>
#include <cstring>
#include <cstdlib>
#include <functional>
#include <sstream>

using namespace std;

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

    int r;
    cin >> r;

    cout << 3 * r * r << "\n";

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repr(i, n) for (int i = (n); i >= 0; --i)
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define FORR(i, m, n) for (int i = (m); i >= (n); --i)
#define ifaxb(a, x, b) if (a < x && x < b)  // 比較は昇順
#define vi vector<int>
#define vii vector<vi>
#define vs vector<string>
#define vss vector<vs>
#define all(x) x.begin(), x.end()
#define ff first
#define ss second
#define pq priority_queue
#define ipair pair<int, int>
#define spair pair<string, string>
#define lpair pair<LL, LL>
#define MP make_pair
#define MM multimap
#define PB push_back
#define INF 2147483647
#define _INF -2147483647
#define pi 3.1415926536
#define MAXN 100004
using namespace std;
typedef long long ll;

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

    vi divisible;
    FOR(i, 1, 101) {
        if (a % i == 0 && b % i == 0) {
            divisible.push_back(i);
        }
    }

    cout << divisible[divisible.size() - k] << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstring> 
#include <cmath>
#include <cstdio>
using namespace std;
int main(){
	long long a,b,c,d,t,n;
	scanf("%lld%lld%lld%lld",&a,&b,&c,&d);
	t=max(a*c,a*d);
	n=max(b*c,b*d); 
		cout<<max(t,n)<<endl;	
	return 0;
}


Measured memory_bytes: 3764
#include <iostream>
#include <vector>
#include <sstream>

typedef unsigned long long ll;
using namespace std;

int main(){
    vector<int> rslt;
    vector<int> change_check;
    int n, m;
    cin >> n >> m;
    rslt.assign(n, 0);
    if ( n != 1)    rslt[0] = 1;
    change_check.assign(n, 0);
    int s, c;
    int error = 0;
    for (int i = 0; i < m; ++i)
    {
        cin >> s >> c;
        if (s == 1 && c == 0 && n != 1){
            error = 1;
            break;
        }
        if (change_check[s - 1] == 0)
        {
            rslt[s - 1] = c;
            change_check[s - 1] = 1;
        }
        else
        {
            if(rslt[s-1] == c)
                continue;
            error = 1;
            break;
        }
    }
    if(error == 1) {
        cout << "-1" << endl;
    }else{
        string s,s_c;
        s = "";
        for (int i = 0; i < n; ++i)
        {
            s_c =  to_string(rslt[i]);
            s = s + s_c;
        }
        cout << s << endl;
    }
}

Measured memory_bytes: 256
n = gets.to_i
h = Hash.new(0)
gets.split.each{|e| h[e.to_i % 4] += 1}

if h[0] * 2 + 1 >= n
    puts "Yes"
else
    puts h[0] * 2 + h[2] >= n ? "Yes" : "No"
end

Measured memory_bytes: 7684
import math
e=map(float,raw_input().split())
a=e[0]
b=e[1]
C=math.radians(e[2])
c=(a**2+b**2-2*a*b*math.cos(C))**0.5
h=b*math.sin(C)
S=h*a*0.5
L=a+b+c
print S
print L
print h

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

using namespace std;

int main(){
	int n;
	cin >> n;
	int counta = 0;
	bool aunOK = true;
	for(int i = 0;i < n;i++){
		string aun;
		cin >> aun;
		if(aun == "A") counta++;
		else{
			counta--;
			if(counta < 0){
				aunOK = false;
			}
		}
	}
	if(counta > 0) aunOK = false;
	string sol;
	if(aunOK) sol = "YES";
	else sol = "NO";
	cout << sol << endl;
}

Measured memory_bytes: 3196
#define REP(i,n) for(int i=0; i<(int)(n); i++)

#include <cstdio>
inline int getInt(){ int s; scanf("%d", &s); return s; }

typedef long long ll;

#include <set>

using namespace std;

int main(){
  const int n = getInt();

  ll ans = 0;
  int mn = 2;

  REP(i,n){
    const int a = getInt();
    if(i == 0){
      ans += a - 1;
    }else{
      ans += (a - 1) / mn;
      if(a <= mn) mn = max(mn, a + 1);
    }
  }

  printf("%lld\n", ans);

  return 0;
}


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

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

  double ans, prob;
  ans = 0;
  for (int i = 1; i <= N; i++){
      int score = i;
      prob = 1.0/N;
      while (score < K){
          score *= 2;
          prob /= 2;
      }
      ans += prob;
  }
  cout << std::setprecision(10) << ans << endl;
}


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

int main() {
  string s;
  cin >> s;
  if (s == "SSS") cout << 0 << endl;
  if (s == "SSR") cout << 1 << endl;
  if (s == "SRS") cout << 1 << endl;
  if (s == "SRR") cout << 2 << endl;
  if (s == "RSS") cout << 1 << endl;
  if (s == "RSR") cout << 1 << endl;
  if (s == "RRS") cout << 2 << endl;
  if (s == "RRR") cout << 3 << endl;
  
  return 0;
}

Measured memory_bytes: 3564
N = int(input())

def gk(n):
    ans = 0
    while n:
        ans += 1
        n //= 10
    return ans


ans = float("inf")
for i in range(1, int(N**(1/2))+1):
    if N % i == 0:
        ans = min(ans,gk( N//i)) 
print(ans)
exit(0)


lst = []
for i in range(2,int(N**(1/2))+1):
    if N % i == 0:
        ans = 0
        while N % i == 0:
            ans += 1
            N //= i
        lst.append( (i,ans) )

cand = [1]
while lst:
    p,cnt = lst.pop()
    nl = []
    # for p == 


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

using namespace std;

#define FOR(i, a, b) for(ll i = (a); i < (b); ++i)
#define FORR(i, a, b) for(ll i = (a); i > (b); --i)
#define REP(i, n) for(ll i = 0; i < (n); ++i)
#define REPR(i, n) for(ll i = n; i >= 0; i--)
#define FOREACH(x, a) for(auto &(x) : (a))
#define VECCIN(x)                                                              \
    for(auto &youso_ : (x)) cin >> youso_
#define mp make_pair
#define bitcnt __builtin_popcount
#define SZ(x) ((ll)(x).size())
#define All(a) (a).begin(), (a).end()
template <typename T = long long> inline T IN() {
    T x;
    cin >> x;
    return (x);
}
inline void CIN() {}
template <class Head, class... Tail>
inline void CIN(Head &&head, Tail &&... tail) {
    cin >> head;
    CIN(move(tail)...);
}
#define CINT(...)                                                              \
    int __VA_ARGS__;                                                           \
    CIN(__VA_ARGS__)
#define LCIN(...)                                                              \
    ll __VA_ARGS__;                                                            \
    CIN(__VA_ARGS__)
#define SCIN(...)                                                              \
    string __VA_ARGS__;                                                        \
    CIN(__VA_ARGS__)
#define Yes(a) cout << (a ? "Yes" : "No") << "\n"
#define YES(a) cout << (a ? "YES" : "NO") << "\n"
#define Printv(v)                                                              \
    FOREACH(x, v) { cout << x << " "; }                                        \
    cout << "\n";

typedef long long ll;
typedef unsigned long long ul;
typedef vector<int> V;
typedef vector<ll> VL;
typedef pair<ll, ll> PL;
typedef priority_queue<ll> PQ;
typedef priority_queue<ll, V, greater<ll>> PQG;

const int INF = 1e9;
const int MOD = 1e9 + 7;
// const int MOD = 998244353;
const ll LINF = 1e18;
const ll dx[] = {1, -1, 0, 0};
const ll dy[] = {0, 0, 1, -1};

string n;

int main() {
    cin >> n;
    REP(i, n.size()) {
        if(n[i] == '1')
            cout << 9;
        else
            cout << 1;
    }
    cout << "\n";
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define optimize() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define nl '\n'
int main()
{
    optimize();
    int n,l;
    cin>>n>>l;

    vector<string>v(n);
    for(int i=0;i<n;i++)
    {
        string s;
        cin>>s;
        v.push_back(s);
    }
    sort(v.begin(),v.end());
    for(auto u:v){
        cout<<u;
    }
  return 0;
}



Measured memory_bytes: 3624
import java.util.HashSet;
import java.util.Set;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Arrays;

public class Main {
    public static void main(String[] args) throws Exception {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String[] xyz = br.readLine().split(" ");
        int x = Integer.parseInt(xyz[0]);
        int y = Integer.parseInt(xyz[1]);
        int z = Integer.parseInt(xyz[2]);
        
        int a = x*10+y+z;
        int b = x+y*10+z;
        int c = x+y+z*10;
        
        if (a>=b && a>=c) {
            System.out.println(a);
        }
        else if (b>=a && b >= c) {
            System.out.println(b);
        }
        else {
            System.out.println(c);
        }
        
        //System.out.println(Math.max(a, b, c));
        
        
    }
}


Measured memory_bytes: 22356
N,M,C = map(int,input().split())
B = list(map(int,input().split()))
A = []
for i in range(N):
    A.append(list(map(int,input().split())))

ans = 0
for i in range(N):
    tmp = 0
    for j in range(M):
        tmp += A[i][j]*B[j]
    tmp += C
    if tmp > 0:
        ans += 1
print(ans)


Measured memory_bytes: 3060
import java.util.LinkedList;
import java.util.Queue;
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		Scanner input = new Scanner(System.in);
		String[] nAndQuantum = new String[2];
		nAndQuantum = input.nextLine().split(" ");
		int n = Integer.parseInt(nAndQuantum[0]);
		int quantum = Integer.parseInt(nAndQuantum[1]);
		Queue<Integer> times = new LinkedList<Integer>();
		Queue<String> names = new LinkedList<String>();
		String[] nameAndTime = new String[2];
		for(int i = 0; i < n; i++) {
			nameAndTime = input.nextLine().split(" ");
			names.add(nameAndTime[0]);
			times.add(Integer.parseInt(nameAndTime[1]));
			
		}
		int totalTime = 0;
		while(!times.isEmpty() && !names.isEmpty()) {
			String name;
			int time;
			if(times.peek() > quantum) {
				time = times.poll();
				totalTime = totalTime + quantum;
				name = names.poll();
				time = time - quantum;
				times.add(time);
				names.add(name);
				
			}
			else if(times.peek() <= quantum) {
				time = times.poll();
				totalTime = totalTime + time;
				name = names.poll();
				System.out.println(name + " " + totalTime);
				
			}
			
		}

	}

}


Measured memory_bytes: 105772
import itertools
A,B,Q = [int(_) for _ in input().split(" ")]
s_array = [int(input()) for _ in range(A)]
t_array = [int(input()) for _ in range(B)]                                                  
x = [int(input()) for _ in range(Q)]

def binary_search(arr,point,start,end):
    pivot = (start+end)//2
    if end -start > 1:
        if arr[pivot] <point :
            return binary_search(arr,point,pivot,end)
        else:
            return binary_search(arr,point,start,pivot)
    else:
        return start
    
def find_closest_path(s_1,s_2,t_1,t_2,point):
    shortest = 10**11
    for s,t in itertools.product([s_1,s_2],[t_1,t_2]):
        length = min(abs(point-t), abs(point -s )) + abs(s - t)
        if length < shortest:
            shortest = length 
    return shortest 


for i in range(Q):
    s_idx = binary_search(s_array,x[i],0,len(s_array)-1)
    t_idx = binary_search(t_array,x[i],0,len(t_array)-1)
    if len(s_array)>1:
        s_1,s_2 = s_array[s_idx],s_array[s_idx+1] 
    else:
        s_1,s_2 = s_array[0],s_array[0]
    if len(t_array)>1:
        t_1,t_2 = t_array[t_idx],t_array[t_idx+1]    
    else:
        t_1,t_2 = t_array[0],t_array[0]
    answer = find_closest_path(s_1,s_2,t_1,t_2,x[i])
    print(answer)








Measured memory_bytes: 16176
#pragma warning (disable:4996)
#include <stdio.h>
#include <stdlib.h>

int input(int *num){
	unsigned short int i;
	char str[1000];
	scanf("%s", str);
	for (i = 0; str[i] != '\0'; i++){
		num[i] = str[i] - '0';
	}
	if (str[0] == '0')exit(0);
	return i;
}
int calc(int n, int *num){
	int sum = 0;
	unsigned short int i;
	for (i = 0; i < n; i++){
		sum += num[i];
	}
	return sum;
}
void output(int sum){
	printf("%d\n", sum);
}
int main(void){
	unsigned short int n;
	int num[1000];
	while (1){
		n = input(num);
		output(calc(n, num));
	}
	return 0;
}

Measured memory_bytes: 540
#include <bits/stdc++.h>
#define INF (1<<30)
#define MOD 1000000007
#define l_ength size
using ll = long long;
using namespace std;

int main(){
	int n, k; cin >> n >> k;
	vector<ll> a(n);
	for( auto &k : a ) cin >> k;
	vector<ll> sp(n+1);
	sp[0] = 0;
	for( int i = 0; i < n; ++i ){
		sp[i+1] = sp[i];
		if( a[i] > 0 ) sp[i+1] += a[i];
	}
	vector<ll> sm(n+1);
	sm[0] = 0;
	for( int i = 0; i < n; ++i ){
		sm[i+1] = sm[i];
		if( a[i] < 0 ) sm[i+1] += a[i];
		/*
		まちがい: if( a[i] < 0 ) sm[i+1] = sm[i] + a[i];
		これは a[i] >= 0 のときに sm が更新されなくなって RE を吐く
		*/
	}
	ll opt = sp[n];
	ll ans = 0;
	for( int i = 0; i+k <= n; ++i ){
		ans = max( { ans, opt-(sp[i+k]-sp[i]), opt+(sm[i+k]-sm[i]) } );
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 2560
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <functional>
#include <stack>
#include <queue>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <list>
#include <set>
using namespace std;
typedef long long ll;


int main(int argc, char *args[]) {
	ll n,k;
	int a[100000];
	cin >> n >> k;
	if ((n - 1) % (k - 1) == 0) cout << (n - 1) / (k - 1) << endl;
	else cout << (n - 1) / (k - 1) + 1 << endl;
}


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

using namespace std;

int main()
{
  int N, K; cin >> N >> K;
  vector<int> x(N);
  for (int i = 0; i < N; ++i) {
    cin >> x[i];
  }

  int ans = 0;
  for (int i = 0; i < N; ++i) {
    ans += min(2*x[i], 2*abs(x[i] - K));
  }

  cout << ans;
}

Measured memory_bytes: 256
#include <stdio.h>

int main() {
    int a,b;
    scanf("%d%d",&a,&b);
    char *result;
    if(a>b) {
        result= ">";
    }
    else if(b>a) {
        result = "<";
    }
    else{
        result = "==";
    }
    printf("a %s b\n",result);
    return 0;
}



Measured memory_bytes: 2044
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
using P = pair<int, int>;
using vec = vector<int>;
using mat = vector<vector<int>>;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define endl "\n"

constexpr int MOD = 1000000007;
const int INF = 1 << 30;

int main() {
    int n;
    cin >> n;
    vec a(n);
    rep(i, n) cin >> a[i];

    map<int, int> m;
    rep(i, n) m[a[i]]++;

    int res = 0;
    int c = 0;

    for (auto&& p : m) {
        if (p.second % 2 == 0) c++;
        res++;
    }

    if (c % 2) res--;

    cout << res << endl;
    return 0;
}

Measured memory_bytes: 5376
#include <cstdio>
#include <cstring>
#include <cmath>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <stack>
using namespace std;

#define ll long long
#define mst(a) memset(a, 0, sizeof a)

const int mod = 1e9+7;
const int maxn = 1e5+50;
const int inf = 1e9;

int a[maxn];

int main()
{
    int n;
    scanf("%d", &n);
    for (int i = 0; i < n; ++i)
        scanf("%d", &a[i]);
    sort(a, a + n);
    int min_d = inf;
    int ans = a[0];
    for (int i = 0; i < n-1; ++i)
    {
        int tmp = min(abs(a[n-1]/2 - a[i]), abs((a[n-1]+1)/2 - a[i]));
        if (tmp < min_d)
        {
            min_d = tmp;
            ans = a[i];
        }
    }
    printf("%d %d\n", a[n-1], ans);
    return 0;
}

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

template<typename T>
T get_value(std::istream& is);

int getMinNum(int _nOriginal, const std::set<char>& _avoid)
{
	std::string org = std::to_string(_nOriginal);
	for (auto& c : org)
	{
		if (_avoid.find(c) != _avoid.end())
		{
			return getMinNum(_nOriginal + 1, _avoid);
		}
	}

	return _nOriginal;
}

int main()
{
	std::cin.sync_with_stdio(false);
	std::cin.tie(nullptr);

	int N, K;

	std::cin >> N >> K;
	std::vector<char> v(K);
	std::set<char> s;

	for (auto& e : v) {
		std::cin >> e;
		s.insert(e);
	}

	int answer = getMinNum(N, s);
	std::cout << answer << std::endl;

	return 0;
};


template<typename T>
inline T get_value(std::istream& is)
{
	T v;
	is >> v;
	return v;
}


Measured memory_bytes: 10240
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define repd(i, a, b) for (ll i = (ll)(a); i < (ll)(b); i++)

int main()
{
  int N, T;
  cin >> N >> T;
  int c[N], t[N];
  int cost = 1001;
  rep(i, N)
  {
    cin >> c[i] >> t[i];

    if (t[i] <= T)
    {
      if (c[i] < cost)
        cost = c[i];
    }
  }

  if (cost == 1001)
  {
    cout << "TLE";
    return 0;
  }

  cout << cost;
}

Measured memory_bytes: 256