akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<cstdio>
#include<vector>
#include<algorithm>
#include<cmath>
#include<queue>
using namespace std;

int main(){
    int N;
    while(cin>>N,N){
        vector<int> card[2];
        int ba=-1,in;
        bool latte[201]={},turn=0;
        for(int i=0;i<N;i++){
            cin>>in;
            latte[in]=true;
        }
        for(int i=1;i<=2*N;i++){
            card[!latte[i]].push_back(i);
        }
        sort(card[0].begin(),card[0].end()); sort(card[1].begin(),card[1].end());
        while(card[0].size() && card[1].size()){
            vector<int>::iterator itr =
                upper_bound(card[turn].begin(),card[turn].end(),ba);
            if(itr==card[turn].end()) ba=-1;
            else{
                ba = *itr;
                card[turn].erase(itr);
            }
            turn = !turn;
        }
        printf("%d\n%d\n",card[1].size(),card[0].size());
    }
    return 0;
}

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

int n,k;

long long a[100009];
long long dp[100009];
long long f( long long x)
{
    if(x>=n-1)
    {
        return 0;
    }
    if(dp[x]!=-1)
        return dp[x];
    long long y=100000000009;
    for(int i=1; i<=k && x+i<=n-1; i++)
    {
        y=min(y,(f(x+i)+abs(a[x]-a[x+i]))) ;
    }

    dp[x]=y;
    return y;


}
int main()
{
memset(dp,-1,sizeof dp);
    cin>>n;
    cin>>k;

    for(int i=0; i<n; i++)
    {
        cin>>a[i];
    }
  cout<< f(0);
    return 0;
}


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

int main() {
		
	int n, l; cin >> n >> l;
	vector<string> s(n);
	for (int i = 0; i < n; i++) {
		cin >> s[i];
	}
	sort(s.begin(), s.end());
	string ans = "";
	for (int i = 0; i < n; i++) {
		ans += s[i];
	}

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

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

int main(){
    string S,T,U;
    int A,B;
    cin >> S >> T >> A >> B >> U;
    if (S == U){
        cout << A - 1 << ' ' << B << endl;
    }
    else if (T == U){
        cout << A << ' ' << B - 1 << endl;
    }
}

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

#define int ll
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 emplace_back
#define INF (1LL<<59)

//verified AOJ GRL_1
#define MAX_V 100000
struct edge{int to,cost;};

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

signed main(){
    int v,e,s,t;
    cin>>v>>e>>s>>t;
    s--,t--;
    
    vector<edge> G[MAX_V];
    
    rep(i,e){
        int a,b;
        cin>>a>>b;
        a--,b--;
        G[a].pb(edge{b,1});
        G[b].pb(edge{a,1});
    }
    
    vector<int> d1(v),d2(v);
    dijkstra(s,d1,G);
    dijkstra(t,d2,G);

    int length = d1[t];
    assert(length!=INF);
    
    vector<int> a(MAX_V,0),b(MAX_V,0);
    for(auto e:d1)if(e!=INF) a[e]++;
    for(auto e:d2)if(e!=INF) b[e]++;
    
    ll ans = 0;
    rep(i,MAX_V){
        int less = length - i - 2;
        if(less<0)continue;
        ans += a[i] * b[less];
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 17040
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cstring>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <numeric>
#include <utility>
#include <iomanip>
#include <algorithm>
#include <functional>
#include <unordered_map>
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; }

template<class T> vector<T> make_vec(size_t a) { return vector<T>(a); }
template<class T, class... Ts> auto make_vec(size_t a, Ts... ts) {
  return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}
template<class T, class V>
typename enable_if<is_class<T>::value == 0>::type fill(T &t, const V &v) {
    t = v;
}
template<class T, class V>
typename enable_if<is_class<T>::value != 0>::type fill(T &t, const V &v){
    for (auto &e : t) fill(e, v);
}

#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }

#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)
template<class T> ostream& operator << (ostream &s, set<T> P)
{ EACH(it, P) { s << "<" << *it << "> "; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s << endl; }





int count(const string &S) {
    int res = 0;
    for (int i = 0; i+1 < S.size(); ++i) {
        if (S[i] == 'A' && S[i+1] == 'B') ++res;
    }
    return res;
}

int N;
vector<string> S;

long long solve() {
    long long res = 0;
    for (int i = 0; i < N; ++i) res += count(S[i]);

    int a = 0, b = 0, c = 0;
    for (int i = 0; i < N; ++i) {
        if (S[i][0] == 'B' && S[i].back() == 'A') ++a;
        else if (S[i].back() == 'A') ++b;
        else if (S[i][0] == 'B') ++c;
    }
    long long add = 0;
    if (b + c == 0) add = max(0, a-1);
    else add = a + min(b, c);


    //COUT(a); COUT(b); COUT(c); COUT(add);

    res += add;
    return res;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    while (cin >> N) {
        S.resize(N);
        for (int i = 0; i < N; ++i) cin >> S[i];
        cout << solve() << endl;
    }
}


















Measured memory_bytes: 768
#include <iostream>
#include <string>
#include <vector>
#include <climits>
#include <algorithm>
#include <set>
#include <unordered_map>
#include <queue>
#include <iomanip>
#include <map>

#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define ll long long
#define P pair<int, int>

using namespace std;
int mod = 1000000007;

string s;
int main() {
  cin >> s;
  int ans = 0;
  for(int i=1; i<s.size(); i++) {
    if (s.at(i) != s.at(i-1)) {
      ans++;
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 512
inp = [ i for i in map(int, input().split())]
maximum = 0

patten1 = inp[0] + inp[0]-1
patten2 = inp[0] + inp[1]
patten3 = inp[1] + inp[1]-1

if patten1 > patten2 :
  maximum = patten1
else:
  maximum = patten2

if maximum > patten3:
  print(maximum)
else:
  print(patten3)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
const long long MOD = 1000000007;
const long long INF = MOD + 1;
const long double PI = 3.1415926;
#define FOR(i, r, n) for(int i=(ll)(r); i<(ll)(n); i++) 
#define REP(i, n) FOR(i, (0), n)
#define ALL(r) r.begin(), r.end()
#define ll long long int
using namespace std;
string s;
vector<ll> v;
vector<pair<ll, ll>> vp;
vector<vector<ll>> vv(110, vector<ll>(110, INF));
vector<tuple<ll, ll, ll>> vt;
set<ll> st;
map<char, ll> mp;

ll n, m;
set<pair<ll, ll>> done, imp;
map<pair<int, int>, int> inque;
typedef tuple<ll, ll, ll> TP;
priority_queue <TP,vector<TP>,greater<TP>> que;

void solve(int dep, int x, int y)
{
	if (dep <= n)
	{
		done.emplace(x, y);
		if (dep < n)
		{
			if (!done.count(make_pair(x + 1, y + 1))) {
				inque[make_pair(x + 1, y + 1)] = min(inque[make_pair(x + 1, y + 1)], dep);
				que.emplace(dep + 1, x + 1, y + 1);
			}
			if (!done.count(make_pair(x + 1, y))) {
				inque[make_pair(x + 1, y)] = min(inque[make_pair(x + 1, y)], dep);
				que.emplace(dep + 1, x + 1, y);
			}
			if (!done.count(make_pair(x, y + 1))) {
				inque[make_pair(x, y + 1)] = min(inque[make_pair(x, y + 1)], dep);
				que.emplace(dep + 1, x, y + 1);
			}
			if (!done.count(make_pair(x, y - 1))) {
				inque[make_pair(x, y - 1)] = min(inque[make_pair(x, y - 1)], dep);
				que.emplace(dep + 1, x , y - 1);
			}
			if (!done.count(make_pair(x - 1, y))) {
				inque[make_pair(x - 1, y)] = min(inque[make_pair(x - 1, y)], dep);
				que.emplace(dep + 1, x - 1, y);
			}
			if (!done.count(make_pair(x - 1, y - 1))) {
				inque[make_pair(x - 1, y - 1)] = min(inque[make_pair(x - 1, y - 1)], dep);
				que.emplace(dep + 1, x - 1, y - 1);
			}
		}
	}
}

int main()
{
	while (true)
	{
		done.clear(); imp.clear();
		cin >> n >> m;
		if (!n && !m) break;
		FOR(i, -32, 32)
			FOR(j, -32, 32)
		{
			inque[make_pair(i, j)] = INF;
		}
		REP(i, m)
		{
			ll a, b;
			cin >> a >> b;
			imp.emplace(a, b);
		}
		ll x, y;
		cin >> x >> y;
		que.emplace(0, x, y);
		inque[make_pair(x, y)] = 0;
		while (!que.empty())
		{
			ll dep;
			tie(dep, x, y) = que.top();
			que.pop();
			if (!done.count(make_pair(x, y)) && !imp.count(make_pair(x, y))) solve(dep, x, y);
		}
		cout << done.size() << endl;
	}
}

Measured memory_bytes: 3884
import java.util.Scanner;

class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int num[];
		int answer[];
		int N = sc.nextInt();
		num = new int[N];
		answer = new int[N];
		for(int i = 0; i < N; i++) {
			num[i] = sc.nextInt();
		}
		int lastsum = num[N - 1];
		for(int i = 0; i < N - 1; i += 2) {
			lastsum -= num[i];
		}
		for(int i = 1; i < N ; i += 2) {
			lastsum += num[i];
		}
		answer[N - 1] = lastsum;
		for(int i = N - 2 ; i >= 0 ; i--) {
			answer[i] = 2 * num[i] - answer[i + 1];
		}
		for(int i = 0; i < N; i++) {
			if(i == N - 1) System.out.print(answer[i]);
			else System.out.print(answer[i] + " ");
		}
		sc.close();
	}
}

Measured memory_bytes: 65796
#include<bits/stdc++.h>
#define ll long long
#define FOR(i,start,end) for(int i=start;i<=end;i++)

using namespace std;

int main(void){
    // Your code here!
    ll n; cin >> n;
    ll ans = 0;
    vector<ll> e(n+1,0);
    FOR(i,1,n) {
        for (int j = i; j <= n; j += i) {
            e[j]++;
        }
    }
    FOR(i,1,n) ans+= i*e[i];
    cout << ans << endl;
}

Measured memory_bytes: 81400
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <cstdlib>
#include <set>
#include <queue>
using namespace std;
typedef long long LL;
const int inf = 1 << 30;
const LL INF = 1LL << 60;
const int MaxN = 100005;

char s[20];

int main()
{
	while(scanf("%s", s + 1) != EOF)
	{
		int len = strlen(s + 1);
		int x = s[1] - '0' - 1 + (len - 1) * 9;
		int y = 0;
		for(int i = 1; i <= len; i++) y += (s[i] - '0');
		printf("%d\n", max(x, y));
	}
	return 0;
}

Measured memory_bytes: 128
#include<iostream>
#define ll long long
using namespace std;

ll min_moves(ll n) 
{ 
   
    ll ans = 1e12;
  
    for (ll i = 1; i * i <= n; i++) { 
  
        if (n % i == 0) { 
  
            ans = min(ans, i + n / i - 2); 
        } 
    } 
  
    return ans; 
} 
int main() {

ll n = 0;

cin >> n;

cout << min_moves(n);

    return 0;
}

Measured memory_bytes: 632
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

#define REP(i, m, n) for(int i=int(m);i<int(n);i++)
#define EACH(i, c) for (auto &(i): c)
#define all(c) begin(c),end(c)
#define EXIST(s, e) ((s).find(e)!=(s).end())
#define SORT(c) sort(begin(c),end(c))
#define pb emplace_back
#define MP make_pair
#define SZ(a) int((a).size())

//#define LOCAL 1
#ifdef LOCAL
#define DEBUG(s) cout << (s) << endl
#define dump(x)  cerr << #x << " = " << (x) << endl
#define BR cout << endl;
#else
#define DEBUG(s) do{}while(0)
#define dump(x) do{}while(0)
#define BR
#endif


//改造
typedef long long int ll;
using namespace std;


//ここから編集する


int main() {
    int N;
    cin >> N;
    vector<int> c(9, 0);
    REP(i, 0, N) {
        int tmp;
        cin >> tmp;
        if (tmp > 3200) tmp = 3200;
        c[tmp / 400]++;
    }
    int res = 0;
    REP(i, 0, 8) {
        if (c[i] > 0) res++;
    }

    if (res == 0) {
        cout << 1 << " " << c[8];
    } else {
        cout << res << " " << res + c[8];
    }

    cout << endl;

    return 0;

}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int p;
int gcd(int a,int b){
  if(b==0)return a;
  p++;
  return gcd(b,a%b);
}
int main(){
  int a,b;
  while(cin>>a>>b,a){
    p=0;
    if(a<b)swap(a,b);
    cout<<gcd(a,b)<<' ';
    cout<<p<<endl;
  }
}


Measured memory_bytes: 3020
// atcoder/panasonic2020/C/main.cpp
// author: @___Johniel
// github: https://github.com/johniel/

#include <bits/stdc++.h>

#define each(i, c) for (auto& i : c)
#define unless(cond) if (!(cond))

using namespace std;

template<typename P, typename Q> ostream& operator << (ostream& os, pair<P, Q> p) { os << "(" << p.first << "," << p.second << ")"; return os; }
template<typename P, typename Q> istream& operator >> (istream& is, pair<P, Q>& p) { is >> p.first >> p.second; return is; }
template<typename T> ostream& operator << (ostream& os, vector<T> v) { os << "("; for (auto& i: v) os << i << ","; os << ")"; return os; }
template<typename T> istream& operator >> (istream& is, vector<T>& v) { for (auto& i: v) is >> i; return is; }
template<typename T> ostream& operator << (ostream& os, set<T> s) { os << "#{"; for (auto& i: s) os << i << ","; os << "}"; return os; }
template<typename K, typename V> ostream& operator << (ostream& os, map<K, V> m) { os << "{"; for (auto& i: m) os << i << ","; os << "}"; return os; }

template<typename T> inline T setmax(T& a, T b) { return a = std::max(a, b); }
template<typename T> inline T setmin(T& a, T b) { return a = std::min(a, b); }

using lli = long long int;
using ull = unsigned long long;
using point = complex<double>;
using str = string;
template<typename T> using vec = vector<T>;

int di[] = {0, 1, -1, 0, 1, -1, 1, -1};
int dj[] = {1, 0, 0, -1, 1, -1, -1, 1};
constexpr lli mod = 1e9 + 7;

int main(int argc, char *argv[])
{
  ios_base::sync_with_stdio(0);
  cin.tie(0);

  long double a, b, c;
  while (cin >> a >> b >> c) {
    auto d = (c - a - b);
    bool f = d * d > 4.0 * a * b;
    f = f && (0 < d);
    cout << (f ? "Yes" : "No") << endl;
  }

  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdint.h>
#include <math.h>

int main()
{
	int n;
	scanf("%d", &n);
	int32_t a[n], ans[n], cnt = 0;
	for(int i = 0 ; i < n ; i++)
	{
		ans[i] = 0;
		scanf("%d", &a[i]);
	}
	for(int i = n - 1 ; i >= 0 ; i--)
	{
		if(a[i] == 1)
		{
			ans[cnt++] = i + 1;
			for(int j = 1 ; j <= sqrt(i + 1) ; j++)
			{
				if(!((i + 1) % j))
				{
					if(((i + 1) / j) == j)
						a[j - 1] ^= 1;
					else
					{
						a[(i + 1) / j - 1] ^= 1;
						a[j - 1] ^= 1;
					}
				}
			}
		}
	}
	printf("%d\n", cnt);
	if(cnt != 0)
	{
		for(int i = cnt - 1 ; i >= 0 ; i--)
			printf("%d ", ans[i]);
		printf("\n");
	}
}

Measured memory_bytes: 2432
n = int(input())
a = list(map(int, input().split()))

is_even = True
loop_count = 0
while (is_even):
    for r in a:
        if a[0] % 2 == 0:
            a.append((a[0] // 2))
            a.pop(0)
        else:
            is_even = False
            break
    else:
        loop_count += 1
print(loop_count)

Measured memory_bytes: 3060
use std::io::{self, Stdin};
use std::str::{self, FromStr};
use std::error::Error;
use std::thread;
fn exec() {
    let mut sc = Scanner::new();
    let n: usize = sc.ne();
    let mut a = vec![0i64; n];
    let mut b = vec![0i64; n];
    for i in 0..n {
        a[i] = sc.ne();
        b[i] = sc.ne();
    }
    let mut cur = 0i64;
    for i in (0..n).rev() {
        let x = a[i] + cur;
        cur += (b[i] - (x % b[i])) % b[i];
    }
    println!("{}", cur);
}
const DEFAULT_STACK: usize = 16 * 1024 * 1024;
fn main() {
    let builder = thread::Builder::new();
    let th = builder.stack_size(DEFAULT_STACK);
    let handle = th.spawn(|| { exec(); }).unwrap();
    let _ = handle.join();
}

#[allow(dead_code)]
struct Scanner {
    stdin: Stdin,
    id: usize,
    buf: Vec<u8>,
}

#[allow(dead_code)]
impl Scanner {
    fn new() -> Scanner {
        Scanner {
            stdin: io::stdin(),
            id: 0,
            buf: Vec::new(),
        }
    }
    fn next_line(&mut self) -> Option<String> {
        let mut res = String::new();
        match self.stdin.read_line(&mut res) {
            Ok(0) => return None,
            Ok(_) => Some(res),
            Err(why) => panic!("error in read_line: {}", why.description()),
        }
    }
    fn next<T: FromStr>(&mut self) -> Option<T> {
        while self.buf.len() == 0 {
            self.buf = match self.next_line() {
                Some(r) => {
                    self.id = 0;
                    r.trim().as_bytes().to_owned()
                }
                None => return None,
            };
        }
        let l = self.id;
        assert!(self.buf[l] != b' ');
        let n = self.buf.len();
        let mut r = l;
        while r < n && self.buf[r] != b' ' {
            r += 1;
        }
        let res = match str::from_utf8(&self.buf[l..r]).ok().unwrap().parse::<T>() {
            Ok(s) => Some(s),
            Err(_) => panic!("parse error"),
        };
        while r < n && self.buf[r] == b' ' {
            r += 1;
        }
        if r == n {
            self.buf.clear();
        } else {
            self.id = r;
        }
        res
    }
    fn ne<T: FromStr>(&mut self) -> T {
        self.next::<T>().unwrap()
    }
}


Measured memory_bytes: 2044
//inputに入力データ全体が入る
function Main(input) {
    var tmp=inputting(input)
    var n=parseInt(tmp[0][0])
    var m=parseInt(tmp[0][1])
    var answer=new Array(n)
    for(var t=1;t<=n;t++){
        answer[(""+t)]=0
    }
    var kekka={ac:0,wa:0}
    for(var i=1;i<tmp.length;i++){
        //console.log(tmp[i])
        if(answer[(""+tmp[i][0])]>=0){//未AC
            //console.log(answer[(""+tmp[i][0])])
            if(tmp[i][1]=="AC"){
                kekka.ac++//AC数+1
                kekka.wa+=answer[(""+tmp[i][0])]//WA数加算
                answer[(""+tmp[i][0])]=-1//以降WAの対象外
            }
            else{
                if(tmp[i][1]=="WA"){
                    answer[(""+tmp[i][0])]++//この問題のWA数を+1
                }
            }
        }

    }


    console.log(kekka.ac+" "+kekka.wa)//標準出力
}
function inputting(input){
    //標準入力で受け取ったデータを、改行区切りでi行目、空白区切りでj番目のデータが[i][j]に格納される配列に変換する
    input = input.split("\n");
    var tmp=[]
    for(var i=0;i<input.length;i++){
        tmp[i]=input[i].split(" ")
    }
    return tmp
}
function parseint_array(arr){
    var ret=[]
    for(var i=0;i<arr.length;i++){
        ret[i]=[]
        for(var j=0;j<arr[i].length;j++){
            ret[i][j]=parseInt(arr[i][j])
        }
    }
    return ret
}
//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));
//Main("2 5\n1 WA\n1 AC\n2 WA\n2 AC\n2 WA")//標準入力サンプル

Measured memory_bytes: 54928
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
			int N =sc.nextInt();
			int M =0;
			int L =0;
			
				for(int i=0; i<=N/4; i++){
					M=N-4*i;
				
					if(M%7==0){
						L++;
					}
				}
					if(L>=1){		
						System.out.println("Yes");
					} else {
						System.out.println("No");
					}
	}
}

Measured memory_bytes: 21972
#include <bits/stdc++.h>
using namespace std;
#define ll long long
const int maxx = 100005;
priority_queue<ll> q;
struct node{
    ll x,y;
};
node a[maxx];
bool cmp(node p1,node p2)
{
    if(p1.x != p2.x)
        return p1.x < p2.x;
    return p1.y > p2.y;
}
int main()
{
    ll n,m;
    cin>>n>>m;
    for(int i=1;i<=n;i++){
        cin>>a[i].x>>a[i].y;
    }
    sort(a+1,a+1+n,cmp);
    ll ans = 0;
    int k = 1;
    for(int i=1;i<=m;i++)
    {
        while(k<=n && a[k].x <= i){
            q.push(a[k].y),k++;
        }
        if(!q.empty()){
            ll now = q.top();
            q.pop();
            ans += now;
        }
    }
    cout<<ans<<endl;
    return 0;
}



Measured memory_bytes: 2936
#include<stdio.h>

int main(){
	double a,b,c,d,e,f;
	double ans,ans2;

	while(scanf("%lf%lf%lf%lf%lf%lf",&a,&b,&c,&d,&e,&f)!=EOF){

		    ans=(e*c-b*f)/(a*e-b*d);
			ans2=(c*d-a*f)/(b*d-a*e);
	
					if((e*c-b*f)==0){ ans=0.000 ; }
			else if((c*d-a*f)==0){ ans2=0.000 ;}

		printf("%.3f %.3f\n",ans,ans2);
	}
	return 0;
}

Measured memory_bytes: 0
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Created by shoya on 2017/04/15.
 */
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        PrintWriter pw = new PrintWriter(System.out);
        int n = sc.nextInt();
        int ans = 0;
        int prev = -1;
        int upFlag = -1;
        for (int i = 0; i < n; i++){
            int curr = sc.nextInt();
            //System.out.printf("Prev %d Curr %d Up %d Ans %d\n", prev, curr, upFlag, ans);
            if (prev == -1) {
                prev = curr;
                continue;
            }
            if (upFlag == -1){
                if (curr > prev)
                    upFlag = 1;
                else if (curr < prev)
                    upFlag = 0;
                prev = curr;
                continue;
            }
            if ((upFlag == 1 && prev > curr) || (upFlag == 0 && prev < curr)){
                ans++;
                prev = curr;
                upFlag = -1;
                continue;
            }
            prev = curr;
        }

        //System.out.printf("Up %d Ans %d\n", upFlag, ans);
        pw.println(ans + 1);
        pw.flush();
        return;
    }
}

Measured memory_bytes: 48736
def binary_search(list,target):

	result = -1
	left = 0
	right = len(list) - 1

	while left <= right:
		center = int((left + right)/2)
		if list[center] == target:
			result = center
			break
		elif list[center] < target:
			left = center + 1
		elif list[center] > target:
			right = center - 1

	if result == -1:
		return result
	else:
		return result


if __name__=="__main__":
    n=int(input())
    s=list(input())
    rlist=[]
    glist=[]
    blist=[]
    ans=0
    if len(s)<=3:
        print(0)
        exit()
    for i in range(n):
        if s[i]=="R":
            rlist.append(i)
        elif s[i]=="G":
            glist.append(i)
        else:
            blist.append(i)
    if len(rlist)==0 or len(glist)==0 or len(blist)==0:
        print(0)
        exit()
    ans+=len(rlist)*len(glist)*len(blist)
    for i in range(n-2):
        for j in range(i+1,n-1):
            k=2*j-i
            if s[i]==s[j]:
                continue
            elif k>len(s)-1:
                continue
            else:
                if s[k]!=s[i] and s[k]!=s[j]:
                    ans-=1

    print(ans)

Measured memory_bytes: 73816
def main():
    k = [[[0 for x in range(10)] for x in range(3)] for x in range(4)]
    n = int(input())
    for i in range(n):
        b, f, r, v = map(int, raw_input().split())
        k[b-1][f-1][r-1] += v

    for b in range(4):
        for f in range(3):
            print(" " + " ".join(map(str, k[b][f])))
        if b != 3:
            print("#"*20)

main()

Measured memory_bytes: 4248
//Don't have to see. start------------------------------------------
var read = require('readline').createInterface({
  input: process.stdin,
  output: process.stdout
});
var obj; var inLine = [];
read.on('line', function(input){inLine.push(input);});
read.on('close', function(){
  obj = init(inLine);
  console.error("\n");
  var start = Date.now();
  Main();
  var end = Date.now() - start;
  myerr("time : " + end + "ms");
  myerr("memory : " + Math.round(process.memoryUsage().heapTotal / 1024) + "KB");
});
function makeClone(obj){return JSON.parse(JSON.stringify(obj));}
function nextInt(){return myconv(next(),1);} function nextStrArray(){return myconv(next(),2);}
function nextIntArray(){return myconv(next(),4);} function nextCharArray(){return myconv(next(),6);}
function next(){return obj.next();} function hasNext(){return obj.hasNext();}
function init(input){  
  var returnObj = {
    list : input, index : 0, max : input.length,
    hasNext : function(){return (this.index < this.max);},
    next : function(){if(!this.hasNext()){throw "ArrayIndexOutOfBoundsException ‚There is no more input";}else{var returnInput = this.list[this.index++];return returnInput;}}
  };
  return returnObj;
}
function myout(s){console.log(s);}
function myerr(s){console.error("debug:" + require("util").inspect(s,false,null));}
//param "no" is
//unknown or outlier : return i. 1: parseInt.
//2: split space. 4: split space and parseInt.
//6: split 1 character. 7: split 1 character and parseInt.
//8: join space. 9: join nextline. 0: join no character.
function myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(" ");case 4:return i.split(" ").map(Number);case 6:return i.split("");case 7:return i.split("").map(Number);case 8:return i.join(" ");case 9:return i.join("\n");case 0:return i.join("");default:return i;}}catch(e){return i;}}

//Don't have to see. end------------------------------------------
function Main(){
  var one = nextIntArray();
  var N = one[0];
  var Q = one[1];
  var list = new Array(N);
  for(var i = 0; i < N; i++){
    list[i] = {
      child : [],
      access : false,
      add : 0,
      count : 0
    };
  }
  for(var i = 0; i < N - 1; i++){
    var tmp = nextIntArray();
    list[tmp[0] - 1].child.push(tmp[1] - 1);
    list[tmp[1] - 1].child.push(tmp[0] - 1);
  }
  for(var i = 0; i < Q; i++){
    var tmp = nextIntArray();
    list[tmp[0] - 1].add += tmp[1];
  }
  var maeIndex = 0;
  var atoIndex = 1;
  var queue = new Array(N + 100);
  queue[maeIndex] = 0;
  list[0].access = true;
  while(maeIndex != atoIndex){
    var now = queue[maeIndex];
    maeIndex++;
    list[now].count += list[now].add;
    var child = list[now].child;
    for(var i = 0; i < child.length; i++){
      if(!list[child[i]].access){
        list[child[i]].access = true;
        list[child[i]].add += list[now].add;
        queue[atoIndex] = child[i];
        atoIndex++;
      }
    }
  }
  var output = new Array(N);
  for(var i = 0; i < N; i++){
    output[i] = list[i].count;
  }
  myout(myconv(output, 8));
}


Measured memory_bytes: 184328
package main

import (
	"fmt"
	"math"
)

func abs(a int) int {
	return int(math.Abs(float64(a)))
}

func main() {

	var n int
	sum := 0

	fmt.Scan(&n)

	t := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Scan(&t[i])
		sum += t[i]
	}

	a := 0
	b := sum
	c := sum
	ans := sum
	for _, x := range t {
		a += x
		b -= x
		c = abs(a - b)
		if c < ans {
			ans = c
		}
	}
	fmt.Println(ans)
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
void Main();

using i8  = int8_t;   /* -128 ~ 127 */
using u8  = uint8_t;  /* 0 ~ 255 */
using i16 = int16_t;  /* -32,768 ~ 32,767 */
using u16 = uint16_t; /* 0 ~ 65,535 */
using i32 = int32_t;  /* -2,147,483,648 ~ 2,147,483,647 */
using u32 = uint32_t; /* 0 ~ 4,294,967,295 */
using i64 = int64_t;  /* -9,223,372,036,854,775,808 ~ 9,223,372,036,854,775,807 */
using u64 = uint64_t; /* 0 ~ 18,446,744,073,709,551,615 */
using f32 = float;    /* (-3.4 * 10^38) ~ (3.4 * 10^38) */
using f64 = double;   /* (-1.7 * 10^308) ~ (1.7 * 10^308) */
using f80 = __float80;
template <class T> using Vec = vector<T>;
constexpr i64 INF = 1010000000000000017;
constexpr i64 MOD = 1e9 + 7;
constexpr f64 EPS = 1e-12;
constexpr f64 PI = 3.14159265358979323846;
#define ALL(v) v.begin(), v.end()
#define YN(a, b, c) ((c)? a : b)
#define GCD(a, b) __gcd(a, b) /* 最大公約数 */
#define LCM(a, b) (i64)(a / (f64)__gcd(a, b) * b) /* 最小公倍数 */

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

void Main() {
    string S;
    cin >> S;
    map<char, i32> m;
    string al = "abcdefghijklmnopqrstuvwxyz";
    for (i32 i = 0; i < S.size(); i++) {
        m[S[i]] = i + 1;
    }
    if (S.size() < 26) {
        for (i32 i = 0; i < al.size(); i++) {
            if (m.find(al[i]) != m.end()) continue;
            cout << S << al[i] << endl;
            return;
        }
    }
    if (S == "zyxwvutsrqponmlkjihgfedcba") {
        cout << -1 << endl;
        return;
    }
    string ans;
    i32 index;
    for (index = S.size() - 2; index >= 0; index--) {
        if (S[index + 1] > S[index]) break;
    }
    char min_c = 'z';
    for (i32 i = index + 1; i < S.size(); i++) {
        if (S[index] < S[i] && min_c > S[i]) min_c = S[i];
    }
    for (i32 i = 0; i < index; i++) {
        ans += S[i];
    }
    ans += min_c;
    cout << ans << endl;
}


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

typedef int64_t Int;
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
 
const double EPS = 1e-10;
const Int INF = 1e18;
const int inf = 1e9;
const Int mod = 1e9+7;

bool print_space_enable = false;
void print() { 
    cout << endl; 
    print_space_enable = false;
}

template <class Head, class... Tail>
void print(Head&& head, Tail&&... tail) {
    if (print_space_enable) cout << " ";
    cout << fixed << setprecision(15) << head;
    print_space_enable = true;
    print(std::forward<Tail>(tail)...);
}

template<typename T>
void print(vector<T> v) {
    for (size_t i = 0; i < v.size(); i++) {
        if (i > 0) std::cout << " ";
        std::cout << v[i];
    }
    std::cout << std::endl;
}

int main() {
    Int a, b, n;
    cin >> a >> b >> n;
    Int cur = min(b - 1, n);
    print((Int)((double)a / (double)b * cur));
    return 0;
}

Measured memory_bytes: 3592
#include <iostream>
#include <complex>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <numeric>
#include <cstring>
#include <ctime>
#include <cstdlib>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <cmath>
#include <bitset>
#include <cassert>
#include <queue>
#include <stack>
#include <deque>
#include <random>
#include <iomanip>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
typedef long long int ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<P,P> PP;
const ll MOD=998244353;
const ll MAX_N=500010;
const ll INF=100100100100100;


int main(){
    int n,m;
    cin>>n>>m;
    vector<int> k(m);
    vector<vector<int> > s(m);
    for(int i=0;i<m;i++){
        cin>>k[i];
        for(int j=0;j<k[i];j++){
            int A;
            cin>>A;
            s[i].push_back(A-1);
        }
    }
    vector<int> p(m);
    for(int i=0;i<m;i++) cin>>p[i];
    int ans=0;
    for(int bit=0;bit<(1<<n);bit++){
        bool f=true;
        for(int i=0;i<m;i++){
            int num=0;
            for(int j=0;j<k[i];j++){
                int point=s[i][j];
                if(1 & (bit>>point) ) num++;
            }
            num%=2;
            if(num!=p[i]){
                f=false;
                break;
            }
        }
        if(f) ans++;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 3196
#include<bits/stdc++.h>
using namespace std;
const int MAXN = 205;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
template <typename T> void chkmax(T &x, T y) {x = max(x, y); }
template <typename T> void chkmin(T &x, T y) {x = min(x, y); } 
template <typename T> void read(T &x) {
	x = 0; int f = 1;
	char c = getchar();
	for (; !isdigit(c); c = getchar()) if (c == '-') f = -f;
	for (; isdigit(c); c = getchar()) x = x * 10 + c - '0';
	x *= f;
}
template <typename T> void write(T x) {
	if (x < 0) x = -x, putchar('-');
	if (x > 9) write(x / 10);
	putchar(x % 10 + '0');
}
template <typename T> void writeln(T x) {
	write(x);
	puts("");
}
int ans, d[MAXN]; ll Min;
int n, x[MAXN], y[MAXN];
vector <int> a[MAXN];
void work(int pos, int fa, int depth) {
	if (fa == 0) chkmax(d[depth], (int) a[pos].size());
	else chkmax(d[depth], (int) a[pos].size() - 1);
	for (auto x : a[pos])
		if (x != fa) work(x, pos, depth + 1);
}
int main() {
	read(n), ans = n + 1;
	for (int i = 1; i <= n - 1; i++) {
		read(x[i]), read(y[i]);
		a[x[i]].push_back(y[i]);
		a[y[i]].push_back(x[i]);
	}
	for (int i = 1; i <= n; i++) {
		memset(d, 0, sizeof(d));
		work(i, 0, 1);
		int now = 1; ll cnt = 1;
		for (int i = 1; i <= n; i++)
			if (d[i]) {
				now++;
				cnt *= d[i];
			} else break;
		if (now < ans) ans = now, Min = cnt;
		else if (now == ans) chkmin(Min, cnt);
	}
	for (int i = 1; i <= n - 1; i++) {
		memset(d, 0, sizeof(d));
		work(x[i], y[i], 1);
		work(y[i], x[i], 1);
		int now = 1; ll cnt = 1;
		for (int i = 1; i <= n; i++)
			if (d[i]) {
				now++;
				cnt *= d[i];
			} else break;
		if (now < ans) ans = now, Min = 2 * cnt;
		else if (now == ans) chkmin(Min, 2 * cnt);
	}
	printf("%d %lld\n", ans, Min);
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define lli long long int
#define rep(x,y) for(lli i=x;i<y;i++)
#define pb push_back
#define mp make_pair
#define bg() begin()
#define en() end()
#define ft first
#define sc second
#define vect_lli_it vector<lli>::iterator
#define set_lli_it set<lli>::iterator
#define inf 1e18
int main(){
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    lli n,m;
    cin>>n>>m;
    lli arr[n];
    rep(0,n)
    cin>>arr[i];
    lli sum=0;
    rep(0,n){
    	sum+=arr[i];
	}
	//cout<<sum<<"\n";
	lli thres=sum/(4*m)+((sum%(4*m)==0)?0:1);
	lli count=0;
	rep(0,n){
		if(arr[i]>=thres)
		count++;
	}
	if(count>=m)
	cout<<"Yes";
	else
	cout<<"No";
	return 0;
}


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

typedef long long int lli;

long long int max(long long int a,long long int b){
  if(a>b)
    return a;
  else
    return b;
}
typedef pair<int,int> pii;
typedef vector<int> vi;
bool check(int len,vector<char>& str){
  bool flag = true;
  if((len+1)%2!=0){
    return false;
  }
  int mid = len/2;
  for(int i = 0;i<=mid;i++){
    if(str[i]!=str[mid+i+1])
      flag = false;
  }

  return flag;
}
void solve(){
  string s;
  cin>>s;
  int n = s.length();
  vector<char> str;
  for(int i = 0;i<n;i++){
    str.push_back(s.at(i));
  }
  for(int i = n-2;i>=0;i--){
    if(check(i,str)==true){
      cout<<i+1;
      return;
    }
  }

  cout<<0;
  return;

  
}

int main(){
  solve(); 
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define Mx 3e3+5
#define mod 1000000007
using namespace std;
char s[1005][1005];
ll dp[1005][1005];
int h,w;
ll ways(int i,int j)
{
    if(i==h-1&&j==w-1)
        return 1;
    if(dp[i][j]!=-1) return dp[i][j];
    ll ret = 0;
    if((s[i+1][j]=='.')&&i+1<h)
        ret = ways(i+1,j);
    if((s[i][j+1]=='.')&&j+1<w)
        ret = ((ret%mod)+(ways(i,j+1)%mod))%mod;
    return dp[i][j] = ret;
}
int main()
{
    cin>>h>>w;
    memset(dp,-1,sizeof(dp));
    for(int i=0; i<h; i++)
    {
        cin>>s[i];
    }
    cout<<ways(0,0)<<endl;
    return 0;
}



Measured memory_bytes: 9216
w,h,n = map(int,input().split())
dots = [list(map(int,input().split())) for i in range(n)]
xl = [dots[i] for i in range(n) if dots[i][2] == 1]
xr = [dots[i] for i in range(n) if dots[i][2] == 2]
yd = [dots[i] for i in range(n) if dots[i][2] == 3]
yu = [dots[i] for i in range(n) if dots[i][2] == 4]

kfunc1 = lambda x : x[0]
kfunc2 = lambda y : y[1]

xxl = max(xl,key = kfunc1,default = [0,0,0])
xxr = min(xr,key = kfunc1,default = [w,0,0])
yyd = max(yd,key = kfunc2,default = [0,0,0])
yyu = min(yu,key = kfunc2,default = [0,h,0])

if xxl[0] >= xxr[0] or yyd[1] >= yyu[1]: print(0)
else : print((xxr[0]-xxl[0])*(yyu[1]-yyd[1]))

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

using namespace std;

int main(){
    int n = 10;
    vector<int> a(n);
    for(int i = 0; i < n; i++){
        cin >> a[i];
    }
    int count = 0;
    for(int i = 0; i < n; i++){
        count += a[i];
    }
    cout << count << endl;
    return 0;
}


Measured memory_bytes: 3088
#include <stdio.h>

int min(int x, int y)
{
	return (x <= y ? x : y);
}

int max(int x, int y)
{
	return (x >= y ? x : y);
}

int main(void)
{
	int a, b, c, d, p;
	int x, y;
	
	scanf("%d %d %d %d %d", &a, &b, &c, &d, &p);
	
	x = p * a;
	y = b + max(0, p - c) * d;
	
	printf("%d\n", min(x, y));
	
	return (0);
}

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

int main(){
	int N;
	cin>>N;
	
	int d=0;
	int p[1000][3];
	for(int i=0;i<N;i++){
		for(int j=0;j<3;j++){
			cin>>p[i][j];
		}
		for(int a=0;a<i;a++){
			if((p[i][0]==p[a][0]||p[i][0]==p[a][1]||p[i][0]==p[a][2])&&
			   (p[i][1]==p[a][0]||p[i][1]==p[a][1]||p[i][1]==p[a][2])&&
			   (p[i][2]==p[a][0]||p[i][2]==p[a][1]||p[i][2]==p[a][2])){
			   d++;
			   p[i][0]=0; p[i][1]=0; p[i][2]=0;//?????????????????????
			   break;
			}
		}
	}
	
	
	
	cout<<d<<endl;
	
	return 0;
}

Measured memory_bytes: 3124
#include <iostream>
#include <cstdio>
using namespace std;
 
int p[110], q[110], cnt;
long long N;
     
void solve(long long n){
	if(n<1)	return;
   	if(!(n&1)){
   		q[++q[0]]=cnt++;
   		solve(n-1);
   	}else{
   		p[++p[0]]=cnt++;
   		solve(n>>1);
 	}
}
    
int main(){
  	scanf("%lld", &N);
  	solve(N);
  	printf("%d\n", cnt*2);
  	for(int i=1; i<=q[0]; i++)	printf("%d ", cnt-q[i]);
  	for(int i=p[0]; i; i--)		printf("%d ", cnt-p[i]);
   	for(int i=1; i<=cnt; i++)	printf("%d ", i);
 	return 0;
}

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

#define MAX 2000001
#define VMAX 10000

void CountingSort(int *,int *,int);

int C[VMAX+1],n;

int main(){
  int *A,*B;
  int i,m = 0;
  
  scanf("%d", &n);
  if(n < 1 || n > 2000000)return 0;

  A = malloc(sizeof(int)*n+1);
  B = malloc(sizeof(int)*n+1);
 
  for(i = 1;i < n+1; i++){
    scanf("%d",&A[i]);
    if(m < A[i])m = A[i];
  }
 CountingSort(A,B,m);

 for(i = 1;i < n+1; i++){
    if(i > 1)printf(" ");
    printf("%d",B[i]);
  }
  printf("\n");
  return 0;
}

void CountingSort(int *A,int *B,int k){
  int i,j;
  for(i = 0;i <= k; i++){
    C[i] = 0;
  }
  for(j = 1;j < n+1; j++){
    C[A[j]]++;
  }
  for(i = 1;i <= k; i++){
    C[i] += C[i-1];
  }
  for(j = n; j > 0;j--){
    B[C[A[j]]] = A[j];
    C[A[j]]--;
  }
  
}



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

int main() {

  string S;
  cin >> S;

  int N = S.size();

  vector<int> num(26,0);
  for(int i = 0;i < S.size();i++) {
    int n = S.at(i) - 'a';
    num.at(n)++;
  }

  int mnum = 25;
  bool all = true;
  for(int i = 25;i >= 0;i--) {
    if(num.at(i) == 0) {
      mnum = i;
      all = false;
    }
  }

  if(all) {
    int i = S.size()-1;
    while(i > 0 && S.at(i-1) > S.at(i)) {
      i--;
    }
    if(i == 0) {
      cout << -1 << endl;
      return 0;
    }else {
      char ch = S.at(i-1),mini = S.at(i);
      for(int j = i+1;j < S.size();j++) {
        if(ch < S.at(j) && mini > S.at(j)) mini = S.at(j);
      }
      cout << S.substr(0,i-1) + mini << endl;
    }

  }else {
    cout << S + (char)(mnum+'a') << endl;
  }

  
}


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

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

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

  vector<int> dist;
  for(int i = 0; i < m-1; ++i){
    dist.push_back(x[i+1] - x[i]);
  }

  sort(dist.begin(), dist.end());
  
  ll ans = 0;
  for(int i = 0; i < m - n; ++i){
    ans += dist[i];
  }

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


Measured memory_bytes: 1276
N, M = map(int, input().split())
ac = [False] * N
wa_cnt = [0] * N
ac_cnt = 0
for i in range(M):
    p, s = input().split()
    p_i = int(p) - 1
    if s == 'WA':
        if not ac[p_i]:
            wa_cnt[p_i] += 1
    else:
        if not ac[p_i]:
            ac[p_i] = True
            ac_cnt += 1

wa_cnt_sum = 0
for i in range(N):
    if ac[i]:
        wa_cnt_sum += wa_cnt[i]

print(ac_cnt,wa_cnt_sum)


Measured memory_bytes: 10380
#include <bits/stdc++.h>
#define vsort(v) sort(v.begin(), v.end())
#define rvsort(v) sort(v.begin(), v.end(), greater<ll>())
#define ll long long
#define rep(i, s, g) for (ll i = (s); i < (g); i++)
#define MOD 1000000007
#define vfind(v, target) find(v.begin(), v.end(), target)
#define notFound(v, target) (vfind(v, target) == v.end())

using namespace std;

int main()
{
  ll n; cin >> n;
  vector<pair<ll, ll>> res;
  for (ll i = 2; i * i <= n; i++) {
    if (n % i) continue;
    res.emplace_back(i, 0);
    while (n % i == 0) {
      n /= i;
      res.back().second++;
    }
  }
  if (n != 1) res.emplace_back(n, 1);
  ll ans = 0;
  vector<ll> tmp(res.size(), 1);
  for (ll i = 0; i < res.size(); i++) {
  	while (res[i].second >= tmp[i]) {
    	ans++;
      	res[i].second -= tmp[i];
    	tmp[i]++;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
int main(){
int n,k,c=0;
cin>>n>>k;
vector<int> a(n);
for(int i=0;i<n;i++)cin>>a[i];
sort(a.begin(),a.end());
reverse(a.begin(),a.end());
for(int i=0;i<k;i++) c+=a[i];
cout<<c;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
#include <bitset>
#define M 1000000007
#define M1 998244353

#define tr(container, it) \
for(typeof(container.begin()) it = container.begin(); it != container.end(); it++)

#define fast                        \
  ios_base::sync_with_stdio(false); \
  cin.tie(NULL);

#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()

ll power(ll x, ll n)
{
    ll result = 1;
    while (n)
    {
        if (n % 2 == 1)
            result = result * x;
        n = n / 2;
        x = x * x;
    }
    return result;
}

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

ll lcm(ll a, ll b) {
    return (a * b) / gcd(a, b);
}

inline ll mul(ll x, ll y, ll m)
{
    ll z = 1LL * x * y;
    if (z >= m)
    {
        z %= m;
    }
    return z;
}

ll powmod(ll x, ll y, ll m)
{
    ll r = 1;
    while (y)
    {
        if (y & 1)
        {
            r = mul(r, x, m);
        }
        y >>= 1;
        x = mul(x, x, m);
    }
    return r;
}



void start()
{
    fast;
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
}
/***********************************************************************************************************/

int main()
{
    start();
    int c, d, m;
    cin>>c>>d>>m;
    int a[c], b[d];
    for (int i=0;i<c;i++)
    {
        cin>>a[i];
    }
    for (int i=0;i<d;i++)
    {
        cin>>b[i];
    }
    int ans=INT_MAX;
    for (int i=0;i<m;i++)
    {
        int x, y, z;
        cin>>x>>y>>z;
        ans=min(ans, a[x-1]+b[y-1]-z);
    }
    int x, y;
    x=*min_element(a, a+c);
    y=*min_element(b, b+d);
    cout<<min(ans, x+y);
    return 0;
}

Measured memory_bytes: 4400
#include <iostream>
#include <algorithm>
#include <map>
using namespace std;
int main() {
	int h, w; cin >> h >> w;
	char s[52][52];
	for(int i=1;i<h+1;i++){
		for(int j=1;j<w+1;j++){
			cin >> s[i][j];
		}
	}
	for(int i=0;i<h+2;i++){
		for(int j=0;j<w+2;j++){
			s[0][j] = 'a';
			s[i][0] = 'a';
			s[i][w+1] = 'a';
			s[h+1][j] = 'a';
		}
	}
	int c[52][52];
	for(int i=1;i<h+1;i++){
		for(int j=1;j<w+1;j++){
			c[i][j] = 0;
		}
	}
	for(int i=1;i<h+1;i++){
		for(int j=1;j<w+1;j++){
			if(s[i-1][j-1]=='#'){
				c[i][j]++;
			}
			if(s[i-1][j]=='#'){
				c[i][j]++;
			}
			if(s[i-1][j+1]=='#'){
				c[i][j]++;
			}
			if(s[i][j-1]=='#'){
				c[i][j]++;
			}
			if(s[i][j+1]=='#'){
				c[i][j]++;
			}
			if(s[i+1][j-1]=='#'){
				c[i][j]++;
			}
			if(s[i+1][j]=='#'){
				c[i][j]++;
			}
			if(s[i+1][j+1]=='#'){
				c[i][j]++;
			}
			if(s[i][j]=='#'){
				cout << '#';
			}
			if(s[i][j]!='#'){
				cout << c[i][j];
			}
		}
		cout << endl;
	}
	return 0;
}

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

typedef long long int ll;
#define rep(i,n) for (int i = 0; i < (n); i++)
#define all(v) (v).begin(), (v).end()
#define sz(x) int(x.size())
const ll mod = 1000000007;
const ll INF = 1001001001001001;

int main() {
    ll n; cin >> n;
    ll k; cin >> k;
    ll a[n];
    rep(i,n) {
        cin >> a[i];
        a[i] %= k;
    }
    ll b[n+1]; b[0] = 0;
    rep(i,n) {
        b[i+1] = (b[i]+a[i])%k;
    }
    ll c[n+1];
    ll x = k;
    while (x < 1000000) {
        x *= 2;
    }
    rep(i,n+1) {
        c[i] = (b[i]+x-i)%k;
    }
    //rep(i,n+1) {printf("%lld\n", c[i]);}
    map<ll, ll> mp;
    rep(i,min(k,n+1)) {
        mp[c[i]]++;
    }
    ll ans = 0;
    int idxr = (int)min(k,n+1);
    for (int i = 0; i+idxr < n+1; i++) {
        //printf("%d\n",i);
        ans += (ll)(mp[c[i]]-1);
        mp[c[i]]--;
        mp[c[i+idxr]]++;
        //for(auto itr = mp.begin(); itr != mp.end(); itr++) {printf("(%lld, %lld) %lld ", itr->first, itr->second, ans);}
        //printf("syakutori\n");
    }
    //cout << ans << endl;
    for (int i = n+1-idxr; i < n+1; i++) {
        //printf("%d\n",i);
        ans +=(ll)(mp[c[i]]-1);
        mp[c[i]]--;
        //for(auto itr = mp.begin(); itr != mp.end(); itr++) {printf("(%lld, %lld) %lld ", itr->first, itr->second, ans);}
        //printf("syakutori\n");
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 20804
import java.util.Collections;
import java.util.PriorityQueue;
import java.util.Queue;
import java.util.Scanner;

class Job implements Comparable<Job> {
	int a;
	int b;

	Job(int a, int b) {
		this.a = a;
		this.b = b;
	}

	@Override
	public int compareTo(Job otherJob) {
		if (otherJob.a == this.a) return this.b - otherJob.b;
		else return this.a - otherJob.a;
	}
}

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String[] line = sc.nextLine().split(" ");
		int N = Integer.parseInt(line[0]);
		int M = Integer.parseInt(line[1]);

		Queue<Job> q = new PriorityQueue<>();
		for (int i = 0; i < N; i++) {
			line = sc.nextLine().split(" ");
			q.add(new Job(Integer.parseInt(line[0]), Integer.parseInt(line[1])));
		}

		int cnt = 0;
		Queue<Integer> jobQ = new PriorityQueue<>(Collections.reverseOrder());
		for (int i = 1; i <= M; i++) {
			while (!q.isEmpty()) {
				Job job = q.peek();
				if (job.a <= i) {
					jobQ.add(q.poll().b);
				}
				else break;
			}
			if (!jobQ.isEmpty()) cnt += jobQ.poll();
		}
		System.out.println(cnt);
	}
}

Measured memory_bytes: 113100
// a template for main.cpp
#include <bits/stdc++.h>
#define ll long long
using namespace std;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    vector<int> a(n);
    for (int &x : a) cin >> x;
    vector<vector<int>> g(n);
   	for (int i = 1; i < n; i++) {
   		int u, v;
   		cin >> u >> v;
   		u--, v--;
   		g[u].push_back(v);
   		g[v].push_back(u);
   	}
   	vector<int> lis(n);
   	vector<int> tail(n + 1, INT32_MIN);
   	function<void(int, int, int)> dfs = [&](int node, int par, int len)  {
   		int index = -1;
   		int newlen = len;
   		int prev = -1;
   		if (a[node] > tail[len]) {
   			newlen++;
   			index = newlen;
   			prev = tail[newlen];
   			tail[index] = a[node];
   		} else {
   			index = lower_bound(tail.begin() + 1, tail.begin() + len + 1, a[node]) - tail.begin();
   			prev = tail[index];
   			tail[index] = a[node];
   		}
   		lis[node] = newlen;
   		for (int adj : g[node]) {
   			if (adj != par) dfs(adj, node, newlen);
   		}
   		tail[index] = prev;
   	};
   	dfs(0, -1, 0);
   	for (int x : lis) {
   		cout << x << endl;
   	}
}



Measured memory_bytes: 36608