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

// ABC068B - Break Number
int main(){
  int n;
  cin >> n;

  int r = 1;
  for (int i = 0; i < 7; ++i) {
    if ((1 << i) <= n) {
      r = (1 << i);
    }
  }

  cout << r << endl;
  return 0;
}


Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS

#include <iostream>
#include <string>
#include <vector>
#include <cmath>
#include <fstream>
#include <set>
#include <utility>
#include <algorithm>
#include <queue>
#include <stack>
#include <deque>
#include <numeric>
#include <sstream>
#include <list>
#include <map>
#include <functional>
#include <iterator>

#define rep(i,p,n) for(int i=(int)p;i<(int)n;i++)
#define repp(i,p,n) for(int i=(int)p;i>=(int)n;i--)
#define Sort(x) sort(x.begin(),x.end())
#define PSort(x) sort(begin(x), end(x), pairCompare)
#define ll long long
#define INF 2000000000
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define vi vector<int>
#define PI 3.14159265358979
int dx[4] = { -1,0,1,0 }, dy[4] = { 0,1,0,-1 };
using namespace std;

int main(){	
	ll a, b, x;
	cin >> a >> b >> x;
	a--;
	b = b / x + 1;
	(a != -1) ? (a = a / x + 1):a=0;
	printf("%lld\n", b - a);

	return 0;
}



Measured memory_bytes: 256
str = gets.split
n = str[0].to_i
a = str[1].to_i
b = str[2].to_i
add = (a-b).to_f

enemy = []
for x in 0...n
  str = gets
  enemy[x] = str.to_i
end

answer = ((enemy.min/a)..(enemy.max/b+1)).bsearch{|i|
  count = 0
  for x in 0...n
    count += ([enemy[x] - b * i, 0].max / add).ceil
  end
  count <= i
}
puts(answer)

Measured memory_bytes: 3144
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LINF = 1e18;
inline ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
inline ll lcm(ll a, ll b) { return a / gcd(a, b)*b; }
template<class S,class T> ostream& operator << (ostream& out,const pair<S,T>& o){ out << "(" << o.first << "," << o.second << ")"; return out; }
template<class T> ostream& operator << (ostream& out,const vector<T> V){ for(int i = 0; i < V.size(); i++){ out << V[i]; if(i!=V.size()-1) out << " ";} return out; }
template<class T> ostream& operator << (ostream& out,const vector<vector<T> > Mat){ for(int i = 0; i < Mat.size(); i++) { if(i != 0) out << endl; out << Mat[i];} return out; }
template<class S,class T> ostream& operator << (ostream& out,const map<S,T> mp){ out << "{ "; for(auto it = mp.begin(); it != mp.end(); it++){ out << it->first << ":" << it->second; if(mp.size()-1 != distance(mp.begin(),it)) out << ", "; } out << " }"; return out; }

/*
 <url:https://atcoder.jp/contests/caddi2018b/tasks/caddi2018b_b>
 問題文============================================================
 =================================================================
 解説=============================================================
 ================================================================
 */

template<class Type>
Type solve(Type res = Type()){
    ll N,H,W; cin >> N >> H >> W;
    for(int i = 0; i < N;i++){
        ll A,B; cin >> A >> B;
        if(H <= A && W <= B) res++;
    }
    return res;
}
int main(void) {
    cin.tie(0); ios_base::sync_with_stdio(false);
    // solve(0);
    cout << fixed << setprecision(15) << solve<ll>() << endl;
    return 0;
}


Measured memory_bytes: 256
n,m,c = (int(_) for _ in input().split())
b = [int(_) for _ in input().split()]
a = [[int(i) for i in input().split()] for i in range(n)]

t = 0
for i in a:
    s = 0
    for j in range(m):
        s = s + i[j]*b[j]

    if(s+c > 0):
        t = t + 1

print(t)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n,i;
  cin >> n;
  vector<int> vec(n);
  for(i=0;i<n;i++){
    cin >> vec.at(i);
  }
  sort(vec.begin(),vec.end());
  reverse(vec.begin(),vec.end());
  int count = 0;
  for(i=0;i<n-1;i++){
    if(vec.at(i)!=vec.at(i+1) ){
    count ++;
    }
  }
  count++;
  cout << count << endl;
}


Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		try(Scanner scanner = new Scanner(System.in)) {
			String data1 = scanner.nextLine();
			String data2 = scanner.nextLine();

			int N = Integer.parseInt(data1);

			String[] arr = data2.split(" ");
			List<Integer> list = new ArrayList<Integer>();
			for (String s : arr) {
				list.add(Integer.parseInt(s));
			}

			int count = 0;
			for (int i = 1; i <= list.size(); i++) {
				if (i % 2 == 0) {
					continue;
				}
				int n = list.get(i - 1);
				if (n % 2 != 0) {
					count++;
				}
			}

			System.out.println(count);
		}
	}
}

Measured memory_bytes: 35608
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<queue>
#include<stack>
#include<cassert>
#include<numeric>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
using namespace std;
const int INF = 1001001001;
const long long LINF = 1001002003004005006ll;
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; }
typedef long long ll;
typedef pair<int,int> P;

int main(){
    int l,r,d;
    cin >> l >> r >> d;
    int ans = 0;
    for(int i=l;i<=r;i++){
        if(i%d==0)ans++;
    }
    cout << ans << endl;
}

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

#define FOR(i,a,b) for(int i = (a); i < (b); ++i)
#define REP(i,n) FOR(i,0,n)
using ll = long long;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using mii = map<int, int>;
using msi = map<string, int>;
using pii = pair<int, int>;

struct Edge {
    int to;     // 辺の行き先
    int weight; // 辺の重み
    Edge(int t, int w) : to(t), weight(w) { }
};
using Graph = vector<vector<Edge>>;

int main()
{
    ios::sync_with_stdio(false);
    int h,w,n;
    cin >>h>>w>>n;
    int a = max(h,w);
    int ans = (n+a -1)/a;
    cout << ans << endl;
     
    return 0;
}

Measured memory_bytes: 384
#include "bits/stdc++.h"
using namespace std;
#ifdef _DEBUG
#include "dump.hpp"
#else
#define dump(...)
#endif

//#define int long long
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9) + 7;
const double PI = acos(-1);
const double EPS = 1e-9;
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; }
struct DisjointSet {
	vector<int>p, rank;
	DisjointSet(int n) {
		p.resize(n);
		rank.assign(n, 0);
		rep(i, 0, n)p[i] = i;
	}
	int findSet(int x) {
		if (x != p[x])p[x] = findSet(p[x]);
		return p[x];
	}
	int same(int x, int y) {
		return findSet(x) == findSet(y);
	}
	void unite(int x, int y) {
		if (same(x, y))return;
		x = findSet(x), y = findSet(y);
		if (rank[x] < rank[y])p[x] = y;
		else {
			p[y] = x;
			if (rank[x] == rank[y])rank[x]++;
		}
	}
};
signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n, q; cin >> n >> q;
	DisjointSet uf(n);
	rep(i, 0, q) {
		int com, x, y; cin >> com >> x >> y;
		if (com)cout << uf.same(x, y) << endl;
		else uf.unite(x, y);
	}
	return 0;
}

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

using namespace std;
#define int long long int
#define pb push_back
#define ub upper_bound
#define lb lower_bound
#define vi vector <int>
#define sz(s) (int)s.size()
#define pii pair<int,int>
#define piii pair< int,pair<int,int> >
#define tiii tuple <int,int,int>
#define ff first
#define ss second
#define all(a) a.begin(),a.end()
#define rall(v) v.rbegin(),v.rend()
#define endl '\n'
#define matrix vector <vector <int> >
#define boost ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define NAYAN freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
#define N 1006
#define mod 1000000007
#define mod2 998244353
#define inf 1e18




int32_t main()  
{
    boost
    // #ifndef ONLINE_JUDGE 
    // NAYAN
    // #endif
    string s1,s2;

    cin >> s1 >> s2;

    int n=s1.length();
    int m=s2.length();

    s1=' '+s1;
    s2=' '+s2;


    vector <vector <int> > dp(n+1,vector<int> (m+1,0));

    int i,j;

    for(i=1;i<=n;i++)
    {
        for(j=1;j<=m;j++)
        {
            if(s1[i]==s2[j])
            {
                dp[i][j]=1+dp[i-1][j-1];
            }
            else
            {
                dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
            }
        }
    }

    string ans="";

    i=n;
    j=m;
    while(i>=1 && j>=1)
    {
        if(s1[i]==s2[j])
        {
            ans=s1[i]+ans;
            i--;
            j--;
        }
        else
        {
            if(dp[i-1][j]>dp[i][j-1])
                i--;
            else
                j--;
        }
    }
    cout << ans << endl;


}

Measured memory_bytes: 70784
s = input()
t = input()

while s != '':
    if [i for i, x in enumerate(s) if x == s[0]] == [i for i, x in enumerate(t) if x == t[0]]:
        s = s.replace(s[0],'')
        t = t.replace(t[0],'')
    else:
        print('No')
        exit()

print('Yes')


Measured memory_bytes: 11548
#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>
#include <cstdint>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <cmath>
#include <cstdlib>
#include <sstream>
#include <functional>

#include <boost/range/irange.hpp>
using boost::irange;

#include <boost/utility/string_ref.hpp>
using string_view = boost::string_ref;

using namespace std;

struct edge_t {
    int a,b;
};

vector<int> neighbour(const vector<edge_t>& edges, int k)
{
    vector<int> neighbour_k;
    neighbour_k.reserve(edges.size());
    
    for(const auto& e : edges)
    {
        if(e.a == k) neighbour_k.push_back(e.b);
        else if(e.b == k) neighbour_k.push_back(e.a);
    }
    
    sort(begin(neighbour_k), end(neighbour_k));
    
    return neighbour_k;
}

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

    int n,m;
    cin >> n >> m;
    
    vector<edge_t> edges(m);
    for(auto& e : edges) cin >> e.a >> e.b;
    
    const auto neighbour_1 = neighbour(edges, 1);
    const auto neighbour_n = neighbour(edges, n);
    
    vector<int> isec;
    
    set_intersection(begin(neighbour_1), end(neighbour_1), begin(neighbour_n), end(neighbour_n), back_inserter(isec));
    
    if(isec.empty())
    {
        cout << "IMPOSSIBLE\n";
    }
    else
    {
        cout << "POSSIBLE\n";
    }

    return 0;
}



Measured memory_bytes: 2560
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <tuple>
#include <utility>
#include <vector>
#define ll long long
#define double long double
#define itn int
#define endl '\n'
#define co(ans) cout<<ans<<endl
#define COYE cout<<"YES"<<endl
#define COYe cout<<"Yes"<<endl
#define COye cout<<"yes"<<endl
#define CONO cout<<"NO"<<endl
#define CONo cout<<"No"<<endl
#define COno cout<<"no"<<endl
#define FORE(i,a) for(auto &i:a)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define FFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define RREP(i,n)  FFOR(i,1,n)
#define PB push_back
#define MP make_pair
#define ALL(V) (V).begin(),(V).end()
#define SORT(V) sort((V).begin(),(V).end())
#define REVERSE(V) reverse((V).begin(),(V).end())
#define EACH(V,i) for(typeof((V).begin()) i=(V).begin();i!=(V).end();++i)
#define INF ((1LL<<62)-(1LL<<31))
#define EPS 1e-10
#define PI 3.141592653589793238
#define MOD 1000000007
#define MAX 5100000
using namespace std;
using Graph=vector<vector<int>>;
inline int toInt(string s){int v;istringstream sin(s);sin>>v;return v;}
template<class T>inline string toString(T x){ostringstream sout;sout<<x;return sout.str();}
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;}
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
const int dx[4]={0,1,0,-1},dy[4]={1,0,-1,0};
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}

int main(){
  int N,M,ans=0;
  bool CAN=true;
  
  cin>>N>>M;
  Graph G(N);
  ll SEEN[N];
  REP(i,M){
    ll a,b;
    cin>>a>>b;
    G[a-1].PB(b-1);
    G[b-1].PB(a-1);
  }
  REP(i,N) SEEN[i]=0;
  
  VI A,B;
  A.PB(0);
  B.PB(G[0][0]);
  SEEN[0]=1;
  SEEN[G[0][0]]=1;
  
  ll T=0;
  while(1!=0){
    bool CAN=false;
    REP(i,G[T].size()){
      if(SEEN[G[T][i]]==0){
        A.PB(G[T][i]);
        SEEN[G[T][i]]=1;
        T=G[T][i];
        CAN=true;
        break;
      }
    }
    if(CAN==false) break;
  }
  
  T=G[0][0];
  while(1!=0){
    bool CAN=false;
    REP(i,G[T].size()){
      if(SEEN[G[T][i]]==0){
        B.PB(G[T][i]);
        SEEN[G[T][i]]=1;
        T=G[T][i];
        CAN=true;
        break;
      }
    }
    if(CAN==false) break;
  }
  
  
  REVERSE(A);
  cout<<A.size()+B.size()<<endl;
  REP(i,A.size()) cout<<A.at(i)+1<<" ";
  REP(i,B.size()) cout<<B.at(i)+1<<" ";
  cout<<endl;
  return 0;
}

Measured memory_bytes: 7544
def main():
    N = int(input())
    A = list(map(int, input().split()))
    x = 0
    s = 0
    r = 0
    res = 0
    for l in range(N):
        while N > r and x ^ A[r] == s + A[r]:
            x ^= A[r]
            s += A[r]
            r += 1

        x ^= A[l]
        s -= A[l]
        res += r - l

    print(res)
if __name__ == '__main__':
    main()

Measured memory_bytes: 24840
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
#define rep(i,m,n) for(int i=(int)(m);i<(int)(n);++i)
#define rREP(i,m,n) for(int (i)=(n)-1; (i)>=(m);--(i))
#define all(x) (x).begin(),(x).end()
#define out(y,x,h,w) (y)<0||(x)<0||(y)>=(h)||(x)>=(w)
constexpr int INF = 1000000001;
constexpr ll mod = 1000000007;
constexpr double PI = 3.1415926535897932;

template<class T>inline bool chmin(T& a, T b) {
	if (a > b) {
		a = b;
		return true;
	}
	return false;
}
template<class T>inline bool chmax(T& a, T b) {
	if (a < b) {
		a = b;
		return true;
	}
	return false;
}
inline void init() {
	cin.tie(nullptr); cout.tie(nullptr);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(15);
}

int main() {
	init();

	int N; cin >> N;
	vector<map<char,int>>s(N);
	rep(i, 0, N) {
		string a; cin >> a;
		rep(j, 0, a.size()) {
			s[i][a[j]]++;
		}
	}
	string ans = "";
	for (auto p : s[0]) {
		int cnt = p.second;
		char ch = p.first;
		bool ok = true;
		rep(i, 1, N) {
			if (s[i].count(ch))chmin(cnt, s[i][ch]);
			else ok = false;
		}
		if (ok) {
			rep(i, 0, cnt) {
				ans += ch;
			}
		}
	}
	cout << ans << "\n";

	return 0;
}

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

bool is_prime(int x) {
  if (x < 2) return false;
  else if (x == 2) return true;
  else if (x % 2 == 0) return false;
  
  double sqrtx = sqrt(x);
  for (int i = 3; i <= sqrtx; i += 2) {
    if (x % i == 0) return false;
  }
    return true;
}

int main() {
  bool next_prime = true;
  int x;
  cin >> x;
  
  while (next_prime) {
    if (is_prime(x)) {
      next_prime = false;
      cout << x << endl;
    }
    else x++;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
int main(){
  int n;
  cin>>n;
  vector<int> t(n);
  rep(i,n){
    cin>>t[i];
  }
  int m;
  cin>>m;
  vector<int> ans(m);
  rep(i,m){
    int p,x;
    cin>>p>>x;
    int c=t[p-1];
    t[p-1]=x;
    rep(j,n){
      ans[i]+=t[j];
    }
    t[p-1]=c;
  }
  rep(i,m){
    cout<<ans[i]<<endl;
  }
}

Measured memory_bytes: 3584
/*
(A，B](左边取不到）里可以整除C的数有B/C-A/C个，那答案就出来了

B/C-A/C+B/D-A/D-（B/e-A/e）（e为cd最小公倍数）

在判断一下左边界A，总的一减即可。
*/

#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const int N=100005;
//int a[N];
int n,L ;
LL gcd(LL a,LL b)
{
	return a == 0 ? b : gcd(b % a, a);
}
LL  a,b,c,d;
int main()
{
     cin>>a>>b>>c>>d;
     LL ans=b/c-a/c+b/d-a/d-(b/(c*d/gcd(c,d))-a/(c*d/gcd(c,d)));
     if(a%c==0) ans++;
     if(a%d==0) ans++;
     if(a%(c*d)==0) ans--;
   //cout<<ans<<endl;
     ans=b-a+1-ans;
     cout<<ans<<endl;
 
	return 0;
 
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
#define ll long long int
#define pb push_back
using namespace std;
ll c[200005]={0};
vector<ll>v[200005];
ll k;
void isc(int i)
{
    k++;
    c[i]=1;
    for(auto it : v[i]){
       if(c[it]==0){
           isc(it);
       }
    }
}

void solve()
{
    ll n,m;
    cin >> n >> m;
    
    for(int i=0,x,y;i<m;i++){
      cin >> x >> y;
      v[x].pb(y);
      v[y].pb(x);
    }
    ll ans=0;
    for(int i=0;i<n;i++)
    {
        k=0;
        if(c[i]==0){
            isc(i);
        }
        ans=max(ans,k);
    }
    cout << ans << endl;
}

int main()
{
    int t=1;
    //cin >> t;
    while(t--)
    solve();
    return 0;
}

Measured memory_bytes: 22348
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		new Main().run();
	}

	private void run() {
		Scanner scanner = new Scanner(System.in);
		while (true) {
			int n = scanner.nextInt();
			if (n == 0)
				break;
			a = new int[10];
			while (n-- > 0) {
				int b = scanner.nextInt();
				a[b]++;
			}
			int sum = 0;
			for (int i = 1; i < 5; i++) {
				int c = Math.min(a[i], a[10 - i]);
				sum += c;
				a[i] -= c;
				a[10 - i] -= c;
			}
			sum += a[5] / 2;
			a[5] %= 2;

			ans = 0;
			dfs(1, 0, 0);
			System.out.println(sum + ans);

		}
	}

	private void dfs(int i, int sum, int now) {
		int rem = sum;
		for (int j = 1; j < 10; j++)
			rem += a[j] * j;
		if (now + rem / 10 <= ans)
			return;
		ans = Math.max(ans, now);
		if (sum == 10) {
			dfs(1, 0, now + 1);
			return;
		}
		if (i == 10)
			return;
		dfs(i + 1, sum, now);
		if (a[i] > 0 && i + sum <= 10) {
			a[i]--;
			dfs(i, sum + i, now);
			a[i]++;
		}
	}

	int ans;
	int[] a;
}

Measured memory_bytes: 30684
def mcheck(m):
  if m >= 1 and m <= 12:
    return True
  else:
    return False

S = [int(x) for x in list(input())]
  
A = S[0] * 10 + S[1]
B = S[2] * 10 + S[3]

Acheck = mcheck(A)
Bcheck = mcheck(B)

result = 'NA'
if Acheck and Bcheck:
  result = 'AMBIGUOUS'
elif Acheck == True and Bcheck == False:
  result = 'MMYY'
elif Acheck == False and Bcheck == True:
  result = 'YYMM'
  
print(result)

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

int main()
{
    ll n,f=0;
    cin>>n;
    unordered_map<ll,ll> m;
    for(ll i=0;i<n;i++)
    {
        ll x;
        cin>>x;
        if(m.find(x)!=m.end())
        {
            f=1;
            break;
        }
        m[x]++;
    }
    if(f) cout<<"NO"<<endl;
    else cout<<"YES"<<endl;
}

Measured memory_bytes: 8520
using System;
using System.Collections.Generic;
class Program
{
	static void Main(string[] args)
	{
		string[] str = Console.ReadLine().Split();
		long N = long.Parse(str[0]);
		long A = long.Parse(str[1]);
		long B = long.Parse(str[2]);
		long mod = 1000000007;
		long ans = Mpow(2,N,mod);
		ans = ans + mod - Ncr(N,A,mod) + mod - Ncr(N,B,mod) - 1 + mod;
		ans %= mod;
		Console.WriteLine(ans);
	}
	
	public static long Mpow(long x,long n,long m)
	{
		long ans = 1;
		while(n > 0){
			if(n % 2 == 1){
				ans = ans * x % m;
				n -= 1;
			}
			x = x * x % m;
			n /= 2;
		}
		return ans;
	}
	public static long Ncr(long n,long r,long m)
	{
		long ans = 1;
		for(var i=n-r+1;i<=n;i++){
			ans = ans * i % m;
		}
		for(var i=2;i<=r;i++){
			ans = ans * Mpow(i,m-2,m) % m;
		}
		return ans;
	}
}

Measured memory_bytes: 11220
{-# OPTIONS_GHC -O2 #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE TupleSections #-}
module Main where

import           Data.List
import           Control.Monad
import           Debug.Trace
import qualified Data.ByteString.Char8         as BC
import           Data.Maybe                     ( fromJust, fromMaybe )
import qualified Data.Set                      as S
import qualified Data.IntMap.Strict            as IM
import qualified Data.IntMap.Lazy            as IML
import qualified Data.Map.Strict               as M
import           Data.Char
import qualified Data.Array.IArray as A
import qualified Data.Array.Unboxed as UA
import Data.Bits
import Control.Monad.State.Strict
import qualified Data.Array.ST as STA
import qualified Data.Array.IO as IOA
import qualified Data.Array.MArray as MA
import Control.Monad.ST
import System.IO (stdin)
import Control.Arrow
import qualified Data.Vector as V
import qualified Data.Vector.Unboxed as UV
import qualified Data.Vector.Generic as GV
import qualified Data.Vector.Mutable as MV
import Data.Ix
import Data.Ord (Down(Down))
import qualified Data.Sequence as Seq
import Data.Foldable (toList)
-- import Control.Lens

debug = False

ts :: Show a => a -> a
ts a = if debug then traceShowId a else a


readTuple2 :: IO (Int, Int)
readTuple2 = do
    [a, b] <- readInts
    return (a, b)

readTuple3 :: IO (Int, Int, Int)
readTuple3 = do
    [a, b, c] <- readInts
    return (a, b, c)


readInt :: IO Int
readInt = fst . fromJust . BC.readInt <$> BC.getLine

readInts :: IO [Int]
readInts = map (fst . fromJust . BC.readInt) . BC.words <$> BC.getLine

split :: (a -> Bool) -> [a] -> [[a]]
split f [] = []
split f as =
    let (fo, la) = span f as
        las      = case la of
            [] -> []
            xs -> split f $ tail xs
    in  case fo of
            [] -> las
            xs -> xs : las


solve :: Int -> Int -> Int
solve n k = modZero + modHalf where
  modZero = (n `div` k) ^ 3
  modHalf = if odd k then 0 else ((n + (k `div` 2)) `div` k) ^ 3



main :: IO ()
main = do
  readTuple2 >>= print . uncurry solve





Measured memory_bytes: 380
N, Q = map(int, input().split())
S = input()
counts = [0 for i in range(N)]
cnt = 0
for i in range(1, N):
    if(S[i-1:i+1] == "AC"):
        cnt += 1
    counts[i] = cnt

for i in range(Q):
    l, r = map(int, input().split())
    print(counts[r-1] - counts[l-1])


Measured memory_bytes: 6184
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i=0; i<(int)(n); i++)
#define ALL(x) x.begin(), x.end()
#define MOD 1000000007
typedef long long ll;

int main() {
    int n, a;
    cin >> n >> a;
    if(n%a == 0){
        cout << n/a << endl;
    }else{
        cout << n/a+1 << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
 
#define f(i,a,b) for( ll i = a; i < b ; i++ ) 
#define af(i,a,b) for( ll i = a; i >= b ; i--)
#define rep(i,a,b,k) for(ll i = a; i < b ; i+= k )
#define arep(i,a,b,k) for( ll i = a; i >= b ; i-= k)
#define ones(x) (ll) __builtin_popcount(x);1
#define fs first
#define sc second
#define pb push_back
#define po pop_back
#define mp make_pair	
#define sz(a) (ll) a.size()
#define all(a) a.begin(), a.end()
#define sor(a) sort( a.begin(), a.end() )
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL)
#define ller ios::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr)
#define yes cout<<"Yes\n"
#define no cout<<"No\n"
using namespace std;
typedef long long ll;
typedef long double ld;	
typedef pair<ll,ll> ii ;
typedef vector<ll>  vi ;
typedef vector<ii> vii ;
 
const ll MAX = 10000000;
const ll inf = 5e18-1;

int main() {
	fastio;
	ll n,m,c,cont=0;
	cin>>n>>m>>c;
	ll b[m];
	f(i,0,m){
		cin>>b[i];
	}
	while(n--){
		ll sum=0;
		ll a[m];
		f(i,0,m){
			cin>>a[i];
		}
		f(i,0,m){
			sum += a[i]*b[i];
		}
		sum+=c;
		if(sum>0) cont++;
	}
	cout<<cont<<endl;
    return 0;
	}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm> 
using namespace std;
 
int to_sum(int x) {
	int sum = 0;
	while ( x > 0) {
		sum += x % 10;
		x /= 10;
	}
	return sum;	
}
 
int main() {
	int n;
 
	cin >> n;
	cout << (n % to_sum(n) == 0 ? "Yes" : "No") << endl;
}

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

int main() {
    int N;
    cin >> N;
    int sum=0;

    int a;
    for(int i=0;i<N;i++){
        cin >> a;
        while(a%2==0){
            a/=2;
            sum++;
        }
    }

    cout << sum << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
template <class T> inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T> inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return 1;
    }
    return 0;
}
typedef long long int ll;

#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define endl "\n"
const double EPS = 1e-7;
const int INF = 1 << 30;
const ll LLINF = 1LL << 60;
const double PI = acos(-1);
const int MOD = 1000000007;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

//-------------------------------------

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s, t;
    cin >> s >> t;
    sort(ALL(s));
    sort(RALL(t));
    cout << (s < t ? "Yes" : "No") << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int a = scan.nextInt();
        int b = scan.nextInt();
        int c = scan.nextInt();
        int d = scan.nextInt();

        System.out.println(Math.min(a, b) + Math.min(c, d));
    }
}


Measured memory_bytes: 21844
#include <bits/stdc++.h>
using namespace std;
int main() {
 	string s;
  	cin >> s;
  	if (s.size() % 2)
      return cout << "No", 0;
  	for (int i = 0; i < s.size(); i += 2)
      if (s[i] != 'h' || s[i + 1] != 'i')
        return cout << "No", 0;
  	cout << "Yes";
}

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

int top;
int S[STACK_SIZE];

void initialize();
bool isEmpty();
bool isFull();
void push(int NewElement);
int pop();

int main()
{
    initialize();
    string input[STACK_SIZE];
    int i = 0;

    while(cin >> input[i]){
        i++;
    }

    for(int j = 0; j < i; j++){
        if(input[j] == "+"){
            int ans = pop() + pop();
            // cout << "Pushed : "<< ans << endl;
            push(ans);
        }else if(input[j] == "-"){//これだとOK
            int ans = -pop();
            ans += pop();
            //これだとダメ int ans = -pop() + pop();
            // cout << "Pushed : "<< ans << endl;
            push(ans);
        }else if(input[j] == "*"){
            int ans = pop() * pop();
            // cout << "Pushed : "<< ans << endl;
            push(ans);
        }else{
            push(stoi(input[j]));
            // cout << "NumPushed : "<< stoi(input[j]) << endl;
            }
        // rep(k, i) cout << S[k] << " ";
        // cout << "Top : " <<top << endl;

    }

    cout << S[1] << endl;

    return 0;
}

void initialize() //スタックの初期化
{
    top = 0;
    return;
}

bool isEmpty() //スタックが空の時Trueを返す
{
    return top == 0;
}

bool isFull() //スタックが満タンの時Trueを返す
{
    return top >= STACK_SIZE - 1;
}

void push(int NewElement) //末尾に要素を追加
{
    if (isFull()){
        printf("オーバーフロー\n");
        return;
    }

    ++top;
    S[top] = NewElement;
    return;
}

int pop() //要素を末尾から1取り出す
{
    if (isEmpty()){
        printf("アンダーフロー\n");
        return -9999;
    }

    --top;
    return S[top + 1];
}



Measured memory_bytes: 3224
#include<bits/stdc++.h>
#define int long long
const int inf=8938103643641919514ll;
const int mod=1000000007ll;
const int dd[]={0,-1,0,1,0};
using namespace std;
int a,b,c,d;
int p[200000];
signed main(){
	cin>>a>>b>>c;
	int ans=a*100+b*10+c;
	if(ans%4==0)
		cout<<"YES"<<endl;
	else
		cout<<"NO"<<endl;
}

Measured memory_bytes: 256
while (n, x = gets.split.map(&:to_i)) != [0, 0] do

	count = 0
	for i in 1..n do
		for j in (i+1)..n do
			for k in (j+1)..n do
				if  i + j + k == x then
					count += 1
				end
			end		
		end
	end

	puts count

end

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

using namespace std;

typedef long long lli;
typedef double lld;
typedef vector<lli> vll;
typedef vector<bool> vbl;
typedef vector<double> vdl;
typedef vector<vector<lli>> mat;
typedef vector<vdl> mad;
typedef unordered_map<lli,unordered_map<lli,lli>> graph;
typedef complex<double> cmp;
typedef vector<cmp> vcl;

lli n;
vll x;
lli l;
lli q;

unordered_map<lli,unordered_map<lli,lli>> dp;
lli ub = 1;

bool check(lli bit,lli from,lli to){
  for(lli b = ub;b > 0;b >>= 1){
    if(bit&b) from = dp[b][from];
  }
  return from >= to;
}

int main(){
  cin >> n;
  x = vll(n+1);
  for(lli i = 1;i <= n;i++) cin >> x[i];
  cin >> l;
  for(lli i = 1;i <= n+1;i++) dp[0][i] = i;
  for(lli i = 1;i <= n;i++) dp[1][i] = upper_bound(x.begin(),x.end(),x[i]+l)-x.begin()-1;
  dp[1][n+1] = n+1;
  for(lli b = 2;b < n;b <<= 1){
    ub = b;
    for(lli i = 1;i <= n+1;i++) dp[b][i] = dp[(b >> 1)][dp[(b >> 1)][i]];
  }
  cin >> q;
  for(lli i = 0;i < q;i++){
    lli a,b;
    cin >> a >> b;
    if(a > b) swap(a,b);
    lli ans = (ub << 1)-1ll;
    for(lli bit = ub;bit > 0;bit >>= 1){
      if(check(ans^bit,a,b)) ans ^= bit;
    }
    cout << ans << endl;
  }
  return 0;
}


Measured memory_bytes: 75684
using System;

class Program {
  static void Main() {
    double n = double.Parse(Console.ReadLine());
    double result = 0;
    for(double i=1;i<=n;i++) {
      if (i%3==0||i%5==0) {continue;}
      result += i;
    }
    Console.WriteLine(result.ToString());
  }
}

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

int f(int n) {
  if (n % 2 == 0) return n / 2;
  else return n * 3 + 1;
}

int main() {
  int s;
  cin >> s;
  set<int> a;
  a.insert(s);
  while (1) {
    s = f(s);
    if (a.count(s) == 0) a.insert(s);
    else break;
  }
  cout << a.size() + 1 << endl;
  return 0;
}


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

void makeFibonacci(int fib[]){
  fib[0] = 1;
  fib[1] = 1;
  for(int i=2; i<=44; i++){
    fib[i] = fib[i-1] + fib[i-2];
  }
}

int main(){

  int fib[45];
  makeFibonacci(fib);

  int n;
  scanf("%d", &n);
  printf("%d\n", fib[n]);

  return 0;
}



Measured memory_bytes: 3236
#include <bits/stdc++.h>
#include <vector>
#include <iostream>
#include<algorithm>
#include<string>
#include <map>
#include <queue>

using namespace std;

void ans(long long N, long long X,long long &pate) {
    //cout << pate << endl;
    if (N == 1) {
        if (X <= 0) return;
        else if (X >= 5) pate += 3;
        else  pate+= X - 1;       
    }
    else {
        if (X <= 0)return;
        if (X < pow(2, N + 1) - 1)
            ans(N - 1, X - 1,pate);
        else {
            pate += pow(2, N);
            ans(N - 1, X - (pow(2, N + 1) - 1),pate);
        }
    }
}
int main() {
    long long N, X;
    cin >> N >> X;
    long long pate = 0;

    ans(N, X, pate);
    cout << pate << endl;

}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int func(int a, int b);
int main(){
	int a, b, c;

	while(cin >> a >> b){
		c=func(a,b);
		cout << c << endl;
	}
	
	return 0;
}

int func(int a, int b){
	int d, e, f;

	if(a>=b){ d=a; e=b; }
	else { d=b; e=a; }
	f=e;
	while(1){
		if(d%f==0) return f;
		f=d % e;
		d=e;
		e=f;
	}
}

Measured memory_bytes: 3076
using System;
using System.Linq;

class Program
{
    static void Main(string[] args)
    {
        var input = Console.ReadLine().Split().Select(x => long.Parse(x)).ToArray();
        Console.WriteLine(input[0] == input[1] ? "Yes" : "No");

#if DEBUG
		Console.ReadKey();
#endif
    }
}

Measured memory_bytes: 13396
type Scanner() = class
    let mutable hold = [||]
    let mutable index = 0
    member public this.Next() =
        if hold.Length > index
        then 
            index <- index + 1
            hold.[index - 1]
        else
            let mutable st = stdin.ReadLine()
            while st = "" do st <- stdin.ReadLine()
            hold <- st.Split(' ')
            if hold.Length = 0
            then
                this.Next()
            else
                index <- 1
                hold.[index - 1]
            
    member public this.NextI32() =
        this.Next() |> int

    member public this.ArrayI32(n: int) =
        [for _ in 0 .. n - 1 -> this.NextI32()]

    member public this.NextI64() =
        this.Next() |> int64
    
    member public this.ArrayI64(n: int) =
        [for _ in 0 .. n - 1 -> this.NextI64()]

    member public this.NextF32() =
        this.Next() |> float32
    
    member public this.ArrayF32(n: int) =
        [for _ in 0 .. n - 1 -> this.NextF32()]

    member public this.NextF64() =
        this.Next() |> double
    
    member public this.ArrayF64(n: int) =
        [for _ in 0 .. n - 1 -> this.NextF64()]

    member public __.Tuple2List n (f : int -> 'a list) =
        [for _ in 0 .. n - 1 -> f 2 |> fun x -> x.[0], x.[1]]
    
    member public __.Tuple3List n (f : int -> 'a list) =
        [for _ in 0 .. n - 1 -> f 3 |> fun x -> x.[0], x.[1], x.[2]]

end

[<EntryPoint>]
let main _ =
    let scanner = Scanner()
    let a = scanner.Next()
    let b = scanner.Next()

    let lenComparison f lena lenb =
        if f lena > f lenb then
            (true, "GREATER")
        else if f lena < f lenb then
            (true, "LESS")
        else
            (false, "")

    let rec intComparison (aa:string) (bb:string) ind len =
        let x = int aa.[ind]
        let y = int bb.[ind]
        if x <> y then
            if x > y then "GREATER" else "LESS"
        else
            if ind + 1 = len then
                "EQUAL"
            else
                intComparison aa bb (ind + 1) len

    match lenComparison String.length a b with
        | (x, y) when x -> y
        | (_, _) -> intComparison a b 0 (String.length a)
    |> printfn "%s"

    0



Measured memory_bytes: 14812
/*
// Author -> Preeyadarshee Dev
//
// train hard win easy :D
// nik is love
// nik is motivation
//
// do modulo operations very carefully
// try to avoid binary search, use linear search preferrably to make calculations easier
// always make your custom binary search and watch out for overflows
// read the problems carefully
*/
/*
*/
#include <bits/stdc++.h>
#define mp                    make_pair
#define pb                    push_back
#define ll                   long long
#define ss                       second
#define ff                        first
#define fr(i,a,b)   for(ll i=a;i<b;i++)
#define f(i,n)                fr(i,0,n)
#define rf(i,b,a) for(ll i=b-1;i>=a;i--)
#define r(i,n)                rf(i,n,0)
#define inf                   1000000007
#define eps                  0.000000000000001
#define endl                       '\n'
#define sz(a)                int((a).size())
#define all(c)               (c).begin(),(c).end()
#define tr(c,i)              for(typeof(c).begin() i = (c).begin(); i != (c).end(); i++)
#define present(c,x)         ((c).find(x) != (c).end())
#define cpresent(c,x)        (find(all(c),x) != (c).end())
#define pi                   pair<int,int>
#define PI                   3.141592653589793238462643383279502884197169399375105820974944592307816406286
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
typedef pair<int,int> ii;
typedef vector< int > vi;
typedef vector< vi > vvi;
int dx[8]={1,-1,0,0,-1,-1,1,1};
int dy[8]={0,0,-1,1,-1,1,-1,1};
vector<int> adj[100010];
vector<int> vis(100010,0);
ll gcd(ll a,ll b)
{
    if(b==0)
        return a;
    else
        return gcd(b,a%b);
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    //ifstream fin;
    //ofstream fout;
    //fin.open("input.txt");
    //fout.open("output.txt");
    //let's fuck dp
    long long a,b,c,d;
    cin>>a>>b>>c>>d;
    ll gc=gcd(c,d);
    ll e=(c*d)/gc;
    ll l=a-1,r=b;
    ll cnt1=r/c-l/c+r/d-l/d-r/e+l/e;
    ll ans=b-(a-1)-cnt1;
    cout<<ans<<endl;
}



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

int main() {
    int n;
    cin >> n;

    if (n == 1) {
        cout << 1 << endl;
    } else if (n % 2) {
        cout << (double)(n / 2 + 1) / (double)n << endl;
    } else {
        cout << 0.5 << endl;
    }

    return 0;
}

Measured memory_bytes: 256
//#include "pch.h"
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
#include <functional>
#include <map>
#include <iomanip>
#include <math.h> 
#include <stack>
#include <queue>
#include <bitset>
#include <cstdlib>
#include <tuple>
#include <cctype>
#include <ctype.h>
#include <set>
#include <sstream>
#include <time.h>
#include <numeric>
using namespace std;
//#define int long long
#define rep(i,s,n) for(int i = s;i<n;i++)
#define repe(i,s,n) for(int i = s;i<=n;i++)
#define rrep(i,s,n) for(int i = (n)-1;i>=(s);i--)
#define all(v) (v).begin(),(v).end()
#define pb push_back
#define fi first
#define se second
#define chmin(a,b) a=min((a),(b))
#define chmax(a,b) a=max((a),(b))
#define l1 list[index]
#define l2 list[index - 1]
#define l3 list[index + 1]
#define iif(i,j) ((i<0 && j<0) || (i>0 && j>0)) ? true : false 
typedef long long ll;
typedef pair<int, int>pint;
typedef vector<int>vint;
typedef vector<pint>vpint;
typedef pair<pint, int> P1;
typedef pair<int, pint> P2;
typedef pair<pint, pint> PP;
static const ll maxLL = (ll)1 << 62;
const ll MOD = 1000000007;
const ll INF = 1e18;
const double PI = 3.14159265359;
int ca[12] = { 31,28,31,30,31,30,31,31,30,31,30,31 };




signed main() {
	ll a, b, q;
	//ll s[100005], t[100005];
	//vector<pair<ll,ll>>x(100005, make_pair(INF, INF));
	//ll s2[100005], t2[100005];
	ll x[100005];
	vector<ll>s, t;


	cin >> a >> b >> q;

	for (int i = 0; i < a; i++) {
		ll num;
		cin >> num;
		s.push_back(num);
	}

	for (int i = 0; i < b; i++) {
		ll num;
		cin >> num;
		t.push_back(num);
	}

	vector<ll>ans;

	for (int i = 0; i < q; i++) {
		ll nn;
		cin >> nn;

		auto Iter1 = lower_bound(s.begin(), s.end(), nn);
		auto Iter2 = lower_bound(t.begin(), t.end(), nn);

		//vector<ll>ss = { Iter1 - s.begin() - 1};
		//vector<ll>tt = { Iter2 - t.begin() - 1};
		vector<ll>ss = { Iter1 - s.begin() };
		vector<ll>tt = { Iter2 - t.begin() };

		if (ss[0] == s.size())ss[0] = s.size() - 1;
		if (tt[0] == t.size())tt[0] = t.size() - 1;

		if (ss[0]  > 0) {
			ss.push_back(ss[0] - 1);
		}

		if ( tt[0]  > 0) {
			tt.push_back(tt[0] - 1);
		}

		ll minn = INF;

		for (int j = 0; j < ss.size(); j++) {
			for (int k = 0; k < tt.size(); k++) {
				minn = min({minn, abs(t[tt[k]] - s[ss[j]]) + abs(nn - t[tt[k]]), abs(t[tt[k]] - s[ss[j]]) + abs(nn - s[ss[j]])	});
			}
		}

		//cout << minn << endl;
		ans.push_back(minn);
	}

	for (int i = 0; i < ans.size(); i++) {
		cout << ans[i] << endl;
	}



	return 0;
}

Measured memory_bytes: 3828
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int INF = 1e9;
const int MOD = 1e9 + 7;

int dp[100010];

int main()
{
  int n;
  cin >> n;
  vector<int> h(n);
  for (auto &e : h)
    cin >> e;

  for (int i = 0; i < n; ++i)
    dp[i] = INF;

  dp[0] = 0;

  for (int i = 0; i < n; ++i)
  {
    dp[i + 2] = min(dp[i + 2], dp[i] + abs(h[i + 2] - h[i]));
    dp[i + 1] = min(dp[i + 1], dp[i] + abs(h[i] - h[i + 1]));
  }

  cout << dp[n - 1] << endl;

  return 0;
}


Measured memory_bytes: 1024
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <iomanip>
#include <iostream>
#include <map>
#include <string>
#include <utility>
#include <vector>
using namespace std;
typedef long long ll;

int main(){
    int N;
    double ans = 0;

    cin >> N;

    int v;
    vector<int> V;

    for(int i = 0; i < N; i++){
        cin >> v;
        V.push_back(v);
    }

    sort(V.begin(), V.end(), greater<int>());

    for(int i = 0; i < N - 1; i++){
        ans += (double)V[i] / pow(2.0, (double)i + 1.0);
    }
    ans += (double)V[N - 1] / pow(2.0, (double)N - 1.0);

    cout << setprecision(10) << ans << endl;

    return 0;
}


Measured memory_bytes: 256
class Unionfind():  # Unionfind
    def __init__(self, N):
        self.N = N
        self.parents = [-1] * N

    def find(self, x):  # グループの根
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):  # グループの併合
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return
        if self.parents[x] > self.parents[y]:
            x, y = y, x
        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):  # グループのサイズ
        return - self.parents[self.find(x)]


n, m = map(int, input().split())
ab = [list(map(int, input().split())) for _ in range(m)]

uf = Unionfind(n)
ans, cnt = [], n * (n - 1) // 2
for a, b in ab[::-1]:
    ans.append(max(cnt, 0))
    if uf.find(a - 1) != uf.find(b - 1):
        cnt -= uf.size(a - 1) * uf.size(b - 1)
        uf.union(a - 1, b - 1)
print(*ans[::-1], sep='\n')


Measured memory_bytes: 101888
#include<stdio.h>
int main(){
    int n;
    scanf("%d",&n);
    int a = n / 100;
    int b = n % 100;
    int c = n % 10;
    b = b / 10;
    //printf("%d %d %d\n",a,b,c);
    int flag = 0;
    if(a == 7 || b == 7){
        flag = 1;
    }
    if(c == 7){
        flag = 1;
    }
    if(flag == 1){
        printf("Yes\n");
    }else{
        printf("No\n");
    }
}

Measured memory_bytes: 1660
def mod_combination(mod: int, n: int, r: int) -> int:
  a, b, c = mod_factorials(mod, [n, r, n - r])

  return a * pow(b, mod - 2, mod) % mod * pow(c, mod - 2, mod) % mod

def mod_factorials(mod: int, N: [int]) -> [int]:
  result = [1] * len(N)
  tuples = sorted([(i, n) for i, n in enumerate(N)], key=lambda t: t[1])

  fact = 1
  i = 1
  for t in tuples:
    for j in range(i, t[1] + 1):
      fact = fact * j % mod
      i = i + 1

    result[t[0]] = fact

  return result


def main():
  MOD = 10 ** 9 + 7

  N, M, K = [int(i) for i in input().strip().split(' ')]
  c = mod_combination(MOD, N * M - 2, K - 2)

  X = 0
  Y = 0
  for i in range(M):
    X += (M - i) * i
  for i in range(N):
    Y += (N - i) * i

  total = (X * (N ** 2) + Y * (M ** 2)) % MOD * c % MOD
  print(total)


main()

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

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

  vector<int> wCount(n);
  wCount[0] = 0;
  for (int i = 1; i < n; ++i) {
    wCount[i] = wCount[i - 1];
    if (s[i - 1] == 'W') {
      wCount[i] += 1;
    }
  }
  vector<int> eCount(n);
  eCount[n - 1] = 0;
  for (int i = n - 2; i >= 0; --i) {
    eCount[i] = eCount[i + 1];
    if (s[i + 1] == 'E') {
      eCount[i] += 1;
    }
  }

  int res = n;
  for (int i = 0; i < n; ++i) {
    res = min(res, wCount[i] + eCount[i]);
  }
  cout << res << endl;
}


Measured memory_bytes: 3076
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <queue>
#include <algorithm>
#include <utility>
#include <cmath>
#include <bitset>
#include <map>
#include <cstring>
#include <cstdlib>

#define INF_LL 9000000000000000000
#define INF 2000000000

#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> PII;

class Union_find{
private:
	vector<int> par;
	vector<int> rank;
	int n;

public:
	Union_find(int a){
		n = a;
		for(int i = 0;i < n;i++){
			par.push_back(i);
			rank.push_back(0);
		}
	}

	int find(int x){
		if(par[x] == x){
			return x;
		}else{
			return par[x] = find(par[x]);
		}
	}

	void unite(int x, int y){
		x = find(x);
		y = find(y);
		if(x == y) return;

		if(rank[x] < rank[y]){
			par[x] = y;
		}else{
			par[y] = x;
			if(rank[x] == rank[y]) rank[x]++;
		}
	}

	bool same(int x, int y){
		return find(x) == find(y);
	}
};

int flag[10] = {};
int N, M;
vector<int> G[9];

int dfs(int x, int be, int cnt){
	if(cnt == N) return 1;
	
	ll res = 0;
	REP(i, G[x].size()){
		if(flag[G[x][i]]) continue;
		flag[G[x][i]] = true;
		res += dfs(G[x][i], x, cnt+1);
		flag[G[x][i]] = false;
	}
	return res;
}

int main(void){
	cin >> N >> M;
	REP(i, M){
		int a, b;
		cin >> a >> b; a--; b--;
		G[a].push_back(b);
		G[b].push_back(a);
	}
	flag[0] = true;
	cout << dfs(0, -1, 1) << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  
  vector<int> v(5);
  for(int i; i < 5; i++)
    cin >> v.at(i);
  
  vector<int> w(5);
  for(int i; i < 5; i++)
    w.at(i) = (v.at(i) % 10);
  
  int j = 10;
  int k = 0;
  
  while(k < 5){
    if((w.at(k) > 0) && (w.at(k) < j))
      j = w.at(k);
    k++;
  }
  
  int l = 0;
  int m = 0;
  
  while(l < 5){
    if(w.at(l) == 0){
      m += v.at(l);
    }
    if(w.at(l) != 0){
      m += ((v.at(l) - w.at(l)) + 10);
    }
    l++;
  }
  
  cout << m + j - 10 << endl; 
}
         

Measured memory_bytes: 256
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.NoSuchElementException;
import java.util.PriorityQueue;

class Main {
	public static void main(String[] args) {
		new Main().run();
	}
	
	void run() {
		FastScanner sc=new FastScanner();
		PrintWriter pw=new PrintWriter(System.out);
		int N=sc.nextInt();
		int K=sc.nextInt();
		pw.println(N-K+1);
		pw.close();
	}
	
	static void tr(Object... objects) {
		System.out.println(Arrays.deepToString(objects));
	}

}


class FastScanner {
    private final InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;
    private boolean hasNextByte() {
        if (ptr < buflen) {
            return true;
        }else{
            ptr = 0;
            try {
                buflen = in.read(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (buflen <= 0) {
                return false;
            }
        }
        return true;
    }
    private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;}
    private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126;}
    public boolean hasNext() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++; return hasNextByte();}
    public String next() {
        if (!hasNext()) throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while(isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }

    public int nextInt() {
    	return Integer.parseInt(next());
    }
    
    public long nextLong() {
    	return Long.parseLong(next());
    }
}

Measured memory_bytes: 21332
#include<cstdio>
#include<algorithm>
#define fo(i,a,b) for(i=a;i<=b;i++)
using namespace std;
typedef long long ll;
const int maxn=100000+10;
const ll inf=100000000000000000;
int h[maxn],go[maxn*2],nxt[maxn*2],dis[maxn*2],size[maxn];
ll dep[maxn];
ll ans,sum,mi,se;
bool czy;
int i,j,k,l,r,t,n,m,tot,root;
void add(int x,int y,int z){
    go[++tot]=y;
    dis[tot]=z;
    nxt[tot]=h[x];
    h[x]=tot;
}
void dfs(int x,int y){
    int t=h[x];
    while (t){
        if (go[t]!=y){
            dfs(go[t],x);
            size[x]+=size[go[t]];
        }
        t=nxt[t];
    }
    size[x]++;
}
void dg(int x,int y){
    int t=h[x];
    while (t){
        if (go[t]!=y){
            dep[go[t]]=dep[x]+(ll)dis[t];
            dg(go[t],x);
        }
        t=nxt[t];
    }
}
int main(){
    scanf("%d",&n);
    fo(i,1,n-1){
        scanf("%d%d%d",&j,&k,&l);
        add(j,k,l);add(k,j,l);
    }
    dfs(1,0);
    root=1;t=0;
    while (1){
        r=h[root];
        while (r){
            if (go[r]!=t&&size[go[r]]==n/2&&n%2==0){
                czy=1;
                mi=dis[r];
            }
            if (go[r]!=t&&size[go[r]]>n/2){
                t=root;
                root=go[r];
                break;
            }
            r=nxt[r];
        }
        if (!r) break;
    }
    dg(root,0);
    fo(i,1,n) sum+=dep[i];
    if (!czy){
        mi=inf;
        fo(i,1,n)
            if (i!=root) mi=min(mi,dep[i]);
    }
    ans=sum*2;
    ans-=mi;
    printf("%lld\n",ans);
}

Measured memory_bytes: 8064