akhauriyash/Code-Regression huggingface dataset:
program best_representation
  implicit none
  character(500000) :: w, r
  integer :: n, z(2,500000) = 0, i, k, p, per, m = 0
  logical :: g(2,500000) = .true.
  read(*,*) w
  n = len_trim(w)
  z(1,1:n) = z_algorithm(w)
  per = -1
  do i = n, 2, -1
    if (z(1,i)+i-1 == n) then
      per = z(1,i)
      do p = 1, n, per
        if (mod(z(1,p),per) == 0 .and. z(1,p)+p-1 == n) cycle
        per = -1
        exit
      end do
    end if
    if (per > 0) exit
  end do
  if (per < 0) then
    write(*,'(i0)') 1
    write(*,'(i0)') 1
    stop
  end if
  if (per == 1) then
    write(*,'(i0)') n
    write(*,'(i0)') 1
    stop
  end if
  r = ""
  do i = 1, n
    r(i:i) = w(n-i+1:n-i+1)
  end do
  z(2,1:n) = z_algorithm(r)
  do i = 1, 2
    do p = 1, n-1
      if (.not.g(i,p)) cycle
      k = 2
      do while ((k-1)*p <= z(i,p+1))
        g(i,k*p) = .false.
        k = k+1
      end do
    end do
  end do
  g(2,1:n) = g(2,n:1:-1)
  do i = 1, n-1
    if (g(1,i) .and. g(2,i+1)) m = m+1
  end do
  write(*,'(i0)') 2
  write(*,'(i0)') m
contains
  function z_algorithm(s) result(z)
    character(*) :: s
    integer :: z(len_trim(s)), n, i, j, k
    z = 0
    n = len_trim(s)
    z(1) = n
    i = 1
    j = 0
    do while (i < n)
      do while (i+j < n .and. s(j+1:j+1) == s(i+j+1:i+j+1))
        j = j+1
      end do
      z(i+1) = j
      if (j == 0) then
        i = i+1
        cycle
      end if
      k = 1
      do while (i+k < n .and. k+z(k+1) < j)
        z(i+k+1) = z(k+1)
        k = k+1
      end do
      i = i+k
      j = j-k
    end do
  end
end program best_representation

Measured memory_bytes: 11452
#include <iostream>
#define REP(i, a, b) for (auto i = (a); i < (b); ++i)
using namespace std;

using ll = long long;

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

	string s; cin >> s; int l = 0, r = s.size() - 1, cnt = 0;
	while (l < r) {
		if (s[l] != s[r]) ++cnt;
		++l; --r;
	}
	cout << cnt;
}

Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Scanner;

public class Main {
    public static void main(String args[]) {
        try (Scanner in = new Scanner(System.in)) {
            int N = in.nextInt();
            long[] A = new long[N];
            for (int i = 0; i < N; i++) {
                A[i] = in.nextInt();
            }

            long op = 0;
            long sum = 0;
            long op2 = 0;
            long sum2 = 0;
            for (int i = 0; i < N; i++) {
                sum += A[i];
                sum2 += A[i];
                if (i % 2 == 0) {
                    if (sum <= 0) {
                        op += (1 - sum);
                        sum = 1;
                    }
                    if (sum2 >= 0) {
                        op2 += (sum2 - -1);
                        sum2 = -1;
                    }
                } else {
                    if (sum >= 0) {
                        op += (sum - -1);
                        sum = -1;
                    }
                    if (sum2 <= 0) {
                        op2 += (1 - sum2);
                        sum2 = 1;
                    }
                }
            }

            System.out.println(Math.min(op, op2));
        }
    }
}


Measured memory_bytes: 62260
#include <stdio.h>

int main(void)
{
	int h, w;
	int i, j;

	while (1){
		scanf("%d %d", &h, &w);
		if (h == 0 && w == 0)break;

		for (i = 0; i < h; i++){
			if (i == 0 || i == h - 1){
				for (j = 0; j < w; j++){
					printf("#");
				}
				printf("\n");
			}
			else {
			   printf("#");
			   for (j = 0; j < w - 2; j++){
					 printf(".");
				 }
				 printf("#");
				 printf("\n");
			}
		}
		printf("\n");
	}

	return (0);
}

Measured memory_bytes: 572
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};
    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };
    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };
    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };
    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };
    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input! {
        n: chars
    }
    println!("{}",
        if n.contains(&'9') {"Yes"} else {"No"}
    );
}


Measured memory_bytes: 4352
#include<iostream>
int count[100010];
int main(void){
    int tmp,ans=-1,N;
    std::cin>>N;
    for(int i=0;i!=100010;i++){
        count[i]=0;
    }
    while(std::cin>>tmp){
        count[tmp]++;
    }
    for(int i=1;i!=100001;i++){
        tmp=count[i-1]+count[i]+count[i+1];
        if(ans<tmp){
            ans=tmp;
        }
    }
    std::cout<<ans<<std::endl;
    return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
using i64 = int_fast64_t;
using ui64 = uint_fast64_t;
#define REP(i, n) for (i64 (i) = 0; (i) < (n); ++(i))
#define FOR(i, a, b) for (i64 (i) = (a); (i) < (b); ++(i))

template<typename T> struct Edge {
    int from, to;
    T weight;
    Edge() : from(0), to(0), weight(0) {}
    Edge(int f, int t, T w) : from(f), to(t), weight(w) {}
};
template<typename T> using Edges = vector< Edge< T > >;
template<typename T> using Graph = vector< Edges< T > >;
template<typename T> void     add_edge(Graph< T > &g, int from, int to, T w = 1) { g[from].emplace_back(from, to, w); g[to].emplace_back(to, from, w); }
template<typename T> void      add_arc(Graph< T > &g, int from, int to, T w = 1) { g[from].emplace_back(from, to, w); }
template<typename T> void add_to_edges(Edges< T > &e, int from, int to, T w = 1) { e.emplace_back(from, to, w); }

template<typename T> using Matrix = vector< vector< T > >;
template<typename T> Matrix< T > WarshallFloyd(Graph< T > &g) {
    const auto INF = numeric_limits< T >::max() / 10;
    int vertex = g.size();
    Matrix< T > dist(vertex, vector< T >(vertex, INF));
    for (int i = 0; i < vertex; ++i) dist[i][i] = 0;
    for (int i = 0; i < vertex; ++i) {
        for (auto &e : g[i]) {
            dist[e.from][e.to] = min(dist[e.from][e.to], e.weight);
        }
    }
    for (int k = 0; k < vertex; ++k) {
        for (int i = 0; i < vertex; ++i) {
            for (int j = 0; j < vertex; ++j) {
                if (dist[i][k] != INF and dist[k][j] != INF) {
                    dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);
                }
            }
        }
    }
    return dist;
}
template<typename T> void add_edge_to_matrix(Matrix< T > &mat, int from, int to, T weight = 1) {
    const auto INF = numeric_limits< T >::max() / 10;
    mat[from][to] = mat[to][from] = min(mat[from][to], weight);
    int vertex = mat.size();
    for (int k : {from, to}) {
        for (int i = 0; i < vertex; ++i) {
            for (int j = 0; j < vertex; ++j) {
                if (mat[i][k] != INF and mat[k][j] != INF) {
                    mat[i][j] = min(mat[i][j], mat[i][k] + mat[k][j]);
                }
            }
        }
    }
}

signed main() {

    int N, M, L;
    cin >> N >> M >> L;

    Graph<i64> g(N);
    REP(i, M) {
        int A, B;
        i64 C;
        cin >> A >> B >> C;
        --A, --B;
        add_edge(g, A, B, C);
    }

    auto wf = WarshallFloyd(g);
    Graph<int> g2(N);
    REP(i, N) REP(j, N) {
        if (wf[i][j] <= L) add_edge(g2, i, j, 1);
    }

    auto wf2 = WarshallFloyd(g2);

    int Q;
    cin >> Q;

    while (Q--) {
        int S, T;
        cin >> S >> T;
        --S, --T;
        if (wf2[S][T] >= 1e8) cout << -1 << endl;
        else cout << max<i64>(0, wf2[S][T] - 1) << endl;
    }

}

Measured memory_bytes: 7552
#include<bits/stdc++.h>
#define x first
#define y second
#define pb push_back
#define eb emplace_back
#define all(a) (a).begin(),(a).end()
#define SZ(a) (int)(a).size()
#define FOR(i, a, b) for(int i=(a); i<=(b); ++i)
#define iFOR(i, a, b) for(int i=(a); i>=(b); --i)
#define make_unique(a) sort(all((a))), (a).resize(unique(all((a)))-(a).begin())

using namespace std;

typedef pair<int,int> PII;
typedef long long LL;
typedef unsigned long long UL; // ULLONG_MAX, %llu
typedef unsigned int UI; //UINT_MAX %u
typedef double DD;
typedef long double LD;
typedef pair<LL,LL> PLL;
typedef pair<DD,DD> PDD;
typedef vector<int> VI;
typedef vector<LL> VL;

const int N = 6;
char t[N][N];
int red[N][N];
int R, C;
int ans, k;
void permute(int nw){
    if(nw == R+C){
        int cnt = 0;
        FOR(i, 0, R-1){
            FOR(j, 0, C-1){
                if(!red[i][j] && t[i][j] == '#') ++cnt;
            }
        }
        if(cnt == k) ++ans;
        return ;
    }
    if(nw < R){
        FOR(i,0,C-1) ++red[nw][i];
        permute(nw+1);
        FOR(i,0,C-1) --red[nw][i];
        permute(nw+1);
    }else{
        FOR(i,0,R-1) ++red[i][nw-R];
        permute(nw+1);
        FOR(i,0,R-1) --red[i][nw-R];
        permute(nw+1);
    }
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin >> R >> C >> k;
    FOR(i,0,R-1) cin >> t[i];
    permute(0);
    cout << ans;
	return 0;
}
/*
 *
 *
 *
 *
 *
 *
 *
 *
 *
 *
 */


Measured memory_bytes: 3648
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <iostream>
#include <ctime>
#include <map>
#include <queue>
#include <cstdlib>
#include <string>
#include <climits>
#include <set>
#include <vector>
#define int long long
using namespace std;
inline int read(){
	int k=0,f=1;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){k=k*10+ch-'0';ch=getchar();}
	return k*f;
}
const int MOD=1e9+7;
int n,m;
signed main()
{
	n=read();m=read();
	if(abs(n-m)>1)return puts("0")&0;
	if(n<m)swap(n,m);
	if(n==m){
		int k=1;
		for(int i=1;i<=n;i++)k=k*i%MOD;
		printf("%lld",k*k%MOD*2%MOD);
	}else{
		int k=1;
		for(int i=1;i<=m;i++)k=k*i%MOD;
		printf("%lld",k*k%MOD*n%MOD);
	}
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fi first
#define se second
#define pii pair<int,int>
#define mp make_pair
#define pb push_back
#define space putchar(' ')
#define enter putchar('\n')
#define eps 1e-10
#define MAXN 100005
//#define ivorysi
using namespace std;
typedef long long int64;
typedef unsigned int u32;
typedef double db;
template<class T>
void read(T &res) {
    res = 0;T f = 1;char c = getchar();
    while(c < '0' || c > '9') {
	if(c == '-') f = -1;
	c = getchar();
    }
    while(c >= '0' && c <= '9') {
	res = res * 10 +c - '0';
	c = getchar();
    }
    res *= f;
}
template<class T>
void out(T x) {
    if(x < 0) {x = -x;putchar('-');}
    if(x >= 10) {
	out(x / 10);
    }
    putchar('0' + x % 10);
}
int N;
void Solve() {
    read(N);
    int res = 0;
    for(int i = 1 ; i <= N ; ++i) {
	res += i;
	if(res >= N) {
	    for(int j = 1 ; j <= i ; ++j) {
		if(j == res - N) continue;
		out(j);enter;
	    }
	    return;
	}
    }
}
int main() {
#ifdef ivorysi
    freopen("f1.in","r",stdin);
#endif
    Solve();
    return 0;
}


Measured memory_bytes: 256
package main

import "fmt"

func main() {
	var a, b int
	const (
		h = 100
		w = 100
	)
	fmt.Scan(&a, &b)
	grid := make([][]byte, h)
	for i := range grid {
		grid[i] = make([]byte, w)
	}
	// fmt.Println("initialize grid")
	// fmt.Println(grid)

	for i := 0; i < h/2; i++ {
		for j := 0; j < w; j++ {
			grid[i][j] = '#'
		}
	}
	// fmt.Println("filled '#'")
	// fmt.Println(grid)
	for i := h / 2; i < len(grid); i++ {
		for j := range grid[i] {
			grid[i][j] = '.'
		}
	}
	// fmt.Println("filled '.'")
	// fmt.Println(grid)

	a--
	b--

	i, j := 0, 0

	for ; a > 0; a-- {
		// a個白にする
		grid[i][j] = '.'
		j += 2;
		if j >= w {
			i += 2
			j = 0
		}
	}
	i, j = h/2+1, 0
	for ; b > 0; b-- {
		grid[i][j] = '#'
		j += 2
		if j >= w {
			i += 2
			j = 0
		}
	}

	fmt.Println(h, w)
	for i := range grid {
		fmt.Println(string(grid[i]))
	}
}


Measured memory_bytes: 512
using System;
using System.Linq;
using System.Collections.Generic;
using System.Text;

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            long N = long.Parse(Console.ReadLine());
            double count = 0;
            for (int i = 0; i < N; i++)
            {
                if (i % 2 == 0) count += 1.0;
            }

            Console.WriteLine((count / (double)N).ToString());
//            Console.Read();
        }
    }
}

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

int main() {
	int N, K, Q;
	cin >> N >> K >> Q;
	vector<int> v(N);
	int q = Q;
	while (q--) {
		int a;
		cin >> a;
		v[a-1]++;
	}

	for (int i = 0; i < N; i++) {
		if (K - Q + v[i] > 0) cout << "Yes" << endl;
		else cout << "No" << endl;
	}

	return 0;
}

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

typedef long long ll;

void solve() {
    int N; cin >> N;
    vector<int> A(N), B(N);
    for (int i = 0; i < N; i++)
        cin >> A[i] >> B[i];
    sort(A.begin(), A.end());
    sort(B.begin(), B.end());
    if (N & 1)
        cout << B[(N - 1) / 2] - A[(N - 1) / 2] + 1 << '\n';
    else
        cout << B[N / 2] + B[N / 2 - 1] - A[N / 2] - A[N / 2 - 1] + 1 << '\n';
}

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);

    solve();
    return 0;
}


Measured memory_bytes: 4764
#include <stdio.h>
#include <stdlib.h>
     
int main(void){
  long long x,ans=1e9;
  scanf("%lld",&x);
  while(x>=100){
    ans=ans<llabs(753-x%1000)?ans:llabs(753-x%1000);
    x/=10;
  }
  printf("%lld\n",ans);
  return 0;
}


Measured memory_bytes: 128
using System.Linq;
using static System.Console;

class Program
{
    static void Main(string[] args)
    {
        var candypack = ReadLine().Split().Select(x => int.Parse(x)).ToArray();
        if (candypack[0] == candypack[1] + candypack[2])
            WriteLine("Yes");
        else if (candypack[1] == candypack[0] + candypack[2])
            WriteLine("Yes");
        else if (candypack[2] == candypack[0] + candypack[1])
            WriteLine("Yes");
        else
            WriteLine("No");
    }
}

Measured memory_bytes: 2776
//To debug :  g++ -g file.cpp -o code
//to flush output : fflush(stdout) or cout.flush()
//cout<<setprecision(p)<<fixed<<var
//use 1LL<<i to for 64 bit shifting , (ll)2 because by default 2 is ll
//take care of precedence rule of operators 
//do not forget to change the sizes of arrays and value of contants and other things after debugging  

#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i,a,n) for(i=a;i<n;++i)
#define irep(i,n,a) for(i=n;i>a;--i)
#define mod 1000000007
#define pb push_back
#define big 9223372036854775807
#define big1 LONG_MAX
#define big2 ll_MAX
#define big3 1000000000
#define sma1 LONG_MIN
#define sma2 ll_MIN
#define sma3 -1000000000
#define mp make_pair
#define dub double
#define ivec vector<ll>
#define lvec vector<long long>
#define cvec vector<char>
#define svec vector<string>
#define mt make_tuple
#define MOD 998244353
#define ld long double
#define pi acos(-1.0)
 
#define SZ(x)  (ll)(x.size())
 
//comment the below if not required

/*

#define ss second.second
#define ff first.first
#define f first
#define s second
#define sf second.first
#define fs first.second
*/
 
#define IOS std::ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)

ll t,n,i,a,b,tot,ed;

int main()
{

    IOS;

    t=1;

    while(t--)
    {
        cin>>n;

        for(i=1;i<n;++i)
        {
            cin>>a>>b;
            
            if(a>b)
                swap(a,b);

            ed += a*(n-b+1);


        }

        for(i=1;i<=n;++i)
        {
            a = n-i+1;
            tot += (a*(a+1))/2;
        }


        tot -= ed;


        cout<<tot;

    }





    return 0;
}

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

#define REP(i,n) for(long long i = 0; i < (n); i++)
#define FOR(i, m, n) for(long long i = (m);i < (n); ++i)
#define ALL(obj) (obj).begin(),(obj).end()
#define SPEED cin.tie(0);ios::sync_with_stdio(false);

template<class T> using V = vector<T>;
template<class T, class U> using P = pair<T, U>;
template<class T> using PQ = priority_queue<T>;
template<class T> using PQR = priority_queue<T,vector<T>,greater<T>>;

const ll MOD = (ll)1e9 + 7;
const ll MOD2 = 998244353;
const ll HIGHINF = (ll)1e18;
const ll LOWINF = (ll)1e15;
const long double PI = 3.1415926535897932384626433;

template<typename T> vector<T> make_v(size_t N,T init){return vector<T>(N,init);}
template<typename... T> auto make_v(size_t N,T... t){return vector<decltype(make_v(t...))>(N,make_v(t...));}
template <class T> void corner(bool flg, T hoge) {if (flg) {cout << hoge << endl; exit(0);}}
template <class T, class U>ostream &operator<<(ostream &o, const map<T, U>&obj) {o << "{"; for (auto &x : obj) o << " {" << x.first << " : " << x.second << "}" << ","; o << " }"; return o;}
template <class T>ostream &operator<<(ostream &o, const set<T>&obj) {o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr) o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o;}
template <class T>ostream &operator<<(ostream &o, const multiset<T>&obj) {o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr) o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o;}
template <class T>ostream &operator<<(ostream &o, const vector<T>&obj) {o << "{"; for (int i = 0; i < (int)obj.size(); ++i)o << (i > 0 ? ", " : "") << obj[i]; o << "}"; return o;}
template <class T, class U>ostream &operator<<(ostream &o, const pair<T, U>&obj) {o << "{" << obj.first << ", " << obj.second << "}"; return o;}
template <template <class tmp>  class T, class U> ostream &operator<<(ostream &o, const T<U> &obj) {o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr)o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o;}
void print(void) {cout << endl;}
template <class Head> void print(Head&& head) {cout << head;print();}
template <class Head, class... Tail> void print(Head&& head, Tail&&... tail) {cout << head << " ";print(forward<Tail>(tail)...);}
template <class T> void chmax(T& a, const T b){a=max<T>(a,b);}
template <class T> void chmin(T& a, const T b){a=min<T>(a,b);}
void YN(bool flg) {cout << ((flg) ? "YES" : "NO") << endl;}
void Yn(bool flg) {cout << ((flg) ? "Yes" : "No") << endl;}
void yn(bool flg) {cout << ((flg) ? "yes" : "no") << endl;}

int main() {
    int N; cin >> N;
    V<ll> x(N),y(N);
    for(int i = 0; i < N; ++i) cin >> x[i] >> y[i];
    map<P<ll,ll>,ll> mp;
    for(int i = 0; i < N; ++i){
        for(int j = 0; j < N; ++j){
            if(i==j) continue;
            mp[{x[i]-x[j],y[i]-y[j]}]++;
        }
    }
    ll ans = 0;
    for(auto e:mp){
        chmax(ans,e.second);
    }

    cout << N - ans << endl;



    return 0;
}


Measured memory_bytes: 384
#include<iostream>
using namespace std;
#define MAX 500000
#define SENTINEL 2000000000
int L[MAX/2+2],R[MAX/2+2];
int cnt;

void merge(int A[],int left,int right,int mid){
    for(int i=0;i<mid-left;i++) L[i] = A[left+i];
    for(int i=0;i<right-mid;i++) R[i] = A[mid+i];
    L[mid-left]=SENTINEL;R[right-mid]=SENTINEL;
    int i=0,j=0;
    for(int k=left;k<right;k++){
        cnt++;
        if(L[i] <= R[j]){
            A[k]=L[i++];
        }else{
            A[k]=R[j++];
        }
    }
}

void mergeSort(int A[],int left,int right){
    if(left+1<right){
        int mid=(left+right)/2;
        mergeSort(A,left,mid);
        mergeSort(A,mid,right);
        merge(A,left,right,mid);
    }
}

int main(){
    int A[MAX],n;
    cnt = 0;
    cin >> n;
    for(int i=0;i<n;i++)cin >> A[i];
    mergeSort(A,0,n);
    for(int i=0;i<n;i++){
        cout << ((i>0)?" ":"") << A[i];
    }
    cout << endl << cnt << endl;
    return 0;
}



Measured memory_bytes: 6872
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <algorithm>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <numeric>

using namespace std;
int main()
{
    string s1, s2;
    cin>>s1>>s2;
    cout<<s2<<s1<<endl;
	return 0; 
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
 
using namespace std;
using namespace __gnu_pbds;
 
 
#define pb push_back
#define mp make_pair
#define lb lower_bound
#define ub upper_bound
#define f first
#define s second
#define resz resize
#define ini ll_MAX
#define inl LLONG_MAX
#define MOD 1000000007
#define sz(x) ll((x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define F0R(i, a) for (ll i = 0; i < (a); i++)
#define FORR(i, a, b) for (ll i = a; i >= (b); i--)
#define F0RR(i, a) for (ll i = a; i >= 0; i--)
#define trav(a, x) for (auto& a : x)
#define pbds tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update> 
 
using ll = long long;
using vi = vector<ll>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vb = vector<bool>;
using vd = vector<double>;
using vs = vector<string>;
 
using pii = pair<ll, ll>;
using pll = pair<ll, ll>;
using pdd = pair<double, double>;
 
using vpii = vector<pii>;
using vvpii = vector<vpii>;
using vpll = vector<pll>;
using vvpll = vector<vpll>;
using vpdd = vector<pdd>;
using vvpdd = vector<vpdd>;
 


// ll Arr[105];
// ll Size[105];


// ll root (ll i)
// {
//     while(Arr[ i ] != i)
//     {
//         Arr[ i ] = Arr[ Arr[ i ] ] ; 
// i = Arr[ i ]; 
//     }
// return i;
// }


// void initialize(ll N)
// {
//     for(ll i = 0;i<N;i++)
//     {
//         Arr[ i ] = i ;
//         Size[ i ] = 1;
//     }
// }
// void weighted_union(ll A,ll B)
// {
//     ll root_A = root(A);
//     ll root_B = root(B);
//     if(Size[root_A] < Size[root_B ])
//     {
// Arr[ root_A ] = Arr[root_B];
// Size[root_B] += Size[root_A];
// }
//     else
//     {
// Arr[ root_B ] = Arr[root_A];
// Size[root_A] += Size[root_B];
// }

// }

ll mod(ll a,ll b)
{
    return (b+a%b)%b;
}
 
ll gcd(ll a,ll b)
{
    if(b==0)return a;
    else return gcd(b,a%b);
}
ll po(ll a,ll b)
{
    ll ans = 1;
    while(b--)
        ans*=a;
    return ans;
}
ll power(ll a,ll b,ll c)
{
    ll x=1,y=a;
    while(b > 0)
    {
        if(b%2 == 1)
        {
            x=(x*y)%c;
        }
        y = (y*y)%c;
        b /= 2;
    }
    return x%c;
}
 
double sqdist(double a,double b,double c,double d)
{
    return (a-c)*(a-c)+(b-d)*(b-d);
}
ll fact(ll n)
{
    if(n==0)return 1;
    ll ans = 1;
    FOR(i,1,n+1)ans*=i;
    return ans;
}


ll check(ll i)
{
    ll p = 0;
    while(i)
    {
        if(i%2)p++;
        i/=2;
    }
    // cout<<i<<' '<<p<<endl;
    return p;
}


void solve()
{
    int n,k;
    cin>>n>>k;
    vector<int> arr(n,0);
    for(auto &i:arr)cin>>i;
    vector<int> dp(n,INT_MAX);
dp[0]=0;
    for(int i=0;i<n;i++)
    {
        for(int j=1;j<=k;j++)
        {
            if(i+j<n)
                dp[i+j]=min(dp[i+j],dp[i]+abs(arr[i]-arr[i+j]));
        }
    }
    cout<<dp[n-1];
}   
 
main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    // #ifndef ONLINE_JUDGE
    // freopen("input.txt","r",stdin);
    // freopen("output.txt","w",stdout);
    // #endif
    solve();
}

Measured memory_bytes: 3936
#include<cstdio>
#include<cstring>
#include<cmath>
#include<bitset>
#include<iostream>
#include<algorithm>
#include<string>
#include<utility>
#include<tuple>
#include<vector>
#include<list>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<numeric>
#include<functional>
#include<iomanip>
#include<random>

#define IOS ios::sync_with_stdio(false),cin.tie(0)
#define REP(i,n) for(int i = 0;i < n;i++)
#define FOR(i,a,b) for(int i = a;i < b;i++)
#define MEM(a,b) memset(a,b,sizeof(a))
#define ALL(x) (x).begin(),(x).end()
#define LMAX 9223372036854775807
#define LMIN -9223372036854775808

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef pair<ull, ull> UP;
typedef tuple<int, int, int> T;

struct UnionFind {
	vector<int> data;
	UnionFind(int size) : data(size, -1) {}
	void unionSet(int x, int y) {
		x = root(x), y = root(y);
		if (x != y) {
			if (data[y] < data[x])swap(x, y);
			data[x] += data[y]; data[y] = x;
		}
	}
	bool findSet(int x, int y) {
		return root(x) == root(y);
	}
	int root(int x) {
		return data[x] < 0 ? x : data[x] = root(data[x]);
	}
	int size(int x) {
		return -data[root(x)];
	}
};

ll gcd(ll a, ll b) {
	if (a < b)swap(a, b);
	int k = a % b;
	if (k == 1)return 1;
	if (k == 0)return b;
	int ans = gcd(b, k);
	return ans;
}
ll digisum(ll a) {
	int sum = 0;
	while (a) {
		sum += a % 10;
		a /= 10;
	}
	return sum;
}
ll countpow(ll a, ll b) {
	int ans = 0;
	if (b == 0)return -1;
	while (1) {
		if (a % b == 0) {
			a /= b;
			ans++;
		}
		else break;
	}
	return ans;
}


int main() {
	IOS;
	int a, b;
	char o;
	cin >> a >> o >> b;
	int ans;
	if (o == '+')ans = a + b;
	else ans = a - b;
	cout << ans << endl;
}



Measured memory_bytes: 256
package main

import (
	"bufio"
	"os"
	"sort"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func scanInt() int {
	iv, _ := strconv.Atoi(scanString())
	return iv
}

func scanString() string {
	sc.Scan()
	return sc.Text()
}

func init() {
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 100001), 100001*100)
}

func main() {
	n, _ := scanInt(), scanInt()
	s := make([]string, n)
	for i := range s {
		s[i] = scanString()
	}

	sort.Strings(s)
	var wr = bufio.NewWriter(os.Stdout)
	for _, v := range s {
		wr.WriteString(v)
	}
	wr.WriteString("\n")
	wr.Flush()
}


Measured memory_bytes: 640
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; ++i)
typedef long long ll;

int main()
{
	string s,t;cin >> s >> t;
	sort(s.begin(),s.end());
	sort(t.begin(),t.end());
	vector<int> snum;
	vector<int> tnum;
	rep(i,s.size()-1)
	{
		int l = 1;
		while(s[i]==s[i+1])
		{
			i++;
			l++;
		}
		snum.push_back(l);
	}
	rep(i,t.size()-1)
	{
		int l = 1;
		while(t[i]==t[i+1])
		{
			i++;
			l++;
		}
		tnum.push_back(l);
	}

	sort(snum.begin(),snum.end());
	sort(tnum.begin(),tnum.end());
	if(snum.size()!=tnum.size())
	{
		cout<<"No"<<endl;
		return 0;
	}
	rep(i,snum.size())
	{
		if(snum[i]!=tnum[i])
		{
			cout<<"No"<<endl;
			return 0;
		}
	}
	cout<<"Yes"<<endl;
	return 0;
}

Measured memory_bytes: 776
#include<iostream>
#include<stdio.h>
#include<string>
#include<vector>
#include<algorithm>

using namespace std;
int main()
{
    int a,b;
    cin >> a >> b;

    int d = a/b;
    int r = a%b;
    double f = a/(double)b;

    printf("%d %d %.6f\n",d,r,f);






    return 0;
}


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

public class Main {
    public static PrintWriter out;
    public static FastScanner in;

    ArrayList<Integer>[] G;
    int n;
    private void solve(){
        n = in.nextInt();
        int m = in.nextInt();

        G = new ArrayList[n];
        for(int i=0;i<n;i++){
            G[i]= new ArrayList<>();
        }

        for(int i=0;i<m;i++){
            int u = in.nextInt();
            int v = in.nextInt();

            G[u-1].add(v-1);
            G[v-1].add(u-1);
        }
        out.print(visit(0,1));

    }

    private int visit(int u,int mask){
        int g = mask,c;
        for(c=0;g>0;g >>=1){
            c+= g & 1;
        }
        //out.println(c);
        if(c == n){
            return 1;
        }
        int count =0;
        for(int v:G[u]){
            if((mask & (1<<v)) == 0){
                //out.println(v +" "+mask);
                count+=visit(v,mask|(1<<v));
            }
        }
        return count;
    }

    private void runIO() {
        in = new FastScanner();
        out = new PrintWriter(new BufferedOutputStream(System.out));
        solve();
        out.close();
    }
    private static class FastScanner {
        BufferedReader bufferedReader;
        StringTokenizer stringTokenizer;

        private FastScanner() {
            bufferedReader = new BufferedReader(new InputStreamReader(System.in));
        }

        private String next() {
            if (stringTokenizer == null || !stringTokenizer.hasMoreElements()) {
                try {
                    stringTokenizer = new StringTokenizer(bufferedReader.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return stringTokenizer.nextToken();
        }

        private int nextInt() {
            return Integer.parseInt(next());
        }

        private long nextLong() {
            return Long.parseLong(next());
        }

        private String nextLine() {
            String ret = "";
            try {
                ret = bufferedReader.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return ret;
        }
    }

    public static void main(String[] args) {
        new Main().runIO();
    }
}


Measured memory_bytes: 22612
N, A, B = map(int, input().split())


def f(n, a, b):
    if n == 1:
        return [a, b]

    mask = 1 << (n-1)
    if a & mask == b & mask:
        v1 = f(n-1, a, b)
        v2 = f(n-1, a ^ mask, v1[1] ^ mask)
        ret = v1[:1]
        ret.extend(v2)
        ret.extend(v1[1:])
        return ret
    else:
        v1 = f(n-1, a, a ^ 1)
        v2 = f(n-1, a ^ 1 ^ mask, b)
        v1.extend(v2)
        return v1


if bin(A ^ B).count('1') % 2 == 0:
    print("NO")
else:
    print("YES")
    res = f(N, A, B)
    for p in res:
        print(p)


Measured memory_bytes: 9884
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <string>
#include <cstdio>

using namespace std;

int sum(vector<int> &tree, int i) {
    int ans = 0;
    while (i > 0) {
        ans += tree[i];
        i -= (i & -i);
    }
    return ans;
}
void update(vector<int> &tree, int i, int diff) {
    while (i < tree.size()) {
        tree[i] += diff;
        i += (i & -i);
    }
}

int main(){
    int n;
    long long k;
    cin >> n >> k;
    
    vector<int> a(n);
    for (int i=0;i<n;i++){cin >> a[i];}
    
    vector<long long> b(n+1,0);
    vector<int> c(n+1,0);
    vector<int> tree(n+2,0);
    vector<pair<long long,int>> p(n+1);

    for (int i=1;i<n+1;i++){b[i] = b[i-1] + a[i-1];}
    for (int i=1;i<n+1;i++){b[i] -= i*k;}
    for (int i=0;i<n+1;i++){p[i] = make_pair(b[i],i);}
    
    sort(p.begin(),p.end());
    int num = 1;
    c[p[0].second] = 1;
    for (int i=1;i<n+1;i++){
        if(p[i].first == p[i-1].first) c[p[i].second] = num;
        else c[p[i].second] = ++num;
    }

    long long cnt = 0;
    for (int i=0;i<n+1;i++){
        cnt += sum(tree, c[i]);
        update(tree, c[i], 1);
    }
    
    cout << cnt << '\n';
    return 0;
}

Measured memory_bytes: 7296
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> P;
typedef pair<int,int> Pi;
#define rep(i,n) for(ll i=0;i<n;i++)
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define fi first
#define se second
#define endl "\n"

template<typename T> inline bool chmax(T &a, T b){if(a<b){a=b;return true;}return false;}
template<typename T> inline bool chmin(T &a, T b){if(a>b){a=b;return true;}return false;}
template<typename T> ostream& operator<<(ostream& s,const complex<T>& d) {return s<<"("<<d.real()<<", "<<d.imag()<< ")";}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const pair<T1,T2>& d) {return s<<"("<<d.first<<", "<<d.second<<")";}
template<typename T> ostream& operator<<(ostream& s, const vector<T>& d){int len=d.size();rep(i,len){s<<d[i];if(i<len-1) s<<" ";}return s;}
template<typename T> ostream& operator<<(ostream& s,const vector<vector<T>>& d){int len=d.size();rep(i,len){s<<d[i]<<endl;}return s;}
template<typename T> ostream& operator<<(ostream& s,const set<T>& v){s<<"{ ";for(auto itr=v.begin();itr!=v.end();++itr) {if (itr!=v.begin()) {s<< ", ";}s<<(*itr);}s<<" }";return s;}
template<typename T> ostream& operator<<(ostream& s,const multiset<T>& v){s<<"{ ";for(auto itr=v.begin();itr!=v.end();++itr) {if (itr!=v.begin()) {s<< ", ";}s<<(*itr);}s<<" }";return s;}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const map<T1,T2>& m){s<<"{"<<endl;for(auto itr=m.begin();itr!=m.end();++itr){s<<" "<<(*itr).first<<" : "<<(*itr).second<<endl;}s<<"}"<<endl;return s;}

const ll mod=1e9+7;
const ll inf=1e17;
const int INF=1e9;
const double EPS=1e-10;
const double PI=acos(-1);

//約数列挙
template <class T>
vector<T> divisor(T x){
	vector<T> res;
	for(T i=1;i*i<=x;i++){
		if(x%i==0){
			res.push_back(i);
			if(i!=x/i){
				res.push_back(x/i);
			}
		}
	}
	return res;
}

int main(){
	cin.tie(0);ios::sync_with_stdio(false);
	ll n;
	cin>>n;
	vector<ll> ret=divisor(n);
	ll ans=inf;
	for(auto x:ret){
		ll y=n/x;
		chmin(ans,x+y-2);
	}
	cout<<ans<<endl;
}

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

vector<int> ans, v[100000];
vector<bool> visit;

void dfs(int i){
    ans.push_back(i);
    visit[i] = true;
    for(int j : v[i]){
        if(visit[j])    continue;
        dfs(j);
        return;
    }
}

int main(){
    int n, m;
    cin >> n >> m;
    int a, b;
    for(int i = 0; i < m; i++){
        cin >> a >> b;
        a--, b--;
        v[a].push_back(b);
        v[b].push_back(a);
    }
    visit.resize(n, 0);
    dfs(0);
    reverse(ans.begin(), ans.end());
    ans.pop_back(); // 賢い
    dfs(0); // 賢い
    cout << ans.size() << endl;
    for(int i = 0; i < ans.size(); i++) cout << ans[i]+1 << " \n"[i==ans.size()-1];
    return 0;
}

Measured memory_bytes: 9720
using System;
using System.Collections.Generic;
class Solve{
    int N;
    long T;
    long[] a;
    public Solve(){}
    public static int Main(){
        new Solve().Calc();
        return 0;
    }
    void Calc(){
        getinput();
        long min = 1000000001;
        long max = 0;
        int count = 0;
        for(int i=0;i<N;i++){
            if(a[i] < min){
                min = a[i];
            }
            else if(a[i] - min == max){
                count++;
            }
            else if(a[i] - min > max){
                count = 1;
                max = a[i] - min;
            }
        }
        Console.WriteLine(count);
    }
    void getinput(){
        string[] str = Console.ReadLine().Split(' ');
        N = int.Parse(str[0]);
        T = Int64.Parse(str[1]);
        str = Console.ReadLine().Split(' ');
        a = new long[N];
        for(int i=0;i<N;i++){
            a[i] = Int64.Parse(str[i]);
        }
    }    
}

Measured memory_bytes: 12632
#include <bits/stdc++.h>
using namespace std;
int f,x,bisa;
int main () {
	cin >>f;
	
for (int s=1; s<=9;s++){
	for (int d=1; d<=9;d++) {
		if (d*s==f){
			bisa=1;
		}
	}
}
if (bisa==1){
	cout << "Yes"<<endl;
}else {
	cout << "No" << endl;
}
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <iostream>
#include <vector>
#include <algorithm>
#include <ctime>
#include <cmath>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <random>
#include <unordered_set>
#include <unordered_map>
#include <string>
#include <cstring>
#include <iomanip>
using namespace std;

#define int long long
#define double long double
#define mp make_pair
#define debug(x) cerr << #x << ": " << x << '\n';
#define fi first
#define se second
#define pb push_back
//typedef long long ll;
typedef pair<int, int> pii;
 
void fast() {
    ios_base::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
}

signed main() {
	fast();
	int a1 = -2e9, a2 = -2e9, a3 = -2e9, a4 = -2e9;
	int n;
	cin >> n;
	int ans = 0;
	for (int i = 0; i < n; i++) {
		int x, y;
		cin >> x >> y;
		ans = max(ans, a1 -x - y);
		ans = max(ans, a2 + x - y);
		ans = max(ans, a3 - x + y);
		ans = max(ans, a4 + x + y);
		a1 = max(a1, x + y);
		a2 = max(a2, -x + y);
		a3 = max(a3, x - y);
		a4 = max(a4, -x - y);
	}	
	cout << ans;
	return 0;
}

Measured memory_bytes: 3636
#include <stdio.h>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <list>
#include <iterator>
#include <assert.h>
#pragma warning(disable:4996) 

typedef long long ll;
#define MIN(a, b) ((a)>(b)? (b): (a))
#define MAX(a, b) ((a)<(b)? (b): (a))
#define LINF 9223300000000000000
#define INF 2140000000
const long long MOD = 1000000007;
using namespace std;

int main(int argc, char* argv[])
{
    char str[5]={0};
    scanf("%s", str);
    if(str[0]==str[1] || str[1]==str[2] || str[2]==str[3]) {
        printf("Bad\n");
    }
    else {
        printf("Good\n");
    }


    return 0;
}


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

using namespace std;

int main()
{	float M;
    int N,L1,O[100],a = 0,flag = 0;
    cin >> N >> M;
  	float V;

    while(cin >> L1){
      O[a]= L1;
      V = V + O[a];
      a++;
    }
	
for(int i = 0; i < a; i++){
 	if(O[i] >= V * (1 / (4 * M))){
     	flag++;
      
 	}
     	}
  
  if(flag >= M){
  	cout << "Yes";
  }
  if(flag < M){
    cout << "No";
  }

}

Measured memory_bytes: 256
import java.util.Scanner;
import java.util.Random;
import java.io.IOException;
import java.io.PrintWriter;
import java.io.File;
import java.io.FileWriter;

public class Main{
    public static Random rand = new Random();
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        PrintWriter out = new PrintWriter(System.out);
        long start = System.currentTimeMillis();
        int D = Integer.parseInt(sc.next());
        int[] C = new int[26];
        int[] L = new int[26];
        for (int i = 0; i < 26; i++){
            C[i] = Integer.parseInt(sc.next());
            L[i] = 0;
        }
        int[][] S = new int[D][26];
        int[] Ans = new int[D];
        for (int i = 0; i < D; i++){
            int maxS = 0;
            for (int j = 0; j < 26; j++){
                S[i][j] = Integer.parseInt(sc.next());
                if (S[i][j] > maxS){
                    maxS = S[i][j];
                    Ans[i] = j + 1;
                }
            }
        }
        int maxPoint = calcPoint(Ans, S, C, L, D);
        

        while (System.currentTimeMillis() - start < 1850){
            maxPoint = change(Ans, S, C, L, D, maxPoint, 1500 - (System.currentTimeMillis() - start));
        }

        
        
        for (int i = 0; i < D; i++){
            out.print(Ans[i]);
            out.print("\n");
        }

        //out.println(maxPoint);
        //template
        sc.close();
        out.flush();
    }

    public static int calcPoint(int[] Ans, int[][] S, int[] C, int[] L, int D){
        int point = 0;
        for (int i = 0; i < 26; i++){
            L[i] = 0;
        }
        for (int i = 0; i < D; i++){
            point += S[i][Ans[i] - 1];
            L[Ans[i] - 1] = i + 1;
            for (int j = 0; j < 26; j++){
                point -= C[j] * (i + 1 - L[j]);
            }
        }
        return point;
    }

    public static int change(int[] Ans, int[][] S, int[] C, int[] L, int D, int maxPoint, long t){
        int ci = rand.nextInt(D);
        int cj = rand.nextInt(D);
        int before = Ans[ci];
        int beforej = Ans[cj];
        Ans[ci] = rand.nextInt(26) + 1;
        Ans[cj] = rand.nextInt(26) + 1;
        int newPoint = calcPoint(Ans, S, C, L, D);
        if (newPoint < maxPoint){
            if (rand.nextInt(1900) < t){
                return newPoint;
            }
            else{
                Ans[ci] = before;
                Ans[cj] = beforej;
            return maxPoint;
            }    
        }
        else{
            return newPoint;
        }
    }
}

Measured memory_bytes: 42268
//#define sort(nums) sort(nums.begin(),nums.end())
#include <bits/stdc++.h>
#define mod 1000000007
#define deb(x) cout<<#x<<" "<<x<<endl
using namespace std;
using ll = long long int;

void jets(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
}


int main(){
// #ifndef ONLINE_JUDGE
//     freopen("input.txt", "r", stdin);
//     freopen("output.txt", "w", stdout);
// #endif
    jets();
    int n,w;
    cin>>n>>w;
    int val[n],weights[n];
    for(int i =0 ;i<n;i++){
    	cin>>weights[i];
    	cin>>val[i];
    }

    ll dp[n+1][w+1];
    memset(dp,0,sizeof(dp));
    for(int i=1;i<n+1;i++){
    	for(int j=1;j<w+1;j++)
    		if(j<weights[i-1])
    			dp[i][j]=dp[i-1][j];
    		else
    			dp[i][j]=max(dp[i-1][j],val[i-1]+dp[i-1][j-weights[i-1]]);
    }
    cout<<dp[n][w]<<endl;


    return 0;
}

Measured memory_bytes: 82448
#include <stdio.h>

typedef struct {
	int la;
	int th;
} NUM;

int main(void)
{
	int id, i;
	char str[16];
	NUM num[2000] = {{0, 0}};
	
	while (fgets(str, 16, stdin), str[0] != '\n'){
		i = 0;
		id = 0;
		while (str[i] != ','){
			id = id * 10 + str[i] - '0';
			i++;
		}
		
		num[id].la++;
	}
	
	while (fgets(str, 16, stdin) != NULL){
		i = 0;
		id = 0;
		while (str[i] != ','){
			id = id * 10 + str[i] - '0';
			i++;
		}
		
		num[id].th++;
	}
	
	for (i = 0; i < 2000; i++){
		if (num[i].la > 0 && num[i].th > 0){
			printf("%d %d\n", i, num[i].la + num[i].th);
		}
	}
	
	return (0);
}

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

#define rep(i, n) for(int (i) = 0; (i) < (n); (i)++)
#define repn(i, n) for(int (i) = 1; (i) <= (n); (i)++)
#define repr(i, n) for(int (i) = (n-1); (i) >= 0; (i)--)
#define all(x) (x).begin(), (x).end()
#define lint long long
#define ulint unsigned long long
#define fi first
#define se second
#define setpre(x) cout << fixed << setprecision(x)
#define ii(x) int x; cin >> (x)
#define ii2(x, y) int x, y; cin >> (x) >> (y)
#define ii3(x, y, z) int x, y, z; cin >> (x) >> (y) >> (z)
#define out(x) cout << (x) << endl
#define outs(x) cout << (x) << " "
#define yn(x) cout << ((x)?("Yes"):("No")) << endl
#define YN(x) cout << ((x)?("YES"):("NO")) << endl
#define bit_c(x) __builtin_popcountll(x)

inline void logger(){ cout << " [LOGGER] " << endl; }
template<typename A, typename... B>
void logger(const A& a, const B&... b){
    cout << a << " , ";
    logger(b...);
}

typedef pair<lint, lint> P;
const lint MOD = 1000000007;
const lint MOD9 = 998244353;
const lint INF = MOD * MOD;
const int MAX = 2005;

/* ...o(^-^)o... */

vector<int> to[MAX];
int d[MAX][MAX];
bool seen[MAX];

int main(){
    int n; cin >> n;
    int x, y; cin >> x >> y; x--; y--;

    rep(i, n-1){
        to[i].push_back(i+1);
        to[i+1].push_back(i);
    }
    to[x].push_back(y); to[y].push_back(x);

    rep(s, n){
        rep(i, n){
            seen[i] = false;
        }
        queue<int> q; q.push(s); seen[s] = true;

        while(!q.empty()){
            int t = q.front(); q.pop();
            for(int u : to[t]){
                if(seen[u]) continue;
                seen[u] = true;
                d[s][u] = d[s][t] + 1;
                q.push(u);
            }
        }
    }
    vector<int> ans(n);
    rep(i, n) rep(j, n){
        ans[d[i][j]]++;
    }
    rep(i, n-1){
        out(ans[i+1] / 2);
    }
}

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

ll ctoi(const char c){if('0'<=c&&c<='9') return (c-'0');return -1;}
#define ALL(x) begin(x),end(x)
  
int main(){
  ll n;
  cin >> n;
  vector<ll> a(n);
  rep(i,n) cin >> a[i];
  ll ans = 0;
  
  rep(i,n){
    if(a[a[i]-1] == i+1) ans++;
    a[i] = -1; //相思相愛うさぎ併せて１カウントする
  }
  
  cout << ans << endl;
  
}

Measured memory_bytes: 3976
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <queue>
#include <stack>
#include <cstdlib>
#include <map>
#include <iomanip>
#include <set>
#include <stdio.h>
#include <ctype.h>
#include <random>
#include <string.h>
#include <cmath>
#include <unordered_map>
#include <cstdio>
using namespace std;
#define all(vec) vec.begin(),vec.end()
typedef long long ll;

ll gcd(ll x, ll y) {
	if (y == 0)return x;
	return gcd(y, x%y);
}
ll lcm(ll x, ll y) {
	return x / gcd(x, y)*y;
}
ll kai(ll x, ll y, ll m) {
	ll res = 1;
	for (ll i = x - y + 1; i <= x; i++) {
		res *= i; res %= m;
	}
	return res;
}
ll mod_pow(ll x, ll y, ll m) {
	ll res = 1;
	while (y > 0) {
		if (y & 1) {
			res = res * x % m;
		}
		x = x * x % m;
		y >>= 1;
	}
	return res;
}

ll comb(ll x, ll y, ll m) {
	if (y > x)return 0;
	return kai(x, y, m) * mod_pow(kai(y, y, m), m - 2, m) % m;
}

ll ans;
int cnt;
string s, t;
int p;
int k;

signed main() {
	int mi = 1, ma = 10;
	while (ma - mi > 1) {
		int md = (mi + ma) / 2;
		cout << "? " << md << endl;
		cin >> s;
		if (s == "Y")mi = md;
		else ma = md;
	}
	if (mi == 9) {
		cout << "? " << 8000000000 << endl;
		cin >> s;
		cout << "? " << 89 << endl;
		cin >> t;
		if (s == "Y" || (s == "N"&&t == "N")) {
			for (ll i = 8; i >= 1; i--) {
				cout << "? " << i * 1000000000 << endl;
				cin >> s;
				if (s == "N") {
					cout << "! " << i + 1 << endl;
					return 0;
				}
			}
			cout << "! " << 1 << endl;
			return 0;
		}
	}
	p = mi + 1;
	k = p;
	ans = mi;
	while (1) {
		p *= 10;
		cnt++;
		if (cnt == 9) {
			cout << "! " << 1000000000 << endl;
			return 0;
		}
		mi = 0, ma = 10;
		while (ma - mi > 1) {
			int md = (mi + ma) / 2;
			cout << "? " << ans * 10 + md << endl;
			cin >> s;
			if (s == "Y")mi = md;
			else ma = md;
		}
		if (mi < 9) {
			ans = ans * 10 + mi;
			continue;
		}
		cout << "? " << p << endl;
		cin >> s;
		if ((k == 10 && s == "Y") || (k != 10 && s == "N")) {
			ans = ans * 10 + mi;
			continue;
		}
		for (int i = 8; i >= 0; i--) {
			cout << "? " << (ans * 10 + i) * 1000000000 << endl;
			cin >> s;
			if (s == "N") {
				cout << "! " << ans * 10 + i + 1 << endl;
				return 0;
			}
		}
		cout << "! " << ans * 10 << endl;
		return 0;
	}
}


Measured memory_bytes: 596
#include <cstdio>
int a[1001];
int main(int argc, const char * argv[]) {
   
    int n,m;
    
    scanf("%d %d",&n,&m);
    
    int mx = 10000;
    int sum = 0;
    for(int i=0;i<n;i++){
        scanf("%d",&a[i]);
        if(mx>a[i]) mx = a[i];
        sum+=a[i];
    }
    
    int left = m-sum;
    
    printf("%d\n",n+left/mx);
    
    return 0;
}


Measured memory_bytes: 128
#include <iostream>      // cout, endl, cin
#include <string>        // string, to_string, stoi
#include <vector>        // vector
#include <algorithm>     // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility>       // pair, make_pair
#include <tuple>         // tuple, make_tuple
#include <cstdint>       // int64_t, int*_t
#include <cstdio>        // printf
#include <map>           // map
#include <queue>         // queue, priority_queue
#include <set>           // set
#include <stack>         // stack
#include <deque>         // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset>        // bitset
#include <cctype>        // isupper, islower, isdigit, toupper, tolower
#include <iomanip>
using namespace std;

int main()
{
  int A, B, H, M;
  double ax, ay, aang, bx, by, bang, dist;
  cin >> A >> B >> H >> M;

  aang = (1 - (H + M / 60.0) / 12.0) * 2 * M_PI;
  bang = (1 - M / 60.0) * 2 * M_PI;
  ax = A * cos(aang);
  ay = A * sin(aang);
  bx = B * cos(bang);
  by = B * sin(bang);
  dist = sqrt(pow(ax - bx, 2) + pow(ay - by, 2));

  cout << fixed << setprecision(10) << dist << endl;
}


Measured memory_bytes: 3648
#include<stdio.h>
int main(){
    int n,p[15],i,sum = 0,max = 0;
    scanf("%d",&n);
    for(i=0;i<n;i++){
        scanf("%d",&p[i]);
        sum += p[i];
        if(max<p[i]){
            max = p[i];        }
    }
    sum -= max/2;
    printf("%d\n",sum);
    return 0;
}

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

using namespace std;

int main() {
    string str;
    string c = "000";

    cin >> str;

    int min = abs(753 - stoi(str.substr(0, 3)));

    int temp;
    for (int i = 1; i < str.size() - 2; i++) {
        temp = abs(753 - stoi(str.substr(i, 3)));
        if (temp < min)
            min = temp;
    }

    cout << min << endl;

    return 0;
}



Measured memory_bytes: 256