akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a),i##formax=(b);i<i##formax;i++)
#define FORR(i,a,b) for(int i=(a),i##formax=(b);i>=i##formax;i--)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define pcnt __builtin_popcount
#define sz(x) (int)(x).size()
#define maxs(x,y) x=max(x,y)
#define mins(x,y) x=min(x,y)
#define show(x) cout<<#x<<" = "<<x<<endl;
#define all(a) (a.begin()),(a.end())
#define each(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++)
#define perm(c) sort(all(c));for(bool c##p=1;c##p;c##p=next_permutation(all(c)))
#define bitComb(a,n,k) for(int a##x,a##y,a=(1<<k)-1;a<(1<<n);a##x=a&-a,a##y=a+a##x,a=(((a&~a##y)/a##x)>>1)|a##y)
#define uniq(v) sort(all(v));v.erase(unique(all(v)), v.end())
#define bit(n) (1LL<<(n))
#define randInt(l,r) (uniform_int_distribution<ll>(l,r)(rnd))
#define randDouble(l,r) (uniform_real_distribution<double>(l,r)(rnd))
#define dout(d) printf("%.12f\n",d)

typedef long long ll;
typedef __int128_t lll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
template<class T>using V=vector<T>;
template<class T>using VV=V<V<T>>;
template<class T,class Y>ostream& operator<<(ostream& o,const pair<T,Y>& p){return o<<"("<<p.fi<<", "<<p.se<<")";}
template<typename A,size_t N,typename T>void Fill(A (&array)[N],const T&v){fill((T*)array,(T*)(array+N),v);}
lll gcd(lll a,lll b,lll &x,lll &y){if(!b){x=1;y=0;return a;}lll d=gcd(b,a%b,y,x);y-=a/b*x;return d;}
ll gcd(ll a,ll b){lll x=0,y=0;return gcd(a,b,x,y);}
ll modInv(ll a,ll m){lll x,y;gcd(a,m,x,y);return (x%m+m)%m;}
ll modPow(lll a,lll n,ll m){if(!a)return a;lll p=1;for(;n>0;n>>=1,a=a*a%m)if(n&1)p=p*a%m;return(ll)p;}
bool isPrime(ll n){if(n<2||n%2==0)return n==2;lll t=n-1,d=t/(t&-t);for(lll a:{2,325,9375,28178,450775,9780504,1795265022})if(a%n){for(t=d,a=modPow(a,t,n);t!=n-1&&a!=1&&a!=n-1;a=a*a%n,t=t*2%n);if(a!=n-1&&t%2==0)return 0;}return 1;}
const int IINF = 1e9+6;
const ll LINF = 1e18;
const int MOD = 1e9+7;
const double PI = acos(-1);
const double EPS = 1e-10;
static random_device rd;
static mt19937 rnd(rd());

ll L, R, D, M, N;
pll s(ll a, ll n){
  if(n==0) return mp(0ll, 0ll);
  if(n&1){
    pll p = s(a, n-1);
    return mp((p.fi+(n-1)%M*modPow(a, n-1, M))%M, (p.se*a+1) % M);
  }else{
    pll p = s(a, n/2);
    ll k = modPow(a, n/2, M);
    return mp((n/2%M*k%M*p.se%M+p.fi*(k+1)%M)%M, (k+1)*p.se%M);
  }
}
main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> N >> L >> D >> M;
  R = L+D*N;
  ll ans = 0, ten = 1;
  FOR(i, 1, 19){
    ll l = (max(ten-L, 0ll)+D-1)/D*D+L;
    ten *= 10;
    ll r = (max(ten-L, 0ll)+D-1)/D*D+L;
    mins(r, R);
    if(r<=l) continue;
    ll d = modPow(10, i, M), n = (r-l)/D;
    pll p = s(d, n);
    ans = (ans*modPow(d, n, M)%M + (r-D)%M*p.se%M-D%M*p.fi%M)%M;
  }
  cout << (ans+M)%M << endl;
}

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

using namespace std;

#define INF 2140000000
#define MOD 1000000007

int main() {
	int n;

	cin >> n;
	
	vector<int> h(n);

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

	int ans = 1;

	for (int i = 1; i < n; ++i) {
		int cnt = 0;
		for (int j = 0; j < i; ++j) {
			if (h[j] <= h[i]) {
				cnt++;
			}
		}

		if (cnt == i) {
			ans++;
		}
	}

	cout << ans << endl;
	



	return 0;
}

Measured memory_bytes: 256
# coding: utf-8

N = int(input())
nums = [int(x.strip()) for x in input().split(' ') ] # 1人は関係ない
leng = len(nums)+ 1
l = [0] * leng

for num in nums:
    l[num-1] = l[num-1] + 1

for ans in l:
    print(ans)

Measured memory_bytes: 32184
#include<iostream>
using namespace std;
int main(){
    int n;
    cin>>n;
    int A[2][100];
    for(int i=0;i<2;i++){
        for(int j=0;j<n;j++) cin>>A[i][j];
    }
    int ans[100]={0};
    for(int i=0;i<n;i++){
        for(int j=0;j<n;j++){
            if(i>j) ans[i]=ans[i]+A[0][j];
            if(i==j) ans[i]=ans[i]+A[0][j]+A[1][j];
            if(i<j) ans[i]=ans[i]+A[1][j];
        }
    }
    int x=0;
    for(int i=0;i<n;i++){
        if(x<ans[i]) x=ans[i];
    }
    cout<<x;
}

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

int main(){
  int ans=0;
  char S[102];
  scanf("%s",S);
  int N=strlen(S);
  for(int i=0;i<N/2;i++){
    if(S[i]!=S[N-1-i]) ans++;
  }
  printf("%d\n",ans);
  return 0;
}

Measured memory_bytes: 1728
#pragma GCC optimize("O3")
#include<bits/stdc++.h>
#include<map>
#include<iostream>
#include <cstring>
#include <iomanip>
#include <algorithm>
#define forr(i,a,b) for(int i=a;i<=b;i++)
#define F first
#define S second
#define input ios_base::sync_with_stdio(0);cin.tie(0);

const double PI  = acos(-1.0);
using namespace std;
//typedef pair<double,double>pdd;
typedef long long  ll;
typedef pair<ll, ll>pii;
//typedef complex<double> point;
//int x[8]={1,0,0,-1,-1,-1,1,1};
//int y[8]={0,1,-1,0,-1,1,-1,1};
//char rv[4]={'D','R','L','U'};
const double EPS = 1e-9;
const int N = 100000 + 9;
int n,mem[N][5],a[N],b[N],c[N];

int dp(int i,int  pr)
{
    if(i > n)return 0;
    if(mem[i][pr] != -1) return mem[i][pr];

    int c1 = 0, c2 = 0, c3 = 0;

    if(pr != 0) c1 = a[i] + dp(i+1, 0);
    if(pr != 1) c2 = b[i] + dp(i+1, 1);
    if(pr != 2) c3 = c[i] + dp(i+1, 2);

    return mem[i][pr] = max({c1,c2,c3});
}

 int main()
{
//freopen("calc.in","r",stdin);
//freopen("calc.out","w",stdout);
//__builtin_popcount()
input
        cin>>n;
        forr(i,1,n)cin>>a[i]>>b[i]>>c[i];

        memset(mem,-1,sizeof mem);

        cout<<dp(1,4)<<endl;





return 0;
}


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

int asc(const void *a,const void *b){
  return *(int *)a-*(int *)b;
}

int main(void){
  int i;

  int n;
  scanf("%d",&n);

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

  qsort(v,n,sizeof(int),asc);

  double ans=v[0];

  for(i=1;i<n;i++){
    ans=(ans+v[i])/2;
  }

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

  return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
int main() {
    int N; cin >> N;
    vector<pair<int, int>> A;
    for (int i = 0; i < N; i++) {
        int x, l; cin >> x >> l;
        A.emplace_back(x + l, x - l);
    }
    sort(begin(A), end(A));
    int ee = INT_MIN;
    int ans = 0;
    for (auto &a : A) {
        int e, s; tie(e, s) = a;
        if (ee <= s) ans++, ee = e;
    }
    cout << ans << endl;
    return 0;
}


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

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n;
    cin>>n;
    int count=0;
    if(n>2 && n<=100)
    {
    while(n--)
    {
        int D1,D2;
        cin>>D1>>D2;
        while((D1>0 &&D1<=6) && (D2>0 && D2<=6))
        {

        if(D1==D2)
        {
            count++;
            break;
        }
        if(count>=3)
            break;
        else
        {
            count=0;
            break;
        }
        }
        
        
    }
    if(count>=3)
    {
        cout<<"Yes"<<'\n';
    }
    else
    {
        cout<<"No"<<'\n';
    }
    
    }
    return 0;
}

Measured memory_bytes: 3624
l,r = map(int, input().split())
if r-l+1>2019:
  print(0)
  exit()
L = []
for i in range(l,r):
  for j in range(i+1,r+1):
    a = i*j
    b = a%2019
    L.append(b)
print(min(L))


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

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n,m;
	cin>>n>>m;
	priority_queue<ll> pq;
	for(int i=0; i<n; ++i){
		ll x; cin>>x;
		pq.push(x);
	}
	for(int i=0; i<m; ++i){
		auto x = pq.top(); pq.pop();
		pq.push(x/2);
	}
	ll ans = 0;
	while(!pq.empty()){
		ans += pq.top(); pq.pop();
	}
	cout<<ans<<'\n';

	return 0;
}


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

#if MYDEBUG
#include "lib/cp_debug.hpp"
#else
#define DBG(...) ;
#endif
#if __cplusplus <= 201402L
template <typename T>
T gcd(T a, T b) { return ((a % b == 0) ? b : gcd(b, a % b)); }
template <typename T>
T lcm(T a, T b) { return a / gcd(a, b) * b; }
#endif
using LL = long long;
constexpr LL LINF = 334ll << 53;
constexpr int INF = 15 << 26;
constexpr LL MOD = 1E9 + 7;

namespace Problem {
using namespace std;

class Solver {
 public:
  string s;
  int n, q;
  Solver(string s) : s(s), n(s.length()){};

  void solve() {
    cin >> q;
    vector<vector<vector<int>>> dp(q + 1, vector<vector<int>>(n, vector<int>(n)));
    for (int i = 0; i < n; ++i) {
      dp[0][i][i] = 1;
    }
    for (int i = 0; i < n - 1; ++i) {
      if (s[i] == s[i + 1]) {
        dp[0][i][i + 1] = 2;
      } else {
        dp[0][i][i + 1] = 1;
      }
    }
    for (int d = 2; d < n; ++d) {
      for (int i = 0; i < n - d; ++i) {
        if (s[i] == s[i + d]) {
          dp[0][i][i + d] = dp[0][i + 1][i + d - 1] + 2;
        } else {
          dp[0][i][i + d] = max(dp[0][i + 1][i + d], dp[0][i][i + d - 1]);
        }
      }
    }
    DBG(dp[0])
    for (int i = 1; i <= q; ++i) {
      for (int j = 0; j < n; ++j) {
        dp[i][j][j] = 1;
      }
      for (int j = 0; j < n - 1; ++j) {
        if (s[j] == s[j + 1]) {
          dp[i][j][j + 1] = 2;
        } else {
          dp[i][j][j + 1] = 2;
        }
      }
      for (int d = 2; d < n; ++d) {
        for (int j = 0; j < n - d; ++j) {
          dp[i][j][j + d] = dp[i - 1][j][j + d];
          if (s[j] == s[j + d]) {
            dp[i][j][j + d] = max(dp[i][j][j + d], dp[i][j + 1][j + d - 1] + 2);
          } else {
            dp[i][j][j + d] = max({dp[i][j][j + d], dp[i][j + 1][j + d], dp[i][j][j + d - 1], dp[i - 1][j + 1][j + d - 1] + 2 /*, dp[i - 1][j][j + d - 1] + 2*/});
          }
        }
      }
    }
    DBG(dp)
    cout << dp[q][0][n - 1] << endl;
  }
};

}  // namespace Problem

int main() {
  std::cin.tie(0);
  std::ios_base::sync_with_stdio(false);
  // std::cout << std::fixed << std::setprecision(12);
  std::string s;
  std::cin >> s;
  Problem::Solver sol(s);
  sol.solve();
  return 0;
}


Measured memory_bytes: 109952
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
using namespace std;
typedef long long ll;
int INF = (1LL << 30) - 1;
int MOD = 1e9+7;
int cntab(string str){
    int cnt = 0;
    rep(i,0,str.size()-1){
        cnt += str.substr(i,2) == "AB";
    }
    return cnt;
}
main(){
    int N;
    cin >> N;
    vector<string> V(N);
    rep(i,0,N)cin >> V[i];
    int cnt = 0, ca = 0, cb = 0, cab = 0;
    rep(i,0,N){
        //cout << cntab(V[i]) << endl;
        cnt += cntab(V[i]);
        if(V[i][0] == 'B' && V[i].back() == 'A')cab++;
        else if(V[i][0] == 'B')cb++;
        else if(V[i].back() == 'A')ca++;
    }
    //cout << ca << " " << cb << " " << cab << endl;
    //cout << cnt << endl;
    if(cab){
        if(ca && cb){
            cnt += 2;
            ca--,cb--;
        }else if((ca >= 1) ^ (cb >= 1)){
            cnt++;
            ca = max(0, ca-1);
            cb = max(0, cb-1);
        }
    }
    int c = min(ca, cb); 
    cnt += c;
    ca -= c;
    cb -= c;
    cnt += max(0, cab-1);
    //cout << ca << " " << cb << " " << cab << endl;
    cout << cnt << endl;
}

Measured memory_bytes: 768
#include <iostream>
#include <sstream>
using namespace std;
main()
{
    string s;
    while( getline( cin, s ), s != "0" )
    {
        stringstream ss(s);
        ss << s;
        int sum = 0, one = 0, a;
        while( ss >> a )
        {
            if( a == 1 ) one++;
            else sum += min( 10, a );
        }
        if( one > 21 || sum > 21 || one + sum > 21 )
        {
            cout << 0 << endl;
        }
        else
        {
            int p = ( 11 * one + sum - 21 + 10 - 1) / 10;
            cout << p + ( one - p ) * 11 + sum << endl;
        }
        
    }
    return 0;
}


Measured memory_bytes: 3200
N = gets.to_i

playlist = []
N.times do 
  song_set = gets.split()
  song = song_set[0]
  time = song_set[1]
  playlist << {"#{song}": "#{time}"}
end

sleep_name = gets.chomp.to_s

sleep_song_count = 0
playlist.each_with_index do |array, index|
  if sleep_name == array.keys.first.to_s
    sleep_song_count = index + 1
  end
end

left_over_list = playlist.drop(sleep_song_count)

total_sleep_time = 0
left_over_list.each do |array|
  total_sleep_time += array.values.first.to_i
end

puts total_sleep_time


Measured memory_bytes: 1788
#include<bits/stdc++.h>
using namespace std;
#define ALL(x) x.begin(),x.end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define debug(v) cout<<#v<<":";for(auto x:v){cout<<x<<' ';}cout<<endl;
#define mod 1000000007
using ll=long long;
const int INF=1000000000;
const ll LINF=1001002003004005006ll;
int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};
// ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
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;}

struct IOSetup{
    IOSetup(){
        cin.tie(0);
        ios::sync_with_stdio(0);
        cout<<fixed<<setprecision(12);
    }
} iosetup;

template<typename T1,typename T2>
ostream &operator<<(ostream &os,const pair<T1,T2>&p){
    os<<p.first<<" "<<p.second;
    return os;
}

template<typename T>
ostream &operator<<(ostream &os,const vector<T>&v){
    for(int i=0;i<(int)v.size();i++) os<<v[i]<<(i+1==v.size()?"":" ");
    return os;
}


signed main(){
    ll n;cin>>n;
    
    ll ans=0;
    for(ll i=1;i<=n;i++){
        ans+=i*(i+1)/2;
    }
    rep(i,n-1){
        ll u,v;cin>>u>>v;
        if(u>v) swap(u,v);
        ll mi=(n-v+1)*u;
        ans-=mi;
    }
    cout<<ans<<endl;
    return 0;
}


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

bool sortbysec(const pair<long long,long long>&a,const pair<long long,long long> &b)
{
	return(a.second<b.second);
	//sort(s.begin(),s.end(),sortbysec);
	//s.push_back(make_pair(x,y));
}

int main()
{
	vector<pair<long long,long long>> ve;
	long long n,k,h;
	cin>>n>>k;
	long long a[n+1],i,dp[n+1],j;
	for(i=0;i<n;i++)
		cin>>a[i];
	dp[0]=0;
	dp[1]=abs(a[1]-a[0]);
	
	for(i=2;i<n;i++)
	{
	    h=1e10;
	    for(j=1;j<=k && j<=i;j++)
		    h = min(abs(a[i]-a[i-j]) + dp[i-j] , h);
		dp[i] = h;    
	}	
	cout<<dp[n-1];
	return 0;
}

Measured memory_bytes: 1792
#include <stdio.h>
#include <math.h>
int main() {
   int H1,M1,H2,M2,K;
   int d_H,d_M,d;
   int d_HK,d_MK;

   scanf("%d %d %d %d %d", &H1, &M1, &H2, &M2, &K);

    d_H = H2 - H1;
    d_M = M2 - M1;
    d = d_H*60 + d_M;
    if(d<= K){
        printf("0");
    }else{
        printf("%d",(d-K));


    }
    
    //printf("theta = %f\n",theta);


  return 0;
}

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

int main() {
  int n;
  scanf("%d", &n);
  vector<int> arr(2*n);
  for (int &x : arr) scanf("%d", &x);
  sort(arr.begin(), arr.end());
  int ans = 0;
  for (int i = 0; i < arr.size(); i += 2) ans += arr[i];
  printf("%d\n", ans);
}

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

int main() {
    int n;
    cin >> n;
    vector<int> d(n);

    for (auto& e : d) {
        cin >> e;
    }

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

    cout << d[n/2] - d[n/2 - 1] << endl;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define LLINF 9223372036854775807
#define MOD ll(1e9+7)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cerr<<#x<<": "<<x<<endl

int main(){
    double w, h, x, y;
    cin >> w >> h >> x >> y;

    printf("%.12f ",w*h/2);
    if(x == w/2 && y == h/2){
        cout << 1 << endl;
    }else{

        cout << 0 << endl;
    }

    return 0;

}


Measured memory_bytes: 256
import sys
n = int(input())
aa = input()
a = aa.split()

for i in range(n):
    if(int(a[i]) == 0):
        print(0)
        sys.exit()

result = 1
for i in range(n):
    result *= int(a[i])
    if(result > 1000000000000000000):
        print(-1)
        sys.exit()

print(result)


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

using namespace std;

int main() {
  
  int N; cin >> N;
  int a[N]; // sorted
  for(int i=0; i<N; i++) scanf("%d", &a[i]);
  int Q; cin >> Q;
  int ans = 0;
  while(Q--) {
    int b; cin >> b;
    int l = 0, r = N;
    while(r-l > 1) {
      int m = (l+r) / 2;
      if(a[m] <= b) {
	l = m;
      }
      else {
	r = m;
      }
    }
    if(a[l] == b) ans ++; // lower_bound
  }
  
  printf("%d\n", ans);
  return 0;
}

Measured memory_bytes: 1616
#include <bits/stdc++.h>
using namespace std;
#define REP(i,m,n) for(int i = m;i < n;i++)
#define rep(i,n) REP(i,0,n)
#define rrep(i,n) REP(i,1,n+1)
typedef pair<int,int> P;
typedef pair<int, P> PP;
#define fi first
#define se second
const int inf = 1e9;

int a[100002];
int main(){
	int n,sum = 0;
	scanf("%d", &n);
	rrep(i,n)scanf("%d", &a[i]);
	REP(i,1,n+2){
		sum += abs(a[i]-a[i-1]);
	}
	rrep(i,n){
		int d = abs(a[i-1]-a[i])+abs(a[i]-a[i+1])-abs(a[i-1]-a[i+1]);
		printf("%d\n", sum-d);
	}
	//printf("%d\n", sum);
	return 0;
}

Measured memory_bytes: 1664
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int A = Integer.parseInt(sc.next());
		int B = Integer.parseInt(sc.next());
		int C = Integer.parseInt(sc.next());
		sc.close();

		if(A == B) {
			System.out.println(C);
		}else if(B == C) {
			System.out.println(A);
		}else if(C == A) {
			System.out.println(B);
		}

	}
}

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

int main(){
  int s;
  cin >> s;
  int a = s/100, b = s%100;
  string ans = "NA";
  if(a > 0 && a < 13 && b > 0 && b < 13) ans = "AMBIGUOUS";
  if(a > 0 && a < 13 && (b == 0 || b > 12)) ans = "MMYY";
  if((a == 0 || a > 12) && b > 0 && b < 13) ans = "YYMM";
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;


int main()
{
	int t=0;
	char p[3]={'A','B','C'};
	string s[3];
	for(int i=0;i<3;i++)
	{
		cin>>s[i];
	}
	while(1)
	{
		if(s[t]=="")
		{
			cout<<p[t]<<endl;
			return 0;
		}
		int r=t;
		t=s[t][0]-'a';
		s[r].erase(0,1);

	}
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <map>
#include <vector>
#include <stack>
#include <queue>
#include <tuple>
#include <cassert>
#include <functional>
#include <set>
#include <deque>
#include <list>
using namespace std;
typedef long long ll;
int dx[4] = {0,0,1,-1};
int dy[4] = {1,-1,0,0};
#define LNF __LONG_LONG_MAX__
const ll MOD = 1000000007;
const int MAX = 200000;

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;
}
// 法mでのaの逆元を計算
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;
}
// a^n mod を計算する
long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
//最大公約数
long long gcd(long long x, long long y){
    if(y==0) return x;
    else return gcd(y,x%y);
}
//最小公倍数
long long lcm(long long x, long long y){
    return x / gcd(x, y) * y;
}
// nが大きく,kが10^7程度の時の二項係数
long long com[200005];
void combination(long long n,long long k){
    com[0] = 1;
    for(int i=1;i<=k;i++){
        com[i] = (com[i-1]*(n-i+1)%MOD)*modinv(i,MOD)%MOD;
    }
}

int main(){
    int N; cin >> N;
    vector<int> d(N);
    for(int i=0;i<N;i++){
        cin >> d[i];
    }
    sort(d.begin(),d.end());
    int now=d[0];
    int out=1;
    for(int i=1;i<N;i++){
        if(now==d[i]) continue;
        out++;
        now = d[i];
    }
    cout << out << endl;
    return 0;
}


Measured memory_bytes: 3620
#include <cstdio>
#include <vector>
#include <limits>

using namespace std;

namespace {

static size_t Merge(size_t* A, size_t left, size_t mid, size_t right) {
  const size_t n1 = mid - left;
  const size_t n2 = right - mid;

  vector<size_t> L(n1+1);
  vector<size_t> R(n2+1);
  for (size_t i = 0; i < n1; ++i) {
    L[i] = A[left + i];
  }
  for (size_t i = 0; i < n2; ++i) {
    R[i] = A[mid + i];
  }

  static const size_t kInf = numeric_limits<size_t>::max();
  L[n1] = kInf;
  R[n2] = kInf;

  size_t i = 0;
  size_t j = 0;
  for (size_t k = left; k < right; ++k) {
    if (L[i] <= R[j]) {
      A[k] = L[i];
      i++;
    } else {
      A[k] = R[j];
      j++;
    }
  }
  return right - left;
}

static size_t MergeSortInternal(size_t* A, size_t left, size_t right) {
  if (left + 1 >= right) return 0;

  const size_t mid = (left + right) / 2;
  size_t ret = MergeSortInternal(A, left, mid);
  ret += MergeSortInternal(A, mid, right);
  return ret + Merge(A, left, mid, right);
}

static size_t MergeSort(size_t* A, size_t n) {
  return MergeSortInternal(A, 0, n);
}
} // namespace

int main() {
  size_t n;
  size_t S[500000];
  scanf("%lu", &n);
  for (size_t i = 0; i < n; ++i) {
    scanf("%lu", &S[i]);
  }

  const size_t swapped = MergeSort(S, n);
  for (size_t i = 0; i < n; ++i) {
    if (i > 0) printf(" ");
    printf("%lu", S[i]);
  }
  printf("\n");
  printf("%lu\n", swapped);

  return 0;
}

Measured memory_bytes: 8716
while True:
  try:
    p, q = map(int, input().split())
  except EOFError:
    break
  dic = [None] * q
  save = []
  counter = 0
  while p:
    if dic[p] != None:
      print("".join(save))
      print(" " * dic[p] + "^" * (counter - dic[p]))
      break
    dic[p] = counter
    save.append(str(p * 10 // q))
    p = p * 10 % q
    counter += 1
  else:
    print("".join(save))



Measured memory_bytes: 21444
#include <stdio.h>
#include <cstdio>
#include <iostream>
#include <queue>
#include <set>
#include <vector>
#include <cstring>

const long long INFTY = 5e12;

long long int section_sum(std::vector<long long int> accumulated_sum, long long int i, long long int j);


int main(){
  
  // read problem
  long long int N;
  long long int tmp;
  std::vector<long long int> a, a_accum;
  
  scanf("%lld", &N);
  
  for(long long int i = 0; i < N; i++){
    scanf("%lld", &tmp);
    a.push_back(tmp);
  }
  a_accum.push_back(a[0]);
  for(long long int i = 1; i < N; i++){
    a_accum.push_back(a_accum[i-1]+a[i]);
  }
  
  std::cerr << "a:" << std::endl;
  for(long long int i = 0; i < N; i++){
    std::cerr << a[i] << " ";
  }std::cerr << std::endl;
  
  std::cerr << "a_accum:" << std::endl;
  for(long long int i = 0; i < N; i++){
    std::cerr << a_accum[i] << " ";
  }std::cerr << std::endl;
  
  // solve problem
  std::vector<std::vector<long long int> > dp_table(N);
  for(long long int i = 0; i < N; i++){
    for(long long int j = 0; j < N; j++){
      dp_table[i].push_back(0);
    }
  }
  
  for(long long int l = 1; l < N; l++){
    for(long long int i = 0; i < N-l; i++){
      tmp = dp_table[i][i] + dp_table[i+1][i+l];
      for(long long int j = i+1; j < i+l; j++){
        tmp = std::min(tmp, dp_table[i][j] + dp_table[j+1][i+l]);
      }
      tmp += section_sum(a_accum, i, i+l);
      dp_table[i][i+l] = tmp;
    }
  }
  
  std::cerr << "Answer:" << std::endl;
  std::cout << dp_table[0][N-1] << std::endl;
  
  return 0;
}

long long int section_sum(std::vector<long long int> accumulated_sum, long long int i, long long int j){
  if(i == 0){
    return accumulated_sum[j];
  }
  else{
    return accumulated_sum[j] - accumulated_sum[i-1];
  }
}


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

int main() {
    int n;
    cin >> n;
    vector<int> v;
    map<int,int> cnt;
    for (int i = 0; i < n; i++) {
        int a;
        cin >> a;
        v.push_back(a);
        cnt[a]++;
    }
    sort(v.begin(), v.end());
    reverse(v.begin(), v.end());

    for (int i = v[0]; i >= (v[0] + 3) / 2; i--) {
        if (cnt[i] < 2) {
            cout << "Impossible" << endl;
            return 0;
        }
    }

    for (int i = (v[0] - 1) / 2; i >= 1; i--) {
        if (cnt[i] != 0) {
            cout << "Impossible" << endl;
            return 0;
        }
    }

    if (v[0] & 1) {
        if (cnt[(v[0] + 1) / 2] != 2) {
            cout << "Impossible" << endl;
            return 0;
        }
    } else {
        if (cnt[(v[0] + 1) / 2] != 1) {
            cout << "Impossible" << endl;
            return 0;
        }
    }
    cout << "Possible" << endl;
    return 0;
}


Measured memory_bytes: 256
from collections import deque
import sys
sys.setrecursionlimit(10**7)
N = int(input())
ab = [list(map(int,input().split())) for i in range(N-1)]
E = [[] for _ in range(N+1)]
for i in range(N-1):
    E[ab[i][0]].append(ab[i][1])
color = [0]*(N+1)

start = 1
q = deque([start])
while(q):
    v = q.pop()
    c = 0
    for u in E[v]:
        c += 1 + (c + 1 == color[v])
        color[u] = c
        q.append(u)
print(max(color))
for i in range(N-1):
    print(color[ab[i][1]])

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

int n;
long long a[505][505];

long long lcm(long long a,long long b) {
	return a / __gcd(a, b) * b;
}
void build() {
	int ptr = 2;
	vector<int> primes;
	while (primes.size() < 1007) {
		bool prime = 1;
		for (int i = 2; i * i <= ptr; ++i) {
			if (ptr % i == 0) {
				prime = 0;
				break;
			}
		}
		if (prime) primes.push_back(ptr);
		ptr++;
	}
	for (int i = 0; i < 500; ++i) {
		for (int j = 0; j < 500; ++j) {
			if (!(i + j & 1)) {
				a[i][j] = primes[(i + j) / 2] * primes[(i - j) / 2 + 752];
			}
		}
	}
	for (int i = 0; i < 500; ++i) {
		for (int j = 0; j < 500; ++j) {
			if (i + j & 1) {
				a[i][j] = 1;
				if (i > 0) a[i][j] = lcm(a[i][j], a[i - 1][j]);
				if (j > 0) a[i][j] = lcm(a[i][j], a[i][j - 1]);
				if (i < 499) a[i][j] = lcm(a[i][j], a[i + 1][j]);
				if (j < 499) a[i][j] = lcm(a[i][j], a[i][j + 1]);
				a[i][j]++;
			}
		}
	}
}

int main() {
	ios_base::sync_with_stdio(false);
	build();
	cin >> n;
	for (int i = 0; i < n; ++i) {
		for (int j = 0; j < n; ++j) {
			cout << a[i][j] << ' ';
		}
		cout << '\n';
	}
}


Measured memory_bytes: 5120
use std::cmp;

fn main() {
    let mut stdin = String::new();
    std::io::Read::read_to_string(&mut std::io::stdin(), &mut stdin).unwrap();
    let mut stdin = stdin.split_whitespace();
    let mut get = || stdin.next().unwrap();
    macro_rules! get {
        ($t:ty) => {
            get().parse::<$t>().unwrap()
        };
        () => {
            get!(i64)
        };
    }

    let (n, k) = (get!(), get!());
    let a = (n / k + 1) * k - n;
    println!("{}", cmp::min(a, k - a));
}


Measured memory_bytes: 4352
#include<bits/stdc++.h>
using namespace std;
int main() {
	long long k;
	cin>>k;
	queue<long long> q;
	for (int i=1;i<10;i++) q.push(i);
	while(!q.empty()){
		long long p=q.front();
		q.pop();
		k--;
		if (k==0){
			cout<<p<<endl;
			break;
		}
		for (long long i=(p%10)-1;i<=(p%10)+1;i++){
			if (i<0 || i>=10) continue;
			q.push(p*10+i);
		}
	}
	return 0;
}

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

int main() {
	int n;

	while(cin >> n, n) {
		int a[128];
		bool flag = true;
		int ans = 0;

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

		while(flag) {
			flag = false;
			for(int i = 0; i < n - 1; i++) {
				if(a[i] > a[i + 1]) {
					int tmp = a[i];
					a[i] = a[i + 1];
					a[i + 1] = tmp;
					ans++;
					flag = true;
				}
			}
		}
		cout << ans << endl;
	}

	return 0;
}

Measured memory_bytes: 1160
use std::io;
use std::cmp;

// read a line(without line feed)
fn read_line() -> String {
    let mut in_str = String::new();
    io::stdin().read_line(&mut in_str).unwrap();
    return in_str.trim().to_string();
}

// read wods on a line
pub fn read_words_in_line() -> Vec<String> {
    let s = read_line();
    return s.split_whitespace().map(|x| x.to_string()).collect::<Vec<String>>()
}

// read type t on a line
pub fn read_t_in_line<T : std::str::FromStr>() -> Vec<T> {
    let mut v : Vec<T> = Vec::new();
    for e in read_words_in_line().iter().map(|x| x.parse::<T>()) {
        if let Ok(r) = e {
            v.push(r);
        }
        else{
            return Vec::new();
        }
    }
    return v;
}

// sort slice
pub fn sort<T : std::cmp::Ord>(slice : &mut [T]) {
    slice.sort();
}
// sort slice by reverse order
pub fn sort_rev<T : std::cmp::Ord>(slice : &mut [T]) {
    slice.sort_by(|x, y| y.cmp(x));
}

pub fn min<T : std::cmp::Ord>(a : T, b : T) -> T{
    return cmp::min(a, b);
}

pub fn max<T : std::cmp::Ord>(a : T, b : T) -> T{
    return cmp::max(a, b);
}



fn main(){
    const MAX_N : usize = 100010;

    let v = read_t_in_line::<i32>();
    let(n, h) = (v[0] as usize, v[1]);
    let mut aa = [0 ; MAX_N];
    let mut bb = [0 ; MAX_N];

    for i in 0..n {
        let v2 = read_t_in_line::<i32>();
        let (a, b) = (v2[0], v2[1]);
        aa[i] = a;
        bb[i] = b;
    }

    // aaとbbをそれぞれsort
    // bbを大きい順番に使う, aaは一番大きい値しか利用しない
    let a_slice : &mut [i32] = &mut aa[0..n]; 
    sort_rev(a_slice);
    let b_slice : &mut [i32] = &mut bb[0..n]; 
    sort_rev(b_slice);

    let a_max = a_slice[0];
    let mut min_count = (h + a_max - 1) / a_max;
    let mut b_sum = 0;
    for i in 0..b_slice.len() {
        b_sum += b_slice[i];
        if b_sum >= h {
            min_count = min(min_count, i as i32 + 1);
            break;
        }
        else{
            min_count = min(min_count, ((h - b_sum) + a_max - 1) / a_max + i as i32 + 1);
        }
    }

    println!("{}", min_count);


}


Measured memory_bytes: 5116
#include <stdio.h>
#include <algorithm>
#include <stdlib.h>
#include <string.h>
#include <queue>
#define rep(i,n) for(int i = 0; i < n; ++i)
#define rrep(i,n) for(int i = 1; i <= n; ++i)
using namespace std;
typedef pair<int,int> P;
const int INF = 1000000000;

int main(){
	int n;
	
	while (true){
		scanf("%d",&n);
		if(n==0)break;
		int scr=0,a,b=0,c=0; 
		rep(i,n){
			scanf("%d",&a);
			if(a>0)b++;
			if(a>1)c=1;
			}
	if(c==1)scr = b+1;
		
	if(scr>0)printf("%d\n",scr);
	else printf("NA\n");
	}
	return 0;
}

Measured memory_bytes: 1040
N = int(input())

H = list(map(int, input().split()))
H.append(1000000006)
max_ = 0
now = 0
for index in range(N):
    if H[index] >= H[index + 1]:
        now += 1
    else:
        max_ = max(max_, now)
        now = 0

print(max_)

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

#define _GLIBCXX_DEBUG

int main() {
  int h, w;
  string word;
  
  cin >> h >> w;
  
  for(int i = 0; i < w+2; i++)
    cout << "#";
  cout << endl;
  
  for(int i = 0; i < h; i++){
    cin >> word;
    cout << "#" << word << "#" << endl;
  }
  
  for(int i = 0; i < w+2; i++)
    cout << "#";
  cout << endl;
}

Measured memory_bytes: 256
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())


N,M,K=map(int,input().split())
retu_n=[0]*N
block_n=[0]*N
uf = UnionFind(N)


for m in range(M):
  a,b=map(int,input().split())
  retu_n[a-1] +=1
  retu_n[b-1] +=1
  uf.union(a-1,b-1)
  
  
for k in range(K):
  c,d=map(int,input().split())
  if uf.same(c-1, d-1):
    block_n[c-1] += 1
    block_n[d-1] += 1
    
  
for n in range(N):
  print(uf.size(n)-retu_n[n]-block_n[n]-1, end=" ")


Measured memory_bytes: 9372
#include<iostream>
#include<string>
#include<cmath>
//#include<array>
#include<algorithm>
//#include<deque>
#include<vector>
//#include<utility>
//#include<set>
//#include<map>
//#include<list>

using namespace std;
using LLI = long long int;
vector<int>dir_x = {0,0,1,1,1,-1,-1,-1};
vector<int>dir_y = {1,-1,1,0,-1,1,0,-1};
vector<int>dir_x2 = {0,0,1,-1};
vector<int>dir_y2 = {1,-1,0,0};

//class UnionFind {
//public:
//	vector<int>data;
//	UnionFind(int size) :data(size, -1) {};
//	bool unionset(int x, int y) {
//		x = root(x), y = root(y);
//		if (x != y) {
//			if (data[y] < data[x]) {
//				swap(x, y);
//			}
//			data[x] += data[y];
//			data[y] = x;
//		}
//		return x != y;
//	}
//	bool findset(int x, int y) {
//		return root(x) == root(y);
//	}
//	int root(int x) {
//		return data[x] < 0 ? x : data[x] = root(data[x]);
//	}
//	int size(int x) {
//		return -data[root(x)];
//	}
//};

//LLI gcd(LLI x, LLI y) {
//	LLI tmp, r;
//	if (x < y) {
//		tmp = x;
//		x = y;
//		y = tmp;
//	}
//	r = x % y;
//	while (r != 0) {
//		x = y;
//		y = r;
//		r = x % y;
//	}
//	return y;
//}
//LLI lcm(LLI x,LLI y) {
//	return x / gcd(x,y) * y;
//}

//long nCr(int n,int r) {
//	long ans = 1;
//	for (int i = n; i > n - r;i--) {
//		ans = ans * i;
//	}
//	for (int i = 1; i < r + 1;i++) {
//		ans = ans / i;
//	}
//	return ans;
//}

//const int n_max = 8;
//array<array<bool, n_max>, n_max>graph;
//int dfs(int v,int N,array<bool,n_max>visited) {
//	int ret = 0;
//	bool all_visited = true;
//	for (int i = 0; i < N;i++) {
//		if (visited[i] == false) {
//			all_visited = false;
//		}
//	}	
//	if (all_visited) {
//		return 1;
//	}
//	for (int i = 0; i < N;i++) {
//		if (graph[v][i] == false) {
//			continue;
//		}
//		if (visited[i] == true) {
//			continue;
//		}
//		visited[i] = true;
//		ret += dfs(i,N,visited);
//		visited[i] = false;
//	}
//	return ret;
//}

//vector<vector<int>>sub;
//int dfs(int id) {
//	if (sub[id].size() == 0) {
//		return 1;
//	}
//	int minP = (int)1e9;
//	int maxP = 0;
//	for (int i : sub[id]) {
//		int P = dfs(i);
//		minP = min(minP, P);
//		maxP = max(maxP, P);
//	}
//	return minP + maxP + 1;
//}

LLI N;

LLI dfs(LLI num,bool three,bool five,bool seven) {
	if (num > N) {
		return 0;
	}
	LLI res = 0;
	if (three && five && seven) {
		res++;
	}
	res += dfs(num * 10 + 3,true,five,seven);
	res += dfs(num * 10 + 5,three,true,seven);
	res += dfs(num * 10 + 7,three,five,true);
	return res;
}

int main(void) {
	cin >> N;
	cout << dfs(0,0,0,0) << endl;
}

Measured memory_bytes: 256
fun main(args: Array<String>) {

    val (N) = readInts()
    val set = mutableSetOf<Int>()

    (1 .. N).forEach {
        val i = readLine()!!.toInt()

        if (set.contains(i)) set.remove(i)
        else set.add(i)
    }

    println(set.count())
}

fun readInts(): List<Int> = readStrings().map { it.toInt() }
fun readStrings(): List<String> = readLine()!!.split(" ")

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

int main ()
{
    int N;
    long M;
  	cin >> N >> M;
    long A[100010];
    A[0]=0;
    long tmp;
    long long cnt=0;
    map<long,int>mp;
    for(int i=0;i<N;i++){
        cin >> tmp; 
        A[i+1]=(A[i]+tmp)%M;
    }
    mp[0]=1;
    for(int r=1;r<=N;r++){
        cnt+=mp[A[r]];
        mp[A[r]]++;
    }
    cout << cnt << endl;
    return 0;
}












Measured memory_bytes: 4992
#include <bits/stdc++.h>
using namespace std;
#define IOS ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep1(i,n) for(ll i=1;i<=n;i++)
#define rep_start(a,i,n) for(ll i=a;i<=n;i++)
#define rev(i,n) for(ll i=n-1;i>=0;i--)
#define rev1(i,n) for(ll i=n;i>0;i--)
#define sz(a) int((a).size())
#define all(c) c.begin,c.end()
#define tr(c,i) for(typeof(c).begin() i=c.begin; i!=c.end(); i++)
#define present(c,x) (c.find(x)!=c.end())
#define cpresent(c,x) (find(all(c),x)!=c.end())
#define pb push_back
#define F first
#define S second
#define INF 1e9+7
typedef long long int ll;
typedef vector<int> vi;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<vi> vvi;
typedef pair<int,int> ii;
typedef vector<ii> vii;

ll m=1e9+7;

ll pow(ll a, ll b){
    ll res = 1;
    a %= m;
    while(b){
        if(b&1) res = (res * a) % m;
        a *= a; a %= m;
        b >>= 1;
    }
    return res;
}
void solve(){
    ll n,k;
    cin>>n>>k;
    ll gcd[k+1];
    rep1(i,k) gcd[i]=pow(k/i,n)%m;
    rev1(i,k) for(ll j=2*i;j<=k;j+=i) gcd[i]=(gcd[i]-gcd[j]+m)%m;
    //rep1(i,k) cout<<i<<" "<<gcd[i]<<"\n";
    ll ans=0;
    rep1(i,k) ans=ans+(gcd[i]*i)%m;
    cout<<ans%m;
}

signed main() {
    // your code goes here
    IOS
    ll t=1;
    //cin>>t;
    rep1(i,t){
        solve(); 
    }
}

Measured memory_bytes: 4376
#include <bits/stdc++.h>
 
using namespace std;
 
int n;
int a[int(1e6)];
int res;
 
int main() {
	cin >> n;
	for (int i = 1; i <= 2 * n; ++i) {
		cin >> a[i];
	}
	sort(a + 1, a + 2 * n + 1);
	for (int i = 1; i <= 2 * n; i += 2) {
		res += a[i];
	}
	cout << res << endl;
}

Measured memory_bytes: 384
import java.io.*;
import java.util.*;
//import java.util.stream.*;
//import java.math.*;

public class Main {

    public static int gcd(int a, int b) {
        return (b == 0) ? a : gcd(b, a % b);
    }

    public static void main(String[] args) throws IOException {

        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
        Scanner sc = new Scanner(System.in);
        //forl(n, array, sc);
        int h = sc.nextInt();
        int w = sc.nextInt();
        for (int i = 0; i < h + 2; i++) {
            if (i == 0 || i == h + 1) {
                for (int j = 0; j < w + 2; j++) {
                    System.out.print("#");
                }
            } else {
                System.out.print("#" + sc.next() + "#");
            }
            System.out.println();
        }
        bw.flush();
    }

    public static void forl(int n, int[] array, Scanner sc) {
        for (int i = 0; i < n; i++) {
            array[i] = sc.nextInt();
        }
    }
}


Measured memory_bytes: 23508
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int maxn=1e5+7;
int a[maxn];
int main(){
    int n,m,p,x,sum=0,ans;
    cin>>n;
    for(int i=1;i<=n;i++){
        cin>>a[i];
        sum+=a[i];
    }
    cin>>m;
    for(int i=1;i<=m;i++){
        cin>>p>>x;
        ans=sum+x-a[p];
        cout<<ans<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int N = 2e5 + 10;
#define fi first
#define se second
#define pb push_back
#define mp make_pair
int k;
char a[N];
int main() {
  ios::sync_with_stdio(false);
  cin>>k>>a+1;
  int n=strlen(a+1);
  if(k<n){
  	for(int i=1;i<=k;i++)cout<<a[i];
  		cout<<"...";
  }else{
  	cout<<a+1;
  }
 	return 0;
}

Measured memory_bytes: 3616
// Example program
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i = a; i < b; i++)
typedef long long ll;
typedef vector<ll> vi;
typedef pair<ll,ll> ii;
typedef vector<ii> vii;


int main() {
    int n,m;
    cin >> n >> m;
    string s;
    cin >> s;
    int flag = 1;
    if(s.size() != n+m+1) {
        flag = 0;
    } else {
        if(s[n] != '-') flag = 0;
        else {
            rep(i,0,s.size()) {
                if(i == n) continue;
                int num = s[i]-'0';
                if(num < 0 || num > 9) flag = 0;
            }    
        }
    }
    if(flag) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 256
import java.math.BigInteger;
import java.util.*;

public class Main {
	String s;
	int n;
	boolean []used;
	ArrayList<String[]> list, list2;
	HashMap<String, Integer> set;
	
	private void dfs(int deep){
		if(deep == n){
			StringBuilder sb1 = new StringBuilder();
			StringBuilder sb2 = new StringBuilder();
			for(int i = 0; i < n; i++){
				if(used[i]){
					sb1.append(s.charAt(i));
				}
				else{
					sb2.append(s.charAt(i));
				}
			}
			list.add(new String[]{sb1.toString(), sb2.reverse().toString()});
			return;
		}
		used[deep] = true;
		dfs(deep+1);
		used[deep] = false;
		dfs(deep+1);
	}
	private void dfs2(int deep){
		if(deep == n){
			StringBuilder sb1 = new StringBuilder();
			StringBuilder sb2 = new StringBuilder();
			for(int i = 0; i < n; i++){
				if(used[i]){
					sb1.append(s.charAt(2 * n - 1 - i));
				}
				else{
					sb2.append(s.charAt(2 * n - 1 - i));
				}
			}
			
			String s1 = sb1.reverse().toString();
			String s2 = sb2.toString();
			String s = s1 + " " + s2;
			if(set.containsKey(s)){
				set.put(s, set.get(s) + 1);
			}
			else{
				set.put(s, 1);
			}
			return;
		}
		used[deep] = true;
		dfs2(deep+1);
		used[deep] = false;
		dfs2(deep+1);
	}
	
	private void doit(){
		Scanner sc = new Scanner(System.in);
		while(sc.hasNext()){
			n = sc.nextInt();
			s = sc.next();
			used = new boolean[n];
			list = new ArrayList<>();
			dfs(0);
			used = new boolean[n];
			set = new HashMap<>();
			dfs2(0);
			long count = 0;
			for(int i = 0; i < list.size(); i++){
				String s = list.get(i)[1] + " " + list.get(i)[0];
				if(set.containsKey(s)){
					count += set.get(s);
				}
			}
			System.out.println(count);
		}
	}

	private void debug(Object... o) {
		System.out.println("debug = " + Arrays.deepToString(o));
	}

	public static void main(String[] args) {
		new Main().doit();
	}

}


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

int main() {
  int n;
  cin >> n;
  vector<int> w(n);
  for (int i = 0; i < n; i++) {
    cin >> w[i];
  }
  int dif=999990;
  for(int i = 1; i < n; i++){
    int r = 0,l=0;
    for (int j = 0; j < i; j++) l += w[j];
    for (int j = i; j < n; j++) r += w[j];
    dif = min(dif, abs(l-r));
  }

  cout << dif;
  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

typedef long long ll;

int main(void){
  int i, j, n;
  int nj_minus, nj_plus;
  int t[102];
  ll ans, dp[102][22];

  scanf("%d", &n);

  for(i = 0; i < n; i++){
    scanf("%d", &t[i]);
  }

  //DPツ配ツ療アツ渉可甘コツ可サ
  for(i = 0; i < 102; i++){
    for(j = 0; j < 22; j++){
      dp[i][j] = 0;
    }
  }

  //ツ債カツ陛督づ個個仰嘉環づーDPツづ可づヲツづィツ全ツづ?青カツ青ャツつキツづゥ
  dp[0][t[0]] = 1;

  for(i = 0; i < n - 2; i++){
    for(j = 0; j <= 20; j++){
      if(dp[i][j] == 0) continue;

      nj_minus = j - t[i + 1];
      nj_plus = j + t[i + 1];

      if(0 <= nj_minus){
        dp[i + 1][nj_minus] += dp[i][j];
      }
      if(nj_plus <= 20){
        dp[i + 1][nj_plus] += dp[i][j];
      }
    }
  }

  //ツ債カツ陛督づ個計ツ算ツづ可づヲツづィツ仰?づ淞つスt[n - 1]ツづ可づ按づゥツ篠ョツづ個青板つェツ督堋つヲツづ?づ按づゥ
  printf("%lld\n", dp[n - 2][t[n - 1]]);

  return 0;
}

Measured memory_bytes: 0
#include<cstdio>
#include<list>
using namespace std;

int main() {
    list<int> L;
    int n,num;
    char order[100];
    scanf("%d", &n);
    
    for(int i=0;i<n;i++){
        scanf("%s", order);
        
        if(order[0] == 'i'){
            scanf("%d", &num);
            L.push_front(num);
        }else if(order[6] == 'F'){
            L.pop_front();
        }else if(order[6] == 'L') {
            L.pop_back();
        }else if(order[0] == 'd') {
            scanf("%d", &num);
            for(list<int>::iterator it=L.begin();it!=L.end();it++){
                if(*it == num){
                    L.erase(it);
                    break;
                }
            }
        }

    }
    int i=0;
    for(list<int>::iterator it=L.begin();it!=L.end();it++){
        if(i++) printf(" ");
        printf("%d", *it);
    }
    printf("\n");
}


Measured memory_bytes: 34032
S=input()
if 0<int(S[:2])<13:
  if 0<int(S[2:])<13:
    print("AMBIGUOUS")
  else:
    print("MMYY")
else:
  if 0<int(S[2:])<13:
    print("YYMM")
  else:
    print("NA")

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

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

ll MOD = 1e9+7;

class mint{
    ll n;
public:
    mint(ll m = 0){
        n = ((m % MOD) + MOD) % MOD;
    }
    bool operator==(const mint& m){
        return n == m.n;
    }
    mint operator-() const {
        return mint(-n);
    }
    mint& operator+=(const mint& m){
        n += m.n;
        if(n >= MOD) n -= MOD;
        return *this;
    }
    mint& operator-=(const mint& m){
        n += MOD - m.n;
        if(n >= MOD) n -= MOD;
        return *this;
    }
    mint& operator*=(const  mint& m){
        n *= m.n;
        n %= MOD;
        return *this;
    }
    mint operator+(const mint& m) const{
        mint res(*this);
        res += m;
        return res;
    }
    mint operator-(const mint& m) const{
        mint res(*this);
        res -= m;
        return res;
    }
    mint operator*(const mint& m) const{
        mint res(*this);
        res *= m;
        return res;
    }
    mint pow(ll t) const{
        if(t == 0) return mint(1);
        mint m = pow(t>>1);
        m *= m;
        if((t & 1) == 1) m *= *this;
        return m;
    }
    // for prime modulo
    mint inv() const{
        return pow(MOD-2);
    }
    mint& operator/=(const mint& m){
        (*this) *= m.inv();
        n %= MOD;
        return *this;
    }
    mint operator/(const mint& m) const{
        mint res(*this);
        res /= m;
        return res;
    }
    friend ostream& operator<<(ostream& os, const mint& m){
        os << m.n;
        return os;
    }
};

ll N;
ll X[100000];
mint f[100000];
mint g[100000];

int main(){
    cin >> N;
    for(int i=0;i<N;i++) cin >> X[i];
    f[0] = mint(1);
    for(int i=1;i<N;i++) f[i] = f[i-1] * mint(i);
    f[0] = f[N-1];
    for(int i=1;i<N;i++) f[i] = f[0] / mint(i);
    for(int i=2;i<N;i++) f[i] += f[i-1];
    vector<ll> v;
    for(int i=1;i<N;i++) v.push_back(X[i]-X[i-1]);
    mint ans(0);
    for(int i=1;i<N;i++){
        ans += f[i] * v[i-1];
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 6620
# D - Score Attack
import sys
sys.setrecursionlimit(10 ** 9)

import numpy as np
from heapq import heappush, heappop

N, M, = map(int, input().split())
graph = [[] for _ in range(N+1)] # graph[0]は使わない

for _ in range(M):
    a, b, c = map(int, input().split())
    graph[a].append((b, -c)) # ヒープ構造を使うため重みはマイナスの値

def dijkstra(start, co):
    INF = float('inf')
    dist = [INF] * (N+1) # dist[0]は使わない
    dist[start] = 0
    que = [(0, start, co)] # queではscoreを先頭に
    while que:
        score, place, count = heappop(que) # placeは現在地
        if score > dist[place] or count > 2000: # 前来た時より点数が悪いか、無限ループしている場合continue
            continue
        for next_node, weight in graph[place]:
            score2 = score + weight
            if next_node == N and count > 1000: # いくらでも大きくなる場合
                print('inf')
                exit()
            if dist[next_node] > score2 and count < 2000: # 点数が良くなるなら、データを更新
                dist[next_node] = score2
                heappush(que, (score2, next_node, count+1))
    return dist

d1 = np.array(dijkstra(1, 0))
print(-int(d1[N]))

Measured memory_bytes: 12748
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))

s = b[a[0] - 1]

for i in range(1, n):
    s += b[a[i] - 1]
    if (a[i] - a[i - 1]) == 1:
        s += c[a[i] - 2]

print(s)


Measured memory_bytes: 3064
#include <stdio.h>
int main()
{
    int m, f, r;
    while (scanf("%d %d %d", &m, &f, &r), m + f + r != -3)
    {
        if (m == -1 || f == -1)
            printf("F\n");
        else if (m + f >= 80)
            printf("A\n");
        else if (m + f >= 65)
            printf("B\n");
        else if (m + f >= 50)
            printf("C\n");
        else if (m + f >= 30)
        {
            if (r >= 50)
                printf("C\n");
            else
                printf("D\n");
        }
        else
            printf("F\n");
    }
    return 0;
}


Measured memory_bytes: 2088