akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <string>
using namespace std;
int main() {
	//int a,b,c;
	string s,n="ABC";
	cin >> s;// cin >> b;// cin >> c;
	//a[0]==a[2]?cout << "Yes"<< endl: cout << "No" << endl;
	cout << n+s << endl;
	
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int ans=0;
		for(int i=N ; i<=999 ; i++) {
			if(check(i)) {
				ans = i;
				break;
			}
		}
		System.out.println(ans);
		sc.close();
	}
	static boolean check(int n) {
		int one = n%10; n/=10;
		int two = n%10; n/=10;
		int thr = n%10;
		if( (one==two) && (two==thr) ) {
			return true;
		}
		return false;
	}

}


Measured memory_bytes: 22612
#include <algorithm>
#include <cassert>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
//#include <regex>

/* g++ -g -std=c++0x */
/* g++ -g -std=c++11 */

using namespace std;

// freopen("input.txt", "rt", stdin);
// freopen("output.txt", "wt", stdout);

#define ALL(c)          (c).begin(), (c).end()
#define ALLR(c)         (c).rbegin(), (c).rend()
#define FOR(i,a,b)      for (int i=(a); i < (b); ++i)
#define FORR(i,a,b)     for (int i=(a); i > (b); --i)
#define FOR_ALL(i,c)    for (__typeof((c).begin()) i=(c).begin();   \
                             i != (c).end(); ++i)
#define FOR_ALLR(i,c)   for (__typeof((c).rbegin()) i=(c).rbegin(); \
                             i != (c).rend(); ++i)
#define SZ(array)       (sizeof(array)/sizeof(array[0]))
#define lc(x)           (x<<1)     /* 2*x */
#define rc(x)           (x<<1 | 1) /* 2*x+1 */
#define lowbit(x)       (x & (-x)) /* 0b10100 -> 0b100 */

typedef long long       LL;
typedef map<int,int>    MII;
typedef pair<int,int>   PII;
typedef set<int>        SI;
typedef vector<bool>    VB;
typedef vector<double>  VD;
typedef vector<int>     VI;
typedef vector<string>  VS;

/* check if a key is in container C */
template <class C>
inline bool in_(const typename C::key_type& k, const C& A)
{ return A.find(k) != A.end(); }
inline bool in_(const string& s, const string& S)
{ return S.find(s) != string::npos; }

int main()
{
/* #ifndef ONLINE_JUDGE */
/*     freopen("foo", "rt", stdin); */
/* #endif */
    std::ios::sync_with_stdio(false);

    string a[3];
    FOR(i,0,3)
        cin >> a[i];
    string ans;
    for (int i = 0; i < 3; i++) {
        for (int j =0; j < 3; j++) {
            if (i==j) {
                ans += a[i][j];
            }
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
fun main(args:Array<String>) {
    val N = readLine()!!.toInt()
    val listDict = mutableMapOf("AC" to 0, "WA" to 0, "TLE" to 0, "RE" to 0)
    for(i in 0 until N){
        val a = readLine()!!
        listDict[a] = listDict[a]!!.plus(1)
    }

    for(key in listDict.keys){
        println(key + " " + "x" + " " + listDict[key])
    }

}

Measured memory_bytes: 57964
pub fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

pub fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}

pub fn read_vec2<T: std::str::FromStr>(n: usize) -> Vec<Vec<T>> {
    (0..n).map(|_| read_vec()).collect()
}

pub fn read_col<T: std::str::FromStr>(n: usize) -> Vec<T> {
    (0..n).map(|_| read()).collect()
}

fn is_prime(n: u32) -> bool {
    if n < 2 {
        return false;
    }
    let mid = ((n as f64).sqrt() as u32) + 1;
    for i in 2..mid {
        if n % i == 0 {
            return false;
        }
    }
    true
}

fn main() {
    let q: usize = read();
    let lrv: Vec<Vec<usize>> = read_vec2(q);
    let mut ruiseki: Vec<u32> = vec![0, 0];

    let mut tmp = 0;
    for i in 1..50000 {
        ruiseki.push(tmp);
        if is_prime(2 * i + 1) && is_prime(i + 1) {
            tmp += 1;
        }
        ruiseki.push(tmp);
    }

    for lr in lrv {
        let l = lr[0];
        let r = lr[1];
        println!("{}", ruiseki[r] - ruiseki[l - 1]);
    }
}


Measured memory_bytes: 10876
#include<iostream>
#include<vector>
#include<string>
#include<map>
#include<set>
#include<algorithm>

using namespace std;

typedef long long int Int;

int main(void) {
    int N;
    Int sum = 0;
    cin>>N;
    vector<int> A(N+2);
    A[0] = A[N+1] = 0;
    for(int i = 1;i <= N;i++) {
        cin>>A[i];
        sum += abs(A[i]-A[i-1]);
    }
    sum += abs(A[N+1]-A[N]);

    for(int i = 1;i <= N;i++) {
        cout<<sum - abs(A[i]-A[i-1])-abs(A[i+1]-A[i])+abs(A[i-1]-A[i+1])<<endl;
    }

    return 0;
}


Measured memory_bytes: 2296
#include <iostream>
#include <algorithm>

using namespace std;

#define MAX 500
typedef long long ll;

int main(){
  int n, arr[MAX];

  cin >> n;
  for(int i = 0 ; i < n ; i++){
    cin >> arr[i];
  }
  sort(arr, arr+n, greater<int>());
  ll ans = 0;
  for(int i = 0 ; i < n ; i++){
    if(arr[i]-i/4 > 0){
      ans += arr[i]-i/4;
    }
  }
  cout << ++ans << endl;

  return 0;
}

Measured memory_bytes: 1172
function abc064_a()

	# STEP.01
	# get the number of the slice of cake
	r,g,b = Base.parse.( Base.split( Base.readline( Base.STDIN ) ) )

	# STEP.02
	# output the result
	if Base.isequal( Base.rem( 10*(10*r+g)+b, 4 ), 0 )
		Base.println( Base.STDOUT, "YES" )
	else
		Base.println( Base.STDOUT, "NO" )
	end

	# STEP.TRUE_END
	return Base.nothing

end

#==================================================================================================#

Main.abc064_a()


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

int n,k;
int w[1000000];

void qsort(int a[],int left,int right){
   if(left < right){
      int pivot = a[(left+right)/2];
      int next_l = left,next_r = right;
      while(left<right){
         while(a[left] < pivot) left++;
         while(a[right] > pivot) right--;
         if(left <= right){
            swap(a[left],a[right]);
            left++;
            right--;
         }
      }
      qsort(a,next_l,right);
      qsort(a,left,next_r);
   }
}
int main(){
   int n;
   cin >> n;
   int a[n],sumA = 0;
   rep(i,n){
      cin >> a[i];
      sumA +=a[i];
   } 

   qsort(a,0,n-1); //数列をソート
   //rep(i,n) cout << a[i] << " ";

   int q;
   cin >> q;
   int m[q];
   rep(i,q) cin >> m[i];
   rep(i,q){
      if(sumA < m[i]){
         cout << "no" << endl;
         continue;
      }
      //cout << i << endl;
      bool judge = false;
      for(int k=0;k<(1<<n);k++){
         int sum = 0;
         for(int t=0;t<n;t++){
            if(k&(1<<t)){
               sum += a[t];
               //cout << sum << endl;
            }
         }
         //cout <<k<< endl;
         if(sum == m[i]){
            judge = true;
            break;
         }
      }

      if(judge)cout << "yes"<<endl;
      else cout << "no" << endl;
   }
   return 0;
}



Measured memory_bytes: 3100
#include<iostream>
#include<vector>
#include<queue>
#include<algorithm>
#include<string>
#include<cmath>

using namespace std;
constexpr int MOD = 1e9 + 7;
using ll = long long;
template <typename T> T In() {
    T t;
    cin >> t;
    return t;
}
template <typename T> vector<vector<T>> Vec2(int i, int j, T ini = 0) {
    vector<vector<T>> vec(i, vector<T>(j, ini));
    return move(vec);
}
template <typename T> vector<vector<vector<T>>> Vec3(int i, int j, int k, T ini = 0) {
    vector<vector<vector<T>>> vec(i, vector<vector<T>>(j, vector<T>(k, ini)));
    return move(vec);
}

struct NodeData {
    vector<int> edge;
    int parent=-1;
    int point = 0;
};


void updatePoint(vector<NodeData> &tree, int index) {
    for(int j : tree[index].edge) {
        if(tree[index].parent != j) {
            tree[j].parent = index;
            tree[j].point += tree[index].point;
            updatePoint(tree, j);
        }
    }
}

int main() {
    int N = In<int>();
    int Q = In<int>();
    vector<NodeData> tree(N);
    for(int i = 0; i < N - 1;  i++) {
        int a = In<int>()-1;
        int b = In<int>()-1;
        tree[a].edge.push_back(b);
        tree[b].edge.push_back(a);
    }
    for(int q = 0; q < Q; q++) {
        int p = In<int>();
        int x = In<int>();
        tree[p-1].point += x;
    }

    updatePoint(tree, 0);
    for(const auto& node : tree) {
        cout << node.point << " ";
    }
}


Measured memory_bytes: 24320
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <algorithm>
#include <numeric>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <functional>
#define _USE_MATH_DEFINES
#include <cmath>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <cfloat>
#include <cmath>
#include <ctime>
#include <cstdio>
#include <cassert>
using namespace std;

#define EPS 1e-12
#define ull unsigned long long
#define ll long long
#define VI vector<ll>
#define PII pair<ll, ll> 
#define VVI vector<vector<ll> >
#define REP(i,n) for(int i=0,_n=(n);(i)<(int)_n;++i)
#define RANGE(i,a,b) for(int i=(int)a,_b=(int)(b);(i)<_b;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
#define ALLR(c) (c).rbegin(), (c).rend()
#define PB push_back
#define MP(a, b) make_pair(a, b)
#define POPCOUNT __builtin_popcount
#define POPCOUNTLL __builtin_popcountll
#define CLEAR(table, v) memset(table, v, sizeof(table));
#define PRINT1(table, D0) REP(d0, D0) cout<<table[d0]<<" "; cout<<"\n";
#define PRINT2(table, D0, D1) REP(d0, D0) { REP(d1, D1) cout<<table[d0][d1]<<" "; cout<<"\n"; }
#define PRINT3(table, D0, D1, D2) REP(d0, D0) { REP(d1, D1) { REP(d2, D2) cout<<table[d0][d1][d2]<<" "; cout<<"\n"; } cout<<"\n"; }
#define UNIFORM_DOUBLE(a, b) (((b-a)*(double)rand()/RAND_MAX)+a) // [a, b) 
#define UNIFORM_LL(a, b) (ll)UNIFORM_DOUBLE(a, b) // [a, b) 
#define IN(v, lo, hi) ((lo)<=(v) && (v)<(hi))
#define DD(v) cout<<#v<<": "<<v<<endl
template <typename T0, typename T1> std::ostream& operator<<(std::ostream& os, const map<T0, T1>& v) { for( typename map<T0, T1>::const_iterator p = v.begin(); p!=v.end(); p++ ){os << p->first << ": " << p->second << " ";} return os; }
template <typename T0, typename T1> std::ostream& operator<<(std::ostream& os, const pair<T0, T1>& v) { os << v.first << ": " << v.second << " "; return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const vector<T>& v) { for( int i = 0; i < (int)v.size(); i++ ) { os << v[i] << " "; } return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const vector<vector<T> >& v) { for( int i = 0; i < (int)v.size(); i++ ) { os << v[i] << endl; } return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const set<T>& v) { vector<T> tmp(v.begin(), v.end()); os << tmp; return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const deque<T>& v) { vector<T> tmp(v.begin(), v.end()); os << tmp; return os; }

#define MOD 1000000007LL
#define INF (1LL<<60)

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll N;
	while(cin>>N) {
		VI A(N), B(N);
		REP(i, N) cin>>A[i];
		REP(i, N) cin>>B[i];
		ll ans = -1;
		if(accumulate(ALL(A), 0LL) >= accumulate(ALL(B), 0LL)) {
			ll v=0;
			VI cap;
			ans = 0;
			REP(i, N) {
				if(A[i]<B[i]) {
					v+=B[i]-A[i];
					ans++;
				} else cap.PB(A[i]-B[i]);
			}
			sort(ALLR(cap));
			REP(i, cap.size()) {
				if(v==0) break;
				ll sub = min(v, cap[i]);
				v-=sub;
				ans++;
			}
		}
		cout<<ans<<endl;
	}
	
	return 0;
}


Measured memory_bytes: 2936
#include <stdio.h>

int main(){
	int N, A, B;
	scanf("%d %d %d", &N, &A, &B);
	int temp;
	temp = (A>B?B:A);
	printf("%d %d", temp, ((N-(A>B?A:B)>temp?0:A+B-N)));
	
}

Measured memory_bytes: 128
#include <algorithm>
#include <iostream>
#include <vector>
#include <set>
#include <map>
using namespace std;

#define rep(i, a, b) for(int i = a; i < (b); ++i)
int main() {
    int N ;
    cin >> N;
    int count = 1;
    vector<char> S(N);
    rep(i, 0, N){
        cin >> S[i];
    }
    rep(i, 0, N-1){
        if (S[i] != S[i+1]){
            count+=1;
        }
    }
    cout << count << endl;
    return 0;
}

Measured memory_bytes: 384
// #define DEBUGGING
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define ALL(V) (V).begin(), (V).end()
#define ALLR(V) (V).rbegin(), (V).rend()

template <typename T> using V = vector<T>;
template <typename T> using VV = V<V<T>>;
template <typename T, typename U> using P = pair<T, U>;
using ll = int64_t;
using PLL = P<ll, ll>;

template <typename T> const T& var_min(const T &t) { return t; }
template <typename T> const T& var_max(const T &t) { return t; }
template <typename T, typename... Tail> const T& var_min(const T &t, const Tail&... tail) { return min(t, var_min(tail...)); }
template <typename T, typename... Tail> const T& var_max(const T &t, const Tail&... tail) { return max(t, var_max(tail...)); }
template <typename T, typename... Tail> void chmin(T &t, const Tail&... tail) { t = var_min(t, tail...); }
template <typename T, typename... Tail> void chmax(T &t, const Tail&... tail) { t = var_max(t, tail...); }
template <typename T> const T& clamp(const T &t, const T &low, const T &high) { return max(low, min(high, t)); }
template <typename T> void chclamp(T &t, const T &low, const T &high) { t = clamp(t, low, high); }

namespace __init {

struct InitIO {
    InitIO() {
        cin.tie(nullptr);
        ios_base::sync_with_stdio(false);
        cout << fixed << setprecision(30);
    }
} init_io;

}

#ifdef DEBUGGING
#include "../debug.cpp"
#else
#define DEBUG(...) 0
#define DEBUG_SEPARATOR_LINE 0
#endif

template <typename T>
T make_v(T init) { return init; }

template <typename T, typename... Tail>
auto make_v(T init, size_t s, Tail... tail) {
#define rec make_v(init, tail...)
    return V<decltype(rec)>(s, rec);
#undef rec
}

using ld = long double;
V<ll> pow2(32, 1);
V<ld> rpow2(32, 1);

int main() {
    for(ll i = 1; i < pow2.size(); i++) {
        pow2[i] = pow2[i - 1] * 2;
        rpow2[i] = rpow2[i - 1] / 2;
    }
    ll N, K;
    cin >> N >> K;
    
    ld ans = 0;
    for(ll i = 1; i <= N; i++) {
        ll ok = 49, ng = -1;
        while(ok - ng > 1) {
            ll mid = (ok + ng) / 2;
            if(pow2[mid] * i >= K) ok = mid;
            else ng = mid;
        }
        ans += rpow2[ok];
    }
    ans *= 1.0 / N;
    cout << ans << endl;
    return 0;
}


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

using namespace std;

vector<string> ans;

int main(){
	while(1){
		string str;
		getline(cin,str);
		
		if(str == ".")break; 
		
		vector<int> hmk;
		vector<int> hkk;
		bool balance = true;
		
		for(int i = 0;i < str.size();i++){
			if(!balance) break;
			if(str[i] == '(') hmk.push_back(i);
			if(str[i] == '[') hkk.push_back(i);
			if(str[i] == ')'){
				if(hmk.size() == 0) balance = false;
				else{
					for(int j = 0;j < hkk.size();j++){
						if(hmk.back() < hkk[j]){balance = false;break;}
					}
					hmk.pop_back();
				}
			}
			if(str[i] == ']'){
				if(hkk.size() == 0) balance = false;
				else{
					for(int j = 0;j < hmk.size();j++){
						if(hkk.back() < hmk[j]){balance = false;break;}
					}
					hkk.pop_back();
				}
			}
		}
		
		string yn;
		if(hmk.size() == 0 && hkk.size() == 0 && balance) yn = "yes";
		else yn = "no";
		
		ans.push_back(yn);
	}
	for(int i = 0;i < ans.size();i++){
		cout << ans[i] << endl;
	}
	return 0;
}

Measured memory_bytes: 3376
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;

vector<P> es;

void build(int l, int r){
    if(r-l <= 1) return;
    int mid = (l+r+1)/2;
    for(int i=l+1;i<mid;i++){
        es.push_back({l+1,i+1});
    }
    build(l+1, mid);
    build(mid, r);
}

int main() {
    int n, k;
    cin >> n >> k;
    build(0, n);
    cout << es.size() << endl;
    for(int i=0;i<int(es.size());i++){
        cout << es[i].first << " " << es[i].second << endl;
    }
    for(int i=0;i<k;i++){
        int l = 0, r = n;
        string res;
        while(1){
            cout << l+1 << endl;
            cin >> res;
            if(res == "Yes"){
                break;
            }
            else if(res == "Near"){
                r = (l+r+1)/2;
                l++;
            }
            else{
                l = (l+r+1)/2;
            }
        }
    }
    return 0;
}



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

map<string, int> mp;
vector<pair<int, string> > v;

int main() {
  int n;
  cin >> n;
  for(int i = 0; i< n; ++i) {
    string s;
    cin >> s;
    ++mp[s];
  }
  for (auto p: mp) {
    v.push_back(pair<int, string>(p.second, p.first));
  }
  sort(v.begin(), v.end());
  for (auto p: v) {
    if (p.first == v.back().first) {
      cout << p.second << "\n";
    }
  }
}



Measured memory_bytes: 28916
#include <iostream>

using namespace std;

int main(){
    int N,ans;
    int ar[105];

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

    ans = ar[0];
    for(int i = 1 ; i < N ; i++){
        if(ar[i] > ar[i-1]){
            ans += ar[i] - ar[i-1];
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <bitset>
#include <vector>
#include <string>
#include <map>
#include <algorithm>

#define REP(i,n) for(int i=0;i<(int)(n);i++)

using namespace std;

int main() {
  while(1){
    int n;
    cin>>n;
    if(!n)break;
    vector<int> v(n);
    REP(i,n)cin>>v[i];
    int sum = accumulate(begin(v),end(v),0);
    int mx=0;
    REP(i,(1<<n)){
      bitset<20> bs(i);
      int s=0;
      REP(j,n){
        if(bs[j]){
          s+=v[j];
          if(s <= sum/2)
            mx=max(s,mx);
        }
      }
    }
    cout<<sum - mx*2<<endl;
  }
  return 0;
}

Measured memory_bytes: 1192
using System;
using System.Linq;
using System.Collections.Generic;
using static System.Console;
using static System.Math;
using System.Text;

namespace ConsoleApp
{
    class Program
    {

        static void Main(string[] args)
        {
            var x = long.Parse(ReadLine());
            
            var fhc = (long)Math.Floor(x / 500.0);
            var fc = (long)Math.Floor((x - 500 * fhc) / 5.0);

            WriteLine(fhc * 1000 + fc * 5);
        }



    }

}


Measured memory_bytes: 11092
#include<iostream>
#include<algorithm>
#include<cmath>
#include<bitset>
using namespace std;
typedef long long ll;

string minu(ll n,int base )
{
  string res;
  if(n == 0)return "0";
  ll a,b;
  int t=0;
  for(;n;t++)
    {
      t=t&1;
      a=n/base;
      b=n-a*base;
      if(b<0&&t==0)
	{
	  b+=base;
	  a-=1;
	}
      else if(t==1&&b>0)
	{
	  b-=base;
	  a+=1;
	}
      if(b<0)b=-b;
      res=" "+res;
      res[0]=b+'0';
      n=a;
    }

  return res;
}

int main()
{
  ll value;
  while(cin >> value,value)
    {
      cout << minu(value,10) << endl;
    }
  return 0;
}

Measured memory_bytes: 1200
import bisect
N=int(input())
A=list(map(int,input().split()))
A.sort()
B=list(map(int,input().split()))
B.sort()
C=list(map(int,input().split()))
C.sort()

ans=0
for b in B:
  a=bisect.bisect_left(A,b)
  c=N-bisect.bisect_right(C,b)
  ans+=a*c
print(ans)

Measured memory_bytes: 23232
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int N; cin >> N;
    vector<string> S(N); for (string& s : S) cin >> s;
    long long ans = 0;
    for (int A = 0; A < N; A++) {
        for (int i = 0; i < N; i++) {
            for (int j = 0; j < N; j++) {
                if (S[(i+A)%N][j] != S[(j+A)%N][i]) {
                    goto NEXT;
                }
            }
        }
        ans += N;
        NEXT:;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 384
#include <cstdio>
int m[]={0,1,2,3,5,7,8,9},n;
char b[16],*c;
int main(){while(scanf("%d",&n),n){sprintf(b,"%o",n);for(c=b;*c;c++)putchar(m[*c-'0']+'0');puts("");}return 0;}

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

typedef long long int ll;
ll dp[100005][10],A[100005],B[100005],C[100005],N;

ll fun( int i,int p)
{
    if(i==N)
    {
        if(p==1)
        return A[N];
        
        if(p==2)
        return B[N];
        
        if(p==3)
        return C[N];
    }
    
  else  if(i>N)
    return -1000000000000;
    
    else
    {
        if(dp[i][p]!=-1)
        return dp[i][p];
        
        else
        {
            if(p==1)
            {
                dp[i][p] = max(A[i]+fun(i+1,2),A[i]+fun(i+1,3));
            }
            if(p==2)
            {
                dp[i][p] = max(B[i] + fun(i+1,1),B[i] + fun(i+1,3));
            }
            if(p==3)
            {
                dp[i][p]  = max(C[i] + fun(i+1,1),C[i] + fun(i+1,2));
            }
        }
    }
    return dp[i][p];
    
    
}




int main()
{ 
   ll i,x,y,z,ans;
   cin>>N;
   for(i=1;i<=N;i++)
   {
       cin>>A[i]>>B[i]>>C[i];
   }
   memset(dp,-1,sizeof dp);
   x = fun(1,1);
   y = fun(1,2);
   z = fun(1,3);
   
  ans = max(x,y);
  ans = max(ans,z);
  
  cout<<ans;
   
   return 0;
}
   
   
   
   
  

Measured memory_bytes: 15104
//           _____                  _______                  _____                   _____
//          /\    \                /::\    \                /\    \                 /\    \
//         /::\    \              /::::\    \              /::\____\               /::\    \
//        /::::\    \            /::::::\    \            /:::/    /              /::::\    \
//       /::::::\    \          /::::::::\    \          /:::/    /              /::::::\    \
//      /:::/\:::\    \        /:::/~~\:::\    \        /:::/    /              /:::/\:::\    \
//     /:::/__\:::\    \      /:::/    \:::\    \      /:::/    /              /:::/__\:::\    \
//    /::::\   \:::\    \    /:::/    / \:::\    \    /:::/    /              /::::\   \:::\    \
//   /::::::\   \:::\    \  /:::/____/   \:::\____\  /:::/    /      _____   /::::::\   \:::\    \
//  /:::/\:::\   \:::\    \|:::|    |     |:::|    |/:::/____/      /\    \ /:::/\:::\   \:::\    \
// /:::/  \:::\   \:::\____|:::|____|     |:::|____|:::|    /      /::\____/:::/  \:::\   \:::\____\
// \::/    \:::\  /:::/    /\:::\   _\___/:::/    /|:::|____\     /:::/    \::/    \:::\  /:::/    /
//  \/____/ \:::\/:::/    /  \:::\ |::| /:::/    /  \:::\    \   /:::/    / \/____/ \:::\/:::/    /
//           \::::::/    /    \:::\|::|/:::/    /    \:::\    \ /:::/    /           \::::::/    /
//            \::::/    /      \::::::::::/    /      \:::\    /:::/    /             \::::/    /
//            /:::/    /        \::::::::/    /        \:::\__/:::/    /              /:::/    /
//           /:::/    /          \::::::/    /          \::::::::/    /              /:::/    /
//          /:::/    /            \::::/____/            \::::::/    /              /:::/    /
//         /:::/    /              |::|    |              \::::/    /              /:::/    /
//         \::/    /               |::|____|               \::/____/               \::/    /
//          \/____/                 ~~                      ~~                      \/____/
//I am aqua
#include<bits/stdc++.h>
typedef long long ll;
typedef long double ld;
#define pii pair< int,int >
#define mp make_pair
#define yes cout<<"YES\n";
#define no cout<<"NO\n";
#define speed  ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define pb push_back
#define pob pop_back
#define pf push_front
#define pof pop_front
#define l first
#define r second
#define input.txt ifstream fin("input.txt");
#define output.txt ofstream fout("output.txt");
#define BTT( a,b ) (((a)>>(b))&1)
#define LB(x) (x % -(x))
using namespace std;
//---------------------------------------------------------------------------------------------------------------------
///Variables
const int maxn=2e5+10;

//--------------------------------------------------------------------------------------------------------------------
///Function

//---------------------------------------------------------------------------------------------------------------------
///Main
int main()
{
    int a,b,c;
    cin>>a>>b>>c;
    cout<<c<<' '<<a<<' '<<b;
}
//I know that ;
//I know where I am
//Do not think I don't


Measured memory_bytes: 256
using System;
class c
{
    static void Main()
    {
        int n = int.Parse(Console.ReadLine());
        var v = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
        var even = new int[100001];
        var odd = new int[100001];
        for (int i = 0; i < n; i++)
        {
            if (i % 2 == 0) even[v[i]]++;
            else odd[v[i]]++;
        }
        int e1 = 0, e2 = 0, o1 = 0, o2 = 0;
        for (int i = 1; i <= 100000; i++)
        {
            if (even[i] >= even[e1])
            {
                e2 = e1;
                e1 = i;
            }
            else if (even[i] >= even[e2])
            {
                e2 = i;
            }
            if (odd[i] >= odd[o1])
            {
                o2 = o1;
                o1 = i;
            }
            else if (odd[i] >= odd[o2])
            {
                o2 = i;
            }
        }
        if (o1 == e1) Console.WriteLine(Math.Min(n - even[e2] - odd[o1], n - even[e1] - odd[o2]));
        else Console.WriteLine(n - even[e1] - odd[o1]);
    }
}

Measured memory_bytes: 19680
from sys import stdin


def dp_solve(i, h, dp, K):
    for i in range(1, n):
        if i <= K:
            dp[i] = abs(h[i]-h[0])
        else:
            dp[i] = min([d + abs(h[i]-hk) for d, hk in zip(dp[i-K:i], h[i-K:i])])
    return dp[n-1]


if __name__ == "__main__":
    n, K = map(int, input().split())
    h = list(map(int, stdin.readline().split()))
    inf = float('inf')
    dp = [inf]*n

    print(dp_solve(n-1, h, dp, K))


Measured memory_bytes: 14012
import java.io.PrintWriter

fun next() = readLine()!!
fun nextInt() = next().toInt()
fun nextLong() = next().toLong()
fun nextDouble() = next().toDouble()
fun nextList() = next().split(" ")
fun nextIntList() = nextList().map(String::toInt)
fun nextLongList() = nextList().map(String::toLong)
fun nextDoubleList() = nextList().map(String::toDouble)

val pw = PrintWriter(System.out)
fun print(s: Any = "") = pw.print(s)
fun println(s: Any = "") = pw.println(s)

fun <T> Iterable<T>.join(separator: CharSequence = ", ", prefix: CharSequence = "", postfix: CharSequence = "") = joinToString(separator, prefix, postfix)
fun <T> Array<T>.join(separator: CharSequence = ", ", prefix: CharSequence = "", postfix: CharSequence = "") = joinToString(separator, prefix, postfix)

fun main(args: Array<String>) {
    main()
    pw.flush()
}

fun main() {
    val (A, B) = nextLongList()
    println(f(A - 1) xor f(B))
}

fun f(N: Long): Long {
    val a = if ((N + 1) % 2 == 0L) 0L else N
    val b = if (((N + 1) / 2L) % 2 == 0L) 0L else 1L
    return a xor b
}

Measured memory_bytes: 36336
import sys

cnt = {}

for line in sys.stdin:
  for l in line:
    if l.isalpha():
      c = l.lower()
      cnt[c] = cnt.get(c,0)+1

for i in range(26):
  c = chr(ord('a')+i)
  print( c, " : ", cnt.get(c,0), sep = '' )

Measured memory_bytes: 7468
#include<iostream>
#include<math.h>
#include<string.h>
#include<vector>
using namespace std;

int main(){
	int n;
	cin >> n;
	int x=n,sn=0;
	while(x){
		sn+=x%10;	
		x=x/10;
	}
	if(n%sn==0){
		cout << "Yes" << endl;
	}else{
		cout << "No" << endl;
	}
	return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

void selec(int *,int);
int main(){
  int n,a[100],i;
  scanf("%d",&n);
  if(n<1||n>100)fprintf(stderr,"ERRRRRRRRRRRRRRRR\n");
  for(i=0;i<n;i++){
    scanf("%d",&a[i]);
  }
  selec(a,n);
  return 0;
}

void selec(int *a,int n){
  int i,minj,j,x,count=0;
  for(i=0;i<n;i++){
    minj=i;
    for(j=i;j<n;j++){
      if(a[j]<a[minj]){
	minj=j;
      }
    }
      	x=a[i];
	a[i]=a[minj];
	a[minj]=x;
	if(i!=minj){
	  count++;
  }
	}
  for(i=0;i<n;i++){
    if(i>0)printf(" ");
    printf("%d",a[i]);
  }
  printf("\n%d\n",count);
}



Measured memory_bytes: 2068
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cstring>
#include <cstdlib>
#include <cmath>
using namespace std;
using ll = long long;

struct P {
    bool operator<(const P &p) const {
        return a < p.a;
    }
    int a, b;
};

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

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

    vector<P> p(n);
    for (int i = 0; i < n; i++) {
        int a, b;
        cin >> a >> b;
        p[i] = { a, b };
    }
    sort(p.begin(), p.end());

    vector<int> ma(n);
    ma[n - 1] = p[n - 1].b;
    for (int i = n - 2; i >= 0; i--) {
        ma[i] = max(p[i].b, ma[i + 1]);
    }

    int r = 0;
    vector<int> dp(t);
    dp[0] = 0;
    for (int i = 0; i < n - 1; i++) {
        int a = p[i].a;
        int b = p[i].b;
        int s = 0;
        for (int j = t - 1; j >= a; j--) {
            dp[j] = max(dp[j], dp[j - a] + b);
            s = max(s, dp[j]);
        }
        r = max(r, s + ma[i + 1]);
    }

    cout << r << endl;

    //順番は、最後に（使うものの中で）一番時間がかかるものであればよい

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<iostream>
#include<vector>
#include<math.h>
#include<iomanip>
#include<string>
#include<algorithm>
#include<numeric>
#include<utility>
#define ll long long int
#define endl "\n"
#define ss string
using namespace std;
/*ll  mod(ll  a,ll  b)
{
  if(a>b)
    return (a-b);
  else
    return (b-a);
}
double distance(ll  x1, ll  y1, ll  x2, ll  y2)
{

    return sqrt(pow(x2 - x1, 2) +
                pow(y2 - y1, 2) * 1.0);
}*/


int main()
{
 ss s1,s2;
 cin>>s1>>s2;
 int m=s2.size()-1;
 s2.pop_back();
 if(s1==s2)
  cout<<"Yes";
 else
  cout<<"No";
    return 0;

}


Measured memory_bytes: 3572
/*
 * Author : Andrew J
*/
#include <bits/stdc++.h>
using namespace std;
#define rall(x) x.rbegin() , x.rend()
#define all(x) x.begin() , x.end()
#define fi first
#define se second
#define pb push_back
using ll = long long;
using ii = pair <int , int>;
void in(int &x);
// const int N = ;
#define singleCase
// #define multipleCase
int n,k;

void work() {
   in(n); in(k);
   vector <int> v(n);
   bool pos = false;
   for (int i = 0 ; i < n ; i++) {
      in(v[i]);
      if (v[i] >= k) {
         pos = true;
      }
   }
   if (!pos) {
      puts("IMPOSSIBLE");
      return;
   }
   int g = v[0];
   for (int i = 1 ; i < n ; i++) {
      g = __gcd(g , v[i]);
   }
   if (k % g == 0) {
      puts("POSSIBLE");
   } else {
      puts("IMPOSSIBLE");
   }
   return;
}

int main() {
   #ifdef multipleCase
      int nQ; in(nQ);
      while (nQ--)
         work();
   #endif
   #ifdef singleCase
      work();
   #endif
   return 0;
}

void in(int &x) {
	bool neg = false;
	register int c;
	x = 0;
	c = getchar();
	if(c == '-') {
		neg = true;
		c = getchar();
	}
	for (; c > 47 && c < 58; c = getchar())
	  x = (x << 1) + (x << 3) + c - 48;
	if (neg) x *= -1;
}


Measured memory_bytes: 3644
#include <bits/stdc++.h>
using namespace std;
using Int = long long;
using Graph = vector<vector<pair<int, int>>>;
template <class T>
using priority_queue_min = priority_queue<T, vector<T>, greater<T>>;
Graph minimum_spanning_tree(const Graph &g) {
    Graph ans(g.size());
    priority_queue_min<tuple<int, int, int>> Q;
    vector<bool> used(g.size());
    int cnt = 0;
    used[0] = true;
    cnt++;
    for (auto &e : g[0]) {
        Q.emplace(e.second, 0, e.first);
    }
    while (cnt < g.size()) {
        int cost, src, dst;
        tie(cost, src, dst) = Q.top();
        Q.pop();
        if (!used[dst]) {
            used[dst] = true;
            cnt++;
            ans[src].emplace_back(dst, cost);
            ans[dst].emplace_back(src, cost);
            for (auto &e : g[dst]) {
                if (!used[e.first]) Q.emplace(e.second, dst, e.first);
            }
        }
    }
    return ans;
}
Int sum_edge(const Graph &g) {
    Int ans = 0;
    for (auto &es : g) for (auto &e : es) ans += e.second;
    return ans / 2;
}
vector<vector<int>> max_edge(const Graph &g) {
    vector<vector<int>> ans(g.size(), vector<int>(g.size()));
    stack<pair<int, int>> S;
    for (int i = 0; i < g.size(); i++) {
        S.emplace(i, -1);
        while (!S.empty()) {
            int curr, prev;
            tie(curr, prev) = S.top();
            S.pop();
            for (auto &e : g[curr]) if (prev != e.first) {
                S.emplace(e.first, curr);
                ans[i][e.first] = max(ans[i][curr], e.second);
            }
        }
    }
    return ans;
}
int main() {
    cin.tie(nullptr); ios::sync_with_stdio(false);
    int N, M; cin >> N >> M;
    Graph G(N);
    for (int i = 0; i < M; i++) {
        int a, b, c; cin >> a >> b >> c; a--, b--;
        G[a].emplace_back(b, c);
        G[b].emplace_back(a, c);
    }
    G = minimum_spanning_tree(G);
    auto sum = sum_edge(G);
    auto maxE = max_edge(G);
    int Q; cin >> Q;
    for (int i = 0; i < Q; i++) {
        int s, t; cin >> s >> t; s--, t--;
        cout << sum - maxE[s][t] << '\n';
    }
    return 0;
}


Measured memory_bytes: 66676
#[allow(dead_code)]
fn getline() -> String {
    let mut res = String::new();
    std::io::stdin().read_line(&mut res).ok();
    res
}

#[allow(unused_macros)]
macro_rules! readl {
    ($t: ty) => {
        {
            let s = getline();
            s.trim().parse::<$t>().unwrap()
        }
    };
    ($( $t: ty),+ ) => {
        {
            let s = getline();
            let mut iter = s.trim().split(' ');
            ($(iter.next().unwrap().parse::<$t>().unwrap(),)*)
        }
    };
}

#[allow(unused_macros)]
macro_rules! readlvec {
    ($t: ty) => {
        {
            let s = getline();
            let iter = s.trim().split(' ');
            iter.map(|x| x.parse().unwrap()).collect::<Vec<$t>>()
        }
    }
}

#[allow(unused_macros)]
macro_rules! debug { ($x: expr) => { println!("{}: {:?}", stringify!($x), $x) } }
// macro_rules! debug { ($x: expr) => () }

#[allow(dead_code)]
fn show<T>(iter: T) -> String
where
    T: Iterator,
    T::Item: std::fmt::Display
{
    let mut res = iter.fold(String::new(), |sum, e| sum + &format!("{} ", e));
    res.pop();
    res
}

#[allow(unused_imports)]
use std::cmp::{max, min};
#[allow(unused_imports)]
use std::collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, VecDeque};
#[allow(unused_imports)]
use std::collections::btree_map::Entry::{Occupied, Vacant};

fn main() {
    use std::io::Write;
    let out = std::io::stdout();
    let mut out = std::io::BufWriter::new(out.lock());
    macro_rules! printf { ($($arg:tt)*) => (write!(out, $($arg)*).unwrap()); }
    macro_rules! printfln { () => (writeln!(out).unwrap()); ($($arg:tt)*) => (writeln!(out, $($arg)*).unwrap()); }
    
    let l = readl!(usize);
    
    let n = 20;

    let mut ans = vec![];
    
    
    for i in 0..(n-2) {
        ans.push((i, i+1, 1<<i));
        ans.push((i, i+1, 0));
    }

    let mut x = 0;
    for i in (1..(n-1)).rev() {
        let ra = 1<<i;
        while x+ra <= l {
            ans.push((i, n-1, x));
            x += ra;
        }
    }

    while x < l {
        ans.push((0, n-1, x));
        x += 1
    }
        

    printfln!("{} {}", n, ans.len());
    for &(a, b, c) in &ans {
        printfln!("{} {} {}", a + 1, b + 1, c);
    }
}


Measured memory_bytes: 4352
#include <stdio.h>

int main(int argc, char const *argv[]) {
  int i, j, n, minj, tmp, count = 0;
  int A[100];

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

  for(i = 0; i < n; i++) {
    minj = i;
    for(j = i; j < n; j++) {
      if(A[j] < A[minj]) minj = j;
    }
    if(minj != i) {
      tmp = A[i];
      A[i] = A[minj];
      A[minj] = tmp;
      count++;
    }
  }

  for(i = 0; i < n; i++) {
    printf("%d", A[i]);
    if(i != n - 1) printf(" ");
    else printf("\n");
  }
  printf("%d\n", count);

  return 0;
}


Measured memory_bytes: 1932
//B - Distance
//Hiia
#include <stdio.h>
#include <stdlib.h>//rannsuu, zettaichi(absolute)
#include <time.h>
//srand((unsigned int) time(0));
#include <math.h>//koudona keisann
#include <string.h>//hairetsu
#define max(p,q)((p)>(q)?(p):(q))
#define min(p,q)((p)<(q)?(p):(q))
typedef long long ll;
//#define N 998244353
#define pi 3.1415926535897932384626433832

int gcd(int m,int n){if((0==m)||(0==n))return 0;while(m!=n)if(m>n)m=m-n;else n=n-m;return m;}
int lcm(int m,int n){if((0==m)||(0==n))return 0;return(m*n/gcd(m, n));}
int fact(int x){if(x==1) return(x);else return(x*fact(x-1));}//Kaijou x!
int ruijou(int base,int exponent){int i,answer=1;i=exponent;while(i!=0){answer=answer*base;--i;}return answer;}//ruijou base^exponent

long long int llgcd(long long int m,long long int n){if((0==m)||(0==n))return 0;while(m!=n)if(m>n)m=m-n;else n=n-m;return m;}
long long int lllcm(long long int m,long long int n){if((0==m)||(0==n))return 0;return(m*n/llgcd(m, n));}
long long int llfact(long long int x){if(x==1) return(x);else return(x*llfact(x-1));}//Kaijou
int llruijou(long long int base,long long int exponent){long long int i,answer=1;i=exponent;while(i!=0){answer=answer*base;--i;}return answer;}//ruijou base^exponent

int main()
{
  ll n,d,x[200010],y[200010],c=0;
  scanf("%lld %lld", &n, &d);
  for(ll i = 1; i <= n; i++) {
    scanf("%lld %lld", &x[i], &y[i]);
    if(x[i]*x[i]+y[i]*y[i]<=d*d){
      c++;
    }
  }
  printf("%lld\n", c);
  return 0;
}


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

typedef long long int in;

in dp[2][100005],l=1000000007,vis[100005];

vector<in> v[100005];

void dfs(in node)
{
    vis[node]=1;
    
    for(auto it:v[node])
    if(!vis[it])
    {
        dfs(it);
        
        dp[0][node]=((dp[0][node]%l)*((dp[0][it]+dp[1][it])%l))%l;
        dp[1][node]=(dp[1][node]*dp[0][it])%l;
    }
}

int main() 
{
	in n,i;
	cin>>n;
	
	for(i=1;i<n;++i)
	{
	    in r,g;
	    cin>>r>>g;
	    
	    v[r].push_back(g);
	    v[g].push_back(r);
	}
	
	for(i=0;i<=100000;++i)
	{
	    dp[0][i]=1;
	    dp[1][i]=1;
	}
	
	dfs(1);
	
	in ans=(dp[0][1]+dp[1][1])%l;
	
	cout<<ans;
	
	return 0;
}

Measured memory_bytes: 12288
#include<iostream>
#include<vector>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<queue>
#include<deque>
#include<map>
#include<bitset>
using namespace std;
typedef long long ll;

#define rep(i, n) for(int i = 0;i < (n);i++)
#define repr(i, n) for(int i = (n);i >= 0;i--)
#define repf(i, m, n) for(int i = (m);i < (n);i++)

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 dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0};
//////////////////////////////////////////////////


int main() {
    int n; cin >> n;
    map<string, int> m;
    int mx = 0;
    rep(i,n) {
        string s; cin >> s;
        m[s]++;
        chmax(mx, m[s]);
    }
    for (auto v : m) {
        if (v.second==mx) {
            cout << v.first << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 25216
import java.util.*;

class Main{
	public static void main(String args[]){
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int m = sc.nextInt();
		int[] cou = new int[n+1];
		int[][] s = new int[m][3];
		for(int i = 0; i < m; i++){
			s[i][0] = sc.nextInt();
			s[i][1] = sc.nextInt();
			s[i][2] = i;
		}
		Arrays.sort(s,(a,b)->Integer.compare(a[1],b[1]));
		String[] an = new String[m];
		for(int i = 0; i < m; i++){
			an[s[i][2]] = String.format("%06d%06d",s[i][0],++cou[s[i][0]]);
		}
		for(String a : an){
			System.out.println(a);
		}
	}
}


Measured memory_bytes: 158896
#include <bits/stdc++.h>
using namespace std;
#define int long long
using ll=long long;
using vi=vector<int>;
using vl=vector<long long>;
using pii=pair<int,int>;
using pll=pair<long long,long long>;
#define ITR(i,c) for(auto i=begin(c);i!=end(c);++i)
#define FORE(x,c) for(auto &x:c)
#define REPF(i,a,n) for(int i=a,i##len=(int)(n);i<i##len;++i)
#define REP(i,n) REPF(i,0,n)
#define REPR(i,n) for(int i=(int)(n);i>=0;--i)
#define REPW(i,n) for(i=0;i<(int)(n);++i)
#define ALL(c) begin(c),end(c)
#define RALL(c) rbegin(c),rend(c)
#define SZ(c) ((int)c.size())
#define CONTAIN(c,x) (c.find(x)!=end(c))
#define OUTOFRANGE(y,x,h,w) (y<0||x<0||y>=h||x>=w)
#define dump(...)
const int DX[9]={0,1,0,-1,1,1,-1,-1,0},DY[9]={-1,0,1,0,-1,1,1,-1,0};
#define INF (1001001001)
#define INFLL (1001001001001001001ll)
template<class T> ostream& operator << (ostream &os,const vector<T> &v) {
    ITR(i,v) os << *i << (i==end(v)-1 ? "" : " "); return os; }
template<class T> istream& operator >> (istream &is,vector<T> &v) {
    ITR(i,v) is >> * i; return is; }
template<class T> istream& operator >> (istream &is, pair<T,T> &p) {
        is >> p.first >> p.second; return is; }
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;}
//------------------------------------------------------------------------------
struct before_main_function {
    before_main_function() {
        #ifdef int
            #undef INF
            #define INF INFLL
            #define stoi stoll
        #endif
        cin.tie(0);ios::sync_with_stdio(false);
        cout<<setprecision(15)<<fixed;
    }
} before_main_function;
//------------------8<------------------------------------8<--------------------

signed main() {
    int n,m;
    cin>>n>>m;
    vector<int> red(n,0);
    vector<int> cnt(n,1);
    red[0]=1;
    REP(i,m) {
        int a,b;
        cin>>a>>b;
        a--,b--;
        if(red[a]) {
            red[b]=1;
        }
        cnt[b]++;
        cnt[a]--;
        if(cnt[a]==0) {
            red[a]=0;
        }
    }
    int ans=0;
    REP(i,n) {
        if(red[i]) ans++;
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 1792
def test():
    n,x = map(int,input().split())
    l = list(map(int,input().split()))
    d = [0]
    count = 1
    for i in range(1,n+1):
        a = d[i-1] + l[i-1]
        d.append(a)
        if a <= x:
            count += 1
    print(count)


if __name__ == "__main__":
    test()


Measured memory_bytes: 3060
#include<stdio.h>
#include<stdlib.h>

struct node{
  struct node *right;
  struct node *left;
  struct node *parent;
  int key;
};
typedef struct node * Node;
#define NIL NULL

Node root;

Node treeMinimum(Node x){
  while(x->left!=NIL)x=x->left;
  return x;

}

Node treeMaximum(Node x){
  while(x->right!=NIL)x=x->right;
  return x;


}

Node treeSearch(Node u, int k){
  while(u!=NIL&&k!=u->key){
    if(k<u->key)u=u->left;
    else u=u->right;
  }
  return u;
}

Node treeSuccessor(Node x){
  Node y;
  if(x->right!=NIL)return treeMinimum(x->right);

  y=x->parent;
  while(y!=NIL && x==y->right){
    x=y;
    y=y->parent;
  }
  return y;
}

void treeDelete(Node z){
  Node y; // node to be deleted
  Node x; // child of y
  if(z->left==NIL||z->right==NIL)y=z;
  else y=treeSuccessor(z);

  if(y->left!=NIL)x=y->left;
  else x=y->right;

  if(x!=NIL)x->parent=y->parent;

  if(y->parent!=NIL)root=x;
  else if(y==y->parent->left)y->parent->left=x;
  else y->parent->right=x;

  if(y!=z)z->key=y->key;
  
}

void insert(int k){
  Node y = NIL;
  Node x = root;
  Node z;

  z = malloc(sizeof(struct node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;

  while(x!=NIL){
    y=x;
    if(z->key<x->key)
      x=x->left;
    else x=x->right;
  }
  z->parent=y;

  if(y==NIL)
    root=z;
  else if(z->key<y->key)
    y->left=z;
  else
    y->right=z;
    
}

void inorder(Node u){
  if(u==NIL)return;
  inorder(u->left);
  printf(" %d",u->key);
  inorder(u->right);
}
void preorder(Node u){
  if(u==NIL)return;
  printf(" %d",u->key);
  preorder(u->left);
  preorder(u->right);
}


int main(){
  int n, i, x;
  char com[20];
  scanf("%d", &n);

  for ( i = 0; i < n; i++ ){
    scanf("%s", com);
    if ( com[0] == 'f' ){
      scanf("%d", &x);
      Node t = treeSearch(root, x);
      if ( t != NIL ) printf("yes\n");
      else printf("no\n");
    } else if ( com[0] == 'i' ){
      scanf("%d", &x);
      insert(x);
    } else if ( com[0] == 'p' ){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    } else if ( com[0] == 'd' ){
      scanf("%d", &x);
      treeDelete(treeSearch(root, x));
    }
  }

  return 0;
}



Measured memory_bytes: 20472
#include <bits/stdc++.h>
using namespace std;
#define ref(i,x,y)for(int i=x;i<=y;++i)
#define def(i,x,y)for(int i=x;i>=y;--i)
const int N=101,mod=1e9+7;
int n,nn,ans,a[N],b[N],f[N][N],g[N][N],f1[N][N],f2[N][N];
int main(){
	cin>>n;nn=n*2-1;
	ref(i,1,nn)cin>>a[i];
	sort(a+1,a+nn+1);
	ref(i,1,n-1)b[i]=(a[i]!=a[i+1]);
	ref(i,n+1,nn)b[i]=(a[i]!=a[i-1]);
	b[n]=1; f[0][0]=1;
	ref(i,1,n-1){
		memset(g,0,sizeof g);
		ref(x,0,nn)ref(y,0,nn)if(f[x][y])
			g[x+b[n-i]][y+b[n+i]]=f[x][y];
		memset(f,0,sizeof f);
		memset(f1,0,sizeof f1);
		memset(f2,0,sizeof f2);
		ref(x,0,nn)ref(y,0,nn)if(g[x][y]){
			(f1[x][y+1]+=g[x][y])%=mod;
			(f2[x+1][y]+=g[x][y])%=mod;
			(f[x][y]+=g[x][y])%=mod;
		}
		def(i,nn,0)def(j,nn,0){
			(f1[i][j]+=f1[i+1][j])%=mod;
			(f2[i][j]+=f2[i][j+1])%=mod;
			(f[i][j]+=f1[i+1][j])%=mod;
			(f[i][j]+=f2[i][j+1])%=mod;
		}
	}
	ref(x,0,nn)ref(y,0,nn)(ans+=f[x][y])%=mod;
	cout<<ans<<endl;
}

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

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

int main() {
	ll A, B, C, D;
	cin >> A >> B >> C >> D;
  	ll LCM = C/gcd(C, D)*D;
	ll ac = (A-1) / C;
	ll ad = (A-1) / D;
	ll bc = B / C;
	ll bd = B / D;
	ll acd = (A-1) / LCM;
	ll bcd = B / LCM;

	ll ans = B-A+1-bc+ac-bd+ad+bcd-acd;
  	cout << ans << endl;
}


Measured memory_bytes: 256
if __name__ == '__main__':
    numbers = input().split()

    a = int(numbers[0])
    b = int(numbers[1])
    c = int(numbers[2])
    d = int(numbers[3])

    a_b = abs(a - b)
    b_c = abs(b - c)
    a_c = abs(a - c)

    if a_c <= d or (a_b <= d and b_c <= d):
        print("Yes")
    else:
        print("No")


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define inf 999999999
#define loop(i, a, b) for (int i = (a), i##len = (b); i < i##len; ++i)
#define rep(i, n) loop(i, 0, n)
#define lin long long
#define lfl long double

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

    long double jpy = 0;
    long double btc = 0;
    rep(i,n)
    {
        long double x;
        string u;
        cin >> x >> u;

        if(u == "JPY")
            jpy += x;
        else
            btc += x;
    }

    long double res = jpy + btc * 380000;

    cout << std::fixed << std::setprecision(4)  << res << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
#define rep(i,n) for (ll i=0;i<(n);++i)
#define rep2(i,a,b) for (ll i=(a);i<(b);++i)
#define debug(x) cout << #x << '=' << x << endl
#define all(v) (v).begin(),(v).end()
const ll MOD=1e9+7;
//const ll MOD=998244353;
const ll INF=1e9;
const ll IINF=1e18;

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;
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int A,B; cin >> A >> B;
    rep(i,10000){
        if (i*8/100==A&&i*10/100==B){
            cout << i << '\n';
            return 0;
        }
    }
    cout << -1 << '\n';
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void) {
        int n;
        scanf("%d", &n);
        int arr[n];
        for (int i = 0; i < n; i++) {
                scanf("%d", &arr[i]);
        }
        int s1, s2, d, pre_d = 0xFFFFFFF;
        for (int i = 1; i < n; i++) {
                s1 = 0;
                s2 = 0;
                for (int j = 0; j < i; j++) {
                        s1 += arr[j];
                }
                for (int j = i; j < n; j++) {
                        s2 += arr[j];
                }
                d = s1 < s2 ? s2 - s1 : s1 - s2;
                if (d > pre_d) {
                        break;
                }
                pre_d = d;
        }
        printf("%d\n", pre_d);
        return 0;
}


Measured memory_bytes: 128