akhauriyash/Code-Regression huggingface dataset:
import sys
sys.setrecursionlimit(10**9)
 
def dfs(now, prev):
    # 今いる頂点から行ける頂点を順に next に入れてループ
    for next, w in g[now]:
        if ans[next] == -1:
            ans[next]=0
            if  w % 2 != 0:
                if ans[now]==0:
                    ans[next]=1
                    dfs(next,now)
                else:
                    ans[next]=0
                    dfs(next,now)
            else:
                ans[next]=ans[now]
                dfs(next,now)
    
 
#木構造の取り込み 
n=int(input())
g = [[] for i in range(n)]
for i in range(n-1):
    u, v , w= map(int, input().split())
    u -= 1
    v -= 1
    g[u].append([v,w])
    g[v].append([u,w])

ans=[-1]*n
ans[0]=0
dfs(0,0)
for i in range(n):
    print(ans[i])

Measured memory_bytes: 85212
import java.util.*;

public class Main {

    public static void main(String args[]) {

        // 入力
        Scanner sc = new Scanner(System.in);
        Integer[] c1 = new Integer[3];
        Integer[] c2 = new Integer[3];
        Integer[] c3 = new Integer[3];
        Arrays.setAll(c1, i -> Integer.parseInt(sc.next()));
        Arrays.setAll(c2, i -> Integer.parseInt(sc.next()));
        Arrays.setAll(c3, i -> Integer.parseInt(sc.next()));
        sc.close();

        // 主処理
        Integer[] vertical = new Integer[] { c1[0] - c1[0], c2[0] - c1[0], c3[0] - c1[0] };

        Integer[] newC1 = new Integer[] { vertical[0] + c1[0], vertical[0] + c1[1], vertical[0] + c1[2] };
        Integer[] newC2 = new Integer[] { vertical[1] + c1[0], vertical[1] + c1[1], vertical[1] + c1[2] };
        Integer[] newC3 = new Integer[] { vertical[2] + c1[0], vertical[2] + c1[1], vertical[2] + c1[2] };

        boolean judge1 = Arrays.equals(c1, newC1);
        boolean judge2 = Arrays.equals(c2, newC2);
        boolean judge3 = Arrays.equals(c3, newC3);
        boolean judge = judge1 && judge2 && judge3;
        String result = judge ? "Yes" : "No";

        // 出力
        System.out.println(result);
    }
}


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

int main() {
    ll X;
    cin >> X;
    rep(i, 150){
        for(ll j=-i; j<=i; j++){
            if(i*i*i*i*i-j*j*j*j*j==X){
                cout << i << " " << j << endl;
            }
        }
    }
}

Measured memory_bytes: 3564
#include <bits/stdc++.h>
#include<algorithm>
 using namespace std;
 #define ll long long int
 
 int main(){
 ll n,x,t;
 cin>>n>>x>>t;
 if(n<=x){
	 cout<<t<<endl;
 }
 else if(n>x){
	 ll temp1=n%x;
	 ll temp=n/x;
	 if(temp1==0){
	 cout<<temp*t<<endl;
 }
 else{
	 cout<<(temp*t)+t<<endl;
 }
 }
 return 0;
 
 }
 

Measured memory_bytes: 3596
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<iostream>
#include<map>
#include<numeric>
#include<queue>
#include<sstream>
#include<stack>
#include<string>
#include<unordered_set>
#include<vector>

#define ll long long
#define P pair<int,int>
#define FOR(i,N) for(int i=0;i<(int)N;i++)
#define FORIN(i,a,b) for(int i=a;i<(int)b;i++)
#define ALL(x) (x).begin(),(x).end()
#define LAST(x) (x)[(x).size()-1]
#define GI(name) int (name);scanf("%d",&(name))
#define GI2(name1,name2) int (name1),(name2);scanf("%d %d",&(name1),&(name2))
#define GI3(name1,name2,name3) int (name1),(name2),(name3);scanf("%d %d %d",&(name1),&(name2),&(name3))
#define GVI(name,size) vector<int> (name)(size);FOR(i,(size))scanf("%d",&(name)[i])
#define MOD 1000000007

using namespace std;

string to_hex(int x){
    stringstream ss;
    ss<<hex<<x;
    return ss.str();
}

inline int get_int(){
    int ret;
    scanf("%d",&ret);
    return ret;
}

inline vector<int> get_ints(int n){
    vector<int> ret(n);
    FOR(i,n){
        scanf("%d",&ret[i]);
    }
    return ret;
}

inline string get_str(){
    string ret;
    cin>>ret;
    return ret;
}

bool is_prime(int n){
    int s=sqrt(n)+1;
    for(int i=2;i<=s;++i){
        if(n%i==0){
            return 0;
        }
    }
    return 1;
}

vector<P> prime_division(int n){
    vector<P> ret;
    int s=sqrt(n)+1;
    int c=0;
    for(int i=2;i<=n;++i){
        if(n%i==0){
            c=0;
            do{
                ++c;
                n/=i;
            }while(n%i==0);
            ret.push_back(P(i,c));
        }
    }
    return ret;
}

struct UnionFind{
    vector<int> data;
    UnionFind(int size){
        data=vector<int>(size,-1);
    }
    bool union_set(int x,int y){
        x=root(x);
        y=root(y);
        if(x!=y){
            if(data[y]<data[x])swap(x,y);
            data[x]+=data[y];
            data[y]=x;
        }
        return x!=y;
    }
    bool find(int x,int y){
        return root(x)==root(y);
    }
    int root(int x){
        return data[x]<0?x:data[x]=root(data[x]);
    }
    int size(int x){
        return -data[root(x)];
    }
};

string to_string(string s){
    return s;
}

template<class T>
string to_string(vector<T> v){
    string ret="{";
    FOR(i,v.size()-1){
        ret+=to_string(v[i])+",";
    }
    if(v.size()>0){
        ret+=to_string(LAST(v));
    }
    ret+="}";
    return ret;
}

void debug_print(){
    cerr<<endl;
}

template<class Head,class... Tail>
void debug_print(Head head,Tail... tail){
    cerr<<to_string(head)<<" ";
    debug_print(tail...);
}

template<class... T>
void debug(T... args){
    cerr<<"["<<__LINE__<<"]: ";
    debug_print(args...);
}

void print(){
    cout<<endl;
}

template<class Head,class... Tail>
void print(Head head,Tail... tail){
    cout<<to_string(head);
    print(tail...);
}

int main(){
    GI(N);
    int list[9]={};
    FOR(i,N){
        GI(a);
        list[min(8,a/400)]++;
    }
    int ans=0;
    FOR(i,8){
        if(list[i])ans++;
    }
    cout<<max(1,ans)<<" "<<ans+list[8]<<endl;
    return 0;
}

Measured memory_bytes: 256
//ABC067 A - Sharing Cookies
#include <iostream>
using namespace std;

int main(void){
  int a,b;
  cin >> a >> b;  
  int c = a + b;

  if((a%3==0)||(b%3==0)||(c%3==0)){
    cout << "Possible" << endl;
  }
  else{
    cout << "Impossible" << endl;
  }

  return 0;
}



Measured memory_bytes: 256
using System;
using System.Linq;

namespace ConsoleApp95 {
    class Program {
        static void Main(string[] args) {
            var st = Console.ReadLine().Split().Select(int.Parse).ToArray();
            int A = st[0];
            int B = st[1];
            int C = st[2];
            int D = st[3];
            int E = st[4];
            int F = st[5];

            int ans_overall = 0;
            int ans_sugar = 0;
            double max_density = -1;

            for (int a = 0; a * 100 * A <= F; a++) {
                for (int b = 0; a * 100 * A + b * 100 * B <= F; b++) {
                    for (int c = 0; a * 100 * A + b * 100 * B + c * C <= F; c++) {
                        for (int d = 0; a * 100 * A + b * 100 * B + c * C + d * D <= F; d++) {
                            int water = a * 100 * A + b * 100 * B;
                            int sugar = c * C + d * D;
                            int sum = water + sugar;
                            if (sugar <= E * water / 100) {
                                double density = (double)sugar * 100 / sum;

                                if (density > max_density) {
                                    max_density = density;
                                    ans_overall = sum;
                                    ans_sugar = sugar;
                                }
                            }
                        }
                    }
                }
            }
            Console.WriteLine(ans_overall + " " + ans_sugar);
        }
    }
}

Measured memory_bytes: 13268
import java.util.Scanner;

public class Main {

    private static Scanner sc = new Scanner(System.in);

    public static void main(String[] args) {
        int d = sc.nextInt();
        int eve = 25 - d;
        StringBuilder sb = new StringBuilder("Christmas");
        for (int i = 0; i < eve; i++) {
            sb.append(" Eve");
        }
        System.out.println(sb);
    }
}

Measured memory_bytes: 23252
n,m = map(int,input().split())
li=[]
ac_li=[0]*n
wa_li=[0]*n
ac = 0
wa = 0
for _ in range(m):
    a,b = input().split()
    li.append([int(a),b])

for i in li:
    if i[1] == "AC":
        if ac_li[i[0]-1] == 0:
            ac_li[i[0]-1] = 1
            ac +=1
    else:
        if ac_li[i[0]-1] == 0:
            wa_li[i[0]-1] += 1

for j in range(n):
    if ac_li[j]==1:
        wa += wa_li[j]
print(ac,wa)

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

int main(){
	ios_base::sync_with_stdio(0); cin.tie(0);
    string s;cin>>s;
    if(s[2]==s[3]&&s[4]==s[5]){
        cout<<"Yes\n";
    }else{
        cout<<"No\n";
    }
}


Measured memory_bytes: 256
#include"bits/stdc++.h"
using namespace std;
using ll=long long;
template<typename T=ll>inline T in(istream&is=cin){T ret;is>>ret;return ret;}
template<typename T>inline auto vec2(typename vector<T>::size_type h,typename vector<T>::size_type w,T v=T()){return vector<vector<T>>(h,vector<T>(w,v));}

int main()
{
    cout<<"Yes"<<endl;
    ll n=in(),m=in();
    vector<vector<ll>>e(n);
    for(ll i=0;i<m;++i){
        ll a=in()-1,b=in()-1;
        e[a].push_back(b);
        e[b].push_back(a);
    }
    vector<ll>ans(n,-1);
    queue<ll>q;q.push(0);
    while(!q.empty()){
        ll r=q.front();q.pop();
        for(auto rr:e[r]){
            if(ans[rr]==-1){
                ans[rr]=r+1;
                q.push(rr);
            }
        }
    }
    for(ll i=1;i<n;++i)cout<<ans[i]<<endl;
}


Measured memory_bytes: 13024
wlist = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
k = int(input()) - 1
print(wlist[k])

Measured memory_bytes: 2940
#include<iostream>
using ll = long long;
using namespace std;

int main()
{
  ll a;
  double b;
  cin >> a >> b;
  ll b2 = (b*100) + 0.5; //〇.66666とかをくっきりさせるために少数をたす 
  a =  (a * b2) / 100;
  cout << a << '\n';
}


Measured memory_bytes: 3192
#include <bits/stdc++.h> 
using namespace std;
using ll=long long;
using ull=unsigned long long;

#define int ll
using pii=pair<int,int>;
#define INF LONG_MAX
#define MOD 1000000007
#define rng(a) a.begin(),a.end()
#define rrng(a) a.end(),a.begin()

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

  int N;
  cin>>N;
  vector<pii>x(N);
  for(int i=0;i<N;i++)cin>>x[i].first>>x[i].second;
  vector<pii>X;
  for(int i=0;i<N;i++){
    for(int j=0;j<N;j++){
      if(i==j)continue;
      int p=x[i].first-x[j].first;
      int q=x[i].second-x[j].second;
      X.push_back({p,q});
    }
  }
  int ans=N;
  for(auto it:X){
    int sum=0;
    for(int i=0;i<N;i++){
      for(int j=0;j<N;j++){
        if(i==j)continue;
        int xif=x[i].first;
        int xis=x[i].second;
        int xjf=x[j].first;
        int xjs=x[j].second;
        if(xif-xjf==it.first&&xis-xjs==it.second)sum++;
      }
    }
    ans=min(ans,N-sum);
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <iomanip>
#include <random>
#include <cstdio>
#include <cmath>
#include <map>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (int) n; i++)

int main() {
    int ans = 0;
    rep(i,3) {
        char c; cin >> c;
        if (c == '1')
        {
            ans++;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main() {
    int m,n,i;
    cin>>n>>m;
    if(m==n)
    {
        for(i=0;i<m;i++)
        cout<<n;
    }
    else if(m>n)
    {
        for(i=0;i<m;i++)
        cout<<n;
    }
    else for(i=0;i<n;i++)
    cout<<m;
}


Measured memory_bytes: 256
from bisect import bisect_left
n = int(input())
red = sorted([list(map(int, input().split())) for i in range(n)])
blue = sorted([list(map(int, input().split())) for i in range(n)])

ans = 0
for x,y, in blue:
    i = bisect_left([a[0] for a in red], x)
    tmp = sorted(red[:i], key=lambda x:x[1], reverse=True)
    for xx, yy in tmp:
        if y > yy:
            ans += 1
            red.remove([xx,yy])
            break
print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define loop(n) for (int ngtkana_is_genius = 0; ngtkana_is_genius < int(n); ngtkana_is_genius++)
#define rep(i, begin, end) for(int i = int(begin); i < int(end); i++)
#define all(v) v.begin(), v.end()
#define rand(l, r) std::uniform_int_distribution<>(l, r)(mt)
#define lint long long
auto cmn = [](auto& a, auto b){if (a > b) {a = b; return true;} return false;};
auto cmx = [](auto& a, auto b){if (a < b) {a = b; return true;} return false;};
void debug_impl() { std::cerr << std::endl; }
template <typename Head, typename... Tail>
void debug_impl(Head head, Tail... tail){
  std::cerr << " " << head;
  debug_impl(tail...);
}
#ifndef STOPIT
#define debug(...)\
  std::cerr << std::boolalpha << "[" << #__VA_ARGS__ << "]:";\
  debug_impl(__VA_ARGS__);\
  std::cerr << std::noboolalpha;
#else
#define debug 0;
#endif

auto remove_common_header(lint x, lint y) {
  auto mask = std::numeric_limits< lint >::max() >> (__builtin_clzll(x ^ y) - 1);
  return std::make_tuple(x & mask, y & mask, mask);
}

auto ceil2(lint x) {
  if (x == 0 || x == 1) return 1LL;
  return (std::numeric_limits< lint >::max() >> __builtin_clzll(x - 1) - 1) + 1;
}

template < typename Container, typename Value = typename Container::value_type, std::enable_if_t<!std::is_same< Container, std::string >::value, std::nullptr_t> = nullptr>
std::istream& operator>> (std::istream& is, Container& v)
  { for (auto & x : v) { is >> x; } return is; }

template < typename Container, typename Value = typename Container::value_type, std::enable_if_t<!std::is_same< Container, std::string >::value, std::nullptr_t> = nullptr >
std::ostream& operator<< (std::ostream& os, Container const& v) {
 os << "{";
  for (auto it = v.begin(); it != v.end(); it++)
    {os << (it != v.begin() ? "," : "") << *it;}
  return os << "}";
}

int main() {
  std::cin.tie(0); std::cin.sync_with_stdio(false);
  lint a, b; std::cin >> a >> b;
  if (a == b) {
    std::cout << 1 << std::endl;
    return 0;
  }
  lint c;
  std::tie(a, b, c) = remove_common_header(a, b);
  (c /= 2) += 1;
  if (c < b)
    { b = c + ceil2(b + 1 - c) - 1; }
  assert(a <= c && c <= b && b < 2 * c);
  auto ret = (c - a) + std::min(c, b - a + 1);
  std::cout << ret << std::endl;
  return 0;
}


Measured memory_bytes: 256
#include <limits.h>
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

#define int long long

#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define REPS(i, n) for (int i = 1, i##_len = (n); i <= i##_len; ++i)
#define FOR(i, a, b) for (int i = (a), i##_len = (b); i <= i##_len; ++i)
#define REV(i, a, b) for (int i = (a); i >= (b); --i)
#define CLR(a, b) memset((a), (b), sizeof(a))
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define INF (LLONG_MAX - 1e5)

using namespace std;

int N, A[5000];

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

    cin >> N;

    int ans = 0;
    REP(i, N) {
        int a;
        cin >> a;
        ans += a - 1;
    }
    cout << ans << endl;
    return 0;
}


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

using namespace std;

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

	long long n,m,d; cin >> n >> m >> d;

	long double ans;

	if(d != 0)ans = (double)(n-d)*2.0*(m-1.0)/(double)(n*n);
	else ans = (double)n*(m-1.0)/(double)(n*n);
	cout << std::setprecision(20) << ans << endl;	

	return 0;

}

Measured memory_bytes: 256
package main

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

func out(x ...interface{}) {
	fmt.Println(x...)
}

var sc = bufio.NewScanner(os.Stdin)

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

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

func main() {
	sc.Split(bufio.ScanWords)

	A, B := getInt(), getInt()
	ans := -1
	for i := 0; i < 1500; i++ {
		a := int(float64(i) * 0.08)
		b := int(float64(i) * 0.10)
		if a == A && b == B {
			ans = i
			break
		}
	}
	out(ans)
}


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

int main(){
 	int N;
  	double x,sum=0;
  	string T;
  	cin >> N;
  	for(int i=0;i<N;i++){
     	cin >> x >> T;
      	sum += (T == "JPY") ? x : (380000.0*x);
    }
  	printf("%.10lf\n",sum);
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#pragma comment(linker, "/stack:512000000")
#include<utility>
#include<iostream>
#include<fstream>
#include<vector>
#include<array>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<ctime>
#include<functional>
#include<random>
#include<climits>
#include<queue>
#include<stack>
#include<deque>
#include<bitset>
#include<map>
#include<set>
#include<unordered_map>
#include<unordered_set>
#include<cassert>
#include<ccomplex>
#include<chrono>

#ifdef ONLINE_JUDGE
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,tune=native")
#pragma GCC optimize("unroll-loops")
#define int128 __int128
#else
#define int128 long long
#endif

#define all(x) x.begin(), x.end()
#define make_unique(x) sort(all((x))); (x).resize(unique(all((x))) - (x).begin())
#define mp make_pair
#define X first
#define Y second

using namespace std;

using ll = long long;
using ull = unsigned long long;
using ld = long double;
mt19937_64 gen(time(nullptr));

struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        // http://xorshift.di.unimi.it/splitmix64.c
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};

ll mod = 1e9 + 7;

namespace {
    ll mul(ll a, ll b) {
        ll val = a * b - (ll)((ld)a * b / mod) * mod;
        if (val < 0) val += mod;
        if (val >= mod) val -= mod;
        return val;
    }
    ll poww(ll a, ll b) {
        ll val = 1;
        a %= mod;
        while (b > 0) {
            if (b % 2) val = mul(a, val);
            a = mul(a, a);
            b >>= 1;
        }
        return val % mod;
    }
    ll inv(ll a) {
        return poww(a, mod - 2);
    }
}

ll const maxn = 3e5 + 5;

ll dp[3001][3001][5][2];
ll a[3001][3001];


signed main() {
    ios_base::sync_with_stdio(0);cin.tie(0); cout.tie(0);
    
    ll n, m, kk; cin >> n >> m >> kk;
    for (ll i = 0; i < kk; i++) {
        ll r, c; cin >> r >> c; r--; c--;
        ll w; cin >> w;
        a[r][c] = w;
    }
    for (ll i = 0; i < n; i++) {
        for (ll j = 0; j < m; j++) {
            for (ll k = 0; k < 4; k++) { 
                for (ll kk = 0; kk < 2; kk++) {
                    if (kk == 0) {
                        dp[i][j][k + 1][1] = max(dp[i][j][k + 1][1], dp[i][j][k][kk] + a[i][j]);
                    }
                    dp[i][j + 1][k][0] = max(dp[i][j + 1][k][0], dp[i][j][k][kk]);
                    dp[i + 1][j][0][0] = max(dp[i + 1][j][0][0], dp[i][j][k][kk]);
                }
            }
        }
    }
    ll ans = 0;
    for (ll k = 0; k < 4; k++) {
        for (ll kk = 0; kk < 2; kk++) {
            ans = max(ans, dp[n - 1][m - 1][k][kk]);
        }
    }
    cout << ans << endl;
    return 0;
}

/*


*/

/*

*/

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



int main(){
    int n,k;
    int ans=0;
    int now=1;
    cin >> n >> k;
    rep(i,n){
        int a=now*2;
        int b=now+k;
        now=min(a,b);
    }
    cout << now << endl;
    return 0;
}

Measured memory_bytes: 256
s = list(input())
#print(s)

c = 0
n = [] 
ans = [] # -> 追加箇所
for i in range(len(s)):
    if s[i] == "," or s[i] == "." or s[i] == " ":
        if c >= 3 and c <= 6:
            #for j in range(len(n)):
            #    print(n[j], end = "")
            ans = ans + n + [" "] # ->追加箇所

        n.clear()
        c = 0

    else:
        n.append(s[i])
        c += 1
#print(ans)
del ans[-1] # ->追加箇所
#print(ans)
#print(*ans, sep="") # ->追加箇所
for i in range(len(ans)) :
    print(ans[i], end="")
print()


Measured memory_bytes: 5596
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0;i<((int)(n));i++)
#define reg(i,a,b) for(int i = ((int)(a));i<=((int)(b));i++)
#define irep(i,n) for(int i = ((int)(n)-1);i>=0;i--)
#define ireg(i,a,b) for(int i = ((int)(b));i>=((int)(a));i--)
typedef long long ll;

/*
反転数に帰着
*/

string s;
vector<ll> c[100010];
ll t=0,ans=0;
bool beg=true;

void init(){
	cin>>s;
}

int main(void){
	init();
	rep(i,s.size()){
		if(s[i]=='A'){
			if(beg){
				beg=false;
				t++;
			}
			c[t-1].push_back(0);
		}else if(s[i]=='B' && s[i+1]=='C'){
			if(beg){
				beg=false;
				t++;
			}
			c[t-1].push_back(1);
			i++;
		}else{
			beg=true;
		}
	}
	rep(i,t){
		ll tmp=0;
		rep(j,c[i].size()){
			if(c[i][j]==0){
				tmp++;
			}else{
				ans+=tmp;
			}
		}
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 4984
#include<stdio.h>
#include<stdlib.h>
int main()
{
  int x[3]={1,0,0},t;
  char a,b;
  for(;~scanf(" %c,%c",&a,&b);)
    {
      //printf("[a-'A']=%d [b-'A']=%d\n",a-'A',b-'A');
      t=x[a-'A'];
      x[a-'A']=x[b-'A'];
      x[b-'A']=t;
      //  for(t=0;t<3;t++)
      //    printf("%d ",x[t]);
      //  puts("");
    }
  for(t=0;t<3;t++)
    if(x[t]==1)
      printf("%c\n",'A'+t);
  exit(0);      
}

Measured memory_bytes: 0
using System;
using System.Linq;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            var n = int.Parse(Console.ReadLine());
            var a = Console.ReadLine().Split(' ').Select(i => int.Parse(i));
            var eArray = new int[n + 1];
            foreach (var item in a)
            {
                eArray[item]++;
            }
            for (int i = 1; i < eArray.Length; i++)
            {
                Console.WriteLine(eArray[i]);
            }
        }

        private static int GCD(int a, int b)
        {
            if (a == b) return a;
            if (a < b)
            {
                var temp = a;
                a = b;
                b = temp;
            }
            while (b != 0)
            {
                var r = a % b;
                a = b;
                b = r;
            }
            return a;
        }
    }
}


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

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

    int ans = 0;
    rep(i, n-2) {
        if (s.at(i) != 'A')
            continue;
        if (s.at(i+1) !='B')
            continue;
        if (s.at(i+2) != 'C')
            continue;
        ans++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long int ll;
typedef long double ld;
using namespace std;
int main(){
	ios_base::sync_with_stdio(false);  
	cin.tie(NULL);
	int n,k;cin>>n>>k;
	ll arr[n];
	for(int i=0;i<n;i++){
		ll a;cin>>a;
		arr[i] = a;
	}
	for(int i=k;i<n;i++){
		if(arr[i]>arr[i-k]){
			cout<<"Yes"<<endl;
		}
		else{
			cout<<"No"<<endl;
		}
	}
}

Measured memory_bytes: 5156
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
int n,m,i,c[100005],a,b,v,k,t[100005];
set<int> g[100005];
vector<int>first_half;
vector<int>second_half;
vector<int>total;
int par[209],group[209];
int arra[150000];
vector<int>arr;
map<char,int>cp;
map<int,int>mp;
deque<char>stp1;
deque<char>stp2;
map<int,int>pos;
map<string,int>check;
map<string,string>server;
vector<string>ans1;
vector<string>ans2;
vector<string>ans3;
string server1[1009];
string ip1[1009];
string server2[1009];
string ip2[1009];
ll cashier[109];
ll fir[109];
ll sec[100009];
vector<ll>sl1;
vector<ll>sl2;
int main()
{
  	
  ll a,b,c=0,d,e,f,g,h,i,j,k,l,n,s1=1,s2=1,m1=5,m2=15,t,m,mod=1000000007;
  //cin>>t;
  
  cin>>k>>n;
  ll sum1=0,sum2=0;
  for(i=1;i<=n;i++)
  {
     
     cin>>a;
     c=c+a;  	
  }
  
  if(c>k)
    cout<<"-1";
   else
   cout<<k-c; 
       
  
  
  
 
  
  
    	
  }
  
  
  
  	

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

int main(){
    
    int n;
    cin >> n;
    vector<int> a(n);
    for(int i=0; i<n; i++){
        cin >> a.at(i);
        a.at(i) = a.at(i)-(i+1);
    }
    sort(a.begin(),a.end());
    long long sum = 0;
    for(int i: a) {
        sum += abs(i - a.at((int)a.size()/2));
    }
    cout << sum << endl;
}


Measured memory_bytes: 4052
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n;
    cin>>n;
    string ans="";
    while(n!=0){
        if(n%2!=0){
            n--;
            ans="1"+ans;
        }
        else ans="0"+ans;
        n/=-2;
    }
    if(ans=="")ans="0";
    cout<<ans<<endl;
    return 0;
}


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

int main() {
	int a, b;
	string day[] = { "Thursday","Friday","Saturday","Sunday","Monday","Tuesday","Wednesday" };
	int months[] = { 31,29,31,30,31,30,31,31,30,31,30,31 };
	while (cin >> a >> b, a) {
		a--; b--;
		rep(i, a)b += months[i];
		cout << day[b % 7] << endl;
	}
	return 0;
}

Measured memory_bytes: 3172
from collections import Counter
import sys
input = sys.stdin.readline

N = int(input())
AB = [[int(i) for i in input().split()] for _ in range(N)]

mod = 10 ** 9 + 7

def gcd(a, b) :
  if b > a : 
    a, b = b, a
  
  while b != 0 :
    a, b = b, a % b
  return a

p = []
both = 0
zeroa = 0
zerob = 0
for a, b in AB :
  if a == 0 and b == 0 :
    both += 1
    continue
  elif a == 0 :
    zeroa += 1
    continue
  elif b == 0 :
    zerob += 1
    continue
    
  g = gcd(abs(a), abs(b))
  a //= g
  b //= g
  if a < 0 :
    a *= -1
    b *= -1
  p.append((a, b))

ret = 1
visited = set()
cnt = Counter(p)
for k, v in cnt.items() :
  a, b = k
  c, d = b, -a
  if c < 0 :
    c *= -1
    d *= -1
  if cnt[(c, d)] == 0 :
    ret *= pow(2, v, mod)
  else :
    if not (c, d) in visited :
      u = cnt[(c, d)]
      ret *= (pow(2, u, mod) + pow(2, v, mod) - 1)
      visited.add((a, b))
      visited.add((c, d))
  ret %= mod

ret *= pow(2, zeroa, mod) + pow(2, zerob, mod) - 1
ret %= mod

print((ret - 1 + both) % mod)

Measured memory_bytes: 166640
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <queue>
#include <stack>
#include <cstdlib>
#include <map>
#include <iomanip>
#include <set>
#include <stdio.h>
#include <ctype.h>
#include <random>
#include <string.h>
#include <cmath>
#include <unordered_map>
#include <cstdio>
using namespace std;
#define all(vec) vec.begin(),vec.end()
typedef long long ll;

ll gcd(ll x, ll y) {
	if (y == 0)return x;
	return gcd(y, x%y);
}
ll lcm(ll x, ll y) {
	return x / gcd(x, y)*y;
}
ll kai(ll x, ll y, ll m) {
	ll res = 1;
	for (ll i = x - y + 1; i <= x; i++) {
		res *= i; res %= m;
	}
	return res;
}
ll mod_pow(ll x, ll y, ll m) {
	ll res = 1;
	while (y > 0) {
		if (y & 1) {
			res = res * x % m;
		}
		x = x * x % m;
		y >>= 1;
	}
	return res;
}

ll comb(ll x, ll y, ll m) {
	if (y > x)return 0;
	return kai(x, y, m) * mod_pow(kai(y, y, m), m - 2, m) % m;
}

int n, c[30], s[400][30];
int d[30];

signed main() {
	std::random_device rnd;
	cin >> n;
	for (int i = 1; i <= 26; i++)cin >> c[i];
	for (int i = 1; i <= n; i++)for (int j = 1; j <= 26; j++)cin >> s[i][j];
	for (int i = 1; i <= n; i++) {
		int ma = -1000000000, p = 0;
		for (int j = 1; j <= 26; j++) {
			int cnt = 0;
			d[j] = i;
			for (int k = 1; k <= 26; k++)cnt -= c[k] * (i - d[k]);
			cnt += s[i][j];
			if (ma < cnt) {
				ma = cnt;
				p = j;
			}
		}
		cout << p << endl;
	}
}

Measured memory_bytes: 3680
#include <bits/stdc++.h>
//#include <atcoder/all>
#define ll long long int
#define MOD 1000000007
#define P pair<ll,ll>
#define INF 1000000000000000000

//using namespace atcoder;
using namespace std;

int main(void){
  ll n, k;
  cin >> n >> k;
  
  vector<ll> a(n);
  for (int i = 0; i < n; i++){
    cin >> a[i];
  }
  
  vector<ll> bitn(50, 0);
  for (ll i = 0; i < n; i++){
    for (ll j = 0; j < 45; j++){
      if ((a[i] >> j) & 1)
        bitn[j]++;
    }
  }

  ll ans = 0;
  for (ll i = 0; i < n; i++){
    ans += (k ^ a[i]);
  }

  for (ll j = 0; j < 45; j++){
    ll t = 0;
    if (!((k >> j) & 1))
      continue;


    for (ll l = 44; l > j; l--){
      if ((k >> l) & 1)
        t += (1LL << l) * (n - bitn[l]);
      else
        t += (1LL << l) * (bitn[l]);

    }

    t += (1LL << j) * bitn[j];

    for (ll l = j-1; l >= 0; l--){
      t += (1LL << l) * max(bitn[l], n - bitn[l]);
    }

    ans = max(ans, t);
  }


  cout << ans << endl;

  

  return 0;
}


Measured memory_bytes: 4052
#include<stdio.h>

int main(void){
    int i,j,S=0,n,N,ans;
    scanf("%d",&N);
    n = N;

    for(i=1;i<11;i++){
        S += n % 10;
        n = n /10; 
    }

    

    if(N % S == 0){
        printf("Yes");
        return 0;
    }

    printf("No");
    return 0;

}

Measured memory_bytes: 128
N = int(input())
S = input().rstrip()
K = int(input())
char = S[K-1]
answer = ["*"]*N
next_index = 0
index_list = []
for i in range(N):
    now = S.find(char, next_index)
    if now == -1:
        break
    next_index = now + 1 
    index_list.append(now)
for i in index_list:
    answer[i] = char
print(*answer, sep="")


Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define N 100003
#define what_is(x) cerr << #x << " is " << x << endl;

using namespace std;

int main() {
	// for fast input output using cin cout
	std::ios_base::sync_with_stdio(false);

	// size of array
	// input
	int n, m;
	cin >> n >> m;
	long long ans = 0;
	ans += ((n - m) * 100) + (m * 1900);
	ans *= (pow(2, m));

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

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

typedef long long ll;
typedef unsigned int ui;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> ii;
typedef vector<ii> vii;
const int INF = int (1e9) + int (1e5);
const ll INFL = ll(2e18) + ll(1e10);
const ui MOD = 1E9 + 7;
const double EPS = 1e-9;
#define FOR(i,n) for (int i=0;i<(n);++i)
#define ROF(i,x) for(int i = (x) ; i >= 0 ; --i)
#define MP make_pair
#define ALL(a) (a).begin(),(a).end()
#define ODD(x) (((x)&1)==0?(0):(1))
#define sign(x) ((x > 0) - (x < 0))
#define dbg(x) cerr << #x"= " << x << endl

std::mt19937_64  generator(std::chrono::system_clock::now().time_since_epoch().count());

inline ll powmod(ll a,ll b,ll mod) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a, ll b) { return a ? gcd(b%a, a): b; }
ll lcm(ll a, ll b) { return a / gcd(a,b) * b; }


void READ(bool _local){
    ios_base::sync_with_stdio(false); cin.tie(0);
#ifdef _DEBUG
    if (_local)
        freopen ("in.txt", "r", stdin);
#endif
}
int n,m;
string s[21];

int getmx(int a,int b){
	if (s[a][b]=='#') return -1;
	vvi d(n,vi(m));
	FOR(i,n)FOR(j,m) {
		if (s[i][j]=='.') d[i][j]=-1;
		else d[i][j]=INF;
	}
	d[a][b]=0;
	queue<ii> q;
	q.push(MP(a,b));
	int ret=0;
	while(!q.empty()){
		ii p=q.front();q.pop();
		int dd=d[p.first][p.second];
		ret=max(ret,dd);
		++dd;
		if (p.first && d[p.first-1][p.second]==-1){
				d[p.first-1][p.second] =dd;
				q.push(MP(p.first-1,p.second));
		}
		if (p.first+1<n && d[p.first+1][p.second]==-1){
				d[p.first+1][p.second] =dd;
				q.push(MP(p.first+1,p.second));
		}
		if (p.second && d[p.first][p.second-1]==-1){
				d[p.first][p.second-1] =dd;
				q.push(MP(p.first,p.second-1));
		}
		if (p.second+1<m && d[p.first][p.second+1]==-1){
				d[p.first][p.second+1] =dd;
				q.push(MP(p.first,p.second+1));
		}
	}
	return ret;
}
int main() {
    READ(1);
	cin>>n>>m;
	FOR(i,n) cin>>s[i];
	int mx=0;
	FOR(i,n)FOR(j,m) mx=max(mx,getmx(i,j));
	cout << mx;
}



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

#define endl '\n'

int A[(int)1e5 + 123];
int n;

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

    cin >> n;
    for(int i = 1; i <= n; i++) {
        int v;
        cin >> A[i];
    }
    long long res = 0;
    long long c = 0;
    for(int i = 1; i <= n; i++) {
        if(A[i] == i) {
            c++;
        }
        else {
            if(c > 0) {
                res += (c / 2) + (c % 2);
            }
            c = 0;
        }
    }
    if(c > 0) {
        res += (c / 2) + (c % 2);
    }
    cout << res;
    
    return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define repr(i, a, b) for(int i = a; i >= b; i--)
#define int long long
#define all(a) a.begin(), a.end()
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
typedef pair<int, int> P;
const int mod = 1000000007;
const int INF = 1e18;

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    vector<int> a(n), b(n);
    vector<P> c(n);
    int ans = 0;
    rep(i, 0, n){
        cin >> a[i] >> b[i];
        c[i].first = a[i] + b[i];
        c[i].second = i;
    }
    sort(c.rbegin(), c.rend());
    rep(i, 0, n){
        if(i % 2 == 0){
            ans += a[c[i].second];
        }else{
            ans -= b[c[i].second];
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 3456
#include <iostream>
#include <stdio.h>
#include <vector>
#include <queue>
#include <algorithm>
#define pb push_back
#define boost ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
// #define cerr if(0)cerr
using namespace std;
typedef long long LL;

const int N=3010;
string s,t;
int a,b;
int DP[N][N];
vector <char> V;

int main()
{
  boost;
  cin>>s>>t;
  a=s.size();
  b=t.size();
  for(int i=1; i<=a; i++)
  {
    for(int j=1; j<=b; j++)
    {
      if(s[i-1]==t[j-1])DP[i][j]=DP[i-1][j-1]+1;
      else DP[i][j]=max(DP[i][j-1],DP[i-1][j]);
    }
  }
  while(a&&b)
  {
    if(s[a-1]==t[b-1]){
      V.pb(s[a-1]);
      a--;
      b--;
    }
    else
    {
      if(DP[a-1][b]>DP[a][b-1])a--;
      else b--;
    }
  }
  for(int i=V.size()-1; i>=0; i--)cout<<V[i];

  return 0;
}


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

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

        System.out.println(main.solve());
    }

    long solve() {
        int n = sc.nextInt();
        long[] a = new long[n];
        for(int i=0;i<n;i++) a[i] = sc.nextLong();
        long[][] dp = new long[n][2];
        // if i%2=0, choose exactly i/2 from a[0:i]; onlyt dp[i][0] matters
        // else choose either (i-1)/2 (dp[i][0]) or (i+1)/2 (dp[i][1]) from [0:i];
        dp[0][0] = 0; dp[0][1] = a[0];
        dp[1][0] = Math.max(a[0],a[1]); dp[1][1] = dp[1][0];
        for(int i=2;i<n;i++){
            if(i%2==1){
                long temp = Math.max(dp[i-1][1], a[i]+dp[i-2][0]);
                dp[i][0] = temp; dp[i][1] = temp;
            } else{
                // first check dp[i][0], choose(i-1)/2
                long v1 = dp[i-1][0]; // choice 1: choose as i-1
                long v2 = a[i]+dp[i-2][0];
                dp[i][0] = Math.max(v1,v2);
                // then check dp[i][1], choose(i+1)/2
                dp[i][1] = a[i] + dp[i-2][1];
            }
        }
        return dp[n-1][0];
    }
}

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

#define repd(i, a, b) for (ll i = (a); i < (b); i++)
#define repb(i, n) for (ll i = (n)-1; i >= 0; i--)
#define rep(i, n) repd(i, 0, n)

using namespace std;

using ll = long long;
using ul = unsigned long long;
ll mod = 1000000007;

int main() {
source:
    ll n, m;
    cin >> n >> m;
    vector<vector<ll>> v(n);
    ll h[n];
    rep(i, n) { cin >> h[i]; }

    rep(i, m) {
        ll a, b;
        cin >> a >> b;
        a--;
        b--;
        v[a].push_back(b);
        v[b].push_back(a);
    }

    ll ans = 0;
    rep(i, n) {
        bool judge = true;
        for (ll next : v[i]) {
            if (h[next] >= h[i]) {
                judge = false;
                break;
            }
        }
        if (judge) {
            ans++;
        }
    }
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 9860
#include<stdio.h>
#define Max 500000
#define term 1000000000

int Left[(Max/2)+2], Right[(Max/2)+2];
int c=0;


void merge(int e[], int n, int left, int mid, int right){
  int i,j,k;

  int x = (mid-left);
  int y = (right-mid);

  for ( i=0; i<x; i++ )
   Left[i] = e[left+i];
  for ( i=0; i<y; i++ )
   Right[i] = e[mid+i];

  Left[x]= Right[y] = term;
  i = j = 0;
  for ( k=left; k<right; k++){
    c++;
    if ( Left[i]<=Right[j] ){
      e[k] = Left[i++];
    } else {
      e[k] = Right[j++];
    }
  }
}

void mergeSort(int e[], int n, int left, int right ){
  int mid;
  if ( left+1<right ){
    mid=(left + right)/2;
    mergeSort(e, n, left, mid);
    mergeSort(e, n, mid, right);
    merge(e, n, left, mid, right);
  }
}

int main(){
  int e[Max], n, i;
  scanf("%d", &n);
  for ( i=0; i<n; i++) {
    scanf("%d", &e[i]);
    if (e[i]>=term ){
      return 1;
    }
  }
  mergeSort(e,n,0,n);

  for ( i=0; i<n; i++) {
    if ( i !=0 ) 
    printf(" ");

    printf("%d", e[i]);
    }
  printf("\n");

  printf("%d\n", c);


  return 0;
}




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

                                                                                   

int main(){


    int h, w, i, j, t, f, x, y;

    char s[51][51];

    int k[51][51];

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

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


    cin >> h >> w;


    for( i = 1 ; i <= h ; i = i + 1 ){

         for( j = 1 ; j <= w ; j = j + 1 ){

              cin >> s[j][i];

              }

         }


    for( i = 1 ; i <= h ; i = i + 1 ){

         for( j = 1 ; j <= w ; j = j + 1 ){

              if( s[j][i] == '.' ){

                  t = 0;

                  for( f = 0 ; f < 8 ; f = f + 1 ){

                       x = j + dx[f];

                       y = i + dy[f];

                       if( x > 0 && y > 0 && w >= x && h >= y && s[x][y] == '#' ) t += 1;

                       }

                  k[j][i] = t;

                  }

              }

         }


    for( i = 1 ; i <= h ; i = i + 1 ){

         for( j = 1 ; j <= w ; j = j + 1 ){

              if( s[j][i] == '#' ) cout << "#";

              else cout << k[j][i];

              }

         cout << endl;

         }


    return 0;

    }

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for(int i= 0; i < (n); i++)
using ll= long long int;
using namespace std;
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; }
ll mod= 1e9 + 7;

int main(){
  int a,b;
  cin >> a >>b;
  if(b%a==0){cout << a+b <<endl;}else{cout <<b-a << endl;}
}

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

int main(){
  int a,b,ans;
  ans=0;
  std::cin>>a>>b;
  std::vector<int>price(a);
  for(int i=0;i<a;i++){
    std::cin>>price[i];
  }
  std::sort(price.begin(),price.end());
  for(int i=0;i<b;i++){
    ans+=price[i];
  }
  std::cout<<ans<<std::endl;
  return 0;
}

Measured memory_bytes: 3656
#include<stdio.h>

int main(){
    int H,W;
    
    while(1){
    scanf("%d %d",&H,&W);
    if(H == 0 && W == 0) break;
    for(int i=0;i<H;i++){
       for(int j=0;j<W;j++){
           if(i % 2 == 0){
               if(j%2==0){
                   printf("#");
               }else {
                   printf(".");
               }
           }else if(i%2==1){
               if(j%2==0){
                   printf(".");
               }else {
                   printf("#");
               }
           }
       }
       printf("\n");
        }
        printf("\n");
    }
    return 0;
}


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

#define ll long long
#define vvi vector<vector<int>>
#define vec vector
#define pq priority_queue
#define all(v) (v).begin(), (v).end()
#define uniqueV(x) sort(x.begin(), x.end()); x.erase(unique(x.begin(), x.end()), x.end());
#define rep(i, n) for (int (i) = (0); (i) < (n); ++(i))
#define repp(i, m, n) for (int (i) = (m); (i) < (n); ++(i))
#define debug(x) cerr << #x << ": " << x << endl;
#define debug2(x, y) cerr<<"("<<#x<<", "<<#y<<") = "<<"("<<x<<", "<<y<<")"<<endl;
#define debug3(x, y, z) cerr<<"("<<#x<<", "<<#y<<", "<<#z<<") = "<<"("<<x<<", "<<y<<", "<<z<<")"<<endl;
#define debugB(value, size) cerr<<#value<<": "<<bitset<size>(value) << endl;
#define line() cerr << "---------------" << endl;

const int dx[] = {1, -1, 0, 0};
const int dy[] = {0, 0, -1, 1};
const double PI = 3.14159265358979323846;

template<typename T>
void printA(vector<T> &printArray, char between = ' ') {
   int paSize = printArray.size();
   for (int i = 0; i < paSize; i++) { cerr << printArray[i] << between;}
   if (between != '\n') {cerr << endl;}
}

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

string s;
map<ll, ll> mp;
ll N, K;

int main() {
   cin >> N >> K;
   rep (i, N) {
      ll a, b;
      cin >> a >> b;
      mp[a] += b;
   }

   ll cnt = 0;
   for (auto x : mp) {
      cnt += x.second;
      if (cnt >= K) {
         cout << x.first << endl;
         return 0;
      }
   }


   return 0;
}

Measured memory_bytes: 4224
#include<stdio.h>
#define MAX 2000001
void Heep(int);
int n,A[MAX];

void Heep(int i) {
  int l,r,large,ala;

  l = 2 * i;
  r = 2 * i + 1;

  if(l <= n && A[l] > A[i])
    large = l;
  else large = i;
  if(r <= n && A[r] > A[large])
    large = r;
  if (large != i) {
    ala = A[i];
    A[i] = A[large];
    A[large] = ala;
    Heep(large);
  }
}
int main() {
  int i;

  scanf("%d",&n);
  for(i = 1 ; i <= n ; i++) {
    scanf("%d",&A[i]);
  }
  
  for(i = n / 2 ; i >= 1 ; i--) {
    Heep(i);
  }
  
  for(i = 1 ; i <= n ; i++) {
    printf(" %d", A[i]);
  }
  
  printf("\n");
  
  return 0;
}




Measured memory_bytes: 3648
#include<cstdio>
#include<algorithm>
using namespace std;
int n,m,a[200005],ans;
bool check(int mid){
	for(int i=mid<<1|1,j=n+n;i<j;++i,--j)
		if(a[i]+a[j]<m)
			return false;
	return true;
}
int main(){
	scanf("%d%d",&n,&m);
	for(int i=1;i<=n+n;++i)scanf("%d",&a[i]);
	sort(a+1,a+n+n+1);
	int l=0,r=n-1,res=n;
	while(l<=r){
		int mid=l+r>>1;
		if(check(mid))res=mid,r=mid-1;
		else l=mid+1;
	}
	for(int i=1,j=res<<1;i<j;++i,--j)ans=max(ans,a[i]+a[j]);
	for(int i=res<<1|1,j=n+n;i<j;++i,--j)ans=max(ans,a[i]+a[j]-m);
	printf("%d\n",ans);
	return 0;
}


Measured memory_bytes: 896
#include <iostream>
#include <algorithm>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <string.h>
#include <vector>
#include <queue>
#include <cmath>
#include <bitset>
#include <complex>
#include <functional>
#include <numeric>
#include <iomanip>

// output
#define SPBR(w, n) std::cout<<(w + 1 == n ? '\n' : ' ');
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl
// utility
#define ALL(i) (i).begin(), (i).end()
#define FOR(i, a, n) for(int i=(a);i<(n);++i)
#define RFOR(i, a, n) for(int i=(n)-1;i>=(a);--i)
#define REP(i, n) for(int i=0;i<int(n);++i)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define IN(a, x, b) (a<=x && x<b)
#define OUT(a, x, b) (x<a || b<=x)
template<class T> inline T chmax(T & a, const T b) { return a = (a < b) ? b : a; }
template<class T> inline T chmin(T& a, const T b) { return a = (a > b) ? b : a; }

// type/const
#define int ll
using ll = long long;
using ull = unsigned long long;
using ld = long double;
const int MOD = 1000000007;
/* const int MOD = 998244353; */
const int INF = 1e18;
const double PI = acos(-1);

using namespace std;
struct INIT { 
  INIT(){cin.tie(0); ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);
}}INIT;


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

  vector<int> A(N, 0);

  REP(i, N-1){
    int a;
    cin >> a;
    A[a-1]++;
  }

  REP(i, N){
    cout << A[i] << "\n";
  }


  return 0;
}

Measured memory_bytes: 4768
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int K = sc.nextInt();
        int t = 7;
        for (int i = 0; i < K; i++){
            if (t % K == 0){
                System.out.println(i + 1);
                System.exit(0);
            }
            t = (t * 10 + 7) % K;
        }

        System.out.println("-1");

    }
}

Measured memory_bytes: 35808
#include <atcoder/all>
#include <bits/stdc++.h>

using namespace std;
using namespace atcoder;
 
int main()
{
  string s;
  cin >> s;
  int n = s.size();
  vector<int> lcp = lcp_array(s, suffix_array(s));
  std::cout << 1ll * n * (n + 1) / 2 - accumulate(lcp.begin(), lcp.end(), 0LL);
}

Measured memory_bytes: 15672
#include<stdio.h>
int main(){
  int i,j,n,a[15][15],x,y;
  while(1){
    for(i=0;i<15;i++)
      for(j=0;j<15;j++)
	a[i][j]=0;
    scanf("%d",&n);
    if(n==0)break;
    a[n/2+1][n/2]=1;
    x=n/2;
    y=n/2+1;
    for(i=2;i<=n*n;i++){
      x++;
      y++;
      if(x>n-1){
	x=0;

      }
      if(y>n-1){
	y=0;

      }
      if(a[y][x]!=0){
	y++;
	x--;
	if(x<0){
	  x=n-1;

	}
	if(y>n-1){
	  y=0;

	}
      }
      a[y][x]=i;
    }
    for(i=0;i<n;i++){
      for(j=0;j<n;j++){
	printf("%4d",a[i][j]);
      }
      printf("\n");
    }
  }
  return 0;
}

Measured memory_bytes: 1044
#include<iostream>
using namespace std;
#define int long long
#define MOD (long long)(1e9+7)
#define MAX_VAL (long long)(1e5*2+100)

long long fac[MAX_VAL], mmi[MAX_VAL], temp[MAX_VAL];

void factorial(){
	fac[0] = fac[1] = 1;
	for(long long i = 2; i < MAX_VAL; fac[i]%=MOD,i++)
		fac[i] = fac[i-1]*(i%MOD);
}


long long power_mod(long long x, long long n){
	long long ans = 1;
	for(;n;n>>=1,x*=x,ans%=MOD,x%=MOD)
		if(n&1)ans*=x;
	return ans%MOD;
}

void modular_multiplicatibe_inverse(){
	mmi[MAX_VAL-1] = power_mod(fac[MAX_VAL-1],MOD-2);
	for(long long i = MAX_VAL-2; i >= 0; mmi[i]%=MOD,i--)
		mmi[i] = mmi[i+1]*((i+1)%MOD);
}

long long combination(long long n, long long r){
	return fac[n]*(mmi[r]*mmi[n-r]%MOD)%MOD;
}

signed main(){
	int H, W, A, B, ans = 0;
	cin>>H>>W>>A>>B;
	factorial();
	modular_multiplicatibe_inverse();

	for(int i = B+1; i <= W; ans%=MOD,i++)
		ans += combination(i+H-A-2,H-A-1)*combination(A+W-i-1,W-i)%MOD;
	
	cout<<ans<<endl;

}

Measured memory_bytes: 3328
#include<bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rep2(i, m, n) for(int i = (int)(m); i < (int)(n); i++)
#define rep_inv(i, n, m) for(int i = (int)(n); i > (int)(m); i--)
using namespace std;
using ll = long long;
using vl = vector<ll>;
using vc = vector<char>;
using vvl = vector<vl>;
using vvc = vector<vc>;
using pll = pair<ll, ll>;
using vpll = vector<pll>;

int main(){
  ll N;
  cin >> N;
  map<ll, ll> num;
  ll A;
  rep(i, N){
    cin >> A;

    if(num[A] == 1)
      num[A] = 0;
    else
      num[A] = 1;
  }

  ll cnt = 0;
  for(auto it = num.begin(); it != num.end(); it++){
    if(it->second == 1) cnt++;
  }

  cout << cnt << endl;
  
  return 0;
}


Measured memory_bytes: 6528
N, a, b = gets.strip.split.map(&:to_i)

def digit_sum(x)
  s = 0
  while x > 0
    s += x % 10
    x /= 10
  end
  s
end

ans = (1...N + 1)
          .map { |x| [x, digit_sum(x)] }
          .select { |d| a <= d[1] && d[1] <= b }
          .inject(0) { |sum, d| sum + d[0] }

p ans


Measured memory_bytes: 14600
n = gets.to_i
array = gets.split.map(&:to_i)

height = 0

(n-1).times do |i|
  a = array[i].to_i
  b = array[i+1].to_i
  if a > b
    height += a - b
    array[i+1] = array[i+1] + a - b
  end
end

puts height

Measured memory_bytes: 28216