akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define fr(i,a,n) for(ll i=a;i<n;i++)
#define YES cout<<"YES"<<endl
#define all(v) v.begin(),v.end()
#define NO cout<<"NO"<<endl
#define pb(x) emplace_back(x)
#define fastio std::ios_base:: sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define vi vector<ll>
#define mi map<ll,ll>
#define pi pair<ll,ll>
#define what(x) cout<<#x<<" ="<<x<<endl;
#define scn(n) scanf("%d",&n)
#define print(a) printf("%d",a);
using namespace std;
using ll =int;
ll n;

ll dp[200005],a[200005]={1000000000};
ll invalid=1e9;
ll cnt=0;
int solve(ll i,ll p)
{ //cnt++;
    if(i==n-1)return dp[i]=0;
    if(i>=n)return 1e9;
    if(dp[i]!=-1)return dp[i];
    //what(p-a[i]);
    //cout<<i<<" GG "<<i+1<<endl;

    ll x=abs(a[i+1]-a[i])+solve( i+1,a[i]);

   // what(x);

    ll y=abs(a[i+2]-a[i])+solve(i+2,a[i]);
   // cout<<i<<" "<<i+2<<endl;
   //what(x); what(y);
    x=min(x,y);



    return dp[i]=x;

}

int main()
{
    ll t;
    memset(dp,-1,sizeof dp);

    scn(n);
    fr(i,0,n)cin>>a[i];

    solve(0,a[0]);

    printf("%d\n",dp[0]);
    //what(cnt);
    //fr(i,0,n)cout<<dp[i]<<" ";

}



























Measured memory_bytes: 11224
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
int INF=1<<29;

int main(){
	int N;
	cin>>N;
	vector<int> A(N);
	for(int i=0;i<N;i++) cin>>A[i];
	sort(A.begin(),A.end());
	A.erase(unique(A.begin(),A.end()),A.end());
	if((N-A.size())%2) cout<<A.size()-1;
	else cout<<A.size();
	return 0;
}

Measured memory_bytes: 640
#include<stdio.h>
#include<string.h>
#define LEN 100005
 
typedef struct pp{
  char name[100];
  int t;
}P;
 
P Q[LEN+1];
int head, tail, n;
 
void enqueue(P );
P dequeue(void);
int calc(int,int);
 
int main(){
  int e=0,c;
  int i,q;
  P u;
  scanf("%d %d\n", &n, &q);
 
  for ( i = 1; i <= n; i++){
    scanf("%s", Q[i].name);
    scanf("%d",&Q[i].t);
 
  }
 
  head = 1;
  tail = n+1;
   
  while(head != tail){
    u = dequeue();
    c = calc(q,u.t);
    u.t -= c;;
    e += c;
    
 
    if(u.t > 0){
      enqueue(u);
    }
     
    else{
      printf("%s %d\n", u.name ,e);
    }
  
  }
  return 0;
}
P dequeue(){
    P x;
    x = Q[head];
    head = (head+1)%LEN;
    return x;
      }
void enqueue(P x){
  Q[tail] = x;
  tail = (tail + 1)%LEN;
}
int calc(int x, int y){
  return x < y ? x:y;
}

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

typedef complex<double> P;

#define EPS (1e-10)
#define EQ(a,b) (abs((a)-(b)) < EPS)
#define EQV(a,b) ( EQ((a).real(), (b).real()) && EQ((a).imag(), (b).imag()) )

double cross(P ,P);
int func(P,P,P,P);

int main(void){
  double xa,ya,xb,yb,xc,yc,xd,yd;
  P a,b,c,d;

  while(~scanf("%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf"
	      ,&a.real(),&a.imag(),&b.real(),&b.imag()
	      ,&c.real(),&c.imag(),&d.real(),&d.imag())){
    if(func(a,b,c,d)||func(a,c,b,d))cout << "YES" << endl;
    else cout << "NO" << endl;
  }


  return 0;
}

double cross(P a,P b) {
  return (a.real() * b.imag() - a.imag() * b.real());
}

int func(P a1,P a2,P b1,P b2) {
  return ( cross(a2-a1, b1-a1) * cross(a2-a1, b2-a1) < EPS ) &&
         ( cross(b2-b1, a1-b1) * cross(b2-b1, a2-b1) < EPS );
}

Measured memory_bytes: 0
#include <algorithm>
#include <iostream>
#include <cmath>
#include <numeric>
#include <string>
#include <vector>

using namespace std;
using ll = long long;
using pll = pair<ll, ll>;

const auto MOD = static_cast<ll>(1e9 + 7);

ll A, B, C;

int main() {
    cin >> A >> B >> C;
    if (A % 2 && B % 2 && C % 2) {
        cout << min(A * B, min(B * C, C * A)) << endl;
    }
    else {
        cout << 0 << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
 
using namespace std;
 
int main() {
    int n, W;
    scanf("%d %d", &n, &W); 
    
    vector<long long> w(n), v(n);
    for(int i = 0; i < n; ++i) 
        scanf("%lld%lld", &w[i], &v[i]);
        
    vector<long long> dp(W+1);
    
    for(int i = 0; i < n; ++i) {
        for(int j = W - w[i]; j >= 0; --j) { 
            dp[j + w[i]] = max(dp[j] + v[i], dp[j+w[i]]);//cout<<dp[j+w[i]]<<endl;
        }
    }
    printf("%lld\n", dp[W]);
}

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

int main() {
  ll n;
  cin >> n;
 
  vector<ll> v(n),count_odd(100000),count_even(100000);
  for (ll i=0;i<n;i++) {
    cin >> v.at(i);
    ll x = v.at(i);
    if (i%2==0) count_odd.at(x-1)++;
    else count_even.at(x-1)++;
  }
  
  vector<pair<ll,ll>> odd_index(100000),even_index(100000);
  for (ll i=0;i<100000;i++) {
    odd_index.at(i) = make_pair(count_odd.at(i),i);
    even_index.at(i) = make_pair(count_even.at(i),i);
  }
  sort(odd_index.begin(),odd_index.end());
  sort(even_index.begin(),even_index.end());
  
  ll ans;
  ll o1=odd_index.at(99999).first, e1=even_index.at(99999).first;
  ll o2=odd_index.at(99999).second, e2=even_index.at(99999).second;
  ll o3=odd_index.at(99998).first, e3=even_index.at(99998).first;
  if (o2 != e2) ans = n-o1-e1;
  else ans = n - max((o1+e3),(o3+e1));
  
  cout << ans;
}

Measured memory_bytes: 5888
def main():
    
    a,b = map(int, input().split())

    ans = ''
    if a >= b:
        for i in range(a):
            ans += str(b)
        print(ans)
    else:
        for i in range(b):
            ans += str(a)
        print(ans)
    


if __name__ == '__main__':
    main()



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

int main() {
    vector<bool> v(31, false);
    for(int i=0; i<28; ++i) {
        int n; cin >> n;
        v[n] = true;
    }
    for(int i=1; i<=30; ++i) {
        if(!v[i]) {
            cout << i << endl;
        }
    }
}


Measured memory_bytes: 3084
import java.util.ArrayList;
import java.util.List;
import java.util.PriorityQueue;
import java.util.Scanner;


public class Main {

	static class State { // →bの辺の重さw
		int b, w;
		public State(int b, int w) {
			this.b = b;
			this.w = w;
		}
	}
	static class PQ implements Comparable<PQ>{
		int now, d;
		public PQ(int now, int d) {
			this.now = now;
			this.d = d;
		}
		public int compareTo(PQ p) { // →大小→
			return this.d - p.d;
		}
	}

	public static void main(String[] args) throws Exception {
		try(Scanner sc = new Scanner(System.in)) {
			int V = sc.nextInt(); // 頂点数
			int INF = Integer.MAX_VALUE;

			@SuppressWarnings("unchecked")
			List<State>[] edge = new ArrayList[V];
			for(int i=0; i<V; i++) {
				edge[i] = new ArrayList<State>();
			}
			for(int i=0; i<V; i++) {
				int u = sc.nextInt();
				int k = sc.nextInt();
				for(int j=0; j<k; j++) {
					int v = sc.nextInt();
					int c = sc.nextInt();
					edge[u].add(new State(v, c));
				}
			}
			PriorityQueue<PQ> pq = new PriorityQueue<>();
			int[] dis = new int[V];
			boolean[] processed = new boolean[V];
			for(int i=0; i<V; i++) {
				dis[i] = INF;
				processed[i] = false;
			}

			dis[0] = 0;
			pq.add(new PQ(0, 0));
			while(! pq.isEmpty()) {
				PQ p = pq.poll();
				if(processed[p.now]) {
					continue;
				}
				processed[p.now] = true;
				for(State s : edge[p.now]) {
					if(p.d+s.w < dis[s.b]) {
						dis[s.b] = p.d + s.w;
						pq.add(new PQ(s.b, dis[s.b]));
					}
				}
			}
			for(int i=0; i<V; i++){
				System.out.println(i+" "+dis[i]);
			}
		}
	}

}


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

using namespace std;

#define LL long long
#define DD double
#define Pb push_back
#define Bp pop_back
#define Pf push_front
#define Fp pop_front
#define Ub upper_bound
#define Lb lower_bound
#define In insert
#define All(x) x.begin(), x.end()
#define mem(a, b) memset(a, b, sizeof(a))
#define fast ios_base::sync_with_stdio(0);cin.tie(0)
#define X first
#define Y second
#define mx1 10
#define mx2 110
#define mx3 1010
#define mx4 10010
#define mx5 100010
#define mx6 1000010

typedef vector<LL> Vl;
typedef vector<DD> Vd;
typedef vector<bool> Vb;
typedef vector<Vl> VVl;
typedef pair<LL, LL> Pll;
typedef pair<DD, DD> Pdd;
typedef vector<Pll> Vpl;
typedef vector<Pdd> Vpd;
typedef queue<LL> Ql;
typedef stack<LL> Sl;
typedef deque<LL> Dl;

LL _set(LL N, LL pos) {return N = N | (1 << pos);}
LL _reset(LL N, LL pos) {return N = N & ~(1 << pos);}
bool _check(LL N, LL pos) {return (bool)(N & (1 << pos));}
bool _upper(char a) {return a >= 'A' && a <= 'Z';}
bool _lower(char a) {return a >= 'a' && a <= 'z';}
bool _digit(char a) {return a >= '0' && a <= '9';}

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

///**************************DONE****************************///

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

    int t = 1;
    while(a > 0 && c > 0){
        if(t % 2)
            c -= b;
        else
            a -= d;
        t++;
    }

    if(a > 0)
        cout << "Yes\n";
    else
        cout << "No\n";
    return 0;
}


Measured memory_bytes: 3608
N,Y=map(int,input().split())

for x in range(N+1):
  for y in range(N+1-x):
    if 10000*x+5000*y+1000*(N-x-y)==Y:
      print("%d %d %d"%(x,y,N-x-y))
      exit()
print("-1 -1 -1")

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

#define INF (2e9)
#define FOR(i, a, b) for (ll (i) = (a); (i) < (b); ++(i))
#define REP(i, n) FOR(i, 0, n)

using namespace std;

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

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

using ll = long long;
using ld = long double;

#define ALL(x) (x).begin(), (x).end()
template<class T>
using vc = vector<T>;
using vi = vc<ll>;
using vvi = vc<vi>;

template<class T>
using va = valarray<T>;
using vad = va<ld>;
using vai = va<ll>;

using pii = pair<ll, ll>;

vi Read(ll n) {
    auto      v = vi(n);
    for (auto i = std::size_t(0); i < n; ++i) {
        cin >> v[i];
    }
    return v;
}

template<class T>
void DumpRow(const T& A) {
    for (const auto& value : A)
        cout << value << "\n";
}

template<class T>
void DumpColumn(const T& A) {
    auto isFirst = true;
    for (const auto& value : A) {
        if (isFirst) {
            cout << value;
            isFirst = false;
        } else {
            cout << " " << value;
        }

    }
    cout << endl;
}

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

    ll n;
    cin >> n;
    auto v = vi(n);
    iota(ALL(v), 1);

    do {
        DumpColumn(v); // now
    } while (next_permutation(ALL(v)));

    return 0;
}



Measured memory_bytes: 3188
#include<iostream>
using namespace std;
int main (void){

    int n, i, j, z, min, w[100];
    int a = 0, b = 0, c = 0; 

    cin >> n;

    for(i = 0;i < n;i++){

        cin >> w[i];

    }

    for(i = 0;i < n;i++){
        
        for(j = i;j >= 0;j--){

            a += w[j];
        }
        for(z = i + 1;z < n;z++){

            b += w[z];
        }

        c = a - b;
        if(c < 0)
            c *= -1;

        if(i == 0)
            min = c;

        if(min > c)
        min = c;

        a = 0, b = 0;
    }    

    cout << min << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int H,W;
  cin >> H >> W;
  vector<vector<char>> p(H,vector<char>(W));
  for(int i = 0; i< H; i++){
    for(int j = 0; j<W; j++){
      cin >> p.at(i).at(j);
    }
  }
vector<vector<char>> q(H+2,vector<char>(W+2,'#'));
  for(int i = 1; i<= H; i++){
    for(int j = 1; j<=W; j++){
      q.at(i).at(j)= p.at(i-1).at(j-1);
    }
  }
  for(int i = 0; i<=H+1; i++){
    for(int j = 0; j<=W+1;j++){
      if(j == W+1){
        cout << q.at(i).at(j)<< endl;
      }
      else{
        cout << q.at(i).at(j);
      }
    }
  
}
}



Measured memory_bytes: 256
#pragma GCC optimize "03"
#include "bits/stdc++.h"
using namespace std;
 
#define ll long long int
#define ld long double
#define pi pair<int, int>
#define pb push_back
#define fi first
#define se second
#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#ifndef LOCAL
#define endl '\n'
#endif
 
const int N = 1e5 + 5;
const int mod = 1e9 + 7;
const int inf = 1e9 + 9;
 
signed main() {
	IOS;
	#ifdef LOCAL
		freopen("input.txt","r", stdin);
		freopen("output.txt","w",stdout);
	#endif
	int n, l, s = 0;
	cin >> n >> l;
	for(int i = 1; i <= n; i++)
		s += (l + i -1);
	int mi = inf, ans;
	for(int i = 1; i <= n; i++){
		int x = l + i - 1;
		if(abs(x) < mi)
			mi = abs(x), ans = s - x;
	}		
	cout << ans;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
#define ld long double
typedef pair<ll,ll> P;
#define boost ios_base::sync_with_stdio(false);cin.tie(0); cout.tie(0);
int main()
{
    ll n,m,i,j;
    cin>>n>>m;
    string S[n];
    for(i=0;i<n;i++)
    cin>>S[i];
    ll DP[n+1][m+1];
    memset(DP,0,sizeof(DP));
    DP[n-1][m-1]=1;
    for(i=n-2;i>=0;i--)
    {
        if(S[i][m-1]!='#')
        DP[i][m-1]=DP[i+1][m-1];
    }
    for(i=m-2;i>=0;i--)
    {
        if(S[n-1][i]!='#')
        DP[n-1][i]=DP[n-1][i+1];
    }
    for(i=n-2;i>=0;i--)
    {
        for(j=m-2;j>=0;j--)
        {
            if(S[i][j]!='#')
            {
                DP[i][j]=DP[i+1][j]+DP[i][j+1];
                DP[i][j]=DP[i][j]%((ll)(1e9+7));
            }
        }
    }
    cout<<DP[0][0]<<endl;
}


Measured memory_bytes: 9088
def z_algo(s):
    """文字列sについて、各iについて「SとS[i:|S|]の最長共通接頭辞の長さ」
    を記録した配列をO(|S|)で構築する
    """
    res = [0] * len(s)
    res[0] = len(s)
    i = 1
    j = 0
    while i < len(s):
        while i + j < len(s) and s[j] == s[i + j]:
            j += 1
        res[i] = j
        if j == 0:
            i += 1
            continue
        k = 1
        while i + k < len(s) and k + res[k] < j:
            res[i + k] = res[k]
            k += 1
        i += k
        j -= k
    return res


n = int(input())
s = input()

ans = 0
for i in range(n):
    t = z_algo(s[i:n])
    for i, num in enumerate(t):
        ans = max(ans, min(num, i))
print(ans)

Measured memory_bytes: 53596
#include "bits/stdc++.h"
#define ll long long
#define rep2(i,a,b) for(int i=(a);i<=(b);++i)
#define rep(i,n) for(int i=0;i<n;i++)
#define pii pair<int,int>
#define ti3 tuple<int,int,int>
ll int MOD=1e9+7;
#define N 200000
 
using namespace std;
string alphabet("abcdefghijklmnopqrstuvwxyz");

main(){
    ll int x,y;
  cin>>x>>y;
    if(abs(x-y)<2) cout<<"Brown";
    else cout<<"Alice";
    return 0;
}

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

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

    int n, d;
    cin >> n >> d;
    int r = d * 2 + 1;
    cout << (n + r - 1) / r << endl;

    return 0;
}

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

int main() {
	string s;
	cin >> s;
	int a[4];
	for (int i = 0; i < 4; i++) {
		a[i] = s[i] - '0';
	}
	for (int i = 0; i < (1 << 3); i++) {
		int ans = a[0];
		for (int j = 0; j < 3; j++) {
			if ((i >> j) & 1) {
				ans += a[j + 1];
			} else {
				ans -= a[j + 1];
			}
		}
		if (ans == 7) {
			cout << a[0];
			for (int j = 0; j < 3; j++) {
				if ((i >> j) & 1) {
					cout << '+';
				} else {
					cout << '-';
				}
				cout << a[j + 1];
			}
			cout << "=7" << endl;
			return 0;
		}
	}
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <stack>
using namespace std;
int n, nn, q;
long long a[200001], ans[200001], num[200001];
stack<long long> s;
void solve(long long len, long long sum)
{
    int pos = lower_bound(a + 1, a + nn + 1, len) - a - 1;
    if (!pos)
    {
        ans[1] += sum;
        ans[len + 1] -= sum;
        return;
    }
    num[pos] += len / a[pos] * sum;
    solve(len % a[pos], sum);
}
int main(int argc, char const *argv[])
{
    scanf("%d%d", &n, &q);
    s.push(n);
    for (int i = 1; i <= q; i++)
    {
        long long x;
        scanf("%lld", &x);
        while (!s.empty() && x < s.top())
        {
            s.pop();
        }
        s.push(x);
    }
    nn = s.size();
    for (int i = nn; i >= 1; i--)
    {
        a[i] = s.top();
        s.pop();
    }
    num[nn] = 1;
    for (int i = nn; i >= 1; i--)
    {
        solve(a[i], num[i]);
    }
    for (int i = 1; i <= n; i++)
    {
        ans[i] += ans[i - 1];
    }
    for (int i = 1; i <= n; i++)
    {
        printf("%lld\n", ans[i]);
    }
    return 0;
}

Measured memory_bytes: 6900
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <vector>
#include <cstdlib>
#include <iomanip>
#include <cmath>
#include <ctime>
#include <map>
#include <set>
#include<string>
#include <queue>
#include <stack>
using namespace std;
typedef long long ll;
const int maxn=1e5+4;
int main(){
    int n,i;
    while(cin>>n>>i){
    	printf("%d\n",n-i+1);
	}
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int32_t main(){
	int n, sum = 0; cin>>n;
	string s = to_string(n);
	for(char c: s){
		sum += (c - '0');
	}
	cout<<(n % sum == 0 ? "Yes" : "No");
}


Measured memory_bytes: 256
from math import floor,ceil,sqrt
import fractions
from collections import deque
import itertools
import collections
from heapq import *
N,K=map(int,input().split())
lr=[list(map(int,input().split())) for _ in range(K)]
ans=[0]*N
ans[0]=1
p=998244353
  
"""
print(ans)
for j in range(K):
    l = lr[j][0]
    r = lr[j][1]
    if l < N:
        ans[l] = ans[l] + 1
    if r + 1 < N:
        ans[r + 1] = ans[r + 1] - 1
print(ans)
print()
"""
for i in range(N):
    #print(ans)
    #print(i)
    for j in range(K):
        l = i+lr[j][0]
        r = i+lr[j][1]
        #print(l,r)
        if l < N:
            ans[l] = ans[l] + ans[i]
        if r + 1 < N:
            ans[r + 1] = ans[r + 1] - ans[i]
    #print(ans)
    ans[0]=0
    if i<N-1:
        ans[i+1]=(ans[i+1]+ans[i])%p
    #print(ans)
    #print()
print(ans[N-1])




Measured memory_bytes: 74724
#include<bits/stdc++.h>
using namespace std;
int main() {
	int N,ans=0;
	cin >> N;
	
	for (int i = 1; i <= N; i++)
	{
		int l = to_string(i).length();
		if( l % 2 == 1) ++ans;
	}

	cout << ans << endl;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
int main() {
	int N, M;
	cin >> N >> M;
	vector<int>A(N);
	for (int i = 0; i < M; i++) {
		int a, b;
		cin >> a >> b;
		A.at(a - 1)++;
		A.at(b - 1)++;
	}
	for (int i = 0; i < N; i++) {
		cout << A.at(i) << endl;
	}
}

Measured memory_bytes: 256
N = int(input())
def num2alpha(num):
    if num<=26:
        return chr(64+num)
    elif num%26==0:
        return num2alpha(num//26-1)+chr(90)
    else:
        return num2alpha(num//26)+chr(64+num%26)
      
print(num2alpha(N).lower())

Measured memory_bytes: 9176
#include <iostream>
#include <fstream>
#include <cmath>  
#include <cstdlib>
#include <ctime>
#include <algorithm>
#include <numeric>
#include <functional>
#include <string> 
#include <vector>
#include <bitset>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <deque>

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

#define REP(i,n) for(int i = 0; i < int(n); i++)
#define REREP(i,n) for(int i = int(n - 1); i >= 0; i--)
#define FOR(i, m, n) for(int i = int(m);i < int(n);i++)
#define REFOR(i, m, n) for(int i = int(n - 1);i >= int(m);i--)
#define ALL(obj) (obj).begin(),(obj).end()
#define fi first 
#define se second

#define VI vector<int>
#define VVI vector<vector<int>>
#define VVVI vector<vector<vector<int>>>
#define VD vector<double>
#define VVD vector<vector<double>>
#define VVVD vector<vector<vector<double>>>
#define VL vector<ll>
#define VVL vector<vector<ll>>
#define VVVL vector<vector<vector<ll>>>
#define VB vector<bool>
#define VVB vector<vector<bool>>
#define VVVB vector<vector<vector<bool>>>
#define VS vector<string>
#define VVS vector<vector<string>>
#define VVVS vector<vector<vector<string>>>

#define PII pair<int,int>
#define PDD pair<double,double>
#define PLL pair<ll,ll>
#define VPII vector<pair<int,int>>
#define VVPII vector<vector<pair<int,int>>>
#define VVVPII vector<vector<vector<pair<int,int>>>>
#define VPLL vector<pair<ll,ll>>
#define VVPLL vector<vector<pair<ll,ll>>>
#define VVVPLL vector<vector<vector<pair<ll,ll>>>>

const ll MOD = (ll)1e9 + 7;
const ll HINF = (ll)1e18;
const ll LINF = (ll)1e9;
const long double PI = 3.1415926535897932384626433;


void YN(bool flag) {
	cout << ((flag) ? "YES" : "NO") << endl;
}

void Yn(bool flag) {
	cout << ((flag) ? "Yes" : "No") << endl;
}

void yn(bool flag) {
	cout << ((flag) ? "yes" : "no") << endl;
}

int main() {
	int N,K; cin >> N >>K;
	VI cnt(K,0);
	ll a = 0, b = 0;
	for (int i = 1; i <= N; ++i) {
		if (i%K == 0)a++;
		if (K % 2 == 0 && i%K == K / 2)b++;
	}
	
	cout << a*a*a + b*b*b << endl;





	return 0;
}



Measured memory_bytes: 1024
// 
#include <bits/stdc++.h>
#define endl "\n"
#define rep(i,n) for(int i=0;i<int(n);i++)
#define e_b emplace_back
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> ipair;
typedef pair<ll,ll> lpair;
template <class T>ostream &operator<<(ostream &o,const vector<T>&v) //vectorの中身を見る
{o<<"{";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")<<v[i];o<<"}";return o;}
void map_p(map<int,int>& d){cout<<"map: ";for(auto a : d){cout<<"{"<<a.first<<":"<<a.second<<"}";}cout<<endl;} //mapの中身を見る
void set_p(set<int>& d){cout<<"set: ";for(int a : d){cout<<a<<" ";}cout<<endl;} //setの中身を見る


int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(12);

    ll n;
    cin>>n;
    vector<ll> a(n+1);
    for(int i=1;i<=n;i++) cin>>a[i];
    ll mon=1000,stock=0,day=1;
    while(true){
        if(day==n) break;
        if(a[day]==a[day+1]){
            day++;
            continue;
        }else if(a[day]<a[day+1]){
            ll now=day;
            while(a[now]<a[now+1]){
                now++;
                if(now==n) break;
            }
            ll can=(mon-mon%a[day])/a[day]; //買う株
            stock+=can;
            mon-=a[day]*can;
            // nowに売る
            mon+=a[now]*stock;
            stock=0;
            day=now;
        }else{
            ll now=day;
            while(a[now+1]<a[now]){
                now++;
                if(now==n) break;
            }
            day=now;
        }
    }
    cout<<mon<<endl;
    return 0;
}

Measured memory_bytes: 3640
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <map>
#include <queue>
#include <iomanip>
#include <set>
#include <tuple>
#define mkp make_pair
#define mkt make_tuple
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
const ll MOD=1e9+7;

int N;
vector<int> g[200020];

int size[200020];
ll two[200020];

int setSize(int now,int par){
  size[now]=1;
  for(auto to:g[now]){
    if(to==par) continue;
    size[now]+=setSize(to,now);
  }
  return size[now];
}

ll ans;

void add(ll &a,ll b){
  a=(a+b)%MOD;
}

void dfs(int now,int par){
  ll sum=1;
  ll res=0;
  for(auto nex:g[now]){
    if(nex==par) continue;
    add(res,(two[size[nex]]-1+MOD)%MOD);
    sum+=size[nex];
    dfs(nex,now);
  }
  ll p=N-sum;
  add(res,(two[p]-1+MOD)%MOD);
  add(res,1ll);
  //cout<<now<<" "<<res<<endl;
  add(ans,res);
}

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

int main(){
  cin>>N;
  rep(i,N-1){
    int a,b;
    cin>>a>>b;
    a--;b--;
    g[a].push_back(b);
    g[b].push_back(a);
  }

  two[0]=1;
  for(int i=1;i<=N;i++) two[i]=two[i-1]*2%MOD;

  setSize(0,-1);
  dfs(0,-1);
  //cout<<ans<<endl;

  ll res=(N*two[N-1]%MOD-ans+MOD)%MOD;
  for(ll i=1;i<=N;i++) res=res*mod_pow(2ll,MOD-2)%MOD;

  cout<<res<<endl;


  return 0;
}


Measured memory_bytes: 24704
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <unordered_map>
#include <functional>
#include <utility>
#include <tuple>
#include <cctype>
#include <bitset>
#include <complex>
#include <cmath>
#include <array>
#include <numeric>
using namespace std;
#define INF 0x3f3f3f3f
#define INFLL 0x3f3f3f3f3f3f3f3fLL
//#define MOD 998244353
#define MOD 1000000007
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define eb emplace_back
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pint;
typedef pair<ll,ll> pll;
typedef tuple<int,int,int> tint;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<ull> vull;
typedef vector<pint> vpint;
int dx[8]={0,0,-1,1,1,1,-1,-1};
int dy[8]={-1,1,0,0,1,-1,1,-1};
const int SIZE=100050;
//↑templete
signed main(){

	int a, b;
	cin>>a>>b;
	string S=to_string(a), T=to_string(b);
	string U, V;
	for(int i=0;i<b;i++)
		U+=S;
	for(int i=0;i<a;i++)
		V+=T;
	cout<<min(U, V)<<endl;


	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define dl double
#define mp make_pair
#define pb push_back
using namespace std;

//***********************************************************************

// hash struct for unordered_map
struct hash_pair { 
    template <class T1, class T2> 
    size_t operator()(const pair<T1, T2>& p) const
    { 
        auto hash1 = hash<T1>{}(p.first); 
        auto hash2 = hash<T2>{}(p.second); 
        return hash1 ^ hash2; 
    } 
};

int MAXNUM = 5e3+5;
vector <int>vis(MAXNUM);
vector<int> pr;
void sieve() {
	pr.push_back(2);
	for(ll i=3;i<MAXNUM;i+=2) if(!vis[i]) {
		pr.push_back(i);
		for(ll j=i*i;j<MAXNUM;j+=2*i) vis[j]=true;
	}
}
//************************************************************************

ll cnt[1<<16];
ll dp[1<<16];
// ll finddpvalue(ll mask,ll pos)
// {
//     if(pos==-1)
//     {
//         return cnt[mask];
//     }
//     if(dp[mask][pos]!=-1)
//     {
//         return dp[mask][pos];
//     }
//     ll ans=0;
//     ans+=finddpvalue(mask,pos-1);
//     if(mask&(1<<pos))
//     ans+=finddpvalue(mask^(1<<pos),pos-1);
//     return dp[mask][pos]=ans;

// }

ll finddpvalue2(int mask)
{
    if(mask==0)
    return 0;
    if(dp[mask]!=-1)
    return dp[mask];
    ll ans=cnt[mask];
    for(int i = (mask-1)&mask; i > 0; i = (i-1) & mask)
    {
        int group=mask^i;
        //cout << "mask : " << mask << " i : " << i << " grp :" << group << endl;
        ans=max(ans,cnt[group]+finddpvalue2(i));
    }
    return dp[mask]=ans;
}


void solve()
{
    ll n;
    cin >> n;
    vector<vector<ll>> v(n,vector<ll>(n));
    for(int i=0;i<n;i++)
    {
        for(int j=0;j<n;j++)
        {
            cin >> v[i][j];
        }
    }
    memset(cnt,0,sizeof cnt);
    for(ll mask=0;mask<(1<<n);mask++)
    {
        for(ll i=0;i<n;i++)
        {
            if(mask&(1<<i))
            {
                for(ll j=i+1;j<n;j++)
                {
                    if(mask&(1<<j))
                    cnt[mask]+=v[i][j];
                }
            }
        }
    }
    memset(dp,-1,sizeof dp);
    //cout << "c0"  << endl;
    ll ans=finddpvalue2((1<<n)-1);
    //cout << "c0"  << endl;
    cout << ans << endl;
}


int main()
{ 
	ios_base::sync_with_stdio(false); 
    cin.tie(NULL);
	ll t;
	//cin >> t;
	t=1;
	while(t--)
	{
		solve();
	}

	return 0;
}

Measured memory_bytes: 1280
#include <algorithm>
#include <iostream>
#include <utility>
#include <vector>
using namespace std;
using Line = vector<char>;
using Puzzle = vector<Line>;

void newline() {cout << endl;}
template <typename T>
void put(T input){cout << input;}
template <typename T>
void putl(T input){put(input); newline();}

int n;
int point;
Puzzle puzzle;

void swap_rec(int column, int row){
  if(0<column){
    swap(puzzle[column][row], puzzle[column-1][row]);
    swap_rec(column-1, row);
  }
}

void drop(){
  Puzzle prev_puzzle = puzzle;
  for(int column=puzzle.size()-1; 0<=column; column--){
    for(int row=puzzle[column].size()-1; 0<=row; row--){
      if(puzzle[column][row] == '#')
        swap_rec(column, row);
    }
  }
  if(puzzle != prev_puzzle) drop();
}

int clear(Line &line, int n, char c){
  if(line[n] == c){
    line[n]='#';
    if(1 <= n && n < line.size()-1){
      return int(c)-int('0')+clear(line, n+1, c)+clear(line, n-1, c);
    }else{
      return int(c)-int('0');
    }
  } else {
    return 0; 
  }
}


int solve(){
  Puzzle prev_puzzle = puzzle;
  for(Line &line: puzzle)
    for(int k=1; k<line.size()-1; k++)
      if(line[k] != '#' && line[k-1] == line[k] && line[k] == line[k+1])
        point+=clear(line, k, line[k]);
  drop();
  if(prev_puzzle != puzzle) solve();
  return point;
}

int main() {
  while(cin>>n && n){
    point=0; puzzle={}; puzzle.reserve(n);
    for(int ic=0; ic<n; ic++){
      Line line; 
      line.resize(5);
      for(int lc=0; lc<5; lc++){
        char s; cin >> s; line[lc]=s;
      }
      puzzle.push_back(line);
    }
    putl(solve());
  }
}

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

using namespace std;

int main(){
    int n,a,b,ans=0,d,p=0;
    cin >> n >> a >> b;
    for(int t=1;t<=n;t++){
        d=t,p=0;
        while(d>=1){
            p+=d%10;
            d/=10;
        }
        if(p>=a && p<=b){
            ans+=t;
        }
    }
    cout << ans << '\n';
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline

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

mod=10**9+7
# mod の逆元
def modinv(a, mod=10**9+7):
    return pow(a, mod-2, mod)

# 正,負 で分ける
b=[]
c=[]
for i in a:
    if i>=0:
        b.append(i)
    else:
        c.append(i)

b.sort(reverse=True)
c.sort()
ans=1
if k==n:
    for i in range(n):
        ans*=a[i]
        ans%=mod

elif k%2==1 and len(c)==n:
    c.sort(reverse=True)
    for i in range(k):
        ans*=c[i]
        ans%=mod

else:
    x=k
    # プラスの配列をどこまで進めたか
    v=0
    # マイナスの配列をどこまで進めたか？
    w=0
    if k%2==1:
        ans*=b.pop(0)
        k-=1

    for i in range(k):
        if x>=2:
            x-=2
            if v+2<=len(b) and w+2<=len(c):
                if b[v]*b[v+1]>c[w]*c[w+1]:
                    ans*=b[v]*b[v+1]
                    v+=2
                else:
                    ans*=c[w]*c[w+1]
                    w+=2


            elif v+2<=len(b):
                ans*=b[v]*b[v+1]
                v+=2

            else:
                ans*=c[w]*c[w+1]
                w+=2

            ans%=mod
            if x==0:
                break

print(ans)

Measured memory_bytes: 107608
#include <stdio.h>
int main (void)
{
    int i;
    int n;
    long long ans = 1;
    scanf("%d",&n);

    for(i=1;i<=n;i++){
        ans *= i;
        if(ans > (1000000000 + 7))
            ans %= (1000000000 + 7);

        
    }

    printf("%lld\n",ans);

    return 0;
}

Measured memory_bytes: 128
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
	private static int[][] paper = new int[10][10];

	public static void main(String[] args) throws NumberFormatException, IOException {
		BufferedReader reader = new BufferedReader(new InputStreamReader(System.in), 128);
		String sLine;
		while ((sLine = reader.readLine()) != null) {
			droppingInk(sLine.charAt(0) & 0x0F, sLine.charAt(2) & 0x0F, sLine.charAt(4) & 0x0F);
		}
		calcResult();
	}

	private static void droppingInk(int x, int y, int size) {
		staining(x, y - 1);
		staining(x - 1, y);
		staining(x, y);
		staining(x + 1, y);
		staining(x, y + 1);
		if (size == 1) {
			return;
		}

		staining(x - 1, y - 1);
		staining(x + 1, y - 1);
		staining(x - 1, y + 1);
		staining(x + 1, y + 1);
		if (size == 2) {
			return;
		}

		staining(x, y - 2);
		staining(x - 2, y);
		staining(x + 2, y);
		staining(x, y + 2);
	}

	private static void staining(int x, int y) {
		if (x >= 0 && x < 10 && y >= 0 && y < 10) {
			paper[x][y]++;
		}
	}

	private static void calcResult() {
		int white = 0;
		int maxnoud = 0;
		for (int[] row : paper) {
			for (int colum : row) {
				if (colum == 0) {
					white++;
				} else if (colum > maxnoud) {
					maxnoud = colum;
				}
			}
		}
		System.out.println(white);
		System.out.println(maxnoud);
	}
}

Measured memory_bytes: 17048
#include <iostream>
#include <string>
#include <vector>
#include <climits>
#include <set>
#include <algorithm>
#include <unordered_map>
#include <queue>
#include <iomanip>
#include <map>
#include <utility>
#include <numeric>
#include <chrono>
#include <ctime>
#include <bitset>
#include <iterator>

#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define P pair<long long, long long>
#define debug(x) cerr << #x << ": " << x << ", "
#define debugln(x) cerr << #x << ": " << x << '\n'

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 namespace std;
using ll = long long;
const ll mod = 1e9 + 7;

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

  vector<int> a(4);
  rep(i, 4) {
    cin >> a[i];
  }
  sort(a.begin(), a.end());
  if (a[0] == 1 && a[1] == 4 && a[2] == 7 && a[3] == 9) {
    cout << "YES" << endl;
  } else {
    cout << "NO" << endl;
  }

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = (0); i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(x) (x).begin(),(x).end()
#define rrng(x) (x).rbegin(),(x).rend()
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define show(x) cout << #x << " = " << (x) << endl
#define show2(x,y) cout << #x << " = " << (x) << ", " << #y << " = " << (y) << endl
#define show3(x,y,z) cout << #x << " = " << (x) << ", " << #y << " = " << (y) <<  ", " << #z << " = " << (z) << endl
#define showv(v) rep(i,v.size()) printf("%d%c", v[i], i==v.size()-1?'\n':' ')
#define showv2(v) rep(j,v.size()) showv(v[j])
#define showt(t,n) rep(i,n) printf("%d%c", t[i], i==n-1?'\n':' ')
#define showt2(t,r,c) rep(j,r) showt(t[j],c)
#define showvp(p) rep(i,p.size()) printf("%d %d\n", p[i].first, p[i].second);
#define printv(v) rep(i,v.size()) printf("%d\n", v[i])
#define printt(t,n) rep(i,n) printf("%d\n", t[i])
#define incl(v,x) find(rng(v),x)!=v.end()
#define incls(s,c) s.find(c)!=string::npos
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define bit(n,k) ((n>>k)&1) // nのk bit目
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define uni(x) x.erase(unique(rng(x)),x.end())
#define SP << " " <<
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<string> vs;
typedef pair<int, int> P;
typedef tuple<int, int, int> T;
typedef vector<P> vp;
typedef vector<T> vt;
const int mod = 1000000007;
const double EPS = 1e-9;
const int INF = (1<<30)-1;
const ll INFLL = (1LL<<62)-1;
#define dame { puts("No"); return 0;}
#define yn {puts("Yes");}else{puts("No");}
inline int in() { int x; scanf("%d",&x); return x;}
template<typename T>inline ll suma(const v(T)& a) { ll res(0); for (auto&& x : a) res += x; return res;}
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

int main () {
  ll n, k;
  cin >> n >> k;
  vector<double> p(n);
  rep(i,n) cin >> p[i];
  
  vector<int> csum(p.size()+1);
  rep(i,p.size()) {
    csum[i+1] = csum[i] + p[i];
  }
  int sum = 0;
  int lx;
  rep(l,n-k+1) {
    int tmp = csum[l+k] - csum[l];
    if (tmp > sum) {
      sum = tmp;
      lx = l;
    }
  }

  double ans_mx = 0;
  double ans = 0;
  srep(i,lx,lx+k) {
    ans += (p[i]+1)/2;
  }
  ans_mx = max(ans_mx,ans);

  cout << fixed << setprecision(10) << ans_mx << endl;
  return 0;
}

Measured memory_bytes: 2560
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)n; i++)
#define ALL(a) (a).begin(), (a).end()
const ll mod = 1e9 + 7;

int main()
{
    int n, k;
    cin >> n >> k;
    if (k == 1)
        cout << 0 << endl;
    else
        cout << n - k << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <utility>
#include <algorithm>
#include <cmath>
#include <queue>
#include <set>
#include <map>
#include <cassert>
#include <fstream>
#include <iomanip>

using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;

const ll mod = 1e9 + 7;

vector<ll> dx = {1, -1, 0, 0};
vector<ll> dy = {0, 0, 1, -1};

vector<vector<ll>> g;

long long gcd(const long long& a, const long long& b)
{
    if (b == 0)
    {
        return a;
    }
    return gcd(b, a % b);
}

int main() {
    
    cin.tie(0);
    ios_base::sync_with_stdio(0);
    
    ll n, k, s;
    cin >> n >> k >> s;
    
    for (int i = 0; i < n; ++i)
    {
        if (i < k)
        {
            cout << s;
        }
        else
        {
            if (s == 1000000000ll)
            {
                cout << 1;
            }
            else
            {
                cout << 1000000000ll;
            }
        }
        
        if (i != n - 1)
        {
            cout << " ";
        }
        else
        {
            cout << endl;
        }
    }

    return 0;
}

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

int main(){
    int x, y;
    while(cin >> x >> y, x != 0 || y != 0){
        if( x < y){
            cout << x << " " << y << endl;
        }else{
            cout << y << " " << x << endl;
        }
    }

    return 0;
}


Measured memory_bytes: 3096
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <map>
#include <vector>
#include <stack>
#include <queue>
#include <tuple>

using namespace std;
typedef long long ll;
int dx[4] = {0,0,1,-1};
int dy[4] = {1,-1,0,0};
const int INF = 1<<29;
const ll LNF = 1LL<<60;

ll a[100010][3];
ll dp[100010][3];

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

    for(int i=0;i<N;i++){
        for(int j=0;j<3;j++){
            for(int k=0;k<3;k++){
                if(j==k) continue;
                dp[i+1][k] = max(dp[i+1][k],dp[i][j]+a[i][k]);
            }
        }
    }
    cout << max(dp[N][0],max(dp[N][1],dp[N][2])) << endl;
    return 0;
}


Measured memory_bytes: 4992
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;

int main(){
    
    ll N, K;
    cin >> N >> K;
    vector<ll>A(101010, 0);
    for(ll i = 0; i < N; i++){
        ll a, b;
        cin >> a >> b;
        A[a] += b;
    }
    for(ll i = 1; ; i++){
        K -= A[i];
        if(K <= 0){
            cout << i << endl;
            return 0;
        }
    }
    return 0;
}

Measured memory_bytes: 1536
import copy
n = int(input())
li = list(map(int,input().split()))
li1 = copy.copy(li)
li1.sort()
cnt = 0
for i in range(n):
    if li[i] != li1[i]:
        cnt += 1

if cnt <= 2:
    print('YES')
else:
    print('NO')

Measured memory_bytes: 9340
#include <bits/stdc++.h>
#define forn(i,b) for(int i=0 ; i< b ;i++)
#define for1(i,b) for(int i=1 ; i<=b ;i++)
#define reps(i,a,b) for(int i=a ; i< b.length() ;i++)
typedef long long ll;
#define MOD 1000000007

using namespace std;




int main()
{

  ll sum=0, n ;
  cin >> n ;
  for(int i=1 ; i<=n ; i++){
    if(i%5==0 || i%3==0){
      continue ;
    }else {
      sum += i ;
    }
  }
cout <<sum ;
  return 0 ;
}


Measured memory_bytes: 3616
#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 ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef long double ld;
int main()
{
  int n;
  cin >> n;
  vector<int> time(n);
  ll sum_t = 0;
  REP(i,n){
    cin >> time[i];
    sum_t += (ll)time[i];
  }
  
  int m;
  cin >> m;
  int p,x;
  REP(i,m){
    cin >> p >> x;
    cout << sum_t - time[p-1] + x << '\n';
  }
  return 0;
}


Measured memory_bytes: 384
package main

import (
	"bufio"
	"errors"
	"fmt"
	"io"
	"math"
	"os"
	"strconv"
)

func main() {
	sc := NewScanner(os.Stdin)
	n, _ := sc.NextInt()
	a, _ := sc.NextInts(n)
	q, _ := sc.NextInt()
	b, c := make([]int, q), make([]int, q)
	for i := 0; i < q; i++ {
		b[i], _ = sc.NextInt()
		c[i], _ = sc.NextInt()
	}
	ans := solve(n, q, a, b, c)
	for _, v := range ans {
		fmt.Println(v)
	}
}

func solve(n, q int, a, b, c []int) (ans []int) {
	count := map[int]int{}
	for _, v := range a {
		count[v]++
	}
	ans = make([]int, q+1)
	ans[0] = sum(count)
	for i := 0; i < q; i++ {
		ans[i+1] = ans[i] - b[i]*count[b[i]] + c[i]*count[b[i]]
		count[c[i]] += count[b[i]]
		delete(count, b[i])
	}
	return ans[1:]
}

func sum(count map[int]int) int {
	ret := 0
	for k, v := range count {
		ret += k * v
	}
	return ret
}

// Scanner is a wrapper of bufio.Scanner which is customized for competitive programing.
type Scanner struct {
	bufio.Scanner
}

// NewScanner is a constructor for Scanner.
func NewScanner(r io.Reader) *Scanner {
	sc := Scanner{*bufio.NewScanner(r)}
	sc.Buffer([]byte{}, math.MaxInt64)
	sc.Split(bufio.ScanWords)
	return &sc
}

// NextInt reads a integer from io stream.
func (sc *Scanner) NextInt() (int, error) {
	if !sc.Scan() {
		return -1, errors.New("failed to scan")
	}
	return strconv.Atoi(sc.Text())
}

// NextInts reads n integers from io stream.
func (sc *Scanner) NextInts(n int) (arr []int, e error) {
	arr = make([]int, n)
	for i := 0; i < n; i++ {
		v, e := sc.NextInt()
		if e != nil {
			return nil, e
		}
		arr[i] = v
	}
	return arr, nil
}


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

#define rep(i, n) for (int i = 0; i < int(n); i++)
#define rrep(i, n) for (int i = int(n) - 1; i >= 0; i--)
#define reps(i, n) for (int i = 1; i <= int(n); i++)
#define rreps(i, n) for (int i = int(n); i >= 1; i--)
#define repc(i, n) for (int i = 0; i <= int(n); i++)
#define rrepc(i, n) for (int i = int(n); i >= 0; i--)
#define repi(i, a, b) for (int i = int(a); i < int(b); i++)
#define repic(i, a, b) for (int i = int(a); i <= int(b); i++)
#define each(x, y) for (auto &x : y)
#define all(a) (a).begin(), (a).end()
#define bit(b) (1ll << (b))

using namespace std;

using i32 = int;
using i64 = long long;
using u64 = unsigned long long;
using f80 = long double;
using vi32 = vector<i32>;
using vi64 = vector<i64>;
using vu64 = vector<u64>;
using vf80 = vector<f80>;
using vstr = vector<string>;

inline void yes() { cout << "Yes" << '\n'; exit(0); }
inline void no() { cout << "No" << '\n'; exit(0); }
inline i64 gcd(i64 a, i64 b) { if (min(a, b) == 0) return max(a, b); if (a % b == 0) return b; return gcd(b, a % b); }
inline i64 lcm(i64 a, i64 b) { return a / gcd(a, b) * b; }
inline u64 xorshift() { static u64 x = 88172645463325252ull; x = x ^ (x << 7); return x = x ^ (x >> 9); }
void solve(); int main() { ios::sync_with_stdio(0); cin.tie(0); cout << fixed << setprecision(16); solve(); return 0; }
template <typename T> class pqasc : public priority_queue<T, vector<T>, greater<T>> {};
template <typename T> class pqdesc : public priority_queue<T, vector<T>, less<T>> {};
template <typename T> inline void amax(T &x, T y) { if (x < y) x = y; }
template <typename T> inline void amin(T &x, T y) { if (x > y) x = y; }
template <typename T> inline T power(T x, i64 n, T e = 1) { T r = e; while (n > 0) { if (n & 1) r *= x; x *= x; n >>= 1; } return r; }
template <typename T> istream& operator>>(istream &is, vector<T> &v) { each(x, v) is >> x; return is; }
template <typename T> ostream& operator<<(ostream &os, vector<T> &v) { rep(i, v.size()) { if (i) os << ' '; os << v[i]; } return os; }
template <typename T, typename S> istream& operator>>(istream &is, pair<T, S> &p) { is >> p.first >> p.second; return is; }
template <typename T, typename S> ostream& operator<<(ostream &os, pair<T, S> &p) { os << p.first << ' ' << p.second; return os; }

void solve() {
  int n, m;
  cin >> n;
  set<string> se;
  rep(i, n) { string u; cin >> u; se.insert(u); }
  cin >> m;
  bool opened = false;
  rep(i, m) {
    string s; cin >> s;
    if (se.count(s) > 0) {
      opened = !opened;
      if (opened) {
        cout << "Opened by " << s << '\n';
      } else {
        cout << "Closed by " << s << '\n';
      }
    } else {
      cout << "Unknown " << s << '\n';
    }
  }
}



Measured memory_bytes: 3236
#include <stdio.h>

int main(void)
{
	int width, height;		//Value W, H. (Rectangle)
	int x, y, r;			//Value x, y, r. (Circle coordinate x, y and Radius of circle r.)
	int flag;				//answer flag.

	scanf("%d %d %d %d %d", &width, &height, &x, &y, &r);

	if( (x - r < 0 || x + r > width) || (y - r < 0 || y + r > height) )
		printf("No\n");
	else
		printf("Yes\n");

	return (0);
}



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


int main(){
    string str1,str2;
    int n, len1, len2;
    scanf("%d",&n);
    for(int i=1;i<=n;++i){
        cin>>str1>>str2;
        //scanf("%s",str1);
        //scanf("%s",str2);
        len1 = str1.size();
        len2 = str2.size();
        str1 = ' '+str1;
        str2 = ' '+str2;
        int c[len1+1][len2+1];
        for(int i=0;i<=len1;++i) c[i][0] = 0;
        for(int i=0;i<=len2;++i) c[0][i] = 0;
        for(int i=1;i<=len1;++i){
            for(int j=1;j<=len2;++j){
                if(str1[i]==str2[j]){
                    c[i][j] = c[i-1][j-1]+1;
                }
                else{
                    c[i][j] = max(c[i-1][j],c[i][j-1]);
                }
            }
        }
        printf("%d\n",c[len1][len2]);
    }
    return 0;
}





Measured memory_bytes: 7192
#![allow(unused_imports)]
use itertools::Itertools;
use proconio::{input, marker::*};
use std::cmp::*;
use std::collections::*;
use superslice::*;

fn main() {
    input! {
        n: usize,
        m: usize,
        k: u64,
        mut a: [u64;n],
        mut b: [u64;m]
    }

    let mut a_sums = vec![0; n + 1];
    a_sums[0] = 0;

    let mut b_sums = vec![0; m + 1];
    b_sums[0] = 0;

    for i in 0..n {
        a_sums[i + 1] = a_sums[i] + a[i];
    }

    for i in 0..m {
        b_sums[i + 1] = b_sums[i] + b[i];
    }

    let mut ans = 0;
    let mut cur_b = m;
    for i in 0..=n {
        if a_sums[i] > k {
            break;
        }
        while a_sums[i] + b_sums[cur_b] > k {
            if cur_b > 0 {
                cur_b -= 1;
            } else {
                break;
            }
        }
        ans = max(ans, i + cur_b);
    }

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


Measured memory_bytes: 12452
#include<iostream>
#include<string>
#include<typeinfo>
#include<vector>
#include<algorithm>
#include<map>
#include<stdio.h>
using namespace std;
int main()
{
	int N, K;
	cin >> N >> K;

	char c;
	int cnt=0;
	for(int i=0; i<N; i++){
		cin >> c;
		if(i==K-1){
			printf("%c", c+32);
		}else{
			cout << c;
		}
	}
	cout << endl;
	return 0;
}

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

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

    vector<int> x(m);
    rep (i, m)
        cin >> x[i];

    if (m == 1)
    {
        cout << 0 << endl;
        return 0;
    }

    sort(x.begin(), x.end());

    vector<int> dist(m - 1);
    rep (i, m - 1)
        dist[i] = x[i + 1] - x[i];

    sort(dist.begin(), dist.end(), greater<int>());

    ll ans = accumulate(dist.begin(), dist.end(), 0);
    int cnt = min(n - 1, m - 1);
    rep (i, cnt)
        ans -= dist[i];

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

Measured memory_bytes: 4064
#include<bits/stdc++.h>
using namespace std;
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define pii pair<int,int> 
#define int long long 
#define N 20005

int32_t main(){
    string s;
    cin>>s;
    if(s=="ABC") cout<<"ARC"<<endl;
    else cout<<"ABC"<<endl;
}

Measured memory_bytes: 3580