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

#define pb push_back
#define ll long long int
#define mpi map<int, int>
#define vi vector<int>
#define si set<int>
#define pii pair<int, int>
#define vpi vector<pii>
#define vs vector<string>
#define pri priority_queue<int>
#define mp make_pair
#define ff first
#define ss second
#define mod 1000000007
#define For(i, n) for (int i = 0; i < n; i++)
#define Ford(i, a, b) for (int i = a; i >= b; i--)
#define Rep(i, x, y) for (int i = x; i <= y; i++)
#define mem(a, b) memset(a, b, sizeof(a))
#define fastio                    \
    ios_base::sync_with_stdio(0); \
    cin.tie(0);                   \
    cout.tie(0)

double tick()
{
    static clock_t oldt, newt = clock();
    double diff = 1.0 * (newt - oldt) / CLOCKS_PER_SEC;
    oldt = newt;
    return diff;
}

int main()
{
    int k, a, b;
    cin >> k >> a >> b;
    if (b / k - a / k == 0 && (k != a && k != b) && k != 1 && b % k != 0 && a % k != 0)
        cout << "NG";
    else
        cout << "OK";
    cerr << "execution time is: " << tick() << "\n";
}


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

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

    vector<string> ans;
    string S = "a";

    function<void(int)> rec = [&](int i) {
        if (i == N) {
            ans.push_back(S);
            return;
        }

        int mc = *max_element(S.begin(), S.end()) - 'a';
        for (int c=0; c<=mc+1; ++c) {
            S.push_back(char('a' + c));
            rec(i+1);
            S.pop_back();
        }
    };

    rec(1);
    for (const string& s : ans) cout << s << endl;
}

Measured memory_bytes: 9588
/*
ID: victorn2
LANG: C++
TASK: fact4
*/

// 178

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#define trie bakayerou_konayarou
#define pb push_back
#define INF 0x3f3f3f3f
#define ll long long
#define int long long
#define endl '\n'
#define f first
#define s second
#define FAST cin.tie(0), cout.tie(0), ios::sync_with_stdio(0)
#define debug(x) cout << "DEBUG " << x << endl
#define debug2(x, y) cout << "DEBUG " << x << " " << y << endl
#define debug3(x, y, z) cout << "DEBUG " << x << " " << y << " " << z<< endl
#define debug4(x, y, z, o) cout << "DEBUG " << x << " " << y << " " << z<< " " << o << endl
using namespace std;
using namespace __gnu_pbds;
typedef pair<int, ll> pii;
typedef pair<int, pair<int, int>> ppi;
typedef vector<vector<int>> mat;
typedef tree<int,null_type,less<int>,rb_tree_tag,
tree_order_statistics_node_update> indexed_set;
const ll mod = 1e9+7;
const ll MOD = 9901;
const int LINF = 0x3f3f3f3f3f3f3f;
const int MAXN = 200005;
#define fin cin
#define fout cout

int a, b, c, n, m, k;
string s, t;

int32_t main() {
	cin >> s >> t;
	int ans = 0;
	for(int i = 0; i < s.size(); i++)
		if(s[i] != t[i]) ans++;
	cout << ans << endl;

}

Measured memory_bytes: 3848
n=int(input())
a=input()
b=['A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z','A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z']


for i in a:
  print(b[b.index(i)+n],end='')

Measured memory_bytes: 74620
#include <iostream>
#include <string>
#include <algorithm>

using namespace std;

int main(void){
   string s[3];
   for(int i = 0; i < 3; i++)
    cin >> s[i];
    for(int i = 0; i < 2; i++)
        for(int j = i+1; j < 3; j++)
            if(s[i][0]<s[j][0])
                swap(s[i][0], s[j][0]);
    int ans = (s[0][0]-48)*10+s[1][0]+s[2][0]-96;
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
//https://atcoder.jp/contests/abc172/tasks/abc172_b
#include <bits/stdc++.h>
#define ll long long int
using namespace std;
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	string s;
	cin>>s;
	string t;
	cin>>t;
	ll cnt=0;
	ll n;
	n=s.length();
	ll i;
	for(i=0;i<n;i++)
	{
		if(s[i]!=t[i])
		{
			cnt++;
		}
		else
		{
			cnt=cnt;
		}
	}
	cout<<cnt<<"\n";
	return 0;
}

Measured memory_bytes: 3748
n = int(input())
room_list = [[[0 for i in range(10)] for j in range(3)] for k in range(4)]
for i in range(n):
    b, f, r, v = map(int, input().split())
    room_list[b - 1][f - 1][r - 1] += v

output =[]
for i in range(4):
    for j in range(3):
        output = list(map(str, room_list[i][j]))
        print(" " + " ".join(output))
    if i < 3:
        print("#" * 20)

Measured memory_bytes: 7724
#include <algorithm>
#include <bits/stdc++.h>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;

#define rep(X, S, E) for (int(X) = (S); (X) < (E); ++(X))
#define rrep(X, S, E) for (int(X) = (E)-1; (X) >= (S); --(X))
#define itrep(X, Y) for (auto(X) = (Y).begin(); (X) != (Y).end(); (X)++)
#define all(X) (X).begin(), (X).end()
#define sortDecending(X) sort(all(X), greater<ll>()) //降順
#define sortAscending(X) sort(all(X))                //昇順
#define pb push_back
#define mp make_pair
#define fi first
#define sc second
#define print(x) cout << x << endl
#define printDouble(x) cout << fixed << setprecision(13) << x << endl
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<bool> vb;
typedef priority_queue<ll, vl> decendingQueue;              //降順
typedef priority_queue<ll, vl, greater<ll>> ascendingQueue; //昇順
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
const ll INT_INF = 1e9;
const ll LL_INF = 1e18;

// http://hos.ac/slides/20140319_bit.pdf
class BinaryIndexedTree {
  int N;
  vl bit;

public:
  BinaryIndexedTree(int N) {
    this->N = N;
    bit = vl(N);
  }

  // v[i] += w;
  void add(int i, int w) {
    for (int x = i; x < N; x |= x + 1) {
      bit[x] += w;
    }
  }

  // v[0] + ... + v[a-1]
  int sum(int a) {
    int ret = 0;
    for (int x = a - 1; x >= 0; x = (x & (x + 1)) - 1) {
      ret += bit[x];
    }
    return ret;
  }
};

// http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_5_D&lang=jp
int main() {
  int N;
  cin >> N;

  vl a(N);
  rep(i, 0, N) { cin >> a[i]; }

  vector<pair<ll, int>> b;
  rep(i, 0, N) { b.push_back(mp(a[i], i)); }
  sortAscending(b);

  rep(i, 0, N) { a[b[i].second] = i; }

  BinaryIndexedTree bit(N);
  ll ans = 0;
  rep(i, 0, N) {
    bit.add(a[i], 1);

    // 自分より大きい値の数
    ans += i - bit.sum(a[i]);
  }

  print(ans);
  return 0;
}



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

using ll = long long;
using ull = unsigned long long;

#define MOD 1000000007

int main(void) {
    ll start = LONG_LONG_MAX, end = 0;
    string S;
    cin >> S;
    for(ll i = 0;i < S.size();i++) {
        if(S[i] == 'A') start = min(start, i);
        if(S[i] == 'Z') end = max(end, i);
    }
    cout << end - start + 1 << endl;
    return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
  
/* attention
    long longのシフト演算には気をつけよう
    タイポした時のデバッグが死ぬほどきつくなるので変数名は最低3字くらい使った方がいいかも
    sizeは(int)とキャストしよう
    ごちゃごちゃ場合分けを考える前に全探索は考えましたか？
*/

const ll mod = 1e9+7;

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

    int a, b, c; cin >> a >> b >> c;
    int l = a-b;

    c -= min(c, l);
    cout << c << endl;
   
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <queue>
#include <tuple>

#define REP(i, a, b) for (int i = int(a); i < int(b); i++)
#define dump(val) cerr << __LINE__ << ":\t" << #val << " = " << (val) << endl

using namespace std;

typedef long long int lli;
typedef tuple<int,int,int,int> Point;

int main() {
    int W, H;
    while (cin >> W >> H, W + H) {
        vector<vector<char>> L(H + 2, vector<char>(W + 2, '#')), R(H + 2, vector<char>(W + 2, '#'));
        int xl, yl, xr, yr;
        REP (i, 1, H + 1) {
            REP (j, 1, W + 1) {
                cin >> L[i][j];
                if (L[i][j] == 'L') {
                    yl = i;
                    xl = j;
                }
            }
            REP (j, 1, W + 1) {
                cin >> R[i][j];
                if (R[i][j] == 'R') {
                    yr = i;
                    xr = j;
                }
            }
        }

        // used[yl][xl][yr][xr]
        vector<vector<vector<vector<bool>>>> used(H + 2, vector<vector<vector<bool>>>(W + 2, vector<vector<bool>>(H + 2, vector<bool>(W + 2, false))));
        queue<Point> q;
        int dx[4] = {0, 1, 0, -1};
        int dy[4] = {1, 0, -1, 0};
        q.emplace(yl, xl, yr, xr);
        bool ans = false;
        while (q.size()) {
            Point p = q.front();
            q.pop();
            yl = get<0>(p);
            xl = get<1>(p);
            yr = get<2>(p);
            xr = get<3>(p);
            if (used[yl][xl][yr][xr]) continue;
            used[yl][xl][yr][xr] = true;

            if (L[yl][xl] == '%' && R[yr][xr] == '%') {
                ans = true;
                break;
            }
            if (L[yl][xl] == '%' || R[yr][xr] == '%') continue;
            REP (k, 0, 4) {
                int nyl = yl + dy[k];
                int nxl = xl + dx[k];
                int nyr = yr + dy[k];
                int nxr = xr - dx[k];

                if (L[nyl][nxl] == '#') {
                    nyl = yl;
                    nxl = xl;
                }
                if (R[nyr][nxr] == '#') {
                    nyr = yr;
                    nxr = xr;                    
                }

                q.emplace(nyl, nxl, nyr, nxr);
            }
        }
        cout << (ans ? "Yes" : "No") << endl;
    }
    return 0;
}


Measured memory_bytes: 15888
#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,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define fi first
#define se second

template<typename A, typename B> inline bool chmax(A &a, B b) { if (a<b) { a=b; return 1; } return 0; }
template<typename A, typename B> inline bool chmin(A &a, B b) { if (a>b) { a=b; return 1; } return 0; }

typedef long long ll;
typedef pair<int, int> pii;
const ll INF = 1ll<<29;
const bool debug = 0;

int main() {
	int w;
	cin >> w;
	cout << w * 32 << endl;
	return 0;
}

Measured memory_bytes: 3116
#include<stdio.h>
#include<iostream>
#include<iomanip>
#include<string>
#include<vector>
#include<queue>
#include<stack>
#include<map>
#include<set>
#include<algorithm>
#include<string>
#include<math.h>
using namespace std;

const int MAX = 1000;

int main(){
    int X,Y,Z,K;
    long long A[MAX],B[MAX],C[MAX];
    vector<long long> v1,v2;

    cin >> X >> Y >> Z >> K;
    for(int i = 0;i < X;i++)cin >> A[i];
    for(int i = 0;i < Y;i++)cin >> B[i];
    for(int i = 0;i < Z;i++)cin >> C[i];

    for(int i = 0;i < X;i++){
        for(int j = 0;j < Y;j++){
            v1.push_back(A[i] + B[j]);
        }
    }

    sort(v1.begin(),v1.end(),greater<long long>());

    for(int i = 0;i < Z;i++){
        for(int j = 0;j < min(K,X*Y);j++){
            v2.push_back(C[i] + v1[j]);
        }
    }

    sort(v2.begin(),v2.end(),greater<long long>());

    for(int i = 0;i < K;i++){
        cout << v2[i] << endl;
    }
    
    return 0;
}

Measured memory_bytes: 43108
from fractions import gcd
A, B, C, D = map(int, input().split())
A -= 1
# / だと駄目らしいんだが。。。最小公倍数なのになぜ？
L = C*D//gcd(C,D)
a = A - ((A//C)+(A//D)-(A//L))
b = B - ((B//C)+(B//D)-(B//L))
print(int(b - a))


Measured memory_bytes: 5088
N,K=map(int,input().split())

def ans156(N:int, K:int):
    length=1#0桁はないため、1からスタート
    while True:
        if N<K:
            break
        N=int(N/K)#割り切れるごとに1桁ずつ増えていく。
        length+=1
    return length

print(ans156(N,K))

Measured memory_bytes: 9084
//Code by ASIM FOIZE AIMON
//CSE'19;CUET
//avoid copy paste//Hit the frined button
#include <bits/stdc++.h>
using namespace std;
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);
#define precise cout.precision(10); cout << fixed;
#define endl "\n"
#define int int64_t
#define ll long long
#define yes printf("YES\n")
#define no printf("NO\n")

int32_t main()
{
    /*#ifndef ONLINE_JUDGE
        freopen("/media/AIMON/SSDVol/Progs/CodeForces/input.txt", "r", stdin);
        freopen("/media/AIMON/SSDVol/Progs/CodeForces/output.txt", "w", stdout);
    #endif*/
    int a[100001],b[10001],c,d,e,s,f,m,n,p,t,i,j,k;
    vector<int>v;
    cin>>n>>k;
    if(n<=9 && k<=9)
    {
        cout<<n*k<<endl;
    }
    else
        cout<<-1<<endl;
}


Measured memory_bytes: 3640
import java.util.*;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int MOD = 998244353;
		int N = sc.nextInt();
		int S = sc.nextInt();
		long[][] dp = new long[N+1][S+1];
		dp[0][0] = 1;
		for(int i = 0; i < N; i++) {
        	int A = sc.nextInt();
			for(int j = 0; j <= S; j++)
				dp[i+1][j] = dp[i][j] * 2 % MOD;
			for(int j = 0; j + A <= S; j++)
				dp[i+1][j+A] += dp[i][j];
		}
		System.out.println(dp[N][S] % MOD);
	}
}


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

using namespace std;

#define INF 1000000000
#define pb(a) push_back(a)
#define vi vector<int>
#define vvi vector<vi>
#define P pair<int,int>
#define all(vec) (vec.begin()),(vec.end())
#define ll long long
#define sz(x) ((int)(x).size())
#define in(x) int x;cin>>x;
#define bit(n) (1<<(n))

#define REP(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define REP3(i, m, n) for(int i = m, i##_len=(n);i < i##_len;i++)
#define FORVEC(i, v) for(int i = 0;i < sz(v);i++)


int main(){
    long long n,k,ans;
    cin>>n>>k;
    ans=0ll;
    REP3(b,k+1,n+1){
        ans+=(b-k)*(n/b);
        if(n%b)ans+=max(0ll,n%b-max(0ll,k-1ll));
        //cout<<b<<","<<ans<<endl;
    }
    cout<<ans<<endl;
    
    return 0;
}

Measured memory_bytes: 256
import sys

while 1:
    H,W = map(int, raw_input().split())

    if H == 0 and W == 0:
        break

    for i in range(H):
        for j in range(W):
            if j == W-1:
                print "#"
            elif i == 0 or i == H-1 or j == 0:
                sys.stdout.write("#")
            else:
                sys.stdout.write(".")

        if i == H-1:
            print ""

Measured memory_bytes: 6376
from itertools import product

N, M, X = map(int, input().split())

CA = [list(map(int, input().split())) for _ in range(N)]

ans = 100000000
for buylist in product((0, 1), repeat=N):
    cost = 0
    und = [0]*M
    for idx, x in enumerate(buylist):
        if x == 1:
            cost += CA[idx][0]
            for i in range(1, M+1):
                und[i-1] += CA[idx][i]
    cnt = 0
    for i in range(M):
        if und[i] >= X:
            cnt += 1
    if cnt == M and cost < ans:
        ans = cost
if ans == 100000000:
    print(-1)
else:
    print(ans)



Measured memory_bytes: 9128
#include <iostream>
#include<vector>
#include<string>
using namespace std;

int main() {
	string s;cin>>s;
	int g=0;
	int p=0;
	for(int i=0;i<s.size();i++){
		if(s[i]=='g')g++;
		if(s[i]=='p')p++;
	}
	cout<<(g-p)/2<<endl;
	return 0;
}


Measured memory_bytes: 512
fun main(args: Array<String>) {
    val n = readLine()!!.toInt()
    val s = readLine()!!
    var ans = s.count { it == '.' }
    ans = Math.min(ans, s.count { it == '#' })
    val blackCount = Array(n) { 0 }
    blackCount[0] = if (s[0] == '#') 1 else 0
    (1 until n).forEach { blackCount[it] = blackCount[it - 1] + if (s[it] == '#') 1 else 0 }

    val whiteCount = Array(n) { 0 }
    whiteCount[n - 1] = if (s[n - 1] == '.') 1 else 0
    (n - 2 downTo 0).forEach { whiteCount[it] = whiteCount[it + 1] + if (s[it] == '.') 1 else 0 }

    for (i in 0 until (n - 1)) {
        val white = blackCount[i]
        val black = whiteCount[i + 1]
        ans = Math.min(ans, white + black)
    }
    println(ans)
}


Measured memory_bytes: 41328
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0; i<n; i++)
#define rep1(i, n) for(int i=1; i<=n; i++)
#define rrep(i, n) for(int i=n-1; i>=0; i--)
#define rrep1(i, n) for(int i=n; i>=1; i--)
#define all(v) v.begin(),v.end()
using ll = long long;
using pii = pair<int, int>;
using pil = pair<int, ll>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
const int INF = 1e9;
const ll LLINF = 1e18;
const ll MOD = 1e9+7;
const double EPS = 1e-10;
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; }

using Graph = vector<vector<int>>;
const int MAXN = 1005;
const int MAXV = 1000005;

int n;
int id[MAXN][MAXN];
int dist[MAXV];
int state[MAXV]; // 0:未訪問 1:探索中 2:探索済み

int toId(int i, int j) {
    if (i > j) swap(i, j);
    return id[i][j];
}

int dfs(const Graph &g, int u) {
    if (state[u] == 1) return -1; // サイクル検出
    if (state[u] == 2) return dist[u]; // 探索済みなので何もしない

    state[u] = 1;
    dist[u] = 1;
    for (int v: g[u]) {
        int res = dfs(g, v);
        if (res == -1) return -1;
        dist[u] = max(dist[u], res + 1);
    }
    state[u] = 2;
    return dist[u];
}

int main() {
    cin >> n;
    vector<vector<int>> a(n, vector<int>(n-1));
    int m = n * (n-1) / 2;
    Graph g(m);

    rep(i, n) {
        rep(j, n-1) { 
            cin >> a[i][j];
            a[i][j]--;
        }
    }

    int V = 0;
    rep(i, n) rep(j, n) {
        if (i < j) id[i][j] = V++;
    }

    rep(i, n) {
        rep(j, n-1) {
            a[i][j] = toId(i, a[i][j]);
        }
        rep(j, n-2) {
            g[a[i][j+1]].push_back(a[i][j]);
        }
    }

    int ans = 0;
    rep(i, V) {
        int res = dfs(g, i);
        if (res == -1) {
            cout << -1 << endl;
            return 0;
        }
        chmax(ans, res);
    }
    cout << ans << endl;
}


Measured memory_bytes: 43264
#include <stdio.h>
 
#include <algorithm>
#include <deque>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <utility>
#include <vector>
#include <climits>
 
using namespace std;
typedef long long llong;
 
static pair<llong, llong> min_divisors(llong n) {
  pair<llong, llong> res;
  llong min_sum = LLONG_MAX;
  for (llong i = 1; i * i <= n; ++i) {
    if (n % i == 0) {
      llong m = n / i;
      llong sum = i + m;
      if (sum < min_sum) {
        res = {i, m};
        min_sum = sum;
      }
    }
  }
  return res;
}
 
 
void CWalkOnMultiplicationTable(std::istream& in, std::ostream& out) {
    llong n;
    in >> n;
    pair<llong, llong> p = min_divisors(n);
    out << p.first + p.second - 2 << endl;
}
 
int main(int argc, char** argv) { CWalkOnMultiplicationTable(cin, cout); return 0; }

Measured memory_bytes: 256
#include <algorithm>
#include <iomanip>
#include <iostream>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define SORT(a) sort((a).begin(), (a).end())
#define RSORT(a) sort((a).rbegin(), (a).rend())
#define REP(i, n) for (int i = 0; i < n; i++)
#define RREP(i, n) for (int i = n; 0 <= i; i--)
#define FOR(i, start, end) for (int i = start; i < end; i++)
#define FORSTEP(i, start, end, step) for (int i = start; i < end; i += step)
#define ALL(a) a.begin(), a.end()
typedef long long ll;
const int INF = 100100100;
using namespace std;

class UnionFind {
  public:
    // 親の番号を格納する。大家だった場合は－1
    vector<int> Parent;

    // 作るときはparentの値をすべて-1にする
    //こうするとすべてばらばらになる
    UnionFind(int N) { Parent = vector<int>(N, -1); }

    // Aがどのグループに属しているか調べる
    int root(int A) {
        if (Parent[A] < 0)
            return A;
        return Parent[A] = root(Parent[A]);
    }

    int size(int A) {
        return -Parent[root(A)]; //親をとっていきたい
    }

    // AとBをくっつける
    bool connect(int A, int B) {
        A = root(A);
        B = root(B);
        //すでにくっついているからくっつけない
        if (A == B)
            return false;

        // 大きい方(A)に小さい方(B)をくっつけたい
        //大小が逆のばあいひっくり返す
        if (size(A) < size(B))
            swap(A, B);
        Parent[A] += Parent[B];
        Parent[B] = A;
        return true;
    }
};

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N, M;
    cin >> N >> M;
    vector<int> A(M), B(M);
    REP(i, M) {
        cin >> A[i] >> B[i];
        // 1番目の島を0番目にしたい
        A[i]--;
        B[i]--;
    }

    vector<ll> ans(M);
    ans[M - 1] = (ll)N * (N - 1) / 2;

    UnionFind uni(N);
    for (int i = M - 1; 1 <= i; i--) {
        ans[i - 1] = ans[i];
        //繋がっていないのが繋がったとき
        if (uni.root(A[i]) != uni.root(B[i])) {
            ans[i - 1] -= (ll)uni.size(A[i]) * uni.size(B[i]);
            uni.connect(A[i], B[i]);
        }
    }

    REP(i, M) cout << ans[i] << "\n";

    return 0;
}

Measured memory_bytes: 3328
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Main m = new Main();
		m.run();
	}

	Scanner sc = new Scanner(System.in);

	void run() {
		
		char[] s = sc.next().toCharArray();
		int n = s.length;
		int b = 0;
		
		long sum = 0;
		for(int i = 0; i < n; i++){
			if(s[i] == 'W'){
				sum += b;
			}else{
				b++;
			}
		}
		
		System.out.println(sum);
	}
}


Measured memory_bytes: 25904
#include <stdlib.h>
#include <stdio.h>
#include <time.h>
#include <math.h>
#include <iostream>
#include <string>
#include<algorithm>
#include <vector>
#include <cassert>
#include<cmath>
using namespace std;
int main() {
	int i, j;
	int A, B, K;
	int sum,sub ;
	double decide;
	cin >> A >> B >> K;


	sum = A;
	sub = B-K+1;


	decide = (B - A + 1) / 2;
	if (decide < K) {
		for (i = 0; i < (B-A+1); ++i) {
			cout << sum << endl;
			++sum;
		}
		//cout << "test" << endl;
	}
	else {
		for (i = 0; i < K; ++i) {
			cout << sum << endl;
			++sum;
		}
		for (i = 0; i < K; ++i) {
			cout << sub << endl;
			++sub;
		}

	}



}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
    public static long solve[] = new long[100001];
    public static int a[] = new int[100001];
    public static long n;
    public static void main(String args[])throws IOException
    {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        n=Long.parseLong(br.readLine());
        for(int i=0;i<n-1;i++)
            solve[i]=-1;
        solve[(int)n-1]=0;
        String S[]=br.readLine().split(" ");
        for(int i=0;i<n;i++)
            a[i]=Integer.parseInt(S[i]);
        System.out.println(DP(0));
    }
    public static long DP(int x)
    {
        if(solve[x]==-1)
        {
            if(x==n-2)
                solve[x]=DP(x+1)+(Math.abs(a[x]-a[x+1]));
            else
                solve[x]=Math.min(DP(x+1)+(Math.abs(a[x]-a[x+1])),DP(x+2)+(Math.abs(a[x]-a[x+2])));
        }
        return solve[x];
    }
}

Measured memory_bytes: 52796
#include<bits/stdc++.h>
using namespace std;
int a[20];
int main(){
	a[1]=1,a[4]=1,a[9]=1,a[7]=1;
	for(int i=0;i<4;i++){
		int t;
		cin>>t;
		a[t]=0;
	}
	if(a[1]||a[9]||a[7]||a[4]){
		cout<<"NO\n";
	}
	else cout<<"YES\n";
	
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,l,r) for(long long i=(l);i<(r);++i)
#define REP(i,n) FOR(i,0,n)
#define int long long

signed main(){
    int N,A,B;
    cin>>N>>A>>B;
    cout<<min(N*A,B)<<endl;
}

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

int main() {
	int a , b ;
	scanf("%d%d",&a,&b);
	//bool done = false;
	int mid = (a+b)/2;
	if(abs(a-mid)== abs(b-mid))printf("%d\n",mid);
	else
	puts("IMPOSSIBLE");
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 10;
int n, k, ans;
int a[maxn];
bool sec[maxn];
vector<int> E[maxn];
int dfs(int x)
{
	int ret = 0;
	for(auto v : E[x])
		ret = max(ret, dfs(v));
	++ret;
	if(ret == k && !sec[x]) ++ans, ret = 0;
	return ret;
}
int main()
{
	scanf("%d%d", &n, &k); 
	for(int i = 1; i <= n; ++i) scanf("%d", &a[i]);
	ans += (a[1] != 1);
	for(int i = 2; i <= n; ++i) E[a[i]].push_back(i);
	sec[1] = 1;
	for(auto v : E[1]) sec[v] = 1;
	dfs(1);
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 10752
#include <stdio.h>

//Istiyak Hossain

int main()
{
    int W, H, x, y, r;

    scanf("%d %d %d %d %d", &W, &H, &x, &y, &r);

    if((x + r) <= W && (y + r) <= H && (x -r) >= 0 && (y - r) >= 0){
        printf("Yes\n");
    }
    else {
        printf("No\n");
    }

    return 0;
}



Measured memory_bytes: 2064
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <numeric>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <string>
#include <iterator>
#include <cmath>
#include <deque>
#include <stack>
#include <functional>
using namespace std;
#define int long long

signed main()
{
    {
        if (fopen("input.txt", "r")) {
            freopen("input.txt", "r", stdin);
            freopen("output.txt", "w", stdout);
        }
        ios_base::sync_with_stdio(false);
        cin.tie(NULL);
        cout.tie(NULL);
    }

    int n;
    cin >> n;
    if (n % 2) {
        cout << 0;
        return 0;
    }
    int ans5 = 0, d = 2;
    while (d <= n / 5LL) {
        d *= 5LL;
        ans5 += n / d;
    }
    d = 1;
    int ans2 = 0;
    while (d <= n / 2LL) {
        d *= 2LL;
        ans2 += n / d;
    }
    cout << min(ans5, ans2);
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long 
int main()
{
  int n,fl;
  int c[10][10];
  long long cnt;

  for(int i=0; i<10; i++){
    for(int j=0; j<10; j++) c[i][j] = 0;
  }

  cin >> n;

  fl = 1;

  for(int i=1; i<=n; i++){
    if(fl * 10 <= i) fl *= 10;
    c[i / fl][i % 10]++;
  }

  cnt = 0;
  for(int i=0; i<10; i++){
    for(int j=0; j<10; j++) cnt += (c[i][j] * c[j][i]);
  }

  cout << cnt << endl;
  return 0;
}


Measured memory_bytes: 256
n = int(input())
monster = list(map(int,input().split()))
hero = list(map(int,input().split()))
s=0
for i in range(n):
    cur = hero[i]
    if cur>=monster[i]:
        cur-=monster[i]
        s+=monster[i]
        monster[i]=0
    else:
        monster[i]-=cur
        s+=cur
        cur=0
    if cur>0:
        if monster[i]>0:
            if cur >= monster[i]:
                cur -= monster[i]
                s += monster[i]
                monster[i] = 0
            else:
                monster[i] -= cur
                s+=cur
                cur = 0
        else:
            if i<=n-1:
                if cur >= monster[i+1]:
                    cur -= monster[i+1]
                    s += monster[i+1]
                    monster[i+1] = 0
                else:
                    monster[i+1] -= cur
                    s+=cur
                    cur = 0
print(s)


Measured memory_bytes: 18476
#include<bits/stdc++.h>
using namespace std;
main(){
int i,j,k,l,n,m;
while(cin>>n){
int x[n-1];
for(i=0;i<n-1;i++)cin>>x[i];
j=x[0];
for(i=0;i<n-2;i++){
 if(x[i]<x[i+1]) j+=x[i];
 else j+=x[i+1];
}
j+=x[n-2];
if(n==2)j=x[0]*2;
cout<<j<<endl;
} return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/rope>
using namespace __gnu_cxx;
using namespace std;
#define mst(a,b) memset(a,b,sizeof(a))
#define ALL(x) x.begin(),x.end()
#define debug(a) cout << #a": " << a << endl;
#define eularMod(a, b) a < b ? a : a % b + b
#define X first
#define Y second
#define lc rt << 1
#define rc rt << 1 | 1
inline int lowbit(int x){ return x & -x; }
typedef long long LL;
typedef pair<int, int> pii;
typedef unsigned long long ULL;
const int N = 1e5 + 10;
const int M = 1e7 + 10;
const int mod = (int) 1000000007;
const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fLL;
const double PI = acos(-1.0);
const double eps = 1e-6;

int prime[N];
bool vis[N];
LL a[N];
int tot;
set<LL> st;
map<LL, int> cnt;
map<LL, LL> has;

void getPrime() {
    for (int i = 2; i < N; i++) {
        if (!vis[i])
            prime[tot++] = i;
        for (int j = 0; j < tot && 1LL * i * prime[j] < N; j++) {
            vis[i * prime[j]] = true;
            if (i % prime[j] == 0)
                break;
        }
    }
}
void getSqu() {
    for (LL i = 1; i * i <= 10000000000LL; i++)
        st.insert(i * i);
}

int main() {
#ifdef purple_bro
    freopen("in.txt", "r", stdin);
//    freopen("out.txt","w",stdout);
#endif
    getPrime();
    getSqu();

    int n;

    scanf("%d", &n);

    for (int i = 1; i <= n; i++)
        scanf("%lld", &a[i]);

    bool one = false;

    for (int i = 1; i <= n; i++) {
        LL now = 1;
        LL r = 1;

//        debug(a[i]);

        for (int j = 0; j <= 333; j++) {
            int c = 0;
            for (; a[i] % prime[j] == 0; a[i] /= prime[j])
                c++;
            c %= 3;
            if (!c)
                continue;
            for (int k = 0; k < c; k++)
                now *= prime[j];
            for (int k = c; k < 3; k++)
                r *= prime[j];
            if (a[i] == 1)
                break;
        }

        if (a[i] != 1) {
            if (st.count(a[i])) {
                LL t = sqrt(a[i] + 0.5);
                now *= a[i];
                r *= t;
            } else {
                now *= a[i];
                r *= a[i] * a[i];
            }
        }

        if (now == 1) {
            one = true;
            continue;
        }

//        debug(now);

        cnt[now]++;
        has[now] = r;
    }

    LL res = one;

    for (map<LL, int>::iterator it = cnt.begin(); it != cnt.end(); it++) {
        LL u = it -> X;
        int c = it -> Y;
        if (has.find(u) != has.end()) {
            res += max(c, cnt[has[u]]);
            cnt.erase(has[u]);
        } else
            res += c;
    }

    printf("%lld\n", res);

    return 0;
}


Measured memory_bytes: 18304
n = int(input())
A,B = 0,0
for i in range(n):
    x,y = map(int,input().split())
    t,a = 1,1
    if A > x:
        t = A // x
        if A % x != 0:
            t += 1
    if B > y:
        a = B // y
        if B % y != 0:
            a += 1
    m = max(t,a)
    A = x*m
    B = y*m
print(A+B)

Measured memory_bytes: 9136
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define _GLIBCXX_DEBUG
#define all(x) x.begin(), x.end()
using namespace std;
typedef long long ll;
typedef pair<int, int> pair;
const int inf = 1000000000; //10^9
const ll inff = 1000000000000000000; //10^18

int main(){
    int n;
    cin >> n;
    int a[n];
    rep(i, n) {
        cin >> a[i];
    }
    int ans=0;
    rep(i, n) {
        ans += a[i] -1;
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3620
N = gets.to_i
A = gets.split.map(&:to_i).sort.reverse

ans = A[0]
tmp = 1
cnt = 0
2.upto(N-1) do
  ans += A[tmp]
  cnt += 1
  if cnt == 2
    tmp += 1
    cnt = 0
  end
end

puts(ans)


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


int main(){
    string s;
    cin>>s;
    int n=s.length();
    for(int i=0;i<n-1;i++){
        if(s[i]==s[i+1]){
            cout<<"Bad";
            return 0;
        }
    }
    cout<<"Good";

    return 0;
}

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

int main() {
	long long n, k;
	cin >> n >> k;
	map<int, long long> mp;
	for (int i = 0; i < n; i++) {
		int a, b;
		cin >> a >> b;
		mp[a] += b;
	}
	int ans;
	for (auto e : mp) {
		if (e.second >= k) {ans = e.first; break;}
		else k -= e.second;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 4224
#include<bits/stdc++.h>
using namespace std;
int main()
{
 string s;
  cin>>s;
 for(int i=0;i<s.size();i++)
 {
    if(s[i]=='9') cout<<'1';
    else if(s[i]=='1') cout<<'9';
     else cout<<s[i];
 }
    return 0;
}

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

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

  vector<int> dc(100010, 0);
  vector<set<int>> ss(C+1), ts(C+1);
  for (int i = 0; i < n; ++i) {
    int s, t, c;
    cin >> s >> t >> c;
    ++dc[s - 1];
    --dc[t];
    ss[c].insert(s);
    ts[c].insert(t);
  }
  for (int c = 1; c <= C; ++c) {
    for (auto s : ss[c]) {
      if (ts[c].find(s) != ts[c].end()) {
        --dc[s - 1];
        ++dc[s];
      }
    }
  }

  int ret = 0;
  int r = 0;
  for (int i = 0; i < dc.size(); ++i) {
    r += dc[i];
    ret = max(ret, r);
  }
  cout << ret << "\n";

  return 0;
}


Measured memory_bytes: 9984
package main

import (
	"bufio"
	"bytes"
	"fmt"
	"os"
	"strconv"
)

type List struct {
	head *Node
	tail *Node
}

type Node struct {
	next *Node
	prev *Node
	v    int
}

func NewList() List {
	head, tail := &Node{}, &Node{}
	head.next, tail.prev = tail, head
	return List{head, tail}
}

func (l *List) Insert(x int) {
	node := &Node{}
	node.v = x
	node.next, node.prev = l.tail, l.tail.prev
	l.tail.prev, l.tail.prev.next = node, node
}

func (l List) String() string {
	var b bytes.Buffer
	node := l.head.next
	for node != l.tail {
		b.WriteString(fmt.Sprint(node.v))
		node = node.next
		if node != l.tail {
			b.WriteString(" ")
		}
	}
	return b.String()
}

func (l *List) Dump(w *bufio.Writer) {
	w.WriteString(fmt.Sprintln(l))
}

func Splice(s *List, t *List) {
	tTailP := t.tail.prev
	sHeadN := s.head.next
	sTailP := s.tail.prev

	// t:  h 1 2 3       t
	// s:        h 4 5 6 t
	//           ^
	tTailP.next = sHeadN
	sTailP.next = sHeadN.prev

	// t:  h 1 2 3       t
	// s:        h 4 5 6 t
	//                   ^
	sTailP.next = t.tail
	t.tail.prev = sTailP

	*s = NewList()
}

func NextInt(sc *bufio.Scanner) (int, error) {
	sc.Scan()
	return strconv.Atoi(sc.Text())
}


func main() {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	w := bufio.NewWriter(os.Stdout)

	n, _ := NextInt(sc)
	s := make([]List, n)
	for i := 0; i < n; i++ {
		s[i] = NewList()
	}

	q, _ := NextInt(sc)
	for i := 0; i < q; i++ {
		cmd, _ := NextInt(sc)
		t, _ := NextInt(sc)
		// fmt.Println(t, ":", s[t])
		switch cmd {
		case 0:
			x, _ := NextInt(sc)
			s[t].Insert(x)
		case 1:
			s[t].Dump(w)
		case 2:
			tt, _ := NextInt(sc)
			// fmt.Println("before:", s[t],",",s[tt])
			Splice(&s[t], &s[tt])
			// fmt.Println(" after:", s[t],",",s[tt])
		}
	}

	w.Flush()
}



Measured memory_bytes: 40016
#include<cstdio>

using ll=long long;

int main(void)
{
	char s[200000+2];

	while(scanf("%200000[BW]\n", s)==1)
	{
		ll ans=0;
		int bn=0;

		for(int i=0;s[i];i++)
		{
			if(s[i]=='B') bn++;
			if(s[i]=='W') ans+=bn;
		}
		printf("%lld\n", ans);
	}

	return 0;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
vector<long long> v;
void digui(long long cur,int time){
	if(time==0)return;
	int last_digit=cur%10;
	v.push_back(cur*10+last_digit);
	if(last_digit!=9)v.push_back(cur*10+last_digit+1);
	if(last_digit!=0)v.push_back(cur*10+last_digit-1);
	digui(cur*10+last_digit,time-1);
	if(last_digit!=9)digui(cur*10+last_digit+1,time-1);
	if(last_digit!=0)digui(cur*10+last_digit-1,time-1);
}
int main()
{
	int k;cin>>k;
	for(int i=1;i<10;i++){
		v.push_back(i);
		digui(i,10);
	}
	sort(v.begin(),v.end());
	cout<<v[k-1];
	return 0;
}

Measured memory_bytes: 11580
#include<stdio.h>
int main(void) {
    int q1, b, c1, c2, q2;
	int aizu_c, normal_c,leaveMoney;
	while (1) {
		scanf("%d", &q1);
		if (q1 == 0)break;
		scanf("%d %d %d %d", &b, &c1, &c2, &q2);
		aizu_c = 0;
		normal_c = 0;
		leaveMoney = b;
		while(leaveMoney - c1 >= 0 && aizu_c < q2) {
			leaveMoney -= c1;
			aizu_c++;
		}
		while (leaveMoney - c2 >= 0) {
			leaveMoney -= c2;
			normal_c++;
		}
		while (1) {
			if (aizu_c == 0) {
				printf("NA\n");
				break;
			}else if(aizu_c + normal_c >= q1){
				printf("%d %d\n",aizu_c,normal_c);
				break;
			}else if(aizu_c != 0){
				aizu_c--;
				leaveMoney += c1;
				normal_c += leaveMoney / c2;
				leaveMoney -= c2 * (leaveMoney / c2);
			}
		}
	}
	return 0;
}

Measured memory_bytes: 612
#include <iostream>
#include <cmath>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <map>
#include <set>
using namespace std;
#define MOD 1000000007
#define INF 1<<30
#define LINF (ll)1<<62
#define rep(i,n) for(ll i=0; i<(n); i++)
#define REP(i,a,b) for(ll i=(a); i<(b); i++)
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll, ll> P;
typedef vector<pair<ll, ll>> vpl;



int main(){
    ll n,m; cin >> n >> m;
    vpl ab;
    ll a,b;
    rep(i,n){
        cin >> a >> b;
        ab.emplace_back(a,b);
    }
    sort(ab.begin(), ab.end());
    ll ans=0;
    ll i=0;
    ll index=0;
    while(i<m){
        if(i+ab[index].second < m){
            ans += ab[index].first * ab[index].second;
            i += ab[index].second; 
        }else{
            ans += ab[index].first * (m-i);
            i = m;
        }
        index++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 2420
#include<iostream>
using namespace std;
int main()
{
    long long int n,a,b,t,s=0;
    long long int x[110000];
    cin>>n>>a>>b;
    for(int i=0;i<n;i++)
        cin>>x[i];
        for(int i=0;i<n-1;i++)
        {
            t=(x[i+1]-x[i])*a;
            if(t>b) s+=b;
            else s+=t;
        }
        cout<<s;
        return 0;
}

Measured memory_bytes: 1024
import math
S = list(input())
N = len(S)
K = math.floor(N/2)
S1 = S[:K]
S2 = S[:-K-1:-1]
res = 0
for s1,s2 in zip(S1,S2):
    if(s1 != s2):
        res += 1
print(res)


Measured memory_bytes: 3060
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <map>
#include <cmath>
using namespace std;

#if 0
#define DEBUG(x) do{cerr << #x << "=" << x << endl;}while(0);
#else
#define DEBUG
#endif

int main(){
	int n;
	string s;
	cin >> n >> s;
	int len = s.size();
	bool flag = true;
	if(len % 2 == 1) flag = false;
	for(int i=0; i<len/2;++i){
		if(s[i] == s[len/2+i]){

		}
		else{
			flag = false;
		}
	}

	cout << (flag ? "Yes" : "No") << endl;

	return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		solve3027();
	}

	public static void solve3027() {
		Scanner sc = new Scanner(System.in);

		int N = sc.nextInt();
		String binary = Integer.toBinaryString(N);
		int binaryNumDigits = binary.length();

		int ans = binary.contains("0") ? binaryNumDigits - 1 : binaryNumDigits;
		System.out.println(ans);

		sc.close();
	}
}



Measured memory_bytes: 26212
import java.util.*;
import java.util.regex.Pattern;

public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		String S = sc.next();

		String[] s = S.split("");

		int[] bCnt = new int[N+1];
		bCnt[0] = 0;

		for(int i=1; i<N+1; i++){
			if(s[i-1].equals("#")){
				bCnt[i] = bCnt[i-1]+1;
			} else{
				bCnt[i] = bCnt[i-1];
			}
		}

		int[] wCnt = new int[N+1];
		wCnt[N]=0;

		for(int i=N-1; i>-1; i--){
			if(s[i].equals(".")){
				wCnt[i]= wCnt[i+1]+1;
			}else{
				wCnt[i]= wCnt[i+1];
			}
		}

		int min = 200001;

		for(int i=0; i<N+1; i++){
			if(min>bCnt[i]+wCnt[i]){
				min = bCnt[i]+wCnt[i];
			}
		}

		System.out.println(min);


	}


}


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

using namespace std;

vector<string> split(const string& s, char c) {
    vector<string> v; stringstream ss(s); string x;
    while (getline(ss, x, c)) v.emplace_back(x); return move(v);
}
template<typename T, typename... Args>
inline string arrStr(T arr, int n) {
    stringstream s; s << "[";
    for(int i = 0; i < n - 1; i++) s << arr[i] << ",";
    s << arr[n - 1] << "]";
    return s.str();
}

#define ANTHRO(args...) {__anthro_begin(__LINE__); __anthro(split(#args, ',').begin(), args);}

inline void __anthro_begin(int line) { cerr << "#" << line << ": "; }
template<typename T> inline void __anthro_out_var(vector<T> val) { cerr << arrStr(val, val.size()); }
template<typename T> inline void __anthro_out_var(T* val) { cerr << arrStr(val,2); } //Change the values in case you want to debug something
template<typename T> inline void __anthro_out_var(T val) { cerr << val; }
inline void __anthro(vector<string>::iterator it) { cerr << endl; }

template<typename T, typename... Args>
inline void __anthro(vector<string>::iterator it, T a, Args... args) {
    cerr << it->substr((*it)[0] == ' ', it->length()) << "=";
    __anthro_out_var(a);
    cerr << "; ";
    __anthro(++it, args...);
}
//Simple Debugger

#define ll long long
#define MOD 1000000007
#define EPS 1e-9
int const INF = (int)1e9 + 1e3;
ll const INFL = (ll)1e18 + 1e6;
/*
    This is D.Unbalanced
*/

int main(){
    string s; cin>>s;
    for(auto& c:s) c-='a';
    vector<vector<int>> a(100010,vector<int> (26,0));
    bool flag=false;
    int k=0,st=0,en=0;
    for(int i=1;i<=s.length();i++){
        a[i]=a[i-1];
        a[i][s[i-1]]++;
        //ANTHRO(a[i-1],a[i],a[i][s[i-1]],a[i-2][s[i-1]]);
        if((i-2)>=0 && (a[i][s[i-1]]-a[i-2][s[i-1]])>=2){
            st=i-1;
            en=i;
            break;
        }
        else if((i-3)>=0 && (a[i][s[i-1]]-a[i-3][s[i-1]])>=2)
        {
            st=i-2;
            en=i;
            break;
        }
    }
    if(st==0&&en==0){
        cout<<-1<<" "<<-1;
    }
    else{
        cout<<st<<" "<<en;
    }
    return 0;
}


Measured memory_bytes: 13568
#include <iostream>
#include <vector>
#include <cstdlib>  
#include <algorithm>
#include <string>

using namespace std;
 
int main() {
    string s;cin>>s;
    if(s[s.length()-1] == 's') cout<<s+"es";
    else cout<<s+"s";
    return 0;
}

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

using namespace std;

int main() {
  int N;
  cin >> N;
  int64_t S = 0;
  unordered_map<int, int64_t> M;
  for (int i = 0; i < N; i++) {
    int64_t t;
    cin >> t;
    M[t]++;
    S += t;
  }

  int Q;
  cin >> Q;
  for (int i = 0; i < Q; i++) {
    int64_t B, C;
    cin >> B >> C;
    int64_t diff = (C - B) * M[B];
    S += diff;
    M[C] += M[B];
    M[B] = 0;
    cout << S << endl;
  }

  return 0;
}


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

#define int long long int
#define mp make_pair
using namespace std;

int32_t main() {
    string s;
    cin >> s;
    int n = s.length();
    int pos = n-1;
    int ans = 0;
    for (int i = n-1; i >= 0; --i) {
        if(s[i] == 'B'){
            ans += pos - i;
            pos--;
        }
    }
    printf("%lld",ans);
    return 0;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int INF = 1e9+5;
int main(){
    int sz;
    cin>>sz;
    int arr[sz];
    int k;
    cin>>k;
    vector<int> dp(sz,INF);
    dp[0]= 0;
    for(int i = 0;i<sz;i++) cin>>arr[i];
    for(int i = 0;i<sz;i++){
        for(int j =i+1;j<i+k+1;j++){
            if(j<sz){
                dp[j] = min(dp[j],dp[i]+abs(arr[i]-arr[j]));
            }
        }
    }cout<<dp[sz-1]<<endl;


}


Measured memory_bytes: 1024
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <map>
#include <math.h>
#include <cstring>

using namespace std;

#define REP(i,n)	for(int i=0;i<(n);++i)
#define REPS(i,s,t)	for(int i=(s);i<(t);++i)

#define INF 		2000000007
#define MOD			998244353

#define MAX 		100005

typedef unsigned int 			uint;
typedef unsigned long long int	ull;
typedef long long int ll;



int main(void) {
	vector<int> a(3);
	REP(i,3)cin>>a[i];

	sort(a.begin(),a.end());

	cout << (a[2]-a[0]) << endl;



    return 0;
}

Measured memory_bytes: 256
n, m = map(int, input().split())
k = []
s = []
for _ in range(m):
    line = [int(x) - 1 for x in input().split()]
    k.append(line[0] + 1)
    s.append(line[1:])
p = list(map(int, input().split()))

ans = 0
for combi in range(2**n):
    ok = True
    for index in range(len(p)):
        count = 0
        for i in range(n):
            if(combi >> i) & 1 and i in s[index]:
                count += 1
        if(count % 2 != p[index]):
            ok = False

    if ok:
        ans += 1
print(ans)

Measured memory_bytes: 42224
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i, n) for (ll i = 0; i < n; ++i)
#define ALL(a) a.begin(), a.end()
ll dx[4] = { 0, 1, 0, -1 };
ll dy[4] = { 1, 0, -1, 0 };
const ll INF = 1e14;
const ll MOD = 1e9 + 7;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    // input
    string s;
    cin >> s;
    int n = s.size();
    // output
    int ans = 0;
    int cntG = 0, cntP = 0;
    rep(i, n)
    {
        if (s[i] == 'g') {
            if (cntP < cntG) {
                cntP++, ans++;
            } else {
                cntG++;
            }
        } else {
            if (cntP < cntG) {
                cntP++;
            } else {
                cntG++, ans--;
            }
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
string to_string(const string& s) {
	return '"' + s + '"';
}
string to_string(const bool b) {
	return (b ? "true" : "false");
}
string to_string(const char* s) {
	return to_string((string)s);
}
string to_string(const char c) {
	string s = "'";
	s += c;
	s += "'";
	return s;
}
template<class T, class U>
string to_string(const pair<T, U>& p) {
	string s = "(";
	s += to_string(p.first);
	s += ", ";
	s += to_string(p.second);
	s += ")";
	return s;
}
template<class T>
string to_string(const T& a) {
	bool first = true;
	string s = "{";
	for (const auto& x : a) {
		if(!first){
			s += ", ";
		}
		first = false;
		s += to_string(x);
	}
	s += "}";
	return s;
}
void debug_out() {cerr << '\n';}
template<class Head, class... Tail>
void debug_out(Head head, Tail... tail) {
	cerr << ' ' << to_string(head);
	debug_out(tail...);
}
#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "] = ", debug_out(__VA_ARGS__)
#else
#define debug(...)
#endif
using ll = long long;
using ld = long double;
const int mod = 998244353;
const int inf = 1e9 + 100;
const ll inf64 = 7e18l;
struct point {
	int t, x, y;
};
int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout << fixed << setprecision(20);
	int n;
	cin >> n;
	vector<point> a(n + 1);
	a[0] = {0, 0, 0};
	for (int i = 1; i <= n; ++i) {
		cin >> a[i].t >> a[i].x >> a[i].y;
	}
	
	for (int i = 1; i <= n; ++i) {
		int dist = abs(a[i].x - a[i - 1].x) + abs(a[i].y - a[i - 1].y);
		int t = a[i].t - a[i - 1].t;
		if (t < dist || t % 2 != dist % 2) {
			cout << "No\n";
			return 0;
		}
	}
	cout << "Yes\n";
 	return 0;
}


Measured memory_bytes: 1408
#include<bits/stdc++.h>
using namespace std;
int main(){
int n,q;
cin>>n>>q;
string a[n];
for(int i=0;i<n;i++){
	cin>>a[i];
}
sort(a,a+n);
for(int i=0;i<n;i++){
	cout<<a[i];
}
return 0;
}


Measured memory_bytes: 256
/*
#pragma GCC optimize(2)
#pragma GCC optimize(3,"Ofast","inline")
*/
#include<bits/stdc++.h>
#define ALL(x) (x).begin(),(x).end()
#define ll long long
#define db double
#define ull unsigned long long
#define pii_ pair<int,int>
#define mp_ make_pair
#define pb push_back
#define fi first
#define se second
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define per(i,a,b) for(int i=(a);i>=(b);i--)
#define show1(a) cout<<#a<<" = "<<a<<endl
#define show2(a,b) cout<<#a<<" = "<<a<<"; "<<#b<<" = "<<b<<endl
using namespace std;
const ll INF = 1LL<<60;
const int inf = 1<<30;
const int maxn = 2e5+5;
inline void fastio() {ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);}

char s[1005],t[1005];

int main()
{
    fastio();
    cin>>s+1>>t+1;
    int n = strlen(s+1),m = strlen(t+1);
    int ans = inf;
    rep(i,1,n-m+1){
        int cnt = 0;
        rep(j,1,m) if(s[i+j-1]!=t[j]) cnt++;
        ans = min(ans,cnt);
    }
    cout<<ans<<endl;
    return 0;
}


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

int main(void){
	int a,b;
	cin>>a>>b;
	int c=1;
	while(c<=b){
		c*=10;
	}
	int n=a*c+b;
	bool f=false;
	for(int i=0;i<1000;i++){
		if(n==i*i){
			f=true;
			break;
		}
	}
	
	if(f){
		cout<<"Yes"<<endl;
	}else{
		cout<<"No"<<endl;
	}
	return 0;
}

Measured memory_bytes: 256