akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

#define REP(i, n) for (int i = (int)(0); i < (int)(n); ++i)
#define REPE(i, n) for (int i = (int)(0); i <= (int)(n); ++i)
#define REPR(i, m, n) for (int i = (int)(m); i < (int)(n); ++i)
#define REPRE(i, m, n) for (int i = (int)(m); i <= (int)(n); ++i)
#define FOR(e, c) for (auto &e : c)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define VIDESC(v) sort(v.begin(), v.end(), greater<int>());
 
int main() {
    int n;
    cin >> n;
    vector<int> cards(n);
    REP(i,n) cin>>cards.at(i);
    VIDESC(cards);

    int alice=0, bob=0;
    REP(i,n){
        if(i%2==0)alice+=cards.at(i);
        else bob+=cards.at(i);
    }
    cout<< alice-bob <<endl;
}

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

#define rep(i, n) for(int i = 0; i < (n); ++i)
#define repr(i, n) for(int i = (n-1); i >= 0; --i)

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

typedef long long ll;
typedef pair<int, int> P;

const int MAX = 200005;
const int INF = 1001001001;
const int MOD = 1000000007;

struct UnionFind {
    vector<int> par, rank, _size;
    UnionFind(int n):par(n), rank(n), _size(n, 1) { for (int i = 0; i < n; ++i) par[i] = i; }
    int find(int x) {
        if (par[x] == x) return x;
        return par[x] = find(par[x]);
    }
    void unite(int x, int y) {
        x = find(x), y = find(y);
        if (x == y) return;
        if (rank[x] > rank[y]) swap(x, y);
        par[x] = y; _size[y] += _size[x];
        if (rank[x] == rank[y]) rank[y]++;
    }
    int size(int x) { return _size[find(x)]; }
    bool same(int x, int y) { return find(x) == find(y); }
};

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

    vector<int> p(N);
    for (auto &i : p) cin >> i;

    UnionFind uf(N+1);
    rep(i, M) {
        int x, y;
        cin >> x >> y;
        uf.unite(x, y);
    }

    int ans = 0;
    rep(i, N) {
        if (uf.same(p[i], i+1)) ans++;
    }

    cout << ans << endl;
}

Measured memory_bytes: 4764
#include <stdio.h>
#include <stdint.h>
#include <inttypes.h>
#include <stdlib.h>
#include <string.h>

typedef unsigned long long int uint64;
typedef long long int          int64;
 
#define MAX(a,b) ((a)>(b)?(a):(b))
#define MIN(a,b) ((a)<(b)?(a):(b))
#define ABS(a) ((a)>(0)?(a):-(a))

void get_N (int64 *n)
{
  int cnt;
  
  cnt = scanf("%lld", n);

  return;
}

void get_NK (int64 *n, int64 *k)
{
  int cnt;
  
  cnt = scanf("%lld %lld", n, k);

  return;
}

void get_N1234 (int64 *n1, int64 *n2, int64 *n3, int64 *n4)
{
  int cnt;

  if (n2 == NULL) {
    cnt = scanf("%lld", n1);
    return;
  }
  if (n3 == NULL) {
    cnt = scanf("%lld %lld", n1, n2);
    return;
  }
  if (n4 == NULL) {
    cnt = scanf("%lld %lld %lld", n1, n2, n3);
    return;
  }
  cnt = scanf("%lld %lld %lld %lld", n1, n2, n3, n4);
  return;
}

void omit_LF (void)
{
  char c;
  int  cnt;
  
  cnt = scanf("%c", &c);
  return;
}

char *get_S (int64 n)
{
  char *buf;
  int  i;
  int  cnt;

  buf = malloc((size_t)(n * sizeof(char)));
  if (buf == NULL) {
    return NULL;
  }

  cnt = scanf("%s", buf);

  return buf;
}

char *get_SN (int64 max, int64 *size)
{
  char *buf;
  int  i;
  int  n;
  int  cnt;

  buf = malloc((size_t)(max * sizeof(char)));
  if (buf == NULL) {
    return NULL;
  }

  cnt = scanf("%s", buf);

  n = strlen(buf);

  *size = n;
  
  return buf;
}

int64 *get_NSeq (int64 n)
{
  int64 *buf;
  int64 i;

  buf = malloc((size_t)(n * sizeof(int64)));
  for (i=0; i<n; i++) {
    get_N(&buf[i]);
  }

  return buf;
}

typedef struct _tmp_t {
  int64    a;
  int64    b;
} tmp_t;


int compare_a(const void *a, const void *b)
{
  tmp_t *x;
  tmp_t *y;

  x = (tmp_t *)a;
  y = (tmp_t *)b;

  if (x->a > y->a) return 1;
  if (x->a < y->a) return -1;

  return 0;
}

int compare_b(const void *a, const void *b)
{
  tmp_t *x;
  tmp_t *y;

  x = (tmp_t *)a;
  y = (tmp_t *)b;

  if (x->b > y->b) return 1;
  if (x->b < y->b) return -1;

  return 0;
}

void qsort_a (tmp_t *array, int size)
{
  qsort(array, size, sizeof(tmp_t), compare_a);
}

void qsort_b (tmp_t *array, int size)
{
  qsort(array, size, sizeof(tmp_t), compare_b);
}

int main()
{
  int64 N = 7;
  int i;
  char *str;
  
  str = get_S(N);

  for (i=0; i < N; i++) {
    if ((str[2] == str[3]) && (str[4] == str[5])) {
      printf("Yes");
      return 0;
    }
  }

  printf("No");
  return 0;
}



Measured memory_bytes: 128
#include <stdio.h>
#include <stdlib.h>
#define MAX 2000000
int n;

void CountingSort(int A[], int B[], int k)
{
  int C[k + 1];

  for (int i = 0; i <= k; i++)
  {
    C[i] = 0;
  }

  for (int i = 0; i < n; i++)
  {
    C[A[i]]++;
  }
  for (int i = 1; i <= k; i++)
  {
    C[i] = C[i] + C[i - 1];
  }

  int j = n;
  for (int i = 0; i < n; i++)
  {
    j = n - 1 - i;
    B[C[A[j]] - 1] = A[j];
    C[A[j]]--;
  }
}

int main()
{
  int *A;
  int *B;
  A = (int *)malloc(MAX * sizeof(int));
  B = (int *)malloc(MAX * sizeof(int));

  scanf("%d\n", &n);
  for (int i = 0; i < n; i++)
  {
    scanf("%d", &A[i]);
  }

  CountingSort(A, B, 10000);

  for (int i = 0; i < n; i++)
  {
    printf("%d", B[i]);
    if (i < n - 1)
    {
      printf(" ");
    }
    else
    {
      printf("\n");
    }
  }
  return 0;
}


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

#define LIMIT 10001

int main(void){
  while(true){
    int n, a, b, c, x;
    cin >> n >> a >> b >> c >> x;
    if(n == 0 && a == 0 && b == 0 && c == 0 && x == 0){ break; }
    
    vector<int> y(n);
    for(int i = 0; i < n; i++){ cin >> y[i]; }

    int turn, reel = 0;
    for(turn = 0; turn <= LIMIT && reel != n; turn++){
      if(x == y[reel]){ ++reel; }
      x = (a * x + b) % c;
    }

    if(turn > LIMIT){ cout << -1 << endl; }
    else{ cout << turn - 1 << endl; }
  }

  return 0;
}

Measured memory_bytes: 3100
#include <cstdio>
#include <algorithm>
#include <map>
#include <string>
#include <vector>
#include <cmath>
#include <random>
#include <climits>
#include <set>
#include <deque>
#include <queue>
#include <bitset>
#include <stack>

#define mod 1000000007
#define INF 9999999999
#define rep(i,n) for(int (i)=0; (i)<(n); (i)++)
#define P pair<int, int>

using namespace std;
using ll = long long;

int dx[] = {1, 0, -1, 0};
int dy[] = {0, 1, 0, -1};
int dx2[] = {1, 1, 0, -1, -1, -1, 0, 1};
int dy2[] = {0, -1, -1, -1, 0, 1, 1, 1};

struct edge {int from, to, cost; };

int v, e;
ll s[10000], t[10000], c[10000];
ll d[105][105];

void warshall_floyd_init(){
    rep(i, v){
        rep(j, v){
            if(i != j){
                d[i][j] = INF;
            }else{
                d[i][j] = 0;
            }
        } 
    }
}

void warshall_floyd(){
    rep(k, v)
        rep(i, v)
            rep(j, v)
                if(d[i][k] != INF && d[k][j] != INF)
                    d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
}

bool isNegativeCycle(){
    rep(i, v){
        if(d[i][i] < 0) return true;
    }
    return false;
}

void solve(){
    scanf("%d%d", &v, &e);
    warshall_floyd_init();
    rep(i, e) scanf("%lld%lld%lld", &s[i], &t[i], &c[i]);
    rep(i, e) d[s[i]][t[i]] = c[i];
    warshall_floyd();
    if(isNegativeCycle()){
        printf("NEGATIVE CYCLE\n");
        return;
    }
    rep(i, v){
        rep(j, v){
            if(d[i][j] == INF) printf("INF");
            else printf("%lld", d[i][j]);
            if(j != v-1) printf(" ");
        }
        printf("\n");
    }
}

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



Measured memory_bytes: 2900
#include <stdio.h>

int main(void)
{
	int x,sum=0,y;
	scanf("%d",&x);
	y = x;
	do {
		sum+=(x%10);
		x/=10;
	} while (x!=0);
	if (y%sum) printf("No");
	else printf("Yes");
	return 0;
}

Measured memory_bytes: 128
n = int(input())
s = list(input())

c0 = 0
c1 = 0
z0 = 0
z1 = 0
for i in range(n):
    if s[i] == "(":
        c0 += 1
    else:
        if c0 > 0:
            c0 -= 1
        else:
            c1 += 1
ans = ["("]*c1 + s + [")"]*c0
print("".join(ans))

Measured memory_bytes: 9132
#include <cstdio>
#include <map>
#include <set>
#include <algorithm>

using namespace std;

int n;
int a[111111];

int main(void) {
  set<int> s;
  map<int, int> m;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%d", a+i);
    m[a[i]] += 1;
    s.insert(a[i]);
  }

  int res = 0;
  for (auto&& x : s) {
    if (m[x] > x) res += m[x] - x;
    else if (m[x] < x) res += m[x];
  }
  printf("%d\n", res);
  return 0;
}


Measured memory_bytes: 9728
/**********************
 * Author: Cloud_     *
 * Date:   16.06.2020 * 
 * Time:   02.47.55   *
 *                    *
***********************/
#include <bits/stdc++.h>
using namespace std;

#define gap " "
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define ok cout<<"ok"<<endl
#define dbg(x) cout<<(#x)<<" is "<<x<<endl
#define fastio {ios_base::sync_with_stdio(false);cin.tie(NULL);}

typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;

const int N=100009;
int ar[14],br[15][15],cr[20];
void clr(int n)
{
	int i;
	for(i=0; i<=n; i++)
	cr[i]=0;	
}
int checkbit(int n,int pos)
{
	return ((n>>pos) & 1);
}
int check(int x,int m)
{
	int i;
	for(i=1; i<=m; i++)
	{
		if(cr[i]<x) return 0;
	}

	return 1;
}
int main()
{
  
   int k,n,m,x,i,j,sz,sum,mn=INT_MAX;
   scanf("%d %d %d",&n,&m,&x);

   for(i=1; i<=n; i++)
   {
   	 scanf("%d",&ar[i]);
   	 for(j=1; j<=m; j++)
   	 {
   	 	scanf("%d",&br[i][j]);
   	 }
   }

  
   sz= 1 << n;
   for(i=0; i<sz; i++)
   {
   	 clr(m+2); sum=0;
   	 for(j=0; j<n; j++)
   	 {
       if(checkbit(i,j))
       {
         sum+=ar[j+1];
         for(k=1; k<=m; k++)
         {
         	cr[k]+=br[j+1][k];
         }
       }
   	 }

   	 if(check(x,m) && sum<mn) mn=sum;
   }

   if(mn==INT_MAX) printf("-1\n");
   else printf("%d\n",mn);
   
  return 0;
}

Measured memory_bytes: 3828
import java.io.*;
import java.util.*;

public class Main {
	public static void main(String[] args) {
		try {
			BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
			int T = Integer.parseInt(in.readLine());
			for (int i = 0; i < T; i++) {
				String[] sar = in.readLine().split(" ");
				int[] side = new int[3];
				for (int j = 0; j < 3; j++) {
					side[j] = Integer.parseInt(sar[j]);
				}
				Arrays.sort(side);
				if (side[0] * side[0] + side[1] * side[1] == side[2] * side[2]) {
					System.out.println("YES");
				} else {
					System.out.println("NO");
				}
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}

Measured memory_bytes: 10000
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
using namespace std;
typedef vector<int> vi;
#define repab(i,a,b) for(int i=a;i<b;i++)

int main(int argc, char **argv)
{
  const int margin = 3;
  const int field_size = 8;
  map<char, pair<vi, vi>> m;
  m['A'] = make_pair(vi({-1,  0, -1}), vi({ 0, -1, -1}));
  m['B'] = make_pair(vi({ 0,  0,  0}), vi({-1, -2, -3}));
  m['C'] = make_pair(vi({-1, -2, -3}), vi({ 0,  0,  0}));
  m['D'] = make_pair(vi({ 0,  1,  1}), vi({-1, -1, -2}));
  m['E'] = make_pair(vi({-1, -1, -2}), vi({ 0, -1, -1}));
  m['F'] = make_pair(vi({ 0, -1, -1}), vi({-1, -1, -2}));
  m['G'] = make_pair(vi({-1,  0,  1}), vi({ 0, -1, -1}));
  char c;
  int x, y;
  for (;;) {
    vector<vi> field(field_size+margin*2, vi(field_size+margin*2, 0));
    x = y = 0;
    repab (j, margin, field_size+margin) {
      repab (i, margin, field_size+margin) {
        cin.get(c);
        field[i][j] = c-'0';
        if (field[i][j]) {
          x = i;
          y = j;
        }
      }
      cin.get(c); // maybe '\n'
    }
    if (cin.eof())
      break;
    cin.get(c); // maybe '\n'

    for (char c = 'A'; c <= 'G'; c++) {
      vi& cordx = m[c].first;
      vi& cordy = m[c].second;
      if (field[x][y]
          && field[x+cordx[0]][y+cordy[0]]
          && field[x+cordx[1]][y+cordy[1]]
          && field[x+cordx[2]][y+cordy[2]]) {
        cout << c << endl;
        break;
      }
    }
  }
  return 0;
}

Measured memory_bytes: 1172
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  string T= "No";
  cin >> N;
  for(int i=1; i<10; i++){
    for(int j=1; j<10; j++){
      if (N == i * j){
        T = "Yes";
        break;
      }
      else
        continue;
    }
  }
  cout << T << endl;
}

Measured memory_bytes: 256
import scala.io.StdIn.{readInt, readLine};

object Main {
    def main(args: Array[String]): Unit = {
        val n = readInt();
        val arr = readLine().split(" ").map(_.toInt);
        sort(arr);
    }
    def sort(arr: Array[Int]): Unit = {
        for (i <- 0 until arr.length) {
            val v = arr(i);
            var j = i - 1;
            while (j >= 0 && v < arr(j)) {
                arr(j + 1) = arr(j);
                j -= 1;
            }
            arr(j + 1) = v;
            println(arr.mkString(" "));
        }
    }
}


Measured memory_bytes: 46080
#include<bits/stdc++.h>
using namespace std;
#define FastRead ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define int long long int
#define ll int
#define bits_count __builtin_popcountll
#define endl '\n'
#define double long double
#define ld double
#define FOR(i,a,n) for (ll i=(a);i<=(n);++i)
#define RFOR(i,a,n) for (ll i=(n);i>=(a);--i)
#define ZERO(a) memset((a),0,sizeof((a)))
#define MINUS(a) memset((a),-1,sizeof((a)))
#define f first
#define s second
#define pb push_back
#define mk make_pair
#define all(g) g.begin(),g.end()
#define sz(x) (ll)x.size()
#define pr pair<int,int>
int fastMax(int x, int y) { return (((y-x)>>(32-1))&(x^y))^y; }
int fastMin(int x, int y) { return (((y-x)>>(32-1))&(x^y))^x; }
    
// #include <ext/pb_ds/assoc_container.hpp> // Common file
// #include <ext/pb_ds/tree_policy.hpp>     // Including tree_order_statistics_node_updat
// using namespace __gnu_pbds;
// typedef tree<ll, null_type, less_equal<ll>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
// const int RANDOM = chrono::high_resolution_clock::now().time_since_epoch().count();
// struct chash { int operator()(int x) const { return x ^ RANDOM; }};
// cc_hash_table<int, int, hash<int>> cnt;

int dx[] = {0,0,-1,1};
int dy[] = {1,-1,0,0};

vector<vector<int>> dist[5];
vector<vector<char>> a;

#define prx pair<pair<int,pair<int,int>>,pair<int,int>>
void solve(){
    int H,W,K; cin>>H>>W>>K;
    int x1,y1,x2,y2; cin>>x1>>y1>>x2>>y2;

    a.resize(H+1);
    FOR(i,0,H) a[i].resize(W+1,'@');

    FOR(j,0,4){
        dist[j].resize(H+1);
        FOR(i,0,H) dist[j][i].resize(W+1,1e10);
    }
    FOR(k,0,4) FOR(i,0,H) FOR(j,0,W)  dist[k][i][j] = 1e15;    
    FOR(i,1,H) FOR(j,1,W) cin>>a[i][j];

    priority_queue<prx,vector<prx>,greater<prx>> pq;
    
    pq.push(mk(mk(0,mk(0,4)),mk(x1,y1)));
    dist[4][x1][y1] = 0;

    while(pq.size()){
        auto top = pq.top(); pq.pop();
        int dis = top.f.f; 
        int k_left = top.f.s.f,dir = top.f.s.s;
        int x = top.s.f,y = top.s.s;
        
        FOR(d,0,3){
            int nx = x + dx[d],ny = y + dy[d];

            if(nx < 1 || ny < 1 || nx > H || ny > W) continue;
            if(a[nx][ny] == '@') continue;

            int n_dis,n_k_left;

            if(dir == d){
                if(k_left > 0){
                    n_k_left = k_left-1;
                    n_dis = dis;
                }else n_k_left = K-1,n_dis = dis+1;
            }else {
                n_k_left = K-1;
                n_dis = dis+1;
            }

            if(n_dis >= dist[d][nx][ny]) continue;
            else {
                pq.push(mk(mk(n_dis,mk(n_k_left,d)),mk(nx,ny)));
                dist[d][nx][ny] = n_dis;
            }
        }
    }

    int ans = 1e10;
    FOR(i,0,4) ans = min(ans,dist[i][x2][y2]);

    if(ans >= 1e10) cout<<-1<<endl;
    else cout<<ans<<endl;
}
    
signed main(){
    
    FastRead;     

    int t = 1; 
    // cin>>t;
    FOR(i,1,t){
        // cout<<"Case #"<<i<<": ";
        solve();
    }
}
    




Measured memory_bytes: 83364
class Factorials:
    def __init__(self, n=10**6, mod=10**9 + 7):
        self.mod = mod

        # self.fac[i] ≡ i! (factorial:階乗)
        self.fac = [1] * (n+1)
        for i in range(2, n+1):
            self.fac[i] = self.fac[i-1] * i % mod

        # self.rec[i] ≡ 1 / i! (reciprocal:逆数)
        self.rec = [1] * (n+1)
        self.rec[n] = pow(self.fac[n], mod-2, mod)
        for i in range(n-1, 1, -1):
            self.rec[i] = self.rec[i+1] * (i+1) % mod

    # comb(n, r) ≡ nCr
    def comb(self, n, r):
        return self.fac[n] * self.rec[r] * self.rec[n - r] % self.mod

x, y = map(int, input().split())

if (x + y) % 3 != 0:
    print(0)
    exit()
if y < x/2 or 2*x < y:
    print(0)
    exit()

n = (x + y) // 3
r = x - n
c = Factorials(n)
print(c.comb(n, r))


Measured memory_bytes: 74680
/*
 ▓█████▄  ▄████▄  ▓██   ██▓ ██▓███   ██░ ██ ▓█████  ██▀███
▒██▀ ██▌▒██▀ ▀█   ▒██  ██▒▓██░  ██▒▓██░ ██▒▓█   ▀ ▓██ ▒ ██▒
 ░██   █▌▒▓█    ▄   ▒██ ██░▓██░ ██▓▒▒██▀▀██░▒███   ▓██ ░▄█ ▒
 ░▓█▄   ▌▒▓▓▄ ▄██▒  ░ ▐██▓░▒██▄█▓▒ ▒░▓█ ░██ ▒▓█  ▄ ▒██▀▀█▄
 ░▒████▓ ▒ ▓███▀ ░  ░ ██▒▓░▒██▒ ░  ░░▓█▒░██▓░▒████▒░██▓ ▒██▒
  ▒▒▓  ▒ ░ ░▒ ▒  ░   ██▒▒▒ ▒▓▒░ ░  ░ ▒ ░░▒░▒░░ ▒░ ░░ ▒▓ ░▒▓░
  ░ ▒  ▒   ░  ▒    ▓██ ░▒░ ░▒ ░      ▒ ░▒░ ░ ░ ░  ░  ░▒ ░ ▒░
  ░ ░  ░ ░         ▒ ▒ ░░  ░░        ░  ░░ ░   ░     ░░   ░
    ░    ░ ░       ░ ░               ░  ░  ░   ░  ░   ░
  ░      ░         ░ ░
*/
//focus less on how much problem you should solve within a fixed time and focus more on getting the problem solved and
//learning something from it
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define rep(i,a,b) for(ll i=a; i<b; i++)
#define per(i,a,b) for(ll i=a; i>=b; i--)
#define ll long long int
#define ld long double
#define vi vector<ll>
#define vii vector <pair<ll,ll> >
#define sedes set <ll, greater <ll> >
#define seasc set <ll>
#define pb push_back
#define mkp make_pair
#define ff first
#define ss second
#define MOD 1000000007
#define prec(n) fixed<<setprecision(n)
#define maxpq priority_queue<int>
#define minpq priority_queue<int, vector<int>, greater<int> >
#define umap unordered_map<ll, ll>
#define map map<ll, ll>
#define autoit(x,it) for(auto it = x.begin(); it != x.end(); it++)
#define mems(a, i) memset(a, i, sizeof(a))
#define endl '\n'
#define all(v) v.begin(),v.end()
#define gcd(a,b) __gcd((a),(b))
#define lcm(a,b) ((a)*(b))/gcd((a),(b))
#define printx(x) printf("%lld\n",x);
#define printxy(x,y) cout << x << y <<endl;
#define printxyz(x,y,z) cout << x << y << z <<endl;
#define deba(a) cout << #a << a << endl;
#define debab(a,b) cout << #a << a << #b << b << endl;
int main()
{
	fast;
	ll a;
	cin >> a;
	cout << a + (a * a) + (a * a * a) << endl;
	return 0;
}

Measured memory_bytes: 3604
#include "bits/stdc++.h"
// Begin Header {{{
#define all(x) (x).begin(), (x).end()
#define rep(i, s, n) for (i64 i = (s), i##_limit = (n); i < i##_limit; ++i)
#define repr(i, s, t) for (i64 i = (s), i##_limit = (t); i >= i##_limit; --i)
#define var(type, ...) \
    type __VA_ARGS__;  \
    read(__VA_ARGS__);
#ifndef DBG
#define dump(...)
#endif
using namespace std;
using i64 = int_fast64_t;
using pii = pair<i64, i64>;
template <class T, class U>
inline bool chmax(T &a, const U &b) {
    return b > a && (a = b, true);
}
template <class T, class U>
inline bool chmin(T &a, const U &b) {
    return b < a && (a = b, true);
}
constexpr int INF = 0x3f3f3f3f;
constexpr i64 LINF = 0x3f3f3f3f3f3f3f3fLL;

template <class T>
inline vector<T> makeV(const T &initValue, size_t sz) {
    return vector<T>(sz, initValue);
}

template <class T, class... Args>
inline auto makeV(const T &initValue, size_t sz, Args... args) {
    return vector<decltype(makeV<T>(initValue, args...))>(
        sz, makeV<T>(initValue, args...));
}

template <class T>
inline istream &operator>>(istream &is, vector<T> &vec) {
    for (auto &e : vec) is >> e;
    return is;
}

inline void read() {}

template <class Head, class... Tail>
inline void read(Head &head, Tail &... tail) {
    cin >> head;
    read(tail...);
}

inline void print() { cout << "\n"; }

template <class Head, class... Tail>
inline void print(Head &&head, Tail &&... tail) {
    cout << head;
    if (sizeof...(tail)) cout << ' ';
    print(forward<Tail>(tail)...);
}

template <class T>
inline ostream &operator<<(ostream &os, const vector<T> &vec) {
    static constexpr const char *delim[] = {" ", ""};
    for (const auto &e : vec) os << e << delim[&e == &vec.back()];
    return os;
}

template <class Container>
struct Rev {
    Container &x_;
    inline Rev(Container &x) : x_(x) {}
    inline auto begin() { return rbegin(x_); }
    inline auto end() { return rend(x_); }
};
// }}} End Header

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    var(double, r);
    cout << fixed << setprecision(12);
    print(2 * r * M_PI);

    return 0;
}


Measured memory_bytes: 3824
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		sc.nextLine();
		int minPoint = 0;
		int minRank = 0;
		for (int i = 0; i < N; i++) {
			int Ai = sc.nextInt();
			int Bi = sc.nextInt();
			sc.nextLine();
			if (i == 0 || Bi < minPoint) {
				minPoint = Bi;
				minRank = Ai;
			}
		}
		sc.close();
		
		System.out.println(minRank + minPoint);
	}
}

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

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

const int maxn = 1e5+10;
const int mod = 1e9+7;

using namespace std;

void solve(){
    int n,k;
    cin>>n>>k;
    vi vs(n);
    for(int &x:vs) cin >> x;
    sort(all(vs));
    int s=0;
    for(int i=0;i<k;++i){
        s+=vs[i];
    }
    cout<<s<<endl;
}

int32_t main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int t=1;
    //cin>>t;
    while(t--){
        solve();
    }
    return 0;
}

Measured memory_bytes: 3652
fun main(args: Array<String>) {
    val (h, w) = readLine()!!.split(' ').map(String::toInt)
    val aMap = Array(h) { readLine()!!.split(' ').map(String::toLong).toLongArray() }
    val bMap = Array(h) { readLine()!!.split(' ').map(String::toLong).toLongArray() }
    val diffMap = Array(h) { IntArray(w) }
    for (r in 0 until h) {
        for (c in 0 until w) {
            diffMap[r][c] = Math.abs(aMap[r][c] - bMap[r][c]).toInt()
        }
    }
 
    val size = (h + w) * 80
    val dp =
            Array(h) {
                Array(w) {
                    BooleanArray(size) { false }
                }
            }
    dp[0][0][Math.abs(aMap[0][0] - bMap[0][0]).toInt()] = true
    for (r in 0 until h) {
        for (c in 0 until w) {
            val diff = diffMap[r][c]
            for (i in 0 until size) {
                val minus = Math.abs(i - diff)
                val plus = i + diff
                if (r - 1 >= 0) {
                    if (dp[r - 1][c][i]) {
                        dp[r][c][plus] = true
                        dp[r][c][minus] = true
                    }
                }
                if (c - 1 >= 0) {
                    if (dp[r][c - 1][i]) {
                        dp[r][c][plus] = true
                        dp[r][c][minus] = true
                    }
                }
            }
        }
    }
 
    val min = dp[h - 1][w - 1].indexOfFirst { it }
    println(min)
}

Measured memory_bytes: 158648
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <string.h>
using  namespace  std;

#define ff first
#define ss second
#define pb push_back
#define ll long long
#define mod 1000000007
#define ull unsigned long long
#define mst(ss,b) memset(ss,b,sizeof(ss));
#define pl(x) cout << #x << "= " << x << endl;
const int inf = 0x3f3f3f3f;
const int N = 3e3+10;

vector<int>E[N];
int n, a[N], sg[N];

void dfs(int u, int fa){
    sg[u] = 0;
    for(auto v : E[u]){
        if(v == fa || a[v] >= a[u])continue;
        dfs(v, u);
        if(!sg[v])sg[u] = 1;
    }
}

int  main(){
    scanf("%d", &n);
    for(int i=1; i<=n; i++)scanf("%d", &a[i]);
    for(int i=1; i<n; i++){
        int u, v; scanf("%d%d", &u, &v);
        E[u].pb(v);
        E[v].pb(u);
    }
    for(int i=1; i<=n; i++){
        dfs(i, -1);
        if(sg[i])printf("%d ", i);
    }
//    int m = ans.size();
//    for(int i=0; i<m; i++)printf("%d%c", ans[i], "\n"[i == m-1]);
    return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long int ll;

int main(){

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

    ll res = t;

    for(int i=0; i<n-1; i++){
        res += min(timetable[i+1] - timetable[i], t);
    }

    cout << res << endl;

    return 0;
}

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

int main() {
    int n; cin >> n;
    long long a[200010];
    for (int i = 1; i <= n; i++) {
        cin >> a[i];
    }
    map<long long, int> diff;
    for (int i = 1; i <= n; i++) {
        diff[a[i] + i]++;
    }
    long long res = 0;
    for (int i = 1; i <= n; i++) {
        res += diff[i - a[i]];
    }
    cout << res << endl;
    return 0;
}


Measured memory_bytes: 27856
#include <bits/stdc++.h>
using namespace std;
int main(){
  string S;
  cin >>S;
  int check=0;
  for(int i=1;i<4;i++){
    if(S.at(i-1)==S.at(i)){check=1;}
  }
  if(check==1){cout <<"Bad"<<endl;}
  else{cout <<"Good"<<endl;}
  }

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;

class F
{
	static void Main()
	{
		var n = int.Parse(Console.ReadLine());
		var rs = new int[n - 1].Select(_ => Console.ReadLine().Split().Select(int.Parse).ToArray()).ToArray();
		var map = rs.Concat(rs.Select(r => new[] { r[1], r[0] })).ToLookup(r => r[0], r => r[1]);

		var tour = new int[n + 1].Select(_ => new List<int>()).ToArray();
		var c = 0;
		var q = new Stack<int>();
		var parents = new Stack<int>();
		var u = new bool[n + 1];

		q.Push(1);
		parents.Push(0);
		while (q.Any())
		{
			var p = q.Peek();
			if (!u[p])
			{
				u[p] = true;
				var p0 = parents.Peek();
				if (p != 1) tour[p0].Add(++c);
				foreach (var x in map[p])
				{
					if (x == p0) continue;
					q.Push(x);
				}
				parents.Push(p);
			}
			else
			{
				if (p != 1) tour[p].Add(++c);
				q.Pop();
				parents.Pop();
			}
		}

		Console.WriteLine((tour.Select(l => Hole(l, n - 1)).Aggregate((x, y) => x + y) / 2).V);
	}

	static MInt Hole(List<int> l, int m)
	{
		if (l.Count < 2) return 0;

		MInt bSum = 0;
		for (int i = 0; i < l.Count; i++)
		{
			var c = ((l[(i + 1) % l.Count] - l[i]) / 2 + m) % m;
			bSum += ((MInt)2).Pow(c) - 1;
		}
		return 1 - (1 + bSum) / ((MInt)2).Pow(m);
	}
}

struct MInt
{
	const int M = 1000000007;
	public long V;
	public MInt(long v) { V = (v %= M) < 0 ? v + M : v; }

	public static implicit operator MInt(long v) => new MInt(v);
	public static MInt operator +(MInt x) => x;
	public static MInt operator -(MInt x) => -x.V;
	public static MInt operator +(MInt x, MInt y) => x.V + y.V;
	public static MInt operator -(MInt x, MInt y) => x.V - y.V;
	public static MInt operator *(MInt x, MInt y) => x.V * y.V;
	public static MInt operator /(MInt x, MInt y) => x * y.Inv();

	public MInt Pow(int i) => MPow(V, i);
	public MInt Inv() => MPow(V, M - 2);

	static long MPow(long b, int i)
	{
		for (var r = 1L; ; b = b * b % M)
		{
			if (i % 2 > 0) r = r * b % M;
			if ((i /= 2) < 1) return r;
		}
	}
}


Measured memory_bytes: 73500
#include <cstdio>
#include <cmath>
#include <algorithm>
using namespace std;

bool ans[1000];

bool judge(int a,int b,int c) {
	if (pow(c,2)==(pow(a,2)+pow(b,2))) {
		return true;
	}
	return false;
}

int main() {
	int N,aside[3];
	scanf("%d",&N);
	for(int i=0;i<N;++i) {
		scanf("%d %d %d",&aside[0],&aside[1],&aside[2]);
		sort(aside,aside+3);
		if(judge(aside[0],aside[1],aside[2])) { ans[i]=true; }
		else { ans[i]=false; }
	}
	for(int i=0;i<N;++i) { 
		if(ans[i]) { puts("YES"); }
		else { puts("NO"); }
	}
	return 0;
}

Measured memory_bytes: 1028
fun main(args: Array<String>) {
  var dpA = 0
  var dpB = 0
  var dpC = 0

  val n = readLine()!!.toInt()
  for (i in 0 until n) {
    val (a, b, c) = readLine()!!.split(" ").map { it.toInt() }
    val prevA = dpA
    val prevB = dpB
    val prevC = dpC
    dpA = Math.max(prevB, prevC) + a
    dpB = Math.max(prevA, prevC) + b
    dpC = Math.max(prevB, prevA) + c
  }

  println(Math.max(dpA, Math.max(dpB, dpC)))
}



Measured memory_bytes: 59868
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPS(i, x) for (int i = 1; i <= (int)(x); i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define FORS(i, m, n) for (int i = m; i <= n; i++)
#define INF 2e9
#define MOD (1000000007)
#define EPS 1e-9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef long long int lli;
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    string L;
    cin >> L;
    int N = L.size();
    vector<ll> a(N + 1);
    a[0] = 1;
    REPS(i, N - 1)
    {
        a[i] = (a[i - 1] * 3) % MOD;
    }
    int count = 0;
    int p = 1;
    REP(i, N)
    {
        if (L[i] == '1')
        {
            count = (count + a[N - 1 - i] * p) % MOD;
            p = (p * 2) % MOD;
        }
    }
    count = (count + p) % MOD;
    cout << count << "\n";
}

Measured memory_bytes: 1232
#include <iostream>
#include <map>
#include <vector>

using namespace std;

typedef long long ll;

const ll DIV = 1e+9 + 7;

long long factorial(long long n, long long mod) {
    long long ret = 1;
    for (long long i = 1; i <= n; i++) {
        ret = (ret * i) % mod;
    }
    return ret;
}

long long inv_mod(long long n, long long mod) {
    long long a = n % mod, b = mod - 2, ret = 1;
    while (b > 0) {
        if (b & 1) ret = (ret * a) % mod;
        a = (a * a) % mod;
        b >>= 1;
    }
    return ret;
}

long long nPr(long long n, long long r, long long mod) {
    long long ret = 1;
    for (long long i = n; i >= n - r + 1; i--) {
        ret = ret * (i % mod) % mod;
    }
    return ret;
}

long long nCr(long long n, long long r, long long mod) {
    return nPr(n,r,mod) * inv_mod(factorial(r,mod),mod) % mod;
}

long long nHr(long long n, long long r, long long mod) {
    return nCr(n+r-1,r,mod);
}

map<ll, ll> prime_factor(ll n){
  map<ll, ll> res;
  for (ll i = 2; i * i <= n; i++) {
    while (n % i == 0) {
      ++res[i];
      n /= i;
    }
  }
  if (n != 1) res[n] = 1;
  return res;
}

int main(int argc, char const *argv[]) {
  ll n, m;
  cin >> n >> m;
  map<ll, ll> pfmp;
  pfmp = prime_factor(m);
  vector<ll> vec, many;
  ll ans = 1;
  for(auto x : pfmp) {
    ans *= nHr(n, x.second, DIV);
    ans %= DIV;
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
        // 文字列の入力
		String in = sc.next();

        String[] dow = {"SUN","MON","TUE","WED","THU","FRI","SAT"};

        int i;
        for(i = 0; i < dow.length; i++){    

            if(in.equals(dow[i])){ 
                break;
            }
            
        }
         
        // 出力
            System.out.println(7 - i);   
	}
}

Measured memory_bytes: 22100
#include <cstdio>
#include <cstring>
#include <vector>
#include <set>
#include <cstdlib>
#include <map>

#define X first
#define Y second
#define PB push_back

using namespace std;

typedef long long ll;
typedef pair < int, int > pii;
typedef vector < int > vi;

const int N = 2e5 + 500;
const int INF = 0x3f3f3f3f;
const int MOD = 1e9 + 7;
const int BASE = 31337;

char s[N];
int n, sol = 0, lst = 0;

int main(){
	scanf("%s", s);
	n = strlen(s);
	for(int i = 0;i < n;){
		int cur = 0;
		for(;i < n && (cur == lst || cur == 0);i++)
			cur = BASE * cur + s[i];
		if(lst == cur && i == n)
			break;
		lst = cur;	
		sol++;
	}
	printf("%d\n", sol);
	return 0;
}


Measured memory_bytes: 384
#include"bits/stdc++.h"
#include<boost/multi_array.hpp>
#include<boost/optional.hpp>
#include<boost/range/irange.hpp>
#include<boost/range/algorithm.hpp>
#include<boost/range/adaptors.hpp>
using namespace std;
namespace adaptor = boost::adaptors;

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep3(i,m,n) for(int (i)=m;(i)<=(n);(i)++)
#define rep3rev(i,m,n) for(int (i)=m;(i)>=(n);(i)--)
typedef long long ll;

void Main()
{
	int N;
  	cin >> N;
  	vector<int> A(N);
  	rep(i,N) cin >> A[i];
  	sort(A.begin(), A.end());
  	int count = 1;
  	int ans = 0;
  	rep(i,N-1){
		if(A[i] == A[i+1]){
        	count++; 
        }
      	else{
        	ans += count%2;
          	count = 1;
        }
    }
  	ans += count%2;
  	cout << ans << endl;
	return;
}

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

Measured memory_bytes: 640
#include<cstdio>
#include<algorithm>
using namespace std;
char s[5];
int main(){
	scanf("%s",s+1);
	int b=0,a=0;
	for(int i=1;i<=3;i++){
		if(s[i]=='R'){
			a++;
		}
		if(s[i]=='S'){
			if(a>b) b=a;
			a=0;
		}
	}
	if(a>b) b=a;
	printf("%d",b);
	return 0;
}

Measured memory_bytes: 1712
#include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<vector<int> > vvi;
typedef vector<ll> vl;
typedef vector<vector<ll> > vvl;
#define REP(var, a, b) for (int var = (a); var < (b); var++)
#define rep(var, n) for (int var = 0; var < (n); ++var)
#define ALL(c) (c).begin(), (c).end()
#define rALL(c) (c).rbegin(), (c).rend()
ll MOD = 1000000007;

int main() {
  //
  ll n;
  cin >> n;
  vl v(n);
  rep(i, n) cin >> v[i];
  sort(ALL(v), greater<ll>());
  double ans = 0;
  double d = 2.0;
  rep(i, n) {
    if (i < n - 2) {
      ans += v[i] / d;
      d *= 2.0;
    } else {
      ans += (v[i] + v[i + 1]) / d;
      break;
    }
  }
  cout << setprecision(10) << fixed << ans << endl;
  return 0;
}


Measured memory_bytes: 888
#include <iostream>
#include <string>
#include <map>
#include <vector>
#include <bitset>
#include <iomanip>
#include <deque>
#include <tuple>
#include <algorithm>

using namespace std;

int main()
{
    double a, b, c;

    cin >> a >> b >> c;

    cout << (a + b) * c / 2 << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
constexpr long long MOD = 1000000007;
constexpr long long INF = 1LL << 60;
const long double PI = acosl(-1.0);
constexpr long double EPS = 1e-11;
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
int main(){
ll n;
cin >> n;
vector<ll> a(n);
for (ll i = 0; i < n; i++) cin >> a[i];
vector<ll> left(n+1, 0), right(n+1, 0);

for (int i = 0; i < n; ++i) left[i + 1] = left[i] ^ a[i];
for (int i = n-1; i >= 0; --i) right[i] = right[i+1]^a[i];
for (int i = 0; i < n; ++i) {
        // 左側
        ll l = left[i];

        // 右側
        ll r = right[i+1];
        ll res = l ^ r;
        cout << res << " ";
}}

Measured memory_bytes: 7944
#include "bits/stdc++.h"
#define ll long long
#define inf 1000000007 //10^9+7
#define sort(vec) sort((vec).begin(),(vec).end());
#define rever(vec) reverse((vec).begin(),(vec).end());
#define unsort(vec) sort((vec)); rever((vec));
using namespace std;

int main() {
  string s;
  cin>>s;
  string f="000";
  int ans=0;
  int e=s.size()-2;
  vector<int>vec(e);
  for(int i=0;i<e;i++) {
    f.at(0)=s.at(i);
    f.at(1)=s.at(i+1);
    f.at(2)=s.at(i+2);
    ans=stoi(f);
    vec.at(i)=abs(753-ans);
  }
  sort(vec);
  cout<<vec.at(0)<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <utility>
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
using namespace std;
template<class T>bool chmax(T &a, const T &b) { if(a < b){ a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if(a > b){ a = b; return 1; } return 0; }
int main()
{
  int n;cin >> n;
  vector<string> s(n);
  rep(i,n) cin >> s[i];
  
  using pi = pair<int,int>;
  vector<pi> up, down;
  rep(i,n) {
    int a = 0;
    int b = 0;
    int m = s[i].size();
    rep(j,m) {
      if(s[i][j] == '(') a++;
      else a--;
      chmin(b, a);
    }
    if(a >= 0) up.emplace_back(a, b);
    else {
      a = 0;
      b = 0;
      rep(j,m) {
	if(s[i][m-1-j] == ')') a++;
	else a--;
	chmin(b, a);
      }
      down.emplace_back(a, b);
    }
  }
  sort(up.begin(), up.end(), [](pi a, pi b) {
			       return a.second > b.second;
			     });

  sort(down.begin(), down.end(), [](pi a, pi b) {
			       return a.second > b.second;
			     });  
  
  int nowup = 0;
  for(auto p: up) {
    if(nowup + p.second < 0) {
      cout << "No" << "\n";
      return 0;
    }
    else nowup += p.first;
  }

  int nowdo = 0;
  for(auto p: down) {
    if(nowdo + p.second < 0) {
      cout << "No" << "\n";
      return 0;
    }
    else nowdo += p.first;
  }  

  if(nowup == nowdo) cout << "Yes" << "\n";
  else cout << "No" << "\n";

  return 0;
}


Measured memory_bytes: 42572
#include<iostream>
#include<iomanip>
#include<cstdio>
#include<algorithm>
#include<cassert>
#include<cmath>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<queue>
#include<stack>
#include <cstring>
#include <functional>
//#include<unordered_map>
//#include<unordered_set>
using namespace std;
#define MOD 1000000007
#define MOD2 998244353
#define INF ((1<<30)-1)
#define LINF ((Int)1<<60)
#define EPS (1e-10)
typedef long long Int;
typedef pair<Int, Int> P; 
const int N = 200005;
//////////////////////////////

int n;
Int dp[111][5][5][5]; //a-0, c-1, g-2, t-3
//agc-021, acg-012, gac-201

void solve()
{
	int m;
	cin >> m;

	dp[0][0][0][0] = 1;
	for (int n = 0; n < 111; ++n) {
		for (int i = 0; i < 5; ++i) {
			for (int j = 0; j < 5; ++j) {
				for (int k = 0; k < 5; ++k) {
					for (int l = 1; l < 5; ++l) {
						if (i == 1 && j == 2 && l == 3) continue;
						if (i == 1 && k == 2 && l == 3) continue;
						if (j == 1 && k == 2 && l == 3) continue;
						if (j == 2 && k == 1 && l == 3) continue;
						if (j == 1 && k == 3 && l == 2) continue;
						dp[n + 1][j][k][l] += dp[n][i][j][k];
						dp[n + 1][j][k][l] %= MOD;
					}
				}
			}
		}
	}

	Int res = 0;
	for (int i = 1; i < 5; ++i)
		for (int j = 1; j < 5; ++j)
			for (int k = 1; k < 5; ++k)
				res += dp[m][i][j][k];

	cout << res % MOD << endl;
}

int main() {
	ios_base::sync_with_stdio(0); cin.tie(0); cout << fixed << setprecision(13);
	solve();
	return 0;
}


Measured memory_bytes: 3736
<?php
    fscanf(STDIN, "%d", $n);
    $input = fgets(STDIN);
    $a = explode(" ", $input);
    $ans = 0;
    for($i = 0; $i < $n; $i++){
        if($a[$a[$i] - 1] - 1 == $i)$ans++;
    }
    echo $ans / 2,"\n";
?>


Measured memory_bytes: 21876
in_str = raw_input().split()
num = []
for s in in_str:
    num.append(int(s))
if(num[0] < num[2] or num[1] < num[3] or num[2] < 0 or num[3] < 0):
    print "No"
elif(num[0] < num[2]+num[4] or num[1] < num[3]+num[4] or num[2]-num[4] < 0 or num[3]-num[4] < 0):
    print "No"
else:
    print "Yes"

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

#define rep(i,n) for(int i = 0; i < (n); i++)
#define rrep(i,n) for(int i = (n)-1; i >= 0; i--)
#define rep1(i,n) for(int i = 1; i <= (n); i++)
#define rrep1(i,n) for(int i = (n); i > 0; i--)

#define ll long long
#define pi pair<int, int>
#define pll pair<ll, ll>

#define MOD 1000000007
#define INF 1000000000000000LL

using namespace std;

int main(){
  int n,m;cin>>n>>m;
  vector<vector<int>>g(n);
  vector<int> in_count(n);
  rep(i, n-1+m){
    int a,b; cin>>a>>b; a--;b--;
    g[a].push_back(b);
    in_count[b]++;
  }

  vector<int> sorted_nodes;
  queue<int> count0;
  rep(i, n)if(in_count[i]==0)count0.push(i);
  int root = count0.front();
  while(count0.size()){
    int p = count0.front();count0.pop();
    sorted_nodes.push_back(p);
    for(auto c:g[p]){
      in_count[c]--;
      if(in_count[c]==0)count0.push(c);
    }
  }

  vector<int>parent(n);

  for(auto c:sorted_nodes){
    for(auto chi: g[c]){
      parent[chi]=c;
    }
  }

  parent[root]=-1;

  rep(i, n)cout<<parent[i]+1<<endl;

  return 0;
}


Measured memory_bytes: 9684
#include <iostream>
#include <fstream>
#include <string>

#define REP(i, n) for (int i = 0; i < (n); ++i)
using namespace std;

typedef long long ll;

int main()
{

    int n;
    cin >> n;
    string s;
    cin >> s;

    if (n % 2 == 1)
    {
        cout << "No" << endl;
        return 0;
    }
    if (s.substr(0, n / 2) == s.substr(n / 2, n / 2))
    {
        cout << "Yes" << endl;
    }
    else
    {
        cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
while True:
	try:
		a,b,c = map(str, raw_input().replace("+","=").split("="))
		i = 1 if a!=a[0]=="X" or b!=b[0]=="X" or c!=c[0]=="X" else 0
		for x in range(i,10):
			if eval((a+"+"+b).replace("X",str(x))) == int(c.replace("X",str(x))):
				print x
				break
		else:
			print "NA"
	except:
		break

Measured memory_bytes: 4260
N = int(input())
Ps = int("".join(input().split()))
Qs = int("".join(input().split()))

import itertools

l = list(range(1, N + 1))
l = itertools.permutations(l)
ln = []
for L in l:
    ln.append(int("".join(map(str, L))))
a = 0
b = 0
for i in range(len(ln)):
    if Ps == ln[i]:
        a = i
        break
for j in range(len(ln)):
    if Qs == ln[j]:
        b = j
        break

print(abs(a - b))

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

typedef long long ll;

int main(int argc, char *argv[]) {
  ll n, d;
  cin >> n >> d;
  
  ll x[n][d];

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

  int ans = 0;
  for (int i = 0; i < n; ++i) {
    for (int j = i+1; j < n; ++j) {
      ll tmp = 0;
      for (int k = 0; k < d; ++k) {
        tmp += pow(x[j][k] - x[i][k], 2);
      }
      double d1 = sqrt(tmp);
      double d2 = floor(d1);

      if (fabs(d2 - d1) <= DBL_EPSILON) {
        ans++;
      }
    }
  }
  
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(int argc, const char * argv[]) {
    // insert code here...

    int x,y,z;
    scanf("%d %d %d",&x,&y,&z);
    if(x<y&&x<z&&y<z){
        printf("Yes\n");
    }else{
        printf("No\n");

    }
    return 0;
}


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

char sheet[10][10];
char buf[12][10][10];
int ans[12][3];
int sum;

inline bool check(int x, int y, int s) {
  if (!sheet[y][x] || !sheet[y][x+1] || !sheet[y+1][x] || !sheet[y][x-1] || !sheet[y-1][x]) return false;
  if (!s) return true;
  if (!sheet[y+1][x+1] || !sheet[y-1][x+1] || !sheet[y+1][x-1] || !sheet[y-1][x-1]) return false;
  if (s==1) return true;
  if (!sheet[y][x+2] || !sheet[y+2][x] || !sheet[y][x-2] || !sheet[y-2][x]) return false;
  return true;
}

inline void absorb(int x, int y, int s) {
  --sheet[y][x];
  --sheet[y][x+1];
  --sheet[y+1][x];
  --sheet[y][x-1];
  --sheet[y-1][x];
  if (!s) return;
  --sheet[y+1][x+1];
  --sheet[y-1][x+1];
  --sheet[y+1][x-1];
  --sheet[y-1][x-1];
  if (s==1) return;
  --sheet[y][x+2];
  --sheet[y+2][x];
  --sheet[y][x-2];
  --sheet[y-2][x];
}

bool dfs(int x, int y, int s, int n) {
  bool r = false;
  char ds, w;
  if (!s) {
    ds = 5;
    w = 1;
  } else if (s==1) {
    ds = 9;
    w = 1;
  } else {
    ds = 13;
    w = 2;
  }

  if (check(x, y, s)) {
    ans[n][0] = x;
    ans[n][1] = y;
    ans[n][2] = s+1;
    memcpy(&buf[n][0][0], sheet, sizeof(char)*100);
    absorb(x, y, s);
    sum -= ds;
    if (!n) r = !sum;
    else r = dfs(x, y, s, n-1);
    if (r) return r;
    memcpy(sheet, &buf[n][0][0], sizeof(char)*100);
    sum += ds;
  }
  if (x<9-w) {
    r = dfs(x+1, y, s, n);
  } else if (y<9-w) {
    r = dfs(w, y+1, s, n);
  } else if (s) {
    r = dfs(1, 1, s-1, n);
  }
  return r;
}

int main() {
  int m, t;
  sum = 0;
  cin >> m;
  for (int i=0; i<10; i++) {
    for (int j=0; j<10; j++) {
      cin >> t;
      sum += t;
      sheet[i][j] = (char)t;
    }
  }
  dfs(2, 2, 2, m-1);
  for (int i=0; i<m; i++) {
    cout << ans[i][0] << " " << ans[i][1] << " " << ans[i][2] << endl;
  }
}

Measured memory_bytes: 1168
//#pragma GCC optimize("Ofast")
#include <set>
#include <map>
#include <cmath>
#include <stack>
#include <queue>
#include <vector>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#define endl '\n'
#define fast ios::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define zy 2333333
#define bql 2147483647
using namespace std;
long long n,a[100005];
int main()
{
	fast;
	cin>>n;
	for (int i=1;i<=n;i++)
	   cin>>a[i];
	a[0]=-100;int flag=0;
	for (int i=1;i<=n;i++)
	{
		if (a[i]>a[i-1])
		   a[i]--;
	}
	for (int i=1;i<=n;i++)
	{
		if (a[i]<a[i-1])
		{
			flag=1;
			break;
		}
	}
	
	if (flag==1)
	   cout<<"No"<<endl;
	else 
	   cout<<"Yes"<<endl;
	return 0;
}

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

#define int long long 
#define boost ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

const int N = 100000 + 10;

int a[N] , pa[N] , sa[N];
int32_t main(){

	boost;
	
	int n;
	cin >> n;

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

	for(int i = 0 ; i < n ; ++i){
		if(i == 0){
			pa[0] = a[0];
			sa[n-1] = a[n-1];
		}
		else{
			pa[i] = __gcd(a[i] , pa[i-1]);
			sa[n-i-1] = __gcd(a[n-i-1] , sa[n-i]);
		}
	}
	
	int ans;
	for(int i = 0 ; i < n-1 ; ++i){
		if(i == 0){
			ans = sa[i+1];
		}
		else{
			// cout << __gcd(pa[i-1] , sa[i+1]) << "\n";
			ans = max(ans , __gcd(pa[i-1] , sa[i+1]));
		}
	}

	ans = max(pa[n-2],ans);
	cout << ans;

	return 0;
}

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

#define PAIR pair<double, double>

int main() {
	int n, k;
	double s, x, y, x1, y1, tmp, d, h;
	char t;
	while (cin >> n) {
		if (n == 0) break;

		vector<PAIR> list;
		vector<int> res;
		for (int i = 0; i < n; i++) {
			cin >> x >> t >> y;
			list.push_back(make_pair(x, y));
		}
		sort(list.begin(), list.end());

		double dx = list[0].first;
		double dy = list[0].second;

		k = 1;
		s = (list[1].second - dy) / (list[1].first - dx);
		for (int i = 2; i < n; i++) {
			x = list[i].first;
			y = list[i].second;

			tmp = (y - dy) / (x - dx);
			if (s < tmp) {
				s = tmp;
				k = i;
			}
		}

		res.push_back(0);
		res.push_back(k);
		while (true) {
			h = 0;
			k = 0;
			for (int i = 0; i < n; i++) {
				x = list[i].first;
				y = list[i].second;

				x1 = list[res[res.size() - 1]].first;
				y1 = list[res[res.size() - 1]].second;

				dx = list[res[res.size() - 2]].first;
				dy = list[res[res.size() - 2]].second;

				dx -= x1;
				dy -= y1;

				x -= x1;
				y -= y1;

				d = (dx * x + dy * y) / (hypot(dx, dy) * hypot(x, y));
				d = acos(d);
				if (h < d) {
					k = i;
					h = d;
				}
			}
			if (k == 0) break;
			res.push_back(k);
		}
		cout << n - res.size() << endl;
	}
	return 0;
}

Measured memory_bytes: 3356