akhauriyash/Code-Regression huggingface dataset:
/*  /$$                                     /$$
      | $$                                    | $$
  /$$$$$$$  /$$$$$$   /$$$$$$$  /$$$$$$   /$$$$$$$  /$$$$$$   /$$$$$$
 /$$__  $$ /$$__  $$ /$$_____/ /$$__  $$ /$$__  $$ /$$__  $$ /$$__  $$
| $$  | $$| $$$$$$$$| $$      | $$  \ $$| $$  | $$| $$$$$$$$| $$  \__/
| $$  | $$| $$_____/| $$      | $$  | $$| $$  | $$| $$_____/| $$
|  $$$$$$$|  $$$$$$$|  $$$$$$$|  $$$$$$/|  $$$$$$$|  $$$$$$$| $$
 \_______/ \_______/ \_______/ \______/  \_______/ \_______/|__//$$$$$$ /$$$$$$
                                                               |______/|______/

*/
#include <bits/stdc++.h>
#define fastio        ios_base::sync_with_stdio(false); cin.tie(NULL);
#define ln            cout << endl;
#define vi            vector<int>
#define vll           vector<long long>
#define sortl(vec)    sort(vec.begin(), vec.end());
#define sortr(vec)    sort(vec.rbegin(), vec.rend());
#define forn(i, x, n) for(long long i = x; i < n; i++)
#define revn(i, n, x) for(long long i = n; i >= x; i--)
#define in(vec)       for(auto &it : vec) cin >> it;
#define loop(vec)     for(auto &it : vec)
#define	out(vec)      for(auto &it : vec) cout << it << " "; ln
#define ll            long long
#define mod           1000000007
#define debug(x)      cout << x << endl;
#define pb            emplace_back
#define mp            make_pair
#define um            unordered_map
#define pii           pair<int, int>
#define pll           pair<ll, ll>
#define f             first
#define s             second
#define pi            3.14159265359
#define CLOCK         cerr<<"time taken : "<<(float)clock()/CLOCKS_PER_SEC<<" secs"<<endl;
using namespace std;

ll bS(ll l, ll r, ll x, vll arr) {
	while (l <= r) {
		ll m = l + (r - l) / 2;

		if (arr[m] == x)
			return m;

		if (arr[m] < x)
			l = m + 1;

		else
			r = m - 1;
	}

	return -1;
}

void primeFactors(ll n) {
	while (n % 2 == 0) {
		//cout << 2 << " ";
		n = n / 2;
	}

	for (ll i = 3; i <= sqrt(n); i += 2) {
		while (n % i == 0) {
			//cout << i << " ";
			n = n / i;
		}
	}

	if (n > 2)
		cout << n << " ";
}

ll power(ll x, ll y, ll p) {
	ll res = 1;
	x = x % p;

	while (y > 0) {
		if (y & 1)
			res = (res * x) % p;

		y = y >> 1;
		x = (x * x) % p;
	}
	return res;
}

ll modulo(ll a, ll b) {
	ll c = a % b;
	return (c < 0) ? c + b : c;
}

int main() {
// in(vec) works for size-defined type vectors

#ifndef ONLINE_JUDGE
	// for getting input from input.txt
	freopen("input1.txt", "r", stdin);
	// for writing output to output.txt
	freopen("output1.txt", "w", stdout);
#endif

	fastio
	ll t = 1;
	while (t--) {
		ll n, k;
		cin >> n >> k;
		vll vec(n);
		in(vec);
		ll mini = 1e18 + 7, tmp;

		for (ll i = 0; i < n - k + 1; i++) {
			if (vec[i] < 0 && vec[i + k - 1] <= 0)
				tmp = abs(vec[i]);
			if (vec[i] >= 0 && vec[i + k - 1] > 0)
				tmp = abs(vec[i + k - 1]);
			if (vec[i] <= 0 && vec[i + k - 1] >= 0)
				tmp = min((vec[i + k - 1] + abs(vec[i + k - 1] - vec[i])), (abs(vec[i]) + abs(vec[i + k - 1] - vec[i])));

			mini = min(tmp, mini);
		}
		cout << mini << endl;
	}


	CLOCK
	return 0;
}



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


#define INF 1000000000000


signed main()
 {
int a,b,c,d;
cin>>a>>b>>c>>d;
while(true){
  c-=b;
  if(c<=0){cout<<"Yes";exit(0);}
  a-=d;
  if(a<=0){cout<<"No"; exit(0);}
}
}


Measured memory_bytes: 3632
#include <iostream>
#include <cstring>
#include <string>
#include <vector>
#include <cmath>
#include <map>
#include <queue>
#include <set>
#include <algorithm>
#include <iomanip>

using namespace std;

const int mod = 1000000007;

set<int> st[26];
string s;
int dp[200500];

int greedy(int m = -1){
    int pos = m;
    int res = 0, mx, k;
    set<int>::iterator r;
    while (pos != s.size()){
        mx = -1;
        //cout << res << " " << pos << endl;
        for (int i = 0; i < 26; i++){
            r = st[i].upper_bound(pos);
            k = (r != st[i].end() ? (*r):s.size());
            if (k > mx){
                mx = k;
            }

        }
        pos = mx;
        res++;
    }
    return res;
}

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

    cin >> s;
    dp[s.size()] = 0;
    int mx, k;
        set<int>::iterator r;
     for (int i =0 ; i < s.size(); i++)
        st[s[i] - 'a'].insert(i);
    for (int pos = s.size() - 1; pos >= 0; pos--){
        mx = -1;
        for (int i = 0; i < 26; i++){
            r = st[i].upper_bound(pos);
            k = (r != st[i].end() ? (*r):s.size());
            if (k > mx){
                mx = k;
            }
        }
        dp[pos] = dp[mx] + 1;
    }

    int l = greedy();
    string ans;
    for (int i = 0; i < l; i++)
        ans += '&';
    int last = -1;
    for (int i = 0; i < l; i++){
        for (int j = 0; j < 26; j++){
            r = st[j].upper_bound(last);
            //if (j == 0)
            //cout << i << " " << (r != st[j].end() ? (*r):s.size()) << " " << dp[(r != st[j].end() ? (*r):s.size())] << endl;
            if (i + 1 + dp[(r != st[j].end() ? (*r):s.size())] == l){
                ans[i] = 'a' + j;
                last = (r != st[j].end() ? (*r):s.size());
                break;
            }
        }
    }
    cout << ans;
    return 0;
}


Measured memory_bytes: 10644
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
using ll = long long;
int main() {
  ll a,b,c,d;
  cin>>a>>b>>c>>d;
  double e,f;
  e=(30*c-5.5*d)*M_PI/180;
  f=a*a+b*b-2*a*b*cos(e);
  double g=sqrt(f);
  cout << fixed << setprecision(16);
  cout<<g<<endl;
  
}

Measured memory_bytes: 4204
#include<bits/stdc++.h>
using namespace std;
inline void rd(int &x){
  int k, m=0;
  x=0;
  for(;;){
    k = getchar_unlocked();
    if(k=='-'){
      m=1;
      break;
    }
    if('0'<=k&&k<='9'){
      x=k-'0';
      break;
    }
  }
  for(;;){
    k = getchar_unlocked();
    if(k<'0'||k>'9'){
      break;
    }
    x=x*10+k-'0';
  }
  if(m){
    x=-x;
  }
}
inline void wt_L(char a){
  putchar_unlocked(a);
}
inline void wt_L(int x){
  char f[10];
  int m=0, s=0;
  if(x<0){
    m=1;
    x=-x;
  }
  while(x){
    f[s++]=x%10;
    x/=10;
  }
  if(!s){
    f[s++]=0;
  }
  if(m){
    putchar_unlocked('-');
  }
  while(s--){
    putchar_unlocked(f[s]+'0');
  }
}
int N;
int D[100000];
int main(){
  rd(N);
  {
    int Lj4PdHRW;
    for(Lj4PdHRW=0;Lj4PdHRW<N;Lj4PdHRW++){
      rd(D[Lj4PdHRW]);
    }
  }
  sort(D,D+N);
  wt_L(D[N/2]-D[N/2-1]);
  wt_L('\n');
  return 0;
}
// cLay varsion 20190630-1

// --- original code ---
// int N, D[1d5];
// {
//   rd(N,D(N));
//   sort(D,D+N);
//   wt(D[N/2]-D[N/2-1]);
// }


Measured memory_bytes: 640
fn main() {
  let n: usize = read();
  let vec: Vec<usize> = reads(n);
  
  let ans = vec.iter().fold((0,0), |(a,r),&x| (a+(x+r)/2, if x==0 {0} else {(x+r)%2})).0;
  println!("{}", ans)
}

fn read<T: std::str::FromStr>() -> T {
  let mut buf = String::new();
  std::io::stdin().read_line(&mut buf).ok();
  buf.trim().parse::<T>().ok().unwrap()
}

fn reads<T: std::str::FromStr>(n: usize) -> Vec<T> {
  let mut vec: Vec<T> = vec![];
  for _ in 0 .. n {
    vec.push(read());
  }
  vec
}

Measured memory_bytes: 4352
#include<algorithm>
#include<bitset>
#include<climits>
#include<cmath>
#include<cstdlib>
#include<iomanip>
#include<iostream>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<stack>
#include<string>
#include<time.h>
#include<tuple>
#include<utility>
#include<vector>

using namespace std;
long gcd(long x, long y) { if (x > y) { return gcd(y, x); } long r; while (y != 0) { r = x % y; x = y; y = r; } return x; }
long lcm(long x, long y) { return (x / gcd(x, y) * y); }

int main(void) {

	long res = 0;//重複あるよ
	long N; cin >> N;
	vector<long> L(N); for (int i = 0; i < N; i++) cin >> L[i];
	sort(L.begin(), L.end());

	//まず二本を選ぶ。
	for (int i = 0; i < N; i++) for (int j = i + 1; j < N; j++) {
		// L[i] と L[j]
		//このとき残りのL[k]はi != k かつ j != kかつ　abs(d[i] - d[j])  < d[k] < (d[i] + d[j])
		long lmin = abs(L[i] - L[j]);
		long lmax = (L[i] + L[j]);
		if (lmax <= L[0]) continue;
		auto minind = upper_bound(L.begin(), L.end(), lmin);
		auto maxind = lower_bound(L.begin(), L.end(), lmax);
		long score = distance(minind, maxind);
		if (lmin < L[i] && L[i] < lmax) score--;
		if (lmin < L[j] && L[j] < lmax) score--;
		res += score;
	}
    res /= 3;
	cout << res << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define __ <<' '<<
#define ___ <<' '
#define bash push_back
#define ALL(x) x.begin(),x.end()
//#define int long long

struct IoSetup {IoSetup() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout <<fixed<<setprecision(12);
    cerr <<fixed<<setprecision(12);
}}IoSetup;

using ll = long long;
using pii = pair<int, int>;
constexpr int INF = 0x3f3f3f3f;
constexpr long long LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr int SMOD = 1000000007;
constexpr int NMOD = 998244353;
constexpr int dx[]={1,0,-1,0,1,1,-1,-1};
constexpr int dy[]={0,1,0,-1,-1,1,-1,1};

inline bool inside(int x,int y,int w,int h){return (x>=0 && y>=0 && x<w && y<h);}
template<class T>bool chmax(T &a, const T &b){return(a<b?a=b,true:false);}
template<class T>bool chmin(T &a, const T &b){return(a>b?a=b,true:false);}
inline int qp(int a,ll b,int mo){ll ans=1;do{if(b&1)ans=1ll*ans*a%mo;a=1ll*a*a%mo;}while(b>>=1);return ans;}


const int MAX = 510000;
const int MOD = NMOD;
long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}


int n, m, k;
ll p[200200];
signed main() {

    cin >> n >> m >> k;
    int K = k;
    if(m == 1) {
        cout << (k >= n-1) << endl;
        return 0;
    }
    
    ll ans = m;
    COMinit();
    
    for(int i = 1; i < n; i++) {
        ans = ans * (m - 1) % NMOD;
    }
    p[n-1] = 1;
    for(int i = n-2; i >= 0; i--) {
        p[i] = p[i+1] * (m - 1) % NMOD;
    }
    
    for(int i = k; i > 0; i--) {
        ans += COM(n-1, i) * m % NMOD * p[i] % NMOD;
        ans %= NMOD;
    }
    cout << ans << endl;
  
    return 0;
}



Measured memory_bytes: 17160
#include <bits/stdc++.h>
using namespace std;
using ll = long long int;
using P = pair<ll,ll>;
int INF = 1e9+7;

int main() {
    int A,B;
    cin >> A >> B;
    if (B%A == 0) {cout << A+B << endl;}
    else cout << B-A << endl;
}


Measured memory_bytes: 384
n=list(map(int,input().split()))
#x1=n[0],y1=n[1],x2=n[2],y2=n[3]
vec=[n[2]-n[0],n[3]-n[1]]
vertvec=[(-1)*vec[1],vec[0]]
x3=n[2]+vertvec[0]
y3=n[3]+vertvec[1]
x4=n[0]+vertvec[0]
y4=n[1]+vertvec[1]
print(x3,y3,x4,y4)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> l_l;
typedef pair<int , int> i_i;
typedef vector<ll> vl;
typedef vector<int> vi;
typedef vector<char> vec;
typedef vector<bool> veb;
typedef vector<string> ves;
typedef vector<vector<ll>> vvl;
typedef vector<vector<int>> vvi;
typedef vector<vector<char>> vvec;
typedef vector<vector<bool>> vveb;
typedef vector<vector<string>> vves;
#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 rep2(i,n) for(int i=2;i<(int)(n);i++)
#define repk(i,k,n) for(int i=k;i<(int)(n);i++)
#define rev(v) reverse(v.begin(), v.end())
#define fs first
#define sc second
#define pb push_back
#define pp pop_back
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define maxel(a) *max_element(all(a))
#define minel(a) *min_element(all(a))
#define acc accumulate
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define mod (1000000007)
typedef long long int64;
//const int64 INF = 1LL << 58;
#define dame { puts("-1"); return 0;}
#define YES { cout << "YES" << endl; return 0; }
#define NO { cout << "NO" << endl; return 0; }
#define Yes { cout << "Yes" << endl; return 0; }
#define No { cout << "No" << endl; return 0; }
#define OK { cout << "OK" << endl; return 0; }
#define NG { cout << "NG" << endl; return 0; }
#define sz(v) ((int)(v).size())
#define uniq(a) sort(all(a));(a).resize(unique(all(a)) - a.begin());
#define dab(v) for(auto i:v)cout<<i<<' '; cout << endl;
#define vin(v) for (ll i = 0; i < v.size(); ++i) cin >> v[i];
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 (a>b) { a=b; return 1; } return 0; }
template<class T>void out(T a){cout << a << endl;}
template<class T>void die(T a){cout << a << endl; exit(0);}
int dx[] = {0, 0, -1, 1};
int dy[] = {1, -1, 0, 0};

#define SIZE 200005
#define MOD 1000000007
 
typedef pair <int,int> P;
 
ll inv[SIZE], fac[SIZE], finv[SIZE];
void make(){
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for(int i=2; i<SIZE; i++)
	{
		inv[i] = MOD - inv[MOD%i]*(MOD/i)%MOD;
		fac[i] = fac[i-1] * (ll) i % MOD;
		finv[i] = finv[i-1] * inv[i] % MOD;
	}
    return ;
}
ll comb(int a,int b){
	if(a < b) return 0;
	return fac[a] * (finv[b] * finv[a-b] % MOD) % MOD;
}



ll beki(int a, int n){
    if(n == 0) return 1;
    ll ans = beki(a, n / 2);
    ans = ans * ans;
    if(n % 2 == 1) ans = ans * a;
    return ans;
}




int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
    //cout << fixed << setprecision(15);
    
    ll A,B,C,K;cin>>A>>B>>C>>K;
	ll ans = 0;
	if(K <= A) {
		cout << K << endl;
		return 0;
	}
	K -= A; ans += A;
	if( K<=B){
		out(A);
		return 0;
	}
	K -= B;
	out(ans - K);
}

Measured memory_bytes: 3648
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll read(){
	ll a=0,b=getchar(),c=1;
	while(!isdigit(b))c=b=='-'?-1:1,b=getchar();
	while(isdigit(b))a=a*10+b-'0',b=getchar();
	return a*c;
}
int a[5];
int main(){
	int x=read();
	a[x]=1,x=read(),a[x]=1;
	for(int i=1;i<4;i++)
		if(a[i]==0)cout << i;
	return 0;
}

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

using namespace std;

#define sim template <class c
#define ris return *this
#define dor > debug &operator<<
#define eni(x)                                                                        \
	sim > typename enable_if<sizeof dud<c>(0) x 1, debug &>::type operator<<(c i) \
	{
sim > struct rge
{
	c b, e;
};
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c *x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug
{
#ifdef LOCAL
	~debug()
	{
		cerr << endl;
	}
	eni(!=) cerr << boolalpha << i;
	ris;
} eni(==) ris << range(begin(i), end(i));
}
sim, class b dor(pair<b, c> d)
{
	ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d)
{
	*this << "[";
	for (auto it = d.b; it != d.e; ++it)
		*this << ", " + 2 * (it == d.b) << *it;
	ris << "]";
}
#else
	sim dor(const c &)
	{
		ris;
	}
#endif
}
;
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

#define forn(i, n) for (ll i = 0; i < int(n); i++)
#define rfor(n, i) for (ll i = (n - 1); i >= 0; --i)
#define all(V) V.begin(), V.end()
#define rall(V) V.rbegin(), V.rend()
#define len(V) (int)V.size()
#define ll long long
#define ld long double
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define endl '\n'
#define M_PI 3.14159265358979323846
#define EPS 1e-7

vector<string> s;

int f(int i, int j, int h, int w)
{
	int res = 0;
	if (i + 1 < h && s[i + 1][j] == '#')
		res++;
	if (j + 1 < w && s[i][j + 1] == '#')
		res++;
	if (i + 1 < h && j + 1 < w && s[i + 1][j + 1] == '#')
		res++;
	if (i - 1 >= 0 && s [i - 1][j] == '#')
		res++;
	if (i - 1 >= 0 && j - 1 >= 0 && s [i - 1][j - 1] == '#')
		res++;
	if (j - 1 >= 0 && s [i][j - 1] == '#')
		res++;
	if (i + 1 < h && j - 1 >= 0 && s [i + 1][j - 1] == '#')
		res++;
	if (i - 1 >= 0 && j + 1 < w && s [i - 1][j + 1] == '#')
		res++;
	return res;
}

void solve()
{	
	int h, w; cin >> h >> w;
	s.resize(h);
	forn(i, h)
	{
		cin >> s[i];
	}
	for (int i = 0; i < h; ++i)
	{
		for (int j = 0; j < w; ++j)
		{
			if (s[i][j] == '.')
			{
				int cnt = f(i, j, h, w);
				s[i][j] = (char)(cnt + '0');
			}
		}
	}

	for (int i = 0; i < h; ++i)
	{
		for (int j = 0; j < w; ++j)
		{
			cout << s[i][j];
		}
		cout << endl;
	}
}

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


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

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

    int ans = 1;
    while(1){
        if((int)(ans * 0.08) == a && (int)(ans * 0.1) == b){
            break;
        }
        else if((int)(ans * 0.08) > a && (int)(ans * 0.1) > b){
            ans = -1;
            break;
        }
        ans++;
    }

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

Measured memory_bytes: 256
import java.io.File;
import java.io.FileNotFoundException;
import java.util.Arrays;
import java.util.LinkedList;
import java.util.Scanner;

public class Main {
	Scanner sc;

	class P implements Comparable<P> {
		double x;
		double y;

		double r;
		double theta;

		P(double xx, double yy) {
			x = xx;
			y = yy;
		}

		void org(P t) {
			x -= t.x;
			y -= t.y;
		}

		void st() {
			r = Math.sqrt(x * x + y * y);
			theta = Math.atan2(y, x);
			rot(0);
		}

		P sum(P t) {
			return new P(x + t.x, y + t.y);
		}

		P div(double v) {
			return new P(x / v, y / v);
		}

		public int compareTo(P t) {
			if (Math.abs(theta - t.theta) < 1e-11) {
				if ((r - t.r) < 0) {
					return -1;

				}
				return 1;

			}
			if (theta - t.theta > 0) {
				return 1;
			}
			return -1;
		}

		void rot(double theta) {
			this.theta += theta;
			while (this.theta > Math.PI * 2) {
				this.theta -= Math.PI * 2;
			}
			while (this.theta < 0) {
				this.theta += Math.PI * 2;
			}
		}
	}

	class Poly {
		P[] E;
		int n;

		Poly(int n, Scanner sc) {
			E = new P[n];
			this.n = n;
			for (int i = 0; i < n; i++) {
				E[i] = new P(sc.nextDouble(), sc.nextDouble());
			}
		}

		void set() {
			P sum = new P(0, 0);
			for (P p : E) {
				sum = sum.sum(p);
			}
			P org = sum.div(n);

			for (P p : E) {
				p.org(org);
				p.st();
			}

			Arrays.sort(E);
		}

		boolean check(double theta, Poly target) {
			for (P p : E) {
				p.rot(theta);
			}
			Arrays.sort(E);

			boolean ok = true;
			Poly a = target;
			Poly b = this;
			for (int i = 0; i < n; i++) {
	//			System.out.println(a.E[i].r + " " + a.E[i].theta);
	//			System.out.println(b.E[i].r + " " + b.E[i].theta);
			}
			for (int i = 0; i < n; i++) {
				if (Math.abs(E[i].r - target.E[i].r) > 1e-9 ) {
					ok = false;
					break;
				}
				if (Math.abs(E[i].theta - target.E[i].theta) > 1e-9 && Math.abs(Math.abs(E[i].theta - target.E[i].theta ) - Math.PI*2) > 1e-9) {
					ok = false;
					break;
				}
			}

			for (P p : E) {
				p.rot(-theta);
			}
			Arrays.sort(E);
			return ok;
		}
	}

	void run() {
		for (;;) {
			int n = sc.nextInt();
			if (n == 0) {
				break;
			}
			Poly a = new Poly(n, sc);
			Poly b = new Poly(n, sc);
			a.set();
			b.set();

			double t1 = 100;
			for (int i = 0; i < n; i++) {
				double t = -a.E[0].theta + b.E[i].theta;
				if (b.check(-t, a)) {
					
					while (t > Math.PI*2 ) {
						t -= Math.PI*2;
					}
					while (t < 0) {
						t += Math.PI*2 ;
					}

					t = Math.min(2*Math.PI-t, t);
					
					t1 = Math.min(t,t1);
				}
			}
			System.out.printf("%.8f\n",t1);
		}
	}

	/**
	 * @param args
	 */

	Main() {
		sc = new Scanner(System.in);
		try {
			sc = new Scanner(new File(""));
		} catch (FileNotFoundException e) {
			// TODO Auto-generated catch block
			// e.printStackTrace();
		}
	}

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		new Main().run();
	}

}

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

int main(){
  long long N,M;
  cin>>N>>M;
  vector<long long>A(N,0);
  for(int i=0;i<N;i++){
    cin>>A[i];
  }
  sort(A.begin(),A.end());
  
  vector<pair<long long,long long>>vec;
  for(int i=0;i<M;i++){
    long long b,c;
    cin>>b>>c;
    vec.emplace_back(c,b);
  }
  
  sort(vec.begin(),vec.end());
  
  int temp1=0;
  int temp2=0;
  int temp3=0;
  while(1){
    if(A[temp1]<vec[M-1-temp2].first && vec[M-1-temp2].second-temp3>0){
      A[temp1]=vec[M-1-temp2].first;
      temp1++;
      temp3++;
      continue;
    }
    if(A[temp1]<vec[M-1-temp2].first && vec[M-1-temp2].second-temp3==0){
      temp2++;
      temp3=0;
      continue;
    }
    break;
  }

  long long sum=0;
  for(int i=0;i<N;i++){
    sum=sum+A[i];
  }
  cout<<setprecision(18)<<sum<<endl;
  return 0;
}

 

Measured memory_bytes: 3188
N = int(input())
a, b, c = [0], [0], [0]
for i in range(N):
    a_i, b_i, c_i = map(int, input().split())
    a.append(a_i)
    b.append(b_i)
    c.append(c_i)
DP = [[0 for j in range(3)] for i in range(N+1)]
for days in range(1, N+1):
    for ABC in range(3):
        if ABC == 0:
            DP[days][ABC] = max(DP[days-1][1], DP[days-1][2]) + a[days]
        elif ABC == 1:
            DP[days][ABC] = max(DP[days-1][0], DP[days-1][2]) + b[days]
        elif ABC == 2:
            DP[days][ABC] = max(DP[days-1][0], DP[days-1][1]) + c[days]
print(max(DP[N]))



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

    h0 = 0
    h1 = abs(H[1] - H[0])

    for i in range(2, N):
        h0, h1 = h1, min(
            h0 + abs(H[i] - H[i - 2]),
            h1 + abs(H[i] - H[i - 1]))

    print(h1)


if __name__ == '__main__':
    main()

Measured memory_bytes: 52208
import bisect
import sys
input = sys.stdin.readline

N = int(input())
A = [-1*int(input()) for _ in range(N)]

maxims = [A[0]]
ans = 1
for a in A[1:]:
    if maxims[-1] > a:
        idx = bisect.bisect(maxims,a)
        maxims[idx] = a
    else:
        maxims.append(a)
        ans += 1
    
print(ans)
    
    
    

Measured memory_bytes: 8600
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int a,b=0;
    cin>>a;
    for(int i=0; i<=a; i++){
        for(int j=0; j<=a; j++){
            if(4*i+7*j==a){
                b++;
            }
        }
    }
    if(b==0) cout<<"No"<<endl;
    else cout<<"Yes"<<endl;
    return 0;
    
}

Measured memory_bytes: 256
import collections as col

if __name__ == '__main__':
	N = int(input())
	lst = []
	for _ in range(N):
		lst.append(input())

	c = col.Counter(lst)
	C = c.most_common()
	l = []
	co = C[0][1]
	for cc in C:
		if cc[1] == co:
			l.append(cc[0])
		else:
			break
	l.sort()
	for s in l:
		print(s)

Measured memory_bytes: 121732
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vint;
typedef pair<int,int> pint;
typedef vector<pint> vpint;
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,n) for(int i=n-1;i>=(0);i--)
#define reps(i,f,n) for(int i=(f);i<(n);i++)
#define each(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++)
#define all(v) (v).begin(),(v).end()
#define eall(v) unique(all(v), v.end())
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))
const int MOD = 1e9 + 7;
const int INF = 1e9;
const ll INFF = 1e18;

const int MAX_N = 110;
int dist[MAX_N][MAX_N];

//答えが1つ大きくなる問題.
int a[1010], b[1010], c[1010];
int main(void){
    int N, M; cin >> N >> M;
    rep(i, M){
        cin >> a[i] >> b[i] >> c[i];
        a[i]--; b[i]--;
    }
    rep(i, MAX_N)rep(j, MAX_N) dist[i][j] = INF;
    rep(i, N)dist[i][i] = 0;
    rep(i, M)dist[a[i]][b[i]] = c[i], dist[b[i]][a[i]] = c[i];
    rep(k, N)rep(i, N)rep(j, N) dist[i][j] = chmin(dist[i][j], dist[i][k] + dist[k][j]);

    set<pair<int, int>> se;
    rep(k, M)rep(i, N)rep(j, N){ // i->a[i]->b[i]->j
        if(dist[i][a[k]] + c[k] + dist[b[k]][j] == dist[i][j]){ //a[k]-b[k]
            se.insert(mp(min(a[k], b[k]), max(a[k], b[k])));
        }
    }
    printf("%d\n", M - se.size());
    return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
int main() {
  int64_t h;
  int a,b;
  cin >> h >> a;
  for(int i = 0; i < a; i++){
    cin >> b;
    h -= b;
  }
  string r = h <= 0 ? "Yes" : "No";
  cout << r;
}

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

int main() {
    int N;
    cin >> N;
    vector<ll> A(N);
    for (int i = 0; i < N; i++)
    {
        cin >> A[i];
    }
    sort(A.begin(), A.end(), greater<int>());

    ll ans = 0;
    for (int i = 1; i < N; i++)
    {
        if (i == 1) {
            ans += A[0];
            continue;
        }
        if (i >= 2)
        {
            ans += A[i / 2];
        }
        
    }
    cout << ans << endl;
  return 0;
}


Measured memory_bytes: 4844
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define REP(i,a,b) for (int i = a; i < (b); ++i)
#define all(x) (x).begin(),(x).end()
const int INF = 1000000007;
typedef long long ll;
using namespace std;
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; }
ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
ll lcm(ll a, ll b) { return (a * b) / gcd(a,b); }
ll fac(ll a) { return a > 1 ? fac(a - 1) * a : 1; }
bool echeck(ll a) { return a % 2 == 0 ? 1 : 0; }
ll comb(ll n, ll m){
  ll tmp = 1;
  for(int i = n; i >= n - m + 1; i--){
    tmp *= i;
  }
  ll temp = 1;
  for(int i = 1; i <= m; i++){
    temp *= i;
  }
  return tmp / temp;
}
int main(){
  // ios::sync_with_stdio(false);cin.tie(nullptr);
  cout << "square1001" << endl;
  return 0;
} 


Measured memory_bytes: 3068
#include <iostream>

using namespace std;

int main(){
    int x;
    cin >> x;
    int ans = 0;
    int i = 0,n = 0;
    for(i = 1; n < x; i++) n += i;//総和がxを超える時のiを調べる

    cout << i-1 << endl;
    
    return 0;
}

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

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<char, ll> pcl;

#define m0(x) memset(x, 0, sizeof(x))
#define all(x) x.begin(), x.end()
#define rep(i, n) for(int i = 0; i < (n); i++)
#define asort(x) sort(all(x));
#define dsort(x, t) sort(x.begin(), x.end(), greater<t>());
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end());
#define MINS(m, s) m.insert(mp(s, 1));
#define MFIN(m, s) m.find(s) != m.end()
#define mp make_pair
#define pb push_back
#define INF (1 << 29)
const int mod = 1000000007;

int main() {
    int h1, m1, h2, m2, k, h, m;
    cin >> h1 >> m1 >> h2 >> m2 >> k;
    h = h2 - h1;

    if(m2 >= m1) {
        m = m2 - m1;
    } else {
        m2 = m2 + 60;
        m = m2 - m1;
        h--;
    }

    if(h * 60 + m - k >= 0) {
        cout << h * 60 + m - k << endl;
    } else {
        cout << 0 << endl;
    }
    return 0;
}

Measured memory_bytes: 3624
/** By @ZhakudaMagzhan **/
# include  <bits/stdc++.h>

# define mp  make_pair
# define pb  push_back

# define   sz(x)  (int)x.size()
# define  all(x)  x.begin(), x.end()
# define  bit(x)  __builtin_popcountll(x)

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

typedef pair <int,int> pii;

const int inf = (int) 1e9+50, mod = 999983ll;
const ll linf = (ll) 2e18;

int kob (int x, int y) { return ((ll)x * y) % mod; } 
int aza (int x, int y) { x -= y; if (x < 0) return x + mod; return x; } 
int kos (int x, int y) { x += y; if (x >= mod) return x - mod; return x; }

const int maxn = (int) 1e5 + 777, maxn2 = (int) 1e6 + 777;    

//temp.cpp

int main () {
	#define FN "" 
	#ifdef lcl	
		freopen (FN".in", "r", stdin);
		freopen (FN".out", "w", stdout);
	#endif
	ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); 
	ll q, h, s, d, l;
	cin >> q >> h >> s >> d;
	cin >> l;
	h = min (h, q * 2);
	s = min (s, h * 2);
	d = min (d, s * 2);


	if (l >= 2) {
		cout << (l / 2) * d + (l % 2) * s;
	}
	else {
		cout << s;
	}
	return 0;
}

Measured memory_bytes: 256
N = int(input())
A = [int(i) for i in input().split()]
total = abs(A[0])
for i in range(N-1):
    total += abs(A[i+1]-A[i])
total += abs(A[N-1])
print(total+abs(A[1])-abs(A[1]-A[0])-abs(A[0]))
for i in range(1,N-1):        
    print(total+abs(A[i-1]-A[i+1])-abs(A[i-1]-A[i])-abs(A[i]-A[i+1]))    
print(total+abs(A[N-2])-abs(A[N-2]-A[N-1])-abs(A[N-1]))

Measured memory_bytes: 14048
#include<stdio.h>

int F[50];

int fibonacci(int n){
  int i;
  if(n==0 || n==1) return F[n]=1;
  if(F[n]!=0) return;
  return F[n]=fibonacci(n-2)+fibonacci(n-1);
}
int main(){
  int i,n;
  scanf("%d",&n);
  for(i=0;i<n;i++) F[n]=0;
  i=fibonacci(n);
  printf("%d\n",i);
  return 0;
}



Measured memory_bytes: 2104
#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
using P = pair<ll, ll>;
using mat = vector<vector<ll>>;

inline void IOS() { ios::sync_with_stdio(false), cin.tie(0); }

template <typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
	fill((T *)array, (T *)(array + N), val);
}

const ll INF = 1e16;
const ll MOD = 1e9 + 7;
//int dx[4] = {1,0,-1,0};
//int dy[4] = {0,1,0,-1};
//ll pas[5001][5002];

vector<ll> g[114514];
ll dp[114514] = {};
ll n, m;

ll rec(int i){
	if(dp[i] > 0)return dp[i];
	ll &tmp = dp[i];
	for (int j = 0;j < g[i].size();++j) {
		tmp = max(tmp, rec(g[i][j]) + 1);
	}
	return tmp;
}

signed main(){
	IOS();
	cin >> n >> m;
	for (int i = 1;i <= m;++i) {
		ll x, y;
		cin >> x >> y;
		g[x].push_back(y);
	}	
	ll ans = 0;
	for (int i = 1;i <= n;++i) {
		ans = max(ans, rec(i));
	}
	cout << ans << endl;
	
}

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

#define INF 1.1e9
#define LINF 1.1e18
#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(), (v).end()

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

int n;
string s;
int a,b;

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

	cin>>n>>s;

	REP(i,n) {
		if(s[i]=='(') {
			if(i<n-1&&s[i+1]==')') i++;
			else a++;
		}
		else {
			if(a>0) a--;
			else b++;
		}
	}
	REP(i,b) cout<<'('<<flush;
	cout<<s<<flush;
	REP(i,a) cout<<')'<<flush;
	cout<<endl;

	return 0;
}


Measured memory_bytes: 256
A = int(input())
B = int(input())
C = int(input())
X = int(input())
count = 0
for i in range(A+1):
    for j in range(B+1):
        for k in range(C+1):
            if (X== 500*i +100*j +50*k):
                count += 1
print(count)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
using lint = long long int;
using P = pair<int, int>;
using PL = pair<lint, lint>;
#define FOR(i, begin, end) for(int i=(begin),i##_end_=(end);i<i##_end_;i++)
#define IFOR(i, begin, end) for(int i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--)
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
#define ALL(a)  (a).begin(),(a).end()
constexpr int MOD = 1000000007;
constexpr int INF = 2147483647;
void yes(bool expr) {cout << (expr ? "Yes" : "No") << "\n";}
int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int X;
  cin >> X;
  cout << 10 - X/200 << endl;
}

Measured memory_bytes: 3648
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i < (n); i++)
#define lower(s) transform(s.begin(), s.end(), s.begin(), ::tolower)
using namespace std;
using ll = long long;
int INF = 1001001001;

int main() {
  string s;
  cin >> s;
  string rs = s;
  reverse(rs.begin(), rs.end());
  int ans = 0;
  for(int i=0; i * 2 < s.size(); i++) {
    if(s[i] != rs[i]) ans++;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3624
a = int(input())
b = int(input())
c = int(input())
x = int(input())
ans = 0
for i in range(a+1):
    for j in range(b+1):
        for k in range(c+1):
            if 500*i + 100*j + 50*k == x:
                ans += 1
print(ans)

Measured memory_bytes: 67368
#define _USE_MATH_DEFINES

#include <vector>
#include <list>
#include <map>
#include <string>
#include <iostream>
#include <fstream>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <utility>
#include <ctgmath>
#include <queue>
#include <set>

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> pll;
const ll mod = 1000000007;
const ll inf = 10e17;
const ld eps = 10e-9;



ll solve(void);
ll gcd(ll x, ll y);

int main(void)
{
	while (solve())
	{
	}
	return 0;
}

ll mulmod(ll x, ll y)
{
	return (x * y) % mod;
}

ll submod(ll x, ll y)
{
	return (x - y + 100 * mod) % mod;
}

ll power(ll n, ll r)
{
	if ( r == 0 ) { return 1; }
	if ( r == 1 ) { return n; }
	if ( n == 0 ) { return 0; }
	if ( n == 1 ) { return 1; }

	if (r % 2 == 0)
	{
		ll y = power(n, r/2);
		return mulmod(y, y);
	}
	else
	{
		ll y = power(n, (r-1)/2);
		return n * mulmod(y, y) % mod;
	}
}

ll gcd(ll x, ll y)
{
	if (y == 1) { return 1;}
	if (x % y == 0) { return y; }
	return gcd(y, x % y);
}

vector<ll> perm;
vector<ll> inv;
void init_inv(ll m)
{
	perm.resize(m);
	inv.resize(m);
	
	perm[0] = 1;
	inv[0] = 1;

	for (ll i = 1; i < m; i++)
	{
		perm[i] = mulmod(perm[i-1], i);
	}
	
	for (ll i = 1; i < m; i++)
	{
		inv[i] = power(perm[i], mod - 2);
	}
}

ll ncr(ll n, ll r)
{
	// n (n-1) ... (n-r)
	if ( r == n || r == 0 ) { return 1; }

	ll ans = 1;
	//for (ll i = 0; i < r; i++)
	//	ans = mulmod(ans, n - i);

	return mulmod(perm[n], mulmod(inv[n-r], inv[r]));
}

ll solve(void)
{
	string s;
	cin >> s;
	s[0] ++;

	cout << s << endl;

	return 0;
}



Measured memory_bytes: 256
while True:
    a,b=map(int,input().split())
    sum1=0
    if a==0 and b==0:
        break
    for i in range(a):
        if sum1%2==0:
            sum2=0
            for j in range(b):
                if sum2%2==0:
                    print("#",end="")
                    sum2+=1
                else:
                    print(".",end="")
                    sum2+=1
            if sum2==b:
                print()
            sum1+=1
        else:
            sum2=0
            for j in range(b):
                if sum2%2==0:
                    print(".",end="")
                    sum2+=1
                else:
                    print("#",end="")
                    sum2+=1  
            if sum2==b:
                print()
            sum1+=1
    print()


Measured memory_bytes: 7004
using System;
using System.Linq;
using System.Collections.Generic;

namespace AtCoder
{
    class Takofes
    {
        public static void Main()
        {
            int N = int.Parse(Console.ReadLine());
            string str = Console.ReadLine();
            string[] stArrayData = str.Split(' ');
            var list = new List<int>();
            list = stArrayData.Select(s => int.Parse(s)).ToList();

            int answer = 0;

            while(list.Count > 1)
            {
                int a = list[0];
                list.RemoveAt(0);

                for(int j = 0; j < list.Count; j++)
                {
                    answer += a * list[j];
                }
            }

            Console.WriteLine(answer);
        }
    }
}


Measured memory_bytes: 13268
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;
using ll = long long;
using ld = long double;
using ii = pair<ll, ll>;
using vi = vector<ll>;
using vvi = vector<vi>;
using vii = vector<ii>;
using vvii = vector<vii>;

template<class T>
using min_heap = priority_queue<T, vector<T>, greater<T>>;
template<class TIn, class TOut = null_type>
using order_tree = tree<TIn, TOut, less<TIn>, rb_tree_tag,
	tree_order_statistics_node_update>;

constexpr int INF = 1000000010;
constexpr ll LLINF = 1000000000000000010LL;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	
	string S;
	cin >> S;
	int N = (int)S.length();

	ll ans = 1LL + N * (N + 1LL) / 2LL;
	vi cnt(26, 0LL);
	for (char c : S) {
		cnt[c - 'a']++;
		ans -= cnt[c - 'a'];
	}
	
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 720
import itertools


num_vertex, target = map(int, input().split(' '))

# ensure num_vertex >= 3
if num_vertex == 2:
    if target == 0:
        print("1")
        print("1 2")
    else:
        print("-1")

    exit(0)

edges = [(1, i) for i in range(2, num_vertex+1)]
appendable_edges = list(itertools.combinations(range(2, num_vertex+1), 2))

num_removal = len(appendable_edges) - target

if num_removal < 0:
    print("-1")
    exit(0)

edges.extend(appendable_edges[:num_removal])

print(len(edges))
for edge in edges:
    src, dest = edge
    print(src, dest)

exit(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;
//using P = pair<int, int>;

int main() {
    string s;
    cin >> s;
    rep(i,s.size()) s[i] = 'x';
    cout << s << endl;
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main()
{
    int A,B,x,y,z;
    scanf("%d %d",&A,&B);
    x=A+B;
    y=A-B;
    z=A*B;
    if(x>=y&&x>=z)
       {
           printf("%d\n",x);
       }
    else if(y>=x&&y>=z)
       {
           printf("%d\n",y);
       }
    else
       {
           printf("%d\n",z);
       }
       return 0;
}


Measured memory_bytes: 1736
import java.util.*;

public class Main {
    static long INF = 100100100100100118L;
    
    public static void main(String[] args) throws Exception {
        // Your code here!
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        
        // to: 隣接リスト(有向)
        List<long[]>[] to = new List[n];
        for (int i = 0; i < n; i++) {
            to[i] = new ArrayList<long[]>();
        }
        for (int i = 0; i < n-1; i++) {
            long p = sc.nextInt() - 1;
            long q = sc.nextInt() - 1;
            long dis = sc.nextInt();
            to[(int)p].add(new long[]{q, dis});
            to[(int)q].add(new long[]{p, dis});
        }
        
        int query = sc.nextInt();
        int start = sc.nextInt() - 1;
        
        // dist: startからの最短距離
        long[] dist = new long[n];
        Arrays.fill(dist, INF);
        dist[start] = 0;
        
        // ダイクストラ法: BFSで距離を配る。
        // (キューの先頭の点はそう来る他最短経路がないので最短距離が確定する)
        PriorityQueue<Point> que = new PriorityQueue<>();
        que.add(new Point(start, 0));
        while (!que.isEmpty()) {
            Point cur = que.poll();
            long p = cur.name;
            long dis = cur.dist;
            
            // distより大きいdisを持つ点からは配らせない
            if (dis > dist[(int)p]) continue;
            
            // // 確定したpとdis
            // System.out.println(p + " " + dis);
            
            // 子に「自分の距離 + p→qの距離」を配る
            for (long[] qData : to[(int)p]) {
                long q = qData[0];
                long PtoQ = qData[1];
                
                // 最短距離が更新される場合だけキューに入れる
                if (dis + PtoQ < dist[(int)q]) {
                    dist[(int)q] = dis + PtoQ;
                    que.add(new Point(q, dist[(int)q]));
                }
            }
        }
        // System.out.println(dist[0]);
        
        while (query-- > 0) {
            System.out.println(dist[sc.nextInt()-1] + dist[sc.nextInt()-1]);
        }
    }
}
    
class Point implements Comparable<Point> {
    long name;
    long dist;
     
    Point(long name, long dist) {
        this.name = name;
        this.dist = dist;
    }
    
    @Override
    public int compareTo(Point o) { // longでもint
        //重みの小さい順
        if (this.dist < o.dist) {
            return -1;
        } 
        return 1;
    }
}

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

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

    string s;
    cin >> s;

    int n = s.size();
    int z = 0, o = 0;
    for (int i = 0; i < n; i++) {
        if (s[i] == '0') {
            z++;
        } else {
            o++;
        }
    }

    cout << min(z, o) * 2 << "\n";
    return 0;
}

Measured memory_bytes: 1144
#include <iostream>
#include <cstdio>
#include <cstring>
#include <deque>
using namespace std;

typedef long long llt;

const int MaxN = 200000 + 5;

int N; llt C;
llt H[MaxN];
llt F[MaxN], G[MaxN];
int Que[MaxN], head = 1, tail = 0;

void init() {
  scanf("%d %lld", &N, &C);
  for (int i = 1; i <= N; ++i) scanf("%lld", &H[i]);
}

// k_{xy} (x > y)
inline double getk(int x, int y) {
  return 1.0 * (G[x] - G[y]) / (H[x] - H[y]);
}

inline void getg(int i) {
  G[i] = F[i] + H[i] * H[i];
}

void solve() {
  F[1] = 0; getg(1);
  Que[++tail] = 1;
  F[2] = F[1] + (H[1] - H[2]) * (H[1] - H[2]) + C; getg(2);
  Que[++tail] = 2;

  for (int i = 3; i <= N; ++i) {
    while (head < tail && getk(Que[head + 1], Que[head]) < 2 * H[i]) head++;

    int j = Que[head];
    F[i] = F[j] + (H[i] - H[j]) * (H[i] - H[j]) + C; getg(i);
    while (head < tail && getk(i, Que[tail]) < getk(Que[tail], Que[tail - 1])) tail--;
    Que[++tail] = i;
  }
  printf("%lld\n", F[N]);
}

int main() {
  init();
  solve();
  return 0;
}

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

// 包除原理と問題文の条件を組み合わせると、
// N= 2*N- binom(Nset, 2) を満たす自然数Nset が存在することが必要。
// 逆にそのような自然数Nset が存在するとき、問題文の条件を満たすように構成できる。
int main(){
  int N;
  cin >> N;
  
  int Nset= 2;
  while(Nset*(Nset-1) < 2*N){
    Nset++;
  }

  if(Nset*(Nset-1) != 2*N){
    cout << "No" << endl;
  }
  else{
    cout << "Yes" << endl;

    vector<set<int>> ans(Nset);
    int n_ins= 1;
    for(int s1=0; s1<Nset; s1++){
      for(int s2=s1+1; s2<Nset; s2++){
        ans.at(s1).insert(n_ins);
        ans.at(s2).insert(n_ins);
        n_ins++;
      }
    }

    cout << Nset << endl;
    for(auto S_k:ans){
      cout << S_k.size() <<" ";
      for(auto elem:S_k){
        cout << elem <<" ";
      }
      cout << endl;
    }
  }
}

Measured memory_bytes: 12860
#include <fstream>
#include <iostream>
#include <cmath>
#include <vector>
#include <queue>
#include <utility>
#include <algorithm>
using namespace std;

int cnt_sum_s(int n, int k, int s, int tmp_sum) {
  if (n == 0) {
    return (tmp_sum == s) ? 1 : 0;
  }

  int res = 0;
  for (int i = k+1; i < 10; i++) {
    res += cnt_sum_s(n-1, i , s, tmp_sum + i);
  }

  return res;
}

int main() {
  // ifstream cin("../test.txt");
  while (true) {
    int n,s;
    cin >> n >> s;
    if (!(n|s)) break;

    int res = cnt_sum_s(n, -1, s, 0);

    cout << res << endl;
  }
}

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

int main(){
	int n,num=0;
	scanf("%d",&n);
	int a[n+1];
	for(int i=1;i<=n;i++){
		scanf("%d",&a[i]);
	}
	for(int i=1;i<=n;i++){
		if(i%2==1){
			if(a[i]%2==1)num++;
		}
	}
	printf("%d",num);
	return 0;
} 

Measured memory_bytes: 1728
#include<bits/stdc++.h>
using namespace std;
 
int main(){
	int n,k;cin>>n>>k;
	vector<int> h(n);
	for(int i = 0; i < n; i++)
		cin>>h[i];
	vector<int> dp(n, INT_MAX);
	dp[0] = 0;
	dp[1] = abs(h[1] - h[0]);
	for(int i = 2; i < n; i++){
		for(int j = 1; j <= k; j++){
			if(j <= i){
				dp[i] = min(dp[i], dp[i-j] + abs(h[i] - h[i-j]));
			}
		}
 
	}
	cout<<dp[n-1]<<endl;
	return 0;
}

Measured memory_bytes: 1024
table = []

while True:
    temporary = []
    n, x = map(int, input().split())
    if n == 0 and x == 0:
        break
    else:
        temporary.append(n)
        temporary.append(x)
        table.append(temporary)

for i in range(len(table)):
    ans = 0
    for j in range( 1, table[i][0] + 1):
        for k in range(j + 1, table[i][0] + 1):
            for l in range(k + 1, table[i][0] + 1):
                if j + k + l == table[i][1]:
                    ans += 1
                    #print("{}+{}+{}".format(j, k, l))
    print(ans)



Measured memory_bytes: 5596
N,M = gets.split.map(&:to_i)
As = N.times.map{gets.chomp.to_s}
Bs = M.times.map{gets.chomp.to_s}
count = 0

Bs.each_with_index do |b,i|
    count += 1 if As[i].include?(b)
end

if count == M
    puts 'Yes'
else
    puts 'No'
end

Measured memory_bytes: 1788
#include<iostream>
#include<cmath>
#include<algorithm>
#include <cassert>
#include<string>
#include<vector>
#include <utility>
using namespace std;
int a = 0, b = 0, c = 0, d = 0, e[100][100] = { -1 }, f[10000], g[10000], h[10000], m[100] = { 0 }, counto = 0, x[100] = { 0 }, y = 0, z = 0;
long long ab[100000], abc = 0,abcd=0;
pair<int, int>manji[100], daburu[100];
char rikka, toka[50][50];
string saya, homu, kyok, mami[100], mado[100];
bool gg = false;
vector<char>uc;
vector<int>gachi;
int main() {
	cin >> saya;
	
	for (int i = 0; i < 4; i++) {
		if (saya[i] == '2') {
			counto++;
		}
	}
	cout << counto << endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll = long long;
using ld = long double;
const ll ATCODER_AMARI = 1000000007; //10^9 + 7
const ll INF = 10000000000000;
//階乗できるよ
ll kaizyo(ll k){
  ll sum = 1;
  for(int i = 1 ; i < k + 1; i++) {
    sum *= i;
    sum = sum % ATCODER_AMARI;
  }
  return sum;
}

int main() {
  string s; cin >> s;
  string ans;
  rep(i,s.size()){
    ans.push_back('x');
  }

  cout << ans << endl;
}



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

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

  vector<int> a(N);
  rep(i,N) cin >> a[i];

  vector<int> ans(N);
  rep(i,N) ans[a[i]-1] = i+1;

  rep(i,N) {
    cout << ans[i] << endl;
  }

  return 0;
}


Measured memory_bytes: 1664
n, m = map(int, input().split())
array = []
for i in range(n):
    array.append([int(k) for k in input().split()])
result = {}
for arr in array:
    for i, k in enumerate(arr):
        if i == 0:
            continue
        if k not in result:
            result[k] = 0
        result[k] += 1
res = 0
for i in result.items():
    if i[1] == n:
        res += 1
print(res)

Measured memory_bytes: 3064
n = int(input())

ac = 0
wa = 0
tle = 0
re = 0

for i in range(n):
  status = input()
  if status == 'AC':
    ac += 1
  elif status == 'WA':
    wa += 1
  elif status == 'TLE':
    tle += 1
  else:
    re += 1

print('AC x', ac)
print('WA x', wa)
print('TLE x', tle)
print('RE x', re)


Measured memory_bytes: 9072
#include<bits/stdc++.h>
using namespace std;
int main(){
  int k,s;cin>>k>>s;
  int ans=0;
  for(int i=0;i<=k;i++){
    for(int j=0;j<=k;j++){
      if(s-i-j>=0&&s-i-j<=k)ans++;
    }
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 256
// SeeAlso: https://atcoder.jp/contests/abc122/tasks/abc122_b

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

#define MAX 100000

typedef int _loop_int;
#define REP(i,n) for(int i = 0; i < n; i++)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a);i<(_loop_int)(b);++i)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1;i>=(_loop_int)(a);--i)

#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

#define CHMIN(a,b) a=min((a),(b))
#define CHMAX(a,b) a=max((a),(b))

int dp[101][4][4][4]; 
 
int main(){
 
    int N;
    cin >> N;
 
    dp[0][3][3][3] = 1;
 
    int mod = 1e9 + 7;
 
    for(int len = 0; len < N; len++){
        for(int c1 = 0; c1 < 4; c1++){
            for(int c2 = 0; c2 < 4; c2++){

                for(int c3 = 0; c3 < 4; c3++){
 
                    if(dp[len][c1][c2][c3] == 0) continue;
 
                    for(int a = 0; a < 4; a++){
 
                        if(a == 2 && c1 == 1 && c2 == 0) continue;
                        if(a == 2 && c1 == 0 && c2 == 1) continue;
                        if(a == 1 && c1 == 2 && c2 == 0) continue;
                        if(a == 2 && c1 == 1 && c3 == 0) continue;
                        if(a == 2 && c2 == 1 && c3 == 0) continue;
 
                        dp[len+1][a][c1][c2] += dp[len][c1][c2][c3];
                        dp[len+1][a][c1][c2] %= mod;
                    }
                }
            }
        }
    }
 
    int ans = 0;
    
    for(int c1 = 0; c1 < 4; c1++){
        for(int c2 = 0; c2 < 4; c2++){
            for(int c3 = 0; c3 < 4; c3++){
                ans += dp[N][c1][c2][c3];
                ans %= mod;
            }
        }
    }

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


Measured memory_bytes: 256