akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cassert>
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define rep(i,n) FOR(i,0,n)
#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define vint vector<int>
#define vdouble vector<double>
#define vstring vector<string>
using namespace std;

#include<map>
#include<set>
#include<queue>

typedef long long ll;
typedef unsigned long long ull;

const int MAX_N = 1000000;

struct UnionFind
{
	// par[i]????????????i????±?????????¨??????????????????i == par[i]?????¨???????????????i?????¨?????????????????§??????
	// sizes[i]???????????????i?????¨?????????????????????????????°???i?????????????????§????????´???????????????????????¨??????
	vector<int> par;
	vector<int> sizes;

	UnionFind(int n) : par(n), sizes(n, 1) {
		rep(i, n) par[i] = i;
	}

	int find(int x) {
		if (x == par[x]) return x;
		return par[x] = find(par[x]); // ????????????????????????????????°???????????????????????¢???
	}

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

		if (x == y) return;

		// x?????¨???y?????¨????????§???????????????????????????
		if (sizes[x] < sizes[y]) swap(x, y);

		par[y] = x; // ??????????????????????????°??????
		sizes[x] += sizes[y];
		sizes[y] = 0;  // sizes[y]????????????????????¨???????????§0?????\????????????????????????
	}

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

	int size(int x) {
		return sizes[find(x)];
	}
};

int N, M, Q;

int main() {

	cin >> N >> M;
	UnionFind uf(N);
	rep(i, M){
		int f1, f2; cin >> f1 >> f2;
		uf.unite(f1, f2);
	}
	cin >> Q;
	rep(i, Q)
	{
		int f1, f2; cin >> f1 >> f2;
		cout << (uf.same(f1, f2) ? "yes" : "no") << endl;
	}

}

Measured memory_bytes: 3616
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**6)

def dfs(v,p):
    for i in tree[v]:
        if i==p:
            continue
        res[i]+=res[v]
        dfs(i,v)

n,q = map(int, input().split())
tree = [[] for _ in range(n)]
for i in range(n-1):
    a,b = map(int,input().split())
    tree[a-1].append(b-1)
    tree[b-1].append(a-1)

res = [0]*n
for i in range(q):
    p,x = map(int,input().split())
    res[p-1] += x

dfs(0,-1)
print(*res)

Measured memory_bytes: 230960
#pragma target("avx")
#pragma optimize("O3")
#include<bits/stdc++.h>
using ll = int_fast64_t;
using P = std::pair<ll,ll>;
using PP = std::pair<ll,P>;
using V = std::vector<ll>;
template<typename T> using pq = std::priority_queue<T>;
template<typename T> using rpq = std::priority_queue<T, std::vector<T>, std::greater<T>>;

#define REP(i,b,e) for(ll i=b; i<e; i++)
#define ALL(vec) vec.begin(),vec.end()
#define PRINT(vec) printf("[ ");for(auto &i:vec)printf("%ld ",i);puts("]");
#define SCAN(vec) for(auto &i:vec)scanf("%ld",&i)
#define fi first
#define se second

const int MOD = 1e9+7;
const ll INF = 1e18;
int dx[] = {0, 1, 0, -1, 1, 1, -1, -1}, dy[] = {1, 0, -1, 0, 1, -1, -1, 1};

int main(){
	int n, s;
	scanf("%d %d", &n, &s);
	int ans = 0;
	REP(i, 0, n+1) REP(j, 0, n+1) {
	    if(0<=s-i-j && s-i-j<=n) ans++;
	}
	printf("%d\n", ans);
	return 0;
}



Measured memory_bytes: 3792
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep2(i,m,n) for(int (i)=(m);(i)<(n);(i)++)
const ll INF = 1LL<<60;

const int mod = 1000003;
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const {
    mint res(*this);
    return res+=a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res-=a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res*=a;
  }
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const {
    return pow(mod-2);
  }
  mint& operator/=(const mint a) {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const {
    mint res(*this);
    return res/=a;
  }
};

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    vector<mint> prod(mod), prodinv(mod);
    prod[0]=1;
    prodinv[mod-1]=-1;
    rep2(i,1,mod)prod[i]=prod[i-1]*i;
    rep2(i,1,mod)prodinv[mod-i-1]=mint(mod-i)*prodinv[mod-i];
    ll q;cin>>q;
    rep(i,q){
        ll x,d,n;cin>>x>>d>>n;
        mint mx=mint(x),md=mint(d);
        if(d==0){cout<<mx.pow(n).x<<endl;continue;}
        mint l = mx/md;
        mint r = (mx+md*(n-1))/md;
        if(n>=mod||r.x<l.x){cout<<0<<endl;continue;}
        cout<<(prod[r.x]*prodinv[l.x-1]*md.pow(n)).x<<endl;

    }
    return 0;
}

Measured memory_bytes: 16512
use std::io::*;
use std::str::FromStr;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let mut cs = vec![vec![0; 3]; 3];
    for y in 0..3 {
        for x in 0..3 {
            cs[y][x] = read();
        }
    }
    for y1 in 0..3 {
        for y2 in y1+1..3 {
            for x1 in 0..3 {
                for x2 in x1+1..3 {
                    if cs[y1][x1] + cs[y2][x2] != cs[y1][x2] + cs[y2][x1] {
                        println!("No");
                        return;
                    }
                }
            }
        }
    }
    println!("Yes");
}

Measured memory_bytes: 4352
#include <stdio.h>

long sqrt(long p0,long p1){
  int i;
  long m=0,a=0;
  for(i=126;i>=0;i-=2){
    a=(a<<2)|(((i>=64?p0:p1)>>i)&3);
    m<<=1;
    if(a-m-1>=0){
      a-=m+1;
      m|=2;
    }
  }
  return(m>>1);
}

void rnprint(long p0,int p1,int p2){
  printf("%ld.",p0>>p1);
  p0&=((long)1<<p1)-1;
  for(;p2>0;p2--){
    p0<<=1;
    p0+=p0<<2;
    printf("%ld",p0>>p1);
    p0&=((long)1<<p1)-1;
  }
  return;
}

int main(){
  int n,i,j,k;
  long p[9][2],a,b,m=0;
  scanf("%d",&n);
  for(i=0;i<n;i++){
    for(j=0;j<2;j++){
      scanf("%ld",&p[i][j]);
    }
  }
  for(i=0;i<n-1;i++){
    for(j=i+1;j<n;j++){
      a=0;
      for(k=0;k<2;k++){
        b=p[i][k]-p[j][k];
        a+=b*b;
      }
      m+=sqrt(a<<28,0);
    }
  }
  rnprint((m<<1)/n,46,7);
  return(0);
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#include <vector>
#include <string>
using namespace std;
 
 
int main() {
  int blue, red;
  vector<string> blue_str(100), red_str(100);
  vector<int> blue_count(100), red_count(100);
  
  cin >> blue;
  for (int i = 0; i < blue; i++) { cin >> blue_str.at(i); }
  
  cin >> red;
  for (int i = 0; i < red; i++) { cin >> red_str.at(i); }
  
  /* count the number of each string. */
  for (int h = 0; h < blue; h++) {
    int b_count = 0;
    for (int i = 0; i < blue; i++) {
      if (blue_str.at(h) == blue_str.at(i)) {
        b_count++;
      }
    }
    blue_count.at(h) = b_count;
  }
  
  for (int h = 0; h < red; h++) {
    int r_count = 0;
    for (int i = 0; i < red; i++) {
      if (red_str.at(h) == red_str.at(i)){
        r_count++;
      }
    }
    red_count.at(h) = r_count;
  }
  
  /* subtract */
  int max = 0;
  for (int h = 0; h < 100; h++) {
    for (int i = 0; i < blue; i++) {
      if (blue_str.at(h) == red_str.at(i)) {
        blue_count.at(h) -= red_count.at(i);
        break;
      }
    }
    if (max < blue_count.at(h)) { max = blue_count.at(h); }
  }
  cout << max << endl;
  
  //for (int i = 0; i < 100; i++) { cout << blue_count.at(i) << " " << red_count.at(i) << endl; }
  //for (int i = 0; i < red + blue; i++) { cout << red_str.at(i) << blue_str.at(i) << endl; }
}

Measured memory_bytes: 256
#ifndef _GLIBCXX_NO_ASSERT
#include <cassert>
#endif
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#if __cplusplus >= 201103L
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
#endif
// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#if __cplusplus >= 201103L
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif
using namespace std;

#define rep(i,n) for(int i=0; i<((int)n); i++)
#define REP(i,n) for(int i=0; i<=((int)n); i++)
#define srep(i,a,n) for(int i=a; i<((int)n); i++)
#define SREP(i,a,n) for(int i=a; i<=((int)n); i++)
#define rrep(i,n) for(int i=n-1; i>=0; i--)
#define RREP(i,n) for(int i=n; i>=0; i--)
#define INF 1000000000
const int mod = INF+7;

int main(){
  string S;
  cin >> S;
  int N=S.length();
  int div=1;
  string str_pre="";
  str_pre+=S[0];
  string str="";
  str+=S[1];
  int index=2;
  while(index<=N){
    if(str==str_pre){
      str+=S[index];
    }
    else if(str!=str_pre){
      div++;
      str_pre="";
      str_pre+=str;
      str="";
      str+=S[index];
    }
    index++;
  }

  printf("%d\n", div);
}


Measured memory_bytes: 640
#include <cmath>
#include <functional>
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
#include <map>
#include <list>
#include <time.h>
#include <math.h>
#include <random>
#include <deque>
#include <queue>
#include <cassert>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>
#include <bitset>
#include <sstream>
#include <chrono>
#include <cstring>

using namespace std;

typedef long long ll;

#ifdef iq
  mt19937 rnd(228);
#else
  mt19937 rnd(chrono::high_resolution_clock::now().time_since_epoch().count());
#endif

int main() {
#ifdef iq
  freopen("a.in", "r", stdin);
#endif
  ios::sync_with_stdio(0);
  cin.tie(0);
  auto gcd = [&] (ll a, ll b) {
    while (b) {
      ll cur = a % b;
      a = b;
      b = cur;
    }
    return a;
  };
  int t;
  cin >> t;
  while (t--) {
    ll a, b, c, d;
    cin >> a >> b >> c >> d;
    if (b > a) {
      cout << "No\n";
      continue;
    }
    if (b > d) {
      cout << "No\n";
      continue;
    }
    ll x = c - b + 1;
    ll cur = gcd(b, d);
    ll ost = x % cur;
    if (ost < 0) ost += cur;
    ost = ost - a % cur;
    if (ost < 0) ost += cur;
    if (ost) x += cur - ost;
    cout << (x >= 0 ? "Yes\n" : "No\n");
  }
}


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

typedef long long ll;
#define ar array
#define vi vector<int>
#define vvi vector<vector<int>>
#define vll vector<long long>
#define all(x) (x).begin(), (x).end()
#define en '\n'
#define FILL(x, v) memset(x, v, sizeof(x))
#define pb push_back
#define fast                     \
	ios::sync_with_stdio(false); \
	cin.tie(NULL);               \
	cout.tie(NULL);
#define F_OR(i, a, b, s) for (int i = (a); ((s) > 0 ? i < (b) : i > (b)); i += (s))
#define F_OR1(e) F_OR(i, 0, e, 1)
#define F_OR2(i, e) F_OR(i, 0, e, 1)
#define F_OR3(i, b, e) F_OR(i, b, e, 1)
#define F_OR4(i, b, e, s) F_OR(i, b, e, s)
#define GET5(a, b, c, d, e, ...) e
#define F_ORC(...) GET5(__VA_ARGS__, F_OR4, F_OR3, F_OR2, F_OR1)
#define FOR(...)       \
	F_ORC(__VA_ARGS__) \
	(__VA_ARGS__)

#define E_ACH2(x, a) for (auto &x : a)
#define E_ACH3(x, y, a) for (auto &[x, y] : a)
#define E_ACH4(x, y, z, a) for (auto &[x, y, z] : a)
#define E_ACHC(...) GET5(__VA_ARGS__, E_ACH4, E_ACH3, E_ACH2)
#define EACH(...)       \
	E_ACHC(__VA_ARGS__) \
	(__VA_ARGS__)

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

int main()
{
	fast;
	int n;
	cin >> n;
	map<string, int> mp;
	FOR(n)
	{
		string s;
		cin >> s;
		mp[s]++;
	}
	int m = 0;
	for (auto p : mp)
		chmax(m, p.second);
	for (auto p : mp)
		if (p.second == m)
			cout << p.first << en;
}

Measured memory_bytes: 19264
N,M = map(int,input().split())
AB = [[int(x) for x in input().split()] for _ in range(M)]

se1 = set()
se2 = set()

for a,b in AB:
    if a>b:
        a,b = b,a
    if a==1:
        se1.add(b)
    if b==N:
        se2.add(a)

se = se1&se2
answer = 'POSSIBLE' if se else 'IMPOSSIBLE'
print(answer)


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

int main(){

    vector<int>a(5);
    int k;
    bool check=true;
    for(int i=0;i<5;i++) cin>>a.at(i);
    cin>>k;

    for(int i=0;i<5;i++){

        for(int j=i+1;j<5;j++){
            if(a.at(j)-a.at(i)>k) check=false;
        }


    }

    if(check) cout<<"Yay!"<<endl;
    else cout<<":("<<endl;


    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <string>
#include <cstring>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <cmath>
#include <iomanip>
#include <cassert>
#include <bitset>
using namespace std;

typedef pair<int, int> P;
#define rep(i, n) for (int i=0; i<(n); i++)
#define all(c) (c).begin(), (c).end()
#define uniq(c) c.erase(unique(all(c)), (c).end())
#define index(xs, x) (int)(lower_bound(all(xs), x) - xs.begin())
#define _1 first
#define _2 second
#define pb push_back
#define INF 1145141919
#define MOD 1000000007

int N, H;
int A[100000];
int B[100000];
int C[100000];
int D[100000];

int deg[401];
vector<int> G[401];
bool used[401];
bool nonzero(int x) {
  used[x] = true;
  bool ret = deg[x] != 0;
  for (int t : G[x]) if (!used[t]) ret |= nonzero(t);
  return ret;
}

void no() {
  cout << "NO\n";
  exit(0);
}

signed main() {
  ios::sync_with_stdio(false); cin.tie(0);
  cin >> N >> H;
  const int V = 2*H+1;
  int g = 0;
  rep(i, N) {
    cin >> A[i] >> B[i] >> C[i] >> D[i];
    if (C[i]==0&&D[i]==0) g++;
    if (C[i]>0&&D[i]>0) g--;
    int u = ((C[i]==0)? +A[i] : -C[i]);
    int v = ((D[i]==0)? -B[i] : +D[i]);
    //cout<<u<<"->"<<v<<"\n";
    u += H;
    v += H;
    deg[u]++;
    deg[v]--;
    G[u].pb(v);
    G[v].pb(u);
  }
  if (g <= 0) no();
  //rep(i, V) cout<<deg[i]<<",";cout<<"\n";
  int a = 0, b = 0;
  int s = 0;
  rep(i, V) {
    if (i-H > 0) {
      // -1
      if (deg[i] >= 0) a += deg[i];
      else no();
    }
    else {
      // +1
      if (deg[i] <= 0) b += -deg[i];
      else no();
    }
  }
  if (a != g || b != g) no();
  // cycle
  rep(i, V) if (!used[i] && G[i].size()) {
    if (!nonzero(i)) no();
  }
  cout << "YES\n";
  return 0;
}


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

int main()
{
	string str;
	cin >> str;
	long long ans = 0, tmp = 0;
	size_t pos = str.find('W');
	while (pos != string::npos)
	{
		ans += pos - tmp;
		tmp++;
		pos = str.find('W', pos + 1);
	}
	cout << ans << endl;
	cin >> ws;
	return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define floop(i,a,n) for (int i=a;i<n;i++)
#define rfloop(i,a,n) for (int i=n-1;i>=a;i--)
#define mloop(it,x) for(it=x.begin();it!=x.end();it++)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define sz(x) ((ll)(x).size())
#define cases ll t; cin>>t; while(t--)
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
typedef long long ll;
typedef unsigned long long int ull;
typedef vector<ll> vec;
typedef pair<ll,ll> pll;
typedef double db;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
const ll mod=1000000007;
ll pm(ll x,ll n) {ll result=1; while(n>0){if(n%2==1) result=((result%mod)*(x%mod))%mod; x=((x%mod)*(x%mod))%mod; n/=2;} return result;}
ll p(ll x,ll n) {ll result=1; while(n>0){if(n%2==1) result=result*x; x=x*x; n/=2;} return result;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
ll ncr(ll n,ll r) { ll p=1,k=1; if(n-r<r) r=n-r; if(r!=0) {while(r!=0) {p*=n; k*=r; ll temp=gcd(p,k); p/=temp; k/=temp; n--; r--;} } else p=1; return p;}
ll factorial[300000+1];
void fact(ll n) { factorial[0]=1; factorial[1]=1; floop(i,2,n+1) factorial[i] = (i * factorial[i-1]%mod) % mod; }
ll d,coeff1,coeff2; 
void euclid(ll a, ll b) { if(b==0) { d=a; coeff1=1; coeff2=0; } else { euclid(b,a%b); ll temp=coeff1; coeff1=coeff2; coeff2=temp-(a/b)*(coeff2); } }
ll modinv(ll a) { euclid(a,mod); return (coeff1%mod+mod)%mod; }
int prime[1000001]={};
int spf[1000001]={};
void sieve(ll n)
{
	prime[0]=1;
	prime[1]=1;
	for(ll i=2;i*i<=n;i++)
	{
		if(prime[i]==0)
		{
			for(ll j=i*i;j<=n;j+=i)
			{
				prime[j]=1;	
				if(spf[j]==j)
				spf[j]=i;	
			}		
		}
	}
}
/*
vec s(300000,0);
vec si(300000,1);
ll root(ll a)
{
	while(s[a]!=a)
	a=s[a];
	return a;
}
void uni(ll a,ll b)
{
	ll r1=root(a);
	ll r2=root(b);
	if(si[r1]<si[r2])
	{
		s[r1]=s[r2];
		si[r2]+=si[r1];
	}
	else
	{
		s[r2]=s[r1];
		si[r1]+=si[r2];
	}
}
vector<vec > adj(300000);
vec vis(300000,0);
vec dist(300000,0);
void dfs(ll t,ll n)
{
	vis[t]=1;
	floop(i,0,sz(adj[t]))
	{
		if(vis[adj[t][i]]==0)
		{
			dist[adj[t][i]]=dist[t]+1;
			vis[adj[t][i]]=1;
		//	sum[adj[t][i]]=sum[t]+c[t][adj[t][i]];
			dfs(adj[t][i],n);
		}
	}
}*/
struct my_comp
{
	bool operator()(pair<ll,pll> p1, pair<ll,pll> p2)
	{
		if(p1.fi!=p2.fi)
		return p1.fi>p2.fi;
		return p1.se.fi<p2.se.fi;
	}
};
//freopen("input.txt", "r", stdin);
//freopen("output.txt", "w", stdout);	
int main()
{
	ll k;
	cin>>k;
	if(k%2==0)
	{
		cout<<-1<<"\n";
		return 0;
	}
	string s="";
	string temp=to_string(k);
	floop(i,0,sz(temp))
	s+='7';
	if(stoll(s)<k)
	s+='7';
	ll cur=stoll(s);
	ll add=cur%k;
	if(add==0)
	{
		cout<<sz(s)<<"\n";
		return 0;
	}
	floop(i,1,1e7)
	{
		ll abhi=add*10+7;
		add=abhi%k;
		if(add==0)
		{	
			cout<<sz(s)+i<<"\n";
			return 0;
		}
	}
	cout<<-1<<"\n";
	return 0;
}

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

int main() {
    int N, k = 1;
    bool flg = true;
    std::cin >> N;
    while (true) {
        for (int i = 1; i < N+1; i++) {
            if (i % k == 0) {
                flg = false;
            }
        }
        if (flg) break;
        k *= 2;
        flg = true;
    }
    std::cout << k/2 << std::endl;
    return 0;
}

Measured memory_bytes: 256
from typing import Set


class UnionFind:
    """Union-Find: O(α(N))"""

    __slots__ = ["_data_size", "_first_idx", "_parents"]

    def __init__(self, data_size: int, is_zero_origin: bool = True) -> None:
        self._data_size = data_size
        self._first_idx = 0 if is_zero_origin else 1
        self._parents = [-1] * (data_size + self._first_idx)

    def __getitem__(self, x: int) -> int:
        """Find the group (root) of vertex x."""
        if self._parents[x] < 0:
            return x
        self._parents[x] = self[self._parents[x]]
        return self._parents[x]

    def __len__(self) -> int:
        """Count the number of groups (roots)."""
        return len(self.groups)

    @property
    def groups(self) -> Set[int]:
        """Return the set of groups (roots)."""
        return {
            self[x] for x in range(self._first_idx, self._data_size + self._first_idx)
        }

    def is_connected(self, x: int, y: int) -> bool:
        """Return whether two vertices x and y are connected or not."""
        return self[x] == self[y]

    def unite(self, x: int, y: int) -> None:
        """Unite two groups of vertices x and y."""
        x, y = self[x], self[y]
        if x == y:
            return
        if self._parents[x] > self._parents[y]:
            x, y = y, x
        self._parents[x] += self._parents[y]
        self._parents[y] = x

    def unite_all(self, *vertices: int) -> None:
        """Unite the groups of all of the given vertices."""
        x = vertices[0]
        for y in vertices[1:]:
            self.unite(x, y)

    def get_size(self, x: int) -> int:
        """Return the size of the group vertex x belongs."""
        return -self._parents[self[x]]


def unionfind():
    # https://judge.yosupo.jp/problem/unionfind
    N, Q, *TUV = map(int, open(0).read().split())
    tree = UnionFind(N)
    res = []
    for t, u, v in zip(*[iter(TUV)] * 3):
        if t:
            res.append(int(tree.is_connected(u, v)))
        else:
            tree.unite(u, v)
    print("\n".join(map(str, res)))


if __name__ == "__main__":
    unionfind()


Measured memory_bytes: 142888
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AtcoderTemplateForCSharp
{
    public class Program
    {
        public static void Main(string[] args)
        {
            var n = int.Parse(Console.ReadLine());

            var a = new List<long>();

            a.AddRange(Console.ReadLine().Split(' ').Select(x => long.Parse(x)));

            var ans = a.Sum() - a.LongCount();

            Console.WriteLine(ans);
        }
    }
}

Measured memory_bytes: 13408
//#define NDEBUG
 
#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <map>
#include <queue>
#include <set>
#include <tuple>
#include <cassert>
#include <unistd.h>
#include <cstdio>
#include <cstdlib>
#include <stack>
#include <random>
using namespace std;
typedef long long ll;
typedef pair<int, ll> P;
typedef tuple<int, int, int> T;
const int MN = 50500; 
const int MD = 1000003;

int n, m;
vector<P> g[MN];
vector<P> edge;

ll calc(int l, int r) {
    ll res = 1;
    while (l <= r) {
        P p = g[l][g[l].size()-1];
        l = p.first+1;
        res *= p.second; res %= MD;
    }
    return res;
}
int solve() {
    if (n % 2) return 0;
    for (int i = 0; i < n; i++) {
        g[i].clear();
    }
    edge.clear();
    for (int i = 0; i < n-1; i++) {
        g[i].push_back(P(i+1, 1));
    }
    vector<T> buf;
    buf.push_back(T(n-1, 0, n-1));
    for (int i = 0; i < m; i++) {
        int a, b;
        cin >> a >> b; a--; b--;
        if (a > b) swap(a, b);
        if ((b-a) % 2 == 0) continue;
        buf.push_back(T(b-a, a, b));
    }
    sort(buf.begin(), buf.end());
    for (T t: buf) {
        int a, b, c;
        tie(c, a, b) = t;
        edge.push_back(P(a, b));
    }
    for (P p: edge) {
        int a, b;
        tie(a, b) = p;
        ll res = calc(a, b) + calc(a+1, b-1);
        res %= MD;
        g[a].push_back(P(b, res));
    }
    return g[0][g[0].size()-1].second;
}

int main() {
    while (true) {
        cin >> n >> m;
        if (!n) break;
        cout << solve() << endl;
    }
}

Measured memory_bytes: 6184
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <functional>
#include <queue>
#include <set>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)

using namespace std;
typedef long long int lli;

int main(){
	int N,M;
	char A[50][50],B[50][50];
	cin>>N>>M;
	rep(i,N)rep(j,N)cin>>A[i][j];
	rep(i,M)rep(j,M)cin>>B[i][j];
	
	bool match=false;
	rep(k,N-M+1)rep(l,N-M+1){
		bool pmatch=true;
		rep(i,M)rep(j,M)if(B[i][j]!=A[i+k][j+l])pmatch=false;
		if(pmatch)match=true;
	}
	if(match)cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
}

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

int main(){
    int n, m;
    int a = 1;
    cin >> n >> m;
    if(n == 0 && m == 0)
    return 0;
    cout << n * (n - 1)/2 + m*(m -1)/2 << endl;
    return 0;
    
}


Measured memory_bytes: 256
N, X = map(int, input().split(' '))
A = list(map(int, input().split(' ')))

cost = max(0, A[0] + A[1] - X)
A[1] = max(0, A[1] - cost)

for i in range(2, N):
    cost += max(0, A[i - 1] + A[i] - X)
    A[i] = max(0, A[i] - max(0, A[i - 1] + A[i] - X))

print(cost)


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

int main()
{
    int n,a[101],i,j,key;
    while(scanf("%d",&n)==1)
    {
        for(i=0; i<n; i++){
            scanf("%d",&a[i]);


        }
        for(i=0; i<=n-1 ;i++){

           key=a[i];

           j = i - 1;
           while(j >= 0 && a[j] > key){
            a[j+1]=a[j];
            j--;
           }
        a[j+1] = key;
        printf("%d",a[0]);
        for(int k=1;k<=n-1;k++)
            printf(" %d",a[k]);
        printf("\n");
    }



    }
return 0;
}

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

#define pb push_back
#define ff first
#define ss second
#define all(x) (x).begin(), (x).end()
#define ll long long
#define ii pair<int,int>
#define vi vector<int>
#define vll vector<ll>
#define vii vector<ii>

using namespace std;

int32_t main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	//#ifndef ONLINE_JUDGE
	//freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);
	//#endif
	ll a,b,k;
	cin>>a>>b>>k;
	ll aux=a;
	a = max(0LL,a-k);
	k = max(0LL,k-aux);
	b = max(0LL,b-k);
	cout<<a<<" "<<b<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cmath>

using namespace std;

int main(void) {
	int i, count, bit;
	long long ans, tmp;
	string S, s;
	// get input ----------------------------------------------
	cin >> S;
	// sum ----------------------------------------------------
	ans = 0;
	count = 0;
	while (count < pow(2, S.size() - 1)) {
		s = S[0];
		tmp = stoll(s);
		for (i = 1; i < S.size(); i++) {
			bit = pow(2, i - 1);
			bit &= count;
			if (bit != 0) {
				ans += tmp;
				tmp = 0;
			}
			else {
				tmp *= 10;
			}
			s = S[i];
			tmp += stoll(s);
		}
		ans += tmp;
		count++;
	}
	// disp answer ---------------------------------------------
	cout << ans << endl;
	return 0;
}




Measured memory_bytes: 384
a,b = map(int, input().split())

if a * b < 0:
    print('Zero')
    exit()
elif a > 0 and b > 0:
    print('Positive')
    exit()
else:
    if abs(a-b) % 2 == 0:
        print('Negative')
    else:
        print('Positive')

Measured memory_bytes: 9160
#include <cstdio>
#include <algorithm>
static const int MAXN = 103;

int n, s[MAXN];

int main()
{
    scanf("%d", &n);
    for (int i = 0; i < n; ++i) scanf("%d", &s[i]);
    std::sort(s, s + n);

    int ans = 0;
    for (int i = 0; i < n; ++i) ans += s[i];

    if (ans % 10 == 0) {
        int i;
        for (i = 0; i < n; ++i) if (s[i] % 10 != 0) break;
        if (i == n) puts("0"); else printf("%d\n", ans - s[i]);
    } else {
        printf("%d\n", ans);
    }

    return 0;
}


Measured memory_bytes: 128
def existOdd(lst):
    for i in lst:
        if i%2==1:
            return False
    return True

cookie=list(map(int,input().split()))
seen=[]
res=0
while existOdd(cookie):
    seen.append(cookie)
    cookie=[cookie[1]/2+cookie[2]/2,cookie[0]/2+cookie[2]/2,cookie[0]/2+cookie[1]/2]
    if cookie in seen:
        res=-1
        break
    res+=1

print(res)


Measured memory_bytes: 9256
#include<iostream>
#include<cstring>
#include<cmath>
#include<algorithm> 
using namespace std;
int main()
{
	long long i,j;
	char s[100];
	cin>>s;
	for(i=0;i<strlen(s)-1;i++)
	{
		if(s[i]!=s[i+1])
		{
			cout<<"Yes";
			return 0;
		}
	}
	cout<<"No";
}

Measured memory_bytes: 888
#include <iostream>
#include <numeric>
#include <stdio.h>
#include <iomanip>
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
using namespace std;
using ll = long long;
#define rep(i, n) for (long long i = 0; i < (long long)(n); i++)
int Max(int(a), int(b), int(c)) {
	return max(max(a, b), c);
}
int Min(int(a), int(b), int(c)) {
	return min(min(a, b), c);
}

int main() {
	ll N,M;
	cin >> N>>M;
	vector<int> vec(M);
	for (int i = 0; i < M; i++) {
		cin >> vec.at(i);
	}
	sort(vec.begin(), vec.end());
	if (N >= M) {
		cout << 0 << endl;
	}
	else {
		
		
		vector<int> L(M - 1);
		ll an = 0;
		for (int i = 0; i < M - 1; i++) {
			L.at(i) = vec.at(i + 1) - vec.at(i);
			an += L.at(i);
		}
		sort(L.begin(), L.end());
		reverse(L.begin(), L.end());
		for (int i = 0; i < N - 1; i++) {
			an-= L.at(i);
		}
		cout << an << endl;
	}
}


Measured memory_bytes: 1024
import java.util.*;
import java.util.stream.Collectors;

public class Main {
    public static void main(String[] args) {
        final Scanner scanner = new Scanner(System.in);
        final int n = scanner.nextInt();
        scanner.nextLine();
        final Map<String, Integer> map = new HashMap<>();

        for (int i = 0; i < n; i++) {
            final String str = scanner.nextLine();
            if (!map.containsKey(str)) {
                map.put(str, 0);
            }

            map.put(str, map.get(str) + 1);
        }

        final List<Map.Entry<String, Integer>> sorted = map.entrySet()
                .stream()
                .sorted((o1, o2) -> o2.getValue() - o1.getValue())
                .collect(Collectors.toList());

        final List<String> strings = sorted.stream()
                .filter(it -> it.getValue() == sorted.get(0).getValue())
                .sorted(Comparator.comparing(Map.Entry::getKey))
                .map(Map.Entry::getKey)
                .collect(Collectors.toList());

        for (String s: strings) {
            System.out.println(s);
        }
    }
}

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

int main(){
    string s, t; cin >> s >> t;
    int n = s.length(), m = t.length(), i, j, lcs[n+1][m+1];
    for(i = 0; i <= n; i++){
        for(j = 0; j <= m; j++){
            if(i == 0 || j == 0)    lcs[i][j] = 0;
            else if(s[i-1] == t[j-1])   lcs[i][j] = lcs[i-1][j-1] + 1;
            else                        lcs[i][j] = max(lcs[i-1][j], lcs[i][j-1]);
        }
    }
    string res = ""; i = n; j = m;
    // cout << lcs[n][m] << endl;
    while(i >= 1 && j >= 1){
        if(s[i-1] == t[j-1])
            res = t[j-1] + res, i--, j--;
        else if(lcs[i][j-1] > lcs[i-1][j])    j--;
        else                                  i--;
    }
    cout << res << endl;
    return 0;
}


Measured memory_bytes: 35456
a,b,h,m=map(int,input().split())
import math
ang=abs(5.5*m-30*h)
if ang<=180:
  ang=ang/180
else:
  ang=(360-ang)/180
ans=a**2+b**2-2*a*b*math.cos(ang*math.pi)
print(ans**(1/2))


Measured memory_bytes: 9440
from heapq import heappush,heappop,heapify
from collections import deque,defaultdict,Counter
import itertools
from functools import *
from itertools import permutations,combinations,groupby
import sys
import bisect
import string
import math
import time
import random
def Golf():
    *a,=map(int,open(0))
def S_():
    return input()
def IS():
    return input().split()
def LS():
    return [i for i in input().split()]
def I():
    return int(input())
def MI():
    return map(int,input().split())
def LI():
    return [int(i) for i in input().split()]
def LI_():
    return [int(i)-1 for i in input().split()]
def NI(n):
    return [int(input()) for i in range(n)]
def NI_(n):
    return [int(input())-1 for i in range(n)]
def StoI():
    return [ord(i)-97 for i in input()]
def ItoS(nn):
    return chr(nn+97)
def LtoS(ls):
    return ''.join([chr(i+97) for i in ls])
def GI(V,E,Directed=False,index=0):
    org_inp=[]
    g=[[] for i in range(n)]
    for i in range(E):
        inp=LI()
        org_inp.append(inp)
        if index==0:
            inp[0]-=1
            inp[1]-=1
        if len(inp)==2:
            a,b=inp
            g[a].append(b)
            if not Directed:
                g[b].append(a)
        elif len(inp)==3:
            a,b,c=inp
            aa=(inp[0],inp[2])
            bb=(inp[1],inp[2])
            g[a].append(bb)
            if not Directed:
                g[b].append(aa)
    return g,org_inp
def GGI(h,w,search=None,replacement_of_found='.',mp_def={'#':1,'.':0}):
#h,w,g,sg=GGI(h,w,search=['S','G'],replacement_of_found='.',mp_def={'#':1,'.':0}) # sample usage
    mp=[1]*(w+2)
    found={}
    for i in range(h):
        s=input()
        for char in search:
            if char in s:
                found[char]=((i+1)*(w+2)+s.index(char)+1)
                mp_def[char]=mp_def[replacement_of_found]
        mp+=[1]+[mp_def[j] for j in s]+[1]
    mp+=[1]*(w+2)
    return h+2,w+2,mp,found
def bit_combination(k,n=2):
    rt=[]
    for tb in range(n**k):
        s=[tb//(n**bt)%n for bt in range(k)]
        rt+=[s]
    return rt
def show(*inp,end='\n'):
    if show_flg:
        print(*inp,end=end)
YN=['YES','NO']

mo=10**9+7
inf=float('inf')
l_alp=string.ascii_lowercase
u_alp=string.ascii_uppercase
ts=time.time()
#sys.setrecursionlimit(10**7)
input=lambda: sys.stdin.readline().rstrip()
 
def ran_input():
    import random
    n=random.randint(4,16)
    rmin,rmax=1,10
    a=[random.randint(rmin,rmax) for _ in range(n)]
    return n,a

show_flg=False
show_flg=True

ans=0

n,m=LI()
a=LI()
ac=[0]
for i in a:
    ac+=[(ac[-1]+i)%m]
c=Counter(ac)
for i,j in c.items():
    ans+=j*(j-1)//2
print(ans)

Measured memory_bytes: 63084
#include<stdio.h>
#include<stdlib.h>
#include<math.h>

int main()
{
    int N, Ra[40005], Ga[40005], Ba[40005], i, j;
    long long int sum=0;
    char S[40005];
    scanf("%d", &N);
    scanf(" %s ", S);
    if(S[N-1]=='R')
    {
        Ra[N-1]=1;
        Ga[N-1]=0;
        Ba[N-1]=0;
    }
    else if(S[N-1]=='G')
    {
        Ra[N-1]=0;
        Ga[N-1]=1;
        Ba[N-1]=0;
    }
    else
    {
        Ra[N-1]=0;
        Ga[N-1]=0;
        Ba[N-1]=1;
    }
    for(i=N-2;i>=0;i=i-1)
    {
        if(S[i]=='R')
        {
            Ra[i]=Ra[i+1]+1;
            Ga[i]=Ga[i+1];
            Ba[i]=Ba[i+1];
        }
        else if(S[i]=='G')
        {
            Ra[i]=Ra[i+1];
            Ga[i]=Ga[i+1]+1;
            Ba[i]=Ba[i+1];
        }
        else
        {
            Ra[i]=Ra[i+1];
            Ga[i]=Ga[i+1];
            Ba[i]=Ba[i+1]+1;
        }
    }
    for(i=0;i<N;i=i+1)
    {
        for(j=i+1;j<N;j=j+1)
        {
            if(S[i]==S[j])
            {
                continue;
            }
            if((S[i]=='R' && S[j]=='G') || (S[i]=='G' && S[j]=='R'))
            {
                sum = sum + Ba[j];
                if(2*j-i<=N-1 && S[2*j-i]=='B')
                {
                    sum=sum-1;
                }
            }
            else if((S[i]=='R' && S[j]=='B') || (S[i]=='B' && S[j]=='R'))
            {
                sum = sum + Ga[j];
                if(2*j-i<=N-1 && S[2*j-i]=='G')
                {
                    sum=sum-1;
                }
            }
            else if((S[i]=='G' && S[j]=='B') || (S[i]=='B' && S[j]=='G'))
            {
                sum = sum + Ra[j];
                if(2*j-i<=N-1 && S[2*j-i]=='R')
                {
                    sum=sum-1;
                }
            }
        }
    }
    printf("%lld\n", sum);
}

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

const ll mod = 1e9 + 7;

const int N = 2e5 + 5;

class UnionFind {
  int p[N], sz[N];
  public:
    UnionFind() {
      for (int i = 0; i < N; i++) {
        p[i] = i;
        sz[i] = 1;
      }
    }
    int par(int a) {
      if (p[a] == a)
        return p[a];
      else
        return p[a] = par(p[a]);
    }

    void unite(int a, int b) {
      a = par(a);
      b = par(b);
      if (a == b) return;
      if (sz[a] < sz[b]) swap(a, b);
      p[b] = a;
      sz[a] += sz[b];
      sz[b] = 1;
    }
};

int main() {
  int n, k, l;
  cin >> n >> k >> l;
  UnionFind road, rail;
  map<pair<int, int>, int> ans;
  for (int i = 0; i < k; i++) {
    int x, y;
    cin >> x >> y;
    road.unite(x, y);
  }
  for (int i = 0; i < l; i++) {
    int x, y;
    cin >> x >> y;
    rail.unite(x, y);
  }
  for (int i = 1; i <= n; i++) {
    ans[{road.par(i), rail.par(i)}] += 1;
  }
  for (int i = 1; i <= n; i++) {
    cout << ans[{road.par(i), rail.par(i)}] << " ";
  }
  cout << endl;
  return 0;
}


Measured memory_bytes: 18060
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
typedef long long ll;
template<typename T>
void print(T x) {
    cout << x << endl;
}
int main(void) {
    int A[3][3];
    bool B[3][3];
    rep(i, 3) {
        rep(j, 3) {
            cin >> A[i][j];
            B[i][j] = false;
        }
    }
    int n; cin >> n;
    rep(i, n) {
        int b; cin >> b;
        rep(i, 3) {
            rep(j, 3) {
                if(A[i][j] == b)
                    B[i][j] = true;
            }
        }
    }
    bool hit;
    rep(i, 3) {
        hit = true;
        rep(j, 3) {
            if(!B[i][j]) hit = false;
        }
        if(hit) break;
    }
    if(hit) {
        cout << "Yes";
        return 0;
    }
    rep(i, 3) {
        hit = true;
        rep(j, 3) {
            if(!B[j][i]) hit = false;
        }
        if(hit) break;
    }
    if(hit) {
        cout << "Yes";
        return 0;
    }
    if(B[0][0]&&B[1][1]&&B[2][2]) {
        cout << "Yes";
        return 0;
    }
    if(B[0][2]&&B[1][1]&&B[2][0]) {
        cout << "Yes";
        return 0;
    }
    cout << "No";
}


Measured memory_bytes: 256
use std::collections::HashSet;
use std::io::{stdin, Read};

macro_rules! parse {
    ($it: ident) => {
        $it.next().unwrap().parse().unwrap()
    };
    ($it: ident,2) => {
        (parse!($it), parse!($it))
    };
    ($it: ident,3) => {
        (parse!($it), parse!($it), parse!($it))
    };
    ($it: ident,4) => {
        (parse!($it), parse!($it), parse!($it), parse!($it))
    };
    ($it: ident, $n: expr) => {
        (&mut $it).take($n).map(|e| e.parse().unwrap()).collect();
    };
}

fn solve(s: &str) {
    let mut it = s.split_whitespace();
    let (n, m): (usize, usize) = parse!(it, 2);
    let mut g = vec![vec![]; n];
    for _ in 0..m {
        let (a, b): (usize, usize) = parse!(it, 2);
        g[a - 1].push(b - 1);
    }

    for start in 0..std::cmp::min(n, 100) {
        let mut cycles = vec![];
        let mut parents = vec![std::usize::MAX; n];
        let mut seen = vec![Unseen; n];
        seen[start] = Seen;
        dfs(&g, start, &mut seen, &mut parents, &mut cycles);
        'outer: for cycle in cycles {
            for &i in cycle.iter() {
                let mut count = 0;
                for j in g[i].iter() {
                    if cycle.contains(j) {
                        count += 1;
                    }
                }
                if count > 1 {
                    continue 'outer;
                }
            }
            println!("{}", cycle.len());
            for i in cycle {
                println!("{}", i + 1);
            }
            return;
        }
    }
    println!("{}", -1);
}

fn get_cycle(parents: &Vec<usize>, start: usize, end: usize) -> HashSet<usize> {
    let mut ret = HashSet::new();
    let mut cur = end;
    while cur != start {
        ret.insert(cur);
        cur = parents[cur];
    }
    ret.insert(start);
    ret
}

fn dfs(
    g: &Vec<Vec<usize>>,
    u: usize,
    seen: &mut Vec<State>,
    parents: &mut Vec<usize>,
    cycles: &mut Vec<HashSet<usize>>,
) {
    for &v in g[u].iter() {
        match seen[v] {
            Unseen => {
                seen[v] = Seen;
                parents[v] = u;
                dfs(g, v, seen, parents, cycles);
            }
            Seen => {
                cycles.push(get_cycle(parents, v, u));
            }
            _ => (),
        }
    }
    seen[u] = Checked;
}

#[derive(Clone, Copy, Debug)]
enum State {
    Unseen,
    Seen,
    Checked,
}
use State::*;

fn main() {
    let mut s = String::new();
    stdin().read_to_string(&mut s).unwrap();
    solve(&s);
}

#[cfg(test)]
mod tests {
    use super::*;
    #[test]
    fn test_input() {
        let s = "
        ";
        solve(s);
    }
}


Measured memory_bytes: 4476
N, K = map(int, input().split())
A = [int(i) for i in input().split()]

ans = A
for k in range(K):
    temp = [0 for _ in range(N)]
    for i in range(N):
        a = ans[i]
        temp[max(i-a, 0)] += 1
        if i + a + 1 < N:
            temp[i+a+1] -= 1

    ans[0] = temp[0]
    for j in range(1, N):
        ans[j] = ans[j-1] + temp[j]

    if ans.count(N) == N:
        break

for i in range(N):
    print(ans[i], end=" ")

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

int main(){
    string S; cin >> S;
    
    int r=0;
    int res=0;
    rep(l, S.size()) {
        while(r<S.size() && (S[r] == 'A' || S[r] == 'T' || S[r] == 'G' || S[r] == 'C')) {
            r++;
        }
        res = max(res, r - l);
        if(l == r) r++;
    } 
    cout << res << endl;
}
   

Measured memory_bytes: 256
N=int(input()) 
P = [[-1]*N for i in range(N)]
for i in range(N):
  A = int(input()) 
  for j in range(A):
    x,y=map(int, input().split())
    P[i][x-1] = y
    

def check(bit,P):
  con = False
  T = [-1]*N
  for i in range(N):
    if bit[i] == '1':
      for j in range(N):
        if P[i][j] == 1:
          if bit[j] == '0':
            return True        
        elif P[i][j] == 0:
          if bit[j] == '1':
            return True
  return False
          

cnt = 0
for i in range(2**N):
  bit = bin(i)[2:].zfill(N)
  if not check(bit,P):
    cnt = max(cnt,bit.count('1'))
    #print(bit)

    
print(cnt)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
inline void ci(void){
  return;
}
template <typename First, typename... Rest>
void ci(First& first, Rest&... rest){
  cin >> first;
  ci(rest...);
  return;
}
inline void co(void){
  cout << "\n";
  return;
}
template <typename First, typename... Rest>
void co(First first, Rest... rest){
  cout << first << " ";
  co(rest...);
  return;
}
#define ll long long
#define ld long double
#define st string
#define dl double
#define wh while
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define tp tuple
#define ft first
#define sc second
#define ve vector
#define tos to_string
#define len length
#define rt return 0
#define br break
#define con continue
#define lcm(n, m) (n * m / gcd(n, m))
#define np next_permutation
#define repi(i, m, n) for(int i=(int)(m);i<(int)(n);i++)
#define rep(i, n) repi(i, 0, n)
#define repill(i, m, n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define repll(i, n) repill(i, 0, n)
#define revi(i, m, n) for(int i=(int)(m);i>(int)(n);i--)
#define rev(i, n) revi(i, 0, n)
#define revill(i, m, n) for(ll i=(ll)(m);i>(ll)(n);i--)
#define revll(i, n) revill(i, 0, n)
#define sz(v) ((int)(v).size()) 
#define each(i, n) for(auto&& i: n)
#define all(n) (n.begin(), n.end())
#define sp(n) cout << fixed << setprecision(n)
// sqrt ルート, int 2*10^9, gcd　最大公約数
// __builtin_popcount bitの個数

int main() {
  int A, B;
  ci(A, B);
  int a = 0;
  repi(i, A, B + 1){
    st c = tos(i);
    if(c.at(0) == c.at(4) && c.at(1) == c.at(3)){
      a++;
    }
  }
  co(a);
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;   
int main()  
{ 
long long s[90];
int N;
cin>>N;
s[1]=2;
s[2]=1;
for(int i=3;i<=87;i++)
    s[i]=s[i-1]+s[i-2];
cout<<s[N+1];
system("pause");
return 0;
}


Measured memory_bytes: 504
#include<iostream>
#include<stdio.h>
using namespace std;

int main(){
	int w,h;
	int x,y;
	
	while(1)
	{
		cin>>h>>w;
		if (w==0 && h==0)
			break;
		for(y=0 ; y<h ; y++)
		{
			for(x=0 ; x<w ; x++)
			{
				if((x+y)%2==0)
					cout<<"#";
				else
					cout<<".";
			}
			cout<<endl;
		}
		cout<<endl;
	}
	return 0;
}



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

int main(){
  int N,d[60];
  int sum=0;
  cin>>N;
  for(int i=0;i<N;i++){
    cin>>d[i];
  }
  for(int i=0;i<N-1;i++){
    for(int j=i+1;j<N;j++){
      int hp=d[i]*d[j];
      sum+=hp;
    }
  }
  cout<<sum<<endl;
}

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

using namespace std;


int main() {
    int x, n; cin >> x >> n;
  if(n==0){
    cout << x << endl;
    return 0;
  }
  vector<int> p(100);
  for(int i = 0;i < n;i++){
    int t = 0;
    cin >> t;
    p[t]++;
  }
  
  for(int i = 0; i<100;i++){
    if(p[x-i]!=1){
      cout << x-i << endl;
      return 0;
    }
    if(p[x+i]!=1){
      cout << x+i << endl;
      return 0;
    }
  }
    return 0;
}


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

long long lcm(long long  a, long long b){
    long long res = 1;
    long long bigger = max(a,b);
    long long smaller = min(a,b);
    for(int i = 2; i <= max(a,b); i++){
        while(bigger % i == 0 && smaller % i == 0){
            res *= i;
            bigger /= i;
            smaller /= i;
        }
    }
    return res*bigger*smaller;
}

int main(){
    int a, b;
    cin >> a >> b;
    cout << lcm(a,b) << endl;
}

Measured memory_bytes: 508
n, k = map(int,input().split())
x = n
d = set(map(str,input().split()))
can_use = {str(i) for i in range(10)} ^ d
s_can_use = sorted(list(can_use))
'''
for i in range(9): 
    if set(list(str(x))) | can_use == can_use:
        print(n)
        break
    else:
        if s_can_use[0] == 0:
'''
for i in range(10**6):
    if set(list(str(x))) | can_use == can_use:
        print(n)
        break
    else:
        n += 1
        x = n
#print(n)

Measured memory_bytes: 3064
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int k = sc.nextInt();
		ArrayList<Integer> p = new ArrayList<Integer>();
		int pSum = 0;
		for (int i = 0; i < n; ++i) {
			int tmp = sc.nextInt();
			pSum += tmp;
			p.add(tmp);
		}
		Collections.sort(p, Comparator.reverseOrder());

		for (int i = 0; i < p.size(); ++i) {
			if (n == k) {
				break;
			}

			pSum -= p.get(i);
			--n;
		}
		System.out.println(pSum);
	}
}


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

const int INF = 2e9;
const int MAX_N = 1e5;
const int MAX_K = 100;

int dp[MAX_N];

int main(){
    int N;
    scanf("%d",&N);
    int K;
    scanf("%d",&K);
    std::vector<int> h(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%d",&h[i]);
    }

    for (int i=1; i<N; i++)
    {
        int mn = INF;
        for (int j = 1; j <= min(K, i); j++)
        {
            mn = min(mn, dp[i-j]+abs(h[i]-h[i-j]));
        }
        dp[i] = mn;
    }
    cout << dp[N-1] << endl;
    
    return 0;
}


Measured memory_bytes: 1024
s  = input()
n = len(s)


# rule 1 
def kaibun(s):
    n = len(s)
    l = s
    r = s[::-1]
    if l == r:
        return True
    else:
        return False

if kaibun(s) and kaibun(s[int((n+1)/2):]) and kaibun(s[:int((n-1)/2)]):
    print("Yes")
else:
    print("No")
    

Measured memory_bytes: 3060
#include<stdio.h>
#include<stdlib.h>

int fastDigit(int n){
  if(n <= 9) return n;
  else fastDigit(n / 10);
}

int main(void){
  int n, i, j, result=0;
  int c[10][10]={0};
  scanf("%d", &n);
  for(i=1;i<=n;i++){
    if(i%10==0){
      continue;
    }else{
      j = fastDigit(i);
      c[j][i%10]++;
    }
  }
  for(i=1;i<=9;i++){
    for(j=1;j<=9;j++){
      result += c[i][j] * c[j][i];
    }
  }
  printf("%d",result);
      
  return 0;
  
}

Measured memory_bytes: 128