akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

int main() {
    int N, M;
    cin >> N >> M;
    vector<ll> H(N);
    for(int i = 0; i < N; i++){
        cin >> H.at(i);
    }
    vector<bool> C(N,true);
    for(int i = 0; i < M; i++){
        ll A, B;
        cin >> A >> B;
        if(H.at(A-1) < H.at(B-1)){
            C.at(A-1) = false;
        }else if(H.at(A-1) == H.at(B-1)){
            C.at(B-1) = false;
            C.at(A-1) = false;
        }
        else{
            C.at(B-1) = false;
        }
    }
    ll ans = 0;
    for(int i = 0; i < N; i++){
        if(C.at(i) == true) ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 3948
import java.io.IOException;

public class Main {

	public static void main(String[] args) {
		while (true) {
			int h = nextInt();
			if (h == 0) {
				break;
			}
			int w = nextInt();

			int cross = h * h + w * w;
			int[] min = new int[3];
			min[0] = Integer.MAX_VALUE;
			for (int height = 1; height <= 150; height++) {
				int width = (int) Math.ceil(Math.sqrt(cross - height * height));
				if (height == h
						|| (height * height + width * width == cross && height < h)) {
					width++;
				}

				if (height >= width) {
					break;
				}
				if (min[0] > height * height + width * width) {
					min[0] = height * height + width * width;
					min[1] = height;
					min[2] = width;
				}
			}
			System.out.println(min[1] + " " + min[2]);

		}

	}

	static int nextInt() {
		int c;
		try {
			c = System.in.read();
			while (c != '-' && (c < '0' || c > '9'))
				c = System.in.read();
			if (c == '-')
				return -nextInt();
			int res = 0;
			while (c >= '0' && c <= '9') {
				res = res * 10 + c - '0';
				c = System.in.read();
			}
			return res;
		} catch (IOException e) {
			e.printStackTrace();
		}
		return -1;
	}

}

Measured memory_bytes: 16856
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define pii pair<int,int>
#define mp make_pair
#define fi first
#define se second
#define eb emplace_back
using namespace std;
const int mod = 1e9 + 7;
const int maxn = 2e5 + 233;
int n;
struct seg_tree{
	int ch[maxn*4],val[maxn*4];
	void push_down(int l,int r,int cur){
		int mid = (l+r)>>1,lc = cur<<1,rc = lc|1;
		val[lc] += val[cur];
		val[rc] += val[cur];
		val[cur] = 0;
		ch[cur]=min(ch[lc]-val[lc],ch[rc]-val[rc]);
		return ;
	}
	void sub(int l,int r,int cur,int x,int y){
		if(x<=l&&r<=y){
			val[cur]++;
			return ;
		}
		if(r<x||l>y)return ;
		int mid=(l+r)>>1,lc=cur<<1,rc=lc|1;
		if(val[cur])push_down(l,r,cur);
		sub(l,mid,lc,x,y);
		sub(mid+1,r,rc,x,y);
		ch[cur]=min(ch[lc]-val[lc],ch[rc]-val[rc]);
		return ; 
	}
	int query(int l,int r,int cur,int x,int y){
		if(x<=l&&r<=y)return ch[cur]-val[cur];
		if(r<x||l>y)return 1e9;
		int mid=(l+r)>>1,lc=cur<<1,rc=lc|1;
		if(val[cur])push_down(l,r,cur);
		return min(query(l,mid,lc,x,y),query(mid+1,r,rc,x,y));
	}
	void build(int l,int r,int cur){
		if(l==r){
			ch[cur] = l;
			val[cur] = 0;
			return;
		}
		int mid=(l+r)>>1,lc=cur<<1,rc=lc|1;
		build(l,mid,lc);
		build(mid+1,r,rc);
		ch[cur] = min(ch[lc],ch[rc]);
		val[cur] = 0;
	}
}L,R;
struct camel{
	int l,r,k,v;
}a[maxn];
bool cmp(const camel &a,const camel &b){
	return a.v>b.v; 
}
int main()
{
	int T;cin>>T;
	while(T--){
		ll ans = 0;
		cin>>n;
		L.build(1,n,1);
		R.build(1,n,1);
		for(int i=1;i<=n;i++)
			scanf("%d%d%d",&a[i].k,&a[i].l,&a[i].r),
			a[i].v = max(a[i].l,a[i].r)-min(a[i].l,a[i].r);
		sort(a+1,a+1+n,cmp);
		for(int i=1;i<=n;i++){
			if(a[i].l>=a[i].r){
				int k = a[i].k;
				if(L.query(1,n,1,k,n)>0){
					L.sub(1,n,1,k,n);
					ans += a[i].l;
				}
				else ans += a[i].r;
			}
			else{
				int k = n-a[i].k;
				if(k>0&&R.query(1,n,1,k,n)>0){
					R.sub(1,n,1,k,n);
					ans += a[i].r;
				}
				else ans += a[i].l;
			}
		}
		cout << ans << endl;
	}
	return 0;
}


Measured memory_bytes: 15036
import java.util.*;
 
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        try {
            String line;
            /* input */
            while(true){
                int n = sc.nextInt();
                if(n==0) return;
                
                int[] nums = new int[n];
                int total = 0;
                for(int i=0;i<n;i++){
                	nums[i] = sc.nextInt();
                	total += nums[i];
                }
                
                int sum, index = 0, diff = 0, min = total;
                
                while(index<Math.pow(2, n)){
                	sum = 0;
                	for(int i=0;i<n;i++){
                		if((1 << i&index)>0) sum += nums[i];
                	}
                	diff = Math.abs(total - 2*sum); 
                	if(diff<=1){
                		min = diff;
                		break;
                	}
                	if(diff<min) min = diff;
                	index = index + 1;
                }
                
                System.out.println(min);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

Measured memory_bytes: 19056
N, M = gets.split.map(&:to_i)
X = gets.split.map(&:to_i).sort!

if N >= M
  puts 0
else
  d = []
  1.step(M-1) {|i| d << X[i] - X[i-1] }
  d.sort!.pop(N-1)
  puts d.inject(:+)
end


Measured memory_bytes: 9968
#include <bits/stdc++.h>
using namespace std;
using pii=pair<int,int>;

#define fi first
#define se second
#define pb push_back
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define H_MAX 50
#define W_MAX 50

int dx[4]={0,1,0,-1};
int dy[4]={1,0,-1,0};
int H,W;

namespace patch {
  template < typename T > std::string to_string( const T& n )
  {
    std::ostringstream stm ;
    stm << n ;
    return stm.str() ;
  }
}

int main() {
  int n;
  cin >> n;
  int a;
  // 105, 135, 189, 165, 195
  if (n < 105) 
    a = 0;
  else if(n < 135)
    a = 1;
  else if(n < 165)
    a = 2;
  else if(n < 189)
    a = 3;
  else if(n < 195)
    a = 4;
  else 
    a = 5;
  cout << a << endl;

  return 0;
}
 


Measured memory_bytes: 256
using System;

public class Hello{
    public static void Main(){
        var times = int.Parse(Console.ReadLine());
        var input = Console.ReadLine().Split(' ');
        var result = "APPROVED";
        
        for(var i = 0;i < times;i++){
            if(int.Parse(input[i]) % 2 == 0){
                if(int.Parse(input[i]) % 3 == 0 || int.Parse(input[i]) % 5 == 0){
                    result = "APPROVED";
                }else{
                    result = "DENIED";
                    break;
                }
            }
        }
        Console.WriteLine(result);
    }
}

Measured memory_bytes: 11092
/*input
4
0
0
0
0
*/
// C++ program to count the Minimum number of 
// increasing subsequences 
//taken from geeks for geeks;
#include <bits/stdc++.h> 
using namespace std; 

int MinimumNumIncreasingSubsequences(int arr[], int n) 
{ 
	multiset<int> last; 

	// last element in each increasing subsequence 
	// found so far 
	for (int i = 0; i < n; i++) { 

		// here our current element is arr[i] 
		multiset<int>::iterator it = last.lower_bound(arr[i]); 

		// iterator to the first element larger 
		// than or equal to arr[i] 
		if (it == last.begin()) 

			// if all the elements in last larger 
			// than or to arr[i] then insert it into last 
			last.insert(arr[i]); 

		else { 
			it--; 

			// the largest element smaller than arr[i] is the number 
			// before *it which is it-- 
			last.erase(it); // erase the largest element smaller than arr[i] 
			last.insert(arr[i]); // and replace it with arr[i] 
		} 
	} 
	return last.size(); // our answer is the size of last 
} 
int main() 
{ 
	int n;
	cin >> n;
	int arr[n];
	for(int i = 0; i < n; i++) cin >> arr[i];
//	int arr[] = { 8, 4, 1, 2, 9 }; 
//	int n = sizeof(arr) / sizeof(int); 
//	cout << "Minimum number of increasing subsequences are : "
	cout	<< MinimumNumIncreasingSubsequences(arr, n) << '\n'; 
	return 0; 
} 


Measured memory_bytes: 5376
w = input()
d = dict()
ans = 'Yes'
for i in w:
    if d.get(i) is None:
        d[i] = 1
    else:
        d[i] += 1
for i in d.values():
    if i % 2 == 1:
        ans = 'No'
        break
print(ans)

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

signed main() {
  string s;cin>>s;
  bool ok = true;
  for(int i=0;i<s.size();++i){
    if (i%2==0){
      string t = "RUD";
      bool ok2 = false;
      for(int j=0;j<3;++j){
        ok2 |= s[i] == t[j];
      }
      ok &= ok2;
    }else{
      string t = "LUD";
      bool ok2 = false;
      for(int j=0;j<3;++j){
        ok2 |= s[i] == t[j];
      }
      ok &= ok2;      
    }

  }
  cout<<(ok?"Yes":"No")<<endl;
  return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <vector>
#include <algorithm>
 
using namespace std;
 
const long long MAX_N = 100000;
long long N;
vector<long long> Counter(MAX_N + 1, 0);
 
int main() {
  scanf("%lld", &N);
  long long ai;
  for (int i = 0; i < N; ++i) {
    scanf("%lld", &ai);
    if (ai == 0) {
      ++Counter[0];
      ++Counter[1];
    } else {
      for (int j = -1; j < 2; ++j) {
        ++Counter[ai + j];
      }
    }
  }
  vector<long long>::iterator iter = max_element(Counter.begin(),
                                                 Counter.end());
  long long answer = distance(Counter.begin(), iter);
  printf("%lld\n", Counter[answer]);
}

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

using namespace std;

int main(){
  string T;
  T.reserve(200000);
  cin >> T;
  string O="";
  O.reserve(200000);
  int N =T.length();
  if(T[0]=='P'){
    O += "P";
  }else if(T[0]=='D'){
    O += "D";
  }else{
    O += "D";
  }
  for(int i=1;i<N;i++){
    if(T[i]=='P'){
      O += "P";
    }else if(T[i]=='D'){
      O += "D";
    }else{
        O += "D";
    }
  }
  cout << O;
  return 0;
}


Measured memory_bytes: 3788
N=int(input())
flag=1 if N>=0 else 0
newN=abs(N)
M=0
A=bin(newN)[2:]
#print('N:',N)
#print('newN:',newN)
#print('M:',M)
#print('A:',A)
for i in range(len(A)):
	position=-(i*2+flag+1)
	if position < -len(A):
		break
	else:
		#print('A[{}]={}'.format(position,A[position]))
		if A[position]=='1':
			M+=2**(position*(-1)-1)
			newN+=2**(position*(-1)-1)
			A=bin(newN)[2:]
			#print('N:',A)
			#print('M:',bin(M)[2:])
print(bin(newN|M)[2:])

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
int main(){
    int a,b,c;
    cin>>a>>b>>c;
    int x=a+b;
    int y=a+c;
    int z=b+c;
    if(x<y&&x<z){cout<<x<<endl;}
    else if(y<x&&y<z){cout<<y<<endl;}
    else{cout<<z<<endl;}
    return 0;}

Measured memory_bytes: 256
#include<iostream>
#include <numeric>
#include<algorithm>
#include<math.h>
#include<vector>
int main(){
    int n=0;
    double mean=0;
    std::cin>>n;
    std::vector<int> v(n);
    for(int i=0;i<n;i++){std::cin>>v[i];mean+=v[i];}
    std::vector<double> d(n);
    for(int i=0;i<n;i++)d[i]=fabs(v[i]*n-mean);
    int ans=0;
    for(int i=0;i<n;i++){
    if(d[i]<d[ans])ans=i;
    }


    std::cout<<ans<<std::endl;
//    for (int i=0;i<n;i++)std::cout<<d[i]<<" "<<ans<<std::endl;
    return 0;
    }


Measured memory_bytes: 256
#include<cstdio>
#include<iostream>
using namespace std;
long long maxx(long long a,long long b,long long c)
{
	if(a>=b&&a>=c) return a;
	if(b>=a&&b>=c) return b;
	if(c>=a&&c>=b) return c;
}
int main()
{
	long long A,B,C,maxs;
	cin>>A>>B>>C;
	maxs=maxx(A,B,C);
	if(A%2==0||B%2==0||C%2==0) cout<<"0"<<endl;
	else
	{
		if(A==maxs) cout<<B*C<<endl;
		else if(B==maxs) cout<<A*C<<endl;
		else cout<<A*B<<endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define double long double
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,n) for(int i=1;i<=(n);i++)
#define mod (ll)(1e9+7)
#define inf (ll)(3e18+7)
#define P pair<int,int>
#define PiP pair<int,pair<int,int>>
#define all(x) x.begin(),x.end()
using namespace std;

int main() {
  int n, m, X, Y;
  cin >> n >> m >> X >> Y;
  vector<int> x(n), y(m);
  rep(i, n)cin >> x.at(i);
  rep(i, m)cin >> y.at(i);
  int xmax = *max_element(all(x)), ymin = *min_element(all(y));
  bool ans = false;
  for(int i = X+1; i <= Y; i++){
    if(xmax < i && i <= ymin)ans=true;
  }
  if(ans)cout << "No War";
  else cout << "War";
}

Measured memory_bytes: 256
#include <stdio.h>

int face[7][7][4] = {
{{0},{0},{0},{0},{0},{0},{0}},
{{0},{0},{0,1,2,3},{0,1,3,5},{0,1,4,2},{0,1,5,4},{0}},
{{0},{0,2,1,4},{0},{0,2,3,1},{0,2,4,6},{0},{0,2,6,3}},
{{0},{0,3,1,2},{0,3,2,6},{0},{0},{0,3,5,1},{0,3,6,5}},
{{0},{0,4,1,5},{0,4,2,1},{0},{0},{0,4,5,6},{0,4,6,2}},
{{0},{0,5,1,3},{0},{0,5,3,6},{0,5,4,1},{0},{0,5,6,4}},
{{0},{0},{0,6,2,4},{0,6,3,2},{0,6,4,5},{0,6,5,3},{0}}};
int assign[7];

int main()
{
	int q, i, t, f;

	for (i = 1; i <= 6; i++) scanf("%d", assign+i);
	scanf("%d", &q);
	while (q--) {
		scanf("%d%d", &t, &f);
		for (i = 1; i <= 6; i++) {
			if (assign[i] == t) t = i;
			if (assign[i] == f) f = i;
		}
		printf("%d\n", assign[face[t][f][3]]);
	}
	return 0;
}



Measured memory_bytes: 2048
#include<stdio.h>
typedef struct{
  int pt;
  int le;
  int ri;
} Tree;
Tree tree[1000000];
#define NIL -1
int main()
{
  int i,id,j,n,k,d[100000],depth=0,num;

  scanf("%d",&n);

  for(i=0;i<n;i++){
    tree[i].pt=NIL;
    tree[i].le=NIL;
    tree[i].ri=NIL;
  }

  for(i=0;i<n;i++){
    scanf("%d%d",&id,&k);
    for(j=0;j<k;j++){
      scanf("%d",&d[j]);
      if(j==0){ tree[d[0]].pt=id; tree[id].le=d[0]; }
      else{ tree[d[j]].pt=id; tree[d[j-1]].ri=d[j]; }
    }
  }
  
  for(i=0;i<n;i++){
    printf("node %d: parent = %d, ",i,tree[i].pt);
    num=i;
    while(tree[num].pt!=NIL){ depth++; num=tree[num].pt; }
    printf("depth = %d,",depth);
    depth=0;
    if(tree[i].pt==NIL && tree[i].le==NIL){ printf(" root, []\n"); }
    else if(tree[i].pt==NIL && tree[i].le!=NIL){
      printf(" root, [%d",tree[i].le);
      for(j=tree[tree[i].le].ri;j!=NIL;j=tree[j].ri){
        printf(", %d",j);
      }
      printf("]\n");
    }
    
    else if(tree[i].le!=NIL){
      printf(" internal node, [%d",tree[i].le);
      for(j=tree[tree[i].le].ri;j!=NIL;j=tree[j].ri){
        printf(", %d",j);
      }
      printf("]\n");
    }
    
    else{ printf(" leaf, []\n"); }
    
  }
  return 0;
}



Measured memory_bytes: 3260
def main():
    s = list(input())
    count = 0

    if s[0] == 'A':
        for i in range(2, len(s)-1):
            if s[i] == 'C':
                count += 1
        if (count != 1):
            return 'WA'
        count = 0
        for i in range(len(s)):
            if s[i].isupper():
                count += 1
        if count > 2:
            return 'WA'
    else:
        return 'WA'

    return 'AC'
    


if __name__=='__main__':
    print(main())

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

int main() {
	int a, b, c, d;
	scanf("%d%d%d%d", &a, &b, &c, &d);
	if(a*b>c*d) printf("%d\n", a*b); else printf("%d\n", c*d);
	return 0;
}

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

int costs[1000];
int bits[1000];

const long INF = 1LL << 29;
long dp[1 << 12];

int main() {
    int N, M;
    cin >> N >> M;
    for (int i = 0; i < M; i++) {
        int b;
        cin >> costs[i] >> b;
        int k = 0;
        bits[i] = 0;
        for (int j = 0; j < b; j++) {
            cin >> k;
            k--;
            bits[i] |= (1 << k);
        }
    }
    for (int j = 0; j < (1 << 12); j++) {
        dp[j] = INF;
    }
    dp[0] = 0;
    for (int i = 0; i < M; i++) {
        for (int j = 0; j < (1 << N); j++) {
            dp[j | bits[i]] = min(dp[j | bits[i]], dp[j] + costs[i]);
        }
    }
    if (dp[(1 << N) - 1] < INF) {
        cout << dp[(1 << N) - 1] << endl;
    } else {
        cout << "-1" << endl;
    }
}

Measured memory_bytes: 256
K = int(input())
ls = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
print(ls[K-1])

Measured memory_bytes: 3316
# solution

data = int(input())
array = list(map(int, input().split()))

t = [0] * data
t[0] = sum(array[::2]) - sum(array[1::2])
for i in range(1, data):
    t[i] = 2 * array[i - 1] - t[i - 1]
print(*list(map(str, t)))


Measured memory_bytes: 20124
#include <bits/stdc++.h>
using namespace std;
using Int = long long;
int PREP = (cin.tie(nullptr), ios::sync_with_stdio(false), cout << fixed << setprecision(9), 0);
//int SEGV = getenv("D") || (exit(system("D= SEGFAULT_SIGNALS=all catchsegv ./prog.exe") >> 8), 0);
int main() {
    int N; cin >> N;
    vector<Int> A(N); for (auto &a : A) cin >> a;
    Int stock = 0, money = 1000;
    for (int i = 0; i < N; i++) {
        if (i == N - 1 || A[i] > A[i + 1]) {
            money += stock * A[i];
            stock = 0;
        } else {
            Int t = money / A[i];
            money -= A[i] * t;
            stock += t;
        }
    }
    cout << money << endl;
    return 0;
}


Measured memory_bytes: 3648
#include <iostream>
#include <cmath>
#include <iomanip>
#include <limits>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
int MAX = 1000000007;

int main() {
    int n;
    cin >> n;
    int a[n];
    for(int i=0;i<n;i++) cin >> a[i];
    int cnt[10][1000] = {0};
    int Max[1000] = {0};

    for(int i=0;i<n;i++){
        while(a[i]>1){
            for(int j=2;j<1000;j++){
                if(a[i] % j == 0){
                    a[i] /= j;
                    cnt[i][j]++;
                    break;
                }
            }
        }
        for(int j=2;j<1000;j++){
            Max[j] = max(Max[j],cnt[i][j]);
        }
    }
    int ans=1;
    for(int j=2;j<1000;j++){
        if(Max[j] > 0){
            for(int k=0;k<Max[j];k++) ans *= j;
        }
    }
    cout << ans << endl;
}



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

#define trav(a, A) for (auto & a : A)
#define f first
#define s second

typedef long long ll;

ll MOD = 1e+9+7;
const ll INFLL = 0x3f3f3f3f3f3f3f3f;
const int INF = 0x3f3f3f3f;
const ll MAXN = 1e+5+7;

int main ()
{
	ios_base::sync_with_stdio (0);
	cin.tie (0);
	ll i, j, n;
	string s;
	cin >> s;
	if (s.back () == 's') s += "es";
	else s += 's';
	cout << s << '\n';

	return 0;
}



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

using namespace std;

int main()
{
  long long X,Y;
  cin>> X>> Y;

  int ret=0;
  long long now=X;
  while(now<=Y)
  {
    now*=2;
    ret++;
  }
  cout<< ret<< endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,a,b) for(ll i=ll(a);i<ll(b);i++)
#define irep(i,a,b) for(ll i=ll(a);i>=ll(b);i--)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
#define pb push_back
#define mp make_pair
#define F .first
#define S .second 
using ll=long long;
using ld=long double;
const ll INF = 1LL<<60;
const ll mod=1e9+7;
using namespace std;
ll GCD(ll a, ll b) { return b ? GCD(b, a%b) : a; }


int main(){
    ll n,k,ans=0;
    cin>>n;
    k=n%10;
    if(n%10==3)cout<<"bon";
    else if(k==0||k==1||k==6||k==8)cout<<"pon";
    else cout<<"hon";
}

Measured memory_bytes: 3624
#include <iostream>
#include <iomanip>
#include <vector>
#include <map>
#include <unordered_map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <math.h>
#include <sstream>
#include <numeric>
#include <string>
#include <cassert>
#include <bitset>

using namespace std;
typedef long long ll;

int main() {
  int A, B;
  cin >> A >> B;
  if (A <= 9 and B <= 9) {
    cout << A * B << endl;
  } else {
    cout << -1 << endl;
  }
  return 0;
}


Measured memory_bytes: 256
import java.util.*;
import java.lang.*;

class Main{
    public static void main(String args[]){
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.nextLine());
        String[] line = sc.nextLine().split(" ");
        int[] data =new int[n];
        for(int i=0; i < n; i++){
            data[i] = Integer.parseInt(line[i]);
        }

        int q = Integer.parseInt(sc.nextLine());
        String[] line2 = sc.nextLine().split(" ");
        int[] searcher = new int[q];
        for(int i=0; i < q; i++){
            searcher[i] = Integer.parseInt(line2[i]);
        }

        int result = 0;
        for(int i = 0; i < q; i++){
            for(int j = 0; j < n; j++){
                if(searcher[i] == data[j]){
                    result++;
                    break;
                }
            }
        }
        System.out.println(result);
        



    }
    static void bubble(int[] arr, int n){

    }
    static void selection(int[] arr, int n){

    }
    static void insertionSort(int[] arr, int n, int g,int count){
        for(int i = g; i < n; i++){
            int v = arr[i];
            int j = i - g;
            while(j >= 0 && arr[j] > arr[i]){
                arr[i] = arr[j];
                j-=g;
                count++;
            }
            arr[j + g] = v;
        }
    }
    static void shellsort(int[] arr, int n){

        for(int i = 1; ; ){
            if(i > n){
                break;
            }

            i = (i * 3) + 1;
        }
    }
}
class Struct{
    String name;
    int time;
    public Struct(String n, int t){
        name = n;
        time = t;
    }
}

Measured memory_bytes: 29968
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; ++i)
using namespace std;
#define int long long
#define double long double
 
int gcd(int x, int y){
    if (y == 0)
        return x;
    x = x % y;
    gcd(y, x);
}
 
int check(int i,int ans){
    if(i<2) return ans;
    ans=i*check(i-2,ans);
}
main(){
    int n;
    string s;
    cin>>n>>s;
    int count=0;
    rep(i,n-2){
        if(s[i]=='A'&&s[i+1]=='B'&&s[i+2]=='C') count++;
    }
    cout<<count<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define fo(i,n) for(int i=0;i<n;++i)
#define fos(j,i,n) for(int j=i;j<n;++j)
#define N 100004
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define M 1000000007
#define ll long long
#define abs(x) (x<0?(-x):x)
#define dis(k) cout << k << endl
#define forr(i,n) for(int i= n-1;i>=0;--i)
#define min(x,y) (x<y?x:y)
#define max(x,y) (x>y?x:y)
#define dbg(vari) cerr<<#vari<<" = "<<(vari)<<endl;
 
int main(){
	fast;
	int t;
	t=1;
	//cin >> t;
	while(t--){
		ll int h;
		cin >> h;
		h=log2(h);
		h=pow(2,h);
		dis(h+(h-1));
	}
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
struct Fast {Fast(){std::cin.tie(0);ios::sync_with_stdio(false);cout.precision(20);}} fast;

/* define */
#define FOR(I,X,Y) for(long long (I)=(X);(I)<(Y);(I)++)
#define REP(I,X,Y) for(long long (I)=(Y)-1;(I)>=(X);(I)--)
#define ALL(X) (X).begin(),(X).end()
#define pb push_back
#define COUNT(V,X) (upper_bound((V).begin(),(V).end(),X)-lower_bound((V).begin(),(V).end(),X))
#define debug(x) cerr<<#x<<':'<<x<<endl;
#define DEBUG(v) cerr<<#v<<':';for(auto xXx:v)cerr<<xXx<<' ';cerr<<endl;
#define Yes(X) if(X){cout<<"Yes"<<endl;}else{cout<<"No"<<endl;}
#define YES(X) if(X){cout<<"YES"<<endl;}else{cout<<"NO"<<endl;}
#define ctoi(C) (C-'0')
#define pow2(x) ((long long)((long long)1<<x))


/* alias */
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vii = vector<vector<int>>;
using vl = vector<long long>;
using vll = vector<vector<long long>>;
using pi = pair<int,int>;
using pl = pair<long long,long long>;
template<typename T> using PQ = priority_queue<T>;
template<typename T> using minPQ = priority_queue<T, vector<T>, greater<T>>;

/* const */
const long long dx[] = {1,0,-1,0};
const long long dy[] = {0,1,0,-1};
const long long dx8[] = {1,1,0,-1,-1,-1,0,1};
const long long dy8[] = {0,1,1,1,0,-1,-1,-1};
const long long dx9[] = {1,1,0,-1,-1,-1,0,1,0};
const long long dy9[] = {0,1,1,1,0,-1,-1,-1,0};
const int INF = 1000000007;
const long long LINF = 1000000000000000007;

/* func */
template <typename T> inline bool chmin(T& a, const T& b) {if (a > b) a = b; return a > b;}
template <typename T> inline bool chmax(T& a, const T& b) {if (a < b) a = b; return a < b;}
long long max(long long x,int y){return max(x,(long long)y);}
long long max(int x,long long y){return max((long long)x,y);}
long long min(long long x,int y){return min(x,(long long)y);}
long long min(int x,long long y){return min((long long)x,y);}

/* liblary */



/* main */

signed main(){
	ll N,K;
	cin >> N >> K;
	vl A(N);
	FOR(i,0,N)cin >> A[i];
	ll ans = 0;
	ll counter[60] = {0};
	FOR(i,0,N){
		FOR(j,0,60){
			if(A[i]&pow2(j)){
				counter[j]++;
			}
		}
	}
	REP(i,0,60){
		if(pow2(i) > K){
			ans += counter[i] * pow2(i);
		}
		else{
			if(N-counter[i] > counter[i]){
				ans += (N - counter[i]) * pow2(i);
				K -= (ll)((ll)1 << i);
			}
			else{
				ans += counter[i] * pow2(i);
			}
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 1024
#include "bits/stdc++.h"
    //#include<iostream>
    using namespace std;
    #define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
    #define ll long long int
    #define int ll
    //#define slld(t) scanf("%lld",&t)
    //#define sd(t) scanf("%d",&t)
    //#define pd(t) printf("%d\n",t)
    //#define plld(t) printf("%lld\n",t)
    #define vec vector < int >
    #define vecp vector < pair < int , int > >
    #define ff first
    #define ss second
    #define pb push_back
    #define mp make_pair
    #define debug(x)   cerr<<#x<<": "<<x<<endl
    #define pii pair < int , int >
    #define pll pair < ll , ll > 
    #define fr(i , a , b) for(int  i = a ; i <= b ; i++)
    #define all(v) v.begin() , v.end()
    #define mod  1000000007
    #define N 100005
    #define mod1 1000000007
    #define mod2 1000000009
    #define bitcnt __builtin_popcount
    #define PI acos(-1)
    //#define endl "\n" 
    #define mid  (s+e)/2
    #define MAX 10000007
    //const int inf = (int)1e18 + 10;;
    int dpa[N] , dpb[N] , dpc[N];
    int a[N] , b[N] , c[N];
    signed main(){
      fast;
      
      //freopen("input.txt" , "r" , stdin);
      //freopen("output.txt" , "w" , stdout);
      
     
        int n ;
        cin >> n ;
        for(int i = 0 ; i < n ; i++)
              cin >> a[i] >> b[i] >> c[i];
     
     
     
        dpa[0] = a[0];
        dpb[0] = b[0];
        dpc[0] = c[0];
        for(int i = 1 ; i <n ; i++){
               dpa[i] = max(dpb[i-1]  , dpc[i-1]) + a[i];
               dpb[i] = max(dpc[i-1]  , dpa[i-1]) + b[i];
               dpc[i] = max(dpa[i-1]  , dpb[i-1]) + c[i];
               
        }
     
        cout << max(dpa[n-1] , max(dpb[n-1] , dpc[n-1])) << endl;
     
       
     
     }

Measured memory_bytes: 4992
#include <bits/stdc++.h>
#include <map>
#include <set>
#include <vector>
#include <algorithm>
#include <iostream>
#include <bitset>
#include <cassert>
#include <queue>
#include <stack>
#include <iomanip>
#include <math.h>
#include <time.h>
using namespace std;
#define rep(i, n) for (ll i = 0; i < (ll)n; i++)
#define repf(i, a, b) for (ll i = (ll)a; i < (ll)b; i++)
#define repr(i, a, b) for (ll i = (ll)a; i > (ll)b; i--)
#define all(v) (v).begin(), (v).end()
#define mp(a, b) make_pair(a, b)
#define pb(x) push_back(x)
#define eb(x) emplace_back(x)
#define F first
#define S second
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ld, ld> pdd;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<int> vii;
typedef vector<vii> vvii;
const ll mod = 1e9 + 7;
const int infi = 1147483600;
const ll infl = 1e18 + 5;
const char ENDL = '\n';
//cout << fixed << setprecision(17) << res << endl;
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n;
    cin >> n;
    vii a(n), b(n);
    rep(i, n) cin >> a[i];
    multiset<pii> que;
    rep(i,n){
        cin >> b[i];
        if (a[i]!=b[i])
        que.insert(mp(b[i], i));
    }
    ll cnt = 0;
    while (!(que.empty())){
        auto itr = que.end();
        itr--;
        int idx = (*itr).S;
        que.erase(itr);
        if (a[idx]==b[idx]){
            continue;
        }
        ll d = b[(idx + n - 1) % n] + b[(idx + 1) % n];
        if ((b[idx]-a[idx])%d==0){
            cnt += (b[idx] - a[idx]) / d;
            b[idx] = a[idx];
            continue;
        }
        if (b[idx]<=d){
            cout << -1 << ENDL;
            return 0;
        }
        cnt += b[idx] / d;
        b[idx] %= d;
        if (b[idx]<a[idx]){
            cout << -1 << ENDL;
            return 0;
        }
        que.insert(mp(b[idx], idx));
    }
    cout << cnt << ENDL;
}


Measured memory_bytes: 11264
import java.util.Scanner;

//Numeral System
public class Main{

	static int f(char[] s){
		int r = 0;
		int x = 1;
		for(int i=0;i<s.length;i++){
			if(Character.isDigit(s[i]))x = s[i]-'0';
			else {
				switch(s[i]){
				case 'm': r+=x*1000;break;
				case 'c': r+=x*100;break;
				case 'x': r+=x*10;break;
				case 'i': r+=x;
				}
				x = 1;
			}
		}
		return r;
	}

	static String g(int r){
		String s = "";
		if(r/1000>0){
			if(r/1000>1)s+=r/1000;
			s+='m';
		}
		r%=1000;
		if(r/100>0){
			if(r/100>1)s+=r/100;
			s+='c';
		}
		r%=100;
		if(r/10>0){
			if(r/10>1)s+=r/10;
			s+='x';
		}
		r%=10;
		if(r>=2)s+=r+"i";
		else if(r==1)s+='i';
		return s;
	}
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int t = sc.nextInt();
		while(t--!=0){
			System.out.println(g(f(sc.next().toCharArray()) + f(sc.next().toCharArray())));
		}
	}
}

Measured memory_bytes: 13000
N, K = map(int, input().split())
xs = list(map(int, input().split()))

ts = [float('inf')] * (N-K+1)

for i in range(N-K+1):
  r = xs[i+K-1]
  l = xs[i]  
  ts[i] = (r - l) + min(abs(r-0), abs(l-0))  

print(min(ts))


Measured memory_bytes: 14224
// 3340382
#include <iostream>
#include <vector>
#include <algorithm>
#include <tuple>
using namespace std;

long long N, X[1009], Y[1009], H[1009]; vector<tuple<long long, long long, long long>>vec;

int main() {
	cin >> N; tuple<long long, long long, long long>G = make_tuple(-1, -1, -1);
	for (int i = 1; i <= N; i++) {
		cin >> X[i] >> Y[i] >> H[i];
		if (H[i] >= 1 && get<0>(G) == -1) G = make_tuple(X[i], Y[i], H[i]); // updatehere
	}
	for (int i = 0; i <= 100; i++) {
		for (int j = 0; j <= 100; j++) {
			long long V = get<2>(G) + abs(get<0>(G) - i) + abs(get<1>(G) - j); V = max(V, 0LL); bool flag = true;
			for (int k = 1; k <= N; k++) {
				long long VV = V - abs(X[k] - i) - abs(Y[k] - j); VV = max(VV, 0LL);
				if (H[k] != VV) flag = false;
			}
			if (flag == true) vec.push_back(make_tuple(i, j, V));
		}
	}
	if (vec.size() == 1) {
		cout << get<0>(vec[0]) << " " << get<1>(vec[0]) << " " << get<2>(vec[0]) << endl;
	}
	return 0;
}

Measured memory_bytes: 256
n,m=map(int,input().split())
d=[[float('inf') for i in range(n)] for i in range(n)]
r=[list(map(int,input().split())) for i in range(m)]

def wf(d):
    for k in range(n):
        for i in range(n):
            for j in range(n):
                d[i][j]=min(d[i][j],d[i][k]+d[k][j])
    return d


for u,v,c in r:
    u,v=u-1,v-1
    d[u][v]=d[v][u]=c

wf(d)

cnt=0
for u,v,c in r:
    u,v=u-1,v-1
    if d[u][v]!=c:
        cnt+=1
print(cnt)

Measured memory_bytes: 3700
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<algorithm>
#include<string>
#include<map>
#include<vector>
#include<set>
#include<iomanip>
#define FAST ios::sync_with_stdio(false)
typedef long long ll;
const int inf = 0x3f3f3f3f;
const int mod = (int)1e9 + 9;
const int maxn = (int)1e5 + 5;
using namespace std;

int a[105];

int main()
{
	FAST;
	int n, x;
	cin >> n >> x;
	for(int i = 0; i < n; i++){
		cin >> a[i];
		x -= a[i];
	}
	sort(a, a + n);
	int ans = n;
	ans += (x / a[0]);
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include<cmath>
#include<math.h>
#include<ctype.h>
#include<algorithm>
#include<bitset>
#include<cassert>
#include<cctype>
#include<cerrno>
#include<cfloat>
#include<ciso646>
#include<climits>
#include<clocale>
#include<complex>
#include<csetjmp>
#include<csignal>
#include<cstdarg>
#include<cstddef>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<ctime>
#include<cwchar>
#include<cwctype>
#include<deque>
#include<exception>
#include<fstream>
#include<functional>
#include<iomanip>
#include<ios>
#include<iosfwd>
#include<iostream>
#include<istream>
#include<iterator>
#include<limits>
#include<list>
#include<locale>
#include<map>
#include<memory>
#include<new>
#include<numeric>
#include<ostream>
#include<queue>
#include<set>
#include<sstream>
#include<stack>
#include<stdexcept>
#include<streambuf>
#include<string>
#include<typeinfo>
#include<utility>
#include<valarray>
#include<vector>
#include<string.h>
#include<stdlib.h>
#include<stdio.h>
using namespace std;
int n,f[200010],g[200010],high[200010],low[200010];
int cnt,head[200010],to[400010],nxt[400010];
char s[200010];
int in[200010],out[200010];
void add(int x,int y)
{
	cnt++;
	to[cnt]=y;
	nxt[cnt]=head[x];
	head[x]=cnt;
}
void dfs1(int x,int fa)
{
	if (s[x]=='1')
	{
		in[x]=true;
	}
	for (int i=head[x];i;i=nxt[i])
	{
		int y=to[i];
		if (y==fa)
		{
			continue;
		}
		dfs1(y,x);
		in[x]|=in[y];
		f[x]=max(f[x],f[y]+1);
	}
}
void dfs2(int x,int fa)
{
	int mx=0,mx2=0,sum=0;
	for (int i=head[x];i;i=nxt[i])
	{
		int y=to[i];
		if (y==fa)
		{
			continue;
		}
		if (f[y]+1>mx)
		{
			mx2=mx;
			mx=f[y]+1;
		}
		else if (f[y]+1>mx2)
		{
			mx2=f[y]+1;
		}
		sum+=in[y];
	}
	for (int i=head[x];i;i=nxt[i])
	{
		int y=to[i];
		if (y==fa)
		{
			continue;
		}
		if (f[y]+1==mx)
		{
			g[y]=max(g[x]+1,mx2+1);
		}
		else
		{
			g[y]=max(g[x]+1,mx+1);
		}
		out[y]=out[x];
		if (sum-in[y] || s[x]=='1')
		{
			out[y]=1;
		}
		dfs2(y,x);
	}
}
void dfs3(int x,int fa)
{
	int mx=g[x],mx2=0;
	for (int i=head[x];i;i=nxt[i])
	{
		int y=to[i];
		if (y==fa)
		{
			continue;
		}
		if (f[y]+1>mx)
		{
			mx2=mx;
			mx=f[y]+1;
		}
		else if (f[y]+1>mx2)
		{
			mx2=f[y]+1;
		}
	}
	high[x]=min(mx2+1,mx-1);
	if (s[x]=='1')
	{
		low[x]=0;
	}
	else
	{
		low[x]=high[x]+1;
		if (out[x])
		{
			low[x]=min(low[x],g[x]);
		}
		for (int i=head[x];i;i=nxt[i])
		{
			int y=to[i];
			if (y==fa)
			{
				continue;
			}
			if (in[y])
			{
				low[x]=min(low[x],f[y]+1);
			}
		}
	}
	for (int i=head[x];i;i=nxt[i])
	{
		int y=to[i];
		if (y==fa)
		{
			continue;
		}
		dfs3(y,x);
	}
}
int main()
{
	scanf("%d",&n);
	for (int i=1;i<n;i++)
	{
		int x,y;
		scanf("%d%d",&x,&y);
		add(x,y);
		add(y,x);
	}
	scanf("%s",s+1);
	dfs1(1,0);
	dfs2(1,0);
	dfs3(1,0);
	long long ans=0;
	for (int i=1;i<=n;i++)
	{
		ans+=1LL*(high[i]-low[i]+1);
	}
	ans++;
	printf("%lld\n",ans);
    return 0;
}
//一顾倾人城，再顾倾人国。
//——李延年《李延年歌》

Measured memory_bytes: 20992
#if !defined(__clang__) && defined(__GNUC__)
#include <bits/stdc++.h>
#else
#include <cstdlib>
#include <climits>
#include <iostream>
#include <cstdint>
#include <vector>
#include <string>
#include <complex>
#include <bitset>
#include <queue>
#include <deque>
#include <stack>
#include <utility>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <regex>
#endif //  !defined(__clang__) && defined(__GNUG__)
#include <boost/lexical_cast.hpp>
#include <boost/algorithm/string.hpp>
#include <boost/multi_array.hpp>
#include <boost/optional.hpp>
#include <boost/math/common_factor_rt.hpp>

using namespace std;

int main()
{
    int64_t N;
    std::cin >> N;

    int64_t count = 0;
    bool cond = false;
    for (decltype(N) i = 1; i <= N; ++i) {
        int64_t p_i;
        std::cin >> p_i;

        if (cond) {
            count++;
            cond = false;
        }
        else {
            if (i == p_i) {
                cond = true;
            }
        }
    }

    if (cond) {
        count++;
    }

    std::cout << count << std::endl;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(){
	long long X, points;
	cin >> X;
	if (X / 500 != 0)
		points = X / 500 * 1000 + X % 500 / 5 * 5;
	else
		points = X / 5 * 5;
	cout << points;
	return 0;	
}


Measured memory_bytes: 256
import java.util.*;

public class Main {
    private static Scanner sc = new Scanner(System.in);
    private static int[] msn = new int[100000];
    private static int[] msd = new int[100000];
    public static void main(String[] args) throws Exception {
        int msnc = 0;
        int msdc = 0;
        for (int i = 2;i <= 300000;i++) {
            if (i%7==1||i%7==6) {
                msn[msnc] = i;
                boolean b = true;
                for (int j = 0;j < msnc;j++) {
                    if (i%msn[j]==0) {
                        b = false;
                        break;
                    }
                }
                if (b) {
                    msd[msdc] = i;
                    msdc++;
                }
                msnc++;
            }
        }
        
        while (true) {
            int n = sc.nextInt();
            if (n==1) break;
            solve(n);
        }
    }
    
    private static void solve(int val) {
        StringBuilder sb = new StringBuilder();
        sb.append(val).append(":");
        for (int i = 0;i < 100000;i++) {
            int n = msd[i];
            if (n!=0) {
                if (val%msd[i]==0) {
                    sb.append(" ").append(msd[i]);
                }
            }
        }
        System.out.println(sb.toString());
    }
}

Measured memory_bytes: 30944
#include<stdio.h>
int R=1,C=1,H[2000010],N[2000010];
//評価関数（いまはMAX）
int hyouka(int a,int b){
  if(C<b)return 1;
  if(C<a||b==0)return 0;
  return N[H[a]]<N[H[b]]?1:0;
}
//挿入関数
void hin(int a){
  int i=C++;
  for(N[H[0]=R]=a;hyouka(0,i/2);i/=2)H[i]=H[i/2];
  H[i]=R++;
}
//取り出す関数
int hout(){
  int rt=H[1],i,j=2,k=H[--C];
  for(i=1;hyouka(i,C);i=j)H[i]=H[j=i*2+1-hyouka(i*2,i*2+1)];
  H[j/2]=k;
  return rt;
}
int lb(int l,int r,long long n,long long *d){
  if(n>(1<<29))return r;
  while(l-r){
    int m=(l+r)/2;
    n<=d[m]?(r=m):(l=m+1);
  }
  return l;
}

long long i,j,k,s=0,c,a[200010],b[200010],d[200010];
int n;
int main(){
  scanf("%d",&n);
  for(i=0;i<n;i++)scanf("%lld",&a[i]);
  for(i=0;i<n;i++)scanf("%lld",&b[i]);
  for(i=0;i<30;i++){
    R=C=1;
    k=(1<<i);//printf("%d\n",k);
    for(j=0;j<n;j++)hin((int)(b[j]&((2LL<<i)-1)));
    for(j=0;j<n;j++)d[j]=N[hout()];
    //for(j=0;j<n;j++)printf("%d ",d[j]);printf("\n");
    for(j=c=0;j<n;j++)c+=(lb(0,n,2*k-(a[j]&((2LL<<i)-1)),d)-
			  lb(0,n,1*k-(a[j]&((2LL<<i)-1)),d)+
			  n-
			  lb(0,n,3LL*k-(a[j]&((2LL<<i)-1)),d));
    s+=c%2*k;
    /*or(j=0;j<n;j++)printf("%d %d %d %d\n",s,
			   lb(0,n,2*k-(a[j]&((2<<i)-1)),d),
			   lb(0,n,1*k-(a[j]&((2<<i)-1)),d),
			   lb(0,n,3*k-(a[j]&((2<<i)-1)),d));//*/
  }
  printf("%lld\n",s);
  return 0;
}


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

using ll = long long;
using Vi = vector<int>;
using Vl = vector<ll>;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;

constexpr int I_INF = numeric_limits<int>::max();
constexpr ll L_INF = numeric_limits<ll>::max();

//==================================

int dp[100010];

int main() {
#ifdef FASTIO
    cin.tie(0), cout.tie(0);
    ios::sync_with_stdio(false);
#endif
#ifdef FILEINPUT
    ifstream ifs("./in_out/input.txt");
    cin.rdbuf(ifs.rdbuf());
#endif

    int N;
    cin >> N;

    fill_n(&dp[0], sizeof(dp) / sizeof(dp[0]), I_INF);
    dp[0] = 0;
    for (int i = 0; i < N; i++) {
        dp[i + 1] = min(dp[i + 1], dp[i] + 1);
        int add = 6;
        while (i + add <= N) {
            dp[i + add] = min(dp[i + add], dp[i] + 1);
            add *= 6;
        }
        add = 9;
        while (i + add <= N) {
            dp[i + add] = min(dp[i + add], dp[i] + 1);
            add *= 9;
        }
    }

    cout << dp[N] << endl;

    return 0;
}

Measured memory_bytes: 640
import math

from collections import Counter


def func(i):
    if i >= 1:
        return math.factorial(i)
    else:
        return 1


N = int(input())

S = [''.join(sorted(list(input()))) for i in range(N)]

print(sum([func(i) // func(i-2) // 2 for i in Counter(S).values()]))


Measured memory_bytes: 19720
use proconio::{fastout, input};

const MOD: u64 = 1_000_000_007;

#[fastout]
fn main() {
    input! {
        n: usize,
        a: [u64; n],
    }

    let mut ans = 0;
    let mut sum: u64 = a.iter().sum();

    for i in a {
        sum -= i;
        ans += (sum % MOD) * (i % MOD) % MOD;
        ans %= MOD;
    }

    println!("{}", ans);
}


Measured memory_bytes: 5560
#include <bits/stdc++.h>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <string>
using namespace std;
typedef long long int ll;
#define rep(i, n) for (int(i) = 0; (i) < (n); (i)++)

bool isPrime(int x){
    if(x==1)return 0;
    if(x==2)return 1;
    if(x%2==0)return 0;
    for(int i=3;i*i<=x;i++)if(x%i==0)return 0;
    return 1;
}
int main() {
    ll a,b,c,k;
    cin >> a >> b >> c >> k;
    int ans=0;
        if(a-k<0){
            k-=a;
            ans+=a;
            if(b-k<0){
                k-=b;
                if(c-k<0){
                    ans-=c;
                    cout << ans <<endl;
                }else{
                    ans-=k; 
                    cout << ans <<endl;
                }
            }else{
                cout << ans <<endl;
                return 0;
            }
        }else{
            cout << k <<endl;
            return 0;
        }        
    return 0;
}


Measured memory_bytes: 3632
#include <algorithm>
#include <array>
#include <cstddef>
#include <cstdint>
#include <iostream>
#include <map>
#include <set>
#include <vector>

using namespace std;

int main()
{
    int n;
    cin >> n;
    vector<int64_t> vs(n);
    for (auto& v : vs)
    {
        cin >> v;
    }
    int counter = 0;
    while (true)
    {
        bool success = true;
        for (auto& v : vs)
        {
            if (v % 2 != 0)
            {
                success = false;
            }
            else
            {
                v /= 2;
            }
        }
        if (success)
        {
            counter++;
        }
        else
        {
            break;
        }
    }
    cout << counter << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, a) for(int i=0; i<(a); i++)
typedef long long ll;
template<typename T>
struct edge {
  int src, to;
  T cost;
  edge(int to, T cost) : src(-1), to(to), cost(cost) {}
  edge(int src, int to, T cost) : src(src), to(to), cost(cost) {}
  edge &operator=(const int &x) {
    to = x;
    return *this;
  }
  operator int() const { return to; }
};
template<typename T>
using Edges = vector<edge<T>>;
template<typename T>
using WeightedGraph = vector<Edges<T>>;
using UnWeightedGraph = vector<vector<int>>;
template<typename T>
using Matrix = vector<vector<T>>;

/////////////////////////////////////////////////////////////////////
const ll inf = 1LL<<60;

ll d;
vector<ll> c(26);
vector<vector<ll>> s(365, vector<ll>(26));
vector<ll> t(365);

vector<ll> calc() {
  vector<ll> nsc(26);
  vector<ll> score(d);
  vector<ll> last(26, -1);
  rep(i, d) {
    last[t[i]] = i;
    rep(j, 26) {
      if (t[i] == j) nsc[j] += s[i][j];
      else nsc[j] -= c[j]*(i-last[j]);
    }
    ll sum = 0;
    rep(j, 26) sum += nsc[j];
    score[i] = sum;
  }
  return score;
}

int main()
{
  srand((unsigned)time(NULL));

  cin>>d;
  rep(i, 26) cin>>c[i];
  rep(i, d) rep(j, 26) cin>>s[i][j];

  rep(i, d) {
    ll tmp = 0;
    ll ma = -inf;
    rep(j, 26) {
      if (s[i][j] > ma) {
        ma = s[i][j];
        tmp = j;
      } else if (s[i][j] == ma) {
        if (c[j] < c[tmp]) {
          tmp = j;
        }
      }
    }
    t[i] = tmp;
  }
  vector<ll> fsc = calc();

  {
    vector<ll> last(26, -1);
    vector<ll> nsc(26);
    rep(i, d) {
      ll idx = 0;
      ll sum = 0;
      rep(j, 26) {
        nsc[j] -= c[j]*(i-last[j]);
        sum += nsc[j];
      }
      rep(j, 26) {
        ll aa = sum + c[j]*(i-last[j]) + s[i][j];
        ll bb = sum + c[idx]*(i-last[idx]) + s[i][idx];
        if (aa > bb && aa >= fsc[i]) {
          idx = j;
        }
      }
      nsc[idx] += c[idx]*(i-last[idx]) + s[i][idx];
      last[idx] = i;
      t[i] = idx;
    }
  }
  vector<ll> ssc = calc();

  int ti = clock();
  while (clock() - ti < 195 * CLOCKS_PER_SEC / 100) {
    ll nd = rand() % d;
    ll nx = rand() % 26;
    ll px = t[nd];
    t[nd] = nx;
    vector<ll> tsc = calc();
    if (ssc[d-1] < tsc[d-1]) {
      ssc = tsc;
    } else {
      t[nd] = px;
    }
  }

  rep(i, d) cout << t[i]+1 << endl;

  return 0;
}


Measured memory_bytes: 3760
fun main(args: Array<String>) {
    val S = readLine()!!
    if (S.startsWith("A") && S[1].isLowerCase() && S.last().isLowerCase()) {
        S.substring(2, S.lastIndex).let {
            if (it.count { c -> c == 'C' } == 1) {
                if (it.filter { c -> c != 'C' }.all { c -> c.isLowerCase() }) {
                    println("AC")
                } else println("WA")
            } else println("WA")
        }
    } else println("WA")
}

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

using namespace std;
using ll = long long;

int main() {
    cin.tie(nullptr); ios::sync_with_stdio(false);
    int N, M; cin >> N >> M;
    vector<int> H(N);
    for (int i = 0; i < N; i++)
        cin >> H[i];
    vector<vector<int>> G(N);
    for (int i = 0; i < M; i++)
    {
        int Ai, Bi; cin >> Ai >> Bi;
        G[Ai-1].push_back(Bi-1);
        G[Bi-1].push_back(Ai-1);
    }
    int ans = 0;
    for (int i = 0; i < N; i++)
    {
        bool flag = true;
        int hight = H[i];
        for (int j = 0; j < G[i].size(); j++)
        {
            if (H[G[i][j]] >= hight)
            {
                flag = false;
            }
        }
        ans += flag;
    }
    cout << ans << endl;
}

Measured memory_bytes: 8744
n, m, c = list(map(int, input().split()))
bs = list(map(int, input().split()))
ans = 0
for i in range(n):
    score = c
    for a, b in zip(list(map(int, input().split())), bs):
        score += a*b
    if score > 0:
        ans += 1
print(ans)

Measured memory_bytes: 3060
import java.io.*;

class Main {
    BufferedReader bf;
    PrintWriter writer;
    StringBuilder sb;
    static boolean local_system = false;

    void run() throws IOException {
        int[] c = ni();
        int i = 0;
        for(;i<c.length;i++) if(c[i] == 0) break;
        writer.println(i+1);
    }

    public static void main(String[] args) throws IOException {
        long start_time = System.currentTimeMillis();
        Main obj = new Main();
        obj.run();
        long end_time = System.currentTimeMillis();
        if (local_system) obj.writer.println("Time : " + (end_time - start_time));
        obj.close();
    }

    public Main(){
        writer = new PrintWriter(System.out);
        bf = new BufferedReader(new InputStreamReader(System.in));
        sb = new StringBuilder();
    }

    public int i() throws IOException {
        return Integer.parseInt(bf.readLine());
    }

    public long l() throws IOException {
        return Long.parseLong(bf.readLine());
    }

    public int[] ni() throws IOException {
        String[] data = bf.readLine().split(" ");
        int[] send = new int[data.length];
        for (int i = 0, h = data.length; i < h; i++) send[i] = Integer.parseInt(data[i]);
        return send;
    }

    public long[] nl() throws IOException {
        String[] data = bf.readLine().split(" ");
        long[] send = new long[data.length];
        for (int i = 0, h = data.length; i < h; i++) send[i] = Long.parseLong(data[i]);
        return send;
    }

    public void close() throws IOException{
        writer.flush();
        writer.close();
        bf.close();
    }
}




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

int n, m, x, mn=1e9, c[15], a[15][15];
int main() {
	int i, j, k;
	cin >> n >> m >> x;
	for(i=0; i<n; i++) {
		cin >> c[i];
		for(j=0; j<m; j++) cin >> a[i][j];
	}
	for(k=0; k<1<<n; k++) {
		int sc=0, sa[15]={};
		for(i=0; i<n; i++) {
			if(k>>i & 1) {
				sc += c[i];
				for(j=0; j<m; j++) sa[j] += a[i][j];
			}
		}
		for(j=0; j<m; j++) if(sa[j] < x) break;
		if(j==m) mn = min(mn, sc);
	}
	cout << (mn==1e9 ? -1 : mn);
	return 0;
}

Measured memory_bytes: 3636