akhauriyash/Code-Regression huggingface dataset:
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();
		int value = a + b + c;
		int product = a * b * c;
		if (value == 5 + 5 + 7 & product == 5 * 5 * 7) {
			System.out.println("YES");
		} else {
			System.out.println("NO");
		}
	}
}


Measured memory_bytes: 21844
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i <= (int)(n); i++)
typedef int64_t Int;

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

    Int sum = 0;
    rep1(i,N){
        if(i % 3 != 0 && i % 5 != 0){
            sum += i;
        }
    }
    cout << sum << endl;
}


Measured memory_bytes: 3624
#include <iostream>
#include <vector>
#include <fstream>
#include <algorithm>
#include <iomanip>
#include <map>
#include <queue>
#include <stack>
#include <set>
#include <ctime>
#include <iterator>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
using namespace std;

int main()
{
    stack<int> s;
    int z;
    while(cin>>z)
    {
        if(z==0)
        {
            cout<<s.top()<<endl;
            s.pop();
        }
        else s.push(z);
    }
}

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

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

  vector<int> H(N, 0);
  for (int i = 0; i < N; i++) {
    scanf("%d", &H.at(i));
  }
  
  bool is_first = true;
  int baseline;
  for (int i = 0; i < N - 1; i++) {
    if (H.at(i) > H.at(i + 1)) {
      H.at(i)--;
      if (is_first) {
        baseline = H.at(i);
        is_first = false;
      } else {
        if (H.at(i) < baseline) {
          printf("No");
          return 0;  
        } else {
          baseline = H.at(i);
        }
      }
    }

    if (H.at(i) > H.at(i + 1)) {
      printf("No");
      return 0;
    }
  }

  printf("Yes");
  return 0;
}

Measured memory_bytes: 640
#include<cstdio>
#include<iostream>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<set>
#include<map>
#include<vector>
#include<stack>
#include<queue>
#include<deque>
#include<list>
#include<cstdlib>
#include<ctime>
#include<cctype>

using namespace std;

int dp[100050][3];
int n;
int main()
{
	cin >> n;
	for(int i = 1; i <= n; i++)
	{
		int a, b, c;
		cin >> a >> b >> c;
		dp[i][1] = max(dp[i-1][0], dp[i-1][2])+ b;
		dp[i][0] = max(dp[i-1][1], dp[i-1][2])+ a;
		dp[i][2] = max(dp[i-1][0], dp[i-1][1]) + c;
	}
	cout << max(max(dp[n][0], dp[n][1]), dp[n][2]) << endl;
	return 0;
}

Measured memory_bytes: 1408
#include<bits/stdc++.h>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) for(int i = 0; i < (b); i++)
#define all(a) (a).begin(), (a).end()
#define show(x)  cerr << #x << " = " << (x) << endl;
using namespace std;

const int gmax_n = 505;

int cntX[2][gmax_n] = {0};
int cntY[2][gmax_n] = {0};
bool usa[gmax_n][gmax_n] = {{0}}, neko[gmax_n][gmax_n] = {{0}};

int checkPointU(int n, int u, pair<int, int> p){
    int y = p.first;
    int x = p.second;
    usa[y][x] = 1;


    int cnt = 0;
    cntX[0][x]++;
    cntY[0][y]++;

    rep(i,n){
        if(cntX[0][i] == n) cnt++;
        if(cntY[0][i] == n) cnt++;
    }

    bool f = true;
    rep(i,n) if(usa[i][i] == 0) f = false;
    if(f) cnt++;

    f = true;
    rep(i,n) if(usa[i][n - 1 - i] == 0) f = false;
    if(f) cnt++;
    //y = find(y,parY[0][x], cntY[0][x]);
    //x = find(x,parX[0][y], cntX[0][y]);
    //show(cntX[0][y][x])
    //show(cntY[0][x][y])
    //show(cnt)
    if(n == 1) cnt = 1;
    if(cnt >= u || cnt >= u) return 1;
    else return 0;
}

int checkPointN(int n, int v, pair<int, int> p){
    int y = p.first;
    int x = p.second;
    neko[y][x] = 1;


    int cnt = 0;
    cntX[1][x]++;
    cntY[1][y]++;

    rep(i,n){
        if(cntX[1][i] == n) cnt++;
        if(cntY[1][i] == n) cnt++;
    }

    bool f = true;
    rep(i,n) if(neko[i][i] == 0) f = false;
    if(f) cnt++;

    f = true;
    rep(i,n) if(neko[i][n - 1 - i] == 0) f = false;
    if(f) cnt++;
    //y = find(y,parY[0][x], cntY[0][x]);
    //x = find(x,parX[0][y], cntX[0][y]);
    //show(cntX[0][y][x])
    //show(cntY[0][x][y])

    if(n == 1) cnt = 1;
    if(cnt >= v || cnt >= v) return 1;
    else return 0;
}

int main(){
    int n, u, v, m;
    cin >> n >> u >> v >> m;

    int x;
    map<int,pair<int, int>> up, np;
    rep(i,n){
        rep(j,n){
            cin >> x;
            up[x] = make_pair(i,j);
        }
    }
    rep(i,n){
        rep(j,n){
            cin >> x;
            np[x] = make_pair(i,j);
        }
    }

    int ans = 0;
    rep(i,m){
        int a;
        cin >> a;
        //cout << a << endl;
        if(ans == 0){
            int utmp = -1, vtmp = -1;
            utmp = (up.count(a) ? checkPointU(n,u,up[a]) : 0);
            vtmp = (np.count(a) ? checkPointN(n,v,np[a]) : 0);
//            show(utmp)
            //show(vtmp)
            if(utmp == 0 && vtmp != 0) ans = 1;
            else if(utmp != 0 && vtmp == 0) ans = 2;
            else if(utmp != 0 && vtmp != 0) ans = 3;
            else if(utmp == 0 && vtmp == 0);
            else assert(0);
        }
 //       show(ans)
 //           rep(i,n){ rep(j,n){ cout << usa[i][j]; } cout << endl; }
 //       cout << endl;
 //           rep(i,n){ rep(j,n){ cout << neko[i][j]; } cout << endl; }
    }
    if(ans == 1) cout << "NEKO" << endl;
    else if(ans == 2) cout << "USAGI" << endl;
    else cout << "DRAW" << endl;
}

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

int main(){
  string S;
  cin>>S;
  int i,k,ppp;
  ppp=0;
  std::vector<int> v(26,0);
  if(S.size()==26){
    if(S=="zyxwvutsrqponmlkjihgfedcba")cout<<-1;
    else{
      for(i=25;i>=0;i--){
        for(k=(char)S[i]-97;k<26;k++){
          if(v[k]){ppp++;break;}
        }
        if(ppp)break;
        else v[(char)S[i]-97]++;
      }
      for(int j=0;j<i;j++)cout<<S[j];
      cout<<(char)(k+97);
    }
  }
  else{
    cout<<S;
    sort(S.begin(),S.end());
    for(i=0;i<S.size();i++){
      if(S[i]!=97+i){
        cout<<(char)(97+i);
        break;
      }
    }
    if(i==S.size())cout<<(char)(97+i);
  }
  cout<<endl;
}


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

int main()
{
	int a,b;
	cin >> a >> b;
	int ans;
	if (a+b == 3)
	{
		ans = 3;
	}
	else if (a+b == 4)
	{
		ans = 2;
	}
	else
	{
		ans = 1;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<set>
#define FOR(i,a,b) for(int i=a;i<=b;i++)
using namespace std;
int n;
int a[123456];
int main()
{
	scanf("%d",&n);
	FOR(i,1,n)
	  scanf("%d",a+i);
	multiset <int> S;
	int d=0;  
	FOR(i,1,n) d=max(a[i],d),S.insert(a[i]);
	int low=d+1;
	FOR(i,0,d)
	{
		int tmp=max(i,d-i);
		if( S.find(tmp)== S.end() ) 
		  {   
		     puts("Impossible");
		     return 0;
		  } 
		S.erase(S.find(tmp));  //phai xoa dung 1 vi tri
		low=min(low,tmp);  
    }
    if(!S.empty() && (*S.begin())<= low) 
      {
      	   puts("Impossible");
      	   return 0;
      }
    else puts("Possible");  
	return 0;
}

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

namespace Finding_a_Word
{
    class Program
    {
        static void Main(string[] args)
        {
            List<string> input = new List<string>();

            string word = Console.ReadLine().ToLower();

            while (true)
            {
                string[] temp = Console.ReadLine().Split(' ');
                if (temp[temp.Length - 1].Equals("END_OF_TEXT"))
                {
                    break;
                }

                foreach (string item in temp)
                {
                    input.Add(item.ToLower());
                }
            }

            int count = 0;
            foreach (string item in input)
            {
                if (item.Equals(word))
                {
                    ++count;
                }
            }
            Console.WriteLine(count);
        }
    }
}



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

int n,m,x[111116];

struct matrix{
	long long f[3][3];
}a,b,e,f;

matrix operator *(matrix a,matrix b){
	static matrix c;
	memset(c.f,0,sizeof(c.f));
	for (int i=0;i<=2;i++)
		for (int j=0;j<=2;j++)
			for (int k=0;k<=2;k++)
				c.f[i][j]=(c.f[i][j]+a.f[i][k]*b.f[k][j])%mod;
	return c;
}

matrix power(matrix x,int y){
	static matrix t;t=e;
	for (;y;x=x*x,y/=2)
		if (y&1) t=t*x;
	return t;
}

int read(){
	int x=0;char ch=getchar();
	for (;!isdigit(ch);ch=getchar());
	for (;isdigit(ch);ch=getchar()) x=x*10+ch-'0';
	return x;
}

int main(){
	a.f[0][0]=1;a.f[0][1]=2;a.f[0][2]=1;
	a.f[1][0]=0;a.f[1][1]=1;a.f[1][2]=1;
	a.f[2][0]=0;a.f[2][1]=0;a.f[2][2]=1;
	
	b.f[0][0]=1;b.f[0][1]=0;b.f[0][2]=0;
	b.f[1][0]=0;b.f[1][1]=1;b.f[1][2]=0;
	b.f[2][0]=1;b.f[2][1]=0;b.f[2][2]=1;
	
	e.f[0][0]=1;e.f[0][1]=0;e.f[0][2]=0;
	e.f[1][0]=0;e.f[1][1]=1;e.f[1][2]=0;
	e.f[2][0]=0;e.f[2][1]=0;e.f[2][2]=1;
	
	f.f[0][0]=1;
	
	n=read();m=read();
	for (int i=1;i<=m;i++) x[i]=read();
	for (int i=1;i<=m;i++) f=f*power(a*b,x[i]-x[i-1]-1)*a;
	f=f*power(a*b,n-x[m]);
	printf("%lld\n",f.f[0][2]);
	return 0;
}

Measured memory_bytes: 640
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);

      	int a = sc.nextInt();
      
      	a %= 1000;
      	if(a == 0) a = 1000;
     
        System.out.println(1000 - a);
        
	}
}

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


int main () {
  string S, ans = "Yes";
  int all_count = 0;
  cin >> S;

  for (int i = 0; i < 3; i++) {
    int count = 0;
    for (int j = i + 1; j < 4; j++) {
      if (S.at(i) == S.at(j)) count++;
    }
    if (count == 1) all_count++;
  }
  if (all_count != 2) ans = "No";
  cout << ans << endl;
}


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

int main() {
	int n;
	string temp;
	cin >> temp;
	n = temp.length();
	int ob = 0, ow = 0, eb = 0, ew = 0;
	for (int i = 0; i < n; i++) {
		if (i % 2 == 0) {
			if (temp[i] == '0') {
				eb++;
			}
			else {
				ew++;
			}
		}
		else {
			if (temp[i] == '0') {
				ob++;
			}
			else {
				ow++;
			}
		}
	}
	cout << min(ob + ew, ow + eb) << endl;
	return 0;
}

Measured memory_bytes: 3724
from itertools import accumulate

# bisectはどっちでも（どちらに等号をつけても）うまくいくっぽい
from bisect import bisect_right, bisect_left

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

# 累積和を前計算
cumsum = list(accumulate(A))
cumsum.insert(0, 0)  # out of index 対策


ans = float('inf')
# 真ん中を全探索
for i in range(2, N-1):  # 左側は最低2つ残さなきゃいけないから2から(0もあるので）、右も同じ理由でN-1
    # 左の真ん中
    Lmid = cumsum[i] / 2

    # 左真ん中がどこに入るべきか
    Lx = bisect_left(cumsum, Lmid)

    # Lxまで取るのか、Lx-1まで取るのか（どこまで取ると望ましい値Lmidに近づくのか）
    # 左側がLmidに近づくと右側もLmidに近づく→差の絶対値が0に近づく
    if abs(cumsum[Lx-1] - Lmid) < abs(cumsum[Lx] - Lmid):
        Lx -= 1


    # 右側処理（基本は左と同じ）
    Rmid = (cumsum[N] + cumsum[i]) / 2  # 3分探索に要領でcumsum[N]を加えてやる
    Rx = bisect_left(cumsum, Rmid)
    # 超えるべきか超えないべきか
    if abs(cumsum[Rx-1] - Rmid) < abs(cumsum[Rx] - Rmid):
        Rx -= 1


    # 左からLx個の和
    P = cumsum[Lx]

    # Lx番目+1から真ん中区切りiまでの和
    Q = cumsum[i]-cumsum[Lx]

    # 真ん中区切りのi+1番目からRx番目までの和
    R = cumsum[Rx]-cumsum[i]

    # Rx+1番目から最後まで
    S = cumsum[N]-cumsum[Rx]
    
    ans = min(ans, max(P, Q, R, S) - min(P, Q, R, S))

print(ans)


Measured memory_bytes: 24296
#include <bits/stdc++.h>
#define all(a) (a).begin(), (a).end()
#define REP(i, n) for(int (i)=0; (i)<(n); (i)++)
#define RREP(i, n) for(int (i)=(n)-1, (i)>=0; (i)--)
#define ios() cin.tie(0), ios::sync_with_stdio(false)
typedef long long ll;
typedef unsigned long long ull;
ll const MOD = 1e9+7;
ll const INF = 1e18;
using namespace std;

int main(){
    int n;
    string str;
    cin >> n >> str;
    deque<char> deq;
    
    REP(i, str.length()){
        if(str[i] == '('){
            deq.push_back(str[i]);
        }else{
            if(!deq.empty() && deq.back() == '('){
                deq.pop_back();
            }else{
                deq.push_back(str[i]);
            }
        }
    }

    while(!deq.empty()){
        if(deq.front() == ')'){
            str = '(' + str;
        }else{
            str += ')';
        }
        deq.pop_front();
    }

    cout << str << endl;

    return 0;
}

Measured memory_bytes: 256
let N = Int(readLine()!)!
var sumE = 0
for _ in 1..<N {
    let line = readLine()!.split(separator: " ").map { Int($0)! }.sorted()
    let (u, v) = (line[0], line[1])
    sumE += u * (N-v+1)
}

let sumV = N*(N+1)*(N+2) / 6
print(sumV - sumE)


Measured memory_bytes: 8304
#include<bits/stdc++.h>
#define boost ios::sync_with_stdio(false); cin.tie(0)
#define ll              long long int
#define ld              long double
#define mk              make_pair
#define pb              push_back
#define f               first
#define s               second
#define fo(i,a,b)       for(i=a;i<b;i++)
#define foe(i,a,b)      for(i=a;i<=b;i++)
#define all(x)          x.begin(),x.end()
#define vi              vector<int>
#define vl              vector <long long int>
#define pii             pair <int,int>
#define pll             pair <long long int, long long int>
#define vpii            vector< pair<int,int> >
#define vpll            vector < pair <long long int,long long int> >
#define MOD             1000000007
using namespace std;
const int inf = INT_MAX;
const ll inf64 = LLONG_MAX;


int main()
{
    boost;
    ll n,k;
    cin >> n >> k;
    ll i;
    vi cnt(n);
    fo(i,0,k)
    {
    	ll d;
    	cin >> d;
    	while(d--)
    	{
    		ll num;
    		cin >> num;
    		num--;
    		cnt[num]++;
    	}
    }
    ll ans = 0;
    fo(i,0,n)if(cnt[i]==0)ans++;
    cout << ans;
    
    return 0;
}

Measured memory_bytes: 3496
#include <bits/stdc++.h>
using namespace std;
map<string,int >Map;
int M,N;
string ss;
string x;
vector<pair<string,int > >Ready;
int cnt;
void test()
{
    cout<<"test: "<<endl;
    for(map<string,int>::iterator iter=Map.begin();iter!=Map.end();iter++)
    {
        cout<<iter->first<<" "<<iter->second<<endl;
    }
    return ;
}
void add()
{
    map<string ,int>::iterator iter=Map.begin();
    cnt=0;
    Ready.clear();
    for(;iter!=Map.end();iter++)
    {
        string a=iter->first;
        x="";
        for(int i=0;i<M;i++)
        {
            if(a[i]==ss[i])
            {
                x+='0';
            }
            else
            {
                x+='1';
            }
        }
        if(Map.find(x)!=Map.end())
        {
            if(Map[x]<1+iter->second)
            {
                Ready.push_back(make_pair(x,1+iter->second));
                cnt++;
            }
        }
        else
        {
           Ready.push_back(make_pair(x,1+iter->second));
                cnt++;
        }
    }
    for(int i=0;i<cnt;i++)
    {
        if(Map.find(Ready[i].first)==Map.end())
        {
            Map.insert(Ready[i]);
        }
        else
        {
            Map[Ready[i].first]=Ready[i].second;
        }
    }
    return ;
}
int main() {

    std::ios::sync_with_stdio(false);
    while(cin>>N>>M)
    {
        if(M==0&&N==0)
        {
            return 0;
        }
        Map.clear();
        ss="";
        for(int i=0;i<M;i++)
        {
            ss+='0';
        }
        Map.insert(make_pair(ss,0));
        for(int i=0;i<N;i++)
        {
            cin>>ss;
            add();
        }
        ss="";
        for(int i=0;i<M;i++)
        {
            ss+='0';
        }
        cout<<Map[ss]<<endl;
    }
    return 0;
}



Measured memory_bytes: 158648
#import sys
import numpy as np
#from collections import defaultdict
#import math
#from collections import deque

#input = sys.stdin.readline
#import decimal

def main():
    N = int(input())
    S = input()
    S_new =""
    for i in range(len(S)):
         S_new +=chr((ord(S[i])+N-ord("A"))%26+ord("A"))
    print(S_new)
if __name__ == "__main__":
    main()

Measured memory_bytes: 27200
#!/usr/bin/env python
# -*- coding: utf-8 -*-

"""
input:
2
2 2
5 3

output:
......Q.
Q.......
..Q.....
.......Q
.....Q..
...Q....
.Q......
....Q...
"""

import sys

N = 8
FREE, NOT_FREE = -1, 1


def generate_board(_q_list):
    for queen in _q_list:
        x, y = map(int, queen)
        init_q_check[x][y] = True

    return init_q_check


def print_board():
    for i in range(N):
        for j in range(N):
            if q_check[i][j]:
                if row[i] != j:
                    return None

    for i in range(N):
        print(''.join(('Q' if row[i] == j else '.' for j in range(N))))

    return None


def recursive(i):
    if i == N:
        print_board()
        return None

    for j in range(N):
        if ((col[j] is NOT_FREE) or
                (dpos[i + j] is NOT_FREE) or
                (dneg[i - j + N - 1] is NOT_FREE)):
            continue

        row[i] = j
        col[j] = dpos[i + j] = dneg[i - j + N - 1] = NOT_FREE

        recursive(i + 1)

        row[i] = col[j] = dpos[i + j] = dneg[i - j + N - 1] = FREE

    return q_check


if __name__ == '__main__':
    _input = sys.stdin.readlines()
    q_num = int(_input[0])
    q_list = map(lambda x: x.split(), _input[1:])

    # initialize
    row, col = ([FREE] * N for _ in range(2))
    dpos, dneg = ([FREE] * (2 * N - 1) for _ in range(2))

    init_q_check = [[False] * N for _ in range(N)]
    q_check = generate_board(q_list)

    ans = recursive(0)

Measured memory_bytes: 7816
#include <bits/stdc++.h>
#define FOR(i, begin, end) for(int i=(begin);i<(end);i++)
#define REP(i, n) FOR(i,0,n)
#define IFOR(i, begin, end) for(int i=(end)-1;i>=(begin);i--)
#define IREP(i, n) IFOR(i,0,n)
#define SORT(a) sort(a.begin(), a.end())
#define REVERSE(a) reverse(a.begin(), a.end())
#define int long long
#define INF 1000000000000000
using namespace std;

typedef pair<int, int> Pii;

template<typename T>
void readvec(vector<T> &a);
void readindex(vector<int> &a);

#define MAX_V 700
int V;
struct edge{int to, cost;};
vector<edge> G[MAX_V];

void add_edge(int from, int to, int cost){
    G[from].push_back(edge({to, cost}));
}

void add_edge2(int v1, int v2, int cost){
    G[v1].push_back(edge({v2, cost}));
    G[v2].push_back(edge({v1, cost}));
}

vector<int> color(MAX_V, -1);
bool dfs(int v, int a[2]){
    REP(i, G[v].size()){
        if(color[G[v][i].to] == -1){
            color[G[v][i].to] = 1 - color[v];
            a[color[G[v][i].to]]++;
            if(!dfs(G[v][i].to, a)) return false;
        }else{
            if(color[v] == color[G[v][i].to]) return false;
        }
    }
    return true;
}

signed main(){

    int N, M; cin >> N >> M;
    V = N;
    vector< vector<bool> > is_exist(N, vector<bool>(N, false));
    int A, B;
    REP(i, M){
        cin >> A >> B;
        is_exist[A - 1][B - 1] = true; is_exist[B - 1][A - 1] = true;
    }
    REP(i, N){
        REP(j, i){
            if(!is_exist[i][j]) add_edge2(i, j, 1);
        }
    }

    vector<int> t1(0), t2(0);
    REP(i, N){
        if(color[i] == -1){
            int a[2] = {1, 0};
            color[i] = 0;
            if(!dfs(i, a)){
                cout << -1;
                return 0;
            }
            t1.push_back(a[0]);
            t2.push_back(a[1]);
        }
    }

    int n = t1.size();
    int K = N / 2;
    vector< vector<bool> > dp(n + 1, vector<bool>(K + 1, 0));
    dp[0][0] = true;
    REP(i, n){
        REP(k, K + 1){
            if(dp[i][k]){
                if(k + t1[i] <= K) dp[i + 1][k + t1[i]] = true;
                if(k + t2[i] <= K) dp[i + 1][k + t2[i]] = true;
            }
        }
    }

    int N1, N2;
    IREP(i, K + 1){
        if(dp[n][i]){
            N1 = i;
            break;
        }
    }
    N2 = N - N1;

    cout << N1 * (N1 - 1) / 2 + N2 * (N2 - 1) / 2;
    
    return 0;
}


template<typename T>
void readvec(vector<T> &a){
    REP(i, a.size()){
        cin >> a[i];
    }
}
void readindex(vector<int> &a){
    REP(i, a.size()){
        cin >> a[i];
        a[i]--;
    }
}

Measured memory_bytes: 11008
#include <bits/stdc++.h>
#define int long long
#define mod (int)(1e9+7)
#define inf (int)(3e18)
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<n;i++)
#define P std::pair<int,int>
#define PiP std::pair<int,std::pair<int,int>>
#define all(v) v.begin(),v.end()
#define mkp std::make_pair
#define prique(T) std::priority_queue<T,vector<T>,greater<T>>
using namespace std;
template<class T> inline void chmax(T& a, T b) { a = std::max(a, b); }
template<class T> inline void chmin(T& a, T b) { a = std::min(a, b); }

bool prime(int x) {
	for (int i = 2; i * i <= x; i++) {
		if (x % i == 0)return false;
	}
	return x != 1;
}
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x % y);
}
int lcm(int x, int y) {
	return x / gcd(x, y) * y;
}
int kai(int x, int y) {
	int res = 1;
	for (int i = x - y + 1; i <= x; i++) {
		res *= i; res %= mod;
	}
	return res;
}
int mod_pow(int x, int y, int m) {
	int res = 1;
	while (y > 0) {
		if (y & 1) {
			res = res * x % m;
		}
		x = x * x % m;
		y >>= 1;
	}
	return res;
}
int comb(int x, int y) {
	if (y > x)return 0;
	return kai(x, y) * mod_pow(kai(y, y), mod - 2, mod) % mod;
}
int get_rand(int MIN, int MAX) {
	std::random_device rnd;
	std::mt19937_64 mt64(rnd());
	std::uniform_int_distribution<int>engine(MIN, MAX);
	return engine(mt64);
}
/*--------Library Zone!--------*/


signed main() {
	int n, k, ans = 0;
	cin >> n >> k;
	rep(i, n) {
		int a; cin >> a;
		if (a >= k)ans++;
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

typedef struct name
{
	int value;
	struct name* next;
	int isodd;
}p_list;

int main()
{
	int n,i,j,m=0;//m:evenpath.size
	int u,v,w,startnode=100010;
	//path evenpath[100010];
	p_list* narr[100010]={(p_list *)0};//関係を持つノードの配列
	int nsizarr[100010]={0};
	int ans[100010]={0};
	scanf("%d",&n);
	for(i=0;i<n-1;i++)
	{
		scanf("%d %d %d",&u,&v,&w);
		
		p_list* lp=(p_list *)calloc(1,sizeof(p_list));
		lp->next=narr[u];
		narr[u]=lp;
		lp->value=v;
		lp->isodd=w%2;
		
		lp=(p_list *)calloc(1,sizeof(p_list));
		lp->next=narr[v];
		narr[v]=lp;
		lp->value=u;
		lp->isodd=w%2;
		
		if(u<startnode)startnode=u;
	}
	
	int treenodes[100010]={0};
	int nextnodes[100010]={0};
	treenodes[0]=startnode;
	ans[startnode]=1;
	int treesize=1;
	int nextsize=1;
	while(nextsize!=0)
	{
		nextsize=0;
		for(i=0;i<treesize;i++)
		{
			//j=0;
			//printf("a: %d\n",narr[treenodes[0]][0]);
			while(narr[treenodes[i]]!=NULL)
			{
				int prevnum=treenodes[i];
				int nextcnd=narr[treenodes[i]]->value;
				//printf("from:%d\n",prevnum);
				//printf("to:%d\n",nextcnd);
				
				if(ans[nextcnd]==0)//まだnextcndが未探索(木に加えられていない)なら
				{
					//printf("add: %d\n",nextcnd);
					if(narr[prevnum]->isodd)
					{
						nextnodes[nextsize]=nextcnd;
						nextsize++;
					}
					else
					{
						treenodes[treesize]=nextcnd;
						treesize++;
					}
				}
				if(narr[prevnum]->isodd)ans[nextcnd]=ans[prevnum]+1;
				else ans[nextcnd]=ans[prevnum];
				//j++;
				narr[prevnum]=narr[prevnum]->next;
			}
		}
		memcpy(treenodes,nextnodes,sizeof(nextnodes));
		treesize=nextsize;
			//printf("go next\n");
	}
	
	for(i=0;i<n;i++)
	{
		printf("%d\n",ans[i+1]%2);
	}
	
}


Measured memory_bytes: 8576
#include <bits/stdc++.h>
#define endl "\n"
using namespace std;
#define ll long long
#define ld long double
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define repo(i,n) for(int i = 1; i < (int)(n); i++)
#define pb push_back
#define mp make_pair
#define np next_permutation
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
#define uniq(v) v.erase(unique(v.begin(),v.end()),v.end())
#define lb(v,x) (lower_bound(v.begin(),v.end(),x)-v.begin())
#define ub(v,x) (upper_bound(v.begin(),v.end(),x)-v.begin())
using Pair = pair<ll,pair<int,int>>;
#define pq priority_queue<Pair, vector<Pair>, greater<Pair>> 
const ll mod=1000000007;
//const ll mod=998244353;
const ld pi=acos(-1.0);
const ll INF = 1LL<<61;
template<class T>bool chmax(T &a, const T &b) { 
  if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) {
  if (b<a) { a=b; return 1; } return 0; }
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }
//intの最大値2147483647 ≒ 2×10^9
//long longの最大値9223372036854775807 ≒ 9×10^18
//'大文字'+=32;    で小文字に
//  cout << fixed << setprecision (20);   小数点以下2０桁まで
//実行時間制約2秒では２×10^8回くらいまで計算できる




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

  ll n,m;
  cin>>n>>m;

  vector<ll> p(n);
  rep(i,n){
    cin>>p[i];
  }

  sort(all(p));

//ok以上の握手がm個以上ある
//————————————————二分探索——————————————————————————

  ll ng = INF;
  ll ok = 0;
  while (abs(ok - ng) > 1) {
    ll mid = (ng + ok) / 2;

    ll cnt=0;
    rep(i,n){
      int x = lb(p,mid-p[i]);
      if(x<n) cnt+=n-x;
    }
    (cnt>=m? ok : ng) = mid;
  }

//——————————————————————————————————————————

  auto rui=p;
  for(int i=n-2;i>=0;i--){
    rui[i]+=rui[i+1];
  }

  ll cnt=0;
  ll ans=0;
  rep(i,n){
    int x = lb(p,ok-p[i]);
    if(x<n) {
      cnt+=n-x;
      ans+=p[i]*(n-x)+rui[x];
    }
  }
  if(cnt>m) ans-=(cnt-m)*ok;

  cout << ans << endl;
}

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

int main() {
 int n,a,b;
  cin >> n >> a >> b;
  if((b-a)%2==0)cout<< "Alice"<<endl;
  else cout << "Borys"<<endl;
}

Measured memory_bytes: 256
n,x = map(int,input().split())
a = list(map(int,input().split()))
a.sort()
ans = 0
if sum(a) == x:
    ans = n
elif sum(a) < x:
    ans = n - 1
else:
    for i in range(n):
        if a[i] <= x:
            ans += 1
            x -= a[i]
print(ans)


Measured memory_bytes: 3060
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
#include<queue>
#include<functional>
using namespace std;
int main() {
	string S; cin >> S;
	for (int i = 0; i < S.size() - 1; i++) {
		if (S.substr(i, 2) == "AC") { cout << "Yes" << endl; return 0; }
	}
	cout << "No" << endl;
	return 0;
}

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

int main(void)
{
	int sum;
	while (scanf("%d", &sum), sum){
		int tmp, res = sum;
		for (int i = 0; i < 9; i++){
			scanf("%d", &tmp);
			res -= tmp;
		}
		printf("%d\n", res);
	}
	
	return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include <cstdio>
using namespace std;
int main()
{
int n,max,min;
scanf("%d",&n);
int a[n];
for(int i=0;i<n;i++)
scanf("%d",&a[i]);
max=min=a[0];
for(int i=1;i<n;i++)
{
if(a[i]>max)
max=a[i];
if(a[i]<min)
min=a[i];
}
printf("%d",(max-min));


}

Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10**7)
INF = 10 ** 18
MOD = 10 ** 9 + 7
def POW(x, y):
    if y == 0:
        return 1
    elif y == 1:
        return x
    elif y % 2 == 0:
        return POW(x, y // 2) ** 2 % MOD
    else:
        return POW(x, y // 2) ** 2 * x % MOD
def mod_factorial(x, y): return x * POW(y, MOD - 2) % MOD
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def II(): return int(sys.stdin.readline())
def SI(): return input()
from collections import Counter

patis = [INF] * 51
layers = [INF] * 51
patis[0] = layers[0] = 1

def calc_layers(n):
    if layers[n] == INF:
        layers[n] = 3 + calc_layers(n - 1) * 2
    return layers[n]
calc_layers(50)

def calc_patis(n):
    if patis[n] == INF:
        patis[n] = 1 + calc_patis(n - 1) * 2
    return patis[n]
calc_patis(50)

def dfs(n, x):
    if layers[n] <= x:
        return patis[n], x - layers[n]
    ret = 0
    x -= 1
    if x <= 0:
        return ret, 0
    r, x = dfs(n - 1, x)
    ret += r
    if x <= 0:
        return ret, 0
    x -= 1
    ret += 1
    if x <= 0:
        return ret, 0
    r, x = dfs(n - 1, x)
    ret += r
    if x <= 0:
        return ret, 0
    x -= 1
    ret += 1
    return ret, x

def main():
    N, X = LI()
    ans, _ = dfs(N, X)
    return ans

print(main())

Measured memory_bytes: 3316
#include<iostream>
#include<map>
#include<iomanip>

using namespace std;
using ll=long long;

#define rep(i, a, n) for (int i = (a); i < (n); i++)

void Main(){
  int a,b,c;
  cin>>a>>b>>c;

  map<int,int> mp;
  mp[a]=1;

  auto itr = mp.find(b);
  if( itr != mp.end() ) {
    mp[b]++;
  } else {
    mp[b]=1;
  }
  itr = mp.find(c);
  if( itr != mp.end() ) {
    mp[c]++;
  } else {
    mp[c]=1;
  }
  mp[5]==2 && mp[7]==1 ? cout<<"YES"<<endl : cout<<"NO"<<endl;
}

int main(){
  std::cin.tie(nullptr);                  // 標準入出力高速化
  std::ios_base::sync_with_stdio(false);  // SとS++の入出力出力を非同期
  Main();
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a) for(int i = 0; i < (a); i++)
#define ALL(a) (a).begin(),(a).end()
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1e9;
const long long LINF = 1e18;
const long long MOD = 1e9 + 7;

using ll = long long;
template <ll MOD = 1000000007>
struct Mint{
    ll x;

    Mint() : x(0) {}
    Mint(ll t){
        x = t % MOD;
        if(x < 0) x += MOD;
    }
    
    Mint pow(ll n){
        Mint res(1), t(x);
        while(n > 0){
            if(n & 1) res *= t;
            t *= t;
            n >>= 1;
        }
        return res;
    }

    Mint inv() const {
        ll a = x, b = MOD, u = 1, v = 0, t;
        while(b > 0){
            t = a / b;
            a -= t * b;
            swap(a, b);
            u -= t * v;
            swap(u, v);
        }
        return Mint(u);
    }

    Mint & operator += (Mint a){
        x += a.x;
        if(x >= MOD) x -= MOD;
        return *this;
    }
    
    Mint & operator -= (Mint a){
        x += MOD - a.x;
        if(x >= MOD) x -= MOD;
        return *this;
    }

    Mint & operator *= (Mint a){
        x = 1LL * x * a.x % MOD;
        return *this;
    }

    Mint & operator /= (Mint a){
        return (*this) *= a.inv();
    }

    Mint operator + (Mint a) const { return Mint(x) += a; }
    Mint operator - (Mint a) const { return Mint(x) -= a; }
    Mint operator * (Mint a) const { return Mint(x) *= a; }
    Mint operator / (Mint a) const { return Mint(x) /= a; }

    Mint operator - () const{ return Mint(-x); }

    bool operator == (const Mint a){ return x == a.x; }
    bool operator != (const Mint a){ return x != a.x; }
    bool operator < (const Mint a){ return x < a.x; }

    friend ostream & operator << (ostream & os, const Mint &a){
        return os << a.x;
    }

    friend istream & operator >> (istream & is, Mint &a){
        ll t;
        is >> t;
        a = Mint<MOD>(t);
        return (is);
    }
};

signed main(){
    int n;
    cin >> n;
    ll c[n];
    REP(i,n){
        cin >> c[i];
    }
    sort(c, c + n);
    reverse(c, c + n);
    Mint<> ans = 0;
    Mint<> t = Mint<>(2).pow(n - 1);
    REP(i,n){
        ans += Mint<>(c[i]) * t;
        t += Mint<>(2).pow(n - 2);
    }
    cout << ans * Mint<>(2).pow(n) << endl;
    return 0;
}

Measured memory_bytes: 1792
import java.util.Scanner;

public class Main {

	/** 正直者 */
	private static final String HONEST = "H";
	/** 嘘つき */
	private static final String DISHONEST = "D";

	public static void main(String[] args) {
		try (Scanner scanner = new Scanner(System.in)) {
			String a = scanner.next();
			String b = scanner.next();
			System.out.println((HONEST.equals(a) ? b : reverse(b)));
		}
	}

	/**
	 * @param input
	 * @return inputの反対
	 */
	private static String reverse(String input) {
		return (HONEST.equals(input) ? DISHONEST : HONEST);
	}
}


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

#define rep(i, n) REP(i, 0, n)
#define REP(i, k, n) for(auto i = k; i != n; i++)
#define rrep(i, n) RREP(i, n, 0)
#define RREP(i, n, k) for(auto i = n; i != k; i--)
#define all(x, r) (x), (x)+(r)
#define ALL(x) (x).begin(), (x).end()
#define debug(x) cerr << #x << " " << x << endl
#define exst(x, data) (data).find(x) != (data).end()
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define eb emplace_back
#define np next_permutation
#define b32 bitset<32>

using ll = long long;
using Pii = pair<int,int>;
using Tiii = tuple<int, int, int>;
template<class T>using V = vector<T>;

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

    int N, C; cin >> N >> C;
    V<V<int>> D = V<V<int>>(C+1, V<int>(C+1));
    REP(i,1,C+1) REP(j,1,C+1) cin >> D[i][j];
    V<V<int>> c = V<V<int>>(N+1, V<int>(N+1));
    REP(i,1,N+1) REP(j,1,N+1) cin >> c[i][j];

    V<map<int,int>> groups = V<map<int,int>>(3);
    REP(i,1,N+1) REP(j,1,N+1) groups[(i+j)%3][c[i][j]]++;

    V<map<int,ll>> ans = V<map<int,ll>>(3);
    rep(g,3) {
        map<int,int> &group = groups[g];
        REP(i,1,C+1) {
            REP(j,group.begin(),group.end()) {
                ans[g][i] += j->second * D[j->first][i];
            }
        }
    }

    // rep(i,3) {
    //     REP(j,ans[i].begin(),ans[i].end()) {
    //         cout << j->first << " " << j->second << endl;
    //     } cout << endl;
    // }

    ll res = LLONG_MAX;
    REP(i,1,C+1) REP(j,1,C+1) REP(k,1,C+1) {
        if(i!=j && j!=k && i!=k) {
            res = min(res, ans[0][i] + ans[1][j] + ans[2][k]);
            // cout << ans[0][i] << " " << ans[1][j] << " " << ans[2][k] << endl;
        }
    }
    cout << res << endl;

    // rep(g,3) {
    //     map<int,int> &group = groups[g];
    //     REP(i,group.begin(),group.end()) {
    //         cout << i->first << " " << i->second << endl;
    //     } cout << endl;
    // }
    return 0;
}


Measured memory_bytes: 1280
#include <bits/stdc++.h>
using namespace std;
using pii=pair<int,int>;
using ll=long long;
using pll=pair<ll,ll>;
 
#define fi first
#define se second
#define pb push_back
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define MOD 1000000007
 
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
 
int main() {
	int N;
	cin >> N;
	vector<string> S(N);
	ll ans = 0, counta = 0, countb = 0, countab=0;
	rep(i,N) {
		cin >> S[i];
		int n = S[i].length();
		if(S[i][0] == 'B') countb++;
		if(S[i][n-1] == 'A') counta++;
		if(S[i][0] == 'B' && S[i][n-1] == 'A') countab++;
	}
	rep(i,N) rep(j,S[i].length()-1) {
		if(S[i][j] == 'A' && S[i][j+1] == 'B') ans++;
	}
	ans += min(counta, countb);
	if(countab != 0 && countab == counta && countab == countb) ans -= 1;
	cout << ans << endl;
 
 
  return 0;
}

Measured memory_bytes: 768
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
constexpr long double EPS = 1e-15;
const long double PI = acos(-1);
constexpr int inf = 2e9;
constexpr ll INF = 2e18;
constexpr ll MOD = 1e9+7;
constexpr ll MOD1 = 998244353;
typedef pair<ll,ll> P;
//#define all(v) (v).begin(), (v).end()
#define rep(i,a,b) for (int i = (a); i < (b); i++)
#define REP(i,n) rep(i,0,n)
#define sz(s) (s).size()
#define pb push_back
#define fi first
#define se second
//#define mp make_pair

long double a,b,x;

bool ok(long double ang) {
    long double the = 180;
    long double k = b * sin(ang*PI);
    long double h = a * sin((0.5 - ang)*PI);
    long double v;
    if (k >= h) {
        v = (a / sin(ang*PI)) * (k - (h / 2));
    } else {
        v = b * b * tan(ang*PI) / 2;
    }
    v *= a;
    return v >= x - EPS;
}

void solve() {
    cin >> a >> b >> x;
    long double l = 0, r = 0.5;
    for (int i = 0; i < 100; i++) {
        long double mid = (l + r) / 2;
        if (ok(mid)) {
            r = mid;
        } else {
            l = mid;
        }
    }
    cout << setprecision(20) << 180 * (0.5 - r) << endl;
}

int main(int argc, char *argv[]){
    // /* Regular */
    // int case_num = 1;
    // if (argc > 1 && stoi(argv[1])) cin >> case_num;
    // REP(case_no, case_num) {
    //   cerr << endl << "case " << case_no + 1 << endl;
    //   solve();
    // }
    /* AOJ */
    solve();
    return 0;
}

Measured memory_bytes: 384
// luogu-judger-enable-o2
#include<bits/stdc++.h>
#define N 100005
#define mp make_pair
#define pr pair<int,int>
#define fr first
#define sd second
using namespace std;
const int INF=2e9;
int K,h[N],e_tot=0,d[N]; bool done[N];
struct E{ int to,nex,w; }e[N<<1];
inline void add(int u,int v,int w){
	e[++e_tot]=(E){v,h[u],w}; h[u]=e_tot;
}
void Dijkstra(int s){
	for(int i=0;i<K;++i) d[i]=INF,done[i]=0;
	priority_queue<pr> Q; d[s]=0; Q.push(mp(-d[s],s));
	while(!Q.empty()){
		pr x=Q.top(); Q.pop(); int u=x.sd;
		if(done[u]) continue; done[u]=1;
		for(int i=h[u],v;i;i=e[i].nex){
			v=e[i].to;
			if(d[v]>d[u]+e[i].w){
				d[v]=d[u]+e[i].w; Q.push(mp(-d[v],v));
			}
		}
	}
}
int main(){
	scanf("%d",&K);
	for(int i=0,nex;i<K;++i){
		nex=(i+1)%K; add(i,nex,1);
	}
	for(int i=0,nex;i<K;++i){
		nex=i*10%K; add(i,nex,0);
	}
	Dijkstra(1); printf("%d\n",d[0]+1);
	return 0;
}

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

struct UnionFind{
    vector<int> par;
    vector<int> siz;

    UnionFind(int n): par(n), siz(n){
        for(int i=0; i<n; i++){
            par[i] = i;
            siz[i] = 1;
        }
    }

    int root(int x){
        if(par[x] == x) return x;
        else return par[x] = root(par[x]);
    }

    int size(int x){
        return siz[root(x)];
        
    }

    void unite(int x, int y){
        int rx = root(x);
        int ry = root(y);
        if(rx != ry){
            par[ry] = rx;
            siz[rx] += siz[ry];
        }
    }

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

signed main(){
    // cout << fixed << setprecision(10) << flush;

    int n;
    cin >> n;

    vector<int> x(n), y(n);
    for(int i=0; i<n; i++){
        cin >> x[i] >> y[i];
    }

    vector<int> inv_x(n+1), inv_y(n+1);
    for(int i=0; i<n; i++){
        inv_x[x[i]] = i;
        inv_y[y[i]] = i;
    }

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

    UnionFind uf(n);
    set<pair<int, int>> st;
    for(int i=0; i<x.size(); i++){
        auto itr_lim = st.lower_bound(make_pair(y[inv_x[x[i]]], inv_x[x[i]]));
        bool f = true;
        for(auto itr = st.begin(); itr != itr_lim; itr++){
            uf.unite(inv_x[x[i]], itr->second);
            f = false;
        }
        
        if(f) st.insert(make_pair(y[inv_x[x[i]]], inv_x[x[i]]));
    }

    for(int i=0; i<n; i++){
        cout << uf.size(i) << endl;
    }

    return 0;
}

Measured memory_bytes: 17092
#include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define HUGE_NUM 1000000000000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;


struct Info{
	Info(int arg_A,int arg_index){
		A = arg_A;
		index = arg_index;
	}
	bool operator<(const struct Info &arg) const{

		return A < arg.A;
	}

	int A,index;
};

int main(){

	int N;
	scanf("%d",&N);

	vector<Info> info;

	int tmp;

	for(int i = 1; i <= N; i++){
		scanf("%d",&tmp);
		info.push_back(Info(tmp,i));
	}

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

	printf("%d",info[0].index);

	for(int i = 1; i < info.size(); i++){

		printf(" %d",info[i].index);
	}
	printf("\n");

	return 0;
}


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

int main() {
  int n;
  cin >> n;
  int p[n];
  for ( int i = 0; i < n; i++ ) { cin >> p[i]; }
  int ans = 0;
  for ( int i = 1; i < n-1; i++ ) {
    vector<int> tmp;
    tmp.push_back(p[i-1]);
    tmp.push_back(p[i]);
    tmp.push_back(p[i+1]);
    sort(tmp.begin(), tmp.end());
    if ( tmp[1] == p[i] ) { ans++; }
  }
  cout << ans << endl;
  return 0;
}

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

#define MAXN (100010)

int n;
int cnt1[MAXN], cnt2[MAXN];

int main() {
    scanf("%d", &n);
    for (int i = 1; i <= n; ++i) {
        int x;
        scanf("%d", &x);
        if (i & 1) ++cnt1[x];
        else ++cnt2[x];
    }
    std::pair<int, int> odd1(0, 0), odd2(0, 0); // first: count, second: number
    std::pair<int, int> even1(0, 0), even2(0, 0);
    for (int i = 1; i < MAXN; ++i) {
        if (cnt1[i] >= odd1.first) {
            odd2 = odd1;
            odd1 = {cnt1[i], i};
        } else if (cnt1[i] > odd2.first) {
            odd2 = {cnt1[i], i};
        }

        if (cnt2[i] >= even1.first) {
            even2 = even1;
            even1 = {cnt2[i], i};
        } else if (cnt2[i] > even2.first) {
            even2 = {cnt2[i], i};
        }
    }

    if (odd1.second == even1.second) {
        printf("%d\n", n - std::max(odd1.first + even2.first, odd2.first + even1.first));
    } else {
        printf("%d\n", n - odd1.first - even1.first);
    }

    return 0;
}

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

#define REP(i, n) for(int (i)=0;(i)<(n);++(i))
#define REPV(iter, v) for(auto (iter)=(v).begin(); (iter)!=(v).end();++(iter))
#define ALL(v) (v).begin(),(v).end()

#define MOD 1000000007

using namespace std;

typedef long long ll;

int main()
{
    ll H, W;
    cin >> H >> W;
    ll ans = LONG_MAX;

    for (ll h = 1; h <= H - 1; ++h)
    {
        ll s1, s2, s3, sMax, sMin;
        s1 = h * W;

        s2 = (H - h) * (W / 2);
        s3 = (H - h) * (W - W / 2);
        sMax = max(s1, max(s2, s3));
        sMin = min(s1, min(s2, s3));
        ans = min(ans, sMax -sMin);

        s2 = ((H - h) / 2) * W;
        s3 = ((H - h) - ((H - h) / 2)) * W;
        sMax = max(s1, max(s2, s3));
        sMin = min(s1, min(s2, s3));
        ans = min(ans, sMax -sMin);
    }

    for (ll w = 1; w <= W - 1; ++w)
    {
        ll s1, s2, s3, sMax, sMin;
        s1 = H * w;

        s2 = (H / 2) * (W - w);
        s3 = (H - H / 2) * (W - w);
        sMax = max(s1, max(s2, s3));
        sMin = min(s1, min(s2, s3));
        ans = min(ans, sMax - sMin);

        s2 = H * ((W - w) / 2);
        s3 = H * ((W - w) - ((W - w) / 2));
        sMax = max(s1, max(s2, s3));
        sMin = min(s1, min(s2, s3));
        ans = min(ans, sMax - sMin);
    }

    cout << ans << endl;
}


Measured memory_bytes: 256
s = input()
l = len(s)
A = [-1] * (l+1)

inf = float("inf")
tmp = ""
for i in range(l):
	if i == 0:
		if s[i] == ">":
			A[i] = inf
		else:
			A[i] = 0

		tmp = s[i]

	if s[i] == tmp:
		continue
	elif s[i] == ">" and tmp == "<":
		A[i] = inf
		tmp = ">"
	elif s[i] == "<" and tmp == ">":
		A[i] = 0
		tmp = "<"

if s[i] == ">":
	A[-1] = 0
else:
	A[-1] = inf

ans = 0
flg = 0
cnt = 0
pool = 0
for i in range(l+1):
	if A[i] == inf:
		flg = 1
		pool = cnt
		cnt = 0
		continue
	if A[i] == 0:
		if flg == 1:
			ans += max(pool, cnt) + 1
		flg = 0
		cnt = 0
		pool = 0
		continue
	
	cnt += 1
	ans += cnt

if flg == 1:
	ans += pool + 1


print(ans)




Measured memory_bytes: 7580
D,G = map(int, input().split())
pc = [0] + [list(map(int, input().split())) for _ in range(D)]

def function(G, i):
    if i == 0:
        return 10**9
    n = min(G // (i *100), pc[i][0])
    s = n * i * 100
    if n == pc[i][0]:
        s += pc[i][1]
    if s < G:
        n += function(G-s, i - 1)
    return min(n, function(G, i-1))

print(function(G, D))

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

int main()
{
  string str;
  cin >> str;
  if(str == "SUN")
  {
    cout << "7\n";
  }
  else if(str == "MON")
  {
    cout << "6\n";
  }
  else if(str == "TUE")
  {
    cout << "5\n";
  }
  else if(str == "WED")
  {
    cout << "4\n";
  }
  else if(str == "THU")
  {
    cout << "3\n";
  }
  else if(str == "FRI")
  {
    cout << "2\n";
  }
  else
  {
    cout << "1\n";
  }
  return (0);
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int n,a=2,b=3;
int main()
{
	ios_base::sync_with_stdio(0);cin.tie();cout.tie();
	cin>>n;
	if (n==3)
	{
		cout<<"2 5 63\n";
		return 0;
	}
	while (n>3 && b<30000)
	{
		cout<<b<<' '<<b+6<<' ';
		b+=12;
		n-=2;
	}
	while (n>1 && a<30000)
	{
		cout<<a<<' '<<a+2<<' ';
		a+=6;
		n-=2;
	}
	int c=6;
	while (n)
	{
		cout<<c<<' ';
		c+=6;
		n--;
	}
	return 0;
}

Measured memory_bytes: 384
#include <stdio.h>

int main(void) {
    int i, N, O;
    long long A[100010];
    scanf("%d", &N);
    O = 0;
    for (i=0;i<N;i++) {
        scanf("%lld", &A[i]);
        if (A[i]%2) O++;
    }
    if (O%2) printf("NO\n");
    else printf("YES\n");
    
    return 0;
}

Measured memory_bytes: 896
n = input()
x = len(n)
inf = 10 ** 9
#dp[i][flg]...i桁目まで、未満フラグ=1
dp = [[inf] * 2 for _ in range(x+1)]
dp[0][0] = 0
dp[0][1] = 1
for i in range(x):
    s = int(n[i])
    dp[i+1][0] = min(dp[i][0] + s, dp[i][1] + 10 - s)
    dp[i+1][1] = min(dp[i][0] + s + 1, dp[i][1] + 9 - s)

print(dp[x][0])


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

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

max = 0
cnt = 0
value = H[0]
for i in range(N-1):
    if value >= H[i+1]:
        cnt += 1
        if max < cnt:
            max = cnt
    else:
        cnt = 0
    value = H[i+1]
print(max)

Measured memory_bytes: 14252
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const long long INF = 1LL << 60;
 
typedef pair<ll,ll> pairs;
vector<pairs> p;
bool pairCompare(const pair<double,ll>& firstElof, const pair<double,ll>& secondElof){
    return firstElof.first < secondElof.first;
}
#define MAX_N 1000100
bool x[MAX_N];
ll num[MAX_N];
ll fibl[MAX_N]={0};
 
ll fib(ll a){
    if (fibl[a]!=0)return fibl[a];
    if (a==0){
        return 0;
    }else if (a==1){
        return 1;
    }
    return fibl[a]=fib(a-1)+fib(a-2);
}
 
ll eratosthenes(ll n) {
    int p = 0;
    for (ll i=0; i<=n; ++i) x[i] = true;
    x[0] = x[1] = false;
    for(int i=2; i<=n; ++i) {
        if(x[i]) {
            p++;
            for(int j=2*i; j<=n; j+=i) x[j] = false;
        }
        
        num[i] = p;
    }
    return p;
}
 
ll gcd(ll a,ll b){
    if (a%b==0)return(b);
    else return(gcd(b,a%b));
}
 
ll keta(ll N){
    int tmp{};
    while( N > 0 ){
        tmp += ( N % 10 );
        N /= 10;
    }
    N = tmp;
    return N;
}

int main(){
    ll a,b,c;
    cin >> a >> b >> c;
    
    cout << max({a+b*10+c, a*10+b+c, a+b+c*10}) << endl;
    
    return 0;
}



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

int main(){
    long long a,b,c,k;
    cin>>a>>b>>c>>k;
    if(k%2==0)cout<<a-b<<endl;
    else cout<<b-a<<endl;

    return 0;
}

Measured memory_bytes: 3608
from heapq import heappush, heappop, heapify
x, y, a, b, c = map(int, input().split())
p = sorted(list(map(int, input().split())), reverse=True)
q = sorted(list(map(int, input().split())), reverse=True)
r = sorted(list(map(int, input().split())), reverse=True)


R, B = p[:x], q[:y]
heapify(R)
heapify(B)
for i in range(c):
	if min(R[0], B[0]) > r[i]:
		break
	if R[0] < B[0]:
		heappop(R)
		heappush(R, r[i])
	else:
		heappop(B)
		heappush(B, r[i])

print(sum(R) + sum(B))

Measured memory_bytes: 23456
import java.util.*;
//import java.util.stream.Collectors;

public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		
		int x = Integer.parseInt(sc.next());
		int a = Integer.parseInt(sc.next());
		int b = Integer.parseInt(sc.next());
		System.out.println(a >= b ? "delicious" : (x + a) >= b ? "safe" : "dangerous");
	}
}


Measured memory_bytes: 35684
#include <bits/stdc++.h>
 using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
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; } 
using ll=long long;
 int main(){
  string s;
   cin>>s;
   if(s=="ABC")cout<<"ARC"<<endl;
   else cout<<"ABC"<<endl;
}

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

int main() {
	string x; cin >> x;
	stack<char> que;
	for (int i = 0; i < x.size(); i++)
	{
		if(que.empty()) que.push(x[i]);
		else if(que.top() == 'S' && x[i] == 'T') que.pop();
		else que.push(x[i]);
	}
	cout << que.size() << endl;

	return 0;
}



Measured memory_bytes: 644
#include <iostream>

using namespace std;

int main() {
  int a, b, c, d;
  cin >> a >> b >> c >> d;
  if ((a + b) == (c + d)) cout << "Balanced";
  else if ((a + b) > (c + d)) cout << "Left";
  else cout << "Right";
  cout << '\n';
  return 0;
}

Measured memory_bytes: 256