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

using namespace std;

int A[234567];
bool ans[234567];

int main() {
    int N;
    cin >> N;
    for (int i = 1; i < N + 1; i++) {
        cin >> A[i];
    }
    vector < int > res;
    for (int i = N; i > 0; i--) {
        if (ans[i] != A[i]) {
            res.push_back(i);
            for (int j = 1; j * j <= i; j++) {
                if (i % j == 0) {
                    ans[j] = !ans[j];
                    if (j != i / j) {
                        ans[i / j] = !ans[i / j];
                    }
                }
            }
        }
    }
    reverse(res.begin(),res.end());
    cout << res.size() << endl;
    for (int i = 0; i < res.size(); i++) {
        cout << res[i] << ' ';
    }
    return 0;
}

Measured memory_bytes: 2552
#include<bits/stdc++.h>
#define rep(i,n)  for(ll i=0; i<n; i++)
#define vi vector<int>
#define all(x) (x).begin(),(x).end()
#define INF 1e9
using ll = long long;
using namespace std;
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; }

int main(){
  int n; cin >> n;
  map<int,int> mp;
  rep(i,n){
    int a; cin >> a;
    mp[a]++;
  }
  int q; cin >> q;
  vi b(q),c(q); rep(i,q) cin >> b[i] >> c[i];

  ll ans = 0;
  rep(i,q){
    mp[c[i]] += mp[b[i]];
    int cnt = mp[b[i]];
    mp[b[i]] = 0;
    if(i){
      if(mp.count(b[i])) ans += (c[i]-b[i])*cnt;
    }
    else for(auto x : mp) ans += x.first*x.second;
    cout << ans << "\n";
  }
  return 0;
}


Measured memory_bytes: 8464
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <queue>
#include <stack>
#include <set> 
#include <map>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstring>
#include <iomanip>
#define REP(i,n) for(int i=0; i<(n); ++i)
#define FOR(i,a,b) for(int i=(a); i<(b); ++i)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int INF = 100100100;
const ll INFLL = 100100100100100100;
const int MOD = (int)1e9 + 7;
const ll MODLL = (ll)1e9 + 7;
const double EPS = 1e-9;
 
int main () {

    int st; cin >>st;
    vector<int> a(4); 
    for (int i = 0; i < 4; i++) {
        a[i] = st % 10;
        st /= 10; 
    }
    reverse(a.begin(), a.end());

    int n = 3;
    int s = 0;
    for (; s < (1<<n); s++) {
        int sum = a[0];
        for (int i = 0; i < n; i++) {
            if (s & (1<<i)) {
                sum += a[i+1];
            } else {
                sum -= a[i+1];
            } 
        }
        if (sum == 7) {
            break;
        }
    }

    string ans = to_string(a[0]);
    for (int i = 0; i < n; i++) {
        if (s & (1<<i)) {
            ans = ans + "+" + to_string(a[i+1]);
        } else {
            ans = ans + "-" + to_string(a[i+1]);
        } 
    }
    ans = ans + "=7";

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#pragma GCC optimize ("Ofast")
#include<bits/stdc++.h>
using namespace std;
template<class S, class T> inline S min_L(S a,T b){
  return a<=b?a:b;
}
template<class S, class T> inline S max_L(S a,T b){
  return a>=b?a:b;
}
inline void rd(int &x){
  int k;
  int m=0;
  x=0;
  for(;;){
    k = getchar_unlocked();
    if(k=='-'){
      m=1;
      break;
    }
    if('0'<=k&&k<='9'){
      x=k-'0';
      break;
    }
  }
  for(;;){
    k = getchar_unlocked();
    if(k<'0'||k>'9'){
      break;
    }
    x=x*10+k-'0';
  }
  if(m){
    x=-x;
  }
}
inline void wt_L(char a){
  putchar_unlocked(a);
}
inline void wt_L(int x){
  int s=0;
  int m=0;
  char f[10];
  if(x<0){
    m=1;
    x=-x;
  }
  while(x){
    f[s++]=x%10;
    x/=10;
  }
  if(!s){
    f[s++]=0;
  }
  if(m){
    putchar_unlocked('-');
  }
  while(s--){
    putchar_unlocked(f[s]+'0');
  }
}
inline void wt_L(long long x){
  int s=0;
  int m=0;
  char f[20];
  if(x<0){
    m=1;
    x=-x;
  }
  while(x){
    f[s++]=x%10;
    x/=10;
  }
  if(!s){
    f[s++]=0;
  }
  if(m){
    putchar_unlocked('-');
  }
  while(s--){
    putchar_unlocked(f[s]+'0');
  }
}
template<class S, class T> inline S chmin(S &a, T b){
  if(a>b){
    a=b;
  }
  return a;
}
int N;
int K;
int H[300];
long long dp[300][300];
long long nx[300][300];
int main(){
  int m;
  rd(N);
  rd(K);
  {
    int Lj4PdHRW;
    for(Lj4PdHRW=(0);Lj4PdHRW<(N);Lj4PdHRW++){
      rd(H[Lj4PdHRW]);
    }
  }
  if(N==K){
    wt_L(0);
    wt_L('\n');
    return 0;
  }
  for(m=(0);m<(N);m++){
    int i;
    for(i=(0);i<(K+1);i++){
      int j;
      for(j=(0);j<(m+1);j++){
        nx[i][j] = 4611686016279904256LL;
      }
    }
    if(m<=K){
      nx[m][m] = H[m];
    }
    for(i=(0);i<(K+1);i++){
      int j;
      for(j=(0);j<(m);j++){
        chmin(nx[i][m], dp[i][j] +max_L(H[m] - H[j], 0));
      }
    }
    for(i=(0);i<(K);i++){
      int j;
      for(j=(0);j<(m);j++){
        chmin(nx[i+1][j], dp[i][j]);
      }
    }
    for(i=(0);i<(K+1);i++){
      int j;
      for(j=(0);j<(m+1);j++){
        dp[i][j] = nx[i][j];
      }
    }
  }
  {
    int AlM5nNnR;
    long long XJIcIBrW;
    if(N==0){
      XJIcIBrW = 0;
    }
    else{
      XJIcIBrW = dp[K][0];
      for(AlM5nNnR=(1);AlM5nNnR<(N);AlM5nNnR++){
        XJIcIBrW = min_L(XJIcIBrW, dp[K][AlM5nNnR]);
      }
    }
    wt_L(XJIcIBrW);
    wt_L('\n');
  }
  return 0;
}
// cLay varsion 20191123-1

// --- original code ---
// int N, K, H[300];
// ll dp[300][300], nx[300][300];
// 
// {
//   rd(N,K,H(N));
//   if(N==K) wt(0), return 0;
//   rep(m,N){
//     rep(i,K+1) rep(j,m+1) nx[i][j] = ll_inf;
//     if(m<=K) nx[m][m] = H[m];
//     rep(i,K+1) rep(j,m) nx[i][m] <?= dp[i][j] + max(H[m] - H[j], 0);
//     rep(i,K) rep(j,m) nx[i+1][j] <?= dp[i][j];
//     rep(i,K+1) rep(j,m+1) dp[i][j] = nx[i][j];
//   }
//   wt(min(dp[K](N)));
// }


Measured memory_bytes: 1408
n = int(input())
p = tuple(map(int, input().split()))
q = tuple(map(int, input().split()))

from itertools import permutations
li = [i for i in range(1, n + 1)]
ptn = list(permutations(li))

for itr, val in enumerate(ptn):
  if p == val:
    a = itr
  if q == val:
    b = itr

print(abs(a - b))

Measured memory_bytes: 8052
#include <iostream>
//#include <math.h>
#include <set>
#include<iomanip>
#include <algorithm>
#include <vector>
#include <string>
#include <map>
#include <utility>
#include <queue>
#define INF 1e9+7
#define rep(i,n) for(int i=0;i<n;i++)
#define NO cout<<"NO"<<endl;
#define YES cout << "YES"<<endl;
#define No cout << "No"<<endl;
#define Yes cout << "Yes"<<endl;
#define all(a) a.begin(),a.end()
#define P pair<int,int>
#define space ' '
#define pll pair<ll,ll>
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;

//(int)'a'は97 (int)'A'は65 (int)'1'は49
//おまじない

const int maxn = 100000;

int main(){

  int n;
  int snuke=0;
  int fennec=0;
  int pre[maxn]={0};
  bool used[maxn]={0};
  int dis=0;
  queue<int> que;
  vector<vector<int> > v(maxn);

  cin >> n;
  rep(i,n-1){
    int a,b;
    cin >> a>>b;a--;b--;
    v[a].push_back(b);
    v[b].push_back(a);
  }

  pre[0]=-1;
  que.push(0);
  used[0]=true;
  while(!que.empty()){
    int arg = que.front();que.pop();
    rep(i,v[arg].size()){
      if(!used[v[arg][i]]){
        que.push(v[arg][i]);
        used[v[arg][i]]=true;
        pre[v[arg][i]]=arg;
      }
    }
  }
  int p=n-1;
  dis = 1;
  while(pre[p]!=-1){
    dis++;
    p = pre[p];
  }
  p = n-1;
  fill(used,used+n,false);
  rep(i,dis/2){
    que.push(p);
    used[p]=true;
    p = pre[p];
    if(i==dis/2-1)used[p]=true;
  }

  while(!que.empty()){
    int arg = que.front();que.pop();
    snuke++;
    rep(i,v[arg].size()){
      if(!used[v[arg][i]]){
        que.push(v[arg][i]);
        used[v[arg][i]]=true;
      }
    }
  }
  fennec = n-snuke;
  if(fennec > snuke){
    cout << "Fennec"<<endl;
  }else{
    cout << "Snuke"<<endl;
  }

  return 0;
}


Measured memory_bytes: 6400
#include<bits/stdc++.h>
#define pb push_back
#define pf push_front
#define ppb pop_back
#define mp make_pair
#define re(i , n) for(Long i = 0; i < (Long)n ; i++)
#define rer(i, a, b) for (Long i = a, to = b; i < to; i++)
#define rll(x) Long x;cin>>x;
#define rll2(x,y) Long x,y;cin>>x>>y;
#define rll3(x,y,z) Long x,y,z;cin>>x>>y>>z;
#define rll4(x,y,z,a) Long x,y,z,a;cin>>x>>y>>z>>a;
#define rs(s) string s;cin>>s;
using namespace std;
 
typedef long long Long;
typedef pair<Long,Long> pll;
typedef pair<Long,pll> tll;
 
typedef vector<Long> vll;
typedef vector<pll> vpll;
typedef vector<tll> vtll;
typedef vector<string> vs;
typedef set<Long> si;
 
 
const long double PI = acos(-1);
const Long MX=2e5 + 1;
const Long MOD=1000000007;
const Long MX2=9223372036854775806;
 
 
int main(){
	rll3(n,m,x);
	vll c(n);
	Long v[n][m];
	re(i,n){
		cin>>c[i];
		re(j,m){
			cin>>v[i][j];
		}
	}
	Long resp=0;
	Long mini=MX2;
	for(Long mask=0;mask<(1<<n);mask++){
		resp=0;
		vll suma(m,0);
		for(Long i=0;i<n;i++){
			if((mask>>i) & 1 ==1){
				re(j,m){
					suma[j]+=v[i][j];
				}
				resp+=c[i];
			} 
		}
		bool hola=true;
		re(i,m){
			if(suma[i]<x){
				hola=false;
			}
		}
		if(hola){
			mini=min(mini,resp);
		}
		
	}
	if(mini==MX2){
		cout<<"-1";
		return 0;
	}
	cout<<mini;
	
}

Measured memory_bytes: 3616
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, a, b) for(int i = a; i < b; i++)
#define  all(x) (x).begin(),(x).end()     // 昇順ソート
#define  rall(v) (v).rbegin(), (v).rend() // 降順ソート
#define  FastIO ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
typedef long long ll;
typedef long long int lli;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return true; } return false; }

int main(){
    int n;
    string s;
    cin >> n >> s;
    if (n%2 != 0){
        cout << "No" << endl;
        return 0;
    } 
    int num = n/2;
    if (s.substr(0, num) == s.substr(num, num)){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
char s[4][4];
int main()
{
	for (int i = 1; i <= 3; i++) {
		for (int j = 1; j <= 3; j++) {
			cin >> s[i][j];
			if (i == j)cout << s[i][j];
		}
	}
	return 0;
}

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

typedef long long ll;
const ll MOD = 1e9 + 7;
const long long INF = 1LL<<60;
const double PI=3.14159265358979323846;
const int NMAX=100005;
using namespace std;

int main(){
    ll x,k,d;
    cin >> x >> k >> d;

    ll ln = abs(x)/d;
    if(abs(x)%d > d/2) ln++;

    ll ans;
    if(k < ln){
        ans = abs(x)-(d*k);
    } else {
        k -= ln;
        ans = abs(x)%d;
        if(ans > d/2) ans = d-ans;
        if(k%2 == 1){
            ans = d-ans;
            if(ln == 0){
                ans = d-abs(x);
            }
        }
    }

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

Measured memory_bytes: 3628
#include <iostream>
#include<bits/stdc++.h>
#define int long long 
using namespace std;
const long long MOD=10000007;
const int INF=1e9+5;
// bool isPowerOfTwo(int n)
// {
// 	return (n && !(n & (n-1)));

// } 



int32_t main() {
	// your code goes here
	    //long long c;cin>>c;
		long n;cin>>n;
		vector<int >h(n);
		for(int & x: h)
		   cin>>x;
		vector<int>dp(n,INF);
		dp[0]=0;
		for(int i=0;i<n;i++)
		{
			for(int j:{i+1,i+2})
			  {
			  	if(j<n)
			  	 dp[j]=min(dp[j],dp[i]+abs(h[i]-h[j]));
			  }
			  
		}
		cout<< dp[n-1]<<endl;
	


		 
	
	return 0;
}

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

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

// 4近傍、8近傍
int dx[] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[] = {0, 1, 0, -1, 1, 1, -1, -1};

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

  ll ans = 0;
  ll cnt = 0;
  for (int i = 0; i < s.size(); i++) {
    if (s[i] == 'B') {
      cnt++;
    } else {
      ans += cnt;
    }
  }

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


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
int main(){
    int N, K;
    cin >> N >> K;
    int ans = 1;
    for(int i = 0; i < N; i++){
        if(i == 0){
            ans = ans * K;
        }else{
            ans = ans * (K - 1);
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
<?php
fscanf(STDIN, "%s", $S);
fscanf(STDIN, "%d", $K);
$arr = str_split($S);
$arr = array_values(array_unique($arr));
$kind = count($arr);
 
if ($K === 1) {
    echo cnt($S);
} elseif (strlen($S) === 1) {
    echo intdiv($K, 2);
} elseif ($kind === 1) {
    echo intdiv(strlen($S) * $K, 2);
} else {
    $c1 = cnt($S);
    $c2 = cnt($S . $S);
    echo ($c2 - $c1) * ($K - 1) + $c1;
}
 
function cnt($S) {
    $len = strlen($S);
    $ret = 0;
    $tmp = 0;
    for ($i = 1; $i < $len; $i++) {
        if ($S[$i - 1] === $S[$i]) {
            $tmp++;
        }
        if ($S[$i - 1] !== $S[$i] || $len - 1 === $i) {
            $ret += intdiv($tmp + 1, 2);
            $tmp = 0;
        }
    }
    return $ret;
}

Measured memory_bytes: 4728
#include <cstdio>
#include <cmath>
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <map>
#include <queue>
#include <algorithm>

#ifdef _DEBUG
#define DMP(x) cerr << #x << ": " << x << "\n"
#else
#define DMP(x) ((void)0)
#endif

using namespace std;
using lint = long long;

#pragma GCC optimize ("Ofast", "unroll-loops")
#pragma GCC target ("arch=ivybridge")

const int nmax = 204800, block = 2048, unrl = 16;
int a[nmax], b[nmax];

int main() {

	int N;
	scanf("%d", &N);
	for (int i = 0; i < N; i++) scanf("%d", &a[i]);
	for (int i = 0; i < N; i++) scanf("%d", &b[i]);

	int ans = 0;
	for (int i = 0; i + unrl <= N; i += unrl) {
		for (int j = 0; j + block <= N; j += block) {
			for (int k = j; k < block + j; k++) {

				ans ^= (a[i + 0] + b[k]) ^ (a[i + 1] + b[k]);
				ans ^= (a[i + 2] + b[k]) ^ (a[i + 3] + b[k]);
				ans ^= (a[i + 4] + b[k]) ^ (a[i + 5] + b[k]);
				ans ^= (a[i + 6] + b[k]) ^ (a[i + 7] + b[k]);
              	ans ^= (a[i + 8] + b[k]) ^ (a[i + 9] + b[k]);
				ans ^= (a[i + 10] + b[k]) ^ (a[i + 11] + b[k]);
				ans ^= (a[i + 12] + b[k]) ^ (a[i + 13] + b[k]);
				ans ^= (a[i + 14] + b[k]) ^ (a[i + 15] + b[k]);

			}
		}
	}

	for (int i = 0; i < N / unrl * unrl; i++) {
		for (int j = N / block * block; j < N; j++) {
			ans ^= a[i] + b[j];
		}
	}	
	for (int i = N / unrl * unrl; i < N; i++) {
		for (int j = 0; j < N; j++) {
			ans ^= a[i] + b[j];
		}
	}

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

	return 0;
}


Measured memory_bytes: 1792
#include <stdio.h>
#include <math.h>
int main(void){
    double x1,y1,x2,y2;
    scanf("%lf %lf %lf %lf",&x1,&y1,&x2,&y2);
    printf("%.8lf\n",sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2)));
    
    return 0;
}



Measured memory_bytes: 2048
#include <stdio.h>


int main(){
	int i, j, k, cont=0, vet[5];
	for(i=0;i<5;i++){
		scanf("%i", &vet[i]);
	}
	scanf("%i", &k);
	for(i=0;i<5;i++){
		for(j=i+1; j<5; j++){
			if((vet[j]-vet[i])>k){
				cont++;
			}
		}
	}
	if(cont==0)
		printf("Yay!\n");
	else
		printf(":(\n");
}

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

int main() {

    int N, D;
    cin >> N >> D;
    int X[N][D];
    for(int i = 0; i < N; i++){
        for(int j = 0; j < D; j++){
            cin >> X[i][j];
        }
    }
    int ans = 0;
    for(int i = 0; i < N; i++){
        for(int j = i; j < N; j++){
            if(i==j){
                continue;
            }

            int diff2sum = 0;
            for(int k = 0; k < D; k++){
                diff2sum += ((X[i][k] - X[j][k]) * (X[i][k] - X[j][k]));
            }
            double diff = sqrt(diff2sum);

            if(ceil(diff) == floor(diff)){
                ans++;
            }
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3532
#include <bits/stdc++.h>
#define REP(i,n) for (int i = 0; i < (n); i++)
#define ALL(a) a.begin(), a.end()
#define RALL(a) a.rbegin(), a.rend()
using namespace std;
using ll = long long;
const ll MOD = 1000000007;
const ll INF = MOD * MOD;

int N, K;
vector<int> D(10, 0);

int main() {

    cin >> N >> K;
    for (int i = 0; i < K; i++){
        int x;
        cin >> x;
        D[x] ++;
    }

    for (int i = N;; i++) {
        string s = to_string(i);
        bool ok = true;
        for (int j = 0; j < s.size(); j++) {
            if( D[s[j] - '0'] ) ok = false;
        }
        if(ok) {
            cout << i << endl;
            return 0;
        }
        
    }

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
#define all(x) (x).begin(), (x).end()
#define endl '\n'
#define fsp(x) cout << fixed << setprecision(x)
const ll inf = LLONG_MAX;
const long double pi = M_PI;
void Yes() {cout << "Yes" << endl;}
void No() {cout << "No" << endl;}
void YES() {cout << "YES" << endl;}
void NO() {cout << "NO" << endl;}

int main() {
  ll n;
  string s;
  cin >> n >> s;
  ll r = 0, b = 0;
  for (ll i = 0; i < n; i++) {
    if (s[i] == 'R') r++;
    else b++;
  }
  if (r > b) Yes();
  else No();
}

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

int main(){
  int a,b;
  cin >> a >> b;
  if(a>b){
      for(int i=0; i<a; i++){
          cout <<b;
      }
     cout << endl;
  }else{
    for(int i=0; i<b; i++){
          cout <<a;
      }
      cout << endl;
  }

   return 0;   
}

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

int main(void) {
  int N;
  cin >> N;
  vector<long long> A(N);
  for (int i = 0; i < N; i++) {
    cin >> A[i];
  }

  vector<long long> L(N), R(N);
  L[1] = A[0];
  R[N - 2] = A[N - 1];
  for (int i = 2; i < N; i++) {
    L[i] = __gcd(L[i - 1], A[i - 1]);
  }
  for (int i = N - 3; i >= 0; i--) {
    R[i] = __gcd(R[i + 1], A[i + 1]);
  }
  long long ans = R[0];
  for (int i = 1; i < N - 1; i++) {
    ans = max(ans, __gcd(L[i], R[i]));
  }
  ans = max(L[N - 1], ans);
  cout << ans << endl;
  return 0;
}

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

#define SIZE 2000000

int myatoi(const char* p)
{
  int n=0;
  while (*p!='\n') {
    n = n*10+*p-'0';
    p++;
  }
  return n;
}

void putnum(int n)
{
  int i;
  char buf[20];
  buf[19]='\0';
  for (i=18; n>0; n/=10) buf[i--]=(n%10)+'0';
  puts(buf+i+1);
}

int main() {
  int A[SIZE];
  int H=0;
  int i, l, largest, tmp;
  char com[21];
  do {
    fgets(com, 20, stdin);
    if (com[0] == 'i') {
      A[++H] =myatoi(com+7);
      for (i=H; i>1 && A[i/2]<A[i];i/=2) {
        tmp = A[i/2];
        A[i/2] = A[i];
        A[i] = tmp;
      }

    } else if (com[1]=='x') { // extract
      putnum(A[1]);
      A[1] = A[H];
      i = 1;
      while (1) {
        l = i*2;
        largest = i;
        if (l < H && A[l] > A[i])        largest = l;
        if (l+1 < H && A[l+1] > A[largest])  largest = l+1;
        if (largest == i) break;
        tmp = A[i];
        A[i] = A[largest];
        A[largest] = tmp;
        i = largest;
      }
      H--;
    }
  } while (com[2]!='d');
  return 0;
}


Measured memory_bytes: 5448
#145_D
x,y=map(int,input().split())
mod=10**9+7
if (x+y)%3!=0:
    print(0)
else:
    n=(2*x-y)//3
    m=(2*y-x)//3
    if n<0 or m<0:
        print(0)
    else:
        f=[1 for i in range(m+n+1)]
        for i in range(2,m+n+1):
            f[i]=f[i-1]*i%mod
        print(f[m+n]*pow(f[n],mod-2,mod)*pow(f[m],mod-2,mod)%mod)

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

int main() {
  int h, w, k;
  cin>>h>>w>>k;
  string s[h];
  for (int i=0; i<h; i++) cin>>s[i];
  int acc[h][w+1];
  for (int i=0; i<h; i++) {
    acc[i][0] = 0;
    for (int j=0; j<w; j++) {
      acc[i][j+1] = acc[i][j];
      if (s[i][j] == '1') {
        ++acc[i][j+1];
      }
    }
  }
  int ans = h * w;
  for (int x=0; x<1<<(h-1); x++) {
    vector<vector<int>> v;
    vector<int> tmp;
    tmp.push_back(0);
    int cnt = 0;
    for (int i=0; i<h-1; i++) {
      if ((x >> i) & 1) {
        v.push_back(tmp);
        tmp.clear();
        tmp.push_back(i+1);
        ++cnt;
      } else {
        tmp.push_back(i+1);
      }
    }
    v.push_back(tmp);
    int tmp_acc[v.size()][w+1];
    for (int i=0; i<w+1; i++) {
      for (int j=0; j<v.size(); j++) {
        tmp_acc[j][i] = 0;
        for (int l: v[j]) {
          tmp_acc[j][i] += acc[l][i];
        }
      }
    }
    bool ok = true;
    for (int i=0; i<v.size(); i++) {
      for (int j=0; j<w; j++) {
        if (tmp_acc[i][j+1] - tmp_acc[i][j] > k) {
          ok = false;
          break;
        }
      }
      if (!ok) {
        break;
      }
    }
    if (!ok) {
      continue;
    }
    int prev = 0;
    for (int i=2; i<w+1; i++) {
      for (int j=0; j<v.size(); j++) {
        if (tmp_acc[j][i] - tmp_acc[j][prev] > k) {
          ++cnt;
          prev = i-1;
          break;
        }
      }
    }
    ans = min(cnt, ans);
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 384
#include<stdio.h>
int main()
{
	int H, W, i, j;

	while (1)
	{
		scanf("%d %d", &H, &W);
		if ((H == 0) && (W == 0))
			break;
		for (i = 0; i < H; i++)
		{

			for (j = 0; j < W; j++)
			{
				printf("#");
			}
			printf("\n");
		}
		printf("\n");
	}


	return(0);
}

Measured memory_bytes: 572
#include<vector>
#include<iostream>
#include<stdio.h>
#include<stdlib.h>
#include <iostream>
#include <algorithm>
#include <map>
#include <cmath>
#include<queue>
#include <sstream>
#include <set>
#include<stack>
#include <utility>
#define INF 1000000000000
const long long MOD = 1000000007;

using namespace std;
typedef long long llong;

//int isalpha(char ch): ch がアルファベットなら true を返す
//int isdigit(char ch): ch が数字なら true を返す
//int islower(char ch): ch が小文字なら true を返す
//int isupper(char ch): ch が大文字なら true を返す
//int tolower(char ch): ch の小文字を返す
//int toupper(char ch): ch の大文字を返す

//string型
//size()	文字数を返す
//Insert()	（指定した場所に）文字・文字列を挿入する
//erase()	（指定した場所の）文字・文字列を削除する
//clear()	すべての文字を削除する
//substr()	文字列の（指定した）部分文字列を返す
//replace()	（指定した）部分文字列を新しい文字列に置換する
//c_str()変換
//文字列の比較は、<=や==などを使え
//replace関数を使い、簡単に文字列を置換
//リバース関数：reverse(str.begin(), str.end());
//map<type, type> dict;で宣言
//グラフ理論用変数
//vector<vector<llong> > graph(N);

//ソート
//降順sort(v.begin(), v.end(), std::greater<Type>());

//大文字から小文字へんかん
//w[i] = w[i]-'A'+'a';

//vector
//assignメソッド　引数：サイズ、値
//与えられたサイズと値でvectorを初期化する

//queueクラス
//find()次に取り出す値の表示をする。
//pop()値を取り出す。戻り値はなし
//push()キューに値をプッシュする

//priority_queueクラス

//切り上げ
//ceil
//floor

int main(){
    llong N;
    llong ans=0;
    cin >> N;
    vector<llong> A(N, 0);
    for(int i=0; i<N; i++){
        cin >> A[i];
    }
    map<llong, llong> dict;

    for(int i=0; i<N; i++){
        ans += dict[i-A[i]];
        dict[A[i]+i]++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 26832
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		int i;
		Scanner sc = new Scanner(System.in);
		String S = sc.next();
		String T = sc.next();
		String[] s = S.split("");
		String[] t = T.split("");
		int[] start = new int[26];
		int[] goal = new int[26];
		for (i = 0; i < 26; i++) {
			start[i] = -1;
			goal[i] = -1;
		}
		for (i = 0; i < s.length; i++) {
			 char[] x = s[i].toCharArray();
			 char[] y = t[i].toCharArray();
			 int a = x[0] - 'a';
			 int b = y[0] - 'a';

			 if (start[a] != -1 || goal[b] != -1) {
				 if (start[a] != b || goal[b] != a) {
					 System.out.println("No");
					 return;
				 }
			 }

			 start[a] = b;
			 goal[b] = a;
		}
		System.out.println("Yes");
	}
}

Measured memory_bytes: 68264
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>
//#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

ll dfs(int n, string s, ll sum){
  if( n == 0 ){
    return sum + stoll(s);
  }
  string s0 = s.substr(0, s.size() - n);
  string s1 = s.substr(s.size() - n, s.size() - 1);
  //cout << "s0:"<< s0 << " s1:" << s1 << endl; 
  int temp = stoll(s0);
  return dfs( n - 1, s, sum) + dfs( n - 1, s1, sum + temp);
}
int main(){
  ll ans = 0;
  string S;
  cin >> S;
  ans = dfs(S.size()-1,S,0);
  cout << ans << endl;
  return 0;
}

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

using namespace std;

#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;

void Main()
{
	int a, b, c;
	cin >> a >> b >> c;
	if(a < b && b < c){
		cout << "Yes" << endl;
	}else{
		cout << "No" << endl;
	}
}

int main()
{
	std::cin.tie(nullptr);
	std::ios_base::sync_with_stdio(false);
	std::cout << std::fixed << std::setprecision(15);
	Main();
	return 0;
}



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

using namespace std;

inline void Boost() {
	ios::sync_with_stdio(false);
	cin.tie(NULL); cout.tie(NULL);
}
typedef long long int ll;
typedef long double ld;

const int NMax = 1e5 + 50;
const int LIM = 1e9;

struct op {
	int l, r, d;
};

int in[NMax];
int pos[NMax];
op v[2 * NMax];
vector < pair < int, int > > G[NMax];
vector < pair < int, int > > revG[NMax];

void SolveG(int node);
void SolveRev(int node);

void SolveG(int node) {
	for(auto it: G[node]) {
		if(pos[it.first] == -1) {
			pos[it.first] = pos[node] + it.second;
			SolveRev(it.first); 
			SolveG(it.first);
		}
	}
}
void SolveRev(int node) {
	for(auto it: revG[node]) {
		if(pos[it.first] == -1) {
			pos[it.first] = pos[node] + it.second;
			SolveG(it.first); 
			SolveRev(it.first);
		}
	}
}

int main() {
	Boost();

	int n, m;
	cin >> n >> m;

	for(int i = 1; i <= n; ++i) pos[i] = -1;

	for(int i = 1; i <= m; ++i) {
		cin >> v[i].l >> v[i].r >> v[i].d;
		G[v[i].l].push_back({v[i].r, v[i].d});
		revG[v[i].r].push_back({v[i].l, -v[i].d});
		in[v[i].r]++;
	}

	for(int i = 1; i <= n; ++i) {
		if(in[i] == 0 && pos[i] == -1) {
			if(pos[i] == -1) pos[i] = LIM;
			SolveG(i);
		}
	}

	// for(int i = 1; i <= n; ++i) cout << pos[i] << " ";
	// cout << endl;

	for(int i = 1; i <= m; ++i) {
		if(pos[v[i].r] - pos[v[i].l] != v[i].d) {
			cout << "No";
			exit(0);
		}
	}

	cout << "Yes";
	return 0;
}

Measured memory_bytes: 18176
#include <bits/stdc++.h>
#include <stdio.h>
#define fin freopen("input", "r", stdin)
#define whatis(x) cerr << #x << ": " << x << endl;

using namespace std;
using ll = long long;

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

    int n;
    cin >> n;
    vector<pair<int,int>> ar(n);
    for (int i = 0; i < n; ++i) {
        cin >> ar[i].first;
        ar[i].second = i + 1;
    }

    sort(ar.begin(), ar.end());
    for (auto i : ar) cout << i.second << ' ';
    cout << endl;


    return 0;
}


Measured memory_bytes: 1664
#include<stdio.h>
#include<math.h>
#include<string.h>
#include<ctype.h>
#include<stdlib.h>
#define STR 10
int main(){
    int h1,h2,m1,m2,k,i1,i2,okiterumin,ans;
    scanf("%d %d %d %d %d",&h1,&m1,&h2,&m2,&k);
    i1=h1*60+m1;
    i2=h2*60+m2;
    okiterumin=i2-i1;
    ans=okiterumin-k;
    printf("%d",ans);
    return 0;
}

Measured memory_bytes: 1732
N = int(input())
tmp = [list(map(int, input().split())) for _ in range(3)]
A = tmp[0]
B = tmp[1]
C = tmp[2]
A = list(map(lambda x:x-1,A))
result = B[A[0]]
for i in range(1,N):
  result += B[A[i]]
  if (A[i]-1)==A[i-1]:
    result += C[A[i-1]]
    
print(result)

Measured memory_bytes: 3064
#define _USE_MATH_DEFINES
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <cstdio>
#include <complex>
#include <numeric>
#include <string.h>
#include <random>
#include <cmath>
#define rep(i,n) for (int i = 0; i < (int)n; i++)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pi;
typedef pair<pi, pi> pp;
typedef pair<ll, ll> pl;
double PI = 3.141592653589793238462643383279;
const double EPS = 1e-9;
const ll MOD = 1000000007;
//const ll MOD = 998244353
const int inf = 1 << 30;
const ll linf = 1LL << 60;

ll X, Y;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> X >> Y;
    ll ans = 0;
    if (X <= 3) ans += 100000*(4-X);
    if (Y <= 3) ans += 100000*(4-Y);
    if (X == 1 && Y == 1) ans += 400000;
    cout << ans << endl;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <string>
#include <vector>
#include <utility>
#include <complex>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <deque>
#include <tuple>
#include <bitset>
#include <algorithm>
#include <random>
#include <regex>
using namespace std;
typedef long double ld;
typedef long long ll;
typedef vector<int> vint;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
typedef complex<ld> compd;
#define reach(i,a)	for(auto i:a)
#define rep(i,n)	for(int i=0;i<(int)n;i++)
#define REP(i,n)	for(int i=0;i<=(int)n;i++)
#define srep(i,a,n)	for(int i=a;i<(int)n;i++)
#define SREP(i,a,n)	for(int i=a;i<=(int)n;i++)
#define rrep(i,n)	for(int i=n-1;i>=0;i--)
#define RREP(i,n)	for(int i=n;i>=0;i--)
#define all(a)	(a).begin(),(a).end()
#define mp(a,b)	make_pair(a,b)
#define mt	make_tuple
#define pb	push_back
#define fst	first
#define scn second
int bitcnt(ll x) {
	x = ((x & 0xAAAAAAAAAAAAAAAA) >> 1) + (x & 0x5555555555555555);
	x = ((x & 0xCCCCCCCCCCCCCCCC) >> 2) + (x & 0x3333333333333333);
	x = ((x & 0xF0F0F0F0F0F0F0F0) >> 4) + (x & 0x0F0F0F0F0F0F0F0F);
	x = ((x & 0xFF00FF00FF00FF00) >> 8) + (x & 0x00FF00FF00FF00FF);
	x = ((x & 0xFFFF0000FFFF0000) >> 16) + (x & 0x0000FFFF0000FFFF);
	x = ((x & 0xFFFFFFFF00000000) >> 32) + (x & 0x00000000FFFFFFFF);
	return x;
}
int bitcnt(int x) {
	x = ((x & 0xAAAAAAAA) >> 1) + (x & 0x55555555);
	x = ((x & 0xCCCCCCCC) >> 2) + (x & 0x33333333);
	x = ((x & 0xF0F0F0F0) >> 4) + (x & 0x0F0F0F0F);
	x = ((x & 0xFF00FF00) >> 8) + (x & 0x00FF00FF);
	x = ((x & 0xFFFF0000) >> 16) + (x & 0x0000FFFF);
	return x;
}
ll gcd(ll a, ll b) {
	return a%b == 0 ? b : gcd(b, a%b);
}
#define debug(x)	cout<<"case #" << x << ": " << endl
#define DEBUG 0
const ll inf = 1e18;
const ll mod = 1e9 + 7;
const ld eps = 1e-9;
const int dx[] = { 1,0,-1,0 };
const int dy[] = { 0,1,0,-1 };

int main() {
	int n;	cin >> n;
	int left = 0, right = n;
	cout << 0 << endl;
	string sl;	cin >> sl;
	if (sl == "Vacant")	return 0;
	while (left + 2 < right) {
		int mid = (left + right) / 2;
		cout << mid << endl;
		string sm;	cin >> sm;
		if (sm == "Vacant")	return 0;
		if ((sm == sl)^(left % 2 == mid % 2)) {
			right = mid;
		}
		else {
			left = mid;
			sl = sm;
		}
	}
	srep(i, left, right) {
		cout << i << endl;
		string s;	cin >> s;
		if (s == "Vacant")	return 0;
	}
	return 0;
}
// 99999 10000
// 0,99997=Male

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

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

  cout << (a + b + 1) / 2 << endl;
  return 0;
}

Measured memory_bytes: 3636
//#include"pch.h"
//#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<stdlib.h>
#include<cmath>
#include<math.h>
#include<string>
#include<string.h>
#include<algorithm>
#include<iostream>

using namespace std;
int main() {

	int N, A, B, tmp = 0;
	int sum = 0;
	cin >> N >> A >> B;
	for (int i = 0; i < N; i++) {
		tmp = (N - i) % 10 + (N - i) % 100 / 10 + (N - i) % 1000 / 100 + (N - i) % 10000 / 1000 + (N - i) / 10000;
		if (A <= tmp && tmp <= B)sum += N - i;
	}
	cout << sum << endl;



	return(0);
}

Measured memory_bytes: 256
import os, sys, re, math

N = int(input())
S = dict()
for i in range(N):
    w = ''.join(sorted(input()))
    if w in S:
        S[w] += 1
    else:
        S[w] = 1

count = 0
for (w, n) in S.items():
    if n > 1:
        count += (n * (n - 1)) // 2
print(count)


Measured memory_bytes: 18096
import sys


def read():
    return sys.stdin.buffer.readline().rstrip()


class FenwickTree:
    def __init__(self, n):
        self._n = n
        self._a = [0] * n

    def add(self, i, x):
        i += 1
        while i <= self._n:
            self._a[i - 1] += x
            i += i & -i

    def sum(self, l, r):
        return self._sum(r) - self._sum(l)

    def _sum(self, r):
        s = 0
        while r > 0:
            s += self._a[r - 1]
            r -= r & -r
        return s


def main():
    n, q = map(int, read().split())
    fw = FenwickTree(n)
    for i, ai in enumerate(map(int, read().split())):
        fw.add(i, ai)
    for _ in range(q):
        query = [int(i) for i in read().split()]
        if query[0] == 0:
            fw.add(query[1], query[2])
        else:
            print(fw.sum(query[1], query[2]))


if __name__ == '__main__':
    main()


Measured memory_bytes: 123256
def soinsuubunkai(n):
    i = 2
    list = [1]
    while i**2 <= n:
        if n%i == 0:
            list.append(i)
            if i != n//i:
                list.append(n//i)
        i += 1
    list.append(n)
    return list
n, m = map(int, input().split())
l = soinsuubunkai(m)
l.sort()
r = len(l)
for i in range(r):
    if m//l[r-i-1] >= n:
        print(l[r-i-1])
        quit()



Measured memory_bytes: 38640
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<n ; ++i)
#define REP(i,a,b) for(int i=a; i<b; ++i)
typedef long long ll;
//プロトタイプ宣言
int gcd(int , int);


int main(){
  int n,k,q;
  cin >> n >> k >> q;
  vector<int> a(q),count(n,k);
  rep(i,q) cin >> a[i];
  rep(i,n) count[i] -= q;
  rep(i,q){
    count[a[i] - 1]++;    
  }
  rep(i,n){
    if(count[i] > 0) cout << "Yes" << endl;
    else cout << "No" << endl;
  }
  
}








































//以下、ライブラリ
//ユークリッドの互除法

int gcd(int a, int b) {
  return b ? gcd(b, a%b) : a;
}



Measured memory_bytes: 1408
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

using std::cerr;
using std::cin;
using std::cout;
using std::endl;

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

  //0,1,2→2回
  //0,1,1→2回

  //「単調増加部」「前と同じ」で分ける
  //0,3,4とかは構成不可なので気をつける

  int n;
  cin>>n;
  std::vector<int64_t> a(n);
  for(int i=0;i<n;i++){
    cin>>a[i];
    if(a[i]>i){
      cout<<-1<<endl;
      return 0;
    }
  }
  for(int i=1;i<n;i++){
    if(a[i-1]<a[i]&&a[i-1]+1!=a[i]){
      cout<<-1<<endl;
      return 0;
    }
  }
  int64_t result=0;
  int stair[200000]={};
  int id=1;
  for(int i=1;i<n;i++){
    if(a[i-1]+1==a[i]){
      stair[i-1]=id;
      stair[i]=id;
    }else{
      id++;
    }
  }
  for(int i=0;i<n-1;i++){
    if(stair[i]==0){
      result+=a[i];
    }

    else if(stair[i]!=stair[i+1]){
      result+=a[i];
    }
  }


    result+=a[n-1];

  cout<<result<<endl;




  
  return 0;
}


Measured memory_bytes: 2560
import java.util.Scanner;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int area = a*b;
        int length =2*(a+b) ;
        System.out.println(area + " " + length);
        }
    }
 


Measured memory_bytes: 26180
//高知能系Vtuberの高井茅乃です。
//Twitter: https://twitter.com/takaichino
//YouTube: https://www.youtube.com/channel/UCTOxnI3eOI_o1HRgzq-LEZw

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

#define INF 1999999999
#define REP(i,n) for(int i=0;i<n;i++)
#define REP1(i,n) for(int i=1;i<=n;i++)
#define MODA 1000000007 

int main() {
	int ans = 0;
	int tmp;
	ll x;
	cin >> x;
	ll a, b;
	bool ch = false;
	for(a = -1000; a <= 1000; a++){
		for(b = -1000; b <= 1000; b++){
			ll d = pow(a, 5) - pow(b, 5);
			if(d == x){
				ch = true;
				break;
			}
		}
		if(ch) break;
	}
	cout << a << " " << b << endl;
}

Measured memory_bytes: 4008
#include<cstdio>
#include<iostream>
#include<cstring>
#include<cmath>
#include<algorithm>
#define ll long long
using namespace std;
char s[300010];
int qianw[300010],houe[300010],houw[300010],qiane[300010];
int main()
{
	int n;
	scanf("%d",&n);
	scanf("%s",s+1);
	for(int i=1;i<=n;i++)
	{
		qiane[i]=qiane[i-1];
		qianw[i]=qianw[i-1];
		if(s[i]=='E') qiane[i]++;
		else qianw[i]++;
	}
	for(int i=n;i>=1;i--)
	{
		houe[i]=houe[i+1];
		houw[i]=houw[i+1];
		if(s[i]=='E') houe[i]++;
		else houw[i]++;
	}
	int ans=1e9;
	for(int i=1;i<=n;i++)
	{
		ans=min(ans,qianw[i-1]+houe[i+1]);
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 5248
#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
#include <cstdio>
#include <string>
#include <cmath>
#include <queue>
#include <tuple>
#include <bitset>
#include <cassert>
#include <chrono>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <random>
#include <set>
#include <stack>
#include <time.h>

//#include <bits/stdc++.h>
#define maxs(x,y) x = max(x,y)
#define mins(x,y) x = min(x,y)
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define repr(i, n) for (int i = (n) - 1; i >= 0; i--)
#define FOR(i,i0,n) for(int (i)=(i0);(i)<(n);(i)++)
#define FORR(i,i0,n) for(int (i)=(n)-1; (i)>=(i0);(i)--)
#define SORT(x) sort(x.begin(),x.end())
#define SORTR(x) sort(x.begin(),x.end(),greater<int>())
#define rn return
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define mt make_tuple

using namespace std;
using ll = long long;
typedef std::pair<int,int> pii;
typedef std::pair<int,double> pid;
typedef std::vector<int> vi;
typedef std::vector<pii> vii;

#define PI 3.14159265358979323846264338327950L
const int mod = 1000000007;



void solve(){
    int r,g,b,n;
    cin >> r >> g >> b >> n;
    
    int ans =  0;
    for(int i = 0; i <= 3000; i++){
        for(int j = 0; j <= 3000;j++){
            int cur = i*r + g*j;
            int need = n-cur;
            if (need < 0) continue;
            if (need%b == 0) ans++;
        }
    }
    cout << ans;
    
}



int main(){
    int T;
    T = 1;
    // cin >> T;
    while(T--){
        solve();
        cout << endl;
    }
}





































Measured memory_bytes: 3616
#include <bits/stdc++.h>
#define rep(i, n) for(ll i = 0; i < n; i++)
#define repr(i, n) for(ll i = n; i >= 0; i--)
#define inf LLONG_MAX
#define all(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;

class UnionFind {
    vector<ll> par;
    public:
        UnionFind(ll n) {
            par.resize(n);
            rep(i, n) {
                par[i] = i;
            }
        }

        ll root(ll a) {
            if (par[a] == a) {
                return a;
            } else {
                return par[a] = root(par[a]);
            }
        }

        bool is_same(ll a, ll b) {
            return root(a) == root(b);
        }

        void unite(ll a, ll b) {
            ll ra = root(a);
            ll rb = root(b);
            if (ra == rb) return;
            par[ra] = rb;
        }

        void printall() {
            rep(i, this->par.size()) {
                cout << i << ": " << this->par[i] << endl;
            }
        }
};


int main()
{
    ll n, m; cin >> n >> m;
    vector<pair<ll, ll>> ab(m);
    ll count = 0;
    rep(i, m) {
        ll a, b; cin >> a >> b;
        ab[i] = make_pair(a-1, b-1);
    }
    
    rep(i, m) {
        UnionFind uf = UnionFind(n);
        rep(j, m) {
            if (j == i) continue;
            auto elem = ab[j];
            uf.unite(elem.first, elem.second);
        }

        if (!uf.is_same(ab[i].first, ab[i].second)) {
            count++;
        }
    }

    cout << count << endl;


    return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
//#include<cctype>
#include<climits>
#include<iostream>
#include<string>
#include<vector>
#include<map>
//#include<list>
#include<queue>
#include<deque>
#include<algorithm>
//#include<numeric>
#include<utility>
#include<complex>
//#include<memory>
#include<functional>
#include<cassert>
#include<set>
#include<stack>

const int dx[] = {1, 0, -1, 0};
const int dy[] = {0, 1, 0, -1};
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int, int> pii;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int T;
    cin >> T;
    while (T--) {
        string s;
        cin >> s;
        int n = s.size();
        vector<int> v(n);
        for (int i = 0; i < n; i++) v[i] = s[i]-'0';
        int turn = 0;
        while (v.size() > 1) {
            int p = v.back(); v.pop_back();
            int q = v.back(); v.pop_back();
            if (p+q < 10) v.push_back(p+q);
            else {
                v.push_back(1);
                v.push_back((p+q)%10);
            }
            turn++;
        }
        if (turn%2 == 0) cout << "Audrey wins." << endl;
        else cout << "Fabre wins." << endl;
    }
    return 0;
}

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

#define rep(i,n) for(int i=0;i<n;i++)
#define repn(i,n) for(int i=1;i<=n;i++)
#define LL long long
#define pii pair <int,int>
#define fi first
#define se second
#define pb push_back
#define mpr make_pair

using namespace std;

const LL MOD=1e9+7;

string s;
int num[30],ans=0,z[500010];
bool bad[500010],bad2[500010];

void calcZ()
{
	int lb=0,ub=0;
	repn(i,s.size()-1)
	{
		if(s[i]!=s[0]) continue;
		if(i>ub)
		{
			int p=i;
			while(p<s.size()&&s[p]==s[p-i]) p++;
			lb=i;
			ub=p-1;
			z[i]=p-i;
		}
		else
		{
			int j=i-lb;
			if(j+z[j]-1<ub-lb) z[i]=z[j];
			else
			{
				int p=ub+1;
				while(p<s.size()&&s[p]==s[p-i]) p++;
				z[i]=p-i;
				lb=i;
				ub=p-1;
			}
		}
	}
}

int main()
{
	cin>>s;
	rep(i,s.size()) num[s[i]-'a']++;
	rep(i,26)
	{
		if(num[i]==s.size())
		{
			cout<<s.size()<<endl<<1<<endl;
			return 0;
		}
	}
	calcZ();
	rep(i,s.size())
	{
		if(bad[i]) continue;
		for(int j=i+1;j+i<s.size();j+=i+1)
		{
			if(z[j]>=i+1) bad[j+i]=true;
			else break;
		}
	}
	if(!bad[s.size()-1])
	{
		cout<<1<<endl<<1<<endl;
		return 0;
	}
	memset(z,0,sizeof(z));
	reverse(s.begin(),s.end());
	calcZ();
	rep(i,s.size())
	{
		if(bad2[i]) continue;
		for(int j=i+1;j+i<s.size();j+=i+1)
		{
			if(z[j]>=i+1) bad2[j+i]=true;
			else break;
		}
	}
	rep(i,s.size()-1) if(!bad[i]&& !bad2[s.size()-i-2]) ans++;
	cout<<2<<endl<<ans<<endl;
	return 0;
}

Measured memory_bytes: 3844
#include<iostream>
#include<vector>

using namespace std;
int main(){
    int N, Q;
    vector<int> A;
    vector<long long int> S;
    int i;
    int count_max;
    long long int Si;

    int count[100000+1] = {};

    cin >> N;
    for(i=0; i<N; i++){
        int ai;
        cin >> ai;
        A.push_back(ai);
        count[ai] += 1;
        Si += ai;
    }
    
    cin >> Q;

    int count_bi;
    int bi, ci;
    for(i=0; i<Q; i++){
        cin >> bi >> ci;
        count_bi = count[bi];    
        Si = Si - (count_bi * bi) + (count_bi * ci);    
        count[ci] = count[ci] + count_bi;
        count[bi] = count[bi] - count_bi;;
        S.push_back(Si);
    }

    for(i=0; i<Q; i++){
        cout << S[i] << endl;
    }

    return 0;

}


Measured memory_bytes: 4620
#include <iostream>
#include <algorithm>
#include <cstdint>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <bitset>
#include <string>
#include <boost/range/irange.hpp>

using namespace std;
using boost::irange;

int main()
{
    int n;
    cin >> n;
    vector<int> as(n);
    for(auto& a:as) cin >> a;
    
    vector<int> xs(n);
    
    for(int i = 0; i < n; ++i)
    {
        if(i % 2 == 0)
        {
            xs.back() += as[i];
        }
        else
        {
            xs.back() -= as[i];
        }
    }
    xs[0] = 2 * as[0] - xs.back();
    for(int i = 1; i < n - 1; ++i)
    {
        xs[i] = 2 * as[i] - xs[i-1];
    }
    
    cout << xs.back() << ' ';
    for(int i = 0; i < n-1; ++i) cout << xs[i] << ' ';
    cout << '\n';
    
    return 0;
}


Measured memory_bytes: 2048
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<int64_t,int64_t> pll;
typedef vector<int64_t> vl;
int dx[]={1,-1,0,0,1,-1,1,-1};
int dy[]={0,0,1,-1,1,-1,-1,1};
const long double PI = acos(-1);
#define INF (2147483647)
#define mod (1000000007)
#define limit (7368791)
#define rep(i,a,b) for (int64_t i = (a); i < (b); i++)
#define REP(i,n) rep(i,0,n)
#define sz(s) (s).size()
#define ALL(a) begin(a),end(a)
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define fi first
#define se second

void solve() 
{
    int n,m;cin>>n>>m;
    bool acwa[n];int wacnt[n];
    REP(i,n){acwa[i]=0;wacnt[i]=0;}
    REP(i,m){
        int p;string s;
        cin>>p>>s;p--;
        if(s=="WA"&&!acwa[p]){
            wacnt[p]++;
        }else if(s=="AC"){
            acwa[p]=1;
        }
    }
    int ans=0,sum=0;;
    REP(i,n){
        if(acwa[i]){ans++;sum+=wacnt[i];}
    }
    cout<<ans<<" "<<sum<<endl;
}
int main()
{
    cin.tie(0);
	ios::sync_with_stdio(false);
    solve();
    return 0;
}


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

int solve();

int main()
{
	printf("%d\n", solve());
	return 0;
}

int solve()
{
	int n, count{};
	scanf("%d", &n);
	std::vector<long long> plus, a(n), b(n);
	long long minus{};
	for (auto& e: a) scanf("%lld", &e);
	for (int i{}; i < n; i++)
	{
		scanf("%lld", &b[i]);
		if (a[i] > b[i])
			plus.push_back(a[i] - b[i]);
		else if (a[i] < b[i])
		{
			minus += b[i] - a[i];
			count++;
		}
	}
	if (minus == 0) return 0;
	std::sort(plus.rbegin(), plus.rend());
	for (unsigned int i{1}; i < plus.size(); i++)
		plus[i] += plus[i - 1];
	for (unsigned int i{}; i < plus.size(); i++)
	{
		count++;
		if (minus <= plus[i]) return count;
	}

	return -1;
}

Measured memory_bytes: 2428
def main():
    X,K,D = map(int,input().split())
    cnt = 0
    #k回以内でできるだけ0に同じ符号で近づける:s
    #そして同じ方向にもう一度だけ動かす:t
    if X == 0:
        s = 0
        t = s + D
        cnt += 1
        if cnt == K:
            return t
    else:
        X = abs(X)
        cnt += (X//D)
        if cnt >= K:
            ans = X - (K*D)
            return ans
        s = X - (cnt*D)
        t = s - D
        t = abs(t)
        cnt += 1
        if cnt == K:
            return t

    nokori = K - cnt
    if nokori % 2 == 0:
        return t
    else:
        return s

print(main())


Measured memory_bytes: 9096
def cal(x): return (x+1)/2

N, K = map(int, input().split())
p = list(map(int, input().split()))

ans  = sum(cal(p[i]) for i in range(K))
    
cnt = ans

for i in range(K, N):
  cnt = cnt-cal(p[i-K])+cal(p[i])
  ans = max(cnt, ans)
print(ans)

Measured memory_bytes: 25060
#include <bits/stdc++.h>    
//#include <ext/pb_ds/assoc_container.hpp> 
//#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
//#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//using namespace __gnu_pbds; 
#define fastio() ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define pb  push_back
#define show(x) cout<<(#x)<<" : "<<x<<endl;
#define ll  long long
#define ld  long double
#define fill(a,val) memset(a,val,sizeof(a))
#define mp  make_pair
#define ff  first
#define ss  second
#define pii pair<ll,ll>
#define sq(x) ((x)*(x))
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define endl "\n"
#define int long long 
#define printclock cerr<<"Time : "<<1000*(ld)clock()/(ld)CLOCKS_PER_SEC<<"ms\n";
const ll MOD     = 1000*1000*1000+7;
const ll INF     = 1ll*1000*1000*1000*1000*1000*1000 + 7;
const ll MOD2    = 998244353;
const ll N       = 1000 * 100 + 10;
const ll N2      = 70;
const ld PI  = 3.141592653589793;
//template<class T> using oset=tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
ll gcd(ll a, ll b){if(!b)return a;return gcd(b, a % b);} 
ll power(ll x,ll y,ll p = LLONG_MAX ){ll res=1;x%=p;while(y>0){if(y&1)res=(res*x)%p;y=y>>1;x=(x*x)%p;}return res;}
ll lcm(ll a , ll b){return (a*b)/gcd(a,b);}

signed main()
{
    fastio();
    //cout<<fixed<<setprecision(20);
    //CHECK for LONG LONG and LONG DOUBLE
    //*comment for all except cc/cf    
    #ifndef ONLINE_JUDGE    
           freopen("input.txt","r",stdin);
           freopen("output.txt","w",stdout);
    #endif//*/
    int n,k,sum(0);
    cin>>n>>k;
    int a[n];
    for (int i = 0; i < n; ++i)
    {
        cin>>a[i];
    }
    sort(a,a+n);
    for (int i = 0; i < k; ++i)
    {
        sum+=a[i];
    }
    cout<<sum;


    printclock;
    return 0;
}

Measured memory_bytes: 3800