akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
//---------------------------------------------------------------------------------------------------
typedef long long ll;
ll maxRectangleInHistogram(vector<int> &v) {
    int n = v.size();
    stack<int> s;
    vector<int> L(n), R(n);
    rep(i, 0, n) {
        while (s.size() && v[s.top()] >= v[i]) s.pop();
        L[i] = s.size() ? (s.top() + 1) : 0;
        s.push(i);
    }
    while (s.size()) s.pop();
    rrep(i, n - 1, 0) {
        while (s.size() > 0 && v[s.top()] >= v[i]) s.pop();
        R[i] = s.size() ? s.top() : n;
        s.push(i);
    }
    ll res = 0;
    rep(i, 0, n) res = max(res, 1LL * v[i] * (R[i] - L[i]));
    return res;
}
ll maxRectangle(vector<vector<int>> &v) { // 0:can't use, 1:can use
    int h = v.size();
    int w = v[0].size();

    ll res = 0;
    vector<int> vv(w, 0);
    rep(y, 0, h) {
        rep(x, 0, w) {
            if (v[y][x]) vv[x]++;
            else vv[x] = 0;
        }
        res = max(res, maxRectangleInHistogram(vv));
    }
    return res;
}
/*---------------------------------------------------------------------------------------------------
????????????????????????????????? ??§?????§  
??????????????? ??§?????§ ???????´<_??? ?????? Welcome to My Coding Space!
???????????? ??? ?´_???`??????/??? ???i     
?????????????????????????????? ???  |???|     
????????? /?????? /??£??£??£??£/??????|  
??? ???_(__??????/???    ???/ .| .|????????????  
??? ????????????/????????????/??????u??????  
---------------------------------------------------------------------------------------------------*/










int H, W, C[2020][2020];
//---------------------------------------------------------------------------------------------------
void _main() {
    cin >> H >> W;
    rep(y, 0, H) rep(x, 0, W) cin >> C[y][x];

    vector<vector<int>> v(H, vector<int>(W, 0));
    rep(y, 0, H) rep(x, 0, W) v[y][x] = 1 - C[y][x];
    cout << maxRectangle(v) << endl;
}

Measured memory_bytes: 21624
#include<bits/stdc++.h>
using namespace std;
int main(){
 	string S;
  	cin >> S;
  	int ans = 10000;
  	for(int i=0; i < S.size(); ++i){
     	string sub;
      	sub = S.substr(i, 3);
      	int num = stoi(sub);
      	if(ans > abs(753-num)){
         	ans =  abs(753-num);
        }
    }
  	cout << ans << endl;
  
}


Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<map>
using namespace std;
const int N=2e5+5;
int f1[N],f2[N];
int find1(int x){
    if(f1[x]==x)
        return x;
    return f1[x]=find1(f1[x]);
}
int find2(int x){
    if(f2[x]==x)
        return x;
    return f2[x]=find2(f2[x]);
}
map<pair<int,int>,int>p;
int main()
{
    int n,k,l;
    scanf("%d%d%d",&n,&k,&l);
    for(int i=1;i<=n;i++)
        f1[i]=f2[i]=i;
    for(int i=1;i<=k;i++){
        int u,v;
        scanf("%d%d",&u,&v);
        int a=find1(u),b=find1(v);
        f1[a]=b;
    }
    for(int i=1;i<=l;i++){
        int u,v;
        scanf("%d%d",&u,&v);
        int a=find2(u),b=find2(v);
        f2[a]=b;
    }
    for(int i=1;i<=n;i++)
        p[make_pair(find1(i),find2(i))]++;
    for(int i=1;i<=n;i++)
        printf("%d ",p[make_pair(f1[i],f2[i])]);
}


Measured memory_bytes: 13568
#include<stdio.h>
int main(){
    int n,i,A[101][101],B[100],C[100],D[100],j,k,t,s,math;
    scanf("%d",&n);
    for(i=0;i<n;i++){
        scanf("%d%d",&B[i],&C[i]);
    }
    D[0]=B[0];
    for(i=1;i<=n;i++){
        D[i]=C[i-1];
    }
    n=n+1;
    for(i=0;i<n;i++){
        A[i][i]=0;
    }
    for(j=2;j<n;j++){
        for(i=1;i<=n-j+1;i++){
            t=i+j-1;
            A[i][t]=10000000;
            for(s=i;s<=t-1;s++){
                math=A[i][s]+A[s+1][t]+D[i-1]*D[s]*D[t];
                if(A[i][t]>math)A[i][t]=math;
            }
        }
    }
    printf("%d\n",A[1][n-1]);
    return 0;
}


Measured memory_bytes: 2052
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define int long long
#define endl '\n'
#define pb push_back
#define fi first
#define se second
#define all(c) (c).begin(),(c).end()
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef vector<int> vi;

template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define TRACE
#ifndef ONLINE_JUDGE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
	cerr << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
	const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif

const ll inf = 1e18;
const int mod = 1e9 + 7;
const int N = 2e5 + 10;

signed main() {
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);

	int n;
	cin >> n;
	int ans = 1;
	bool ok = 1;
	for(int i = 0; i < n; i++) {
		int x;
		cin >> x;
		if(x == 0) {
			cout << 0;
			return 0;
		}
		if(ans > (inf / x)) {
			ok = 0;
		}
		ans *= x;
	}
	if(!ok) {
		cout << -1;
	}
	else {
		cout << ans;
	}

	return 0;
}

Measured memory_bytes: 3652
#include<bits/stdc++.h>
    using namespace std;
    bool isprime(int n)
    {
        for(int i=2;i<n;i++)
        {
            if(n%i == 0)
            return false;
        }
        return true;
    }
    int main()
    {
      int x;
      cin>>x;
      while(!isprime(x))
      {
          x++;
      }
      cout<<x;
      return 0;
    }

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define watch(x) cout << (#x) << " is " << (x) << endl
typedef long long ll;
using namespace std;
int static fast = [](){
  ios::sync_with_stdio(false);
  cin.tie(0); cout.tie(0); return 0;
}();
// freopen("input.txt", "r", stdin);

int main() {
    string s;
    cin >> s;
    string sym = "-+";
    for(int state = 0; state < 8; state++) {
        int target = 7 - (s[0]-'0');
        int acc = 0;
        for(int d = 0; d < 3; d++) {
            if ((state >> d) & 1) {
                acc += (s[d+1]-'0');
            } else {
                acc -= (s[d+1]-'0');
            }
        }
        if (acc == target) {
            cout << s[0];
            for(int d = 0; d < 3; d++) {
                cout << sym[(state >> d) & 1] << s[d+1];
            }
            cout << "=7" << endl;
            break;
        }

    }
    return 0;
}




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

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
const ull mod = 1e9 + 7;
#define REP(i,n) for(int i=0;i<(int)n;++i)

int main(){
    int A, B;
    cin >> A >> B;
    cout << (((A*B)%2==0) ? "No" : "Yes") << endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
#include <queue>
using namespace std;

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n;
	while (cin >> n) {
		int MIN = 1000, MAX = -1000;
		int in[200];
		for (int i = 0; i < n; ++i) {
			cin >> in[i];
			MIN = MIN < in[i] ? MIN : in[i];
			MAX = MAX > in[i] ? MAX : in[i];
		}
		long long  ans = 1e9;
		//cout << ans << endl;
		for (int i = MIN; i <= MAX; ++i) {
			long long sum = 0;
			for (int j = 0; j < n; ++j) {
				sum += (in[j] - i) * (in[j] - i);
			}
			ans = ans < sum ? ans : sum;
		}
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 256
L = sorted(list(map(int,input().split())))
a = L[2] - L[0]
b = L[2] - L[1]
if a%2 == 0 and b%2 == 0:
    ans = (a + b)/2
elif a%2 == 1 and b%2 == 1:
    ans = (a + b)/2
else:
    ans = (a + b + 1)/2 + 1
print(int(ans))

Measured memory_bytes: 3064
import bisect
N = int(input())
L_s = list(map(int,input().split()))
L_s.sort()
answer = 0
for i in range(len(L_s)-2):
    for j in range(i+1,len(L_s)-1):
        l = bisect.bisect_left(L_s,L_s[i]+L_s[j])
        answer += l-j-1
print(answer)

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

int main()
{
	int n, m;
  	cin >> n >> m;
	int a = (n * (n - 1)) / 2;
	int b = (m * (m - 1)) / 2;
	cout << a + b << endl;
	
	return 0;
}

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

#define fi first
#define se second
#define pb push_back

using namespace std;

typedef long long ll;

const int MAX = 1e6;
vector <ll> a;

ll dew(ll b) {
    ll s = 0;
    for (int i = 0; i < (int) a.size(); i++) {
        s += abs(a[i] - (b + i + 1));
    }
    return s;
}

void solve() {
    int n;
    cin >> n;
    a.resize(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    ll low = -1e14, high = 1e14, at = -1;
    while (low <= high) {
        ll mid = (low + high) >> 1;
        ll se = dew(mid), fe = dew(mid - 1), te = dew(mid + 1);
        if (fe >= se && se <= te) {
            at = se;
            break;
        }
        if (fe <= se && se <= te) {
            high = mid - 1;
        } else {
            low = mid + 1;
        }
    }
    cout << at;
}

int main() {
	ios::sync_with_stdio(false);
	int t = 1;
	while (t--) {
	    solve();
	}
	return 0;
}


Measured memory_bytes: 1792
#include "bits/stdc++.h"

#define REP(i, n, N) for(ll i=(n); i<(N); i++)
#define RREP(i, n, N) for(ll i=(N-1); i>=n; i--)
#define CK(n, a, b) ((a)<=(n)&&(n)<(b))
#define ALL(v) (v).begin(),(v).end()
#define MCP(a, b) memcpy(b,a,sizeof(b))
#define p(s) cout<<(s)<<endl
#define p2(a, b) cout<<(a)<<" "<<(b)<<endl
#define v2(T) vector<vector<T>>
typedef long long ll;
using namespace std;
const ll mod = 1e9 + 7;
const ll inf = 1e18;

string s;
ll ans=0;
int main() {
	cin>>s;
	REP(l,0,s.size()){
		REP(r,l,s.size()+1) {
			bool ok=true;
			REP(i,l,r){
				if(!(s[i]=='A'||s[i]=='T'||
					s[i]=='G'||s[i]=='C')){
					ok=false;
					break;
				}
			}
			if(ok){
				ans=max(ans, r-l);
			}
		}
	}
	p(ans);
	return 0;
}


Measured memory_bytes: 256
words = lambda t : list(map(t, input().split()))
m,d = words(int)

def is_mday(m,d1,d10):
    if d1 >= 2 and d10 >= 2 and m == d1 * d10:
        return True
    else:
        return False

ans = 0
for m0 in range(1,m+1):
    for d0 in range(1,d+1):
        d1 = d0 % 10
        d10 = d0 // 10
        if is_mday(m0,d1,d10):
            ans += 1

print(ans)


Measured memory_bytes: 40176
#include <cstdio>
#include <algorithm>
#include <iostream>
#include <vector>
#include <string>
#include <math.h>
#include <time.h>
#include <stdlib.h>
using namespace std;

int main(){
	int joi,ioi;
	char str[10000];
	while(scanf("%s",str) != EOF){
		joi=0;
		ioi=0;
		for(int i=0;str[i+2]!='\0';i++){
			if(str[i+1]=='O'&&str[i+2]=='I'){
				if(str[i]=='J') joi++;
				if(str[i]=='I') ioi++;
			}
		}
		printf("%d\n%d\n",joi,ioi);
	}
	return 0;
}


Measured memory_bytes: 3180
#include <stdio.h>
#include<bits/stdc++.h>
#define ll long long
#define fr first
#define sc second
#define ii pair < int , int >
#define mp make_pair
using namespace std;
int n;
string  a[2];
int memo[60][5][5];
int mod = 1e9+7;
int solve(int i,int last1 , int last2)
{
    if(i == n)
    {
        return 1;
    }
    int &ret = memo[i][last1][last2];
    if(ret != -1)
        return ret;
    ret = 0;
    if(a[0][i] == a[1][i])
    {
        for(int j=1;j<=3;j++)
        {
            if(j!=last1 && j!=last2)
            {
                ret+=solve(i+1,j,j);
                ret%=mod;
            }
        }
    }
    else
    {
        for(int j=1;j<=3;j++)
        {
            for(int k=1;k<=3;k++)
            {
                if(j!=last1 && k!=last2 && j!=k)
                {
                    ret+=solve(i+2,j,k);
                    ret%=mod;
                }
            }

        }
    }
    return ret;
}
int main()
{
    memset(memo,-1,sizeof(memo));
cin>>n;
cin>>a[0]>>a[1];
cout<<solve(0,0,0);
}


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

using namespace std;

int main(void)
{
	string s;
	cin >> s;

	for(int i=s.size()-2;i>0;i=i-2)
	{
		if(s.substr(0,i/2)==s.substr(i/2,i/2))
		{
			cout << i << endl;
			return 0;
		}
	}

}

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

int main(){
  int n; cin>>n;
  vector<double> a(n);
  for (int i=0;i<n;++i)cin>>a[i];
  
  double all_pro = 1;
  for (int i=0;i<n;++i)all_pro *= a[i];
  
  double mot=0;
  for(int i=0;i<n;++i)mot+=all_pro/a[i];
  
  double ans=(double)all_pro/(double)mot;
  cout<<setprecision(15)<<ans<<endl;
  
  return 0;
}


Measured memory_bytes: 256
import bisect
import os
from collections import Counter, deque
from fractions import gcd
from functools import lru_cache
from functools import reduce
import functools
import heapq
import itertools
import math
import numpy as np
import re
import sys
import string

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(2147483647)
INF = float("inf")

# S = sys.stdin.readline().rstrip()
# i = 2
# while len(S) - i > 0:
#     l = len(S) - i
#     if S[:l // 2] == S[l // 2:l]:
#         print(l)
#         break
#     i += 2

#
# N = int(sys.stdin.readline())
# A = [int(sys.stdin.readline()) for _ in range(N)]
#
# ans = 0
# i = 0
# for _ in range(N+1):
#     i = A[i]-1
#     ans += 1
#     if i == 1:
#         print(ans)
#         exit()
# print(-1)


N = int(sys.stdin.readline())
A = list(map(int, sys.stdin.readline().split()))
print(max(A) - min(A))


Measured memory_bytes: 13648
#include<bits/stdc++.h>
using namespace std;
char n;
int a,b;
int main()
{
    cin>>a>>b;
    for(int s=0;s<a;s++)
    {
        cin>>n;
        if(n<'0'||n>'9')
        {
            cout<<"No"<<endl;
            return 0;
        }
    }
    cin>>n;
    if(n!='-')
    {
        cout<<"No"<<endl;
        return 0;
    }
    for(int s=0;s<b;s++)
    {
        cin>>n;
        if(n<'0'||n>'9')
        {
            cout<<"No"<<endl;
            return 0;
        }
    }
    cout<<"Yes"<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
int n,a,b,c;
int l[9];
bool f[9];
int main(){
	cin>>n>>a>>b>>c;
	rep(i,n)cin>>l[i];
	rep(i,n)f[i]=1;
	int ans=1145141919;
	rep(i,(1<<n)){
		rep(j,(1<<n)){
			int cnt=0;
			int K=n;
			int A=0,B=0,C=0;
			bool fa=0,fb=0,fc=0;
			rep(k,n){
				if((i>>k)&1){
					if((j>>k)&1){//A
						A+=l[k];
						fa=1;
					}
					else{//B
						B+=l[k];
						fb=1;
					}
				}
				else{
					if((j>>k)&1){//C
						C+=l[k];
						fc=1;
					}
					else{//Don't use
						K--;
					}
				}
			}
			if(fa&&fb&&fc);
			else continue;
			cnt=abs(a-A)+abs(b-B)+abs(c-C);
			ans=min(ans,cnt+(K-3)*10);
		}
	}
	cout<<ans<<endl;
	return 0;
}


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

int N, a[100005];

int sum(int i, int *bit)
{
    //printf("sum i:%lld\n", i);
    int s = 0;
    while(i > 0){
        //printf("sum::s += bit[%lld] %lld = %lld + %lld\n", i, s + bit[i], s, bit[i]);
        s += bit[i];
        i -= (i & (-i));
    }
    return s;
}

void add(int i, int x, int *bit)
{
    //printf("add i:%lld x:%lld\n", i, x);
    while(i <= N * 2 + 1){
        bit[i] += x;
        //printf("add::bit[%lld] = %lld\n", i, bit[i]);
        i += (i & (-i));
    }
}

bool C(int x)
{
    int bit[200010] = {0};
    int s[N + 1] = {0};
    int res = 0;
    for(int i = 0; i < N; i++){
        if(a[i] >= x){
            s[i] = 1;
            //res++;
        }
        else s[i] = -1;
        if(i > 0)s[i] += s[i - 1];
    }
    add(N + 1, 1, bit);
    for(int i = 0; i < N; i++){
        res += sum(N + 1 + s[i], bit);
        add(N + 1 + s[i], 1, bit);
    }
    return (res >= (N * (N + 1) / 2 + 1) / 2);
}

int binary(int lb, int ub)
{
    for(int i = 0; i < 64; i++){
        int mid = (ub + lb) / 2;
        //printf("lb:%lld ub:%lld mid:%lld\n", lb, ub, mid);
        if(C(mid))lb = mid;
        else ub = mid;
    }
    return lb;
}

signed main()
{
    cin >> N;
    int mx = 0;
    for(int i = 0; i < N; i++){
        cin >> a[i];
        mx = max(mx, a[i]);
    }
    cout << binary(0, mx + 1) << endl;


    return 0;
}


Measured memory_bytes: 3328
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#include<limits.h>
#define lpton(i,n) for(int i=0;i<(int)n;i++)
#define lpto0(i,n) for(int i=n;i>-1;i--)
#define lpmn(i,m,n) for(i=m;i<n;i++)
#define ms0(l) memset(l,0,sizeof(l))
#define ms(l,n,s) memset(l,n,s)
#define m(x,n) (x*)malloc(n*sizeof(x))
typedef struct tree{
  int nnode;
  int parent;
  int left;
  int right;
}tree;
int dep;
void print(tree*,int);
int sibling(tree*,int);
int degree(tree*,int);
int depth(tree*,int);
int height(tree*,int);
char* typename(tree*,int);
int main(){
  int n,nnode;
  tree *tr;
  scanf("%d",&n);
  tr=m(tree,n);
  ms(tr,-1,n*sizeof(tree));
  lpton(i,n){
    scanf("%d",&nnode);
    (tr+nnode)->nnode=nnode;
    scanf("%d%d",&(tr+nnode)->left,&(tr+nnode)->right);
    (tr+((tr+nnode)->left))->parent=nnode;
    (tr+((tr+nnode)->right))->parent=nnode;
  }
  print(tr,n);
  free(tr);
  return 0;
}
void print(tree *tr,int n){
int sb,dg,dp,hg;
  lpton(i,n){
    dep=0;
    sb=sibling(tr,i);
    dg=degree(tr,i);
    dp=depth(tr,i);
    hg=height(tr,i);
    printf("node %d: parent = %d, sibling = %d, degree = %d, depth = %d, height = %d, %s\n",(tr+i)->nnode,(tr+i)->parent,sb,dg,dp,hg,typename(tr,i));
  }
}
int sibling(tree *tr,int i){
  if((tr+i)->parent==-1)return -1;
  else if((tr+((tr+i)->parent))->left==(tr+i)->nnode)return (tr+((tr+i)->parent))->right;
  else return (tr+((tr+i)->parent))->left;
}
int degree(tree *tr,int i){
  if((tr+i)->right==-1&&(tr+i)->left==-1)return 0;
  else if((tr+i)->right!=-1&&(tr+i)->left!=-1)return 2;
  else return 1;
}
int depth(tree *tr,int i){
  if((tr+i)->parent==-1)return dep;
  depth(tr,(tr+i)->parent);
  return dep+=1;
}
int height(tree *tr,int i){
  int h1=0,h2=0;
  if((tr+i)->left!=-1)h1=(height(tr,(tr+i)->left))+1;
  if((tr+i)->right!=-1)h2=(height(tr,(tr+i)->right))+1;
  return (h1>h2?h1:h2);
}
char *typename(tree *tr,int i){
if((tr+i)->parent==-1)return "root";
else if(degree(tr,i)==0)return "leaf";
else return "internal node";
}



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

int main() {
  int N,x;
  cin>>N;
  x=0;
  for (int i=0;i<N;i++){
    int l,r;
    cin>>l>>r;
    x+=r-l+1;
  }
  cout<<x<<endl;
}



Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <utility>
#include <tuple>
#include <algorithm>
#include <numeric>
#include <cstring>
#include <cmath>
#include <climits>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
const int INF = (1<<30)-1;
const long long LINF = (1LL<<62)-1;
const long double PI = acos(-1.0L);
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  string s;
  cin >> n >> s;
  int ans = 0;
  rep(i, s.size()-2) {
    if (s.substr(i, 3) == "ABC")
      ans++;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
n = gets.to_i

a = gets.chomp.split(" ").map(&:to_i)

min = Float::INFINITY

for i in 0..n-2 do
  sumarr1 = a[0..i]
  sumarr2 = a[i+1..-1]
  sum1 = sumarr1.inject(:+)
  sum2 = sumarr2.inject(:+)
  if (sum2-sum1).abs < min
    min = (sum2 - sum1).abs
  end
end
puts min

Measured memory_bytes: 1788
#include<bits/stdc++.h> 
//#define <- プログラムの文字列を置換する
//typedef <- 新しい型に名前を付けるためのキーワード

using namespace std;

#define MAX_N 1

typedef long long ll;

const double PI = 3.141592653589793;
const long long MOD = 1e9 + 7;
const long long INF = 1e15;


int main(){
    int n,m;
    cin >> n >> m;
    bool check[m];
    memset(check,false,sizeof check);
    for(int i = 0; i < n ;i++){
        int k;
        cin >> k;
        bool temp[m];
        memset(temp,false,sizeof temp);
        for(int j = 0 ; j < k ; j++){
            int a;
            cin >> a;
            a--;
            temp[a] = true;
        }
        for(int l = 0; l < m ; l++){
            if(i == 0) check[l] = temp[l];
            check[l] = check[l] & temp[l];
        }
    }
    int count = 0;
    for(int i = 0; i < m ;i++){
        if(check[i]){
            count++;
        }
    }
    cout << count << endl;
    return 0;
}

Measured memory_bytes: 256
s = input()
n = int(input())

reverse  = False
forward  = ""
backward = ""

for _ in range(n):
  query = input().split()
  if query == ["1"]:
    reverse = not reverse
  else:
    if query[1] == "1":
      if reverse:
        backward += query[2][::-1]
      else:
        forward = query[2] + forward
    else:
      if reverse:
        forward = query[2][::-1] + forward
      else:
        backward += query[2]

if reverse:
  print(backward[::-1] + s[::-1] + forward[::-1])
else:
  print(forward + s + backward)

Measured memory_bytes: 4432
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(n);++i)
#define FORR(it,cont) for(auto it=rbegin(cont);it!=rend(cont);++it)
#define FOR(it,cont) for(auto it=begin(cont);it!=end(cont);++it)
#define ALL(cont) begin(cont), end(cont)
#define LB(b,e,v) lower_bound(b,e,v)
#define UB(b,e,v) upper_bound(b,e,v)
#define AS_MOD(a,b) ((((a) % (b) ) + (b)) % (b))
#define MODDING(a,b) (a) = AS_MOD(a,b)
#define MAXIMIZE(a, b) (a) = max((a),(b))
#define MINIMIZE(a, b) (a) = min((a),(b))

using namespace std;
typedef long long ll;
int N,K;
int main(int argc, char **argv, char **envp) {
  ll answer = 0;
  cin >> N >> K;
  for (int nit = K; nit <= 2 * N; nit += K) {
    if (nit % 2 != 0)continue;
    int a = nit / 2;
    ll sub = (a + N) / K - a / K;
    answer += sub * sub;
  }
  cout << answer << endl;
  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>          // printf(), scanf()
#define MAX_N 500000
 
typedef struct node_tbl
{
    int key;
    int parent;
    int left;
    int right;
} node;
 
const int nil = -1;
node t[MAX_N + 1];
int root;

int ix;
 
int
tree_minimum(int u)
{
    while (t[u].left != nil)
        u = t[u].left;
 
    return u;
}
 
int
find(int u, int k)
{
    while (u != nil && k != t[u].key)
    {
        if (k < t[u].key)
            u = t[u].left;
        else
            u = t[u].right;
    }
 
    return u;
}
 
int
tree_successor(int u)
{
    if (t[u].right != nil)
        return tree_minimum(t[u].right);
 
    int y = t[u].parent;
    while (y != nil && u == t[y].right)
    {
        u = y;
        y = t[y].parent;
    }
 
    return y;
}
 
void
delete(int z)
{
    int y; /* ????????????????±? */
    int x; /* y?????? */
 
    /* ??????????????????????±??????? */
    if (t[z].left == nil || t[z].right == nil)
        y = z;
    else
        y = tree_successor(z);
 
    /* y??????x????±??????? */
    if (t[y].left != nil)
        x = t[y].left;
    else
        x = t[y].right;
 
    if (x != nil)
        t[x].parent = t[y].parent;
 
    if (t[y].parent == nil)
        root = x;
    else
    {
        if (y == t[t[y].parent].left)
            t[t[y].parent].left = x;
        else
            t[t[y].parent].right = x;
    }
 
    if (y != z)
        t[z].key = t[y].key;

}
 
void
insert(int k)
{
    int z;
 
    int y = nil;
    int x = root;

        z = ix++;

 
    t[z].key = k;
    t[z].left = nil;
    t[z].right = nil;
 
    while (x != nil)
    {
        y = x;
        if (t[z].key < t[x].key)
            x = t[x].left;
        else
            x = t[x].right;
    }
 
    t[z].parent = y;
    if (y == nil)
        root = z;
    else
    {
        if (t[z].key < t[y].key)
            t[y].left = z;
        else
            t[y].right = z;
    }
}
 
void
inorder(int u)
{
    if (u == nil)
        return;
 
    inorder(t[u].left);
    printf(" %d", t[u].key);
    inorder(t[u].right);
}
 
void
preorder(int u)
{
    if (u == nil)
        return;
 
    printf(" %d", t[u].key);
    preorder(t[u].left);
    preorder(t[u].right);
}
 
int
main(int argc, char** argv)
{
    char command[8];
    int n;
    int x;
    int i;
 
    root = nil;

    ix = 0;
    scanf("%d", &n);
    for (i = 0; i < n; ++i)
    {
        scanf("%s", command);
        switch (command[0])
        {
        case 'd':
            scanf("%d", &x);
            delete(find(root, x));
            break;
 
        case 'f':
            scanf("%d", &x);
            printf("%s\n", find(root, x) != nil ? "yes" : "no");
            break;
 
        case 'i':
            scanf("%d", &x);
            insert(x);
            break;
 
        case 'p':
        default:
            inorder(root);
            printf("\n");
 
            preorder(root);
            printf("\n");
            break;
        }
    }
 
    return 0;
}


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

#define rep( i, n, m ) for(int i = ( n ); i < ( m ); i++)
#define rep_d( i, n, m ) for(int i = ( n ) - 1; i >= ( m ); i--)
#define sort_asc( X ) sort(( X ).begin(), ( X ).end())
#define sort_desc( X ) sort(( X ).begin(), ( X ).end(), greater <>())
#define endl "\n"

template <class T> bool chmax( T& a, T b );
template <class T> bool chmin( T& a, T b );
int* eratosthenes( int N );
bool bit_search( int pattern, int N );
void initialize( void );

const ll INF = 1LL << 60;
const int k_mod = 1e9 + 7;
template <typename T, typename K> struct P {
	T a; K b;
};
typedef struct {
	vector <int> to;
	int cost;
} edge;

int main( void ){
	// initialize();
	int N;
	cin >> N;
	map<string, bool> mp;
	rep(i,0,N){
		string s;cin >>s;
		mp[s] = true;
	}
	int cnt = 0;
	for(auto m:mp){
		cnt++;
	}
	cout << cnt << endl;
}

template <class T> bool chmax( T& a, T b ) {
	if (a < b){
		a = b; return true;
	}
	return false;
}
template <class T> bool chmin( T& a, T b ) {
	if (a > b){
		a = b; return true;
	}
	return false;
}
int* eratosthenes( int N ){
	int* prime_array = new int[ N + 1 ];
	int lim = N;
	prime_array[ 0 ] = 0;
	prime_array[ 1 ] = 0;
	rep( i, 2, N + 1 ){
		prime_array[ i ] = 1;
	}
	rep( i, 2, lim ){
		if (prime_array[ i ] == 0)
			continue;
		lim = N / i;
		for(int j = i * 2; j < N + 1; j += i){
			prime_array[ j ] = 0;
		}
	}
	return prime_array;
}
bool bit_search( int pattern, int N ){
	int cnt = 0;
	rep( bit, 0, N ){
		if (pattern & ( 1 << bit )){
			cnt++;
		}
	}
	return true;
}
void initialize( void ){
	cout << fixed << setprecision( 10 );
}


Measured memory_bytes: 19232
// tsukasa_diary's programing contest code template
#include <bits/stdc++.h>
using namespace std;
#define TSUKASA_DIARY_S_TEMPLATE
// define
#define for_(i,a,b) for(int i=(a);i<(b);++i)
#define for_rev(i,a,b) for(int i=(a);i>=(b);--i)
#define allof(a) (a).begin(),(a).end()
#define minit(a,b) memset(a,b,sizeof(a))
#define size_of(a) int((a).size())
#define cauto const auto
// typedef
typedef long long lint;
typedef double Double;
typedef pair< int, int > pii;
template< typename T > using Vec = vector< T >;
template< typename T > using Matrix = Vec< Vec< T > >;
template< typename T > using USet = unordered_set< T >;
template< typename T, class C > using MyUSet = unordered_set< T, C >;
template< typename T, typename F > using UMap = unordered_map< T, F >;
template< typename T, typename F, class C > using MyUMap = unordered_map< T, F, C >;
// hash
class PiiHash { public: size_t operator () (const pii& p) const { return (p.first << 16) | p.second; } };
// popcount
inline int POPCNT(int x) { return __builtin_popcount(x); }
inline int POPCNT(lint x) { return __builtin_popcount(x); }
// inf
const int iINF = 1L << 30;
const lint lINF = 1LL << 60;
// eps
const Double EPS = 1e-9;
const Double PI = acos(-1);
// inrange
template< typename T >
inline bool in_range(T v, T mi, T mx) { return mi <= v && v < mx; }
template< typename T >
inline bool in_range(T x, T y, T W, T H) { return in_range(x,0,W) && in_range(y,0,H); }
// neighbor clockwise
const int DX[4] = {0,1,0,-1}, DY[4] = {-1,0,1,0};
const int DX_[8] = {0,1,1,1,0,-1,-1,-1}, DY_[8] = {-1,-1,0,1,1,1,0,-1};
// variable update
template< typename T > inline void modAdd(T& a, T b, T mod) { a = (a + b) % mod; }
template< typename T > inline void minUpdate(T& a, T b) { a = min(a, b); }
template< typename T > inline void maxUpdate(T& a, T b) { a = max(a, b); }
// converter
template< typename F, typename T >
inline void convert(F& from, T& to) {
	stringstream ss;
	ss << from; ss >> to;
}

string S;
int K;

char addC(char c, int a) {
	int b = (c - 'a') + a;
	b %= 26;
	return char('a' + b);
}

int dsta(char c) {
	int b = (c - 'a');
	return (26 - b) % 26;
}

int main() {
	cin >> S;
	cin >> K;
	
	int n = S.size();
	for_(i,0,n) {
		int k = dsta(S[i]);
		if (k <= K) {
			S[i] = 'a';
			K -= k;
		}
	}
	
	S[n - 1] = addC(S[n - 1], K);
	cout << S << endl;
}

Measured memory_bytes: 640
// clang-format off
#include <bits/stdc++.h>
using namespace std;
// #define int long long
#define main signed main()
#define loop(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) loop(i, 0, n)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define prec(n) fixed << setprecision(n)
constexpr int INF = sizeof(int) == sizeof(long long) ? 1000000000000000000LL : 1000000000;
constexpr int MOD = 1000000007;
constexpr double PI = 3.14159265358979;
template<typename A, typename B> bool cmin(A &a, const B &b) { return a > b ? (a = b, true) : false; }
template<typename A, typename B> bool cmax(A &a, const B &b) { return a < b ? (a = b, true) : false; }
bool odd(const int &n) { return n & 1; }
bool even(const int &n) { return ~n & 1; }
template<typename T = int> T in() { T x; cin >> x; return x; }
template<typename T = int> T in(T &&x) { T z(forward<T>(x)); cin >> z; return z; }
template<typename T> istream &operator>>(istream &is, vector<T> &v) { for (T &x : v) is >> x; return is; }
template<typename A, typename B> istream &operator>>(istream &is, pair<A, B> &p) { return is >> p.first >> p.second; }
template<typename T> ostream &operator<<(ostream &os, const vector<vector<T>> &v) { int n = v.size(); rep(i, n) os << v[i] << (i == n - 1 ? "" : "\n"); return os; }
template<typename T> ostream &operator<<(ostream &os, const vector<T> &v) { int n = v.size(); rep(i, n) os << v[i] << (i == n - 1 ? "" : " "); return os; }
template<typename A, typename B> ostream &operator<<(ostream &os, const pair<A, B> &p) { return os << p.first << ' ' << p.second; }
template<typename Head, typename Value> auto vectors(const Head &head, const Value &v) { return vector<Value>(head, v); }
template<typename Head, typename... Tail> auto vectors(Head x, Tail... tail) { auto inner = vectors(tail...); return vector<decltype(inner)>(x, inner); }
// clang-format on

main {
  while (true) {
    int n = in();
    if (n == 0) break;
    vector<int> x(n), y(n), r(n), c(n);
    rep(i, n) cin >> x[i] >> y[i] >> r[i] >> c[i];
    auto intersectCC = [&](int i, int j) {
      int r2 = (r[i] + r[j]) * (r[i] + r[j]);
      int d = (x[i] - x[j]) * (x[i] - x[j]) + (y[i] - y[j]) * (y[i] - y[j]);
      return d < r2;
    };
    auto intersect = [&](int t, int used) {
      bool f = false;
      rep(i, t) f |= (~used >> i & 1) && intersectCC(t, i);
      return f;
    };
    vector<int> dp(1 << n, -1);
    function<int(int)> dfs = [&](int used) {
      if (dp[used] != -1) return dp[used];
      cmax(dp[used], 0);
      rep(i, n) loop(j, i + 1, n) {
        if ((used >> i & 1) || (used >> j & 1) || c[i] != c[j]) continue;
        if (intersect(i, used) || intersect(j, used)) continue;
        cmax(dp[used], dfs(used | (1 << i) | (1 << j)) + 2);
      }
      return dp[used];
    };
    cout << dfs(0) << endl;
  }
}



Measured memory_bytes: 68460
//#pragma GCC optimize("O3")
//#pragma GCC target("avx2")
// 293206GT
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <set>
#include <map>
#include <queue>
#include <unordered_map>
#include <unordered_set>
#include <unordered_set>
#include <stack>
#include <string>
#include<algorithm>
#include <random>
#include <bitset>
#include <chrono>

typedef long long ll;
#define int ll
using namespace std;
#define put(a) cout << (a) << '\n'
#define sqr(x) (x) * (x)
typedef pair<ll, ll> pii;
typedef long double ld;

typedef pair<ld, ld> pld;
#define rep(x, y, a) for (int x = (y); x < (int)(a); ++x)
#define all(a) a.begin(), a.end()
#define chkmax(a, b) a = max(a, (b))
#define chkmin(a, b) a = min(a, (b))
#define prev asasdasd
#define next aasdasda
#define left asdasdasdasd
#define right asnabsdkasdl
#define rank asdasdknlasd
#define move asdasdas

typedef vector<int> vi;
typedef vector<pii> vpii;
namespace IO {
    template<class A, class B>
    ostream &operator<<(ostream &out, pair<A, B> &a) {
        out << a.first << " " << a.second;
        return out;
    }

    template<class A, class B>
    ostream &operator<<(ostream &out, vector<pair<A, B>> &a) {
        for (pair<A, B> x: a)
            out << x.first << " " << x.second << '\n';
    }

    template<class A>
    ostream &operator<<(ostream &out, vector<A> &a) {
        for (A x: a) out << x << ' ';
        return out;
    }

    template<class A, class B>
    istream &operator>>(istream &in, pair<A, B> &a) {
        in >> a.first >> a.second;
        return in;
    }

    template<class A>
    istream &operator>>(istream &in, vector<A> &a) {
        for (A &x: a) in >> x;
        return in;
    }
}
using namespace IO;

int gcd(int a, int b) { return (b == 0 ? a : gcd(b, a % b)); }

void solve() {
    int n;
    cin >> n;
    vi a(n, 0);
    rep(i, 0, n) {
        char c;
        cin >> c;
        if (c == 'G') a[i] = 1;
        if (c == 'B') a[i] = 2;
    }
    vector<vi> pref(3, vi(n + 1, 0));
    rep(i, 1,  n + 1) {
        rep(j, 0, 3) pref[j][i] = pref[j][i - 1] + int(a[i - 1] == j);
    }
    int res = 0;
    rep(i, 0, n) rep(j, i + 1, n) if (a[i] != a[j]) {
        int s = 3;
        s -= a[i] + a[j];
        res += pref[s][n] - pref[s][j + 1] - (j + j - i < n && a[j + j - i] == s);
    }
    put(res);
}


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

//    freopen("input.txt", "r", stdin);
    int t = 1;
//    cin >> t;
    while (t--) solve();
}

Measured memory_bytes: 3256
#!/usr/bin/env python3
import sys
INF = float("inf")
MOD = 10**9+7

N = int(input())
A = list(map(int, input().split()))


AA = [(a, i) for i, a in enumerate(A, start=1)]
AA.sort(reverse=True)
# print(AA)

DP = {}
DP[(0, 0)] = 0

for wa in range(1, N+1):
    # AA[:wa]までを考える
    a, i = AA[wa-1]
    for x in range(wa+1):
        y = wa - x
        DP[(x, y)] = 0
        if x - 1 >= 0:
            DP[(x, y)] = max(DP[(x, y)], DP[(x-1, y)]+a*(i-x))
        if y - 1 >= 0:
            DP[(x, y)] = max(DP[(x, y)], DP[(x, y-1)]+a*(N-y-i+1))
        # print(wa, (x, y), (a, i), DP[x][y])

print(max([DP[(x, N-x)] for x in range(N+1)]))


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

string a,b;
int dp[3010][3010];
pair<int,int> c[3010][3010];

void print(int x,int y)
{
	if(x==0||y==0) return;
	else{
		print(c[x][y].first,c[x][y].second);
		if(a[x-1]==b[y-1]){
			cout<<a[x-1];
		}
	}
}

signed main()
{
	ios::sync_with_stdio(false);
	cin>>a>>b;
	for(int i=1;i<=a.size();i++){
		for(int j=1;j<=b.size();j++){
			if(a[i-1]==b[j-1]){dp[i][j]=dp[i-1][j-1]+1;c[i][j]=make_pair(i-1,j-1);}
			else{
				if(dp[i-1][j]>dp[i][j-1]) c[i][j]=make_pair(i-1,j);
				else c[i][j]=make_pair(i,j-1);
				dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
			}
		}
	}
	print(a.size(),b.size());
	cout<<endl;
	return 0;
}

Measured memory_bytes: 106496
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define rep2(i, s, n) for (ll i = (s); i < (ll)(n); i++)
#define repd(i, n) for (ll i = (ll)(n)-1; i >= 0; i--)
const ll INF = 1LL << 60;
const int INF32 = 1 << 29;
const ll MOD = 1000000007;
using Graph = vector<vector<int>>; // グラフ型
using pint = pair<int, int>;

long long gcd(long long a, long long b)
{
    if (b == 0)
    {
        return a;
    }
    else
    {
        return gcd(b, a % b);
    }
}

int main()
{
    int K;
    cin >> K;
    ll ans = 0;
    rep2(i, 1, K + 1)
    {
        rep2(j, 1, K + 1)
        {
            rep2(k, 1, K + 1)
            {
                ans += gcd(i, gcd(j, k));
            }
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 3608
#include <iostream>
#include<algorithm>
#include<sstream>
#include<cmath>
#include<vector>
#include<iomanip>
#include<map>
#include<set>
#include<queue>
using namespace std;
typedef long long ll;
typedef long double ld;
#define rep(i,n) for(int i = 0; i < n;i++)
int main() {
	ll n, m, ans = 0,sum = 0,x,y;cin >> n >> m;
	vector<pair<ll, ll>> a(n);
	rep(i, n) {
		cin >> x >>  y;
		a[i] = make_pair(x, y);
	}
	sort(a.begin(), a.end());
	int i = 0;
	while (sum < m) {
		sum += a[i].second;
		ans += a[i].first * a[i].second;
		i++;
	}
	int u = sum - m;
	ans -= u * a[i - 1].first;
	cout << ans << endl;
}

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

const int mod = 1e9 + 7;

int cnt[26];
int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int n;
	string s;
	cin>>n>>s;
	for(int i=0;i<n;i++){
		cnt[s[i]-'a']++;
	}
	int ans = 1;
	for(int i=0;i<26;i++)
		ans = 1LL * ans * (1+cnt[i]) % mod;
	ans--;
	if(ans<0)	ans+=mod;
	cout<<ans<<endl;
}




Measured memory_bytes: 512
from collections import defaultdict as de
n,q=map(int,input().split())
s=[[]for i in range(n+1)]
a=de(int)
for i in range(n-1):
    o,b=map(int,input().split())
    s[o].append(b)
    s[b].append(o)
for i in range(q):
    p,x=map(int,input().split())
    a[p]=a[p]+x
t=[0]*(n+1)
g=[[1,0,0]]
while g:
    w=[]
    for i in g:
        t[i[0]]=i[1]+a[i[0]]
        for j in s[i[0]]:
            if j!=i[2]:
                w.append([j,t[i[0]],i[0]])
    else:
        g=w
print(*t[1:])

Measured memory_bytes: 89068
import math
if __name__ == '__main__':
    N = int(input())
    A = [int(elem) for elem in input().split()]
    count = [0]*N
    for i in A:
      #  print("i", i)
      #  print("A",A[i-1])
        count[i-1] = count[i-1]+1
    
    [print (i) for i in count]

Measured memory_bytes: 33540
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cstdio>
#include <cassert>
#define int long long
using namespace std;

int n;
int a[100000];

signed main() {
	int i;
	
	cin >> n;
	for (i = 0; i < n; i++) cin >> a[i];
	sort(a, a + n, greater<int>());
	
	double minDist = 1145141919;
	int ans = 0;
	for (i = 1; i < n; i++) {
		double dist = a[i] - (double)a[0] / 2;
		if (dist < 0) dist *= -1;
		if (minDist > dist) {
			minDist = dist;
			ans = i;
		}
	}
	cout << a[0] << " " << a[ans] << endl;
	return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
const int N=1e5+7;
int n,m,fa[N],ans;
int find(int x){return x==fa[x]?x:fa[x]=find(fa[x]);}
int main()
{
	scanf("%d%d",&n,&m);
	ans=n;
	for(int i=1;i<=n;i++)fa[i]=i;
	for(int i=1,x,y;i<=m;i++)
	{
		scanf("%d%d%*d",&x,&y);
		x=find(x),y=find(y);
		if(x!=y)fa[x]=y,ans--;
	}
	printf("%d\n",ans);
}

Measured memory_bytes: 640
X,K,D = [int(i) for i in input().split()]
X = abs(X)
M = X//D
if K <= M:
    print(X - K*D)
    exit()
X = X - M*D
K -= M
if K%2 == 0:
    print(X)
else:
    print(abs(X-D))

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

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            var s = Console.ReadLine().Split(' ');
            var n = int.Parse(s[0]);
            var x = int.Parse(s[1]);
            var sls = Console.ReadLine().Split(' ');
            var ls = new int[n];
            for (int i = 0; i < n; i++)
            {
                ls[i] = int.Parse(sls[i]);
            }
            bool isyesorno = false;
            bool yes = false;
            if (!isyesorno)
            {
                int place = 0;
                int count = 0;
                while (place <= x)
                {
                    if (count < n)
                    {
                        place += ls[count];
                        count++;
                    }
                    else
                    {
                        count++;
                        break;
                    }
                }
                Console.WriteLine(count);
            }
            else
            {
                if (yes)
                {
                    Console.WriteLine("Yes");
                }
                else
                {
                    Console.WriteLine("No");
                }
            }

#if DEBUG
            Console.WriteLine("続行するには何かキーを押してください．．．");
            Console.ReadKey();
#endif
        }
    }
}

Measured memory_bytes: 13140
#include<iostream>
#include<cstdio>
#include<cmath>

using namespace std;

/*
n
a1
..
an

n<100000
ai<1000000000

out: first, second
*/
typedef long long int ll;


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

  int s=0;
  for(int i=0; i<n; i++){
    ll a;
    cin >> a;
    s += a%2;
  }

  if(s == 0)
    cout << "second\n";
  else
    cout << "first\n";


  return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,n,m) for(int i = (n); i <(m); i++)
#define rrep(i,n,m) for(int i = (n) - 1; i >=(m); i--)
#define pvec(vec) {for (auto v: vec) cout << v << ' '; cout << endl;}
#define pivec(vec) {rep(i, 0, vec.size()) cout << i << ':' << vec[i] << ' '; cout << endl;}

using namespace std;
using ll = long long;
using block = tuple<int, int, int, int>;

int N;
vector<int> X, Y;
vector<int> Y_posi[5000], Y_nega[5000]; 
vector<block> points;
vector<int> grid;

int main()
{
    // read input
    scanf("%d", &N);
    rep(i, 0, N)
    {
        int x1, y1, x2, y2;
        scanf("%d %d %d %d", &x1, &y1, &x2, &y2);

        points.emplace_back(x1, y1, x2, y2); 
        X.emplace_back(x1);
        X.emplace_back(x2);
        Y.emplace_back(y1);
        Y.emplace_back(y2);
    }

    // make compressed axes
    sort(X.begin(), X.end());
    sort(Y.begin(), Y.end());
    X.erase(unique(X.begin(), X.end()), X.end());
    Y.erase(unique(Y.begin(), Y.end()), Y.end());

    // paint corner
    for (block point: points)
    {
        int x1, y1, x2, y2;
        tie(x1, y1, x2, y2) = point;

        x1 = lower_bound(X.begin(), X.end(), x1) - X.begin();
        x2 = lower_bound(X.begin(), X.end(), x2) - X.begin();
        y1 = lower_bound(Y.begin(), Y.end(), y1) - Y.begin();
        y2 = lower_bound(Y.begin(), Y.end(), y2) - Y.begin();

        Y_posi[y1].push_back(x1);
        Y_posi[y1].push_back(x2);
        Y_nega[y2].push_back(x1);
        Y_nega[y2].push_back(x2);
    }

    long long ans = 0;
    vector<int> grid(X.size(), 0);
    rep(y, 0, (int)Y.size()-1)
    {
        // paint upper line
        for (int i=0; i < (int) Y_posi[y].size(); i += 2)
        {
            int from  = Y_posi[y][i];
            int to = Y_posi[y][i+1];
            
            rep(x, from, to) ++grid[x];
        }

        // paint bottom line
        for (int i=0; i < (int) Y_nega[y].size(); i += 2)
        {
            int from  = Y_nega[y][i];
            int to = Y_nega[y][i+1];
            
            rep(x, from, to) --grid[x];
        }

        // take cumulative sum 
        rep(x, 0, (int)X.size())
        {
            if (grid[x] == 0) continue;
            
            ans += (ll) (Y[y+1]-Y[y]) * (X[x+1]-X[x]);
        }
    }
    printf("%lld\n", ans);
    return 0;
}



Measured memory_bytes: 3720
n=int(input())
a=sorted(list(map(int,input().split())))

def groupby():
    global a
    a2=[[a[0],1]]
    for i in range(1,len(a)):
        if a2[-1][0]==a[i]:
            a2[-1][1]+=1
        else:
            a2.append([a[i],1])
    return a2

b=groupby()
ans=0
for i in b:
    if i[0]>i[1]:
        ans+=i[1]
    else:
        ans+=(i[1]-i[0])

print(ans)


Measured memory_bytes: 71464
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <queue>
#include <map>
#include <unordered_map>
#include <set>
#include <functional>
#include <bitset>
#include <numeric>
#include <ccomplex>
#include <cassert>
#include <random>
using namespace std;
using ll = long long;


int main() {
	int n, k; cin >> n >> k;
	vector<double> p(n);
	for (int i = 0; i < n; i++) cin >> p[i];
	double s = 0;
	for (int i = 0; i < k; i++) s += (p[i] + 1) / 2;
	double ans = s;
	for (int i = k; i < n; i++) {
		s -= (p[i - k] + 1) / 2;
		s += (p[i] + 1) / 2;
		ans = max(ans, s);
	}
	printf("%.10f\n", ans);
	return 0;
}


Measured memory_bytes: 1792
#include <algorithm>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
#define rep(i, x, n) for(int i = x; i < n; i++)
using namespace std;
const long long INF = 1LL << 60;
template <class T> inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
}
template <class T> inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}
const int MOD = 1000000007;
int main() {
    int N;
    cin >> N;
    int P[30];
    rep(i, 0, N) { cin >> P[i]; }
    int res = 0;
    rep(i, 1, N - 1) {
        int a = P[i - 1];
        int b = P[i];
        int c = P[i + 1];
        if((a < b && b < c) || (a > b && b > c)) {
            res++;
        }
    }
    cout << res << endl;
}

Measured memory_bytes: 256
x = int(input())

if 400 <= x and x <= 599:
    print(8)
elif 600 <= x and x <= 799:
    print(7)
elif 800 <= x and x <= 999:
    print(6)
elif 1000 <= x and x <= 1199:
    print(5)
elif 1200 <= x and x <= 1399:
    print(4)
elif 1400 <= x and x <= 1599:
    print(3)
elif 1600 <= x and x <= 1799:
    print(2)
else:
    print(1)

Measured memory_bytes: 9184
N, x = [int(i) for i in input().split()]
a = [int(i) for i in input().split()]
a.sort()

if sum(a) == x:
    print(N)
    exit()

low = 0
high = N - 1
most_happy = 0

while low <= high:
    i = int((low + high) / 2)
    if sum(a[0:i]) <= x:
        low = i + 1
        if i > most_happy:
            most_happy = i
    else:
        high = i - 1

print(most_happy)
exit()


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

long long N,K;
vector<long long> A(200010),F(200010);

bool check(long long v,long long n) {
  long long sum = 0;
  for(int i = 0;i < n;i++) {
    if(A.at(i)*F.at(i) > v) {
      sum += A.at(i) - v / F.at(i);
    }
  }
  
  return (sum <= K);
}

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

  for(int i = 0;i < N;i++) {
    cin >> A.at(i);
  }
  
  for(int i = 0;i < N;i++) {
    cin >> F.at(i);
  }
  

  sort(A.begin(),A.begin()+N);
  sort(F.rbegin(),F.rend());

  long long ng = -1,ok = 1e12+1;
  while(abs(ok-ng) > 1) {
    long long mid = (ok+ng) / 2;
    if(check(mid,N)) ok = mid;
    else ng = mid;
  }

 
  cout << ok << endl;

}


Measured memory_bytes: 3328
n,k=map(int,input().split())
a=list(map(int,input().split()))
b=[]
max1=0
s=0
c=[]
p=0
if n==k:
    for i in range(n):
        p += (1 / a[i]) * (a[i] * (a[i] + 1) / 2)
else:
    for i in range(n):
        s+=a[i]
        c.append(s)

        if i-k>-1:
            b.append(s-c[i-k])


    t=max(b)
    r=b.index(t)

    for i in range(r+1,r+k+1):
        p+=(1/a[i])*(a[i]*(a[i]+1)/2)
print(p)


Measured memory_bytes: 27460