akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define fo(i, n) for (i = 0; i < n; i++)
#define Fo(i, k, n) for (i = k; k < n ? i < n : i > n; k < n ? i += 1 : i -= 1)
#define ll long long
#define si(x) scanf("%d", &x)
#define sl(x) scanf("%lld", &x)
#define ss(s) scanf("%s", s)
#define pi(x) printf("%d\n", x)
#define pl(x) printf("%lld\n", x)
#define ps(s) printf("%s\n", s)
#define deb(x) cout << #x << "=" << x << endl
#define deb2(x, y) cout << #x << "=" << x << ", " << #y << "=" << y << endl
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define clr(x) memset(x, 0, sizeof(x))
#define sortall(x) sort(all(x))
#define tr(it, a) for (auto it = a.begin(); it != a.end(); it++)
#define PI 3.1415926535897932384626
typedef pair<int, int> pii;
typedef pair<ll, ll> pl;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<pii> vpii;


int main()
{
    ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    srand(chrono::high_resolution_clock::now().time_since_epoch().count());

    int n, m, i, j, k;
    cin>>n;
    int orig[n];
    fo(i, n) 
        cin>>orig[i];
    cin>>m;
    int ind[m], price[m];
    fo(i, m) {
        cin>>ind[i]>>price[i];
    }

    fo(i, m) {
        int copy[n] = {0};
        fo(j, n) {
            copy[j] = orig[j];
        }
        copy[ind[i]-1] = price[i];
        int sum = 0;
        fo(k, n) {
            sum+=copy[k];
        }
        cout<<sum<<endl;
    }

return 0;
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
template<class T>
inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}

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

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
//const ll mod = 1000000007;
int H, W, A, B;
string ans[1005];
int Rest[1005];
int main() {
    //cout.precision(10);
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> H >> W >> A >> B;
    for(int h = 0; h <= H; h++) {
        int num = h * A + (H - h) * (W - A);
        int w;
        int rest = num - W * B;
        if((H - 2 * B != 0 && (rest % (H - 2 * B) == 0)) || (rest == 0)) {
            w = rest / (H - 2 * B);
            if(0 <= w && w <= W) {
                w = W - w;
                cerr << h << " " << w << endl;
                for(int i = 0; i < H; i++) {
                    for(int j = 0; j < W; j++) ans[i].push_back('0');
                }
                for(int i = 0; i < w; i++) {
                    Rest[i] = H - B;
                }
                for(int i = w; i < W; i++) {
                    Rest[i] = B;
                }
                for(int i = 0; i < H; i++) {
                    vector<i_i> v;
                    for(int j = 0; j < W; j++) {
                        v.push_back({Rest[j], j});
                    }
                    sort(v.begin(), v.end(), greater<i_i>());
                    int now = W - A;
                    if(i >= h) {
                        now = A;
                    }
                    //cerr << i << " " << now << endl;
                    for(int k = 0; k < now; k++) {
                        int index = v[k].second;
                        ans[i][index] = '1';
                        Rest[index]--;
                    }
                }
                for(int i = 0; i < H; i++) cout << ans[i] << endl;
                return 0;
            }
        }
    }
    cout << "No" << endl;
    return 0;
}


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

using namespace std;

int N,a[1000010];

int main()
{
    scanf("%d",&N);
    for (int i=1;i<=2*N;i++)scanf("%d",&a[i]);
    int ans = 0;
    sort(a+1,a+2*N+1);
    for (int i=1;i<=2*N;i+=2)ans += a[i];
    printf("%d\n",ans);
}

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

using namespace std;
typedef long long ll;

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

int main()
{
    int n;
    cin >> n;
    vector<int> x(n), y(n), h(n);
    rep(i, n) cin >> x[i] >> y[i] >> h[i];

    int idx;
    rep(i, n)
    {
        if (h[i] > 0)
        {
            idx = i;
            break;
        }
    }

    rep(cx, 100 + 1)
    {
        rep(cy, 100 + 1)
        {
            int H = h[idx] + abs(x[idx] - cx) + abs(y[idx] - cy);
            bool ck = true;
            rep(i, n)
            {

                if (h[i] != max(H - abs(x[i] - cx) - abs(y[i] - cy), 0))
                {
                    ck = false;
                    break;
                }
            }
            if (ck)
            {
                printf("%d %d %d\n", cx, cy, H);
            }
        }
    }
    return 0;
}


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

inline int read() {
	register int x = 0, v = 1;
	register char ch = getchar();
	while (!isdigit(ch)) {
		if (ch == '-') v = -1;
		ch = getchar();
	}
	while (isdigit(ch)) {
		x = x * 10 + ch - '0';
		ch = getchar();
	}
	return x * v;
}

char a[1000000];
int len, ans, top;
char list[1000000];

inline void merge(int x, int y) {
	// printf("a=%c b=%c\n", a[x], a[y]);
	list[x] = y;
}

int main() {
	// freopen("in.in", "r", stdin);
	// freopen("out.out", "w", stdout);
	scanf("%s", a + 1);
	len = strlen(a + 1);
	for (int i = 1; i <= len; ++i) {
		if (a[i] != list[top] && top) {
			--top;
			ans += 2;
		} else list[++top] = a[i];
	}
	printf("%d\n", ans);
	return 0;
}



Measured memory_bytes: 384
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cstring>
#include <complex>
#include <stack>
#include <queue>
#include <unordered_map>
#include <map>
using namespace std ;
using ll = long long;

int main(){
    int N,count;
    cin >> N;
    for(int i=1; i<=N; i++){
        count = count+i;
    }
    cout << count << endl;
    return 0 ;
}

Measured memory_bytes: 256
import Control.Arrow (second)
import Data.List (sort, scanl1)
import Data.Vector.Unboxed (Vector)
import qualified Data.Vector.Unboxed as UV
import Data.ByteString.Char8 (ByteString)
import qualified Data.ByteString.Char8 as BSC8



main :: IO ()
main = do
  let readInt = fmap (second BSC8.tail) . BSC8.readInt
  (n, k) <- (\vec -> (vec UV.! 0, vec UV.! 1)) . UV.unfoldrN 2 readInt <$> BSC8.getLine

  ps <- UV.unfoldrN n readInt <$> BSC8.getLine
  print $ sum $ take k $ sort $ UV.toList ps

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

using namespace std;

#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl

template<class T> void printvec(const vector<T>& v) {
  for (auto x : v) { cout << x << " "; }
  cout << endl;
}
template<class T> void printtree(const vector< vector<T> >& tree) {
  for (long long i = 0; i < tree.size(); ++i) {
    cout << i + 1 << ": "; printvec(tree[i]);
  }
}
template<class T, class U> void printmap(const map<T, U>& mp) {
  for (auto x : mp) { cout << x.first << "=>" << x.second << endl; }
}

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

#define rep(i, n) for(ll i = 0; i < n; ++i)
#define all(s) s.begin(), s.end()
#define sz(x) (ll)(x).size()
#define fr first
#define sc second
#define mp make_pair
#define pb push_back
#define eb emplace_back

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> triple;
typedef double D;
typedef vector<ll> vl;
typedef vector<P> vp;

const ll INF = 1e9;
const ll MOD = 1000000007;  // 1e9 + 7

int main(int argc, char** argv) {
  cin.tie(NULL);
  cout.tie(NULL);
  ios_base::sync_with_stdio(false);
  cout << setprecision(10) << fixed;

  ll n;
  cin >> n;
  vector<P> p(n); // pair of <x,y>
  rep(i,n) {
    cin >> p[i].first >> p[i].second;
  }
  vector<pair<double,ll>> v(n); // pair of <angle, idx>
  rep(i,n) {
    double ang = atan2(p[i].first, p[i].second);
    v[i] = pair<double,ll>(ang, i);
  }
  sort(all(v)); // sort by angle

  double ans = 0;
  rep(i,n) { // try all starting node
    double x = 0;
    double y = 0;
    rep(j,n) {
      ll idx = v[(i+j)%n].second;
      x += p[idx].first;
      y += p[idx].second;
      chmax(ans, sqrt(x*x+y*y));
    }
  }

  cout << ans << endl;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
typedef long long ll;
typedef double lf;
typedef pair<ll,ll> ii;
#define REP(i,n) for(int i=0;i<n;i++)
#define REP1(i,n) for(ll i=1;i<=n;i++)
#define RST(i,n) memset(i,n,sizeof i)
#define SZ(a) (int)a.size()
#define ALL(a) a.begin(),a.end()
#define X first
#define Y second
#define mkp make_pair
#define pb push_back
#define eb emplace_back
#define pob pop_back
#ifdef cold66
#define debug(...) do{\
    fprintf(stderr,"%s - %d (%s) = ",__PRETTY_FUNCTION__,__LINE__,#__VA_ARGS__);\
    _do(__VA_ARGS__);\
}while(0)
template<typename T>void _do(T &&_x){cerr<<_x<<endl;}
template<typename T,typename ...S> void _do(T &&_x,S &&..._t){cerr<<_x<<" ,";_do(_t...);}
template<typename _a,typename _b> ostream& operator << (ostream &_s,const pair<_a,_b> &_p){return _s<<"("<<_p.X<<","<<_p.Y<<")";}
template<typename It> ostream& _OUTC(ostream &_s,It _ita,It _itb)
{
    _s<<"{";
    for(It _it=_ita;_it!=_itb;_it++)
    {
        _s<<(_it==_ita?"":",")<<*_it;
    }
    _s<<"}";
    return _s;
}
template<typename _a> ostream &operator << (ostream &_s,vector<_a> &_c){return _OUTC(_s,ALL(_c));}
template<typename _a> ostream &operator << (ostream &_s,set<_a> &_c){return _OUTC(_s,ALL(_c));}
template<typename _a,typename _b> ostream &operator << (ostream &_s,map<_a,_b> &_c){return _OUTC(_s,ALL(_c));}
template<typename _t> void pary(_t _a,_t _b){_OUTC(cerr,_a,_b);cerr<<endl;}
#define IOS()
#else
#define debug(...)
#define pary(...)
#define endl '\n'
#define IOS() ios_base::sync_with_stdio(0);cin.tie(0);
#endif // cold66
//}
template<class T> inline bool chkmax(T &a, const T &b) { return b > a ? a = b, true : false; }
template<class T> inline bool chkmin(T &a, const T &b) { return b < a ? a = b, true : false; }
template<class T> using MaxHeap = priority_queue<T>;
template<class T> using MinHeap = priority_queue<T, vector<T>, greater<T>>;

const ll MAXn=5e2+5,MAXlg=__lg(MAXn)+2;
const ll MOD=1000000007;
const ll INF=0x3f3f3f3f;

int n,m;
int d[MAXn][MAXn];
vector<ii> pos;
vector<pair<ii,ii> > ans;
int main(){
  IOS();
  cin>>n>>m;
  REP(i,n)REP(j,m) cin>>d[i][j];
  REP(i,n){
    if( i&1 ){
      for(int j=m-1;j>=0;j--) pos.eb(i,j);
    }
    else{
      REP(j,m) pos.eb(i,j);
    }
  }
  for(int i=1;i<SZ(pos);i++){
    if( d[pos[i-1].X][pos[i-1].Y]&1 ){
      ans.eb(pos[i-1],pos[i]);
      d[pos[i].X][pos[i].Y]++;
    }
  }
  cout<<SZ(ans)<<endl;
  for( auto i:ans ) cout<<i.X.X+1<<' '<<i.X.Y+1<<' '<<i.Y.X+1<<' '<<i.Y.Y+1<<endl;;
}


Measured memory_bytes: 13036
from sys import stdin

def bfs(graph,start,d):
    queue = [start]
    explored = []

    while len(queue) > 0:
        node = queue.pop(0)
#        print 'node ' + str(node)
        if node not in explored:
            neighbours = graph[node]
            for neighbour in neighbours:
                if neighbour not in queue:
                    # print 'neighbour ' + str(neighbour)
                    if d[neighbour-1] == -1:
                        d[neighbour - 1] = d[node - 1] + 1
                        queue.append(neighbour)
                        # print 'queue ' + str(queue)

            explored.append(node)

        # print 'd ' + str(d)
        # print '\n'


def main():
    n = int(stdin.readline())

    graph_dict = {}

    d = [-1]*n

    for i in xrange(n):
        entry = [int(s) for s in stdin.readline().split()[2:]]
        graph_dict[i+1] = entry

    d[0] = 0
    bfs(graph_dict,1,d)

    for i in xrange(n):
        print str(i+1) + ' ' + str(d[i])

main()


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

struct edge{int to,cost;};
vector<edge> G[2][MAX_V];
int d[2][MAX_V];

int dijkstra(int s,int V,int ver){
    priority_queue< pii,vector<pii>,greater<pii> > que;
    rep(i,MAX_V)d[ver][i]=INF;
    d[ver][s]=0;
    que.push(pii(0,s));
    
    while(que.size()){
        pii p=que.top();
        que.pop();
        
        int v=p.second;
        if(d[ver][v]<p.first)continue;
        
        rep(i,G[ver][v].size()){
            edge e=G[ver][v][i];
            if(d[ver][e.to]>d[ver][v]+e.cost){
                d[ver][e.to]=d[ver][v]+e.cost;
                que.push(pii(d[ver][e.to],e.to));
            }
        }
    }
    return d[ver][V];
}




int main(){
    int n,m;
    while(cin>>n>>m){
        if(n==0&&m==0)break;
        rep(i,2)rep(j,MAX_V)G[i][j].clear();
        rep(i,n){
            int a,b,cost,time;
            cin>>a>>b>>cost>>time;
            a--,b--;
            G[0][a].pb(edge{b,cost});
            G[0][b].pb(edge{a,cost});
            G[1][a].pb(edge{b,time});
            G[1][b].pb(edge{a,time});
        }
        int k;
        cin>>k;
        rep(i,k){
            int p,q,r;
            cin>>p>>q>>r;
            p--,q--;
            cout<<dijkstra(p,q,r)<<endl;
        }
    }
}

Measured memory_bytes: 3128
#include <iostream>
#include <vector>
#include <algorithm>

#define pb push_back

using namespace std;

typedef long long int lli;
typedef unsigned long long int ulli;
typedef pair<int,int> pi;
typedef vector<int> vi;
typedef vector<pair<int,int>> vpi;

bool comp(pi a, pi b) {
    return b.second < b.first;
}
int main() {
    lli n,h,a,b,amax=-1;
    cin >> n >> h;
    vpi vec;
    while(n--) {
        cin >> a >> b;
        vec.pb({b,a});
        amax = max(amax,a);
    }
    sort(vec.rbegin(),vec.rend());
    
    int t = h, x = 0;
    for(auto p:vec) {
        if (p.first >= amax) {
            h -= p.first; x++;
        }
        if(h <= 0) {
            cout << x << "\n"; return 0;
        }
    }
    
    t = (h%amax== 0) ? h/amax: h/amax+1; 
    
    n = t+x;    
    cout << n;
    return 0;
}

Measured memory_bytes: 1400
S = input()
if int(S[:4]) == 2019:
    if int(S[5:7]) == 4:
        if int(S[8:-1]) == 30:
            print('Heisei')
        elif int(S[8:-1]) >= 31:
            print('TBD')
        else:
            print('Heisei')
    elif int(S[5:7]) >= 5:
        print('TBD')
    else:
        print('Heisei')
elif int(S[:4]) >= 2020:
    print('TBD')
else:
    print('Heisei')


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

using namespace std;

const int N=200005;

int n,m,ans;
vector<int>e[N];

int mv[N<<2],tag[N<<2];
void build(int x,int l,int r){
	mv[x]=r-m-1;if(l==r)return;
	int mid=(l+r)>>1,ls=x<<1,rs=ls|1;
	build(ls,l,mid),build(rs,mid+1,r);
}
void update(int x,int l,int r,int s,int t){
	if(l==s&&r==t){tag[x]++,mv[x]++;return;}
	int mid=(l+r)>>1,ls=x<<1,rs=ls|1;
	if(t<=mid)update(ls,l,mid,s,t);
	else if(s>mid)update(rs,mid+1,r,s,t);
	else update(ls,l,mid,s,mid),update(rs,mid+1,r,mid+1,t);
	mv[x]=max(mv[ls],mv[rs])+tag[x];
}

int main(){
	scanf("%d%d",&n,&m);
	for(int i=1,l,r;i<=n;i++)scanf("%d%d",&l,&r),e[l].push_back(r);
	build(1,1,m+1);ans=n-m;
	for(int i=0;i<=m;i++){
		for(int v:e[i])update(1,1,m+1,1,v);
		ans=max(ans,mv[1]-i);
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 14720
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.*;


public class Main {

    public static void main(String[] args) throws IOException {
        Scanner s = new Scanner(System.in);
        int x =s.nextInt(),y=s.nextInt();
        boolean flag = false;
        for(int i=0;i<=x;i++){
            int cr = i*2;
            int tur = (x-i)*4;
            if(cr+tur==y){
                flag = true;
                break;
            }
        }
        System.out.println(flag?"Yes":"No");

    }
}




class Scanner
{
    StringTokenizer st;
    BufferedReader br;

    public Scanner(InputStream s){	br = new BufferedReader(new InputStreamReader(s));}

    public String next() throws IOException
    {
        while (st == null || !st.hasMoreTokens())
            st = new StringTokenizer(br.readLine());
        return st.nextToken();
    }

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

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

    public String nextLine() throws IOException {return br.readLine();}

    public double nextDouble() throws IOException
    {
        String x = next();
        StringBuilder sb = new StringBuilder("0");
        double res = 0, f = 1;
        boolean dec = false, neg = false;
        int start = 0;
        if(x.charAt(0) == '-')
        {
            neg = true;
            start++;
        }
        for(int i = start; i < x.length(); i++)
            if(x.charAt(i) == '.')
            {
                res = Long.parseLong(sb.toString());
                sb = new StringBuilder("0");
                dec = true;
            }
            else
            {
                sb.append(x.charAt(i));
                if(dec)
                    f *= 10;
            }
        res += Long.parseLong(sb.toString()) / f;
        return res * (neg?-1:1);
    }

    public boolean ready() throws IOException {return br.ready();}


}

Measured memory_bytes: 25384
import sys
from io import StringIO
import unittest
import os

# 再帰処理上限(dfs作成時に設定するのが面倒なので限度近い値を組み込む)
sys.setrecursionlimit(999999999)


# 実装を行う関数
def resolve(test=""):
    try:
        a, b, c, d = map(int, input().split())

        aaa = []
        aaa.append(a * c)
        aaa.append(a * d)
        aaa.append(b * c)
        aaa.append(b * d)

        if a <= 0 <= b or c <= 0 <= d:
            aaa.append(0)

        print(max(aaa))

    except IndexError as err:
        print("インデックスエラー:", err.args[0])


# テストクラス
class TestClass(unittest.TestCase):
    def assertIO(self, assert_input, output):
        stdout, sat_in = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(assert_input)
        resolve(sys._getframe().f_back.f_code.co_name)
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, sat_in
        self.assertEqual(out, output)

    def test_input_1(self):
        test_input = """1 2 1 1"""
        output = """2"""
        self.assertIO(test_input, output)

    def test_input_2(self):
        test_input = """3 5 -4 -2"""
        output = """-6"""
        self.assertIO(test_input, output)

    def test_input_3(self):
        test_input = """-1000000000 0 -1000000000 0"""
        output = """1000000000000000000"""
        self.assertIO(test_input, output)

    # 自作テストパターン
    def test_original(self):
        pass


# youk_debug_library
def list_to_tsv(target: [], limit_row: int = 0, limit_column: int = 0) -> str:
    # 行列を制限の範囲内に絞り込む
    if limit_row is not 0:
        target = target[:limit_row]
    if limit_column is not 0:
        target = [i[:limit_column] for i in target]

    # 行番号、列番号を追加
    target = [[cnt] + i for cnt, i in enumerate(target)]  # 行番号
    target.insert(0, [i for i in range(len(target[0]))])  # 列番号
    # tsv形式で出力
    result = ""
    for a in target:
        result += '\t'.join(map(str, a)) + '\r\n'
    return result


# 実装orテストの呼び出し処理
if __name__ == "__main__":
    if os.environ.get("USERNAME") is None:
        # AtCoder提出時の場合
        resolve()

    else:
        # 自PCの場合
        unittest.main(verbosity=2)


Measured memory_bytes: 70876
#include<stdio.h>
int main(void) {
    int num1, num2;
    int ans;
    char enzanshi;


    while(1) {
        scanf("%d %c %d", &num1, &enzanshi, &num2);

        if(enzanshi == '?') {
            break;
        }

        if(enzanshi == '+') {
            ans = num1 + num2;
        } else if(enzanshi == '-') {
            ans = num1 - num2;        
        } else if(enzanshi == '*') {
            ans = num1 * num2;
        } else if(enzanshi == '/') {
            ans = num1 / num2;
        }

        printf("%d\n", ans);
    }
        return 0;
}

Measured memory_bytes: 600
#define _USE_MATH_DEFINES
#include "bits/stdc++.h"
using namespace std;
#define FOR(i,j,k) for(int (i)=(j);(i)<(int)(k);++(i))
#define rep(i,j) FOR(i,0,j)
#define each(x,y) for(auto &(x):(y))
#define mp make_pair
#define MT make_tuple
#define all(x) (x).begin(),(x).end()
#define debug(x) cout<<#x<<": "<<(x)<<endl
#define smax(x,y) (x)=max((x),(y))
#define smin(x,y) (x)=min((x),(y))
#define MEM(x,y) memset((x),(y),sizeof (x))
#define sz(x) (int)(x).size()
#define RT return
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;
using vll = vector<ll>;

void solve() {
    string S;
    cin >> S;
    int N = sz(S);
    int x = 0;
    const string CB = "CB";
    ll ans = 0;
    for (int i = N - 1; i >= 0; --i) {
        if (CB[x % 2] == S[i])x++;
        else if (S[i] == 'A'&&x % 2 == 0)ans += x / 2;
        else if (S[i] == 'C')x = 1;
        else x = 0;
    }
    cout << ans << endl;
}

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

Measured memory_bytes: 720
#include<iostream> 
#include<cstring>
#include<vector>
using namespace std;
typedef long long ll;
int main(){
	int n, k;
	 cin >> n >> k; 
	 vector<int> a(n);
	 int hmax = 0;
	 for(int i = 0; i<n; i++){
	 	cin >> a[i];
	 	if(a[i] > hmax) hmax = a[i];
	 }
	 int l = 1, h = hmax;
	 while(l!=h){
	 	int m = l + (h-l)/2;
	 	
	 	 ll cnt = 0;
	 	for(int i = 0; i<n; i++){
	 		if(a[i] % m == 0){
	 			cnt+=(a[i] / m -1);
			 }
			 else{
			 	cnt += a[i] / m;
			 }
		 }
		 if(cnt <= k){
		 	h = m;
		 } 
		 else {
		 	l = m+1;
		 }
	 }
	 cout << l;
	 return 0;
}

Measured memory_bytes: 3980
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdbool.h>
#include <math.h>
#include <limits.h>
char lowcmp[26]="abcdefghijklmnopqrstuvwxyz";
char upcmp[26]="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
long long mod=1000000007;
int max(int a, int b){return a>b?a:b;}
int min(int a, int b){return a<b?a:b;}
int gcd(int a, int b){return min(a,b)==0?max(a,b):gcd(min(a,b),max(a,b)%min(a,b));}
long long llmax(long long a, long long b){return a>b?a:b;}
long long llmin(long long a, long long b){return a<b?a:b;}
long long llgcd(long long a, long long b){return llmin(a,b)==0?llmax(a,b):llgcd(llmin(a,b),llmax(a,b)%llmin(a,b));}
int assort(const void *a, const void *b){return *(int*)a-*(int*)b;}
int dessort(const void *a, const void *b){return *(int*)b-*(int*)a;}
int llassort(const void *a, const void *b){return *(long long*)a-*(long long*)b;}
int lldessort(const void *a, const void *b){return *(long long*)b-*(long long*)a;}
int charassort(const void *a, const void *b){return strcmp((char*)a ,(char*)b);}
int chardessort(const void *a, const void *b){return strcmp((char*)b ,(char*)a);}
int ntoi(char c){return c-'0';}
int ltoi(char c){return c-'a';}
int utoi(char c){return c-'A';}
long long ncr(int a,int b){long long ans=1;for(int i=0;i<b;i++){ans=ans*(a-i)/(i+1);}return(ans);}
long long npr(int a,int b){long long ans=1;for(int i=0;i<b;i++){ans=ans*(a-i);}return(ans);}


int main(void){
    int a,b,k;
    scanf("%d%d%d",&a,&b,&k);
    for (int i=0; i<k ;i++){
        if (i%2==0){
            if (a%2==1){
                a--;
            }
            b+=a/2;
            a/=2;
        } else {
            if (b%2==1){
                b--;
            }
            a+=b/2;
            b/=2;
        }
    }
    printf("%d %d\n",a,b);
	return 0 ;
}

Measured memory_bytes: 128
//#include <bits/stdc++.h>
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<string>
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<cmath>
#include<cstring>
#include<bitset>
#include<stack>

#define X first
#define Y second
#define PB push_back
#define MP make_pair
#define scd(a) scanf("%d",&a)
#define scdd(a,b) scanf("%d%d",&a,&b)
#define scddd(a,b,c) scanf("%d%d%d",&a,&b,&c)
#define ALL(x) x.begin(),x.end()
#define mst(var,val) memset(var,val,sizeof(var))
#define IOS ios::sync_with_stdio(false);cin.tie(0)
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
#define ls rt<<1
#define rs rt<<1|1
#ifdef local
#define dbg(a) cout << #a": " << a << endl;
#else
#define dbg(a)
#endif // loacl


using namespace std;
typedef long long ll;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef pair <ll, int> pli;
typedef pair <double, double> pdd;
const ll inf=0x3f3f3f3f;
const long long INF=0x3f3f3f3f3f3f3f3fLL;
const double PI=acos(-1.0);
const long double eps=1e-6;
const int mod=1e9+7;
const int maxn=20;
const int N=1e5+10;
const int M=N<<1;
const ll mm=(1LL<<32);

template <class T>
inline void read(T &x) {
    x = 0;
    char c = getchar();
    bool f = 0;
    for (; !isdigit(c); c = getchar()) f ^= c == '-';
    for (; isdigit(c); c = getchar()) x = x * 10 + (c ^ 48);
    x = f ? -x : x;
}

template <class T>
inline void write(T x) {
    if (x < 0) {
        putchar('-');
        x = -x;
    }
    T y = 1;
    int len = 1;
    for (; y <= x / 10; y *= 10) ++len;
    for (; len; --len, x %= y, y /= 10) putchar(x / y + 48);
}
ll qpow(ll a,ll b,ll MOD)
{
    ll ans=1;
    while(b)
    {
        if(b&1) ans=(ans*a)%MOD;
        b>>=1;
        a=(a*a)%MOD;
    }
    return ans;
}

int a[N];
int main()
{
#ifdef local
    //freopen("in.txt","r",stdin);
    //freopen("out.txt","w",stdout);
#endif // local
    int n;cin>>n;
    rep1(i,n) cin>>a[i];
    int mx=0;
    int ans=0;
    for(int i=2;i<=n;++i)
    {
        if(a[i-1]>=a[i]) mx++;
        else ans=max(mx,ans),mx=0;
    }
    ans=max(ans,mx);
    cout<<ans<<endl;
}



Measured memory_bytes: 640
# e1 will be less than e2
def ifcycle(e1,e2):
    while uf[e1]>=0:
        e1=uf[e1]
    while uf[e2]>=0:
        e2=uf[e2]
    if e1==e2:
        return True
    if uf[e1]<=uf[e2]:
        uf[e1]+=uf[e2]
        uf[e2]=e1
    else:
        uf[e2]+=uf[e1]
        uf[e1]=e2
        return False
    
    
x,y=map(int,input().split())
a=[]
# for union-find
uf=[-1]*x
for i in range(y):
    v1,v2,v3=map(int,input().split())
    a.append([v3,v1,v2])
a.sort() 
ans=0 ; cnt=0
for p in range(y):
    w,s,t=a[p]
    if not ifcycle(s,t):
        ans+=w
        cnt+=1
        if cnt>=x: print(w)

print(ans)
























    


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

public class Main {
    public static void main(String[] args) {
        FastScanner sc = new FastScanner();
        long n = sc.nextLong();
        List<Long> list = new ArrayList<>();
        for(long i = 1 ;i*i<=n;i++){
            if(n % i == 0){
                list.add(i);
                list.add(n/i);
            }
        }
        Collections.sort(list);
        long ans = 0;
        for(long k: list){
            if(k == 1){
                continue;
            }
            if(n % (k-1) == n/(k-1)){
                ans += k-1;
            }
        }
        System.out.println(ans);
    }
}

class FastScanner {
    private final InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;

    private boolean hasNextByte() {
        if (ptr < buflen) {
            return true;
        } else {
            ptr = 0;
            try {
                buflen = in.read(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (buflen <= 0) {
                return false;
            }
        }
        return true;
    }

    private int readByte() {
        if (hasNextByte())
            return buffer[ptr++];
        else
            return -1;
    }

    private static boolean isPrintableChar(int c) {
        return 33 <= c && c <= 126;
    }

    public boolean hasNext() {
        while (hasNextByte() && !isPrintableChar(buffer[ptr]))
            ptr++;
        return hasNextByte();
    }

    public String next() {
        if (!hasNext())
            throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while (isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }

    public long nextLong() {
        if (!hasNext())
            throw new NoSuchElementException();
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while (true) {
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            } else if (b == -1 || !isPrintableChar(b)) {
                return minus ? -n : n;
            } else {
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }

    public int nextInt() {
        long nl = nextLong();
        if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE)
            throw new NumberFormatException();
        return (int) nl;
    }

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


Measured memory_bytes: 23508
#include <iostream>
#include <vector>

using namespace std;

typedef long long ll;
typedef vector<int> vi;

#define MX 200005
#define MOD 1'000'000'007
#define invmod(x) bigmod(x,MOD-2)
#define br '\n'

ll bigmod(ll base, ll pw)
{
	ll ret = 1;
	while(pw)
	{
		if(pw&1)
			ret = ret*base %MOD;
		base = base*base %MOD;
		pw >>= 1;
	}
	return ret;
}

int n;
ll fact[MX], inv[MX];

void calc()
{
	fact[0] = 1;
	inv[0] = invmod(1);
	for(int i=1; i<MX; i++)
	{
		fact[i] = i*fact[i-1] %MOD;
		inv[i] = invmod(fact[i]);
	}
}

void treedp(int u, int p, const vector<vi> &adj, vi &sz, vector<ll> &dp)
{
	dp[u] = 1;
	sz[u] = 1;
	for(auto v: adj[u])
	{
		if(v != p)
		{
			treedp(v,u,adj,sz,dp);
			dp[u] = dp[u]*(dp[v]*inv[sz[v]]%MOD) %MOD;
			sz[u] += sz[v];
		}
	}
	dp[u] = dp[u]*fact[sz[u]-1] %MOD;
}

void reroot(int u, int p, const vector<vi> &adj, vi &sz, vector<ll> &dp)
{
	dp[u] = dp[p]*invmod(dp[u]*inv[sz[u]] %MOD) %MOD;
	dp[u] = dp[u]*invmod(n-sz[u]) %MOD;
	for(auto v: adj[u])
	{
		if(v != p)
		{
			dp[u] = dp[u]*(dp[v]*inv[sz[v]]%MOD) %MOD;
		}
	}
	for(auto v: adj[u])
	{
		if(v != p)
		{
			reroot(v,u,adj,sz,dp);
		}
	}
}

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

	calc();

	while(cin >> n)
	{
		vector<vi> adj(n);
		vi sz(n);
		vector<ll> dp(n);

		int u, v;
		for(int i=1; i<n; i++)
		{
			cin >> u >> v;
			u--; v--;
			adj[u].push_back(v);
			adj[v].push_back(u);
		}

		treedp(0,-1,adj,sz,dp);
		for(auto u: adj[0])
			reroot(u,0,adj,sz,dp);
		for(auto x: dp)
			cout << x << br;
	}

	return 0;
}


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

int main(){
  int N;cin>>N;
  string S;cin>>S;
  int ans=0;
  for(int i=0;i<N;i++){
    if(S[i+1]!=S[i]||S[i+1]=='\0')ans++;
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
int main(){
  int a,b,c,d;
  cin>>a>>b>>c>>d;
  if(a<=b&&c<=d)cout<<a+c<<endl;
  else if(a<=b&&c>d)cout<<a+d<<endl;
  else if(a>b&&c<=d)cout<<b+c<<endl;
  else cout<<b+d<<endl;
    return 0;
}


Measured memory_bytes: 256
#![allow(unused, non_snake_case, dead_code, non_upper_case_globals)]
use std::cmp::*;
use std::collections::*;
use std::mem::*;

fn main() {
    let (r, w, e) = (std::io::stdin(), std::io::stdout(), std::io::stderr());
    let mut io = IO::new(r.lock(), w.lock(), e.lock());

    let n: usize = io.read();
    let s = io.chars();
    let mut mp: HashMap<i64, i64> = HashMap::new();
    let ns = s
        .iter()
        .map(|&c| (c as u8 - b'a') as i64)
        .collect::<Vec<_>>();
    for &num in ns.iter() {
        let m = mp.entry(num).or_insert(0);
        *m += 1;
    }
    let ans = mp.iter().fold(1, |ret, (i, x)| ret * (x + 1) % MOD);
    io.writeln((ans - 1 + MOD) % MOD);
}

static MOD: i64 = 1000000007;
static INF: i64 = std::i64::MAX >> 1;
// IO
use std::io::*;
struct IO<R: Read, W: Write, E: Write> {
    Read: R,
    Write: BufWriter<W>,
    Error: BufWriter<E>,
}
impl<R: Read, W: Write, E: Write> IO<R, W, E> {
    fn new(r: R, w: W, e: E) -> IO<R, W, E> {
        IO {
            Read: r,
            Write: BufWriter::new(w),
            Error: BufWriter::new(e),
        }
    }
    fn read<T>(&mut self) -> T
    where
        T: std::str::FromStr,
    {
        let next: String = self
            .Read
            .by_ref()
            .bytes()
            .map(|c| c.unwrap() as char)
            .skip_while(|c| c.is_whitespace())
            .take_while(|c| !c.is_whitespace())
            .collect();
        next.parse().ok().unwrap()
    }
    fn chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
    fn readn<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read::<T>()).collect::<Vec<_>>()
    }
    fn readmat<T: std::str::FromStr>(&mut self, n: usize, m: usize) -> Vec<Vec<T>> {
        (0..n).map(|_| self.readn(m)).collect()
    }
    fn write<S: ToString>(&mut self, val: S) {
        self.Write.write(val.to_string().as_bytes());
    }
    fn writeln<S: ToString>(&mut self, val: S) {
        self.Write.write(val.to_string().as_bytes());
        self.Write.write(b"\n");
    }
    fn debug<S: std::fmt::Debug>(&mut self, val: S) {
        writeln!(self.Error, "(debug) {:?}", &val);
    }
    fn debug2<S: std::fmt::Debug, T: std::fmt::Debug>(&mut self, val1: S, val2: T) {
        writeln!(self.Error, "(debug2) {:?} -> {:?}", val1, val2);
    }
    fn debug3<S: std::fmt::Debug, T: std::fmt::Debug, U: std::fmt::Debug>(
        &mut self,
        val1: S,
        val2: T,
        val3: U,
    ) {
        writeln!(
            self.Error,
            "(debug3) {:?} -> {:?} -> {:?}",
            val1, val2, val3
        );
    }
}


Measured memory_bytes: 4352
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
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; }
const ll INF=1LL<<60;
const int inf=1<<30;
const int mod=1e9+7;
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n,k;cin >> n >> k;
    ll ans=0;
    for(ll i=k;i<=n+1;i++){
        ll r=n*(n+1)/2-(n-i)*(n-i+1)/2;
        ll l=(i-1)*i/2;
        (ans+=r-l+1)%=mod;
    }
    cout << ans << endl;
}

Measured memory_bytes: 3640
from sys import exit

ii = lambda : int(input())
mi = lambda : map(int,input().split())
li = lambda : list(map(int,input().split()))


def main():
    n = ii()
    s,t = input().split()
    ns = ""

    for i in range(n):
        ns+=s[i]
        ns+=t[i]

    print(ns)
    
main()


Measured memory_bytes: 2940
/*
  AtCoder Beginner Contest 096
  D - Five, Five Everywhere
*/

#include<iostream>
using namespace std;

bool isPrime(int x) {
  if (x < 2) return false;
  for (int i = 2; i*i <= x; ++i) {
    if (x % i == 0) return false;
  }
  return true;
}

int N;

int main() {
  scanf("%d", &N);
  for (int i = 2; i <= 55555; ++i) {
    if (isPrime(i) && (i % 5) == 1) {
      printf("%d ", i);
      --N;
    }
    if (N == 0) break;
  }

  printf("\n");
  return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;


public class Main {

    public static void main(String[] args) {

    	Main main=new Main();

    	main.run();

    }

    void run() {

    	Scanner sc=new Scanner(System.in);

    	String[] S=sc.next().split("");

    	int sum=0;
    	for(int i=0;i<S.length;i++) {

    		if(S[i].equals("1")) {
    			sum++;
    		}

    	}

    	System.out.println(sum);



    }
}



Measured memory_bytes: 23636
#include<stdio.h>
int main(void){
	
	int n,s,a[100],max,min,sum,ave,ave1[20],k,l,m;
	
	l=1;
	
	while(1){
		
		scanf("%d",&n);
		sum=0;
		
		if(n==0)break;
		
		for(k=1;k<=n;k++){
			
			scanf("%d",&s);
			
			a[k]=s;
			
			if(k==1){
				max=a[1];
				min=a[1];
			}
			
			if(a[k]>max){
				max=a[k];
			}
			if(a[k]<min){
				min=a[k];
			}
			
			sum=sum+a[k];
			
		}
		
		ave=(sum-max-min)/(n-2);
/*		
		printf("max%d,min%d\n",max,min);
		printf("sum%d,ave%d\n",sum,ave);
*/		
//		printf("%d\n",ave);
		
		ave1[l]=ave;
		
		l++;
	}
	
	for(m=1;m<l;m++){
		printf("%d\n",ave1[m]);
	}
	
	return 0;
}


Measured memory_bytes: 2048
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<n;i++)
#define rep2(i,n) for(int i=0;i<=n;i++)
#define repr(i,a,n) for(int i=a;i<n;i++)
#define all(a) a.begin(),a.end()
#define P pair<long long,long long>
#define double long double
#define vector2(a,b,c) vector<vector<int>> a(b/*縦！w*/,vector<int>(c/*横！w*/))
#define INF 1e10
#define MOD 1e9+7
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; }
using Graph = vector<vector<int>>;
struct edge{int from,to,cost;};
signed main(){
  int a,b;
  cin>>a>>b;
  char c[a][b];
  rep(i,a)rep(j,b)
    cin>>c[i][j];
  int dp[a][b];
  if(c[0][0]=='.')
    dp[0][0]=0;
  else
    dp[0][0]=1;
  rep1(i,a){
    if(c[i-1][0]=='.'&&c[i][0]=='#')
    dp[i][0]=dp[i-1][0]+1;
    else
      dp[i][0]=dp[i-1][0];
      }  
  rep1(i,b){
    if(c[0][i-1]=='.'&&c[0][i]=='#')
    dp[0][i]=dp[0][i-1]+1;
    else
      dp[0][i]=dp[0][i-1];
      }
  rep1(i,a)rep1(j,b){
    if(c[i][j]=='.')
   dp[i][j]=min(dp[i-1][j],dp[i][j-1]);
    else{
      if(c[i-1][j]=='.'&&c[i][j-1]=='.')
      dp[i][j]=min(dp[i-1][j],dp[i][j-1])+1;
      else if(c[i-1][j]=='.'&&c[i][j-1]=='#')
        dp[i][j]=min(dp[i-1][j]+1,dp[i][j-1]);
     else if(c[i][j-1]=='.'&&c[i-1][j]=='#')
        dp[i][j]=min(dp[i-1][j],dp[i][j-1]+1);
      else
        dp[i][j]=min(dp[i-1][j],dp[i][j-1]);
 }
    }
  cout<<dp[a-1][b-1]<<endl;
}


Measured memory_bytes: 384
#include "stdio.h"

int main(){
	int a, b;
	scanf("%d %d", &a, &b);
	
	int x=0;
	int y=0;
	int z=0;
	
	x = a+b;
	y = a-b;
	z = a*b;
	
	if(x >= y && x >= z){
		printf("%d\n", x);
	}
	else if(y >= x && y >= z){
		printf("%d\n", y);
	}
	else if(z >= x && z>= y){
		printf("%d\n", z);
	}
	
	return (0);
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  int a[110];
  for (int i=0; i < n; i++) {
    cin >> a[i];
  }
  int sum=0;
  for (int i=0; i < n; i++) {
    sum += a[i];
  }
  int t=1;
  for (int i=0; i < n; i++){
    if(sum - a[i]<= a[i]){
      cout << "No" << endl;
      return 0;
    }
  }
    cout << "Yes" << endl;
  
}

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

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

int main(){
  int n,k,x;
  int ans=0;
  cin>>n;
  cin>>k;
  rep(i,n){
    cin>>x;
    ans+=(min(abs(x),abs(k-x)))*2;
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
// const bool debug=true;
const bool debug=false;
#define DEBUG if(debug==true)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const ll MOD = 1000000007;

int main(void) {
    int a,b,c,d,e,f;
    cin>>a>>b>>c>>d>>e>>f;
    vector<int> water;
    for(int i=0;a*i<=f/100;i++){
        for(int j=0;a*i+b*j<=f/100;j++)water.push_back(a*i*100+b*j*100);
    }
    int res_ws=0, res_s=0;
    double res_a=0;
    rep(i,water.size()){
        int sugar_max = water[i]/100*e;
        int sugar_amo=0;
        for(int j=0;c*j<=sugar_max&&water[i]+c*j<=f;j++){
            for(int k=0;c*j+d*k<=sugar_max&&water[i]+c*j+d*k<=f;k++)sugar_amo=max(sugar_amo,c*j+d*k);
        }
        if(res_a<=(sugar_amo*100.0)/(sugar_amo+water[i])){
            res_a =(sugar_amo*100.0)/(sugar_amo+water[i]);
            res_ws=sugar_amo+water[i];
            res_s=sugar_amo;
        }
    }
    cout << res_ws << " " << res_s << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <queue>
#include <vector>
#include <utility>
#define maxn 100005
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
int n,m;
vector <int> adj[maxn];
int deg[maxn];
int par[maxn];
int main(){
	scanf("%d%d",&n,&m);
	for(int i=1;i<n+m;i++){
		int u,v;
		scanf("%d%d",&u,&v);
		adj[u].push_back(v);
		deg[v]++;
	}
	queue <int> que;
	for(int i=1;i<=n;i++){
		if(deg[i] == 0){
			par[i] = 0;
			que.push(i);
		}
	}
	for(int i=1;i<=n;i++){
		int u = que.front(); que.pop();
		for(int j=0;j<(int)adj[u].size();j++){
			int v = adj[u][j];
			deg[v]--;
			if(deg[v] == 0){
				par[v] = u;
				que.push(v);
			}
		}
	}
	for(int i=1;i<=n;i++){
		printf("%d\n",par[i]);
	}
	return 0;
}


Measured memory_bytes: 7040
#include <bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef long double ld;
 
#define REP(i,a,n) for(int (i)=(a); (i)<(int)(n); (i)++)
#define rep(i,n) REP(i,0,n)
#define vec vector 


int main(){
  ll N;
  cin >> N;
  vector <ll> A(N);
  rep(i, N) cin >> A.at(i);
  
  map<ll, ll> memo;
  
  rep(i, N){
    memo[A.at(i)]++;
    if(memo[A.at(i)] >=2){
      memo[A.at(i)]=0;
    }
  }
  
  ll res = 0;
  for(const auto & x: memo){
    if(x.second == 1){
      res++;
    }
  }
  
  cout << res;
  
}

Measured memory_bytes: 7296
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int D;
  cin >> D;
  if(D==25)
    cout << "Christmas" << endl;
  else if(D==24)                                                                                 
    cout << "Christmas Eve" << endl;
  else if(D==23)
    cout << "Christmas Eve Eve" << endl;
  else if(D==22)
    cout << "Christmas Eve Eve Eve" << endl;
}


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


int main()
{
  int n;
  cin >> n;
  vector<int> w(n);
  rep(i, n)
    cin >> w[i];
  int r = 0;
  rep(i, n)
    r += w[i];
  int l = 0;
  int ans = r;
  rep(i, n)
  {
    l += w[i];
    r -= w[i];
    int d = abs(r - l);
    if (d < ans)
      ans = d;
    else
      break;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
from collections import Counter, defaultdict
import sys
sys.setrecursionlimit(10 ** 5 + 10)
# input = sys.stdin.readline
from math import factorial
import heapq, bisect
import math
import itertools

def main():
    s = list(input())
    t = list(input())

    if len(set(t) - set(s)) > 0:
        print(-1)
        sys.exit()

    abc_123_dic = defaultdict(int)
    for i in range(26):
        aaa = chr(97 + i)
        abc_123_dic[aaa] = i + 1
        abc_123_dic[i + 1] = aaa


    str_dic = [[] for i in range(27)]

    for i in range(len(s)):
        now_ind = abc_123_dic[s[i]]
        str_dic[now_ind].append(i + 1)


    ans_list = [0 for i in range(len(t))]
    pre_ind = 0
    for i in range(len(t)):
        now_str = t[i]
        now_ind = abc_123_dic[now_str]
        insert_ind = bisect.bisect_right(str_dic[now_ind], pre_ind)
        if insert_ind == len(str_dic[now_ind]):
            ans_list[i] = str_dic[now_ind][0]
        else:
            ans_list[i] = str_dic[now_ind][insert_ind]
        pre_ind = ans_list[i]

    pre_ind = 0
    ans = 0
    # print(ans_list)
    for i in range(len(t)):
        if pre_ind >= ans_list[i]:
           ans += len(s)
        pre_ind = ans_list[i]
        # print(ans)
    ans += ans_list[len(t) - 1]
    print(ans)






if __name__ == '__main__':
    main()



Measured memory_bytes: 60380
#include <bits/stdc++.h>
typedef long long ll;
#define REP(i,a) for(int i = 0; i < (a); i++)
using namespace std;
#define INF 1e9

int dist[200][200];
int N,M,R;

void warshall_floyd(){
	REP(k,N)
		REP(i,N)
			REP(j,N)
				dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);
}

int main(){
	cin >> N >> M >> R;
	int r[R];
	REP(i,R){
		cin >> r[i];
		r[i]--;
	}
	int a[M],b[M],c[M];
	REP(i,M) cin >> a[i] >> b[i] >> c[i];
	REP(i,N){
		REP(j,N){
			dist[i][j] = INF;
		}
	}
	REP(i,M){
		dist[a[i] - 1][b[i] - 1] = c[i];
		dist[b[i] - 1][a[i] - 1] = c[i];
	}
	warshall_floyd();
	sort(r, r + R);
	int ans = INF;
	do{
		int num = 0;
		REP(i,R - 1) num += dist[r[i]][r[i + 1]];
		ans = min(ans, num);
	}while(next_permutation(r, r + R));
	cout << ans << endl;
}

Measured memory_bytes: 640
import qualified Data.Text as T
import qualified Data.Text.IO as T
import qualified Data.Text.Read as T
import Data.IntMap.Strict (IntMap)
import qualified Data.IntMap.Strict as IMS
import Data.Bool (bool)

main :: IO ()
main = do
  [n, m] <- map unsafeTextToInt . T.words <$> T.getLine :: IO [Int]
  abs <- sequence . replicate m $ unsafeListToPair . map (pred . unsafeTextToInt) . T.words <$> T.getLine :: IO [(Int, Int)]
  let
    (u, v) = foldl step (IMS.empty, IMS.empty) abs :: (IntMap Int, IntMap Int)
      where
        step uv (i, j) = fst $ unite i j uv
--  print . maximum . map (\i -> IMS.findWithDefault 1 (snd $ root i u) v) $ [0..(n - 1)]
  print . maximum . (1 :) . IMS.elems $ v

type UF = IntMap Int

parent :: Int -> UF -> Maybe Int
parent = IMS.lookup

root :: Int -> UF -> (UF, Int)
root i u = maybe (u, i) (\j -> let (u', j') = root j u in (bool (IMS.insert i j' u') u (j' == j), j')) (parent i u)

unite :: Int -> Int -> (UF, IntMap Int) -> ((UF, IntMap Int), ())
unite i j (u, v) | i' == j'  = ((u'', v), ())
                 | otherwise = ((IMS.insert j' i' u'', IMS.alter (Just . ((IMS.findWithDefault 1 j' v) +) . maybe 1 id) i' v), ())
  where
    (u', i') = root i u
    (u'', j') = root j u'

isSame :: Int -> Int -> UF -> (UF, Bool)
isSame i j u = (u'', i' == j')
  where
    (u', i') = root i u
    (u'', j') = root j u'

unsafeListToPair :: [Int] -> (Int, Int)
unsafeListToPair [x, y] = (x, y)
{-# INLINE unsafeListToPair #-}

unsafeTextToInt :: T.Text -> Int
unsafeTextToInt s = case T.signed T.decimal s of
  Right (n, _) -> n
{-# INLINE unsafeTextToInt #-}


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

#define rep(i, n) for (ll i = 0; i < (n); i++)
#define rep2(i, a, b) for (ll i = (a); i < (b); i++)
#define chmax(x, v)                                                            \
  do {                                                                         \
    x = max(x, v);                                                             \
  } while (0)
typedef uint64_t ull;
typedef int64_t ll;
typedef std::pair<ll, ll> PLL;

using namespace std;

signed main() {
  ll x, y;
  cin >> x >> y;
  if (x == y) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
  return 0;
}


Measured memory_bytes: 256
from copy import copy
n, *a = map(int, open(0).read().split())
a.sort()
b = copy(a)
for i in range(n - 1):
    b[i + 1] += b[i]

ans = 0
for i in range(n - 1):
    if b[i] * 2 < a[i + 1]:
        ans = i + 1
print(n - ans)


Measured memory_bytes: 20160