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

typedef long long ll;
const ll INF = 1010000000000000017LL;
const ll MOD = 1000000007LL;

#define REP(i, n) for(ll i = 0 ; i < n; i++)

//#define DEBUG(fmt, ...)
#define DEBUG(fmt, ...) fprintf(stderr, fmt "\n", ##__VA_ARGS__)

int main(){
    std::cout<<std::fixed<<std::setprecision(10);

    string s;
    ll Q;
    cin >> s >> Q;

    ll reverse = 0;
    deque<char> left;
    deque<char> right;

    REP(i, Q){
        ll T;
        cin >> T;
        if( T == 1 ){
            reverse = !reverse;
        }else{
            ll F;
            char C;
            cin >> F >> C;
            if( reverse ){
                if( F == 1 ){
                    right.push_back(C);
                }else{
                    left.push_back(C);
                }
            }else{
                if( F == 1 ){
                    left.push_back(C);
                }else{
                    right.push_back(C);
                }
            }
        }
    }

    stringstream ss;
    if( reverse){
        while(!right.empty()){
            ss << right.back();
            right.pop_back();
        }
        std::reverse(s.begin(), s.end());
        ss << s;
        while(!left.empty()){
            ss << left.front();
            left.pop_front();
        }

    }else{
        while(!left.empty()){
            ss << left.back();
            left.pop_back();
        }
        ss << s;
        while(!right.empty()){
            ss << right.front();
            right.pop_front();
        }
    }
    cout << ss.str() << endl;
}


Measured memory_bytes: 1540
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <cstdlib>
#include <vector>
#include <iomanip>
#include <utility>
using namespace std;
#define ll long long
#define inf 1000000007
int main(void){
    ll n;
    cin >> n;
    ll a[n];
    ll sum = 0, count = 0, check = inf;
    for(ll i = 0; i < n; i++){
        cin >> a[i];
        if(a[i] <= 0)
            count++;
        check = min(abs(a[i]), check);
        sum += abs(a[i]);
    }
    if(count % 2 == 0)
        cout << sum << endl;
    else
        cout << sum - 2*check << endl;
    return 0;
}

Measured memory_bytes: 1024
#include<iostream>
#include<vector>
#include<algorithm>
#include<cstdio>
using namespace std;

int main(){
    int a, b;
    while(cin >> a >> b){
        if(a == 0 && b == 0)return 0;
        for(int i=0; i < a; i++){
            for(int j=0; j < b; j++){
                if((i + j) % 2 == 0)cout << '#';
                else cout << '.';
            }
            cout << endl;
        }
        cout << endl;
    }
}


Measured memory_bytes: 3028
// G++ MACRO.CPP -STD=C++14
#include <bits/stdc++.h>
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;
using namespace std;

#define dump(x)  cout << #x << " = " << (x) << endl;
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define POSSIBLE(n) cout << ((n) ? "POSSIBLE" : "IMPOSSIBLE"  ) << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible"  ) << endl
#define possible(n) cout << ((n) ? "possible" : "impossible"  ) << endl

#define SANKOU(n,a,b) cout << ((n) ? (#a) : (#b) ) << endl

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)

#define FOREACH(x,a) for(auto& (x) : (a) )

#define WFA(d,v) REP(k,v)REP(i,v)REP(j,v)d[i][j]=min(d[i][j],d[i][k]+d[k][j])

#define SCOUT(x) cout<<(x)<<" "
#define ENDL cout<<endl

#define VECCIN(x) for(auto&youso_: (x) )cin>>youso_
#define VECIN2(x,y) REP(i,x.size())cin>>x[i]>>y[i]
#define VECCOUT(x) if(1){for(auto tt=x.begin();tt!=x.end();tt++){if(tt!=x.begin())cout<<" ";cout<<(*tt);}cout<<endl;}

#define ALL(obj) (obj).begin(),(obj).end()

#define EXIST(n,x) (find(ALL(n),x)!=n.end())
#define UNIQUE(obj) sort(ALL( obj )); obj.erase(unique(ALL(obj)),obj.end())
#define EN(x) if(1){cout<<#x<<endl;return 0;}
#define COUT(x) cout<<(x)<<endl
void CINT(){}
template <class Head,class... Tail>
void CINT(Head&& head,Tail&&... tail){
    cin>>head;
    CINT(move(tail)...);
}
#define CIN(...) int __VA_ARGS__;CINT(__VA_ARGS__)
#define LCIN(...) ll __VA_ARGS__;CINT(__VA_ARGS__)
#define SCIN(...) string __VA_ARGS__;CINT(__VA_ARGS__)

template <class T = ll>
T IN(){T x;cin>>x;return (x);}

template <class Head>
void VT(Head head){}
template <class Head,class Seco,class... Tail>
void VT(Head&& head,Seco&& seco,Tail&&... tail){
    seco.resize(head);
    VT(head,move(tail)...);
}
void VT2(){}
template <class Head,class... Tail>
void VT2(Head&& head,Tail&&... tail){
  VECCIN(head);
  VT2(move(tail)...);
}

template <class Head>
void VT3(Head&& head){}
template <class Head,class Seco,class... Tail>
void VT3(Head&& head,Seco&& seco,Tail&&... tail){
  seco[head]=IN();
  VT3(head,move(tail)...);
}

#define VC1(n,...) V __VA_ARGS__;VT(n,__VA_ARGS__);VT2(__VA_ARGS__); //aaabbbccc
#define VC2(n,...) V __VA_ARGS__;VT(n,__VA_ARGS__);REP(i,n)VT3(i,__VA_ARGS__); //abcabcabc

// #include <boost/multiprecision/cpp_int.hpp>
// using namespace boost::multiprecision; // cpp_int

#define P pair<ll,ll>
#define V vector<ll>
#define M map<ll,ll>
#define S set<int>
#define PQ priority_queue<int>
#define PQG priority_queue<int,V,greater<int>>

#define str string

#define pb(a) push_back(a)
#define mp make_pair


int main(){
  LCIN(n,k);VC2(n,a,b);
  M m;REP(i,n)m[a[i]]+=b[i];

  ll num = 0;
  FOREACH(xx,m){
    num += xx.second;
    if(k<=num){COUT(xx.first);break;}
  }

  return 0;
}


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

int main(){

	int N;
  
  	cin >> N;
  	int a[N];
  	a[0]=0;
	for(int i = 1; i <= N ; i++ )cin >> a[i];
  	
  	int n = 1;
  	for(int i = 1; i <= N ; i++ ){
    	n = a[n];
    	if(n == 2){
        	cout << i << endl ;
          	return 0;
        }
    }
  	cout << -1 << endl ;

}

Measured memory_bytes: 640
// atcoder/abc170/F/main.cpp
// author: @___Johniel
// github: https://github.com/johniel/

#include <bits/stdc++.h>

#define each(i, c) for (auto& i : c)
#define unless(cond) if (!(cond))

using namespace std;

template<typename P, typename Q> ostream& operator << (ostream& os, pair<P, Q> p) { os << "(" << p.first << "," << p.second << ")"; return os; }
template<typename P, typename Q> istream& operator >> (istream& is, pair<P, Q>& p) { is >> p.first >> p.second; return is; }
template<typename T> ostream& operator << (ostream& os, vector<T> v) { os << "("; for (auto& i: v) os << i << ","; os << ")"; return os; }
template<typename T> istream& operator >> (istream& is, vector<T>& v) { for (auto& i: v) is >> i; return is; }
template<typename T> ostream& operator << (ostream& os, set<T> s) { os << "#{"; for (auto& i: s) os << i << ","; os << "}"; return os; }
template<typename K, typename V> ostream& operator << (ostream& os, map<K, V> m) { os << "{"; for (auto& i: m) os << i << ","; os << "}"; return os; }

template<typename T> inline T setmax(T& a, T b) { return a = std::max(a, b); }
template<typename T> inline T setmin(T& a, T b) { return a = std::min(a, b); }

using lli = long long int;
using ull = unsigned long long;
using point = complex<double>;
using str = string;
template<typename T> using vec = vector<T>;

constexpr array<int, 8> di({0, 1, -1, 0, 1, -1, 1, -1});
constexpr array<int, 8> dj({1, 0, 0, -1, 1, -1, -1, 1});
constexpr lli mod = 1e9 + 7;

struct S {
  int i, j, d;
  pair<int, int> c;
};
bool operator < (S a, S b)
{
  return a.c > b.c;
}

int main(int argc, char *argv[])
{
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.setf(ios_base::fixed);
  cout.precision(15);

  int h, w, k;
  int si, sj, gi, gj;
  while (cin >> h >> w >> k >> si >> sj >> gi >> gj) {
    --si;
    --sj;
    --gi;
    --gj;
    char g[h][w];
    for (int i = 0; i < h; ++i) {
      for (int j = 0; j < w; ++j) {
        cin >> g[i][j];
      }
    }

    const int inf = 1 << 29;
    const int D = 4;
    pair<int, int> cost[h][w][D];
    fill(&cost[0][0][0], &cost[h - 1][w - 1][D - 1] + 1, make_pair(inf, 0));

    priority_queue<S> q;
    for (int d = 0; d < 4; ++d) {
      q.push({si, sj, d, cost[si][sj][d] = {0, 0}});
    }

    for (; q.size();) {
      auto s = q.top();
      q.pop();
      if (cost[s.i][s.j][s.d] != s.c) continue;
      for (int d = 0; d < 4; ++d) {
        int ni = s.i + di[d];
        int nj = s.j + dj[d];
        unless (0 <= ni && ni < h) continue;
        unless (0 <= nj && nj < w) continue;
        if (g[ni][nj] == '@') continue;
        pair<int, int> x = s.c;
        if (d == s.d) {
          ++x.second;
          x.first += x.second / k;
          x.second %= k;
        } else {
          x.first += !!x.second;
          x.second = 1;
        }
        if (cost[ni][nj][d] > x) {
          cost[ni][nj][d] = x;
          q.push({ni, nj, d, x});
        }
      }
    }

    int mn = inf;
    for (int d = 0; d < 4; ++d) {
      setmin(mn, cost[gi][gj][d].first + bool(cost[gi][gj][d].second));
    }
    cout << (mn == inf ? -1 : mn) << endl;
  }

  return 0;
}


Measured memory_bytes: 40668
#include <bits/stdc++.h>
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ll long long
#define mod 1000000007

using namespace std;

int main()
{
    IOS;
    string s,s1;
    int n,k;
    cin>>n>>k;
    cin>>s;
    s1=s;
    transform(s1.begin(), s1.end(), s1.begin(), ::tolower);
    for(int y=0;y<n;y++)
    {
        if(y==k-1)
            cout<<s1[y];
        else
            cout<<s[y];
    }
    //cout<<s1;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<(n);i++)
#define rrep(i,n) for(int i=(n-1);i>=0;i--)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define RFOR(i,a,b) for(int i=(a-1);i>=(b);i--)
#define all(x) (x).begin(), (x).end()
const int INF = 1e18;
const int MOD = 1e9+7;
typedef vector<int> vint;
typedef pair<int, int> pint;
typedef string str;
typedef vector<str> vstr;
void print() {cout<<endl;}template<class Head,class...Tail>void print(Head&&head,Tail&&...tail){cout<<head;if(sizeof...(tail)!=0)cout<<" ";print(forward<Tail>(tail)...);}template<class T>void print(vector<T>&vec){for(auto&a:vec){cout<<a;if(&a!=&vec.back())cout<<" ";}cout<<endl;}template<class T>void print(vector<vector<T>>&df){for(auto&vec:df){print(vec);}}
template<class T=int>T in() {T x;cin>>x;return(x);}
template<class T=int>vector<T> input_to_vector(int n) {vector<T>x;rep(i,n){T a;cin>>a;x.push_back(a);}return(x);}

signed main(){
    vint A = input_to_vector(3);
    sort(all(A));
    print(A[2] * 10 + A[1] + A[0]);
}

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

using namespace std;

int main()
{
    int n, m, d, r;
    
    scanf("%d", &n);
    scanf("%d", &m);
    
    vector<int> s(n); s[0] = 0;
    vector<int> a(m + 1); a[0] = 0;
    
    for(int i = 1; i < n; i++)
    {
        scanf("%d", &d);
        
        s[i] = d + s[i - 1];
    }
    
    long long ret = 0;
    
    for(int i = 1; i <= m; i++)
    {
        scanf("%d", &r);
        
        a[i] = r + a[i - 1];
        
        ret = ret + abs(s[a[i]] - s[a[i - 1]]);
    }
    
    printf("%lld\n", ret % 100000);
    
    return 0;
}

Measured memory_bytes: 3632
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <queue>
#include <stack>
#include <math.h>
#include <set>
#include <unordered_map>
using namespace std;

int n,m;
//n个盒子，m次操作
vector<int> qiu,hong;
int main(){
    scanf("%d%d",&n,&m);
    qiu.resize(n+1);
    hong.resize(n+1);
    for(int i=1;i<=n;i++){
        qiu[i]=1;
    }
    hong[1]=1;
    for(int i=0;i<m;i++){
        int a,b;
        scanf("%d %d",&a,&b);
        if(hong[a]!=0){
            hong[b]=1;
        }
        qiu[a]--;
        qiu[b]++;
        if(qiu[a]==0){
            hong[a]=0;
        }
        if(qiu[b]==0){
            hong[b]=0;
        }
    }
    int cnt=0;
    for(int i=1;i<=n;i++){
        if(qiu[i]!=0 && hong[i]!=0){
            cnt++;
        }
    }
    printf("%d",cnt);
    return 0;
}


Measured memory_bytes: 1024
object Main extends App {

  val s = scala.io.StdIn.readLine()

  def solve(): String = {
    for(i <- 0 until s.length) {
      if (i % 2 == 0) {
        if(s(i) == 'L') return "No"
      } else {
        if(s(i) == 'R') return "No"
      }
    }
    return "Yes"
  }

  println(solve)

}

Measured memory_bytes: 25424
#include "bits/stdc++.h"
#define FOR(i, a, b) for (int i = a; i < b; i++)
#define mFOR(i, a, b) for (int i = a; i > b; i--)
#define MP make_pair
#define PB push_back
#define ALL(v) v.begin(), v.end()
#define N 100007
#define INF 1000000007
using namespace std;

typedef long long ll;

ll gcd(ll a, ll b) { return b == 0 ? a : gcd(b, a % b); }
ll fceil(ll a, ll b) { return (a % b == 0 ? a / b : a / b + 1); }
int main()
{
   int n, x, l, d = 0, ctr = 1;
   cin >> n >> x;
   for (ctr = 1; ctr <= n; ctr++)
   {
      cin >> l;
      if (d + l <= x)
         d += l;
      else
         break;
   }
   cout << ctr << endl;
   return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int before[100005] = {};
int co = 0;
void BFS(int i, int n, vector<int> ds[])
{
   queue<int> q;
   q.push(i);
   before[i] = 1;
   while(!q.empty())
   {
      int u = q.front();
      q.pop();
      for(auto it: ds[u])
      {
         co++;
         if(!before[it])
         {
            q.push(it);
            before[it] = u;
         }
      }
      cout << endl;
   }
}
int main()
{
   ios_base::sync_with_stdio(0);
   cin.tie(0);

   int n, m;
   cin >> n >> m;
   vector<int> ds[n+1];
   for(int i =0; i < m; i++)
   {
      int x, y;
      cin >> x >> y;
      ds[x].push_back(y);
      ds[y].push_back(x);
   }

   int cnt = 0;
   for(int i =1; i<= n; i++)
   {
      if(!before[i])
      {
         cnt++;
         BFS(i, n, ds);
      }
      if(cnt==2)
      {
         cout << "No";
         return 0;
      }
   }
   cout << "Yes" << endl;
   for(int i = 2; i <= n; i++)
      cout << before[i] << endl;

   return 0;

}


Measured memory_bytes: 10552
#!/usr/bin/env ruby
# require 'pry'

# dpテンプレ

s = gets.chomp.split('')
t = gets.chomp.split('')

ans = 1000
(s.length-t.length + 1).times do |i|
  count = t.length
  t.length.times do |j|
    if s[i+j] == t[j]
      count -= 1
    end
    ans = [count, ans].min
  end
end

puts ans

Measured memory_bytes: 14312
#include<iostream>

using namespace std;

int main()
{
    
int n;cin>>n;int arr[n];for(int i=0;i<n;i++)cin>>arr[i];
int dp[n];
dp[0]=0;
for(int i=1;i<n;i++)
{
    int a=dp[i-1]+abs(arr[i]-arr[i-1]);
    if(i-2<0)
    dp[i]=a;
    else
    dp[i]=min(a,dp[i-2]+abs(arr[i]-arr[i-2]));
}

cout<<dp[n-1]<<" ";
}


Measured memory_bytes: 1024
// #include <bits/stdc++.h>
// #define FOR(i, m, n) for (int i = m; i < (n); i++)
// #define RFOR(i, m, n) for (int i = (m - 1); i >= 0; i--)
// #define REP(i, n) FOR(i, 0, n)
// #define RREP(i, n) RFOR(i, n, 0)
// #define ALL(v) v.begin(), v.end()
// #define RALL(v) v.rbegin(), v.rend()
// #define print(ele) cout << (ele) << endl
// #define print10(ele) cout << fixed << setprecision(10) << (ele) << endl

// using namespace std;
// typedef long long ll;
// typedef vector<int> ivec;
// typedef vector<string> svec;
// typedef vector<ll> lvec;

// const int mod = 1e9 + 7;
// const ll INF = 1000000000000000000LL;

// int main() {
//   ivec a(9);
//   REP(i, 9) cin >> a[i];
//   int n;
//   cin >> n;
//   ivec b(n);
//   REP(i, n) cin >> b[i];
//   bool ok = false;

//   vector<bool> ans(9, false);
//   REP(i, n) {
//     REP(j, 9) {
//       if (a[j] == b[i]) {
//         ans[j] = true;
//       }
//     }
//   }

//   if (ans[0] && ans[1] && ans[2])
//     ok = true;
//   else if (ans[3] && ans[4] && ans[5])
//     ok = true;
//   else if (ans[6] && ans[7] && ans[8])
//     ok = true;
//   else if (ans[0] && ans[4] && ans[8])
//     ok = true;
//   else if (ans[2] && ans[4] && ans[6])
//     ok = true;
//   else if (ans[0] && ans[3] && ans[6])
//     ok = true;
//   else if (ans[1] && ans[4] && ans[7])
//     ok = true;
//   else if (ans[2] && ans[5] && ans[8])
//     ok = true;

//   print(ok ? "Yes" : "No");
//   return 0;
// }

#include <bits/stdc++.h>
#define FOR(i, m, n) for (int i = m; i < (n); i++)
#define RFOR(i, m, n) for (int i = (m - 1); i >= 0; i--)
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) RFOR(i, n, 0)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
#define print(ele) cout << (ele) << endl
#define print10(ele) cout << fixed << setprecision(10) << (ele) << endl

using namespace std;
typedef long long ll;
typedef vector<int> ivec;
typedef vector<string> svec;
typedef vector<ll> lvec;

const int mod = 1e9 + 7;
const ll INF = 1000000000000000000LL;

int main() {
  vector<ivec> a(3, ivec(3));
  REP(i, 3) REP(j, 3) cin >> a[i][j];
  int n;
  cin >> n;
  ivec b(n);
  REP(i, n) cin >> b[i];

  vector<ivec> bingo(3, ivec(3));

  REP(i, 3) {
    REP(j, 3) {
      REP(k, n) {
        if (a[i][j] == b[k]) {
          bingo[i][j] = 1;
        }
      }
    }
  }

  bool ok = false;

  REP(i, 3) {
    int count = 0;
    REP(j, 3) {
      count += bingo[i][j];
      if (count == 3) {
        ok = true;
      }
    }
  }

  REP(i, 3) {
    int count = 0;
    REP(j, 3) {
      count += bingo[j][i];
      if (count == 3) {
        ok = true;
      }
    }
  }

  {
    int count = 0;
    REP(i, 3) {
      count += bingo[i][i];
      if (count == 3) {
        ok = true;
      }
    }
  }

  {
    int count = 0;
    REP(i, 3) {
      count += bingo[i][2 - i];
      if (count == 3) {
        ok = true;
      }
    }
  }

  print(ok ? "Yes" : "No");
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
struct ios_accelerate { ios_accelerate() { ios::sync_with_stdio(false); cin.tie(nullptr); } } CALL;

#define REP(i, n) for(auto (i) = (n)*0; (i) < (n); (i)++)
#define RNG(i, a, b) for(auto (i) = (a); (i) < (b); (i)++)
#define RBF(i, v) for(auto& (i) : (v))
#define ALL(x) (x).begin(), (x).end()

using LL = long long;
using UL = unsigned long;
using ULL = unsigned long long;
template<typename T> using V = vector<T>;
template<typename T> using VV = vector<vector<T>>;
template<typename T> using P = pair<T, T>;

const double PI = 3.141592653589793;
const int MOD = 1000000007;
const LL INF64 = static_cast<LL>(1e18) + 2;
const int INF = static_cast<int>(1e9) + 2;

template<typename T> inline void upsort(vector<T>& x) { sort(x.begin(), x.end()); }
template<typename T> inline void downsort(vector<T>& x) { sort(x.begin(), x.end(), greater<T>()); }
template<typename T> inline void col(T x) { cout << x << '\n'; }
template<> inline void col(double x) { cout << fixed << setprecision(12) << x << '\n'; }

signed main() {
	int n, m;
	cin >> n >> m;
	V<bool> AC(n + 1, false);
	V<int> WA(n + 1, 0);
	REP(i, m) {
		int p;
		string s;
		cin >> p >> s;
		if (s == "AC") {
			AC[p] = true;
		}
		else {
			if (!AC[p]) {
				WA[p]++;
			}
		}
	}

	int ac = 0, wa = 0;
	RNG(i, 1, n + 1) {
		if (AC[i]) {
			ac++;
			wa += WA[i];
		}
	}

	cout << ac << ' ' << wa << endl;
	return 0;
}


Measured memory_bytes: 3716
fun main(args: Array<String>) {
    val n = readLine()!!.toInt()
    val a = readLine()!!.split(' ').map { it.toInt() }.toMutableList()

    var ad = Array<Int>(n) { 0 }.toMutableList()
    var flag = true
    a.map { if (it == 0 || it % 2 == 1) flag = false }
    if (flag)
        a.forEachIndexed { i, it ->
            var s = 2
            while (it % s == 0) {
                ad[i]++
                s *= 2
            }
        }
    val ans = ad.min()

    println(ans)
}

Measured memory_bytes: 38180
#A

"""
s = input().split("/")
if int(s[1]) <= 4:
    print("Heisei")
else:
    print("TBD")

#B
"""
n = int(input())
ans = 0
for i in range(n):
    a = input().split()
    if a[1] == "JPY":
        ans += int(a[0])
    else:
        ans +=  float(a[0]) * 380000
print(ans)


Measured memory_bytes: 38384
#include<bits/stdc++.h>
using namespace std;
int n,x,sum;
string s;
 
int main(){
  cin>>n;
  for(x=1;sum<n;x++)sum+=x;
  x--;
    for(int i=0;i<x;i++)s+=')';
    for(int i=0;i<x;i++)s+='(';
    swap(s[x],s[x-(sum-n)]);
    cout<<s<<endl;
    return 0;
}

Measured memory_bytes: 3312
#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
typedef long long   ll;
#define pb                push_back
#define mp                make_pair
#define all(a)            (a).begin(), (a).end()
#define clr(a,h)          memset(a, (h), sizeof(a))
#define mem(a,h)          memset(a, (h), sizeof(a))
#define fi first
#define se second
#define por(a,b) (((a%MOD) * (b%MOD))%MOD)
#define forg(i, b, e, c)    for (ll i = (ll)b; i < (ll)e; i+=c)
#define forr(i, b, e)    for (ll i = b; i < e; i++)
 
 
using namespace std;
//using namespace __gnu_pbds;
typedef double lldb;
typedef pair<ll, ll>  ii;
typedef pair<ii, ll>  iii;
typedef vector<ll>     vi;
typedef vector<vi>     vvi;
typedef vector<ii>      vii;
typedef vector<ll>      vll;
//typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
const ll INF = 1e9;
const double PI = acos(-1);
#define tam 220000
#define offset 
const ll MOD= 1e9+7;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int suffix[tam],prefix[tam],v[tam];
int  main()
{
    ios::sync_with_stdio(false);cin.tie(0);
    int n;
    cin>>n;
    forr(i,0,n)
    {
        cin>>v[i];
        if (i-(v[i]-1)>=0)
            suffix[i-(v[i]-1)]++;
    }
    ll  tot=0;
    forr(i,0,n)
    {

        int possuf=(i-(v[i]-1));
        int pospre=(i+(v[i]-1));
        if (possuf>=0)
            suffix[possuf]--;
        if (i+v[i]+1<n)
            tot+=suffix[i+v[i]+1];
        
        if (i-v[i]-1>=0)
            tot+=prefix[i-v[i]-1];
        if (pospre<n)
            prefix[pospre]++;
     //   cout<<tot<<' ';
    }
    cout<<tot/2<<endl;
}
// PLUS ULTRA!
    


Measured memory_bytes: 5940
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define printInt(a) printf("%d\n", a)
using namespace std;

int main() {
    int h, w, k;
    scanf("%d %d %d", &h, &w, &k);
    bool squares[h][w];
    char input[w+1];
    rep(i, h) {
        scanf("%s", input);
        rep(j, w) {
            squares[i][j] =
                input[j] == '#' ? true : false;
        }
    }
    int hpattern = 1 << h;
    int wpattern = 1 << w;
    int counter, res = 0;
    rep(hp, hpattern) {
        rep(wp, wpattern) {
            counter = 0;
            rep(i, h) {
                rep(j, w) {
                    if (hp >> i & 1 &&
                        wp >> j & 1 &&
                        squares[i][j]) {
                            counter++;
                        }
                }
            }
            if (counter == k)
                res++;
        }
    }
    printInt(res);
    return 0;
}


Measured memory_bytes: 3824
s = input()
x, y = map(int, input().split())

# Tで区切り、各Tの前にFが何文字あるか数える
steps = []
cnt = 0
for i in range(len(s)):
    if s[i] == "F":
        cnt += 1
    elif s[i] == "T":
        steps.append(cnt)
        cnt = 0
# 最後のブロックについて
if cnt > 0:
    steps.append(cnt)
AX = steps[0::2]
AY = steps[1::2]

# X軸方向の最大値
max_X = sum(AX)
# dpX[i][j] = X軸方向の移動をi回行って、jに到達できるか
# j = 0, 1, ..., 2*max_X だが、実際のX座標は -max_X, ..., 0, ..., max_X
# 原点(x=0)は、j = max_Xに相当する
dpX = [[0 for _ in range(2 * max_X + 1)] for _ in range(len(AX) + 1)]
dpX[0][max_X] = 1
# 最初に右へ移動する場合
if s[0] == "F":
    dpX[1][max_X + AX[0]] = 1
    for i in range(1, len(AX)):
        for j in range(2 * max_X + 1):
            if dpX[i][j] == 1:
                # +X方向に移動
                if j + AX[i] <= 2 * max_X:
                    dpX[i + 1][j + AX[i]] = 1
                # -X方向に移動
                if 0 <= j - AX[i]:
                    dpX[i + 1][j - AX[i]] = 1
# 最初に回転する場合
else:
    for i in range(len(AX)):
        for j in range(2 * max_X + 1):
            if dpX[i][j] == 1:
                # +X方向に移動
                if j + AX[i] <= 2 * max_X:
                    dpX[i + 1][j + AX[i]] = 1
                # -X方向に移動
                if 0 <= j - AX[i]:
                    dpX[i + 1][j - AX[i]] = 1
# Y軸方向の最大値
max_Y = sum(AY)
# dpY[i][j] = Y軸方向の移動をi回行って、jに到達できるか
# j = 0, 1, ..., 2*max_Y だが、実際のY座標は -max_Y, ..., 0, ..., max_Y
# 原点(y=0)は、j = max_Yに相当する
dpY = [[0 for _ in range(2 * max_Y + 1)] for _ in range(len(AY) + 1)]
dpY[0][max_Y] = 1
for i in range(len(AY)):
    for j in range(2 * max_Y + 1):
        if dpY[i][j] == 1:
            # +Y方向に移動
            if j + AY[i] <= 2 * max_Y:
                dpY[i + 1][j + AY[i]] = 1
            # -Y方向に移動
            if 0 <= j - AY[i]:
                dpY[i + 1][j - AY[i]] = 1

if -max_X <= x <= max_X and -max_Y <= y <= max_Y:
    if dpX[-1][x + max_X] == 1 and dpY[-1][y + max_Y] == 1:
        print("Yes")
        exit()
print("No")


Measured memory_bytes: 206516
#include <iostream>
using namespace std;
 
int main()
{
  int N, X, i;
  cin >> N >> X;
  int L[N], D[N + 1];
  D[0] = 0;
  for (i = 0; i < N; i++) {
    cin >> L[i];
    D[i+1] = D[i] + L[i];
    if (D[i+1] > X)
      break;
  }
  cout << i + 1 << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#include <iostream>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <algorithm>
int main() {
  int N,i,a;
  cin>>N;
  int L[N]={0};
  for(i=0;i<N;i++){
  cin>>L[i];
  }
  sort(L,L+i);
  a=L[N-1];
  N=N-1;
  for(i=0;i<N;i++){
  a=a-L[i];
  }
  if(a<0){
   cout<<"Yes"<<endl;
  }else{
   cout<<"No"<<endl;
  }
}

Measured memory_bytes: 256
N = gets.chomp.to_i
T,A = gets.chomp.split(" ").map(&:to_i)
heights = gets.chomp.split(" ").map(&:to_i)
min_ave_temp = 100000000
min_ave_num = 0

heights.each_with_index do |height, i|
  ave_temp = T - height*0.006
  ave_temp_diff = ave_temp - A
  ave_temp_diff < 0 ? ave_temp_diff=-ave_temp_diff : ""
  if ave_temp_diff < min_ave_temp
    min_ave_temp = ave_temp_diff
    min_ave_num = i+1
  end
end

puts min_ave_num

Measured memory_bytes: 1788
/*
 * Author: .-O_O-.
 */
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include<bits/stdc++.h>
using namespace __gnu_pbds;
using namespace std;
#define ll long long
#define pb push_back
#define vi vector<int>
#define rep0(a,b) for(int a=0;a<b;a++)
#define rep1(a,b) for(int a=1;a<=b;a++)
#define repp(a,b,c) for(int a=b;a<c;a++)
#define in insert
#define len length()
#define si size()
#define lb lower_bound
#define ub upper_bound
#define beg begin()
#define en end()
#define f first
#define s second
#define pr(a) cout<<a
#define pr2(a,b) cout<<a<<" "<<b<<"\n"
#define nx cout<<"\n"
#define int long long
// void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}
                                                     
template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]"<<endl;}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define deb(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define deb(x...)
#endif
const ll mod = 1000000007;
const ll N = 105;
const ll mm = 1e+18;
void solve()
{
    int w,a,b;
    cin>>w>>a>>b;
    if(a>b){
        cout<<max(0LL,a-(b+w));
    }
    else{
        cout<<max(0LL,b-(a+w));
    }
}
signed main()
{
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    int t=1;
    //cin>>t;
    rep1(_i,t){
        //cout<<"Case #"<<_i<<": ";
        solve();
        //nx;
    }
    return 0;
}

Measured memory_bytes: 3652
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <map>
#include <queue>
#include <deque>
#include <string>
#include <stack>
#include <vector>
#include <set>
#include <tuple>
#include <utility>
#include <functional>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef tuple<int,int,int> T;
const int INF = 1000000000;
const int MOD = 1000000007;
int main(){
	int h,w,m;
	cin >> h >> w >> m;
	map<int,int> x_num;
	map<int,int> y_num;

	vector<P> xy(m);
	for(int i = 0;i < m;i++){
		int y,x;
		cin >> y >> x;
		xy[i] = P(x,y);
		x_num[x]++;
		y_num[y]++;
	}


	int max_x_num = 0;
	int cnt_max_x = 0;
	int max_y_num = 0;
	int cnt_max_y = 0;

	for(auto itr = x_num.begin(); itr != x_num.end();itr++){
		max_x_num = max(max_x_num,itr->second);
	}

	for(auto itr = y_num.begin(); itr != y_num.end();itr++){
		max_y_num = max(max_y_num,itr->second);
	}

	for(auto itr = x_num.begin(); itr != x_num.end();itr++){
		if(itr->second == max_x_num)cnt_max_x++;
	}

	for(auto itr = y_num.begin(); itr != y_num.end();itr++){
		if(itr->second == max_y_num)cnt_max_y++;
	}

	ll cnt = (ll)cnt_max_x * cnt_max_y;

	for(int i = 0;i < m;i++){
		int x = xy[i].first;
		int y = xy[i].second;
		if(x_num[x] == max_x_num && y_num[y] == max_y_num)cnt--;
	}

	if(cnt > 0)cout << max_x_num + max_y_num << endl;
	else cout << max_x_num + max_y_num - 1 << endl;
}


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

int main(){
    int a,b;
    string S;
    cin >> S ;
    if(S.find("YAKI")==0){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
    

    
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(x) (x).begin(), (x).end()
using ll = long long;
using namespace std;
template <typename T>
using vec = std::vector<T>;

int main() {
    int A,B,X;
    cin >> A >> B >> X;
    cout << (A<=X&&X<=A+B?"YES":"NO") << endl;
}


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

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

    int ans=0;
    for(int i=0; i<n+1; i++){
        string tmp = to_string(i);
        int sum=0;

        for(auto t : tmp){
            sum += t - '0';
        }
        //cout<<i<<" : "<<sum<<endl;
        if(sum<a){
            continue;
        }
        if(sum>b){
            continue;
        }

        ans += i;
    }

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

Measured memory_bytes: 3752
function main(input) {
  let kari = input[0].trim().split(" ").map(i => parseInt(i));
  let k = kari[3];
  let sum = 0;

  let j=0;

  for(let i=1;i>-2;i--){
    if(kari[j]<k){
      sum+=kari[j]*i;
      k-=kari[j];
    }else{
      sum+=k*i;
      break;
    }
    j++;
  }
  console.log(sum);
}
main(require('fs').readFileSync('/dev/stdin', 'utf8').trim().split("\n"));

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

ll gcd(ll a,ll b){
  if(b == 0) return a;
  return gcd(b, a % b);
}

using Graph = vector<vector<char>>;

ll calc(ll a, ll b, ll p){//aのb乗をpで割った余り
  if(b == 0) return 1;

  else if(b%2 == 0){
    ll d = calc(a,b/2,p);
    return (d*d)%p;
  }
  else if(b%2 == 1){
    return (a * calc(a,b-1,p))%p;
  }
}

typedef pair<int,int> P;

bool is_prime(int n){//nが素数であるかどうか判定 iで割り切れると素数でない
    if(n == 1) return false;//1は例外
    for(int i = 2;i*i <= n;i++){
        if(n%i == 0) return false;
    }
    
    return true;
}
int factorial(int a){
  int res = 1;
  while(a){
    res *= a;
    a--;
  }
  return res;
}

int main(){
  string S;
  cin >> S;
  int N = S.size();
  vector<pair<int,int>> p;//子供が集まる場所の集合
  for(int i = 0;i<N-1;i++){
    if(S[i] == 'R' && S[i+1] == 'L'){
       p.push_back(make_pair(i,i+1));
    }
  }
  /*rep(i,p.size()){
    cout << p[i].first << p[i].second << endl;
  }*/
  
  vector<pair<char,int>> lan;
  S.push_back('#');
  int c = 1;
  for(int i = 0;i<N;i++){
    if(S[i] == S[i+1]){
      c++;
    }
    else{
      lan.push_back(make_pair(S[i],c));
      c = 1;
    }
  }
  /*rep(i,lan.size()){
    cout << lan[i].first  << lan[i].second << endl;
  }*/
  vector<int> ans(N);
  int j = 0;
  rep(i,lan.size()-1){
    if(lan[i].first == 'R' && lan[i+1].first == 'L'){
       ans[p[j].first] = 1 + (lan[i].second-1)/2 + lan[i+1].second/2;
       ans[p[j].second] = 1 + (lan[i+1].second-1)/2 + lan[i].second/2;
       j++;
    }
  }
  //cout << j << endl;
  rep(i,N){
    cout << ans[i] << " ";
  }
  cout << endl;
}

Measured memory_bytes: 2228
#include<iostream>
#include<cstdio>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<algorithm>
#include<math.h>
#include<numeric>
#include<iomanip>
#include<queue>
#include<functional>

using namespace std;

typedef vector<int> vi;
typedef pair<int, int> pii;
typedef long long ll;
typedef vector<long long> vll;
typedef pair<long long, long long> pll;

//const ll INF = 1e15;
const ll MOD = 1e9 + 7;

int main(){
	int A, B;
	cin >> A >> B;
	string S;
	cin >> S;
	int i;
	bool flg = false;
	for (i = 0; i < A + B + 1; i++){
		if (i != A){
			int c = S[i] - '0';
			if (c < 0 || c>9){
				flg = true;
				break;
			}
		}
		else{
			if (S[i] != '-'){
				flg = true;
				break;
			}
		}
	}
	if (flg){
		cout << "No" << endl;
	}
	else{
		cout << "Yes" << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
const ll md = 1000000007;
vector<ll> fact(1e6 + 7), invfact(1e6 + 7);

ll fn(ll a, ll r, ll n, ll mod = md) {
    ll res = 1, x = r%mod;
    ll ans = 0;
    while(n) {
        if(n&1) ans = (x*ans + res)%mod;
        res = ((res*x)%mod + res%mod)%mod;
        x = (x*x)%mod;
        n = n/2;
    }
    ans = (ans*a)%mod;
    return ans;
}

ll nCr(ll n, ll r) {
    if(r == 0) return 1;
    ll num = fact[n];
    ll den = (invfact[r] % md *invfact[n-r] % md)%md;
    return (num*den)%md;
}

ll mul(ll a, ll b, ll mod = md) {
    ll res = (a%mod * b%mod)%mod;
    return res;
}

ll mulm(ll a, ll b, ll mod = md) {
    ll r = 0;
    a %= mod;
    while (b) {
        if (b & 1) r = (r+a)%mod;
        a = (a+a)%mod;
        b = b/2;
    }
    r %= mod;
    return r;
}

ll power(ll x, ll n, ll mod = md) {
    ll res = 1;
    x %= mod;
    while (n) {
        if (n & 1)  res = (res*x)%mod;
        n = n/2;
        x = (x*x)%mod;
    }
    return res;
}

ll power2(ll x, ll n) {
    ll res = 1;
    while (n)  
    {  
        if (n & 1)  res = (res*x);  
        n = n/2; 
        x = (x*x);  
    }  
    return res;
}

bool is_prime(ll x) {
    if(x == 1 || x == 0) return false;
    for(int i=2; i*i <= x; i++) {
        if(x%i == 0) return false;
    }
    return true;
}

ll compgcd(ll n, vector<ll> const &primes) { 
    ll res = n; 
    for (ll i=0; primes[i]*primes[i] <= n; i++) {
        if (n % primes[i]== 0) { 
            res -= (res / primes[i]); 
            while (n%primes[i]== 0) {
               n/=primes[i]; 
            }
        } 
    } 
    if (n > 1) {
       res -= (res / n); 
    }
    return res; 
} 

void sieve(vector<bool> &prime, vector<ll> &primes, ll lim) {
    for(int i = 2; i*i <= lim; i++) {
        if(prime[i]) {
            for(int j = 2; j*i <= lim; j++) {
                prime[j*i] = false;
            }
        }
    }
    for(int i = 2; i <= lim; i++) {
        if(prime[i]) {
            primes.push_back(i);
        }
    }
}

void sieveGCD(ll lim, vector<ll> &tab, vector<ll> const &primes) {
    for(int  i = 1; i <= lim; i++) {
        tab[i] = i;
    }
    for(int i = 0; i<primes.size() && primes[i] <= lim; i++) {
        tab[primes[i]] = primes[i]-1;
        for(int j = 2; primes[i]*j <= lim; j++) {
            tab[primes[i]*j] = (tab[primes[i]*j]/primes[i])*(primes[i]-1);
        }
    }
}

int main() 
{ 
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n, k, count = 0;
    cin >> n >> k;
    vector<int> a(n);
    for(int i = 0; i < n; i++) {
        cin >> a[i];
        if(k > 0) {
            k -= a[i];
            count++;
        }
    }
    sort(a.begin(), a.end());
    count += k/a[0];
    cout << count << "\n";
    return 0; 
}

Measured memory_bytes: 15872
from math import sqrt
N = int(input())
Numbers = []
for _ in range(N):
    Numbers.append(int(input()))
count = 0
for Num in Numbers:
    flag = True
    for j in range(2, int(sqrt(Num) + 1)):
        if Num % j == 0:
            flag = False
            break
    if flag:
        count += 1
print(count)



Measured memory_bytes: 6000
N = int(input())
score = [int(input()) for i in range(N)]
ans = 0
minimum = 100
for s in score:
    ans += s
    if s % 10 != 0:
        minimum = min(minimum, s)

if ans % 10 != 0:
    print(ans)
else:
    if minimum == 100:
        print('0')
    else:
        print(ans-minimum)


Measured memory_bytes: 2940
#include <iostream>
#include <fstream>
#include <string>
#include <unordered_map>
#include <stdio.h>
#include <list>
#include <vector>
#include <algorithm>
#include <stack>
#include <climits>
#include <cmath>
#include <map>
#include <queue>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; ++i)
#define ALL(v) v.begin(), v.end()
typedef long long ll;

int main()
{
	ll n;
	cin >> n;
	vector<ll> a(n);
	rep(i,n)cin>>a[i];
	ll two = 0;
	ll four = 0;
	rep(i,n)
	{
		if(a[i]%4==0)
		{
			four ++ ;
			continue;
		}
		else if(a[i]%2==0)
		{
			two ++ ;
			continue;
		}
	}
	if(four>0&&n%2==1)
	{
		n--;
	}
	n-=four*2;
	n-=two;
	if(n>0)
	cout<<"No"<<endl;
	else 
	cout<<"Yes"<<endl;


	return 0;
}

Measured memory_bytes: 1152
#include <bits/stdc++.h>
using namespace std;
int main() {
  int x_1,y_1,x_2,y_2;
  cin>>x_1>>y_1>>x_2>>y_2;
  int x_3,y_3,x_4,y_4;
  x_3=x_2-(y_2-y_1);
  y_3=y_2+(x_2-x_1);
  x_4=x_1-(y_2-y_1);
  y_4=y_1+(x_2-x_1);
  cout<<x_3<<" "<<y_3<<" "<<x_4<<" "<<y_4<<" "<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using lint     = long long;
const lint inf = 1LL << 60;
const lint mod = 1000000007;

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    lint n, k;
    cin >> n >> k;
    lint ret = 0;
    for (int b = k + 1; b <= n; ++b) {
        lint temp = n / b;
        ret += temp * (b - k);
        lint rem = n % b;
        if (k != 0)
            ret += max(0LL, rem + 1 - k);
        else
            ret += max(0LL, rem - k);
    }
    cout << ret << "\n";
    return 0;
}

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

bp = [0] * (n+10)
for i in range(2, n+10):
    if bp[i] == 0:
        bp[i] = i
        for j in range(i*i, n+1, i):
            bp[j] = i


def fact(n):
    ret=1
    while n>1:
        now=n
        cnt=0
        p=bp[now]
        while now % p == 0:
            now//=p
            cnt+=1
        ret*=cnt+1
        n=now
    return ret
ans=0
for i in range(1,n+1):
    ans += i*fact(i)

print(ans)

Measured memory_bytes: 152140
//atcoder.jp abc 120 d
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define mk make_pair
#define pii pair<int,int>
#define fst first
#define scd second
using namespace std;

inline ll read() {
	ll f=1,x=0;char ch=getchar();
	while(!isdigit(ch)){if(ch=='-')f=-1;ch=getchar();}
	while(isdigit(ch)){x=x*10+ch-'0';ch=getchar();}
	return x*f;
}

const int MAXN=1e5+5;
int n,m,fa[MAXN];

struct EDGE {
	int u,v;
}e[MAXN];

ll ans[MAXN],sz[MAXN];

int get_fa(int x) {
	if(x==fa[x]) return x;
	return fa[x]=get_fa(fa[x]);
}

int main() {
    //freopen("","r",stdin);
    //freopen("","w",stdout);
	ios::sync_with_stdio(0);cin.tie(0);/*syn加速*/
	n=read();m=read();
	
	for(int i=1;i<=m;++i) {
		e[i].u=read(); e[i].v=read();
	}
	
	for(int i=1;i<=n;++i) 
	   fa[i]=i,sz[i]=1;
	
	ans[m]=(ll)n*(n-1)/2;
	
	for(int i=m;i>=1;--i) {
		int u=get_fa(e[i].u),v=get_fa(e[i].v);
		if(u==v) 
		    ans[i-1]=ans[i];
		else {
			ans[i-1]=ans[i]-sz[v]*sz[u];
			sz[v]+=sz[u]; fa[u]=v;
		}
	}
	
	for(int i=1;i<=m;++i) 
	   cout<<ans[i]<<endl;
	return 0;
}

Measured memory_bytes: 4096
#include <bits/stdc++.h>
#define MOD 1000000007LL
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

int n;
ll a[500005];
int cnt[21][500005];

int main(void){
	scanf("%d",&n);
	for(int i=0;i<n;i++){
		int a;
		scanf("%d",&a);
		for(int j=0;j<21;j++){
			cnt[j][i+1]+=cnt[j][i];
			if(a>>j & 1)cnt[j][i+1]++;
		}
	}
	ll ans=0;
	for(int i=0;i<n;i++){
		int mi=n;
		for(int j=0;j<21;j++){
			int k=upper_bound(cnt[j]+i,cnt[j]+n+1,cnt[j][i]+1)-cnt[j];
			mi=min(k-1,mi);
		}
		//printf("%d\n",mi);
		ans+=(ll)mi-i;
	}
	printf("%lld\n",ans);
	return 0;
}

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

int main(){
  char c;  
  cin>>c;
  if(c>='a'&&c<='z') cout<<'a'<<endl;
  else cout<<'A'<<endl;
  return 0;
}


Measured memory_bytes: 3588
#include <bits/stdc++.h>
using namespace std;
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);
#define mp make_pair
#define ff first
#define ss second
#define pb push_back
#define eb emplace_back
#define ppb pop_back
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define all(x) x.begin(),x.end()
#define sz(x) (int)x.size()
#define rall(x) x.rbegin(),x.rend()
#define mu(x) x.resize(unique(all(x))-x.begin());
#define srt(x) sort(all(x));
#define rev(x) reverse(all(x));
#define each(x,a) for(auto& x:a)
#define REP(i,a,b) for(int i=a;i<=b;i++)
#define PER(i,a,b) for(int i=a;i>=b;i--)
#define debug(x) cerr<<#x<<" "<<x<<"\n";
#define debug_v(x) { cout<<#x<<"\n";  each(y,x) cout<<y<<" "; cout<<'\n';}
#define debug_vp(x) { cout<<#x<<"\n";  each(y,x) cout<<y.ff<<" "<<y.ss<<'\n'; cout<<'\n';}
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
typedef vector<bool> vb;

int main(){
	fastio;
	int a,b,c;
	cin>>a>>b>>c;
	swap(a,b);
	swap(a,c);
	cout<<a<<" "<<b<<" "<<c;
	return 0;
}


Measured memory_bytes: 256
# D Water_Bottle
import math
a,b,x = map(int,input().split(" "))
x /= a
if (x == a*b):
    #水筒が満タンの場合
    print(0)
elif (x > a*b/2):
    #水筒の半分の容積より水の容積が大きかった場合
    ha = a/2
    print(90-math.degrees(math.atan(ha/(b-(x/a)))))
else:
    #水の容積が水筒の半分の容積以下だった場合
    c = 2*x/b
    print(90-math.degrees(math.atan(c/b)))



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

#define ll long long 
#define inf 0x3f3f3f3f
#define infll 0x3f3f3f3f3f3f3f3f
#define all(x) (x).begin(),(x).end()
#define f(i, a, b) for (int i=a; i<(signed)(b); ++i)
#define pc __builtin_popcount // counts number of 1's in bin(num)

const double pi = 2*acos(0.0);
//__gcd(n1, n2);
//cout << fixed;
//cout << setprecision(6); //fixes # of dp



int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
    cout.tie(0);
	
    string s;
    cin >> s;
    string ans = "";
    f(i, 0, s.length()){
        ans += 'x';
    }
    cout << ans;
}   








Measured memory_bytes: 256
import std.stdio, std.string, std.conv, std.algorithm, std.range;

void main() {
    auto S = readln.split.to!(int[]);
    auto N = S[0], M = S[1];
    auto table = new int[][N];
    foreach (i; 0..M) {
        auto edge = readln.split.map!(a => to!int(a)-1).array;
        table[edge[0]] ~= edge[1];
        table[edge[1]] ~= edge[0];
    }

    alias getSelection = (c, memo) => table[c].filter!(a => !memo.canFind(a)).array;
    int go(int c, int[] memo) {
        auto selection = getSelection(c, memo);
        if (memo.length == N-1) return 1;
        if (selection.length == 0) return 0;
        return selection.map!(a => go(a, memo ~ c)).sum;
    }
    writeln(go(0, new int[0]));
}

Measured memory_bytes: 1276
#include <algorithm>
#include <bitset>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <cctype>
#include <assert.h>
#include <stdlib.h>
#include <stdio.h>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <limits>
#include <map>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
using namespace std;
//#define int long long    ←保留
#define rep(i, n) for (int i = 0; i < n; i++)
const int MOD = 1e9 + 7;
const int INF = 1e18 + 9;
constexpr long double pi = 3.141592653589793238462643383279; //円周率
//C++(GCC9.2.1)

/*signed*/int main() {
    //宣言
    long long H;
    long long W;
    cin >> H >> W;
    long long sum = H * W;
    if ((H == 1) || (W == 1)) sum = 1;
    else if (sum % 2 == 0) sum = sum / 2;
    else sum = sum / 2 + 1;
    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 3592
#include <math.h>
#include <iostream>
#include <algorithm>
#include <functional>
#include <string>


using namespace std;

int main(void)
{
	int a, b;

	while (cin >> a >> b, !cin.eof())
	{
		int sum = to_string(a+b).length();


		cout << sum << endl;
	}

	return 0;
}

Measured memory_bytes: 1216
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  
  char c;
  cin >> c;
  if(c == 'a' || c == 'i' || c == 'u' || c == 'e' || c == 'o'){
  	cout << "vowel" << endl;
  }
  else {
  	cout << "consonant" << endl;
  }
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <cmath>
#include <tuple>
#include <cstdio>
#include <bitset>
#include <sstream>
#include <iterator>
#include <numeric>
#include <map>
#include <cstring>
#include <set>
#include <functional>
#include <iomanip>

using namespace std;

#define DEBUG_ //!!提出時にコメントアウト!!
#ifdef DEBUG_
	#define dump(x)  cerr << #x << " = " << (x) << endl;
#else
	#define dump(x)  ;
#endif

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define SZ(x) ((int)(x).size())
#define pb push_back
#define eb emplace_back

//#define int long long

typedef long long LL;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;

template <typename T>
std::string printVector(const std::vector<T> &data)
{
    std::stringstream ss;
    std::ostream_iterator<T> out_it(ss, ", ");
    ss << "[";
    std::copy(data.begin(), data.end() - 1, out_it);
    ss << data.back() << "]";
    return ss.str();
}

const int MOD = 1e9+7;
const LL LINF = 1001002003004005006ll;
const int INF = 1001001001;

signed main(int argc, char const *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int A, B;
    cin>>A>>B;
    if(A!=2 && B!=2){
        cout<<"Yes"<<endl;
    }
    else{cout<<"No"<<endl;}

}


Measured memory_bytes: 256