akhauriyash/Code-Regression huggingface dataset:
shared void main(){
  assert(exists t=process.readLine());
  value u=t.split().iterator();
  assert(exists a=parseInteger(u.next().string));
  assert(exists b=parseInteger(u.next().string));
  assert(exists c=parseInteger(u.next().string));
  assert(exists d=parseInteger(u.next().string));
  assert(exists e=parseInteger(u.next().string));
  assert(exists f=parseInteger(u.next().string));
  variable Integer water=0;
  variable Integer sugar=0;
  for(i in 0..f){
    if(i%(100*a)!=0){
      continue;
    }
    for(j in 0..f-i){
      if(j%(100*b)!=0){
        continue;
      }
      for(k in 0..f-i-j){
        if(k%c!=0){
          continue;
        }
        for(l in 0..f-i-j-k){
          if(l%d!=0){
            continue;
          }
          if((k+l)*100<=e*(i+j)){
            if((water==0&&sugar==0)||sugar*(i+j+k+l)<(k+l)*water){
              water=i+j+k+l;
              sugar=k+l;
            }
          }
        }
      }
    }
  }
  print(water.string+" "+sugar.string);
}

Measured memory_bytes: 191772
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n,m=0,s=1;
	cin>>n;
	int a[n+1];
	int b=1;
	for(int i=1;i<=n;i++)
	{
		cin>>a[i];
	}
	while(b==1)
	{
		s=s*2;
		for(int i=1;i<=n;i++)
		{
			if(a[i]%2==0)
			{
				a[i]=a[i]/2;
			}
			else
			{
				b=0;
			}
		}
		if(b!=0)
		{
			m++;
		}
	}
	cout<<m;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;
long long int firstNumber,secondNumber;

long long int GCD(int x, int y)
{
    while(x!=y)
    {
        if(x<y)
        {
            y = y-x;
        }
        if(y<x)
        {
            x = x-y;
        }
    }
    return x;
}

long long int LCM(int x, int y)
{
    return (x / GCD(x,y))*y;
}



int main()
{   while(cin >> firstNumber >> secondNumber)
    {
        cout << GCD(firstNumber,secondNumber) << " " << LCM(firstNumber,secondNumber) << endl;
    }

}

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

struct Data {
    int index;
    int P, Y;

    bool operator <(const Data& iValue) {
        if (this->P == iValue.P) return this->Y < iValue.Y;
        else return this->P < iValue.P;
    }
};

int main() {
    int N, M; cin >> N >> M;
    vector<Data> List(M);
    rep (i, M) {
        int p, y; cin >> p >> y;
        List[i].index = i;
        List[i].P = p;
        List[i].Y = y;
    }

    sort(List.begin(), List.end());

    int same = List[0].P;
    int cnt = 1;
    map<int, string> ans;
    rep (i, M) {
        if (same != List[i].P) {
            cnt = 1;
            same = List[i].P;
        }
        char buff[184];
        sprintf(buff, "%06d%06d", List[i].P, cnt++);
        string id = buff;
        ans[List[i].index] = id;
    }

    for (const auto& it : ans) {
        cout << it.second << endl;
    }

    return 0;
}


Measured memory_bytes: 13568
#include <algorithm>
#include <cassert>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <utility>
#include <vector>

using namespace std;
using ll = long long;

constexpr ll infl = 10000000000000007LL;
constexpr int inf = 1000000007;

#include <vector>
using namespace std;

class UnionFind {
    vector<int> parent;
    vector<int> rank;

public:
    int root(int x) {
        return parent[x] >= 0 ? parent[x] = root(parent[x]) : x;
    }

    void unite(int x, int y) {
        int rootX = root(x);
        int rootY = root(y);
        if (rootX == rootY)
            return;

        if (rank[rootX] > rank[rootY]) {
            parent[rootX] += parent[rootY];
            parent[rootY] = rootX;
        } else {
            if (rank[rootX] == rank[rootY])
                ++rank[rootY];

            parent[rootY] += parent[rootX];
            parent[rootX] = rootY;
        }
    }

    bool same(int x, int y) {
        return root(x) == root(y);
    }

    int groupSize(int x) {
        return -parent[root(x)];
    }

    int numGroup() {
        int num = 0;
        for (int k : parent) {
            num += k < 0;
        }
        return num;
    }

    UnionFind(int size) : parent(size + 1, -1), rank(size + 1, 1) {
        parent[0] = rank[0] = 0;
    }
};

int main() {
    int n, k;
    cin >> n >> k;
    vector<int> p(n);
    for (int i = 0; i < n; ++i) {
        cin >> p[i];
    }
    UnionFind uf(n - k + 1);
    // iからはじめて昇順の最大長さがk以上なiをもとめていく
    vector<int> idxs;
    p.push_back(-inf);
    for (int i = 0, r = 1; i < n - k + 1; ++i) {
        if (r == i)
            ++r;

        while (p[r] > p[r - 1])
            ++r;

        if (r - i >= k)
            idxs.push_back(i);
    }
    p.pop_back();
    for (int i = 1; i < idxs.size(); ++i) {
        uf.unite(idxs[i] + 1, idxs[i - 1] + 1);
    }
    // [i, i+k]の最小がもっとも左に最大がもっとも右にきているかチェックしていく
    // 長さがk + 1なのに注意
    deque<int> deq_min, deq_max;
    for (int i = 0; i < n; ++i) {
        while (deq_min.size() > 0 && p[deq_min.back()] >= p[i]) {
            deq_min.pop_back();
        }
        while (deq_max.size() > 0 && p[deq_max.back()] <= p[i]) {
            deq_max.pop_back();
        }
        deq_min.push_back(i);
        deq_max.push_back(i);

        if (i >= k) {
            int idx = i - k;
            if (p[idx] == p[deq_min.front()] && p[idx + k] == p[deq_max.front()]) {
                uf.unite(idx + 1, idx + 2);
            }

            if (deq_min.front() == idx)
                deq_min.pop_front();

            if (deq_max.front() == idx)
                deq_max.pop_front();
        }
    }

    cout << uf.numGroup() << endl;
    return 0;
}

Measured memory_bytes: 4464
/*
ID: Sho10
LANG: C++
TASK:race
*/
#include <bits/stdc++.h> //Andrei Alexandru a.k.a Sho10
#define ll long long int
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#define all(a) (a).begin(), (a).end()
#define sz size
#define f first
#define s second
#define pb push_back
#define er erase
#define in insert
#define mp make_pair
#define pi pair
#define rc(s) return cout<<s,0
#define endl '\n'
#define mod 1000000007
#define PI 3.14159265359
#define CODE_START  ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
ll n,k,a[200005];
int32_t main(){
CODE_START;
cin>>n>>k;
for(ll i=0;i<n;i++)
{
    cin>>a[i];
}
sort(a,a+n);
reverse(a,a+n);
ll ans=0;
for(ll i=k;i<n;i++)
ans=ans+a[i];
cout<<ans<<endl;
}




Measured memory_bytes: 1792
#include <iostream>
#include <algorithm>
#include <fstream>
#include <vector>
#include <deque>
#include <assert.h>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <stdio.h>
#include <string.h>
#include <utility>
#include <math.h>
#include <bitset>
#include <iomanip>

using namespace std;

#define F(i , a , b) for(int (i) = (a) ; (i) <= (b) ; (i)++)
#define pb push_back
#define ll long long
#define E(a) cerr << #a << " = " << a << '\n'
#define X first
#define Y second
#define INF 10000000000000

const int MAX_N = 100000 + 10 , mod = 1000000007;

string s,t,p;



int32_t main(){

    //    freopen("input.txt" , "r" , stdin);
    //    freopen("output.txt" , "w" , stdout);
    //    cout << setprecision(10) << fixed;

    cin >> s >> t >> p;
    cout << s[0] << t[0] << p[0];



    return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <cmath>
#include <climits>
#include <iomanip>
#include <set>
#include <map>
using namespace std;
typedef long long ll;
int main(){
  ll n = 0;
  string s;
  cin >> n >> s;
  ll all = 0;
  for(int i = 0;i < s.size();i++){
    if(s[i] == '#')all++;
  }
  ll now = 0;
  ll res = 0;
  res = max(res,all);
  for(int i = 0;i < n;i++){
    if(s[i] == '.')now++;
    else all--;
    res = max(res,now + all);
  }
  res = max(res,now);
  cout << s.size() - res << endl;
  return 0;
}

Measured memory_bytes: 640
N = gets.chomp!.to_i
Xs = gets.chomp!.split(" ").map! { |i| i.to_i }

min_sum = 1000000
(1..100).each do |p|
  sum = 0
  Xs.each do |x|
    sum += (x - p) * (x - p)
  end
  min_sum = sum if min_sum > sum
end
puts min_sum


Measured memory_bytes: 14292
using System;
using System.Collections.Generic;
using System.Linq;

namespace B___K_th_Common_Divisor
{
    class Program
    {
        static void Main(string[] args)
        {
            var input = Console.ReadLine().Split(' ');
            var a = int.Parse(input[0]);
            var b = int.Parse(input[1]);
            var k = int.Parse(input[2]);
            var c = new List<int>();
            for (var i = 0; i < 100; i++)
            {
                c.Add(i+1);
            }    
            var quary = c.Where(x => a % x == 0 && b % x == 0)
                         .OrderByDescending(x => x)
                         .ToList();
            Console.WriteLine(quary[k - 1]);
        }
    }
}

Measured memory_bytes: 13396
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
const ll mod = 1000000007;
const ll INF = 1001001001;
const ll LINF = 1001001001001001001;

void prvec(vector<ll> vec){
    ll n = vec.size();
    rep(i,n) cout << "i" << " " << vec.at(i) << "\n";
}

void pr2d(vector<vector<ll>> vvec){
    ll h = vvec.size();
    ll w = vvec.at(0).size();
    rep(i,h){
        rep(j,w){
            cout << vvec.at(i).at(j) << " ";
        }
        cout << "\n";
    }
}

int main(){
    ll n , k ; cin >> n >> k;
    ll ans = 0;
    for(ll i=k;i<=n+1;i++){
        if( n*i - (i*(i-1)) + 1 >= 0) ans = (ans + n*i - (i*(i-1)) + 1) %mod;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3640
#include <iostream>
#include <algorithm>
#include <queue>
#include <vector>
#include <map>
#include <string>
 
using namespace std;
 
void solve();
 
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    solve();
}
 
void solve() {
    string a,b;
    cin >> a >> b;
    int tmp = stoi(a + b);
    for(int i = 1; ; i++) {
        if(i * i == tmp) {
            cout << "Yes" << endl;
            return;
        }
        if(i * i > tmp) {
            break;
        }
    }
    cout << "No" << endl;

    

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define endl "\n"
#define fo(i,s,e) for( i=s;i<e;i++)
#define rfo(i,s,e) for(i=s;i>e;i--)
#define LLI long long int
#define LI long int 
const LI MOD=1e9+7;
#define pb push_back
#define pob pop_back()
#define sp " "
#define ff first
#define ss second
//            When something is important enough, you do it even if the odds are not in your favor.

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);cout.tie(NULL);
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
    // code goes here
    int t=1;//cin>>t;
    while(t--){
      LI n,k,i;cin>>n>>k;
      LI a[n];
      fo(i,0,n) cin>>a[i];
      sort(a,a+n);
      LLI sum=0;
      fo(i,0,k) sum+=a[i];
      cout<<sum;
    }
    return 0;
}

Measured memory_bytes: 3668
#include <bits/stdc++.h>
 
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>
 
using namespace std;
using namespace __gnu_pbds;
 
#define int long long int
#define endl "\n"
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define all(c) c.begin(), c.end()
 
struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        // http://xorshift.di.unimi.it/splitmix64.c
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }
 
    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};
 
typedef tree< int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

int dp[100001];

int totalCost(int h[], int n, int k) {
	if (n == 0)
		return 0;
	if (dp[n] != -1)
		return dp[n];
	int ans = INT_MAX;
	for (int i = 1; i <= k; i++) {
		if (n-i >= 0)
			ans = min(ans, abs(h[n] - h[n-i]) + totalCost(h, n-i, k));
	}
	return dp[n] = ans;
}

void solve() {
    int n, k;
    cin >> n >> k;
    int h[n];
    for (int i = 0; i < n; i++) {
    	cin >> h[i];
    	dp[i] = -1;
    }
    cout << totalCost(h, n-1, k) << endl;
}
 
signed main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	
	int t = 1;
	// cin >> t;
	while (t--) {
		solve();
	}
  
	return 0;
}

Measured memory_bytes: 12956
from sys import stdin


def main():
    x, y, a, b, c = map(int, stdin.readline().split())
    p = list(map(int, stdin.readline().split()))
    q = list(map(int, stdin.readline().split()))
    r = list(map(int, stdin.readline().split()))

    pqr = []

    for pi in p:
        pqr.append([pi, 0])
    for qi in q:
        pqr.append([qi, 1])
    for ri in r:
        pqr.append([ri, 2])

    pqr.sort(reverse=True)

    ans = 0
    c_a = 0
    c_b = 0
    c_c = 0

    for pqri in pqr:
        if pqri[1] == 0 and c_a < x:
            ans += pqri[0]
            c_a += 1
        elif pqri[1] == 1 and c_b < y:
            ans += pqri[0]
            c_b += 1
        elif pqri[1] == 2 and (c_a < x or c_b < y) and c_a + c_b + c_c < x + y:
            ans += pqri[0]
            c_c += 1
        if c_a + c_b + c_c == x + y:
            print(ans)
            exit()


if __name__ == "__main__":
    main()


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

typedef long long ll;
//loop
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
//STL
#define ALL(x) (x).begin(),(x).end()
#define SIZE(x) ((ll)(x).size())
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))

//const
#define MOD 1000000007 //10^9+7:合同式の法

//acronym
#define PB push_back //vectorヘの挿入
#define MP make_pair //pairのコンストラクタ
#define F first //pairの一つ目の要素
#define S second //pairの二つ目の要素

void Main() {
    int a, b;
    cin >> a >> b;
    if (a % 3 == 0 || b % 3 == 0 || (a + b) % 3 == 0) {
        cout << "Possible" << endl;
    } else {
        cout << "Impossible" << endl;
    }
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	Main();
	return 0;
}


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

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ALL(a) begin(a),end(a)
#define COUNTOF(a) (sizeof(a)/sizeof(a[0]))
#define SP << " " <<
#define FMT(a) #a<<":"<<a 
#define FMT2(a,b) #a<<":"<<a<<", "<<#b<<":"<<b 
#define FMT3(a,b,c) #a<<":"<<a<<", "<<#b<<":"<<b<<", "<<#c<<":"<<c 
#define FMT4(a,b,c,d) #a<<":"<<a<<", "<<#b<<":"<<b<<", "<<#c<<":"<<c<<", "<<#d<<":"<<d 
typedef long long ll;
template<class T> istream& operator >> (istream& s, vector<T>& v) {
  for (T& x: v) s >> x;
  return s;
}
inline void Yes(bool f=true){cout<<(f?"Yes":"No")<<endl;}
inline void YES(bool f=true){cout<<(f?"YES":"NO")<<endl;}
#define ANS(a) cout<<a<<endl

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

    int N; cin >>N;
    Yes(N/100==N%10);
}


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

int64_t MOD = 1000000007;
int64_t MAX = 9223372036854775807;
double PI = 3.141592653589793;

int main()
{
    int y, m, d;
    char c1, c2;
    cin >> y >> c1 >> m >> c2 >> d;
    if (m >= 5)
        cout << "TBD";
    else
        cout << "Heisei";
}

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

#define int ll

signed main(){
    int n,x;
    cin>>n>>x;
    vector<int> v(n),t;
    rep(i,n)cin>>v[i];
    t=v;
    
    for(int i=1;i<n;i++){
        if(v[i-1]+v[i]<=x)continue;
        int d = v[i-1]+v[i]-x;
        
        if(v[i]>=d)v[i]-=d;
        else{
            d-=v[i];
            v[i]=0;
            
            v[i-1]-=d;
        }
    }
    int ans=0;
    rep(i,n)ans += t[i]-v[i];
    
    cout<<ans<<endl;
}

Measured memory_bytes: 1792
import java.util.Scanner;

public class Main{


	public static void main(String args[]){

		Scanner sc = new Scanner(System.in);
		int n=sc.nextInt();
		int num[]= new int[n];
		for (int i=0;i<n;++i){
			num[i]=sc.nextInt();
		}
		int div;
		int counter=0;

		for (int i=0;i<n;++i){
			div =0;
			if (num[i]==2) ++counter;
			if (num[i]%2==0) ++div;
			for (int j=3;j<=(double)Math.pow(num[i],0.5) && div ==0;j=j+2){
				if (num[i]%j == 0) ++div;
			}
			if (div==0) ++counter;
		}
		System.out.println(counter);
	}

}


Measured memory_bytes: 41436
fun main(args: Array<String>) {
    val (N, W) = readLine()!!.split(" "). map { it.toInt() }
    val dp = LongArray(W+1)
    val w = IntArray(N+1)
    val v = IntArray(N+1)
    for ( i in 0 until N) {
        val a = readLine()!!.split(" "). map { it.toInt() }
        w[i] = a[0]
        v[i] = a[1]
    }
    for (i in 0 until N) {
        for (j in W downTo w[i]) {
            dp[j] = Math.max(dp[j], dp[j - w[i]] + v[i])
        }
    }
    println(dp.max())
}

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

int main() {
	string s;
	cin >> s;
	int flag = 0;
	
	for(int i = 0; i < s.length(); i++){
		if(flag == 0){
			if(s[i] == 'C'){
				flag++;
			}
		}else if(flag == 1){
			if(s[i] == 'F'){
				flag++;
				break;
			}
		}
	}
	
	if(flag == 2){
		cout << "Yes" << endl;
	}else{
		cout << "No" << endl;
	}
	
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  char str1[100], str2[100], str3[1000];
  scanf("%s %s", str1, str2);
  strcat(str3, str1);
  strcat(str3, str1);
  
  if(strstr(str3, str2) == NULL){
      printf("No");
      cout << endl;
  }
  else {
      printf("Yes"); 
      cout << endl;
  }
}


Measured memory_bytes: 3304
#include <bits/stdc++.h>
#include <vector>
#include <queue>
#include <set>
#include <iostream>
#include <iomanip>
using namespace std;
typedef long long LL;
#define REP(i,n) for(int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}

int main(){
    LL N, X, M;
    cin >> N >> X >> M;

    vector<LL> A;
    vector<int> Indexes(M, -1);

    int index = 0;
    LL val = X;
    LL total = 0;
    while(Indexes[val] == -1){
        A.push_back(val);
        Indexes[val] = index;
        index++;
        total += val;
        val = (val*val)%M;
    }

    LL cycleSum = 0;
    int cycle = index - Indexes[val];
    for(int i=Indexes[val]; i<index; i++){
        cycleSum += A[i];
    }

    LL ans = 0;
    if(N <= index){
        REP(i, N){
            ans += A[i];
        }
        cout << ans << endl;
        return 0;
    }

    ans += total;
    N -= index;

    LL r = N % (cycle);
    LL q = N / (cycle);

    ans += (cycleSum * q);

    for(int i=Indexes[val]; i<Indexes[val]+r; i++){
        ans += A[i];
    }

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

Measured memory_bytes: 4308
#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 FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end())
#define VRSORT(v) sort(v.rbegin(), v.rend())//vectorの降順ソート
#define ll long long
#define pb(a) push_back(a)
#define INF 1000000000
#define MOD 1000000007
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

typedef vector<unsigned int>vec;
typedef vector<vec> mat;

typedef tuple<ll, ll, ll> T;

int dy[]={0, 0, 1, -1, 0};
int dx[]={1, -1, 0, 0, 0};

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    char c;cin>>c;
    if(c=='a' || c=='i' || c=='u' || c=='e' || c=='o') cout<<"vowel";
    else cout<<"consonant";
    cout<<endl;
}

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

using namespace std;

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

    vector<int> a(n);
    vector<int> b(n);
    vector<int> c(n);

    for (int i = 0; i < n; ++i) {
        cin >> a[i];
        cin >> b[i];
        cin >> c[i];
    }

    vector<int> Fa(n, 0);
    vector<int> Fb(n, 0);
    vector<int> Fc(n, 0);

    Fa[0] = a[0];
    Fb[0] = b[0];
    Fc[0] = c[0];

    for (int i = 1; i < n; ++i) {
        Fa[i] = a[i] + max(Fb[i - 1], Fc[i - 1]);
        Fb[i] = b[i] + max(Fa[i - 1], Fc[i - 1]);
        Fc[i] = c[i] + max(Fa[i - 1], Fb[i - 1]);
    }

    cout << max(Fa[n - 1], max(Fb[n - 1], Fc[n - 1]));
    
    return 0;
}

Measured memory_bytes: 2560
#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  cin >> N;
  vector<int> vec(N); 

  for (int i = 0; i < N; i++) 
    cin >> vec.at(i);

  sort(vec.begin(), vec.end());

  int b = 1;
  for (int i = 0; i < N-1; i++) {
     if (vec.at(i)<vec.at(i+1)) 
        b++;
  }   
  cout << b << endl;
}

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

using namespace std;

using ll = long long;
using P = pair<ll, ll>;
using Graph = vector<vector<ll>>;
#define rep(i, n) for(ll i=0;i<(ll)(n);i++)
#define rep2(i, m, n) for(ll i=m;i<(ll)(n);i++)
#define rrep(i, n, m) for(ll i=n;i>=(ll)(m);i--)
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int ddx[8] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll MOD = 1000000007;
const ll INF = 1000000000000000000L;
#ifdef __DEBUG

/**
 * For DEBUG
 * https://github.com/ta7uw/cpp-pyprint
 */
#include "cpp-pyprint/pyprint.h"

#endif

void Main() {
    ll N; cin >> N;
    set<ll> A;
    rep(i, N){
        ll tmp; cin >> tmp;
        if (A.find(tmp) != A.end()){
            A.erase(tmp);
        } else {
            A.insert(tmp);
        }
    }
    cout << A.size() << endl;

}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    Main();
    return 0;
}


Measured memory_bytes: 4992
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define all(v) v.begin(), v.end()
#define vl vector<ll>
#define vi vector<int>
#define pii pair<int,int>
#define pb push_back
#define ff first
#define ss second
const int N=100005;
void solve()
{
    ll n,k=0,val=0,m=INT64_MIN,i=0,j;
    ll ans=0;
    ll perm[5005]{},c[5005]{};
    cin>>n>>k;
    for(i=1;i<=n;i++)cin>>perm[i];
    for(i=1;i<=n;i++)cin>>c[i];

    for(i=1;i<=n;i++)
    {
        ll score=0;
        int vis[5005]={};
        ll turns=0;
        j=i;
        while(turns<k)
        {
            //if(i==3)cout<<score<<" ";
            j=perm[j];
            if(vis[j])
            {
                if(score<0)break;
                score*=(k-turns)/turns;
                for(int p=0;p<k%turns+turns;p++)
                {
                    score+=c[j];
                    j=perm[j];
                    m=max(m,score);
                }
                break;
            }
            score+=c[j];
            turns++;
            vis[j]=1;
            m=max(m,score);
        }
        //if(score==16)cout<<i;
    }
    cout<<m;
}
int main()
{
    ios::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin) ;
    freopen("output.txt", "w", stdout) ;
    #endif
    int t=1;
    //cin>>t;
    while(t--)solve();
    return 0;
}

Measured memory_bytes: 3736
import java.util.EmptyStackException;
import java.util.Scanner;
import java.util.Stack;


public class Main{

	@SuppressWarnings("unchecked")
	public static void main(String[] args) {
		Scanner s = new Scanner(System.in);
		while(true) {
			String str = s.nextLine();
			if(".".equals(str))
				break;
			solve(str);
		}
	}

	public static void solve(String str) {
		Stack<String> stack = new Stack<String>();
//		Stack round = new Stack();
		for(int i=0 ; i<str.length() ; i++) {
			String c = str.substring(i, i+1);
			if("(".equals(c)) {
				stack.push("(");
			}else if(")".equals(c)) {
				Object o = null;
				try{
					o = stack.pop();
				}catch(EmptyStackException e) {
					System.out.println("no");
					return;
				}
				if(o == null || !"(".equals(o)) {
					System.out.println("no");
					return;
				}
			}else if("[".equals(c)) {
				stack.push("[");
			}else if("]".equals(c)) {
				Object so = null;
				try{
					so = stack.pop();
				}
				catch(EmptyStackException e) {
					System.out.println("no");
					return;
				}
				if(so == null || !"[".equals(so)) {
					System.out.println("no");
					return;
				}
			}
		}
		if(! stack.isEmpty()) {
			System.out.println("no");
			return;
		}
		if(! stack.isEmpty()) {
			System.out.println("no");
			return;
		}
		System.out.println("yes");
	}
}

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

#define pb         push_back

typedef long long ll;
const ll INF = 1000000000000000000ll;
const ll MOD = 1000000007ll;
const double EPS = 1e-8;

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

    int x, t;
    cin >> x >> t;

    cout << max(x - t, 0) << endl;

    
    return 0;
}


Measured memory_bytes: 256
//#include<iostream>
//#include<algorithm>
//#include<string>
//#include <cmath>
//#include <vector>
#include <bits/stdc++.h>

using namespace std;

#define ll long long
#define REP(x,n) for(int x=0;x<n;x++)

// vector 操作  vector<int> data(10,5) 5が10個　data(10) 要素数10
// v.size(), v.empty(), v.insert(itr,値), v.erase(itr) (first,last),
// sort(itr), find(all(x),値),reverse(itr),accumulate(itr,0) 積算,
//v.swap
// stringも同じ itrがただの数字になる
// s.substr(n,m)n番目以降m文字取り出す　erase(n,m)も  s.find
#define vei vector<int> 
#define velli vector<long long int> 
#define pb(x) push_back(x) // 末尾にxを加える
#define pb2 pop_back() // 末尾削除
#define all(x) (x).begin(),(x).end() //イテレーター
#define be(x) (x).begin()
//auto  auto begin = v.begin()とか

// map 操作  map<string,int> mp キー=string 値=int型  pair< , >型
// 代入:mp["abc"]=123  mp.erase(キー)
// itr = mp.begin()のとき　itr->first = key, itr->second = val
// mp.find(key) itrを返す
typedef pair<int,int> P;  //q(p.first,p.second)で定義できる？

// lcm( , ) gcd( , ) 最大公約数　最小公倍数


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

    ll int ans = k;
    
    if(n==1) cout << ans;
    else{
        REP(i,n-1){
        ans *= (k-1);
        }
        cout << ans;
    }

}

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

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  long long n;
  cin >> n;
  if (n & 1) {
    cout << 0 << '\n';
  } else {
    long long res = 0;
    n /= 2;
    while (true) {
      n /= 5;
      if (n == 0) break;
      res += n;
    }
    cout << res << '\n';
  }
}


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

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

	string s;
	cin >> s;

	int idx = 0;
	string prev;
	vector<vector<string> > vs(1);

	for(int i = 0; i < s.size();) {
		string tmp;
		if(s[i] == 'e')
			tmp = "egg";
		else
			tmp = "chicken";

		if(prev == tmp) {
			vs.push_back(vector<string>());
			++idx;
		}

		vs[idx].push_back(tmp);
		prev = tmp;
		i += tmp.size();
	}

	int len = 0;
	string ans;
	for(int i = 0; i < vs.size(); ++i) {
		if(vs[i].size() > len) {
			len = vs[i].size();
			ans = vs[i][len - 1];
		}
	}

	cout << ans << endl;

	return EXIT_SUCCESS;
}

Measured memory_bytes: 1280
s = input()
n = len(s)

# パターン数
for i in range(2**(n-1)):
    
    exp = s[0]

    # 右シフトする
    for j in range(1, n):
        if (i >> j-1) & 1:
            exp += '+'
        else:
            exp += '-'
        
        exp += s[j]

    if eval(exp) == 7:
        print('{}=7'.format(exp))
        exit()

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
const int M = 1e5 + 10;
vector<int> vc[M];
int dfs(int pos , int pre) {
    int len = vc[pos].size();
    int res = 0;
    for(int i = 0 ; i < len ; i++) {
        int v = vc[pos][i];
        if(v != pre) {
            res += dfs(v , pos);
        }
    }
    if(res >= 2) {
        printf("First\n");
        exit(0);
    }
    else if(res == 0) return 1;
    else return 0;
}
int main() {
    int n , u , v;
    scanf("%d" , &n);
    for(int i = 1 ; i < n ; i++) {
        scanf("%d%d" , &u , &v);
        vc[u].push_back(v);
        vc[v].push_back(u);
    }
    int ans = dfs(1 , 0);
    if(ans)
        printf("First\n");
    else
        printf("Second\n");
    return 0;
}

Measured memory_bytes: 5888
#include <bits/stdc++.h>
using namespace std;
//#include <boost/multiprecision/cpp_int.hpp>
//using multiInt = boost::multiprecision::cpp_int;

using ll = long long int;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
template<typename Q_temp>
using smaller_queue = priority_queue <Q_temp, vector<Q_temp>, greater<Q_temp> >;

const int INF = (int) 1e9;
const ll LINF = (ll) 1e18;
const ll MOD = (ll) (1e9 + 7);
const double PI = acos(-1.0);
const int limit = 200010;

#define REP(i,m,n) for(ll i = m; i < (ll)(n); ++i)
#define rep(i,n) REP(i, 0, n)
#define MP make_pair
#define YES(n) cout << ((n) ? "YES" : "NO") << endl
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible") << endl
#define all(v) v.begin(), v.end()
#define NP(v) next_permutation(all(v))
#define dbg(x_) cerr << #x_ << ":" << x_ << endl;
#define dbg2(x_) for(auto a_ : x_) cerr << a_ << " "; cerr << endl;
#define dbg3(x_ , sx_) rep(i, sx_) cerr << x_[i] << " "; cerr << endl;
vector<int> Dx = {0, 0, -1, 1, -1, 1, -1, 1, 0};
vector<int> Dy = {1, -1, 0, 0, -1, -1, 1, 1, 0};

//------------------------------------------------------

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll a, b, q;
    cin >> a >> b >> q;
    vector<ll> s(a + 2), t(b + 2);
    s[0] = t[0] = -LINF, s[a + 1] = t[b + 1] = LINF;
    for (int i = 1; i <= a; ++i) cin >> s[i];
    for (int i = 1; i <= b; ++i) cin >> t[i];

    rep(query, q) {
        ll x;
        cin >> x;

        auto itr_sh = lower_bound(all(s), x);
        auto itr_te = lower_bound(all(t), x);
        ll L_sh = x - *(itr_sh - 1);
        ll L_te = x - *(itr_te - 1);
        ll R_sh = *itr_sh - x;
        ll R_te = *itr_te - x;

        ll LL = max(L_sh, L_te);
        ll RR = max(R_sh, R_te);
        ll Ls_Rt = 2 * L_sh + R_te;
        ll Rt_Ls = L_sh + 2 * R_te;
        ll Lt_Rs = 2 * L_te + R_sh;
        ll Rs_Lt = L_te + 2 * R_sh;
        cout << min({LL, RR, Ls_Rt, Rt_Ls, Lt_Rs, Rs_Lt}) << endl;
    }
    return 0;
}

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

typedef long long ll;
const int MOD=1e9+7;

struct modint {
    int val;
    modint inv() const{
        int tmp,a=val,b=MOD,x=1,y=0;
        while(b)tmp=a/b,a-=tmp*b,swap(a,b),x-=tmp*y,swap(x,y);
        return modint(x);
    }
public:
    modint():val(0){}
    modint(ll x){if((val=x%MOD)<0)val+=MOD;}
    modint pow(ll t){modint res=1,b=*this; while(t){if(t&1)res*=b;b*=b;t>>=1;}return res;}
    modint& operator+=(const modint& x){if((val+=x.val)>=MOD)val-=MOD;return *this;}
    modint& operator-=(const modint& x){if((val+=MOD-x.val)>=MOD)val-=MOD; return *this;}
    modint& operator*=(const modint& x){val=(ll)val*x.val%MOD; return *this;}
    modint& operator/=(const modint& x){return *this*=x.inv();}
    bool operator==(const modint& x) const{return val==x.val;}
    bool operator!=(const modint& x) const{return val!=x.val;}
    bool operator<(const modint& x) const{return val<x.val;}
    bool operator<=(const modint& x) const{return val<=x.val;}
    bool operator>(const modint& x) const{return val>x.val;}
    bool operator>=(const modint& x) const{return val>=x.val;}
    modint operator+(const modint& x) const{return modint(*this)+=x;}
    modint operator-(const modint& x) const{return modint(*this)-=x;}
    modint operator*(const modint& x) const{return modint(*this)*=x;}
    modint operator/(const modint& x) const{return modint(*this)/=x;}
};

modint dp[100010][2];
int main() {
  string l;
  cin >> l;
  int n = l.size();
  dp[0][0] = 1;
  for (int i = 0; i < n; ++i) { 
    if (l[i] == '1') {
      dp[i+1][1] += dp[i][0];
      dp[i+1][0] += modint(2)*dp[i][0];
    }
    else {
      dp[i+1][0] += dp[i][0];
    }
    dp[i+1][1] += modint(3)*dp[i][1];
  }
  modint ans = dp[n][0]+dp[n][1];
  cout << ans.val << endl;
}



Measured memory_bytes: 1280
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define fr(i,j,k) for(int i=j;i<k;i++)
#define f(n) fr(i,0,n)
#define f1(n) fr(i,1,n+1)
#define pb push_back
#define F first
#define S second
#define all(x) x.begin(), x.end()
const int mod = 1e9+7;
const int maxn = 100005;
ll dp[3005][3005];
vector<int>v;
ll solve(int l ,int r) {
	if (~dp[l][r]) {
		return dp[l][r];
	}
	if (l > r) {
		return dp[l][r] = 0;
	}
	dp[l][r] = max(v[r] - solve(l, r - 1), v[l] - solve(l + 1, r));
	return dp[l][r];
}
void go() {
	int n, k;
	cin >> n;
	v.pb(0);
	f(n) {
		int x;
		cin >> x;
		v.pb(x);
	}
	memset(dp, -1, sizeof(dp));
	cout << solve(1, n) << '\n';
}
int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int c = 0;
    int t;
    if (!c) {
        t = 1;
    }
    else {
        cin >> t;
    }
    while (t--) {
        go();
    }
    
}

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

int main() {
    int w, h, n;
    cin >> w >> h >> n;
    vector<vector<bool>> white(h, vector<bool>(w, true));
    for (int i=0; i<n; i++) {
        int x, y, a;
        cin >> x >> y >> a;
        if (a == 1) {
            for (int j=0; j<x; j++) {
                for (int k=0; k<h; k++) {
                    white[k][j] = false;
                }
            }
        }
        if (a == 2) {
            for (int j=x; j<w; j++) {
                for (int k=0; k<h; k++) {
                    white[k][j] = false;
                }
            }
        }
        if (a == 3) {
            for (int j=0; j<y; j++) {
                for (int k=0; k<w; k++) {
                    white[j][k] = false;
                }
            }
        }
        if (a == 4) {
            for (int j=y; j<h; j++) {
                for (int k=0; k<w; k++) {
                    white[j][k] = false;
                }
            }
        }
    }
    int ans = 0;
    for (auto i: white) {
        for (auto j: i) {
            if (j) ans++;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
using namespace std;
int main(){
  int a,b,c,d,e;
  cin>>a>>b>>c;
  cout<<min(b,c)<<endl;
  d=max(b,c);
  e=min(b,c);
  if(a-d-e<0)
    cout<<(a-d-e)*-1<<endl;
  else
    cout<<0<<endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<queue>
#include<list>
using namespace std;
int main() {
	string s;
	cin >> s;
	cout << s.substr(0, 4) << ' ' << s.substr(4, 8) << endl;
	return 0;



}

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

#include <bits/stdc++.h>
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define FFOR(i, a, b) FOR(i, a, b+1)
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) FOR(i, 1, n+1)
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define LEN(x) (int)(x).size()
#define DUMP(x) cerr<<__LINE__<<' '<<#x<<"="<<(x)<<endl;
#define pb push_back
#define eb emplace_back
#define mp make_pair

using namespace std;
using lint = long long;
using pii =  pair<int, int>;
using pll =  pair<lint, lint>;
template <typename T> using vc = vector<T>;
template <typename T> using vvc = vector<vector<T>>;
template <typename T> inline bool chmax(T &a, T b){if(a<b){a = b; return true;} return false;}
template <typename T> inline bool chmin(T &a, T b){if(a>b){a = b; return true;} return false;}

constexpr lint ten(int n) {return n==0 ? 1 : ten(n-1)*10;}

struct mint {
    long long x;
    static constexpr long long MOD = 998244353;

    mint(long long x=0):x((x%MOD+MOD)%MOD){}

    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(long long t) const {
        mint res = 1, a(*this);
        while(t){
            if(t&1) res *= a;
            t >>= 1, a *= a;
        }
        return res;
    }
    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;
    }
    friend istream& operator>>(istream& in, mint& a){
        long long _v; in>>_v;
        a = mint(_v);
        return in;
    }
    friend ostream& operator<<(ostream& out, const mint& a){
        return out<<a.x;
    }
    friend bool operator==(const mint& a, const mint& b){
        return a.x == b.x;
    }
    friend bool operator!=(const mint& a, const mint& b){
        return a.x != b.x;
    }
};

class FKnapsackForAllSubsets {
public:
    void solve(std::istream& in, std::ostream& out){
        ios_base::sync_with_stdio(false);
        in.tie(nullptr), out.tie(nullptr);
        int N, S;
        in>>N>>S;
        vc<int> A(N);
        for(auto& a : A) in>>a;
        vvc<mint> dp(N+1, vc<mint>(S+1, 0));
        dp[0][0] = 1;
        REP(i, N) REP(j, S+1){
            dp[i+1][j] += dp[i][j] * 2;
            if(j+A[i]<=S) dp[i+1][j+A[i]] += dp[i][j];
        }
        out<<dp[N][S]<<'\n';
    }
};


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


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

int main() {
  string S; cin >> S;
  int cnt = 0;
  for(int i = 0; i < S.size(); ++i){
    if(S.at(i) == 'o') cnt++;
  }
    
  if(S.size() < 8) cout << "YES" << endl;
  if(8 <= S.size()){
    if(cnt < S.size() - 7) cout << "NO" << endl;
    else cout << "YES" << endl;
  } 
}

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

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

    int n, t;
    cin >> n >> t;

    int mi = 1e9, d = -1e9, cnt = 1, a;
    REP(i, n){
        cin >> a;
        mi = min(mi, a);
        if(d < a - mi){
            d = a - mi;
            cnt = 1;
        }else if(d == a - mi){
            cnt++;
        }
    }
    cout << cnt << endl;


    return 0;
}

Measured memory_bytes: 256
n,m=map(int,input().split())
ab=[list(map(int,input().split())) for i in range(n)]
ab.sort(key=lambda x: x[0])
t=0
ans=0
while(m>0):
  if(ab[t][1]<m):
    m-=ab[t][1]
    ans+=ab[t][0]*ab[t][1]
    t+=1
  else:
    ans+=ab[t][0]*m
    m=0
print(ans)

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

int main(void)
{
    int n,flag[200000],i,j,count,sum=0;

    cin >> n;

    for(i=0;i<n;i++){
        cin >> flag[i];
    }

    for(i=n-1;i>=0;i--){
        count = 0;
        for(j=1;j<n/(i+1);j++){
            count += flag[(i+1)*(j+1)-1]; 
        }
        if(count%2) flag[i] = !flag[i];
        sum += flag[i];
    }

    cout << sum << endl;
    for(i=0;i<n;i++) if(flag[i]) cout << i+1 << " ";
    
    return 0;
}

Measured memory_bytes: 1792
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <stack>

using namespace std;

int main(){

	int n,table[10000],ans[3] = {0},tmp,length,S;

	scanf("%d",&n);

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

	for(int i = 0; i < n; i++){
		for(int k = 0; k < n; k++){
			if(i != k){
				S = 1;
				for(length = 0; ;length++){
					if(table[k]/S == 0){
						break;
					}else{
						S *= 10;
					}
				}
				tmp = table[i]*pow(10,length)+table[k];


				if(ans[0] == 0 || ans[1] == 0 || ans[2] == 0){
					if(ans[0] == 0){
						ans[0] = tmp;
					}else if(ans[1] == 0){
						if(tmp < ans[0]){
							ans[1] = ans[0];
							ans[0] = tmp;
						}else{
							ans[1] = tmp;
						}
					}else{ //ans[2] == 0
						if(tmp < ans[0]){
							ans[2] = ans[1];
							ans[1] = ans[0];
							ans[0] = tmp;
						}else if(tmp < ans[1]){
							ans[2] = ans[1];
							ans[1] = tmp;
						}else{
							ans[2] = tmp;
						}
					}
				}else{
					if(tmp < ans[0]){
						ans[2] = ans[1];
						ans[1] = ans[0];
						ans[0] = tmp;
					}else if(tmp < ans[1]){
						ans[2] = ans[1];
						ans[1] = tmp;
					}else if(tmp < ans[2]){
						ans[2] = tmp;
					}
				}
			}
		}
	}
	printf("%d\n",ans[2]);

	return 0;
}

Measured memory_bytes: 2956
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i < (n+1); ++i)
const double PI  =3.141592653589793238463;
using namespace std;
using ll = long long;
const ll INF = +10010010000;
typedef pair<int,int> P;
const int mod = 1e9+7;

struct mint{
    ll x;
    mint(ll x=0):x((x%mod+mod)%mod){}
    mint& operator+=(const mint a){
        (x+=a.x)%=mod;
        return *this;
    }
    mint& operator-=(const mint a){
        (x-=mod-a.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;
    }

    // for prime mod
    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;
    }
};

struct combination{
  vector<mint> fact, ifact;
  combination(int n):fact(n+1),ifact(n+1){
    fact[0] = 1;
    for(int i = 1; i<n;++i)fact[i] = fact[i-1] * i;
    ifact[n] = fact[n].inv();
    for(int i = n; i>=1;--i) ifact[i-1] = ifact[i] * i;
  }
  mint operator()(int n, int k){
    if(k<0 || k>n)return 0;
    return fact[n] * ifact[k] + ifact[n-k]; 
  }
};

int main(){
    vector<int> x(5);
    rep(i,5) cin >> x[i];
    rep(i,5){
        if(x[i] == 0){
            cout << i+1<<endl;
            return 0;
        }
    }
    return 0;
}

Measured memory_bytes: 3620
#include <bits/stdc++.h>
#define rep(i, n) for (int i=0; i<(int)(n); i++)
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
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;}
/*
void chmin(ll a, ll b){if (a>b){a = b; return true;}return false;}
void chmax(ll a, ll b){if (a<b){a = b; return true;}return false;}
*/

const ll MOD = 1000000007;
const ll INF = 9999999999;

int main() {
  string s; cin >>s;
  int n = s.size();
  int G = 0, P = 0;
  for (int i=0; i<n; i++){
    if (s.at(i) == 'g'){
      G++;
    }else{
      P++;
    }
  }
  int ans = (G-P)/2;
  cout <<ans <<endl;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
#define nl '\n'
int main()
{
   string d="delicious",s="safe",dd="dangerous";
    int x,y,z;
    cin>>x>>y>>z;
    if(z<=y)
      cout<<d;
    else if(abs(y-z)<=x)
      cout<<s;
    else
      cout<<dd;
    cout<<nl;
    return 0;
}


Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <cassert>
#include <string>
#include <vector>
#include <utility>
#include <complex>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <deque>
#include <tuple>
#include <bitset>
#include <limits>
#include <algorithm>
#include <array>
#include <random>
#include <complex>
#include <regex>
#include <iomanip>
using namespace std;
typedef long double ld;
typedef long long ll;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define fcout cout << fixed << setprecision(10)
#define rep(i,n)    for(int i=0; i<(int)n; i++)
#define mp(a,b) make_pair(a,b)
#define pb push_back
#define all(x) x.begin(), x.end()
#define F first
#define S second
const ll inf = 1e18;
const ll mod = 1e9 + 7;

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

// mod. m での a の逆元 a^(-1) を計算する。
ll modinv(ll a, ll m) {
    ll b = m, u = 1, v = 0;
    while (b) {
        ll t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}

ll modpow(ll a, ll n){
    ll res = 1;
    while(n>0){
        if(n&1){
            res = res * a % mod;
        }
        a = a * a % mod;
        n >>=1;
    }
    return res;
}



int main(){
    int d;
    cin >> d;
    ll ans=0;
    int c[26]; // 満足度の下がりやすさ、（d-最終日）* cだけその日の終わりに引かれる。
    int last[26] = {0};
    int s[365][26]; // d日目にタイプiのコンテストを開いた時の上昇量
    int t[365];
    rep(i, 26) cin >> c[i];
    rep(i,d) rep(j,26) cin >> s[i][j];

    rep(i,d){
        int t=0;
        rep(j,26){
            if(s[i][t] < s[i][j]) t = j;
        }
        printf("%d\n", t+1);
    }
}

Measured memory_bytes: 3800
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <set>
using namespace std;
//________
#define pb        emplace_back
#define fi        first
#define se        second
#define ALL(x)    x.begin(),x.end()
#define err(...)  fprintf(stderr, __VA_ARGS__ )
#define show(x)   cerr << #x << ':' << (x) << endl
#define outl(x)   cout << (x) << '\n'
#define FAST()    cin.tie(0), ios::sync_with_stdio(false)
#define rep(i,n)     for(int i=0; i<(n); ++i)
#define reps(i,f,n)  for(int i=(f); i<=(n); ++i)
template<class A, class B>inline bool chmax(A &a, B b){return b>a ? a=b,1 : 0;}
template<class A, class B>inline bool chmin(A &a, B b){return b<a ? a=b,1 : 0;}
inline bool inside(int y, int x, int H, int W){return(y>=0 && x>=0 && y<H && x<W);}
constexpr int dx[] = {1, 0, -1, 0,  1, 1, -1, -1};
constexpr int dy[] = {0, 1, 0, -1,  -1, 1, 1, -1};
typedef long long ll;
typedef pair<int,int> pii;
#define let const auto
#define INF  0x3f3f3f3f
#define LINF 0x3f3f3f3f3f3f3f3f
#define NIL -1
//________

int N;
pii a[200010];
int idx[200010];

signed main()
{
   FAST();

   cin >> N;
   rep(i, N) {
      cin >> a[i].fi;
      a[i].se = i;
   }

   sort(a, a+N);

   int right = N / 2;
   int left = N / 2 - 1;


   // for (int i=0; i<N; ++i) {
   //    if (i < N/2) {
   //       //right
   //       if (a[right].se == i) {
   //          outl(a[right - 1].fi);
   //       } else {
   //          outl(a[right].fi);
   //       }
   //    }
   //    else {
   //       //left
   //       if (a[left].se == i) {
   //          outl(a[left + 1].fi);
   //       } else {
   //          outl(a[left].fi);
   //       }
   //    }
   // }

   const int len = N / 2;
   for (int i=0; i<N; ++i) {
      idx[ a[i].se ] = i;
   }

   for (int i=0; i<N; ++i) {
      int pos = idx[i];
      if (pos >= len) {
         outl(a[len-1].fi);
      }
      else {
         outl( a[len].fi );
      }
   }
}



Measured memory_bytes: 4608