akhauriyash/Code-Regression huggingface dataset:
#include "bits/stdc++.h"
using namespace std;

const int N=2e5+20,MOD=1e9+7;

int n,zero;
long long a,b,p[N],ans=1;
map <pair <long long,long long>,int> negative,positive;

int get(long long a,long long b)
{
	a*=-1;
	if(positive.find({b,a})==positive.end()) return 0;

	long long ans=positive[{b,a}];
	positive.erase({b,a});
	return ans;
}

int main()
{
	p[0]=1;
	for(int i=1;i<N;i++) p[i]=(p[i-1]*2)%MOD;

	scanf("%d",&n);
	while(n--)
	{
		scanf("%lld%lld",&a,&b);

		if(a==0 and b==0)
		{
			zero++;
			continue;
		}

		long long g=__gcd(a,b);
		a/=g,b/=g;
		if(b<0) a*=-1,b*=-1;
		if(a<=0) negative[{a,b}]++;
		else positive[{a,b}]++;
	}

	for(auto i:negative)
	{
		a=i.first.first,b=i.first.second;
		ans*=(p[i.second]+p[get(a,b)]-1ll)%MOD;
		ans%=MOD;
	}

	for(auto i:positive)
	{
		a=i.first.first,b=i.first.second;
		ans*=p[i.second];
		ans%=MOD;
	}

	ans=(ans+zero-1)%MOD;
	if(ans<0) ans+=MOD;
	printf("%lld",ans);
}

Measured memory_bytes: 17892
package main

import (
	"fmt"
)

func min(a, b int) int {
	if a >= b {
		return b
	}
	return a
}

func main() {
	var n, a, b int
	fmt.Scan(&n, &a, &b)
	if a+b <= n {
		fmt.Println(min(a, b), 0)
	} else {
		fmt.Println(min(a, b), a+b-n)
	}
}


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

int main() {
	int H, N, A, T = 0;
	cin >> H >> N;
	for (int i = 0; i < N; i++) {
		cin >> A;
		T += A;
	}
	cout << (T >= H ? "Yes" : "No") << endl;
	return 0;
}


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

#define pb push_back
#define eb emplace_back
#define ff first
#define ss second
#define endl '\n'
#define boost ios::sync_with_stdio(false) ; cin.tie(NULL); cout.tie(NULL);

const int N = 3001;
pair<int , pair<int,int> >  dp[3001][3001];

template < class T > T max(T a , T b){
    
    if(a>b)
        return a;
    return b;
}

signed main(){

   string a , b;
   cin>>a>>b;

   int n = a.size();
   int m = b.size();

   for(int i = 1 ; i <= n ; ++i)
    for(int j = 1 ; j <= m ; ++j){

        if(a[i-1]==b[j-1]){
            dp[i][j].ff = 1 + dp[i-1][j-1].ff;
            dp[i][j].ss = {i-1,j-1};
        }
        else{
           
           if(dp[i][j-1].ff>dp[i][j].ff){

                dp[i][j].ff = dp[i][j-1].ff;
                dp[i][j].ss = dp[i][j-1].ss;
           }

           if(dp[i-1][j].ff > dp[i][j].ff){

                dp[i][j].ff = dp[i-1][j].ff;
                dp[i][j].ss = dp[i-1][j].ss;
           }
        }
    }

   // cout<<dp[n][m].ff<<endl;
    string s;
    pair<int,int> prev = dp[n][m].ss;
    pair<int,int> zero;
    zero = {0,0};
    while(1){

        s.pb(a[prev.ff]);
        if(prev==zero)
            break;
        prev = dp[prev.ff][prev.ss].ss;
    }
    reverse(s.begin(),s.end());

    if(s.size()>dp[n][m].ff)
        s.erase(s.begin());
    cout<<s<<endl;
}

Measured memory_bytes: 105728
/*Coded by::
    **Avinash Tiwary**
    **BE/10298/2015**
    **Production Engineer**
    **Producing <code>**
*/
#include<bits/stdc++.h>
#define buf ios_base::sync_with_stdio (0), cin.tie (0)
typedef long long ll;
typedef double dob;
#define MAX 50010
#define M5 200009
#define M6 2000009
#define M 1000000007
#define inf LLONG_MAX
using namespace std;
typedef vector<ll> V;
typedef queue<ll > Q;
typedef stack<ll> S;
typedef pair<ll,ll> P;
#define F first
#define S second
#define mp make_pair
#define mt make_tuple
#define pb push_back
ll fac[M6],not_prime[M6];
ll power(ll x,ll n){
    if(n==0) return 1;
    /*while(n){
        if(n%2) x=(((x*x)%M)*x)%M; 
        else x=(x*x)%M;
        n/=2;
    }*/
    if(n%2 == 0) return power((x*x),n/2);
    else return (x*power((x*x),(n-1)/2));
}
void fact(){
    fac[0]=1;
    for(ll i=1;i<M6;i++) fac[i]=(i*fac[i-1])%M;
}
void sieve(){
    not_prime[1]=1; not_prime[0]=1;
    for(ll p=2;p*p<M6;p++){
        if(!not_prime[p]){
            for(ll i=p*2;i<=M6;i+=p) not_prime[i]=1;
        }
    }
}
ll modi(ll a, ll m){
    ll m0 = m, t, q; ll x0 = 0, x1 = 1;
    if (m == 1) return 0;
    while (a > 1){  q = a / m; t = m; m = a % m, a = t;t = x0;x0 = x1 - q * x0; x1 = t;}
    if (x1 < 0) x1 += m0;return x1;
}
ll n,m,ar[M6],br[M6],cr[M6];
V g[M5];
/*ll solve(ll sor,ll des){
	if(sor==des) return 1;
	else return 0;
	if(dp[sor][des]!=-1) return dp[sor][des];
	ll i,ans=0;
	for(i=1;i<=n;i++){
		if(connect[i][des]){
			ans+=solve(n,i); ans%=M;
		}
	}
	return dp[sor][des]=ans;
}*/
int main(){
    //buf; 
    //fact();
    //sieve()
    ll i,j,k,l,test,flag,ans,x,y; string s;
    //cin>>test;
    test=1;
    while(test--){
    	cin>>n>>x;
    	for(i=1;i<=n;i++) {
    		cin>>ar[i]>>br[i];
    		cr[i]=br[i];
    	}
    	l=*max_element(ar+1,ar+n+1);
    	ans=ceil(x*1.0/l);
    	//cout<<ans<<" ";
    	sort(cr+1,cr+n+1);
    	ll y=0;
    	for(i=n;i>=1;i--){
    		
    			y+=cr[i];
    			ans=min((ll)ceil(max(x-y,0LL)*1.0/l)+n-i+1LL,ans);
    		
    	}
    	cout<<ans;
	}
    return 0;
}

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

typedef long long ll;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define each(itr,c) for(__typeof(c.begin()) itr=c.begin(); itr!=c.end(); ++itr)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second

struct Magic{ int cost,damage; };
vector<Magic> s,a;

const int N=200000;

const int INF=123456789;
int dp[2][N+1];
void calc(const vector<Magic> &v, int dst[])
{
    int V=v.size();

    fill(dp[0],dp[2],INF);
    dp[0][0]=0;
    rep(i,V)rep(j,N+2)
    {
        if(j-v[i].damage<0) dp[(i+1)&1][j]=dp[i&1][j];
        else dp[(i+1)&1][j]=min(dp[i&1][j],dp[(i+1)&1][j-v[i].damage]+v[i].cost);
    }

    rep(i,N+1) dst[i]=dp[V&1][i];

    int min_cost=INF;
    for(int i=N; i>=0; --i)
    {
        min_cost=min(min_cost,dst[i]);
        dst[i]=min_cost;
    }
}

int main()
{
    int ds[N+1],da[N+1];

    int n;
    while(cin >>n,n)
    {
        s.clear();
        a.clear();

        vector<int> hp(n);
        rep(i,n) cin >>hp[i];

        int m;
        cin >>m;
        rep(i,m)
        {
            string M,sa;
            int mp,d;
            cin >>M >>mp >>sa >>d;

            if(d==0) continue;
            if(d>=N) d=N;

            if(sa=="All") a.pb(Magic{mp,d});
            else s.pb(Magic{mp,d});
        }

        calc(s,ds);
        calc(a,da);

        int ans=INF;

        rep(i,100001)
        {
            bool valid=true;
            int tmp=da[i];
            rep(j,n)
            {
                int rem=hp[j]-i;
                if(rem<=0) continue;
                if(ds[rem]==INF)
                {
                    valid=false;
                    break;
                }
                tmp+=ds[rem];
            }

            if(!valid) continue;
            ans=min(ans,tmp);
        }

        printf("%d\n", ans);
    }
    return 0;
}

Measured memory_bytes: 6364
#include <stdio.h>
#define bit(n,k)(((n)>>(k))&1)

int a[110];
int bingo[8]={
	0b1001001000,
	0b0100100100,
	0b0010010010,
	0b1110000000,
	0b0001110000,
	0b0000001110,
	0b1000100010,
	0b0010101000
};
int main(){
	for(int i=1;i<=9;i++){
		int t;
		scanf("%d",&t);
		a[t]=i;
	}
	int n;
	scanf("%d",&n);
	int s=0;
	for(int i=0;i<n;i++){
		int t;
		scanf("%d",&t);
		s|=1<<a[t];
	}
	for(int i=0;i<8;i++){
		if((s&bingo[i])==bingo[i]){
			puts("Yes");
			return 0;
		}
	}
	puts("No");
}

Measured memory_bytes: 128
import sys
sys.setrecursionlimit(10**9)
n=int(input())
h=[int(x) for x in input().split()]

ans_list=[]

def A(i,n,h,ans_list):
    ans=0
    for j in range(i,n-1):
        if h[j]>=h[j+1]:
            ans+=1
            if j==n-2:
                ans_list.append(ans)
                break
        else:
            ans_list.append(ans)
            A(j+1,n,h,ans_list)
            break
        
if n==1:
    print(0)
else:
    A(0,n,h,ans_list)
    print(max(ans_list))


Measured memory_bytes: 102016
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cstring>

using namespace std;

#define N 100008

int n, top, ans;
int f[N], son[N], fa[N], vis[N];
struct road
{
    int next, to;
}r[2*N];

void build(int u, int v)
{
    r[++top].to = v;
    r[top].next = f[u];
    f[u] = top;
}

int dfs(int now, int fa)
{
    if (son[now] > 2)   return now;
    for (int i = f[now]; i; i = r[i].next)
    {
        if (r[i].to == fa) continue;
        now = dfs(r[i].to, now);
    }
    return now;
}

void solve()
{
    for (int i = 0; i < n; i++)
    {
        if (son[i] == 1)
        {
            vis[dfs(i, -1)] = 1;
            ans++;
        }
    }
    for (int i = 0; i < n; i++)
        if (vis[i] == 1)
            ans--;
    ans = max(ans, 1);
}

int main()
{
    int x, y;
    while (~scanf("%d", &n))
    {
        top = ans = 0;
        memset(f, 0, sizeof(f));
        memset(vis, 0, sizeof(vis));
        memset(son, 0, sizeof(son));
        for (int i = 1; i < n; i++)
        {
            scanf("%d%d", &x, &y);
            son[x]++;
            son[y]++;
            build(x, y);
            build(y, x);
        }
        solve();
        printf("%d\n", ans);
    }
    return 0;
}

Measured memory_bytes: 6144
import sys
sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline

n, m = map(int, input().split())

e000 = [0]*n
e001 = [0]*n
e010 = [0]*n
e011 = [0]*n
e100 = [0]*n
e101 = [0]*n
e110 = [0]*n
e111 = [0]*n

for i in range(n):
    x,y,z = map(int, input().split())
    e000[i]=-x-y-z
    e001[i]=-x-y+z
    e010[i]=-x+y-z
    e011[i]=-x+y+z
    e100[i]=x-y-z
    e101[i]=x-y+z
    e110[i]=x+y-z
    e111[i]=x+y+z

if m==0:
    print(0)
    exit()

e000.sort()
e001.sort()
e010.sort()
e011.sort()
e100.sort()
e101.sort()
e110.sort()
e111.sort()

elist = [e000,e001,e010,e011,e100,e101,e110,e111]

ans = 0
for e in elist:
    ans = max(ans, sum(e[-m:]))

print(ans)




Measured memory_bytes: 3316
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin >> n;
  int a[200005];
  for(int i=0;i<n;i++){
    cin >> a[i];
  }
  int ma=-1000000001;
  int mi=1000000001;
  int st;
  for(int i=0;i<n;i++){
    if(i!=0)ma=max(ma,a[i]-mi);
    if(mi>a[i]){
      mi=a[i];
    }
    else{ 
      ma=max(ma,a[i]-mi);
    }
    
  }
  cout << ma << endl;
  return 0;
}

Measured memory_bytes: 3876
import java.util.Arrays;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        String S = sc.next();

        System.out.println(solve(S) ? "Yes" : "No");

        sc.close();
    }

    static boolean solve(String S) {
        char[] letters = S.toCharArray();
        Arrays.sort(letters);

        return letters[0] == letters[1] && letters[1] != letters[2] && letters[2] == letters[3];
    }
}

Measured memory_bytes: 35744
#include<bits/stdc++.h>
using namespace std;
const int maxn=1e5+10;
char str[maxn];
int main()
{
    while(scanf("%s",str)!=EOF)
    {
        int gg=0,pp=0,ans=0;
        int len=strlen(str);
        for(int i=0; i<len; i++)
        {
            if(str[i]=='g')
            {
                if(pp<gg)ans++,pp++;
                else gg++;
            }
            else
            {
                if(pp<gg)pp++;
                else gg++,ans--;
            }
        }
        printf("%d\n",ans);
    }
}


Measured memory_bytes: 384
attrs = Array.new
while line = $stdin.gets
    attrs << line.chomp.split.map{|v| v.to_i }
end

N = attrs.shift[0]
H = attrs.shift
m = 0
tmp = 0
if N == 1 then
  puts 0
else
  for i in 0..(H.length - 2) do
    tmp = 0 if H[i] < H[i + 1]
    tmp += 1 if H[i] >= H[i + 1]
    m = [ tmp, m ].max
  end
  puts m
end

Measured memory_bytes: 12300
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
int main()
{
  int x,y,res=0;
  cin >> x >> y;
  if(x<=3) res+=100000;
  if(x<=2) res+=100000;
  if(x==1) res+=100000;
  if(y<=3) res+=100000;
  if(y<=2) res+=100000;
  if(y==1) res+=100000;
  if(x==1&&y==1) res+=400000;
  cout << res << endl;
  return 0;
}

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

//#pragma comment(linker, "/stack:200000000")
#pragma GCC optimaxze("O3", "Ofast", "unroll-loops", "fast-math")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")


#define int long long
#define endl '\n'

using namespace std;

signed main(){
    //ios_base::sync_with_stdio(false);
    //cin.tie(0);
    int i, n, m, j;
    cin >> n >> m;
    vector < double > a(n);
    double sum = 0;
    for (i = 0; i < n; i++){
        cin >> a[i];
        sum += a[i];
    }
    int ans = 0;
    for (i = 0; i < n; i++){
        if (a[i] / sum >= 1 / (double)(4 * m)){
            ans++;
        }
    }
    if (ans >= m){
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }
    return 0;
}


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

typedef long long ll;

ll cnt_m;
ll cnt_b;

//分割統治で考える。Aはもともとswapされる配列なので、mergeSortで分割した後、R[]の項が選ばれれば
//swap回数が減る。

ll merge(int A[],int left,int mid,int right)
{
  ll res = 0;
  
  int n1 = mid - left;
  int n2 = right - mid;

  int L[n1+1],R[n2+1];
  for(int i=0;i < n1;i++){
    L[i] = A[left+i];
  }
  for(int i=0;i < n2;i++){
    R[i] = A[mid+i];
  }
  
  L[n1]=R[n2]=INF;
  
  int i=0,j=0;
  for(int k=left;k < right;k++){
    if(L[i] <= R[j]){
      A[k] = L[i++];
    }
    else{
      A[k] = R[j++];
      res += n1-i;
      //R[]の項が選ばれたとき、swapの回数が減る。(iが増える)
      //また、
    }
  }
  return res;
}

ll mergeSort(int A[],int left,int right)
{
  ll cnt1,cnt2,cnt3;
  
  if(left+1 < right){
    int mid = (left + right)/2;
    cnt1 = mergeSort(A,left,mid);
    cnt2 = mergeSort(A,mid,right);
    cnt3 = merge(A,left,mid,right);
    return cnt1+cnt2+cnt3;
  }
  else return 0;
}

int bubbleSort(int A[],int n)
{
  int i,j;
  int temp;
  
  for(i = 0; i < n ;i++){
    for(j = n-1; j > i ;j--){
      
      if( A[j-1] > A[j] ){
	swap(A[j-1],A[j]);
	cnt_b++;
      }
    }
  }
}

int main()
{
  int i;
  int n;
  int A[200001];
  int B[200001];
  
  scanf("%d",&n);

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

  cnt_m = mergeSort(A,0,n);

  //bubbleSort(B,n);

  //for(int i=0;i < n;i++) cout << A[i];
  //cout << endl;

  //cout << cnt_m << endl << "cnt_b = " << cnt_b << endl;
  cout << cnt_m << endl;
  return 0;
}




Measured memory_bytes: 4792
# -*- coding: utf-8 -*-

n = int(input())

a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))

ans = b[a[0]-1]

for i, food in enumerate(a[1:]):
    ans += b[food-1]
    if a[i] == food-1:
        ans += c[food-2]

print(ans)


Measured memory_bytes: 9064
#include <iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main()
{
    int n;
    cin >> n;
    vector<double> S(n);
    for(int i=0;i<n;i++)
    {
        cin >> S.at(i);
    }
    sort(S.begin(),S.end());
    double ans=(S.at(0)+S.at(1))/2;
    for(int i=2;i<n;i++)
    {
        ans=(ans+S.at(i))/2;
    }
    cout << ans << endl;
    return 0;
}


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

typedef long long ll;

const int MOD = 1000000007;
const int INF = 1001001001;
const double PI = acos(-1);

#define rep(i, n)  for(int i=0;i<(n);++i)
#define all(x) (x).begin(),(x).end()
int gcd(int x, int y) { return y ? gcd(y, x % y) : x; }

int main() {
    char s;
    cin >> s;
    if (int(s) >= int('a')) cout << "a" << endl;
    else cout << "A" << endl;
}


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

int main() {
	vector<int>A = { 1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51 };
	int K;
	cin >> K;
	cout << A[K - 1] << endl;
	return 0;
}

Measured memory_bytes: 3612
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long int ll;
const int MOD = 1e9+7;

double dp[3005][3005];

int main()
{
  int n;
  cin >> n;
  vector<double> p(n);
  REP(i,n) cin >> p[i];
  dp[0][0]=1.0;
  
  REP(i,n){
    REP(j,i+1){
      dp[i+1][j+1] += dp[i][j] * p[i];
      dp[i+1][j] += dp[i][j] * (1.0 - p[i]);
    }
  }
  double res = 0.0;
  FOR(i,n/2+1,n+1) res += dp[n][i];
  cout << fixed << setprecision(10) << res << '\n';
  return 0;
}

Measured memory_bytes: 69120
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include <queue> //C++
#include <string> //C++
#include <iostream> //C++
#include <vector> //C++
#include <algorithm> //C++
using namespace std; //C++
#define rep(i, a, n) for (i = (a); i < (n); i++)


int main() 
{
		int n;
		scanf("%d", &n);

		int x = n * 800 - n / 15 * 200;

		cout << x << endl;
	

}

Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <cstdlib>
#include <cstdio>
#include <string>
#include <cstring>
#include <cassert>
#include <utility>
#include <iomanip>

using namespace std;

#define sz(x) (int) x.size()
#define unique(x) x.erase(unique(x.begin(), x.end()), x.end())
#define all(a) a.begin(), a.end()
#define sqr(x) ((x) * (x)) 
#define y1 aksjdaskdjksjfksdjf
#define left kdnvldvoiwejifejg
#define right lkdsjflksdjfdjfk
#define prev asdasfsadjkjsdfjs

const int MAXN = 2 * 105000;
const int INF = (int) 1e9;

int n;
int h[MAXN];
int a[MAXN];
long long ans;

int num;
long long tree[4 * MAXN];

void initTree() {
  num = 1;
  while (num < n) {
    num *= 2;
  }

  for (int i = 1; i < 2 * num; i++) {
    tree[i] = -INF;
  }
}

long long getMax(int l, int r) {
  l = num + l; r = num + r;
  long long res = -INF;
  
  while (l <= r) {
    if (l & 1) {
      res = max(res, tree[l]);
      l++;
    }
    if (r % 2 == 0) {
      res = max(res, tree[r]);
      r--;
    }
    l /= 2; r /= 2;
  }

  return res;
}

void update(int pos, long long val) {
  pos = num + pos;
  tree[pos] = val;
  pos /= 2;
  while (pos > 0) {
    tree[pos] = max(tree[pos * 2], tree[pos * 2 + 1]);
    pos /= 2;
  }
}

int main() { 

  scanf("%d", &n);

  for (int i = 0; i < n; i++) {
    scanf("%d", &h[i]);
  }
  for (int i = 0; i < n; i++) {
    scanf("%d", &a[i]);
  }

  initTree();

  for (int i = 0; i < n; i++) {
    long long cur = a[i];
    if (h[i] > 1) {
      long long mx = getMax(0, h[i] - 2);
      if (mx >= 0) {
        cur += mx;
      }
    }
    ans = max(ans, cur);
    update(h[i] - 1, cur);
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 8448
//g++ -std=c++14 test.cpp -o test.out
//問題URL
//https://atcoder.jp/contests/caddi2018/tasks/caddi2018_b

//参考：
//https://drken1215.hatenablog.com/entry/2018/12/23/014700

//ポイント：
//状態がキープできるのはどういう時かを見る＋偶奇に注目する

//残り全部偶数という状態を作れば勝ち確
//相手が(1,1,0,1)みたいな奇数個とる削り方をしてきても
//そのままお返しすれば残り全部偶数という状態をキープ可能

#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <iomanip>
#include <vector>
#include <queue>
#include <map> 
#include <utility>
#include <limits.h>
#include <bitset>
#include <set>
using namespace std;
 
#define LL long long int
const LL INF = (1LL<<60);
const int INF_INT = 2147483647-1e6-1;
const LL mod = 1000000007ll;
const int mod_int = 1000000007;

LL N;
LL A[100000];

string ans = "second";

void solve(){
	for(int i=0;i<N;i++){
		if(A[i]%2==1){
			ans = "first";
			return;
		}
	}
}
 
int main(){
    cin >> N;
    for(int i=0;i<N;i++) cin >> A[i];
 
    solve();

    cout << ans << endl;
    return 0;
}

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

// iterator
#define REP(i,from, to) for(lli i=from;i<to;i++)
#define REPE(i,from, to) for(lli i=from;i<=to;i++)
#define REP_R(i,from, to) for(lli i=from;i>to;i--)
#define REPE_R(i,from, to) for(lli i=from;i>=to;i--)
#define REPIT(it,container) for(auto it = container.begin(); it != container.end(); it++)
#define REPIT_R(it,container) for(auto it = container.rbegin(); it != container.rend(); it++)

// input
#define cin1(x)             cin >> x
#define cin2(x, y)          cin >> x >> y
#define cin3(x, y, z)       cin >> x >> y >> z
#define ncin1(n, x)         REP(i, 0, n) { cin1(x[i]); }
#define ncin2(n, x, y)      REP(i, 0, n) { cin2(x[i], y[i]); }
#define ncin3(n, x, y, z)   REP(i, 0, n) { cin3(x[i], y[i], z[i]); }
#define ncinp(n, p)         REP(i, 0, n) { lli p1,p2; cin >> p1 >> p2; p[i] = P(p1, p2); }
#define ncin1_1(n, x)       REPE(i, 1, n) { cin1(x[i]); }
#define ncin2_1(n, x, y)    REPE(i, 1, n) { cin2(x[i], y[i]); }
#define ncin3_1(n, x, y, z) REPE(i, 1, n) { cin3(x[i], y[i], z[i]); }
#define ncinp_1(n, p)       REPE(i, 1, n) { lli p1,p2; cin >> p1 >> p2; p[i] = P(p1, p2); }

// output
#define cout1(x)         cout << #x << ": " << x << endl;
#define cout2(x, y)      cout << #x << ": " << x << ", " << #y << ": " << y << endl;
#define cout3(x, y, z)   cout << #x << ": " << x << ", " << #y << ": " << y << ", " << #z << ": " << z << endl;;
#define ncout1(n, x)     REP(i, 0, n) {cout << #x << "[" << i << "]: "<< x[i] << endl;}

#define coutp(p)         cout << #p << ":" <<  " (" << p.first << ", " << p.second << ")" << endl;

// sort
#define sort_r(x, y)        sort(x, y, greater<lli>()); // 降順(5,4,3,,,)

#define ARRAY_LENGTH(array) (sizeof(array) / sizeof(array[0]))

typedef long long int lli;
typedef pair<lli, lli> P;
typedef tuple<lli, lli, lli> tup;
typedef vector<lli> vlli;

int main() {
    lli a,b,c;
    cin3(a,b,c);

    if (a+b+c>=22) {
        cout << "bust" << endl;
    }
    else
        cout << "win" << endl;
}


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

#define int long long
#define uint unsigned int
#define pii pair<int, int>

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define FORR(i,a,b) for(int i=(a);i>=(b);--i)
#define REP(i,n) FOR(i,0,n)
#define REPR(i,n) FORR(i,n,0)
#define ALL(c) ((c).begin()), ((c).end())

#define PB(a) push_back(a)
#define EMPB(...) emplace_back(__VA_ARGS__)
#define EMP(...) emplace(__VA_ARGS__)
#define MP(a,b) make_pair(a,b)
#define MT(...) make_tuple(__VA_ARGS__)

#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
#define MINF(a) memset(a,0x3f,sizeof(a))

#define PW(n) (1LL << (n))

using namespace std;

template <class T> inline bool CHMIN(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template <class T> inline bool CHMAX(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template <class T> inline void SORT(T &a) { sort(a.begin(), a.end()); }
template <class T> inline void REV(T &a) { reverse(a.begin(), a.end()); }
template <class T> inline void UNI(T &a) { sort(a.begin(), a.end()); a.erase(unique(a.begin(), a.end()), a.end()); }

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

const int MOD = 1000000007;
const int INF = 0x3f3f3f3f3f3f3f3f;
const double EPS = 1e-10;

/* ---------------------------------------------------------------------------------------------------- */



signed main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  
  char b;
  cin >> b;
  if (b == 'A') cout << 'T' << endl;
  if (b == 'T') cout << 'A' << endl;
  if (b == 'C') cout << 'G' << endl;
  if (b == 'G') cout << 'C' << endl;

  return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

using ll = long long;
using ii = pair<int,int>;
using vi = vector<int>;
using vii = vector<ii>;
const int oo = 1e9+7;

int n;
vector<ll> groups;
vector<ll> dp; 
ll score;
vi not_taken;

void solve(int i, int mask, int group) {
    
    if(i == (int)not_taken.size()) {
        dp[mask] = max(dp[mask], score + groups[group]);
        return;
    }
    
    solve(i+1, mask, group);
    solve(i+1, mask ^ (1 << not_taken[i]), group ^ (1 << not_taken[i]));
}

int main() {
    
    scanf("%d", &n);
    
    groups.assign(1 << n, 0);
    dp.assign(1 << n, -oo);
    
    vector<vector<ll>> compa(n, vector<ll>(n, 0));
    
    for(int i = 0; i < n; ++i) {
        for(int j = 0; j < n; ++j) {
            scanf("%lld", &compa[i][j]);
        }
    }
    
    for(int mask = 0; mask < (1 << n); ++mask) {
        for(int i = 0; i < n; ++i) {
            if(!(mask & (1 << i))) continue;
            for(int j = i+1; j < n; ++j) {
                if(mask & (1 << j)) {
                    groups[mask] += compa[i][j];
                }
            }
        }
    }
    
    dp[0] = 0;
    
    for(int mask = 0; mask < (1 << n); ++mask) {
        not_taken.clear();
        for(int i = 0; i < n; ++i) {
            if(!(mask & (1 << i))) {
                not_taken.push_back(i);
            }
        }
        score = dp[mask];
        solve(0, mask, 0); //not_taken, mask, 0, dp[mask]);
    }
    
    printf("%lld\n", dp[(1 << n)-1]);
    
    return 0;
}




Measured memory_bytes: 1280
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author Sagor
 */

#include <fstream>
#include <iostream>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
typedef long long int ll;
typedef double ld;
using namespace std;

class hjhj {
public:
	void solve(std::istream& in, std::ostream& out) {
	    int n,i,j;
	    in>>n;
	    string s;
	    in>>s;
	  //  out<<s;
	    int l = s.size(),c=0;
	    for(i=0;i<l;i++)
        {
	        if(s[i]=='A'&& s[i+1]=='B'&&s [i+2]=='C')
	            c++;
        }
	    out<<c<<endl;

	}
};


int main() {
    std::ios_base::sync_with_stdio(0);
    std::cin.tie(0);
	hjhj solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


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

typedef unsigned long long ll;

ll md = 1000000007;

int main(int, char**) 
{
	ll a, b, c;
	cin >> a >> b >> c;

	a -=b;
	if (c > a)
		c -= a;
	else
		c = 0;

	cout << c << endl;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <vector>
#include <algorithm>

int main()
{
    int N;
    std::vector<long> d;
    std::cin >> N;
    for(int i=0; i<N; i++){
        int temp;
        std::cin >>temp;
        d.push_back(temp);
    }
    std::sort(d.begin(),d.end());
    long s1=d[(N+1)/2];
    long s2=d[(N+1)/2-1];
    std::cout << s1-s2 << std::endl;
    return 0;
}

Measured memory_bytes: 1400
#include<iostream>
#include<stdio.h>
//#include <bits/stdc++.h>
#include<vector>
#include<float.h>
#include<iomanip>
#include<algorithm>
#include<string>
#include<cstring>
#include<math.h>
#include<cmath>
#include<sstream>
#include<set>
#include<map>
#include<queue>
#include <cassert>
#include <cmath>
#include<cstdint>

#define INF 1e9
#define rep(i,n)for(int i=0;(i)<(int)(n);i++)
#define REP(i,a,b)for(int i=(int)(a);(i)<=(int)(b);i++)
#define VEC(type, c, n) std::vector<type> c(n);for(auto& i:c)std::cin>>i;
#define vec(type,n) vector<type>(n)
#define vvec(m,n) vector<vector<int>> (int(m),vector<int>(n))
#define ALL(a)  (a).begin(),(a).end()

using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
using P = pair<int,int>;

vector<int>bitSearch(int bit,int n){
    vector<int>S;
    rep(i,n)if(bit&(1<<i))S.push_back(i);
    return S;
}

int d[100][100];             //スタートからの距離を保存
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};


int main(){
   int s, w;
   cin >> s >> w;
   cout << (w >= s ? "unsafe" : "safe") << endl;
}



Measured memory_bytes: 3596
def resolve():
    N = int(input())
    cnt = 0
    for _ in range(N):
        a, b = map(int, input().split())
        if a == b:
            cnt += 1
            if cnt == 3:
                return print("Yes")
        else:
            cnt = 0

    print("No")


if __name__ == "__main__":
    resolve()

Measured memory_bytes: 9120
#include <iostream>
using namespace std;
int main() {
	
	int a = 1, b = 1;
	
	while(!((a == 0)&&(b == 0))) {
		cin >> a >> b;
		for (int i = 1; i <= a; i++) {
			for (int j = 1; j <= b; j++) {
				if ((i + j)%2 == 0) {
					cout << '#';
				} else cout << '.';
			} cout << endl;
		}
		if (!((a == 0)&&(b == 0))) {
			cout << endl;
		}
	}
	
	return 0;
} 


Measured memory_bytes: 3072
#include <bits/stdc++.h>
#include <algorithm>
#include <math.h>
#define rep(i, n) for (long long i = 0; i < (long long)(n); i++)
#define INF 999999999
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

using llong = long long;
using namespace std;

int main(){
    llong x,y,z;
    cin >> x >> y >> z;
    cout << x+y+z - max(x,max(y,z)) << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<ll,ll> l_l;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<P> vp;
typedef vector<l_l> vpl;
#define pb push_back
#define sz(x) (int)(x).size()
#define fi first
#define se second
#define rep(i,n) for(int i=0;i<(n);i++)
#define rrep(i,n) for(int i=1;i<=(n);i++)
const int INF=1001001000;
const int mINF=-1001001000;
const ll LINF=10100100100100100;
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;
struct mint {
ll x;
mint(ll x=0):x((x%mod+mod)%mod){}
mint operator-() const { return mint(-x);}
mint& operator+=(const mint a) {
if ((x += a.x) >= mod) x -= mod;
return *this;
}
mint& operator-=(const mint a) {
if ((x += mod-a.x) >= mod) x -= mod;
return *this;
}
mint& operator*=(const mint a) {
(x *= a.x) %= mod;
return *this;
}
mint operator+(const mint a) const {
mint res(*this);
return res+=a;
}
mint operator-(const mint a) const {
mint res(*this);
return res-=a;
}
mint operator*(const mint a) const {
mint res(*this);
return res*=a;
}
mint pow(ll t) const {
if (!t) return 1;
mint a = pow(t>>1);
a *= a;
if (t&1) a *= *this;
return a;
}
mint inv() const {
return pow(mod-2);
}
mint& operator/=(const mint a) {
return (*this) *= a.inv();
}
mint operator/(const mint a) const {
mint res(*this);
return res/=a;
}
};
mint dp[1010][1010];
int main(){
    ll h,w;cin>>h>>w;
    vector<string> g(h);
    rep(i,h)cin>>g[i];
    rep(i,h){
        rep(j,w){
            dp[i][j]=0;
        }
    }
    dp[0][0]=1;
    rep(i,h){
        rep(j,w){
            if(i+1<=h-1)if(g[i+1][j]!='#')dp[i+1][j]+=dp[i][j];
            if(j+1<=w-1)if(g[i][j+1]!='#')dp[i][j+1]+=dp[i][j];
        }
    }
    cout<<dp[h-1][w-1].x<<endl;
    return 0;
}

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

using namespace std;
using ll = long long;

int main() {
	int N, Q;
	cin >> N >> Q;
	vector<ll> a(N + 1, 0);
	vector<ll> x(Q);
	for (int i = 1; i <= N; ++i) { cin >> a[i]; }
	for (int i = 0; i < Q; ++i) { cin >> x[i]; }

	vector<ll> dr(N + 1, 0);
	dr[N] = a[N];
	for (int i = N - 1; i > 0; --i) { dr[i] += dr[i + 1] + a[i]; }
	vector<ll> dc(N + 1, 0);
	for (int i = 1; i <= N; ++i) {
		if (N % 2 == 1) {
			dc[i] = (i % 2 == 1 ? a[i] : 0);
		} else {
			dc[i] = (i % 2 == 0 ? a[i] : 0);
		}
	}
	for (int i = 1; i <= N; ++i ) { dc[i] += dc[i - 1]; }

	for (int q = 0; q < Q; ++q) {
		ll X = x[q];
		int l = 1, r = N;
		while (r - l > 1) {
			int mid = (l + r) / 2;
			int tl = mid, tr = (N - mid + 1) / 2 + mid - 1;
			if ((abs(a[tl - 1] - X) > abs(a[tl] - X)) && (abs(a[tl - 1] - X) > abs(a[tr] - X))) {
				l = mid;
			} else {
				r = mid;
			}
		}
		int idx = (N - l + 1) / 2 + l;
		ll res = dc[l - 1] + dr[idx];
		cout << res << endl;
	}

	return 0;
}


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

using namespace std;

int n, m, deg[100010] = {0};
struct edge {
	int v, next;
}e[100010 << 1];
int head[100010], cnt = 0;
void adde(int u, int v) {
	e[cnt].v = v;
	e[cnt].next = head[u];
	head[u] = cnt++;
}

int d4[100010], d6[100010];
bool solve() {
	d4[0] = d6[0] = 0;
	for(int i = 1; i <= n; ++i) {
		if(deg[i] & 1) return false;
		if(deg[i] >= 4) d4[++d4[0]] = i;
		if(deg[i] >= 6) d6[++d6[0]] = i;
	}
	
	if(d6[0]) return true;
	if(d4[0] >= 3) return true;
	if(d4[0] != 2) return false;
	
	int ret = 0;
	for(int i = head[d4[1]], u, v; ~i; i = e[i].next) {
		u = e[i].v; v = d4[1];
		while(deg[u] == 2) {
			int temp = e[head[u]].v != v ? e[head[u]].v : e[e[head[u]].next].v;
			v = u;
			u = temp;
		}
		if(u == d4[2]) ++ret;
	}
	return ret == 2;
}

int main() {
	memset(head, -1, sizeof head);
	
	scanf("%d%d", &n, &m);
	for(int i = 1, u, v; i <= m; ++i) {
		scanf("%d%d", &u, &v);
		adde(u, v);
		adde(v, u);
		++deg[u]; ++deg[v];
	}
	
	puts(solve() ? "Yes" : "No");
	
	return 0;
}

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

#define _GLIBCXX_DEBUG
#define all(v) (v).begin(),(v).end()

using namespace std;

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

const ll LINF=1LL<<60;
const int INF=1<<29;
const int MOD=1e9+7;

template<typename T> bool chmax(T &a,const T b){if(a < b){a=b; return true;} return false;}
template<typename T> bool chmin(T &a,const T b){if(a > b){a=b; return true;} return false;}


int main(){
    int n; cin >> n;
    vi a(n);
    for(auto &x : a) cin >> x;
    ll ans=0;
    for(int i=1; i<n; i++){
        int up=max(a[i-1]-a[i], 0);
        a[i]+=up;
        ans+=up;
    }
    cout << ans << endl;
    return 0;
}

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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, n) for (int i = 1; i <= (int)(n); i++)
#define all(v) v.begin(), v.end()
using ll = long long;
using pi = pair<int, int>;
using pl = pair<ll, ll>;
using vi = vector<int>;
using vii = vector<vi>;
using vl = vector<ll>;
using vll = vector<vl>;

int main() {
	int n,q=0,d=0;
	ll cnt = 0;
	cin >> n;
	vector<int>que(n);
	rep(i, n) { 
		cin >> q;
		que[i] = q;
		cnt += q;
	}
	int m;
	cin >> m;
	rep(i, m) {
		cin >> q >> d;
		cout << cnt - que[q - 1] + d << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n)  for(long long i=0;i<(long long)(n);i++)
#define REP(i,k,n) for(long long i=k;i<(long long)(n);i++)
#define all(a) a.begin(),a.end()
#define pb push_back
#define eb emplace_back
#define lb(v,k) (lower_bound(all(v),k)-v.begin())
#define ub(v,k) (upper_bound(all(v),k)-v.begin())
#define fi first
#define se second
typedef long long ll;
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll> PP;
typedef multiset<ll> S;
typedef priority_queue<ll> PQ;
typedef priority_queue<P,vector<P>,greater<P>> SPQ;
using vi=vector<ll>;
using vvi=vector<vector<ll>>;
const ll inf=1001001001001001;
const int INF=1001001001;
const int mod=1000000007;
const double pi=3.14159265358979323846;
bool chmin(auto &a,auto b){if(a>b){a=b;return true;}return false;}
bool chmax(auto &a,auto b){if(a<b){a=b;return true;}return false;}
void outvi(vi v){rep(i,v.size()){if(i)cout<<' ';cout<<v[i];}cout<<endl;}
void outvvi(vvi v){rep(i,v.size()){rep(j,v[i].size()){if(j)cout<<' ';cout<<v[i][j];}cout<<endl;}}
int main(){
    ll n,k,ans=0;cin>>n>>k;
    vi a(3);
    rep(i,3)cin>>a[i];
    vi v(n);
    string t;cin>>t;
    rep(i,n){
        if(t[i]=='s')v[i]=0;
        else if(t[i]=='p')v[i]=1;
        else v[i]=2;
    }
    rep(i,k){
        for(ll j=i;j<n;j+=k){
            ans+=a[v[j]];
            if(j>=k){
                if(v[j-k]==v[j]){
                    ans-=a[v[j]];
                    v[j]=3;
                }
            }
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 1280
// https://atcoder.jp/contests/dp/tasks/dp_d

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define em emplace_back
#define test ll t;cin>>t;while(t--)
#define M 1000000007
#define input ll x;cin >> x
ll solve(ll n, ll w, ll weight[], ll value[]);
ll power(ll a, ll b)
{
	ll res = 1;
	a = a % M;
	while (b > 0)
	{
		if (b & 1)
		{
			res = (res * a) % M;
			b--;
		}
		a = (a * a) % M;
		b >>= 1;
	}
	return res;
}
ll fermat_inv(ll y) { return power(y, M - 2); }
ll gcd(ll a, ll b) { return (b == 0) ? a : gcd(b, a % b); }

int main () {
	ios_base::sync_with_stdio(false); 
    cin.tie(NULL);
	ll n, w;
	cin >> n >> w;
	ll weight[n], value[n];
	for (size_t i = 0; i < n; i++)
	{
		cin >> weight[i] >> value[i];
	}

	ll sol = solve(n, w, weight, value);
	cout << sol;
}

ll solve(ll n, ll w, ll weight[], ll value[]){
	ll dp[n + 1][w + 1];
	for (size_t i = 0; i <= n; i++)
	{
		dp[i][0] = 0;
	}
	for (size_t i = 0; i <= w; i++)
	{
		dp[0][i] = 0;
	}
	for (size_t i = 1; i <= n; i++)
	{
		for (size_t j = 1; j <= w; j++)
		{
			if(weight[i-1]<=j){
				dp[i][j] = max(dp[i - 1][j] , value[i - 1] + dp[i - 1][j - weight[i-1]]);
			}
			else
				dp[i][j] = dp[i - 1][j];
		}
	}
	return dp[n][w];
}

Measured memory_bytes: 82464
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <cmath>
#include <climits>
#include <cassert>
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <string>
#include <list>
#include <bitset>
#include <vector>
using namespace std;

#define I64d_OJ

//#ifdef I64d_OJ
//#define LL __int64
//#endif // I64d_OJ
#ifdef I64d_OJ
#define LL long long
#endif // I64d_OJ

typedef unsigned LL ULL;
typedef unsigned uint;
typedef pair<int,int> pii;
typedef pair<double,double> pdd;
typedef pair<LL,LL> pLL;
typedef vector<int> vi;

inline int read(){
    int x=0,f=1;
    char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-') f=-f; ch=getchar();}
    while(ch>='0'&&ch<='9'){x=x*10+ch-'0'; ch=getchar();}
    return x*f;
}

#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
#define ls rt<<1
#define rs rt<<1|1
#define MID(a,b) (((LL)(a)+(LL)(b))>>1)
#define absx(a) ((a)<0?-(a):(a))
#define MK(a,b) make_pair(a,b)
#define PB(a) push_back(a)
#define lowbit(x) ((x)&-(x))

#define lc c[x][0]
#define rc c[x][1]

template< typename T >
inline void Max(T &a,T &b){if(a<b) a=b;}
template< typename T>
inline void Min(T &a,T &b){if(a>b) a=b;}

const double pi=(double)acos(-1.0);
const double eps=(double)1e-8;
const int INF = (int) 0x3f3f3f3f;
const int MOD = (int) 1e9+7;
const int MAXN =(int) 1e5+10;
const int MAXM = (int) 3e6+10;

///--------------------START-------------------------
int A,B,X,Y,C;
int p[MAXN],q[MAXN],r[MAXN];
int ans[MAXN<<1];

void work(){
    scanf("%d%d%d%d%d",&X,&Y,&A,&B,&C);
    for(int i=1;i<=A;i++) scanf("%d",&p[i]);
    for(int i=1;i<=B;i++) scanf("%d",&q[i]);
    for(int i=1;i<=C;i++) scanf("%d",&r[i]);
    sort(p+1,p+1+A);
    sort(q+1,q+1+B);
    sort(r+1,r+1+C);
    int anscnt=0;
    LL ANS=0,tmpans=0;
    for(int i=0;i<X;i++) ans[++anscnt]=p[A-i];
    for(int i=0;i<Y;i++) ans[++anscnt]=q[B-i];
    sort(ans+1,ans+1+anscnt);
    for(int i=1;i<=anscnt;i++) tmpans+=ans[i];
    ANS=tmpans;
    int mi=min(C,X+Y);
    LL x=0,y=0;
    for(int i=1;i<=mi;i++){
        x+=ans[i];
        y+=r[C-i+1];
        ANS=max(ANS,tmpans-x+y);
    }
    printf("%lld\n",ANS);
}

///--------------------END-------------------------
int main(){
#ifdef NNever
//freopen("data.in","r",stdin);
///freopen("out.txt","w",stdout);
#endif // NNever
    work();
    return 0;
}





Measured memory_bytes: 2176
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        String input = scan.nextLine();
        
        char[] input_char = input.toCharArray();
        
        char current_char = input_char[0];
        int count = 0;
        for (int i=1;i<input_char.length;i++) {
            if (input_char[i]!=current_char) {
                count++;
                current_char = input_char[i];
            }
        }
        
        System.out.println(count);
    }
}


Measured memory_bytes: 13512
import java.util.*;

public class Main {
    public static void main(String[] args){
        Scanner sc=new Scanner(System.in);
        int N=sc.nextInt();

        ArrayList<Integer>[] o=new ArrayList[N];
        ArrayList<Integer>[] w=new ArrayList[N];
        for(int i=0;i<N;i++){
            o[i]=new ArrayList<>();
            w[i]=new ArrayList<>();
        }

        for(int i=0;i<N-1;i++){
            int u=sc.nextInt();
            int v=sc.nextInt();
            int a=sc.nextInt();
            o[u-1].add(v-1);
            w[u-1].add(a);
            o[v-1].add(u-1);
            w[v-1].add(a);
        }
        char[] result=new char[2*N];
        boolean isEven=true;

        Stack<Integer> q=new Stack<>();
        q.add(0);
        Stack<Integer> s=new Stack<Integer>();
        s.add(0);
        Stack<Boolean> bool=new Stack<Boolean>();
        bool.add(true);
        int pos=0;
        int index=0;
        result[0]='0';
        while(q.size()!=0){
            if(result[o[pos].get(index)*2]==0){
                q.add(pos);
                s.add(index);
                bool.add(isEven);
                if((w[pos].get(index)%2==1)){
                    isEven=!isEven;
                }
                pos=o[pos].get(index);
                index=0;
                if(isEven){
                    result[pos*2]='0';
                }else{
                    result[pos*2]='1';
                }
                continue;
            }

            index++;
            if(index==o[pos].size()){
                index=s.pop();
                pos=q.pop();
                isEven=bool.pop();
            }

        }


        for(int i=0;i<N;i++){
            result[2*i+1]='\n';
        }
        System.out.print(new String(result));

    }
    static boolean isMonth(int a){
        return a>0&&a<13;
    }

}


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

int main()
{
  int n;
  bool ans = 1;
  cin >> n;
  vector<int> vec(n);
  for (int i = 0; i < n; i++)
    cin >> vec[i];
  sort(vec.begin(), vec.end());

  for (int i = 0; i < n - 1; i++)
  {
    if (vec[i] == vec[i + 1])
    {
      ans = 0;
      break;
    }
  }
  if (ans)
    cout << "YES" << endl;
  else
    cout << "NO" << endl;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
#define itn int
#define int long long
#define mod 1000000007
#define INFi 2147483647
#define INFl 9223372036854775807LL
#define fi first
#define se second
#define be begin()
#define en end()
#define re reverse
#define Set setprecision 
int abs(int a,int b){
    return max(a,b)-min(a,b);
}
int gcd(int a,int b){//最大公約数
  int c=a%b;
  while(true){
    if(c==0) break;
    a=b;
    b=c;
    c=a%b;
  }
  return b;
}
int lcm(int a,int b){//最小公倍数
  return (a*b)/gcd(a,b);
}
signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);    
    int a,b,d;
    int c=0;
    cin>>a>>b;
    for(int i=0;i<b;i++){
      cin>>d;
      c+=d;
    }
    if(c>=a) cout<<"Yes";
    else cout<<"No";
    cout<<"\n"; 
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
using namespace std;
int N;
vector<int> v;
int main() {
	cin >> N;
	for (int i = 0; i < N; ++i) {
		int a;
		cin >> a;
		v.push_back(a);
	}
	sort(v.begin(), v.end());
	int minV = 0;
	for (int i = -100; i <= 100; ++i) {
		int temp = 0;
		for (int j = 0; j < N; ++j) {
			temp += (i - v[j])*(i - v[j]);
		}
		if (i == -100) minV = temp;
		else minV = min(minV, temp);
	}
	cout << minV << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using lint = long long int;
using pint = pair<int, int>;
using plint = pair<lint, lint>;
#define FOR(i, begin, end) for(int i=(begin),i##_end_=(end);i<i##_end_;i++)
#define IFOR(i, begin, end) for(int i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--)
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
template<typename T> ostream &operator<<(ostream &os, const vector<T> &vec){ os << "["; for (auto v : vec) os << v << ","; os << "]"; return os; }
template<typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &pa){ os << "(" << pa.first << "," << pa.second << ")"; return os; }
template<typename T> bool mmin(T &m, const T q) { if (m > q) {m = q; return true;} else return false; }
#define dbg(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ") " << __FILE__ << endl;

constexpr lint INF = 1LL << 60;
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    cin >> N;
    vector<plint> LR(N);
    REP(i, N) cin >> LR[i].first >> LR[i].second;
    sort(LR.begin(), LR.end(), [](plint l, plint r) { return l.first + l.second > r.first + r.second; });

    vector<pint> w(N, pint(N / 2, N / 2));
    REP(i, N / 2)
    {
        w[i] = make_pair(i, i + 1);
        w[N - 1 - i] = make_pair(i + 1, i);
    }
    vector<lint> dp(N + 1, INF);
    dp[0] = 0;
    REP(i, N)
    {
        IREP(j, i + 1)
        {
            mmin(dp[j + 1], dp[j] + LR[i].first * w[j].first + LR[i].second * w[j].second);
            dp[j] += LR[i].first * w[N - 1 - i + j].first + LR[i].second * w[N - 1 - i + j].second;
        }
    }
    cout << *min_element(dp.begin(), dp.end()) << endl;
}


Measured memory_bytes: 3808
def main():
    N = int(input())
    A = [int(i) for i in input().split()]
    cnt_minus = 0
    zero_idx = []
    for i, a in enumerate(A):
        if a < 0:
            cnt_minus += 1
        elif a == 0:
            zero_idx.append(i)
    flag = False
    for z in zero_idx:
        if (0 < z and A[z-1] < 0) or (z < N - 1 and A[z+1] < 0):
            flag = True

    ans = 0
    if cnt_minus % 2 == 0:
        ans = sum(abs(a) for a in A)
    elif flag:
        ans = sum(abs(a) for a in A)
    else:
        ans = sum(abs(a) for a in A) - min(abs(a) for a in A) * 2
    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 64624
/**
 *   @FileName	a.cpp
 *   @Author	kanpurin
 *   @Created	2020.08.12 01:21:27
**/

#include "bits/stdc++.h" 
using namespace std; 
typedef long long ll;

int main() {
    int h,w,k;cin >> h >> w >> k;
    vector<string> s(h);
    int start_x,start_y;
    for (int i = 0; i < h; i++) {
        cin >> s[i];
        for (int j = 0; j < w; j++) {
            if (s[i][j] == 'S') {
                start_x = i;
                start_y = j;
            }
        }
    }
    int dx[] = {0,1,0,-1};
    int dy[] = {1,0,-1,0};
    queue<pair<int,int>> que;
    que.push({start_x,start_y});
    vector<vector<int>> dist(h,vector<int>(w,-1));
    dist[start_x][start_y] = 0;
    int ans = min({start_x,start_y,h-1-start_x,w-1-start_y});
    while(!que.empty()) {
        auto p = que.front();
        que.pop();
        int nx = p.first;
        int ny = p.second;
        for (int i = 0; i < 4; i++) {
            int x = dx[i] + nx;
            int y = dy[i] + ny;
            if (x >= 0 && x < h && y >= 0 && y < w && s[x][y] == '.' && dist[x][y] == -1) {
                dist[x][y] = dist[nx][ny] + 1;
                ans = min({ans,x,y,h-1-x,w-1-y});
                if (dist[x][y] < k) {
                    que.push({x,y});
                }
            }
        }
    }
    cout << (ans + k - 1) / k + 1 << endl;
    return 0;
}


Measured memory_bytes: 6932