akhauriyash/Code-Regression huggingface dataset:
import java.util.HashSet;
import java.util.Scanner;

public class Main {

	public static String Y = "Yes";
	public static String N = "No";
	public static String I = "IMPOSSIBLE";
	public static String B = "Bad";
	public static String G = "Good";
	public static long MOD = (long) (Math.pow(10, 9) + 7);
	public static Scanner sc = new Scanner(System.in);

	public static void main(String[] args) {

		int n = ni();
		HashSet<String> hs = new HashSet<>();

		for (int i = 0; i < n; i++) {
			hs.add(n());
		}

		out(hs.size());

	}

	/*
	 * 以下メソッド集
	 */
	static int ni() {
		return sc.nextInt();
	}

	static long nl() {
		return sc.nextLong();
	}

	static String n() {
		return sc.next();
	}

	static char[] nc() {
		return sc.next().toCharArray();
	}

	static int kaijo(int n) {
		if (n == 0 || n == 1) {
			return 1;
		} else {
			return n * kaijo(n - 1);
		}
	}

	static int fib(int n) {
		return (n == 1 || n == 0) ? n : fib(n - 2) + fib(n - 1);
	}

	static long lcm(long m, long n) {

		return m * n / gcd(m, n);
	}

	static int lcm(int m, int n) {

		return m * n / gcd(m, n);
	}

	static long gcd(long a, long b) {
		return (b == 0) ? a : gcd(b, a % b);
	}

	static int gcd(int a, int b) {
		return (b == 0) ? a : gcd(b, a % b);
	}

	static void out(String info) {
		System.out.println(info);
	}

	static void out(int info) {
		System.out.println(info);
	}

	static void out(double info) {
		System.out.println(info);
	}

	static void out(long info) {
		System.out.println(info);
	}

	static void out(char info) {
		System.out.println(info);
	}

	static void outn(String info) {
		System.out.print(info);
	}

	static void outn(int info) {
		System.out.print(info);
	}

	static void outn(double info) {
		System.out.print(info);
	}

	static void outn(long info) {
		System.out.print(info);
	}

	static void outn(char info) {
		System.out.print(info);
	}

	static int max(int a, int b) {
		return Math.max(a, b);
	}

	static long max(long a, long b) {
		return Math.max(a, b);
	}

	static int min(int a, int b) {
		return Math.min(a, b);
	}

	static long min(long a, long b) {
		return Math.min(a, b);
	}
}


Measured memory_bytes: 78512
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for (int i=(a);i<(n);i++)
#define SZ(a) int((a).size())
#define pb push_back

const int N=3010;
int n,a[N];
vector<int> e[N];
int g[N];

int dfs(int v) {
	if (g[v]!=-1) return g[v];
	g[v]=0;
	for (int u:e[v]) g[v]|=!dfs(u);
	return g[v];
}

int main() {
	scanf("%d",&n);
	rep(i,0,n) scanf("%d",&a[i]);
	rep(i,0,n-1) {
		int x,y;
		scanf("%d %d",&x,&y); x--; y--;
		if (a[x]<a[y]) swap(x,y);
		if (a[x]>a[y]) e[x].pb(y);
	}
	fill_n(g,n,-1);
	rep(i,0,n) if (dfs(i)) printf("%d ",i+1);
	printf("\n");
}


Measured memory_bytes: 384
#include<stdio.h>

int number[100000]={};

int main(void){
	int N,Q,i;
	long long int S=0;
	scanf("%d",&N);
	for(i=0;i<N;i++){
		int A;
		scanf("%d",&A);
		number[A]++;
		S+=A;
	}
	scanf("%d",&Q);
	int B[Q],C[Q];
	for(i=0;i<Q;i++){
		scanf("%d %d",&B[i],&C[i]);		
	}
	for(i=0;i<Q;i++){
		S+=(C[i]-B[i])*number[B[i]];
		number[C[i]]+=number[B[i]];
		number[B[i]]=0;
		printf("%lld\n",S);
	}
	return 0;
}

Measured memory_bytes: 2900
#include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <iostream>
#include <sstream>
#include <functional>
#include <map>
#include <string>
#include <cstring>
#include <vector>
#include <queue>
#include <stack>
#include <deque>
#include <set>
#include <list>
#include <numeric>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<P,int> PP;
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const ll INF = 1LL<<29;
const ll mod = 1e9+7;
#define rep(i,n) for(int (i)=0;(i)<(ll)(n);++(i))
#define repd(i,n,d) for(ll (i)=0;(i)<(ll)(n);(i)+=(d))
#define all(v) (v).begin(), (v).end()
#define pb(x) push_back(x)
#define mp(x,y) make_pair((x),(y))
#define mset(m,v) memset((m),(v),sizeof(m))
#define chmin(X,Y) ((X)>(Y)?X=(Y),true:false)
#define chmax(X,Y) ((X)<(Y)?X=(Y),true:false)
#define fst first
#define snd second
#define UNIQUE(x) (x).erase(unique(all(x)),(x).end())
template<class T> ostream &operator<<(ostream &os, const vector<T> &v){int n=v.size();rep(i,n)os<<v[i]<<(i==n-1?"":" ");return os;}

#define N 100001
int n;
int a[N], b[N];

int main(){
	scanf("%d", &n);
	rep(i, n) scanf("%d", a+i);
	rep(i, n){
		int s = 0;
		while(a[i]>1){
			if(a[i]&1) b[i] = 1;
			a[i] >>= 1;
			s++;
		}
		a[i] = s;
	}
	int res = 0;
	rep(i, n){
		if(b[i]){
			if(i>0 && a[i]<a[i-1] || a[i]<a[i+1]) continue;
			res++;
			if(a[i]==a[i+1]) b[i+1] = 0;
		}
	}
	cerr<<res<<endl;
	set<PP> st;
	st.insert(PP(P(0, n), 0));
	vector<P> v(n);
	rep(i, n) v[i] = P(a[i], i);
	sort(all(v));
	for(auto &&x: v){
		int p = x.snd;
		auto it = st.upper_bound(PP(P(p, n+1), 0)); --it;
		res += x.fst - it->snd;
		int l = it->fst.fst, r = it->fst.snd;
		st.erase(it);
		if(l<p) st.insert(PP(P(l, p), x.fst));
		if(p+1<r) st.insert(PP(P(p+1, r), x.fst));
	}
	cout<<res<<endl;
	return 0;
}


Measured memory_bytes: 4992
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		long n = sc.nextLong();
		sc.close();

		List<Long> b = new ArrayList<>();
		long base = 1;
		while (true) {
			base *= 26;
			b.add(base);
			if (base > 1000000000000001L) {
				break;
			}
		}

		int a = 0;
		for (int i = 0; i < b.size(); i++) {
			if (n <= b.get(i)) {
				a = i + 1;
				break;
			}
			n -= b.get(i);
		}

		int[] c = new int[a];
		int i = 0;
		n--;
		while (n > 0) {
			c[i] = (int) (n % 26);
			n /= 26;
			i++;
		}

		for (i = a - 1; i >= 0; i--) {
			char d = (char) ('a' + c[i]);
			System.out.print(d);
		}
		System.out.println();
	}
}


Measured memory_bytes: 35572
import sys
input = lambda: sys.stdin.readline().rstrip()

N, X = map(int, input().split())

a = [1]
p = [1]
for i in range(N):
    a.append(a[i] * 2 + 3)
    p.append(p[i] * 2 + 1)

def rec(n,x):
    if n == 0:
        return 0 if x <= 0 else 1
    #真ん中以下まで到達    
    elif x <= 1 + a[n-1]:
        #バンズが一枚増えているので,真ん中以下までしか到達してない場合はn-1からx-1食べるのと同じ
        return rec(n-1, x-1)
    #真ん中以降まで到達
    else:
        #バンズ+N-1バーガー+真ん中のパティ+N-1バーガーのうち[x-a[n-1]-2]分を食べる

        return p[n-1] + 1 + rec(n-1, x-a[n-1]-2)

print(rec(N,X))

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

#define llint long long int

using namespace std;

int main()
{
    int N;

    cin >> N;

    vector<int> hidari(N), migi(N);

    for (int i = 0; i < N; i++)
    {
        int x, y;

        cin >> x >> y;

        hidari[i] = x + y;
        migi[i] = 1000000000 - x + y;
    }
    sort(hidari.begin(), hidari.end());
    sort(migi.begin(), migi.end());

    int ans1 = hidari[N - 1] - hidari[0];
    int ans2 = migi[N - 1] - migi[0];

    if (ans1 > ans2)
    {
        cout << ans1 << endl;
    }
    else
    {
        cout << ans2 << endl;
    }
}

Measured memory_bytes: 4836
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 
using namespace std;
#define IOS {ios :: sync_with_stdio(false); cin.tie(0);cout.tie(0); }
#define F first
#define S second
#define pb push_back
typedef long double ld;
#define deci(n) cout << fixed << setprecision(n);
typedef long long ll;

#define mem0(x)  memset(x,0,sizeof(x));
#define mem1(x)  memset(x,1,sizeof(x));
#define memm1(x) memset(x,-1,sizeof(x));
#define all(a) a.begin(), a.end()
#define pll pair<ll, ll>
#define bits(x) __builtin_popcount(x)
#define fori(n)  for (ll i = 0; i < n; i++)
#define fori2(n) for(ll i=1;i<=n;i++)
#define forj(n)  for (ll j = 0; j < n; j++)
#define forj2(n) for(ll j=1;j<=n;j++)
#define fork(n)  for (ll k = 0; k < n; k++)
#define fork2(n) for(ll k=1;k<=n;k++)
#define vll vector <ll>
#define mll map <ll, ll>
#define vpll vector <pll>
const ll md = 1e9 + 7;

#define BSET(a, p) ((a) | (1ll << (p)))
#define BCHK(a, p) ((a) & (1ll << (p)))
#define BXOR(a, p) ((a) ^ (1ll << (p)));
#define BREM(a, p) (BCHK(a, p)?(BXOR(a, p)):(a))
#define BSHO(a, N) (bitset<N>(a))
// const ll N = 100005;
// ll fac[N] = {1};
// #define calfac for(ll i=1  ;i<N;i++) fac[i] = (fac[i-1]*i)%md;
// ll C[N+1][M+1]; 
// void  ncr(){
//     ll n = N,k = M; 
//     for (ll i = 0; i <= n; i++) { 
//         for (ll j = 0; j <= min(i, k); j++) { 
//             if (j == 0 || j == i)  C[i][j] = 1; 
//             else C[i][j] = C[i - 1][j - 1] +  C[i - 1][j]; 
//         } 
//     } 
// } 


#define RBTTYPE int
#define ordered_set tree<RBTTYPE, null_type, less<RBTTYPE>, rb_tree_tag,tree_order_statistics_node_update> 
// Ordered set docs:
// order_of_key (k) : Number of items strictly smaller than k .
// find_by_order(k) : K-th element in a set (counting from zero).
ll modexp(ll x, ll ex) {
    ll ans = 1ll;
    while (ex > 0) {
        if (ex & 1ll) ans = (ans * x) % md;
        ex >>= 1ll;
        x = (x * x) % md;
    }
    return ans;
}
ll modInv(ll a)
{
    return pow(a,md-2);
}
 
// ll nCr(ll n,ll r)
// {
//     return (fac[n]*modInv((fac[r]*fac[n-r])%md))%md;
// }

 
ll po(ll x,ll n){
    if(n==0) return 1;
    if(n%2==1) return (x*po(x,n-1));
    else {
        ll k=po(x,n/2);
        return (k*k);
    }
}
 
ll gcd(ll x, ll y) {
    if (x < y) return gcd(y, x);
    if (y == 0) return x;
    return gcd(y, x % y);
}
const ll N = 200005;
ll a[N],h[N],bit[N],n;
void update(ll x,ll val){
    for(; x <= n ; x += (x&(-x))){
        bit[x] = max(bit[x],val);
    }
}
ll query(ll x){
    ll mx = 0;
    for(; x > 0 ; x -= (x&(-x))){
        mx = max(bit[x],mx);
    }
    return mx;
}


int32_t main(){
    IOS;
    ll i,j,k,m,p,q;
    cin >> n;
    fori2(n) cin >> h[i];
    fori2(n) cin >> a[i];
    fori2(n){
        k = query(h[i]-1);
        update(h[i],k + a[i]);
    }
    ll ans = 0;
    fori2(n+2) ans = max(ans,query(i));
    cout << ans << "\n";
} 

Measured memory_bytes: 4992
#include <stdio.h>

#define N 20
#define Q 200

int n;
int A[N];

int solve(i, m) {
	if (m == 0) return 1;

	if (i >= n) return 0;

	if (solve(i+1, m) || solve(i+1, m-A[i])) return 1;

	return 0;
}

int main() {
	int i;
	int q;
	int M[Q];

	scanf("%d", &n);

	for (i = 0; i < n; i++)
		scanf("%d", &A[i]);

	scanf("%d", &q);

	for (i = 0; i < q; i++)
		scanf("%d", &M[i]);

	for (i = 0; i < q; i++) {
		if (solve(0, M[i])) printf("yes\n");
		else printf("no\n");
	}

	return 0;
}

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

void Get357Number(vector<long long>& vec, string s, int startDigit, int endDigit, bool exist3, bool exist5, bool exist7) {

	if (s.size() == endDigit) {
		if (exist3 && exist5 && exist7) {
			vec.push_back(stoll(s));
		}
		return;		
	}
		
	for (int i = 0; i < 3; i++) {

		if (i == 0) {
			int tmp_digit = startDigit + 1;
			string tmp_s = s;
			bool tmp_exist3 = true;
			tmp_s += '3';
			Get357Number(vec, tmp_s, tmp_digit, endDigit, tmp_exist3, exist5, exist7);
		}
		else if (i == 1) {
			int tmp_digit = startDigit + 1;
			string tmp_s = s;
			bool tmp_exist5 = true;
			tmp_s += '5';
			Get357Number(vec, tmp_s, tmp_digit, endDigit, exist3, tmp_exist5, exist7);
		}
		else if (i == 2) {
			int tmp_digit = startDigit + 1;
			string tmp_s = s;
			bool tmp_exist7 = true;
			tmp_s += '7';
			Get357Number(vec, tmp_s, tmp_digit, endDigit,exist3,exist5,tmp_exist7);
		}

	}		
	return;

}

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

	vector<long long> c;
	string s;
	
	for (int i = 3; i <= 10; i++) Get357Number(c, s, 0, i, false, false, false);

	int ans;
	for (int i = 0; i < c.size(); i++) {
		if (n < c[i]) {
			ans = i;
			break;
		}
	}
	
	cout << ans << endl;
	
	return 0;	
}

Measured memory_bytes: 1400
#include<iostream>
#include<cstdio>
using namespace std;
int main(){
  int mas[10][10]={0};
  int dx1[5]={1,0,0,0,-1},dx2[9]={1,1,1,0,0,0,-1,-1,-1},dx3[13]={2,1,1,1,0,0,0,0,0,-1,-1,-1,-2};
  int dy1[5]={0,0,1,-1,0},dy2[9]={1,0,-1,1,0,-1,1,0,-1},dy3[13]={0,1,0,-1,2,1,0,-1,-2,1,0,-1,0};
  int x,y,size,nx,ny,bell=0,hess=0;
  while(scanf("%d,%d,%d",&x,&y,&size)!=EOF){
    if(size==1){
      for(int i=0;i<5;i++){
	nx=x+dx1[i];
        ny=y+dy1[i];
	if(nx>=0 && nx<10 && ny>=0 && ny<10){
	  mas[ny][nx]++;
	}
      }
    }
    else if(size==2){
      for(int i=0;i<9;i++){
	nx=x+dx2[i];
	ny=y+dy2[i];
	if(nx>=0 && nx<10 && ny>=0 && ny<10){
	  mas[ny][nx]++;
	}
      }
    }
    else if(size==3){
      for(int i=0;i<13;i++){
	nx=x+dx3[i];
	ny=y+dy3[i];
	if(nx>=0 && nx<10 && ny>=0 && ny<10){
	  mas[ny][nx]++;
	}
      }
    }
    /*for(int i=0;i<10;i++){
      for(int j=0;j<10;j++){
      cout << mas[i][j];
      }
      cout << endl;
      }*/
  }
  for(int i=0;i<10;i++){
    for(int j=0;j<10;j++){
      if(mas[i][j]>bell){
	bell=mas[i][j];
      }
      if(mas[i][j]==0){
	hess++;
      }
    }
  }
  cout << hess << endl << bell << endl;
  return (0);
}

Measured memory_bytes: 1212
#include <bits/stdc++.h>
using namespace std;
typedef int64_t int64;
typedef uint32_t uint;
typedef uint64_t uint64;

int fn_S(const string& s){
    int sum = 0;
    for(uint i=0; i<s.size(); ++i){
        sum += s[i]-'0';
    }
    return sum;
}

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

    string s; cin >> s;
    int N = stoi(s);
    int SN = fn_S(s);
    
    cout << ((N%SN==0)?"Yes":"No") << endl;
    
    return 0;
}

Measured memory_bytes: 256
class UnionFind:
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n
 
    def find(self, x):#要素xが属するグループの根を返す
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]
 
    def union(self, x, y):#要素xが属するグループと要素yが属するグループとを併合する
        x = self.find(x)
        y = self.find(y)
 
        if x == y:
            return
 
        if self.parents[x] > self.parents[y]:
            x, y = y, x
 
        self.parents[x] += self.parents[y]
        self.parents[y] = x
 
    def size(self, x):#要素xが属するグループのサイズ（要素数）を返す
        return -self.parents[self.find(x)]
 
    def same(self, x, y):#要素x, yが同じグループに属するかどうかを返す
        return self.find(x) == self.find(y)
 
    def members(self, x):#要素xが属するグループに属する要素をリストで返す
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]
 
    def roots(self):#すべての根の要素をリストで返す
        return [i for i, x in enumerate(self.parents) if x < 0]
 
    def group_count(self):#グループの数を返す
        return len(self.roots())
 
    def all_group_members(self):#{ルート要素: [そのグループに含まれる要素のリスト], ...}の辞書を返す
        return {r: self.members(r) for r in self.roots()}
 
    def __str__(self):#print()での表示用 ルート要素: [そのグループに含まれる要素のリスト]を文字列で返す
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())
 

n, m  = map(int,input().split())
fri = []

uf = UnionFind(n)

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

for a,b in fri:
    uf.union(a,b)
    
ans = 0
for i in range(n):
    ans = max(ans, uf.size(i))
print(ans)

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

int main() {
	int N;
	cin >> N;
	vector<string> Si(N);
	for (int n = 0; n < N; n++) {
		cin >> Si[n];
	}
	vector<pair<int, int>> up, down;
	for (int n = 0; n < N; n++) {
		int h = 0, b = 0;
		for (int i = 0; i < Si[n].size(); i++) {
			if (Si[n][i] == '(') {
				h++;
			}
			else if (Si[n][i] == ')') {
				h--;
			}
			else {
				break;
			}
			b = min(b, h);
		}
		if (h >= 0) {
			up.emplace_back(b, h);
		}
		else {
			down.emplace_back(b - h, h);
		}
	}
	sort(up.rbegin(), up.rend());
	sort(down.begin(), down.end());
	int h = 0;
	for (int i = 0; i < up.size(); i++) {
		if (h + up[i].first < 0) {
			cout << "No" << endl;
			return 0;
		}
		h += up[i].second;
	}
	for (int i = 0; i < down.size(); i++) {
		if (h + down[i].first + down[i].second < 0) {
			cout << "No" << endl;
			return 0;
		}
		h += down[i].second;
	}

	if (h == 0) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
	return 0;
}

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

int main(){
	int n, p;
	vector<ull> rem;
	ull ans = 0;
	string s;
	cin>>n>>p;
	cin>>s;
	if(p==2 || p==5){
		int cnt = 0;
		for(int i=0;i<n;i++){
			int digit = s[i]-'0';
			if(digit%p == 0){
				ans += (i+1);
			}
		}
	}
	else{
		reverse(s.begin(), s.end());
		rem.assign(p, 0);
		int cur_rem = 0, pw = 1;
		for(int i=0;i<n;i++){
			int digit = s[i]-'0';
			cur_rem = (pw*digit + cur_rem)%p;
			pw*=10;
			pw%=p;
			rem[cur_rem]++;
		}
		for(int i=0;i<p;i++){
			//cout<<i<<": "<<rem[i]<<"\n";
			ans += (rem[i]*(rem[i]-1))/2;
		}
		ans += rem[0];
	}
	cout<<ans<<"\n";
	return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define LOCAL
using namespace std;
template <typename A, typename B>
ostream& operator <<(ostream& out, const pair<A, B>& a) {
out << "(" << a.first << "," << a.second << ")";
return out;
}
template <typename T, size_t N>
ostream& operator <<(ostream& out, const array<T, N>& a) {
out << "["; bool first = true;
for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
return out;
}
template <typename T>
ostream& operator <<(ostream& out, const vector<T>& a) {
out << "["; bool first = true;
for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
return out;
}
template <typename T, class Cmp>
ostream& operator <<(ostream& out, const set<T, Cmp>& a) {
out << "{"; bool first = true;
for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "}";
return out;
}
template <typename U, typename T, class Cmp>
ostream& operator <<(ostream& out, const map<U, T, Cmp>& a) {
out << "{"; bool first = true;
for (auto& p : a) { out << (first ? "" : ", "); out << p.first << ":" << p.second; first = 0;} out << "}";
return out;
}
#ifdef LOCAL
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
#else
#define trace(...) 42
#endif
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
const char* comma = strchr(names + 1, ',');
cerr.write(names, comma - names) << ": " << arg1 << " |";
__f(comma + 1, args...);
}
#define rep(i,n) for(int i=0; i<(n); i++)
using ll = long long;
#define int long long
using P = pair<int,int>;
int dp[3300][3300];
const int mod = 998244353;
signed main(){
    int n,s;cin >> n  >> s;
    int a[n];
    rep(i,n)cin >> a[i];
    dp[0][0] = 1;
    rep(i,n)rep(j,s+1){
        dp[i+1][j] =(dp[i+1][j]+ dp[i][j]*2%mod)%mod;
        if(j-a[i] >= 0)dp[i+1][j] = (dp[i+1][j]+dp[i][j-a[i]])%mod;
    }
    cout << dp[n][s]%mod << endl;
    return 0;
}

Measured memory_bytes: 81000
#include<iostream>
#include<algorithm>
#include<string>
#include<map>
#include<vector>
#define rep(i, n) for(int i=0; i<n; i++)
using namespace std;
typedef long long ll;

int main(){
    int x,y,a,b,c; cin >>x>>y>>a>>b>>c;
    int p[a],q[b],r[c];
    vector<pair<int, int> > all;
    rep(i,a){ cin >> p[i]; all.push_back({p[i],1});}
    rep(i,b){ cin >> q[i]; all.push_back({q[i],2});}
    rep(i,c){ cin >> r[i]; all.push_back({r[i],0});}
    sort(all.rbegin(), all.rend());
    int red=0, green=0, eat=0, i=0;
    ll ans = 0;
    while(eat < x+y){
        //cout << all[eat].first << endl;
        if(all[i].second == 1){
            if(red < x){ ans+=all[i].first; eat++;}
            red++;
        }else if(all[i].second == 2){
            if(green < y){ ans+=all[i].first; eat++;}
            green++;
        }else{
            ans+=all[i].first;
            eat++;
        }
        //cout<<"eat " << eat << endl;
        //cout << "ans "<< ans << endl;
        i++;
    }
    cout << ans << endl;
    
}

Measured memory_bytes: 8484
#include <bits/stdc++.h>
// #include <atcoder/all>
#define ll long long int
#define ld long double
#define yorn(f) std::cout<<((f)?"Yes":"No")<<endl;
#define YORN(f) std::cout<<((f)?"YES":"NO")<<endl;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define repi(i, n) for (ll i = 1; i < (ll)(n); i++)
#define all(x) (x).begin(), (x).end()
#define put(x) std::cout << x << endl;
#define println(x) std::cout << x << endl;
template<typename T>bool mins(T& x,const T&y){if(x>y){x=y;return true;}else return false;}
template<typename T>bool maxs(T& x,const T&y){if(x<y){x=y;return true;}else return false;}
const ll INF = 1e18;
using namespace std;
// using namespace atcoder;
void Main()
{
    ll n;
    cin >> n;

    vector<ll> A(n), B(n);
    rep(i, n) cin >> A[i] >> B[i];
    
    sort(all(A));
    sort(all(B));

    if (n % 2 == 0) {
        ll mA = A[n/2-1] + A[n/2];
        ll mB = B[n/2-1] + B[n/2];
        ll res = mB - mA + 1;
        put(res);
    }
    else {
        ll mA = A[n/2];
        ll mB = B[n/2];
        ll res = mB - mA + 1;
        put(res);
    }
}
signed main(){ Main();return 0;}

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

int main()
{
	string s;
	int res = 0, tmp = 0;
	while(getline(cin, s)){
		for(auto c : s){
			if(isdigit(c)){
				tmp = tmp * 10 + c - '0';
			}
			else{
				res += tmp;
				tmp = 0;
			}
		}
		res += tmp;
		tmp = 0;
	}
	cout << res << endl;
	return 0;
}

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

ll modinv(ll a,ll m){
   ll b=m,u=1,v=0;
   while(b){
      ll t=a/b;
      a-=t*b; 
      swap(a,b);
      u-=t*v; 
      swap(u,v);
   }
   u%=m;
   if(u<0) u+=m;
   return u;
}

ll gcd(ll x,ll y){
   if(y==0) return x;
   else return gcd(y,x%y);
}
ll lcm(ll x,ll y){
   return x/gcd(x,y)*y;
}



int main(){
  int n;
  cin>>n;
  vector<unsigned long long> a(n,0);
  
  unsigned long long ans=1;
  bool f=false;
  rep(i,n){
     cin>>a[i];
  }
  rep(i,n){
     unsigned long long c=ans*a[i];
   if((c/ans)!=a[i]) {
      f=true;
      break;
   }

     ans*=a[i];
  }
  rep(i,n){
     if(a[i]==0) {f=false;
     cout<<"0";
     return 0;
     }
  }
  if(ans>1000000000000000000) f=true;
  if(f==true) cout<<"-1";
  else cout<<ans;
   return 0;
}



Measured memory_bytes: 4048
def min(a,b); a < b ? a : b; end

N = gets.to_i
S = gets.chomp

R,G,B = %w/R G B/.map{|c| S.count(c) }

c2 = N.times.inject(0) do |s, j|
  d = min(j, S.size - 1 - j)
  next s if d.zero?
  s + (1 .. d).count{|d_| S[j] != S[j - d_] && S[j] != S[j + d_] && S[j - d_] != S[j + d_] }
end

puts R * G * B - c2



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

#define rep(i, n) for (int i = 0; i < n; i++)
#define rep1(i, n) for (int i = 1; i <= n; i++)
#define show(a, n) rep(i,n) {cout<<a[i]<<' ';} cout<<endl;

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

const int INF = 1 << 30;
const long long INFL = 1LL << 62;
const int MOD = 1000000007;
const int MAX = 100000;
const int N = 100000;

int main() {
	ll h, n;
	cin >> h >> n;
	ll sum_a = 0;
	rep(i, n) {
		ll a;
		cin >> a;
		sum_a += a;
	}
	if(sum_a >= h) cout << "Yes" << endl;
	else cout << "No" << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <cstring>
#include <math.h>
#include <bitset>
#include <queue>
#include <set>
#include <iomanip>
#include <math.h>
#include <assert.h>
// #include<bits/stdc++.h>
using namespace std;
typedef long long ll;
constexpr long long int INFLL = 1001001001001001LL;
constexpr long long int infll = 1001001001001001LL;
constexpr int INF = 1000000007;
constexpr int inf = 1000000007;
const int 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;
}

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

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

inline double nCr(const int n, int r)
{
    if (n == 0)
    {
        return 0;
    }
    if (r == 0)
    {
        return 1;
    }
    if (r == 1)
    {
        return n;
    }
    if (n == r)
    {
        return 1;
    }

    if (r > n / 2)
    {
        r = n / 2;
    }

    double result = 1;
    for (double i = 1; i <= r; i++)
    {
        result *= (n - i + 1) / i;
    }

    return (result);
}

template <typename T>
T seinomi(T a)
{
    if (a > 0)
    {
        return a;
    }
    else
    {
        return 0;
    }
}

template <typename T>
map<T, T> soinsuubunkai(T n) //連想配列[素因数f.first][個数f.second]
{
    map<T, T> ret;
    for (T i = 2; i * i <= n; i++)
    {
        while (n % i == 0)
        {
            ret[i]++;
            n /= i;
        }
    }
    if (n != 1)
        ret[n] = 1;
    return ret;
}

template <typename T>
T ketasuu(T num)
{
    return std::to_string(num).length();
}

int kaizyou(int k)
{
    int sum = 1;
    for (int i = 1; i <= k; ++i)
    {
        sum *= i;
    }
    return sum;
}

template <class ForwardIt, class T>
void iota(ForwardIt first, ForwardIt last, T value)
{
    while (first != last)
    {
        *first++ = value;
        ++value;
    }
}

//nの階乗を計算
int factorial(int n)
{
    int answer = 1;
    while (n > 1)
    {
        answer *= n;
        n--;
    }
    return answer;
}
int comb(int n, int r)
{
    return factorial(n) / (factorial(r) * factorial(n - r));
}

long long modpow(long long a, long long n, long long mod)
{
    long long res = 1;
    while (n > 0)
    {
        if (n & 1)
            res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}


template <typename T>
T amarinasi(T a,T b){
    if(a%b==0)
{
    return a/b;
}
else if(a%b>0)
{
    return a/b+1;
}
else
{
    return a/b-1;
}
}

//小数点以下10桁テンプレート（main関数内の最初に貼付け）
//std::cout << std::fixed << std::setprecision(10);

//----------------------------------------------------------------

int main(){
ll n;
cin>>n;
double t,a;
cin>>t>>a;
double h;
double ans=1000000;
ll out;
for(int i=0;i<n;i++){
    cin>>h;
    double tmp=t-h*0.006;
    if(chmin(ans,fabs(a-tmp))){
        out=i+1;
    }
}
cout<<out<<endl;
}












Measured memory_bytes: 256
#include <bits/stdc++.h>
#define LLI long long int
#define FOR(v, a, b) for(LLI v = (a); v < (b); ++v)
#define FORE(v, a, b) for(LLI v = (a); v <= (b); ++v)
#define REP(v, n) FOR(v, 0, n)
#define REPE(v, n) FORE(v, 0, n)
#define REV(v, a, b) for(LLI v = (a); v >= (b); --v)
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define ITR(it, c) for(auto it = (c).begin(); it != (c).end(); ++it)
#define RITR(it, c) for(auto it = (c).rbegin(); it != (c).rend(); ++it)
#define EXIST(c,x) ((c).find(x) != (c).end())
#define fst first
#define snd second
#define popcount __builtin_popcount
#define UNIQ(v) (v).erase(unique(ALL(v)), (v).end())
#define bit(i) (1LL<<(i))

#ifdef DEBUG
#include <misc/C++/Debug.cpp>
#else
#define dump(...) ((void)0)
#endif

#define gcd __gcd

using namespace std;
template <class T> constexpr T lcm(T m, T n){return m/gcd(m,n)*n;}

template <typename I> void join(ostream &ost, I s, I t, string d=" "){for(auto i=s; i!=t; ++i){if(i!=s)ost<<d; ost<<*i;}ost<<endl;}
template <typename T> istream& operator>>(istream &is, vector<T> &v){for(auto &a : v) is >> a; return is;}
template <typename T, typename U> bool chmin(T &a, const U &b){return (a>b ? a=b, true : false);}
template <typename T, typename U> bool chmax(T &a, const U &b){return (a<b ? a=b, true : false);}
template <typename T, size_t N, typename U> void fill_array(T (&a)[N], const U &v){fill((U*)a, (U*)(a+N), v);}

struct Init{
  Init(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(12);
    cerr << fixed << setprecision(12);
  }
}init;



int main(){
  int N;
  while(cin >> N){
    LLI ans = 0;


    map<pair<char,char>, LLI> m;

    FORE(i,1,N){
      auto s = to_string(i);

      m[make_pair(s.front(), s.back())] += 1;
    }

    FORE(i,1,N){
      auto s = to_string(i);
      
      ans += m[make_pair(s.back(), s.front())];
    }
    

    


    cout << ans << endl;
  }

  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<utility>
#include<map>
#include<queue>
#include<set>
#include<bitset>
#include<stdio.h>
#include<deque>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
typedef long long ll;
 
int main()
{
    int a, b;
    cin >> a >> b;
    if((a*b) % 2 == 0){
        cout << "No" << endl;
    }
    else{
        cout << "Yes" << endl; 
    }
    system("pause");
}

Measured memory_bytes: 504
#include <iostream>
#include <algorithm>
#include <iomanip>
#include"stdio.h"
#include <cstring>
#include<math.h>
#include<map>
#include<queue>
#include<stack>
#include"time.h"
#define MAX_INT  ((unsigned)(-1)>>1)
#define MIN_INT  (~MAX_INT)
#define db printf("where!\n");
#define pb push_back
using namespace std;
#define ll long long
template<class T>inline void read(T &res){
char c;T flag=1;
while((c=getchar())<'0'||c>'9')if(c=='-')flag=-1;res=c-'0';
while((c=getchar())>='0'&&c<='9')res=res*10+c-'0';res*=flag;
}
 
int main()
{
    string s;cin>>s;
    if(s[0]=='7'||s[1]=='7'||s[2]=='7') cout<<"Yes";
    else cout<<"No";
 
    return 0;
}

Measured memory_bytes: 3040
///////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////
//                       _oo0oo_                         //
//                      o8888888o                        //
//                      88" . "88      ------ hzt1       //
//                      (| -_- |)                        //
//                      0\  =  /0                        //
//                    ___/`---'\___                      //
//                  .' \|     |// '.                     //
//                 / \|||  :  |||// \                    //
//                / _||||| -:- |||||- \                  //
//               |   | \  -  /// |     |                 //
//               | \_|  ''\---/''  |_/ |                 //
//               \  .-\__  '-'  ___/-. /                 //
//             ___'. .'  /--.--\  `. .'___               //
//          ."" '<  `.___\_<|>_/___.' >' "".             //
//         | | :  `- \`.;`\ _ /`;.`/ - ` : | |           //
//         \  \ `_.   \_ __\ /__ _/   .-` /  /           //
//     =====`-.____`.___ \_____/___.-`___.-'=====        //
//                       `=---='                         //
//                                                       //
//                                                       //
//     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~       //
//                                                       //
//                 God-He Bless All.                     //
//           This Code Will Never Explode.               //
//                                                       //
//                                                       //
///////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////
#include<cstdio>
#include<cstring>
#include<cctype>
#include<algorithm>
#include<vector>
#define pb push_back
#define mp make_pair
#define xx first
#define yy second
#define rep(i,a,b) for(int i=(a),i##_end_=(b);i<=i##_end_;i++)
#define dwn(i,a,b) for(int i=(a),i##_end_=(b);i>=i##_end_;i--)
using namespace std;
const int Size=1<<16;
char buffer[Size],*head,*tail;
inline char Getchar() {
    if(head==tail) {
        int l=fread(buffer,1,Size,stdin);
        tail=(head=buffer)+l;
    }
    if(head==tail) return -1;
    return *head++;
}
inline int read() {
    int x=0,f=1;char c=Getchar();
    for(;!isdigit(c);c=Getchar()) if(c=='-') f=-1;
    for(;isdigit(c);c=Getchar()) x=x*10+c-'0';
    return x*f;
}
typedef long long ll;
const int maxn=210;
const int mod=998244353;
int n,x[maxn],y[maxn],pw[maxn];
int check(int i,int j,int k) {
	return (x[k]-x[i])*(y[i]-y[j])==(y[k]-y[i])*(x[i]-x[j]);
}
int main() {
	n=read();
	rep(i,1,n) x[i]=read(),y[i]=read();
	pw[0]=1;
	rep(i,1,n) pw[i]=pw[i-1]*2%mod;
	int ans=pw[n];
	(ans+=mod-(n+1))%=mod;
	rep(i,1,n) rep(j,i+1,n) {
		int x=i,y=j,cnt=0;
		rep(k,1,n) if(check(i,j,k)) {
			cnt++;x=min(x,k);
			y=max(y,k);
		}
		if(x==i&&y==j) {
			(ans+=mod-pw[cnt])%=mod;
			(ans+=(cnt+1))%=mod;
		}
	}
	printf("%d\n",ans);
	return 0;
}


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


#include "boost/multiprecision/cpp_int.hpp"
#include "boost/multiprecision/cpp_dec_float.hpp"
namespace mp = boost::multiprecision;
typedef mp::cpp_int LL;
typedef mp::number<mp::cpp_dec_float<1024>> DD;// 仮数部が1024ビットの浮動小数点数型(TLEしたら小さくする)

 
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 rrep(i,r,l) for(ll i=r;i>=l;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-12;
#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,class S>
inline bool chmax(T &a, S b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}
template<class T,class S>
inline bool chmin(T &a, S b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
}

void mod_print(ll k){
    ll P=50000;
    rep(y,1,P){
        ll x=mod(y*k);
        
        if(abs(x)<=P||x+P>=i_7){
            if(x+P>=i_7){
                x-=i_7;
            }
            cout<<x<<"/"<<y<<endl;
            //cout<<setprecision(5)<<(dd)x/(dd)y;
            return;
        }
    }
    cout<<"nun"<<endl;
}
#define all(c) c.begin(),c.end()
typedef vector<ll> vl;
//////////////////////////



int main(){fastio
    string s,t;cin>>s>>t;
    ll ls=s.size(),lt=t.size();
    ll ans=inf;
    rep(i,0,ls-1){
        ll sum=0;
        rep(j,0,lt-1){
            if(i+j>=ls){
                sum=inf;break;
            }
            if(s[i+j]!=t[j])sum++;
        }
        chmin(ans,sum);
    }
    cout<<ans<<endl;
    
    return 0;
}


Measured memory_bytes: 3632
import java.io.*;
import java.util.*;

class Main {
	
	public static void main(String[] args) throws IOException {
		
		BufferedReader br = 
			new BufferedReader(new InputStreamReader(System.in));
		
		ArrayList<String> ans = new ArrayList<String>();
		
		while (true) {
			
			String out = "";
			String in = br.readLine();
			if (in == null) break;
			
			for (int i = 0; i < in.length(); i++) {
				if (in.charAt(i) == '@') {
					
					for (int j = 0; j < in.charAt(i + 1) - '0'; j++)
						out += String.valueOf(in.charAt(i + 2));
					i += 2;
				} else
					out += String.valueOf(in.charAt(i));
			}
			ans.add(out);
			
		}
		
		for (String a : ans)
			System.out.println(a);
		
	}
	
}

Measured memory_bytes: 9352
//#include <tourist>
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> p;
const int INF = 1e9;
const ll LINF = ll(1e18) + 1;
const int MOD = 1000000007;
const int dx[4] = {0, 1, 0, -1}, dy[4] = {-1, 0, 1, 0};
const int Dx[8] = {0, 1, 1, 1, 0, -1, -1, -1}, Dy[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl
#define rep(i, n) for (int i = 0; i < n; i++)
#define ALL(v) v.begin(), v.end()
#define debug(v)          \
    cout << #v << ":";    \
    for (auto x : v)      \
    {                     \
        cout << x << ' '; \
    }                     \
    cout << endl;
template <class T>
bool chmax(T &a, const T &b)
{
    if (a < b)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T &a, const T &b)
{
    if (b < a)
    {
        a = b;
        return 1;
    }
    return 0;
}
//setprecision(15)有効数字15桁
//-std=c++14
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
ll x,y;
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> x>>y;
    ll ans=y-x;
    if(ans<0){
        ans=LINF;
    }
    ll now=x;
    now*=-1;
    ll temp=y-now+1;
    if(temp>=0){
        chmin(ans,temp);
    }
    ll g=-y;
    temp = g - x+1;
    if (temp >= 0)
    {
        chmin(ans, temp);
    }
    temp = g - now+2;
    if (temp >= 0)
    {
        chmin(ans, temp);
    }
    cout << ans << "\n";
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <algorithm>
using namespace std;
void debug() {cout<<endl;}
template<typename T,typename... Args>
void debug(T x,Args... args) {cout<<x<<" ";debug(args...);}
#define forn(i,a,b) for(int i=a;i<b;++i)
#define pb push_back
#define F first
#define S second
#define endl "\n"
typedef long long ll;
typedef pair<int, int> pii;


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

string a, b;
cin >> a >> b;

a = a+b;
int n = stoi(a);
int x = sqrt(n);
if(x*x == n)cout << "Yes" << endl;
else cout << "No"<< endl;



}




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

void solve () {
    string s;
    cin >> s;
    int n = (int) s.size();
    string corr, corr2;
    for (int i = 0; i < n; i++) {
        corr += i % 2 ? '1' : '0';
        corr2 += i % 2 ? '0' : '1';
    }
    vector<int> ans(2);
    for (int i = 0; i < n; i++) {
        ans[0] += s[i] == corr[i] ? 1 : 0;
        ans[1] += s[i] == corr2[i] ? 1 : 0;
    }
    cout << min (ans[0], ans[1]);
}
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    solve();
    return 0;
}


Measured memory_bytes: 3900
import Control.Monad
import qualified Data.ByteString.Char8 as B
import Data.Maybe (fromJust)
import Data.Array.IO
import Data.Char

main :: IO ()
main = do
    [h, w] <- map (fst . fromJust . B.readInt) . B.words <$> B.getLine
    ary <- newArray ((0, 0), (w + 1, h + 1)) 0 :: IO (IOUArray (Int, Int) Int)
    forM_ [1..h] $ \j -> do
        forM_ [1..w] $ \i -> do
            c <- getChar
            when (c == '#') $ do
                modify ary (i - 1, j - 1)
                modify ary (i - 1, j)
                modify ary (i - 1 , j + 1)
                modify ary (i, j - 1)
                writeArray ary (i, j) 9
                modify ary (i, j + 1)
                modify ary (i + 1, j - 1)
                modify ary (i + 1, j)
                modify ary (i + 1, j + 1)
        getChar
    forM_ [1..h] $ \j -> do
        forM_ [1..w] $ \i -> do
            n <- readArray ary (i, j)
            putChar $ if n >= 9 then '#' else intToDigit n
        putChar '\n'
    where
        modify ary (i, j) = do
            n <- readArray ary (i, j)
            writeArray ary (i, j) (n + 1)


Measured memory_bytes: 1020
#include <iostream>
#include <cstdio>
#include <cctype>
using namespace std;


int main()
{
	char ch;

	while (true)
	{
		scanf("%c", &ch);

		if (ch == '\n') {
			break;
		}
		else if (islower(ch)) {
			printf("%c", toupper(ch));
		}
		else {
			printf("%c", tolower(ch));
		}
	}

	cout << endl;

    return 0;
}



Measured memory_bytes: 3148
def bfs(n,e,fordfs):
    #点の数、スタートの点、有向グラフ
    W = [-1]*n
    #各点の状態量、最短距離とか,見たかどうかとか
    W[e] = 0
    que = deque()
    que.append(e)
    len = [float("inf")]*n
    len[e] = 0
    while que:
        now = que.popleft()
        nowv = W[now]
        nowlen = len[now]
        for ne in fordfs[now]:
            if nowv == W[ne]:
                #ループが嫌な時
                return -1
            elif W[ne] == -1:
                W[ne] = (nowv+1) % 2
                len[ne] = nowlen+1
                que.append(ne)
    return len


def examB():
    N = I()
    v = [[]for _ in range(N)]
    for i in range(N):
        a = I()
        v[i].append(a-1)
    v[1]=[]
    b = bfs(N,0,v)
    if b==-1:
        ans = -1
    else:
        ans = b[1]
    if ans==float("inf"):
        ans = -1
    print(ans)

import sys
import copy
import bisect
import heapq
from collections import Counter,defaultdict,deque
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def S(): return sys.stdin.readline().strip()
mod = 10**9 + 7
inf = float('inf')

examB()


Measured memory_bytes: 56112
n = int(input())
P = list(map(int, input().split()))
ans = 0
for i in range(1, n-1):
    tmp_P = P[i-1:i+2]
    a = tmp_P[1]
    tmp_P.sort()
    if a == tmp_P[1]:
        ans += 1

print(ans)

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

template<typename T1,typename T2> void chmin(T1 &a,T2 b){if(a>b) a=b;};
template<typename T1,typename T2> void chmax(T1 &a,T2 b){if(a<b) a=b;};

const Int MAX = 114514;
Int dp[3][3][10][MAX];
signed main(){
  Int n;
  while(cin>>n,n){
    memset(dp,0,sizeof(dp));
    if(n&1){
      dp[1][1][1][1]=1;
      dp[0][0][0][1]=1;
      for(Int i=1;i<n;i++){
	for(Int j=0;j<2;j++){
	  for(Int k=0;k<2;k++){
	    for(Int l=0;l<=8;l++){
	      dp[j][0][l][i+1]+=dp[j][k][l][i];
	      if(!k) dp[j][1][l+1][i+1]+=dp[j][k][l][i];
	    }
	  }
	}
      }
      Int ans=0;
      for(Int j=0;j<2;j++)
	for(Int k=0;k<2;k++)
	  if(!j||!k) ans+=dp[j][k][8][n];
      for(Int i=1;i<=8;i++) ans*=i;
      cout<<ans<<endl;
    }else{      
      dp[1][1][1][1]=1;
      dp[2][2][1][1]=1;
      dp[0][0][0][1]=1;
      for(Int i=1;i<n/2;i++){
	for(Int j=0;j<3;j++){
	  for(Int k=0;k<3;k++){
	    for(Int l=0;l<=8;l++){
	      dp[j][0][l][i+1]+=dp[j][k][l][i];
	      for(Int nk=1;nk<3;nk++)
		if(k!=nk) dp[j][nk][l+1][i+1]+=dp[j][k][l][i];
	    }
	  }
	}
      }
      Int ans=0;
      for(Int j=0;j<3;j++)
	for(Int k=0;k<3;k++)
	  if(j+k!=3) ans+=dp[j][k][8][n/2];      
      for(Int i=1;i<=8;i++) ans*=i;
      cout<<ans<<endl;
    }
  }
  return 0;
}
 




Measured memory_bytes: 83612
# coding: utf-8
import math
import numpy as np
#N = int(input())
#A = list(map(int,input().split()))
x = int(input())
#x, y = map(int,input().split())
for i in range(1,10**5):
    if (i*x)%360==0:
        print(i)
        break

Measured memory_bytes: 27084
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<n; ++i)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
using namespace std;
using ll = int64_t;
using ld = long double;
using P = pair<int, int>;
using vs = vector<string>;
using vi = vector<int>;
using vvi = vector<vi>;
const int INF = 100010001;
const ll LINF = (ll)INF*INF*10;

const int mod = 1000000007;
//const int mod = 998244353;

struct mint {
    int64_t x;
    mint(int64_t 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(int64_t 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) {return mint(*this) /= a;}
};

istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, m;
    cin >> n >> m;
    vi a(n), b(m);
    rep(i, n) {
        cin >> a[i];
    }
    rep(j, m) {
        cin >> b[j];
    }

    sort(all(a));
    sort(all(b));
    bool x = true;
    if(a[0] < m or b[0] < n or a[n-1] != n*m or b[m-1] != n*m) x = false;
    rep(i, n-1) {
        if(a[i] == a[i+1]) x = false;
    }
    rep(j, m-1) {
        if(b[j] == b[j+1]) x = false;
    }

    if(!x) {
        cout << 0 << endl;
        return 0;
    }


    mint ans = 1;
    for(int i = n*m; i > 0; --i) {
        int aa = lower_bound(all(a), i) - a.begin();
        int bb = lower_bound(all(b), i) - b.begin();
        if(a[aa] == i and b[bb] == i) continue;
        if(a[aa] == i) {
            ans *= m-bb;
        } else if(b[bb] == i) {
            ans *= n-aa;
        } else {
            int num = n*m-i;
            int sq = (n-aa)*(m-bb);
            ans *= (sq-num);
        }
    }

    cout << ans << endl;
}

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

#define NS (25)

using namespace std;

template<typename _Tp> inline void IN(_Tp &dig)
{
	char c; bool flag = 0; dig = 0;
	while (c = getchar(), !isdigit(c)) if (c == '-') flag = 1;
	while (isdigit(c)) dig = dig * 10 + c - '0', c = getchar();
	if (flag) dig = -dig;
}

int n, m, C, B[NS], ans;

int main(int argc, char const* argv[])
{
	IN(n), IN(m), IN(C);
	for (int i = 1; i <= m; i += 1) IN(B[i]);
	for (int i = 1; i <= n; i += 1)
	{
		int tot = 0;
		for (int j = 1, a; j <= m; j += 1) IN(a), tot += a * B[j];
		if (tot + C > 0) ans++;
	}
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 256
fn main() {
    let mut buf = String::new();
    std::io::stdin().read_line(&mut buf).ok();
    let v:Vec<i32> = buf.trim().split_whitespace()
        .map(|e| e.parse().ok().unwrap()).collect();
    let (a,b) = (v[0],v[1]);
    println!("{}",if (a&1)^(b&1)!=0 {"IMPOSSIBLE".to_string()} else {((a+b)/2).to_string()});
}

Measured memory_bytes: 4352
#include "iostream"
#include "algorithm"
#include "string"
#include "vector"
#include "cmath"
#include "bitset"
#include "queue"
#include "functional"
#include "map"
#include "unordered_map"
#include "set"
#include "stack"
#include "tuple"

#define rep(n) for (int i = 0; i < n; ++i)
#define REP(n,i) for (int i = 0; i < n; ++i)
#define mod 1000000007
#define sp ' '
#define intmax 2147483647
#define llmax 9223372036854775807
#define nyan "(=^･ω･^=)"
#define mkp make_pair
#define mkt make_tuple
#define P pair<ll, ll>
#define iP pair<int,int>
typedef long long ll;
using namespace std;

int k;
bool g[100000] = {};
priority_queue<iP, vector<iP>, greater<iP>>q;

int main() {
	cin >> k;
	q.push(mkp(1, 1));
	while (q.top().second) {
		int qf = q.top().first, qs = q.top().second;
		q.pop();
		if (!g[qs]) {
			g[qs] = true;
			if (!g[(qs * 10) % k])
				q.push(mkp(qf, (qs * 10) % k));
			if (!g[(qs + 1) % k])
				q.push(mkp(qf + 1, (qs + 1) % k));
		}
	}
	cout << q.top().first << endl;
	return 0;
}

Measured memory_bytes: 1020
#include <bits/stdc++.h>
typedef long long ll;
#define pb push_back
using namespace std;
ll n;
const ll N = 1e5 + 10;
ll p[N];
const ll mod = 1e9 + 7;
ll ME(ll x,ll nn,ll M)
{
    ll result=1;
    while(nn>0)
    {
        if(nn % 2 ==1)
            result=(result * x)%M;
        x=(x*x)%M;
        nn=nn/2;
    }
    return result;
}
int main()
{
        ios_base::sync_with_stdio(false);
        cin.tie(NULL); cout.tie(NULL);
        cin >> n;
        p[1] = 1;
        ll ff=1LL;
        for(ll i=2;i<=n;i++) {
                p[i] = ME(i,mod-2,mod);
                ff = (ff * i)%mod;
                p[i] += p[i-1];
                p[i] %= mod;
        }
        ll ans = 0;
        for(ll i=1;i<=n;i++) {
                ll x;
                cin >> x;
                ll ret = 0;
                ret = (ret + p[i])%mod;
                ret = (ret + mod - 1 + p[n-i+1])%mod;
                ret %= mod;
                ret = (ret * x)%mod;
                ans = (ans + ret)%mod;
        }
        cout << (ans*ff)%mod << endl;
        return 0;
}


Measured memory_bytes: 1024