akhauriyash/Code-Regression huggingface dataset:
//Tonight's the night and it is going to happen again and again.
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mp make_pair
#define pb push_back
#define T ll t; cin>>t; while(t--)
#define mod 1000000007
#define mem(name,val) memset(name,val,sizeof(name))
#define f(n) for(ll i = 0;i<n;i++)
#define endl "\n"
ll gcd(ll a,ll b){if(b==0){return a;}return gcd(b,a%b);}
int main()
{
   ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
   #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
   #endif
   string s;cin>>s;
   if(s[0]=='R'&&s[1]=='R'&&s[2]=='R'){cout<<3;return 0;}
   if(s[0]=='R'&&s[1]=='R'){cout<<2;return 0;}
   if(s[2]=='R'&&s[1]=='R'){cout<<2;return 0;}
   if(s[0]=='R'){cout<<1;return 0;}
   if(s[1]=='R'){cout<<1;return 0;}
   if(s[2]=='R'){cout<<1;return 0;}
   else{cout<<0;} 
}

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

using int64 = long long;

vector<int64> divisor(int64 n) {
    vector<int64> res;
    for (int64 i = 1; i * i <= n; ++i) {
        if (n % i == 0) {
            res.emplace_back(i);
            if (i * i != n) res.emplace_back(n / i);
        }
    }
    sort(res.begin(), res.end());
    return res;
}

int main(){
    int N, K; cin >> N >> K;
    vector<int> A(N);
    for (int i = 0; i < N; ++i) cin >> A[i];

    int64 sum = 0;
    for (int i = 0; i < N; ++i) sum += A[i];

    vector<int64> div = divisor(sum);
    sort(div.rbegin(), div.rend());

    for (auto& d: div) {
        vector<int64> m(N);
        int64 sum = 0;
        for(int i = 0; i < N; ++i) {
            m[i] = A[i] % d;
            sum += m[i];
        }
        sort(m.rbegin(), m.rend());
        int64 t = sum;
        for (int i = 0; i < t / d; ++i) sum -= m[i];

        if (sum <= K) {
            cout << d << endl;
            return 0;
        }



    }
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cmath>
#include <queue>
#include <utility>
#include <map>
#include <climits>
#include <vector>
#include <set>
#include <string>
#include <numeric>

#define FAST_IO ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr)
#define int long long
using namespace std;
typedef vector<int> vi;
typedef pair<int, int> ii;
typedef vector<pair<int, int>> vii;
const int N = 1e5 + 2;
const int INF = 1e9 + 5;
const int MOD = 1e9 + 7;

int32_t main() {
    FAST_IO;
    int x;
    cin >> x;
    int si = 0, p = 100;
    int amount = p;
    int ans = 0;
    while (amount < x) {
        si = amount/100;
        amount += si;
        ans++;
    }
    cout << ans;
    return 0;
}

Measured memory_bytes: 3652
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define MOD 1000000007
int modexp(int x, int y)
{
	int mod = MOD,res = 1;
    x = (x % mod + mod) % mod;
    while(y)
    {
        if(y & 1)res = (res*x) % mod;
        y >>= 1;
        x = ((x%mod)*(x%mod)) % mod;
    }
    return res; 
}
int modInverse(int x)
{
	return modexp(x,MOD-2)%MOD;
}

int choose(int n,int r)
{
  const int mod = MOD;
  int a = 1, b = 1;
  
 for(int i = 0; i < r; i++)
 { //calculate factorial
   a = ((a%mod)*((n-i)%mod))%mod;  //calculate X
   b = ((b%mod)*((1+i)%mod))%mod;	//calculate Y
 }
  
  int ans = ((a%mod)*((modInverse(b)%mod)%mod))%mod;
  
  return ans%mod;
}
  
int32_t main()
{
  
  int n,a,b;
  cin >> n >> a >> b ;
  //total ways of making the bouquet become 2^n -1
  int ans = (modexp(2,n)%MOD - 1)%MOD;
  //subtrct ways of nCa + nCb
  //factorial or X/Y under mod, can be found by modular inverse arithmetic
  //This is an application of fermat's little theorem
  //X/Y%mod == X%mod * Y^(mod-2)%mod)%mod, where mod must be a prime number
  int ans1 = (choose(n,a)%MOD + choose(n,b)%MOD)%MOD;
  ans = (ans%MOD- ans1%MOD)%MOD;
  
  cout << (ans + MOD)%MOD;
  
  
  
}


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

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

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

    ll n, m;
    cin >> n >> m;

    vector<pll> v(n);
    for(int i = 0; i < n; i++){
        cin >> v[i].first >> v[i].second;
    }
    sort(v.begin(), v.end());

    ll ans = 0;
    ll p = 0;
    while(m > 0){
        ll t = min(m, v[p].second);
        m -= t;
        ans += v[p].first * t;
        p++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 1792
#include<iostream>
#include<cstdio>
#include<vector>
#include<algorithm>
typedef std::pair<int,int> P;
typedef long long ll;
const ll mod=1e9+7;
std::vector<P> row,col;
const int N=1005;
bool vc[N],vr[N];
int n,m;
int main() {
    scanf("%d%d",&n,&m);
    for(int i=0,x;i<n;i++) {
        scanf("%d",&x);
        row.push_back(P(x,i+1));
    }
    for(int i=0,x;i<m;i++) {
        scanf("%d",&x);
        col.push_back(P(x,i+1));
    }
    std::sort(row.begin(),row.end(),std::greater<P>());
    std::sort(col.begin(),col.end(),std::greater<P>());
    int pl=0,pr=0;int nr=0,nc=0;
    ll ans=1;
    for(int i=n*m;i;i--) {
        if(pl<row.size()&&row[pl].first>i) {ans=0;break;}
        if(pr<col.size()&&col[pr].first>i) {ans=0;break;}
        int L=0,R=0;
        if(pl<row.size()&&row[pl].first==i) L=row[pl++].second;
        if(pr<col.size()&&col[pr].first==i) R=col[pr++].second;
        if(L&&vr[L]||R&&vc[R]) {
            ans=0;break;
        }
        if(!L&&!R) {
            int tmp=nr*nc-(n*m-i);
            if(tmp<=0) {
                ans=0;break;
            }ans=ans*tmp%mod;
        }
        else if(!L) {
            nc++;ans=ans*nr%mod;
            vc[R]=1;
        }
        else if(!R) {
            nr++;ans=ans*nc%mod;
            vr[L]=1;
        }
        else {
            nr++;nc++;
            vr[L]=vc[R]=1;
        }
    }
    printf("%lld\n",ans);
    return 0;
}


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

using namespace std;

int main(void){
  int A,B,C,K;
  int total = 0;
  int cnt = 0;

  cin >> A >> B >> C >> K;

  for(int i = 0;i < A;i++){
    total++;
    cnt++;
    if(cnt >= K){
      cout << total << endl;
      return 0;
    }
  }

  if(cnt >= K){
    cout << total << endl;
    return 0;
  }

  for(int j = 0;j < B;j++){
    cnt++;
    if(cnt >= K){
      cout << total << endl;
      return 0;
    }
  }

  if(cnt >= K){
    cout << total << endl;
    return 0;
  }

  for(int k = 0;k < C;k++){
    total--;
    cnt++;
    if(cnt >= K){
      cout << total << endl;
      return 0;
    }
  }

  if(cnt >= K){
    total--;
    cout << total << endl;
    return 0;
  }

  return 0;
}

Measured memory_bytes: 3560
Imports System

Public Class Program

    Public Shared Sub Main(args As String())

        Dim N As Integer = Integer.Parse(Console.ReadLine)
        Dim a() As Integer = Array.ConvertAll(Of String, Integer)(Console.ReadLine.Split(" "), AddressOf Integer.Parse)


        Dim nextnumber As Integer = 1

        Dim breaknumber As Integer = 0

        Dim OK As Boolean = False


        For i As Integer = 0 To a.Length - 1

            If a(i) = 1 Then
                OK = True
            End If

            If a(i) = nextnumber Then
                nextnumber += 1
            Else
                breaknumber += 1

            End If

        Next


        If OK Then
            Console.WriteLine(breaknumber)
        Else
            Console.WriteLine(-1)
        End If





    End Sub




End Class


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

int main(void){
    vector<string> ans;
    string s;
    int k;
    cin >> s >> k;
    int si = s.size();
    for(int i=0;i<si;++i){
        for(int j=1;j<=min(si-i,6);++j){
            string sub = s.substr(i, j);
            ans.push_back(sub);
        }
    }
    sort(ans.begin(), ans.end());
    ans.erase(std::unique(ans.begin(), ans.end()), ans.end());
    cout << ans[k-1] << endl;
}

Measured memory_bytes: 1916
n,t = map(int,input().split())
ab = [[0,0] for _ in range(n)]
for i in range(n):
    ab[i] = list(map(int,input().split()))
dp = [[0]*t for i in range(n+1)]
ab.sort()
ans = 0
for i in range(n):
    a,b = ab[i]
    for j in range(t)[::-1]:
        v = dp[i][j]
        ans = max(ans,v+b)
        dp[i+1][j] = max(dp[i+1][j], dp[i][j])
        if j + a >= t:continue
        dp[i+1][j+a] = max(dp[i][j+a], v+b)
print(ans)


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


int main() {
	int n, m;
	cin >> n >> m;
	for (int i = 0;i < m;i++) {
		int x;
		cin >> x;
		n = n - x;
		if (n < 0) {
			cout << -1;
			return 0;
		}
		
	}
	cout << n;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rrep(i, n) for(int i = n-1; i >= 0; i--)
#define  all(x) (x).begin(),(x).end()     // 昇順ソート
#define  rall(v) (v).rbegin(), (v).rend() // 降順ソート
#define  FastIO ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
typedef long long ll;
using P = pair<int,int>;
using VI = vector<int>;
using VVI = vector<vector<int>>;
using VL = vector<ll>;
using VVL = vector<vector<ll>>;
using VP = vector<P>;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return true; } return false; }

int n, ans;
VI abc, l;

const int INF = 1<<20;

int f(int x, VI useL){
    int cost = INF;
    int sz = useL.size();
    for(int i = 1; i < (1<<sz); i++){
        VI used;
        rep(j, sz) if (i>>j & 1) used.push_back(j);
        int len = 0;
        int merge = 0;
        rep(j, used.size()){
            if (j != 0) merge += 10;
            len += useL[used[j]];
            cost = min(cost, abs(len - x) + merge);
        }
    }
    return cost;
}

void dfs(VI nums){
    if ((int)nums.size() == n){
        int sum = 0;
        for(int j = 0; j < 3; j++){
            int x = abc[j];
            VI useL;
            for(int k = 0; k < n; k++){
                if (nums[k] == j) useL.push_back(l[k]);
            }
            sum += f(x, useL);
        }
        ans = min(ans, sum);
    }else{
        for(int j = 0; j < 3; j++){
            nums.push_back(j);
            dfs(nums);
            nums.pop_back();
        }
    }
}

int main(){
    cin >> n;
    abc.resize(3);
    l.resize(n);
    rep(i,3) cin >> abc[i];
    rep(i,n) cin >> l[i];
    ans = INF;
    dfs(VI(0));
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3624
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <fstream>
#include <sstream>
#include <set>
#include <map>
#include <vector>
#include <list>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <string>
#include <stack>
#include <queue>
#include <bitset>     //UWAGA - w czasie kompilacji musi byc znany rozmiar wektora - nie mozna go zmienic
#include <cassert>
#include <iomanip>        //do setprecision
#include <ctime>
#include <complex>
using namespace std;

#define FOR(i,b,e) for(int i=(b);i<(e);++i)
#define FORQ(i,b,e) for(int i=(b);i<=(e);++i)
#define FORD(i,b,e) for(int i=(b)-1;i>=(e);--i)
#define REP(x, n) for(int x = 0; x < (n); ++x)

#define ST first
#define ND second
#define PB push_back
#define PF push_front
#define MP make_pair
#define LL long long
#define ULL unsigned LL
#define LD long double
#define pii pair<int,int>
#define pll pair<LL,LL>
#define vi vector<int>
#define vl vector<LL>
#define vii vector<vi>
#define vll vector<vl>

const double pi = 3.14159265358979323846264;
const int mod=1000000007;

int d(LL a){
    int c=1;
    while(a>=10){
        a/=10;
        c++;
    }
    return c;
}

int main(){
	LL n,ans=0;
    cin>>n;
    int dn=d(n);
    vii c(11,vi(11,0));
    FOR(i,1,n+1){
        if(i<10){
            c[i][i]++;
            continue;
        }
        string s=to_string(i);
        int ln=s.length();
        c[s[0]-'0'][s[ln-1]-'0']++;
    }
    FOR(i,1,10){
        FOR(j,1,10){
            ans+=c[i][j]*c[j][i];
        }
    }
    cout<<ans<<endl;
    

}


Measured memory_bytes: 256
#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 double EPS = 1e-10;
const int INF = 2147483647;
//cout << fixed << std::setprecision(9)
//memset(a, 0, sizeof(a));
//--------------------------

int main()
{
	map<int, int> D;
	map<int, int> T;
	int n, m;

	cin >> n;
	for (int i = 0;i < n;i++) {
		int temp;
		cin >> temp;
		if (D.find(temp) == D.end()) {
			D.insert(make_pair(temp, 1));
		}
		else {
			(D.find(temp)->second)++;
		}
	}

	cin >> m;
	for (int i = 0;i < m;i++) {
		int temp;
		cin >> temp;
		if (T.find(temp) == T.end()) {
			T.insert(make_pair(temp, 1));
		}
		else {
			(T.find(temp)->second)++;
		}
	}

	map<int, int>::iterator itr;
	for (itr = T.begin();itr != T.end();itr++) {
		int current = itr->first;
		if (D.find(current) == D.end() || itr->second > D.find(current)->second) {
			cout << "NO" << endl;
			return 0;
		}
	}

	cout << "YES" << endl;

	return 0;
}


Measured memory_bytes: 18944
#include<stdio.h>
#include<string.h>

int main(void){
    char s[200001], t[200001], c1, c2;
    int flag = 0;
    scanf("%s\n%s", s, t);
    int length = strlen(s);
    
    for(int i = 0; i < length; i++){
        if(t[i] != s[i]){
            c1 = s[i];
            c2 = t[i];
            for(int j = 0; j < length; j++){
                if(s[j] == c1){
                    if(j < i){
                        flag = 1;
                        break;
                    }
                    s[j] = c2;
                    continue;
                }
                if(s[j] == c2){
                    if(j < i){
                        flag = 1;
                        break;
                    }
                    s[j] = c1;
                }
            }
        }
        if(flag){
            break;
        }
    }

    if(strcmp(s, t) == 0){
        printf("Yes\n");
    }
    else{
        printf("No\n");
    }
    return 0;
}

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

typedef long long int ll;
typedef pair<ll, ll> p_ll;
typedef vector<pair<ll, ll>> vec_p; //vector<pair<ll, ll>> pairs(n) ,pairs.at(i) = make_pair(i*i, i)

#define ture ture
#define flase false
#define falg flag

#define REP(i, x) for (ll i = 0; i < (ll)(x); i++)
#define REPS(i, x) for (ll i = 1; i <= (ll)(x); i++)
#define RREP(i, x) for (ll i = ((ll)(x)-1); i >= 0; i--)
#define RREPS(i, x) for (ll i = ((ll)(x)); i > 0; i--)
#define all(x) (x).begin(), (x).end()

const ll MOD = pow(10, 9) + 7;
const ll LLINF = pow(2, 61) - 1;//llの最大9*10^18
const int INF = pow(2, 30) - 1;

ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }

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

    ll N,K;

    cin >> N >> K;

    vector<ll> d(K);
    vector<vector<int>> A(K, vector<int>(N));

    REP(i,K){
        cin >> d.at(i);
        REP(j,d.at(i)){
            cin >> A.at(i).at(j);
        }
    }
    
    vector<ll> vec;
    vec.push_back(0);

    REP(i, K){
        REP(j,d.at(i)){
            vec.push_back(A.at(i).at(j));
        }
    }

    sort(vec.begin(), vec.end());
    //cout << vec.size() << endl;

    ll tmp = 0;

    REP(i,vec.size()-1){
        if(!(vec.at(i)==vec.at(i+1))){
            tmp++;
        }
        //cout << tmp<<endl;
    }
    cout << N - tmp << endl;
}


Measured memory_bytes: 3824
from collections import defaultdict
from collections import deque
from sys import stdin


def sp(G,R,V):
    d = {}
    INF = float('inf')
    for i in range(V):
        d[i] = INF
    d[R] = 0
    q = deque([(R)])
    while q:
        u = q.popleft()
        for v in G[u]:
            if d[v[0]] > d[u] + v[1]:
                d[v[0]] = d[u] + v[1]
                q.append(v[0])
    return d


V, E, R = [int(x) for x in stdin.readline().split(' ')]
G = defaultdict(list)
for case in range(E):
    s, t, w = [int(x) for x in stdin.readline().split(' ')]
    G[s].append((t,w))
d = sp(G, R, V)
for k in range(V):
        if d[k] == float('inf'):
            print("INF")
        else:
            print(d[k])

Measured memory_bytes: 106864
import java.io.IOException;
import java.util.NoSuchElementException;

import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;

public class Main {
    public static void main(String[] args) throws IOException {
        try (
            BufferedReader reader = new BufferedReader(
                new InputStreamReader(System.in))) {
            FastScanner fs = new FastScanner();

            final int N = fs.nextInt();

            int sm = 0;

            for (int i = 0; i < N; i++) {
                int l = fs.nextInt();
                int r = fs.nextInt();
                sm += r - l + 1;
            }

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

class FastScanner {
    private final InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;
    private boolean hasNextByte() {
        if (ptr < buflen) {
            return true;
        } else {
            ptr = 0;
            try {
                buflen = in.read(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (buflen <= 0) {
                return false;
            }
        }
        return true;
    }
    private int readByte() {
        if (hasNextByte()) return buffer[ptr++];
        else return -1;
    }
    private static boolean isPrintableChar(int c) {
        return 33 <= c && c <= 126;
    }
    public boolean hasNext() {
        while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++;
        return hasNextByte();
    }
    public String next() {
        if (!hasNext()) throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while(isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }
    public long nextLong() {
        if (!hasNext()) throw new NoSuchElementException();
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while(true) {
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            } else if(b == -1 || !isPrintableChar(b)) {
                return minus ? -n : n;
            } else {
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }
    public int nextInt() {
        long nl = nextLong();
        if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE)
            throw new NumberFormatException();
        return (int) nl;
    }
    public double nextDouble() {
        return Double.parseDouble(next());
    }
}


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

typedef long long ll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<long long> vll;
typedef vector<vector<long long>> vvll;
typedef pair<int,int> pii;
typedef pair<long long, int> pli;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define sz(x) (x).size()

ll mod = 1000000007;

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

ll inv(ll x){
  ll res = 1;
  ll k = mod - 2;
  ll y = x;
  while(k){
    if(k&1)res = (res*y)%mod;
    y = (y*y) % mod;
    k /= 2;
  }
  return res;
}


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

  int n;
  cin >> n;
  string x;
  cin >> x;

  int p = 0;
  rep(i,n){
    if (x[i] == '1')p++;
  }

  if(p == 0){
    rep(i, n){
      cout << 1 << endl;
    }
  }else if(p == 1){
    rep(i,n){
      if(x[i] == '1') cout << 0 << endl;
      else if(i != n-1)cout << 1 << endl;
      else cout << 2 << endl;
    }
  }else{
    vi ma(n),mb(n);
    int a = 0,b = 0;
    int pa = 1,pb = 1;
    for(int i = n-1;i >= 0;i--){
      ma[i] = pa;
      mb[i] = pb;
      if(x[i] == '1'){
        a = (a+pa) % (p-1);
        b = (b+pb) % (p+1);
      }
      pa = pa*2 % (p-1);
      pb = pb*2 % (p+1);
    }
    rep(i,n){
      int y = 0;
      int ret = 1;
      if(x[i] == '1'){
        y = a - ma[i];
        if(y < 0)y += (p-1);
        y %= p-1;
      }else{
        y = b + mb[i];
        y %= p+1;
      }
      while(y){
        int tmp = y;
        int cnt = 0;
        while(tmp){
          if(tmp % 2 == 1){
            cnt += 1;
          }
          tmp /= 2;
        }
        y %= cnt;
        ret ++;
      }
      cout << ret << endl;
    }
  }
}

Measured memory_bytes: 5176
using System;
using System.Collections;
using System.Linq;


public class Test
{
	public static void Main()
	{
		string[] str = Console.ReadLine().Split(' ');
		int maisu = int.Parse(str[0]);
		int mokuhyou = int.Parse(str[1]);
		bool ok = false;
		for(int x10000 = 0 ; x10000 <= maisu ; x10000++)
		{
			for(int x5000 = 0 ; x5000 <= maisu - x10000 ; x5000++)
			{
				if(10000 * x10000 + 5000 * x5000 + 1000 * (maisu - x10000 - x5000) == mokuhyou)
				{
				    if(ok == false){
					    Console.WriteLine(x10000 +" "+ x5000 +" " + (maisu-x10000-x5000));
				    }
					ok = true;
				}
			}
		}
		if(ok==false){
			Console.WriteLine("-1 -1 -1");
		}
	}
}

Measured memory_bytes: 13140
#include <bits/stdc++.h>
using namespace std;
using int64 = long long;


int64 C(int64 n){
  return n * (n - 1) / 2;
}

int main(){
  int n;
  cin >> n;
  vector<int> a(n), c(n);
  for(int i = 0; i < n; ++i){
    cin >> a[i];
    --a[i];
    c[a[i]]++;
  }
  int64 sum = 0;
  for(int i = 0; i < n; ++i){
    sum += C(c[i]);
  }
  for(int i = 0; i < n; ++i){
    cout << sum - C(c[a[i]]) + C(c[a[i]] - 1) << endl;
  }
}

Measured memory_bytes: 4844
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <queue>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
 
using namespace std;
 
typedef long long ll;
typedef unsigned long long ull;
 
static const double EPS = 1e-8;
static const double PI = 4.0 * atan(1.0);
static const double PI2 = 8.0 * atan(1.0);
 
#define REP(i,n)	for(int i=0;i<(int)n;++i)
#define ALL(c)		(c).begin(),(c).end()
#define CLEAR(v)	memset(v,0,sizeof(v))
#define MP(a,b)		make_pair((a),(b))
#define ABS(a)		((a)>0?(a):-(a))
#define FOR(i,s,n)	for(int i=s;i<(int)n;++i)

int main(){
    string s;
    cin >> s;
    for(int i=0;i<s.size() - 1;i++) {
        if(s[i] == s[i+1]) { 
            cout << i+1 << " " << i + 2 << endl;
            return 0;
        }
        if(i<s.size()-2 && s[i] == s[i+2]) {
            cout << i+1 << " " << i + 3 << endl;
            return 0;
        }
    }
    cout << -1 << " " << -1 << endl;
}


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

set<int> calc(string &a, string &b){
    int A = a.size(), B = b.size();
    set<int> st;
    rep(i,A+1){
        bool ok = true;
        rep(j,B){
            if (i+j >= A) break;
            if (a[i+j] == '?' || b[j] == '?') continue;
            if (a[i+j] != b[j]) ok = false;
        }
        if (ok) st.insert(i);
    }
    return st;
}

int main(void){
    vector<string> vs(3);
    rep(i,3) cin >> vs[i];
    int res = 6000;
    int pos[] = {0,1,2};
    do {
        string &a = vs[pos[0]], &b = vs[pos[1]], &c = vs[pos[2]];
        int A = a.size(), B = b.size(), C = c.size();
        auto fab = calc(a,b), fbc = calc(b,c), fac = calc(a,c);
        for (int x : fab) {
            rep(y, max(B+1, A-x)){
                if (y <= B && !fbc.count(y)) continue;
                if (x+y >= A || fac.count(x+y)) {
                    res = min(res, max({A, x+B, x+y+C}));
                }
            }
        }
    } while(next_permutation(pos, pos+3));
    cout << res << endl;
    return 0;
}


Measured memory_bytes: 384
//#include <bits/stdc++.h>
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
//#include "boost/multiprecision/cpp_int.hpp"
//typedef boost::multiprecision::cpp_int LL;
typedef long double dd;
#define i_7 (ll)(1E9+7)
//#define i_7 998244353
#define i_5 i_7-2

ll mod(ll a){
    ll c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
typedef pair<ll,ll> l_l;
typedef pair<dd,dd> d_d;
ll inf=(ll)1E16;
#define rep(i,l,r) for(ll i=l;i<=r;i++)
#define pb push_back
ll max(ll a,ll b){if(a<b)return b;else return a;}
ll min(ll a,ll b){if(a>b)return b;else return a;}
void Max(ll &pos,ll val){pos=max(pos,val);}//Max(dp[n],dp[n-1]);
void Min(ll &pos,ll val){pos=min(pos,val);}
void Add(ll &pos,ll val){pos=mod(pos+val);}
dd EPS=1E-9;
#define fastio ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define fi first
#define se second
#define endl "\n"
#define SORT(v) sort(v.begin(),v.end())
#define ERASE(v) v.erase(unique(v.begin(),v.end()),v.end())
#define POSL(v,x) (lower_bound(v.begin(),v.end(),x)-v.begin())
#define POSU(v,x) (upper_bound(v.begin(),v.end(),x)-v.begin())
//template<class T>void max(T a,T b){if(a<b)return b;else return a;}
//template<class T>void min(T a,T b){if(a>b)return b;else return a;}
//template<class T>bool Max(T&a, T b){if(a < b){a = b;return 1;}return 0;}
//template<class T>bool Min(T&a, T b){if(a > b){a = b;return 1;}return 0;}

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


int main(){fastio
    ll n;cin>>n;
    set<ll>s;
    while(n--){
        ll a;cin>>a;
        if(s.find(a)!=s.end()){
            s.erase(a);
        }else{
            s.insert(a);
        }
    }
    cout<<s.size()<<endl;
    
    return 0;
}


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

#define MAX 1000000001

struct Card{
    char suit;
    int value;
};

int partition(struct Card A[], int p, int r){
    int x = A[r].value;
    int i = p-1;
    for(int j = i+1; j < r; j++){
        if(A[j].value <= x){
            i++;
            swap(A[i], A[j]);
        }
    }
    swap(A[i+1], A[r]);
    return i+1;
}

void quickSort(struct Card A[], int p, int r){
    if(p < r){
        int q = partition(A, p, r);
        quickSort(A, p, q-1);
        quickSort(A, q+1, r);
    }
}

void merge(struct Card A[], int left, int mid, int right){
    int n1 = mid-left;
    int n2 = right-mid;
    struct Card L[n1+1];
    struct Card R[n2+1];
    for(int i = 0; i < n1; i++) L[i] = A[left+i];
    for(int i = 0; i < n2; i++) R[i] = A[mid+i];
    L[n1].value = MAX;
    R[n2].value = MAX;

    int li = 0;
    int ri = 0;

    for(int i = left; i < right; i++){
        if(L[li].value <= R[ri].value){
            A[i] = L[li];
            li++;
        }else{
            A[i] = R[ri];
            ri++;
        }
    }
}

void mergeSort(struct Card A[], int left, int right){
    if(left+1 < right){
        int mid = (left+right) / 2;
        mergeSort(A, left, mid);
        mergeSort(A, mid, right);
        merge(A, left, mid, right);
    }
}

int main(){
    int n;
    cin >> n;
    struct Card A[n], B[n];
    for(int i = 0; i < n; i++){
        char s;
        int val;
        cin >> s >> val;
        A[i].suit = B[i].suit = s;
        A[i].value = B[i].value = val;
    }

    mergeSort(A, 0, n);
    quickSort(B, 0, n-1);

    bool isStable = true;
    for(int i = 0; i < n; i++){
        if(A[i].suit != B[i].suit){
            isStable = false;
            break;
        }
    }

    if(isStable)    cout << "Stable" << endl;
    else            cout << "Not stable" << endl;

    for(int i = 0; i < n; i++){
        cout << B[i].suit << " " << B[i].value << endl;
    }

    return 0;
}


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

using namespace std;

typedef long long ll;

const int INF = 1000000000;

void dfs(int u, int d, vector<vector<int>>& adj, vector<int>& visited, vector<int>& dist)
{
  visited[u] = 1;
  dist[u] = d;
  for (int v : adj[u]) {
    if (visited[v]) { continue; }
    dfs(v, d + 1, adj, visited, dist);
  }
}

int main()
{
  int N; scanf("%d", &N);
  vector<vector<int> > adj(N + 1, vector<int>());
  for (int i = 0; i < N - 1; ++i) {
    int a, b;
    scanf("%d %d", &a, &b);
    adj[a].push_back(b);
    adj[b].push_back(a);
  }

  vector<int> visited(N + 5, 0);
  vector<int> d_fennec(N + 5, -1), d_snuke(N + 5, -1);
  dfs(1, 0, adj, visited, d_fennec);
  fill(visited.begin(), visited.end(), 0);
  dfs(N, 0, adj, visited, d_snuke);

  int fennec = 0, snuke = 0;
  for (int i = 1; i <= N; ++i) {
    if (d_fennec[i] <= d_snuke[i]) { ++fennec; }
    else { ++snuke; }
  }
  string ans = (fennec > snuke) ? "Fennec" : "Snuke";
  printf("%s\n", ans.c_str());
  return 0;
}


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

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

  for(int i = n; i < 1000; i++) {
    if(i % 10 == (i/10) % 10 && i % 10 == (i/100) % 10) {
      cout << i << endl;
      return 0;
    }
  }

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <functional>

using namespace std;

int main(void){
  long long int n, k ,h[200000], i, sum = 0;
  cin >> n >> k;
  for(i = 0; i < n; i++){
    cin >> h[i];
  }
  sort(h, h+n, greater<long long int>());
  for(i = k; i < n; i++){
    sum += h[i];
  }
  cout << sum << endl;
  return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define int long long
using namespace std;

int n,ii=0,now=0;

signed main()
{
	cin>>n;
	while (ii<=80000000)
	{
		ii++;
		now=(now*10+7)%n;
		
		if (now==0)  return cout<<ii<<endl,0;
	}
	cout<<-1<<endl;
	return 0;
}

Measured memory_bytes: 3608
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
const double eps = 1e-10;
const int MOD = 1000000007;
const int INF = 1000000000;
const ll LINF = 1ll<<50;
template<typename T>
void printv(const vector<T>& s) {
  for(int i=0;i<(int)(s.size());++i) {
    cout << s[i];
    if(i == (int)(s.size())-1) cout << endl;
    else cout << " ";
  }
}
int dfs (int now, const vvi &t) {
  if((int)(t[now].size()) == 0) {
    return 0;
  } else {
    int res = 0;
    for(int i=0;i<(int)(t[now].size());++i) {
      res ^= 1 + dfs(t[now][i], t);
    }
    return res;
  }
}
int main() {
  cin.tie(0);
  cout << fixed << setprecision(10);
  int n; cin >> n;
  vvi g(n);
  for(int i=0;i<n-1;++i) {
    int x, y; cin >> x >> y;
    x--; y--;
    g[x].push_back(y);
    g[y].push_back(x);
  }
  vvi t(n);
  queue<P> que;
  que.push({0, -1});
  while(!que.empty()) {
    int now = que.front().first, prev = que.front().second; que.pop();
    for(int i=0;i<(int)(g[now].size());++i) {
      int next = g[now][i];
      if(next != prev) {
        t[now].push_back(next);
        que.push({next, now});
      }
    }
  }
  int ans = dfs(0, t);
  cout << (ans==0 ? "Bob" : "Alice") << endl;
}


Measured memory_bytes: 15872
#include <stdio.h>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <list>
#include <iterator>
#include <assert.h>
#pragma warning(disable:4996) 

typedef long long ll;
#define MIN(a, b) ((a)>(b)? (b): (a))
#define MAX(a, b) ((a)<(b)? (b): (a))
#define LINF 9223300000000000000
#define INF 2140000000
const long long MOD = 1000000007;
using namespace std;



int main(int argc, char* argv[])
{
    char str[205]={0};
    while( scanf("%s", str) && str[0]!='-') {
        int len=strlen(str);

        int m,i;
        scanf("%d", &m);
        int sum=0;
        for(i=0; i<m; i++) {
            int tmp;
            scanf("%d", &tmp);
            sum = (sum+tmp)%len;
        }

        vector<char> str2;
        for(i=sum; i<len; i++) {
            str2.push_back(str[i]);
        }
        for(i=0; i<sum; i++) {
            str2.push_back(str[i]);
        }
        str2.push_back('\0');
        printf("%s\n", &str2[0]);
    }
    return 0;
}



Measured memory_bytes: 2644
s = input()
counter = 0
Ccounter = 0
Bigcounter = 0
while len(s)-4 >= counter:
    if s[counter+2] == "C":
        Ccounter += 1
    counter += 1
counter = 0
while len(s)-1 >= counter:
    if s[counter].islower() == False:
        Bigcounter += 1
    counter += 1
if s[0]=="A" and Ccounter == 1 and Bigcounter == 2:
    print("AC")
else:
    print("WA")

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i,l,r) for(ll i=(l);i<(r);i++)
    int num[]={59049,46656,7776,6561,1296,729,216,81,36,9,6,1};
int count(int a,int cnt){
    if(!a)return cnt;
    rep(i,0,12)if(a>=num[i]){
        if(i==11)return cnt+a;
        return min(count(a-num[i],cnt+1),count(a-num[i+1],cnt+1));
    }
}
int main(){
    int a,cnt=0;
    cin>>a;
    cout<<count(a,0);
}

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



int main() {
  int n, m; ///n桁の数
  cin >> n >> m;
  int f = 0;
  vector<int> num(n, 0);
  vector<int> check(n, 0);
  rep(i, m){
    int s, c; ///s桁目の数がc
    cin >> s >> c;


    if(c == 0 && s == 1 && n!= 1) {
      f = 1;
      break;
    }
    else if(check[s-1] != 0 &&  num[s-1] != c){
      f = 1;
      break;
    }
    else{
      num[s-1] = c;
      check[s-1] = -1;
    }
    /*
    else{
      num[s-1] = c;
      check[s-1] = -1;
    }
    */
  }
  if (f == 1) cout << -1 << endl;
  else {
    if(check[0]==0 and n != 1){
      num[0] = 1;
    }
  
    
    rep(i, n) cout << num[i];
  }
    } 
   
  





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

#define vi vector<int>
#define vvi vector<vi>
#define pii pair<int,int>
#define ll long long
template<typename T, typename U> 
static inline void amin(T &x, U y){
	if(x>y)
		x = y;
}
template<typename T, typename U> 
static inline void amax(T &x, U y){
	if(x<y)
		x = y;
}
#define rep(i,n) for(int i = 0; i < n; ++i)
#define REP(i,k,n) for(int i = k; i <= n; ++i)
#define REPR(i,k,n) for(int i = k; i >= n; --i)

int inf = 2e9;
ll INF = 2e18;
const int mod = 1e9+7;

int main(){
	int n, k;
	cin >> n>> k;
	int a;
	int dp[n][k+1];
	rep(ch,n){
		cin >> a;
		int suff = 1;
		if(ch==0){
			for(int x=0;x<=k;++x){
				if(x<=a)
					dp[0][x] = 1;
				else
					dp[0][x] = 0;
			}
			continue;
		}
		rep(i,k+1){
			dp[ch][i] = suff;
			suff = (suff+dp[ch-1][i+1])%mod;
			if(i>=a){
				suff = (suff-dp[ch-1][i-a]+mod)%mod;
			}
		}
	}
	cout<<dp[n-1][k]<<endl;
	return 0;
}

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

int main() {
  int N, K, X, Y,sum;
  cin >> N >> K >> X >> Y;
  if (K > N){
    for (int i = 1; i <= N; i++){
      sum += X;
    }
  }
  else {
    for (int i = 1; i <= K; i++){
    sum += X;
    }
    for (int i = 1; i <= N-K; i++){
      sum += Y;
    }
  }
  cout << sum << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> iint;
typedef pair<ll,ll> llll;
#define ALL(x) (x).begin(),(x).end()
const ll zero = 0;
const ll one = 1;
const ll INF = 9223372036854775807; //10^18
const int inINF = 2147483647; //10^9
const ll MOD = 1000000007; //10^9+7
const ll MOD2 = 998244353;
void Yes() {printf("Yes\n");}
void No() {printf("No\n");}
void YES() {printf("YES\n");}
void NO() {printf("NO\n");}

void dfs(vector<vector<int>> &G, vector<int> &d, int v, int par){
    for (int w : G[v]){
        if(w == par) continue;
        d[w] = d[v] + 1;
        dfs(G, d, w, v);
    }
}

int main(){
    int N;
    cin >> N;
    int u, v; cin >> u >> v; u--; v--;
    vector<vector<int>> G(N);
    int a, b;
    for (int i = 0; i < N-1; i++) {
        cin >> a >> b; a--; b--;
        G[a].push_back(b);
        G[b].push_back(a);
    }
    vector<int> du(N), dv(N);
    du[u] = 0; dv[v] = 0;
    dfs(G, du, u, -1);
    dfs(G, dv, v, -1);
    int m = 0;
    for (int i = 0; i < N; i++) {
        if(du[i] < dv[i]){
            m = max(dv[i] - 1, m);
        }
    }
    printf("%d\n", m);

}

Measured memory_bytes: 15908
#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
const int INF = 1e9, MOD = 1e9 + 7, ohara = 1e6 + 10;
const ll LINF = 1e18;
using namespace std;

#define rep(i, n) for (int(i) = 0; (i) < (int)(n); (i)++)
#define rrep(i, a, b) for (int i = (a); i < (b); i++)
#define rrrep(i, a, b) for (int i = (a); i >= (b); i--)
#define all(v) (v).begin(), (v).end()
#define Size(n) (n).size()
#define Cout(x) cout << (x) << endl
#define Cerr(x) cerr << (x) << endl
#define fi first
#define se second

ll n, cnt, ans, anss, a[ohara], b, c, d, tmp, tmpp, m, h, w, x, y, sum, pos, k, cop[ohara];
ld doua;
int dy[] = {1, 0, -1, 0};
int dx[] = {0, 1, 0, -1};
//int dy[]={-1,0,1,-1,1,-1,0,1};
//int dx[]={-1,-1,-1,0,0,1,1,1};
string alph("abcdefghijklmnopqrstuvwxyz"), s;
bool fl;
struct edge
{
    int to, cost;
};

//-------------------------↓↓↓↓↓↓------------------------

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

    cin >> n;
    rep(i, n) cin >> a[i], cop[i] = a[i];
    sum = 0;
    // 1 -1 1 -1
    rep(i, n)
    {
        sum += a[i];
        if (i % 2 == 0)
        {
            if (sum > 0)
                continue;
            ans += 1 - sum;
            a[i] += 1 - sum;
            sum = 1;
        }
        else
        {
            if (sum < 0)
                continue;
            ans += sum + 1;
            a[i] -= sum + 1;
            sum = -1;
        }
    }
    // 逆
    sum = 0;
    rep(i, n) a[i] = cop[i];
    rep(i, n)
    {
        sum += a[i];
        if (i % 2 != 0)
        {
            if (sum > 0)
                continue;
            anss += 1 - sum;
            a[i] += 1 - sum;
            sum = 1;
        }
        else
        {
            if (sum < 0)
                continue;
            anss += sum + 1;
            a[i] -= sum + 1;
            sum = -1;
        }
    }
    Cout(min(ans, anss));
    return 0;
}


Measured memory_bytes: 5120
import java.util.Scanner;

public class Main {
    //辞書で早く出てくるほうの勝ち、ポイントゲット
    public static void main(String[] args) {
        Scanner stdIn = new Scanner(System.in);
        int n = stdIn.nextInt();
        int L = 0;
        int R = 0;
        for(int i = 0; i < n; i++) {
            String s1 = stdIn.next();
            String s2 = stdIn.next();

            if(s1.compareTo(s2) == 0) {
                L++;
                R++;
            }
            else if(s1.compareTo(s2) < 0) {
                L += 3;
            }
            else {
                R += 3;
            }
        }

        System.out.println(R + " " + L);
    }

}



Measured memory_bytes: 30012
#include<stdio.h>
#define FOR(i,a,b) for(int i=a;i<b;i++)

int main(){

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

	char a[102][102];
	FOR(i,0,h){
		scanf("%s",a[i]);
	}

	FOR(num,0,w+2) printf("#");
	printf("\n");

	FOR(i,0,h){
		printf("#%s#\n",a[i]);
	}

	FOR(num,0,w+2) printf("#");
	printf("\n");
}

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

#define whole(f,x,...) ([&](decltype((x)) whole) { return (f)(begin(whole), end(whole), ## __VA_ARGS__); })(x)
#define REP(i, n) for(int i = 0;i < n;++i)
#define REPR(i, n) for(int i = n;i >= 0;--i)
#define FOR(i, a, b) for(int i = a;i < b;++i)
#define ALL(x) (x).begin(),(x).end()
#define INF 999999999
using namespace std;
#define lint long long

int main()
{
  int n; cin >> n;
  int b[n-1];
  REP(i,n-1){
    cin >> b[i];
  }
  lint sum = 0;
  sum += b[0];
  FOR(i,0,n-2){
    if(b[i] < b[i+1]){
     sum += b[i];
    }
    else{
     sum += b[i+1]; 
    }
  }
  sum += b[n-2];
  cout << sum << "\n";
  return 0;
}




Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <map>
#include <unordered_map>
#include <set>
#include <queue>
using namespace std;
#define ALL(x) (x).begin(),(x).end()
#define SZ(x) int((x).size())
#define OUT(x) cout << (x) << endl
typedef long long ll;
typedef vector<int> V;
typedef vector<vector<int>> VV;
typedef pair<int, int> P;
typedef map<string, int> M;
typedef unordered_map<int, int> HM;
typedef set<int> S;
typedef multiset<int> MS;
typedef queue<int> Q;

int main(){
    int n,m; cin>>n>>m;
    vector<pair<ll, vector<ll>>> dic(n);
    for(int i=0; i<n; i++){
        ll x,y,z; cin>>x>>y>>z;
        dic[i] = make_pair(0, vector<ll>{x,y,z});
    }
    ll ans = 0;
    for(int bit=0; bit<(1<<3); bit++){
        int a,b,c;
        a = (bit&(1<<0))? -1:1;
        b = (bit&(1<<1))? -1:1;
        c = (bit&(1<<2))? -1:1;
        for(int i=0; i<n; i++){
            dic[i].first = dic[i].second[0]*a+dic[i].second[1]*b+dic[i].second[2]*c;
        }
        sort(ALL(dic), greater<pair<ll,vector<ll>>>());
        ll sum = 0;
        for(int i=0; i<m; i++) sum += dic[i].first;
        ans = max(ans, sum);
    }
    OUT(ans);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define endl '\n'
#define sz(v) (int)v.size() 
#define all(v) v.begin(), v.end()
void dbg_out() { cerr << "\b\b]\n"; }
template<typename Head, typename... Tail> void dbg_out(Head H, Tail... T){ cerr << H << ", "; dbg_out(T...);}
#define watch(...) cerr << "[" << #__VA_ARGS__ << "]: [", dbg_out(__VA_ARGS__)


/****************************** CODE IS HERE ***********************************/

struct DSU {
  vector <int> parent, size;
  int components;
  DSU(int n) {
    parent.resize(n+1);
    size.assign(n+1, 1);
    iota(all(parent), 0);
    components = n;
  }

  //get leader
  int find(int a){
    if(parent[a] == a) return a;
    return parent[a] =  find(parent[a]);
  }

  void dsu_union(int a, int b){
    int x = find(a);
    int y = find(b);
    if(x == y) return;
    if(size[x] < size[y])
      swap(x, y);
    components--; //components decreases with union
    parent[y] = x;
    size[x] += size[y];
  }
};

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

    int n, m; cin >> n >> m;
    DSU graph(n);
    for (int i = 0, u, v; i < m; ++i) {
        cin >> u >> v;
        graph.dsu_union(u, v);
    }

    int mx = 0;
    for (int i = 1; i <= n; ++i) {
        int x = graph.find(i);
        mx = max(mx, graph.size[x]);
    }

    cout << mx;


    return 0;
}



Measured memory_bytes: 4764
def is_composite(n):
    r,d,a = 0,0,n-1
    while a%2 == 0:
        a = a >> 1
        r += 1
    d = a
    for a in [2,7,61]:
        x = pow(a,d,n)
        if x == 1 or x == n-1:
            continue
        for i in range(r-1):
            x = pow(x,2,n)
            if x == n-1:
               break
        else:
            return True
    return False

def is_prime(n):
    if n in [2,7,61]:
        return True
    elif 0 in (n%2,n%7,n%61):
        return False
    else:
        return not is_composite(n)

cnt = 0
n = int(input())
for i in range(n):
    s = int(input())
    if is_prime(s):
        cnt += 1

print(cnt)


Measured memory_bytes: 5616
#include<stdio.h>

int
main()
{
    int a, b;

    scanf("%d %d", &a, &b);

    if (a < b)
        printf("a < b\n");
    else if (a > b)
        printf("a > b\n");
    else
        printf("a == b\n");

    return 0;
}


Measured memory_bytes: 2036
#include <bits/stdc++.h>
using namespace std;
 
int main() {
int N ; cin >> N;
int K; cin >> K;

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

sort (vec.begin(), vec.end());

int SUM =0;
for (int j=0; j<K; j++){
	SUM += vec.at(j);}

cout << SUM <<endl;




}

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

#define PI 3.1415926535897932
#define MOD 1000000007
#define INF 1e9

#define REP(i, n) for(int i = 0; i < (n); i++)
#define REP1(i, n) for(int i = 1; i <= (n); i++)
#define ALL(v) (v).begin(), (v).end()
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO  cout << "NO"  << endl
#define No  cout << "No"  << endl

using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef vector<bool> vb;


void solve()
{
    int ans = 0;
    vi a(5);
    REP(i, 5)
    {
        int x; cin >> x;
        a[i] = x % 10;
        ans += x - a[i];
    }
    sort(ALL(a));
    bool frag = true;
    REP(i, 5)
    {
        if(frag && a[i] != 0)
        {
            ans += a[i];
            frag = false;
        }
        else if(a[i] != 0)
        {
            ans += 10;
        }
    }
    cout << ans << endl;
} 
    
int main() 
{
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(20);

    solve();

    return 0;
}

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

map<ll, int> prime_decomposition(ll n){
    map<ll, int> ans = map<ll, int>();
    ll k = pow(n, 0.5) + 1;
    ll i = 2;
    while(n > 1 and i < n and i < k){
        if (n % i == 0){
            ans[i] += 1;
            n = (ll)(n / i);
        }else{
            i += 1;
        }
    }
    if (n > 1){
        ans[n] += 1;
    }
    return ans;
}

int main(){
    ll A, B;
    cin >> A >> B;
    map<ll, int> a_primes = prime_decomposition(A);
    map<ll, int> b_primes = prime_decomposition(B);
    int ans = 1;
    for (pair<ll, int> p: a_primes){
        if (b_primes.count(p.first) > 0){
            ans += 1;//min(b_primes[p.first], p.second);
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 640
use proconio::*;

#[fastout]
#[allow(non_snake_case)]
fn main() {
    input! {
        N: usize, M: usize, X: usize,
        A: [[usize; M + 1]; N],
    }
    let mut ans = std::usize::MAX;
    for bit in 0..1 << N {
        let mut v: Vec<usize> = vec![0; M + 1];
        for i in 0..N {
            if bit & (1 << i) != 0 {
                for j in 0..M + 1 {
                    v[j] += A[i][j];
                }
            }
        }
        if (1..M + 1).filter(|&x| v[x] >= X).count() == M {
            ans = if ans > v[0] { v[0] } else { ans };
        }
    }
    if ans == std::usize::MAX {
        println!("{}", -1)
    } else {
        println!("{}", ans);
    }
}


Measured memory_bytes: 2164
#include <bits/stdc++.h>
#include <math.h>
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rrep(i, n) for(int i = 0; i <= (n); i++)
using namespace std;
typedef long long ll;
 
const ll INF = 1LL<<62;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
// 多次元 vector 生成
template<class T>
vector<T> make_vec(size_t a){
    return vector<T>(a);
}
template<class T, class... Ts>
auto make_vec(size_t a, Ts... ts){
  return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}

const int MOD = 1000000007;

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

    int xd[4] = {-1,0,1,0};
    int yd[4] = {0,-1,0,1};
    rep(i,H){
        rep(j,W){
            if (s[i][j] == '.') continue;
            bool isOK = false;
            int y,x;
            rep(k,4){
                y = i+yd[k];
                x = j+xd[k];
                if (0 > x || 0 > y || x >= W || y >= H) continue;
                if (s[y][x] == '#'){
                    isOK = true;
                    break;
                }
            }
            if (!isOK){
                //cout << x << " " << y << endl;
                cout << "No" << endl;
                return 0;
            }
        }
    }

    cout << "Yes" << endl;
}


Measured memory_bytes: 3580