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

int main() {

  int N;
  cin >> N;

  map<string, int> mp;
  for (int i = 0; i < N; i++) {
    string s_;
    cin >> s_;
    mp[s_]++;
  }

  int mx = 0;
  for (auto item:mp) {
    mx = max(mx, item.second);
  }

  for (auto item:mp) {
    if (item.second == mx) {
      cout << item.first << endl;
    }
  }

  return 0;

}

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

//=============mobigcom============================
ll modinv(ll a, ll m) {
    ll b = m, u = 1, v = 0;
    while (b) {
        ll t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}

ll COM(ll n, ll k, ll mod){
  ll up = 1, down = 1;
  for (ll i = 0; i < k; ++i) {
    up *= (n - i);
    up %= mod;
  }
  for (ll i = 1; i <= k; ++i) {
    down *= modinv(i, mod);
    down %= mod;
  }
  return (up * down % mod);
}
//=================================================


//=============modpow============================
ll modpow(ll a, ll n, ll mod)
{
    ll res = 1;
    while (n > 0)
    {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
//=================================================

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  ll N, A, B;
  cin >> N >> A >> B;
  ll mod = pow(10, 9) + 7;
  ll ans = modpow(2, N, mod) - 1;
  ans -= COM(N, A, mod);
  if (ans < 0) {
    ans += mod;
  }
  ans -= COM(N, B, mod);
  if (ans < 0) {
    ans += mod;
  }
  cout << ans << "\n";
}


Measured memory_bytes: 3636
n = int(raw_input())
a = []
for i in range(n):
  a.append(raw_input())
b = set(a)
c = len(b)
d = len(a)
ans = []
if c == d:
  for i in range(n-1):
    x = a[i]
    y = a[i+1]
    z = x[-1]
    w = y[0]
    if z == w:
      ans.append(1)
    else:
      ans.append(0)
  if ans.count(1)==n-1:
    print "Yes"
  else:
    print "No"
else:
  print "No"

Measured memory_bytes: 2692
#include<iostream>
#define int long long
using namespace std;
int n,p[200000],w[200000],m;
int find(int x)
{
	if(p[x]==x)return x;
	int F=p[x];
	p[x]=find(p[x]);
	w[x]+=w[F];
	return p[x];
}
signed main()
{
	cin>>n>>m;
	for(int i=1;i<=n;i++)p[i]=i;
	while(m--)
	{
		int l,r,d;
		cin>>l>>r>>d;
		int x=find(l),y=find(r);
		if(x==y&&w[r]-w[l]!=d){cout<<"No"<<endl;return 0;}
		else p[y]=x,w[y]=w[l]+d-w[r];
	}
	cout<<"Yes"<<endl;
	return 0;
}

Measured memory_bytes: 1792
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <vector>
#include <cmath>
#include <iomanip>
using namespace std;
int main(void){
    string S,T;
    cin >> S >> T;
    int Slen,Tlen;
    Slen = S.length();
    Tlen = T.length();
    if(Tlen-Slen == 1){
        for(int i=0;i<Slen;i++){
            if(S[i] != T[i]){
                goto error;
            }
        }
        cout << "Yes" << endl;
        return 0;
    }
error:
    cout << "No" << endl;
}


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

int n;
vector<pair<int, int>> a;
vector<int> bit;
long long ans;

int getsum(int x){ // [1, x]
	int res = 0;
	while(x > 0){
		res += bit[x];
		x -= x & -x;
	}
	return res;
}

void update(int x, int t){
	while(x <= n){
		bit[x] += t;
		x += x & -x;
	}
}

int main(){
//	cin.tie(0);
//	ios::sync_with_stdio(false);
	cin >> n;
	bit.resize(n+1);
	for(int i=0; i<n; ++i){
		int t;
		cin >> t;
		a.push_back(make_pair(t, i));
	}
	sort(a.begin(), a.end());
	for(int i=0; i<n; ++i)
		a[i].first = i+1;
	sort(a.begin(), a.end(), [](const pair<int, int> &x, const pair<int, int> &y){return x.second < y.second;});
	for(int i=n-1; i>=0; --i){
		ans += getsum(a[i].first);
		update(a[i].first, 1);
	}
//	for(int i=0; i<n; ++i)
//		cout << a[i].first << " " << a[i].second << "\n";
	cout << ans << "\n";
}


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

using namespace std;

int main()
{
    int a, b;
    while (cin >> a >> b, a) {
        if (a < b) swap(a, b);
        int res = 0;
        while (b != 0) {
            int r = a % b;
            a = b;
            b = r;
            res++;
        }
        cout << a << " " << res << endl;
    }
    return 0;
}

Measured memory_bytes: 3012
#include <cstdio>
#define LL long long
const int maxn = 1005;
const LL mo = 1e9 + 7;
using namespace std;
int n, m, cnt[2], lnk[2], V;
char str[maxn][maxn]; LL k;
LL pow(LL x, LL t){
	LL res = 1; x %= mo;
	while (t > 0){
		if (t & 1) res = res * x % mo;
		x = x * x % mo;
		t >>= 1;
	}
	return res;
}
int main(){
	scanf("%d%d%lld", &n, &m, &k);
	for (int i = 1; i <= n; i++) scanf("%s", str[i] + 1);
	for (int i = 1; i <= n; i++)
		if (str[i][1] == '#' && str[i][m] == '#') cnt[0]++;
	for (int j = 1; j <= m; j++)
		if (str[1][j] == '#' && str[n][j] == '#') cnt[1]++;
	for (int i = 1; i <= n; i++)
		for (int j = 1; j <= m; j++){
			V += (str[i][j] == '#'); 
			if (str[i][j] == '#' && str[i][j + 1] == '#') lnk[0]++;
			if (str[i][j] == '#' && str[i + 1][j] == '#') lnk[1]++;
		}
	if (cnt[0] == 0 && cnt[1] == 0){
		printf("%lld\n", pow(V, k - 1));
		return 0;
	}
	if (cnt[0] > 0 && cnt[1] > 0){
		puts("1"); return 0;
	}
	if (cnt[0] > 0){
		LL ans = pow(V, k - 1) - 1ll * lnk[0] * (pow(V, k - 1) - pow(cnt[0], k - 1)) % mo * pow(V - cnt[0], mo - 2) % mo;
		printf("%lld\n", (ans + mo) % mo);
	}
	if (cnt[1] > 0){
		LL ans = pow(V, k - 1) - 1ll * lnk[1] * (pow(V, k - 1) - pow(cnt[1], k - 1)) % mo * pow(V - cnt[1], mo - 2) % mo;
		printf("%lld\n", (ans + mo) % mo);
	}
	return 0;
}

Measured memory_bytes: 1152
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>//sort,reverse
#include<utility>//pair
#include<queue>//queue,priority_queue
#include<deque>//double_ended queue
using namespace std;
typedef pair<int,int> P;//Pでpair<-,->を表す。
typedef long long LL; 
LL MOD=1000000007;

/*ここから*/

vector<LL> d;
int D;//約数の個数
void divisor(LL x){
    for(int i=1;i*i<=x;i++){
        if(x%i==0){d.push_back(i);}
    }
    D=d.size();
    for(int i=D-1;i>=0;i--){
        if(d[i]*d[i]<x){d.push_back(x/d[i]);}
    }
    D=d.size();
}

/*ここまで*/

int main()
{ 
    LL n,K;
    cin>>n>>K;
    LL a[n];
    LL sum=0;
    for(int i=0;i<n;i++){
        cin>>a[i];
        sum=sum+a[i];
    }
    //約数計算
    divisor(sum);
    //上から満たすか調べる。
    bool flg=true;
    LL ans=0;
    while(flg){
        LL x=d.back();
        d.pop_back();

        LL b[n];
        for(int i=0;i<n;i++){b[i]=a[i]%x;}
        sort(b,b+n);
        //累積和
        for(int i=1;i<n;i++){b[i]=b[i]+b[i-1];}
        int k=n-1-b[n-1]/x;
        if(b[k]<=K){flg=false;ans=x;}
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
using ld = long double;
#define rep(i,s,e) for(int (i) = (s);(i) <= (e);(i)++)

int N;
vector<i64> a;

int main(){
    cin >> N;
    a.resize(N);
    rep(i,0,N - 1){
        cin >> a[i];
    }

    using P = pair<i64,i64>;

    vector<P> vec;
    rep(i,0,N - 1) vec.emplace_back(a[i],i);

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

    set<int> st;
    st.insert(-1);
    st.insert(N);
    i64 ans = 0;
    for(auto & p : vec){
        i64 i = p.second;
        int l = *(--st.lower_bound(i));
        int r= *(st.upper_bound(i));
        ans += (i - l) * (r - i) * p.first;
        st.insert(i);
    }

    cout << ans << endl;
}


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

int main()
{
	int N;
	cin >> N;
	vector<int> p(N);

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

	int q = 0;
	int score = 0;
	for (int i = 0; i <= N; i++) {
		for (int j = 0; j < N; j++){
			if (p[j] >= i)
				q++;
		}
		if (i <= q)
			score = i;
		else break;
		q = 0;
	}
	cout << score << endl;

	return 0;
}

Measured memory_bytes: 3096
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define MOD 1000000007
#define MAX 100010
#define aout(a) REP(i,sizeof(a)) cout << a[i] << " "; cout << endl;
#define vout(v) REP(i,v,size()) cout << v[i] << " "; cout << endl;
using namespace std;
using ll = long long;
using P = pair<int,int>;
using Graph = vector<vector<int>>;

int main(){
  int N; cin>>N;
  vector<ll> A(N);
  REP(i,N) cin>>A[i];
  ll ans = 0;
  vector<ll> sum(N-1);
  sum[0] = A[0];
  FOR(i,1,N-1){
    sum[i] = (sum[i-1] + A[i]) % MOD;
  }
  REP(i,N-1){
    int tmp = (A[i+1] * sum[i]) % MOD;
    ans = (ans + tmp) % MOD;
  }
  cout << ans;
}

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

int main()
{
	int T, P, R;
	while (cin >> T >> P >> R && T != 0 && P != 0 && R != 0)
	{
		int accept[51][11] = {};
		int wrong[51][11] = {};
		int penalty[51] = {};
		int teamID[51] = {};
		for (int i = 1; i <= T; i++)
		{
			teamID[i] = i;
		}

		for (int i = 0; i < R; i++)
		{
			int tId,pId,time;
			cin >> tId >> pId >> time;
			char message[10];
			cin >> message;
			if (message[0] == 'C' && accept[tId][pId] == 0)
			{
				accept[tId][pId]++;
				penalty[tId] += (wrong[tId][pId] * 1200 + time);
			}
			else
			{
				wrong[tId][pId]++;
			}
		}
		int acceptSum[51];
		for (int i = 0; i < 51; i++)
		{
			acceptSum[i] = 99;
		}
		for (int i = 1; i <= T; i++)
		{
			int sum = 0;
			for (int j = 1; j <= P; j++)
			{
				sum += accept[i][j];
			}
			acceptSum[i] = sum;
		}
		for (int i = 1; i <= T - 1; i++)
		{
			for (int j = i + 1; j <= T; j++)
			{
				if (acceptSum[teamID[i]] < acceptSum[teamID[j]] ||
					(acceptSum[teamID[i]] == acceptSum[teamID[j]] && penalty[teamID[i]] > penalty[teamID[j]])|| 
					(acceptSum[teamID[i]] == acceptSum[teamID[j]] && penalty[teamID[i]] == penalty[teamID[j]] && teamID[i] > teamID[j]) )
				{
					int tmp = teamID[i];
					teamID[i] = teamID[j];
					teamID[j] = tmp;
				}
			}
		}
		
		for (int i = 1; i <= T; i++)
		{
			cout << teamID[i] << " " << acceptSum[teamID[i]] << " " << penalty[teamID[i]] << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 1168
while True:
    a, op, b = input().split()   # 3変数ともに文字列として読み込む
    a =int(a)                   # a を整数に変換
    b = int(b)                   # b を整数に変換


    if op=="?": # opが"?"の時は終了
        break
    else:  
        if op== '+':
            print(a+b)
        elif op== '-':
            print(a-b)
        elif op== '*':
            print(a*b)
        elif op== '/':
            print(a//b)    



Measured memory_bytes: 5592
import sys, bisect, math, itertools, string, queue, copy
# import numpy as np
# import scipy
from collections import Counter,defaultdict,deque
from itertools import permutations, combinations
from heapq import heappop, heappush
from fractions import gcd
# input = sys.stdin.readline
sys.setrecursionlimit(10**8)
mod = 10**9+7
def inp(): return int(input())
def inpm(): return map(int,input().split())
def inpl(): return list(map(int, input().split()))
def inpls(): return list(input().split())
def inplm(n): return list(int(input()) for _ in range(n))
def inplL(n): return [list(input()) for _ in range(n)]
def inplT(n): return [tuple(input()) for _ in range(n)]
def inpll(n): return [list(map(int, input().split())) for _ in range(n)]
def inplls(n): return sorted([list(map(int, input().split())) for _ in range(n)])


def f(dp,n,k):
    if dp[k] != -1:
        return dp[k]
    if k == 1:
        return 1
    cnt = 0
    cnt = pow(k,n,mod)
    for i in range(2,k+1):
        cnt += mod
        cnt -= f(dp,n,k//i) 
        cnt %= mod
    dp[k] = cnt       
    return cnt

def main():
    n,k = inpm()
    ans = 0
    dp = [-1 for _ in range(k+1)]
    for e in range(1,k+1):
        ans += e*f(dp,n,k//e)
        ans %= mod
    print(ans)
    
if __name__ == "__main__":
    main()

Measured memory_bytes: 85108
#include <bits/stdc++.h>
using namespace std;
#define pp pair<int,int>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ll long long
#define all(a) (a).begin(),(a).end()
ll MOD=1000000007;
ll mod=998244353;
int inf=1000001000;
ll INF=10000000000000000;


int main(){
    double xs,ys,xt,yt;
    cin >> xs >> ys >> xt >> yt;
    int n;
    cin >> n;
    vector<vector<double>> e(n+2,vector<double>(n+2));
    double Inf=-1;
    vector<double> d(n+2,Inf);
    d.at(0)=0;
    vector<pair<pair<double,double>,double>> a(n+2);
    a.at(0).first.first=xs;
    a.at(0).first.second=ys;
    a.at(0).second=0;
    a.at(n+1).first.first=xt;
    a.at(n+1).first.second=yt;
    a.at(n+1).second=0;
    rep(i,n){
        double f,g,h;
        cin >> f >> g >> h;
        a.at(i+1).first.first=f;
        a.at(i+1).first.second=g;
        a.at(i+1).second=h;
    }
    double z=0;
    rep(i,n+2){
        rep(j,n+2){
            e.at(i).at(j)=max(z,sqrt(pow(a.at(i).first.first-a.at(j).first.first,2)+pow(a.at(i).first.second-a.at(j).first.second,2))-a.at(i).second-a.at(j).second);
        }
    }
    queue<int> q;
    q.push(0);
    while (!q.empty()){
        int k=q.front();
        q.pop();
        rep(i,n+2){
            if (d.at(i)>d.at(k)+e.at(k).at(i) || d.at(i)==-1){
                d.at(i)=d.at(k)+e.at(k).at(i);
                q.push(i);
            }
        }
    }
    cout << fixed << setprecision(10) << d.at(n+1) << endl;
}


Measured memory_bytes: 9216
s = str(input())
c = s[2:-1].count("C")
if (s[1:s.find("C")]+s[s.find("C")+1:]).islower():
    count = 1
else:
    count = 0
if s[0] == "A" and count == 1 and c == 1:
    print("AC")
else:
    print("WA")

Measured memory_bytes: 3060
#include"bits/stdc++.h"
#include<boost/multi_array.hpp>
#include<boost/optional.hpp>
#include<boost/range/irange.hpp>
#include<boost/range/algorithm.hpp>
#include<boost/range/adaptors.hpp>
using namespace std;
namespace adaptor = boost::adaptors;

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep3(i,m,n) for(int (i)=m;(i)<=(n);(i)++)
#define rep3rev(i,m,n) for(int (i)=m;(i)>=(n);(i)--)
#define cy cout << "Yes" << endl
#define cn cout << "No" << endl
typedef long long ll;

void Main()
{
	int A, B, C;
  	cin >> A >> B >> C;
  	
  if( C >=A && C<= B )cy;
  else cn;
	return;
}

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


Measured memory_bytes: 256
#include <iostream>
#include <vector>

using namespace std;

int main()
{
    int N, M;
    cin >> N >> M;
    vector<int> Height;
    int h;
    for (int i = 0; i < N; i++)
    {
        cin >> h;
        Height.push_back(h);
    }
    int a, b;
    vector<int> A;

    vector<int> B;

    vector<bool> good;
    for (int i = 0; i < N; i++)
    {
        good.push_back(true);
    }



    for (int i = 0; i < M; i++)
    {
        cin >> a >> b;
        a--;
        b--;

        if (Height[a] > Height[b])
        {
            good[b] = false;
            /* code */
        }
        else if (Height[a] < Height[b])
        {
            good[a] = false;
            /* code */
        }else
        {
            good[a] = false;
            good[b] = false;
        }
        
        
    }
    
    int res = 0;
    for (int i = 0; i < N; i++)
    {
        if (good[i])
        {
            res++;
            /* code */
        }
        
    }
    cout << res << endl;




    return 0;
}

Measured memory_bytes: 3924
local n,m=io.read("n","n")
local stair={}
for i=1,n do
    stair[i]=true
end
for i=1,m do
    local a=io.read("n")
    stair[a]=false
end

local dp={}
dp[0]=1
for i=1,n do
    dp[i]=0
end

for now=0,n-1 do
    for next=now+1,math.min(n,now+2) do
        if stair[next] then
            dp[next]=dp[next]+dp[now]
            dp[next]=dp[next]%1000000007
        end
    end
end
print(dp[n])

Measured memory_bytes: 4472
fun main () {
    val (N, A, B) = readLine()!!.split(" ").map(String::toLong)

    val term = (N / (A + B))
    val lastMod = (N % (A + B))

    var blueCount = term * A
    if (lastMod >= A) blueCount += A
    else blueCount += lastMod
    print(blueCount)
}


Measured memory_bytes: 36532
#include <iostream>
#include <string>
#include <cstring>
#include <algorithm>
#include <functional>
#include <cmath>
#include <set>
#include <queue>
#include <vector>
#include <climits>
#include <sstream>
#include <iomanip>
#include <map>
using namespace std;

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

	auto result = 0ll;
	for (auto i = K + 1; i <= N; ++i)
	{
		auto temp = N / i;
		result += temp * (i - K);
		if (K > 0)
		{
			result += max(0ll, (N % i) - K + 1);
		}
		else
		{
			result += max(0ll, N % i);
		}
	}

	cout << result << endl;

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define SORT(a) sort((a).begin(), (a).end())
#define RSORT(a) reverse((a).begin(), (a).end())
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long ll;
const long long INF = 1LL << 60;

int main() {
  int n;
  ll a, b;
  cin >> n >> a >> b;
  vector<ll> x(n);
  for (int i = 0; i < n; i++) cin >> x[i];
  ll total = 0;
  for (int i = 0; i < n - 1; i++) {
    total += min((x[i + 1] - x[i]) * a, b);
  }
  cout << total << endl;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define REP(i, s, n) for (int i = s; i < n; i++)
#define ALL(a) a.begin(), a.end()
#define MOD 1000000007
using namespace std;
typedef long long ll;

int main() {
    int H, N; cin >> H >> N;
    ll sum = 0;
    REP(i, 0, N) {
        int a; cin >> a;
        sum = sum + a;
    }
    if (sum >= H) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
  string s,t;
  cin >> s;
  cin >> t;
  sort (s.begin(), s.end() );
  sort (t.begin(), t.end() );
  reverse(t.begin(), t.end() );
  if (s < t) cout << "Yes" << endl; 
  else cout << "No" <<endl;
}

Measured memory_bytes: 3616
#include <stdio.h>
int main (){
	int a,b;
	char op;
	for (int i=1;i>0 ; i++){
	scanf ("%d %c %d",&a,&op,&b);
	if (op=='?')
	{
		break;
	}
	if (op == '+'){
		printf ("%d\n",a+b);
	}
		else if (op == '-'){
		printf ("%d\n",a-b);
	}
		else if (op == '/'){
		printf ("%d\n",a/b);
	}
		else if (op == '*'){
		printf ("%d\n",a*b);
	}
}
	return 0;
}


Measured memory_bytes: 1920
#include<vector>
#include<map>
#include<climits>
#include<set>
#include<queue>
#include<algorithm>
#include<functional>
#include<numeric>
#include<utility>
#include<sstream>
#include<iostream>
#include<iomanip>
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<cctype>
#include<string>
#include<bitset>
#include<cstring>
#include<list>
using namespace std;
typedef vector<string>vs;
typedef vector<int>vi;
typedef vector<vi>vvi;
typedef pair<int,int>pii;
typedef long long ll;
typedef pair<ll,ll>pll;
#define REP(i,x,n) for(int i=(x);i<(n);++i)
#define rep(i,x) REP(i,0,(x))
#define fi first
#define se second
#define each(i,c) for(typeof(c)::iterator i=(c).begin();i!=(c).end();++i)
#define all(c) (c).begin(),(c).end()
#define rall(c) (c).rbegin(),(c).rend()
#define pb push_back

const int dx[]={-1,0,1,0};
const int dy[]={0,-1,0,1};
int X,Y;
int stx,sty,skx,sky;
int fld[50][50];
bool f[50][50][50][50];

struct data{
    int tx,ty,kx,ky,cnt;
    data(int a,int b,int c,int d,int e):
        ty(a),tx(b),ky(c),kx(d),cnt(e){}
    data(){}
};
int solve(){
    fill_n(***f,50*50*50*50,false);
    queue<data>Q;Q.push(data(sty,stx,sky,skx,0));
    while(Q.size()){
        data d=Q.front();Q.pop();
        if(f[d.ty][d.tx][d.ky][d.kx])continue;
        f[d.ty][d.tx][d.ky][d.kx]=true;
        if(d.ty==d.ky&&d.tx==d.kx)return d.cnt;
        if(d.cnt>100)continue;
        rep(i,4){
            int nty=d.ty+dy[i];
            int ntx=d.tx+dx[i];
            int nky=d.ky+dy[(i+2)%4];
            int nkx=d.kx+dx[(i+2)%4];
            if(nty<0||nty>=Y||ntx<0||ntx>=X||fld[nty][ntx]){
                nty=d.ty;ntx=d.tx;
            }
            if(nky<0||nky>=Y||nkx<0||nkx>=X||fld[nky][nkx]){
                nky=d.ky;nkx=d.kx;
            }
            Q.push(data(nty,ntx,nky,nkx,d.cnt+1));
        }
    }
    return -1;
}

int main(){
    while(cin>>X>>Y,X||Y){
        cin>>stx>>sty;
        cin>>skx>>sky;
        stx--;sty--;skx--;sky--;
        rep(i,Y)rep(j,X)cin>>fld[i][j];
        int ans=solve();
        if(ans==-1)cout<<"NA"<<endl;
        else cout<<ans<<endl;
    }
    return 0;
}

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

#define fst first
#define snd second
#define ll long long
#define ld long double
#define pb push_back
#define emp emplace_back
#define pii pair<int, int>
#define usg unsigned
#define sg signed
#define mp make_pair

using namespace std;

void setIO(){
	ios::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	// freopen("input.txt", "r", stdin);
	// freopen("output.txt", "w", stdout);
}

const ld PI = 4*atan((ld)1);
const ll INF = 1e18+7;
const int mxn = 5e3+7;

ll dp[mxn][mxn];
int adj[mxn], v[mxn], cy[mxn];

int main(){
	setIO();
	int n, k;
	cin >> n >> k;
	for (int i = 0; i < n; i++){
		int x; cin >> x;
		adj[i] = x-1;
	}
	for (int i = 0; i < n; i++)
		cin >> v[i];
	for (int i = 0; i < n; i++){
		int cur = adj[i], ct = 1;
		dp[i][0] = v[i];
		while (cur != i){
			dp[i][ct] = dp[i][ct-1]+v[cur];
			cur = adj[cur];
			ct++;
		}
		cy[i] = ct;
	}
	ll ans = 0;
	for (int i = 0; i < n; i++){
		ll sum = 0;
		if (dp[i][cy[i]-1] > 0){
			sum += (k/cy[i]*dp[i][cy[i]-1]);
			ll mx = 0, mx2 = 0;
			for (int j = 0; j < k%cy[i]; j++)
				mx = max(mx, dp[i][j]);
			for (int j = 0; j < cy[i]; j++)
				mx2 = max(mx2, dp[i][j]);
			sum = max(sum+mx, sum-dp[i][cy[i]-1]+mx2);
		}
		else{
			ll mx = 0;
			for (int j = 0; j < cy[i]; j++)
				mx = max(mx, dp[i][j]);
			sum += mx;
		}
		ans = max(ans, sum);
	}
	if (!ans){
		ans = -INF;
		for (int i = 0; i < n; i++)
			ans = max(ans, (ll)v[i]);
	}
	cout << ans << endl;
}

Measured memory_bytes: 199264
n = int(input())
num_array = input().split(" ")

point = 0
for i in range(n-2):
    if int(num_array[i]) < int(num_array[i+1]) < int(num_array[i+2]):
        point += 1
    if int(num_array[i]) > int(num_array[i+1]) > int(num_array[i+2]):
        point += 1

print(point)

Measured memory_bytes: 3060
def gcd(a, b):
    big = max(a, b)
    small = min(a, b)
    
    r = small
    while r != 0:
        r = big % small
        big = small
        small = r
    
    return big
    
def lcm(a, b):
    gcd_num = gcd(a, b)
    return (a // gcd_num) * (b // gcd_num) * gcd_num

def main():
    n, m = map(int, input().split())
    s = input()
    t = input()
    
    a = n // gcd(n, m)
    b = m // gcd(n, m)
    lcm_num = lcm(n, m)
    
    ans = lcm_num
    for i in range(n // a):
        if s[a * i] != t[b * i]:
            ans = -1
            break
    
    print(ans)
    
if __name__ == '__main__':
    main()

Measured memory_bytes: 3316
#include <iostream>
#include <climits>
#include <cmath>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <string>
#define INF_INT (INT_MAX / 2)
#define INF_LONG (LONG_MAX / 2)
//#define DEBUG true
#define DEBUG false
#define MAX_H 50
using namespace std;

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

  int h, w;
  cin >> h >> w;
  string s[MAX_H];
  for(int i = 0; i < h; i++) cin >> s[i];

  int dx[4] = {0, 1, 0, -1};
  int dy[4] = {-1, 0, 1, 0};
  for(int i = 0; i < h; i++){
    for(int j = 0; j < w; j++){
      if(s[i][j] == '.') continue;
      bool exist = false;
      for(int k = 0; k < 4; k++){
        int ni = i + dy[k];
        int nj = j + dx[k];
        if(!(0 <= ni && ni < h) && (0 <= nj && nj < w))
          continue;
        if(s[ni][nj] == '#'){
          exist = true;
          break;
        }
      }
      if(!exist){
        cout << "No" << endl;
        return 0;
      }
    }
  }

  cout << "Yes" << endl;

  return 0;
}


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

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

int main() {
  int h, w; cin>>h>>w;
  vector<string> a(h);
  for (int i = 0; i < h; i++) cin>>a[i];

  vector<vector<int>> cost(h, vector<int>(w, 1e9));
  queue<int> q;
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      if (a[i][j] == '#') {
        cost[i][j] = 0;
        q.push(i*w + j);
      }
    }
  }

  while (!q.empty()) {
    int m = q.front(); q.pop();
    int y = m / w, x = m % w;
    for (int i = 0; i < 4; i++) {
      int nx = x + dx[i], ny = y + dy[i];
      if (0 <= nx and nx < w and 0 <= ny and ny < h) {
        if (cost[y][x] + 1 < cost[ny][nx]) {
          cost[ny][nx] = cost[y][x] + 1;
          q.push(ny*w + nx);
        }
      }
    }
  }

  int ans = 0;
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      ans = max(ans, cost[i][j]);
    }
  }
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 9344
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <iomanip>
#include <stack>
#include <queue>
#include <numeric>
#include <map>
#include <unordered_map>
#include <set>
#include <fstream>
#include <chrono>
#include <random>
#include <bitset>
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define sz(x) ((int)(x).size())
#define pb push_back
using ll = long long;
using namespace std;
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; }
ll gcd(ll a, ll b) {return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) {return a/gcd(a,b)*b;}

int main(){
  int A, B, T; cin >> A >> B >> T;
  cout << (T/A)*B << endl;
  return 0;
}


Measured memory_bytes: 3576
import math
a, b, h, m = map(int, input().split())

m_a = m * 6
h_a = h * 30
if m > 0:
    h_a = h_a + m * 0.5
print(math.sqrt(a ** 2 + b ** 2 - (2 * a * b * math.cos(math.radians(max(m_a, h_a) - min(m_a, h_a))))))


Measured memory_bytes: 9388
from collections import deque
import sys
sys.setrecursionlimit(10**7)
#input = sys.stdin.readline
def isprime(n):
  if n <= 1:
    return False
  else:
    for i in range(2,(int(n**0.5)+2)):
      if n%i == 0:
        return False
    return True

def solve():
  n = int(input())
  query = []
  for i in range(3,55556):
    if isprime(i):
      if i%5 == 2:
        query.append(i)
  for i in range(n):
    print(query[i],end =" ")
      
solve()

Measured memory_bytes: 3572
#include<iostream>
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,m,c;
    long long int vote=0;
    cin>>n>>m;
    int ar[n];
    for(int i=0;i<n;i++){
        cin>>ar[i];
        vote+=ar[i];
    }
    c=n;
    float d=((float)vote/(4*m));
    for(int i=0;i<n;i++){
        if(ar[i]<d){
            c--;
        }
    }
    if(c>=m){ 
        cout<<"Yes"<<endl;
    }
    else {
        cout<<"No"<<endl;
    }
}






Measured memory_bytes: 256
#include <iostream>
#include <math.h>
using namespace std;
int main() {
  int j=0;
  for(;;){
    string n = "";
    cin >> n;
	if (n == "") break;
    string a = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
    string b = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
    string o = "";
	if (j) cout << " "; 
    for (int i=0; i<n.size(); i++){
      if (a.find(n[i]) != -1) {
        o += b[a.find(n[i])];
      } else {
        o += n[i];
      }
    }
	 cout << o;
	 j++;
  }
  cout << endl;
}

Measured memory_bytes: 3148
import java.util.Scanner;

public class Main {
	static int cnt=0;
	public static void Merge(int a[],int start,int end){
		if (start>=end) return;
		int center=(start+end)/2;
		Merge(a,start,center);
		Merge(a,center+1,end);
		int n1=center-start+1;
		int n2=end-center;
		int[] L=new int[n1];
		int[] R=new int[n2];
		for (int i=0;i<n1;i++){L[i]=a[start+i];}
		for (int i=0;i<n2;i++){R[i]=a[center+1+i];}
		int i=0; int j=0;
		for (int k=start;k<=end;k++){
			cnt++;
			if (i==n1) a[k]=R[j++];
			else if (j==n2) a[k]=L[i++];
			else if (L[i]<=R[j]) a[k]=L[i++];
			else a[k]=R[j++];
		}
	}
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
	    int n = in.nextInt();
	    int[] A = new int[n];
	    for (int i = 0; i<n; i++) {
	      A[i] = in.nextInt();
	    }
		Merge(A,0,n-1);
		for (int i=0;i<n;i++){
			System.out.print(A[i]);
			if (i<n-1) System.out.print(" ");
		}
		System.out.println();
		System.out.println(cnt);
	}
}

Measured memory_bytes: 169088
import java.util.*;
 
public class Main{
  public static int[] dp;
  public static void main(String[]args){
    Scanner sc =  new Scanner(System.in);
    int N = Integer.parseInt(sc.nextLine());
    String[] s = sc.nextLine().split(" ");
    double[] p = new double[N];
    for(int i = 0; i< N; i++){
      p[i] = Double.parseDouble(s[i]);
    }
    
    double[][] dp = new double[N+1][N+1];
    dp[0][0] = 1.0;
    
    for(int i = 0; i < N; i++){
      for(int j = 0; j <= i; j++){
        dp[i+1][j+1] += dp[i][j] * p[i];
        dp[i+1][j] += dp[i][j] * (1.0 - p[i]);
      }
    }
    double ans = 0.0;
    for(int i = (N/2)+1; i <= N; i++){
      ans += dp[N][i];
    }
    System.out.println(ans);
  }
}

Measured memory_bytes: 133052
# -*- coding: utf-8 -*-
n = int(input())
s = input()

cnt = 0
for i in range(1000):
    cand = "{:03d}".format(i)
    idx1 = s.find(cand[0])
    if idx1 == -1:
        continue

    idx2 = s[idx1+1:].find(cand[1])
    if idx2 == -1:
        continue

    idx3 = s[idx2+idx1+2:].find(cand[2])
    if idx3 == -1:
        continue

    cnt += 1

print(cnt)


Measured memory_bytes: 3060
n=int(input())
a=input().split()
b=input().split()
c=input().split()
to=0

for i in range(n):
    to+=int(b[int(a[i])-1])
    if i!=0 and int(a[i])-int(a[i-1])==1:
        to+=int(c[int(a[i-1])-1])
print(to)


Measured memory_bytes: 3060
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
	public static void main(String[] args)throws IOException{
		try{
			BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
			String str = br.readLine();
			String result = br.readLine();

			int slen = str.length();
			int rlen = result.length();
			int j = 0;
			for(int i = 0; i < slen; i++){
				if(str.charAt(i) == result.charAt(0)){
					int count = i;
					for(j = 0; j < rlen; j++){
						count = (i + j) % slen;
						if(str.charAt(count) != result.charAt(j)){
							break;
						}
					}
				}
				if(rlen == j){
					break;
				}
			}
			if(rlen == j){
				System.out.println("Yes");
			}else{
				System.out.println("No");
			}

		}catch(IOException e){
			System.err.println(e);
		}
	}
}

Measured memory_bytes: 24356
s = input()

torf = True


if s[0] != "A":
    torf = False


if s[2:-1].count("C") != 1:
    torf = False

cindex = s[2:-1].find("C") + 2

slist = list(s)

slist.pop(cindex)
slist.pop(0)

s1 = "".join(slist)
if s1.islower() != True:
    torf = False

if torf:
    print("AC")
else :
    print("WA")


Measured memory_bytes: 3060
#include <iostream>

int main(){
  int h;
  int key[251];
  std::cin >> h;
  for(int i=0; i<h; i++){ std::cin >> key[i]; }

  for(int i=0; i<h; i++){
    std::cout << "node " << i+1 << ": ";
    std::cout << "key = " << key[i] << ", ";
    if( i>0 ){ std::cout << "parent key = " << key[(i-1)/2] << ", "; }
    if( i*2+1<h ){ std::cout << "left key = " << key[2*i+1] << ", "; }
    if( i*2+2<h ){ std::cout << "right key = " << key[2*i+2] << ", "; }
    std::cout << std::endl;
  }
  return 0;
}



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

int main() {
    int N, W; cin >> N >> W;
    vector<vector<ll> > dp(N+1, vector<ll> (100000+1));
    for (int i = 0; i <= N; i++) {
        for (int j = 0;j <= 100000; j++) {
          dp[i][j] = INF;
        }
    }
  	dp[0][0] = 0;
    ll w, v;
    for (int i = 1; i <= N; i++) {
        cin >> w >> v;
        for (int j = 0; j <= 100000; j++) {
            if (j >= v)
                dp[i][j] = min(dp[i-1][j-v] + w, dp[i-1][j]);
            else
                dp[i][j] =  dp[i-1][j];
        }
    }
    int ans = 100000;
    for (int i = 100000; i >= 0; i--) {
        if (dp[N][i] <= W) {
          ans = i;
          break;
        }
    }
    cout << ans << endl;;
}


Measured memory_bytes: 80256
#include<bits/stdc++.h>
using namespace std;
int main(void){
  int a,b,k;
  cin>>a>>b>>k;
  for(int i = 0; i < k; i++) {
    if(i%2==0){
      if(a%2==1) a--;
      b+=(a/2);
      a/=2;
    }else{
      if(b%2==1) b--;
      a+=(b/2);
      b/=2;
    }
  }
  cout << a <<" "<<b;
}

Measured memory_bytes: 256
import java.util.Scanner;

class Main
{
	public static void main(String args[])
	{
		boolean not[] = new boolean[100000];
		not[0] = true;
		not[1] = true;
		int pCount = 2;
		for (int i = 2; i * i < 100000; i++)
		{
			if (not[i]) continue;
			for (int x = (i << 1); x < 100000; x += i)
			{
				if (not[x]) continue;
				not[x] = true;
				pCount++;
			}
		}
		int primes[] = new int[100000 - pCount];
		int index = 0;
		for (int i = 0; i < 100000; i++)
		{
			if (!not[i])
			{
				primes[index] = i;
				index++;
			}
		}
		Scanner sc = new Scanner(System.in);
		while (true)
		{
			int n = sc.nextInt();
			if (n == 0) break;
			int count = 0;
			int m = n / 2 + 1;
			for (int i = 0; primes[i] < m; i++)
			{
				if (not[n - primes[i]]) continue;
				count++;
			}
			System.out.println(count);
		}
	}
}

Measured memory_bytes: 13000
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> P;
typedef pair<int,int> Pi;
#define rep(i,n) for(ll i=0;i<n;i++)
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define fi first
#define se second
#define endl "\n"

template<typename T> inline bool chmax(T &a, T b){if(a<b){a=b;return true;}return false;}
template<typename T> inline bool chmin(T &a, T b){if(a>b){a=b;return true;}return false;}
template<typename T> ostream& operator<<(ostream& s,const complex<T>& d) {return s<<"("<<d.real()<<", "<<d.imag()<< ")";}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const pair<T1,T2>& d) {return s<<"("<<d.first<<", "<<d.second<<")";}
template<typename T> ostream& operator<<(ostream& s, const vector<T>& d){int len=d.size();rep(i,len){s<<d[i];if(i<len-1) s<<" ";}return s;}
template<typename T> ostream& operator<<(ostream& s,const vector<vector<T>>& d){int len=d.size();rep(i,len){s<<d[i]<<endl;}return s;}
template<typename T> ostream& operator<<(ostream& s,const set<T>& v){s<<"{ ";for(auto itr=v.begin();itr!=v.end();++itr) {if (itr!=v.begin()) {s<< ", ";}s<<(*itr);}s<<" }";return s;}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const map<T1,T2>& m){s<<"{"<<endl;for(auto itr=m.begin();itr!=m.end();++itr){s<<" "<<(*itr).first<<" : "<<(*itr).second<<endl;}s<<"}"<<endl;return s;}

const ll mod=1e9+7;
const ll inf=1e17;
const int INF=1e9;
const double PI=acos(-1);
const double EPS=1e-10;

int main(){
	cin.tie(0);ios::sync_with_stdio(false);
	ll n;
	cin>>n;
	vector<ll> a(n),b(n);
	rep(i,n){
		cin>>a[i];
		b[i]=a[i];
	}
	ll sum=0,ans=0;
	//+,-,+,....てなる
	rep(i,n){
		if(i%2==0){
			if(sum+a[i]<=0){
				ll tar=1-sum;
				ans+=tar-a[i];
				sum=1;
			}else{
				sum+=a[i];
			}
		}else{
			if(sum+a[i]>=0){
				ll tar=-1-sum;
				ans+=a[i]-tar;
				sum=-1;
			}else{
				sum+=a[i];
			}
		}
	}
	//-,+,-,....
	ll cnt=0;
	sum=0;
	rep(i,n){
		if(i%2==1){
			if(sum+a[i]<=0){
				ll tar=1-sum;
				cnt+=tar-a[i];
				sum=1;
			}else{
				sum+=a[i];
			}
		}else{
			if(sum+a[i]>=0){
				ll tar=-1-sum;
				cnt+=a[i]-tar;
				sum=-1;
			}else{
				sum+=a[i];
			}
		}
	}
	chmin(ans,cnt);
	cout<<ans<<endl;
}

Measured memory_bytes: 1792
#include <iostream>
using namespace std;
int main(void){
	string a,b;
	cin >> a >> b;
	if(a=="H"){
		if(b=="H")cout<<"H";
		else cout<<"D";
	}else{
		if(b=="H")cout<<"D";
		else cout<<"H";
	}
	return 0;
}
	

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

using namespace std;


//repetition
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define euc_dis(x, y) sqrt(x*x + y*y)

#define pb push_back
#define INF 999999999
#define MOD 1000000007
#define sp ' '


//typedef
typedef long long ll;
typedef pair<int, int> pint;
typedef pair<long, long> pll;
typedef map<int, int> mint;
typedef set<int> sint;
typedef vector<int> vint;
typedef vector<char> vchr;
typedef vector<long long> vll;
typedef vector<string> vstr;


ll mod(ll a, ll b){return (a%b+b)%b;}
ll gcd(ll a, ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b){return a*b/gcd(a,b);}
void Yes(){cout << "Yes" << endl;}
void No(){cout << "No" << endl;}
void Judge(bool b){b?Yes():No();}
void YES(){cout << "YES" << endl;}
void NO(){cout << "NO" << endl;}
void JUDGE(bool b){b?YES():NO();}
ll powMod(ll a, ll b, ll c){ll ans=1; rep(i, b){ans=ans*a%c;} return ans;}
double distance(ll x1, ll y1, ll x2, ll y2){return sqrt((x1-x2)*(x1-x2) + (y1-y2)*(y1-y2));}

template<typename T>
void ppp(T n){cout << n << endl;}
template<typename T>
void dpp(T n){cerr << n << endl;}
template<typename T>
void vpp(T a){rep(i,a.size()){cout << a[i] << endl;}}
template<typename T>
void vdp(T a){rep(i,a.size()){cerr << a[i];}cerr << endl;}

const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
const int ddx[8] = {1,0,-1,0,1,-1,-1,1};
const int ddy[8] = {0,1,0,-1,1,1,-1,-1};


const int nmax = 50;

int n, m;
int a[101], b[101];

bool graph[101][101];
bool visited[101];

void dfs(int v){
    visited[v] = true;
    for(int w = 0; w < n; ++w){
        if(!graph[v][w]) continue;
        if(visited[w]) continue;
        dfs(w);
    }

}


int main(){
    int ans = 0;

    cin >> n >> m;

    for(int i = 0; i < m; ++i){
        cin >> a[i] >> b[i];
        a[i]--;
        b[i]--;
        graph[a[i]][b[i]] = graph[b[i]][a[i]] = true;
    }

    for(int i = 0; i < m; ++i){

        graph[a[i]][b[i]] = graph[b[i]][a[i]] = false;

        for(int j = 0; j < n; ++j){
            visited[j] = false;
        }

        dfs(1);

        bool bridge = false;
        for(int j = 0; j < n; ++j){
            if(!visited[j]) bridge = true;
        }

        if(bridge) ++ans;

        graph[a[i]][b[i]] = graph[b[i]][a[i]] = true;

    }

    ppp(ans);

    return 0;
}


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

#define rep(i,x,y) for(int i=(x);i<(y);++i)
#define debug(x) #x << "=" << (x)

#ifdef DEBUG
#define _GLIBCXX_DEBUG
#define print(x) std::cerr << debug(x) << " (L:" << __LINE__ << ")" << std::endl
#else
#define print(x)
#endif

const int inf=1e9;
const int64_t inf64=1e18;
const double eps=1e-9;

template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec){
    os << "[";
    for (const auto &v : vec) {
    	os << v << ",";
    }
    os << "]";
    return os;
}

using i64=int64_t;

void solve(){
    string S;
    cin >> S;
    cout << S.substr(0,S.size()-string("FESTIVAL").size()) << endl;
}

int main(){
    std::cin.tie(0);
    std::ios::sync_with_stdio(false);
    cout.setf(ios::fixed);
    cout.precision(16);
    solve();
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,n) for (int i=0; i<(n); ++i)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
using namespace std;
typedef long long ll;
int main(){
  int a,b;
  cin >> a >>b;
  if(13<=a){
    cout << b << endl;
  }else if(6<=a){
    cout << b/2 << endl;
  }else{
    cout << 0 << endl;
  }
}

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

int main() {
  int n;cin>>n;
  string sn[n];rep(i,n)cin>>sn[i];
  sort(sn, sn+n);
  int cnt=1;
  rep(i,n-1) {
    if (sn[i]!=sn[i+1]) cnt++;
  }
  cout<<cnt;
}


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

#define rep(i, n) for(int i = 0; i < n; i++)
#define ALL(v) (v).begin(), (v).end()

int main()
{
  int X, Y, Z, K; cin >> X >> Y >> Z >> K;
  vector<ll> A(X), B(Y), C(Z);
  rep(i, X) cin >> A[i];
  rep(i, Y) cin >> B[i];
  rep(i, Z) cin >> C[i];

  vector<ll> AB;
  for (int i = 0; i < X; ++i) {
    for (int j = 0; j < Y; ++j) {
      AB.push_back(A[i]+B[j]);
    }
  }

  sort(ALL(AB), greater<ll>());

  vector<ll> ABC;
  for (int i = 0; i < min(K, (int)AB.size()); ++i) {
    for (int j = 0; j < Z; ++j) {
      ABC.push_back(AB[i]+C[j]);
    }
  }

  sort(ALL(ABC), greater<ll>());

  rep(i, K) cout << ABC[i] << endl;
}

Measured memory_bytes: 43312
N = int(input())
city = []
for i in range(N):
    city_i = [i] + list(map(int,input().split()))
    city.append(city_i)
#print(city)

edges = []
city.sort(key = lambda x:x[1])
for i in range(N-1):
    w = city[i+1][1] - city[i][1]
    edges.append((w,city[i][0],city[i+1][0]))

city.sort(key = lambda x:x[2])
for i in range(N-1):
    w = city[i+1][2] - city[i][2]
    edges.append((w,city[i][0],city[i+1][0]))
edges.sort()
#print(edges)



def find(x):
    if par[x] < 0:
        return x
    else:
        par[x] = find(par[x])
        return par[x]

def unite(x,y):
    x = find(x)
    y = find(y)
    if x == y:
        return False
    else:
        if par[x] > par[y]:
            x,y = y,x
        par[x] += par[y]
        par[y] = x
        return True

def same(x,y):
    return find(x) == find(y)

par = [-1]*N

ans = 0
for e in edges:
    if same(e[1],e[2]):
        continue
    unite(e[1],e[2])
    ans += e[0]
print(ans)



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

#define int long long

signed main() {
	// your code goes here
	int n;
	cin>>n;
	map<int,int>mp;
	bool flag = 1;
	for(int i = 0; i<n; ++i){
	    int x;
	    cin>>x;
	    mp[x]++;
	    if(mp[x]>1)flag = 0;
	}
	if(flag)cout<<"YES";
	else cout<<"NO";
}


Measured memory_bytes: 12800
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <vector>
#include <set>

#define mod 1000000007
#define MAX_N 100000

using namespace std;

bool already[1000001];

int main()
{
    int K, counter, resto;

    scanf("%d", &K);

    memset(already, 0, sizeof already);

    counter = 1;
    resto = 7 % K;
    already[resto] = true;

    while(resto){
        ++counter;
        resto = (10 * resto + 7) % K;
        if(already[resto])
            break;
        already[resto] = true;
    }

    if(resto)
        printf("-1");
    else
        printf("%d", counter);

    return 0;
}


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

using ll = long long;
using pii = pair<int, int>;

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

  int n; cin >> n;
  priority_queue<pii, vector<pii>, greater<pii>> pq;
  for(int i=0; i<n; i++) {
    int x, y; cin >> x >> y;
    pq.push({y, x});
  }

  int t = 0;
  while(pq.size()) {
    pair<int, int> job = pq.top(); pq.pop();
    if(t + job.second > job.first) {
      cout << "No" << endl;
      exit(0);
    }

    t += job.second;
  }

  cout << "Yes" << endl;

  return 0;
}

Measured memory_bytes: 2420
#include <iostream>
#include <math.h>
#include <string>
#include <vector>
using namespace std;

int main () {
    int H, W;
    cin >> H >> W;

    string data[100];

    for(int i = 0; i < H; i++){
        cin >> data[i];
    }

    for(int i=0; i < W+2; i++){
        cout << "#";
    }

    cout << endl;

    for(int i = 0; i < H; i++){
        cout << "#";
        cout << data[i];
        cout << "#" << endl;
    }

    for(int i=0; i < W+2; i++){
        cout << "#";
    }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
typedef long long ll;
using namespace std;
int INF = 1LL << 30;
int MOD = 1e9+7;
main(){
    int A,B,C;
    cin >> A >> B >> C;
    if(C - A <= B && C - A >= 0)cout << "YES" << endl;
    else cout << "NO" << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <vector>
#include <cstdio>
#include <algorithm>

using namespace std;

#define ll long long
#define REP(i, N) for(int i = 0; i < N; i++)

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

    int a[N];
    REP(i, N) cin >> a[i];
    sort(a, a + N, greater<int>());

    int Alice = 0;
    REP(i, N) {
        if (i % 2 == 0) Alice += a[i];
        else Alice -= a[i];
    }

    cout << Alice << "\n";
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>

#define MAX_N (50)
#define NUM_MOD (1000000007)

long solve(long l, long x, const long *hs, const long *ps) {
  // x == 0 or l == 0
  if (x == 0) {
    return 0;
  } else if (l == 0) {
    return 1;
  }
  // l > 0 and x > 0
  if (x < 2) {
    return 0;
  } else if (x < hs[l - 1] + 2) {
    return solve(l - 1, x - 1, hs, ps);
  } else if (x == hs[l - 1] + 2) {
    return ps[l - 1] + 1;
  } else if (x < 2 * hs[l - 1] + 3) {
    return ps[l - 1] + 1 + solve(l - 1, x - (hs[l - 1] + 2), hs, ps);
  } else {
    return ps[l];
  }
}

int main(int argc, char *argv[]) {
  // read inputs
  long N, X;
  scanf("%ld %ld", &N, &X);

  // calculate the height of the level l burgers
  long hs[MAX_N + 1], ps[MAX_N + 1];
  hs[0] = 1;
  ps[0] = 1;
  for (int l = 1; l <= N; l++) {
    hs[l] = 2 * hs[l - 1] + 3;
    ps[l] = 2 * ps[l - 1] + 1;
  }

  // solve
  printf("%ld\n", solve(N, X, hs, ps));

  return 0;
}


Measured memory_bytes: 128
import fractions
a,b,c,d=map(int,input().split())
def lcm(a, b):
    return a * b // fractions.gcd(a, b)

Cok=b//c-(a-1)//c
Dok=b//d-(a-1)//d
CDok=b//lcm(c,d)-(a-1)//lcm(c,d)
print(b-a+1-Cok-Dok+CDok)

Measured memory_bytes: 5048
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vb=vector<bool>;
using vvb=vector<vb>;
using vd=vector<double>;
using vvd=vector<vd>;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using pll=pair<ll,ll>;
using tll=tuple<ll,ll>;
using tlll=tuple<ll,ll,ll>;
using vs=vector<string>;
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rep(i,n) range(i,0,n)
#define rrep(i,n) for(ll i=(n)-1;i>=0;i--)
#define range(i,a,n) for(ll i=(a);i<(n);i++)
#define LINF ((ll)1ll<<60)
#define INF ((int)1<<30)
#define EPS (1e-9)
#define MOD (1000000007ll)
#define fcout(a) cout<<setprecision(a)<<fixed
#define fs first
#define sc second
#define PI (3.1415926535897932384)

int dx[]={1,0,-1,0,1,-1,-1,1},dy[]={0,1,0,-1,1,1,-1,-1};
template<class T>bool chmax(T&a,T b){if(a<b){a=b; return true;}return false;}
template<class T>bool chmin(T&a,T b){if(a>b){a=b; return true;}return false;}
template<class S>S sum(vector<S>&a){return accumulate(all(a),S());}
template<class S>S max(vector<S>&a){return *max_element(all(a));}
template<class S>S min(vector<S>&a){return *min_element(all(a));}
ll max(int a,ll b){return max((ll)a,b);} ll max(ll a,int b){return max(a,(ll)b);}

template<class T>void puta(T&&t){cout<<t<<"\n";}
template<class H,class...T>void puta(H&&h,T&&...t){cout<<h<<' ';puta(t...);}
template<class S,class T>void tf(bool b,S t,T f){if(b)puta(t);else puta(f);}
void YN(bool b){tf(b,"YES","NO");}
void Yn(bool b){tf(b,"Yes","No");}
void yn(bool b){tf(b,"yes","no");}
template<class S,class T>ostream&operator<<(ostream&os,pair<S,T>p){os<<"["<<p.first<<", "<<p.second<<"]";return os;};
template<class S>auto&operator<<(ostream&os,vector<S>t){bool a=1;for(auto s:t){os<<(a?"":" ")<<s;a=0;}return os;}
template<class S>auto&operator>>(istream&is,vector<S>&t){for(S&a:t)cin>>a;return is;}

/*他のライブラリを入れる場所*/


int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll n;
	while(cin>>n,n){
		rep(i,9){
			ll t; cin>>t;
			n-=t;
		}
		puta(n);
	}
	return 0;
}


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

typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

struct p
{
	int x;
	int y;
};

p ara[10];

int sq(int x)
{
	return x*x;
}

ld dis(p a,p b)
{
	ld ans=sq(a.x-b.x)+sq(a.y-b.y);
	ans*=1.0;
	ans=sqrt(ans);
	
	return ans;
}

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

	int n;
	cin>>n;
	
	for(int i=1;i<=n;i++) cin>>ara[i].x>>ara[i].y;
	
	vector<int>v;
	
	for(int i=1;i<=n;i++) v.push_back(i);
	
	ld ans=0.0;
	
	while(next_permutation(v.begin(),v.end()))
	{
		ld d=0.0;
		for(int i=0;i<v.size()-1;i++)
		{
			d+=dis(ara[v[i]],ara[v[i+1]]);
		}
      
		ans+=d;
	}
	
	ld d=0.0;
	
	for(int i=0;i<v.size()-1;i++) d+=dis(ara[v[i]],ara[v[i+1]]);
  
	ans+=d;
	
	for(int i=1;i<=n;i++) ans/=(ld)i;
	
	cout<<fixed<<setprecision(10)<<ans;
		
					                                				
	cerr<<"\nTime elapsed: " << 1000.0 * clock() / CLOCKS_PER_SEC << " ms\n";
	
	return 0;
}


Measured memory_bytes: 512