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

#define INF 1e9+1

int main(){
  int N, k; cin >> N >> k;
  vector<int> dp(N+1, INF);
  vector<int> cost(N+1, 0);
  for(int i=1; i<N+1; ++i){
    int a; cin >> a;
    cost[i]=a;
  }
  dp[0] = 0;
  dp[1] = 0;
  for(int i=1; i<N+1; ++i){
    for(int j=0; j<min(i,k+1); ++j){
      dp[i] = min(dp[i], dp[i-j]+abs(cost[i]-cost[i-j]));
    }
  }
  cout << dp[N] << endl;
  return 0;
}

Measured memory_bytes: 1024
// In the name of God

#include <bits/stdc++.h>

using namespace std;

const int N = (int)1e5+5;

int a[N], dp[N];

int main() {
	ios_base::sync_with_stdio(0), cin.tie(0);
	int n;
	cin >> n;
	for(int i=0;i<n;i++) cin >> a[i];
	for(int i=n-2;i>=0;i--) {
		if(a[i] >= a[i+1]) dp[i] = dp[i+1]+1;
	}
	int mx = 0;
	for(int i=0;i<n;i++) mx=max(mx, dp[i]);
	cout << mx;
	return 0;
}


Measured memory_bytes: 1024
N = int(input())
V = list(map(int, input().split()))
C = list(map(int, input().split()))

sa = [0] * N

for i in range(N) :
  sa[i] = V[i] - C[i]
sa.sort()
sa.reverse()

ans = 0
for i in sa :
  if i < 0 :
    break
  ans += i
print(ans)
  

Measured memory_bytes: 3060
def slove():
    import sys
    input = sys.stdin.readline
    a, b = list(map(int, input().rstrip('\n').split()))
    s = str(input().rstrip('\n'))
    ls = list("1234567890")
    for i in range(len(s)):
        if i < a:
            if s[i] not in ls:
                print("No")
                exit()
        elif i == a:
            if s[i] != "-":
                print("No")
                exit()
        elif b <= i:
            if s[i] not in ls:
                print("No")
                exit()
    print("Yes")


if __name__ == '__main__':
    slove()


Measured memory_bytes: 38384
/*input
async layered coding
*/
#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops,no-stack-protector")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<double,double> pdd;
#define IOS ios_base::sync_with_stdio(0); cin.tie(0)
#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define F first
#define S second
#define REP(i,n) for(int i=0;i<((int)n);i++)
#define pb push_back
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#ifdef leowang
#define debug(...) do{\
	fprintf(stderr,"%s - %d : (%s) = ",__PRETTY_FUNCTION__,__LINE__,#__VA_ARGS__);\
	_DO(__VA_ARGS__);\
}while(0)
template<typename I> void _DO(I&&x){cerr<<x<<endl;}
template<typename I,typename...T> void _DO(I&&x,T&&...tail){cerr<<x<<", ";_DO(tail...);}
#else
#define debug(...)
#endif
template<typename T1,typename T2>
ostream& operator<<(ostream& out,pair<T1,T2> P){
	out<<'('<<P.F<<','<<P.S<<')';
	return out;
}
//}}}
const ll maxn=300005;
const ll maxlg=__lg(maxn)+2;
const ll INF64=8000000000000000000LL;
const int INF=0x3f3f3f3f;
const ll MOD=ll(1e9+7);
const double PI=acos(-1);
//const ll p=880301;
//const ll P=31;

ll mypow(ll a,ll b){
	ll res=1LL;
	while(b){
		if(b&1) res=res*a%MOD;
		a=a*a%MOD;
		
		b>>=1;
	}
	return res;
}
string s[]={"Even","Odd"};
int main()
{
	IOS;
	int x,a,b;
	cin>>x>>a>>b;
	cout<<(x-a)%b;
	return 0;
}


Measured memory_bytes: 256
X, N = map(int, input().split())
if not N == 0:
  p_l = list(map(int, input().split()))
if N == 0:
  print(X)
  exit()
a = b = X
if not a in p_l:
  if not b in p_l:
    if a > b:
      print(b)
      exit()
    else:
      print(a)
      exit()
  print(a)
  exit()
elif not b in p_l:
  if not a in p_l:
    if a > b:
      print(b)
      exit()
    else:
      print(a)
      exit()
  print(b)
while True:
  a += 1
  if b > 0:
    b -= 1
  if a in p_l and b in p_l:
    continue
  if not a in p_l:
    if not b in p_l:
      if a > b:
        print(b)
#        print("A")
        exit()
      else:
#        print("B")
        print(a)
        exit()
#    print("C")
    print(a)
    exit()
  elif not b in p_l:
    if not a in p_l:
      if a > b:
        print(b)
#        print("D")
        exit()
      else:
        print(a)
#        print("E")
        exit()
#    print("F")
    print(b)
    exit()

Measured memory_bytes: 9264
n = int(input())
lst = []
lst10 = []
for i in range(n):
    x = int(input())
    if x%10==0:
        lst10.append(x)
    else:
        lst.append(x)
    
if len(lst)==0:
    print(0)

else:
    s = sum(lst10)
    t = sum(lst)
    
    lst = sorted(lst)
    i = 0
    while t % 10 == 0:
        t -= lst[i]
    
    print(s+t)

Measured memory_bytes: 3064
"""
author : halo2halo
date : 8, Jan, 2020
"""

import sys

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

S = read().rstrip()
T = S[::-1]
L = (len(S) + 1) // 2

ans = sum(x != y for x, y in zip(S[:L], T[:L]))
print(ans)


Measured memory_bytes: 3060
from collections import deque

N = int(input())
mod = 26
count = 1

for i in range(11):
    if N > mod ** (i+1):
        N -= mod ** (i+1)
        count += 1
    else:
        break

tmp = N-1
num = deque([0 for i in range(count)])

for i in reversed(range(len(num))):
    num[i] = chr(ord('a') + tmp % mod)
    tmp = tmp // mod

print(''.join(num))

Measured memory_bytes: 9468
#include <cstdio>
#include <bits/stdc++.h>
#include <algorithm>
#include <iostream>
#include <string>
#include <cmath>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#define rep(i,n) for (int i=0;i<n;i++)
using ll = long long;
using namespace std;


void solve(){

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

    int n,a,b;
    cin >> n >> a >> b;
    if(n*a<b){
        cout << n*a << endl;
    }

    else{
        cout << b << endl;
    }

    return 0;
}

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

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  string S, T;
  cin >> S >> T;
  ll q;
  cin >> q;
  vector<char> element_S(S.size() + 1, ' ');
  vector<char> element_T(T.size() + 1, ' ');
  for (ll i = 0; i < S.size(); ++i) {
    if (element_S.at(i) == ' ') {
      element_S.at(i + 1) = S.at(i);
    }
    else if (element_S.at(i) == 'A') {
      if (S.at(i) == 'B') {
        element_S.at(i + 1) = ' ';
      }
      else {
        element_S.at(i + 1) = 'B';
      }
    }
    else {
      if (S.at(i) == 'A') {
        element_S.at(i + 1) = ' ';
      }
      else {
        element_S.at(i + 1) = 'A';
      }
    }
  }
  for (ll i = 0; i < T.size(); ++i) {
    if (element_T.at(i) == ' ') {
      element_T.at(i + 1) = T.at(i);
    }
    else if (element_T.at(i) == 'A') {
      if (T.at(i) == 'B') {
        element_T.at(i + 1) = ' ';
      }
      else {
        element_T.at(i + 1) = 'B';
      }
    }
    else {
      if (T.at(i) == 'A') {
        element_T.at(i + 1) = ' ';
      }
      else {
        element_T.at(i + 1) = 'A';
      }
    }
  }
  // for (ll i = 0; i <= S.size(); ++i) {
  //   cout << element_S.at(i) << " ";
  // }
  // cout << "\n";
  // for (ll i = 0; i < element_T.size(); ++i) {
  //   cout << element_T.at(i) << " ";
  // }
  // cout << "\n";
  for (ll i = 0; i < q; ++i) {
    ll a, b, c, d;
    cin >> a >> b >> c >> d;
    a -= 1;c -= 1;
    char s, t;
    char sa = element_S.at(a), sb = element_S.at(b), tc = element_T.at(c), td = element_T.at(d);
    if (sa == sb) {
      s = ' ';
    }
    else if (sa == ' ') {
      s = sb;
    }
    else if (sb == ' ') {
      if (sa == 'A') {
        s = 'B';
      }
      else {
        s = 'A';
      }
    }
    else {
      s = sa;
    }

    if (tc == td) {
      t = ' ';
    }
    else if (tc == ' ') {
      t = td;
    }
    else if (td == ' ') {
      if (tc == 'A') {
        t = 'B';
      }
      else {
        t = 'A';
      }
    }
    else {
      t = tc;
    }

    if (s == t) {
      cout << "YES" << "\n";
    }
    else {
      cout << "NO" << "\n";
    }
  }
}


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

#define rep(i, n) for (int i = 0; i < (n); ++i)

using namespace std;

using ll = long long;
using P = pair<int, int>;

int main() {
  int n, m;
  cin >> n;
  vector<int> t(n);
  rep(i, n) cin >> t[i];
  cin >> m;
  vector<P> px(m);
  rep(i, m) {
    int p, x;
    cin >> p >> x;
    px[i] = make_pair(p - 1, x);
  }

  rep(i, m) {
    int result = 0;
    P tmp = px[i];
    rep(j, n) {
      if (j == tmp.first) {
        result += tmp.second;
      } else {
        result += t[j];
      }
    }
    cout << result << endl;
  }


  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<numeric>
#include<string>
#include<cmath>
#include<set>
#include<queue>
#include<deque>
#include<bitset>
#include<iomanip>
#include<cctype>
#include<map>
#include<cstring>
#include<bitset>
#include<cassert>

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

using namespace std;
using ll = long long int;

const int inf = 1001001000;
const long long int Inf = 1001001001001001000;



void print(vector<vector<int>> a){
	for (int i = 0; i < a.size(); i++)
	{
		for (int j=0;j<a[i].size();j++){
			cout << a[i][j] << " ";
		}
		cout << endl;
	}
}

void print(vector<vector<long long int>> a){
	for (int i=0;i<a.size();i++){
		for (int j=0;j<a[i].size();j++){
			cout << a[i][j] << " ";
		}
		cout << endl;
	}
}

void print(vector<int> a){
    int n = a.size();
    for (int j=0;j<n;j++) {
        if (j != n-1) cout << a[j] << " ";
        else cout << a[j] << endl;
    }
}

void print(vector<long long int> a){
    int n = a.size();
    for (int j=0;j<n;j++) {
        if (j != n-1) cout << a[j] << " ";
        else cout << a[j] << endl;
    }
}

void print(set<int> a){
	for (auto x:a)
		cout << x << " ";
	cout << endl;
}


int main(){
	int n;
	cin >> n;
	vector<ll> a(n);
	rep(i, n) cin >> a[i];
	ll s = 0;
	rep(i, n) s += a[i];
	vector<ll> ans(n,0);
	ans[0] = s;
	for (int i = 1; i < n; i += 2)
	{
		ans[0] -= 2*a[i];
	}
	rep2(i,1,n){
		ans[i] = 2 * a[i-1] - ans[i - 1];
	}
	print(ans);

	return 0;
}

Measured memory_bytes: 3712
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, from, to) for (int i = from; i < (to); ++i)
#define mp(x,y) make_pair(x,y)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
using ll = long long;
using vin=vector<int>;
using vll=vector<ll>;
using P = pair<int, int>;
const int inf=1e9+7;
const ll INF=1e18;
template <typename T> void chmin(T &a, T b) { a = min(a, b); }
template <typename T> void chmax(T &a, T b) { a = max(a, b); }

int main() {
  string s;
  int k;
  cin>>s>>k;
  ////
  int n=s.size();
  int cnt=0;
  while(k>0){
    if(cnt!=n-1){
      if(s[cnt]==97){
        cnt++;
        continue;
      }
        if(122-s[cnt]+1<=k){
          k-=122-s[cnt]+1;
          s[cnt]=97;
          cnt++;
        }
        else{
          cnt++;
        }
    }
    else{///cnt=n-1 
      k=k%26;
      if(s[cnt]+k>122){
        s[cnt]=s[cnt]-26+k; 
      }
      else{s[cnt]+=k;}
      k=0;
      
    }
  }
  cout<<s<<endl;
}

Measured memory_bytes: 3760
import java.util.*;
class Main {
    public static void main(String[] args) {
        Scanner sc =new Scanner(System.in);
        int count = 0;
        long n = sc.nextLong();
        long d = sc.nextLong();
        for(long i =0;i<n;i++){
            long x = sc.nextLong();
            long y = sc.nextLong();
            if(Math.sqrt((x*x)+(y*y))<=d){
                count++;
            }
            else    
                continue;
        }
        System.out.println(count);
    }
    
}

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

bool binarysearch(int a,int s[],int l,int r){
    int mid;
    while(l<=r){
        mid = (r+l)/2;
        if(s[mid]==a){return 1;}

        if(s[mid]<a){
            l = mid + 1;
        }else{
            r = mid - 1;
        }
    }
    return 0;
}

int main(){
    int n,q,c(0);
    cin >> n;
    int s[n];
    for(int i=0;i<n;i++){
        cin >> s[i];
    }
    cin >> q;
    int t[q];
    for(int i=0;i<q;i++){
        cin >> t[i];
        for(int j=0;j<n;j++){
            if(s[j]==t[i]){
                c++;
                break;
            }
        }
    }

    cout << c << endl;
    return 0;
}


Measured memory_bytes: 3104
//#include <bits/stdc++.h>
//#include <stdio.h>
#include<iostream>
#include<cstdio>
#include<bitset>
#include<algorithm>
#include<vector>
#include<list>
#include<queue>
#include<stack>
#include <bits/stdc++.h>
#include<string>
#include<string.h>
#include<cmath>
#include<utility>
#include<functional>
#include<map>
#include<set>
#include<cctype>
#include<fstream>
#include <numeric>
#include <iomanip>
#include <cstring> 
using namespace std;
using ll=long long;

#define FOR(i, a, b) for( int i=(a);i<=(b);i++)
#define RFOR(i, a, b) for( int i=(a);i>=(b);i--)
#define LFOR(i, a, b) for( long long int i=(a);i<=(b);i++)
#define LRFOR(i, a, b) for(long long int i=(a);i>=(b);i--)
#define MOD 1000000007


#include <iostream>
#include <cmath>
using namespace std;
 

 
bool isPrimeNum( ll x ){ // 素数である場合 true を返す
  if( x <= 1 ){ // 1以下である場合は素数でないことがすぐにわかる
    return false;
  }
  // sqrt( double型 ) は引数の平方根を double型で返すので、int型でキャスト
  int n = (int)sqrt( (double)x );
  for( int i = 2; i <= n; i++ ){
    if( x % i == 0 ){ // 割り切る整数がある場合、即判定終了
      return false;
    }
  }
  return true; // 割り切る整数がない場合、素数である
}

constexpr ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
constexpr ll lcm(int a,int b){return a*b/gcd(a,b);}
constexpr ll abs(ll a,ll b){
if(a>=b)return a-b;
if(a<b)return b-a;
}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
 

 
int main() {
    ll N;
    cin >> N;
    int ans=999;
    FOR(i,1,1000000){
      if(N%i==0){
        ll tmp;
        if(i >= N/i){
          tmp=i;
        }else{
          tmp=N/i;
        }

        int count=0;
        while(tmp>0){
          count++;
          tmp=tmp/10;
        }
        if(count<ans){ans=count;}

      }
    }

    cout<<ans<<endl;

  return 0;
}





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

for x,y,h in lst:
    if h != 0:
        break

for cx in range(101):
    for cy in range(101):
        H = abs(cx-x) + abs(cy-y) + h
        if all(hi == max(H-abs(cx-xi)-abs(cy-yi),0) for xi,yi,hi in lst):
            print(cx,cy,H)
            exit()


Measured memory_bytes: 48348
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; (i) < (n); ++ (i))
#define loop(i,a,n) for (int i = (a); (i) < (n); ++ (i))
#define ll long long
#define ld long double
#define EPS 0.0000000001
#define INF (int)1e9
#define MOD 0
//#define int ll
using namespace std;
typedef vector<long long> vl;

signed main() {
  int n,m = 0;
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> n;
  vector<int> a(n),b(n,0);
  rep(i,n) {
    cin >> a[i];
  } 
  for(int i = n;i > 0;i--) {
    int sum = 0;
    for(int j = 2;j*i <= n;j++) {
      if(b[i*j-1] == 1) sum++;
    }
    if(a[i-1] != sum%2) {
      b[i-1]++;
      m++;
    }
  }
  cout << m << endl;
  rep(i,n) {
    if(i != 0) cout << ' ';
    if(b[i] == 1) cout << i+1;
  }
  cout << endl;
}

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

using namespace std;

typedef long long LL;

const int nmax = 100007; const LL inf = 2e18; const int mod = 1000000007;

char s[nmax];
int N;
string a;
bool gg;

inline bool Ok(int x,int y){
   int i,j;
   j = y-x+1;
   if(j == 6){
      a = "eraser";
      int q = 0;
      for(i = x; i <= y; ++i,++q)
         if(s[i] != a[q])return 0;
      return 1;
   }
   if(j == 5){
      a = "erase";
      int q = 0;
       gg = 0;
      for(i = x; i <= y&&!gg; ++i,++q)
         if(s[i] != a[q])gg=1;

     if(!gg)
      return 1;

      a = "dream";
      for(i = x,gg=q=0; i <= y&&!gg; ++i,++q)
         if(s[i] != a[q])gg=1;
     if(!gg)
      return 1;
      return 0;
   }
   int q;
   a = "dreamer";
   for(i = x,gg=q=0; i <= y&&!gg; ++i,++q)
         if(s[i] != a[q])gg=1;
     if(!gg)
      return 1;
   return 0;
}

int main(){
//   #ifndef GLOBAL_JUDGE
//      freopen("txt.in","r",stdin);
//      freopen("txt.out","w",stdout);
//   #endif // GLOBAL_JUDGE
   int i,j;
   cin >> (s+1);
   N = strlen(s+1);
   for(i = N;i;){
      if(i-4>=0 && Ok(i-4,i))i-=5;
      else if(i-5>=0 && Ok(i-5,i))i-=6;
      else if(i-6>=0 && Ok(i-6,i))i-=7;
      else{
         cout << "NO\n";
         return 0;
      }

   }
   cout << "YES\n";
   return 0;
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
 
int main(){
  long a,b,v,w,t;
  string ans = "YES";
  
  cin >> a >> v >> b >> w >> t;
  
  long dab = abs(b - a);
  long dvw = v - w;
  
  if(dab > dvw * t)
    	ans = "NO";
  cout << ans << endl;
}

Measured memory_bytes: 3588
#include<bits/stdc++.h>
using namespace std;
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);

int main(){
	IOS;
	int n;
	cin >> n;
	int a[n][3];

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

	int dp[n][3];
	dp[0][0] = a[0][0];
	dp[0][1] = a[0][1];
	dp[0][2] = a[0][2];

	for(int i=1; i < n; ++i){
		dp[i][0] = a[i][0] + max(dp[i-1][1],dp[i-1][2]);
		dp[i][1] = a[i][1] + max(dp[i-1][0],dp[i-1][2]);
		dp[i][2] = a[i][2] + max(dp[i-1][0],dp[i-1][1]);
	}
	cout << max(dp[n-1][0],max(dp[n-1][1],dp[n-1][2])) << endl;
}

Measured memory_bytes: 2560
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();
    int c = sc.nextInt();
    sc.close();
    int ans = (c-(a-b))>0 ? c-(a-b) : 0;
    System.out.println(ans);
  }
}

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


int main(){
    vector<int> a = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
    int k;
    cin >> k;

    cout << a.at(k-1) << endl;

}

Measured memory_bytes: 256
#include <stdio.h>
#include <cmath>

int main(){

    char s[8003] = {};
    int x,y;
    int gx[8000] ,gy[8000];
    bool dx[8000][8000] ,dy[8000][8000]; //DP!!!!!
    scanf("%s\n", &s);
    scanf("%d %d", &x, &y);

    int i = 0;
    while( s[i] == 'F'){
        i++;
    }
    x = x-i;
    i++;

    x = std::abs(x);
    y = std::abs(y);

    int j = 0;
    int ix = 0;
    int iy = 0;
    bool yoko = false;
    while( s[i] != 0){
        if( s[i] == 'T'){
            if(yoko) gx[ix++] = j;
            else gy[iy++] = j;
            yoko = !yoko;
            i++;
            j = 0;
        }else{
            i++;
            j++;
        }
    }
    if(yoko) gx[ix++] = j;
    else gy[iy++] = j;
    yoko = !yoko;

    dx[0][0] = true;
    dy[0][0] = true;
    for (int k = 1; k <= iy; k++){
        for (int l = 0; l < 8000; l++){
            if(dx[k-1][l]){
                if(l+gx[k-1] < 8001)   dx[k][l+gx[k-1]] = true;
                if(l-gx[k-1] > -1)     dx[k][l-gx[k-1]] = true;
            }
            if(dy[k-1][l]){
                if(l+gy[k-1] < 8001)   dy[k][l+gy[k-1]] = true;
                if(l-gy[k-1] > -1)     dy[k][l-gy[k-1]] = true;
            }
        }
    }

    if( dx[iy][x] && dy[iy][y] ) printf ("Yes\n");
    else    printf ("No\n");


    return 0;
}



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

int main(){
  ll n,d;
  cin >> n >> d;
  d *=d;
  int cnt = 0;
  rep(i,n){
    ll x,y;
    cin >> x >>y;
    if(d<x*x+y*y);
    else cnt++;
  }
  cout << cnt << endl;
  return 0;
}


Measured memory_bytes: 3632
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ALL(x) (x).begin(),(x).end()

#include <bits/stdc++.h>
using namespace std;

int bubbleSort(vector<int>& A,int N){
  int c=0;
  bool flag=1;
  while(flag){
    flag=0;
    for(int j=N-1;j>0;j--){
      if(A[j]<A[j-1]){
        int v=A[j];
        A[j]=A[j-1];
        A[j-1]=v;
        c++;
        flag=1;
      }
    }
  }
  return c;
}

int main() {
  int n;
  cin >> n;
  
  vector<int> vec(n);
  rep(i,n) cin >> vec[i];
  
  int ans=bubbleSort(vec,n);
  
  for(int i=0;i<n;i++){
    if(i>0) cout <<" ";
    cout<<vec[i];
  }
  cout<<endl;
  cout<<ans<<endl;
      
  return 0;
}


Measured memory_bytes: 3112
//$g++ -std=c++11 Template.cpp 

//#include <bits/stdc++.h>
#include <iostream>
#include <complex>
#include <sstream>
#include <string>
#include <algorithm>
#include <deque>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <vector>
#include <set>
#include <limits>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <ctime>
#include <climits>
#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define FOR(i, j, k) for(int i = (int)(j); i < (int)(k); ++i)
#define ROF(i, j, k) for(int i = (int)(j); i >= (int)(k); --i)
#define FORLL(i, n, m) for(long long i = n; i < (long long)(m); i++)
#define SORT(v, n) sort(v, v+n)
#define REVERSE(v) reverse((v).begin(), (v).end())

using namespace std;
using ll = long long;
const ll MOD=1000000007LL;
typedef pair<int, int> P;

ll ADD(ll x, ll y) { return (x+y) % MOD; }
ll SUB(ll x, ll y) { return (x-y+MOD) % MOD; }
ll MUL(ll x, ll y) { return x*y % MOD; }
ll POW(ll x, ll e) { ll v=1; for(; e; x=MUL(x,x), e>>=1) if (e&1) v = MUL(v,x); return v; }
ll DIV(ll x, ll y) { /*assert(y%MOD!=0);*/ return MUL(x, POW(y, MOD-2)); }

priority_queue<int> q_descending;
priority_queue<int, vector<int>, greater<int> > q_ascending;

int sosu_c[25];

int
main(void){  
  ios_base::sync_with_stdio(false);

  int n;
  cin >> n;

  ll ans = 0LL;
  
  int sosu[25] = {2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97};

  ll val = 1;

  REP(i, 25) sosu_c[i] = 0;  
  FOR(i, 2, n+1){
    val = val * i;        
    //check yakusu
    REP(i, 25){
      //wareru dake
      while(val % sosu[i] == 0){
	sosu_c[i]++;
	val /= sosu[i];
      }
    }        
  }

  REP(p, 25){
    if(sosu_c[p] >= 74) ++ans;
  }

  REP(p, 25) REP(q, 25){
    if(p == q) continue;    
    if(sosu_c[p] >= 24 && sosu_c[q] >= 2) ++ans;
    if(sosu_c[p] >= 14 && sosu_c[q] >= 4) ++ans;
  }

  //r, qの重複カウントを防ぐ
  REP(p, 25) FOR(q, p+1, 25) REP(r, 25) {
    if(p == r || q == r) continue;
    if(sosu_c[p] >= 4 && sosu_c[q] >= 4 && sosu_c[r] >= 2) ++ans;
  }
  
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
//
// Modular Arithmetics
//
// cf.
//   drken: 「1000000007 で割ったあまり」の求め方を総特集！ 〜 逆元から離散対数まで 〜
//     https://qiita.com/drken/items/3b4fdf0a78e7a138cd9a
//
// verified:
//   AGC 025 B - RGB Coloring
//     https://beta.atcoder.jp/contests/agc025/tasks/agc025_b
//


#include <iostream>
using namespace std;


const int MAX = 510000;
const int MOD = 998244353;

long long fac[MAX], finv[MAX], inv[MAX];
void COMinit(){
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}


int main() {
    COMinit(); // テーブルを作る
    long long N, A, B, K;
    cin >> N >> A >> B >> K;
    long long res = 0;
    for (long long a = 0; a <= N; ++a) { // A の個数を全探索
        long long rem = K - a * A;
        if (rem % B != 0) continue;
        long long b = rem / B;
        if (b > N) continue;
        long long tmp = COM(N, a) * COM(N, b) % MOD;
        res += tmp;
        res %= MOD;
    }
    
    cout << res << endl;
}

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

#define rep2(x,fr,to) for(int x=(fr);x<(to);x++)
#define rep(x,to) for(int x=0;x<(to);x++)
#define repr(x,fr,to) for(int x=(fr);x>=(to);x--)
#define all(c) c.begin(),c.end()
#define sz(v) (int)v.size()

using namespace std;
typedef long long ll; typedef vector<int> VI; typedef pair<int,int> pii;
typedef vector<ll> VL; const int MD = (int)1e9 + 7;
void dbg(){ cerr << "\n"; } template <typename T,typename ...T2> void dbg(const T& fst, const T2&...rst){ cerr << fst << ": "; dbg(rst...); }
template <class T, class T2> void amax(T& a,T2 b){ if(a < b) a = b;}

int main()
{
	//cin.tie(0); ios_base::sync_with_stdio(false);
	int n, ans =0;
	string s;
	cin >>s;
	if(s[1]=='B') puts("ARC");
	else puts("ABC");
	return 0;
}


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

int main(){
  int a,b,c,d;
  cin >> a;
  b = a / 100;
  c = a / 10 - b * 10;
  d = a - 100 * b - 10 * c;
  cout << b + c + d << endl;
}  

Measured memory_bytes: 256
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

public class Main {
	public static void main(String[] args){
		Map<String,Integer> sales = new HashMap<>();
		Scanner sc = new Scanner(System.in);

		int a = sc.nextInt();

		for(int i = 0; i < a;i++){
			int x= sc.nextInt();
			String key = sc.next();
			if(x ==0){
				sales.put(key,sc.nextInt());
			}else if(x == 1){
				if(sales.containsKey(key)){
				System.out.println(sales.get(key));
				}else{
					System.out.println(0);
				}
			}else{
				sales.remove(key);
			}
		}
	}
}


Measured memory_bytes: 193504
#include "bits/stdc++.h"

#define REP(i, n, N) for(ll i=(n); i<(N); i++)
#define RREP(i, n, N) for(ll i=(N-1); i>=(n); i--)
#define LREP(lst,itr) for(auto itr = lst.begin(); itr != lst.end(); ++itr)
#define CK(n, a, b) ((a)<=(n)&&(n)<(b))
#define ALL(v) (v).begin(),(v).end()
#define MCP(a, b) memcpy(b,a,sizeof(b))
#define P(s) cout<<(s)<<endl
#define P2(a, b) cout<<(a)<<" "<<(b)<<endl
#define V2(T) vector<vector<T>>
typedef long long ll;
using namespace std;
const ll MOD = 1e9 + 7;
const ll INF = 1e18;

int main(){
    ll N,M;
    priority_queue<ll> que;
    cin >> N >> M;
    REP(i,0,N){
        ll cur;
        cin >> cur;
        que.push(cur);
    }
    ll now;
    REP(i,0,M){
        now=que.top();
        que.pop();
        que.push(now/2);
    }
    ll ans=0;
    while(!que.empty()){
        ans+=que.top();
        que.pop();
    }
    P(ans);
}

Measured memory_bytes: 1400
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner scanner = new Scanner(System.in);

		int corner = scanner.nextInt();
		int totalLength = 0;
		int maxSideLength = 0;

		for(int i = 0; i < corner; ++i) {
			int temp = scanner.nextInt();
			maxSideLength = Math.max(maxSideLength, temp);
			totalLength += temp;
		}
		totalLength -= maxSideLength;

		String result = (maxSideLength < totalLength) ? "Yes" : "No";

		System.out.println(result);

		scanner.close();

	}

}

Measured memory_bytes: 23252
#include <iostream>
#include <vector>
#include <algorithm>
#include <cstring>
typedef long long ll;
using namespace std;

int main(){
  ll i,j,k,n,c,w,h;
  cin >> n >> c;
  ll d[c][c],col[n][n];
  for(i=0;i<c;i++){
    for(j=0;j<c;j++)cin >> d[i][j];
  }
  for(i=0;i<n;i++){
    for(j=0;j<n;j++)cin >> col[i][j];
  }

  ll a[3]={};
  ll ret = 1e9;
  ll pick[3][c];
  memset(pick,0,sizeof(pick));

  for(i=0;i<c;i++){
    for(h=0;h<n;h++){
      for(w=0;w<n;w++){
        pick[(h+w+2)%3][i]+=d[col[h][w]-1][i];
      }
    }
  }
  for(i=0;i<c;i++){
    for(j=0;j<c;j++){
      if(i==j)continue;
      for(k=0;k<c;k++){
        if(i==k || j==k)continue;
        ll sum = pick[0][i]+pick[1][j]+pick[2][k];
        ret = min(ret,sum);
      }
    }
  }
  cout << ret << endl;
  return 0;
}


Measured memory_bytes: 2176
from itertools import product
D, G = map(int, input().split())
P, C = map(list, zip(*[tuple(map(int, input().split())) for _ in range(D)]))
CP = [100*i*p+c for i, (p, c) in enumerate(zip(P, C), 1)]
ans = 10**9
for prod in product((True, False), repeat=D):
    I = [i for i, p in enumerate(prod) if p]
    A = sum(CP[i] for i in I)
    r = sum(P[i] for i in I)
    if A >= G:
        ans = min(ans, r)
    else:
        j = max(i for i, p in enumerate(prod) if not p)
        if G > A + 100*(j+1)*(P[j]-1):
            continue
        ans = min(ans, r + (G-A-1)//((j+1)*100)+1)
print(ans)

Measured memory_bytes: 3064
#include <algorithm>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <queue>
#define MOD (1000000007l)
#define rep(i, n) for(long i = 0; i < n; i++)

using namespace std;

void solve() {
  long a, b;
  cin >> a >> b;

  long aa = a;
  long bb = b;

  while (bb) {
    aa *= 10;
    bb /= 10;
  }

  long num = aa + b;

  for (long i = 1; i <= num; i++) {
    if (i * i == num) {
      cout << "Yes" << endl;
      return;
    }
  }

  cout << "No" << endl;
}

int main(void) {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout.precision(12);
  solve();
  return 0;
}


Measured memory_bytes: 256
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%b==0 || b%a==0)
			System.out.println(a+b);
		else
			System.out.println(Math.abs(a-b));
	}
}

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

#define reps(v, f, l) for (int v = (f), v##_ = (l); v < v##_; ++v)
#define rep(v, n) reps(v, 0, n)
#define lep(v, n) reps(v, 1, n + 1)
#define rreps(v, f, l) for (int v = (l), v##_ = (f); v >= v##_; --v)
#define rrep(v, n) rreps(v, 0, n - 1)
#define rlep(v, n) rreps(v, 1, n)
#define show_a(a, size) rep(a##_it, size) std::cout << a[a##_it] << " \n"[a##_it == a##_it_ - 1];
#define show_v(v) show_a(v, v.size())
#define debug(x) std::cerr << #x << " = " << (x) << "\n";

using namespace std;

typedef long long int lint;

static inline int in(){ int x; scanf("%d", &x); return x; }
static inline lint inl(){ lint x; scanf("%lld", &x); return x; }

int main()
{
  lep(i, 9){
    lep(j, 9){
      printf("%dx%d=%d\n", i, j, i * j);
    }
  }
  return 0;
}

Measured memory_bytes: 1096
#include <iostream>
#include <vector>
#include <limits.h>
#include <algorithm>
#include <string>
#include <math.h>
#include <limits.h>
#include <queue>
#include <map>
#include <set>
#include <iomanip>
#include <bitset>
#include <cassert>
#include <random>
#include <functional>
#include <stack>
#include <iomanip>
using namespace std;

long long N, M;

bool judge(long long g) {
	return (N * g <= M);
}

int main() {
	cin >> N >> M;
	long long ans = 0;
	for (long long n = 1; n * n <= M; n++) {
		if (M % n != 0)continue;
		if (judge(n))ans = max(ans, n);
		if (judge(M / n))ans = max(ans, M / n);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include<iomanip>
#include<limits>
#include<thread>
#include<utility>
#include<iostream>
#include<string>
#include<algorithm>
#include<set>
#include<map>
#include<vector>
#include<stack>
#include<queue>
#include<cmath>
#include<numeric>
#include<cassert>
#include<random>
#include<chrono>
#include<unordered_set>
#include<unordered_map>
#include<fstream>
#include<list>
#include<functional>
#include<bitset>
#include<complex>
#include<tuple>
using namespace std;
typedef unsigned long long int ull;
typedef long long int ll;
typedef pair<ll,ll> pll;
typedef pair<int,int> pi;
typedef pair<double,double> pd;
typedef pair<double,ll> pdl;
#define F first
#define S second
const ll E=1e18+7;
const ll MOD=1000000007;

ll mod_pow(ll a,ll x){
    ll ret=1;
    while(x>0){
        if(x&1){(ret*=a)%=MOD;}
        (a*=a)%=MOD;
        x>>=1;
    }
    return ret;
}


int main(){
    ll n,x,y,z;
    cin>>n>>x>>y>>z;
    vector<vector<ll>> dp(n+1,vector<ll>(1LL<<(x+y+z),0));
    dp[0][0]=1;
    vector<vector<ll>> edge(1LL<<(x+y+z),vector<ll>(10,0));
    ll X=(1LL<<(x+y+z))-1;
    for(int i=0;i<(1LL<<(x+y+z));i++){
        for(int t=0;t<10;t++){
            ll w=i;
            w<<=t+1;
            w|=1LL<<t;
            w&=X;
            ll cnt=0;
            vector<ll> A={x,y,z};
            ll l=-1;
            for(int j=0;j<(x+y+z);j++){
                if(w>>j&1){A[cnt]-=j-l; l=j; if(A[cnt]==0){cnt++;}}
            }
            if(A[0]==0 && A[1]==0 && A[2]==0){edge[i][t]=0;}
            else{edge[i][t]=1;}
        }
    }
    for(int i=0;i<n;i++){
        for(int t=0;t<(1LL<<(x+y+z));t++){
            for(int j=0;j<10;j++){
                ll w=t;
                w<<=j+1;
                w|=1LL<<j;
                w&=X;
                dp[i+1][w]+=dp[i][t]*edge[t][j];
                dp[i+1][w]%=MOD;
            }
        }
    }
    ll ans=mod_pow(10,n);
    for(auto &I:dp.back()){(ans-=I)%=MOD;}
    if(ans<0){ans+=MOD;}
    cout<<ans<<endl;
    
    return 0;
}


Measured memory_bytes: 57724
import java.util.Scanner;

public class Main {

    static Scanner sc = new Scanner(System.in);


    public static void main(String[] args) {
        String a = sc.next();
        String b = sc.next();
        int sum = 0;
        for (int i = 0; i < a.length(); i++) {
            if (a.charAt(i) != b.charAt(i)) {
                sum++;
            }
        }
        System.out.println(sum);
    }
}

Measured memory_bytes: 41288
use proconio::input;

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

    let mut all_xor = 0;

    for na in &a {
        all_xor ^= na;
    }

    for na in &a {
        print!("{} ", all_xor ^ na);
    }
    println!();
}


Measured memory_bytes: 6288
import heapq

N,M = map(int,input().split())
A = list(map(int,input().split()))
A = [-a for a in A]

heapq.heapify(A)

for _ in range(M):
    b = -heapq.heappop(A)//2
    #print(b)
    heapq.heappush(A,-b)
print(-sum(A))

Measured memory_bytes: 14180
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <stdlib.h>
#include <string.h>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <stdio.h>
#include <tuple>
#include <bitset>
#include <cfloat>
#include <fstream>
#include <limits.h>
#include <list>
#include <math.h>
#include <random>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <numeric>
#include <utility>
#include <sstream>

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;
}

using namespace std;
#define int long long
#define ll long long
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define FORR(i,a,b)for(ll i=(a);i<=(b);i++)
#define repr(i,n) for(ll i=n;i>=0;i--)
#define P pair<ll, ll>
#define sz(x) (ll)x.size()
#define ALL(x) (x).begin(),(x).end()
#define ALLR(x) (x).rbegin(),(x).rend()
#define VE vector<ll>
#define COUT(x) cout<<(x)<<endl
#define MA map<ll,ll>
#define SE set<ll>
#define PQ priority_queue<ll>
#define PQR priority_queue<ll,VE,greater<ll>>
#define COUT(x) cout<<(x)<<endl
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define EPS (1e-10)


const long long MOD = 1000000007;
//const long long MOD = 998244353;
const long long INF = 1LL << 60;


long long modinv(long long a, long long m) {
	long long b = m, u = 1, v = 0;
	while (b) {
		long long t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}
ll gcd(ll a, ll b) {
	if (a < b)swap(a, b);
	if (b == 0) return a;
	unsigned r;
	while ((r = a % b)) {
		a = b;
		b = r;
	}
	return b;
}
ll lcm(ll a, ll b) {
	ll g = gcd(a, b);
	return a * g / b;
}
bool prime(ll n) {
	for (ll i = 2; i <= sqrt(n); i++) {
		if (n%i == 0)return false;
	}
	return n != 1;
}




const long double PI = 3.14159265359;
const int MAX_N = 100010;





signed main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int n; cin >> n;
	VE a(n); rep(i, n)cin >> a[i];
	VE b(n); rep(i, n)b[i] = a[i] - (i + 1);
	sort(ALL(b));
	int tmp = b[n / 2];
	int ans = 0;
	rep(i, n) {
		ans += abs(a[i] - (tmp + i+1));
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3456
#include <bits/stdc++.h>
#define IO_OP std::ios::sync_with_stdio(0); std::cin.tie(0);
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define EB emplace_back

using namespace std;

typedef long long ll;
typedef pair<int, int> pi;
typedef vector<int> vi;

const int INF = 1e9 + 7;

int main()
{
	IO_OP;
	
	int n, k, si, a;
	cin >> n >> k;
	for(int i=0;i<n;i++) {
		cin >> a;
		if(a == 1) {
			si = i;
		}
	}
	int ans = INF;
	for(int i=0;i<k;i++) {
		int j = si - i;
		if(j < 0) continue;
		int cans = (j + k - 2) / (k - 1) + 1 + (max(n - j - k, 0) + k - 2) / (k - 1);
		ans = min(ans, cans);
	}
	cout << ans << endl;
}



Measured memory_bytes: 256
buff = "NNNNWNNNWNNNENNNENNNWNNN"

class Dice:
        num =[ -1 for x in range(6) ]
        def roll(self, d):
                if   d == "N":
                        b = self.num[0]
                        self.num[0] = self.num[1]
                        self.num[1] = self.num[5]
                        self.num[5] = self.num[4]
                        self.num[4] = b
                elif d == "S":
                        b = self.num[0]
                        self.num[0] = self.num[4]
                        self.num[4] = self.num[5]
                        self.num[5] = self.num[1]
                        self.num[1] = b
                elif d == "W":
                        b = self.num[3]
                        self.num[3] = self.num[0]
                        self.num[0] = self.num[2]
                        self.num[2] = self.num[5]
                        self.num[5] = b
                elif d == "E":
                        b = self.num[3]
                        self.num[3] = self.num[5]
                        self.num[5] = self.num[2]
                        self.num[2] = self.num[0]
                        self.num[0] = b
        
        def __init__(self, lst):
                self.num = lst
        
        def print_num(self, m):
                #print(self.num[m])
                return self.num[m]

lst = [ int(i) for i in input().split() ]
q = int(input())

qst = []
for p in range(q):
        qst.append([ int(i) for i in input().split() ])


dice = Dice(lst)

for c in qst:
        for d in buff:
                dice.roll(d)
                if dice.print_num(0) == c[0] and dice.print_num(1) == c[1]:
                        print(dice.print_num(2))





Measured memory_bytes: 5612
#include <stdio.h>
#include <stdlib.h>
#define N 100000

int partition(int *A, int  p, int r){
	int i, j, x, temp;
	x = A[r];
	i = p-1;
	for(j=p; j<r; j++){
		if(A[j]<=x){
			i=i+1;
			//A[i] と A[j] を交換
			temp=A[i];
			A[i]=A[j];
			A[j]=temp;
		}
	}
	//A[i+1] と A[r] を交換
	temp=A[i+1];
	A[i+1]=A[r];
	A[r]=temp;
	
	return i+1;
}

int main(void){
	int i, n, A[N], r;
	scanf("%d", &n);
	for(i=0; i<n; i++) scanf("%d", &A[i]);
	
	r = partition(A, 0, n-1);
	for(i=0; i<r; i++) printf("%d ", A[i]);
	printf("[%d] ", A[r]);
	for(i=r+1; i<n-1; i++) printf("%d ", A[i]);
	printf("%d\n", A[n-1]);
	
	return 0;
}


Measured memory_bytes: 2244
#define _USE_MATH_DEFINES
//#include <bits/stdc++.h>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <complex>
#include <deque>
#include <iomanip>
#include <ios>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <vector>

using namespace std;
#define REP(i,n) for(int i=0;i<(int)(n);i++)

template <typename T>
class Bit{
public:
  Bit(int sz):bit(vector<T>(sz+1)),size(sz){}
  T sum(int i){
    T s=0;
    while(i>0){
      s+=bit[i];
      i-=i&-i;
    }
    return s;
  }
  void add(int i,T x){
    while(i<=size){
      bit[i]+=x;
      i+=i&-i;
    }
  }
private:
  Bit();
  vector<T> bit;
  int size;
};

void solve(int N, std::vector<long long> A, int Q, std::vector<long long> B, std::vector<long long> C){
  Bit<long long> cnt{100010};
  REP(i,N){
    cnt.add((int)A[i],A[i]);
  }
  REP(i,Q){
    long long from=cnt.sum((int)B[i])-cnt.sum((int)B[i]-1);
    cnt.add((int)B[i],-from);
    cnt.add((int)C[i],from*C[i]/B[i]);
    cout<<cnt.sum(100011)<<endl;
  }
}

int main(){
  int N;
  scanf("%d",&N);
  std::vector<long long> A(N);
  for(int i = 0 ; i < N ; i++){
    scanf("%lld",&A[i]);
  }
  int Q;
  scanf("%d",&Q);
  std::vector<long long> B(Q);
  std::vector<long long> C(Q);
  for(int i = 0 ; i < Q ; i++){
    scanf("%lld",&B[i]);
    scanf("%lld",&C[i]);
  }
  solve(N, std::move(A), Q, std::move(B), std::move(C));
  return 0;
}


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

if N == 1:
    print(1)
else:
    divide = 0
    if A[0] < A[1]:
        up = 1
    elif A[0] > A[1]:
        up = -1
    else:
        up = 0
    for i in range(1,N-1):
        if A[i] == A[i+1]:
            continue
        elif A[i] < A[i+1]:
            if up < 0:
                divide += 1
                up = 0
            else:
                up = 1
                continue
        else:
            if up > 0:
                divide += 1
                up = 0
            else:
                up = -1
                continue
    print(divide+1)

Measured memory_bytes: 14428
n = gets.to_i

graph = Array.new(n+1){[]}
visited = [false]*(n+1)
dist = [0]*(n+1)
stack = []
(n-1).times do |i|
  u,v,w = gets.split.map(&:to_i)
  graph[u] << [v,w]
  graph[v] << [u,w]
  stack << u
end

while k = stack.pop
  next if visited[k]
  visited[k] = true
  graph[k].each do |t,w|
    if !visited[t]
      stack << t
      dist[t] = dist[k] + w
    end
  end
end
1.upto(n) do |i|
  if dist[i] % 2 == 0
    p 0
  else
    p 1
  end
end
#p dist



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

using namespace std;


struct Zone{
	int originalOrder;
	int area;
	int year;
	int id;
};

vector<Zone> vecArr(100001);

int cmp0(Zone z1,Zone z2)
{
	if(z1.area < z2.area)
	{
		return true;
	}
	else if((z1.area == z2.area) && (z1.year < z2.year))
	{
		return true;
	}
	else
	{
		return false;
	}
}

int cmp1(Zone z1,Zone z2)
{
	if(z1.originalOrder < z2.originalOrder)
		return true;
	else
		return false;
}

string FillString(string str)
{
	int nLen = str.length();

	if(1 == nLen)
	{
		return "00000" + str;
	}
	else if(2 == nLen)
	{
		return "0000" + str;
	}
	else if(3 == nLen)
	{
		return "000" + str;
	}
	else if(4 == nLen)
	{
		return "00" + str;
	}
	else if(5 == nLen)
	{
		return "0" + str;
	}
	else
	{
		return str;
	}
}

void Print(int n1,int n2)
{
	string str1 = FillString(to_string(n1));
	string str2 = FillString(to_string(n2));
	cout << str1 + str2 << endl;
}

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

	vecArr.clear();

	Zone z;
	for(int i = 0; i < M; ++i)
	{
		cin >> z.area >> z.year;
		z.originalOrder = i + 1;
		vecArr.push_back(z);
	}

	sort(vecArr.begin(),vecArr.end(),cmp0);

	int nArea = -1;
	int nCount = 0;
	for(int i = 0; i < M; ++i)
	{
		nCount++;
		if(-1 == nArea)
		{
			nArea = vecArr[i].area;
			vecArr[i].id = nCount;
		}
		else if(vecArr[i].area == nArea)
		{
			vecArr[i].id = nCount;
		}
		else
		{
			nArea = vecArr[i].area;
			vecArr[i].id = 1;
			nCount = 1;
		}
	}

	sort(vecArr.begin(),vecArr.end(),cmp1);

	for(int i = 0; i < M; ++i)
	{
		Print(vecArr[i].area,vecArr[i].id);
	}

	return 0;
}

Measured memory_bytes: 3072
# coding: utf-8
while 1:
    n=int(input())
    if n==0:
        break
    data=[[] for i in range(n+1)]
    for i in range(n+1):
        m=int(input())
        x,y=map(int,input().split())
        for j in range(m-1):
            _x,_y=map(int,input().split())
            data[i].append((abs(_x+_y-x-y),1 if x<_x else 3 if x>_x else 0 if y<_y else 2))
            x,y=_x,_y
    for i in range(1,n+1):
        d=[(e[0],(e[1]+(data[0][0][1]-data[i][0][1]))%4) for e in data[i]]
        f=[(e[0],(e[1]+(data[0][0][1]-data[i][-1][1]))%4) for e in data[i][::-1]]
        if data[0]==d:
            print(i)
        elif data[0]==f:
            print(i)
    print('+++++')


Measured memory_bytes: 5660
k = int(input())
line = input()

m = []
am = 1
for n in range(k):
    m.append(int(line.split()[n]))
    if(n==0):
        tallest = m[n]
    if(n>0):
        tallest = max(m[n], tallest)
        coef = m[n] - tallest
        if(coef>=0):
            am+=1
print(am)

Measured memory_bytes: 3060
#include<iostream>
#include<cstring>
#include<cmath>
#include<cstdio>
#include<algorithm>
#include<set>
#include<map>

#define fo(i,a,b) for(int i=a;i<=b;i++)
#define fd(i,a,b) for(int i=a;i>=b;i--)

using namespace std;

typedef long long LL;
typedef double db;

const int N = 1010;

int n,a[N][N];
int s[N],k;

int main(){
	//n=get();
	/*a[0][0]=0;
	fo(i,2,200)
		fo(x,0,i){
			int y=i-x;
			if (x<2&&y<2)continue;
			k=0;
			fo(u,1,x/2)s[++k]=a[x-u*2][y+u];
			fo(u,1,y/2)s[++k]=a[x+u][y-u*2];
			sort(s+1,s+1+k);
			int k_=1;
			fo(i,2,k)
			if (s[i]>s[i-1])s[++k_]=s[i];
			k=k_;
			int ans=k;
			fo(i,1,k)
			if (s[i]!=i-1){ans=i-1;break;}
			a[x][y]=ans;
			if (ans==0)printf("%d %d\n",x,y);
		}*/
	LL x,y;
	scanf("%lld%lld",&x,&y);
	if (x-y>=-1&&x-y<=1)printf("Brown\n");
	else printf("Alice\n");
	return 0;
}

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


int main() {
    int a,b,k;
    cin >> a >> b >> k;
    vector<int> ans;
    int num = min(a,b);
    for(int i=1;i<=num;i++){
        if(a%i==0 && b%i==0){
            ans.push_back(i);
        }
    }
  	cout << ans[ans.size()-k] <<endl;
    
    return 0;
}






Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
    int a[32]={1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
    int k;
    cin>>k;
    cout<<a[k-1]<<endl;
    return 0;
}

Measured memory_bytes: 256
/*
   TASK: nocows
   LANG: C++14
 */

#include "bits/stdc++.h"
typedef long long ll;
typedef long double ld;

using namespace std;
#define finish(x) return cout << x, 0;

void setIn(string s) { freopen(s.c_str(),"r",stdin); }
void setOut(string s) { freopen(s.c_str(),"w",stdout); }

const string USCAO_TAG = "nocows";
void usaco() { setIn(USCAO_TAG + ".in"); setOut(USCAO_TAG + ".out"); }
/*
template<typename... Args>
void print(Args... args) {
	((std::cout << args << " "), ...);
}
*/
ll a[100001];
ll dp[100001][101];

int main() {
	//usaco();
	#ifndef ONLINE_JUDGE
	//setIn("in.txt");
	#endif

	int n, k;
	cin >> n >> k;

	memset(dp, 0x3f3f3f3f, sizeof dp);
	for(int i = 1; i <= n; i++)
		cin >> a[i];

	a[0] = a[1];

	ll dp2[100001];
	memset(dp2, 0x3f3f3f3f, sizeof dp2);

	for(int i = k; i >= 1; i--){
		dp[n][i] = abs(a[n] - a[n - i]);
		dp2[n - i] = min(dp2[n - i], dp[n][i]);
	}

	for(int i = n - 1; i >= 1; i--){
		for(int j = 1; i - j >= 0 && j <= k; j++){
			dp[i][j] = min(dp[i][j], dp2[i] + abs(a[i] - a[i - j]));
			dp2[i - j] = min(dp2[i - j], dp[i][j]);
		}
	}

	ll mn = 1e9;
	for(int i = 1; i <= k; i++){
		mn = min(mn, dp[1][i]);
	}
	cout << mn;
}

Measured memory_bytes: 80768
#include<cstdio>
#include<algorithm>
using namespace std;
#define MAXN 2000
#define MAXM 4000000
#define MO 1000000007
int dp[MAXN+5][MAXN+5],n,k;
int fac[MAXM+5],inv[MAXM+5];
int PowMod(int a,int b)
{
	int ret=1;
	while(b)
	{
		if(b&1) ret=1LL*ret*a%MO;
		a=1LL*a*a%MO;
		b>>=1;
	}
	return ret;
}
int C(int n,int m)
{
	return 1LL*fac[n]*inv[m]%MO*inv[n-m]%MO;
}
int main()
{
	fac[0]=1;
	for(int i=1;i<=MAXM;i++)
		fac[i]=1LL*fac[i-1]*i%MO;
	inv[MAXM]=PowMod(fac[MAXM],MO-2);
	for(int i=MAXM-1;i>=0;i--)
		inv[i]=1LL*inv[i+1]*(i+1)%MO;
	scanf("%d%d",&n,&k);
	if(k==1)
	{
		printf("1\n");
		return 0;
	}
	dp[0][0]=1;
	for(int i=1;i<=n;i++)
		for(int j=0;j<=i;j++)
		{
			dp[i][j]=dp[i-1][j];
			if(j!=0)
				dp[i][j]+=1LL*dp[i][j-1]*C(n*k-i-(k-1)*(j-1)-1,k-2)%MO;
			dp[i][j]%=MO;
		}
	int ans=1LL*dp[n][n]*fac[n]%MO;
	printf("%d\n",ans);
}

Measured memory_bytes: 47104
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
typedef long long ll;
using namespace std;
int main()
{
  int A, B, C;
  cin >> A >> B >> C;
  rep(i, 101)
  {
    if (A * i % B == C)
    {
      cout << "YES" << endl;
      return 0;
    }
  }
  if (A == 1)
  {
    cout << "YES" << endl;
    return 0;
  }
  cout << "NO" << endl;
  return 0;
}

Measured memory_bytes: 256