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

#define TASKNAME ""

using namespace std;

const ll INF = 1e9 + 7;
const ll MAXN = 1e6 + 7;
const double EPS = 1e-8;

vector <vector <pair <ll, ll> > > gr;
ll n, m;

void dfs(ll v, ll t, vector <ll> &d, vector <ll> &w) {
    if (w[v] != -1) {
        return;
    }
    if (v == t) {
        w[v] = 1;
        return;
    }
    w[v] = 0;
    for (auto e : gr[v]) {
        ll u = e.first, r = e.second;
        if (d[u] + r == d[v]) {
            dfs(u, t, d, w);
            w[v] = (w[v] + w[u]) % INF;
        }
    }
}

void dijkstra(ll s, vector <ll> &d, vector <ll> &w) {
    d.resize(n, INF * INF);
    w.resize(n, -1);
    d[s] = 0;
    set <pair <ll, ll> > q;
    q.insert({d[s], s});
    while (!q.empty()) {
        ll v = q.begin()->second;
        q.erase(q.begin());
        for (auto e : gr[v]) {
            ll u = e.first, r = e.second;
            if (d[u] > d[v] + r) {
                q.erase({d[u], u});
                d[u] = d[v] + r;
                q.insert({d[u], u});
            }
        }
    }
    for (ll i = 0; i < n; i++) {
        dfs(i, s, d, w);
    }
}

int main() {
    #ifdef MY
        freopen("input.txt", "r", stdin);
        //freopen("output.txt", "w", stdout);
    #else
        //freopen(TASKNAME".in", "r", stdin);
        //freopen(TASKNAME".out", "w", stdout);
        ios_base::sync_with_stdio(false);
        cin.tie(0);
        cout.tie(0);
    #endif // MY
    ll s, t;
    cin >> n >> m >> s >> t;
    s--, t--;
    gr.resize(n);
    for (ll i = 0; i < m; i++) {
        ll v, u, w;
        cin >> v >> u >> w;
        v--, u--;
        gr[v].push_back({u, w});
        gr[u].push_back({v, w});
    }
    vector <ll> ds, ws, dt, wt;
    dijkstra(s, ds, ws);
    dijkstra(t, dt, wt);
//    for (int i = 0; i < n; i++) {
//        cout << ws[i] << " ";
//    }
//    cout << "\n";
    ll res = ws[t] * wt[s] % INF;
    ll all = ds[t];
    for (ll i = 0; i < n; i++) {
        if (ds[i] + dt[i] != all) continue;
        if (ds[i] == dt[i]) {
            //cout << ws[i] << " " << wt[i] << "\n";
            res = (res - ws[i] * wt[i] % INF * ws[i] % INF * wt[i] % INF + INF) % INF;
        }
    }
    for (ll v = 0; v < n; v++) {
        for (auto e : gr[v]) {
            ll u = e.first, w = e.second;
            if (ds[v] + dt[u] + w != all) continue;
            if (w > abs(dt[u] - ds[v])) {
                res = (res - ws[v] * wt[u] % INF * ws[v] % INF * wt[u] % INF + INF) % INF;
            }
        }
    }
    cout << res;
}


Measured memory_bytes: 21232
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<string>
using namespace std;
bool FF[1000002];
int main(){

	for(int i=3;i<1000001;i+=2){FF[i]=true;
		for(int j=3;j*j<=i;j+=2)
			if(i%j==0){FF[i]=false;break;}
}
	FF[2]=true;
	int Q,M;
	while(1){
		cin>>Q>>M;if(Q==0&&M==0)break;

		int D[35]={};
		bool F[1000002];
		for(int i=0;i<Q;i++)
			cin>>D[i];
		int P=0;
		for(int i=0;i<=M;i++)
			F[i]=false;

		for(int i=0;i<Q;i++){
			for(int j=0;j<=M;j++)
			{
				
				if(j==D[i])F[j]=true;
				if(j-D[i]>0&&F[j-D[i]]==true)F[j]=true;
				if(F[j]==true&&FF[j]==true)P=j;
			}}
		if(P>0)cout<<P<<endl;
		else cout<<"NA"<<endl;
	}
	return 0;
}

Measured memory_bytes: 3108
#include<iostream>

#include<cstring>

using namespace std;

#define LENMIN 3
#define LENMAX 99

char S[LENMAX + 1];

bool isPalin(char* start, char* end){
	for(end--; start < end; start++, end--){
		if(*start != *end){
			return false;
		}
	}
	return true;
}

int main(void){
	cin >> S;
	const int N = strlen(S);
	
	if( !isPalin(S, &S[(N-1)/2]) ){//条件2
		cout << "No" << endl;
		return 0;
	}
	if( !isPalin(&S[((N+3)/2) - 1], &S[N]) ){//条件3
		cout << "No" << endl;
		return 0;
	}
	if( !isPalin(S, &S[N]) ){//条件1
		cout << "No" << endl;
		return 0;
	}
	
	cout << "Yes" << endl;
	
	return 0;
}


Measured memory_bytes: 256
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define INF 0x6fffffff
#define INFL 0x6fffffffffffffffLL

int main() {
	ll		a,b,h,i,j,k,l,m,n,x,y;
	ll		ans = 0;
	string	s;
	cin >> n >> k >> s;
	char	c = s[0];
	x = 0;
	for(i=1;i<n;i++) {
		if (c != s[i]) {
			for(;i<n;i++) {
				if (c == s[i]) break;
				s[i] = c;
			}
			x++;
		}
		if (x==k) break;
	}
	if (s[0] == 'L') i=1;
	else i=0;
	if (s[n-1] == 'R') n=n-1;
	for(;i<n;i++) {
		if (s[i]=='L') {
			if (s[i-1]=='L') ans++;
		} else {
			if (s[i+1]=='R') ans++;
		}
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 3704
#include <iostream>
#include <string>
#include <cctype>

using namespace std;

int main()
{
	string s;

	while (true) {
		unsigned int ans = 0;
		getline(cin, s);
		for (unsigned int i = 0; i < s.length(); ++i) {
			ans += s[i] - '0';
		}
		if (ans == 0) break;
		cout << ans << endl;
	}
	return 0;
}


Measured memory_bytes: 3212
#include <algorithm>
#include <cstdio>
#include <deque>
#include <iomanip>
#include <iostream>
#include <queue>
#include <stack>
#include <utility>
#include <vector>
using std::cerr;
using std::cin;
using std::cout;
using std::endl;

void OutputError(std::string s) {
  cerr << "\033[93m" << s << "\033[m" << endl;
  return;
}

int main(void) {
  cout << std::fixed << std::setprecision(10);
  cin.tie(0);
  std::ios::sync_with_stdio(false);

  long long a, b, c;
  cin >> a >> b >> c;

  if (a % 2 == 0 || b % 2 == 0 || c % 2 == 0) {
    cout << 0 << endl;
    exit(0);
  } else {
    long long x = b * c, y = c * a, z = a * b;
    cout << std::min({x, y, z});
    exit(0);
  }

  return 0;
}


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

int main()
{
    ll x,y,a,b,c;cin>>x>>y>>a>>b>>c;
    
    ll p[a],q[b],r[c],s[x+y+c];
    for(ll i=0;i<a;++i){
        cin>>p[i];
    }
    for(ll i=0;i<b;++i){
        cin>>q[i];
    }
    for(ll i=0;i<c;++i){
        cin>>r[i];
    }
    
    sort(p, p + a, greater< ll >());
    sort(q, q + b, greater< ll >());

    for(ll i=0;i<x;++i){
        s[i]=p[i];
    }
    for(ll i=0;i<y;++i){
        s[x+i]=q[i];
    }
    for(ll i=0;i<c;++i){
        s[x+y+i]=r[i];
    }
    sort(s, s + x+y+c, greater< ll >());
    
    ll ans=0;
    for(ll i=0;i<x+y;++i){
        ans+=s[i];
    }
    
    cout<<ans<<endl;
}

Measured memory_bytes: 4736
#include <iostream>
#include <iomanip>
#include <math.h>
using namespace std;
int main(){
	int n;
	cin >> n;
	for(int i=0;i<n;i++){
		double x1,x2,x3,y1,y2,y3;
		cin >> x1 >> y1 >> x2 >> y2 >> x3 >> y3;
		double c1 = 2.0*(x1-x2);
		double c2 = 2.0*(y1-y2);
		double c3 = 2.0*(x1-x3);
		double c4 = 2.0*(y1-y3);
		double c5 = x1*x1 + y1*y1;
		double c6 = x2*x2 + y2*y2;
		double c7 = x3*x3 + y3*y3;
		double px = (c4*(c5-c6)-c2*(c5-c7))/(c1*c4-c2*c3);
		double py;
		if(c2!=0.0) py = (c5-c6-c1*px)/c2;
		else py = (c5-c7-c3*px)/c4;
		double r = sqrt((px-x1)*(px-x1)+(py-y1)*(py-y1));
		cout << fixed << setprecision(3) << px << " " << py << " " << r << endl;
	}
}

Measured memory_bytes: 1288
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<tuple>
#include<map>
#include<queue>
#include<math.h>
#include<numeric>
#include<iomanip>
#define rep(i, n) rep2(i,0,n)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define PI acos(-1);
typedef long long ll;
using namespace std;
const int MOD = 1000000007;
//scanf("%d", &a); '\n'; cout << fixed << setprecision(10);
 
int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n,m;
	cin >> n>>m;
	rep(i, m) {
		int a;
		cin >> a;
		n -= a;
	}
	cout << max(-1, n);
}

Measured memory_bytes: 3644
#include <iostream>
#include <algorithm>
#define rep(i,a,b) for(int i=a; i< (int)(b); ++i)
#define ALL(x) (x).begin(),(x).end()
#define rALL(x) (x).rbegin(),(x).rend()
typedef long double ld;
using ll=long long;
using namespace std;
const auto mod=1e9+7;


int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  int k; cin >> k;
  int sum=0;
  rep(i,1,k+1){
  	rep(j,1,k+1){
  		rep(l,1,k+1){
  			int res = __gcd(i,j);
  			sum+=__gcd(res,l);
  		}
  	}
  }
  cout << sum << endl;
 }

Measured memory_bytes: 3648
import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {

        Scanner scanner = new java.util.Scanner(System.in);

        // 入力が取得できる
        int N = scanner.nextInt();

        List<Work> l = new ArrayList<Work>();

        for (int i=1; i <= N; i++) {

            int w = scanner.nextInt();
            int e = scanner.nextInt();

            Work work = new Work(w, e);
            l.add(work);
        }

        l.sort(new Comparator<Work>() {
            @Override
            public int compare(Work o1, Work o2) {
                return o1.endtime - o2.endtime;
            }
        });

        int ws =0;

        for (Work work : l) {

            ws = ws + work.work;

            if (ws > work.endtime) {
                System.out.print("No");
                System.exit(0);
            }
        }

        System.out.print("Yes");
        scanner.close();
    }

    static class Work {

       public int work;
       public int endtime;

       public Work(int work, int endtime) {
           this.work = work;
           this.endtime = endtime;
       }

    }
}

Measured memory_bytes: 105404
#include <cstdio>
#include <cstdint>
#include <vector>
#include <algorithm>
#include <utility>
#include <set>
#include <string>
#include <tuple>

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

  if (A <= 5) {
    puts("0");
  } else if (A <= 12) {
    printf("%d\n", B/2);
  } else {
    printf("%d\n", B);
  }
}


Measured memory_bytes: 128
import java.util.Scanner;
 public class Main{
   public static void main(String[]args){
     Scanner sc = new Scanner(System.in);
     int a = sc.nextInt();
     String s = sc.next();
     if(a>=3200){
       System.out.println(s);
     }else{
       System.out.println("red");
     }
   }
 }

Measured memory_bytes: 21204
import java.util.*;
 
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int [] ans = new int [N+1];
        int tmp = 0;
        
        for(int i=1; i<N; i++){
            for(int j=1; j<N; j++){
                for(int k=1; k<N ; k++){
                    tmp = i*i+j*j+k*k+i*j+j*k+k*i;
                    if(tmp>N){
                        break;
                    }else{
                        ans[tmp]++;
                    }
                }
            }
        }
        
        for(int i=1; i<=N; i++){
            System.out.println(ans[i]);
        }
        
    }
}

Measured memory_bytes: 38956
# -*- coding: utf-8 -*-
"""
Created on Sun Jun  9 21:02:21 2019

@author: hisaki
"""

N = int(input())

W = list(map(int,input().split()))

sum_W = sum(W)
min_abs = 0;
for i in range(N):
    s1=0
    for k in range(i):
        s1 += W[k]
    s2 = sum_W -s1
    
    if i == 0:
        min_abs = abs(s1-s2)
    elif abs(s1-s2)<min_abs:
        min_abs = abs(s1-s2)

print (min_abs)




Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <map>
#include <algorithm>
#include <iomanip>
#include <queue>
#include <utility>
#include <set>
#include <unordered_set>
#include <stack>
#include <iterator>
#include <random>
#include <fstream>
#include <chrono>
#include <math.h>
using namespace std;
#define int long long
int32_t main()
{
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    // Нужно набрать один вроде
    int x, n;
    cin >> x >> n;
    int p[101];
    for(int i = 0; i < n; i++) {
        int tt;
        cin >> tt;
        p[tt]=1;
    }
    int diff,ans = 1e18;
    for(int i = 0; i <= 101; i++){
        if(p[i] == 1)
            continue;
        if(abs(x-i) < diff)
        {
            diff = abs(x-i);
            ans = i;
        }
    }
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 3196
sx, sy, tx, ty = map(int, input().split())
dist_x, dist_y = abs(tx-sx), abs(ty-sy)

# print("dist_x: {}, dist_y: {}".format(dist_x, dist_y))

path1 = ""
path2 = ""
path3 = ""
path4 = ""

if dist_x == 0 and dist_y == 0:
    pass
elif dist_x == 0 and dist_y != 0:
    path1 += "D"*disy_y if sy > ty else "U"*dist_y
    path2 += "U"*disy_y if sy > ty else "D"*dist_y
    path3 += "D"*disy_y if sy > ty else "U"*dist_y
    path4 += "U"*disy_y if sy > ty else "D"*dist_y
elif dist_x != 0 and dist_y == 0:
    path1 += "L"+dist_x if sx > tx else "R"*dist_x
    path2 += "R"+dist_x if sx > tx else "L"*dist_x
    path3 += "L"+dist_x if sx > tx else "R"*dist_x
    path4 += "R"+dist_x if sx > tx else "L"*dist_x
else:
    path1 += "D"*disy_y if sy > ty else "U"*dist_y
    path1 += "L"+dist_x if sx > tx else "R"*dist_x

    path2 += "U"*disy_y if sy > ty else "D"*dist_y
    path2 += "R"+dist_x if sx > tx else "L"*dist_x

    path3 += "R" if sx > tx else "L"
    path3 += "D"*(disy_y+1) if sy > ty else "U"*(dist_y+1)
    path3 += "L"*(disy_x+1) if sx > tx else "R"*(dist_x+1)
    path3 += "U" if sy > ty else "D"

    path4 += "L" if sx > tx else "R"
    path4 += "U"*(disy_y+1) if sy > ty else "D"*(dist_y+1)
    path4 += "R"*(disy_x+1) if sx > tx else "L"*(dist_x+1)
    path4 += "D" if sy > ty else "U"

print(path1+path2+path3+path4)


Measured memory_bytes: 3188
using System;
using System.Collections.Generic;
class Solve{
    public long a;
    public long b;
    public long h;
    public Solve(){}
    public static int Main(){
        new Solve().Calc();
        return 0;
    }
    void Calc(){
        getinput();
        Console.WriteLine((a+b)*h/2);
    }
    void getinput(){
        a = int.Parse(Console.ReadLine());
        b = int.Parse(Console.ReadLine());
        h = int.Parse(Console.ReadLine());
    }    
}

Measured memory_bytes: 2776
package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func nextStr() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func main() {
	sc.Split(bufio.ScanWords)
	n := nextInt()
	k := nextInt()
	h := make([]int, n)
	for i := range h {
		h[i] = nextInt()
	}
	ans := 0
	//体力が大きいモンスターK体に必殺技を使う
	sort.Ints(h)
	for i := 0; i < n-k; i++ {
		ans += h[i]
	}
	fmt.Println(ans)
}

Measured memory_bytes: 4736
#include <iostream>
#include <vector>
#include <limits>
#include <algorithm>
using namespace std;

constexpr int64_t MIN = numeric_limits<int64_t>::min();

int main()
{
	int N;

	cin >> N;
	vector<int[5][2]> F(N);
	vector<int64_t[11]> P(N);

	for (int i = 0; i < N; ++i)
	{
		for (int j = 0; j < 5; ++j)
		{
			cin >> F[i][j][0] >> F[i][j][1];
		}
	}

	for (int i = 0; i < N; ++i)
	{
		for (int j = 0; j < 11; ++j)
		{
			cin >> P[i][j];
		}
	}

	int64_t max_b = MIN;
	for (int i = 1; i < 1 << 10; ++i)
	{
		int64_t b = 0;
		for (int j = 0; j < N; ++j)
		{
			int count = 0;
			for (int k = 0; k < 5; ++k)
			{
				int a = 2 * k;
				int b = 2 * k + 1;

				if (F[j][k][0] == 1 && (i & (1 << a)) != 0)
				{
					++count;
				}

				if (F[j][k][1] == 1 && (i & (1 << b)) != 0)
				{
					++count;
				}
			}

			b += P[j][count];
		}

		max_b = max(max_b, b);
	}

	cout << max_b << endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#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...);
}

#define pb             push_back
#define sz(x)          (int)((x).size())
#define all(x)         (x).begin(), (x).end()
#define rep(i, n)  	   for (int i = 0; i < n; ++i)
#define irep(i, a, b)  for (int i = a; i <= b; ++i)
#define repr(i, a, b)  for (int i = a; i >= b; --i)
#define iter(it, x)    for (auto it = x.begin(); it != x.end(); ++it)

using ll = long long;
using P = pair<int,int>;
using vi = vector<int>;
const char nl = '\n';
const int inf = 2e9;
const ll INF = (ll)2e18;
const ll mod = 1e9 + 7;
const int N = 2e6 + 15;

int main(){
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	int n;
	cin >> n;
	string s;
	vi ans(4, 0);
	string type[4] = {"AC", "WA", "TLE", "RE"};
	while (n--) {
		cin >> s;
		for (int i = 0; i < 4; ++i) {
			if (type[i] == s) ans[i]++;
		}
	}
	for (int i = 0; i < 4; ++i) {
		cout << type[i] << " x " << ans[i] << nl;
	}
    return 0;
}


Measured memory_bytes: 3652
#include<bits/stdc++.h>
using namespace std;
#define ll long long 
#define INF 999999999
#define rep(i,n) for(int i=0;i<n;i++)
const int MOD = 1000000007;

int main(){
  string s; cin >> s;
  int n=s.size();
  for(int i=0;i<n/2;i++){
     if(s[i] != s[n-1-i]){
        cout << "No" << endl;
        return 0;
     }
  }
  for(int i=0;i<n/4;i++){
     if(s[i] != s[(n-3)/2-i]){
        cout << "No" << endl;
        return 0;
     }
  }
  for(int i=0;i<n/4;i++){
     if( s[(n+1)/2+i] != s[n-1-i]){
        cout << "No" << endl;
        return 0;
     }
  }

  cout << "Yes" << endl;
}



Measured memory_bytes: 256
N,K = map(int,input().split())

grid = [[0]*(2*K+2) for i in range(2*K+2)]
for i in range(N):
    x,y,c = input().split()
    x,y = int(x),int(y)
    if c == 'W':
        x += K
    grid[y%(2*K)+1][x%(2*K)+1] += 1

for i in range(2*K+2):
    for j in range(2*K+1):
        grid[i][j+1] += grid[i][j]
for i in range(2*K+1):
    for j in range(2*K+2):
        grid[i+1][j] += grid[i][j]

def count(x1,x2,y1,y2):
    return grid[y1][x1] - grid[y1][x2] - grid[y2][x1] + grid[y2][x2]

ans = 0
for i in range(K):
    for j in range(K):
        tmp = count(j,j+K,i,i+K) + count(0,j,0,i) + count(j+K,2*K,0,i) +\
            count(0,j,i+K,2*K) + count(j+K,2*K,i+K,2*K)
        ans = max(ans, tmp, N-tmp)
print(ans)

Measured memory_bytes: 80988
#include <iostream>
using namespace std;
main() {
	int h, w;
	while (cin >> h >> w, h!=0||h!=w) {
		for (int i=0; i<h; i++) {
			for (int j=0; j<w; j++) cout << "#";
			cout << endl;
		}
		cout << endl;
	}
}

Measured memory_bytes: 3100
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <climits>
#include <cfloat>
using namespace std;

const int MAX = 100000;
const int INF = INT_MAX / 2;

void solve(const vector<pair<int, int> >& attack, vector<int>& cost)
{
    cost.assign(MAX+1, INF);
    cost[0] = 0;

    int n = attack.size();
    for(int i=0; i<MAX; ++i){
        for(int j=0; j<n; ++j){
            int k = i + attack[j].second;
            if(k > MAX)
                k = MAX;
            cost[k] = min(cost[k], cost[i] + attack[j].first);
        }
    }

    for(int i=MAX; i>0; --i)
        cost[i-1] = min(cost[i-1], cost[i]);
}

int main()
{
    for(;;){
        int n;
        cin >> n;
        if(n == 0)
            return 0;

        vector<int> hp(n);
        for(int i=0; i<n; ++i)
            cin >> hp[i];

        int m;
        cin >> m;
        vector<pair<int, int> > a; // 単体攻撃
        vector<pair<int, int> > b; // 全体攻撃
        for(int i=0; i<m; ++i){
            string s, target;
            int mp, damage;
            cin >> s >> mp >> target >> damage;
            if(target == "Single")
                a.push_back(make_pair(mp, damage));
            else
                b.push_back(make_pair(mp, damage));
        }

        vector<int> cost1, cost2;
        solve(a, cost1);
        solve(b, cost2);

        long long ret = INF;
        for(int i=0; i<=MAX; ++i){
            long long tmp = cost2[i];
            for(int j=0; j<n; ++j)
                tmp += cost1[max(0, hp[j] - i)];
            ret = min(ret, tmp);
        }
        cout << ret << endl;
    }
}

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

#define rep(i,n) for (int i=0;i<(n);i++)
#define rep2(i,a,b) for (int i=(a);i<(b);i++)
#define all(a) (a).begin(),(a).end()

int calcDP(const vector<int>& w, int width) {
    int N = w.size();
    vector<vector<bool>> dp(N + 1, vector<bool>(width + 1));
    dp[0][0] = true;
    int ma = 0;
    rep(i, N) {
        rep(j, width + 1) {
            if (!dp[i][j]) continue;
            dp[i + 1][j] = true;
            if (j + w[i] <= width) {
                dp[i + 1][j + w[i]] = true;
            }
        }
    }
    rep(j, width + 1) {
        if (dp[N][j]) ma = max(ma, j);
    }
    return ma;
}

int main() {
    int N;
    while (cin >> N, N) {
        vector<int> r(N), w(N);
        rep(i, N) cin >> r[i] >> w[i];
        sort(all(r));
        reverse(all(r));
        sort(all(w));
        reverse(all(w));

        int sm_r = accumulate(all(r), 0);
        int sm_w = accumulate(all(w), 0);
        int Tr = max(sm_r, 2 * r[0]);
        int Tw = sm_w;

        if (2 * r[0] > sm_r) {
            int width = 2 * r[0] - sm_r;
            int ma_1 = calcDP(w, width);
            w.erase(w.begin());
            int ma_2 = calcDP(w, width);
            Tw -= min(ma_1, ma_2);
        }

        cout << Tr + Tw << endl;

        // int sm = 0;
        // int j = 0;
        // if (2 * r[0] > sm_r) {
        //     int width = 2 * r[0] - sm_r;
        //     cout << "width = " << width << endl;
        //     while (sm < width && j < N) {
        //         sm += w[j];
        //         j++;
        //     }
        // }
        //
        // int Tw = max(sm_w - sm, 2 * w[j]);
        //
        // cout << Tr << " " << Tw << " " << j << " " << sm << endl;
        //
        // cout << Tr + Tw << endl;
    }

}

Measured memory_bytes: 3224
#include <iostream>
#include <functional>
#include <algorithm>
#include <cmath>
#include <numeric>
#include <string>
#include <vector>
#include <array>
#include <memory>
#include <set>
#include <map>

using namespace std;

#define Get(ty,...) ty __VA_ARGS__;cins(__VA_ARGS__);
#define GetArray(ty,v,n) vector<ty> v(n);cin_arr(v,n);
#define ci cin
#define co cout
#define en endl;
#define Arr(f, arr,pred) f(arr.begin(),arr.end(),pred)
#define Arr2(f, arr) f(arr.begin(),arr.end())
#define ArrExpr(f, arr,expr) f(arr.begin(),arr.end(),[](auto x){return expr;})
#define Acc(init,arr,pred) accumulate(arr.begin(),arr.end(),init,pred)

void cins(){}

template<class Head,class... Tail>
void cins(Head& head,Tail&... tail) {
	cin >> head;
	cins(tail...);
}

template<class Arr>
void cin_arr(Arr& v,int n) {
	for (int i = 0; i < n; i++)
		cin >> v[i];
}



int main() {
	Get(int, n);
	GetArray(int, v, n);
	int count=0;
	for (int i = 1; i < v.size() - 1; i++) {
		if (
			(v[i - 1] < v[i]&& v[i] < v[i + 1]) 
			|| (v[i + 1] < v[i] && v[i] < v[i - 1]))
			count++;
	}
	co << count << en;
}




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

using namespace std;
using ll = long long;
#define REP(i, n) for (int i = 0; i < n; ++i)
#define ALL(v) v.begin(), v.end()

int main() {
  ll n, k;
  cin >> n >> k;
  vector<ll> v(n);
  REP(i, n) cin >> v[i];
  sort(ALL(v), greater<>());
  ll ans = 0;
  for (int i = k; i < n; ++i) {
    ans += v[i];
  }
  cout << ans << endl;
}


Measured memory_bytes: 1792
import sys
input = sys.stdin.readline
def ii(): return int(input())
def mi(): return map(int, input().rstrip().split())
def lmi(): return list(map(int, input().rstrip().split()))
def li(): return list(input().rstrip())
# template

# BEGIN CUT HERE
from queue import Queue
def bfs(field, sy, sx, wall, dir):
    h = len(field)
    w = len(field[0])
    dp = [[-1 for _j in range(w)] for _i in range(h)]
    q = Queue()

    dp[sy][sx] = 0
    q.put((sy, sx))
    
    dy = [1, -1, 0, 0, 1, 1, -1, -1]
    dx = [0, 0, 1, -1, 1, -1, 1, -1]
    def isin(x,y): return 0 <= y and y < h and 0 <= x and x < w
    
    while not q.empty():
        y, x = q.get()
        for k in range(dir):
            ny,nx = y+dy[k],x+dx[k]
            if not isin(nx, ny) or field[ny][nx] == wall:
                continue
            elif dp[ny][nx] != -1:
                continue
            dp[ny][nx] = dp[y][x] + 1
            q.put((ny,nx))
        
    return dp
    
# END CUT HERE

def ABC088_D():
    h, w = mi()
    s = [['' for _j in range(w)] for _i in range(h)]
    for i in range(h):
        s[i] = li()
    dp = bfs(s, 0, 0, '#', 4)
    if dp[h - 1][w - 1] < 0:
        print(-1)
    else:
        cnt = 0
        for i in range(h):
            for j in range(w):
                cnt += s[i][j] == '.'
        print(cnt - (dp[h - 1][w - 1] + 1)) # 0-indexed
# verified on 2019/06/13
# Python3:29ms https://atcoder.jp/contests/abc088/submissions/5898220
# Pypy3:239ms https://atcoder.jp/contests/abc088/submissions/5898207
# https://atcoder.jp/contests/abc088/tasks/abc088_d

def ATC002_A():
    R, C = mi()
    sy, sx = mi()
    gy, gx = mi()
    s = [['' for _j in range(C)] for _i in range(R)]
    for i in range(R):
        s[i] = li()
    dp = bfs(s, sy-1, sx-1, '#', 4) # 0-indexed
    print(dp[gy-1][gx-1]) # 0-indexed

# グリッドでないbfs
def ABC126_D():
    N= ii()
    G = [[] for i in range(N)]
    for i in range(N-1):
        a, b, w = mi()
        a -= 1
        b -= 1
        G[a].append((b,w))
        G[b].append((a,w))
    dist = [-1 for _ in range(N)]
    que = Queue()
    for v in range(N):
        if dist[v] != -1:
            # v が探索済ならスルー
            continue
        dist[v] = 0
        que.put(v)
        while not que.empty():
            v = que.get()
            for nv,nw in G[v]:
                if dist[nv] == -1:
                    dist[nv] = dist[v] + nw
                    que.put(nv)
    for i in dist:
        if i % 2 == 0:
            print(0)
        else:
            print(1)
# verified on 2019/06/28
# Python3 https://atcoder.jp/contests/abc126/submissions/6141196


if __name__ == '__main__':
    # ABC088_D()
    # ATC002_A()
    ABC126_D()

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

int main(){
  int N;
  cin >> N;
  
  float p;
  if(N%2 == 0){
    p = (float)(N/2)/N;
    cout << p << endl;
  } else {
	p = (float)(N/2 + 1)/N;
    cout << p << endl;
  }
  
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0;i<n;i++)
typedef long long ll;

int main(){
    int n, q;
    cin >> n >> q;
    string s;
    cin >> s;
    vector<int> l(q+1), r(q+1);
    rep(i, q){
        cin >> l[i];
        cin >> r[i];
    }
    vector<int> ans(q, 0);
    vector<int> A(n);
    A[0] = 0;
    for(int i=1;i<n;i++){
        A[i] = A[i-1];
        if(s[i-1] == 'A' && s[i]=='C')  A[i] = A[i-1]+1;
    }

    rep(i, q){
        cout << A[r[i]-1] - A[l[i]-1] << endl;
    }

    return 0;
}

Measured memory_bytes: 2688
#include <iostream>
#include <cmath>
#include <string>
#include <algorithm>
#include <set>
#include <queue>
#include <stack>
#include <utility>
#include <tuple>
#include <random>
#include <map>
using namespace std;

const double pi = acos(-1);
#define nyan cout << "(=^•ω•^=)" << endl;
#define int long long
#define rep(i, n) for(int i = 0; i < n; i++)
#define loop while(true)
#define YN(f) f?cout<<"YES"<<endl:cout<<"NO"<<endl;
#define yn(f) f?cout<<"Yes"<<endl:cout<<"No"<<endl;

int n,a,b;

signed main(){
	cin>>n>>a>>b;
	int v=max((long long)0,a+b-n);
	cout<<min(a,b)<<" "<<v<<endl;
	return 0;
}

Measured memory_bytes: 764
from collections import defaultdict
N = int(input())
a = list(map(int,input().split()))
d = defaultdict(int)
for i in range(N):
  d[a[i]] += 1
ans = 0
for x in range(min(a), max(a)+1):
  ans = max(ans, d[x-1] + d[x] + d[x+1])
print(ans)

Measured memory_bytes: 19424
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<(n); ++i)
#define chmin(x,y) x = min(x,y)
#define chmax(x,y) x = max(x,y)
using namespace std;
typedef long long ll;
typedef pair<int, int> P; 
const int inf = 1<<21;
const ll INF = 1LL << 60;
const ll mod = 1e9+7;
const int dx[4] = {-1, 0, 1, 0};
const int dy[4] = {0, -1, 0, 1};

int h, w, k;
char s[15][10005];

int main() {
    cin >> h >> w >> k;
    rep(i, h)rep(j, w) cin >> s[i][j];
    int ans = inf;

    // bit全探索
    for(int bit=0; bit < 1<<h-1; ++bit){
        bool flag = true;
        vector<int> id(h);
        int g = 0;
        rep(i, h){
            id[i] = g;
            if (bit>>i & 1) ++g;
        }
        ++g;
        int cnts[15][10005]; // cnts[i][j]: idとj

        rep(i, g)rep(j, w) cnts[i][j] = 0;
        rep(i, h)rep(j, w) cnts[id[i]][j] += (s[i][j]-'0');

        int num = g-1;
        vector<int> now(g);
        rep(j, w){
            bool ff = true;
            rep(i, g) now[i] += cnts[i][j];
            rep(i, g) {
                if (now[i] > k){
                    ff = false;
                }
            }
            if (!ff) {
                num++;
                now = vector<int>(g);
                rep(i, g) now[i] += cnts[i][j];
                rep(i, g) {
                    if (now[i] > k){
                        flag = false;
                    }
                }
                if (!flag){
                    num = inf;
                    break;
                }
            }
            if (!flag) break;
        }
        chmin(ans, num);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 384
import java.util.Scanner;

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

        if(n.charAt(0)==n.charAt(2)){
            System.out.println("Yes");
        }else{
            System.out.println("No");
        }
    }
}


Measured memory_bytes: 22996
#include <bits/stdc++.h>
#define rep(i,n) for (ll i=1; i<=(n); i++)
using namespace std;
typedef long long ll;

int main(){
    double N; cin >> N;
    vector <pair<double,double>> A(N+1);
    vector <double> B(N+2);
    rep(i,N){
        double x; cin >> x;
        double y; cin >> y;
        A[i]=make_pair(x,y);
    }
    
    double num=1;
    double NUM=0;
    for (double i=1; i<=N-1; i++){
        num*=i;
        NUM+=i;
    }
    

    double sum=0;
    for (ll i=1; i<=N-1; i++){
        for (ll j=i+1; j<=N; j++){
            double sukosi=0;
            sukosi=sqrt((double)(A[i].first-A[j].first)*(A[i].first-A[j].first) +(double)(A[i].second-A[j].second)*(A[i].second-A[j].second));
            sum+=sukosi*(N-1)/NUM*num*(double)N;
        }
    }
    cout << fixed << setprecision(10) << sum/(double)(num*N) << endl;
    
}

Measured memory_bytes: 256
package main

import "fmt"

func main() {
	var h, w, n int
	fmt.Scan(&h, &w, &n)

	k := 0
	if h < w {
		k = w
	} else {
		k = h
	}

	i := 1
	for n > k*i {
		i++
	}
	fmt.Println(i)
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<ll, ll> Pl;
#define vi vector<int>
#define vl vector<long long>
#define vvi vector< vector<int> >
#define vvl vector< vector<ll> >
#define vp vector<P>
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define REPD(i, n) for (int i = (int)(n-1); i >= 0; i--)
#define FOR(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define FORD(i, a, b) for (int i = (int)(a); i >= (int)(b); i--)
#define INF 1e18
#define INFTY 1e9
const int mod = 1000000007;
#define SIZE_OF_ARRAY(array) (sizeof(array)/sizeof(array[0]))

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

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

//cout << fixed << setprecision(10) << y << endl;
struct edge {int to, cost;};
vector< vector<edge> > es;

int gcd(int a, int b) {
    int r = a % b;
    if (r == 0) return b;
    return gcd(b, r);
}

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


int main() {
    int n;
    cin >> n;
    vl a(n);
    REP(i, n) cin >> a[i];
    sort(a.begin(), a.end(), greater<ll>());
    ll res = a[0];
    int cnt = 1;
    FOR(i, 1, n-1) {
        if (cnt == n-1) break;
        res += a[i];
        cnt += 1;
        if (cnt == n-1) break;
        res += a[i];
        cnt += 1;
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 4844
#include<iostream>
#include<algorithm>
#include<string>
using namespace std;
int N,M,X,C[12],A[12][12],ans=0;
bool able=false;
void solve(bool f,int n,int flag){
	flag=flag*2+f;
	if(n==N){
		bool buy,res=true;
		int x[12]={0},money=0;
		for(int i=N-1;i>=0;i--){
			buy=flag%2;
			flag/=2;
			if(buy){
				money+=C[i];
				for(int j=0;j<M;j++){
					x[j]+=A[i][j];
				}
			}
		}
		for(int i=0;i<M;i++){
			if(x[i]<X){res=false;break;}
		}
		if(res){
			ans=min(ans,money);
			able=true;
		}
	}else{
		solve(0,n+1,flag);
		solve(1,n+1,flag);
	}
}
int main(){
	cin>>N>>M>>X;
	for(int i=0;i<N;i++){
		cin>>C[i];
		ans+=C[i];
		for(int j=0;j<M;j++)cin>>A[i][j];
	}
	solve(0,0,0);
	if(!able)ans=-1;
	cout<<ans;
	return 0;
}

Measured memory_bytes: 3636
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <algorithm>
#include <set>

// int max: 2 x 10^9, long long max: 9 x 10^18

using namespace std;

const int MAX = 510000;
const int MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main()
{
  COMinit();
  int s;
  cin >> s;

  if(s < 3){
    cout << 0;
    return 0;
  }

  int limit = s / 3;

  vector<long long> pattern(limit + 1, 1);

  for(int i=2; i<limit+1; i++){
    int amari = s - 3*i;

    pattern[i] = COM(amari+i-1, amari);
  }

  int result = 1;
  for(int i=2; i<limit+1; i++){
    result += pattern[i];
    result = result % MOD;
  }

  cout << result;

  return 0;
}

Measured memory_bytes: 15128
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>

using namespace std;

static const long long MOD = 1000000007LL;

static const int N_MAX = 200000;

static long long extgcd(long long a, long long b, long long &x, long long &y) {
    long long d = a;
    if (b != 0) {
        d = extgcd(b, a % b, y, x);
        y -= (a / b) * x;
    } else {
        x = 1;
        y = 0;
    }
    return d;
}


static long long modinv(long long a) {
    long long x, y;
    extgcd(a, MOD, x, y);
    return (x % MOD + MOD) % MOD;
}


static long long facttable[N_MAX + 1];

static void init_facttable(long long N) {
    facttable[0] = 1LL;
    for (long long i = 1LL; i <= N; i++) {
        facttable[i] = facttable[i - 1] * i % MOD;
    }
}

static vector<pair<long long, long long> > dp;

static pair<long long, long long> dfs(vector<vector<int> > &G, int n = 0, int par = -1) {
    long long nnode = 1;
    long long divider = 1;
    long long k = 1;
    for (int t : G[n]) {
        if (par == t) continue;
        auto p = dfs(G, t, n);
        nnode += p.first;
        divider *= facttable[p.first];
        divider %= MOD;
        k *= p.second;
        k %= MOD;
    }
    long long comb = facttable[nnode - 1] * modinv(divider) % MOD * k % MOD;

    auto np = make_pair(nnode, comb);
    dp[n] = np;
    return np;
}

static vector<long long> ans;

static void dfs2(vector<vector<int> >&G, int n = 0, int par = -1, pair<long long, long long> ppar = {0LL, 1LL}) {
    auto pn = dp[n];
    long long nnode = pn.first;
    long long comb = pn.second;
    long long nnode0 = nnode + ppar.first;
    long long comb0 = comb * facttable[nnode0 - 1] % MOD * modinv(
        facttable[nnode - 1] * facttable[ppar.first] % MOD
    ) % MOD * ppar.second % MOD;
    ans[n] = comb0;
    for (int t : G[n]) {
        if (par == t) continue;
        auto pt = dp[t];
        long long nnode1 = nnode0 - pt.first;
        long long comb1 = comb0 * facttable[nnode1 - 1] % MOD * facttable[pt.first] % MOD * modinv(
            facttable[nnode0 - 1] * pt.second % MOD
        ) % MOD;
        dfs2(G, t, n, make_pair(nnode1, comb1));
    }
}

static void solve(int N, vector<int> a, vector<int> b) {
    init_facttable(N);
    dp.resize(N);
    ans.resize(N);
    vector<vector<int> > G(N);
    for (int i = 0; i < N - 1; i++) {
        int ai = a[i] - 1;
        int bi = b[i] - 1;
        G[ai].push_back(bi);
        G[bi].push_back(ai);
    }
    dfs(G);
    dfs2(G);
    for (int k = 0; k < N; k++) {
        cout << ans[k] << endl;
    }
}

int main() {
    int N;
    cin >> N;
    vector<int> a(N - 1), b(N - 1);
    for (int i = 0; i < N - 1; i++) {
        cin >> a[i] >> b[i];
    }
    solve(N, move(a), move(b));
}


Measured memory_bytes: 21748
import java.io.*;
import java.util.*;

public class Main {


    public static void main(String[] args) throws Exception {

        FastReader fs = new FastReader();
        out = new PrintWriter(new BufferedOutputStream(System.out));

       int n = fs.nextInt();
       int[] inp = new int[n];

       for(int i=0 ; i<n ; i++){
           inp[i] = fs.nextInt();
       }

       long ans = 0 ;

       for(int i=0 ; i<n ; i++){
           int max = inp[i];
           for(int j=i+1 ; j<n ; j++){
               if(inp[j]<max){
                   ans += (max-inp[j]);
               }else{
                   i = j - 1 ;
                   break;
               }
               if(j==n-1){
                   i = j;
               }
           }
       }

       out.println(ans);

        out.close();

    }

    //-----------PrintWriter for faster output---------------------------------
    public static PrintWriter out;

    //-----------MyScanner class for faster input----------
    public static class FastReader {
        BufferedReader br;
        StringTokenizer st;

        public FastReader() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        long nextLong() {
            return Long.parseLong(next());
        }

        double nextDouble() {
            return Double.parseDouble(next());
        }

        String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }

    }
    //--------------------------------------------------------
}



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

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

    ll n;
    cin>>n;
    ll a[n];
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    //lowは下限―1、upは上限+1にする
    long long low=-1,up=1e12,mid;
    while(up-low>1){
        mid=(up+low)/2;
        //上半分か下半分の条件を求める
        ll t=a[0]-mid;
        for(int i=1;i<n;i++){
            t=a[i]-t;
        }
    
        //上半分の時
        if(t>=mid){
            low=mid;
        }
    
        //下半分の時
        else{
            up=mid;
        }
    }
    //lowが答え
    cout<<2*low<<" ";
    ll t=low;
    for(int i=0;i<n-1;i++){
        cout<<(ll)2*(a[i]-t)<<" ";
        t=a[i]-t;
    }
}

Measured memory_bytes: 2176
// CODE © by 𝕌𝕥𝕜𝕒𝕣𝕤𝕙 𝔾𝕒𝕣𝕘
// Copying or sharing of this code without permission of the Author is strictly prohibited!!!
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define Speed ios::sync_with_stdio(0); cin.tie(0);
#define pb push_back
#define endl "\n"
int dp[401][401];
int prf[401];
int f(int si, int ei) {
	// cout << si << " " << ei << endl;
	if (dp[si][ei] != -1)return dp[si][ei];
	if (si == ei)return 0;
	int &ans = dp[si][ei];
	ans = LLONG_MAX;
	for (int i = si; i < ei; i++) {
		ans = min(ans, f(si, i) + f(i + 1, ei) + prf[ei] - prf[si - 1]);
	}
	return ans;
}
signed main() {
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	// freopen("output.txt", "w", stdout);
#endif
	int a = 0, b = 0, c = 0, d = 0, i = 0, j = 0, k = 0, t = 0, n = 0, q = 0;
	cin >> n;
	for (int i = 0; i < 401; i++)
		for (int j = 0; j < 401; j++)dp[i][j] = -1;
	int arr[n + 1];
	memset(prf, 0, sizeof(prf));
	for (i = 1; i <= n; i++) {cin >> arr[i]; prf[i] += prf[i - 1] + arr[i];}
	cout << f(1, n);
}

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

int main() {
   string str;
  cin >> str ;
  if(str.at(2)==str.at(3)&&str.at(4)==str.at(5)){
    cout << "Yes" << endl;}
  else {
    cout << "No" << endl;}
  
 
  
}



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

using ll = long long;
// #define int long long

#define REP(i, n) for (int i = 0; i < (n); ++i)
#define REPS(i, r, n) for (int i = (r); i < (n); ++i)
#define REPR(i, n) for(int i = (n); i >= 0; --i) // from n to 0
#define REPRS(i, r, n) for(int i = (n); i >= (r); --i) // from n to r
#define COUTB(x) cout << (x) << "\n"
#define COUTS(x) cout << (x) << " "
#define PB push_back
#define SORT(obj) sort((obj).begin(), (obj).end())
#define SORTR(obj) sort((obj).begin(), (obj).end(), greater<>())
#define ALL(obj) (obj).begin(), (obj).end()
#define MOD 1000000007
#define PI (acos(-1))
/***** MAIN *****/
signed main() {
  int n;
  cin >> n;
  int trees[n];
  bool firstWins = false;
  REP(i,n) {
    cin >> trees[i];
    if(trees[i] % 2 != 0) firstWins = true;
  }
  if(firstWins) cout << "first";
  else cout << "second";
  cout << "\n";
  return 0;
}
/***** MAIN *****/


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

template <class T>
inline void read(T &res)
{
	res = 0; bool bo = 0; char c;
	while (((c = getchar()) < '0' || c > '9') && c != '-');
	if (c == '-') bo = 1; else res = c - 48;
	while ((c = getchar()) >= '0' && c <= '9')
		res = (res << 3) + (res << 1) + (c - 48);
	if (bo) res = ~res + 1;
}

typedef long long ll;

const int N = 1e6 + 5, P = 2e5 + 3, EI = 998244353;

int n, a[N], f[N], t[N], w[N], th[N], ff = 1, tot, rev[N], yg[N];
bool vis[N];
ll ans, g[N];

int qpow(int a, int b)
{
	int res = 1;
	while (b)
	{
		if (b & 1) res = 1ll * res * a % EI;
		a = 1ll * a * a % EI;
		b >>= 1;
	}
	return res;
}

void FFT(int n, int *a, int op)
{
	for (int i = 0; i < n; i++) if (i < rev[i]) std::swap(a[i], a[rev[i]]);
	yg[n] = qpow(3, (EI - 1) / n * ((n + op) % n));
	for (int i = n >> 1; i; i >>= 1)
		yg[i] = 1ll * yg[i << 1] * yg[i << 1] % EI;
	for (int k = 1; k < n; k <<= 1)
	{
		int x = yg[k << 1];
		for (int i = 0; i < n; i += k << 1)
		{
			int w = 1;
			for (int j = 0; j < k; j++)
			{
				int u = a[i + j], v = 1ll * w * a[i + j + k] % EI;
				a[i + j] = (u + v) % EI; a[i + j + k] = (u - v + EI) % EI;
				w = 1ll * w * x % EI;
			}
		}
	}
	if (op == -1)
	{
		int gg = qpow(n, EI - 2);
		for (int i = 0; i < n; i++) a[i] = 1ll * a[i] * gg % EI;
	}
}

int main()
{
	read(n);
	for (int i = 1; i <= n; i++) read(a[i]);
	for (int i = 0, j = 1; i < P - 1; i++, j = 2ll * j % P) th[j] = i;
	for (int i = 1; i <= n; i++) if (a[i]) f[th[a[i]]]++;
	while (ff < 2 * P - 1) ff <<= 1, tot++;
	for (int i = 0; i < ff; i++)
		rev[i] = (rev[i >> 1] >> 1) | ((i & 1) << tot - 1);
	for (int i = 0; i < P; i++)
	{
		w[i] = f[i];
		if (f[i] > 4000) f[i] = 0, vis[i] = 1;
	}
	FFT(ff, f, 1);
	for (int i = 0; i < ff; i++) f[i] = 1ll * f[i] * f[i] % EI;
	FFT(ff, f, -1);
	for (int i = 0; i < ff; i++) g[i] = f[i];
	for (int i = 0; i < P; i++) if (vis[i])
		for (int j = 0; j < P; j++)
			g[i + j] += 1ll * w[i] * w[j] * (vis[j] ? 1 : 2);
	for (int i = 0, j = 1; i < ff; i++, j = 2ll * j % P) ans += g[i] * j;
	for (int i = 1; i <= n; i++) ans -= 1ll * a[i] * a[i] % P;
	return std::cout << ans / 2 << std::endl, 0;
}

Measured memory_bytes: 14216
#author : dokueki

import sys
INT_MAX = sys.maxsize
INT_MIN = -(sys.maxsize)
sys.setrecursionlimit(10**7)
mod = 1000000007


def IOE():
    sys.stdin = open("input.txt", "r")
    sys.stdout = open("output.txt", "w")


def main():
    n = int(sys.stdin.readline())
    a = list(map(int, sys.stdin.readline().split()))
    d = dict()
    for i in range(1, n + 1):
        d[i] = 0
    for i in a:
        d[i] += 1
    for i in d.values():
        print(i)


if __name__ == "__main__":
    try:
        IOE()
    except:
        pass
    main()


Measured memory_bytes: 117932
#include<bits/stdc++.h>
using namespace std;
set<int>s;
int main()
{
    cin.tie(0);ios_base::sync_with_stdio(false);
    int n,t=0;
    cin>>n;
    while(n--)
    {
        int x;
        cin>>x;
        if(s.count(x)){s.erase(x);t--;continue;}
        s.insert(x);
        t++;
    }
    cout<<t<<endl;
return 0;
}



Measured memory_bytes: 4992
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define LLINF 9223372036854775807
#define MOD ll(1e9+7)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cerr<<#x<<": "<<x<<endl


int main(){
    ll q;
    cin >> q;
    ll c = 0;
    multiset<ll> lst, rst;
    ll bsum = 0;
    ll fmin = 0;
    for(int i = 0; i < q; i++){
        ll f;
        cin >> f;
        if(f==1){
            ll a, b;
            cin >> a >> b;
            bsum += b;
            lst.insert(a);
            rst.insert(a);

            if(*(--lst.end()) > *(rst.begin())){
                ll lbig = *(--lst.end());
                ll rsmall = *(rst.begin());
                rst.insert(lbig);
                lst.erase(--lst.end());
                lst.insert(rsmall);
                rst.erase(rst.begin());
                fmin += abs(lbig-rsmall);
            }

        }else{

            cout << *(--lst.end()) << " " << fmin + bsum << endl;
        }
    }


    return 0;
}


Measured memory_bytes: 18944
#include<bits/stdc++.h>
using namespace std;
#define REP(i,a,b) for(int (i)=(a);(i)<(int)(b);(i)++)
#define RREP(i,a,b) for(int (i)=(a);(i)>=(int)(b);(i)--)
typedef long long ll;
typedef pair<ll, ll> P;
const int MOD = 1000000007;

bool po[10];

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

    fill(po, po + 10, true);
    REP(i,0,k){
        int x;
        cin >> x;
        po[x] = false;
    }
    
    while(true){
        string temp = to_string(n);
        bool flag = true;
        REP(i,0,temp.size()){
            if (!po[(int)(temp[i] - '0')]){
                flag = false;
                break;
            }
        }
        if (flag){
            cout << n << endl;
            return 0;
        }
        n++;
    }
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
int main(void){
  int L,R;
  int d;
  int i;
  int s=0;
  scanf("%d%d%d",&L,&R,&d);
  for(i=L;i<=R;i++){
    if(i%d==0){
      s=s+1;
    }
  }
  printf("%d",s);
  return 0;
}

Measured memory_bytes: 1704