akhauriyash/Code-Regression huggingface dataset:
import numpy as np
# import sys
# readline = sys.stdin.readline
# generator = (readline().strip() for _ in range(N))

# N, M = map(int, input().split())
# As = list(map(int, input().split()))
# queries = (input() for _ in range(N))


def solve():
    H, W, K = map(int, input().split())

    matrix = np.zeros(shape=(H, W), dtype=int)
    for i in range(H):
        cs = input()
        cs = cs.replace('#', '1')
        cs = cs.replace('.', '0')
        matrix[i] = np.array(list(map(int, cs)), dtype=int)

    total = 0

    for h in range(2 ** H):
        for w in range(2 ** W):
            tmp = matrix.copy()
            for i in range(H):
                if (h >> i) & 1:
                    tmp[i] *= 0
            for j in range(W):
                if (w >> j) & 1:
                    tmp[:, j] *= 0
            if tmp.sum() == K:
                total += 1

    return total


def main():
    print(solve())


if __name__ == "__main__":
    main()


Measured memory_bytes: 27228
/*
 NOTE:
*/
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <ctime>
#define MP make_pair
#define F first
#define S second
#define TIME (double)clock()/CLOCKS_PER_SEC
using namespace std;
typedef long long ll;

int n;
int calc (int x) { 
	int ans = 0;
	while (x)
		ans += x % 10, x /= 10;
	return ans;
}
int main()
{
//	freopen("test.in", "r", stdin);
//	freopen("test.out", "w", stdout);
 	ios::sync_with_stdio(false);
	cin >> n;
	int fans = 1000000;
	for (int i = 1; i < n; i ++)
		fans = min(fans, calc(i) + calc(n - i));
	cout << fans << endl;
	return 0;
}
/*
*/



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

typedef struct sp {
    int number;
    char name[11];
    int point;
} Data;


int com(const void *a, const void *b) {
    Data da = *(Data *)a;
    Data db = *(Data *)b;
    int cmp = strcmp(da.name, db.name);
    if(cmp == 0) return db.point - da.point;
    else return cmp;
}

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

    Data a[n];
    for(int i = 0; i < n; i++) {
        a[i].number = i + 1;
        cin >> a[i].name;
        cin >> a[i].point;
    }

    qsort(a, n, sizeof(Data), com);

    for(int i = 0; i < n; i++) {
        cout << a[i].number << endl;
    }

    return 0;
}

Measured memory_bytes: 256
//↓template↓

#include "bits/stdc++.h"
using namespace std;
#define Would
#define you
#define all(n)  n.begin(),n.end()
const long long INF = 1e18;
const long long MOD = 1e9 + 7;
const double pi = acos(-1);
const int SIZE = 1 << 17;
int dx[] = { 1,0,-1,0 }, dy[] = { 0,1,0,-1 }, alp[30];
long long fac[200005], finv[200005], inv[200005];
vector<long long>dij;
struct edge { long long to, cost; };
vector<vector<edge> >G;

long long mod_pow(long long a, long long b) {
	long long res = 1;
	while (b) {
		if (b & 1) { res = res * a%MOD; }
		a = a * a%MOD;
		b >>= 1;
	}
	return res;
}

void addedge(int from, int to, int cost) {
	G[from].push_back({ to,cost });
	G[to].push_back({ from,cost });
}

//↑template↑

void dijkstra(int n) {
	priority_queue<pair<long long, long long>, vector<pair<long long, long long>>, greater<pair<long long, long long>>>que;
	fill(dij.begin(), dij.end(), INF);
	dij[n] = 0;
	que.push(pair<long long, long long>(0, n));

	while (!que.empty()) {
		pair<long long, long long>p = que.top();
		que.pop();
		long long mon = p.second;
		if (dij[mon] < p.first) continue;
		for (int i = 0; i < G[mon].size(); ++i) {
			edge e = G[mon][i];
			if (dij[e.to] > dij[mon] + e.cost) {
				dij[e.to] = dij[mon] + e.cost;
				que.push(pair<long long, long long>(dij[e.to], e.to));
			}
		}
	}
}

int n, k[100005], ans;
int main() {
	cin >> n;
	for (int i = 0; i < n; ++i) { cin >> k[i]; }
	for (int i = 0; i < n; ++i) {
		if (k[i] == i + 1) { swap(k[i], k[i + 1]); ++ans; }
	}
	cout << ans << endl;
}

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

int main() {
  int n, m, k;
  cin >> n >> m >> k;
  vector<ll> a(n);
  rep(i, n) cin >> a[i];
  vector<ll> b(m);
  rep(i, m) cin >> b[i];
  vector<ll> acum{0};
  rep(i, n) acum.push_back(a[i] + acum[i]);
  vector<ll> bcum{0};
  rep(i, m) bcum.push_back(b[i] + bcum[i]);
  int ans = 0;
  rep(i, n+1) {
    if (acum[i] > k) break;
    int index = upper_bound(bcum.begin(), bcum.end(), k-acum[i]) - bcum.begin();
    ans = max(ans, i+index-1);
  }
  cout << ans << '\n';
  return 0;
}

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

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

int main(){
  string s;
  cin >> s;

  int n = s.size();
  int ans = 0;
  rep(i, (n+1)/2){
    if(s.at(i)!=s.at(n-1-i)) ans++;
  }
  cout << ans;
}

Measured memory_bytes: 256
import copy
import math

def calc(x, aa):
    a = copy.deepcopy(aa)
    cnt = k
    while cnt > 0:
        for i in range(n):
            if (a[i] > x):
                cnt -= a[i] // x
                a[i] = x
            if cnt < 0:
                return False
        if cnt < 0:
            return False
        return True
    
n, k = map(int, input().split())
a = [int(i) for i in input().split()]
left, right = 0, max(a)
if k == 0:
    print(right)
    exit()
    
while (right - left) > 1:
    middle = (left + right) / 2
    if calc(middle, a):
        right = middle
    else:
        left = middle        
for i in range(max(math.floor(left) - 10, 1), math.ceil(right) + 10):
    if calc(i, a):
        print(i)
        exit()

Measured memory_bytes: 180464
# -*- coding: utf-8 -*-
h,w = list(map(int,input().split()))

cmbs = [["."] + list(input()) + ["."]  for _ in range(h)]
cmbs.insert(0,["."] * (w+2))
cmbs.append(["."] * (w+2))

#print(cmbs)
#全てのsについて、上下左右いずれかに#があるか調べる
ret = "Yes"
for i in range(1,h+1):
    for j in range(1,w+1):
        if cmbs[i][j] == "#":
            if cmbs[i-1][j] =="." and cmbs[i+1][j] =="." and cmbs[i][j-1] =="." and cmbs[i][j+1] ==".":
                ret ="No"
print(ret)

Measured memory_bytes: 3064
using System;
using static System.Console;
using static System.Math;
using System.Numerics;
using System.Collections.Generic;
using System.Linq;


namespace AtCoder
{
    public class Program
    {
        public static void Main(string[] args)
        {
            int ans = 0;
            //var s = int.Parse(ReadLine());
            //var s = Console.ReadLine().Split(' ')
            var s = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
            char[,] nyuryoku = new char[s[0], s[1]];
            for (int i = 0; i < s[0]; i++)
            {
                var a = Console.ReadLine().Split(' ');
                string str = a[0];
                for (int j = 0; j < s[1]; j++)
                {
                    nyuryoku[i, j] = str[j];
                }
            }
            for (int bit_h = 0; bit_h < (1 << (s[0])); bit_h++)
            {
                for (int bit_w = 0; bit_w < (1 << (s[1])); bit_w++)
                {
                    int count = 0;
                    for (int i = 0; i < s[0]; i++)
                        for (int j = 0; j < s[1]; j++)
                            if ((bit_h & (1 << i)) == 0
                            && (bit_w & (1 << j)) == 0
                            && nyuryoku[i, j] == '#')
                                count++;
                    if (count == s[2])
                        ans++;
                }
            }
            WriteLine(ans);
            Out.Flush();
        }


    }
}

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

using namespace std;


#define PI 3.14159265
#define int long long

int record = INT_MAX;

int h, w, k;

vector < vector <char> > s;

void rec(vector <int> &from){

	if(from.back() + 1 == h){

		int ans = from.size() - 2;

		bool good = true;

		vector <vector <int> > row(1, vector <int>(from.size() - 1));

		for(int j = 0; j < w; j++){
			vector <int> add(from.size() - 1);
			for(int i = 0; i < from.size() - 1; i++){
				for(int c = from[i] + 1; c <= from[i + 1]; c++){
					if(s[c][j] == '1') add[i]++;
				}
			}

			for(int i = 0; i < from.size() - 1; i++){
				if(row.back()[i] + add[i] > k){
					if(row.back()[i]){
						for(int it = 0; it < i; it++){
							row.back()[it] -= add[it];
						}
						row.emplace_back(add);
						break;
					}else{
						good = false;
					}
				}else{
					row.back()[i] += add[i];
				}
			}
		}

		ans += row.size() - 1;

		if(good){
			// if(record > ans){
			// 	cout << ans << ' ' << row.size() - 1 << endl;
			// }
			record = min(record, ans);
		}
	}

	for(int i = 1; i <= h; i++){
		if(from.back() + i <= h - 1){
			from.emplace_back(from.back() + i);
			rec(from);
		}
	}

	from.pop_back();

}

main(){
	
	cin >> h >> w >> k;

	s.assign(h, vector <char>(w));

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

	vector <int> from = {-1};

	rec(from);


	cout << record << endl;


	
	
	
	return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
 
using namespace std;
using ll = long long;
// #define int ll
using PII = pair<ll, ll>;
 
#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
 
template<typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template<typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }
template<typename T> bool IN(T a, T b, T x) { return a<=x&&x<b; }
template<typename T> T ceil(T a, T b) { return a/b + !!(a%b); }

template<typename T> vector<T> make_v(size_t a) { return vector<T>(a); }
template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts) { 
  return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}
template<typename T,typename V> typename enable_if<is_class<T>::value==0>::type
fill_v(T &t, const V &v) { t=v; }
template<typename T,typename V> typename enable_if<is_class<T>::value!=0>::type
fill_v(T &t, const V &v ) { for(auto &e:t) fill_v(e,v); }

template<class S,class T>
ostream &operator <<(ostream& out,const pair<S,T>& a){
  out<<'('<<a.first<<','<<a.second<<')'; return out;
}
template<typename T>
istream& operator >> (istream& is, vector<T>& vec){
  for(T& x: vec) {is >> x;} return is;
}
template<class T>
ostream &operator <<(ostream& out,const vector<T>& a){
  out<<'['; for(T i: a) {out<<i<<',';} out<<']'; return out;
}

int dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0}; // DRUL
const int INF = 1<<30;
const ll LLINF = 1LL<<60;
const int MOD = 1000000007;

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

  ll xa, ya, xb, yb;
  cin >> xa >> ya >> xb >> yb;

  ll dx = xb - xa, dy = yb - ya;

  ll tmp = dx;
  dx = -dy;
  dy = tmp;
  ll xc = xb + dx, yc = yb + dy;

  tmp = dx;
  dx = -dy;
  dy = tmp;
  ll xd = xc + dx, yd = yc + dy;

  cout << xc << " " << yc << " " << xd << " " << yd << endl;

  return 0;
}


Measured memory_bytes: 256
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.Collection;
import java.util.Scanner;
import java.util.Queue;
import java.util.ArrayDeque;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        DarkRoom solver = new DarkRoom();
        solver.solve(1, in, out);
        out.close();
    }

    static class DarkRoom {
        int[] D;
        int[] Dark;
        int[][] v;
        int N;
        int M;
        int K;

        public void solve(int testNumber, Scanner in, PrintWriter out) {
            N = in.nextInt();
            M = in.nextInt();
            K = in.nextInt();
            D = new int[M];
            Dark = new int[N];
            Arrays.fill(Dark, -1);
            for (int i = 0; i < M; i++) {
                D[i] = in.nextInt() - 1;
                Dark[D[i]] = i;
            }
            v = new int[N][K];
            for (int i = 0; i < N; i++) {
                for (int j = 0; j < K; j++) {
                    v[i][j] = in.nextInt() - 1;
                }
            }
            final int INF = (int) 1e9;
            int[] minDist = new int[1 << M];
            Arrays.fill(minDist, INF);
            minDist[(1 << M) - 1] = 0;
            Queue<Integer> que = new ArrayDeque<>();
            que.add((1 << M) - 1);
            while (!que.isEmpty()) {
                int now = que.poll();
                for (int i = 0; i < K; i++) {
                    int nxtBit = 0;
                    for (int j = 0; j < M; j++) {
                        if ((now & (1 << j)) != 0 && Dark[v[D[j]][i]] != -1) {
                            nxtBit |= (1 << Dark[v[D[j]][i]]);
                        }
                    }
                    if (minDist[now] + 1 < minDist[nxtBit]) {
                        minDist[nxtBit] = minDist[now] + 1;
                        que.add((nxtBit));
                    }
                }
            }
            out.println(minDist[0]);
        }

    }
}




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

using namespace std;

#define EPS 1e-9
#define For(i,N) FOR(i,N)
#define Forr(i,a,b) FORR(i,a,b)
#define Fotr(i,a,b,c) FOTR(i,a,b,c)
#define FOR(i,N) FORR(i, 0, N)
#define FORR(i,a,b) FOTR(i, a, b, 1)
#define FOTR(i,a,b,c) for(int i=(a);i<(b);i+=(c))
#define FOREACH(i,x) for(__typeof__((x).begin())i=(x).begin();i!=(x).end();i++)
#define MEM(a,x) memset(a,x,sizeof(a))
#define BCHK(a,x) (((a)>>(x))&1)
#define BSET(a,x) ((a)|(1<<(x)))
#define BCLR(a,x) ((a)&(~(1<<(x))))
#define BTGL(a,x) ((a)^(1<<(x)))
#define FMT(...) (sprintf(CRTBUFF, __VA_ARGS__)?CRTBUFF:0)
#define read() freopen("input.txt","r",stdin)
#define write() freopen("output.txt","w",stdout)
#define cpp_io() {ios_base::sync_with_stdio(false);cin.tie(NULL);}
#define BUFFSIZE 30000
#define INF 1000000000
#define MAX 300010
#define MOD 1000000007
#define pb push_back
#define mkpr make_pair
#define pii pair<int, int>
#define PI acos(-1)
#define ll long long
#define fi first
#define si second
#define all(x) x.begin(), x.end()
#define double long double

char CRTBUFF[BUFFSIZE];
#define dbg(args...) {cerr<<"-->";debugger::call(#args,args);cerr<<"\n";}
struct debugger {
    static void call(const char* it) {}
    template<typename T, typename ... aT>
    static void call(const char* it, T a, aT... rest) {
        string b;
        for (; *it&&*it != ','; ++it) if (*it != ' ')b += *it;
        cerr << b << "=" << a << " ";
        call(++it, rest...);
    }
};

int B1[305*305];
int B2[305*305];

vector<int> V[305*305];

void fnc(int d, int lim){
    FOR(i, d){
        int c = 0, j = i;
        while(j<=lim){
            V[i].pb(c);
            if(j+d<=lim) c+= abs(B1[j] - B1[j+d]) + abs(B2[j] - B2[j+d]);
            j+=d;
        }
    }
}

int fnc2(int x, int y, int d){
    int m = x%d;
    x -= m, y -= m;
    return V[m][y/d] - V[m][x/d];
}

int main(){
    cpp_io();
    #ifdef LOCAL
        read();
        //write();
    #endif

    int h, w, d, z;
    cin>>h>>w>>d;

    FOR(i, h) FOR(j, w){
        cin>>z;
        B1[z] = i+1;
        B2[z] = j+1;
    }
    fnc(d, h*w);

    int q, x, y;
    cin>>q;

    while(q--){
        int ans = 0;
        cin>>x>>y;
        cout<<fnc2(x, y, d)<<"\n";
    }
}





















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

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

  int s;
  s = n % 500 - a;
  if(s <= 0){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
}


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


int main(){
        int n,p;
        cin >>n >>p;
        string s;
        cin >> s;
        vector<ll> cnt(p);
        ll ans =0;
        if(p==2 || p == 5){
                rep(i,n){
                                if((int)(s.at(i)-'0')%p ==0){
                                                             ans += i+1;
                        }
                }
        }
        else{
                int before = 0;
                int t = 1;
                cnt.at(0) ++;
                for(int i=n-1;i>=0;i--){
                        int d = s.at(i)-'0';
                        int now = (before + t * d) % p;
                        ans += cnt.at(now) ;
                        cnt.at(now) ++;
                        t = (t * 10)% p;
                        before = now;
                }
        }
        
        cout << ans << endl;

                              
        
        return 0;
}



Measured memory_bytes: 640
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scan = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        int N = scan.nextInt();
        int x = N * 800;
        int y = N / 15 * 200;
        System.out.println(x - y);
    }
}


Measured memory_bytes: 22736
#include <stdio.h>

int main(void){
  int N;
  scanf("%d",&N);
  int ans = N;
  
  for(int i = 0;i <= N;i++){
    int cc = 0;
    int t = i;
    while(t > 0) cc += t%6,t /= 6;
    t = N-i;
    while(t > 0) cc += t%9,t /= 9;
    if(ans > cc) ans = cc;
  }

  printf("%d\n",ans);

  return 0;
}

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

using namespace std;

const int MAXN = 200005;

int n, k, p[MAXN], minP[MAXN], maxP[MAXN], dp[MAXN];

int main() {
    scanf("%d%d", &n, &k);
    for(int i = 0; i < n; ++i)
        scanf("%d", &p[i]);

    set<int> s;
    for(int i = 0; i < n; ++i) {
        s.insert(p[i]);
        if (i >= k-2) {
            minP[i-k+2] = *s.begin();
            maxP[i-k+2] = *s.rbegin();
            s.erase(p[i-k+2]);
        }
    }

    dp[n-1] = 1;
    for(int i = n-2; i >= 0; --i)
        dp[i] = (p[i] < p[i+1]) ? (dp[i+1] + 1) : 1;

    bool original = false;
    int ans = 0;

    for(int i = k-1; i < n; ++i) {
        if (dp[i-k+1] >= k)
            original = true;
        else if (i == k-1 || maxP[i-k+1] > p[i] || p[i-k] > minP[i-k+1])
            ++ans;
    }
    if (original)
        ++ans;

    printf("%d", ans);

    return 0;
}


Measured memory_bytes: 11136
line1 = list(map(int, input().split()))
line2 = list(map(int, input().split()))
line3 = list(map(int, input().split()))

b1 = [line1[1]-line1[0], line1[2]-line1[0]]
b2 = [line2[1]-line2[0], line2[2]-line2[0]]
b3 = [line3[1]-line3[0], line3[2]-line3[0]]

a1 = [line2[0] - line1[0], line3[0] - line1[0]]
a2 = [line2[1] - line1[1], line3[1] - line1[1]]
a3 = [line2[2] - line1[2], line3[2] - line1[2]]

check = False
if b1[0] == b2[0] and b1[0] == b3[0]:
    if b1[1] == b2[1] and b1[1] == b3[1]:
        if a1[0] == a2[0] and a1[0] == a3[0]:
            if a1[1] == a2[1] and a1[1] == a3[1]:
                check = True

if check:
    print("Yes")
else:
    print("No")


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

using namespace std;

#define LL long long

const int MAXN = 212345;
const int INF  = 0x3f3f3f3f;

int main () {

	ios_base::sync_with_stdio(false); cin.tie(NULL);
	
	LL a, b;
	cin >> a >> b;

	cout << max (a - b, max (a + b, a * b)) << endl;
	

	return 0;
}

Measured memory_bytes: 256
N = int(input())
A = list(map(int, input().split()))
count_list = [0 for i in range(0, 10**5+1)]
for a in A:
    for i in range(-1, 2, 1):
        if a+i >= 0:
            count_list[a+i] += 1
print(max(count_list))


Measured memory_bytes: 13964
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<vector>
using namespace std;
typedef long long ll;
vector<pair<ll,int> >v;
int n,a,b,x,y;
ll d;
struct P{ll x,y,id;
friend bool operator <(P a,P b){return a.x==b.x?a.y<b.y:a.x<b.x;}}p[100010];
int dis(P a,P b){return abs(a.x-b.x)+abs(a.y-b.y);}
int fa[100010];ll sz[100010];
int find_f(int x){return fa[x]==x?x:fa[x]=find_f(fa[x]);}
int cnt[100010];
void solve(int now)
{
    vector<pair<ll,int> >::iterator _last,it;
    v.clear();
    int pre=1;bool _is=0;
    for (int i=1;i<=n;i++)
    {
        if (p[i].x!=p[i-1].x) v.clear(),_is=1;
        while (p[i].x-p[pre].x>d&&pre<=n) pre++;
        while (p[i].x-p[pre].x==d&&pre<=n) v.push_back(make_pair(p[pre].y,p[pre].id)),++pre;
        it=lower_bound(v.begin(),v.end(),make_pair(p[i].y-d+now,0));
        if (_is){_is=0;_last=v.begin();}
        _last=max(_last,it);
        if (it==v.end()||it->first >p[i].y+d-now) continue;
        for(;_last!=v.end()&&_last->first<=p[i].y+d-now;_last++) 
        {
            x=find_f(_last->second);y=find_f(p[i].id);
            if (x!=y) fa[x]=y;
        }
        cnt[p[i].id]+=(_last-it);
        if (_last!=it) _last--;
    }
}
int main()
{
    scanf("%d%d%d",&n,&a,&b);
    for (int i=1;i<=n;i++) scanf("%d%d",&p[i].x,&p[i].y);
    d=dis(p[a],p[b]);
    for (int i=1;i<=n;i++) {fa[i]=i;x=p[i].x;y=p[i].y;p[i].x=x-y;p[i].y=x+y;p[i].id=i;}
    sort(p+1,p+n+1);
    solve(0);
    for (int i=1;i<=n;i++) swap(p[i].x,p[i].y);
    sort(p+1,p+n+1);
    solve(1);
    for (int i=1;i<=n;i++) sz[find_f(i)]+=cnt[i];
    cout<<sz[find_f(a)];
}

Measured memory_bytes: 8664
//
//  main.cpp
//

#include <algorithm>
#include <array>
#include <assert.h>
#include <iostream>
#include <limits>
#include <math.h>
#include <memory>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>

using namespace std;

using ll = long long;
using ull = unsigned long long;

template<typename INT>
struct ListCostGraph {
    struct Edge {
        size_t from;
        size_t to;
        INT cost;
    };
    vector<vector<Edge>> edges;
    
    ListCostGraph(size_t size) { edges.resize(size); }
    
    void add_edge(size_t from, size_t to, INT cost) {
        edges[from].push_back(Edge{from, to, cost});
    }
    
    void add_edge_bidir(size_t a, size_t b, INT cost) {
        add_edge(a, b, cost);
        add_edge(b, a, cost);
    }
    
    vector<INT> dijkstra(size_t s) {
        // O(E logV)
        vector<INT> dist(edges.size(), numeric_limits<INT>::max());
        struct P {
            size_t vertex;
            INT distance;
            P(size_t vertex, INT distance)
            : vertex(vertex)
            , distance(distance) {}
        };
        auto compare = [](const P& lhs, const P& rhs) {
            return lhs.distance > rhs.distance;
        };
        priority_queue<P, vector<P>, decltype(compare)> que(compare);
        dist[s] = 0;
        que.push(P(s, 0));
        while (!que.empty()) {
            P p = que.top();
            que.pop();
            size_t v = p.vertex;
            INT d = p.distance;
            if (dist[v] < d) {
                continue;
            }
            for (int i = 0; i < edges[v].size(); i++) {
                const Edge& e = edges[v][i];
                INT new_dist = dist[v] + e.cost;
                if (dist[e.to] <= new_dist) {    // eを使っても最短経路が改善しないとき
                    continue;
                }
                dist[e.to] = new_dist;
                que.push(P(e.to, new_dist));
            }
        }
        return dist;
    }
};

int main() {
    int N;
    ll X;
    cin >> N >> X;
    vector<ll> ais;
    ll ais_sum = 0;
    for (int i = 0; i < N; i++) {
        ll ai;
        cin >> ai;
        ais.push_back(ai);
        ais_sum += ai;
    }
    ListCostGraph<ll> graph(N+1);
    for (int i = 0; i < N; i++) {
        graph.add_edge(i, i+1, ais[i]);
        graph.add_edge(i+1, i, 0);
        if (i < N-1) {
            graph.add_edge(i, i+2, X);
        }
    }
    ll min_dist = graph.dijkstra(0)[N];
    cout << ais_sum - min_dist << endl;
}


Measured memory_bytes: 17268
#include <cstdio>
#include <cmath>
#include <algorithm>
using namespace std;
long long n;
int main(){
    scanf("%lld",&n);
    for (int x=(int)(sqrt(n)+0.5);x>=1;x--){
        if (n%x==0){
            printf("%lld\n",n/x+x-2);
            return 0;
        }
    }
}


Measured memory_bytes: 128
import java.util.Scanner;

public class Main {
	public static void main(String... args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int m = sc.nextInt();
		int x = sc.nextInt();
int f=-1;
long a[]=new long[m+1];
a[0]=-3;
for(int i=1;i<=m;i++){
	a[i]=sc.nextLong();
if(a[i-1]<x&&a[i]>x){
	f=i;
}
}

System.out.println(Math.min(f-1, m-f+1));

	}}

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

// macro
#define rep(i,n) for(i=0;i<n;i++)
#define ll long long
#define all(v) v.begin(), v.end()

// code starts
#define INF 10000000

int main()
{
  int q;cin>>q;
  int i,j,k;
  rep(i,q)
  {
    string x,y;cin>>x>>y;
    int xs=x.size();
    int ys=y.size();
    vector<vector<int>> dp(xs+1,vector<int>(ys+1,0));
    rep(j,xs)
    {
      rep(k,ys)
      {
        if(x[j]==y[k])
        {
          dp[j+1][k+1]=dp[j][k]+1;
        }
        else
        {
          dp[j+1][k+1]=max(dp[j][k+1],dp[j+1][k]);
        }
      }
    }
    cout<<dp[xs][ys]<<endl;
  }
}


Measured memory_bytes: 6780
import java.util.Scanner;
public class Main {
    public static void main(String[] args){
        try(Scanner sc = new Scanner(System.in)){
            int w = sc.nextInt();
            int n = sc.nextInt();
            int[] values = new int[w];

            for(int i=0;i<values.length; i++){
                values[i] = i + 1;
            }

            for(int i=0; i<n; i++) {
                String str = sc.next();
                String[] ab = str.split(",");
                int a = Integer.parseInt(ab[0]) - 1;
                int b = Integer.parseInt(ab[1]) - 1;

                int x = values[a];
                values[a] = values[b];
                values[b] = x;

            }
            for(int i=0; i<w; i++) {
                System.out.println(values[i]);
            }
        }
    }
}


Measured memory_bytes: 26080
import sys

bing = [list(map(int, input().split())) for i in range(3)]
n = int(input())
line = [int(input()) for i in range(n)]

ans = [[0,0,0], [0,0,0], [0,0,0]]
for l in line:
    for i in range(3):
        for j in range(3):
            if l == bing[i][j]:
                ans[i][j] = bing[i][j]

# 横比較
for l in ans:
    if 0 not in l:
        print("Yes")
        sys.exit()

# 縦比較
for i in range(3):
    if ans[0][i] != 0 and ans[1][i] != 0 and ans[2][i] != 0:
        print("Yes")
        sys.exit()

# 斜め比較
if ans[0][0] != 0 and ans[1][1] != 0 and ans[2][2] != 0:
    print("Yes")
elif ans[0][2] != 0 and ans[1][1] != 0 and ans[2][0] != 0:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 38384
#include<cstdio>
#include<bitset>
std::bitset<4000032> f;
int main()
{
	int N,sum=0,a,i,k;
	f[0] = 1;
	scanf("%d",&N);
	for(i=0;i<N;i++)scanf("%d",&a),f |= (f<<a),sum += a;
	k = (sum+1)>>1;
	while(f[k] == 0)k++;
	printf("%d",k);
	return 0;
}

Measured memory_bytes: 1792
#include<iostream>
#include<iomanip>
#include<cmath>
#include<string>
#include<cstring>
#include<vector>
#include<list>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<stack>
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define mp make_pair
#define mt make_tuple
#define pqueue priority_queue
const int inf=1e9+7;
const ll mod=1e9+7;
const ll mod1=998244353;
const ll big=1e18;
const double PI=2*asin(1);

int N, K;
int parent[100005];
int doub[32][100005];
int depth[100005];
int ok[100005];
vector<vector<int> > edge(100005);

void prepare() {
  for(ll i=0;i<N;++i) {
    doub[0][i] = parent[i];
  }
  for(ll i=1;i<32;++i) {
    for(ll j=0;j<N;++j) {
      doub[i][j] = doub[i-1][doub[i-1][j]];
    }
  }
}

void getdepth(ll u, ll dist) {
  depth[u] = dist;
  for(ll i=0;i<edge[u].size();++i) {
    getdepth(edge[u][i], dist+1);
  }
  return;
}

void getok(ll u) {
  if(ok[u]) return;
  ok[u] = true;
  for(ll i=0;i<edge[u].size();++i) {
    getok(edge[u][i]);
  }
  return;
}

ll getcut(ll u) {
  ll h=K-1;
  ll two;
  ll ans=u;
  ll tmp;
  while(h>0) {
    two = 1;
    tmp = 0;
    while(2*two<h) {
      two *= 2;
      tmp++;
    }
    h -= two;
    ans = doub[tmp][ans];
  }
  return ans;
}

int main() {
  cin>>N>>K;
  ll tmp;
  ll ans = 0;
  for(ll i=0;i<N;++i) {
    cin>>tmp;
    tmp--;
    if(i==0 && tmp!=0) ans++;
    if(i!=0) {
      parent[i] = tmp;
      edge[tmp].push_back(i);
    }
  }
  prepare();
  /**
  for(ll i=0;i<10;++i) {
    for(ll j=0;j<N;++j) {
      cout<<doub[i][j]<<" ";
    }
    cout<<endl;
  }
  **/
  getdepth(0, 0);
  vector<pair<ll, ll> > arr(N);
  for(ll i=0;i<N;++i) arr[i] = mp(depth[i], i);
  sort(arr.begin(), arr.end(), greater<pair<ll, ll> >());
  ll cut;
  for(ll i=0;i<N;++i) {
    if(ok[arr[i].se]) continue;
    if(arr[i].fi<=K) continue;
    ans++;
    cut = getcut(arr[i].se);
    getok(cut);
  }
  cout<<ans<<endl;
}




Measured memory_bytes: 28764
#![allow(unused_imports)]
#![allow(non_snake_case)]
use std::cmp::*;
use std::collections::*;
use std::io::Write;

#[allow(unused_macros)]
macro_rules! debug {
    ($($e:expr),*) => {
        #[cfg(debug_assertions)]
        $({
            let (e, mut err) = (stringify!($e), std::io::stderr());
            writeln!(err, "{} = {:?}", e, $e).unwrap()
        })*
    };
}

fn main() {
    let n = read::<usize>();
    println!("{}", n * n * n);
}

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

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}


Measured memory_bytes: 2088
#include <iostream>
using namespace std;
long long n, m, ans=1, cnt, M=1e9+7, C[100050][35]={1};
int main() {
	int i, j;
	cin>>n>>m;
	for(i=1; i<=n+30; i++) {
		C[i][0] = 1;
		for(j=1; j<=min(i,30); j++) C[i][j] = (C[i-1][j-1] + C[i-1][j]) % M;
	}
	for(i=2; m>1; ) {
		if(m%i==0) cnt++, m /= i;
		else {
			ans = (ans * C[cnt+n-1][cnt]) % M;
			cnt = 0;
			i++;
		}
	}
	ans = (ans * C[cnt+n-1][cnt]) % M;
	cout<<ans;
	return 0;
}

Measured memory_bytes: 27648
cards = {}
n = int(input())

for _ in range(n):
	mark, rank = input().split()
	cards.setdefault(mark, []).append(int(rank))

for mark in ['S', 'H', 'C', 'D']:
	for rank in range(1, 14):
		if rank not in cards[mark]:
			print('{} {}'.format(mark, rank))



Measured memory_bytes: 5592
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define rep1(i,n) for(int i=1;i<=(int)n;i++)
#define sp(n) cout << fixed << setprecision(n)
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; }
typedef long long ll;
using namespace std;
int main(void){
    int m,d;cin>>m>>d;
    int res=0;
    for(int i=1;i<=d;i++){
        int x=i%10,y=i/10;
        if(x>=2&&y>=2&&x*y>=1&&x*y<=m){
            //cout<<x<<" "<<y<<endl;
            res++;
        }
    }
    cout<<res<<endl;
}

Measured memory_bytes: 256
from collections import deque
from collections import defaultdict
import sys
readline = sys.stdin.readline

N, Q = list(map(int, readline().split()))
T = defaultdict(list)
for _ in range(N-1):
    a, b = list(map(int, readline().split()))
    T[a].append(b)

P = defaultdict(int)
for _ in range(Q):
    p, x = list(map(int, readline().split()))
    P[p] += x

q = deque()
ans = [0] * (N+1)
ans[1] = P[1]

for t in T[1]:
    q.append([1, t])
while q:
    a, b = q.popleft()
    ans[b] += ans[a] + P[b]
    for c in T[b]:
        q.append([b, c])

print(*ans[1:])


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

int main()
{
        ll K, N; cin >> K >> N;
        vector<ll> A(N, 0);
        for (int i = 0; i < N; ++i) {
                cin >> A[i];
        }
        sort(A.begin(), A.end());
        vector<ll> ans;
        ll sum = 0;
        for (int i = 0; i < N-1; ++i) {
                ans.push_back(A[i+1]-A[i]);
                sum += (A[i+1]-A[i]);
        }
        ans.push_back(K-sum);
        sort(ans.begin(), ans.end(), greater<ll>());
        cout << K - ans[0] << endl;





}


Measured memory_bytes: 3956
A, B = map(int, input().split())
f = False
ans = 0
n = A * 100 // 8
m = (A + 1) * 100 // 8
for i in range(n, m + 1):
  if i * 8 // 100 == A and i // 10 == B:
    f = True
    ans = i
    break
print(ans if f else -1)


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

using namespace std;

int main() {
    string s, t;
    cin >> s >> t;

    if (t.length() > s.length()) {
        for (int i=0;i<s.length();i++) {
            if (s[i] != t[i]) {
                cout << "No" << endl;
                return 0;
            }
        }
    }

    cout << "Yes" << endl;
}


Measured memory_bytes: 3592
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define all(x) x.begin(),x.end();
#define rall(x) x.rbegin(),x.rend();
#define ld long double
#define pll pair < long long , long long >
#define endl "\n"
using namespace std;

int main()
{
    int h,a;
    cin >> h >> a;
    if(h%a==0)
    {
        cout << h/a;
    }
    else
    {
        cout << h/a+1;
    }
}


Measured memory_bytes: 256
import java.util.*;

public class Main {
public static void main(String[] args) {
		
		Scanner keyboard = new Scanner(System.in); 
		
		int A  = keyboard.nextInt();
		int B  = keyboard.nextInt();
		int K  = keyboard.nextInt();
		
		int N = A < B ? A : B;
		int[] ans = new int[N+1];
		
		for(int i=1; i<N+1; i++){
			int a = A % i;
			int b = B % i;
			if(a == 0 && b == 0){
				ans[i] = i;
			}
		}
		
		Arrays.sort(ans); 
		for(int j=N; j>=0; j--){
			if(N-j +1 == K){
				System.out.println(ans[j]) ;
				break;
			}
		}
		keyboard.close();	
	}
}

Measured memory_bytes: 21716
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <numeric>
#include <set>
using namespace std;
typedef long long int ll;


int main(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	int n; cin >> n;
	vector<int> a[n];
	for(int i=0;i<n;i++){
		for(int j=0;j<n-1;j++){
			int x; cin >> x;
			x--;
			a[i].push_back(x);
		}
		reverse(a[i].begin(),a[i].end());
	}
	int day=0;
	queue<int> check;
	for(int i=0;i<n;i++){
		check.push(i);
	}
	while(check.size()){
		queue<int> ok;
		set<int> s;
		day++;
		while(check.size()){
			int k=check.front();
			check.pop();
			if(s.find(k)!=s.end())continue;
			if(a[a[k].back()].back()==k){
				ok.push(k);
				ok.push(a[k].back());
				s.insert(k);
				s.insert(a[k].back());
			}
		}
		while(ok.size()){
			int k=ok.front();
			ok.pop();
			a[k].pop_back();
			if(a[k].size())check.push(k);
		}
	}
	for(int i=0;i<n;i++){
		if(a[i].size()){
			cout << -1 << endl;
			return 0;
		}
	}
	cout << day << endl;
}

Measured memory_bytes: 4352
import Control.Monad
import Data.List as L

data ABCD = Input { a :: Int,
b :: Int,
c :: Int,
d :: Int } deriving (Show)

toAbcd :: [Int] -> ABCD
toAbcd input = case input of
  a:b:c:d:_ -> Input a b c d

patterns :: Int -> Int -> Int -> [[Int]]
patterns 0 _ _ = [[]]
patterns rest start end = concat $ map (\a -> map (\b -> a : b) $ patterns (rest-1) a end) [start..end]

score :: [ABCD] -> [Int] -> Int
score inputs pattern = foldl (\acc cur -> if (pattern !! ((b cur) - 1)) - (pattern !! ((a cur) - 1)) == (c cur)
  then acc + d cur
  else acc) 0 inputs

main=do
  (n:m:q:_)<-L.map read . words<$>getLine::IO[Int]
  inputs <- map toAbcd <$> forM [1..q] (\_-> L.map read . words<$> getLine::IO[Int])
  print $ maximum $ map (\a -> score inputs a) $ patterns n 1 m

Measured memory_bytes: 4884
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<bitset>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<deque>
#include<list>
#include<iomanip>
#include<cmath>
#include<cstring>
#include<functional>
using namespace std;
 
#define repr(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) repr(i, 0, n)
#define INF 2e9
#define MOD 1000000007
//#define MOD 998244353
#define LINF (long long)4e18
#define jck 3.141592
 
using ll = long long;
using Pi = pair<int,int>;
using Pl = pair<ll,ll>;
 
 
 

 
int main(){
	int X; cin >> X;
	int ans = 0;
	rep(i,1000000){
		ll t = i*(i+1)/2;
		if(t >= X){
			ans = i;
			break;
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
def tap_dance(s)
  odd = %w[R U D]
  even = %w[L U D]

  s.each_char.with_index do |c, i|
    table = (i % 2).zero? ? odd : even
    return 'No' unless table.include?(c)
  end
  'Yes'
end

puts tap_dance(gets.chomp)

Measured memory_bytes: 1788
def main():
    import sys
    input = sys.stdin.readline
    n = int(input().rstrip('\n'))
    s = [int(input().rstrip('\n')) for _ in range(n)]
    t = 0
    for i in s:
        t += i
    if t % 10 != 0:
        print(t)
    else:
        s.sort()
        for i in s:
            if (t - i) % 10 != 0:
                print(t - i)
                exit()
        print(0)


if __name__ == '__main__':
    main()


Measured memory_bytes: 38384
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int n,ans,a,hi;
int main(){
    ios::sync_with_stdio(false);
    cin >> n;
    for(int i=0;i<n;i++){
    	cin >> a;
    	ans+=a;
    	hi=max(hi,a);
	}
	ans-=hi/2;
	cout << ans;
    return 0;
}

Measured memory_bytes: 256
from operator import mul
from functools import reduce

def cmb(n,r):
    r = min(n-r,r)
    if r == 0: return 1
    over = reduce(mul, range(n, n - r, -1))
    under = reduce(mul, range(1,r + 1))
    return over // under


if __name__ == '__main__':
    a,b = map(int, input().split())
    c = 0
    d = 0
    if a > 1:
        c = cmb(a,2)
    if b > 1:
        d = cmb(b,2)
    print(c+d)

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

//定数
const long long MOD1=1000000007;
const long long MOD2=998244353;
const long double PI=3.1415926535897932;
const long long MAXLL=9223372036854775807;
const long long INF=2305843009213693951;
const long long dx[]={0,1,0,-1,1,-1,1,-1};
const long long dy[]={1,0,-1,0,1,1,-1,-1};

//省略
#define ll long long
#define ull unsigned long long
#define ld long double
#define uld unsigned long double
#define pll pair<long long,long long>
#define vl vector<long long>
#define vvl vector<vector<long long>>
#define vvvl vector<vector<vector<long long>>>
#define vc vector<char>
#define vvc vector<vector<char>>
#define vs vector<string>
#define vb vector<bool>
#define vvb vector<vector<bool>>
#define vp vector<pair<long long,long long>>
#define umap unordered_map
#define uset unordered_set
#define Lqueue priority_queue<long long>
#define Squeue priority_queue<long long,vector<long long>,greater<long long>>
#define fi first
#define se second
#define mp make_pair
#define eb emplace_back

//マクロ
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define rbf(a,x) for(auto& a:x)
#define rep(i,n) for(long long i=0;i<(long long)(n);i++)
#define rep2(i,s,n) for(long long i=(s);i<(long long)(n);i++)
#define bitrep(i,s,n) for(long long i=(s);i<(1LL<<(n));i++)
#define bitcheck(bit,i) (bit)&(1LL<<(i))
#define Maxe(x) *max_element((x).begin(),(x).end())
#define Mine(x) *min_element((x).begin(),(x).end())
#define Size(x) ((long long)(x).size())
#define Lin(s) getline(cin,(s))

//Yes,No
void Yes(bool a){cout<<(a?"Yes":"No")<<endl;}
void YES(bool a){cout<<(a?"YES":"NO")<<endl;}

//MAX,MIN
template<class T,class U> auto max(T a,U b){return a>b?a:b;}
template<class T,class U> auto min(T a,U b){return a<b?a:b;}

//最大公約数,最小公倍数
long long gcd(long long a,long long b){return b?gcd(b,a%b):a;}
long long lcm(long long a,long long b){return a/gcd(a,b)*b;}

//切り上げ除算
long long cutup(long long a,long long b){return (a+b-1)/b;}

//累乗
template<typename t>
constexpr t my_pow(t a,long long b){
    if(b==0)return 1;
    if(a==0)return 0;
    t x=1;
    while(b>0){
        if(b&1LL)x*=a;
        a*=a;
        b>>=1LL;
    }
    return x;
}
#define pow my_pow

//chmin,chmax
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;}

//組み合わせ O(r)
template<typename t>
constexpr t nCr(t n,long long r){
    if(r==0)return 1;
    if(n==0)return 0;
    if(n<r)return 0;
    t x=1;
    for(long long i=1;i<=r;i++){
        x*=n-i+1;
        x/=i;
    }
    return x;
}

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    ll n,k;
    cin>>n>>k;
    YES(cutup(n,2)>=k);
}

Measured memory_bytes: 3624
use std::io::Read;

fn main() {
    let mut buf = String::new();
    std::io::stdin().read_to_string(&mut buf).unwrap();

    let answer = solve(&buf);

    println!("{}", answer);
}

fn solve(input: &str) -> String {
    let mut iterator = input.split_whitespace();

    let n: usize = iterator.next().unwrap().parse().unwrap();
    let mut ans: usize = 0;
    for i in 1..=n {
        let mut keta = 0;
        let mut k = i;
        while k > 0 {
            keta += 1;
            k /= 10;
        }
        if keta % 2 == 1 {
            ans += 1;
        }
    }

    return ans.to_string();
}


Measured memory_bytes: 2076
N, M = map(int, input().split())
p = list(map(int, input().split()))
par = [i for i in range(N+1)]
rank = [0] * (N+1)
def find(x):
    if par[x] == x:
        return x
    else:
        #親を検索
        par[x] = find(par[x])
        return par[x]

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

def union(x, y):
    x = find(x)
    y = find(y)
    if rank[x] < rank[y]:
        par[x] = y
    else:
        par[y] = x
        if rank[x] == rank[y]:
            rank[x] += 1

for i in range(M):
    x, y = map(int, input().split())
    union(x, y)
S = {}
for i in range(N):
    S[p[i]] = par[i+1]
ans = 0
for i in range(N):
    if same_checker(S[p[i]], S[i+1]):
        ans += 1

print(ans)


Measured memory_bytes: 22624
# -*- coding: utf-8 -*-
import math
import itertools
n=int(input())  #数値入力 「N」だけの入力のとき
i=0
lst = []
while i < n: 
    a,b=map(int, input().split())  #複数数値入力　「A B」みたいなスペース空いた入力のとき
    lst.append([a,b])
    i+=1

conp=[]
for i,j in itertools.combinations(lst, 2):
    conp.append(math.sqrt((i[0]-j[0])*(i[0]-j[0])+(i[1]-j[1])*(i[1]-j[1])))

length_sum = sum(float(i) for i in conp)
print(math.factorial(n-1) * 2 * length_sum/math.factorial(n))



Measured memory_bytes: 3064
//競技プログラミング用のテンプレート
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <queue>
#include <string>
#include <math.h>

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

using namespace std;
using ll = long long int;
using p = pair<int, int>;
using pl = pair<ll, ll>;
using v = vector<int>;
using vd = vector<double>;
using vs = vector<string>;
using vl = vector<ll>;

ll f(ll x){
    if(x < 2)
    {
        return 1;
    }else{
        return x * f(x - 2);
    }
}

int main()
{
    ll n;
    cin >> n;
    if(n % 2 != 0)
    {
        cout << 0 << endl;
    }else{
        ll count = 0;
        for(ll i = 10; i <= n; i *= 5)
        {
            count += n / i;
        }
        cout << count << endl;
    }
}

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

#define ff              first
#define ss              second
#define int             long long
#define pb              push_back
#define mp              make_pair
#define pii             pair<int,int>
#define vi              vector<int>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define MX              200005
#define mod             1000000007
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define mk(arr,n,type)  type *arr=new type[n];
#define w(x)            int x; cin>>x; while(x--)
#define pw(b,p)         pow(b,p) + 0.1
#define ull unsigned long long
#define ll long long

void add(int &a,int b){
    a+=b;
    if(a>=mod)
        a-=mod;
}

int isPal(string s){
    int n=s.length();
    int l=0,r=n-1;
    int ans=0;
    while(l<r){
        if(s[l]!=s[r]){
            ans++;
        }
        l++;r--;
    }
    return ans;
}

int32_t main()
{
    // int t;cin>>t;
    // while(t--){
        
    // }
    string s;cin>>s;
    int ans=isPal(s);
    cout<<ans<<endl;
    return 0;
}


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

typedef long long ll;
typedef long double ld;

#define pb push_back
#define sort(s) sort(s.begin(),s.end())
#define reverse(s) reverse(s.begin(),s.end())
#define rep(i,n) for(ll (i)=0;(i)<(n);(i)++)

const ll mod = 1e9+7;

//最大公約数
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;
}

//素数判定
bool isPrime(ll x){
    ll i;
    if(x < 2)return 0;
    else if(x == 2) return 1;
    if(x%2 == 0) return 0;
    for(i = 3; i*i <= x; i += 2) if(x%i == 0) return 0;
    return 1;
}

//桁和
int digsum(ll n) {
    int res = 0;
    while(n > 0) {
        res += n%10;
        n /= 10;
    }
    return res;
}

//桁数
int dignum(ll n) {
    int res = 0;
    while(n > 0) {
        res++;
        n /= 10;
    }
    return res;
}

//文字列中の特定の文字カウント
ll stringcount(string s,char c){
    return count(s.cbegin(),s.cend(),c);
}

//階乗
ll ka(ll i){
    ll res=1;
    while(i>0){
        res=res*i;
        i--;
    }
    return res;
}
 
//ncr
ll ncr(ll x,ll y){
    if(x==1){
        return 0;
    }
    ll a = x;
    ll b = 1;
    
    for(ll i=1;i<y;i++){
        a*=x-i;
        b*=i+1;
    }
    return a/b;
}

//フィボナッチ数列 -92
ll f(ll x){
    ll dp[x+1];
    dp[1]=1;
    dp[2]=1;
    for(ll i=3;i<=x;i++){
        dp[i]=dp[i-1]+dp[i-2];
    }
    return dp[x];
}

int npr(int x){
    int re = 1;
    while(x>1){
        re*=x;
        x--;
    }
    return re;
}



int main(){
    int n,m;
    cin >> n >> m;
    int ans = ncr(n,2)+ncr(m,2);
    cout << ans << endl;

}

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

int main(){
  string s;
  cin >> s;
  int x = 0;
  for(int i = 0; i < s.size(); i++){
    if(s[i] == 'x'){
      x++;
    }
  }
  if(x >= 8){
    cout << "NO" << endl;
  }
  else{
    cout << "YES" << endl;
  }
}

Measured memory_bytes: 256
import sys
def input(): return sys.stdin.readline().strip()

def main():
    n, x, m = map(int, input().split())
    if x == 0:
        print(0)
        return
    if x == 1:
        print(n)
        return

    d = {}
    d_idx = {}
    d_unit = {}
    idx = 0
    pow_x = x
    unit = 0
    while idx < n and pow_x not in d:
        d[pow_x] = idx
        d_idx[idx] = pow_x
        unit += pow_x
        d_unit[idx] = unit

        pow_x *= pow_x
        pow_x %= m
        idx += 1
    # x^{2^idx} = 1

    if idx == n:
        print(unit)
        return
    pre_idx = d[pow_x]
    pre_unit = d_unit[pre_idx] - d_idx[pre_idx]
    iter_unit = unit - pre_unit
    ans = pre_unit + iter_unit * ((n - pre_idx) // (idx - pre_idx))
    for i in range((n - pre_idx) % (idx - pre_idx)):
        ans += d_idx[i + pre_idx]
    print(ans)

if __name__ == "__main__":
    main()


Measured memory_bytes: 89156