akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;

int main(){
    int n,d,x; cin >> n >> d >> x;
    int sum = 0;

    for(int i=0;i<n;i++){
        int a; cin >> a;
        sum += (d-1)/a;
    }
    sum += n + x;
    cout << sum << endl;
}



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

if (A%2==0 and B%2==0) or (A%2==1 and B%2==1):
  print(int((B-A)//2))

elif (A-1)<=(N-B):
  print(int(A+(B-A-1)//2))

else:
  print(int(N-B+1+(B-A-1)//2))

Measured memory_bytes: 3060
#include<iomanip>
#include<limits>
#include<thread>
#include<utility>
#include<iostream>
#include<string>
#include<algorithm>
#include<set>
#include<map>
#include<vector>
#include<stack>
#include<queue>
#include<cmath>
#include<math.h>
#include<numeric>
#include<cassert>
#include<random>
#include<deque>
#include<chrono>
#include<unordered_map>
#include<list>
using namespace std;
typedef unsigned long long int ull;
typedef long long int ll;
typedef pair<ll,ll> pll;
typedef pair<int,int> pi;
const ll E=1e18+7;
#define F first
#define S second
#define MK make_pair
const ll MOD=1000000007;

ll d,g;
vector<ll> prob;
vector<ll> comp;

ll judge(ll a){
    ll count=0;
    ll sum=0;
    vector<ll> P;
    for(int i=0;i<d;i++){
        if(a&(1<<i)){
            sum+=comp[i];
            count+=prob[i];
        }
        else{
            for(int t=0;t<prob[i];t++){
                P.push_back(i*100+100);
            }
        }
    }
    sort(P.begin(),P.end(),greater<ll>());
    for(int i=0;i<P.size() && sum<g;i++){
        count++;
        sum+=P[i];
    }
    if(sum<g){return E;}
    return count;
}


int main(){
    cin>>d>>g;
    for(int i=1;i<=d;i++){
        ll p,c;
        cin>>p>>c;
        comp.push_back(c+i*p*100);
        prob.push_back(p);
    }
    ll a=0;
    for(int i=0;i<d;i++){
        a+=1<<i;
    }
    ll ans=E;
    for(;a>=0;){
        ans=min(ans,judge(a));
        a--;
    }
    cout<<ans<<endl;
    
    return 0;
}


Measured memory_bytes: 256
import java.util.*;

class Main {
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		long n = in.nextLong();
		long a = in.nextLong();
		long b = in.nextLong();
		long syou = n/(a+b);
		long amari = n%(a+b);
		long result = syou*a;
		if(amari >= a) {
			result = result + a;
		} else {
			result = result + amari;
		}
		System.out.println(result);
		in.close();
	}
}


Measured memory_bytes: 23636
N=int(input())
S=[input() for n in range(N)]

S.sort()

l=[]
c=[]
prev=S[0]
cnt=0
for n in range(len(S)):
    if S[n]==prev:
        cnt+=1
    else:
        c.append(cnt)
        cnt=1
        l.append(prev)
        prev=S[n]
if cnt!=0:
    c.append(cnt)
    l.append(prev)

max_cnt=max(c)

max_str=[]
for n in range(len(c)):
    if c[n]==max_cnt:
       max_str.append(l[n])
max_str.sort()

for e in max_str:
    print(e) 

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

long long xor_ll(long long x){
    if(x<0) return 0;
    long long y = x%4;
    if(y==1) x = 1;
    else if(y==2) x+=1;
    else if(y==3) x = 0;
    else x = x;
    return x;
}
int main(){
    long long a,b; cin >> a >> b;
    long long ans = xor_ll(b)^xor_ll(a-1);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#define N 100
#define WHITE 0
#define GRAY 1
#define BLACK 2

void Dfs(void);
void Dfsvisit(int);


int n,time;
int d[N+1],f[N+1],G[N+1][N+1],C[N+1];

int main(){

  int i,j,k,id,l;

  scanf("%d",&n);

  for(i=1;i<=n;i++){
    for(j=1;j<=n;j++){
      G[i][j]=0;
    }
  }

  for(i=1;i<=n;i++){
    scanf("%d %d",&id,&k);
    for(j=0;j<k;j++){
      scanf("%d",&l);
      G[i][l]=1;
    }
  }

  Dfs();

  for(i=1;i<=n;i++){
    printf("%d %d %d\n",i,d[i],f[i]);
  }
  return 0;
}

void Dfs(void){
 
  int i;

  for(i=1;i<=n;i++){
    C[i]=WHITE;
  }
  time=0;
  for(i=1;i<=n;i++){
    if(C[i]==WHITE){
      Dfsvisit(i);
    }
  }
}

void Dfsvisit(int u){

  int v;

  C[u]=GRAY;
  d[u]=++time;

  for(v=1;v<=n;v++){
    if(G[u][v]==1){
      if(C[v]==WHITE){
	Dfsvisit(v);
      }
    }
  }

  C[u]=BLACK;
  f[u]=++time;
}

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

using namespace std;

template <typename T> void read(T &x)
{
	x = 0; char c = getchar(); bool f = 0;
	while(!isdigit(c) && c!='-') c = getchar();
	if(c == '-') f = 1, c = getchar();
	while(isdigit(c)) x = x*10+c-'0', c = getchar();
	if(f) x = -x;
}

typedef pair<int, int> pii;

const int MX = 200005;

struct ITV
{
	pii v, p;

	ITV (const pii &v0, const pii &p0) : v(v0), p(p0) {}

	bool operator < (const ITV &t) const {return v > t.v;}
};

struct NODE
{
	int v, p;

	NODE (const int &v0 = 0, const int &p0 = 0) : v(v0), p(p0) {}

	NODE operator + (const NODE &t) {return (v<t.v) ? *this : t;}
};

struct SEGT
{
	#define ls (a<<1)
	#define rs (a<<1|1)
	#define mid ((l+r)>>1)

	NODE t[2][MX*4];

	void upd(int a)
	{
		t[0][a] = t[0][ls] + t[0][rs];
		t[1][a] = t[1][ls] + t[1][rs];
	}

	void build(int a, int l, int r, int *s)
	{
		if(l == r)
		{
			if(l&1) t[1][a] = NODE(s[l], l), t[0][a] = NODE(+MX, 0);
			else t[0][a] = NODE(s[l], l), t[1][a] = NODE(+MX, 0);
		}
		else build(ls, l, mid, s), build(rs, mid+1, r, s), upd(a);
	}

	NODE qur(int a, int l, int r, int ql, int qr, int p)
	{
		if(ql<=l && r<=qr) return t[p][a];
		else if(ql>r || qr<l) return NODE(+MX, 0);
		else return qur(ls, l, mid, ql, qr, p) + qur(rs, mid+1, r, ql, qr, p);
	}

	#undef ls
	#undef rs
	#undef mid
} T;

int n;
int seq[MX];

pii best_pair(int l, int r)
{
	NODE nl = T.qur(1, 1, n, l, r-1, l&1);
	NODE nr = T.qur(1, 1, n, nl.p+1, r, (nl.p+1)&1);
	return make_pair(nl.p, nr.p);
}

void work()
{
	priority_queue<ITV> que;
	pii ini = best_pair(1, n);
	que.push(ITV(make_pair(seq[ini.first], seq[ini.second]), make_pair(1, n)));
	while(que.size())
	{
		ITV x = que.top();
		que.pop();
		printf("%d %d ", x.v.first, x.v.second);
		pii d = best_pair(x.p.first, x.p.second);
		if(x.p.first < d.first)
		{
			pii t = best_pair(x.p.first, d.first-1);
			que.push(ITV(make_pair(seq[t.first], seq[t.second]), make_pair(x.p.first, d.first-1)));
		}
		if(d.second - d.first > 2)
		{
			pii t = best_pair(d.first+1, d.second-1);
			que.push(ITV(make_pair(seq[t.first], seq[t.second]), make_pair(d.first+1, d.second-1)));
		}
		if(d.second < x.p.second)
		{
			pii t = best_pair(d.second+1, x.p.second);
			que.push(ITV(make_pair(seq[t.first], seq[t.second]), make_pair(d.second+1, x.p.second)));
		}
	}
}

int main()
{
	read(n);
	for(int i=1; i<=n; i++) read(seq[i]);
	T.build(1, 1, n, seq);
	work();
	return 0;
}


Measured memory_bytes: 15604
"""
じょえちゃんねる
高評価・チャンネル登録よろしくお願いします！
https://www.youtube.com/channel/UCRXsI3FL_kvaVL9zoolBfbQ
"""
n, r = map(int, input().split())
if n >= 10:
    print(r)
else:
    print(r + 100 * (10 - n))


Measured memory_bytes: 2940
N = int(input())
B_List = list(map(int,input().split()))
A_List = [[] for i in range(N)]
A_List[0] = B_List[0]
A_List[1] = B_List[0]
for i in range(1,N - 1):
    if B_List[i] <= B_List[i-1]:
        A_List[i] = B_List[i]
    A_List[i+1] = B_List[i]
        
        

print(sum(A_List))

Measured memory_bytes: 9184
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int INF = 1<<30;
const ll LINF = 1LL<<60;

vector<ll> pf(ll n) {
    vector<ll> ans;
    for (ll i = 2; i*i <= n; i++) {
        if (n%i != 0) continue;
        ll ex = 0;
        ll tmp = i;
        while (n%i == 0) {
            ++ex;
            n/=i;
            ans.push_back(tmp);
            tmp *= i;
        }
    }
    if (n!=1) ans.push_back(n);
    return ans;
}

int main() {
    ios::sync_with_stdio(0); cin.tie(0);
    if (fopen("input.in", "r")) {
        freopen("input.in", "r", stdin);
        freopen("output.out", "w", stdout);
    }

    ll n; cin >> n;
    vector<ll> p = pf(n);
    sort(p.begin(), p.end());

    int ans = 0;
    for (int i = 0; i < p.size(); i++) {
        if (p[i]>n) break;
        if (n%p[i]==0) {
            ++ans;
            n/=p[i];
        }
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3668
from sys import stdin
nii=lambda:map(int,stdin.readline().split())
lnii=lambda:list(map(int,stdin.readline().split()))

a,b=nii()
ans=0
for i in range(a,b+1):
  s=str(i)
  if s==s[::-1]:
    ans+=1

print(ans)

Measured memory_bytes: 9184
import sys

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")

def main():
    inf=float("inf")
    n = int(input())
    period_shop_to_open = [[0] * n for _ in range(10)]
    for shop in range(n):
        aa = list(map(int, input().split()))
        for period, opened in enumerate(aa):
            period_shop_to_open[period][shop] = opened
    shop_times_to_profit = [list(map(int, input().split())) for _ in range(n)]

    ans = -inf
    for j_open in range(1,1 << 10):
        shop_to_open_times = [0] * n
        for shop in range(n):
            for period in range(10):
                if (j_open >> period) & 1 and period_shop_to_open[period][shop]:
                    shop_to_open_times[shop] += 1
        profit = 0
        for shop in range(n):
            profit += shop_times_to_profit[shop][shop_to_open_times[shop]]
        ans = max(ans, profit)
    print(ans)

main()


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
int main()
{
    std::ios::sync_with_stdio(false);
	int n;
	cin>>n;
	vector<int> score(n);
	//vector<int> mod10(n);
	int mins = 9999999;
	int sum = 0;
	for(int i = 0 ; i < n ; i++)
	{
		cin>>score[i];
		sum+=score[i];
		if(score[i]%10!=0)
		{
			if(score[i]<mins)
			{
				mins=score[i];
			}
		}
	}
	
	if(mins==9999999)
	{
		cout<<0;
	}
	else if(sum%10!=0)
	{
		cout<<sum;
	}
	else
	{
		cout<<sum-mins;
	}
	
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define INF 2147483647
#define INF_LL 9223372036854775807
#define MOD 1000000007
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;

int main() {
	int N;
	cin >> N;
	vector<ll> A(N), B(N);
	deque<pair<ll, pair<ll, ll>>> C(N);
	for (int i = 0; i < N; i++) {
		cin >> A[i] >> B[i];
		C[i].first = B[i] + A[i]; //高橋目線
		C[i].second.second = i;
		C[i].second.first = A[i];
	}
	sort(C.begin(), C.end(), greater<>());
	ll Tk = 0, Ao = 0;
	for (int i = 0; i < N; i++) {
		if (i % 2 == 0) {
			Tk += A[C[0].second.second];
			C.pop_front();
		}
		else {
			Ao += B[C[0].second.second];
			C.pop_front();
		}
	}
	cout << Tk - Ao << endl;
}

Measured memory_bytes: 4224
/////////////////////////   _LeMur_
#include <algorithm>
#include <iostream>
#include <cstring>
#include <cassert>
#include <bitset>
#include <cstdio>
#include <vector>
#include <string>
#include <ctime>
#include <stack>
#include <queue>
#include <cmath>
#include <ctime>
#include <list>
#include <map>
#include <set>

using namespace std;

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

int n;
int a , b;
int x , y , z;

int main(){
    scanf("%d%d%d",&n,&a,&b);
    for(int i=1;i<=n;i++){
        int tiv;
        scanf("%d",&tiv);
        if(tiv <= a) x++;
        if(tiv > a && tiv <= b) y++;
        if(tiv > b) z++;
    }
    int answ = min(x , y);
    answ = min(answ , z);
    cout<<answ<<endl;
    return 0;
}


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

int main() {
	ios_base::sync_with_stdio( false );

	string S;
	cin >> S;

	int result = 0;
	char x = ' ';

	for( int i = 0; i < S.size(); ++i ) {
		if( S[i] != x ) {
			x = S[i];
			result += 1;
		}
	}

	cout << result-1 << endl;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define MAX 2000000
#define MOD 1000000007

int main(){
  int N;
  cin>>N;
  vector<int> a(N),b(N),c(N);
  for(int i=0;i<N;i++){
    cin>>a.at(i)>>b.at(i)>>c.at(i);
  }

  vector<vector<int>> dp(N,vector<int>(3,0));
  dp.at(0).at(0)=a.at(0);
  dp.at(0).at(1)=b.at(0);
  dp.at(0).at(2)=c.at(0);
  for(int i=1;i<N;i++){
    dp.at(i).at(0)=max(dp.at(i-1).at(1),dp.at(i-1).at(2))+a.at(i);
    dp.at(i).at(1)=max(dp.at(i-1).at(0),dp.at(i-1).at(2))+b.at(i);
    dp.at(i).at(2)=max(dp.at(i-1).at(0),dp.at(i-1).at(1))+c.at(i);
  }

  cout<<max({dp.at(N-1).at(0),dp.at(N-1).at(1),dp.at(N-1).at(2)})<<endl;
}


Measured memory_bytes: 6912
#include <iostream>

using namespace std;

int main(void)
{
    int n;
    int i = 1;

    cin >> n;

    do {
        int x = i;
        if (x % 3 == 0)
        {
            cout << " " << i;
        }
        else if (x % 10 ==3)
        {
            cout << " " << i;
        }
        else 
        {
            x /= 10;
            while (x) 
            {
                if (x % 10 == 3)
                {
                    cout << " " << i;
                    break;
                }
                x /= 10; 
            }
        }
    } while (++i <= n);
    cout << endl;
}


Measured memory_bytes: 3104
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<set>
#include<iomanip>
#define pi 3.14159265358979323846
#define ll long long
#define rep(i, a, n) for(int i = a; i < n; i++)
using namespace std;
int main(){
  int a, b, c = 0;
  cin >> a>> b;
  rep(i, 0, b){
    int d;
    cin >> d;
    c += d;
  }
  if(c >= a){
    cout << "Yes\n";
  }
  else{
    cout << "No\n";
  }
}

Measured memory_bytes: 3564
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		String s = sc.next();
	    char[] c = s.toCharArray();
	    char temp = ' ';

	    int count1 = 0;  //count2が2溜まるごとにcount1を増やす
		int count2 = 0;
		for(int i = 0; i < n; i++) {
			if(c[i] != temp) {
				count2++;
				if(count2 == 2) {
					count1++;
					count2 = 0;  //count2のリセット
					temp = ' ';  //tempのリセット
				}
				else temp = c[i];
			}
		}
		System.out.println(count1);
	}

}



Measured memory_bytes: 29904
import sys
def na(): map(int,sys.stdin.readline().split())
def ns(): return sys.stdin.readline().strip()

s=ns()
t=ns()
n=len(s)
for i in range(n):
    if s[n-i:] + s[0:n-i] == t:
        print('Yes')
        exit()
print('No')

Measured memory_bytes: 3060
a,b,c=map(int,input() .split())
if a<=b:
    if c>=b:
        print(a,b,c)
    elif a<=c<=b:
        print(a,c,b)
    elif c<a:
        print(c,a,b)
else:
    if c>a:
        print(b,a,c)
    elif b<=c<=a:
        print(b,c,a)
    elif c<b:
        print(c,b,a)



Measured memory_bytes: 5596
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i = 0; i < (n); i++)
#define INF 2 << 29
#define MOD 1000000007
#define Yes(f) puts((f)? "Yes" : "No")
#define YES(f) puts((f)? "YES" : "NO")
int gcd(int a, int b) {
	if (b != 0)return gcd(b, a % b);
	return a;
}
int lcm(int a, int b) {
	return a / gcd(a, b) * b;
}

using Graph = vector<vector<int>>;

int main(){
	int h, n; cin >> h >> n;
	int sum = 0;
	rep(i,n){
		int a; cin >> a;
		sum += a;
	}
	Yes(sum >= h);

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int (i) = 0; (i) < (n); i++)
#define ll long long
using namespace std;
int main(){
  int N = 0;
  cin >> N;
  map <string,ll> mp;
  string S;
  rep(i,N){
    cin >> S;
    mp[S]++;
  }
  ll a = 0;
  for(auto i: mp){
    a = max(a,i.second);
  }
  for(auto i: mp){
    if(a == i.second){
      cout << i.first << endl;
    }
  }
}

Measured memory_bytes: 25216
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <string>
#include <cstring>
#include <queue>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <map>
#include <numeric>
#include <functional>
#include <cmath>
#include <cassert>
#include <string>
#include <iostream>

using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<ll, ll> PL;
const ll mod = 1000000007;
const ll MOD = 1000000007;
const ll INF = 1LL << 60;
#define PI (acos(-1))

ll lcm(ll a, ll b)
{
    return a * b / __gcd(a, b);
}
vector<ll> divisor(ll n)
{
    vector<ll> ret;
    for (ll i = 1; i * i <= n; i++)
    {
        if (n % i == 0)
        {
            ret.push_back(i);
            if (i * i != n)
                ret.push_back(n / i);
        }
    }
    sort(begin(ret), end(ret));
    return (ret);
}

const ll MAX = 510000;
ll fac[MAX], finv[MAX], inv[MAX];
// テーブルを作る前処理
void COMinit()
{
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (ll 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;
    }
}
// 二項係数計算
ll COM(ll n, ll k)
{
    if (n < k)
        return 0;
    if (n < 0 || k < 0)
        return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

ll x[101010];
ll solve()
{
    ll n, a, b;
    cin >> n >> a >> b;
    for(int i=0; i < n; i++){
        cin >> x[i];
    }
    ll ans = 0;
    for(int i=0; i < n - 1; i++){
        if((x[i+1] - x[i])*a <= b){
            ans += (x[i + 1] - x[i]) * a;
        }else{
            ans += b;
        }
    }
    cout << ans << endl;

    return 0;
}

int main()
{
    //cout.precision(10);
    ios::sync_with_stdio(false);
    cin.tie(0);

    solve();
}


Measured memory_bytes: 1024
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
n,k = map(int,readline().split())
A = list(map(int,readline().split()))

class SegmentTree:
    def __init__(self, n, ele, segfun):
        #####単位元######要設定0or1orinf
        self.ide_ele = ele
        self.segfun = segfun
        ####################
        self.n = n
        self.N0 = 1 << n.bit_length()
        self.data = [self.ide_ele] * (self.N0 * 2)
        
    def update_add(self, l, r, val):
        l += self.N0
        r += self.N0
        while l < r:
            if l & 1:
                self.data[l] += val
                l += 1
            if r & 1:
                self.data[r - 1] += val
                r -= 1
            l //= 2
            r //= 2

    def update(self, l, r, val):
        l += self.N0
        r += self.N0
        while l < r:
            if l & 1:
                self.data[l] = self.segfun(self.data[l], val)
                l += 1
            if r & 1:
                self.data[r - 1] = self.segfun(self.data[r - 1], val)
                r -= 1
            l //= 2
            r //= 2

    def query(self, i):
        i += len(self.data) // 2
        ret = self.data[i]
        while i > 0:
            i //= 2
            ret = self.segfun(ret, self.data[i])
        return ret

for i in range(k):
  m = n
  S = SegmentTree(n,0,lambda a, b: a+b)
  for j in range(n):
    q = A[j]
    m = min(m,q)
    S.update_add(max(1,j-q+1),min(n+1,j+q+2), 1)
  if i < k-1 and m >= n-1:
    A = [n]*n
    break
  for l in range(n):
    p = S.query(l+1)
    A[l] = p
    
print(*A)

Measured memory_bytes: 177976
#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
using namespace std;
#ifndef FAST_IO
 #define IOS ios_base::sync_with_stdio(false);cin.tie(nullptr);
#endif

#define FILE_IO freopen("input.txt","r",stdin)
#define int long long
#define f first
#define s second
#define endl '\n'
#define all(c) c.begin(),c.end()
#define bp __builtin_popcount
#define debug(x) cerr << #x << " = " << x << endl;

const int MOD = 1e9 + 7;
const int INF = 1e18;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
template <typename T>void print(T t){for(auto &it : t)cout<<it<<" ";}
inline int powerexp(int a, int b, int m = MOD){ int res = 1;while(b){if(b&1)res = res * a % m;a = a * a % m,b >>= 1;}return res % m;}
inline int modinv(int a){ return powerexp(a,MOD-2,MOD);}
inline int lcm(int a, int b){ int g = __gcd(a,b);return a/g*b;}
inline int add(int x, int y){ x += y; if (x >= MOD) x -=  MOD; return x;}
inline int mul(int x, int y){ return (x * 1ll * y) % MOD;}
inline int sub(int x, int y){ x -= y; if (x<0) x += MOD; return x ;}

//-------------------< start here >-------------------------// 

double calc(pair<double, double> a, pair<double, double> b){
  double x = (a.f - b.f) * (a.f - b.f);
  double y = (a.s - b.s) * (a.s - b.s);
  double dist = sqrt(x + y);
  return dist;	
}

void solve(){
	cout << fixed;
	cout << setprecision(10);
    double x1, x2, y1, y2;
    pair<double, double> p1, p2;
    cin >> x1 >> y1 >> x2 >> y2;
    p1 = make_pair(x1, y1);
    p2 = make_pair(x2, y2);
    double ret = calc(p1, p2);
    cout << ret << endl;
}

//-----------------------------
//comment from here for TOPCODER 
int32_t main(){
   IOS;
   solve();
   //find();
   #ifdef LOCAL_DEFINE
   cerr << "time elapsed " << (double)clock()/CLOCKS_PER_SEC << endl;
   #endif
}



Measured memory_bytes: 3284
#include<iostream>
#include<iomanip>
#include<string>
#include<set>
#include<vector>
#include<utility>
#include<queue>
#include<algorithm>
#include<functional>
using namespace std;
#define LL long long
#define MOD 100000
#define inf 1999999999


int main() {
	int a, b, c;
	cin >> a >> b >> c;
	cout << (b - a == c - b ? (string)"YES" : (string)"NO") << endl;

	return 0;
}


Measured memory_bytes: 256
H, W = map(int, input().split())
s = [list(input()) for _ in range(H)]

INF = 10**9
di = [-1, 0, 1, 0]
dj = [0, -1, 0, 1]
def update(v, h, d, dist, q):
    if dist[W*v+h] != INF:
        return
    dist[W*v+h] = d
    q.append((v, h))

ans = 0
for si in range(H):
    for sj in range(W):
        if s[si][sj] == "#":
            continue
        dist = [INF]*H*W
        dist[W*si+sj] = 0
        q = [(si, sj)]
        while len(q) > 0:
            current = q.pop(0)
            v = current[0]
            h = current[1]
            for dir in range(4):
                ni = v+di[dir]
                nj = h+dj[dir]
                
                if ni<0 or H<=ni or nj<0 or W<= nj:
                    continue
                if s[ni][nj] == "#":
                    continue
                update(ni, nj, dist[W*v+h]+1,dist, q)
        for v in dist:
            if v == INF:
                continue
            ans = max(ans, v)
print(ans)









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

using namespace std;
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9 + 7;
const ll LINF = 1e18;

int main() {

    int n, m; cin >> n >> m;

    vector<int> c(n, 0);
    for (int i = 0; i < m; ++i) {
        int a, b; cin >> a >> b;
        --a; --b;

        c[a]++;
        c[b]++;
    }

    bool ok = true;
    for (int i = 0; i < n; ++i) {
        if (c[i] % 2 == 1) {
            ok = false;
            break;
        }
    }

    if (ok) {
        puts("YES");
    } else {
        puts("NO");
    }
}

Measured memory_bytes: 640
#include <iostream>
#include <iomanip>
#include <string>
#include <stack>
#include <vector>
#include <math.h>
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <iterator>
#include <map>
#include <set>
#include <queue>
#include <list>
#include <regex>
using namespace std;
using pii  = pair<int,int>;
using ll=long long;
using ld=long double;
#define pb push_back
#define mp make_pair
#define sc second
#define fr first
#define stpr setprecision
#define cYES cout<<"YES"<<endl
#define cNO cout<<"NO"<<endl
#define cYes cout<<"Yes"<<endl
#define cNo cout<<"No"<<endl
#define rep(i,n) for(ll i=0;i<(n);++i)
#define Rep(i,a,b) for(ll i=(a);i<(b);++i)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define rRep(i,a,b) for(int i=a;i>=b;i--)
#define crep(i) for(char i='a';i<='z';++i)
#define psortsecond(A,N) sort(A,A+N,[](const pii &a, const pii &b){return a.second<b.second;});
#define ALL(x) (x).begin(),(x).end()
#define debug(v) cout<<#v<<":";for(auto x:v){cout<<x<<' ';}cout<<endl;
#define endl '\n'
int ctoi(const char c){
  if('0' <= c && c <= '9') return (c-'0');
  return -1;
}
ll gcd(ll a,ll b){return (b == 0 ? a : gcd(b, a%b));}
ll lcm(ll a,ll b){return a*b/gcd(a,b);}
constexpr ll MOD=1000000007;
constexpr ll INF=1000000011;
constexpr ll MOD2=998244353;
constexpr ll LINF = 1001002003004005006ll;
constexpr ld EPS=10e-8;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
template<typename T> istream& operator>>(istream& is,vector<T>& v){for(auto&& x:v)is >> x;return is;}
template<typename T,typename U> istream& operator>>(istream& is, pair<T,U>& p){ is >> p.first; is >> p.second; return is;}
template<typename T,typename U> ostream& operator>>(ostream& os, const pair<T,U>& p){ os << p.first << ' ' << p.second; return os;}
template<class T> ostream& operator<<(ostream& os, vector<T>& v){
  for(auto i=begin(v); i != end(v); ++i){
    if(i !=begin(v)) os << ' ';
    os << *i;
  }
  return os;
}

bool sosuu[100007];

bool check(ll X){
  if(sosuu[X]&&sosuu[(X+1)/2]){
    return 1;
  }
  else{
    return 0;
  }
}

int main(){
  ll N=100000;
  ll sum[100007];
  for(int i=1;i<=100000;i++){
    ll Y=i;
    ll T=0;
    if(i==1){
      sosuu[i]=0;
    }
    else if(i==2){
      sosuu[i]=1;
    }
    else{
      Rep(j,2,sqrt(i)+1){
        if(Y%j==0){
          T=1;
        }
      }
      if(T==0){
        sosuu[i]=1;
      }
      else{
        sosuu[i]=0;
      }
    }
  }
  sum[0]=0;
  Rep(i,1,N+1){
    if(i%2==0){
      sum[i]=sum[i-1];
    }
    else if(check(i)){
      sum[i]=sum[i-1]+1;
    }
    else{
      sum[i]=sum[i-1];
    }
  }
  ll Q;
  cin >> Q;
  rep(i,Q){
    ll l,r;
    cin >> l >> r;
    cout << sum[r]-sum[l-1] << endl;
  }
}

Measured memory_bytes: 1536
#include <bits/stdc++.h>
using namespace std;
void Main();

using i8  = int8_t;   /* -128 ~ 127 */
using u8  = uint8_t;  /* 0 ~ 255 */
using i16 = int16_t;  /* -32,768 ~ 32,767 */
using u16 = uint16_t; /* 0 ~ 65,535 */
using i32 = int32_t;  /* -2,147,483,648 ~ 2,147,483,647 */
using u32 = uint32_t; /* 0 ~ 4,294,967,295 */
using i64 = int64_t;  /* -9,223,372,036,854,775,808 ~ 9,223,372,036,854,775,807 */
using u64 = uint64_t; /* 0 ~ 18,446,744,073,709,551,615 */
using f32 = float;    /* (-3.4 * 10^38) ~ (3.4 * 10^38) */
using f64 = double;   /* (-1.7 * 10^308) ~ (1.7 * 10^308) */
using f80 = __float80;
template <class T> using Vec = vector<T>;
constexpr i64 INF = 1010000000000000017;
constexpr i64 MOD = 1e9 + 7;
constexpr f64 EPS = 1e-12;
constexpr f64 PI = 3.14159265358979323846;
#define ALL(v) v.begin(), v.end()
#define GCD(a, b) __gcd(a, b) /* 最大公約数 */
#define LCM(a, b) a / __gcd(a, b) * b /* 最小公倍数 */

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(15);
    Main();
    return 0;
}

void Main() {
    i32 A, B;
    cin >> A >> B;
    if (A > 9 || B > 9) {
        cout << -1 << endl;
        return;
    }
    cout << A * B << endl;
}


Measured memory_bytes: 3592
#include<cstdio>
#include<iostream>
#include<map>
#include<string>
#include<queue>
#include<map>
#include<vector>
#include<set>
#include<cstring>
using namespace std;
typedef long long ll;
const ll mod=998244353;
ll dp[3004]={0};
ll a[3005];
ll n,s;
int main()
{
	ll ans=0;
	scanf("%lld%lld",&n,&s);
	for(ll i=1;i<=n;i++)
	{
		scanf("%lld",&a[i]);
	}
	for(ll i=1;i<=n;i++)
	{
		for(ll j=s-a[i];j>=0;j--)
		{
			dp[j+a[i]]+=dp[j];
			dp[j+a[i]]%=mod;
		}
		dp[a[i]]+=i;
		ans+=dp[s];
		ans%=mod;
	}
	printf("%lld",ans);
}

Measured memory_bytes: 256
#include <stdio.h>
#include <vector>
#include <queue>
#define NUM 100000
#define NIL -1
using namespace std;

int node_num;
vector<int> v[NUM + 1];
queue<int> Q;
int color[NUM + 1];

bool is_connected(int a, int b){
    if(color[a] == color[b]){
        return true;
    }else{
        return false;
    }
}

void add_next(int n){
    for(int i = 0; i < v[n].size(); i++){
        if(color[v[n][i]] != NIL)
            continue;
        Q.push(v[n][i]);
        color[v[n][i]] = color[n];
    }
}

void bfs(){
    for(int i = 1; i <= node_num; i++){
        if(color[i] != NIL)
            continue;
        color[i] = i;
        Q.push(i);
        add_next(i);

        while(Q.size()){
            int top = Q.front();
            Q.pop();
            add_next(top);
        }
    }
    return;
}

void init(){
    for(int i = 0; i <= NUM; i++){
        color[i] = NIL;
    }
}

int main(void){
    init();

    int m;
    scanf("%d", &node_num);
    scanf("%d", &m);

    for(int i = 0; i < m; i++){
        int a, b;
        scanf("%d %d", &a, &b);
        v[a].push_back(b);
        v[b].push_back(a);
    }

    bfs();
     
    int q;
    scanf("%d", &q);
    for(int i = 0; i < q; i++){
        int a, b;
        scanf("%d %d", &a, &b);
        if(is_connected(a, b)){
            printf("yes\n");
        }else{
            printf("no\n");
        }
    }
}



Measured memory_bytes: 8556
#include<iostream>
#include<vector>
#include<algorithm>
#include<map>
#include<cstring>
#include<math.h>
#include<bitset>
#include<queue>
#include<set>
#include<iomanip>
// #include<bits/stdc++.h>
using namespace std;
#define ll long long

int main(){
  bool ans=true;
  int N;
  cin >> N;
  int t,x,y;
  int ts=0,xs=0, ys=0;
  for(int i=0; i<N; i++){
    int tg,xg,yg;
    cin >> tg >> xg >> yg;
    int t=tg-ts;
    int sum=abs(xg-xs)+abs(yg-ys);
    if(sum > t){
      ans = false;
    }
    if((t-sum)%2 == 1){
      ans = false;
    }
    xs = xg;
    ys = yg;
    ts = tg;
  }
  if(ans){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
  return 0;
}


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

static const int MAX = 200000;

int main() {
    long int R[MAX], n;
    cin >> n;
    for (int i = 0; i < n; i++){
        cin >> R[i];
    }

    long int maxv = -2000000000;
    long int minv = R[0];
    
    for (int j = 1; j < n; j++){
        maxv = max(maxv, R[j] - minv);
        minv = min(minv, R[j]);
    }
    
    cout << maxv << endl;
    
    return 0;
}


Measured memory_bytes: 4684
#include "bits/stdc++.h"
#define FI first.first
#define SE first.second
#define TH second
#define fi first
#define se second
#define th second

using namespace std;

template<typename T>
string to_string(const vector<T>& vc, int w) {
	if(vc.empty()) return "";
	if(w + 1 == vc.size()) return to_string(vc[w]);
	return to_string(vc[w]) + "," + to_string(vc, w + 1);
}

template<typename T>
string to_string(const vector<T>& vc) {
	return "{" + to_string(vc, 0) + "}";
}

void debug_out() { cerr << endl; }
 
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}
 
#ifdef DEBUG
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

class DebugStream {}LOG;
template <typename T>DebugStream &operator<<(DebugStream &s, const T&) { return s; }
#ifdef DEBUG
#define LOG clog
#endif

typedef long long ll;
typedef pair<ll, ll> ii;
typedef long double ld;
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());

const int maxN = 3e3 + 9, maxV = 1e6 + 9, MOD = 1e9 + 7, SQ = 335, lg = 20, bs = 29;

int n, m, k;
ll mat[maxN][maxN], dp[maxN][maxN][4];

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	#ifdef DEBUG
	freopen("input.txt", "r", stdin);
	#endif

	cin >> n >> m >> k;
	for(int i = 0, a, b, c; i < k; i++) {
		cin >> a >> b >> c;
		a--, b--;
		mat[a][b] = c;
	}

	for(int i = 0; i < n; i++) {
		for(int j = 0; j < m; j++) {
			for(int k = 2; k >= 0; k--)
				dp[i][j][k + 1] = max(dp[i][j][k + 1], dp[i][j][k] + mat[i][j]);
			for(int k = 0; k <= 3; k++) {
				dp[i][j + 1][k] = max(dp[i][j + 1][k], dp[i][j][k]);
				dp[i + 1][j][0] = max(dp[i + 1][j][0], dp[i][j][k]);
			}
		}
	}

	cout << *max_element(dp[n - 1][m - 1], dp[n - 1][m - 1] + 4) << '\n';
}



Measured memory_bytes: 356160
#include <bits/stdc++.h>
using namespace std;
 
int main()
{   
    int h,w;
    cin>>h>>w;
    vector<string> a(h);
    for(int i=0;i<h;i++){
        cin>>a[i];
    }
    
    vector<bool> row(h,false);
    vector<bool> col(w,false);
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            if(a[i][j]=='#'){
                row[i]=true;
                col[j]=true;
            }
        }
    }
    for(int i=0;i<h;i++){
        if(row[i]){
            for(int j=0;j<w;j++){
                if(col[j]){
                    cout<<a[i][j];
                }
            }
            cout<<endl;
        }
    }
}

Measured memory_bytes: 256
using System;

namespace A___RGB_Cards
{
    class Program
    {
        static void Main(string[] args)
        {
            var input = Console.ReadLine().Split(' ');
            var a = int.Parse(input[0] + input[1] + input[2]);
            if (a % 4 == 0)
            {
                Console.WriteLine("YES");
            }
            else
            {
                Console.WriteLine("NO");
            }
        }
    }
}

Measured memory_bytes: 11092
#include<iostream>
using namespace std;
int n, s;
int ans = 0;
void solve(int i, int sum, int num) {
	if (i == n&&sum == s) {
		ans++;
		return;
	}
	for (int j = num; j <= 9; j++) {
		solve(i + 1, sum + j, j + 1);
	}
	return;
}
int main() {
	while (cin >> n >> s&&n + s) {
		ans = 0;
		solve(0, 0, 0);
		cout << ans << endl;
	}
}

Measured memory_bytes: 3100
#include <iostream>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
#include <cassert>
#include <functional>
#include <string>
#include <sstream>
#include <cctype>
#include <queue>
#include <stack>
#include <map>
#include <iomanip>
using namespace std;
typedef long long ll;
#define rep(i, j, n) for (int i = j; i < n; i++)

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

void Main(){
  int N; cin >> N;
  vector<int> V;
  int cur = 0;
  int sum = 0;
  rep(i, 0, N){
    int A; cin >> A;
    V.push_back(A - cur);
    sum += abs(A - cur);
    cur = A;
  }
  V.push_back(0 - cur);
  sum += abs(0 - cur);
  rep(i, 1, N + 1){
    if(V[i - 1] * V[i] > 0) cout << sum << endl;
    else cout << sum - 2 * min(abs(V[i - 1]), abs(V[i])) << endl;
  }
}

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

int main(){
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  //cout << std::fixed << std::setprecision(15);

  Main();
}


Measured memory_bytes: 1784
N, K = map(int, input().split())
S = list(input())
S += [0]
s = []
L_count = 1
R_count = 1
count = 0

for i in range(N):
    if S[i + 1] == S[i] and S[i] == 'L':
        L_count += 1
    elif S[i + 1] == S[i] and S[i] == 'R':
        R_count += 1
    else:
        if S[i] == 'L':
            s.append(L_count)
            L_count = 1
        else:
            s.append(R_count)
            R_count = 1

for i in s:
    if i != 1:
        count += i - 1

print(min(N - 1, count + 2 * K))

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

int main() {
  int N;
  cin >> N;
  vector<int> D(N);
  for (int i = 0; i < N; i++) cin >> D.at(i);
  int sum = 0;
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < i; j++) {
      sum += D.at(i) * D.at(j);
    }
  }
  cout << sum << "\n";
}

Measured memory_bytes: 256
from collections import Counter
n = int(input())
Si = [Counter(input()) for _ in range(n)]
letters = set(Si[0].keys())
for S in Si:
    letters = set(S.keys()) & letters
letters = list(letters)
letters.sort()
for key in letters:
    count = float('inf')
    for S in Si:
        count = min(count, S[key])
    print(key*count, end='')
print('')

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

using namespace std;

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

#define fi first
#define se second
#define mp make_pair
#define fastIO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);

int main(){
  fastIO;
  int n, m, q;
  cin >> n >> m >> q;
  cout << min((q+n-1)/n, (q+m-1)/m);
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> pll;
typedef pair<int,int> pii;
#define fastio() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define pb push_back
#define F first
#define S second
//cout<<fixed<<setprecision(11);
const string nl="\n";
const ll MOD=1000000007;
const ll ARR_MAX = 1e5+1;
const ll VALUE_UPPER=1e5+5;
const ll INF = 1e14;

void solve(){
    int n;cin>>n;
    ll w;cin>>w;
    ll weight[n],value[n];
    for(int i=0;i<n;i++){
    	cin>>weight[i]>>value[i];
    }
    ll dp[VALUE_UPPER],prev[VALUE_UPPER]; //dp[i]=minimum weight needed to get a value of i.
    for(int i=0;i<VALUE_UPPER;i++){
    	dp[i]=INF;
    }
    dp[0]=0;
    for(int i=0;i<n;i++){
    	for(int j=0;j<VALUE_UPPER;j++){
    		prev[j]=dp[j];
    	}
    	for(int j=value[i];j<VALUE_UPPER;j++){
    		dp[j] = min(prev[j],prev[j-value[i]]+weight[i]);
    	}
    }
    for(int j=VALUE_UPPER-1;j>=0;j--){
    	if(dp[j]<=w){
    		cout<<j<<nl;
    		return;
    	}
    }
}

int main(){
    int t=1;
    // cin>>t;
    while(t--){
        solve();
    }
    return 0;
}

Measured memory_bytes: 1792
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <complex>
#include <queue>
#include <map>
#include <set>
#include <cstring>
#include <cstdlib>
#include <string>
#include <cmath>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
const int INF = 1<<29;

int k;
double r, l;
double p,e,t;

double rec(int num, double r, double l) {
  if (t<r-e || l+e<t) return 0;
  if (t-e<r && l<t+e) return 1;
  double tt = (r+l)/2;
  if (num == k) {
    if (abs(t-tt) < e) return 1;
    else return 0;
  }
  if (tt<t) {
    return p*rec(num+1, r, tt) + (1.0-p)*rec(num+1, tt, l);
  } else {
    return (1.0-p)*rec(num+1, r, tt) + p*rec(num+1, tt, l);
  }
}

int main() {
  cin >> k >> r >> l;
  cin >> p >> e >> t;

  printf("%.12f\n", rec(0, r, l));
}

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

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            //[summary]C - Maximal Value
            int N = int.Parse(Console.ReadLine());
            var B = ReadLine();

            int ans = B[0];

            for(int i = 1; i < N - 1; i++)
            {
                ans += Math.Min(B[i - 1], B[i]);
            }

            ans += B[N - 2];

            Console.WriteLine(ans);
        }

        static List<int> ReadLine()
        {
            var line = Console.ReadLine();
            var arr = line.Split(' ');

            return arr.Select(x => int.Parse(x)).ToList();
        }
    }
}

Measured memory_bytes: 13268
import java.util.*;
public class Main {
	Scanner sc = new Scanner(System.in);
	
	boolean reverce(String str) {
		for (int i=0;i<str.length()/2;i++) 
			if (str.charAt(i) != str.charAt(str.length()-1-i)) return false;
		return true;
	}
	
	void run() {
		int count = 0;
		while (sc.hasNext()) {
			if (reverce(sc.next())) count ++; 
		}
		System.out.println(count);
	}
	public static void main(String[] args) {
		new Main().run();
	}
}

Measured memory_bytes: 12000
# encoding:utf-8
import copy
import numpy as np
import random
import bisect #bisect_left　これで二部探索の大小検索が行える
import math

N = int(input())

A = []
for i in range(N):
    A.append(int(input()))


paper = {}
for i in range(N):
    if A[i] in paper.keys():
        paper[A[i]] += 1
    else:
        paper[A[i]] = 1

cnt = 0
for key in paper.keys():
    if paper[key] %2 == 0:
        pass
    else:
        cnt += 1


print(cnt)


Measured memory_bytes: 26324
#include <bits/stdc++.h>
using namespace std;
const int dx[]={0,1,0,-1,1,-1,-1,1};
const int dy[]={-1,0,1,0,1,1,-1,-1};
const int INF = 1<<30;
const double EPS = 1e-15;
#define PB push_back
#define mk make_pair
#define fi first
#define se second
#define ll long long
#define reps(i,j,k) for(int i = (j); i < (k); i++)
#define rep(i,j) reps(i,0,j)
#define MOD 1000000007
typedef pair<int,int> Pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
double memo[1<<12][12][12];
double dist(double a,double b){
    if(a<b)swap(a,b);
    return sqrt(((a+b)*(a+b))-((a-b)*(a-b)));
}
double search(int bit,int dep,int prev,vi cake){
    if(dep == cake.size()){
        return (double)cake[prev];
    }
    if(bit != 0 && memo[bit][dep][prev]){
        return memo[bit][dep][prev];
    }
    double ret = INF;
    rep(i,cake.size()){
        if(!(bit>>i & 1)){
            if(bit == 0){
                ret = min(ret,search(bit|1<<i,dep+1,i,cake)+cake[i]);
            }
            else{
                ret = min(ret,search(bit|1<<i,dep+1,i,cake)+dist(cake[prev],cake[i]));        
            }
        }
    }
    if(prev != -1)memo[bit][dep][prev] = ret;
    return ret;
}
int main(){
    string str;
    while(getline(cin,str)){
        memset(memo,0,sizeof(memo));
        stringstream ss(str);
        vi cake;
        int tmp;
        double len;
        bool f=false;
        while(ss >> tmp){
            if(!f)len = (double)tmp;
            else cake.PB(tmp);
            f = true;
        }
        double ret = search(0,0,-1,cake);
        //printf("%lf \n",ret);
        if(len-ret > -EPS)puts("OK");
        else puts("NA");
    }
    return 0;
}

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

using namespace std;

const int maxn = 1e5 + 10;
const int mod = 1e9 + 7;
#define ll long long

vector<int> Map[maxn];

int ans[4],vis[maxn];

void bfs(int a,int b){
    vis[a] = 1;
    vis[b] = 2;
    queue<int> q;
    q.push(a);
    q.push(b);
    while (!q.empty()){
        int x = q.front();
        ans[vis[x]]++;
        q.pop();
        for(int i=0;i<Map[x].size();i++){
            if(vis[Map[x][i]]) continue;
            vis[Map[x][i]] = vis[x];
            q.push(Map[x][i]);
        }
    }
}

int main() {
    //freopen("input.txt", "r", stdin);
    int n,a,b;
    cin>>n;
    for(int i=1;i<n;i++){
        cin>>a>>b;
        Map[a].push_back(b);
        Map[b].push_back(a);
    }
    bfs(1,n);
    if(ans[1]>ans[2])  cout<<"Fennec"<<endl;
    else               cout<<"Snuke"<<endl;
    return 0;
}


Measured memory_bytes: 6272
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
using namespace std;
typedef long long ll;
int INF = (1LL << 30) - 1;
int MOD = 1e9+7;
main(){
    int N;
    cin >> N;
    int a,cnt = 0;
    rep(i,0,N){
        cin >> a;
        cnt += a % 2;
    }
    string str[] = {"first","second"};
    cout << str[cnt == 0] << endl;
}

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

long long MOD = 998244353;

long long Calc(long long X, long long Y) {
	if (Y == 0) return 1;
	if (Y % 2 == 0) {
		long long Z = Calc(X, Y / 2);
		return (Z * Z) % MOD;
	}
	return (X * Calc(X, Y - 1)) % MOD;
}

int main() {
	static long long N, A, S[1000010] = {}, X[1000010] = {}, ANS = 0;
	cin >> N;
	for (int i = 0; i < N; i++) {
		cin >> A;
		S[A]++;
	}
	for (long long i = 1; i <= 1000000; i++) {
		X[i] = Calc(i, MOD - 2);
	}
	for (long long i = 1; i <= 1000000; i++) {
		for (long long j = 2; i * j <= 1000000; j++) X[i * j] = (MOD + X[i * j] - X[i]) % MOD;
	}
	for (long long i = 1; i <= 1000000; i++) {
		long long COUNT = 0, Cur = 0;
		for (long long j = 1; i * j <= 1000000; j++) {
			if (S[i * j] == 0) continue;
			long long P = S[i * j];
			COUNT += (((Cur * (i * j) % MOD) % MOD) * P) % MOD;
			COUNT %= MOD;
			COUNT += (((P * (P - 1) / 2) % MOD) * ((i * j * i * j) % MOD)) % MOD;
			COUNT %= MOD;
			Cur += i * j * P;
			Cur %= MOD;
		}
		ANS += (COUNT * X[i]) % MOD;
		ANS %= MOD;
	}
	cout << ANS << endl;
}

Measured memory_bytes: 15872
def main():
    mod = 10**9 + 7
    s = input()
    n = len(s)

    a_num = 0
    c_num = s.count('C')
    q_num = 0
    q_cnt = s.count('?')

    pow3, pow2, pow1, pow0 = 0, 0, 0, 0
    if q_cnt >= 3:
        pow3 = pow(3, q_cnt-3, mod)
        pow2 = pow3 * 3 % mod
        pow1 = pow2 * 3 % mod
        pow0 = pow1 * 3 % mod
    elif q_cnt == 2:
        pow2 = 1
        pow1 = 3
        pow0 = 9
    elif q_cnt == 1:
        pow1 = 1
        pow0 = 3
    else:
        pow0 = 1

    ans = 0
    for x in s:
        if x == 'A':
            a_num += 1
        elif x == 'B':
            ans += pow0 * a_num * c_num
            ans += pow1 * (q_num * c_num + a_num * (q_cnt - q_num))
            ans += pow2 * (q_num) * (q_cnt - q_num)
            ans %= mod
        elif x == 'C':
            c_num -= 1
        else:
            ans += pow1 * a_num * c_num
            ans += pow2 * (q_num * c_num + a_num * (q_cnt - q_num - 1))
            ans += pow3 * (q_num) * (q_cnt - q_num - 1)
            ans %= mod
            q_num += 1

    print(ans)

main()

Measured memory_bytes: 73304
#include <bits/stdc++.h>
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define pb push_back
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) FOR(i, 0, n)
#define ll long long
using namespace std;

const ll P = 1000000007;
int gcd(int a, int b) { return b != 0 ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a / gcd(a, b) * b; }

int main()
{
  cout << fixed << setprecision(10);
  int A,B,C;
  cin >> A >> B >> C;
  ll sum = 0;
  if(A+B+1>=C)
  {
    cout << B+C << endl;
  }
  else
  {
    cout << B+A+B+1 << endl;
  }
  return 0;
}


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

using namespace std;

int main()
{
  int N, S[200000];

  scanf("%d", &N);
  for(int i = 0; i < N; i++) {
    scanf("%d", &S[i]);
  }

  for(int i = 1; i <= N; i++) {
    if(N % i == 0) {
      bool match = true;
      for(int j = i; j < N; j += i) {
        for(int k = 0; k < i; k++) match &= S[k] == S[j + k];
      }
      if(match) {
        printf("%d\n", N / i);
        return (0);
      }
    }
  }
}

Measured memory_bytes: 3996
x1, y1, x2, y2 = map(int, input().split())
x3, y3 = x2 - y2 + y1, y2 + x2 - x1
x4, y4 = x3 - y3 + y2, y3 + x3 - x2
print(x3, y3, x4, y4)

Measured memory_bytes: 2940
#include<bits/stdc++.h>
using namespace std;
#define INF (1<<26)
struct edge{
  int from,to,cost;
  bool operator < (const edge &e)const{
    return cost < e.cost;
  }
};

vector<edge> g;
int n,m;

int pa[200],ra[200];

void init(){
  for(int i=0;i<200;i++)
    pa[i]=i,ra[i]=0;
}

int find(int x){
  if(pa[x]==x)return x;
  return pa[x]=find(pa[x]);
}

void unite(int x,int y){
  x=find(x),y=find(y);
  if(x==y)return;
  if(ra[x]>ra[y])swap(x,y);
  pa[x]=y;
  if(ra[x]==ra[y])ra[x]++;
}

int calc(int x){
  init();
  int res=0;
  for(int i=x;i<(int)g.size();i++){
    edge e=g[i];
    if(find(e.from)==find(e.to))continue;
    unite(e.from,e.to);
    res=e.cost;
  }
  for(int i=2;i<=n;i++)
    if(find(i-1)!=find(i))
      return INF;
  return res-g[x].cost;
}

int solve(){
  int ans=INF;
  for(int i=0;i<(int)g.size();i++){
    if(i&&g[i].cost==g[i-1].cost)continue;
    ans=min(ans,calc(i));
  }
  if(ans==INF)return -1;
  else return ans;
}

int main(){
  while(1){
    cin>>n>>m;
    if(n==0&&m==0)break;
    g.clear();
    for(int i=0;i<m;i++){
      edge e;
      cin>>e.from>>e.to>>e.cost;
      g.push_back(e);
    }
    sort(g.begin(),g.end());
    cout<<solve()<<endl;
  }
  return 0;
}

Measured memory_bytes: 1340
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <utility>
#include <tuple>
#include <algorithm>
#include <numeric>
#include <cstdio>
#include <cmath>
#define rep(i, n) for(int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

int main() {
  int N;
  cin >> N;
  vector<int> a(N*3);
  rep(i, N*3) cin >> a[i];
  priority_queue<int, vector<int>, greater<int>> mx;
  ll mxsum = 0;
  rep(i, N) {
    mx.push(a[i]);
    mxsum += a[i];
  }
  vector<ll> l(N+1);
  l[0] = mxsum;
  rep(i, N) {
    if (a[N+i] > mx.top()) {
      mxsum += a[N+i]-mx.top();
      mx.pop();
      mx.push(a[N+i]);
    }
    l[i+1] = mxsum;
  }
  priority_queue<int> mn;
  ll mnsum = 0;
  rep(i, N) {
    mn.push(a[N*2+i]);
    mnsum += a[N*2+i];
  }
  vector<ll> r(N+1);
  r[N] = mnsum;
  for (int i=N-1; i>=0; i--) {
    if (a[N+i] < mn.top()) {
      mnsum += a[N+i]-mn.top();
      mn.pop();
      mn.push(a[N+i]);
    }
    r[i] = mnsum;
  }
  ll ans = -1e18;
  rep(i, N+1)
    chmax(ans, l[i]-r[i]);
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3960