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

const int N = 1e5 + 5, M = 2 * N;
int adj[N], v[M], nxt[M], e;
__inline void ins(int u0, int v0) {
    v[e] = v0; nxt[e] = adj[u0]; adj[u0] = e ++;
}

int l[N], r[N], color[N];
bool cons[N], colored[N];
int n, k;

bool solve(int u, int p) {
    bool consed = false;
    int cl = -1, cr = -1;
    for (int e = adj[u]; ~e; e = nxt[e]) if (v[e] != p) {
        if (!solve(v[e], u)) return false;
        if (cons[v[e]]) {
            if (!consed) {
                consed = true;
                cl = l[v[e]] - 1, cr = r[v[e]] + 1;
            }
            else {
                if (!((cl ^ l[v[e]]) & 1)) return false;
                cl = std::max(cl, l[v[e]] - 1);
                cr = std::min(cr, r[v[e]] + 1);
            }
        }
    }

    if (cl > cr) return false;
    
    if (colored[u]) {
        if (consed) {
            if ((color[u] ^ cl) & 1) return false;
            if (color[u] < cl || color[u] > cr) return false;
        }
    }
    else {
        cons[u] = consed;
        l[u] = cl; r[u] = cr;
    }

    return true;
}

void encolor(int u, int p, int cp) {
    if (!cons[u]) {
        color[u] = cp + 1;
    }
    else {
        if (cp + 1 >= l[u] && cp + 1 <= r[u])
            color[u] = cp + 1;
        else
            color[u] = cp - 1;
    }

    for (int e = adj[u]; ~e; e = nxt[e]) if (v[e] != p) {
        encolor(v[e], u, color[u]);
    }
}

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

    std::cin >> n;
    memset(adj + 1, -1, sizeof(*adj) * n);

    for (int i = 0; i < n - 1; ++ i) {
        int a, b; std::cin >> a >> b;
        ins(a, b); ins(b, a);
    }

    std::cin >> k;
    for (int i = 0; i < k; ++ i) {
        int v, p; std::cin >> v >> p;
        colored[v] = cons[v] = true;
        l[v] = r[v] = color[v] = p;
    }

    bool succ = solve(1, 0);
    //std::cout << l[5] << " " << r[5] << std::endl;
    if (succ) {
        std::cout << "Yes\n";
        encolor(1, 0, l[1] - 1);
        for (int i = 1; i <= n; ++ i)
            std::cout << color[i] << '\n';
    }
    else {
        std::cout << "No\n";
    }
}


Measured memory_bytes: 12032
object Main extends App {
  
  val sc = new java.util.Scanner(System.in)
  val s = sc.next()
  val k = sc.nextLong()
  val i = s.indexWhere(_ != '1')
  if (i == -1) {
    println(s.head)
  } else if (i < k) {
    println(s(i))
  } else {
    println(1)
  }
}


Measured memory_bytes: 55324
use proconio::input;
use proconio::marker::Chars;

fn main() {
    input! {
        mut s: Chars
    };
    s.reverse();
    let dream = "dream".chars().rev().collect::<Vec<char>>();
    let dreamer = "dreamer".chars().rev().collect::<Vec<char>>();
    let erase = "erase".chars().rev().collect::<Vec<char>>();
    let eraser = "eraser".chars().rev().collect::<Vec<char>>();
    let n = s.len();
    let mut i = 0;
    while i < n {
        let s_i = s[i];
        match s_i {
            'm' => {
                let n_s = dream.len();
                if i + n_s <= n && &s[i..i + n_s] == dream.as_slice() {
                    i += n_s;
                } else {
                    println!("NO");
                    return;
                }
            }
            'e' => {
                let n_s = erase.len();
                if i + n_s <= n && &s[i..i + n_s] == erase.as_slice() {
                    i += n_s;
                } else {
                    println!("NO");
                    return;
                }
            }
            'r' => {
                let n_s1 = dreamer.len();
                let n_s2 = eraser.len();
                if i + n_s1 <= n && &s[i..i + n_s1] == dreamer.as_slice() {
                    i += n_s1;
                } else if i + n_s2 <= n && &s[i..i + n_s2] == eraser.as_slice() {
                    i += n_s2;
                } else {
                    println!("NO");
                    return;
                }
            }
            _ => {
                println!("NO");
                return;
            }
        }
    }
    println!("YES");
}


Measured memory_bytes: 2500
#include <iostream>
using namespace std;
int main() {
    int a[32] = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
    int K;
    cin >> K;
    cout << a[K-1] << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <sstream>
#include <vector>
#include <algorithm>
#include <queue>
using namespace std;
typedef long long ll;
int n;
ll W,weight,v,w0,ans=0,savew,savev;
ll dp[4][101];
int main(int argc,char const* argv[])
{
  cin >> n >> W;
  vector<ll> w[4];
  for(ll i=0;i<n;i++)
    {
      cin >> weight >> v;
      if(i==0)
	{
	  w0=weight;
	  w[0].push_back(v);
	}
      else if(weight==w0) w[0].push_back(v);
      else if(weight==(w0+1)) w[1].push_back(v);
      else if(weight==(w0+2)) w[2].push_back(v);
      else if(weight==(w0+3)) w[3].push_back(v);
    }
  for(int i=0;i<4;i++) sort(w[i].rbegin(),w[i].rend());
  for(int i=0;i<4;i++) 
    {
      for(int j=0;j<w[i].size();j++) dp[i][j+1]=dp[i][j]+w[i][j];
    }
  for(int i=0;i<=w[0].size();i++)
    {
      for(int j=0;j<=w[1].size();j++)
	{
	  for(int k=0;k<=w[2].size();k++)
	    {
	      for(int l=0;l<=w[3].size();l++)
		{
		  savew=w0*i+(w0+1)*j+(w0+2)*k+(w0+3)*l;
		  savev=dp[0][i]+dp[1][j]+dp[2][k]+dp[3][l];
		  if(savew<=W) ans=max(ans,savev);
		}
	    }
	}
    }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
import sys
sys.setrecursionlimit(2*10**5)


def dfs(v, graph, memo):
    if memo[v] != -1:
        return memo[v]
    ret = 0
    for c in graph[v]:
        ret = max(ret, dfs(c, graph, memo) + 1)
    memo[v] = ret
    return ret


def main():
    N, M = map(int, input().split())
    graph = [[] for _ in range(N)]
    for _ in range(M):
        x, y = map(int, input().split())
        x, y = x - 1, y - 1
        graph[x].append(y)
    memo = [-1] * N
    ans = 0
    for i in range(N):
        ans = max(ans, dfs(i, graph, memo))
    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 135884
N=input()
W=list(map(int, input().split()))
#print(N)
#print(W)

W_all = 0
for i in range(len(W)):
  W_all += W[i]
#print(W_all)

min_abs = W_all
W_tmp = 0
for i in range(len(W)):
  W_tmp += W[i]
  cur_abs = abs((W_all - W_tmp) - W_tmp)
  if cur_abs < min_abs:
    min_abs = cur_abs
    
print(min_abs)


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

int h(int n){

	if(n == 0){
		return 0;
	}else{
		return n + h(n-1);
	}
}

int main(){

	int a, b, x;

	cin >> a >> b;

	x = h(b-a) - b;

	cout << x << endl;

}


Measured memory_bytes: 256
fun main(args: Array<String>) {
  val s = readLine()!!.split("")
  var d = "Yes"
  for (i in 1 until s.size) {
    if (i % 2 == 0 && s[i].equals("R")) {
      d = "No"
      break
    } else if (i % 2 == 1 && s[i].equals("L")) {
      d = "No"
      break
    }
  }  
  println(d)
}

Measured memory_bytes: 37928
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <cassert>
#include <iostream>
#include <iomanip>
#include <sstream>
#include <algorithm>
#include <numeric>
#include <complex>
#include <stack>
#include <queue>
#include <list>
#include <set>
#include <map>
#include <bitset>
#include <functional>
#include <iterator>

using namespace std;

#define dump(n) cout<<"# "<<#n<<'='<<(n)<<endl
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define peri(i,a,b) for(int i=int(b);i-->int(a);)
#define rep(i,n) repi(i,0,n)
#define per(i,n) peri(i,0,n)
#define iter(c) __typeof__((c).begin())
#define foreach(i,c) for(iter(c) i=(c).begin();i!=(c).end();++i)
#define all(c) (c).begin(),(c).end()
#define mp make_pair

typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<string> vs;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

const int INFTY=1<<29;
const double EPS=1e-9;

template<typename T1,typename T2>
ostream& operator<<(ostream& os,const pair<T1,T2>& p){
	return os<<'('<<p.first<<','<<p.second<<')';
}
template<typename T>
ostream& operator<<(ostream& os,const vector<T>& a){
	os<<'[';
	rep(i,a.size()) os<<(i?" ":"")<<a[i];
	return os<<']';
}

int main()
{
	for(ll n,q;cin>>n>>q && n|q;){
		vl ws(n),ts(n),xs(n),ys(q);
		rep(i,n) cin>>ws[i]>>ts[i]>>xs[i];
		rep(i,q) cin>>ys[i];
		
		ll a=0,b=0,c=1; // 復旧度の増分(ax^2+bx+c)
		
		deque<pll> wis(n);
		rep(i,n) wis[i]=mp(ws[i],i);
		sort(all(wis));
		priority_queue<pll,vector<pll>,greater<pll>> eis;
		
		vl restore(n,-1);
		vector<ll> log(1);
		for(ll day=0;day<=3652425;){
			while(!wis.empty() && log.back()>=wis[0].first){
				ll i=wis[0].second;
				restore[i]=day;
				ll s=day;
				eis.emplace(s+xs[i],i);
				wis.pop_front();
				if(ts[i]==2) a++,b-=2*s,c+=s*s;
				if(ts[i]==1) b++,c-=s;
				if(ts[i]==0) c++;
			}
			while(!eis.empty() && day>=eis.top().first){
				ll e=eis.top().first,i=eis.top().second;
				eis.pop();
				ll s=e-xs[i];
				if(ts[i]==2) a--,b+=2*s,c-=s*s;
				if(ts[i]==1) b--,c+=s;
				if(ts[i]==0) c--;
			}
			day++;
			log.push_back(log.back()+a*day*day+b*day+c);
		}
		
		rep(i,n)
			if(restore[i]==-1)
				cout<<"Many years later"<<endl;
			else
				cout<<restore[i]<<endl;
		rep(i,q)
			cout<<log[ys[i]]<<endl;
	}
	
	return 0;
}

Measured memory_bytes: 43040
#include <iostream>
using namespace std;
#define MAX  100000
#define NIL  -1

struct node
{
	int parent, left, right;

};
struct node T[MAX];
void includeCalculatePreorderTree(int num)//前序
{
	if (num == NIL)//不存在当前节点
		return;
	cout <<" "<< num;
	includeCalculatePreorderTree(T[num].left);
	includeCalculatePreorderTree(T[num].right);
}
void includeCalculateInorderTree(int num)//中序
{
	if (num == NIL)
		return;
	includeCalculateInorderTree(T[num].left);
	cout <<" "<< num;
	includeCalculateInorderTree(T[num].right);
}
void includeCalculatePosterTree(int num)//后序
{
	if (num == NIL)
		return;
	includeCalculatePosterTree(T[num].left);
	includeCalculatePosterTree(T[num].right);
	cout <<" "<< num;

}
int main()
{
	int total,j,k,n,root;
	cin >> total;
	for (int i = 0; i < total; i++)
		T[i].parent = NIL;
	for (int i = 0; i < total; i++)
	{
		cin >> j >> k >> n;
		T[j].left = k;
		T[j].right = n;
		if (k != NIL)
			T[k].parent = j;
		if (n != NIL)
			T[n].parent = j;
	}
	for (int i = 0; i < total; i++)
		if (T[i].parent == NIL)
			root = i;
	cout <<"Preorder" << endl;
	includeCalculatePreorderTree(root);
	cout << endl;
	cout<< "Inorder" << endl;
	includeCalculateInorderTree(root);
	cout << endl;
	cout<<"Postorder"<<endl;
	includeCalculatePosterTree(root);
	cout << endl;
	return 0;
}


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

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

  int sx, sy, tx, ty;
  cin >> sx >> sy >> tx >> ty;

  string ans = "";

  int dx = tx - sx;
  int dy = ty - sy;

  for (int i = 0; i < dy; i++) {
    ans += 'U';
  }
  for (int i = 0; i < dx; i++) {
    ans += 'R';
  }
  for (int i = 0; i < dy; i++) {
    ans += 'D';
  }
  for (int i = 0; i < dx; i++) {
    ans += 'L';
  }
  ans += 'L';
  for (int i = 0; i < dy + 1; i++) {
    ans += 'U';
  }
  for (int i = 0; i < dx + 1; i++) {
    ans += 'R';
  }
  ans += 'D';
  ans += 'R';
  for (int i = 0; i < dy + 1; i++) {
    ans += 'D';
  }
  for (int i = 0; i < dx + 1; i++) {
    ans += 'L';
  }
  ans += 'U';

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
long a[100][100];
long b[100][100];
int main(){
	int n,m,l;
	scanf("%d%d%d",&n,&m,&l);
	for(int i=0;i<n;i++)for(int j=0;j<m;j++)scanf("%ld",&a[i][j]);
	for(int i=0;i<m;i++)for(int j=0;j<l;j++)scanf("%ld",&b[i][j]);
	for(int i=0;i<n;i++)for(int j=0;j<l;j++){
		long ans=0;
		for(int k=0;k<m;k++)ans+=a[i][k]*b[k][j];
		printf("%ld%c",ans,j==l-1?10:32);
	}
	
}


Measured memory_bytes: 2108
#include <bits/stdc++.h>
#define rep(i , x , y) for(register int i = (x) , _## i = ((y) + 1) ; i < _## i ; i ++)
#define Rep(i , x , y) for(register int i = (x) , _## i = ((y) - 1) ; i > _## i ; i --)
using namespace std ;
#define int long long
using ll = long long ;
using pii = pair < int , int > ;
const static int _ = 1 << 20 ;
char fin[_] , * p1 = fin , * p2 = fin ;
inline char gc() { return (p1 == p2) && (p2 = (p1 = fin) + fread(fin , 1 , _ , stdin) , p1 == p2) ? EOF : * p1 ++ ; }
inline int read() {
	bool sign = 1 ; char c = 0 ; while(c < 48) ((c = gc()) == 45) && (sign = 0) ;
	int x = (c & 15) ; while((c = gc()) > 47) x = (x << 1) + (x << 3) + (c & 15) ;
	return sign ? x : -x ;
}
template < class T > void print(T x , char c = '\n') {
	(x == 0) && (putchar(48)) , (x < 0) && (putchar(45) , x = -x) ;
	static char _st[100] ; int _stp = 0 ;
	while(x) _st[++ _stp] = x % 10 ^ 48 , x /= 10 ;
	while(_stp) putchar(_st[_stp --]) ; putchar(c) ;
}
template < class T > void cmax(T & x , T y) { (x < y) && (x = y) ; }
template < class T > void cmin(T & x , T y) { (x > y) && (x = y) ; }
signed main() {
#ifdef _WIN64
	freopen("testdata.in" , "r" , stdin) ;
#endif
	int n = read() , x , y = 0 , ans = 0 ;
	while(n --) {
		x = read() ;
		if(x == y + 1) y ++ ;
		else ans ++ ;
	}
	if(y) print(ans) ;
	else print(-1) ;
	return 0 ;
}


Measured memory_bytes: 1280
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <iomanip>
#include <queue>
#include <map>
#include <fstream>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define ALL(x) (x).begin(),(x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x)) //最大値を求める
#define MIN(x) *min_element(ALL(x)) //最小値を求める
#define INF 1e9 
typedef long long ll;
typedef long double ld;
int main(){
    string s,t;
    cin>>s>>t;
    queue<char> p,q;
    REP(i,SIZE(s)){
        char c=s[i];
        char d=t[i];
        p.push(c);
        q.push(d);
    }
    bool is=false;
    REP(i,SIZE(s)){
        char f=p.front();
        p.pop();
        p.push(f);
        if(p==q){
            is=true;
            break;
        }
    }
    cout<<(is?"Yes":"No")<<endl;
    return 0;
}


Measured memory_bytes: 3628
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int K,N;
    cin>>K>>N;
    int arr[N];
    for(int i=0;i<N;i++)
    {
        cin>>arr[i];
    }
    long long s = 0;

    long long t1,t2;
    t1 = arr[N-1] - arr[0];
    t2 = arr[0] + (K-arr[1]);
    s = t1 < t2 ? t1 : t2;
    long long m =s;
    for(int i=0;i<N-1;i++)
    {
        t1 = K - arr[i];
        t1 += arr[i-1];
        t2 = arr[i] + (K-arr[i+1]);
        s = t1 < t2 ? t1 : t2;
        if(s<m)
        {
             m=s;
        }
    }
    t1 = (K-arr[N-1]) + arr[N-2];
    t2 = arr[N-1] - arr[0];
    s = t1 > t2 ? t2 : t1;
    if(s<m)
    {
            m=s;
    }
    cout<<m<<endl;


}


Measured memory_bytes: 1024
#ifdef __GNUC__
#pragma GCC target("avx2")
#pragma GCC optimize ("O30")
#pragma GCC optimize ("tree-vectorize")
#pragma GCC optimize("unroll-loops")
#define iss std::cin
#endif
#include "bits/stdc++.h"
#define rep(i, times) for(ll i = 0; i < (times); ++i)
#define p(x) (cout << (x) << "\n")
using ll = long long; using ld = long double; using namespace std;

#ifndef __GNUC__
string text =
R"X(
6
3 14 159 2 6 53
58 9 79 323 84 6
2643 383 2 79 50 288
)X";
stringstream iss{text};
#endif 

class Festival
{
	ll N{0};
	vector<vector<ll>> A;
	void inp( ) {
		iss >> N; A.resize(3, vector<ll>(N));
		for (auto &abc : A) {
			for (auto &a : abc)  iss >> a;
		}		
		sort(begin(A[0]), end(A[0]));
		sort(begin(A[2]), end(A[2]));
	}
	void biSearch( ) {
		ll cnt{0};
		for (auto &b : A[1]) {
			auto itA = lower_bound(begin(A[0]), end(A[0]), b);//A<bなる最大要素の位置
			auto itC = upper_bound(begin(A[2]), end(A[2]), b);//b<Cなる最小要素の位置
			cnt += (end(A[2]) - itC) * (itA - begin(A[0]));
		}
		p(cnt);
	}
public:
	void procedures( ) {
		inp( );	biSearch( );
	}
};
int main( ) {
	cin.tie(0);	ios::sync_with_stdio(0);
	class Festival a; a.procedures( );
}

Measured memory_bytes: 6372
n=int(input())
S=input()

l,cnt1=0,0
for s in S:
  if s=='(':
    cnt1+=1
  else:
    cnt1-=1
    l=min(l,cnt1)
r,cnt2=0,0
for s in S[::-1]:
  if s==')':
    cnt2+=1
  else:
    cnt2-=1
    r=min(r,cnt2)
print('('*-l+ S + ')'*-r)


Measured memory_bytes: 3060
#include "bits/stdc++.h"
#define in std::cin
#define out std::cout
#define rep(i,N) for(int i=0;i<N;++i)
typedef long long int LL;

LL N, M, Q;

int main()
{
	in >> N >> M >> Q;
	std::vector<LL>L(M), R(M), p(Q), q(Q);
	std::vector<std::vector<LL>>imos(N + 1, std::vector<LL>(N + 1, 0));
	rep(i, M)
	{
		in >> L[i] >> R[i];
		imos[L[i]][R[i]]++;
	}
	rep(i, imos.size() - 1) rep(j, imos.size()) imos[i + 1][j] += imos[i][j];
	rep(i, imos.size()) rep(j, imos.size() - 1) imos[i][j + 1] += imos[i][j];
	rep(i, Q)
	{
		in >> p[i] >> q[i];
		out << imos[q[i]][q[i]] - imos[p[i] - 1][q[i]] - imos[q[i]][p[i] - 1] + imos[p[i] - 1][p[i] - 1] << std::endl;
	}
	return 0;
}


Measured memory_bytes: 7552
#include<iostream>
#include<algorithm>

using namespace std;

const int ans_max = 1000000;

int main(){
	int n, t, ans = ans_max;
	cin >> n >> t;
	for(int i = 0; i < n; i++){
		int c, t2;
		cin >> c >> t2;
		if(t >= t2) ans = min(ans, c);
	}
	if(ans == ans_max){
		cout << "TLE" << endl;
	}else{
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <array>
#include <algorithm>
#include <limits>
#include <cmath>
#include <numeric>
#include <string>

using namespace std;

using ll = long long int;
using ull = unsigned long long int;
#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 REP(i, a, b) for(int i = (a); i <= (b); ++i )
#define RREP(i, a, b) for(int i = (a); i >= (b); --i )
#define llrep(i, a, b) for(ll i = (a); i < (b); ++i )
#define llrrep(i, a, b) for(ll i = (a); i > (b); --i )
#define llREP(i, a, b) for(ll i = (a); i <= (b); ++i )
#define llRREP(i, a, b) for(ll i = (a); i >= (b); --i )
#define ullrep(i, a, b) for(ull i = (a); i < (b); ++i )
#define ullrrep(i, a, b) for(ull i = (a); i > (b); --i )
#define ullREP(i, a, b) for(ull i = (a); i <= (b); ++i )
#define ullRREP(i, a, b) for(ull i = (a); i >= (b); --i )



ull D, N;
ull A[10010];
ull tgti[10010];
int main() {
    cin >> N;
    ull cnt = 0;
    rep(i, 0, N) {
        ull tmp;
        cin >> tmp;
        if(tmp%2 == 0){
            tgti[cnt] = cnt;
            A[cnt++] = tmp;
        }
    }

    ull ans = 0;
    ull rescnt = cnt;
    while(rescnt>0) {
        ull curcnt = 0;
        for (ull i = 0; i < rescnt; i++) {
            if (A[tgti[i]] % 2 == 0) {
                A[tgti[i]] /= 2;
                tgti[curcnt++] = tgti[i];
                ans++;
            }
        }
        rescnt = curcnt;
    }
    cout << ans << endl;
}

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

typedef int i;
typedef long double d;
typedef pair<d,d> pd;
d PI = 3.14159265358979323846264338327950288419716939937510582097494459230781640628620899;
int main(){
    i minArmLength ,hourArmLength ,hours,minutes;
    cin >> hourArmLength >> minArmLength >> hours >> minutes;

    d minuteElapsed = hours*60+minutes;
    d hoursAngle =(double)minuteElapsed/60/12.0*360.0;
    d minutesAngle = (double)minutes/60.0*360.0;

    pd hoursPosition = {sin(PI*hoursAngle/180)*hourArmLength,cos(PI*hoursAngle/180)*hourArmLength};
    pd minutesPosition = {sin(PI*minutesAngle/180)*minArmLength ,cos(PI*minutesAngle/180)*minArmLength};

    d distance = sqrt(pow(hoursPosition.first-minutesPosition.first,2)+pow(hoursPosition.second-minutesPosition.second,2));
    cout << setprecision(30) << distance << '\n';
    return 0;
}

Measured memory_bytes: 4164
#include <bits/stdc++.h>
using namespace std;
int main(){
	int x1,x2,y2,y1;
	cin>>x1>>y1>>x2>>y2;
	int Ch=x2-x1,Ku=y1-y2;
	cout<<x2+Ku<<" "<<y2+Ch<<" "<<x1+Ku<<" "<<y1+Ch<<endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define _xx ios_base::sync_with_stdio(0);cin.tie(0);
using namespace std;
typedef long long ll;

ll C(ll n,ll m)
{
    if(m==0||n==m) return 1;
    ll sb=min(m,n-m);
    ll f=1,f1;
    for(ll i=1;i<=sb;i++)
    {
        f1=f*(n-i+1)/(i);
        f=f1;
    }
    return f1;
}
int a[100100];
int main()
{
    int n;
    cin>>n;
    for(int i=0;i<n;i++) cin>>a[i];
    sort(a,a+n);
    int m=a[n-1]/2;
    int ans;
    int fla=-1;
    for(int i=0;i<n;i++){
        int t=a[i]>m?a[n-1]-a[i]:a[i];
        if(m==t){ans=a[i];break;}
        else if(t>fla){
            ans=a[i];
            fla=t;
        }
    }
    cout<<a[n-1]<<" "<<ans<<endl;
    return 0;
}


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

using namespace std;
// ascending order
#define vsort(v) sort(v.begin(), v.end())
// descending order
#define vsort_r(v) sort(v.begin(), v.end(), greater<int>())
#define vunique(v) unique(v.begin(), v.end())
#define mp make_pair
#define ts(x) to_string(x)
#define rep(i, a, b) for(int i = (int)a; i < (int)b; i++)
#define repm(i, a, b) for(int i = (int)a; i > (int)b; i--)
#define bit(a) bitset<8>(a)
#define des_priority_queue priority_queue<int, vector<int>, greater<int> >
#define all(v) (v).begin(), (v).end()
typedef long long ll;
typedef pair<int, int> P;
const ll INF = 1e18;

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

	int n, m;
	cin >> n >> m;
	vector<pair<int, int> > E[n], EE[n];
	rep(i, 0, m) {
		int a, b, c;
		cin >> a >> b >> c;
		a--; b--;
		E[a].push_back(make_pair(b, c));
		EE[b].push_back(make_pair(a, -c));
	}

	int vis[n], col[n];
	memset(vis, 0, sizeof(vis));
	memset(col, 0, sizeof(col));
	rep(i, 0, n) if(not vis[i]) {
		col[i] = 0;
		vis[i] = 1;
		queue<int> q;
		q.push(i);
		while(!q.empty()) {
			int v = q.front(); q.pop();

			rep(p, 0, E[v].size()) {
				if(vis[E[v][p].first]) {
					if(col[v] + E[v][p].second != col[E[v][p].first]){
						cout << "No" << endl;
						return 0;
					}
				} else {
					col[E[v][p].first] = col[v] + E[v][p].second;
					vis[E[v][p].first] = 1;
					q.push(E[v][p].first);
				}
			}
			
			rep(p, 0, EE[v].size()) {
				if(vis[EE[v][p].first]) {
					if(col[v] + EE[v][p].second != col[EE[v][p].first] ){
						cout << "No" << endl;
						return 0;
					}
				} else {
					col[EE[v][p].first] = col[v] + EE[v][p].second;
					vis[EE[v][p].first] = 1;
					q.push(EE[v][p].first);
				}
			}
		}
	}
	cout << "Yes" << endl;

}


Measured memory_bytes: 12928
/*
w2sc
2019/12/19
19:32:08
*/
#include <bits/stdc++.h>
#define ull unsigned long long
#define ll long long
using namespace std;
const double EPS=1e-10;
struct Point{
    double x,y;
    Point(){}
    Point(double xx,double yy){x=xx,y=yy;}
    Point operator -(Point A){return Point(x-A.x,y-A.y);}
    Point operator +(Point A){return Point(x+A.x,y+A.y);}
    double operator ^(Point A){return x*A.y-y*A.x;}
    double operator *(Point A){return x*A.x+y*A.y;}
    double len(){return sqrt(x*x+y*y);}
};
typedef Point Vec;
Vec v,u;
Point A,B;
int main()
{
    scanf("%lf%lf",&A.x,&A.y);
    scanf("%lf%lf",&B.x,&B.y);
    v=B-A;
    int q;
    cin>>q;
    while(q--)
    {
        scanf("%lf%lf",&B.x,&B.y);
        u=B-A;
        if((v^u)>EPS) puts("COUNTER_CLOCKWISE");
        else if((v^u)<-EPS) puts("CLOCKWISE");
        else if(u*v<-EPS) puts("ONLINE_BACK");
        else if(u.len()>v.len()) puts("ONLINE_FRONT");
        else puts("ON_SEGMENT");
    }
    return 0;
}



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

int main()
{
    int n;
    cin >> n;
    vector<string> s(n);
    for (int i=0; i<n; i++) cin >> s[i];
    sort(s.begin(), s.end());
    s.erase(unique(s.begin(), s.end()), s.end());
    cout << s.size() << endl;
    return 0;
}

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

#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 
  
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> 
 
#define FS              ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ll              long long int
#define ld              long double
#define pb              push_back
#define bp              __builtin_popcount
#define sz              size()
#define ff              first
#define ss              second
#define vll             vector<ll>
#define vbool           vector<bool>
#define vpll            vector<pair<ll,ll>>
#define pll             pair<ll,ll>
#define vllv            vector<vector<ll>>
#define setpri(x)       cout<<setprecision(x)<<fixed;
#define all(v)          v.begin(),v.end()
#define allr(v)         v.rbegin(),v.rend()
#define yesr {cout<<"YES"<<endl;return;}
#define nor {cout<<"NO"<<endl;return;}
// getline (std::cin,name);
ll MOD=1e9+7;
ll ceil1(ll n,ll x){return (n-1)/x+(n>0);}

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

ll pow1(ll n,ll m ,ll mod=MOD );
ll pow2(ll n,ll k);

ll modinv(ll n,ll mod){  return pow1(n,mod-2,mod);}

bool func(pair<ll,ll> &a,pair<ll,ll> &b ){
        if(a.ff != b.ff)return a.ff < b.ff;
        return a.ss > b.ss;
}
ll const N=(ll)1e3+11;

void solve(){
        ll i,j,k,l,n,m,x,y,z,r;
        
        cin>>n>>m;
        cout<<n*m<<endl;
}
int main(){
        FS;
        ll i,j,k,n,m,x,y,z,q;
        q=1;
        // cin>>q;
        while(q--){
                solve();
        }
        return 0;
}


ll pow1(ll n,ll m,ll mod){
        if(m==0)return 1;
        
        if(m%2==0)return pow1((n*n)%mod,m/2,mod);
    	
    	return (pow1((n*n)%mod,m/2,mod)*n)%mod;
}

ll pow2(ll n,ll k){
        ll ans=1;
            while(k>0){
                if(k%2==1)ans=ans*n;
                n=n*n;
                k/=2;
            }
            return ans;
}

Measured memory_bytes: 3600
#include <bits/stdc++.h>
using namespace std;
#define inf 999999999
#define loop(i, a, b) for (int i = (a), i##len = (b); i < i##len; ++i)
#define rep(i, n) loop(i, 0, n)
#define lin long long
#define lfl long double

lin l;
vector<int> u;
vector<int> v;
vector<int> w;


int main(void)
{
    cin >> l;
    l--;

    lin p = 1;
    lin s = 1;

    while(p * 2 - 2 < l)
    {
        u.push_back(s);
        v.push_back(s+1);
        w.push_back(0);

        u.push_back(s);
        v.push_back(s+1);
        w.push_back(p);

        p *= 2;
        s++;
    }

    lin f = s;
    lin n = p - 1;

    while(p > 1)
    {
        s--;
        p /= 2;

        //cout << "# " << l << n << p << s << endl; 

        if((l - n) >= p)
        {
            u.push_back(s);
            v.push_back(f);
            w.push_back(n+1);
            n += p;
        }
    }

    cout << f << " " << u.size() << endl;
    for(int i = 0; i < u.size(); i++)
    {
        cout << u[i] << " " << v[i] << " " << w[i] << endl;
    }

    return 0;
}


Measured memory_bytes: 256
from math import ceil

a, v = map(int, input().split())
b, w = map(int, input().split())
t = int(input())
pace = v - w
if pace <= 0:
    print("NO")
else:
    diff = abs(a - b)
    if ceil(diff / pace) <= t:
        print("YES")
    else:
        print("NO")

Measured memory_bytes: 9184
package main

import (
  "fmt"
  "math"
)

func main() {
  A := make([]int, 5)
  B := make([]int, 5)
  for i := 0; i < 5; i++ {
    fmt.Scan(&A[i])
    B[i] = A[i]
  }
  var sumB int
  for i := 0; i < 5; i++ {
    if mod := A[i] % 10; mod != 0 {
      B[i] += 10 - mod
    }
    sumB += B[i]
  }
  min := math.MaxInt32
  for i := 0; i < 5; i++ {
    if order := sumB - B[i] + A[i]; order < min {
      min = order
    }
  }
  fmt.Println(min)
}


Measured memory_bytes: 512
#include <iostream>
#include <fstream>
#include <vector>
#include <map>
#include <cmath>
#include <algorithm>

using namespace std;
#define LOCAL  1
#define UPLOAD 2
#define ll long long
ll gcd(ll x,ll y){return y?gcd(y,x%y):x;}
template <class T = long long> T input(){T x;cin >> x;return x;}
template <class T> void output(T x){cout << x << endl;}
#define debug(x) cerr << #x<< ": " << x<< '\n';

unsigned long long d(unsigned long long N){
  unsigned digit=0;
  while(N!=0){
      N /= 10;
      digit++;
  }
  return digit;
}

int main()
{
#if ENVIRONMENT == LOCAL
    std::ifstream in("input.txt");
    std::cin.rdbuf(in.rdbuf());
#endif
  int N = input();  
  string S = input<string>();

  if(S.substr(0, N/2) == S.substr(N/2, N)){
    output("Yes");
  }
  else{
    output("No");
  }

  return 0;
}

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

int main() {
  int N;
  cin >> N;
  
  if (N%2 == 1) {
    cout << "No" << endl;
  }
  
  else if (N%2 == 0) {
    string S;
    cin >> S;
    bool Echo = true;
    for (int i=0; 2*i<N; i++) {
      if (S.at(i) != S.at(i+(N/2))) {
        Echo = false;
        break;
      }
    }
    cout << (Echo ? "Yes" : "No") << endl;
  }
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
using namespace std;
int main(){
  string str;
  cin >> str;
  while(str[0]!='0'){
    int i,o=0;
    for(i=0;i<str.size();i++){
      o+=str[i]-'0';
    }
    cout << o << endl;
    cin >> str;
  }
  return 0;
}



Measured memory_bytes: 3180
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

public class AtCoderD
{
    private static List<string> answers;
    private static int n;

    static void Main()
    {
        n = int.Parse(Console.ReadLine());

        answers = new List<string>();
        Progress("a");

        string[] array = answers.ToArray();
        Array.Sort(array, new StringComparator());
        foreach (var str in array)
        {
            Console.WriteLine(str);
        }
    }

    private static void Progress(String str)
    {
        if (str.Length == n)
        {
            answers.Add(str);
            return;
        }

        // 既存の文字列
        List<string> consume = new List<string>();
        for (int i = 0; i < str.Length; i++)
        {
            string s = str.Substring(i, 1);
            if (!consume.Contains(s))
            {
                consume.Add(s);
            }
        }

        foreach (var s in consume)
        {
            Progress(str + s);
        }
        Progress(str + Next(consume.Last()));
    }

    // 文字列比較のComparator
    class StringComparator : IComparer<string>
    {
        int IComparer<string>.Compare(string a, string b)
        {
            for (int i = 0; i < Math.Min(a.Length, b.Length); i++)
            {
                if (a[i] < b[i])
                {
                    return -1;
                }
                else if (a[i] > b[i])
                {
                    return 1;
                }
            }
            if (a.Length < b.Length)
            {
                return -1;
            }
            else if (a.Length > b.Length)
            {
                return 1;
            }
            else
            {
                return 0;
            }
        }
    }

    private static string Next(String s)
    {
        char c = s[0];
        return ((char)(c + 1)).ToString();
    }
}

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

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

int main() {
  int a, b, h;
  cin >> a >> b >> h;

  int ans = (a + b) * h / 2;
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<string>
#include<cstring>
#include<cmath>
#include<vector>
#include<map>
#include<stack>
#include<set>
#include<cstdlib>
#include<deque>
#include<queue>
#include<bitset>
#include<functional>
#include<utility>
#include<list>
#include<iomanip>
#include<ctime>
#include<cassert>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
using namespace std;
const int INF=1e9+1;
int main()
{
	string s;
	int ans=0;
	cin>>s;
	for(int i=1;i<s.size();i++)
	{
		if(s[i]!=s[i-1]) ans++;
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 512
#include<iostream>
using namespace std;
int main(){
	int n,x;
	cin>>n;
	int c=0;
	for(int i=15;i<=n;i++)
	if(n>=15&&i%15==0)
	c++;
	x=(n*800)-(c*200);
	cout<<x;

	return 0;
}



Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define mod 1000000007
#define fi first
#define sc second
#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
struct bity
{
	#define d 63
	vector<ll> wek;
	bity(){}
	bity(int v)
	{
		wek.resize((v/d)+2, 0);
	}
	void upper(int v)
	{
	    while(wek.size() < (v/d)+2) wek.pb(0);
	}
	void ustaw(int v)
	{
		wek[v/d]|=(1LL<<(v%d));
	}
	void zeruj()
	{
		fill(wek.begin(), wek.end(), 0);
	}
	int licz()
	{
		int ret=0;
		for (const ll &i : wek)
			ret+=__builtin_popcountll(i);
		return ret;
	}
};
 
void oruj(bity &a, const bity &b)
{
	int r=min(a.wek.size(), b.wek.size());
	for (int i=0; i<r; i++)
		a.wek[i]|=b.wek[i];
}

int n;
char f[505][505];
bity B[10][505];
ll ans;
int C[10];
int cur[10];
int main(){
	scanf("%d",&n);
	for(int i=0;i<n;i++) scanf("%s",&f[i]);
	rep(i,n)rep(j,n)if(f[i][j]!='#')C[f[i][j]-'0']++;
	repn(x,9) rep(i,n) B[x][i] = bity(C[x]);
	for(int i=0;i<2*n-1;i++){
		for(int j=min(i,n-1);j>=max(0,i-n+1);j--){
			int x = j, y = i-j;
			if(f[x][y] != '#'){
			    B[f[x][y]-'0'][x].upper(C[f[x][y]-'0']);
				if(x) repn(w,9) oruj(B[w][x],B[w][x-1]);
				repn(w,9) ans += 1LL*w*(f[x][y]-'0')*(B[w][x].licz());
				B[f[x][y]-'0'][x].ustaw(cur[f[x][y]-'0']++);
			}
			else{
				repn(w,9) B[w][x].zeruj();
			}
		}
	}
	cout << ans << endl;
}


Measured memory_bytes: 18304
#include <iostream>
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <set>
#include <queue>
#include <map>
 
using namespace std;
typedef long long int ll;
typedef pair <int,int> pii;
typedef pair<ll,ll> pll;
 
 
/*bool compare_function(const pair<int, int> a, const pair<int, int> b)
{
    return a.first < b.first;
}*/
// use case
//sort(V.begin(), V.end(), compare_function);
 
/*struct compare
{
    bool operator ()(const pair<int, int> &a, const pair<int, int> &b) {
    if (a.second-a.first==b.second-b.first)
    {
        return a.first>b.first;
    }
    return a.second-a.first < b.second-b.first;}
};
priority_queue <pair<int,int>, vector <pair<int,int>>, compare> Q;*/
 
/*void print1(vector <int> X)
{
    for (int i=0; i<X.size(); i++)
    {
        cout<<X[i]<<" ";
    }
    cout<<endl;
    return;
}
 
void print2(vector <vector <int>> X)
{
    for (int i=0; i<X.size(); i++)
    {
    for (int j=0;j<X[i].size();j++) {
        cout<<X[i][j]<<" ";}
    cout<<endl;}
    return;
}*/

 
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int n,m;
    cin>>n>>m;
    vector <set<int>> G(n+1);
    for (int i=0;i<m;i++) {
		int a,b;
		cin>>a>>b;
		G[a].insert(b);
		G[b].insert(a);
		}
	vector <int> P(n+1,0);
	int ats=0;
	P[0]=1;
	for (int i=1;i<=n;i++) {
		if (P[i]==0) {
			ats++;
			queue <int> Q;
			Q.push(i);
			while (!Q.empty()) {
				int x=Q.front();
				Q.pop();
				P[x]=1;
				for (int u:G[x]) {
					if (P[u]==0) {
						Q.push(u);
						}
					}
				}
			}
		}
	cout<<ats-1<<endl;
    return 0;
}


Measured memory_bytes: 17720
#include <string>
#include <vector>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <map>
#include <list>
#include <set>
#include <numeric>
#include <queue>
#include <stack>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <climits>
#include <cfloat>
using namespace std;
typedef long long LL;
typedef pair<double,double> P;

const double g=9.8;

int solve(double a, double b, double c, double& r0, double& r1)
{
	double D=b*b-4*a*c;
	if(D<0){
		return 0;
	}

	double d=sqrt(D);
	r0=(-b+d)/(2*a);
	r1=(-b-d)/(2*a);
	if(r0>r1){
		swap(r0,r1);
	}
	return D==0?1:2;
}

int solve2(double X, double Y, double V, double& t0, double& t1)
{
	return solve(g*X*X/(2*V*V),-X,Y+g*X*X/(2*V*V), t0, t1);
}

bool intersection(P a, P b, P& r)
{
	r.first = max(a.first, b.first);
	r.second = min(a.second, b.second);
	if(r.first >= r.second){
		return false;
	}

	return true;
}

void sum(P a, P b, vector<P> r)
{
	P d;
	if (intersection(a,b,d)){
		P p=P(min(a.first,b.first), max(a.second, b.second));
		r.push_back(p);
	}
	else
	{
		r.push_back(a);
		r.push_back(b);
	}
}

void intersection(vector<P>& a, vector<P>& b, vector<P>& res)
{
	res.clear();
	for(int i=0;i<a.size();i++){
		P p=a[i];
		for(int j=0;j<b.size();j++){
			P q=b[j];
			P r;
			if(intersection(p,q,r)){
				res.push_back(r);
			}
		}
	}
}

void debug(vector<P>& p){
	/*
	for(int i=0;i<p.size();i++){
		cout << p[i].first << ", " << p[i].second << ": ";
	}
	cout << endl;*/
}
int main() {
	int N;
	double V,X,Y;
	cin >> N >> V >> X >> Y;
	if(V==0){
		cout << "No" << endl;
		return 0;
	}

	vector<P> res;
	double t0,t1;
	if(solve2(X,Y,V,t0,t1)==2){
		res.push_back(P(t0,t1));
	}

	for(int i=0;i<N;i++){
		debug(res);
		double L,B,R,T;
		cin >> L >> B >> R >> T;
		if (X<=L){
			continue;
		}
		vector<P> lt, rt, lb, rb, t, b, tb;

		if (L==0){
			L=1e-10;
		}
		if(R==0){
			R=1e-10;
		}

		// top
		if (solve2(L,T,V,t0,t1)==2){
			lt.push_back(P(t0,t1));
		}

		if (X<=R){
			if(T<Y){
				t=lt;
			}
		}
		else
		{
			if(solve2(R,T,V,t0,t1)==2){
				rt.push_back(P(t0,t1));
			}
			intersection(lt, rt, t);
		}

		b=t;
		// bottom
		if (solve2(L,B,V,t0,t1)==2){
			//cout << "aaa " << t0 << ", " << t1 << endl;
			b.push_back(P(t1,DBL_MAX));
			if (B>0){
				double mx0=t0/(1+t0*t0)*V*V/g;
				//cout << "mx0 " << mx0 << endl;
				if(mx0<L){
					b.push_back(P(-DBL_MAX,t0));
				}
				else
				{
					//double mt=sqrt(g*B/(g*B-V*V/2));
					double mt=sqrt(2*g*B/(V*V-2*g*B));
					double mxt=mt/(1+mt*mt)*V*V/g;
					double RR=min(R,X);
					//cout << "mt " << mt << ", " << mxt << endl;
					if(mxt<RR){
						b.push_back(P(-DBL_MAX,mt));
					}
					else
					{
						if(solve2(RR,B,V,t0,t1)==2){
							b.push_back(P(-DBL_MAX, t0));
						}
					}
				}
			}
			else {
				b.push_back(P(-DBL_MAX,t0));
			}
		}
		else
		{
			b.push_back(P(-DBL_MAX,DBL_MAX));
		}
		//cout << "obs ";
		debug(b);
		vector<P> merged;
		intersection(res, b, merged);
		res.swap(merged);
 	}

	debug(res);
	if(res.size()){
		cout << "Yes" << endl;
	}
	else
	{
		cout << "No" << endl;
	}
}

Measured memory_bytes: 1232
n = int(input())
sinput = input().split()
s=[]
for i in range(n):
    s.append(int(sinput[i]))

q = int(input())
tinput = input().split()
t=[]
for i in range(q):
    t.append(int(tinput[i]))
answer = 0

import math
for tn in t:
    smin = 0
    smax = n - 1
    c = math.floor((n - 1) / 2)
    while(smax - smin > 1):
        if(tn == s[c]):
            answer = answer + 1
            break
        elif(tn > s[c]):
            if(tn == s[smax]):
                answer = answer + 1
                break
            smin = c
            c = math.floor((smin + smax) / 2) 
        elif(tn < s[c]):
            if(tn == s[smin]):
                answer = answer + 1
                break
            smax = c
            c = math.floor((smin + smax) / 2)

print(answer)


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

int main(void){
	int n,max =0,ans =0;
	scanf("%d",&n);
	char s[n];
	int flag_a[26];
	int flag_b[26];
	scanf("%s",&s);

	int i,j;
	for(i=0;i<n;i++){
		//flagの初期化
		for(j=0;j<26;j++){
		flag_a[j]=0;
		flag_b[j]=0;
		}
		//0からiまでにa-zがあるかどうか判別する
		for(j=0;j<i;j++){
			if( s[j] =='a')flag_a[0] =1;
			if( s[j] =='b')flag_a[1] =1;
			if( s[j] =='c')flag_a[2] =1;
			if( s[j] =='d')flag_a[3] =1;
			if( s[j] =='e')flag_a[4] =1;
			if( s[j] =='f')flag_a[5] =1;
			if( s[j] =='g')flag_a[6] =1;
			if( s[j] =='h')flag_a[7] =1;
			if( s[j] =='i')flag_a[8] =1;
			if( s[j] =='j')flag_a[9] =1;
			if( s[j] =='k')flag_a[10] =1;
			if( s[j] =='l')flag_a[11] =1;
			if( s[j] =='m')flag_a[12] =1;
			if( s[j] =='n')flag_a[13] =1;
			if( s[j] =='o')flag_a[14] =1;
			if( s[j] =='p')flag_a[15] =1;
			if( s[j] =='q')flag_a[16] =1;
			if( s[j] =='r')flag_a[17] =1;
			if( s[j] =='s')flag_a[18] =1;
			if( s[j] =='t')flag_a[19] =1;
			if( s[j] =='u')flag_a[20] =1;
			if( s[j] =='v')flag_a[21] =1;
			if( s[j] =='w')flag_a[22] =1;
			if( s[j] =='x')flag_a[23] =1;
			if( s[j] =='y')flag_a[24] =1;
			if( s[j] =='z')flag_a[25] =1;
		}
		//i+1からnまでにa-zがあるかどうか判別する
		for(j=i;j<n;j++){
			if( s[j] =='a')flag_b[0] =1;
			if( s[j] =='b')flag_b[1] =1;
			if( s[j] =='c')flag_b[2] =1;
			if( s[j] =='d')flag_b[3] =1;
			if( s[j] =='e')flag_b[4] =1;
			if( s[j] =='f')flag_b[5] =1;
			if( s[j] =='g')flag_b[6] =1;
			if( s[j] =='h')flag_b[7] =1;
			if( s[j] =='i')flag_b[8] =1;
			if( s[j] =='j')flag_b[9] =1;
			if( s[j] =='k')flag_b[10] =1;
			if( s[j] =='l')flag_b[11] =1;
			if( s[j] =='m')flag_b[12] =1;
			if( s[j] =='n')flag_b[13] =1;
			if( s[j] =='o')flag_b[14] =1;
			if( s[j] =='p')flag_b[15] =1;
			if( s[j] =='q')flag_b[16] =1;
			if( s[j] =='r')flag_b[17] =1;
			if( s[j] =='s')flag_b[18] =1;
			if( s[j] =='t')flag_b[19] =1;
			if( s[j] =='u')flag_b[20] =1;
			if( s[j] =='v')flag_b[21] =1;
			if( s[j] =='w')flag_b[22] =1;
			if( s[j] =='x')flag_b[23] =1;
			if( s[j] =='y')flag_b[24] =1;
			if( s[j] =='z')flag_b[25] =1;
		}
		for(j=0;j<26;j++){
			if( flag_a[j] == flag_b[j] && flag_a[j]==1){
				ans++;
			}
		}
		if( max < ans) max = ans;
		ans =0;
	}
	printf("%d",max);
	return 0;
}

Measured memory_bytes: 128
S = input()

length = len(S)
counter = 0

for i in range(length):
    if i % 2 == 0:
        if S[i] == '0':
            counter += 1

    else:
        if S[i] == '1':
            counter += 1

print(length - counter if length // 2 < counter else counter)


Measured memory_bytes: 3188
#include <stdio.h>

int main(int argc, const char * argv[]) {
    int cards[4][13];
    int n;
    char mark;
    int num;
    
    int i,j;
    
    for(i = 0;i < 13;i++){
        cards[0][i] = i + 1;
        cards[1][i] = i + 1;
        cards[2][i] = i + 1;
        cards[3][i] = i + 1;
    }
    
    scanf("%d\n",&n);
    
    for(i = 0;i < n;i++){
        if(i != n-1)scanf("%c %d\n",&mark,&num);
        else scanf("%c %d",&mark,&num);
        switch(mark){
            case 'S':
                cards[0][num-1] = 0;
                break;
            case 'H':
                cards[1][num-1] = 0;
                break;
            case 'C':
                cards[2][num-1] = 0;
                break;
            case 'D':
                cards[3][num-1] = 0;
                break;
        }
    }
    
    for(i = 0;i < 4;i++){
        for(j = 0;j < 13;j++){
            if(cards[i][j] != 0){
                switch(i){
                    case 0:
                        printf("S %d\n",cards[i][j]);
                        break;
                    case 1:
                        printf("H %d\n",cards[i][j]);
                        break;
                    case 2:
                        printf("C %d\n",cards[i][j]);
                        break;
                    case 3:
                        printf("D %d\n",cards[i][j]);
                        break;
                }
            }
        }
    }
    return 0;
}

Measured memory_bytes: 596
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define endl '\n'
#define int long long
#define P pair<int,int>

const int N = 505;
int board[N][N];
bool visited[N][N];

struct points{
    int x;
    int y;
    int nx;
    int ny;
};

signed main() {
    int h,w;
    cin >> h >> w;

    for (int i = 1; i <= h; i++) {
        for (int j = 1; j <= w; j++) {
            cin >> board[i][j];
        }
    }

    vector<points> ans;

    bool flag = true;
    for(int i = 1; i <= h; i++){
        if(flag){
            for(int j = 1; j <= w; j++){
                if(j == w) {
                    if(i == h) continue;
                    if(board[i][j] % 2 == 1) {
                        board[i+1][j]++;
                        points V = {i,j,i+1,j};
                        ans.push_back(V);
                    }
                } else {
                    if(board[i][j] % 2 == 1) {
                        board[i][j + 1]++;
                        points V = {i,j,i,j+1};
                        ans.push_back(V);
                    }
                }
            }
        } else {
            for(int j = w; j >= 1; j--){
                if(j == 1) {
                    if(i == h) continue;
                    if(board[i][j] % 2 == 1) {
                        board[i+1][j]++;
                        points V = {i,j,i+1,j};
                        ans.push_back(V);
                    }
                } else {
                    if(board[i][j] % 2 == 1) {
                        board[i][j - 1]++;
                        points V = {i,j,i,j-1};
                        ans.push_back(V);
                    }
                }
            }
        }
        flag = !flag;
    }

    cout << ans.size() << endl;
    for(auto i: ans){
        cout << i.x << " " << i.y << " " << i.nx << " " << i.ny << endl;
    }
}


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

int main()
{
  int64_t N;
  cin >> N;
  vector<int64_t> A(N + 1), Count(N + 1, 0);
  stack<int64_t> Ans;
  for (int i = 1; i <= N; i++)
    cin >> A.at(i);
  for (int i = N; i >= 1; i--)
  {
    int64_t cnt = 0;
    for (int j = i; j <= N; j += i)
    {
      cnt += Count.at(j);
    }
    if (cnt % 2 != A.at(i))
    {
      Count.at(i) = 1;
      Ans.push(i);
    }
  }
  cout << Ans.size() << endl;
  while (!Ans.empty())
  {
    cout << Ans.top();
    Ans.pop();
    if (!Ans.empty())
      cout << ' ';
    else
      cout << endl;
  }
}


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

int main(){
	string s;
	int count = 0;
	int index;
	int a, b;
	cin >> a >> b >> s;
	for(int i=0; i<s.size(); i++){
		if(s[i] =='-') {
			count++;
			index = i;
		}
	}
	if(count == 1 && index == a)
		cout << "Yes";
	else
		cout << "No";
	return 0;
}


Measured memory_bytes: 256
def main():
    k = int(input())
    x = 0
    flag = True
    # 等比数列の和
    # 初項7 公比10 
    # 7 * (1-10**i) / (1-10)
    # 7*(10**i-1)/9
    # これをkで割りきれるか
    # 7*(10**i-1) を 9*kで我りきれるか
    # kが7倍数かそうでないかで条件分ける
    # 割った余りを保持しておいて10倍してまた割るを繰り返す
    mod = 1
    for i in range(1, 10**6+1):
        mod *= 10
        if k % 7 == 0:
            mod = mod % (9*k/7)
            if mod == 1:
                print(i)
                flag = False
                break
        else:
            mod = mod % (9*k)
            if mod == 1:
                print(i)
                flag = False
                break

    if flag:
        print('-1')
        
if __name__ == '__main__':
    main()


Measured memory_bytes: 9184
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
using namespace std;
int main(){
    int n,a,s;
    cin >> n;
    if((n*100)%108==0){
        a=n/1.08;
        cout << a <<endl;
    }
    else{
        a=n/1.08+1;
        s=a*1.08;
        if(s!=n){
            cout << ":(" <<endl;
        }
        else{
            cout << a << endl;
        }
    }
   
}

Measured memory_bytes: 256