akhauriyash/Code-Regression huggingface dataset:
import java.io.BufferedReader;
import java.io.InputStreamReader;

class Main {

        static BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));

        public static void main(String[] args) throws Exception{
        
            String row; 
            while ((row = reader.readLine()) != null) {
                int n = Integer.parseInt(row);
                System.out.println(rec(0, n)); 
            }

        }

        public static int rec(int sum, int n) {
            if (n == 1) {
                return sum + 2;
            }

            return rec(sum + n, n-1); 
        }

}

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

long long n, m, q, a[200000];
bool is_black[200000][7];
bool visited_1[200000][7];
bool visited_2[200000][7];
int dx[] = {1, 0, -1, 0};
int dy[] = {0, 1, 0, -1};


void visit_1(int r, int c){
    visited_1[r][c] = true;
    for(int i = 0; i < 4; i++){
        int r_ = r + dx[i];
        int c_ = c + dy[i];
        if(r_ >= 0 && r_ < m/7 && c_ >= 0 && c_ < 7 && (!is_black[r_][c_]) && (!visited_1[r_][c_])){
            visit_1(r_, c_);
        }
    }
}

void visit_2(int r, int c){
    visited_2[r][c] = true;
    for(int i = 0; i < 4; i++){
        int r_ = r + dx[i];
        int c_ = c + dy[i];
        if(r_ >= 0 && r_ < 2*m/7 && c_ >= 0 && c_ < 7 && (!is_black[r_][c_]) && (!visited_2[r_][c_])){
            visit_2(r_, c_);
        }
    }
}

int main(){
    cin >> n >> m >> q;
    if(m % 7 == 0){
    for(int i = 0; i < q; i++){
        cin >> a[i];
        is_black[a[i] / 7][a[i] % 7] = true;
        is_black[(a[i]+m)/7][a[i]%7] = true;
    }
    }else{
        m *= 7;
        for(int i = 0; i < q; i++){
            cin >> a[i];
            for(int j = 0; j < 7; j++){
                is_black[(a[i] + j*m/7)/7][(a[i]+j*m/7)%7] = true;
                is_black[(a[i] + j*m/7 + m)/7][(a[i]+j*m/7)%7] = true;
            }
        }
    }
    long long cnt_1 = 0;
    for(int i = 0; i < m/7; i++){
        for(int j = 0; j < 7; j++){
            if(!visited_1[i][j] && !is_black[i][j]){
                visit_1(i, j);
                cnt_1++;
            }
        }
    }

    long long cnt_2 = 0;
    for(int i = 0; i < 2*m/7; i++){
        for(int j = 0; j < 7; j++){
            if(!visited_2[i][j] && !is_black[i][j]){
                visit_2(i, j);
                cnt_2++;
            }
        }
    }

    cout << (cnt_2 - cnt_1) * (7 * n / m) + (2*cnt_1 - cnt_2) << endl;
    //cout << cnt_1 << endl;
    //cout << cnt_2 << endl;
    
}

Measured memory_bytes: 7680
#include<bits/stdc++.h>
using namespace std;
 
#define ll long long
#define lf long double
#define pb push_back
#define mp make_pair
#define F first
#define S second
typedef pair <ll,ll > ii;
typedef vector <ll> vi;
typedef vector <ii> vii;
typedef vector <bool> vb;
typedef vector <vector <ll> > vv;
typedef vector <vector <vector<ll> > > vvv;
typedef vector <string> vs;
typedef vector <lf> vf;
#define sz(x) (ll)(x).size()
#define tr1(x) cerr << #x << ": " << x << endl
#define tr2(x, y) cerr << #x << ": " << x << " | " << #y << ": " << y << endl
#define tr3(x,y,z) cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define tr4(x,y,z,w) cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<" | "<<#w<<": "<<w<<endl
#define trv(a) cerr<<#a<<": ";for(ll zz=0;zz<sz(a);zz++) cerr<<a[zz]<<" ";cerr<<endl
#define trii(x) cerr<<#x<<": ("<<x.F<<","<<x.S<<")\n";
#define trvii(a) cerr<<#a<<": ";for(ll zz=0;zz<sz(a);zz++) cerr<<"("<<a[zz].F<<","<<a[zz].S<<") ";cerr<<nl
#define trset(s) cerr<<#s<<": ";for(auto &i:s) cerr<<i<<" ";cerr<<"\n"
#define trsetii(s) cerr<<#s<<": ";for(auto &i:s) trii(i);
#define epsilon 0.000000001L
#define mod 1000000007ll
#define inf 9999999999999999ll
#define nl endl
#define all(x) x.begin(), x.end()
#define r_all(x) x.rbegin(), x.rend()
#define fast()  ios_base::sync_with_stdio(false);cin.tie(NULL)
#define modulo 998244353ll


int main()
{
    fast();
    ll n,m;
    cin>>n>>m;
    vv e(n,vi());
    for(ll i=0;i<m;i++)
    {
        ll u,v;
        cin>>u>>v;
        u--;v--;
        e[u].pb(v);e[v].pb(u);
    }
    vb vis(n,false);
    vi parent(n,-1);
    queue <ll> q;
    vis[0]=true;
    q.push(0);
    while(!q.empty())
    {
        ll u=q.front();
        q.pop();
        for(ll v:e[u])
        {
            if(!vis[v])
            {
                vis[v]=true;
                parent[v]=u;
                q.push(v);
            }
        }
    }
    bool possible=true;
    for(ll i=0;i<n;i++)
    {
        if(!vis[i])
            possible=false;
    }
    if(!possible)
    {
        cout<<"No\n";
        return 0;
    }
    cout<<"Yes\n";
    for(ll i=1;i<n;i++)
    {
        cout<<parent[i]+1<<"\n";
    }
}



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

int main(void){
    int a,b;
    cin>>a>>b;
    if(a==1) a+=13;
    if(b==1) b+=13;

    if(a>b) cout<<"Alice"<<endl;
    else if(a<b) cout<<"Bob"<<endl;
    else cout<<"Draw"<<endl;
}

Measured memory_bytes: 256
package main

import (
	"fmt"
)

func main() {
	var N int
	fmt.Scanf("%d", &N)
	a := make([]int, N)
	for i := 0; i < N; i++ {
		fmt.Scanf("%d", &a[i])
	}
	for i := 0; i < 30; i++ {
		z, o := 0, 0
		for j := 0; j < N; j++ {
			if a[j]&(1<<uint(i)) == 0 {
				z++
			} else {
				o++
			}
		}
		if !(o == 0 || o == 2*z || o == 2*z-1 || o == 2*z+1) {
			fmt.Println("No")
			return
		}
	}
	fmt.Println("Yes")
	return
}


Measured memory_bytes: 5504
#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp> // Common file
//#include <ext/pb_ds/tree_policy.hpp>
//#include <functional> // for less
#define PI acos(-1.0)
#define eps 1e-9
#define ll long long
#define ull unsigned long long
#define nl printf("\n")
#define sf scanf
#define pf printf
#define INF (ll)1e15
#define mod 1000000007

///#define isValid(n,m,nx,ny)nx>=0&&nx<n&&ny>=0&&ny<m
///int kx[]={1, 1, -1, -1, 2, 2, -2, -2}; //knight moves
///int ky[]={2,-2,  2, -2, 1,-1,  1, -1}; //knight moves
///int dx[]={1,-1,0,0,1,-1,1,-1};//eight direction
///int dy[]={0,0,1,-1,1,-1,-1,1};//eight direction
 
///using namespace __gnu_pbds;
using namespace std;
 
///inline double toRad(double deg){return deg*PI/180;}
///inline double toDeg(double rad){return rad*180/PI;}
///typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> new_data_set;
 
const int S=123456;
int main()
{
    #ifndef ONLINE_JUDGE
    //freopen("input.txt","r",stdin);
    #endif
    int k,s;
    while(sf("%d %d",&k,&s)==2)
    {
        ll cnt=0;
        for(int i=0;i<=k;i++)
        {
            for(int j=0;j<=k;j++)
            {
                int rem=(s-i-j);
                if(rem>=0 && rem<=k)cnt++;
            }
        }
        pf("%lld\n",cnt);
    }
    return 0;
}
 









 




























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

int main(){
  string S;
  cin >> S;
  
  int i,j,k;
  j = 0;
  k = 0;
  for(i=0;i<3;i++)
    if (S[i] == 'R'){
      j++;
      k = max(k,j);
    }
    else
      j = 0;
        
  cout << k << endl;
  
  return 0;
}

Measured memory_bytes: 3612
#include<iostream>
#include<vector>
#include<cstring>
using namespace std;
typedef long long ll;
#define ip(arr, n) for(int i=0; i<n; i++) cin>>arr[i];
#define op(arr, n) for(int i=0; i<n; i++) cout<<arr[i]<<" ";
#define fstIO ios_base::sync_with_stdio(false); cin.tie(NULL);
#define mod 1000000007
#define MAX 1002

int n,m;
ll dp[MAX][MAX];
char arr[MAX][MAX];

void bottomUp(){
    memset(dp, 0, sizeof(dp));

    dp[0][0]=1;
    for(int i=0; i<n; i++){
        for(int j=0; j<m; j++){
            if(arr[i][j] == '#'){
                dp[i][j]=0;
                continue;
            }
            if(i>0) dp[i][j] = (dp[i][j]+dp[i-1][j])%mod;
            if(j>0) dp[i][j] = (dp[i][j]+dp[i][j-1])%mod;
        }
    }
    cout<<dp[n-1][m-1]<<endl;
}
int main(){
    cin>>n>>m;
    for(int i=0; i<n; i++){
        for(int j=0; j<m; j++){
            cin>>arr[i][j];
        }
    }
    bottomUp();
    return 0;
}

Measured memory_bytes: 9088
#include <iostream>
#include <iomanip>
#include <utility>
#include <cmath>
#include <random>
#include <vector>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <string>
#include <algorithm>
using namespace std;

#define rep(i,n) for(int i = 0; i<n; ++i)
#define REP(i,n) for(int i = 1; i<=n; ++i)
#define all(x) begin(perm),end(perm)
#define showall(obj) for(auto x:obj)cout<<x<<endl;
typedef long long ll;
typedef pair<int,int> ip;
typedef pair<ll,ll> lp;
typedef vector<int> vint;
typedef vector<ll> vll;
const int inf = 100100100;
const ll INF = 1LL<<60;
const int MOD = (int)1e9 + 7;

int main(){
	int a,b,c,x,y;
	cin>>a>>b>>c>>x>>y;
	ll ans = INF; 
	for(int i = 0; i<=max(x,y); ++i){
		ll cost = c*2*i+a*max(0,(x-i))+b*max(0,(y-i));
		ans = min(ans, cost);
	}
	cout<<ans<<endl; return 0;
}


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


int main(){
    string S, T; cin >> S >> T;
    int A, B; cin >> A >> B;
    string U; cin >> U;
    if( U == S){
        cout << A - 1 << " " << B;
    }
    else{
        cout << A << " " << B-1;
    }
}

Measured memory_bytes: 256
let n, m = Scanf.scanf "%d %d " (fun x y -> x, y)

let rec rev_read_ints accu = function
  | 0 -> accu
  | k -> rev_read_ints ((Scanf.scanf "%d %d\n" (fun x y -> x-1, y-1)) :: accu) (k-1)

let xy = List.rev (rev_read_ints [] m)

let possible = Array.make n false
let () = possible.(0) <- true

let numbers = Array.make n 1

let rec solve = function
  | [] -> ()
  | (x, y) :: tl -> if possible.(x) then begin possible.(y) <- true; if numbers.(x) = 1 then possible.(x) <- false end;
    numbers.(x) <- numbers.(x) - 1; numbers.(y) <- numbers.(y) + 1; solve tl

let () = solve xy; print_int (Array.fold_left (fun x y -> x + (if y then 1 else 0)) 0 possible)

Measured memory_bytes: 10880
#include <iostream>
#include <cstring>
#include <map>
#include <set>
#include <vector>
using namespace std;

int main() {
  const int64_t mod = 1000000007;
  int H,W;
  cin >> H >> W;
  
  vector<string> grid(H);
  for(int i=0;i<H;i++){
    string line;
    cin >> line;
    grid[i] = line;
  }
  
  int64_t dp[1001][1001];
  for(int i=0;i<=H;i++){
    for(int j=0;j<=W;j++){
      dp[i][j] = 0;
    }
  }
  
  dp[1][1] = 1;
  for(int i=1;i<=H;i++){
    for(int j=1;j<=W;j++){
      if(grid[i-1][j-1] == '#'){continue;}
      if(dp[i-1][j]>=0 && dp[i][j-1]>=0){
        dp[i][j] = (dp[i][j] + dp[i-1][j]) % mod;
        dp[i][j] = (dp[i][j] + dp[i][j-1]) % mod;
      } else {
        dp[i][j] = max(dp[i-1][j],dp[i][j-1]);
      }
      
      //cout << i << "," << j << ":" << dp[i][j] << endl;
    }
  }
  
  //dp[H][W] = max(dp[H][W],(int64_t)0);

	cout << dp[H][W] << endl;
	return 0;
}

Measured memory_bytes: 9088
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N;
  int64_t S;
  cin >> N;
  S = 0;
  for(int i=0; i<N; i++){
    if((i+1) % 3 != 0 && (i+1) % 5 != 0 )
    S += i+1;
  }
  cout << S << endl;
}


Measured memory_bytes: 3636
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
int main() {
	int n, m, x, cnt1 = 0, cnt2 = 0; cin >> n >> m >> x;
	for (int i = 0; i < m; i++) {
		int p; cin >> p;
		if (p < x)cnt1++;
		else cnt2++;
	}
	cout << min(cnt1, cnt2) << endl;
}

Measured memory_bytes: 256
N, M = map(int, input().split())
A = list(map(int, input().split()))
BC = [list(map(int, input().split())) for _ in range(M)]

A.sort(reverse=True)
BC.sort(key=lambda x:x[1],reverse=True)

R=[]
n=0
for i in range(M):
    R.extend([BC[i][1]]*BC[i][0])
    n = n + BC[i][0]
    if n >= N:
        break

R=sorted(A+R, reverse=True)[:N]
print(sum(R))



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

#define REP(i,n) for(ll i=0;i<(ll)n;i++)
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define spa << " " <<
#define fi first
#define se second
#define ALL(a)  (a).begin(),(a).end()
#define ALLR(a)  (a).rbegin(),(a).rend()

using ld = long double;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;
using pll = pair<long, long>;
using pdd = pair<ld, ld>;

template<typename T> struct V : vector<T> { using vector<T>::vector; };
V() -> V<ll>;
V(size_t) -> V<ll>;
template<typename T> V(size_t, T) -> V<T>;
template<typename T> vector<T> make_vec(size_t n, T a) { return vector<T>(n, a); }
template<typename... Ts> auto make_vec(size_t n, Ts... ts) { return vector<decltype(make_vec(ts...))>(n, make_vec(ts...)); }
template<class S, class T> ostream& operator << (ostream& os, const pair<S, T> v){os << "(" << v.first << ", " << v.second << ")"; return os;}
template<typename T> ostream& operator<<(ostream &os, const vector<T> &v) { for (auto &e : v) os << e << ' '; return os; }
template<class T> ostream& operator<<(ostream& os, const vector<vector<T>> &v){ for(auto &e : v){os << e << "\n";} return os;}
struct fast_ios { fast_ios(){ cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;

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 (a>b) { a=b; return 1; } return 0; }
void fail() { cout << -1 << '\n'; exit(0); }
inline int popcount(const int x) { return __builtin_popcount(x); }
inline int popcount(const ll x) { return __builtin_popcountll(x); }
template<typename T> void debug(vector<vector<T>>&v,ll h,ll w){for(ll i=0;i<h;i++)
{cerr<<v[i][0];for(ll j=1;j<w;j++)cerr spa v[i][j];cerr<<endl;}};
template<typename T> void debug(vector<T>&v,ll n){if(n!=0)cerr<<v[0];
for(ll i=1;i<n;i++)cerr spa v[i];
cerr<<endl;};

const ll INF = (1ll<<62);
// const ld EPS   = 1e-10;
// const ld PI    = acos(-1.0);
const ll mod = (int)1e9 + 7;
//const ll mod = 998244353;

int main(){

    ll N, K;
    cin >> N >> K;
    V<ll> p(N);
    REP(i, N) cin >> p[i];
    sort(ALL(p));
    ll res = 0;
    REP(i, K) res += p[i];
    cout << res << endl;

    return 0;
}

Measured memory_bytes: 3652
import math

def main():
    IN = [int(_) for _ in input().split()]
    N = IN[0]
    T = IN[1]

    for x in range(N+1):
        for y in range(N+1):
            if y > N - x:
                continue
            z = N - y - x
            s = 10000 * x + 5000 * y + 1000 * z
            if T == s:
                print(x, y, z)
                return
    print("-1 -1 -1")
        

if __name__ == "__main__":
    main()


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

int main(){
  ll x;
  cin >> x;
  
  for(ll a=-120; a<=120; a++){
    for(ll b=-120; b<a; b++){
      if(pow(a,5)-pow(b,5) == x){
        cout << a << " " << b << endl;
        return 0;
      }
    }
  }
  
  return 0;
}


Measured memory_bytes: 4012
#include<bits/stdc++.h>    
using namespace std;
#define ll long long 
#define pi pair<ll,ll>
#define pd pair<ld,ld>
#define pb push_back
#define inf 1e16
#define mod 998244353
#define en '\n'
#define ld long double
#define ff first
#define ss second
#define ull unsigned long long 
#define fr(a,b,c) for(int a = b ; a <= c ; a ++ )
const ll MAXN = 200010;
ll pw(ll b, ll r, ll md){
	ll ans = 1;
	while(r){
		if(r&1)ans = (ans*b)%md;
		b = (b*b)%md;
		r>>=1;
	}
	return ans;
}
int main(){
	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	ll s,w;cin>>s>>w;
	if(w>=s)cout<<"unsafe\n";
	else cout<<"safe\n";
	return 0 ; 
}

Measured memory_bytes: 3648
from fractions import *

n, *a = map(int, open(0).read().split())
b = [0]
for i in a:
    b += gcd(b[-1], i),
w = m = 0
for i in range(n):
    m = max(m, gcd(w, b[-i - 2]))
    w = gcd(w, a[~i])
print(m)


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

signed main() {
    int N, C;
    cin >> N >> C;

    vector<int> s(N), t(N), c(N);
    vector<vector<int>> imos(C, vector<int> (5e5));
    for (int i = 0; i < N; i++) {
        cin >> s[i] >> t[i] >> c[i];
        s[i] *= 2;
        t[i] *= 2;
        c[i]--;

        imos[c[i]][s[i] - 1]++;
        imos[c[i]][t[i] + 1]--;
    }

    for (int i = 0; i < C; i++) {
        for (int j = 1; j < imos[i].size(); j++) {
            imos[i][j] += imos[i][j - 1];
        }
    }

    int ans = 0;
    for (int i = 0; i < imos[0].size(); i++) {
        int t = 0;
        for (int j = 0; j < C; j++) {
            t += !!imos[j][i];
        }
        ans = max(ans, t);
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 123776
#include <iostream>			//std::cout, std::cin
#include <string>			//std::string,std::to_string(C++11)
#include <vector>			//std::vector
#include <valarray>			//std::valarray
#include <algorithm>		//std::sort
#include <ctime>			//localtime_s
#include <cstdlib>			//abs
#include <cmath>			//abs,std::pow,sqrt,sin,cos,round,floor,ceil
#include <fstream>			//std::ifstream,std::ofstream
#include <iomanip>			//std::setprecision,std::setw,std::setfill
#include <random>			//std::random(C++11)
#include <numeric>			//std::accumulate
#include <functional>		//std::greater
#include <chrono>			//std::chrono(C++11)
#include <bitset>			//std::bitset
#include <queue>			//std::queue

const static double	de_PI	= 3.14159265358979323846;
const static int	de_MOD	= 1000000007;
const static int	de_MAX	= 999999999;

int main(void) {

	//std::ifstream in("123.txt");	std::cin.rdbuf(in.rdbuf());
	//std::ofstream ofs("456.csv");
	//std::chrono::system_clock::time_point t_st = std::chrono::system_clock::now();

	std::vector<int> A;
	int a = 0, b = 0;
	while (std::cin >> a) {
		std::cin >> b;
		A.push_back(std::to_string(a + b).length());
	}
	for (unsigned int i = 0; i < A.size(); i++) {
		std::cout << A[i] << std::endl;
	}

	//std::chrono::system_clock::time_point t_ed = std::chrono::system_clock::now();
	//std::cout << std::chrono::duration_cast<std::chrono::milliseconds>(t_ed - t_st).count() << "ms" << std::endl;

}

Measured memory_bytes: 3136
#include <iostream>
#include <algorithm>

using namespace std;

const int modi = 998244353;
const int maxn = 210000;

struct rec{
    int x, d;
};

rec r[maxn];
int nxt2[maxn],nxt[maxn];
int x[maxn];
int dp[maxn];

bool comp(const rec & a,const rec & b){
    return a.x < b.x;
}

//Segment tree

int seg[maxn * 3];

int pos, v;

void update(int o,int l,int r){
    if (l == r){
        seg[o] = v;
    }
    else{
        int mid = (l+r) >> 1;
        if (pos <= mid) update(o*2,l,mid);
        else update(o*2+1,mid+1,r);
        seg[o] = max(seg[o*2],seg[o*2+1]);
    }
}

int ql, qr;
int qans;

void query(int o,int l,int r){
    if (ql <= l && r <= qr){
        qans = max(qans, seg[o]);
    }
    else{
        int mid = (l + r) >> 1;
        if (ql <= mid) query(o*2,l,mid);
        if (mid < qr) query(o*2+1,mid+1,r);
    }
}

int main(int argc, const char * argv[]) {
    int n;
    cin >> n;
    for (int i = 1;i <= n;i++){
        cin >> r[i].x >> r[i].d;
        x[i] = r[i].x;
    }
    sort(r+1,r+n+1,comp);
    sort(x+1,x+n+1);
    for (int i = 1;i <= n;i++){
        nxt2[i] = lower_bound(x+1,x+n+1,r[i].d + r[i].x) - x;
    }
    nxt[n] = n+1;
    pos = n;
    v = n+1;
    update(1,1,n);
    
    for (int i = n-1;i >= 1;i--){
        pos = i;
        v = nxt2[i];
        update(1,1,n);
        
        ql = i;
        qr = nxt2[i] - 1;
        qans = 0;
        query(1,1,n);
        nxt[i] = qans;
        
        pos = i;
        v = nxt[i];
        update(1,1,n);
    }
    /*for (int i = 1;i <= n;i++){
        cout << nxt[i] << " ";
    }
    cout << endl;*/
    dp[n+1] = 1;
    for (int i = n;i >= 1;i--){
        dp[i] = (dp[nxt[i]] + dp[i+1]) % modi;
    }
    cout << dp[1] << endl;
    return 0;
}


Measured memory_bytes: 7552
import java.util.*;

public class Main{
	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int K = sc.nextInt();
		String S = sc.next();
		
		int count = 0;
		char ch = S.charAt(0);
		for(int i = 1; i < N; i++) {
			if(ch != S.charAt(i)) {
				ch = S.charAt(i);
				count++;
			}
		}
		
		int result = (N - 1) - count;
		result += (Math.min(count - 1, K))*2;
		if(count <= K)result++;
		
		System.out.println((count!=0)?Math.min(result, N - 1):N-1);
	}
}

Measured memory_bytes: 24948
#include <stdio.h>

int main() {
  int A, B; // 3 4
  char str[20]; // menampung postal code
  bool valid = true; // kita anggap semua postal code AWALNYA itu valid
  scanf("%d %d", &A, &B);
  scanf("%s", str);

  if(str[A] != '-') { // cek apakah di index A itu bukan -
    valid = false; // jika bukan, valid menjadi false
  }

  for(int i = 0; str[i] != '\0'; i++) {
    if(i != A) { // cek index selain A
      if(str[i] < '0' || str[i] > '9') { // jika dia di luar rentang 0 sampai 9
        valid = false; // valid menjadi false
        break; // keluar dari loop
      }
    }
  }

  // jika valid adalah true, puts yes, selain itu no
  (valid) ? puts("Yes") : puts("No"); 
  return 0;
}

Measured memory_bytes: 1664
#include <bits/stdc++.h>
using namespace std;
  
#define ll long long
#define all(aaa) aaa.begin(), aaa.end()

const int N = 3005, MOD = 998244353;
int dp[N], a[N];

void add(int &a, int b) {
    a += b;
    if (a >= MOD)
        a -= MOD;
}

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

    int n, s;
    cin >> n >> s;

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

    ll ans = 0;

    for (int i = 0; i < n; i++) {
        if (s - a[i] >= 0) {
            ans = (ans + dp[s - a[i]] * (ll)(n - i)) % MOD;
        }

        if (a[i] == s) {
            ans = (ans + (i + 1) * (ll)(n - i)) % MOD;
        }

        for (int j = s - a[i]; j >= 0; j--) {
            add(dp[j + a[i]], dp[j]);
        }

        add(dp[a[i]], i + 1);
    }

    cout << ans << "\n";

    return 0;   
}   

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

#define Abs(x)((x) < 0 ? (x) * -1 : (x))

#define rep(x, y) for ((x) = 0; (x) < (y); (x)++)
#define repin(x, y) for ((x) = 0; (x) <= (y); (x)++)
#define nep(x, y) for ((x) = (y) - 1; 0 <= (x); (x)--)
#define nepi(x, y, z) for ((x) = (y) - 1; (z) <= (x); (x)--)
#define repi(x, y, z) for ((x) = (z); (x) < (y); (x)++)
#define repiin(x, y, z) for ((x) = (z); (x) <= (y); (x)++)
#define reps(x, y, z) for ((x) = 0; (x) < (y); (x) += (z))
#define repis(x, y, z, s) for ((x) = (z); (x) < (y); (x) += (s))
#define repiins(x, y, z, s) for ((x) = (z); (x) <= (y); (x) += (s))
#define repit(x) for (__typeof((x).begin()) it = (x).begin(); it != (x).end(); it++)
#define repit2(x) for (__typeof((x).begin()) it2 = (x).begin(); it2 != (x).end(); it2++)
#define nepit(x) for (__typeof((x).rbegin()) it = (x).rbegin(); it != (x).rend(); it++)

#define All(x) (x).begin(),(x).end()

#define Mem0(x) memset(x, 0, sizeof(x))
#define Mem1(x) memset(x, -1, sizeof(x))

// can be applied to string type
#define Unique(v) v.resize(unique(All(v)) - v.begin())

#define peq(p0, p1)(p0.first == p1.first && p0.second == p1.second)

#define End '\n'
#define Out(x) cout<<(x)<<End
template<typename T>
void Debug(const T &val) { cerr << val << End; }
template<typename T, typename... Args>
void Debug(const T &val, Args... args) {
    cerr << val << ' ';
	Debug(std::forward<Args>(args)...);
}

template<typename T> inline bool Max(T &x, const T &y) { return x < y ? x = y, 1 : 0; }
template<typename T> inline bool Min(T &x, const T &y) { return x > y ? x = y, 1 : 0; }
template<typename T> using V = vector<T>;
template<typename T> using VV = V<V<T> >;

// can be applied to string type
#define Sort(v) sort(All(v))
#define SortR(v) sort(All(v), std::greater<__typeof(v[0])>())
// array sorters
#define Sart(a) sort(a, a + sizeof(a) / sizeof(__typeof(a[0])));
#define SartR(a) sort(a, a + sizeof(a) / sizeof(__typeof(a[0])), std::greater<__typeof(a[0])>())

#define pb push_back
#define mp make_pair
#define a first
#define b second
#define lb std::lower_bound
#define ub std::upper_bound

#define lbi(v, x) lb(All(v), (x))-v.begin()
#define ubi(v, x) ub(All(v), (x))-v.begin()

static const ll MOD = 1e9 + 7;
static const double PI = 3.141592653589793;

#define LOCAL 0

int main()
{
#if LOCAL
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
    freopen("debug.txt", "w", stderr);
#endif

    cin.tie(0);
    ios::sync_with_stdio(false);
	//std::cout.precision(18);

    long n;

	cin >> n;

	long a, b, c;
	long ans = LONG_MAX;

	long i, len = n / 2;

    repiin(i, len, 1) {
		a = i;
		b = n - a;
		c = 0;

		while (a) {
			c += (a % 10);
			a /= 10;
		}
		while (b) {
			c += (b % 10);
			b /= 10;
		}

		Min(ans, c);
	}

	Out(ans);
	
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main()
{
	//freopen("input.txt", "r", stdin);
	
	int n;
	bool cards[4][13] = {};
	char suitset[] = {'S', 'H', 'C', 'D'};
	
	cin >> n;
	for(int i = 0; i < n; i++){
		char suit;
		int num;
		cin >> suit >> num;
		switch(suit){
			case 'S':
				suit = 0;
				break;
			case 'H':
				suit = 1;
				break;
			case 'C':
				suit = 2;
				break;
			case 'D':
				suit = 3;
		}
		cards[suit][num - 1] = true;
	}
	
	
	for(int i = 0; i < 4; i++){
		for(int j = 0; j < 13; j++){
			if(!cards[i][j]){
				cout << suitset[i] << " " << (j + 1) << endl;
			}
		}
	}
	
	return 0;
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
 
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
 
typedef long long ll;
typedef vector<int> vi;
typedef unsigned long ul;
typedef vector<ll> vl;
typedef pair<int,int> pi;
typedef vector<pi> vpi;
typedef set<int> si;
typedef multiset<int> mi;
 
const ll INF = 1e18;
const int MOD = 1e9+7;

int t, n;
vector<pair<double,double>> v;

double deltaT(double r) {
	
	double mn=DBL_MAX;
	
	for(int i=0; i<n-1; ++i) mn=min(mn,(r/v[i].f)+((t-r)/v[i].s));

	double dude = (r/v[n-1].f)+((t-r)/v[n-1].s);
	
	return (mn-dude)*3600;
}

int main() {
	
	cin.tie(NULL);
	ios_base::sync_with_stdio(false);
	
	//ofstream cout ("C_output.txt");
	//ifstream cin ("fileName.txt");
 	
	int x, n;
	cin >> x >> n;
	
	vi v(n);
	for(int i=0; i<n; ++i) cin >> v[i];
	
	sort(v.begin(), v.end());
	
	if(!binary_search(v.begin(), v.end(), x)) cout << x << "\n";
	else {
		
		for(int i=1; ; ++i) {
			if(!binary_search(v.begin(), v.end(), x-i)) {
				cout << x-i << "\n";
				return 0;
			}
			else if(!binary_search(v.begin(), v.end(), x+i)) {
				cout << x+i << "\n";
				return 0;
			}
		} 
	}
	
	return 0;
}


Measured memory_bytes: 3616
#include <bits/stdc++.h>
using namespace std;
#define ll int64_t
const ll mod = 1000000007;

const ll LINF = 1e13;
const ll LLINF = 1e18;
const ll ALPHABET = 26;

template <class T>
void Swap(T& r, T& l) {
  T tmp = r;
  r = l;
  l = tmp;
}

template<typename T>
istream& operator >> (istream& is, vector<T>& vec) {
  for (T& x : vec) is >> x; //for(int i=0; i<vec.size(); i++) is >> x[i]; とかでもいい
  return is;
}


int main() {
  ll h, w;
  cin >> h >> w;

  ll n;
  cin >> n;

  vector<ll> a(n);
  cin >> a;

  ll ans = 0;
  vector<vector<ll>> ansmp(h, vector<ll>(w, 0) );
  ll count = 0;
  ll id = 1;

  for (int i = 0; i < w; i++) { //w列h行
    if (i % 2 == 0 ) {
      for (int j = 0; j < h; j++) {
        ansmp[j][i] = id;
        count++;
        if (count == a[id - 1]) {
          id++;
          count = 0;
        }
      }
    } else {
      for (int j = h - 1; j >= 0; j--) {
        ansmp[j][i] = id;
        count++;
        if (count == a[id - 1]) {
          id++;
          count = 0;
        }
      }
    }

  }


  for (int j = 0; j < h; j++) {
    for (int i = 0; i < w; i++) {
      cout << ansmp[j][i];
      if (i == w - 1)continue;
      cout << " ";
    }
    cout << endl;
  }




}




















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

//#define FILEIO

using namespace std;

const int SZ = 52;
const double EPS = 1e-9;
const int MOD = 100000008;
const int INF = ( 1 << 30 ) - 1;
const double PI = 2 * acos( 0.0 );

template <class T> T MIN(T a, T b) { return (a < b) ? a : b; }
template <class T> T MAX(T a, T b) { return (a > b) ? a : b; }
template <class T> void SWAP(T &a, T &b) { T c; c = a; a = b; b = c; }
template <class T> T GCD(T a, T b) { T c; while(b > 0) { c = a % b; a = b; b = c; } return a; }

bool CMP(int a, int b)
{
     return (a > b);
}

int main()
{
    #ifdef FILEIO
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif

    long long int n, i, j, k, r, g, b, len;
    long long int sum;
    char s[5000];

    cin >> n >> s;
    len = strlen(s);
    r = g = b = 0;
    for(i = 0; i < len; i++)
    {
        if(s[i] == 'R')
        {
            r++;
        }
        else if(s[i] == 'G')
        {
            g++;
        }
        else if(s[i] == 'B')
        {
            b++;
        }
    }
    sum = r * g * b;
    for(i = 0; i < n; i++)
    {
        for(j = i + 1; j < n; j++)
        {
            if(j < (2 * j) - i && (2 * j) - i < n)
            {
                k = (2 * j) - i;
                if(s[i] != s[j] && s[j] != s[k] && s[k] != s[i])
                {
                    sum--;
                }
            }
        }
    }
    cout << sum << endl;

    return 0;
}



Measured memory_bytes: 3600
import sys

input = sys.stdin.readline

def main():
    while True:
        h,w = map(int, input().split())
        
        if h==0 and w ==0:
            sys.exit()
        print("#" * w)
        for i in range(h-2):
            print("#" + "." * (w-2) + "#")
        print("#" * w)
        print("")
    
if __name__ == "__main__":
    main()


Measured memory_bytes: 5624
import java.util.*;
import java.math.*;
import java.io.*;
import java.lang.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        String s = sc.next();
        int max = 0;
        for (int i = 1; i < s.length()-1; i++) {
            int cnt = 0;
            StringBuffer t = new StringBuffer();
            StringBuffer u = new StringBuffer();
            for (int j = 0; j < s.length(); j++) {
                if(j < i){
                    t.append(s.charAt(j));
                }else {
                    u.append(s.charAt(j));
                }
            }
            for (char j = 'a'; j <= 'z'; j++) {
                if(t.indexOf(String.valueOf(j)) != -1 && u.indexOf(String.valueOf(j)) != -1){
                    cnt++;
                }
            }
            max = Math.max(max,cnt);
        }
        System.out.println(max);

        sc.close();
    }
}

class io{
    public static void br(){
        System.out.println("");
    }

    public static void YesNo(boolean f) {
        System.out.println(f?"Yes":"No");
    }
    public static void YESNO(boolean f) {
        System.out.println(f?"YES":"NO");
    }

}

class Algo{
    public static boolean isOdd(int n){
        return n % 2 == 1;
    }
    public static boolean isEven(int n){
        return n % 2 == 0;
    }


}



Measured memory_bytes: 23252
#include <bits/stdc++.h>
using namespace std;
int main () {
  string A, B;
  cin >> A >> B;
  int ans = 0;
  for(int i = 0; i < A.size(); i++) {
    if(!(A[i] == B[i])) {
      ans++;
    }
  }
  cout << ans << endl;
}

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

int main()
{
  int A, B, M;
  cin >> A >> B >> M;
  vector<int> a(A);
  vector<int> b(B);
  for (int i = 0; i < A; i++)
    cin >> a[i];
  for (int i = 0; i < B; i++)
    cin >> b[i];
  int minA = *min_element(a.begin(), a.end());
  int minB = *min_element(b.begin(), b.end());
  int ans = minA + minB;
  for (int i = 0; i < M; i++)
  {
    int x, y, c;
    cin >> x >> y >> c;
    x--;
    y--;
    ans = min(ans, a[x] + b[y] - c);
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define COUT(x) cout << #x << " = " << (x) << ", "
typedef long long ll;
using namespace std;
static const ll MOD = 1000000007;

int N;
vector<string> vec;

void func(string s, char c){
  if(s.size() == N){
    vec.push_back(s);
    return;
  }else{
    char tmp = c;
    for(char i = 'a'; i <= tmp; i++){
      string res = s;
      res.push_back(i);
      if(i == tmp){
	func(res, tmp + 1);
      }else{
	func(res, tmp);
      }
    }
    return;
  }
}

int main(){
  cin >> N;
  func("", 'a');
  for(auto x: vec){
    cout << x << endl;
  }
}


Measured memory_bytes: 7796
/*
START BY THE NAME OF ALMIGHTY ALLAH
THIS WONT BE ACCEPTED
STOP_GIVING_UP

██╗███████╗████████╗██╗ █████╗ ██╗  ██╗
██║██╔════╝╚══██╔══╝██║██╔══██╗██║ ██╔╝
██║███████╗   ██║   ██║███████║█████╔╝
██║╚════██║   ██║   ██║██╔══██║██╔═██╗
██║███████║   ██║   ██║██║  ██║██║  ██╗
╚═╝╚══════╝   ╚═╝   ╚═╝╚═╝  ╚═╝╚═╝  ╚═╝

*/
#include<bits/stdc++.h>
#define l(i,a,n)for(int i=a;i<n;i++)
#define pb push_back
#define in insert
#define mp make_pair
#define lw(v) sort(v.begin(),v.end());
#define hi(v) sort(v.begin(),v.end(),greater<long long>());
#define all(v) v.begin(),v.end()
#define filein freopen ("input.txt", "r", stdin)
#define fileout freopen ("output.txt", "w", stdout)
using namespace std;
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    long long t,r=1,r1=0,r2=0,k=0,a,b,c=1,m,d=0,n,e,f,x=0,g,p=0,q=0,y=0,z=0;
    vector<long long>v;
    vector<long long>u;
    set<char>s;
    std::vector<int>::iterator it;
    string  s1,s2,s3,s4;
   cin>>n>>m;
   k=n+m;
   if(k==3)
   {
       cout<<k<<endl;
   }
   else if(k==4)
   {
       cout<<2<<endl;
   }
   else if(k==5)
   {
       cout<<1<<endl;
   }


}


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

int main(){
    int N,A,bai;
    cin>>N>>A;

    bai=N-N/500*500;

    if(bai<=A){
        cout<<"Yes"<<endl;
    }
    else{
        cout<<"No"<<endl;
    }
    
}

Measured memory_bytes: 256
#include <iostream>
#include <map>
#include <algorithm>
#include <string>
#include <vector> 
#include <numeric>
#include <cmath>
#include <queue>
#include <iomanip>
#include <functional>

#define CHMAX(a,b) a = std::max(a,b)
#define CHMIN(a,b) a = std::min(a,b)
#define CHABS(a) a = std::abs(a) 
#define COUT(a) std::cout << a << std::endl
#define CERR(a) std::cerr << a << std::endl
#define FOR(n) for(lli i = 0; i < n; i++)

using namespace std;
using lli = long long int;
using pll = pair<lli, lli>;
using tlll = tuple<lli, lli, lli>;
using vll = vector<lli>;

lli mod197 = 1000000007LL;
lli INF = 10000000000000;

// ax + by = gcd(a,b) 最大公約数
template< typename T >
T extgcd(T a, T b, T& x, T& y) {
	T d = a;
	if (b != 0) {
		d = extgcd(b, a % b, y, x);
		y -= (a / b) * x;
	}
	else {
		x = 1;
		y = 0;
	}
	return d;
}


int main(void) {

	string n;
	cin >> n;

	int count = 0;
	for (char c : n)
		if (c == '2')
			count++;

	COUT(count);

	return 0;
}


Measured memory_bytes: 256
N = int(input())
AB = sorted([list(map(int,input().split())) for _ in range(N)], key = lambda x:x[1])

task_sum = 0
for i in range(N):
    task_sum += AB[i][0]
    if(task_sum>AB[i][1]):
        print("No")
        exit()
print("Yes")


Measured memory_bytes: 55264
#include <iostream>
#include <algorithm>
#include <vector>

using namespace std;

int main()
{
  int n, q, b, m, e;
  cin >> n;

  std::vector<int> A;
  int a[n];
  for(int i=0; i<n; i++){
    cin >> a[i];
    A.push_back(a[i]);
  }

  cin >> q;

  for(int i=0; i<q; i++){
    cin >> b >> m >> e;
    std::rotate(A.begin()+b, A.begin()+m, A.begin()+e);
  }

  for(int i=0; i<n; i++){
    cout << A[i];
    if(i!=n-1) cout << " ";
  }
  cout << endl;

  return 0;
}



Measured memory_bytes: 3144
#include<iostream>
#include<string>
#include<cmath>
#include<queue>
#include<map>
#include<set>
#include<list>
#include<iomanip>
#include<vector>
#include<random>
#include<functional>
#include<algorithm>
#include<stack>
#include<cstdio>
#include<bitset>
#include<unordered_map>
#include <climits>
#include<fstream>
using namespace std;
//---------------------------------------------------
//library zone!!!!!
typedef long long ll;
typedef long double ld;
#define rep(i,j) for(ll i=0;i<(long long)(j);i++)
#define all(a) (a).begin(),(a).end()
const ll Mod = 1000000007;
struct P {
	ll pos, cost;
};
bool operator<(P a, P b) { return a.cost < b.cost; }
bool operator>(P a, P b) { return a.cost > b.cost; }
struct B {
	ll to, cost;
};
struct E {
	ll from, to, cost;
};
bool operator<(E a, E b) {
	return a.cost < b.cost;
}
struct H {
	ll x, y;
};
bool operator<(H a, H b) {
	if (a.x != b.x) return a.x < b.x;
	return a.y < b.y;
}
bool operator>(H a, H b) {
	if (a.x != b.x) return a.x > b.x;
	return a.y > b.y;
}
bool operator==(H a, H b) {
	return a.x == b.x&&a.y == b.y;
}
bool operator!=(H a, H b) {
	return a.x != b.x || a.y != b.y;
}
ll gcm(ll i, ll j) {
	if (i > j) swap(i, j);
	if (i == 0) return j;
	return gcm(j%i, i);
}
ld mod_pow(ld x, ll n, ll p) {
	ld res = 1;
	while (n > 0) {
		if (n & 1) res = res * x;
		x = x * x;
		n >>= 1;
	}
	return res;
}//x^n%p
const ll Inf = 3023372036854775807;
const int inf = 1500000000;
#define int long long
//----------------------------------------------------
//++++++++++++++++++++++++++++++++++++++++++++++++++++
signed main() {
	int n,k;
	cin>>n>>k;
	if(n%k==0) cout<<0<<endl;
	else cout<<1<<endl;
}


Measured memory_bytes: 256
n = gets.to_i
x = gets.split(" ").map(&:to_f)
y = gets.split(" ").map(&:to_f)
z = []
for i in 0..n-1
    d = (x[i]-y[i]).abs
    z = z.push(d)
end
mad = 0
eud_2 = 0
sp_3 = 0
z.each {|distance|
    mad += distance
    eud_2 += distance**2
    sp_3 += distance **3
}

puts mad
puts Math.sqrt(eud_2).round(6)
puts Math.cbrt(sp_3).round(6)
puts z.max

Measured memory_bytes: 8900
#include <bits/stdc++.h>
using namespace std;
#define rep(i, s, n) for (int i = (s); i < (int)(n); i++)
#define all(v) v.begin(), v.end()
using ll = long long;
const ll MOD = 1e9+7; ll LLINF = 1LL << 60; int INF = INT_MAX;

//

int main(){
    int a,b,c,d; cin>>a>>b>>c>>d;
    while(a>0 && c>0){
        c-=b;
        a-=d;
        if(c<=0){
            cout<<"Yes"<<endl;
            break;
        }
        if(a<=0){
            cout<<"No"<<endl;
            break;
        }
        
    }
}

Measured memory_bytes: 3636
n,k = map(int, input().split())
a = list(map(int, input().split()))
a.sort(reverse=True)
MOD = 10**9+7

pos = []
neg  = []
pool = []
zeros = 0
for i in range(n):
    if a[i]>0:
        pos.append(a[i])
    if a[i]<0:
        neg.append(a[i])
    if a[i]==0:
        zeros+=1
pos.sort()
neg.sort(reverse=True)
ans = []
if len(pos)==0:
    if len(neg)<k or (zeros>0 and k%2):
        ans = [0]
    else:
        if(k%2):
            for i in range(k):
                ans.append(neg[i])
        else:
            for i in range(k):
                ans.append(neg[-i-1])
    k = 0
elif len(pos)+len(neg)<k:
    ans = [0]
else:
    if k%2== 1:
        ans.append(pos[-1])
        pos.pop()
        k-=1
    while(k):
        if len(pos)<2 and len(neg)<2:
            if zeros>0:
                ans = [0]
                k = 0
            else:
                ans.append(pos[0])
                ans.append(neg[0])
                k -= 2
            break
        elif len(pos)<2:
            ans.append(neg[-1])
            ans.append(neg[-2])
            neg.pop()
            neg.pop()
        elif len(neg)<2:
            ans.append(pos[-1])
            ans.append(pos[-2])
            pos.pop()
            pos.pop()
        else:
            if neg[-1]*neg[-2] >= pos[-1]*pos[-2]:
                ans.append(neg[-1])
                ans.append(neg[-2])
                neg.pop()
                neg.pop()   
            else:
                ans.append(pos[-1])
                ans.append(pos[-2])
                pos.pop()
                pos.pop()
        k -= 2



res = 1
for i in range(len(ans)):
    res *= ans[i]
    res %= MOD

print(res)

    
    




Measured memory_bytes: 119524
#include<bits/stdc++.h>
using namespace std;
int b[105];
int main(){
	int n;
	cin>>n;
	for(int i=1;i<=n-1;i++){
		cin>>b[i];
	}
	int sum=b[1]+b[n-1];
	for(int i=0;i<=n-2;i++){
		sum+=min(b[i],b[i+1]);
	}
	cout<<sum<<endl;
	return 0;
}

Measured memory_bytes: 256
N,D=map(int,input().split())
X=[list(map(int,input().split())) for i in range(N)]
c=0
for i in range(N-1):
    for j in range(i+1,N):
        c += (sum((a-b)**2 for a,b in zip(X[i],X[j]))**0.5).is_integer()
print(c)


Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define rep(i, start, end) for (long long i = start; i < end; ++i)
#define srt(x) sort((x).begin(), (x).end());
#define rsrt(x) sort((x).rbegin(), (x).rend());
#define deb(x) cout<<#x<<" = "<<(x)<<" (L"<<LINE<<")"<<endl;
#define vdeb(x) {cout<<#x<<" = { "; rep(i, x.size()) cout<<x[i]<<' '; cout <<'}'<<" (L"<<LINE<<")"<<endl;}
using namespace std;
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vivi = vector<vi>;
using vll = vector<long long>;
using vllvll = vector<vll>;
using vs = vector<string>;
using um = unordered_map<long long, long long>;
const long long INF = 1LL << 60;
const long long MOD = 1e9 + 7;

int main()
{
    ll V, E;
    cin >> V >> E;
    vllvll M(V, vll(V, INF));
    ll s, t, d;
    rep(i, 0, E) {
        cin >> s >> t >> d;        
        M[s][t] = d;
    }

    rep(i, 0, V) {
        M[i][i] = 0;
    }
    rep(k, 0, V) {
        rep(i, 0, V) {
            rep(j, 0, V) {
                M[i][j] = min(M[i][j], M[i][k] + M[k][j]);
            }
        }
    }

    rep(i, 0, V) {
        if(M[i][i] < 0) {
            cout << "NEGATIVE CYCLE" << endl;
            return 0;
        }
    }

    rep(i, 0, V) {
        rep(j, 0, V) {
            if (M[i][j] >= 1LL<<59)
                cout << "INF";
            else
                cout << M[i][j];
            if (j != V - 1)
                cout << ' ';
        }
        cout << endl;
    }
}


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

#define int long long
const int pinf=2e18;

int32_t main()
{
    //FILE *fptr1=freopen("in.txt","r",stdin);
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    int n,m,x;
    cin>>n>>m>>x;
    int a[n][m];
    int c[n];

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

    int mn=pinf;
    for(int i=1;i<(1<<n);i++)
    {
        vector <int> ind;
        for(int j=0;j<n;j++)
        {
            if(i&(1<<j))
                ind.push_back(j);
        }
        bool f=0;
        for(int j=0;j<m;j++)
        {
            int s=0;
            for(auto i:ind)
            {
                s+=a[i][j];
            }
            if(s<x)
            {
                f=1;
                break;
            }
        }
        if(!f)
        {
            int s=0;
            for(auto x:ind)
                s+=c[x];
            mn=min(mn,s);
        }
    }
    if(mn==pinf)
        cout<< "-1";
    else
        cout<<mn;
    return 0;
}


Measured memory_bytes: 3636
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;

using ld = double;
using Point =complex<ld>;
const ld pi = 3.14159265358979323846;

void solve(int n,double d){
    Point cur = Point(0,0), dir = Point(0,1);
    rep(i,n){
        ld l,r, t;
        cin>>l>>r>>t;
        if(l==r){
            cur += dir * 2.0 * pi * l/360.0 * t ;
        }
        else if(l==-r){
            ld ang = 2.0 * pi * r /360 * t / d;
            dir *= Point(cos(ang),sin(ang));
        }
        else {
            Point x = cur + d * Point(0,1) * dir;
            Point y = cur - d * Point(0,1) * dir;
            Point c = (-r*x+l*y)/(l-r);
            ld ra = abs(cur-c);
            ld ang = (l+r)/2.0 * t /360.0 / ra * 2.0 * pi ;
            if(abs(l)>abs(r))ang = -ang;
            cur = c + (cur-c) * Point(cos(ang),sin(ang));
            dir = dir * Point(cos(ang),sin(ang));
        }
    }
    cout<<cur.real()<<endl<<cur.imag()<<endl;
}


int main(){
    int n;
    ld d;
    cout<<fixed<<setprecision(10);
    while(cin>>n>>d,n!=0)solve(n,d);
    return 0;
}


Measured memory_bytes: 3480
#include <iostream>
#include <algorithm>
#include <string>
#include <stack>
using namespace std;
const int limit = 100000;
int a[limit],b[limit],c[limit],num[limit+1];
int main(void){
    int N,Q;
    cin >> N;
    for(int i=0;i<N;i++)cin >> a[i];
    cin >> Q;
    for(int i=0;i<Q;i++)cin >> b[i] >> c[i];
    long long S = 0;
    for(int i=0;i<N;i++){
        S+=a[i];
        num[a[i]]++;
    }
    for(int i=0;i<Q;i++){
        int ex = num[b[i]];
        S += (c[i] - b[i]) * ex;
        num[b[i]] = 0;
        num[c[i]] += ex;
        cout << S << endl;
    }
}




Measured memory_bytes: 5112
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<stack>
#include<string>
#include<map>
#include<set>
#include<tuple>
#include<cmath>
#include<iomanip>


using namespace std;
typedef long long ll;
typedef vector<ll> v;
typedef vector<vector<ll>> vv;


#define MOD 1000000007
#define INF 1001001001
#define MIN -1001001001
#define rep(i,k,N) for(int i=k;i<N;i++)
#define MP make_pair
#define MT make_tuple //tie,make_tuple は別物
#define PB push_back
#define PF push_front
#define all(x) (x).begin(),(x).end()


int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
void YN(bool ans){
    if(ans)cout<<"Yes"<<endl;
    else cout <<"No"<<endl;
    return;
}

int main(){
    ll A,B,C;
    cin>>A>>B>>C;
    YN(A+B>=C);
    return 0;
}

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


int main()
{
	long int n, a, b, c=0;
	scanf("%ld", &n);
	a=n;
	while(a){
		b=a%10;
		c+=b;
		a=a/10;
	}
	
	if(n%c==0) printf("Yes\n");
	
	else printf("No\n");
	return 0;
}

Measured memory_bytes: 128
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <queue>
#include <unordered_map>
#include <unordered_set>
#include <map>
#include <set>
using namespace std;

#define INF (1ll<<60)

int n;
vector<vector<int>> G;

class BIT
{
public:
    vector<long long> bit;
    int M;

    BIT(int M):
        bit(vector<long long>(M+1, -(1ll<<60))), M(M) {}

    long long sum(int i) {
        if (i<=0) return 0;
        return max(bit[i],sum(i-(i&-i)));
    }

    void add(int i, long long x) {
        if (i > M) return;
        bit[i] = max(bit[i], x);
        add(i+(i&-i), x);
    }
};

int main(int argc, char const *argv[]) {
    cin>>n;
    vector<long long> h(n+1,0);
    vector<long long> a(n+1,0),b(n+1,0);
    vector<long long> dp(n+1,0);
    for(int i=0;i<n;++i)cin>>h[i+1];
    for(int i=0;i<n;++i)cin>>a[i+1];
    for(int i=0;i<=n;++i)b[h[i]] = i;
    long long res = 0;
    int m = (1<<20);
    BIT bit(m);
    bit.add(1,0);
    for(int i=1;i<=n;++i){
        int k = b[i];
        long long tmp = bit.sum(1+k) + a[k];
        res = max(res,tmp);
        bit.add(1+k,tmp);
    }
    cout<<res<<endl;
    return 0;
}

Measured memory_bytes: 14720