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

using namespace std;
typedef long long ll;

#define MOD (long long)(1e9+7)
#define INF (1LL<<60)
#define rep(i,n) for(ll i = 0; i < (n); i++)
#define rep1(i,n) for(ll i = 1; i <= (n); i++)

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


// 最大公約数
ll gcd(ll a, ll b)
{
  if(b == 0) return a;
  return gcd(b, a % b);
}

// mod m におけるa の逆元
ll modinv(ll a, ll m) {
  ll b = m, u = 1, v = 0;
  while (b) {
    ll t = a / b;
    a -= t * b; swap(a, b);
    u -= t * v; swap(u, v);
  }
  u %= m;
  if (u < 0) u += m;
  return u;
}

// 素因数分解
vector<pair<ll, ll>> prim;
void pf(ll n)
{
  ll s = sqrt(n);
  ll r = 0;
  for(ll i = 2; i <= s; i++) {
    if((n % i) == 0) {
      r = 0;
      do {
	r++;
	n = n / i;
      } while((n % i) == 0);
      prim.push_back({i, r});
    }
  }
  if(n > s) {
    prim.push_back({n, 1});
  }
}

void solve()
{
  ll N; cin >> N;
  // ll N, K; cin >> N >> K;
  // ll x, y, z; cin >> x >> y >> z;
  // ll a, b, c; cin >> a >> b >> c;
  // string s; cin >> s;
  vector<ll> x(N); rep(i, N) cin >> x[i];
  
  ll ans = INF;

  for(ll i = 1; i <= 100; i++) {
    ll su = 0;
    rep(j, N) {
      su += (x[j] - i) * (x[j] - i);
    }
    cerr << su << endl;
    ans = min(su, ans);
  }

  cout << ans << endl;

}


int main(void)
{
  // ll t; cin >> t; rep(i, t)
  solve();
}


Measured memory_bytes: 3596
#include <iostream>
#include <algorithm>
#include <vector>
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
using namespace std;
typedef long long ll;
const ll MOD=1e+9+7;
struct mint{
  ll x;
  mint(ll x=0):x(x%MOD){}
  mint& operator+=(const mint a){
    if((x+=a.x)>=MOD) x-=MOD;
    return *this;
  }
  mint& operator-=(const mint a){
    if((x += MOD-a.x)>=MOD) x-=MOD;
    return *this;
  }
  mint& operator*=(const mint a){
    (x*=a.x)%=MOD;
    return *this;
  }
  mint operator+(const mint a) const{
    mint res(*this);
    return res+=a;
  }
  mint operator-(const mint a) const{
    mint res(*this);
    return res-=a;
  }
  mint operator*(const mint a) const{
    mint res(*this);
    return res*=a;
  }
  mint pow(ll t) const{
    if(!t) return 1;
    mint a = pow(t>>1);
    a*=a;
    if(t&1) a*=*this;
    return a;
  }
  
  //for prime mod
  mint inv() const{
    return pow(MOD-2);
  }
  mint& operator/=(const mint a){
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const{
    mint res(*this);
    return res/=a;
  }
};

int main()
{
  int n;
  cin >> n;
  vector<ll> t(n),a(n);
  rep(i,n) cin >> t[i];
  rep(i,n) cin >> a[i];

  vector<ll> ax(n,0),in(n,1e+9+10);
  ll tax=0,tin=1e+9+10;
  rep(i,n){
    if(tax<t[i]){
      ax[i] = in[i] = t[i];
      tax = t[i];
    }
    else if(tax==t[i]){
      ax[i] = tax;in[i] = 1;
    }
  }

  ll aax = 0;
  for(int i=n-1;i>=0;--i){
    if(aax<a[i]){
      if(a[i]<in[i]||ax[i]<a[i]){
	cout << 0 << "\n";
	return 0;
      }
      else{
	ax[i] = in[i] = a[i];
	aax = a[i];
      }
    }
    else if(aax==a[i]){
      in[i] = max(in[i],1LL);
      ax[i] = min(ax[i],a[i]);
    }
  }

  mint res(1);
  rep(i,n){
    if(in[i]>ax[i]){
      cout << 0 << "\n";
      return 0;
    }
    else{
      res *= (mint)(ax[i]-in[i]+1);
    }
  }

  cout << res.x << "\n";
  
  return 0;
}


Measured memory_bytes: 3328
#include<deque>
#include<queue>
#include<vector>
#include<algorithm>
#include<iostream>
#include<set>
#include<cmath>
#include<tuple>
#include<string>
#include<chrono>
#include<functional>
#include<iterator>
#include<random>
#include<unordered_set>
#include<array>
#include<map>
#include<iomanip>
#include<assert.h>
#include<bitset>
#include<stack>
#include<memory>
using namespace std;
using namespace std::chrono;
typedef long long int llint;
typedef double lldo;
#define mp make_pair
#define mt make_tuple
#define pub push_back
#define puf push_front
#define pob pop_back
#define pof pop_front
#define fir first
#define sec second
#define res resize
#define ins insert
#define era erase
/*cout<<fixed<<setprecision(20);cin.tie(0);ios::sync_with_stdio(false);*/
const llint mod=1000000007;
const llint big=2.19e15+1;
const long double pai=3.141592653589793238462643383279502884197;
const long double eps=1e-15;
template <class T,class U>bool mineq(T& a,U b){if(a>b){a=b;return true;}return false;}
template <class T,class U>bool maxeq(T& a,U b){if(a<b){a=b;return true;}return false;}
llint gcd(llint a,llint b){if(a%b==0){return b;}else return gcd(b,a%b);}
llint lcm(llint a,llint b){if(a==0){return b;}return a/gcd(a,b)*b;}
template<class T> void SO(T& ve){sort(ve.begin(),ve.end());}
template<class T> void REV(T& ve){reverse(ve.begin(),ve.end());}
template<class T>llint LBI(vector<T>&ar,T in){return lower_bound(ar.begin(),ar.end(),in)-ar.begin();}
template<class T>llint UBI(vector<T>&ar,T in){return upper_bound(ar.begin(),ar.end(),in)-ar.begin();}

int main(void){
	//約数列挙ってpythonでできるの？ 
	// n%m==n/m==x
	// n==x*m+x
	// n==x*(m+1),m>x
	llint n,ans=0,i;cin>>n;
	for(i=1;i*(i+1)<n;i++){
		if(n%i==0){ans+=n/i-1;}
	}
	cout<<ans<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <stdio.h>
#include <algorithm>
using namespace std;
#define ll long long
#define r(i,n) for(int i=0;i<n;i++)
#define rn(i,n) for(int i=1;i<=n;i++)

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

  
  k--;n--;

  cout<<(n+k-1)/k<<endl;


  return 0;
}


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

ll gcd(ll x,ll y) {return y ? gcd(y,x%y) : x;} 
ll lcm(ll x,ll y) {return x/gcd(x,y)*y;}

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

    return 0;
}











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

int main() {
  int N, M;
  cin >> N >> M;
  vector<int> d(M);
  vector<vector<int>> num(N, vector<int>(M));
  for (int i = 0; i < M; i++) {
    cin >> d.at(i);
    for (int j = 0; j < d.at(i); j++) {
      int k;
      cin >> k;
      num.at(k - 1).at(i) = 1;
    }
  }
  int count = 0;
  for (int i = 0; i < N; i++) {
    int sum = 0;
    for (int j = 0; j < M; j++) {
      sum += num.at(i).at(j);
    }
    if (sum == 0) {
      count++;
    }
    sum = 0;
  }
  cout << count << endl;
}

Measured memory_bytes: 3604
#include <bits/stdc++.h>
using namespace std;
int N, M;
int A[1000000 + 100];
int main()
{
	scanf("%d%d", &N, &M);
	int fl = 0, Gcd;
	for (int i = 1; i <= N; ++i)
	{
		scanf("%d", &A[i]);
		if (i != 1) Gcd = __gcd(A[i-1], A[i]);
		if (A[i] == M) { puts("POSSIBLE"); return 0; }
		if (A[i] > M)fl = 1;
	}
	if (!fl)
	{
		puts("IMPOSSIBLE");
		return 0;
	}
	if (M % Gcd == 0)
		puts("POSSIBLE");
	else puts("IMPOSSIBLE");
	return 0;
}

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

const int INF = 1<<28;

int main() {
  int W; cin >> W;
  vector<int> a(W);
  for(int i = 0; i < W; ++i) cin >> a[i];
  vector<int> L(W+1), R(W+1);
  L[0] = -1;
  for(int i = 0; i < W; ++i) {
    L[i+1] = L[i] - 1;
    if(a[i] == 0) L[i+1] = INF;
    else if(a[i] < 0) L[i+1] = min(L[i+1], -a[i]-1);
  }
  R[W] = -1;
  for(int i = W-1; i >= 0; --i) {
    R[i] = R[i+1] - 1;
    if(a[i] == 0) R[i] = INF;
    else if(a[i] < 0) R[i] = min(R[i], -a[i]-1);
  }
  int res = 0;
  for(int i = 0; i < W; ++i) {
    if(a[i] > 0); else continue;
    int t = max(L[i+1], R[i]);
    if(t < 0) continue;
    res += min(a[i], t+1);
  }
  cout << res << endl;
  return 0;
}

Measured memory_bytes: 2328
S = input()
N = len(S)

ans = 0
for bit in range(1<<(N-1)):
    formula = ""
    for i in range(N-1):
        if (bit >> i) & 1:
            k = "+"
        else:
            k = ""
        formula += S[i] + k
    formula += S[N-1]
    ans += eval(formula)
print(ans)

Measured memory_bytes: 3060
#include <stdio.h>

#define MAX 500000
#define SENTINEL 2000000000

int L[MAX/2+2], R[MAX/2+2];
int cnt;

void merge(int A[],int n,int left, int mid, int right) {
  int i, j, k;
  int n1 = mid -left;
  int n2 = right - mid;
  for(i=0;i<n1;i++) L[i] = A[left + i];
  for(i=0;i<n2;i++) R[i] = A[mid + i];
  L[n1] = R[n2] = SENTINEL;
  i=0, j=0;
  for(k=left; k<right; k++) {
    cnt++;
    if(L[i]<=R[j]) {
      A[k] = L[i++];
    } else {
      A[k] = R[j++];
    }
  }
}

void mergeSort(int A[],int n,int left,int right) {
  int mid;
  if(left+1 < right) {
    mid = (left+right) / 2;
    mergeSort(A,n,left,mid);
    mergeSort(A,n,mid, right);
    merge(A,n,left,mid,right);
  }
}

int main(void) {
  int A[MAX], n, i;
  cnt = 0;

  scanf("%d",&n);
  for(i=0;i<n;i++) scanf("%d",&A[i]);

  mergeSort(A, n, 0, n);
  for(i=0;i<n;i++) {
    if(i) printf(" ");
    printf("%d",A[i]);
  }
  printf("\n%d\n",cnt);

  return 0;
}


Measured memory_bytes: 5592
#include<bits/stdc++.h>
using namespace std;
int main(){
	stack<int> s;
	char c;
	int res = 0;
	while(cin >> c){
		int n = c-'0';
		if(s.empty() || s.top() + n != 1) s.push(n);
		else s.pop(), res++;
	}
	cout << 2*res << endl;
}

Measured memory_bytes: 640
#include <stdio.h>
#include <string.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdlib.h>
#include <limits.h>
int acs(const void *a, const void *b){return *(int*)a - *(int*)b;} /* 1,2,3,4.. */
int des(const void *a, const void *b){return *(int*)b - *(int*)a;} /* 8,7,6,5.. */
#define min(a,b) (a < b ? a: b)
#define max(a,b) (a > b ? a: b)

#define MAXN (1000)
#define MOD (998244353)

int a[MAXN][MAXN];
int sn[MAXN];
bool wait[MAXN][MAXN];
int last[MAXN];

int main(void)
{
    int n;
    scanf("%d",&n);

    for(int i=0;i<n;i++)for(int j=0;j<n-1;j++)
    {
        scanf("%d",&(a[i][j]));
    }
    
    int siain = 0;
    int maxday = 0;
    while(1)
    {
        bool siai = false;
        for(int i=0;i<n;i++)
        {
            if(sn[i]==n-1) continue;
            // jと試合できるならする
            int j = a[i][sn[i]]-1;
            if(wait[j][i])
            {
                sn[i]++;
                sn[j]++;
                int day = max(last[i],last[j])+1;
                last[i] = day;
                last[j] = day;
                maxday = max(day, maxday);
                siai = true;
                siain++;
                i--;
            }else
            {
                wait[i][j] = true;
            }
        }
        if(!siai)
        {
            printf("-1\n");
            return 0;
        }
        if(siain>=(n*(n-1)/2)) break;
    }
    printf("%d\n",maxday);

    return 0;
}







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

using namespace std;

const ll mod=1000000007;
const ll inf=1e18;

int main(){

  ll n,m;
  string s;

  cin >> n >> m >> s;

  ll dp[n+1]={};

  ll p=n;
  bool owa=false;

  while(p!=0){
    ll k=0;
    for(ll i=1;i<=m;i++){
      if(p-i==-1){
        owa=true;
        break;
      }
      if(s[p-i]=='1')dp[p-i]=-1;
      else{
        k=i;
        dp[p-i]=dp[p]+1;
      }
    }

    if(k==0){
      cout << -1 << endl;
      return 0;
    }


    if(owa)p=0;
    else p=p-k;
  }
  if(dp[0]==0)cout << -1 << endl;
  else{
    p=0;
    ll a=dp[p];
    vector<ll> v;
    bool mugokuka=true;
    while(p!=n){
      for(ll i=1;i<=m;i++){
        if(dp[p+i]+1==dp[p]){
          v.push_back(i);
          mugokuka=false;
          p=p+i;
          break;
        }
      }
    }
    for(ll i=0;i<v.size();i++)cout << v[i] << " " ;
    
    
  }

}

Measured memory_bytes: 5156
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
using namespace std;
typedef long long int ll;

int N;
string S;
vector<int> memo, memo2;

int main(){
	cin >> N >> S;
	memo.resize(N);
	memo2.resize(N);
	for(int i = 0; i < S.length(); i++){
		if(i == 0){
			if(S[i] == '.') memo[i]++;
		}else{
			if(S[i] == '.') memo[i] = memo[i - 1] + 1;
			else memo[i] = memo[i - 1];
		}
	}
	for(int i = S.length() - 1; i >= 0; i--){
		if(i == S.length() - 1){
			if(S[i] == '#') memo2[i]++;
		}else{
			if(S[i] == '#') memo2[i] = memo2[i + 1] + 1;
			else memo2[i] = memo2[i + 1];
		}
	}
	int res = 222222;
	for(int i = 0; i < N; i++){
		res = min(res, (N - i - 1) - memo[i] + i + 1 - memo2[i]);
	}
	cout << res << endl;
	return 0;
}


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

using ll = long long;
using ull = unsigned long long;

const double PI = acos(-1);
const int inf = 2e9;
const ll INF = 2e18;
const ll MOD = 1e9 + 7;

#define sz(s) (s).size()
#define pb push_back
#define fi first
#define se second
#define REP(i, n) for (int i = 0; i < n; i++)
#define ALL(a) begin(a), end(a)

int main(void) {
    int N;
    string S;
    cin >> N >> S;
    int ans = 0;
    REP(i, 10) {
        REP(j, 10) {
            REP(k, 10) {
                vector<int> pin = {i, j, k};
                int m = 0;
                REP(n, N) {
                    if ((int)S[n] - '0' == pin[m]) {
                        m++;
                    }
                    if (m == 3) {
                        ans++;
                        break;
                    }
                }
            }
        }
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
//              _      _                 
//             (_)    | |                
//    _ __ ___  _  ___| |__   __ _  ___  
//   | '_ ` _ \| |/ __| '_ \ / _` |/ _ \ 
//   | | | | | | | (__| | | | (_| | (_) |
//   |_| |_| |_|_|\___|_| |_|\__,_|\___/ 
//                                       
// 
#include <bits/stdc++.h>
#define int long long
#define mp make_pair
#define pb push_back
#define ld long double
#define pii pair<int,int>
#define sz(x) (int)x.size()
#define piii pair<pii,pii>
#define precise cout<<fixed<<setprecision(10)
#define st first
#define nd second
#define ins insert
#define vi vector<int>
#define BOOST ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
/*#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")*/
using namespace std;
const int MAX=2e5+5;
int tab[MAX];
int32_t main()
{
  BOOST;
  int n;
  cin>>n;
  int pom=0;
  for (int i=1;i<=n;i++)cin>>tab[i],pom^=tab[i];
  for (int i=1;i<=n;i++)cout<<(pom^tab[i])<<" ";
  return 0;
}


Measured memory_bytes: 5204
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)

//-----------------------------------------------

//------------------------------------------------
int main(){
  string s;
  cin>>s;
  if(s=="Sunny")  cout<<"Cloudy"<<endl;
  if(s=="Cloudy")  cout<<"Rainy"<<endl;
  if(s=="Rainy")  cout<<"Sunny"<<endl;
}


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

#define rep(i, l, n) for(long long i=(l); i<(long long)(n); i++)
#define REP(i, n) for(long long i=1; i<=(long long)(n); i++)

using namespace std;

/*
long long rec(long long i, long long j) {
    if (dp[i][j] > -1) {
        return dp[i][j]; 
    }

    long long res;
    if (i == N) {
        res = 0;
    } else if (j < w[i]) {
        res = rec(i+1, j);
    } else {
        res = max(rec(i+1, j), rec(i+1, j-w[i]) + v[i]);
    }

    return dp[i][j] = res;
}
*/

int main(){
    long long N, W;
    cin >> N >> W;
    vector<int> w(N);
    vector<int> v(N);
    vector<vector<long> > dp(N+1, vector<long>(W+1, 0));

    rep(i, 0, N) {
        cin >> w[i] >> v[i];
    }

    rep(i, 1, N+1) {
        rep(j, 0, W+1) {
            if (j - w[i-1] >= 0) dp[i][j] = max(dp[i-1][j], dp[i-1][j - w[i-1]] + v[i-1]);             
            else dp[i][j] = dp[i-1][j];
        }
    }

    long long ans = dp[N][W];
    cout << ans << endl;

    return 0;
}



Measured memory_bytes: 80256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);

		while(true){
			int n = sc.nextInt();

			if(n == 0){
				break;
			}

			char[][] input = new char[n][];
			for(int i = 0; i < n; i++){
				input[i] = sc.next().toCharArray();
			}

			for(int i = 0; i < n; i++){
				for(int j = input[i].length - 1; j >= 0; j--){
					if(input[i][j] == '.'){
						input[i][j] = '+';
						break;
					}
				}
			}

			//debug
//			for(int i = 0; i < n; i++){
//				System.out.println(input[i]);
//			}

			for(int i = n - 1; i >= 0; i--){
				for(int j = 0; j < input[i].length; j++){
					if(input[i][j] == '+'){
						for(int k = i - 1; k >= 0; k--){
							if(input[k][j] >= 'a' && input[k][j] <= 'z'){
								break;
							}
							if(input[k][j] == '+'){
								for(int l = k + 1; l < i; l++){
									input[l][j] = '|';
								}
								break;
							}
						}

						break;
					}
				}
			}

			for(int i = 0; i < n; i++){
				for(int j = 0; j < input[i].length; j++){
					if(input[i][j] == '.'){
						input[i][j] = ' ';
					}
				}
			}

			for(int i = 0; i < n; i++){
				System.out.println(input[i]);
			}
		}
	}

}



Measured memory_bytes: 83980
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <assert.h>
#include <numeric>

using namespace std;
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
typedef long long ll;

ll dp[1002][1002][8];
int N, M;
/*
 3 3
 1 1 -2
 1 -2 1
 -2 1 1
 */

void dodp(ll score, int i, int k) {
    if (i == 0) {
        dp[i+1][1][k] = score;
    }else {
        dp[i+1][1][k] = max(dp[i+0][1][k], score);
    }
    
    
    REP(j, M+1) {
        if (j > 1) {
            if (j == i+1) {
                dp[i+1][j][k] = dp[i][j-1][k]+score;
            }else {
                dp[i+1][j][k] = max(dp[i][j][k], dp[i][j-1][k]+score);
            }
            
        }
        //cout << i << ", " <<  j << ", " << dp[i+1][j][k] << endl;
        
    }
}
ll solve() {
    
    cin >> N >> M;
    ll ans = 0;
    REP(i, N) {
        ll x, y, z;
        cin >> x >> y >> z;
        
        dodp( x+y+z, i, 0);
        dodp(-x+y+z, i, 1);
        dodp( x-y+z, i, 2);
        dodp( x+y-z, i, 3);
        dodp(-x-y+z, i, 4);
        dodp(-x+y-z, i, 5);
        dodp( x-y-z, i, 6);
        dodp(-x-y-z, i, 7);
    }
    
    
    REP(k, 8) {
        ans = max(ans, dp[N][M][k]);
        //cout <<dp[N][M][k] << endl;
    }
    
    return ans;
}

int main() {
    cout << solve() << endl;
}


Measured memory_bytes: 62848
#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>;
using ull= unsigned long long;
const double pi=acos(-1);

//vector<int> s[2];
//vector<ull> u[2];
//const int N=500;
//int n;
//int d[N][N];

int main(){
  long double a,b,h,m;
  cin >>a>>b>>h>>m;
  //double a2,b2,h2,m2;
  //a2=(double)a;
  //b2=(
  double alpha=2*pi/12*(h+m/60);
  double beta=2*pi*m/60;
  double c=sqrt(a*a+b*b-2*a*b*cos(alpha-beta));
  cout <<setprecision(20)<<c<<endl;
}


Measured memory_bytes: 4132
#include <bits/stdc++.h>
using namespace std;
#define iter(i, a, b) for(int i=(a); i<(b); i++)
#define rep(i, a) iter(i, 0, a)
#define rep1(i, a) iter(i, 1, (a)+1)
#define log(a) cerr<<"\033[32m[DEBUG] "<<#a<<'='<<(a)<<" @ line "<<__LINE__<<"\033[0m"<<endl
#define all(a) a.begin(), a.end()
#define fi first
#define se second
#define pb push_back
#define mp make_pair
using ll=long long;
using pii=pair<int, int>;
//#define int ll
const int MOD=1000000007;
signed main() {
    ios_base::sync_with_stdio(false); cin.tie(0);
    int N, K; cin >> N >> K;
	vector<int> v;
	rep(i, N) { int t; cin >> t; v.pb(t); }
	sort(all(v));
	ll ans = 0;
	rep(i, N-K) ans += v[i];
	cout << ans << endl;
}

Measured memory_bytes: 4252
import math, cmath
 
def koch(p1, p2, n):
    if n == 0:
        return [p1, p2]
     
    rad60 = math.pi/3
    v1 = (p2 - p1)/3
    v2 = cmath.rect(abs(v1), cmath.phase(v1)+rad60)
    q1 = p1 + v1
    q2 = q1 + v2
    q3 = q1 + v1
    if n == 1:
        return [p1,q1,q2,q3,p2]
    else:
        x1 = koch(p1,q1,n-1)[:-1]
        x2 = koch(q1,q2,n-1)[:-1]
        x3 = koch(q2,q3,n-1)[:-1]
        x4 = koch(q3,p2,n-1)
        x = x1 + x2 + x3 + x4
    return x
 
n = int(raw_input())
p1 = complex(0,0)
p2 = complex(100,0)
 
for e in koch(p1,p2,n):
    print e.real,e.imag

Measured memory_bytes: 7000
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<stack>
typedef long long int LL;
using namespace std;
int main()
{
    LL N,cnt=0;
    char S[100010];
    stack<char> text;
    scanf("%s",S);
    N=strlen(S);
    for(int i=0;i<N;i++)
    {
        if(text.empty()||text.top()==S[i])
            text.push(S[i]);
        else
        {
            text.pop();
            cnt+=2;
        }
    }
    printf("%lld\n",cnt);
    return 0;
}


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

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

int main(){
  cin.tie(nullptr);ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(15);
  int n;cin>>n;
  vector<int> hoge(n);
  rep(i,n)cin>>hoge[i];
  sort(all(hoge));
  cout<<hoge[n-1]-hoge[0]<<endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define LLI long long int
#define ULTRA 2134567890
#define de(x) if(x!=0 && MODE==x)
#define MODE 1
using namespace std;


vector<LLI> h;

int main()
{
    int i,j;
    int N,K;

    scanf("%d %d", &N, &K);
    for( i=0; i<N; i++)
    {
        LLI a;
        scanf("%lld", &a);
        h.push_back(a);
    }

    LLI ans = 0LL;
    if( K < N)
    {
        sort( h.begin(), h.end() );
        for( i=0; i<N-K; i++)
            ans += h[i];
    }
    printf("%lld\n", ans);

    return 0;
}

//
//          ___ ___  __________  __________
//         /////\  \/\   ______\/\\\\\\\\\\\  Code by ~Ice Tea~ of
//        //// \ \  \ \  \_____/\ \\\\_____/      New Empire of CHSH ...
//       ////   \ \  \ \  \      \ \\\\\\\\\\\
//      ////__   \ \  \ \  \      \ \\\\_____/
//     ///////\   \ \  \ \  \______\ \\\\_______   ________
//    ////____/    \ \__\ \___   ___\ \\\\\\\\\\\ _\  ___  \_
//   /__/           \/__/\/__/\  \__/\ \\\\_____//\  .\_/\_  \
//                           \ \  \   \ \\\\\\\\\\\\  \_\/_\  \
// ... with the AC Power of   \ \  \   \ \\\\_____/ \   _____  \
//   The Great Tsundere Doggy. \ \  \   \ \\\\     \ \  \  \ \  \
//                              \ \__\   \ \\\\\\\\\\ \__\  \ \__\
//                               \/__/    \/________/\/__/   \/__/
//


Measured memory_bytes: 2420
cnt = 0
def merge(a, left, mid, right):
    global cnt
    l = 0
    l_e = mid - left
    r = 0
    r_e = right - mid - 1

    L = a[left:mid + 1]
    R = a[mid + 1:right + 1]
    csr = left
    while l <= l_e and r <= r_e:
        cnt += 1
        if L[l] < R[r]:
            a[csr] = L[l]
            l += 1
        else:
            a[csr] = R[r]
            r += 1
        csr += 1
    if l == l_e + 1:
        while r <= r_e:
            a[csr] = R[r]
            r += 1
            csr += 1
            cnt += 1
    else:
        while l <= l_e:
            a[csr] = L[l]
            l += 1
            csr += 1
            cnt += 1

def merge_sort(a, l, r):
    mid = (l + r) // 2
    if l < r:
        merge_sort(a, l, mid)
    if l + 1 < r:
        merge_sort(a, mid + 1, r)
    if l < r:
        merge(a, l, mid, r)


n = int(input())
a = [int(i) for i in input().split()]
merge_sort(a, 0, n - 1)
print(' '.join(map(str, a)))
print(cnt)



Measured memory_bytes: 66724
#include<bits/stdc++.h>
#define watch(x) cout << (#x) << " is " << (x) << endl
typedef long long ll;
using namespace std;
int static fast = [](){
  ios::sync_with_stdio(false);
  cin.tie(0); cout.tie(0); return 0;
}();
// freopen("input.txt", "r", stdin);


int main() {
    int h, n, hp, mp;
    cin >> h >> n;
    vector<ll> cost(20003, INT_MAX);
    cost[0] = 0;
    for(int i = 0; i < n; i++) {
        cin >> hp >> mp;
        for(int j = hp; j <= 20002; j++) {
            cost[j] = min(cost[j], cost[j-hp]+mp);
        }
        /*
        for(int j = h; j >= 0; j--) {
            for(int k = 1; k <= 1+(j-1)/hp; k++) {
                cost[j] = min(cost[j], cost[max(0, j-k*hp)] + mp*k);
            }
        }
        */
    }
    ll ans = INT_MAX;
    for(int i = h; i <= 20002; i++)
        ans = min(ans, cost[i]);
    cout << ans << endl;

    return 0;
}



Measured memory_bytes: 512
#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 reps(i, n) for (int i = 1; i <= (n); i++)
#define repi(i, a, b) for (int i = (a); i < (b); i++)
#define all(a) (a).begin(), (a).end()
#define bit(b) (1ull << (b))

using namespace std;
using i32 = long long;
using u32 = unsigned long long;
using i64 = long long;
using u64 = unsigned long long;
using f64 = double;
using vi32 = vector<i32>;
using vu32 = vector<u32>;
using vi64 = vector<i64>;
using vu64 = vector<u64>;
using vf64 = vector<f64>;
using vstr = vector<string>;
using vvi32 = vector<vi32>;
using vvu32 = vector<vu32>;
using vvi64 = vector<vi64>;
using vvu64 = vector<vu64>;
using vvf64 = vector<vf64>;

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

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout << fixed << setprecision(16);
  int n;
  cin >> n;
  vi32 l(n * 2);
  rep(i, n * 2) cin >> l[i];
  sort(all(l));
  int sum = 0;
  rep(i, n * 2) if (i % 2 == 0) sum += l[i];
  cout << sum << endl;
  return 0;
}

Measured memory_bytes: 256
#include<deque>
#include<list>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<vector>
#include<algorithm>
#include<string>
#include<iostream>
#include<sstream>
#include<cmath>
#include<cstring>
using namespace std;
int a[10][10],b[10][10],c[21],d[21],n,m;
int mx;
void fn(int p,int q,int r){
  int h=1,i;
  for(i=0;i<n;i++){
    if(a[q][i]&&b[q][i]){
      b[q][i]=b[i][q]=0;
      c[p]=i;
      fn(p+1,i,r+a[q][i]);
      b[q][i]=b[i][q]=-1;
      h=0;
    }
  }
  if(h){
    if(mx<r){
      mx=r;
      c[p]=-1;
      memcpy(d,c,sizeof(d));
    }
  }
  return;
}
int main(){
  int i;
  memset(b,-1,sizeof(b));
  while(cin>>n>>m,n||m){
    memset(a,0,sizeof(a));
    for(i=0;i<m;i++){
      int p,q,r;
      cin>>p>>q>>r;
      p--;
      q--;
      a[p][q]=a[q][p]=r;
    }
    mx=0;
    for(i=0;i<n;i++){
      c[0]=i;
      fn(1,i,0);
    }
    cout<<mx<<endl;
    for(i=0;d[i+1]!=-1;i++)
      cout<<d[i]+1<<" ";
    cout<<d[i]+1<<endl;
  }
  return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
#define s second
#define f first
#define pb push_back
#define endl '\n'
using namespace std;


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

const int INF = 0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3f3fLL;

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

	int T;
	cin >> T;

	cout << (ll)T*(T + 1)/2ll << endl;

	return 0;
}


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

using ll = long long int;

const int MAX = (int)(1e5 + 5);
const ll INF = (ll)(1e10 + 5);

const int MAX_N = (int)(1e3 + 5);

int n, m;
ll x[MAX_N];
ll y[MAX_N];
ll z[MAX_N];

ll d[2] = {-1LL, 1LL};

ll ans;

ll calc(vector<ll> &cur) {
  sort(cur.begin(), cur.end(), greater<ll>());
  
  ll ret = 0LL;

  for (int i = 0; i < m; ++i) {
    ret += cur[i];
  }

  return ret;
}

int main(void) {
  // Here your code !
  scanf("%d %d", &n, &m);

  for (int i = 0; i < n; ++i) {
    scanf("%lld %lld %lld", &(x[i]), &(y[i]), &(z[i]));
  }

  ans = -1LL;

  for (int i = 0; i < 2; ++i) {
    for (int j = 0; j < 2; ++j) {
      for (int k = 0; k < 2; ++k) {
        vector<ll> cur;

        for (int l = 0; l < n; ++l) {
          cur.push_back(d[i] * x[l] + d[j] * y[l] + d[k] * z[l]);
        }

        ans = max(ans, calc(cur));
      }
    }
  }

  printf("%lld\n", ans);

  return 0;
}


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

template<typename T>
void out(T x) { cout << x << endl; exit(0); }
#define watch(x) cout << (#x) << " is " << (x) << endl





using ll = long long;

const ll mod = 1e9+7;
const int maxn = 1e6 + 5;





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


    ll lo=100;
    ll hi=105;

    ll x;
    cin>>x;

    while (hi<x) {
	lo+=100;
	hi+=105;
    }

    cout<<(lo<=x && x<=hi)<<endl;
    return 0;
}


Measured memory_bytes: 3656
#include <bits/stdc++.h>
#include <algorithm>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#include <iostream>
#include <vector>
#include <cstdlib>
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
using ll = long long;
using namespace std;


    long long a[100010][3];
    long long dp[100010][3];
int main() {
    int n;
    cin >> n;
    
    
    for(int i = 0;i <n;i++) {
        for(int j = 0;j<3;j++){
         cin >>a[i][j];
        }
    }
    
    for(int i = 0;i<n;i++) {
     for(int j =0;j<3;j++){
      for(int k =0;k<3;k++){
       if(j==k){
           continue;
               }
          chmax(dp[i+1][k],dp[i][j]+a[i][k]);
      }
     }
    }
    
    long long res = 0;
    for(int j = 0;j <3; j++) {
     chmax(res,dp[n][j]);
    }
    cout << res;
}

Measured memory_bytes: 8292
#include <iostream>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <unordered_map>
#include <random>
#include <queue>

#define BIG 998244353
#define LLMAX 9223372036854775807
#define LLMIN (-9223372036854775808)
#define long long long

using namespace std;


int main() {
    int r,g,b,n;
    cin >> r >> g >> b >> n;
    int rr = 0;
    int gg = 0;
    int c = 0;
    while (rr <= n){
        while(rr + gg <= n){
            if((n - rr - gg) % b == 0)++c;
            gg += g;
        }
        gg = 0;
        rr += r;
    }
    cout << c << endl;
}




Measured memory_bytes: 888
#include<iostream>
#include<string>
using namespace std;
int k;
char c;
string s;
int main()
{
	cin>>k;
	for(int i=1;i<=k;i++)
	{
		cin>>c;
		if(c!=s[s.length()-1])s+=c;
	}
	cout<<s.length();
	return 0;
}

Measured memory_bytes: 512
#include <iostream>
#include <vector>
#define rep(i,n) for(int i=0;i<(n);++i)
using namespace std;

int main() {
	int n;cin >> n;
	vector<int> arr(n);
	rep(i,n) cin >> arr[i];
	
	rep(i,n){
		if(i != n - 1) cout << arr[i] << ' ';
		else cout << arr[i] << endl;;
	}
	
	for(int i = 1; i< n; ++i){
		int v = arr[i];
		int j = i - 1;
		while(j >= 0 && arr[j] > v){
			arr[j + 1] = arr[j];
			j--;
		}
		arr[j + 1] = v;
		rep(k,n){
			if(k != n - 1) cout << arr[k] << ' ';
			else cout << arr[k] << endl;
		}
	}
	return 0;
}


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

using namespace std;
#define all(a)a.begin(),a.end()
using ll=long long;
const int INF = 1<<30;
const ll INFll =1LL<<62;
const int mod= int(1e9)+7;
using P = pair<ll,ll>;
using ld=long double;

int main(){
    ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    vector<int>c;
    int d;vector<vector<int>>s;
    vector<int>last;
    auto calc=[&](int t,int day){
        int k=0;
        k+=s[day][t];
        for (int j = 0; j < 26; ++j){
            if(j==t)continue;
            else  k-=c[j]*(day+1-last[j]);
        }
        return k;
    };
    cin >>d;
    c.resize(26);
    for (int i = 0; i <26; ++i) cin >>c[i];
    s.assign(d,vector<int>(26));
    for (int i = 0; i < d; ++i)for (int j = 0; j < 26; ++j) cin >>s[i][j];
    int score=0;
    last.assign(26,0);
    vector<int>t(d);
    vector<P>p(d);
    for (int day = 0; day < d; ++day) {
        int now=-INF,now2=-INF;int d=INF;
        for (int i = 0; i < 26; ++i) {
//            if(day==4&&i==19){
//                cout <<now<<" "<<calc(i,day)<<" "<<endl;
//            }
           if(now<calc(i,day)){
               now=calc(i,day);
               t[day]=i+1;
               p[day].first=i+1;
           }
           else if(now2<calc(i,day)){
               now2=calc(i,day);
               p[day].second=i+1;
           }
        }
        last[t[day]-1]=day+1;
        score+=now;
//        cout <<score<<endl;
    }
    vector<int>copy(d);
    vector<int>lcopy(d);
    auto ucalc=[&](){
        int kk=0;
        for (int i = 0; i < d; ++i) {
            kk+=s[i][copy[i]];
            lcopy[copy[i]]=i+1;
            for (int j = 0; j < 26; ++j)score-=c[j]*(i+1-lcopy[j]);
            return kk;
        }
    };
    for (int i = 0; i < 1 << 16; ++i) {
        copy=t;lcopy=last;
        for (int j =0; j <16; ++j) {
            int k=d-j-1;
            if((1>>j)&1){
                copy[k]=p[k].second;
            }
        }
        if(score<ucalc()) {
            score = ucalc();
            t=copy;
            for (int i = 0; i < last.size(); ++i) {
                last[i]=lcopy[i];
            }

        }
    }
    for (int i = 0; i < d; ++i) {
        cout<<t[i]<<endl;
    }
//    for (int i = 0; i < 26; ++i) {
//        cout <<last[i]<<endl;
//    }
//    cout <<score<<endl;
    return 0;
}

Measured memory_bytes: 3736
#include <bits/stdc++.h>
#pragma GCC optimize(2)
using namespace std;

typedef unsigned long long ull;

inline ull in()
{
	ull ret = 0, w = 0;
	char ch;
	while (!isdigit(ch))
	{
		w |= (ch == '-');
		ch = getchar();
	}
	while (isdigit(ch))
	{
		ret = (ret << 3) + (ret << 1) + (ch ^ 48);
		ch = getchar();
	}
	return w ? -ret : ret;
}

inline void out(ull x)
{
	if (x < 0)
	{
		putchar('-');
		x = -x;
	}
	if (x > 9)
		out(x / 10);
	putchar(x % 10 + 48);
}

int main()
{
  
  double n, x;
  cin >> n;
  double all = 0;
  while (n--)
  {
  	cin >> x;
  	all += (double)(1 / x);
	}
	double ans = (double)(1 / all);
	cout << fixed << setprecision(5) << ans << endl;
	  
  return 0;
  
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
const int N=1e5+5;

int main(){
    ll a,b,v,w,t;cin>>a>>v>>b>>w>>t;
    if(abs(a-b)>t*(v-w))
        cout<<"NO"<<endl;
    else
        cout<<"YES"<<endl;
    return 0;
}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
#define in_range(x, y, r, c) (x < r && y < c && x >= 0 && y >= 0)
using namespace std;
const int mod = 1e9+7;
bool no[100100];
int memo[100100];

int ups(int v){
	if (v == 0) return 1;
	if (v < 1) return 0;
	if (no[v]) return 0;
	if (memo[v] != -1) return memo[v];
	return memo[v] = (ups(v-1) + ups(v-2))%mod;
}

int main(){
	int n, m, aux;
	cin >> n >> m;
	memset(no, false, sizeof no);
	memset(memo, -1, sizeof memo);
	for (int i=0; i<m; i++){
		cin >> aux;
		no[aux] = true;
	}
	cout << ups(n) << endl;
    return 0;
}

Measured memory_bytes: 3840
#include <iostream>
#include <iomanip>
#include <string>
#include <sstream>
#include <bitset>
#include <algorithm>
#include <cmath>
#include <numeric>
#include <utility>
#include <set>
#include <map>
#include <tuple> 
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <list>
using namespace  std;
typedef pair<long long , long long> P;
typedef long long ll;
typedef long long lint;
#define REP(i, n) for(long long (i)=0; (i)<(n); ++i)
#define FOR(i, a, b) for(long long (i)=(a); (i)<(b); ++i)
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
const long long MOD = static_cast<long long>(1e9) + 7LL;
const long long INF = 1234567891234567890LL;

vector<vector<ll>> G;
vector<ll> dist;
vector<ll> used;
ll N, M;
void init(ll n){
    G.resize(3*n);
    dist.resize(3*n, INF);
    used.resize(3*n, 0);
}

void dijkstra(ll s){
    priority_queue<P> pq;
    pq.push(P(0, s));
    while(pq.size()){
        P p = pq.top(); pq.pop();
        ll d = p.first;
        ll v = p.second;
        if(used[v]) continue;
        used[v] = 1;
        for(ll i=0; i<G[v].size(); i++){
            ll nv = G[v][i];
            if(used[nv])continue;
            if(dist[nv]==INF or dist[nv]> dist[v]+1){
                    dist[nv] = dist[v] + 1;
                    pq.push(P(dist[nv], nv));
            }
        }
    }
}

void bfs(ll s){
    queue<ll> q;
    q.push(s);
    while(q.size()){
        ll v = q.front(); q.pop();
        if(used[v]) continue;
        used[v] = 1;
        for(ll i=0; i<G[v].size(); i++){
            ll nv = G[v][i];
            if(used[nv]) continue;
            q.push(nv); 
            dist[nv] = dist[v] + 1;
        }
    }
}

signed main(){
    cin>>N>>M;
    init(N);
    REP(i, M){
        ll u, v;cin>>u>>v;
        u--,v--;
        REP(j, 3){
            G[j*N+u].push_back(((j+1)%3)*N+v);
        }
    }
    ll S, T; cin >> S >> T;
    S--, T--;
    dist[0*N+S] = 0;
    bfs(S);
    if(dist[0*N+T]==INF) cout<<-1<<endl;
    else cout << dist[T]/3 << endl;
    return 0;
}

Measured memory_bytes: 21376
#include<bits/stdc++.h>
#define maxn 100010
using namespace std;
int id[maxn], cnt, res[maxn], c[maxn], head[maxn], nxt[maxn], a[maxn], edge;
void create(int u, int v)
{
	edge++; a[edge] = v; nxt[edge] = head[u]; head[u] = edge;
}
void dfs(int u, int fa)
{
	for (int i = head[u]; i; i = nxt[i])
	{
		int v = a[i];
		if (v != fa) dfs(v, u);
	}
	id[++cnt] = u;
}
int main()
{
	int n;
	scanf("%d", &n);
	for (int i = 1; i <= n - 1; i++)
	{
		int u, v;
		scanf("%d%d", &u, &v);
		create(u, v); create(v, u);
	}
	for (int i = 1; i <= n; i++)
		scanf("%d", &c[i]);
	dfs(1, 0);
	int sum = 0;
	sort(c + 1, c + n + 1);
	for (int i = 1; i <= n; i++)
	{
		if (i != n) sum += c[i];
		res[id[i]] = c[i];
	}
	printf("%d\n", sum);
	for (int i = 1; i <= n; i++)
		printf("%d ", res[i]);
	puts("");
	return 0;
}

Measured memory_bytes: 896
#include<bits/stdc++.h>
    using namespace std;
    typedef long long ll;
    //--<for debugging>
    #define whatis(x) cout << #x << " is " << x<<" ";
    #define whatisl(x) cout << #x << " is " << x<<"\n";
    #define parr(array,end)for(ll loop=0;loop<end;loop++)cout<<array[loop]<<" ";cout<<"\n";
    #define lline cout<<"\n";
    #define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args);cout<<"\n";}
     
    void err(istream_iterator<string> it) {}
    template<typename T, typename... Args>
    void err(istream_iterator<string> it, T a, Args... args) {
    	cout << *it << " = " << a <<" , ";
    	err(++it, args...);
    }
    //--</for debugging> 
    #define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
    #define testcase ll tt; cin >> tt; while(tt--)
    #define cina ll num,loop;cin>>num;ll a[num];rep(loop,0,num)cin>>a[loop];
    #define boost ios_base::sync_with_stdio(false);cin.tie(NULL);
    #define pb push_back 
    #define vars ll h,i,j,k,d,l,r,x,y,b,c,v,var,n,m,z,s,ans,ind1,ind2,flag,limit1,limit2,limit3,mod;
    #define vll vector<ll>
    #define pll pair<ll,ll>
    #define sll set<ll>
    #define pint pair<int,int>
    const ll INF=1e9+7;
    const ll MOD=1e9+7;
    int main()
    {
        boost vars 
        cin>>n;
        cout<<1000*(n/500)+5*((n%500)/5);
    }

Measured memory_bytes: 768
import java.util.*;
public class Main {
 
  public static void main(String[] args) {
    Scanner sc=new Scanner(System.in);
  	int N = sc.nextInt();
  	int[] T = new int[N];
  	for(int i=0 ; i < N ; i++){
  		T[i] = sc.nextInt();
  	}
  	int M = sc.nextInt();
  	int[][] PM = new int[M][2];
  	for(int i=0 ; i < M ; i++){
		PM[i][0]= sc.nextInt();
  		PM[i][1]= sc.nextInt();
  	}
 
    
  	for(int i=0 ; i < M ; i++){
  		int ans=0;
  		for(int j=0 ; j < N ; j++){
  			if(PM[i][0]==j+1){
  				ans +=PM[i][1];
  			}else{
  				ans +=T[j];
  			}
  		}
  		System.out.println(ans);
  	}
    
  }
}

Measured memory_bytes: 21716
#include<stdio.h>

int prime();

int num,a[100][100];

int main(){

  int i,j,e,sum;
  
  scanf("%d",&num);

  for(i = 0; i < num; i++){
    for(j = 0; j < num; j++){
      scanf("%d",&e);
      if(e == -1)a[i][j] = 100000;
      else a[i][j] = e;
    }
  }
  sum = prime();
  printf("%d\n",sum);
  return 0;
}


int prime(){

  int u,minv,i,v;
  int d[100],p[100],color[100];

  for(i = 0; i < num; i++){
    d[i] = 100000;
    p[i] = -1;
    color[i] = 0;
  }

  d[0] =0;

  while(1){
    minv = 100000;
    u = -1;
    for(i = 0; i < num; i++){
      if(minv > d[i] && color[i] != 2){
	u = i;
	minv = d[i];
      }
    }

    if(u == -1)break;
    color[u] =2;
    for(v = 0; v < num; v++){
      if(color[v] != 2 && a[u][v] != 100000){
	if(d[v] > a[u][v]){
	  d[v] = a[u][v];
	  p[v] = u;
	  color[v] = 1;
	}
      }
    }
  }
    int sum = 0;
    for (i = 0; i < num; i++){
      if(p[i] != -1)sum += a[i][p[i]];
    }

  
    return sum;
  
}

Measured memory_bytes: 636
#include <bits/stdc++.h>
#ifdef DEBUG
  #include "debug.hpp"
#else
  #define DUMP(var)
#endif

using namespace std;
template< class T1, class T2 > inline istream &
operator>>( istream & fin, pair< T1, T2 > & pr )
{ fin >> pr.first >> pr.second; return fin; }
template< class T0, class T1, class T2 > inline istream &
operator>>( istream & fin, tuple< T0, T1, T2 > & t )
{ fin >> get<0>(t) >> get<1>(t) >> get<2>(t); return fin; }
template< class T > inline istream &
operator>>( istream & fin, vector< T > & a ) {
for(auto & u: a) fin >> u; return fin; }
template<class T, size_t n> inline istream &
operator>>( istream & fin, array<T, n> & a ) {
for(auto & u: a) fin >> u; return fin; }
template<class FwdIter> inline auto
dump(FwdIter first, FwdIter last, const char * dlm = " ") -> void {
using value_type = typename iterator_traits<FwdIter>::value_type;
copy(first, last, ostream_iterator<value_type>(cout, dlm)); }
template<typename T> vector<T> & operator--(vector<T> & a)
{ for(auto & i: a) --i; return a; }
/* @@@ ----------------------------------- */


int main(const int /*argc*/, char ** /*argv*/) {
  ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);

  size_t n;
  cin >> n;
  vector<int> a(n - 1);
  cin >> a;

  int out = a.front() + a.back();
  for (int i = 1; i + 1 < n; ++i) {
    out += min(a[i - 1], a[i]);
  }

  cout << out;

  return EXIT_SUCCESS;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
#define rep(i,n) for((i)=0;(i)<(n);(i)++)
template<class T,class C> T max(T a,C b){ return ((a)>(T)(b) ? (a) : (T)(b)); }
template<class T,class C> T min(T a,C b){ return ((a)<(T)(b) ? (a) : (T)(b)); }
typedef long long ll;
typedef long double ld;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
int main(){
  ll n,m,k,i,j,result=0;
  ll a,b,c,d;
  string s;
  
  cin >> a >> b >> c >> d;
  
  result = a*c;
  result = max(result,a*d);
  result = max(result,b*c);
  result = max(result,b*d);
  
  cout << result << endl;
  return 0;
}


Measured memory_bytes: 3624
#include <cstdio>
#include <utility>
#include <algorithm>

using namespace std;
class UnionFind {
private:
  static const int UF_MAX_N = 200010;
  int parent[UF_MAX_N];
  int rank[UF_MAX_N];
  int N;
public:
  void init(int n) {
    N=n;
    for(int i=0;i<n;++i) {
      parent[i] = i;
      rank[i]=0;
    }
  }

  int getRoot(int x){
    if (parent[x] == x) {
      return x;
    } else {
      return parent[x] = getRoot(parent[x]);
    }
  }

  void unite(int x, int y) {
    x = getRoot(x);
    y = getRoot(y);
    if ( x==y) return;

    if(rank[x] < rank[y]) {
      parent[x] = y;
    } else {
      parent[y] = x;
      if(rank[x] == rank[y]) rank[x]++;
    }
  }

  bool same(int x, int y) {
    return getRoot(x) == getRoot(y);
  }
};

UnionFind uf;

int main() {
  int N,M;
  scanf("%d%d", &N, &M);
  uf.init(N);
  for(int i=0;i<M;++i) {
    int a,b;
    scanf("%d%d", &a, &b);
    if(a==1) {
      uf.unite(a-1,b-1);
    } else if(b==N) {
      uf.unite(a-1,b-1);
    }
  }

  if(uf.same(0, N-1)) {
    printf("POSSIBLE\n");
  } else {
    printf("IMPOSSIBLE\n");
  }

  return 0;
}


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

int main()
{
    int A, B, C, D;
    cin >> A >> B >> C >> D;
    bool pressing[2][110] = {0};
    fill(&pressing[0][A], &pressing[0][B], 1);
    fill(&pressing[1][C], &pressing[1][D], 1);
    int ans = 0;
    REP(i, 110) if(pressing[0][i] && pressing[1][i]) ans++;
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
using System;
using System.Linq;
using static System.Console;

public static class Program
{
    public static void Main()
    {
        var line = ReadLine().Split(' ').Select(int.Parse).ToArray();
        int count = 0;
        for(int i = 0; i < line[0]; ++i)
        {
            var xy = ReadLine().Split(' ').Select(int.Parse).ToArray();
            if ((long)xy[0] * xy[0] + (long)xy[1] * xy[1] <= (long)line[1] * line[1]) ++count;
        }
        WriteLine(count);
    }
}

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

using namespace std;

int main()
{
  int N, M;
  scanf("%d %d", &N, &M);
  priority_queue<int> pq;
  
  for (int i = 0; i < N; i++) {
    int a;
    scanf("%d", &a);
    pq.push(a);
  }
  
  for (int i = 0; i < M; i++) {
    int a = pq.top(); pq.pop();
    pq.push(a / 2);
  }
  
  long long ans = 0;
  for (int i = 0; i < N; i++) {
    ans += pq.top(); pq.pop();
  }
  
  printf("%lld\n", ans);
  
  return 0;
}

Measured memory_bytes: 892
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <string>
#include <vector>
#include <set>
#include <stack>
using namespace std;

int sum_index(int n)
{
    int sum = 0;
    while (n > 0) {
        sum += n % 10;
        n /= 10;
    }
    return sum;
}

int main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
    int n, a, b;
    cin >> n >> a >> b;

    int sum = 0;
    for (int i = 1; i <= n; i++) {
        if (sum_index(i) >= a && sum_index(i) <= b) {
            sum += i;
        }
    }
    cout << sum << endl;
	return 0;
}

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

int main(){
  int n;
  cin >> n;
  int a[n];
  for(int i=0; i<n; i++){
    cin >> a[i];
  }

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

Measured memory_bytes: 3084
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<queue>

using namespace std;

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

    for (int i = 0 ; i<S.size() ; i++) {
        if (S.substr(i, 1) == "1" && K != i+1) {
            continue;
        } else if (S.substr(i, 1) == "1" && K == i+1) {
            cout<<S.substr(i, 1)<<endl;
            break;
        } else if (S.substr(i, 1) != "1") {
            cout<<S.substr(i, 1)<<endl;
            break;
        }
    }
    
    return 0;
}


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

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

    if (s[1] != 'R')
    {
        if (s[0] == 'R' || s[2] == 'R')
        {
            cout << 1 << "\n";
        }
        else
        {
            cout << 0 << "\n";
        }
    }
    else
    {
        int ans = 0;
        for (int i = 0; i < 3; i++)
        {
            if (s[i] == 'R') ans++;
        }
        cout << ans << "\n";
    }
}

Measured memory_bytes: 3592
#!/usr/bin/env python3
import sys


def solve(N: int, M: int, A: "List[int]"):
    play = N - sum(A)
    if play > -1:
        print(play)
    else:
        print(-1)


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    M = int(next(tokens))  # type: int
    A = [int(next(tokens)) for _ in range(M)]  # type: "List[int]"
    solve(N, M, A)

if __name__ == '__main__':
    main()


Measured memory_bytes: 10136