akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define db double
#define p pair<double, ll>
template<class T> void chmin(T& x, T y){if(x > y) x = y;}
template<class T> void chmax(T& x, T y){if(x < y) x = y;}

ll K;

int S(ll x){
    int res = 0;
    for(int i = 0; i < 20; i++){
        res += x % 10;
        x /= 10;
    }
    return res;
}

db g(ll x){
    return (db)x / (db)S(x);
}

ll snuke(ll x){
    priority_queue<p, vector<p>, greater<p>> pq;
   ll md = 1;
    while((x * 10) % md != x * 10){
        ll t = x - (x % md) + md - 1;
        pq.push({g(t), t});
        md *= 10;
    }
    return pq.top().second;
}

int main(){
    cin >> K;
    ll idx = 1;
    for(int i = 0; i < K; i++){
        cout << idx << endl;
        idx = snuke(idx + 1);
    }
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define For(i,n,k) for(ll i=(n);i<(k);i++)
ll n,num=0;
int graph[100][100]={0};
void Main(){    
    cin>>n;
    if(n==3){
        graph[0][2]=1;
        graph[1][2]=1;
        num=2;
    }
    else if(n%2){
        For(i,0,n){
            if(i==0||i==n-2){
                graph[i][n-1]=1;
                graph[i][1]=1;
                graph[i][n-3]=1;
                num+=3;
            }
            else if(i==n-1){
                graph[i][0]=1;
                graph[i][n-2]=1;
                graph[i][n/2]=1;
                graph[i][n/2-1]=1;
                num+=4;
            }
            else if(i==n/2||i==n/2-1){
                graph[i][n/2-2]=1;
                graph[i][n/2+1]=1;
                graph[i][n-1]=1;        
                num+=3;        
            }
            else{
                graph[i][i+1]=1;
                graph[i][i-1]=1;
                graph[i][n-i-1]=1;
                graph[i][n-i-3]=1;           
                num+=4;     
            }
        }
        num/=2;
    }
    else{
        For(i,0,n){
            if(i==0||i==n-1){
                graph[i][n/2]=1;
                graph[i][n/2-1]=1;
                graph[i][n-2]=1;
                graph[i][1]=1;
            }
            else if(i==n/2||i==n/2-1){
                graph[i][0]=1;
                graph[i][n-1]=1;
                graph[i][n/2-2]=1;     
                graph[i][n/2+1]=1;          
            }
            else{
                graph[i][i+1]=1;
                graph[i][i-1]=1;
                graph[i][n-i]=1;
                graph[i][n-i-2]=1;               
            }
        }
        if(n==4) num=4;
        else num=n*2;
    }
    cout<<num<<endl;
    For(i,0,n){
        for(ll j=i+1;j<n;j++){
            if(graph[i][j]) cout<<i+1<<" "<<j+1<<endl;
        }
    }
}
int main(){
    Main();
    return 0;
}


Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
	"strconv"
)

func main() {
	switch nextInt() {
	case 22:
		fmt.Println("Christmas Eve Eve Eve")
	case 23:
		fmt.Println("Christmas Eve Eve")
	case 24:
		fmt.Println("Christmas Eve")
	case 25:
		fmt.Println("Christmas")
	}
}

// https://atcoder.jp/contests/abc125/submissions/5181045
func pow(a, b int) int {
	return int(math.Pow(float64(a), float64(b)))
}

func lcm(a, b int) int {
	return a * b / gcd(a, b)
}

func gcd(a, b int) int {
	if a < b {
		a, b = b, a
	}
	for b != 0 {
		a, b = b, a%b
	}
	return a
}

func max(a ...int) int {
	r := a[0]
	for i := 0; i < len(a); i++ {
		if r < a[i] {
			r = a[i]
		}
	}
	return r
}

func min(a ...int) int {
	r := a[0]
	for i := 0; i < len(a); i++ {
		if r > a[i] {
			r = a[i]
		}
	}
	return r
}

func sum(a []int) (r int) {
	for i := range a {
		r += a[i]
	}
	return r
}

func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}

var nextReader func() []byte

func init() {
	nextReader = newScanner()
}

func newScanner() func() []byte {
	r := bufio.NewScanner(os.Stdin)
	r.Buffer(make([]byte, 1024), int(1e+11))
	r.Split(bufio.ScanWords)
	return func() []byte {
		r.Scan()
		return r.Bytes()
	}
}

func nextBytes() []byte {
	return nextReader()
}

func nextString() string {
	return string(nextReader())
}

func nextInt64() int64 {
	v, _ := strconv.ParseInt(string(nextReader()), 10, 64)
	return v
}

func nextInt() int {
	v, _ := strconv.Atoi(string(nextReader()))
	return v
}

func nextInts(n int) []int {
	r := make([]int, n)
	for i := 0; i < n; i++ {
		r[i] = nextInt()
	}
	return r
}

func nextFloat64() float64 {
	f, _ := strconv.ParseFloat(string(nextReader()), 64)
	return f
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i=0;i<(n);++i)
#define fi first
#define se second
#define INF 1000000009
#define lINF 1000000000000000009
typedef long long ll;

int main(){
  int n;
  cin>>n;
  multiset<int>st;
  int ans=0;
  rep(i,n){
    int a;
    scanf("%d",&a);
    auto it=st.lower_bound(a);
    if(it==st.begin()){
      ans++;
      st.insert(a);
    }
    else{
      --it;
      st.erase(it);
      st.insert(a);
    }
  }
  cout<<ans<<endl;
  return(0);
}


Measured memory_bytes: 4992
#include <bits/stdc++.h>
#define rep(i,x,n) for(int i=x; i<(int)(n); i++)
#define rep_eq(i,x,n) for(int i=x; i<=(int)(n); i++)
using namespace std;

int main() {
  int A,B,K; cin >>A >>B >>K;
  rep_eq(i,A,min(B,A+K-1)) cout <<i <<endl;
  rep_eq(i,max(B-K+1,A+K),B) cout <<i << endl;
  return 0;
}


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

long n, l, m;
long long s;

int main(){
	cin >> n;
	l = (long)sqrt(n);
	s = 0;
	for (long a = 1; a <= l; a++){
		m = n/a - 1;
		if (n % a == 0 && a < m) s += m;
	}
	cout << s;
}

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

int main() {
	ios_base::sync_with_stdio( false );
	
	int m1, d1, m2, d2;
	cin >> m1 >> d1 >> m2 >> d2;
	cout << (d1 > d2) << endl;

	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n;
    long long d;
    cin >> n >> d;
    //cout << d*d << endl;
    long long x;
    long long y;
    int cnt=0;
    long long tmp;
    for(int i=0; i<n; i++){
        cin >> x >> y;
        tmp =x*x + y*y;
        //cout << tmp << endl;
        if( d*d >= tmp){
            cnt++;
        }
    }

    cout << cnt << endl;
}




Measured memory_bytes: 3616
#define _CRT_SECURE_NO_WARNINGS
#include<cstdio>
#include<vector>
#include<string>
#include<iostream>
#include<algorithm>
#include<map>
#include<iterator>
#include<set>
#include<stack>
#include<queue>
#include<fstream>
#include<iomanip>
#include <unordered_map>
#include <unordered_set>
#include <numeric>
#include<cmath>
#include<list>
#include <sstream>
#include<unordered_map>
using namespace std;

#define FOR(i,a,b) for(int i = (a); i < (b); i++)
#define RFOR(i,b,a) for(int i = (b) - 1; i >= (a); i--)
#define ITER(it,a) for(typeof(a.begin()) it = a.begin(); it != a.end(); it++)
#define FILL(a,value) memset(a, value, sizeof(a))

#define ALL(a) a.begin(),a.end()
#define SZ(a) (int)a.size()
#define PB push_back
#define MP make_pair

typedef long long LL;
typedef vector<int> VI;
typedef pair<int, int> PII;

const double PI = acos(-1.0);
const int INF = 1000 * 1000 * 1000 + 7;
const LL LINF = INF * (LL)INF;

const int MAX = 100 + 47;

int A[MAX];
int main()
{
	//freopen("in.txt", "r", stdin);
	//freopen("out.txt", "w", stdout);
	//ios::sync_with_stdio(false); cin.tie(0);
	int n;
	cin >> n;
	n *= 2;
	FOR(i, 0, n) cin >> A[i];
	sort(A, A + n);
	reverse(A, A + n);
	int ans = 0;
	for (int i = 1; i < n; i += 2)
	{
		ans += A[i];
	}

	cout << ans << endl;
}


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

int huda[3], kingaku[3] = {10000, 5000, 1000};

bool money(int left_n, int left_y, int y){
    if(left_y < 0) return false;
    if(left_n*kingaku[y] < left_y) return false;
    bool flag = false;
    if(y==3){
        if(left_y == 0&&left_n == 0){
            return true;
        }
        else{
            return false;
        }
    }
    for(int n = left_n;n>=0;n--){
        if(flag) break;
        huda[y] = left_n - n;
        if(money(n, left_y-huda[y]*kingaku[y], y+1)){
            flag = true;
            return true;
        }
    }
    if(flag) return true;
    else return false;
}

int main(){
    long long int n, y;
    cin >> n >> y;
    if(n*10000 < y){
        cout << "-1 -1 -1" << endl;
        return 0;
    }
    if(money(n,y,0)){
        cout << huda[0] << " " << huda[1] << " " << huda[2] << endl;
    }
    else cout << "-1 -1 -1" << endl;
    return 0;
}

Measured memory_bytes: 256
fun main(args: Array<String>) {
    val n = readLine()!!.toInt()
    val nodes: Array<Node> = Array(n) { i ->
        readLine()!!.split(" ").map { it.toInt() }.let { Node(i, it[0], it[1]) }
    }
    val edges: ArrayList<Edge> = ArrayList(2 * n)
    nodes.sortBy { it.x }
    for (i in 0 until n - 1) {
        val a = nodes[i]
        val b = nodes[i + 1]
        val d = b.x - a.x
        edges.add(Edge(a.id, b.id, d))
    }
    nodes.sortBy { it.y }
    for (i in 0 until n - 1) {
        val a = nodes[i]
        val b = nodes[i + 1]
        val d = b.y - a.y
        edges.add(Edge(a.id, b.id, d))
    }
    edges.sortBy { it.dist }
    var d = 0L
    val uf = UnionFind(n)
    edges.forEach {
        if (!uf.hasSameRoot(it.from, it.to)) {
            d += it.dist
            uf.unite(it.from, it.to)
        }
    }
    println(d)
}

data class Node(val id: Int, val x: Int, val y: Int)

data class Edge(val from: Int, val to: Int, val dist: Int)

class UnionFind(size: Int) {
    private val data: Array<Int> = Array(size) { -1 }

    fun unite(x: Int, y: Int) {
        val x = find(x)
        val y = find(y)
        if (data[x] > data[y]) {
            val temp = data[x]
            data[x] = data[y]
            data[y] = temp
        }
        data[x] += data[y]
        data[y] = x
    }

    fun find(k: Int): Int {
        if (this.data[k] < 0) return k
        data[k] = find(data[k])
        return data[k]
    }

    fun hasSameRoot(x: Int, y: Int) = find(x) == find(y)

    fun size(k: Int) = -data[find(k)]
}


Measured memory_bytes: 73788
#include <bits/stdc++.h>
#include <string.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 k;
    string s;
    cin >> k;
    cin >> s;
    int b = s.size();
  int a = min(k,b);
    rep(i,a){
        cout << s[i];
        if(i == a-1 && s.size() > k){
            cout << "...";
        }
    }

    
    return 0;
}

Measured memory_bytes: 3628
s = input()
for i in range(2 ** len(s) - 1):
    tmp = s[0]
    for j in range(len(s) - 1):
        if ((i >> j) & 1):
            tmp += '+'
        else:
            tmp += '-'
        tmp += s[j + 1]
    if(eval(tmp) == 7):
        print(tmp + "=7")
        break

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  int n;
  cin >> n;
  int a[n];
  int max_a=-1000, min_a=1000;
  for(int i=0; i<n; i++){
    cin >> a[i];
    if(a[i]>max_a) max_a = a[i];
    if(a[i]<min_a) min_a = a[i];
  }
  int ans = 10000000;
  int sum=0;
  for(int i=min_a; i<=max_a; i++){
    sum = 0;
    for(int j=0; j<n; j++){
      sum += (i-a[j])*(i-a[j]);
    }
    if(ans>=sum) ans = sum;
    else break;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
x = gets()
alf = []
num = []
i = 0
until x.nil?
y = x.downcase
if i == 0
 ('a'..'z').each do |str|
  alf << str
  num << y.count(str)
 end
else
 k = 0
 ('a'..'z').each do |str|
  num[k] += y.count(str)
  k += 1
 end
end
x = gets()
i += 1
end

i = 0

while i < 26
 puts "#{alf[i]} : #{num[i]}"
 i += 1
end


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

using ll = long long;

int main() {
    int N;
    cin >> N;
    vector<ll> s(N+1);
    for(int i = 0; i < N; i++) {
        ll a;
        cin >> a;
        s[i+1] = s[i] + a;
    }

    ll ans = 1e18 + 1;
    for(int i = 1; i <= N-1; i++) {
        ans = min(ans, abs(s[i] - (s[N] - s[i])));
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
int main() {
	multiset<std::string> set;
	int i;
	for(cin>>i; i; i--) set.insert("a");
	for(cin>>i; i; i--) set.insert("b");
	for(cin>>i; i; i--) set.insert("c");
	while(set.size()>1) {
		std::string s=*set.begin(),t=*set.rbegin();
		set.erase(set.lower_bound(s));
		set.erase(set.lower_bound(t));
		set.insert(s+t);
	}
	printf("%s\n",(*set.begin()).c_str());
	return 0;
}

Measured memory_bytes: 256
N = int(input())
def cul(x, y, z):
    return(x**2 + y**2 + z**2 + x*y + y*z + z*x)

for n in range(1, N+1):
    m = 0
    ma = int((n**0.5)//1)
    ans = 0
    lim = ma + 1
    for x in range(1, lim):
        for y in range(x, lim):
            for z in range(y, lim):
                a = cul(x, y, z)
                if a == n:
                    if x == y == z:
                        ans += 1
                    elif x == y or y == z or z == x:
                        ans += 3
                    else:
                        ans += 6
                if a > n:
                    break
    print(ans)



Measured memory_bytes: 76236
#include <iostream>
#include <iterator>
#include <vector>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <string>
#include <numeric>
#include <iomanip>
#include <limits>
#include <set>
#include <map>
#include <type_traits>
#include <cstdint>
#include <queue>
#define _USE_MATH_DEFINES
#include <math.h>

typedef long long ll;

using namespace std;

//素因数分解
void factoring(ll n, map<ll, ll>& mp) {
	for (ll i = 2; i * i <= n; i++) {
		while (n % i == 0) {
			mp[i]++;
			n /= i;
		}
	}
	if (n != 1) mp[n]++;
}

//絶対値
template<class T, class U = std::make_unsigned_t<T>>
U SafeAbs( T x ) {
    return x < 0 ? -static_cast<uintmax_t>(x) : x;
}

//最大・最小
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;
}

//xのn乗
ll mod_pow(ll x, ll n, ll mod) {
    ll res = 1;
    while (n > 0) {
        if (n & 1) res = res * x % mod;
        x = x * x % mod;
        n >>= 1;
    }
    return res;
}
//xの逆元
ll mod_inv(ll x, ll mod) {//O(log(mod))
    return mod_pow(x, mod - 2, mod);
}

//nCr
ll ncr(ll n, ll r, ll mod){
	ll res=1;
	ll num=1,den=1;
	for(ll i=n;i>=n-r+1;i--){
		(den*=i)%=mod;
	}
	for(ll i=1;i<=r;i++){
		(num*=i)%=mod;
	}
	
	res=den*mod_inv(num,mod);

	return res%mod;
}


//二分探索
bool isOk(ll index, ll key,vector<ll> &a){
	
	if(a[index]>key){
		return true;
	}
	
	return false;
}

ll bin_search(ll key, vector<ll> &a){
	
	ll l=-1;
	ll r=a.size();

	while(abs(r-l)>1){
		ll mid = (l+r)/2;
		if(isOk(mid, key, a)){
			r=mid;
		}
		else{
			l=mid;
		}
	}
	return r;
}

/*
//深さ優先探索
void dfs(vector<vector<ll>> &gra,vector<bool> &seen, ll v){

	seen[v]=true;

	for(auto next : gra[v]){
		if(seen[next]){
			continue;
		}

		dfs(gra,seen,next);
	}
	
}
*/
const ll MOD=1000000007;

void solve(){
	ll n,l;
	cin>>n>>l;

	ll be=0;
	for(ll i=0;i<n;i++){
		be+=(l+i);
	}

	ll min=300;
	ll ans=0;
	for(ll i=0;i<n;i++){
		if(abs(l+i)<min){
			min=abs(l+i);
			ans=i;
		}
	}

	ans=be-(l+ans);


	cout<<ans<<endl;
}


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


Measured memory_bytes: 256
import static java.lang.Integer.parseInt;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

/**
 * A Thief (0-1 Knapsack problem)
 */
public class Main {

	public static void main(String[] args) throws IOException {

		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String line = "";

		StringBuilder sb = new StringBuilder();
		int c = 0;
		while (!(line = br.readLine()).equals("0")) {
			c++;
			int w = parseInt(line);
			int n = parseInt(br.readLine());

			int[][] dp = new int[n + 1][w + 1];
			int[] vs = new int[n + 1];
			int[] ws = new int[n + 1];

			for (int i = 1; i < n + 1; i++) {
				line = br.readLine();
				vs[i] = parseInt(line.substring(0, line.indexOf(',')));
				ws[i] = parseInt(line.substring(line.indexOf(',') + 1));
			}

			int maxv = 0;
			int minw = w;
			for (int i = 1; i < n + 1; i++) {
				for (int j = 1; j < w + 1; j++) {
					if (j >= ws[i]) {
						dp[i][j] = Math.max(dp[i - 1][j - ws[i]] + vs[i],
								dp[i - 1][j]);
						//
						if (dp[i][j] > maxv) {
							maxv = dp[i][j];
							minw = j;
						} else if (dp[i][j] == maxv) {
							minw = j < minw ? j : minw;
						}
					} else {
						dp[i][j] = dp[i - 1][j];
					}
				}
			}
			sb.append(String.format("Case %d:\n%d\n%d\n", c, maxv, minw));
		}
		System.out.print(sb.toString());
	}

}

Measured memory_bytes: 24616
#include <stdio.h>


int solve(int n, int k, int s){
	unsigned int bit=1;
	int max=1<<n;
	int count=0,i,sum;
	while(bit<max){
		if(__builtin_popcount(bit)==k){
			sum=0;
			for(i=0;i<n;i++){
				if(1<<i&bit)sum+=i+1;
			}
			if(sum==s)count++;
		}
		bit++;
	}
	return count;
}

int main(void){
	int n,k,s;
	while(scanf("%d %d %d",&n,&k,&s),n|k|s){
		printf("%d\n",solve(n,k,s));
	}
	return 0;
}

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

#define ll long long
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define sc(x) scanf("%lld",&x)
#define pr(x) printf("%lld\n",x)
#define clr(x) memset(x, 0, sizeof(x))
#define all(x) x.begin(), x.end()
typedef pair<ll, ll> pii;
typedef vector< ll > vl;
typedef vector< pii > vpii;

#define trace2(x, y)             cout <<#x<<": "<<x<<" | "<<#y<<": "<<y<< endl;
#define trace3(x, y, z)          cout <<#x<<": "<<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl;
#define trace4(a, b, c, d)       cout <<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl;
#define trace5(a, b, c, d, e)    cout <<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<<": "<<e<<endl;



//DONT WASTE YOUR TIME......i said don't waste -_- 
//prove yourself remember....fuck ps&&as hard....show them your are better then them
//Be confident.....dont lose hope.......You can do it.....
//dimaag  khoob h tere meh ....bas concentration ki kami h
//CONCENTRATE
//A,B,C dimaag nhi ...observation h .....zyaada mat sochna unme.....bas observe karna dhyaan se aur implement kar daal jitni jaldi ho sake

//capture it

// fortunately or unfortunately tu sabse badaah chodu h ....ek number ka chutiyaa -_-

const ll N= 1e6+55,mod = 1e9+7;

vl v;
int main() {
 	//freopen("task.in","r",stdin);freopen("task.out","w",stdout);
	ll i,j,k,a,b,c,x,y,z;
	sc(a);sc(b);sc(c);
	x=a;y=b;z=c;
	v.pb(a);v.pb(b);v.pb(c);
	sort(v.begin(),v.end());
	if((x%2==0 && y%2==0 && z%2==0) || (x%2==1 && y%2==1 && z%2==1)){
		j=(v[2]-v[1])/2;
		j+=(v[2]-v[0])/2;
		pr(j);
		return 0;
	}
	j=0;j++;c=0;
	for(i=0;i<3;i++){
		if(v[i]%2){
			c++;
		}
	}
	if(c==2){
		for(i=0;i<3;i++){
			if(v[i]%2){
				v[i]++;
			}
		}
	}
	else{
		for(i=0;i<3;i++){
			if(v[i]%2==0){
				v[i]++;
			}	
		}
	}	
	j+=(v[2]-v[1])/2;
	j+=(v[2]-v[0])/2;
	pr(j);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int n,a;
    cin>>n;
    std::deque<int> deq;
    for (int i=0;i<n;i++) {
        cin>>a;
        deq.emplace_back(a);
    }
    int flag=0;
    int check_num=1;
    int count=0;
    for (int j=0;j<n;j++) {
        if (deq[j]!=check_num) {
            count++;
        } else {
            check_num++;
            flag=1;
        }
    }
    if (flag==0) {
        cout<<-1<<endl;
    } else {
        cout<<count<<endl;
    }
}

Measured memory_bytes: 1024
N,A,B,C,D=map(int,input().split())
A=A-1
B=B-1
C=C-1
D=D-1

s=input()

if C<D:
    if not "##" in s[A:D+1]:
        ans="Yes"
    else:
        ans="No"
elif D<C:
    if not "##" in s[A:C+1]:
        if "..." in s[B-1:D+2]:
            ans="Yes"
        else:
            ans="No"
    else:
        ans="No"

print(ans)



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

#define name ""
#define ini freopen(name".inp","r",stdin); freopen(name".out","w",stdout)
#define long long long 
#define db double
#define pii pair <int, int> 
#define pll pair <long, long>
#define all(c) c.begin(), c.end()
#define fastio ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
template <class T> inline void chmin(T& a, const T& val) { if (a > val) a = val; }
template <class T> inline void chmax(T& a, const T& val) { if (a < val) a = val; }
template <class T> long sqr(T& a) { return 1ll * a * a; }
template <class T> void compress(vector <T> &a){
  sort(all(a));
  a.resize(unique(all(a)) - a.begin());
}

const db pi = acos(-1.00);
const db eps = 1e-6;
const int INF = 1e9;
const int MOD = 1e9+7;
const int dx[4] = {0, 0, -1, 1};
const int dy[4] = {-1, 1, 0, 0};

const int N = 2e5+1;
int n, mark[N], a[N], cur, meow;
long k;

void dfs(int u){
  mark[u] = ++cur;
  if (mark[a[u]]){
    meow = mark[a[u]];
    return;
  }
  dfs(a[u]);
}

int main()
{
  fastio;
  cin >> n >> k; k++;
  for (int i = 1; i <= n; i++) cin >> a[i];
  dfs(1);
  if (k <= cur){
    for (int u = 1; u <= n; u++){
      if (mark[u] == k) return cout << u, 0;
    }
  }
  else {
    k -= meow; 
    k %= (cur + 1 - meow);
    k += meow;
    for (int u = 1; u <= n; u++){
      if (mark[u] == k) return cout << u, 0;
    }
  }
  return 0;
}

Measured memory_bytes: 5172
#include <iostream>
#include <algorithm>
constexpr int N = 100'000, INF = 1'000'000'000;
int n;
std::pair<int, int> a[N];
int main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    std::cin >> n;
    for (int i = 0; i < n; ++i) {
        int x, l;
        std::cin >> x >> l;
        a[i] = {x - l, x + l};
    }
    std::sort(a, a + n, [&](const auto &lhs, const auto &rhs) {
        return lhs.second < rhs.second;
    });
    int ans = 0, lst = -INF;
    for (int i = 0; i < n; ++i) {
        if (a[i].first >= lst) {
            ++ans;
            lst = a[i].second;
        }
    }
    std::cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 1024
n,q = map(int,input().split())
s = input()

a = [0 for i in range(n+1)]
for i in range(n-1):
    if s[i:i+2] == 'AC':
        a[i+1] = 1

for i in range(n):
    a[i+1] += a[i]

for i in range(q):
    l,r = map(int,input().split())
    print(a[r-1] - a[l-1])


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

int main(){
    string s;
    cin >> s;
    string ans= "yes";
    rep(i,s.size()){
        for(int j=i+1;j<s.size();j++){
            if(s[i]==s[j]){
                ans ="no";
            }
        }
    }
    cout << ans << endl;
    return 0;
    }

Measured memory_bytes: 3612
N, M = map(int, input().split())
S = list(input().split())
T = list(input().split())
MOD = 10**9+7
dp = [[0] * (M+1) for _ in range(N+1)]
sum = [[0] * (M+1) for _ in range(N+1)]
dp[0][0] = 1
for i in range(N+1):
    sum[i][0] = 1
for j in range(M+1):
    sum[0][j] = 1
for i in range(N):
    for j in range(M):
        if S[i] == T[j]:
            dp[i+1][j+1] = sum[i][j]
        sum[i+1][j+1] = (sum[i+1][j] + sum[i][j+1] - sum[i][j] + dp[i+1][j+1]) % MOD
print(sum[N][M])

Measured memory_bytes: 104156
var input = require('fs').readFileSync('/dev/stdin', 'utf8');
var arr = input.trim().split("\n");
while (arr.shift() != 0) {
    var a = arr.shift().split(" ").map(Number);
    var min = Infinity;
    a.sort(function(a, b) {
        min = Math.min(min, Math.abs(a - b));
        return a - b;
    });
    console.log(min);
}


Measured memory_bytes: 19536
#include <iostream>
#include <string>
#include <cmath>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<iomanip>
#define _USE_MATH_DEFINES
#include <math.h>
#include <functional>
using namespace std;

#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)

typedef long long ll;
const ll INF = 1e17;
const ll MOD = 1000000007;
const ll MAX = 1000001;

ll max(ll a, ll b) {
	if (a > b) { return a; }
	return b;
}

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

ll gcd(ll a, ll b) {
	if (b == 0) { return a; }
	if (a < b) { return gcd(b, a); }
	return gcd(b, a%b);
}

ll lcm(ll a, ll b) {
	return a * b / gcd(a, b);
}

struct edge {
	ll ind;
	ll fr;
	ll to;
	ll d;
};


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


int main() {

	string S;
	cin >> S;

	ll N = S.size();

	vector<ll> a(N+1,0);

	rep(i, N) a[i] = S[i] - '0';

	vector<ll> b(N + 1, 0);

	b[0] = a[0];

	repn(i, N) {
		if (a[i] != a[i - 1]) { b[i] = 1; }
	}

	ll ans = N;
	
	rep(i, N + 1) {
		if (b[i] == 0) { continue; }

		ll d = max(i, N - i);
		ans = min(d, ans);
	}

	cout << ans;



	system("PAUSE");

	

}


Measured memory_bytes: 2296
def getmaxs(l):
    max1 = max2 = poz1 = poz2 = 0
    for i in range(0, len(l)):
        if l[i] > max1:
            max2 = max1
            poz2 = poz1
            max1 = l[i]
            poz1 = i
        elif l[i] > max2:
            max2 = l[i]
            poz2 = i
    return max1, max2, poz1, poz2


f1 = [0 for x in range(0, 10 ** 5 + 1)]
f2 = [0 for x in range(0, 10 ** 5 + 1)]

n = int(input())
l = list(map(int, input().split()))
for i in range(0, n):
    x = l[i]
    if i % 2 == 0:
        f1[x] = f1[x] + 1
    else:
        f2[x] = f2[x] + 1

m1, m2, p1, p2 = getmaxs(f1)
n1, n2, q1, q2 = getmaxs(f2)
if p1 != q1:
    print(n-n1-m1)
else:
    print(min(n-n1-m2, n-n2-m1))



Measured memory_bytes: 15844
def main():

    s = int(input())

    dp = [0] * 2001
    dp[3] = 1
    dp[4] = 1
    dp[5] = 1
    dp[6] = 2
    dp[7] = 3
    dp[8] = 4
    if s < 9:
        print(dp[s])
        return
    M = 10 ** 9 + 7
    total = sum(dp[:7]) + 1
    for i in range(9, s+1):
        dp[i] = total
        total += dp[i-2]
    print(dp[s] % M)
    return


if __name__=='__main__':
    main()


Measured memory_bytes: 9168
#include <iostream>
#include <math.h>
#include <algorithm>
#include <map>
using namespace std;
typedef long long ll;
#define rep(i,s,n)for(ll i=s;i<n;i++)
#define repe(i,s,n)for(ll i=s;i<=n;i++)
#define rep_r(i,s,n)for(ll i=n-1;i>=s;i--)
#define repe_r(i,s,n)for(ll i=s;i<=n;i++)
static const ll MOD = 1e9 + 7;
static const double PI = 3.141592653589793;
static const ll MAX_L = (ll)1 << 62;

map<pair<ll, ll>, ll> mp;

int main() {
	ll Y[9] = { 0, 0,0,-1,-1,-1,-2,-2,-2 };
	ll X[9] = { 0, -1,-2,0,-1,-2,0,-1,-2 };

	ll h, w, n; cin >> h >> w >> n;
	rep(i, 0, n) {
		ll a, b; cin >> a >> b;
		a--, b--;
		rep(j, 0, 9) {
			ll ny = a + Y[j];
			ll nx = b + X[j];
			if (ny >= 0 && nx >= 0 && ny + 2 < h && nx + 2 < w) {
				mp[{ny, nx}]++;
			}
		}
	}

	ll ans[10] = {};

	for (map<pair<ll, ll>, ll>::iterator it = mp.begin(); it != mp.end(); it++) {
		ans[it->second]++;
	}

	cout << (h - 2) * (w - 2) - mp.size() << endl;
	repe(i, 1, 9) {
		cout << ans[i] << endl;
	}

	return 0;
}

Measured memory_bytes: 56448
# -*- coding: utf-8 -*-

N = int(input())
a = list(map(int, input().split()))

a.sort(reverse=True)

alice = 0
bob = 0
for i in range(N):
    if(i%2 == 0):
        alice += a[i]
    else:
        bob += a[i]
        
print(alice - bob)

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

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    if (n >= 400 and n <= 599)
        cout << 8;
    else if (n >= 600 and n <= 799)
        cout << 7;
    else if (n >= 800 and n <= 999)
        cout << 6;
    else if (n >= 1000 and n <= 1199)
        cout << 5;
    else if (n >= 1200 and n <= 1399)
        cout << 4;
    else if (n >= 1400 and n <= 1599)
        cout << 3;
    else if (n >= 1600 and n <= 1799)
        cout << 2;
    else if (n >= 1800 and n <= 1999)
        cout << 1;
    return 0;
}

Measured memory_bytes: 3648
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<vector>
#define SF scanf
#define PF printf
#define MAXN 100010
using namespace std;
int n,m,sum;
vector<int> a[MAXN];
bool vis[MAXN],used[MAXN];
int val[MAXN],b[MAXN];
long long ans;
int dfs(int x){
    vis[x]=1;
    int idx=x;
    for(int i=0;i<a[x].size();i++)
        if(vis[a[x][i]]==0){
            int id=dfs(a[x][i]);
            if(val[id]<val[idx])
                idx=id;
        }
    return idx;
}
int main(){
    SF("%d%d",&n,&m);
    int u,v;
    for(int i=0;i<n;i++)
        SF("%d",&val[i]);
    for(int i=0;i<m;i++){
        SF("%d%d",&u,&v);
        a[u].push_back(v);
        a[v].push_back(u);
    }
    for(int i=0;i<n;i++)
        if(vis[i]==0){
            int maxid=dfs(i);
            used[maxid]=1;
            sum++;
        }
    int cnt=2*sum-2,tot=0;
    if(sum==1){
        PF("0");
        return 0;
    }
    for(int i=0;i<n;i++)
        if(used[i]==1)
            ans+=val[i];
    cnt-=sum;
    for(int i=0;i<n;i++)
        if(used[i]==0)
            b[++tot]=val[i];
    if(cnt>tot){
        PF("Impossible");
        return 0;
    }
    sort(b+1,b+1+tot);
    for(int i=1;i<=cnt;i++)
        ans+=b[i];
    PF("%lld\n",ans);
}


Measured memory_bytes: 6784
#include<iostream>
#include<string>
#include<cstring>
using namespace std;
string s;
int main()
{
     cin>>s;
	 if(s[0]=='Y'&&s[1]=='A'&&s[2]=='K'&&s[3]=='I') cout<<"Yes";
	 else cout<<"No";
     return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

typedef long long ll;

int main(){
  int n,m;

  for(int I = 0 ;; I++){
    ll ans = 0;
    int res[21] = {0};    

    cin >> n >> m;

    if(n == 0 && m == 0) break;
    res[0] = n;    

    int tmp[n];

    while(true){
      fill(tmp,tmp+n,0);

      if(res[m]) break;
      ans++;

      for(int i = 0 ; i < n ; i++){
	if(res[i] >= 2){
	  tmp[i+1] += res[i] / 2;
	  tmp[0] += res[i] / 2;

	  if(res[i] % 2)
	    tmp[i]++;
	}
	else{
	  tmp[i] += res[i];
	}
      }
      
      for(int i = 0 ; i < n ; i++){
	res[i] = tmp[i];
      }
    }    

    cout << "Case " << I+1 << ": ";
    cout << ans << endl;
  }

  return 0;
}

Measured memory_bytes: 1164
#include<iostream>
#include<stdio.h>
#include<string>
#include<vector>
#include<map>
#include<tuple>
#include<algorithm>
#include<cmath>
#include<limits>
#include<set>
#include<queue>
using namespace std;
#define int long  long int
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a / gcd(a, b) * b; }

signed main(){
	int A, B;
	cin >> A >> B;
	int ans = A * B - (A + B) + 1;
	cout << ans;
}

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

struct edge{
    int to;
    int from;
};
struct UnionFind{//雛形を与える(初期化と結合のみ)
    vector<int> par;//親(根)
    vector<int> rank;//木の深さ

    void init(int n){//初期化関数
        par.resize(n);
        rank.resize(n);
        for(int i = 0; i < n; i++){
            par[i] = i;//初めはノード一個の木なので根は自身
            rank[i] = 1;
        }
    }

    int root(int x){//木の根を求める
    if(par[x] == x) return x;
    else return par[x] = root(par[x]);
    }

    bool same(int x, int y){//同じ木かどうか判定
        return root(x) == root(y);//同じ木ならtrue
    }

    void unite(int x, int y){
        x = root(x);
        y = root(y);
        if(x == y) return;//もし同じ木に属していたら何もしない
        if(rank[x] < rank[y]) swap(x, y);//数が大きい方に小さい方を結合させる
        par[y] = x;
        rank[x] += rank[y];//深さが同じ時だけ結合後深さが増える
    }

    int size(int x) {//深さを返す関数
        return rank[root(x)];
    }
};

int main(){
    ll N, M, K;
    cin >> N >> M >> K;
    vector<ll> r[N];
    vector<edge> G1(M);
    vector<ll> fre(N, 0);
    UnionFind U;
    U.init(N);
    for(int i = 0; i < M; i++){
        ll x, y;
        cin >> x >> y;
        x--;
        y--;
        fre[x]++;
        fre[y]++;
        U.unite(x, y);
    }
    for(int i = 0; i < K; i++){
        ll x, y;
        cin >> x >> y;
        x--;
        y--;
        r[x].push_back(y);
        r[y].push_back(x);
    }
    for(int i = 0; i < N; i++){
        ll ans = U.size(i) - fre[i] - 1;
        for(int v:r[i]){
            if(U.same(v, i)) ans--;
        }
        cout << ans << " ";
    }
    cout << endl;
}

Measured memory_bytes: 9088
# -*- coding: utf-8 -*-

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

# 確認するのは1からBまででいい(Bの倍数分は割り切れるから余りに影響を与えない)
for i in range(1, B+1):
    if (A * i) % B == C:
        print("YES")
        exit()
print("NO")

Measured memory_bytes: 2940
#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>
#include <numeric>
using namespace std;
typedef long long int ll;

#define EPS (1e-7)
#define INF 1e18
#define max(p,q)((p)>(q)?(p):(q))
#define min(p,q)((p)<(q)?(p):(q))
#define PI (acos(-1))

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

int REC(vector<vector<int>>& G, vector<int>& input, int num){
    //cout << "Hi" << endl;

    int len = input.size();
    vector<int> a, b;
    a.assign(input.begin(), input.begin() + len / 2);
    b.assign(input.begin() + len / 2, input.end());

    for(auto tmp1 : a) for(auto tmp2 : b){
        G[tmp1][tmp2] = num;
        G[tmp2][tmp1] = num;
    }
    num++;
    if (a.size() > 1) REC(G, a, num);
    if (b.size() > 1) REC(G, b, num);
    return 0;
}

int main() {

    int N;
    cin >> N;

    vector<vector<int>> G(N, vector<int>(N, -1));
    //cout << "Hi" << endl;
    vector<int> I;
    REP(i, N) I.push_back(i);
    //cout << "Hi" << endl;

    REC(G, I, 1);

    for(int i = 0; i < N - 1; i++){
        for(int j = i + 1; j < N; j++){
            cout << G[i][j] << " ";
        }
        cout << endl;
    }


    return 0;
}

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

int main() {
	// your code goes here
	long long int  n,a=0;
	cin>>n;
	a=n%10;
	if(a==2 || a==4 || a==5 || a==7 || a==9)
	{
		cout << "hon" << endl;
	}
	else if(a==0 || a==1 || a==6 || a==8)
	{
		cout << "pon" << endl;
	}
	else if(a==3)
	{
		cout << "bon" << endl; 
	}
	return 0;
}

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


// DEFINE TO MAKE WRITING SMALL
typedef long long ll;
typedef pair<ll,ll> pll;
typedef pair<int,int> pii;
typedef vector<pair<ll,ll>> vpll;

#define pb push_back
#define ppb pop_back
#define mp make_pair
#define F first
#define S second
#define REP(i,a,b) for(int i=a;i<=b;i++)
#define REPR(i,a,b) for(int i=a;i>=b;i--)
#define lb(arr,x) lower_bound(arr.begin(),arr.end(),x)
#define ub(arr,x) upper_bound(arr.begin(),arr.end(),x)
#define er(arr,x) equal_range(arr.begin(),arr.end(),x)
// #define sort(arr) sort(arr.begin(),arr.end())
#define reverse(arr) reverse(arr.begin(),arr.end()

#define scan(x) cin>>x
#define print(x) cout<<x
#define newline cout<<"\n"
#define mod 1000000007
#define MAX 1000007

#define INF 1e9
#define test int t;cin>>t;while(t--)
#define fastIO ios_base::sync_with_stdio(false);cin.tie(NULL);

// GLOBAL VARIABLES
ll fact[MAX] = {0};
bool isPrime[MAX];

// POWER USING BINARY EXPONENTIATION
ll power(ll a,ll n){
    ll res = 1;
    ll x = a;
    while(n){
        if(n&1) res = (res*x);
        x = (x*x);
        n >>= 1;
    }
    return res;
}

// EUCLIDEAN THEOREM FOR GCD
ll gcd(ll a,ll b){
	return (!b) ? a : gcd(b,a%b);  
}

// Nth FIBONACCI NUMBER TO FIND IT
pair<ll,ll> fibonacci(ll n){
	if(n == 0){
		return {0,1}; 
	}
	pair<ll,ll> p = fibonacci(n >> 1);
	ll a = ((p.first%mod) * ((2*(p.second)%mod)%mod - (p.first)%mod))%mod;
	ll b = ((p.first%mod) * (p.first%mod))%mod + ((p.second%mod) * (p.second%mod))%mod;
	
	if(n & 1) return {b,(a+b)%mod};
	else return {a,b};
}

// FATORIAL OF A NUMBER MOD WITH mod VARIABLE
void factorial(){
    fact[0] = 1;
    fact[1] = 1;
    for(int i=2;i<MAX;i++){
        fact[i] = (i*fact[i-1])%mod;
    }
}

// CALCULATE THE INVERSE OF THE FUNCTION
ll inverse(ll n){
    ll res = 1;
    ll x = n;
    ll MOD = mod-2;
    while(MOD){
        if(MOD & 1) res = (res*x)%mod;
        MOD >>= 1;
        x = (x*x)%mod;
    }
    return res;
}

// FINDING THE COMBINATION WITH N,R
ll combination(ll n,ll r){
    return (((fact[n] * inverse(fact[r]))%mod) * 1ll * inverse(fact[n-r]))%mod;
}

// FINDING THE PRIME NUMBERS USING SEIVE METHOD
void seive(int n){
    for(int i=0;i<3001;i++) isPrime[i]=true;
    isPrime[0] = false;
    isPrime[1] = false;
    for(int i=2;i*i<=n;i++){
        if(isPrime[i]){
            for(int j=i*i;j<=n;j+=i){
                isPrime[j] = false;
            }
        }   
    }
}




int main(){
    fastIO;
    int n,count=0;
    cin>>n;
    ll arr[n];
    REP(i,0,n-1) cin>>arr[i];
    sort(arr,arr+n);
    REP(i,0,n-3){
        REP(j,i+1,n-2){
            REP(k,j+1,n-1){
                if(arr[i]!=arr[j] && arr[j]!=arr[k] && arr[i]!=arr[k] && arr[i]+arr[j] > arr[k]){
                    count++;
                }
            }
        }
    }
    cout<<count<<endl;
}




Measured memory_bytes: 3636
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <cstdio>
#include <cmath>
#include <tuple>
#include <iomanip>
#include <numeric>
#include <unordered_map>
#include <sstream>
#include<limits.h>
#include<float.h>
#include<list>
#include <array>
#include <complex>
#include<stdio.h>
#include<string.h>
#include <bitset>
#include<assert.h>

using namespace std;
#define int long long

#define I32_MAX 2147483647
#define I64_MAX 9223372036854775807LL
#define I64_MAX2 1223372036854775807LL
#define INF I64_MAX2
#define MOD 1000000007
#define MEM_SIZE 10000
#define DEBUG_OUT true
#define ALL(x) (x).begin(), (x).end()

template<typename T> void DEBUG(T e){if(DEBUG_OUT == false)return; std::cout << e <<" ";}
template<typename T> void DEBUG(const std::vector<T>& v){if(DEBUG_OUT == false)return;for(const auto& e : v){std::cout<< e << " "; } std::cout << std::endl;}
template<typename T> void DEBUG(const std::vector<std::vector<T> >& vv){if(DEBUG_OUT == false)return;for(const auto& v : vv){ DEBUG(v); } }
template<class T,class... Ts> void DEBUG(T d, Ts... e){if(DEBUG_OUT == false)return;DEBUG(d);DEBUG(e...);}
template <class T> void corner(bool flg, T hoge) {if (flg) {cout << hoge << endl; abort();}}
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); }
//SOLVE


double dist (vector<double> &v1,vector<double>&v2)
{
  
  return sqrt(pow(v1[0] - v2[0],2) + pow(v1[1] - v2[1],2));
}

void solve(void)
{
  int N;
  cin>>N;
  vector<vector<double> > data (N,vector<double>(2,0));
  for (int i = 0; i < N; i++)
  {
    cin>>data[i][0]>>data[i][1];
  }
  vector<int> vec(N);
  for (int i = 0; i < N; i++)
  {
    vec[i] = i;
  }
  int M = 1;
  for (int i = 0; i < N; i++)
  {
    M *=(i+1);
  }
  double SUM = 0;
  for (int i = 0; i < M; i++)
  {

    for (int j = 0; j < N-1; j++)
    {
      SUM += dist(data[vec[j]],data[vec[j+1]]);
    }
    next_permutation(ALL(vec));
  }
  cout<<SUM/double(M)<<endl;
  
  
  
  return;
}
int32_t main(int32_t argc, const char *argv[])
{
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);

  std::cout << std::fixed;
  std::cout << std::setprecision(11);
  solve();

  return 0;
}


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

using ll = int64_t;
#define int ll

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i <= (n); ++i)
#define drep(i, n) for (int i = (n)-1; i >= 0; --i)
#define ddrep(i, n) for (int i = n; i > 0; --i)
#define srep(i, s, t) for (int i = s; i < t; ++i)

#define rng(a) a.begin(), a.end()
#define pb push_back
#define eb emplace_back
#define fi first
#define se second

#define chmax(x, y) (x = max(x, y))
#define chmin(x, y) (x = min(x, y))

using pi = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vi>;
using ld = long double;

template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
  os << "(" << p.first << "," << p.second << ")";
  return os;
}

template <class T> ostream &operator<<(ostream &os, const vector<T> &v) {
  os << "{";
  rep(i, (int)v.size()) {
    if (i)
      os << ",";
    os << v[i];
  }
  os << "}";
  return os;
}

template <typename T, size_t S> void printArray(const T (&array)[S]) {
  for (auto val : array)
    std::cout << val << ", ";
  std::cout << "\n";
}

void printSpace() { printf(" "); }

void printEoln() { printf("\n"); }

void print(ll x, int suc = 1) {
  printf("%" PRId64, x);
  if (suc == 1)
    printEoln();
  if (suc == 2)
    printSpace();
}

const int mod = 1e9 + 7;
const int inf = 1e9 + 5;

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

  char c;
  std::cin >> c;
  char vowel[] = {'a', 'i', 'u', 'e', 'o'};
  bool ok = false;
  for (char &v : vowel) {
    if (c == v)
      ok = true;
  }
  std::cout << (ok ? "vowel" : "consonant") << std::endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <math.h>
#include <map>
#include <functional>
#include <queue>
#include <stack>
#include <string.h>
#include <list>
using namespace std;
#define rep(i,n) for(int i = 0; i < n; i++)



int main(){
    string s,t;
    cin >> s >> t;
    int n = s.length();
    bool flag = false;

    rep(i,n){
        char c = s[0];
        rep(j,n - 1){
            s[j] = s[j+1];
        }
        s[n-1] = c;
        if(s==t){
            flag = true;
            break;
        }
    }
    if(flag) cout << "Yes" << endl;
    else cout << "No" << endl;

    return 0;
}

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

using namespace std;

const int MAX_N = 2e5 + 200;

int n, m, ai[MAX_N], mem[MAX_N];

int find(int x) { return x == mem[x] ? x : mem[x] = find(mem[x]); }

int main()
{
    scanf("%d%d", &n, &m);
    for (int i = 1; i <= (n << 1); i++)
        mem[i] = i;
    for (int i = 1; i <= n; i++)
        scanf("%d", &ai[i]), mem[find(ai[i])] = find(i + n);
    for (int i = 1, u, v; i <= m; i++)
        scanf("%d%d", &u, &v), mem[find(u)] = find(v);
    int ans = 0;
    for (int i = 1; i <= n; i++)
        if (find(i) == find(n + i))
            ans++;
    printf("%d\n", ans);
    return 0;
}

Measured memory_bytes: 1408
import itertools
import math

n = int(input())
c1 = range(1, n + 1)
c2 = itertools.combinations(range(1, n + 1), 2)
c3 = itertools.combinations(range(1, n + 1), 3)

t1 = sum(list(c1))
t2 = sum(list(map(lambda x: math.gcd(x[0], x[1]), c2))) * 6
t3 = sum(list(map(lambda x: math.gcd(x[0], math.gcd(x[1], x[2])), c3))) * 6

print(sum([t1, t2, t3]))


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

int main() {
  using Edge = pair<int, int>;
  using Graph = vector<vector<Edge>>;

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

  Graph G(N);
  for(auto i = 0; i < M; ++i) {
    int s, t, d;
    cin >> s >> t >> d;
    --s, --t;
    G[s].emplace_back(t, d);
    G[t].emplace_back(s, d);
  }

  // Djikstra
  vector<int> m(N, -1);
  vector<vector<int>> d(N, vector<int>(N, -1));
  vector<vector<vector<int>>> p(N, vector<vector<int>>(N));

  for(auto i = 0; i < N; ++i) {
    using Node = tuple<int, int, int>;
    priority_queue<Node, vector<Node>, greater<Node>> q;
    q.emplace(0, i, i);

    while(!q.empty()) {
      int cost, cur, pre;
      tie(cost, cur, pre) = q.top();
      q.pop();

      if(d[i][cur] == cost) p[i][cur].emplace_back(pre);
      if(d[i][cur] != -1) continue;
      m[i] = max(m[i], cost);
      d[i][cur] = cost;
      p[i][cur] = {pre};

      for(auto e: G[cur]) {
        auto nex = e.first;
        auto c = cost + e.second;
        if(d[i][nex] == -1) q.emplace(c, nex, cur);
      }
    }
  }

  // BFS
  vector<bool> use(N);
  auto D = *max_element(begin(m), end(m));

  for(auto i = 0; i < N; ++i) {
    queue<int> q;
    for(auto v = 0; v < N; ++v) if(d[i][v] == D) q.emplace(v);

    while(!q.empty()) {
      auto cur = q.front();
      q.pop();
      use[cur] = true;
      for(auto nex: p[i][cur]) if(nex != cur) q.emplace(nex);
    }
  }

  vector<int> ans;
  for(auto i = 0; i < N; ++i) if(!use[i]) ans.emplace_back(i + 1);
  cout << ans.size() << endl;
  for(auto i: ans) cout << i << endl;
}

Measured memory_bytes: 135172
import sys
def input(): return sys.stdin.readline().rstrip()
class Sieve: #区間[2,n]の値の素因数分解
    def __init__(self,n=1):
        self.primes=[]
        self.f=[0]*(n+1) #ふるい（素数ならその値）
        self.f[0]=self.f[1]=-1
        for i in range(2,n+1): #素数リスト作成
            if self.f[i]: continue
            self.primes.append(i)
            self.f[i]=i
            for j in range(i*i,n+1,i):
                if not self.f[j]:
                    self.f[j]=i  # 最小の素因数を代入
    def is_prime(self, x):
        return self.f[x]==x
    def prime_fact(self,x): # 素因数分解の昇順リスト, {2:p,3:q,5:r,...}
        fact_dict=dict()
        while x!=1:
            p=self.f[x]
            fact_dict[p]=fact_dict.get(p,0)+1
            x//=self.f[x]
        return fact_dict

def main():
    n=int(input())
    A=list(map(int,input().split()))
    mod=10**9+7
    p_lis={}
    Prime=Sieve(10**6+5)
    for a in A:
        f=Prime.prime_fact(a)
        #print(f)
        for key in f:
            p_lis[key]=max(p_lis.get(key,0),f[key])
    lcm=1
    #print(p_lis)
    for key in p_lis:
        lcm=(lcm*pow(key,p_lis[key],mod))%mod
    ans=0
    #print(lcm)
    for a in A:
        b=lcm*pow(a,mod-2,mod)%mod
        ans=(ans+b)%mod
    print(ans)


if __name__ == '__main__':
    main()



Measured memory_bytes: 56160
#include <bits/stdc++.h>
#define INL inline
#define REG register
#define DB double
#define LDB long double
#define ULL unsigned long long
#define LL long long

#define RPT(i,x,y) for (REG int i=(x);i<(y);i++)
#define DRPT(i,x,y) for (REG int i=(x);i>(y);i--)
#define MST(a,b) memset((a),(b),sizeof(a))
#define MRK() cout<<"Mark"<<endl;
#define WRT(x) cout<<#x<<" = "<<(x)<<endl;

#define MAXN 10000
#define MAXM 10000
#define MOD 998244353
#define INF 0x3f3f3f3f
#define LLINF 0x3f3f3f3f3f3f3f3f
#define EPS 1e-5

#define _ 0
using namespace std;

int n;
int a[210000];
int col[210000];
int main()
{
	//WRT(INF);
	cin>>n;
	RPT(i,0,n)
	{
		scanf("%d",&a[i]);
		a[i]=1061108567-a[i];
	}
	int cnt=1;
	MST(col,INF);
	col[0]=a[0];
	RPT(i,1,n)
	{
		int pos=(upper_bound(col,col+cnt,a[i])-col);
		if (pos==cnt)
			cnt++;
		col[pos]=a[i];
		//cout<<a[i]<<' '<<cnt<<endl;
	}
	cout<<cnt;
	return ~~(0^_^0);
}



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

template<int MAX_N>
struct UnionFind {
    int data[MAX_N];
    int group;
    UnionFind(int n) { init(n);}
    void init(int n) {
        fill_n(data, n, -1);
        group = n;
    }
    void unite(int x, int y) {
        x = root(x); y = root(y);
        if(data[x] < data[y])  swap(x, y);        
        if(x != y){
            data[x] += data[y];
            data[y] = x;
            --group;
        }
    }
    int root(int x) { return data[x] < 0 ? x : data[x] = root(data[x]);}
    bool same(int a, int b) { return root(a) == root(b);}
};

class in{struct It{int it;const bool rev;explicit constexpr It(int it_, bool rev=false):it(it_),rev(rev){}int operator*(){return it;}bool operator!=(It& r){return it!=r.it;}void operator++(){rev?--it:++it;}};const It i,n;public:explicit constexpr in(int n):i(0),n(n<0?0:n){}explicit constexpr in(int i,int n):i(i,n<i),n(n){}const It& begin(){return i;}const It& end(){return n;}};

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

    int n, q;
    cin >> n >> q;
    UnionFind<10000> uf(n);

    for(int _ : in(q)) {
        int k, u, v;
        cin >> k >> u >> v;
        if(k)
            cout << uf.same(u, v) << '\n';
        else
            uf.unite(u, v);
    }
    return 0;
}

Measured memory_bytes: 3220