akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
using namespace std;

class Dice {
public:
    int label[6];

    Dice(int* nums) {
        for (int i = 0; i < 6; i++) label[i] = nums[i];
    }

    void printTop() {
        cout << label[0] << endl;
    }

    void roll(char direction) {
        int new_label[6];
        switch (direction) {
            case 'N':
                new_label[0] = label[1];
                new_label[1] = label[5];
                new_label[2] = label[2];
                new_label[3] = label[3];
                new_label[4] = label[0];
                new_label[5] = label[4];
                break;
            
            case 'S':
                new_label[0] = label[4];
                new_label[1] = label[0];
                new_label[2] = label[2];
                new_label[3] = label[3];
                new_label[4] = label[5];
                new_label[5] = label[1];
                break;
            
            case 'E':
                new_label[0] = label[3];
                new_label[1] = label[1];
                new_label[2] = label[0];
                new_label[3] = label[5];
                new_label[4] = label[4];
                new_label[5] = label[2];
                break;
            
            case 'W':
                new_label[0] = label[2];
                new_label[1] = label[1];
                new_label[2] = label[5];
                new_label[3] = label[0];
                new_label[4] = label[4];
                new_label[5] = label[3];
                break;

            default:
                new_label[0] = label[0];
                new_label[1] = label[1];
                new_label[2] = label[2];
                new_label[3] = label[3];
                new_label[4] = label[4];
                new_label[5] = label[5];
        }

        for (int i= 0; i < 6; i++) label[i] = new_label[i];
    }
};

int main(void) {
    int nums[6];
    for (int i = 0; i < 6; i++) cin >> nums[i];
    Dice dice(nums);

    string commands;
    cin >> commands;
    for (int i = 0; i < commands.size(); i++) dice.roll(commands[i]);
    dice.printTop();

    return 0;
}

Measured memory_bytes: 1204
#include<bits/stdc++.h>
#define int long long
#define endl '\n'
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
using namespace std;
const int MOD=1e9+7;

 const int MAXN=100,MAXW=1e5;
 int w[MAXN+1],v[MAXN+1];
 int dp[MAXN+1][MAXW+1];
   
int32_t main()
{
   IOS
   memset(dp,0,sizeof(dp));
   int N,W;cin>>N>>W;
   for(int i=1;i<=N;i++)
   cin>>w[i]>>v[i];
   for(int i=1;i<=N;i++)
   { 
	   for(int j=0;j<=W;j++)
	   dp[i][j]=dp[i-1][j];
	   
	   for(int j=0;j<=W;j++)
	   {
		   if(j+w[i]<=W)dp[i][j+w[i]]=max(dp[i][j+w[i]],v[i]+dp[i-1][j]);
	   }
   }
   cout<< dp[N][W] << endl;
}


Measured memory_bytes: 79232
#include <iostream>
#include <set>
using namespace std;
multiset <int> mp;
int main(){
	int n;
	cin >> n;
	for (int i = 1; i <= n; ++ i){
		int x;
		cin >> x;
		mp.insert(x);
	}
	int ans = 0;
	while (! mp.empty()){
		int x = *mp.rbegin();
		mp.erase(-- mp.end());
		for (int i = 30; i >= 0; -- i){
			int sum = 1 << i;
			if (mp.find(sum - x) != mp.end()){
				++ ans;
				mp.erase(mp.find(sum - x));
				break;
			}
		}
	}
	cout << ans << endl;
}


Measured memory_bytes: 9600
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(a) (a).begin(),(a).end()
#define pb emplace_back
#define INF (1e9+1)

int main(){
    string s = "aiueo";
    
    
    char ch;
    cin>>ch;
    
    
    rep(i,s.size()){
        if(ch==s[i]){
            cout<<"vowel"<<endl;
            return 0;
        }
    }
    cout<<"consonant"<<endl;
}


Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.Scanner;

public class Main {

  public static void main(String[] args) {

    Scanner sc = new Scanner(System.in);

    int N = Integer.parseInt(sc.next());

    ArrayList<Integer> list = new ArrayList<Integer>();
    list.add(1);
    int e6 = 6, e9 = 9, flag = 0;
    while (true) {
      if (flag == 6) {
        e6 *= 6;
      } else if (flag == 9) {
        e9 *= 9;
      }
      if (e6 > N && e9 > N) {
        break;
      } else if (e6 < e9) {
        list.add(e6);
        flag = 6;
      } else {
        list.add(e9);
        flag = 9;
      }
    }

    int dp[] = new int[N + 1];
    dp[0] = 0;
    for (int i = 1; i < N + 1; i++) {
      dp[i] = dp[i - 1] + 1;
      for (int j = 0; j < list.size(); j++) {
        int t = list.get(j);
        if (i - t < 0) {
          break;
        } else {
          dp[i] = Math.min(dp[i], dp[i - t] + 1);
        }
      }
    }
    System.out.println(dp[N]);
  }
}

Measured memory_bytes: 24916
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mp make_pair
#define pb push_back
#define ff first
#define ss second
#define vi vector<int>
#define vll vector<ll> 
#define inf 100000000000
#define mod 1000000007

ll power(ll a , ll b)
{
    ll prod = 1;
    while(b)
    {
        if(b&1)
        prod = (prod*a);
        a = (a*a);
        b >>= 1;
    }
    return prod;
}


int main()
{
    ll n , k , sum = 0;
    cin >> n >> k;
    int a[n];
    for(int i = 0 ; i < n ; i++)
        cin >> a[i];
    
    int index = 0 , max1 = -1;
    for(int i = 0 ; i < k ; i++)
    {
        sum += a[i];
    }
    max1 = sum;
    for(int i = k ; i < n ; i++)
    {
        sum += a[i];
        sum -= a[i-k];
        if(sum > max1)
        {
            index = i - k + 1;
            max1 = sum;
        }
    }
    // cout << index << endl;
    // cout << max1 + k << endl;
    printf("%0.9lf\n" , (double)((max1 + k)*1.0)/2.0);
    return 0;
}

Measured memory_bytes: 1024
n=int(input())
f=[list(map(int,input().split())) for i in range(n)]
p=[list(map(int,input().split())) for i in range(n)]
#print(f,p)
l=[0]*1024

for i in range(1024):
    I=format(i,'b').zfill(10)
    for k in range(n):
        c=0
        for j in range(10):
            if I[j]=='1' and f[k][j]==1:
                c+=1
        l[i]+=p[k][c]  
#print(l)    
print(max(l[1:]))

Measured memory_bytes: 40764
#!/usr/bin/env python3
import sys
from collections import deque
import heapq

sys.setrecursionlimit(10000)
INF = 1<<32


def solve(N: int, K: int, V: "List[int]"):
    # 捨てるられるのはK-(A+B)
    # A, Bを全探索
    n = min(N,K)

    ans = 0
    for i in range(n+1):
        for j in range(n-i+1):
            s = V[:i] + V[::-1][:j]
            # print(i, j, V[:i], V[::-1][:j], s)
            s.sort(reverse=True)
            for k in range(max(0, K-(i+j))):
                t = s.copy()
                if(len(s) >= 1 and s[-1] < 0):
                    s.pop()

                    
            ans = max(ans, sum(s))

    print(ans)

    return



def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    K = int(next(tokens))  # type: int
    V = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, K, V)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3444
S=['a','x','z','c']
S=input()
words=[a for a in S]
n=len(words)
if n%2==1:
    del words[-1]
else:
    del words[-2:]
while True:
    n=len(words)
    m=round(n/2)
    if words[:m]==words[-m:]:
        print(n)
        break
    else:
        del words[-2:]



Measured memory_bytes: 2940
n = int(input())
p = list(map(int, input().split()))

ans = 0
for i in range(1, n-1):
  if p[i-1] < p[i] and p[i] < p[i+1]:
    ans += 1
  elif p[i-1] > p[i] and p[i] > p[i+1]:
    ans += 1

print(ans)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
#define st first
#define nd second
using ll = long long;
using namespace std;
using pii = pair<int,int>;
map<pii,int> mp;
vector<int> gr[55];
ll bm[25];
ll dfs(int tar,int id,int fr){
    if(id == tar){
        return (1LL<<mp[{id,fr}]);
    }
    ll sum = 0LL;
    for(auto it: gr[id]){
        if(it != fr) sum += dfs(tar,it,id);
        if(sum > 0LL) break;
    }
    if(sum == 0LL) return sum;
    if(fr != 0) return sum + (1LL<<mp[{id,fr}]);
    return sum;
}
int main(){
    int n;
    scanf("%d",&n);
    int x,y;
    for(int i = 0;i<n-1;i++){
        scanf("%d%d",&x,&y);
        mp[{x,y}] = i;
        mp[{y,x}] = i;
        gr[x].push_back(y);
        gr[y].push_back(x);
    }
    int m;
    scanf("%d",&m);
    for(int i =0;i<m;i++){
        scanf("%d%d",&x,&y);
        bm[i] = dfs(y,x,0);
    }
    ll ans = 0LL;
    int ct = 1LL;
    for(int i = 0 ;i < (1<<m);i++){
        ll b = 0LL;
        ct = 1;
        for(int j = 0; j < m; j++){
            if(i & (1<<j)) b |= bm[j],ct=-ct;
        }
        int ma = n -1;
        for(int j = 0; j < n-1;j++){
            if(b & (1LL<<j)) ma--;
        }
        ans += ct * (1LL<<ma);
    }
    printf("%lld",ans);

}


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

ll solve() {
    ll N;
    cin >> N;
    vector<ll> L(2*N);
    for ( int i = 0; i < 2*N; i++ ) {
        cin >> L[i];
    }
    sort(L.begin(), L.end(), greater<>());
    ll ans = 0;
    for ( int i = 0; i < N; i++ ) {
        ans += L[2*i+1];
    }
    return ans;
}

int main() {
    auto ans = solve();
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<iostream>
#include<cmath>
#include<cstring>
#include<map>
#include<vector>

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define REV(i,a,b) for(int i=(a)-1;i>=(b);i--)

using namespace std;

typedef long long ll;

int A,B,C;
ll K;


int main(){
  cin >> A >> B >> C >> K;
  if (K % 2 == 1){
    cout << B - A << endl;
  }
  else cout << A - B << endl;


  return 0;
}

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

// GNU C Compiler
//template<class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str(); }

// type
using ll = int_fast64_t;
using ull = uint_fast64_t;
using LL = long long;
using ULL = unsigned long long;
using PII = pair<int, int>;
//using pair<T1, T2> = p12;

//container
#define PB emplace_back
#define MP make_pair 
#define SZ(a) int((a).size())
#define ALL(v) v.begin(),v.end()

//repetition
#define REP(n) for(int i=0; i<(n); i++)
#define REPj(n) for(int j=0; j<(n); j++)
#define REPinit(i,a,n) for(int i=(a); i<(n); i++)
#define REPinitj(j,a,n) for(int j=(a); j<(n); j++)

//algorithm
//#define SORT(c) sort((c).begin(),(c).end())

//constant

//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))

//Optimizer
// #pragma GCC optimize("Ofast")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

/* 
	add utility Algorithm
*/

int main(int argc, char const *argv[])
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int N;
    cin >> N;

    vector<int> d(N, 0);
    REPinit(i, 0, N) cin >> d[i];

    ll ans = 0;
    REPinit(i, 0, N - 1) {
        REPinit(j, i + 1, N) { 
            ans += d[i] * d[j];
        }
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3656
#include <iostream>
#include <vector>
#include <array>
#include <algorithm>
#include <cmath>
#include <queue>
#include <limits>
#include <map>
#include <cassert>
#include <iterator>
using namespace std;
using VI = vector<int>;
using P = pair<int, int>;
using VP = vector<P>;
constexpr P undefined = P(-1, -1);

int main() {
    int n;
    cin >> n;
    
    n = 1 << n;
    VI as(n);
    VP max_first(n), max_second(n);
    for (int i = 0; i < n; i++) {
        cin >> as[i];
    }
    
    max_first[0] = P(as[0], 0);
    VP tmp;
    VI bits;
    for (int i = 1; i < n; i++) {
        tmp.clear();
        tmp.push_back(P(as[i], i));
        int j = i;
        bits.clear();
        while (j) {
            int k = j & (-j);
            bits.push_back(k);
            j ^= k;
        }
        for (int b: bits) {
            tmp.push_back(max_first[i ^ b]);
            tmp.push_back(max_second[i ^ b]);
        }
        sort(tmp.begin(), tmp.end());
        tmp.erase(unique(tmp.begin(), tmp.end()), tmp.end());
        reverse(tmp.begin(), tmp.end());
        max_first[i] = tmp[0];
        max_second[i] = tmp[1];
    }
    
    int ans = 0;
    for (int i = 1; i < n; i++) {
        ans = max(ans, max_first[i].first + max_second[i].first);
        cout << ans << endl;
    }
}


Measured memory_bytes: 8192
import java.util.Scanner;

public class Main{
	public static void main(String [] args){
		Scanner sc = new Scanner(System.in);
		int work, n = sc.nextInt();
		for(int i = 3; i <= n; i++){
			if(i % 3 == 0){
				System.out.print(" " + i);
				continue;
			}
			work = i;
			while(work != 0){
				if(work % 10 == 3){
					System.out.print(" " + i);
					break;
				}
				work /= 10;
			}
		}
		System.out.println("");
	}
}

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

using namespace std;

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

#define BIL ((ll)1e9)
#define MOD ((ll)1e9+7)
#define INF (1LL<<60)           //1LL<<63でオーバーフロー
#define inf (1<<29)             //1<<29でオーバーフロー

int main(int argc,char* argv[]){
    int d,n;
    cin >> d >> n;

    if(n==100)n++;

    ll ans=0;
    if(d==0){
        ans=n;
    }else if(d==1){
        ans=n*100;
    }else if(d==2){
        ans=n*100*100;
    }

    cout << ans << endl;

    return 0;
}


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



int main()
{
int N,M,X;
cin>>N>>M>>X;
vector<int>A(M);
for(int i=0;i<M;i++)
{cin>>A[i];}
vector<int>chizu(N+1);
for(int i=0;i<N+1;i++)
{chizu[i]=0;}
for(int i=0;i<M;i++)
{chizu[A[i]]=1;}

vector<int>ruisekiwa(N+1);
ruisekiwa[0]=0;
for(int i=0;i<N;i++)
{ruisekiwa[i+1]=ruisekiwa[i]+chizu[i+1];}

cout<<min(ruisekiwa[X],ruisekiwa[N]-ruisekiwa[X])<<endl;

}


Measured memory_bytes: 256
import math
x, y, z = map(float, input().split())
z = z / 180 * math.pi
print('%.06f' % (x * y * math.sin(z) / 2))
print('%.06f' % ((x**2 + y**2 -2*x*y*math.cos(z))**(1/2) + x + y))
print('%.06f' % (y*math.sin(z)))


Measured memory_bytes: 5696
#include<bits/stdc++.h>
using namespace std;
string s;
int cnta;
int main()
{
    cin>>s;
    for(int i=0;i<s.size();i++)
    {
        if(s[i]=='A'||s[i]=='a')
        cnta++;
    }
    if(cnta==0||cnta==s.size())
    printf("No\n");
    else
    printf("Yes\n");
    return 0;
}

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

#define rep(i, n) for(int i = 0; i<(n); i++)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
typedef long long ll;

vector<pair<ll, ll>> prime_factorize(ll n) {
    vector<pair<ll, ll>> res;
    for (ll p = 2; p * p <= n; p++) {
        if (n % p != 0) continue;
        int num = 0;
        while (n % p == 0) {
            ++num;
            n /= p;
        }
        res.push_back(make_pair(p, num));
    }
    if (n != 1) res.push_back(make_pair(n, 1));
    return res;
}

int dp[101][76];

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

    // N!の素因数分解
    map<ll, int> sisuu; // key:素数, value:素数の個数
    for (int i = 2; i <= N; i++) {
        auto ps = prime_factorize(i);
        for (auto it: ps) sisuu[it.first] += it.second;
    }

    vector<int> nums; // 素因数の指数部分
    for (auto a: sisuu) nums.push_back(a.second);
    int len = nums.size();
    vector<int> div75 = {1, 3, 5, 15, 25, 75}; // 約数が75個になる指数部分の候補

    dp[0][1] = 1;
    rep(i, len) {
        for (auto d1:div75) {
            for (auto d2: div75) {
                if (d1 * d2 <= 75 && nums[i] + 1 >= d2) {
                    dp[i + 1][d1 * d2] += dp[i][d1];
                }
            }
        }
    }
    cout << dp[len][75] << endl;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		while(sc.hasNext()) {
			int a = sc.nextInt();
			int b = sc.nextInt();
			if (a == 0 && b == 0)
				break;
			if (b < a) {
				int tmp = a;
				a = b;
				b = tmp;
			}
		System.out.println(a + " " + b);
		}
	}
}



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

int main(){
  double a, b;
  cin >> a >> b;
  int ans = -1;
  for(double i = 1000000; i >= 1; --i){
    int valuea = i * 0.08;
    int valueb = i * 0.1;
    if(valuea == a && valueb == b){
      ans = i;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 384
#include <iostream>
#include <set>
#include <vector>
#include <string>
#include <algorithm>
#include <iterator>
#include <map>
#include <utility>
#include <list>
#include <climits>
#include <bitset>
#include <numeric>

using namespace std;

#define rep(i, n) for(int i = 0; i < n; i++)
#define repi(i, n) for(auto i = (n).begin(); i != (n).end(); i++)
#define in_arr(type, a, n) copy_n(istream_iterator<type>(cin), n, (a).begin());
#define ll long long int

int main(){
    string s;
    cin >> s;
    int pos = s.size() - 1;
    while(pos >= 0){
        if(pos >= 6 && s.substr(pos - 6, 7) == "dreamer"){
            pos -= 7;
        }else if(pos >= 5 && s.substr(pos - 5, 6) == "eraser"){
            pos -= 6;
        }else if(pos >= 4 && s.substr(pos - 4, 5) == "dream"){
            pos -= 5;
        }else if(pos >= 4 && s.substr(pos - 4, 5) == "erase"){
            pos -= 5;
        }else{
            cout << "NO" << endl;
            return 0;
        }
    }
    cout << "YES" << endl;
    return 0;
}


Measured memory_bytes: 512
#include<cstdio>

int main () {
    int a, b;
    char op;

    for (int i=0;; i++) {
        scanf("%d %c %d", &a, &op, &b);
        if (op == '?') break;
        else if (op == '+') printf("%d\n", a + b);
        else if (op == '-') printf("%d\n", a - b);
        else if (op == '/') printf("%d\n", a / b);
        else if (op == '*') printf("%d\n", a * b);
    }
    return 0;
}

Measured memory_bytes: 1028
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<functional>
#include<fstream>
#include<utility>
#include<bitset>
#include<map>
#include<deque>
#include<cmath>
#include<random>
#include<string.h>
#define FOR(i, a, b) for (int i = a; i < b; ++i)
#define rep(N) for (int i = 0; i < N; ++i)
#define Rep(a, b) for (int i = a; i < b; ++i)
#define For(i, N) for (int i = 0; i < N; ++i)
#define all(v) v.begin(), v.end()
#define rev(v) v.rbegin(), v.rend()
#define makei(N) int N; cin >> N;
#define makel(N) ll N; cin >> N;
#define makes(s) string s; cin >> s;
#define maked(d) double d; cin >> d;
#define makev(v, N) vi v(N); rep(N)cin >> v[i];
#define mod 1000000007
#define re return 0

using namespace std;
using ll = long long int;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vll = vector<ll>;
using vb = vector<bool>;
using vvb = vector<vector<bool>>;
using vs = vector<string>;
using pii = pair<int, int>;
using pis = pair<int, string>;
using msi = map<string, int>;

template<typename T>
void say(T s) {
	cout << s << "\n";
}

template<typename T>
void say(vector<T> s) {
	auto itr = s.begin();
	cout << *(itr++);
	while (itr != s.end()) {
		cout << " " << *(itr++);
	}
	cout << "\n";
}

void yn(bool b) {
	if (b)say("Yes");
	else say("No");
}

int main() {
	makei(H);
	makei(W);
	rep(W + 2)cout << "#";
	cout << endl;
	rep(H) {
		string s;
		cin >> s;
		say("#" + s + "#");
	}
	rep(W + 2)cout << "#";
	cout << endl;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cmath>
#include <cstring>
#include <vector>
#include <algorithm>
#define EPS 1e-10
using namespace std;

int testc,n;

double add(double a,double b){
	if(fabs(a+b)<EPS*(fabs(a)+fabs(b)))return 0;
	return a+b;
}

struct P{
	double x,y;
	int flag;
	P(){}
	P(double xx,double yy){
		x=xx;
		y=yy;
		flag=-1;
	}
	P(double xx,double yy,int f){
		x=xx;
		y=yy;
		flag=f;
	}
	P operator +(P p){
		return P(x+p.x,y+p.y);
	}
	P operator -(P p){
		return P(x-p.x,y-p.y);
	}
	P operator *(double d){
		return P(x*d,y*d);
	}
	P operator /(double d){
		return P(x/d,y/d);
	}
	double dot(P p){
		return add(x*p.x,y*p.y);
	}
	double det(P p){
		return add(x*p.y,-y*p.x);
	}
};

bool on_seg(P p1,P p2,P q){
	return (p1-q).det(p2-q)==0 && (p1-q).dot(p2-q)<=0;
}

bool comp(const P& p1,const P& p2){
	if(add(p1.x,-p2.x)==0)return p1.y<p2.y;
	return p1.x<p2.x;
}

P intersection(P p1,P p2,P q1,P q2){
	return p1+(p2-p1)*((q2-q1).det(q1-p1)/(q2-q1).det(p2-p1));
}

vector<P> data[2][2][2];
P a,b;
vector<P> cross;
int solve(){
	cross.clear();
	for(int i=0;i<2;i++){
		for(int j=0;j<2;j++){
			for(int k=0;k<data[i][j][0].size();k++){
				P p1=data[i][j][0][k],p2=data[i][j][1][k];
				if((p1-p2).det(a-b)==0)continue;
				P r=intersection(p1,p2,a,b);
				if(on_seg(p1,p2,r) && on_seg(a,b,r)){
					if(i==0){
						if(j==0)r.flag=0;
						else r.flag=1;
					}else{
						if(j==0)r.flag=1;
						else r.flag=0;
					}
					cross.push_back(r);
				}
			}
		}
	}
	int now=-1,cnt=0;
	sort(cross.begin(),cross.end(),comp);
	for(int i=0;i<cross.size();i++){
		P p=cross[i];
		if(now==-1){
			now=cross[i].flag;
		}else{
			if(now!=cross[i].flag)cnt++;
			now=cross[i].flag;
		}
	}
	return cnt;
}

int main(void){
	scanf("%d",&testc);
	for(int ddd=0;ddd<testc;ddd++){
		scanf("%lf %lf %lf %lf",&a.x,&a.y,&b.x,&b.y);
		scanf("%d",&n);
		for(int i=0;i<2;i++){
			for(int j=0;j<2;j++){
				for(int k=0;k<2;k++)data[i][j][k].clear();
			}
		}
		for(int i=0;i<n;i++){
			int xs,ys,xt,yt,o,l;
			scanf("%d %d %d %d %d %d",&xs,&ys,&xt,&yt,&o,&l);
			data[o][l][0].push_back(P(xs,ys));
			data[o][l][1].push_back(P(xt,yt));
		}
		printf("%d\n",solve());
	}
	return 0;
}

Measured memory_bytes: 1092
#include<bits/stdc++.h>
#define N 10000000
using namespace std;
bool used[N];

int main(){
  int m,n;
  while(1){
    cin>>m>>n;
    if(!m&&!n)break;
    memset(used,0,sizeof(used));
    for(int i=m;i<N;i++){
      if(!used[i]){
	if(!n)break;
	else{
	  n--;
	  for(int j=i;j<N;j+=i)
	    used[j]=true;;
	}
      }
    }
    for(int i=m;i<N;i++)
      if(!used[i]){
	cout<<i<<endl;
	break;
      }
  }
  return 0;
}

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

int main()
{
	int a, b, c;
	cin >> a >> b >> c;
	if(a < b) swap(a, b);
	if(a < c) swap(a, c);
	cout << a * 10 + b + c << endl;
	return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#define INF (__INT32_MAX__ / 2)
#define MAX_N 100000

using namespace std;

typedef struct Shop {
    int A, B;
} Shop;

#define $Type Shop
#define $Key A

Shop shops[MAX_N];
int N, M;

long long solve() {
    long long count = 0;
    long long cost = 0;

    for(long long i = 0; count < M; ++i) {
        long long rest = M - count;
        long long buy = rest > shops[i].B ? shops[i].B : rest;
        count += buy;
        cost += buy * shops[i].A;
    }

    return cost;
}

void merge_sort($Type *array, int left, int right);

int main(int argc, char **argv) {
    scanf("%d %d", &N, &M);

    for(int i = 0; i < N; ++i)
        scanf("%d %d", &shops[i].A, &shops[i].B);

    merge_sort(shops, 0, N);
    printf("%lld\n", solve());
}


// <-----# マージソート #----->
$Type L[MAX_N / 2 + 2], R[MAX_N / 2 + 2];
void merge_sort($Type *array, int left, int right) {
    if(right - left == 1)
        return;
    
    //divide
    int mid = (left + right) / 2;
    merge_sort(array, left, mid);
    merge_sort(array, mid, right);

    for(int i = 0; i < mid - left; ++i) L[i] = array[left + i];
    for(int i = 0; i < right - mid; ++i) R[i] = array[mid + i];
    L[mid - left].$Key = INF;    //番兵
    R[right - mid].$Key = INF;

    //conquer
    int j = 0, k = 0;
    for(int i = left; i < right; ++i) {
        if(L[j].$Key <= R[k].$Key)
            array[i] = L[j++];
        else
            array[i] = R[k++];
    }
}
// >-----# マージソート #-----<

Measured memory_bytes: 1664
public class Main {

    public static void main(String[] args) {
        int num = new java.util.Scanner(System.in).nextInt();
        System.out.println(HPB(num));
    }

    static public String HPB(int number) {
        // "pon"パターン
        int[] ponNumber = {0, 1, 6, 8};

        // 1の位が3なら"bon"
        if (number % 10 == 3)
            return "bon";

        // 1の位が"pon"パターンに当てはまるか
        for (int ponInt : ponNumber) {
            if (number % 10 == ponInt)
                return "pon";
        }

        // "bon"でも"pon"でもないものは"hon"パターン
        return "hon";
    }
}


Measured memory_bytes: 35576
{-# LANGUAGE BangPatterns #-}
import           Control.Exception           (assert)
import           Control.Monad
import           Control.Monad.Primitive
import qualified Control.Monad.ST            as ST
import qualified Data.Array.IO               as IO
import qualified Data.Array.ST               as ST
import qualified Data.Array.Unboxed          as A
import           Data.Bits
import qualified Data.ByteString.Char8       as BS
import           Data.Char
import           Data.Foldable
import           Data.List
import qualified Data.Map.Strict             as Map
import           Data.Maybe
import qualified Data.Sequence               as Seq
import qualified Data.Set                    as Set
import qualified Data.Vector                 as VB
import qualified Data.Vector.Mutable         as VBM
import qualified Data.Vector.Unboxed         as V
import qualified Data.Vector.Unboxed.Mutable as VM
import           Debug.Trace

readInt = fst . fromJust . BS.readInt
readIntList = map readInt . BS.words
getInt = readInt <$> BS.getLine
getIntList = readIntList <$> BS.getLine
getIntVec n = V.unfoldrN n (BS.readInt . BS.dropWhile isSpace) <$> BS.getLine

readInteger = fst . fromJust . BS.readInteger
readIntegerList = map readInteger . BS.words
getInteger = readInteger <$> BS.getLine
getIntegerList = readIntegerList <$> BS.getLine

inf :: Int
inf = 10^18

main = do
  [n', m'] <- getIntList
  let n = min n' m'
      m = max n' m'

      ans | n >= 3 && m >= 3 = (n - 2) * (m - 2)
          | n == 1 && m >= 2 = m - 2
          | n == 1 && m == 1 = 1
          | otherwise = 0
  print ans



Measured memory_bytes: 380
#include <iostream>
using namespace std;
int main(void){
    long long N,i,n;
    string S;
    cin>>N>>S;
    n=S.length();
    for(i=0;i<n;i++){
        S[i]=(S[i]-'A'+N)%26+'A';
    }
    cout<<S<<endl;
}


Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <set>
#include <string>
#include <vector>

using namespace std;
const int MOD = 1000000007;

int main() {
    int N;
    cin >> N;
    long long count = 1, count1 = 1, count2 = 1;
    for(int i = 0; i < N; ++i){
        count = 10 * count % MOD;
        count1 = 9 * count1 % MOD;
        count2 = 8 * count2 % MOD;
    }
    count1 = 2 * count1 % MOD;
    long long ans = count - (count1 - count2);
    if(ans < 0){
        ans += MOD;
    } 
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3596
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        long x = sc.nextLong();
        long[] a = new long[n];
        for (int i = 0; i < n; i++) {
            a[i] = sc.nextLong();
        }

        long count = 0;
        if (a[0] > x) {
            count += a[0] - x;
            a[0] -= count;
        }
        for (int i = 0; i < n - 1; i++) {
            if (a[i] + a[i + 1] <= x) {
                continue;
            }
            long diff = a[i] + a[i + 1] - x;
            count += diff;
            a[i + 1] -= diff;
        }
        System.out.println(count);
    }

}


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

int m, k;
vector <int> seq;

int main()
{
    scanf("%d %d", &m, &k);
    if (k == 0)
        for (int i = 0; i < 1 << m; i++) {
            seq.push_back(i);
            seq.push_back(i);
        }
    else if (k >= 1 << m || m == 1) { printf("-1\n"); return 0; }
         else {
            for (int i = 0; i < 1 << m; i++) if (i != k)
                seq.push_back(i);
            seq.push_back(k);
            for (int i = (1 << m) - 1; i >= 0; i--) if (i != k)
                seq.push_back(i);
            seq.push_back(k);
         }
    for (int i = 0; i < seq.size(); i++)
        printf("%d%c", seq[i], i + 1 < seq.size()? ' ': '\n');
    return 0;
}


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

using namespace std;
using ll=long long;
using ull=unsigned long long;
using pii=pair<int,int>;

#define INF LONG_MAX
#define MOD 1000000007
#define rng(a) a.begin(),a.end()
#define rrng(a) a.end(),a.begin()
#define endl "\n"

unsigned int randxor(){
  static unsigned int x=123456789,y=362436069,z=521288629,w=88675123;
  unsigned int t;
  t=(x^(x<<11));x=y;y=z;z=w; return( w=(w^(w>>19))^(t^(t>>8)) );
}

#define int ll

int D;
const int N=26;
vector<vector<int>>s;
vector<int>c;

ll score(vector<int>&t){
  ll score=0;
  ll ans=0;
  vector<int>last(N,-1);
  for(int i=0;i<D;i++){
    ans+=s[i][t[i]];
    last[t[i]]=i;
    for(int j=0;j<N;j++){
      if(last[j]==-1)ans-=c[j]*(i+1);
      else ans-=c[j]*(i-last[j]);
    }
    score+=max(ans+1000000,0ll);
  }
  return score;
}

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

  auto start = std::chrono::system_clock::now();  
  cin>>D;
  c.resize(N);
  for(int i=0;i<N;i++)cin>>c[i];
  s.resize(D,vector<int>(N));
  for(int i=0;i<D;i++)for(int j=0;j<N;j++)cin>>s[i][j];

  vector<int>t(D,0);

  ll S=0;
  for(int i=0;i<D;i++){
    for(int j=0;j<N;j++){
      int memon=t[i];
      t[i]=j;
      ll SS=score(t);
      if(S<SS)S=SS;
      else t[i]=memon;
    }
  }
  while(true){
    for(int x=0;x<100;x++){
      int d=randxor()%D;
      int n=randxor()%N;
      int memon=t[d];
      t[d]=n;
      ll SS=score(t);
      if(S<SS)S=SS;
      else t[d]=memon;
    }
    auto end = std::chrono::system_clock::now();
    auto dur = end-start;
    auto msec = std::chrono::duration_cast<std::chrono::milliseconds>(dur).count();
    if(1980<msec)break;
  }

  for(auto it:t)cout<<it+1<<endl;
  return 0;
}


Measured memory_bytes: 3768
#include<iostream>
#include<string>
#include<algorithm>
#include<math.h>
#include<vector>
#include<utility>

using namespace std;

int main(){

	int n;
	cin>>n;
	string s1,s2;
	cin>>s1>>s2;

	for(int i=0;i<n;i++){
		cout<<s1[i]<<s2[i];
	}

	cout<<endl;

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define IO_OP std::ios::sync_with_stdio(0); std::cin.tie(0);
#define F first
#define S second
#define V vector
#define PB push_back
#define MP make_pair
#define EB emplace_back
#define ALL(v) (v).begin(), (v).end()
#define debug(x) cerr << #x << " is " << x << endl

using namespace std;

typedef long long ll;
typedef pair<int, int> pi;
typedef V<int> vi;

const int INF = 1e9 + 7, N = 2e5 + 7, M = 998244353;

vi G[N];
bool vis[N];

int dfs(int u) {
	vis[u] = 1;
	int ans = 1;
	for(int v:G[u]) ans = (ll) ans * dfs(v) % M;
	ans = (ans + 1) % M;
	return ans;
}

signed main()
{
	IO_OP;

	int n;
	cin >> n;
	V<pi> v;
	for(int i = 0; i < n; i++) {
		int x, d;
		cin >> x >> d;
		v.EB(x, d);
	}
	sort(ALL(v));
	deque<pi> dk;
	for(int i = v.size() - 1; i >= 0; i--) {
		int r = v[i].F + v[i].S;
		while(dk.size() && dk[0].F < r) G[i].PB(dk[0].S), dk.pop_front();
		dk.push_front({v[i].F, i});
	}
	int ans = 1;
	for(int i = 0; i < n; i++) {
		if(!vis[i]) ans = (ll) ans * dfs(i) % M;
	}
	cout << ans << endl;

}





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

#define ll long long
#define Fi first
#define Se second
#define Pb push_back
#define vi vector<int>
#define vp vector<pair<int,int>>
#define vvi vector<vector<int>>
#define vvp vector<vector<pair<int,int>>>

const int INF = 1e9;
const int MOD = 1e9+7;
using Graph = vector<vector<int>>; //Caution!! Segmentation Fault!! Don't forget to add +1!

#define all(v) v.begin(),v.end()
#define output_s(a) printf("%s\n",(a).c_str())

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define Rep(i,n,m) for(int i=(int)(n);i<(int)(m);i++)
#define RepS(i,n,m) for(int i=(int)(n);i<=(int)(m);i++)
#define RRepS(i,n,m) for(int i=(int)(n);i>=(int)(m);i--)
#define RepA(x) for(auto &item:(x))

void CINT(){}
template <class Head,class... Tail>
void CINT(Head&& head,Tail&&... tail){
    cin>>head;
    CINT(move(tail)...);
}    
#define CIN(...) int __VA_ARGS__;CINT(__VA_ARGS__)
#define LCIN(...) ll __VA_ARGS__;CINT(__VA_ARGS__)
#define SCIN(...) string __VA_ARGS__;CINT(__VA_ARGS__)

template<typename TypeInt> //最大公約数
TypeInt GCD(TypeInt a,TypeInt b){
    if(a%b==0) return b;
    else return GCD(b,a%b);
}
template<typename TypeInt> //最小公倍数
TypeInt LCM(TypeInt a,TypeInt b){
    return a*b/GCD(a,b);
}

int IN_int(){
    int x;
    scanf("%d",&x);
    return x;
}

//library----------------------------------------------

//const int dx[4]={1,0,-1,0};
//const int dy[4]={0,1,0,-1};
const int dx[8]={1,0,-1,0,1,-1,-1,1};
const int dy[8]={0,1,0,-1,1,1,-1,-1};

const int NMAX = 100;
bool flag;

bool comp(int x,int y){
    return abs(0-x)<abs(0-y);
}

signed main(){
    int N=IN_int();
    map<string,int> card;
    rep(i,N){
        string s;cin>>s;
        card[s]++;
    }
    int M=IN_int();
    rep(i,M){
        string s;cin>>s;
        card[s]--;
    }
    int ans=0;
    RepA(card){
        ans=max(ans,item.Se);
    }
    printf("%d\n",ans);

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define SZ(x) ((int)x.size())
#define FOR(i,a,b) for (int i=a;i<=b;++i)
#define FORD(i,a,b) for (int i=a;i>=b;--i)
using namespace std;
typedef long long LL;
typedef pair<LL,int> pa;
typedef vector<int> vec;
void getint(int &v){
    char ch,fu=0;
    for(ch='*'; (ch<'0'||ch>'9')&&ch!='-'; ch=getchar());
    if(ch=='-') fu=1, ch=getchar();
    for(v=0; ch>='0'&&ch<='9'; ch=getchar()) v=v*10+ch-'0';
    if(fu) v=-v;
}
const LL INF=1e18;
int n,D,a[500010];
bool u[500010];
LL ans;
struct node{
	pa v[2][2]; //[in MST now];[use + -]
	pa t;
	node(){
		v[0][0]=v[0][1]=v[1][0]=v[1][1]=mp(INF,0);
		t=mp(INF,0);
	}
}T[800010];
void pushup(int rt){
	T[rt].t=min(T[rt<<1].t,T[rt<<1|1].t);
	T[rt].t=min(T[rt].t,mp(T[rt<<1].v[0][0].fi+T[rt<<1|1].v[1][1].fi,T[rt<<1].v[0][0].se));
	T[rt].t=min(T[rt].t,mp(T[rt<<1].v[1][0].fi+T[rt<<1|1].v[0][1].fi,T[rt<<1|1].v[0][1].se));
	T[rt].v[0][0]=min(T[rt<<1].v[0][0],T[rt<<1|1].v[0][0]);
	T[rt].v[0][1]=min(T[rt<<1].v[0][1],T[rt<<1|1].v[0][1]);
	T[rt].v[1][0]=min(T[rt<<1].v[1][0],T[rt<<1|1].v[1][0]);
	T[rt].v[1][1]=min(T[rt<<1].v[1][1],T[rt<<1|1].v[1][1]);
}
void build(int l,int r,int rt){
	if (l==r){
		T[rt].v[u[l]][0]=mp(a[l]-1ll*l*D,l);
		T[rt].v[u[l]][1]=mp(a[l]+1ll*l*D,l);
		T[rt].v[u[l]^1][0]=mp(INF,0);
		T[rt].v[u[l]^1][1]=mp(INF,0);
		return;
	}
	int m=l+r>>1;
	build(l,m,rt<<1);
	build(m+1,r,rt<<1|1);
	pushup(rt);
}
void upd(int l,int r,int rt,int x){
	if (l==r){
		T[rt].v[u[l]][0]=mp(a[l]-1ll*l*D,l);
		T[rt].v[u[l]][1]=mp(a[l]+1ll*l*D,l);
		T[rt].v[u[l]^1][0]=mp(INF,0);
		T[rt].v[u[l]^1][1]=mp(INF,0);
		return;
	}
	int m=l+r>>1;
	if (x<=m) upd(l,m,rt<<1,x);
	else upd(m+1,r,rt<<1|1,x);
	pushup(rt);
}
void prim(){
	build(1,n,1);
	u[1]=1;
	upd(1,n,1,1);
	FOR(rp,2,n){
		pa tmp=T[1].t;
		ans+=tmp.fi;
		u[tmp.se]=1;
		upd(1,n,1,tmp.se);
	}
}
int main(){
	cin>>n>>D;
	FOR(i,1,n) getint(a[i]);
	prim();
	printf("%lld\n",ans);
	return 0;
}


Measured memory_bytes: 64128
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define pp pair<int,int>
#define ll long long
#define ld long double
int inf=100000000;
ll INF=4000000000000000000;
ll MOD=1000000007;


int main() {
  int n;
  cin >> n;
  vector<int> a(n),c(0);
  list<int> b;
  rep(i,n) cin >> a.at(i);
  for (int i=n-1;i>=0;i--){
      b.push_back(a.at(i));
  }
  rep(i,n) {
      auto it=b.begin();
      rep(j,n-i){
          if (*it==n-i-j) {
            b.erase(it);
            c.push_back(*it);
            break;
          }
          it++;
          if (j==n-i-1) {cout << -1 << endl;return 0;}
      }
  }
  for (int i=n-1;i>=0;i--) cout << c.at(i) << endl;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner scan = new Scanner(System.in);
		int a = scan.nextInt();
		int b = scan.nextInt();
		int c = scan.nextInt();
		if(a==b) {
			System.out.println(c);
		}else if(b==c) {
			System.out.println(a);
		}else if(a==c) {
			System.out.println(b);
		}
	}

}


Measured memory_bytes: 23636
#include <bits/stdc++.h>
using namespace std;
template <class T>
inline bool chmax(T &a, T b)
{
	if (a < b)
	{
		a = b;
		return 1;
	}
	return 0;
}
template <class T>
inline bool chmin(T &a, T b)
{
	if (a > b)
	{
		a = b;
		return 1;
	}
	return 0;
}
const long long INFLL = 1LL << 60;
const int INF = 1 << 28;
const long long MOD = 1000000000 + 7;
int main(){
	int n,m;
	long long bef;
	cin >>n;
	bool ans=true;
	map<long long ,int>d;
	for(int i=0;i<n;i++){
		cin >>bef;
		d[bef]+=0;
		d[bef]++;
	}
	cin >>m;
	for(int i=0;i<m;i++){
		cin>>bef;
		if(d[bef]>=1){
		d[bef]--;
		}else{
			ans=false;
			break;
		}
		}
	cout << (ans ? "YES" : "NO") << endl;
}


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

// 型定義
typedef long long ll;
typedef pair<ll, ll> P;

// forループ
#define REP(i,n) for(ll i=0; i<(ll)(n); ++i)

// 定数宣言
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

// グラフ表現
using Graph = vector<vector<int>>;

// グラフの辺表現
using Edge = map<pair<int,int>,int>;

// n次元配列の初期化。第２引数の型のサイズごとに初期化していく。
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

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

// 最小公倍数
ll lcm(ll a, ll b){
    return a*b/gcd(a, b);
}

ll dp[1100][5000];

int main()
{
    cout << fixed << setprecision(15);
    ll N, M;
    cin >> N >> M;

    vector<ll> A(M), B(M), C(M, 0); // c はビットで表す

    REP(i, M){
        cin >> A[i] >> B[i];
        REP(j, B[i]){
            ll t;
            cin >> t;
            t--;
            C[i] += (1<<t);
        }
    }
    
    // REP(i, M){
    //     cout << C[i] << endl;
    // }
    // Fill(dp, INF);
    REP(i, 1100){
        REP(j, 5000){
            dp[i][j] = INF;
        }
    }

    dp[0][0] = 0;

    // cout << 1 << endl;
    for (ll i=0; i<M; ++i) {
        for (int j=0; j<(1<<N); ++j) {
            dp[i+1][j] = min(dp[i+1][j], dp[i][j]);
            
            ll nj = j | C[i];
            dp[i+1][nj] = min(dp[i+1][nj], dp[i][j] + A[i]);
        }
    }

    // cout << 2 << endl;
    if(dp[M][(1<<N)-1] == INF){
        cout << -1 << endl;
        return 0;
    }
    cout << dp[M][(1<<N)-1] << endl;
    // cout << INF << endl;
    return 0;
}

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

int main() {
    char B[51][51];
    int N[52][52]={};
    int h, w;
    cin >> h >> w;
    for(int i = 0; i< h; ++i) {
        cin >> B[i];
    }
    for(int i = 0; i < h; ++i) {
        for(int j = 0; j < w; ++j) {
            if(B[i][j] == '#') {
                ++N[i][j];
                ++N[i][j+1];
                ++N[i][j+2];
                ++N[i+1][j];
                ++N[i+1][j+2];
                ++N[i+2][j];
                ++N[i+2][j+1];
                ++N[i+2][j+2];
            }
        }
    }
    for(int i = 0; i < h; ++i) {
        for(int j = 0; j < w; ++j) {
            if(B[i][j] == '#') {
                cout << '#';
            } else {
                cout << N[i+1][j+1];
            }
        }
        cout << endl;
    }
}

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

int n;

int binarysearch(int a[],int key){
    int left=0;
    int right=n;
    while (left<right) {
        int mid=(left+right)/2;
        if (a[mid]==key) {
            return 1;
        }else if (key<a[mid]){
            right=mid;
        }else{
            left=mid+1;
        }
    }
    return 0;
}

int main(){
    cin>>n;
    int s[n];
    for (int i=0; i<n; i++) {
        cin>>s[i];
    }
    int q;
    cin>>q;
    int ans=0;
    for (int i=0; i<q; i++) {
        int t;
        cin>>t;
        ans+=binarysearch(s, t);
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 3488
#include<iostream>
using namespace std;
class Cube{
public:
int f[6];
Cube(){}
void roll_z(){ roll(1,2,4,3);}
void roll_y(){ roll(0,2,5,3);}
void roll_x(){ roll(0,1,5,4);}
void roll(int i,int j,int k,int l){
int t=f[i]; f[i]=f[j]; f[j]=f[k]; f[k]=f[l]; f[l]=t;
}
};
int getRight(Cube c1,int f1,int f2){
for(int i=0;i<6;i++){
for(int j=0;j<4;j++){
if(c1.f[0]==f1&&c1.f[1]==f2)return c1.f[2];
c1.roll_z();
}
if(i%2==0) c1.roll_y();
else c1.roll_x();
}
return -1;
}
int main(){
Cube c;
int f1,f2;
for(int i=0;i<6;i++) cin >>c.f[i];
int q; cin >>q;
for(int i=0;i<q;i++){
cin >>f1 >>f2;
cout <<getRight(c,f1,f2) <<endl;
}
return 0;
}

Measured memory_bytes: 3068
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
 
public class Main {

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

      String[] lines = br.readLine().split(" ");
      int a = Integer.parseInt(lines[0]);
      int b = Integer.parseInt(lines[1]);

      System.out.println((a+b) / 2);
    }
  }
}


Measured memory_bytes: 24324
from itertools import product

n = int(input())
xs, ys, hs = zip(*[[int(x) for x in input().split()] for _ in range(n)])

for i, j in product(range(0,101), repeat=2):
    k = -1
    l = 1 << 32
    for x, y, h in zip(xs, ys, hs):
        if h == 0:
             l = min(l, abs(x-i) + abs(y-j))
        elif k == -1:
             k = abs(x-i) + abs(y-j) + h
        elif k!=-1 and k - h != abs(x-i) + abs(y-j):
            break
        if k > l:
            break
    else:
        if k!=-1:
            print(i, j, k)
        elif l==1:
            print(i, j, 1)
        break
        

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

int main(){
  int H,W;
  cin >> H >>W;
  string s[60];
  int dx[8]={1,1,1,0,0,-1,-1,-1};
  int dy[8]={1,0,-1,1,-1,1,0,-1};
    
  for(int i=0;i<H;i++){
  cin>>s[i];
  }
 
  for(int i=0;i<H;i++){
    for(int j=0;j<W;j++){
     if(s[i][j]=='.'){
      
       int cnt=0;
       for(int k=0;k<8;k++){
         int i2=i+dx[k];
         int j2=j+dy[k];
         if(i2>=0 && i2<H && j2>=0 && j2<W && s[i2][j2]=='#'){
         cnt++;
         }
         s[i][j] = cnt+'0';
       }
     }  
       
      
    }  
  }

  for(int i=0;i<H;i++) cout << s[i] << endl;
return 0;
}


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

using namespace std;

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

//===



int main() {
	int r;
	cin >> r;
	cout << 3 * r * r << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
	int w,a,b;
	cin>>w>>a>>b;
	if(b+w<=a+w&&a<=b+w){
		cout<<0<<endl;
	}
	else if(b+w>=a+w&&b<=a+w){
		cout<<0<<endl;
	}
	else{
		cout<<min(abs(b-a-w),abs(a-b-w))<<endl;
	}
}


Measured memory_bytes: 256
#
# File    : A.rb
# Author  : Kazune Takahashi
# Created : 12/29/2018, 9:01:37 PM
# Powered by Visual Studio Code
#

a, b, c = gets.chomp.split(" ").map{|i| i.to_i}
if c >= a + b + 1
  puts b + (a + b + 1)
else
  puts b + c
end


Measured memory_bytes: 1788
program r20628b
 
implicit none
integer :: c(1:26)
integer :: interval(1:26)
integer, allocatable :: s(:, :)
integer, allocatable :: t(:), v(:)
integer :: i, j, d

read *, d

allocate(s(1:26, 1:d))
allocate(t(1:d))
allocate(v(0:d))

interval(:) = 0 !interval(i) = d - last(d,i)
v(0) = 0

read *, c(1:26)

do i = 1, d
 read *, s(:, i)
end do

do i = 1, d
 read *, t(i)
 
 v(i) = v(i-1) + s(t(i), i)
 
 do j = 1, 26
  if(t(i) == j) then
   interval(j) = 0
  else
   interval(j) = interval(j) + 1
  end if
  v(i) = v(i) - (c(j) * interval(j))
 end do
 
 print *, v(i)
end do

end program r20628b

Measured memory_bytes: 2892
#include <iostream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
#include <set>

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,j) FOR(i,0,j)
#define mp std::make_pair

typedef long long ll;
typedef unsigned long long ull;
typedef std::pair<int,int> P;
typedef std::pair<int,P> State;

const int INF = 1001001001;

// S N E W(南北東西)
const int dx[8] = {0, 0, 1, -1, 1, 1, -1, -1}, dy[8] = {1, -1, 0, 0, 1, -1, 1, -1};

int N;
std::vector<std::string> dict[26];

std::vector<std::string> split(std::string s){
    s += " ";
    std::vector<std::string> res;
    int pos = 0, prev_pos = 0;
    while(pos = s.find(" ", pos), pos != std::string::npos){
        res.push_back(s.substr(prev_pos, pos-prev_pos));
        ++pos; prev_pos = pos;
    }
    return res;
}

int main(){
    while(std::cin >> N, N){
        REP(i, 26){
            dict[i].clear();
        }
        std::cin.ignore();

        REP(i, N){
            std::string s;
            std::getline(std::cin, s);

            for(auto t : split(s)){
                dict[t[0]-'a'].push_back(t);
            }
        }

        char C;
        std::cin >> C;

        auto &v = dict[C-'a'];
        std::sort(v.begin(), v.end());

        std::vector<std::pair<int, std::string>> res;
        int n = 1;
        for(int i=0;i<v.size();i++){
            if(i+1 >= v.size() || v[i] != v[i+1]){
                res.push_back(mp(-n, v[i]));
                n = 1;
            }else{
                ++n;
            }
        }

        std::sort(res.begin(), res.end());
    
        if(res.size() == 0){
            puts("NA");
        }else{
            for(int i=0;i<std::min<int>(res.size(),5);i++){
                // printf("%d, %s\n", res[i].first, res[i].second.c_str());
                if(i == 0){std::cout << res[i].second;}
                else{std::cout << " " << res[i].second;}
            }
            std::cout << std::endl;
        }
    }
}

Measured memory_bytes: 1276
#include <iostream>
#include <vector>
using namespace std;
int main(void){
    // Your code here!
    int n,m;
    cin>>n>>m;
    vector<int> a(n);
    int sum = 0;
    for(int i=0;i<n;++i){
        cin>>a[i];
        sum += a[i];
    }
    int count = 0;
    for(int i=0;i<n;++i) if(a[i]*4*m>=sum) count++;
    if(count >= m) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}


Measured memory_bytes: 256
H, W = map(int, input().split())
S = [input() for _ in range(H)]
ad = ['.' for _ in range(W)]
S.append(ad)
S.insert(0, ad)
newS = [['#' for _ in range(W)] for _ in range(H)]
for i in range(1, H+1):
    for j in range(W):
        if S[i][j] == '.':
            c = max(0, j-1)
            d = min(W-1, j+1)
            cnt = S[i][c:d+1].count('#')
            cnt += S[i-1][c:d+1].count('#')
            cnt += S[i+1][c:d+1].count('#')
            newS[i-1][j] = str(cnt)
for i in newS:
    print(''.join(i))


Measured memory_bytes: 3188
#include <iostream>
#include <algorithm>
#include <vector>

using namespace std;

using VI = vector<int>;

#define ALL(a) (a).begin(),(a).end()
#define SORT(c) sort((c).begin(),(c).end())
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define IN(v) int v;cin>>v;
#define OUT(v) cout<<v<<endl

int main() {
  IN(N);

  VI S;
  REP(i, N) {
    IN(s);
    S.push_back(s);
  }
  SORT(S);

  int ans = 0;
  IN(q);
  REP(i, q) {
    IN(t);
    if (binary_search(ALL(S), t))
      ++ans;
  }
  OUT(ans);

  return 0;
}



Measured memory_bytes: 3220
#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(),(x).end()
#define ll long long
#define vi vector<int>
#define pii pair<int,int>
#define F first
#define S second
#define pb push_back
#define forn(b) for(int i = 0; i < b; i++)
#define rforn(b) for(int i = b - 1 ;i >= 0; i--)
#define It(m) for(auto it = m.begin(); it != m.end(); it++)
#define N 500500
#define PI 3.14159265358979323846264338327950L
#define speed ios_base :: sync_with_stdio(0);cin.tie(0);cout.tie(0);
    
const ll mod = (ll)1e9 + 7;
    
int main(){
    speed;
    char c; cin >> c;
    if(c >= 'a' && c <= 'z') cout << 'a';
    else cout << 'A';   
    return 0;
}

Measured memory_bytes: 3652