akhauriyash/Code-Regression huggingface dataset:
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.*;
 
public class Main {
    public static void main(String[] args) throws Exception {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        PrintWriter out = new PrintWriter(System.out);
        int N = Integer.parseInt(br.readLine());
        List<List<Long>> list = new ArrayList<>();
        long ans = 0;
        for (int i = 0; i < N; i++) {
            String[] arr =  br.readLine().split(" ");
            list.add(Arrays.asList(
                Long.parseLong(arr[0]),
                Long.parseLong(arr[1]),
                Long.parseLong(arr[0]) + Long.parseLong(arr[1])
            ));
        }
        list.sort((a, b) -> {
                if (a.get(2) - b.get(2) != 0) {
                    return b.get(2) - a.get(2) > 0 ? 1 : -1;
                } else {
                    return b.get(0) - a.get(0) > 0 ? 1 : -1;
                }
            }
        );
        for (int i = 0; i < N; i++) {
            if (i % 2 == 0) {
                ans += list.get(i).get(0); 
            } else {
                ans -= list.get(i).get(1);
            }
        }
        out.println(ans);
        out.close();
    }
}

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

using namespace std;

vector<int> dp(1e5+1, 1e9+9);

int main(){
    //freopen("i.in", "r", stdin);
    int n; cin>>n;
    vector<int> h(n);
    rep(i, 0, n) cin>>h[i];
    dp[0]=0;
    rep(i, 0, n){
        //cout<<dp[i]<<" "<<h[i]<<" "<<h[i+1]<<"\n";
        dp[i+1] = min(dp[i+1], dp[i]+abs(h[i]-h[i+1]));
        dp[i+2] = min(dp[i+2], dp[i]+abs(h[i]-h[i+2]));
    }
    cout<<dp[n-1];
}

Measured memory_bytes: 1024
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#define ll long long
#define rep(i,n) for(ll i=0;i<(n);i++)
#define max(p,q) ((p)>(q)?(p):(q))
#define min(p,q) ((p)<(q)?(p):(q))
#define chmax(a,b) ((a)=(a)>(b)?(a):(b))
#define chmin(a,b) ((a)=(a)<(b)?(a):(b))
#define abs(p) ((p)>=(0)?(p):(-(p)))
#define MOD 1000000007
ll powll(ll a,ll b){ll r=1;rep(i,b){r*=a;}return r;}
#define swap(a,b) do{ll w=(a);(a)=(b);(b)=w;}while(0)
#define swapd(a,b) do{double w=(a);(a)=(b);(b)=w}while(0)
#define in(a) scanf("%lld", &(a))
#define in2(a,b) scanf("%lld %lld",&(a),&(b))
#define in3(a,b,c) scanf("%lld %lld %lld",&(a),&(b),&(c))
#define ind(a) scanf("%lf", &(a))
#define ins(a) scanf("%s", (a))
#define inc(a) scanf("%c", &(a))
#define put(a) printf("%lld\n", (a))
#define putd(a) printf("%.15f\n", (a))
//      puts(a) printf("%s\n", a) 文字はこっち
//your code here!
int main(void){
    ll H, W;
    char C[105][105];
    in2(H, W);
    rep(i, H) ins(C+i);
    rep(i, H) rep(_, 2) puts(C[i]);
    return 0;
}


Measured memory_bytes: 128
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();
    int data[]={n+m,n-m,n*m};
    int max=n+m;

    for(int i=1;i<data.length;i++){
      // System.out.println(data[i]);
       max=Math.max(data[i],max);
    }
    System.out.println(max);

  }
}


Measured memory_bytes: 21844
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
#define N 100005
typedef pair<int, int> pii;
vector<pii> q;
int n;

bool comp (pii a, pii b) {
    
    return (a.first < b.first);
}


int main(int argc, const char * argv[]) {
    
    cin >> n;
    int i, now;
    for (i = 0; i < n; i++) {
        cin >> now;
        q.push_back(make_pair(now, i + 1));
    }
    sort(q.begin(), q.begin() + n, comp);
    for (i = 0; i < n; i++) {
        cout << q[i].second << ' ';
    }
    
    return 0;
}

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

using namespace std;

const int N = 2e5 + 5;

char s[N];

int main() {
  scanf("%s", s);
  int n = strlen(s);
  int b, w;
  long long ans = 0;
  b = w = 0;
  for (int i = 0; i < n; ++i) {
    if (s[i] == 'B')
      ++b;
    else
      ans += b;
  }
  printf("%lld\n", ans);
  return 0;
}

Measured memory_bytes: 384
#include<iostream>
#include<stdlib.h>
#include<stdio.h>
#include<bits/stdc++.h>
using namespace std;
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;
/*---------------------DEBUGGING--------------------------------------------*/
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif
/*-------------------------------------------------------------------------------------*/
//#define mp make_pair
#define pb push_back
#define ll long long
#define pii pair<int,int>
#define pcc pair<char,char>
#define F first
#define S second
#define int long long
#define pi 3.141592653589793238462643383279502
#define M  1000000007
#define rep(i,a,n) for(int i=a;i<n;i++)
#define INF 10000000000000
#define N 200005
#define vi vector<int>
#define all(v) v.begin(),v.end()
#define endl "\n"
//#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>

signed main()
{
   ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
   int x,k,d;
   cin>>x>>k>>d;
   x=abs(x);
   int rem=(x%d);
   int diff=(x-rem);
   int steps=(diff/d);
   //debug(steps,rem);
   if(steps>k)
   {
       cout<<(x-k*d)<<endl;
   }
   else
   {
       if(steps%2!=(k%2))
       {
           int ans=min(abs(rem-d),rem+d);
           cout<<ans<<endl;
       }
       else
        cout<<rem<<endl;
   }
}



Measured memory_bytes: 3672
#include<iostream>
#include<math.h>
#include<iomanip>
#include<vector>
#include<algorithm>
#include<queue>
#include<string>
#include<stdlib.h>
#include<stack>
using namespace std;
#define PI 3.14159265358979
typedef  long long ll;
#define rep(i,n) for(int i=0;i<n;i++)
#include<set>
long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

int main(void)
{
ll k;
cin>>k;

ll bfrmod = 0;

for(int i =0;i<=k;++i)
{
    ll now = 7*modpow(10,i,k);
    ll modnow = now%k;

    bfrmod = (modnow+bfrmod);
    bfrmod %=k;

    if(bfrmod==0) 
    {
        cout<<i+1<<endl;
        return 0;
    }



}
    cout<<-1<<endl;


}

Measured memory_bytes: 3196
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
#define REP(i,n) for (ll i = 0; i < (n); ++i)
#define RREP(i, n) for (ll i = n - 1; i >= 0; --i)


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

    const string colors = "RGB";
    map<char, int> c2i = {{'R', 0}, {'G', 1}, {'B', 2}};

    vector<vector<ll>> num(3, vector<ll>(n, 0));
    RREP(i, n){
        REP(c, 3){
            if(i + 1 < n){
                num.at(c).at(i) = num.at(c).at(i + 1);
            }
        }
        num.at(c2i.at(s.at(i))).at(i)++;
    }

    ll ans = 0;
    REP(i, n){
        for(ll j = i + 1; j < n; ++j){
            if(s.at(i) == s.at(j)){
                continue;
            }
            const ll delta = j - i;
            REP(c, 3){
                if(s.at(i) != colors.at(c) && s.at(j) != colors.at(c)){
                    ans += num.at(c).at(j);
                    if(j + delta < n && s.at(j + delta) == colors.at(c)){
                        ans--;
                    }
                    break;
                }
            }
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3684
#include <stdio.h>
int main(void){
int R;
  scanf("%d",&R);
  if(R<1200){
    printf("ABC");
  }
  else if(R>=1200&&R<2800){
  printf("ARC");
  }
  else if(R>=2800){
  printf("AGC");}
return 0;
}

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

int C[256];

bool check(int N, int ka, int kb, int kc) {
    bool ok = true;
    if (N - ka > 0) {
        ok = ok && (C['a'] == (N - ka + 3 - 1) / 3);
    }
    if (N - kb > 0) {
        ok = ok && (C['b'] == (N - kb + 3 - 1) / 3);
    }
    if (N - kc > 0) {
        ok = ok && (C['c'] == (N - kc + 3 - 1) / 3);
    }
    return ok;
}

int main() {
    string S;
    cin >> S;

    for (int i=0; i<S.size(); i++) {
        C[S.at(i)]++;
    }

    bool ok = check(S.size(), 0, 1, 2) ||
              check(S.size(), 0, 2, 1) ||
              check(S.size(), 1, 0, 2) ||
              check(S.size(), 2, 0, 1) ||
              check(S.size(), 1, 2, 0) ||
              check(S.size(), 2, 1, 0);

    cout << (ok ? "YES" : "NO") << endl;
    return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG //これつけるとA[N]でもいいらしい
//for文のマクロ
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define big 1000000007
#define all(a) sort((a).begin(),(a).end()) //ソートのマクロ
#define Re(a) reverse((a).begin(),(a).end())
int main(){
    int n;
    cin>>n;
    vector<int> a(n);
    int g=0;
    rep(i,n){
        cin>>a[i];
        if(a[i]%2==0){
            g++;
        }
    }
    int ans = pow(3,n);
    ans = ans - pow(2,g);
    cout<<ans<<endl;
}

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
#define REP(i, n) for(int i=0; i<n; i++)
#define REPi(i, a, b) for(int i=int(a); i<int(b); i++)
#define MEMS(a,b) memset(a,b,sizeof(a))
#define mp make_pair
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const ll MOD = 1e9+7;

#define MAX_N 1000100

//素因数分解 O(n**1/2)
map<ll, ll> prime_factor(ll n){
    map<ll, ll> res;
    for(ll i = 2; i * i <= n; i++){
        while(n % i == 0){
            ++res[i];
            n /= i;
        }
    }
    if(n != 1) res[n] = 1;
    return res;
}

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

    auto prime = prime_factor(N);

    ll ans = 0;
    for(auto&& p : prime){
        ll num = p.second;  
        ll x = 1;
        while(num >= x){
            ans++;
            num -= x;
            x++;
        }
    }

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


Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
typedef long long ll;
ll pow(ll x,ll y){
  ll ans = 1;
  while(y){
    if(y&1) ans = ans*x;
    x = x*x;
    y >>= 1;
  }
  return ans;
}
int main(){
  ll N,P,i;scanf("%lld%lld",&N,&P);
  if(N >= 40){
    printf("1\n");return 0;
  }
  else if(N == 1){
    printf("%lld\n",P);return 0;
  }
  ll ans = 1;
  for(i=2;pow(i,N)<=P;i++){
    if(P%pow(i,N) == 0) ans = i;
  }
  printf("%lld\n",ans);
}

Measured memory_bytes: 3760
//      https://youtu.be/X_hMZYDMps4

#include<bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef long double ld;
typedef long long unsigned llu;
typedef pair<long long, long long> pll;
const long long inf = 2000000000000000000LL;    // 2e18
#define pi                  acos(-1.0)
#define fast                ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define nl                  "\n"
#define ff                  first
#define ss                  second
#define pb                  push_back
#define pf                  push_front
#define all(x)              x.begin(),x.end()
#define debug(x)            cout<<"debug "<<x<<"\n"

int main()
{
    fast;
    ll t,i,j,k,l,m,n,o,p,q,temp,ans=0,flag=0,mod=1000000007,odd=0,even=0,a,b;
    cin>>n>>a>>b;
    if(a>b || (n==1 && a!=b)){
        cout<<"0";
        return 0;
    }
    temp=(((n-1)*b)+a)-(((n-1)*a)+b);
    cout<<max(0LL,temp+1);
}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
 
typedef long long LL;
typedef pair<int, int> PII;
typedef vector<int> VI;
#define MP make_pair
#define PB push_back
#define X first
#define Y second
 
#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
#define RFOR(i, b, a) for(int i = (b) - 1; i >= (a); --i)
#define ALL(a) a.begin(), a.end()
#define SZ(a) (int)((a).size())
#define FILL(a, value) memset(a, value, sizeof(a))
#define debug(a) cerr << #a << " = " << a << endl;
 
template<typename T> void setmax(T& x, T y) {x = max(x, y);}
template<typename T> void setmin(T& x, T y) {x = min(x, y);}
 
const double PI = acos(-1.0);
const int INF = 1e9 + 47;
const LL LINF = 1LL * INF * INF;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

string s[100];
int c[100];

vector<PII> g[1 << 15];

int get(int i, int len, int is_l)
{
	return 50 * i + 2 * len + is_l;
}
LL d[1 << 15];

int main()
{
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	int n;
	cin >> n;
	FOR(i, 0, n)
		cin >> s[i] >> c[i];
	FOR(i, 0, n)
	{
		FOR(len, 0, SZ(s[i]) + 1)
		{
			FOR(is_l, 0, 2)
			{
				FOR(j, 0, n)
				{
					bool ok = 1;
					if(is_l)
					{
						FOR(k, 0, min(len, SZ(s[j])))
						{
							if(s[i][SZ(s[i]) - len + k] != s[j][SZ(s[j]) - 1 - k]) ok = 0;
							
						}
					}
					else
					{
						FOR(k, 0, min(len, SZ(s[j])))
						{
							if(s[i][len - 1 - k] != s[j][k]) ok = 0;
						}
					}
					if(ok)
					{
						//cout << i << " " << j << " " << is_l << " " << len << endl;
						if(SZ(s[j]) >= len)
						{
							g[get(j, SZ(s[j]) - len, 1 - is_l)].PB(MP(get(i, len, is_l), c[j]));
						}
						else
						{
							g[get(i, len - SZ(s[j]), is_l)].PB(MP(get(i, len, is_l), c[j]));
						}
					}
				}
			}
		}
	}
	FOR(i, 0, 1 << 15)
		d[i] = LINF;
	set<pair<LL, int>> q;
	FOR(i, 0, n)
	{
		FOR(j, 0, 2)
		{
			int v = get(i, 0, j);
			d[v] = 0;
			q.insert(MP(0, v));		
		}
		FOR(len, 0, SZ(s[i]))
		{
			bool okl = 1, okr = 1;
			FOR(j, 0, len + 1)
			{
				if(s[i][j] != s[i][len - j]) okr = 0;
				if(s[i][SZ(s[i]) - 1 - j] != s[i][SZ(s[i]) - 1 - len + j]) okl = 0;
			}
			//cout << i << " " << len << " " << okl << " " << okr << " " << endl;
			if(okl)
			{
				int v = get(i, len + 1, 1);
				d[v] = 0;
				q.insert(MP(0, v));
			}
			if(okr)
			{
				int v = get(i, len + 1, 0);
				d[v] = 0;
				q.insert(MP(0, v));
			}
		}
	}
	/*FOR(v, 0, 1 << 15)
	{
		if(!SZ(g[v])) continue;
		cout << v / 50 << " " << (v % 50) / 2 << " " << v % 2 << endl;
		FOR(j, 0, SZ(g[v]))
		{
			int to = g[v][j].X;
			cout << to / 50 << " " << (to % 50) / 2 << " " << to % 2 << endl;
		}
		cout << endl;
	}*/
	while(SZ(q))
	{
		int v = q.begin()->Y;
		q.erase(q.begin());
		for(auto [to, co] : g[v])
		{
			if(d[to] > d[v] + co)
			{
				q.erase(MP(d[to], to));
				d[to] = d[v] + co;
				q.insert(MP(d[to], to));
			}
		}
	}
	LL mn = LINF;
	FOR(i, 0, n)
	{
		FOR(j, 0, 2)
		{
			int v = get(i, SZ(s[i]), j);
			setmin(mn, d[v] + c[i]);
		}
	}
	if(mn >= LINF) mn = -1;
	cout << mn << endl;
	
	cerr << "Time elapsed: " << clock() / (double)CLOCKS_PER_SEC << endl;
	return 0;
}
 


Measured memory_bytes: 4880
/**
 * @author torith
 * @date 2018-11-08
 */

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

int main(){

    cin.tie(0);
    ios::sync_with_stdio(false);
    int N; cin >> N;
    map<int,int> rec1,rec2;
    for (int i = 0; i < N; ++i) {
        int t; cin >> t;
        if(i % 2 == 0){
            rec1[t]++;
        }else{
            rec2[t]++;
        }
    }

    vector<pair<int,int> > rrec1, rrec2;
    for(auto & r: rec1){
        rrec1.push_back(make_pair(r.second, r.first));
    }

    for(auto & r: rec2){
        rrec2.push_back(make_pair(r.second, r.first));
    }

    sort(rrec1.begin(), rrec1.end());
    sort(rrec2.begin(), rrec2.end());

    int ans = N;
    // 最大値が同じだったとき2番めにかえる　
    auto end1 = rrec1.rbegin();
    auto end2 = rrec2.rbegin();
    if(end1->second == end2->second){
        if ((end1+1) != rrec1.rend()) {
            ans = N - (end1+1)->first - end2->first;
        }else{
            ans = N - end2->first;
        }

        if ((end2+1) != rrec2.rend()) {
            ans = min(ans, N - (end2+1)->first - end1->first);
        }else{
            ans = min(ans, N - end1->first);
        }

    }else{
        ans -= end1->first + end2->first;
    }

    cout << ans << "\n";

    return 0;
}



Measured memory_bytes: 6140
#include<cstdio>
int main()
{int n,k;
int long long x,y,cost;
scanf("%d %d %lld %lld",&n,&k,&x,&y);
if(n-k>0)
{cost=(n-k)*y+x*k;
}
if(n==k)
{cost=n*x;
}
if(n<k)
{cost=n*x;
}
printf("%lld",cost);
}

Measured memory_bytes: 128
import sys
input = lambda: sys.stdin.readline().rstrip()
input_nums = lambda: list(map(int, input().split()))

def main():
    N, K = input_nums()
    total_p = 0
    for i in range(1, N+1):
        p = 1/N
        val = i
        cnt = 0
        while val < K:
            cnt += 1
            val *= 2
        total_p += p * (1/2)**cnt
    print(total_p)

if __name__ == '__main__':
    main()


Measured memory_bytes: 2940
import heapq

N, M = map(int, input().split())
A = list(map(lambda x: int(x)*(-1), input().split()))

heapq.heapify(A) 

for _ in range(M):
    tmp_min = heapq.heappop(A)
    heapq.heappush(A, (-1)*(-tmp_min//2))
print(-sum(A))

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

#define rep(i,n) for(long long int (i)=0;(i)<(int)(n);(i)++)
#define rrep(i,a,b) for(long long int i=(a);i<(b);i++)
#define rrrep(i,a,b) for(long long int i=(a);i>=(b);i--)
#define all(v) (v).begin(), (v).end()
#define pb(q) push_back(q)
#define Abs(a,b) max(a,b)-min(a,b)
#define YES(condition) if(condition){cout << "YES" << endl;}else{cout << "NO" << endl;}
#define Yes(condition) if(condition){cout << "Yes" << endl;}else{cout << "No" << endl;}
#define Cout(x) cout<<(x)<<endl
#define POSSIBLE(condition) if(condition){cout << "POSSIBLE" << endl;}else{cout << "IMPOSSIBLE" << endl;}
#define Possible(condition) if(condition){cout << "Possible" << endl;}else{cout << "Impossible" << endl;}
#define possible(condition) if(condition){cout << "possible" << endl;}else{cout << "impossible" << endl;}
#define Size(n) (n).size()

typedef long long ll;


using namespace std;

const int INF = 1e9,MOD = 1e9 + 7,ohara = 1e6;
const ll LINF = 1e18;


long long int n,cnt=0,ans=INF,a,b,c,d,cmp,cmpp,m,h,w,x,y,sum=0,pos;
int dy[]={1,0,-1,0};
int dx[]={0,1,0,-1};
string alph("abcdefghijklmnopqrstuvwxyz"),s;
bool fl=true;
struct edge{int to,cost;};

//-------------------------↓↓↓↓↓↓------------------------

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

      
      cin>>s;
      ll ma=0;
      for(char c='a';c<='z';c++){
        rep(i,Size(s)){
          if(s[i]==c){
            if(fl){
              fl=false;
              ma=max(ma,cnt);
            }
            else{
            ma=max(ma,cnt);
            }
            cnt=0;
          }
          else{
          cnt++;
          }
        }
        ma=max(ma,cnt);
        ans=min(ans,ma);
        cnt=0;
        ma=0;
        fl=true;
      }
      Cout(ans);
     

       
return 0;
}


Measured memory_bytes: 256
import sys

sys.setrecursionlimit(10 ** 6)

N = int(input())
A = list(map(int, input().split()))


def solve(i, ret, t):
    if i == N:
        return ret
    else:
        if t == '?':
            if A[i] > A[i - 1]:
                return solve(i + 1, ret, 'up')
            elif A[i] < A[i - 1]:
                return solve(i + 1, ret, 'down')
            else:
                return solve(i + 1, ret, '?')

        elif t == 'up' and A[i] < A[i - 1]:
            return solve(i + 1, ret + 1, '?')
        elif t == 'down' and A[i] > A[i - 1]:
            return solve(i + 1, ret + 1, '?')
        else:
            return solve(i + 1, ret, t)


print(solve(1, 1, '?'))


Measured memory_bytes: 95320
//If you can think it, you should implement it
#include<bits/stdc++.h>
using namespace std;
 
#define xlr8 ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define int long long int
#define ld long double
#define mod 1000000007
#define eb emplace_back
#define mp make_pair
#define nl "\n"
#define ignore cin.ignore(numeric_limits<streamsize>::max(),'\n')

#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }

void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
    cerr << *it << " = " << a << endl;
    err(++it, args...);
}

int power(int a,int b,int m=mod){ int ans=1; a=a%m;  while(b>0) {  if(b&1)  ans=(1LL*a*ans)%m; b>>=1;a=(1LL*a*a)%m;}return ans;}
int ncr(int n,int r){ int res=1; if(r>n-r)r=n-r; for(int i=0;i<r;i++) {  res*=n-i;  res/=i+1; } return res; }
int gcd(int a,int b){  if(b==0) return a;  return gcd(b,a%b);}
int lcm(int a,int b){return (a* b)/gcd(a,b);}

//__builtin_popcount()
//memset(a,0,sizeof(a))
//bool next_permutation(a.begin(),a.end())

int sum(int a)
{
    int cnt=0;
    while(a!=0)
    {
        cnt+=a%10;
        a/=10;
    }
    return cnt;
}

signed main(){
    xlr8;
    int tt=1;
    //cin>>tt;
    while(tt--)
    {
        int n,m,x;
        cin>>n>>m>>x;
        int a[n][m],c[n];
        for(int i=0;i<n;i++)
            {cin>>c[i];
                for(int j=0;j<m;j++)
                 cin>>a[i][j];
            }
        int price=LLONG_MAX;
        for(int bit=1;bit<(1<<n);bit++)
        {
            vector<int> ans(m,0);
            int tprice=0;
            for(int i=0;i<n;i++)
                if((1<<i)&bit)
                    {tprice+=c[i];for(int j=0;j<m;j++)
                        ans[j]+=a[i][j];}

            bool flag=true;
            for(int i=0;i<m;i++)
                if(ans[i]<x)
                    flag=false;
            if(flag)
                price=min(price,tprice);
        }
        if(price==LLONG_MAX)
            cout<<-1<<nl;
        else
            cout<<price<<nl;





    }

 return 0;
}

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

int main(){
  string s, t, res = "UNRESTORABLE";
  cin >> s >> t;
  int n = s.size(), m = t.size();
  for (int i=n-m; i>=0; i--){
    bool ok = true;
    rep(j, m){
      if (s[i+j] == t[j] || s[i+j] == '?') continue;
      ok = false;
      break;
    }
    if (ok){
      rep(j, m) s[i+j] = t[j];
      rep(j, n) if (s[j] == '?') s[j] = 'a';
      res = s;
      break;
    }
  }
  cout << res << endl;
  return 0;
}


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

using namespace std;
typedef long long ll;
#define rep(i,n) for( int i=0; i<n; ++i )

int main(){
  int n;
  std::cin >> n;
  ll cnt = 0;
  char bf = ' ';
  rep(i,n){
    char c;
    cin >> c;
    if ( c != bf ){
      bf = c;
      cnt++;
    }
  }
  cout << cnt << endl;
}

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

using namespace std;

int main()
{
    ios_base::sync_with_stdio(0);
    int n, m;
    cin >> n >> m;
    vector<int> a(m);
    for (int i = 0; i < m; ++i)
        cin >> a[i];
    sort(a.begin(), a.end());
    vector<int> r;
    for (int i = 0; i < m - 1; ++i)
        r.push_back(a[i + 1] - a[i]);
    sort(r.begin(), r.end());
    int odp = 0;
    if (n < m)
        for (int i = 0; i < m - n; ++i)
            odp += r[i];
    cout << odp;
    return 0;
}


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

int gcd(int a, int b){
    if(a < b) swap(a, b);
    int d, r;
    d = a / b;
    r = a % b;
    return (r > 0 ? gcd(b, r) : b);
}

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

    int n, x;
    cin >> n >> x;
    vector<int> A(n + 1);
    REP(i, n) cin >> A[i];
    A[n] = x;
    sort(A.begin(), A.end());

    int g = A[1] - A[0];
    for(int i = 1; i < n; i++){
        g = gcd(g, A[i + 1] - A[i]);
    }

    cout << g << endl;

    return 0;
}

Measured memory_bytes: 640
#include<stdio.h>
int main(void)
{
    int x,c1,c5,c10,c50,c100,c500;
	x==0;
	scanf("%d %d %d %d %d %d",&c1,&c5,&c10,&c50,&c100,&c500);
	x=1*c1+5*c5+10*c10+50*c50+100*c100+500*c500;
	if (x>=1000){
	    printf("1\n");
	}
	else {
	    printf("0\n");
	}
	return 0;
}

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

int main(){
    int n;
    cin>>n;
    vector<int> a(n+1);
    rep(i,n+1) cin>>a[i];
    vector<int> b(n);
    rep(i,n) cin>>b[i];
    ll ans=0;
    rep(i,n){
        if(b[i]>a[i]){
            ans+=a[i];
            b[i]-=a[i];
            if(a[i+1]>=b[i]){
                a[i+1]-=b[i];
                ans+=b[i];
            }
            else{
                ans+=a[i+1];
                a[i+1]=0;
            }
        }
        else ans+=b[i];
    }
    cout<<ans<<"\n";
    return 0;
}

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

using namespace std;

typedef long long ll;
#define fastIO ios_base::sync_with_stdio(false);cin.tie(0);
#define MOD 1000000007
#define all(a) (a).begin(), (a).end()
#define testcase ll tc;cin>>tc;while(tc--)
#define inp(a) vector<ll> a(n); for(ll i=0;i<n;i++) cin>>a[i];
#define out(a) for(ll i=0;i<n;i++) cout<<a[i]<<" ";
#define OF(i,n) for(ll i=n-1;i>=0;i--)
#define FO(i,n) for(ll i=0;i<n;i++)
#define FOR(i,l,n) for(ll i=l;i<n;i++)
#define ca cout<<ans;en;
#define cint ll temp;cin>>temp;
#define en cout<<"\n";
#define pb push_back
#define mp make_pair
#define S second
#define F first
#define pi 3.14159265
#include <fstream>

// void filereadwrite(){
// 	std::ifstream infile("input.txt");
// 	if (!infile.is_open()) {
// 	    return 0;
// 	}
// 	int n;
// 	infile>>n;
// 	int a[n];
// 	int i=0;
// 	while(infile >>a[i] && i<n)
// 		i++;
// 	sort(a,a+n);
// 	freopen("output.txt", "w", stdout);
// }

int main(){
	fastIO;
		int n;
		cin>>n;
		cout<<((n%1000)? 1000-n%1000 : 0 )<<endl;
}

Measured memory_bytes: 3652
#include<bits/stdc++.h>
#define ll long long
#define db long double
#define fi first
#define se second
#define  pb push_back
#define  pob pop_back
#define W while
#define fn(i,x) for(int i=0;i<x;i++)
#define fs(i,s,x) for(int i=s;i<x;i++)
#define fr(i,x) for(int i=x;i>=0;i--)
#define fit(it,s) for(auto it=s.begin();it!=s.end();it++)
#define mp make_pair
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vii vector<int>
#define vll vector<ll>
#define mod 1000000007
#define MAX 1005

// cout << "Case #" << i << ": " << "Your Ans" <<  "\n";

using namespace std;
int main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
 
    // freopen("in.txt","r",stdin);
    // freopen("out.txt","w",stdout);
    
    ll n,d;
    cin >> n >> d;
    ll x[n][d];
    fn(i,n){
    	fn(j,d) cin >> x[i][j];
    }
    ll ans = 0;
    fn(i,n){
    	fs(j,i+1,n){
           ll sum = 0;
           fn(k,d){
           	 sum += (x[i][k]-x[j][k])*(x[i][k]-x[j][k]);
           }
           ll o =sqrt(sum);
           if(o*o == sum) ans++;
    	} 
    }
    cout << ans;
 
}

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

int zero(){
	cout << "0" << endl;
	return 0;
}

int main(){
	long long N,A,B,ans;
	cin >> N >> A >> B;
	
	if(N==1 && A!=B)return zero();
	if(A>B)return zero();
	
	ans=(N-2)*(B-A)+1;
	
	cout << ans << endl;
	return 0;
}

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

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

int sx, sy, gx, gy;

int main(void) {
    cin >> sx >> sy >> gx >> gy;
    int dx = gx - sx, dy = gy - sy;

    string s = "";
    s += string(dy, 'U');
    s += string(dx, 'R');
    s += string(dy, 'D');
    s += string(dx, 'L');
    s += "L";

    s += string(dy + 1, 'U');
    s += string(dx + 1, 'R');
    s += "DR";
    s += string(dy + 1, 'D');
    s += string(dx + 1, 'L');
    s += "U";

    cout << s << endl;

    return 0;
}

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

int main() {
  int t[5];
  for(int i = 0; i < 5; ++i) cin >> t[i];
  int max_index = 0;
  int max_num = 0;
  for (int i = 0; i < 5; ++i ) {
   if (t[i]%10 == 0 ) continue;
   else if (max_num < (10- (t[i] % 10))){
      max_num = 10-(t[i] % 10);
      max_index = i;
    }
  }
  int ans = 0;
  for (int i = 0; i < 5; ++i ) {
    if ( i == max_index ) {
      ans += t[i];
    } else {
      ans += (t[i]+9)/10*10;
    }
  }
  cout << ans << endl;
     
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define pf push_front

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

#define mp make_pair
#define fi first
#define se second
typedef pair<int,int> pint;
#define All(s) s.begin(),s.end()
#define rAll(s) s.rbegin(),s.rend()
#define REP(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)
double pi = 3.141592653589793;
ll mod = 1000000007;
ll INF = 1000000001;
int intmax = 2147483647;
int intmin = -2147483648;
ll llmax = 9223372036854775807;
ll llmin = -9223372036854775807;



int main(){
    ll n, f=0, tmp = 10;
    cin >> n;
    if(n%2==1){
        cout << 0 <<endl;
    }else{
        n -= n%10;
/*        while(n > 0){
            tmp = n;
            while(tmp%2 == 0){
                t++;
                tmp/=2;
                // cout << "t:" << t << endl;
            }
            tmp = n;
            while(tmp%5 == 0){
                f++;
                tmp/=5;
                cout << "f:" << f << endl;
            }
            n -= 10;
            cout << "n:" << n << endl;
        }
*/
        while(n>=tmp){
            f += n/tmp;
            tmp *= 5;
        }
        cout << f << endl;
    }
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
using namespace std;
int x[100][100],y[100][100],d[100][100];
int counter;
int ans;
void cal(int X,int Y){
	if(d[X][Y]==-1){
		d[X][Y]=counter;
		cal(x[X][Y],y[X][Y]);
	}
	else if(d[X][Y]==counter){
		ans++;
	}
}
int main(){
	int n;
	while(cin>>n,n){
		ans=counter=0;
		for(int i=0;i<n;i++)for(int j=0;j<n;j++)cin>>x[j][i]>>y[j][i],d[j][i]=-1;;
		for(int i=0;i<n;i++){
			for(int j=0;j<n;j++){
				if(d[i][j]==-1){
					counter++;
					cal(i,j);
				}
			}
		}
		
		cout<<ans<<endl;
	}
	
	return 0;
}


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

#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 reps(i, n) for (int i = 1; i <= int(n); i++)
#define rreps(i, n) for (int i = int(n); i >= 1; i--)
#define repc(i, n) for (int i = 0; i <= int(n); i++)
#define rrepc(i, n) for (int i = int(n); i >= 0; i--)
#define repi(i, a, b) for (int i = int(a); i < int(b); i++)
#define repic(i, a, b) for (int i = int(a); i <= int(b); i++)
#define each(x, y) for (auto &x : y)
#define all(a) (a).begin(), (a).end()
#define bit32(x) (1 << (x))
#define bit64(x) (1ll << (x))
#define sz(v) ((int) v.size())

using namespace std;

using i64 = long long;
using f80 = long double;
using vi32 = vector<int>;
using vi64 = vector<i64>;
using vf80 = vector<f80>;
using vstr = vector<string>;

inline void yes() { cout << "Yes" << endl; exit(0); }
inline void no() { cout << "No" << endl; exit(0); }
inline i64 gcd(i64 a, i64 b) { if (min(a, b) == 0) return max(a, b); if (a % b == 0) return b; return gcd(b, a % b); }
inline i64 lcm(i64 a, i64 b) { if (min(a, b) == 0) return max(a, b); return a / gcd(a, b) * b; }
template <typename T> class pqasc : public priority_queue<T, vector<T>, greater<T>> {};
template <typename T> class pqdesc : public priority_queue<T, vector<T>, less<T>> {};
template <typename T> inline void amax(T &x, T y) { x = max(x, y); }
template <typename T> inline void amin(T &x, T y) { x = min(x, y); }
template <typename T> inline T exp(T x, i64 n, T e = 1) { T r = e; while (n > 0) { if (n & 1) r *= x; x *= x; n >>= 1; } return r; }
template <typename T> istream& operator>>(istream &is, vector<T> &v) { each(x, v) is >> x; return is; }
template <typename T> ostream& operator<<(ostream &os, vector<T> &v) { rep(i, v.size()) { if (i) os << ' '; os << v[i]; } return os; }
void solve(); int main() { ios::sync_with_stdio(0); cin.tie(0); cout << fixed << setprecision(16); solve(); return 0; }

void solve() {
  int w, h, n;
  cin >> w >> h >> n;
  int l = 0, r = w, d = 0, u = h;
  rep(i, n) {
    int x, y, a;
    cin >> x >> y >> a;
    if (a == 1) {
      amax(l, x);
    } else if (a == 2) {
      amin(r, x);
    } else if (a == 3) {
      amax(d, y);
    } else {
      amin(u, y);
    }
  }
  if (l >= r || d >= u) {
    cout << 0 << endl;
    return;
  }
  cout << (r - l) * (u - d) << endl;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    private static final int MOD = 1000000007;

    public static void main(String[] args) {
        final Scanner scanner = new Scanner(System.in);
        final int n = scanner.nextInt();
        final long k = scanner.nextLong();

        final int[] array = new int[n];
        for (int i = 0; i < array.length; i++) {
            array[i] = scanner.nextInt();
        }

        long all = 0;
        long latter = 0;

        for (int i = 0; i < array.length; i++) {
            for (int j = 0; j < array.length; j++) {
                if (array[i] > array[j]) {
                    if (i < j) {
                        latter++;
                    }
                    all++;
                }
            }
        }

        System.out.println(((all * (k * (k - 1) / 2 % MOD)) %MOD + latter * k % MOD) % MOD);
    }
}


Measured memory_bytes: 26224
import numpy as np
S = str(input())
S_list =[S]
total = 0

def X(li,X):
	for j in range(len(li)):
		dis = -len(S)+len(li[j])
		li.append(li[j][:X+1+dis]+ '!' + li[j][-len(li[j])+X+1+dis:])

	return li
			
for i in range(len(S)-1):
	S_list = X(S_list,i)
	
for i in range(len(S_list)):
	temp = S_list[i].split('!')
	for j in range(len(temp)):
		total = total + int(temp[j])
		
print(total)

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

public class Main {

	public static void main(String[] args) throws IOException {
		// TODO 自動生成されたメソッド・スタブ
		BufferedReader vd = new BufferedReader(new InputStreamReader(System.in));
		String cd = vd.readLine();
		String[] fd = cd.split("");
		int n = Integer.parseInt(cd);
		int k =0;
		for(int i=0;i<fd.length;++i) {
			k=k+Integer.parseInt(fd[i]);
		}
		if(n%k==0) System.out.println("Yes");
		else System.out.println("No");
	}

}


Measured memory_bytes: 21460
#include <bits/stdc++.h>
using namespace std;
int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	vector<int>digit;
	int N,M;
	cin>>N>>M;
	bool key=true;
	for(int i=0;i<N;i++)
	{
		digit.push_back(-1);
	}
	for(int i=0;i<M;i++)
	{
		int s,c;
		cin>>s>>c;
		s--;
		if(s==0&&c==0&&N!=1){
			key=false;
		}
		if(digit[s]!=-1&&c!=digit[s]){
			key=false;
		}
		digit[s]=c;
	}
	if(!key){
		cout<<-1<<endl;
		return 0;
	}
	for(int i=0;i<N;i++)
	{
		if(digit[i]==-1){
			if(i==0&&N!=1){
				cout<<1;
			}
			else cout<<0;
		}
		else{
			cout<<digit[i];
		}
	}
	cout<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
int main(){
  
  int howtimes,shuffle,lastcard=0,i,j,k;
  char card[1000]={

};
  
 
  while(1){
    
    scanf("%s",card);
    
    if(card[0] != '-'){
      
      scanf("%d",&howtimes);
      
      for(i = 0; card[i] != '\0'; i++){
	
	lastcard=i+1;
	
      }
      
      for(i = 0; i < howtimes; i++){
	
	scanf("%d",&shuffle);
	
	for(j = 0; j < shuffle; j++){
	  
	  card[lastcard+j]=card[j];
	  
	}
	
	for(j = 0; j < lastcard; j++){
	  
	  card[j]=card[shuffle+j];
	  
	}
	
      }
      
      for(i = 0; i < lastcard; i++){
	
	printf("%c",card[i]);
	
      }
      
      printf("\n");
      
    } else {
      
      break;
      
    }  
    
  }
  
  return 0;
  
}


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

typedef long long ll;
typedef long double ld;
const ll M=1e9+7;
const ll MAXN=1e6+7;
const ld pi=acos(-1);

#define gi(n) ll n=read()
#define endl '\n'
#define rep(i,a,b) for(ll i=a; i<b; ++i)
#define per(i,a,b) for(ll i=b-1; i>=a; --i)

typedef vector<ll> V;
typedef vector<V> VV;
typedef set<ll> S;
typedef pair<ll,ll> pl;
typedef vector<pl> Vp;

#define all(v) v.begin(),v.end()
#define pb push_back
#define fs first
#define sc second

inline ll read(){
	ll x=0,ff=1;
	char ch=getchar();
	while(!isdigit(ch)) {if(ch=='-') ff=-1;ch=getchar();}
	while(isdigit(ch)) {x=(x<<1)+(x<<3)+(ch^48);ch=getchar();}
	return x*ff;
}

ll gcd(ll a, ll b){return b?gcd(b,a%b):a;}
//ll pow1(ll p,ll d, ll P){return d?(pow1(p*p%P,d>>1,P)*(d&1?p%P:1))%P:1;}
ll mul(ll a,ll b,ll P){return b?(mul(a*2%P,b>>1,P)+(b&1?a:0))%P:0;}
ll pow1(ll p,ll d, ll P){return d?mul(pow1(mul(p,p,P),d>>1,P),(d&1?p%P:1),P):1;}

V prime;
bool is_composite[MAXN];
void sieve (ll n){
	std::fill (is_composite, is_composite + n, false);
	rep(i,2,n){
		if(!is_composite[i]) prime.pb(i);
		for(ll j = 0; j < prime.size() && i*prime[j] < n; ++j){
			is_composite[i*prime[j]] = true;
			if(i % prime[j] == 0) break;
		}
	}
}
ll modInverse(ll a, ll m){
	ll m0=m,y=0,x=1;
	if(m==1) return 0;
	while(a>1){
		ll q=a/m,t=m;
		m=a%m;
		a=t; 
		t=y;

		y = x-q*y; 
		x = t;
	}
	if(x<0) x += m0;
	return x; 
}

void doit(){
	gi(n);
	ll a[n],c=0;
	rep(i,0,n) a[i]=read();
	sort(a,a+n);
	rep(i,0,n) rep(j,i+1,n) rep(k,j+1,n) if(a[i]+a[j]>a[k] and a[i]-a[j] and a[j]-a[k]) c++;
	cout<<c;
}

int main(){
//	for(gi(t);t--;cout<<endl)
		doit();
	return 0;
}

Measured memory_bytes: 3600
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1e18

int main() {
    int N, M;
    cin >> N >> M;
    for (int i = 1; i <= M / 2; i++) cout << i << " " << M - (i - 1) << endl;
    for (int i = 1; i <= (M + 1) / 2; i++) cout << M + i << " " << (2 * M + 1) - (i - 1) << endl;
    return 0;
}

Measured memory_bytes: 3592
n = int(input())
v = list(map(int,input().split()))
c = list(map(int,input().split()))

num = 0
a = []
for i in range(len(v)):
    a.append(v[i] - c[i])

a.sort(reverse=True)

for b in a:
    if b <= 0:
        break
    num += b

print(num)


Measured memory_bytes: 3060
fun main(args: Array<String>) {
    val n = readLine()!!.toInt()
    val dList = readLine()!!.split(" ").map(String::toInt)
    var sum = 0
    for (x in 0 until n) {
        for (y in x+1 until n)
            sum += dList[x] * dList[y]
    }
    println(sum)
}

Measured memory_bytes: 36152
#include<iostream>
#include<string>
#include<algorithm>
#define MAX 1001
using namespace std;

int main() {
    int n,mat[MAX][MAX];
    string s1,s2;
    cin >> n;
    for(int k=0;k<n;k++) {
        cin >> s1 >> s2;
        for(int i = 0; i < s1.size(); i++) {
            for(int j = 0; j < s2.size(); j++) {
                mat[i + 1][j + 1] = (s1[i] == s2[j] ? mat[i][j] + 1 : max(mat[i][j + 1], mat[i + 1][j]));
            }
        }
        cout << mat[s1.size()][s2.size()] << endl;
    }
}

Measured memory_bytes: 5116
//
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
// #define MOD 1000000007
#define rp(i,n) for(int i=0;i<(n);i++)
#define up(i,s,e,d) for(int i=(s);i<(e);i+=(d))
#define ot(x) cout<<(x)
#define ote(x) cout<<(x)<<endl
#define all(x) (x).begin(),(x).end()

int main(){
	int N;cin>>N;
	int maxi = 0;
	int all = 0;
	vi P(N);
	rp(i,N){
		cin>>P[i];
		maxi = max(maxi,P[i]);
		all += P[i];
	}

	ll ans = all - (maxi/2);
	ote(ans);
}


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

using namespace std;

int main()
{	
	std::deque<int> dq;
	char s[20];
	int i;

	cin >> s;

	for (i = 0; s[i] != '\0'; i++) {
		if (s[i] == '1')dq.push_back(1);
		else if (s[i] == '0')dq.push_back(0);
		else if (s[i] == 'B' && !dq.empty())dq.pop_back();
	}
	for (i = 0; i != dq.size(); ++i)
		cout << dq[i];
	cout << endl;
	return 0;
}

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

int a, b, c, d;

int main(void){
    // Here your code !
    scanf("%d %d %d %d", &a, &b, &c, &d);

    if (d < a || b < c) printf("0\n");
    else if (a <= d && d <= b && c < a) printf("%d\n", (d - a));
    else if (a <= d && d <= b && a <= c && c <= b) printf("%d\n", (d - c));
    else if (c <= a && a <= d && c <= b && b <= d) printf("%d\n", (b - a));
    else if (b < d && a <= c && c <= b) printf("%d\n", (b - c));
    else printf("0\n");
    return 0;
}


Measured memory_bytes: 256
/*********************************************JMD**********************************************/
//                                  |\  |     | |   |   /\                                   //
    //                              | \ |     | |---|  /--\                              //
        //                          |  \| |___| |   | /    \1999                     //
/*******************************************************************************************/
#include <bits/stdc++.h>
using namespace std;

typedef long long int ll;
typedef unsigned long long int ull;

#define mp make_pair
#define pb push_back
#define pf push_front
#define ss second
#define ff first
#define mem(x,val) memset(x,val,sizeof(x))
#define forr(i,a,b) for(ll i=a;i<b;i++)
#define f(i,n) forr(i,0,n)
#define sz(x) ll((x).size())
#define all(x) ((x).begin(),(x).end())
#define asc(x) ((int)(x))
#define precision(x) cout<<fixed<<setprecision((x));

const ll mod=1e9 + 7;

/*******************************************************************************************/
vector< vector< pair<ll,ll> > > g;
vector<ll> vis;
vector<ll> ans;

void dfs(ll x)
{
    vis[x]=1;

    f(i,g[x].size())
    {
        if(!vis[g[x][i].ff])
        {
            if(g[x][i].ss%2) ans[g[x][i].ff]=!ans[x];
            else ans[g[x][i].ff]=ans[x];

            dfs(g[x][i].ff);
        }
    }
}
void solve()
{
    ll n;
    cin>>n;

    g.resize(n);
    vis.resize(n);
    ans.resize(n);

    f(i,n-1)
    {
        ll x,y,w;
        cin>>x>>y>>w;
        x--,y--;

        g[x].pb({y,w});
        g[y].pb({x,w});
    }

    dfs(0);

    for(auto x: ans) cout<<x<<"\n";

    return;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    ll t=1;
    //cin>>t;
    clock_t launch=clock();

    while(t--)
    {
        solve();
    }

    clog<<((long double)(clock()-launch)/CLOCKS_PER_SEC)<<"\n";
}


Measured memory_bytes: 9984
#include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> P;

int main(void) {
  int n;
  cin >> n;
  vector<int> v(n);
  for (int i = 0; i < n; i++) {
    cin >> v[i];
  }
  map<int, int> even_map;
  map<int, int> odd_map;

  for (int i = 0; i < n; i++) {
    if (i % 2 == 0) {
      even_map[v[i]]++;
    } else {
      odd_map[v[i]]++;
    }
  }
  vector<P> even, odd;
  for (auto e : even_map) {
    even.push_back(P(e.second, e.first));
  }
  for (auto o : odd_map) {
    odd.push_back(P(o.second, o.first));
  }
  sort(even.begin(), even.end(), greater<P>());
  sort(odd.begin(), odd.end(), greater<P>());
  even.push_back(P(0, 0));
  odd.push_back(P(0, 0));
  if (even[0].second != odd[0].second) {
    cout << (n - even[0].first - odd[0].first) << endl;
  } else {
    cout << min(n - even[0].first - odd[1].first,
                n - even[1].first - odd[0].first)
         << endl;
  }

  return 0;
}


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

typedef long long ll;
const int mod=1e9+7;

int main(){
  int n;
  while(cin>>n){
    ll a=1;
    for(int i=2;i<=n;i++){
      a=(a*i)%mod;
    }
    cout<<a<<endl;
  }
  return 0;
}

Measured memory_bytes: 3176
#include <iostream>
#include <string>
#include <vector>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>

using namespace std;
using ll = long long;

#define all(c) (c).begin(), (c).end()
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define pb(e) push_back(e)
#define mp(a, b) make_pair(a, b)
#define fr first
#define sc second

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

const int MAX_V = 10004;
int V;
vector<int> G[MAX_V];
vector<int> rG[MAX_V];
vector<int> vs;
bool used[MAX_V];
int cmp[MAX_V];

void add_edge(int from, int to) {
    G[from].push_back(to);
    rG[to].push_back(from);
}

void dfs(int v) {
    used[v] = true;
    for (auto u : G[v]) {
        if (!used[u]) dfs(u);
    }
    vs.push_back(v);
}

void rdfs(int v, int k) {
    used[v] = true;
    cmp[v] = k;
    for (auto u : rG[v]) {
        if (!used[u]) rdfs(u, k);
    }
}

int scc() {
    memset(used, 0, sizeof(used));
    vs.clear();
    rep(i, V) if (!used[i]) dfs(i);
    memset(used, 0, sizeof(used));

    int k = 0;
    for (int i = vs.size() - 1; i >= 0; i--) {
        if (!used[vs[i]]) rdfs(vs[i], k++);
    }
    return k;
}
int E;
int main() {
    cin >> V >> E;
    rep(i, E) {
        int a, b;
        cin >> a >> b;
        add_edge(a, b);
    }
    scc();
    int Q;
    cin >> Q;
    rep(_, Q) {
        int a, b;
        cin >> a >> b;
        if (cmp[a] == cmp[b])
            cout << "1" << endl;
        else
            cout << "0" << endl;
    }
    return 0;
}

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

using namespace std;
typedef long long ll;

const ll MOD = 998244353;

int main() {
    int n, k;
    cin >> n >> k;

    vector<vector<int>> ranges(k, vector<int>(2));
    for (int i = 0; i < k; i++)cin >> ranges[i][0] >> ranges[i][1];

    vector<ll> dp(n * 3);
    dp[0] = 1;
    for (int i = 0; i < n; i++) {
        for (auto range:ranges) {
            dp[i + range[0]] += dp[i], dp[i + range[0]] %= MOD;
            dp[i + range[1] + 1] += MOD - dp[i], dp[i + range[1]] %= MOD;
        }

        if (i > 0) dp[i + 1] += dp[i], dp[i + 1] %= MOD;
    }

    cout << dp[n - 1] << endl;
    return 0;
}


Measured memory_bytes: 8008