akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;

int main(){
  int n, x;
  cin >> n >> x;
  vector<int>ar(n);
  for (int i = 0; i < n; i++){
    cin >> ar[i];
  }
  int ans = 1;
  int sum = 0;
  for (int i = 0 ; i < n; i++){
    sum += ar[i];
    if (sum <= x){
      ans++;
    } else{
      break;
    }
  }
  cout << ans << '\n';
  return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
// #define int long long

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

#define REP(i, n) for (int i = 0; i < (n); ++i)
#define RREP(i, n) for (int i = (n); i >= 0; --i)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define RFOR(i, a, b) for (int i = (a); i >= (b); --i)
#define ALL(v) (v).begin(), (v).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" \
                      << " " << __FILE__ << endl;

typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<vi> vvi;
typedef pair<int, int> pii;

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

    int N;
    cin >> N;
    string c;
    cin >> c;

    int cntR = 0;
    for (char ch : c) {
        if (ch == 'R') cntR++;
    }

    int cntRinLeft = 0;
    REP(i, cntR) {
        if (c[i] == 'R') cntRinLeft++;
    }

    cout << cntR-cntRinLeft << endl;

    return 0;
}


Measured memory_bytes: 3692
def water(h):
    global ans
    if len(h)==1:
        ans+=h[0]
    else:
        m=min(h)
        ans+=m
        for i in range(len(h)):
            h[i]-=m
        a=h.index(0)
        if a==0:
            water(h[1:])
        elif a==len(h)-1:
            water(h[:-1])
        else:
            water(h[:a])
            water(h[a+1:])

n=int(input())
h=list(map(int,input().split()))
ans=0
water(h)
print(ans)

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

using namespace std;

typedef long long int ll;

void fastio()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
}

int hcf(int a, int b) {
    if(b==0) return a;
    return hcf(b, a%b);
}

int main()
{
    fastio();

    int x;
    cin >> x;

    cout << 360/hcf(360,x) << endl;

    return 0;
}

Measured memory_bytes: 3604
/*
文字列の配列の初期化、整数の型がlongになっているか
関数（splitとかcontainsとか）内では"+"とかは正規表現となされるので"\\+"とする
配列のコピーはarr1=arr.clone()
HashSet<>[]はおのおの初期化した？？？？？
 */
import java.util.*;
import java.awt.*;
import java.awt.geom.*;
import static java.lang.System.*;
import static java.lang.Math.*;
public class Main {
    public static void main(String[] $) {
        Scanner sc = new Scanner(in);
        int[] prime=Generate_prime(1299709);
        while (true) {
            int n = sc.nextInt();
            if (n == 0) break;
            int d = Arrays.binarySearch(prime, n);
            if (n == 1 || d > 0) {
                out.println(0);
            } else {
                d = ~d;
                out.println(prime[d] - prime[d - 1]);
            }
        }
    }
    static int[] Generate_prime(int n) {
        ArrayList<Integer> prime = new ArrayList<>();
        prime.add(2);
        prime.add(3);
        for (int i = 6; i <= n; i += 6) {
            int p1 = i - 1, p2 = i + 1;
            if (isPrime(p1)) prime.add(p1);
            if (isPrime(p2)) prime.add(p2);
        }
        int t=prime.size();
        int[] Generated_prime=new int[t+1];
        //Iteratorでもよい
        for (int i=1;i<=t;i++){
            Generated_prime[i]=prime.get(i-1);
        }
        return Generated_prime;
    }
    static boolean isPrime(int p){
        if(p==1)return false;
        int t= (int) (sqrt(p)+1);
        boolean f=true;
        for (int i = 5; i <= t && f; i++) if(p%i==0) f=false;
        return f;
    }
}


Measured memory_bytes: 35020
#include <iostream>
#include <bits/stdc++.h>
#define IO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
using namespace std;
string s;
long long dp[100004][13];
long long mod = 1e9 + 7;
long long solve(long long i, long long rem){
    if(i == s.size()){
        if(rem % 13 == 5)return 1;
        return 0;
    }
    if(dp[i][rem] != -1)return dp[i][rem];
    long long z = rem;
    if(s[i] == '?'){
        long long ann = 0;
        for(int j = 0; j < 10; j++){
            long long rem2 = rem*10 + (j);
            rem2 = rem2 % 13;
            ann = (ann + (solve(i+1, rem2))%mod ) % mod;
        }
        return dp[i][z] = ann;
    }

    rem = rem*10 + (s[i] - '0');
    rem = rem % 13;
    return dp[i][z] = (solve(i+1, rem))%mod;
}
int main()
{
    cin>>s;
    memset(dp, -1, sizeof dp);
    cout<<solve(0,0);
    return 0;
}


Measured memory_bytes: 16896
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
const ll INF=1LL<<60;
const double EPS = 1e-10;
const ll mod=1000000007;

int main(void){
    string s,t;
    cin>>s>>t;
    int ans=0;
    for(int i=0;i<s.size();i++){
        if(s[i]!=t[i]) ans++;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 3916
N = int(input())

matrix = [[1 for i in range(N)] for i in range(N)]
for i in range(N):
    matrix[i][i] = 0

if N%2==0:
    for i in range(N):
        matrix[i][N-i-1] = 0
else:
    for i in range(N-1):
        matrix[i][N-i-2] = 0

print(int((N*(N-1)/2)-int(N/2)))
for i in range(N):
    for j in range(i+1,N):
        if matrix[i][j] == 1:
            print(i+1,j+1)


Measured memory_bytes: 3700
#include <bits/stdc++.h>
//#include <atcoder/all>
#define rep(i, a) for (int i = (int)0; i < (int)a; ++i)
#define rrep(i, a) for (int i = (int)a - 1; i >= 0; --i)
#define REP(i, a, b) for (int i = (int)a; i < (int)b; ++i)
#define RREP(i, a, b) for (int i = (int)a - 1; i >= b; --i)
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define popcount __builtin_popcount
using ll = long long;
constexpr ll mod = 1e9 + 7;
constexpr ll INF = 1LL << 60;


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

ll gcd(ll n, ll m)
{
	ll tmp;
	while (m != 0)
	{
		tmp = n % m;
		n = m;
		m = tmp;
	}
	return n;
}

ll lcm(ll n, ll m)
{
	return abs(n) / gcd(n, m) * abs(m); //gl=xy
}

using namespace std;
//using namespace atcoder;

void solve(){
	ll n;
	cin>>n;
	vector<ll>a(n);
	rep(i,n)cin>>a[i];
	sort(rall(a));
	map<ll,ll>mp;
	rep(i,n)mp[a[i]]++;
	int ans=0;
	rep(i,n){
		if(!mp.count(a[i]))continue;
		rep(j,30){
			ll x=1LL<<(30-j);
			if(x-a[i]<a[i])break;
			if(mp.count(x-a[i])){
				if(x-a[i]==a[i]&&mp[a[i]]==1)continue;
				mp[x-a[i]]--;
				mp[a[i]]--;
				if(mp[x-a[i]]==0)mp.erase(x-a[i]);
				if(mp[a[i]]==0)mp.erase(a[i]);
				++ans;
				break;
			}
		}
	}
	cout<<ans<<"\n";
}


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


Measured memory_bytes: 17180
#include <bits/stdc++.h>
#define LOOP(n) for (int _i = 0; _i < (n); _i++)
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define FOR(i, r, n) for (int i = (r); i < (n); ++i)
#define ALL(obj) begin(obj), end(obj)
using namespace std;
using ll = long long;
using ull = unsigned long long;

const int INF = 2100100100;
const int MOD = 1e9 + 7;

// 多次元 vector 生成
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>
bool chmax(T &a, const T &b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T &a, const T &b) {
    if (b < a) {
        a = b;
        return 1;
    }
    return 0;
}

int main() {
    // cin.tie(0);
    // ios::sync_with_stdio(false);
    int N;
    cin >> N;
    vector<int> X(N), sX(N);
    REP(i, N) { cin >> X.at(i); }
    sX = X;
    sort(ALL(sX));

    int l = sX[N / 2 - 1];
    int r = sX[N / 2];

    REP(i, N) {
        if (r <= X[i]) {
            cout << l << endl;
        } else {
            cout << r << endl;
        }
    }

    return 0;
}


Measured memory_bytes: 3712
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(ri,n) for(int ri = (int)(n-1); ri >= 0; ri--)
#define rep2(i,x,n) for(int i = (int)(x); i < (int)(n); i++)
#define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++)
#define rrepit(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++)
#define ALL(n) begin(n), end(n)
using ll = long long;
using namespace std;

int main(){
	int k;
	cin >> k;
	vector<int> a(k);
	rep(snip_i, k) cin >> a.at(snip_i);
	ll l, r;
	l = r = 2;
	rrep(i, k){
		ll x, y, n_a = a.at(i);
		if(l % n_a != 0 && r < l + (n_a - l % n_a)){
			// cerr << l % n_a << " " << r % n_a << endl;
			cout << -1 << endl;
			return 0;
		}
		x = (l+n_a-1)/n_a*n_a;
		y = r/n_a*n_a;
		l = x;
		r = y + n_a - 1;
	}
	cout << l << " " << r << endl;
	return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <stdio.h>
#include <queue>
#include <climits>
#include <map>
#include <set>
const int mod = 1e9 + 7;
const int inf = 1 << 20;
const long long INF = 1LL << 60;
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
using namespace std;

int main()
{
    int h,w;
    cin >> h >> w;
    int cnt = 0;
    for(int i = 0; i < h; i++){
        for(int j = 0; j < w; j++){
            char c;
            cin >> c;
            if(c == '#') cnt++;
        }
    }
    if(cnt == h + w -1) cout << "Possible" << endl;
    else cout << "Impossible" << endl;
}

Measured memory_bytes: 256
k,n=map(int,input().split())
arr=list(map(int,input().split()))
ans=10**18 #最小値を求めるので十分大きな値で初期化
for i in range(n): #上式を元に最短距離を求める
 dist1=(arr[i-1]-arr[i])%k
 dist2=(arr[i]-arr[(i+1)%n])%k
 ans=min(ans,dist1,dist2)
print(ans)


Measured memory_bytes: 25840
#include <iostream>
using namespace std;
int n;
int a;
int p = 0;

void is_prime()
{
	for(int i = 2; i*i <= a; i++)
	{
		if (a % i == 0)
		{
			return;
		}
	}
	
	p++;
}

int main()
{
	cin >> n;
	for(int i = 0; i < n; i++)
	{
		cin >> a;
		is_prime();
	}
	
	cout << p << endl;
	return 0;
}

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

int main(){
    char x;
    int a=0,b=0,c=0;
    for(int i=0;i<3;i++){
        cin >> x;
        if(x=='a')a++;
        else if(x=='b')b++;
        else c++;
    }
    if(a==b&&b==c)cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define WHOLE(v) (v).begin(), (v).end()
#define REV_WHOLE(v) (v).rbegin(), (v).rend()
using i64 = int64_t;
using namespace std;
template<class F>auto recursive(F f){return[f](auto...a){return f(f,a...);};}
template<class T>using rev_priority_queue=priority_queue<T,vector<T>,greater<T>>;
template<class T>using vector2d=vector<vector<T>>;
struct fixprec{int p;fixprec(int p):p(p){}};
ostream&operator<<(ostream&o,fixprec f){return o<<fixed<<setprecision(f.p);}
int main() {
    int N;
    cin >> N;
    i64 A, B, C;
    cin >> A >> B >> C;
    bool yesno = true;
    string ans = "";
    vector<string> s(N);
    for(int i = 0; i < N; i++) {
        cin >> s[i];
    }
    for(int i = 0; i < N; i++) {
        if(s[i] == "AB") {
            if(A > B || (A == B && (i == N - 1 || s[i + 1] == "BC"))) {
                A--, B++;
                ans.push_back('B');
            } else if (A < B || (A == B && (s[i + 1] == "AB" || s[i + 1] == "AC"))) {
                A++, B--;
                ans.push_back('A');
            }
        } else if(s[i] == "BC") {
            if(B > C || (B == C && (i == N - 1 || s[i + 1] == "AC"))) {
                B--, C++;
                ans.push_back('C');
            } else if (B < C || (B == C && (s[i + 1] == "AB" || s[i + 1] == "BC"))) {
                B++, C--;
                ans.push_back('B');
            }
        } else if(s[i] == "AC") {
            if (C > A || (C == A && (i == N - 1 || s[i + 1] == "AB"))) {
                C--, A++;
                ans.push_back('A');
            } else if (C < A || (C == A && (s[i + 1] == "AC" || s[i + 1] == "BC"))) {
                C++, A--;
                ans.push_back('C');
            }
        }
        if(A < 0 || B < 0 || C < 0) yesno = false;
    }
    cout << (yesno ? "Yes" : "No") << endl;
    if(!yesno) return 0;
    for(int i = 0; i < N; i++) {
        cout << ans[i] << endl;
    }
    return 0;
}



Measured memory_bytes: 6692
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>

using namespace std;
 
int n[2],m[2];
map< pair<string,string> , int > memo[501][501];
vector< vector<int> > a[2];
vector< vector<string> > b[2];
 
int dfs(int p1,int p2,string s1,string s2){
        if(p1 == n[0]-1 && p2 == n[1]-1) return (s1 == "" && s2 == "");
		if(memo[p1][p2].count(make_pair(s1,s2))) return memo[p1][p2][make_pair(s1,s2)];

        int ans = 0;
		if(p1 <= p2 || p2 == n[1]-1){
			for(int i = 0 ; i < a[0][p1].size() ; i++){
					string x = s1 + b[0][p1][i];
					string y = s2;
					int I = 0 , J = 0;
					for( ; I < x.size() && J < y.size() && x[I] == y[J] ; ) I++ , J++ ;
					if( I == x.size() || J == y.size() ){
							
							if( I == x.size() && I == y.size() ) x = "" , y = "";
							else if( I == x.size() ) x = "" , y = y.substr(J);
							else if( J == y.size() ) x = x.substr(I) , y = "";
							
							ans = ( ans + dfs(a[0][p1][i],p2,x,y) ) % 1000000007;
					}
			}
		}
        
		if(p1 > p2 || p1 == n[0]-1){
			for(int j = 0 ; j < a[1][p2].size() ; j++){
					string x = s1;
					string y = s2 + b[1][p2][j] ;
					int I = 0 , J = 0;
					for( ; I < x.size() && J < y.size() && x[I] == y[J] ; ) I++ , J++ ;
					if( I == x.size() || J == y.size() ){
							
							if( I == x.size() && I == y.size() ) x = "" , y = "";
							else if( I == x.size() ) x = "" , y = y.substr(J);
							else if( J == y.size() ) x = x.substr(I) , y = "";
							
							ans = ( ans + dfs(p1, a[1][p2][j],x,y) ) % 1000000007;
					}
			}
		}
        return memo[p1][p2][make_pair(s1,s2)] = ans;
}
 
int main(){
        int T;cin >> T;
        while(T--){
                for(int i = 0 ; i < 2 ; i++){
                        cin >> n[i] >> m[i];
                        //cout << n[i] << " " << m[i] << endl;
                        a[i].clear(); b[i].clear(); a[i].resize((unsigned)n[i]) , b[i].resize((unsigned)n[i]);
                        for(int j = 0 ; j < m[i] ; j++){
                                int A,B; string C;
                                cin >> A >> B >> C;
                                a[i][A].push_back(B);
                                b[i][A].push_back(C);
                        }
                }
				for(int i = 0 ; i < 501 ; i++)
					for(int j = 0 ; j < 501 ; j++)
						memo[i][j].clear();
                cout << dfs(0,0,"","") << endl;
        }
}

Measured memory_bytes: 7756
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <map>
#include <vector>
#include <stack>
#include <queue>
#include <tuple>
#include <cassert>
#include <functional>
#include <set>
#include <deque>
using namespace std;
typedef long long ll;
int dx[4] = {0,0,1,-1};
int dy[4] = {1,-1,0,0};
const int INF = 1<<29;
#define LNF __LONG_LONG_MAX__
const ll MOD = 1000000007;
const int MAX = 200000;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
// 法mでのaの逆元を計算
long long modinv(long long a, long long m) {
    long long b = m, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}
// a^n mod を計算する
long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
//最大公約数
int gcd(int x, int y) { return (x % y)? gcd(y, x % y): y; }
//最小公倍数
int lcm(int x, int y) { return x / gcd(x, y) * y; }
// nが大きく,kが10^7程度の時の二項係数
long long com[200005];
void combination(long long n,long long k){
    com[0] = 1;
    for(int i=1;i<=k;i++){
        com[i] = (com[i-1]*(n-i+1)%MOD)*modinv(i,MOD)%MOD;
    }
}

int main(){
    int N; cin >> N;
    string S; cin >> S;
    vector<int> b(N+1,0);
    vector<int> w(N+1,0);
    for(int i=0;i<N;i++){
        if(S[i]=='#'){
            b[i+1] = b[i]+1;
            w[i+1] = w[i];
        }else{
            b[i+1] = b[i];
            w[i+1] = w[i]+1;
        }
    }
    int out=INF;
    for(int i=0;i<=N;i++){
        int tmp=0;
        tmp += b[i]-b[0];
        tmp += w[N]-w[i];
        if(out>tmp) out = tmp;
    }
    cout << out << endl;
    return 0;
}


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

namespace AtCoders {
	class Program {
		static void Main(string[] args) {

			var inputArray = retreiveLongArray();
			var inputCount = 3;

			// 不正な入力は処理しない
			if (inputArray.Length != inputCount) {
				Console.WriteLine("invalid input");
				return;
			}

			var N = inputArray[0];
			var a = inputArray[1];
			var b = inputArray[2];

			//答えの出力
			var ans = getAns(N,a,b);
			Console.WriteLine(ans);

		}

		/// <summary>
		/// 答えを求める
		/// </summary>
		/// <param name="N"></param>
		/// <param name="a"></param>
		/// <param name="b"></param>
		/// <returns></returns>
		private static long getAns(long N, long a, long b) {

			if (N == 2) {
				return 0;
			}

			long limit = 1000000000 + 7;
			//a,bの条件を考えない場合 2n-1通り。(-1は一本も選ばないとき)
			var pattern = repeatNijou(2, N, limit)-1;
			//Console.WriteLine($"合計{pattern}");
			var num_a = calcCombination(N, a, limit);
			var num_b = calcCombination(N, b, limit);
			var ans = pattern - num_a - num_b;
			//nCaをlimitで割ったあまりは,
			while (ans < 0) {
				//Console.WriteLine($"途中経過{ans}");
				ans = ans + limit;
			}

			return ans;
		}

		/// <summary>
		/// 繰り返し2乗法
		/// </summary>
		/// <param name="tei"></param>
		/// <param name="beki"></param>
		/// <param name="limit"></param>
		/// <returns></returns>
		private static long repeatNijou(long tei,long beki, long limit) {

			if (beki == 1) {
				return tei;
			}

			var result = repeatNijou(tei, beki / 2, limit) % limit;
			//べきが偶数のときは、半分同士をかける
			if (beki%2 == 0) {
				var ans = result*result;
				return (ans % limit);
			}//べきが奇数の時
			else {
				var ans = ((result * result)%limit) * tei;
				return (ans % limit);
			}

		}

		/// <summary>
		/// n個からp個を選ぶ組み合わせの数をlimitで割ったあまりを求める
		/// X*Y(limit-2)
		/// </summary>
		/// <param name="n"></param>
		/// <param name="p"></param>
		/// <returns></returns>
		private static long calcCombination(long N, long p,long limit) {

			long x = 1;
			long y = 1;


			for (long i = 0; i < p; i++) {
				x = (x * (N - i) )% limit;//分子
				y=(y*(i+1)) % limit;//分母
				//Console.WriteLine($"p={p},combi={combinationNum}");
			}

			var longAns = x * repeatNijou(y, limit - 2, limit);
			return longAns % limit;
		}

		/// <summary>
		/// スペースで区切られた文字列配列の入力を受け取る
		/// </summary>
		/// <returns></returns>
		private static string[] retreiveStringArray() {
			var inputArray =  Console.ReadLine().Split(' ');
			return inputArray;
		}

		/// <summary>
		/// スペースで区切られた整数配列の入力を受け取る
		/// </summary>
		/// <returns></returns>
		private static long[] retreiveLongArray() {
			var inputArray = Console.ReadLine().Split(' ');
			var longArray = inputArray.Select(s => long.Parse(s));
			return longArray.ToArray();
		}
	}
}


Measured memory_bytes: 13396
// AtCoder Regular Contest 065
// D - 連結 / Connectivity

#include <cstdio>
#include <map>
using namespace std;
typedef long long int ll;
typedef pair<int, int> PII;


const int MAX_N = 200000;


class UnionFind{
    public:
        void init(int n);
        void unite(int a, int b);
        bool same(int a, int b);
        int root(int a);
    private:
        int par[MAX_N];
        int rank[MAX_N];
};

void UnionFind::init(int n) {
    for (int i = 0; i < n; i++) {
        par[i] = i;
        rank[i] = 0;
    }
    return;
}

void UnionFind::unite(int a, int b) {
    a = root(a);
    b = root(b);
    if (a == b) {
        return;
    }
    if (rank[a] < rank[b]) {
        par[a] = b;
    } else {
        par[b] = a;
        if (rank[a] == rank[b]) {
            rank[a]++;
        }
    }
    return;
}

bool UnionFind::same(int a, int b) {
    return root(a) == root(b);
}

int UnionFind::root(int a) {
    if (par[a] != a) {
        par[a] = root(par[a]);
    }
    return par[a];
}


int N, KL[2];
UnionFind uf[2];
map<PII, int> mp;

int main() {

    PII p;
    int a, b;

    scanf("%d%d%d", &N, &KL[0], &KL[1]);
    for (int j = 0; j < 2; j++) {
        uf[j].init(N);
        for (int i = 0; i < KL[j]; i++) {
            scanf("%d%d", &a, &b);
            uf[j].unite(a - 1, b - 1);
        }
    }

    for (int i = 0; i < N; i++) {
        p = PII(uf[0].root(i), uf[1].root(i));
        mp[p] = mp[p] + 1;
    }

    for (int i = 0; i < N; i++) {
        p = PII(uf[0].root(i), uf[1].root(i));
        printf("%d%c", mp[p], i == N - 1 ? '\n' : ' ');
    }

    return 0;

}





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

using namespace std;

int main(){
    int N;
    cin>>N;
    vector <int>H(N);
    for(int i = 0 ; i < N ; i++){
        cin>>H[i];
    }
    
    int ans = 1;
    int top = H[0];
    for(int i = 1 ; i < N ; i++) {
        if(H[i-1] <= H[i] && top <= H[i] ) {
            ans++;
            top = H[i];
        }
    }

    cout<<ans<<endl;

    return 0;
}


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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;

int n;
string s;

int main()
{
    cin >>n;
    int s=0;
    int x,y;
    while(n--)
    {
        scanf("%d %d",&x,&y);
        s+=(y-x+1);
    }
    cout << s;
    return 0;
}


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

	ArrayList<Long> llist = new ArrayList<>();
	int n = sc.nextInt();
	int count = 0;
	for (int i = 0; i < n; i++) {
		long l = sc.nextLong();
		llist.add(l);
	}
	Collections.sort(llist);

	for(int i = 0; i < n-2; i++) {
		for(int j = i+1; j < n-1; j++) {
			for(int k = j+1; k < n; k++) {
				if(llist.get(i).equals(llist.get(j)) || llist.get(j).equals(llist.get(k)) || llist.get(k).equals(llist.get(i))) {
					continue;
				}

				if(llist.get(i)+llist.get(j) > llist.get(k) && llist.get(j)+llist.get(k) > llist.get(i) && llist.get(k)+llist.get(i) > llist.get(j)) {
					count++;
				}
			}
		}
	}

System.out.println(count);

}
}


Measured memory_bytes: 38168
#include <stdio.h>

int main(){
    const unsigned int length_input = 3;
    char input_S[length_input+1];

    scanf("%s", input_S);
    /* printf("%s\n", input_S); */

    if((input_S[0] - input_S[1] == 0) && (input_S[1] - input_S[2] == 0 )){
        printf("No\n");
    }
    else{
        printf("Yes\n");
    }

    return(0);
}

Measured memory_bytes: 128
#include <stdio.h>
#include <string.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <math.h>
#include <stdlib.h>
#include <bitset>
#include <time.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;
int n,m;
int dp[109][109];
int a[1009],b[1009],c[1009];
int main()
{
    scanf("%d%d",&n,&m);
    for(int i=1;i<=n;++i)
    {
        for(int j=1;j<=n;++j)dp[i][j]=1e9;
        dp[i][i]=0;
    }
    for(int i=0;i<m;++i)
    {
        scanf("%d%d%d",&a[i],&b[i],&c[i]);
        dp[a[i]][b[i]]=min(dp[a[i]][b[i]],c[i]);
        dp[b[i]][a[i]]=min(dp[b[i]][a[i]],c[i]);
    }
    for(int i=1;i<=n;++i)
    {
        for(int j=1;j<=n;++j)
        {
            for(int l=1;l<=n;++l)
            {
                if(dp[j][l]>dp[j][i]+dp[i][l])dp[j][l]=dp[j][i]+dp[i][l];
            }
        }
    }
    int ans=0;
    for(int i=0;i<m;++i)
    {
        if(dp[a[i]][b[i]]!=c[i])++ans;
    }
    printf("%d\n",ans);
    return 0;
}


Measured memory_bytes: 256
open System

let N,T=stdin.ReadLine().Split()|>fun c-> int c.[0],int c.[1]
[<EntryPoint>]
let main argv =
    [|for i in [0..N-1] do yield (stdin.ReadLine().Split()|>Array.map int|>fun c -> (if c.[1]<=T then c.[0] else 100000))|]
    |>Array.min
    |>fun c -> if c=100000 then "TLE" else (c|>string)
    |>stdout.WriteLine
    0


Measured memory_bytes: 13396
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
inline char tc(void){
	static char fl[10000],*A=fl,*B=fl;
	return A==B&&(B=(A=fl)+fread(fl,1,10000,stdin),A==B)?EOF:*A++;
}
inline int read(void){
	int a=0;char c;
	while((c=tc())<'0'||c>'9');
	while(c>='0'&&c<='9')a=a*10+c-'0',c=tc();
	return a;
}
int n,a[200005];
long long ans;
int main(void){
	register int i;
	n=read();
	for(i=1;i<=n;++i){
		a[i]=read();
		if(i==1&&a[i]!=0){
			puts("-1");return 0;
		}
		if(i!=1&&a[i]-a[i-1]>1){
			puts("-1");return 0;
		}
	}
	for(i=n;i;--i)
		if(a[i]!=a[i+1]-1)ans+=a[i];
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 1024
#include <cstdio>
#include <algorithm>
#define LL long long
#define maxn 200010
using namespace std;
int a[maxn],n,cnt[maxn],mx;//cnt[]统计相同数值的元素数量
LL ans,out;
int main(){
	int i;
	scanf("%d",&n);
	for(i=1;i<=n;i++)scanf("%d",&a[i]),cnt[a[i]]++,mx=max(mx,a[i]);
	for(i=1;i<=mx;i++)
		if(cnt[i]>=2)ans+=(LL)cnt[i]*(cnt[i]-1)/2;//任选2个
	for(i=1;i<=n;i++){
		if(cnt[a[i]]>=2){
			out=ans-cnt[a[i]]*(cnt[a[i]]-1)/2;//先扣除
			out+=(cnt[a[i]]-1)*(cnt[a[i]]-1-1)/2;//再加回
		}else out=ans;
		printf("%lld\n",out);
	}
	return 0;
}

Measured memory_bytes: 3584
#include <iostream>
#include <set>

using namespace std;

int main()
{
    ios_base::sync_with_stdio(0);
    int n;
    cin >> n;
    set<int> s;
    for (int i = 0; i < n; ++i)
    {
        int x;
        cin >> x;
        s.insert(x);
    }
    if (s.size() == n)
        cout << "YES";
    else
        cout << "NO";
    return 0;
}


Measured memory_bytes: 9600
n,m=map(int,input().split())

dict = {}
for i in range(m):
    p,s=input().split()
    dict.setdefault(p,[]).append(s)

ac_count=0
wa_count=0
for p,s in dict.items():
    is_ac=False
    wa_tmp_count=0
    for ans in s:
        if ans=='AC':
            ac_count+=1
            is_ac=True
        else:
            wa_tmp_count+=1
        if is_ac:
            wa_count+=wa_tmp_count
            break
print(ac_count, wa_count)

Measured memory_bytes: 71256
#![allow(unused_imports)]
use std::cmp::*;
use std::collections::*;
use itertools::Itertools;
use num_traits::clamp;
use ordered_float::OrderedFloat;
use proconio::{input, marker::*, fastout};
use superslice::*;

#[fastout()]
fn main() {
    input! {
        n: usize,
        ab: [(Usize1, Usize1); n-1]
    }

    let mut graph = vec![Vec::new(); n];
    for (a, b) in ab {
        graph[a].push(b);
        graph[b].push(a);
    }

    let mut ldist = vec![0; n];
    let mut stack = Vec::new();
    let mut visited = vec![false; n];
    stack.push((0, 0));
    visited[0] = true;
    while let Some((node, dist)) = stack.pop() {
        ldist[node] = dist;
        for &next in &graph[node] {
            if !visited[next] {
                visited[next] = true;
                stack.push((next, dist+1));
            }
        }
    }

    let mut rdist = vec![0; n];
    let mut stack = Vec::new();
    let mut visited = vec![false; n];
    stack.push((n-1, 0));
    visited[n-1] = true;
    while let Some((node, dist)) = stack.pop() {
        rdist[node] = dist;
        for &next in &graph[node] {
            if !visited[next] {
                visited[next] = true;
                stack.push((next, dist+1));
            }
        }
    }

    let mut p = 0i64;
    for i in 1..n-1 {
        if ldist[i] <= rdist[i] {
            p += 1;
        } else {
            p -= 1;
        }
    }
    if p > 0 {
        println!("Fennec");
    } else {
        println!("Snuke");
    }
}


Measured memory_bytes: 10392
#include <iostream>
#include <cstdlib>
#include <cmath>
#include <algorithm>

using namespace std;

int main(void) {
  int n;
  cin >> n;
  while (getchar() != '\n');

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

  int res[200];
  for (int i = 0; i < n; i++) {
    int count = 0;
    while (a[i] % 2 == 0) {
      a[i] /= 2;
      count++;
    }
    res[i] = count;
  }
  cout << *min_element(res, res + n) << endl;
  return EXIT_SUCCESS;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <utility>
#include <stack>
#include <numeric>
#include <algorithm>
#include <tuple>
#include <stdio.h>
#include <bitset>
#include <limits.h>
#include <complex>
#include <deque>
#include <iomanip>
#include <list>
using namespace std;
#define pi pair<int32,int32>
#define pl pair<int64,int64>
#define chmax(a,b) (a<b ? a=b:0)
#define chmin(a,b) (a>b ? a=b:0)
#define en cout << endl //セミコロンつけろ
//#define MM 1000000000
//#define MOD MM+7
const int MM = 1e9;
const int MOD = MM+7;
const long double PI = acos(-1);
const long long INF = 1e15;
int dx[8] = {-1,0,1,0,-1,-1,1,1};
int dy[8] = {0,-1,0,1,-1,1,1,-1};
// 'A' = 65, 'Z' = 90, 'a' = 97, 'z' = 122
template<typename T>
T GCD(T u,T v){
    return v ? GCD(v,u%v) : u;
}
template<typename T>
T LCM(T x,T y){
    T gc = GCD(x,y);
    return x*y/gc;
}

int main(){
    long long L,R; cin >> L >> R;
    if (R - L >= 2019){
        cout << 0 << endl;
        return 0;
    } else {
        long long ans = MM;
        for (long long i = L; i < R; i++){
            for (long long j = L+1; j <= R; j++){
                ans = min(ans, (i*j) % 2019);
            }
        }
        cout << ans << endl;
    }
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <ctime>
#include <cassert>
#include <iostream>
#include <cctype>
#include <sstream>
#include <string>
#include <list>
#include <vector>
#include <queue>
#include <set>
#include <stack>
#include <map>
#include <utility>
#include <numeric>
#include <algorithm>
#include <iterator>
#include <bitset>
#include <complex>
#include <fstream>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
typedef vector<int> vint;
typedef pair<int, int> pint;
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
template<class T> T RoundOff(T a){ return int(a+.5-(a<0)); }
template<class T, class C> void chmax(T& a, C b){ if(a < b) a = b; }
template<class T, class C> void chmin(T& a, C b){ if(b < a) a = b; }
template<class T, class C> pair<T, C> mp(T a, C b){ return make_pair(a, b); }


const int INF = 1 << 30;

int W, H, F, M, O;
int G[16][16];

int memo[16][16][16][16][55];

// return 総発掘費用
int rec(int left, int right, int x, int y, int o)
{
	if(y + 1 == H) return o <= 0 ? INF : 0;
	if(o <= 1) return INF;
	
	if(memo[left][right][x][y][o] != -1) return memo[left][right][x][y][o];
	
	int res = INF;
	
	if(0 < left){
		int next_o = min(o - (x - left + 1) + max(0, G[y][left - 1]), M);
		int expense =  - min(0, G[y][left - 1]);
		res = min(res, rec(left - 1, right, left - 1, y, next_o) + expense);
	}
	
	if(right + 1 < W){
		int next_o = min(o - (right + 1 - x) + max(0, G[y][right + 1]), M);
		int expense =  - min(0, G[y][right + 1]);
		res = min(res, rec(left, right + 1, right + 1, y, next_o) + expense);
	}
	
	for(int d = left; d <= right; d++){
		int next_o = min(o - abs(x - d) - 1 + max(0, G[y + 1][d]), M);
		int expense =  - min(0, G[y + 1][d]);
		res = min(res, rec(d, d, d, y + 1, next_o) + expense);
	}
	
	return memo[left][right][x][y][o] = res;  
}

bool input()
{
	cin >> W >> H;
	
	if(W == 0 && H == 0) return false;
	
	cin >> F >> M >> O;

	rep(y, H) rep(x, W) cin >> G[y][x];
	
	return true;
}

int main()
{
	while(input()){
		if(O <= 1)
		{
			cout << "NA" << endl;
			continue;
		}
		
		memset(memo, -1, sizeof memo);
		int res = INF;
		
		for(int i = 0; i < W; i++){
			int next_o = min(O + max(0, G[0][i]) - 1, M);
			int expense = - min(0, G[0][i]);
			res = min(res, rec(i, i, i, 0, next_o) + expense);
		}
		
		if(res <= F) cout << res << endl;
		else cout << "NA" << endl;
	}
	
	return 0;
}

Measured memory_bytes: 14000
L, R = map(int, input().split())
C = []
flag = False
for i in range(L, R+1):
    if i%2019==0:
        flag = True
        break
    else:
        C.append(i)
        
if flag:
    print(0)
else:
    import itertools
    ans = 4080400
    for x, y in list(itertools.combinations(C, 2)):
        if (x*y)%2019<ans:
            ans = (x*y)%2019
    print(ans)

Measured memory_bytes: 148284
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;
#define inf 0x3f3f3f
#define N 10000
int fa[2*N+5],t,n,m,k;
double s[N+5][2],s1;
struct mzls
{
	int u,v;
	double w;
	bool operator<(const mzls &a)const
	{
		return a.w<w;
	}
}g[N*N+5],as;
inline int find(int x)
{
	if(fa[x]==-1)
		return x;
	return fa[x]=find(fa[x]);
}
inline double K()
{
	double sum=0.0;
	sort(g+1,g+t+1);
	memset(fa,-1,sizeof(fa));
	int j=0;
	for(int i=1;i<=t;i++)
	{
		int u=g[i].u,v=g[i].v;
		int r1=find(u),r2=find(v);
		if(r1!=r2)
		{
			fa[r2]=r1;
			sum+=g[i].w;
			j++;
			if(j>=n-1)
				break;
		}
	}
	return sum;
}
inline void insert(int x,int y,double z)
{
	as.u=x,as.v=y,as.w=z;
	g[++t]=as;
}
int main()
{
	scanf("%d%d",&n,&m);
	for(int i=1;i<=n;i++)
		scanf("%lf%lf",&s[i][0],&s[i][1]);
	for(int i=1;i<=m;i++)
	{
		int x,y;
		double z;
		scanf("%d%d",&x,&y);
		z=sqrt((s[x][1]-s[y][1])*(s[x][1]-s[y][1])+(s[x][0]-s[y][0])*(s[x][0]-s[y][0]));
		s1+=z;
		insert(x,y,z);
	}
	printf("%lf\n",s1-K());
}


Measured memory_bytes: 3452
/* tempate
 *
 *
 */

#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <queue>
#include <deque>
#include <list>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>

using namespace std;


#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repr(i,n) for(int (i)=(n); (i)>=(0); (i)--)
#define SIZE(x) ((int)(x).size())
#define GCD(a, b) int gcd(int a,int b){return b?gcd(b,a%b):a;}
#define QP(a, b) int qp(int a,ll b){int ans=1;do{if(b&1)ans=1ll*ans*a%mo;a=1ll*a*a%mo;}while(b>>=1);return ans;}
#define pb(a) push_back(a)
#define mp(a,b) make_pair(a,b)
#define all(v) (v).begin(),(v).end()


template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}
template<typename A, size_t N, typename T>
void FILL(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

typedef vector<int, int> vint;
typedef pair<int,int> pint;
typedef vector<pint>vpint;
typedef long long ll;

int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const ll INF = 1LL << 60;
const ll MOD = 1000000007LL;


int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n; cin >> n;
    ll res = 0;
    if(n == 1){
        cout << 0 << endl;
        return 0;
    }
    for(ll i = 2; i <= n - 1; i++){
        res += i;
    }
    res++;
    cout << res;
    cout << endl;
    return 0;
}


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

int main() {
    int N;
    cin >> N;
    int f;
    for (int i = 1; i <= 100000000; i *= 10){
        f += (N%(i*10))/i;
    }
    if (N % f == 0) {
        cout << "Yes" << endl;
    }
    else {
        cout << "No" << endl;
    }
}


Measured memory_bytes: 256
S = input()
count = 0
for letter in S:
    count += 1
    if count % 2 == 1 and letter == "L":
        print("No")
        count -=1
        break
    elif count % 2 == 0 and letter == "R":
        print("No")
        count -=1
        break
if count == len(S):
    print("Yes")

Measured memory_bytes: 3060
//BISMILLAH
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define lli long long int
#define ve vector<int>
#define FOR(n)          for(int i=0; i<(int)(n); ++i)
#define TEST_CASE(t)    for(int z=1;z<=t;z++)
#define PRINT_CASE      printf("Case %d: ",z)
#define pb push_back
#define mod 1000000007
int arr[1000000];
int main()
{
  ll n,flag,temp=0;
  ll cnt=0;
  cin>>n;

  for(ll a=1;a<=n;a++)
  {
     ll rightb=n,leftb=1;
     while(leftb<=rightb)
     {
         ll b = leftb + (rightb - leftb) / 2;
         if(a*b<= n-1)
         {
             cnt++;
             leftb +=1;
         }
         else rightb = b-1;
     }
  }
  cout<<cnt<<endl;

}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
template <typename T> void read(T &t) {
	t=0; char ch=getchar(); int f=1;
	while (ch<'0'||ch>'9') { if (ch=='-') f=-1; ch=getchar(); }
	do { (t*=10)+=ch-'0'; ch=getchar(); } while ('0'<=ch&&ch<='9'); t*=f;
}
typedef long long ll;
const int maxn=(1<<18)+10;
const int INF=100000;
int n,q,w[maxn],dep[maxn];
int tot,d[100],K;
ll val[maxn],dp[(1<<9)+10][INF+10],ans,s1,s2;
int main() {
	//printf("%d\n",sizeof(dp)/1024/1024);
	//freopen("1.txt","r",stdin);
	K=9;
	read(n);
	for (int i=1;i<=n;i++) read(val[i]),read(w[i]),dep[i]=dep[i/2]+1;
	for (register int i=1;i<=n;++i) if (dep[i]<=K) {
		for (register int j=0;j<=INF;++j) {
			dp[i][j]=dp[i/2][j];
			if (j>=w[i]) dp[i][j]=max(dp[i][j],dp[i/2][j-w[i]]+val[i]);
		}
		continue;
		for (int j=0;j+w[i]<=INF;j++) dp[i][j+w[i]]=max(dp[i][j+w[i]],dp[i/2][j]+val[i]);
		//printf("%d\n",i);
	} else break;
	int x,y,z;
	read(q);
	while (q--) {
		read(x); read(y);
		if (dep[x]<=K) printf("%lld\n",dp[x][y]);
		else {
			tot=0;
			ans=0;
			z=x;
			while (1) {
				d[++tot]=z;
				z/=2;
				if (dep[z]<=K) break;		
			}
			for (register int t=0;t<(1<<tot);++t) {
				s1=s2=0;
				for (register int i=1;i<=tot;++i)
					if (t&(1<<(i-1))) {
						s1+=val[d[i]],s2+=w[d[i]];
						if (s2>y) break;
					}
				if (s2>y) continue;
				ans=max(ans,s1+dp[z][y-s2]);
			}
			printf("%lld\n",ans);
		}
	}
	return 0;
}
/*
  0. Enough array size? Enough array size? Enough array size? Interger overflow?
  
  1. Think TWICE, Code ONCE!
  Are there any counterexamples to your algo?
    
  2. Be careful about the BOUNDARIES!
  N=1? P=1? Something about 0?
    
  3. Do not make STUPID MISTAKES!
  Time complexity? Memory usage? Precision error?
*/

Measured memory_bytes: 407008
#include<iostream>
#include<iomanip>
#include<cmath>
#include<string>
#include<cstring>
#include<vector>
#include<list>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<stack>
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define mp make_pair
#define rep(i, n) for(int i=0;i<n;++i)
#define rrep(i, n) for(int i=n;i>=0;--i)
const int inf=1e9+7;
const ll mod=1e9+7;
const ll mod1=998244353;
const ll big=1e18;
const double PI=2*asin(1);

int main() {
  int N, K;
  cin>>N>>K;
  vector<int> p(N);
  for(int i=0;i<N;++i) cin>>p[i];
  sort(p.begin(), p.end());
  int ans = 0;
  for(int i=0;i<K;++i) ans += p[i];
  cout<<ans<<endl;
}



Measured memory_bytes: 3628
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int a,b,c;
	cin>>a>>b>>c;
	int ans=b-a,gg=c-b;
	if(ans==gg)
	{
		cout<<"YES"<<endl;
	}
	else
	{
		cout<<"NO"<<endl;
	}
}

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

using namespace std;

struct Node{
    int parent;
    int left;
    int right;
};
struct Node T[100009];
int DepthList[100009];
int nil = -1;

int getDepth(int u){
    int depth = 0;
    while( T[u].parent != nil){
        u = T[u].parent;
        depth++;
    }
    return depth;
}

void setDepth(int u, int depth){
    DepthList[u] = depth;
    if(T[u].left != nil){
        setDepth(T[u].left, ++depth);
    }
    if(T[u].right != nil){
        setDepth(T[u].right, depth);
    }
}

void printChildlen(int u){
    int child = T[u].left;
    cout << "[";
    while(child != nil){
        cout << child;
        if(T[child].right != nil){
            cout << ", ";
        }
        child = T[child].right;
    }
    cout << "]";
}

string getType(int u){
    return getDepth(u) == 0 ? "root" : T[u].left == nil ? "leaf" : "internal node";
}

void printData(int u){
    cout << "node " << u << ": ";
    cout << "parent = " << T[u].parent << ", ";
    cout << "depth = " << getDepth(u) << ", ";
    cout << getType(u) << ", ";
    printChildlen(u);
    cout << endl;
}

int main(void){
    int n;
    cin >> n;
    int id, k;
    for(int i = 0; i < n; i++){
        T[i].parent = T[i].left = T[i].right = nil;
    }
    for(int i = 0; i < n; i++){
        cin >> id >> k;
        for(int j = 0; j < k; j++){
            int child, temp;
            cin >> child;
            if( j == 0) T[id].left = child;
            else T[temp].right = child;
            temp = child;
            T[temp].parent = id;
        }
    }
    for(int i = 0; i < n; i++){
        if(T[i].parent == nil){
            setDepth(i, 0);
            break;
        }
    }
    for(int i = 0; i < n; i++){
        printData(i);
    }
    return 0;
}


Measured memory_bytes: 4748
// #define _CRT_SECURE_NO_WARNINGS
// #define _USE_MATH_DEFINES
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <cmath>
#include <cstdlib>
#include <functional>
#include <locale>
#include <cctype>
#include <sstream>
#include <iomanip>	// 10????????? cout << setprecision(10) << double;
using namespace std;

typedef long long LL;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef map<int, int> MAPII;
typedef multimap<int, char, greater<int> > MuMAPIC;
typedef vector<pair<int, int> > VPII;
typedef multimap<int, string, greater<int> > MuMIS;

#define MP make_pair
#define FAST_IO  cin.tie(0); ios::sync_with_stdio(false);
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
//for gcc (???test)
// #define FOREACH_IT(it,c) for(typeof(c)::iterator it=(c).begin(); it!=(c).end(); ++it)
//for Visual Studio
#define foreach_it(type,it,c) for(type::iterator it=c.begin(),c_end=c.end();it!=c_end;++it)
// for Debug.
#define DUMP_VVI(b) FOR(i,0,b.size()){FOR(j,0,b[i].size())printf("%d ",b[i][j]);puts("");}
#define D_OUT(str,value) if(dbgF){cout<<str<<" : "<<value<<endl;}
// ??\??????push_back(d)???array[d]???????????????1?????§?????????
// int INPUT_INT() {int d;cin>>d;return d;}
template<class T>T IN(){T d;cin>>d;return d;}
// ?????§??¬?´???°???Greatest Common Divisor???
LL gcd(LL a, LL b){ return (b > 0) ? gcd(b, a%b) : a; }
// ????°???¬?????°???Least Common Multiple???
LL lcm(LL a, LL b){ return a / gcd(a, b) * b; }

// ------------------- include, typedef, define END. -------------------

int main(){
	FAST_IO;
	// for D_OUT(str, value)  ... cout<< str <<" : "<< value <<endl;
	bool dbgF = true;
	
	//??????????????????????????????.
	int t;
	while(cin>>t, t){
		int nowTime = 0;
		int n=0;
		cin >> n;
		FOR(i,0,n){
			int s=0,f=0;
			cin >> s >> f;
			nowTime += f-s;
		}
		if(t <= nowTime)
			cout << "OK" << endl;
		else
			cout << (t - nowTime) << endl;
	}
	
	return 0;
}

Measured memory_bytes: 1196
#include <cstdio>
using namespace std;
inline int rd()
{
	int x=0,p=1;
	char a=getchar();
	while((a<48||a>57)&&a!='-')a=getchar();
	if(a=='-')p=-p,a=getchar();
	while(a>47&&a<58)
	{
		x=(x<<1)+(x<<3)+(a&15);
		a=getchar();
	}
	return x*p;
}
int n;
int a[100002],b[100002];
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)scanf("%d",&a[i]),b[a[i]]=i;
	for(int i=1;i<=n;i++)printf("%d%c",b[i],i==n?'\n':' ');
	return 0;
}

Measured memory_bytes: 1536
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <cmath>
#include <deque>
using namespace std;

typedef pair<int, int> P;
#define rep(i, n) for (int i=0; i<(n); i++)
#define all(c) (c).begin(), (c).end()
#define _1 first
#define _2 second
#define pb push_back
#define INF 1145141919
#define MOD 1000000007

int N, K;
string S;
signed main() {
  ios::sync_with_stdio(false); cin.tie(0);
  cin >> N >> K;
  deque<bool> d;
  rep(i, N) {
    char c; cin >> c;
    d.push_back(c == 'A');
  }
  bool f = false;
  int mx = min(K, N*2 + (K%2));
  rep(i, mx) {
    if ((d.front() ^ f) == true) {
      d.pop_front();
      d.push_front(f);
    }
    else {
      d.pop_front();
      f ^= true;
      d.push_back(f ^ true);
    }
  }
  rep(i, N) cout << ((d[i]^f)?'A':'B'); cout << "\n";
  return 0;
}


Measured memory_bytes: 640
#include <iostream>

int main() {
    
    while (true) {
        int h, w = 0;
        std::cin >> h >> w;
        
        if (h == 0 && w == 0) {
            break;
        }
        
        int i = 0;
        int j = 0;
        
        for (i = 0; i < h; ++i) {
            for (j = 0; j < w; ++j) {
                std::cout << "#";
                if (j == w - 1) {
                    std::cout << "\n";
                }
            }
        }
        
        std::cout << std::endl;
    }
}



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

#define ll long long
#define nl '\n'
#define deb(x) cerr<<#x" = "<<x<<nl
#define in() ( { int a ; scanf("%d", &a); a; } )

const int N = 3e5 + 9;
const int mod = 1e9 + 7;

int s[10], id[10], a[10];
int32_t main()
{
    int n, m; cin >> n >> m;
    map<int, int > mp;
    for(int i = 0; i < m; i++){
        cin >> id[i] >> a[i];
        --id[i];
        s[id[i]] = a[i];
        mp[id[i]] = a[i];
    }
    if(mp.find(0) == mp.end() && n != 1) s[0] = 1;
    for(int i = 0; i < m; i++) if(s[id[i]] != a[i]) return cout << -1 << nl, 0;
    if(s[0] == 0 && n != 1) return cout << -1 << nl, 0;
    for(int i = 0; i < n; i++) cout << s[i];
    cout << nl;
    return 0;
}


Measured memory_bytes: 256
#include <cmath>
#include <iostream>
#include <vector>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <bitset>
#include <algorithm>
#include <functional>
#include <utility>
#include <iomanip>

#define int long long int
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() )

using namespace std;

typedef pair<int, int> P;

const int INF = 1e15;
const int MOD = 1e9+7;

template <typename T>
using vector2 = vector<vector<T>>;
template <typename T>
vector2<T> initVec2(size_t n0, size_t n1, T e = T()){
    return vector2<T>(n0, vector<T>(n1, e));
}

template <typename T>
using vector3 = vector<vector<vector<T>>>;
template <typename T>
vector3<T> initVec3(size_t n0, size_t n1, size_t n2, T e = T()){
    return vector3<T>(n0, vector2<T>(n1, vector<T>(n2, e)));
}

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

    int h, w, x, y;
    cin >> h >> w >> x >> y;

    if(h % x == 0 && w % y == 0){
        cout << "No" << endl;
        return 0;
    }

    int plus = ((h + x - 1) / x) * ((w + y - 1) / y);
    int minus = (h / x) * (w / y);
    int ans = 1;
    while(ans * plus <= (ans + 1) * minus){
        ans++;
    }

    cout << "Yes" << endl;
    rep(i, h){
        rep(j, w){
            if(i % x == 0 && j % y == 0){
                cout << ans << " ";
            }else if((i + 1) % x == 0 && (j + 1) % y == 0){
                cout << - ans - 1 << " ";
            }else{
                cout << 0 << " ";
            }
        }
        cout << endl;
    }

    return 0;
}


Measured memory_bytes: 1408