akhauriyash/Code-Regression huggingface dataset:
//↓template↓

#include "bits/stdc++.h"
using namespace std;
#define Would
#define you
#define all(n)  n.begin(),n.end()
const long long INF = 1e18;
const long long MOD = 1e9 + 7;
const double pi = acos(-1);
const long long SIZE = 1 << 17;
int dx[] = { 1,0,-1,0 }, dy[] = { 0,1,0,-1 }, alp[30];
long long fac[200005], finv[200005], inv[200005];
vector<long long>dij;
struct edge { long long to, cost; };
vector<vector<edge> >G;

long long mod_pow(long long a, long long b) {
	long long res = 1, mul = a;
	for (int i = 0; i < 31; ++i) {
		if (b >> i & 1) {
			res *= mul;
			res %= MOD;
		}
		mul = (mul * mul) % MOD;
	}

	return res;
}

void addedge(int from, int to, int cost) {
	G[from].push_back({ to,cost });
	G[to].push_back({ from,cost });
}

//↑template↑





long long a, b, c, ans[10], current = 1, rem;
int main() {
	cin >> a >> b >> c;
	--a; --b;
	vector<pair<long long, long long>>v(c), p;
	for (int i = 0; i < c; ++i) { cin >> v[i].first >> v[i].second; --v[i].first, --v[i].second; }

	for (int i = 0; i < v.size(); ++i) {
		for (int j = 0; j < 3; ++j) {
			for (int k = 0; k < 3; ++k) {
				if (v[i].first - j >= 0 && v[i].first - j <= a - 2 && v[i].second - k >= 0 && v[i].second - k <= b - 2) { p.push_back(make_pair(v[i].first - j, v[i].second - k)); }
			}
		}
	}
	sort(all(p));
	if (p.size() != 0) {
		pair<long long, long long>mon = p[0];
		for (int i = 1; i < p.size(); ++i) {
			if (p[i] == mon) { ++current; }
			else { ++ans[current]; ++rem; current = 1; mon = p[i]; }
		}
		++ans[current]; ++rem;
		ans[0] = (a - 1)*(b - 1) - rem;
	}
	else { ans[0] = (a - 1)*(b - 1); }
	for (int i = 0; i < 10; ++i) { cout << ans[i] << endl; }
}

Measured memory_bytes: 19944
s=gets.chomp.split("")
t=[]
ans=Array.new(s.size,0)
c,o,e=0,0,0
for i in 0..s.size-1
  if s[i]=="R"
    c+=1
    o+=1 if c%2==1
    e+=1 if c%2==0
  else
    if c%2==0
      ans[i]+=o
      ans[i-1]+=e
    else
      ans[i]+=e
      ans[i-1]+=o
    end
    c,o,e=0,0,0
  end
end
s.reverse!
ans.reverse!
c,o,e=0,0,0
for i in 0..s.size-1
  if s[i]=="L"
    c+=1
    o+=1 if c%2==1
    e+=1 if c%2==0
  else
    if c%2==0
      ans[i]+=o
      ans[i-1]+=e
    else
      ans[i]+=e
      ans[i-1]+=o
    end
    c,o,e=0,0,0
  end
end
ans.reverse!
for i in 0..s.size-1
  printf "#{ans[i]} "
end


Measured memory_bytes: 10516
/*
	  Chase
	   Your
	  Legend

	英雄志逐传奇
*/

#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <math.h>
#include <stdio.h>

#define rep(i, n) for(int i = 0; i < (n); i++)
typedef long long ll;
using namespace std;

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

	vector<char>vec(n);
	rep(i, n) {
		cin >> vec[i];
	}

	int p = -1;
	int w = -1;
	int g = -1;
	int y = -1;

	rep(i, n) {
		if (vec[i] == 'G') {
			g = 1;
		}
		else if (vec[i] == 'W') {
			w = 1;
		}
		else if (vec[i] == 'Y') {
			y = 1;
		}
		else if (vec[i] == 'P') {
			p = 1;
		}

	}


	if (g == 1 && w == 1 && g == 1 && y == 1) {
		cout << "Four" << endl;
	}
	else {
		cout << "Three" << endl;
	}
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(){
  int a,b,c,d,h1,h2,k1,k2;
  cin >>h1>>h2>>k1>>k2>>a>>b>>c>>d;
  h1=h1*a+(h1/10)*c;
  h2=h2*b+(h2/20)*d;
  k1=k1*a+(k1/10)*c;
  k2=k2*b+(k2/20)*d;
  if((h1+h2)==(k1+k2))cout << "even" <<endl;
  else if(h1+h2>k1+k2)cout <<"hiroshi" <<endl;
  else cout <<"kenjiro" <<endl;
   return 0;
 }

Measured memory_bytes: 3100
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <utility>
#include <sstream>
#include <complex>
#include <numeric>
#include <iomanip>

using namespace std;

#define FOR(i,a,b) for(long long i=(a);i<(b);i++)
#define REP(i,N) for(long long i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define fi first
#define se second

#define PI acos(-1.0)
#define INF 1000000007
#define EPS 1e-10
#define MAX_N 20000
#define MAX_M 16

typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<double, double> PD;
typedef pair<string, ll> PS;
typedef vector<ll> V;
typedef pair<P, char> PC;

int n;
double dx1, dx2, dx3, dy1, dy2, dy3;

int main(){
	cin >> n;
	REP(i, n){
		cin >> dx1 >> dy1 >> dx2 >> dy2 >> dx3 >> dy3;
		double a = 2 * (dx1 - dx2), b = 2 * (dy1 - dy2), c = (dx1*dx1 + dy1*dy1) - (dx2*dx2 + dy2*dy2);
		double d = 2 * (dx2 - dx3), e = 2 * (dy2 - dy3), f = (dx2*dx2 + dy2*dy2) - (dx3*dx3 + dy3*dy3);
		double x, y;
		//if (a < 0){
		//	a = -a;
		//	b = -b;
		//	c = -c;
		//}
		//if (d < 0){
		//	d = -d;
		//	e = -e;
		//	f = -f;
		//}
		//if (a == 0){
		//	y = c / b;
		//	x = (f - e*y) / d;
		//}
		//else if (b == 0){
		//	x = c / a;
		//	if (d == 0) y = f / e;
		//	else y = (f - e*x) / d;
		//}
		//else if (a != 0 && b != 0){
			x = (b*f - c*e) / (b*d - a*e);
			y = (c*d - a*f) / (b*d - a*e);
		//}
		cout << fixed << setprecision(3) << x << " " << y << " " << sqrt((dx1 - x)*(dx1 - x) + (dy1 - y)*(dy1 - y)) << endl;
	}
}

Measured memory_bytes: 1288
#include <bits/stdc++.h>
using namespace std;
#define sd(x) scanf("%d", &x)
#define sz(v) (int) v.size()
#define pr(v) For(i, 0, sz(v)) {cout<<v[i]<<" ";} cout<<endl;
#define slld(x) scanf("%lld", &x)
#define all(x) x.begin(), x.end()
#define For(i, st, en) for(ll i=st; i<en; i++)
#define tr(x) for(auto it=x.begin(); it!=x.end(); it++)
#define fast std::ios::sync_with_stdio(false);cin.tie(NULL);
#define pb push_back
#define ll long long
#define int long long
#define mp make_pair
#define F first
#define S second
typedef pair<int, int> pii;
typedef vector<int> vi;
#define MOD 1000000007
#define INF 1000000000000000007LL

const int N = 100005;
 
// it's swapnil07 ;)
 
#ifdef SWAPNIL07
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    cout << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma = strchr(names + 1, ',');cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
int begtime = clock();
#define end_routine() cout << "\n\nTime elapsed: " << (clock() - begtime)*1000/CLOCKS_PER_SEC << " ms\n\n";
#else
#define endl '\n'
#define trace(...)
#define end_routine()
#endif

#define PI 3.14159265358979

signed main()
{
    fast
    #ifdef SWAPNIL07
        freopen("input.txt","r",stdin);
        freopen("output.txt","w",stdout);
    #endif
    double r; cin>>r;
    double ans = 2.0*PI*r;
    cout<<fixed<<setprecision(10)<<ans;
    return 0;
}






Measured memory_bytes: 3800
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.List;

public class Main {

    public static void main(String[] args) throws IOException {

        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));


        List<Character> alpha = Arrays.asList('a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z');
        //int[] index = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25};
        boolean[] visited = new boolean[26];

        char[] cs = reader.readLine().toCharArray();

        for (int i = 0; i < cs.length; i++) {
            int pos = alpha.indexOf(cs[i]);

//            System.out.print(cs[i]);

            if (visited[pos] == false)
                visited[pos] = true;
            else {
                System.out.print("no");
                return;
            }

        }

        System.out.print("yes");
//        PrintWriter writer = new PrintWriter(System.out);
//
//        writer.close();


    }
}


Measured memory_bytes: 22612
#include <bits/stdc++.h>
#define cal(a,b) ((a+=b)%=mo)
using namespace std;
const int N=2050,mo=1e9+7;
int f[N][N][2];
int main(){
  int n,k; cin>>n>>k;
  f[n+1][0][0]=1;
  for (int i=n+1; i>1; --i){
    for (int j=n; j>=0; --j) cal(f[i][j][0],f[i][j+1][0]);
    for (int j=0; j<=n; ++j)
      for (int t=0; t<=1; ++t){
	cal(f[i-1][j][0],f[i][j][t]);
	cal(f[i-1][j+1][1],f[i][j][t]);
      }
  }
  int ans=f[1][n-k][0];
  for (int i=1; i<n-k; ++i) cal(ans,ans);
  cout<<ans;
  return 0;
}


Measured memory_bytes: 33024
#define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_WARNINGS

#include <iostream>
#include <string>
#include <sstream>
#include <iomanip>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <utility>
#include <numeric>

using namespace std;
typedef long long llong;
typedef unsigned long long ullong;

const ullong MOD = 1000000000 + 7;

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

	int minn = 9999999;
	for (int i = 1; i <= sqrt(n); i++)
	{
		if (n % i == 0)
		{
			ullong j = n / i;
			int x = max(to_string(i).length(), to_string(j).length());
			minn = min(minn, x);
		}
	}

	cout << minn << endl;
}

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

int main() {
	int N, X, m,min=1000, sum=0,cnt;

	cin >> N >> X;

	for (int i = 1; i <= N; i++) {
		cin >> m;

		if( m < min)
			min = m;

		sum = sum + m;

	}
	
	cnt = N + (X - sum) / min;
	
	cout << cnt;

	return 0;
}

Measured memory_bytes: 256
Nin = input()
l = len(Nin)
fow = int(Nin[0])

all9 = True
for n in Nin[1:]:
    if n != '9':
        all9 = False
if all9:
    ans = fow+(l-1)*9
else:
    ans = fow-1+(l-1)*9
print(ans)

Measured memory_bytes: 3060
#include<stdio.h>
#include<stdlib.h>
#define M 2000001
#define V 10000

main(){
  unsigned short *A, *B;

  int C[V+1];
  int n, i, j;
  scanf("%d", &n);

  A = malloc(sizeof(short)*n+1);
  B = malloc(sizeof(short)*n+1);

  for ( i = 0; i <= V; i++ ) C[i] = 0;

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

  for ( i = 1; i <= V; i++ ) C[i] = C[i] + C[i-1];

  for ( j = 1; j <= n; j++ ){
    B[C[A[j]]] = A[j];
    C[A[j]]--;
  }

  for ( i = 1; i <= n; i++ ){
    if ( i > 1 ) printf(" ");
    printf("%d", B[i]);
  }
  printf("\n");
  return 0;
}



Measured memory_bytes: 9640
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0; i<n; i++)
#define eb(t) emplace_back(t)
typedef long long ll;
typedef long long unsigned int llu;
ll MOD = 1000000007;
ll INF = 1000000009;

void solve(){

    string s;
    cin >> s;
    deque<char> d;
    rep(i,s.size()){
        d.push_back(s[i]);
    }
    ll q;
    cin >> q;
    ll e = 0;
    rep(i,q){
        ll t;
        cin >> t;
        if(t==1){
            e++;
            continue;
        }
        ll f;
        cin >> f;
        char c;
        cin >> c;
        if(e%2==0 && f==1) {
            d.push_front(c);
            continue;
        }
        if(e%2==1 && f==2) {
            d.push_front(c);
            continue;
        }
        d.push_back(c);
    }

    /*
    rep(i,d.size()){
        cout << d[i];
    }
    cout << endl;
    */

    string ans = "";
    ll x = d.size();
    rep(i,x){
        ans += d.front();
        d.pop_front();
    }
    
    if(e%2==1) reverse(ans.begin(), ans.end());
    //reverse(topst.begin(), topst.end());

    //cout << topst << s << endl;
    cout << ans << endl;

}

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


Measured memory_bytes: 1368
import java.util.*;
public class Main {

	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		int t=sc.nextInt();
		sc.nextLine();
		int ac=0;
		int tle=0;
		int wa=0;
		int re=0;
	    while(t-->0) {
	    	String str=sc.nextLine();
	    	if(str.equals("AC")) ac++;
	    	if(str.equals("TLE")) tle++;
	    	if(str.equals("WA")) wa++;
	    	if(str.equals("RE")) re++;
	    }
	    
	    System.out.println("AC"+" "+"x"+" "+ac);
	    System.out.println("WA"+" "+"x"+" "+wa);
	    System.out.println("TLE"+" "+"x"+" "+tle);
	    System.out.println("RE"+" "+"x"+" "+re);
	}

}


Measured memory_bytes: 51372
# A0J 0005
# 最大公約数と最小公倍数

def gcd(a, b)
  if b.zero?
    a
  else
    gcd(b, a % b)
  end
end

def lcm(a, b)
  d = gcd(a, b)
  d * (a / d) * (b / d)
end

pairs = ARGF.each_line.map {|line| line.split(" ").map {|x| x.to_i}}
pairs.each do |a, b|
  puts [gcd(a, b), lcm(a, b)].join(" ")
end

Measured memory_bytes: 6108
#include <iostream>
#include <stack>
#include <string>

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

using namespace std;

int main(void){
	for(string in; getline(cin, in) && in != ".";){
		stack<char> table;
		string out = "yes";

		rep(i, in.length()){
			char curChar = in.at(i);
			if(curChar == '[' || curChar == '(') table.push(curChar);
			else if(curChar == ']'){
				if(!table.empty() && table.top() == '[') table.pop();
				else{ out = "no"; break; }
			}
			else if(curChar == ')'){
				if(!table.empty() && table.top() == '(') table.pop();
				else{ out = "no"; break; }
			}
		}
		if(!table.empty()) out = "no";
		cout << out << endl;
	}

	return 0;
}

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

int main(){
    ll n,k,q; cin >> n >> k >> q;
    vector<int> att(n);
    int a;
    rep(i,q){
        cin >> a;
        att[a-1]++;
    }
    rep(i,n){
        if(k + att[i] - q > 0) cout << "Yes" << endl;
        else cout << "No" << endl;
    }
}

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

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

int N,M;
int A[1010],B[1010],R[1010];
vector<pair<int,int>> E[101];
int mat[101][101];

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>N>>M;
	FOR(x,N) FOR(y,N) mat[x][y]=(x==y)?0:1<<25;
	FOR(i,M) {
		cin>>A[i]>>B[i]>>R[i];
		A[i]--;
		B[i]--;
		mat[A[i]][B[i]]=mat[B[i]][A[i]]=R[i];
	}
	FOR(k,N) FOR(i,N) FOR(j,N) mat[i][j]=min(mat[i][j],mat[i][k]+mat[k][j]);
	
	int ng=0;
	FOR(i,M) {
		int ok=0;
		FOR(x,N) FOR(y,N) {
			if(mat[x][y]==mat[x][A[i]]+mat[B[i]][y]+R[i]) ok=1;
			if(mat[x][y]==mat[x][B[i]]+mat[A[i]][y]+R[i]) ok=1;
		}
		if(ok==0) ng++;
	}
	cout<<ng<<endl;
	
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n';
	FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	solve(); return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <algorithm>	// require sort next_permutation count __gcd reverse etc.
#include <cstdlib>	// require abs exit atof atoi 
#include <cstdio>		// require scanf printf
#include <functional>
#include <numeric>	// require accumulate
#include <cmath>		// require fabs
#include <climits>
#include <limits>
#include <cfloat>
#include <iomanip>	// require setw
#include <sstream>	// require stringstream 
#include <cstring>	// require memset
#include <cctype>		// require tolower, toupper
#include <fstream>	// require freopen
#include <ctime>		// require srand
#define rep(i,n) for(int i=0;i<(n);i++)
#define ALL(A) A.begin(), A.end()

using namespace std;

typedef long long ll;
typedef pair<int, int> P;

const int max_n = 4*100005;
int n;
int dat[max_n];

// 初期化
void init_seg (int n_ )
{
	// 簡単の為、要素数を2のべき乗に
	n = 1;
	while (n < n_ ) n *= 2;

	// すべての値を INT_MAX に
	rep (i, 2*n - 1 ) dat[i] = INT_MAX;
}

// k 番目の値 ( 0-indexed ) を a に変更
void update (int k, int a )
{
	// 葉の節点
	k += n - 1;
	dat[k] = a;

	// 登りながら更新
	while (k > 0 ){
		k = (k - 1 )/2;
		dat[k] = min (dat[2*k + 1], dat[2*k + 2] );
	} // end while
}

/*
	[a, b ) の最小値を求める
	後ろの方の引数は、計算の簡単なための引数
	k は節点の番号、l, r はその節点 [l, r ) に対応づいていることを表す
	したがって、外からは query (a, b, 0, 0, n ) として呼ぶ
 */
int query (int a, int b, int k, int l, int r )
{
	// [a, b ) と [l, r ) が交差しなければ INT_MAX
	if (r <= a || b <= l ) return INT_MAX;

	// [a, b ) が [l, r ) を完全に含んでいれば、この節点の値
	if (a <= l && r <= b ) return dat[k];
	else{
	// そうでなければ、2つの子の最小値
		int vl = query (a, b, 2*k + 1, l, (l+r)/2 );
		int vr = query (a, b, 2*k + 2, (l+r)/2, r );
		return min (vl, vr );
	} // end if
}

int main()
{
	ios_base::sync_with_stdio(0);
	int n_, q; cin >> n_ >> q;
	init_seg (n_ );

	rep (i, q ){
		int com, x, y; cin >> com >> x >> y;
		if (com == 0 ){	// update
			update (x, y );
		}else{			// find 
			int res = query (x, y+1, 0, 0, n );
			cout << res << endl;
		} // end if
	} // end loop
		
	return 0;
}

Measured memory_bytes: 2228
#include<algorithm>//sort,二分探索,など
#include<bitset>//固定長bit集合
#include<cmath>//pow,logなど
#include<complex>//複素数
#include<deque>//両端アクセスのキュー
#include<functional>//sortのgreater
#include<iomanip>//setprecision(浮動小数点の出力の誤差)
#include<iostream>//入出力
#include<iterator>//集合演算(積集合,和集合,差集合など)
#include<map>//map(辞書)
#include<numeric>//iota(整数列の生成),gcdとlcm(c++17)
#include<queue>//キュー
#include<set>//集合
#include<stack>//スタック
#include<string>//文字列
#include<unordered_map>//イテレータあるけど順序保持しないmap
#include<unordered_set>//イテレータあるけど順序保持しないset
#include<utility>//pair
#include<vector>//可変長配列
using namespace std;



int main() {
  int N;
  cin >> N;
  string Ns;
  Ns = to_string(N);
  if(Ns.at(0) == '7' || Ns.at(1) == '7' || Ns.at(2) == '7'){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
  
}


Measured memory_bytes: 3660
#include<iostream>
#include<vector>
using namespace std;
using ll = long long;
using db = double;

//cin.tie(0);
//ios::sync_with_stdio(false);



signed main(){
    int m,d;cin>>m>>d;
    int ans=0;
    for(int i=1;i < m+1;i++)
    {
        for(int j=22;j < d+1;j++)
        {
            if(i==(j%10)*(j/10) && (j%10)>1 && (j/10)>1){
                ans++;
            }
        }
    }
    cout<<ans<<endl;


}

Measured memory_bytes: 764
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>

#include <algorithm>
#include <bitset>
#include <complex>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>

#include <cassert>
#include <functional>

typedef long long ll;
using namespace std;

#ifndef LOCAL
#define debug(...) ;
#else
#define debug(...) cerr << __LINE__ << " : " << #__VA_ARGS__ << " = " << _tostr(__VA_ARGS__) << endl;

template<typename T>
ostream &operator<<(ostream &out, const vector<T> &v);

template<typename T1, typename T2>
ostream &operator<<(ostream &out, const pair<T1, T2> &p) {
  out << "{" << p.first << ", " << p.second << "}";
  return out;
}

template<typename T>
ostream &operator<<(ostream &out, const vector<T> &v) {
  out << '{';
  for (const T &item : v) out << item << ", ";
  out << "\b\b}";
  return out;
}

void _tostr_rec(ostringstream &oss) {
  oss << "\b\b \b";
}

template<typename Head, typename... Tail>
void _tostr_rec(ostringstream &oss, Head &&head, Tail &&... tail) {
  oss << head << ", ";
  _tostr_rec(oss, forward<Tail>(tail)...);
}

template<typename... T>
string _tostr(T &&... args) {
  ostringstream oss;
  int size = sizeof...(args);
  if (size > 1) oss << "{";
  _tostr_rec(oss, forward<T>(args)...);
  if (size > 1) oss << "}";
  return oss.str();
}
#endif

#define mod 1000000007 //1e9+7(prime number)
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define SIZE 200010

ll dp[SIZE][2];

int main() {
  int N, A[SIZE];

  cin >> N;
  for (int i = 0; i < N; i++) cin >> A[i];

  for (int i = 0; i <= N; i++) dp[i][0] = dp[i][1] = -LLINF;
  dp[0][0] = 0;

  for (int i = 0; i < N; i++) {
    dp[i + 1][0] = max(dp[i][0] + A[i], dp[i][1] - A[i]);
    dp[i + 1][1] = max(dp[i][0] - A[i], dp[i][1] + A[i]);
  }

  cout << dp[N][0] << endl;

  return 0;
}

Measured memory_bytes: 5580
#include <cstdio>
#include <iostream>
using namespace std;
int N, arr[25], Max, result;

int main()
{
    scanf("%d", &N);
    for(int i = 0; i < N; i++)
    {
        scanf("%d", &arr[i]);
        if(Max <= arr[i])
        {
            Max = arr[i];
            result++;
        }
    }
    printf("%d", result);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define vi vector<int>
const int INF = 1e9;
using namespace std;
int main(){
    int h, w;
    cin >> h >> w;
    vector<vector<char>> grid(h+1, vector<char>(w+1));
    vector<vi> v(h+1, vi(w+1,INF));
    for (int i = 0; i < h; ++i) {
        for (int j = 0; j < w; ++j) {
            cin >> grid[i][j];
        }
    }
    v[0][0] = 0;
    if(grid[0][0] == '#') v[0][0] = 1;
    for (int i = 0; i < h; ++i) {
        for (int j = 0; j < w; ++j) {
            v[i+1][j] = min(v[i+1][j], v[i][j] + (grid[i][j] != grid[i+1][j]));
            v[i][j+1] = min(v[i][j+1], v[i][j] + (grid[i][j] != grid[i][j+1]));
        }
    }
    int ans = v[h-1][w-1];
    if(grid[h-1][w-1] == '#') ans++;
    cout << ans/2;
}

Measured memory_bytes: 256
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
from itertools import permutations, accumulate, combinations, combinations_with_replacement
from math import sqrt, ceil, floor, factorial
from bisect import bisect_left, bisect_right
from copy import deepcopy
from operator import itemgetter
from functools import reduce
#from fractions import gcd
#from math import gcd
import sys
def I(): return int(input())
def Is(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def TI(): return tuple(map(int, input().split()))
def IR(n): return [I() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def TIR(n): return [TI() for _ in range(n)]
def S(): return input()
def Ss(): return input().split()
def LS(): return list(input())
def SR(n): return [S() for _ in range(n)]
def SsR(n): return [Ss() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
sys.setrecursionlimit(10**6)
MOD = 10**9+7
INF = float('inf')


n = I()
print(n**3)

Measured memory_bytes: 38256
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using ld=long double;
using st=string;
using ch=char;
typedef pair<ll,ll> P;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<P> vP;
typedef vector<ch> vc;
typedef vector<vc> vvc;
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define rep(i,n) FOR(i,0,n)
#define ROF(i,a,b) for(ll i=a;i>=b;i--)
#define per(i,a) ROF(i,a,0)
#define pb push_back
#define mp make_pair
const ll MOD=1000000007;
const ll MOD2=998244353;
const ld PI=acos(-1);
const ll INF=1e18;
st abc="abcdefghijklmnopqrstuvwxyz";
st ABC="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
struct edge{ll to,cost;};

int main() {
  ll x;cin >> x;
  ll nx=x;
  rep(i,360){
    nx+=x;
    if(nx%360==0){
      cout << i+2 << endl;
      return 0;
    }
  }
}

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

typedef long long   signed int LL;
typedef long long unsigned int LU;

#define incID(i, l, r) for(int i = (l)    ; i <  (r); i++)
#define incII(i, l, r) for(int i = (l)    ; i <= (r); i++)
#define decID(i, l, r) for(int i = (r) - 1; i >= (l); i--)
#define decII(i, l, r) for(int i = (r)    ; i >= (l); i--)
#define  inc(i, n) incID(i, 0, n)
#define inc1(i, n) incII(i, 1, n)
#define  dec(i, n) decID(i, 0, n)
#define dec1(i, n) decII(i, 1, n)

#define inII(v, l, r) ((l) <= (v) && (v) <= (r))
#define inID(v, l, r) ((l) <= (v) && (v) <  (r))

#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define UB upper_bound
#define LB lower_bound
#define PQ priority_queue

#define  ALL(v)  v.begin(),  v.end()
#define RALL(v) v.rbegin(), v.rend()
#define  FOR(it, v) for(auto it =  v.begin(); it !=  v.end(); ++it)
#define RFOR(it, v) for(auto it = v.rbegin(); it != v.rend(); ++it)

template<typename T> bool   setmin(T & a, T b) { if(b <  a) { a = b; return true; } else { return false; } }
template<typename T> bool   setmax(T & a, T b) { if(b >  a) { a = b; return true; } else { return false; } }
template<typename T> bool setmineq(T & a, T b) { if(b <= a) { a = b; return true; } else { return false; } }
template<typename T> bool setmaxeq(T & a, T b) { if(b >= a) { a = b; return true; } else { return false; } }
template<typename T> T gcd(T a, T b) { return (b == 0 ? a : gcd(b, a % b)); }
template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }

// ---- ----

LL n, a[200000];

int main() {
	cin >> n;
	inc(i, n) { cin >> a[i]; }
	
	LL s = 0, t = 0;
	inc(i, n) { s += a[i]; }
	
	LL ans = 1e15;
	inc(i, n - 1) {
		s -= a[i];
		t += a[i];
		setmin(ans, abs(s - t));
	}
	
	cout << ans << endl;
	
	return 0;
}


Measured memory_bytes: 1792
#include "bits/stdc++.h"
#define ll long long int
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define all(a) a.begin(),a.end()
using namespace std;
ll dp[3001][3001];
int main(void)
{
	string s, t, ans;
	cin>>s>>t;
	ll i, j, ind1, ind2;
	for(i=0; i<3001; i++)
		dp[0][i] = 0, dp[i][0] = 0;
	for(i=1; i<=s.length(); i++)
	{
		for(j=1; j<=t.length(); j++)
		{
			ind1 =i-1;
			ind2 = j-1;
			if(s[ind1] == t[ind2])
				dp[i][j] = dp[i-1][j-1] + 1;
			else
				dp[i][j] = max(dp[i-1][j], dp[i][j-1]);
		}	
	}
	i = s.length(), j = t.length();
	while(i>0 && j>0)
	{
		if(s[i-1] == t[j-1])
		{	
			ans.pb(s[i-1]);
			i--;
			j--;
		}
		else
		{
			if(dp[i][j] == dp[i-1][j])
				i--;
			else
				j--;
		}
	}
	reverse(all(ans));
	cout<<ans<<"\n";
}	

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

using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n;
  string s;
  cin >> n >> s;
  s = "1" + s;
  int ans = 0;
  for (int i = 1; i < n + 1; i++) {
    if (s[i - 1] != s[i]) ans++;
  }
  cout << ans << endl;
  return 0;
}


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

int main(){
    
    int n,m,p;
    cin>>n>>m;
    
    string s;
    int a[n][2]={0};
    
    int correct,wrong;
    correct=wrong=0;
    for(int i=0;i<m;i++){
        cin>>p>>s;
        
        if(a[p-1][0]==0){
            if(s=="AC"){
                a[p-1][0]=1;
            }
            else
                a[p-1][1]++;
        }
        
    }
    for(int i=0;i<n;i++){
        if(a[i][0]){
            correct++;
            wrong+=a[i][1];
        }
    }
    cout<<correct<<" "<<wrong<<endl;
    return 0;
}

Measured memory_bytes: 1152
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repr(i, n) for (int i = (n); i >= 0; --i)
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define FORR(i, m, n) for (int i = (m); i >= (n); --i)
using namespace std;
typedef long long ll;
const ll mod = 1000000007;
const ll mod2 = 998244353;
const int INF = -1000000005;

int main() {
  int n, ri, rj, ans = INF;
  cin >> n >> ri;
  rep(i, n-1) {
    cin >> rj;
    ans = max(ans, rj - ri);
    if (rj < ri) ri = rj;
  }

  cout << ans << endl;

  
  return 0;
}



Measured memory_bytes: 3092
import java.io.*;

public class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		StringBuilder sb;
		do {
			sb = new StringBuilder();
			
			String[] strs = br.readLine().split("\\s+");
			int height	= Integer.parseInt(strs[0]);
			int width	= Integer.parseInt(strs[1]);
			
			if (height == 0 && width == 0) break;
			
			for (int i = 0; i < height; i++) {
				for (int j = 0; j < width; j++) {
					sb.append( (i + j) % 2 == 0 ? "#" : ".");
				}
				sb.append("\n");
			}
			
			System.out.println(sb);
		} while (true);
	}
}

Measured memory_bytes: 25904
def gcd(x, y):
    if(y == 0):
        return x
        
    return gcd(y, x%y)
    
def lcm(x, y):
    return (x*y)//(gcd(x, y))


n = int(input())
x = []
for i in range(n):
    x.append(int(input()))
        
l = x[0]
for i in range(1, n):
    l = lcm(l, x[i])
        
print(l)

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

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define deg_to_rad(deg) (((deg) / 360) * 2 * M_PI)
#define rad_to_deg(rad) (((rad) / 2 / M_PI) * 360)

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

typedef long long ll;

ll gcd(ll x, ll y)
{
    return y ? gcd(y, x % y) : x;
}

vector<pair<ll, int>> factorize(ll n)
{
    vector<pair<ll, int>> res;
    for (ll i = 2; i * i <= n; i++)
    {
        if (n % i)
            continue;
        res.emplace_back(i, 0);
        while (n % i == 0)
        {
            n /= i;
            res.back().second++;
        }
    }
    if (n != 1)
        res.emplace_back(n, 1);
    return res;
}

int main()
{
    ll a, b;
    cin >> a >> b;
    ll g = gcd(a, b);
    auto f = factorize(g);
    int ans = f.size() + 1;
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3636
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <numeric>
#include <unordered_map>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <memory>
#include <iomanip>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
constexpr long long MOD = 1e9 + 7;
constexpr long long MAX = 1000000;

//long long MOD = 998244353;
constexpr ll INF = 1e17;
constexpr double PI = 3.141592653589793;
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; }

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

    ll a, b, k;
    cin >> a >> b >> k;

    if (k <= a) {
        cout << a - k << " " << b << "\n";
    }
    else {
        cout << 0ll << " " << max(b - (k - a), 0ll) << "\n";
    }

    return 0;
}

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

int main() {
  int a,b,c;
  std::cin >> a >> b >> c;
  if (a==b || b==c || c==a) {
    if (a!=b || b!=c) {
      std::cout << "Yes\n";
      return 0;
    }
  }
  std::cout << "No\n";
  return 0;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
signed main() { 
  ios::sync_with_stdio(false); cin.tie(0);
  //d
  int n;
  cin >> n;
  vector<pair<int, int>> in(n);
  for (int i = 0; i < n; i++) {
    cin >> in[i].second >> in[i].first;
  }
  sort(in.begin(), in.end());
  long long sum = 0;
  for (auto x : in) {
    sum += x.second;
    //cerr << "x = " << x.first << " " << x.second << endl;
    //cerr << "sum = " << sum << endl;
    if (sum > x.first) {
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;
  return 0;
}

Measured memory_bytes: 1792
#include<stdio.h>
#include<iostream>
#include<string.h>
#include<vector>
#include<algorithm>
#include<set>
#include<queue>
using namespace std;

int n;
struct jikoku{
    int hh,hm,hs,ah,am,as;
};
bool operator<(const jikoku j1,const jikoku j2){
    if(j1.ah<j2.ah)return 1;
    if(j1.ah==j2.ah&&j1.am<j2.am)return 1;
    if(j1.ah==j2.ah&&j1.am==j2.am&&j1.as<j2.as)return 1;
    return 0;
}
bool comh(const jikoku j1,const jikoku j2){
    if(j1.hh<j2.hh)return 1;
    if(j1.hh==j2.hh&&j1.hm<j2.hm)return 1;
    if(j1.hh==j2.hh&&j1.hm==j2.hm&&j1.hs<j2.hs)return 1;
    return 0;
}
bool ok(const jikoku j1,const jikoku j2){
    if(j1.ah<j2.hh)return 1;
    if(j1.ah==j2.hh&&j1.am<j2.hm)return 1;
    if(j1.ah==j2.hh&&j1.am==j2.hm&&j1.as<=j2.hs)return 1;
    return 0;
}
vector<jikoku>vec;

int main(){
   // freopen("/Users/shitian/Downloads/2013-input.txt","r",stdin);
    while(cin>>n,n){
        vec.clear();
        for(int i=0;i<n;i++){
            jikoku j;
            char c;
            cin>>j.hh>>c>>j.hm>>c>>j.hs>>j.ah>>c>>j.am>>c>>j.as;
            vec.push_back(j);
        }
        vector<jikoku>se;
        for(int i=0;i<n;i++){
            se.push_back(vec[i]);
        }
        sort(se.begin(),se.end());
        sort(vec.begin(),vec.end(),comh);
        for(int i=0;i<n;i++){
            if(ok(*se.begin() , vec[i])){
                se.erase(se.begin());
            }
        }
        cout<<se.size()<<endl;
    }
}

Measured memory_bytes: 3508
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
#define INF 1000000000
#define LLINF 10000000000000000ll
#define MOD 1000000007

bool dbgflag = false;

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

  int n;
  cin >> n;
  vector<ll> sft;
  
  //sft.emplace_back(0);
  ll tens = 1;
  int i;
  while(tens < n) {
    i = 0;
    while (1) {
      ll t;
      if (sft.size() == 0) t = 0;
      else t = sft[i];
      if (t >= tens) break;
      i++;
      sft.emplace_back(3*tens + t);
      sft.emplace_back(5*tens + t);
      sft.emplace_back(7*tens + t);
    }
    tens *= 10;
  }

  int cnt = 0;
  for (ll as: sft) {
    ll a = as;
    //if (dbgflag) cout << a << endl;
    if (a > n) continue;
    bool thr = false, fiv = false, sev = false;
    while (a > 0) {
      int md = a % 10;
      if (md == 3) thr = true;
      else if (md == 5) fiv = true;
      else if (md == 7) sev = true;
      else {
        thr = false;
        break;
      }
      a /= 10;
    }
    if (thr && fiv && sev) {
      if (dbgflag) cout << as << endl;
      cnt++;
    }
  }

  cout << cnt << endl;
  
}


Measured memory_bytes: 2420
#pragma once
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
using P = pair<ll, ll>;
#define rep(i, n) for(ll i=0;i<(ll)(n);i++)
#define rep2(i, m, n) for(ll i=m;i<(ll)(n);i++)
#define rrep(i, n, m) for(ll i=n;i>=(ll)(m);i--)
#define ALL(obj) (obj).begin(), (obj).end()

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

	ll N;

	cin >> N;
	ll p[100001] = { -1 };
	ll tmp;
	rep(i, N) {
		cin >> tmp;
		p[tmp] = i + 1;
	}

	rep2(i, 1, N+1) {
		cout << p[i] << " ";
	}

	return 0;
}

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

int main()
{
    int n,m;
    cin>>n>>m;
    int A[n][m];
    for(int i=0;i<n;i++){
        for(int j = 0;j<m;j++){
            char c;
            cin>>c;
            if(c=='.'){
                A[i][j] = 1;
            }
            else{
                A[i][j] = 0;
            }
        }
    }
    int dp[n][m];
    for(int i=0;i<n;i++){
        for(int j=0;j<m;j++){
            if(i==0&&j==0){
                dp[i][j] = A[i][j];
            }
            else if(i==0){
                dp[i][j] = dp[i][j-1]&&A[i][j];
            }
            else if(j==0){
                dp[i][j] = dp[i-1][j]&&A[i][j];
            }
            else{
                if(A[i][j]==1){
                    dp[i][j] = ((dp[i-1][j]%1000000007)+(dp[i][j-1])%1000000007);
                }
                else{
                    dp[i][j] = 0;
                }
            }
        }
    }

    cout<<dp[n-1][m-1]%1000000007<<endl;

	return 0;
}

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

const int N = 100005;
const long long inf = 1e18;

typedef pair<long long,int> li;

int n, m, C;
vector< pair<int,int> > G[N];
long long d[N];
vector <li> ver; 
int pos[N];
long long sum;
long long ans = inf;

void dijkstra() {
	for (int i = 1; i <= n; ++i) d[i] = inf; 
	priority_queue < li, vector<li>, greater<li> > q; q.push(li(0,1)); d[1] = 0;
	while(!q.empty()) {
		int u = q.top().second; long long du = q.top().first; q.pop();
		if (du != d[u]) continue;
		for (auto edge: G[u]) {
			int v = edge.second, w = edge.first;
			if (d[v] > du + w) d[v] = du + w, q.push(li(d[v],v));
		}
	}
}

int main() {
	ios_base::sync_with_stdio(false); cin.tie(0);
	cin >> n >> m >> C;
	while(m--) {
		int u, v, w; cin >> u >> v >> w; sum += w;
		G[u].push_back(make_pair(w, v)); G[v].push_back(make_pair(w, u));
	}
	dijkstra();
	for (int i = 1; i <= n; ++i) ver.push_back(make_pair(d[i], i));
	sort(ver.begin(),ver.end()); 
	for (int i = 0; i < (int)ver.size(); ++i) pos[ver[i].second] = i;

	long long mx = 0, cur = 0;
	for (auto p: ver) {
		int u = p.second;
		mx = max(mx, p.first);
		for (auto edge: G[u]) {
			int v = edge.second, w = edge.first;
			if (pos[v] <= pos[u]) cur += w;
		}
		ans = min(ans, sum - cur + 1LL * C * mx);
	}

	cout << ans << endl;
}

Measured memory_bytes: 15348
while True:
    n,x=map(int, input().split())
    if n==x==0:
        break
    
    cou=0
    for i in range(1,n-1):
        for j in range(i+1,n):
            for k in range(j+1,n+1):
                if i+j+k==x:
                    cou+=1
    
    print(cou)


Measured memory_bytes: 5592
#include <iostream>
#include <iomanip>
#include <cmath>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <numeric>
#include <random>
#include <algorithm>
#include <functional>

using namespace std;
typedef long long ll;

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

const int INF = (1 << 30) - 1;
const ll INFLL= (1LL << 61) - 1;
const int MOD = 1000000007;
#define ALL(a) (a).begin(),(a).end()
#define rALL(a) (a).rbegin(),(a).rend()
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)

int main(){
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  string s;
  cin>>s;
  int n=s.length()/2,ans=0;
  FOR(i,1,n){
    string tmp1=s.substr(0,i), tmp2=s.substr(i,i);
    if(tmp1==tmp2){
      ans=i*2;
    }
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 256
import java.util.*;
public class Main {
	static final Scanner stdin = new Scanner(System.in);
	public static void main(String[] args) {
		int n;
		while((n=stdin.nextInt()) != 0){
			stdin.nextLine();
			T[] record = new T[n];
			for(int i = 0; i < n; ++i) record[i] = new T(stdin.nextLine().split(" "));
			Arrays.sort(record);
			for(T t: record) System.out.println(t.id + " " + t.sum);
		}
	}
	static class T implements Comparable<T>{
		int sum, id;
		@Override public int compareTo(T o2) { return sum != o2.sum ? o2.sum - sum : id - o2.id; }
		T(String[] in){
			int[] frame = new int[10];
			id = Integer.parseInt(in[0]);
			int[] input = new int[in.length-1];
			for(int i = 0; i < input.length; ++i) input[i] = Integer.parseInt(in[i+1]);
			sum = 0;
			for(int i = 0, p = 0; p < 10; ++p){
				frame[p] = input[i] + input[i+1];
				if(p == 9){ //?¬¬10?????¬??????
					if(frame[p] >= 10) frame[p] += input[i+2]; //????????¢ or ???????????????
				}else if(input[i] == 10){ //???????????????
					frame[p] += input[i+2];
					++i;
				}else{
					if(frame[p] == 10) frame[p] += input[i+2]; //????????¢
					i+=2;
				}
				sum += frame[p];
			}
		}
	}
}

Measured memory_bytes: 28640
#include <bits/stdc++.h>
#include <iostream>
#include <math.h>
using namespace std;
int main()
{
    int N, Q;
    cin >> N;
    multiset<int>S;
    for (int i=0; i < N; i++) {
        int s;
        cin >> s;
        S.insert(s);
    }

    cin >> Q;
    multiset<int>T;
    for (int i=0; i < Q; i++) {
        int s;
        cin >> s;
        T.insert(s);
    }

    multiset<int> result;
    set_intersection(S.begin(), S.end(),
                        T.begin(), T.end(),
                        std::inserter(result, result.end()));
    cout << result.size() << endl;
    return 0;
}


Measured memory_bytes: 10112
#include <iostream>
#include <cstdio>
#include <cmath>
#include <ctime>
#include <cstdlib>
#include <cassert>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <string>
#include <algorithm>
#include <utility>
#define llint long long
#define inf 1e9
#define rep(x, s, t) for(llint (x) = (s); (x) < (t); (x)++)
#define Rep(x, s, t) for(llint (x) = (s); (x) <= (t); (x)++)
#define chmin(x, y) (x) = min((x), (y))
#define chmax(x, y) (x) = max((x), (y))

using namespace std;
typedef pair<int, int> P;
typedef pair<P, P> S;

int h, w, k, m;
int sx, sy, tx, ty;
vector<int> vec;
char c[1500005];
int dist[1500005][4][25];
int sum[1500005];
int dx[] = {1, 0, -1, 0}, dy[] = {0, -1, 0, 1};

int get(int sx, int sy, int tx, int ty)
{
	int ret = sum[ty*w+tx];
	if(sy >= 1) ret -= sum[(sy-1)*w+tx];
	if(sx >= 1) ret -= sum[ty*w+(sx-1)];
	if(sx >= 1 && sy >= 1) ret += sum[(sy-1)*w+(sx-1)];
	return ret;
}

bool check(int x, int y, int d, int k)
{
	int nx = x + dx[d]*k, ny = y + dy[d]*k;
	if(x > nx) swap(x, nx);
	if(y > ny) swap(y, ny);
	return get(x, y, nx, ny) == 0;
}

deque<S> deq;
void add(int x, int y, int d, int s, int nx, int ny, int nd, int ns, int c){
	if(dist[ny*w+nx][nd][ns] > dist[y*w+x][d][s]){
		dist[ny*w+nx][nd][ns] = dist[y*w+x][d][s] + c;
		if(c == 0) deq.push_front(S(P(nx, ny), P(nd, ns)));
		else deq.push_back(S(P(nx, ny), P(nd, ns)));
	}
}

void bfs()
{
	deq.push_front(S(P(sx, sy), P(0, 0)));
	
	for(int i = 0; i < h*w; i++){
		for(int j = 0; j <= m; j++){
			for(int d = 0; d < 4; d++){
				dist[i][d][j] = inf;
			}
		}
	}
	dist[sy*w+sx][0][0] = 0;
	
	llint x, y, d, s;
	while(deq.size()){
		x = deq.front().first.first, y = deq.front().first.second;
		d = deq.front().second.first, s = deq.front().second.second;
		deq.pop_front();
		//cout << x << " " << y << " "<< d << " " <<s << endl;
		if(s == 0){
			for(int i = 0; i < 4; i++){
				add(x, y, d, s, x, y, i, 1, 0);
			}
		}
		else{
			int nd = d, ns = s+1, c = 0;
			if(s == m) nd = 0, ns = 0, c = 1;
			add(x, y, d, s, x, y, nd, ns, c);
			if(check(x, y, d, vec[s-1])){
				int nx = x + dx[d]*vec[s-1], ny = y + dy[d]*vec[s-1];
				if(nx < 0 || nx >= w || ny < 0 || ny >= h) continue;
				add(x, y, d, s, nx, ny, nd, ns, c);
			}
		}
	}
}

int main(void)
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	cin >> h >> w >> k;
	cin >> sy >> sx >> ty >> tx;
	sx--, sy--, tx--, ty--;
	for(int y = 0; y < h; y++){
		for(int x = 0; x < w; x++){
			cin >> c[y*w+x];
		}
	}
	
	for(int y = 0; y < h; y++){
		for(int x = 0; x < w; x++){
			if(y >= 1) sum[y*w+x] += sum[(y-1)*w+x];
			if(x >= 1) sum[y*w+x] += sum[y*w+(x-1)];
			if(x >= 1 && y >= 1) sum[y*w+x] -= sum[(y-1)*w+(x-1)];
			if(c[y*w+x] == '@') sum[y*w+x]++;
		}
	}
	
	llint rem = k;
	for(int j = 0; ; j++){
		if(rem >= (1<<j)){
			vec.push_back(1<<j);
			rem -= (1<<j);
		}
		else break;
	}
	if(rem > 0) vec.push_back(rem);
	m = vec.size();
	
	bfs();
	
	int ans = inf;
	for(int i = 0; i < 4; i++) ans = min(ans, dist[ty*w+tx][i][0]);
	if(ans > inf/2) ans = -1;
	cout << ans << endl;
	
	return 0;
}

Measured memory_bytes: 403548
#include<bits/stdc++.h>
using namespace std;
int main(){
    int a,b,p=0;
    cin>>a>>b;
    int c[a];
    for(int i=0;i<a;i++) cin>>c[i];
    for(int i=0;i<a;i++){
        int x,y;
        x=c[i]*2;
        y=(b-c[i])*2;
        if(x<y) p+=x;
        else p+=y;
    }
    cout<<p<<endl;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
#define INF (1<<30)
#define INFLL (1ll<<60)
typedef pair<int, int> P;
typedef pair<P, P> E;
#define MOD (1000000007ll)
#define l_ength size
#define EPS (1e-10)
#define PI (acos(-1.0))
#define R (PI/2)

void mul_mod(ll& a, ll b){
	a *= b;
	a %= MOD;
}

void add_mod(ll& a, ll b){
	b += MOD;
	a += b;
	a %= MOD;
}

ll rwpw(ll a, ll p){
	ll ret = 1ll;
	while(p){
		if(p%2){
			mul_mod(ret,a);
		}
		mul_mod(a,a);
		p /= 2;
	}
	return ret;
}

int main(void){
	ll N,h,n,w,a,b;
	cin >> N;
	for(h=1ll; h<=3500ll; ++h){
		for(n=1ll; n<=3500ll; ++n){
			b = 4ll*h*n - N*n - N*h;
			a = N * h * n;
			if(b > 0ll && a%b==0ll){
				w = a / b;
				cout << h << " " << n << " " << w << endl;
				return 0;
			}
		}
	}
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <set>
#include <map>
#include <queue>
#include <string>
#include <cstring>
#include <bitset>
#include <functional>
#include <random>
#define REP(i,a,n) for(int i=a;i<=n;++i)
#define PER(i,a,n) for(int i=n;i>=a;--i)
#define hr putchar(10)
#define pb push_back
#define lc (o<<1)
#define rc (lc|1)
#define mid ((l+r)>>1)
#define ls lc,l,mid
#define rs rc,mid+1,r
#define x first
#define y second
#define io std::ios::sync_with_stdio(false)
#define endl '\n'
#define DB(a) ({REP(__i,1,n) cout<<a[__i]<<',';hr;})
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int P = 1e9+7, INF = 0x3f3f3f3f;
ll gcd(ll a,ll b) {return b?gcd(b,a%b):a;}
ll qpow(ll a,ll n) {ll r=1%P;for (a%=P;n;a=a*a%P,n>>=1)if(n&1)r=r*a%P;return r;}
ll inv(ll x){return x<=1?1:inv(P%x)*(P-P/x)%P;}
inline int rd() {int x=0;char p=getchar();while(p<'0'||p>'9')p=getchar();while(p>='0'&&p<='9')x=x*10+p-'0',p=getchar();return x;}
//head



#ifdef ONLINE_JUDGE
const int N = 1e6+50;
#else
const int N = 1e2+10;
#endif




int main() {
	int n=rd();
	string s;
	cin>>s;
	map<int,int> q;
	for(char &c:s) ++q[c];
	ll ans=1;
	for(auto t:q) ans=ans*(t.y+1)%P;
	printf("%lld\n",ans-1);
}








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

int main() {
int N;
cin>>N;
N=N%10;
if(N==3){cout<<"bon"<<endl;}
else if(N==0||N==1||N==6||N==8){cout<<"pon"<<endl;}
else{cout<<"hon"<<endl;}
}


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

using ll = long long;
using pii = pair<int, int>;
template <class T>
using V = vector<T>;
template <class T>
using VV = V<V<T>>;

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define rep(i, n) rep2(i, 0, n)
#define rep2(i, m, n) for (int i = m; i < (n); i++)
#define per(i, b) per2(i, 0, b)
#define per2(i, a, b) for (int i = int(b) - 1; i >= int(a); i--)
#define ALL(c) (c).begin(), (c).end()
#define SZ(x) ((int)(x).size())

constexpr ll TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n - 1); }

template <class T, class U>
void chmin(T& t, const U& u) {
    if (t > u) t = u;
}
template <class T, class U>
void chmax(T& t, const U& u) {
    if (t < u) t = u;
}

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

template <class T>
ostream& operator<<(ostream& os, const vector<T>& v) {
    os << "{";
    rep(i, v.size()) {
        if (i) os << ",";
        os << v[i];
    }
    os << "}";
    return os;
}

#ifdef LOCAL
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
    cerr << " " << H;
    debug_out(T...);
}
#define debug(...) \
    cerr << __LINE__ << " [" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#define dump(x) cerr << __LINE__ << " " << #x << " = " << (x) << endl
#else
#define debug(...) (void(0))
#define dump(x) (void(0))
#endif

constexpr ll INF = TEN(18);

int main() {
    int N, K;
    cin >> N >> K;
    V<int> P(N), C(N);
    rep(i, N) cin >> P[i], --P[i];
    rep(i, N) cin >> C[i];

    ll ans = -INF;

    rep(i, N) {
        int v = i;
        ll cycle_sum = 0;
        int cycle_cnt = 0;

        while (true) {
            cycle_cnt++;
            cycle_sum += C[v];
            v = P[v];
            if (v == i) break;
        }

        ll path = 0;
        int cnt = 0;

        while (true) {
            cnt++;
            path += C[v];

            if (cnt > K) break;

            int num = (K - cnt) / cycle_cnt;
            ll score = path + max(0ll, cycle_sum) * num;
            chmax(ans, score);

            v = P[v];
            if (v == i) break;
        }
    }

    cout << ans << endl;

    return 0;
}

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

int main()
{
	int k,a,b;
	cin>>k;
	cin>>a>>b;
	
	
	
	if(a%k==0) 
	{
		cout<<"OK"<<endl;
		return 0;
	}
	
	int digit;
	digit=(a/k+1)*k;
    if(digit>a && digit<=b)
	cout<<"OK"<<endl;
	else 
	cout<<"NG"<<endl;
	return 0;
	
	
	
	
	
	
	
}


Measured memory_bytes: 3648
#include<stdio.h>
int main(){
	int a,b,d,r;
	double f,x,y;
	scanf("%d%d",&a,&b);
	d=a/b;
	r=a%b;
	x=a;
	y=b;
	f=x/y;
	printf("%d %d %f\n",d,r,f);
	return 0;
}


Measured memory_bytes: 2048