akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
const int INF = 1000000000;
#define REP(i,s,n) for(int i=(int)(s);i<(int)(n);i++)
#define rep(i,n) REP(i, 0, n)

struct UnionFind{
    vector <int> data;
    UnionFind(int N) : data(N, -1){}
    void unite(int x, int y){
        x = root(x); y = root(y);
        if(x != y){
            data[x] += data[y];
            data[y] = x;
        }
    }
    int root(int x){ return data[x] < 0 ? x : data[x] = root(data[x]);}
};

typedef pair<bool, int> pbt;;
bool marked[100000];
int p[100000];
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N, Q, _t;
    char _c;
    while(cin >> N >> Q && N){
        memset(marked, 0, sizeof(marked));
        marked[0] = true;;
        UnionFind uf(N);
        vector<pbt> query;
        
        REP(i, 1, N){
            cin >> p[i];
            --p[i];
        }
        rep(i, Q){
            cin >> _c >>_t;
            --_t;
            if(_c == 'Q')
              query.push_back(pbt(1, _t));
            else if(!marked[_t]){
                query.push_back(pbt(0, _t));
                marked[_t] = true;
            }
        }

        rep(i, N)
          if(!marked[i])
            uf.unite(p[i], i);
        ll sum = 0LL;
        for(int i = query.size() - 1; i >= 0; --i){
            int v = query[i].second;
            if(query[i].first)
              sum += uf.root(v) + 1;
            else
              uf.unite(p[v], v);
        }
        cout << sum << endl;
    }
    return 0;
}

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

using namespace std;
using P=tuple<int, int>;

class Solver {

};

int main() {
	while (true) {
		int w, h;
		cin >> w >> h;
		if (w == 0)break;

		vector<vector<bool>> grid(h, vector<bool>(w, true));
		P start, goal;
		for (int i = 0; i < h; i++) {
			for (int j = 0; j < w; j++) {
				int val;
				cin >> val;
				if (val == 1)grid[i][j] = false;
				if (val == 2) {
					start = make_tuple(i, j);
				}
				if (val == 3) {
					goal = make_tuple(i, j);
				}
			}
		}

		queue<tuple<P, int, vector<P>>> que;
		vector<P> breaks;
		que.emplace(make_tuple(start, 0, breaks));
		bool valid = false;
		//vector<vector<bool>> visited(h, vector<bool>(w, false));
		while (que.size() > 0) {
			P pos = get<0>(que.front());
			int y = get<0>(pos);
			int x = get<1>(pos);
			int cnt = get<1>(que.front());
			vector<P> breaks = get<2>(que.front());

			que.pop();
			//if (visited[y][x])continue;
			if (cnt >= 10)continue;

			//if (cnt > 0)visited[y][x] = true;
			vector<vector<bool>> status(h, vector<bool>(w, true));
			for (int i = 0; i < h; i++) {
				for (int j = 0; j < w; j++) {
					status[i][j] = grid[i][j];
				}
			}
			for (int i = 0; i < breaks.size(); i++) {
				int y = get<0>(breaks[i]);
				int x = get<1>(breaks[i]);
				status[y][x] = true;
			}

			for (int i = y + 1; i < h; i++) {
				if (!status[i][x])break;
				if (make_tuple(i, x) == goal) {
					cout << cnt + 1 << endl;
					valid = true;
					break;
				}
				if (i + 1 < h && !status[i + 1][x]) {
					P now = make_tuple(i, x);
					if (i + 1 < h)breaks.emplace_back(make_tuple(i + 1, x));
					que.emplace(make_tuple(now, cnt + 1, breaks));
					if (i + 1 < h)breaks.pop_back();
				}
			}
			for (int i = y - 1; i >= 0; i--) {
				if (!status[i][x])break;
				if (make_tuple(i, x) == goal) {
					cout << cnt + 1 << endl;
					valid = true;
					break;
				}
				if (i - 1 >=0 && !status[i - 1][x]) {
					P now = make_tuple(i, x);
					if (i - 1 >= 0)breaks.emplace_back(make_tuple(i - 1, x));
					que.emplace(make_tuple(now, cnt + 1, breaks));
					if (i - 1 >= 0)breaks.pop_back();
				}
			}
			for (int i = x + 1; i < w; i++) {
				if (!status[y][i])break;
				if (make_tuple(y, i) == goal) {
					cout << cnt + 1 << endl;
					valid = true;
					break;
				}
				if (i + 1 <w && !status[y][i + 1]) {
					P now = make_tuple(y, i);
					if (i + 1 < w)breaks.emplace_back(make_tuple(y, i + 1));
					que.emplace(make_tuple(now, cnt + 1, breaks));
					if (i + 1 < w)breaks.pop_back();
				}
			}
			for (int i = x - 1; i >= 0; i--) {
				if (!status[y][i])break;
				if (make_tuple(y, i) == goal) {
					cout << cnt + 1 << endl;
					valid = true;
					break;
				}
				if (i - 1 >=0 && !status[y][i - 1]) {
					P now = make_tuple(y, i);
					if (i - 1 >= 0)breaks.emplace_back(make_tuple(y, i - 1));
					que.emplace(make_tuple(now, cnt + 1, breaks));
					if (i - 1 >= 0)breaks.pop_back();
				}
			}
			if (valid)break;
		}
		if (!valid)cout << -1 << endl;
	}
}


Measured memory_bytes: 13084
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using pli = pair<ll, int>;
using pil = pair<int, ll>;
using uint = unsigned int;
template <typename T>
using Graph = vector<vector<T>>;
const int MOD = 1e9 + 7;
const ld PI = acosl(-1);

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

    string S, T;
    cin >> S >> T;
    int N = S.length();
    int ans = 0;
    for (int i = 0; i < N; ++i)
        ans += S[i] != T[i];
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3836
n = int(input())
a = [int(_) for _ in input().split()]

a.insert(0,0)
a.append(0)

cost = 0
for i in range(n+1):
    cost += abs(a[i+1]-a[i])

for i in range(1,n+1):
    print(cost + abs(a[i+1]-a[i-1]) - abs(a[i+1]-a[i]) -abs(a[i]-a[i-1]))

Measured memory_bytes: 14176
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,l,r) for(long long i=(l);i<(r);++i)
#define REP(i,n) FOR(i,0,n)
#define int long long
#define pb push_back
#define mp make_pair
const int MOD=1e9+7;
const int INF=1e15;

signed main(){
    int W,H,N;cin>>W>>H>>N;
    int l=0;int s=0;int u=H;int r=W;
    REP(i,N){
        int x,y,a;cin>>x>>y>>a;
        if(a==1)l=max(l,x);
        if(a==2)r=min(r,x);
        if(a==3)s=max(s,y);
        if(a==4)u=min(u,y);
    }
    int H2=u-s;
    if(H2<0)H2=0;
    int W2=r-l;
    if(W2<0)W2=0;
    cout<<H2*W2<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
// #include <boost/multiprecision/mpfr.hpp>  // Defines the Backend type that wraps MPFR
#define pb push_back
#define mp make_pair
#define forn(i,a,b) for(int i =a;i<b;i++)
#define fi first
#define se second
#define fast ios_base::sync_with_stdio(false);

// namespace mp = boost::multiprecision;     // Reduce the typing a bit later...
using namespace std;


int main(){
	int n;
	cin >> n;
	int a[n];
	forn(i,0,n)
		cin >> a[i];

	int cur[21];int r= -1;
	memset(cur,0,sizeof(cur));
	auto ok = [&](int b){
		int c = 0;
		int cpya= a[b];
		int cpycur[21];
		memcpy(cpycur,cur,sizeof(cpycur));
		while(cpya>0){
			if(cpya&1)
			{
				if(cpycur[c]>0)
					return false;
				else
					cpycur[c] = 1;
			}
			c++;
			cpya>>=1;
		}
		memcpy(cur,cpycur,sizeof(cur));		return true;
	};
	long long ans =  0;
	int l =0;
	while(l<n){
		r++;
		// cout << r << endl;
		while(r<n && ok(r)){
			// chg = 1;
			r++;
		}
		r--;
		ans+=(r-l+1);
		// for(int i =0;i<3;i++){
		// 	cout << cur[i] << " ";
		// }
		// cout << endl;
		int c= 0;
		while(a[l]>0){
			if(a[l]&1)
				cur[c]=0;

			c++;
			a[l]>>=1;
		}
		// 	for(int i =0;i<3;i++){
		// 	cout << cur[i] << " ";
		// }
		// cout << endl;
		// r= max(l,r);
		// int chg = 0;
		// while(r<n && ok(r+1)){
		// 	chg = 1;
		// 	r++;
		// }
		// ans+=(r-l+1);
		// int c= 0;
		// while(a[l]>0){
		// 	if(a[l]&1)
		// 		cur[c]=0;
		// 	c++;
		// 	a[l]>>=1;
		// }
		// r++;
		// cout << l << " " << r << endl;
		l++;
	}
	cout << ans << endl;
}

Measured memory_bytes: 4408
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vl = vector<ll>;
using vvl = vector<vl>;
using vb = vector<bool>;
#define FOR(i,a,b) for(ll i = (a); i < (b); i++)
#define all(s) (s).begin(),(s).end()

ll n, k;
vl logs;
bool test(ll target) {   
    ll output = 0;
    for(ll curr : logs) {
        if(target + curr - 1 == 0) cout << "blub" << endl;
        output += ((target + curr - 1)/target) - 1;
    }

    return output <= k;
}

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

    ll mini = 1;
    ll maxi = 0;

    FOR(i, 0, n) {
        ll next; cin >> next;
        logs.push_back(next);
        maxi = max(maxi, next);
    }

    while(abs(maxi - mini) >= 1) {
        ll mid = (maxi + mini) / 2;

        if(test(mid)) {
            maxi = mid;
        } else {
            mini = mid+1;
        }
    }
    
    cout << maxi << endl;

    /*FOR(i, 0, k) {
        ll next = logs.top();
        logs.pop();

        ll a, b;
        ll other = logs.top();
        if(other == next) {
            a = next / 2;
            b = next - a;
        } else {
            a = other;
            b = next - a;
        }

        a = next / 2;
        b = next - a;
        cerr << a << " " << b << endl;
        
        logs.push(a);
        logs.push(b);
    }*/

    /*while(!logs.empty()) {
        cout << logs.top() << endl;
        logs.pop();
    }*/

    //cout << logs.top() << endl;
}

Measured memory_bytes: 5300
#include<bits/stdc++.h>
using namespace std;
int main(){
	long long  n,w;
	cin>>n>>w;
	long long a[n],cost[n];
	for(int i=0;i<n;i++){
		cin>>a[i]>>cost[i];
	}
	long long  dp[n+1][w+1]={0};
	for(int i=0;i<=n;i++){
		for(int j=0;j<=w;j++){
			if(i==0||j==0){
				dp[i][j]=0;
			}
			else{
				int op1,op2;
//				op1=dp[i-1][j];
				if(a[i-1]<=j){
					dp[i][j]=max(dp[i-1][j],dp[i-1][j-a[i-1]]+cost[i-1]);
				}
				else{
					dp[i][j]=dp[i-1][j];
				}
//				dp[i][j]=max(op1,op2);
			}
		}
	}
	cout<<dp[n][w]<<" ";
}

Measured memory_bytes: 79104
module Main where
import Debug.Trace
import Data.List
import qualified Data.Sequence as S
import qualified Data.ByteString.Char8 as B
import Data.Int
import Data.Char
import Data.Array
import Data.Maybe
import qualified Data.Map as M
import Data.Ord
import Data.Functor
import Control.Applicative
import Control.Monad

fib :: Int -> Int
fib = iter (listArray (0, 44) [x| x <- 1:1:(replicate 43 0)]) 2 where
    iter ar i n 
        | i <= n = iter (ar // [(i, ar!(i-1) + ar!(i-2))]) (i+1) n
        | otherwise = ar!n

readIntLn:: IO Int
readIntLn = (fst . fromJust . B.readInt) <$> B.getLine

main :: IO() 
main = do
    n <- readIntLn
    print $ fib n



Measured memory_bytes: 3584
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <unordered_map>
#include <utility>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <cstdio>
#include <math.h>
#include <stdio.h>
#include <deque>

using namespace std;

#define REP(i,n,m) for( long long int i = (n); i < (m); i++ )
#define REV(v) for (auto itr = v.rbegin(); itr != v.rend(); itr++)
#define ll long long
#define ALL(a) (a).begin(), (a).end()
#define SORT(v) sort( ALL(v) );
#define LAST(v) v[v.size()-1]
#define ZERO(a) memset(a,0,sizeof(a));
#define MINUS(a) memset(a,-1,sizeof(a));
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define pi pair<int, int>
#define MP make_pair
#define PB push_back
#define EB emplace_back
#define IIN(a) int a; cin >> a;
#define LIN(a) ll a; cin >> a;
#define SIN(a) string a; cin >> a;
#define VL(v,n) vector<ll> v(n);
#define Read_VL(v,n) vector<ll> v(n);REP(i,0,n)cin>>v[i];
#define sumV(v,n) Vl(acm,n) REP(i,0,n) acm[i] = v[i] + ( i == 0 ? 0 : acm[i - 1]);
#define EPS (1e-10)
#define INF 1000000000000LL

void YN(bool b){cout<<(b?"YES":"NO")<<"\n";}
void Yn(bool b){cout<<(b?"Yes":"No")<<"\n";}
void yn(bool b){cout<<(b?"yes":"no")<<"\n";}

template<class S>S max(vector<S>&a){return *max_element(all(a));}
template<class S>S min(vector<S>&a){return *min_element(all(a));}

template<class T>void puta(T&&t){cout<<t<<"\n";}
template<class H,class...T>void puta(H&&h,T&&...t){cout<<h<<' ';puta(t...);}


template<class T=ll>struct Graph{
	int n;
	vector<vector<tuple<ll,T>>>edge;
	Graph(int N=1):n(N){edge.resize(n);}
	void add(ll f,ll t,T c,bool d=false){
		edge[f].emplace_back(t,c);
		if(!d)edge[t].emplace_back(f,c);
	}
	void view(){
		REP(i,0,n)for(auto&e:edge[i])
			puta(i,"=>",get<0>(e),", cost :",get<1>(e));
	}
};


bool length_cmp( string &a, string &b ){
  return a.size() < b.size();
}

ll StoLL( string s )
{
	ll num=0;
  REP( i, 0, s.size() ){
    num = num * 10 + ( s[i] ^ 48 );
  }
  return num;
}

ll CtoLL( char c )
{
	if( 'a' <= c && c <= 'z'){
		return (ll)( c ^ 96 ) ;
	}
	else if( 'A' <= c && c <= 'Z'){
		return (ll)( c ^ 64 );
	}
  return 0;
}


ll mod=1000000007;
ll dx[4] = { 1, 0, -1, 0 };
ll dy[4] = { 0, 1, 0, -1 };
//I ASCII code: '0' = 48; 'A' = 65; 'a' = 97


struct person{
	string name;
	ll height;
};

bool p_operator( person &a, person &b ){
	return a.name < b.name;
}

#include <chrono>
signed main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    LIN(a) LIN(b)
    Yn( a % 2 != 0 && b % 2 != 0 );
    return 0;
}


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

using VI = vector<int>;
using VVI = vector<VI>;
using PII = pair<int, int>;
using LL = long long;
using VL = vector<LL>;
using VVL = vector<VL>;
using PLL = pair<LL, LL>;
using VS = vector<string>;

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define MT make_tuple
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

#define FF first
#define SS second

#define DUMP(x) cout<<#x<<":"<<(x)<<endl
template<class S, class T>
istream& operator>>(istream& is, pair<S,T>& p){
  return is >> p.FF >> p.SS;
}
template<class T>
istream& operator>>(istream& is, vector<T>& xs){
  for(auto& x: xs)
	is >> x;
  return is;
}
template<class S, class T>
ostream& operator<<(ostream& os, const pair<S,T>& p){
  return os << p.FF << " " << p.SS;
}
template<class T>
ostream& operator<<(ostream& os, const vector<T>& xs){
  for(unsigned int i=0;i<xs.size();++i)
	os << (i?" ":"") << xs[i];
  return os;
}
template<class T>
void maxi(T& x, T y){
  if(x < y) x = y;
}
template<class T>
void mini(T& x, T y){
  if(x > y) x = y;
}


const double EPS = 1e-10;
const double PI  = acos(-1.0);
const LL MOD = 1e9+7;

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

  int N;
  cin >> N;
  VI xs(N);
  cin >> xs;

  vector<bool> used(N);
  VI len(N+1, 1);
  for(int x: xs){
	if(used[x-1]) len[x] = len[x-1]+1;
	used[x] = true;
  }

  int ans = 0;
  REP(i,N+1) maxi(ans, len[i]);
  cout << N-ans << endl;

  return 0;
}


Measured memory_bytes: 1920
/*
Arthor : Ender_zzm
E-mail zzm_ender_wiggin@outlook.com
Blog oi.ender-zzm.pro
*/
#include <bits/stdc++.h>
using namespace std;

template<class T>
inline void read(T &a) {
    register T x = 0, flag = 1;
    register char ch;
    while (!isdigit(ch = getchar())) if (ch == '-') flag = -1;
    while (x = x * 10 + (ch & 15), isdigit(ch = getchar()));
    a = x * flag;
}

template <class T>
inline void write(T x) {
    if (x < 0)
        putchar('-'), x = -x;
    if(x >= 10) write(x / 10); 
    putchar(x % 10 + '0');
}

template<class T> inline bool Chkmax(T& x, const T& y) { return x < y ? x = y, true : false; }
template<class T> inline bool Chkmin(T& x, const T& y) { return x > y ? x = y, true : false; }

#define For(i, a, b) for (int i = (a); i <= (b); i++) 
#define Rep(i, a, b) for (int i = (a); i >= (b); i--) 
#define For_edge(x) for (int i = head[x]; i; i = net[i])
#define mem0(a) memset(a, 0, sizeof a)

#define int long long
const int maxn = 5010;
int n;
int a[maxn];
int Sum[maxn][4];
string s;

int Id (char c) {
	if (c == 'R') return 1;
	if (c == 'G') return 2;
	else return 3;
}
signed main() {
	cin >> n;
	cin >> s;
	int ans = 0;
	For (i, 0, n - 1) {
		a[i + 1] = Id(s[i]);
	}
	For (i, 1, n) {
		Sum[i][1] = Sum[i - 1][1], Sum[i][2] = Sum[i - 1][2], Sum[i][3] = Sum[i - 1][3];
		Sum[i][a[i]] ++;
	}
	For (i, 1, n) {
		For (j, i + 1, n) {
			if (a[i] == a[j]) continue;
			int tmp = 6 - a[i] - a[j];
			if (tmp == a[i] || tmp == a[j]) continue;
			ans += Sum[i - 1][tmp];
			//i - k == j - i\
			//k - i == i - j
			//k == 2 * i - j
			int pos = 2 * i - j;
			if (pos < 1 || pos > n) continue;
			if (a[pos] == tmp) ans --;
		}
	}
	cout << ans;
}


Measured memory_bytes: 3808
n,m = map(int,input().split())
A = [0 for i in range(n)]
B = [0 for i in range(m)]
for i in range(n):
    A[i] = list(map(int,input().split()))
for i in range(m):
    B[i] = int(input())

for i in range(n):
    a = 0
    for j in range(m):
        a += A[i][j]*B[j]
    print(a)


Measured memory_bytes: 6020
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#include <string.h>


int main(void)
{
	//変数の宣言
	int a,b;
	int i,j,k;
	
	//データの読み込み
	scanf("%d %d",&a,&b);
	
	
	
//	printf("nは%dです\n", n);
//	printf("データの読み込み終了\n");
	//実際の処理
	
	if(a==1&&b==1){
		printf("2 2\n##\n..");
	}else if(a!=1&&b!=1){
		printf("100 100\n");
		a=a-2;
		b=b-2;
		for(i=0;i<50;i++){
			for(j=0;j<50;j++){
				if(i%2==0&&j%2==0){
					if(a>0){
						printf(".");
						a=a-1;
					}else{
						printf("#");
					}
				}else{
					printf("#");
				}
			}
			for(j=0;j<50;j++){
				if(i%2==0&&j%2==1){
					if(b>0){
						printf("#");
						b=b-1;
					}else{
						printf(".");
					}
				}else{
					printf(".");
				}
			}
			printf("\n");
		}
		for(i=0;i<50;i++){
			for(j=0;j<50;j++){
				printf(".");
			}
			for(j=0;j<50;j++){
				printf("#");
			}
			printf("\n");
		}
	}else if(a==1){
		printf("100 100\n");
		b=b-1;
		for(i=0;i<50;i++){
			for(j=0;j<50;j++){
				printf("#");
			}
			for(j=0;j<50;j++){
				if(i%2==0&&j%2==1){
					if(b>0){
						printf("#");
						b=b-1;
					}else{
						printf(".");
					}
				}else{
					printf(".");
				}
			}
			printf("\n");
		}
		for(i=0;i<50;i++){
			for(j=0;j<50;j++){
				printf("#");
			}
			for(j=0;j<50;j++){
				printf("#");
			}
			printf("\n");
		}
	}else{
		printf("100 100\n");
		a=a-1;
		for(i=0;i<50;i++){
			for(j=0;j<50;j++){
				if(i%2==0&&j%2==0){
					if(a>0){
						printf(".");
						a=a-1;
					}else{
						printf("#");
					}
				}else{
					printf("#");
				}
			}
			for(j=0;j<50;j++){
				printf(".");
			}
			printf("\n");
		}
		for(i=0;i<50;i++){
			for(j=0;j<50;j++){
				printf(".");
			}
			for(j=0;j<50;j++){
				printf(".");
			}
			printf("\n");
		}
	}
	
	
		
//	printf("計算部分終了\n");
	
	//出力
	
	//	printf("%ld",ans);
	
//	printf("結果の出力終了\n");
	
	return 0;
}


Measured memory_bytes: 128
# AGC033A - Darker and Darker (PyPy 400ms)
def bfs() -> None:
    dxy = [(1, 0), (-1, 0), (0, 1), (0, -1)]
    cur, q = 0, []
    # append default blacks to a queue
    q = [(x, y) for x in range(H) for y in range(W) if B[x][y] == 0]
    while q:  # append new blacks until all whites become black
        next_q = []
        for x, y in q:
            for dx, dy in dxy:
                nx, ny = x + dx, y + dy
                if 0 <= nx < H and 0 <= ny < W and B[nx][ny] == -1:
                    B[nx][ny] = cur + 1
                    next_q.append((nx, ny))
        q = next_q
        cur += 1
    return cur - 1


def main():
    global H, W, B
    H, W, *A = open(0).read().split()
    H, W = int(H), int(W)
    # default blacks: 0, whites: -1
    B = [[0 if i == "#" else -1 for i in a] for a in A]
    ans = bfs()
    print(ans)


if __name__ == "__main__":
    main()

Measured memory_bytes: 111468
n,x = map(int,input().split())
x_list = list(map(int,input().split()))
x_list.append(x)
x_list.sort()
sa_list = []
for i in range(1,n+1):
  sa = x_list[i] - x_list[i-1]
  sa_list.append(sa)
from fractions import gcd
from functools import reduce
def gcd_list(numbers):
    return reduce(gcd, numbers)

print(gcd_list(sa_list))




Measured memory_bytes: 15020
#include<bits/stdc++.h>
using namespace std;
#define INF 100010
typedef pair<int,int> P;
vector<int> G[100010];
vector<int> GG[100010];
int V,E,n;
int ord[100010];
int low[100010];
int par[100010];

int lowlink(int x,int p){
  ord[x]=n++,par[x]=p;
  int ans=ord[x];
  for(int i=0;i<G[x].size();i++){
    if(G[x][i]==p)continue;
    if(ord[G[x][i]]!=INF)ans=min(ord[G[x][i]],ans);
    else {
      ans=min(ans,lowlink(G[x][i],x));
      GG[x].push_back(G[x][i]);
    }
  }
  return low[x]=ans;
}

int main(){
  for(int i=0;i<100010;i++)
    low[i]=ord[i]=INF;
  cin>>V>>E;
  P p[100010];
  for(int i=0;i<E;i++){
    int s,t;
    cin>>s>>t;
    G[s].push_back(t);
    G[t].push_back(s);
    if(s>t)swap(s,t);
    p[i]=P(s,t);
  }
  sort(p,p+E);
  lowlink(0,-1);
  for(int i=0;i<V;i++){
    int f=0;
    if(i==0&&GG[0].size()>1)f=1;
    if(i!=0)
      for(int j=0;j<GG[i].size();j++){
	if(GG[i][j]==par[i])continue;
	if(low[GG[i][j]]>=ord[i])f=1;
	//cout<<i<<" "<<G[i][j]<<" "<<low[i]<<" "<<low[G[i][j]]<<" "<<f<<endl;
      }
    //cout<<low[i]<<endl;
    if(f)cout<<i<<endl;
  }
  return 0;
}



Measured memory_bytes: 11028
#include<iostream>
#include<stdio.h>
#include<string>
#include<vector>
#include<iosfwd>
#include<sstream>
#define N 100
using namespace std;
int main(void){
    int a,b,c;
    cin >> a >> b >> c;
    if((a<c && c<b) || (b<c && c<a))  cout << "Yes" <<endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 504
n = int(input())
a = list(map(int, input().split()))
cnt4,cnt2=0,0
for i in a:
    if i % 4 == 0:
        cnt4 += 1
    elif i % 2 == 0:
        cnt2 += 1

cnt2 = max(1,cnt2)
print('Yes' if 2 * cnt4 + cnt2 >= n else 'No')

Measured memory_bytes: 14380
#include<iostream>
#include<string>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<vector>
#include<functional>
#include<iomanip>
#include<queue>
#include<cassert>
#include<tuple>
#include<set>
#include<map>
#include<list>
#include<bitset>
#include<utility>
#include<numeric>

#define PB push_back
#define all(a)  (a).begin(),(a).end()
#define ALL(v) begin(v), end(v)
#define DWN(a)  (a).begin(),(a).end(), greater<int>()
#define rep(i, m) for (int i = 0; i < m; i++)
#define REP(i, n, m) for (int i = n; i < m; i++)
#define V vector<int>
#define VV vector<V>
#define VVV vector<VV>

using namespace std;

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

const int dx[4] = { 1, 0, -1, 0 };
const int dy[4] = { 0, 1, 0, -1 };
const int inf = (int)1e9;
const ll INF = (ll)1e18;
const ll MOD{ (ll)1e9 + 7 };
const long double EPS = 1e-10;

int N, M, Q;
int p[510][510] = {};

int main() {
	cin >> N >> M >> Q;
	
	for (int i = 1; i <= M; i++) {
		int L, R;
		cin >> L >> R;
		p[L][R]++;
	}

	for (int i = 1; i <= N; i++) {
		for (int j = 1; j <= N; j++) {
			p[i][j] += p[i][j - 1];
		}
	}

	for (int i = 1; i <= N; i++) {
		for (int j = 1; j <= N; j++) {
			p[i][j] += p[i - 1][j];
		}
	}

	for (int i = 1; i <= Q; i++) {
		int L, R;
		cin >> L >> R;
		cout << p[R][R] + p[L - 1][L - 1] - p[L - 1][R] - p[R][L - 1] << endl;
	}

	return 0;
}


Measured memory_bytes: 1920
if __name__ == "__main__":

    n = int(input())
    a_list = map(int, input().split())
    a_list_sorted = sorted(a_list)
    
    sum = (a_list_sorted[0] + a_list_sorted[1])/2 
    for i, a in enumerate(a_list_sorted):
        if i >= 2:
            sum = (sum + a)/2

    print('{0}'.format(sum))    


Measured memory_bytes: 3060
#include <stdio.h>

int main(void){
	int data[2];
	int i;
	int a, b, c;
	int num=0;
	
	while(1){
		scanf("%d %d", &data[0], &data[1]);
		if(data[0] == 0 && data[1] == 0){
			return 0;
		}
		
		a = 1;
		num = 0;
		for(a=1 ; a <= data[0] ; a++){
			for(b=1 ; b <= data[0] ; b++){
				c = data[1] - a - b;
				if(a == b || b == c || c == a){
					
				}
				else if(c <= 0 || c > data[0]){
					
				}
				else if(a < b && b < c){
					//printf("%d+%d+%d=%d\n", a, b, c, a+b+c);
					num++;
				}
				else{
					
				}
			}
		}
		printf("%d\n", num);
	}
	
	return 0;
}

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

#define _GLIBCXX_DEBUG
#define all(v) (v).begin(),(v).end()

using namespace std;

using ll=long long;
using pii=pair<int, int>;
using vi=vector<int>;
using vii=vector<vector<int>>;

const ll LINF=1LL<<60;
const int INF=1<<29;
const ll MOD=1e9+7;

int main(){
    int N; cin >> N;
    for(int i=1; i<=9; i++){
        if(N%i == 0 && N/i <= 9){
            cout  << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" <<endl;
    return 0;
}

Measured memory_bytes: 3632
#include<iostream>
#include<algorithm>
#include<math.h>
#include<string>
using namespace std;
int main(){
long long int A, B, C, D ,E ,F, N,M;
long long V[10000000] = {};
long long G[10000000] = {};
string S,Sa,Sb,Sc;
bool ans = true;
cin >> A >> B;
cout << (A - 1) * (B - 1) << endl;

return 0; 
}


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

using namespace std;

#define INF 1001000100010001000
#define MOD 1000000007
#define EPS 1e-10
#define int long long
#define rep(i, N) for (int i = 0; i < N; i++)
#define Rep(i, N) for (int i = 1; i < N; i++)
#define For(i, a, b) for (int i = (a); i < (b); i++)
#define pb push_back
#define eb emplece_back
#define mp make_pair
#define i_i pair<int, int>
#define vi vector<int>
#define vvi vector<vi >
#define vb vector<bool>
#define vvb vector<vb >
#define vp vector< i_i >
#define all(a) (a).begin(), (a).end()
#define Int(x) int x; cin >> x;
#define int2(x, y) Int(x); Int(y);
#define int3(x, y, z) Int(x); int2(y, z);
#define fir first
#define sec second
#define ffir first.first
#define fsec first.second
#define sfir second.first
#define ssec second.second

//int dxy[5] = {0, 1, 0, -1, 0};
// cmd

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

    int2(n, m);
    double yui = pow(0.5, m), per = pow(0.5, m);
    double ans = 0;
    int k = (n - m) * 100 + m * 1900;

    Rep(i, 100000) {
        ans += (k * i) * per;
        //cout << ans << " " << per << endl;
        //per *= yui;
        per = per * (1 - yui);
    }

    printf("%.0lf\n", ans);
    //cout << ans << endl;

    return 0;
}




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

int n,k;
vector<ll >vec;
void input();

void solve(){
    ll sum=0;
    sort(vec.begin(),vec.end());
    for(int i=0;i<k;i++){
        sum+=vec[i];
    }
    cout<<sum<<"\n";
}

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

}

void input(){
    cin>>n>>k;

    for(int i=0;i<n;i++){
        ll a;
        cin>>a;
        vec.push_back(a);
    }
}


Measured memory_bytes: 3652
#include<cstdio>
#include<cstring>
#include<vector>
#include<queue>
#include<algorithm>
#include<cmath>
#include<climits>
#include<string>
#include<set>
#include<numeric>
#include<map>
#include<iostream>
using namespace std;
#define rep(i,n) for(int i = 0;i<((int)(n));i++)
#define reg(i,a,b) for(int i = ((int)(a));i<=((int)(b));i++)
#define irep(i,n) for(int i = ((int)(n)-1);i>=0;i--)
#define ireg(i,a,b) for(int i = ((int)(b));i>=((int)(a));i--)
typedef long long ll;
typedef pair<ll, ll> mp;



int main(void){
	string S,T;
	cin>>S>>T;
	//後ろから探して，入ったら，ほかの場所は全てa
	irep(i,S.size()-T.size()+1){
		bool can=true;
		rep(j,T.size()){
			if(S[i+j]!=T[j] && S[i+j]!='?')can=false;
		}
		if(can){
			rep(j,T.size()){
				S[i+j]=T[j];
			}
			rep(j,S.size()){
				if(S[j]=='?')S[j]='a';
			}
			cout<<S<<endl;
			return 0;
		}
	}
	printf("UNRESTORABLE\n");
	return 0;
}

Measured memory_bytes: 256
N = int(input())
BAs = []
for n in range(N):
    A, B = [int(s) for s in input().split(' ')]
    BAs.append((B, A))
BAs.sort()
time = 0
count = 0
for B, A in BAs:
    time += A
    if time > B:
        break
    else:
        count += 1
if count == N:
    print('Yes')
else:
    print('No')


Measured memory_bytes: 29492
N=int(input())
V=[]
a,b=0,0
for i in range(N):
  V.append(list(map(int,input().split())))
V.sort(key=lambda x: x[1])
for i in range(N):
  a=a+V[i][0]
  if a>V[i][1]:
    b=b+1
if b==0:
  print("Yes")
else:
  print("No")

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

const int MAXH = 13;
const int MAXW = 13;
const int di[] = {1,0,-1,0};
const int dj[] = {0,1,0,-1};
const int INF = 1<<28;

int W, H;
char G[MAXH][MAXW];
int si, sj, ti, tj;
int N;
int ice[MAXH][MAXW];
int ans;
bool vis[MAXH][MAXW];
int cnt[1000];
int fromG[MAXH][MAXW];

int dfs(int pi, int pj, int n) {
  int res = 1;
  ice[pi][pj] = n;
  for(int k = 0; k < 4; ++k) {
    int ni = pi + di[k];
    int nj = pj + dj[k];
    if(ni < 0 || ni >= H) continue;
    if(nj < 0 || nj >= W) continue;
    if(G[ni][nj] != 'X') continue;
    if(ice[ni][nj] != -1) continue;
    res += dfs(ni, nj, n);
  }
  return res;
}

void bfs(int si, int sj) {
  queue<pair<int,int> > que;
  fill(fromG[0], fromG[MAXH], INF);
  que.push(make_pair(si,sj));
  fromG[si][sj] = 0;
  while(que.size()) {
    int pi = que.front().first;
    int pj = que.front().second;
    que.pop();
    for(int k = 0; k < 4; ++k) {
      int ni = pi + di[k];
      int nj = pj + dj[k];
      if(ni < 0 || ni >= H) continue;
      if(nj < 0 || nj >= W) continue;
      if(G[ni][nj] == '#') continue;
      if(fromG[ni][nj] != INF) continue;
      que.push(make_pair(ni,nj));
      fromG[ni][nj] = fromG[pi][pj] + 1;
    }
  }
}

void dfs2(int pi, int pj, int previ, int prevj, int cost) {
  if(cost+fromG[pi][pj] >= ans) return;
  if(pi == ti && pj == tj) {
    ans = min(ans, cost);
    return;
  }
  for(int k = 0; k < 4; ++k) {
    int ni = pi + di[k];
    int nj = pj + dj[k];
    if(ni < 0 || ni >= H) continue;
    if(nj < 0 || nj >= W) continue;
    if(ni == previ && nj == prevj) continue;
    if(vis[ni][nj]) return;
  }

  vis[pi][pj] = true;
  for(int k = 0; k < 4; ++k) {
    int ni = pi + di[k];
    int nj = pj + dj[k];
    if(ni < 0 || ni >= H) continue;
    if(nj < 0 || nj >= W) continue;
    if(vis[ni][nj]) continue;
    if(G[ni][nj] == '#') continue;
    if(G[ni][nj] == 'X' && cnt[ice[ni][nj]] == 0) continue;

    if(G[ni][nj] == 'X') cnt[ice[ni][nj]] -= 1;
    dfs2(ni, nj, pi, pj, cost+1);
    if(G[ni][nj] == 'X') cnt[ice[ni][nj]] += 1;
  }
  vis[pi][pj] = false;
}

int main() {
  while(cin >> W >> H && (W|H)) {
    for(int i = 0; i < H; ++i) {
      for(int j = 0; j < W; ++j) {
        cin >> G[i][j];
        if(G[i][j] == 'S') {
          si = i;
          sj = j;
          G[i][j] = '.';
        }
        if(G[i][j] == 'G') {
          ti = i;
          tj = j;
          G[i][j] = '.';
        }
      }
    }
    fill(ice[0], ice[MAXH], -1);
    N = 0;
    for(int i = 0; i < H; ++i) {
      for(int j = 0; j < W; ++j) {
        if(G[i][j] == 'X' && ice[i][j] == -1) {
          cnt[N] = dfs(i, j, N)/2;
          if(cnt[N] == 0) {
            ice[i][j] = -1;
            G[i][j] = '#';
          } else {
            ++N;
          }
        }
      }
    }
    bfs(ti, tj);
    ans = INF;
    fill(vis[0], vis[MAXH], 0);
    dfs2(si, sj, -1, -1, 0);
    cout << ans << endl;
  }
  return 0;
}

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

/*
unsigned seed1 = std::chrono::system_clock::now().time_since_epoch().count();
mt19937 g1.seed(seed1);

ios_base::sync_with_stdio(false);
cin.tie(NULL);
*/
using namespace std;

const double PI = 2 * acos(0);

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef long double ld;
typedef vector<vector<ll>> matrix;

int n;
ll x[1005];
ll y[1005];

int main() {
  scanf("%d", &n);
  set<ll> parity;
  ll maxS = 0;
  for(int i = 0; i < n; i++) {
    scanf("%lld %lld", &x[i], &y[i]);
    ll s = abs(x[i]) + abs(y[i]);
    maxS = max(maxS, s);
    parity.insert(s%2);
  }
  if(parity.size() == 2) {
    printf("-1\n");
    return 0;
  }
  vector<ll> all;
  all.push_back(1LL);
  maxS--;
  if(maxS%2) {
    all.push_back(1LL);
    maxS--;
  }
  ll curr = 2;
  while(maxS > 0) {
    maxS -= curr;
    all.push_back(curr);
    curr *= 2;
  }
  reverse(all.begin(), all.end());
  printf("%d\n", all.size());
  for(int i = 0; i < all.size(); i++) {
    printf("%lld", all[i]);
    if(i+1 == all.size()) printf("\n");
    else printf(" ");
  }
  for(int i = 0; i < n; i++) {
    for(ll out: all) {
      if(abs(x[i]) > abs(y[i])) {
        if(x[i] > 0) {
          x[i] -= out;
          printf("R");
        }
        else {
          x[i] += out;
          printf("L");
        }
      }
      else {
        if(y[i] > 0) {
          y[i] -= out;
          printf("U");
        }
        else {
          y[i] += out;
          printf("D");
        }
      }
    }
    printf("\n");
  }
}


Measured memory_bytes: 256
import math
def combination(n,r):
    return math.factorial(n) / (math.factorial(n-r) * math.factorial(r))

N,P = map(int,input().split())
A = list(map(int,input().split()))
odd = list(filter(lambda n:n%2==1, A))
even = list(filter(lambda n:n%2==0, A))
O = len(odd)
E = len(even)
O_a = 0
E_a = 0

for i in range(O+1):
    if i % 2 == 0:
        E_a += combination(O,i)
    else:
        O_a += combination(O,i)

if P == 0:
    print(int(2**E * E_a))
else:
    print(int(2**E * O_a))


Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD=1e9+7;
const int INF=1e9;

ll dp[101][100001];

int main(){
    int n,k;
    cin>>n>>k;
    int a[n];
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    dp[0][0]=1;
    for(int i=0;i<n;i++){
        dp[i+1][0]=1;
        for(int j=1;j<=a[i];j++){
            dp[i+1][j]=(dp[i+1][j-1]+dp[i][j])%MOD;
        }
        for(int j=a[i]+1;j<=k;j++){
            dp[i+1][j]=(dp[i+1][j-1]+dp[i][j]-dp[i][j-a[i]-1]+MOD)%MOD;
        }
    }
    cout<<dp[n][k]<<endl;
}

Measured memory_bytes: 78336
#include <iostream>

int main()
{
  int maxA=0;
  for(int &n=maxA;;n++)
  {
    if(n*n*n*n*n-(n-1)*(n-1)*(n-1)*(n-1)*(n-1)>1000000000)
    {
      break;
    }
  }
  int minA=0;
  for(int &n=minA;;n--)
  {
    if(n*n*n*n*n-(n-1)*(n-1)*(n-1)*(n-1)*(n-1)>1000000000)
    {
      break;
    }
  }
  int maxB=0;
  for(int &n=maxB;;n++)
  {
    if(n*n*n*n*n-(n-1)*(n-1)*(n-1)*(n-1)*(n-1)>1000000000)
    {
      break;
    }
  }
  int minB=0;
  for(int &n=minB;;n--)
  {
    if(n*n*n*n*n-(n-1)*(n-1)*(n-1)*(n-1)*(n-1)>1000000000)
    {
      break;
    }
  }
  
  int X;
  std::cin>>X;
  
  for(int A=minA;A<=maxA;A++)
  {
    for(int B=minB;B<=maxB;B++)
    {
      if(A*A*A*A*A-B*B*B*B*B==X)
      {
        std::cout<<A<<" "<<B<<std::endl;
        return 0;
      }
    }
  }
}

Measured memory_bytes: 3564
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <stdio.h>
#include <string>

using namespace std;

int main(){
  int N;
  cin >> N;
  vector<int> A(N);
  for(int i = 0; i < N; i++){
    cin >> A[i];
  }
  sort(A.begin(), A.end());
  cout << A[N - 1] - A[0] << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,k;
  cin >> n >> k;
  double a[n],ans,s[n],ke;
  s[0]=0.0;
  for(int i=1;i<=n;i++){
    cin >> a[i];
    double an=1+a[i];
    s[i]=an+s[i-1];
  }
  for(int i=0;i<=n-k;i++){
    ke=s[i+k]-s[i];
    ans=max(ke,ans);
  }
  printf("%.10f",ans/2);
}

Measured memory_bytes: 6908
#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <typeinfo>
#include <numeric>
#include <functional>
#include <unordered_map>
#include <bitset>
#include <stack>
#include <assert.h>


using namespace std;
using ll = long long;
using ull = unsigned long long;

const ll INF = 1e16;
const ll MOD = 1e9 + 7;

#define REP(i, n) for(ll i = 0; i < n; i++)








int main(){
    ll h, w, q;
    cin >> h >> w >> q;
    vector<string> s(h);
    REP(i, h){
        cin >> s[i];
    }
    
    vector<vector<ll>> blue(h + 1, vector<ll>(w + 1)), cnt1(h + 1, vector<ll>(w + 1)), cnt2(h + 1, vector<ll>(w + 1));
    REP(i, h){
        REP(j, w){
            if(s[i][j] == '0') continue;
            blue[i + 1][j + 1] = 1;
            if(i > 0 && s[i - 1][j] == '1'){
                cnt1[i + 1][j + 1]++;
            }
            if(j > 0 && s[i][j - 1] == '1'){
                cnt2[i + 1][j + 1]++;
            }
        }
    }
    
    REP(i, h + 1){
        REP(j, w){
            blue[i][j + 1] += blue[i][j];
        }
    }
    REP(i, h){
        REP(j, w + 1){
            blue[i + 1][j] += blue[i][j];
        }
    }
    
    REP(i, h + 1){
        REP(j, w){
            cnt1[i][j + 1] += cnt1[i][j];
            cnt2[i][j + 1] += cnt2[i][j];
        }
    }
    REP(i, h){
        REP(j, w + 1){
            cnt1[i + 1][j] += cnt1[i][j];
            cnt2[i + 1][j] += cnt2[i][j];
        }
    }
    
    /*
    cerr << endl << endl;
    REP(i, h + 1){
        REP(j, w + 1){
            cerr << blue[i][j] << ' ';
        }
        cerr << endl;
    }
    REP(i, h + 1){
        REP(j, w + 1){
            cerr << cnt1[i][j] << ' ';
        }
        cerr << endl;
    }
    REP(i, h + 1){
        REP(j, w + 1){
            cerr << cnt2[i][j] << ' ';
        }
        cerr << endl;
    }
    cerr << endl;
    */
    
    REP(i, q){
        ll x1, y1, x2, y2;
        cin >> x1 >> y1 >> x2 >> y2;
        ll t1 = (blue[x2][y2] - blue[x1 - 1][y2] - blue[x2][y1 - 1] + blue[x1 - 1][y1 - 1]);
        ll t2 = (cnt1[x2][y2] - cnt1[x1][y2] - cnt1[x2][y1 - 1] + cnt1[x1][y1 - 1]);
        ll t3 = (cnt2[x2][y2] - cnt2[x1 - 1][y2] - cnt2[x2][y1] + cnt2[x1 - 1][y1]);
        // cerr << t1 << endl;
        // cerr << t2 << endl;
        // cerr << t3 << endl;
        cout << t1 - t2 - t3 << endl;
    }
}

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

int main() {
  string A, B, C;
  cin >> A >> B >> C;
  if (A.at(A.size()-1)==B.at(0) && B.at(B.size()-1)==C.at(0))
    cout << "YES" << endl;
  else
    cout << "NO" << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <cmath>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <algorithm>
#define rep(i,n) for(int i=0; i<n; i++)
#define all(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
const ll mod=1e9+7;

int main(){
	string S;
	cin >> S;
	int ans;
	if(S=="SUN"){
		ans=7;
	}
	if(S=="MON"){
		ans=6;
	}
	if(S=="TUE"){
		ans=5;
	}
	if(S=="WED"){
		ans=4;
	}
	if(S=="THU"){
		ans=3;
	}
	if(S=="FRI"){
		ans=2;
	}
	if(S=="SAT"){
		ans=1;
	}

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

Measured memory_bytes: 256
using System;
using System.Collections.Generic;

namespace ABC050_B_Contest_with_Drinks_Easy
{
	internal class Program
	{
		public static void Main(string[] args)
		{
			int n = int.Parse(Console.ReadLine());
			string[] input = Console.ReadLine().Split(' ');
			List<int> tList = new List<int>(n);
			
			for (int i = 0; i < n; i++)
				tList.Add(int.Parse(input[i]));
			
			int m = int.Parse(Console.ReadLine());
			List<int> pList = new List<int>(m);
			List<int> xList = new List<int>(m);
			
			for (int i = 0; i < m; i++)
			{
				input = Console.ReadLine().Split(' ');
				pList.Add(int.Parse(input[0]));
				xList.Add(int.Parse(input[1]));
			}

			for (int i = 0; i < m; i++)
			{
				//インデックスが1から始まっているので-1
				int value = tList[pList[i] - 1];
				tList[pList[i] - 1] = xList[i];

				int sum = 0;
				for (int j = 0; j < n; j++)
					sum += tList[j];
				
				Console.WriteLine(sum);
				tList[pList[i] - 1] = value;
			}
			
		}
	}
}

Measured memory_bytes: 13140
// D - Powerful Discount Tickets

import java.util.*;

public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);

		int N = sc.nextInt();
		int M = sc.nextInt();

		sc.nextLine();
		PriorityQueue<Long> AQueue = new PriorityQueue(Comparator.reverseOrder());
		for(int i=0;i<N;i++){
			AQueue.add(sc.nextLong());
		}

		
		for(int i=0; i<M;i++){
			long m = AQueue.poll();
			AQueue.add((long)(m/2));
		}

		long sum = 0;
		Iterator<Long> it = AQueue.iterator();
		while(it.hasNext()){
			sum += it.next();
		}
		System.out.println(sum);	
	}
}

Measured memory_bytes: 59480
import java.util.*;
public class Main{


public static void main (String []args)
{
	Scanner scan=new Scanner(System.in);
	//long t=scan.nextLong();
	//long ways[]=new long[1000000000];
	//ways[1]=1;
	//ways[i]=ways[i-1]*2;
	
	//while(t-->0){
         int n=scan.nextInt();
       //  int k=scan.nextInt();
         int a[]=new int[n];
         int b[]=new int[n];
          int c[]=new int[n];
        // int dp[]=new int[n];
        for(int i=0;i<n;i++)
       {  a[i]=scan.nextInt();
          b[i]=scan.nextInt();
          c[i]=scan.nextInt();
       }
       
	int dp[][]=new int[n][3];
	for(int i=1;i<n;i++)
        for(int j=0;j<3;j++)
        dp[i][j]=Integer.MIN_VALUE;
        dp[0][0]=a[0];
        dp[0][1]=b[0];
	dp[0][2]=c[0];
	
	for(int i=1;i<n;i++)
	{  
	
		
		dp[i][0]=a[i]+Math.max(dp[i-1][1],dp[i-1][2]);
		dp[i][1]=b[i]+Math.max(dp[i-1][0],dp[i-1][2]);
	     dp[i][2]=c[i]+Math.max(dp[i-1][1],dp[i-1][0]);
		}
         
         System.out.println(Math.max(Math.max(dp[n-1][0],dp[n-1][1]),dp[n-1][2]));
//}//
}
}


Measured memory_bytes: 94324
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace kyopro
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] xa = Console.ReadLine().Split();
            int x = int.Parse(xa[0]);
            int a = int.Parse(xa[1]);
            if(x < a)
            {
                Console.WriteLine(0);
            }else if(x >= a)
            {
                Console.WriteLine(10);
            }
        }
    }
}


Measured memory_bytes: 13140
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp>
//#include <boost/lexical_cast.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>
using namespace std;
using namespace __gnu_pbds;
#define int long long
#define pb push_back
#define mp make_pair
#define endl '\n'
#define PI acos(-1)
#define bitcount(a) __builtin_popcountll(a)
#define P pair<int,int>
typedef tree<int,null_type,less_equal <int>,rb_tree_tag,tree_order_statistics_node_update>ordered_set;

long mod=1e9+7;
signed main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int n,a,b;
	cin>>n>>a>>b;
	cout<<min(n*a,b);
	return 0;
}

Measured memory_bytes: 256
N,Y=map(int,input().split())
answer=[]

try:
 for i in range(N+1):
   for j in range(N-i+1):
     sum=i*10000+j*5000+(N-i-j)*1000
     if sum==Y:
       raise Exception
except Exception:
  print(i,j,N-i-j)
else:
  print(-1,-1,-1)

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

int main() {
  string str;
  getline(cin, str);

  for(int i=0; i < str.length(); i++) {
    if     (str.substr(i, 5) == "apple") str.replace(i, 5, "peach");
    else if(str.substr(i, 5) == "peach") str.replace(i, 5, "apple");
  }

  cout << str << endl;
}

Measured memory_bytes: 1184
import java.util.Scanner;

class Main {
    public static void main(String[] args) {
	Scanner sc = new Scanner(System.in);

	int N = sc.nextInt();
	int A[] = new int[N];
	for (int i = 0; i < N; i++)
	    A[i] = sc.nextInt();

	boolean bl = true;
	for (int i = 0; i < N; i++) {
	    if (A[i] % 2 == 0) {
		if (!(A[i] % 3 == 0 || A[i] % 5 == 0)) {
		    bl = false;
		    break;
		}
	    }
	}

	if (bl)
	    System.out.println("APPROVED");
	else
	    System.out.println("DENIED");
    }
}

Measured memory_bytes: 21844
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
const double eps = 1e-10;
const int MOD = 1000000007;
const int INF = 1000000000;
const ll LINF = 1ll<<50;
template<typename T>
void printv(const vector<T>& s) {
  for(int i=0;i<(int)(s.size());++i) {
    cout << s[i];
    if(i == (int)(s.size())-1) cout << endl;
    else cout << " ";
  }
}
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  int n; cin >> n;
  vector<int> a(n);
  for(int i=0;i<n;++i) {
    cin >> a[i];
  }
  vector<ll> su(n+1, 0);
  for(int i=0;i<n;++i) {
    su[i+1] = su[i] + a[i];
  }
  int l = 1;
  vector<int> fl(n+1);
  for(int i=2;i<=n-2;++i) {
    while(l < i-1 && abs(2*su[l] - su[i]) > abs(2*su[l+1] - su[i])) {
      l++;
    }
    fl[i] = l;
  }
  int r = n-1;
  vector<ll> fr(n+1);
  for(int i=n-2;i>=2;--i) {
    while(r > i+1 && abs(2*su[r] - su[i] - su[n]) > abs(2*su[r-1] - su[i] - su[n])) {
      r--;
    }
    fr[i] = r;
  }
  ll mi = LINF;
  for(int i=2;i<=n-2;++i) {
    ll tmpma = max(su[fl[i]], max(su[i] - su[fl[i]], max(su[fr[i]] - su[i], su[n] - su[fr[i]])));
    ll tmpmi = min(su[fl[i]], min(su[i] - su[fl[i]], min(su[fr[i]] - su[i], su[n] - su[fr[i]])));
    mi = min(mi, tmpma - tmpmi);
  }
  cout << mi << endl;
}


Measured memory_bytes: 4992
#include <sstream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <iostream>
#include <utility>
#include <set>
#include <cctype>
#include <queue>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
using namespace std;
#define INF 100000000

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

int BIT[1000010], bit_size;

void bit_init(int n) {
    for (int i = 0; i < n+10; i++) BIT[i] = 0;
    bit_size = n;
}

int bit_sum(int n) {
    int ans = 0;
    while (n > 0) {
        ans += BIT[n];
        n &= n-1;
    }
    return ans;
}

void bit_add(int n, int v) {
    while (n <= bit_size) {
        BIT[n] += v;
        n += n & (-n);
    }
}

int main(void) {
    int n, q;
    cin >> n >> q;
    bit_init(n);
    while (q--) {
        int com, x, y;
        cin >> com >> x >> y;
        if (com == 0) {
            bit_add(x, y);
        } else {
            cout << bit_sum(y) - bit_sum(x-1) << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 1552
#include <stdio.h>
#include <stdlib.h>
#include <math.h>


int main(){
  int n,k,i,x=1;
  scanf("%d",&n);
  scanf("%d",&k);
  for(i=1;i<=n;i++){
    x=fmin(x*2,x+k);
  }
  printf("%d\n",x);
  return 0;
}

Measured memory_bytes: 128
import java.util.*;
class Main{
    public static void main(String[] args){
        Scanner scanner=new Scanner(System.in);
        int a,b;
        a=scanner.nextInt();
        b=scanner.nextInt();
        
        if(a < b){
            System.out.println("a < b");
        }
        else if(a > b){
            System.out.println("a > b");
        }
        else
            System.out.println("a == b");
    }
}


Measured memory_bytes: 26156
#include"bits/stdc++.h"
#define int long long
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=(a);i<(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define itr(i,x) for(auto i=(x).begin();i!=(x).end();++i)
#define All(x) (x).begin(),(x).end()
using namespace std;
typedef pair<int,int> P;
const int mod=1000000007;
int gcd(int x,int y){return y?gcd(y,x%y):x;}
int lcm(int x,int y){return x*y/gcd(x,y);}

signed main(){
	int n;cin>>n;
	vector<int> a(n);
	rep(i,n) cin>>a[i];
	list<int> b;
	rep(i,n){
		if(i&1) b.push_back(a[i]);
		else b.push_front(a[i]);
	}
	if(n%2==0) reverse(All(b));
	itr(i,b) cout<<*i<<" \n"[i==--b.end()];
}


Measured memory_bytes: 9984
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define INF 1e9+7
#define rep(i,n) for(ll i=0;i<n;i++)
#define pii pair<int,int>
#define pll pair<ll,ll>
const int maxn = 1000000;
ll mod = INF;


int main(){
    int n;
    ll ans=0;
    ll cnt[10][10]={0};

    cin >> n;
    int k=1;
    for(int i=1;i<=n;i++){
        if(k*10<=i)k=k*10;
        cnt[i/k][i%10]++;
    }

    for(int i=1;i<=9;i++){
        for(int j=1;j<=9;j++){
            ans+=cnt[i][j]*cnt[j][i];
        }
    }

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

Measured memory_bytes: 3628
#include<bits/stdc++.h>
using namespace std;
int main(){
    int N,K;
    cin >> N;
    string s;
    cin >> s;
    cin>>K;
    K--;
    char ans = s[K];
    for(int i = 0; i< N; i++){
        if(s[i] != ans){
            s[i] = '*';
        }
    }
    cout << s <<  endl;
    return 0;
}

Measured memory_bytes: 256