akhauriyash/Code-Regression huggingface dataset:
#ifndef LOCAL
#pragma GCC optimize("O3")
#endif
#include "bits/stdc++.h"
using namespace std;
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
using ll = long long ;

int main(){
	int n ;
	cin >> n ;
	vector<int> v(n) ;
	for(int &x : v){
		cin >> x ;
	}
	sort(v.begin(),v.end()) ;
	debug() << imie(v) ;
	int nax = v[n-1] ;
    int index = lower_bound(v.begin(),v.end(),nax/2) - v.begin();
    if ( v[index] == nax/2 || v[index] == nax/2+1 ){
    	cout << nax << ' ' << v[index] << endl;
    }
    else {
    	if ( v[index-1] >= nax-v[index] ){
    		cout << nax << ' ' << v[index-1] << endl;
    	}
    	else cout << nax << ' ' << v[index] << endl;
    }
    return 0 ;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define INF (1LL<<50)
#define MOD 1000000007
 
int main(){
    int X,A;
	cin >> X >> A;
    if(X<A){
      cout << 0 << endl;
    }else{
      cout << 10 << endl;
    }
    return 0;
}

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

int main(){
        int n;
        int i;
        int x;

        cin >> n;
        for(i = 1; i<=n; i++)
        {
                if( i % 3 == 0)
                {
                        cout << " " << i;
                } else {
                        x = i;
                        while(x != 0)
                        {
                                if(x % 10 == 3)
                                {
                                        cout << " " << i;
                                        break;
                                }
                                x = x / 10;
                        }
                }

        }
        cout << endl;
        return 0;
}

Measured memory_bytes: 3056
#include <iostream>
#include <cstdint>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <cassert>
#include <climits>
#include <string>
#include <bitset>
#include <cfloat>
#include <unordered_set>
#pragma GCC optimize("Ofast")
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef vector<pair<int, int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<string> > vvs;
typedef vector<vector<ll> > vvll;

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i <= (n); ++i)
#define irep(it, stl) for (auto it = stl.begin(); it != stl.end(); it++)
#define drep(i, n) for (int i = (n)-1; i >= 0; --i)
#define mes(a) cout << (a) << endl
#define dmes(a, b) cout << (a) << " " << (b) << endl
#define re0 return 0
#define mp(p, q) make_pair(p, q)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define Sort(a) sort(a.begin(), a.end())
#define rSort(a) sort(a.rbegin(), a.rend())
#define MATHPI acos(-1)
#define itn int;
int dx[8] = { 1, 0, -1, 0, 1, -1, -1, 1 };
int dy[8] = { 0, 1, 0, -1, 1, 1, -1, -1 };
template <class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template <class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
struct io { io() { ios::sync_with_stdio(false); cin.tie(0); } };
const int INF = INT_MAX;
const ll LLINF = 1LL << 60;
const ll MOD = 1000000007;
const double EPS = 1e-9;

signed main(void) 
{
    string s;
    cin >> s;
    
    if (s[5] == '1') {
        mes("TBD");
        re0;
    }
    if (s[6] == '5' || s[6] == '6' || s[6] == '7' || s[6] == '8' || s[6] == '9') {
        mes("TBD");
        re0;
    }
    
    
    
    mes("Heisei");
    
}


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

signed main() {
	string s;cin >>s;
	int num=s.size();
	int ans=0;
	int tmp=0;
  	int sum=0;
	for(int i=0;i<(1<<num-1);i++){
		tmp=s[0]-'0';ans=0;		
		for(int j=1;j<num;j++){
			if((i>>(j-1))%2==0){
				tmp=tmp*10+(s[j]-'0');	
			}else{
				ans+=tmp;
				tmp=(s[j]-'0');
			}
		}
		ans+=tmp;
		sum+=ans;
    // 	cout<<ans<<endl;

  
	}
	cout<<sum<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
using namespace std;
int N, K, a[100009];
int main() {
	cin >> N >> K;
	long long sum = 0;
	for (int i = 0; i < N; i++) {
		cin >> a[i];
		sum += (a[i] > 0 ? a[i] : 0);
	}
	long long cur = 0, cs = 0, ret = 0;
	for (int i = 0; i < N; i++) {
		cur += a[i];
		cs += (a[i] > 0 ? a[i] : 0);
		if (i >= K - 1) {
			ret = max(ret, sum - min(cs - cur, cs));
			cur -= a[i - K + 1];
			cs -= (a[i - K + 1] > 0 ? a[i - K + 1] : 0);
		}
	}
	cout << ret << '\n';
	return 0;
}

Measured memory_bytes: 640
N , W = map(int, input().split() )
wv = [list(map(int,input().split())) for _ in range(N) ]
maxv = 100100
dp = [[10**10] * (maxv) for _ in range(N+1) ]
dp[0][0] = 0
for i in range(N):
    for j in range(maxv):
        if j >= wv[i][1]:
            dp[i+1][j] = min(dp[i+1][j] , dp[i][j-wv[i][1]]+wv[i][0])
        dp[i+1][j] = min(dp[i+1][j] , dp[i][j])

ans = 0
for j in range(maxv):
    if dp[N][j] <= W:
        ans = j
print(ans)

Measured memory_bytes: 121324
const processData = (lines) => {
  const X = +lines[0]

  let a = 100
  let year = 0
  while(a<X) {
    year++
    a = Math.floor(a * 1.01)
  }
  console.log(year)
}

let i = ''
process.stdin.on('data', c => i += c)
process.stdin.on('end', () => {
  const {EOL} = require('os')
  const lines = i.split(EOL) /*your input text, split by lines*/
  processData(lines)
})


Measured memory_bytes: 29948
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define MOD 1000000007
using namespace std;
long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
long long int comb_mod(long long int n,long long int m)
{
    if (m == 0)
    {
        return 1;
    }
    if (m > n - m)
    {
        m = n - m;
    }
    long long int up = 1, down = 1;
    for (long long int i = 1; i <= m; i++)
    {
        up = (up * (n - i + 1)) % MOD;
        down = (down * i) % MOD;
    }
    return up * modpow(down, MOD - 2,MOD) % MOD;
}
int main()
{
    long long int n,a,b;
    cin >> n >> a >> b;
    long long int total = modpow(2,n,MOD);
    total--;
    cout << (total - comb_mod(n,a) - comb_mod(n,b) + MOD * 2) % MOD << "\n";

    return 0;
}

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

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

ll MOD = 998244353;
const int N = 3005, S = 3005;
ll expo[N], dp[S][N];
vector<int> a;
int n, s;

int main(){
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    cin >> n >> s;
    a.assign(n + 1, 0);
    for(int i = 1; i <= n; i++){
        cin >> a[i];
    }
    memset(expo, 0, N * sizeof(ll));
    memset(dp, 0, N * S * sizeof(ll));
    expo[0] = 1;
    for(int i = 1; i <= N; i++){
        expo[i] = expo[i-1] * i;
    }
    dp[0][0] = 1;
    for(int i = 1; i <= n; i++){
        for(int sum = 0; sum <= s; sum++){
            if(sum >= a[i])
                dp[i][sum] += dp[i-1][sum - a[i]];
            dp[i][sum] %= 998244353;
            dp[i][sum] += 2 * dp[i - 1][sum];
            dp[i][sum] %= 998244353;
        }
    }
    cout << dp[n][s];
}

Measured memory_bytes: 74184
using System;
class Program
{
    public static void Main()
    {
        string[] str = Console.ReadLine().Split(' ');
        int g, b;
        g = int.Parse(str[1]);
        b = int.Parse(str[2]);
        Console.WriteLine(((10 * g + b) % 4 == 0) ? "YES" : "NO");
    }
}

Measured memory_bytes: 11092
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define pp pair<int,int>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ld long double
#define al(a) (a).begin(),(a).end()
#define mk make_pair
#define check cout<<"?"<<endl;

ll MOD=1000000007;
ll mod=998244353;
int inf=1000001000;
ll INF=1e18+5;

int main(){
    int n,ans=0; cin>>n;
    for(int i=3;i<=n;i+=2){
        int cnt=0;
        for(int j=1;j*j<=i;j++)
        if(i%j==0) cnt+=2-(j*j==i);
        if(cnt==8) ans++;
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 3616
#include<iostream>
#include<algorithm>


using namespace std;
int sum(int x){
  int a=0;
while(x>0){
  a+=x%10;
    x/=10;
}
  return a;
}
int main(){
  int n,c,d,total=0;
  cin>>n>>c>>d;
  for(int i=1;i<n+1;i++){
    int e=sum(i);
    if(c<=e and d>=e){
      total+=i;
    }
  }
  cout<<total<<endl;
}


Measured memory_bytes: 256
#include <algorithm>
#include <bits/stdc++.h>
#include <cstdint>
#include <iostream>
#include <iterator>
#include <vector>

// lib/util.hpp
#ifndef UTIL_HPP
#define UTIL_HPP


typedef ::std::int_fast64_t i64;
typedef ::std::uint_fast64_t u64;
typedef ::std::int_fast32_t i32;
typedef ::std::uint_fast32_t u32;

namespace tools {
  template <typename T>
  void read(::std::istream& is, ::std::vector<T>& vector, const typename ::std::vector<T>::size_type size) {
    vector.reserve(size);
    ::std::copy_n(::std::istream_iterator<T>(is), size, ::std::back_inserter(vector));
  }
  template <typename T>
  void read(::std::vector<T>& vector, const typename ::std::vector<T>::size_type size) {
    ::tools::read(::std::cin, vector, size);
  }

  template <typename T, ::std::size_t N>
  void read(::std::istream& is, ::std::array<T, N>& array) {
    ::std::copy_n(std::istream_iterator<T>(is), N, array.begin());
  }
  template <typename T, ::std::size_t N>
  void read(::std::array<T, N>& array) {
    ::tools::read(::std::cin, array);
  }
}

#endif

// main.cpp

int main() {
  i64 N, M;
  std::cin >> N >> M;

  std::vector<std::unordered_set<i64>> graph(N);
  for (i64 i = 0; i < M; ++i) {
    i64 A_i, B_i;
    std::cin >> A_i >> B_i;
    --A_i;
    --B_i;
    graph[A_i].insert(B_i);
    graph[B_i].insert(A_i);
  }

  std::vector<i64> prev(N, -1);
  std::queue<i64> queue({0});
  std::vector<bool> will_visit(N, false);
  will_visit[0] = true;
  while (!queue.empty()) {
    const i64 current = queue.front();
    queue.pop();
    for (const i64& next : graph[current]) {
      if (!will_visit[next]) {
        prev[next] = current;
        queue.push(next);
        will_visit[next] = true;
      }
    }
  }

  std::cout << "Yes" << std::endl;
  for (i64 i = 1; i < N; ++i) {
    std::cout << prev[i] + 1 << std::endl;
  }
  return 0;
}

Measured memory_bytes: 28148
#include<stdio.h>

int main(void){
int W,H,x,y,r;
scanf("%d %d %d %d %d",&W,&H,&x,&y,&r);
if(x-r<0 || x+r>W || y-r<0 || y+r>H){
  printf("No\n");
}else{
  printf("Yes\n");
}
  return 0;
}


Measured memory_bytes: 2092
#[allow(unused_imports)]
use std::cmp::{min,max};
#[allow(unused_imports)]
use std::collections::{BTreeMap,BTreeSet};
#[allow(unused_imports)]
use std::ops::*;
#[allow(unused_imports)]
use std::collections::BinaryHeap;

#[allow(unused_macros)]
macro_rules! tf {
    ($c:expr, $t:expr, $f:expr) => {{
        if $c { $t } else { $f }
    }};
}

struct BIT<T> {
    xs: Vec<T>,
    n: usize,
}

// 0-indexed
impl<T:Add<T,Output=T>+Sub<T,Output=T>+Default+Clone+Copy> BIT<T> {
    fn new(n: usize) -> BIT<T> {
        let mut m = 1;
        while m < n {
            m *= 2;
        }
        let n = m;
        BIT::<T> {
            xs: vec![T::default(); n+1],
            n: n
        }
    }
    fn sum(&self, i: usize) -> T {
        let mut i = i + 1;
        let mut res = T::default();
        while i > 0 {
            res = res + self.xs[i];
            i = i - (1usize << i.trailing_zeros());
        }
        res
    }
    fn range_sum(&self, l: usize, r: usize) -> T {
        self.sum(r-1) - self.sum(l-1)
    }
    fn add(&mut self, i: usize, x: T) {
        let mut i = i + 1;
        while i <= self.n {
            self.xs[i] = self.xs[i] + x;
            i = i + (1usize << i.trailing_zeros())
        }
    }
}

fn main() {
    let (n,q) = {
        let xs = read_vec_i64();
        (xs[0] as usize, xs[1] as usize)
    };
    let mut bit: BIT<i64> = BIT::new(n);
    for i in 0..q {
        let (com,x,y) = {
            let xs = read_vec_i64();
            (xs[0] as usize, xs[1] as usize, xs[2] as usize)
        };
        if com == 0 {
            bit.add(x-1, y as i64);
        }
        if com == 1 {
            let res = bit.range_sum(x-1, y);
            println!("{}", res);
        }
    }
}

#[allow(dead_code)]
fn read_line() -> String {
    let mut ret = String::new();
    std::io::stdin().read_line(&mut ret).ok();
    ret.pop();
    //ret.pop();
    return ret;
}

#[allow(dead_code)]
fn read_i64() -> i64 {
    let ss = read_line();
    return ss.parse::<i64>().unwrap();
}

#[allow(dead_code)]
fn read_vec_i64() -> Vec<i64> {
    let mut res = vec![];
    let ss = read_line();
    for ts in ss.split_whitespace() {
        let x = ts.parse::<i64>().unwrap();
        res.push(x);
    }
    return res;
}

use std::fmt::Display;
#[allow(dead_code)]
fn write_vec<T: Display>(xs: &Vec<T>) {
    if xs.len() == 0 {
        println!("");
        return;
    }
    print!("{}", xs[0]);
    for i in 1..xs.len() {
        print!(" {}", xs[i]);
    }
    println!("");
}



Measured memory_bytes: 2116
#include <iostream>
#include <vector>

int main (void) {
    int N;
    std::cin >> N;

    std::vector<int> ans(N);
    for (int i = 0; i < N - 1; i++) {
        int a;
        std::cin >> a;
        a--;
        ans[a]++;
    }
    for (const auto x : ans) {
        std::cout << x << std::endl;
    }
    return 0;
}


Measured memory_bytes: 3992
#include <stdio.h>

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

    int a[2][n];
    int total[2][n];
    for (int i = 0; i < 2; i++) {
        for (int j = 0; j < n; j++) {
            scanf("%d", &a[i][j]);
        }
    }

    for (int j = 0; j < n; j++) {
        if (j == 0) {
            total[0][j] = a[0][j];
        } else {
            total[0][j] = total[0][j - 1] + a[0][j];
        }
    }

    for (int j = n - 1; j >= 0; j--) {
        if (j == n - 1) {
            total[1][j] = a[1][j];
        } else {
            total[1][j] = total[1][j + 1] + a[1][j];
        }
    }

    int max = 0;
    for (int i = 0; i < n; i++) {
        if (max < total[0][i] + total[1][i]) {
            max = total[0][i] + total[1][i];
        }
    }

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

    return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define endl "\n"
#define int long long

const int N=1005;
const int MOD=1e9+7;

int32_t main()
{
  
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int a,b,c;
  cin>>a>>b>>c;
  int x=max(a,b);
   if(c%x!=0)
   {
   	cout<<c/x+1;
   }
   else
   {
   	cout<<c/x;
   }
  
  
}


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

using namespace std;


void weather_predicition()
{
  string s;
  cin >> s;

  if (s == "Sunny") cout << "Cloudy\n";
  else if (s == "Cloudy") cout << "Rainy\n";
  else if (s == "Rainy") cout << "Sunny\n";
}


void odds_of_oddness()
{
  int n;
  cin >> n;

  int cnt = 0;
  for (int i = 1; i <= n; ++i)
  {
    if (i % 2 != 0) ++cnt;
  }

  cout << (float)cnt / (float)n << "\n";
}


void curtain()
{
  int a, b;
  cin >> a >> b;

  if (a - 2 * b > 0) cout << a - 2 * b << "\n";
  else cout << 0 << "\n";
}


void cant_wait_for_holiday()
{
  string s;
  cin >> s;

  vector<string> S{"SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT"};

  int cnt = 7;
  for (int i = 0; i < 7; ++i)
  {
    if (s == S[i]) cout << cnt << "\n"; 
    --cnt;
  }

}


int main()
{
  //weather_predicition();
  //odds_of_oddness();
  //curtain();
  cant_wait_for_holiday();
}

Measured memory_bytes: 256
#include <stdio.h>
int main(void){
    int S,h,m,s;
    scanf("%d",&S);
    h=S/3600;
    m=(S-h*3600)/60;
    s=S-h*3600-m*60;
    printf("%d:%d:%d\n",h,m,s);
    return 0;
}




Measured memory_bytes: 2104
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define vi vector<int>
#define vvi vector<vi>
#define vs vector<string>
#define pb push_back
#define P pair<int,int>
#define vp vector<P>
#define PP pair<P,int>
#define vpp vector<PP>
#define fi first
#define se second
#define INF (1<<30)
#define MOD 1000000007
#define REP(i,n) for(int i=0;i<n;i++)
#define REPR(i,n) for(int i=n;i>=0;i--)
#define FOR(i,m,n) for(int i=m;i<n;i++)
#define all(x) (x).begin(),(x).end()
signed main(){
    int n;
    cin>>n;
    map<int,int> ma;
    FOR(i,1,n+1){
        int t=i;
        for(int j=2;j<=i;j++){
            while(!(t%j)){
                ma[j]++;
                t/=j;
            }
        }
    }
    int ans=1;
    for(auto i:ma){
        (ans*=i.se+1)%=MOD;
    }
    cout<<ans<<endl;
    return 0;
}

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

#define max(a,b) a > b ? a : b
#define min(a,b) a < b ? a : b

using namespace std;

//int judgeString(string S)
//{}

int main()
{
    string S;
    string S1;
    string S2;
    string invS;
    string invS1;
    string invS2;

    int N, N1, N2;

    cin >> S;

    N = S.length();
    N1 = (N - 1) / 2;
    N2 = (N + 3) / 2;


    S1 = S.substr(0, N1);
    S2 = S.substr(N2-1, N-N2+2);

    invS = S;
    invS1 = S1;
    invS2 = S2;
    reverse(invS.begin(), invS.end());
    reverse(invS1.begin(), invS1.end());
    reverse(invS2.begin(), invS2.end());

    if (S == invS && S1 == invS1 && S2 == invS2 && N >= 3 && N <= 99 && N % 2 == 1)
    {
        cout << "Yes" << endl;
    }
    else
    {
        cout << "No" << endl;
    }
}

Measured memory_bytes: 256
N, M = list(map(int, input().split()))
A = set()
for i in range(M):
    A.add(int(input()))

dp = [0] * (N+1)
dp[0] = 1
for i in range(1, N+1):
    if i in A:
        continue
    dp[i] = dp[i-1]
    if i > 1:
        dp[i] += dp[i-2]
    dp[i] %= 1000000007


print(dp[N])






Measured memory_bytes: 11884
#include <bits/stdc++.h>
    #include<cmath> 
     
    #define fastio ios_base::sync_with_stdio(false); cin.tie(NULL);
    #define SUBL freopen("/home/ajinkya/Desktop/input.txt","r",stdin); freopen("/home/ajinkya/Desktop/output.txt","w",stdout); 
    #define ll long long
    #define ull unsigned long long
    #define FI(i,a,n) for(int i=a; i<=n; i++)
    #define RFI(i,n,a) for(int i=n; i>=a; i--)
    #define FLL(i,a,n) for(ll i=a; i<=n; i++)
    #define RFLL(i,n,a) for(ll i=n; i>=a; i--)
    #define vi vector<int>
    #define vll vector<ll>
    #define all(v) v.begin(),v.end()
    #define pll pair<ll,ll>
    #define pi pair<int, int>
    #define GCD(a,b) __gcd(a,b)
    #define MP make_pair
    #define PB push_back
    #define PF push_front
    #define LB lower_bound
    #define UB upper_bound
    #define debug(x) cout << x << endl
    #define MOD 1000000007
    #define INF LLONG_MAX
    #define PI 3.14159265359
    using namespace std;
     
     
    int main()
    {
        fastio 
        // SUBL
      	int n;
      	cin >> n;
      	double ans=0;
      	for(int i=1; i<=n; i++) 
      	{
      		double x;
      		cin >> x;
      		ans += (1/x);
      	}
      	cout << fixed << setprecision(10) << 1/ans;
        return 0;
    }         	

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#define MAX 10000
#define INFTY 1 << 29
 
using namespace std;
vector<int> par,rank1;

struct Edge{
  int source, target, cost;

  Edge(int source, int target, int cost) : source(source), target(target), cost(cost) {}
  
  /*bool operator < (const Edge &e) const {
    return cost < e.cost;
  }*/
};
 
void init_UnionFind(int v){
  par = vector<int>(v);
  rank1 = vector<int>(v);
  for(int i = 0 ; i < v; i++){
    par[i] = i; 
    rank1[i] = 0;
  }
}
 
int find(int x){ 
  if(par[x] == x) return x; 
  return par[x] = find(par[x]);
}
 
void unite(int x,int y){ 
  x = find(x); y = find(y);
  if(x == y) return;
   
  if(rank1[x] < rank1[y]){
    par[x] = y;
  } else {
    par[y] = x;
    if(rank1[x] == rank1[y]) rank1[x]++;
  }
}
 
bool same(int x,int y){
  return find(x) == find(y);
}

bool comp(const Edge& e1, const Edge& e2){
  return e1.cost < e2.cost;
}

int kruskal(int V, vector<Edge> e){
  int ansCost = 0;
  //sort(e.begin(), e.end());
  sort(e.begin(), e.end(), comp);

  init_UnionFind(V);
  for(int i = 0; i < e.size(); i++){
    Edge edge = e[i];
    if(!same(edge.source, edge.target)){
      ansCost += edge.cost;
      unite(edge.source, edge.target);
    }
  }
  return ansCost;
}

int main(){
  int V, E, source, target, cost;
  vector<Edge> e;

  cin >> V >> E;

  for(int i = 0; i < E; i++){
    cin >> source >> target >> cost;
    e.push_back(Edge(source, target, cost));
  }

  cout << kruskal(V,e) << endl;
  return 0;
}


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

using namespace std;
using ll = long long;

#define rep(i, a) for (int (i) = 0; (i) < (int) (a); (i)++)
#define reps(i, a, b) for (int (i) = (int) (a); (i) < (int) (b); (i)++)
#define rrep(i, a) for (int (i) = (int) a-1; (i) >= 0; (i)--)
#define rreps(i, a, b) for (int (i) = (int) (a)-1; (i) >= (int) (b); (i)--)
#define MP(a, b) make_pair((a), (b))
#define PB(a) push_back((a))
#define all(v) (v).begin(), (v).end()
#define PRINT(f) if((f)){cout << (TRUE__) << endl;}else{cout << FALSE__ << endl;}
#define TRUE__ "Yes"
#define FALSE__ "No"
#define PERM(v) next_permutation(all(v))
#define UNIQUE(v) sort(all(v));(v).erase(unique(all(v)), v.end())
#define CIN(type, x) type x;cin >> x

#ifdef LOCAL
	#define lcout(a) cout << a;
	#define lcoutln(a) cout << a << endl;
	#define lcerr(a) cerr << a;
	#define lcerrln(a) cerr << a << endl;
#else
	#define lcout(a) 
	#define lcoutln(a) 
	#define lcerr(a) 
	#define lcerrln(a) 
#endif




int main()
{
	CIN(string, s);
	for (int i = 0; i < s.length(); i += 2) cout << s[i];
	cout << endl;
}


Measured memory_bytes: 512
import java.util.*;

class Main{
    static int n;
    static int[][] table;
    static int min;
    static int max;
    static int[][] maps;

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

	n = sc.nextInt();

	while(n!=0){
	    min = 31;
	    max = 0;
	    table = new int[n][30];
	    for(int i=0; i<n; i++){
		int dateNum = sc.nextInt();
		for(int j=0; j<dateNum; j++){
		    int date = sc.nextInt();
		    table[i][date-1] = 1;
		    if(date>max)max = date;
		}
	    }
	    maps = new int[n][n];
	    for(int i=0; i<n; i++){
		maps[i][i] = 1;
	    }

	    solve();
	    if(min==31){min = -1;}
	    System.out.println(min);

	    n = sc.nextInt();
	}
    }

    public static void solve(){
	int[] checkList = new int[n];
	for(int j=0; j<max; j++){
	    checkList = new int[n];
	    for(int i=0; i<n; i++){
		if(table[i][j]==1){
		    checkList[i] = 1;
		}
	    }

	    setMaps(checkList);
	    if(collectedMaps()){min = j+1; return;}
	}
    }

    public static void setMaps(int[] checkList){
	for(int i=0; i<n; i++){
	    if(checkList[i]==1){//i&#200;&#214;&#204;&#220;&#8364;&#206;&#187;&#210;&#194;&#185;&#8364;&#172;&#8364;&#8364;&#8364;&#191;&#8364;&#233;
		for(int j=0; j<n; j++){
		    if(maps[i][j]==1){
			for(int k=0; k<n; k++){
			    if(checkList[k]==1)maps[k][j]=1;
			}
		    }
		}
	    }
	}
    }

    public static boolean collectedMaps(){
	int count = 0;
	for(int i=0; i<n; i++){
	    count = 0;
	    for(int j=0; j<n; j++){
		if(maps[i][j]==1){count++;}
	    }
	    if(count==n){return true;}
	}
	return false;
    }
}

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

using namespace std;

typedef long long ll;
typedef long double ld;

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.flush();
	ll t=1;
	//cin>>t;
	while(t--)
	{
		ll A,B,M;
		ll a[100001],b[100001],i;
		ll x,y,m;
		cin>>A>>B>>M;
		for(i=1;i<=A;i++)
		{
			cin>>a[i];
			}
		for(i=1;i<=B;i++)
		{
			cin>>b[i];
			}
		// 
		ll ans=99999999999;
		for(i=0;i<M;i++)
		{
			cin>>x>>y>>m;
			if(x<=A && x>=1 && y<=B && y>=1)
			{
				ll c=a[x]+b[y]-m;
				ans=min(ans,c);
				}
			
		}
		for(i=1;i<=min(A,B);i++)
		{
			ll c=a[i]+b[i];
			ans=min(ans,c);
			}
		sort(a+1,a+A+1);
		sort(b+1,b+B+1);
		ans=min(ans,(a[1]+b[1]));
		
		if(ans==99999999999)
		{
			ans=-1; // not exist
			}
		
		cout<<ans<<endl;
	}
	
	
return 0;
}


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

int main() {
  int n, m; cin >> n >> m;
  int lr = 0, rr = n;
  vector<int> l(m), r(m);
  rep(i,m) {
    cin >> l[i] >> r[i];
    lr = max(lr, l[i]);
    rr = min(rr, r[i]);
  }
  int ans = rr - lr + 1;
  if (ans <= 0) ans = 0;
  cout << ans << endl;
  return 0;
}

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

int main(){
    long long a, b;
    cin >> a >> b;

    for(long long i = 0; i <= 20000; i++){
        long double yen = (long double) i;
        long long tax_8 = yen * 0.08;
        long long tax_10 = yen * 0.1;
        if(tax_8 == a and tax_10 == b){
            cout << i << endl;
            return 0;
        }
    }
    cout << "-1" << endl;
    return 0;
}

Measured memory_bytes: 3612
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Globalization;
using System.Diagnostics;
using static System.Console;
using Pair = System.Collections.Generic.KeyValuePair<int, int>;
 
class Program
{
    static void Main()
    {
        SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
        new Program().Solve();
        Out.Flush();
    }
    
    Scanner cin = new Scanner();
    Random rnd = new Random();
    Stopwatch sw = new Stopwatch();
    readonly int[] dd = { 0, 1, 0, -1, 0 };
    readonly int mod = 1000000007;
    readonly string alfa = "abcdefghijklmnopqrstuvwxyz";
 
    int N, K;
    int[] A;
    void Solve()
    {
       N = cin.Nextint;
       K = cin.Nextint;
       A = cin.Scanint;
       Array.Sort(A);
       int ans = 0;
       //if(N >400 || K > 400)return;
       for (int i = 0; i < N; i++)
       {
            if(A[i] >= K)continue;
            int cnt = 0;
            bool flag = true;
           for (int j = N - 1; j >= 0; j--)
            {
                if(i == j)continue;
                if(cnt + A[j] >= K)continue;
                if(cnt + A[j] + A[i] >= K)
                {
                    flag = false;
                    break;
                }
                cnt+=A[j];
            }
            if(flag)
            {
                ans++;
            }
       }
       WriteLine(ans);


    }
 
}
 
class Scanner
{
    string[] s; int i;
    char[] cs = new char[] { ' ' };
    public Scanner() { s = new string[0]; i = 0; }
    public string[] Scan { get { return ReadLine().Split(); } }
    public int[] Scanint { get { return Array.ConvertAll(Scan, int.Parse); } }
    public long[] Scanlong { get { return Array.ConvertAll(Scan, long.Parse); } }
    public double[] Scandouble { get { return Array.ConvertAll(Scan, double.Parse); } }
    public string Next
    {
        get
        {
            if (i < s.Length) return s[i++];
            string st = ReadLine();
            while (st == "") st = ReadLine();
            s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
            i = 0;
            return Next;
        }
    }
    public int Nextint { get { return int.Parse(Next); } }
    public long Nextlong { get { return long.Parse(Next); } }
    public double Nextdouble { get { return double.Parse(Next); } }
}

Measured memory_bytes: 13300
#pragma region header
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i <= (int)(n); i++)
#define rev(i, n) for(int i = (int)(n - 1); i >= 0; i--)
#define rev1(i, n) for(int i = (int)(n); i > 0; i--)
#define pb push_back
#define all(v) (v).begin(), (v).end()
#define resort(v) sort((v).rbegin(), (v).rend())
#define vi vector<int>
#define vvi vector<vector<int>>
#define vc vector<char>
#define vvc vector<vector<char>>
#define vb vector<bool>
#define vvb vector<vector<bool>>
using ll = long long;
using P = pair<int, int>;
/* ----------------よく使う数字や配列----------------- */
int dx[] = {1,0,-1,0};
int dy[] = {0,1,0,-1};
constexpr ll mod = 1e9+7;
constexpr int inf = INT32_MAX/2;
constexpr ll INF = LLONG_MAX/2;
constexpr long double eps = DBL_EPSILON;
constexpr long double pi = 3.141592653589793238462643383279;
/* ----------------------end----------------------- */

/* --------------------テンプレート------------------ */
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
/* ----------------------end----------------------- */

/* --------------------ライブラリ-------------------- */
ll fact(int i) {       //階乗
    if (i == 0) return 1;
    return (fact(i - 1)) * i % mod;
}
ll gcd(ll a, ll b) {        //最大公約数
    if(b == 0) return a;
    return gcd(b, a % b); 
}
ll lcm(ll a, ll b) {      //最小公倍数
    return a / gcd(a, b) * b ;
}
int keta(ll n) {        //桁数を求める
    if(n == 0) return 1;
    int count = 0;
    while(n != 0) {
        n /= 10;
        count++;
    }
    return count;
}
ll ketasum(ll n) {    //各桁の和
    ll sum = 0;
    while(n != 0) {
        sum += n % 10;
        n /= 10;
    }
    return sum;
}
bool isprime(int n) { //素数判定
    if(n==1)return false;
    if(n==2)return true;
    for(int i = 2;i<=sqrt(n);i++) {
        if(n%i==0) return false;
    }
    return true;
}
/* ----------------------end----------------------- */
#pragma endregion
signed main() {
    int a,b,c;cin >> a >> b >> c;
    rep(i, 100000000) {
        int k=a,l=b,m=c;
        if((k&1)||(l&1)||(m&1)) {
            cout << i << endl;
            return 0;
        }
        a=(l+m)/2,b=(m+k)/2,c=(k+l)/2;
    }
    cout << -1 << endl;
    return 0;
}

Measured memory_bytes: 3528
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep2(i,a,b) for(ll i=(a);i<(b);++i)

template<class T> inline void chmin(T& a, T b) {if (a > b) a = b;}
template<class T> inline void chmax(T& a, T b) {if (a < b) a = b;}

//vector出力
template <class T>ostream &operator<<(ostream &o,const vector<T>&v){
  o<<"{";
  for(int i=0;i<(int)v.size();i++) o << (i>0?", ":"") << v[i];
  o<<"}";
  return o;
}


int main() {
  int N; cin >> N;
  ll D,A,x,h;
  cin >> D >> A; // 範囲　爆弾
  vector<vector<ll>> XH(N);
  rep(i,N) {
    cin >> x >> h;
    XH[i] = {x,h}; // 場所　体力
  }
  sort(XH.begin(),XH.end());
  ll cnt=0;
  queue<vector<ll>> bomb;
  ll now=0;
  rep(i,N) {
    auto t = XH[i];
    while (!bomb.empty() && bomb.front()[0]<t[0]-D){
      now-=bomb.front()[1]; bomb.pop();
    }
    t[1]-=now*A;
    if (t[1]<0) continue;
    ll add = (t[1]+A-1)/A;
    cnt+=add;
    now+=add;
    bomb.push({t[0]+D ,add});
  }
  cout << cnt << endl;
}

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


const int inf=1e9+2;

int main()
{
 int n,w;
    long long i;
    cin>>n>>w;
    //dp[i]=== maximum weight with value i;
    int wt[n],val[n];
    long long sum=0;
    for(i=0;i<n;i++)
    { cin>>wt[i]>>val[i];
     sum+=val[i];}
    
    vector<long long>dp(sum+2,inf);
    dp[0]=0;
    
    for(i=0;i<n;i++)
    {
       for(int value=sum-val[i];value>=0;value--)
           dp[value+val[i]]=min(dp[value+val[i]],dp[value]+wt[i]); 
    }
              
              long long ans=0;
              
              for(i=0;i<=sum;i++)
              {
                  
               if(dp[i]<=w)
                   ans=max(ans,i);
              }
              
              cout<<ans;
              
    
    
    
}

Measured memory_bytes: 1024
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <queue>
#include <utility>
#include <map>
#include <bitset>
#define ll long long
using namespace std;
using p = pair<ll, ll>;
ll dx[4] = {-1, 0, 1, 0};
ll dy[4] = {0, 1, 0, -1};

int main(void){
    ll n;
    cin >> n;
    ll a[n];
    for(ll i = 0; i < n; i++)
        cin >> a[i];
    sort(a, a+n);
    ll ans = 0;
    ll count = 1;
    for(ll i = 1; i < n; i++){
        if(a[i]==a[i-1]) count++;
        else{
            if(count%2!=0) ans++;
            count = 1;
        }
    }
    if(count%2!=0) ans++;
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 1024
import java.util.Scanner

import scala.collection.Searching._
import scala.annotation.tailrec
import scala.collection.immutable.Queue

class IUnionFind(val size: Int) {

  private case class Node(var parent: Option[Int], var treeSize: Int)

  private val nodes = Array.fill[Node](size)(new Node(None, 1))

  def union(t1: Int, t2: Int): IUnionFind = {
    if (t1 == t2) return this

    val root1 = root(t1)
    val root2 = root(t2)
    if (root1 == root2) return this

    val node1 = nodes(root1)
    val node2 = nodes(root2)

    if (node1.treeSize < node2.treeSize) {
      node1.parent = Some(t2)
      node2.treeSize += node1.treeSize
    } else {
      node2.parent = Some(t1)
      node1.treeSize += node2.treeSize
    }
    this
  }

  def connected(t1: Int, t2: Int): Boolean = t1 == t2 || root(t1) == root(t2)

  @tailrec
  private def root(t: Int): Int = nodes(t).parent match {
    case None => t
    case Some(p) => root(p)
  }
}


object Main {
  def solve(sc: => Scanner): Unit = {
    val E, Y = sc.nextInt
    E match {
      case 0 => {
        if (Y >= 1989) {
          println("H" + (Y - 1988))
        } else if (Y >= 1926) {
          println("S" + (Y - 1925))
        } else if (Y >= 1912) {
          println("T" + (Y - 1911))
        } else {
          println("M" + (Y - 1867))
        }
      }
      case 1 => {
        println(Y + 1867)
      }
      case 2 => {
        println(Y + 1911)
      }
      case 3 => {
        println(Y + 1925)
      }
      case 4 => {
        println(Y + 1988)
      }
    }
  }

  def main(args: Array[String]): Unit = {
    val sc: Scanner = new Scanner(System.in)
    solve(sc)
  }
}

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

using namespace std;

typedef long long ll;
const ll INF = 1LL<<60;

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

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


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

    cin >> a >> b >> c >> d;

    if((abs(b-a) <= d && abs(c-b) <= d) || abs(a-c) <= d){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
    

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int n;
float a[105];
float ans;
int main()
{
cin>>n;
for(int i=0;i<n;i++)
  {
  	cin>>a[i];
  	ans+=1.0/a[i];
  }
ans=1.0/ans;
printf("%.10f",ans);
return 0;
}


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

int main(int argc, char *argv[]) {
  int n;
  std::cin >> n;
  long a[100001];
  for (int i = 0; i < n; ++i)
    std::cin >> a[i];
  int q;
  std::cin >> q;

  for (int i = 0; i < q; ++i) {
    long k;
    std::cin >> k;
    std::cout << std::lower_bound(a, a + n, k) - a << std::endl;
  }
}



Measured memory_bytes: 3912
#include <vector>
#include <iostream>

using namespace std;

int main()
{
	int num = 0;
	int vals[100];
	while (cin >> num)
	{
		for (int i = 0; i < num; ++i) {
			cin >> vals[i];
			if (i<num - 1) cout << vals[i] << " ";
		}
		cout << vals[num-1] << endl;
		for (int i = 1; i < num; ++i)
		{
			int tmp = vals[i];
			int pos = i - 1;
			while (pos >= 0 && vals[pos] > tmp)
			{
				vals[pos + 1] = vals[pos];
				pos--;
			}
			vals[pos + 1] = tmp;
			for (int j = 0; j < num - 1; ++j) cout << vals[j] << " ";
			cout << vals[num-1] << endl;
		}
	}
	return 0;
}

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

int main() {
  int h,w;
  cin>>h>>w;
  char a[h][w];
  int res[h][w];
  queue<int> memo;
  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++) {
      cin>>a[i][j];
      if(a[i][j]=='#') {
        res[i][j]=0;
        memo.push(i);memo.push(j);
      }
      else res[i][j]=-1;
    }
  }
  int ans=0;
  while(!memo.empty()){
    int y=memo.front();memo.pop();
    int x=memo.front();memo.pop();
    int dy[4]={0,1,0,-1},dx[4]={1,0,-1,0};
    for(int i=0;i<4;i++){
      int ny=y+dy[i],nx=x+dx[i];
      if(ny<0||ny>=h||nx<0||nx>=w) continue;
      if(res[ny][nx]!=-1) continue;
      res[ny][nx]=res[y][x]+1;
      ans=max(ans,res[ny][nx]);
      memo.push(ny);memo.push(nx);
    }
  }
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 13328
#include <iostream>

using namespace std;

int main(){
    int n, a, b;
    cin >> n >> a >> b;
    int q1=0, q2=0, q3=0;
    for(int i=0; i<n; ++i){
        int p;
        cin >> p;
        if(p<=a) ++q1;
        else if(p<=b) ++q2;
        else ++q3;
    }
    cout << min(q1, min(q2, q3)) << endl;
    return 0;
}


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

using namespace std;

int main()
{
	int N,i,halfN;
	int *d;
	cin >> N;
	d = (int*)malloc(sizeof(int)*N);
	for (i = 0; i < N; i++)cin >> d[i];
	sort(d, d + N);//小さい順にソート
	halfN = (int)(N / 2);
	cout << d[halfN] - d[halfN - 1] << endl;
	return 0;
}

Measured memory_bytes: 640
import java.util.*;

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

        System.out.println(Math.max(Math.max(10 * a + b + c, a + 10 * b + c),
                                    10 * c + b + a));
    }
}

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

#define F 26

typedef struct trieNode{
  int cnt;
  struct trieNode *next[F];
} trie;

trie* newNode(void){
  trie *res=(trie *)malloc(sizeof(trie));
  res->cnt=0;
  int i;
  for(i=0;i<F;i++) res->next[i]=NULL;
  return res;
}

void freeNode(trie *r){
  if(r==NULL) return;
  int i;
  for(i=0;i<F;i++) freeNode(r->next[i]);
  free(r);
  return;
}

trie* add(trie *r,char *s){
  if(r==NULL) r=newNode();
  r->cnt++;
  if(*s!='\0') r->next[*s-'a']=add(r->next[*s-'a'],s+1);
  return r;
}

int count(trie *r){
  return r==NULL?0:r->cnt;
}

void calc(trie *r,char *s,int *cnt,int *before){
  if(*s=='\0') return;
  int local=r->cnt;
  int i;
  for(i=0;i<F;i++){
    int c=count(r->next[i]);
    local-=c;
    if(*s!='a'+i) cnt[(*s-'a')*F+i]+=c;
  }
  *before+=local;
  calc(r->next[*s-'a'],s+1,cnt,before);
  return;
}

void run(void){
  int n;
  scanf("%d",&n);
  char **sp=(char **)malloc(sizeof(char *)*n);
  char *s=(char *)malloc(sizeof(char)*(400000+n));
  trie *root=NULL;
  char *p=s;
  int i;
  for(i=0;i<n;i++){
    scanf("%s",p);
    root=add(root,p);
    sp[i]=p;
    p+=strlen(p)+1;
  }
  int *before=(int *)calloc(n,sizeof(int));
  int *cnt=(int *)calloc(F*F*n,sizeof(int));
  for(i=0;i<n;i++) calc(root,sp[i],cnt+F*F*i,before+i);
  int q;
  scanf("%d",&q);
  while(q--){
    int k;
    char pe[27];
    scanf("%d%s",&k,pe);
    k--;
    int ans=before[k];
    int j;
    for(i=F-1;i>=0;i--){
      for(j=i-1;j>=0;j--){
	ans+=cnt[k*F*F+(pe[i]-'a')*F+pe[j]-'a'];
      }
    }
    printf("%d\n",ans+1);
  }
  free(sp);
  free(s);
  freeNode(root);
  free(before);
  free(cnt);
  return;
}

int main(void){
  run();
  return 0;
}


Measured memory_bytes: 292352
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin>>n;
  vector<int> t(n);
  int sum=0;
  for (int i = 0; i < n; i++){
    cin >> t[i];
    sum += t[i];
  }
  int m;
  cin >> m;
  vector<int> p(m), x(m);
  for (int i = 0; i < m;i++){
    cin >> p[i] >> x[i];
    int tmp = sum;
    tmp -= t[p[i] - 1];
    tmp += x[i];
    cout << tmp << endl;
  }
  return 0;
}

Measured memory_bytes: 3640
#include<iostream>
using namespace std;
int main(){
	int n, l,i;
	int taste=0;
	cin >> n >> l;

	if (l+n-1<0)		{i = 1;n = n-1;}
	else if (l + 1 - 1 <= 0 && l + n - 1 >= 0)		{ i = 1; }
	else		{ i = 2; }

	for (i; i <= n; i++){
		taste += l + i - 1;
	}
	cout << taste << endl;

	return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Runtime.InteropServices;
using System.Security.Policy;
using System.Text;
using System.Threading.Tasks;

class Program
{   static void Main(string[] args)
    {
        string s = Console.ReadLine();
        bool ok = true;
        for (int i = 0; i < s.Length; i++)
        {
            char c = s[i];
            if(i % 2 == 0)
            {
                if (c != 'R' && c != 'U' && c != 'D')
                {
                    ok = false;
                    break;
                }
            }
            else
            {
                if (c != 'L' && c != 'U' && c != 'D')
                {
                    ok = false;
                    break;
                }
            }
        }
        if (ok)
        {
            Console.WriteLine("Yes");
            return;
        }
        Console.WriteLine("No");
    }
}


Measured memory_bytes: 11092
#include <bits/stdc++.h>
const int mu=1000000007;
const int N=3005,inv2=(mu+1)>>1;
int dp[N][N],a[N],x,y,n,m,ans;
long long ksm(int x,int y){
	long long ans=1;
	for (;y;y>>=1,x=x*1ll*x%mu)
		if (y&1) ans=ans*x%mu;
	return ans;
}
int main(){
	scanf("%d%d",&n,&m);
	for (int i=1;i<=n;i++) scanf("%d",&a[i]);
	for (int i=1;i<=n;i++)
		for (int j=1;j<=n;j++)
			if (a[i]>a[j]) dp[i][j]=1;
	for (int i=1;i<=m;i++){
		scanf("%d%d",&x,&y);
		dp[x][y]=dp[y][x]=1ll*(dp[x][y]+dp[y][x])*inv2%mu;
		for (int j=1;j<=n;j++){
			if (j==x || y==j) continue;
			dp[y][j]=dp[x][j]=(dp[y][j]+dp[x][j])*1ll*inv2%mu;
			dp[j][y]=dp[j][x]=(dp[j][y]+dp[j][x])*1ll*inv2%mu; 
		}
	}	
	for(int i=1;i<=n;i++)
		for (int j=i+1;j<=n;j++)
			ans=(ans+dp[i][j])%mu;
	printf("%d",ans*ksm(2,m)%mu); 
}

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


int main(){
    while(true){
        int H, W;
        cin >> H >> W;
        if(H==0&&W==0) break;
        for(int row=0; row<H; row++){
            for(int col=0; col<W; col++){
                cout << "#";
            }
            cout << endl;
        }
        cout << endl;
    }
    return 0;
}


Measured memory_bytes: 3104
#define _CRT_SECURE_NO_WARNINGS

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <memory.h>
#include <math.h>
#include <assert.h>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <string>
#include <algorithm>
#include <iostream>
#include <functional>
#include <unordered_set>
#include <bitset>

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define Fi first
#define Se second
#define pb(x) push_back(x)
#define szz(x) (int)x.size()
#define rep(i,n) for(int i=0;i<n;i++)
#define all(x) x.begin(),x.end()
typedef tuple<int, int, int> t3;

int n;
vector <int> w;

int main() {
	scanf("%d", &n);
	for (int i = 1; i <= n; i++) {
		int x; scanf("%d", &x);
		w.pb(x - i);
	}
	sort(all(w));
	int v = w[szz(w) / 2];
	ll ans = 0;
	for (int e : w) {
		ans += abs(e - v);
	}
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 1400
#include<bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); 
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#define int long long
void test_case(){
	int a, b, c, d; cin>>a>>b>>c>>d;
	int ans = b*d;
	ans  = max(ans, a*c);
	ans = max(ans, a*d);
	ans = max(ans, b*c);
	
	if(a < 0 && b > 0){
		ans = max(ans, 0LL);
	}
	if(c < 0 && d > 0){
		ans = max(ans, 0LL);
	}
	cout<<ans<<endl;
	
}
		
 
signed main(){
	IOS;
	int t=1, i=1; 
	//cin>>t;
	while(t--){
		//cout<<"Case #"<<i<<": ";
		test_case();
		i++;
	}
}


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

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;

#define pb push_back
#define rep(i, a, n) for(int i = (a); i < (n); i++)
#define dep(i, a, n) for(int i = (a); i >= (n); i--)
#define mod (ll)(1e9+7)
#define int ll

__attribute__((constructor))
void initial() {
  cin.tie(0);
  ios::sync_with_stdio(false);
}


signed main() {
  int x;
  cin >> x;
  if(x < 1200) {
    cout << "ABC" << endl;
  }else {
    cout << "ARC" << endl;
  }
}


Measured memory_bytes: 256
import sys
from math import ceil

def input():
    return sys.stdin.readline().strip()

def iinput():
    return int(input())

def finput():
    return float(input())

def tinput():
    return input().split()

def rinput():
    return map(int, tinput())

def rlinput():
    return list(rinput())

def nok(a, b):
    m = a * b
    while a != 0 and b != 0:
        if a > b:
            a %= b
        else:
            b %= a
    return m // (a + b)    


def main():
    w, h, x, y = rinput()
    if x == w / 2 and y == h / 2:
        print(w * h / 2, 1)
    else:
        print(w * h / 2, 0)
    
    
    
main()

Measured memory_bytes: 3064
s = input()
t = input()
a = len(s)
b = len(t)
ans = 2000
for i in range(a-b+1):
  k = 0
  for j in range(b):
    if s[i+j] != t[j]:
      k += 1
  ans = min(ans,k)
print(ans)

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

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

    if(N==1 && M==1){
        cout << 1 << endl; return 0;
    }
    
    if(N==1){
        cout << M-2 << endl; return 0;
    }

    if(M==1){
        cout << N-2 << endl; return 0;
    }

    cout << (N-2)*(M-2) <<endl; 
}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
#define LL long long
#define Lowbit(X) (X&(-X))
#define Lson (X<<1)
#define Rson (X<<1|1)
#define Cl(X,Y) memset((X),(Y),sizeof(X))
#define FOR(i,A,B) for(int i=A;i<=B;i++)
#define BOR(i,A,B) for(int i=A;i>=B;i--)
#define FOR_SIDE(i,A) for(int i=Head[A];i;i=Next[i])
#define INF 0x7fffffff
using namespace std;
const int MAXN=2e3+10;

int DP[MAXN][MAXN];
bool Vis[MAXN][MAXN];
int Row,Line,Stax,Stay,Endx,Endy,New,A,B;
char Map[MAXN][MAXN];
int Dx[5]={0,0,-1,0,1},Dy[5]={0,1,0,-1,0};
int Dx5[21]={0,-1,-1,1,1,0,-1,-2,-2,-2,-2,-2,-1,0,1,2,2,2,2,2,1};
int Dy5[21]={0,1,-1,-1,1,2,2,2,1,0,-1,-2,-2,-2,-2,-2,-1,0,1,2,2};

struct Node { int E,F; };
queue<Node>Mine;

inline void DFS(int X,int Y,int Time) {
    Vis[X][Y]=true;
    DP[X][Y]=Time;
    FOR(i,1,4) {
        int Nx=X+Dx[i],Ny=Y+Dy[i];
        if(Nx>Row || Nx<1 || Ny>Line || Ny<1 || Vis[Nx][Ny]) continue;
        DFS(Nx,Ny,Time);
    }
    FOR(i,1,20) {
        int Nx=X+Dx5[i],Ny=Y+Dy5[i];
        if(Nx<=Row && Nx>=1 && Ny<=Line && Ny>=1 && !Vis[Nx][Ny]) {
            Mine.push(Node{ Nx,Ny }); 
			if(DP[Nx][Ny]) DP[Nx][Ny]=min(Time+1,DP[Nx][Ny]);
			else DP[Nx][Ny]=Time+1;
        }
    }
}

int main() {
    scanf("%d %d",&Row,&Line);
    scanf("%d %d",&Stax,&Stay);
    scanf("%d %d",&Endx,&Endy);
    FOR(i,1,Row) { 
		scanf("%s",Map[i]+1); 
		FOR(j,1,Line) if(Map[i][j]=='#') Vis[i][j]=true;
	}
	Mine.push(Node{ Stax,Stay });
	while(!Mine.empty()) {
		int W=Mine.front().E,S=Mine.front().F;
		if(Vis[W][S]) { Mine.pop(); continue; }
        DFS(W,S,DP[W][S]);
		Mine.pop();
    }
    if(!Vis[Endx][Endy]) { printf("-1\n"); }
    else { printf("%d\n",DP[Endx][Endy]); }
    return 0;
}


Measured memory_bytes: 15616