akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define REVERSE(v,n) reverse(v,v+n);
#define VREVERSE(v) reverse(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
#define INF 9999999

using namespace std;

typedef pair<int, int> P;

int dy[4] = { 0,0,1,-1 };
int dx[4] = { 1,-1,0,0 };
int main() {
	int n;
	cin >> n;
	set<int>mochi;
	REP(i, n) {
		int a;
		cin >> a;
		mochi.insert(a);
	}
	cout << mochi.size() << endl;
}



Measured memory_bytes: 384
#include <iostream>

using namespace std;

typedef long long lint;
int main(void)
{
  lint N;
  cin >> N;
  lint tn = N;
  lint sn = 0;
  while(tn != 0){
    lint tmp = 0;
    sn += tn % 10;
    tn = tn / 10;
  }

  
  if(N % sn == 0){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
#define fastio() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define loop(i,a,b) for(int i=a;i<b;i++)
#define test() int t;cin>>t;loop(test,1,t+1)
#define pb push_back
#define eb emplace_back
#define mkp make_pair
#define nl cout<<"\n"
#define sp cout<<" "
#define F first
#define S second
#define vi vector<int>
#define vl vector<ll>
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vii vector<pii>
#define vll vector<pll>
#define MOD 1000000007
#define all(x) x.begin(),x.end()

template<class C> void min_self( C &a, C b ){ a = min(a,b); }
template<class C> void max_self( C &a, C b ){ a = max(a,b); }

void mod( ll &n, ll m=MOD ){ n%=m,n+=m,n%=m; }

const int MAXN = 1e5+5;
int dx[] = {1,0,-1,0};
int dy[] = {0,1,0,-1};

int main() 
{
    fastio();

    int n,cap;
    cin>>n>>cap;
    ll weight[n],val[n];
    for(int i=0;i<n;i++) cin>>weight[i]>>val[i];

    ll dp[n+1][cap]={};
    // dp[i][j] = max value with index till i and total weight j
    for(int i=0;i<n;i++)
    {
        for(int j=0;j<=cap;j++)
        {
            dp[i+1][j] = dp[i][j];
            if( j-weight[i] >= 0 )
                max_self(dp[i+1][j], val[i] + dp[i][j-weight[i]]);
        }
    }
    ll ans = 0;
    for(int i=0;i<=cap;i++)
    {
        max_self(ans,dp[n][i]);
    }
    cout<<ans,nl;

    return 0;
}

Measured memory_bytes: 79104
r, b, g, n = [int(x) for x in input().rstrip().split(" ")]

total = 0

for current_1 in range(0, n + 1, r):
  for current_2 in range(current_1, n + 1, b):
    if (n - current_2) % g == 0:
      total += 1

print(total)

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

using namespace std;

#define MAXN 200005

int N, M;
int cnt;
vector<int> adj[MAXN];
vector<bool> visited;

void dfs(int v)
{
    if (visited[v])
        return;
    
    visited[v] = true;
    cnt++;
    for (auto u : adj[v])
        dfs(u);
}

int main()
{
    cin >> N >> M;
    visited.assign(N + 1, false);
    for (int i = 0; i < M; i++) {
        int a, b;
        cin >> a >> b;
        adj[a].push_back(b);
        adj[b].push_back(a);
    }
    int ans = 0;
    for (int i = 1; i <= N; i++) {
        cnt = 0;
        dfs(i);
        ans = max(ans, cnt);
    }
    cout << ans << '\n';
    return 0;
}

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

double prob(int i){
	return (i+1)/2.0;
}
signed main() { 
	cin.tie(0);
	cin.sync_with_stdio();
	int n, k; 
	cin>>n>>k;
	vector<int> v(n);
	for(int &i : v)
		cin>>i;
	double sol = 0;
	double tot = 0;
	for(int i = 0; i < k; i++){
		tot += prob(v[i]);
	}
	sol = tot;
	for(int i = k; i < n; i++){
		tot -= prob(v[i-k]);
		tot += prob(v[i]);
		sol = max(sol, tot);
	}
	cout<<setprecision(20)<<sol;
}


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

int main() {
  int N;
  cin >> N;
  
  int number = 1;
  for (int i = 1; i <= 7; i++){
    number *= 2;
    if (N < number) break;
  }
  cout << number/2 << endl;
}

Measured memory_bytes: 256
// I SELL YOU...! 
#include<iostream>
#include<vector>
#include<algorithm>
#include<functional>
#include<queue>
#include<chrono>
#include<iomanip>
#include<map>
#include<set>
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
void init_io(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << setprecision(10);
}
signed main(){
  init_io();
  ll n,a,b,c,ans=100000000000;
  cin >> n >> a >> b >> c;
  vector<ll> l(8,0);
  for(int i=0;i<n;i++){
    cin >> l[i];
  }
  for(int ia=0;ia<4;ia++){
    for(int ib=0;ib<4;ib++){
      for(int ic=0;ic<4;ic++){
        for(int id=0;id<4;id++){
          for(int ie=0;ie<4;ie++){
            for(int iF=0;iF<4;iF++){
              for(int ig=0;ig<4;ig++){
                for(int ih=0;ih<4;ih++){
                  ll val[4];
                  fill(val,val+4,0);
                  val[ia] += l[0];
                  val[ib] += l[1];
                  val[ic] += l[2];
                  val[id] += l[3];
                  val[ie] += l[4];
                  val[iF] += l[5];
                  val[ig] += l[6];
                  val[ih] += l[7];
                  if(val[0]!=0&&val[1]!=0&&val[2]!=0){
                    ll t0=0,t1=0,t2=0;
                    if(ia==0) t0++;
                    else if(ia==1) t1++;
                    else if(ia==2)t2++;
                    if(ib==0) t0++;
                    else if(ib==1) t1++;
                    else if(ib==2)t2++;
                    if(ic==0) t0++;
                    else if(ic==1) t1++;
                    else if(ic==2)t2++;
                    if(id==0) t0++;
                    else if(id==1) t1++;
                    else if(id==2)t2++;
                    if(ie==0) t0++;
                    else if(ie==1) t1++;
                    else if(ie==2)t2++;
                    if(iF==0) t0++;
                    else if(iF==1) t1++;
                    else if(iF==2)t2++;
                    if(ig==0) t0++;
                    else if(ig==1) t1++;
                    else if(ig==2)t2++;
                    if(ih==0) t0++;
                    else if(ih==1) t1++;
                    else if(ih==2) t2++;
                    ans = min(ans,
                        (t0-1)*10+(t1-1)*10+(t2-1)*10
                        +abs(a-val[0])+abs(b-val[1])+abs(c-val[2]));
                  }
                }
              }
            }
          }
        }
      }
    }
  }
  cout << ans << endl;
}


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

#define rep(i, n) for (int i = 0; i < n; ++i)
#define all(x) (x).begin(),(x).end()
#define endl "\n"

using ll = long long;
using P = pair<int,int>;
using mp =  map<int,int>;

const int MOD = 1e9 + 7;

int main() {
	ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);

    int n;
    cin >> n;
    vector<P> pi(n);
    rep(i, n){
        int x, l;
        cin >> x >> l;
        pi[i].first = x + l;
        pi[i].second = x - l;
    }

    sort(all(pi));
     
    int ans = 0;
    int tmp = -MOD;
    rep(i, n){
        if(tmp <= pi[i].second){
            ans++;
            tmp = pi[i].first;
        }
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 1024
program ABC_086_A_PlacingMarbles
implicit none
   integer n
   read(*, *) n
   if(n == 000) then
      write(*, *) 0
   else if(n == 001) then
      write(*, *) 1
   else if(n == 010) then
      write(*, *) 1
   else if(n == 100) then
      write(*, *) 1
   else if(n == 011) then
      write(*, *) 2
   else if(n == 101) then
      write(*, *) 2
   else if(n == 110) then
      write(*, *) 2
   else if(n == 111) then
      write(*, *) 3
   end if
end program ABC_086_A_PlacingMarbles

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

using namespace std;

int main(){

	int N;
	cin >> N;

	int A , B;
	vector<int> now(2*N);

	for(int i = 0; i < 2*N; i++){
		cin >> now.at(i);

		if(i%2==1){
			B += now.at(i);
		}
		else{
			A += now.at(i);
		}
	}

	cout << B - A + N <<endl;

}

Measured memory_bytes: 3644
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main() {
  int A,B;
  cin >>A>>B;
  if(B%A==0)cout<<A+B<<endl;
  else cout<<B-A<<endl;
  return 0;
    
  
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <cstring>
#include <algorithm> 
#include <math.h>
#include <queue>
#include <functional>
#include <map>
#include <vector>
#include <string>
using namespace std;

typedef long long ll;
typedef pair<int, int> P;
typedef pair<int, pair<int, int>> PP;


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

const ll MOD = 1000000007;
const ll INF = 100000000000;




int main(void){
    string s; cin >> s;
    int cnt1=0,cnt2=0;
    for(int i=0;i<s.length();i++){
        if(s[i]=='0') cnt1++;
        else cnt2++;
    }
    
    cout << 2*min(cnt1,cnt2) << endl;
   
}



Measured memory_bytes: 512
import std.algorithm, std.container, std.conv, std.math, std.range, std.typecons, std.stdio, std.string;

auto rdsp(){return readln.splitter;}
void pick(R,T)(ref R r,ref T t){t=r.front.to!T;r.popFront;}
void readV(T...)(ref T t){auto r=rdsp;foreach(ref v;t)pick(r,v);}

void main()
{
  long a, b, x; readV(a, b, x);
  writeln(b/x+1 - (a == 0 ? 0 : (a-1)/x+1));
}


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


namespace AtCodeeeer
{
    class AtCOOOOOOOOOOOder
    {
        static void Main(string[] args)
        {
            int[] nk = ReadLine().Split(' ').Select(int.Parse).ToArray();
            int N = nk[0];
            int K = nk[1];
            string s = ReadLine();

            var ans = "";
            for (int i = 0; i < N; i++)
            {
                if (i == K-1)
                {
                    ans += s[i].ToString().ToLower();
                }
                else
                {

                    ans += s[i];
                }
            }

            WriteLine(ans);
        }
    }
}


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

int main()
{
  long long K, cnt=1, cnt2=0, cnt3=1, cnt4=1, A=1;
  string S;
  cin >> S >> K;
  rep(i, S.size()-1){
    if(S.at(i)!=S.at(i+1)) A=0;
  }
  if(A==1) cnt2=K*S.size()/2;
  else if(S.at(0)!=S.at(S.size()-1)){
    rep(i,S.size()-1){
      if(S.at(i)==S.at(i+1)) cnt++;
      else{
        cnt2=cnt2+cnt/2;
        cnt=1;
      }
    }
    cnt2=cnt2+cnt/2;
    cnt2=cnt2*K;
  }
  else if(S.at(0)==S.at(S.size()-1)){
    rep(i, S.size()-1){
      if(S.at(i)==S.at(i+1)) cnt3++;
      else break;
    }
    for(int i=S.size()-1; i>0; i--){
      if(S.at(i)==S.at(i-1)) cnt4++;
      else break;
    }
    for(int i=cnt3; i<S.size()-cnt4; i++){
      if(S.at(i)==S.at(i+1)) cnt++;
      else{
        cnt2=cnt2+cnt/2;
        cnt=1;
      }
    }
    cnt2=cnt2+cnt/2;
    cnt2=cnt2*K+(cnt3+cnt4)/2*(K-1)+cnt3/2+cnt4/2;      
  }
  cout << cnt2 << endl;
}

Measured memory_bytes: 256
from math import ceil #切り上げ
import numpy as np
import sys
 
def inp(): return int(input()) #一個だけ読み取り
def inpm(): return map(int,input().split()) #mapオブジェクトで呼び出し
def inpl(): return list(map(int, input().split())) #数字リストをintで
def inpls(): return list(input().split()) #リストをstrで
 
def check(a,b,X):
  if a**5-b**5 == X:
    return 1
  else:
    return 0
  
X = inp()
for A in range(-118,120):
  for B in range(-119,119):
    if check(A,B,X):
      print(str(A) + " " + str(B))
      sys.exit()

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

Measured memory_bytes: 1476
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <string>
#include <vector>

using namespace std;
using LLONG = long long;
const LLONG MOD = 1000000007;

int main()
{
    int N; cin >> N;
    if (N / 100 == 7)
    {
        cout << "Yes\n";
        return 0;
    }
    N %= 100;
    if (N / 10 == 7)
    {
        cout << "Yes\n";
        return 0;
    }
    N %= 10;
    cout << (N == 7 ? "Yes\n" : "No\n");
}


Measured memory_bytes: 3624
n,m = gets.split.map(&:to_i)
edge = []
count = 0
m.times do
	a,b = gets.split.map(&:to_i)
	edge.push([a,b])
end
m.times do |cut|
	queue = [1]
	checked = []
	while t = queue.shift
		m.times do |i|
			l = i == cut ? nil : (edge[i][0] == t ? edge[i][1] : (edge[i][1] == t ? edge[i][0] : nil))
			if l && !checked.include?(l)
				checked.push(l)
				queue.push(l)
			end
		end
	end
	count += 1 if checked.length != n
end
puts count

Measured memory_bytes: 1788
# -*- coding: utf-8 -*-

s = set(input())
ans = 0
for i in s:
    if 'N' in i:
        ans += 1
    elif 'W' in i:
        ans += -2
    elif 'S' in i:
        ans += -1
    else:
        ans += 2
print('Yes' if ans == 0 else 'No')
    

Measured memory_bytes: 3060
n,m=map(int,input().split())

L=[[] for i in range(n+1)]
for i in range(m):
    a,b=map(int,input().split())
    L[a].append(b)
    L[b].append(a)
    
now=[]
nex=[1]
went={1}
res={i:-1 for i in range(n+1)}
res[1]=1

while len(nex)>0:
    now=nex[:]
    nex=[]
    for x in now:
        for go in L[x]:
            if res[go]==-1:
                res[go]=x
                nex.append(go)
                
                
#print
print("Yes")
for i in range(2,n+1):
    print(res[i])

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

using namespace std;

typedef long long int ll;

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

  int k;
  cin >> k;
  string s;
  cin >> s;
  if(s.length() <= k) cout << s << '\n';
  else{
    for(int i = 0; i < k; i++) cout << s[i];
    cout << "...\n";
  }
}


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

class Main{

  public static void main(String[] args){

    BufferedReader bfr=new BufferedReader(new InputStreamReader(System.in));
    String str="";
    StringTokenizer stk;
    int DIST,M_JUMP;

    try{
      str=bfr.readLine();
      if(str=="") {
        System.exit(0);
      }
      stk=new StringTokenizer(str," ");
      DIST=Integer.parseInt(stk.nextToken());
      M_JUMP=Integer.parseInt(stk.nextToken());
      int d_jk=DIST/M_JUMP;
      int kaisu=d_jk+((DIST-(M_JUMP*d_jk))/1);
      System.out.println(kaisu);


    } catch (IOException e) {
      System.exit(0);
    }
    catch(NumberFormatException e) {
      System.exit(0);
    }

    catch(NullPointerException e) {
      System.exit(0);
    }
  }
}


Measured memory_bytes: 24360
#include <vector>
#include <math.h>
#include <iostream>
#include <string>
#include <algorithm>
#include <queue>
#include <iomanip>
#include <deque>
#include <cctype>
#include <unordered_map>

using namespace std;
using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int,int>;
using pll = pair<long, long>;
template <class T> using V = vector<T>;
template <class T> using VV = V<V<T>>;
#define rep(i, n) for(int i = 0; i<n; i++)
#define rep_s(i, start, n) for(int i= start;  i<n; i++)
#define rep_down(i, n) for(int i = n-1; i>=0; i--)
#define rep_down_s(i, n, start) for(int i = n-1; i>=start; i--)
#define ALL(a) (a).begin(), (a).end()
#define ALL_str(a) (a).cbegin(), (a).cend()

string alphabet_upper = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
string alphabet_lower  = "abcdefghijklmnopqrstuvwxyz";
string numbers = "0123456789";
/*
for (iterator = hash.begin(); iterator != hash.end(); iterator++)
{
// ここで、要素毎の操作を行います。
std::pair<std::string, CMyClass> element = *iterator;

}
*/
/*
using edge = struct {int to; ll cost;};
vector<edge> tree[limit];
ll depth[limit];

void dfs(int v, int p, ll d){
  depth[v] = d;
  //cout <<"v: " << v << endl;
  for (auto &e: tree[v]){
    //cout << "e.to: " << e.to << endl;
    if (e.to == p) continue;
    dfs(e.to, v, d+e.cost);
  }
}
*/
int keta_sum(int num){
  int dig, sum = 0;
  while(num){
    dig = num % 10;
    sum = sum + dig;
    num = num / 10;
  }
  return sum;
}

ll binary_search(ll left_key, ll border, ll low, ll high) {
     // 配列 a の左端と右端
    ll mid = (low+high)/2;
    while (high > low+1) {
       mid = (low+high)/2;
        if (left_key*mid>border) high = mid;
        else if (left_key*mid<border) low = mid;
        else {
          mid =mid-1;
          break;
        }
    }
    return mid;
}

bool IsPrime(ll a){
  ll b = sqrt(a);
  b++;
  while(b-->=2){
    if (a%b==0) return false;
  }
  return true;
}

ll gcd(ll a, ll b){
  ll tmp;
  if(a<b){
    tmp = a;
    a = b;
    b = tmp;
  }

  ll r = a % b;
  while(r!=0){
    a = b;
    b = r;
    r = a % b;
  }
  return b;
}

struct UnionFind {
    vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2

    UnionFind(int N) : par(N) { //最初は全てが根であるとして初期化
        for(int i = 0; i < N; i++) par[i] = i;
    }

    int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }

    void unite(int x, int y) { // xとyの木を併合
        int rx = root(x); //xの根をrx
        int ry = root(y); //yの根をry
        if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
        par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
    }

    bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
};

int main(void){
  ll N, M, A, B, C, D, E, F, K,L, W, H, P, Q, R, X, Y;
  ll ans;
  string S, T;
  cin >> N >> M;
  A = sqrt(M);
  ans = 0;
  rep_s(i, 1, A+1){
    if (M%i == 0){
      D = M/i;
      if (i>= N) ans = max(ans, D);
      if (D>= N) ans = max(ans, (ll)i);
    }
  }
  
  cout << ans << endl;

}


Measured memory_bytes: 256
def main(m, n):
    ck = [True] * (7368792)
    for i in range(m, 7368792):
        if ck[i]:
            n -= 1
            ck[i::i]=[False]*((7368791-i)//i+1)
            if n != 0:
                continue
            i += 1
            while not ck[i]:
                i += 1
            print(i)
            return


while 1:
    m, n = map(int, input().split())
    if n == m == 0:
        break
    main(m, n)




Measured memory_bytes: 121528
#include <bits/stdc++.h>
#define be(v) (v).begin(),(v).end()
#define pb(q) push_back(q)
typedef long long ll;
using namespace std;
const ll mod=1000000007;
#define doublecout(a) cout<<fixed<<setprecision(10)<<a<<endl;

int main() {
    cin.tie(0);
    cout.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 b=0;
    sort(a,a+n);
    for(int i=1;i<n;i++){
        if(a[i]==a[i-1])b++;
    }
    if(b%2)b++;
    cout << n-b<<endl;
    return 0;
}


Measured memory_bytes: 768
<?php
fscanf(STDIN,"%d %d %d %d",$a,$b,$h,$m);

$hangle = $h == 0 ? 360 : 360 / 12 * $h;
if ($m !== 0) {
    $mangle = $m == 0 ? 360 : 360 / 60 * $m;
    $hangle += 360 / 12 / 60 * $m;
}
if ($hangle == $mangle) {
    echo "0".PHP_EOL;
    exit;
} else if ($hangle > $mangle) {
    $angle = $hangle - $mangle;
} else {
    $angle = $mangle - $hangle;
}

if ($angle == 90) {
    echo sqrt(($a ** 2) + ($b ** 2)).PHP_EOL;
} else {
    echo sqrt(($a ** 2) + ($b ** 2) - (2 * $a * $b * cos(deg2rad($angle))));
}

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

// types
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pdd;
typedef vector<ll> vll;

// macros
#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define FI first
#define SE second
#define REP(i,n) for(int i=0;i<((int)n);i++)
#define REP1(i,n) for(int i=1;i<((int)n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define PB push_back
#define EB emplace_back
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL

// constants
const int inf = 1e9;
const ll linf = 1LL << 50;
const double eps = 1e-10;
const int MOD = 1e9 + 7;
const int dx[4] = {-1, 0, 1, 0};
const int dy[4] = {0, -1, 0, 1};

ll n, k;

ll gcdSearch(vll a, ll gcd){
  vll modPlus(n), modMinus(n);
  ll A, B;
  A = B = 0;
  REP(i, n){
    modPlus[i] = a[i] % gcd;
    //modMinus[i] = gcd - a[i] % gcd;
    B += gcd - modPlus[i];
  }
  sort(modPlus.begin(), modPlus.end());
  //sort(modMinus.begin(), modMinus.end());

  ll mpIndex, mmIndex, counter, kCounter;
  mpIndex = mmIndex = counter = kCounter = 0;
  ll need = LLINF;
  REP(i, n){
    A += modPlus[i];
    B -= gcd - modPlus[i];
    need = min(need, max(A, B));

    //if(modPlus[mpIndex] > modMinus[mmIndex]){
    //  modPlus[mpIndex] -= modMinus[mmIndex];
    //  kCounter += modMinus[mmIndex];
    //  mmIndex++;
    //  counter++;
    //}
    //else if(modPlus[mpIndex] < modMinus[mmIndex]){
    //  modMinus[mmIndex] -= modPlus[mpIndex];
    //  kCounter += modPlus[mpIndex];
    //  mpIndex++;
    //  counter++;
    //}
    //else{
    //  kCounter += modPlus[mpIndex];
    //  mmIndex++;
    //  mpIndex++;
    //  counter += 2;
    //}
    //if(kCounter > k)
    //  return false;
    //if(counter == n)
    //  return true;
  }
  return need;

}

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

  cin >> n >> k;
  vll a(n);
  ll sum = 0;
  REP(i, n){
    cin >> a[i];
    sum += a[i];
  }

  set<ll> gcd;
  for(ll i = 1; i*i <= sum; i++){
    if(sum % i == 0){
      gcd.insert(i);
      gcd.insert(sum/i);
    }
  }

  ll ans = 1;
  for(ll x : gcd){
    if(gcdSearch(a, x) <= k)
      ans = max(ans, x);
  }

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


Measured memory_bytes: 384
import sys,math,collections,itertools
input = sys.stdin.readline


N,M = list(map(int,input().split()))
road = [[] for _ in range(N+1)]
flag = [-1 for _ in range(N+1)]
flag[1]=0
for i in range(M):
    a,b = map(int,input().split())
    road[a].append(b)
    road[b].append(a)
q = collections.deque([1])
while q:
    now = q.popleft()
    for r in road[now]:
        if flag[r] == -1:
            flag[r] = now
            q.append(r)
            
print('Yes')
for i in range(2,N+1):
    print(flag[i])

Measured memory_bytes: 34080
#include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
// #include <numeric>
#include <complex>
#include <tuple>

#define FAST ios_base::sync_with_stdio(false); cin.tie(0)
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define repr(i, a, b) for(int i=int(a); i>=int(b); i--)
#define reps(i,n) for(int i=1;i<=int(n);++i)
#define RREP(i,x) for(int i=((int)(x)-1);i>=0;i--)
#define RREPS(i,x) for(int i=((int)(x));i>0;i--)
#define iceil(x,y) (x+y-1)/y
#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it)
#define all(x) (x).begin(),(x).end()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() )

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

using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
typedef pair<int, PII> PP;

ll n,x;
ll pat[52];
ll size[52];

ll ans=0;

ll solve(ll n, ll x) {
	if (x==0) return 0;
	if (n==0) return 1;

	if (x <= 1 + size[n-1]) {
		return solve(n-1, x-1);
	}
	else {
		return pat[n-1]+1+solve(n-1,x-2-size[n-1]);
	}
}

int main()
{
	FAST;

	cin >> n >> x;
	pat[0] = 1;
	size[0] = 1;
	reps(i,50) {
		pat[i] = 2*pat[i-1] + 1;
		size[i] = 2*size[i-1] + 3;
	}

	cout << solve(n,x) << "\n";

	return 0;
}

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

const int MaxN = 1e5 + 10;
int n, parent[MaxN], cnt[MaxN], root;
vector <int> e[MaxN];

bool dfs(int node) {
    bool ans = true;
    for (auto x : e[node]) {
        if (x != parent[node]) {
            parent[x] = node;
            ans &= dfs(x);
        }
    }
    if (cnt[node] > 1 || cnt[node] == 0 && node == root)
       return false;
    if (cnt[node] == 0)
       cnt[parent[node]]++;
    return ans;
}

int main() {
    cin >> n;
    for (int i = 0; i < n - 1; i++) {
        int a, b;
        cin >> a >> b;
        e[--a].push_back(--b);
        e[b].push_back(a);
    }
    if (n == 2) {
        cout << "Second";
        return 0;
    }
    for (int i = 0; i < n; i++) {
        if (e[i].size() > 1) {
            parent[i] = i;
            root = i;
            if (dfs(i))
               cout << "Second";
            else
                cout << "First";
            return 0;
        }
    }
}


Measured memory_bytes: 6656
h, n = gets.split.map(&:to_i)
a = Array.new(n){gets.split.map(&:to_i)}
dp = Array.new(h + 1, Float::INFINITY)
dp[0] = 0
h.next.times do |i|
  a.each do |x, y|
    if i + x < h && dp[i + x] > dp[i] + y
      dp[i + x] = dp[i] + y
    elsif i + x >= h && dp[h] > dp[i] + y
      dp[h] = dp[i] + y
    end
  end
end
puts dp[h]

Measured memory_bytes: 2044
#include <iostream>
#include <iomanip>
#include <fstream>
#include <cstdio>
#include <sstream>
#include <cassert>
#include <vector>
#include <string>
#include <bitset>
#include <cmath>
#include <algorithm>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <random>
#include <chrono>
#include <ctime>

using namespace std;

#define en '\n'
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) int((x).size())

typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const int INF = 1e9 + 7;
const ll INFLL = 1e18;
const double EPS = 1e-9;
const double PI = 3.1415926535897932384626433832795;
const int MAX_SIZE = 5e5;

mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());

bool IS_ONE_TEST = 1;
ld START_TIME, TIME;

void fast_in_out() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
}

void solve() {
    int n;
    cin >> n;
    cout << (n >= 30 ? "Yes" : "No") << en;
    
}

int main() {
    START_TIME = clock();
    fast_in_out();
    int TESTS = 1;
    if (!IS_ONE_TEST) cin >> TESTS;
    while (TESTS--) { solve(); }
#ifdef __APPLE__
    TIME = (clock() - START_TIME) / CLOCKS_PER_SEC;
    cerr << en << TIME * 1000 << " ms." << en;
#endif
    return 0;
}

/*
     ▄▀▀▀▄
▄███▀░◐░░░▌
    ▌░░░░░▐
    ▐░░░░░▐
    ▌░░░░░▐▄▄
    ▌░░░░▄▀▒▒▀▀▀▀▄
   ▐░░░░▐▒▒▒▒▒▒▒▒▀▀▄
   ▐░░░░▐▄▒▒▒▒▒▒▒▒▒▒▀▄
    ▀▄░░░░▀▄▒▒▒▒▒▒▒▒▒▒▀▄
      ▀▄▄▄▄▄█▄▄▄▄▄▄▄▄▄▄▄▀▄
           ▌▌░▌▌
           ▌▌░▌▌
         ▄▄▌▌▄▌▌        */


Measured memory_bytes: 3644
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <cmath>
#include <algorithm>
#include <sstream>
#include <stack>
#include <cstring>
#include <iomanip>
#include <ctime>
#include <cassert>
using namespace std;
#define REP(i,a,b) for(int (i)=(a);(i)<=(b);++i)
#define PER(i,a,b) for(int (i)=(a); (i)>=(b);--i)
#define fi first
#define se second
#define pb push_back
#define SZ(x) ((int)((x).size()))
#define ALL(t) t.begin(),t.end()
#define clr(x) memset(x,0,sizeof(x))
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef long double ld;
#define DBG(vari) cout<<"["<<__LINE__<<"] "<<#vari<<" = "<<(vari)<<endl;
template<class T> ostream &operator<<(ostream &os, vector<T> V){ os<<"[";for(auto vv:V)os<<vv<<",";return os<<"]"; } 
template<class L, class R> ostream &operator<<(ostream &os, pair<L,R> P) { return os<<"("<<P.fi<<","<<P.se<<")"; }
#define flash ios_base::sync_with_stdio(0);
#define read freopen("1.in","r",stdin);
#define write freopen("1.out","w",stdout);
inline bool EQ(ld a,ld b) {return fabs(a-b)<=(1e-7);}
const ll mod=(1e9+7);
const ld pi=(acos(-1));
//CUT BEGINS

int main() {
	int n,ans=0; cin>>n;
	int a[n+5];
	REP(i,1,n) cin>>a[i];
	REP(i,1,n-1) if(a[i]==i) swap(a[i],a[i+1]),++ans;
	if(a[n]==n) ++ans;
	cout<<ans;
	return 0;
}

Measured memory_bytes: 640
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>
#include <limits.h>




int main()
{

	int i;
	int z; //左は１、右は０
	char a[33];
	int ans;

	while(1)
	{
		scanf("%s",a);
		if(a[0]=='#'){break;}
		else
		{
			ans=0;
			for(i=0;i<strlen(a);i++)
			{
				if(i==0)
				{
					if((a[i]=='y')||(a[i]=='u')||(a[i]=='i')||(a[i]=='o')||(a[i]=='p')||(a[i]=='h')||(a[i]=='j')||(a[i]=='k')||(a[i]=='l')||(a[i]=='n')||(a[i]=='m'))
					{
						z=0;
					}else
					{
						z=1;
					}
				}else
				{
					if(z==0)
					{
						if((a[i]=='y')||(a[i]=='u')||(a[i]=='i')||(a[i]=='o')||(a[i]=='p')||(a[i]=='h')||(a[i]=='j')||(a[i]=='k')||(a[i]=='l')||(a[i]=='n')||(a[i]=='m')){}
						else{z=1;ans++;}
					}else
					{
						if((a[i]=='y')||(a[i]=='u')||(a[i]=='i')||(a[i]=='o')||(a[i]=='p')||(a[i]=='h')||(a[i]=='j')||(a[i]=='k')||(a[i]=='l')||(a[i]=='n')||(a[i]=='m'))
						{z=0;ans++;}
					}
				}
			}
			printf("%d\n",ans);
		}
	}
	return 0;
}
	

Measured memory_bytes: 968
import java.util.Scanner;

class Main
{
	public static void main(String[] args){
		Scanner scan = new Scanner(System.in);
		
		int[] a = new int[101];
		int v;
		
		int n = scan.nextInt();
		
		for(int i=1; i<=n; i++){
			a[i] = scan.nextInt();
		}
		
		for(int i=1; i<=n; i++){
			v = a[i];
			for(int q=i-1; q>0; q--){
				if(v > a[q]){
					for(int j=i; j>q; j--){
						a[j] = a[j-1];
					}
					a[q+1] = v;
					break;
				}
				else if(q==1){
					for(int j=i; j>0; j--){
						a[j] = a[j-1];
					}
					a[q] = v;
				}
			}
			for(int h=1; h<=n; h++){
				System.out.print(a[h]);
				if(h!=n){
					System.out.print(" ");
				}
			}
			System.out.print("\n");
		}
	}
}


Measured memory_bytes: 33948
/*
 * ID: adityaa
 * LANG: C++
 */
#include <bits/stdc++.h>
using namespace std;

#define fio ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define mem(x, y) memset(x, y, sizeof x);
#define fi first
#define se second
#define pb push_back
#define pii pair<int , int>
#define asdfg y1
#define int long long
#define double long double
#define endl '\n'
#define PI 3.14159265359

/*-----------------------------------------------------------------------*/

#define TRACE

#ifdef TRACE
#define trace(...) __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
#define trace(...)
#endif

/*-----------------------------------------------------------------------*/

// check base cases n = 0 , n = 1
// max / min questions - check for binary search
const int maxn = (int) 1e6 + 6;
const double EPS = 1e-9;
const int INF = (int)1e18 + 18;
const int mod = (int) 998244353;
int n , height[maxn] , dp[maxn];

signed main() {
    
    fio;
    cin >> n;
    for(int i = 1; i <= n; i++){
        cin >> height[i];
    }
    
    dp[1] = 0;
    dp[2] = abs(height[2] - height[1]);
    for(int i = 3; i <= n; i++){
        dp[i] = dp[i - 1] + abs(height[i] - height[i - 1]);
        dp[i] = min(dp[i] , dp[i - 2] + abs(height[i] - height[i - 2]));
    }
    
    cout << dp[n] << endl;
    
    
    
    
    return 0;
    
}


Measured memory_bytes: 5120
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> pll;
typedef unsigned long long ull;

const int MOD =  1000000007; //   1000000009 , 1000000023 ,1000000007 , 998244353
const ll INF = ll(1e18);
const ld PI = 4*atan((ld)1);

using namespace __gnu_pbds;
template<typename T, class cmp = std::less<T>>
using Tree = tree<T, null_type, cmp, rb_tree_tag, tree_order_statistics_node_update>;

bool isprime(ll n){
  for(ll i=2 ; i*i<=n ; i++){
    if(n%i==0)return false;
  }
  return true;
}

int main() {
  #ifndef ONLINE_JUDGE
    freopen("input.txt" , "r" , stdin);
  #endif
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.precision(10);

  ll n,x,t;
  cin >> n >> x >> t;
  ll res = (n + x - 1)/x;
  res = res * t;
  cout << res ;

}


Measured memory_bytes: 3644
#include <bits/stdc++.h>
using namespace std;
//cin.ignore();	// better to use 2 times getline(cin,s);
// g++ iterator.cpp -std=c++17
//cout << (A + B == C ? "YES" : "NO") << endl;
#define pb push_back
#define mk make_pair
#define vll vector<ll>
#define mll map<ll,ll >
#define mlli map<ll,ll>::iterator
#define size size()
#define endl "\n"
#define ll long long int
#define ld long double
void fast(){ios_base::sync_with_stdio(false);
   	cin.tie(NULL);
   	cout.tie(NULL);}


int main(void)
{
	fast();
	string s;
	cin>>s;
	int cnt=0;
	for(int i=0;i<s.size-1;i++)
	{
		if(s[i]=='h' && s[i+1]=='i')
		{
			cnt++;
		}
	}
	if(s.size%2==0 && cnt==s.size/2)
	{
		cout<<"Yes"<<endl;
	}
	else
	{
		cout<<"No"<<endl;
	}


	// string hi="";
	// for(int i=1;i<=5;i++)
	// {
	// 	hi=hi+"hi";
	// 	if(hi==s)
	// 	{
	// 		cout<<"Yes"<<endl;
	// 		return 0;
	// 	}
	// }
	// cout<<"No"<<endl;
	// return 0;


	// if(s.size%2!=0)
	// {
	// 	cout<<"No"<<endl;
	// }
	// else
	// {
	// 	if(s.size==2)
	// 	{
	// 		if(s=="hi")
	// 		{
	// 			cout<<"Yes"<<endl;
	// 		}
	// 		else
	// 		{
	// 			cout<<"No"<<endl;			// too many lines of code(think...)
	// 		}
	// 	}
	// 	else if(s.size==4)
	// 	{
	// 		if(s=="hihi")
	// 		{
	// 			cout<<"Yes"<<endl;
	// 		}
	// 		else
	// 		{
	// 			cout<<"No"<<endl;
	// 		}
	// 	}
	// 	else if(s.size==6)
	// 	{
	// 		if(s=="hihihi")
	// 		{
	// 			cout<<"Yes"<<endl;
	// 		}
	// 		else
	// 		{
	// 			cout<<"No"<<endl;
	// 		}
	// 	}
	// 	else if(s.size==8)
	// 	{
	// 		if(s=="hihihihi")
	// 		{
	// 			cout<<"Yes"<<endl;
	// 		}
	// 		else
	// 		{
	// 			cout<<"No"<<endl;
	// 		}
	// 	}
	// 	else if(s.size==10)
	// 	{
	// 		if(s=="hihihihihi")
	// 		{
	// 			cout<<"Yes"<<endl;
	// 		}
	// 		else
	// 		{
	// 			cout<<"No"<<endl;
	// 		}
	// 	}
	// }
}

Measured memory_bytes: 256
// D - Coloring Edges on Tree
#include <bits/stdc++.h>
using namespace std;
#define rp(i,s,e) for(int i=(s);i<(e);++i)

int main(){
	int N; cin>>N;
	int G[N], C[N-1];
	rp(i, 0, N-1){
		int p; scanf("%d%d", &p, C+i);
		G[--C[i]] = p-1;
	}

	int colors[N], pre_colors[N]; rp(i, 0, N) colors[i] = pre_colors[i] = 0;

	int K = 1;
	rp(c, 1, N){
		int p = G[c];
		int color = pre_colors[p] + 1;
		pre_colors[p] = colors[c] = color==colors[p]? ++color: color;
		K = max(K, color);
	}

	cout<< K <<endl;
	for(int c:C) cout<< colors[c] <<endl;
}

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

#define rep(i, n) REP(i, 0, n)
#define repr(i, n) for (int i = (n); i >= 0; i--)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for (int i = x; i < n; i++)
#define OP(m) cout << m << endl
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;

int main()
{
    vector<int> a(5);

    rep(i, 5) cin >> a[i];

    int ans = 1000;

    do
    {
        int sum = 0;
        rep(i, 4)
        {
            if (a[i] % 10 == 0)
                sum += a[i];
            else
                sum += a[i] + (10 - a[i] % 10);
        }
        sum += a[4];

        ans = min(ans, sum);

    } while (next_permutation(ALL(a)));

    OP(ans);

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define all(a) a.begin(), a.end()
#define rep(i, n) for(int i = 0; i < n; i++)
#define endl "\n"
typedef long long ll;

const int BIG_NUM = 1e9;

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

    string s;
    cin >> s;
    for(int i = 0; i < 3; i++) {
        if(s[i] == s[i + 1]) {
            cout << "Bad";
            return 0;
        }
    }
    cout << "Good";
    return 0;
}


Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;

#if DEBUG && !ONLINE_JUDGE
    ifstream input_from_file("input.txt");
    #define cin input_from_file
#else

#endif



int main() {
    ios::sync_with_stdio(false);
    cin.tie(0); // Togliere nei problemi con query online

    int N;
    LL K;
    cin >> N >> K;
    vector<int> A(N+1);
    for (int i = 1; i <= N; i++) cin >> A[i];
    LL per = 0;
    int at = 1;
    vector<int> visited(N+1, -1);
    while (visited[at] == -1 and K != 0) {
        //~ cout << at << " " << A[at] <<endl;
        visited[at] = per;
        per++;
        at = A[at];
        K--;
    }
    //~ cout << per << endl;
    per -= visited[at];
    K %= per;
    //~ cout << per << " " << at << " " << K << " " << endl;
    while (K != 0) at = A[at], K--;
    cout << at << "\n";
}


Measured memory_bytes: 4784
n, = list(map(int, input().strip().split()))

mm = list(map(int, input().strip().split()))

dp = [float('inf')] * n

dp[0] = 0

for i in range(n):
  if i < n - 1:
    dp[i+1] = min(dp[i+1], dp[i] + abs(mm[i+1] - mm[i]))
  if i < n - 2:
    dp[i+2] = min(dp[i+2], dp[i] + abs(mm[i+2] - mm[i]))

print(dp[n-1])

Measured memory_bytes: 13980
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
typedef long long ll;
typedef pair<int,int> pint;
typedef pair<ll,int> pli;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;

int main(){
    int n,m,q;
    cin>>n>>m>>q;
    vector<ll> t,s;
    t.push_back(-longinf);
    s.push_back(-longinf);
    rep(i,n){
        ll x;
        cin>>x;
        t.push_back(x);
    }
    rep(i,m){
        ll x;
        cin>>x;
        s.push_back(x);
    }
    t.push_back(longinf);
    s.push_back(longinf);
    while(q--){
        ll cur;
        cin>>cur;
        auto itr=lower_bound(t.begin(),t.end(),cur); // CE conflicting declaration ?
        ll lt=*prev(itr),rt=*itr;
        itr=lower_bound(s.begin(),s.end(),cur);
        ll ls=*prev(itr),rs=*itr;
        ll ans=min(max(rt,rs)-cur,cur-min(ls,lt));
        ans=min(ans,rt-ls+min(rt-cur,cur-ls));
        ans=min(ans,rs-lt+min(rs-cur,cur-lt));
        cout<<ans<<endl;
    }
    return 0;

}


Measured memory_bytes: 3060
/*
All Pairs Shortest Path | Aizu Online Judge
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=GRL_1_C
 */
#include <iostream>
#include <limits>

#define FORR(i,b,e) for(int i=(b);i<(int)(e);++i)
#define FOR(i,e) FORR(i,0,e)
#define dump(var) cerr << #var ": " << var << "\n"
#define dumpc(con) for(auto& e: con) cerr << e << " "; cerr<<"\n"

typedef long long ll;
typedef unsigned long long ull;

const double EPS = 1e-6;
const int d4[] = {0, -1, 0, 1, 0};

using namespace std;

const ll INF = numeric_limits<ll>::max();
ll dist[110][110];

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

    int V, E;
    cin >> V >> E;
    FOR(i, V) FOR(j, V) dist[i][j] = INF;
    FOR(i, V) dist[i][i] = 0;
    FOR(i, E) {
        int s, t, d;
        cin >> s >> t >> d;
        dist[s][t] = d;
    }

    FOR(k, V) FOR(i, V) FOR(j, V) {
        if (dist[i][k] != INF && dist[k][j] != INF) {
            dist[i][j] = min(dist[i][j], dist[i][k]+dist[k][j]);
            if (i == j && dist[i][j] < 0) goto NC;
        }
    }
    {
        auto p = [](ll d){
            if (d == INF) cout << "INF";
            else cout << d;
        };
        FOR(i, V) {
            p(dist[i][0]);
            FORR(j, 1, V) cout << ' ', p(dist[i][j]);
            cout << '\n';
        }
    }
    return 0;

    NC:
    cout << "NEGATIVE CYCLE" << endl;

    return 0;
}

Measured memory_bytes: 1288
# https://onlinejudge.u-aizu.ac.jp/courses/lesson/1/ALDS1/6/ALDS1_6_D
# 本の解説がわかりやすい
# ここでは本には書いてないことの補足を意識しながらコメントを付けていく
WMAX = 10**4 + 1
n = int(input())
A = list(map(int, input().split()))
B = sorted(A)
is_visited = [False] * n  # 巡回管理用
next_idxs = {}  # Aの要素について、これのkeyを見れば、その数字がsort後にどの位置にあるのかわかるように対応させる
for i, b in enumerate(B):
    next_idxs[b] = i

m_A = min(A)  # globalで一番小さい要素

# ソート後の並び順から巡回可能なグループから答えを計算する
# グループ内の最小の要素をm, グループの和をS, グループ内の要素数をn2とする。
# 具体的には,m*(n2-2) + S もしくは m + S + (1+n2)*m_Aのうち小さい方
ans = 0
for i in range(n):
    if is_visited[i]:
        continue  # 巡回済みならば次へ
    cur = i  # 巡回制御用のidx #探索済みでないiが入るはず
    S = 0  # 合計管理用
    n2 = 0
    m = WMAX  # グループ内の最小値探索用
    while True:
        # まずはもろもろの値を更新
        is_visited[cur] = True
        S += A[cur]
        m = min(m, A[cur])
        n2 += 1
        # ここで次のidxを取得する
        cur = next_idxs[A[cur]]
        if is_visited[cur]:
            break  # もし一周したらおわり
    # ループ内で完結したほうがいいのか外から要素を変えいてきたほうがいいのか
    # 小さい方を採用して答えに足し込む
    ans += min(m*(n2-2)+S, m+S+(1+n2)*m_A)

print(ans)


Measured memory_bytes: 5720
#include "bits/stdc++.h"
using namespace std;
int main(void){
  int A,B,C;
  string ans;
  cin >> A >> B;
  C = A + B;
  if (A%3==0)
    ans = "Possible";
  else if (B%3==0)
    ans = "Possible";
  else if (C%3==0)
    ans = "Possible";
  else
    ans = "Impossible";
  
  cout << ans << endl;
}

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

/*
struct Node{
    int key;
    Node *prev, *next;
};

Node *nil;

Node* listSearch(int key){
    Node *cur = nil->next;
    while( cur != nil && cur->key != key){
        cur = cur->next;
    }
    return cur;
}

void init() {
    nil = (Node *)malloc(sizeof(Node));
    nil->next = nil;
    nil->prev = nil;
}

void printList(){
    Node *cur = nil->next;
    int isf = 0;
    while(1){
        if(cur == nil) break;
        if(isf++ > 0) printf(" ");
        printf("%d", cur->key);
        cur = cur->next;
    }
    printf("\n");
}

void deleteNode(Node *t){
    if(t == nil) return;
    t->prev->next = t->next;
    t->prev->next = t->prev;
    free(t);
}

void deleteFirst(){
    deleteNode(nil->next);
}

void deleteLast(){
    deleteNode(nil->prev);
}

void deleteKey(int key){
    deleteNode(listSearch(key));
}

void insert(int key) {
    Node *x = (Node *)malloc(sizeof(Node));
    x->key = key;
    x->next = nil->next;
    nil->next->prev = x;
    nil->next = x;
    x->prev = nil;
}

int main(){
    int key, n;
    int size = 0;
    char com[20];
    int np = 0, nd = 0;
    scanf("%d", &n);
    init();
    for(int i=0; i < n; i++){
        scanf("%s%d", com, &key);
        if(com[0] == 'i') { insert(key); np++; size++;}
        else if(com[0] == 'd'){
            if(strlen(com) > 6){
                if(com[6] == 'F') deleteFirst();
                else if(com[6] == 'L') deleteLast();
            } else {
                deleteKey(key); nd++;
            }
            size--;
        }
    }

    printList();

    return 0;
}

*/

int main(){
    int q,x;
    char com[20];
    list<int> v;
    scanf("%d", &q);
    for(int i=0; i<q; i++){
        scanf("%s", com);
        if(com[0] == 'i') {
            scanf("%d", &x);
            v.push_front(x);
        } else if(com[6] == 'L'){
            v.pop_back();
        } else if(com[6] == 'F'){
            v.pop_front();
        } else if(com[0] == 'd'){
            scanf("%d", &x);
            for(list<int>::iterator it = v.begin(); it != v.end(); it++){
                if( *it == x){
                    v.erase(it);
                    break;
                }
            }
        }
    }
    int i = 0;
    for(list<int>::iterator it = v.begin(); it != v.end(); it++){
        if(i++) printf(" ");
        printf("%d", *it);
    }
    printf("\n");
}


Measured memory_bytes: 34484
#include<bits/stdc++.h>
 
using namespace std;
 
 
int main(){
	int n;
	scanf("%d",&n);
	int i,dp[100002][3];

	int a[100002],b[100002],c[100002];
	for(i=1;i<=n;i++)
		scanf("%d%d%d",&a[i],&b[i],&c[i]);

	dp[1][0]=a[1];
	dp[1][1]=b[1];
	dp[1][2]=c[1];

	for(i=2;i<=n;i++){
		dp[i][0] = max(dp[i-1][1]+a[i],dp[i-1][2]+a[i]);
		dp[i][1] = max(dp[i-1][0]+b[i],dp[i-1][2]+b[i]);
		dp[i][2] = max(dp[i-1][0]+c[i],dp[i-1][1]+c[i]);
	}

	int ans = max(max(dp[n][0],dp[n][1]),dp[n][2]);
	printf("%d\n",ans );

	return 0;
}


Measured memory_bytes: 2560
//ITP1_7_A

#include <stdio.h>

int main(){

	int m,f,r;
	
	while(1){
	
		scanf("%d %d %d",&m,&f,&r);
		if(m==-1&&f==-1&&r==-1){break;}
		//??????
			if(m==-1||f==-1){printf("F\n");}
		else if(m+f>=80){printf("A\n");}
		else if(m+f>=65){printf("B\n");}
		else if(m+f>=50){printf("C\n");}
		else if(m+f>=30&&r>=50){printf("C\n");}
		else if(m+f>=30){printf("D\n");}
		else{printf("F\n");}
		
	}
	
	return 0;

}

Measured memory_bytes: 584
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int f[10005];
int s[105];
int main(){
  int n;scanf("%d",&n);
  for(int i=1;i<=n;++i)scanf("%d",&s[i]);
  f[0]=true;
  for(int i=1;i<=n;++i){
    for(int j=10000;j>=s[i];--j)f[j]|=f[j-s[i]];
  }
  for(int j=10000;j>=0;--j){
    if(j==0||(f[j]&&j%10!=0)){
      printf("%d\n",j);return 0;
    }
  }
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
#include<bits/stdc++.h>
#include<string.h>
#include<vector>
#include<queue>
using namespace std;

int main()
{
   char quit[12]="END_OF_TEXT";
   char word[11], line[1111];
   cin>>word; int wordlength=strlen(word),c=0;

   while(1){
       cin>>line; if(strcmp(line,quit)==0) break;
       int linelength=strlen(line),i;

        for(i=0;i<linelength;i++){
            if(line[i]>=65 && line[i]<=90) line[i]+=32;
        }

        if(strcmp(line,word)==0) c++;

   }
   cout<<c<<"\n";
}



Measured memory_bytes: 3092
#include<cstdio>
using namespace std;
int main(){
    int n;
    while(scanf("%d",&n),n){
        int jiro[32]={0};
        for(int i = 1;i <= n; i++){
            scanf("%d",&jiro[i]);
        }
        bool f = 0;
        int now = 32;
        int x = 0,y = 1;
        int ans[64]={0};
        for(;;){
            if(now <= 0){
                ans[x-1] = 0;
                break;
            }
            if(f == 0){
                now -= (now-1)%5;
                ans[x] = now;
                x++;
                f = 1;
            }
            else if(f == 1){
                int ji;
                (y%n == 0)? ji = jiro[n] : ji = jiro[y%n];
                now -= ji;
                ans[x] = now;
                y++;
                x++;
                f = 0;
            }
        }
        for(int i = 0;i < x; i++)printf("%d\n",ans[i]);
    }
    return 0;
}

Measured memory_bytes: 1028
#include<cstdio>
#include<algorithm>
using namespace std;
int a[200005],n,p[200005],a1;
int main()
{
	scanf("%d",&n);for(int i=1;i<=n;++i) {scanf("%d",&a[i]);p[a[i]]=i;}p[n+1]=200001;
	int cnt=0;
	for(int i=1;i<=n;++i) {
		if(p[i]<p[i-1]) {a1=a1<cnt?cnt:a1;cnt=1;}
		else ++cnt;
	}
	a1=a1<cnt?cnt:a1;
	cnt=0;
	for(int i=n;i>=1;--i) {
		if(p[i]>p[i+1]) {a1=a1<cnt?cnt:a1;cnt=1;}
		else ++cnt;
	}
	a1=a1<cnt?cnt:a1;
	printf("%d\n",n-a1);
	return 0;
}

Measured memory_bytes: 1664
h, w = gets.split.map(&:to_i)

h.times do
  str, ans = gets, [-1] * w
  
  w.times do |i|
    if str[i] == "c"
      c = 0
      for j in i...w
        ans[j] = c
        c += 1
      end
    end
  end
  
  puts ans.join(" ")
end

Measured memory_bytes: 8824