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

int main(){
  
  string str;
  int cnt[4]={0,0,0,0};
  cin>>str;
  for(int i=0;i<str.size();i++){
    if(str[i]>='a' && str[i]<='z') cnt[0]++;
    else if(str[i]>='A' && str[i]<='Z') cnt[1]++;
    else if(str[i]>='0' && str[i]<='9') cnt[2]++;
  }
  if(str.length()>=6) cnt[3]++;

  //  for(int i=0;i<4;i++)
  //cout<<cnt[]

  if(cnt[0]>0 && cnt[1]>0 && cnt[2]>0 && cnt[3]>0)
    cout<<"VALID"<<endl;
  else cout<<"INVALID"<<endl;
  return 0;
}

Measured memory_bytes: 1180
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60


def main():
    MOD = 1000000007
    N, *A = map(int, read().split())

    ans = 1
    C = [0, 0, 0]
    for a in A:
        try:
            ans = (ans * C.count(a)) % MOD
            C[C.index(a)] += 1
        except ValueError:
            print(0)
            return

    print(ans)
    return


if __name__ == '__main__':
    main()


Measured memory_bytes: 14044
N = int(input())
L = sorted([int(n) for n in input().split()])

ans = 0

for i in range(N):
    for j in range(i+1,N):
        for k in range(j+1,N):
            if L[i] != L[j] and L[j]!= L[k] and L[i] != L[k]:
                if L[k] < L[i] + L[j] and L[i] < L[k] + L[j] and L[j] < L[i] + L[k]:
                    ans += 1

print(ans)


Measured memory_bytes: 9200
#include<bits/stdc++.h>
using namespace std;
inline int_fast64_t read(){int_fast64_t x=0,f=1;char c=getchar();while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();}while(c>='0'&&c<='9')x=x*10+c-'0',c=getchar();return x*f;}
inline string read_s(){string s="";char c=getchar();while(c<'!'||c>'~'){c=getchar();}while(c>='!'&&c<='~'){s+=c;c=getchar();}return s;}
void Main(){
    int A = read(), P = read();
    printf("%d\n", (A*3+P)/2);
}
int main(){cin.tie(nullptr);ios::sync_with_stdio(false);Main();return 0;}

Measured memory_bytes: 256
#include <iostream>
#include <string>
using namespace std;
 
int main() { 
    int n, r = 0, b = 0;
    cin >> n;
    string s;
    cin >> s;
    for(int i = 0; i < n; ++i) {
        if(s[i] == 'R') {
            r++;
        } else {
            b++;
        }
    }
    if(r > b) {
        cout << "Yes" << '\n';
    } else {
        cout << "No" << '\n';
    }    
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
int main(){
	int N;
	cin >> N;
	vector<int> d(N);
	for(int i = 0; i < N; i++)
		cin >> d.at(i);
	sort(d.begin(), d.end()); 
	int count = d.at(N/2)-d.at(N/2-1);
	cout << count << endl;
}


Measured memory_bytes: 768
#include <algorithm>
#include <cstdio>
using namespace std;

int T, N, V[1010], W[1010];

int main() {

	for ( int t = 1; scanf( "%d", &T ) && T; t++ ) {
	
		scanf( "%d", &N );
	
		for ( int i = 0; i < N; i++ ) { scanf( "%d,%d", &V[i], &W[i] ); }
	
		int A[1010][1010] = {{0}};
	
		for ( int i = 1; i <= N; i++ ) {
		
			for ( int j = 0; j <= T; j++ ) {
	
				if ( j < W[i-1] ) {
	
					A[i][j] = A[i-1][j];
	
				} else {
	
					A[i][j] = max( A[i-1][j], A[i-1][j-W[i-1]] + V[i-1] );
					
				}
	
			}
	
		}
		
		/*for ( int i = 1; i <= N; i++ ) {
		
			printf( "i = %d\n", i );
		
			for ( int j = 0; j <= T; j++ ) {
			
				printf( "\tj = %d\t%d\n", j, A[i][j] );
			
			}
		
		}*/
		
		int best = -1, best_w = -1;
		
		for ( int j = 0; j <= T; j++ ) {
		
			if ( A[N][j] > best ) {
			
				best = A[N][j];
				best_w = j;
				
			}
		
		}
		
		printf( "Case %d:\n%d\n%d\n", t, best, best_w );
	
	}

}

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

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  
  int a, b, c;
  cin >> a >> b >> c;

  int cant = max(0, c - a - b - 1);
  cout << b + c - cant << '\n';
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		long MOD=1000000007;
		Scanner sc = new Scanner(System.in);
		char[] S=sc.next().toCharArray();
		int N=S.length;
		long a=0,b=0,c=0,z=1;
		for(int i=0;i<N;i++){
			switch(S[i]){
			case 'A': a+=z; break;
			case 'B': b+=a; break;
			case 'C': c+=b; break;
			case '?': c=3*c+b; b=3*b+a; a=3*a+z; z*=3; break;
			}
			if(a>=MOD) a%=MOD;
			if(b>=MOD) b%=MOD;
			if(c>=MOD) c%=MOD;
			if(z>=MOD) z%=MOD;
			
		}
		System.out.println(c);
	}
}


Measured memory_bytes: 25940
#include <iostream>
#include <cstdio>
#include <stack>
#include <vector>
#include <string>
#include <algorithm>
using namespace std;

int main() {
    int sum = 0;
    stack<int> S1;
    stack<pair<int, int> > S2;
    char input;
    for (int i = 0; scanf("%c", &input) != EOF; i++) {
        if (input == '\\') {
            S1.push(i); continue;
        }
        if (input == '/' && S1.size() > 0) {
            int j = S1.top(); S1.pop();
            sum += i - j;
            int a = i - j;
            while (S2.size() > 0 && S2.top().first > j) {
                a += S2.top().second; S2.pop();
            }
            S2.push(make_pair(j, a));
        }
    }
    
    vector<int> ans;
    cout << sum << endl;
    cout << S2.size();
    while (S2.size() > 0) {
        ans.push_back(S2.top().second); S2.pop();
    }
    reverse(ans.begin(), ans.end());
    for (int i = 0; i < ans.size(); i++) {
        cout << " " << ans[i];
    }
    cout << endl;
    // cout << input;
    return 0;
}


Measured memory_bytes: 3264
//libs

#include <bits/stdc++.h>

//other stuff

using namespace std;

//function call

//main

int main(){
	int n,g=0,s1=0,s2=0;
	cin >>n ;
	bool t=0;
	int a[n];
	for(int i=0;i<n;i++){
		cin >>a[i];
	}
	for(int i=0;i<n-1;i++){
		if(a[i]>a[i+1]){
			if(s2>0){
				s2=0;
				g++;
			}
			else{
				s1++;
			}
		}
		else if(a[i]<a[i+1]){
			if(s1>0){
				s1=0;
				g++;
			}
			else{
				s2++;
			}
		}
	}
	cout<< g+1 <<endl;
return 0;
}

//functions



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

using ll = long long;
using P = pair<ll, ll>;

const ll MOD = 998244353;
const ll INF = 1ll<<60;

#define FOR(i,a,b) for (ll i=(a);i<(ll)(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define DEBUG(x) ;
#define DEBUG(x) std::cerr << #x << " : " << (x) << std::endl;

int dx[4]{0, 1, 0, -1};
int dy[4]{1, 0, -1, 0};

ll dp[3020][3020]{};

int main(int argc, char **argv)
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	ll A, B, C, D; cin >> A >> B >> C >> D;
	for (ll h = A; h <= C; ++h)
	{
		for (ll w = B; w <= D; ++w)
		{
			if (h == A && w == B)
			{
				dp[h][w] = 1;
				continue;
			}

			ll &x = dp[h][w];
			(x += dp[h][w-1]*h) %= MOD;
			(x += dp[h-1][w]*w) %= MOD;
			x -= dp[h-1][w-1] * (w-1) * (h-1) % MOD;
			if (x < 0) x += MOD;
		}
	}
	std::cout << dp[C][D] << std::endl;
	return 0;
}


Measured memory_bytes: 74320
# -*- coding: utf-8 -*-


# 入力を整数に変換して受け取る
def input_int():
    return int(input())


# マイナス1した値を返却
def int1(x):
    return int(x) - 1


# 半角スペース区切り入力をIntに変換してMapで受け取る
def input_to_int_map():
    return map(int, input().split())


# 半角スペース区切り入力をIntに変換して受け取る
def input_to_int_tuple():
    return tuple(map(int, input().split()))


# 半角スペース区切り入力をIntに変換してマイナス1した値を受け取る
def input_to_int_tuple_minus1():
    return tuple(map(int1, input().split()))


def main():
    n, k = input_to_int_map()
    a_array = input_to_int_tuple()

    for k_val, pre_k_val in zip(a_array[k:], a_array[k - k:]):
        if k_val > pre_k_val:
            print("Yes")
        else:
            print("No")

if __name__ == "__main__":
    main()


Measured memory_bytes: 31952
import java.util.*;

public class Main {
    //-------------------------------------------------------------//
    public static final void main(String[] args) {
        new Main().solve();
    }
    //-------------------------------------------------------------//
    private final Scanner sc = new Scanner(System.in);

    void solve() {
        int N = sc.nextInt();
        boolean[] used = new boolean[8];
        int joker = 0;
        for (int i = 0; i < N; i++) {
            int a = sc.nextInt();
            if (a <= 399) {
                used[0] = true;
            } else if (a <= 799) {
                used[1] = true;
            } else if (a <= 1199) {
                used[2] = true;
            } else if (a <= 1599) {
                used[3] = true;
            } else if (a <= 1999) {
                used[4] = true;
            } else if (a <= 2399) {
                used[5] = true;
            } else if (a <= 2799) {
                used[6] = true;
            } else if (a <= 3199) {
                used[7] = true;
            } else {
                joker++;
            }
        }
        int ans = 0;
        for (int i = 0; i < 8; i++) if (used[i]) ans++;
        // min
        if (ans == 0) {
            if (joker > 0) System.out.println(1);
            else System.out.println(0);
        }
        else {
            System.out.println(ans);
        }
        // max
        System.out.println(ans + joker);
    }
}

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

using ll = long long;
using pii = pair<int, int>;

constexpr int INF = 1e9;
constexpr ll INFLL = 1e18;

void dfs(vector<vector<int>> const& g, int v, int p, vector<vector<int>>& dp) {
    int const d = g[v].size();
    if(d == 1) { // leaf
        dp[v][0] = 0;
        dp[v][1] = 1;
        return;
    }

    int sum = 0;
    for(auto to : g[v]) {
        if(to != p) {
            dfs(g, to, v, dp);
            sum += dp[to][1];
        }
    }
    if(sum >= INF) {
        cout << v << endl;
    }
    for(auto to : g[v]) {
        if(to != p) {
            if(d == 2) { // par and a child
                dp[v][0] = dp[to][0];
                dp[v][1] = dp[to][1];
            } else {
                dp[v][1] = min({dp[v][1], sum - dp[to][1] + dp[to][0], sum});
            }
        }
    }
}

int main() {
    int N; cin >> N;
    vector<vector<int>> g(N);
    for(int i = 0; i < N - 1; ++i) {
        int x, y; cin >> x >> y;
        g[x].push_back(y);
        g[y].push_back(x);
    }
    int r = -1;
    for(int i = 0; i < N; ++i) {
        if(g[i].size() >= 3) r = i;
    }
    if(r == -1) { // path
        cout << 1 << endl;
        return 0;
    }

    vector<vector<int>> dp(N, vector<int>(2, INF));
    dfs(g, r, -1, dp);
    cout << dp[r][1] << endl;
}

Measured memory_bytes: 16256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <tuple>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <cmath>
#include <iomanip>
#include <functional>
#define rep(i, n) for(int i = 0; i < (int)(n); ++i)
using namespace std;
using lint = int64_t;

int main() {
    int N;
    cin >> N;
    if (N == 0) {
        cout << 0 << "\n";
        return 0;
    }
    vector<int> ans;
    while (N) {
        if (N % 2 == 0) ans.push_back(0);
        else ans.push_back(1);
        if (N < 0) N = (-N + 1) / 2;
        else N = -(N / 2);
    }
    reverse(ans.begin(), ans.end());
    for (auto n : ans) cout << n;
    cout << "\n";
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <string>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <deque>
#include <numeric>
#include <bitset>
#include <iomanip>
#include <cassert>
#include <chrono>
#include <random>
#include <limits>
#include <iterator>
#include <functional>
#include <sstream>
#include <complex>
using namespace std;

typedef long long ll;
typedef uint64_t ull;
typedef pair<int, int> P;
constexpr double EPS = 1e-9;
constexpr int INF = 1001001001;
constexpr int mod = 1000000007;
// constexpr int mod = 998244353;

#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)

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

    int n, q;
    cin >> n >> q;
    vector<vector<int>> graph(n);
    for(int i = 0; i < n - 1; ++i){
        int a, b;
        cin >> a >> b;
        --a, --b;
        graph[a].emplace_back(b);
        graph[b].emplace_back(a);
    }
    vector<int> score(n, 0);
    for(int i = 0; i < q; ++i){
        int p, x;
        cin >> p >> x;
        --p;
        score[p] += x;
    }

    auto dfs = [&](auto&& self, int from = 0, int sum = 0, int p = -1) -> void {
        score[from] += sum;
        sum = score[from];
        for(int to : graph[from]){
            if(to == p) continue;
            self(self, to, sum, from);
        }
    };

    dfs(dfs);
    for(int i = 0; i < n; ++i){
        cout << score[i];
        cout << ((i == n - 1) ? '\n' : ' ');
    }
}

Measured memory_bytes: 19712
#include <bits/stdc++.h>
#define ll long long
#define MODV 1000000007
#define INFLL LLONG_MAX // 9223372036854775807
#define EPS 1e-9
#define rep(i, n) for(ll i=0, i##_len=(ll)(n); i<i##_len; i++)
#define repf(i, n) for(ll i=1, i##_len=(ll)(n+1); i<i##_len; i++)
#define all(v) v.begin(), v.end()
#define endl "\n"
#define vi vector<ll>
#define vvi vector<vector<ll>>
#define Yes() cout << "Yes" << endl
#define YES() cout << "YES" << endl
#define No() cout << "No" << endl
#define NO() cout << "NO" << endl
#define Init() std::ios::sync_with_stdio(false); std::cin.tie(0); std::cout<<fixed<<setprecision(15);
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; }
using namespace std;

// Aiに10e9を掛けて全て整数とする。（それらをBiとする。）
// 問題は「Bi*Bjが10e18の倍数である組の数」と考えることができる。
// 10e18の倍数であるということは、素因数分解したときの2及び5の肩がそれぞれ18以上である必要がある。

int main(){
    Init();
    ll n; cin >> n;
    vvi cnt(19, vi(19, 0));
    rep(i, n){
        long double a;
        cin >> a;
        ll iNum = llround(a*(1e9));
        
        ll d2 = 0, d5 = 0;
        while(iNum%2 == 0 && d2 < 18){
            d2++;
            iNum /= 2;
        }
        while(iNum%5 == 0 && d5 < 18){
            d5++;
            iNum /= 5;
        }
        cnt[d2][d5]++;
    }

    ll ans = 0;
    for(ll i2=0; i2<19; i2++){
        for(ll i5=0; i5<19; i5++){
            for(ll j2=0; j2<19; j2++){
                for(ll j5=0; j5<19; j5++){
                    // 足し合わせても乗数が18に満たないなら飛ばす
                    if(i2+j2 < 18 || i5+j5 < 18) continue;
                    // 自分を含む場所を見ている場合
                    if(i2 == j2 && i5 == j5) ans += cnt[i2][i5]*(cnt[i2][i5]-1);
                    // 違うならそのまま掛ける
                    else ans += cnt[i2][i5]*cnt[j2][j5];
                }
            }
        }
    }
    // 重複を除く
    cout << ans/2 << endl;
}

Measured memory_bytes: 3776
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**6)

N = int(input())
graph = [[] for _ in range(N+1)]
for _ in range(N-1):
    a, b = map(int, input().split())
    graph[a].append(b)
    graph[b].append(a)

s = -1
for n in range(N):
    if len(graph[n]) > 2:
        s = n
        break

checked = [False]*N


def dfs2(s):
    ans = 0
    S = [0]*N
    T = [0]*N
    # Req = [True]*N
    Ind = [0]*N
    stack = [s]
    while stack:
        p = stack[-1]
        if Ind[p] == len(graph[p]):
            ans += max(T[p] - S[p] - 1, 0)
            stack.pop()
            if stack:
                par = stack[-1]
                T[par] += 1
                if S[p] > 0 or T[p] > 1:
                    S[par] += 1
        elif len(stack) > 1 and stack[-2] == graph[p][Ind[p]]:
            Ind[p] += 1
        else:
            stack.append(graph[p][Ind[p]])
            Ind[p] += 1
    return ans


if s == -1:
    ans = 1
else:
    ans = dfs2(s)

print(ans)


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

 
int main () 
{
  int H,M,S,h,m,s,t;
  for(int i=0;i<3;i++)
  {
   cin >> H >> M >> S >> h >> m >> s;
   t=(h*3600+m*60+s)-(H*3600+M*60+S);
   cout << t/3600 << ' ' << (t%3600)/60 << ' ' << t%3600%60 << '\n';
  } 
   
  return 0;
}
 

Measured memory_bytes: 1160
n = gets.chop.to_i
 
a = []
 
n.times do
  u, k, *v = gets.chop.split.map(&:to_i)
  a << Array.new(n) { |i| (v.include?(i + 1)) ? 1 : 0 }
end
 
a.each { |i| puts i.join(' ') }

Measured memory_bytes: 6152
#include<iostream>
#include<algorithm>
#include<string>
#include<math.h>
#include<vector>
//#include <bits/stdc++.h>
#include<cstring>
#include<iostream>
using namespace std;
int main() {
	int X;
	cin >> X;
	int mx = 0;
	if (X == 1) {
		cout << X << endl;
		//cin >> X;
		return 0;
	}
		
	for (int i = 2; i <= X; i++) 
		for (int j = 2; j <= X; j++) {
			//cout << i << " " << j << " " << pow(i, j) << endl;
			if (pow(i, j) == X) {
				//cout << "i j " << i << " " << j << " " << X << endl;
				mx = X;
				break;
			}
			else if (pow(i, j) > X && j == 2) {
				//mx = max(mx, (int)pow(i, j - 1));
				//cout << "i j " << i << " " << j - 1 << " " << (int)pow(i, j - 1) << " max " << mx << endl;
				break;
			}
			else if (pow(i,j) > X && j >=3) {
				mx = max(mx, (int)pow(i, j - 1));				
				//cout << "i j " << i << " " << j-1 << " " << (int)pow(i, j - 1) << " max " << mx << endl;
				break;
			}
		}
	cout << mx << endl;
	//cin >> X;
	return 0;
}

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

#define rep(i,a,b) for(int i=a;i<b;i++)
#define int long long
const int inf = 100100100100100009;
const int mod = 1000000007;

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

    int n; cin >> n;
    int arr[n]; rep(i,0,n) cin >> arr[i];

    int buff = 0;
    int left = 0;
    int right = 0;
    int ans = 0;

    while(left < n){

        if(right < n && (buff ^ arr[right]) == buff + arr[right]){
            buff += arr[right];
            right++;
            
        }else{
            ans += right - left;
            buff -= arr[left];
            left++;
        }
    }
    
    cout << ans << endl;
    
}   

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

template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b)a=b;};
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b)a=b;};

Int n;
Int ls[11],rs[11],us[11],ds[11];
vector<Int> ans;

Int used[11];
void dfs(Int bit){
  //cout<<bit<<endl;
  while(bit){
    Int idx=-1;
    for(Int i=0;i<n;i++){
      if((~bit>>i)&1) continue;
      if(idx<0) idx=i;
      if(rs[idx]>rs[i]){
        idx=i;
        continue;
      }
      if(rs[idx]==rs[i]){
        if(us[idx]>us[i]){
          idx=i;
        }
      }
    }
    //cout<<idx<<endl;
    bit^=1<<idx;
    used[idx]=1;
    ans.emplace_back(idx);

    Int lft=10000;
    Int rgh=rs[idx];
    Int top=ds[idx];
    for(Int i=0;i<n;i++){
      if(rs[i]>=ls[idx])
        if(us[i]<top&&top<ds[i])
          chmin(lft,rs[i]);
    }

    Int nxt=0;
    for(Int i=0;i<n;i++){
      if(used[i]) continue;
      if((~bit>>i)&1) continue;
      //cout<<i<<":"<<ds[i]<<" "<<ls[i]<<" "<<rs[i]<<endl;
      if(ds[i]<=top&&lft>=ls[i]&&rs[i]>=rgh) nxt|=1<<i;
    }
    //cout<<bit<<" "<<nxt<<":"<<idx<<":"<<lft<<" "<<rgh<<" "<<top<<endl;
    dfs(nxt);
    bit&=~nxt;
  }
}
signed main(){
  cin.tie(0);
  ios::sync_with_stdio(0);

  Int first=1;
  while(cin>>n,n){
    if(!first) cout<<endl;
    first=0;

    for(Int i=0;i<n;i++){
      Int x1,y1,x2,y2;
      cin>>x1>>y1>>x2>>y2;
      ls[i]=max(x1,x2);
      rs[i]=min(x1,x2);
      us[i]=min(y1,y2);
      ds[i]=max(y1,y2);
    }
    memset(used,0,sizeof(used));
    ans.clear();
    Int bit=(1<<n)-1;
    dfs(bit);
    vector<Int> ord(n);
    for(Int i=0;i<n;i++) ord[ans[i]]=i+1;
    for(Int i=0;i<n;i++) cout<<ord[i]<<endl;
  }
  return 0;
}



Measured memory_bytes: 3172
N, X = map(int, input().split())
L = [x for x in map(int, input().split())]
D = [0]*(N+1)
for i in range(N+1):
  if i == 0:
    D[i] = 0
  else:
    D[i] = D[i-1] + L[i-1]
ans = [x for x in D if x <= X]
print(len(ans))



Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1};
using pii = pair<int, int>;
int main() {
  string s;
  int k;
  cin >> s >> k;

  string ans = "";

  const char ch = '{';

  for (int i = 0; i < s.size(); i++) {
    if (s[i] == 'a' && i != s.size() - 1) {
      ans += 'a';
    } else if (ch - s[i] <= k && i != s.size() - 1) {
      ans += 'a';
      k -= (ch - s[i]);
    } else {
      if (i != s.size() - 1)
        ans += s[i];
      else {
        // cout << "fejoofewij" << endl;
        // cout << k << endl;
        ans += (s[i] + k % 26) > 'z' ? s[i] + k % 26 - 'z' + 'a' - 1
                                     : s[i] + k % 26;
      }
    }
  }
  cout << ans << endl;

  // cout << k << endl;
}

Measured memory_bytes: 3740
#include <iostream>
#include <algorithm>
#include <vector>
#include <tuple>
#include <set>

using namespace std;

typedef long long ll;
typedef pair <int, int> pii;
typedef tuple <int, int, int> piii;
typedef vector <int> vi;
typedef vector <pii> vpii;
typedef vector <piii> vpiii;

struct UF {
    vi v;
    UF(int n) : v(n, -1) {}
    int root(int i) { return (v[i] < 0 ? i : v[i] = root(v[i])); }
    bool in(int i, int j) { return (root(i) == root(j)); }
    void merge(int i, int j) {
        if((i = root(i)) == (j = root(j))) return ;
        if(v[i] < v[j]) swap(i, j);
        v[i] += v[j];
        v[j] = i;
        
        return ;
    }
};

piii A[100000];
int B[100000];

int main() {
    int n; cin >> n;
    UF uf(n);
    int u, v;
    for(int i = 0; i < n; ++i) {
        cin >> u >> v;
        A[i] = piii(u, v, i); 
    }
    
    sort(A, A + n);
    for(int i = 1; i < n; ++i) {
        int l, g, f, k;
        tie(u, v, k) = A[i];
        tie(l, f, g) = A[i - 1];
        if(l == u) uf.merge(k, g);
    }
    
    sort(A, A + n, [](piii& r, piii& t) -> bool {
        int u, v, h, l, g, f;
        tie(u, v, h) = r;
        tie(l, g, f) = t;
        return v < g;
    });
    
    for(int i = 1; i < n; ++i) {
        int l, g, f, k;
        tie(u, v, k) = A[i];
        tie(l, f, g) = A[i - 1];
        if(v == f) uf.merge(k, g);
    }
    
    set <int> xA[100000], yA[100000];
    
    for(int i = 0; i < n; ++i) {
        int h;
        tie(u, v, h) = A[i];
        xA[uf.root(h)].insert(u);
        yA[uf.root(h)].insert(v);
        B[uf.root(h)] += 1;
    }
    
    ll mx = 0;
    for(int i = 0; i < n; ++i) {
      	ll nx = (ll) xA[i].size() * yA[i].size();
      	nx -= B[i];
        mx += max(nx, 0LL);
    }
  
    cout << mx;
    
    return 0;
}

Measured memory_bytes: 16000
#include<iostream>
#include<string>
#include<vector>
#include<utility>
#include<queue>
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<map>
#include<complex>
#define INF 2147483647
#define llINF 9223372036854775807
#define pb push_back
#define mp make_pair 
#define F first
#define S second
#define ll long long

using namespace std;
int main(){
  int n;
  while(cin>>n,n){
    int ma=0;
    int time_table[30][65][65]={};
    for(int i=0;i<n;i++){
      int a,b,c;
      scanf("%d:%d:%d",&a,&b,&c);
      time_table[a][b][c]++;
      scanf("%d:%d:%d",&a,&b,&c);
      time_table[a][b][c]--;
    }
    int cnt=0;
    for(int i=0;i<=24;i++){
      for(int j=0;j<=60;j++){
	for(int k=0;k<=60;k++){
	  cnt+=time_table[i][j][k];
	  ma=max(ma,cnt);
	}
      }
    }
    cout<<ma<<endl;
  }
  return 0;
}



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


int main() {

    int n;
    cin>>n;
    
    string s;
    cin>>s;


    //全部黒か、全部白か、前半白で後半黒か、その小さい方
    vector<int> white_cnt(n,0);
    vector<int> black_cnt(n,0);
    int white=0,black=0;
    for(int i=0;i<n;i++){
        if(s.at(i)=='#')
            white++;

        if(s.at(n-1-i)=='.')
            black++;

        white_cnt.at(i)=white;
        black_cnt.at(n-1-i)=black;
    }


    int min_wk=s.size();
    for(int i=0;i<n-1;i++){
        min_wk=min(min_wk,white_cnt.at(i)+black_cnt.at(i+1));
    }

    cout<<min(min_wk,min(black,white))<<endl;

    return 0;
}

Measured memory_bytes: 2180
#include <cstdio>
#include <vector>

using namespace std;

vector <int> inv(const vector <int> &v) {
    int i;
    vector <int> iv(v.size());
    
    for (i = 0; i < v.size(); i++) iv[v[i]] = i;
    
    return iv;
}

vector <int> mul(const vector <int> &v, const vector <int> &w) {
    int i;
    vector <int> z;
    
    for (i = 0; i < v.size(); i++) z.push_back(v[w[i]]);
    
    return z;
}

vector <int> pow(const vector <int> &v, int n) {
    int i;
    vector <int> w = v, z;
    
    for (i = 0; i < v.size(); i++) z.push_back(i);
    
    while (n > 0) {
        if (n & 1) z = mul(z, w);
        w = mul(w, w);
        n >>= 1;
    }
    
    return z;
}

int main() {
    int n, k, i;
    vector <int> p, q, ip, iq, v, a, b, ans;
    
    scanf("%d %d", &n, &k);
    
    for (i = 0; i < n; i++) {
        int x;
        scanf("%d", &x);
        p.push_back(x - 1);
    }
    
    for (i = 0; i < n; i++) {
        int x;
        scanf("%d", &x);
        q.push_back(x - 1);
    }
    
    ip = inv(p);
    iq = inv(q);
    
    v = pow(mul(q, mul(ip, mul(iq, p))), (k - 1) / 6);
    
    if (k % 6 == 1) {
        a = v;
        b = p;
    } else if (k % 6 == 2) {
        a = v;
        b = q;
    } else if (k % 6 == 3) {
        a = v;
        b = mul(q, ip);
    } else if (k % 6 == 4) {
        a = mul(v, q);
        b = ip;
    } else if (k % 6 == 5) {
        a = mul(v, mul(q, ip));
        b = iq;
    } else {
        a = mul(v, mul(q, ip));
        b = mul(iq, p);
    }
    
    ans = mul(a, mul(b, inv(a)));
    
    for (i = 0; i < v.size(); i++) {
        if (i > 0) putchar(' ');
        printf("%d", ans[i] + 1);
    }
    puts("");
    
    return 0;
}


Measured memory_bytes: 5288
from collections import Counter
from string import ascii_lowercase
n = int(input())
s = {ai:float("INF") for ai in ascii_lowercase}

for i in range(n):
    si = input()
    c = Counter(si)
    for k in ascii_lowercase:
        s[k] = min(s[k],c[k])

ans = ""
for key in ascii_lowercase:
    ans += key*s[key]
print(ans)

Measured memory_bytes: 9860
#include <iostream>
#include <vector>
#include<algorithm>
using namespace std;

int main(int argc, const char * argv[]) {
    int n, l;
    string s;
    vector<string> v;
    
    cin >> n >> l;
    for (int i=0; i<n; i++) {
        cin >> s;
        v.push_back(s);
    }
    
    sort(v.begin(), v.end());
    for (int i=0; i<n; i++) {
        cout << v[i];
    }
    cout << endl;
    
    return 0;
}

Measured memory_bytes: 256
N=int(input())
A=list(map(int,input().split()))
A.sort()

i=N-1
ans=1
count=0
while i>=1:
    if A[i-1]==A[i]:
        ans*=A[i]
        i-=2
        count+=1
    else:
        i-=1
    if count==2:
        print(ans)
        break
else:
    print(0)


Measured memory_bytes: 20052
#include<iostream>
#include<string>
using namespace std;
int main(){
	int N,Y,x=0,y=0,z=0,sum=0,max=0;
	cin>>N>>Y;
	for(int i=0;i<=N;i++){
		z=i;
		sum=Y-1000*z;
		max=10000*(N-z);
		x=N-z;
		y=0;
		while(max>=sum&&x>=0){
			if(max==sum){
				cout<<x<<" "<<y<<" "<<z;
				return 0;
			}
			max=max-5000;
			y++;
			x=x-1;
		}
	}
	cout<<-1<<" "<<-1<<" "<<-1;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <numeric>
using namespace std;

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

int main() {
    vector<int> primes;
    int n = 2;
    while (primes.size() < 55) {
        while (n % 5 != 1 or !isPrime(n)) {
            n++;
        }
        primes.push_back(n++);
    }

    int N;
    cin >> N;
    for (int i = 0; i < N; i++) {
        cout << primes[i] << " ";
    }
    cout << endl;

    return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#define ll long long
const int M=205,N=5005;
int n,m,i,j,v[M][N],t[M],q[M][N];
ll a[N],sum,f[N],ans;
int read(){
	char c=getchar();int k=0;for (;c<48||c>57;c=getchar());
	for (;c>47&&c<58;c=getchar()) k=(k<<3)+(k<<1)+c-48;return k;
}
void gmax(ll &x,ll k){if (k>x) x=k;}
int main(){
	n=read();m=read();
	for (i=2;i<=n;i++) a[i]=a[i-1]+read();
	for (i=1;i<=n;i++){
		for (j=1;j<=m;j++){
			int k=read();
			for (;t[j]&&k>v[j][t[j]];t[j]--)
				f[q[j][t[j]]]-=v[j][t[j]],
				f[q[j][t[j]-1]]+=v[j][t[j]];
			f[i]+=k;f[q[j][t[j]]]-=k;
			q[j][++t[j]]=i;v[j][t[j]]=k;
		}
		for (j=i,sum=0;j;j--) sum+=f[j],
			gmax(ans,sum-a[i]+a[j]);
	}
	printf("%lld",ans);
}

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

#define ran 202202

struct modular_arithmetic{
	int mod;

	modular_arithmetic(){
		mod = 1000000007;
	}
	//No specific settings.
	int add(int x,int y){return (x+=y)<mod?x:x-mod;}
	int sub(int x,int y){return (x-=y)>=0?x:x+mod;}
	int mul(int x,int y){return (int)((long long int)x*y%mod);}
	int pw(int base, int p) {
		int res = 1, mu = base%mod;
		for(;p>0;p/=2) {
			if (p&1) res = mul(res, mu);
			mu = mul(mu, mu);
		}
		return res;
	}
	int rev(int x) {return pw(x, mod-2);}
};
modular_arithmetic ma;

int n;
vector<int> e[ran];
int cnt[ran];
int ans;

void dfs(int cur, int par) {
	cnt[cur] = 1;
	for(int i=0;i<(int)e[cur].size();i++) {
		int nxt = e[cur][i];
		if(nxt==par) continue;
		
		dfs(nxt, cur);
		cnt[cur] += cnt[nxt];
		ans = ma.sub(ans, ma.pw(2, cnt[nxt]));
		ans = ma.add(ans, 1);
	}
	ans = ma.sub(ans, ma.pw(2, n - cnt[cur]));
	ans = ma.add(ans, 1);
	
	ans = ma.add(ans, ma.pw(2, n-1));
	ans = ma.sub(ans, 1);
}

int main() {
	scanf("%d", &n);
	for(int i=1;i<n;i++) {
		int x, y;
		scanf("%d%d", &x, &y);
		e[x].push_back(y);
		e[y].push_back(x);
	}
	
	ans = 0;
	dfs(1, -1);
	ans = ma.mul(ans, ma.rev(ma.pw(2, n)));
	
	printf("%d\n", ans);
	
	return 0;
}

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

int main() {
    int n, minv, maxv;
    int R[200000];
    
    cin >> n;
    
    for (int i = 0; i < n; i++) {
        cin >> R[i];
    }
    
    minv = R[0];
    maxv = R[1] - minv;
    for (int j = 1; j < n; j++) {
        if (maxv < R[j] - minv) maxv = R[j] - minv;
        if (minv > R[j]) minv = R[j];
    }
    
    cout << maxv << endl;
    
    return 0;
}



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

#define int long long

signed main(){
    int n, k;
    cin >> n >> k;
    int a[100010];
    int sei[100010] = {};
    int wa[100010] = {};

    for(int i = 0;i < n;i++){
        cin >> a[i];
        wa[i+1] = wa[i] + a[i];
        if(a[i] > 0){
            sei[i+1] = a[i];
        }
        sei[i+1] += sei[i];
    }

    int ans = LLONG_MIN;

    for(int i = 0;i <= n-k;i++){
        int a1 = sei[i]+wa[i+k]-wa[i]+sei[n]-sei[i+k];
        int a2 = sei[n]-sei[i+k]+sei[i];
        ans = max(ans, max(a1, a2));
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 2560
#include <iostream>
#include <cmath>
#include <string>

using namespace std;

int main(){
	int n;
	cin >> n;
	int a[n];

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

	sort(a, a+n);
	cout << a[n/2] - a[n/2-1] << endl;
	return 0;
}

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

int main()
{
    int n;
    cin >> n;
    vector<int> A(n);
    rep(i, n)
    {
        int a;
        cin >> a;
        A[i] = a - (i + 1);
    }

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

    int med;
    if (n % 2 == 0)
        med = round((A[n / 2] + A[n / 2 - 1]) / 2.0);
    else
        med = A[n / 2];

    ll ans = 0;
    rep(i, n)
    {
        ans += abs(A[i] - med);
    }

    cout << ans << endl;
}

Measured memory_bytes: 1024
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sstream>
#include <iostream>
#include <math.h>
#include <time.h>
#include <unistd.h>
#include <algorithm>
#include <map>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <set>
#include <string>

#ifndef ONLINE_JUDGE
	#define DEBUG(x) cout << '>' << #x << ':' << x << endl;
#else
	#define DEBUG(x) do {} while(0);
#endif

#define pb push_back
#define mp make_pair
#define X first
#define Y second
#define FOR(i, A, N) for(int (i) = (A); (i) < (N); (i)++)
#define REP(i, N) for(int (i) = 0; (i) < (N); (i)++)

using namespace std;
typedef long long ll;
inline bool EQ(double a, double b) { return fabs(a-b) < 1e-9; }

int n,m,k;
int main() {
	scanf("%d%d%d", &n, &m, &k);
	for(int R = 0; R <= n; R++) {
		// zmacknul sem R radku, tj. mam ted R*M cernych poli
		int black  = R*m; // za radky
		for(int C = 0; C <= m; C++) {
			// ted jsem domackl C sloupcu, kazdym zmacknutim odstranim R cernych
			if(black == k) {
				printf("Yes\n");
				return 0;
			}
			black += n-R-R;
		}
		if(black == k) {
			printf("Yes\n");
			return 0;
		}
	}
	printf("No\n");
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#define rep(i, n) for(int i = 0; i < (n); ++i)
using namespace std;

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

  int a, b, c; cin >> a >> b >> c;
  int sum = a+b+c;
  int tmp = 2*max({a, b, c}) - (sum-max({a, b, c}));

  int ans;
  if(tmp%2 == 0) ans = tmp/2;
  else ans = tmp/2 + 2;

  cout << ans << '\n';
  return 0;
}


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

using namespace std;

int main()
{
    long long int i,n,s,p,j,v[110];

    scanf("%lld",&n);

        s=0;
        for(i=0;i<n;i++)
    {
        scanf("%lld",&v[i]);

    }
    for( i=0;i<n-1;i++)
        for( j=n-1;j>=i+1;j--)
           if(v[j]<v[j-1])
           {
           swap(v[j],v[j-1]);
            s++;
           }
    for(i=0;i<n;i++)
    {
        printf("%lld",v[i]);
        if(i!=n-1)
            printf(" ");
    }
    printf("\n");

    cout<<s<<endl;


    return 0;
}

Measured memory_bytes: 3212
// 解き直し.
// https://img.atcoder.jp/abc169/editorial.pdf
// C++(GCC 9.2.1)
#include <bits/stdc++.h>
using namespace std;
using LL = long long;
#define repex(i, a, b, c) for(int i = a; i < b; i += c)
#define repx(i, a, b) repex(i, a, b, 1)
#define rep(i, n) repx(i, 0, n)
#define repr(i, a, b) for(int i = a; i >= b; i--)
const LL MOD = 998244353;
LL dp[3030][3030], a[3030], memo[3030], mPow2[3030];

int main(){
    
    // 1. 入力情報.
    int N, S;
    scanf("%d %d", &N, &S);
    rep(i, N) scanf("%lld", &a[i]);
    
    // 2. 2 の べき乗 を 保存.
    mPow2[0] = 1;
    repx(i, 1, 3030) mPow2[i] = mPow2[i - 1] * 2, mPow2[i] %= MOD;
    
    // 2. dp更新.
    repx(i, 1, N + 1){
        repr(j, S, 0){
            int d = j - (int)a[i - 1];
            if(d > 0 && memo[d]) dp[i][j] += dp[i - 1][d], dp[i][j] %= MOD, memo[j]++;
            if(d == 0)           dp[i][j] += mPow2[i - 1], memo[j]++;
            dp[i][j] += dp[i - 1][j] * 2;
            dp[i][j] %= MOD;
        }
    }
    // rep(i, N + 1){
    //     rep(j, S + 1) printf("%lld ", dp[i][j]);
    //     puts("");
    // }
    
    // 3. 出力.
    printf("%lld\n", dp[N][S]);
    return 0;
    
}

Measured memory_bytes: 74852
#include <set>
#include <map>
#include <list>
#include <cmath>
#include <ctime>
#include <deque>
#include <queue>
#include <stack>
#include <cctype>
#include <cstdio>
#include <string>
#include <vector>
#include <cassert>
#include <cstdlib>
#include <cstring>
#include <sstream>
#include <iostream>
#include <algorithm>

using namespace std;
int x,y,z,k,s;
int ans;
int main()
{
    scanf("%d%d",&k,&s);
    ans=0;
    for (x=0;x<=k;++x)
        for (y=0;y<=k;++y)
        {
            z=s-x-y;
            if (z<=k&&z>=0) ans++;
        }
    printf("%d\n",ans);
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <vector>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <utility>
#include <map>
#include <list>
#include <climits>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>
#include <bitset>
#include <string>

// #define cerr if(false)cerr
#define watch(x) cerr << "> " << #x << ": " << x << "\n";

using namespace std;

template <typename T>
std::ostream &operator <<(std::ostream &out, vector<T> &v) {
	for (typename vector<T>::size_type i = 0; i < v.size(); ++i)
		out << v[i] << " ";
	out << "\n";
    return out;
}
template <typename T, typename N>
std::ostream &operator <<(std::ostream &out, vector<pair<T, N> > &v) {
	for (size_t i = 0; i < v.size(); ++i)
		out << "(" << v[i].first << ", " << v[i].second << ") ";
	out << "\n";
    return out;
}
template <typename T>
std::ostream &operator <<(std::ostream &out, vector<vector<T> > &v) {
	for (size_t i = 0; i < v.size(); ++i) {
		for (size_t j = 0; j < v[i].size(); ++j) {
			out << v[i][j] << " ";
		}
		out << "\n";
	}
   	return out;
}

int main() {

	std::ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);

	int n;
	cin >> n;

	int a, b;
	int c = 0;
	for (int i = 0; i < n; ++i) {
		cin >> a >> b;
		if (a == b) {
			++c;
		} else {
			c = 0;
		}

		if (c == 3) {
			cout << "Yes\n";
			return 0;
		}
	}

	cout << "No\n";

	return 0;

}

Measured memory_bytes: 3612
#include <iostream>
#include <fstream>
#include <vector>
#include <set>
#include <map>
#include <cstring>
#include <string>
#include <cmath>
#include <cassert>
#include <ctime>
#include <algorithm>
#include <sstream>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <cstdlib>
#include <cstdio>
#include <iterator>
#include <functional>
#include <bitset>

#ifdef LOCAL
#define eprintf(...) fprintf(stderr,__VA_ARGS__)
clock_t __my_start_clock = clock();
#else
#define eprintf(...)
#endif

#define TIMESTAMP(x) eprintf("["#x"] Time : %.3lf s.\n", (clock() - __my_start_clock)*1.0/CLOCKS_PER_SEC)
#define TIMESTAMPf(x,...) eprintf("[" x "] Time : %.3lf s.\n", __VA_ARGS__, (clock() - __my_start_clock)*1.0/CLOCKS_PER_SEC)

using namespace std;

#ifdef LOCAL
static struct __timestamper {
  string what;
  __timestamper(const char* what) : what(what){};
  __timestamper(const string& what) : what(what){};
  ~__timestamper(){
    TIMESTAMPf("%s", what.data());
	}
} __TIMESTAMPER("end");
#else 
struct __timestamper {};
#endif

typedef long long ll;
typedef long double ld;

void solve() {
  ll n;
  ll a, b, c, d;
  scanf("%lld%lld%lld%lld%lld", &n, &a, &b, &c, &d);
  set<pair<ll, ll>> s;
  map<ll, ll> cost;
  auto add = [&](ll val, ll c) {
    if (!cost.count(val) || cost[val] > c) {
      s.erase({cost[val], val});
      cost[val] = c;
      s.insert({cost[val], val});
    }
  };
  auto down = [](ll x, ll m) {
    return x / m * m;
  };
  auto up = [&](ll x, ll m) {
    return down(x + m - 1, m);
  };
  add(n, 0);
  while (!s.empty()) {
    auto [cost, val] = *s.begin();
    s.erase(s.begin());
    eprintf("%lld %lld\n", cost, val);
    if (0 < val && val < 10) {
      add(val - 1, cost + d);
    }
    if (val < numeric_limits<ll>::max() / d / 2) {
      add(0, cost + val * d);
    }
    add(up(val, 2) / 2, cost + a + (up(val, 2) - val) * d);
    add(up(val, 3) / 3, cost + b + (up(val, 3) - val) * d);
    add(up(val, 5) / 5, cost + c + (up(val, 5) - val) * d);
    add(down(val, 2) / 2, cost + a + (val - down(val, 2)) * d);
    add(down(val, 3) / 3, cost + b + (val - down(val, 3)) * d);
    add(down(val, 5) / 5, cost + c + (val - down(val, 5)) * d);
  }
  printf("%lld\n", cost[0]);
}

int main() {
#ifdef LOCAL
  freopen("a.in", "r", stdin);
  freopen("a.out", "w", stdout);
#endif

  int t;
  scanf("%d", &t);
  while (t-->0) solve();

  return 0;
}


Measured memory_bytes: 4524
#include <iostream>
#include <vector>
#include <string>
#include <cstdlib>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <stack>
#include <math.h>
#define rep(i, n) for(int i = 0; i < (n); ++i)
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;}
const long long INF = 1LL << 60;

// --------write my code!!!!!----------//

int main(){
    int A; cin >> A;
    int B[A*2];
    rep(i,A*2) cin >> B[i];
    sort(B,B+A*2);
    int res=0;
    for(int i=0; i<A*2; i+=2){
        res+=B[i];
    }
    cout << res << endl;
}


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

using ll = long long;
using pii = pair<ll, ll>;
using vi = vector<ll>;
using vvi = vector<vi>;

template <class T>
using max_heap = priority_queue<T>;
template <class T>
using min_heap = priority_queue<T, vector<T>, greater<T>>;

template <class T, class U>
void chmax(T &a, U b) {
    if (a < b) a = b;
}
template <class T, class U>
void chmin(T &a, U b) {
    if (b < a) a = b;
}

#define rep(i, j, k) for (int i = j; i < k; i++)
#define all(obj) (obj).begin(), (obj).end()
#define rall(obj) (obj).rbegin(), (obj).rend()
#define debug(x) cerr << #x << ": " << x << endl;
#define debug2(x, y) cerr << #x << ": " << x << ", " << #y << ": " << y << endl;
#define int ll

const ll mod = 1e9 + 7;
const ll inf = (1LL << 60);

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.precision(10);
    cout << fixed;

    int N, M;
    cin >> N >> M;

    int sum = 0;
    rep(i, 0, M) {
        int a;
        cin >> a;
        sum += a;
    }

    if (sum > N) {
        cout << -1 << endl;
    } else {
        cout << N - sum << endl;
    }
    return 0;
}


Measured memory_bytes: 3644
# include <bits/stdc++.h>
  typedef long long ll;
#define pii  pair<int,int>
#define vpii vector<pii>
#define vll  vector<ll>
#define vi  vector<int>
#define pb push_back
#define f  first
#define s  second
#define all v.begin(),v.end()
#define fio ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
typedef unsigned long long ulll;
 
using namespace std ;
int main () {

   int a,b;
   cin>>a>>b;
   
   if(a+b<=23)
     cout<<a+b;
     
     else
     cout<<(a+b)-24;
   
  return 0;
}

Measured memory_bytes: 384
def main():
    N = int(input())
    S = [str(i) for i in input()]

    white = []
    black = []

    # 黒を数える
    black_num = 0
    for s in S:
        black.append(black_num)
        if s == "#":
            black_num += 1
    black.append(black_num)

    # 白を数える
    S.reverse()
    white_num = 0
    for s in S:
        white.append(white_num)
        if s == ".":
            white_num += 1
    white.append(white_num)
    white.reverse()

    min_num = N
    for i in range(N + 1):
        temp_sum = white[i] + black[i]
        if min_num > temp_sum:
            min_num = temp_sum

    print(min_num)


if __name__ == '__main__':
    main()


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

vector<string> dfs(map<string, int> mp, vector<string> v, int i, int N){
    if (i == 0) {
        v.push_back("a");
        mp["a"] = 1;
        return dfs(mp, v, i+1, N);
    } else {
        vector<string> ans, res;
        if (i == N) return v;
        for (int j = 0; j <= i; j++) {
            string p{static_cast<char>('a' + j - 1)}, s{static_cast<char>('a' + j)};
            if (j > 0 && !mp.count(p)) {
                continue;
            }
            map<string, int> tmpM = mp;
            tmpM[s] = 1;
            vector<string> tmpV = v;
            for (int k = 0; k < tmpV.size(); k++) {
                tmpV[k] += static_cast<char>('a' + j);
            }
            res = dfs(tmpM, tmpV, i+1, N);
            ans.insert(ans.end(), res.begin(), res.end());
        }
        return ans;
    }
}

int main(){
    int N;
    map<string, int> mp;
    vector<string> v;
    cin >> N;
    vector<string> ans = dfs(mp, v, 0, N);
    for (auto v : ans) {
        cout << v << endl;
    }
    return 0;
}


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

int main() {
    int r;
    double pi = 3.14159265358979323846;
    cin >> r;
    double ans = r * 2 * pi;
    cout << ans << endl;
}


Measured memory_bytes: 3776
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define rep2(i, s, n) for (ll i = (s); i < (ll)(n); i++)
#define repd(i, n) for (ll i = (ll)(n)-1; i >= 0; i--)
const ll INF = 1LL << 60;
const int INF32 = 1 << 29;
const ll MOD = 1000000007;
using Graph = vector<vector<int>>; // グラフ型
using pint = pair<int, int>;

int main()
{
    string S;
    cin >> S;
    ll ans = 0;
    ll tmp = 0;
    rep(i, 1 << (S.size() - 1))
    {
        tmp = S[0] - '0';
        rep(j, S.size() - 1)
        {
            if (i & (1 << j))
            {
                ans += tmp;
                tmp = 0;
            }
            tmp = tmp * 10 + (S[j + 1] - '0');
        }
        ans += tmp;
    }
    cout << ans << endl;
}

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

struct edge{ int to,cost; };

int d[20];
vector<edge> vec[20];

void dfs(int v,int prev){
	for(int i = 0;i < vec[v].size();i++){
		edge e = vec[v][i];
		if(e.to == prev) continue;
		d[e.to] = d[v] + e.cost;
		dfs(e.to,v);
	}
}

int main(){
	int n;
	while(cin >> n,n){
		for(int i = 0;i < 20;i++) vec[i].clear();
		int ans = 0;
		for(int i = 0;i < n - 1;i++){
			int a,b,t;
			cin >> a >> b >> t; a--;b--;
			vec[a].push_back({b,t});
			vec[b].push_back({a,t});
			ans += t;
		}
		d[0] = 0;
		dfs(0,-1);
		int ma = 0;
		for(int i = 0;i < n;i++){
			if(vec[i].size() == 1 && i) ans -= vec[i][0].cost;
			else ma = max(ma,d[i]);
		}
		cout << ans * 2 - ma << endl;
	}
	return 0;
}

Measured memory_bytes: 3092
#include<iostream>
#include<set>
#include <bitset>
#include<queue>
#include<vector>
#include<map>
#include<stack>
#include <cstdio>
#include<algorithm>
#include <sstream>
#include<string>
#include<string.h>
#include <cmath>
#include <iomanip>
#include <string>
#include<list>
#include <limits>
#include <numeric>
#include <type_traits>
#define int long long
#define ll long long
#define mod  1000000007
#define inf 1e17
#define rep(i,j,n) for(int i=j;i<n;i++)
#define P pair<int,int>
double pi = 3.141592653589793;
using namespace std;
//ここから始めよう
int solve(int a,int b,int c){
    return (a/2)*4+(b/2)*4+(c/2)*4;
}
signed main(){
    int a,b,c,d,e,f,g;cin>>a>>b>>c>>d>>e>>f>>g;int ans=0;ans+=2*b;
    if(a>=1&&d>=1&&e>=1)ans+=max(solve(a,d,e),solve(a-1,d-1,e-1)+6);
    else ans+=solve(a,d,e);
    cout<<ans/2<<endl;
    return 0;
}

Measured memory_bytes: 256
#!/usr/bin/env python3
import sys


class UnionFind(object):
    __slots__ = ["nodes"]

    def __init__(self, n: int):
        self.nodes = [-1]*n # 親: -(属するノード数), それ以外: (親ノードindex)

    def find(self, x: int) -> int:
        if self.nodes[x] < 0:
            return x
        else:
            self.nodes[x] = self.find(self.nodes[x]) # compression
            return self.nodes[x]

    def has_same_root(self, x, y) -> bool:
        return self.find(x) == self.find(y)
    
    def size(self, x) -> int:
        return -self.nodes[self.find(x)]

    def unite(self, x: int, y: int) -> None:
        if self.has_same_root(x, y):
            return

        root_x, root_y = self.find(x), self.find(y)
        if self.nodes[root_x] < self.nodes[root_y]:
            bigroot, smallroot = (root_x, root_y)
        else: 
            bigroot, smallroot = (root_y, root_x)
        self.nodes[bigroot] += self.nodes[smallroot]
        self.nodes[smallroot] = bigroot


def solve(N: int, M: int, p: "List[int]", x: "List[int]", y: "List[int]"):
    U = UnionFind(2 * N + 1)
    for i, pi in enumerate(p):
        U.unite(i+1, N + pi)
    for xx, yy in zip(x, y):
        U.unite(xx, yy)
    res = 0
    for i in range(1, N+1):
        if U.has_same_root(i, N+i):
            res += 1
    
    print(res)
    return


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    M = int(next(tokens))  # type: int
    p = [ int(next(tokens)) for _ in range(N) ]  # type: "List[int]"
    x = [int()] * (M)  # type: "List[int]" 
    y = [int()] * (M)  # type: "List[int]" 
    for i in range(M):
        x[i] = int(next(tokens))
        y[i] = int(next(tokens))
    solve(N, M, p, x, y)

if __name__ == '__main__':
    main()


Measured memory_bytes: 108892