akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
void query1(const int &p, const char &c, vector<set<int>> &a) {
	for (int i = 0; i < 26; i++) {
		if (a[i].count(p)) {
			a[i].erase(p);
			break;
		}
	}
	a[c - 'a'].insert(p);
}
void query2(const int &l, const int &r, const vector<set<int>> &a) {
	int cnt = 0;
	for (int i = 0; i < 26; i++) {
		if (a[i].lower_bound(l) != a[i].upper_bound(r)) cnt++;
	}
	printf("%d\n", cnt);
}
int main() {
	int n;
	scanf("%d", &n);
	char s[n];
	scanf("%s", s);
	vector<set<int>> a(26);
	for (int i = 0; i < n; i++) a[s[i] - 'a'].insert(i);
	int q;
	scanf("%d", &q);
	while (q--) {
		int p;
		scanf("%d", &p);
		if (p == 1) {
			int i;
			char c;
			scanf("%d %c", &i, &c);
			query1(i - 1, c, a);
		} else {
			int l, r;
			scanf("%d%d", &l, &r);
			query2(l - 1, r - 1, a);
		}
	}
	return 0;
}

Measured memory_bytes: 24192
#include <stdio.h>  
#include <algorithm>  
#include <assert.h>
#include <bitset>
#include <cmath>  
#include <complex>  
#include <deque>  
#include <functional>  
#include <iostream>  
#include <limits.h>  
#include <map>  
#include <math.h>  
#include <queue>  
#include <set>  
#include <stdlib.h>  
#include <string.h>  
#include <string>  
#include <time.h>  
#include <unordered_map>  
#include <unordered_set>  
#include <vector>  

#pragma warning(disable:4996)  
#pragma comment(linker, "/STACK:336777216")  
using namespace std;

#define mp make_pair  
#define Fi first  
#define Se second  
#define pb(x) push_back(x)  
#define szz(x) ((int)(x).size())  
#define rep(i, n) for(int i=0;i<n;i++)  
#define all(x) (x).begin(), (x).end()  
#define ldb ldouble  

typedef tuple<int, int, int> t3;
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ldb;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef pair <ll, int> pli;
typedef pair <db, db> pdd;

int IT_MAX = 1 << 19;
const ll MOD = 1000000007;
const int INF = 0x3f3f3f3f;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
const db PI = acos(-1);
const db ERR = 1e-10;

int in[3][105];
int main() {
	int ans = 0;
	int N, i, j, k, l;
	scanf("%d", &N);
	for (i = 1; i <= 2; i++) for (j = 1; j <= N; j++) scanf("%d", &in[i][j]);

	for (i = 1; i <= N; i++) {
		int s = 0;
		for (j = 1; j <= i; j++) s += in[1][j];
		for (j = i; j <= N; j++) s += in[2][j];
		ans = max(ans, s);
	}
	return !printf("%d\n", ans);
}

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

int main() {
    int a, b;
    cin >> a >> b;
    if (a==b) cout << 2*a << endl;
    else if (a>b) cout << 2*a-1 << endl;
    else cout << 2*b-1 <<endl; 
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define INF 1000000005
#define MOD 1000000007
#define EPS 1e-10
#define rep(i,n) for(int i=0;i<(int)n;++i)
#define each(a, b) for(auto (a): (b))
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define pb push_back
#define show(x) cout <<#x<<" = "<<(x)<<endl
#define spair(p) cout <<#p<<": "<<p.fi<<" "<<p.se<<endl
#define svec(v) cout<<#v<<":";rep(kbrni,v.size())cout<<" "<<v[kbrni];cout<<endl
#define sset(s) cout<<#s<<":";each(kbrni,s)cout <<" "<<kbrni;cout<<endl

using namespace std;

typedef pair<int,int>P;

const int MAX_N = 100005;

vector<int> G[MAX_N];
bool flag[MAX_N];

int dfs(int u)
{
    flag[u] = true;
    int ans = 0;
    rep(i,G[u].size()){
        if(!flag[G[u][i]]){
            ans ^= (dfs(G[u][i]) + 1);
        }
    }
    return ans;
}

int main()
{
    int n;
    cin >> n;
    rep(i,n-1){
        int a,b;
        cin >> a >> b;
        G[a-1].pb(b-1);
        G[b-1].pb(a-1);
    }
    rep(i,n){
        flag[i] = false;;
    }
    int res = dfs(0);
    if(res){
        cout << "Alice\n";
    }else{
        cout << "Bob\n";
    }
    return 0;
}


Measured memory_bytes: 10496
import sys
input = sys.stdin.readline


def main():
    X, N = map(int, input().split())
    p = list(map(int, input().split()))
    assert N == len(p)
    if N == 0:
        print(X)
        exit()
    abs_list = []
    abs_list2 = list(range(-100, 100))
    abs_list2.sort()
    abs_list2 = sorted(abs_list2, key=abs)
    for i in p:
        abs_list.append(i-X)
    abs_list.sort()
    abs_list = sorted(abs_list, key=abs)
    # print(abs_list)
    # print(abs_list2)
    for i in range(N):
        if abs_list[i] != abs_list2[i]:
            print(X+abs_list2[i])
            exit()
    print(X+abs_list2[N])


if __name__ == '__main__':
    main()


Measured memory_bytes: 9216
//#pragma GCC optimize ("O3")
//#pragma GCC target ("sse4")

#include <bits/stdc++.h>

using namespace std;

// CHECK THE LIMITS
typedef long long ll;

static const int NMAX = 1e5;

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    
    int a,b;
    cin >> a >> b;
    if((a+b)%2 == 0)
        cout << (a+b)/2;
    else
        cout << "IMPOSSIBLE";

    return 0;
}

Measured memory_bytes: 256
from collections import deque

H, W, K = map(int, input().split())
A = [input() for h in range(H)]

for h in range(H):
  for w in range(W):
    if A[h][w] == 'S':
      sx, sy = h, w

INF = 1000
dist = [[INF for w in range(W)] for h in range(H)]
dist[sx][sy] = 0


dxy = [[1, 0], [0, 1], [-1, 0], [0, -1]]
start = []
d = deque([[sx, sy]])
while d:
  x, y = d.popleft()
  for dx, dy in dxy:
    xx = x + dx; yy = y + dy
    if 0<=xx<H and 0<=yy<W and dist[xx][yy]==INF:
      if A[xx][yy] == '.':
        dist[xx][yy] = dist[x][y] + 1
        d.append([xx, yy])
        if dist[xx][yy] <= K:
          start.append([xx, yy])

ans = min(-(-(H-1-sx)//K)+1, -(-sx//K)+1, -(-(W-1-sy)//K)+1, -(-sy//K)+1)
for x, y in start:
  ans = min(ans, -(-(W-1 - y)//K) + 1) # 右
  ans = min(ans, -(-y//K) + 1) # 左
  ans = min(ans, -(-(H-1 - x)//K) + 1) # 下
  ans = min(ans, -(-x//K) + 1) # 上

print(ans)

Measured memory_bytes: 128352
#include<iostream>
#include<stdio.h>
#include<iomanip>
using namespace std;

int main() {

  int a, b, x;
  cin >> a >> b >> x;

  if(a>x){
    cout << "NO" << endl;
  } else {
    if(a+b>=x){
      cout << "YES" << endl;
    } else {
      cout << "NO" << endl;
    }
  }
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <cstdio>
#include <cmath>
#include <tuple>
#include <iomanip>
#include <numeric>
#include <unordered_map>
#include <sstream>
#include<limits.h>
#include<float.h>
#include<list>
#include <array>
#include <complex>
#include<stdio.h>
#include<string.h>
#include <bitset>

using namespace std;
#define int long long

#define I32_MAX 2147483647
#define I64_MAX 9223372036854775807LL
#define I64_MAX2 1223372036854775807LL
#define INF I64_MAX2
#define MOD 1000000007
#define MEM_SIZE 10000
#define DEBUG_OUT true
#define ALL(x) (x).begin(), (x).end()

template<typename T> void DEBUG(T e){if(DEBUG_OUT == false)return; std::cout << e <<" ";}
template<typename T> void DEBUG(const std::vector<T>& v){if(DEBUG_OUT == false)return;for(const auto& e : v){std::cout<< e << " "; } std::cout << std::endl;}
template<typename T> void DEBUG(const std::vector<std::vector<T> >& vv){if(DEBUG_OUT == false)return;for(const auto& v : vv){ DEBUG(v); } }
template<class T,class... Ts> void DEBUG(T d, Ts... e){if(DEBUG_OUT == false)return;DEBUG(d);DEBUG(e...);}
template <class T> void corner(bool flg, T hoge) {if (flg) {cout << hoge << endl; abort();}}
template< typename T1, typename T2 > inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template< typename T1, typename T2 > inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }
//SOLVE

//-----CODE------//
void solve(void)
{ 
  string str;
  cin>>str;
  if(str == "AKIHABARA" || str == "KIHABARA" ||str == "AKIHBARA" ||str == "AKIHABRA" ||str == "AKIHABAR"||str == "KIHBARA"  ||str == "KIHABRA" ||str == "KIHABAR"||str == "KIHBRA" ||str == "AKIHBR" ||str == "KIHBR" || str == "AKIHBRA"|| str == "AKIHBAR" || str == "AKIHABR"||str == "AKIHBARA" ||str == "KIHABR"||str == "KIHBAR"  )
  {
    cout<<"YES"<<endl;
  }
  else
  {
    cout<<"NO"<<endl;
  }
  

  return;
}
int32_t main(int32_t argc, const char *argv[])
{
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);

  std::cout << std::fixed;
  std::cout << std::setprecision(9);
  solve();

  return 0;
}


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

using namespace std;
#define _for(i,j,N) for(int i = (j); i < (N);i++)
#define _rep(i,j,N) for(int i = (j); i <= (N);i++)
#define _dec(i,j,N) for(int i = (N-1);i >= 0;i--)
#define _dep(i,j,N) for(int i = (N); i>= 0;i--)
#define ALL(x) x.begin(),x.end()
#define LL long long
#define ULL unsigned LL
#define PB push_back


LL dp[2][40005];
int R[4005];
int B[4005];

const LL mod = 998244353;

int main()
{
    string s;
    cin >> s;
    int sz = s.size();
    R[0] = (B[0] = 0);
    _rep(i,1,sz){
        R[i] = R[i-1];B[i] = B[i-1];
        if(s[i-1] == '0') R[i] += 2;
        else if(s[i-1] == '1'){R[i]++;B[i]++;}
        else B[i]+=2;
    }
    _rep(i,sz+1,2*sz){
        R[i] = R[i-1];B[i] = B[i-1];
    }

    memset(dp,0,sizeof(dp));
    dp[0][0] = 1;
    int t = 1;
    _rep(n,1,2*sz){
        int bef = t^1;
        _rep(i,0,n){
            LL &ans = dp[t][i];
            if(B[n] < n-i){ans = 0;continue;}
            if(R[n] < i){ans = 0;break;}
            if(!i){ans = dp[bef][i];continue;}
            ans = (dp[bef][i] + dp[bef][i-1])%mod;
            //printf("%d %d %lld\n",n,i,ans);
        }
        t = t^1;
    }

    /*
    _rep(i,1,sz){
        printf("%d ",B[i]);
    }
    printf("\n");
    //cout << R[sz] << endl;
    */

    printf("%lld\n",dp[t^1][R[sz]]);

}

Measured memory_bytes: 896
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <numeric>
#include <sstream>
#include <iostream>
#include <iomanip>
#define _USE_MATH_DEFINES
#include <cmath>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <cfloat>
#include <cmath>
#include <ctime>
#include <cassert>
#include <cctype>
#include <cstdio>
#include <cassert>
using namespace std;

#define EPS 1e-12
#define ull unsigned long long
#define ll long long
#define VI vector<ll>
#define PII pair<ll, ll> 
#define VVI vector<vector<ll> >
#define VVVI vector<vector<vector<ll>>>
#define VVVVI vector<vector<vector<vector<ll>>>>
#define REP(i,n) for(ll i=0,_n=(n);(i)<(ll)_n;++i)
#define REPR(i,n) for(ll i=(ll)(n)-1;0<=(i);--i)
#define RANGE(i,a,b) for(ll i=(ll)a,_b=(ll)(b);(i)<_b;++i)
#define RANGER(i,a,b) for(ll i=(ll)(b)-1,_a=(ll)(a);(_a)<=i;--i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
#define ALLR(c) (c).rbegin(), (c).rend()
#define PB push_back
#define MP(a, b) make_pair(a, b)
#define POPCOUNT __builtin_popcount
#define POPCOUNTLL __builtin_popcountll
#define CLEAR(table, v) memset(table, v, sizeof(table));
#define UNIFORM_DOUBLE(a, b) (((b-a)*(double)rand()/RAND_MAX)+a) // [a, b) 
#define UNIFORM_LL(a, b) (ll)UNIFORM_DOUBLE(a, b) // [a, b) 
#define IN(v, lo, hi) ((lo)<=(v) && (v)<(hi))
#define DD(v) cout<<#v<<": "<<v<<endl
#define FI first
#define SE second
template <typename T0, typename T1> std::ostream& operator<<(std::ostream& os, const map<T0, T1>& v) { for( typename map<T0, T1>::const_iterator p = v.begin(); p!=v.end(); p++ ){os << p->first << ": " << p->second << " ";} return os; }
template <typename T0, typename T1> std::ostream& operator<<(std::ostream& os, const pair<T0, T1>& v) { os << v.first << ": " << v.second << " "; return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const vector<T>& v) { for( int i = 0; i < (int)v.size(); i++ ) { os << v[i] << " "; } return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const set<T>& v) { vector<T> tmp(v.begin(), v.end()); os << tmp; return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const deque<T>& v) { vector<T> tmp(v.begin(), v.end()); os << tmp; return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const vector<vector<T> >& v) { for( int i = 0; i < (int)v.size(); i++ ) { os << v[i] << endl; } return os; }
template<typename T>void maxUpdate(T& a, T b) {a = max(a, b);}
template<typename T>void minUpdate(T& a, T b) {a = min(a, b);}

#define MOD 1000000007LL
#define INF (1LL<<60)

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll N,M,W,H;
	string s;
	while(cin>>N) {
		ll ans = 0;
		for(ll d=1; d*d<=N; d++) {
			if(N%d==0) {
				ll k0 = d;
				REP(loop, 2) {
//					DD(k0);
					ll m = k0-1;
					if(0<m) {
						ll k1 = N/k0;
						if(N/m==k1 && N%m==k1) ans += m;
					}
					k0 = N/k0;
				}
			}
		}
		
		cout<<ans<<endl;
	}
	
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
	int i,n,m;
	cin>>n>>m;
	vector<bool> vis(n+1,false);
	bool ans=false;
	for (i=0;i<m;i++){
		int a,b;
		cin>>a>>b;
		if(a==1){
			if(vis[b]){
				ans=true;
			}
			vis[b]=true;
		}else if(b==n){
			if(vis[a]){
				ans=true;
			}
			vis[a]=true;
		}
	}
	if(!ans) cout<<"IMPOSSIBLE";
	else cout<<"POSSIBLE";
	return 0;
}

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

int main(){
  int a,b;
  cin >>a>>b;
  string c;
  c=to_string(a)+to_string(b);
  
  if(stoi(c)%((int)sqrt(stoi(c)))==0){
    cout<<"Yes"<<endl;
    return 0;
  }
  cout<<"No"<<endl;
  return 0;
}


  

Measured memory_bytes: 256
import numpy as np
import scipy.sparse.csgraph as csg

if __name__ == '__main__':
    N = int(input())
    A = [list(map(int, input().split())) for i in range(N)]

    G = np.asarray(A, dtype=np.uint32)
    G2 = csg.floyd_warshall(G, directed=False)
    # print(G)
    # print(G2)
    # print(G == G2)
    if np.any(G != G2):
        print(-1)
        exit()
    ans = 0
    G[G == 0] = 1
    for i in range(N):
        for j in range(i + 1, N):
            n = np.min(G[i] + G[j])
            if n > G[i, j]:
                ans += G[i, j]

    print(ans)


Measured memory_bytes: 23124
#include <stdio.h>
int main(void){
    long n, m, l, a[1000][1000]={{0}}, b[1000][1000]={{0}}, c[1000][1000]={{0}}, i, j, k;
    
    scanf("%ld %ld %ld\n", &n, &m, &l);
    
    for(i=0; i<n; i++){
        for(k=0; k<m; k++){
            scanf("%ld", &a[i][k]);
        }
    }
    
    for(k=0; k<m; k++){
        for(j=0; j<l; j++){
            scanf("%ld", &b[k][j]);
        }
    }
    
    for(i=0; i<n; i++){
        for(j=0; j<l; j++){
            for(k=0; k<m; k++){
                c[i][j] = c[i][j] + a[i][k]*b[k][j];
            }
        }
    }
    
    for(i=0; i<n; i++){
        for(j=0; j<l; j++){
            printf("%ld", c[i][j]);
            if(j<l-1){
                printf(" ");
            }
        }
        printf("\n");
    }
            
    return 0;
}


Measured memory_bytes: 25292
#include <iostream>
#include <stdio.h>
#include <string>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <math.h>
#include <vector>
#include <algorithm>

using namespace std;

int main(){
	int a, b;
	cin >> a >> b;
	if(a * b % 2 == 0){
		cout << "Even" << endl;
	}else{
		cout << "Odd" << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#pragma GCC optimize ("O3")
#pragma GCC target ("avx2") 
#pragma GCC optimization ("unroll-loops")


using namespace std;
using ll = long long;
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL);
#define ff first
#define ss second
#define Ceil(x, y) ((x+y-1)/y)
#define pb(x) push_back(x)
#define eb(x) emplace_back(x);
const int mod = (int) 1e9 + 7;


void solve()
{
	int n;
	cin>>n;
	ll ans = 0;
	for(int i=1; i<=n; i++)
	{
		if(n % i == 0)
			ans += n/i - 1;
		else
			ans += n/i;
	}
	cout<<ans;
}

int main(int argc, char *argv[])
{
	clock_t clk_start = clock();
	fast;
	#ifndef ONLINE_JUDGE
		freopen("input.txt", "r", stdin);
		freopen("output.txt", "w", stdout);
	#endif
 
	int cases = 1;
	// cin>>cases;
	for(int i=1; i<=cases; i++)
	{
		// cout<<"Case #"<<i<<": ";
		solve();
	}
	cerr<<"Execution Time: "<<fixed<<double(clock() - clk_start)/double(CLOCKS_PER_SEC)<<setprecision(6)<<" sec\n"; 
}

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

const long long MOD = 1000000007;
const long long MAX = 2000000;

template<typename T>
T gcd(T a, T b) {
    return b != 0 ? gcd(b, a % b) : a;
}

template<typename T>
T lcm(T a, T b) {
    return a * b / gcd(a, b);
}

int main()
{
    int K;
    string S;
    cin>>K;
    cin>>S;
    if(S.size()<=K){
        cout<<S<<endl;
    }else{
        for(int i=0;i<K;i++){
            cout<<S[i];
        }
        cout<<"..."<<endl;
    }

}


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

using namespace std;

const int N = (int)2e5 + 1;
const long long INF = 1e9 + 7;

typedef long long ll;
typedef long double ld;

typedef pair < int, int > pii;
typedef pair < ll, ll > pll;

int n;
ll x[N], s[N];
int main(){
  scanf ("%d", &n);
  for (int i = 1; i <= n; ++i){
    int v;
    scanf ("%d", &v);
    x[i] = x[i - 1] ^ v;
    s[i] = s[i - 1] + v;
  }
  ll len = 0, ans = 0;
  for (int i = 1; i <= n; ++i){
    while (s[i] - s[len] != (x[i] ^ x[len])){
      ++len;
    }
    ans += i - len;
  }
  printf ("%lld\n", ans);
  return 0;
}


Measured memory_bytes: 3328
#include<bits/stdc++.h>
using namespace std;
 
#define rep(i, a, n) for(int i=a; i<n; i++)
#define ll long long
#define all(x) begin(x), end(x)
#define toInt(x) (x - '0')
#define pll pair<ll, ll>
#define MAXN 200 + 5
const long long INF = 1LL << 60;
const int inf = 1 << 30;

void printVec(std::vector<int> &vec) {
  std::cout << "";
  for (auto it = vec.begin(); it != vec.end(); ++it) {
    std::cout << *it << " ";
  }
  std::cout << std::endl;
}
 
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; }

bool solve(string s){
  for(int i=0; i<s.size() / 2; i++){
    if(s[i] != s[s.size() - 1 - i]){
      return false;
    }
  }
  return true;
}
int main(){
  string s;
  cin >> s;
  // cout << solve(s) << endl;
  int n  = s.size();

  bool c1 = solve(s);
  bool c2 = solve(s.substr(0, (n - 1)/2));
  bool c3 = solve(s.substr((n+3)/2-1, std::string::npos));

  if(c1 == 1 && c2 == 1 && c3 == 1){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
}
     


Measured memory_bytes: 256
n,k = map(int, input().split())

# 取得される値とその出現回数を保存
d = {}
for _ in range(n):
  a,b = map(int, input().split())
  if a not in d: d[a] = b
  else: d[a] += b

# 値の小さい順にカウントしていき、kを超えた時点の値をk番目の値とする
t = 0
for i in sorted(d.items(), key=lambda x:x[0]):
  t += i[1]
  if t >= k:
    print(i[0])
    exit()

Measured memory_bytes: 20968
#include <bits/stdc++.h>
#define int long long int
#define MOD(x) ((x % MOD_N) + MOD_N) % MOD_N
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define FORE(i,a,b) for(int i=(a);i<=(b);++i)
#define RFOR(i,a,b) for(int i=(b)-1;i>=(a);--i)
#define RFORE(i,a,b) for(int i=(b);i>=(a);--i)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define ALL(c) (c).begin(),(c).end()
#define RALL(c) (c).rbegin(),(c).rend()
#define SORT(c) sort(ALL(c))
#define RSORT(c) sort(RALL(c))
#define SZ(c) (int)((c).size())
#define EACH(i,v) for(auto i=v.begin();i!=v.end();++i)
#define REACH(i,v) for(auto i=v.rbegin();i!=v.rend();++i)
#define LB(c,x) distance((c).begin(),lower_bound(ALL(c),x))
#define UB(c,x) distance((c).begin(),upper_bound(ALL(c),x))
#define COUNT(c,x) (lower_bound(ALL(c),x)-upper_bound(ALL(c),x))
#define UNIQUE(c) SORT(c); (c).erase(unique(ALL(c)),(c).end());
#define COPY(c1,c2) copy(ALL(c1),(c2).begin())
#define EXIST(s,e) (bool)((s).find(e)!=(s).end())
#define PB push_back
#define MP make_pair
#define DUMP(x)  cerr<<#x<<" = "<<(x)<<endl;
#define NL cerr<<endl;
using namespace std;
template<typename T,typename U> using P=pair<T,U>;
template<typename T> using V=vector<T>;
template<typename T>bool chmax(T&a,T b){if(a<b){a=b;return true;}return false;}
template<typename T>bool chmin(T&a,T b){if(a>b){a=b;return true;}return false;}
template<typename T>T sum(vector<T>&v){return accumulate(ALL(v),T());}
template<typename T>T sum(vector<T>&v,int a,int b){return accumulate(v.begin()+a,v.begin()+b,T());}
template<typename T>T max(vector<T>&v){return *max_element(ALL(v));}
template<typename T>T min(vector<T>&v){return *max_element(ALL(v));}
template<typename T>T max_index(vector<T>&v){return distance((v).begin(),max_element(ALL(v)));}
template<typename T>T min_index(vector<T>&v){return distance((v).begin(),min_element(ALL(v)));}

struct edge { int to, cost; };

template<typename T>auto&operator<<(ostream&s,const vector<T>&v){s<<"[";bool a=1;for(auto e:v){s<<(a?"":" ")<<e;a=0;}s<<"]";return s;}
template<typename T,typename U>auto&operator<<(ostream&s,const pair<T,U>&p){s<<"("<<p.first<<","<<p.second<<")";return s;}
template<typename T>auto&operator<<(ostream&s,const set<T>&st){s<<"{";bool a=1;for(auto e:st){s<<(a?"":" ")<<e;a=0;}s<<"}";return s;}
template<typename T,typename U>auto&operator<<(ostream&s,const map<T,U>&m){s<<"{";bool a=1;for(auto e:m){s<<(a?"":" ")<<e.first<<":"<<e.second;a=0;}s<<"}";return s;}

const int INF = 1e18;
const int MOD_N = 1e9+7;

int LevenshteinDistance(const string& s1, const string& s2) {
   int n1 = s1.size(), n2 = s2.size();
   V<V<int>> dp(n1+1, V<int>(n2+1));
   FORE(i, 0, n1) dp[i][0] = i;
   FORE(j, 0, n2) dp[0][j] = j;
   REP(i, n1) {
      REP(j, n2) {
         dp[i+1][j+1] = min(
               dp[i][j] + (s1[i] == s2[j] ? 0 : 1),
               min(dp[i+1][j] + 1,
                   dp[i][j+1] + 1));
      }
   }
   return dp[n1][n2];
}

signed main()
{
   string s1, s2; cin >> s1 >> s2;
   cout << LevenshteinDistance(s1, s2) << endl;

   return 0;
}



Measured memory_bytes: 10832
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
#define int long long
#define gmax(x,y) x=max(x,y)
#define gmin(x,y) x=min(x,y)
#define F first
#define S second
#define P pair
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define rep(i,a,b) for(int i=a;i<b;i++)
#define V vector
#define RE return
#define ALL(a) a.begin(),a.end()
#define MP make_pair
#define PB emplace_back
#define PF emplace_front
#define FILL(a,b) memset(a,b,sizeof(a))
#define lwb lower_bound
#define upb upper_bound
using namespace std;
struct node{
	int l,r,k;
}p[200005];
bool cmp(int x,int y){
	RE p[x].k<p[y].k;
}
bool cmq(int x,int y){
	RE p[x].k>p[y].k;
}
void solve(){
	int n;
	cin>>n;
	int ans=0;
	V<int> v1,v2;
	FOR(i,1,n){
		cin>>p[i].k>>p[i].l>>p[i].r;
		if(p[i].r>p[i].l){
			v2.PB(i);ans+=p[i].l;
		}else{
			ans+=p[i].r;v1.PB(i);
		}
	}
	sort(ALL(v1),cmp);
	priority_queue<int,V<int>,greater<int> > q;
	int cnt=0;
	for(auto u:v1){
		int t=p[u].k;
		if(t<=cnt){
			int s=q.top();q.pop();
			if(s<p[u].l-p[u].r){
				q.emplace(p[u].l-p[u].r);
			}else q.emplace(s);
		}else{
			q.emplace(p[u].l-p[u].r);
			cnt++;
		}
	}
	while(!q.empty()){
		int cur=q.top();
		ans+=cur;
		q.pop();
	}
	sort(ALL(v2),cmq);
	cnt=0;
	for(auto u:v2){
		int t=p[u].k+1;
		if(t>n)continue;
		if(t>=n-cnt+1){
			int s=q.top();q.pop();
			if(s<p[u].r-p[u].l){
				q.emplace(p[u].r-p[u].l);
			}else q.emplace(s);
		}else{
			q.emplace(p[u].r-p[u].l);
			cnt++;
		}
	}
	while(!q.empty()){
		int cur=q.top();
		ans+=cur;
		q.pop();
	}
	cout<<ans<<'\n';
}
signed main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	int t;
	cin>>t;
	while(t--)solve();
	RE 0;
}


Measured memory_bytes: 11080
#include <algorithm>
#include <bitset>
#include <cmath>
#include <iostream>
#include <iterator>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <utility>
#include <unordered_map>
#include <unordered_set>
using namespace std;

#define ABS(a) (((a) >= 0) ? (a) : -(a))
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define MIN(a, b) ((a) > (b) ? (b) : (a))
#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 REP(i, n) for (int i = 0; i < (n); ++i)
#define NINTH_POWER_OF_TEN 1000000000
#define int long long

typedef long long ll;
typedef pair<int, int> Pair;

const int kMaxN = 100000;

string S;
int ans = 0;

int dp[kMaxN+1][4];

signed main() {
  cin >> S;
  int n = S.length();

  dp[0][0] = 1;
  REP(i, n) {
    if (S[i] == '?') {
      REP(j, 4) { dp[i+1][j] += 3*dp[i][j]; }
      REP(j, 3) { dp[i+1][j+1] += dp[i][j]; }
    } else {
      REP(j, 4) { dp[i+1][j] += dp[i][j]; }
      if (S[i] == 'A') {
        dp[i+1][1] += dp[i][0];
      } else if (S[i] == 'B') {
        dp[i+1][2] += dp[i][1];
      } else {
        dp[i+1][3] += dp[i][2];
      }
    }
    REP(j, 4) { dp[i+1][j] %= NINTH_POWER_OF_TEN+7; }
  }
  ans = dp[n][3];

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


Measured memory_bytes: 3584
#include<string.h>
#include<iostream>
#include<algorithm>
#include<cmath>
#include<math.h>
#include<vector>
using namespace std;
#define ll long long 
#define r(i,n) for(ll i=0;i<n;i++)
#define rp(i,k,n) for(ll i=k;i<n;i++)
#define rt return 
#define r1 rt 1;
#define r0 rt 0;
#define db double
#define p(x) cout<<x<<endl;
#include<map>
ll power(ll k){
	ll x=1;
	r(i,k)x*=3;rt x;
}
int main(){
	while(1){
		
		ll n;
		cin>>n;
		vector<ll>a(n);
		r(i,n)cin>>a[i];
if(n==1){
ll b,c,d;
c=a[0];
b=c-1;
d=c+1;
int ct=0;
if(c%2==0)ct++;
if(b%2==0)ct++;
if(d%2==0)ct++;
p(ct)r0
}
ll kisu=1;
r(i,n){if(a[i]%2==0)kisu*=2;else kisu*=1;}
p(power(n)-kisu)
r0
	}}//main and while

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

using namespace std;

typedef long long int ll;
typedef pair<int,int> P;

#define rep(i,n) for(int i=0;i<(n);++i)
#define repi(i,a,b) for(int i=int(a);i<(b);i++)
#define repr(i,b,a) for(int i=int(b);i>=(a);i--)
#define all(x) x.begin(),x.end()

const ll mod = 1e9+7;
const ll INF = 1e9;

ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
bool valid(int lx,int ux,int ly,int uy,int x,int y){
	return lx<=x&&x<ux&&ly<=y&&y<uy; 
}
ll power(ll x,ll p){
	if(p==0)return 1;
	ll res=power(x*x%mod,p/2);
	if(p%2==1)res=res*x%mod;
	return res;
}

int main()
{
	int n;
	cin>>n;
	vector<int> a(n);
	rep(i,n)cin>>a[i];
	rep(i,n){
		if(a[i]%3!=0&&a[i]%5!=0){
			if(a[i]%2!=0)continue;
			cout<<"DENIED"<<endl;
			return 0;
		}
	}
	cout<<"APPROVED"<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

int main(void){
  int n,i,j,ans;
  char s[10000001];

  s[0]='1';
  s[1]='1';
  for(i=2;i<=10000001;i++)
    s[i]='0';

  for(i=2;i*i<=10000001;i++){
    if(s[i]=='0'){
      for(j=2*i;j<=10000001;j+=i)
	s[j]='1';
      }
}

  while(scanf("%d",&n),n){
    for(i=n;;i--){
      if(s[i]=='0' && s[i-2]=='0' && s[i-6]=='0' && s[i-8]=='0'){
	printf("%d\n",i);
	break;
      }
    }
  }
  return 0;
}

Measured memory_bytes: 9000
n = int(input())
ls = []
for i in range(n):
  ls.append([int(input())-1,False])
count = 0
x = 0
while (x != 1):
  if ls[x][1]:
    count = -1
    break
  else:
    count += 1
    ls[x][1] = True
    x = ls[x][0]
print(count)

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

int main(){
	// sengen
	int a,b;
	cin >> a >> b;
	int answer;
	// nyuryoku

	// keisan
	for(int i=1;i<=3;i++){
		if(i != a && i != b){
			answer = i;
		}
	}
	cout << answer << endl;
}

Measured memory_bytes: 256
# coding: UTF-8
import sys
#sys.setrecursionlimit(n)
import heapq
import re
import bisect
import random
import math
import itertools
from collections import defaultdict, deque
from copy import deepcopy
from decimal import *

readl= lambda: list(map(int, sys.stdin.readline().split()))
readt= lambda: tuple(map(int, sys.stdin.readline().split()))
read = lambda: sys.stdin.readline().rstrip()
readi = lambda: int(read())
readmi = lambda: map(int, sys.stdin.readline().split())
readms = lambda: map(str, sys.stdin.readline().split())

n = readi()
t = []
l = []
for i in range(n):
    t.append(readl())
    l.append(i)
s = 0
for i in list(itertools.permutations(l,2)):
    s += math.sqrt(((t[i[0]][0] - t[i[1]][0]) ** 2) + ((t[i[0]][1] - t[i[1]][1]) ** 2))

print(s / n)   

Measured memory_bytes: 6804
#include<bits/stdc++.h>
#define ll long long

using namespace std;

int main(){
	ll h;
	char c;
	
	cin>>h;
	c=h;
	
	if(c>='A' && c<='Z') cout<<1<<"\n";
		else if(c>='a' && c<='z') cout<<2<<"\n";
			else cout<<0<<"\n";
}


Measured memory_bytes: 3112
#include <iostream>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <vector>
#include <queue>
#include <algorithm>
#include <bitset>
#include <cstdlib>
#include <cmath>
#define INF 1000000000
#define MOD 1000000007
#define ll long long int
using namespace std;
/*
int main(){
  string s; cin>>s;
  if(s[0] == s[2]) cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
  return 0;

}

*/

int main(){
  int a,b,c,d; cin>>a>>b>>c>>d;
  cout<<max(min(b,d) - max(a,c) , 0)<<endl;

  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
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; }
//---------------------------------------------------------------------------------------------------

void _main() {
	int r,D,x0;
	cin >> r >> D >> x0;
	int beforex = x0;
	int ans = 0;
	rep(i, 0, 10) {
		ans = r * beforex - D;
		cout << ans << endl;
		beforex = ans;
	}
}

Measured memory_bytes: 256
import java.util.Scanner;
class Main {
	
	static void aryPrint(int[] a) {
		for(int i = 0; i < a.length - 1; i++) {
			System.out.print(a[i] + " ");
		}
		System.out.println(a[a.length - 1]);
	}

	public static void main(String[] args) {
		Scanner stdIn = new Scanner(System.in);
		
		int n = stdIn.nextInt();
		int[] a = new int [n];
		int count = 0;
		
		for(int i = 0; i < a.length; i++) {
			a[i] = stdIn.nextInt();
		}
		int i = 0;
		int flag = 1;		//逆の隣接する要素が存在する
		while(flag == 1){
			flag = 0;
			for(int j = a.length - 1; j - 1 >= i; j--) {
				if(a[j] < a[j - 1]) {
					int t = a[j];
					a[j] = a[j - 1];
					a[j - 1] = t;
					flag = 1;
					count++;
				}
			}
			i++;
		}
		aryPrint(a);
		System.out.println(count);
	}

}



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


int main(){
  long long ans = 0;
  int k; cin >> k;
  for (int a = 1; a <= k; a++)
  for (int b = 1; b <= k; b++)
  for (int c = 1; c <= k; c++)
  {
    ans += __gcd(__gcd(a,b),c);
  }
  cout << ans << endl;
}

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

#define fi first
#define se second
#define be begin
#define en end
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define ALL(a) (a).be() , (a).en()
#define REP(i,n) for(int (i)=0;(i)<(n);(i)++)        //repeat n times
#define REP2(i,s,n) for(int (i)=(s);(i)<(n);(i)++)   //repeat from s to n 
#define REPD(i,n) for(int (i)=(n);(i)>=0;(i)--)      //repeat from n to 0
#define REPD2(i,s,e) for(int (i)=(s);(i)>=(e);(i)--) //repeat from s to e
#define RANGE(i,v) for(auto &(i):v)                  //repeat range
#define ASIZE(a) (sizeof(a) / sizeof(a[0]))          //array size

using LL = long long;

template<typename T> using V = vector< T >;
using Vi = V<int>;
using Vll = V<LL>;
using Vs = V<string>;

int main(){
    int H,W;
    cin>>H>>W;
    V<V<char>> a(H,V<char>(W));
    Vi cnt_H(H);
    Vi cnt_W(W);
    REP(i,H){
        REP(j,W){
            cin>>a[i][j];
            if(a[i][j]=='.'){
                cnt_H[i]++;
                cnt_W[j]++;
            }
        }
    }

    REP(i,H){
        if(cnt_H[i]==W) continue;
        REP(j,W){
            if(cnt_W[j]==H) continue;
            cout<<a[i][j];
        }
        cout<<endl;
    }
    return 0;
}

Measured memory_bytes: 256
n,p=map(int,input().split())
def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])
    if temp!=1:
        arr.append([temp, 1])
    if arr==[]:
        arr.append([n, 1])
    return arr

lst=factorization(p)
# print(lst)
ans=1
for a,b in lst:
    if b>=n:
        ans*=pow(a,b//n)
print(ans)

Measured memory_bytes: 63180
#!/usr/bin/env python3
import sys
import collections as cl


def II(): return int(sys.stdin.readline())


def MI(): return map(int, sys.stdin.readline().split())


def LI(): return list(map(int, sys.stdin.readline().split()))


def main():
    S = input()
    Q = II()
    
    direction = 1
    pre = []
    sur = []

    for i in range(Q):
        query = input()
        if query == '1':
            direction *= -1
        else:
            _, f, c = query.split()
            if direction == 1:
                if f == '1':
                    pre.append(c)
                else:
                    sur.append(c)
            else:
                if f == '1':
                    sur.append(c)
                else:
                    pre.append(c)

    if direction == 1:
        ans = "".join(pre[::-1]) + S + "".join(sur)
    else:
        ans = "".join(sur[::-1]) + "".join(S[::-1]) + "".join(pre)
    print(ans)

main()


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

    using namespace std;
    using ll = long long int;
    constexpr ll M = 1e9 + 7;
    inline ll sum_1(const ll n) { return ((n * (n + 1)) / 2) % M; }
    inline ll sum_2(const ll n) { return ((n * (n + 1) * (2 * n + 1)) / 6) % M; }
    inline ll sum_3(const ll n) { return (((n * (n + 1)) / 2) % M * ((n * (n + 1)) / 2) % M) % M; }
    inline ll sum_1(const ll i, const ll j) { return (sum_1(j) - sum_1(i - 1) + M) % M; }
    inline ll sum_2(const ll i, const ll j) { return (sum_2(j) - sum_2(i - 1) + M) % M; }
    inline ll sum_3(const ll i, const ll j) { return (sum_3(j) - sum_3(i - 1) + M) % M; }

    ll pow_f(ll b, ll e) {
        ll ans = 1;
        while (e) {
            if (e&1) {
                ans = (ans * b);
            }
            b = (b * b);
            e >>= 1;
        }
        return ans;
    }

    ll nCr(ll n, ll r) {
        if (r > n || n < 0 || r < 0) { return 0; }
        if (n == r || r == 0) { return 1; }
        r = min(r, n-r);
        ll ans = 1;
        for (ll i = 1; i <= r; ++i) {
            ans = (ans * (n-i+1))/(i); 
        }
        return ans;
    }

    ll nCr(tuple<ll,ll> t) {
        auto n = get<0>(t);
        auto k = get<1>(t);
        return nCr(n+k-1, k);
    }

    void solve() {
        ll x;
        cin >> x;

        ll limit = 2*64;
        for (ll i = -limit; i <= limit; ++i) {
            for (ll j = -limit; j <= limit; ++j) {
                if ((pow_f(i, 5) - pow_f(j, 5)) == x) {
                    cout << i << " " << j << endl;
                    return;
                }
            }
        }

    }

    int main() {
        ios_base::sync_with_stdio(false);
        cin.tie(0);
        cout.tie(0);
        #ifdef D_LOCAL
            freopen("in.in", "r", stdin);
            freopen("out.out", "w", stdout);
        #endif

        solve();

        return 0;
    }

Measured memory_bytes: 3664
def factorization(n):
    index = []
    num = n
    for i in range(2, int(n ** 0.5 + 1)):
        if num % i == 0:
            c = 0
            while num % i == 0:
                c += 1
                num //= i
            index.append(c)

    if num != 1:
        index.append(1)

    if index == []:
        index.append(-1)

    return index

def main():
    n = int(input())
    a = factorization(n)
    ans = 0
    for i in a:
        for j in range(1, 45):
            if i >= j:
                i -= j
                ans += 1
            else:
                break
    print(ans)

main()

Measured memory_bytes: 9468
import copy
n = int(input())
x = list(map(int,input().split()))
y = copy.copy(x)
y.sort()
m1 = y[n//2-1]
m2 = y[n//2]
for i in range(n):
    if m2 == m1:
        print(m1)
    else:
        if x[i]<m2:
            print(m2)
        if x[i]>m1:
            print(m1)


Measured memory_bytes: 93256
MAX_TIME = 10

N = int(input())

# F[店のインデックス]
# 他の店
# 選択する時間帯を2進法で表現したもの
F = [sum(v << MAX_TIME - k - 1 for k, v
         in enumerate(map(int, input().split())))
     for i in range(N)]

# P[店のインデックス][合致した時間帯の数]
# 利益
P = [[int(j) for j in input().split()] for i in range(N)]


def main():
    # 予めビットをカウントしておく
    pattern = [sum(i >> j & 1 for j in range(MAX_TIME))
               for i in range(2 ** MAX_TIME)]

    # 営業時間帯 すべて試す
    # 最低でも ひとつの時間帯
    print(max(sum(
        P[j][pattern[F[j] & i]] for j in range(N))
        for i in range(1, 2 ** MAX_TIME)))

    return


main()


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

int main() {
  ll x;
  cin >> x;

  for (ll a = -1000; a <= 1000; a++) {
    for (ll b = -1000; b <= 1000; b++) {
      if (a*a*a*a*a - b*b*b*b*b == x) {
        cout << a << " " << b << endl;
        return 0;
      }
    }
  }
}


Measured memory_bytes: 3636
//============================================================================
// Name        : 2407.cpp
// Author      : afterCmidday
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <iostream>
#include <string>
using namespace std;

int main(void){
	string str;
	cin >> str;
	if(str[0] == str[str.size() - 1]){
		cout << str[0] << endl;
	}else{
		cout << 'o' << endl;
	}
}

Measured memory_bytes: 1176
#include <bits/stdc++.h>
#define sp ' '
#define nyan "(=^・ω・^=)"
#define mkp make_pair
#define intmax 2147483647
#define llmax 9223372036854775807
#define lP pair<ll,ll>
#define iP pair<int,int>
typedef long long ll;
using namespace std;
const int mod = 1000000007;

int N, a;
ll s, res;
map<ll, ll>mp;
int main() {
	cin >> N;
	mp[0] = 1;
	for (int i = 0; i != N; ++i) {
		cin >> a;
		s += a;
		++mp[s];
	}
	for (auto it = mp.begin(); it != mp.end(); ++it) {
		res += it->second*(it->second - 1) / 2;
	}
	cout << res << endl;
	return 0;
}

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

using namespace std;

int main(){
  int N;
  cin >> N;
  vector<bool> vec(1000000001, false);
  rep(i, N){
    int A;
    cin >> A;
    if(vec[A]){
      vec[A] = false;
    }
    else{
      vec[A] = true;
    }
  }
  
  int ans = 0;
  rep(i, 1000000001){
    if(vec[i]) ans++;
  }
  
  cout << ans << endl;
}
    


Measured memory_bytes: 122496
#include <algorithm>     //sort,二分探索,など
#include <bitset>        //固定長bit集合
#include <cmath>         //pow,logなど
#include <complex>       //複素数
#include <deque>         //両端アクセスのキュー
#include <functional>    //sortのgreater
#include <iomanip>       //setprecision(浮動小数点の出力の誤差)
#include <iostream>      //入出力
#include <iterator>      //集合演算(積集合,和集合,差集合など)
#include <map>           //map(辞書)
#include <numeric>       //iota(整数列の生成),gcdとlcm(c++17)
#include <queue>         //キュー
#include <set>           //集合
#include <stack>         //スタック
#include <string>        //文字列
#include <unordered_map> //イテレータあるけど順序保持しないmap
#include <unordered_set> //イテレータあるけど順序保持しないset
#include <utility>       //pair
#include <vector>        //可変長配列

using namespace std;
typedef long long ll;
typedef pair< ll, ll > P;

//マクロ
#define REP(i, n) for (ll i = 0; i < (ll)(n); i++)
#define REPD(i, n) for (ll i = (ll)(n)-1; i >= 0; i--)
#define FOR(i, a, b) for (ll i = (a); i <= (b); i++)
#define FORD(i, a, b) for (ll i = (a); i >= (b); i--)
#define ALL(x) (x).begin(), (x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size())      //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x))
#define INF 1000000000000 //10^12
#define MOD 1000000007    //10^9+7
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define MAXR 100000 //10^5:最大のrange(素数列挙などで使用)

// debug
#define DEBUG(x) cout << #x << ": " << x << endl
#define DEBUG2(x, y) cout << #x << ": " << x << " " << #y << ": " << y << endl
#define DEBUG_VEC(v)   \
  cout << #v << ":";   \
  REP(i, v.size())     \
  cout << " " << v[i]; \
  cout << endl
#define DEBUG_ARR(v, n) \
  cout << #v << ":";    \
  REP(i, n)             \
  cout << " " << v[i];  \
  cout << endl

signed main()
{
  ll A, B, C, K;
  cin >> A >> B >> C >> K;

  ll ans = 0;
  if (K > A)
  {
    K -= A;
    ans += A;
  }
  else
  {
    cout << K << endl;
    return 0;
  }
  if (K > B)
  {
    K -= B;
  }
  else
  {
    cout << ans << endl;
    return 0;
  }
  cout << ans - K << endl;
  return 0;
}

Measured memory_bytes: 3592
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <queue>
#include <map>
typedef long long LL;

int int_vector_find(std::vector<int> vec, int num) {
	auto itr = std::find(vec.begin(), vec.end(), num);
	int index = std::distance(vec.begin(), itr);

	if (index != vec.size()) {
		return 1;
	}
	else {
		return 0;
	}
}

int main() {
	std::vector<int> n;
	int ans = 0;
	for (int i = 0; i < 5; ++i) {
		int a;
		std::cin >> a;
		n.push_back(a);
	}
	int temp = 9;
	bool hoge = false;

	for (int i = 0; i < 5; ++i) {
		if (n[i] % 10 <= temp%10 && n[i] % 10 !=0) {
			temp = n[i];
			hoge = 1;
		}
	}

	for (int i = 0; i < 5; ++i) {
		if (n[i] != temp||hoge==false) {
			if (n[i] % 10 == 0) {
				ans += n[i];
			}
			else {
				ans += n[i] / 10 * 10 + 10;
			}
		}
		else {
			ans += temp;
			hoge = false;
		}
	}

	
		std::cout << ans << std::endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N,x;
  cin>>N;
  vector<int> A(N);
  vector<int> B(N);
  for(int i=0;i<N;i++){
    cin>>x;
    A.at(i)=x;
    B.at(i)=x;
  }
  sort(B.begin(), B.end());
  reverse(B.begin(), B.end());
  for(int i=0;i<N;i++){
    if(A.at(i)==B.at(0)){
      cout<<B.at(1)<<endl;
    }
    else{
      cout<<B.at(0)<<endl;
    }
  }
}

Measured memory_bytes: 3200
#include<stdio.h>
#include<iostream>
#include<iomanip>
#include<string>
#include<vector>
#include<queue>
#include<stack>
#include<map>
#include<set>
#include<algorithm>
#include<string>
#include<math.h>
using namespace std;

const int MAX = 200000;

int N,K;
int A[MAX];

bool check(int len){
    int c = 0;
    for(int i = 0;i < N;i++){
        c += (A[i] - 1) / len;
    }
    return c <= K;
}

int main(){
    cin >> N >> K;
    for(int i = 0;i < N;i++){
        cin >> A[i];
    }

    int l = 1;
    int r = pow(10,9);
    int m = 0;
    int ans = pow(10,9);

    while(l < r){
        m = (l + r) / 2;
        if(check(m)){
            r = m;
            ans = min(ans,m);
        }else{
            l = m + 1;
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3944
a, b, x = map(int, input().split())
import math

S = a*b
s = x/a
if s == S:
  print(0)

elif s >= S/2:
  em_s = S-s
  tan = (a**2)/(2*em_s)
  ans = math.degrees(math.atan(tan))
  print(90-ans)

else:
  tan = (2*s)/(b**2)
  ans = math.degrees(math.atan(tan))
  print(90-ans)

Measured memory_bytes: 9324
#include<iostream>
#include<algorithm>
#include<queue>
#include<vector>
#include<string>
using namespace std;
int main() {
	int n; cin >> n;
	string s;
	priority_queue<string>que;
	long long cntall = 0,cntsome;
	for (int i = 0; i < n; ++i) {
		cin >> s;
		sort(s.begin(), s.end());
		que.push(s);
	}
	while (!que.empty()&&que.size()!=1){
		cntsome = 0;
		string a = que.top();
		que.pop();
		string b = que.top();
		if(a==b) que.pop();
		while (a == b) {
			++cntsome;
			if (que.empty()) break;
			a = b;
			b = que.top();
			if(a==b) que.pop();
		}
		for (int i = 1; i <= cntsome; ++i) {
			cntall += i;
		}
	}
	cout << cntall << endl;
	return 0;
}

Measured memory_bytes: 5748
#include <iostream>
#include <algorithm>
#include <bitset>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <complex>
#include <string.h>
#include <numeric>
using namespace std;

//#define int long long
#define reps(i,s,n) for(int (i)=(s);(i)<(n);++(i))
#define rep(i,n) reps(i,0,n)
#define rept(i,n) rep(i,(n)+1)
#define repst(i,s,n) reps(i,s,(n)+1)
#define reprt(i,n,t) for(int (i)=(n);(i)>=(t);--(i))
#define repr(i,n) reprt(i,n,0)
#define each(i,v) for(auto &(i):(v))
#define eachr(i,v) for(auto &(i)=(v).rbegin();(i)!=(v).rend();(i)++)
#define all(c) (c).begin(),(c).end()
#define rall(c) (c).rbegin(),(c).rend()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define tmax(x,y,z) max(x,max(y,z))
#define tmin(x,y,z) min(x,min(y,z))
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
#define ln '\n'
#define bln(i,n) (((i)==(n)-1)?'\n':' ')
#define dbg(x) cout<<#x" = "<<(x)<<ln<<flush
#define dbga(x,n) {cout<<#x" : ";for(int (i)=0;i<(n);++i){cout<<((x)[i])<<(i==((n)-1)?'\n':' ')<<flush;}}
#define zero(a) memset(a,0,sizeof(a))
#define unq(a) sort(all(a)),a.erase(unique(all(a)),a.end())

//typedef complex<double> P;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<string> vst;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
typedef vector<vector<int> > mat;

const ll inf = (ll)1e9+10;
const ll linf = (ll)1e18+10;
const ll mod = (ll)(1e9+7);
const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};
const int ddx[] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[] = {1, 1, 0, -1, -1, -1, 0, 1};
const double eps = 1e-10;

ll mop(ll a,ll b,ll m=mod) {ll r=1;a%=m;for(;b;b>>=1){if(b&1)r=r*a%m;a=a*a%m;}return r;}
ll gcd(ll a,ll b) {return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b) {return a/gcd(a,b)*b;}
bool ool(int x,int y,int h,int w) {return((x<0)||(h<=x)||(y<0)||(w<=y));}
bool deq(double a,double b) {return abs(a-b)<eps;}

struct oreno_initializer {
	oreno_initializer() {
		cin.tie(0);
		ios::sync_with_stdio(0);
	}
} oreno_initializer;



int n, d, x, a, res;

signed main() {
	cin >> n >> d >> x;
	res = x;
	rep(i,n) {
		cin >> a;
		for (int j=1; j<=d; j+=a) res++;
	}
	cout << res << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ld long double
int main()
{
	int n;
	cin>>n;
	vector<ld>dp(n+1);
	dp[0]=1;
	for(int coins = 1;coins<=n;coins++)
	{
		ld c;
		cin>>c;
		for(int j=coins;j>=0;j--)
		{
			dp[j] = (j==0?0:dp[j-1]*c)+dp[j]*(1-c);
		}
	}
	ld ans = 0;
	for(int heads = 0;heads<=n;heads++)
	{
		int tails = n-heads;
		if(heads>tails)
		{
			ans += dp[heads];
		}
	}
	cout<<setprecision(10)<<ans<<"\n";
	return 0;
}


Measured memory_bytes: 384
#include<stdio.h>
main(){
    unsigned long a[1000],b[1000],tmp_a[1000],tmp_b[1000];
    int i,j;
    for(j=0;scanf("%ld %ld",&a[j],&b[j])!=EOF;j++);
     
    for(i=0;i<j;i++){
        tmp_a[i]=a[i];
        tmp_b[i]=b[i];
    }
    unsigned long r[1000],tmp,gcd[1000],lcm[1000];
    for(i=0;i<j;i++){
        while(abs(a[i]-b[i])!=0){
            if(a[i]<b[i]){
                tmp=a[i];
                a[i]=b[i];
                b[i]=tmp;
            }
            r[i]=a[i]-b[i];
            a[i]=b[i];
            b[i]=r[i];
        }
        gcd[i]=b[i];
    }
    for(i=0;i<j;i++){
        lcm[i]=(tmp_a[i]*tmp_b[i])/gcd[i];
    }
    for(i=0;i<j;i++){
        printf("%ld %ld\n",gcd[i],lcm[i]);
    }
    return 0;
}

Measured memory_bytes: 624
using System;

public class Program {

        public static void Main(string[] args) {

            var input = Console.ReadLine().Split();

            var a1 = int.Parse(input[0]);
            var a2 = int.Parse(input[1]);
            var a3 = int.Parse(input[2]);

            if(a1 + a2 + a3 >= 22) {

                Console.WriteLine("bust");

            } else {

                Console.WriteLine("win");

            }


        }

    }

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

using namespace std;

int main(void){
    
    int n;
    cin >> n;
    
    vector<int> a(n);
    for (int i = 0; i < n; i++) cin >> a[i];
    
    const int M = 1000005;
    
    vector<int> cnt(M);
    
    for (int x : a){
        if (cnt[x] != 0){
            cnt[x] = 2;
            continue;
        }
        else{
            for (int i = x; i < M; i+=x) cnt[i]++;
        }
    }
    int ans = 0;
    for (int x : a){
        if (cnt[x] == 1) ans++;
    }
    cout << ans << endl;
}


Measured memory_bytes: 7980
MOD=998244353
from collections import Counter
N=int(input())
D=list(map(int,input().split()))
if D[0]!=0:
    print(0)
    exit()
c=sorted(Counter(D[1:]).most_common(),key=lambda x:x[0])
ans=1
for i in range(1,len(c)):
    if(c[i][0]!=i+1):
        print(0)
        exit()
    ans=(ans*pow(c[i-1][1],c[i][1],MOD))%MOD
print(ans)

Measured memory_bytes: 74420