akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
int main(){
    int a,b;
    while(cin>>a>>b){
        if(a==0&&b==0)break;
        for(int i=0;i<a;i++){
            for(int j=0;j<b;j++){
                if(i==0||j==0||i==a-1||j==b-1)cout << '#';
                else cout<<'.';
            }
            cout << endl;
        }
        cout << endl;
    }
}


Measured memory_bytes: 3120
#include <iostream>
using namespace std;
int main(){
	int i,j,n,k;
	cin>>n>>k;
	int a[n] = {0};
	int d;
	int x;
	for(i=0; i<k; i++){
		cin>>d;
		for(j=0; j<d; j++){
			cin>>x;
			a[x-1] = 1;
		}
	}
	int c = 0;
	for(i=0; i<n; i++){
		if(a[i] == 0){
			c++;
		}
	}
	cout << c ;
	return 0;
}

Measured memory_bytes: 3636
#include <stdio.h>

int main(void) {
	int a,b,x;
	scanf("%d",&a);
	scanf("%d",&b);
	scanf("%d",&x);
		if(a+b<x){
			printf("NO");
		}else if(x < a){
			printf("NO");
		}else{
			printf("YES");
		}	
	return 0;
}


Measured memory_bytes: 128
#include <algorithm>
#include <iostream>
#include <vector>
using ll=long long;
#define rep(i,a,b) for(ll i=a;i<ll(b);i++)
#define repr(i,a,b) for(ll i=a;i>=ll(b);i--)
#define endl "\n"
#define ALL(x) x.begin(),x.end()
#define ALLR(x) x.rbegin(),x.rend()
using namespace std;

int N, ans;
int main() {
	cin >> N;
	vector<int> L(N);
	rep(i, 0, N) cin >> L[i];

	sort(ALL(L));
	rep(a, 0, N-2){
		rep(b, a+1, N-1){
			rep(c, b+1, N){
				if(L[a] == L[b] || L[b] == L[c] || L[c] == L[a]) continue;
				if(L[c] < L[a]+L[b]) ans++;
			}
		}
	}
	cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3228
N,*A = `dd`.split.map(&:to_i)

def r(as)
  s = 0
  sgn = 1
  ans = 0
  as.each{ |a|
    sgn *= -1
    s = -s
    a *= sgn
    ans += [1-(s+a), 0].max
    s = [1,s+a].max
  }
  ans
end

p [r(A), r(A.map{ |a| -a })].min

Measured memory_bytes: 12804
#include<bits/stdc++.h>
#define r(i,n) for(int i=0;i<n;i++)
using namespace std;
int h,w,sum,cnt;
int dx[]={0,0,1,-1};
int dy[]={1,-1,0,0};
bool used[99][99];
string s[99];
void dfs(int y,int x){
  used[y][x]=1;
  if(s[y][x]=='*')cnt++;
  if(cnt==sum)return;
  r(i,4){
    int yy=y+dy[i];
    int xx=x+dx[i];
    if(yy<0||xx<0||yy>=h||xx>=w)continue;
    if(used[yy][xx]||s[yy][xx]=='.')continue;
    dfs(yy,xx);
    if(cnt==sum)return;
  }
}
int main(){
  cin>>h>>w;
  r(i,h)cin>>s[i];
  r(i,h)r(j,w)if(((i==0||i==h-1)||(i%2==0&&j!=w/2)||(i%2&&i%4==3&&(j==w/2-1||j==w/2+1))||(i%2&&i%4==1&&(j==0||j==w-1)))&&s[i][j]=='.')s[i][j]='#';

  r(i,h)r(j,w)if(s[i][j]=='*')sum++;

  r(i,h)r(j,w)if(s[i][j]=='@')dfs(i,j);

  r(i,h)r(j,w)if(s[i][j]=='#'&&!used[i][j])s[i][j]='.';

  r(i,h)cout<<s[i]<<endl;
}

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

bool check(char s){
    if(s=='A' or s=='T' or s=='C' or s=='G')
        return true;
    else
        return false;
}

int main(void)
{
    string S;
    cin >> S;
    int max{0};
    for(int start=0; start<S.size(); ++start){
            if(check(char(S[start]))){
                for(int end=start; end <S.size(); ++end){
                    if(check(char(S[end]))){
                        int len = end-start+1;
                        if(len>max)
                            max = len;
                    }
                    else{
                        break;
                    }

                }
            }
    }

    cout << max << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
typedef  long long ll;
typedef vector<int> vi;
typedef vector<pair<int, int> > vii;
typedef vector<vector<int> > vvi;
#define clr(a, b) memset(a, b, sizeof(a))
#define pb push_back
#define mkp make_pair
#define forn(i, n) for(int i=0; i<(int)n; ++i)
#define forab(i, a, b) for(int i=(int)a; i<(int)b; ++i)

const int inf = (int)1e6+5;
const int nax = (int)3e5+5;

void compute(){
    string s; cin>>s;
    int n = s.length();
    ll res = 0;
    int zeroes = 0, ones = 0;
    forn(i, n){
        if(s[i] == '0') ++zeroes;
        else ++ones;
    }
    res = 2*min(ones, zeroes);
    cout<<res<<"\n";
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    //    int t;
    //    cin>>t;
    //    while(t--)
    compute();
    return 0;
}


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

int main() {
  int N;
  cin >> N;
  vector<int> B(N - 1);
  for (int i = 0; i < N - 1; ++i)
    cin >> B[i];

  vector<int> A(N);
  for (int i = 0; i < N - 1; ++i) {
    if (i == 0)
      A[i] = B[i];
    A[i + 1] = B[i];
  }

  for (int i = 0; i < N - 1; ++i) {
    if (max(A[i], A[i + 1]) != B[i])
      if (A[i] < A[i + 1])
        A[i + 1] = A[i];
      else
        A[i] = A[i + 1];
  }

  int ans = 0;
  for (int i = 0; i < N; ++i) ans += A[i];

  cout << ans << endl;
}

Measured memory_bytes: 256
import std.stdio;
import std.conv;
import std.string;
import std.typecons;
import std.algorithm;
import std.array;
import std.range;
import std.math;
import std.regex : regex;
import std.container;
import std.bigint;


void main()
{
  auto hw = readln.chomp.split.to!(int[]);
  auto c = new int[][](10, 10);
  
  foreach (i; 0..10) {
    c[i] = readln.chomp.split.to!(int[]);
  }

  int[int] cnt;
  foreach (i; 0..hw[0]) {
    auto a = readln.chomp.split.to!(int[]);
    foreach (j; 0..hw[1]) {
      cnt[a[j]]++;
    }
  }

  foreach (k; 0..10) {
    foreach (i; 0..10) {
      foreach (j; 0..10) {
        if (i == j) continue;
        c[i][j] = min(c[i][j], c[i][k] + c[k][j]);
      }
    } 
  }
  int cost;
  foreach (k; cnt.keys) {
    if (k == -1 || k == 1) continue;
    cost += c[k][1] * cnt[k];
  }

  cost.writeln;
}


Measured memory_bytes: 4092
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
 
#include <bits/stdc++.h>
 
using namespace std;
 
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
template <typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
  
#define pb push_back
#define in insert
#define f first
#define s second
#define ll long long
#define dd double
  
const int mod = 1e9 + 7;
const int N = 2e5 + 7;
const int inf = 2e9;
const ll INF = 1e18;

map<int, int> m;
int a[N];

int main() {
	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	// freopen("*.in", "r", stdin);freopen("*.out", "w", stdout);
	int n;
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		m[a[i]]++;
	}

	int cnt = 0;
	for (int i = 0; i < n; i++) {
		bool flag = 1;
		if (m[a[i]] > 1) continue;
		if (m[1] && a[i] != 1) continue; 
		for (int j = 2; j * j <= a[i]; j++) {
			if (a[i] % j == 0) {
				if (m[j] || m[a[i] / j]) {
					flag = 0;
					break;
				}
			}
		}

		if (flag) {cnt++;}
	}
	cout << cnt;
}

Measured memory_bytes: 33288
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <iomanip>
#include <utility>
#include <tuple>
#include <functional>
#include <bitset>
#include <cassert>
#include <complex>
#include <time.h>
#define ll long long
#define double long double
#define itn int
#define endl '\n'
#define co(ans) cout<<ans<<endl;
#define COYE cout<<"YES"<<endl;
#define COYe cout<<"Yes"<<endl;
#define COye cout<<"yes"<<endl;
#define CONO cout<<"NO"<<endl;
#define CONo cout<<"No"<<endl;
#define COno cout<<"no"<<endl;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define FFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define RREP(i,n)  FFOR(i,1,n)
#define ALL(V) ((V).begin(),(V).end())
#define SORT(V) sort((V).begin(),(V).end())
#define REVERSE(V) reverse((V).begin(),(V).end())
#define INF ((1LL<<62)-(1LL<<31))
#define EPS 1e-10
#define PI 3.141592653589793238
#define MOD 1000000007
#define MAX 5100000
template<class T>bool chmax(T &a,const T &b){if(a<b){a=b;return 1;}return 0;}
template<class T>bool chmin(T &a,const T &b){if(b<a){a=b;return 1;}return 0;}
using namespace std;

int main(){
  ll N,cnt=0;
  string S;
  cin>>N>>S;
  
  ll A[N],cntr=0,cntg=0,cntb=0;
  REP(i,N){
    if(S.at(i)=='R'){
      A[i]=1;
      cntr++;
    }
    if(S.at(i)=='G'){
      A[i]=2;
      cntg++;
    }
    if(S.at(i)=='B'){
      A[i]=3;
      cntb++;
    }
  }
  
  for(int i=0; i<N-2; ++i){
    for(int j=i+1; j<N-1; ++j){
      int k=2*j-i;
      if(k>=N) continue;
      
      if(A[i]+A[j]==3){
        if(A[k]==3) cnt++;
      }
      if(A[i]+A[j]==5){
        if(A[k]==1) cnt++;
      }
      if(A[i]+A[j]==4 && A[i]!=2){
        if(A[k]==2) cnt++;
      }
    }
  }
  
  
  cout<<cntr*cntg*cntb-cnt<<endl;
  return 0;
}

Measured memory_bytes: 3652
//#define _GLIBCXX_DEBUG
#include "bits/stdc++.h"

using namespace std;

//------------------------------- Type Names -------------------------------//

using i64 = int_fast64_t;

using seika = string;
//{akari : 1D, yukari : 2D, maki : 3D} vector
template <class kizuna>
using akari = vector<kizuna>;
template <class yuzuki>
using yukari = akari<akari<yuzuki>>;
template <class tsurumaki>
using maki = akari<yukari<tsurumaki>>;
//{akane : ascending order, aoi : decending order} priority queue
template <class kotonoha>
using akane = priority_queue<kotonoha, akari<kotonoha>, greater<kotonoha>>;
template <class kotonoha>
using aoi = priority_queue<kotonoha>;

//------------------------------- Libraries ---------------------------------//

//------------------------------- Dubug Functions ---------------------------//

inline void print()
{
    cout << endl;
}
template <typename First, typename... Rest>
void print(const First &first, const Rest &... rest)
{
    cout << first << ' ';
    print(rest...);
}

//------------------------------- Solver ------------------------------------//

void solve()
{
    int n;
    cin >> n;
    cout << (n + 1) / 2 << endl;
}

int main()
{
    solve();
    return 0;
}


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

using namespace std;

long long solve(int N, const vector<int>& a){
    vector<long long> pre;
    {
        priority_queue<int, vector<int>, greater<int>> qu;
        long long sum = 0;
        for(int i=0;i<N;i++){
            sum += a[i];
            qu.push(a[i]);
        }
        pre.push_back(sum);
        for(int i=0;i<N;i++){
            sum += a[i+N];
            qu.push(a[i+N]);
            sum -= qu.top(); qu.pop();
            pre.push_back(sum);
        }
    }
    vector<long long> post;
    {
        priority_queue<int> qu;
        long long sum = 0;
        for(int i=0;i<N;i++){
            sum += a[3*N-1-i];
            qu.push(a[3*N-1-i]);
        }
        post.push_back(sum);
        for(int i=0;i<N;i++){
            sum += a[2*N-1-i];
            qu.push(a[2*N-1-i]);
            sum -= qu.top(); qu.pop();
            post.push_back(sum);
        }
    }
    long long res = pre[0] - post.back();
    for(int i=1;i<pre.size();i++){
        res = max(res, pre[i] - post[post.size()-1-i]);
    }
    return res;
}

int main(){
    int N;
    while(cin >> N){
        vector<int> a(3*N);
        for(auto& t : a) cin >> t;
        cout << solve(N, a) << endl;
    }
}

Measured memory_bytes: 4460
#include <bits/stdc++.h>
using namespace std;
typedef long long  ll;
typedef vector<int> VI;
typedef vector<ll> VLL;

int main(){
    int n;
    cin >> n;
    VI a(n);
    for(int i=0; i<n; ++i){
        cin >> a[i];
    }
    sort(a.begin(),a.end());
    a.back()/=2;

    cout << accumulate(a.begin(),a.end(),0) << endl;
    return 0;
}

Measured memory_bytes: 256
def solve(N, K, A):
    MOD = 10 ** 9 + 7
    ans = 1
    if A[-1] == 0 and K & 1:
        return 0
    if A[-1] < 0 and K & 1:
        for k in range(K):
            ans *= A[~k]
            ans %= MOD
        return ans

    i, j = 0, len(A) - 1
    if K & 1:
        ans *= A[-1]
        j -= 1
    for _ in xrange(K // 2):
        if A[i] * A[i + 1] > A[j] * A[j - 1]:
            ans *= A[i]
            ans %= MOD
            ans *= A[i+1]
            ans %= MOD
            i += 2
        else:
            ans *= A[j]
            ans %= MOD
            ans *= A[j-1]
            ans %= MOD
            j -= 2

    return ans

    

N, K = map(int, raw_input().split())
A = map(int, raw_input().split())
A.sort()
print solve(N, K, A)


Measured memory_bytes: 96520
#include <iostream>
#include <fstream>
#include <vector>
#include <queue>
#include <string>
#include <limits>
#include <algorithm>
#include <map>
#include <sstream>
#include <unordered_map>

using ll = long long;
using ull = unsigned long long;
using uint = unsigned int;
static ull tenq = 1000000000;
static ull mod = tenq + 7;

using namespace std;

int main()
{
  ll N, K;
  cin >> N >> K;
  vector<pair<ll, ll>> as(N);
  for (auto i = 0; i < N; i++) {
    ll a, b;
    cin >> a >> b;
    as[i] = make_pair(a, b);
  }
  sort(as.begin(), as.end());

  ll ik = 0;
  for (auto i = 0; i < N; i++){
    ik += as[i].second;
    if (K <= ik) {
      cout << as[i].first << endl;
      break;
    }
  }

  return 0;
}


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

int main() {
    int N;
    cin>>N;
    if(N<=1) {
        cout<<0;
        return 0;
    }
    vector<int> height(N,0);
    for(int i=0;i<N;i++)
        cin>>height[i];

    int p2=0, p1 = abs(height[N-2]-height[N-1]);

    for(int i=N-3; i>=0;i--) {
        int temp = p1;
        p1 = min(p1 + abs(height[i]-height[i+1]), 
                      p2+abs(height[i]-height[i+2]));
        p2 = temp;
    }
    cout<<p1<<endl;
    return 0;
}

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

using namespace std;

using int64 = long long;

constexpr int DEBUG = 0;

class OnlineMedian {
 private:
  priority_queue<int64, vector<int64>, less<int64>> pq_less;
  priority_queue<int64, vector<int64>, greater<int64>> pq_greater;
 public:
  void Add(int64 x) {
    if (pq_less.empty() || x <= pq_less.top()) {
      pq_less.push(x); pq_less.push(x);
    } else {
      pq_greater.push(x); pq_greater.push(x);
    }
    if (pq_less.size() > pq_greater.size()) {
      int64 t = pq_less.top(); pq_less.pop(); pq_greater.push(t);
    } else if (pq_greater.size() > pq_less.size()) {
      int64 t = pq_greater.top(); pq_greater.pop(); pq_less.push(t);
    }
  }
  // Returns a median. When there are two, returns a less one.
  int64 LessMedian() { return pq_less.top(); }
  // Returns a median. When there are two, returns a greater one.
  int64 GreaterMedian() { return pq_greater.top(); }
  bool Empty() { return pq_less.empty(); }
};

class OnlineLeastAbsoluteErrors {
 private:
  OnlineMedian online_median;
  int64 sum_of_absolute_errors = 0;
 public:
  void Add(int64 x) {
    if (!online_median.Empty()) {
      if (x > online_median.GreaterMedian()) {
        sum_of_absolute_errors += x - online_median.GreaterMedian();
      } else if (x < online_median.LessMedian()) {
        sum_of_absolute_errors += online_median.LessMedian() - x;
      }
    }
    online_median.Add(x);
  }
  
  int64 SumOfAbsoluteErrors() {
    return sum_of_absolute_errors;
  }

  int64 LessMedian() {
    return online_median.LessMedian();
  }
};

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

  int num_queries;
  cin >> num_queries;

  OnlineLeastAbsoluteErrors online_lae;
  int64 base = 0;
  for (int i = 0; i < num_queries; i++) {
    int command;
    cin >> command;
    if (command == 1) {
      int64 a, b;
      cin >> a >> b;

      base += b;

      online_lae.Add(a);
    } else {
      // Output
      cout << online_lae.LessMedian() << " "
          << online_lae.SumOfAbsoluteErrors() + base << endl;
    }
  } 
}


Measured memory_bytes: 4588
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    char[] S = sc.next().toCharArray();
    for (int i = 0; i < 3; i++) S[i] = (S[i] == '1') ? '9' : '1';
    System.out.println(S);
  }
}

Measured memory_bytes: 22612
#include <iostream>
#include <cmath>
#include <string>
#include <vector>
#include <algorithm>

using namespace std;

int main(){
    int n;
    cin >> n;
    long long a[n+1],b[n];
    long long temp;
    long long total=0;
    for(int i=0; i<n+1; ++i){
        cin >> a[i];
        total += a[i];
    }
    for(int i=0; i<n; ++i) cin >> b[i];
    for(int i=0; i<n; ++i){
        temp = a[i] - b[i];
        if(temp>=0){
            a[i] = temp;
        }
        else if(temp<0){
            a[i] = 0;
            a[i+1] += temp;
            if(a[i+1]<0) a[i+1] = 0;
        }
        // cout << temp << " ";
    }
    temp = 0;
    for(int i=0; i<n+1; ++i){
        temp += a[i];
        // cout << a[i] << " ";
    }
    // cout << endl;
    cout << total - temp << endl;
    return 0;
}


Measured memory_bytes: 1792
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <iomanip>
#include <utility>
#include <tuple>
#include <functional>
#include <bitset>
#include <cassert>
#include <complex>
#include <stdio.h>
#include <time.h>
//#define int long long
#define all(a) a.begin(),a.end()
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define pb push_back
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef long double ld;
typedef complex<ld> com;
constexpr int inf = 1000000000;
constexpr ll INF = 1000000000000000000;
constexpr ld EPS = 1e-12;
constexpr ld PI = 3.141592653589793238;
template<class T, class U> inline bool chmax(T &a, const U &b) { if (a < b) { a = b; return true; } return false; }
template<class T, class U> inline bool chmin(T &a, const U &b) { if (a > b) { a = b; return true; } return false; }
ll gcd(ll n, ll m) { return (m ? gcd(m, n%m) : n); }

signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(20);

	int k;
	cin >> k;
	int ans = 0;
	for (int i = 1; i <= k; i++) {
		for (int j = 1; j <= k; j++) {
			for (int x = 1; x <= k; x++) {
				ans += gcd(gcd(i, j), x);
			}
		}
	}
	cout << ans << '\n';
}

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

int main()
{
  string S;cin >> S;
  bool flag = true;
  rep(i, S.size()) {
    if (i % 2 == 1) {
      if (S.at(i) == 'L' || S.at(i) == 'U' || S.at(i) == 'D') {
        continue;
      }
    } else {
      if (S.at(i) == 'R' || S.at(i) == 'U' || S.at(i) == 'D') {
        continue;
      }
    }
    flag = false;
  }

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

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <cassert>
#include <climits>
#include <string>
#include <bitset>
#include <cfloat>
#include <unordered_set>
#pragma GCC optimize("Ofast")
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef vector<pair<int,int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<string> > vvs;
typedef vector<vector<ll> > vvll;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define irep(it, stl) for(auto it = stl.begin(); it != stl.end(); it++)
#define drep(i,n) for(int i = (n) - 1; i >= 0; --i)
#define fin(ans) cout << (ans) << '\n'
#define STLL(s) strtoll(s.c_str(), NULL, 10)
#define mp(p,q) make_pair(p, q)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define Sort(a) sort(a.begin(), a.end())
#define Rort(a) sort(a.rbegin(), a.rend())
#define MATHPI acos(-1)
#define itn int;
#define endl '\n';
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
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;}
inline string getline(){string s; getline(cin,s); return s;}
inline void yn(const bool b){b?fin("Yes"):fin("No");}
struct io{io(){ios::sync_with_stdio(false);cin.tie(0);}};
const int INF = INT_MAX;
const ll LLINF = 1LL<<60;
const ll MOD = 1000000007;
const double EPS = 1e-9;


int main() {
    vi ans;
    int n,k;
    cin>>n>>k;
    string s;
    cin>>s;
    int pos=n;
    while(pos>0){
        // fin(pos);
        bool ch=0;
        for(int i=k;i>0&&pos-i>=0;i--){
            // cout<<pos<<" "<<s[pos-i]<<endl;
            if(s[pos-i]=='0'){
                ch=1;
                pos-=i;
                ans.pb(i);
                break;
            }
        }
        if(!ch){
            if(pos-k<=0){
                ans.pb(pos);
                break;
            } else {
                fin(-1);
                return 0;
            }
        }
    }
    reverse(all(ans));
    rep(i,ans.size()){
        if(!i)cout<<ans[i];
        else cout<<" "<<ans[i];
    }
    cout<<endl;
}


Measured memory_bytes: 1144
import math
isPrime = [1 for _ in range (10002)]
isPrime[:2] = [0, 0]
for i in range(2, 101):
    for j in range(i*i, 10001, i):
        isPrime[j] = 0
prime = []
for i in range(10001):
    if isPrime[i] == 1:
        prime.append(i)
while True:
    n = int(input())
    if n == 0:
        break
    cnt = 0
    for i in range(len(prime) + 1):
        sum = 0
        for j in range(i,len(prime)):
            sum += prime[j]
            if sum == n:
                cnt += 1
                break
            if sum > n:
                break
    print(cnt)

        

Measured memory_bytes: 7804
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define ALL(x) (x).begin(), (x).end()
typedef long long ll;
typedef pair<int, int> pii;
const int INF = 1e9;
const int MOD = 1000000007;
const double PI = acos(-1);
int dx[4] = {0,1,0,-1};
int dy[4] = {1,0,-1,0};

void solve() {
	int n, m;
	cin >> n >> m;
	vector<int> x(m), y(m);
	rep(i,m) {
		cin >> x[i] >> y[i];
		x[i]--, y[i]--;
	}
	vector<bool> is(n);
	vector<int> v(n, 1);
	is[0] = true;
	rep(i,m) {
		int a = x[i];
		int b = y[i];
		v[a]--, v[b]++;
		if (is[a]) is[b] = true;
		if (!v[a]) is[a] = false;
	}
	int ans = 0;
	rep(i,n) if (is[i]) ans++;
	cout << ans << endl;
}

int main() {
	solve();
	return 0;
}

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

#include <boost/multiprecision/cpp_int.hpp>

// increment
#define rep_n(_1, _2, _3, NAME, ...) NAME
#define rep_2(i, n) for (int(i) = 0; (i) < (int)(n); ++(i))
#define rep_3(i, initial, n) \
  for (int(i) = (int)(initial); (i) < (int)(n); ++(i))
#define rep(...) rep_n(__VA_ARGS__, rep_3, rep_2, rep_1)(__VA_ARGS__)
// decrement
#define rep_r_n(_1, _2, _3, NAME, ...) NAME
#define rep_r_2(i, n) for (int(i) = (int)(n); (i) > 0; (i)--)
#define rep_r_3(i, initial, n) \
  for (int(i) = (int)(initial); (i) > (int)(n); (i)--)
#define rep_r(...) rep_r_n(__VA_ARGS__, rep_r_3, rep_r_2)(__VA_ARGS__)
// define type definition
using namespace std;
typedef long long ll;
using mpint = boost::multiprecision::cpp_int;  // 多倍長整数（任意精度）
typedef pair<int, int> P;

// define construct variable
const double EPS = numeric_limits<double>::epsilon();
// 10^9 + 7
const ll MOD = ll(1e9) + 7;
const ll INF = ll(1e10);
const string ALPHABET = "abcdefghijklmnopqrstuvwxyz";
const double PI = acos(-1);

// define methods
// 最大公約数
ll gcd(const ll a, const ll b) { return b ? gcd(b, a % b) : a; }
// 最小公倍数
ll lcm(const ll a, const ll b) { return a / gcd(a, b) * b; }
// char -> int
int ctoi(char c) { return (int)(c - '0'); }
// 素因数分解
vector<pair<ll, ll>> prime_factorize(ll n) {
  vector<pair<ll, ll>> p;
  for (ll i = 2; i * i <= n; i++) {
    if ((n % i) != 0) continue;
    pair<ll, ll> a = make_pair(i, 0);
    while ((n % i) == 0) {
      n /= i;
      a.second += 1;
    }
    p.push_back(a);
  }

  if (n != 1) p.push_back(make_pair(n, 1));
  return p;
}
// 組み合わせの整合性を保つ（後ほど解析する）
ll modinv(ll a) {
  ll b = MOD, u = 1, v = 0;
  while (b) {
    ll t = a / b;
    a -= t * b;
    swap(a, b);
    u -= t * v;
    swap(u, v);
  }
  u %= MOD;
  if (u < 0) {
    u += MOD;
  }
  return u;
}
// 順列
ll permutation(const ll n, const ll m) {
  ll result = 1;
  for (ll i = n; i > n - m; i--) {
    result = (result * i) % MOD;
  }
  return result;
}

// 繰り返し n 乗法
ll repeat_square(const ll n, const ll x) {
  if (x == 0) return 1;
  ll res = repeat_square(n, x / 2);
  res = res * res % MOD;
  if ((x % 2) == 1) res = res * n % MOD;
  return res;
}
// 組み合わせ nCm
ll combination(ll n, ll m) {
  ll p = permutation(n, m);
  ll div = 1;
  for (ll i = 2; i <= m; i++) {
    div = (div * i) % MOD;
  }
  return (p * modinv(div)) % MOD;
}

// アルファベットの取得
string get_alphabet(ll n) {
  n--;
  return string(1, 'a' + (n % 26));
}

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

  ll ans = 0;
  if (2 * N <= M) {
    M -= N * 2;
    ans += N;
  } else {
    ll d = max(M/2, gcd(N, (M/2)));
    if (M >= d*2) {
      ans += d;
      M -= (d*2);
    }
  }
  
  
  ans += (M/4);
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3628
import java.io.IOException;
import java.io.InputStream;
import java.util.NoSuchElementException;

public class Main {

	public static void main(String[] args) {
		FScanner sc = new FScanner();
		int N = sc.nextInt();
		int[] A = new int[N];
		for (int i = 0; i < N; i++) {
			A[i] = sc.nextInt();
		}
		int[] B = new int[N];
		for (int i = 0; i < N; i++) {
			B[i] = sc.nextInt();
		}
		int[] C = new int[N - 1];
		for (int i = 0; i < N - 1; i++) {
			C[i] = sc.nextInt();
		}
		long manzoku = 0;
		int before = 0;
		for (int i = 0; i < N; i++) {
			manzoku += B[A[i] - 1];
			if (before != 0 && before + 1 == A[i]) {
				manzoku += C[before - 1];
			}
			before = A[i];
		}
		System.out.println(manzoku);
	}

}

class FScanner {
	private final InputStream in = System.in;
	private final byte[] buffer = new byte[1024];
	private int ptr = 0;
	private int buflen = 0;

	private boolean hasNextByte() {
		if (ptr < buflen) {
			return true;
		} else {
			ptr = 0;
			try {
				buflen = in.read(buffer);
			} catch (IOException e) {
				e.printStackTrace();
			}
			if (buflen <= 0) {
				return false;
			}
		}
		return true;
	}

	private int readByte() {
		if (hasNextByte())
			return buffer[ptr++];
		else
			return -1;
	}

	private static boolean isPrintableChar(int c) {
		return 33 <= c && c <= 126;
	}

	public boolean hasNext() {
		while (hasNextByte() && !isPrintableChar(buffer[ptr]))
			ptr++;
		return hasNextByte();
	}

	public String next() {
		if (!hasNext())
			throw new NoSuchElementException();
		StringBuilder sb = new StringBuilder();
		int b = readByte();
		while (isPrintableChar(b)) {
			sb.appendCodePoint(b);
			b = readByte();
		}
		return sb.toString();
	}

	public long nextLong() {
		if (!hasNext())
			throw new NoSuchElementException();
		long n = 0;
		boolean minus = false;
		int b = readByte();
		if (b == '-') {
			minus = true;
			b = readByte();
		}
		if (b < '0' || '9' < b) {
			throw new NumberFormatException();
		}
		while (true) {
			if ('0' <= b && b <= '9') {
				n *= 10;
				n += b - '0';
			} else if (b == -1 || !isPrintableChar(b)) {
				return minus ? -n : n;
			} else {
				throw new NumberFormatException();
			}
			b = readByte();
		}
	}

	public int nextInt() {
		long nl = nextLong();
		if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE)
			throw new NumberFormatException();
		return (int) nl;
	}

	public double nextDouble() {
		return Double.parseDouble(next());
	}
}

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

int main()
{
	int N;
	cin >> N;
	vector<long long> A(N),S(N),D(N); //S[i]は、A[0]+...+A[i]を表す.D[i]はA[i+1]+...+A[N-1]を表す
	cin >> A[0];
	S[0] = A[0];
	for (int i = 1; i < N; i++)
	{
		cin >> A[i];
		S[i] = S[i - 1] + A[i];
	}
	
	long long length = S[N - 1];

	for (int i = 0; i < N; i++)
	{
		D[i] = length - S[i]; 
		
	}
	long long dist = length;
	for (int i = 0; i < N; i++) 
	{
		if (dist > abs(D[i] - S[i]))
		{
			dist = abs(D[i] - S[i]);
		}
	}
	cout << dist;
}


Measured memory_bytes: 4992
#include <bits/stdc++.h>
using namespace std;
 
int main() {
 int H,W;
 cin >> H >> W;
  vector<string> vec(H);
 for(int i=0;i<H;i++){
 	cin >> vec.at(i);
 }
 for(int i=0;i<W+1;i++){
 	cout << "#" ;
 }
  cout << "#" << endl;
  for(int i=0;i<H;i++){
  	cout << "#" << vec.at(i) << "#" << endl;
  }
  for(int i=0;i<W+1;i++){
 	cout << "#" ;
 }
  cout << "#" << endl;
}

Measured memory_bytes: 256
//                             In The Name Of Allah
#include <bits/stdc++.h>
#define	ss second
#define ff first
#define use_fast ios::sync_with_stdio(false), cin.tie(0), cout.tie(0)
#define ret(n) return cout << n, 0
#define se(n) cout << setprecision(n) << fixed
#define pb push_back
#define int long long
#define ld long double
using namespace std; 
 
const int N = 1000, OO = 1e18 + 100, M = 998244353, P = 6151, SQ = 120, lg = 22;
typedef pair <int, int> pii;

int32_t main() {
    use_fast;
	int n, m;
	cin >> n >> m;
	if(m == n)
		cout << "Yes" << endl;
	else	
		cout << "No" << endl;
	return 0; 
}
/*
be carefull :
1- if not solve after 20 min, read again twice
2- after submit read the code again
3- fun with contest
4- ... 
*/	

Measured memory_bytes: 256
def main() -> None:
    n = int(input())
    a = list(map(int, input().split()))
    a.sort()

    i = 0
    j = 3 * n - 1

    ans = 0
    while True:
        j -= 1
        i += 1

        if i <= j:
            ans += a[j]
            j -= 1
        else:
            break

    print(ans)


if __name__ == '__main__':
    main()

Measured memory_bytes: 37084
#include <cstdio>
#include <cstring>
#include <algorithm>

using namespace std;

const int N=524444;

typedef long long LL;

int n,f[N],ans,g[N],h[N],e[N],nxt[N],tot;

char c;

int read()
{
    int x=0,sig=1;
    for (c=getchar();c<'0' || c>'9';c=getchar()) if (c=='-') sig=-1;
    for (;c>='0' && c<='9';c=getchar()) x=x*10+c-48;
    return x*sig;
}

void Add(int x,int y)
{
	e[++tot]=y; nxt[tot]=h[x]; h[x]=tot;
}

void dfs(int x,int y)
{
	int i,j,k;
	for (i=h[x],j=k=0;i;i=nxt[i]) if (e[i]!=y)
	{
		dfs(e[i],x);
		if ((j&f[e[i]])>0) k=max(k,g[j&f[e[i]]]+1);
		j|=f[e[i]];
	}
	//for (i=0;((1<<i)&j)>0;i++);
	//k=max(k,i);
	for (;((1<<k)&j)>0;k++);
	ans=max(ans,k);
	f[x]=1<<k;
	for (;g[j]>k;j^=(1<<g[j])) f[x]|=(1<<g[j]);
}

int main()
{
	n=read();
	for (int i=1,x,y;i<n;i++)
	{
		x=read(); y=read();
		Add(x,y); Add(y,x);
	}
	for (int i=1,j=0;i<N;i<<=1,j++) g[i]=j;
	for (int i=3;i<N;i++) if (!g[i]) g[i]=g[i-1];
	dfs(1,0);
	printf("%d\n",ans);
    return 0;
}

Measured memory_bytes: 13696
N = int(input())
S = []

for i in range(N):
  W = str(input())
  if i > 0:
    if y != W[0]:
      print("No")
      quit()
  y = W[-1]
  if W in S:
    print("No")
    quit()
  else:
    S.append(W)  
    
print("Yes")

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

using namespace std;
typedef long long ll;
const ll MOD = 1e9 + 7;

int N, A, B;

ll cpow (ll b, int e)
{
    if (e == 1) return b % MOD;
    if (e == 0) return 1;

    ll v = cpow (b, e / 2);
    v = (v * v) % MOD;
    if (e & 1) v = (v * b) % MOD;
    return v;
}

ll inv (ll b)
{
    return cpow (b, MOD - 2);
}

int main()
{
    ios_base::sync_with_stdio(0);

    cin >> N >> A >> B;

    ll res = cpow (2, N);
    res--;
    ll ctot = 1;
    for (int i = 1; i <= A; i++)
    {
        ctot = (ctot * (N - i + 1)) % MOD;
        ctot = (ctot * inv (i)) % MOD;
    }
    res = res - ctot;
    ctot = 1;
    for (int i = 1; i <= B; i++)
    {
        ctot = (ctot * (N - i + 1)) % MOD;
        ctot = (ctot * inv (i)) % MOD;
    }
    res = res - ctot;

    res = (res % MOD) + MOD;
    res = res % MOD;
    cout << res << "\n";
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
using namespace std;
char b[100000],d[100000];
int main(){
    string a;
    int n;
    while(true){
    cin>>n;
    if(n==0)
        break;
    cin>>a;
    for(int i=0;i<a.size();i++)
        d[i]=a[i];
    int dtop=a.size();
    for(int u=0;u<n;u++){
        int count=1,top=0;
        for(int i=1;i<dtop;i++){
            if(d[i-1]==d[i])
                count++;
            else{
                int c=100000;
				bool first=true;
                for(int j=0;j<6;j++){
                    if(count/c!=0||first==false){
                        b[top]=count/c+'0';
                        count%=c;
						first=false;
                        top++;
                    }
                    c/=10;
                }
                b[top]=d[i-1];
                top++;
                count=1;
            }
        }
        int c=100000;
		bool first=true;
        for(int j=0;j<6;j++){
            if(count/c!=0||first==false){
                b[top]=count/c+'0';
                count%=c;
				first=false;
                top++;
            }
            c/=10;
        }
        b[top]=d[dtop-1];
        top++;
        for(int i=0;i<top;i++)
            d[i]=b[i];
        dtop=top;
    }
    for(int i=0;i<dtop;i++)
        cout<<d[i];
    cout<<endl;
    }
    return 0;
}

Measured memory_bytes: 1272
import java.util.*;

class Main{

    int h, w, n;
    char[][] map;

    void solve(){
        Scanner sc = new Scanner(System.in);

        h = sc.nextInt();
        w = sc.nextInt();
        n = sc.nextInt();

        int sx = 0, sy = 0;
        int[][] cheese = new int[n][2];
        map = new char[h][w];
        for(int i=0; i<h; i++){
            String s = sc.next();
            for(int j=0; j<w; j++){
                map[i][j] = s.charAt(j);
                if(map[i][j]=='S'){
                    sx = j; sy = i;
                }
                if(map[i][j]-'0'>0 && map[i][j]-'0'<=n){
                    cheese[map[i][j]-'0'-1][0] = j;
                    cheese[map[i][j]-'0'-1][1] = i;
                }
            }
        }

        int cnt = 0;
        for(int i=0; i<n; i++){
            if(i==0) cnt += bfs(sx, sy, cheese[i][0], cheese[i][1]);
            else cnt += bfs(cheese[i-1][0], cheese[i-1][1], cheese[i][0], cheese[i][1]);
        }
        System.out.println(cnt);
    }

    int[] dx = {1, -1, 0, 0};
    int[] dy = {0, 0, 1, -1};
    int bfs(int sx, int sy, int gx, int gy){
        // x, y, cnt
        LinkedList<int[]> list = new LinkedList<int[]>();
        list.add(new int[]{sx, sy, 0});
        boolean[][] v = new boolean[h][w];

        while(list.size()>0){
            int[] p = list.poll();
            int x = p[0], y = p[1], cnt = p[2];

            if(x==gx && y==gy) return cnt;
            if(v[y][x]) continue;
            v[y][x] = true;
            
            for(int i=0; i<4; i++){
                int nx = x + dx[i], ny = y + dy[i];
                if(nx<0 || nx>=w || ny<0 || ny>=h) continue;
                if(map[ny][nx]!='X') list.add(new int[]{nx, ny, cnt+1});
            }
        }
        return -1;
    }

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

Measured memory_bytes: 125292
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define each(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++)
#define rng(a) a.begin(),a.end()
#define maxs(x,y) x = max(x,y)
#define mins(x,y) x = min(x,y)
#define pb push_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcount
#define uni(x) x.erase(unique(rng(x)),x.end())
#define snuke srand((unsigned)clock()+(unsigned)time(NULL));
#define df(x) int x = in()
#define dame { puts("-1"); return 0;}
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,vector<T>,greater<T> >
#define bn(x) ((1<<x)-1)
#define newline puts("")
#define v(T) vector<T>
#define vv(T) vector<vector<T>>
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
inline int in() { int x; scanf("%d",&x); return x;}
inline void priv(vi a) { rep(i,sz(a)) printf("%d%c",a[i],i==sz(a)-1?'\n':' ');}
template<typename T>istream& operator>>(istream&i,vector<T>&v)
{rep(j,sz(v))i>>v[j];return i;}
template<typename T>string join(const vector<T>&v)
{stringstream s;rep(i,sz(v))s<<' '<<v[i];return s.str().substr(1);}
template<typename T>ostream& operator<<(ostream&o,const vector<T>&v)
{if(sz(v))o<<join(v);return o;}
template<typename T1,typename T2>istream& operator>>(istream&i,pair<T1,T2>&v)
{return i>>v.fi>>v.se;}
template<typename T1,typename T2>ostream& operator<<(ostream&o,const pair<T1,T2>&v)
{return o<<v.fi<<","<<v.se;}
const int MX = 100005, INF = 1001001001;
const ll LINF = 1e18;
const double eps = 1e-10;

#define bsf __builtin_ctzll
ll gcd(ll a, ll b) {
  // a = abs(a); b = abs(b);
  if (!a || !b) return a|b;
  int t = bsf(a|b); a >>= bsf(a);
  do { b >>= bsf(b); if (a > b) swap(a, b); b -= a;} while (b);
  return a << t;
}
ll lcm(ll x, ll y) { return x/gcd(x,y)*y;}


int main() {
  int n,m;
  scanf("%d%d",&n,&m);
  vi a(n);
  cin>>a;
  int x = 0, mx = 0;
  rep(i,n) x = gcd(x,a[i]);
  rep(i,n) mx = max(mx,a[i]);
  if (m%x || m > mx) puts("IMPOSSIBLE");
  else puts("POSSIBLE");
  return 0;
}






















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

int main() {
  int n; cin >> n;
  vector<int> a(n);
  rep(i, n) cin >> a[i];
  sort(all(a));

  LL sum = a[0];
  int ans = n;
  for (int i = 1; i < n; i ++) {
    if (sum * 2 < a[i]) ans = n - i;
    sum += a[i];
  }

  cout << ans << endl;
}

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

int main(){
  int a, b, c;
  cin >> a >> b >> c;
  int mn = min(a, b);
  int mx = max(a, b);
  if(mn <= c && c <= mx) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 3624
import sys

s = sys.stdin.readline().rstrip()

def main():
    s1 = s[::2]
    s2 = s[1::2]
    res1 = s1.count('1') + s2.count('0')
    res2 = s1.count('0') + s2.count('1')
    return min(res1, res2)

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

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

#define ll long long
#define MOD 1000000007

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

	ll int n,m;
	cin>>n>>m;
	ll int a[m];
	ll int sum=0;
	for(int i=0;i<m;i++) {
		cin>>a[i];
		sum+=a[i];
	}	
	if(sum>n) cout<<"-1"<<endl;
	else cout<<n-sum<<endl;
	return 0;
}

Measured memory_bytes: 3732
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vi>;
using vvl = vector<vl>;
const int INF = 1 << 28;
const ll MOD = 1000000007;
template <class T>
bool chmax(T &a, const T &b) {
    return (a < b) ? (a = b, 1) : 0;
}
template <class T>
bool chmin(T &a, const T &b) {
    return (b < a) ? (a = b, 1) : 0;
}

struct UnionFind {
    vector<int> rank, parent, size;

    // +1 for 1-indexed nodes
    UnionFind(int n) : rank(n + 1, 0), parent(n + 1), size(n + 1, 1) {
        iota(parent.begin(), parent.end(), 0); // parent is itself
    }
    int root(int x) {
        if (x != parent[x]) {
            parent[x] = root(parent[x]);
        }
        return parent[x];
    }
    bool isSame(int x, int y) { return root(x) == root(y); }
    bool unite(int x, int y) { return link(root(x), root(y)); }
    bool link(int x, int y) {
        if (x == y)
            return false;
        if (rank[x] > rank[y]) {
            parent[y] = x;
            size[x] += size[y];
        } else {
            parent[x] = y;
            size[y] += size[x];
            if (rank[x] == rank[y]) {
                rank[y]++;
            }
        }
        return true;
    }
    int getSize(int x) { return size[root(x)]; }
};

int main() {
    int n;
    cin >> n;
    vi x(n), y(n);
    vector<tuple<int, int, int>> xy;
    vector<tuple<int, int, int>> yx;
    for (int i = 0; i < n; ++i) {
        cin >> x[i] >> y[i];
        xy.emplace_back(x[i], y[i], i);
        yx.emplace_back(y[i], x[i], i);
    }
    sort(xy.begin(), xy.end());
    UnionFind uf(n);
    for (int i = 1; i < n; ++i) {
        if (get<0>(xy[i]) == get<0>(xy[i - 1]))
            uf.unite(get<2>(xy[i]), get<2>(xy[i - 1]));
    }
    sort(yx.begin(), yx.end());
    for (int i = 1; i < n; ++i) {
        if (get<0>(yx[i]) == get<0>(yx[i - 1]))
            uf.unite(get<2>(yx[i]), get<2>(yx[i - 1]));
    }
    vector<set<int>> xs(100000);
    vector<set<int>> ys(100000);
    for (int i = 0; i < n; ++i) {
        int root = uf.root(i);
        xs[root].insert(x[i]);
        ys[root].insert(y[i]);
    }
    ll ret = 0;
    for (int i = 0; i < n; ++i) {
        ret += xs[i].size() * ys[i].size();
    }
    ret -= n;
    cout << ret << "\n";
    return 0;
}

Measured memory_bytes: 18604
#include <iostream>
#include <string>
#include <stdlib.h>
using namespace std;

int main(void) {
        int input;
    
        cin >> input;
    
        while (input > 10) {
            if (input % 10 == 7) {
                printf("Yes");
                return 0;
            }
            input /= 10;
        }
        if (input % 10 == 7) {
            printf("Yes");
        }else
        {
            printf("No");
        }
    return 0;
}

Measured memory_bytes: 3772
import sys
input = lambda: sys.stdin.readline().rstrip()
n = int(input())
a = list(map(int, input().split()))
f = 0
even = 0
odd = 0

for i in a:
    if i % 4 == 0:
        f += 1
    elif i % 2 == 0:
        even += 1
    else:
        odd += 1

even %= 2
if f - even - odd < -1:
    print('No')
else:
    print('Yes')


Measured memory_bytes: 15020
#include <bits/stdc++.h>
using namespace std;
const int inf = (1LL << 31) - 1;

// 0 - indexed
template <typename Monoid>
struct Segmenttree
{
	using F = function<Monoid(Monoid, Monoid)>;
	const Monoid e;
	const F f;

	int sz;
	vector<Monoid> seg;

	// size, operator, unit
	Segmenttree(int N, const F &f, const Monoid &e) : f(f), e(e)
	{
		sz = 1;
		while (sz < N)
			sz *= 2;
		seg.assign(2 * sz - 1, e);
	}

	void set(int k, const Monoid &x) { seg[k + sz - 1] = x; }

	void build()
	{
		for (int k = sz - 2; k >= 0; k--)
		{
			seg[k] = f(seg[2 * k + 1], seg[2 * k + 2]);
		}
	}

	void update(int k, const Monoid &x)
	{
		k += sz - 1;
		seg[k] = x;
		while (k > 0)
		{
			k = (k - 1) / 2;
			seg[k] = f(seg[k * 2 + 1], seg[k * 2 + 2]);
		}
	}

	Monoid sub_query(int a, int b, int k, int l, int r)
	{
		if (r <= a || b <= l)
			return e;

		if (a <= l && r <= b)
			return seg[k];
		else
		{
			Monoid vl = sub_query(a, b, k * 2 + 1, l, (l + r) / 2);
			Monoid vr = sub_query(a, b, k * 2 + 2, (l + r) / 2, r);
			return f(vl, vr);
		}
	}

	// [l, r)
	Monoid query(int l, int r)
	{
		return sub_query(l, r, 0, 0, sz);
	}

	Monoid operator[](const int &k) const
	{
		return seg[k + sz];
	}
};

auto Range_Minimum_Query = [](int a, int b) { return min(a, b); }; // unit = inf
auto Range_Maximum_Query = [](int a, int b) { return max(a, b); }; // unit = -inf
auto Range_Sum_Query = [](int a, int b) { return a + b; };		   // unit = 0

int main()
{
	int N, Q;
	cin >> N >> Q;
	Segmenttree<int> seg(N + 1, Range_Minimum_Query, inf);

	while (Q--)
	{
		int f;
		cin >> f;
		if (f == 1)
		{
			int l, r;
			cin >> l >> r;

			cout << seg.query(l, r + 1) << "\n";
		}
		if (f == 0)
		{
			int i, a;
			cin >> i >> a;

			seg.update(i, a);
		}
	}
}



Measured memory_bytes: 3892
#include <stdio.h>
int main(void)
{
	int n,l[1001],r[1001],i,a=0;
	scanf("%d",&n);
	for(i=0; i<n; i++){
		scanf("%d%d",&l[i],&r[i]);
		a=a+(r[i]-l[i]+1);
	}
	printf("%d\n",a);
	return 0;
}

Measured memory_bytes: 128
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")

#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#include <iomanip>


using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
typedef long double ld;

typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;

typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;

#define rep(i, a, b) for (int i=a; i<(b); i++)
#define rp(i, a) for (int i=0; i<(a); i++)
#define repd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define rpd(i,a) for (int i = (a)-1; i >= 0; i--)

#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define shandom_ruffle random_shuffle

const int MOD = 1000000007;
const ll INF = 1e18;
const int MX = 100001; //check the limits, dummy


int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    cout << std::setprecision(9);
    cout << std::fixed;

    ll x;
    cin >> x;
    if(x < 1200) cout << "ABC"<<endl;
    else cout << "ARC"<<endl;

    return 0;
}

// read the question correctly (ll vs int)
// template by super1 derived from bqi343


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

#define INF 1000000000
static const long long Q = 1000000007;

long long merge(int A[], int left, int mid, int right)
{
    long long counter = 0;
    int n1 = mid - left;
    int n2 = right - mid;
    int L[n1 + 1];
    int R[n2 + 1];
    for(int i = 0; i < n1; i++)
        L[i] = A[left + i];
    for(int i = 0; i < n2; i++)
        R[i] = A[mid + i];
    L[n1] = INF;
    R[n2] = INF;
    int i = 0;
    int j = 0;
    for(int k = left; k < right; k++)
    {
        if(L[i] <= R[j])
        {
            A[k] = L[i];
            i++;
        }
        else
        {
            counter += n1 - i;
            A[k] = R[j];
            j++;
        }
    }
    return counter;
}

long long merge_sort(int A[], int left, int right)
{
    if(left + 1 < right)
    {
        int mid = (left + right) / 2;
        long long count1 = merge_sort(A, left, mid);
        long long count2 = merge_sort(A, mid, right);
        long long count3 = merge(A, left, mid, right);
        return count1 + count2 + count3;
    }
    else return 0;
}

int main()
{
    int N;
    long long K;
    scanf("%d %lld", &N, &K);
    int A[N];
    for(int i = 0; i < N; i++)
    {
        scanf("%d", &A[i]);
    }


    long long A_inv_num = merge_sort(A, 0, N) % Q; // Aの転倒数

    int A2[N * 2];
    for(int i = 0; i < 2 * N; i++)
    {
        A2[i] = A[i % N];
    }

    long long A2A_invnum = merge(A2, 0, N, 2 * N) % Q;

    long long result = 0;
    if(K % 2 == 0)
    {
        A2A_invnum = (A2A_invnum * (K / 2)) % Q;
        A2A_invnum = (A2A_invnum * (K - 1)) % Q;
    }
    else
    {
        A2A_invnum = (A2A_invnum * ((K - 1) / 2)) % Q;
        A2A_invnum = (A2A_invnum * K) % Q;
    }
    result = (
            ((A_inv_num * K) % Q)
            + A2A_invnum
            ) % Q;

    printf("%lld\n", result);
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>

#include <string>

using namespace std;

void print(int a, int b, char str[]) {
	for (int i = a; i <= b; i++) {
		printf("%c", str[i]);
	}
	printf("\n");
}

void reverse(int a, int b, char str[]) {
	for (int i = a, j = b; i < j; i++, j--) {
		char tmp = str[i];
		str[i] = str[j];
		str[j] = tmp;
	}
}

void replace(int a, int b, char p[], char str[]) {
	for (int i = a, j = 0; i <= b; i++, j++) {
		str[i] = p[j];
	}
}

int main() {
	char str[1001];
	cin >> str;

	int q;
	cin >> q;

	for (int i = 0; i < q; i++) {
		char cmd[10], p[1000];
		int a, b;
		cin >> cmd >> a >> b;
		if (strcmp(cmd, "print") == 0) {
			print(a, b, str);
		} else if (strcmp(cmd, "reverse") == 0) {
			reverse(a, b, str);
		} else if (strcmp(cmd, "replace") == 0) {
			cin >> p;
			replace(a, b, p, str);
		}
	}
	return 0;
}

Measured memory_bytes: 1120
s = gets.chomp.to_s
t = gets.chomp.to_s

class RotatableString < String
  attr_accessor :string

  def initialize(string)
    @string = (string)
  end

  def rotate!
    @string = @string[-1] + @string[0..-2]
  end
end

answer = "No"
rotate_string = RotatableString.new(s)

s.length.times do
  if rotate_string.rotate! == t
    answer = "Yes"
    break
  end
end

puts answer

Measured memory_bytes: 1788