akhauriyash/Code-Regression huggingface dataset:
#include <float.h>
#include <inttypes.h>
#include <limits.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <unistd.h>
#include <math.h>
#ifdef __cplusplus
#include <bits/stdc++.h>
#endif

uint32_t nextpint(void){ char c=getchar_unlocked(); while(c<'0'||'9'<c) c=getchar_unlocked(); uint32_t x=0; while('0'<=c && c<='9'){ x=x*10+c-'0'; c=getchar_unlocked(); } return x; }
void printint(uint32_t x){ if(x<0){x=-x; putchar_unlocked('-');}else if(x==0){putchar_unlocked('0');} int d=0; char s[10]; while(x){ s[d]='0'+x%10; x/=10; d++; } for (int i=d-1; i>=0; i--) putchar_unlocked(s[i]); putchar_unlocked('\n'); }
void rsort_d32(void *base, const int count);

int32_t a[200000];
int32_t b[200000];

int main(void){
	uint32_t n=nextpint();
	for(uint32_t i=0; i<n; i++){
		int32_t k=nextpint();
		a[i]=i+k;
		b[i]=i-k;
	}
	rsort_d32(a, n);
	rsort_d32(b, n);
	uint64_t ans=0;
	uint32_t al=0, bl=0;
	while(al<n){
		int32_t A=a[al];
		while(bl<n && b[bl]<A) bl++;
		if(bl==n) break;
		if(b[bl]==A){
			int32_t ac=0, bc=0;
			while(al<n && a[al]==A) al++, ac++;
			while(bl<n && b[bl]==A) bl++, bc++;
			ans+=(int64_t)ac*bc;
		}else{
			al++;
		}
	}
	printf("%"PRIu64"\n", ans);
}

void rsort_d32(void *base, const int count){
	int32_t *a=base;
	int32_t *b=malloc(count*sizeof(int32_t));
	int c[0x100];
	memset(c, 0, sizeof(c)); for(int i=0; i<count; i++){ c[(a[i]>>(0<<3))&0xFF]++; } for(int i=1; i<0x100; i++) c[i]+=c[i-1]; for(int i=count-1; i>=0; i--){ b[--c[(a[i]>>(0<<3))&0xFF]]=a[i]; }{void *t=a; a=b; b=t;}
	memset(c, 0, sizeof(c)); for(int i=0; i<count; i++){ c[(a[i]>>(1<<3))&0xFF]++; } for(int i=1; i<0x100; i++) c[i]+=c[i-1]; for(int i=count-1; i>=0; i--){ b[--c[(a[i]>>(1<<3))&0xFF]]=a[i]; }{void *t=a; a=b; b=t;}
	memset(c, 0, sizeof(c)); for(int i=0; i<count; i++){ c[(a[i]>>(2<<3))&0xFF]++; } for(int i=1; i<0x100; i++) c[i]+=c[i-1]; for(int i=count-1; i>=0; i--){ b[--c[(a[i]>>(2<<3))&0xFF]]=a[i]; }{void *t=a; a=b; b=t;}
	memset(c, 0, sizeof(c)); for(int i=0; i<count; i++){ c[(a[i]>>(3<<3))+0x80]++; } for(int i=1; i<0x100; i++) c[i]+=c[i-1]; for(int i=count-1; i>=0; i--){ b[--c[(a[i]>>(3<<3))+0x80]]=a[i]; }{void *t=a; a=b; b=t;}
	free(b);
}


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

using namespace std;

int gcd(int a, int b){
    if(a%b==0){
        return b;
    } else{
        return gcd(b, a%b);
    }
}

int main(){
    int n, x;
    cin >> n >> x;
    vector<int> xs(n+1);
    xs[n]=x;
    for(int i=0; i<n; ++i){
        cin >> x;
        xs[i]=x;
    }
    sort(xs.begin(), xs.end());
    vector<int> xs2(n);
    for(int i=0; i<n; ++i){
        xs2[i]=xs[i+1]-xs[i];
    }
    int d=xs2[0];
    for(int i=1; i<n; ++i){
        d=gcd(d, xs2[i]);
    }
    cout << d << endl;
    return 0;
}


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

int main() {
	int N;
	cin >> N;
	unordered_map<int, long long> M;
	vector<int>A(N);
	for (int i = 0; i < N; i++) {
		int a;
		cin >> a;
		A[i] = a;
		M[a]++;
	}
	long long ans = 0;
	for (auto m : M) ans += m.second * (m.second - 1) / 2;
	for (int i = 0; i < N; i++) cout << ans - M[A[i]] + 1 << endl;
}


Measured memory_bytes: 8392
#include <stdio.h>

int main(void) {
	int i = 0;
	int j = 0;
	int k = 0;
	int n = 0;	//?????????????????°.
	int v = 0;

	int card[100] = {};	//??????????????????.

	//????????????????????????.
	scanf("%d", &n);
	for (i = 0; i < n; i++)
		scanf("%d", &card[i]);

	for (i = 1; i < n; i++) {
		
		//???????????????.
		for (k = 0; k < n; k++) {
			if (k == n - 1)
				printf("%d\n", card[k]);
			else
				printf("%d ", card[k]);
		}

		v = card[i];
		j = i - 1;
		while (j >= 0 && card[j] > v) {
			card[j+1] = card[j];
			j--;
		}
		card[j+1] = v;
	}

	//???????????????.
	for (k = 0; k < n; k++) {
		if (k == n - 1)
			printf("%d\n", card[k]);
		else
			printf("%d ", card[k]);
	}

	return 0;
}

Measured memory_bytes: 600
#include <iostream>
using namespace std;
int main(int argc, char const *argv[])
{
    int k,s;
    cin >>k>>s;
    int cnt =0;
    for(int i=0;i<=k;++i){
        for (int j = 0; j <= k; j++){
            int z = s-i-j;
            if(z>=0 && z<=k)cnt++;
        }
    }
    cout << cnt<<endl;
    return 0;
}


Measured memory_bytes: 256
package main

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

type Alds15c struct {
	f func(a ...interface{}) (n int, err error)
}

func main() {
	a := NewAlds15c()
	a.main()
}

func NewAlds15c() *Alds15c {
	a := &Alds15c{}
	return a
}

func (a *Alds15c) main() {
	scanner := bufio.NewScanner(os.Stdin)
	a.handle(scanner, fmt.Println)
}

type Point struct {
	X float64
	Y float64
}

// コッホ曲線を出力
// 内分点の結果をa.fへ渡す
func (a *Alds15c) koch(d int, p1 *Point, p2 *Point) {
	if d == 0 {
		return
	}

	s := &Point{X: ((2 * p1.X) / 3) + (p2.X / 3), Y: ((2 * p1.Y) / 3) + (p2.Y / 3)}
	t := &Point{X: ((p1.X) / 3) + (2 * p2.X / 3), Y: ((p1.Y) / 3) + (2 * p2.Y / 3)}

	// rotate vector(s -> u)
	rad := math.Pi / 3
	cos60 := math.Cos(rad)
	sin60 := math.Sin(rad)
	st := &Point{X: t.X - s.X, Y: t.Y - s.Y}
	u := &Point{X: (st.X*cos60 - st.Y*sin60) + s.X, Y: (st.X*sin60 + st.Y*cos60) + s.Y}

	a.koch(d-1, p1, s)
	a.f(fmt.Sprintf("%f %f", s.X, s.Y))

	a.koch(d-1, s, u)
	a.f(fmt.Sprintf("%f %f", u.X, u.Y))

	a.koch(d-1, u, t)
	a.f(fmt.Sprintf("%f %f", t.X, t.Y))

	a.koch(d-1, t, p2)
}

func (a *Alds15c) handle(scanner *bufio.Scanner, f func(a ...interface{}) (n int, err error)) {

	a.f = f

	scanner.Split(bufio.ScanWords)
	scanner.Scan()
	d, _ := strconv.Atoi(scanner.Text())

	p1 := &Point{X: 0.0, Y: 0.0}
	p2 := &Point{X: 100.0, Y: 0.0}

	// 始点
	a.f(fmt.Sprintf("%f %f", p1.X, p1.Y))

	// コッホ曲線の内分点
	a.koch(d, p1, p2)

	// 終点
	a.f(fmt.Sprintf("%f %f", p2.X, p2.Y))
}



Measured memory_bytes: 1464
#include<bits/stdc++.h>
using namespace std;
  typedef struct{
    int left;
    int parent;
    int right;
  }node;

int n,c,num,cnt=1;

node tree[100001];

int f=3;

int main(){
  
  cin>>n;
  int k[n],id[n];
  int depth[n];
  int height[n];
  int sibling[n];
  int degree[n];

  memset(tree,-1,sizeof(tree));
  memset(depth,-1,sizeof(depth));
  memset(height,-1,sizeof(height));
  memset(sibling,-1,sizeof(sibling));
  memset(degree,0,sizeof(degree));

  for(int i=0;i<n;i++){
    cin>>id[i];
    cin>>tree[id[i]].left;
    cin>>tree[id[i]].right;
    int left=tree[id[i]].left;
    int right=tree[id[i]].right;
    if(tree[id[i]].left!=-1){
      tree[left].parent=id[i];
      sibling[left]=right;
      degree[id[i]]++;
    }
    if(tree[id[i]].right!=-1){
      tree[right].parent=id[i];
      sibling[right]=left;
      degree[id[i]]++;
    }
  }

  for(int i=0;i<n;i++){
    if(tree[id[i]].parent==-1){
      depth[id[i]]=0;
      int left=tree[id[i]].left;
      int right=tree[id[i]].right;
      depth[right]=depth[id[i]]+1;
      depth[left]=depth[id[i]]+1;
    }
    if(tree[id[i]].left==-1&&tree[id[i]].right==-1){
      height[id[i]]=0;
      int parent=tree[id[i]].parent;
      height[parent]=depth[id[i]]+1;  
    }
  }
  
  for(int j=0;j<n;j++){
    for(int i=0;i<n;i++){
      int left=tree[id[i]].left;
      int right=tree[id[i]].right;
      int parent=tree[id[i]].parent;
      if(depth[id[i]]!=-1&&left!=-1){
	depth[left]=depth[id[i]]+1;
      }
      if(depth[id[i]]!=-1&&right!=-1){
	depth[right]=depth[id[i]]+1;
      }
      if(parent!=-1&&height[parent]<height[id[i]]+1){
	height[parent]=height[id[i]]+1;
      }
    }
  }

 
  for(int i=0;i<n;i++){
    cout<<"node "<<i<<": parent = "<<tree[i].parent;
    cout<< ", sibling = "<<sibling[i]<<", degree = "<<degree[i]<<", depth = ";
    cout<<depth[i]<<", height = "<<height[i]<<", ";
    if(tree[i].parent==-1) cout<<"root"<<endl;
    else if(tree[i].left==-1&&tree[i].right==-1) cout<<"leaf"<<endl;
    else cout<<"internal node"<<endl;
  }
   
  return 0;
} 
    

      
    
    
  

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

stack<int> S;

bool judge(vector<int> b, int N);

int main() {
    int N;
    cin >> N;
    vector<int> b(N+1);
    b[0] = -1;
    for (int i = 1; i <= N; i++) {
        cin >> b[i];
    }
    if (judge(b, N)) {
        while (!S.empty()) {
            cout << S.top() << '\n';
            S.pop();
        }
    }
    else 
        cout << -1 << '\n';
        
}


bool judge(vector<int> b, int N) {
    bool flag = true;
    while(1) {
        bool done = false;
        for (int i = b.size()-1; i >= 0; i--) {
            if (b[i] == i) {
                b.erase(b.begin()+i);
                S.push(i);
                done = true;
                break;
            }
        }
        if (!done) {
            if (b.size() == 1) {
                break;}
            else {
                flag = false;
                break;
            }
        }
    }
    return flag;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int m,k;
int main() {
    cin>>m>>k;
    if (m>=2) {
        if (k<=(1<<m)-1) {
            for (int i=(1<<m)-1; i>=0; i--) {
                if (i!=k) cout<<i<<' ';
            }
            cout<<k<<' ';
            for (int i=0; i<=(1<<m)-1; i++) {
                if (i!=k) cout<<i<<' ';
            }
            cout<<k<<'\n';
        }
        else cout<<"-1\n";
    }
    else if (m==1) {
        if (k>=1) cout<<"-1\n";
        else cout<<"1 0 0 1\n";
    }
    else {
        if (k>=1) cout<<"-1\n";
        else cout<<"0 0\n";
    }
}

Measured memory_bytes: 3548
#include<cstdio>  
#include<iostream>  
#include<algorithm>  
#include<cstdlib>  
#include<cstring>
#include<string>
#include<climits>
#include<vector>
#include<cmath>
#include<map>
#include<set>
#include<queue>
#define LL long long
  
using namespace std;
  
inline char nc(){
    /* 
  static char buf[100000],*p1=buf,*p2=buf;
  if (p1==p2) { p2=(p1=buf)+fread(buf,1,100000,stdin); if (p1==p2) return EOF; }
  return *p1++;
    */return getchar();
}
  
inline void read(int &x){
  char c=nc();int b=1;
  for (;!(c>='0' && c<='9');c=nc()) if (c=='-') b=-1;
  for (x=0;c>='0' && c<='9';x=x*10+c-'0',c=nc()); x*=b;
}
  
inline void read(LL &x){
  char c=nc();LL b=1;
  for (;!(c>='0' && c<='9');c=nc()) if (c=='-') b=-1;
  for (x=0;c>='0' && c<='9';x=x*10+c-'0',c=nc()); x*=b;
}
 
inline int read(char *s)
{
    char c=nc();int len=1;
    for(;!(c>='a' && c<='z');c=nc()) if (c==EOF) return 0;
    for(;(c>='a' && c<='z');s[len++]=c,c=nc());
    s[len++]='\0';
    return len-2;
}
 
inline void read(char &x){
  for (x=nc();!(x>='A' && x<='Z');x=nc());
}
 
int wt,ss[19];
inline void print(int x){
    if (x<0) x=-x,putchar('-'); 
    if (!x) putchar(48); else {
    for (wt=0;x;ss[++wt]=x%10,x/=10);
    for (;wt;putchar(ss[wt]+48),wt--);}
}
inline void print(LL x){
    if (x<0) x=-x,putchar('-');
    if (!x) putchar(48); else {for (wt=0;x;ss[++wt]=x%10,x/=10);for (;wt;putchar(ss[wt]+48),wt--);}
}

int n,m,b[4];

LL pow(LL x,int y)
{
	LL res=1;
	for (;y;y>>=1)
	{
		if (y&1) res*=x;
		x*=x;
	}
	return res;
}

int main()
{
	read(n);read(m);
	int x;
	for (int i=1;i<=n;i++)
		read(x),b[x%2]++;
	if (b[1]==0)
	{
		if (m==0) print(pow(2LL,b[0]));
		else print(0);
	}
	else print(pow(2LL,b[0]+b[1])/2);
	puts("");
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <math.h>
#include <vector>
#include <cstdlib>
 
using namespace std;

int main(int argc, const char *argv[]) {
  int N;
  int sum = 0;

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

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

  return 0;
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline

N = [int(x) for x in input().rstrip()][::-1] + [0]
L = len(N)

dp = [[10 ** 18, 10 ** 18] for _ in range(L + 1)]
dp[0] = [0, 0]
dp[1] = [N[0], 10 - N[0]]

for i in range(2, L + 1):
    n = N[i - 1]
    dp[i][0] = min(dp[i - 1][0] + n, dp[i - 1][1] + (n + 1))
    dp[i][1] = min(dp[i - 1][0] + (10 - n), dp[i - 1][1] + (10 - (n + 1)))

print(dp[-1][0])


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

#define fast_io ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

using namespace std;

#define debug(x) cout<<(#x)<<"="<<(x)<<", ";
#define debug1(x) debug(x) cout<<'\n';
#define debug2(x1, x2) debug(x1) debug(x2) cout<<'\n';
#define debug3(x1, x2, x3) debug(x1) debug(x2) debug(x3) cout<<'\n';
#define debug4(x1, x2, x3, x4) debug(x1) debug(x2) debug(x3) debug(x4) cout<<'\n';
#define debug5(x1, x2, x3, x4, x5) debug(x1) debug(x2) debug(x3) debug(x4) debug(x5) cout<<'\n';

#define fcout cout<<fixed<<setprecision(15)
#define repp(i,j,k) for(int i=j; i<k; ++i)
#define rep(i,j) repp(i,0,j)
#define rrep(i,j,k) for(int i=j; i>=k; --i)
#define all(x) (x).begin(), (x).end()
#define sort(x) sort(x.begin(), x.end())
#define lb(x,val) lower_bound(x.begin(), x.end(), val)
#define ub(x,val) upper_bound(x.begin(), x.end(), val)
#define pb(x) emplace_back(x);

typedef long long int lli;
typedef pair<int,int> pii;
typedef pair<lli,lli> pll;
typedef vector<int> vi;
typedef vector<lli> vl;
typedef tuple<int, int, lli> tiil;

//const lli M=998244353ll;
const lli M=1000000007ll;
const double D=1.0;

int main(){
fast_io
int n; cin>>n;
cout<<(24*2-n);
return 0;
}

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

#define int long long
#define all(v) (v).begin(), (v).end()
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }

const int INF = 1e18;

int A, B, Q;
vector<int> s, t;

// 配列からkey以下の値のインデックスを返す
int bin(vector<int> &v, int key) {
   auto check = [&](int mid) -> bool {
      return v[mid] <= key;
   };

    // [l, r)
   int l = 0;
   int r = v.size();

   while (r - l > 1) {
      int mid = (l + r) / 2;
      if (check(mid)) {
         l = mid;
      } else {
         r = mid;
      }
   }

   return l;
}

int solve(int x) {
  // Right, Leftはxより右にあるか左にあるか
  // abs取るのは、値が見つからなかったときの処理をINFで統一させたいから(-INFあるとめんどい）
  int sRight = abs(*lower_bound(all(s), x));
  int sLeft = s[bin(s, x)];
  int tRight = abs(*lower_bound(all(t), x));
  int tLeft = t[bin(t, x)];

  int ret = INF;

  // (s, t) -> x -> (t, s)
  if (sLeft != INF and tLeft != INF) {
    chmin(ret, abs(x - min(sLeft, tLeft)));
  } 

  // s -> x -> t {
  if (sLeft != INF and tRight != INF) {
    chmin(ret, min(abs(x - sLeft), abs(x - tRight)) + abs(sLeft - tRight));
  }

  // t -> x -> s {
  if (tLeft != INF and sRight != INF) {
    chmin(ret, min(abs(x - tLeft), abs(x - sRight)) + abs(tLeft - sRight));
  }

  // x -> (s, t) -> (t, s)
  if (sRight != INF and tRight != INF) {
    chmin(ret, abs(max(sRight, tRight) - x));
  }

  return ret;
}

signed main() {
  cin >> A >> B >> Q;
  s.resize(A);
  t.resize(B);
  for (int i = 0; i < A; i++) {
    cin >> s[i];
  }
  for (int i = 0; i < B; i++) {
    cin >> t[i];
  }

  // 番兵を設置すると値が見つからなかったときの処理が楽になる
  s.push_back(INF);
  s.push_back(-INF);
  t.push_back(INF);
  t.push_back(-INF);
  sort(all(t));
  sort(all(s));

  while (Q--) {
    int x;
    cin >> x;
    int ans = solve(x);
    cout << ans << endl;
  }

  return 0;
}

Measured memory_bytes: 2912
n, y = input().split()
n = int(n)
y = int(y) // 1000

if y > 10 * n:
    print(-1,-1,-1)
elif y < n:
    print(-1,-1,-1)
else:
    flg = False

    for i in range(n+1):
        for j in range(n-i+1):
            k = n-i-j
            if y == i + 5 * j + 10 * k:
                print(k,j,i)
                flg = True
                break
        if flg == True:
            break

    if flg == False:
        print(-1,-1,-1)

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

using ll = int64_t;
#define int ll

#define FOR(i, a, b) for (int i = int(a); i < int(b); i++)
#define REP(i, b) FOR(i, 0, b)
#define MP make_pair
#define PB push_back
#define EB emplace_back
#define ALL(x) x.begin(), x.end()

using pi = pair<int, int>;
using vi = vector<int>;
using ld = long double;

template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
  os << "(" << p.first << "," << p.second << ")";
  return os;
}

template <class T> ostream &operator<<(ostream &os, const vector<T> &v) {
  os << "{";
  REP(i, (int)v.size()) {
    if (i)
      os << ",";
    os << v[i];
  }
  os << "}";
  return os;
}

ll read() {
  ll i;
  scanf("%" SCNd64, &i);
  return i;
}

void printSpace() { printf(" "); }

void printEoln() { printf("\n"); }

void print(ll x, int suc = 1) {
  printf("%" PRId64, x);
  if (suc == 1)
    printEoln();
  if (suc == 2)
    printSpace();
}

string readString() {
  static char buf[3341000];
  scanf("%s", buf);
  return string(buf);
}

char *readCharArray() {
  static char buf[3341000];
  static int bufUsed = 0;
  char *ret = buf + bufUsed;
  scanf("%s", ret);
  bufUsed += strlen(ret) + 1;
  return ret;
}

template <class T, class U> void chmax(T &a, U b) {
  if (a < b)
    a = b;
}

template <class T, class U> void chmin(T &a, U b) {
  if (b < a)
    a = b;
}

template <class T> T Sq(const T &t) { return t * t; }

const int mod = 1e9 + 7;

signed main() {
  int n, k;
  std::cin >> n >> k;
  map<int, int> aCnt;
  REP(i, n) {
    int tmp = read();
    if (aCnt.count(tmp) == 0)
      aCnt[tmp] = 1;
    else
      aCnt[tmp]++;
  }
  vi cnts;
  for (auto &p : aCnt)
    cnts.PB(p.second);
  sort(ALL(cnts));
  int ans = 0;
  REP(i, cnts.size() - k) ans += cnts[i];
  print(ans);
}


Measured memory_bytes: 14964
def main():
    import sys
    sys.setrecursionlimit(10**6)
    input = sys.stdin.readline
    x = int(input())
    if x < 600:
        print(8)
    elif x < 800:
        print(7)
    elif x < 1000:
        print(6)
    elif x < 1200:
        print(5)
    elif x < 1400:
        print(4)
    elif x < 1600:
        print(3)
    elif x < 1800:
        print(2)
    else:
        print(1)

if __name__ == '__main__':
    main()

Measured memory_bytes: 9192
#include <iostream>
#include <algorithm>
using namespace std;
int main()
{
  int n;
  int k;
  cin >> n >> k;
  int a[n];
  for(int i=0;i<n;i++)
  {
    int x;
    cin >>x;
    a[i]=x;
  }
  sort(a,a+n,greater<int>()); //大きい順にソートなにもなしだと小さい順
  int total=0;
  for(int i=0;i<k;i++)
  {
    total+=a[i];
  }
  cout << total << endl;
  return 0;
}
  

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

const int MAX_N = 2e6+10;
ll dp[MAX_N];
int n, k;
int l[20], r[20];
const int MOD = 998244353;

void solve()
{
	dp[1]=1;
	dp[2]=-1;
	for(int i=1;i<=n;++i){
		(dp[i]+=dp[i-1])%=MOD;
		for(int j=0;j<k;++j){
			(dp[i+l[j]]+=dp[i])%=MOD;
			(dp[i+r[j]+1]-=dp[i]-MOD)%=MOD;
		}
	}
	cout<<dp[n]<<'\n';
}

int main()
{
	cin >> n >> k;
	for(int i=0;i<k;++i){
		cin >> l[i]>>r[i];
	}
	solve();
	return 0;
}

Measured memory_bytes: 6664
#include<bits/stdc++.h>
#define ll  long long
#define FAST_IO ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define mod 1000000007
#define f(i,n)   for(int i=0;i<n;i++)

using namespace std;
/************************BELIAL**********DEVIL*********BELIAL***********DEVIL*************************/


int main()
{
  FAST_IO
  int n;
  cin>>n;
  int arr[n],dp[n];


  f(i,n)
  {
  	cin>>arr[i];
    dp[i]= INT_MAX;

  }
  dp[0]=0;
 f(i,n)
 {
      
   for(int j=i+1;j<=i+2;j++)
   {
        if(j<n)
      dp[j]= min(dp[j],dp[i]+abs(arr[j]-arr[i])); 

   }


 }
   cout<<dp[n-1];


}



Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define endl '\n';
#define rep(i,n) for(int i=0; i<(n); i++)
using namespace std;
using ll = long long;
using P = pair<int,int>;
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("Ofast")
constexpr ll INF = 1e18;
constexpr int inf = 1e9;
constexpr double INFD = 1e100;
constexpr ll mod = 1000000007;
constexpr ll mod2 = 998244353;
const double PI = 3.1415926535897932384626433832795028841971;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
// ios::sync_with_stdio(false);
// cin.tie(nullptr);
// ---------------------------------------------------------------------------

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

Measured memory_bytes: 512
import java.util.Scanner;

public class Main{
	public static void main(String args[]){
		Scanner scan = new Scanner(System.in);
		int capacityOfA = scan.nextInt();
		int waterInA = scan.nextInt();
		int waterInB= scan.nextInt();
		int printNum = waterInB - (capacityOfA - waterInA);
		if(printNum < 0){
			printNum = 0;
		}
		System.out.println(printNum);
	}
}

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

using namespace std;

int main(){
    int n;
    cin >> n;
    int a[n];
    for(int i=0;i<n;i++){
        cin >> a[i];
    }
    for(int i=n-1;i>0;i--){
        cout << a[i] << " ";
    }
    cout << a[0] << endl;
    return 0;
}


Measured memory_bytes: 3092
#!/usr/bin/env python
# -*- coding: utf-8 -*-

import sys  # {{{
import os
import time
import re
from pydoc import help
import string
import math
from operator import itemgetter
from collections import Counter
from collections import deque
from collections import defaultdict as dd
import fractions
from heapq import heappop, heappush, heapify
import array
from bisect import bisect_left, bisect_right, insort_left, insort_right
from copy import deepcopy as dcopy
import itertools
# }}}

# pre-defined{{{
sys.setrecursionlimit(10**7)
INF = 10**20
GOSA = 1.0 / 10**10
MOD = 10**9+7
ALPHABETS = [chr(i) for i in range(ord('a'), ord('z')+1)]  # can also use string module
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def DP(N, M, first): return [[first] * M for n in range(N)]
def DP3(N, M, L, first): return [[[first] * L for n in range(M)] for _ in range(N)]
from inspect import currentframe
# }}}

def solve():
    s = input()
    if s == "ABC":
        print("ARC")
    else:
        print("ABC")

    return 0

if __name__ == "__main__":# {{{
    solve()

# vim: set foldmethod=marker: }}}


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

using ll=long long;

using vi=vector<int>;
using vll=vector<ll>;
using vvi=vector<vi>;
using vs=vector<string>;

int main() {
  ll N,A,B; cin >>N >>A >>B;
  ll ans=0;
  if ((B-A)%2==0) {
    ans=(B-A)/2;
  } else {
    ans=min(A,N-B+1)+(B-A-1)/2;
  }
  cout <<ans <<endl;
  return 0;
}


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

#define rep(i,n) for (int i = 0; i < (int)(n); ++i)
#define reps(i,n) for (int i = 1; i <= (int)(n); ++i)
#define repd(i,n) for (int i = (int)(n - 1); i >= 0; --i)
#define repds(i,n) for (int i = (int)(n); i > 0; --i)
#define loop(i,x,n) for (int i = (int)(x); i < (n); ++i)
#define loops(i,x,n) for (int i = (int)(x); i <= (n); ++i)
#define loopd(i,x,n) for (int i = (int)(x); i > (n); --i)
#define loopds(i,x,n) for (int i = (int)(x); i >= (n); --i)
#define itrep(i,a) for (auto i = begin(a); i != end(a); ++i)
#define itrepd(i,a) for (auto i = rbegin(a); i != rend(a); ++i)
#define all(f,x,...) [&](decltype(x)& whole) { return (f)(begin(whole), end(whole), ##__VA_ARGS__); }(x)
using namespace std;
using ll = long long;
using ld = long double;
constexpr ll inf = static_cast<ll>(1e18);
constexpr int iinf = static_cast<int>(1e9);
constexpr double dinf = 1e10;
constexpr ld ldinf = 1e18;
ll mod = static_cast<ll>(1e9 + 7);
template<class T> constexpr int sz(const T& a) { return (int)a.size(); }
template<class T> constexpr T pow2(const T a) { return a * a; }
template<class T, class ... Args> constexpr void mins(T& a, Args... args) { a = min<T>({ a, args... }); }
template<class T, class... Args> constexpr void maxs(T& a, Args... args) { a = max<T>({ a,args... }); }
template<class a, int N, class T>
void fillArray(a(&array)[N], const T& val) { std::fill((T*)array, (T*)(array + N), val); }

int h, w, n;
int x[200005], y[200005];
set<int> s[200005];
void solve() {
    cin >> h >> w >> n;
    rep(i, n) {
        cin >> x[i] >> y[i];
        --x[i]; --y[i];
        s[x[i]].emplace(y[i]);
    }
    int ans = h;
    int maxy = 0;
    rep(i, h - 1) {
        if (s[i + 1].empty()) {
            ++maxy;
            continue;
        }
        auto l = *s[i + 1].begin();
        if (l <= maxy) {
            ans = i + 1;
            break;
        }
        if (s[i + 1].find(maxy + 1) == s[i + 1].end()) ++maxy;
    }
    cout << ans << endl;
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    solve();
    return 0;
}


Measured memory_bytes: 20608
def main():
    H, W = map(int, input().split())
    board = [list(input()) for _ in range(H)]
    new_board = []
    for i in range(H):
        new_line = ""
        for j in range(W):
            num_bomb = 0
            if board[i][j] != "#":
                for k in range(-1, 2):
                    for l in range(-1, 2):
                        idx1, idx2 = i+k, j+l
                        if idx1 >= 0 and idx2 >= 0 and idx1 < H and idx2 < W:
                            item = board[i+k][j+l]
                            if item == "#":
                                num_bomb += 1
                new_line += str(num_bomb)
            else:
                new_line += "#"

        new_board.append(new_line)

    for i in range(H):
        print(new_board[i])


if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <array>
#include <vector>

using namespace std;

int main() {

  int a, b, c, d;
  cin >> a >> b >> c >> d;
  int sum = a + b + c + d;

  cout << ( sum / 60 ) << endl << ( sum % 60 ) << endl;  
}

Measured memory_bytes: 1160
#include<iostream>
#include<iomanip>
#include<cmath>
#include<string>
#include<cstring>
#include<vector>
#include<list>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<stack>
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define mp make_pair
#define mt make_tuple
#define pqueue priority_queue
const int inf=1e9+7;
const ll mod=1e9+7;
const ll mod1=998244353;
const ll big=1e18;
const double PI=2*asin(1);

int main() {
  int N, K;
  cin>>N>>K;
  int tmp;
  int index;
  for(int i=0;i<N;++i) {
    cin>>tmp;
  }
  N -= K;
  K--;
  if(N%K==0) cout<<N/K+1<<endl;
  else cout<<N/K+2<<endl;
}


Measured memory_bytes: 3596
import std.stdio;
import std.ascii;
import std.range;
import std.array;
import std.functional;
import std.algorithm;
import std.conv;
import std.container;
import std.math;
import std.numeric;
import std.string;
import std.c.string;
import std.random;
import std.regex;
import std.typecons;

const EPS = 1e-6;
struct Point {
    double x, y;
    Point opBinary(alias op)(in Point p) const {
        if (op == "+") return Point(x + p.x, y + p.y);
        if (op == "-") return Point(x - p.x, y - p.y);
    }
    Point opBinary(alias op)(double n) const {
        if (op == "*") return Point(n * x, n * y);
        if (op == "/") return Point(n / x, n / y);
    }
}
bool EQ(in Point a, in Point b) {
    return abs(a.x - b.x) <= EPS && abs(a.y - b.y) <= EPS;
}
double norm(in Point a) {
    return sqrt(a.x * a.x + a.y * a.y);
}
Point unit(in Point a) {
    return a / norm(a);
}
double distance(in Point a, in Point b) {
    auto dx = a.x - b.x,
         dy = a.y - b.y;
    return sqrt(dx * dx + dy * dy);
}
double dot(in Point a, in Point b) {
    return a.x * b.x + a.y * b.y;
}
double cross(in Point a, in Point b) {
    return a.x * b.y - a.y * b.x;
}
double angle(in Point a, in Point b, in Point c) {
    auto p = b - a, q = c - b;
    return acos(p.dot(q) / (p.norm * q.norm)) / PI * 180;
}

int N;
double r, theta;
Point[] P;
bool[][][] C;
double[][] D;

void input() {
    scanf("%d\n", &N);
    scanf("%lf %lf\n", &r, &theta);
    P = new Point[N];
    foreach (i; 0 .. N) {
        int x, y; scanf("%d %d\n", &x, &y);
        P[i] = Point(x, y);
    }
    C = new bool[][][](N, N, N);
    foreach (i; 0 .. N) {
        foreach (j; 0 .. N) {
            foreach (k; 0 .. N) {
                if (i == j || j == k || k == i) continue;
                C[i][j][k] = angle(P[i], P[j], P[k]) < theta + EPS;
            }
        }
    }
    foreach (k; 1 .. N) C[0][0][k] = true;
    D = new double[][](N, N);
    foreach (i; 0 .. N) {
        foreach (j; 0 .. N) {
            D[i][j] = distance(P[i], P[j]);
        }
    }
}

const INF = 1e10;

void solve() {
    auto L = cast(int)(r) + 1;
    auto dp = new double[][][](2, N, N);
    foreach (i; 0 .. 2) foreach (j; 0 .. N) dp[i][j][] = INF;
    dp[0][0][0] = 0.0;
    int ans = 0;
    auto flag = true;
    foreach (c; 0 .. L - 1) {
        if (!flag) break;
        flag = false;
        foreach (i; 0 .. N) foreach (j; 0 .. N) { dp[(c + 1) & 1][i][j] = INF; }
        foreach (u; 0 .. N) {
            foreach (v; 0 .. N) {
                foreach (n; 0 .. N) {
                    if (u == n || v == n) continue;
                    if (!C[u][v][n]) continue;
                    auto nd = dp[c & 1][u][v] + D[v][n];
                    if (dp[(c + 1) & 1][v][n] > nd) {
                        dp[(c + 1) & 1][v][n] = nd;
                        if (nd < r + EPS) {
                            ans = c + 1;
                            flag = true;
                        }
                    }
                }
            }
        }
    }
    writeln(ans);
}

void main() {
    input; solve;
}

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

#define dbg(help) cerr << #help << " = " << (help) << endl;
#define int  long long
#define endl "\n"

using namespace std;

void boot_up() {
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifdef LOCAL 
    freopen("input.txt", "r", stdin); 
    freopen("output.txt", "w", stdout); 
#endif
    cout.setf(ios::fixed); cout.precision(4);
}

const int INF = 1e18, maxn = 3e5 + 1;

signed main() {
    boot_up();

    int N, K;
    cin >> N >> K;
 
    int maximum = (N - 1) * (N - 2) / 2;
 
    if (K > maximum) {
        cout << -1 << endl;
        return 0;
    }
 
    int M = (N - 1) + (maximum - K);
    cout << M << endl;
 
    for (int i = 2; i <= N; i++) {
        cout << 1 << " " << i << endl;
        M--;
    }
 
    for (int i = 2; i <= N; i++) {
        for (int j = i + 1; j <= N; j++) {
            if (M > 0) {
                cout << i << " " << j << endl;
                M--;
            }
            else {
                return 0;
            }
        }
    }

    return 0;
}


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

signed main(void)
{
	int n;
	string s, t, u;
	cin >> n;
	cout << 0 << endl;
	cin >> s; 
	cout << n - 1 << endl;
	cin >> t;
	if (s == "Vacant" || t == "Vacant") return 0;

	int l, r, m;
	l = 0;
	r = n - 1;
	while(true)
	{
		m = (l + r) / 2;
		cout << m << endl;
		cin >> u;
		if (u == "Vacant") return 0;
		if ((m  - l) % 2 == 0)
		{
			if (u != s)
			{
				r = m;
				t = u;
			}
			else
			{
				l = m;
				s = u;
			}
		}
		else
		{
			if (u == s)
			{
				r = m;
				t = u;
			}
			else
			{
				l = m;
				s = u;
			}
		}
	}
}


Measured memory_bytes: 852
// 基本テンプレート
 
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
using namespace std;
 
#define rep(i,a,n) for(int (i)=(a); (i)<(n); (i)++)
#define repq(i,a,n) for(int (i)=(a); (i)<=(n); (i)++)
#define repr(i,a,n) for(int (i)=(a); (i)>=(n); (i)--)
#define debug(...) fprintf(stderr, __VA_ARGS__)
#define int long long int
 
template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}
 
typedef pair<int, int> pii;
typedef long long ll;
 
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const ll INF = 1001001001001001LL;
const ll MOD = 1000000007LL;
 
signed main() {
    int N, K; cin >> N >> K;


    int cntz = 0, ans = 0;
    for(int A=1; A<=N; A++) {
        if(A % K == 0) cntz++;
    }
    ans += cntz*cntz*cntz;

    if(K % 2 == 1) {
        cout << ans << endl;
    }
    else {
        int cnt = 0;
        for(int A=1; A<=N; A++) {
            if(A % K == K / 2) cnt++;
        }

        ans += cnt * cnt * cnt;
        cout << ans << endl;
    }
    return 0;
}

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

typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;

#define fst first
#define snd second
#define MP make_pair
#define PB push_back

VI PS, QS, AS, NS, cnts;
int P, Q, A, N;
int T;

VVI have_n_ts;

// p / q

constexpr int MEMO_LIMIT = 2500;
int ymemo[MEMO_LIMIT][MEMO_LIMIT][2] = {};

int p_, q_;

inline void yakubun(int &p, int &q) {
    p_ = p, q_ = q;
    if (p_ < MEMO_LIMIT && q_ < MEMO_LIMIT && ymemo[p_][q_][0]) {
        p = ymemo[p_][q_][0];
        q = ymemo[p_][q_][1];
        return;
    }

    int c = __gcd(p, q);
    if (c == 1) return;
    p /= c;
    q /= c;

    if (p_ < MEMO_LIMIT && q_ < MEMO_LIMIT) {
        ymemo[p_][q_][0] = p;
        ymemo[p_][q_][1] = q;
    }
}

inline void add(int p1, int q1, int p2, int q2, int &np, int &nq) {
    np = p1 * q2 + p2 * q1;
    nq = q1 * q2;
    if (np > 0) {
        yakubun(np, nq);
    }
}

inline void sub(int p1, int q1, int p2, int q2, int &np, int &nq) {
    add(p1, q1, -1 * p2, q2, np, nq);
}

int np, nq;
inline void dfs(int p, int q, int a, int n, int before) {
    if (a > 12000) return;

    for (int t : have_n_ts[n]) {
        cnts[t] += a <= AS[t] && p == PS[t] && q == QS[t];
    }
    
    if (n >= 7) return;

    for (int i = before; i * a <= 12000; i++) {
        add(p, q, 1, i, np, nq);
        dfs(np, nq, a * i, n + 1, i);
    }
}

int main(void) {
    have_n_ts.resize(8);
    T = 0;
    while (cin >> P >> Q >> A >> N, P) {
        yakubun(P, Q);
        PS.PB(P);
        QS.PB(Q);
        AS.PB(A);
        NS.PB(N);
        for (int i = 1; i <= N; i++) {
            have_n_ts[i].PB(T);
        }
        ++T;
    }

    cnts.resize(T);

    dfs(0, 1, 1, 0, 1);

    for (auto cnt : cnts) cout << cnt << endl;

	return 0;
}

Measured memory_bytes: 48304
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
#define rep(i, n) for(int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
const ll mod = 1000000007;

vector<vector<ll>> C(60, vector<ll>(60));

void PascalTriangle() {

    rep(i, 60) {
        C[i][0] = C[i][i] = 1;
    }

    for(int i = 2; i < 60; i++) {
        for(int j = 1; j < i; j++) {
            C[i][j] = C[i-1][j] + C[i-1][j-1];
        }
    }
}

int main() {
    int n, a, b;
    cin >> n >> a >> b;

    vector<ll> v(n);
    rep(i, n) {
        cin >> v[i];
    } 
    sort(v.begin(), v.end());
    reverse(v.begin(), v.end());

    ll sum = 0;
    rep(i, a) {
        sum += v[i];
    }
    double avg = (double)sum/a;
    printf("%.7f\n", avg);

    PascalTriangle();

    ll ans = 0;
    if(v[0] != v[a-1]) {

        int x = 0, y = 0;
        rep(i, n) {
            if(v[i] == v[a-1]) {
                x++;
            }
        }
        rep(i, a) {
            if(v[i] == v[a-1]) {
                y++;
            }
        }

        ans = C[x][y];
    }
    else if(v[0] == v[a-1]) {

        int x = 0;
        rep(i, n) {
            if(v[i] == v[0]) {
                x++;
            }
        }

        for(int i = a; i <= min(b, x); i++) {
            ans += C[x][i];
        }
    }

    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <deque>
#include <climits>
#include <cmath>
#include <algorithm>
#include <string>
using namespace std;
#define ll long long int
#define ld long long double
#define vi vector<long long int>
#define vc vector<char>
#define vs vector<string>
#define pb push_back
#define mp make_pair
#define f(i,a,n) for(i = (a); i < (n); i++)
#define fi(i,a,n) for(i = (a); i <= (n); i++)
#define F first
#define S second

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

    ll n;
    cin>>n;

    vector<string> v(n);

    vector<pair<string,ll>> p(n);

    for(ll i=0;i<n;i++){
        cin>>p[i].first>>p[i].second;
        v[i] = p[i].first;
    }

    vector<pair<ll,ll>> c;

    sort(v.begin(),v.end());
    auto last = unique(v.begin(),v.end());
    v.erase(last,v.end());
    for(ll i=0;i<v.size();i++){


        for(ll j=0;j<n;j++){
            if(v[i]==p[j].first){
                c.push_back(make_pair(p[j].second,j+1));
            }
        }

        sort(c.rbegin(),c.rend());

        for(ll k=0;k<c.size();k++){
            cout<<c[k].second<<endl;
        }

        c.clear();

    }


}

Measured memory_bytes: 256
const Main = input => {
  const inp = input.split(" ");
  const hitsujiNum = parseInt(inp[0], 10);
  const ookamiNum = parseInt(inp[1], 10);
  
  if(hitsujiNum <= ookamiNum) {
    console.log("unsafe");
  } else {
    console.log("safe");
  }
}
 
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 29620
#include <bits/stdc++.h>
using namespace std;
/*{{{*/  //template
#define rep(i,n) for(int i=0;i<n;i++)
constexpr int INF = numeric_limits<int>::max()/2;
constexpr long long LINF = numeric_limits<long long>::max()/3;
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
#define sz(x) (int)(x).size()
#define debug(x) cerr<<#x<<":"<<x<<endl
#define debug2(x,y) cerr<<#x<<","<<#y":"<<x<<","<<y<<endl
//struct fin{ fin(){ cin.tie(0); ios::sync_with_stdio(false); } } fin_;
struct Double{ double d; explicit Double(double x) : d(x){} };
ostream& operator<<(ostream& os,const Double x){ os << fixed << setprecision(20) << x.d; return os; }
template<typename T> ostream& operator<<(ostream& os,const vector<T>& vec){ os << "["; for(const auto& v : vec){ os << v << ","; } os << "]"; return os; }
template<typename T,typename U> ostream& operator<<(ostream& os,const pair<T,U>& p){ os << "(" << p.first << ","<< p.second <<")"; return os; }
template<typename T> ostream& operator<<(ostream& os,const set<T>& st){ os<<"{"; for(T v:st) os<<v<<","; os <<"}"; return os; }
template<typename T,typename U> inline void chmax(T &x,U y){ if(y>x) x = y; }
template<typename T,typename U> inline void chmin(T &x,U y){ if(y<x) x = y; }
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
ll gcd(ll a,ll b){ if(b==0) return a; else return gcd(b,a%b); }
//constexpr double eps = 1e-14; 
constexpr double eps = 1e-10; 
constexpr ll mod = 1e9+7;
const int dx[]={1,0,-1,0} ,dy[] = {0,1,0,-1};
/*}}}*/

ll N;

int main(){
    cin >> N;
    vector<ll> a(N);
    rep(i,N){
        cin >> a[i];
        a[i]--;
    }

    int cnt=0;
    rep(i,N){
        int r = a[i];
        if(a[r] == i) cnt++;
    }
    cout << cnt  / 2 << endl;
}


Measured memory_bytes: 1024
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.HashMap;
import java.util.Map;

public class Main {
    static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

    public static void main(String[] args) throws Exception {
        int N = Integer.parseInt(br.readLine().trim());
        int[] A = new int[N];
        int num=0;
        for(int i=0; i<A.length; i++){
            A[i] = Integer.parseInt(br.readLine().trim());
        }
        Map<Integer,Integer> map = new HashMap<>();
        for(int i=0; i<A.length; i++){
            map.put(A[i],map.getOrDefault(A[i],0)+1);
        }
        for(Map.Entry<Integer,Integer> entry: map.entrySet()){
            if(entry.getValue()%2 != 0) num++;
        }
        System.out.println(num);

    }


    static int[] inputval() throws Exception {
        String[] strarray = br.readLine().trim().split(" ");
        int[] intarray = new int[strarray.length];
        for (int i = 0; i < intarray.length; i++) {
            intarray[i] = Integer.parseInt(strarray[i]);
        }
        return intarray;
    }

    static void array_sout(int[][] array) {
        for (int i = 0; i < array.length; i++) {
            for (int j = 0; j < array[0].length; j++) {
                System.out.print(array[i][j] + " ");
            }
            System.out.println();
        }
    }

    static void array_sout(int[] array) {
        for (int i = 0; i < array.length; i++) {
            System.out.print(array[i] + " ");
        }
        System.out.println();
    }
}

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

int main(){
  int N;
  std::cin>>N;
  std::vector<int> A(N);
  for (int i = 0; i < N; i++){
    std::cin>>A[i];
  }
  std::sort(A.begin(),A.end());
  for (int i = 0; i < N-1; i++){
    int temp1 = A[i];
    int temp2 = A[i+1];
    while(temp1 != 0){
      int temp = temp1;
      temp1 = temp2 % temp1;
      temp2 = temp;
    }
    A[i+1] = temp2;
  }
  std::cout<<A[N-1]<<std::endl;

  return 0;
}


Measured memory_bytes: 640
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.stream.IntStream;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author mikit
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        CTrainTicket solver = new CTrainTicket();
        solver.solve(1, in, out);
        out.close();
    }

    static class CTrainTicket {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int[] a = in.next().chars().map(i -> i - '0').toArray();
            for (int i = 0; i < 8; i++) {
                StringBuilder exp = new StringBuilder(Integer.toString(a[0]));
                int val = a[0];
                for (int j = 0; j < 3; j++) {
                    exp.append((i & 1 << j) > 0 ? "+" : "-");
                    exp.append(a[j + 1]);
                    val += a[j + 1] * ((i & 1 << j) > 0 ? 1 : -1);
                }
                if (val == 7) {
                    out.println(exp.append("=7"));
                    return;
                }
            }
        }

    }
}



Measured memory_bytes: 26964
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define INF (1LL<<50)
#define MOD 1000000007

int main(){
    ll N;
    cin >> N;
    vector<char> V;
    while(N>0){
        V.push_back('a'+(N-1)%26);
        N--;
        N/=26;
    }
    reverse(V.begin(),V.end());
    rep(i,V.size())cout << V[i] ;
    cout << endl;
    return 0;
}

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

using namespace std;
using ll = long long;

# define var auto

int main() {
    int num,w;
    cin >> num >> w;
    vector<ll> dp(w+1);
    for(var i=0;i<num;i++)
    {
        vector<ll> newdp(w+1);
        ll we,v;
        cin >> we >> v;
        for(var j=0;j<=w;j++)
            if(j-we>=0)
                newdp[j]=max(dp[j],dp[j-we]+v);
            else newdp[j]=dp[j];
        dp=newdp;
    }
    ll m=0;
    for(var i=0;i<=w;i++)
        m=max(m,dp[i]);
    cout << m << endl;
    return 0;
}

Measured memory_bytes: 1804
#include<cstdio>
#include<queue>
#include<utility>
#include<cstring>
#include<stack>
#include<algorithm>
#include<cmath>
#include<iostream>
#include<map>
#define MAX_N 100001
#define INF_INT 2147483647
#define INF_LL 9223372036854775807
#define REP(i,n) for(int i=0;i<(int)(n);i++)
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> P;

int main()
{
  ll N,cnt=0,ma=0,sum;
  string S;
  cin >> S;
  if(S.size() < 4){
    printf("No\n");
    return 0;
  }else{
    if(S.substr(0,4) == "YAKI"){
      printf("Yes\n");
    }else
      printf("No\n");
    return 0;
  }
  return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <cstdio>
#include <algorithm>
#define EPS (1e-10)
using namespace std;
static const int COUNTER_CLOCKWISE=1;
static const int CLOCKWISE=-1;
static const int ONLINE_BACK=2;
static const int ONLINE_FRONT = -2;
static const int ON_SEGMENT=0;
class Point{
public:
    double x,y;
    Point(double x=0, double y=0):x(x),y(y){}
    Point operator +(const Point &p){
        return Point(x+p.x,y+p.y);
    }
    Point operator -(const Point &p){
        return Point(x-p.x,y-p.y);
    }
    Point operator *(double k){
        return Point(k*x,k*y);
    }
    Point operator /(double k){
        return Point(x/k,y/k);
    }

    double norm(){
        return x*x+y*y;
    }
    double abs(){
        return sqrt(norm());
    }
};
typedef Point Vector;
struct segment{
    Point p1,p2;
};
double dot(const Vector &v1,const Vector &v2){
    return v1.x*v2.x+v1.y*v2.y;
}
double cross(const Vector &v1,const Vector &v2){
    return v1.x*v2.y-v1.y*v2.x;
}
bool isParallel(const Vector &v1,const Vector &v2){
    if(fabs(cross(v1,v2)-0.0)<EPS)return true;
    return false;
}
bool isOrthogonal(const Vector &v1,const Vector &v2){
    if(fabs(dot(v1,v2)-0.0)<EPS)return true;
    return false;
}
Point projection( Point &p, Point &p1, Point &p2){
    Vector a=p-p1;
    Vector b=p2-p1;
    double r=dot(a,b);
    double pro_abs=r/b.norm();
    Vector res=b*pro_abs;
    return Point(res.x+p1.x,res.y+p1.y);
}
Point reflection(Point &p, Point &p1, Point &p2){
    Point pro=projection(p,p1,p2);
    Vector v=pro-p;
    v=v*2;
    return Point(v.x+p.x,v.y+p.y);
}
int ccw(Point &p, Point &p1, Point &p2){
    Vector a=p-p1;
    Vector b=p2-p1;
    if(cross(a,b)>0)return COUNTER_CLOCKWISE;
    if(cross(a,b)<0)return CLOCKWISE;
    if(dot(a,b)<0)return ONLINE_BACK;
    if(a.norm()>b.norm())return ONLINE_FRONT;
    return ON_SEGMENT;
}
bool intersect(segment &s1,segment &s2){
    if(ccw(s1.p1,s2.p1,s2.p2)*ccw(s1.p2,s2.p1,s2.p2)<=0 && ccw(s2.p1,s1.p1,s1.p2)*ccw(s2.p2,s1.p1,s1.p2)<=0)
        return true;
    return false;
}
double getDistanceSP(Point &p,segment &s){
    if(dot(p-s.p1,s.p2-s.p1)<0)return (p-s.p1).abs();
    if(dot(p-s.p2,s.p1-s.p2)<0)return (p-s.p2).abs();
    return fabs(cross(p-s.p1,s.p2-s.p1)/(s.p2-s.p1).abs());
}
double Distance(segment &s1,segment &s2){
    if(intersect(s1,s2))return 0;
    return min(min(getDistanceSP(s1.p1,s2),getDistanceSP(s1.p2,s2)),min(getDistanceSP(s2.p1,s1),getDistanceSP(s2.p2,s1)));
}
Point CrossPoint(segment &s1,segment &s2){
    Vector base =s2.p2-s2.p1;
    double d1=fabs(cross(base,s1.p1-s2.p1));
    double d2=fabs(cross(base,s1.p2-s2.p1));
    double t=d1/(d1+d2);
    return (s1.p2-s1.p1)*t+s1.p1;
}
int main()
{
    int q,p0x,p0y,p1x,p1y,p2x,p2y,p3x,p3y;
    segment s1,s2;
    cin>>q;
    while(q>0){
        cin>>p0x>>p0y>>p1x>>p1y>>p2x>>p2y>>p3x>>p3y;
        s1.p1=Point(p0x,p0y);
        s1.p2=Point(p1x,p1y);
        s2.p1=Point(p2x,p2y);
        s2.p2=Point(p3x,p3y);
        Point res=CrossPoint(s1,s2);
        printf("%.8f %.8f\n",res.x,res.y);
        q--;
    }
    return 0;
}


Measured memory_bytes: 3228