akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <string>
#include <vector>
#include <deque>
#include <list>
#include <queue>
#include <math.h>
#include <assert.h>
#include <set>
#include <map>
#include <bitset>
#include <ctime>
#include <time.h>
#include <algorithm>
#include <cstdio>
#include <fstream>
#include <stack>
#include <ctype.h>
#include <numeric>
#include <sstream>
#include <unistd.h>
#include <unordered_map>
#include <unordered_set>
#include <limits>
#include <random>
#include <chrono>
#include <iomanip>
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
typedef long long ll;
#define debug(name) DEBUG(#name, (name))
template<typename T>
void DEBUG(string label, T value) {
    cerr << "[" << label << " = " << value << "]\n";
}

void solve(){
    int n;
    string s;
    cin >> n >> s;
    map<char,int> cnt;
    ll ans =0;
    for(int i = 0; i < n; ++i){
        cnt[s[i]]++;
        if(s[i] == 'R'){
            ans += cnt['G'] * cnt['B'];
            for(int j = i - 1; j >= 0; --j){
                int k = i - (i - 1 - j + 1) * 2;
                if(k < 0){
                    break;
                }
                if(s[j] != s[i] && s[k] != s[i] && s[j] != s[k]){
                    ans--;
                }
            }
        }
        else if(s[i] == 'G'){
            ans += cnt['R'] * cnt['B'];
            for(int j = i - 1; j >= 0; --j){
                int k = i - (i - 1 - j + 1) * 2;
                if(k < 0){
                    break;
                }
                if(s[j] != s[i] && s[k] != s[i] && s[j] != s[k]){
                    ans--;
                }
            }

        }
        else if(s[i] == 'B'){
            ans += cnt['G'] * cnt['R'];
            for(int j = i - 1; j >= 0; --j){
                int k = i - (i - 1 - j + 1) * 2;
                if(k < 0){
                    break;
                }
                if(s[j] != s[i] && s[k] != s[i] && s[j] != s[k]){
                    ans--;
                }
            }
        }
        else {
            throw;
        }
    }
    cout << ans << endl;
}
int main(int argv, char **argc){
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

    solve();
}


Measured memory_bytes: 3648
#include <map>
#include <cstdio>
#include <vector>
using namespace std;
int n, q, c, e; long long x, s[100009], w[100009], ans[100009];
int main() {
	scanf("%d%d", &n, &q); s[c++] = n;
	for (int i = 0; i < q; i++) {
		scanf("%lld", &x);
		while (c > 0 && s[c - 1] >= x) c--;
		s[c++] = x;
	}
	map<long long, long long> d; d[-s[c - 1]] = 1;
	for (int i = c - 2; i >= 0; i--) {
		e = 0;
		for (pair<long long, long long> j : d) {
			if (-j.first <= s[i]) break;
			d[-s[i]] += (-j.first) / s[i] * j.second;
			d[-((-j.first) % s[i])] += j.second;
			w[e++] = j.first;
		}
		for (int j = 0; j < e; j++) d.erase(w[j]);
	}
	for (int i = n; i >= 1; i--) ans[i] = ans[i + 1] + d[-i];
	for (int i = 1; i <= n; i++) printf("%lld\n", ans[i]);
	return 0;
}

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

const int MAX = 510000;
const int MOD = 1000000007;

ll fac[MAX], finv[MAX], inv[MAX];

void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main(){
  int n,k;
  cin >> n >> k;
  vector<ll> a(n);
  for(int i=0;i<n;++i) cin >> a[i];
  COMinit();
  sort(a.begin(),a.end());

  ll ans=0;
  for(int i=0;i<n-1;++i){
    ll cnt=COM(n,k)-COM(i+1,k)-COM(n-i-1,k);
    //cnt=cnt%MOD;
    if(cnt<0) cnt+=MOD;
    ans+=(cnt*(a[i+1]-a[i]))%MOD;
    ans=ans%MOD;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 15916
s = input()
n = len(s)
s_rev=s[::-1]
s1=s[0:(n-1)//2]
s1_rev=s1[::-1]
s2=s[(n+1)//2:n]
s2_rev=s2[::-1]
if s == s_rev and s1==s1_rev and s2 == s2_rev:
	print("Yes")
else:
	print("No")


Measured memory_bytes: 3060
#include <stdio.h>
int main(void){
    char c;
    char vowel[5] = {'a','e','i','o','u'};
    scanf("%c",&c);
    for(int i = 0; i < 5; i++){
        if(c == vowel[i]){
            printf("vowel\n");
            return 0;
        }
    }
    printf("consonant\n");

    return 0;
}


Measured memory_bytes: 128
#include<iostream>
#include<algorithm>
#include<vector>
#include <iomanip>
#include <math.h>
#include <string.h>
#include <stdio.h>

using namespace std;
 
int main(){

  	string str;
	cin >> str;
  
  	int number;
  	cin >> number;
  
  
  	for(int i=0; i<number; i++){
  		string order;
  		cin >> order;
      	int a, b;
      	string q;
  		if(order=="print"){
    		cin >> a >> b;
          	cout << str.substr(a,b-a+1) << endl;
    	}
  		else if(order=="reverse"){
    		cin >> a >> b;
          	string moji;
          	moji = str.substr(a, b-a+1);
          	reverse(moji.begin(), moji.end());
          	str = str.replace(a, b-a+1, moji);
    	}
  		else if(order=="replace"){
    		cin >> a >> b;
          	cin >> q;
          	str = str.replace(a, b-a+1, q);    
    	}
    }  
  
  return 0;

  
}


Measured memory_bytes: 3208
n = int(input())
index6, index9, num6, num9 = 0, 0, 0, 0
INF = float('inf')    
a = [INF for _ in range(n+1)]
a[n] = 0

for i in range(n, -1, -1):
    if a[i] == INF:
        continue
    j = 1
    while i-9**j >= 0:
        a[i-9**j] = min(a[i]+1, a[i-9**j])
        j += 1
    j = 1
    while i-6**j >= 0:
        a[i-6**j] = min(a[i]+1, a[i-6**j])
        j += 1
    if i-1 >= 0:
        a[i-1] = min(a[i]+1, a[i-1])
print(a[0])


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

#define loop(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) for (int i = 0; i < n; ++i)
#define dump(a) cerr << #a << " = " << (a) << "(L:" << __LINE__ << ")" << endl

const long long MOD = 998244353;

void solve(long long N, long long S, std::vector<long long> A) {
    vector<vector<long long> > dp(4000, vector<long long>(4000, 0));
    dp[0][0] = 1;
    rep (i, N) {
        rep (j, S+1) {
            dp[i+1][j] += dp[i][j];
            dp[i+1][j] %= MOD;
            dp[i+1][j] += dp[i][j];
            dp[i+1][j] %= MOD;
            if (j + A[i] <= S) {
                dp[i+1][j + A[i]] += dp[i][j];
                dp[i+1][j + A[i]] %= MOD;
            }
        }
    }
    cout << dp[N][S] << endl;
}

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


Measured memory_bytes: 128400
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
    string a;
    cin>>a;
    int l=a.size();
    int b[1005],k=0,x=0;
    for(int i=0;i<l;i++){
        for(int j=0;j<l;j++){
            if(a[i]==a[j])
                x++;
        }
        b[k++]=x;
        x=0;
    }
    for(int i=0;i<k;i++){
        if(b[i]%2==1){
            cout<<"No"<<endl;
            return 0;
        }
    }
    cout<<"Yes"<<endl;
}


Measured memory_bytes: 3600
def c():
    N, M = map(int, input().split())
    if N > 1:
        ans = list('1' + '0' * (N-1))
    else:
        ans = ['0']

    digits = {}
    for j in range(M):
        s, c = map(int, input().split())
        if (s, c) == (1, 0) and N > 2:
            print(str(-1))
            return
        if s in digits:
            if digits[s] != c:
                print(str(-1))
                return
            else:
                # do nothing
                pass
        else:
            digits[s] = c
            ans[s-1] = str(c)

    print(''.join(ans))


##########
c()


Measured memory_bytes: 3064
h,w=map(int,input().split())
n=int(input())
a=list(map(int,input().split()))
lst=[]


for i in range(1,n+1):
  for j in range(a[i-1]):
    lst.append(str(i))

lst.reverse()
    
ans=[[0]*w for i in range(h)]

for i in range(h):
  if i%2==0:
    for j in range(w):
      ans[i][j]=lst.pop()

  else:
    for j in range(w-1,-1,-1):
      ans[i][j]=lst.pop()

for i in ans:
  print(' '.join(i))


Measured memory_bytes: 9760
#include <stdio.h>

int main(void){

  int n;
  scanf("%d", &n);
  int d1,d2,d3;
  d1 = n%10;
  n /=10;
  d2 = n%10;
  n /= 10;
  d3 = n%10;

  if (d1 == 7 || d2 == 7 || d3 == 7) {
    printf("Yes\n");
  } else {
    printf("No\n");
  }

  return 0;
}

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

typedef long long ll;
#define pb push_back

int main(){
    int n, w;
    cin >> n >> w;
    int W[110], V[110];
 
    for(int i=0; i<n; i++){
        cin >> W[i] >> V[i];
    }
 
    vector<ll> itm[5];
    ll w1 = W[0];
 
    for(int i=0; i<n; i++){
        itm[W[i]-w1].pb(V[i]);
    }
 
    for(int i=0; i<5; i++) sort(itm[i].begin(), itm[i].end());
 
    for(int i=0; i<5; i++){
        itm[i].pb(0);
        reverse(itm[i].begin(), itm[i].end());
    }
 
    ll cost_max = 0LL;
    for(int i = 0; i < 4; i++) {
    	for(int j = 1; j < itm[i].size(); j++) itm[i][j] += itm[i][j-1];
    }
 
    // unsigned int で0-1はUNSINGED_INTMAX-1になるのでやばい
    for(int i=0; i<itm[0].size(); i++){
        //if(i+1 != itm[0].size()) itm[0][i+1] += itm[0][i];
        for(int j=0; j<itm[1].size(); j++){
            //if(j+1 != itm[1].size()) itm[1][j+1] += itm[1][j];
            for(int k=0; k<itm[2].size(); k++){
                //if(k+1 != itm[2].size()) itm[2][k+1] += itm[2][k];
                for(int l=0; l<itm[3].size(); l++){
                    //if(l+1 != itm[3].size()) itm[3][l+1] += itm[3][l];
                    ll val_sum = itm[0][i] + itm[1][j] + itm[2][k] + itm[3][l];
                    ll sum_W = w1*i + (w1+1)*j + (w1+2)*k + (w1+3)*l;
                    if(sum_W <= w && cost_max < val_sum) cost_max = val_sum;
                }
            }
        }
    }
 
    cout << cost_max << endl;

}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
#define N 100010

class Segtree{
  public:
  ll n;
  ll *dat;
  void init(ll nn){
    for(n=1;n<nn;n*=2){}
    dat=new ll[n];
    for(int i=0;i<n;i++)dat[i]=1;
  }
  
  
  void upd(ll l,ll r){
    for(ll i=l;i<=r;i++)dat[i]=0;
  }
  
  ll qry(ll l,ll r){
    ll res=0;
    for(ll i=l;i<=r;i++)res+=dat[i];
    return res;
  }
};

vector<ll> g[N];
ll n;
class HLD{
  public:
  ll chain[N],id[N],chn;
  ll par[N],len[N];
  
  ll siz[N],dep[N];
  void dfs(ll x,ll from,ll d){
    siz[x]=1; dep[x]=d;
    for(auto y:g[x]){
      if(y==from)continue;
      dfs(y,x,d+1);
      siz[x]+=siz[y];
    }
  }
  
  void build(){
    for(int i=1;i<=n;i++){
      chain[i]=-1;
    }
    P dat[N];
    for(int i=1;i<=n;i++){
      dat[i-1]=make_pair(dep[i],i);
    }sort(dat,dat+n);
    chn=0;
    for(int i=0;i<n;i++){
      ll x=dat[i].second;
      if(~chain[x])continue;
      for(auto y:g[x])if(~chain[y])par[chn]=y;
      for(int j=0;;j++){
	chain[x]=chn;
	id[x]=j; len[chn]=j;
	ll ma=-1,pnt=-1;
	for(auto y:g[x]){
	  if(~chain[y])continue;
	  if(ma<siz[y])ma=siz[y],pnt=y;
	}
	if(pnt==-1)break;
	x=pnt;
      }
      chn++;
    }
  }
  
  Segtree seg[N];
  void init(){
    dfs(0,-1,0);
    build();
    for(int i=0;i<chn;i++){
      seg[i].init(len[i]+1);
    }
  }
  
  void upd(ll a,ll b){
    while(chain[a]!=chain[b]){
      if(chain[a]<chain[b])swap(a,b);
      ll c=chain[a];
      seg[c].upd(0,id[a]);
      //cout<<c<<" 0 "<<id[a]<<endl;
      a=par[c];
    }
    ll aid=id[a],bid=id[b]; if(aid>bid)swap(aid,bid);
    if(aid!=bid)seg[chain[a]].upd(aid+1,bid);
    //cout<<chain[a]<<" "<<aid+1<<" "<<bid<<endl;
  }
  
  ll qry(ll a,ll b){
    ll res=0;
    while(chain[a]!=chain[b]){
      if(chain[a]<chain[b])swap(a,b);
      ll c=chain[a];
      res+=seg[c].qry(0,id[a]);
      //cout<<c<<" 0 "<<id[a]<<" "<<seg[c].qry(0,id[a])<<endl;
      a=par[c];
    }
    ll aid=id[a],bid=id[b]; if(aid>bid){swap(aid,bid);swap(a,b);}
    if(aid!=bid)res+=seg[chain[a]].qry(aid+1,bid);
    //cout<<chain[a]<<" "<<aid+1<<" "<<bid<<" "<<seg[chain[a]].qry(aid+1,bid)<<endl;
    
    return a;
    
    return res;
  }
  
};HLD hld;

int main(){
  cin>>n;
  for(int i=0;i<n;i++){
      ll k;cin>>k;
      for(int j=0;j<k;j++){
	  ll x;cin>>x;
	  g[x].push_back(i);
	  g[i].push_back(x);
      }
  }
  hld.init();
  ll q;cin>>q;
  for(int i=0;i<q;i++){
      ll a,b;cin>>a>>b;
      cout<<hld.qry(a,b)<<endl;
  }
  return 0;
}



Measured memory_bytes: 20044
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0;i<n;i++)
using namespace std;
int main(){
    string s;cin>>s;
    bool is=true;
    for(int i=1;i<=2;i++)if(s[i]==s[i-1]||s[i]==s[i+1])is=false;
    cout<<(is?"Good":"Bad")<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n)    for(int i=0; i<(n); ++i)
#define REP(i, d, n) for(int i=(d); i<(n); ++i)
#define rrep(i, n)   for(int i=(n-1); i>=0; --i)
#define all(v)       v.begin(), v.end()
#define rall(v)      v.rbegin(), v.rend()
#define int          long long
template<typename T>
using vv  = vector<vector<T>>;
using vi  = vector<int>;
using vvi = vector<vector<int>>;
using P   = pair<int, int>;
using ll  = long long;
constexpr ll INF = 1LL << 60;

signed main(){

    int x[5];
    int z = 0;
    rep(i, 5){
        cin >> x[i];
        if(x[i] == 0){
            z = i+1;
        }
    }   

    cout << z << endl;

    return 0;
}



Measured memory_bytes: 3632
#include <iostream>
#include <algorithm>
#include <functional>
#include <vector>
#include <string>
#include <map>
#include <sstream>
#include <cmath>
#include <iomanip>
#include <stdexcept>
// #include <bits/stdc++.h>
#define ll long long
#define ld long double
#define rep(i,h) for(int i = 0; i < h; i++)
#define rep1(i,h) for(int i = 0; i <= h; i++)
#define rep2(i,n,h) for(int i = n; i < h; i++)
#define rep3(i,n,h) for(int i = n; i <= h; i++)

using namespace std;


int main(void) {
  string s;
  cin >> s;
  string st = s;
  int h = s.length(), count = 0, cou = 0;
  s[0] = 0;
      for(int i = 0; i < h; i++) {
          if(i % 2 == 0) {
              s[i] = '0';
          } else {
              s[i] = '1';
          }
          if(s[i] != st[i]) {
              count++;
          }
      }
      cout << endl;
      s[0] = 1;
      for(int i = 0; i < h; i++) {
          if(i % 2 == 0) {
              s[i] = '1';
          } else {
              s[i] = '0';
          }
          if(s[i] != st[i]) {
              cou++;
          }
      }
      cout << min(count, cou) << endl;
    return 0;
}






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

void fnInput(int& rnTrgSu, int& rnTrgKin)
{
  cin >> rnTrgSu >> rnTrgKin;
}

int fnRcsSch(int nPos, int nTrgSu, int nTrgKin, vector<int>& rvnMoneyCnt)
{
  const vector<int> cnvnMoney{10000, 5000, 1000};

  if (nTrgSu == 0 && nTrgKin == 0) return  1;
  if (nTrgKin <  0)                return -1;
  if (nPos == rvnMoneyCnt.size())  return  0;

  if (nPos == rvnMoneyCnt.size() - 1)
  {
    rvnMoneyCnt[nPos] = nTrgSu;
    return fnRcsSch(nPos + 1, 0, nTrgKin - cnvnMoney[nPos] * nTrgSu, rvnMoneyCnt);
  }
  else
    for (int i = 0; i <= nTrgSu; i++)
    {
      rvnMoneyCnt[nPos] = i;
      for (int i = nPos + 1; i < rvnMoneyCnt.size(); i++)
        rvnMoneyCnt[i] = 0;

      int nRslt = fnRcsSch(nPos + 1, nTrgSu - i, nTrgKin - cnvnMoney[nPos] * i, rvnMoneyCnt);
      if      (nRslt ==  1)  return 1;
      else if (nRslt == -1)  break;
    }

  return 0;
}

int fnExhSch(int nTrgSu, int nTrgKin)
{
  vector<int> vnMoneyCnt(3);

  if (fnRcsSch(0, nTrgSu, nTrgKin, vnMoneyCnt))
  {
    for (int i = 0; i < vnMoneyCnt.size(); i++)
    {
      if ( i )  cout << " ";
      cout << vnMoneyCnt[i];
    }
    cout << endl;
  }
  else
    cout << -1 << " " << -1 << " " << -1 << endl;
}

int main()
{
  int nTrgSu, nTrgKin;
  
  fnInput(nTrgSu, nTrgKin);
  fnExhSch(nTrgSu, nTrgKin);

  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
main(){
  string r,a;
  while(1){
    int h=0,b=0;
    cin>>r>>a;
    if(r=="0"&&a=="0") break;
    for(int i=0;i<r.size();i++){
      for(int j=0;j<a.size();j++){
	if(r[i]==a[j]){
	  if(i==j){
	    h++;
	  }
	  else{
	    b++;
	  }
	}
      }
    }
    cout<<h<<" "<<b<<endl;
  }
}

Measured memory_bytes: 3148
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define endl "\n"
#define se second
#define ll long long
//priority_queue<int, vector<int>, greater<int> > pq;
#define _CRT_SECURE_NO_DEPRECATE
const int N = 300300;
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
const ll mod =  1e9+7;
int f[N];
int arr[N];
int main()
{
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	int n;
	cin>>n;
	rep(i,1,n+1)
	{
		cin>>arr[i];
		f[arr[i]]++;
	}
int ans=0;
int sum=0;
rep(i,1,100005)
{
	int x=n-sum;
	if(x==sum)
	ans++;
	sum+=f[i];
	
	
}
cout<<ans;
}


Measured memory_bytes: 1024
#include<stdio.h>
int main(void) {
  int a, b, c, x;
  int ans = 0;
  scanf("%d%d%d%d", &a, &b, &c, &x);
  int i, j, k;
  for (i = 0; i <= a; i++) {
    for (j = 0; j <= b; j++) {
      for (k = 0; k <= c; k++) {
        int t = 500 * i + 100 * j + 50 * k;
        if (t == x)
          ans++;
      }
    }
  }
  printf("%d\n", ans);
  return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <cstdlib>
#include <utility>
#include <cmath>

using namespace std;

int main()
{
   int N;
   double D;
   int x, y;
   int result = 0;
   cin >> N >> D;
   pair<int, int> coords[N];
   

   for(int i = 0; i < N; i++){
    cin >> x >> y;
    coords[i] = make_pair(x, y);
   }
   
   for(int i = 0; i < N; i++){
    double distance = sqrt(pow(coords[i].first, 2) + pow(coords[i].second, 2));
    if(distance <= D){
        result++;   
    }
   }
   
   cout << result << endl;

   
   return 0;
}


Measured memory_bytes: 5296
#[allow(unused_imports)]
use proconio::marker::{Bytes, Chars};
use proconio::{fastout, input};
#[fastout]
fn main() {
    input! {
        n: usize,
        t: [(usize, usize, usize); n],

    }
    // |xi - xi+1| + |yi - yi+1|がt2-t1より大きく、かつ偶奇が一致していればいい
    let t0: (isize, isize, isize) = (0, 0, 0);
    let mut ans = true;
    let distance =
        (t[0].1 as isize - t0.1 as isize).abs() + (t[0].2 as isize - t0.2 as isize).abs();
    if distance > t[0].0 as isize - t0.0 || distance % 2 != (t[0].0 as isize - t0.0) % 2 {
        ans = false;
    }
    for i in 0..(n - 1) {
        let distance = (t[i + 1].1 as isize - t[i].1 as isize).abs()
            + (t[i + 1].2 as isize - t[i].2 as isize).abs();
        if distance as usize > t[i + 1].0 - t[i].0
            || distance as usize % 2 != (t[i + 1].0 - t[i].0) % 2
        {
            ans = false;
            break;
        }
    }
    if ans {
        println!("Yes");
    } else {
        println!("No");
    }
}


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

int n;

int main(){
    cin>>n;
    bool valid=false;
    for(int i=1;i<=9;i++){
        for(int j=1;j<=9;j++){
            if(i*j==n){
                valid=true;
            }
        }
    }
    if(valid){
        cout<<"Yes"<<endl;
    }else{
        cout<<"No"<<endl;
    }
}

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

int fc[100001], md = 1e9 + 7;

int main(){
	fc[0] = 1;
	f(i, 1, 100001)fc[i] = (ll)fc[i - 1] * i % md;
	int a, b;
	scanf("%d%d", &a, &b);
	if (a > b)swap(a, b);
	if (a + 1 < b) { printf("0\n"); return 0; }
	int an = (ll)fc[a] * fc[b] % md;
	if (a == b && (an <<= 1) >= md)an -= md;
	printf("%d\n", an);
}

Measured memory_bytes: 640
function main(input) {
  const [a,b,c] = input.split(" ")
  
  if(parseInt(a) + parseInt(b) + parseInt(c) < 22){
  	return console.log("win")
  }else{
    return console.log("bust")
  }
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 7372
"use strict";

/**
 * Resolves problem.
 * @param  {string} input
 * @returns {string}
 */
var main = function(input) {
    const params = input.split(" ").map(x => parseInt(x));
    const N = params[0];
    const Y = params[1];

    // 1. 10000x + 5000y + 1000z = Y
    // 2. x + y + z = N
    // したがって x = -(y + z) + N である。
    // これを 2. 式に代入した -5000y - 9000z + 10000N = Y となる y, z の組み合わせを検索する。
    // ただし 0 <= y <= N, 0 <= z <= N, y + z <= N である。
    for (let y = 0; y <= N; y++) {
        for (let z = 0; z <= N; z++) {
            if ((y + z) > N)
                break;
            const matches = ((-5000 * y) + (-9000 * z) + (10000 * N)) === Y;
            if (matches) {
                const x = N - (y + z);
                return [x, y, z].join(" ");
            }
        }
    }
    return [-1, -1, -1].join(" ");
};

const output = main(require("fs").readFileSync("/dev/stdin", "utf8"));
console.log(output); // console.log outputs with trailing new line!


Measured memory_bytes: 7372
#include <iostream>
#include <vector>
#include <cmath>
#include <map>
#include <queue>
#include <algorithm>

using namespace std;
typedef long long ll;

int main() {
    ll H,W,D;
    cin >> H >> W >> D;

    vector<vector<ll>> A(H+10,vector<ll>(W+10));
    vector<ll> idx(H*W+10),idy(H*W+10),d(H*W+10);
    for(int i=0;i<H;i++){
        for(int j=0;j<W;j++){
            cin >> A[i][j];
            idx[A[i][j]]=i;idy[A[i][j]]=j;
        }
    }
    for(int i=D+1;i<=H*W;i++){
        d[i]=d[i-D]+llabs(idx[i]-idx[i-D])+llabs(idy[i]-idy[i-D]);
    }
    ll Q;cin >> Q;
    vector<ll> L(Q+10),R(Q+10);
    for(int i=0;i<Q;i++){
        cin >> L[i] >> R[i];
    }
    for(int i=0;i<Q;i++){
        cout << d[R[i]]-d[L[i]] << endl;
    }
}

Measured memory_bytes: 5632
#include <algorithm>
#include <bitset>
#include <cctype>
#include <chrono>
#include <cmath>
#include <cstdio>
#include <ctime>
#include <deque>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <string>
#include <tuple>
#include <unordered_map>
#include <vector>
using namespace std;

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

const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fLL;
/*----------------------------------------*/

// https://atcoder.jp/contests/cf17-final-open/tasks/cf17_final_d
int main() {
  cin.tie(0); ios::sync_with_stdio(false);
  // freopen("input.txt", "r", stdin);

  int n; cin >> n;
  vector<int> w(n), s(n), v(n);
  vector<pair<int, pair<int, int>>> ws(n);
  REP(i, n) {
    cin >> w[i] >> s[i] >> v[i];
    ws[i] = {w[i] + s[i], {-v[i], i}};
  }
  sort(ALL(ws));
  vector<vector<long long> > dp(n + 1, vector<long long>(10002, 0));
  REP(i, n) {
    int now = ws[i].second.second;
    REP(j, 10002) {
      dp[i + 1][j] = max(dp[i + 1][j], dp[i][j]);
      if (j <= s[now]) dp[i + 1][min(j + w[now], 10001)] = max(dp[i + 1][min(j + w[now], 10001)], dp[i][j] + v[now]);
    }
  }
  long long ans = 0;
  REP(j, 10002) ans = max(ans, dp[n][j]);
  cout << ans << '\n';
  return 0;
}


Measured memory_bytes: 78592
#include<iostream>
#include<set>
#include<vector>
#include<algorithm>
#define MINF -1000000000
using namespace std;
int main(){
  int n,m,tmp,cnt;
  cin >> n >> m;
  int a[m],dp[n+1];
  int num[]={0,2,5,5,4,5,6,3,7,6};
  for(int i=0;i<m;i++){
    cin >> a[i];
  }
  sort(a,a+m,greater<int>());
  fill(dp,dp+n+1,MINF);
  dp[0]=0;
  for(int i=0;i<=n;i++){
    for(int j=0;j<m;j++){
      tmp = i-num[a[j]];
      if(tmp>=0){
        dp[i]=max(dp[tmp]+1,dp[i]);
      } 
    }
  }
  cnt=dp[n];
  for(int i=0;i<cnt;i++){
    for(int j=0;j<m;j++){
      tmp=n-num[a[j]];
      if(tmp>=0){
        if(dp[tmp]==dp[n]-1){
          cout << a[j];
          n-=num[a[j]];
          break;
        }
      }
    }
  }
  cout <<endl;
}


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

#define fi first
#define se second
#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define repr(i,a,b) for(int i=(int)(a-1);i>=b;i--)
#define rep(i,n) repl(i,0,n)
#define each(itr,v) for(auto itr:v)
#define pb(s) push_back(s)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout << #x" = " << x << endl
#define maxch(x,y) x=max(x,y)
#define minch(x,y) x=min(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt(x) bitset<32>(x).count()

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

#define INF INT_MAX/3

int main(){
    cin.sync_with_stdio(false);
    int a[3];
    cin >> a[0] >> a[1] >> a[2];
    sort(a, a + 3);
    int t = a[2] - a[0] + a[2] - a[1];
    if (t % 2) {
        cout << t / 2 + 2 << endl;
    } else {
        cout << t / 2 << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <numeric>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <array>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
using namespace std;
typedef long long unsigned int ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

int GCD(const int& a, const int& b){
   const int& _a = max(a,b);
   const int& _b = min(a,b);
   if(_a % _b == 0){
      return _b;
   }
   else{
      return GCD(_b, _a % _b);
   }
}

int LCM(const int& a, const int& b){
   const int& _a = max(a,b);
   const int& _b = min(a,b);
   return (_a*_b)/(GCD(_a, _b));
}

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

   int lower = max(a,c);
   int upper = min(b,d);
   cout << max(0, upper - lower) << endl;

   return 0;
}

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

using namespace std;

int main(){
    int N;
    cin >> N;
    vector<int> a(N);
    rep(i, N)cin >> a[i];

    int next = a[0];
    int count = 1;
    while(true){
        if(count > N){
            cout << -1 << endl;
            break;
        }

        if( next == 2 ){
            cout << count << endl;            
            break;
        }
        next = a[next - 1];
        count += 1;

    }    
    return 0;
}


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

int main()
{
    int A1, A2, A3;

    cin >> A1 >> A2 >> A3;

    if (A1 + A2 + A3 >= 22)
    {
        cout << "bust" << endl;
    }
    else
    {
        cout << "win" << endl;
    }
}


Measured memory_bytes: 256
#include<iostream>
#include<queue>
using namespace std;
int main()
{
	int h,w,a[55][55],d[]={0,1,0,-1,0},py,px,ny,nx,c=0;
	char m[55][55];
	queue<int>q;
	cin>>h>>w;
	for(int y=1;y<=h;y++)
	{
		cin>>(m[y]+1);
		for(int x=1;x<=w;x++)
		{
			a[y][x]=-1;
			c+=(m[y][x]=='.');
		}
	}
	a[1][1]=1;
	q.push(100);
	while(!q.empty())
	{
		py=q.front()/99;
		px=q.front()%99;
		q.pop();
		for(int i=0;i<4;i++)
		{
			ny=py+d[i];
			nx=px+d[i+1];
			if(a[ny][nx]<0&&m[ny][nx]=='.')
			{
				a[ny][nx]=a[py][px]+1;
				q.push(ny*99+nx);
			}
		}
	}
	if(a[h][w]<0)cout<<"-1"<<endl;
	else cout<<c-a[h][w]<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
int main(void){
    int x, y;
    while (1) {
        scanf("%d%d", &x, &y);
        if (x == 0 && y == 0) break;
        if (x >= y) printf("%d %d", y, x);
        else printf("%d %d", x, y);
        printf("\n");
    }
    
    return 0;
}



Measured memory_bytes: 2040
#include <iostream>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <unordered_map>
#include <algorithm>
#include <functional>
#include <numeric>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cassert>
#include <climits>
#define bogo_sort   std::sort
#define bozo_sort   std::stable_sort
#define alles(obj)  obj.begin(), obj.end()
#define elif        else if
#define unless(flg) if(!(flg))
#define elless(flg) else if(!(flg))
#define echo        std::cout <<
#define read        std::cin >>
#define endl        std::endl
#define fin         << '\n'
#define bash        push_back
#define fish        push_front
#define makePair    std::make_pair
#define _           << ' ' <<
// type-define
#define Stack       std::stack
#define Queue       std::queue
#define Deque       std::deque
#define PQueue      std::priority_queue
#define Set         std::set
#define Vector      std::vector
#define Pair        std::pair
#define Map         std::map
#define HashMap     std::unordered_map
#define Greater     std::greater
using String  =     std::string;
using llong   =     long long;
using boolean =     bool;
using Pii     =     Pair<int, int>;
using Vi      =     Vector<int>;
using Vii     =     Vector<Pii>;
// utils
constexpr int   dx[] = {1, 0, -1, 0, 1, 1, -1, -1};
constexpr int   dy[] = {0, 1, 0, -1, 1, -1, 1, -1};
constexpr int   INF  = 0x3f3f3f3f;
constexpr llong LINF = 0x3f3f3f3f3f3f3f3fLL;

namespace {
    template<class A, class B> A power ( llong x, llong n, llong mod ) {
        llong ans = 1;
        while ( n > 0 ) {
            if ( n & 1 ) ans = ( ans * x ) % mod;
            x = ( x * x ) % mod;
            n >>= 1;
        }
        return ans;
    }
    template<class A, class B> A power ( A x, B n ) { return power( x, n, 1000000007 ); }
    template<class A> A gcd ( A x, A y ) { return x % y ? gcd( y, x % y ) : y; }
    template<class A, class B> A lcm   ( A x,  B y ) { return ( x / gcd(x, y) * y ); }
    template<class A> inline A abs ( A n ) { return ( n < 0 ) ? -n : n; }
    template<class A, class B> inline bool chmax ( A &a, const B &b ) { return b > a ? a = b, true : false; }
    template<class A, class B> inline bool chmin ( A &a, const B &b ) { return b < a ? a = b, true : false; }
    boolean isMovable ( int x, int y, int w, int h ) {
        return ( x >= 0 && y >= 0 && x < w && y < h );
    }
}

namespace Rlyeh {

    signed call_of_Cthulhu( signed datum ) {

        llong ans = 0;
        int n;
        read n;
        for ( int i = 0; i < n; i++ ) {
            int a;
            read a;
            ans += a-1;
        }
        echo ans fin;

        return 0;
    }
}

signed main(){std::cin.tie(0); std::ios::sync_with_stdio(false); int main_result = Rlyeh::call_of_Cthulhu(114514); return 0;}


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

using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<double> VEC;
typedef vector<VEC> MAT;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<int, PII> TIII;
typedef long long LL;
typedef vector<LL> VLL;

//container util

//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define MT(a,b,c) MP(a, MP(b, c))
#define T1 first
#define T2 second.first
#define T3 second.second


//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define EPS 1e-8

char s[1111];

int main(){
	while(1){
		cin.getline(s,1111);
		if(!strcmp(s, "."))return 0;
		int n=strlen(s);
		stack<char> st;
		int flag = 0;
		REP(i,n){
			if(s[i]=='('||s[i]=='[')st.push(s[i]);
			else if(s[i]==')'){
				if(!st.empty()&&st.top()=='('){
					st.pop();
				}else{
					flag = 1;
					cout << "no" << endl;
					break;
				}
			}
			else if(s[i]==']'){
				if(!st.empty()&&st.top()=='['){
					st.pop();
				}else{
					flag = 1;
					cout << "no" << endl;
					break;
				}
			}
		}
		if(flag == 1)continue;
		if(st.empty())cout << "yes" << endl;
		else cout << "no" << endl;
	}
}

Measured memory_bytes: 1160
#include <iostream>
#include <algorithm>

using namespace std;

int X[200010];
int Y[200010];

int main() {
    int N;

    cin >> N;
    for(int i = 0; i < N; i++) {
        cin >> X[i];
        Y[i] = X[i];
    }

    //std::sort(&X[0], &X[N-1]);
    std::sort(X, X + N);
    int left = (N - 1)/2;
    int right = left + 1;
    for(int j = 0; j < N; j++) {
        //auto ret = std::find(X, X+N, Y[j]);
        //size_t i = std::distance(X, ret);
        int i = std::lower_bound(X, X+N, Y[j]) - X;
        if(i <= left) cout << X[right] << endl;
        else if(i >= right) cout << X[left] << endl;
    }

    

}

Measured memory_bytes: 3712
n = int(input())
a = [int(x) for x in input().split()]
a.sort(reverse=True)

k = 1
index = 0
ans = 0
for i in range(n-1):
  k -= 1
  ans += a[index]
  if k == 0:
    index += 1
    k = 2

print(ans)

Measured memory_bytes: 31592
#include <iostream>
#include <string>
using namespace std;
  
int main(){
    string x;
    while (cin >> x){
        if (x == "0") break;
        long s = 0;
        for (long i = 0; i < x.size(); i++){
            s += x[i] - '0';
        }
        cout << s << endl;
    }
    return 0;
}

Measured memory_bytes: 1188
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <sstream>
#include <string>
#define _repargs(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _repargs(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define mod 1000000007
#define inf 2000000007
#define mp make_pair
#define pb push_back
typedef long long ll;
using namespace std;
template <typename T>
inline void output(T a, int p = 0) {
    if(p) cout << fixed << setprecision(p)  << a << "\n";
    else cout << a << "\n";
}
// end of template

template <typename T> inline void voutput(T &v){
    rep(i, v.size()){
        if (i) cout << " " << v[i];
        else cout << v[i];
    }
    cout << endl;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    // source code
    
    int N;
    cin >> N;
    vector<pair<int, int>> A(N);
    rep(i, N) cin >> A[i].first;
    rep(i, N) cin >> A[i].second;
    
    
    int ans = mod;
    
    rep(b, 1 << N) {
        vector<int> blue(N); // 1: blue, 0: red
        rep(j, N) {
            blue[j] = (b >> j) & 1;
        }
        int blues = 0;
        rep(i, N) if(blue[i] == 1) blues++;
        if(blues % 2 != 0) continue;
        
        vector<int> B(N), used(N);
        rep(i, N) B[i] = blue[i] ? A[i].second : A[i].first;
        vector<int> C = B;
        vector<int> D(N);
        sort(all(C));
        int cnt = 0;
        bool ok = true;
        rep(i, N) {
            bool breaked = false;
            rep(j, N) {
                if(C[i] == B[j] && abs(i - j) % 2 == blue[j] && used[j] == 0) {
                    used[j] = 1;
                    D[i] = j;
                    breaked = true;
                    break;
                }
            }
            if (!breaked) {
                ok = false;
                break;
            }
        }
        rep(i, N) {
            rep(j, N) {
                if(i < j && D[i] > D[j]) cnt++;
                if(i > j && D[i] < D[j]) cnt++;
            }
        }
        cnt /= 2;
        if(!ok) continue;
//        cout << "blue: ";
//        voutput(blue);
//        cout << "C: ";
//        voutput(C);
//        cout << "ind: ";
//        voutput(D);
        ans = min(ans, cnt);
        
    }
    if(ans == mod) output(-1);
    else output(ans);
    
    return 0;
}


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

int main() {
  int N;
  cin >> N;
  vector<int> d(N);
  for(int i = 0; i < N; i++) {
    cin >> d.at(i);
  }
  sort(d.begin(), d.end());
  reverse(d.begin(), d.end());
  int count = 1;
  for(int i = 1; i < N; i++) {
    if(d.at(i - 1) > d.at(i)) {
      count++;
    }
  }
  cout << count << endl;
}


Measured memory_bytes: 256
#atcoder template
def main():
    import sys
    imput = sys.stdin.readline
    #文字列入力の時は上記はerrorとなる。
    #ここにコード
    #input
    N = int(input())
    A = list(map(int, input().split()))

    #output
    import itertools
    import math
    B = list(itertools.accumulate(A))

    def f(a, i):
        return abs(B[i]-B[a]-B[a])
    def g(b, i):
        return abs(B[-1]-B[b]- (B[b]- B[i]))
    answer = pow(10, 10)
    for i in range(1, N-2):
        left1 = 0
        right1 = i
        while left1 + 2 < right1:
            c1 = left1 + (right1 - left1)//3
            c2 = right1 - (right1 - left1)//3
            if f(c1, i) > f(c2, i):#条件が満たされる:
                left1 = c1
            else:
                right1 = c2
        left2 = i
        right2 = N-1
        while left2 + 2 < right2:
            c3 = left2 + (right2 - left2)//3
            c4 = right2 - (right2 - left2)//3
            if g(c3, i) > g(c4, i):#条件が満たされる:
                left2 = c3
            else:
                right2 = c4
        p = sorted([(f(j, i), j) for j in range(left1, right1+1)])[0][1]
        q = sorted([(g(j, i), j) for j in range(left2, right2+1)])[0][1]
        m = min(B[p], B[i]-B[p], B[q]-B[i], B[-1]-B[q])
        M = max(B[p], B[i]-B[p], B[q]-B[i], B[-1]-B[q])
        answer = min(answer, M-m)

    print(answer)

    #N = 1のときなどcorner caseを確認！
if __name__ == "__main__":
    main()

Measured memory_bytes: 93580
#pragma GCC optimize("O3")
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
using namespace std;

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

template <class T> inline T chmax(T &a, const T b) {return a = (a < b) ? b : a;}
template <class T> inline T chmin(T &a, const T b) {return a = (a > b) ? b : a;}

constexpr int MOD = 1e9 + 7;
constexpr int inf = 1e9;
constexpr long long INF = 1e18;

#define all(a) (a).begin(), (a).end()

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

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

    int d; cin>>d;
    vector<int> c(26);
    for(int i=0; i<26; i++) cin>>c[i];
    vector<vector<int>> s(d, vector<int>(26));
    for(int i=0; i<d; i++){
        for(int j=0; j<26; j++) cin>>s[i][j];
    }
    vector<int> t(d);
    vector<set<int>> day(26);
    for(int i=0; i<d; i++){
        cin>>t[i];
        t[i]--;
        day[t[i]].emplace(i);
    }

    for(int i=0; i<26; i++){
        day[i].emplace(-1);
        day[i].emplace(d);
    }

    vector<int> l(26, 0);
    ll ans = 0;
    for(int i=0; i<d; i++){
        ans += s[i][t[i]];
        l[t[i]] = i + 1;
        for(int j=0; j<26; j++){
            ans -= c[j] * (i + 1 - l[j]);
        }
    }

    int m; cin>>m;
    while(m--){
        int dd, ncon; cin>>dd>>ncon;
        dd--, ncon--;
        int pcon = t[dd];
        t[dd] = ncon;

        {
            // 引く
            ans -= s[dd][pcon];
            auto itr = day[pcon].lower_bound(dd);
            int d0 = dd - *prev(itr);
            int d1 = *next(itr) - *prev(itr);
            int d2 = *next(itr) - dd; 
            ans += d0 * (d0 - 1) / 2 * c[pcon];
            ans -= d1 * (d1 - 1) / 2 * c[pcon];
            ans += d2 * (d2 - 1) / 2 * c[pcon];
            day[pcon].erase(dd);
        }

        {
            // 足す
            ans += s[dd][ncon];
            day[ncon].emplace(dd);
            auto itr = day[ncon].lower_bound(dd);
            int d0 = dd - *prev(itr);
            int d1 = *next(itr) - *prev(itr);
            int d2 = *next(itr) - dd;
            ans -= d0 * (d0 - 1) / 2 * c[ncon];
            ans += d1 * (d1 - 1) / 2 * c[ncon];
            ans -= d2 * (d2 - 1) / 2 * c[ncon];
        }

        cout << ans << endl;
    }

    return 0;
}

Measured memory_bytes: 3672
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <iomanip>
#include <cassert>
using namespace std;

#define GET_ARG(a,b,c,F,...) F
#define REP3(i,s,e) for (i = s; i <= e; i++)
#define REP2(i,n) REP3 (i,0,(int)(n)-1)
#define REP(...) GET_ARG (__VA_ARGS__,REP3,REP2) (__VA_ARGS__)
#define RREP3(i,s,e) for (i = s; i >= e; i--)
#define RREP2(i,n) RREP3 (i,(int)(n)-1,0)
#define RREP(...) GET_ARG (__VA_ARGS__,RREP3,RREP2) (__VA_ARGS__)
#define DEBUG(x) cerr << #x ": " << x << endl

typedef long long ll;

int main(void) {
    string s;
    cin >> s;
    int i, j, n = s.size()-1;
    ll ans = 0;
    REP (i,1<<n) {
        ll x = s[0] - '0';
        REP (j,n) {
            if (i&1<<j) {
                ans += x;
                x = s[j+1] - '0';
            }
            else
                x = x * 10 + s[j+1] - '0';
        }
        ans += x;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long int
#define endl '\n'
#define pb push_back
#define PI 3.14159265
int M = 1000000007;
int32_t main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int n;
  cin >> n;
  int a[n + 1];
  int ans = 0;
  for (int i = 1; i <= n; ++i)
  {
    cin >> a[i];
    if (i % 2 && a[i] % 2)
      ans++;
  }
  cout << ans;


}


Measured memory_bytes: 3644
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <utility>
#include <cmath>
#include <functional>
#include <queue>
//#include <stack>
#include <climits>
#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,n1,n2) for(int i=n1;i<n2;i++)
#define put(a) cout<<a<<endl;
using namespace std;
typedef long long ll;
//typedef unsigned long long ull;
typedef pair<int, int> P;

int a,b;

int main() {
    cin >> a >> b;
    string res = "No";
    if(a*b%2!=0){
        res = "Yes";
    }
    put(res);
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#define SIZE 50001

int isPrime(int n);
void show_prev_next_prime(int n);

int main(int argc, const char *argv[])
{
	int n;

	while(scanf("%d", &n)!=EOF)
		show_prev_next_prime(n);	
	
	return 0;
}

int isPrime(int n)
{
	int i;
	if(n<=1) return 0;
	else if(n==2) return 1;
	else if(n%2==0) return 0;
	else{
		for(i=3; i*i<=n; i+=2)
			if(n%i==0) return 0;
	}
	return 1;
}

void show_prev_next_prime(int n)
{
	int i;
	for(i=n-1; isPrime(i)==0; i--);
	printf("%d ", i);
	for(i=n+1; isPrime(i)==0; i++);
	printf("%d\n", i);
}

Measured memory_bytes: 0
#include <algorithm>
#include<stdio.h>
#include <cstdio>
#include <iostream>
#include <iomanip>
#include <string>
#include <algorithm>
#include <vector>
#include <math.h>
#include<stack>
#include <queue>
#include<map>
#include <set>
#include<math.h>
using namespace std;
#define int long long
#define ll long long
#define rep(i,n) for(ll i=0;i<n;++i)
#define loop(i,m,n) for(ll i=m;i<n;++i)
#define ggr getchar(); getchar();return 0;
#define pie 3.141592653589793238462643383279
#define elif else if
#define P pair<ll,ll>
const int mod = 1000000007;
const int mod2 = 998244353;
int bin(int bina) {
	int ans = 0;
	for (int i = 0; bina > 0; i++)
	{
		ans = ans + (bina % 2) * pow(10, i);
		bina = bina / 2;
	}
	return ans;
}
bool prime(int n) {
	for (ll i = 2; i <= sqrt(n); i++) {
		if (n % i == 0)return false;
	}
	return n != 1;
}
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x % y);
}
int lcm(int x, int y) {
	return x * y / gcd(x, y);
}
int kai(int x) {
	if (x == 0)return 1;
	return kai(x - 1) * x % mod;
}
int mod_pow(int x, int y, int mod) {
	int res = 1;
	while (y > 0) {
		if (y & 1) {
			res = res * x % mod;
		}
		x = x * x % mod;
		y >>= 1;
	}
	return res;
}
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;
}
struct union_find {
	int par[200010], size_[200010];
	void init(int x) {
		rep(i, x) { par[i] = i; size_[i] = 1; }
	}
	int find(int x) {
		if (par[x] == x)return x;
		return par[x] = find(par[x]);
	}
	void unite(int x, int y) {
		x = find(x); y = find(y);
		if (x == y)return;
		if (size_[x] < size_[y]) {
			par[x] = y;
			size_[y] += size_[x];
		}
		else {
			par[y] = x;
			size_[x] += size_[y];
		}
	}
};
struct edge { int to, cost; };

signed main() {
	int a;
	string s;
	cin >> a >> s;
	if (a >= 3200)cout << s << endl;
	else cout << "red" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("unroll-loops") 
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp> 
#define int long long
#define fr(i,a,b) for(int i = a ; i <= b ; ++i)
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define all(x) begin(x), end(x)
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) (int)(x).size()
#define pb push_back
#define fst first
#define snd second
using namespace __gnu_pbds;
using ordered_set =
 tree<int, null_type,less<int>,
 rb_tree_tag,tree_order_statistics_node_update>;
//find_by_order(k):returns iterator to kth element starting from 0
//order_of_key(k):returns count of elements strictly smaller than k
typedef long long ll;typedef pair<int, int> pii;
typedef vector<int> vi;typedef long double ld;
template<class T>
using min_heap = priority_queue<T,vector<T>,greater<T>>; 
template<typename T> T gcd(T a, T b){return(b?__gcd(a,b):a);}
template<typename T> T lcm(T a, T b){return(a*(b/gcd(a,b)));}
template<typename T> 
void remdup(vector<T>& v) {
	sort(all(v)); v.erase(unique(all(v)), v.end());
}
template<typename T> void re(vector<T> &v) {trav(i,v) cin >> i;}
void unsyncIO() { ios_base::sync_with_stdio(0); cin.tie(0); }
#ifdef np
#include "C:\Users\navodit\Desktop\mycodes\pr.h"
#else
#define trace(...)
#endif

#define MOD 1000000007  





void solve(){
	vector<vi>bin(3,vector<int>(3)) , mark(3,vector<int>(3));
	rep(i,0,3) rep(j,0,3) cin >> bin[i][j];
	int n ;
	cin >> n; 
	while(n--){
		int a ;
		cin >> a ; 
		rep(i,0,3){
			rep(j,0,3){
				if(bin[i][j] == a) mark[i][j] = 1;
			}
		}
	}
	rep(i,0,3){
		if(mark[0][i] + mark[1][i] + mark[2][i] == 3){
			cout << "Yes\n";
			return ;
		}
	}
	
	rep(i,0,3){
		if(mark[i][0] + mark[i][1] + mark[i][2] == 3){
			cout << "Yes\n";
			return;
		}
	}
	if(max((mark[0][0] + mark[1][1] + mark[2][2]),(mark[1][1] + mark[2][0] + mark[0][2])) == 3){
		cout << "Yes\n";
		return ;
	}
	cout << "No\n";
}

signed main() {
	unsyncIO();
	int tt =1 ;
	// cin >> tt;
	rep(i,0,tt) solve();













#ifdef np
	cout <<endl<<endl<< "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
	return 0;
}


Measured memory_bytes: 3652
#include<iostream>
#include<set>
#include<vector>

using namespace std;

int main()
{
	int n;
	cin >> n;
	vector<int> a(n),pos(n);
	for(int i=0;i<n;i++)
		cin >> a[i];
	for(int i=0;i<n;i++)
		pos[a[i]-1]=i;
	set<int> st;

	st.insert(-1);
	st.insert(n);

	long long ans=0;
	for(int i=0;i<n;i++)
	{
		auto itr=st.lower_bound(pos[i]);
		long long right=*itr-pos[i];
		itr--;
		long long left=pos[i]-*itr;	
		ans+=(i+1)*right*left;
		st.insert(pos[i]);		
	}

	cout << ans << endl;

}


Measured memory_bytes: 11136
N = int(input())
T = list(map(int,input().split()))
M = int(input())
D = [list(map(int,input().split())) for _ in range(M)]

#print(T,D)

for i in range(M):
    temp = T.copy()
    temp[D[i][0]-1] = D[i][1]
    print(sum(temp))
    

Measured memory_bytes: 9136