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

using namespace std;
using ll = long long;
using ii = pair<ll, ll>;
using is = pair<int, string>;

const int MAX { 200010 };
const ll MOD { 1000000007 }, oo { 1LL << 62 };

ii solve(int N, const vector<is>& xs)
{
    vector<int> ys(N + 1, 0), ac(N + 1, 0);
    int ans = 0, pen = 0;

    for (auto x : xs)
    {
        auto p = x.first;
        auto v = x.second;

        if (v == "AC")
        {
            if (ac[p])
                continue;

            ac[p] = 1;
            ++ans;
            pen += ys[p];
        } else
            ys[p]++;
    }

    return { ans, pen };
}

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

    int N, M;
    cin >> N >> M;

    vector<is> xs(M);

    for (int i = 0; i < M; ++i)
        cin >> xs[i].first >> xs[i].second;

    auto ans = solve(N, xs);

    cout << ans.first << ' ' << ans.second << '\n';

    return 0;
}


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

const int64_t MOD= 998244353;
/* 剰余環 Z/nZ */
struct mint{ // Z/nZ に関する演算(n:素数の場合は除算も)をサポートする構造体
  int64_t rep; // 出力すべき代表元 rep \in {0,1,..,MOD- 1}
  mint(int64_t x=0): rep(((x%MOD)+ MOD)% MOD){}
  mint operator-() const { return mint(-rep);}
  mint& operator+=(const mint& x){
    rep+= x.rep; 
    if(rep>= MOD) rep-= MOD;
    return *this;
  }
  mint& operator-=(const mint& x){
    rep-= x.rep;
    if(rep< 0) rep+= MOD;
    return *this;
  }
  mint& operator*=(const mint& x){
    rep*= x.rep; rep%= MOD;
    return *this;
  }
  mint operator+(const mint x) const {
    mint ans(*this);
    ans+= x;
    return ans;
  }
  mint operator-(const mint x) const {
    mint ans(*this);
    ans-= x;
    return ans;
  }
  mint operator*(const mint x) const {
    mint ans(*this);
    ans*= x;
    return ans;
  }

  mint pow(int64_t d) const{ // d \geq 0
    if(d==0) return 1;
    else{
      mint ans= pow(d>>1);
      ans*= ans;
      if(d&1){ ans*= *this; }

      return ans;
    }
  }

  friend istream& operator >> (istream &is, mint& x) noexcept{
    int64_t a;
    is >> a;
    x= a;
  }
  friend ostream& operator << (ostream &os, const mint& x) noexcept{
    return os << x.rep;
  }
  // MOD が素数(<=> Z/nZ が体)のとき
  mint inv() const{
    return pow(MOD-2);
  }
  mint& operator/=(const mint& x){
    *this *= x.inv();
    return *this;
  }
  mint operator/(const mint x) const {
    mint ans(*this);
    ans/= x;
    return ans;
  }
};

int main(){ 
// g(R):= \sum_{L in [1,R]} f(L,R) とおくと,
// ans  = \sum_{R in [1,N]} g(R).
// よってg(R) を順次求めればいい。まず、
// f(L,R)=  [x^S] \prod_{i in [L,R]} (1+ x^{A_i})
//       =: [x^S] F_{L,R} とおく. このとき、
// g(R)=  \sum_{L in [1,R]} [x^S] F_{L,R}
//     =  [x^S] \sum_{L in [1,R]} F_{L,R}
//     =: [x^S] G_R
//     =  [x^S] G_{R-1}(1+ x^{A_R})+ (1+ x^{A_R})
//     =  [x^S] (1+ G_{R-1}) (1+ x^{A_R}).
// まとめると、G_R= (1+ G_{R-1}) (1+ x^{A_R}), G_0= 0 の各係数をDPで順次求めていけばいい。
  int N,S;
  cin >> N >> S;

  vector<int> data(N);
  for(int i=0; i<N; i++){
    cin >> data.at(i);
  }

  vector<mint> dp(S+1);
  vector<mint> buf(S+1);
  mint ans= 0;
  for(int i=0; i<N; i++){
    dp.at(0)+= 1;

    for(int s=S; s>=0; s--){
      dp.at(s)= (s >= data.at(i)) ? dp.at(s)+ dp.at(s- data.at(i))
                                  : dp.at(s);
    }
    ans+= dp.at(S);
  }

  cout << ans << endl; 
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long a,b,n;
    cin>>a>>b>>n;
    long long x_i=min(b-1,n);
    long long result=((a*x_i)/b)-(a*(x_i/b));
    cout<<result<<endl;
    return 0;
}

Measured memory_bytes: 3640
import sys
sys.setrecursionlimit(10**9)

def mi(): return map(int,input().split())
def ii(): return int(input())
def isp(): return input().split()
def deb(text): print("-------\n{}\n-------".format(text))

INF=10**20
def main():
    A,B,C,X,Y = mi()

    ans = INF
    for z in range(10**6):
        x = max(0,X-z//2)
        y = max(0,Y-z//2)

        ans = min(A*x+B*y+C*z,ans)
    
    print(ans)




if __name__ == "__main__":
    main()

Measured memory_bytes: 73152
#include <iostream>

using namespace std;

#define REP(i,n) for (int i=0;i<(n);++i)

int main() {
	int s[5];
	REP(i,5) {
		cin >> s[i];
		if (s[i] < 40) s[i] = 40;
	}

	int total = 0;
	REP(i,5) total += s[i];

	cout << total / 5 << endl;

	return 0;
}

Measured memory_bytes: 1164
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int(i) = 0; (i) < (n); (i)++)
#define FOR(i, m, n) for(int(i) = (m); (i) < (n); (i)++)
#define All(v) (v).begin(), (v).end()
#define pb push_back
#define MP(a, b) make_pair((a), (b))
template <class T> vector<T> make_vec(size_t a, T val) {
    return vector<T>(a, val);
}
template <class T, class... Ts> auto make_vec(size_t a, Ts... ts) {
    return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using Graph = vector<vector<int>>;
template <typename T> struct edge {
    int to;
    T cost;
    edge(int t, T c) : to(t), cost(c) {}
};
template <typename T> using WGraph = vector<vector<edge<T>>>;
const int INF = 1 << 30;
const ll LINF = 1LL << 60;
const int MOD = 1e9 + 7;

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

int main() {
    int H, W;
    cin >> H >> W;
    int cy, cx, gy, gx;
    cin >> cy >> cx >> gy >> gx;
    cy--, cx--, gy--, gx--;
    vector<string> mp(H);
    rep(i, H) { cin >> mp[i]; }
    vector<vector<ll>> dist(H, vector<ll>(W, INF));
    priority_queue<pair<int, pii>, vector<pair<int, pii>>,
                   greater<pair<int, pii>>>
        que;
    que.push(MP(0, MP(cx, cy)));
    dist[cy][cx] = 0;
    while(!que.empty()) {
        auto p = que.top();
        que.pop();
        int d = p.first;
        int x = p.second.first, y = p.second.second;
        for(int i = 0; i < 4; i++) {
            int nx = x + dx[i], ny = y + dy[i];
            if(nx >= 0 && nx < W && ny >= 0 && ny < H) {
                if(mp[ny][nx] != '#') {
                    if(dist[ny][nx] <= d)
                        continue;
                    que.push(MP(d, MP(nx, ny)));
                    dist[ny][nx] = d;
                }
            }
        }
        for(int nx = x - 2; nx <= x + 2; nx++) {
            for(int ny = y - 2; ny <= y + 2; ny++) {
                if(nx >= 0 && nx < W && ny >= 0 && ny < H) {
                    if(mp[ny][nx] != '#') {
                        if(dist[ny][nx] <= d + 1)
                            continue;
                        que.push(MP(d + 1, MP(nx, ny)));
                        dist[ny][nx] = d + 1;
                    }
                }
            }
        }
    }
    cout << (dist[gy][gx] == INF ? -1 : dist[gy][gx]) << endl;
}

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

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

	double limit = t + 0.5 - a;
	int ans = 0;
	for (int i = 0; i < limit; i += a)
	{
		ans += b;
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
N = int(input())
mod = 10**9 + 7
def inv(x):
    return pow(x, mod - 2, mod)
def comb(n, k):
    ue = 1
    shita = 1
    n %= mod
    for i in range(k):
        ue = ue * (n - i) % mod
        shita = shita * (i + 1) % mod
    return ue * inv(shita) % mod
if N == 1:
    print(0)
else:
    print((pow(10,N,mod)-2*pow(9,N,mod)+pow(8,N,mod))%mod)


Measured memory_bytes: 9132
#define _CRT_SECURE_NO_WARNINGS
#include <cstdio>
#include <vector>
#include <string>
#include <iostream>
#include <algorithm>
#include <map>
#include <iterator>
#include <functional>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <fstream>
#include <iomanip>
#include <unordered_map>
#include <unordered_set>
#include <numeric>
#include <cmath>
#include <list>
#include <sstream>
#include <tuple>
#include <complex>
#include <stdio.h>
using namespace std;
#pragma GCC optimize("O3")
#pragma GCC target("sse4")

typedef long double LD;
typedef long long LL;
typedef pair<int, int> PII;
typedef pair<LD, LD> PDD;
typedef pair<LL, LL> PLL;
typedef vector<int> VI;
typedef vector<LL> VLL;
typedef vector<char> VCH;
typedef vector<LD> VLD;
typedef vector<string> VS;
typedef vector<VS> VSS;
typedef vector<VI> VVI;
typedef vector<VLL> VVLL;
typedef vector<VCH> VVCH;
typedef vector<PII> VPII;
typedef vector<PLL> VPLL;
typedef vector<PDD> VPDD;
#define MP make_pair
#define PB push_back
#define X first
#define Y second
#define next fake_next
#define prev fake_prev
#define left fake_left
#define right fake_right

#define FOR(i,a,b) for(int i = (a); i < (b); ++i)
#define RFOR(i,b,a) for(int i = (b) - 1; i >= (a); --i)
#define REP(i, t) FOR(i,0,t)
#define ALL(a) a.begin(), a.end()
#define SZ(a) (int)((a).size())

const LD PI = acos(-1.0);
const LL mod = 1000000007;
const LL INF = 1e9;
const LL LINF = 1e18;
const LL MAXQ = 1007;
const int MAXN = 10007;

int main()
{
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	//freopen("In.txt", "r", stdin);

	int n;
	cin >> n;
	VLL a(n);
	FOR(i, 0, n)
		cin >> a[i];

	LL ans = 0;

	VPLL b(n);
	FOR(i, 0, n)
		b[i] = MP(a[i], i);

	sort(ALL(b));

	FOR(i, 0, n)
		if (abs(i - b[i].Y) & 1)
			++ans;

	ans /= 2;
	cout << ans;
//	cin >> n;
	return 0;
}

Measured memory_bytes: 2560
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//#include <boost/multiprecision/cpp_ll.hpp>
//typedef boost::multiprecision::cpp_ll ll;
typedef long double dd;
#define i_7 (ll)(1E9+7)
//#define i_7 998244353
#define i_5 i_7-2
ll mod(ll a){
    ll c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
typedef pair<ll,ll> l_l;
ll inf=(ll)1E18;
#define rep(i,l,r) for(ll i=l;i<=r;i++)
#define pb push_back
ll max(ll a,ll b){if(a<b)return b;else return a;}
ll min(ll a,ll b){if(a>b)return b;else return a;}
void Max(ll &pos,ll val){pos=max(pos,val);}//Max(dp[n],dp[n-1]);
void Min(ll &pos,ll val){pos=min(pos,val);}
void Add(ll &pos,ll val){pos=mod(pos+val);}
dd EPS=1E-9;
#define endl "\n"
#define fastio ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);

struct U_F{
    vector<ll> par;
    vector<ll> rank;
private:
    vector<ll> num;
public:
    void init(ll n){
        rep(i,0,n-1){
            par.pb(i);
            rank.pb(0);
            num.pb(1);
        }
    }
    ll find(ll x){
        if(par[x]==x)return x;
        return par[x]=find(par[x]);
    }
    void unite(ll x,ll y){
        x=find(x);
        y=find(y);
        if(x==y)return;
        if(rank[x]<rank[y]){
            par[x]=y;
            num[y]=num[x]+num[y];
        }else if(rank[x]==rank[y]){
            par[y]=x;
            rank[x]++;
            num[x]=num[x]+num[y];
        }else{
            par[y]=x;
            num[x]=num[x]+num[y];
        }
    }
    bool same(ll x,ll y){
        return find(x)==find(y);
    }
    ll g_num(ll x){
        x=find(x);
        return num[x];
    }
};

int main(){fastio
    ll n,m;cin>>n>>m;
    U_F uf;
    uf.init(n);
    ll a[m],b[m];
    rep(i,0,m-1){
        cin>>a[i]>>b[i];
        uf.unite(a[i]-1,b[i]-1);
    }
    ll maxi=0;
    rep(i,0,n-1){
        maxi=max(maxi,uf.g_num(i));
    }
    cout<<maxi<<endl;

    return 0;
}





Measured memory_bytes: 10964
num_counts = int(input())
nums = list(map(int, input().split()))
swap_counts = 0

for i in range(num_counts):
    mini = i
    for j in range(i, num_counts):
        if nums[j] < nums[mini]:
            mini = j
    if i == mini:
        continue
    nums[i], nums[mini] = nums[mini], nums[i]
    swap_counts += 1
    
for num in nums[:-1]:
    print(num, end=' ')
print(nums[-1])
print(swap_counts)


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

 int popcount(long long n) {
	n = (n & 0x5555555555555555) + (n >> 1 & 0x5555555555555555);
	n = (n & 0x3333333333333333) + (n >> 2 & 0x3333333333333333);
	n = (n & 0x0f0f0f0f0f0f0f0f) + (n >> 4 & 0x0f0f0f0f0f0f0f0f);
	n = (n & 0x00ff00ff00ff00ff) + (n >> 8 & 0x00ff00ff00ff00ff);
	n = (n & 0x0000ffff0000ffff) + (n >> 16 & 0x0000ffff0000ffff);
	n = (n & 0x00000000ffffffff) + (n >> 32 & 0x00000000ffffffff);
	return n;
}

struct Edge{
	int to, id;
	Edge(int to,int id):to(to),id(id) {}
};
vector<Edge>g[55];
vector<int>es;
bool dfs(int v,int tv,int p=-1) {
	if (v == tv) {
		return true;
	}
	for (Edge e:g[v]) {
		if (p == e.to) {
			continue;
		}
		if (dfs(e.to, tv, v)) {
			es.push_back(e.id);
			return true;
		}
	}
	return false;
}

int main() {
	int N;
	cin >> N;
	for (int n = 0;n<N-1;++n) {
		int a, b;
		cin >> a >> b;
		a--;
		b--;
		g[a].emplace_back(b, n);
		g[b].emplace_back(a, n);
	}
	int M;
	cin >> M;
	vector<long long> eset(M);
	for (int m = 0;m<M;++m) {
		int a, b;
		cin >> a >> b;
		--a;
		--b;
		es = vector<int>();
		dfs(a, b);
		for (int e:es) {
			eset[m] |= (long long)1 << e;
		}
	}

	long long ans = 0;
	for (int i = 0;i<(1<<M);++i) {
		long long mask = 0;
		for (int j = 0;j < M;++j) {
			if (i >> j & 1) {
				mask |= eset[j];
			}
		}
		int white = popcount(mask);
		long long  now = 1ll << (N - 1 - white);
		if (0 == popcount(i) %2) {
			ans += now;
		}
		else{
			ans -= now;
		}
	}
	cout << ans <<endl;
	return 0;
}

Measured memory_bytes: 3628
#include <iostream>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <sstream>
#include <vector>
#include <set>
#include <stack>
#include <queue>
 
#define rep(i, n) for (int i = 0; i < n; ++i)
#define all(x) x.begin(), x.end()
 
 
using namespace std;
const int MAXN = 1000005;
const int INF = 0x7f7f7f7f;
typedef long long ll;
 
int h, w, k, x_1, y_1, x_2, y_2;
 
 
int main() {
    //freopen("../input.txt", "r", stdin);
    //freopen("../output.txt", "w", stdout);
    cin >> h >> w >> k >> x_1 >> y_1 >> x_2 >> y_2;
    --x_1; --x_2; --y_1;--y_2;
    int pool_ans[h + 5][w + 5];
    char pool[h + 5][w + 5];
    int pool_mark[h + 5][w + 5];
    memset(pool_ans, 0x7f, sizeof(pool_ans));
    memset(pool_mark, 0, sizeof(pool_mark));
    pool_ans[x_1][y_1] = 0;
 
    rep(i, h) {
        rep(j, w) {
            cin >> pool[i][j];
        }
    }
    queue<pair<int, int>> next_point;
    next_point.push(pair<int, int>(x_1, y_1));
    pool_mark[x_1][y_1] = 1;
    while (pool_ans[x_2][y_2] == 0x7f7f7f7f && !next_point.empty()) {
        pair<int, int> cur_point = next_point.front();
        next_point.pop();
        int x = cur_point.first, y = cur_point.second;
        int cur_ans = pool_ans[x][y] + 1;
        pool[x][y] = '@';
        rep(i, k) {
            if (x + i + 1 >= h || pool[x + i + 1][y] == '@') break;
            pool_ans[x + i + 1][y] = min(pool_ans[x + i + 1][y], cur_ans);
            if (!pool_mark[x + i + 1][y]) {
                pool_mark[x + i + 1][y] = 1;
                next_point.push(pair<int, int>(x + i + 1, y));
            }
        }
        rep(i, k) {
            if (x - i - 1 < 0 || pool[x - i - 1][y] == '@') break;
            pool_ans[x - i - 1][y] = min(pool_ans[x - i - 1][y], cur_ans);
            if (!pool_mark[x - i - 1][y]) {
                pool_mark[x - i - 1][y] = 1;
                next_point.push(pair<int, int>(x - i - 1, y));
            }
        }
        rep(i, k) {
            if (y + i + 1 >= w || pool[x][y + i + 1] == '@') break;
            pool_ans[x][y + i + 1] = min(pool_ans[x][y + i + 1], cur_ans);
            if (!pool_mark[x][y + i + 1]) {
                pool_mark[x][y + i + 1] = 1;
                next_point.push(pair<int, int>(x, y + i + 1));
            }
        }
        rep(i, k) {
            if (y - i - 1 < 0 || pool[x][y - i - 1] == '@') break;
            pool_ans[x][y - i - 1] = min(pool_ans[x][y - i - 1], cur_ans);
            if (!pool_mark[x][y - i - 1]) {
                pool_mark[x][y - i - 1] = 1;
                next_point.push(pair<int, int>(x, y - i - 1));
            }
        }
    }
    if (pool_ans[x_2][y_2]==0x7f7f7f7f){
        cout << -1 << endl;
    } else {
        cout << pool_ans[x_2][y_2] << endl;
    }
 
    return 0;
}

Measured memory_bytes: 51412
import java.util.*;
public class Main{
    public static void main(String args[]) {
        Scanner cin = new Scanner(System.in);
        while(cin.hasNext()){
        	int n = cin.nextInt();
        	int[][] vote = readMatrix(cin,n,2);
        	System.out.println(getNum(vote,n));
        }
    }
    public static long getNum(int[][] vote, int n){
    	long[] result={vote[0][0],vote[0][1]};
    	long result1;
    	for(int i=1;i<n;i++){
    		result1 = result[1];
    		if(result[0]>vote[i][0]){
    			if(result[0]%vote[i][0]!=0) result[0] += vote[i][0]-result[0]%vote[i][0];
    		}else{result[0]=vote[i][0];}
    		result[1] = result[0]/vote[i][0]*vote[i][1];
    		if(result1>result[1]){
    			result[1] = result1;
    			if(result[1]%vote[i][1]!=0) result[1] += vote[i][1]-result[1]%vote[i][1];
    			 result[0] = result[1]/vote[i][1]*vote[i][0];
    		}
    	}
    	return result[0]+result[1];
    }
    public static int[][] readMatrix(Scanner in,int n,int m){
    	int[][] mtx = new int[n][m];
    	for(int i=0;i<n;i++){
    		for(int j=0;j<m;j++){
    			mtx[i][j] = in.nextInt();
    		}
    	}
    	return mtx;
    }
    
}

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

using namespace std;

int main() {
  int n, h, w;
  cin >> n >> h >> w;
  int ans = 0;
  for (int i = 0; i < n; i++) {
    int a, b;
    cin >> a >> b;
    ans += (h <= a && w <= b);
  }
  cout << ans << '\n';
  return 0;
}

Measured memory_bytes: 256
def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)
    divisors.sort()
    return(divisors)
n = int(input())
ans = make_divisors(n)
if len(ans)%2 == 1:
    answer = ans[((len(ans)+1)//2)-1]
else:
    answer = ans[(len(ans)//2)]
print(len(str(answer)))

Measured memory_bytes: 3188
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main(void) {
	int num, i = 0, aa, bb, as = 0, bs = 0, an, bn, ans;
	cin >> num;
	vector<int> a(100001, 0), b(100001, 0);
	for (; i < (num >> 1); i++) {
		scanf("%d%d", &aa, &bb);
		a[aa]++;
		b[bb]++;
	}
	for (aa = 0, bb = 0, i = 0; i < 100000; i++) {
		if (aa < a[i]) {
			as = aa;
			aa = a[i];
			an = i;
		}
		else if (as < a[i])
			as = a[i];
		if (bb < b[i]) {
			bs = bb;
			bb = b[i];
			bn = i;
		}
		else if (bs < b[i])
			bs = b[i];
	}
	if (an == bn)
		ans = max(aa + bs, bb + as);
	else
		ans = aa + bb;
	printf("%d\n", num - ans);
	return 0;
}

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

int main(void)
{
        int W, H, x, y, r;

        cin >> W >> H >> x >> y >> r;

        if( ( (x-r) >= 0) && (x+r <= W) && ((y-r) >= 0) && ((y+r) <= H))
        {
                cout << "Yes" << endl;
        }
        else
        {
                cout << "No" << endl;
        }

        return 0;
}

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

using namespace std;

int main() {
  int N, A;
  cin >> N >> A;
  int mod = N % 500;
  if (mod > A) {
    cout << "No" << endl;
  } else {
    cout << "Yes" << endl;
  }
  
  return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>

using namespace std;
typedef long long ll;

int main(){
  ll N,K;
  cin >> N >> K;
  ll p[N];
  for(int i=0;i<N;i++){
    cin >> p[i];
  }
  ll sum[200001];
  sum[0]=0;
  for(int i=1;i<200001;i++){
    sum[i] = sum[i-1]+i;
  }
  vector<pair<ll ,int> >sum2(N-K+1);
  ll go=0;
  for(int j=0;j<K;j++){
    go+=p[j];
  }
  sum2[0] = make_pair(go,0);
  for(int i=1;i<N-K+1;i++){
    sum2[i]=make_pair(sum2[i-1].first-p[i-1]+p[i+K-1],i);
  }
  sort(sum2.begin(),sum2.end());
  double ans=0;
  for(ll i=0;i<K;i++){
    ans += sum[p[sum2[N-K].second+i]]/(1.0*p[sum2[N-K].second+i]);
  }
  printf("%.12f\n", ans);

}


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

#define MAX_N 100010
int a[MAX_N];

int gcd(int s, int t)
{
    if (t == 0) return s;
    return gcd(t, s % t);
}

int main(void)
{
    int n, k;
    bool flag = false;;
    scanf("%d%d", &n, &k);
    for (int i = 0; i < n; i++) scanf("%d", &a[i]);
    sort(a, a + n);
    for (int i = 0; i < n; i++) if (k == a[i]) flag = true;
    if (!flag) {
        if (n == 1) flag = false;
        else if (k > a[n - 1]) flag = false;
        else {
            int _gcd = gcd(a[0], a[1]);
            for (int i = 1; i < n - 1; i++)
                _gcd = gcd(a[i], _gcd);
            if (_gcd == 1) flag = true;
            else if (gcd(k, _gcd) > 1) flag = true;
        }
    }
    if (flag) printf("POSSIBLE\n");
    else printf("IMPOSSIBLE\n");
    return 0;
}


Measured memory_bytes: 640
{-# LANGUAGE OverloadedStrings #-}

import Control.Monad
import Control.Applicative
import qualified Data.Text as T
import qualified Data.Text.IO as T
import qualified Data.Map.Strict as M
import Data.List

main :: IO()
main = do
    n <- readLn
    [d, x] <- map read . words <$> getLine
    as <- map read <$> replicateM n getLine
    print $ solve n d x as
    
solve :: Int -> Int -> Int -> [Int] -> Int
solve n d x as = foldl' sub x as
    where
        sub :: Int -> Int -> Int
        sub temp a = temp + length (takeWhile (\d' -> d' <= d) $ map (\num -> num * a + 1) [0..])

Measured memory_bytes: 1020
#include <iostream>
#include <stack>
#include <algorithm>
#include <vector>
#include <math.h>
#include <stdio.h>
#include <functional>
#include <string>
#include <cstdlib>
#include <numeric>
#include <cstdbool>
#include <cstring>
#include <map> 
#include<set>
#include<queue>
#include <iomanip>

typedef long long ll;

#define rep(i,n) for(ll i=0;i<n;i++)
using namespace std;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

const long long INF = 1000000000000000;
const ll inf = -1e18;
typedef pair<ll, ll> P;
ll ma = 1000000000 + 7;
ll mx = 1000003;
ll h,n, w,m,t; string s;
ll R, C;
ll sy, sx, gy, gx;
char maze[110][110];
ll dis[20][20];
int dx[4] = { 1, 0, -1, 0 };
int dy[4] = { 0, 1, 0, -1 };
ll gcd(ll x, ll y) {
	if (x % y == 0) return y;
	return gcd(y, x % y);
}
ll lcm(ll a,ll b) {
	ll g = gcd(a, b);
	return a / g * b;
}
void comb(vector<vector <ll> >& v) {
	for (ll i = 0; i < v.size(); i++) {
		v[i][0] = 1;
		v[i][i] = 1;
	}
	for (ll k = 1; k < v.size(); k++) {
		for (int j = 1; j < k; j++) {
			v[k][j] = (v[k - 1][j - 1] + v[k - 1][j])%ma;
		}
	}
}

ll GetDigit(ll num) {
	return log10(num) + 1;
}
ll Combination(int n, int r)
{
	if (n - r < r) r = n - r;
	if (r == 0) return 1;
	if (r == 1) return n;

	vector<ll> numerator(r);
	vector<ll> denominator(r);

	for (int k = 0; k < r; k++)
	{
		numerator[k] = n - r + k + 1;
		denominator[k] = k + 1;
	}

	for (int p = 2; p <= r; p++)
	{
		int pivot = denominator[p - 1];
		if (pivot > 1)
		{
			int offset = (n - r) % p;
			for (int k = p - 1; k < r; k += p)
			{
				numerator[k - offset] /= pivot;
				denominator[k] /= pivot;
			}
		}
	}

	ll result = 1;
	for (int k = 0; k < r; k++)
	{
		if (numerator[k] > 1) result *= numerator[k];
		result %= ma;
	}

	return result;
}

ll bfs() {
	queue<P> que;
	for (int i = 0; i < R; i++) {
		for (int j = 0; j < C; j++) dis[i][j] = INF;
	}
	que.push(P(sy - 1, sx - 1));
	dis[sy - 1][sx - 1] = 0;

	while (que.size() > 0) {
		P p = que.front();
		que.pop();
		if (p.first == gy - 1 && p.second == gx - 1) break;
		for (ll i = 0; i < 4; i++) {
			ll ny = p.first + dy[i];
			ll nx = p.second + dx[i];
			if (0 <= ny && ny < R && 0 <= nx && nx < C && maze[ny][nx] == '.' && dis[ny][nx] == INF) {
				que.push(P(ny, nx));
				dis[ny][nx] = dis[p.first][p.second] + 1;
			}
		}
	}
	return dis[gy - 1][gx - 1];
}
ll res = 0;
vector<ll> A(13);
ll p = 0;
ll q, ans;
struct item {
	ll a, b, c, d;
} st[55];


int main() {
	cin >> n;
	string t;
	cin >> s >> t;
	ll cnt = 0;
	rep(i, n) {
		ll tmp = cnt;
		rep(j, n - i) {
			if (s[i + j] != t[j]) {
				cnt++;
				break;
			}
		}
		if (tmp == cnt)break;
	}
	cout << n + cnt << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <string>
#include <set>
#include <vector>
#include <map>
#include <list>
#include <stack>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> p;
static const int MAX = 100000;
static const int NIL = -1;

const int limit = 50;
int n, m;
int a[limit], b[limit];
bool graph[limit][limit];
bool visited[limit];

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

int main(void) {
    cin >> n >> m;
    int i, j;
    for(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;
    }
    int ans=0;
    
    for(i=0; i<m; i++) {
        graph[a[i]][b[i]] = graph[b[i]][a[i]] = false;
        for(j=0; j<n; j++)
            visited[j]=false;
        dfs(0);
        
        bool bridge=false;
        for(j=0; j<n; j++) {
            if(visited[j]==false)
                bridge=true;
        }
        if(bridge)
            ans+=1;
        
        graph[a[i]][b[i]] = graph[b[i]][a[i]] = true;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
import sys
input = sys.stdin.readline

H, W = map(int, input().split())
state = [list(input().rstrip()) for _ in range(H)]

ans = [[["."]*W for _ in range(H)] for _ in range(2)]

color = 0 # base color
was_blank = False # whether previous row was blank
for h in range(H):
    must_color = []
    for w in range(W):
        if state[h][w] == "#":
            must_color.append(w)
    if not must_color:
        if not was_blank:
            color ^= 1
        for w in range(1, W):
            ans[color][h][w] = "#"
        ans[color^1][h][0] = "#"
        was_blank = True
    else:
        color ^= 1
        for w in range(W):
            ans[color][h][w] = "#"
        for w in must_color:
            ans[color^1][h][w] = "#"
        was_blank = False

for h in range(H):
    print("".join(ans[0][h]))
print()
for h in range(H):
    print("".join(ans[1][h]))

Measured memory_bytes: 11380
#include <stdio.h>

void era(int year, int mon, int day);

int main(void)
{
    int year, mon, day;
    while(scanf("%d %d %d", &year, &mon, &day) != EOF) {
        era(year, mon, day);
    }
}

void era(int year, int mon, int day)
{
    int m, t, s, h;
    int date;
    m = year - 1867;
    t = year - 1911;
    s = year - 1925;
    h = year - 1988;
    date = year * 10000 + mon * 100 + day;
    if (date < 18680908) {
        printf("pre-meiji\n");
    } else if (date < 19120730) {
        printf("meiji %d %d %d\n", m, mon, day);
    } else if (date < 19261225) {
        printf("taisho %d %d %d\n", t, mon, day);
    } else if (date < 19890108) {
        printf("showa %d %d %d\n", s, mon, day);
    } else {
        printf("heisei %d %d %d\n", h, mon, day);
    }
}

Measured memory_bytes: 1036
#include <stdlib.h>
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
using ll=long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
inline constexpr ll gcd(ll a,ll b){if(!a||!b)return 0;while(b){ll c=b;b=a%b;a=c;}return a;}
inline constexpr ll lcm(ll a,ll b){if(!a||!b)return 0;return a*b/gcd(a,b);}
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
const long long INF=1LL << 60;
long long a,b;
long long dp[100200][110];
long long w[110],v[110];


int main(){
    long long a,b;
    cin>>a>>b;
    vector<long long> vec(a);
    rep(i,a){
        cin>>vec.at(i);
        vec.at(i)-=b;
    }
    if(a==1){
        cout<<abs(vec.at(0))<<endl;
    }
    else{
        long long gc=gcd(vec.at(0),vec.at(1));
        for(long long i=2;i<a;i++){
            gc=gcd(gc,vec.at(i));
        }
        cout<<abs(gc)<<endl;
    }
    
}



Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <numeric>
#include <cmath>
#include <stack>
#include <map>
#include <iomanip>
using namespace std;

int64_t min(int64_t a,int64_t b) {
    if (a > b)
    {
        return b ;
    }else
    {
        return a ;
    }
}

const int MAX = 510000;
const int MOD = 1000000007;

int64_t fac[MAX], finv[MAX], inv[MAX];

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

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


int main(){
    int64_t n ;
    cin >> n ;
    //n += 1 ;
    stack<char> ans ;
    while (n > 0)
    {
        int64_t next = n%26 ;
        if (next == 0)
        {
            next = 26 ;
        }
        
        char a = 'a' -1 + next ;
        ans.push(a) ;
        if (next == 26)
        {
            n -- ;
        }
        
        n /= 26 ;
    }
    while (ans.empty() == 0)
    {
        cout << ans.top() ;
        ans.pop() ;
    }
    cout << endl ;
}

Measured memory_bytes: 3628
#include <stdio.h>
 int main(){
   int a, b;
   scanf("%d %d",&a, &b);
   if(a<b){
    printf("a < b\n");
   }
   else if(a>b){
    printf("a > b\n");
   } else if(a==b){
    printf("a == b\n");
   }
}

Measured memory_bytes: 1812
#!/usr/bin/env python3
import sys, math, itertools, collections, bisect
input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8')
inf = float('inf') ;mod = 10**9+7
mans = inf ;ans = 0 ;count = 0 ;pro = 1

class Segment_Tree:
    __slots__ = ['ide_ele', 'size', 'num', 'seg', 'segfunc']

    def __init__(self, size, func, element):
        #####単位元######
        self.ide_ele = element
        self.size = size

        #num:n以上の最小の2のべき乗
        self.num = 2 ** (self.size - 1).bit_length()
        self.seg = [self.ide_ele] * 2 * self.num

        #####segfunc######
        self.segfunc = func

    def apply(self, apply_seq):
        #set_val
        for i in range(self.size):
            self.seg[i + self.num - 1] = apply_seq[i]    
        #built
        for i in range(self.num - 2, -1, -1) :
            self.seg[i] = self.segfunc(self.seg[2 * i + 1], self.seg[2 * i + 2]) 
        
    def update(self, k, x):
        k += self.num - 1
        self.seg[k] = x
        while k:
            k = (k-1) // 2
            self.seg[k] = self.segfunc(self.seg[k * 2 + 1],  self.seg[k * 2 + 2])
        
    def query(self, p, q):
        if q <= p:
            return self.ide_ele
        p += self.num - 1
        q += self.num - 2
        res = self.ide_ele
        while q - p > 1:
            if p & 1 == 0:
                res = self.segfunc(res, self.seg[p])
            if q & 1 == 1:
                res = self.segfunc(res, self.seg[q])
                q -= 1
            p = p // 2
            q = (q - 1) // 2 
        if p == q:
            res = self.segfunc(res, self.seg[p])
        else:
            res = self.segfunc(self.segfunc(res, self.seg[p]), self.seg[q])
        return res


def segor(x,y):
  return x | y  

n = int(input())
st = Segment_Tree(n,segor,0)
S = input()
data = [0] * n
for i,si in enumerate(S):
  k = ord(si)-ord("a")
  data[i] = 1 << k
st.apply(data)
Q = int(input())
for _ in range(Q):
  typo,a,b = input().split()
  if typo == "1":
    st.update(int(a)-1,1 << (ord(b)-ord("a")))
  if typo == "2":
    print(bin((st.query(int(a)-1,int(b))))[2:].count("1"))
  


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

#define REP(i, n) for(int (i)=0; (i)<(n); (i)++)
#define ALL(x) (x).begin(), (x).end()
#define OUT(a) cout << (a) << "\n"

typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;

const ll MOD = 10e9 + 7;

int main() {
    int n;
  	cin >> n;
  	cout << 3*n*n << endl;
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		//String s= sc.next();
		String buff= "";
		//double n = sc.nextInt()/1000.0;
		int m = sc.nextInt();
		int k = sc.nextInt();
		//String s=sc.next();
		long count=1,flag=0;
		long count1=0,count2=0;
		int count3=9999999;
		int[] array1 = new int[m];
		int[] array2 = new int[m];
		int[] array3 = new int[m-1];
		/*array[0]=n-m;
		array[1]=n*m;
		array[2]=n+m;*/
		//Arrays.sort(array);

		for(int i=k-m+1;i<m+k;i++) {
			System.out.print(i+" ");
		}

		/*if(count==0) {
			System.out.println("No");
		}else {
			System.out.println("Yes");
		}*/

		//System.out.println(count);
	}
}




Measured memory_bytes: 23892
#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <cmath>
#include <cstdlib>
#include <sstream>
#include <fstream>
#include <stdio.h>
#include <set>
#include <map>
#include <utility>
#include <numeric>
#include <queue>
#include <bitset>
#include <stack>
#include <unordered_map>
using namespace std;
#define mem(a, b) memset(a, b, sizeof(a))
string a, b, ans;
int dp[3005][3005];
 
int solve(int i, int j)
{
	if (i == a.size() || j == b.size()) return 0;
	if (~dp[i][j]) return dp[i][j];
	if (a[i] == b[j]) return dp[i][j] = solve(i + 1, j + 1) + 1;
	return dp[i][j] = max(solve(i + 1, j), solve(i, j + 1));
}
 
void build(int i, int j)
{
	if (i == a.size() || j == b.size()) return;
	if (a[i] == b[j]) {
		ans += a[i];
		build(i + 1, j + 1);
	}
	else {
		if (solve(i, j) == solve(i + 1, j)) build(i + 1, j);
		else build(i, j + 1);
	}
}
int main(){
	cin >> a >> b;
	mem(dp, -1);
	solve(0, 0);
	build(0, 0);
	cout << ans;
	return 0;
}



Measured memory_bytes: 39212
#include<bits/stdc++.h>
using namespace std;
int main()
{
    char m[1005];
    scanf(" %[^\n]",m);
    int l;
    l=strlen(m);
    if(m[l-1]=='s')
    {
        printf("%ses\n",m);
    }
    else
    {
        printf("%ss\n",m);
    }
    return 0;


}


Measured memory_bytes: 3752
from collections import deque

def bfs():
    q = deque()
    t = 0
    x = [-1 + i for i in range(5)]
    for i in range(1, 5):
        q.append(i)
        dist = [-1] * 5
        dist[i] = 0
        while q:
            j = q.popleft()
            for i in G[j]:
                if dist[i] == -1:
                    dist[i] = dist[j] + 1
                    q.append(i)
        dist.sort()
        if x == dist:
            t = 1
            break
    return t

G = [[] for _ in range(5)]
for _ in range(3):
    a, b = map(int, input().split())
    G[a].append(b)
    G[b].append(a)
print("YES" if bfs() else "NO")

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

using Graph = vector<vector<int> >;
Graph G;

void dfs(int v, vector<bool> &seen, int &res) {
    bool end = true;
    for (int i = 0; i < seen.size(); ++i) if (!seen[i] && i != v) end = false;
    if (end) {
        ++res;
        return;
    }

    seen[v] = true;
    for (auto nv : G[v]) {
        if (seen[nv]) continue;
        dfs(nv, seen, res);
    }
    seen[v] = false;
}

int main() {
    int N, M; cin >> N >> M;
    G.assign(N, vector<int>());
    for (int i = 0; i < M; ++i) {
        int a, b; cin >> a >> b; --a, --b;
        G[a].push_back(b);
        G[b].push_back(a);
    }
    vector<bool> seen(N, false);
    int res = 0;
    dfs(0, seen, res);
    cout << res << endl;
}

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

int main() {
    
    ios::sync_with_stdio(false);
    
    string s; cin >> s;
    vector<int> alfabeto(26, 0);

    for (char c : s) {
        alfabeto[(int)c - 65] = 1;
    }

    int total = 0;
    for (int i = 0; i < alfabeto.size(); i++) {
        if (alfabeto[i] != 0) {
            total++;
        }
    }

    if (total == 2) {
        cout << "Yes" << endl;
    }
    else {
        cout << "No" << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef double db;
typedef vector <ll> vll;
typedef pair <ll, ll> pll;
#define pb push_back
#define mp make_pair
#define MAX 1000000
#define mod 1000000007
#define all(_) _.begin(), _.end()
#define F first
#define S second
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>

int main()
{
    ios_base :: sync_with_stdio(false);
    cin.tie(NULL), cout.tie(NULL);
    vll a(3);
    ll c1 = 0, c2 = 0;
    for(ll i = 0; i < 3; i++)
    {
        cin >> a[i];
        if(a[i] == 5)
            c1++;
        else if(a[i] == 7)
            c2++;
    }
    cout << (c1 == 2 && c2 == 1 ? "YES" : "NO") << endl;
    return 0;
}

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

using namespace std;


const int N = 510;

char v[N][N];
char r[N][N];
char b[N][N];

int main() {
	int h, w;
	scanf("%d%d", &h, &w);

	for (int i = 0; i < h; ++i) {
		for (int j = 0; j < w; ++j) {
			scanf(" %c", &v[i][j]);
		}
	}
	memset(b, '.', sizeof b);
	memset(r, '.', sizeof r);
	// blue
	for (int i = 0; i < h; ++i) {
		if (i % 2 == 0) {
			b[i][0] = '#';
		} else {
			for (int j = 0; j < w-1; ++j) {
				b[i][j] = '#';
			}
		}
	}

	// red
	for (int i = 0; i < h; ++i) {
		if (i % 2 == 1) {
			r[i][w-1] = '#';
		} else {
			for (int j = 1; j < w; ++j) {
				r[i][j] = '#';
			}
		}
	}

	for (int i = 0; i < h; ++i) {
		for (int j = 0; j < w; ++j) {
			if(b[i][j] == '.' && v[i][j] == '#') {
				b[i][j] = '#';
			}
			if(r[i][j] == '.' && v[i][j] == '#') {
				r[i][j] = '#';
			}
		}
	}

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

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

typedef long long ll;
typedef pair<int, int> ii;
const int mod = 1e9+7;
const ll INF = 1e18;
const int inf = 1e9;

void solve()
{
  vector<int> a(5, 0);
  int d=0;
  int di=0;
  for (int i=0; i<5; i++) {
    cin >> a[i];
    int t=a[i]%10;
    if (t!=0) {
      if (d==0||d>t) {
        d=t;
        di=i;
      }
    }
  }
  int ans=0;
  for (int i=0; i<5; i++) {
    if (i==di) {
      ans += a[i];
    } else {
      if (a[i]%10==0) {
        ans += a[i];
      } else {
        ans += (a[i]+9)/10*10;
      }
    }
  }
  cout << ans << endl;
}

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


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

#define ll long long
#define fornum(A,B,C) for(A=B;A<C;++A)
#define mp make_pair
#define pii pair<int,int>
#define pll pair<ll,ll>

using namespace std;

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

ll N,K,RSP[6];
char T[101010];
ll i, j, k, ans;

int main(){
    scanf("%lld%lld", &N,&K);
    fornum(i,0,3){
        scanf("%lld", &RSP[i]);
    }
    scanf("%s", T);
    fornum(i,0,K){
        j = i;
        char s ='*';
        while(j<N){
            if(s==T[j]){
                s = '*';
            }else{
                if(T[j]=='r'){
                    ans += RSP[2];
                }else if(T[j]=='s'){
                    ans += RSP[0];
                }else if(T[j]=='p'){
                    ans += RSP[1];
                }
                s = T[j];
            }
            j += K;
        }
    }
    printf("%lld", ans);

    return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <cmath>
#include <cassert>
#include <sstream>
#include <fstream>

#define all(c) (c).begin(), (c).end()
#define iter(c) __typeof((c).begin())
#define cpresent(c, e) (find(all(c), (e)) != (c).end())
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define tr(c, i) for (iter(c) i = (c).begin(); i != (c).end(); ++i)
#define pb(e) push_back(e)
#define mp(a, b) make_pair(a, b)

using namespace std;
typedef long long unsigned int ll;

int main() {

  int N;
  cin >> N;
  string S;
  string lastS;
  cin >> lastS;
  set<string> used = {lastS};
  bool valid = true;
  for (int i = 0; i < N - 1; ++i) {
    cin >> S;
    auto search = used.find(S);
    if (search != used.end()) {
      valid = false;
    }
    if (S[0] != lastS[lastS.size() - 1]) {
      valid = false;
    }
    used.insert(S);
    lastS = S;
  }

  if (valid) {
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
  return 0;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace atcorder_BeginnerContest_122
{
    class Program
    {

        static void Main(string[] args)
        {
            string data = Console.ReadLine();
            int len = data.Length;

            int idx = 0;
            int maxCnt = 0;
            int tmpCnt = 0;
            while(idx < len)
            {
                string tmp = data.Substring(idx, 1);
                if (("A" == tmp) || ("C" == tmp) || ("G" == tmp) || ("T" == tmp))
                {
                    tmpCnt++;
                    if (maxCnt < tmpCnt)
                    {
                        maxCnt = tmpCnt;
                    }
                }
                else
                {
                    tmpCnt = 0;
                }
                idx++;

            }
            Console.WriteLine(maxCnt);

        }
    }
}



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

#define int long long

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

#define endl '\n'
#define fi first
#define se second
#define all(v) v.begin(), v.end()

#define print(x)    cout << #x << " : " << x << endl;
#define darr(a,n)   for(int i=0; i<n; i++) cout << a[i] <<' '; cout<< '\n';
#define fast        ios_base::sync_with_stdio (false); cin.tie (nullptr);
#define dvec(vct)   for(auto i : vct) cout << i << " "; cout << endl;

const int maxn = 1e6;
const int mod = 1e9 + 7;
// const int mod = 998244353;


/*****************************************************************************/



void solve() {
    int n; cin >> n;
    int A[n+1];
    int cnt[1 + (int)2e5] = {0};
    for (int i = 1; i <= n; i++) {
        cin >> A[i];
        cnt[A[i]]++;
    }
    
    int ans = 0;
    for (int i = 1; i <= n; i++) {
        int x = cnt[i];
        if (x <= 1) continue;
        ans += (x * (x-1))/2;
    }

    for (int k = 1; k <= n; k++) {
        int curr = ans;
        curr -= (cnt[A[k]] * (cnt[A[k]] - 1))/2;
        int temp = cnt[A[k]] - 1;
        if (temp >= 2) {
            curr += (temp * (temp-1))/2;
        } 
        cout << curr << endl;
    }
      
}



/*****************************************************************************/



int32_t main() {
    fast;
    // #ifndef ONLINE_JUDGE
    //     freopen("input.txt", "r", stdin);
    //     freopen("output.txt", "w", stdout);
    // #endif
    auto start = chrono::steady_clock::now();
    solve();

    auto end = chrono::steady_clock::now();
    auto diff = end - start;
    // #ifndef ONLINE_JUDGE
    //     cout << "\n\n";
    //     cout << "TIME : " << chrono::duration<double, milli> (diff).count() << " ms" << endl;
    // #endif
}


Measured memory_bytes: 5760
import sys 
from collections import deque
 
h, w = map(int, sys.stdin.readline().split())
grid = []
for _ in range(h):
    grid.append(list(sys.stdin.readline().strip()))
 
q = deque()
for i in range(h):
    for j in range(w):
        if grid[i][j] == "#":
            q.append((0, i, j))
 
while q:
    count, y, x = q.popleft()
    for dy, dx in ((-1, 0), (1, 0), (0, 1), (0, -1)):
        if 0 <= y+dy < h and 0 <= x+dx < w:
            if grid[y+dy][x+dx] == "#":
                continue
            else:
                grid[y+dy][x+dx] = "#"
                q.append((count+1, y+dy, x+dx))
 
print(count)

Measured memory_bytes: 213536
#include <bits/stdc++.h>
using namespace std; 
#define priority_queue pq
#define pu push
#define loop for(int i=0;i<n;i++)
int ar[100001];
int32_t  main()
{ 
	int r;
	cin>>r;
	cout<<2*3.1415926*r;
	
}


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

int main(void){
    int n;
    
    while(cin >> n && n) {
        char a[201] = {};
        for (int i = 0; i < n; i++) cin >> a[i];
        int max1 = 0;
        int max2 = 0;
        int r = 0;
        int b[201] = {};
        for (int i = 0; i < n; i++) {
            if (b[(int)a[i]] == max1) max1++;
            else if (b[(int)a[i]] == max2) max2++;
            b[(int)a[i]]++;
            
            if ((n-i-1)+max2 < max1) {
                //cout << "break at " << i << endl;
                r = i + 1;
                break;
            }
        }
        if (max1 == max2) {
            cout << "TIE" << endl;
            continue;
        }
        else {
            for (int i = 65; i < 100; i++) {
                if (b[i] == max1) {
                    cout << (char)i << " " << r << endl;
                    break;
                }
            }
        }
    }
}

Measured memory_bytes: 3120
def main():
    n, k = list(map(int, input().split()))
    p_list = list(map(int, input().split()))
    
    p_list.sort()
    total_money = 0
    for i in range(k):
        total_money += p_list[i]
    
    print(total_money)

if __name__ == '__main__':
    main()

Measured memory_bytes: 9256
/*********************************************************************************\
*  _________  _      _  ________  _       _       __       ________               *
* |___   ___|| |    | ||  ______|| |     | |     /  \     |  ____  |              *
*     | |    | |    | || |______ | |_____| |    / /\ \    | |____| |              *
*     | |    | |    | ||______  ||  _____  |   / /__\ \   |  __  __|              *
*     | |    | |____| | ______| || |     | |  / ______ \  | |  \ \                *
*     |_|    |________||________||_|     |_| /_/      \_\ |_|   \_\               *
*  ________       __      ________  _    __       __       ________               *
* |  ______|     /  \    |  ____  || |  / /      /  \     |  ____  |              *
* | |______     / /\ \   | |____| || |_/ /      / /\ \    | |____| |              *
* |______  |   / /__\ \  |  __  __||  __ \     / /__\ \   |  __  __|              *
*  ______| |  / ______ \ | |  \ \  | |  \ \   / ______ \  | |  \ \                *
* |________| /_/      \_\|_|   \_\ |_|   \_\ /_/      \_\ |_|   \_\               *
*                                                                                 *
*                                                                                 *
*   Department of Computer Science & Engineering                                  *
*   Student ID : 18CSE035                                                         *
*   Bangabnadhu Sheikh Mujibur Rahman Science & Technology University,Gopalgonj.  *
*                                                                                 *
\*********************************************************************************/

//Now Write to Code ___________________________

#include<bits/stdc++.h>
using namespace std;

int main()
{
   int i,j,x,y,N,cnt = 1;

   cin >> N;
   int P[N+1];

   for(i = 0; i < N; i++)
   {
   	   cin >> P[i];
   }

   x = P[0];

   for(i = 1; i < N; i++)
   {
   	  if(x >= P[i])
   	  {
   	  	cnt++;
        x = P[i];
   	  }
   }

   cout << cnt << endl;
    
    return 0;
}

Measured memory_bytes: 1024
#include <iostream>
using namespace std;
int main(void){
  int a,b,n;
  cin>>a>>b>>n;
  for(int i=0;i<n;i++){
    int x,y;
    cin>>x>>y;
    if(x<b&&a<y){
      cout<<1<<endl;
      return 0;
    }
  }
  cout<<0<<endl;
  return 0;    
}


Measured memory_bytes: 3104