akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define gc getchar()
using namespace std;
typedef long long ll;
const int N=200009;
int n,fa[N],a[N],f[N],c[N][2];
ll Ans;
struct cmp
{
	bool operator() (const int &x,const int &y)
	{
		if ((ll)c[x][0]*c[y][1]==(ll)c[x][1]*c[y][0]) return x<y;
		return (ll)c[x][0]*c[y][1]>(ll)c[x][1]*c[y][0];
	}
};
multiset<int,cmp> st;
int read()
{
	int x=1;
	char ch;
	while (ch=gc,ch<'0'||ch>'9') if (ch=='-') x=-1;
	int s=ch-'0';
	while (ch=gc,ch>='0'&&ch<='9') s=s*10+ch-'0';
	return s*x;
}
int find(int x)
{
	return f[x]==x?x:f[x]=find(f[x]);
}
int main()
{
	n=read();
	for (int i=2;i<=n;i++) fa[i]=read();
	for (int i=1;i<=n;i++) f[i]=i,a[i]=read(),c[i][a[i]]++;
	for (int i=2;i<=n;i++) st.insert(i);
	for (int i=1;i<n;i++)
	{
		int x=(*st.begin());
		int y=find(fa[x]);
		st.erase(x);
		if (y!=1) st.erase(y);
		Ans+=(ll)c[y][1]*c[x][0];
		c[y][0]+=c[x][0],c[y][1]+=c[x][1];
		f[x]=y;
		if (y!=1) st.insert(y);
	}
	printf("%lld\n",Ans);
	return 0;
}


Measured memory_bytes: 15616
n, k = map(int, input().split())
if k==0:
  print(n**2)
else:
  ans = 0
  for i in range(k+1, n+1):
    t = (n+1)//i
    ans += t*(i-k) + max(0, (n-(t*i+k)+1))
  print(ans)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int MAXN = 3000;
int N;
int meilleur[MAXN][MAXN];

int somme[MAXN + 1];
int recursion(int gauche , int droite)
{
	if (gauche > droite) return 0;
	else if (meilleur[gauche][droite] != 0)
	{
		return meilleur[gauche][droite];
	}
	meilleur[gauche][droite] = somme[droite + 1] - somme[gauche] - min(recursion(gauche + 1 ,droite) , recursion(gauche , droite - 1));
	return meilleur[gauche][droite];
}
int32_t main()
{
	cin >> N;
	for (int i = 1 ; i <= N ; i++)
	{
		int a;
		cin>>a;
		somme[i] = somme[i - 1] + a;
	}
	cout<<2 * recursion(0 , N - 1) - somme[N]<<endl;
}

Measured memory_bytes: 70144
#include <algorithm>
#include <cstring>
#include <iostream>
#include <string>
#include <vector>

int main()
{
    int n, m, x, y;
    std::cin >> n >> m >> x >> y;
    int A[n], B[m];
    for (int i = 0; i < n; i++) { std::cin >> A[i]; }
    for (int i = 0; i < m; i++) { std::cin >> B[i]; }

    bool war = false;
    for (int z = x + 1; z <= y; z++)
    {
        war = false;
        for (int i = 0; i < n; i++)
        {
            if (A[i] >= z)
            {
                war = true;
                break;
            }
        }
        if (war) { continue; }
        for (int i = 0; i < m; i++)
        {
            if (B[i] < z)
            {
                war = true;
                break;
            }
        }
        if (!war)
        {
            std::cout << "No War" << std::endl;
            return 0;
        }
    }

    std::cout << "War" << std::endl;

    return 0;
}

Measured memory_bytes: 256
#include<cmath>
#include<cstdio>
#include<vector>

#define rep(i,n) for(int i=0;i<(n);i++)

using namespace std;

const double EPS=1e-6;
const double INF=1e77;
const double PI=acos(-1);

template<class T>
struct point{
	T x,y;
	point operator+(const point &a)const{ return (point){x+a.x,y+a.y}; }
	point operator-(const point &a)const{ return (point){x-a.x,y-a.y}; }
};

template<class T>
point<T> operator*(T c,const point<T> &a){ return (point<T>){c*a.x,c*a.y}; }

template<class T>
T cross(const point<T> &a,const point<T> &b){ return a.x*b.y-a.y*b.x; }

template<class T>
double abs(const point<T> &a){ return sqrt(a.x*a.x+a.y*a.y); }

point<double> rot(const point<double> &a,double theta){
	return (point<double>){a.x*cos(theta)-a.y*sin(theta),a.x*sin(theta)+a.y*cos(theta)};
}

template<class T>
double arg(const point<T> &a){
	double t=atan2(a.y,a.x);
	return t<0?t+2*PI:t;
}

template<class T>
struct polygon:vector< point<T> >{
	polygon(){}
	polygon(int n):vector< point<T> >(n){}
};

template<class T>
struct circle{
	point<T> c;
	T r;
};

enum {CCW=1,CW=-1,ON=0};
int ccw(const point<double> &a,const point<double> &b,const point<double> &c){
	double rdir=cross(b-a,c-a);
	if(rdir> EPS) return CCW;
	if(rdir<-EPS) return CW;
	return ON;
}

int get_intersect(const circle<double> &C1,const circle<double> &C2,vector< point<double> > &res){
	double r1=C1.r,r2=C2.r;
	point<double> p1=C1.c,p2=C2.c;

	double d=abs(p1-p2);
	if(d<EPS && abs(r1-r2)<EPS){ // C1==C2
		return -1;
	}
	else if(r1+r2<d-EPS || d+EPS<abs(r1-r2)){
		return 0;
	}
	else{
		double a=(r1*r1-r2*r2+d*d)/(2*d);
		double h=sqrt(max(r1*r1-a*a,0.0));
		point<double> tmp1=p1+a/d*(p2-p1);
		point<double> tmp2=h/d*(p2-p1);
		if(abs(tmp2)<EPS){
			res.push_back(tmp1);
			return 1;
		}
		else{
			res.push_back((point<double>){tmp1.x-tmp2.y,tmp1.y+tmp2.x});
			res.push_back((point<double>){tmp1.x+tmp2.y,tmp1.y-tmp2.x});
			return 2;
		}
	}
}

int main(){
	for(int n,r,q;scanf("%d%d%d",&n,&r,&q),n;){
		point<double> O={0,0};
		circle<double> C={O,r};

		polygon<double> F(n);
		rep(i,n) scanf("%lf%lf",&F[i].x,&F[i].y);

		int u=-1;
		for(u=0;abs(abs(F[u])-r)>EPS;u++);
		while(q--){
			int u_next=-1;
			double phi_next=INF;
			point<double> p_next;
			rep(v,n) if(u!=v) {
				vector< point<double> > Q;
				get_intersect(C,(circle<double>){F[u],abs(F[v]-F[u])},Q);

				point<double> p=(ccw(F[u],F[v],Q[0])==CCW?Q[0]:Q[1]);
				double phi=arg(p-F[u])-arg(F[v]-F[u]);
				if(phi<EPS) phi+=2*PI;
				if(phi<phi_next-EPS || abs(phi-phi_next)<EPS && abs(p-F[u])>abs(p_next-F[u])){
					phi_next=phi;
					p_next=p;
					u_next=v;
				}
			}

			rep(v,n) F[v]=F[u]+rot(F[v]-F[u],phi_next);

			u=u_next;
			printf("%.9f %.9f\n",p_next.x,p_next.y);
		}
	}

	return 0;
}

Measured memory_bytes: 1204
def solve(n):
    if n%2==0:
        return n//2,n,n
    for a in range(1,3501):
        for b in range(1,3501):
            den=4*a*b-n*a-n*b
            if den<=0:
                continue
            c=n*a*b/den
            if c.is_integer():
                return a,b,int(c)
    
n=int(input())
print(*solve(n))

Measured memory_bytes: 38896
#include <cmath>
#include <cstdio>
#include <iostream>
#include <utility>
#include <vector>
using namespace std;
#define EPS (1e-10)

struct P{
  double X, Y, Z;
};

namespace std{
  P operator-(const P& a, const P& b){
    P ret = {a.X-b.X, a.Y-b.Y, a.Z-b.Z};
    return ret;
  }
}

double dot_3d(P a, P b){
  return a.X*b.X + a.Y*b.Y + a.Z*b.Z;
}

P cross(P a, P b){
  P ret = {a.Y*b.Z-a.Z*b.Y,a.Z*b.X-a.X*b.Z,a.X*b.Y-a.Y*b.X};
  return ret;
}

double norm_3d(P a){
  return a.X*a.X + a.Y*a.Y + a.Z*a.Z;
}

int main(){
  int N, Q;
  cin >> N >> Q;
  vector<P> obs(N);
  vector<long long int> r(N), l(N);
  for(int i = 0; i < N; ++i){
    cin >> obs[i].X >> obs[i].Y >> obs[i].Z >> r[i] >> l[i];
  }
  P s, d;
  for(int i = 0; i < Q; ++i){
    cin >> s.X >> s.Y >> s.Z >> d.X >> d.Y >> d.Z;
    P v = d-s;
    long long int ans = 0LL;
    for(int j = 0; j < N; ++j){
      if(norm_3d(cross(v,obs[j]-s))/norm_3d(v) <= r[j]*r[j]+EPS &&
	 dot_3d(v,obs[j]-s) >= -EPS && dot_3d(s-d,obs[j]-d) >= -EPS) ans += l[j];
    }
    cout << ans << endl;
  }
  return 0;
}

Measured memory_bytes: 3228
#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp> // Common file
//#include <ext/pb_ds/tree_policy.hpp> // Including seg_tree_order_statistics_node_update
#include <stdio.h>
#include <cassert>
using namespace std;
//using namespace __gnu_pbds;
typedef long long lo;
typedef pair<lo,lo> ll;//pair
typedef vector<lo> vl;  //vector of long
typedef vector<ll > vll;   //vector of pair
typedef priority_queue<lo>p_q;
typedef vector< vl > vvl;  //vector of vectors
#define X first
#define Y second
#define mp(a,b) make_pair((a),(b))
#define REP(a,b) for(lo i=(a);i<(lo)b;i++)//no need to declare variable i
#define REPE(a,b,c,d) REP(a,b)for(lo j=(c);j<(lo)d;j++)//no need to declare vaiables i,j
#define REPV(a,b,c) for(lo(a)=b;(a)<(c);(a)++)//a is the variable
#define IREP(a,b) for(lo i=(a);i>=(b);i--)
#define IREPV(a,b,c) for(lo(a)=b;(a)>=(c);(a)--)
#define all(v) (v).begin(),(v).end()
#define TRV(a) for(auto it : a)
#define INF 100001
//#define MOD lo(1e17)
#define M 1000000007
#define CHECK_BIT(var,pos) ((var) & (1<<(pos)))
#define pb(a) push_back((a))
#define endl "\n"
#define eps 1e-9
#define PI 3.141592653589793
template<typename T> ostream& operator<< ( ostream &o,vector<T> v ) {
    if ( v.size() >0 )o<<v[0];
    for ( unsigned   i=1; i<v.size(); i++ )o<<" "<<v[i];
    return o<<endl;
}
template<typename U,typename V> ostream& operator<< ( ostream &o,pair<U,V> p ) {
    return o<<"("<<p.first<<", "<<p.second<<") ";
}
template<typename T> istream& operator>> ( istream &in,vector<T> &v ) {
    for ( unsigned   i=0; i<v.size(); i++ )in>>v[i];
    return in;
}
template<typename T> istream& operator>> ( istream &in,pair <T,T> &p ) {
    in>>p.X;
    in>>p.Y;
    return in;
}


int main(){
        lo x,y,t,yy;
        cin>>t;
        lo mn=-1e10;
        while(t--){
                cin>>x>>y;
                if(x>mn){
                        mn=x;
                        yy=y;
                }

        }
        mn+=yy;
        cout<<mn<<endl;
        return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;
//
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
		int n=sc.nextInt();
		int m=sc.nextInt();
		if (n==m) {
			System.out.println("Yes");
		} else {
			System.out.println("No");
		}
		
		//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
	}
	//----------------------------------------
	//メソッド置き場

	//----------------------------------------
}

Measured memory_bytes: 21844
/*{{{*/
#include <bits/stdc++.h>
#define SZ(X) ((int)(X).size())
#define ALL(X) (X).begin(), (X).end()
#define REP(I, N) for (int I = 0; I < (N); ++I)
#define REPP(I, A, B) for (int I = (A); I < (B); ++I)
#define FOR(I, A, B) for (int I = (A); I <= (B); ++I)
#define FORS(I, S) for (int I = 0; S[I]; ++I)
#define RS(X) scanf("%s", (X))
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define CASET int ___T; scanf("%d", &___T); for(int cs=1;cs<=___T;cs++)
#define MP make_pair
#define PB emplace_back
#define MS0(X) memset((X), 0, sizeof((X)))
#define MS1(X) memset((X), -1, sizeof((X)))
#define LEN(X) strlen(X)
#define F first
#define S second
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef long double LD;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<PII> VPII;
typedef pair<LL,LL> PLL;
typedef vector<PLL> VPLL;
template<class T> void _R(T &x) { cin >> x; }
void _R(int &x) { scanf("%d", &x); }
void _R(int64_t &x) { scanf("%lld", &x); }
void _R(double &x) { scanf("%lf", &x); }
void _R(char &x) { scanf(" %c", &x); }
void _R(char *x) { scanf("%s", x); }
void R() {}
template<class T, class... U> void R(T &head, U &... tail) { _R(head); R(tail...); }
template<class T> void _W(const T &x) { cout << x; }
void _W(const int &x) { printf("%d", x); }
void _W(const int64_t &x) { printf("%lld", x); }
void _W(const double &x) { printf("%.16f", x); }
void _W(const char &x) { putchar(x); }
void _W(const char *x) { printf("%s", x); }
template<class T,class U> void _W(const pair<T,U> &x) {_W(x.F); putchar(' '); _W(x.S);}
template<class T> void _W(const vector<T> &x) { for (auto i = x.begin(); i != x.end(); _W(*i++)) if (i != x.cbegin()) putchar(' '); }
void W() {}
template<class T, class... U> void W(const T &head, const U &... tail) { _W(head); putchar(sizeof...(tail) ? ' ' : '\n'); W(tail...); }
#ifdef HOME
 #define DEBUG(...) {printf("# ");printf(__VA_ARGS__);puts("");}
#else
 #define DEBUG(...)
#endif
int MOD = 1e9+7;
void ADD(LL& x,LL v){x=(x+v)%MOD;if(x<0)x+=MOD;}
/*}}}*/
const int SIZE = 1e6+10;
LL d[2][2019];
int main(){
    string s;
    R(s);
    int now=0,nxt=1;
    LL an=0;
    REP(i,SZ(s)){
        MS0(d[nxt]);
        int v=s[i]-'0';
        d[nxt][v]=1;
        REP(j,2019){
            d[nxt][v]+=d[now][j];
            v+=10;
            if(v>=2019)v-=2019;
        }
        an+=d[nxt][0];
        swap(now,nxt);
    }
    W(an);
    return 0;
}


Measured memory_bytes: 3760
x,k,d = map(int,input().split())
x = abs(x)
num = x//d
if k >= num:
    x -= num*d
    cnt = k-num
else:
    x -= k*d
    print(x)
    exit()
if abs(x) > abs(x-d):
    x -= d
    cnt -= 1

if cnt%2 == 0:
    print(abs(x))
else:
    print(abs(abs(x)-abs(d)))

Measured memory_bytes: 9168
N = int(input())
n = 0
for i in range(1,N+1):
    if i % 3 == 0 and i % 5 == 0:
        continue   
    elif i  % 3 == 0:
        continue
    elif i % 5 == 0:
        continue
    else:
        n += i
print(n)    

Measured memory_bytes: 9112
###############################################################################

from sys import stdout
from bisect import bisect_left as binl
from copy import copy, deepcopy
from collections import defaultdict


mod = 1


def intin():
    input_tuple = input().split()
    if len(input_tuple) <= 1:
        return int(input_tuple[0])
    return tuple(map(int, input_tuple))


def intina():
    return [int(i) for i in input().split()]


def intinl(count):
    return [intin() for _ in range(count)]


def modadd(x, y):
    global mod
    return (x + y) % mod


def modmlt(x, y):
    global mod
    return (x * y) % mod


def lcm(x, y):
    while y != 0:
        z = x % y
        x = y
        y = z
    return x


def combination(x, y):
    assert(x >= y)

    if y > x // 2:
        y = x - y

    ret = 1

    for i in range(0, y):
        j = x - i
        i = i + 1

        ret = ret * j
        ret = ret // i

    return ret


def get_divisors(x):
    retlist = []
    for i in range(1, int(x**0.5) + 3):
        if x % i == 0:
            retlist.append(i)
            retlist.append(x // i)
    return retlist


def get_factors(x):
    retlist = []
    for i in range(2, int(x**0.5) + 3):
        while x % i == 0:
            retlist.append(i)
            x = x // i
    retlist.append(x)
    return retlist


def make_linklist(xylist):
    linklist = {}
    for a, b in xylist:
        linklist.setdefault(a, [])
        linklist.setdefault(b, [])
        linklist[a].append(b)
        linklist[b].append(a)
    return linklist


def calc_longest_distance(linklist, v=1):
    distance_list = {}
    distance_count = 0
    distance = 0
    vlist_previous = []
    vlist = [v]
    nodecount = len(linklist)

    while distance_count < nodecount:
        vlist_next = []
        for v in vlist:
            distance_list[v] = distance
            distance_count += 1
            vlist_next.extend(linklist[v])
        distance += 1
        vlist_to_del = vlist_previous
        vlist_previous = vlist
        vlist = list(set(vlist_next) - set(vlist_to_del))

    max_distance = -1
    max_v = None
    for v, distance in distance_list.items():
        if distance > max_distance:
            max_distance = distance
            max_v = v

    return (max_distance, max_v)


def calc_tree_diameter(linklist, v=1):
    _, u = calc_longest_distance(linklist, v)
    distance, _ = calc_longest_distance(linklist, u)
    return distance


###############################################################################


def main():
    a, b = intin()

    if a > 8 or b > 8:
        print(':(')
    else:
        print('Yay!')

if __name__ == '__main__':
    main()


Measured memory_bytes: 3544
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rng(i, a, b) for (int i = int(a); i < int(b); i++)
#define rep(i, b) rng(i, 0, b)
#define gnr(i, a, b) for (int i = int(b) - 1; i >= int(a); i--)
#define per(i, b) gnr(i, 0, b)
#define bg begin()
#define ed end()
#define all(x) x.bg, x.ed
#define vi vector<int>
template <class t, class u>
bool chmax(t &a, u b)
{
    if (a < b)
    {
        a = b;
        return true;
    }
    return false;
}
template <class t, class u>
bool chmin(t &a, u b)
{
    if (b < a)
    {
        a = b;
        return true;
    }
    return false;
}

ll mod = 1000000007;
int n, m;
vi p;

bool isAllOn(int num, vector<vector<int>> &vvi)
{
    rep(i, m)
    {
            int sum = 0;
        rep(j, vvi[i].size())
        {
            if ((num & (1 << (vvi[i][j] - 1))) == 0)
            {
                sum++;
            }
        }
            if(sum%2!=p[i]){
                return false;
            }
    }
    return true;
}
signed main()
{
    cin >> n >> m;
    vector<vector<int>> vvi;
    rep(i, m)
    {
        int k;
        cin >> k;
        vi s(k);
        rep(j, k)
        {
            cin >> s[j];
        }
        vvi.push_back(s);
    }
    rep(i, m)
    {
        int a;
        cin >> a;
        p.push_back(a);
    }
    int ans = 0;
    rep(i, 1 << n)
    {
        if (isAllOn(i, vvi))
        {
            ans++;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3612
#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <assert.h>
#include <numeric>

using namespace std;

#define ll long long
#define rep(i, n) for (i = 0; i < n; i++)

int main()
{
  string N;
  cin >> N;
  bool yes = false;
  for (char c : N)
  {
    if (c == '7')
    {
      yes = true;
    }
  }
  if (yes)
  {
    cout << "Yes" << endl;
  }
  else
  {
    cout << "No" << endl;
  }
}


Measured memory_bytes: 3628
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
int main(){
    int W,H,N;
    cin >>W>>H>>N;
    vector<int> x(N);
    vector<int> y(N);
    vector<int> a(N);
    int a1 = 0,a2 = 12345678,a3 = 0,a4 = 12345678;
    for(int i = 0;i < N;i++){
        cin >> x[i] >> y[i] >> a[i];
        
    }
    for(int i = 0;i < N;i++){
        if(a[i] == 1){
            a1 = max(a1,x[i]);
        }
        if(a[i] == 2){
            a2 = min(a2,x[i]);
        }
        if(a[i] == 3){
            a3 = max(a3,y[i]);
        }
        if(a[i] == 4){
            a4 = min(a4,y[i]);
        }
    }
    if(a1 >= a2 || a3 >= a4){
        cout << 0 << endl;
    }
    else{
      if(a2 > W && a4 > H) cout << (W -a1)*(H-a3) << endl;
      if(a2 <= W && a4 > H) cout << (a2 -a1)*(H-a3) << endl;
      if(a2 > W && a4 <= H) cout << (W -a1)*(a4-a3) << endl;
      if(a2 <= W && a4 <= H) cout << (a2 -a1)*(a4-a3) << endl;
    }
    

}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define forin(in, n) for(int i=0; i<n; i++) cin>>in[i]
#define forout(out) for(int i=0; i<(int)out.size(); i++) cout<<out[i]<<endl
#define rep(i, n) for(int i=0; i<(n); i++)

int main(){
    int n; cin>> n;
    vector<double> v(n);
    forin(v, n); sort(v.begin(), v.end());

    double ans=v[0];
    rep(i, n-1){
        ans = (ans + v[i+1])/2;
    }
    printf("%.8lf\n", ans);
}

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

int main()
{
    int n;
    cin>>n;
    long long cnt=1;
    long long x=n;
    long long ans=0;
    while(x%360)
    {
       x=n*cnt;
       cnt++;
       ans++;
    }
    cout<<ans<<endl;
}


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

int main() {
  string S,T;
  cin>>S>>T;
  
  int n=S.size();
  int m=T.size();
  
  int ans=-1;
  
  for(int i=0;i<=n-m;i++){
    string a=S.substr(i,m);
    int cnt=0;
    for(int j=0;j<m;j++){
      if(a[j]==T[j])cnt++;
      ans=max(ans,cnt);
    }
  }
  
  cout<<m-ans<<endl;
}




Measured memory_bytes: 3628
#include <stdio.h>

int a[500001],n;

void maxHeapify(int i){
  int l,r,largest,k;

  l=2*i;
  r=2*i+1;

  if(l<=n && a[l]>a[i])
    largest = l;
  else
    largest = i;
  if(r<=n && a[r]>a[largest])
    largest = r;

  if(largest!=i){
    k=a[i];
    a[i]=a[largest];
    a[largest]=k;
    maxHeapify(largest);
  }
}

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

  for(i=n/2; i>0; i--)
    maxHeapify(i);

  for(i=1; i<n; i++)
    printf(" %d",a[i]);
  printf(" %d\n",a[i]);

  return 0;
}



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

A = list(map(int, input().split()))

min_idx = A.index(min(A))

if K >= N:
    print(1)
else:
    if ((N-1)%(K-1) == 0):
        print((N - 1)// (K - 1))
    else:
        print((N - 1) // (K - 1) + 1)

Measured memory_bytes: 13880
let puts st = print_string st; print_string "\n";;
let puti num = print_int num; print_string "\n";;
let getSL () = Str.split (Str.regexp " ") (read_line ());;
let getLI () = Array.of_list @@ List.map int_of_string (getSL ());;
let geti () = int_of_string (read_line ());;
let rep n f =
    let rec repimpl i n = if i < n then (f i; repimpl (i+1) n) else () in repimpl 0 n;;
let rep_from from until f =
    let rec repimpl i n = if i < n then (f i; repimpl (i+1) n) else () in repimpl from until;;


let solve () =
    let len = geti () in
    let inl = getLI () in
    let res = ref 0 in
    rep_from 0 (len-2) (fun i ->
        if (inl.(i) < inl.(i+1) && inl.(i+1) < inl.(i+2)) || (inl.(i+1) < inl.(i) && inl.(i+2) < inl.(i+1)) then
            res := !res + 1
    );
    puti !res;;

solve ();;


Measured memory_bytes: 2432
//#pragma GCC oplmize(2)
// #pragma GCC optimize("Ofast")
// #pragma GCC target("avx,avx2,fma")
// #pragma GCC optimization ("unroll-loops")
#include <bits/stdc++.h>
#define ll int
#define sc(x) scanf("%d",&x)
#define scs(x) scanf("%s",x+1)
#define pr(x) printf("%d\n",x)
#define prs(x) printf("%s\n",x)
using namespace std;
const int maxn=3e5+5;
const int mod=1e9+7;
const double pi=acos(-1.0);
const double eps = 1e-8;
ll h,w,m,a[maxn],b[maxn],x,y,mx,my,idx,idy,ma;
map<pair<ll,ll>,ll>mp;
vector<ll>v1;
vector<ll>v2;

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    sc(h),sc(w),sc(m);
    for(int i=1;i<=m;i++){
        sc(x),sc(y);
        a[x]++;
        b[y]++;
        mp[{x,y}]++;
        mx=max(mx,a[x]);
        my=max(my,b[y]);
    }
    for(int i=1;i<=h;i++){
        if(a[i]==mx) v1.push_back(i);
    }
    for(int i=1;i<=w;i++){
        if(b[i]==my) v2.push_back(i);
    }
    for(int i=0;i<v1.size();i++){
        for(int j=0;j<v2.size();j++){
            if(mp[{v1[i],v2[j]}]==0) {
                pr(mx+my);
                return 0;
            }
        }
    }
    pr(mx+my-1);
    return 0;
}


Measured memory_bytes: 28408
let () =
	let a, b, c = Scanf.scanf "%d %d %d\n" (fun a b c -> a, b, c) in
    Printf.printf 
    	(if a = b && a <> c then "Yes"
         else if a = c && a <> b then "Yes"
         else if b = c && a <> b then "Yes"
         else "No")

Measured memory_bytes: 384
// https://atcoder.jp/contests/abc062/tasks/arc074_b
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
#define REP(i, n) FOR(i, 0, n)
#define FOR(i, s, n) for (int i = (s), i##_len = (n); i < i##_len; ++i)
#define ALL(obj) (obj).begin(), (obj).end()
#define ALLR(obj) (obj).rbegin(), (obj).rend()
const ll INFL = 1e18;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    vector<int> v(n * 3);
    REP(i, n * 3) cin >> v[i];
    priority_queue<int, vector<int>, greater<int>> q1;
    priority_queue<int> q2;
    ll sum1 = 0, sum2 = 0;
    REP(i, n) {
        q1.push(v[i]);
        q2.push(v[i + n * 2]);
        sum1 += v[i];
        sum2 += v[i + n * 2];
    }
    vector<ll> v1, v2;
    v1.push_back(sum1);
    v2.push_back(sum2);
    REP(i, n) {
        int t = q1.top();
        if (t < v[i + n]) {
            q1.pop();
            q1.push(v[i + n]);
            sum1 += v[i + n] - t;
        }
        v1.push_back(sum1);
    }
    REP(i, n) {
        int t = q2.top();
        if (t > v[2 * n - i - 1]) {
            q2.pop();
            q2.push(v[2 * n - i - 1]);
            sum2 += v[2 * n - i - 1] - t;
        }
        v2.push_back(sum2);
    }
    ll maxv = -INFL;
    ll minv = INFL;
    ll ans = -INFL;
    for (auto &x : v1) {
        maxv = max(maxv, x);
        x = maxv;
    }
    for (auto &x : v2) {
        minv = min(minv, x);
        x = minv;
    }
    REP(i, v1.size()) ans = max(ans, v1[i] - v2[v2.size() - 1 - i]);
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 4592
#include<iostream>
using namespace std;
int main() {
  int s;
  cin >> s;
  int a = s / 100;
  int b = s % 100;
  if(a>12 || a<1){
    if(b>12 || b<1){
      cout << "NA";
    }else{
      cout << "YYMM";
    }
  }else{
    if(b>12 || b<1){
      cout << "MMYY";
    }else{
      cout << "AMBIGUOUS";
    }
  }
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int A = sc.nextInt();
		int B = sc.nextInt();
		int C = sc.nextInt();

		if (A + B +1 <= C ) {
			System.out.println(B + B + A + 1);
		} else {
			System.out.println(B + C);
		}
	}
}


Measured memory_bytes: 19796
#include<stdio.h>
 int main(void){
 int i,b,f,r,v,j,k,count;
 int room[4][3][10]={0};
 scanf("%d",&count);
 for(i=0;i<count;i++){
 scanf("%d %d %d %d",&b,&f,&r,&v);
 room[b-1][f-1][r-1]+=v;
 }
 for(i=0;i<4;i++){
 for(j=0;j<3;j++){
 for(k=0;k<10;k++)
 printf(" %d",room[i][j][k]);
 printf("\n");
 }
 if(i!=3) printf("####################\n") ;
 }
 return 0;
 }


Measured memory_bytes: 2084
#import sys
#import numpy as np
#import math
#import itertools
#from fractions import Fraction
#import itertools
from collections import deque
#import heapq
#from fractions  import gcd
#input=sys.stdin.readline
#import bisect

n=int(input())
r=[list(map(int,input().split())) for _ in range(n-1)]
for i in range(n-1):
    time=r[i][1]
    for j in range(i,n-1):
        if time>=r[j][1]:
            if time%r[j][2]==0:
                time+=r[j][0]
            else:
                time=((time//r[j][2])+1)*r[j][2]
                time+=r[j][0]
        else:
            time=r[j][1]
            time+=r[j][0]
    print(time)
print(0)

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

int main() {
		int n;
		int a;
		int b;
	while( true ){
		int sa=0;
		int sb=0;
		cin >> n;
		
		if(n == 0){
			return 0;
		}
		for(int i=0;i<n;i++){
			cin >> a >> b;
			if(a>b){
				sa+=a+b;
			}else{
				if(a<b){
				sb+=a+b;	
				}else{
					sa+=a;
					sb+=b;
				}
			}
		}
		cout << sa << " " << sb << endl;
	}
}

Measured memory_bytes: 1160
#include <iostream>
#include <vector>
#include <string>
using namespace std;
//変数デバッグ
#define DEB(variable) cout << #variable << '=' << variable << endl

//for簡易表記(引数ミス防止)
#define FOR(LoopVariable,numberOFbegin,numberOFend) for (int LoopVariable = (numberOFbegin); (LoopVariable) < (numberOFend); (LoopVariable)++)
#define REP(LoopVariable,numberOFend) for(int LoopVariable = 0;(LoopVariable)<(numberOFend);LoopVariable++)

int main(){

    int a,b;
    cin >> a >> b;

    cout << a * b - a - b + 1 << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>

using namespace std;
using namespace boost::multiprecision;

#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define REPI(i,a,b) for(int i=int(a);i<int(b);++i)
#define RREP(i,x) for(int i=((int)(x)-1);i>=0;i--)
#define ALL(x) (x).begin(),(x).end()

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

  REP(i, n) {
    if((((i+1) * 108)/100) == n) {
      cout << (i+1) << endl;
      return 0;
    }
  }

  cout << ":(" << endl;
  return 0;
}


Measured memory_bytes: 256
#pragma warning disable

using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
// Do not use: System.Numerics; at CodeIQ

public class Test
{
    public static void Main()
    {
        var N = Int32.Parse(Console.ReadLine());
        var a = Console.ReadLine().Split(' ').Select(x => Int32.Parse(x)).ToArray();

        int sectionsCount = 1;
        bool increasing = false;
        bool decreasing = false;

        int lastNum = a[0];  // N >= 1 なのでok

        for (int i = 1; i < a.Length; i++)
        {
            if (a[i] > lastNum)
            {
                if (decreasing)
                {
                    sectionsCount++;
                    increasing = decreasing = false;
                }
                else
                {
                    increasing = true;
                }
            }
            else if (a[i] < lastNum)
            {
                if (increasing)
                {
                    sectionsCount++;
                    increasing = decreasing = false;
                }
                else
                {
                    decreasing = true;
                }
            }
            else
            {
                // do nothing
            }

            lastNum = a[i];
        }

        Console.WriteLine(sectionsCount);
    }
}

Measured memory_bytes: 19680
#include <iostream>
#include <climits>
#include <vector>

using namespace std;

typedef long long ll;

const int MAX_N = 200000;

template<typename T> class LazyRMQ {
    public:
    int n;
    T inf = INT_MAX;
    vector<T> data, lazy;
    
    LazyRMQ(int m, T init_value=INT_MAX){
        // 2のべき乗にする
        n = 1;
        while(n < m) n <<= 1;
        data.assign(2*n-1, init_value);
        lazy.assign(2*n-1, 0);
        inf = init_value;
    }

    void eval(int k, int kl, int kr){
        if(data[k] == inf) data[k] = 0;
        if(lazy[k] == 0) return;
        data[k] += lazy[k];
        if(kr - kl > 1){
            lazy[2*k+1] += lazy[k];
            lazy[2*k+2] += lazy[k];
        }
        lazy[k] = 0;
    }

    // [s,t)
    void add(int s, int t, T x, int k, int kl, int kr){
        eval(k, kl, kr);
        if(kr <= s || t <= kl) return;
        if(s <= kl && kr <= t){
            lazy[k] += x;
            eval(k, kl, kr);
            return;
        }
        int kc = (kl+kr)/2;
        add(s, t, x, 2*k+1, kl, kc);
        add(s, t, x, 2*k+2, kc, kr);
        data[k] = max(data[2*k+1], data[2*k+2]);
    }

    // [s,t)
    T find(int s, int t, int k, int kl, int kr){
        eval(k, kl, kr);
        if(kr <= s || t <= kl) return inf;
        if(s <= kl && kr <= t) return data[k];
        int kc = (kl+kr)/2;
        T vl = find(s, t, 2*k+1, kl, kc);
        T vr = find(s, t, 2*k+2, kc, kr);
        return max(vl, vr);
    }
};

int main() {
    int n,m,l,r; ll a;
    cin >> n >> m;
    vector<pair<int, ll>> ranges[n+1];
    for(int i=0;i<m;++i) {
        cin >> l >> r >> a;
        ranges[r].emplace_back(l, a);
    }

    LazyRMQ<ll> tree(n+2, -(1<<30));
    for(int i=1;i<=n;++i) {
        ll opt = tree.find(0, i, 0, 0, tree.n);
        tree.add(i, i+1, opt, 0, 0, tree.n);
        for(pair<int, ll> p: ranges[i]) {
            tree.add(p.first, i+1, p.second, 0, 0, tree.n);
        }
    }

    cout << tree.find(0, n+1, 0, 0, tree.n) << endl;
}

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

using namespace std;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int a, b;
    cin >> a >> b;

    if((a < 1 || a > 9) || (b < 1 || b > 9))
    {
        cout << "-1" << endl;
    } else
    {
        cout << a*b << endl;
    }

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define INF 0x3f3f3f3f
#define eps 1e-8
#define pb push_back
#define endl '\n'
using namespace std;
const ll maxn = 2e6 + 5;
ll num[maxn],a,b,c,d,t,n,m,k;
string str;
int main()
{
    cin >> str;
    if(str[0] == '7' || str[1] == '7' || str[2] == '7')
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 3636
#! /usr/bin/env python3

n, m, x = map(int, input().split())

a = [int(i) for i in input().split()] 

cost_0 = 0
cost_n = 0

for i in a:
    if i < x:
        cost_0 += 1
    if i > x:
        cost_n += 1

print(min(cost_0, cost_n))


Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
#define mp make_pair
#define nl '\n'
#define pb push_back
#define ub upper_bound
#define lb lower_bound
#define flood(x) memset(x, 0x3f3f3f3f, sizeof x)
#define drain(x) memset(x, 0, sizeof x)
#define dcit cin.sync_with_stdio(0);cin.tie(0);
#define frp(x, y) freopen(x, "r", stdin);freopen(y, "w", stdout);
typedef pair<int, int> pii;
typedef long long ll;

#ifdef LOCAL_PROJECT

#define gc getchar()
#define pc(x) putchar(x)

#endif
#ifndef LOCAL_PROJECT

#define gc getchar_unlocked()
#define pc(x) putchar_unlocked(x)

#endif

template<typename T> void scani(T &x) {x = 0;register bool _=0;register T c=gc;_=c==45;c=_?gc:c;while(c<48||c>57)c=gc;for(;c<48||c>57;c=gc);for(;c>47&&c<58;c=gc)x=(x<<3)+(x<<1)+(c&15);x=_?-x:x;}
template<typename T> void printi(T n) {register bool _=0;_=n<0;n=_?-n:n;char snum[65];int i=0;do{snum[i++]=n%10+48;n/= 10;}while(n);--i;if (_)pc(45);while(i>=0)pc(snum[i--]);pc(10);}
string nextstring() { string r; register char c=gc;while(c==32||c==10) c = gc;while(!(c==32||c==10)) { r += c;c = gc; }return r; }
char nextgetchar(){ register char c = gc; while(c==32 || c==10) c = gc; return c;}

void prints(string k){ for (int i = 0; i < k.length(); i++)pc(k[i]); }
void scani() {}

template<typename First, typename ... Ints>
void scani(First &arg, Ints&... rest) { scani(arg);scani(rest...); }

const int MOD = 1e9+7;
int N; int arr[22][22], dp[(1<<22)+1];

int main(){
    dp[0] = 1;
    scani(N);
    for (int i = 0; i < N; i++)
        for (int j = 0; j < N; j++)
            scani(arr[i][j]);
        
    dp[0] = 1;    
    for (int mask = 0; mask < (1<<N); mask++) {
        int men = __builtin_popcount(mask);
        for (int i = 0; i < N; i++) {
            if(arr[men][i] && !((1<<i) & mask)) {
                int mask2 = (1<<i) ^ mask;
                dp[mask2] += dp[mask];
                dp[mask2]%=MOD;
            }
        }
    }
    printi(dp[(1<<N)-1]);
    return 0;
}

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

typedef long long int ll;
typedef vector<long long>lve;
typedef vector<pair<ll,ll> > lvp;

#define sp         ' '
#define endl       '\n'
#define F          first
#define S          second
#define pp         pop_back`
#define pb         push_back
#define mp         make_pair 
#define GCD(x,y)   __gcd(x,y)
#define PI         2*acos(0.0)
#define lb         lower_bound
#define bs         binary_search
#define all(x)     x.begin(),x.end()
#define LCM(x,y)   ((x*y)/__gcd(x,y))
#define btpc       __builtin_popcountll
#define spc(x)     cout<<fixed<<setprecision(x)

const   long long  cs=2e5+5;
const   long long  inf=1e18;
const   long long  mod=1e9+7;
void solve()
{
    int64_t t,n,m,a,b,c,d,e,i,j,k,x,y,cnt=0,cnt1=0;
    bool flag = false;   
    
    string s;
    cin>>s;
    sort(all(s));
    if(s[0]==s[1] && s[1]!=s[2] && s[2]==s[3]) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;    
}
int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);    cout.tie(NULL);

    // freopen ("input.txt","r",stdin);
    // freopen ("output.txt","w",stdout);

    // int32_t tc;
    // cin>>tc;
    // while(tc--)
    solve();

    return 0;
}


Measured memory_bytes: 3564
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>

static const int MOD = 1000000007;
using ll = long long;
using u32 = uint32_t;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208;

int main() {
    int a, b;
    cin >> a >> b;
    cout << max(0, a-b-b) << "\n";
    return 0;
}

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

int main(){
	int a, b, c, d;
	int e, f, g, h;
	std::cin >> a >> b >> c >> d;
	std::cin >> e >> f >> g >> h;
	std::cout << std::max(a + b + c + d, e + f + g + h) << std::endl;
	return 0;
}

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

void solve() {
  string o, e;
  cin >> o >> e;
  int oz = (int) o.size();
  int ez = (int) e.size();
  int flag = 0;
  int lim = oz;
  if(oz > ez) {
    lim = ez;
    flag = 1;
  }
  else if (oz < ez) {
    lim = oz;
    flag = 2;
  }
 for (int i = 0; i < lim; i++) {
    cout << o[i] << e[i];
 }
 if(flag == 1){
   cout << o[oz-1];
 }
 else if (flag == 2) {
   cout << e[ez-1];
 }

}

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


Measured memory_bytes: 256
#include<iostream> 
#include<string>
#include<algorithm>
using namespace std;
struct Card
{
	int value;
	char suit;
};

void BubbleSort(Card card[], int n) {
	for (int i = 0; i < n; i++) {
		for (int k = 0; k < n - 1; k++) {
			if (card[k].value > card[k + 1].value) {
				Card temp = card[k];
				card[k] = card[k + 1];
				card[k + 1] = temp;
			}
		}
	}
}
void SelectionSort(Card card[], int n) {
	for (int i = 0; i < n - 1; i++) {
		int j = i;
		for (int k = i + 1; k < n; k++) {
			if (card[j].value > card[k].value) {
				j = k;
			}
		}
		Card temp = card[j];
		card[j] = card[i];
		card[i] = temp;
	}
}

void print(Card card[], int N) {
	cout << card[0].suit << card[0].value;
	for (int i = 1; i < N; i++) {
		cout<<" "<< char(card[i].suit) << card[i].value;
	}
	cout << endl;
}

void isStable(Card c1[], Card c2[],int N) {
	for (int i = 0; i < N; i++) {
		if (c1[i].suit != c2[i].suit) {
			cout << "Not stable" << endl;
			return;
		}
	}
	cout << "Stable" << endl;
}
int main()
{
	Card c1[100];
	Card c2[100];
	int num;
	cin >> num;
	for (int i = 0; i < num; i++) {
		cin >> c1[i].suit >> c1[i].value;
		c2[i].suit = c1[i].suit;
		c2[i].value = c1[i].value;
	}
	BubbleSort(c1, num);
	print(c1, num);
	cout << "Stable" << endl;
	SelectionSort(c2, num);
	print(c2, num);
	isStable(c1, c2, num);
}


Measured memory_bytes: 3104
import sys, re
from math import ceil, floor, sqrt, pi, factorial, gcd
from copy import deepcopy
from collections import Counter, deque
from heapq import heapify, heappop, heappush
from itertools import accumulate, product, combinations, combinations_with_replacement
from bisect import bisect, bisect_left, bisect_right
from functools import reduce
from decimal import Decimal, getcontext


# input = sys.stdin.readline
def i_input(): return int(input())


def i_map(): return map(int, input().split())


def i_list(): return list(i_map())


def i_row(N): return [i_input() for _ in range(N)]


def i_row_list(N): return [i_list() for _ in range(N)]


def s_input(): return input()


def s_map(): return input().split()


def s_list(): return list(s_map())


def s_row(N): return [s_input for _ in range(N)]


def s_row_str(N): return [s_list() for _ in range(N)]


def s_row_list(N): return [list(s_input()) for _ in range(N)]


def lcm(a, b): return a * b // gcd(a, b)


sys.setrecursionlimit(10 ** 6)
INF = float('inf')
MOD = 10 ** 9 + 7
num_list = []
str_list = []


def main():
    d, t, s = i_list()

    print('Yes' if d/s <= t else 'No')


if __name__ == '__main__':
    main()


Measured memory_bytes: 10516
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
string s,t;
int dp[3010][3010];

int main() {
    cin >> s >> t;
    for (int i = 0; i <= s.size(); i++) {
        for (int j = 0; j <= t.size(); j++) {
            dp[i+1][j] = max(dp[i+1][j], dp[i][j]);
            dp[i][j+1] = max(dp[i][j+1], dp[i][j]);
            if (i < s.size() && j < t.size())
                dp[i+1][j+1] = max(dp[i+1][j+1], dp[i][j] + (s[i] == t[j]));
        }
    }
    int i = s.size(), j = t.size();
    string ans = "";
    // for (int i = 0; i <= s.size(); i++) {
    //     for (int j = 0; j <= t.size(); j++) {
    //         cout << dp[i][j] << " ";
    //     }
    //     cout << endl;
    // }
    while (dp[i][j] > 0) {
        // cout << i << " " << j << endl;
        // cout << dp[i][j] << endl;
        if (i > 0 && dp[i-1][j] == dp[i][j]) {
            i--;
            continue;
        }
        if (j > 0 && dp[i][j-1] == dp[i][j]) {
            j--;
            continue;
        }
        if (i > 0 && j > 0 && s[i-1] == t[j-1] && dp[i][j] == dp[i-1][j-1] + 1) {
            ans = ans + s[i-1];
            i--;
            j--;
        }
    }
    reverse(ans.begin(), ans.end());
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 35584
#include <iostream>
#include <vector>
#include <functional>

template<typename T> class segment_tree {
	int N;
	std::vector<T> value;

public :
	const std::function<T(T, T)> op;
	const T id;

	segment_tree(const std::vector<T>& a, const std::function<T(T, T)>& f, const T& t) : op(f), id(t) {
		int n = a.size(), m = 1;
		while (m < n) m *= 2;
		value.resize((N = m) * 2, id);
		for (int i = 0; i < n; i++) value[N + i] = a[i];
		for (int i = N - 1; i > 0; i--) value[i] = op(value[i * 2], value[i * 2 + 1]);
	}

	segment_tree(const int& n, const std::function<T(T, T)>& f, const T& t) : op(f), id(t) {
		int m = 1;
		while (m < n) m *= 2;
		value.resize((N = m) * 2, id);
	}

	void point_update(int i, const T& t) {
		i += N;
		value[i] = t;
		while (i /= 2) value[i] = op(value[i * 2], value[i * 2 + 1]);
	}

	T range_fold(const int& L, const int& R, const int& i = 1, const int& l = 0, int r = -1)const{
		if (r == -1) r = N;
		if (L <= l && r <= R) return value[i];
		if (r <= L || R <= l) return id;
		return op(
			range_fold(L, R, i * 2, l, (l + r) / 2),
			range_fold(L, R, i * 2 + 1, (l + r) / 2, r)
		);
	}

	inline const T& operator[](const int& i)const{return value[N + i];}
};

int main() {
	int n, q;
	std::cin >> n >> q;
	std::vector<long long> a(n);
	for (int i = 0; i < n; i++) std::cin >> a[i];

	segment_tree<long long> sg(a, [](long long a, long long b){return a + b;}, 0);
	while (q--) {
		int op;
		std::cin >> op;
		if (op == 0) {
			int p; long long x;
			std::cin >> p >> x;
			sg.point_update(p, sg[p] + x);
		} else {
			int l, r;
			std::cin >> l >> r;
			std::cout << sg.range_fold(l, r) << '\n';
		}
	}

	return 0;
}

Measured memory_bytes: 16428
#include<iostream>
#include<stdio.h>
#include<algorithm>
#include<vector>
#include<utility>
#include<string>
#include<stack>
#include<queue>
#include<set>
#include<math.h>
#include <map>
using namespace std;
typedef long long int ll;
#define repi(i,a,b) for(ll i=a;i<b;i++)
#define rep(i,a) repi(i,0,a)
#define all(u) u.begin(),u.end()
#define pl pair<ll,ll>
#define fi first
#define se second
#define mod 1000000007
#define inf 1e16
#define mp(a,b) make_pair(a,b)
#define len(u,N) u.begin(),u.begin()+N

ll K;

int main() {
    cin >> K;
    ll N = inf;
    repi(i,2,N+1){
        ll check = 1;
        vector<ll> g(i);
        rep(j,i) g[j] = j;
        rep(j,K%i){
            g[j] += i;
            repi(k,0,j) g[k]--;
            repi(k,j+1,i) g[k]--;
            rep(k,i){
                if (g[k] < 0) check = 0;
                if (g[k] > g[j]) check = 0;
            }
        }
        rep(k,i) g[k] += K/i;
        
        if (check){
            rep(j,i){
                if (!(g[j] >= 0 && g[j] <= 1e16+1000)) break;
                if (j == i-1) N = i;
            }
            if (N != inf){
                cout << N << endl;
                rep(i,N) cout << g[i] << " ";
                cout << endl;
                return 0;
            }
        }
    }
    return 0;
}


Measured memory_bytes: 384
#include <string>
#include <iostream>
#include <vector>
using namespace std;
struct tr{
    vector<tr*> children;
    string name;
    int depth;
    void prt(){
        for(int i=0;i<depth;i++){cout<<".";}
        cout<<name<<endl;
        for(auto i=children.begin();i!=children.end();i++){
            (*i)->prt();
        }
    }        
};

int main(){
    int n,i,p;
    cin>>n;
    vector<tr> t(n);
    for(i=0;i<n;i++){
        tr buf;
        cin>>p;
        cin>>buf.name;
        if(!i){
            buf.depth=0;
            t[0]=buf;
        }        
        else{
            buf.depth=t[p-1].depth+1;
            t[i]=buf;
            t[p-1].children.push_back(&t[i]);
        }
    }
    t[0].prt();
    return 0;
}



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

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

  rep(x,n+1) {
    rep(y,m+1) {
      if (k == x*(m-y)+y*(n-x)) {
        cout << "Yes" << endl;
        return 0;
      }
    }
  }

  cout << "No" << endl;
  return 0;
}


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

int main(){
    int n;
    cin >> n;
    vector<vector<int>> a(n, vector<int>(3));
    for(int i=0; i<n; i++){
        for(int j=0; j<3; j++){
            cin >> a[i][j];
        }
    }
    vector<int> ans(n, 0);
    for(int i=0; i<3; i++){
        for(int j=0; j<n; j++){
            bool ok = true;
            for(int k=0; k<n; k++){
                if(j == k) continue;
                if(a[j][i] == a[k][i]){
                    ok = false;
                    break;
                }
            }
            if(ok) ans[j] += a[j][i];
        }
    }
    for(int i=0; i<n; i++){
        cout << ans[i] << endl;
    }
    return 0;
}



Measured memory_bytes: 3152
N, D = map(int, input().split())
XY = [map(int, input().split()) for _ in range(N)]
X, Y = [list(i) for i in zip(*XY)]
count = 0

for cnt in range(N):
    dist = X[cnt] ** 2 + Y[cnt] ** 2

    if dist <= D ** 2:
        count = count + 1

print(count)


Measured memory_bytes: 116604
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <cstdio>

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;
ll N, K;
vector<ll> a(100001);

int main() {
    long double W, H, x, y;
    cin >> W >> H >> x >> y;
    long double S = W * H / 2;
        cout << S << ' ';
        if ((W / 2 == x) and  (H / 2 == y)) {
            cout << 1 << '\n';
        }
        else {
            cout << 0 << '\n';
        }
 
}


Measured memory_bytes: 1024
import copy
n, d = map(int, input().split())
point_list = []
for i in range(n):
    point = list(map(int, input().split()))
    point_list.append(point)

count = 0

point_list_copy = copy.deepcopy(point_list)

for point in point_list:
    point_list_copy.pop(0)
    for point_copy in point_list_copy:
        distance = 0
        for i in range(d):
            distance += (point[i] - point_copy[i])**2
        dist = distance ** (1/2)
        if dist == int(dist):
            count += 1

print (count)

Measured memory_bytes: 3572
from sys import stdin

n = int(stdin.readline().rstrip())
a,b = [int(x) for x in stdin.readline().rstrip().split()]
li = list(map(int,stdin.readline().rstrip().split()))

one = 0
two = 0
three = 0

for i in li:
    if i <= a:
        one += 1
    elif a+1 <= i <= b:
        two += 1
    else:
        three += 1
print(min(one,two,three))

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

int main(void) {
    int N,K;
    int d;
    int tmp;
    int cnt = 0;

    cin >> N >> K;

    vector<int> sunuke(N, 0);

    for(int i=0;i<K;i++) {
        cin >> d;
        for(int j=0;j<d;j++) {
            cin >> tmp;
            sunuke[tmp-1] = 1;
        }
    }

    sort(sunuke.begin(), sunuke.end());
    for(int i=0;i<sunuke.size();i++) {
        if(sunuke[i]) {
            break;
        }
        cnt++;
    }
    cout << cnt << "\n";

    return 0;
}


Measured memory_bytes: 3628