akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define double long double
#define fo(a,b) for(int a=0;a<b;a++)
#define Sort(a) sort(a.begin(),a.end())
#define rev(a) reverse(a.begin(),a.end())
#define fi first
#define se second
#define bgn begin()
#define sz size()
#define en end()
#define pb push_back
#define pp() pop_back()
#define V vector
#define P pair
#define yuko(a) setprecision(a)
#define uni(a) a.erase(unique(a.begin(),a.end()),a.end())
#define Q queue
#define pri priority_queue
#define Pri priority_queue<int,vector<int>,greater<int>>
#define PriP priority_queue<P<int,int>,vector<P<int,int>>,greater<P<int,int>>>
#define all(a)  (a).begin(),(a).end()
#define ff first.first
#define fs first.second
#define sf second.first
#define ss second.second

signed main(){
  string s;
  cin >> s;
  if(s == "keyence"){
    cout << "YES" << endl;
    return 0;
  }
    
  int n = s.size();
  for(int i = 0; i < n; i++){
    for(int j = i; j < n; j++){
      string t ="";
      for(int k = 0; k < n; k++){
        if(k >= i && k <= j)
          continue;
        t.push_back(s[k]);
      }
      if(t == "keyence"){
        cout << "YES" << endl;
        return 0; 
      }
    }
  }
  cout << "NO" << endl;
  return 0;
}

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

int main() {
  int N,M,i,j;
  cin >> N >> M;
  for(i=0;i<M+1;i++){
  cout << '#';
  }
  cout << '#' << endl; 
  vector<char> a(M*N);
  for(i=0;i<N;i++){
  cout << '#';
  for(j=0;j<M;j++){
  cin >> a.at(i);
  cout << a.at(i);
  }
  cout << '#' << endl;
  }
  for(i=0;i<M+2;i++){
  cout << '#';
  }
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int mod = 1000000007;

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


Measured memory_bytes: 512
#include <stdio.h>

int main(void){
  int L,R,min = 2018,l,r;
  scanf("%d %d",&L,&R);
  l = L%2019;
  r = R-L+l;
  if(R-L>=2019){printf("%d",0);return 0;}
  for(int i = l;i <= r;i++){
	  for(int j = i + 1;j <= r;j++){
        if(min > (i*j)%2019)min=(i*j)%2019;
	  }  
  }
  printf("%d",min);  
  return 0;
}

Measured memory_bytes: 128
#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
using namespace std;
#define rep(i,x) for(ll i = 0; i < (ll)(x); i++)
#define rrep(i,x) for(ll i = (ll)(x)-1;0 <= i; i--)
#define reps(i,x) for(ll i = 1; i < (ll)(x)+1; i++)
#define rreps(i,x) for(ll i = (ll)(x); 1 <= i; i--)
#define debug(x) cerr << #x << ": " << (x) << "\n";
#define all(x) (x).begin(), (x).end()
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<ll,ll> Pll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<vector<vector<ll>>> vvvl;
const ll INF = numeric_limits<ll>::max()/4;
const int n_max = 1e5+10;
const int q_max = 100;
#define int ll
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<T> &vec, ll k){
   ll n = vec.size();
   k = min(k, n);
   rep(i,k-1)cout << vec[i] << " ";
   cout << vec[k-1] << endl;
}

template <class T>
void print(vector<vector<T>> &df) {
    for (auto& vec : df) {
        print(vec);
    }
}

template<class T, class U>
void print(pair<T,U> &p){
    cout << p.first << " " << p.second << "\n";
}


template<class T>
bool chmax(T &a, T b){if(a < b){a = b; return true;} return false;}
template<class T>
bool chmin(T &a, T b){if(a > b){a = b; return true;} return false;}
struct state{
    state(){}
    ll a,b,c,d;
    bool operator>(state rhs){
        return d > rhs.d;
    };
    bool operator<(state rhs){
        return d < rhs.d;
    };
};
vector<state> v(q_max);
ll ans = 0;
ll n,m,q;
map<vector<ll>, ll> mp;
void dfs(vector<ll> &a){
    if(mp.find(a) != mp.end())return;
    // print(a);
    
    ll t = a.size();
    ll temp = 0;
    rep(i,q){
        if(a[v[i].b] - a[v[i].a] == v[i].c)temp += v[i].d;
    }
    chmax(ans, temp);
    mp[a] = temp;
    reps(i,t-2){
        if(a[i] + 1 <= m && a[i-1] <= a[i]+1 && a[i]+1 <= a[i+1]){
            a[i]++;
            dfs(a);
            a[i]--;
        }
    }
}
signed main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    
    cin >> n >> m >> q;

    rep(i,q){
        cin >> v[i].a >> v[i].b >> v[i].c >> v[i].d;
        // v[i].a--;v[i].b--;
    }

    vector<ll> a(n+2);
    a[0] = 0;
    reps(i,n)a[i] = 1;
    a[n+1] = m+1;
    dfs(a);
    cout << ans << endl;
}

Measured memory_bytes: 23848
#include<stdio.h>
int prime[1000000];
int count[1000000];


int main(){
	
	int n=0, i ,k;
	
	for(i =2 ; i <1000000; i++){
		prime[i] = 1;
		
	}
	for( i =2; i*i<1000000; i++){
		if(prime[i] == 1){
			for(k= 2*i ; k<1000000; k += i){
				prime[k] = 0;
			}
		}
	}
	
	for( i = 0; i< 1000000 ; i++){
		count[i+1] = count[i] + prime[i];
	}

	while(1){

		if(scanf("%d",&n) == EOF){
			break;
		}
		
		printf("%d\n",count[n+1]);
	}

	return 0;
}
	

Measured memory_bytes: 8408
import sys
input = sys.stdin.readline
from collections import *

def judge(x):
    d = defaultdict(int)
    
    for i in range(N-x+1):
        k = hash(S[i:i+x])
        
        if k in d:
            if i>=d[k]+x:
                return True
        else:
            d[k] = i
    
    return False

def binary_search():
    l, r = 0, N
    
    while l<=r:
        m = (l+r)//2
        
        if judge(m):
            l = m+1
        else:
            r = m-1
    
    return r

N = int(input())
S = input()[:-1]
print(binary_search())

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

using namespace std;

#define LL long long
#define pb push_back
#define pLL pair<LL,LL>
#define ff first
#define ss second
#define rep(i,a,b) for(LL i=a;i<=b;++i)
#define repb(i,a,b) for(LL i=a;i>=b;--i)
#define ld double
#define mp make_pair
#define vLL vector<LL>
#define vpLL vector<pLL>
#define vld vector<ld>
#define pld pair<ld,ld>
#define vpld vector<pld>
#define SLL set<LL>
#define SpLL set<pLL>
#define FIO ios::sync_with_stdio(false)

LL n;

int main()
{
	cin>>n;
	LL ans=0;
	rep(i,0,n){
		i++;
		if(i>n) break;
		LL cnt=0;
		rep(j,1,n) if(i%j==0) cnt++;
		if(cnt==8) ans++; 
	}	
	cout << ans << endl;
}

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

int main()
{
    int n, k, i, j;
    double ans;
    scanf("%d %d", &n, &k);

    for (i = 1; i <= n; i++)
    {
        for (j = 1; j <= 150000; j *= 2)
        {
            if (i * j >= k)
            {
                ans += 1.0 / j;
                break;
            }
        }
    }

    printf("%.12lf", ans / n);
}

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

int main(){
  long long n,a,log=0,ans=0,spareans=0;
  cin>>n;
  long long num[n];
  for(int i=0;i<n;i++){
    cin>>num[i];
    log+=num[i];
    if(i%2==0){
      if(log<=0){
        ans+=1-log;
        log=1;
      }
    }else{
      if(log>=0){
        ans+=log+1;
        log=-1;
      }
    }
  }log=0;
  for(int i=0;i<n;i++){
    log+=num[i];
    if(i%2==1){
      if(log<=0){
        spareans+=1-log;
        log=1;
      }
    }else{
      if(log>=0){
        spareans+=log+1;
        log=-1;
      }
    }
  }ans=min(ans,spareans);
  cout<<ans<<endl;
}

Measured memory_bytes: 1024
#include <algorithm>
#include <array>
#include <functional>
#include <iostream>
#include <numeric>
#include <string>
#include <unordered_set>
#include <vector>
#define REP(i, n) for (int i = 0; (i) < (int)(n); ++ (i))
#define ALL(x) begin(x), end(x)
using ll = long long;
using namespace std;
template <typename X, typename T> auto vectors(X x, T a) { return vector<T>(x, a); }
template <typename X, typename Y, typename Z, typename... Zs> auto vectors(X x, Y y, Z z, Zs... zs) { auto cont = vectors(y, z, zs...); return vector<decltype(cont)>(x, cont); }

template <int32_t MOD>
struct mint {
    int64_t value;
    mint() = default;
    mint(int64_t value_) : value(value_) {}
    inline mint<MOD> operator + (mint<MOD> other) const { int64_t c = this->value + other.value; return mint<MOD>(c >= MOD ? c - MOD : c); }
    inline mint<MOD> & operator += (mint<MOD> other) { this->value += other.value; if (this->value >= MOD) this->value -= MOD; return *this; }
};


constexpr int MOD = 998244353;

mint<MOD> solve1(string s) {
    unordered_set<string> used;
    function<void (void)> go = [&]() {
        if (used.count(s)) return;
        used.insert(s);
        REP (i, s.length() - 1) {
            if (s[i] != s[i + 1]) {
                char x = s[i];
                char y = s[i + 1];
                s[i] = s[i + 1] = 'a' ^ 'b' ^ 'c' ^ x ^ y;
                go();
                s[i] = x;
                s[i + 1] = y;
            }
        }
    };
    go();
    return used.size();
}

mint<MOD> solve2(int n, int m, bool is_all_different) {
    auto dp = vectors(n, array<array<mint<MOD>, 4>, 3>());
    dp[0][0][0] = 1;  // "a"
    dp[0][1][1] = 1;  // "b"
    dp[0][2][2] = 1;  // "c"
    REP (i, n - 1) {
        REP (j, 3) {
            REP (last_c, 4) {
                REP (c, 3) {
                    int next_c = (last_c == 3 or (last_c == c) ? 3 : c);
                    dp[i + 1][(j + c) % 3][next_c] += dp[i][j][last_c];
                }
            }
        }
    }
    return dp[n - 1][m][3] + is_all_different;
}

mint<MOD> solve(string const & s) {
    int n = s.length();
    if (n < 4) return solve1(s);

    bool is_all_same = (count(ALL(s), s.front()) == n);
    if (is_all_same) return 1;

    bool is_all_different = true;
    REP (i, n - 1) {
        if (s[i] == s[i + 1]) {
            is_all_different = false;
        }
    }

    int m = (accumulate(ALL(s), 0) - n * 'a') % 3;
    return solve2(n, m, is_all_different);
}

int main() {
    string s; cin >> s;
    cout << solve(s).value << endl;
    return 0;
}


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

typedef long long ll;
ll n, m, t, num1, num2, mx, e1, e2, e3, e4, t1[105], t2[105];
vector<ll> a[4], s[4];
int main()
{
	ll i,j, k, w;
	cin >> n >> m;
	for (i = 0; i < n; i++) {
		scanf ("%lld %lld", &t1[i], &t2[i]);
		a[t1[i] - t1[0]].push_back(t2[i]);
	}
	for (i = 0; i < 4; i++) sort(a[i].begin(), a[i].end());
	for (i = 0; i < 4; i++) {
		s[i].push_back(0);
		if (a[i].empty()) continue;
		s[i].push_back(a[i][0]);
		t = a[i][0];
		for (j = 1; j < a[i].size(); j++) {
			t += a[i][j];
			s[i].push_back(t);
		}
	}
//	for (i =0; i <4; i++) {
//		for (j = 0; j <a[i].size(); j++) {
//			printf("%d ",a[i][j]);
//		}
//		puts("");
//	}

//	e1 = a[0].size();e1 = max(e1, 1);
//	e2 = a[1].size();e2 = max(e2, 1);
//	e3 = a[2].size();e3 = max(e3, 1);
//	e4 = a[3].size();e4 = max(e4, 1);

//	e2 = max(a[1].size(), 1);
//	e3 = max(a[2].size(), 1);
//	e4 = max(a[3].size(), 1);
	for (i = 0; i <= a[0].size(); i++) {
		for (j = 0; j <=a[1].size(); j++) {
			for (k = 0; k <=a[2].size(); k++) {
				for (w = 0; w <=a[3].size(); w++) {
					num1 = num2 = 0;
					if (i > 0) {num1 += s[0][s[0].size() - 1] - s[0][i - 1]; num2 += (a[0].size() - i + 1) * t1[0];}
					if (j > 0) {num1 += s[1][s[1].size() - 1] - s[1][j - 1]; num2 += (a[1].size() - j + 1) * (t1[0] + 1);}
					if (k > 0) {num1 += s[2][s[2].size() - 1] - s[2][k - 1]; num2 += (a[2].size() - k + 1)  * (t1[0] + 2);}
					if (w > 0) {num1 += s[3][s[3].size() - 1] - s[3][w - 1]; num2 += (a[3].size() - w + 1) * (t1[0] + 3);}
					if (num2 <= m) mx = max(mx, num1);
				}
			}
		}
	}
	cout << mx;
    return 0;
}


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

using namespace std;
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define sz(x) ll(x.size())
typedef long long ll;
typedef pair<int, int> P;
const ll INF = 1001001001;

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

    vector<ll> a(n + 1);
    rep(i, n + 1) cin >> a[i];
    vector<ll> b(n);
    rep(i, n) cin >> b[i];

    ll sum = 0;
    for (int i = 0; i < n; i++) {
        ll left = min(a[i], b[i]);
        a[i] -= left;
        b[i] -= left;
        sum += left;

        ll right = min(a[i + 1], b[i]);
        a[i + 1] -= right;
        b[i] -= right;
        sum += right;
    }
    cout << sum << endl;

}


Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
int main(){
    int A, B, C, D, N, ans=0;
    vector<int> V(3);
    char tmp, tmp2;
    string S, S2, S3;
    bool flag=true;
    
    cin >> A>>B>>C>>D;
    
    ans = min(A, B) + min(C, D);
    cout << ans<< endl;

    // if(S[1]==S[2] &&(S[0]==S[1] | S[2]==S[3]))
    // 	cout << "Yes" <<endl;
    // else
    // 	cout << "No" <<endl;

    // string S;
    // cin >>S;
    // cout << S + "pp"<<endl;
    // if(A+B>=C)
    //    puts("Yes");
    // else
    // 	puts("No");
}



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

int main()
{
  int a,b,c,x; cin >>a>>b>>c>>x;
  
  int count = 0;
  for (int i = 0; i <= a;i++)
  {
   for(int j = 0; j <= b; j++)
   {
     for(int k = 0; k <= c; k++)
     {
       if (x == 500*i+100*j+50*k)
         count++;
     }
   }  
  }
  
  cout << count << endl;
}

Measured memory_bytes: 256
l,r=map(int,input().split())
r=min(r,l+2020)
  
ans=10**9
c=0
for i in range(l,r+1):
    for j in range(l,r+1):
        if i!=j:
            ans=min(ans,(i*j)%2019)
        c+=1
print(ans)
    

Measured memory_bytes: 41052
def printBlock(height,width):
    for h in range(height):
        for w in range(width):
            if h%2==0:
                if w%2==0:
                    print('#',end='')
                else:
                    print('.',end='')
            else:
                if w%2==0:
                    print('.',end='')
                else:
                    print('#',end='')
        print('')
    print('')
while True:
    x,y = map(int,input().split())
    if x ==0 and y==0:
        break;
    else:
        printBlock(x,y)



Measured memory_bytes: 7012
#include<stdio.h>
#include<math.h>

int main(){
    double x1,x2,y1,y2;
    scanf("%lf %lf %lf %lf",&x1,&y1,&x2,&y2);
    printf("%.8lf\n",sqrt((x2-x1)*(x2-x1)+(y2-y1)*(y2-y1)));
}



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

typedef long long ll;

const int Maxn = 1005;

int n, m;
ll X[Maxn][3];
ll res;

int main()
{
	scanf("%d %d", &n, &m);
	for (int i = 0; i < n; i++)
		for (int j = 0; j < 3; j++)
			scanf("%lld", &X[i][j]);
	for (int i = 0; i < 1 << 3; i++) {
		vector <ll> best;
		for (int j = 0; j < n; j++) {
			ll cand = 0;
			for (int k = 0; k < 3; k++)
				if (bool(i & 1 << k) == (X[j][k] >= 0))
					cand += abs(X[j][k]);
				else cand -= abs(X[j][k]);
			best.push_back(cand);
		}
		sort(best.rbegin(), best.rend());
		ll cand = 0;
		for (int j = 0; j < m; j++)
			cand += best[j];
		res = max(res, cand);
	}
	printf("%lld\n", res);
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<cmath>
#include<map>
#include<cstdio>
#include<stack>
#include<queue>
#include<fstream>
#include<cstring>
#include<deque>
#include<iomanip>
#include <numeric>
//#include<bits/stdc++.h>

using namespace std;
#define ok1 printf("ok1\n");
#define ok2 printf("ok2\n");
#define M 1000000000000000000LL
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,s,n) for(int i=(s);i<(n);i++)
#define repr(i,n) for(int i=n-1;i>=0;i--)
#define REPR(i,s,n) for(int i=(s);i>=(n);(i)--)
#define all(a) (a).begin(),(a).end()
#define reall(a) (a).rbegin(),(a).rend()
#define pb push_back
#define pf push_front
#define MIN(a,b) a=min((a),(b))
#define MAX(a,b) a=max((a),(b))
#define SIZE(v) (int)v.size()
#define Eunique(v) v.erase(unique(all(v)),v.end());
#define pvec(v) rep(i,v.size()){ cout << v[i] << " ";}
#define INF 0x3f3f3f3f
#define mset(m,v) memset(m,v,sizeof(m))

const double pi = acos(-1.0);

typedef vector<int> vi;
typedef vector<string> vs;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef deque<ll> dll;
typedef pair<ll, ll> P;
#define mod 1e9 + 7;
ll dx[4] = { 1,0,-1,0 }, dy[4] = { 0,1,0,-1 };

ll gcd(ll x, ll y)
{
	ll r;
	while ((r = x % y) != 0)
	{
		x = y;
		y = r;
	}
	return y;
}
ll lcm(ll x, ll y)
{
	x /= gcd(x, y);
	y /= gcd(x, y);
	return (x * y);
}


struct UnionFind {
	vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2

	UnionFind(int N) : par(N) { //最初は全てが根であるとして初期化
		for (int i = 0; i < N; i++) par[i] = i;
	}

	int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
		if (par[x] == x) return x;
		return par[x] = root(par[x]);
	}

	void unite(int x, int y) { // xとyの木を併合
		int rx = root(x); //xの根をrx
		int ry = root(y); //yの根をry
		if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
		par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
	}

	bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
		int rx = root(x);
		int ry = root(y);
		return rx == ry;
	}
};


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

	ll n, w, h;;
	cin >> n >> h >> w;
	cout << (n - w + 1)*(n - h + 1) << endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int n,m;
long long ans;

int main(){
	cin>>n>>m;
	if(n>m) swap(n,m);
	if(n==1&&m==1){puts("1") ;return 0;}
 	if(n==1){ cout<<m-2<<endl;}
	else cout<<1ll*(n-2)*(m-2)<<endl;
}

Measured memory_bytes: 256
// https://atcoder.jp/contests/abc150/tasks/abc150_c
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define REP(i, n) FOR(i, 0, n)
#define REPR(i, n) for (int i = n - 1; i >= 0; i--)
#define FOR(i, s, n) for (int i = (s), i##_len = (n); i < i##_len; ++i)
#define ALL(obj) (obj).begin(), (obj).end()
#define ALLR(obj) (obj).rbegin(), (obj).rend()
#define DIV(a, b) ((a - 1) / b + 1)

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int N;
    cin >> N;
    vector<int> P(N), Q(N), A(N);
    for (auto &x : P) {
        cin >> x;
    }
    for (auto &x : Q) {
        cin >> x;
    }
    iota(ALL(A), 1);
    int cnt = 0, cntP = 0, cntQ = 0;
    do {
        bool flagP = true, flagQ = true;
        REP(i, N) {
            if (A[i] != P[i]) {
                flagP = false;
            }
            if (A[i] != Q[i]) {
                flagQ = false;
            }
        }
        if (flagP) {
            cntP = cnt;
        }
        if (flagQ) {
            cntQ = cnt;
        }
        cnt++;

    } while (next_permutation(ALL(A)));
    cout << abs(cntP - cntQ) << endl;

    return 0;
}


Measured memory_bytes: 3644
#include <iostream>
#include <vector>
#include <string>
#include <utility>
#include <algorithm>
#include <cmath>
#include <queue>
#include <set>
#include <map>
#include <cassert>
#include <fstream>
#include <iomanip>

using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;

const ll mod = 1e9 + 7;

vector<string> g;

int main() {
    
    
    cin.tie(0);
    ios_base::sync_with_stdio(0);
    
    ll n, m;
    cin >> n >> m;
    
    if (n % 2)
    {
        for (int i = 1; i <= m; ++i)
        {
            cout << i << " " << n + 1 - i << endl;
        }
    }
    else
    {
        for (int i = 1; i <= (m + 1) / 2; ++i)
        {
            cout << i << " " << n + 1 - i << endl;
        }
        for (int i = (m + 1) / 2 + 1; i <= m; ++i)
        {
            cout << i + 1 << " " << n + 1 - i << endl;
        }
        
    }
    

    return 0;
}

Measured memory_bytes: 3660
#include <stdio.h>
#include <string.h>

int main(void) {
	//N問　M回回答
	int N, M;
	scanf("%d %d", &N, &M);
	//回答状況
	bool A[100000];
	int Wa[100000];
	memset(Wa, 0, sizeof Wa);
	int P;
	char S[3];
	int ans = 0;
	int pena= 0;
	memset(A,false, sizeof A);
	for (int x = 0; x < M;x++) {
		scanf("%d %s", &P, S);
		//正解なら
		if (S[0] == 'A') {
			if (A[P] == false) {
				A[P] = true;
				pena += Wa[P];
				ans++;
			}

		}else{
			Wa[P]++;
		}
	}
	printf("%d %d",ans,pena);
	
}

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

int main() {
	// your code goes here
	int a,b,c;
	cin>>a>>b>>c;
	if(a<=b && b<=c && a<=c){
		cout<<a<<" "<<b<<" "<<c<<endl;
	}
	else if(a<=b && b>=c && a<=c){
		cout<<a<<" "<<c<<" "<<b<<endl;
	}
	else if(a>=b && b<=c && a<=c){
		cout<<b<<" "<<a<<" "<<c<<endl;
	}
	else if(a>=b && b<=c && a>=c){
		cout<<b<<" "<<c<<" "<<a<<endl;
	}
	else if(a>=b && b>=c && a>=c){
		cout<<c<<" "<<b<<" "<<a<<endl;
	}
	else if(a<=b && b>=c && a>=c){
		cout<<c<<" "<<a<<" "<<b<<endl;
	}
	return 0;
}

Measured memory_bytes: 3080
#include <iostream>
using namespace std;
int main(void){
    int N,A,B;
    
    cin >> N ;
    cin >> A;
    cin >> B;
    if(N==1)
    {
        cout << "Hello World" << endl;
    }
    else
    {
        cout << A+B <<endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include<cstdio>
int n,k,l[15],r[15];
long long f[200005],mod=998244353,sm[200005];
long long query(int l,int r)
{
	if(r<0)
		return 0;
	if(l<=0)
		return sm[r];
	return ((sm[r]-sm[l-1])%mod+mod)%mod;
}
int main()
{
	scanf("%d%d",&n,&k);
	for(int i=1;i<=k;++i)
		scanf("%d%d",&l[i],&r[i]);
	f[0]=sm[0]=1;
	--n;
	for(int i=1;i<=n;++i)
	{
		for(int j=1;j<=k;++j)
			f[i]+=query(i-r[j],i-l[j]),f[i]%=mod;
		sm[i]=(sm[i-1]+f[i])%mod;
	}
	printf("%d",f[n]);
}

Measured memory_bytes: 4860
#include <bits/stdc++.h>
    using namespace std;
    #define ll long long int
    #define pb push_back
    #define mk make_pair
    #define ft first
    #define sc second
    #define ppb pop_back
    #define sz size
    #define forn(i,a,n) for(i=a;i<n;i++)
    #define M 1000000007
    #define inf 2e18
    
    int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    
    ll n;
    cin>>n;
    vector<ll> v(n);
    for(ll i=0;i<n;i++)cin>>v[i];
    ll ans=0;
    for(ll i=0;i<60;i++){
      ll c=0;
      for(ll j=0; j<n;j++){
        c+=((v[j])&1ll); v[j]/=2;
      }
      c = (c*(n-c))%M;
      for(ll k=0;k<i; k++){
        c*=2; c%=M;
      }
      ans+=c; 
      ans%=M;
    }
    cout<<ans<<"\n";
    return 0;
    }   

Measured memory_bytes: 2560
#include <cstdio>
#include <iostream>
#include <cassert>
#include <algorithm>    
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <cstring>
#include <cmath>
#include <bitset>
#define mk make_pair
#define eb emplace_back
#define eps 1e-8
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
// #define int long long
using namespace std;

typedef long double ld;
typedef unsigned int ui;
typedef pair<int,int> pii;
typedef unsigned long long ull; 
typedef vector<int> vii;
typedef vector<long double> vd;
const int inf = 1e9;
const int M = 1e9 + 7;
//__int128


signed main()
{
  ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
  int n;
  cin >> n;
  std::vector<pii> v(n);
  for(int i = 0; i < n; ++i) {
  	int x;
  	cin >> x;
  	v[i] = pii(x, i + 1);
  }
  sort(all(v));
  for(int i = 0; i < n; ++i) {
  	cout << v[i].se << ' ';
  }

	return 0;
}

Measured memory_bytes: 1664
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
int main()
{
	int h,t,a,sum;
	cin >>h >>t;
	for (int i=0;i<t;i++)
	{
		cin >>a;
		sum+=a;
	}
	if (sum>=h)
		cout <<"Yes"<<endl;
	else 
		cout <<"No"<<endl;
	return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <climits>
#include <map>
#include <cmath>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <iterator>
#include <deque>
#include <bitset>
#include <list>
#include <queue>
#include <set>
#include <stack>
#include <functional>
#include <iterator>
#include <locale>
#include <memory>
#include <stdexcept>
#include <utility>
#include <fstream>
#include <ios>
#include <iosfwd>
#include <iomanip>
#include <istream>
#include <sstream>
#include <streambuf>
#include <complex>
#include <numeric>
#include <valarray>
#include <exception>
#include <limits>
#include <new>
#include <typeinfo>
#include <bitset>
#include <queue>
#define speed ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)

using namespace std;

int main() {
	int sumka=0;
	string a;
	cin >> a;
	for (int i = 0; i < a.size(); i++) {
		sumka += a[i]-'0';
	}
	if (sumka % 9 == 0)
		cout << "Yes";
	else
		cout << "No";
}

Measured memory_bytes: 3360
// Template
#include <iostream>
#include <string>
#include <vector>
#include <utility>
#include <functional>
#include <numeric>
#include <list>
#include <set>
#include <map>
#include <algorithm>
#include <cmath>

using namespace std;
typedef long long ll;

#define REP(i, n) for(int i = 0;i < n;i++)
#define INF 1 << 10


int main(){
    int n;
    cin >> n;
    vector<ll> a(n);
    ll max_a = 0LL;
    ll mid_a = 0LL;
    REP(i,n){
        cin>>a[i];
        max_a = max(max_a, a[i]);
    }

    REP(i,n){
        if(abs(max_a/2-a[i]) < abs(max_a/2-mid_a) && a[i]!=max_a){
            mid_a = a[i];
        }
    }

    cout << max_a << " " << mid_a << endl;



    return 0;

}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rep2(i, m, n) for(int i = (int)(m); i < (int)(n); i++)
#define rep_inv(i, n, m) for(int i = (int)(n); i > (int)(m); i--)
using namespace std;
using ll = long long;
using vl = vector<ll>;
using vc = vector<char>;
using vvl = vector<vl>;
using vvc = vector<vc>;
using pll = pair<ll, ll>;
using vpll = vector<pll>;

int main(){
  ll N, T;
  cin >> N >> T;
  vl t(N);
  rep(i, N) cin >> t[i];

  ll X = 0;

  rep2(i, 1, N)
    X += (t[i] - t[i - 1] >= T) ? T : (t[i] - t[i - 1]);
  
  X += T;

  cout << X << endl;
  
  return 0;
}


Measured memory_bytes: 1792
#include<stdio.h>
#include<stdlib.h>
#define N 8
#define FREE 1
#define NAH 0
//init
int num, row[N], col[N], dpos[N*2 -1], dneg[N*2-1], input[2], init[N][N];
void print()
{
        for(int k=0; k<N; k++)
        {
            for(int l=0; l<N; l++)
            {
                if(init[k][l] == 1 && row[k] != l) return;
            }
        }
        for(int k=0; k<N; k++)
        {
            for(int l=0; l<N; l++)
            {
                if(row[k] == l) printf("Q");
                else printf(".");
            }
        printf("\n");
        }
}
void whereIsQueen(int i)
{
    if (i == N)
    {
        print();
        return;
    }
    for (int j = 0; j<=N-1; j++)
    {
        if (col[j] == NAH || dpos[i+j] == NAH || dneg[i-j+N-1] == NAH)
        {
            continue;
        }
        row[i] = j;
        col[j] = NAH;
        dpos[i+j] = NAH;
        dneg[i-j+N-1] = NAH;
        whereIsQueen(i+1);
        col[j] = FREE;
        dpos[i+j] = FREE;
        dneg[i-j+N-1] = FREE;
    }
}

int main()
{
    //init2
    for(int i=0; i<N; i++)
{
    row[i] = FREE;
    col[i] = FREE;
}
for(int i=0; i<N*2-1; i++)
{
    dpos[i] = FREE;
    dneg[i] = FREE;
}
for(int k=0; k<N; k++)
{
    for(int l=0; l<N; l++)
    {
        init[k][l] = 0;
    }
}
    //input
    scanf("%d", &num);
    for(int i=0; i<num; i++)
    {
        scanf("%d%d", &input[0], &input[1]);
        init[input[0]][input[1]] = 1;
    }
    whereIsQueen(0);
    return 0;
}


Measured memory_bytes: 2112
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vl = vector<ll>;
using vll = vector<vl>;
using Pll = pair<ll, ll>;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(v) v.begin(), v.end()
#define sz(x) ((int) x.size())
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define F first
#define S second
const int MOD = 1e9+7;
const ll INF = 2e15;
template<class T> void print(const T& t){ cout << t << endl; }
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; }
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}

int main(){
  ll n, m;
  cin >> n >> m;
  vector<bool> red(n, false);
  vl ball(n, 1);
  red[0] = true;
  rep(i, m){
    ll x, y;
    cin >> x >> y;
    x--;
    y--;
    ball[x]--;
    ball[y]++;
    if (red[x]){
      red[y] = true;
      if(ball[x]==0){
        red[x] = false;
      }
    }
  }
  ll count = 0;
  for (bool r : red){
    if(r){
      count++;
    }
  }
  print(count);
}

Measured memory_bytes: 4048
#include <bits/stdc++.h>
#include<queue>
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
typedef pair<ll,ll> Pll;
typedef pair<double,double> Pdouble;

const int INF = 2000000000;
const int MOD = 1000000007;

const int MAX_N = 2010;
const int MAX_M = 2010;
ll d[MAX_N][MAX_M + 1];

int main() {
  ll n,m;
  cin >> n >> m;

  vector<ll> a(n);

  for(int i=0; i<n; i++){
    cin >> a[i];
  }

  ll count = 0;
  ll sum =0;

  for(int i=0; i<n; i++){
    sum += a[i];
  }

  double cd = sum/(double)(4*m);
  for(int i=0; i<n; i++){
    if(a[i]>=cd){
      count++;
    }
  }

  if(count>=m){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
}

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

int main(){
    int n;
    while(cin >> n, n){
        int mi = 500, ma = 0;
        for(int i = 0; i < n; i++){
            int sum = 0, a;
            for(int j = 0; j < 5; j++){
                cin >> a;
                sum += a;
            }
            mi = min(mi, sum);
            ma = max(ma, sum);
        }
        cout << ma << " " << mi << endl;
    }
    return 0;
}


Measured memory_bytes: 2976
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define P pair<ll,ll>
#define FOR(I,A,B) for(ll I = ll(A); I < ll(B); ++I)
#define FORR(I,A,B) for(ll I = ll((B)-1); I >= ll(A); --I)
#define TO(x,t,f) ((x)?(t):(f))
#define SORT(x) (sort(x.begin(),x.end())) // 0 2 2 3 4 5 8 9
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin()) //xi>=v  x is sorted
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin()) //xi>v  x is sorted
#define NUM(x,v) (POSU(x,v)-POSL(x,v))  //x is sorted
#define REV(x) (reverse(x.begin(),x.end())) //reverse
ll gcd(ll a,ll b){if(a%b==0)return b;return gcd(b,a%b);}
ll lcm(ll a,ll b){ll c=gcd(a,b);return ((a/c)*(b/c)*c);}
#define NEXTP(x) next_permutation(x.begin(),x.end())
const ll INF=ll(1e18)+ll(7);
const ll MOD=1000000007LL;
#define out(a) cout<<fixed<<setprecision((a))

class vec{
public:
	int x,y;
	vec(int x_=0,int y_=0):x(x_),y(y_){}
	void make(int x_,int y_){
		x = x_; y = y_;
	}
	vec operator + (vec A){
		vec ans(this->x+A.x,this->y+A.y);
		return ans;
	}
	vec operator - (vec A){
		vec ans(this->x-A.x,this->y-A.y);
		return ans;
	}
	int operator * (vec A){
		return this->x*A.x+this->y*A.y;
	}
	bool operator == (vec A){
		return (this->x==A.x && this->y==A.y);
	}
	double r(){
		return sqrt((double)x*x+(double)y*y);
	}
	double sita(){
		double ans = atan2(y,x);
		return (ans<0.000?ans+2.0*M_PI:ans);
	}
};
double sin_sita(vec v1,vec v2){ // v2 basis
	return double(v2.x*v1.y-v2.y*v1.x)/v1.r()/v2.r();
}
double cos_sita(vec v1,vec v2){ // v2 basis
	return double(v2.x*v1.x+v2.y*v1.y)/v1.r()/v2.r();
}


int main(){
	int q,x0,y0,x1,y1,x2,y2,x3,y3;
	cin >> q;
	double EPS = 1e-13;
	FOR(i,0,q){
		cin >> x0 >> y0 >> x1 >> y1 >> x2 >> y2 >> x3 >> y3;
		vec v1(x1-x0,y1-y0);
		vec v2(x3-x2,y3-y2);
		double sc = sin_sita(v1,v2);
		double cc = cos_sita(v1,v2);
		if(sc>=1.0-EPS || sc<=-1.0+EPS){
			cout << 1 << endl;
		}else if(cc>=1.0-EPS || cc<=-1.0+EPS){
			cout << 2 << endl;
		}else{
			cout << 0 << endl;
		}
	}

}


Measured memory_bytes: 3088
#include <bits/stdc++.h>
#define forn(i, n) for(int i = 0; i < (int)(n); i++)
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef unsigned int ui32;
const long long INFLL = 1e18;
using namespace std;

const int MAXN = 100000;
int a[MAXN + 1], b[MAXN + 1], c[MAXN + 1];

int main() {
    //ios_base::sync_with_stdio(false);
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);

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

    sort(a, a + n);
    sort(b, b + n);
    sort(c, c + n);

    ll ans = 0;
    for (int i = 0; i < n; i++) {
        int pos1 = lower_bound(a, a + n, b[i]) - a;
        int pos2 = upper_bound(c, c + n, b[i]) - c;

        ans += (ll)pos1 * (n - pos2);
    }

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

Measured memory_bytes: 1408
#include <iostream>

using namespace std;

int main() {
  int d;
  while(cin >> d) {
    int ans = 0;
    
    for(int i = 600 - d; i > 0; i -= d)
      ans += i * i * d;
    cout << ans << endl;
  }
  
  return 0;
}

Measured memory_bytes: 1156
#include <cstdio>
#include <array>
#include <algorithm>

int main()
{
    std::array<int, 100> d;
    int n;

    scanf("%d", &n);
    for(int i = 0; i < n; ++i)
    {
        scanf("%d", &d[i]);
    }

    int diff = 0;
    for(int i = 0; i < n; ++i)
    {
        for(int j = 0; j < n; ++j)
        {
            if(i-j)
            {
                diff = std::max(diff, std::abs(d[i]-d[j]));
            }
        }
    }
    printf("%d\n", diff);
    return 0;
}

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

//region Template
#include "ext/pb_ds/assoc_container.hpp"

using namespace __gnu_pbds;
using namespace std;

typedef long long ll;
typedef long double ld;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;

const int MOD = 1000000007;
using namespace std;
#define finish(x) cout << x; exit(0);
#define fastIO cin.tie(0); cin.sync_with_stdio(false);
#define endl '\n'

void setIn(string s) { freopen(s.c_str(), "r", stdin); }
void setOut(string s) { freopen(s.c_str(),"w",stdout); }

//const string USCAO_TAG = "mountains";
void usaco(const string& USACO_TAG) { setIn(USACO_TAG + ".in"); setOut(USACO_TAG + ".out"); }
void print() {}
template<typename T, typename... Args>
void print(T firstArg, Args... args) {
	#ifdef LOCAL
	cout << firstArg << " ";
	print(args...);
	#endif
}
//endregion

/* Notes:
 * Farah </3
 */

int mx = 0;
const int MAXN = 1e6 + 5;
vector<vector<int>> adj;
bool v[MAXN];
int ans[MAXN];
vector<pair<int, int>> e;

map<pair<int, int>, int> col;

void dfs(int n, int p){
	if(v[n]) return;
	v[n] = 1;

	int c = 1;
	for(auto x : adj[n]){
		if(v[x]) continue;
		if(p == c) c++;
		col[{n, x}] = c;
		col[{x, n}] = c;
		dfs(x, c);
		c++;
	}
}

int main() {
	//usaco("milkvisits");

	#ifdef LOCAL
	setIn("in.txt");
	setOut("out.txt");
	#endif

	int n;
	cin >> n;
	adj.assign(n + 2, vector<int>());

	for(int i = 0; i < n - 1; i++){
		int u, v;
		cin >> u >> v;

		e.push_back({u, v});
		adj[u].push_back(v);
		adj[v].push_back(u);
	}

	for(int i = 1; i <= n; i++){
		mx = max(mx, (int)adj[i].size());
	}

	dfs(1, 0);
	cout << mx << endl;
	for(auto x : e){
		cout << col[x] << endl;
	}
}

Measured memory_bytes: 21496
#include <bits/stdc++.h>
#define IO_OP std::ios::sync_with_stdio(0); std::cin.tie(0);
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define EB emplace_back

using namespace std;

typedef long long ll;
typedef pair<int, int> pi;
typedef vector<int> vi;

const int INF = 1e9 + 7;

int a[100005];

int main()
{
	IO_OP;
	
	int n;
	cin >> n;
	for(int i=1;i<=n;i++)
		cin >> a[i];
	for(int i=1;i<=n;i++) {
		if(a[i] > a[i-1])
			a[i]--;
	}
	for(int i=1;i<=n;i++) {
		if(a[i] < a[i-1]) {
			cout << "No" << endl;
			return 0;
		}
	}
	cout << "Yes" << endl;
}



Measured memory_bytes: 640
#!/usr/bin/env python3
import sys

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines


def main():
    N = int(readline())
    S, T = readline().split()
    S = S.decode()
    T = T.decode()
    ans = []
    for i in range(N):
        ans += [S[i]] + [T[i]]
    ans = ''.join(ans)
    print(ans)


if __name__ == '__main__':
    main()


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

typedef long long ll;
typedef long double ld;
const ll mod = 1e9 + 7;
#define eps 1e-9
using namespace std;

int cnt(ll x) {
    int ctr = 0;
    while (x) {
        ctr++;
        x /= 10;
    }
    return ctr;
}

int main() {
    ll n;
    cin >> n;
    int mx = 1e9;
    for (int i = 1; i <= sqrt(n); i++) {
        if (n % i == 0) {
            int curr = max(cnt(i), cnt(n / i));
            mx = min(mx, curr);
        }
    }
    cout << mx;
    return 0;
}



Measured memory_bytes: 256
#include<stdio.h>
#define MAX 100001
int Partition(int,int);
int A[MAX];
main(){
  int x,i,n;
  scanf("%d",&n);
  for(i = 0 ; i < n ; i++){
    scanf("%d",&A[i]);
  }
  x = Partition(0,n-1);
  for(i = 0  ; i < n ;i++){
    if(i==x) printf("[%d]",A[i]);
    else printf("%d",A[i]);   
    if(i==n-1) printf("\n");
    else printf(" ");
}
  return 0;
}

int Partition(int p,int r){
  int a,R=0,L=0,i,j;
  a=A[r];
  i=p-1;
  for(j = p ; j <= r-1 ; j++){
    if(A[j] <= a){ 
      i = i+1;
      R = A[i];
      A[i] = A[j];
      A[j] = R;
    }
  }
    L = A[i+1];
    A[i+1] = A[r];
    A[r] = L;
    return i+1;
}

Measured memory_bytes: 992
#include <bits/stdc++.h>
#define ll long long
#define ulli unsigned long long int
#define ld long double  
#define endl "\n"
using namespace std; 


void solve() {
    int x;
    cin >> x;

    vector<int> primes {2};

    for (int i = 3; primes[primes.size() - 1] < x; i += 2) {
        bool is_prime = true;
        for (auto x: primes) {
            if (i % x == 0) {
                is_prime = false;
                break;
            }
        }

        if (is_prime) {
            primes.push_back(i);
        }
    }

    cout << primes[primes.size() - 1] << endl;
}

int main() 
{ 
    ios_base::sync_with_stdio(false); 
    cin.tie(NULL); 
  
    int t = 1; 
    //cin >> t; 
    while (t--) { 
        solve(); 
    } 
  
    cerr << "time taken : " << (float)clock() / CLOCKS_PER_SEC << " secs" << endl; 
    return 0; 
} 


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

struct UnionFind {
    vector<int> data;
    int sz;
    UnionFind(int sz) : data(sz, -1), sz(sz) { }
    bool unionSet(int x, int y) {
        if ((x = root(x)) == (y = root(y))) return false;
        if (data[x] > data[y]) swap(x, y);
        data[x] += data[y]; data[y] = x; sz--;
        return true;
    }
    bool findSet(int x, int y) { return root(x) == root(y); }
    int root(int x) { return data[x] < 0 ? x : data[x] = root(data[x]); }
    int size(int x) { return -data[root(x)]; }
    int size() { return sz; }
};

int main() {
    int N, M; cin >> N >> M;
    vector<pair<int, int>> query;
    for (int i = 0; i < M; i++) {
        int a, b; cin >> a >> b; a--, b--;
        query.emplace_back(a, b);
    }
    reverse(query.begin(), query.end());
    UnionFind uf(N);
    vector<long long> ans;
    long long cur = 1LL * N * (N - 1) / 2;
    for (auto &p: query) {
        ans.push_back(cur);

        int a = p.first, b = p.second;
        if (uf.findSet(a, b)) continue;
        cur -= 1LL * uf.size(a) * uf.size(b);
        uf.unionSet(a, b);
    }
    reverse(ans.begin(), ans.end());
    for (auto x: ans) cout << x << endl;
    return 0;
}

Measured memory_bytes: 3444
import math
def gooddistance(l1, l2):
    calc = []
    for i in range(len(l1)):
        calc.append((l1[i] - l2[i])**2)

    if math.sqrt(sum(calc)).is_integer():
        return 1
    else:
        return 0

N, D = map(int, input().split())
lis = [list(map(int, input().split())) for _ in range(N)]
cnt = 0

for i in range(N):
    for j in range(i+1,N):
       cnt += gooddistance(lis[i],lis[j])

print(cnt)

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

ll f(ll a)
{
  string s = to_string(a);
  char t = s[0];
  char u = s.back();
  s[0] = u;
  s[(int)(s.size())-1] = t;
  return stoll(s);
}

int main()
{
  ll N;
  cin >> N;

  vector<vector<ll>> d(10, vector<ll>(10, 0));

  for (int i=1; i<=N; i++) {
    string s = to_string(i);
    d[s[0]-'0'][s.back()-'0']++;
  }

  ll ans = 0;
  for (int i=0; i<=9; i++) {
    for (int j=0; j<=9; j++) {
      ans += d[i][j] * d[j][i];
    }
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 384
#include<iostream>
#include<vector>
using namespace std;
int main() {
	int n;
	vector<int>l;
	while (cin >> n){
		if (n == 0)break;
		bool b = false;
		int sum = n;
		for (int i = 0; i < n; i++){
			int a;
			cin >> a;
			if (a >= 2)b = true;
			if (a == 0)sum--;
		}
		if (b)l.push_back(sum + 1);
		else l.push_back(0);
	}
	for (int i : l) {
		if (i == 0)cout << "NA" << endl;
		else cout << i << endl;
	}
	char c; cin >> c;
	return 0;
}

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

#define rep(i, n) for(int i = 0; i<(n); i++)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
typedef long long ll;

const int MOD = 1000000007;
const ll INF = 1LL << 60;

int main() {
    int N;
    cin >> N;
    vector<ll> h(N + 10);
    rep(i, N) cin >> h[i];

    vector<ll> dp(N + 10, INF);
    dp[0] = 0;
    rep(i, N) {
        chmin(dp[i + 1], dp[i] + abs(h[i + 1] - h[i]));
        chmin(dp[i + 2], dp[i] + abs(h[i + 2] - h[i]));
    }
    cout << dp[N - 1] << endl;
}


Measured memory_bytes: 1792
#include<bits/stdc++.h>
constexpr long long INFL = 1LL << 60;
constexpr int INF = 1e9;

using namespace std;

int main()
{
    int a[3];
    cin >> a[0] >> a[1] >> a[2];
    sort(a, a+3);

    int dif1 = a[2] - a[1];
    int dif2 = a[2] - a[0];
    if(dif1 % 2 == dif2 % 2)
        cout << (dif1 + dif2) / 2 << endl;
    else
        cout << (dif1 + dif2) / 2 + 2 << endl;

    return 0;
}


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

#define dump(x) cout << (x) << '\n'
#define Int int64_t
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
 
Int INF = 1e18;
int inf = 1e9;
Int mod = 1e9+7;

int main() {
    Int n, m;
    cin >> n >> m;
    Int a = max((Int)0, n * (n - 1) / 2);
    Int b = max((Int)0, m * (m - 1) / 2);
    dump(a + b);
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main{

  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int a1,a2,a3;
    a1 = sc.nextInt();
    a2 = sc.nextInt();
    a3 = sc.nextInt();
    if(a1+a2+a3 > 21) {
      System.out.println("bust");
    }else {
      System.out.println("win"); //System.err.println("win");から修正
    }
    sc.close();
  }
}


Measured memory_bytes: 35980
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < n; ++i)
#pragma region Debug
template <typename T>
void view(const std::vector<T> &v)
{
    for (const auto &e : v)
    {
        std::cout << e << " ";
    }
    std::cout << std::endl;
}
template <typename T>
void view(const std::vector<std::vector<T>> &vv)
{
    for (const auto &v : vv)
    {
        view(v);
    }
}
#pragma endregion
template <typename T>
inline bool chmin(T &a, T b)
{
    if (a > b)
    {
        a = b;
        return true;
    }
    return false;
}
template <typename T>
inline bool chmax(T &a, T b)
{
    if (a < b)
    {
        a = b;
        return true;
    }
    return false;
}

#define INF 10e9 + 7

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

    vector<vector<ll>> t(n, vector<ll>(2));
    int max_v = 0;
    rep(i, n){
        cin >> t[i][0] >> t[i][1];
        max_v += t[i][1];
    }

    vector<vector<ll>> dp(n+1, vector<ll>(max_v+1, INF));

    dp[0][0] = 0;

    rep(i, n){
        ll m = t[i][0];
        ll v = t[i][1];
        for(int j=0; j <= max_v; j++){

            if(j-v >= 0) chmin(dp[i + 1][j], dp[i][j-v] + m);

            chmin(dp[i+1][j], dp[i][j]);

        }
    }

    int ans = 0;
    for(int i=0; i <= max_v; i++){
        if(dp[n][i] <= w) ans = i;
    }

    cout <<  ans << endl;

    return 0;
}


Measured memory_bytes: 80256
H,W,K=map(int, input().split())

MOD = 10**9+7
class Mint:
    def __init__(self, value=0):
        self.value = value % MOD
        if self.value < 0: self.value += MOD

    @staticmethod
    def get_value(x): return x.value if isinstance(x, Mint) else x

    def inverse(self):
        a, b = self.value, MOD
        u, v = 1, 0
        while b:
            t = a // b
            b, a = a - t * b, b
            v, u = u - t * v, v
        if u < 0: u += MOD
        return u

    def __repr__(self): return str(self.value)
    def __eq__(self, other): return self.value == other.value
    def __neg__(self): return Mint(-self.value)
    def __hash__(self): return hash(self.value)
    def __bool__(self): return self.value != 0

    def __iadd__(self, other):
        self.value = (self.value + Mint.get_value(other)) % MOD
        return self
    def __add__(self, other):
        new_obj = Mint(self.value)
        new_obj += other
        return new_obj
    __radd__ = __add__

    def __isub__(self, other):
        self.value = (self.value - Mint.get_value(other)) % MOD
        if self.value < 0: self.value += MOD
        return self
    def __sub__(self, other):
        new_obj = Mint(self.value)
        new_obj -= other
        return new_obj
    def __rsub__(self, other):
        new_obj = Mint(Mint.get_value(other))
        new_obj -= self
        return new_obj

    def __imul__(self, other):
        self.value = self.value * Mint.get_value(other) % MOD
        return self
    def __mul__(self, other):
        new_obj = Mint(self.value)
        new_obj *= other
        return new_obj
    __rmul__ = __mul__

    def __ifloordiv__(self, other):
        other = other if isinstance(other, Mint) else Mint(other)
        self *= other.inverse()
        return self
    def __floordiv__(self, other):
        new_obj = Mint(self.value)
        new_obj //= other
        return new_obj
    def __rfloordiv__(self, other):
        new_obj = Mint(Mint.get_value(other))
        new_obj //= self
        return new_obj

def comb(n, r):
    p, q = 1, 1
    for i in range(r):
        p = p * (n-i) % MOD
        q = q * (i+1) % MOD
    return p * pow(q, MOD-2, MOD) % MOD

p = [1]*(8+1)
p[1] = 2
p[2] = 3
for i in range(3,W+1):
    p[i] = p[i-1] + p[i-2]

def f(x):
    if x < 1: return 1
    return p[x]

dp = [[Mint() for _ in range(W+2)] for __ in range(H+1)]
dp[0][K] += 1
for r in range(H):
    for c in range(1, W+1):
        if c >= 2:
            dp[r+1][c-1] += dp[r][c] * (f(c-3) * f(W-c-1))
        dp[r+1][c] += dp[r][c] * (f(c-2) * f(W-c-1))
        if c <= W-1:
            dp[r+1][c+1] += dp[r][c] * (f(c-2) * f(W-c-2))
print(dp[H][1])


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

using namespace std;
typedef long long ll;
char p[100005];

int main()
{
 scanf("%s",p);
 ll ans=0;
 char m=p[0];
 for(ll i=1;p[i]!='\0';i++)
 {
     if(p[i]!=m)
        m=p[i];
     else
     {
         ans++;
         if(m=='0')
            m='1';
         else
            m='0';

     }

 }
 ll len =strlen(p);
m=p[len-1];
  ll ans1=0;
 for(ll i=len-2;i>=0;i--)
 {
     if(p[i]!=m)
        m=p[i];
     else
     {
         ans1++;
         if(m=='0')
            m='1';
         else
            m='0';

     }

 }

 cout<<min(ans,ans1);

    return 0;
}


Measured memory_bytes: 384
S=input()
N=len(S)
count_list=[]
S+='R'
now=1
count=0
for c in S:
    if c==['L','R'][now]:
        count+=1
    if c!=['L','R'][now]:
        count_list.append(count)
        count=1
        now=(now+1)%2

answer=[]
M=len(count_list)//2
for j in range(M):
    left=count_list[2*j]
    right=count_list[2*j+1]
    if (left+right)%2==0:
        answer+=[0]*(left-1)+[(left+right)//2]*2+[0]*(right-1)
    else:
        if left%2==0:
            answer+=[0]*(left-1)+[(left+right-1)//2]+[(left+right+1)//2]+[0]*(right-1)
        else:
            answer+=[0]*(left-1)+[(left+right+1)//2]+[(left+right-1)//2]+[0]*(right-1)
print(*answer)

Measured memory_bytes: 7160