akhauriyash/Code-Regression huggingface dataset:
import java.io.*;
import java.util.*;

public class Main {
    private static class Solver {
        private void Solve() {
            int n = inp.nextInt();
            int[] a = inp.nextArrayInt(n);

            int ans = 0;
            for (int i = 0; i < n; ++i) {
                int j = i;
                while (j + 1 < n && a[j + 1] == a[i]) {
                    j += 1;
                }
                ans += (j - i + 1) / 2;
                i = j;
            }
            out.println(ans);
        }
        static InputReader inp;
        static PrintWriter out;
    }

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

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

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

        private int nextInt() {
            return Integer.parseInt(next());
        }
        private long nextLong() {
            return Long.parseLong(next());
        }
        private int[] nextArrayInt(int n) {
            int[] a = new int[n];
            for (int i = 0; i < n; ++i) {
                a[i] = nextInt();
            }
            return a;
        }
    }
    public static void main(String[] args) throws IOException {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Solver.inp = new InputReader(inputStream);
        Solver.out = new PrintWriter(outputStream);
        Solver solver = new Solver();
        solver.Solve();
        Solver.out.close();
    }
}

Measured memory_bytes: 21204
MAX = pow(10,2)+10
N = int(input())
ans = [0 for _ in range(N+1)] #0indexにしておく

def func(a,b,c):
  return a*a+b*b+c*c+a*b+b*c+c*a
for x in range(1,MAX):
  for y in range(1,MAX):
    for z in range(1,MAX):
      temp = func(x,y,z)
      if temp <= N:
        ans[temp] += 1
for i in range(1,N+1):
  print(ans[i])
        

Measured memory_bytes: 69420
#include<bits/stdc++.h>
using namespace std;
#define ll long long 
#define ld long double
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    int a,b;
    cin>>a>>b;
    int s=1;
    int l=0;
    for(int i=0;true;i++){
        if(s >=b) break;
        s+=-1+a;
        l++;
    }
    cout<<l;
}

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

using namespace std;

int f(int prev) {
    if (prev % 2 == 0) {
        return prev / 2;
    } else {
        return (3 * prev) + 1;
    }
}

int main(int argc, char *argv[]) {
    int s;
    cin >> s;

    multimap<int, int> m;  //  value, idx
    m.emplace(s, 1);
    
    int prev = s;
    int ans = 0;
    for (int i = 2; i < 1000000; i++) {
        int val = f(prev);

        auto ite = m.find(val);
        if (ite != m.end()) {
            ans = i;
            break;
        }
        m.emplace(val, i);
        prev = val;
    }

    cout << ans << endl;
	return 0;
}


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

using namespace std;
int d[100100];

int main()
{
    int n;  cin >> n;
    for(int i = 0;i<n;i++)  cin >> d[i];
    if(n & 1)  return cout << 0 , 0;
    sort(d , d + n);
    cout << d[n/2] - d[n / 2 - 1];
    return 0;
}


Measured memory_bytes: 640
#include <cstdio>
#include <cstring> 
#include <iostream>
#define MN 201000

char s[MN];
int main()
{
	scanf("%s", s + 1);
	int len = strlen(s + 1);
	long long ans = 0;
	int sum = 0;
	for(int i = len; i >= 1; i--)
	{
		if(s[i] == 'A') ans += sum;
		else if(s[i] == 'B') sum = 0;
		else
		{
			if(s[i - 1] == 'B') sum++, i--;
			else sum = 0;
		}
	}
	printf("%lld\n", ans);
}

Measured memory_bytes: 384
import Control.Applicative
import Control.Monad
import Data.List
import Data.Array

main = do
  n <- (read::String -> Int) <$> getLine
  arr <- reverse . sort <$> forM [1..n] (\i -> (read::String -> Int) <$> getLine)
  let m = arr !! 0
      rest = tail arr
  print $ (m `div` 2) + sum rest

Measured memory_bytes: 508
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,c,r=0;
  cin>>n;
  vector<int> v(n),u;
  for(int i=0;i<n;++i){cin>>v[i];v[i]--;}
  c=0;
  for(int i=0;i<n;++i){
    if(i-v[i]){
      if(c)u.emplace_back(c);
      c=0;
    }
    else c++;
  }
  if(c)u.emplace_back(c);
  for(auto&& k:u)r+=k/2+k%2;
  cout<<r;
}

Measured memory_bytes: 1024
N, M = map(int, input().split())
n = [0 for i in range(N)]
pair = [list(map(int, input().split())) for i in range(M)]

pair = sorted(pair)

old_pair = [0, 0]

ok = True

for i in range(M):
    if pair[i] == [1, 0]:
        ok = False
        break
    elif pair[i][0] == old_pair[0] and pair[i][1] != old_pair[1]:
        ok = False
        break
    elif pair[i][0] != old_pair[0]:
        #print(pair[i][0])
        old_pair = pair[i]
        n[pair[i][0] - 1] = pair[i][1]

if n == [0]:
    print(0)
elif not ok:
    print(-1)
else:
    if n[0] == 0:
        print(1, end='')
    else:
        print(n[0], end='')
    for i in range(1, N):
        print(n[i], end='')
    print()


Measured memory_bytes: 3064
while True:
    try:
        a,b,c,d,e,f = map(int,input().split())
        y = (c*d-f*a)/(b*d-e*a)
        x = (c-(b*y))/a
        print('{:.3f} {:.3f}'.format(x,y))
    except EOFError:
        break


Measured memory_bytes: 5612
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        while (sc.hasNextInt()) {
            int inputx = sc.nextInt();
            int x = inputx;
            int sum = 0;
            while (x > 0) {
                sum += x % 10;
                x /= 10;
            }
            if ( inputx % sum == 0 ) {
                System.out.println("Yes");
            } else {
                System.out.println("No");

            }
        }
    }
}


Measured memory_bytes: 21844
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner s = new Scanner(System.in);
        int n = s.nextInt();
        if(n <= 3) {
            System.out.println(0);
            return;
        }
        List<Integer>[] chs = new List[128];
        for(int i = 0; i < 128; i++) {
            chs[i] = new ArrayList<>();
        }
        String str = s.next();
        for(int i = 0; i < str.length(); i++) {
            chs[str.charAt(i)].add(i);
        }
        char[] chars= {'R', 'G', 'B'};
        for(char c : chars) {
            if(chs[c].isEmpty()) {
                System.out.println(0);
                return;
            }
        }
        long res = 0;
        for(int i = 0; i < chars.length; i++) {
            res += count(chs[chars[i]], chs[chars[(i+1)%3]], chs[chars[(i+2)%3]]);
            res += count(chs[chars[i]], chs[chars[(i+2)%3]], chs[chars[(i+1)%3]]);
        }
        System.out.println(res);
    }

    private static long count(List<Integer> a, List<Integer> b, List<Integer> c) {
        long res = 0;
        for(int next : a) {
            for(int nextIndex : b) {
                if(nextIndex < next) {
                    continue;
                }
                if(c.isEmpty() || nextIndex > c.get(c.size()-1)) {
                    break;
                }
                int diff = (nextIndex - next);
                int secIndex = Collections.binarySearch(c, nextIndex);
                if(secIndex < 0) {
                    secIndex = -(secIndex + 1);
                }
                int present = Collections.binarySearch(c, nextIndex + diff);
                res += c.size() - secIndex;
                if (present >= 0) {
                    res -= 1;
                }
            }
        }
        return res;
    }
}


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

#define int long long
typedef pair<int, int> P;
#define mod 1000000007
#define INF (1LL<<60)
 
#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define repi(itr, ds) for (auto itr = ds.begin(); itr != ds.end(); itr++)
#define YES puts("YES")
#define Yes puts("Yes")
#define NO  puts("NO")
#define No  puts("No")
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
 
const int dx[4] = { 1, 0, -1, 0 };
const int dy[4] = { 0, 1, 0, -1 };
 
 
#if 1
//-------------
// DUMPマクロ
// https://www.creativ.xyz/dump-cpp-652/
 
// vector
template <typename T>
istream& operator>>(istream& is, vector<T>& vec) {
    for (T& x : vec) is >> x;
    return is;
}
// pair
template <typename T, typename U>
ostream& operator<<(ostream& os, pair<T, U>& pair_var) {
    os << "(" << pair_var.first << ", " << pair_var.second << ")";
    return os;
}
// vector
template <typename T>
ostream& operator<<(ostream& os, const vector<T>& vec) {
    os << "{";
    for (int i = 0; i < vec.size(); i++) {
        os << vec[i] << (i + 1 == vec.size() ? "" : ", ");
    }
    os << "}";
    return os;
}
// map
template <typename T, typename U>
ostream& operator<<(ostream& os, map<T, U>& map_var) {
    os << "{";
    repi(itr, map_var) {
        os << *itr;
        itr++;
        if (itr != map_var.end()) os << ", ";
        itr--;
    }
    os << "}";
    return os;
}
// set
template <typename T>
ostream& operator<<(ostream& os, set<T>& set_var) {
    os << "{";
    repi(itr, set_var) {
        os << *itr;
        itr++;
        if (itr != set_var.end()) os << ", ";
        itr--;
    }
    os << "}";
    return os;
}
 
#define DUMPOUT cerr
 
void dump_func() {
    DUMPOUT << endl;
}
template <class Head, class... Tail>
void dump_func(Head&& head, Tail&& ... tail) {
    DUMPOUT << head;
    if (sizeof...(Tail) > 0) {
        DUMPOUT << ", ";
    }
    dump_func(std::move(tail)...);
}
#ifdef DEBUG
#define DEB
#define dump(...)                                                              \
    DUMPOUT << "  " << string(#__VA_ARGS__) << ": "                            \
            << "[" << to_string(__LINE__) << ":" << __FUNCTION__ << "]"        \
            << endl                                                            \
            << "    ",                                                         \
        dump_func(__VA_ARGS__)
#else
#define DEB if (false)
#define dump(...)
#endif
#endif


 
signed main() {
    int N, M;
    cin >> N >> M;
    
    int ans = 1900*M + 100*(N-M);
    ans = ans << M;
    
    cout << ans << endl;
    
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define M 100005
#define P 1000000007
struct hh {
	int l,r;
} num[M];
int dp[105][M];
int main() {
	int n,k,pr=1,cnt=0;
	scanf("%d%d",&n,&k);
	while(pr<=n) {
		int t=n/pr,m=n/t;
		num[++cnt].l=pr;
		num[cnt].r=m;
		pr=m+1;
	}
	for(int i=1;i<=cnt;++i)dp[1][i]=num[i].r-num[i].l+1,dp[1][i]+=dp[1][i-1];
	for(int i=2;i<=k;++i){
		for(int j=1;j<=cnt;++j)
			dp[i][j]=1ll*(num[j].r-num[j].l+1)*dp[i-1][cnt-j+1]%P;
		for(int j=2;j<=cnt;++j)dp[i][j]=(dp[i][j]+dp[i][j-1])%P;
	}
	printf("%d",dp[k][cnt]);
}

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

int main() {
	int n, max, min, x;
	long sum;

	cin >> n;

	cin >> x;
	max = min = sum = x;

	for (int i = 0; i < n-1; i++) {
		cin >> x;
			if (x > max)	max = x;
			if (x < min)	min = x;
			sum += x;
	}
	cout << min << " " << max << " " << sum << endl;

	return 0;
}

Measured memory_bytes: 1164
import java.util.Scanner;

public class Main {
  public static void main(String[] args) throws Exception {
    Scanner scanner = new Scanner(System.in);
    try {
      int N = scanner.nextInt();
      int ans = 0;
      for (int i = 0; i * i <= N; i++) {
        ans = i * i;
      }
      System.out.println(ans);
    }
    finally {
      scanner.close();
    }
  }
}

Measured memory_bytes: 23764
#include <cstdio>
#include <iostream>
#include <algorithm>
using namespace std;
int main() {
    string num;
    while (cin>>num) {
        if (num=="#") break;
        int len=num.length();
        if (len<3) puts("0");
        else {
            bool isr=true;
            int pos=(num[0]-'0'+2)%3, res1=0, res2=0;
            for (int i=1; i<len; i++) {
                int next=(num[i]-'0'+2)%3;
                if (pos<next&&isr) {
                    res1++; isr=!isr;
                } else if (pos>next&&!isr) {
                    res1++; isr=!isr;
                }
                pos=next; isr=!isr;
            }
            pos=(num[0]-'0'+2)%3; isr=false;
            for (int i=1; i<len; i++) {
                int next=(num[i]-'0'+2)%3;
                if (pos<next&&isr) {
                    res2++; isr=!isr;
                } else if (pos>next&&!isr) {
                    res2++; isr=!isr;
                }
                pos=next; isr=!isr;
            }
            printf("%d\n",min(res1,res2));
        }
    }
}

Measured memory_bytes: 1144
#include<iostream>
#include<cstdio>
using namespace std;
 
char ans[100000000];
int main(){
    int n;
    while (cin >> n, n){
        char conv[128] = {}, input;
        int m;
        for (int i = 0; i < n; i++){
            cin >> input;
            cin >> conv[input];
        }
        cin >> m;
        for (int i = 0; i < m; i++){
            cin >> input;
            if (conv[input] != 0) ans[i] = conv[input];
            else ans[i] = input;
        }
        for (int i = 0; i < m; i++){
            printf("%c", ans[i]);
        }puts("");
    }
}

Measured memory_bytes: 1220
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#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;

//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
const int DX[] = {0, 1, 0, -1};
const int DY[] = {-1, 0, 1, 0};


//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

int main(int argc, char const *argv[])
{
	cin.tie(0);
	ios::sync_with_stdio(false);

	int n, result;
	LL ans = 0;
	cin >> n;
	VI numbers(n - 1);
	REP(i,n - 1){
		cin >> numbers[i];
	}
	cin >> result;

	vector<vector<LL> > dp(n-1, vector<LL>(21));
	dp[0][numbers[0]] = 1;
	REP(i, n - 2){
		REP(j, 21){
			LL value;
			if(20 >= j + numbers[i+1]){
				value = dp[i + 1][j + numbers[i+1]] += dp[i][j];
			}
			if(j - numbers[i+1] >= 0){
				value = dp[i + 1][j - numbers[i+1]] += dp[i][j];
			}
		}
	}
	cout << dp[n - 2][result] << endl;
	
	return 0;
}

Measured memory_bytes: 1232
from collections import Counter
n, p = map(int, input().split())
s = list(map(int, input()))
ans = 0
if p == 2:
    for i, c in enumerate(s):
        if c % 2 == 0:
            ans += i + 1
elif p == 5:
    for i, c in enumerate(s):
        if c % 5 == 0:
            ans += i + 1
else:
    l = [0] * (n + 1)
    for i, c in enumerate(s):
        l[i + 1] = l[i] + pow(10, n - i - 1, p) * c
        l[i + 1] %= p
    for v in Counter(l).values():
        ans += v * (v - 1) // 2
print(ans)


Measured memory_bytes: 13380
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <stdint.h> // uint64_t

#define max(a,b) ((a) > (b) ? (a) : (b))
#define min(a,b) ((a) > (b) ? (b) : (a))

int get_int3(int *a1, int *a2, int *a3) {
  scanf("%d %d %d", a1, a2, a3);
  return 0;
}
#define NUM_MAX 200000
#define COLOR_MAX 200000
#define DIVISOR 998244353

static int64_t factorial[NUM_MAX*2];
static int64_t inv_factorial[NUM_MAX*2];
static int64_t power_of_c[NUM_MAX+1];

struct pair {
    int x;
    int y;
};

struct pair gcdext(int a, int b) {
    if(a==0) { return (struct pair){0, 1}; }
    struct pair p = gcdext(b%a, a);
    return (struct pair){ p.y - (b/a)*p.x , p.x };
}

void init(int colors) {
    factorial[0] = factorial[1] = 1;
    inv_factorial[0] = inv_factorial[1] = 1;
    int i;
    for(i = 2; i < NUM_MAX*2; i++) {
        factorial[i] = (factorial[i-1]*i)%DIVISOR;
        struct pair p = gcdext(i, DIVISOR);
        int inv = (p.x+DIVISOR)%DIVISOR;
        inv_factorial[i] = (inv_factorial[i-1]*inv)%DIVISOR;
    }
    power_of_c[0] = 1;
    for(i = 1; i <= NUM_MAX; i++) {
        power_of_c[i] = (power_of_c[i-1] * (colors-1))%DIVISOR;
    }
    return;
}

int64_t calc_combi(int n, int k) {
    int64_t ans = 1;
    ans = (ans * factorial[n])%DIVISOR;
    ans = (ans * inv_factorial[n-k])%DIVISOR;
    ans = (ans * inv_factorial[k])%DIVISOR;
    return ans;
}

int main(void) {
    int num, colors, tlimit;
    get_int3(&num, &colors, &tlimit);
    int64_t ans = 0;
    init(colors);

    int k;
    for(k = 0; k <= tlimit; k++) {
        int64_t res = colors;
        int types = num-k;
        res = ( res * power_of_c[types-1] )%DIVISOR;
        res = (res * calc_combi(num-1, num-types))%DIVISOR;
#ifdef DEBUG
        printf("%d -> %lld\n", k, res);
#endif
        ans = (ans + res)%DIVISOR;
    }

    printf("%d\n", (int)ans);
    return 0;
}

Measured memory_bytes: 9548
a,b=map(int, input().split())
L=int(min(-(-a//0.08),-(-b//0.1)))
R=int(max(-(-(a+1)//0.08),-(-(b+1)//0.1)))
for x in range(L,R):
	if int(x*0.08)==a and int(x*0.1)==b:
		print(x)
		break
else:
	print(-1)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0, i##_len = (n); i < i##_len; ++i)
#define rep2(i, x, n) for(int i = x, i##_len = (n); i < i##_len; ++i)
#define all(n) begin(n), end(n)
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vl = vector<ll>;
using vs = vector<string>;
using vc = vector<char>;
using vb = vector<bool>;
using vd = vector<double>;
vi dir = {-1, 0, 1, 0, -1, -1, 1, 1, -1};

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

struct combination {
  vector<mint> fact, ifact;
  combination(int n) : fact(n + 1), ifact(n + 1) {
    assert(n < mod);
    fact[0] = 1;
    for(int i = 1; i <= n; ++i) fact[i] = fact[i - 1] * i;
    ifact[n] = fact[n].inv();
    for(int i = n; i >= 1; --i) ifact[i - 1] = ifact[i] * i;
  }
  mint operator()(int n, int k) {
    if(k < 0 || k > n) return 0;
    return fact[n] * ifact[k] * ifact[n - k];
  }
};

int main() {
  ll n;
  cin >> n;
  vl a(n);
  rep(i, n) cin >> a[i];
  sort(all(a));
  combination c(n);
  mint ans = 0;
  mint d = 0;
  rep(i, n) d += c(n - 1, i) * (i + 1);
  mint m = 2;
  if(n > 1) m = m.pow(n - 2);
  rep(i, n) {
    ans += d * a[i];
    d -= m;
  }
  ans = ans * mint(2).pow(n);
  cout << ans << endl;
}

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

int main() {
  int N,M;
  cin >> N >> M;
  
  vector<int> miti(2*M);
  
  for (int i=0; i<2*M; i++) {
    cin >> miti.at(i);
  }
  
  for (int i=0; i<N; i++) {
    int sum=0;
    
    for (int j=0; j<2*M; j++) {
      if (miti.at(j)==i+1) {
        sum++;
      }
    }
    
    cout << sum << endl;
  }
}

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

int r, g, b, n, ans;

int main() {
	cin >> r >> g >> b >> n;
	for (int i = 0; i <= n; i++)
		for (int j = 0; j <= n; j++) {
			if (r * i + b * j > n)
				break;
			int k = n - r * i - b * j;
			ans += (k % g == 0);
		}
	cout << ans;
}

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

int main() {
  string s;
  cin >> s;
  int maxatgc = 0;
  int atgc = 0;
  for (int i = 0; i < s.size(); i++) {
    if (s[i] == 'A' || s[i] == 'G' || s[i] == 'T' || s[i] == 'C') {
      atgc++;
      maxatgc = max(atgc, maxatgc);
    }
    else {
      atgc = 0;
    }
  }
  cout << maxatgc << endl;
}

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

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

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

ll fact(ll n){
	ll res = 1;
	rep(i, n){
		res *= i + 1;
		res =  res%((ll)(1e9 + 7));
	}
	return res;
}


int main(){
	string s;
	cin >> s;
	ll head = -1, tail = -1;
	rep(i, s.size()){
		if(s[i] == 'A' && head == -1){
			head = i + 1;
		}
	}
	reverse(s.begin(), s.end());
	rep(i, s.size()){
		if(s[i] == 'Z' && tail == -1){
			tail = i;
		}
	}
	tail = s.size() - tail;
	ll ans = tail - head + 1;
	cout << ans << endl;
}

Measured memory_bytes: 640
import java.util.Scanner;

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

		int n = sc.nextInt();
		int a = sc.nextInt();
		int b = sc.nextInt();

		int ans = Math.min(n * a, b);

		System.out.println(ans);

		sc.close();
	}

}


Measured memory_bytes: 23124
mod=10**9+7
n,a,b=map(int,input().split())
ans=pow(2,n,mod)-1
comb1=1
for i in range(n-a+1,n+1):
  comb1*=i
  comb1%=mod
for i in range(1,a+1):
  comb1*=pow(i,mod-2,mod)
  comb1%=mod
comb2=1
for i in range(n-b+1,n+1):
  comb2*=i
  comb2%=mod
for i in range(1,b+1):
  comb2*=pow(i,mod-2,mod)
  comb2%=mod
ans-=(comb1+comb2)
ans%=mod
print(ans)

Measured memory_bytes: 3064
import java.util.Scanner;

public class Main {
    public static void main(String args[]){
        Scanner sc = new Scanner(System.in);
        String S = sc.next();
        S = S.replaceAll("eraser", "-");
        S = S.replaceAll("erase", "-");
        S = S.replaceAll("dreamer", "-");
        S = S.replaceAll("dream", "-");
        S = S.replaceAll("-", "");
        if(S.length() == 0){
            System.out.println("YES");
        }else{
            System.out.println("NO");
        }


        //TLE起こした...
        //後日要検討(DP, 先読みGreedyなど)
//        String[] str = S.split("");
//        int i = 0;
//        boolean flag = false;
//        while(i < str.length){
//            if(S.substring(i).indexOf("dream") == -1 && S.substring(i).indexOf("erase") == -1) {
//                System.out.println("NO");
//                flag = true;
//                break;
//            }else if(S.substring(i, i + 5).equals("dream")){
//                try {
//                    if (str[i + 5].concat(str[i + 6]).equals("er")) {
//                        if(i + 7 < str.length){
//                            if(str[i + 7].equals("a")){
//                                i = i + 5;
//                            }else{
//                                i = i + 7;
//                            }
//                        }else{
//                            i = i + 5;
//                        }
//                    } else {
//                        i = i + 5;
//                    }
//                }catch (ArrayIndexOutOfBoundsException e){
//                    i = i + 5;
//                }
//            }else if(S.substring(i, i + 5).equals("erase")){
//                try {
//                    if (str[i + 5].equals("r")) {
//                        i = i + 6;
//                    } else {
//                        i = i + 5;
//                    }
//                }catch(ArrayIndexOutOfBoundsException e){
//                    i = i + 5;
//                }
//            }
//        }
//        if(!flag){
//            System.out.println("YES");
//        }
    }
}


Measured memory_bytes: 28800
#include <bits/stdc++.h>
#define range(i, l, r) for(int (i) = (l); (i) < (r); (i)++)
#define reversed_range(i, l, r) for (int (i) = (r) - 1; (i) >= l; (i)--)
using namespace std;
template <typename T>
using vec = vector<T>;
using lint = long long;
using ulint = unsigned long long;
using pint = pair<int, int>;
using plint = pair<lint, lint>;

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

template <typename T>
ostream& operator <<(ostream& os, vec<T> v) {
    os << "[";
    for (int i = 0; i < v.size() - 1; i++) {
        os << v.at(i) << ", ";
    }
    return os << v.at(v.size() - 1) << "]";
}

template <typename T>
ostream& operator <<(ostream& os, set<T>& s) {
    os << "{";
    auto it_first_item = s.begin();
    cout << *it_first_item;
    for (auto it = ++it_first_item; it != s.end(); it++) {
        cout << ", " << *it;
    }
    return cout << "}";
}

template <typename T>
ostream& operator <<(ostream& os, unordered_set<T>& s) {
    os << "{";
    auto it_first_item = s.begin();
    cout << *it_first_item;
    for (auto it = ++it_first_item; it != s.end(); it++) {
        cout << ", " << *it;
    }
    return cout << "}";
}

template <typename K, typename V>
ostream& operator <<(ostream& os, map<K, V> m) {
    os << "{";
    auto it_first_item = m.begin();
    cout << it_first_item->first << ": " << it_first_item->second;
    for (auto it = ++it_first_item; it != m.end(); it++) {
        cout << ", " << it->first << ": " << it->second;
    }
    return os << "}";
}

template <typename K, typename V>
ostream& operator <<(ostream& os, unordered_map<K, V> m) {
    os << "{";
    auto it_first_item = m.begin();
    cout << it_first_item->first << ": " << it_first_item->second;
    for (auto it = ++it_first_item; it != m.end(); it++) {
        cout << ", " << it->first << ": " << it->second;
    }
    return os << "}";
}

int main() {
    cin.tie(0); cout.tie(0);
    ios::sync_with_stdio(false);
    lint N;
    cin >> N;
    vec<lint> a_list(N);
    range(i, 0, N) cin >> a_list.at(i);
    unordered_set<lint> this_band_exists;
    lint num_too_smarts = 0;
    for (const auto a : a_list) {
        if (a >= 3200) num_too_smarts += 1;
        else {
            lint band = a / 400;
            this_band_exists.emplace(band);
        }
    }
    cout << max((lint)this_band_exists.size(), 1LL) << " " << this_band_exists.size() + num_too_smarts << "\n";
}

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


int main()
{
	int a;
	cin >> a;
	if (a >= 1000)
		cout << "ABD" << endl;
	else
		cout << "ABC" << endl;
	return 0;
}


Measured memory_bytes: 256
/*Code by Codercjh*/
#include<bits/stdc++.h>
#define fr(i,a,b) for(int i=(a);i<=(b);++i)
#define rf(i,a,b) for(int i=(a);i>=(b);--i)
#define min(a,b) (a<b?a:b)
#define max(a,b) (a>b?a:b)
using namespace std;
typedef long long ll;
template<typename T>
inline void read(T &x){
	char c=getchar();T fh=0;bool f=false;
	while(!isdigit(c))f|=(c=='-'),c=getchar();
	while(isdigit(c))fh=(fh<<1)+(fh<<3)+(c^48),c=getchar();
	x=f?-fh:fh;
	return;
}
ll n,b[200005],a[200005];
ll k;
int main(){
    read(n),read(k);
    fr(i,1,n)read(a[i]);
    ll tot=1,st=a[1];k--;
    b[1]=1;
    while(!b[st]&&k)b[st]=++tot,st=a[st],k--;
    k%=(tot+1-b[st]);
    fr(i,1,k)st=a[st];
    cout<<st;
	return 0;
}


Measured memory_bytes: 6728
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Stack;


public class Main {
	private	static	BufferedReader	br = null;

	static {
		br = new BufferedReader(new InputStreamReader(System.in));
	}
 
    /**
     * @param args
     */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Stack<Integer>	s = new Stack<Integer>();

		while(true) {
			int[]	r = parseRange();
			int		n = 0;
			boolean	f = false;

			if (r[0] == 0 && r[1] == 0) {
				break;
			}

			n = r[0] / 4;
			n = (r[0] % 4 != 0) ? n + 1 : n;
			n = n * 4;

			if (s.size() > 0) {
				s.push(-2);
			}

			for (; n <= r[1]; n += 4) {
				if (n % 400 == 0 || n % 4 == 0 && n % 100 != 0) {
					s.push(n);
					f = true;
				}
			}

			if (!f) {
				s.push(-1);
			}
		}

		for (int l = 0; l < s.size(); l++) {
			int	n = s.get(l);
			if (n == -2) {
				System.out.println("");
			} else if (n == -1) {
				System.out.println("NA");
			} else {
				System.out.println(n);
			}
		}
	}

	private static int[] parseRange() {
		int[]	params = new int[2];
		String	strin  = null;

		if ((strin = parseStdin()) != null) {
			String[]	lines = strin.split(" ");
			params[0] = Integer.parseInt(lines[0]);
			params[1] = Integer.parseInt(lines[1]);
		}
 
		return params;
	}

	private static String parseStdin() {
        String  stdin = null;
        
        try {
        	String  tmp = br.readLine();
        	if (!tmp.isEmpty()) stdin = tmp;
        }
        catch (IOException e) {}
 
        return stdin;
	}
}

Measured memory_bytes: 20048
import std.algorithm;
import std.array;
import std.ascii;
import std.bigint;
import std.complex;
import std.container;
import std.conv;
import std.functional;
import std.math;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

auto readInts() {
	return array(map!(to!int)(readln().strip().split()));
}
auto readInt() {
	return readInts()[0];
}
auto readLongs() {
	return array(map!(to!long)(readln().strip().split()));
}
auto readLong() {
	return readLongs()[0];
}

void readlnTo(T...)(ref T t) {
    auto s = readln().split();
    assert(s.length == t.length);
    foreach(ref ti; t) {
        ti = s[0].to!(typeof(ti));
        s = s[1..$];
    }
}

class UnionFindTree {
public:
    this(size_t n) {
        parent = iota(n).array();
        rank = new size_t[](n);
    }
    size_t find(size_t n) {
        if(n == parent[n]) {
            return n;
        } else {
            parent[n] = find(parent[n]);
            return parent[n];
        }
    }
    void unite(size_t n, size_t m) {
        auto p1 = find(n);
        auto p2 = find(m);
        if(n == m) {
            return;
        }
        if(rank[p1] < rank[p2]) {
            swap(p1, p2);
        }
        if(rank[p1] == rank[p2]) {
            ++rank[p1];
        }
        parent[p2] = p1;
    }
private:
    size_t[] parent;
    size_t[] rank;
}
unittest {
    auto uft = new UnionFindTree(10);
    foreach(i; iota(10)) {
        assert(uft.find(i) == i);
    }
    foreach(i; iota(10).filter!(a => a%3 == 0).drop(1)) {
        uft.unite(i, i-3);
    }
    foreach(i; iota(10).filter!(a => a%3 == 0)) {
        assert(uft.find(0) == uft.find(i));
    }
    foreach(i; iota(10).filter!(a => a%3 != 0)) {
        assert(uft.find(0) != uft.find(i));
    }
}

const real eps = 1e-10;

const long p = 1_000_000_000 + 7;


void main(){
    auto k = readLong();
    auto dp = new long[](k+1);
    dp[] = long.max / 4;

    //BinaryHeap!(Array!(long[]), "a > b") q;
    auto q = new RedBlackTree!(long[]);
    foreach(i; iota(1L,10L)) {
        q.insert([i, i%k]);
    }
    while(!q.empty()) {
        auto f = q.front();
        q.removeFront();
        if(dp[f[1]] <= f[0]) {
            continue;
        }
        dp[f[1]] = f[0];
        foreach(i; iota(10)) {
            if(dp[(f[1] * 10 + i) % k] > f[0] + i) {
                q.insert([f[0] + i, (f[1] * 10 + i) % k]);
            }
        }
    }
    writeln(dp[0]);
}


Measured memory_bytes: 50940
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define  all(x) (x).begin(),(x).end()
typedef long long ll;

vector<int> g[105];
vector<int> d(105, -1);

int main(){
    int n;
    cin >> n;
    rep(i,n){
        int u, k, v;
        cin >> u >> k;
        rep(j, k){
            cin >> v;
            g[u].push_back(v);
        }
    }
    queue<int> q;
    q.push(1);
    d[1] = 0;
    while(!q.empty()){
        int x = q.front(); 
        q.pop();
        for(int v : g[x]){
            if (d[v] != -1) continue;
            q.push(v);
            d[v] = d[x]+1;
        }
    }
    for(int i = 1; i <= n; i++){
        printf("%d %d\n", i, d[i]);
    }
    return 0;
}


Measured memory_bytes: 3272
import java.lang.StringBuilder

fun main(arr:Array<String>) {
    val txt = readLine()!!
    val hint = readLine()!!
    for(i in (0..txt.length-hint.length).reversed()) {
        var isMatch = true
        for(j in hint.indices) {
            if(txt[i+j] == '?') {
                continue
            }
            if(txt[i+j] != hint[j]) {
                isMatch = false
                break
            }
        }
        if(isMatch) {
            val txtList = txt.map { it }.toMutableList()
            for(j in hint.indices) {
                if(txtList[i+j] == '?') {
                    txtList[i+j] = hint[j]
                }
            }
            val ans = txtList.map { if(it == '?') 'a' else it }.joinToString("")
            println(ans)
            return
        }
    }
    println("UNRESTORABLE")
}



Measured memory_bytes: 33804
#include <stdio.h>
#include <stdlib.h>
#include <sys/time.h>

#define N	100000

unsigned int X;

void srand_() {
	struct timeval tv;

	gettimeofday(&tv, NULL);
	X = tv.tv_sec ^ tv.tv_usec;
	if (X % 2 == 0)
		X++;
}

int rand_() {
	return (X *= 3) >> 1;
}

int *oj[N], oo[N];

void link(int i, int j) {
	int o = oo[i]++;

	if (o >= 2 && (o & o - 1) == 0)
		oj[i] = (int *) realloc(oj[i], o * 2 * sizeof *oj[i]);
	oj[i][o] = j;
}

void sort(int *aa, int l, int r) {
	while (l < r) {
		int i = l, j = l, k = r, a = aa[l + rand_() % (r - l)], tmp;

		while (j < k)
			if (aa[j] == a)
				j++;
			else if (aa[j] < a) {
				tmp = aa[i], aa[i] = aa[j], aa[j] = tmp;
				i++, j++;
			} else {
				k--;
				tmp = aa[j], aa[j] = aa[k], aa[k] = tmp;
			}
		sort(aa, l, i);
		l = k;
	}
}

int solve(int *aa, int n, int i_, int l) {
	int i = 0, j = n - 1;

	while (i < j)
		if (i == i_)
			i++;
		else if (j == i_)
			j--;
		else {
			if (aa[i] + aa[j] > l)
				return 0;
			i++, j--;
		}
	return 1;
}

int dp[N];

int dfs(int p, int i, int l) {
	static int aa[N];
	int o, n, lower, upper;

	for (o = 0; o < oo[i]; o++) {
		int j = oj[i][o];

		if (j != p && !dfs(i, j, l))
			return 0;
	}
	n = 0;
	for (o = 0; o < oo[i]; o++) {
		int j = oj[i][o];

		if (j != p)
			aa[n++] = dp[j] + 1;
	}
	sort(aa, 0, n);
	if (p == -1)
		return solve(aa, n % 2 == 0 ? n : n - 1, -1, l);
	if (n % 2 == 0) {
		if (solve(aa, n, -1, l)) {
			dp[i] = 0;
			return 1;
		}
		n--;
	}
	lower = -1, upper = n;
	while (upper - lower > 1) {
		int h = (lower + upper) / 2;

		if (solve(aa, n, h, l))
			upper = h;
		else
			lower = h;
	}
	return upper < n && (dp[i] = aa[upper]) < l;
}

int main() {
	int n, h, i, j, k, lower, upper;

	srand_();
	scanf("%d", &n);
	for (i = 0; i < n; i++)
		oj[i] = (int *) malloc(2 * sizeof *oj[i]);
	for (h = 0; h < n - 1; h++) {
		scanf("%d%d", &i, &j), i--, j--;
		link(i, j), link(j, i);
	}
	k = n - 1;
	for (i = 0; i < n; i++)
		k -= oo[i] / 2;
	lower = 0, upper = n - 1;
	while (upper - lower > 1) {
		int l = (lower + upper) / 2;

		if (dfs(-1, 0, l))
			upper = l;
		else
			lower = l;
	}
	printf("%d %d\n", k, upper);
	return 0;
}


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

using namespace std;
#define MAX_N 31

/*
#define YES cout << "YES" << endl;
#define NO  cout << "NO"  << endl;
#define Yes cout << "Yes" << endl;
#define No  cout << "No"  << endl;
 
#define INF INT_MAX
#define LLINF LLONG_MAX
#define MOD 1000000007
#define PI  acos(-1)

using ll  = long long;
using ull = unsigned long long;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;

#define rep(i, n) for (ll i = 0; i < n; i++)
#define rrep(i, n) for (ll i = (n)-1; i >= 0; i--)

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

int main(int argc, char *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);

    // input values
    vector<int> vec;
    int i = 0;
    for (i = 0; i < MAX_N; i++) {
        int n;
        cin >> n;
        if (n == 0) {
            break;
        }
        vec.push_back(n);
    }

    // dp table
    vector<int> dp(MAX_N, 0);

    // init dp table
    // ok

    // init condition
    dp[0] = 1;
    dp[1] = 1;
    dp[2] = 2;

    // loop
    for (i = 0; i < MAX_N; i++) {
        dp[i+3] = dp[i]+dp[i+1]+dp[i+2];
    }

    for (i = 0; i < vec.size(); i++) {
        cout << dp[vec[i]]/3650+1 << endl;
    }
    return 0;
}


Measured memory_bytes: 3028
#include <iostream>
#include <cstdio>
#include <string>
using namespace std;
int main(void){
    int H,W;
    while(1){
        cin >> H >> W;
        if(H==0 && W==0){break;}
        for(int i=0;i<H;i++){
            for(int j=0;j<W;j++){
                if(i%2==0){
                    if(j%2==0){cout << "#";}else{cout << ".";}
                }else{
                    if(j%2==0){cout << ".";}else{cout << "#";}
                }
            }
            cout << endl;
        }
        cout << endl;
    }
}


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

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

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

const int INF = 1 << 30;
const int MOD = 1000000007;
const int MAX = 100000;
const int N = 100;
const int BLA = 1;
const int WHI = 2;

vi G[MAX];
struct dist {int d, f, c;};
dist D[MAX];

int main() {
	int n; cin>>n;
	rep(i, n-1) {
		int a,b; cin>>a>>b;a--;b--;
		G[a].push_back(b); G[b].push_back(a);
	}
	rep(i, n) {
		D[i].d=INF;
		D[i].c=0;
	}
	D[0].d=0;
	stack<int> S;
	S.push(0);
	while(!S.empty()){
		int i=S.top();S.pop();
		for(auto j: G[i]) {
			if (D[j].d > D[i].d+1) {
				S.push(j);
				D[j].d = D[i].d+1;
				D[j].f = i;
			}
		}
	}
	int cur=n-1, dist_n=D[n-1].d;
	while(cur!=0) {
		if(D[cur].d>dist_n/2) D[cur].c=WHI;
		else D[cur].c=BLA;
		S.push(cur);
		cur=D[cur].f;
	}
	D[0].c=BLA; S.push(0);
	while(!S.empty()){
		int i=S.top();S.pop();
		for(auto j: G[i]) {
			if (D[j].c==0) {
				S.push(j);
				D[j].c=D[i].c;
			}
		}
	}
	int cnt=0;
	rep(i, n) if(D[i].c==BLA) cnt++;
	if(cnt>n/2) cout << "Fennec" << endl;
	else cout << "Snuke" << endl;
}


Measured memory_bytes: 7296
#include<cstdio>
#include<cmath>
#include<iostream>
#include<cstring>
#include<iostream>
#include<cstdlib>
#include<string>
using namespace std;
#define LL long long
const int MaxN = 1e5 + 7;
LL a[MaxN], b[MaxN];
LL x[MaxN], v[MaxN];

int main()
{
    LL n, c;
    scanf("%lld %lld", &n, &c);
    for(int i = 1; i <= n; i++)
        scanf("%lld %lld", &x[i], &v[i]);
    for(LL i = 1; i <= n; i++)
        a[i] = a[i - 1] + v[i] - (x[i] - x[i - 1]); 
    x[n + 1] = c;
    for(LL i = n; i >= 1; i--)
        b[i] = b[i + 1] + v[i] - (x[i+1] - x[i]); 
    for(LL i = 2; i <= n; i++)
        a[i] = max(a[i-1], a[i]);
    for(LL i = n-1; i >= 1; i--)
        b[i] = max(b[i], b[i + 1]);
    LL ans = max(0LL,max(a[n],b[1]));
    for(LL i = 1; i <= n-2; i++) 
        ans = max(ans, a[i] - x[i] + b[i + 1]);
    for(LL i = 2; i <= n; i++)     
        ans = max(ans, b[i] - (c - x[i]) + a[i - 1]);
    printf("%lld\n", ans);
}


Measured memory_bytes: 3328
# -*- coding: utf-8 -*-
"""
E - Friendships
https://atcoder.jp/contests/abc131/tasks/abc131_e

"""
import sys


from itertools import combinations

def solve(N, K):
    limit = (N-1) * (N - 2) // 2
    if K > limit:
        print(-1)
        return

    g = []
    for i in range(2, N+1):
        g.append('{} {}'.format(1, i))
    rem = limit - K
    for f, t in combinations(range(2, N+1), 2):
        if rem <= 0:
            break
        g.append('{} {}'.format(f, t))
        rem -= 1
    print(len(g))
    print(*g, sep='\n')


def main(args):
    N, K = map(int, input().split())
    solve(N, K)


if __name__ == '__main__':
    main(sys.argv[1:])


Measured memory_bytes: 3716
#include <bits/stdc++.h>
#define repr(i,from,to) for(int (i)=(from);(i)<(to);(i)++)
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
// const bool debug=true;
const bool debug=false;
#define DEBUG if(debug==true)
#define vprint(x) for(auto a:(x)) cout << x << endl;
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const ll MOD = 1000000007;
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;
}


class UnionFind{
    public:
        UnionFind(int N) : parent(N, -1) {}
        bool unite(int x, int y){
            x = find(x);
            y = find(y);
            if (x == y){return false;}
            if (parent[x] > parent[y]){swap(x, y);}
            parent[x] += parent[y];
            parent[y] = x;
        }
        int find(int x) {
            if (parent[x] < 0){return x;}
            return parent[x] = find(parent[x]);
        }
        int size(int x) {
            return -parent[find(x)];
        }
        private:
            vector<int> parent;
};

int main(void) {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n,m;cin>>n>>m;
    vector<ll> a(n);
    UnionFind uf(n);
    rep(i,n){
        cin>>a[i];
    }
    rep(i,m){
        ll x,y;cin>>x>>y;
        uf.unite(x,y);
    }
    if(n>2*(m+1)){
        cout << "Impossible" << endl;
        return 0;
    }
    if(n==m+1){
        cout << 0 << endl;
        return 0;
    }
    vector<pair<ll,ll>> mins(n, pair<ll,ll>(n+1,1LL<<60));
    rep(i,n){
        ll root = uf.find(i);
        if(chmin(mins[root].second,a[i])){
            mins[root].first = i;
        }
    }
    vector<bool> check(n,false);
    ll res = 0;
    rep(i,n){
        if(mins[i].first!=n+1){
            res += mins[i].second;
            check[mins[i].first]=true;
        }
    }
    vector<ll> unused;
    rep(i,n){
        if(!check[i]){
            unused.push_back(a[i]);
        }
    }
    sort(begin(unused),end(unused));
    rep(i,n-m-2){
        res += unused[i];
    }
    cout << res << endl;
    return 0;
}


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

char S[15];

int main(){
    scanf(" %s", S);

    int len = strlen(S);
    if(len%2 != 0){
        printf("No");
        return 0;
    }
    for(int i = 0; i < len; i ++){
        if(i%2 == 0 && S[i] != 'h'){
            printf("No");
            return 0;
        }
        if(i%2 == 1 && S[i] != 'i'){
            printf("No");
            return 0;
        }
    }

    printf("Yes");
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <complex>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <numeric>
#include <cstring>
#include <ctime>
#include <cstdlib>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <cmath>
#include <bitset>
#include <cassert>
#include <queue>
#include <stack>
#include <deque>
#include <random>
#include <iomanip>
typedef long long int ll;
typedef long double ld;
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
const ll MOD=1000000007;
const ll MAX_N=500010;
const ll INF=999999999999;
vector<ll> v(200010,0);

int main(){
    ll n,k;
    cin>>n>>k;
    vector<ll> a(n);
    for(ll i=0;i<n;i++){
        cin>>a[i];
        v[a[i]]++;
    }
    vector<ll> q(0);
    ll kind=0;
    for(ll i=0;i<200010;i++){
        if(v[i]!=0){
            kind++;
            q.push_back(v[i]);
        }
    }
    ll ans=0;
    ll i=0;
    sort(q.begin(),q.end());
    while(kind-k>0){
        ans+=q[i];
        i++;
        kind--;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 5492
#include <vector>
#include <string>
#include <algorithm>
#include <numeric>
#include <functional>
#include <iterator>
#include <limits>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstdint>
#include <cassert>

using namespace std;

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

constexpr int DNE = -1;

struct Node {
    int parent;
    int left;
    int right;
    Node() : parent(DNE), left(DNE), right(DNE) {}
};

vector<Node> read_problem()
{
    int n;
    scanf("%d\n", &n);

    vector<Node> nodes(n);
    REP(i, n) {
        int id;
        int left;
        int right;
        scanf("%d %d %d", &id, &left, &right);

        nodes[id].left  = left;
        nodes[id].right = right;
        nodes[left].parent  = id;
        nodes[right].parent = id;
    }

    return nodes;
}

int node_depth(const vector<Node>& nodes, int id)
{
    int d = 0;
    for(Node node = nodes[id]; node.parent != DNE; node = nodes[node.parent]) {
        ++d;
    }

    return d;
}

int node_height(const vector<Node>& nodes, int id)
{
    const Node& node = nodes[id];

    if(node.left == DNE && node.right == DNE) {
        return 0;
    }
    else if(node.left == DNE) {
        return 1 + node_height(nodes, node.right);
    }
    else if(node.right == DNE) {
        return 1 + node_height(nodes, node.left);
    }
    else {
        return 1 + max(node_height(nodes, node.left), node_height(nodes, node.right));
    }
}

int node_sibling(const vector<Node>& nodes, int id)
{
    int parent = nodes[id].parent;
    if(parent == DNE) return DNE;
    const Node& p = nodes[parent];

    if(p.left == id)
        return p.right;
    else
        return p.left;
}

string node_typ(const Node& node)
{
    if(node.parent == DNE)
        return "root";
    else if(node.left == DNE && node.right == DNE)
        return "leaf";
    else
        return "internal node";
}

int main()
{
    vector<Node> nodes = read_problem();
    int n = nodes.size();

    vector<int> depths(n);
    REP(i, n) {
        depths[i] = node_depth(nodes, i);
    }
    //int depth_max = *max_element(depths.begin(), depths.end());

    REP(i, n) {
        Node node = nodes[i];
        int sibling = node_sibling(nodes, i);
        int degree = (node.left != DNE) + (node.right != DNE);
        int depth = depths[i];
        int height = node_height(nodes, i);
        string typ = node_typ(node);

        printf("node %d: parent = %d, sibling = %d, degree = %d, depth = %d, height = %d, %s\n",
               i, node.parent, sibling, degree, depth, height, typ.c_str());
    }

    return 0;
}

Measured memory_bytes: 2780