akhauriyash/Code-Regression huggingface dataset:
use std::io;
use std::io::BufRead;

fn main() {
    let mut sc = Scanner::new(std::io::stdin());
    let n: usize = sc.next().unwrap();
    let mut graph: Vec<Vec<usize>> = vec![vec![]; n];
    for _ in 1..n {
        let mut x: usize = sc.next().unwrap();
        let mut y: usize = sc.next().unwrap();
        x -= 1;
        y -= 1;
        graph[x].push(y);
        graph[y].push(x);
    }
    let res = recur(&graph, 0, n);
    println!("{}", if res == 0 { "Bob" } else { "Alice" });
}

fn recur(graph: &Vec<Vec<usize>>, i: usize, p: usize) -> usize {
    let mut res = 0;
    for j in graph[i].iter() {
        if *j != p {
            res ^= recur(graph, *j, i) + 1;
        }
    }
    res
}

/// Scanner
///
/// # Example
/// ```
/// use contest::io::scanner;
/// let mut sc = scanner::Scanner::new("1 2 \n\n \r\t \n 3.5".as_bytes());
/// assert_eq!("1".to_string(), sc.next::<String>().unwrap());
/// assert_eq!(2, sc.next().unwrap());
/// assert_eq!(3.5, sc.next().unwrap());
/// assert_eq!(None, sc.next::<i32>());
/// ```

pub struct Scanner<R: io::Read> {
    br: io::BufReader<R>,
    // Read tokens are stored in reversed order per line.
    buf: Vec<String>,
}

impl<R: io::Read> Scanner<R> {
    pub fn new(r: R) -> Scanner<R> {
        Scanner {
            br: io::BufReader::new(r),
            buf: vec![],
        }
    }
    #[inline]
    pub fn next<T>(&mut self) -> Option<T>
        where T: std::str::FromStr,
              T::Err: std::fmt::Debug
    {
        self.next_string().map(|s| s.parse::<T>().expect("Parse failed: "))
    }
    fn next_string(&mut self) -> Option<String> {
        self.buf.pop().or_else(|| match self.update() {
            true => self.next_string(),
            false => None,
        })
    }
    #[inline]
    fn update(&mut self) -> bool {
        let mut s = String::new();
        let res = self.br.read_line(&mut s);
        match res.expect("I/O error.") {
            0 => false,
            _ => {
                self.buf = s.split_whitespace().map(|x| x.to_string()).rev().collect();
                true
            }
        }
    }
}


Measured memory_bytes: 16636
#include "bits/stdc++.h"
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000


int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int c[3][3];
    rep(i, 3) rep(j, 3) cin >> c[i][j];
    rep(i, 2) {
        rep(j, 2) {
            if(c[i + 1][j] - c[i][j] != c[i + 1][j + 1] - c[i][j + 1]) {
                cout << "No" << endl;
                return 0;
            }
        }
    }
    cout << "Yes" << endl;

    return 0;
}
// a1 + b1 | a2 + b1 | a3 + b1
// a1 + b2 | a2 + b2 | a3 + b2

Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
int main(void){
    char s[200], p[100], copy[100];
    int i;
    fgets(s, sizeof(s), stdin);
    fgets(p, sizeof(p), stdin);
    //printf("%s", s);
    for(i=0; i < 200;i++){
        if(s[i] == '\n'){
         s[i] = '\0';
         break;
        }
    } 
    for(i=0; i < 100;i++){
        if(p[i] == '\n'){
         p[i] = '\0';
         break;
        }
    }
    //printf("%s\n", p);
    strcpy(copy, s);
    strcat(s, copy);
    //printf("%s\n", s);
    if((strstr(s, p)) == NULL){
        printf("No\n");
    }else{
        printf("Yes\n");
    }
    return 0;
}


Measured memory_bytes: 2100
# include <cmath>
# include <iostream>
# include <queue>
# include <set>
# include <stack>
# include <string>
# include <vector>


using namespace std;


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

    float val = 0;
    for (int i=0; i<n; i++) {
        val += 1 / a[i];
    }
    cout << 1/ val << endl;
    return 0;
}



Measured memory_bytes: 256
n,m=map(int,input().split())
sc=[list(map(int,input().split())) for _ in range(m)]
a=[0]*(n+1)
if n!=1:
    a[1]=1
d=[-1]*(n+1)
flg=True
for i in range(m):
    s=sc[i][0]
    c=sc[i][1]
    if d[s]==-1 or a[s]==c:
        a[s]=c
        d[s]=0
    else:
        flg=False
ans=int("".join(map(str,a)))
if ans>=10**(n-1) and flg:
    print(ans)
elif n==1 and ans==0:
    print(ans)
else:
    print(-1)

Measured memory_bytes: 9212
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
constexpr ll MOD = 1e9 + 7;
//constexpr ll MOD = 998244353;
//constexpr ll MOD = ;
ll mod(ll A, ll M) {return (A % M + M) % M;}
constexpr ll INF = 1LL << 60;
template<class T> bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return false;}
template<class T> bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return false;}
ll divceil(ll A, ll B) {return (A + (B - 1)) / B;}
#define FINALANS(A) do {cout << (A) << '\n'; exit(0);} while (false)

int main()
{
  ll a, b, c, d, e;
  cin >> a >> b >> c >> d >> e;

  ll k;
  cin >> k;

  cout << ((e - a <= k)
               ? "Yay!"
               : ":(")
       << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
vector<long long int>vec1,vec2;
int bs(long long int a){
	int l=0,r=vec2.size();
	while(l<=r){
		int mid=(l+r)/2;
		if(vec2[mid]<=a){
			l=mid+1;
		}
		else
			r=mid-1;
	}
	if(l>vec2.size())
		return vec2.size();
	return l;
}
int main(){
	int n,m,k;
	cin >> n >> m >> k;
	int a;
	cin >> a;
	vec1.push_back(a);
	for(int i=1;i<n;i++){
		cin>> a;
		vec1.push_back(vec1[i-1]+a);
	}
	cin >>a ;
	vec2.push_back(a);
	for(int i=1;i<m;i++){
		cin >> a;
		vec2.push_back(a+vec2[i-1]);
	}
	int ans=bs(k);
	for(int i=0;i<n;i++){
		if(vec1[i]>k){
			break;
		}
		//cout << bs(k-vec1[i]);
		ans=max(ans,i+bs(k-vec1[i])+1);
	}
	cout << ans << '\n';
}


Measured memory_bytes: 7964
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define MOD 1000000007
using namespace std;
int main()
{
    string s;
    cin >> s;
    string t = "";
    vector<string> v;
    for(int i = s.size() - 1;i >= 0;i--)
    {
        if(s[i] == 'r')
        {
            if(s[i - 2] == 'm')
            {
                v.push_back("dreamer");
                i -= 6;
            }
            else
            {
                v.push_back("eraser");
                i -= 5;
            }
        }
        else
        {
            if(s[i] == 'm')
            {
                v.push_back("dream");
                i -= 4;
            }
            else
            {
                v.push_back("erase");
                i -= 4;
            }
        }
    }
    for(int i = v.size() - 1;i >= 0;i--)
    {
        t += v[i];
    }
    if(s == t)
    {
        cout << "YES\n";
    }
    else
    {
        cout << "NO\n";
    }
    
    return 0;
}

Measured memory_bytes: 1532
#include <iostream>
#include <string>
#include <cmath>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<iomanip>
#define _USE_MATH_DEFINES
#include <math.h>
#include <functional>
using namespace std;

#define rep(i,x) for(ll i=0;i<x;i++)
#define repn(i,x) for(ll i=1;i<=x;i++)

typedef long long ll;
const ll INF = 1e17;
const ll MOD =998244353;
const ll MAX = 1000001;

ll max(ll a, ll b) {
	if (a > b) { return a; }
	return b;
}

ll min(ll a, ll b) {
	if (a > b) { return b; }
	return a;
}

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

ll lcm(ll a, ll b) {
	return a / gcd(a, b) *b;
}

struct edge {
	ll ind;
	ll fr;
	ll to;
	ll d;
};


///////////////////////////



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

	vector<ll> a(N + 1);
	repn(i, N) cin >> a[i];

	ll sum = 0;
	repn(i, N) { sum += a[i]; }

	vector<vector<ll>> dp(N + 1, vector<ll>(sum + 1, 0));

	dp[0][0] = 1;

	repn(i, N) {
		rep(j, sum+1) {
			if (j < a[i]) { dp[i][j] = 2 * dp[i - 1][j]; }
			else { dp[i][j] = 2 * dp[i - 1][j] + dp[i - 1][j - a[i]]; }
			dp[i][j] %= MOD;
		}
	}

	
	ll ans = 1;
	repn(i, N) { ans = ans * 3 % MOD; }

	for (ll i = (sum + 1) / 2; i <= sum; i++) {
		ans = ans - 3 * dp[N][i];
		ans %= MOD;
		if (ans < 0) { ans += MOD; }
	}

	vector<vector<ll>> dp2(N + 1, vector<ll>(sum + 1, 0));
	dp2[0][0] = 1;

	repn(i, N) {
		rep(j, sum+1) {
			if (j < a[i]) { dp2[i][j] =dp2[i - 1][j]; }
			else { dp2[i][j] = dp2[i - 1][j] + dp2[i - 1][j - a[i]]; }
			dp2[i][j] %= MOD;
		}
	}

	if (sum % 2 == 0) {
		ans += 3 * dp2[N][sum / 2];
		ans %= MOD;
	}

	cout << ans;

	system("PAUSE");
}


Measured memory_bytes: 424000
#include <bits/stdc++.h>
    using namespace std;
     
int32_t main() {
      int N, counter=0, Vmin;
  	  long long sum=0;
	  cin >> N;
  
      vector<int> V(N);
	  for (int i = 0; i < N; i++) {
 	  cin >> V[i];
	  }
      
      for(int i = 0; i < N; i++){
        if(V[i] < 0){
          ++counter;
          V[i] = -V[i];
        }
       }
     
      sort(V.begin(), V.end());
        Vmin = V[0];
          
      for(int i = 0; i < N; i++){
            sum +=V[i];
      }
 
      if(counter%2 == 0)
        cout << sum <<endl;
      else
        cout << sum - 2*Vmin <<endl;

    }
        

Measured memory_bytes: 640
#include<stdio.h>
#define X 600
int main()
{
  int d,s;
  int i;
  while(scanf("%d",&d)!=EOF)
    {
      s=0;
      for(i=d;i<X;i+=d) s+=d*i*i;
      printf("%d\n",s);
    }
  return 0;
}

Measured memory_bytes: 596
#include<iostream>
#include<set>
#include<algorithm>
using namespace std;

int main(){
  
  int q, com, x;
  set<int> S;
  
  cin >> q;
  for(int i = 0;i < q;i++){
    cin >> com;
    
    if(com == 0){
      cin >> x;
      S.insert(x);
      cout << S.size() << endl;
    }else if(com == 1){
      cin >> x;
      if(S.find(x) != S.end()) cout << 1 << endl;
      else cout << 0 << endl;
    }
  }
  
  return 0;
}


Measured memory_bytes: 12444
#include <limits>
#include <iostream>
#include <queue>
#include <vector>

#define SZ(obj) static_cast<int>(obj.size())

template<typename T>
struct edge {
    int from, to;
    T cost;

    edge(int to, T cost) : from(-1), to(to), cost(cost) { }
    edge(int from, int to, T cost) : from(from), to(to), cost(cost) { }
    edge &operator=(const int& x) {
        to = x;
        return *this;
    }
    operator int() const { return to; }
};

template<typename T>
using Edges = std::vector<edge<T>>;

template<typename T>
using WeightedGraph = std::vector<Edges<T>>;

using UnWeightedGraph = std::vector<std::vector<int>>;

template<typename T>
using Matrix = std::vector<std::vector<T>>;

template<typename T>
std::vector<T> showrest_path_faster_algorithm(WeightedGraph<T>& g, int s) {
    const auto INF = std::numeric_limits<T>::max();
    std::vector<T> dist(SZ(g), INF);
    std::vector<int> pending(SZ(g), 0), times(SZ(g), 0);
    std::queue<int> que;

    que.emplace(s);
    pending[s] = true;
    ++times[s];
    dist[s] = 0;

    while (!que.empty()) {
        int p = que.front(); que.pop();
        pending[p] = false;
        for (auto& e : g[p]) {
            T next_cost = dist[p] + e.cost;
            if (next_cost >= dist[e.to]) continue;
            dist[e.to] = next_cost;
            if (!pending[e.to]) {
                if (++times[e.to] >= SZ(g)) return std::vector<T>();
                pending[e.to] = true;
                que.emplace(e.to);
            }
        }
    }

    return dist;
}


int main() {
    using namespace std;
    int v, e, r; cin >> v >> e >> r;
    WeightedGraph<int> g(v);
    while(e--) {
        int a, b, c; cin >> a >> b >> c;
        g[a].emplace_back(b, c);
    }
    auto dists = showrest_path_faster_algorithm(g, r);
    for (auto& e : dists) {
        if (e == numeric_limits<int>::max()) cout << "INF" << endl;
        else cout << e << endl;
    }

    return 0;
}


Measured memory_bytes: 15392
#include <algorithm>
#include <iostream>
#include <queue>
#include <string>
#include <vector>
#include <math.h>
#include <utility>
#include <map>
#include <queue>
#include <stack>

using namespace std;

#define INF 210000000
#define int long long

int gcd(int a, int b) {
  int amari = a % b;
  int c = b;
  if (amari == 0) {
    return b;
  } else {
    return gcd(b, amari);
  }
}

int lcm(int a, int b) { return a * b / gcd(a, b); }

signed main() {
    int n,m,c;
    cin >> n >> m >> c;
    int ans = 0;
    vector<int> b;
    for(int i=0;i<m;i++){
        int tmp;
        cin >> tmp;
        b.push_back(tmp);
    }
    for(int i=0;i<n;i++){
        int a=c;
        for(int j=0;j<m;j++){
            int tmp;
            cin >> tmp;
            a += tmp * b[j];
        }
        if(a > 0){
            ans++;
        }
    }
    cout << ans;
}



Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <queue>
#include <bitset>
#include <stack>
#include <functional>

#ifdef LOCAL
    #define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
    #define eprintf(...) 42
#endif

#define rep_(i, a_, b_, a, b, ...) for (int i = (a), i##_len = (b); i < i##_len; ++i)
#define rep(i, ...) rep_(i, __VA_ARGS__, __VA_ARGS__, 0, __VA_ARGS__)
#define reprev_(i, a_, b_, a, b, ...) for (int i = (b-1), i##_min = (a); i >= i##_min; --i)
#define reprev(i, ...) reprev_(i, __VA_ARGS__, __VA_ARGS__, 0, __VA_ARGS__)
#define all(x) (x).begin(), (x).end()
template <class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template <class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; }
// template <class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair <int,int> P;
typedef long double ld;

int main (void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n; cin >> n;
    // vector<P> p(n); for (auto &e : p) cin >> e.first >> e.second;
    ll ans = 0;
    rep (i, n) {
        ll l, r; cin >> l >> r;
        ans += r - l + 1;
    }
    cout << ans << "\n";
    return 0;
}

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

int main() {
  int N,M;
  cin >> N >> M;
  vector<int> a(N);
  int c,d;
  for(int i=0;i<M;i++){
    cin >> c >> d ;
    c--;
    d--;
    a[c]++;
    a[d]++;
  }  
  for(int i=0;i<N;i++){
    cout << a[i] << endl;
  }  
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define PI 3.14159265358979323846
#define int long long
constexpr int INF = numeric_limits<int>::max() / 2;
constexpr long long INFL = numeric_limits<long long>::max() / 2;
constexpr int MOD = 1000000007;
using Graph = vector<vector<int>>;



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

    string s;
    int N;
    cin>>s>>N;
    int co=0;
    while(co<s.size()){
        int x='z'-s[co]+1;
        if(N>=x && s[co]!='a'){
            s[co]='a';
            N-=x;
        }
        co++;
    }
    char e=s[s.size()-1]+N%26;
    s[s.size()-1]=e;
    cout << s << endl;



}


Measured memory_bytes: 592
#include <bits/stdc++.h>
using namespace std;
template <class T> inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T> inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return 1;
    }
    return 0;
}
using ll = long long;

#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define endl "\n"
const double EPS = 1e-7;
const int INF = 1 << 30;
const ll LLINF = 1LL << 60;
const double PI = acos(-1);
constexpr int MOD = 1000000007;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

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

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, k;
    cin >> n >> k;
    int ans = 0;
    for(int i = 0; i < n; i++) {
        int x;
        cin >> x;
        ans += 2 * min(abs(0 - x), abs(x - k));
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
//Zory-2019
#include<bits/stdc++.h>
using namespace std;
namespace mine
{
    typedef long long ll;
    #define pr pair<int,int>
    #define FR first
    #define SE second
    #define MP make_pair
    #define PB push_back
    #define vc vector
    #define all(x) (x).begin(),(x).end()
    #define sz(x) ((int)(x).size())
    #define bin(x) (1ll<<(x))
    #define GG(x) if(x) {puts("error");exit(666);}
    #define fo(i,l,r) for(int i=(l),I=(r);i<=I;i++)
    #define fd(i,r,l) for(int i=(r),I=(l);i>=I;i--)
    ll qread()
    {
        ll ans=0,f=1;char c=getchar();
        while(c<'0' or c>'9') {if(c=='-')f=-1;c=getchar();}
        while('0'<=c and c<='9') ans=ans*10+c-'0',c=getchar();
        return ans*f;
    }
    void write(ll num)
    {
        if(num<0) putchar('-'),num=-num;
        if(num>=10) write(num/10);
        putchar('0'+num%10);
    }
    void write1(ll num){write(num);putchar(' ');}
    void write2(ll num){write(num);putchar('\n');}
    template<typename T> void chmax(T &x,const T y) {x=(x>y?x:y);}
    template<typename T> void chmin(T &x,const T y) {x=(x<y?x:y);}
    ll gcd(ll x,ll y){return y?gcd(y,x%y):x;}

    const int INF=0x3f3f3f3f;
    const int MOD=1e9+7;
    int mm(const int x){return x>=MOD?x-MOD:x;}
    template<typename T> void add(T &x,const int &y){x=(x+y>=MOD?x+y-MOD:x+y);}
    ll qpower(ll x,ll e,int mod=MOD){ll ans=1;GG(e<0)while(e){if(e&1)ans=ans*x%mod;x=x*x%mod;e>>=1;}return ans;}
    ll invm(ll x){return qpower(x,MOD-2);}
    const int N=1e6+10;

    struct BIT
    {
        int bit[N];BIT(){memset(bit,0,sizeof bit);}
        int lowbit(int x){return x&-x;}
        void add(int x,int c){while(x<N)bit[x]+=c,x+=lowbit(x);}
        int ask(int x){int ans=0;while(x>=1)ans+=bit[x],x-=lowbit(x);return ans;}
    }bit[2];
    int fm[3][N];int getid(int num){return 1+(num-1)/3;}
    void gg(){puts("No");exit(0);}
    int inv[2],flip[2];
	void main()
	{
        int n=qread();fo(op,0,2) fo(i,1,n) fm[op][i]=qread();
        fo(i,1,n)
        {
            if(getid(fm[0][i])!=getid(fm[1][i]) or getid(fm[1][i])!=getid(fm[2][i])) gg();
            bool x=fm[0][i]<fm[1][i] and fm[1][i]<fm[2][i],y=fm[0][i]>fm[1][i] and fm[1][i]>fm[2][i];
            if(!x and !y) gg();flip[i&1]+=y;
            int id=getid(fm[0][i]);if((id&1)^(i&1)) gg();
            inv[i&1]+=bit[i&1].ask(n-id+1),bit[i&1].add(n-id+1,1);
        }
        if((inv[0]&1)^(flip[1]&1) or (inv[1]&1)^(flip[0]&1)) gg();
        puts("Yes");
	}
};//(ans+MOD)%MOD
signed main()
{
    srand(time(0));
    mine::main();
}


Measured memory_bytes: 18176
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<n; i++)
#define cans cout << ans << endl
#define cyes cout << "Yes" << endl
#define cno cout << "No" << endl
typedef long long ll;


int main(){
    int n;
    cin >> n;
    string s;
    cin >> s;
    int r = 0;
    int now = 0;
    rep(i,n) if(s[i]=='R') r++;
    rep(i,r) if(s[i]=='R') now++;
    cout << r-now << endl;
    return 0;
}

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

int mod = 1000000007;
int64_t large = 9223372036854775807;

int main()
{
    int N;
    cin >> N;
    double ans = 0, tmp;
    for (int i = 0; i < N; i++)
    {
        cin >> tmp;
        ans += 1 / tmp;
    }
    cout << fixed << setprecision(15) << 1 / ans;
}

Measured memory_bytes: 256
n=int(input())
a=list(map(int,input().split()))
total=0
ans1=0
ans2=0
for i in a:
    total+=i
tmp1=total//n
tmp2=-(-total//n)
for i in a:
    ans1+=(i-tmp1)**2
for i in a:
    ans2+=(i-tmp2)**2
print(min(ans1,ans2))

Measured memory_bytes: 38256
#include<bits/stdc++.h>
using namespace std;
#define int long long
using ll = long long;
int32_t main()
{
    int n;
    cin>>n;
    string s;
    cin>>s;
    int R=0,G=0,B=0,sum=0;
    for(int i=0;i<n;i++)if(s[i]=='R')R++;else if(s[i]=='G')G++;else B++;
//    cout<<R<<" "<<G<<' '<<B<<endl;
//    cout<<R*G*B<<endl;
    sum=R*G*B;
//    rep(i,n){
//	    for(int j=1;j<=n;++j){
//		    int ni=i-j,nj=i+j;
//		    if(ni<0 ||nj>=n)break;
//		    if(s[i]!=s[ni]&&s[i]!=s[nj]&&s[ni]!=s[nj]){--sum;}//naritatanaikarahiku
//	    }
//    }
    for(int j=0;j<n;j++)
    {
    for(int i=1;i<=n;i++)
        {
            int a=j-i,b=i+j;
            if(a<0||b>=n)break;
          if(s[j]!=s[a]&&s[j]!=s[b]&&s[a]!=s[b])sum--;
        }
    }
        cout<<sum<<endl;
}


Measured memory_bytes: 3656
N,W = list(map(int, input().split()))
m = []
v = []
dp = [[0 for i in range(W+1)]for j in range(N+1)]
for i in range(N):
    a,b = map(int, input().split())
    m.append(a)
    v.append(b)

for i in range(N):
    for j in range(W):
        if j+m[i] <= W:
            dp[i+1][j+m[i]] = max(dp[i][j] + v[i], dp[i+1][j+m[i]])
        dp[i+1][j] = max(dp[i][j], dp[i+1][j])


print(max(dp[-1]))


Measured memory_bytes: 171272
N = int(input())
A = list(map(int, input().split()))

free = 0
colors = {}

for a in A:
    if a < 3200:
        ai = a // 400
        colors[ai] = True

    else:
        free += 1

lc = len(colors)

print(max(1, lc), lc + free)


Measured memory_bytes: 9052
#include <bits/stdc++.h>
typedef long long ll;
typedef unsigned long long ull;
#define reps(i,s,n) for(int (i)=(s);(i)<(n);++(i))
#define rep(i,n) reps(i,0,n)
#define reptr(i,n) for(int (i)=(n);(i)>=0;--(i))
#define All(x) (x).begin(),(x).end()
const ll MOD=1e9+7;
const int nmax=8;
using namespace std;

int main(){
  ll n;
  cin >> n;
  deque<ll> b;
  if(n%2==0){
    rep(i,n){
      ll a;
      cin >> a;
      if(i%2==0) b.push_back(a);
      else b.push_front(a);
    }
    for(ll i=0;i<b.size();i++){
      if(i!=0) cout << " ";
      cout << *(b.begin()+i);
    }
    cout << "\n";
  }else{
    rep(i,n){
      ll a;
      cin >> a;
      if(i%2==0) b.push_front(a);
      else b.push_back(a);
    }
    for(ll i=0;i<b.size();i++){
      if(i!=0) cout << " ";
      cout << *(b.begin()+i);
    }
    cout << "\n";
  }
}

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

static const long long MOD = 1000000007;

int main() {
    string S;
    cin >> S;
    int N = (int)S.size();
    vector<vector<int>> dp(1000000, vector<int>(13));
    dp[0][0] = 1;

    for (int i = 0; i < N; i++) {
        if (S[i] == '?') {
            for (int j = 0; j < 13; j++) {
                for (int k = 0; k < 10; k++) {
                    (dp[i + 1][(j * 10 + k) % 13] += dp[i][j]) %= MOD;
                }
            }
        } else {
            int k = S[i] - '0';
            for (int j = 0; j < 13; j++) {
                (dp[i + 1][(j * 10 + k) % 13] += dp[i][j]) %= MOD;
            }
        }
    }
    cout << dp[N][5] << endl;
    return 0;
}


Measured memory_bytes: 86272
n=int(input())
listP=list(map(int,input().split()))
counter =0
for i in range(1,n-1):
	if min(listP[i-1],listP[i],listP[i+1])==listP[i] or max(listP[i-1],listP[i],listP[i+1])==listP[i]:
		counter +=0
	else:
		counter +=1
print(counter)

Measured memory_bytes: 3060
using System;
using static System.Console;
using System.Collections.Generic;
using System.Linq;

namespace Atcoder
{
    class Program
    {
        static void Main(string[] args)
        {
            var a = InputNum();
            int sum = 0;
            for(int i = 1; i <= a; i++)
            {
                sum += i;
            }
            WriteLine(sum);
            
        }

        static int InputNum()
        {
            return int.Parse(ReadLine());
        }
        static List<int> InputNumList()
        {
            return ReadLine().Split(' ').Select(int.Parse).ToList();
        }
    }
}



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

using namespace std;

typedef int64_t ll;

template <class T1, class T2>
using dict = std::unordered_map<T1, T2>;

int main(){
    int N;
    cin >> N;
    ll B[N+1];
    rep(i,N-1){
        cin >> B[i+1];
    }
    B[0] = 100000000000;
    B[N] = 100000000000;
    ll ans = 0;
    rep(i,N){
        ans+=min(B[i],B[i+1]);
    }
    cout << ans << "\n";
}

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

#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 FORR(i, m, n) for (int i = m; i >= n; i--)
#define ALL(x) (x).begin(), (x).end()

using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const ll INF = 1e15;

int main() {
  ll s, w;
  cin >> s >> w;
  if (s <= w)
    cout << "unsafe" << endl;
  else
    cout << "safe" << endl;
  return 0;
}

Measured memory_bytes: 3584
#include<iostream>
#include<string>
int main(){
	std::string s;
	char k[6+1];
	int l=0,i=0,j=0;
	getline(std::cin,s);
	
	while(1){
		if(s[i] == '.' || s[i] == ',' || s[i] == ' ' || s[i] == '\0'){
			if(l>=3 && l<=6){
				k[l] = '\0';
				std::cout << (j?" ":"") << k;
				++j;
			}
			l=0;
			++i;
			
			if(s[i]=='\0')
				break;
		}else{
		k[l] = s[i];
		++l;
		
		++i;
		}
	}
	std::cout << std::endl;
}

Measured memory_bytes: 1168
using System;
using System.Linq;
using System.Collections.Generic;

static class Program{
    static void Main() {
        int[]ab=Console.ReadLine().Split().Select(int.Parse).ToArray();
        int a=ab[0];
        int b=ab[1];
        Console.WriteLine(Math.Max(a+a-1,Math.Max(a+b,b+b-1)));
    }
}


Measured memory_bytes: 13268
#define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
using namespace std;

/*BigInteger
#include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/multiprecision/cpp_int.hpp>
#include <boost/rational.hpp>
namespace xxx = boost::multiprecision;
using Bint = xxx::cpp_int;
using Real = xxx::number<xxx::cpp_dec_float<1024>>;
*/

#define int long long
#define pb(x) push_back(x)
#define m0(x) memset((x), 0LL, sizeof(x))
#define mm(x) memset((x), -1LL, sizeof(x))

//container
#define ALL(x) (x).begin(), (x).end()
#define RALL(a) (a).rbegin(), (a).rend()
#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 UNIQUE(v) (v).erase(unique((v).begin(), (v).end()), (v).end());
#define PERM(c) \
  sort(ALL(c)); \
  for (bool c##p = 1; c##p; c##p = next_permutation(ALL(c)))

// debug
#define GET_VAR_NAME(variable) #variable
#define test(x) cout << GET_VAR_NAME(x) << " = " << x << endl;

// bit_macro
#define Bit(n) (1LL << (n))
#define Bitset(a, b) (a) |= (1LL << (b))
#define Bitunset(a, b) (a) &= ~(1LL << (b))
#define Bitcheck(a, b) ((((a) >> (b)) & 1LL) == 1LL)
#define Bitcount(a) __builtin_popcountll((a))

//typedef
typedef long long lint;
typedef unsigned long long ull;
typedef complex<long double> Complex;
typedef pair<int, int> P;
typedef tuple<int, int, int> TP;
typedef vector<int> vec;
typedef vector<vec> mat;

//constant
constexpr int INF = (int)1e18;
constexpr int MOD = (int)1e9 + 7;
constexpr double PI = (double)acos(-1);
constexpr double EPS = (double)1e-10;
constexpr int dx[] = {-1, 0, 0, 1, 0, -1, -1, 1, 1};
constexpr int dy[] = {0, -1, 1, 0, 0, 1, -1, 1, -1};

//
template <typename T>
void chmax(T &a, T b) { a = max(a, b); }
template <typename T>
void chmin(T &a, T b) { a = min(a, b); }
//
inline int toInt(string s) {
  int v;
  istringstream sin(s);
  sin >> v;
  return v;
}
template <class T>
inline string toString(T x) {
  ostringstream sout;
  sout << x;
  return sout.str();
}

//
struct Accelerate_Cin {
  Accelerate_Cin() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout << fixed << setprecision(20);
  };
} Accelerate_Cin;

signed main() {
  int N;
  cin >> N;
  int a[30][30];
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < N; j++) {
      cin >> a[i][j];
    }
  }

  static int dp[30][Bit(22)];
  m0(dp);
  dp[0][0] = 1;

  for (int i = 0; i < N; i++) {
    for (int bit = 0; bit < Bit(N); bit++) {
      if (Bitcount(bit) != i) continue;
      for (int j = 0; j < N; j++) {
        if (a[i][j] && !Bitcheck(bit, j)) {
          (dp[i + 1][bit | Bit(j)] += dp[i][bit]) %= MOD;
        }
      }
    }
  }

  cout << dp[N][Bit(N) - 1] << endl;
  return 0;
}


Measured memory_bytes: 983296
N = int(input())
A = list(map(int,input().split())) 

tmp = 0
for a in A:
    tmp ^= a

ans = []

for a in A:
    ans.append(tmp^a)


an_c = str(ans[0])
for an in ans[1:]:
    an_c += " " + str(an)
    
print(an_c)


Measured memory_bytes: 31340
import java.util.*;

public class Main {
		public static void main(String[] args) {
			
			Scanner sc = new Scanner(System.in);
			
			int A = sc.nextInt();
			int B = sc.nextInt();
			
			if((A != 1) && (B != 1)) {
				System.out.println(1);
			}else if((A != 2) && (B != 2)) {
				System.out.println(2);
			}else {
				System.out.println(3);
			}
			
}
}

Measured memory_bytes: 23124
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

#define REP(i,s,n) for(int i=(int)(s);i<(int)(n);i++)

using namespace std;
typedef vector<int> VI;
typedef pair<int, int> PI;
typedef pair<int, PI> PIPI;

const int DIE = 43200;

string convert(int time) {
  int h = time / 3600;
  int m = time / 60 % 60;
  int s = time % 60;
  stringstream ss;
  ss << setfill('0') << setw(2) << h
     << ":" << setfill('0') << setw(2) << m
     << ":" << setfill('0') << setw(2) << s;
  return ss.str();
}


int main(void) {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  while (cin >> n && n) {
    vector<vector<bool> > tbl(DIE, vector<bool>(n, false));
    REP(i, 0, n) {
      int u[3];
      cin >> u[0] >> u[1] >> u[2];
      set<int> times;
      int perm[3] = {0, 1, 2};
      do {
	REP(r, 0, 60) {
	  int h = u[perm[0]];
	  int m = u[perm[1]];
	  int s = u[perm[2]];
	  h = (h + r) % 60;
	  m = (m + r) % 60;
	  s = (s + r) % 60;
	  // Check if they are consistent
	  if (h % 5 != m / 12) { continue; }
	  int time = (h / 5) * 3600 + m * 60 + s;
	  times.insert(time);
	}
      } while(next_permutation(perm, perm + 3));
      for (set<int>::iterator it = times.begin(); it != times.end(); ++it) {
	tbl[*it][i] = true;
      }
    }
    // Shakutori
    int pos = 0;
    PIPI mi(1e8, PI(0, 0));
    int kind = 0;
    VI freq(n, 0);
    REP(i, 0, DIE) {
      while (pos < DIE && kind < n) {
        REP(j, 0, n) {
	  if (tbl[pos][j]) {
	    freq[j] += 1;
	    if (freq[j] == 1) {
	      kind += 1;
	    }
	  }
	}
	pos += 1;
      }
      if (kind >= n) {
	mi = min(mi, PIPI(pos - i, PI(i, pos - 1))); // note: inclusive!
      }
      // decrement
      REP(j, 0, n) {
	if (tbl[i][j]) {
	  freq[j] -= 1;
	  if (freq[j] == 0) { kind -= 1; }
	}
      }
    }
    cout << convert(mi.second.first) << " " << convert(mi.second.second) << "\n";
  }
}

Measured memory_bytes: 6240
#include <iostream>
#include <string>

using namespace std;

int main()
{
	int sx, sy, tx, ty;
	cin >> sx >> sy >> tx >> ty;
	int w = tx - sx;
	int h = ty - sy;

	string ans;
	ans
		.append(h, 'U').append(w, 'R').append(h, 'D').append(w, 'L')
		.append(1, 'L').append(h + 1, 'U').append(w + 1, 'R').append(1, 'D')
		.append(1, 'R').append(h + 1, 'D').append(w + 1, 'L').append(1, 'U');
	cout << ans << endl;
}


Measured memory_bytes: 256
#include<stdio.h>
 
int main(void)
{
    int a;
    int b;
    int d;
    int r;
    double f;
     
    scanf("%d %d", &a, &b);
     
    d = a / b;
    r = a % b;
    f = 1.0 * a / b;
     
    printf("%d %d %lf\n", d, r, f);
     
    return (0);
}

Measured memory_bytes: 636
import math
import os
import sys
 
if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")
 
sys.setrecursionlimit(2147483647)
INF = float("inf")
 
N = int(sys.stdin.readline())
GA, SA, BA = list(map(int, sys.stdin.readline().split()))
GB, SB, BB = list(map(int, sys.stdin.readline().split()))
 
 
def knapsack(n, ga, sa, ba, gb, sb, bb):
    values = []
    weights = []
    if gb / ga > 1:
        values.append(gb - ga)
        weights.append(ga)
    if sb / sa > 1:
        values.append(sb - sa)
        weights.append(sa)
    if bb / ba > 1:
        values.append(bb - ba)
        weights.append(ba)
    if len(values) == 3:
        # dp[i]: 重さ i 以下で選ぶのの価値の最大値
        dp = [0] * (n + 1)
        dp[0] = n
        for i in range(1, n + 1):
            x = dp[i - 1]
            for w, v in zip(weights, values):
                if i - w >= 0:
                    x = max(x, dp[i - w] + v)
            dp[i] = x
        return dp[n]
    if len(values) == 2:
        w1, w2 = weights
        v1, v2 = values
        if (v1 + w1) / w1 < (v2 + w2) / w2:
            v1, v2 = v2, v1
            w1, w2 = w2, w1
        c1 = n // w1
        c2 = (n - w1 * c1) // w2
        ret = n + v1 * c1 + v2 * c2
        while c1 >= 0:
            a = n - w1 * c1 - w2 * c2
            c1 -= max(1, math.ceil((w2 - a) / w1))
            c2 = (n - w1 * c1) // w2
            ret = max(ret, n + v1 * c1 + v2 * c2)
            if w1 * c1 + w2 * c2 == n:
                break
        return ret
    if len(values) == 1:
        return n + n // weights[0] * values[0]
    return n
 
 
ans = knapsack(N, GA, SA, BA, GB, SB, BB)
ans = knapsack(ans, GB, SB, BB, GA, SA, BA)
print(int(ans))

Measured memory_bytes: 3192
#include<iostream>
#include<algorithm>
#define rep(i,s,n) for(int i=s;i<n;i++)
#define Z 10005
using namespace std;
int d[Z+1];
int main(){
	int n,m,k,r,l;
	while(true){
		cin>>n>>k>>m>>r;
		if(!(n+m+k+r))break;
		rep(i,0,Z)d[i]=0;
		k=1,l=n;
		rep(i,0,Z)d[i]+=k/l,k%=l,k*=10;
		if(m)rep(i,1,n){k=1,l=i*n;rep(j,0,Z)d[j]+=k/l,k%=l,k*=10;}
		for(int i=Z;i>0;i--)d[i-1]+=d[i]/10,d[i]%=10;
		cout<<d[0]<<".";
		rep(i,1,r+1)cout<<d[i];
		cout<<endl;
	}
	return 0;
}

Measured memory_bytes: 2996
import java.util.Scanner;

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

    boolean ok = false;
    LOOP: for (int i = 0; i <= n; i += 4) {
      for (int j = 0; i + j <= n; j += 7) {
        if (i + j == n) {
          ok = true;
          break LOOP;
        }
      }
    }

    if (ok) {
      System.out.println("Yes");
    } else {
      System.out.println("No");
    }
    
    sc.close(); 
  }
}


Measured memory_bytes: 21972
#include <stdio.h>
#include <stdlib.h>

typedef struct node {
    int H, W;
    struct node *next;
} node;


int main()
{
    node *head = NULL, *cur = NULL;

    while( 1 ){
        //メモリ確保
        node *new = (node *)malloc(sizeof(node));
        if( new == NULL ) fprintf(stderr, "ERROR! : malloc\n"), exit(-1);

        //標準入力
        scanf("%d %d", &new->H, &new->W);
        new->next = NULL;

        //終了判定
        if( 0 == new->H && 0 == new->W ) break;

        //連結
        if( head == NULL ) head = new;
        else cur->next = new;
        cur = new;
    }

    //標準出力
    cur = head;
    while( cur ){
        int i, j;
        for( i = 0; i < cur->H; ++i ){
            for( j = 0; j < cur->W; ++j ){
                printf("#");
            }
            printf("\n");
        }
        printf("\n");
        cur = cur->next;
    }

    return 0;
}

Measured memory_bytes: 572
use proconio::input;
use proconio::fastout;


#[fastout]
fn main() {
    input! {
        n: usize,
        mut a: [usize; n],
    }

    a.sort();
    a.reverse();
    let mut ans = a[0];
    for i in 1 .. n - 1 {
        ans += a[(i + 1) / 2];
    }

    println!("{}", ans);
}


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

int main() {
  int N;
  cin >> N;
  
  int ans = 0;
  for (int i = 1; i <= N; i+=2){
    int count = 0;
    for (int j = 1; j <= N; j++){
      if (i%j == 0) count ++;
    }
    if (count == 8) ans ++;
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
//#include <numeric>
//#include <vector>
	//#include<math.h>
	//#include <algorithm>
	//#include <functional>
	//#include <numeric>
	//#include<cmath>
//#include <stdio.h> 
#include <cstdint>
	//#include <string>
	//#include <cstdlib>
	//#define pi 3.14159265359
using namespace std;


	int main() {

		uint64_t n;
		cin >> n;
		uint64_t a, b;
		cin >> a;
		uint64_t def = 0;

		for (uint64_t i = 1; i < n; i++) {
			cin >> b;
			if (a >= b) {
				def += 1;
				a = b;
			}
			else {
				//a = b;
			}
		}

		cout << def+1;

		return 0;

	}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int N = 52;
double a[N];
int main()
{
    int n;cin>>n;
    for (int i=1;i<=n;++i)
	   cin >> a[i];
	sort(a + 1, a + n + 1);
	for (int i = 2; i <= n; i++) {
		a[i] = (a[i] + a[i - 1]) / 2.0;
	}
	cout << a[n] << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define per(i,a,b) for(int i=a;i>=b;i--)
using namespace std;
const int N=2e5+5;
int a[N],n,pos,len1,len2;
int main(){
	scanf("%d",&n);
	rep(i,1,n) scanf("%d",&a[i]);
	sort(a+1,a+n+1,greater<int>());
	rep(i,1,n) if(a[i]>=i&&a[i+1]<i+1){	pos=i; break; }
	rep(i,pos+1,n) if(a[i]>=pos) len1++;
	puts((len1&1)||((a[pos]-pos)&1)?"First":"Second");
	return 0;
}

Measured memory_bytes: 640
#include <iostream>
using namespace std;
int main() {
    int n; cin >> n;
    int ans = 0, cnt = 1;
    for (int i = 0; i < n - 1; i++) {
        int a; cin >> a;
        if (a == cnt) { cnt++; continue; }
        else ans++;
    }
    int a; cin >> a;
    if (ans == n - 1 && a != 1) ans = -1;
    else if (a != cnt) ans++;
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cctype>
#include <complex>
#include <iomanip>
#include <iostream>
#include <queue>
#include <set>
#include <string>
#include <vector>

using std::cin;
using std::cout;
using std::endl;

using std::string;
using std::to_string;
using std::vector;
using std::set;
using std::queue;
using std::priority_queue;

using std::min;
using std::max;
using std::sort;
using std::abs;

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

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

    vector<string> b(m);
    for (int i = 0; i < m; i++) {
        cin >> b[i];
    }

    for (int i = 0; i <= n - m; i++) {
        for (int j = 0; j <= n - m; j++) {
            bool match = true;
            for(int x = 0; x < m; x++){
                for(int y = 0; y < m; y++){
                    if(a[i+x][j+y] != b[x][y]){
                        match = false;
                        goto out;
                    }
                }
            }
            out:
            if(match){
                cout << "Yes" << endl;
                return 0;
            }
        }
    }

    cout << "No" << endl;

    return 0;
}


Measured memory_bytes: 508
let input_array n = Array.init n (fun _ -> Scanf.scanf " %d" (fun e -> e));;

let correct a b c = let ab = Array.mapi (fun i ai -> ai * b.(i)) a in Array.fold_right (+) ab c > 0;;

let () = Scanf.scanf "%d %d %d" (fun n m c -> (
  let b = input_array m in
  let cnt = ref 0 in (
    for i = 1 to n do
      let a = input_array m in
      if correct a b c then cnt := !cnt + 1
    done;
    Printf.printf "%d\n" !cnt
  )
))

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
#define all(x) x.begin(),x.end()
#define rep(i,j,n) for (long long i = j; i < (long long)(n); i++)
#define _GLIBCXX_DEBUG
#define MOD 1000000007
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; }
//(a+b-1)/b
//priority_queue<ll, vector<ll>, greater<ll>> q;
using pl = pair<ll,ll>;
using vvb=vector<vector<bool>>;
using vb= vector<bool>;
ll modpow(ll a,ll b,ll p){
	if(b==0) return 1;
	if(b%2==0){
		ll t=modpow(a,b/2,p);
		return t*t%p;
	}
	return a*(modpow(a,b-1,p))%p;
} 
//cout << fixed << setprecision(桁数);
//__builtin_popcount()
signed main(){
	ll n; cin>>n;
	ll sum=0,ans=0;
	vl t(n);
	rep(i,0,n)cin>>t[i],sum+=t[i];
	ll m; cin>>m;
	rep(i,0,m){
		ll p,x; cin>>p>>x;
		ll ans=sum-t[p-1]+x;
		cout<<ans<<endl;
	}
		
	return 0;
}


Measured memory_bytes: 3612
#  --*-coding:utf-8-*--

import bisect

def main():
    N = int(input())
    L = sorted(map(int, input().split()))

    n = 0
    for i, a in enumerate(L):
        for j, b in enumerate(L[i+1:]):
            n += max(0, bisect.bisect_left(L, a+b)-(j + i + 2))

    print(n)


if __name__ == '__main__':
    main()



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

int main() {
    int a, b, c;
    cin >> a >> b >> c;
    if (a < b && b < c) {
        cout << "Yes" << endl; 
    }
    else {
        cout << "No" << endl;
    }

    return 0;
    
}


Measured memory_bytes: 3076
from collections import deque

N,k = map(int,input().split())

a = list(map(int,input().split()))

d = [-1] * N
d[0] = 0
q = deque()
q.append(1)

while(q):
    x = q.popleft()
    n = a[x - 1]
    if(d[n-1] == -1):
        d[n-1] = d[x-1] + 1
        q.append(n)

if(k <= max(d)):
    for i in range(N):
        if(d[i] == k):
            print(i+1)
            exit()


rS = n

d2 = [-1] * N
d2[rS - 1] = 0
q = deque()
q.append(rS)

while(q):
    x = q.popleft()
    n = a[x - 1]
    if(d2[n-1] == -1):
        d2[n-1] = d2[x-1] + 1
        q.append(n)
ma = max(d2) + 1
k -= d[rS - 1]
k %= ma

for i in range(N):
    if(d2[i] == k):
        print(i+1)
        exit()

Measured memory_bytes: 33840
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <vector>
#include <string>
#include <queue>
#include <deque>
#include <vector>
#include <stack>
#include <set>
#include <map>
#include <algorithm>

#define int long long
#define MOD7 1000000007
#define MOD9 1000000009

#define rep(i, n) for (int i = 0; i < (n); i++)
#define all(a) (a).begin(), (a).end()

using namespace std;

int dx[4] = { 1, 0, -1, 0 };
int dy[4] = { 0, -1, 0, 1 };

int nextInt() {int a; cin >> a; return a;}
char nextChar() {char a; cin >> a; return a;}
double nextDouble() {double a; cin >> a; return a;}
string nextString() {string a; cin >> a; return a;}

void inputVector(vector<int> &v, int &n) {rep(i,n){v.push_back(nextInt());}}
void inputVector(vector<double> &v, int &n) {rep(i,n){v.push_back(nextDouble());}}
void inputVector(vector<string> &v, int &n) {rep(i,n){v.push_back(nextString());}}

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

		vector< pair<int, int> > L;

		L.push_back(make_pair(w, h));

		rep(i, n) {
			int p, s;
			cin >> p >> s;

			vector< pair<int, int> >::iterator it = L.begin();
			rep(j, p - 1) it++;
			pair<int, int> pr = (*it);
			L.erase(it);

			s %= (pr.first + pr.second) * 2;

			bool ok = true;
			int type, len;
			if (s < pr.first) {
				type = 0;
				len = s;
				ok = false;
			}
			s -= pr.first;
			if (ok && s < pr.second) {
				type = 1;
				len = s;
				ok = false;
			}
			s -= pr.second;
			if (ok && s < pr.first) {
				type = 0;
				len = s;
				ok = false;
			}
			s -= pr.first;
			if (ok) {
				type = 1;
				len = s;
			}

			pair<int, int> p1, p2;
			if (type == 0) {
				p1 = make_pair(len, pr.second);
				p2 = make_pair(pr.first - len, pr.second);
				if (len > pr.first - len) {
					L.push_back(p2);
					L.push_back(p1);
				} else {
					L.push_back(p1);
					L.push_back(p2);
				}
			} else {
				p1 = make_pair(pr.first, len);
				p2 = make_pair(pr.first, pr.second - len);
				if (len > pr.second - len) {
					L.push_back(p2);
					L.push_back(p1);
				} else {
					L.push_back(p1);
					L.push_back(p2);
				}
			}
		}

		vector<int> a;
		for (auto e : L) {
			a.push_back(e.first * e.second);
		}

		sort(all(a));

		cout << a[0];
		for (int i = 1; i < a.size(); i++) {
			cout << ' ' << a[i];
		}
		cout << endl;
	}

    return 0;
}

Measured memory_bytes: 2956
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
typedef long long ll;
typedef pair<int,int> P;
typedef vector<int> vec;
typedef vector<vec> mat;
int main(){
    string n;
    int k,x;
    cin>>n>>k;
    ll dp[1000][2][4];
    dp[0][0][0]=1;
    rep(i,n.size())rep(j,2)rep(k,4){
        if(j==1) x=9;
        else x=n[i]-'0';
        rep(l,x+1) if(k+(l!=0)<4) dp[i+1][j||l<x][k+(l!=0)]+=dp[i][j][k];
    }
    cout<<dp[n.size()][0][k]+dp[n.size()][1][k]<<endl;
}

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

vector<long long> get_minFactor(long long max_n) {
    assert(max_n >= 0);

    if(max_n == 0)
        return {-1};
    if(max_n == 1)
        return {-1, -1};
    if(max_n == 2)
        return {-1, -1, 2};

    auto minFactor = vector<long long>(max_n + 1);
    iota(minFactor.begin(), minFactor.end(), 0);
    minFactor[0] = minFactor[1] = -1;

    for(long long i = 2; i * i <= max_n; ++i)
        if(minFactor[i] == i)
            for(long long j = i * i; j <= max_n; j += i)
                if(minFactor[j] == j)
                    minFactor[j] = i;
    
    return minFactor;
}

void solve(int TestCase) {
    int n;
    cin >> n;
    
    auto minFactor = get_minFactor(n+1);
    long long ret = 1;
    auto A = vector<long long>(n+1);
    A[1] = 1;
    for(long long i = 2; i <= n; ++i) {
        auto f = minFactor[i];
        long long cnt = 0;
        long long p = i;
        if(f == p) {
            A[i] = 2;
            ret += i * A[i];
            continue;
        }
        while(p % f == 0) cnt++, p /= f;
        A[i] = A[p] * (cnt + 1);
        ret += i * A[i];
        //cout << i << " " << A[i] << endl;
    }

    cout << ret << endl;
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
 
    int t = 1;
    //cin >> t;
    for(auto i = 1; i <= t; ++i) {
        //cout << "Case #"<< i << ": ";
        solve(i);
    }
}

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

#define mp make_pair
#define fst first
#define snd second
#define forn(i,n) for (int i = 0; i < int(n); i++)
#define forn1(i,n) for (int i = 1; i <= int(n); i++)
#define popcnt __builtin_popcount

using namespace std;

typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,int> pli;
typedef pair<int,ll> pil;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;

template <typename T> T id(T b) {return b;};
template <class It> bool all(It f,It l){return std::all_of(f,l,id<bool>);}
template <class It> bool any(It f,It l){return std::any_of(f,l,id<bool>);}
template <typename T> void chmax(T &x, T y) {if (x < y) x = y;}
template <typename T> void chmin(T &x, T y) {if (x > y) x = y;}

int a,b,c;

int main()
{
#ifdef FASTIO
  ios_base::sync_with_stdio(false); cin.tie(nullptr);
#endif

  cin >> a >> b >> c;
  if (a == b && b == c)
    cout << "Yes\n";
  else
    cout << "No\n";

  return 0;
}


Measured memory_bytes: 256
n,m=gets.split.map &:to_i
v={1=>r=[1]}
h=Hash.new{|h,k|h[k]=[]}
m.times{a,b=gets.split.map &:to_i;h[a]<<b;h[b]<<a}
f=->x{1while h[x].any?{|e|!v[e]&&v[e]=r<<x=e}}
f[1]
r.reverse!
f[1]
p r.size
puts r*' '

Measured memory_bytes: 23548
N = int(input())
abc = [list(map(int, input().split())) for _ in range(N)]

dp = [[0] * 3 for _ in range(N)]
dp[0][0] = abc[0][0]
dp[0][1] = abc[0][1]
dp[0][2] = abc[0][2]

for i in range(1, N):
    for j in range(3):
        for k in range(3):
            if j == k:
                continue
            dpp = dp[i - 1][j] + abc[i][k]
            dp[i][k] = max(dp[i][k], dpp)

print(max(dp[-1]))

Measured memory_bytes: 47388