akhauriyash/Code-Regression huggingface dataset:
from collections import defaultdict
n, a = map(int, input().split())
x = list(map(int, input().split()))

dp = [defaultdict(int) for _ in range(n+1)]
dp[0][a] += 1

for i, x_i in enumerate(x):
    for p in dp[i].keys():
        pk = p + a - x_i
        dp[i+1][pk] += dp[i][p]
        dp[i+1][p] += dp[i][p]

print(dp[n][a] - 1)

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

int main(){
    int k;
    vector<int> in(3);
    cin >> in[0] >> in[1] >>in[2] >>k;
    sort(in.begin(),in.end());
    cout << in[2]*pow(2,k)+in[1]+ in[0]<<endl;
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(void)
{
	int s, h, m;
	scanf("%d", &s);
	h = s / 3600;
	m = s % 3600;
	m = m / 60;
	s = s % 60;
	printf("%d:%d:%d\n", h, m, s);
	return 0;
}


Measured memory_bytes: 2104
# N = 10
# X = '1'*N
N = int(input())
X = input()
popcount_X = X.count('1')
X_ = int(X, 2)

X_mod_minus = X_%(popcount_X-1) if popcount_X > 1 else -1
X_mod_plus = X_%(popcount_X+1)
for i in range(N):
    if X[i] == '0':
        popcount = popcount_X+1
        X_i = (X_mod_plus + pow(2, N-i-1, popcount))%(popcount)
    else:
        if X_mod_minus == -1:
            print(0)
            continue
        popcount = popcount_X-1
        X_i = (X_mod_minus - pow(2, N-i-1, popcount))%(popcount)
    ans = 1
    while X_i > 0:
        X_i %= bin(X_i).count('1')
        ans += 1
    print(ans)

Measured memory_bytes: 9440
#include <cstdio>

int main()
{
    int M1, M2, D1, D2;
    scanf("%d%d%d%d", &M1, &D1, &M2, &D2);
    if (M1 == M2)
    {
        printf("%d\n", 0);
    }
    else
    {
        printf("%d\n", 1);
    }
    return 0;
}

Measured memory_bytes: 128
#include <stdio.h>
long GCD(long a,long b)
{
  long temp;
  while(b!=0)
    {
      temp=a%b;
      a=b;
      b=temp;
    }
  return a;
}

long LCM(long a,long b,long GCD)
{
  return a*(b/GCD);
}

int main(void)
{
  long a,b,G,L,temp;
  while (scanf("%d %d",&a,&b)!=EOF)
    {
      if (a<b)
        {
          temp=a;
          a=b;
          b=temp;
        }
      G=GCD(a,b);
      L=LCM(a,b,G);
      printf("%d %d\n",G,L);
    }
  return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <string>
#include <vector>
#include <math.h>
#include <queue>
#include <deque>
#include <map>
const int MOD = 1e9+7;
#define PI 3.14159265359
typedef long long ll;
using namespace std;

int ctoi(char c){
	return c - '0';
}


int main(){
	double a, b, h, m;
	cin >> a >> b >> h >> m;
	double hour = h*2*PI/12 + m*2*PI/720;
	double mini = m*2*PI/60;
	double hoge = hour - mini;
	cout <<setprecision(10) << sqrt(a*a + b*b - 2*a*b*cos(hoge)) << endl;
	return 0;
}


Measured memory_bytes: 4212
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
ll gcd(ll a, ll b) {
    return b ? gcd(b, a % b) : a;
}
int main() {
    ll A, B, x;
    cin >> A >> B;
    ll g = gcd(A, B), ret = 1;
    for(ll i = 2; i * i <= g; i++) {
        if(g % i == 0) {
            while(g % i == 0) {
                g /= i;
            }
            ret++;
        }
    }
    cout << ret+(g!=1) << endl;
    return 0;
}

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

int main(void){
	string s,t;
  	cin >> s;
  	cin >> t;
  	t.pop_back();
  	if(t == s) cout << "Yes";
    else cout << "No";
	return 0;
}

Measured memory_bytes: 3612
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayList;

public class Main {
	public static void main(String[] args) {
		try {
			BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
			int n = Integer.parseInt(br.readLine());
			String in2 = br.readLine();
			ArrayList<Integer> oddList = new ArrayList<Integer>();
			ArrayList<Integer> evenList = new ArrayList<Integer>();
			for(String str:in2.split(" ")){
				int i = Integer.parseInt(str);
				if(i%2 == 0){
					evenList.add(i);
				}else{
					oddList.add(i);
				}
			}

			while(true){
				if(oddList.size() > 1){
					int i = oddList.get(0) + oddList.get(1);
					oddList.remove(1);
					oddList.remove(0);
					if( i%2 == 0 ){
						evenList.add(i);
					}else{
						oddList.add(i);
					}
				}else if(evenList.size() > 1){
					int i = evenList.get(0) + evenList.get(1);
					evenList.remove(1);
					evenList.remove(0);
					if( i%2 == 0 ){
						evenList.add(i);
					}else{
						oddList.add(i);
					}
				}else{
					int i = evenList.size() + oddList.size();
					if(i == 1){
						System.out.println("YES");
					}else{
						System.out.println("NO");
					}
					break;
				}
			}
		}catch( Exception e ){

		}
	}

}


Measured memory_bytes: 49884
n = int(input())
d, x = map(int,input().split())
a = []
for i in range(n):
    a.append(int(input()))

choco = x
for i in range(n):
    for day in range(d):
        if a[i]*day+1 < d+1:
            choco += 1
print(choco)

Measured memory_bytes: 3060
n = int(input())
parent = [-1] * n
left   = [-1] * n
right  = [-1] * n
sibling = [-1] * n
degree  =  [0] * n
depth   =  [0] * n
for i in range(n):
    x = list(map(int, input().split()))
    left[x[0]]  = x[1]
    right[x[0]] = x[2]
    children = 0
    if x[1] != -1:
        parent[x[1]] = x[0]
        sibling[x[1]] = x[2]
        children += 1
    if x[2] != -1:
        parent[x[2]] = x[0]
        sibling[x[2]] = x[1]
        children += 1
    degree[x[0]] = children
def setDepth(u, p, d):
    d[u] = p
    if right[u] != -1:
        setDepth(right[u], p + 1, d)
    if left[u] != -1:
        setDepth(left[u], p + 1, d)
    return d
def getHeight(u, p, height):
    height += [p]
    if right[u] != -1:
        getHeight(right[u], p + 1, height)
    if left[u] != -1:
        getHeight(left[u], p + 1, height)
    return max(height)
def howNode(u):
    if parent[u] == -1:
        return 'root'
    elif left[u] == right[u] == -1:
        return 'leaf'
    else:
        return 'internal node'
root = parent.index(-1)
setDepth(root, 0, depth)
for i in range(n):
    print('node '+str(i)+': parent = '+str(parent[i])
    +', sibling = '+str(sibling[i])+', degree = '+
    str(degree[i])+', depth = '+str(depth[i])+', height = '
    +str(getHeight(i, 0, []))+', '+howNode(i))


Measured memory_bytes: 5616
#pragma GCC optimize ("O2")
#pragma GCC target ("avx2")
//#include<bits/stdc++.h>
#include<cstdio>
#include<algorithm>
#include<cstring>

using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please

const int CM = 1 << 17, CL = 12;
char cn[CM + CL], * ci = cn + CM + CL, * owa = cn + CM, ct;
const ll ma0 = 1157442765409226768;
const ll ma1 = 1085102592571150095;
const ll ma2 = 71777214294589695;
const ll ma3 = 281470681808895;
const ll ma4 = 4294967295;
inline int getint() {
	if (ci - owa > 0) {
		memcpy(cn, owa, CL);
		ci -= CM;
		fread(cn + CL, 1, CM, stdin);
	}
	ll tmp = *(ll*)ci;
	if ((tmp & ma0) ^ ma0) {
		int dig = 68 - __builtin_ctzll((tmp & ma0) ^ ma0);
		tmp = tmp << dig & ma1;
		tmp = tmp * 10 + (tmp >> 8) & ma2;
		tmp = tmp * 100 + (tmp >> 16) & ma3;
		tmp = tmp * 10000 + (tmp >> 32) & ma4;
		ci += (72 - dig >> 3);
	}
	else {
		tmp = tmp & ma1;
		tmp = tmp * 10 + (tmp >> 8) & ma2;
		tmp = tmp * 100 + (tmp >> 16) & ma3;
		tmp = tmp * 10000 + (tmp >> 32) & ma4;
		ci += 8;
		if ((ct = *ci++) >= '0') {
			tmp = tmp * 10 + ct - '0';
			if (*ci++ == '0') {
				tmp = tmp * 10;
				ci++;
			}
		}
	}
	return tmp;
}
const int mod = 1e9 + 7;
int main() {
	//cin.tie(0);
	//ios::sync_with_stdio(false);

	int N = getint();
	ll kei = 0;
	ll kei2 = 0;
	ll kei3 = 0;
	const ll ma = (1ll << 60) - 1;
	rep(i, N) {
		ll a = getint();
		kei += a;
		kei2 += a * a;
		kei3 += kei2 >> 60;
		kei2 &= ma;
	}
	kei %= mod;
	kei = kei * kei % mod;

	kei2 = kei2 % mod;
	kei3 %= mod;
	kei3 = kei3 * ((1ll << 60) % mod) % mod;
	kei = (kei - kei2 - kei3 + mod + mod) % mod;

	kei = kei * (mod / 2 + 1) % mod;

	printf("%d\n", kei);


	Would you please return 0;
}

Measured memory_bytes: 1688
#include <bits/stdc++.h>
#define FOR(i, a, n) for(ll i = (ll)a; i < (ll)n; i++)
#define rep(i, n) FOR(i, 0, n)
#define ALL(x) (x).begin(), (x).end()
using namespace std;
typedef long long ll;

constexpr int mod = 1e9 + 7;

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

/*-------------------------------------------*/

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

    int n, q, s[100009];

    cin >> n;
    rep(i, n) cin >> s[i];
    sort(s, s + n);

    int ans = 0;
    cin >> q;
    while(q--) {
        int t;
        cin >> t;
        if(binary_search(s, s + n, t)) ans++;
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3532
#include<iostream>
#include<cctype>
#include<cstdio>
#include<cstring>
#include<string>
using namespace std;
string reverse(string str) {
    string result = "";
    for (int i = str.size()-1;  0 <= i; i--) {
        result += str[i];
    }
    return result;
}
int main(){
    string str;
    int q;
    string command;
    string PRINT = "print";
    string REVERSE = "reverse";
    string REPLACE = "replace";
    int a,b;
    string target;
    cin >> str;
    cin >> q;
    
    for (int i = 0; i < q; i++) {

        cin >> command;
        if (command == PRINT){
            cin >> a >> b;
            // cout << PRINT  << "A : " << a << " B : " << b << endl;
        //    cout << str.substr(a, b+1) <<endl;
           cout << str.substr(a,b - a + 1) << endl;
        }
        if (command == REVERSE) {
            cin >> a >> b;
            // cout << REVERSE  << "A : " << a << " B : " << b << endl;
            str =  str.substr(0,a) + reverse(str.substr(a,b-a+1)) + str.substr(b+1,str.size()-1);
            // cout << str.substr(0,a) << reverse(str.substr(a,b-a+1)) << str.substr(b+1,str.size()-1) << endl; 
            
        } 
        if (command == REPLACE) {
            cin >> a >> b >> target;
            // cout << REPLACE << " A : " << a << " B : " << b << " Target : " << target;
            str = str.replace(a,b-a+1,target);
            // cout << "REPLACED " << str <<  " " <<endl;
            // cout << REPLACE << " : " << str  << endl;
           
        }
        
    }
    
    
    
    return 0;
}

Measured memory_bytes: 1232
#pragma region

#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define _rep3(i, begin, end) for (register int i = (begin), i##_end = (end); i < i##_end; i++)
#define _irep3(i, begin, end) for (register int i = (end)-1, i##_begin = (begin); i >= i##_begin; i--)
#define _rep2(i, n) _rep3(i, 0, n)
#define _irep2(i, n) _irep3(i, 0, n)
#define _overload3(_1, _2, _3, name, ...) name
#define rep(...) _overload3(__VA_ARGS__, _rep3, _rep2, )(__VA_ARGS__)
#define irep(...) _overload3(__VA_ARGS__, _irep3, _irep2, )(__VA_ARGS__)
#define out(x) cout << (x) << '\n';
#define debug(x) cerr << #x << " = " << (x) << " (line: " << __LINE__ << ") " << endl;

using namespace std;
using ll = long long;
using vi = vector<int>;
using vl = vector<long long>;
using vb = vector<bool>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<long long>>;
using vvb = vector<vector<bool>>;

template <typename T>
istream &operator>>(istream &is, vector<T> &vec) {
  for (auto &v : vec) is >> v;
  return is;
}
template <typename T1, typename T2>
istream &operator>>(istream &is, pair<T1, T2> &pair) {
  cin >> pair.first >> pair.second;
  return is;
}
template <typename T>
ostream &operator<<(ostream &os, const vector<T> &vec) {
  os << "[ ";
  rep(i, vec.size()) i == 0 ? os << vec[i] : os << ", " << vec[i];
  os << " ]";
  return os;
}

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

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

void init() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(16);
}

#pragma endregion

#define MOD 1000000007
#define INF 2147483647

int main() {
  init();

  int N, K;
  cin >> N >> K;
  int A[2][N];
  rep(i, N) cin >> A[0][i];
  rep(i, N) A[1][i] = 0;

  int temp[N * 3 + 1] = {};

  bool fr;
  rep(i, K) {
    fr = i % 2;

    bool updated = false;
    rep(i, N) {
      temp[N + i - A[fr][i]]++;
      temp[N + i + A[fr][i] + 1]--;
    }
    int now = 0;
    rep(i, N * 3) {
      now += temp[i];
      if (i >= N && i < N * 2) {
        if (A[!fr][i - N] != now) {
          A[!fr][i - N] = now;
          updated = true;
        }
      }
      temp[i] = 0;
    }

    if (!updated) {
      break;
    }
  }

  rep(i, N) {
    cout << A[!fr][i];
    if (i == N - 1) {
      cout << endl;
    } else {
      cout << ' ';
    }
  }
}


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

int main(void) {
  int X;
  cin >> X;

  int ans = 0;
  for (int i = 1; i <= X; i++) {
    for (int j = 2; pow(i, j) <= X; j++) {
      if (pow(i, j) <= X) {
        int tmp = pow(i, j);
        if (tmp > ans) {
          ans = tmp;
        }
      }
      if (i == 1) {
        break;
      }
    }
  }

  cout << ans << endl;
}

Measured memory_bytes: 640
book = []
while True :
    try :
        A = list(input().split())
    except EOFError :
        break
    
    new_word = "ON"
    for i in range(len(book)) :
        if A[0] in book[i] :
            book[i].append(A[1])
            new_word = "OFF"
    if new_word == "ON" :
        book.append([A[0], A[1]])
    
book.sort()
for i in range(len(book)) :
    print(book[i][0])
    page = list(int(book[i][j]) for j in range(1, len(book[i])))
    print(*sorted(page))


Measured memory_bytes: 5620
#include<bits/stdc++.h>
    using namespace std;
  #define int long long int
    #define endl "\n"
    #define MOD 1000000007
    #define mod 1000000007
    #define M 1000000007

    #define pb push_back
    #define take(a,b,c) for(int b=0;b<c;b++) cin>>a[b]
  //  #define mp make_pair
  #define boost ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
  #define mx 400005
  #define fiint(a,b) memset(a,b,sizeof(a))
  #define bitcount __builtin_popcount
  #define fori(i,a,b) for(int i=a;i<b;i++)
  #define ford(i,a,b) for(int i=a;i>=b;i--)
  #define debug(x) cout<<x<<endl;
  #define cases(t) int t; cin>>t; while(t--)
  #define inf1 INT_MAX
  #define all(a) a.begin(),a.end()
  #define vec vector<int>
  #define pii pair<int,int>
  #define plii pair<int,int>
  #define pint pair<int,int>
  #define ff first
  #define ss second
  #define lb lower_bound
  #define ub upper_bound
  #define bs binary_search
  #define sz(x) (int)x.size()
#define PI                    3.14159265359

bool prime[10000001];

void sieveFunction(int maxLimit){
    memset(prime, true, sizeof(prime));
    prime[0] = prime[1]=false;
    for(int i=2; maxLimit >= i ; i++){
        if(prime[i]){
            for(int j=2*i ; maxLimit >= j ; j+=i)
                prime[j]=false;
        }
    }
}
vec v(mx);
vec tree(mx,-1);

signed  main()
{
  //  cout<<"df"<<endl;
    int n ;cin>>n;
    int sum = 0 ;
    map<int,int> m ;
    for(int i = 0 ; i < n ;i++){cin>>v[i];sum+=v[i]; m[v[i]]++;}
    int q ;cin>>q;
    for(int i = 0 ; i < q;i++)
    {
        int b , c ;cin>>b>>c;
        int cnt = 0;
        if(m.find(b)!=m.end())
        {cnt = m[b]; m.erase(b); m[c] += cnt; }
        sum += (c - b)*cnt;
        cout<<sum<<endl;
    }

}


Measured memory_bytes: 13468
import collections,sys
def I(): return int(sys.stdin.readline().rstrip())
N = I()
def primeFactor(num):
    prime_factor = collections.defaultdict(int)
    for i in range(2,int(num**0.5)+1):
        while num%i==0:
            prime_factor[i] += 1
            num //= i
    if num>1:
        prime_factor[num]=1
    return prime_factor
sequence = []
for i in range(1,50):
    sequence.append(i*(i+1)//2)
ans = 0
for v in primeFactor(N).values():
    for j,x in enumerate(sequence,1):
        if v<x:
            ans += j-1
            break
print(ans)


Measured memory_bytes: 9724
#include <iostream>
#include <algorithm>
#include <string>
#include <string.h>
#include <math.h>
#include <cmath>
#include <tuple>
#include <vector>
#include <bitset>
#include <stack>
#include <iomanip>
#include <set>
#include <queue>
#include <map>


typedef long long ll;
typedef unsigned long long ull;
#define mk make_pair
#define mkt make_tuple

using namespace std;
int const N = 4000;
ll count_sub(string s, string p) {
	ll dp[4000][3];
	memset(dp, 0, sizeof(dp));
	dp[0][0] = s[0] == p[0];
	for (int i = 1; i < s.length(); i++)
		dp[i][0] = dp[i-1][0] + (s[i] == p[0]);
	for (int i = 1; i < 3; i++) {
		for (int j = i; j < s.length(); j++) {
				dp[j][i] = dp[j - 1][i] + (s[j] == p[i]?dp[j-1][i-1]:0);
		}
	}
	return dp[s.length()-1][2];
}
int main()
{
	ll n; string s;
	cin >> n >> s;
	ll ans = count_sub(s, "RGB") + count_sub(s, "GRB") + count_sub(s, "BRG")
		+ count_sub(s, "RBG") + count_sub(s, "GBR") + count_sub(s, "BGR");
	for (int i = 0; 2 + 2 * i < n; i++) {
		for (int j = 0; j + 2 + 2 * i < n; j++)
			if (s[j] != s[j + 1 + i] && s[j] != s[j + 2 + 2 * i] && s[j + 1 + i] != s[j + 2 + 2 * i])
				ans--;
	}
	cout << ans;
}


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


int main() {

  long long N;
  cin >> N;

  int c,num = 0;
  bool nine = true;
  while(N > 0) {
    c = N % 10;
    if(N >= 10 && c != 9) nine = false;
    N /= 10;
    num++;
  }

  if(nine) {
    cout << c + 9*(num-1) << endl;
  }else {
    cout << c + 9*(num-1) -1 << endl;
  }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = 1e18;
const ll MOD = 1e9 + 7;
#define all(v) v.begin(), v.end()
#define repi(i, n, init) for (ll i = init; i < (n); i++)
#define repd(i, n, init) for (ll i = (n); i >= init; i--)
#define repm(i, m) for (auto i = m.begin(); i != m.end(); i++)

int main()
{
    string A, B, C;
    cin >> A >> B >> C;
    cout << (A.at(A.length() - 1) == B.at(0) && B.at(B.length() - 1) == C.at(0) ? "YES" : "NO") << endl;
    return 0;
}

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

const static ll MOD = (1e+9)+7;

ll modpow(ll a,ll n){
    if(n==0)return 1;
    if(n%2==1)return a*modpow(a,n-1)%MOD;
    ll t = modpow(a,n/2) % MOD;
    return t*t % MOD;
}

int main(){
    int s,w;cin>>s>>w;
    cout<<(s<=w ? "unsafe":"safe")<<endl;
    return 0;
}

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

vector<P>E[100000];
int d[100000];
P G[200000];
int s[100000], t[100000], l[100000], r[100000];
vector<int>x[200000];

int par[100000];
int find(int x) {
	if (par[x] == x)return x;
	return par[x] = find(par[x]);
}
void unite(int x, int y) {
	x = find(x); y = find(y);
	if (x != y)par[x] = y;
}
int main() {
	int n, m, k, q; scanf("%d%d%d%d", &n, &m, &k, &q);
	rep(i, m) {
		int a, b, l; scanf("%d%d%d", &a, &b, &l); a--; b--;
		E[a].push_back(P(l, b)); E[b].push_back(P(l, a));
		G[i] = P(a, b);
	}
	memset(d, 0x3f, sizeof(d));
	priority_queue<P, vector<P>, greater<P>>que;
	rep(i, k) {
		int f; scanf("%d", &f); f--;
		d[f] = 0; que.push(P(0, f));
	}
	while (!que.empty()) {
		P p = que.top(); que.pop();
		if (d[p.second] != p.first)continue;
		for (P u : E[p.second]) {
			if (d[u.second] > p.first + u.first) {
				d[u.second] = p.first + u.first;
				que.push(P(d[u.second], u.second));
			}
		}
	}
	sort(G, G + m, [](P a, P b) {
		return min(d[a.first], d[a.second]) > min(d[b.first], d[b.second]);
	});
	rep(i, q) {
		scanf("%d%d", &s[i], &t[i]); s[i]--; t[i]--;
		r[i] = m - 1;
	}
	rep(k, 20) {
		rep(i, m)x[i].clear();
		rep(i, n)par[i] = i;
		rep(i, q)x[(l[i] + r[i]) / 2].push_back(i);
		rep(i, m) {
			unite(G[i].first, G[i].second);
			for (int j : x[i]) {
				if (find(s[j]) == find(t[j]))r[j] = i;
				else l[j] = i + 1;
			}
		}
	}
	rep(i, q)printf("%d\n", min(d[G[l[i]].first], d[G[l[i]].second]));
}

Measured memory_bytes: 31024
x1,y1,x2,y2 = map(int,input().split())
 
x = x2 - x1
y = y1 - y2
 
x3 = x2 + y
y3 = y2 + x
x4 = x3 - x
y4 = y3 + y

print(x3,y3,x4,y4)


Measured memory_bytes: 9136
import numpy as np

def main():
    n, s = map(int, input().split())
    nums = [int(c) for c in input().split()]
    mod = 998244353
    dp = np.zeros(s+1, dtype=np.int)
    ans = 0

    for i, num in enumerate(nums, 1):
        dp[0] = i
        if num <= s:
            dp[num:] = dp[num:] + dp[:-num]
            # print(dp)
        dp %= mod
        ans = (ans + dp[-1]) % mod
    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 12516
#include<stdio.h>
#include<stdlib.h>
#include<string.h>

int closest(int a, int b, int *c, int *d, int M) {
	int i;
	int x, y;
	int ol_dist, new_dist;
	int point;
	for(i = 0; i < M; i += 1) {
		if (a > c[i]) {
			x = a - c[i];
		} else {
			x = c[i] - a;
		}
		if (b > d[i]) {
			y = b - d[i];
		} else {
			y = d[i] - b;
		}
		if(i == 0) {
			ol_dist = x + y;
			point = 0;
		} else {
			new_dist = x + y;
			if(new_dist < ol_dist) {
				ol_dist = new_dist;
				point = i;
			}
		}
	}
	return point;
}

int main(void) {
	int i;
	int N, M;
	int *a, *b, *c, *d;
	char buf[128], *ch;

	fgets(buf, sizeof(buf), stdin);
	ch = strtok(buf, " ");
	N = atoi(ch);
	ch = strtok(NULL, " ");
	M = atoi(ch);

	a = (int *)calloc(N, sizeof(int));
	b = (int *)calloc(N, sizeof(int));
	c = (int *)calloc(M, sizeof(int));
	d = (int *)calloc(M, sizeof(int));

	for(i = 0; i < N; i += 1) {
		fgets(buf, sizeof(buf), stdin);
		ch = strtok(buf, " ");
		a[i] = atoi(ch);
		ch = strtok(NULL, " ");
		b[i] = atoi(ch);
	}
	for(i = 0; i < M; i += 1) {
		fgets(buf, sizeof(buf), stdin);
		ch = strtok(buf, " ");
		c[i] = atoi(ch);
		ch = strtok(NULL, " ");
		d[i] = atoi(ch);
	}

	for(i = 0; i < N; i += 1) {
		printf("%d\n", 1 + closest(a[i], b[i], c, d, M));
	}

	free(a);
	free(b);
	free(c);
	free(d);
	return 0;
}


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

namespace past10.Abc
{
    public class Question8
    {
        public static void Main(string[] args)
        {
            var sw = new System.IO.StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);

            var Arr = Console.ReadLine().Split(' ').Select(i => long.Parse(i)).ToArray();

            long N = Arr[0];
            long Y = Arr[1];
            string ans = "-1 -1 -1";
            bool isExit = false;
            for(long x=0;x<=N;++x){
                for(long y=0;y<=N-x;++y){
                    long z = N-x-y;
                    if(10000*x+5000*y+1000*z == Y){
                        ans = x + " " + y + " " + z;
                        isExit = true;
                        break;
                    }
                }
                if(isExit) break;
            }
            Console.WriteLine(ans);

            Console.Out.Flush();
        }
    }
}

Measured memory_bytes: 28252
#include<algorithm>//sort,二分探索,など
#include<bitset>//固定長bit集合
#include<cmath>//pow,logなど
#include<complex>//複素数
#include<deque>//両端アクセスのキュー
#include<functional>//sortのgreater
#include<iomanip>//setprecision(浮動小数点の出力の誤差)
#include<iostream>//入出力
#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;

//マクロ
#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 10000007 //10^9+7
#define PB push_back
#define MP make_pair

int N;
int h[1000000] = {};
ll dp[1000000] = {};

int rec(int p){
    int ans;
    
    if(dp[p]>=0){
        ans=dp[p];
    
    }else if (p == N-1)
    {
        ans = 0;
    
    }else if (p==N-2)
    {
    
        ans=abs(h[p]-h[p+1]);
    }else{
    
        ans = min(rec(p+1)+abs(h[p]-h[p+1]),rec(p+2)+abs(h[p]-h[p+2]));
    }
    
    dp[p] = ans;
    
    return ans;
    
    
}

int solve(){
   
   cin >> N;

   REP(i,N){
       cin >> h[i];
       dp[i] = -1;
   }

   cout << rec(0)<< endl;


    return 0;
}

int main(){
    solve();
}

Measured memory_bytes: 6656
<?php
	$n = trim( fgets( STDIN ) );
	$nums = [];
	for( $i=0; $i<$n; $i++ ) {
		array_push( $nums, intval( trim( fgets( STDIN ) ) ) );
	}
	$cnt = $n;
	$nums2 = [];
	$size = count( $nums );
	for( $j=0; $j<$size; $j++ ) {
		if( 0 == $nums[$j]%2 ) {
			if( 2 != $nums[$j]) { $cnt--; }
		} else {
			array_push( $nums2, $nums[$j] );
		}
	}
	$nums = $nums2;
	$end = max( $nums );
	for( $i=3; $i*$i<=$end; $i+=2 ) {
		$nums2 = [];
		$size = count( $nums );
		for( $j=0; $j<$size; $j++ ) {
			if( 0 == $nums[$j]%$i )  {
				if( $nums[$j] != $i ) {
					$cnt--;
				}
			} else {
				array_push( $nums2, $nums[$j] );
			}
		}
		$nums = $nums2;
	}
	print $cnt;
?>

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

using namespace std;

int main()
{
    int n;
    
    while (cin >> n) {
        if (!n)
            break;

        vector<int> wait;
        int tmp;

        for (int i = 0; i < n; i++) {
            cin >> tmp;
            wait.push_back(tmp);
        }
        sort(wait.begin(), wait.end());

        long sum = 0;
        for (int i = 0; i < wait.size() - 1; i++) 
            sum += (wait.size() - 1 - i) * wait[i];

        cout << sum << endl;
    }

    return 0;
}

Measured memory_bytes: 1324
#include <bits/stdc++.h>
#define FOR(i, a, b) for(int i=(int)(a); i!=(int)(b); i++)
#define RFOR(i, a, b) for(int i=(int)(a); i!=(int)(b); i--)
#define REP(i, n) FOR(i, 0, n)
using namespace std;
using ll = long long;

int main(){
  string s; cin >> s;
  ll n = s.size();

  vector<ll> cnt(26, 0);
  for(const char c: s){
    cnt[c-'a']++;
  }

  ll ans = n*(n-1)/2 + 1;
  REP(i, cnt.size()){
    if(cnt[i]) ans -= (cnt[i]-1)*cnt[i]/2;
  }

  cout << ans << endl; 

  return 0;
}


Measured memory_bytes: 640
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization ("Ofast")
#pragma GCC optimization ("unroll-loops")
#include<bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair<int , int> pii;
typedef pair<ll, ll> pll;
typedef vector<pii> vii;
typedef vector<pll> vll;
#define mod 1000000007
#define rep(i, a, b) for(ll i = a; i < b; i++)
#define repc(i, a, b, c) for (ll i = a; (c > 0 ? i < b : i > b) and c != 0; i += c)
// #define mp make_pair
#define fi first
#define si second
#define pb push_back
#define all(name) name.begin(), name.end()
#define ral(name) name.rbegin(), name.rend()
#define fact(n) rep(i, 1, n+1)ft.pb((ft[i-1]*i)%mod)
#define mod_in(a) power(a, mod - 2)
#define ncr(n, r) (n>=r?((ft[n]*mod_in((ft[r]*ft[(n)-(r)])%mod))%mod):0LL)
#define deb(x) cerr << "[" << #x << " " << x << "]" << endl;
#define endl '\n'
#define int ll
vector<ll> ft(1, 1LL);

/*======================================================================*/
// ll power(ll x, ll y) {
//     ll res = 1;x %= mod;
//     while (y > 0) {
//         if (y & 1)res = (res*x) % mod;
//         y = y>>1;
//         x = (x*x) % mod;
//     }
//     return res%mod;
// }
// bool cmp(pair<int, int> a, pair<int, int> b){
//     return (a.fi+a.si) > (b.fi+b.si);
// }
// void solve(){
//     int n, s = 0;
//     cin >> n;
//     vector<pair<int, int> > v(n) ;
//     rep(i, 0, n)cin >> v[i].fi >> v[i].si, s += v[i].fi;
//     sort(all(v), cmp);
//     rep(i, 0, n){
//         if(v[i].fi+v[i].si <= s){
//             cout << "INDEFINITELY\n";
//             return;
//         }
//         else s -= v[i].fi;
//     }
//     int mi, ans = s;
//     rep(i,0,n){
//         if()
//     }
// }
class Dsu {
    public :
    vector<int> drr;
    vector<int> size_arr;
    Dsu (int n) {
        rep(i, 0, n+1)drr.pb(i), size_arr.pb(1);
    }
    int f_p (int a) {return drr[a] == a ? a : f_p(drr[a]);}
    ll size (int a) {return (ll)size_arr[f_p(a)];}
    void uni(int a, int b) {
        int ap = f_p(a);
        int bp = f_p(b);
        if(ap == bp)return;
        if(size_arr[ap] <= size_arr[bp])swap(ap,bp);
        drr[bp] = ap;
        size_arr[ap] += size_arr[bp];
    }
};
void solve() {
    int n, m;
    cin >> n >> m;
    Dsu d(n+5);
    rep(i, 0, m){
        int a, b;
        cin >> a >> b;
        d.uni(a, b);
    }
    int ans = 0;
    rep(i, 1, n+1){
        ans = max(ans, d.size(i));
    }
    cout << ans << endl;
}

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);cout.tie(NULL);
    // fact((2e6+10));
    // //declare  and  global
    int t = 1;
    // cin >> t;
    rep(i, 0, t){
        solve();
    }
}


Measured memory_bytes: 6692
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>

#ifdef WIN32
	#define LL "%I64d"
#else
	#define LL "%lld"
#endif

#ifdef CT
	#define debug(...) printf(__VA_ARGS__)
	#define setfile() 
#else
	#define debug(...)
	#define filename ""
	#define setfile() freopen(filename".in", "r", stdin); freopen(filename".out", "w", stdout)
#endif

#define R register
#define getc() (_S == _T && (_T = (_S = _B) + fread(_B, 1, 1 << 15, stdin), _S == _T) ? EOF : *_S++)
#define dmax(_a, _b) ((_a) > (_b) ? (_a) : (_b))
#define dmin(_a, _b) ((_a) < (_b) ? (_a) : (_b))
#define cmax(_a, _b) (_a < (_b) ? _a = (_b) : 0)
#define cmin(_a, _b) (_a > (_b) ? _a = (_b) : 0)
#define cabs(_x) ((_x) < 0 ? (- (_x)) : (_x))
char _B[1 << 15], *_S = _B, *_T = _B;
inline int F()
{
	R char ch; R int cnt = 0; R bool minus = 0;
	while (ch = getc(), (ch < '0' || ch > '9') && ch != '-') ;
	ch == '-' ? minus = 1 : cnt = ch - '0';
	while (ch = getc(), ch >= '0' && ch <= '9') cnt = cnt * 10 + ch - '0';
	return minus ? -cnt : cnt;
}
#define maxn 100010
char str[maxn];
int main()
{
//	setfile();
	R int ans = 0;
	scanf("%s", str + 1);
	for (R int i = 1; str[i]; ++i) ans += str[i] == 'g' ? 1 : -1;
	printf("%d\n", ans >> 1 );
	return 0;
}


Measured memory_bytes: 256
from sys import stdin
nii=lambda:map(int,stdin.readline().split())
lnii=lambda:list(map(int,stdin.readline().split()))
from collections import deque

n=int(input())
a=lnii()

ans=deque([])
for i in range(n):
  if i%2==0:
    ans.appendleft(a[i])
  else:
    ans.append(a[i])

if n%2==0:
  ans=reversed(ans)

print(*list(ans))

Measured memory_bytes: 32560
#coding : utf-8

import os
import sys

N = int(input())

A = []

for i in range(N):
	A.append(int(input()))

X = [[A[i], i] for i in range(N)]


X.sort(key = lambda x: x[0], reverse=True)


for i in range(N):
	if i != X[0][1]:
		print(X[0][0])
	else:
		print(X[1][0])



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

using namespace std;

#define FOR(i, n) for(int i = 0; i < (int) n; i++)
#define all(v) v.begin(), v.end()
#define F first
#define S second

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pii;

const ll MOD = 1e9+7;

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

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

	int n; cin >> n;
	vi v(n); 
	map<int,ll> m;
	ll cnt = 0;
	for(auto& p : v){
		cin >> p;
		m[p]++;
	} 

	for(auto& p: m){
		cnt += p.S*(p.S-1)/2;
	}

	FOR(i, n){
		if(m[v[i]] > 1){
			cout << cnt - m[v[i]]*(m[v[i]]-1)/2 + (m[v[i]]-1)*(m[v[i]]-2)/2 << '\n';
		}else{
			cout << cnt << '\n';
		}
	}


	return 0;
}

Measured memory_bytes: 10368
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using pint = pair<int,  int>;
using pll = pair<ll, ll>;
using edge = pair<int, ll>;
using Graph = vector<vector<int>>; 
using WeightedGraph = vector<vector<edge>>;
const ll INF = 1LL << 60;
const int INF32 = 1 << 29;
const ll MOD = 1000000007;

bool dfs(const Graph &G, int v, int vdir, pint &num, vector<int> &dir) {
    bool res = true;
    dir[v] = vdir;
    if (vdir == 1) ++num.first;
    else if (vdir == -1) ++num.second;
    for (auto nv : G[v]) {
        if (dir[nv] == 0) {
            if (!dfs(G, nv, -vdir, num, dir)) res = false;
        }
        else if (dir[nv] != -vdir) res = false;
    }
    return res;
}

bool isbipartite(const Graph &G, vector<pint> &nums) {
    bool res = true;
    int N = (int)G.size();
    vector<int> dir(N, 0);
    for (int v = 0; v < N; ++v) {
        if (dir[v] != 0) continue;
        pint num = {0, 0};
        if (!dfs(G, v, 1, num, dir)) res = false;
        nums.push_back(num);
    }
    return res;
}

int main(){
    int n; cin >> n;
    int V = n;
    vector<vector<long long> > dp(V, vector<long long>(V, INF));
    for (int i = 0; i < V; ++i) dp[i][i] = 0;  // necessary
    Graph G(n);
    for(int i = 0; i < n; ++i){
      string s; cin >> s;
      for(int j = 0; j < n; ++j){
        if(s[j]=='1'){
          G[i].push_back(j);
          dp[i][j]=1;
        }
      }
    }
    vector<pint> tmp;
    ll ans = -1;
    if(!isbipartite(G,tmp)){
      cout << ans << endl;
      return  0;
    }
    // Floyd-Warshall
    for (int k = 0; k < V; ++k)
        for (int i = 0; i < V; ++i)
            for (int j = 0; j < V; ++j)
                dp[i][j] = min(dp[i][j], dp[i][k] + dp[k][j]); 
  
  for(int i = 0; i < n; ++i){
    for(int j = 0; j < n; ++j){
      ans = max(ans,dp[i][j]);
    }
  }
  cout << ans+1 << endl;
}


Measured memory_bytes: 768
#include <iostream>
#include <string>
#include <vector>

using namespace std;

int main(){
    int N, K;
    string S;
    cin >> N >> K;
    cin >> S;

    vector<int> groups;

    char key = '1';
    int cnt_key = 0;

    for(int i=0;i<N;i++){
        if(S.at(i)==key){
            cnt_key++;
        }
        else{
            groups.push_back(cnt_key);
            key = (key=='0')?'1':'0';
            cnt_key = 1;
        }
    }

    groups.push_back(cnt_key);
    if(groups.size()%2 == 0)groups.push_back(0);

    int max_people = 0;
    if(K >= groups.size()/2){
        max_people = N;
    }
    else{
        for(int i=0;i<groups.size()-2*K;i+=2){
            int sum_groups =  0;
            for(int j=i;j<i+1+2*K;j++){
                sum_groups += groups.at(j);
            }
            if(max_people < sum_groups)max_people = sum_groups;
        }
    }

    cout << max_people << endl;

}

Measured memory_bytes: 1020
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

	public static void main(String[] args) throws IOException{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String[] num;
		String str;
		
		int tmp;
		int W = Integer.parseInt(br.readLine());
		int N = Integer.parseInt(br.readLine());
		int[] array = new int[W];

		NumAB[] pair = new NumAB[N];
		for(int i=0;i<W;i++){
			array[i]=i;
		}

		for(int i=0;i<N;i++){
			str = br.readLine();
			num = str.split(",",0);
			pair[i] = new NumAB(Integer.parseInt(num[0])-1,Integer.parseInt(num[1])-1);
		}
		for(int i=0;i<N;i++){
			tmp = array[pair[i].a];
			array[pair[i].a] = array[pair[i].b];
			array[pair[i].b] = tmp;
		}
		for(int i=0;i<W;i++){
			array[i]=array[i]+1;
			System.out.println(array[i]);
		}
	}
}

final class NumAB{
	int a,b;

	//?????????????????????
	NumAB(int x, int y){
		a=x;
		b=y;
	}
}

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

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

    int n;    cin >> n;
    double d;   cin >> d;

    int ans=0;
    rep(i,n){
        double x,y; cin >> x >> y;

        if(d*d>=(x*x+y*y)){
            ans++;
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3764
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func nextInt() int {
	sc.Scan()
	i, _ := strconv.Atoi(sc.Text())
	return i
}

func inputIntSlice(size int) []int {
	slice := make([]int, size)
	for i := range slice {
		slice[i] = nextInt()
	}
	return slice
}

func main() {
	sc.Split(bufio.ScanWords)
	c := make([][]int, 3)
	for i := range c {
		c[i] = inputIntSlice(3)
	}

	ok := false
	for a1 := 0; a1 <= 100; a1++ {
		a := []int{a1, c[1][0] - c[0][0] + a1, c[2][0] - c[0][0] + a1}
		b := []int{c[0][0] - a1, c[0][1] - a1, c[0][2] - a1}
		if a[1] < 0 || a[2] < 0 {
			continue
		}
		if b[0] < 0 || b[1] < 0 || b[2] < 0 {
			continue
		}
		ok = true
		for i := 1; i < 3; i++ {
			for j := 1; j < 3; j++ {
				ok = ok && (a[i]+b[j] == c[i][j])
			}
		}
		if ok {
			break
		}
	}
	if ok {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}
}


Measured memory_bytes: 640
from collections import deque
aq = deque(input())
bq = deque(input())
cq = deque(input())
d={"a":aq,"b":bq,"c":cq}
p=aq.popleft()
while True:
  if len(d[p])==0:
    print(p.upper())
    exit()
  p=d[p].popleft()

Measured memory_bytes: 9332
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <stdio.h>
#include <cmath>
#include <cctype>

using namespace std;

int main()
{
    string s;
    int sum;
    while (true)
    {
        cin >> s;
        if (s[0] == '0')
        {
            break;
        }

        sum = 0;
        for (int i = 0; i < s.size(); i++)
        {
            sum += s[i] - '0';
        }
        cout << sum << endl;
    }

    return 0;
}


Measured memory_bytes: 3184
#include <iostream>
#include <iomanip>
#include <algorithm>
using namespace std;

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

    int N, v[50];
    cin >> N;
    for (int i = 0; i < N; i++)
        cin >> v[i];

    sort(v, v + N);

    double result = (v[0] + v[1]) / 2.0;
    for (int i = 2; i < N; i++)
        result = (result + v[i]) / 2.0;
    cout << fixed << setprecision(6) << result << '\n';

    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<math.h>
using namespace std;
int N;

int main() {
	
	int light[100000];
	int s[100000] = { 0 };
	int cnt = 1;
	int sp = 0;
	cin >> N;
	for (int i = 0; i < N; i++)cin >> light[i];

	for (int i = 1; i < N; i++) {
		if (light[i-1]!=light[i]) {
			cnt++;
		}
		else {
			s[sp] = cnt;
			cnt = 1;
			sp++;
		}
		if (i == N - 1) {
			s[sp] = cnt;
			sp++;
		}
	}
	int ans = 0;
	for (int i = 0; i < sp; i++) {
		ans = max(ans, s[i] + s[i + 1] + s[i + 2]);
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 3864
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define FOR(i,n,m) for(ll i=(n);i<(m);i++)
#define REP(i,n) FOR(i,0,n)
#define REPR(i,n) for(ll i=(n);i>=0;i--)
#define all(vec) vec.begin(),vec.end()
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using P=pair<ll,ll>;
using PP=pair<ll,P>;
using vp=vector<P>;
using vpp=vector<PP>;
using vs=vector<string>;
#define fi first
#define se second
#define pb push_back
template<class T>bool chmax(T &a,const T &b){if(a<b){a=b;return true;}return false;}
template<class T>bool chmin(T &a,const T &b){if(a>b){a=b;return true;}return false;}
const ll MOD=1000000007LL;
const int INF=1<<30;
const ll LINF=1LL<<60;
int sum(int n){
    int res=0;
    while(n){
        res+=n%10;
        n/=10;
    }
    return res;
}
int main(){
    int n;
    cin>>n;
    int ans=INF;
    FOR(i,1,n){
        chmin(ans,sum(i)+sum(n-i));
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
def main():
    N = int(input())
    A = [int(a) for a in input().split()]
    A = sorted(A)

    now = N
    A_cumsum = [A[0]]
    for i in range(1,N):
        A_cumsum.append(A_cumsum[-1]+A[i])
    ans = 0
    for i in range(1,N):
        if A_cumsum[i-1]*2>=A[i]:
            pass
        else:
            ans = i
    print(N-ans)

if __name__ == "__main__":
    main()



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

int main() {
    int M, D;
    cin >> M >> D;

    int ans = 0;
    for (int d = 22; d <= D; d++) {
        int d1 = d % 10;
        int d10 = d / 10;
        if (d1 >= 2 && d1 * d10 <= M) ans++;
    }

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


Measured memory_bytes: 256
/*================================================================
*   Copyright (C) 2019 Sangfor Ltd. All rights reserved.
*
*   创 建 者： badcw
*   创建日期： 2019/12/22
*
================================================================*/
#include <bits/stdc++.h>

#define ll long long
using namespace std;

const int maxn = 1e5+50;
const int mod = 1e9+7;
ll qp(ll a, ll n) {
    ll res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

template <class T>
inline bool scan(T& ret) {
    char c;
    int sgn;
    if (c = getchar(), c == EOF) return 0; // EOF
    while (c != '-' && (c < '0' || c > '9')) c = getchar();
    sgn = (c == '-') ? -1 : 1;
    ret = (c == '-') ? 0 : (c - '0');
    while (c = getchar(), c >= '0' && c <= '9') ret = ret * 10 + (c - '0');
    ret *= sgn;
    return 1;
}

//template <class T>
//inline void out(T x) {
//    if (x > 9) out(x / 10);
//    putchar(x % 10 + '0');
//}

int n;
vector<int> edge[maxn];
int x, y;
int dep[maxn], fa[maxn][30];

void dfs(int u, int pre) {
    dep[u] = dep[pre] + 1, fa[u][0] = pre;
    for(int i = 1; (1 << i) <= n; i ++)
        fa[u][i] = fa[fa[u][i - 1]][i - 1];
    for(auto v : edge[u]) if(v != pre) dfs(v, u);
}

int LCA(int u, int v) {
    if(dep[u] < dep[v]) swap(u, v);
    int d = dep[u] - dep[v];
    for(int i = 0; (1 << i) <= d; i ++)
        if((1 << i) & d) u = fa[u][i];
    if(u == v) return u;
    for(int i = 20; i >= 0; i --)
        if(fa[u][i] != fa[v][i])
            u = fa[u][i], v = fa[v][i];
    return fa[u][0];
}

int dist(int u, int v) {
    return dep[u] + dep[v] - 2 * dep[LCA(u, v)];
}

int main(int argc, char* argv[]) {
    scanf("%d%d%d", &n, &x, &y);
    for (int i = 1; i < n; ++i) {
        int u, v;
        scanf("%d%d", &u, &v);
        edge[u].push_back(v);
        edge[v].push_back(u);
    }
    dfs(1, 0);
    int res = 0;
    for (int i = 1; i <= n; ++i) {
        int tmp1 = dist(x, i);
        int tmp2 = dist(y, i);
        if (tmp1 <= tmp2) res = max(res, tmp2 - 1);
    }
    printf("%d\n", res);
    return 0;
}


Measured memory_bytes: 21888
#include<iostream>
#include<algorithm>
#include<vector>
#include<stack>
#include<map>
#include<set>
#include<queue>
#include<cstdio>
#include<climits>
#include<cmath>
#include<cstring>
#include<string>
#include<sstream>
#include<numeric>
#include<cassert>

#define f first
#define s second
#define mp make_pair

#define REP(i,n) for(int i=0; i<(int)(n); i++)
#define rep(i,s,n) for(int i=(s); i<(int)(n); i++)
#define FOR(i,c) for(__typeof((c).begin()) i=(c).begin(); i!=(c).end(); i++)
#define ALL(c) (c).begin(), (c).end()
#define IN(x,s,g) ((x) >= (s) && (x) < (g))
#define ISIN(x,y,w,h) (IN((x),0,(w)) && IN((y),0,(h)))
#define print(x) printf("%d\n",x)

using namespace std;

typedef unsigned int uint;
typedef long long ll;

const int _dx[] = {0,1,0,-1};
const int _dy[] = {-1,0,1,0};

int getInt(){
  int ret = 0,c;
  c = getchar();
  while(!isdigit(c)) c = getchar();
  while(isdigit(c)){
    ret *= 10;
    ret += c - '0';
    c = getchar();
  }
  return ret;
}

string J(string str){
  rotate(str.begin(),str.end()-1,str.end());
  return str;
}

string C(string str){
  rotate(str.begin(),str.begin()+1,str.end());
  return str;
}

string E(string str){
  int n = str.size();
  string l = str.substr(0,n/2);
  string r = str.substr((n+1)/2);
  string m = (n%2 == 0 ? "" : str.substr(n/2,1));
  return r + m + l;
}

string A(string str){
  return string(str.rbegin(), str.rend());
}

string P(string str){
  FOR(it,str){
    if(isdigit(*it)){
      int num = *it - '0';
      num = (num + 10 - 1) % 10;
      *it = num + '0';
    }
  }
  return str;
}
string M(string str){
  FOR(it,str){
    if(isdigit(*it)){
      int num = *it - '0';
      num = (num + 1) % 10;
      *it = num + '0';
    }
  }
  return str;
}

int main(){
  int n;
  cin>>n;
  while(n --> 0){
    string mes;
    string str;
    cin>>mes>>str;
    for(int i=mes.size()-1; i>=0; i--){
      switch(mes[i]){
      case 'J':
        str = J(str);
        break;
      case 'C':
        str = C(str);
        break;
      case 'E':
        str = E(str);
        break;
      case 'A':
        str = A(str);
        break;
      case 'P':
        str = P(str);
        break;
      case 'M':
        str = M(str);
        break;
      }
    }
    cout << str << endl;
  }
  return 0;
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n,hi,ans;
    hi = 0;
    ans = 0;
    cin >> n;
    vector<int> vec(n);
    for(int i=0;i<n;i++){
        cin >> vec.at(i);
    }
    for(int i=0;i<n;i++){
        if(hi <= vec.at(i)){
            ans ++;
            hi = vec.at(i);
        }
    }
    cout << ans << endl;
}

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

#define all(x) (x).begin(),(x).end()
#define loop(i,n) for(int i=0;i<(n);i++)
#define cont(i,n) for(int i=1;i<=(n);i++)
#define circ(i,a,b) for(int i=(a);i<=(b);i++)
#define range(i,a,b,c) for(int i=(a);((c)>0?i<=(b):i>=(b));i+=(c))
#define foreach(it,v) for(__typeof((v).begin()) it=(v).begin(),_e_D_=(v).end();it!=_e_D_;it++)
#define y0 y0O0OO00OO0OO0OO0OOO00OO0OO0O0O000OO0
#define y1 y1II11II11III11I1III11II111IIII1II1I1
#define pub push_back
#define pob pop_back
#define mak make_pair

typedef long long ll;
typedef long double lf;
const int Inf=0x3f3f3f3f;
const ll INF=0x3f3f3f3f3f3f3f3fll;
/* Source code starts here */

const int jt=1000000007;
int n;
vector<int> nei[1<<18];
int ans;
int siz[1<<18];
int mii[1<<18];

void dfs(int now,int lst){
	siz[now]=1;
	int pr=mii[1];
	foreach(i,nei[now])if(*i!=lst){
		dfs(*i,now);
		siz[now]+=siz[*i];
		(pr+=jt-mii[n-siz[*i]])%=jt;
	}
	if(now>1)(pr+=jt-mii[siz[now]])%=jt;
	(pr+=1ll*mii[n]*(nei[now].size()-1)%jt)%=jt;
	(ans+=pr)%=jt;
}

int main(){
	scanf("%d",&n);
	mii[0]=1;mii[1]=(jt+1)>>1;
	circ(i,2,n)mii[i]=1ll*mii[i-1]*mii[1]%jt;
	cont(i,n-1){
		int a,b;scanf("%d%d",&a,&b);
		nei[a].pub(b);nei[b].pub(a);
	}
	dfs(1,0);
	printf("%d\n",ans);
	return 0;
}

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

int main()
{
    int N, min = 999;
    cin >> N;
    for (int i = 0; i < N; i++)
    {
        int A;
        cin >> A;
        if (A % 2 != 0)
        {
            min = 0;
            break;
        }

        int cnt = 0;
        while (A % 2 == 0)
        {
            cnt++;
            A /= 2;
        }
        if (cnt < min)
        {
            min = cnt;
        }
    }
    cout << min << endl;
}

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

using namespace std;

int main() {
    int r, g, b, n;
    
    cin >> r >> g >> b >> n;
    
    int ans = 0;
    
    for (int i = 0; i * r <= n; ++i) {
        for (int j = 0; i * r + j * g <= n; ++j) {
            if ((n - i * r - j * g) % b == 0) {
                ++ans;
            }
        }
    }
    
    cout << ans << endl;
    
    return 0;
}

Measured memory_bytes: 256