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

int main() {
  int N, M;

  cin >> N >> M;

  vector<int> a(M), b(M);
  vector<int> count(N);

  for (int i = 0; i < M; i++) {
    cin >> a.at(i) >> b.at(i);
    count.at(a.at(i) - 1)++;
    count.at(b.at(i) - 1)++;
  }

  for (int i = 0; i < N; i++) {
    cout << count.at(i) << endl;
  }
}


Measured memory_bytes: 3620
import java.util.*;

public class Main {

	public static void main(String[] args) {
		
		int[][] dp=new int [1<<20][20];
		Scanner sc=new Scanner(System.in);
		int n=(int) sc.nextLong();
		int m=sc.nextInt();
		int sum=0;
		int distance[][]=new int[n][n];
		for (int i = 0; i < m; i++) {
			int u=sc.nextInt();
			int v=sc.nextInt();
			int c=sc.nextInt();
			u--;v--;
			distance[u][v]=c;
			distance[v][u]=c;
			sum+=c;
		}
		int [] s=new int[1<<n];
		for (int i = 1; i <=1<<n; i++) {
			for (int j = 0; j <n; j++) {
				for (int k = j+1; k <n; k++) {
					if((i>>j)%2==1&&(i>>k)%2==1)
					{
						s[i]+=distance[j][k];
					}
				}
			}
			
		}
		//System.out.println(Arrays.toString(s));
		for (int i = 0; i <= 1<<n; i++) {
			Arrays.fill(dp[i], -1);
		}
		dp[1][0]=0;
		for (int i = 0; i <(1<<n); i++) {
			for (int j = 0; j <n; j++) {
				if(dp[i][j]==-1)
					continue;
				for (int k = 0; k < n; k++) {					
					if((i>>k)%2==1||distance[j][k]==0)
						continue;
					dp[i|(1<<k)][k]=Math.max(dp[i|(1<<k)][k], dp[i][j]+distance[j][k]);
						
				}
				int x=(1<<n)-1-i;
				for (int y=x;y>=1;y=(y-1)&x)
					dp[i|y][j]=Math.max(dp[i|y][j],dp[i][j]+s[y|(1<<j)]);
			}
		}
		System.out.println(sum-dp[(1<<n)-1][n-1]);
	
	}

}


Measured memory_bytes: 163924
#include <stdio.h>
#include <string>
#include <iostream>
#include <iomanip>
#include <map>
#include <algorithm>
#include <vector>
#include <math.h>
#define INF 1000000007
using namespace std;

int main(void){
    int n;
    cin >> n;
    if(n==3 || n==5 || n==7){
        cout << "YES" << endl;
        return 0;
    }else {
        cout << "NO" << endl;
    }
    return 0;
}


Measured memory_bytes: 256
import java.io.BufferedReader
import java.io.InputStream
import java.io.InputStreamReader
import java.util.*

fun main(args: Array<String>) {
    val sc = FastScanner(System.`in`)

    val n = sc.nextInt()
    val p = Array(n) { sc.nextInt() }
    val q = Array(n) { sc.nextInt() }

    val res = dist(p) - dist(q)
    println(if (res < 0) -res else res)

}

fun dist(p: Array<Int>): Int {
    val used = mutableSetOf<Int>()
    var res = 0
    for (i in 0 until p.size) {
        var x = p[i]
        for (y in used) if (p[i] > y) x--

        res += (x - 1) * fact(p.size - i - 1)
        used.add(p[i])
    }
    return res
}

fun fact(n: Int): Int = if (n == 0) 1 else n * fact(n - 1)


class FastScanner(s: InputStream) {
    private var st = StringTokenizer("")
    private val br = BufferedReader(InputStreamReader(s))

    fun next(): String {
        while (!st.hasMoreTokens()) st = StringTokenizer(br.readLine())

        return st.nextToken()
    }

    fun nextInt() = next().toInt()
    fun nextLong() = next().toLong()
    fun nextLine() = br.readLine()
    fun nextDouble() = next().toDouble()
    fun ready() = br.ready()
}

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

int main()
{
	int x,y=0;
	cin>>x;
	int cnt=0;
	while(y<360)
	{
		y +=x;
		y = y%360;
		cnt++;
		if(y%360==0) break;
	}
	cout<<cnt<<endl;
}


Measured memory_bytes: 3628
S = str(input())
N = int(len(S))

x = int((N-1)/2)
y = int((N+3)/2)

a = str(S[:x])
b = str(S[y:N-1])

reverse_S = ''.join(list(reversed(S)))
reverse_a = ''.join(list(reversed(a)))
reverse_b = ''.join(list(reversed(b)))

if str(S) == str(reverse_S) and str(a) == str(reverse_a) and str(b) == str(reverse_b):
  print('Yes')
else:
  print('No')

Measured memory_bytes: 3064
from collections import Counter
N, M = map(int, input().split())
A = list(map(lambda x:int(x)%M, input().split()))
B = A[:]
for i in range(N-1):
    B[i+1] += B[i]
    B[i+1] %= M
c = Counter(B)


ans = 0
for k, v in c.items():
    if k == 0:
        ans += v
    if v >= 2:
        ans += v*(v-1)//2
print(ans)

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

using namespace std;
using ll = long long;
using ld = long double;

#define rep(i, a, b) for (auto i = (a); i < (b); ++i)
#define trav(e, x) for (auto &e : x)
#define eb(x...) emplace_back(x)
#define all(x) begin(x), end(x)
#define sz(x) int((x).size())

template<class T> bool ckmin(T& a, const T& b) { return a > b ? a = b, 1 : 0; }
template<class T> bool ckmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; }

const int inf = 1e9;
#define f first
#define s second

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

	int n; cin >> n;
	map<int, vector<pair<int, char>>> RU, DL, UL, RD, RL, UD;
	rep(i, 0, n) {
		int x, y; char d;
		cin >> x >> y >> d;
		x *= 10; y *= 10;
		if (d == 'R' || d == 'U') RU[x + y].eb(x, d);
		if (d == 'D' || d == 'L') DL[x + y].eb(x, d);
		if (d == 'U' || d == 'L') UL[x - y].eb(x, d);
		if (d == 'R' || d == 'D') RD[x - y].eb(x, d);
		if (d == 'R' || d == 'L') RL[y].eb(x, d);
		if (d == 'D' || d == 'U') UD[x].eb(y, d);
	}

	int ans = inf + 1;
	trav(z, RU) {
		auto &v = z.s;
		sort(all(v));
		rep(i, 0, sz(v) - 1)
			if (v[i].s == 'R' && v[i + 1].s == 'U')
				ckmin(ans, v[i + 1].f - v[i].f);
	}

	trav(z, DL) {
		auto &v = z.s;
		sort(all(v));
		rep(i, 0, sz(v) - 1)
			if (v[i].s == 'D' && v[i + 1].s == 'L')
				ckmin(ans, v[i + 1].f - v[i].f);
	}

	trav(z, UL) {
		auto &v = z.s;
		sort(all(v));
		rep(i, 0, sz(v) - 1)
			if (v[i].s == 'U' && v[i + 1].s == 'L')
				ckmin(ans, v[i + 1].f - v[i].f);
	}

	trav(z, RD) {
		auto &v = z.s;
		sort(all(v));
		rep(i, 0, sz(v) - 1)
			if (v[i].s == 'R' && v[i + 1].s == 'D')
				ckmin(ans, v[i + 1].f - v[i].f);
	}

	trav(z, RL) {
		auto &v = z.s;
		sort(all(v));
		rep(i, 0, sz(v) - 1)
			if (v[i].s == 'R' && v[i + 1].s == 'L')
				ckmin(ans, (v[i + 1].f - v[i].f) / 2);
	}

	trav(z, UD) {
		auto &v = z.s;
		sort(all(v));
		rep(i, 0, sz(v) - 1)
			if (v[i].s == 'U' && v[i + 1].s == 'D')
				ckmin(ans, (v[i + 1].f - v[i].f) / 2);
	}

	if (ans > inf) cout << "SAFE"; else cout << ans;
}

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

using namespace std;
using ll = long long;
using ull = unsigned long long;

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  ull n, a, b;
  cin >> n >> a >> b;
  ull bl = n / (a + b);
  n %= (a + b);
  cout << bl * a + min(a, n) << '\n';
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <limits.h>
using namespace std;

int cnt = 0, s[500000];

void Merge(int A[], int left, int mid, int right)
{
	int n1 = mid - left;
	int n2 = right - mid;

	int *L = new int[n1 + 1];
	int *R = new int[n2 + 1];


	for (int i = 0; i < n1; i++) {
		L[i] = A[left + i];
	}

	for (int i = 0; i < n2; i++) {
		R[i] = A[mid + i];
	}

	L[n1] = R[n2] = INT_MAX;

	int i = 0;
	int j = 0;

	for (int k = left; k < right; k++) {
		if (L[i] <= R[j]) {
			A[k] = L[i];
			i++;
		}
		else {
			A[k] = R[j];
			j++;
		}
		cnt++;
	}

	delete[] R;
	delete[] L;

}

void MergeSort(int A[], int left, int right)
{
	if (left + 1 < right) {
		int mid = (right + left) / 2;
		MergeSort(A, left, mid);
		MergeSort(A, mid, right);
		Merge(A, left, mid, right);
	}
}

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

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

	MergeSort(s, 0, n);

	for (int i = 0; i < n; i++) 
	{
		if (i != 0) {
			putchar(' ');
		}
		cout << s[i];
	}

	cout << endl << cnt << endl;
}

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

int main() {
    int k, s;
    cin >> k >> s;

    int res = 0;
    for (int x = 0; x <= k; x++) {
        for (int y = 0; y <= k; y++) {
            int z = s - x - y;
            if (0 <= z and z <= k) res++;
        }
    }
    cout << res << endl;
}

Measured memory_bytes: 256
string = gets.strip
text = gets.strip

min_diff = text.size

(string.size - text.size + 1).times.each do |index|
  break if index + text.size > string.size
  break if min_diff.zero?

  diff = text.size
  substr = string[index...(index + text.size)]
  substr.size.times.each do |i|
    diff -= 1 if substr[i] == text[i]
  end
  min_diff = [min_diff, diff].min
end

puts min_diff

Measured memory_bytes: 14328
import bisect

N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))

A = sorted(A)
C = sorted(C)

counter = 0

for k in range(N):
    i = bisect.bisect_left(A, B[k])
    j = N - bisect.bisect_right(C, B[k])
    counter += i * j

print(counter)

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

using namespace std;

using int64 = long long;
const int mod = 998244353;

const int64 infll = (1LL << 62) - 1;
const int inf = (1 << 30) - 1;

struct IoSetup {
  IoSetup() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
    cerr << fixed << setprecision(10);
  }
} iosetup;


template< typename T1, typename T2 >
ostream &operator<<(ostream &os, const pair< T1, T2 > &p) {
  os << p.first << " " << p.second;
  return os;
}

template< typename T1, typename T2 >
istream &operator>>(istream &is, pair< T1, T2 > &p) {
  is >> p.first >> p.second;
  return is;
}

template< typename T >
ostream &operator<<(ostream &os, const vector< T > &v) {
  for(int i = 0; i < (int) v.size(); i++) {
    os << v[i] << (i + 1 != v.size() ? " " : "");
  }
  return os;
}

template< typename T >
istream &operator>>(istream &is, vector< T > &v) {
  for(T &in : v) is >> in;
  return is;
}

template< typename T1, typename T2 >
inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }

template< typename T1, typename T2 >
inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }

template< typename T = int64 >
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< typename F >
struct FixPoint : F {
  FixPoint(F &&f) : F(forward< F >(f)) {}

  template< typename... Args >
  decltype(auto) operator()(Args &&... args) const {
    return F::operator()(*this, forward< Args >(args)...);
  }
};

template< typename F >
inline decltype(auto) MFP(F &&f) {
  return FixPoint< F >{forward< F >(f)};
}

int main() {
  int A, B, C;
  cin >> A >> B >> C;
  if(A + B + C >= 22) cout << "bust" << endl;
  else cout << "win" << endl;
}



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

int main() {
  int a,b,x,y;
  cin >> x >> y;
  if ((y - 2 * x) % 2 == 0) b = (y - 2 * x) / 2;
  else  { 
    cout << "No" << endl;
    return 0;
  }
  if (b < 0 ) {
    cout << "No" << endl;
    return 0;
  }
  a = x - b;
  if (a < 0) {
    cout << "No" << endl;
    return 0;
  }
  cout << "Yes" << endl;
  
  return 0;
}

Measured memory_bytes: 3600
#include <stdio.h>
#include <iostream>
#include <string>
#include <complex>
#include <iomanip>
using namespace std;

int main()
{
	double x1, x2, y1, y2;
	cin >> x1 >> y1 >> x2 >> y2;
	
	cout << setprecision(10) << sqrt(pow(x2 - x1, 2) + pow(y2 - y1, 2)) << endl;
}


Measured memory_bytes: 3284
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization ("unroll-loops")
#include<bits/stdc++.h>
using namespace std;
typedef long long int lli;
typedef unsigned long long int ulli;
typedef long double ld;
#define S 200005
#define M 1000000007
#define nl cout<<"\n";
#define er  cout<<"\n***********\n";
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define test lli t;  cin>>t; while(t--)
#define all(x) (x).begin(),(x).end()
#define sz(x) (lli)(x.size())
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define Y cout<<"Yes\n";
#define N cout<<"No\n";
#define print(x)                 cout<<#x<<": "<<x<<endl;
#define print2(x, y)             cout<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl;
#define print3(x, y, z)          cout<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl;
#define print4(a, b, c, d)       cout<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl;
#define print5(a, b, c, d, e)    cout<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl;
#define print6(a, b, c, d, e, f) cout<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl;


void solve()
{
    lli n;
    string str;
    cin>>str;
    n=sz(str);
    lli sum=0;
    for(lli i=0;i<n;i++)
    {
        sum=sum+lli(str[i]-'0');
        sum=sum%9;
    }

    if(sum%9==0)
    {
        Y
    }
    else
    {
        N
    }







}


int main()
{
    fast
    #ifndef ONLINE_JUDGE
     freopen("inputa.txt", "r", stdin);
     freopen("outputa.txt", "w", stdout);
    #endif    
     
     // test
     {
          solve();
          nl
     }
}
//a+b=a?b+2?(a&b)
//__builtin_popcnt(number)
//cout<<fixed<<setprecision(8)<<output<<"\n";

Measured memory_bytes: 3780
import math
from itertools import groupby

N = int(input())
S = ["".join(sorted(input())) for i in range(N)]
sizes = [len(list(v)) for k, v in groupby(sorted(S))]


def combinations_count(n, r):
    if n == 1:
        return 0
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))


ans = sum([combinations_count(size, 2) for size in sizes])
print(ans)


Measured memory_bytes: 17604
a=[]
5.times do
  a.push gets.chomp.to_i
end

k = gets.chomp.to_i

5.times do |i|
  ((i+1)..4).each do |j|
    if (a[i] - a[j]).abs > k
      puts ':('
      exit
    end
  end
end

puts 'Yay!'

Measured memory_bytes: 1788
#include <stdio.h>

int main(){
  int K,A,B;
  scanf("%d %d %d",&K,&A,&B);
  
  if((B-A+1)>=K || A%K==0 || B%K==0){
    printf("OK\n");
  }else if(A%K>B%K){
    printf("OK\n");
  }else{
    printf("NG\n");
  }
  return 0;
}

Measured memory_bytes: 1648
# include <iostream>
using namespace std;
int main(){
	int x;
	cin>>x;
	int s[x];
	for(int i=0;i<x;i++){
		scanf("%d",&s[i]);
	}
	int y=0;
	bool a[x];
	for(int i=0;i<x;i++){
	   a[i]=true;
	}
	for(int i=0;i<(x-1);i++){
		if(s[i]==s[i+1]){
		 if(a[i]==true&&a[i+1]==true){
		    a[i]=false;
			a[i+1]=false;
			y++;
		}
			
		}
	}
	cout<<y;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <vector> 
# include <cstdint>
#define FOR(i,l,r) for(int i=(l);i<(r);++i)
#define RFOR(i,l,r) for(int i=(l);i>=(int)(r);i--)
#define rep(i,n)  FOR(i,0,n)
#define rrep(i,n)  RFOR(i,n-1,0)

#define int long long
using namespace std;
const int MX = 1e6;
const int inf = 1e9;

vector<int> ra(MX,0);
vector<int> par(MX,0);
using P = pair<int, int>;
using ll = long long;
const int mod = 1000000007;
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
  mint operator+(const mint a) const { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }
 
  // for prime mod
  mint inv() const { return pow(mod-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}

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

void unite(int x, int y) {
    x = find(x);
    y = find(y);
    if(x==y) return;
    if(ra[x]<ra[y]) {
        par[x] = y;
    }else {
        par[y] = x;
        if(ra[x]==ra[y]) {
            ra[x]++;
            
        }
    }
}

bool same(int x, int y) {
    return find(x) == find(y);
}

int a[MX];
int c[10][1000];

signed main(){
    int n;
    cin >> n;
    string str;
    cin >> str;
    int ans = 1;
    FOR(i,1,n) {
        if(str[i-1]!=str[i]) ans++;
    }
    cout << ans << endl;
    return 0;

}



Measured memory_bytes: 16128
import java.util.Arrays;
import java.util.Scanner;

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

		int n = scanner.nextInt();
		int[] diameters = new int[n];

		for (int i = 0; i < n; i++) {
			diameters[i] = scanner.nextInt();
		}

		diameters = Arrays.stream(diameters).distinct().toArray();

		System.out.println(diameters.length);

		scanner.close();
	}
}

Measured memory_bytes: 28876
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#define ll long long
#define rep(i,n) for(ll i=0;i<(n);i++)
#define max(p,q) ((p)>(q)?(p):(q))
#define min(p,q) ((p)<(q)?(p):(q))
#define chmax(a,b) ((a)=(a)>(b)?(a):(b))
#define chmin(a,b) ((a)=(a)<(b)?(a):(b))
#define abs(p) ((p)>=(0)?(p):(-(p)))
#define MOD 1000000007
ll powll(ll a,ll b){ll r=1;rep(i,b){r*=a;}return r;}
#define swap(a,b) do{ll w=(a);(a)=(b);(b)=w;}while(0)
#define swapd(a,b) do{double w=(a);(a)=(b);(b)=w}while(0)
#define in(a) scanf("%lld", &(a))
#define in2(a,b) scanf("%lld %lld",&(a),&(b))
#define in3(a,b,c) scanf("%lld %lld %lld",&(a),&(b),&(c))
#define ind(a) scanf("%lf", &(a))
#define ins(a) scanf("%s", (a))
#define inc(a) scanf("%c", &(a))
#define put(a) printf("%lld\n", (a))
#define putd(a) printf("%.15f\n", (a))
//      puts(a) printf("%s\n", a) 文字はこっち
//your code here!
int cmp(const void *a, const void *b){
    ll A=*(ll *)a, B=*(ll *)b;
    if(A==B)return 0;
    else return A>B ? 1:-1;//昇順ソート 1,2,....9
}
int main(void){
    ll N, a[105];
    in(N);
    rep(i, N) in(a[i]);
    qsort(a, N, sizeof(ll), cmp);
    put(a[N-1]-a[0]);
    return 0;
}


Measured memory_bytes: 128
N=input()
b=0
count=0
if len(N)==1:
    print(N)
else:
    if (len(set(N[1:]))==1)and(N[1]=="9"):
        print(int(N[0])+9*(len(N)-1))
    else:
        print(int(N[0])-1+9*(len(N)-1))


Measured memory_bytes: 38256
#include <iostream>
#include <iomanip>
#include <vector>
#include <utility>
#include <map>
#include <algorithm>
#include <queue>
#include <cmath>
#include <numeric>
#include <set>

using namespace std;
struct aaa{aaa(){cin.tie(nullptr); ios::sync_with_stdio(false); cout<<fixed<<setprecision(20);};}aaa;
template <class T>ostream &operator<<(ostream &o,const vector<T>&v){o<<"{";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")<<v[i];o<<"}";return o;}
#define debug(v) {cerr<<"\033[1;36m[debug]\033[m "<<#v<<" : "<<v<<endl;}

using int64 = long long;

int main() {
    int n,m;
    cin >> n >> m;
    vector<int> a(m);
    for (int i=0; i<m; i++) cin >> a[i];

    cout << max(-1, n-accumulate(a.begin(),a.end(),0)) << endl;
}

Measured memory_bytes: 3208
import sys
import queue

input_methods=['clipboard','file','key']
using_method=1
input_method=input_methods[using_method]

tin=lambda : map(int, input().split())
lin=lambda : list(tin())
mod=1000000007

#+++++

def main():
	n = int(input())
	#b , c = tin()
	#s = input()
	al = lin()
	al.sort(reverse = True)
	q = queue.PriorityQueue()
	q.put((-al[1], al[1]))
	q.put((-al[1], al[1]))
	score = al[0]
	for v in al[2:]:
		o, f = q.get()
		score += f
		q.put((-v, v))
		q.put((-v, v))
	return score
	
#+++++
isTest=False

def pa(v):
	if isTest:
		print(v)
		
def input_clipboard():
	import clipboard
	input_text=clipboard.get()
	input_l=input_text.splitlines()
	for l in input_l:
		yield l

if __name__ == "__main__":
	if sys.platform =='ios':
		if input_method==input_methods[0]:
			ic=input_clipboard()
			input = lambda : ic.__next__()
		elif input_method==input_methods[1]:
			sys.stdin=open('inputFile.txt')
		else:
			pass
		isTest=True
	else:
		pass
		#input = sys.stdin.readline
			
	ret = main()
	if ret is not None:
		print(ret)

Measured memory_bytes: 40224
import heapq
import math


def main():
    nvertices, nedges, s = map(int, input().split())
    edges = [[] for i in range(nvertices)]
    for i in range(nedges):
        u, v, w = map(int, input().split())
        edges[u].append((v, w))
    INF = float('inf')
    hq = []
    for i in range(nvertices):
        heapq.heappush(hq, ((0 if i == s else INF), i))
    heapq.heapify(hq)
    weights = [INF] * nvertices
    weights[s] = 0
    while hq:
        d, u = heapq.heappop(hq)
        if d > weights[u]:
            continue
        for v, w in edges[u]:
            if weights[u] + w < weights[v]:
                weights[v] = weights[u] + w
                heapq.heappush(hq, (weights[v], v))

    for w in weights:
        print("INF" if math.isinf(w) else w)


main()

Measured memory_bytes: 102728
#include<cstdio>
#include<iostream>
using namespace std;
int a[100010];
int n;
int gcd(int a,int b)
{
	return b==0?a:gcd(b,a%b);
}
bool dg()
{
	long long sum=0;
	bool ex=0;
	int num=0;
	for (int i=1;i<=n;i++)
	{
		sum+=a[i]-1;
		if (a[i]==1) ex=1;
		if (a[i]&1) num++;
	}
	if (ex) return sum%2;
	if ((n-num)%2) return 1;
	if (num==1)
	{
		int g=0;
		for (int i=1;i<=n;i++)
			if (a[i]&1) a[i]--;
		for (int i=1;i<=n;i++)
			g=gcd(g,a[i]);
		for (int i=1;i<=n;i++)
			a[i]/=g;
		return dg()^1;
	}
	return 0;
		
}
int main()
{
	scanf("%d",&n);
	for (int i=1;i<=n;i++)
		scanf("%d",&a[i]);
	if (dg()) printf("First");
		else printf("Second");
}

Measured memory_bytes: 768
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <queue>
#include <string>
#include <set>
#include <map>
#define REP(i,n) for(ll i = 0; i < (ll)n; i++)
#define INF 1000000000000000
using namespace std;
typedef long long ll;
typedef double db;
typedef string str;

int main(){
  str s;
  int n, k;
  cin >> n >> k;
  cin >> s;
  s[k-1] -= 'A'-'a';
  cout << s << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <queue>
#include <vector>
#include <algorithm>
#include <map>

int main(){

  int N;
  long long K;
  scanf("%d",&N);
  scanf("%lld",&K);
  std::vector<long long > A(N);
  for (int i=0; i<N; i++){
    scanf("%lld",&A[i]);
  }
  std::sort(A.begin(), A.end());
  long long left = (long long)-1e18-5;
  long long right = (long long)1e18+5;
  while(right-left>1){
    //printf("=======-\n");
    long long x = (right+left)/2;
    long long count = 0;
    for (int i=0; i<N; i++){
      int indexmin=-1;
      int indexmax=N;
      while(indexmax-indexmin>1){
        int index = (indexmin+indexmax)/2;
        if (A[i]<0){
          if (A[i]*A[index]<=x){
            indexmax = index;
          } else {
            indexmin = index;
          }
        } else {
          if (A[i]*A[index]<=x){
            indexmin = index;
          } else {
            indexmax = index;
          }
        }
      }
      if (A[i]<0){
        count += N-indexmax;
        //printf("count += %lld\n",N-indexmax);
        if (indexmax<=i){
          count--;
        }
      } else {
        count += indexmin+1;
        if (indexmin>=i){
          count--;
        }
      }
      //printf("i=%d, count=%lld\n",i,count);
    }
    count /= 2;
    //printf("x=%lld, count=%lld, K=%lld\n",x, count, K);
    if (count>=K){
      right = x;
    } else {
      left = x;
    }
    //printf("[%lld, %lld]\n",left, right);
  }
  printf("%lld\n", right);
  return 0;
}


Measured memory_bytes: 1792
#include<cstdio>
#include<cstdlib>
#include<string>
#include<iostream>
using namespace std;

struct Node {
    int key;
    Node *right, *left, *parent;
};

Node *root, *NIL;

void insert(int k) {
    Node *y = NIL;
    Node *x = root;
    Node *z;
    
    z = (Node*)malloc(sizeof(Node));
    z->key = k;
    z->left = NIL;
    z->right = NIL;
    
    while (x != NIL) {
        y = x;
        if (z->key < x->key) {
            x = x->left;
        } else {
            x = x->right;
        }
    }
    z->parent = y;
    if (y == NIL) {
        root = z;
    } else {
        if (z->key < y->key) {
            y->left = z;
        } else {
            y->right = z;
        }
    }
}

void inorder(Node *u) {
    if (u == NIL) return;
    inorder(u->left);
    printf(" %d", u->key);
    inorder(u->right);
}

void preorder(Node *u) {
    if (u == NIL) return;
    printf(" %d", u->key);
    preorder(u->left);
    preorder(u->right);
}

int main() {
    int n, i, x;
    string com;
    
    scanf("%d", &n);
    
    for (i = 0; i < n; i++) {
        cin >> com;
        if (com == "insert") {
            scanf("%d", &x);
            insert(x);
        } else if( com == "print") {
            inorder(root);
            printf("\n");
            preorder(root);
            printf("\n");
        }
    }
    
    return 0;
}



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

int main() {
  
  vector<int64_t> a(4);
  int64_t N;
  
  for(int i=0; i < 4; i++){
    cin >> a.at(i);
  }
  cin >> N;
  
  int64_t min2=1000000000;
  for(int i=0; i < 4; i++){
    if( std::pow(2,3-i) * a.at(i) <= min2){
      min2 = std::pow(2,3-i) * a.at(i);
    }
  }
  
  int64_t min1=1000000000;
  for(int i=0; i < 3; i++){
    if( std::pow(2,2-i) * a.at(i) <= min1){
      min1 = std::pow(2,2-i) * a.at(i);
    }
  }
  
  if (2 * min1 <= min2){
    cout << N * min1 << endl;
  }
  
  else{
    cout << (N / 2) * min2 + (N%2) * min1 << endl;
  }
  
	return 0;
}


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

int main(){
    ll N,A,B;
    cin >> N >> A >> B;
    ll ans = 0;
    if ((A - B) % 2 == 0){
        ans = max((A - B) / 2, (B - A) / 2);
    }
    else{
        ans = min(A + (B - A - 1) / 2, (N - B + 1) + (B - A - 1) / 2);
    }
    cout << ans << endl;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
ll mod = 1000000007;

ll r(ll x, ll y) {
  if (y == 0) return 1;
  else if (y % 2 == 0) return r(x, y/2) * r(x, y/2) % mod;
  else return x * r(x, (y-1)/2) % mod * r(x, (y-1)/2) % mod;
}

ll g(int x) {
  if (x == 0 || x == 1) return 1;
  else return g(x - 1) % mod * x;
}
ll inv(int x) {
  if (x == 1) return 1;
  else return mod - inv(mod % x) * (mod / x) % mod;
}
ll ig(int x) {
  if (x == 0 || x == 1) return 1;
  else return ig(x - 1) * inv(x) % mod;
}

int main() {
  ll n, a, b;
  cin >> n >> a >> b;
  ll sum = r(2, n);
  sum %= mod;
  sum--;
  ll AA = g(a) % mod;
  ll A = r(AA, mod - 2) % mod; 
  ll na = n;
  for (int i = 0; i < a; i++) {
    A = A * na % mod;
    na--;
  }
  A %= mod;
  ll BB = g(b) % mod;
  ll B = r(BB, mod - 2) % mod;
  ll nb = n;
  for (int i = 0; i < b; i++) {
    B = B * nb % mod;
    nb--;
  }
  B %= mod;
  sum = sum - A - B;
  if (sum < 0) {
    sum += mod;
  }
  if (sum < 0) {
    sum += mod;
  }
  sum %= mod;
  printf("%lld\n", sum);
} 

Measured memory_bytes: 3328
#include <iostream>
#include <string>
#include <vector>
#include <cstdlib>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <map>
#include <stack>
#include <queue>
#include <set>
#include <cstring>

using namespace std;
#define vsort(v) sort(v.begin(), v.end());
#define asort(array) sort(array.begin(), array.end())
#define vunique(v) unique(v.begin(), v.end());
#define MAX_V 1000
#define INF 1e18
long long d[MAX_V];
struct edge {
	long long from, to, cost;
};

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	int N, M;
	cin >> N >> M;
	fill(d, d + N, INF);
	d[0] = 0; // start

	edge E[M];

	for(int i = 0; i < M; i++) {
		long long a, b, c;
		cin >> a >> b >> c;
		E[i].from = a - 1;
		E[i].to = b - 1;
		E[i].cost = -c;
	}

	for(int i = 0; i < N; i++) {
		for(int j = 0; j < M; j++) {
			edge e = E[j];
			if(d[e.to] > d[e.from] + e.cost) {
				d[e.to] = d[e.from] + e.cost;
				if(i == N - 1 && e.to == N - 1) {
					cout << "inf" << endl;
					return 0;
				}
			}
		}
	}
	cout << -d[N - 1] << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
using namespace std;
typedef long long unsigned int ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

int main() {

    ll N,K;

    cin >> N >> K;

    cout << N-K+1 << endl;


    return 0;
}

Measured memory_bytes: 256
#include"bits/stdc++.h"
using namespace std;
#define REP(k,m,n) for(int (k)=(m);(k)<(n);(k)++)
#define rep(i,n) REP((i),0,(n))
using ll = long long;
constexpr int nil = -1;

int main()
{
    int H, W, K;
    cin >> H >> W >> K;
    vector<string> s(H);
    rep(i, H)cin >> s[i];

    set<int> stw;
    rep(h, H)rep(w, W)if (s[h][w] == '#')stw.insert(w);

    int cnt = 1;
    vector<vector<int>> res(H, vector<int>(W, nil));
    for (const int w : stw) {
        rep(h, H)if (s[h][w] == '#')res[h][w] = cnt++;
        rep(h, H - 1)if (res[h][w] != nil && res[h + 1][w] == nil) {
            res[h + 1][w] = res[h][w];
        }
        for (int h = H - 1; h > 0; h--)if (res[h][w] != nil && res[h - 1][w] == nil) {
            res[h - 1][w] = res[h][w];
        }
    }
    rep(h, H)rep(w, W - 1) {
        if (res[h][w] != nil && res[h][w + 1] == nil) {
            res[h][w + 1] = res[h][w];
        }
    }
    rep(h, H)for (int w = W - 1; w > 0; w--) {
        if (res[h][w] != nil && res[h][w - 1] == nil) {
            res[h][w - 1] = res[h][w];
        }
    }
    for (auto row : res) {
        for (auto col : row) {
            cout << col << " ";
        }
        cout << endl;
    }
    return 0;
}


Measured memory_bytes: 1280
#include <bits/stdc++.h>
using namespace std;
int main()
{
  string s,t;
  cin>>s>>t;
  int i,c=0;
  for(i=0;s[i]!='\0';i++){
  	if(s[i]!=t[i])
              	c++;
  	}
    cout<<c<<endl;
}

Measured memory_bytes: 3844
#include <stdio.h>
#include <iostream>
#include <string>
#include <sstream>
#include <stack>
#include <algorithm>
#include <cmath>
#include <queue>
#include <map>
#include <set>
#include <cstdlib>
#include <bitset>
#include <tuple>
#include <assert.h>
#include <deque>
#include <bitset>
#include <iomanip>
#include <limits>
#include <chrono>
#include <random>
#include <array>
#include <unordered_map>
#include <functional>
#include <complex>
#include <numeric>
#include <cctype>


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; }
//constexpr long long MAX = 5100000;
constexpr long long INF = 1LL << 60;
constexpr int inf = 1000000007;
constexpr long long mod = 1000000007LL;
//constexpr long long mod = 998244353LL;
const long double PI = acos((long double)(-1));

using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;

pair<vector<string>, vector<string>> f(string& t) {
	string s;
	bool b = false;
	vector<string> res1, res2;
	for (int i = 0; i < t.size(); i++) {
		if (b) {
			if (t[i] == '"') {
				res2.emplace_back(s);
				b = false;
				s.clear();
			}
			else {
				s += t[i];
			}
		}
		else {
			if (t[i] == '"') {
				res1.emplace_back(s);
				b = true;
				s.clear();
			}
			else {
				s += t[i];
			}
		}
	}
	if (!s.empty()) res1.emplace_back(s);
	return { res1,res2 };
}

void solve() {
	string s; cin >> s; if (s == ".") exit(0);
	string t; cin >> t;
	if (s == t) {
		cout << "IDENTICAL" << "\n";
		return;
	}
	auto p = f(s);
	auto q = f(t);
	if (p.first != q.first or p.second.size() != q.second.size()) {
		cout << "DIFFERENT" << "\n";
		return;
	}
	int cnt = 0;
	for (int i = 0; i < p.second.size(); i++) {
		cnt += p.second[i] != q.second[i];
	}
	if (cnt == 1) {
		cout << "CLOSE" << "\n";
	}
	else {
		cout << "DIFFERENT" << "\n";
	}
}

int main()
{
	/*
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	*/
	int kkt = 89;
	while (kkt) {
		solve();
	}

}


Measured memory_bytes: 3168
# import itertools
# import pprint
# import copy
# from collections import deque

h,w   = map(int,input().split())
mp    = list(list(input()) for i in range(h))
scx   = [[0 for _ in range(w)] for _ in range(h)]
scy   = [[0 for _ in range(w)] for _ in range(h)]
donex = [[0 for _ in range(w)] for _ in range(h)]
doney = [[0 for _ in range(w)] for _ in range(h)]
sc    = 0
ans   = 0

for y in range(h):
  for x in range(w):
    if mp[y][x]=='#':
      scx[y][x]==0
    elif donex[y][x]==1:
      continue
    else:
      l = 1
      while(x+l<w):
        if mp[y][x+l]=='#':
          break
        l += 1
      for i in range(l):
        scx[y][x+i] = l
        donex[y][x+i] = 1

for y in range(h):
  for x in range(w):
    if mp[y][x]=='#':
      scy[y][x]==0
    elif doney[y][x]==1:
      continue
    else:
      l = 1
      while(y+l<h):
        if mp[y+l][x]=='#':
          break
        l += 1
      for i in range(l):
        scy[y+i][x] = l
        doney[y+i][x] = 1

for y in range(h):
  for x in range(w):
    ans = max(ans, (scy[y][x] + scx[y][x] - 1))

print(ans)

Measured memory_bytes: 317192
#include <bits/stdc++.h>
#include <bitset> 
using namespace std;
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define de(x) cout<<#x<<" = "<<x<<"\n"
#define dd(x) cout<<#x<<" = "<<x<<" "
#define mes(p) memset(p,0,sizeof(p))
#define all(x) x.begin(),x.end()
#define rson mid+1,r,rt<<1|1
#define sz(x) (int)x.size()
#define lson l,mid,rt<<1
#define mp make_pair 
#define pb push_back
#define ls (rt<<1)
#define se second
#define rs (ls|1)
#define fi first
//typedef pair <int ,int > pi;
typedef vector <int > vi;
typedef long long ll;
const int maxn=2e6+5;
const int mod= 1e9+7;
const double pi = acos(-1);
ll a[maxn], b[maxn];
int n;
ll k;
int check(ll x){
	ll K = k;
	rep(i,0,n){
		ll X = x / b[i];
		if(a[i] <= X) continue;
		K -= a[i] - X;
		if(K < 0) return 0;
	}
	return 1;
}
int main(){
	ios_base::sync_with_stdio(0);
    cin.tie(0);
	cin >> n >> k;
	rep(i,0,n ) cin>> a[i];
	rep(i,0,n) cin >>b[i];
	sort(b, b+n);
	sort(a, a+n);
	reverse(a, a+n);
	ll l = 0, r = 1e12+5;	
	while( l <= r){
		ll mid = (l+r)>>1;
		if(check(mid)) r = mid -1;
		else l = mid+1;
	}
	cout << r +1;
	return 0; 
}


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

int main()
{
        int N, Q;
        int i, j;
        char *s;
        char *t, *d;
        int total = 0, min, max;

        scanf("%d %d", &N, &Q);

        s = malloc(sizeof(char)*(N+1));
        scanf("%s", s);

        t = malloc(sizeof(char)*Q);
        d = malloc(sizeof(char)*Q);
        for(i = 0; i < Q; i++) {
                scanf("\n%c %c", &t[i], &d[i]);
        }

        for(i = Q, min = 0, max = N - 1; i >= 0; i--) {
                switch(d[i]) {
                case 'R':
                        if(t[i] == s[max]) {
                                max--;
                        }
                        if(min > 0 && t[i] == s[min - 1]) {
                                min--;
                        }
                        break;

                case 'L':
                        if(t[i] == s[min]) {
                                min++;
                        }
                        if(max < N - 1 && t[i] == s[max + 1]) {
                                max++;
                        }
                        break;
                }
        }


        printf("%d\n", max - min + 1);

        free(s);
        free(t);
        free(d);

        return 0;
}

Measured memory_bytes: 768
using System;
using System.Collections.Generic;

namespace AtCoder_CSharp
{
    class AtCoder
    {
        static void Main(string[] args)
        {
            int[] cord = new int[4];

            int input = int.Parse(Console.ReadLine());

            for(int i = 0; i < 4; i++)
            {
                cord[i] = (int)(input / Math.Pow(10, 3 - i) % 10);

                if (i > 0 && cord[i] == cord[i - 1])
                {
                    Console.WriteLine("Bad");
                    return;
                }
            }

            Console.WriteLine("Good");

        }
    }
}


Measured memory_bytes: 13140
#include <bits/stdc++.h>
#define ADD(a, b) a = (a + ll(b)) % mod
#define MUL(a, b) a = (a * ll(b)) % mod
#define MAX(a, b) a = max(a, b)
#define MIN(a, b) a = min(a, b)
#define rep(i, a, b) for(int i = int(a); i < int(b); i++)
#define rer(i, a, b) for(int i = int(a) - 1; i >= int(b); i--)
#define all(a) (a).begin(), (a).end()
#define sz(v) (int)(v).size()
#define pb push_back
#define sec second
#define fst first
#define debug(fmt, ...) Debug(__LINE__, ":", fmt, ##__VA_ARGS__)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef pair<int, pi> ppi;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vl> mat;
typedef complex<double> comp;
void Debug() {cerr << '\n'; }
template<class FIRST, class... REST>void Debug(FIRST arg, REST... rest){
	cerr<<arg<<" ";Debug(rest...);}
template<class T>ostream& operator<<(ostream& out,const vector<T>& v) {
	out<<"[";if(!v.empty()){rep(i,0,sz(v)-1)out<<v[i]<<", ";out<<v.back();}out<<"]";return out;}
template<class S, class T>ostream& operator<<(ostream& out,const pair<S, T>& v){
	out<<"("<<v.first<<", "<<v.second<<")";return out;}
const int MAX_N = 500010;
const int MAX_V = 100010;
const double eps = 1e-6;
const ll mod = 1000000007;
const int inf = (1 << 30) - 1;
const ll linf = 1LL << 60;
const double PI = 3.14159265358979323846;
mt19937 rng; //use it by rng() % mod, shuffle(all(vec), rng)
///////////////////////////////////////////////////////////////////////////////////////////////////

string str;

bool pal(string s) {
	rep(i, 0, sz(s)) {
		if(s[i] != s[sz(s) - 1 - i]) return false;
	}
	return true;
}

void solve() {
	cin >> str;
	int N = sz(str);
	if(pal(str.substr(0, (N - 1) / 2)) && pal(str.substr((N + 1) / 2, (N - 1) / 2)) && pal(str)) cout << "Yes\n";
	else cout << "No\n";
}

uint32_t rd() {
	uint32_t res;
#ifdef __MINGW32__
	asm volatile("rdrand %0" :"=a"(res) ::"cc");
#else
	res = std::random_device()();
#endif
	return res;
}

int main() {
#ifndef LOCAL
	ios::sync_with_stdio(false);
    cin.tie(0);
#endif
    cout << fixed;
	cout.precision(20);
    cerr << fixed;
	cerr.precision(6);
	rng.seed(rd());
#ifdef LOCAL
	//freopen("in.txt", "wt", stdout); //for tester
	if(!freopen("in.txt", "rt", stdin)) return 1;
#endif	
	solve();
    cerr << "Time: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
	return 0;
}



Measured memory_bytes: 256
import numpy as np
N,T = map(int, input().split())

c_list = []
t_list=[]
for i in range(N):
	c,t=map(int, input().split())
	c_list.append(c)
	t_list.append(t)

c_list = np.array(c_list)
t_list = np.array(t_list)	

if not np.any(t_list[t_list<=T]):
	print('TLE')
else:
	print(min(c_list[t_list<=T]))

Measured memory_bytes: 21408
#include <fstream>
#include <vector>
#include <map>
#include <iostream>

// BE CAREFUL WITH HASH TABLE & UNORDERED MAP
// #include <ext/pb_ds/assoc_container.hpp>
// using namespace __gnu_pbds;
using namespace std;

#define MOD 1000000007
#define FOR(i,a,b) for (int i = (a); i < (b); i++)
#define F0R(i,b) FOR(i,0,b)
#define RFO(i,a,b) for (int i = (b-1); i >= (a); i--)
#define RF0(i,b) RFO(i,0,b)
#define lli long long int
#define pii pair<int,int>
#define add(a,b) ((int) (((lli) (a) + (b))%MOD))
#define mul(a,b) ((int) (((lli) (a) * (b))%MOD))
#define PB emplace_back
#define F first
#define S second

// ifstream cin ("cinput.in");
// ofstream cout ("coutput.out");

int N;
int arr [10000];
map<int,int> pct;

int modexp(int a, int e) {
    int ans = 1;
    int cur = a;
    while (e) {
        if (e&1) {ans = mul(ans, cur); e--;}
        e /= 2;
        cur = mul(cur,cur);
    }
    return ans;
}

void pfact(int n) {
    int ct2 = 0;
    while (n % 2 == 0) {  
        ct2++;
        n = n/2;  
    }
    pct[2] = max(pct[2], ct2);
    for (int i = 3; i*i <= n; i = i + 2)  {
        int ct = 0;
        while (!(n % i)) {  
            ct++;
            n = n/i;  
        }
        pct[i] = max(pct[i], ct);
    } 
    if (n > 2)  
        pct[n] = max(pct[n], 1);
} 

vector<int> primes;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    cin >> N;
    F0R(i,N) {
        cin >> arr[i];
        pfact(arr[i]);
    }
    int lcd = 1;
    while (!pct.empty()) {
        F0R(i,pct.begin()->S) lcd = mul(lcd, pct.begin()->F);
        pct.erase(pct.begin());
    }
    int ans = 0;
    F0R(i,N) {
        ans = add(ans, mul(lcd, modexp(arr[i], MOD-2)));
    }
    cout << ans << '\n';
}

Measured memory_bytes: 4148
import java.io.*;

class Main
{
    public static void main(String args[])throws Exception
    {
        BufferedReader bu=new BufferedReader(new InputStreamReader(System.in));
        StringBuilder sb=new StringBuilder();
        int min=Integer.MAX_VALUE;
        char s[]=bu.readLine().toCharArray(),t[]=bu.readLine().toCharArray();
        int i,j,c,n=s.length,m=t.length;
        for(i=0;i<n;i++)
        {
            if(i+m>n) break;
            c=0;
            for(j=0;j<m;j++)
            if(s[i+j]!=t[j]) c++;
            min=Math.min(min,c);
        }
        System.out.print(min);
    }
}


Measured memory_bytes: 32788
import sys
readline = sys.stdin.readline

N = int(input())
a = sorted(list(map(int, input().split())))
a.append(-1)

ans = 0
pre = 0
count = 0
for n in a:
    if n == pre or pre == 0:
        count += 1
    else:
        if count >= pre:
            ans += count - pre
        else:
            ans += count
        count = 1
    pre = n
print(ans)


Measured memory_bytes: 14692
#include <bits/stdc++.h>
#define be(v) (v).begin(),(v).end()
#define pb(q) push_back(q)
typedef long long ll;
using namespace std;
const ll mod=1000000007, INF=mod*mod*3LL;
#define doublecout(a) cout<<fixed<<setprecision(10)<<a<<endl;

int main() {
    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(false);
    ll n, k;
    cin >> n >> k;
    vector<vector<ll> > past;
    past.resize(n, vector<ll> (62));
    ll a;
    for(int i=0;i<n;i++){
    	cin >> a;
    	a--;
    	past[i][0] = a;
    }
    for(int j=0;j<61;j++)for(int i=0;i<n;i++){
    	past[i][j+1] = past[past[i][j]][j];
    }
    ll now = 0;
    ll m = k;
    for(ll i=0,j=1;j<=m;i++,j*=2) if(m&j) now = past[now][i];
    cout << now +1 << endl;
    return 0;
}


Measured memory_bytes: 108008
//https://atcoder.jp/contests/abc152/tasks/abc152_d
#include <bits/stdc++.h>
#if LOCAL
#include "dump.hpp"
#else
#define dump(...)
#endif
using namespace std;
using ll=long long;
#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
template<class T>bool chmax(T &a, const T &b) {if (a<b) { a=b; return 1; } return 0;}
template<class T>bool chmin(T &a, const T &b) {if (b<a) { a=b; return 1; } return 0;}

pair<ll,ll> gethf(ll v){
    auto f = v%10;
    ll h=0;
    while(v>0){
        h = v%10;
        v /= 10;
    }
    return {h,f};
}

int main(){
    ll N; cin>>N;
    vector<vector<ll>> mat(10,vector<ll>(10));
    FOR(i,1,N+1){
        auto p = gethf(i);
        mat[p.first][p.second]++;
    }
    ll ans=0;
    FOR(i,1,10){
        FOR(j,1,10){
            ans += mat[i][j] * mat[j][i];
        }
    }
    cout<<ans<<endl;

    return 0;
}

int main_() {
#if LOCAL&01
    //std::ifstream in("./test/sample-1.in"); //input.txt
    std::ifstream in("./input.txt"); //input.txt
    std::cin.rdbuf(in.rdbuf());
#else
    cin.tie(0);
    ios::sync_with_stdio(false);
#endif
    ll N; cin>>N;    
    vector<pair<ll,ll>> tmp;
    FOR(i,1,N+1){
        tmp.push_back(gethf(i));
    }
    dump(N,tmp.size())
    dump(tmp);
    ll cnt=0;
    FOR(i,0,tmp.size()){
        FOR(j,0,tmp.size()){
            auto& a=tmp[i];
            auto& b=tmp[j];
            if(a.first==b.second&& a.second==b.first){
                dump(i+1,j+1,a,b);
                ++cnt;
            }
        }
    }
    dump(cnt, cnt+tmp.size());

    return 0;
}

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

int main() {
  ll X, Y;
  cin >> X >> Y;
  Y = Y/X;
  int count = 1;
  while (Y > 1) {
    Y = Y/2;
    count++;
  }
  cout << count << endl;
}


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

#define NDEBUG
#ifdef DEBUG
#include "cout11.h"
#undef NDEBUG
#endif
#include <cassert>

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> ii;
typedef pair<ll,ll> llll;
typedef pair<double,double> dd;

typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<ii> vii;
typedef vector<vector<ii>> vvii;
typedef vector<ll> vll;

#define sz(a)  int((a).size())
#define pb  push_back
#define FOR(var,from,to) for(int var=(from);var<=(to);++var)
#define rep(var,n)  for(int var=0;var<(n);++var)
#define rep1(var,n)  for(int var=1;var<=(n);++var)
#define repC2(vari,varj,n)  for(int vari=0;vari<(n)-1;++vari)for(int varj=vari+1;varj<(n);++varj)
#define ALL(c)  (c).begin(),(c).end()
#define RALL(c)  (c).rbegin(),(c).rend()
#define tr(i,c)  for(auto i=(c).begin(); i!=(c).end(); ++i)
#define found(s,e)  ((s).find(e)!=(s).end())
#define mset(arr,val)  memset(arr,val,sizeof(arr))
#define mid(x,y) ((x)+((y)-(x))/2)
#define IN(x,a,b) ((a)<=(x)&&(x)<=(b))

#include <stdlib.h>

int cmp(const void* a, const void* b) {
    return strcmp(*(char**)a, *(char**)b);
}
string solve(string& s, int k) {
    int L = s.size(); // 5000

    char w[5001];
    rep(i,L) w[i] = s[i]; w[L] = 0;

    char* p[5001];
    rep(i,L) p[i] = w+i;

    qsort((void*)p, (size_t)L, (size_t)sizeof(char*), &cmp);

    set<string> visited;
    int j = 0;
    rep(i,L){
        int w = strlen(p[i]);
        for(int l=1; l<=w; ++l){
            string s(p[i], p[i]+l);
            if (found(visited, s)) continue;
            visited.insert(s);
            //cerr << s << endl;
            if (++j == k) return s;
        }
    }
}

int main() {
    string s; cin >> s;
    int k; cin >> k;
    cout << solve(s,k) << endl;
    return 0;
}


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

using namespace std;

#define fst(t) std::get<0>(t)
#define snd(t) std::get<1>(t)
#define thd(t) std::get<2>(t)
#define unless(p) if(!(p))
#define until(p) while(!(p))

using ll = long long;
using P = std::tuple<int,int>;

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

int N, M;
int D[200100], T[200100];

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

    std::cin >> N;

    for(int i=0;i<N;++i){
        std::cin >> D[i];
    }

    sort(D, D+N);

    std::cin >> M;
    
    for(int i=0;i<M;++i){
        std::cin >> T[i];
    }

    sort(T, T+M);

    for(int i=0,j=0;i<M;i=j){
        while(j < M && T[j] == T[i]){
            ++j;
        }

        int n = j - i;
        auto it = lower_bound(D, D+N, T[i]);

        if(it == D + N || *it != T[i]){
            puts("NO");
            return 0;
        }

        int m = upper_bound(D, D+N, T[i]) - lower_bound(D, D+N, T[i]);
        if(m < n){
            puts("NO");
            return 0;            
        }
    }

    puts("YES");
    return 0;    
}


Measured memory_bytes: 1792