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

int main(){
    int n,m=0,im;
    cin>>n;
    vector<int> a(n);
    for(int i=0;i<n;i++){
        cin>>a[i];
        if(m<a[i]){
            m=a[i];
            im=i;
        }
    }
    sort(a.begin(),a.end(),greater<int>());
    for(int i=0;i<n;i++) cout<<(i!=im?m:a[1])<<endl;
    return 0;
}

Measured memory_bytes: 2432
n = int(input())

X = [int(x) for x in range(1,n+1,2)]

answer = []
cnt = 0
for x in X:
    answer = []
    for i in range(1,n+1):
        if x % i == 0:
            answer.append(i)

    if len(answer) == 8 :
        cnt += 1 
print(cnt)

Measured memory_bytes: 3064
#include "bits/stdc++.h"
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size)
#define MOD 1000000007
const long long mod = 1e9+7;
typedef vector<long long> Vl;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<Vl> VVl;
typedef pair<int, int> PII;
typedef long long ll;

int main(){
    int a,b,c,d,n;
    string s,s1;
    cin >> n >> a;
    c = n / 500;    
    if (n - c * 500 - a <= 0)  cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
} 

Measured memory_bytes: 256
#pragma region
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <vector>
#include <map>
#include <queue>
#include <stack>
#include <set>
#include <list>
#include <iomanip>
#include <cstdint>
#include <bitset>
#include <fstream>
#include <cassert>
#pragma region ACL
#include <atcoder/fenwicktree>
//#include <atcoder/math>
#include <atcoder/string>
#include <atcoder/scc>
#include <atcoder/segtree>
#pragma endregion

using namespace std;
using namespace atcoder;
typedef long long ll;
//#define rep(i, s, e) for (int(i) = (s); (i) < (e); ++(i))
#define rep(i, e) for (int(i) = 0; (i) < (e); ++(i))
#define rrep(i, s) for (int(i) = (s) - 1; (i) >= 0; --(i))
#define all(x) x.begin(),x.end()

#pragma region UnionFind
struct UnionFind
{
	vector<int> par;

	UnionFind(int n) : par(n, -1) {}
	void init(int n) { par.assign(n, -1); }

	int root(int x)
	{
		if (par[x] < 0) return x;
		else return par[x] = root(par[x]);
	}

	bool issame(int x, int y)
	{
		return root(x) == root(y);
	}

	bool merge(int x, int y)
	{
		x = root(x); y = root(y);
		if (x == y) return false;
		if (par[x] > par[y]) swap(x, y);
		par[x] += par[y];
		par[y] = x;
		return true;
	}

	int size(int x)
	{
		return -par[root(x)];
	}
};
#pragma endregion
#pragma region GCD
int gcd(int a, int b)
{
	if (a%b == 0)return b;
	return gcd(b, a%b);
}
#pragma endregion
#pragma region chmin
template<class T> inline bool chmin(T& a, T b)
{
	if (a > b)
	{
		a = b;
		return true;
	}
	return false;
}
#pragma endregion
#pragma region chmax
template<class T> inline bool chmax(T& a, T b)
{
	if (a < b)
	{
		a = b;
		return true;
	}
	return false;
}
#pragma endregion
#pragma endregion


int main()
{
	int n, m; cin >> n >> m;
	UnionFind uf(n);
	rep(i, m)
	{
		int a, b; cin >> a >> b;
		--a, --b;
		uf.merge(a, b);
	}
	map<int, bool> mp;
	int res = 0;
	rep(i, n)
	{
		if (!mp[uf.root(i)])++res;
		mp[uf.root(i)] = true;
	}
	cout << res - 1 << endl;
}

Measured memory_bytes: 7520
#include <stdio.h>

int value(double);

main(){
  int size[6];
  int n, i, j;
  double input;
  
  while(1){
    if(scanf("%d", &n)==EOF) break;
    
    for(i=0;i<6;i++){
      size[i]=0;
    }
    
    for(i=0;i<n;i++){
      scanf("%lf", &input);
      size[value(input)-1]++;
    }

    for(i=0;i<6;i++){
      printf("%d:", i+1);
      for(j=0;j<size[i];j++){
	printf("*");
      }
      printf("\n");
    }
  }
  return 0;
}

int value(double in){
  if(in<165.0) return 1;
  else if(in<170.0) return 2;
  else if(in<175.0) return 3;
  else if(in<180.0) return 4;
  else if(in<185.0) return 5;
  else return 6;
}

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

typedef long long ll;
#define MOD = 1000000007;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define ALL(a) begin(a),end(a)
#define COUNTOF(a) (sizeof(a)/sizeof(a[0]))
template<class T> istream& operator >> (istream& s, vector<T>& v)
{ for (T& x: v) { s >> x; } return s;}
template<class T> void cout_v(const vector<T>& c)
{ for (int i = 0; i < c.size(); i++) cout << c[i] << endl; }
template<class T> void cout_h(const vector<T>& c)
{ for (int i = 0; i < c.size(); i++) cout << c[i] << (i==c.size()-1?"\n":" "); }
template<class T> inline bool chmin(T& a, T b) {return a>b?a=b,true:false;}
template<class T> inline bool chmax(T& a, T b) {return a<b?a=b,true:false;}
template<class T> inline bool is_overlap(const T& as, const T& ae, const T& bs, const T& be)
{ return bs <=ae && as <= be; }
#define SP << " " <<
#define FMT(a) #a<<":"<<a 
#define FMT2(a,b) #a<<":"<<a<<", "<<#b<<":"<<b 
#define FMT3(a,b,c) #a<<":"<<a<<", "<<#b<<":"<<b<<", "<<#c<<":"<<c 
#define FMT4(a,b,c,d) #a<<":"<<a<<", "<<#b<<":"<<b<<", "<<#c<<":"<<c<<", "<<#d<<":"<<d 
#define ANS(a) cout<<a<<endl
void yes(bool f){cout<<(f?"yes":"no")<<endl;}
void Yes(bool f){cout<<(f?"Yes":"No")<<endl;}
void YES(bool f){cout<<(f?"YES":"NO")<<endl;}

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

    int s; cin >>s;

    int ans = 0;
    int a, prev_a = s;
    set<int> history;
    history.insert(s);
    for (int m = 2;; m++) {
        a = prev_a % 2 == 0 ? prev_a / 2 : 3 * prev_a + 1;
        //cout << FMT(a) << endl;
        if (history.count(a)) {
            ans = m;
            break;
        }
        history.insert(a);
        prev_a = a;
    }

    cout << ans << endl;
}


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

int main(){
  int a[15][15];
  int n,x,y,i=1;

  cin >>n;

  while (n!=0){
    for (int j=0;j<n*n;j++)a[j/n][j%n]=-1;
    
    x=n/2;
    y=n/2+1;
    i=1;
    while(i<=n*n){
      if (x>=n){
	x=0;
	continue;
      }else if (x<0){
	x=n-1;
	continue;
      }else if (y>=n){
	y=0;
	continue;
      }else if (y<0){
	y=n-1;
	continue;
      }
      //      cout << i<<"("<<x<<","<<y<<")";
      if (a[y][x]==-1){
	//	cout <<"-";
	a[y][x]=i;
	x++;
	y++;
	i++;
      }else{
	//	cout <<"*("<<a[y][x]<<")**";
	x--;
	y++;
      }
    }

    for (y=0;y<n;y++){
      for (x=0;x<n;x++)
	printf("%4d", a[y][x]);
      cout << endl;
    }
    cin >> n;
  }
  return 0;
}
  

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

const int MOD = 1e9 + 7;
const int iINF = 1e9;
const long long int llINF = 1e18;
const double PI = acos(-1.0);
#define rep(i, n) for (int i = 0; i < (n); i++)
#define REP(i, init, n) for (int i = init; i < (n); i++)

using namespace std;
using ll = long long int;
using P = pair<int, int>;
using T = tuple<int, int, int>;
using edge = struct
{
    int to;
    int cost;
};

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

ll dp[110][30];

int main()
{   
    int N;
    cin >> N;
    vector<int> num(N);

    rep(i, N) cin >> num[i];

    dp[0][num[0]] = 1;

    rep(i, N - 1)
    {
        rep(j, 21)
        {
            if(dp[i][j] == 0) continue;

            int plus = j + num[i + 1], minus = j - num[i + 1];

            if(0 <= plus && plus <= 20)
                dp[i + 1][plus] += dp[i][j];
            
            if(0 <= minus && minus <= 20)
                dp[i + 1][minus] += dp[i][j];
        }
    }

    cout << dp[N - 2][num[N - 1]] << endl;
    
    return 0;
}


Measured memory_bytes: 3116
#include <iostream>
#include <algorithm>
#include <vector> //動的配列
#include <string>
#include <list> //双方向リスト
#include <map> //連想配列
#include <set> //集合
#include <stack>
#include <queue>
#include <deque>
#include <cmath>
#include <bitset>
#include <numeric>
#include <tuple>




typedef long long ll;


using namespace std;

typedef pair<int, int> P;
#define FOR(i,a,b) for(int i=(int)(a) ; i < (int) (b) ; ++i )
#define rep(i,n) FOR(i,0,n)
#define sz(x) int(x.size())


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

// n次元配列の初期化。第２引数の型のサイズごとに初期化していく。
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

//小さい順から取り出すヒープ
//priority_queue<ll, vector<ll>, greater<ll> > pque1;




int main(){
    int n;
    string s;
    cin>>n>>s;
    int ans=1;
    for (int i=1;i<n;i++){
        if (s[i]!=s[i-1]) ans++;
        
    }
    
    cout<<ans<<endl;
    
    return 0;
}


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

using namespace std;

using ll = long long;
using ld = long double;
using P = pair<int, int>;
using vi = vector<int>;
using vl = vector<ll>;
ld EPS = 1e-12;
int INF = numeric_limits<int>::max() / 2;
int MOD = 1e9 + 7;

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

    double n, t, a;
    cin >> n >> t >> a;
    double temp = INF;
    int ans = 0;

    for(int i = 0; i < n; i++){
        double h;
        cin >> h;
        double now = t - 0.006 * h;
        if(abs(now-a) < temp){
            temp = abs(now-a);
            ans = i+1;
        }
    }
    

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


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

int main(){
	int length; cin>>length;
	char s[length];
	int total=0,max=total;
	for(int i=0;i<length;i++){
		cin>>s[i];
		if(s[i]=='I')total++;
		else total--;
		if(total>max)max=total;		
	}
	cout<<max;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
const int N = 3e5 + 11;
int f[N][3][3], n;
char s[N];
inline int A(int x, int y){
	return x + y - (x + y >= mod ? mod : 0);
}
inline int M(int x, int y){
	return 1LL * x * y % mod;
}
int main(){
	scanf("%s", s + 1);
	n = strlen(s + 1);
	f[0][0][0] = 1;
	for(int i = 0;i < n; i++){
		for(int x = 0;x <= 2; x++){
			for(int y = 0;y <= 2; y++){
				int F = f[i][x][y];
				if(s[i+1] != '0'){
					if(y == 0) f[i+1][x+(x!=2)][y] = A(f[i+1][x+(x!=2)][y], F);
					else f[i+1][x][y-1] = A(f[i+1][x][y-1], F);
				}
				if(s[i+1] != '1'){
					if(y == 2) f[i+1][x][y-1] = A(f[i+1][x][y-1], F);
					else f[i+1][x][y+1] = A(f[i+1][x][y+1], F);
				}
			}
		}
	}
	int ans = 0;
	for(int x = 0;x <= 2; x++){
		for(int y = x;y >= 0; y--)ans = A(ans, f[n][x][y]);
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 11136
#include <iostream>
#include <math.h>
#include <vector>
#include <map>
#include <stack>
#include <queue>
#include <set>
#include <algorithm>
#include <iomanip>
#include <string.h>

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define ALL(a)  (a).begin(),(a).end()

typedef long long lint;

using namespace std;

int main(){
  int X;
  cin>>X;
  int ans=1;
  FOR(i,2,X){
    if(i*i>X)continue;
    int p=1;
    while(p<=X)p*=i;
    p/=i;
    // cout<<p<<endl;
    if(p>ans)ans=p;
  }
  cout<<ans<<endl;
  return 0;
}


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

typedef long long LL;
typedef pair<int, int> PII;
typedef vector<int> VI;
#define MP make_pair
#define PB push_back
#define X first
#define Y second

#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
#define RFOR(i, b, a) for(int i = (b) - 1; i >= (a); --i)
#define ALL(a) a.begin(), a.end()
#define SZ(a) (int)((a).size())
#define FILL(a, value) memset(a, value, sizeof(a))
#define debug(a) cout << #a << " = " << a << endl;

const double PI = acos(-1.0);
const LL INF = 1e9 + 47;
const LL LINF = INF * INF;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

int main()
{
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	
	int a, b;
	cin >> a >> b;
	int x = 0, c = 1;
	while(c < b) c += a - 1, x++;
	cout << x;
	return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<iostream>
#define ll long long int
#define pb push_back
#define mk make_pair
#define mt make_tuple
#define ff first
#define ss second
#define mod 1000000007
using namespace std;
ll a[16][16];
ll dp[16][16];

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    string s;
    cin>>s;
    int ans=0;
    for(int i=0;i<s.length();i++)
    {
        if(s[i]=='+')
            ans++;
        else
            ans--;
    }
       cout<<ans<<endl;

}


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

int main() {
  string s;
  cin >> s;

  int count = 0;
  //int flg = 1;                                                                
  for(int i=0; i<s.size()/2; i++) {
    if(s[i] == s[s.size()-1-i]) {
      //flg = 0;                                                                
    }else {
      count += 1;
    }
  }

  cout << count << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int a,b;
  int c,d;
  cin >> a >> b >> c >> d;
  int n = a + b;
  int m = c + d;
  if(n == m)
  {
    cout << "Balanced" << endl;
  }
  else if(n > m)
  {
    cout << "Left" << endl;
  }
  else if(n < m)
  {
    cout << "Right" << endl;
  }
}


Measured memory_bytes: 3616
#include <bits/stdc++.h>
#define fast() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ll long long int
using namespace std;

int main() {
    fast();
    // ll t;
    // cin>>t;
    // while(t--)			
    // {
        
    // }
    map<string,ll>mp;
    ll n;
    cin>>n;
    for(int i=0;i<n;i++)
    {
        string s;
        cin>>s;
        mp[s]++;
    }
    cout<<"AC x "<<mp["AC"]<<endl;
    cout<<"WA x "<<mp["WA"]<<endl;
    cout<<"TLE x "<<mp["TLE"]<<endl;
    cout<<"RE x "<<mp["RE"]<<endl;
    
}


Measured memory_bytes: 3656
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<cassert>
#include<iostream>
#include<sstream>
#include<string>
#include<vector>
#include<queue>
#include<set>
#include<map>
#include<utility>
#include<numeric>
#include<algorithm>
#include<bitset>
#include<complex>
#include<stack>

using namespace std;

typedef long long Int;
typedef vector<int> vint;
typedef pair<int,int> pint;
typedef vector<string> vstring;
typedef vector<pint> vpint;

struct Edge{int to,from,cost;};

#ifdef DEBUG
#define debug cout
#else
stringstream __ss__;
#define debug __ss__
#endif

template<class T> void pv(T a, T b) { for (T i = a; i != b; ++i) debug << *i << " "; debug << endl; }
template<class T> void chmin(T &t, T f) { if (t > f) t = f; }
template<class T> void chmax(T &t, T f) { if (t < f) t = f; }
int in() { int x; scanf("%d", &x); return x; }

#define rep(i,n) for(int i=0;i<(n);++i)
#define repd(i,n) for(int i=(n)-1;i>=0;i--)
#define repn(i,m,n) for(int i=(m);i<=(n);++i)
#define repnd(i,m,n) for(int i=(n)-1;i>=(m);i--)
#define rep0(i,n) for(i=0;i<(n);++i)
#define all(n) n.begin(),n.end()
#define sz(n) ((int)(n).size())
#define IL for(;;)
#define MP make_pair
#define PB push_back
#define SS stringstream
#define X second
#define Y first
#define PUTLINE debug<<"LINE:"<<__LINE__<<endl;

const int INF = 2147483647/3;
const double EPS = 1e-10;
const double PI = acos(-1.0);

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

bool pr[1000000];
int np[1000000];

int main() {
	rep(i,1000000)pr[i]=true;
	pr[0]=pr[1]=false;
	rep(i,1000){
		if(pr[i]){
			int j;
			for(j=i*i;j<1000000;j+=i){
				pr[j]=false;
			}
		}
	}
	rep(i,999999)np[i+1]=np[i]+(pr[i+1]?1:0);
	int n,p,m,res;
	IL{
		cin>>n;
		if(n==0)break;
		res=-n;
		while(n--){
			cin>>p>>m;
			int a=max(0,p-m-1);
			int b=min(999999,p+m);
			res+=np[b]-np[a];
		}
		cout<<res<<endl;
	}
	return 0;
}

Measured memory_bytes: 0
#include <algorithm>
#include <cassert>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
//#include <regex>

/* g++ -g -std=c++0x */
/* g++ -g -std=c++11 */

using namespace std;

// freopen("input.txt", "rt", stdin);
// freopen("output.txt", "wt", stdout);

#define ALL(c)          (c).begin(), (c).end()
#define ALLR(c)         (c).rbegin(), (c).rend()
#define FOR(i,a,b)      for (int i=(a); i < (b); ++i)
#define FORR(i,a,b)     for (int i=(a); i > (b); --i)
#define FOR_ALL(i,c)    for (__typeof((c).begin()) i=(c).begin();   \
                             i != (c).end(); ++i)
#define FOR_ALLR(i,c)   for (__typeof((c).rbegin()) i=(c).rbegin(); \
                             i != (c).rend(); ++i)
#define SZ(array)       (sizeof(array)/sizeof(array[0]))
#define lc(x)           (x<<1)     /* 2*x */
#define rc(x)           (x<<1 | 1) /* 2*x+1 */
#define lowbit(x)       (x & (-x)) /* 0b10100 -> 0b100 */

typedef long long       LL;
typedef map<int,int>    MII;
typedef pair<int,int>   PII;
typedef set<int>        SI;
typedef vector<bool>    VB;
typedef vector<double>  VD;
typedef vector<int>     VI;
typedef vector<string>  VS;

/* check if a key is in container C */
template <class C>
inline bool in_(const typename C::key_type& k, const C& A)
{ return A.find(k) != A.end(); }
inline bool in_(const string& s, const string& S)
{ return S.find(s) != string::npos; }

int main()
{
/* #ifndef ONLINE_JUDGE */
/*     freopen("foo", "rt", stdin); */
/* #endif */
    std::ios::sync_with_stdio(false);

    int N;
    while (cin >> N) {
        cout << N/3 << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <functional>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <bitset>
#include <tuple>
#include <complex>
#include <cassert>
#include <exception>
#include <iomanip>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll> P;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<P> vp;
#define rep(i,a,n) for(ll i = (a);i < (n);i++)
#define per(i,a,n) for(ll i = (a);i > (n);i--)
#define lep(i,a,n) for(ll i = (a);i <= (n);i++)
#define pel(i,a,n) for(ll i = (a);i >= (n);i--)
#define clr(a,b) memset((a),(b),sizeof(a))
#define pb push_back
#define all(c) (c).begin(),(c).end()
#define sz size()
#define print(X) cout << (X) << "\n"
static const int INF = 1e+9+7;
static const ll INFL = 1e+18+7;
int n,m,l;
int p;
string s,t;
ll d[200010],dp[300][300];
char field[200][200];
int main(){
  stack<char> vec;
  cin >> s;
  rep(i,0,s.sz){
    if(s[i] == 'S')vec.push(s[i]);
    else{
      if(vec.empty() || vec.top() == s[i])vec.push(s[i]);
      else{
        if(vec.top() != s[i])vec.pop();
      }
    }
  }
  print(vec.sz);
  return 0;
}

Measured memory_bytes: 644
#include <iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<math.h>
using namespace std;
typedef long long ll;
#define int long long
typedef vector<int> VI;
typedef pair<int, int> pii;
typedef priority_queue<int> PQ;
template<class T>bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; }
#define fore(i,a) for(auto &i:a)
#define REP(i,n) for(int i=0;i<n;i++)
#define eREP(i,n) for(int i=0;i<=n;i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define eFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define SORT(c) sort((c).begin(),(c).end())
#define rSORT(c) sort((c).rbegin(),(c).rend())
#define LB(x,a) lower_bound((x).begin(),(x).end(),(a))
#define UB(x,a) upper_bound((x).begin(),(x).end(),(a))
#define INF 1000000000
#define LLINF 9223372036854775807
#define mod 1000000007
//vector<vector<int> > dp;
//vector<vector<vector<int> > > vvvi;
//dp=vector<vector<int> >(N, vector<int>(M,0));
//vector<pair<int,int> > v;
//v.push_back(make_pair(x,y));
//priority_queue<int,vector<int>, greater<int> > q2;


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

	int N, u, v;
	cin >> N >> u >> v;
	u--;v--;
	VI G[100010];
	REP(i, N - 1) {
		int a, b;
		cin >> a >> b;
		a--; b--;
		G[a].push_back(b);
		G[b].push_back(a);

	}

	if (G[u].size() == 1) {
		if (G[u][0] == v) {
			cout << 0 << endl;
			return 0;
		}
	}
	
	VI d(N);
	REP(i, N)d[i] = INF;
	queue<pii> Q;
	Q.push(pii(v, 0));

	while (!Q.empty()) {
		int a = Q.front().first, cnt = Q.front().second;
		Q.pop();
		d[a] = cnt;
		REP(i, G[a].size()) {
			if (d[G[a][i]] == INF)Q.push(pii(G[a][i], cnt + 1));
		}

	}
	VI di(N);
	vector<bool>can(N, false);
	REP(i, N)di[i] = INF;
	Q.push(pii(u, 0));

	while (!Q.empty()) {
		int a = Q.front().first, cnt = Q.front().second;
		Q.pop();
		di[a] = cnt;
		can[a] = true;
		REP(i, G[a].size()) {
			if (di[G[a][i]] == INF) {
				if (d[a] > di[a])Q.push(pii(G[a][i], cnt + 1));
			}
		}

	}
	int ans = 0;
	REP(i, N) {
		//cout << d[i] << endl;
		if (G[i].size() == 1&&can[i]) {
			chmax(ans, d[G[i][0]]);
		}
	}
	
	cout << ans << endl;

	return 0;
}



Measured memory_bytes: 8192
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <sstream>
#include <unordered_map>
#include <vector>


#define INF 4000000000000000000LL
#define MOD 1000000007
#define ALL(x) std::begin(x), std::end(x)


int main(int argc, char** argv)
{
  std::cin.tie(0);
  std::ios_base::sync_with_stdio(0);

  std::cout << std::fixed << std::setprecision(6);
  std::cerr << std::fixed << std::setprecision(6);

  int N;

  long long A[333333], a[66] = {0}, b[66] = {0};

  std::cin >> N;

  for (int i = 0; i < N; i ++) {
    std::cin >> A[i];

    for (int j = 0; j < 62; j ++)
      if (A[i] & (1LL << j))
        a[j] ++;
  }
  
  for (int i = 0; i < N; i ++) {
    for (int j = 0; j < 62; j ++)
      if (A[i] & (1LL << j))
        a[j] --;
    
    for (int j = 0; j < 62; j ++) {
      long long c = a[j], d = N - 1 - i - c;

      (b[j] += (A[i] & (1LL << j)) ? d : c) %= MOD;
    }
  }

  long long S = 0;
  
  for (int i = 0; i < 62; i ++)
    (S += (b[i] * ((1LL << i) % MOD)) % MOD) %= MOD;

  std::cout << S << std::endl;

  return 0;
}


Measured memory_bytes: 2560
N= int(input())
s = []

for _ in range(N):
    s.append(input())

for i in range(N):
    s[i] = tuple(sorted(s[i]))

import collections
c = collections.Counter(s)
d = [i for i in c.values()]

counter = 0
from math import factorial
for i in d:
    if i > 1:
        counter += i*(i-1)/2

print(int(counter))   

Measured memory_bytes: 26384
// -----------------------------------
// author   : MatsuTaku
// country  : Japan
// created  : 07/05/20 20:45:24
// -----------------------------------

#include <bits/stdc++.h>

using namespace std;
using ll = long long;

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

  int n; cin>>n;
  int ans[4] = {};
  while (n--) {
    string s; cin>>s;
    if (s == "AC")
      ans[0]++;
    if (s == "WA")
      ans[1]++;
    if (s == "TLE")
      ans[2]++;
    if (s == "RE")
      ans[3]++;
  }
  cout << "AC x " << ans[0] << endl;
  cout << "WA x " << ans[1] << endl;
  cout << "TLE x " << ans[2] << endl;
  cout << "RE x " << ans[3] << endl;

  return 0;
}


Measured memory_bytes: 3660
w = list(input())
w.sort()
c = 0
flag = 0
if len(w) % 2 == 0:
    for i in range(round(len(w) / 2)):
        if w[c] != w[c + 1]:
            flag = 1
            break
        c += 2
    if flag == 1:
        print("No")
    else:
        print("Yes")
else:
    print("No")

Measured memory_bytes: 9064
dp=[1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
print(dp[int(input())-1])

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

int main(){
	double n,prev;
	while(cin >> n){
		double ret = 0;
		for(int i=0;i<10;i++){
			ret += n;
			prev = n;
			if(i%2)n=prev/3;
			else n = prev*2;
		}
		printf("%.8lf\n",ret);
	}
}

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

//GCD,LCM
ll gcd(ll a, ll b){ return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b){ return a/gcd(a,b)*b;}

int main()
{
    string S;
    int w;
    cin>>S>>w;

    for(int i=0;i<S.length();i++){
        if(i%w==0){
            cout<<S[i];
        }
    }
    cout<<endl;
    return 0;
}

Measured memory_bytes: 256
n, a = map(int, input().split())
x_i = map(int, input().split())
list = list(i - a for i in x_i)
anslist = [[0 for i in range(5001)] for j in range(n + 1)]
anslist[0][2500] += 1
anslist[1][2500] += 1
anslist[1][list[0] + 2500] += 1
for id in range(n + 1):
    if id == 0 or id == 1: continue
    num = list[id - 1]
    for x in range(5001):
        anslist[id][x] += anslist[id - 1][x]
        if 0 <= x - num < 5001:
            anslist[id][x] += anslist[id - 1][x - num]
print(anslist[n][2500] - 1)

Measured memory_bytes: 5740
// in case of multiple test cases and N=1e5 don't intialize arrays as global except for graph vector-array
// always check whether or not you are doing mod of a negative number
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <bits/stdc++.h>
 
using namespace __gnu_pbds;
using namespace std;

#define double      	long double
#define int         	long long
#define pb          	push_back
#define pii         	pair<int,int>
#define vi          	vector<int>
#define vii         	vector<pii>
#define mi          	map<int,int>
#define mii         	map<pii,int>
#define all(a)      	(a).begin(),(a).end()
#define sz(x)       	(int)x.size()
#define endl        	"\n"
#define repp(i,a,b) 	for(int i=a;i<b;i++)
#define rep(i,a,b) 		for(int i=a;i<=b;i++)
#define brep(i,a,b)     for(int i=a;i>=b;i--)
#define deb1(x)      	cout << #x << "=" << x << endl
#define deb2(x, y)  	cout << #x << "=" << x << "," << #y << "=" << y << endl
#define deb3(x, y, z)  	cout << #x << "=" << x << "," << #y << "=" << y << "," << #z << "=" << z << endl
#define trace(v) 		for(auto it=v.begin();it!=v.end();it++)cout<<*it<<" ";cout<<endl;
#define tracearr(a,l,r) for(int iii=l;iii<=r;iii++)cout << a[iii] << " ";cout << endl;
#define PI          	3.1415926535897932384626
#define F 				first
#define S 				second
#define clr(x,y) 		memset(x, y, sizeof(x))
#define IOS         	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);


typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
// *s.find_by_order(1) - gives the 2nd samllest element in set
// s.order_of_key(x)   - gives the number of elements in the set which are strictly smaller than x


const int N= 3000 + 5;
const int MOD=1e9 + 7;

int n,m;
int dp[N][N][3];
int a[N][N];

int solve(int i,int j,int c)
{
	if(i>n || j>m)
		return 0;
	if(i==n && j==m)
		return a[i][j];
	int& ans = dp[i][j][c];
	if(ans!=-1)
		return ans;
	ans = max(ans,a[i][j] + solve(i+1,j,0));
	if(c<2)
		ans = max(ans,a[i][j] + solve(i,j+1,c+1));
	ans = max(ans,solve(i,j+1,c));
	return ans;
}


int32_t main()
{
	IOS;
	int T=1;
	//cin >> T;
	// int numOfSetBits = __builtin_popcountll(n);
	std::cout << std::fixed << std::setprecision(12);
	while(T--)
	{
		int k;
		cin >> n >> m >> k;
		clr(a,0);
		rep(i,1,k)
		{
			int x,y,z;
			cin >> x >> y >> z;
			a[x][y] = z;
		}
		clr(dp,-1);
		cout << solve(1,1,0);
	}
}

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

using namespace std;

#define ll long long
#define pb push_back
#define F first
#define S second
#define rf(i,a,b) for(int (i) = (a); (i) <= (b); (i)++)
#define rb(i,b,a) for(int (i) = (b); (i) >= (a); (i)--)
#define watch(x) cout << (#x) << " = " << (x) << endl
#define test(t) int(testCnt) = 0; int(t); cin >> (t); while(t -- && ++testCnt)

const int INF = 2e9 + 7;
const int MAXA = 1e5 + 10;
const ll MOD = (ll) 1e9 + 7;
const ll INFLL = 9e18 + 7;

typedef pair<int, int> ii;
typedef pair<ii, int> II;
typedef vector<int> vi;
typedef vector<ii> vii;

int n;
int f[MAXA][5], a[MAXA], b[MAXA], c[MAXA];

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    #ifndef ONLINE_JUDGE
        //freopen("in.in", "r", stdin);
    #endif
    cin >> n;
    rf(i, 1, n) {
        cin >> a[i] >> b[i] >> c[i];
    }
    f[1][1] = a[1];
    f[1][2] = b[1];
    f[1][3] = c[1];
    rf(i, 2, n) {
        f[i][1] = max({f[i][1], f[i - 1][2] + a[i], f[i - 1][3] + a[i]});
        f[i][2] = max({f[i][2], f[i - 1][1] + b[i], f[i - 1][3] + b[i]});
        f[i][3] = max({f[i][3], f[i - 1][1] + c[i], f[i - 1][2] + c[i]});
    }
    cout << max({f[n][1], f[n][2], f[n][3]});
    return 0;
}


Measured memory_bytes: 3328
#include <bits/stdc++.h>
#define REP(i,a,b) for(int i=(a);i<(b);i++)
#define RREP(i,a,b) for(int i=(a);i>=(b);i--)
typedef long long ll; typedef long double ld;
using namespace std;
const int INF=1e9, MOD=1e9+7, around[]={0,1,1,-1,-1,0,-1,1,0,0};
const ld PI=abs(acos(-1));
int n,k;

int main(){
	cin >> n >> k;
	
	int dp[15]={};
	dp[0]=1;
	REP(i,0,n) if(dp[i]) dp[i+1]=min(dp[i]*2,dp[i]+k);
	
	cout << dp[n] << endl;
	return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main()
{
	int t1[100][200], t2[100][200], n, i,j,k,c=0;
	scanf("%d", &n);
	for (i = 0; i < n; i++){
		for (j = 0; j < 3; j++){
			scanf("%d", &t1[j][i]);
		}
	}
	for (i = 0; i < n; i++){
		for (j = 0; j < 3; j++){
			t2[j][i] = t1[j][i];
		 }
	}
	for (j = 0; j < 3; j++){
		for (i = 0; i < n; i++){
			for (k = 0; k < n; k++){
				if (t1[j][i] == t1[j][k] && i != k){
					t2[j][i] = 0;
					t2[j][i] = 0;
				}
			}
		}
	}
	for (i = 0; i < n; i++){
		for (j = 0; j < 3; j++){
			c += t2[j][i];
		}
		printf("%d\n", c);
		c = 0;
	}
	return 0;
}

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

typedef long long ll;
#define REP(i,n) for(ll i=0; i<(ll)(n); i++)
#define REPM(i,n) for(ll i=(n-1); 0=<i; i--)
#define VI vector<int>
#define VL vector<ll>
#define VD vector<double>
#define VS vector<string>
#define V_SORT_U(x) sort(x.begin(), x.end());
#define V_SORT_D(x) sort(x.begin(), x.end(),greater<int>());
#define V_SUM(x) accumulate(x.begin(), x.end(), 0)
#define STR_TRANS_UP(x) transform(x.begin(), x.end(), x.begin(), ::toupper);
#define STR_TRANS_LOW(x) transform(x.begin(), x.end(), x.begin(), ::tolower);

int main(void){
    string S, T;
    cin >> S;
    cin >> T;

    if( (S.length())+1 == T.length())
    {
        if( S == T.substr(0,S.length()) )
        {
            cout << "Yes" << endl;
        }
        else{
            cout << "No" << endl;
        }
        
    }
    else{
        cout << "No" << endl;
    }

    return 0;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
#define int long 
int32_t main()
{
    int d = 10e9 + 7;
    int n;
    cin >> n;
    int ar[n];
    vector<vector<int>> dp(n,vector<int>(n,0));
    for(int i=0;i<n;i++) cin>>ar[i];
    int sum=0;
    for(int i=0;i<n;i++)
    {
        sum+=ar[i];
        for(int k=0,j=i;j<n;j++,k++)
        {
            if(k==j)
            {
                dp[k][j]=ar[k];
            }
            else if(k+1==j)
            {
                dp[k][j]=max(ar[j],ar[k]);
            }
            else
            {
                dp[k][j]=max(ar[k]+min(dp[k+1][j-1],dp[k+2][j]),ar[j]+min(dp[k][j-2],dp[k+1][j-1]));
            }
        }
    }
    int b=sum-dp[0][n-1];
    cout<<dp[0][n-1]-b<<endl;
}


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

using namespace std;

int N;

int d[100005];

vector<int> V;

int main(void) {

	cin >> N;

	for (int i = 1; i <= N; i++) {
		cin >> d[i];
		V.push_back(d[i]);
	}

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

	int ans = max(V[N / 2 ] - V[N / 2-1],0);

	//cout << V[N / 2] << " " << V[N / 2 - 1] << endl;

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 1272
#include<stdio.h>
int main(void){
	int i,j,a;
	int array[3];
	for(i=0;i<3;i++){
		scanf("%d",&array[i]);
	}
	for(i=0;i<2;i++){
		for(j=2;j>i;j--){
			if(array[j-1]>array[j]){
				a=array[j];
				array[j]=array[j-1];
				array[j-1]=a;
			}
		}
	}
	printf("%d %d %d\n",array[0],array[1],array[2]);
	return 0;
}

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


int main(){
	ios_base::sync_with_stdio(0); cin.tie(0);
	
	int arr[32] = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
	
	int k; cin >> k;
	cout << arr[k-1] << endl;
	
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
	int a, b, c, t=0;
	cin >> a >> b >> c;
	for (int i=min(a, b); i>=1; i--)
	{
		if (a%i==0&&b%i==0) t++;
		if (t==c)
		{
			cout << i << endl;
			return 0;
		 } 
	}
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<cassert>
#include<iterator>
#include<complex>
#include<stack>
#include<sstream>
#include<iterator>
#include<list>

using namespace std;

typedef  long long int lint;

#define rep(i, n) for (lint i = 0; i < n; i++)
#define sort(v) sort((v).begin(), (v).end())
#define reverse(v) reverse((v).begin(), (v).end())
#define upper(v,hoge) upper_bound(v.begin(),v.end(),hoge)
#define lower(v,hoge) lower_bound(v.begin(),v.end(),hoge)
#define mp make_pair
#define enld endl

int main() {
	lint X;
	cin >> X;
	if (X >= 30) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << enld;
	}
}

Measured memory_bytes: 3632
#include<stdio.h>
#include<stdlib.h>
int main(){
    int s,i,k;
    int *a;
    scanf("%d",&s);
    a=(int*)malloc(sizeof(int)*1024);
    a[0]=s;
    for(i=1;;i++){
        a[i]=(a[i-1]%2==0)?a[i-1]/2:a[i-1]*3+1;
        for(k=0;k<i;k++){
            if(a[i]==a[k]){
                printf("%d\n",i+1);
                free(a);
                return 0;
            }
        }
    }
}

Measured memory_bytes: 128
N, M, X, Y = map(int,input().split())
x = list(map(int,input().split()))
y = list(map(int,input().split()))
max_x = max(x)
min_y = min(y)
flag = False
for i in range(X+1,Y+1):
  if (max_x < i <= min_y):
    flag = True
    break
  else:
    flag = False
if flag == True:
  print("No War")
else:
  print("War")

Measured memory_bytes: 3064
import java.util.*;
import java.awt.*;
import static java.lang.System.*;
import static java.lang.Math.*;
public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(in);
        int size=1000000;
        long[] fact=new long[size];
        long[] inv=new long[size];
        fact[0]=1;
        inv[0]=1;
        long mod=1000000007;
        for (int i = 1; i < size; i++) {
            fact[i]=(fact[i-1]*i)%mod;
            inv[i]=power(fact[i],(int)mod-2)%mod;
        }
        //comb=fact[n]*inv[k]%mod*inv[n-k]%mod
        int n=sc.nextInt();
        int m=sc.nextInt();
        if(m==1){
            out.println(1);
        }else{
            HashMap<Integer,Integer> map=new HashMap<>();
            int stop=(int)sqrt(m)+1;
          for (int i = 2; i <=stop; i++) {
                while(m%i==0){
                    m/=i;
                    map.put(i,map.getOrDefault(i, 0)+1);
                }
            }
          if(m!=1)map.put(m,1);
            long ans=1;
            for(int k:map.keySet()){
                ans=(ans%mod*fact[n-1+map.get(k)]%mod*inv[n-1]%mod*inv[map.get(k)]%mod)%mod;
            }
            out.println(ans);
        }
      }
    static long power(long x,int n){
        long mod=1000000007;
        long ans=1;
        while (n>0) {
            if((n&1)==1){
                ans=(ans%mod*x%mod)%mod;
            }
            x=(x%mod*x%mod)%mod;
            n>>=1;
        }
        return ans;
    }
}


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

int main(){
    int N;
    cin >> N;
    int a[N+1]; a[0]=-1;
    int b[N+1]; b[0]=-1;
    for(int i=1; i<=N; i++){
        cin >> a[i];
    }
    for(int i=N; i>=1; i--){
        int sum=0;
        for(int j=2; j<=(int) N/i; j++){
            sum += b[i*j];
        }
        sum = sum%2;
        if( a[i]==sum ){
            b[i]=0;
        }else{
            b[i]=1;
        }
    }
    int M=0;
    for(int i=1; i<=N; i++){
        M += b[i];
    }
    cout << M << endl;
    int count=0;
    for(int i=1; i<=N; i++){
        if( b[i]>0 ){
            cout << i;
            count++;
            if( count != M ){
                cout << " ";
            }else{
                break;
            }
        }
    }

    if( M>0 ) cout << endl;

    return 0;
}

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

typedef long long int ll;
#define MAX 100005
ll absl(ll n)
{
	if(n<0)
	{
		return -1*n;
	}
	return n;
}

vector<int > dp(MAX,-1);
int dfs(int u,vector<vector<int > >&adj,vector<int >& visited)
{
	if(dp[u]!=-1)
	{
		return dp[u];
	}
	dp[u]=0;
	for(int v:adj[u])
	{
		if(!visited[v])
		{
			dp[u]=max(1+dfs(v,adj,visited),dp[u]);
		}
	}
	return dp[u];
}

int main()
{
	int n,m,i,x,y;
	cin>>n>>m;
	vector<vector<int > >adj(n);
	for(i=0;i<m;i++)
	{
		cin>>x>>y;
		x--;
		y--;
		adj[x].push_back(y);
	}
	vector<int > visited(n,false);
	int maxi=0;
	for(i=0;i<n;i++)
	{
		if(!visited[i])
		{
			maxi=max(dfs(i,adj,visited),maxi);
		}
		//cout<<i<<" "<<maxi;
	}
	cout<<maxi;
	return 0;
}


Measured memory_bytes: 9856
#include <vector>
#include <iostream>
#include <algorithm>
#include <cmath>
using namespace std;


void a(){
    int N,K; cin >> N >> K;

    cout << N - K + 1;

}

void b(){
    int R,G,B,N; cin >> R >> G >> B >> N;

    int count = 0;
    for(int r = 0; r*R <= N; r++)
        for(int g = 0; r*R + g*G <= N; g++){
            int rg = r*R + g*G;
            if ((N - rg) % B == 0){
                count++;
            }
        }

    cout << count;

}


void c(){
    int N; cin >> N;
    int pure_AB_count = 0;
    int _A_count = 0;
    int B_count = 0;
    int B_A_count = 0;
    for(int i = 0; i < N; i++){
        string s; cin >> s;
        for(int i = 0; i < s.size() - 1; i++){
            if(s[i] == 'A' && s[i+1] == 'B') pure_AB_count++;
        }

        int l = s.size() - 1;
        if(s[0] == 'B' && s[l] == 'A') {
            B_A_count++;
        }else if(s[0] == 'B'){
            B_count++;
        }else if(s[l] == 'A'){
            _A_count++;
        }
    }

    int gen_AB = 0;
    if (B_A_count > 0) {
        gen_AB += B_A_count - 1;
        if (_A_count > 0) {
            _A_count--;
            gen_AB++;
        }
        if (B_count > 0) {
            B_count--;
            gen_AB++;
        }
    }
    gen_AB += min(_A_count,B_count);

    cout << pure_AB_count + gen_AB;

}

void d(){

    long long N; cin >> N;

    long long sum = 0;
    for(long long q = 1; q*q + q< N; q++){
        if ((N - q)%q == 0){
            // N = q*m + q
            long long m = (N-q)/q; // here, always m > q
            sum += m;
        }
    }

    cout << sum;


}
int main(){

    d();
    return 0;


}

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

#define DEBUG(x) cerr << #x << ": " << x << endl;

int main() {
    int n;
    cin >> n;
    vector<int> t;
    int sum = 0;
    for (int i = 0; i < n; i++) {
        int x;
        cin >> x;
        t.push_back(x);
        sum += x;
    }

    int m;
    cin >> m;
    int rep[109][2];
    for (int i = 0; i < m; i++) {
        cin >> rep[i][0] >> rep[i][1];
    }

    for (int i = 0; i < m; i++) {
        int ans = sum;
        ans -= t[ rep[i][0] - 1 ];
        ans += rep[i][1];
        cout << ans << endl;
    }

    return 0;
}

Measured memory_bytes: 256
import numpy
import re
import math

def main():
	"""
	テストコード実行
	:return:
	"""
	n, a, b = map(int, re.split(" +", input()))
	x = 0
	for i in range(1, n + 1):
		if a <= sum(list(map(int, list(str(i))))) <= b:
			x += i
	print(x)

if __name__ == '__main__':
	main()


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

#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <string>
#include <functional>
#include <math.h>
#include <map>
#include <queue>
#include <stack>

typedef long long ll;
typedef unsigned long long ull;

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define RFOR(i,a,b) for(int i=(b-1);i>=(a);--i)
#define REP(i,n)   FOR(i,0,n)
#define RREP(i,n)   RFOR(i,0,n)
#define SORT(s) sort(s.begin(), s.end())
#define P pair<int, int>
#define mp make_pair

const double INF = 1e+09;
const int MOD = 1e9+7;

using namespace std;

template <typename _Ty>
ostream& operator << (ostream& ostr, const vector<_Ty>& v) {if (v.empty()) {ostr << "{ }"; return ostr;}
    ostr << "{" << v.front(); for (auto itr = ++v.begin(); itr != v.end(); itr++) {ostr << ", " << *itr;}
    ostr << "}";
    return ostr;}

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 gcd(int a, int b){
   if (a%b == 0) return(b);
   else return(gcd(b, a%b));}

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

vector<int> uniq(vector<int> vec){
  sort(vec.begin(), vec.end());
  vec.erase(unique(vec.begin(), vec.end()), vec.end());
  return vec;}

vector<ll> divisor(ll n) {
vector<ll> ret;
for(int64_t i = 1; i * i <= n; i++) {
  if(n % i == 0) {
    ret.push_back(i);
    if(i * i != n) ret.push_back(n / i);
  }
}
  sort(begin(ret), end(ret));
  return (ret);
}
void permu(int n){
  vector<int> perm(n);
  REP(i, n) perm[i] = i;
do{
  cout << perm  << endl;
}
while (next_permutation(perm.begin(), perm.end()));
return;}

// printf("%.10f\n" , ans);
int main(void){
  ios::sync_with_stdio(false);
  int a, b;
  cin >> a >> b;
  cout << a * b << endl;
  return 0;
}



Measured memory_bytes: 3196
use std::io::*;
use std::str::FromStr;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        //bytesのiterを生成
        .bytes()
        //それをas charでchar型に変換したiterを生成
        .map(|c| c.expect("failed to read char") as char)
        //c.is_whitespace()がfalseになるまで（つまり普通の文字が出るまで）iterを進めたiterを生成
        .skip_while(|c| c.is_whitespace())
        // !c.is_whitespace()がtrue, 即ち（普通の文字の間）iterを進め, 進んだところまでのiterを生成
        .take_while(|c| !c.is_whitespace())
        // それをcollect()してiterからStringを作る
        .collect();
    // parse()で任意の型に変換して返す。
    token.parse().ok().expect("failed to parse token")
}


fn read_one_line_to_vec<T: FromStr>() -> Vec<T> {
    let stdin = stdin();
    let stdin = stdin.lock();
    let v: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c == &'\x0d' || c == &'\x0a')
        .take_while(|c| !(c == &'\x0d' || c == &'\x0a'))
        .collect();
    v.split_whitespace()
        .map(|c| { let string = c.to_string();
            string.parse::<T>().ok().expect("failed to parse token")})
        .collect()
}

fn main() {
    let _s: u32 = read();
    let targets: Vec<i32> = read_one_line_to_vec();
    let _t_length: u32 = read();
    let search_items: Vec<i32> = read_one_line_to_vec();

    let mut count: i32 = 0;

    for s in search_items {
        let mut left: usize = 0;
        let mut right = targets.len();
        let mut mid = (left + right) / 2;
        while left < right {
            if targets[mid] < s {
                left = mid;
                mid = (left + right) / 2;
            } else if targets[mid] > s {
                right = mid;
                mid = (left + right) / 2;
            } else if targets[mid] == s {
                count += 1;
                break;
            }
            if mid == left || mid == right {
                break
            }
        }
    }
    println!("{}", count);
}

/*
fn print_vec(v: Vec<i32>) {
    let mut v_iter = v.iter();
    print!("{}", v_iter.next().as_ref().unwrap());
    for v in v_iter {
        print!(" {}", v)
    }
    println!();
}
*/


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

#define ll long long
const int N = 200100;
#define sz(s) (int)s.size()
int main()
{
	string s; cin >> s;

	int q; cin >> q;
	char ar[4*N];

	for(int i=N; i<N+sz(s); ++i)
		ar[i]=s[i-N];
		
	int reverse=0, front = N-1, rear = N+sz(s);
	
	while(q--){

		int type; cin >> type;

		if(type==1) reverse^=1;

		else{
			int f;
			char c; cin >> f >> c;
			if(f==1){
				if(reverse==0){
					ar[front]=c;
					--front;
				}
				else{
					ar[rear]=c;
					++rear;
				}
			}

			else{
				if(reverse==0){
					ar[rear]=c;
					++rear;
				}
				else{
					ar[front]=c;
					--front;
				}
			}
		}
	}

	if(reverse == 1)
	for(int i=rear-1; i>front; --i) cout << ar[i];
	
	if(reverse == 0)
	for(int i=front+1; i<rear; ++i) cout << ar[i];

	cout << endl;

	return 0;	
}


Measured memory_bytes: 1152
import java.util.*;
import static java.lang.Math.*;

public class Main {
	int[][] vis;
	int[] color;
	ArrayList<Integer>[] graph;
	
	class Query {
		int v, d, c;
		Query(int v, int d, int c) {
			this.v = v;
			this.d = d;
			this.c = c;
		}
	}
	
	void dfs(int u, int d, int c) {
		if (vis[u][d] == 1) return;
		vis[u][d] = 1;
		if(d == 0) {
			if(color[u] == 0) color[u] = c;
			return;
		}
		dfs(u, d-1, c);
		for (int i = 0; i < graph[u].size(); i++) {
			int v = graph[u].get(i);
			dfs(v, d - 1, c);
		}
	}

	void run() {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt(), m = sc.nextInt();
		vis = new int[n][11];
		color = new int[n];
		graph = new ArrayList[n];
		for (int i = 0; i < graph.length; i++) graph[i] = new ArrayList<Integer>();
		for (int i = 0; i < m; i++) {
			int a = sc.nextInt() - 1, b = sc.nextInt() - 1;
			graph[a].add(b); graph[b].add(a);
		}
		int q = sc.nextInt();
		Stack<Query> s = new Stack<>();
		for (int i = 0; i < q; i++) {
			int v = sc.nextInt() - 1, d = sc.nextInt(), c = sc.nextInt();
			Query query = new Query(v, d, c);
			s.push(query);
		}
		while (!s.isEmpty()) {
			Query query = s.pop();
			dfs(query.v, query.d, query.c);
		}
		for (int i = 0; i < color.length; i++) System.out.println(color[i]);
	}
	
	public static void main(String[] args) {
		new Main().run();
	}
}


Measured memory_bytes: 179800