akhauriyash/Code-Regression huggingface dataset:
#define _USE_MATH_DEFINES 
#include<iomanip> 
#include<cmath>  
#include<iostream>
#include<fstream>
#include<vector>
#include<algorithm>
#include<numeric>
#include<bitset>
#include<map>
#include<unordered_map>
#include<set>
#include<unordered_set>
#include<queue>
#include<deque>
#include<stack>
using namespace std;
typedef long long ll;
#define repi(i,a,b) for(ll i = (ll)(a) ; i < (ll)(b) ; i++)
#define repd(i,a,b) for(ll i = (ll)(a) ; i > (ll)(b) ; i--)
#define rd(x) cin >> x
#define wr(x)  cout << x
#define wrln(x) cout << x << endl
#define wl() cout << endl
const ll MAX_10p5 = 100010;
const ll MAX_10p9 = 1000000010;
const ll MAX_10p18 = 1000000000000000010;
const ll MOD = 1000000007;
const ll m4x[4] = { 1,0,-1,0 };
const ll m4y[4] = { 0,1,0,-1 };
const ll m8x[8] = { 1,1,0,-1,-1,-1,0,1 };
const ll m8y[8] = { 0,1,1,1,0,-1,-1,-1 };
const ll m9x[9] = { 1,1,0,-1,-1,-1,0,1,0 };
const ll m9y[9] = { 0,1,1,1,0,-1,-1,-1,0 };

struct edge {
	ll from, to, cost;
	bool operator<(const edge& right) const {
		return cost < right.cost;
	}
};
struct point {
	ll x, y;
	bool operator<(const point& right) const {
		return x == right.x ? y < right.y : x < right.x;
	}
};

///////////////////////////////////////////////////////////////////////////////////////

ll N, W;
ll v[110], w[110];
ll dp[110][10010];

ll solv(ll i, ll j) {
	ll ret;
	if (i == N) return 0;
	if (dp[i][j]) return dp[i][j];
	if (j >= w[i]) ret = max(solv(i + 1, j), solv(i + 1, j - w[i]) + v[i]);
	else ret = solv(i + 1, j);
	return dp[i][j] = ret;
}

int main() {
	cin >> N >> W;
	repi(i, 0, N) {
		cin >> v[i] >> w[i];
	}
	ll ans = solv(0, W);
	wrln(ans);
	return 0;
}



Measured memory_bytes: 10276
#include <iostream>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <cmath>
#include <map>
#include <cmath>
#include <bitset>
#include <string>
#include <queue>
#include <sstream>

using namespace std;

#define int long long

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

    for(int i = -1000; i <= 1000; i++) {
        for(int j = -1000; j <= 1000; j++) {
            if(pow(i, 5) - pow(j, 5) == x) {
                cout << i << " " << j << endl;
                return 0; 
            }
        }
    }
}

Measured memory_bytes: 4052
package main

import (
    "fmt"
    "os"
)

// 答えが正なら1, 負なら-1, 0なら0を返す。
func solve(a, b int64) int {

    x := a * b
    switch {
    case x == 0:
        return 0
    case x < 0: // zeroをまたぐ
        return 0
    }

    // a,bは共に正もしくは共に負
    if a > 0 {
        return 1
    } else {
        num := b - a + 1
        if num%2 == 0 {
            return 1
        } else {
            return -1
        }
    }
}

func main() {

    var a, b int64
    fmt.Fscanf(os.Stdin, "%d %d\n", &a, &b)

    ans := solve(a, b)
    switch ans {
    case 1:
        fmt.Print("Positive\n")
    case -1:
        fmt.Print("Negative\n")
    default:
        fmt.Print("Zero\n")
    }
}


Measured memory_bytes: 512
N,A,B=map(int, input().split())

def f(n,a,b):
  count = 0
  
  for i in range(1, n+1):
    if a<=sum(map(int,str(i))) and sum(map(int,str(i)))<=b:
      count += i 
  return count

print(f(N,A,B))

Measured memory_bytes: 3060
#include<iostream>
#include<algorithm>
#include<math.h>
#include<vector>
#include<map>
#include<set>
#include<iomanip>

using namespace std;
using ll = long long;

const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;
const double PI = 4.0 * atan(1.0);

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, a, n) for (int i = a; i <= (n); ++i)

int main() {
    double A, B, H, M; cin >> A >> B >> H >> M;
    
    double thetaB = 2.0 * PI * M / 60.0;
    double thetaA = 2.0 * PI * (H / 12.0 + M / (60.0 * 12.0));
    double theta = abs(thetaB - thetaA);
    if (theta > PI) theta = 2.0 * PI - theta;
    
    // double c = sqrt(A * A + B * B - 2.0 * A * B * cos(theta));
    double c = pow(A * A + B * B - 2.0 * A * B * cos(theta), 0.5);

    cout << setprecision(18) << c << endl;
    return 0;
}


Measured memory_bytes: 4348
#include <iostream>
#include <algorithm>
#include <time.h>
#include <stack>
#include <string>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <cassert>

using namespace std;

const int N = 100005;
const int inf = 1000 * 1000 * 1000;
const int mod = 1000 * 1000 * 1000 + 7;

int n,a[N];
int answ , mark[N];

int main(){
    scanf("%d",&n);
    for(int i=1;i<=n;i++){
        int a;
        scanf("%d",&a);
        if(a == 0){
            answ++;
            mark[a]++;
            mark[a+1]++;
        }
        else{
            mark[a-1]++;
            mark[a]++;
            mark[a+1]++;
        }
    }
    for(int i=0;i<=N-2;i++) answ = max(answ , mark[i]);
    cout<<answ<<endl;
    return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#include <stdlib.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;
typedef vector<double> Vec;
typedef vector<Vec> Mat;
typedef pair<ll,ll> P;
typedef pair<double,ll> Pd;
typedef pair<double,double> PD;
typedef priority_queue<P,vector<P>,greater<P> > P_queue;
typedef priority_queue<Pd,vector<Pd>,greater<Pd> > Pd_queue;

const ll MOD=998244353;
const ll mod=1000000007;
const ll INF=1e15;
const double DEL=1e-6;


#define REP(i,a,b) for(int i=(int)a;i<(int)b;i++)
#define rep(i,n) REP(i,0,n)
#define pb push_back
#define mp make_pair
#define ALL(a) a.begin(),a.end()
#define SORT(a) sort(ALL(a))
#define U_ERASE(V) V.erase(unique(ALL(V)), V.end());
#define ADD(a,b) a=(a+b)%mod
#define MUL(a,b) a=(a*b)%mod

ll Solve(){
    ll N; cin>>N;
    ll ans=0;
    vector<P> A,B;
    rep(i,N){
        ll K,L,R; cin>>K>>L>>R; 
        ans+=min(L,R);
        if(L>R) A.pb(mp(K,L-R));
        else B.pb(mp(N-K,R-L));
    }
    ll a=A.size(), b=B.size();
    //cout<<a<<':'<<b<<endl;
    priority_queue<ll> Q,R;
    sort(ALL(A)); sort(ALL(B));
    reverse(ALL(A)); reverse(ALL(B));
    ll c=0;
    for(int i=a;i>0;i--){
        while(c<a){
            if(A[c].first<i) break; 
            Q.push(A[c].second);
            c++;
            if(c==a) break;
        }
        if(!Q.empty()){
            ans+=Q.top();
            Q.pop();
        }
    }
    c=0;
    for(int i=b;i>0;i--){
        while(c<b){
            if(B[c].first<i) break; 
            R.push(B[c].second);
            c++;
            if(c==b) break;
        }
        if(!R.empty()){
            ans+=R.top();
            R.pop();
        }
    }
    return ans;
}

int main(){
    ll T; cin>>T;
    vec a(T);
    rep(i,T) a[i]=Solve();
    rep(i,T) cout<<a[i]<<endl;
}

Measured memory_bytes: 8168
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int q = sc.nextInt();
		int[] l = new int[q];
		int[] r = new int[q];

		int max = 0;
		for(int i = 0; i < q; i++) {
			l[i] = sc.nextInt();
			r[i] = sc.nextInt();

			max = Math.max(max, l[i]);
			max = Math.max(max, r[i]);
		}

		boolean[] pnums = new boolean[max+1];
		for(int i = 2; i <= max; i++) {
			if(pnums[i] != false);
			for(int j = i+i; j <= max; j+=i) {
				pnums[j] = true;
			}
		}

		int cnt = 0;
		int[] cnts = new int[max+1];
		cnts[0] = 1;
		cnts[1] = 1;
		for(int i = 2; i <= max; i++) {
			if( pnums[i] == false && pnums[(i+1)/2] == false )
				cnt++;
			cnts[i] = cnt;
		}

		for(int i = 0; i < q; i++) {
			System.out.println(cnts[r[i]] - cnts[l[i]-1]);
		}
	}
}

Measured memory_bytes: 91772
#include <stdio.h>

int main(void){
    int a,b,c;
    
    scanf("%d %d %d",&a,&b,&c);
    
    if(a>b &&a>c)
        printf("%d\n",b+c);
    else if(b>a && b>c)
        printf("%d\n",a+c);
    else
        printf("%d\n",a+b);
}


Measured memory_bytes: 128
#include <string>
#include <iostream>
#include <math.h>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <map>
#include <set>
typedef long long ll;
const int mod=1e9+7;
#define lol(i,n) for(int i=0;i<n;i++)

using namespace std;
int n,a[110],s[110],sum=0;
int main() {
    cin >>n;
    lol(i,n){
        cin >>a[i];
        sum+=a[i];
        s[i]=sum/(i+1);
    }
    sort(s,s+n);
    cout << s[0] << endl;
}



Measured memory_bytes: 3168
//Lower

#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,x,y) for(int i=x;i<y;i++)
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) (a/__gcd(a, b)*b)
#define range(a) (a).begin(),(a).end()
#define pb push_back
const int inf = 2147483647;

int main (){
    int n;cin>>n;
    vector<int>h(n);
    int c=0,ans=0;
    rep(i,0,n){
        cin>>h[i];
        if(i!=0&&h[i]<=h[i-1]){c++;ans=max(c,ans);}
        if(i!=0&&h[i]>h[i-1])c=0;
    }
    cout << ans << endl;
    return 0;
}

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

#define MP make_pair
#define PB push_back
#define ALL(x)      (x).begin(),(x).end()
#define REP(i,n)    for(int i=0;i<(n);i++)
#define REP1(i,n)   for(int i=1;i<(n);i++)
#define REP2(i,d,n) for(int i=(d);i<(n);i++)
#define RREP(i,n)   for(int i=(n);i>=0;i--)
#define CLR(a)      memset((a),0,sizeof(a))
#define MCLR(a)     memset((a),-1,sizeof(a))
#define RANGE(x,y,maxX,maxY) (0 <= (x) && 0 <= (y) && (x) < (maxX) && (y) < (maxY))

typedef long long LL;
typedef unsigned long long ULL;
typedef vector<int> VI;
typedef vector<VI > VVI;
typedef vector<string> VS;
typedef vector<LL> VLL;
typedef pair<int,int> PII;

const int INF = 0x3f3f3f3f;
const LL INFL = 0x3f3f3f3f3f3f3f3fLL;
const double EPS = 1e-9;

const int DX[]={1,0,-1,0},DY[]={0,-1,0,1};



int main(){
    int h, w;
    cin >> h >> w;
    VS a(h);
    REP(i, h) {
        cin >> a[i];
    }

    REP(i, w+2) {
        cout << "#";
    }

    cout << "\n";

    REP(i, h) {
        cout << "#" << a[i] << "#" << endl;
    }

    REP(i, w+2) {
        cout << "#";
    }

    cout << "\n";

    return 0;
}



Measured memory_bytes: 256
#include "bits/stdc++.h"
#define ALL(x) x.begin(), x.end()
#define LEN(x) (int)x.size()
#define iostreamBooster() do{ cin.tie(nullptr); ios_base::sync_with_stdio(false); }while(0)
using namespace std;
typedef int64_t i64;
typedef pair<int,int> pii;
template<class A, class B>inline bool chmax(A &a, const B &b){return b>a ? a=b,1 : 0;}
template<class A, class B>inline bool chmin(A &a, const B &b){return b<a ? a=b,1 : 0;}
constexpr int INF = 0x3f3f3f3f;

void storeDivisor(vector<int> &dst, int n)
{
  for (int i = 1; i*i <= n; ++i) {
    if (n % i == 0) {
      dst.push_back(i);
      dst.push_back(n / i);
    }
  }
  return;
}

signed main()
{
  int N;
  int a[100010];

  cin >> N;
  for (int i = 0; i < N; ++i) cin >> a[i];

  vector<int> divisors;
  storeDivisor(divisors, a[0]);
  storeDivisor(divisors, a[1]);
  sort(ALL(divisors));
  divisors.erase(unique(ALL(divisors)), divisors.end());


  i64 ans = 1;

  for (int d : divisors) {
    const int cnt = count_if(a, a+N, [d](int a){ return a % d == 0; });
    if (cnt >= N-1) chmax(ans, d);
  }

  cout << ans << endl;

  return 0;
}



Measured memory_bytes: 640
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cstring>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <numeric>
#include <utility>
#include <iomanip>
#include <algorithm>
#include <functional>
using namespace std;

#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s << endl; }

long long N, K, X, Y;

int main() {
    cin >> N >> K >> X >> Y;
    long long res = N * X;
    if (N > K) res += (N - K) * (Y - X);
    cout << res << endl;
}
























Measured memory_bytes: 384
N=int(input())
B=list(map(int,input().split()))
A=[]
for i in range(N):
    if i==0:
        A.append(B[0])
    elif i==N-1:
        A.append(B[N-2])
    else:
        A.append(min(B[i-1],B[i]))
print(sum(A))

Measured memory_bytes: 3060
#include<bits/stdc++.h>
#define pf printf
#define sc(x) scanf("%d",&x);
#define scs(x) scanf("%s",x);
#define scl(x) scanf("%lld",&x);
#define rep(i,s,e) for(int i=s; i<=e; ++i)
#define dep(i,s,e) for(int i=s; i>=e; --i)
typedef long long ll;
using namespace std;
const double pi=acos(-1.0);
int main()
{
	double a,b,h,m;
	scanf("%lf%lf%lf%lf",&a,&b,&h,&m);
	pf("%.20lf\n",sqrt(a*a+b*b-2.0*a*b*cos(6.0*min(abs(m-h*5-m/12),60-abs(m-h*5-m/12))*pi/180)));
}


Measured memory_bytes: 4280
from collections import Counter
import sys


def main():
    data = list(input())
    # count_ind = defaultdict(tuple)

    for haba in range(2, 6):
        for i in range(len(data) - haba + 1):
            now_list = data[i:i+haba]
            count_list = Counter(now_list).values()
            if max(count_list) > haba // 2:
                print(i + 1, i + haba)
                sys.exit()

    print(-1, -1)


if __name__ == '__main__':
    main()

Measured memory_bytes: 49264
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
using namespace std;

const long long N = 1e6 + 17;
ll cnt, ans, lnt, n, l1, x, y;
pair<ll,ll>pr[N];
vector<ll>v,v2,v3;
map<ll,ll>mp;
bool used[N];
vector<string>sv;

int main()
{
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    cin >> x >> y;
    string s;
    cin >> s;
        s[y - 1] = tolower(s[y - 1]);
        cout << s;
}



Measured memory_bytes: 256
from math import floor
n,l,t=map(int,input().split())
li=[]
zero=0
for _ in range(n):
  x,w=map(int,input().split())
  #zero passing
  if w==1:
    zero+=(x+t)//l
    x1=(x+t)%l
  else:
    zero+=(x-t)//l
    x1=(x-t)%l
  li.append(x1)
zero%=n
li.sort()
li=li[zero:]+li[:zero]
for _ in range(n):
  print(li[_])

Measured memory_bytes: 8648
#include <iostream>
#include <string>
#include <vector>
#include <stack>
#include <map>
#include <set>
#include <algorithm>
#include <numeric>
#include <math.h>
#include <stdio.h>
#include <ctype.h>
#include <ios> 
#include <iomanip>
using namespace std;

#define N_MAX   (100000)
#define LL_MAX_NUM (1LL<<60)
#define INF 1e7

typedef long long ll;
typedef long long int lli;

int main() {
	int N, res, max;
	cin >> N;
    res = 0;
    for (int i = 0; i < N; i++) {
        int Hi;
        cin >> Hi;
        if (i == 0) {
            max = Hi;
        }else {
            if (max <= Hi) {
                max = Hi;
                res++;
            }
        }
    }
	cout << res+1 << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int a,b,s[3];
    while(~scanf("%d %d",&a,&b))
    {
        int x,y,z;
        s[0]=a-b;
        s[1]=a+b;
        s[2]=a*b;
        sort(s,s+3);
        printf("%d\n",s[2]);
    }
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<stack>/*** LIFO *** stack<type> var;
push(), top():to get data, pop():to remove, size(), empty() ***/
using namespace std;

#define Fp(I, STAT, END) for(int I = STAT; I < END; I++)
#define Fm(I, STAT, END) for(int I = STAT; I > END; I--)

void merge(int a1[], int a2[], int a[], int a1len, int a2len){
    int i = 0, j = 0;
    while(i < a1len || j < a2len){
        if(j >= a2len || (i < a1len && a1[i] < a2[j])){
	        a[i+j] = a1[i];
	        i++;
        }else{
	        a[i+j] = a2[j];
	        j++;
        }
    }
}

void mergeSort(int a[], int len){
    if(len > 1){
        int m = len / 2;
        int n = len - m;
        int a1[m], a2[n];
        Fp(i, 0, m) a1[i] = a[i];
        Fp(i, 0, n) a2[i] = a[m+i];
        mergeSort(a1, m);
        mergeSort(a2, n);
        merge(a1, a2, a, m, n);
    }
}

int main(){
    int N, K;
    cin >> N >> K;
    int H[N];
    Fp(i, 0, N) cin >> H[i];

    int len = sizeof(H) / sizeof(H[0]);
    mergeSort(H, len);
    
    long atack = 0;
    Fp(i, 0, N - K) atack += (long)H[i];
    cout << atack << endl;
}


Measured memory_bytes: 2560
#include "bits/stdc++.h"
using namespace std;

int main()
{
  int n,d,ans;
  ans=0;
  cin>>n>>d;
  vector<vector<int>> x(n,vector<int>(d));
  for(int i=0;i<n;i++)
  {
    for(int j=0;j<d;j++)
    {
      cin>>x.at(i).at(j);
    }
  }
  for(int i=0;i<n-1;i++)
  {
    for(int j=i+1;j<n;j++)
    {
      int disdis=0;
      int han;
      double dis;
      for(int k=0;k<d;k++)
      {
        disdis+=(x.at(i).at(k)-x.at(j).at(k))*(x.at(i).at(k)-x.at(j).at(k));
      }
      dis=sqrt(disdis);
      han=dis;
      if(dis==han)
        ans++;
    }
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 3724
import java.util.Scanner;
 
public class Main {
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int X=sc.nextInt();
    int Y=sc.nextInt();
    if(Y%2==0 && 2*X<=Y && Y<=4*X) {
    	System.out.println("Yes");
    }else {
    	System.out.println("No");
    }
  }
}

Measured memory_bytes: 35772
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <cstring>
#include <cctype>
#include <cmath>
#include <stack>
#include <queue>
#include <vector>
#include <set>
#include <map>
#include <list>
#include <stdio.h>
#include <string.h>
#include <cstdlib>
#include <math.h>
#include <bitset>
#include <iterator>
#include <iomanip>
#include <sstream>
#include <numeric>
#define INF 2000000000
using namespace std;
int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};
long long gcd(long long a,long long b){if(a%b==0){return b;}else return gcd(b,a%b);}
long long lcm(long long a,long long b){if(a==0){return b;} return a/gcd(a,b)*b;}
#define MOD 1000000007
#define sym cout<<"---------"<<endl;
#define ll long long
#define PL pair<long long, long long>
#define P pair<int,int>
#define mk make_pair
#define en endl
#define WHITE 1
#define BLACK 2
#define GRAY 1
#define RE return 0
#define int ll

int a[105];

signed main(){
  int  n; cin>>n;
  int mid=0;
  int sum=0;
  for(int i=0; i<n; i++){
    cin>>a[i];
    sum+=a[i];
  }
  
  mid=sum/n;
  int cnt=0;
  for(int i=0; i<n; i++){
    cnt+=powf(abs(a[i]-mid),2);
  }
  int cnt2=0;
  for(int i=0; i<n; i++){
    cnt2+=powf(abs(a[i]-(mid+1)), 2);
  }
  cout<<min(cnt, cnt2)<<en;
}


Measured memory_bytes: 256
#include<algorithm>
#include<cstdio>
#include<iostream>
#include<cstring>
#include<cmath>
#include<map>
#include<queue>
#include<set>
#include<sstream>
#include<stack>
#include<string>
#include<vector>
using namespace std;
string s,t;
int main(){
	cin>>s>>t;
	for(int i=0;i<s.size();i++){
		s=s[s.size()-1]+s.substr(0,s.size()-1);
		if(s==t){
			cout<<"Yes"<<endl;
			return 0;
		}
	}
	cout<<"No"<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define LL long long
#define Max 100005
#define Mod 1e9+7
const LL mod=1e9+7;
const LL inf=1e10;
using namespace std;
int main()
{
	/*int n;
	LL a[Max];
	scanf("%d",&n);
	for(int i=0;i<n;i++)
		scanf("%lld",&a[i]);
	sort(a,a+n);
	int t;
	while(a[1]!=inf)
	{
		for(int i=1;a[i]!=inf && i<n;i++)
		{
			t=a[i]%a[0];
			if(t==1)
				break;
			if(t==0)
				a[i]=inf;
			else
				a[i]=t;
		}
		if(t==1)
		{
			printf("%d\n",1);
			return 0;
		}
		sort(a,a+n);
	}
	printf("%lld\n",a[0]);
    return 0;*/
    int n;
    int a[Max];
    scanf("%d",&n);
    for(int i=0;i<n;i++)
		scanf("%d",&a[i]);
	int ans=a[0];
	for(int i=1;i<n;i++)
		ans=min(ans,__gcd(ans,a[i]));
	printf("%d\n",ans);
}


Measured memory_bytes: 640
X,K,D=map(int,input().split())
XX=abs(X)
q=XX//D
mod=XX%D
if K<=q:
  print(XX-K*D)
else:
  KK=K-q
  KKK=KK%2
  if KKK==0:
    print(mod)
  else:
    print(D-mod)

Measured memory_bytes: 9148
X, K, D = map(int,input().split())
res = 0
X = abs(X)
if X >= K * D:
    res = X - K * D
else:
    i = X // D
    j = K - i
    if j % 2 == 0:
        res = X - D * i
    else:
        res = X - D * (i + 1)
print(abs(res))

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

#define PI 3.14159265358979323846264338327950288419

using namespace std;

int n, m, v, p;
int a[100005];

bool ok(int c){
	// can c go through?
	assert(c > p); // if c <= p it's trivial to get it through
	int remain = max(0, v - p); // first vote for top (p-1) and self
	// assume tie break by index for now
	int compete = max(0, remain - (n - c)); // then vote for those behind
	int a_new = a[c] + m; // all m judges vote for me!
	long long remain_votes = 1LL * compete * m;
	for(int i = p; i < c; i++){
		if(a_new < a[i]){
			return false;
		}
		remain_votes -= (a_new - a[i]);
	}
	return (remain_votes <= 0);
}

int main(){
	scanf("%d %d %d %d", &n, &m, &v, &p);
	for(int i = 1; i <= n; i++){
		scanf("%d", &a[i]);
	}
	sort(a + 1, a + n + 1);
	reverse(a + 1, a + n + 1);
	
	int l = p, r = n + 1;
	while(r - l > 1){
		int c = (l + r) >> 1;
		if(ok(c)){
			l = c;
		}else{
			r = c;
		}
	}
	// fix tie break issue
	while(l < n && a[l] == a[l + 1]){
		l++;
	}
	printf("%d\n", l);
	return 0;
}

Measured memory_bytes: 640
#include<iostream>
#include<algorithm>
using namespace std;
static const int MAX = 200000;

int main(){
	int R[MAX], n;

	cin >> n;
	for (int i = 0; i < n; i++) cin >> R[i];

	int maxv = R[1] - R[0];
	int minv = R[0];

	for (int i = 1; i < n; i++) {
		maxv = max(maxv, R[i] - minv);
		minv = min(minv, R[i]);
	}

	cout << maxv << endl;

	return 0;
}


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

int main(void){
   
    int W,a,b;
    cin >> W >> a >> b;
   
    if(a > b){
       swap(a,b);
    }
    
    if(a + W < b){
        cout << b - (a + W) << endl;
    }
    else{
        cout << 0 << endl;
    }
}

Measured memory_bytes: 3516
# coding: utf-8
import collections

s = raw_input()
qn = int(raw_input())
qs = [raw_input().split() for _ in xrange(qn)]

direction = 1
deq = collections.deque(s)
#print deq, '<_>'[direction+1]
for q in qs:
    if q[0] == '1':
        direction *= -1
    else:
        _, fi, ci = q
        fi = -1 if fi == '1' else +1
        if direction * fi == -1:
            deq.appendleft(ci)
        else:
            deq.append(ci)
    #print deq, '<_>'[direction+1]

#print deq, '<_>'[direction+1]
ans = None
ln = len(deq)
if direction == 1:
    ans = ''.join(deq.popleft() for _ in xrange(ln))
else:
    ans = ''.join(deq.pop() for _ in xrange(ln))
print ans


Measured memory_bytes: 47120
n = int(input())
a = list(map(int, input().split()))
a = sorted(a)
res = 0
for i in range(n):
  for j in range(i + 1, n):
    for k in range(j + 1, n):
      if len(set([a[i], a[j], a[k]])) < 3:
        continue
      if a[i] + a[j] > a[k]:
        res += 1
print(res)

Measured memory_bytes: 73984
#include "bits/stdc++.h"
using namespace std;
int main(){
    string a,b,c;
    cin>>a>>b>>c;
    char dif ='A'-'a';
    a[0]+=dif;b[0]+=dif;c[0]+=dif;
    cout<<a[0]<<b[0]<<c[0]<<endl;
}

Measured memory_bytes: 256
def main():
    n = int(input())
    max, dif = 0, 0
    for i in range(1, 10000):
        s = i * (i + 1) // 2
        if s >= n:
            max = i
            dif = s - n
            break
    [print(i) for i in range(1, max + 1) if i != dif]

if __name__ == '__main__':
    main()


Measured memory_bytes: 9220
#define IOS ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#include<bits/stdc++.h>
using namespace std;
	typedef long long ll;
	const int maxn=200050;
	ll po[maxn];
	ll a[maxn],b[maxn];
	map<ll,ll>m;
	int main() {
		IOS
		int n;
		cin>>n;
		for(int i=1;i<=n;i++){
			cin>>a[i];
			b[i]=a[i]-i;
			m[-b[i]]+=1;
		}
		ll ans=0;
		for(int i=1;i<=n;i++){
			ll t=b[i]+2*i;
			if(m[t])
				ans+=m[t];
		}
		cout<<ans<<endl;
		return 0;
	}

Measured memory_bytes: 29480
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define int long long
const int mod =1000000007;
const int INF = 1e18;
signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n,p,ecount=0;
    cin>>n>>p;
    vector<int>a(n);
    for(int i=0;i<n;i++){
        cin>>a[i];
        if(a[i]%2==0){ecount++;}
    }
    if(p==1&&ecount==n){cout<<0;return 0;}
    else if(p==0&&ecount==n){cout<<(int)pow(2,n);return 0;}
    else{cout<<(int)pow(2,n-1);}
}

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

int dp[22][11][202];    // dp[i][j][k]: i番目までの要素でj個用いて合計kとなるような組み合わせ

void solve(int n, int k, int s) {
    for (int i = 0; i <= n; i++) {
        for (int j = 0; j <= k; j++) {
            for (int l = 0; l <= s; l++) {
                dp[i][j][l] = 0;
            }
        }
    }
    dp[0][0][0] = 1;
    for (int i = 1; i <= n; i++) {
        dp[i][1][i] = 1;
    }
    for (int i = 1; i <= n; i++) {
        for (int j = 0; j <= k; j++) {
            for (int l = 0; l <= s; l++) {
                dp[i][j][l] += dp[i - 1][j][l];
                if (l - i >= 0 && j > 1) dp[i][j][l] += dp[i - 1][j - 1][l - i];
            }
        }
    }
    cout << dp[n][k][s] << endl;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N, K, S;
    while (true) {
        cin >> N >> K >> S;
        if (N == 0 && K == 0 && S == 0) break;
        solve(N, K, S);
    }
    return 0;
}


Measured memory_bytes: 3188
import java.util.*;

public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);

        int h = sc.nextInt();
        int w = sc.nextInt();
        int k = sc.nextInt();
        boolean[][] field = new boolean[h][w];

        for(int i = 0; i < h; i++){
            String str = sc.next();
            for(int j = 0; j < w; j++){
                field[i][j] = str.charAt(j) == '#';
            }
        }

        int ans = 0;

        for(int hbit = 0; hbit < (1 << h); hbit++){
            for(int wbit = 0; wbit < (1 << w); wbit++){

                int count = 0;

                for(int i = 0; i < h; i++){
                    for(int j = 0; j < w; j++){
                        if(((hbit >> i) & 1) == 0 && ((wbit >> j) & 1) == 0 && field[i][j]){
                            count++;
                        }
                    }
                }

                if(count == k){
                    ans++;
                }

            }
        }

        System.out.println(ans);

    }
}

Measured memory_bytes: 35624
use std::io::*;
use std::str::FromStr;

pub fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

use std::cmp::{max, min};
use std::collections::HashSet;

fn main() {
    let a: usize = read();
    let b: usize = read();
    let k: usize = read();
    let mut anss: HashSet<usize> = HashSet::new();

    for i in a..min(a + k, b + 1) {
        anss.insert(i);
    }
    for i in (max(a, b + 1 - k)..b + 1).rev() {
        anss.insert(i);
    }

    let mut uniq: Vec<usize> = anss.into_iter().collect();
    uniq.sort();
    for i in uniq {
        println!("{}", i);
    }
}


Measured memory_bytes: 4352
#include<iostream>
#include<stdio.h>
#include<math.h>
using namespace std;

#define MAX 256

int main(void){
	
	int r, c;

	scanf("%d%d", &r, &c);
	
	int a[r + 1][c + 1] = { 0 };

	for (int i = 0; i <= r; i++){
		for (int j = 0; j <= c; j++){
			a[i][j] = 0;
		}
	}

	for (int i = 0; i < r; i++){
		for (int j = 0; j < c; j++){
			scanf("%d", &a[i][j]);
		}
	}

	for (int i = 0; i < r; i++){
		for (int j = 0; j < c; j++){
			a[i][c] += a[i][j];
		}
	}

	for (int i = 0; i < c; i++){
		for (int j = 0; j < r; j++){
			a[r][i] += a[j][i];
		}
	}

	for (int i = 0; i < r; i++){
		a[r][c] += a[i][c];
	}

	for (int i = 0; i <= r; i++){
		for (int j = 0; j < c; j++){
			printf("%d ", a[i][j]);
		}
		printf("%d\n", a[i][c]);
	}

	return 0;
}

Measured memory_bytes: 3220
#include<stdio.h>
#include<string.h>
int main(){
	int r=0,a[4],b[2],i,s=100,nf;
	scanf("%d%d%d%d%d%d",&a[0],&a[1],&a[2],&a[3],&b[0],&b[1]);
	for(i=0;i<4;i++){
		if(s>=a[i]){
			s=a[i];
			nf=i;
		}
	}
	for(i=0;i<4;i++){
		if(i!=nf){
			r+=a[i];
		}
	}
	if(b[0]>b[1]){
		r+=b[0];
	}else{
		r+=b[1];
	}

	printf("%d\n",r);
	return 0;
}

Measured memory_bytes: 2708
#include<stdio.h>
int main()
{
	int n;
	scanf("%d", &n);
	int i, j;
	long long int a[200005];
	for (i = 0; i < n; i++)
		scanf("%lld", &a[i]);
	long long int dp[200005][3];
	long long int min = -100000000000000000;
	dp[0][0] = a[0];
	dp[0][1] = dp[0][2] = min;
	dp[1][1] = a[1];
	dp[1][0] = dp[1][2] = min;
	for (i = 2; i < n; i++)
	{
		for (j = 0; j < 3; j++)
		{
			if (dp[i - 2][j] > min)
				dp[i][j] = dp[i - 2][j] + a[i];
			else
				dp[i][j] = min;
		}
		if (i > 2)
		{
			for (j = 0; j < 2; j++)
				if (dp[i - 3][j] > min && dp[i][j + 1] < dp[i - 3][j] + a[i])
					dp[i][j + 1] = dp[i - 3][j] + a[i];
		}
		else
		{
			if (dp[i][2] < a[i])
				dp[i][2] = a[i];
		}
		if (i > 3)
		{
			if (dp[i - 4][0] > min && dp[i][2] < dp[i - 4][0] + a[i])
				dp[i][2] = dp[i - 4][0] + a[i];
		}
	}
	long long int ans;
	if (n % 2 > 0)
	{
		ans = dp[n - 3][0];
		if (ans < dp[n - 2][1])
			ans = dp[n - 2][1];
		if (ans < dp[n - 1][2])
			ans = dp[n - 1][2];
	}
	else
	{
		ans = dp[n - 2][0];
		if (ans < dp[n - 1][1])
			ans = dp[n - 1][1];
	}
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 7984
#include <cstdio>

int main() {
  int n;
  scanf("%d", &n);
  for (int i=0;i<n;i++) {
    int y, m, d, cnt = 1;
    scanf("%d %d %d", &y, &m, &d);
    if (y % 3 == 0) cnt += 20*(10-m)+(20-d);
    else {
      cnt += 19+(m&1)-d;
      while (++m <= 10) cnt += 19+(m&1);
    }
    while (++y < 1000) {
      if (y % 3 == 0) cnt += 10*20;
      else cnt += 5*20 + 5*19;
    }
    printf("%d\n", cnt);
  }
  return 0;
}

Measured memory_bytes: 2720
#include <iostream>
#include <string>
#include <algorithm>
#include <math.h>
#include <set>
using namespace std;
typedef long long ll;
#define rep(i,s,n)for(int i = s;i<n;i++)
#define repe(i,s,n)for(int i = s;i<=n;i++)

int main() {
	ll A, B, C, D; cin >> A >> B >> C >> D;
	ll cnt = 0;
	repe(i, 0, 100) {
		if (A < i && B >= i && C < i && D >= i) {
			cnt++;
		}
	}
	cout << cnt << endl;
	return 0;
}

Measured memory_bytes: 256
n=int(input())
s=input()

while True:
    cum=[0]*(len(s)+1)
    for i,c in enumerate(s):
        cum[i+1]=cum[i]-1 if c==')' else cum[i]+1
    min_=min(cum)
    if min_<0:
        s='('*abs(min_)+s
        continue
    r=cum[-1]
    if r>0:
        s=s+')'*r
        continue
    print(s)
    exit()

Measured memory_bytes: 3064
#include <iostream>

int main() {
    std::ios::sync_with_stdio(false);

    long long n;
    std::cin >> n;

    int cnt = 0;
    long long cur = 100;
    while (cur < n) {
        ++cnt;
        cur = (long long)((double)cur * 1.01);
    }
    std::cout << cnt << std::endl;
    return 0;
}


Measured memory_bytes: 3660
#! /usr/bin/python3

a = int(input())
b = int(input())
c = int(input())
d = int(input())
e = int(input())
k = int(input())

l = [a, b, c, d, e]
def main():
    for i in range(0, 4):
        for j in range(i+1, 5):
            if l[j] - l[i] > k:
                print(":(")
                return
    print("Yay!")

main()







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

d = {}
for i in range(N):
  S = input()
  if S in d:
    d[S] += 1
  else:
    d[S] = 1

n = list(d.values())
n.sort()
max_n = n[-1]
ans = []
for k in d:
  if d[k] == max_n:
    ans.append(k)

ans.sort()
print(*ans, sep='\n')

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


#define li          long long int
#define rep(i,to)   for(li i=0;i<((li)(to));i++)
#define repp(i,start,to)    for(li i=(li)(start);i<((li)(to));i++)
#define pb          push_back
#define sz(v)       ((li)(v).size())
#define bgn(v)      ((v).begin())
#define eend(v)     ((v).end())
#define allof(v)    (v).begin(), (v).end()
#define dodp(v,n)       memset(v,(li)n,sizeof(v))
#define bit(n)      (1ll<<(li)(n))
#define mp(a,b)     make_pair(a,b)
#define rin rep(i,n)
#define EPS 1e-12
#define ETOL 1e-8
#define MOD 1000000007
typedef pair<li, li> PI;

#define INF bit(60)

#define DBGP 1


#define idp if(DBGP)
#define F first
#define S second
#define p2(a,b)     idp cout<<a<<"\t"<<b<<endl
#define p3(a,b,c)       idp cout<<a<<"\t"<<b<<"\t"<<c<<endl
#define p4(a,b,c,d)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<endl
#define p5(a,b,c,d,e)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<endl
#define p6(a,b,c,d,e,f)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<endl
#define p7(a,b,c,d,e,f,g)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<endl
#define p8(a,b,c,d,e,f,g,h)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<endl
#define p9(a,b,c,d,e,f,g,h,i)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<"\t"<<i<<endl
#define p10(a,b,c,d,e,f,g,h,i,j)        idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<"\t"<<i<<"\t"<<j<<endl
#define foreach(it,v)   for(__typeof((v).begin()) it=(v).begin(); it!=(v).end(); ++it)
#define p2p(x)      idp p2((x).F, (x).S)
#define dump(x,n)   idp{rep(i,n){cout<<x[i]<<" ";}puts("");}
#define dump2(x,n)  idp{rep(i,n){cout<<"["<<x[i].F<<" , "<<x[i].S<<"] ";}puts("");}
#define dumpi(x)    idp{foreach(it, x){cout<<(*it)<<" ";}puts("");}
#define dumpi2(x)   idp{foreach(it, x){cout<<"["<<(it)->F<<" , "<<(it)->S<<"] ";}puts("");}

#define read2d(a,w,h)   rep(i,h)rep(j,w)cin>>a[i][j]
#define dump2d(a,w,h)   rep(i,h){rep(j,w)cout<<a[i][j]<<" ";puts("");}

typedef pair<li, li> PI;

li sum_black[200200];
li sum_white[200200];

int main() {
    li n;
    string s;
    cin >> n;
    cin >> s;
    sum_black[0] = 0;
    sum_white[0] = 0;

    rep(i, n) {
        sum_black[i + 1] = sum_black[i] + (s[i] == '#' ? 1 : 0);
        sum_white[i + 1] = sum_white[i] + (s[i] == '.' ? 1 : 0);
    }

    li res = INF;
    rep(i, n + 1) {
        li tres = sum_black[i] + (sum_white[n] - sum_white[i]);
        res = min(res, tres);
    }
    cout << res << endl;


    return 0;
}

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

int main()
{
    vector<int> prime;
    int pnum = 0;
    for(int i = 2; i < 1000; i++){
        bool f = true;
        for(int j = 0; j < pnum; j++){
            if(i % prime[j] == 0) f = false;
        }
        if(f){
            prime.push_back(i);
            pnum++;
        }
    }
    for(int i = 1000; i < 100007; i++){
        bool f = true;
        for(int j = 0; j < pnum; j++){
            if(i % prime[j] == 0) f = false;
        }
        if(f){
            prime.push_back(i);
        }
    }
    bool ifprime[100007];
    fill(ifprime, ifprime + 100005, false);
    int n = prime.size();
    for(int i = 0; i < n; i++){
        ifprime[prime[i]] = true;
    }
    int ans[100007] {0};
    for(int i = 3; i < 100005; i++){
        ans[i] = ans[i - 1];
        if(ifprime[i] && ifprime[i / 2 + 1]) ans[i]++;
    }
    
    int q;
    cin >> q;
    int l[100007], r[100007];
    for(int i = 0; i < q; i++){
        cin >> l[i] >> r[i];
        cout << ans[r[i]] - ans[l[i] - 1] << endl;
    }
}

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

int main(){
  double left,light;
  int ans_left[4]={0},ans_light[4]={0};
  while(cin >> left){
    cin >> light;
    if(left >= 1.1) ans_left[0]++;
    else if(left >= 0.6) ans_left[1]++;
    else if(left >= 0.2) ans_left[2]++;
    else ans_left[3]++;
    if(light >= 1.1) ans_light[0]++;
    else if(light >= 0.6) ans_light[1]++;
    else if(light >= 0.2) ans_light[2]++;
    else ans_light[3]++;
  }
  for(int i=0;i<4;i++){
    cout << ans_left[i] << " " << ans_light[i] << endl;
  }
}

Measured memory_bytes: 1224
sx, sy, tx, ty = map(int, input().split())

yoko = tx - sx
tate = ty - sy

ans1 = ""
ans2 = ""

ans2 += "LU"

for i in range(tate):
    ans1 += "U"
    ans2 += "U"
for i in range(yoko):
    ans1 += "R"
    ans2 += "R"

ans2 +="RDRD"

for i in range(tate):
    ans1 += "D"
    ans2 += "D"
for i in range(yoko):
    ans1 += "L"
    ans2 += "L"

ans2 += "LU"

print(ans1 + ans2)



Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxN = 2 * (int)1e5 + 10;
int a[maxN];
int n;
ll s[maxN];
ll mn = (ll)1e18;
void go(int l, int i, int r) {
    if (l <= 0 || r >= n || l >= n || r <= 0) return;
    ll f[4];
    f[0] = s[l];
    f[1] = s[i] - s[l];
    f[2] = s[r] - s[i];
    f[3] = s[n] - s[r];
    if (f[0] <= 0 || f[1] <= 0 || f[2] <= 0 || f[3] <= 0) return;
    ll ans = 0;
    for (int i = 0; i < 4; i++) {
        for (int j = 0; j < 4; j++) {
            ans = max(ans, f[i] - f[j]);
        }
    }
    mn = min(mn, ans);
}
int main(){
    ios_base::sync_with_stdio(false);
    //freopen("input.txt", "r", stdin);
    cin >> n;
    for (int i = 1; i <= n; i++) {
        cin >> a[i];
        s[i] = s[i - 1] + a[i];
    }
    int l = 1;
    int r = 3;
    for (int i = 2; i <= n - 2; i++) {
        while (l < i && 2 * s[l] < s[i]) l++; l--;
        while (r < n && 2 * (s[r] - s[i]) < s[n] - s[i]) r++; r--;
        for (int i1 = -1; i1 <= 1; i1++) {
            for (int i2 = -1; i2 <= 1; i2++) {
                go(l + i1, i, r + i2);
            }
        }
        if (l > 1) l--;
        if (r > 1) r--;
    }
    cout << mn;
	return 0;
}


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

using namespace std;

int main()
{
	int n;
	cin >> n;
	int mi = 1000000000, ma = 0;
	for (int i = 0; i < n;i++)
	{
		int a;
		cin >> a;
		ma = max(ma, a);
		mi = min(mi, a);
	}
	cout << ma - mi << endl;
	return 0;
}


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

#define int long long
const long long INF = (long long)1e18;

const int MAX_V = 31;
	
void dijkstra(int s, vector<vector<vector<double>>> &d, vector<vector<vector<vector<pair<pair<int,pair<int,int>>, double>>>>> &G){
	priority_queue<pair<double,pair<int,pair<int,int>>>,vector<pair<double,pair<int,pair<int,int>>>>,greater<pair<double,pair<int,pair<int,int>>>>> q;
	
	int n = G.size();
	
	d.resize(n, vector<vector<double>>(n+1, vector<double>(MAX_V, INF+10)));
	
	d[s][n][0] = 0;
	
	q.push(make_pair(0,make_pair(s,make_pair(n,0))));
	
	while(!q.empty()){
		pair<double,pair<int,pair<int,int>>> p = q.top();q.pop();
		pair<int,pair<int,int>> pp = p.second;
		int v1 = pp.first;
		int v2 = pp.second.first;
		int v3 = pp.second.second;
		
		if(d[v1][v2][v3] < p.first) continue;
		
		// for()
		
		for(pair<pair<int,pair<int,int>>,double> e : G[v1][v2][v3]){
			int e1 = e.first.first;
			int e2 = e.first.second.first;
			int e3 = e.first.second.second;
			
			if(d[e1][e2][e3] > d[v1][v2][v3] + e.second){
				d[e1][e2][e3] = d[v1][v2][v3] + e.second;
				q.push(make_pair(d[e1][e2][e3], e.first));
			}
		}
	}	
}

signed main(){
	cout<<fixed<<setprecision(10);
	
	while(true){
		int n, m;
		int s, g;
		double ans = INF + 10;
		vector<vector<vector<double>>> d;
		vector<vector<pair<int,pair<int,int>>>> F;
		vector<vector<vector<vector<pair<pair<int,pair<int,int>>, double>>>>> G;
		cin>>n>>m;
		
		if(!n && !m) break;
		
		cin>>s>>g;
		
		s--, g--;
		
		F.resize(n);
		G.resize(n, vector<vector<vector<pair<pair<int,pair<int,int>>,double>>>>(n+1, vector<vector<pair<pair<int,pair<int,int>>,double>>>(MAX_V)));
		
		for(int i = 0; i < m; i++){
			int x, y, d, c;
			
			cin>>x>>y>>d>>c;
			
			x--, y--;
			
			F[x].push_back({y, {c, d}});
			F[y].push_back({x, {c, d}});
		}
		
		for(int i = 0; i < n; i++){
			for(int o = 0; o <= n; o++) {
				for(int j = 0; j < F[i].size(); j++){
					for(int k = 0; k < MAX_V; k++){
						for(int l = -1; l <= 1; l++){
							if(k+l <= 0 || k+l > F[i][j].second.first) continue;
							if(o == F[i][j].first) continue;
							
							if(n == o && k+l != 1) continue;
							
							G[i][o][k].push_back({{F[i][j].first,{i,k+l}}, (double)F[i][j].second.second/(k+l)});
						}
					}
				}
			}
		}
		
		dijkstra(s, d, G);
		
		for(int i = 0; i < d[g].size(); i++){
				ans = min(ans, d[g][i][1]);
		}
		
		if(ans >= INF) cout<<"unreachable"<<endl;
		else cout<<ans<<endl;
		
	}
	return 0;
}




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

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(NULL), cout.tie(NULL);

    int k, x;
    cin >> k >> x;

    if(k * 500 >= x)
        cout << "Yes\n";
    else
        cout << "No\n";

    return 0;
}


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

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef pair<int, int> P;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()

int di[4] = {1, 0, -1, 0};
int dj[4] = {0, 1, 0, -1};



int main(){
  int h, w; cin >> h >> w;
  int c_h, c_w; cin >> c_h >> c_w;
  c_h--;
  c_w--;
  int d_h, d_w; cin >> d_h >> d_w;
  d_h--;
  d_w--;
  char s[h][w];
  rep(i, h)rep(j, w) cin >> s[i][j];
  deque <P> q;
  int bfs[h][w];
  rep(i, h)rep(j, w) bfs[i][j] = -1;
  bfs[c_h][c_w] = 0;
  q.push_front(P(c_h, c_w));
  while (q.size() > 0){
    int i = q.front().first;
    int j = q.front().second;
    q.pop_front();
    int d = bfs[i][j];
    rep(v, 4){
      int ni = i + di[v];
      int nj = j + dj[v];
      if (ni < 0|| ni >= h || nj < 0 || nj >= w) continue;
      if (s[ni][nj] == '#')continue;
      if (bfs[ni][nj] <= d && bfs[ni][nj] > -1)continue;
      bfs[ni][nj] = d;
      q.emplace_front(P(ni, nj));
    }
    for (int mi = -2; mi <= 2; mi++){
      for (int mj = -2; mj <= 2; mj++){
        int ni = i + mi;
        int nj = j + mj;
        if (ni < 0 || ni >= h||nj < 0 || nj >= w)continue;
        if (s[ni][nj] == '#') continue;
        if (bfs[ni][nj] <= d+1 && bfs[ni][nj] > -1) continue;
        bfs[ni][nj] = d+1;
        q.emplace_back(P(ni, nj));
      }
    }
  }
  cout << bfs[d_h][d_w] << endl;
}

Measured memory_bytes: 8452
### SNIPPET
  # n = gets.split.map(&:to_i)
  # array = n.times.map { gets.split.map(&:to_i) }
  # [].all?(&:even?)
  # a = [*1..m].repeated_combination(n).to_a
  # [1,2,3,4,5].select { |num| num.even? }  # => [2, 4]
  # ["a","a","b"].group_by(&:itself).map{|k,v| [k, v.count]}.to_h #=> {"a"=>2, "b"=>1}
  # 切り捨て: .floor(2).to_f ,切り上げ： .ceil(2).to_f,四捨五入: round(2)
  # 3.upto(6) do |i|, 6.downto(3) do |i|
  # 公約数125.gcd(100)、公倍数125.lcm(100)
  # PI = Math::PI
  # 高さ = a * Math.sin(w / 180.0 * Math::PI), 底辺 = a * Math.cos(w / 180.0 * Math::PI)
  # def chmax(a, b) a > b ? a : b end
  # INF = Float::INFINITY
  # def chmin(a, b) a < b ? a : b end

a = gets.to_i

puts a + a * a + a * a * a


Measured memory_bytes: 14400
N = int(input())
 
t_prev, x_prev, y_prev = 0, 0, 0
for _ in range(N):
    t, x, y = [int(x) for x in input().split()]
    l = (t - t_prev) - ((x - x_prev) + (y - y_prev))
    if not (l >= 0 and l % 2 == 0):
        print("No")
        exit()
        
print("Yes")

Measured memory_bytes: 3060
const stdin = require('fs').readFileSync('/dev/stdin', 'utf8').trim()

const [w, h, x, y] = stdin
  .split('\n')[0]
  .split(' ')
  .map(Number)

const ans = () => {
  const area = w * h

  if (x === 0 || x === w || y === 0 || y === h) {
    return `${area / 2} 0`
  }
  const min = Math.min(w, h)
  const diag = (min * min) / 2

  const xh = x * h
  const xhMin = Math.min(xh, area - xh)

  const wy = w * y
  const wyMin = Math.min(wy, area - wy)

  if (xhMin === wyMin) {
    return `${xhMin} 1`
  } else {
    return `${Math.max(xhMin, wyMin, diag)} 0`
  }
}

console.log(ans())


Measured memory_bytes: 9420
import sys
sys.setrecursionlimit(10 ** 6)
# input = sys.stdin.readline    ####
int1 = lambda x: int(x) - 1
def II(): return int(input())

def MI(): return map(int, input().split())
def MI1(): return map(int1, input().split())

def LI(): return list(map(int, input().split()))
def LI1(): return list(map(int1, input().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]

def printlist(lst, k='\n'): print(k.join(list(map(str, lst))))
INF = float('inf')

from math import cos, sqrt, radians
def solve():
    a, b ,h, m = MI()

    tyou = 0
    tan = 0
    for i in range(12):
        for j in range(60):
            # print(i, j)
            if i == h and j == m:
                theta = abs(tan - tyou)
                theta = min(theta, 360 - theta)
                # print(tan, tyou)
                # print(a, b, theta)
                ans = sqrt(a**2 + b**2 - 2*a*b*cos(radians(theta)))
                print(ans)
                return
            tan += 0.5
            tyou += 6
        tyou = 0

if __name__ == '__main__':
    solve()


Measured memory_bytes: 9512
// chahat  agarawal
// agrawal117

#include<bits/stdc++.h>
#define mod 1000000007
#define ll long long int
#define endl '\n'
#define pb push_bck
using namespace std;
int main()
{
    ll n;
    cin>>n;
    map<ll,ll> mp;
    ll a;
    ll arr[n+2];
    for(int i=0;i<n;i++){
        cin>>a;
        arr[i]=a;
        mp[a]++;
    }
    a=arr[0];
    mp[a]--;
    ll b,c;
    for(int i=1;i<n;i++){
        b=arr[i];
        mp[b]--;
        ll val=a xor b;
        if(mp.count(val) && mp[val]>=1){
            c=val; mp[c]--; break;
        }
        mp[b]++;
    }
    for(int i=4;i<=n;i++){
        ll val= b xor c;
        if(mp.count(val) && mp[val]>=1){
             mp[val]--;
             b=c;
             c=val;
        }
        else{ cout<<"No"<<endl; return 0; }
    }
    cout<<"Yes"<<endl;
    
    
}

Measured memory_bytes: 5632
#include<stdio.h>

int main(void){
  int i,j,k,l;
  int h,w;
  char map[1000][1000];
  int n;
  int max,min;

  while(1){
    scanf(" %d ",&n);
    if(!n)break;
    
    for(i=0;i<n;i++){
      for(j=0;j<n;j++){
	scanf(" %c ",&map[i][j]);
      }
    }
    
    max = 0;
    for(i=0;i<n;i++){
      for(j=0;j<n;j++){
	h = 0;
	w = 0;
	while(map[i+h][j] == '.' && i+h < n)h++;
	while(map[i][j+w] == '.' && j+w < n)w++;
	if(h<w)min = h;
	else min = w;
	for(k=1;k<min;k++){
	  for(l=1;l<min;l++){
	    if(map[i+k][j+l] == '*'){
	      min = l;
	      break;
	    }
	  }
	}
	if(min>max)max = min;
      }
    }
    
    printf("%d\n",max);
    
  }

  return 0;
}

Measured memory_bytes: 1180
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AtCoder_solve
{
    class Program
    {
        public const ulong mod = 1000000007;

        static void Main(string[] args)

        {
            var n = Input();
            var b = Input3();
            var ans = b[0];

            for(long i = 1; i < n-1; i++)
            {
                ans += Math.Min(b[i - 1], b[i]);
            }

            ans += b[n - 2];
           
            Console.WriteLine(ans);


        }

       
        static public long Input()
        {
            return long.Parse(Console.ReadLine());
        }

        static public string[] Input2()
        {
            return Console.ReadLine().Split();
        }

        static public long[] Input3()
        {
            string[] data = Console.ReadLine().Split();
            long[] res = new long[data.LongLength];
            for(long i = 0; i < data.LongLength; i++)
            {
                res[i] = long.Parse(data[i]);
            }
            return res;
        }
        public static long Choose(long n, long a)
        {
            long x = 1;
            long y = 1;
            for (long i = 0; i < a; i++)
            {
                x *= n - i;
                y *= i + 1;
            }
            return x / y;
        }
    }
}


Measured memory_bytes: 13140
n,x,y=map(int,input().split())
x-=1
y-=1
def dist(a,b):
	return min(abs(b-a),1+abs(a-x)+abs(b-y),1+abs(b-x)+abs(a-y))
#d==1
print(n)
for d in range(2,n):
	ans=0
	for i in range(n-d):
		lst=[]
		if i+d<n and dist(i,i+d)==d:
			lst.append(i+d)
		d0=d
		d0-=abs(x-i)
		d0-=1
		if d0>=0:
			if i<y-d0 and dist(i,y-d0)==d:
				lst.append(y-d0)
			if i<y+d0 and dist(i,y+d0)==d and y+d0<n:
				lst.append(y+d0)
		ans+=len(list(set(lst)))
	print(ans)

Measured memory_bytes: 80348