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

int main() {
  char c;
  cin >> c;
  
  if (c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u'){
    cout << "vowel" << endl;
  }
  else cout << "consonant" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
    
using namespace std;
    
typedef long long ll;
typedef long double ld;
  
mt19937 rnd(time(0));
#define f first
#define s second
#define pb push_back
#define pii pair<int, int>
#define vi vector<int>
// #define int __int128
 
void solve() {
	int r;
	cin >> r;
	cout << r * r << endl;
}
    
signed main() {
    // freopen("cbarn2.in", "r", stdin);
    // freopen("cbarn2.out", "w", stdout);
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int t = 1;
    // cin >> t;
    while (t--) {
        solve();
    }
}

Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <vector>
#include <queue>
using namespace std;

int main(){
	int n, inp;
	long long res1=0, res2=0;
	priority_queue <int> q1, q2;
	cin>>n;
	for(int i = 0;i < n;i ++){
		cin>>inp;
		q1.push(inp);
		q2.push(-inp);
	}
	if(n&1){
		for(int i = 0;i < n/2;i ++){
			res1+=q1.top()*2;
			q1.pop();
			res2-=-q2.top()*2;
			q2.pop();
		}
		res1-=q1.top();
		q1.pop();
		res1-=q1.top();
		q1.pop();
		res2+=-q2.top();
		q2.pop();
		res2+=-q2.top();
		q2.pop();
		for(int i = 1;i < n/2;i ++){
			res1-=q1.top()*2;
			q1.pop();
			res2+=-q2.top()*2;
			q2.pop();
		}
		printf("%lld\n",max(res1,res2));
	}else{
		for(int i = 1;i < n/2;i ++){
			res1+=2*q1.top();
			q1.pop();
		}
		res1+=q1.top();
		q1.pop();
		res1-=q1.top();
		q1.pop();
		for(int i = 1;i < n/2;i ++){
			res1-=2*q1.top();
			q1.pop();
		}
		printf("%lld\n",max(res1,res2));
	}
}

Measured memory_bytes: 1396
N, M, K = map(int, input().split())
MOD = 998244353

ans = pow(M, N, MOD)
g1 = [1, 1]
g2 = [1, 1]
inverse = [0, 1]
for i in range(2, 2*10**5+1):
    g1.append((g1[-1] * i) % MOD)
    inverse.append((-inverse[MOD % i] * (MOD // i)) % MOD)
    g2.append((g2[-1] * inverse[-1]) % MOD)

def memo_comb(n, r, mod=MOD):
    if r < 0 or r > n:
        return 0
    r = min(r, n - r)
    return g1[n] * g2[r] * g2[n-r] % mod


for k in range(K+1, N):
  n = (memo_comb(N-1, k) * M * pow(M-1, N-k-1, MOD)) % MOD
  ans -= n
  ans %= MOD

print(ans)

Measured memory_bytes: 32944
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
#include<stdio.h>
#include <cstdint>
#include <stdlib.h> 
#include <time.h>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define all(a) a.begin(), a.end()
#define fi first
#define se second
#define RNG(x, a, n) &((x)[a]), &((x)[n])
typedef pair<int, int> PII;
typedef long long ll;
template<typename T> bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; } return false; }
template<typename T> bool chmin(T& a, const T& b) { if (a > b) { a = b; return true; } return false; }
const int inf = 1e9 + 7;
const ll longinf = 1LL << 60;
const ll mod = 1e9 + 7;


ll n, a, b, ans;


int main() {

	cin >> n >> a >> b;

	b += a;

	ll tmp = 0;

	ans = n / b * a;

	if (n % b != 0) {
		ans += min(a, n % b);
	}

	cout << ans << endl;


	return 0;
}


Measured memory_bytes: 256
//karna padega 
#include<bits/stdc++.h>
using namespace std;  
#pragma GCC optimize("Ofast") 
#define int long long
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);
#define pb push_back 
#define eb emplace_back
#define fn for(int i =0 ;i <n;i++)
#define fn1 for( int i =1;i<=n; i++)
#define fm for(int j =0 ;j <m;j++)
#define fm1 for(int j =1;j<=m;j++)
#define fi first
#define se second
#define endl '\n'
#define PI  3.14159265358979323846
#define MOD 1000000007
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
const int N = 2e6+5;
const int INF = 1e18L;
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << ": " << arg1 << " |";
  __f(comma + 1, args...);
}
int ar[N];
int br[N];
signed main(){
  #ifndef ONLINE_JUDGE
  freopen("input.txt","r",stdin);
  freopen("output.txt","w",stdout);
  #endif
  IOS;
  int T=1;
  // cin >> T;
  while(T--){
    int n;
    cin >> n ;
    n--;
    fn{
      cin>> br[i];
    }
   int ans = br[0] + br[n-1];
   for(int i=1;i<n;i++)ans+=min(br[i],br[i-1]);
    cout << ans;

  
  
  }
  return 0;
}

Measured memory_bytes: 3652
#include <bits/stdc++.h>
#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define rep(i,n) for (int i = (0); i < (n); ++i)
#define rng(x) (x).begin(),(x).end()
#define rrng(x) (x).rbegin(),(x).rend()
#define debug(x) cout << #x << " = " << (x) << endl;
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define uni(x) x.erase(unique(rng(x)),x.end())
#define SP << " " <<
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using pii = pair<int, int>;
using tiii = tuple<int, int, int>;
const int mod = 1000000007;
const double EPS = 1e-9;
const int INF = 1<<30;
const ll INFLL = 1LL<<60;
//cout << fixed << setprecision(10);

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

//const int mod = 1000000007;
// mint(a).pow(b) -> a^b
struct mint {
  ll x;
  mint(ll x=0):x(x%mod){}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const {
    mint res(*this);
    return res+=a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res-=a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res*=a;
  }
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const {
    return pow(mod-2);
  }
  mint& operator/=(const mint a) {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const {
    mint res(*this);
    return res/=a;
  }
};

int main () {
  int n;
  cin >> n;
  vll a(n);
  rep(i,n) cin >> a[i];

  ll ans = 0;
  rep(b,60) {
    ll bit = ((ll)1<<b); // (ll)をつけないと間違い
    ll cnt = 0;
    rep(i,n) {
      if (a[i]&bit) cnt++;
    }
    //ans += bit*cnt*(n-cnt);
    ans += (((bit%mod)*cnt)%mod*(n-cnt))%mod;
    ans %= mod;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 2560
#include <stdio.h>

int main(void)
{
	int n,x,i,j,k,a;
	while(1){
		scanf("%d%d",&n,&x);
		if(!(n||x))break;
		a=0;
		for(i=1;i<n-1;i++)for(j=i+1;j<n;j++)for(k=j+1;k<=n;k++)if(i+j+k==x)a++;
		printf("%d\n",a);
	}
	return 0;
}


Measured memory_bytes: 2072
import java.util.LinkedList;
import java.util.Scanner;




//D
public class Main {

	static int N;
	static int Q;
	static LinkedList<Integer>[] v;
	static int[] ans;
	static int[] parent;
	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);

		N=sc.nextInt();
		Q=sc.nextInt();
		v=new LinkedList[N+1];
		ans=new int[N+1];
		parent=new int[N+1];
		for(int i=1;i<=N;i++) {
			v[i]=new LinkedList<Integer>();
		}
		for(int i=1;i<=N-1;i++) {
			int a=sc.nextInt();
			int b=sc.nextInt();
			v[a].add(b);
			parent[b]=a;

		}

		for(int i=0;i<Q;i++) {
			int p=sc.nextInt();
			int q=sc.nextInt();
			ans[p]+=q;
		}


		for(int i=2;i<=N;i++) {

			int pi=parent[i];
			System.err.println("i pi "+i+" "+pi);

			if(pi!=0) {ans[i]+=ans[pi];}

		}

		for(int i=1;i<=N;i++) {
			System.out.print(ans[i]+" ");
		}
		System.out.println();
	}

}


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

int main() {
    int n, k, i, j;
    long double m[6];
    cin >> n >> k;
    m[0] = (n - k) * 100 + 1900 * k;
    for (i = 1; i <= k; ++i) {
        m[i] = m[i - 1] * 2;
    }
    cout << (long double) m[k];
}

Measured memory_bytes: 256
import sys
INF = 1 << 60
MOD = 10**9 + 7 # 998244353
sys.setrecursionlimit(2147483647)
input = lambda:sys.stdin.readline().rstrip()
from heapq import heappop, heappush
def resolve():
    n, m = map(int, input().split())
    N = 1 << (n - 1).bit_length()
    N2, now = N * 2, N * 3
    E = [[] for _ in range(N * 3 + m * 2)]
    ref = lambda v : v if v < 3 * N else v - N2

    # build range-edge graph
    for i in range(N - 1, 0, -1):
        cl, cr = i << 1, i << 1 | 1
        E[i].append((cl, 0))
        E[i].append((cr, 0))
        E[ref(cl + N2)].append((ref(i + N2), 0))
        E[ref(cr + N2)].append((ref(i + N2), 0))

    # add range-edge
    for _ in range(m):
        u, v, w = map(int, input().split())
        u -= 1
        # lower
        l, r = u + N, v + N
        while l < r:
            if l & 1:
                E[ref(l + N2)].append((now, 0))
                l += 1
            if r & 1:
                r -= 1
                E[ref(r + N2)].append((now, 0))
            l >>= 1
            r >>= 1
        # upper
        l, r = u + N, v + N
        while l < r:
            if l & 1:
                E[now + 1].append((l, 0))
                l += 1
            if r & 1:
                r -= 1
                E[now + 1].append((r, 0))
            l >>= 1
            r >>= 1
        # range-edge
        E[now].append((now + 1, w))
        now += 2

    # Dijkstra (source : N, termination : N + n - 1)
    dist = [INF] * now
    dist[N] = 0
    heap = [(0, N)]
    while heap:
        d, v = heappop(heap)
        if dist[v] != d:
            continue
        for nv, w in E[v]:
            if dist[nv] > d + w:
                dist[nv] = d + w
                heappush(heap, (d + w, nv))

    ans = dist[N + n - 1]
    if ans == INF:
        ans = -1
    print(ans)
resolve()

Measured memory_bytes: 277268
#!/usr/bin/env python3

def prime_factorize(n):
    a = []
    while n%2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return(a)

A, B = map(int, input().split())

A_lis = prime_factorize(A)
A_lis.append(1)
B_lis = prime_factorize(B)

ans = 1

for i in set(A_lis + B_lis):
    if A_lis.count(i) >= B_lis.count(i):
        ans = ans * (i ** A_lis.count(i))
    else:
        ans = ans * (i ** B_lis.count(i))

print(ans)

Measured memory_bytes: 3064
N,L = map(int,input().split())
a = []
minabs = 1000
tmp = -1

for i in range(N):
    p = L + i
    a.append(L + i)#i = i - 1のため
    if abs(p) < minabs:
        minabs = abs(p)
        tmp = i

print(sum(a) - a[tmp])

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

int main() {
	string S;
	cin >> S;
	string ans = "Good";
	if (S[0] == S[1] || S[1] == S[2] || S[2] == S[3]) ans = "Bad";
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 3604
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define db long double
#define all(a) a.begin(),a.end()
#define pb push_back
#define f(i,l,u) for(ll i=l;i<u;i++)
#define lb lower_bound
#define ub upper_bound
#define pii pair<ll,ll> 

        
long long power( long long x, 
                         ll y, ll p) 
{ 
   long long res = 1; // Initialize result 
  
    x = x % p; 
    while (y > 0) { 
        // If y is odd, multiply x with result 
        if (y & 1) 
            res = (res * x) % p; 
  
        // y must be even now 
        y = y >> 1; // y = y/2 
        x = (x * x) % p; 
    } 
    return res; 
} 
  
// Returns n^(-1) mod p 

  
int main() {
 ios_base::sync_with_stdio(false);
    cin.tie(NULL);
  
   
  ll n;
  cin>>n;
  
  ll mod=1e9+7;
ll dp[2001]={0};
dp[0]=1;
dp[1]=0;
dp[2]=0;
f(i,3,2001)
{
    dp[i]+=dp[i-1];
    dp[i]%=mod;
    if(i-3>=0)
    dp[i]+=dp[i-3];
    dp[i]%=mod;
    
}
cout<<dp[n]<<endl;
   

      

return 0;    
}

Measured memory_bytes: 3616
fun main(){
    val n = readLine()!!.split(" ")[0].toInt()
    val a = readLine()!!.split(" ").map { it.toLong() }
    var kabukazu = 0L
    var motigane = 1000L
    for (i in 0 until n-1){
        motigane += kabukazu * a[i]
        kabukazu = 0
        if (a[i] < a[i + 1]){
            kabukazu += (motigane / a[i])
            motigane -= (a[i] * kabukazu)
        }
    }
    motigane += (kabukazu * a[n-1])
    println(motigane)
}

Measured memory_bytes: 36544
# 25minutes. 
# 簡単なのだが問題をちゃんと読めていないため'WA'を2回繰り返した！

l = list(input())
m = list('ABCDEFGHIJKLMNOPQRSTUVWXYZ')

x = 0
for j in l:
    if j in m:
        x += 1

a = 0
for i in range(2,len(l)-1):
    if l[i] == 'C':
        a += 1
if a == 1 and l[0] == 'A' and x == 2:
    print('AC')
else:
    print('WA')


Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < int(n); i++)
using namespace std;
using ll = long long;
const int INF = (1<<30)-1;
const long long LINF = (1LL<<62)-1;
const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, 1, 0, -1};
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll a;
  string s;
  cin >> a >> s;
  ll b = 0;
  rep(i, s.size()) {
    if (s[i] == '.')
      continue;
    b *= 10;
    b += s[i]-'0';
  }
  cout << a*b/100 << endl;
  return 0;
}

Measured memory_bytes: 3656
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <set>
#include <algorithm>
#include <array>
#include <complex>
#include <string>
#include <utility>
#include <map>
#include <queue>
#include <list>
#include <functional>
#include <numeric>
#include <stack>
#include <tuple>

using namespace std;
int dx[4] = { -1,0,1,0 };
int dy[4] = { 0,1,0,-1 };
const int INF = 100000000;
const long long LINF = 1000000000000000000;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-6;
using pii = std::pair<int, int>;
using ll=long long;  
using pLL = std::pair<ll, ll>;
#define SORT(v) std::sort(v.begin(), v.end())
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
	string s;
	cin >> s;
	int Ccount=0;
    int l = s.size();
	bool up_check=false;
	if(s[0]=='A'){
		for(size_t i=1;i<s.size();++i){
            if (isupper(s[i])) {
                if(i==1||i==l-1||s[i]!='C')up_check = true;
                Ccount++;
            }
		}
	}else{
		cout << "WA" <<endl;
		return 0;
	}
	if(Ccount==1&&up_check==false){
		cout << "AC" <<endl;
	}else{
		cout << "WA" <<endl;
	}
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll mod=1e9+7;

int main()
{
    ll n,h,w;
    cin>>n>>h>>w;
    ll c=0;
    while(n--)

    {
        ll a,b;
        cin>>a>>b;
        if(a>=h && b>=w)
            c++;

    }
    cout<<c<<"\n";



return 0;
}


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

using namespace std;

typedef long long ll;

int main()
{
    ios_base::sync_with_stdio(0);
    int n;
    ll k;
    cin >> n >> k;
    ll t = k;
    string K = "";
    while (t != 0)
    {
        K = (char) ('0' + t % 2) + K;
        t /= 2;
    }
    while (K.size() < 41)
        K = "0" + K;
    vector<ll> il1(41, 0), il0(41, 0);
    ll odp = 0;
    for (int i = 0; i < n; ++i)
    {
        ll x;
        cin >> x;
        odp += (x ^ k);
        for (ll j = 0; j < 41; ++j)
        {
            if ((x & (1LL << j)) > 0)
                ++il1[j];
            else
                ++il0[j];
        }
    }
    for (int i = 0; i < 41; ++i)
    {
        if (K[i] == '1')
        {
            K[i] = '0';
            ll wyn = 0;
            for (ll j = 0; j < 41; ++j)
            {
                ll tyl = 41 - j - 1;
                if (j <= i)
                {
                    if (K[j] == '0')
                        wyn += il1[tyl] * (1LL << tyl);
                    else
                        wyn += il0[tyl] * (1LL << tyl);
                }
                else
                {
                    if (il0[tyl] >= il1[tyl])
                        wyn += il0[tyl] * (1LL << tyl);
                    else
                        wyn += il1[tyl] * (1LL << tyl);
                }
            }
            K[i] = '1';
            odp = max(odp, wyn);
        }
    }
    cout << odp;
    return 0;
}


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

int main(){
	int n;
	while(cin>>n,n){
		int k[n];
		bool check[n],temp=true;
		rep(i,n){
			cin>>k[i];
			if(k[i]>=2)check[i]=true;
			else check[i]=false;
			if(check[i])temp=false;
		}
		if(temp)cout<<"NA"<<endl;
		else{
			int ans=0;
			rep(i,n)if(k[i]>=1)ans++;
			cout<<ans+1<<endl;
		}
	}
	return 0;
}

Measured memory_bytes: 1208
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		StringBuilder sb=new StringBuilder("");
		Scanner n=new Scanner(System.in);
		int a=n.nextInt();
		int b=n.nextInt();
		while (a!=0 || b!=0){
			for (int c=0;c<b;c++){
					sb.append("#");
			}
			System.out.println(sb);
			sb.append("\n");//改行
			sb=new StringBuilder("#");
			for (int d=2;d<a;d++){
				for (int e=2;e<b;e++){
					sb.append(".");
				}
				sb.append("#");
				System.out.println(sb);
				sb.append("\n");//改行
				sb=new StringBuilder("#");
			}
			for (int c=1;c<b;c++){
				sb.append("#");
			}
		sb.append("\n");//改行
		System.out.println(sb);
		a=n.nextInt();b=n.nextInt();
		sb=new StringBuilder("");
		}
	}
}

Measured memory_bytes: 21628
N = 1000000
p = [ 1 ] * N

( p[ 0 ], p[ 1 ] ) = ( 0, 0 )
for i in range ( len ( p ) ):
  if ( p[ i ] ):
    for j in range ( i * 2, len ( p ), i ):
      p[ j ] = 0
for i in range ( 1, len ( p ) ):
  p[ i ] += p[ i - 1 ]

while True:
  try: n = int ( input ( ) )
  except EOFError: break
  print ( p[ n ] )

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

int main(){
    int h, w;
    cin >> h >> w;
    vector<string> s(h);
    for(int i = 0; i < h; i++) cin >> s[i];

    vector<string> ans = s;
    for(int i = 0; i < h; i++){
        for(int j = 0; j < w; j++){
            if(s[i][j] == '#') ans[i][j] = '#';
            else{
                int count = 0;
                for(int ii = -1; ii <= 1; ii++){
                    for(int jj = -1; jj <= 1; jj++){
                        if(ii+i >= 0 && ii+i < h && jj+j >= 0 && jj+j < w && s[ii+i][jj+j] == '#') count++;
                    }
                }
                ans[i][j] = (char)(count+'0');
            }
        }
    }

    for(int i = 0; i < h; i++){
        cout << ans[i] << endl;
    }
    return 0;
}

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

inline double add(double a, double b){
    return abs(a+b)<(1e-10)*(abs(a)+abs(b)) ? 0.0 : a+b;
}

struct vec{
    long double x,y;
    vec operator-(vec b){
        return (vec){add(x,-b.x),add(y,-b.y)};
    }
    vec operator+(vec b){
        return (vec){add(x,b.x),add(y,b.y)};
    }
    vec operator*(long double d){
        return (vec){x*d,y*d};
    }
    bool operator==(vec b){
        return x==b.x&&y==b.y;
    }
    bool operator!=(vec b){
        return x!=b.x||y!=b.y;
    }
    bool operator<(const vec&r) const{
    return this->x==r.x?this->y<r.y:this->x<r.x;
    }
    long double dot(vec v){
        return add(x*v.x,y*v.y);
    }
    long double cross(vec v){
        return add(x*v.y,-y*v.x);
    }
    long double norm(){
        return sqrt(x*x+y*y);
    }
};


const double eps = 0.0000001;

int ccw(vec& a, vec& b, vec& c){
    vec ab = b-a, ac = c-a;
    long double o = ab.cross(ac);
    if(o>0) return 1; //CCW
    if(o<0) return -1; //CW
    if(ab.dot(ac)<0){
        return 2; //C-A-B
    }else{
        if(ab.dot(ab)<ac.dot(ac)){
            return -2; //A-B-C
        }else{
            return 0; //A-C-B
        }
    }
}

vec interSection(vec& p0,vec& p1,vec& p2,vec& p3){
    vec p23=p3-p2,p02=p2-p0,p01=p1-p0;
    double k = p23.cross(p02)/p23.cross(p01);
    return p0+p01*k;
}

int isInterSection(vec& p0,vec& p1,vec& p2,vec& p3){//??????p[0]p[1]??¨p[2]p[3]
    switch(ccw(p0,p1,p2)*ccw(p0,p1,p3)){
        case -1:
        case -4:
            break;
        case 0:
            return ~(ccw(p0,p1,p2)|ccw(p0,p1,p3))?2:-1;//?§???§??\??????????????´???
        default:
            return 0;
    }
    switch(ccw(p2,p3,p0)*ccw(p2,p3,p1)){
        case -1:
        case -4:
        case 0:
            break;
        default:
            return 0;
    }
    return 1;
}

typedef pair<vec,int> P;

struct Section{
    vec v1,v2;//?§??????¨??????
    vector<P> cp;//??????(????????????????????¨?????????)
};

int main(void){
    int N;
    Section line;
    vector<Section> S;
    cin>>N;
    while(N--){
        S.clear();
        line.cp.clear();
        cin >> line.v1.x >> line.v1.y >> line.v2.x >> line.v2.y;
        int n; cin >> n;
        for(int i=0;i<n;i++){
            vec v1,v2;
            int o,l;
            cin >> v1.x >> v1.y >> v2.x >> v2.y >> o >> l;
            if(isInterSection(v1,v2,line.v1,line.v2)){
                line.cp.push_back(P(interSection(v1,v2,line.v1,line.v2),o?l:l^1));
            }
        }
        sort(line.cp.begin(),line.cp.end());
        int c=0,h=line.cp[0].second;
        for(int i=1;i<line.cp.size();i++){
            if(h!=line.cp[i].second){
                c++;
                h=line.cp[i].second;
            }
        }
        cout << c << endl;
    }
    return 0;
}

Measured memory_bytes: 3172
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <stdlib.h>
#include <string.h>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <stdio.h>
#include <tuple>
#include <bitset>
#include <cfloat>
#include <fstream>
#include <limits.h>
#include <list>
#include <math.h>
#include <random>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <numeric>
#include <utility>
#include <sstream>

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

using namespace std;
#define int long long
#define ll long long
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define FORR(i,a,b)for(ll i=(a);i<=(b);i++)
#define repr(i,n) for(ll i=n;i>=0;i--)
#define P pair<ll, ll>
#define sz(x) (ll)x.size()
#define ALL(x) (x).begin(),(x).end()
#define ALLR(x) (x).rbegin(),(x).rend()
#define VE vector<ll>
#define COUT(x) cout<<(x)<<endl
#define MA map<ll,ll>
#define SE set<ll>
#define PQ priority_queue<ll>
#define PQR priority_queue<ll,VE,greater<ll>>
#define COUT(x) cout<<(x)<<endl
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define EPS (1e-10)
#define pb push_back

const long long MOD = 1000000007;
//const long long MOD = 998244353;
const long long INF = 1LL << 60;
const double PI = acos(-1.0);


long long modinv(long long a, long long m) {
	long long b = m, u = 1, v = 0;
	while (b) {
		long long t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}
ll gcd(ll a, ll b) {
	if (a < b)swap(a, b);
	if (b == 0) return a;
	unsigned r;
	while ((r = a % b)) {
		a = b;
		b = r;
	}
	return b;
}
ll lcm(ll a, ll b) {
	ll g = gcd(a, b);
	return a * b / g;
}
bool prime(ll n) {
	for (ll i = 2; i <= sqrt(n); i++) {
		if (n%i == 0)return false;
	}
	return n != 1;
}
map<ll, ll> prime_factor(ll n) {
	map<ll, ll> ret;
	for (ll i = 2; i * i <= n; i++) {
		while (n % i == 0) {
			ret[i]++;
			n /= i;
		}
	}
	if (n != 1) ret[n] = 1;
	return ret;
}



const int MAX_N = 100010;



signed main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	int n, k; cin >> n >> k;
	int r, s, p; cin >> r >> s >> p;
	string t; cin >> t;
	string tmp = "";
	int ans = 0;
	rep(i, n) {
		if (i < k) {
			if (t[i] == 'r') {
				ans += p; tmp += 'p';
			}
			else if (t[i] == 's') {
				ans += r; tmp += 'r';
			}
			else {
				ans += s; tmp += 's';
			}
		}
		else {
			if (t[i] == 'r') {
				if (tmp[i - k] == 'p') {
					tmp += '?';
				}
				else {
					ans += p; tmp += 'p';
				}
			}
			else if (t[i] == 's') {
				if (tmp[i - k] == 'r') {
					tmp += '?';
				}
				else {
					ans += r; tmp += 'r';
				}
			}
			else {
				if (tmp[i - k] == 's') {
					tmp += '?';
				}
				else {
					ans += s; tmp += 's';
				}
			}
		}
		
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
char s[1500];
int main(){
	cin>>s;
	int len=strlen(s);
	if(s[len-1]=='s'){
		s[len]='e';
		s[len+1]='s';
	}
	else{
		s[len]='s';
	}
	cout<<s;
	return 0;
}

Measured memory_bytes: 3592
use proconio::fastout;
use proconio::input;

#[fastout]
fn main() {
    input! {
        n: usize, d: i64,
        xys: [(i64, i64); n],
    }
    let d = d * d;
    let ans = xys.iter().filter(|&(x, y)| (x * x + y * y) <= d).count();
    println!("{}", ans);
}


Measured memory_bytes: 7804
#include "bits/stdc++.h"
#define REP(i,n,N) for(ll i=(n); i<(N); i++)
#define RREP(i,n,N) for(ll i=(N-1); i>=n; i--)
#define CK(n,a,b) ((a)<=(n)&&(n)<(b))
#define ALL(v) (v).begin(),(v).end()
#define p(s) cout<<(s)<<endl
#define p2(a,b) cout<<(a)<<" "<<(b)<<endl
typedef long long ll;
using namespace std;
const ll inf=1e18;

ll D,N;
int main(){
    while(cin>>D>>N){
        if(N==100){
            if(D==0) p(101);
            else if(D==1) p(10100);
            else p(1010000);
            return 0;
        }
        D = pow(100,D);
        ll ans=D*N;
        p(ans);
        return 0;
    }

}

Measured memory_bytes: 512
#include <iostream>

int main() {
  int w;
  int h;
  int x;
  int y;
  int r;
  std::cin >> w >> h >> x >> y >> r;

  bool flag = false;
  if(x + r <= w && x - r >= 0) {
    if(y + r <= h && y - r >= 0) {
      flag = true;
    }
  }

  if(flag) {
    std::cout << "Yes" << std::endl;
  }
  else {
    std::cout << "No" << std::endl;
  }
  return 0;
}

Measured memory_bytes: 3072
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
template <class T> ll size(const T &x) { return x.size(); }
#define rep(i,a,b) for(ll i = (a); i < (b); ++i)
#define iter(it,c) for(__typeof((c).begin()) it = (c).begin(); it != (c).end();++it)
#define MOD 1000000007
#define pb push_back
#define fs first
#define sc second
typedef pair<ll,ll> ii;
typedef vector<ll> vi;
typedef vector<ii> vii;

const int INF = 2147493647;
const double pi = acos(-1);
const double EPS = 1e-9;

int main()
{
    ll n, k;
    cin >> n >> k;
    vi A(n);
    rep(i,0,n) cin >> A[i];
    ll sm = 0;
    rep(i,0,n){
        ll cnt1 = 0;
        rep(j,i+1,n){
            if(A[i] > A[j]) cnt1++;
        }
        ll cnt2 = 0;
        rep(j,0,n){
            if(A[i] > A[j]) cnt2++;
        }
        ll r = (k*(k-1)/2)% MOD;
        sm += (r*cnt2) % MOD;
        sm += (k*cnt1) % MOD;
        sm = (sm) % MOD;
    }
    cout << sm << endl;
}


Measured memory_bytes: 256
N = int(input())
A = list(map(int, input().split()))
Q = int(input())
List = [0 for _ in range(10**5)]
for x in A:
  List[x-1] += 1
ans = sum(A)
for i in range(Q):
  B, C = map(int, input().split())
  if List[B-1] != 0:
    ans += (C-B)*List[B-1]
    List[C-1] += List[B-1]
    List[B-1] = 0
  print(ans)

Measured memory_bytes: 90788
#include <iostream>

using namespace std;

int main()
{
    int w,h,x,y,r;

    cin>>w>>h>>x>>y>>r;

    if(w<0)
        w = w+(w*w);
    if(h<0)
        h = h+(h*h);
    if(x<0)
        x = x+(x*x);
    if(y<0)
        y = y+(y*y);

    if(w>=(x+r) && h>=(y+r))
            cout<<"Yes"<<endl;
    else
        cout<<"No"<<endl;

    return 0;
}





Measured memory_bytes: 3092
#include<iostream>
using namespace std;
int main()
{
	int x, y;
	while (1)
	{
		cin >> x >> y;
		if (x == 0 && y == 0) break;
		if (x > y)
		{
			int t = x;
			x = y;
			y = t;
		}
		cout << x << " " << y << endl;
	}

	return 0;
}


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

#define rep(i, n) for(int i = 0; i < (n); ++i)
#define repc(i, t, n) for(int i = t; i < (n); ++i)

using namespace std;
using ll = long long;

int main(){

	vector<int> n(3);
	rep(i, 3) cin >> n[i];
	swap(n[0], n[1]);
	swap(n[0], n[2]);
	cout << n[0] << " " << n[1] << " " << n[2] << endl;

	return 0;
}

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

bool is_palindrome(int x)
{
	int s=0,p=x;
	
	while(p!=0)
	{
		s=s*10+p%10;
		p/=10;
	}
	
	if(x==s)
		return true;
	else
		return false;
}

int main()
{
	ios::sync_with_stdio(false);
	
	int n,m,s=0;
	cin>>n>>m;
	
	for(int i=n;i<=m;i++)
		if(is_palindrome(i))
			s++;
	
	cout<<s<<endl;
	return 0;
}

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

AB = A+B

if AB >= N:
    if A <= N:
        print(A)
    else:
        print(N)
else:
    amari = N % AB
    if amari > A:
        ans = A * (N//AB) + A
    else:
        ans = A* (N//AB) + amari
    print(ans)

Measured memory_bytes: 3060
def main():
    N = int(input())
    P = list(map(int, input().split()))

    toSkip = False
    count = 0
    for i in range(1, len(P)+1):
        p = P[i-1]
        if p != i or toSkip:
            toSkip = False
            continue

        # swap
        count += 1
        toSkip = True

    print(count)

        
if __name__ == "__main__":
    main()



Measured memory_bytes: 14008
#include<iostream>
#include<algorithm>
#include<string>
using namespace std;
int main(){
    int a, b;
    cin >> a >> b;
    int high[1000] = {0};
    for(int i = 1;i <= 999;i++){
        high[i] = high[i-1]+i;
    }
    for(int i = 1;i <= 999;i++){
        if(high[i] - a == high[i+1] - b)cout << high[i] - a;
    }
}


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

int main()
{   char s[100001];
    scanf("%s",s);
    int k,l=strlen(s);
    scanf("%d",&k);
    int arr[l];
    for(int i=0;i<l;i++){
        arr[i]=s[i]-'a';
    }
    int i=0;
    while(k>0&&i<l){
        if(arr[i]==0){
            i++;
            continue;
        }
        if(k>=26-arr[i]){
            k-=(26-arr[i]);
            arr[i]=0;
            }
            i++;
        }
        arr[l-1]+=k;
        arr[l-1]%=26;
    for(int i=0;i<l;i++){
        printf("%c",'a'+arr[i]);
    }
    return 0;
}


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

int main() {
  ll A, B, V, W, T;
  cin >>A>>V>>B>>W>>T;
  ll def = abs(B-A)-(V-W)*T;
  if(def <= 0) {
    cout << "YES" <<endl;
  }else{cout << "NO" <<endl;}
  
}


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

#define rep(i, N) for(int i = 0;i < N;i++)

typedef long long ll;

const int mod = 1e9 + 7;

using namespace std;



int main(void) {
	ll A, B, V, W, T;
	cin >> A >> V >> B >> W >> T;

	ll dist = abs(A - B);
	ll x = V-W;

	cout << (x * T >= dist ? "YES" : "NO") << endl;

	return 0;
}

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

int main() {

    int a,b,c,k;
    cin>>a>>b>>c>>k;
    int sum=0;

    for(int i=0;i<k;i++){
        if(a==max({a,b,c})){
            a*=2;
        }
        else if(b==max({a,b,c})){
            b*=2;
        }
        else{
            c*=2;
        }
        sum=a+b+c;
    }
    cout<<sum<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
    int k;
    int counta=0;
   int countb=0;

    cin>>k;
    for(int i=1;i<=k;i++){
        if(i%2==0)counta++;
        else countb++;
    }
    cout<<counta*countb<<endl;
}

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

vector<int> binary(int i, int n, int N){
    int x = 1;
    rep(j,N){
        x *= n;
    }
    vector<int> vec(N);
    rep(j,N){
        x /= n;
        vec[j] = i / x;
        i -= x * vec[j];
    }
    return vec;
}

int main(){
    string S;
    cin >> S;
    ll ans = 0;
    int N = S.size();
    if (S.size() == 1){
        ans = stoi(S);
    }
    else{
        int num = 1;
        rep(i,N - 1){
            num *= 2;
        }
        for (int i = 0; i < num; i++){
            vector<int> plus = binary(i,2,N - 1);
            int left = 0;
            int count = 1;
            rep(j,N){
                if (j == N - 1 || plus[j] == 1){
                    ans += stoll(S.substr(left, count));
                    left = j + 1;
                    count = 1;
                }
                else{
                    count++;
                }
            }
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define rep(i, n) for(int i = 0; (i) < (n); (i)++)
#define FOR(i, m, n) for(int i = (m); (i) < (n); (i)++)
#define All(v) (v).begin(), (v).end()
#define MP make_pair
#define pb push_back
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1 << 30;
const ll LINF = 1LL << 61;
const int MOD = 1e9 + 7;

int main() {
    string a, b;
    cin >> a >> b;
    if(a[0] == b[2] && a[1] == b[1] && a[2] == b[0]) {
        cout << "YES" << endl;
    } else {
        cout << "NO" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include<iostream>

using namespace std;

int main(){
  
  int num;
  float numf;
  int spr;
  float sprf;
  
  cin >> num;
  
  for(int i = 0;i<num;i++)
    if(i%2==0)spr++;
  numf = (float)num;
  sprf = (float)spr;  
  
  cout << sprf/numf << endl;
  
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <vector>
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <numeric>
#include <cassert>
#include <memory>
#include <stack>
#include <set>
#include <map>
#include <cctype>
#include <climits>
#include <list>
#include <queue>

#define INF 1000000000
#define MOD 1000000007
typedef long long ll;
typedef unsigned long long ull;
using namespace std;

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

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

  int N,K; cin>>N>>K;
  vector<int> A(N);
  for(int i=0; i<N; i++) {
    cin>>A[i];
    if(A[i] == K) {
      cout << "POSSIBLE" << endl;
      exit(0);
    }
  }
  sort(A.begin(), A.end());
  if(A.back() < K) {
    cout << "IMPOSSIBLE" << endl;
    exit(0);
  }

  int igcd = A[0];
  for(int i=1; i<N; i++) {
    igcd = gcd(igcd, A[i]);
  }
  bool ok = K % igcd == 0 ? true : false;

  string ans = ok ? "POSSIBLE" : "IMPOSSIBLE";
  cout << ans << endl;
}


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

using namespace std;

typedef pair<int, int> P;
typedef long long ll;
#define rep(i, n) for(int i=0;i<(n);i++)
#define rep2(i, m, n) for(int i=m;i<(n);i++)
#define rrep(i, n, m) for(int i=n;i>=(m);i--)
using Graph = vector<vector<int>>;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const ll MOD = 1000000007;
#ifdef __DEBUG

#include "cpp-pyprint/pyprint.h"

#endif

void Main() {
    int N;
    cin >> N;
    map<string, map<int, int>> di;
    for (int i = 0; i < N; ++i) {
        string s;
        int p;
        cin >> s >> p;
        di[s][-p] = i + 1;
    }
    for(auto& d: di){
        for(auto& ans : d.second){
            //print(ans);
            cout << ans.second << endl;
        }
    }
}

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


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

# define C continue;
# define R return

# define D double
# define I insert
# define ll long long
# define ld long double

# define ull unsigned long long
# define ui unsigned int

# define pb push_back
# define pf push_front

# define vi vector < int >
# define vc vector < char >
# define vs vector < string >
# define vb vector < bool >
# define vd vector < D >
# define vll vector < ll >
# define vull vector < ull >
# define vld vector < ld >
# define PQ priority_queue

# define vvi vector < vector < int > >
# define vvb vector < vector < bool > >
# define vvc vector < vector < char > >
# define vvs vector < vs >
# define vvll vector < vector < ll > >
# define vvd vector < vector < D > >
# define vvld vector < vector < ld > >

# define all(v) (v).begin() , (v).end()
# define allrev(v) (v).rbegin() , (v).rend()
# define allcomp(v) v.begin() , v.end() , comp
# define allrevcomp(v) v.rbegin() , v.rend() , comp

# define pii pair < int , int >
# define pll pair < ll , ll >
# define pld pair < ld , ld >
# define pDD pair < D , D >

# define vpld vector < pld >
# define vpii vector < pii >
# define vpll vector < pll >
# define vpDD vector < pDD >

# define vvpii vector < vector < pii > >
# define F first
# define S second
# define mp make_pair

# define dist(a,b,p,q) sqrt((p-a)*(p-a) + (q-b)*(q-b))

# define pp(n) printf("%.10Lf",n);
# define line cout<<"\n";
# define fast ios_base::sync_with_stdio(false) ; cin.tie(0) ; cout.tie(0);

# define fr(a,b) for(int i = a; i < b; i++)
# define rep(i,a,b) for(int i = a; i < b; i++)

string vow = "aeiou";
int month[] = {-1, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};

const int dxhorse[] = {-2, -2, -1, -1, 1, 1, 2, 2};
const int dyhorse[] = {1, -1, 2, -2, 2, -2, 1, -1};

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

const ld pie = 3.1415926535897932384626 ;
const ll mod = 1e9 + 7 ;

void solve(){

    string s;
    cin >> s;
    int ans = 0;
    int n  = s.size();
    fr(1,n){

        if(i && s[i]!=s[i-1])
            ans++;

    }
    cout << ans;line
  	return;

}

int main(){
	fast
	int tc=1;
	//cin >> t;
	while(tc--){
             solve();
    }

	R 0;
}


Measured memory_bytes: 3728
S = input()
scount = 0
tcount = 0
ans = 0
l = len(S)
for c in S:
    if c == "S":
        scount += 1
    else:
        if scount >0:
            scount -=1
            ans += 2

ans += min (scount,tcount) * 2
ans = len(S) -ans
print(ans)

Measured memory_bytes: 3500
from collections import Counter
from collections import deque
from functools import reduce
from pprint import pprint
import bisect
import copy
import fractions
import itertools
import math
import queue
import random
import sys
import time
sys.setrecursionlimit(10**7)
INF = 10 ** 18
MOD = 10 ** 9 + 7
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def MI(): return map(int, sys.stdin.readline().split())
def II(): return int(sys.stdin.readline())
def IS(): return input()
def C(x): return Counter(x)
def GCD_LIST(numbers): return reduce(fractions.gcd, numbers)
def LCM_LIST(numbers): return reduce(LCM, numbers)
def LCM(m, n): return (m * n // fractions.gcd(m, n))


n = II()
a = LI()
print(max(a) - min(a))


Measured memory_bytes: 67564
n = int(input())
a = [int(input()) for _ in range(n)]
a.sort()
front = a[n - 1]
back = a[n - 1]
i = 0
j = n - 2
ans = 0
while i <= j:
    diff1 = abs(front - a[i])
    diff2 = abs(back - a[i])
    diff3 = abs(front - a[j])
    diff4 = abs(back - a[j])
    mx = max(diff1, diff2, diff3, diff4)
    ans += mx
    if mx == diff1:
        front = a[i]
        i += 1
    elif mx == diff2:
        back = a[i]
        i += 1
    elif mx == diff3:
        front = a[j]
        j -= 1
    else:
        back = a[j]
        j -= 1
print(ans)


Measured memory_bytes: 7516
#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
   int a[3];
   for(int i=0;i<3;i++){
   cin>>a[i];
}
sort(a,a+3);
for(int i=0;i<2;i++){
cout<<a[i];
cout<<" ";
}
cout<<a[2]<<endl;
}

Measured memory_bytes: 1176
#include <bits/stdc++.h>
#include <vector>
#include <numeric>
#define PI 3.14159265358979323846
#define MAXINF 1e18L
#define INF 1e9L
#define EPS 1e-9
#define REP(i, n) for(int i=0;i<int(n);++i)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define ALL(v) v.begin(),v.end()
#define SORT(v) sort(ALL(v))
#define DEBUG(x) cerr<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cerr<<#v<<":";for(int i=0;i<v.size();i++) cerr<<" "<<v[i]; cerr<<endl
#define pb push_back
using namespace std;
template<class A>void pr(A a){cout << (a) << endl;}
template<class A,class B>void pr(A a,B b){cout << a << " "  ;pr(b);}
template<class A,class B,class C>void pr(A a,B b,C c){cout << a << " " ;pr(b,c);}
template<class A,class B,class C,class D>void pr(A a,B b,C c,D d){cout << a << " " ;pr(b,c,d);}
typedef long long ll;
typedef pair<int, int> intint;

int main(void)
{
    string n;
    cin >> n;
    cout << (n[0] == '1' ? 9 : 1) << (n[1] == '1' ? 9 : 1) << (n[2] == '1' ? 9 : 1) << endl;
    // pr(n[2] == 1 ? 9 : 1, n[1] == 1 ? 9 : 1, n[0] == 1 ? 9 : 1);
}

Measured memory_bytes: 256
//<============ Author --> @venom ============>//
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>

using namespace std;
using namespace __gnu_pbds;

#define fo(i,n)           for(int i=0;i<n;i++)
#define int               long long
#define pb                emplace_back
#define mp                make_pair
#define ff                first
#define ss                second
#define all(x)            x.begin(), x.end()
#define sortall(x)        sort(all(x))
#define sortrev(x)        sort(all(x), greater<int>())
#define w(x)              int x; cin>>x; while(x--)
#define trunc(x,y)        fixed<<setprecision(y)<<x
#define mk(arr, n, type)  type *arr=new type[n];
#define PI                3.1415926535897932384626
#define mod               1000000007
#define inf               1e9 + 5
#define FIO               ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
typedef pair<int, int>    pi;
typedef vector<int>       vi;
typedef vector<pi>        vpi;
typedef vector<vi>        vvi;
typedef tree<int, null_type, less<int>, rb_tree_tag,
        tree_order_statistics_node_update> indexed_set;
const int N = 3e5, M = N;
int mpow(int base, int exp);
int gcd(int a, int b) {if (a == 0) return b; return gcd(b % a, a);}
//<----------------------------------------------------------------------------->//
void fastIO()
{
  FIO;
#ifndef ONLINE_JUDGE
  // for getting input from input.txt
  freopen("input.txt", "r", stdin);
  // for writing output to output.txt
  freopen("output.txt", "w", stdout);
#endif
}

vector<int> graph[100001];
int dp[100001];

int solve(int src)
{
  if (dp[src] != -1)
    return dp[src];

  bool leaf = 1;
  int bestChild = 0;

  for (int child : graph[src])
  {
    leaf = 0;

    bestChild = max(bestChild, solve(child));
  }

  return dp[src] = leaf ? 0 : 1 + bestChild;
}

int32_t main()
{
  FIO;

  memset(dp, -1, sizeof dp);

  int n, m;
  cin >> n >> m;

  for (int i = 0; i < m; i++)
  {
    int u, v;
    cin >> u >> v;

    graph[u].pb(v);
  }

  int ans = 0;

  for (int i = 1; i <= n; i++)
  {
    ans = max(ans, solve(i));
  }

  cout << ans;

  return 0;
}

int mpow(int base, int exp) {
  base %= mod;
  int result = 1;
  while (exp > 0) {
    if (exp & 1) result = ((int)result * base) % mod;
    base = ((int)base * base) % mod;
    exp >>= 1;
  }
  return result;
}

Measured memory_bytes: 8576
#include<bits/stdc++.h>
using namespace std;
using ld=long double;
struct Edge{
    int from,to;
    ld cost;
};

using Edges=vector<Edge>;
using Graph=vector<Edges>;
ld mst(int n,Graph& g){
    vector<int> used(n,false);
    priority_queue<pair<ld,int>> que;
    que.push({0,0});
    ld res=0;
    while(!que.empty()){
        auto ret=que.top();
        que.pop();
        int v=ret.second;;
        ld cost=ret.first;
        if(used[v]) continue;
        used[v]=true;
        res+=cost;
        for(int i=0;i<g[v].size();i++){
            que.push({g[v][i].cost,g[v][i].to});
        }
    }
    return res;
}

int main(){
    int n,m;
    cin>>n>>m;
    vector<ld> x(n),y(n);
    for(int i=0;i<n;i++) cin>>x[i]>>y[i];
    Graph g(n);
    ld sum=0;
    for(int i=0;i<m;i++){
        int p,q;
        cin>>p>>q;
        p--,q--;
        ld dist=sqrt((x[p]-x[q])*(x[p]-x[q])+(y[p]-y[q])*(y[p]-y[q]));
        sum+=dist;
        g[p].push_back(Edge{p,q,dist});
        g[q].push_back(Edge{q,p,dist});
    }
    for(int i=1;i<n;i++){
        g[0].push_back(Edge{0,i,0});
        g[1].push_back(Edge{i,0,0});
    }
    cout<<setprecision(10)<<fixed;
    cout<<sum-mst(n,g)<<endl;
    return 0;
}


Measured memory_bytes: 9000
from sys import setrecursionlimit as SRL, stdin, stdout

SRL(10 ** 7)
rd = stdin.readline
rrd = lambda: map(int, rd().strip().split())

n, q = rrd()

v = [[] for _i in range(n + 10)]

for i in range(n - 1):
    x, y = rrd()
    v[x].append(y)
    v[y].append(x)

add = [0] * (n + 10)

for i in range(q):
    p, x = rrd()
    add[p] += x

p = [(1, 0)]
vis = [0] * (n + 2)
while len(p):
    now, fa = p.pop()
    add[now] += add[fa]
    vis[now] = 1
    for i in v[now]:
        if not vis[i]:
            p.append((i,now))

stdout.write(" ".join(map(str, add[1:n + 1])))


Measured memory_bytes: 126248
#define _GLIBCXX_DEBUG
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>

using namespace std;
typedef long long ll;

#define REP(i,n) for(int i=0;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()

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

    ll res = 1;
    while(x*2 <= y) {
        res++;
        x *= 2;
    }

    cout << res << endl;
}


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

using namespace std;

typedef long long ll;
typedef pair<ll, ll> pll;


const ll LongINF=1e13+7;
const int INF=1e9+7;
const int dx[]={0,1,0,-1};
const int dy[]={1,0,-1,0};

template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b;return true;}return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b;return true;}return false;}
template <class T, class Y>T GCD(T a, Y b){if(a<b){int c=a;a=b;b=c;}if (a % b == 0){return b;}return GCD(b, a % b);}
void clear(queue<pair<int, int>> &q){queue<pair<int, int>> empty;swap(q, empty);} //queueの中身の型は適時変更を忘れない

#define REP(i,a,b) for(int i=(a);i<(b);i++)
#define rep(i,n) REP(i,0,n)
#define pb push_back
#define rv reverse
#define ALL(a) (a).begin(),(a).end()

//上から何枚かをとった和と、残りの和の差である！！

int main(){
    ll N,X=0,x=0,ANS=LongINF;
    cin>>N;
    vector<ll> A(N);

    rep(i,N){
        cin>>A[i];
        X+=A[i];
    }

    rep(i,N-1){
        X-=A[i];
        x+=A[i];
        ANS=min(ANS,abs(x-X));
    }
    cout<<ANS<<endl;

    return 0;
}

//a=97,z=122

Measured memory_bytes: 1792
N, W = map(int, input().split())

w = [0] * (N + 1)
v = [0] * (N + 1)
for i in range(1, N + 1):
    w[i], v[i] = map(int, input().split())
MAX_W = 1000000
dp = [[0] * (W + 1) for _ in range(N + 1)]

for i in range(1, N + 1):
    for weight in range(1, W + 1):
        if weight - w[i] >= 0:
            dp[i][weight] = max(dp[i][weight], dp[i - 1][weight-w[i]] + v[i])
        dp[i][weight] = max(dp[i-1][weight], dp[i][weight])

print(dp[N][W])

Measured memory_bytes: 121052