akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
using namespace std;
using namespace __gnu_pbds;
#define ll long long
#define pp pair<ll,ll>
typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update> oset;
#define ld long double
#define fi first
#define se second
#define pb push_back
#define all(x) (x).begin() , (x).end()
#define rep(i,a,b) for( ll i = a ; i < b ; i+=1 )
#define sz(v) (ll)(v.size())
#define hell (ll)1000000007
#define slld(x) scanf("%lld",&x)
ll t = 1;
void solve(){
	ll n;
	cin>>n;
	set<ll> seta;
	for(ll i=1;i*i<=n-1;i++){
		if((n-1)%i==0){
			if(i!=1)seta.insert(i);
			seta.insert((n-1)/i);
		}
	}
	for(ll i=2;i*i<=n;i++){
		if(n%i==0){
			ll x = n;
			while(x%i==0)x/=i;
			if(x%i==1)seta.insert(i);
		}
	}
	seta.insert(n);
	if(seta.find(1)!=seta.end())seta.erase(1);
	cout<<sz(seta)<<"\n";
}
signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
	//cin>>t;
    while(t--){
        solve();
        //if(t!=0)cout<<"\n";
    }
    return 0;
}


Measured memory_bytes: 256
n,m = map(int,input().split())
A = [input() for _ in range(n)]
B = [input() for _ in range(m)]
flag=0
for i in range(n-m+1):
    for j in range(n-m+1):
        flag=0
        for k1 in range(m):
            for k2 in range(m):
                if A[i+k1][j+k2]!=B[k1][k2]:
                    flag=1
                    break
            else:
                continue
            if flag==1:
                break
        else:
            print('Yes')
            exit()
else:
    print('No')

Measured memory_bytes: 3064
#include <iostream>

typedef long long int ll;
using namespace std;

int main(void){
  int K;
  cin >> K;
  ll term = 7;
  for(int i=1;i<=K;i++){
    if(term % K == 0){
      cout << i << endl;
      return 0;
    }
    term = (10*term + 7)%K;
  }
  cout << "-1" << endl;
  return 0;
}

Measured memory_bytes: 3600
#include<iostream>
using namespace std;
int main(){
  int x,y,z,w;
  w=0;
  cin >> x >> y;
  for(int i=0;i<=x;i++){
    z=x-i;
    if(i*2+z*4==y){
      w=1;
    }
  }
  if(w==1){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
}

Measured memory_bytes: 3560
import functools

import os

INF = float('inf')


def inp():
    return int(input())


def inpf():
    return float(input())


def inps():
    return input()


def inl():
    return list(map(int, input().split()))


def inlf():
    return list(map(float, input().split()))


def inls():
    return input().split()


def inpm(line):
    return [inp() for _ in range(line)]


def inpfm(line):
    return [inpf() for _ in range(line)]


def inpsm(line):
    return [inps() for _ in range(line)]


def inlm(line):
    return [inl() for _ in range(line)]


def inlfm(line):
    return [inlf() for _ in range(line)]


def inlsm(line):
    return [inls() for _ in range(line)]


def debug(fn):
    if not os.getenv('LOCAL'):
        return fn

    @functools.wraps(fn)
    def wrapper(*args, **kwargs):
        print('DEBUG: {}({}) -> '.format(
            fn.__name__,
            ', '.join(
                list(map(str, args)) +
                ['{}={}'.format(k, str(v)) for k, v in kwargs.items()]
            )
        ), end='')
        ret = fn(*args, **kwargs)
        print(ret)
        return ret

    return wrapper


s = input()
if s == s[::-1]:
    print('Yes')
else:print('No')


Measured memory_bytes: 3568
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

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

    static class AHarmony {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int q = 1; //in.nextInt();
            for (int i = 0; i < q; i++) {
                solve(in, out);
            }
        }

        private void solve(InputReader in, PrintWriter out) {
            long a = in.nextLong(), b = in.nextLong();

            long k = (a + b) / 2;

            if (Math.abs(a - k) == Math.abs(b - k))
                out.println(k);
            else
                out.println("IMPOSSIBLE");
        }

    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public long nextLong() {
            return Long.parseLong(next());
        }

    }
}



Measured memory_bytes: 24788
n, m = map(int, input().split())
k = [0] * m
s = []
for i in range(m):
    ks = list(map(int, input().split()))
    k[i] = ks[0]
    s.append(ks[1:])
p = list(map(int, input().split()))

ans = 0
for bit in range(1 << n):

    S = []
    for i in range(n):
        if bit & (1 << i):
            S.append(i)

    on = 0
    for i in range(m):
        c = 0
        for j in S:
            if ((j + 1) in s[i]):
                c += 1
        if c % 2 == p[i]:
            on += 1

    if on == m:
        ans += 1

print(ans)


Measured memory_bytes: 3188
#include <iostream>
#include <vector>
#include <unordered_set>
#include <unordered_map>
#include <map>
#include <set>
#include <string>
#include <algorithm>
#include <cmath>
#include <utility>
#include <bitset>
#include <queue>

using namespace std;

using ll = long long;

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

// 捨てたいカードで挟むようにする
// ダブった中での
// vector<i
int main()
{
	ll n;
	cin >> n;
	vector<ll> as(n);

	vector<ll> freq(100000, 0);
	vector<ll> uniq;

	vector<ll> duplicated;

	for (int i = 0; i < n; i++)
	{
		ll a;
		cin >> a;
		if (freq[a] == 0)
		{
			freq[a]++;
			uniq.push_back(a);
		}
		else
		{
			duplicated.push_back(a);
		}
	}

	sort(duplicated.begin(), duplicated.end());
	sort(uniq.begin(), uniq.end());

	// for (int i = 0; i < duplicated.size(); i++)
	// 	cout << "dup: " << duplicated[i] << endl;

	// for (int i = 0; i < uniq.size(); i++)
	// 	cout << "uniq: " << uniq[i] << endl;

	while (duplicated.size())
	{
		// cout << "size: " << duplicated.size() << endl;
		// for (int i = 0; i < duplicated.size(); i++)
		// 	cout << "dup: " << duplicated[i] << endl;

		// for (int i = 0; i < uniq.size(); i++)
		// 	cout << "uniq: " << uniq[i] << endl;
		// dupが3枚以上ある => dupの中心から3枚捨てる
		// dupが2枚 => dupから2枚, uniqの中央から1枚
		//   - 1枚しか捨てられない可能性がある
		// dupが1枚 => dupから1枚, uniqから2枚
		//   - 捨てられない可能性がある
		if (duplicated.size() >= 3)
		{
			ll center_idx = (duplicated.size() - 1) / 2;
			duplicated.erase(duplicated.begin() + (center_idx - 1));
			duplicated.erase(duplicated.begin() + (center_idx));
		}
		else if (duplicated.size() == 2)
		{
			ll top = duplicated.front(); // top < tail
			ll tail = duplicated.back();
			bool removed = false;
			for (int i = 0; i < uniq.size(); i++)
			{
				if (top <= uniq[i] && uniq[i] <= tail)
				{
					// 間にuniq挟んで処理
					duplicated.pop_back();
					duplicated.erase(duplicated.begin());
					cout << uniq.size() << endl;
					return 0;
				}
			}

			if (uniq.back() <= top)
			{
				uniq.pop_back();
				duplicated.pop_back();
			}
			else if (tail <= uniq.front())
			{
				uniq.erase(uniq.begin());
				duplicated.erase(uniq.begin());
			}
		}
		else
		{
			ll last_dup = duplicated.front();
			// duplicatedが1このとき
			// それよりおおきいものが2つある or 小さいものが2つある=>dup1ことuniq2個削る
			// そうでないとき == 1 dup 1　のときのみなので0かえす
			ll lg_cnt = 0;
			ll sm_cnt = 0;

			for (int i = 0; i < uniq.size(); i++)
			{
				if (uniq[i] <= last_dup)
					lg_cnt++;
				if (uniq[i] >= last_dup)
					sm_cnt++;
			}

			if (sm_cnt >= 2 || lg_cnt >= 2)
			{
				cout << uniq.size() - 1 << endl;
				return 0;
			}
			else
			{
				cout << 0 << endl;
				return 0;
			}
		}
	}

	cout << uniq.size() << endl;
}

Measured memory_bytes: 3132
#include<stdio.h>

int main(void)
{
	int n, x, i, j, k;

	while(1){
		int count = 0;
		scanf("%d %d", &n, &x);

		if(n==0 && x==0) break;
		else{
			for(i = 1; i <= n; i++){
				for(j = i+1; j <= n ; j++ ){
					for(k = j+1; k <= n; k++ ){
						if(i + j + k == x)
							count++;
					}
				}
			}
			printf("%d\n", count);
		}
	}
	return 0;
}


Measured memory_bytes: 2056
package main

import (
	"fmt"
	"sort"
)

func main() {
	var n, k int
	fmt.Scan(&n)
	fmt.Scan(&k)
	var h []int
	h = make([]int, n)
	for i := 0; i < n; i++ {
		var x int
		fmt.Scan(&x)
		h[i] = x
	}

	sort.Ints(h)
	for i := n - 1; i > n-1-k && i >= 0; i-- {
		h[i] = 0
	}

	var sum int64 = 0
	for i := 0; i < n; i++ {
		sum += int64(h[i])
	}
	fmt.Println(sum)
}


Measured memory_bytes: 5632
#include <bits/stdc++.h>
using namespace std;
#define rep0(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define ll long long
#define coYes cout << "Yes" << endl
#define coYES cout << "YES" << endl
#define coyes cout << "yes" << endl
#define coNo cout << "No" << endl
#define coNO cout << "NO" << endl
#define cono cout << "no" << endl
#define BIT_FLAG_0 (1<<0) // 0000 0000 0000 0001
int gcd(int a, int b){ //最大公約数
    if(a%b == 0){
        return b;
    }else{
    return gcd(b, a%b);
    }
}

int main(){
    int n,c=0;
    bool flag=true;
    cin >> n;
    vector<ll> a(n);
    rep0(i,n)
        cin >> a[i];
    while(flag){
        rep0(i,n){
            if(a[i]%2==0){
                a[i]/=2;
            }else{
                flag=false;
                break;
            }
        }
        c++;
    }
    cout << c-1 << endl;
    return 0;
}

Measured memory_bytes: 3600
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        new Main().run();
    }

    private void run() {
        Scanner scanner = new Scanner(System.in);
        int N = scanner.nextInt();
        int[] A = new int[10000000];
        long max = 0;
        for (int i = 0; i < N; i++) {
            int dist = scanner.nextInt();
            if(i == 0 && dist != 0) {
                System.out.println(0);
                return;
            }
            A[dist]++;
            max = Math.max(dist, max);
        }
        long ans = 1;
        if (A[0] != 1) {
            System.out.println(0);
            return;
        }
        for (int j = 1; j <= max; j++) {
            long a = A[j - 1];
            long n = A[j];

            while(n-- > 0) {
                ans *= (long)a;
                ans %= (long)998244353;
            }

        }
        System.out.println(ans);
    }
}


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

int main(void) {
	int card[4][13] = {0}, n, x, i, j;
	char c, ansc;
	cin >> n;
	while (n--) {
		cin >> c >> x;
		switch (c) {
		case 'S':
			card[0][x-1]++;
			break;
		case 'H':
			card[1][x-1]++;
			break;
		case 'C':
			card[2][x-1]++;
			break;
		case 'D':
			card[3][x-1]++;
			break;
		}
	}
	for (i = 0; i < 4; i++) {
		for (j = 0; j < 13; j++) {
			if (!card[i][j]) {
				switch (i) {
				case 0:
					ansc = 'S';
					break;
				case 1:
					ansc = 'H';
					break;
				case 2:
					ansc = 'C';
					break;
				case 3:
					ansc = 'D';
					break;
				}
				cout << ansc << ' ' << j + 1 << endl;
			}
		}
	}
	return 0;
}

Measured memory_bytes: 1164
#define ll long long
#define ldd long double
#define mpp make_pair
#define pb push_back
#define ff first
#define ss second
#include<bits/stdc++.h>
using namespace std;
int main(){
    ll n,m,y,x,z,h,t,i,j,k;
    ll cnt=0,cnt1=0,sum=0,sum1=0,flag=0,flag1=0,maxi=LLONG_MIN,mini=LLONG_MAX,temp=0,ans=0;
    //freopen("input.txt","r", stdin);
    //freopen("output.txt","w",stdout);
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    cin>>t;
    cout<<2*3.14159*t<<endl;

return 0;
}


Measured memory_bytes: 3800
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#include <numeric>
#include <unordered_map>
#include <queue>
#include <sstream>
#include <cstring>
#include <iomanip>

using namespace std;

typedef long long ll;

const ll INF=1e13+7;

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;}

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

int main(){
    int N;
    ll count=0;
    cin>>N;
    unordered_map<string,int> mp;
    for(int i=0;i<N;i++){
        string A;
        cin>>A;
        sort(A.begin(),A.end());
        count+=mp[A];
        mp[A]++;
    }
    cout<<count<<endl;
    return 0;
}

//a=97,z=122

Measured memory_bytes: 10660
#include<bits/stdc++.h>
using namespace std;
#define lli long long
#define llmax LLONG_MAX   //ranges are defined in climits
#define llmin LLONG_MIN
#define imax INT_MAX
#define imin INT_MIN
#define pb push_back
int main()
{
	ios_base::sync_with_stdio(false);cin.tie(NULL);
  int n;cin>>n;
  
  int x=0,max_x=0;
  for(int i=0;i<n;i++)
  {
    char c; cin>>c;
    if(c=='I')
    ++x;
    else if(c=='D')
    --x;
    max_x = max(x,max_x);
  }
  cout<<max_x;
	return 0;
}

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

#define V             vector
#define PQ            priority_queue

#define pb            push_back
#define mp            make_pair
#define ins           insert
#define endl          '\n'
#define all(x)        x.begin(),x.end()
#define debug(X)      { cerr<<endl<<(#X)<<" = "<<(X)<<endl; }
//#define cerr if(0)cerr

typedef long long ll;
typedef unsigned long long ull;


int main() {
    ios_base::sync_with_stdio(0);cin.tie(0);
#define N 1000000
    int x;
    bool a[N];
    memset(a, 1, sizeof(a));
    
    for (ll i=2; i*i<=N; ++i)
        if (a[i])
            for (ll j=i*i; j<=N; j+=i)
                a[j]=0;
    cin>>x;
    while (!a[x]) ++x;
    cout<<x<<endl;
}



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

using namespace std ;

const int MAX = 12 + 10 ;

int arr[MAX] ;
int k ;

long long dp[MAX][10][2] ;

long long solve(int idx , int prv , bool took)
{
	if(prv < 0 || prv >= 10)
		return 0 ;
	if(prv != 0)
		took = 1 ;
	if(idx == 10)
		return took ;
	long long &ret = dp[idx][prv][took] ;
	if(ret != -1)
		return ret ;
	ret = 0 ;
	if(took == 0)
	{
		ret = solve(idx+1 , 0 , took) ;
		for(int i = 1 ; i <= 9 ; ++i)
			ret += solve(idx+1 , i , took) ;
	}
	else
	{			
		ret += solve(idx+1 , prv+1 , took) ;
		ret += solve(idx+1 , prv , took) ;
		ret += solve(idx+1 , prv-1 , took) ;
	}
	return ret ;
}

int main()
{
	memset(dp , -1 , sizeof(dp)) ;
	ios_base::sync_with_stdio(0) ;
	cin.tie(0) ;
	cin>>k ;
	long long ans = 0ll , cur ;
	for(int idx = 0 ; idx < 10 ; ++idx)
	{
		for(int i = 0 ; i <= 9 ; ++i)
		{
			if(ans != 0 && abs(cur - i) > 1)
					continue ;
			long long x ;
			if(ans == 0)
				x = solve(idx+1 , i , 0) ;
			else
				x = solve(idx+1 , i , 1) ;
			if(x < k)
				k -= x ;
			else
			{
				cur = i ;
				ans = (ans * 10 + i) ;
				break ;
			}
		}
	}
	return cout<<ans<<"\n" , 0 ;
}		

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int N, nr, nc, nt;
bool flag = true;
int main(){
	scanf("%d", &N);
	for(int i = 0; i < N; i++){
		int t, r, c;
		scanf("%d %d %d", &t, &r, &c);
		int dist = abs(nr - r) + abs(nc - c);
		t = t - nt;
		if(dist > t || (t - dist) & 1)	flag = false;
		nt += t, nr = r, nc = c;
	}
	if(flag)	puts("Yes");
	else puts("No");
	return 0;
}

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

template <typename InputIterator>
typename InputIterator::value_type summation(InputIterator first,
                                             InputIterator last) {
  return std::accumulate(first, last, typename InputIterator::value_type());
}
template <typename T>
std::istream &operator>>(std::istream &stream, std::vector<T> &v);
template <typename T1, typename T2>
std::istream &operator>>(std::istream &stream, std::pair<T1, T2> &p);
template <typename T>
std::istream &operator>>(std::istream &stream, std::vector<T> &v) {
  for (auto &i : v) {
    stream >> i;
  }
  return stream;
}
template <typename T1, typename T2>
std::istream &operator>>(std::istream &stream, std::pair<T1, T2> &p) {
  stream >> p.first >> p.second;
  return stream;
}

int main() {
  int64_t n;
  std::cin >> n;
  std::vector<std::pair<int64_t, int64_t>> xy(n);
  std::cin >> xy;

  double ans = 1145148101919;

  for (int64_t i = 0; i < n; i++) {
    for (int64_t j = i + 1; j < n; j++) {
      const double x1 = xy[i].first, x2 = xy[j].first;
      const double y1 = xy[i].second, y2 = xy[j].second;
      const auto rad =
          std::sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2)) / 2;
      const double cx = (static_cast<double>(x1) + x2) / 2;
      const double cy = (static_cast<double>(y1) + y2) / 2;

      if (std::all_of(xy.cbegin(), xy.cend(),
                      [&](const std::pair<int64_t, int64_t> v) {
                        return std::sqrt((v.first - cx) * (v.first - cx) +
                                         (v.second - cy) * (v.second - cy)) <=
                               rad + 1e-4;
                      })) {
        ans = std::min(rad, ans);
      }

      for (int64_t k = j + 1; k < n; k++) {
        const auto x1 = xy[i].first, x2 = xy[j].first, x3 = xy[k].first;
        const auto y1 = xy[i].second, y2 = xy[j].second, y3 = xy[k].second;
        const auto a1 = 2 * (x2 - x1), a2 = 2 * (y2 - y1),
                   a3 = x1 * x1 - x2 * x2 + y1 * y1 - y2 * y2;
        const auto b1 = 2 * (x3 - x2), b2 = 2 * (y3 - y2),
                   b3 = x2 * x2 - x3 * x3 + y2 * y2 - y3 * y3;

        const auto div = b1 * a2 - a1 * b2;
        const double up = a1 * b3 - b1 * a3;

        if (div == 0) {
          continue;
        }
        const auto cy = up / div;
        const auto cx = static_cast<double>(a2 * b3 - b2 * a3) / (-div);
        const auto rad =
            std::sqrt((x1 - cx) * (x1 - cx) + (y1 - cy) * (y1 - cy));

        if (std::all_of(xy.cbegin(), xy.cend(),
                        [&](const std::pair<int64_t, int64_t> v) {
                          return std::sqrt((v.first - cx) * (v.first - cx) +
                                           (v.second - cy) * (v.second - cy)) <=
                                 rad + 1e-4;
                        })) {
          ans = std::min(rad, ans);
        }
      }
    }
  }
  std::cout << std::fixed << std::setprecision(20) << ans << std::endl;
  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

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

	int count=0;
	for (int i = 0; i < n; ++i)
	{
		if(l[i] >= total-l[i]){
			count++;
		}
	}

	if(count == 0){
		printf("Yes");
	}else{
		printf("No");
	}
	return 0;
}


Measured memory_bytes: 128
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <deque>
#include <iostream>
#include <queue>
#include <stack>
#include <utility>
#include <vector>
using std::cin;
using std::cout;
using std::endl;

int main(void) {
    int x;
    cin >> x;
    if (x == 1) {
        cout << 1 << endl;
        return 0;
    }
    for (int number = x; number >= 1; number--) {
        for (int b = 2; b <= number; b++) {
            for (int p = 2; std::pow(b, p) <= number; p++) {
                if (std::pow(b, p) == number) {
                    cout << number << endl;
                    return 0;
                }
            }
        }
    }

    return 0;
}


Measured memory_bytes: 384
n = int(input())
h = [i for i in map(int, input().split())]
DP = [0, abs(h[0]-h[1])]

for i in range(n-2):
    DP += [min(abs(h[i+2]-h[i+1])+DP[i+1], abs(h[i+2]-h[i])+DP[i])]

print(DP[-1])

Measured memory_bytes: 13980
#include <iostream>
#include <queue>
#include <vector>

using namespace std;
typedef pair<int, int> pii;

int main() {
  int n;
  cin >> n;
  vector<pii> G[n];
  vector<int> counter(n, 0);
  for (int i = 0; i < n - 1; i++) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    G[a].push_back(pii(b, i));
    G[b].push_back(pii(a, i));
    counter[a]++;
    counter[b]++;
  }
  //cout << "INPUT OK" << endl;
  int k = 0;
  for (int i = 0; i < n; i++) {
    k = max(k, counter[i]);
  }
  //cout << "COLOR NUM OK: " << k << endl;
  vector<int> paths(n - 1, 0);
  vector<bool> visited(n, false);
  queue<pii> q;
  q.push(pii(0, -1));
  visited[0] = true;
  while (!q.empty()) {
    pii v = q.front();
    q.pop();
    int index = v.first;
    int color = v.second;
    for (pii i : G[index]) {
      int nidx = i.first;
      int pathidx = i.second;
      if (visited[nidx])
        continue;
      color++;
      color %= k;
      paths[pathidx] = color;
      q.push(pii(nidx, color));
      visited[nidx] = true;
    }
  }
  cout << k << endl;
  for (int i = 0; i < n - 1; i++) {
    cout << paths[i] + 1 << endl;
  }
  return 0;
}


Measured memory_bytes: 7424
import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner stdIn = new Scanner(System.in);
        int N = stdIn.nextInt();
        stdIn.close();
        
        long sum = 0;
        for (int i = 1; i <= N; i++) {
            if (i % 3== 0 && i % 5 == 0) {

            } else if (i % 3== 0) {

            } else if (i % 5 == 0) {

            } else {
                sum += i;
            }
        }
        System.out.println(sum);
    }
}

Measured memory_bytes: 27196
import sys
import bisect as bi
import math
from collections import defaultdict as dd
import heapq
import itertools
input=sys.stdin.readline
##import numpy as np
#sys.setrecursionlimit(10**7)
mo=10**9+7
def cin():
    return map(int,sin().split())
def ain():            
    return list(map(int,sin().split()))
def sin():
    return input()
def inin():
    return int(input())
##def power(x, y):
##    if(y == 0):return 1
##    temp = power(x, int(y / 2))%mo
##    if (y % 2 == 0):return (temp * temp)%mo 
##    else:
##        if(y > 0):return (x * temp * temp)%mo 
##        else:return ((temp * temp)//x )%mo
##
for _ in range(1):
    r,c,m=cin()
    d=dd(set)
    ro=[0]*r
    co=[0]*c
    for i in range(m):
        x,y=cin()
        ro[x-1]+=1
        co[y-1]+=1
        d[x-1].add(y-1)

    ans=0
    mar=[];mac=[]
    mar1=max(ro);mac1=max(co);
    for i in range(r):
        if(ro[i]==mar1):
            mar+=[i]
    for i in range(c):
        if(co[i]==mac1):
            mac+=[i]
##    print(mar ,mac)
    t=-1
    ans=mar1+mac1
    for i in mar:
        for j in mac:
            if(j not in d[i]):
                t=0
                break
    print(ans+t)
    
    
    
    
    

                    
                
    

    

        


    
        

    
    
    
    
    
    
    
    
        
    
    
    
    
    
    
        
        
    
    
    
    


    





##
        
    
    
    
    
    
    
        
        
    
    
    
    


    





##def msb(n):n|=n>>1;n|=n>>2;n|=n>>4;n|=n>>8;n|=n>>16;n|=n>>32;n|=n>>64;return n-(n>>1) #2 ki power
##def pref(a,n,f):             
##    pre=[0]*n
##    if(f==0):         ##from beginning
##        pre[0]=a[0]
##        for i in range(1,n):
##            pre[i]=a[i]+pre[i-1]
##    else:              ##from end
##        pre[-1]=a[-1]
##        for i in range(n-2,-1,-1):
##            pre[i]=pre[i+1]+a[i]
##    return pre
##maxint=10**24 
##def kadane(a,size): 
##    max_so_far = -maxint - 1
##    max_ending_here = 0
##       
##    for i in range(0, size): 
##        max_ending_here = max_ending_here + a[i] 
##        if (max_so_far < max_ending_here): 
##            max_so_far = max_ending_here 
##  
##        if max_ending_here < 0: 
##            max_ending_here = 0   
##    return max_so_far


Measured memory_bytes: 199220
n,m=map(int,input().split())
par=[-1]*n

# this par & rank are initialized lists
def find(x):
    global par
    if par[x]<0:
        return x
    else:
        par[x]=find(par[x])
        return par[x]
        
def unite(x,y):
    x,y=find(x),find(y)
    global par
    if x==y:return False
    else:
        if par[x]>par[y]:x,y=y,x
        par[x]+=par[y]
        par[y]=x
        return True

def size(x):
    return -par[find(x)]
def same(x,y):
    return find(x)==find(y)


for i in range(m):
  a,b=map(int,input().split())
  unite(a-1,b-1)

par.sort()
print(-par[0])

Measured memory_bytes: 80620
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
#include<bitset>
#include<vector>
#include<deque>
#include<queue>
#include<map>
#include<set>
#include<stack>
#include<cmath>
#include<iomanip>
#include <functional>
using namespace std;
typedef long long ll;
const int mod = 1000000007;
const int INF = 1 << 28;
const double EPS = 1e-10;
//cout << fixed << std::setprecision(9)
//memset(a, 0, sizeof(a));
//--------------------------

int g[100][100];
int n, m;

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

	for (int i = 0;i < m;i++) {
		int a, b;
		cin >> a >> b;
		g[a][b]++;
		g[b][a]++;
	}

	for (int i = 1;i <= n;i++) {
		int count = 0;
		for (int j = 1;j <= n;j++) {
			count += g[i][j];
		}
		cout << count << endl;
	}

	return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
using namespace std;
int dp[50005][3];
#define INF 2000000000
int main(){
	int n;
	while(scanf("%d",&n) && n){
		for(int i=1;i<50005;i++){
			for(int j=0;j<3;j++){
				dp[i][j]=INF;
			}
		}
		for(int i=1;i<=30;i++){
			dp[200*i][0]=380*i-(i/5)*380;
		}
		for(int i=0;i<=50000;i++){
				for(int j=0;j<=i/300;j++){
					dp[i][1]=min(dp[i][1],dp[i-300*j][0]+550*j-(j/4)*330);
				}
		}
		for(int i=0;i<=50000;i++){
				for(int j=0;j<=i/500;j++){
					dp[i][2]=min(dp[i][2],dp[i-500*j][1]+850*j-(j/3)*306);
				}
		}
		printf("%d\n",dp[n][2]);
	}
}

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

using namespace std;

#define rep(i, n) for(int i = 0; i < (int)n; ++i)
#define FOR(i, a, b) for(int i = a; i < (int)b; ++i)
#define rrep(i, n) for(int i = ((int)n - 1); i >= 0; --i)

typedef long long ll;
typedef long double ld;

const ll INF = 1e18;
const int Inf = 1e9;
const double EPS = 1e-9;
const int MOD = 1e9 + 7;

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(0);
    int n;
    cin >> n;
    set<string> st;
    rep (i, n) {
        string s;
        cin >> s;
        st.insert(s);
    }
    cout << st.size() << endl;
    
    return 0;
}



Measured memory_bytes: 19252
#include <cstdio>
#include <vector>
#include <queue>
#include <utility>
#include <string>
#include <algorithm>
using namespace std;

typedef pair<int,int> pii;

int main() try{
	const int INF = 1010101010;

	int n, m;
	scanf("%d%d", &n, &m);
	vector<int> ds(n + 1, INF);
	for(int i = 0; i < n; ++i){ scanf("%d", &ds[i]); }
	vector<vector<pii>> G(n);
	for(int i = 0; i < m; ++i){
		int a, b;
		scanf("%d%d", &a, &b);
		G[a - 1].emplace_back(b - 1, i);
		G[b - 1].emplace_back(a - 1, i);
	}

	string res1(n, '?');
	vector<int> res2(m, 1000000000);
	priority_queue<pii> pq;
	for(int i = 0; i < n; ++i){
		if(res1[i] != '?'){ continue; }
		int minadj = INF;
		pii pe(-1, -1);
		for(const pii &e : G[i]){
			int v = e.first;
			minadj = min(minadj, ds[v]);
			if(ds[v] == ds[i] && res1[v] == '?'){
				pe = e;
			}
		}
		if(minadj > ds[i]){ throw __LINE__; }
		if(pe.first >= 0){
			res1[i] = 'B';
			res1[pe.first] = 'W';
			res2[pe.second] = ds[i];
			for(const auto &e : G[i]){
				int v = e.first;
				pq.emplace(-ds[v], v);
			}
			for(const auto &e : G[pe.first]){
				int v = e.first;
				pq.emplace(-ds[v], v);
			}
		}
	}
	while(!pq.empty()){
		int u = pq.top().second;
		pq.pop();
		if(res1[u] != '?'){ continue; }
		int mindv = n;
		int eidx = -1;
		for(const pii &e : G[u]){
			int v = e.first;
			if(res1[v] != '?' && ds[mindv] > ds[v]){
				mindv = v;
				eidx = e.second;
			}
			pq.emplace(-ds[v], v);
		}
		if(eidx < 0){
			res1[u] = 'B';
		}
		else if(ds[mindv] > ds[u]){
			throw __LINE__;
		}
		else{
			res1[u] = res1[mindv] ^ 'B' ^ 'W';
			res2[eidx] = ds[u];
		}
	}

	if(count(res1.begin(), res1.end(), '?') > 0){ throw __LINE__; }
	puts(res1.c_str());
	for(int x : res2){ printf("%d\n", x); }
}
catch(int ln){
	fprintf(stderr, "catch %d\n", ln);
	puts("-1");
}


Measured memory_bytes: 14444
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
 
#define ll 				long long
#define int             long long int
#define setbits(x)      __builtin_popcountll(x)
#define mod             1000000007
#define modp            998244353
#define inf             (ll)1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define w(x)            int x; cin>>x; while(x--)
#define FIO           	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl 			'\n'
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;


void solve()
{
	string s;
	cin >> s;
	if(s[0] == s[1] && s[1] == s[2] && s[0] == 'R')
		cout << 3 << endl;
	else if(s[0] == s[1] && s[0] == 'R')
		cout << 2 << endl;
	else if(s[1] == s[2] && s[1] == 'R')
		cout << 2 << endl;
	else if(s[0] == s[1] && s[1] == s[2] && s[0] == 'S')
		cout << 0 << endl;
	else
		cout << 1 << endl;
}
 
int32_t main()
{
	FIO
    // w(t)
    {
    	solve();
    }
    return 0;
}
	

	

Measured memory_bytes: 3640
s=sorted
(n,m,*b),a,*q=[map(int,t.split())for t in open(0)]
t=[-1]*n
r=lambda x:r(t[x])if-1<t[x]else x
def u(x):
 x,y=map(r,x)
 if x-y:
  if t[x]>t[y]:x,y=y,x
  t[x]+=t[y];t[y]=x
*map(u,q),
i=c=0
k=j=n+~m<<1
*d,=eval('[],'*n)
for v in a:d[r(i)]+=v,;i+=1
for p in d:
 if p:x,*y=s(p);c+=x;b+=y;j-=1
print((c+sum(s(b)[:j]),'Impossible')[k>n]*(k>0))

Measured memory_bytes: 138640
// #pragma GCC optimize("O3")
#include <bits/stdc++.h>

using namespace std;

using ll = long long;
using vll = vector<ll>;
using vii = vector<int>;
using pii = pair<int, int>;
template <typename T = vii> 
using vec = vector<T>;

const ll INF = numeric_limits<ll>::max(),
         MOD = 1e9 + 7;

const int INF_i = numeric_limits<int>::max(),
          MAX = 1e6;

ll powm(ll a, ll n = MOD - 2) {
    ll res = 1;
    for (; n; a = (a * a) % MOD, n >>= 1)
        if (n & 1)
            res = (res * a) % MOD;
    return res;
}

ll C(ll n, ll k) {
    ll res = 1;
    for (ll i = 1; i <= k; i++) {
        (res *= n + 1 - i) %= MOD;
        (res *= powm(i)) %= MOD;
    }
    return res;
}

int main() {
    cin.tie(NULL);
    ios_base::sync_with_stdio(false);
    // freopen("in.in", "r", stdin);

    ll n, m, k;
    cin >> n >> m >> k;
    ll res = 0;
    const ll a = C(n * m - 2, k - 2);
    for (int d = 0; d < n; d++) {
        ll ans = (m * m) % MOD;
        (ans *= ((n - d) * a) % MOD) %= MOD;
        (res += (ans * d) % MOD) %= MOD;
    }
    for (int d = 0; d < m; d++) {
        ll ans = (n * n) % MOD;
        (ans *= ((m - d) * a) % MOD) %= MOD;
        (res += (ans * d) % MOD) %= MOD;
    }
    cout << res << '\n';

}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
#define boost ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define pii pair<ll,ll>
const int size=1e5+1;
vector<pii> v1[size];
ll level[size];
int n;
void dfs(ll e,ll p,ll wt)
{
    level[e]=wt;
    for(int i=0;i<v1[e].size();i++)
    {
        ll node=v1[e][i].first;
        ll w=v1[e][i].second;
        if(node==p)
        continue;
        dfs(node,e,w+wt);
    }
}
int main()
{
    boost;
    cin>>n;
    ll x,y,c;
    for(int i=0;i<n-1;i++)
    {
        cin>>x>>y>>c;
        v1[x].pb({y,c});
        v1[y].pb({x,c});
    }
    ll q,k;
    cin>>q>>k;
    dfs(k,-1,0);
    while(q--)
    {
        ll st,end;
        cin>>st>>end;
        cout<<level[st]+level[end]<<endl;
    }
}

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

using namespace std;
using ll=long long;
using ull=unsigned long long;
using pii=pair<int,int>;

const int INF = 1 << 29;
#define MOD 1000000007
#define rng(a) a.begin(),a.end()
#define rrng(a) a.end(),a.begin()

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

  int N,M,R;
  cin>>N>>M>>R;
  vector<int>r(R);
  for(int i=0;i<R;i++)cin>>r[i],r[i]--;
  vector<int>A(M),B(M),C(M);
  for(int i=0;i<M;i++)cin>>A[i]>>B[i]>>C[i];


  //e => 辺
  vector<vector<int>>e(N,vector<int>(N,INF));
  for(int i=0;i<N;i++)e[i][i]=0;
  //i->i => 0
  for(int i=0;i<M;i++){
    A[i]--;
    B[i]--;
    e[A[i]][B[i]]=e[B[i]][A[i]]=C[i];
  }

  for(int k=0;k<N;k++){
    for(int i=0;i<N;i++){
      for(int j=0;j<N;j++){
        e[i][j]=min(e[i][j],e[i][k]+e[k][j]);
      }
    }
  }

  int ans=INF;


  sort(rng(r));
  do{
    int res=0;
    for(int i=0;i<R-1;i++){
      res+=e[r[i]][r[i+1]];
    }
    ans=min(ans,res);
  }while(next_permutation(rng(r)));

  cout<<ans<<endl;

  return 0;
}


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

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

	vector<pair<string, int>> spv( N );
	for( int i = 0; i < N; ++i ) {
		cin >> spv.at( i ).first;
		cin >> spv.at( i ).second;
	}

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

	sort( idx.begin(), idx.end(), [&spv]( int a, int b ) {
		if( spv.at( a ).first == spv.at( b ).first ) {
			return spv.at( a ).second > spv.at( b ).second;
		}

		return spv.at( a ).first < spv.at( b ).first;
	} );

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


Measured memory_bytes: 256
#include <cmath>
#include <iostream>
#include <vector>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <bitset>
#include <algorithm>
#include <functional>
#include <utility>
#include <iomanip>
 
#define int long long int
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() )
 
using namespace std;
 
typedef pair<int, int> P;
 
const int INF = 1e15;
const int MOD = 1e9+7;
 
signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
 
    int n, q;
    cin >> n >> q;
    vector<int> a(n);
    rep(i, n) cin >> a[i];
 
    vector<int> s(n + 1);
    rep(i, n) s[i+1] = s[i] + a[i];
    vector<int> ss((n + 1) / 2 + 1);
    int x = (n + 1) % 2;
    rep(i, (n + 1) / 2){
        ss[i+1] = ss[i] + a[x+2*i];
    }
 
    vector<P> query(q);
    rep(i, q){
        int x;
        cin >> x;
        query[i] = {x, i};
    }
    sort(ALL(query));
 
    vector<int> ans(q);
    int y = 1;
    rep(i, q){
        int x = query[i].first;
 
        while(y < n && a[y-1] < x){
            y++;
        }
 
        while(y < n){
            int limit = max(1LL, 2 * x - a[y-1]);
            int lo = -1;
            int hi = n - 1;
            while(hi - lo > 1){
                int mid = (lo + hi) / 2;
                if(a[mid] >= limit){
                    hi = mid;
                }else{
                    lo = mid;
                }
            }
            int upper = n - y + 1;
            int lower = y - hi;
            if(upper > lower){
                y++;
            }else{
                break;
            }
        }
        int result = s[n] - s[y-1];
        int remain = n - (n - y + 1) * 2;
        if(remain > 0){
            result += ss[(remain+1)/2];
        }
        ans[query[i].second] = result;
    }
 
    rep(i, q){
        cout << ans[i] << endl;
    }
 
    return 0;
}

Measured memory_bytes: 7680
#include<bits/stdc++.h>
using namespace std;
#define FastRead ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ll long long int
#define endl '\n'
#define ld long double
#define FOR(i,a,n) for (ll i=(a);i<=(n);++i)
#define RFOR(i,a,n) for (ll i=(n);i>=(a);--i)
#define FI(i,n) for (ll i=0; i<(n); ++i)
#define ZERO(a) memset((a),0,sizeof((a)))
#define MINUS(a) memset((a),-1,sizeof((a)))
#define f first
#define s second
#define pb push_back
#define mk make_pair
#define all(g) g.begin(),g.end()
int fastMax(int x, int y) { return (((y-x)>>(32-1))&(x^y))^y; }
int fastMin(int x, int y) { return (((y-x)>>(32-1))&(x^y))^x; }
 
/*
░░░░░░░░░░░░░░░░░░░░░░░░░
░░█▀▀▄░░░░░░░░░░░▄▀▀█░░░░
░░█░░░▀▄░▄▄▄▄▄░▄▀░░░█░░░░
░░░▀▄░░░▀░░░░░▀░░░▄▀░░░░░
░░░░░▌░▄▄░░░▄▄░▐▀▀░░░░░░░
░░░░▐░░█▄░░░▄█░░▌▄▄▀▀▀▀█░
░░░░▌▄▄▀▀░▄░▀▀▄▄▐░░░░░░█░
░▄▀▀▐▀▀░▄▄▄▄▄░▀▀▌▄▄▄░░░█░
░█░░░▀▄░█░░░█░▄▀░░░░█▀▀▀░
░░▀▄░░▀░░▀▀▀░░▀░░░▄█▀░░░░
░░░░█░░░░░░░░░░░▄▀▄░▀▄░░░
░░░░█░░░░░░░░░▄▀█░░█░░█░░
░░░░█░░░░░░░░░░░█▄█░░▄▀░░
░░░░█░░░░░░░░░░░████▀░░░░
░░░░▀▄▄▀▀▄▄▀▀▄▄▄█▀░░░░░░░
░░░░░░░░░░░░░░░░░░░░░░░░░
*/
 
// I want to be the very best, like no one ever was, I will battle everyday to claim my rightful place
// #include <ext/pb_ds/assoc_container.hpp> // Common file
// #include <ext/pb_ds/tree_policy.hpp>     // Including tree_order_statistics_node_updat
// using namespace __gnu_pbds;
// typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
 
// I am questioning life and universe and 
// everything else after looking at this

void solve(){
    ll n; cin>>n;
    n--;
    ll ans = n*(n+1)/2;

    cout<<ans<<endl; 
} 
 
signed main(){
 
   FastRead;    
 
 
    ll t;
    t = 1; 
    // cin>>t;
    FOR(i,1,t){
        // cout<<"Case #"<<i<<": ";
        solve();
    }
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<set>
#include<map>
using namespace std;
#define MAX 100100
inline int read()
{
	int x=0;bool t=false;char ch=getchar();
	while((ch<'0'||ch>'9')&&ch!='-')ch=getchar();
	if(ch=='-')t=true,ch=getchar();
	while(ch<='9'&&ch>='0')x=x*10+ch-48,ch=getchar();
	return t?-x:x;
}
map<int,int> M;
multiset<int> S;
int f[MAX],tot;
int getf(int x){return x==f[x]?x:f[x]=getf(f[x]);}
int ID(int x){return M[x]?M[x]:M[x]=++tot;}
int n,a[MAX],b[MAX],ans=0;
int main()
{
	n=read();
	for(int i=1;i<=n;++i)a[i]=read(),S.insert(a[i]),a[n+1]^=a[i];
	for(int i=1;i<=n;++i)b[i]=read(),b[n+1]^=b[i];
	S.insert(a[n+1]);
	for(int i=1;i<=n;++i)
		if(S.find(b[i])==S.end()){puts("-1");return 0;}
		else S.erase(S.find(b[i]));
	for(int i=1;i<=n+1;++i)f[i]=i;
	for(int i=1;i<=n;++i)
		if(a[i]!=b[i])
		{
			int u=ID(a[i]),v=ID(b[i]);
			f[getf(u)]=getf(v);++ans;
		}
	if(!ans){puts("0");return 0;}
	for(int i=1;i<=tot;++i)if(getf(i)==i)++ans;
	bool fl=true;
	for(int i=1;i<=n;++i)if(b[i]==a[n+1])fl=false;
	ans+=fl;ans-=1;
	printf("%d\n",ans);
	return 0;
}


Measured memory_bytes: 7936
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<cmath>
#include<cstdio>
#include<queue>
#include<deque>
#include<map>
#include<stack>
using namespace std;
typedef pair<int,int> ii;
typedef long long ll;
typedef pair<ll,ll> pll;
const int INF=1e9;
const ll MOD=1e9+7;
int dy[]={1,0,-1,0};
int dx[]={0,1,0,-1};

int gcd(int x,int y){
    if(y==0) return x;
    return gcd(y,x%y);
}

int dis2(int x1,int y1,int x2,int y2){
    return (x1-x2)*(x1-x2)+(y1-y2)*(y1-y2);
}

int main(){
    int h,w;cin>>h>>w;
    vector<string> a(h);
    for(int i=0;i<h;i++) cin>>a[i];
    vector<vector<int> > d(h,vector<int>(w,INF));
    queue<ii> que;
    int ans=0;
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            if(a[i][j]=='#'){
                que.push(make_pair(i,j));
                d[i][j]=0;
            }
        }
    }
    while(!que.empty()){
        ii p=que.front();que.pop();
        int y=p.first,x=p.second;
        for(int i=0;i<4;i++){
            int ny=y+dy[i],nx=x+dx[i];
            if(ny>=0&&ny<h&&nx>=0&&nx<w&&a[ny][nx]=='.'&&d[ny][nx]==INF){
                d[ny][nx]=d[y][x]+1;
                que.push(make_pair(ny,nx));
                ans=max(ans,d[ny][nx]);
            }
        }
    }
    cout<<ans<<endl;
    return 0;
}

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

int main() {
    ll n,i,l,m=1e13; cin>>n;
    for(i=1;i<=sqrt(n);i++)
    {
        if (n%i==0)
        { 
            l=(n/i)-1+(i-1);
            m=min(m,l);
        }
    }
    cout<<m;
	return 0;
}

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

using namespace std;

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

int N, M;
vector< int > g[100000];
bool v[100000];
vector< int > latte, malta;

void dfs(int idx)
{
  v[idx] = true;
  latte.push_back(idx);
  for(auto &to : g[idx]) {
    if(!v[to]) return (dfs(to));
  }
}


int main()
{
  cin >> N >> M;
  rep(i, M) {
    int a, b;
    cin >> a >> b;
    --a, --b;
    g[a].push_back(b);
    g[b].push_back(a);
  }

  dfs(0);
  swap(latte, malta);
  dfs(0);
  reverse(latte.begin(), latte.end());
  latte.pop_back();

  cout << latte.size() + malta.size() << endl;
  for(auto &x : latte) cout << x + 1 << " ";
  for(auto &x : malta) cout << x + 1 << " ";
  cout << endl;
}



Measured memory_bytes: 9720
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(ll i=0;i<n;i++)
int main(void){
    ll n;cin>>n;
    if(n%11>0&&n%11<=6)cout<<n/11*2+1<<endl;
    else cout<<(n+10)/11*2;
}

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

#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 ALL(container) (container).begin(), (container).end()

using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int, int> pi;
typedef pair<ll, ll> pll;

const int INF = 1e9;

int main() {
  char b, ans;

  cin >> b;
  if (b == 'A') {
    ans = 'T';
  } else if (b == 'C') {
    ans = 'G';
  } else if (b == 'G') {
    ans = 'C';
  } else {
    ans = 'A';
  }

  cout << ans << endl;

  return 0;
}


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

#define repi(i, s, n) for (intmax_t i {s}, i##_len{n}; i < i##_len; ++i)
#define rep(i, n) repi(i, 0, n)
#define all(x) std::begin(x), std::end(x)

namespace xmaho
{
inline namespace input
{
template<typename T>
T get_value(std::istream& is = std::cin);
template<typename C>
C get_container(std::istream& is = std::cin, typename C::size_type length = std::numeric_limits<typename C::size_type>::max());
}
}
namespace xmaho
{
inline namespace integer
{
template<typename C>
constexpr auto ssize(const C& c) noexcept(noexcept(c.size()))
  -> typename std::common_type<std::ptrdiff_t, typename std::make_signed<decltype(c.size())>::type>::type;
template <class T, ptrdiff_t N>
constexpr std::ptrdiff_t ssize(const T (&)[N]) noexcept;
}
}
using namespace xmaho;

int main()
{
  const auto n {get_value<intmax_t>()};
  const auto a_init {get_value<intmax_t>()};
  const auto b_init {get_value<intmax_t>()};

  intmax_t res {0};
  if ((a_init + b_init) % 2) {
    const auto wall_dis {min({a_init - 1, b_init - 1, n - a_init, n - b_init})};
    res = wall_dis + 1;
    cout << res + ((static_cast<intmax_t>(abs(a_init - b_init))) / 2) << '\n';
    return 0;
  }

  cout << static_cast<intmax_t>(abs(a_init - b_init) / 2) << '\n';
  return 0;
}

class initalization
{
  class custom_numpunct: public std::numpunct<char>
  {
  public:
    using numpunct::numpunct;
  protected:
    std::string do_truename() const override { return "Yes"; }
    std::string do_falsename() const override { return "No"; }
  };

public:
  initalization()
  {
    std::ios_base::sync_with_stdio(false);
    std::cin.tie(nullptr);
    std::cout.imbue(std::locale(std::cout.getloc(), new custom_numpunct{}));
    std::cout << std::boolalpha << std::fixed << std::setprecision(15);
  }
} initalize;

template<typename T>
T xmaho::input::get_value(std::istream& is)
{ T v {}; is >> v; return v; }

template<typename C>
C xmaho::input::get_container(std::istream& is, typename C::size_type length)
{
  C v {};
  if (length != std::numeric_limits<typename C::size_type>::max())
    v.reserve(length);
  typename C::value_type e {};
  for (auto i {length}; i != 0 && is >> e; --i)
    v.push_back(std::move_if_noexcept(e));
  return v;
}

template<typename C>
constexpr auto xmaho::integer::ssize(const C& c) noexcept(noexcept(c.size()))
  -> typename std::common_type<std::ptrdiff_t, typename std::make_signed<decltype(c.size())>::type>::type
{ return c.size(); }

template <class T, ptrdiff_t N>
constexpr std::ptrdiff_t xmaho::integer::ssize(const T (&)[N]) noexcept
{ return N; }


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<map>
using namespace std;
int n,m,ans;
string s[10101];
map<string,int> cnt;
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	{
		cin>>s[i];
		cnt[s[i]]++;
	}
	scanf("%d",&m);
	for(int i=n+1;i<=n+m;i++)
	{
		cin>>s[i];
		cnt[s[i]]--;
	}
	for(int i=1;i<=n+m;i++)
	ans=max(ans,cnt[s[i]]);
	printf("%d",ans);
	return 0;
}

Measured memory_bytes: 384
n = int(input())
ls = list(map(int,input().split()))
cnt = 1
i = 0
flag = 10
while i < n-1:
    if ls[i] < ls[i+1] and flag == 10:
        flag = True
    elif ls[i] > ls[i+1] and flag == 10:
        flag = False
    if flag == True:
        if ls[i] > ls[i+1]:
            cnt += 1
            flag = 10
    elif flag == False:
        if ls[i] < ls[i+1]:
            cnt += 1
            flag = 10
    i += 1
print(cnt)

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

typedef long long ll;

int main(){
    int n; cin >> n;
    ll m = 1e9+7;
    ll ans = 1;
    
    int a[1001] = {0};
    for(int i = 2; i <= n; i++)
    {
        int s = i, t = 2;
        while(s != 1){
            while(s % t == 0){
                a[t]++;
                s/=t;
            }
            t++;
        }
    }
    
    for(int i = 0; i < (int)1001; i++)
    {
        ans = ans*(a[i]+1)%m;
    }
    cout << ans << endl;
        
    return 0;
}

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

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;

#define MOD 1000000007
#define REP(i, N) for (int i = 0; i < N; ++i)
#define REP1(i, N) for (int i = 1; i <= N; ++i)
#define RREP(i, N) for (int i = N - 1; i >= 0; --i)
#define ALL(a) a.begin(), a.end()

int main() {
  int n, x;
  cin >> n >> x;
  if (x == 1 || x == 2 * n - 1) {
    cout << "No" << endl;
    return 0;
  }
  cout << "Yes" << endl;
  if (n == 2) {
    REP1(i, 3) cout << i << endl;
    return 0;
  }
  queue<int> que;
  if (x == 2) {
    REP1(i, 2 * n - 1) {
      if (x - 1 <= i && i <= x + 2) continue;
      que.push(i);
    }
    REP(i, n - 2) {
      cout << que.front() << endl;
      que.pop();
    }
    cout << x + 1 << endl;
    cout << x << endl;
    cout << x - 1 << endl;
    cout << x + 2 << endl;
    while (que.size()) {
      cout << que.front() << endl;
      que.pop();
    }
  } else {
    REP1(i, 2 * n - 1) {
      if (x - 2 <= i && i <= x + 1) continue;
      que.push(i);
    }
    REP(i, n - 2) {
      cout << que.front() << endl;
      que.pop();
    }
    cout << x - 1 << endl;
    cout << x << endl;
    cout << x + 1 << endl;
    cout << x - 2 << endl;
    while (que.size()) {
      cout << que.front() << endl;
      que.pop();
    }
  }
  return 0;
}

Measured memory_bytes: 2304
#include <bits/stdc++.h>
#define itn int
#define rep(i, n) for (int i = 0; i < n; i++)

using namespace std;
typedef long long ll;


int main(){
    int n;
    int a=0;
    int b=0;
    int ab=0;
    int ans=0;
    cin >> n;
    rep(i,n){
        string st;
        cin >> st;
        if(st[0]=='B'){
            if(st.back()=='A'){
                ab++;
            }
            else{
                b++;
            }
        }
        else if(st.back()=='A'){
            a++;
        }
        bool aru = false;
        for(int j = 0; j < st.size(); j++){
            if(aru==true){
                if(st[j]=='B'){
                    ans++;
                }
                aru=false;
            }
            if(st[j]=='A'){
                aru=true;
            }
            else{
                aru=false;
            }
        }
    }
    if(ab!=0){
        if(a==0&&b==0){
            ab--;
        }
    }
    ans+=min(a,b);
    ans+=ab;
    cout << ans << endl;
}


Measured memory_bytes: 256