akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<map>
#include<cstdio>
#include<string>
using namespace std;
int main(){
	int n,m,en,cnt,a,b,c;
	string str,str2;
	while(1){
		map<string,int> data;
		cin >> n;
		if(n==0) break;
		for(int i=0;i<n;i++){
			cin >> str >> en;
			data[str]=en;
		}
		cin >> m;
		for(int i=0;i<m;i++){
			cnt = 0;
			cin >> str >> a;
			for(int j=0;j<a;j++){
				cin >> str2;
				cnt += data[str2];
			}
			if(data[str] > cnt){
				data[str] = cnt;
			}
		}
		cin >> str;
		cout << data[str] << endl;	
	}
}

Measured memory_bytes: 1220
import scala.io.Source.stdin

object Main extends App {
  stdin.getLines.foreach { s =>
    val n = s.split(" ").map(_.toInt)
    if((1 to 10).filter( i => i!=n(0) && i!=n(1) && i!=n(2) ).count( _ <= 20-(n(0)+n(1)) ) >= 4)
      println("YES")
    else
      println("NO")
  }
}

Measured memory_bytes: 44112
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <iostream>
#include <queue>
#include <map>
#include <set>
#include <string>
#include <vector>
using namespace std;
#define REP(i, n) for(int i = 0; i < (int)(n); ++i)
#define FOR(i, c) for(__typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
typedef long long ll;

long long inv(int a, int p) { return a==1 ? 1 : (1-p*inv(p%a,a))/a+p; }
static const int MODVAL = 1000003;
struct mint {
  int val;
  mint():val(0){}
  mint(int x):val(x%MODVAL) {}
  mint(size_t x):val(x%MODVAL) {}
  mint(long long x):val(x%MODVAL) {}
  mint& operator+=(mint y) { val+=y.val; if(val>=MODVAL) val-=MODVAL; return *this; }
  mint& operator-=(mint y) { val-=y.val; if(val<0) val+= MODVAL; return *this; }
  mint& operator*=(mint y) { val=(val*(long long)y.val)%MODVAL; return *this; }
  mint& operator/=(mint y) { val=(val*inv(y.val,MODVAL))%MODVAL; return *this; }
};
inline mint operator+(mint x, mint y) { return x+=y; }
inline mint operator-(mint x, mint y) { return x-=y; }
inline mint operator*(mint x, mint y) { return x*=y; }
inline mint operator/(mint x, mint y) { return x/=y; }
mint POW(mint x, long long n) { mint r(1); for(;n;x*=x,n>>=1) if(n&1) r*=x; return r; }
mint FAC(int n) { static vector<mint> FAC_(1,1);
  while(int(FAC_.size())<=n) FAC_.push_back(FAC_.back()*FAC_.size()); return FAC_[n]; }
inline mint CMB(int n, int k) { return k<0||n<k ? 0 : FAC(n) / (FAC(k) * FAC(n-k)); }
inline ostream& operator<<(ostream& os, mint a) { return os << a.val; }

int main(void) {
  int nQuery;
  scanf("%d", &nQuery);
  REP(iQuery, nQuery) {
    int x, d, n;
    scanf("%d%d%d", &x, &d, &n);
    mint res;
    if(d == 0) {
      res = POW(x, n);
    } else {
      mint x_d = mint(x) / d;
      if(x_d.val + n-1 >= MODVAL) {
        res = 0;
      } else {
        res = FAC((x_d+n-1).val) / FAC((x_d-1).val) * POW(d, n);
      }
    }
    printf("%d\n", res.val);
  }
  return 0;
}


Measured memory_bytes: 6512
#pragma GCC optimize("Ofast")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#include <bits/stdc++.h>
/*#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>*/
 
#define pll              pair <long long,long long>
#define pb               push_back
#define ll               long long
#define ff               first
#define ss               second
#define D(x)             cerr<<#x " = "<<(x)<<endl
#define vll              vector <ll>
#define IOS              ios_base::sync_with_stdio(0); cin.tie(NULL);
#define endl             '\n'   
using namespace std;

ll nc2(ll n)
{
	return (n*(n-1LL))/2LL;
}

int main()
{
    IOS
 	// freopen("input.txt","r",stdin);
 	// freopen("output.txt","w",stdout);
 	// freopen("error.txt","w",stderr);
 	ll n;
 	cin>>n;
 	ll tot=0;
 	map<ll,ll>mp;
 	ll a[n];
 	for(ll i=0;i<n;i++)
 	{
 		cin>>a[i];
 		mp[a[i]]++;
 	}
 	for(pll x:mp)
 	{
 		tot+=nc2(x.second);
 	}	
 	for(ll i=0;i<n;i++)
 	{
 		cout<<tot-nc2(mp[a[i]])+nc2(mp[a[i]]-1)<<endl;
 	}
    return 0;
}

Measured memory_bytes: 12160
#include<stdio.h>
#include<string.h>
int main(void){
    char s[10],t[10],u[10];
    int a,b;
    scanf("%s %s",s,t);
    scanf("%d %d",&a,&b);
    scanf("%s",u);
    if(strcmp(s,u)==0){
        printf("%d %d",a-1,b);
    }
    else{
        printf("%d %d",a,b-1);
    }
    return 0;
}

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

template <typename T, typename U> void cmin(T &a, U b) {
  if (a > b) a = b;
}
template <typename T, typename U> void cmax(T &a, U b) {
  if (a < b) a = b;
}

int main() {
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);

  int N;
  cin >> N;
  vector<int> A(N);
  for (int i = 0; i < N; i++) cin >> A.at(i);
  sort(A.begin(), A.end());

  auto f = [&](auto V) {
    int n = V.size();
    long res = 0;
    for (int i = 0; i + 1 < n; i++) {
      res += abs(V.at(i) - V.at(i + 1));
    }
    return res;
  };

  if (N % 2) {
    
    vector<int> C1;
    for (int i = 0; i < N / 2; i++) {
      C1.push_back(A.at(i));
      C1.push_back(A.at(N - 1 - i));
    }
    auto C2 = C1;
    C1.push_back(A.at(N / 2));
    C2.insert(C2.begin(), A.at(N / 2));
    
    vector<int> C3;
    for (int i = 0; i < N / 2; i++) {
      C3.push_back(A.at(N - 1 - i));
      C3.push_back(A.at(i));
    }
    auto C4 = C3;
    C3.push_back(A.at(N / 2));
    C4.insert(C4.begin(), A.at(N / 2));

    cout << max({f(C1), f(C2), f(C3), f(C4)}) << "\n";
    
  } else {

    int x = A.at(N / 2 - 1);
    int y = A.at(N / 2);

    vector<int> C1;
    for (int i = 0; i < N / 2 - 1; i++) {
      C1.push_back(A.at(i));
      C1.push_back(A.at(N - 1 - i));
    }
    auto C2 = C1;
    C1.push_back(x);
    C1.insert(C1.begin(), y);
    C2.push_back(y);
    C2.insert(C2.begin(), x);
    
    vector<int> C3;
    for (int i = 0; i < N / 2 - 1; i++) {
      C3.push_back(A.at(N - 1 - i));
      C3.push_back(A.at(i));
    }
    auto C4 = C3;
    C3.push_back(x);
    C3.insert(C3.begin(), y);
    C4.push_back(y);
    C4.insert(C4.begin(), x);

    cout << max({f(C1), f(C2), f(C3), f(C4)}) << "\n";

  }
}


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

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

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

	int n;
	cin >> n;

	while (n > 0) {
		if (n % 10 == 7) {
			cout << "Yes";
			return 0;
		}

		n /= 10;
	}

	cout << "No";

	return 0;
}

Measured memory_bytes: 3640
#include <bits/stdc++.h>   
#define rep(i, n) for(long long int i = 0; i < n; i++)
#define _rep(i, m, n) for(long long int i = m; i < n; i++)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const ll mod = 1000000007;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
     
ll gcd(ll A, ll B){
    if(B == 0)return A;
    return gcd(B, A % B);
}
ll lcm(ll A, ll B){
    return A * B / gcd(A, B);
}
using Graph = vector<vector<int>>;
Graph G;

vector<ll> lunlun;

void dfs(ll m, int digits){
    lunlun.push_back(m);
    if(m % 10 >= 1 and digits <= 9){
        dfs(m * 10 + m % 10 - 1, digits + 1);
    }
    if(digits <= 9){
        dfs(m * 10 + (m % 10), digits + 1);
    }
    if(m % 10 <= 8 and digits <= 9){
        dfs(m * 10 + m % 10 + 1, digits + 1);
    }
}

int main(){
    ll k; cin >> k;

    _rep(i, 1, 10){
        dfs(i, 1);
    }
    sort(lunlun.begin(), lunlun.end());
    cout << lunlun[k - 1] << endl;
}

Measured memory_bytes: 5340
S = list(input())

if (S[0] == S[1] and S[2] == S[3] and S[0] != S[2]) or (S[0] == S[2] and S[1] == S[3] and S[0] != S[1]) or (S[0] == S[3] and S[1] == S[2] and S[0] != S[1]):
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3060
n = int(input())
h = list(map(int, input().split()))

cost = [float('inf')] * n
cost[0] = 0
cost[1] = abs(h[1] - h[0])

for i in range(2, n):
    one_step = abs(h[i] - h[i - 1]) + cost[i - 1]
    two_step = abs(h[i] - h[i - 2]) + cost[i - 2]
    cost[i] = min(one_step, two_step)

print(cost[n - 1])

Measured memory_bytes: 13928
#include<bits/stdc++.h>
using namespace std;
const long long INF = (1LL << 32);
const long long MOD = 1000000007;
const long double PI = 3.1415926;
#define FOR(i,r,n) for(ll i = (ll)(r); i < (ll)(n); i++)
#define RFOR(i,r,n) for(ll i=(ll)(n-1);i>=r;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define ALL(x) x.begin(),x.end()
#define RALL(x) x.rbegin(),x.rend()
typedef long long int ll;
typedef vector<ll> vi;
typedef vector<pair<ll, ll>> vp;
typedef vector<string> vs;
typedef vector<char> vc;
typedef list<ll> lst;
typedef pair<ll, ll> P;

ll n, m, k, ans = 0, sum = 0, cnt = 0;
string s;
char c;

#define Endl endl

/*--------------------template--------------------*/


int main() {
    ll a, b, c;
    cin >> a >> b >> c >> n;
    REP(i,a+1) {
        REP(j,b+1) {
            REP(k,c+1) {
                if(i*500+j*100+k*50==n){
                    cnt++;
                }
            }
        }
    }
    cout << cnt << endl;
    
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int gcd(int a, int b) {
  if (a % b == 0) {
    return b;
  }
  return gcd(b, a % b);
}
int main() {
  int n;
  int a, b;
  cin >> n;
  int ans;
  cin >> a >> b;
  ans = gcd(a, b);
  for (int i = 2; i < n; i++) {
    if (ans == 1) {
      break;
    }
    cin >> b;
    ans = gcd(ans, b);
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define MODV 1000000007
#define INF INT_MAX // 2147483647
#define INFLL LLONG_MAX // 9223372036854775807
#define rep(i, n) for(ll i=0, i##_len=(ll)(n); i<i##_len; i++)
#define repf(i, n) for(ll i=1, i##_len=(ll)(n+1); i<i##_len; i++)
#define per(i, n) for(ll i=((ll)(n))-1; i>=0; i--)
#define perf(i, n) for(ll i=((ll)(n)); i>0; i--)
#define all(v) v.begin(), v.end()
#define endl "\n"
#define vi vector<ll>
#define vvi vector<vector<ll>>
#define Yes() cout << "Yes" << endl
#define YES() cout << "YES" << endl
#define No() cout << "No" << endl
#define NO() cout << "NO" << endl
#define Init() std::ios::sync_with_stdio(false); std::cin.tie(0); std::cout<<fixed<<setprecision(15);
template<class T>bool chmax(T &a, const T &b){ if(a<b){ a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b){ if(b<a){ a=b; return 1; } return 0; }
using namespace std;

// 操作の必要回数を計算する
ll repOp(ll dist, ll k){ return ceil(1.0*dist/(k-1)); }

int main(){
    Init();
    ll n, k, pos, ans = INFLL; cin >> n >> k; vi a(n);
    // 入力処理・最小値(1)の添字を取得
    rep(i, n){ cin >> a[i]; if(a[i] == 1) pos = i; }
    // nとkが等しい場合は1回の操作で終了する
    if(n == k) ans = 1;
    // nとkが等しくない場合は左右に何回の操作が必要か分けて計算する
    else{
        // 最初の操作の仕方をk通り試す
        for(ll i=0; i<k; i++){
            // 左右どちらかにはみ出る操作の仕方は飛ばす
            if(pos-i < 0 || pos+(k-1)-i > n-1) continue;
            // 1回操作を行ったのち、最左の1と最右の1からそれぞれ左右に何回操作が必要か計算する
            ll tmp = 1 + repOp(abs(0-(pos-i)), k) + repOp(abs(n-1-(pos+(k-1)-i)), k);
            // 最小値の更新
            chmin(ans, tmp);
        }
    }
    // 出力処理
    cout << ans << endl;
}

Measured memory_bytes: 1024
#include<stdio.h>
int  main()
{
    int ara[11];
    int i,j,t;
    for(i=0;i<10;i++){
        scanf("%d", &ara[i]);
    }
    for(i=0;i<10;i++){
        for(j=i+1;j<10;j++){
            if(ara[i]>ara[j]){
                t=ara[i];
                ara[i]=ara[j];
                ara[j]=t;
            }
        }
    }
    for(i=9;i>6;i--){
        printf("%d\n", ara[i]);
    }

return 0;
}

Measured memory_bytes: 600
#include <map>
#include <queue>
#include <cmath>
#include <ctime>
#include <vector>
#include <cstdio>
#include <complex>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <tr1/unordered_map>
#define num(x) (x>='0' && x<='9')
typedef unsigned long long ull;
typedef long long ll;
using namespace std::tr1;
using namespace std;
int read(){
    int p=0, q=1;
    char ch=getchar();
    while (!num(ch))
        (ch=='-'?q=-1:0),
        ch=getchar();
    while (num(ch)) p=p*10+ch-'0', ch=getchar();
    return p*q;
}
#define N 300000
int n, sum;
int p[N][2], g[2], bit[N], ans[N];
char s[N];
void solve(int x){
	int v=s[x]=='1'?1:-1;
	if (sum==1 && v>0) return;
	ans[x]++;
	int k=(g[v>0]-(v>0)*p[n-x-1][1]+(v<0)*p[n-x-1][0])%(sum-v);
	k=(k+sum-v)%(sum-v);
	while (k){
		k=k%bit[k];
		ans[x]++;
	}
}
int get(int mo){
	int p=0;
	for (int i=0;i<n;i++){
		p=(p<<1)+(s[i]=='1');
		if (p>=mo) p-=mo;
	}
	return p;
}
int main(){
	n=read();
	scanf("%s", s);
	for (int i=0;i<n;i++) sum+=s[i]=='1';
	if (sum>1){
		g[1]=get(sum-1);
		p[0][1]=1%(sum-1);
		for (int i=1;i<n;i++) p[i][1]=(p[i-1][1]<<1)%(sum-1);
	}
	g[0]=get(sum+1);
	p[0][0]=1%(sum+1);
	for (int i=1;i<n;i++) p[i][0]=(p[i-1][0]<<1)%(sum+1);
	for (int i=1;i<n;i++) bit[i]=bit[i>>1]+(i&1);
	for (int i=0;i<n;i++) solve(i);
	for (int i=0;i<n;i++) printf("%d\n", ans[i]);
    return 0;
}

Measured memory_bytes: 7044
#include <iostream>
#include <string>

using namespace std;

const int MOD = 1000000007;

int solve(const string& s){
    const int N = s.size()/2;
    long long res = 1;
    int numS = 0, sumS = 0, inc = 0;
    for(auto& c : s){
        if(c == 'B'){
            if(inc%2 == 0){
                ++inc;
                ++numS;
                ++sumS;
            } else {
                if(numS == 0) return 0;
                --inc;
                res = (res * numS) % MOD;
                --numS;
            }
        } else {
            if(inc%2 == 0){
                if(numS == 0) return 0;
                --inc;
                res = (res * numS) % MOD;
                --numS;
            } else {
                ++inc;
                ++numS;
                ++sumS;
            }
        }
    }
    if(sumS != N) return 0;
    for(int i=1;i<=N;i++) res = (res*i)%MOD;
    return res;
}

int main(){
    int N;
    while(cin >> N){
        string s; cin >> s;
        cout << solve(s) << endl;
    }
}

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

int main(){
  int64_t a,b;
  cin>>a>>b;
  if(a>0) cout<<"Positive"<<endl;
  else if(a==0) cout<<"Zero"<<endl;
  else{
    if(b<0 && (b-a)%2==0) cout<<"Negative"<<endl;
    else if(b<0 && (b-a)%2!=0) cout<<"Positive"<<endl;
    else cout<<"Zero"<<endl;
  }
}


Measured memory_bytes: 256
n = int( input() )
an = list( map(int, input().split()) )

bucket = [0]*(1 + 10**5)

for a in an:
    if a < len(bucket):
        bucket[a] += 1
    else:
        bucket[0] += 1

#print(bucket[:5])
ans = 0
for i in range(len(bucket)):
    if i == bucket[i]:
        continue

    ans += bucket[i] if i > bucket[i] else bucket[i] - i


print(ans)

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

    int main() {
        
        int n,k;
        cin >> n >> k;
        int arr[n];
        
        for(int i=0; i<n; i++)
            cin >> arr[i];
            
            sort(arr, arr+n);
            int ans=0;
//            for(int i=0; i<n; i++){
                for(int j=0; j<k; j++){
                    ans+=arr[j];
                    
                }
//            }
        
        cout << ans <<' ';
        return 0;
        }

Measured memory_bytes: 3612
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplication1
{
    class Program
    {
        public static int[,] map = null;
        public static int[,] marker = null;
        public static int N = 0;
        public static int W = 0;
        public static int H = 0;
        public static bool ret = false;
        public static int count = 0;

        public static List<Point> que = new List<Point>();
        // チーズの硬さと座標
        public static Dictionary<int, Point> goal_list = new Dictionary<int, Point>();
        public static List<int> goal_root = new List<int>();

        static void Main(string[] args)
        {
            var data = new List<int>();

            count = 0;

            var sx = 0;
            var sy = 0;
            var s = Console.ReadLine().Split(' ');
            H = int.Parse(s[0]);
            W = int.Parse(s[1]);

            map = new int[W, H];
            marker = new int[W, H];

            // マップ読み込み
            for (int y = 0; y < H; y++)
            {
                var tmp = Console.ReadLine();
                for (int x = 0; x < tmp.Length; x++)
                {
                    map[x, y] = ('#' == tmp[x]) ? 0 : 1;
                    // 空白マスをカウント
                    count += ('.' == tmp[x]) ? 1 : 0;
                }
            }

            var ex = W - 1;
            var ey = H - 1;

            que.Add(new Point(sx, sy));

            // -1で初期化                
            for (int y = 0; y < H; y++)
                for (int x = 0; x < W; x++)
                    marker[x, y] = -1;

            marker[sx, sy] = 0;

            var ret = false;
            while (0 < que.Count)
            {
                var x = que[0].X;
                var y = que[0].Y;

                // ゴールに到達していたら終了
                if (x == ex && y == ey)
                {
                    ret = true;
                    break;
                }

                AddQue(x, y);
                que.RemoveAt(0);
            }

            // 空白マス数から最短経路の距離を引いたマスだけ塗り潰せる(始点をマイナス1)
            count = count - marker[ex, ey] - 1;
            // 塗り潰せない場合は0を出力
            if (count <= 0) count = 0;
            // そもそもゴールに到達していなかったら-1
            if (!ret) count = -1;
            Console.WriteLine(count);
            Console.Read();
        }

        public static void AddQue(int x, int y)
        {
            var distance = marker[x, y];
            Search(x + 1, y, distance + 1);
            Search(x - 1, y, distance + 1);
            Search(x, y + 1, distance + 1);
            Search(x, y - 1, distance + 1);
        }

        public static bool Search(int x, int y, int distance)
        {
            if (x < 0 || y < 0 || W <= x || H <= y || -1 != marker[x, y] || 1 != map[x, y]) return false;

            marker[x, y] = distance;
            que.Add(new Point(x, y));

            return true;
        }
    }

    public class Point
    {
        public int X { get; set; } = 0;
        public int Y { get; set; } = 0;
        public Point() { }
        public Point(int x, int y) { X = x; Y = y; }
    }
}

Measured memory_bytes: 13268
#include <iostream>
using namespace std;
int main(){
int n,x;
int a;
while(1){
a=0;
cin>>n>>x;
if(n==0&&x==0){
break;
}
for(int i=1;i<=n;i++){
 for(int j=i+1;j<=n;j++){
   for(int k=j+1;k<=n;k++){
      if(i+j+k==x){
           a++;
        }
  }
}
}
cout<<a<<endl;
}
return 0;
}

 

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

using namespace std;

int main(){
  int N; long long K; cin>>N>>K;
  vector<long long> A(N);
  for(int i=0;i<N;i++) cin>>A[i];

  long long res=0;

  for(int d=60;d>=-1;d--){
    if(d!=-1&&!(K&(1LL<<d))) continue;
    long long tmp=0;
    for(int e=60;e>=0;e--){
      long long mask=1LL<<e;
      int num=0;
      for(int i=0;i<N;i++) if(A[i]&mask) num++;

      if(e>d){
        if(K&mask) tmp+=mask*(N-num);
        else tmp+=mask*num;
      }
      else if(e==d) tmp+=mask*num;
      else tmp+=mask*max(num,N-num);
    }
    res=max(res,tmp);
  }

  cout<<res<<endl;

  return 0;
}


Measured memory_bytes: 1152
#include <iostream>
#include <cstring>
#include <climits>
using namespace std;

int memoTable[100000];
int K;

int minCost(int index, int* stoneHeight, int nStones){

    if(index == nStones-1){
        return 0;
    }

    if(memoTable[index] != -1){
        return memoTable[index];
    }

    memoTable[index] = INT_MAX;
    
    for(int i=1; i<=K; ++i){
        
        if(index + i < nStones){
            
            memoTable[index] = min(memoTable[index], minCost(index + i, stoneHeight, nStones) + abs(stoneHeight[index] - stoneHeight[index+i]));
        }
        
        
        
    }
    

    return memoTable[index];
}

int main(){

    int nStones;
    cin >> nStones >> K;

    int stoneHeight[100000];
    for(int i=0; i<nStones; ++i){
        cin >> stoneHeight[i];
    }

    memset(memoTable, -1, sizeof(int) * 100000);
    cout<<minCost(0, stoneHeight, nStones);

    return 0;
}

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

using namespace std;
typedef pair<int, int> P;
typedef long long int ll;
int main(){
  int n;cin>>n;
  vector<int> a(n);
  for(int i=0;i<n;i++){
  	cin>>a[i];
  }
  ll sum=0;
  ll ans1=0;
  for(int i=0;i<n;i++){
  	sum+=a[i];
    if(bool(i&1) && sum>=0){
      ans1+=sum+1;
      sum=-1;
    }else if(!bool(i&1) && sum<=0){
      ans1+=1-sum;
      sum=1;
    }
  }
  sum=0;
  ll ans2=0;
  for(int i=0;i<n;i++){
  	sum+=a[i];
    if(!bool(i&1) && sum>=0){
      ans2+=sum+1;
      sum=-1;
    }else if(bool(i&1) && sum<=0){
      ans2+=1-sum;
      sum=1;
    }
  }
  cout<<min(ans1, ans2)<<endl;
}


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

int N;

int main() {
    cin>>N;
    int sumx=0,sumx2=0;     //dis = N*x^2 + sumx*x + sumx2
    for (int i=0; i<N; i++) {
        int temp;cin>>temp;
        sumx+=temp;
        sumx2+=temp*temp;
    }
    int ans=1000000;
    for (int i=0; i<101; i++) ans=min(ans,N*i*i-2*sumx*i+sumx2);
    cout<<ans<<endl;
    return 0;
}


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

int main() {
     int a, b;
     cin >> a >> b;
     if(a == 1 && b == 2 || b == 1 && a == 2) {
        cout << 3;
        return 0;
     }
     if(a == 2 && b == 3 || a == 3 && b == 2) {
        cout << 1;
        return 0;
     }
     if(a == 1 && b == 3 || b == 1 && a == 3) {
        cout << 2;
        return 0;
     }
    return 0;
}


Measured memory_bytes: 256
# Python3 (3.4.3)
import sys
input = sys.stdin.readline

# -------------------------------------------------------------
# function
# -------------------------------------------------------------


# -------------------------------------------------------------
# main
# -------------------------------------------------------------
K,S = map(int,input().split())

ans = 0
for x in range(K+1):
    for y in range(K+1):
        if 0 <= S-(x+y) <= K:
            ans += 1

print(ans)

Measured memory_bytes: 2940
#include <cstdio>
#include <cstring>
#include <algorithm>

using namespace std;

const int N=10000,mo=1e9+7;

typedef long long LL;

int n,m,tot,p[N],f[N],Inv,ans;

int quick(int x,int y)
{
	if (!y) return 1;
	int s=quick(x,y>>1); s=(LL)s*s%mo;
	if (y&1) s=(LL)s*x%mo;
	return s;
}

int main()
{
	scanf("%d%d",&n,&m);
	Inv=quick(2,mo-2);
	for (int i=1;i*i<=n;i++) if (n%i==0)
	{
		p[tot++]=i;
		if (i*i<n) p[tot++]=n/i;
	}
	sort(p,p+tot);
	for (int i=0;i<tot;i++)
	{
		f[i]=quick(m,(p[i]+1)/2);
		for (int j=0;j<i;j++) if (p[i]%p[j]==0) f[i]=(f[i]-f[j])%mo;
		if (f[i]<0) f[i]+=mo;
		if (p[i]&1) ans=(ans+(LL)f[i]*p[i])%mo;
		else ans=(ans+(LL)f[i]*p[i]%mo*Inv)%mo;
	}
	printf("%d\n",ans);
    return 0;
}

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

typedef long long ll;

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

    vector<char> S(N);
    ll w_num = 0;
    ll e_num = 0;
    for(int i=0;i<N;i++){
        cin >> S[i];
        if(S[i]=='W'){
            w_num++;
        }
        else if(S[i]=='E'){
            e_num++;
        }
    }

    ll left_w = 0;
    ll right_e = e_num;
    ll ans = w_num+e_num;
    for(int i=0;i<N;i++){
        ll num = 0;
        if(S[i]=='W'){
            //cout << i << " : " << max(left_w, right_e) << endl;
            ans = min(ans, left_w+right_e);
            left_w++;
        }
        else{
            //cout << i << " : " << max(left_w, right_e-1) << endl;
            ans = min(ans, left_w+right_e-1);
            right_e--;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 512
a = int(input())

if a % 2 == 0:
    # a以下の偶数の数
    even_num = a / 2
    odd_num = a / 2
else:
    even_num = (a - 1) / 2
    odd_num = (a - 1) / 2 + 1

ans = even_num * odd_num
print(int(ans))

Measured memory_bytes: 2940
n = int(input())
l = []
m1 = 0
m2 = 0
for i in range(n):
    num = int(input())
    l.append(num)
    if num > m1:
        m1 = num
    elif num > m2:
        m2 = num

for i in range(n):
    if l[i] != m1:
        print(m1)
    else:
        print(m2)


Measured memory_bytes: 68952
N = int(input())
if N == 0:
    print('0')
    exit()
res = []
for i in range(32):
    digit = (-2) ** i
    if N % (digit * (-2)) != 0:
        N -= digit
        res.append('1')
    else:
        res.append('0')
while res[-1] == '0':
    res.pop()
print(''.join(res[::-1]))

Measured memory_bytes: 3060
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
#include <string>
#include <stack>
#include <map>
#include <set>
#include <bitset>
#define X first
#define Y second
#define clr(u,v); memset(u,v,sizeof(u));
#define in() freopen("data","r",stdin);
#define out() freopen("ans","w",stdout);
#define Clear(Q); while (!Q.empty()) Q.pop();
#define pb push_back
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int maxn = 1e5 + 10;
const int INF = 0x3f3f3f3f;
int Hash[maxn];
int main()
{
    int n, x;
    scanf("%d", &n);
    for (int i = 0; i < n; i++)
    {
        scanf("%d", &x);
        Hash[x]++;
    }
    int Mx = 0;
    for (int i = 2; i < maxn; i++)
    {
        int temp = Hash[i] + Hash[i-1] + Hash[i-2];
        Mx = max(Mx, temp);
    }
    printf("%d\n", Mx);
    return 0;
}


Measured memory_bytes: 640
#include <stdio.h>
#include <string.h>
#include <math.h>
int main()
{
    int n,m,x,i,s[105],sum1=0,sum2=0;
    scanf("%d %d %d",&n,&m,&x);
    for(i=0;i<m;i++)
        scanf("%d",&s[i]);
    for(i=0;i<m;i++)
    {
        if(s[i]>x&&s[i]<n)
            sum1=sum1+1;
        else
            sum2=sum2+1;
    }
    if(sum1>sum2)
        printf("%d\n",sum2);
    else
        printf("%d\n",sum1);
    return 0;
}


Measured memory_bytes: 128
#include <algorithm>            // https://cpprefjp.github.io/reference/algorithm.html
#include <ios>                  // https://cpprefjp.github.io/reference/ios.html
#include <iostream>             // https://cpprefjp.github.io/reference/iostream.html
#include <map>                  // https://cpprefjp.github.io/reference/map.html
#include <set>
#include <string>               // https://cpprefjp.github.io/reference/string/basic_string/find.html
#include <vector>               // https://cpprefjp.github.io/reference/vector/vector.html
#include <utility>              // https://cpprefjp.github.io/reference/utility.html

#include <cmath>                // https://cpprefjp.github.io/reference/cmath.html
#include <cassert>              // https://cpprefjp.github.io/reference/cassert/assert.html

using namespace std;

typedef long long ll;

#define GCD(a, b) __gcd((a), (b))
#define LCM(a, b) ((a) / GCD((a), (b)) * (b))
#define POPCOUNT(x) __builtin_popcount((x))

#ifdef AT_DEBUG
#define dp(s) (cout << s)
#define dpln(s) (cout << s << endl)
#define dpln_col(c) { for (const auto& x : c) dpln(x); }
#else  // AT_DEBUG
#define dp(s)
#define dpln(s)
#define dpln_col(c)
#endif // AT_DEBUG

int main (int argc, char** argv)
{
	int X;

	cin >> X;

	int count500;
	for (count500 = 0; X >= 500; count500++) {
		X -= 500;
	}

	int count5;
	for (count5 = 0; X >= 5; count5++) {
		X -= 5;
	}

	cout << count500 * 1000 + count5 * 5 << endl;
#ifdef AT_DEBUG
#endif  // AT_DEBUG

	return 0;
}

// Dec Hex    Dec Hex    Dec Hex  Dec Hex  Dec Hex  Dec Hex   Dec Hex   Dec Hex
//   0 00 NUL  16 10 DLE  32 20    48 30 0  64 40 @  80 50 P   96 60 `  112 70 p
//   1 01 SOH  17 11 DC1  33 21 !  49 31 1  65 41 A  81 51 Q   97 61 a  113 71 q
//   2 02 STX  18 12 DC2  34 22 "  50 32 2  66 42 B  82 52 R   98 62 b  114 72 r
//   3 03 ETX  19 13 DC3  35 23 #  51 33 3  67 43 C  83 53 S   99 63 c  115 73 s
//   4 04 EOT  20 14 DC4  36 24 $  52 34 4  68 44 D  84 54 T  100 64 d  116 74 t
//   5 05 ENQ  21 15 NAK  37 25 %  53 35 5  69 45 E  85 55 U  101 65 e  117 75 u
//   6 06 ACK  22 16 SYN  38 26 &  54 36 6  70 46 F  86 56 V  102 66 f  118 76 v
//   7 07 BEL  23 17 ETB  39 27 '  55 37 7  71 47 G  87 57 W  103 67 g  119 77 w
//   8 08 BS   24 18 CAN  40 28 (  56 38 8  72 48 H  88 58 X  104 68 h  120 78 x
//   9 09 HT   25 19 EM   41 29 )  57 39 9  73 49 I  89 59 Y  105 69 i  121 79 y
//  10 0A LF   26 1A SUB  42 2A *  58 3A :  74 4A J  90 5A Z  106 6A j  122 7A z
//  11 0B VT   27 1B ESC  43 2B +  59 3B ;  75 4B K  91 5B [  107 6B k  123 7B {
//  12 0C FF   28 1C FS   44 2C ,  60 3C <  76 4C L  92 5C \  108 6C l  124 7C |
//  13 0D CR   29 1D GS   45 2D -  61 3D =  77 4D M  93 5D ]  109 6D m  125 7D }
//  14 0E SO   30 1E RS   46 2E .  62 3E >  78 4E N  94 5E ^  110 6E n  126 7E ~
//  15 0F SI   31 1F US   47 2F /  63 3F ?  79 4F O  95 5F _  111 6F o  127 7F DEL


Measured memory_bytes: 256
#include<stdio.h>
int main(){
  int n,j,i,su;
  char mark;
  scanf("%d",&n);
  int card[4][13]={0};
  for(i=0;i<n;i++){
    scanf(" %c %d",&mark,&su);
    switch  (mark){
    case 'S': card[0][su-1]=1;
      break;
    case 'H': card[1][su-1]=1;
      break;
    case 'C': card[2][su-1]=1;
      break;
    case 'D': card[3][su-1]=1;
      break;
    }
  }
  for(i=0;i<4;i++){
    for(j=0;j<13;j++){
      if(card[i][j]==0){
      if(i==0)printf("S %d\n",j+1);
      if(i==1)printf("H %d\n",j+1);
      if(i==2)printf("C %d\n",j+1);
      if(i==3)printf("D %d\n",j+1);
      }
    }
  }
  return 0;
}

Measured memory_bytes: 596
#include<bits/stdc++.h>
using namespace std;
#define lp(i,n) for(int i=0;i<n;i++)
#define lps(i,j,n) for(int i=j;i<n;i++)
#define fordebug int hoge;cin>>hoge;
#define DEKAI 1000000007;
#define INF (1<<28)
#define int long long
#define double long double
#define floot10 cout<<fixed<<setprecision(10)



signed main(){
  int n;
  cin>>n;
  int ans=0;
  int cnt=0;
  int mini=INF;
  lp(i,n){
    int a;
    cin>>a;
    ans+=a;
    if(a%2==1){
      cnt++;
      mini=min(a,mini);
    }
  }
  if(cnt%2==1)ans-=mini;
  cout<<ans/2<<endl;
  return 0;
}




Measured memory_bytes: 3096
#include<stdio.h>
//#define _CRT_INT_MAX
#define _CRT_INT_MAX 2147483647
int main(){
    int n;
    scanf("%d",&n);
    int h[100001];
    int i;
    for(i=1;i<=n;i++){
        scanf("%d",&h[i]);
    }
    h[n+1] = 2000000000;
    int j = 1;
    int count=0;
    while(1){
        i=0;
        while(1){
            if(h[j+i]>=h[j+i+1]){
               // printf("true\n");
                i++;
            }
            else{
               // printf("false\n");
                if(count<i){
                count = i;
                }
                j = j+i+1;
                break;
            }

        }
        if(j>n){
            break;
        }
    }
    printf("%d\n",count);
    return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n)for(int i=0;i<(n);i++)
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define pb push_back
using ll = long long;
using P = pair<int, int>;
using Graph = vector<vector<int>>;

const int MAX = 1e5+5;
int main(){
    vector<int> isprime(MAX,1);
    isprime[0] = 0;
    isprime[1] = 0;
    for(int i = 2; i < MAX; ++i){
        if(!isprime[i]) continue;
        for(int j = i*2; j < MAX; j+=i){
            isprime[j] = 0;
        }
    }    
    vector<int> a(MAX,0);
    for(int i = 0; i < MAX; ++i){
        if(i % 2 == 0) continue;
        if(isprime[i] && isprime[(i+1)/2]) a[i] = 1;
    }
    vector<int> s(MAX+1,0);
    for(int i = 0; i < MAX; ++i){
        s[i+1] = s[i] + a[i];
    }
    int q; cin >> q;
    rep(i,q){
        int l, r; cin >> l >> r;
        //[l,r)
        r++;
        int ans = s[r] - s[l];
        cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define ll long long
#define INF (1 << 60)

using namespace std;
int main(){
	ll N;
  cin >> N;
  char tmp;
  ll R_counter=0;
  ll W_counter=0;
  vector<char> c(N);
  for(ll i=0;i<N;i++){
  	cin >> tmp;
    c.at(i)=tmp;
    if(tmp=='R'){
      R_counter++;
    }else{
      W_counter++;
    }
  }
  
  ll tmp_counter=0;
  for(ll i=0;i<R_counter;i++){
  	if(c.at(i)=='R')tmp_counter++;
  }
  cout << R_counter-tmp_counter << endl;
}

Measured memory_bytes: 3596
#include<bits/stdc++.h>
using namespace std;
#define hackcyborg shresth_walia
#define ll long long int
#define ld long double
#define pb push_back
#define p1 1232
#define mod 998244353
#define IO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
long long binpow(long long a, long long b, long long m=mod) {
    a %= m;
    long long res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a % m;
        a = a * a % m;
        b >>= 1;
    }
    return res;
}
int main()
{
   IO
   ll n,s;
   cin>>n>>s;
   ll dp[n+1][s+1];
   memset(dp,0,sizeof(dp));
   ll a[n];
   for(int x=0;x<n;x++)
    cin>>a[x];
    dp[0][0]=1;
    ll g=binpow(2,mod-2);
   for(int x=1;x<=n;x++)
    for(int y=0;y<=s;y++)
   {    if(y>=a[x-1])
       dp[x][y]+=(dp[x-1][y-a[x-1]])*g;
       dp[x][y]%=mod;
       dp[x][y]+=dp[x-1][y];
       dp[x][y]%=mod;
   }
   cout<<(dp[n][s]*binpow(2,n))%mod;
}


Measured memory_bytes: 73924
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int N=2e5+5;
struct P {
    int a,b;
    bool operator <(const P &t) const {
        return 1LL*a*(t.b+1)>1LL*t.a*(b+1);
    }
}p[N];
ll pre[N];
int n,t,cnt=0,tot=0;
int cal() {
    ll f[35];
    for(int i=0;i<35;i++) f[i]=(i?1e9:0);
    for(int i=0;i<cnt;i++) {
        for(int j=30;j>=0;j--) {
            if(f[j]==1e9) continue;
            f[j+1]=min(f[j+1],(f[j]+1)*(p[i].a+1)+p[i].b);
            if(f[j+1]>t) f[j+1]=1e9;
        }
    }
    int ans=0;
    for(int i=0;i<32;i++) {
        if(f[i]!=1e9) {
            int x=t-f[i];
            int y = upper_bound(pre,pre+tot+1,x) - pre - 1;
            ans=max(ans,i+y);
        }
    }
    return ans;
}
int main() {
    //freopen("in.txt","r",stdin);
    scanf("%d%d",&n,&t);
    for(int i=0,a,b;i<n;i++) {
        scanf("%d%d",&a,&b);
        if(a==0) pre[++tot]=b;
        else p[cnt++]={a,b};
    }
    sort(p,p+cnt),sort(pre+1,pre+tot+1);
    for(int i=1;i<=tot;i++) pre[i]=pre[i]+1+pre[i-1];
    printf("%d\n",cal());
    return 0;
}


Measured memory_bytes: 1792
#include<stdio.h>
#include<string.h>
#define maxn 60
#define N 1010
char map[maxn][maxn];
long long nt,ti;
bool use[maxn][maxn];
int n,m,q;
struct task
{
    int r,c;
}s[N];
struct visit
{
    int cnt;
    long long int ti[N];
}vis[maxn][maxn];
struct mat
{
    long long int keep;
    long long int on;
    long long int off;
}cost[maxn][maxn];
int dr[4]={-1,1,0,0};
int dc[4]={0,0,-1,1};
long long min(long long a,long long b)
{
    return a>b?b:a;
}
long long int get()
{
    char ch;
    while (ch=getchar(),ch<'0'||ch>'9');
    long long sum=ch-'0';
    while (ch=getchar(),ch>='0'&&ch<='9')
        sum=sum*10+ch-'0';
    return sum;
}
int get2()
{
    char ch;
    while (ch=getchar(),ch<'0'||ch>'9');
    int sum=ch-'0';
    while (ch=getchar(),ch>='0'&&ch<='9')
        sum=sum*10+ch-'0';
    return sum;
}
void readin()
{
    for (int i=1;i<=n;i++)
        scanf("%s",map[i]+1);
    //for (int i=1;i<=n;i++)
    //    printf("%s\n",map[i]+1);
    for (int i=1;i<=n;i++)
        for (int j=1;j<=m;j++)
            cost[i][j].keep=get();
    for (int i=1;i<=n;i++)
        for (int j=1;j<=m;j++)
            cost[i][j].on=get();
    for (int i=1;i<=n;i++)
        for (int j=1;j<=m;j++)
            cost[i][j].off=get();
   /* for (int i=1;i<=n;i++)
        for (int j=1;j<=m;j++)
            printf("%I64d %I64d %I64d\n",cost[i][j].keep,cost[i][j].on,cost[i][j].off);*/
    for (int i=1;i<=q;i++)
        s[i].r=get2(),s[i].c=get2(),s[i].r++,s[i].c++;
}
bool ok(int r,int c)
{
    if (r<1||r>n||c<1||c>m)return false;
    if (map[r][c]=='#')return false;
    return use[r][c];
}
bool dfs (int r,int c,task end,long long  tim)
{
    if (r==end.r&&c==end.c)
    {
        nt=tim;
        return true;
    }
    use[r][c]=0;
    vis[r][c].ti[++vis[r][c].cnt]=tim;
    for (int i=0;i<=4;i++)
    {
        int nr=r+dr[i];
        int nc=c+dc[i];
        if (ok(nr,nc))
        {
            if (dfs(r+dr[i],c+dc[i],end,tim+1))return true;
        }
    }
    use[r][c]=1;
    vis[r][c].cnt--;
    return false;
}
void work()
{
    nt=0ll;
    for (int i=1;i<=n;i++)
        for (int j=1;j<=m;j++)
            vis[i][j].cnt=0;
    for (int i=1;i<q;i++)
    {
        memset(use,1,sizeof use);
        dfs(s[i].r,s[i].c,s[i+1],nt);
    }
    vis[s[q].r][s[q].c].ti[++vis[s[q].r][s[q].c].cnt]=nt;
    long long ans=0;
    for (int i=1;i<=n;i++)
    {
        for (int j=1;j<=m;j++)
        {
            long long sum=0;
            //printf("cnt=%d : ",vis[i][j].cnt);
            for (int k=1;k<vis[i][j].cnt;k++)
            {
                sum+=min(cost[i][j].on+cost[i][j].off,cost[i][j].keep*(vis[i][j].ti[k+1]-vis[i][j].ti[k]));
                //printf("%lld ",vis[i][j].ti[k]);
                //printf("\n");
            }
            if (vis[i][j].cnt)sum+=cost[i][j].off+cost[i][j].on;
            ans+=sum;
        }
    }
    printf("%lld\n",ans);
}
int main()
{
    while (scanf("%d %d %d",&n,&m,&q)!=EOF)
    {
        readin();
        work();
    }
    return 0;
}
/*
3 3 5
***
*##
**#
1 1 1
1 1 1
1 1 1
1 1 1
1 1 1
1 1 1
1 1 1
1 1 1
1 1 1
1 0
2 1
0 2
2 0
0 0
*/

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

int main()
{
    int n;
    cin>>n;
    int arr[n];
    for(int i=0;i<n;i++)
    cin>>arr[i];
    long long int sum=0;
    for(int i=1;i<n;i++)
    {
        int diff=arr[i]-arr[i-1];
        if(diff<0){
            sum+=abs(diff);
            arr[i]=arr[i-1];
        }
    }
    cout<<sum;
}

Measured memory_bytes: 4340
#coding utf-8
L,R=map(int,input().split())

tmp=99999999999999
if R-L>=2019:
  tmp=0
else:
  for i in range(L%2019,L%2019+R-L):
    for j in range(i+1,L%2019+R-L+1):
      if i==0 or j==0:
        tmp=0
      else:
        if (i*j)%2019<tmp:
          tmp=(i*j)%2019
        
print(tmp)

Measured memory_bytes: 3060
#include <stdio.h>
int main(void){
    int n,a[9]={0},i,t;
    scanf("%d",&n);
    for(i=0;i<n;i++){
        scanf("%d",&t);
        a[t>=3200?8:t/400]++;
    }
    for(t=i=0;i<8;i++){
        t+=!!a[i];
    }
    printf("%d %d", t==0?1:t, a[8]+t);
}


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

int main(){
	
	int n,sum=0;
	
	for( int i=0 ; i<5 ; i++ ){
		cin >> n ;
		if( n < 40 ) n = 40 ;
		sum+=n;
	}
	
	cout << sum/5 << endl ;
	
return 0;
}

Measured memory_bytes: 1160
#include <iostream>
#include <string>
#include <algorithm>
#include <utility>
#include <iomanip>
#include <functional>
#include <queue>
#include <stack>
#include <map>
#include <vector>
#include <cmath>
#include <cctype>
#include <cstdio>
#define ll long long
#define INF 1e+7
#define MOD 1000000007
using namespace std;



int main(){
    int ans=0;
    int m=1000000;
    int N;
        cin>>N;
    int sum=0;
    int a[N];
    for(int i=0; i<N; i++){
        cin >> a[i];
        sum += a[i];
    }
    
    for(int i=0; i<N; i++){
        if(abs(sum-a[i]*N)<m){
            m=abs(sum-a[i]*N);
            ans=i;
        }
    }
    cout << ans << endl;
    
    return 0;
}


Measured memory_bytes: 256
#print#!/usr/bin/env python3
#%% for atcoder uniittest use
import sys
input= lambda: sys.stdin.readline().rstrip()
sys.setrecursionlimit(10**9)
def pin(type=int):return map(type,input().split())
def tupin(t=int):return tuple(pin(t))
def lispin(t=int):return list(pin(t))
#%%code
from fractions import gcd
def resolve():
    N,=pin()
    a=dict()
    for i in range(N):
        t=input()
        a.setdefault(t,0)
        a[t]+=1
    M,=pin()
    for j in range(M):
        s=input()
        a.setdefault(s,0)
        a[s]-=1
    t=(max(a.values()))          
    print(max(0,t))  
#%%submit!
resolve()

Measured memory_bytes: 66284
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
const ll mod=1e9+7,INF=mod*mod*3;//M_PI
#define rep(i,N) for(ll i=0; i<(N); i++)
#define rep1(i,N) for(ll i=1; i<(N); i++)
#define pb push_back

long double A,B;

int main(){

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

cin>>A>>B;
long double C=A*B;
ll ans=floor(C);
cout<<ans<<endl;


}
    


Measured memory_bytes: 3736
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i, n) for(ll i=0; i<n; i++)
#define repr(i, s, e) for(ll i=s; i>=e; i--)
#define reps(i, s, e) for(ll i=s; i<=e; i++)
#define inf 1e18
#define all(v) v.begin(),v.end()
#define ceil(a, b) (a+b-1)/b
#define ok cout << "ok" << endl;
#define sp << " " <<
template<typename T> inline bool chmax(T &a, T b){ if(a<b) a=b; return a<b; }
template<typename T> inline bool chmin(T &a, T b){ if(b<a) a=b; return b<a; }
template<typename T> void vdeb(T v){
    cout << "#vector set debug" << endl;
    for(auto vv : v) cout << vv << " ";
    cout << endl;
}
template<typename T1, typename T2> void adeb(T1 arr[], T2 n){
    cout << "#adebug" << endl;
    for(int i=0; i<=n; i++) cout << arr[i] << " ";
    cout << endl;
}
template<typename T1> void mdeb(T1 mp){
    cout << "#map pair debug" << endl;
    for(auto const& m : mp) cout << m.first sp m.second << endl;
}
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){ fill((T*)array, (T*)(array+N), val); }
void ans(bool b){ cout << (b ? "Yes" : "No") << endl; }
void ans2(bool b){ cout << (b ? "YES" : "NO") << endl; }
int dx[] = {1, 0, -1, 0, 1, -1, 1, -1};
int dy[] = {0, 1, 0, -1, 1, -1, -1, 1};


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

    ll n;
    cin >> n;

    vector<int> bank;
    bank.push_back(1);
    ll buf = 6;
    while(buf < 100000){
        bank.push_back(buf);
        buf *= 6;
    }
    buf = 9;
    while(buf < 100000){
        bank.push_back(buf);
        buf *= 9;
    }

    int dp[100010];
    Fill(dp, 1000000);
    dp[0] = 0;
    reps(i, 1, n){
        for(auto const& e : bank){
            if(i - e < 0) continue;
            dp[i] = min(dp[i], dp[i - e] + 1);
        }
    }

    //adeb(dp, n);

    cout << dp[n] << endl;

    return 0;
}


Measured memory_bytes: 640
#pragma region RegionDefs
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0,i##_len=(n);i<i##_len;++i)
#define reps(i,l,r) for(int i=(l),i##_len=(r);i<i##_len;++i)
#define repr(i,n) for(int i=(n);i>=0;--i)
#define all(x) begin(x),end(x)
using namespace std;
const int INF = 1e9;
template<class T=int> using P  = pair<T, T>;
template<class T=int> using V  = vector<T>;
template<class T=int> using PQ = priority_queue<T>;
template<class T=int> using PQG = priority_queue<T, V<T>, greater<T>>;
typedef long long ll;
const ll MOD = 10e9+7LL;
void in() {}
template<class Head, class... Tail>
void in(Head&& head, Tail&&... tail)
{
    cin >> head;
    in(move(tail)...);
}
#define IN(...) ll __VA_ARGS__; in(__VA_ARGS__)
//時間が厳しいとき使う
#define INI(...) int __VA_ARGS__; in(__VA_ARGS__)
#define INS(T, ...) T __VA_ARGS__; in(__VA_ARGS__)
#define VIN(T, v, n) V<T> v(n); for(auto& _elem:v)cin>>_elem
template<class T>bool chmax(T &a, const T &b) {if (a<b) {a=b; return 1;} return 0;}
template<class T>bool chmin(T &a, const T &b) {if (a>b) {a=b; return 1;} return 0;}
#define y0 y__0
#define y1 y__1
#define j0 j__0
#define j1 j__1
#define YN(e) cout << ((e) ? "YES" : "NO") << endl
#define yn(e) cout << ((e) ? "Yes" : "No") << endl
#pragma endregion RegionDefs

ll a[1005][12];
ll s[1005][12];

ll cc(ll x, ll y, ll x2, ll y2)
{
    return s[x2][y2] - s[x][y2] - s[x2][y] + s[x][y];
}

void solve()
{
    IN(h, w, k);
    rep(y, h)
    {
        rep(x, w)
        {
            char c; cin >> c;
            a[x][y] = c - '0';
            s[x+1][y+1] = a[x][y];
        }
    }
    rep(y, h+1)
    {
        reps(x, 1, w+1)
        {
            s[x][y] += s[x-1][y];
        }
    }
    reps(y, 1, h+1)
    {
        rep(x, w+1)
        {
            s[x][y] += s[x][y-1];
        }
    }
    ll m = h * w;
    for (int bit = 0; bit < (1<<(h-1)); ++bit) {
        vector<int> S;
        S.push_back(0);
        for (int i = 0; i < h-1; ++i) {
            if (bit & (1<<i)) {
                S.push_back(i+1);
            }
        }
        S.push_back(h);
        ll u = 0;
        ll l = 0, r = 0;
        ll a = 0;
        while (true)
        {
            while (r < w)
            {
                for (int i = 0; i < (int)S.size() - 1; ++i)
                {
                    if (cc(l, S[i], r+1, S[i+1]) > k)
                    {
                        goto end;
                    }
                }
                ++r;
            }
            end:;
            if (r == w) break;
            if (l == r) break;
            l = r;
            ++a;
        }
        if (r == w)
        {
            chmin(m, a + (ll)S.size()-2);
        }
    }
    cout << m << endl;
}

int main()
{
    cin.tie(0); cout.tie(0);
    ios::sync_with_stdio(false);
    cout << setprecision(numeric_limits<double>::max_digits10);

    solve();

    return 0;
}

Measured memory_bytes: 512
/*
これを入れて実行
g++ code.cpp
./a.out
 */
 
#include <iostream>
#include <stdio.h>
#include <vector>
#include <string>
#include <cstring>
#include <queue>
#include <deque>
#include <algorithm>
#include <utility>
#include <set>
#include <map>
#include <unordered_map>
#include <cmath>
#include <math.h>
#include <tuple>
#include <iomanip>
#include <bitset>
#include <functional>

#define all(x) (x).begin(),(x).end()
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
 
using namespace std;
typedef long long ll;
typedef long double ld;
 
int dy4[4] = {-1, 0, +1, 0};
int dx4[4] = {0, +1, 0, -1};
int dy8[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
int dx8[8] = {0, 1, 1, 1, 0, -1, -1, -1};
 
const long long INF = 1LL << 62;
const ll MOD = 1e9 + 7;
 
bool greaterSecond(const pair<int, int>& f, const pair<int, int>& s){
    return f.second > s.second;
}
 
ll gcd(ll a, ll b){
	if (b == 0)return a;
	return gcd(b, a % b);
}
 
ll lcm(ll a, ll b){
    return a / gcd(a, b) * b;
}

ll conbinationMemo[100][100];

ll cmemoInit(){
    rep(i, 100){
        rep(j, 100){
            conbinationMemo[i][j] = -1;
        }
    }
}
 
ll nCr(ll n, ll r){
    if(conbinationMemo[n][r] != -1) return conbinationMemo[n][r];
    if(r == 0 || r == n){
        return 1;
    } else if(r == 1){
        return n;
    }
    return conbinationMemo[n][r] = (nCr(n - 1, r) + nCr(n - 1, r - 1));
}
 
ll nPr(ll n, ll r){
    r = n - r;
    ll ret = 1;
    for (ll i = n; i >= r + 1; i--) ret *= i;
    return ret;
}
 
//-----------------------ここから-----------
int main(void){
    ll n;
    cin >> n;
    ll ans = 0;
    for(ll i = 1; i <= n; i++){
        if(i % 3 != 0 && i % 5 != 0){
            ans += i;
        }
    }
    cout << ans << endl;
}

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

#define fast_io ios_base::sync_with_stdio(false) ; cin.tie(0); cout.tie(0);
# define M_PIl          3.141592653589793238462643383279502884L


int main() {
    fast_io;
    long double a,b,h,m;
    cin>>a>>b>>h>>m;
    cout<<fixed<<setprecision(20);

    //double long rad = (abs((h*30)-(m*6)))*(M_PIl/180);
    long double lhand = h*30+m*0.5;
    long double shand = m*6;
    long double rad = abs(lhand-shand);
    rad=rad/180*M_PIl;

    long double ans = sqrt(a*a+b*b-2*a*b*cos(rad));
    cout<<ans<<endl;
}




Measured memory_bytes: 4148
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int a = scan.nextInt();
		int b = scan.nextInt();
		int c = scan.nextInt();
		int d = scan.nextInt();
		scan.close();
		if(a+b>c+d)System.out.println("Left");
		else if(a+b<c+d)System.out.println("Right");
		else System.out.println("Balanced");

	}

}

Measured memory_bytes: 21844
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define All(a) a.begin(),a.end()
#define INF 1000000007
const int MOD = 1000000007;
//accumulate(vec.begin(), vec.end(), 0)

int gcd(int x,int y){
  if(x%y==0) return y;
  else return gcd(y,x%y);
}

bool isPrime(int n){
  if(n < 2) return false;
  else if(n == 2) return true;
  else if(n%2==0) return false;

  for(int i=3;i<=sqrt(n);i++){
    if(n%i==0) return false;
  }
  return true;
}

int main(){
  int x;
  cin >> x;
  while(!isPrime(x)){
     x++;
   }
  cout<< x <<endl;
}


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

int main(){
    int A, B;
    cin >> A >> B;
    if (A > 8 || B > 8)
        cout << ":(" << endl;
    else
        cout << "Yay!" << endl;
    return 0;
}

Measured memory_bytes: 256