akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
int main(){
  string s; cin>>s;
  int digit = s.size()-1;
  long tmp,sum;
  sum = 0;
  for( int i=0; i < ( 1 << digit); ++i){
    tmp = s[0] -'0';
    for( int j=0; j<digit; ++j){
      if( i & ( 1 << j)){
        sum += tmp; tmp = 0;
      }
      tmp = 10*tmp + s[j+1] - '0';
    }
    sum += tmp;
  }
  cout << sum << endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int x[3];
int main(void){
    cin >> x[0] >> x[1] >> x[2];
    int ans=300;
    for(int i=0;i<3;i++){
        for(int j=i+1;j<3;j++){
            ans=min(ans,x[i]+x[j]);
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod=1e9+7;
//const ll num=834732659;
int main()
{
    ll n,k;
    ll ans=0;
    cin>>n>>k;
    for(ll i=k;i<=n+1;i++)
    {
        ans+=i*n-i*(i-1)+1;
        ans%=mod;
    }
    cout<<ans<<endl;
    return 0;
}


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

int n;
double dp[310][310][310];

double solve(int x, int y, int z){
  if(x<0 || y<0 || z<0) return 0;
  if(dp[x][y][z]>0) return dp[x][y][z];
  return dp[x][y][z] = (solve(x-1, y, z)*x + solve(x+1, y-1, z)*y + solve(x, y+1, z-1)*z + n) / (x+y+z);
}

int main(){
  cin >> n;
  int cnt[3];
  rep(i, 3) cnt[i] = 0;
  rep(i, n){
    int a; cin >> a;
    cnt[a-1]++;
  }
  rep(i, cnt[0]+1)rep(j, cnt[1]+1)rep(k, cnt[2]+1) dp[i][j][k] = 0;
  dp[1][0][0] = n;
  cout << fixed << setprecision(10) << solve(cnt[0], cnt[1], cnt[2]) << endl;
}

Measured memory_bytes: 225536
import java.util.*;
public class Main{
	public static void main(String[] args){
  		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int m = sc.nextInt();
		boolean[] start = new boolean[n+1];
		boolean[] end = new boolean[n+1];
		for(int i=0;i<n;i++){
			start[i]=false;
			end[i]=false;
		}
		int keep1;
		int keep2;
		boolean result = false;
		for(int i=0;i<m;i++){
			keep1 = sc.nextInt();
			keep2 = sc.nextInt();
			if(keep1==1){
				start[keep2-1]=true;
			}
			else if(keep2==n){
				end[keep1-1]=true;
			}
		}
		for(int i=0;i<=n;i++){
			if(start[i]&&end[i]){
				System.out.println("POSSIBLE");
				return;
			}
		}
		System.out.println("IMPOSSIBLE");
	}
}


Measured memory_bytes: 94304
#include <bits/stdc++.h>
using namespace std;
using Int = long long;
int main()
{
    int N; cin >> N;
    vector<int> H(N); for (auto& h : H) cin >> h;
    int M = 0, ans = 0;
    for (int i = 0; i < N; i++) {
        if (H[i] >= M) ans++;
        M = max(M, H[i]);
    }
    cout << ans << '\n';
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define M 1000000007
#define ll long long
#define REP(i,a,b) for(ll i=a;i<b;i++)
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define vi vector<int>
#define vll vector<long long>
#define INF 1000000000

ll modInverse(ll a, ll m);
ll gcd(ll a, ll b);
ll power(ll x, unsigned ll y, unsigned ll m);
ll logint(ll x,ll y);


ll gcd(ll a, ll b)
{
    if (a == 0)
        return b;
    return gcd(b%a, a);
}

ll power(ll x, unsigned ll y, unsigned ll m)
{
    if (y == 0)
        return 1;
    ll p = power(x, y/2, m) % m;
    p = (p * p) % m;

    return (y%2 == 0)? p : (x * p) % m;
}

ll modInverse(ll a, ll m)
{
    ll m0 = m;
    ll y = 0, x = 1;

    if (m == 1)
      return 0;

    while (a > 1)
    {
        // q is quotient
        ll q = a / m;
        ll t = m;

        // m is remainder now, process same as
        // Euclid's algo
        m = a % m, a = t;
        t = y;

        // Update y and x
        y = x - q * y;
        x = t;
    }

    // Make x positive
    if (x < 0)
       x += m0;

    return x;
}

void pairsort(ll a[],ll b[], ll n)
{
    pair<ll, ll> pairt[n];

    // Storing the respective array
    // elements in pairs.
    for (ll i = 0; i < n; i++)
    {
        pairt[i].first = a[i];
        pairt[i].second = b[i];
    }

    // Sorting the pair array.
    sort(pairt, pairt + n);

    // Modifying original arrays
    for (ll i = 0; i < n; i++)
    {
        a[i] = pairt[i].first;
        b[i] = pairt[i].second;
    }
}

ll logint(ll x,ll y)
{
    ll ans=0;
    ll a=1;
    for(ll i=0;i<x;i++)
    {
        if(x<=a)
        {
            return ans;
        }
        ans++;
        a*=y;
    }
    return -1;
}
ll dp[3001][3001];
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    /*
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    */
    string a, b;
    cin>>a>>b;
    a = '0'+a;
    b = '0'+b;
    ll n = a.size();
    ll m = b.size();
    memset(dp, 0, sizeof(dp));
    vector<char>ans(0);
    REP(i, 1, n){
        REP(j, 1, m){
            if(a[i] != b[j]){
                dp[i][j] = max(dp[i-1][j], dp[i][j-1]);
            }
            else{
                //ans.pb(ar[i]);
                dp[i][j] = dp[i-1][j-1]+1;
            }
        }
    }
    n--;
    m--;
    ll cc = dp[n][m];
    //cout<<cc;
    while(cc){
        if(dp[n][m] == dp[n-1][m]){
                n--;
            }
        else if(dp[n][m] == dp[n][m-1]){
                dp[n][m] == dp[n][m-1];
                m--;
            }
        else if(dp[n][m] == dp[n-1][m-1]+1){
            ans.pb(a[n]);
            cc--;
            n--;
            m--;
        }
    }
    reverse(ans.begin(), ans.end());
    REP(i, 0, ans.size()){
        cout<<ans[i];
    }
}


Measured memory_bytes: 70656
#include <bits/stdc++.h>
using namespace std;
#define REP(i,N) for(i=0;i<N;i++)
#define MAX_I INT_MAX //1e9
#define MIN_I INT_MIN //-1e9
#define MAX_UI UINT_MAX //1e9
#define MAX_LL LLONG_MAX //1e18
#define MIN_LL LLONG_MIN //-1e18
#define MAX_ULL ULLONG_MAX //1e19
  typedef long long ll;
  typedef pair<int,int> PII;
  typedef pair<char,char> PCC;
  typedef pair<ll,ll> PLL;
  typedef pair<char,int> PCI;
  typedef pair<int,char> PIC;
  typedef pair<ll,int> PLI;
  typedef pair<int,ll> PIL; 
  typedef pair<ll,char> PLC; 
  typedef pair<char,ll> PCL; 

int main(void){
  int N;cin >> N;
  int W[N];
  int sum = 0;
  int i;REP(i,N){
    cin >> W[i];
    sum += W[i];
  }
  int minimum = MAX_I;
  int sum2 = 0;
  REP(i,N){
    sum2 += W[i];
    minimum = min( minimum, abs(sum-2*sum2) );
  }
  cout << minimum << endl;
  return 0;
}


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

int main()
{
	int n, p = 0, cnt;
	string key[] = {"", ".,!? ", "abc", "def", "ghi", "jkl", "mno", "pqrs", "tuv", "wxyz"};
	string str;
	
	cin >> n;
	while (cin >> str) {
		for (char& c : str) {
			n = c - '0';
			if (n) {
				cnt++;
			} else if (p == n) {
			}else {
				cout << key[p][(cnt-1) % key[p].size()];
				cnt = 0;
			}
			p = n;
		}
		cout << endl;
	}
	
	return 0;
}

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

int main()
{
  int n, k, x, ans = 0;

  cin >> n >> k;
  for (int i = 0; i < n; i++)
  {
    cin >> x;
    ans += 2 * min(x, abs(k - x));
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
N,X=map(int,input().split())
abx=list(map(lambda x:abs(int(x)-X),input().split()))

def gcd(x,y):
  if x==0:
    return y
  else:
    return gcd(y%x,x)

g=abx[0]
for i in range(N-1):
  g=gcd(g,abx[i+1])

print(g)

Measured memory_bytes: 14224
def main():
    N, K = list(map(int, input().split()))
    D = set(map(int, input().split()))

    OK_N = set([i for i in range(0, 10)]) - D
    OK_N = list(OK_N)

    l1 = [str(i)for i in OK_N]
    for _ in range(len(str(N)) - 1):
        tmp_l = []
        for li in l1:
            # print(li)
            for ni in OK_N:
                s = li + str(ni)
                tmp_l.append(s)
        l1 = tmp_l

    l2 = [str(i)for i in OK_N]
    for _ in range(len(str(N))):
        tmp_l = []
        for li in l2:
            # print(li)
            for ni in OK_N:
                s = li + str(ni)
                tmp_l.append(s)
        l2 = tmp_l

    lc = []
    for li in l1:
        lc.append(int(li))
    for li in l2:
        lc.append(int(li))
    # print(lc)

    lc.sort()
    for li in lc:
        if li >= N:
            print(li)
            break

if __name__ == "__main__":
    main()

Measured memory_bytes: 9828
n = gets.to_i;
a, b, c = $<.map{ |l| [0]+l.chomp.split.map(&:to_i).sort+[Float::INFINITY] }
puts b.drop(1).reverse.drop(1).reverse.inject(0) { |acc, bi| acc+((0..n+1).bsearch{ |i| a[i] >= bi }-1)*(n+1-((0..n+1).bsearch{ |i| bi < c[i]}))}


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

using namespace std;

#define pb push_back
#define mk make_pair
#define mod 1000000007
#define ff first
#define ss second

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

ll modpow(ll a, ll b){

    ll ans=1;
    while(b){
        if(b&1){
            ans=(ans*a)%mod;
        }
        a=(a*a)%mod;
        b=b/2;
    }
    return ans;
}

vector<pair<int, int> > vt[20];

int main(){

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

    int n;
    cin>>n;

    for(int i = 1; i <= n; i++) {
        int s;
        cin>>s;

        for(int j = 0; j < s; j++) {
            int x,y;
            cin>>x>>y;
            vt[i].push_back(make_pair(x,y));
        }
    }

    int ans = 0;

    for(int i = 0; i < (1<<n); i++) {
        vector<int> vt1(20);
        int cnt = 0;
        int fl = 0;
        set<int> hon;
        for(int j = 0; j < n; j++) {
            if((1<<j) & i) {
                vt1[j+1] = 1;
                cnt++;
                hon.insert(j+1);
            }
        }

        for(int j = 1; j <= n; j++) {
            for(int k = 0; k < vt[j].size(); k++) {

                if(hon.find(j) == hon.end()) continue;

                if(vt[j][k].second == 1) {
                    if(hon.find(vt[j][k].first) == hon.end()) {
                        fl = 1;
                        break;
                    }
                } else {
                    if(hon.find(vt[j][k].first) != hon.end()) {
                        fl = 1;
                        break;
                    }
                }
            }
            if(fl == 1) break;
        }

        if(fl == 0) {
            ans = max(ans, cnt);
        }

    }

    cout<<ans<<endl;


}


Measured memory_bytes: 256
#include <iostream> 
#include <vector> 
#include <algorithm> 
#include <bits/stdc++.h> 
#include <stdlib.h> 
#include <stdio.h> 
#include <functional> 
#include<math.h> 
#include<cstring>
using namespace std;
int main(void){
    // Your code here!
   int N;
   cin >> N;
   vector<int> Odd(100010);
   vector<int> Even(100010);
   for(int i = 0; i < N; i++){
       int x;
       cin >> x;
       if(i % 2 == 0){
           Even.at(x)++;
       }
       else{
           Odd.at(x)++;
       }
   }
   
   
   int max_Odd = 0, max_Even = 0;
   int count_Odd, count_Even;
   
   for(int i = 0; i < 100010; i++){
       if(max_Odd <= Odd.at(i)){
           max_Odd = Odd.at(i);
           count_Odd = i;
       }
       if(max_Even <= Even.at(i)){
           max_Even = Even.at(i);
           count_Even = i;
       }
   }
   sort(Odd.begin(),Odd.end());
   sort(Even.begin(),Even.end());
   reverse(Odd.begin(),Odd.end());
   reverse(Even.begin(),Even.end());
   
   if(count_Even != count_Odd){
       cout << N - max_Odd - max_Even;
   }
   else{
       cout << min( N - Odd.at(0) - Even.at(1), N - Odd.at(1) - Even.at(0));
   }
}


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

#define ll long long
#define Fi first
#define Se second
#define Pb push_back
#define vi vector<int>
#define vp vector<pair<int,int>>
#define vvi vector<vector<int>>
#define vvp vector<vector<pair<int,int>>>

const int INF = 1e9;
const int MOD = 1e9+7;
using Graph = vector<vector<int>>; //Caution!! Segmentation Fault!! Don't forget to add +1!

#define all(v) v.begin(),v.end()
#define output_s(a) printf("%s\n",(a).c_str())

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define Rep(i,n,m) for(int i=(int)(n);i<(int)(m);i++)
#define RepS(i,n,m) for(int i=(int)(n);i<=(int)(m);i++)
#define RRepS(i,n,m) for(int i=(int)(n);i>=(int)(m);i--)
#define RepA(x) for(auto &item:(x))

void CINT(){}
template <class Head,class... Tail>
void CINT(Head&& head,Tail&&... tail){
    cin>>head;
    CINT(move(tail)...);
}    
#define CIN(...) int __VA_ARGS__;CINT(__VA_ARGS__)
#define LCIN(...) ll __VA_ARGS__;CINT(__VA_ARGS__)
#define SCIN(...) string __VA_ARGS__;CINT(__VA_ARGS__)

template<typename TypeInt> //最大公約数
TypeInt GCD(TypeInt a,TypeInt b){
    if(a%b==0) return b;
    else return GCD(b,a%b);
}
template<typename TypeInt> //最小公倍数
TypeInt LCM(TypeInt a,TypeInt b){
    return a*b/GCD(a,b);
}

int IN_int(){
    int x;
    scanf("%d",&x);
    return x;
}

//library----------------------------------------------

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

const int NMAX = 100;
bool flag;

bool cmp(int x,int y){
    return abs(0-x)<abs(0-y);
}

int main(){
    CIN(N,L);
    vi taste(N);
    int ans=0;
    Rep(i,0,N){
        taste[i]=L+(i+1)-1;
        ans+=taste[i];
    }
    sort(all(taste),cmp);
    ans-=taste[0];
    printf("%d\n",ans);

    return 0;
}

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

using namespace std;
const int N = 2e5+7;

int h[N],e[N*2],ne[N*2],idx;
int w[N];
int ans[N]; 
int low[N];

void add(int a,int b){
	e[idx] = b,ne[idx] = h[a] , h[a] = idx++;
}

void dfs(int s,int fa,int pos)
{
	int temp1=-1,temp2=0,k=0;
	if(low[pos] < w[s]) temp1 = low[pos+1] ,low[++pos] = w[s];
	else {
		int j = lower_bound(low+1,low+pos+1,w[s]) - low ;
		temp2 = low[j],k = j;
		low[j] = w[s];
	}
	ans[s] = pos;
	for(int i=h[s];~i;i=ne[i]){
		int j = e[i];
		if(j==fa) continue;
		dfs(j,s,pos);
	}
	if(temp1!=-1) low[pos] = temp1;
	else low[k] = temp2;
}

int main()
{
	int n,a,b;
	scanf("%d",&n);
	for(int i=1;i<=n;i++) scanf("%d",&w[i]);
	memset(h,-1,sizeof h);
	for(int i=1;i<n;i++){
		scanf("%d%d",&a,&b);
		add(a,b),add(b,a);
	}
	dfs(1,0,0);
	for(int i=1;i<=n;i++) printf("%d\n",ans[i]);
	return 0;
}


Measured memory_bytes: 23608
#include<bits/stdc++.h>
#define LL long long
#define M 100005 
using namespace std;
const int P=1e9+7; 
vector<int>edge[M];
int son[M];
int n,m;
LL ans=1,F[M],Ft[M];
int fast(int x,int n){
	LL res=1,a=x;
	while(n>0){
		if(n&1)res=(res*a)%P;
		a=a*a%P;
		n>>=1;
	}
	return res;
}
void dfs(int x,int f){
	son[x]=0;
	for(int i=0;i<edge[x].size();i++){
		int y=edge[x][i];
		if(y==f)continue;
		son[x]++;
		dfs(y,x); 
	} 
}
void DFS(int x,int f){
	if(son[x]==0)return;
	for(int i=0;i<edge[x].size();i++){
		int y=edge[x][i];
		if(y==f)continue;
		if(son[y]>m-2)ans=0;
		else ans=ans*F[m-2]%P*Ft[m-2-son[y]]%P;
		DFS(y,x);
	}
}

int main(){
	cin>>n>>m;
	F[0]=Ft[0]=1;
	for(int i=1;i<=m;i++){
		F[i]=F[i-1]*1LL*i%P;
		Ft[i]=fast(F[i],P-2);
	}
	int a,b;
	for(int i=1;i<n;i++){
		scanf("%d %d",&a,&b);
		edge[a].push_back(b);
		edge[b].push_back(a);
	}
	dfs(1,0);  
	if(son[1]>m-1){
		puts("0");return 0;
	}else{  
		ans=m*F[m-1]%P*Ft[m-1-son[1]]%P;  
		DFS(1,0);
		cout<<ans<<endl;
	}
	return 0;
}

Measured memory_bytes: 10752
def resolve():
    '''
    code here
    '''
    N, K = [int(item) for item in input().split()]
    prices = [int(item) for item in input().split()]

    prices.sort()

    res = 0
    for i in range(K):
        res += prices[i]

    print(res)


if __name__ == "__main__":
    resolve()


Measured memory_bytes: 9180
#include <iostream>
#include <string>

using namespace std;

const int NMAX = 1e6;

int N;
string s;

int v[NMAX + 2];
bool hasOne;

int GETP2(int nr)
{
    int ans = 0;

    while(nr % 2 == 0)
    {
        ans++;
        nr /= 2;
    }

    return ans;
}

bool GetParity() ///0->even, 1->odd
{
    ///C(N, K) = N * (N - 1) * (N - 2) * ... * (N - K + 1)
    ///        / 1 *    2    *    3    * ... *      K

    ///C(N, K + 1) = asBefore * (N - K) / (K + 1)

    long long nrPow2 = 0;

    int ans = 0;

    for(int i = 1; i <= N / 2; i++) ///C(N - 1, i - 1)
    {
        if(v[i] % 2 == 1)
        {
            if(nrPow2 == 0)
                ans++;
        }

        if(v[N - i + 1] % 2 == 1)
        {
            if(nrPow2 == 0)
                ans++;
        }

        nrPow2 += GETP2(N - i);
        nrPow2 -= GETP2(i);
    }

    if(N % 2 == 1)
    {
        if(v[N / 2 + 1] % 2 == 1)
        {
            if(nrPow2 == 0)
                ans++;
        }
    }

    return (ans % 2 == 1);
}

int main()
{
    cin >> N >> s;

    for(int i = 1; i <= N; i++)
    {
        v[i] = s[i - 1] - '1';
        if(v[i] == 1)
            hasOne = true;
    }

    bool parity = GetParity();

    if(parity == 1)
        cout << 1 << '\n';
    else
    {
        if(hasOne == 1)
            cout << 0 << '\n';
        else
        {
            for(int i = 1; i <= N; i++)
                v[i] /= 2;

            parity = GetParity();

            cout << 2 * parity << '\n';
        }
    }

    return 0;
}


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

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

int main(void) {

  string s;
  cin>>s;
  bool a=false,b=false;
  int f,l;
  f = (int)(s[0]-'0')*10+(int)(s[1]-'0');
  l = (int)(s[2] -'0' )*10+(int)(s[3]-'0');
  a = (0 < f && f <= 12);
  b = (0 < l && l <= 12);
  if(a){
    if(b)cout<<"AMBIGUOUS";
	else cout<<"MMYY"; 
  }else{
  	if(b)cout << "YYMM";
    else cout<< "NA";
  }
  
  return 0;
}


Measured memory_bytes: 256
package main

import "fmt"

func main() {
        var m1, m2, d1, d2 string
        fmt.Scanf("%s %s", &m1, &d1)
        fmt.Scanf("%s %s", &m2, &d2)

        if m1 != m2 {
                fmt.Println("1")
        } else {
                fmt.Println("0")
        }
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,b,a) for(int i=b;i>=a;i--)
#define fori(a) for(auto i : a )
#define all(a) begin(a), end(a)
#define set(a,b) memset(a,b,sizeof(a))
#define sz(a) a.size()
#define pi 3.14159
#define ll long long
#define ull unsigned long long
#define pb push_back
#define PF push_front //deque
#define mp make_pair
#define pq priority_queue
#define mod 1000000007
#define f first
#define s second
#define pii pair< int, int >
#define vi vector<int>
#define vpii vector<pii>
#define debug(v) for(auto i:v) cout<<i<<" ";
#define tc int t; cin >> t; while(t--)

using namespace std;
string repeat(string s, int n) {
    string s1 = "";
    for (int i=0; i<n;i++)
        s1+=s;
    return s1;
}
string getString(char x) {
    string s(1, x);
    return s;
}

void optimizeIO(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
}
int gcd(int a, int b){
    if (a == 0)  return b;
    return gcd(b % a, a);
}
void  solve(){
	int n,c;
	cin>>n>>c;
	int d[c+1][c+1];
	rep(i,1,c+1) rep(j,1,c+1) cin>>d[i][j];

	int C[n+1][n+1];
	rep(i,1,n+1) rep(j,1,n+1) cin>>C[i][j];
	map<int,vector<int>> m1;
	rep(i,1,n+1) rep(j,1,n+1) m1[(i+j)%3].push_back(C[i][j]);
	vector<pair<int,int>> v1,v2,v3;
	rep(f,1,c+1){
			int sum=0;
			for(auto i:m1[0]){
				sum+= d[i][f];
			}
			v1.push_back({sum,f});
	}
	rep(f,1,c+1){
			int sum=0;
			for(auto i:m1[1]){
				sum+= d[i][f];
			}
			v2.push_back({sum,f});
	}
	rep(f,1,c+1){
			int sum=0;
			for(auto i:m1[2]){
				sum+= d[i][f];
			}
			v3.push_back({sum,f});
	}
	sort(all(v1));
	sort(all(v2));
	sort(all(v3));
	int ans=INT_MAX;
	rep(i,0,3){
		rep(j,0,3){
			rep(k,0,3){
				if(v1[i].s!=v2[j].s && v1[i].s!=v3[k].s && v3[k].s!=v2[j].s) ans=min(ans,v1[i].f+v2[j].f+v3[k].f);
			}
		}
	}
	cout<<ans<<endl;
}
int main(){
    optimizeIO();
    // tc
    { solve();
    }
}


Measured memory_bytes: 5336
use std::io::*;
use std::str::FromStr;
use utils::*;

pub fn main() {
    let i = stdin();
    let mut o = Vec::new();
    run(i.lock(), &mut o);
    stdout().write_all(&o).unwrap();
}

fn run<R: BufRead, W: Write>(i: R, o: &mut W) {
    let mut i = CpReader::new(i);
    let n = i.read::<usize>();
    let a = i.read_vec::<usize>(n);
    writeln!(o, "{}", solve(&a)).unwrap();
}
fn solve(a: &[usize]) -> usize {
    let mut previous = 0;
    let mut same = 0;
    let mut result = 0;
    for &a in a {
        if a == previous {
            same += 1;
        } else {
            result += same / 2;
            same = 1;
        }
        previous = a;
    }
    result += same / 2;
    result
}

mod utils {
    use super::*;

    pub struct CpReader<R: BufRead> {
        r: R,
        s: String,
    }

    impl<R: BufRead> CpReader<R> {
        pub fn new(r: R) -> Self {
            CpReader {
                r: r,
                s: String::new(),
            }
        }
        pub fn read_line(&mut self) -> &str {
            self.s.clear();
            self.r.read_line(&mut self.s).unwrap();
            self.s.trim()
        }

        pub fn read<T: FromStr>(&mut self) -> T {
            self.read_line().parse().ok().unwrap()
        }

        pub fn read_vec<T: FromStr>(&mut self, n: usize) -> Vec<T> {
            self.read_line()
                .split(' ')
                .take(n)
                .map(|x| x.parse().ok().unwrap())
                .collect()
        }
    }

}


Measured memory_bytes: 4352
n = int(input())
txy = [list(map(int, input().split())) for _ in range(n)]

tmp = [0, 0, 0]
for t, x, y in txy:
    tmp1 = t - tmp[0]
    tmp2 = abs(x - tmp[1]) + abs(y - tmp[2])
    if tmp1 >= tmp2 and (tmp1 + tmp2) % 2 == 0:
        tmp = [t, x, y]
    else:
        print("No")
        exit()
print("Yes")

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

typedef long long int LLI;

#define MOD 1000000007

int n;
LLI as[1000000];
LLI cnt[1000000];

LLI pow(LLI base, LLI exp) {
  if (exp == 0) return 1;
  LLI res = pow(base*base%MOD, exp/2);
  if (exp%2) res = res*base%MOD;
  return res;
}

int main() {
  scanf("%d", &n);
  for (int i=0; i<n; i++) {
    scanf("%lld", &as[i]);
    cnt[as[i]]++;
  }

  if (n%2 == 1) {
    if (cnt[0] != 1) {
      puts("0");
      return 0;
    }

    for (int i=2; i<n; i+=2) {
      if (cnt[i] != 2) {
        puts("0");
        return 0;
      }
    }

    printf("%lld\n", pow(2, n/2));
  } else {
    for (int i=1; i<n; i+=2) {
      if (cnt[i] != 2) {
        puts("0");
        return 0;
      }
    }

    printf("%lld\n", pow(2, n/2));
  }
}


Measured memory_bytes: 1792
#ifdef _WIN32
#include "stdc++.h"
#else
#include <bits/stdc++.h>
#endif

// 継承可能な型
template <class Type>
struct IN : Type
{
	IN()
	{
		std::cin >> *this;
	}
};

// 継承不可能な型
template <class Type>
struct IN_
{
	Type val;

	IN_()
	{
		std::cin >> val;
	}

	operator Type&()
	{
		return val;
	}

	IN_<Type>& operator=(const Type& _value)
	{
		val = _value;
		return *this;
	}
};

template <class Char, class Type>
std::basic_ostream<Char>& operator <<(std::basic_ostream<Char>& os, const IN_<Type>& value)
{
	return os << value.val;
}

template <class Char, class Type>
std::basic_istream<Char>& operator >>(std::basic_istream<Char>& is, IN_<Type>& value)
{
	return is >> value.val;
}

template <class Type>
void OUT(const Type& value)
{
	std::cout << value << std::endl;
}

template <class Type, class ... Args>
void OUT(const Type& value, const Args& ... args)
{
	std::cout << value << ' ';
	OUT(args...);
}

void Yes()
{
	OUT("Yes");
}
void No()
{
	OUT("No");
}

using ll = long long;
using inll = IN_<ll>;
using vll = std::vector<ll>;
using setll = std::set<ll>;
using msetll = std::multiset<ll>;
using instr = IN<std::string>;

#define FOR(i, m, n) for (ll (i) = (m); (i) < (n); ++(i))
#define REP(i, n) for (ll (i) = 0; (i) < (n); ++(i))
#define REPR(i, n) for (ll (i) = (n); (i) >= 0; --(i))
#define ITRREP(it, v) for (auto (it) = (v).begin(); (it) != (v).end(); ++(it))
#define ITRREPR(it, v) for (auto (it) = (v).rbegin(); (it) != (v).rend(); ++(it))
#define DIVUP(a, b) (((a) + (b) - 1) / (b))

void Main();

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

	Main();

#ifdef _DEBUG
	system("pause");
#endif

	return 0;
}

using namespace std;

//////////////////////////////

void Main()
{
	inll h, w, d;

	vector<pair<ll, ll>> m;
	m.resize(h * w);

	REP(i, h)
	{
		REP(j, w)
		{
			inll a_;
			m[a_ - 1] = { i, j };
		}
	}

	vll costs;
	costs.resize(h * w);
	REPR(i, h * w - 1)
	{
		if (i + d < m.size())
			costs[i] = abs(m[i].first - m[i + d].first) + abs(m[i].second - m[i + d].second) + costs[i + d];
		else
			costs[i] = 0;
	}

	inll q;

	vll l, r;
	REP(i, q)
	{
		ll p = 0;

		inll l_, r_;
		l_--; r_--;

		ll x = l_;

		p += costs[x] - costs[r_];

		OUT(p);
	}
}


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

using ll = long long;
using ull = unsigned long long;
using st = string;
using db = double;
using vll = vector<long long>;
using vvll = vector<vll>;
using vchar = vector<char>;
#define rep(i, m, n) for (int i = (int)(m); i < (int)(n); i++)
#define all(v) v.begin(), v.end()
const ll mod = 1000000007;

int main(){
  st s;
  cin >> s;
  if(s.at(2) == s.at(3) && s.at(4) == s.at(5)) cout << "Yes" << endl;
  else cout << "No" << endl;
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-
import sys
import math
import os
import itertools
import _collections
import string

class cin():
    def int():
        return int(sys.stdin.readline().rstrip())
    def string():
        return sys.stdin.readline().rstrip()
    def mapInt():
        return [int(x) for x in cin.string().split()]
    def stringList(n):
        return [input() for i in range(n)]
    def intListList(n):
        return [cin.mapInt() for i in range(n)]
    def intColsList(n):
        return [int(input()) for i in range(n)]

class Util():
    def roundUp(a,b):
        return -(-a // b)
    def toUpperMultiple(a,x):
        return Util.round_up(a,x) * x
    def toLowerMultiple(a,x):
        return (a // x) * x
class Math():
    def gcd(a,b):
        if b == 0:
            return a
        return Math.gcd(b,a % b)

def main():
    N,Q = cin.mapInt()
    S = cin.string()
    A = cin.intListList(Q)
    sums = [0] * N 
    for i in range(1,N):
        sums[i] = sums[i - 1]
        if S[i] == "C" and S[i - 1] == "A":
            sums[i] +=1
    for q in A:
        print(sums[q[1] - 1] - sums[q[0] - 1])
    return

if __name__ == "__main__":
    main()


Measured memory_bytes: 64860
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<stdint.h>
#include<malloc.h>
#include<math.h>
#include<x86intrin.h>


int my_gets(char *buf,int nBuf,FILE *fp){
    int ch;

    while(--nBuf >0){
        ch=getc(fp);
        if(ch==EOF || ch=='\n')
            break;
        *(buf++)=(char)ch;
    }
    *(buf)='\0';

    return nBuf;
}

void InputIntAry(int *a,int nDigit,int N){      //nDigitは想定される最大桁数
    char *buf,*ptr;

    buf=(char*)malloc( (N*(nDigit+2)) * sizeof(char) );
    my_gets(buf,N*(nDigit+2),stdin);

    ptr=strtok(buf," ");
    while(ptr!=NULL && N-->0){
        *(a++)=atoi(ptr);
        ptr=strtok(NULL," ");
    }
    free(buf);
}

int CmpInt(const void *a, const void *b){        //b-aを返す(qsortなら4321)
    return *((int*)b)- *((int*)a);
}

#define MIN(a,b)  ( ((a)>(b))?(b):(a) )

int main(){
    int N;
    int B[100],sum=0;

    scanf("%d%*c",&N);
    InputIntAry(B,10,N-1);
    sum += B[0];
    for(int i=1;i<N-1;i++){
        sum += MIN(B[i],B[i-1]);
    }
    sum += B[N-2];

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

    return 0;
} 

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REP1(i,n) for(int i = 1; i < n+1 ;i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
#define ARRAY_LENGTH(array) (sizeof(array) / sizeof(array[0]))
using namespace std;
typedef long long ll;

int main(){
    vector<vector<int>> a(3,vector<int>(3));
    REP(i,3){
        REP(j,3){
            cin >> a[i][j];
        }
    }
    int n;
    cin>>n;
    vector<int>b(n);
    REP(i,n) cin >> b[i];
    vector<vector<bool>> c(3,vector<bool>(3));
    REP(i,3){REP(j,3){c[i][j]=false;}}//初期化
    REP(h,n){
        REP(i,3){
            REP(j,3){
                
                if (b[h]==a[i][j]){
                    c[i][j]=true;
                }
             }
        }
    }
    REP(i,3){
        if(c[i][0] and c[i][1] and c[i][2]) {
            cout << "Yes"<<endl; return 0;;
        }
        else if(c[0][i] and c[1][i] and c[2][i]){
             cout << "Yes"<<endl; return 0;;
        }
        else if(c[0][0] and c[1][1] and c[2][2]){
             cout << "Yes"<<endl; return 0;
        }
        else if(c[0][2] and c[1][1] and c[2][0]){
             cout << "Yes"<<endl; return 0;
        }


    }
    cout << "No" << endl;
    return 0;







}

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

#define rep(i, n) for(int i = 0; i < n; ++i)
#define all(a) a.begin(), a.end()
#define ll long long

using namespace std;

constexpr ll mod = 1e9+7;

int main()
{
  ll n;
  cin >> n;
  map<ll, ll> cnt;

  rep(i, n) {
    ll key;
    cin >> key;
    ++cnt[key];
  }

  if (n % 2 && cnt[0] != 1) {
    cout << 0 << endl;
    return 0;
  }

  for(ll i = n % 2 + 1; i < n; i += 2) {
    if (cnt[i] != 2) {
      cout << 0 << endl;
      return 0;
    }
  }

  ll ans = 1;
  rep(i, n / 2) {
    ans = (ans * 2) % mod;
  }

  cout << ans << endl;
}


Measured memory_bytes: 4224
#include <iostream>

using namespace std;

int main() {

	int W = 0;
	int H = 0;
	int x = 0;
	int y = 0;
	int r = 0;

	cin >> W >> H >> x >> y >> r;

	if (((x - r >= 0) && (y - r >= 0)) && ((x + r <= W) && (y + r <= H))) {

		cout << "Yes" << endl;

	}
	else {

		cout << "No" << endl;

	}

	return 0;

}

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

int main(){
  int n,m,x;
  cin>>n>>m>>x;
  vector<int> data(m);
  for (int i=0;i<m;i++){
    cin>>data.at(i);
  }
  
  int answer=0;
  
  for (int i=0;i<m;i++){
    if (data.at(i)<x){
      answer+=1;
    }
    else {
      break;
    }
  }
    
    answer=min(answer,m-answer);
    cout<<answer<<endl;
    
    
  
}

  













Measured memory_bytes: 256
/*
 *
 *   Author     : Amit Kumar
 *   Date    	: June 2 2019
 * 
 */

#include <bits/stdc++.h>

//#define FAST_INPUT_OUTPUT
//#define MORE_THAN_ONE_TESTCASE // COMMENT IT

#define vi vector<int>
#define vl vector<long long>
#define mii map<int , int>
#define mll map<long long , long long>
#define msi map<string , i>
#define msl map<string , long long>
#define umii unordered_map<int,int>
#define umll unordered_map<long long ,long long>
#define umsi unordered_map<string , int>
#define umsl map<string , long long> 
#define si set<int>
#define sl set<long long>
#define pii pair<int , int >
#define psi pair<string,int>
#define psl pair<string , long > 
#define pll pair<long long , long long>
#define vpii vector<pii>
#define vpll vector<pll>
#define vpsi vector<psi>
#define vpsl vector<psl>
#define pqi priority_queue<int>
#define pql priority_queue<long long>
#define ub upper_bound
#define lb lower_bound
#define bint long long int
#define ff first
#define ss second
#define all(x) x.begin(),x.end()
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define iv(v) for(auto &i:v){cin>>i;}
#define ov(v) for(auto i:v){cout<<i<<" ";}cout<<endl;
#define ovn(v) for(auto i:v){cout<<i<<endl;}
#define euv(v) for(auto i:v){cerr<<i<<" ";}cerr<<endl;
#define eovn(v) for(auto i:v){cerr<<i<<endl;}
#define os(s) for(auto itr:s){cout<<itr<<" ";}cout<<endl;
#define osn(s) for(auto itr:s){cout<<itr<<endl;}
#define eos(s) for(auto itr:s){cerr<<itr<<" ";}cerr<<endl;
#define eosn(s) for(auto itr:s){cerr<<itr<<endl;}
#define rep(x) for(auto i=0 ; i<(x); ++i)
#define _rep(a,b) for(auto i=(a); i<(b); ++i)
#define endl '\n'
using namespace std;
class edge{
    public:
        int end;
        int weight;
};


void dfs(int start , bint cost , vector<vector<edge>>&tree , vl &visited){
    if(visited[start]!=-1){
        return ;
    }
    visited[start] = cost;
    for(edge e:tree[start]){
        dfs(e.end , cost+e.weight , tree , visited);
    }
    return ;
}

auto SOLUTION_FUNCTION( void ) ->void {

    // your solution goes here 


    int n ;

    cin>>n;

    vector<vector<edge>> tree(n+1);
    for(int i=0; i<n-1; ++i){
        int v , u , w;

        cin>>u>>v>>w;
        edge e;
        e.end=v;
        e.weight = w;

        tree[u].pb(e);

        e.end =u; 
        tree[v].pb(e);
    }

    vl visited(n+1);
    for(int i=0; i<visited.size(); ++i){
        visited[i] = -1;
    }

    dfs(1 , 0 , tree , visited);

    for(int i=1; i<=n;  ++i){
        if(visited[i]&1){
            cout<<1<<endl;
        }else{
            cout<<0<<endl;
        }
    }



    return ;
}




int main(void){
#ifdef FAST_INPUT_OUTPUT
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    cout<<setprecision(10);
    cout<<fixed;
    cout<<boolalpha;
#endif
#ifdef MY_LOCAL_PROJECT
    freopen("din","r",stdin);
    freopen("dout","w",stdout);
#endif
    int testcase = 1;


#ifdef MORE_THAN_ONE_TESTCASE
    cin>>testcase;
#endif
    
    while(testcase--){
        SOLUTION_FUNCTION();
    }

#ifdef MY_LOCAL_PROJECT
    cout<<"Time : "<<1.0*(double)clock()/CLOCKS_PER_SEC<<endl;
#endif
    return 0;
}


Measured memory_bytes: 8576
n = int(input())
re = [list(input().split(' ')) for i in range(n)]
def b2y(btc):
  return float(btc) * 380000
ans = 0
for x, u in re:
  if u == 'JPY':
    ans += float(x)
  else:
    ans += b2y(x)
print(ans)

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

int T[251];

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

    int n;

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

    for (int i = 1; i <= n; i++)
    {
        cout << "node " << i << ": key = ";
        cout << T[i];
        if (i / 2 >= 1)
        {
            cout << ", parent key = " << T[i / 2];
        }
        if (i * 2 <= n)
        {
            cout << ", left key = " << T[i * 2];
        }
        if (i * 2 + 1 <= n)
        {
            cout << ", right key = " << T[i * 2 + 1];
        }
        cout << ", " << endl;
    }

    return 0;
}


Measured memory_bytes: 3108
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;++i)
#define rrep(i,n) for(int i=n-1;i>=0;--i)
#define REP(i,a,b) for(int i=a;i<b;i++)
#define yesno(flg) if(flg){cout<<'YES'<<endl;}else{cout<<'NO'<<endl;}
#define vi vector<int>
#define pb push_back
#define i197 1000000007
#define MAX_N 200002
using namespace std;

typedef long long ll;
typedef pair<int,int> Pii;
typedef pair<Pii,int> Piii;
typedef pair<int,ll> Pil;
typedef pair<ll,ll> Pll;
typedef pair<string,int> Psi;
typedef pair<Psi,int> Psii;

const int inf=1000000000;
struct edge{
	int myc,to,c,cost;
};
struct pos{
	int to,cost,color;
};
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};

vi vec[200001];
int x[200001]={};
int dp[200001];
int main() {
	int n,a,b;
	cin>>n;
	cin>>a;
	int r=0;
	int res=0;
	rep(i,n-1){
		cin>>b;
		if(a<b){
			r=0;
		}else{
			r++;
			res=max(r,res);
		}
		a=b;
	}
	cout<<res<<endl;	
	return 0;
}


Measured memory_bytes: 4992
def compute():
    a, b, c = [int(el) for el in input().split(' ')]
    count = 0
    while a % 2 == b % 2 == c % 2 == 0:
        a, b, c = (b+c)//2, (a+c)//2, (a+b)//2
        count += 1
        if a == b == c:
            print(-1)
            return
    print(count)
    return

compute()


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

#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;

int main() {
	cin.tie(0)->sync_with_stdio(0);
	cin.exceptions(cin.failbit);

	int n, y; cin >> n >> y;
	rep(i, 0, n + 1) rep(j, 0, n + 1 - i) {
		int k = n - i - j;
		if (i * 10000 + j * 5000 + k * 1000 == y) {
			cout << i << " " << j << " " << k << endl;
			return 0;
		}
	}
	cout << "-1 -1 -1" << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<set>
#include<map>
#include<queue>
#include<math.h>
#define REP(i,a) for (int i = 0;i < (a);++i)
#define FOR(i,a,b) for (int i = (a);i < (b); ++i)
#define FORR(i,a,b) for (int i = (a);i >= (b); --i)
#define ALL(obj) (obj).begin(),(obj).end()
#define SORT(list) sort(ALL((list)));
#define MOD 1000000007
using namespace std;
using ll = long long;
int main(){
    ll n;
    cin >> n;
    vector<ll> x(n),y(n),v(n);
    ll fact=1;
    double total = 0;
    REP(i,n){
        cin >> x[i] >> y[i];
        v[i] = i;
        fact*=i+1;
    }

    do{
        REP(i,n-1){
            double dist = sqrt((x[v[i]]-x[v[i+1]])*(x[v[i]]-x[v[i+1]]) + (y[v[i]]-y[v[i+1]])*(y[v[i]]-y[v[i+1]]));
            total += dist;
            //printf("%.12f\n",dist);
        }
    }while(next_permutation(ALL(v)));

    printf("%.12f\n",total/fact);
    return 0;
}

Measured memory_bytes: 256
n, m = (int(x) for x in input().split())
A = sorted([int(x) for x in input().split()])[::-1]
cost = (0, 2, 5, 5, 4, 5, 6, 3, 7, 6)
dp = [[-1] * (n+1) for _ in range(m+1)]
for i in range(m+1):
  dp[i][0] = 0
for i in range(m):
  for j in range(1, n+1):
    dp[i+1][j] = max(dp[i+1][j], dp[i][j])
    if j >= cost[A[i]]:
      if dp[i+1][j-cost[A[i]]] == -1:
        dp[i+1][j] = max(dp[i+1][j], dp[i][j])
      else:
        dp[i+1][j] = max(dp[i+1][j], 10 * dp[i+1][j-cost[A[i]]] + A[i])
print(dp[m][n])

Measured memory_bytes: 31968
#include<iostream>

using namespace std;

struct numTuple
{
	int _x;
	int _y;
	void convert() {
		if (_x > _y) {
			int temp = _x;
			_x = _y;
			_y = temp;
		}
	}

	void input(int xInput,int yInput) {
		_x = xInput;
		_y = yInput;
	}

	void printTuple() {
		cout << _x << ' ' << _y << endl;
	}
};

int main() {
	int x=-1, y=-1;
	numTuple num;

	while ((cin >> x >> y) && !(x == 0 && y == 0)) {
		num.input(x,y);
		num.convert();
		num.printTuple();
	}

	//system("pause");
	return 0;
}

Measured memory_bytes: 3072
<?php

$target = trim(fgets(STDIN));
$search = trim(fgets(STDIN));

for ($i = 0; $i < strlen($target) - strlen($search) + 1; $i++) { 
	$sub = substr($target, $i, strlen($search));
	if($sub == $search){
		echo "$i\n";
	}
}

?>


Measured memory_bytes: 9208
# -*- coding: utf-8 -*-
a, b, c, x, y = map(int, input().split())

total = a * x + b * y
if a + b > 2 * c:
  total = 2 * c * min(x, y)
  if x > y:
    total += (x - y) * min(a, 2 * c)
  elif y > x:
    total += (y - x) * min(b, 2 * c)
print(total)


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

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

    sort(A, A+N);
    int ans = 0;
    int i = 0;
    while(i < N){
        int PreviousValue = A[i];
        int DuplicateCount = 0;
        while( i < N && PreviousValue == A[i]){
            DuplicateCount++;
            i++;
        }
        ans += DuplicateCount % 2;
    }
    cout << ans << endl;


    return 0;
}

Measured memory_bytes: 640
n = int(input())
A = list(map(int,input().split()))
a = A[0]
b = A[1]
x = 0
for i in A[2:]:
    x ^= i
 
d = {}
def F(a,b,xor):
    if (a,b,xor) in d:
        return d[(a,b,xor)]
    if a&1 ^ b&1 != xor&1:
        return float("INF")
    if xor == 0:
        if a<b:
            return float("INF")
        else:
            return (a-b)//2
    c1 = 2*F(a//2,b//2,xor//2)
    c2 = 2*F((a-1)//2,(b+1)//2,xor//2) + 1
    f = min(c1,c2)
    d[(a,b,xor)] = f
    return f
 
ans = F(a,b,x)
if ans >= a:
    print(-1)
else:
    print(ans)

Measured memory_bytes: 9196
// {{{
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <queue>
#include <deque>
#include <bitset>
#include <iterator>
#include <list>
#include <stack>
#include <map>
#include <set>
#include <functional>
#include <numeric>
#include <utility>
#include <limits>
#include <time.h>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <assert.h>

using namespace std;

typedef long int i32;
typedef unsigned long int u32;
typedef long long int i64;
typedef unsigned long long int  u64;
typedef pair<i32, i32> PII;
typedef vector<i32> VI;
typedef vector<string> VS;
typedef vector<PII> VII;
typedef vector<VI> VVI;
typedef map<i32, i32> MPII;
typedef set<i32> SETI;
typedef multiset<i32> MSETI;
#define IN(x) cin >> x;
#define SCD(t) scanf("%d",&t)
#define SCLD(t) scanf("%ld",&t)
#define SCLLD(t) scanf("%lld",&t)
#define SCC(t) scanf("%c",&t)
#define SCS(t) scanf("%s",t)
#define SCF(t) scanf("%f",&t)
#define SCLF(t) scanf("%lf",&t)
#define MEM(a, b) memset(a, (b), sizeof(a))
#define ZERO(a) memset(a, 0, sizeof(a))
#define FOR(i, j, k, in) for (int i=j ; i<k ; i+=in)
#define RFOR(i, j, k, in) for (int i=j ; i>=k ; i-=in)
#define REP(i, j) FOR(i, 0, j, 1)
#define RREP(i, j) RFOR(i, j, 0, 1)
#define all(cont) cont.begin(), cont.end()
#define rall(cont) cont.end(), cont.begin()
#define FOREACH(it, l) for (auto it = l.begin(); it != l.end(); it++)
#define BTW(A, B, C) assert( B <= A && A <= C)
#define MP make_pair
#define PB push_back
#define PF push_front
#define INF (int)1e9
#define EPS 1e-9
#define PI 3.1415926535897932384626433832795
#define MOD 1000000007
#define DEBUG(x) cout << #x << ": " << x << endl;

template<typename T, typename U> inline void amin(T &x, U y) { if(y < x) x = y; }
template<typename T, typename U> inline void amax(T &x, U y) { if(x < y) x = y; }
// }}}

const u64 MAX_N = 100000;
u64 a[MAX_N], b[MAX_N], c[MAX_N];
u64 d[MAX_N];
vector<pair<u64, u64>> e[MAX_N];
int main() {
    u64 N, Q, K;
    IN(N);
    REP(i,N-1){
        scanf("%d %d %d", a+i, b+i, c+i);
        e[a[i]-1].push_back(MP(b[i]-1, c[i]));
        e[b[i]-1].push_back(MP(a[i]-1, c[i]));
    }
    REP(i, N) {
        d[i] = (u64)-1;
    }
    IN(Q);IN(K);
    d[K-1] = 0;
    auto q = priority_queue<pair<u64, u64>>();
    q.push(MP(0, K-1));
    while(!q.empty()) {
        auto vx = q.top();
        u64 v = vx.first;
        u64 x = vx.second;
        q.pop();
        for(const auto& yv : e[x]) {
            u64 y = yv.first;
            u64 _v = yv.second;
            if(d[y] > _v + v) {
                d[y] = _v + v;
                q.push(MP(d[y], y));
            }
        }
    }
    REP(i, Q) {
        int x, y;
        cin >> x >> y;
        cout << d[x-1] + d[y-1] << endl;
    }
    return 0;
}



Measured memory_bytes: 13424
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
const long long INF = numeric_limits<long long>::max();
typedef long long ll;
int main()
{
    string s;
    int q;
    cin >> s >> q;
    int cmd;
    int reverse_cnt = 0;
    vector<pair<string, int>> memo;
    int cnt = 0;
    rep(i,q){
        cin >> cmd;
        if (cmd == 1) reverse_cnt++;
        else{
            int f;
            string c;
            cin >> f >> c;
            if (f==1) memo.push_back(make_pair(c,reverse_cnt));
            else memo.push_back(make_pair(c,reverse_cnt - 1));
            cnt++;
        }
    }
    if (reverse_cnt % 2 != 0) reverse(s.begin(), s.end());
    for (int i = 0; i < memo.size(); i++){
        if ( (reverse_cnt-memo[i].second) % 2 == 0) s.insert(0,memo[i].first);
        else s.append(memo[i].first); 
    }
    cout << s << endl;
    return 0;
}

Measured memory_bytes: 15600
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define FOR(i,n,m) for(int i=(n);i<(m);i++)
#define REP(i,n) for(int i=0;i<(n);i++)
#define REPR(i,n) for(int 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;}
template<typename A,typename B>istream&operator>>(istream&is,pair<A,B> &p){is>>p.fi>>p.se;return is;}
template<typename A,typename B>ostream&operator<<(ostream&os,const pair<A,B> &p){os<<"("<<p.fi<<","<<p.se<<")";return os;}
template<typename T>istream&operator>>(istream&is,vector<T> &t){REP(i,t.size())is>>t[i];return is;}
template<typename T>ostream&operator<<(ostream&os,const vector<T>&t){os<<"{";REP(i,t.size()){if(i)os<<",";os<<t[i];}cout<<"}";return os;}
const ll MOD=1000000007LL;
const int INF=1<<30;
const ll LINF=1LL<<60;
template<int mod>
struct ModInt{
    int x;
    ModInt():x(0){}
    ModInt(long long y):x(y>=0?y%mod:(mod-(-y)%mod)%mod){}
    ModInt &operator+=(const ModInt &p){
        if((x+=p.x)>=mod)x-=mod;
        return *this;
    }
    ModInt &operator-=(const ModInt &p){
        if((x+=mod-p.x)>=mod)x-=mod;
        return *this;
    }
    ModInt &operator*=(const ModInt &p){
        x=(int)(1LL*x*p.x%mod);
        return *this;
    }
    ModInt &operator/=(const ModInt &p){
        *this*=p.inverse();
        return *this;
    }
    ModInt operator-()const{return ModInt(-x);}
    ModInt operator+(const ModInt &p)const{return ModInt(*this)+=p;}
    ModInt operator-(const ModInt &p)const{return ModInt(*this)-=p;}
    ModInt operator*(const ModInt &p)const{return ModInt(*this)*=p;}
    ModInt operator/(const ModInt &p)const{return ModInt(*this)/=p;}
    bool operator==(const ModInt &p)const{return x==p.x;}
    bool operator!=(const ModInt &p)const{return x!=p.x;}
    ModInt inverse()const{
        int a=x,b=mod,u=1,v=0,t;
        while(b>0){
            t=a/b;
            a-=t*b;
            swap(a,b);
            u-=t*v;
            swap(u,v);
        }
        return ModInt(u);
    }
    friend ostream &operator<<(ostream &os,const ModInt<mod> &p){
        return os<<p.x;
    }
    friend istream &operator>>(istream &is,ModInt<mod> &a){
        long long x;
        is>>x;
        a=ModInt<mod>(x);
        return (is);
    }
};

const int mod=1e9+7;
using mint=ModInt<mod>;
int main(){
    int n,m;
    cin>>n>>m;
    vi vec(n);
    cin>>vec;
    mint t=0;
    map<int,mint> ma;
    REP(i,n){
        ma[vec[i]]=ma[vec[i]]+1;
        REP(j,i){
            if(vec[j]>vec[i]){
                t=t+1;
            }
        }
    }
    mint ans=t*m;
    mint sum=n;
    for(auto itr:ma){
        sum-=itr.se;
        ans+=sum*m*(m-1)/2*itr.se;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cstring>
#include <string>
#include <cmath>
#include <cstdio>
#include <vector>

using namespace std;

int main()
{
    int a,b;
    cin>>a>>b;
    if (b<a) cout<<a-1;
    else cout<<a;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(ll i=0;i<n;i++)
#define cY cout << "Yes" << endl;
#define cN cout << "No" << endl;
int fac(int n){
  int x = 1;
  for(int i=1;i<=n;i++) x *= i;
  return x;
}

int main() {
  ll n;
  cin >> n;
  vector<ll>p(n);
  rep(i,n) cin >> p.at(i);
  vector<ll>q(n);
  rep(i,n) cin >> q.at(i);
  vector<ll>a(n);
  rep(i,n) a.at(i) = i+1;
  ll P,Q=0;
  int i = 1;
  do{
    if(p == a) P=i;
    if(q == a) Q=i;
    ++i;
  } while(next_permutation(a.begin(),a.end()));
  cout << abs(P-Q) << endl;
    
  return 0;
}


Measured memory_bytes: 256
N ,M = input().split()
X = list(map(int, input().split()))
ans = 0
if int(N) >= int(M):
    print(ans)
else:
    X.sort()
    #print(X)
    div = []
    for i in range(int(M)-1):
        #print(i)
        div.append(abs(X[i + 1] - X[i]))
    div.sort()
    #print(div)
    for i in range(int(N)-1):
        div.pop()
    #print(div)
    for i in div:
        ans += i
    print(ans)  


Measured memory_bytes: 13964
import java.util.Scanner;

public class Main {
    static int a[] = new int[110];
    static int b[] = new int[110];
    public static void main(String args[]){
        Scanner cin = new Scanner(System.in);
        int n = cin.nextInt();
        for(int i = 1; i <= n; i++) a[i] = cin.nextInt();
        int res = 0;
        for(int i = 1; i <= n; i++){
            b[i] = cin.nextInt();
            if(a[i] - b[i] > 0) res += a[i] - b[i];
        }
        System.out.println(res);
    }

}

Measured memory_bytes: 23252
package main

import "fmt"

func main() {
	var s string
	fmt.Scan(&s)
	m := map[string]int{"SUN": 1, "MON": 2, "TUE": 3, "WED": 4, "THU": 5, "FRI": 6, "SAT": 7}
	fmt.Println(8 - m[s])
}


Measured memory_bytes: 512