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

using namespace std;

const int N = 1e5 + 7 , mod = 1e9 + 7 ;

long long n ; 
long long x[N] ; 
long long a[N] ;

int main()
{
        ios_base::sync_with_stdio(0);
        cin.tie(0);
//        freopen("in.in" , "r" , stdin) ; 
        cin>>n ; 
        long long a[n+1] ; 
        long long ans = 0 , mx = 1 ;      
        long long rem = 0 ;   
        for(int i = 0 ;i <=n;i++){
                long long t ; 
                cin>>a[i] ; 
                rem+=a[i] ; 
        }
        x[n] = a[n] ; 
        for(int i = n ; i ; i--)
                x[i-1] = a[i-1] +  x[i] ; 
        for(int i = 0 ; i <=n;i++){
                long long t = a[i] ; 
                if(t > mx){
                        return cout<<-1,0 ; 
                }
                long long all = min(mx  , rem); 
                mx-=a[i] ; 
                ans+=all ;
                mx*=2 ;   
                if(mx > 1e15)
                        mx = 1e15 ; 
                rem-=a[i] ; 
        }
        cout<< ans ; 
        return 0;
}


Measured memory_bytes: 5120
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef pair<ll,ll> P;
typedef string str;
typedef vector<P> vp;
typedef vector<string> vs;
typedef vector<bool> vb;

const ll mod=1e9+7;
const ll inf=1e18;

#define rep(i,m,n) for(ll i=m;i<n;i++)
#define repr(i,m,n) for(ll i=m-1;i>=n;i--)
#define fi first
#define se second
#define chmax(x,y) x=max(x,y)
#define chmin(x,y) x=min(x,y)
#define eb(x) emplace_back(x)
#define pb(x) pop_back(x)
#define all(x) x.begin(),x.end()
#define allr(x) x.rbegin(),x.rend()
#define sum(x) accumulate(all(x),0)
#define pc(x) __builtin_popcount(x)
#define gll greater<ll>()

struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  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 { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= 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 { return mint(*this) /= a;}
};
istream& operator>>(istream& is, mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}
 
const ll nmax=1000000;


ll fac[nmax],finv[nmax],inv[nmax];

void comint(){
 fac[0]=fac[1]=1;
 finv[0]=finv[1]=1;
 inv[1]=1;
 for(ll i=2;i<nmax;i++){
  fac[i]=fac[i-1]*i%mod;
  inv[i]=mod-inv[mod%i]*(mod/i)%mod;
  finv[i]=finv[i-1]*inv[i]%mod;
}
}

ll com(ll n, ll k){
 if(n<k||n<0||k<0) return 0;
 return fac[n]*(finv[k]*finv[n-k]%mod)%mod;
}

void solve(){
  ll n;
  cin >> n;
  vll x(n),y(n);
  vll p(n),q(n);
  rep(i,0,n) {
    cin >> x[i] >> y[i];
    p[i]=x[i]+y[i];
    q[i]=x[i]-y[i];
  }
  
  sort(all(p));
  sort(all(q));
  ll ans=p[n-1]-p[0];
  chmax(ans,q[n-1]-q[0]);
  
  cout << ans << endl;
}
int main(){
   cin.tie(nullptr);
  ios::sync_with_stdio(false);
  solve();
}


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

int main(){
  ll n,l[4000]; cin >>n;
  for(int i = 1; i<=n; i++) cin >>l[i];
  vector<ll> v(n);
  rep(i,n) v[i]=l[i+1];
  sort(v.begin(), v.end());
  ll ans = 0;
  for(ll mid = n-1; mid>=0; mid--){
    for(ll low = mid-1; low>=0; low--){
      auto itr = lower_bound(v.begin(), v.end(), v[mid]+v[low]);
      ll ng = distance(itr, v.end());
      ans += (n-1-mid)-ng;
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3612
package main

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

func main() {
	A := nextInt()
	B := nextInt()

	fmt.Println(A * B)
}

var stdin = initStdin()

func initStdin() *bufio.Scanner {
	bufsize := 1 * 1024 * 1024 // 1 MB
	var stdin = bufio.NewScanner(os.Stdin)
	stdin.Buffer(make([]byte, bufsize), bufsize)
	stdin.Split(bufio.ScanWords)
	return stdin
}

func nextString() string {
	stdin.Scan()
	return stdin.Text()
}

func nextBytes() []byte {
	stdin.Scan()
	return stdin.Bytes()
}

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

func nextInt64() int64 {
	i, _ := strconv.ParseInt(nextString(), 10, 64)
	return i
}


Measured memory_bytes: 1788
#include <bits/stdc++.h>
#define rep(i,n) for (ll i = 0; i < n; ++i)
#define sz(x) int(x.size())
#define ALL(c) (c).begin(), (c).end()
#define SUM(x) std::accumulate(ALL(x), 0LL)
#define MIN(v) *std::min_element(v.begin(), v.end())
#define MAX(v) *std::max_element(v.begin(), v.end())
#define EXIST(v, x) (std::find(v.begin(), v.end(), x) != v.end())
#define FORV(i, v) for (auto i = v.begin(); i != v.end(); i++)
using namespace std;

using ll = long long;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
const int INF = 1001001001;
const long long INFL = LLONG_MAX / 3;
const double eps = (1e-9);

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

  int a, b; cin >> a >> b;

  vector<string> ans;
  rep(i, 50) ans.emplace_back(100, '#');
  rep(i, 50) ans.emplace_back(100, '.');
  a--; b--;

  for (int i = 0; i < 50; i += 2) {
    for (int j = 0; j < 100; j += 2) {
      if (a > 0) {
        ans[i][j] = '.';
        a--;
      } else {
        break;
      }
    }
    if (a == 0) break;
  }

  for (int i = 51; i < 100; i += 2) {
    for (int j = 0; j < 100; j += 2) {
      if (b > 0) {
        ans[i][j] = '#';
        b--;
      } else {
        break;
      }
    }
    if (b == 0) break;
  }

  cout << 100 << " " << 100 << endl;
  for (auto& s : ans) {
    cout << s << endl;
  }

  return 0;
}


Measured memory_bytes: 256
n=int(input())
H=list(map(int,input().split()))
dp=[0]*n
dp[1]=abs(H[1]-H[0])
for i in range(n-2):
    dp[i+2]=min(dp[i]+abs(H[i+2]-H[i]),dp[i+1]+abs(H[i+2]-H[i+1]))
print(dp[n-1])

Measured memory_bytes: 20672
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <tuple>
#include <set>

using namespace std;

int main()
{
	int X, Y, Z, K;
	cin >> X >> Y >> Z >> K;
	vector<long long> A(X), B(Y), C(Z);

	for (auto &e : A) cin >> e;
	for (auto &e : B) cin >> e;
	for (auto &e : C) cin >> e;

	sort(A.rbegin(), A.rend());
	sort(B.rbegin(), B.rend());
	sort(C.rbegin(), C.rend());

	using state_t = tuple<long long, int, int, int>;
	set<state_t> visited;
	priority_queue<state_t> q;

	auto visit = [&](int a, int b, int c) {
		state_t s(A[a] + B[b] + C[c], a, b, c);
		if (visited.emplace(s).second) {
			q.emplace(s);
		}
	};
	visit(0, 0, 0);

	vector<long long> ans;
	while (ans.size() < K) {
		long long s;
		int a, b, c;
		tie(s, a, b, c) = q.top();
		q.pop();
		
		ans.push_back(s);

		if (a + 1 < X) visit(a + 1, b, c);
		if (b + 1 < Y) visit(a, b + 1, c);
		if (c + 1 < Z) visit(a, b, c + 1);
	}

	for (auto e : ans) {
		cout << e << endl;
	}
}


Measured memory_bytes: 896
#include<bits/stdc++.h>
using namespace std;
const int N=310;
int gi() {
    int x=0,o=1;char ch=getchar();
    while((ch<'0'||ch>'9')&&ch!='-') ch=getchar();
    if(ch=='-') o=-1,ch=getchar();
    while(ch>='0'&&ch<='9') x=x*10+ch-'0',ch=getchar();
    return x*o;
}
char s[N];
int n,k,f[N][N][N];
int main() {
    scanf("%s",s+1),n=strlen(s+1);
    k=gi();
    for(int l=n;l;l--)
        for(int r=l;r<=n;r++)
            for(int i=0;i<=k;i++) {
                if(l==r) f[l][r][i]=1;
                else if(l+1==r) f[l][r][i]=(i||s[l]==s[r])?2:1;
                else {
                    f[l][r][i]=max(f[l+1][r][i],f[l][r-1][i]);
                    if(s[l]==s[r]) f[l][r][i]=max(f[l][r][i],f[l+1][r-1][i]+2);
                    if(i) f[l][r][i]=max(f[l][r][i],f[l+1][r-1][i-1]+2);
                }
            }
    printf("%d\n",f[1][n][k]);
    return 0;
}


Measured memory_bytes: 114560
c = input().split()
c1,c2=c[0],c[1]
v=input().split()
v1,v2 = int(v[0]), int(v[1])
f = input()
if f==c1:
    v1-=1
else:
    v2-=1
print(str(v1) + ' ' + str(v2))

Measured memory_bytes: 3060
#include<bits/stdc++.h>
#define N 100010
using namespace std;
int n;
int a[N];

int t1[N];
int t2[N];

int main()
{
	scanf("%d", &n);
	for(int i = 1; i <= n; ++ i)
		scanf("%d", &a[i]);
	for(int i = 1; i <= n; ++ i)
		if(i & 1)
			++ t1[a[i]];
		else
			++ t2[a[i]];
	int x1 = 0, x2 = 0, y1 = 0, y2 = 0;
	for(int i = 0; i < N; ++ i)
	{
		if(x1 == 0 || t1[x1] <= t1[i])
			x2 = x1, x1 = i;
		else if(t1[x2] < t1[i])
			x2 = i;
		
		if(y1 == 0 || t2[y1] <= t2[i])
			y2 = y1, y1 = i;
		else if(t2[y2] < t2[i])
			y2 = i;
	}
	
	if(x1 != y1)
		printf("%d", n - t1[x1] - t2[y1]);
	else printf("%d", min(n - t1[x1] - t2[y2], n - t1[x2] - t2[y1]));
	return 0;
}

Measured memory_bytes: 1408
n, m = map(int, input().split())
a = list(map(int, input().split()))

flg = 0

b = sorted(a, reverse=True)

for i in range(m):
    x = sum(b) / (4 * m)
    if b[i] < x:
        flg = 1
    
if flg == 1:
    print("No")
else:
    print("Yes")


Measured memory_bytes: 3060
#include <stdio.h>
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#define _USE_MATH_DEFINES
#include <math.h>
#include <cmath>
using namespace std;
using LL = long long;
using P = pair<int, int>;
#define rep(i, n) for (int i = 0; i < n; i++)
const int INF = numeric_limits<int>::infinity();

bool checker(LL num){
    bool three = false, five = false, seven = false;
    while (num > 0){
        switch(num % 10){
            case 3:
                three = true;
                break;
            case 5:
                five = true;
                break;
            case 7:
                seven = true;
                break;
        }
        num /= 10;
        if (three && five && seven){
            return true;
        }
    }

    return false;
}

int main(void)
{
    LL N;
    cin >> N;

    queue<LL> q;
    LL count = 0;
    q.push(3);
    q.push(5);
    q.push(7);
    while (true){
        int i = 0;
        rep (j, pow(3, i+1)){
            LL num = q.front();
            if (num > N){
                goto End;
            }
            q.pop();
            q.push(num*10 + 3);
            q.push(num*10 + 5);
            q.push(num*10 + 7);
            if (checker(num)){
                count++;
            }
        }
    }
End:;
    printf("%lld\n", count);
    return 0;
}

Measured memory_bytes: 768
#include <iostream>
#include <stdio.h>
#include <cstring>
#include <cstdio>
#include <math.h>
#include <algorithm>
#include <vector>
#include <string>
#include <stdlib.h>
#include <queue>
#include <stack>
#include <utility>
#include <fstream>
#include <random>
#include <map>
#include <unordered_map>
#include <cstdlib>
#include <functional>
#include <random>
#include <time.h>
#include <chrono>
#include <sstream>
#include <iomanip>
#define rep(i,n) for(int i=0;i<n;i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define ll long long
#define INF 1000000001
#define mod 1000000007
#define SORT(s) sort(s.begin(), s.end());
#define reverse(s) reverse(s.begin(), s.end());
#define P pair<int,int>
#define mp make_pair
#define valid(x,y,h,w) (0<=x&&x<h&&0<=y&&y<w)
int dx[4] = { 0,1,0,-1 };
int dy[4] = { 1,0,-1,0 };
using namespace std;
int POW(int x, int y) { return int(pow(double(x), double(y))); }
double log(double a, double b) { return log(b) / log(a); }

class City {
public:
	int no;
	int no1;
	int no2;
	int ans;
	City(int i, int a, int b) {
		no = i, no1 = a, no2 = b;
	}
};

int main() {
	int n;
	cin >> n;
	vector<int> x(n), y(n), h(n);
	rep(i, n) {
		cin >> x[i] >> y[i] >> h[i];
	}
	rep(i, 101) {
		rep(j, 101) {
			int H = -1;
			int Hmax = INF * 2;
			rep(k, n) {
				if (h[k] == 0) {
					Hmax = min(Hmax, abs(i - x[k]) + abs(j - y[k]));
				}
				else {
					int guess = h[k] + abs(i - x[k]) + abs(j - y[k]);
					if (H == -1) {
						H = guess;
					}
					else if (H != guess) {
						goto next;
					}
				}
			}

			if (H > 0 && Hmax >= H) {
				cout << i << " " << j << " " << H << endl;
				return 0;
			}

		next:;

		}

	}
}



Measured memory_bytes: 256
main = interact $ pureMain

pureMain :: String -> String
pureMain s = (\ (_, _, _, ans) -> show ans) $ foldl f (1, 0, 0, 0) s

f :: (Int, Int, Int, Int) -> Char -> (Int, Int, Int, Int)
f (m, a, b, c) 'A' = (m, madd m a, b, c)
f (m, a, b, c) 'B' = (m, a, madd a b, c)
f (m, a, b, c) 'C' = (m, a, b, madd b c)
f (m, a, b, c) '?' = (mmul m 3, madd m (mmul 3 a), madd a (mmul 3 b), madd b (mmul 3 c))
f x _ = x

mmul :: Int -> Int -> Int
mmul x y = (x * y) `mod` 1000000007

madd :: Int -> Int -> Int
madd x y = (x + y) `mod` 1000000007

Measured memory_bytes: 29052
#include "bits/stdc++.h"
using namespace std;

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP0(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REP1(i,n) for(int i=1, i##_len=(n); i<=i##_len; ++i)
#define RREP0(i,n) for(int i=n-1; i>=0; --i)
#define RREP1(i,n) for(int i=n; i>=1; --i)
#define SORT(c) sort((c).begin(),(c).end())
#define REVERSE(c) reverse((c).begin(),(c).end())
#define FILL(c, v) fill((c).begin(),(c).end(), v)
#define SZ(a) int((a).size())
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define CLR(a) memset((a), 0 ,sizeof(a))

inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

typedef long long LL;
typedef unsigned long long ULL;

const int INTINF = 2147483647;
const LL LLINF = 9223372036854775807;
int gcd(int a,int b){return b?gcd(b,a%b):a;}

void solve()
{
  int N; cin >> N;
  int ans = 0;
  char mem = '\0';
  REP0(i, N) {
      char s; cin >> s;
      if (s != mem) {ans++; mem = s; }
  }
  cout << ans;
}

int main(int argc, char const *argv[])
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  std::cout<<std::fixed<<std::setprecision(10);
  solve();
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <numeric>
#include <functional>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e16;
const ll MAX_N = 100010;
 
int main() {
    ll a, b, h;
    cin >> a >> b >> h;
    out((a+b)*h/2);
    re0;
}

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

#define DEBUG(x) cerr << #x << ": " << x << endl;
#define ll long long

int main() {
    string s;
    getline(cin, s);
    cout << "A" + s.substr(8, 1) + "C" << endl;

    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

int main() {
  int i, j, k, n, a[1000], v;

  scanf("%d", &n);
  for(i = 0; i < n; i++){
    scanf("%d", &a[i]);
  }
  for(i = 1; i < n; i++){
    for(k = 0; k < n; k++){
      printf("%d",a[k]);
      if(k != n - 1) printf(" ");
      else printf("\n");
    }
    v = a[i];
    j = i - 1;
      while(j >= 0 && a[j] > v){
        a[j+1] = a[j];
        j--;
      }
    a[j+1] = v;
    
  }
  for(k = 0; k < n; k++){
      printf("%d",a[k]);
      if(k != n - 1) printf(" ");
      else printf("\n");
    }
  return 0;
}


Measured memory_bytes: 2124
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<set>
#include<map>
#include<queue>
#define REP(i,a) for (int i = 0;i < (a);++i)
#define FOR(i,a,b) for (int i = (a);i < (b); ++i)
#define FORR(i,a,b) for (int i = (a);i >= (b); --i)
#define ALL(obj) (obj).begin(),(obj).end()
#define SORT(list) sort(ALL((list)));
#define MOD 1000000007
using namespace std;
using ll = long long;
int main(){
    int a,b,c,d;
    cin >> a >> b >> c >> d;
    while(a > 0 && c > 0){
        c-=b;
        if(c <= 0){
            cout << "Yes" << endl;
            return 0;
        }
        a-=d;
        if(a <= 0){
            cout << "No" << endl;
            return 0;
        }
    }
    return 0;
}

Measured memory_bytes: 3636
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
const ll MOD = 1e9 + 7;
const double PI = 3.141592653589793238;
const double EPS = 1e-10;
vector<int> G[100000];
ll dp[100000], dp2[100000];
ll M;
ll dfs(int v, int par) {
	ll t = 1;
	for (int to : G[v]) {
		if (to == par) continue;
		(t *= (1 + dfs(to, v))) %= M;
	}
	return dp[v] = t;
}
void dfs2(int v, int par, ll x) {
	int n = G[v].size();
	vector<ll> child;
	vector<ll> L, R;
	for (int to : G[v]) {
		child.push_back(to);
		if (to == par) {
			L.push_back(x + 1);
			R.push_back(x + 1);
		}
		else {
			L.push_back(dp[to] + 1);
			R.push_back(dp[to] + 1);
		}
	}
	for (int i = 1; i < n; i++) (L[i] *= L[i - 1]) %= M;
	for (int i = n - 1; i > 0; i--) (R[i - 1] *= R[i]) %= M;
	dp2[v] = L[n - 1] % M;
	for (int i = 0; i < n; i++) {
		if (child[i] == par) continue;
		ll t = 1;
		if (i > 0) (t *= L[i - 1]) %= M;
		if (i + 1 < n) (t *= R[i + 1]) %= M;
		dfs2(child[i], v, t);
	}

}
int main() {
	int N;
	cin >> N >> M;
	if (N == 1) {
		cout << 1 << endl;
		return 0;
	}
	for (int i = 0; i < N - 1; i++) {
		int x, y;
		cin >> x >> y;
		x--; y--;
		G[x].push_back(y);
		G[y].push_back(x);
	}
	dfs(0, -1);
	dfs2(0, -1, 0);
	for (int i = 0; i < N; i++) cout << dp2[i] << endl;
}

Measured memory_bytes: 30080
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;
 public class Main
 {
 	public static void main(String[]args)
 	{
 		Scanner sc=new Scanner (System.in);
 		int n=sc.nextInt();
 		int x=sc.nextInt();
 		int t=sc.nextInt();
 		if(n%x==0)
 			System.out.println((n/x)*t);
 		else
 			System.out.println(((n/x)*t)+t);
 	}
 }

Measured memory_bytes: 35836
def examA():
    A = LI()
    A.sort()
    ans = A[2]*10+A[1]+A[0]
    print(ans)
    return

def examB():
    ans = 0
    print(ans)
    return

def examC():
    ans = 0
    print(ans)
    return

def examD():
    ans = 0
    print(ans)
    return

import sys,bisect,itertools,heapq,math,random
from copy import deepcopy
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
def I(): return int(input())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LSI(): return list(map(str,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def SI(): return sys.stdin.readline().strip()
global mod,mod2,inf,alphabet,_ep
mod = 10**9 + 7
mod2 = 998244353
inf = 10**18
_ep = 10**(-12)
alphabet = [chr(ord('a') + i) for i in range(26)]

sys.setrecursionlimit(10**7)

if __name__ == '__main__':
    examA()

"""
142
12 9 1445 0 1
asd dfg hj o o
aidn
"""

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

vector<vector<ll>> g(1e5 + 5, vector<ll>());
vector<bool> visited(1e5, false);

void dfs(ll now, ll parent) {
  if (visited[now]) return;
  visited[now] = true;

  for (ll next : g[now]) {
    if (next == parent) continue;
    dfs(next, now);
  }
}

int main() {
  ll n, m;
  cin >> n >> m;

  ll x, y, z;
  for (ll i = 0; i < m; i++) {
    cin >> x >> y >> z;
    x--; y--;
    g[x].push_back(y);
    g[y].push_back(x);
  }

  ll ans = 0;
  for (ll i = 0; i < n; i++) {
    if (!visited[i]) {
      ans++;
      dfs(i, -1);
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 10368
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
typedef long long ll;
typedef pair<int, int> P;
const int INF = 100100100;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;
struct Edge {
  /* data */
  int to, id;
};

vector<vector<Edge>> g;
vector<int> ans;
void dfs(int v, int c = -1, int p = -1) {
  int k = 1;
  REP(i, g[v].size()) {
    int u = g[v][i].to, ei = g[v][i].id;
    if (u == p) continue;
    if (k == c) k++;
    ans[ei] = k;
    k++;
    dfs(u, ans[ei], v);
  }
}
int main() {
  int N;
  cin >> N;
  g.resize(N);
  ans.resize(N);
  REP(i, N - 1) {
    int a, b;
    cin >> a >> b, a--, b--;
    g[a].push_back(Edge{b, i});
    g[b].push_back(Edge{a, i});
  }
  dfs(0);
  int mx = 0;
  REP(i, N) mx = max(mx, int(g[i].size()));
  cout << mx << endl;
  REP(i, N - 1) { cout << ans[i] << endl; }
}

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

int main()
{
  int n; cin >> n;
  
  int n_ = n, n_dig = 0, high_n, low_n = n%10;
  while (n_) ++n_dig, high_n = n_%10, n_ /= 10;
  
  if (n_dig == 1)
  {
    cout << n << endl;
    return 0;
  }
  
  int count[10][10] = {};
  for (int i = 1; i <= 9; ++i)
  for (int j = 1; j <= 9; ++j)
  {
    if (i == j) ++count[i][j];
    
    if (i < high_n)
    {
      int dig = 2, r = 1;
      while (n_dig >= dig)
      {
        count[i][j] += r;
        r *= 10; ++dig;
      }
    }
    else
    {
      int dig = 2, r = 1;
      while (n_dig > dig)
      {
        count[i][j] += r;
        r *= 10; ++dig;
      }
      
      if (i == high_n)
      {
        count[i][j] += n/10 % r + 1;
        if (j > low_n) --count[i][j];
      }
    }
  }
  
  int total = 0;
  for (int i = 1; i <= 9; ++i)
    for (int j = 1; j <= 9; ++j)
      total += count[i][j] * count[j][i];
  
  cout << total << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cinttypes>
#include <map>
#include <set>

typedef struct {
	int type;
	int delicious;
} Sushi;

int sushi_comp_greater(const void *a, const void *b) {
	return (((const Sushi *)b)->delicious - ((const Sushi *)a)->delicious);
}

int main() {
	int n;
	scanf("%d", &n);
	size_t k;
	scanf("%zd", &k);
	Sushi sushies[n];
	for (int i = 0; i < n; i++) {
		scanf("%d", &sushies[i].type);
		scanf("%d", &sushies[i].delicious);
		sushies[i].type--;
	}

	qsort(sushies, n, sizeof(Sushi), sushi_comp_greater);

	std::map<int, std::multiset<int> > cur_eating;
	uint64_t sum = 0;
	for (size_t i = 0; i < k; i++) {
		cur_eating[sushies[i].type].insert(sushies[i].delicious);
		sum += sushies[i].delicious;
	}

	int delete_head = k - 1;
	int insert_head = k;
	uint64_t res = ((uint64_t)cur_eating.size())*cur_eating.size() + sum;
	for (size_t i = cur_eating.size() + 1; i <= k; i++) {
		while (delete_head >= 0) {
			if (cur_eating[sushies[delete_head].type].size() > 1) {
				while (insert_head < n) {
					if (!cur_eating[sushies[insert_head].type].size())
						break;
					insert_head++;
				}
				if (insert_head >= n) delete_head = -1; // break outer loop
				break;
			}
			delete_head--;
		}
		if (delete_head < 0) break;
		if (insert_head >= n) break;
		sum += sushies[insert_head].delicious;
		sum -= sushies[delete_head].delicious;
		res = std::max(res, sum + ((uint64_t)i)*i);
		cur_eating[sushies[insert_head].type].insert(sushies[insert_head].delicious);
		cur_eating[sushies[delete_head].type].erase(cur_eating[sushies[delete_head].type].find(sushies[delete_head].delicious));
		delete_head--;
		insert_head++;
	}

	printf("%" PRIu64 "\n", res);


	return 0;
}


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

	

int main() {
  
	string S;
	cin >>S;
	
	int count=0;
	int ans=0;
	
	for(int i=0; i<S.size(); i++){
		
		if(S.at(i)=='A'||S.at(i)=='C'||S.at(i)=='G'||S.at(i)=='T'){
			
			count++;
			
		}
		else{
			
			if(count>ans){
				
				ans=count;
				
			}
			count=0;
			
		}
		
	}
	
	if(count>ans){
		
		ans=count;
		
	}
	cout <<ans <<endl;
  
}


Measured memory_bytes: 256
MOD=10**9+7
L=input()

def powmod(a,p):
  if p==0:
    return 1
  elif p==1:
    return a
  else:
    pow2=powmod(a,p//2)
    if p%2==0:
      return (pow2**2)%MOD
    else:
      return (a*pow2**2)%MOD

def invmod(a):
  return powmod(a,MOD-2)    
    
sum=0
cnt_2=1
pow_3=powmod(3,len(L))
inv_3=invmod(3)
for i in range(len(L)):
  pow_3=pow_3*inv_3%MOD
  if L[i] == "1":
    sum += cnt_2*pow_3
    sum %= MOD
    cnt_2 = (cnt_2*2)%MOD
    
sum += cnt_2
sum %= MOD
print(sum)

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

int main() {
    int N, K;
    cin >> N >> K;
    vector<int> A(N);

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

    // 約数の全列挙
    set<int> st;
    for (int i=1; i*i<=sum; ++i) {
        if (sum%i == 0) {
            st.insert(i);
            st.insert(sum/i);
        }
    }

    int ans = 1;
    for (int d : st) {

        int s = 0;
        vector<int> a(N);
        rep(i, N) {
            s += A[i]%d;
            a[i] = A[i]%d;
        }

        sort(a.rbegin(), a.rend());

        int pnum = s/d;
        int s1 = 0;
        rep(i, pnum) {
            s1 += (d - a[i]);
            s -= a[i];
        }

        if (max(s, s1) <= K) {
            ans = max(ans, d);
        }
    }

    cout << ans << endl;

}


Measured memory_bytes: 256
#include <vector>
#include <queue>
#include <stack>
#include <algorithm>
#include <iostream>
#include <string>
#include <tuple>
#include <set>
#include <map>
#include <unordered_map>
#include <complex>
#include <iomanip>
#include <cmath>
using namespace std;
typedef long long ll;

int main()
{
  int x, y;
  cin >> x >> y;
  char s[x + 2][y + 2];
  string ans = "Yes";
  for (int i = 0; i < x + 2; i++) {
    for (int j = 0; j < y + 2; j++) {
      if (i == 0 || j == 0 || j == y + 1 || i == x + 1) s[i][j] = '.';
      else cin >> s[i][j];
    }
  }
  for (int i = 1; i < x + 1; i++) {
    for (int j = 1; j < y + 1; j++) {
      if (s[i][j] == '#') {
        if (s[i - 1][j] != '#' && s[i + 1][j] != '#' && s[i][j - 1] != '#' && s[i][j + 1] != '#') {
          ans = "No";
          break;
        }
      }
    }
    if (ans == "No") break;
  }
  cout << ans << endl;
}


Measured memory_bytes: 384
import itertools
h,w,k = map(int, input().split())
g = []
for _ in range(h):
  i = input()
  g.append(i)
l = [0 for j in range(h)]
d = [0 for j in range(w)]
c =0
for i in range(h):
  a = 0
  for j in range(w):
    if g[i][j] == '#':
      a +=1
  l[i]+=a
  c+=a
for i in range(w):
  b = 0
  for j in range(h):
    if g[j][i] == '#':
      b +=1
  d[i]+=b
ans = 0
for i in list(itertools.product([0,1], repeat=h)):
  e = c
  for x in range(h):
    if i[x] == 1:
      e-= l[x]
  for j in list(itertools.product([0,1], repeat=w)):
    f = e
    for y in range(w):
      if j[y] == 1:
        f -= d[y]
    for x in range(h):
      for y in range(w):
        if i[x] == 1 and j[y] == 1 and g[x][y]=='#':
          f+=1
    if f==k:
      ans+=1
print(ans)

Measured memory_bytes: 68488
#include <bits/stdc++.h>
using namespace std;
#define LL long int
#define ULL unsigned long int
#define LD long double

LL MOD = 1000000007;

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

    double n = (4*x-y)/2.0;
    double m = (y - 2*x)/2.0;

    if(n >= 0 && m >= 0 && n == (int)n && m == (int)m){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }

    return 0;
}

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

using namespace std;
typedef long long ll;

#define INF (long long)(1e9+7)
#define REP(i,n) for(ll i = 0; i < n; i++)
#define REP1(i,n) for(ll i = 1; i <= n; i++)

int main(void)
{
  string s1, s2, s3;
  cin >> s1 >> s2 >> s3;
  ll d = 'A'- 'a';
  printf("%c%c%c\n", (char)(s1[0]+d), (char)(s2[0]+d), (char)(s3[0] + d));
}


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

#define TRACE(x) x
#define WATCH(x) TRACE(cout << #x" = " << x << endl)
#define WATCHR(a, b) TRACE(for (auto it=a; it!=b;) cout << *(it++) << " "; cout << endl)
#define WATCHC(V) TRACE({cout << #V" = "; WATCHR(V.begin(), V.end());})

#define all(x) (x).begin(), (x).end()

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vb = vector<bool>;
using vs = vector<string>;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

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

    int N, L;
    cin >> N >> L;

    vi x(N + 1), t(N + 1);
    for (int i = 1; i <= N; i++) {
        cin >> x[i];
    }
    int ext = 0;
    for (int i = 1; i <= N; i++) {
        cin >> t[i];
        ext += t[i] / (2 * L) * 2;
        t[i] %= 2 * L;
        if (!t[i]) { t[i] = 2 * L; ext -= 2; }
    }

    auto ceil = [](ll n, ll d) { return (n + d - 1) / d; };
    vi left(N + 1), right(N + 1);
    for (int i = 1; i <= N; i++) {
        left[i] = t[i] <= 2 * x[i];
        right[i] = t[i] <= 2 * (L - x[i]);
    }

    int pr = 0, lo = 0, bt = 0;
    for (int i = 1; i <= N - 1; i++) {
        if (left[i] && right[i]) {
            if (lo) { pr++; lo--; }
            else bt++;
        } else if (right[i]) {
            if (bt) { pr++; bt--; }
        } else if (left[i]) {
            lo++;
        }
    }
    pr += bt / 2;
    if (right[N]) pr++;

    cout << (2 + ext + 2 * (N - pr)) * ll(L) << "\n";

    return 0;
}



Measured memory_bytes: 4992
#include <bits/stdc++.h>
#define N 100010
#define pb push_back
#define fi first
#define se second
#define si size()
#define ll long long
#define mp make_pair
#define iter ::iterator
#define all(v) v.begin(), v.end()
#define pp pop_back
#define mapiter map<int, int>::iterator
#define forn(i, n) for(int i = 0; i < n; ++i)
#define forn1(i, n) for(int i = 1; i <= n; ++i)
#define forr(i, n)	for(int i = n - 1; i >= 0; --i)
#define forr1(i, n)	for(int i = n; i >= 1; --i)
#define form(l, r, i)	for(int i = l; i <= r; ++i)
#define forv(r, l, i)	for(int i = r; i >= l; --i)
#define r0 return 0
#define barnarnar ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define lld long double
#define elif else if
 
const int inf = 1e9 + 7;
const lld EPS = 0.00000001;
const ll modwdop = 998244353ll;
 
ll pp = 13337ll;
ll modw = 1e9 + 7;
 
using namespace std;

int main()
{
	barnarnar
	int n;
	cin >> n;
	string s;
	cin >> s;
	ll nr = 0, nb = 0;
	forn(i, n)
	{
		if(s[i] == 'R')	nr++;
		if(s[i] == 'B') nb++;
	}
	ll ans = nr * nb * (n - nr - nb);
	forn(i, n)
	{
		for(int r = 1; i + 2 * r < n; r++)
		{
			set<char> t = {s[i], s[i + r], s[i + 2 * r]};
			if(t.si == 3)	ans--;
		}
	}
	cout << ans;
}

Measured memory_bytes: 3632
# -*- coding: utf-8 -*-
"""
Created on Tue May 28 22:22:21 2019

@author: Yamazaki Kenichi
"""
import heapq

Q = int(input())
Q2 = [input() for i in range(Q)]

ans = []
Al,Ar = [-(-(10**9+1))],[10**9+1]
d, a, b = map(int,Q2[0].split())
heapq.heappush(Al,-a)
B = b

for i in range(1,Q):
    if Q2[i][0] == '1':
#        intput
        d, a, b = map(int,Q2[i].split())
        if len(Al) == len(Ar):
            if a < Ar[0]:
                heapq.heappush(Al,-a)
            else:
                heapq.heappush(Ar,a)
                heapq.heappush(Al,-(heapq.heappop(Ar)))
            C = abs(a - (-Al[0]))
        else:
            C = abs(a - (-Al[0]))
            if a < Ar[0]:
                heapq.heappush(Al,-a)
                heapq.heappush(Ar,-(heapq.heappop(Al)))
            else:
                heapq.heappush(Ar,a)
        B += (b + C)
#        print(Al,Ar,a,B,b)
    else:
#        output
        ans.append([(-Al[0]),B])

for c in ans:
    print(' '.join(map(str,c)))



Measured memory_bytes: 35820
A, B, N = map(int, input().split())
l = -1
r = N
# ans = 0
# for i in range(1, N+1):
#     ans = max(ans, (A*i)//B - (A*(i//B)))
k = min(B-1, N)
ans2 = (A*k)//B - (A*(k//B))

print(ans2)


Measured memory_bytes: 61804
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
typedef long long ll;
#define rep(i,n) for (int i = 0; i < (n); i++)
#define repe(i,n) for (int i = 0; i <= (n); ++i)
#define repe1(i,n) for (int i = 0; i <= (n); ++i)
#define all(x) (x).begin(),(x).end()
#define pb(x) push_back(x)
#define eb(k,v) emplace_back(k,v)
#define ct(res) cout << res << "\n";
#define vi vector<int>
#define vl vector<ll>
using namespace std;
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 int INF = 1e9;
const ll MOD = 1000000007;

using Graph = vector<vector<int>>;

ll modPow(ll x, ll n) {
    if(n==0) return 1;
    ll res = modPow(x*x%MOD, n/2);
    if(n&1) res=res*x%MOD;
    return res;
}
ll mul(ll l, ll r) {
    ll ret =1;
    for(int i=0; i<l-r+1; ++i) {
        ret*=i+r;
        ret%=MOD;
    }
    return ret;
}
ll com(ll n, ll k) {
    ll ret1 = mul(n,n-k+1);
    ll ret2 = mul(k,1);
    ll ret3 = modPow(ret2, MOD-2);
    return ret1*ret3%MOD;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n; cin >> n;
    vi a(n); rep(i,n) cin >> a[i];
    int cnt = 0;
    rep(i,n-1) {
        if (a[i]==a[i+1]) a[i+1] = -1;
    }
    cnt = count(all(a),-1);
    cout << cnt << "\n";
}



Measured memory_bytes: 256
import bisect
n = int(input())
 
l = list(map(int, input().split()))
l.sort()
a = 0
#print(l)
for i in range(n-2):
    for j in range(i+1,n-1):
        s = bisect.bisect_left(l,l[i]+l[j])-j-1
        a+=s


print(a)

Measured memory_bytes: 3188
#%%
import sys
def input():
    return sys.stdin.readline().rstrip()

def main():
    N = int(input())

    print(1/sum([1/int(x) for x in input().split()]))


# %%
if __name__ == '__main__':
    main()

# %%
# from atcoder_test import doTest
# doTest("abc138","b",main)

Measured memory_bytes: 2940
#Satoooh
'''
左からL個、右からR個、取り出す。
取り出す回数は操作回数上限のK回なので、最大K個取り出せる。
操作はK回まで行えるので、操作回数がKより小さくてもOK。
求めるのは、価値の最大値なので、マイナスの宝石は、筒に戻す。
筒に戻せる上限は、下記１と２の小さい値min
１．操作回数制限：K-L-R、操作回数の上限から、LとRを取り出した回数を引く
２．宝石個数制限：手持ちは、L+R個なので、これ以上は戻せない
'''
N, K = map(int, input().split())
*V, = map(int, input().split())#タプルとして入力、仮に1個でもOK
ans = 0#格納されている宝石が負ばかりなら、何もしない

for l in range(K + 1):#左から最大K個取り出す
	for r in range(K - l + 1):
    #右から取り出すのはK-L個、左からL個取り出しているので
		inHand = []#手持ちを格納する配列
		if l + r > N:  # Nを超えてしまうありえない場合を処理
			break#ありえないケースはブレイク
		# inHandに左からl個、右からr個の要素を追加
		inHand = V[: l]
		inHand.extend(V[N - r:])
		tmp = sum(inHand)  
        # 現時点でのinHandの和をtmpとして負の要素をtmpから引いていく
		# inHand中の負の要素を消せるだけ消す
		inHand.sort()
		for i in range(min(K - l - r, l + r)):
			if inHand[i] >= 0:#負の要素だけ消す
				break
			tmp -= inHand[i]#負の要素は手持ちしないことにする
		ans = max(ans, tmp)#求めるのは手持ちの価値の最大値

print(ans)

Measured memory_bytes: 3064
H, W = gets.chomp.split(" ").map(&:to_i)
strs = H.times.map{gets.chomp.chars}
res = Array.new(H).map{Array.new(W, 0)}

H.times do |i|
  W.times do |j|
    if strs[i][j] == '#'
      res[i][j] = '#'
    else
      count = 0
      count += 1 if i > 0   && j > 0   && strs[i-1][j-1] == '#'
      count += 1 if i > 0              && strs[i-1][j]   == '#'
      count += 1 if i > 0   && j < W-1 && strs[i-1][j+1] == '#'
      count += 1 if            j > 0   && strs[i][j-1] == '#'
      count += 1 if            j < W-1 && strs[i][j+1] == '#'
      count += 1 if i < H-1 && j > 0   && strs[i+1][j-1] == '#'
      count += 1 if i < H-1            && strs[i+1][j] == '#'
      count += 1 if i < H-1 && j < W-1 && strs[i+1][j+1] == '#'
      res[i][j] = count
    end
  end
end

res.each { |line| puts line.join }

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

int main(){
  int n,y;
  cin>>n>>y;
  bool ans=0;
  int ans_x;
  int ans_y;
  int ans_z;
  for(int xn=0; xn*10000 <= y; xn++){
    for(int yn=0; xn*10000+yn*5000 <= y; yn++){
      if(xn*10000+yn*5000+(n-xn-yn)*1000==y){
        ans=1;
        ans_x=xn; ans_y=yn; ans_z=n-xn-yn;
      }
    }
  }
  if(ans){
    cout<<ans_x<<" "<<ans_y<<" "<<ans_z<<endl;
  }else{
    cout<<-1<<" "<<-1<<" "<<-1<<endl;
  }
}




Measured memory_bytes: 3632
from math import ceil,sqrt
def main():
    
    # for _ in range(ii()):
    
    # t=int(input())
    # n,m=map(int,input().split())
    # a=list(map(int,input().split()))
    
    
    
    
    
    n=int(input())
    x=n//500
    n%=500
    ans=1000*x
    x=n//5
    ans+=(5*x)
    print(ans)
    
    
    
    
    
    
    
    
    




    
if __name__ =="__main__":
    main()

Measured memory_bytes: 3060
#include <iostream>
#include <list>

using namespace std;;

int main(void){
  int N; cin >> N;
  char c[N];
  int WhiteCount = 0;
  for (int i = 0; i < N; i++){
    cin >> c[i];
    if (c[i] == 'W') {
      WhiteCount++;
    }
  }

  int controlCount = 0;
  int alignedCount = 0;
  for (int i = N-1; i >= 0; i--) {
    if (alignedCount == WhiteCount) break;
    if (c[i] == 'R') controlCount++;
    if (c[i] == 'W'); //noop
    alignedCount++;
  }

  cout << controlCount;
}


Measured memory_bytes: 3788
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;
using vs = vector<string>;
using pll = pair<ll, ll>;
using vp = vector<pll>;
template<class T> using V = vector<T>;
template<class T> using VV = vector<vector<T> >;
#define rep(i, n) for(ll i = 0; i < (n); i++)
#define repb(i, n) for(ll i = (n)-1; i >= 0; i--)
#define repr(i, a, b) for(ll i = (a); i < (b); i++)
#define reprb(i, a, b) for(ll i = (a)-1; i >= (b); i--)
#define ALL(a) (a).begin(), (a).end()
#define SZ(x) ((ll)(x).size())
const ll MOD = 1000000007;
const ll INF = 100000000000000000LL;
inline ll GCD(ll a, ll b){ return b?GCD(b, a % b):a; }
inline ll LCM(ll a, ll b){ return a/GCD(a, b)*b; }
inline ll powint(unsigned long long x, ll y){ ll r=1; while(y){ if(y&1) r*=x; x*=x; y>>=1; } return r; }
inline ll powmod(ll x, ll y, ll m = MOD){ ll r=1; while(y){ if(y&1) r*=x; x*=x; r%=m; x%=m; y>>=1; } return r; }
template<class S, class T>inline bool chmax(S &a, const T &b){ if(a<b) { a=b; return 1; } return 0; }
template<class S, class T>inline bool chmin(S &a, const T &b){ if(b<a) { a=b; return 1; } return 0; }
#ifdef OJ_LOCAL
#include "dump.hpp"
#else
#define dump(...) ((void)0)
#endif

int main(){
    cin.tie(0); ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    ll n;
    cin >> n;
    vll a(n), b(n), c(n);
    rep(i, n){
        cin >> a[i] >> b[i];
        c[i] = a[i] + b[i];
    }
    sort(ALL(c));
    reverse(ALL(c));
    ll ans = 0;
    rep(i, n)if((i&1)==0)ans+=c[i];
    cout << ans-accumulate(ALL(b), 0ll) << endl;
    return 0;
}

Measured memory_bytes: 2560
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;

int N, K, K2;
int x[100010], y[100010];
char c[100010];
int b[4010][4010], w[4010][4010];

int sumb(int p, int q, int r, int s) {
  int res = b[r][s];
  if (p > 0 && q > 0) res += b[p-1][q-1];
  if (p > 0) res -= b[p-1][s];
  if (q > 0) res -= b[r][q-1];
  return res;
}
int sumw(int p, int q, int r, int s) {
  int res = w[r][s];
  if (p > 0 && q > 0) res += w[p-1][q-1];
  if (p > 0) res -= w[p-1][s];
  if (q > 0) res -= w[r][q-1];
  return res;
}

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  
  cin >> N >> K;
  K2 = K << 1;
  for (int i = 0; i < N; i++) {
    cin >> x[i] >> y[i] >> c[i];
    x[i] %= K2;
    y[i] %= K2;
  }
  for (int i = 0; i < N; i++) {
    if (c[i] == 'B') {
      b[y[i]][x[i]]++;
      b[y[i]+K2][x[i]]++;
      b[y[i]][x[i]+K2]++;
      b[y[i]+K2][x[i]+K2]++;
    } else {
      w[y[i]][x[i]]++;
      w[y[i]+K2][x[i]]++;
      w[y[i]][x[i]+K2]++;
      w[y[i]+K2][x[i]+K2]++;
    }
  }
  for (int i = 0; i < 2*K2; i++) {
    for (int j = 0; j+1 < 2*K2; j++) {
      b[i][j+1] += b[i][j];
      w[i][j+1] += w[i][j];
    }
  }
  for (int j = 0; j < 2*K2; j++) {
    for (int i = 0; i+1 < 2*K2; i++) {
      b[i+1][j] += b[i][j];
      w[i+1][j] += w[i][j];
    }
  }
  int ans = 0;
  for (int i = 0; i < 2*K; i++) {
    for (int j = 0; j < 2*K; j++) {
      ans = max(ans, sumb(i, j, i+K-1, j+K-1)+sumb(i+K, j+K, i+2*K-1, j+2*K-1) + sumw(i+K, j, i+2*K-1, j+K-1) + sumw(i, j+K, i+K-1, j+2*K-1));
    }
  }
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 126592
#include <bits/stdc++.h>
using namespace std;
int main() {
  int A, B, C;
  cin >> A >> B >> C;
  if ((A == B) || (B == C) || (C == A)) {
    if ((A == B) && (B == C)) {
      cout << "No" << endl;
    } else {
      cout << "Yes" << endl;
    }
  } else {
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.PrintWriter;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) throws Exception {
        try (BufferedInputStream in = new BufferedInputStream(System.in);
             PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out))) {

            Scanner sc = new Scanner(in);

            // 12:37-

            long w = sc.nextLong();
            long h = sc.nextLong();
            long x = sc.nextLong();
            long y = sc.nextLong();

            out.println(w * h / 2.0 + " " + (x * 2 == w && y * 2 == h ? 1 : 0));
        }
    }
}


Measured memory_bytes: 21844
#include<stdio.h>

int main(){

  int a, b, r,tmp;

  scanf("%d %d",&a,&b);

  if(a < b){
    tmp = a;
    a = b;
    b = tmp;
  }

  r = 1;

  while(r != 0){
    r = a%b;
    a = b;
    b = r;

  }

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

  return 0;
}

Measured memory_bytes: 592
#include <iostream>
#include <cmath>
#include <vector>
#include <queue>
#include <utility>
#include <algorithm>
using namespace std;

int main() {
  int n;
  int d = 100000;
  cin >> n;
  while (n--) {
    int r = d / 20;
    if (r % 1000 > 0)
      r = r - r % 1000 + 1000;
    d += r;
  }
  cout << d << endl;
}

Measured memory_bytes: 1160
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define pii pair<int,int>
#define pb push_back
#define INF INT_MAX
#define mod 1000000007ll
#define fi first
#define se second
#define f(i,p,q) for(int i=p;i<q;i++)
#define si(a) scanf("%d",&a)
#define sii(a,b) scanf("%d %d",&a,&b)
#define siii(a,b,c) scanf("%d %d %d",&a,&b,&c)
#define pi(a) printf("%d\n",a)
#define psi(a) printf(" %d",a)
#define poi(a) printf("%d",a)
#define sl(a) scanf("%lld",&a)
#define pl(a) printf("%lld\n",a)
#define Nline() printf("\n")
#define sstr(str) scanf("%s",str)
#define pstr(str) printf("%s\n",str)
#define SET(a) memset(a,-1,sizeof(a))
#define CLR(a) memset(a,0,sizeof(a))
#define vi vector<int>
#define vvi vector<vi>
#define all(v) (v).begin(),(v).end()
#define SORT(v) sort(all(v))
#define RSORT(v) sort(all(v), greater<int>())
#define VI(a,n) vi a(n); rep(i,n)cin>>a[i];
#define sq(n) (n)*(n)
#define iso ios::sync_with_stdio(false); cin.tie(0);cout.tie(NULL);
int n;
int w;
vector<pair<int,int>>v;
ll dp[101][100005];
int main()
{
    iso;
    cin>>n>>w;

    for(int i=0;i<n;i++)
    {
       int x,y;cin>>x>>y;
       v.push_back({x,y});
    }
    for(int i=0;i<=n;i++)
    {
        for(int j=0;j<=w;j++)
        {
            if(i==0||j==0)
                dp[i][j]=0;
            else if(v[i-1].first>j)
                dp[i][j]=dp[i-1][j];
            else
                dp[i][j]=max(v[i-1].second+dp[i-1][j-v[i-1].first],dp[i-1][j]);
        }
    }
    cout<<dp[n][w];
    }


Measured memory_bytes: 79232
N = int(input())
sum = 0
value = []
mv = 0
mn = 0
for i in range(N):
    val = int(input())
    value.append(val)
    if value[i] > mv:
        mv = value[i]
        mn = i

for i in range(N):
    if i == mn:
        sum += value[i] / 2
    else:
        sum += value[i]

print(int(sum))

Measured memory_bytes: 3064
#include <stdio.h>
#include <stdlib.h>
int main(void) {
    int num,day,move,town=0,temp,road[100000]={0},sum=0,i;
    scanf("%d %d",&num,&day);
    for (i=0; i<num-1; i++) {
        scanf("%d",&temp);
        road[i+1]=road[i]+temp;
    }
    for (i=0; i<day; i++) {
        scanf("%d",&move);
        sum+=abs(road[town+move]-road[town]);
        sum%=100000;
        town+=move;
    }
    printf("%d\n",sum);
    return 0;
}

Measured memory_bytes: 996
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
using namespace std;
using namespace __gnu_pbds;
#define ll long long
#define pp pair<ll,ll>
typedef tree<pp,null_type,less<pp>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
#define ld long double
#define fi first
#define se second
#define pb push_back
#define all(x) (x).begin() , (x).end()
#define rep(i,a,b) for( ll i = a ; i < b ; i+=1 )
#define sz(v) (ll)(v.size())
#define hell (ll)1000000007
#define slld(x) scanf("%lld",&x)
ll t = 1;
const ll inf=2*hell;
const ld PI = 3.1415926535897932384626433832795, eps = 1e-8;
inline ll mult(ll x,ll y){return (x*y)%hell;}
inline ll add(ll x,ll y){x+=y;return x%hell;}
inline ll powMod(ll base,ll expo){
	ll ans=1;
	while(expo){
		if(expo&1)ans=mult(ans,base);
		base=mult(base,base);
		expo>>=1;
	}
	return ans;
}
inline ll gcd(ll a,ll b){
	if(b==0)return a;
	return gcd(b,a%b);
}
void solve(){
	ll a, b, c, d, cur=1;
	cin>>a>>b>>c>>d;
	while(a>0 and c>0){
		if(cur%2)c-=b;
		else
			a-=d;
		cur++;
	}
	a<=0?cout<<"No":cout<<"Yes";
}
signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
 //  	cin>>t;
    while(t--){
        solve();
        if(t)cout<<"\n";
    }
    return 0 ;
}


Measured memory_bytes: 3660
def solve():
    r, g, b, n = map(int, input().split())
    cnt = 0
    for i in range(n+1):
        for j in range(n+1):
            x = n-r*i-g*j
            if x % b == 0 and x >= 0:
                cnt += 1
    print(cnt)
    return 0

if __name__ == "__main__":
    solve()


Measured memory_bytes: 73300
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>

using namespace std;

int main(void){
    int N, cnt;
    string str;

    cin >> N;
    cin >> str;

    cnt = 1;
    for(int i=1; i < N; i++){
        if(str[i] != str[i-1])
            cnt++;
    }

    cout << cnt << endl;

    return 0;
}

Measured memory_bytes: 640
#include <math.h>
#include <utility>
#include <string>
#include <vector>
#include <algorithm>
#include <iostream>
using namespace std;

int main(){
	int t;
	cin >> t;
	for ( int i = 0; i < t; i++ ) {
		int n;
		cin >> n;
		int k;
		cin >> k;
		int x = 0;
		int y = 0;
		vector<int> length;
		for ( int j = 0; j < n; j++ ) {
			y = x;
			cin >> x;
			if ( j == 0 ) continue;
			length.push_back( x - y );
		}
		sort( length.begin(), length.end() );
		int sum = 0;
		for ( int j = 0; j < n - k; j++ ) {
			sum += length[j];
		}
		cout << sum << endl;
	}
	return 0;
}

Measured memory_bytes: 1864
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<utility>
#include<cmath>
#include<cstring>
#include<queue>
#include<cstdio>
#include<sstream>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define mp make_pair
#define all(in) in.begin(),in.end()
const double PI=acos(-1);
const double EPS=1e-8;
const int inf=1e9;
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pii;
int n,m;
vi in;
int ma(){
	int t=1;
	rep(i,m)t*=in[i];
	int a=t;
	rep(i,n-m){
		t=t/in[i]*in[i+m];
		a=max(a,t);
	}
	return a;
}
int main(){
	while(cin>>n>>m,n+m){
		in=vi(n);
		rep(i,n)cin>>in[i];
		int a=ma(),b=0;
		rep(i,n)rep(j,n)if(i!=j){
			swap(in[i],in[j]);
			b=max(b,ma());
			swap(in[i],in[j]);
		}
		if(a>b)cout<<"NO GAME"<<endl;
		else cout<<b-a<<endl;
	}
}

Measured memory_bytes: 1216
#include <iostream>

int solve(int element_count, int sum, int range_max)
{
	if (element_count <= 1) {
		return (element_count == 1 && range_max >= sum) ? 1 : 0;
	}
	int result = 0;
	for (int max_element = element_count - 1; max_element <= range_max; ++max_element) {
		if (sum - max_element >= 0) {
			result += solve(element_count - 1, sum - max_element, max_element - 1);
		}
	}
	return result;
}

int main()
{
	int element_count, sum;
	while (std::cin >> element_count >> sum) {
		if (element_count == 0 && sum == 0) {
			break;
		}
		std::cout << solve(element_count, sum, 9) << std::endl;
	}

	return 0;
}

Measured memory_bytes: 1160