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

enum{U = 0, D = 1, N = 2, E = 3, W = 4, S = 5};
vector<int> d{1, 6, 5, 3, 4, 2};
void rotate(int a, int b, int c, int dd){
	int t = d[a];
	d[a] = d[b];
	d[b] = d[c];
	d[c] = d[dd];
	d[dd] = t;
}

int main(){
	int n;
	while(cin >> n, n){
		int sum = 0;
		d = {1, 6, 5, 3, 4, 2};
		for(int i=0; i < n; i++){
			string s; cin >> s;
			if(s[0] == 'N') rotate(U, S, D, N);
			else if(s[0] == 'E') rotate(E, U, W, D);
			else if(s[0] == 'W') rotate(D, W, U, E);
			else if(s[0] == 'S') rotate(S, U, N, D);
			else if(s[0] == 'R') rotate(S, E, N, W);
			else if(s[0] == 'L') rotate(S, W, N, E);
			sum += d[U];
		}
		cout << sum+1 << endl;
	}
}

Measured memory_bytes: 1220
#include <stdio.h>
#include <stdlib.h>
int main(){
  int i,n,c=0;
   scanf("%d",&n);
  int p[n];
  
 for(i=0;i<n;i++)
   scanf("%d",&p[i]);
   
 for(i=1;i<n-1;i++){
   if((p[i-1]<p[i]&&p[i]<p[i+1])||(p[i-1]>p[i]&&p[i]>p[i+1]))
    c++;
 }
  printf("%d",c);
}

Measured memory_bytes: 128
#include <iostream>
#include <complex>
#include <sstream>
#include <string>
#include <algorithm>
#include <deque>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <vector>
#include <set>
#include <limits>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <ctime>
using namespace std;
#define REP(i, j) for(int i = 0; i < (int)(j); ++i)
#define FOR(i, j, k) for(int i = (int)(j); i < (int)(k); ++i)
#define SORT(v) sort((v).begin(), (v).end())
#define REVERSE(v) reverse((v).begin(), (v).end())
typedef complex<double> P;
const int MAX_N = 1000000005;

int main() {
  int N; cin >>N;
  cout <<N <<":";
  FOR(i, 2, sqrt(N) + 1){
    while(!(N % i)){
      cout <<" " <<i;
      N /= i;
    }
  }
  if(N > 1) cout <<" " <<N;
  cout <<endl;
  return 0;
}

Measured memory_bytes: 1164
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;

public class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		int n = Integer.parseInt(br.readLine());

		int x[] = new int[n];
		int y[] = new int[n];
		long h[] = new long[n];

		int index = 0;
		for (int i = 0; i < n; i++) {
			String str[] = br.readLine().split(" ");
			x[i] = Integer.parseInt(str[0]);
			y[i] = Integer.parseInt(str[1]);
			h[i] = Long.parseLong(str[2]);

			if (h[i] != 0) {
				index = i;
			}
		}

		for (int i = 0; i <= 100; i++) {
			for (int j = 0; j <= 100; j++) {
				int H = (int) (h[index] + Math.abs(i - x[index]) + Math.abs(j - y[index]));
				boolean flag = true;
				
				for (int k = 0; k < n; k++) {
					if (Math.max(H - Math.abs(i - x[k]) - Math.abs(j - y[k]), 0) != h[k]) {
						flag = false;
						break;
					}
				}
				if (flag) {
					System.out.println(i + " " + j + " " + H);
					return;
				}
			}
		}
	}
}


Measured memory_bytes: 23380
import java.util.HashMap;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		StringBuilder sb = new StringBuilder();
		int s = sc.nextInt();
		int[] a = new int[1000000];
		a[0] = s;
		HashMap<Integer, Integer> hm = new HashMap<>();
		hm.put(a[0], 0);
		for (int i = 1; i < 1000000; i++) {
			if (a[i - 1] % 2 == 0) {
				a[i] = a[i - 1] / 2;
			} else {
				a[i] = 3 * a[i - 1] + 1;
			}
			if (hm.containsKey(a[i])) {
				System.out.println(i + 1);
				break;
			} else {
				hm.put(a[i], i);
			}
		}
	}
}


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

int main () {
    int a, b, c;
    cin >> a >> b >> c;
    if (a==b && a!=c) {
        cout << "Yes";
    }
    else if (a==c && a!=b) {
        cout << "Yes";
    }
    else if (b==c && b!=a) {
        cout << "Yes";
    }
    else {
        cout << "No";
    }
    return 0;
}

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


int main(){
  int N;
  cin >> N;
  int x[10],y[10];
  for(int i=1;i<=N;i++){
    cin >> x[i] >> y[i];
  }
  double sum=0.0;
  vector<int>v(N);
  for(int i = 0; i < N; i++) v[i] = i + 1;
  do{
    for(int i=0;i<N-1;i++)
      sum += pow((x[v[i]]-x[v[i+1]])*(x[v[i]]-x[v[i+1]])+(y[v[i]]-y[v[i+1]])*(y[v[i]]-y[v[i+1]]),0.5);
    }while(next_permutation(v.begin(),v.end()));
  int pat=1;
  for(int i=2;i<=N;i++){
    pat*=i;
  }
  cout << fixed << setprecision(10) << sum/pat << endl;
}
      
    
      


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

int main(void) {
    int K;
    cin >> K;
    string S;
    cin >> S;

    if (S.size() <= K)
        cout << S << "\n";
    else
        cout << S.substr(0, K) << "...\n";

    return 0;
}

Measured memory_bytes: 3568
#include <iostream>

using namespace std;
typedef long long ll;

int main(){
    ll n, k;
    cin >> n >> k;
    ll ans = 0;
    for(int i = 0; i < n; ++i){
        ll h;
        cin >> h;
        ans += (h >= k);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 888
#include <stdio.h>
int main()
{
	 int value1,value2;

	scanf("%x%x",&value1,&value2);
	if(value1>value2){
        printf(">\n");
	}else if(value1<value2){
	    printf("<\n");

	}else{
	    printf("=\n");


	}

	return 0;
}


Measured memory_bytes: 128
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<string>
#include<algorithm>
#include<iostream>
#include<queue>
#include<map>
#include<cmath>
#include<set>
#include<stack>
#define ll long long
#define max(x,y) ((x)>(y)?(x):(y))
#define min(x,y) ((x)>(y)?(y):(x))
#define cls(name,x) memset(name,x,sizeof(name))
using namespace std;
const int inf=1<<28;
const int maxn=110;
const int maxm=110;
const int mod=1e9+7;
const double pi=acos(-1.0);
int n;
int val[maxn];
int dp[maxn*maxn];
int main()
{
    //freopen("in.txt","r",stdin);
    while(~scanf("%d",&n))
    {
        cls(dp,0);
        for(int i=0;i<n;i++)
            scanf("%d",&val[i]);
        dp[0]=1;
        for(int i=0;i<n;i++)
        {
            for(int j=maxn*maxn;j>=0;j--)
            {
                if(dp[j]==1)
                dp[j+val[i]]=1;
            }
        }
        int ans=0;
        for(int i=maxn*maxn;i>=0;i--)
        {
            if(dp[i]==1&&i%10!=0)
            {
                ans=i;
                break;
            }
        }
        printf("%d\n",ans);
    }
    return 0;
}


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

int main() {
	ios_base::sync_with_stdio( false );

	int n;
	cin >> n;

	vector<int> S( n );
	for( auto& v: S ) { cin >> v; }

	int q;
	cin >> q;

	int result = 0;

	for( int i = 0; i < q; ++i ) {
		int T;
		cin >> T;

		for( int j = 0; j < n; ++j ) {
			if( S.at(j) == T ) {
				result += 1;
				break;
			}
		}
	}

	cout << result << endl;
}



Measured memory_bytes: 3220
#include <bits/stdc++.h>
using namespace std;
const int MAXN=300100,MOD=1e9+7;
const int automata[8][2]={{3,1},{5,2},{2,2},{4,7},{3,3},{6,1},{5,5},{3,1}};
char ch[MAXN];
int dp[MAXN][8],len;
int main()
{
	ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
	cin>>ch;
	len=strlen(ch);
	dp[len][1]=dp[len][2]=1;
	for(register int i=len-1;~i;i--)
		for(register int j=0;j<8;j++)
		{
			if(ch[i]!='0') dp[i][j]=(dp[i][j]+dp[i+1][automata[j][1]])%MOD;
			if(ch[i]!='1') dp[i][j]=(dp[i][j]+dp[i+1][automata[j][0]])%MOD;
		}
	cout<<dp[0][0]<<endl;
	return 0;
}

Measured memory_bytes: 9984
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef tuple<int,int,int> T;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
typedef vector<T> vt;

int main() {
	string S,T;
	cin >> S;
	vector<int>kug(1, 0);
	for (int i = 0; i < S.size(); ++i) {
		if (S[i] != 'x') {
			T.push_back(S[i]);
			kug.push_back(0);
		}
		else {
			kug.back()++;
		}
	}
	for (int i = 0; i < T.size(); ++i) {
		if (T[i] != T[T.size() - 1 - i]) {
			cout << "-1\n";
			return 0;
		}
	}
	int ans = 0;
	for (int i = 0; i < kug.size(); ++i) {
		ans += abs(kug[i] - kug[kug.size() - 1 - i]);
		
	}
	cout << ans / 2 << endl;
	return 0;
}

Measured memory_bytes: 1148
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define pb push_back
#define all(a) (a).begin(),(a).end()
#define fi first
#define se second
#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
int M=1e9+7;
int mm(int x,int y){x%=M,y%=M;return (x*y)%M;}//Modular Multiply
int po(int x,int y){ if(!y)return 1;int a=po(x,y/2)%M;if(y%2)return mm(a,mm(a,x));return mm(a,a);}//(x**y)%M

signed main(){
	fast;
	string s;
	vector<int> v;
	map<int,int> mp;
	int n,m,c=0,t=1;
	//cin>>t;
	while(t--){
		cin>>s;
		if(s[2]==s[3] and s[5]==s[4]) cout<<"Yes";
		else cout<<"No";

	}
	return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;
int main() {
	int N, M;
	cin >> N;
	M = N % 1000;
	if (M == 0)
		cout << 0 << endl;
	else
		cout << 1000 - M;
}

Measured memory_bytes: 3588
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
typedef long long ll;
const int MOD = 1000000007;
int main()
{
  ll N,P;
  cin >> N >> P;
  ll od=0;
  rep(i,N){
     int a;
     cin >> a;
     if(a%2!=0)od++;
  }
  ll ev=N-od;
  ll ans=(1ll<<ev);
  if(P==1&&od==0){cout << 0 << endl;return 0;}
  ll ad=0;
  vector<ll>nc(od+1);nc[0]=1;
  
  for(ll i=0;i<od;i++){
     nc[i+1]=nc[i]*(od-i)/(i+1);
  }
  for(int i=P;i<=od;i+=2){
     ad+=nc[i];
  }
  cout << ans*ad << endl;
  return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<iostream>
#include<queue>
#include<vector>
#include <bitset>
#include<math.h>
using namespace std;
#define INF 10000000
#define MOD 1000000007
typedef long long ll;
typedef pair<int,int> P;
#define bit(n,k) ((n>>k)&1) /*nのk bit目*/

double dp[310][310][310];

int main(){
    int N,a,A=0,B=0,C=0;
    cin>>N;
    A=N;
    for(int i=0;i<N;i++){
        cin>>a;
        if(a>=2) B++;
        if(a==3) C++;
    }
    dp[0][0][0]=0.0;
    for(int i=1;i<=A;i++){
        for(int j=0;j<=min(i,B);j++){
            for(int k=0;k<=min(j,C);k++){
                dp[i][j][k]=(double)(N-i)/i
                +(double)(dp[i-1][j][k]+1)*(i-j)/i
                +(double)(dp[i][max(j-1,0)][k]+1)*(j-k)/i
                +(double)(dp[i][j][max(k-1,0)]+1)*k/i;
            }
        }
    }
    printf("%.10lf\n",dp[A][B][C]);
}


Measured memory_bytes: 225664
#include <iostream>
#include <vector>
#include <cmath>
#include <cstdio>
using namespace std;
const double PI = 6 * asin(0.5);

double heron(double a,double b,double c){
  double s = (a + b + c) / 2;
  return sqrt(s*(s-a)*(s-b)*(s-c));
}

int main(){
  int n,m;
  while(cin >> n >> m && n && m){
    vector<pair<double,double> > v(n);
    vector<vector<double> > a(n,vector<double>(n,0.0));
    vector<vector<vector<double> > > dp(m+2,vector<vector<double> >(n,vector<double>(n,0.0)));

    for(int i=0;i<n;i++){
      double d;
      cin >> d;
      v[i].first = cos(d * 2.0 * PI);
      v[i].second = sin(d * 2.0 * PI);

      for(int j=i-1;j>=0;j--) a[i][j] = a[j][i] = sqrt(pow(v[i].first-v[j].first,2)+pow(v[i].second-v[j].second,2));
    }

    for(int i=2;i<m;i++){
      for(int j=0;j<n-2;j++){
	for(int k=j+1;k<n-1;k++){
	  for(int l=k+1;l<n;l++){
	    dp[i+1][j][l] = max(dp[i+1][j][l],dp[i][j][k] + heron(a[j][k],a[k][l],a[l][j]));
	  }
	}
      }
    }

    double ans = 0.0;
    for(int i=0;i<n;i++){
      for(int j=0;j<n;j++){
	ans = max(ans,dp[m][i][j]);
      }
    }

    printf("%6f\n",ans);

  }
  return 0;
}

Measured memory_bytes: 1304
n, k = map(int, input().split())
p = list(map(int, input().split()))
p = [(x+1) / 2 for x in p]

# 累積和
def cumsum(a):
    r = [0]
    for v in a:
        r.append(r[-1] + v)
    return r

cs = cumsum(p)

ans = 0
for i in range(k, n+1):
    ans = max(ans, cs[i] - cs[i-k])

print(ans)

Measured memory_bytes: 24548
import sys
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
read = sys.stdin.buffer.read
sys.setrecursionlimit(10 ** 7)

A, B, N = map(int, readline().split())

if N >= B:
    ans_n = B - 1
else:
    ans_n = N

ans = int(A * ans_n / B) - A * int(ans_n / B)
print(ans)

Measured memory_bytes: 9136
n = input()
N = list(n)
if N[0] > N[1]:
    print(N[0] + N[0] + N[0])
elif N[0] == N[1]:
    if N[1] >= N[2]:
        print(N[0] + N[0] + N[0])
    else:
        b = int(N[0]) + 1
        print(b * 111)
else:
    b = int(N[0]) + 1
    print(b * 111)


Measured memory_bytes: 3060
#include <stdio.h>
#include <stdlib.h>

struct node{
  struct node *right;
  struct node *left;
  struct node *parent;
  int key;
};
typedef struct node * Node;
#define NIL NULL

Node root;

void insert(int k){
  Node y = NIL;
  Node x = root;
  Node z;

  z = malloc(sizeof(struct node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;

  while(x!=NIL){
    y=x;
    if(z->key<x->key){x=x->left;}
    else{x=x->right;}
  }
  
  z->parent=y;

  if(y==NIL){root=z;}
  else if(z->key<y->key){y->left=z;}
  else {y->right=z;}
  
}

void inorder(Node u){
  if(u!=NIL){
    inorder(u->left);
    printf(" %d",u->key);
    inorder(u->right);   
  }
}
void preorder(Node u){
  if(u!=NIL){
    printf(" %d",u->key);
    preorder(u->left);
    preorder(u->right); 
  }
}

int main(){
  int n, i, x;
  char com[20];
  scanf("%d",&n);

  for ( i = 0; i < n; i++ )
    {
      scanf("%s",com);

      if ( com[0] == 'i' )
	{
	  scanf("%d",&x);
	  insert(x);
	}
      else if ( com[0] == 'p' )
	{
	  inorder(root);
	  printf("\n");
	  preorder(root);
	  printf("\n");
	} 
    }

  return 0;
}



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

const int maxn = 2e5 + 20;

int n, k, l, a, b;
int visited[2][maxn], ar[maxn];
vector<int> graph[2][maxn];
vector<vector<int>> ans[maxn];

void roadComponent(int i, int CPcnt) {
    visited[0][i] = CPcnt;
    for (int x : graph[0][i])
        if (!visited[0][x])
            roadComponent(x, CPcnt);
}
void railComponent(int i, int CPcnt) {
    visited[1][i] = CPcnt;
    if (ans[visited[0][i]].size() != 0 && ans[visited[0][i]][ans[visited[0][i]].size() - 1][0] == -CPcnt)
        ans[visited[0][i]][ans[visited[0][i]].size() - 1].push_back(i);
    else {
        vector <int> need;
        need.push_back(-CPcnt);
        need.push_back(i);
        ans[visited[0][i]].push_back(need);
    } 
    ar[i] = ans[visited[0][i]].size() -1;
    for (int x : graph[1][i])
        if(!visited[1][x])
            railComponent(x, CPcnt);
}

int main() {
    cin >> n >> k >> l;
    for (int i = 0; i < k; i ++){
        cin >> a >> b;
        graph[0][a].push_back(b);
        graph[0][b].push_back(a);
    }
    for (int i = 0; i < l; i ++){
        cin >> a >> b;
        graph[1][a].push_back(b);
        graph[1][b].push_back(a);
    }

    int CPcnt = 1;
    for(int i = 1; i <= n;i++)
        if (!visited[0][i])
            roadComponent(i, CPcnt++);
    CPcnt = 1;
    for(int i = 1; i <= n;i++)
        if (!visited[1][i])
            railComponent(i, CPcnt++);
    for(int i = 1; i <= n;i++)
        cout << ans[visited[0][i]][ar[i]].size() - 1 << " ";
    cout << endl;


}

Measured memory_bytes: 33204
// きりみんちゃんの配信からきました
package main

import "fmt"

var n, m, x int

func main() {
	fmt.Scan(&n, &m, &x)
	left, right := 0, 0
	for i := 0; i < m; i++ {
		var j int
		fmt.Scan(&j)
		if j < x {
			left += 1
		} else {
			right += 1
		}
	}
	if left < right {
		fmt.Println(left)
	} else {
		fmt.Println(right)
	}
}


Measured memory_bytes: 512
function Main(input) {
    input = input.split("\n");
    var num = parseInt(input[0].split(" ")[0]);
    var basis = parseInt(input[0].split(" ")[1]);
    var x = 0;
    var y = 0;
    var count = 0;
    
    function CalcHeihoukon(a,b){
        return Math.sqrt(Math.pow(a,2)+Math.pow(b,2));
    }
    for(var i=1; i<=num; i++){
        x = parseInt(input[i].split(" ")[0]);
        y = parseInt(input[i].split(" ")[1]);
        if(CalcHeihoukon(x,y)<=basis){
            count+=1;
        }
    }
   console.log(count);
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 62440
#include<stdio.h>
#define N 20
#define Q 200
#define TRUE 1
#define FALSE 0

int solve(int,int);

int n,A[N];

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

  /*    i n p u t   */
  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]);
  }


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

  return 0;
}


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

  if(i>=n) return FALSE;

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

}

Measured memory_bytes: 580
import java.io.*;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner stdIn = new Scanner(System.in);
		double max = Double.MIN_VALUE;
		double min = Double.MAX_VALUE;
		while(stdIn.hasNext()) {
			double a = stdIn.nextDouble();
			max = Math.max(a, max);
			min = Math.min(min, a);
		}
		System.out.println(max - min);
	}
}

Measured memory_bytes: 18684
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	MyScanner sc = new MyScanner();
	Scanner sc2 = new Scanner(System.in);
	final int MOD = 1000000007;
	int[] dx = { 1, 0, 0, -1 };
	int[] dy = { 0, 1, -1, 0 };

	void run() {
		int sum = 0;
		for (int i = 0; i < 5; i++) {
			int input = sc.nextInt();
			sum += input < 40 ? 40 : input;
		}
		System.out.println(sum / 5);
	}

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

	void debug(Object... o) {
		System.out.println(Arrays.deepToString(o));
	}

	void debug2(int[][] array) {
		for (int i = 0; i < array.length; i++) {
			for (int j = 0; j < array[i].length; j++) {
				System.out.print(array[i][j]);
			}
			System.out.println();
		}
	}

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

		double nextDouble() {
			return Double.parseDouble(next());
		}

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

		String next() {
			try {
				StringBuilder res = new StringBuilder("");
				int c = System.in.read();
				while (Character.isWhitespace(c))
					c = System.in.read();
				do {
					res.append((char) c);
				} while (!Character.isWhitespace(c = System.in.read()));
				return res.toString();
			} catch (Exception e) {
				return null;
			}
		}
	}
}

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

struct Team{
    ll size,hp;
    bool pr;
    ll rem(){
        if(pr) return (hp+1)/2;
        return (size <= hp) ? size : hp;
    }
};


int solve(ll n, ll m, int pr){
    Team t[2] = {{n,n*2LL,false},{m,m*2LL,false}};
    t[pr].pr = true;
    int turn = 0, cnt = 0;
    while(true){
        ll attack = t[turn].rem();
        t[(turn+1)%2].hp -= attack;
        if(t[0].rem()>0 && t[1].rem()>0){
            cnt++;
            turn = (turn+1)%2;
        }else{
            break;
        }
    }
    return cnt;
}

int main(void){
    ll n,m;
    cin>>n>>m;
    cout<<min(solve(n,m,0), solve(n,m,1))<<endl;
    return 0;
}



Measured memory_bytes: 3100
###template###
import sys
def input(): return sys.stdin.readline().rstrip()
from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt, ceil, floor
from collections import deque
from bisect import bisect, bisect_left, bisect_right
from string import ascii_lowercase
import heapq
INF = float("inf")
sys.setrecursionlimit(10**7)
# 4近傍（右, 下, 左, 上）
dy = [0, -1, 0, 1]
dx = [1, 0, -1, 0]
def inside(y: int, x: int, H: int, W: int) -> bool: return 0 <= y < H and 0 <= x < W
def mi(): return map(int, input().split())
def ii(): return int(input())
###template###

import fractions
A, B, C, D = mi()

cdall = B//round((C * D / fractions.gcd(C, D)))#1～BにおけるC*Dの約数の個数
call = B//C
dall = B//D

cdminus = (A-1)//round((C * D / fractions.gcd(C, D)))
cminus = (A-1)//(C)
dminus = (A-1)//(D)

divcntall = call+dall-cdall
divcntminus = cminus+dminus-cdminus

print(B-(A-1)-(divcntall-divcntminus))

Measured memory_bytes: 66156
function main(a){
	a = a.split(" ");
	a[0]=parseInt(a[0],10);
	a[2]=parseInt(a[2],10);
	(a[1]=="+")?op(a[0]+a[2]):op(a[0]-a[2]);
	}
function op(a){
	console.log(a);
}
function stn(a){
		return a.map(function(x){return parseInt(x,10);});
}
main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 7372
#define _GLIBCXX_DEBUG//TLEの原因になるので注意！！！！！！！！！！！
#include<cmath>
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
vector<int> arr;
stack<int> st;
queue<int> qu;
queue<pair<int,int> > qu2;
priority_queue<int> pq;
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define rep2(i,n) for(int i=1; i<=(int)(n); i++)
#define mins(x,y) x=min(x,y)
#define maxs(x,y) x=max(x,y)
typedef set<int> set_t;
typedef set<string> set_g;
typedef complex<double> xy_t;
static const int NIL = -1;
static const int INF = 1000000007;
#define mp make_pair
#define sz(x) int(x.xise())
#define mod 1000000007
#define reps(i,s,n) for(int i = s; i < n; i++)
#define Rreps(i,n,e) for(int i = n - 1; i >= e; --i)
#define Rrep(i,n) Rreps(i,n,0)
deque<int> deq;
#define fi first
#define se second
//#define int long long

//cerrはコメントアウトしなくても通る//ただしTLEを引き起こすことがある

ll N,M,H,W,K,Q,A,B;
string S;
//const ll MOD = 998244353;
const ll MOD = (1e+9) + 7;
//const ll INF = 1LL << 60;
//typedef pair<ll,ll> P;
typedef pair<int, int> P;

int dp[100005][3];

int main(){
    int n;
    cin >> n;
    rep(i,n){
        int a[3];
        cin >> a[0]>> a[1]>> a[2];
        if(i==0){
            dp[0][0]=a[0];
            dp[0][1]=a[1];
            dp[0][2]=a[2];
            continue;
        }
        rep(j,3){
            rep(k,3){
                if(j!=k){
                    dp[i][j]=max(dp[i][j],dp[i-1][k]+a[j]);
                }
            }
        }
    }
    int ans=0;
    rep(i,3){
        ans=max(ans,dp[n-1][i]);
    }
    cout<<ans<<endl;
    return 0;
}



Measured memory_bytes: 1408
#include "bits/stdc++.h"
#include<unordered_map>
#include<unordered_set>
#pragma warning(disable:4996)
using namespace std;
using ld = long double;
template<class T>
using Table = vector<vector<T>>;
const ld eps=1e-9;

bool isso(long long int a) {
	if (a == 1 || a == 0)return false;
	for (long long int i = 2; i*i <= a; ++i) {
		if ((a%i)) {
		}
		else {
			return false;
		}
	}
	return true;
}
int main() {
	while (1) {
		int N, X; cin >> N >> X;
		if (!N)break;
		vector<int>as;
		for (int i = 0; i < N; ++i) {
			int a; cin >> a;
			as.emplace_back(a);
		}
		vector<int>oks(2000000);
		oks[0] = true;
		for (int i = 0; i <= X; ++i) {
			if (oks[i]) {
				for (int j = 0; j < N; ++j) {
					oks[i + as[j]] = true;
				}
			}
		}
		int ans = -1;
		for (int i = X; i >= 2; --i) {
			if (oks[i] && isso(i)) {
				ans = i;
				break;
			}
		}
		if (ans == -1)cout << "NA" << endl;
		else cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 10864
#include <bits/stdc++.h>
using namespace std;
struct hopcroft{
	vector<int> dist, pair_l, pair_r;
	vector<bool> seen;
	vector<vector<int>> to;
	int n1, n2;
	hopcroft(int n1, int n2) : n1(n1), n2(n2){
		to.resize(n1);
		pair_l.assign(n1, -1);
		pair_r.assign(n2, -1);
		dist.resize(n1);
		seen.resize(n1);
	}
	void add_edge(int u, int v){
		to[u].push_back(v);
	}
	bool bfs(){
		fill(dist.begin(), dist.end(), -1);
		queue<int> q;
		for (int i = 0; i < n1; i++){
			if (pair_l[i] == -1){
				dist[i] = 0;
				q.push(i);
			}
		}
		bool reach_minus = false;
		while (!q.empty()){
			int u = q.front();
			q.pop();
			for (int adj : to[u]){
				int radj = pair_r[adj];
				if (radj == -1){
					reach_minus = true;
				} else if (dist[radj] == -1){
					dist[radj] = dist[u] + 1;
					q.push(radj);
				}
			}
		}
		return reach_minus;
	}
	bool dfs(int u){
		seen[u] = true;
		for (int adj : to[u]){
			int radj = pair_r[adj];
			if (radj == -1 || (!seen[radj] && dist[radj] == dist[u] + 1 && dfs(radj))){
				pair_l[u] = adj;
				pair_r[adj] = u;
				return true;
			}
		}
		return false;
	}
	int max_matching(){
		int res = 0;
		while (bfs()){
			fill(seen.begin(), seen.end(), false);
			for (int i = 0; i < n1; i++)
				if (pair_l[i] == -1 && dfs(i))
					res++;
		}
		return res;
	}
};
int main(){
	ios::sync_with_stdio(false);
	int n; cin >> n;
	hopcroft hop(n, n - 1);
	vector<int> pu(n), pv(n);
	for(int i = 0; i < n - 1; i++){
		int x; cin >> x;
		for(int j = 0; j < x; j++){
			int y; cin >> y; y--;
			hop.add_edge(y, i);
		}
	}
	auto bad = [](){
		cout << -1 << endl;
		exit(0);
	};
	int mx = hop.max_matching();
	if(mx != n - 1) bad();
	vector<int> seen(n, -2);
	queue<int> q;
	int st = -1;
	for(int i = 0; i < n; i++) if(hop.pair_l[i] == -1) st = i;
	if(st == -1) bad();
	q.push(st); seen[st] = -1;
	while(!q.empty()){
		int u = q.front(); q.pop();
		for(int v : hop.to[u]){
			int nv = hop.pair_r[v];
			if(nv != -1 && seen[nv] == -2){
				pu[v] = nv;
				pv[v] = u;
				seen[nv] = u;
				q.push(nv);
			}
		}
	}
	for(int i = 0; i < n; i++) if(seen[i] == -2) bad();
	for(int i = 0; i < n - 1; i++) cout << pu[i] + 1 << " " << pv[i] + 1 << "\n";
	return 0;
}


Measured memory_bytes: 11108
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
constexpr int inf=1e9+7;
constexpr ll longinf=1LL<<60 ;
constexpr ll mod=1e9+7 ;

void solve(int n){
    vector<string>s(n);
    rep(i,n)cin>>s[i];
    vector<int> sz(n);
    rep(i,n)sz[i]=s[i].size();
    rep(i,n){
        int j=0;
        while(s[i][j]=='.')++j;
        --j;
        if(j>=0)s[i][j]='+';
    }
    rep(i,n){
        int j=0;
        while(j<sz[i]&&s[i][j]!='+')++j;
        if(j==sz[i])continue;
        int k=i-1;
        while(k>=0&&sz[k]>j&&s[k][j]=='.'){
            s[k][j]='|';
            --k;
        }
    }
    rep(i,n)rep(j,sz[i])if(s[i][j]=='.')s[i][j]=' ';
    rep(i,n)cout<<s[i]<<endl;
}


int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n;
    while(cin>>n,n!=0)solve(n);
    return 0;
}


Measured memory_bytes: 3440
#include <iostream>
#include <stdio.h>
 
char a[4],b[4],c[4];
 
using namespace std;
 
int main(void)
{
    cin >> a[0] >> a[1] >> a[2];
    cin >> b[0] >> b[1] >> b[2];
    cin >> c[0] >> c[1] >> c[2];
    cout << a[0] << b[1] << c[2];
    return 0;
}

Measured memory_bytes: 256
import sys
from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt, ceil, floor
from collections import deque
from bisect import bisect, bisect_left, bisect_right
from string import ascii_lowercase
from functools import lru_cache, reduce
from operator import xor
INF = float("inf")
sys.setrecursionlimit(10**7)

# 4近傍（右, 下, 左, 上）
dy = [0, -1, 0, 1]
dx = [1, 0, -1, 0]


def inside(y: int, x: int, H: int, W: int) -> bool: return 0 <= y < H and 0 <= x < W


def main():
    H, W, d = map(int, input().split())
    field = [[0] * W for _ in range(H)]

    # 市松模様
    if d % 2 != 0:
        for y in range(H):
            for x in range(W):
                field[y][x] = (y + x) % 2
    elif d % 4 == 2:
        for y in range(H):
            for x in range(W):
                field[y][x] = (y % 2 * 2) + (y // 2 + x // 2) % 2
    else:
        for y in range(H):
            for x in range(W):
                ny = y + x + 1000
                nx = y - x + 1000
                field[y][x] = ny // d % 2 * 2 + nx // d % 2
                if (y + x) % 2 == 1:
                    field[y][x] ^= 3

    c = "RGBY"
    for line in field:
        print("".join(c[x] for x in line))


if __name__ == '__main__':
    main()


Measured memory_bytes: 6124
using System.Linq;
using System;

public class hello
{
    public static void Main()
    {
        var a = new string[] { "K", "U", "P", "C" };
        var an = new int[4];
        var s = Console.ReadLine().Trim();
        var sL = s.Length;
        var i = 0;
        foreach (var x in a)
            an[i++] = sL - s.Replace(x, "").Length;
        Console.WriteLine(an.Min());
    }
}

Measured memory_bytes: 9476
#include<iostream>
#include<cstdio>
#include<vector>
#include<map>
#include<unordered_map>
#include<set>
#include<string>
#include<algorithm>
#include<math.h>
#include<numeric>
#include<iomanip>
#include<queue>
#include<functional>
#include<iso646.h>
#include<bitset>

#ifndef M_PI
#define M_PI 3.14159265358979
#endif
#define deg_to_rad(deg) (((deg)/360)*2*M_PI)
#define rad_to_deg(rad) (((rad)/2/M_PI)*360)

using namespace std;

typedef vector<int> vi;
typedef pair<int, int> pii;
typedef long long ll;
typedef vector<long long> vll;
typedef pair<long long, long long> pll;

const ll INF = 1e15;
const ll MOD = 1e9 + 7;
const ll MAX = 3030;

// 素数ならtrue，そうでなければfalseを返す
bool isprime(ll n) {
	if (n == 1) {
		return false;
	}
	if (n == 2) {
		return true;
	}
	int sq = (ll)sqrt(double(n));
	for (ll i = 2; i <= sq; i++) {
		if (n % i == 0) {
			return false;
		}
	}
	return true;
}

int main() {
	ll i, j;
	ll X;
	cin >> X;
	while (1) {
		if (isprime(X)) {
			cout << X << endl;
			return 0;
		}
		X++;
	}
	//return 0;
}


Measured memory_bytes: 256
import java.io.*
import java.util.*

fun solve(A: Long, B: Long) {
    println((A * B) / gcd(A, B))
    return
}

tailrec fun gcd(x: Long, y: Long): Long = if (y == 0L) x else gcd(y, x % y)

fun main(args: Array<String>) {
    fun StringArray(size: Int, init: (Int) -> String = { "\u0000" }): Array<String> {
        return Array<String>(size, init)
    }
    class Scanner(stream: InputStream) {
        private val reader = BufferedInputStream(stream).bufferedReader()
        private var st: StringTokenizer? = null
        fun next(): String {
            while (!(st?.hasMoreTokens() ?: false)) st = StringTokenizer(reader.readLine())
            return st!!.nextToken()
        }
    }
    val sc = Scanner(System.`in`)
    val A = sc.next().toLong()
    val B = sc.next().toLong()
    solve(A, B)
}


Measured memory_bytes: 31260
#include<bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define erep(i,a,n) for(int i = a;i<=n;i++)
typedef long long ll;
#define int long long
#define vint vector<int>
#define vvint vector<vector<int>>
#define vstring vector<string>
#define vdouble vector<double>
#define vll vector<ll>:
#define vbool vector<bool>
#define INF 1101010101010101010
#define MOD 1000000007
#define P pair<int,int>
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; }

signed main(){
  string s;
  cin >> s;
  int n = s.size();
  rep(i,0,n){
    if(s[i]=='?') s[i] = 'D';
  }
  cout << s << endl;
}

Measured memory_bytes: 3720
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class Main {
	public static void main(String[] args) throws IOException {
		ReaderWriter r = new ReaderWriter();
		int n = r.rInt();		
		int[] array = r.rIntArray(n);
		String ans = "";
		ans += r.wArray(array);

		for(int i = 1; i < n; i++) {
			int key = array[i];
			int j = i-1;
			while(j >= 0 && array[j] > key) {
				array[j+1] = array[j];
				j--;
			}
			array[j+1] = key;
			ans += r.wArray(array);
		}
		
		r.pAns(ans);
		r.out.close();
	}


}

class ReaderWriter {
	BufferedReader br;
	PrintWriter out;
	StringTokenizer st;

	public ReaderWriter() {
		// br = new BufferedReader(new FileReader("in.txt"));
		// out = new PrintWriter(new FileWriter("out.txt"));
		br = new BufferedReader(new InputStreamReader(System.in));
		out = new PrintWriter(new OutputStreamWriter(System.out));
	}

	String next() throws IOException  {
		while (st == null || !st.hasMoreTokens())
			st = new StringTokenizer(br.readLine().trim());
		return st.nextToken();
	}

	long rLong() throws IOException  {
		return Long.parseLong(next());
	}

	int rInt() throws IOException  {
		return Integer.parseInt(next());
	}

	int[] rIntArray(int n) throws IOException  {
		int[] ret = new int[n];
		for(int i = 0; i < n; i++) {
			ret[i] = rInt();
		}
		return ret;
	}

	double rDouble() throws IOException  {
		return Double.parseDouble(next());
	}

	char rChar() throws IOException  {
		return next().charAt(0);
	}

	String rLine() throws IOException  {
		return br.readLine().trim();
	}

	String wArray(int[] a) throws IOException {
		if(a == null || a.length == 0) {
			return "";
		}
		String ret = "" + a[0];
		for(int i = 1; i < a.length; i++) {
			ret = ret + " " + a[i];
		}
		ret = ret + "\n";
		return ret;
	}

	void pAns(String ans) {
	//	if(ans.charAt(ans.length()-1) == '\n')
	//		ans = ans.substring(0,ans.length()-1);
		System.out.print(ans);
	}
}




Measured memory_bytes: 58108
import sys
input = sys.stdin.readline

def calc(l):
    l2 = l[::-1]
    res = l2[0]
    
    for i in range(1, len(l2)):
        if l2[i-1]-1>l2[i]:
            print(-1)
            exit()
            
        if l2[i]!=l2[i-1]-1:
            res += l2[i]

    return res

N = int(input())
A = [int(input()) for _ in range(N)]

for i in range(N):
    if A[i]>i:
        print(-1)
        exit()

ans = 0
l = []

for i in range(N):
    if i==N-1 or A[i]>A[i+1]:
        l.append(A[i])
        ans += calc(l)
        l = []
    else:
        l.append(A[i])

print(ans)

Measured memory_bytes: 64220
from sys import stdin


if __name__ == "__main__":
    _in = [_.rstrip() for _ in stdin.readlines()]
    N, M = list(map(int,_in[0].split(' ')))  # type:list(int)
    A_arr = list(map(int,_in[1].split(' ')))  # type:list(int)
    # vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
    cnt = -1 if N - sum(A_arr)<0 else N - sum(A_arr)
    # ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    print(cnt)


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

using namespace std;
typedef long long ll;

#define MOD (long long)(1e9+7)
#define INF (1LL<<60)
#define rep(i,n) for(ll i = 0; i < (n); i++)
#define rep1(i,n) for(ll i = 1; i <= (n); i++)

template<class T> inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template<class T> inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}


// 最大公約数
ll gcd(ll a, ll b)
{
  if(b == 0) return a;
  return gcd(b, a % b);
}

// mod m におけるa の逆元
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;
}

// 素因数分解
vector<pair<ll, ll>> prim;
void pf(ll n)
{
  ll s = sqrt(n);
  ll r = 0;
  for(ll i = 2; i <= s; i++) {
    if((n % i) == 0) {
      r = 0;
      do {
	r++;
	n = n / i;
      } while((n % i) == 0);
      prim.push_back({i, r});
    }
  }
  if(n > s) {
    prim.push_back({n, 1});
  }
}


bool add1(vector<ll> &a)
{
  bool ok = true;
  ll n = a.size();
  while(n > 0) {
    n --;
    a[n] ++;
    if(a[n] < 10) {
      break;
    }
    a[n] = 0;
    if(n == 0) ok = false;
  }
  return ok;
}
  

void solve()
{
  ll N; cin >> N;
  // ll N, K; cin >> N >> K;
  // ll x, y, z; cin >> x >> y >> z;
  // ll a, b, c; cin >> a >> b >> c;
  // string s; cin >> s;
  ll ans = 0;
  ll a = 1, a9 = 1, a8 = 1;

  rep(i, N) {
    a *= 10;
    a %= MOD;
    a9 *= 9;
    a9 %= MOD;
    a8 *= 8;
    a8 %= MOD;
  }
  ans = (a + a8) % MOD;
  ans = (ans - ((a9 * 2) % MOD)) % MOD;
  if(ans < 0) ans += MOD;
  cout << ans << endl;
}


int main(void)
{
  // ll t; cin >> t; rep(i, t)
  solve();
}


Measured memory_bytes: 3680
import math
d, g = map(int, input().split())
p = [0] * d
c = [0] * d

for i in range(d):
    p[i], c[i] = map(int, input().split())

# 完全に解く 1
# 全く解かない 0
min_cost = 10**10
for i in range(2**d):
    count = 0
    score = 0
    use_list = []
    for bit in range(d):
        if i & 2 ** bit > 0:
            use_list.append(bit + 1)
            count += p[bit]
            score += (bit + 1) * 100 * p[bit] + c[bit]
    if score < g:
        p_i = max(set(range(1, d+1)) - set(use_list))
        p_count = math.ceil((g - score) / (p_i * 100))
        if p_count <= p[p_i - 1]:
            count += p_count
            score += p_count * (p_i * 100)
    if score >= g:
        min_cost = min(min_cost, count)
print(min_cost)


Measured memory_bytes: 42972
#include<iostream>
#include<cmath>
#include<string>
#include<cstring>
#include<algorithm>
#include<iomanip>
#include<cstdio>
#include<stack>
#include<queue>
using namespace std;
typedef long long ll;
const double P=acos(-1.0);
int main(){
	double a,b,h,m;
	cin>>a>>b>>h>>m;
	double o;
	o=(h*5.0+m/12.0-m)*6;
	//cout<<o<<endl;
	if(abs(o)>=180) o=360-abs(o);
	else o=abs(o);
	double x=o*P/180;
	double ans=sqrt(a*a+b*b-2*a*b*cos(x));
	cout<<fixed<<setprecision(20)<<ans<<endl;
	return 0;
}


Measured memory_bytes: 3616
n=input('')
k=[]
for a in n:
    k.append(a)

s=k[-1]

if s=='0'or s=='1' or s=='6' or s=='8':
    print('pon')
elif s=='2' or s=='4' or s=='5' or s=='7' or s=='9':
    print('hon')
elif s=='3':
    print('bon')

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

int main()
{
  int n; cin >> n;
  int x[n];
  for(int i=0; i<n; i++) cin >> x[i];
  int ans = 1e9;
  for(int p=1; p<=100; p++){
  	int stamina = 0;
    for(int i=0; i<n; i++) stamina += (x[i]-p)*(x[i]-p);
    ans = min(ans, stamina);
  }
  cout << ans << endl;
  
}

Measured memory_bytes: 256
import java.util.*;
public class Main {
    public static void main(String [] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        Set<Integer> s = new HashSet<>();
        for(int i=0;i<n;i++) s.add(sc.nextInt());
        ArrayList<Integer> S = new ArrayList<>(s);
        int q = sc.nextInt();
        int T[] = new int[q];
        for(int i=0;i<q;i++)T[i] = sc.nextInt();
        int cnt = 0;
        for(int i=0;i<S.size();i++){
            for(int j=0;j<q;j++){
                if(S.get(i)==T[j]){
                    cnt++;
                    break;
                }
            }
        }
        System.out.println(cnt);
    }
}


Measured memory_bytes: 40220
// Copyright 2017 wu_qing
#include <cstdio>
#include <algorithm>
const int N = 210;
int n, a[N], ans = 0;
int main() {
    scanf("%d", &n);
    for (int i = 0; i < 2 * n; i++)
        scanf("%d", a + i);
    std::sort(a, a + n * 2);
    for (int i = 0; i < 2 * n; i += 2)
        ans += a[i];
    printf("%d\n", ans);
    return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define ll long long
const int maxn=100005;
int a[maxn]; 
int main() {
	int n;
	cin>>n;
	for(int i=1;i<=n;i++) cin>>a[i];
	sort(a+1,a+n+1);
	double ave=(a[1]+a[2])/2.0;
	for(int i=3;i<=n;i++) {
		ave=(ave+a[i])/2;
	}
	cout<<ave;
	return 0;
}


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

int main(void){
    int N, X;
    cin >> N >>X;
    
    vector<int> L(N);
    for (int i = 0; i < N; i++) {
    			cin >> L.at(i);
  	}
  	
    int count =1;
  	int sum=0;
 	for (int i = 0; i < N; i++) {
    		sum+= L.at(i);
      		if(sum<=X) count++; 
  	}
     
  	cout<< count << endl; 
  	
    
}

Measured memory_bytes: 256
#include <cstdio>
#include <string>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <list>
#include <iterator>
#include <cassert>
#include <numeric>
#include <functional>
#include <time.h>

#pragma warning(disable:4996) 

typedef long long ll;
typedef unsigned long long ull;
#define MIN(a, b) ((a)>(b)? (b): (a))
#define MAX(a, b) ((a)<(b)? (b): (a))
#define LINF  9223300000000000000
#define LINF2 1223300000000000000
#define LINF3 1000000000000
#define INF 2140000000
const long long MOD = 1000000007;
//const long long MOD = 998244353;

using namespace std;


ll mpow(ll x, ll n) { //x^n(mod M)
    ll ans = 1;
    while (n != 0) {
        if (n & 1) ans = ans * x % MOD;
        x = x * x % MOD;
        n = n >> 1;
    }
    return ans;
}

ll minv(ll x) {
    return mpow(x, MOD - 2);
}

void solve()
{
    int n;
    scanf("%d", &n);
    
    ll ans = (mpow(10, n) - mpow(9, n) - mpow(9, n) + mpow(8, n) + MOD + MOD) % MOD;
    printf("%lld\n", ans);

    return;
}

int main()
{
#if 1
    solve();
#else
    int T;
    scanf("%d", &T);
    int t;
    for (t = 0; t < T; t++) {
        //printf("Case #%d: ", t + 1);
        solve();
    }
#endif
    return 0;
}



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

class UnionFind{
public:
    V parent;
    UnionFind(int n){
        parent = V(n, -1);
    }
    int root(int a){
        if (parent[a] < 0)
        {
            return a;
        }
        else
        {
            return parent[a] = root(parent[a]);
        }
    }
    int size(int a){
        return -parent[root(a)];
    }
    bool connect(int a, int b){
        a = root(a);
        b = root(b);
        if (a == b)
        {
            return false;
        }
        else
        {
            if (size(a) < size(b)){
                swap(a, b);
            }
            parent[a] += parent[b];
            parent[b] = a;
            return true;
        }
    }
};

int main()
{
    int n,m;
    cin >> n >> m;
    V a(m), b(m);
    for (int i = 0; i < m; i++)
    {
        cin >> a[i] >> b[i];
        a[i]--;
        b[i]--;
    }
    vector<ll> ans(m);
    ans[m-1] = (ll)n*(n-1)/2;
    UnionFind uni(n);
    for (int i = m-1; i > 0 ; i--)
    {
        ans[i-1] = ans[i];
        if (uni.root(a[i]) != uni.root(b[i]))
        {
            ans[i-1] -= (ll)uni.size(a[i])*uni.size(b[i]);
            uni.connect(a[i], b[i]);
        }
    }
    for (int i = 0; i < m; i++)
    {
        OUT(ans[i]);
    }
}

Measured memory_bytes: 3328
import java.util.*;

class Main {
  public static void main (String[] args) {
    Scanner scanner = new Scanner(System.in);
    while (scanner.hasNext()) {
      int n = scanner.nextInt();
      if (n == 0) {
        break;
      }
      int[] ages = new int[7];
      int c = 0;
      for (int ii = 0; ii < n; ii++) {
        int a = scanner.nextInt();
        if (a < 10) {
          c = 0;
        } else if (a < 20) {
          c = 1;
        } else if (a < 30) {
          c = 2;
        } else if (a < 40) {
          c = 3;
        } else if (a < 50) {
          c = 4;
        } else if (a < 60) {
          c = 5;
        } else {
          c = 6;
        }
        ages[c]++;
      }
      for (int ii = 0; ii < 7; ii++) {
        System.out.println(ages[ii]);
      }
    }
  }
}

Measured memory_bytes: 209672
#include <bits/stdc++.h> 
 
using namespace std;
 
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
 
 
//typedef
//------------------------------------------
typedef pair<int, int> PII;
typedef long long LL;
typedef pair<LL, LL> PLL;
 
//container util
//------------------------------------------
#define PB emplace_back
#define MP make_pair 
#define SZ(a) int((a).size())
//repetition
//------------------------------------------
#define FOR(i,a,b) for(LL i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define SORT(c) sort((c).begin(),(c).end())
//constant
//--------------------------------------------
//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))

struct edge{int to,cost;};
typedef pair<int,int> P;//firstは最短距離,secondは頂点番号
const LL INF=LONG_LONG_MAX;
const int MAX_V=1e5+3;
int V;
vector<edge> G[MAX_V];
LL d[MAX_V];

bool dijkstra(int s){
    priority_queue<P,vector<P>,greater<P> > que;
    fill(d,d+V,INF);
    d[s]=0;
    que.push(P(0,s));
    while(!que.empty()){
        P p=que.top();que.pop();//仮の最短距離が短い順に取り出す
        int v=p.second;
        if(d[v]<p.first)continue;
        REP(i,G[v].size()){
            edge e=G[v][i];
            if(d[e.to]>d[v]+e.cost){
                if(d[e.to]!=INF)return false;
                d[e.to]=d[v]+e.cost;
                que.push(P(d[e.to],e.to));//仮の最短距離と頂点の組を更新が行われる度に追加していく
            }
        }
    }
    return true;
}
struct UnionFind
{
    vector<int> par;
    vector<int> sizes;
    vector<int> rnk;
    UnionFind(){}
    UnionFind(int n){
        par.resize(n);rnk.resize(n,0);
        sizes.resize(n, 1);
        REP(i,n) par[i] = i;
    }

    int find(int x) {
        if (x == par[x]) return x;
        return par[x] = find(par[x]);
    }

    void unite(int x, int y) {
        x = find(x);
        y = find(y);
        if(x==y)return;
        if(rnk[x]<rnk[y]){
            par[x]=y;
            sizes[y]+=sizes[x];
        }else{
            par[y]=x;
            sizes[x]+=sizes[y];
            if(rnk[x]==rnk[y])rnk[x]++;
        }
    }

    bool same(int x, int y) {
        return find(x) == find(y);
    }
    int size(int x) {
        return sizes[find(x)];
    }
};
bool st[MAX_V];
int main(){
    int N,M;
    cin>>N>>M;
    V=N;
    UnionFind uf(N);
    REP(i,M){
        int l,r,d;
        cin>>l>>r>>d;l--;r--;
        edge e{r,d};
        edge e2{l,-d};
        uf.unite(r,l);
        G[l].PB(e);G[r].PB(e2);
    }
    CLR(st);
    REP(i,N){
        int t=uf.find(i);
        if(st[t]==0&&uf.size(t)>1){
            st[t]=1;
            if(!dijkstra(t)){
                cout<<"No"<<endl;
                return 0;
            }
        }
    }
    cout<<"Yes"<<endl;
    return 0;
}


Measured memory_bytes: 11892
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cstring>

#include <algorithm>
#include <numeric>
#include <functional>
#include <vector>

#define LOG(FMT...) fprintf(stderr, FMT)

using namespace std;

typedef long long ll;

const int N = 100010;

int x[N];

int main() {
#ifdef LBT
  freopen("test.in", "r", stdin);
#endif

  int n, k;
  scanf("%d%d", &n, &k);
  for (int i = 1; i <= n; ++i)
    scanf("%d", &x[i]);
  int p = 1;
  while (x[p] < 0) ++p;
  int ans = 1e9;
  if (0 == x[p] && p <= n) {
    for (int i = 1; i <= n - k + 1; ++i)
      if (i <= p && i + k - 1 >= p)
        ans = min(ans, -x[i] + x[i + k - 1] + min(-x[i], x[i + k - 1]));
  } else {
    if (p > k) ans = -x[p - k];
    if (p + k - 1 <= n) ans = min(ans, x[p + k - 1]);
    for (int i = 1; i <= n - k + 1; ++i)
      if (i < p && i + k - 1 >= p)
        ans = min(ans, -x[i] + x[i + k - 1] + min(-x[i], x[i + k - 1]));
  }
  printf("%d\n", ans);

  return 0;
}


Measured memory_bytes: 640