akhauriyash/Code-Regression huggingface dataset:
// #define DEBUG_ON

#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#define timer_start()                          \
  chrono::system_clock::time_point start, end; \
  start = chrono::system_clock::now();
#define timer_wrap()                                                     \
  end = chrono::system_clock::now();                                     \
  double time = static_cast<double>(                                     \
      chrono::duration_cast<chrono::microseconds>(end - start).count() / \
      1000.0);                                                           \
  printf("time %lf[ms]\n", time);                                        \
  start = end;
#define optimize_cin() \
  cin.tie(0);          \
  ios::sync_with_stdio(false)
using namespace std;
#define INF 1000000000  // 10^9
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;
}
// ########## template end ##########

int main() {
#ifdef DEBUG_ON
  timer_start();
#endif

  long long n;
  cin >> n;

  // main

  // output
  cout << fixed;
  cout << setprecision(0) << pow(n, 3) << endl;

#ifdef DEBUG_ON
  timer_wrap();
#endif
  return 0;
}



Measured memory_bytes: 3220
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const static ll INF = 1e15;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
// __uint128_t
const ll MOD = 1e9+7;



int main(){
    ll H, W; cin >> H >> W;
    vector<string> S(H); for(int i = 0; i < H; i++) cin >> S[i];
    ll bs = 0;
    for(int i = 0; i < H; i++){
        for(int j = 0; j < W; j++) if(S[i][j] == '#') bs++;
    }

    vector<vector<ll>> V(H, vector<ll>(W, INF));
    queue<ll> qh, qw;
    qh.push(0); qw.push(0);
    V[0][0] = 0;
    int dh[] = {0, 1, 0, -1};
    int dw[] = {1, 0, -1, 0};
    
    while(!qh.empty()){
        ll h = qh.front(), w = qw.front();
        qh.pop(), qw.pop();
        for(int i = 0; i < 4; i++){
            ll nh = h+dh[i], nw = w+dw[i];
            if(0<=nh && nh < H && 0<=nw && nw<W && S[nh][nw] == '.' && V[h][w]+1<V[nh][nw]){
                qh.push(nh);
                qw.push(nw);
                V[nh][nw] = V[h][w]+1;
            }
        }
    }
    if(V[H-1][W-1] == INF) cout << -1 << endl;
    else cout << H*W-bs-V[H-1][W-1]-1 << endl;






}


Measured memory_bytes: 3620
fn read_str() -> String {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).expect("Fail to read input.");
    s
}

fn read_nums() -> Vec<i32> {
    let s = read_str();
    let a: Vec<&str> = s.split(' ').collect();
    let mut v: Vec<i32> = Vec::new();
    for x in a {
        v.push(x.trim().parse().expect("Could not parse."));
    }
    v
}

fn main() {
    let v = read_nums();
    let (a, b) = (v[0], v[1]);
    if a < b {
        println!("a < b");
    } else if a > b {
        println!("a > b");
    } else {
        println!("a == b");
    }
}



Measured memory_bytes: 5020
import java.util.Scanner;

public class Main {
    static int gcd(int a, int b)
    {
        if(a == 0 || b == 0) return a+b;
        return gcd(b,a%b);
    }

    public static void main(String[] args) {
        Scanner input1 =  new Scanner(System.in);
        int a = input1.nextInt();
        int b = input1.nextInt();
        System.out.println(gcd(a,b));
    }
}


Measured memory_bytes: 26320
#include <iostream>
#include <string>
#include <cstring>
#include <fstream>
#include <random>
#include <cmath>
#include <iomanip>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <map>
#include <deque>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <list>
#include <unordered_map>
#include <bitset>
#include <sstream>

typedef  long long ll;
#define mop 1000000007
using namespace std;

ll gcd(ll a, ll b) {
    if(a < b) gcd(b, a);
    ll r;
    while ((r=a%b)) {
        a = b;
        b = r;
    }
    return b;
}

ll lcm(ll a, ll b) {
    return a * b / gcd(a,b);
}


int main() {
   

    ll a,b;
    cin >> a >> b;
    //cout << gcd(a,b) << endl;
    cout << lcm(a,b) << endl;
    //cout << 18696%123 << endl;



}

Measured memory_bytes: 256
using System;


    public static class Program
    {
    static void Main()
    {
        var data1 = Console.ReadLine().Split(' ');
        int[] a = new int[5];
        for (var i = 0; i < 5; i++)
        {
            a[i] =int.Parse(data1[i]);
        }

        if ((a[2]+a[4]) <= a[0] && (a[2] - a[4]) >= 0 && (a[3] + a[4]) <= a[1] && (a[3] - a[4]) >= 0)
        {
            Console.WriteLine("Yes");
        }
        else
        {
            Console.WriteLine("No");
        }
   
        
       
    }
    }


Measured memory_bytes: 17940
using System;
using System.Collections;

namespace C
{
    class Program
    {
        static void Main(string[] args)
        {
            long n = long.Parse(Console.ReadLine());
            var s = new Stack();
            while (n!=0)
            {
                char c;
                int x;
                bool flag = false;
                if (n % 26 == 0)
                {
                    x = 26;
                    flag = true;
                }
                else
                {
                    x = (int)(n % 26);
                }
                c = (char)(96 + x);
                s.Push(c);
                n /= 26;
                if(flag)n -= 1;//ここ大事
            }
            while (s.Count != 0)
            {
                Console.Write(s.Pop());
            }
        }
    }
}


Measured memory_bytes: 27672
import math

#n, a, b= map(int, input().split())
a, b  = map(int, input().split())
#h = list(map(int, input().split()))
#s = list(str(input()))
#n = int(input())

tot = 0
count = 0

for i in range(a, b+1):
  n_str = list(str(i))
  integ  = [int(s) for s in n_str]
  integ_rev = integ[::-1]
  if (integ == integ_rev):
    count = count + 1

print(count)

Measured memory_bytes: 3060
void 
solve();

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

//////////////////////////////////////////////////
//////////////////////////////////////////////////
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;

long long N, M;
vector<int> X, Y;
int MOD = 1e9 + 7;

void solve() {
	cin >> N >> M;
	N--; M--;
	X.resize(N+1); Y.resize(M+1);
	int prev;
	cin >> prev;
	for (int n = 1; n <= N; n++) {
		int x; cin >> x;
		X[n] = x - prev;
		prev = x;
	}
	cin >> prev;
	for (int m = 1; m <= M; m++) {
		int y; cin >> y;
		Y[m] = y - prev;
		prev = y;
	}
	long long ans = 1;
	long long sum = 0;
	for(long long n = 1;n <= N;n++){
		sum += (long long)(X[n]) * n * (N - n + 1);
	}
	ans = sum % MOD;
	sum = 0;
	for (long long m = 1; m <= M; m++) {
		sum += (long long)(Y[m]) * m * (M - m + 1);
	}
	sum %= MOD;
	ans = (ans * sum) % MOD;
	cout << ans << endl;
	return;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
 
typedef long long int ll;
typedef vector<int> vi;
typedef vector<ll> vll;
 
#define  pb     push_back
#define  all(x) (x).begin(), (x).end()
#define  rep(i,a,b) for(int i=a ; i<b ; ++i)
#define  repr(i,a,b) for(int i=a ; i>=b ; --i)
#define  deb(x) cout << #x << " - " << x << "\n";
#define  IOS    ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define  D2(x)  { cerr << "[" << #x << ": "; for(auto it:x) cerr << it << " "; cerr << "]\n"; }
#define  ps(x,y) fixed<<setprecision(y)<<x
 
#define PI 3.141592653589793
const ll MOD = 1e9 + 7;
const ll INF = 1000000000000;
const ll MAX_N = 1e6 + 2;

void solve(){
    int a,b,c,k; cin >> a >> b >> c >> k;
    int cnt=0;
    while(a>=b) {
        b*=2;
        cnt++;
    }
    while(b>=c){
        c*=2;
        cnt++;
    }
    if(cnt<=k) cout << "Yes";
    else cout << "No";
}
 
int main() {
    IOS;
    // int t; cin >> t;
    int t = 1; 
    while(t--) solve();
}

Measured memory_bytes: 3660
#include <stdio.h>
int main(void){
    int a,b,c;
    
    scanf("%d %d %d",&a,&b,&c);
    
    if (0 <= a && a < b && b < c && c <= 100)
        puts("Yes");
    else
        puts("No");
  
    return 0; 
}


Measured memory_bytes: 2040
#include<stdio.h>
#include<stdlib.h>

#define NIL NULL

struct node{
  struct node *right;
  struct node *left;
  struct node *parent;
  int key;
};
typedef struct node *Node;

Node root;

Node treeMinmum(Node x){
  while(x->left != NIL) x = x->left;
  return x;
}

Node treeMaxmum(Node x){
  while(x->right != NIL) x = x->right;
  return x;
}

Node treeSearch(Node u, int k){
  if(u==NIL || k==u->key) return u;
  if(k<u->key) return treeSearch(u->left,k);
  else return treeSearch(u->right,k);
}

Node treeSuccessor(Node x){
  Node y=NIL;
  
  if(x->right != NIL) return treeMinmum(x->right);

  y = x->parent;
  while(y != NIL && x == y->right){
    x = y;
    y = y->parent;
  }
  return y;
}

void treeDelete(Node z){
  Node y;
  Node x;

  if(z->left == NIL || z->right == NIL) y = z;
  else y = treeSuccessor(z);

  if(y->left != NIL) x = y->left;
  else x = y->right;

  if(x!=NIL) x->parent = y->parent;
  
  if(y->parent == NIL) root = x;
  else if(y==y->parent->left) y->parent->left = x;
  else y->parent->right = x;

  if(y!=z) z->key = y->key;
}

void insert(int k){
  Node y = NIL;
  Node x = root;
  Node z;

  z = malloc(sizeof(struct node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;

  while(x!=NIL){
    y = x;
    if(z->key < x->key) x = x->left;
    else x = x->right;
  }
  z->parent = y;

  if(y==NIL) root = z;
  else if(z->key < y->key) y->left = z;
  else y->right = z;

  
}

void inorder(Node u){
  if(u!=NIL){
    inorder(u->left);
    printf(" %d",u->key);
    inorder(u->right);
  }
}

void preorder(Node u){
  if(u!=NIL){
    printf(" %d",u->key);
    preorder(u->left);
    preorder(u->right);
  }
}

int main(){
  root = malloc(sizeof(Node));
  root = NIL;
  
  int n,i,x;
  char com[20];
  scanf("%d",&n);

  for(i=0;i<n;i++){
    scanf("%s",com);
    if(com[0]=='f'){
      scanf("%d",&x);
      Node t = treeSearch(root,x);
      if(t!=NIL) printf("yes\n");
      else printf("no\n");
    }else if(com[0]=='i'){
      scanf("%d",&x);
      insert(x);
    }else if(com[0]=='p'){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    }else if(com[0]=='d'){
      scanf("%d",&x);
      treeDelete(treeSearch(root,x));
    }
  }

  return 0;
		  
}



Measured memory_bytes: 25132
#pragma comment(linker, "/stack:20000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx")
 
#include <stdio.h>
#include <bits/stdc++.h>
 
using namespace std;
 
#include <x86intrin.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
template <typename T> using ordered_set = tree<T, null_type, std::less<T>, rb_tree_tag, tree_order_statistics_node_update>;
  
#define pb push_back
#define mp make_pair
#define in insert
#define f first
#define s second
#define ll long long
#define dd double
  
const int mod = 1e9 + 7;
const int N = 2e5 + 7;
const int inf = 2e9;
const ll INF = 1e18;

ll n, k; 

vector<vector<int>> mul (vector<vector<int>> a, vector<vector<int>> b) {
	vector<vector<int>> c(n, vector<int> (n));
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++) {
			for (int k = 0; k < n; k++) {
				c[i][j] = (c[i][j] + a[i][k] * 1ll * b[k][j] % mod) % mod;
			}
		}
	}
	return c;
}

vector<vector<int>> binpow (vector<vector<int>> a, ll n) {
	if (n == 1) 
		return a;
	if (n % 2 == 1)
		return mul (binpow (a, n - 1), a);
	else {
		vector<vector<int>> b;
		b = binpow (a, n / 2);
		return mul (b, b);
	}
}

int main() {
	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	// freopen("*.in", "r", stdin);freopen("*.out", "w", stdout);
	cin >> n >> k;
	vector<vector<int>> a(n + 1, vector<int> (n + 1));

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

	vector<vector<int>> v(n + 1, vector<int> (n + 1));
	v = binpow (a, k);
	int sum = 0;

	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++) {
			sum = (sum + v[i][j]) % mod;
		}
	}
	cout << sum;
}

Measured memory_bytes: 2560
# coding: utf-8
# Your code here!
array = input().split()
array = [int(i) for i in array]
if (array[2] + array[4] <= array[0]) & (array[3] + array[4] <= array[1]) & (array[2] - array[4] >= 0) & (array[3] - array[4] >= 0):
    print("Yes")
else:
    print("No")


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

int main() {

	ll n; cin >> n;
	vector<ll> a(n + 1), b(n + 1);
	for (ll i = 0; i < n + 1; i++) {
		cin >> a[i];
	}
	for (ll i = 0; i < n; i++) {
		cin >> b[i];
	}
	ll ans = 0;
	for (ll i = 0; i < n; i++) {
		if (b[i] <= a[i]) {
			a[i] -= b[i];
			ans += b[i];
			b[i] = 0;
		}
		else { // a[i] < b[i]
			b[i] -= a[i];
			ans += a[i];
			a[i] = 0;			
		}
		if (b[i] <= a[i + 1]) {
			a[i + 1] -= b[i];
			ans += b[i];
			b[i] = 0;
		}
		else { // a[i + 1] < b[i]
			b[i] -= a[i + 1];
			ans += a[i + 1];
			a[i + 1] = 0;			
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 4800
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace Competitive
{
    internal class Solution
    {
        public int N, W;
        public long MOD = 1000000007;
        public long[] WS;
        public long[] VS;

        public void Run()
        {
            // 入力
            {
                var line = Input.ReadIntArray();
                N = line[0];
                W = line[1];
            }

            WS = new long[N];
            VS = new long[N];

            for (int i = 0; i < N; i++)
            {
                var line = Input.ReadIntArray();
                WS[i] = line[0];
                VS[i] = line[1];
            }

            // 初期化
            long VM = 100 * 1000;
            long[,] DP = new long[N, VM + 1];
            long inf = long.MaxValue / 10;

            for (int i = 0; i < N; i++)
            {
                for (int v = 0; v <= VM ; v++)
                {   
                    DP[i, v] = v == 0 ? 0 : inf;
                }
            }

            // 1個目の要素
            DP[0, VS[0]] = WS[0];

            // 2個目以降の要素
            for (int i = 1; i < N; i++)
            {
                for (int v = 0; v <= VM; v++)
                {
                    DP[i, v] = DP[i - 1, v];
                    if (v >= VS[i])
                    {
                        DP[i, v] = Math.Min(DP[i - 1, v - VS[i]] + WS[i], DP[i, v]);
                    }
                }
            }

            // 出力
            long ret = 0;
            for (int v = 0; v <= VM; v++)
            {
                if (DP[N - 1, v] <= W)
                {
                    ret = Math.Max(ret, v);
                }
            }

            Console.WriteLine(ret);
        }
    }

    // libs ----------


    // common ----------

    internal static class Input
    {
        public static string ReadString()
        {
            string line = Console.ReadLine();
            return line;
        }

        public static int ReadInt()
        {
            string line = Console.ReadLine();
            return int.Parse(line);
        }

        public static int[] ReadIntArray()
        {
            string line = Console.ReadLine();
            return line.Split(' ').Select(int.Parse).ToArray();
        }

        public static long ReadLong()
        {
            string line = Console.ReadLine();
            return long.Parse(line);
        }

        public static long[] ReadLongArray()
        {
            string line = Console.ReadLine();
            return line.Split(' ').Select(long.Parse).ToArray();
        }

        public static double[] ReadDoubleArray()
        {
            string line = Console.ReadLine();
            return line.Split(' ').Select(double.Parse).ToArray();
        }
    }

    internal class Program
    {
        public static void Main(string[] args)
        {
            var s = new Solution();
            s.Run();
        }
    }
}

Measured memory_bytes: 91232
#include <stdio.h>
#include <algorithm>
#include<math.h>
#include<cstdlib>
#include<cstring>
using namespace std;
 int main()
{ int A,B,C,D;
  scanf("%d%d%d%d",&A,&B,&C,&D);
  int c;
  c = max(A*B,C*D); 
  if(A*B==C*D)
{ 
  printf("%d",A*B);
}
  else
{
  printf("%d",c);
}
 return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <cstring>
#include <algorithm>
#include <queue>
#include <cstdlib>
#include <cstdio>

using namespace std;

int main(){
	int a, b;
	cin >> a >> b;
	if (a % 2 == 0 || b % 2 == 0)
		cout << "Even" << endl;
	else
		cout << "Odd" << endl;
	return 0;
}

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

int main(){
    int n;
    cin >> n;
    string s;
    cin >> s;
    int result = 0;
    int buffer = 0;
    for(int i=0;i<n;i++){
        if(s[i] ==  'I'){
            buffer++;
        }else if(s[i] = 'D'){
            buffer--;
        }

        if(buffer > result){
            result = buffer;
        }
    }
    cout << result << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <stdio.h>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <string>
#include <map>
#include <set>
#include <list>
#define rep(i, n) for(int i=0; i<(n); ++i)
#define rep2(i, s, n) for(int i=s; i<(n); ++i)
#define sz(x) int(x.size())

typedef long long ll;

using namespace std;

/*******-c++14 don't include-*******/
template<typename T>
T gcd(T a, T b){if( b == 0)return a; return gcd(b, a%b); }
template<typename T>
T lcm(T a, T b){return a*b/gcd(a,b); }
void printArr(int *a, int len){for(int i=0; i<len; i++){if(i)cout << " ";cout << a[i];}cout << endl;}
/*******---------------------*******/

static const int INTINF = (2147483647);
static const ll LLINF = (1ll<<32);
static const int MAX = 100001;

int arr[MAX];

int main(int argc, const char * argv[]) {
    // input from txt
    
    /////////
    //write//
    /////////
    
    int n;
    cin >> n;
    int res = (n-1)/2;
    cout << res << endl;
    
    
    return 0;
}


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

using namespace std;
typedef long long ll;
#define int ll

template<typename T1,typename T2> inline void chmin(T1 &a, T2 b){ if(a > b) a = b; }
template<typename T1,typename T2> inline void chmax(T1 &a, T2 b){ if(a < b) a = b; }

#define REP(i,n) for(int i=0;i<n;++i)
#define SORT(name) sort(name.begin(), name.end())
#define ZERO(p) memset(p, 0, sizeof(p))
#define MINUS(p) memset(p, -1, sizeof(p))
#if 1
#  define DBG(fmt, ...) printf(fmt, ##__VA_ARGS__)
#else
#  define DBG(fmt, ...)
#endif

const ll LLINF = (1LL<<60);
const int INF = (1LL<<30);
const double DINF = std::numeric_limits<double>::infinity();
const int MOD = 1000000007;
const int MAX_N = 3010;

int N, T;
vector< pair<int, int> > BA;

int dp[MAX_N][MAX_N][2];

// i 番目の料理を見ていて、現在のコストは j、
// 最後に食べるものを選定済みなら k = 1, そうでないなら k = 0
int dfs(int i, int j, int k) {
    if(i >= N) {
        return 0;
    }

    int& ret = dp[i][j][k];
    if(~ret) { return ret; }

    // 食べない場合
    ret = dfs(i+1, j, k);

    int a = BA[i].second;
    int b = BA[i].first;

    // 食べる場合
    if(j + a < T) {
        chmax(ret, dfs(i+1, j + a, k) + b);
    }

    // これを最後に選ぶ場合
    if(k == 0) {
        chmax(ret, dfs(i+1, j, 1) + b);
    }

    return ret;
}

signed main() {
    cin.tie(0); cout.tie(0);
    ios::sync_with_stdio(false);

    cin >> N >> T;
    REP(i, N) {
        int a, b;
        cin >> a >> b;
        BA.push_back(make_pair(b, a));
    }

    MINUS(dp);
    int ans = dfs(0, 0, 0);
    printf("%lld\n", ans);

    return 0;
}


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

int main() {
  ll N; cin >> N;
  ll v[N];
  for (ll i = 0; i < N; i++) {
    cin >> v[i];
  }
  map<ll,ll> count0;
  map<ll,ll> count1;
  for (ll i = 0; i < N; i++) {
    if (i % 2 == 0) count0[v[i]]++;
    if (i % 2 == 1) count1[v[i]]++;
  }
  ll m0 = 0; ll m1 = 0;
  ll v0, v1;
  for (ll i = 0; i < N; i++) {
    if (i%2 == 0) {
      if (m0 < count0[v[i]]) {v0 = v[i];}
      m0 = max(m0, count0[v[i]]);
    }
    if (i%2 == 1) {
      if (m1 < count1[v[i]]) {v1 = v[i];}
      m1 = max(m1, count1[v[i]]);
    }
  }
  ll c0 = 0;
  ll c1 = 0;
  for (ll i = 0; i <= 100000; i++) {
      if (count0[i] == m0) c0++;
      if (count1[i] == m1) c1++;
  }
  ll res;
  if (c0 == 1 && c1 == 1 && v0 == v1) {
    ll m20 = 0;
    ll m21 = 0;
    for (ll i = 0; i <= N; i++) {
    if (i%2 == 0 && count0[v[i]] < m0) m20 = max(m20, count0[v[i]]);
    if (i%2 == 1 && count1[v[i]] < m1) m21 = max(m21, count1[v[i]]);
    }
    res = min(N-m20-m1, N-m21-m0);
  } else {
    res = N-m0-m1;
  }
  cout << res << endl;
}

Measured memory_bytes: 13568
import java.util.*;
import java.util.stream.IntStream;
class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
	int N = sc.nextInt();
    int[] a = new int[N];
    for (int i = 0; i < N; i++) a[i] = sc.nextInt();
    int[] dp = new int[N];
    dp[0] = 0;
    dp[1] = Math.abs(a[1]-a[0]);
    for (int i = 2; i < N; i++) {
      dp[i] = Math.min(dp[i-2] + Math.abs(a[i] - a[i-2]), 
                       dp[i-1] + Math.abs(a[i] - a[i-1]));
    }
    //System.out.println(Arrays.toString(dp));
    System.out.println(dp[N-1]);
  }
}

Measured memory_bytes: 48572
N=int(input())
A=[int(input()) for i in range(N)]
from collections import deque
A.sort()
q=deque(A)
q2=deque()
q2.append(q.popleft())
k=N-1
while(k>0):
  if len(q)>0:
    q2.appendleft(q.pop())
    k-=1
  if len(q)>0:
    q2.append(q.pop())
    k-=1
  if len(q)>0:
    q2.appendleft(q.popleft())
    k-=1
  if len(q)>0:
    q2.append(q.popleft())
    k-=1
  if len(q)==0:
    break
prev=q2.popleft()
ans=0
for i in range(N-1):
  now=q2.popleft()
  ans+=abs(now-prev)
  prev=now

q=deque(A)
q2=deque()
q2.append(q.pop())
k=N-1
while(k>0):
  if len(q)>0:
    q2.appendleft(q.popleft())
    k-=1
  if len(q)>0:
    q2.append(q.popleft())
    k-=1
  if len(q)>0:
    q2.append(q.pop())
    k-=1
  if len(q)>0:
    q2.appendleft(q.pop())
    k-=1
  if len(q)==0:
    break
prev=q2.popleft()
tmp=0
for i in range(N-1):
  now=q2.popleft()
  tmp+=abs(now-prev)
  prev=now  
  
print(max(ans,tmp))  

Measured memory_bytes: 8172
#include <bits/stdc++.h>
#define LOCAL
using namespace std;
template <typename A, typename B>
ostream& operator <<(ostream& out, const pair<A, B>& a) {
out << "(" << a.first << "," << a.second << ")";
return out;
}
template <typename T, size_t N>
ostream& operator <<(ostream& out, const array<T, N>& a) {
out << "["; bool first = true;
for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
return out;
}
template <typename T>
ostream& operator <<(ostream& out, const vector<T>& a) {
out << "["; bool first = true;
for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
return out;
}
template <typename T, class Cmp>
ostream& operator <<(ostream& out, const set<T, Cmp>& a) {
out << "{"; bool first = true;
for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "}";
return out;
}
template <typename U, typename T, class Cmp>
ostream& operator <<(ostream& out, const map<U, T, Cmp>& a) {
out << "{"; bool first = true;
for (auto& p : a) { out << (first ? "" : ", "); out << p.first << ":" << p.second; first = 0;} out << "}";
return out;
}
#ifdef LOCAL
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
#else
#define trace(...) 42
#endif
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
const char* comma = strchr(names + 1, ',');
cerr.write(names, comma - names) << ": " << arg1 << " |";
__f(comma + 1, args...);
}
#define rep(i,n) for(int i=0; i<(n); i++)
using ll = long long;
#define int long long
using P = pair<int,int>;
//#########################################
const int INF = 1e18;
signed main(){
    int n;cin >> n;
    vector<int> a(n);
    rep(i,n)cin >> a[i];
    vector<P> ans;
    auto push = [&](int x,int y){
        
        a[y] += a[x];
        ans.push_back(P(x,y));

    };
    int mx = -INF;
    int mn = INF;
    rep(i,n){
        mx = max(mx,a[i]);
        mn = min(mn,a[i]);
    }
    if(abs(mx) > abs(mn)){
        int addi = 0;
        rep(i,n){
            if(mx == a[i])addi = i;
        }
        rep(i,n)push(addi,i);
        // trace(a);
        rep(i,n-1)push(i,i+1);
    }
    else {
        int addi = 0;
        rep(i,n){
            if(mn == a[i])addi = i;
           
        }
        rep(i,n)push(addi,i);
        for(int i = n-1;i > 0;i--)push(i,i-1);

    }
    cout << ans.size() << endl;
    for(auto p:ans){
        cout << p.first+1 << " " << p.second+1 << endl;
    }
    // trace(a);
    return 0;
}

Measured memory_bytes: 3508
def is_triangle(a, b, c):
    if a >= b + c:
        return False

    if b >= a + c:
        return False

    if c >= a + b:
        return False

    return True


def main():
    N = int(input())
    L = list([int(x) for x in input().split()])

    L.sort(reverse=True)

    count = 0
    for a_i in range(N-2):
        b_i = a_i + 1
        c_i = 1
        while b_i + c_i < N:

            if not is_triangle(L[a_i], L[b_i], L[-c_i]):
                c_i += 1

            else:
                count += (N - b_i - c_i)
                b_i += 1

    print(count)


if __name__ == '__main__':
    main()


Measured memory_bytes: 9332
d,g=map(int,input().split())
p=[]
c=[]
for i in range(d):
    P,C=map(int,input().split())
    p.append(P)
    c.append(C)
ans=sum(p)
for i in range(2**d):
    z=i
    x=[]
    for j in range(d):
        x.append(z%2)
        z=z//2
    po=0
    m=0
    for j in range(d):
        if x[j]==1:
            po+=100*(j+1)*p[j]+c[j]
            m+=p[j]
    q=[[] for j in range(d)] #残りp、c
    s=0
    for j in range(d):
        if x[j]==0:
            q[s].append(100*(j+1))
            q[s].append(p[j])
            s+=1
    q=[q[j] for j in range(d) if q[j]!=[]]
    q=sorted(q,reverse=True)
    w=len(q)
    for j in range(w):
        q[j][1]-=1
    if po>=g:
        ans=min(ans,m)
    else:
        for j in range(w):
            if po+q[j][0]*q[j][1]>=g:
                m+=(g-po+q[j][0]-1)//q[j][0]
                ans=min(ans,m)
                break
            else:
                po+=q[j][0]*q[j][1]
                m+=q[j][1]
print(ans)


Measured memory_bytes: 9304
n = int(input())
H = list(map(int, input().split( )))
H.append(10**10)
ans = 0
cnt = 0
for i in range(n):
  if H[i] >= H[i+1]:
    cnt += 1
  else:
    ans = max(ans,cnt)
    cnt = 0
print(ans)

Measured memory_bytes: 84932
#[allow(unused_imports)]
use std::cmp;

// Input macro from https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
  (source = $s:expr, $($r:tt)*) => {
    let mut iter = $s.split_whitespace();
    input_inner!{iter, $($r)*}
  };
  ($($r:tt)*) => {
    #[allow(unused_mut)]
    let mut 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: usize,
    k: usize,
    v: [i64; n],
  }
  let mut ans = -(1i64 << 30);
  for l in 0..n {
    for r in l..n+1 {
      if l + n - r > k {
        continue;
      }
      let mut heap = vec![];
      for i in 0..l {
        heap.push(v[i]);
      }
      for i in r..n {
        heap.push(v[i]);
      }
      heap.sort();
      let mut val: i64 = heap.iter().sum();
      for i in 0..cmp::min(l+n-r, k-(l+n-r)) {
        if heap[i] < 0 {
          val -= heap[i];
        }
      }
      ans = cmp::max(ans, val);
    }
  }
  println!("{}", ans);
}


Measured memory_bytes: 4352
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String s = sc.next();
        //System.err.println(s);
        boolean flag = true;
        if(s.startsWith("A")) {
            String ns = s.substring(2, s.length()-1);
            int count = 0;
            for(char c : ns.toCharArray()) {
                if(c=='C') {
                    count++;
                }
            }
            if(count!=1) {
                //System.err.println("not 1");
                flag = false;
            }
            for(char c : s.substring(1).toCharArray()) {
                if(c!='C' && !String.valueOf(c).toLowerCase().equals(String.valueOf(c))) {
                    flag = false;
                }
            }
        } else {
            //System.err.println("not A");
            flag = false;
        }
        System.out.println(flag ? "AC" : "WA");
    }
}

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

#include <algorithm>
#include <iomanip>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>

long long int a[114514] = {};

int main() {

    long long int n, m;
    cin >> n >> m;

    vector< vector< pair< long long int, long long int > > > v;
    for ( long long int i = 0; i < n; i++ ) {
        vector< pair< long long int, long long int > > vv;
        v.push_back( vv );
    }

    for ( long long int i = 0; i < m; i++ ) {
        long long int l, r, c;
        cin >> l >> r >> c;
        l--;
        r--;
        v[l].push_back( make_pair( r, c ) );
    }

    long long int k = -1;
    priority_queue< pair< long long int, long long int > > q;
    q.push( make_pair( 0, 0 ) );
    while( q.size() > 0 ) {
        long long int d = -q.top().first;
        long long int p = q.top().second;
        q.pop();
        for ( long long int i = p; i > k; i-- ) {
            for ( long long int j = 0; j < v[i].size(); j++ ) {
                long long int x = v[i][j].first;
                long long int z = v[i][j].second + d;
                if ( a[x] == 0 || a[x] > z ) a[x] = z;
                q.push( make_pair( -z, x ) );
            }
        }
        k = max( k, p );
    }

    if ( a[n-1] == 0 ) {
        cout << -1 << endl;
    } else {
        cout << a[n-1] << endl;
    }

    return 0;

}


Measured memory_bytes: 9840
import java.util.*;
import java.lang.*;

public class Main{
    public static void main(String args[]){
        Scanner scanner = new Scanner(System.in);
        int N = scanner.nextInt();
        int M = scanner.nextInt();
        List<Integer> a = new ArrayList<>();
        for(int i=0; i<M; i++){
            a.add(scanner.nextInt());
        }
        Set<Integer> bloken = new HashSet<>(a);
        List<Integer> w = new ArrayList<>();
        w.add(1);
        if(bloken.contains(1)){
            w.add(0);
        }else{
            w.add(1);
        }
        
        for(int i=2; i<=N; i++){
            if(bloken.contains(i)){
                w.add(0);
            }else{
                w.add( (w.get(i-1) + w.get(i-2))%1000000007 );
            }
        }
        
        //System.out.println(w);
        System.out.println(w.get(N)%1000000007);
    }
}

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

int main() {
    using namespace std;

    int A, B, C, X;
    cin >> A >> B >> C >> X;

    int count = 0;
    for (int i=0; i<=A; i++) {
        int a = 500 * i;
        for (int j=0; j<=B; j++)  {
            int b = 100 * j;
            for (int k=0; k<=C; k++) {
                int c = 50 * k;
                if ((a + b + c) == X) {
                    count++;
                }
            }
        }
    }

    cout << count << endl;

    return 0;
}

Measured memory_bytes: 256
# https://atcoder.jp/contests/agc027/tasks/agc027_a


def main():
    N, x = map(int, input().split())
    a = list(map(int, input().split()))
    a.sort()

    count = 0
    i = 0
    while x > 0 and i < N:
        if a[i] <= x:
            count += 1
            x -= a[i]
        else:
            break
        i += 1

    if i == N and x != 0:
        count = max(0, count - 1)

    print(count)


if __name__ == '__main__':
    main()


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

using namespace std;
typedef long long ll;
using Graph =vector<int>;
typedef pair<int,int> P;
int ans;
int main(){
  ll X,Y;cin>>X>>Y;
  while(X<=Y){
    ans+=1;
    X*=2;
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 256
macro_rules !input {(source =$s :expr ,$($r :tt ) *) =>{let mut iter =$s .split_whitespace () ;let mut next =||{iter .next () .unwrap () } ;input_inner !{next ,$($r ) *} } ;($($r :tt ) *) =>{let stdin =std ::io ::stdin () ;let mut bytes =std ::io ::Read ::bytes (std ::io ::BufReader ::new (stdin .lock () ) ) ;let mut next =move ||->String {bytes .by_ref () .map (|r |r .unwrap () as char ) .skip_while (|c |c .is_whitespace () ) .take_while (|c |!c .is_whitespace () ) .collect () } ;input_inner !{next ,$($r ) *} } ;}
macro_rules !input_inner {($next :expr ) =>{} ;($next :expr ,) =>{} ;($next :expr ,$var :ident :$t :tt $($r :tt ) *) =>{let $var =read_value !($next ,$t ) ;input_inner !{$next $($r ) *} } ;}
macro_rules !read_value {($next :expr ,($($t :tt ) ,*) ) =>{($(read_value !($next ,$t ) ) ,*) } ;($next :expr ,[$t :tt ;$len :expr ] ) =>{(0 ..$len ) .map (|_ |read_value !($next ,$t ) ) .collect ::<Vec <_ >>() } ;($next :expr ,chars ) =>{read_value !($next ,String ) .chars () .collect ::<Vec <char >>() } ;($next :expr ,usize1 ) =>{read_value !($next ,usize ) -1 } ;($next :expr ,$t :ty ) =>{$next () .parse ::<$t >() .expect ("Parse error" ) } ;}

fn main() {
   input! {
      _a: [usize; 3]
   }
   let mut a = _a;
   a.sort();
   let k1 = (a[2] - a[0])/2;
   let k2 = (a[2] - a[1])/2;
   let mut ans = 0;
   ans += k1 + k2;
   a[0] += k1*2;
   a[1] += k2*2;
   match 2*a[2] - a[0] - a[1] {
      1 => ans += 2,
      2 => ans += 1,
      _ => ()
   }
   println!("{}", ans);
} 


Measured memory_bytes: 4352
program eighty_one
  implicit none
  integer :: n, i
  read(*,*) n
  do i = 1, 9
    if (mod(n,i) == 0 .and. n/i < 10) goto 100
  end do
  write(*,'(a)') "No"
  stop
100 write(*,'(a)') "Yes"
end program eighty_one

Measured memory_bytes: 768
# -*- coding: utf-8 -*-
import sys
sys.setrecursionlimit(10**9)
INF=10**18
MOD=10**9+7
input=lambda: sys.stdin.readline().rstrip()
YesNo=lambda b: bool([print('Yes')] if b else print('No'))
YESNO=lambda b: bool([print('YES')] if b else print('NO'))
int1=lambda x:int(x)-1

def main():
    S=input()
    if S=='ABC':
        print('ARC')
    else:
        print('ABC')

if __name__ == '__main__':
    main()


Measured memory_bytes: 61716
#pragma GCC optimize("Ofast,unroll-loops")
#include<bits/stdc++.h>
#define ll long long
#define F first
#define S second
#define P pair
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define V vector
#define RE return
#define ALL(a) a.begin(),a.end()
#define MP make_pair
#define PB push_back
#define PF push_front
#define FILL(a,b) memset(a,b,sizeof(a))
using namespace std;
int dp[(1<<21)],s[25],p[(1<<21)],mod=1e9+7;
int main(){
	ios::sync_with_stdio(0);
    cin.tie(0);
	int n;
	cin>>n;
	int x;
	FOR(i,0,n-1){
		FOR(j,0,n-1){
			cin>>x;
			if(x)s[i]|=(1<<j);
		}
	}
	int m=(1<<n);
	FOR(i,1,m-1){
		p[i]=p[i&(i-1)]+1;
	}
	dp[0]=1;
	FOR(i,0,n-1){
		FOR(j,0,m-1){
			if(p[j]!=i)continue;
			int t=(j^(m-1))&s[i];
			while(t){
				int tp=(t&(t-1))^t;
				dp[j|tp]=(dp[j|tp]+dp[j])%mod;
				t=t&(t-1);
			}
		}
	}
	cout<<dp[m-1];
	RE 0;
}




Measured memory_bytes: 16640
#include <iostream>
#include <fstream>
#include <bits/stdc++.h>
#include <map>
#define pb push_back
#define ll long long
using namespace std;
int n;
int a[3][100010];
int mem[100010];
vector<int> v;
int main()
{
    int i,a,k,rez=0;
    cin>>n>>k;
    for(i=1;i<=n;i++)
    {
        cin>>a;
        v.push_back(a);
    }
    //memset(mem,-1,100010);
    mem[n - 1] = 0;
    for(i=n-2;i>=0;i--) {
        mem[i] =numeric_limits<int>::max();
        for(int j = 1; j <= k; j ++)
            if (i + j < n)
                mem[i] = min(mem[i], mem[i + j] + abs(v[i] - v[i + j]));
    }
    int n_rez=0;

    cout<<mem[0];
    return 0;
}


Measured memory_bytes: 1144
import math

a, b = [int(x) for x in input().split()]

flg = 0
v = 0

for i in range(10000):
    c = math.floor(i * 0.08)
    d = math.floor(i * 0.10)

    if c == a and d == b:
        v = i
        flg = 1
        break

if flg == 1:
    print(v)
else:
    print(-1)


Measured memory_bytes: 3060
#include<bits/stdc++.h>
#define ll long long
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define clr clear()
#define ins insert
#define tol(s) transform(s.begin(),s.end(),s.begin(),::tolower);
#define tou(s) transform(s.begin(),s.end(),s.begin(),::toupper);
#define rep(i,n) for(__typeof(n) i=0; i<(n); i++)
#define mem(x,val) memset((x),(val),sizeof(x));
#define cusmem(x,val) for(auto &i:x) i=val;
#define all(x) x.begin(),x.end()
#define fastio ios_base::sync_with_stdio(false);\
            cin.tie(NULL);\
            cout.tie(NULL);
using namespace std;
typedef pair<int,int> pii;
typedef pair<ll,ll>pll;
typedef vector<ll> vl;
typedef vector<pll> vpll;
typedef vector<int> vi;
typedef vector<bool> vb;
typedef vector<pii> vpii;
string imp="Impossible\n";

mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
clock_t startTime;
double getCurrentTime() {
    return (double)(clock() - startTime) / CLOCKS_PER_SEC;
}
// const int N=11;
const int N=5e6+5;
ll MOD=1e9+7;
ll n,m,k,i,j;
bool f0,f1,f2;
const int MAXN=2e3;

int main(){
    #ifndef ONLINE_JUDGE
            freopen("input.txt","r",stdin); 
            freopen("output.txt","w",stdout);
    #endif
    fastio
	cout<<fixed<<setprecision(11);
    int tests=1;    
    // cin>>tests;
    while(tests--){
		int l,r,d;
		cin>>l>>r>>d;
		cout<<(r/d)-(l-1)/d;

    }
    return 0;
}



 



Measured memory_bytes: 3648
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include<set>
#include<map>
using namespace std;


int main() {
    string a;
    cin >> a;
    if(a[0] == a[2]){
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }    
}


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

int main() {
  long long a, b, c;
  cin >> a >> b >> c;
  if (c - a - b <= 0 || (c - a - b) * (c - a - b) <= 4 * a * b)
    cout << "No" << endl;
  else
    cout << "Yes" << endl;
}


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

struct UnionFind{
    vector<int> par,num;
    vector<bool> done;
    UnionFind(int n):par(n),num(n,1),done(n,false){
        iota(par.begin(),par.end(),0);  //include<numeric>
    }
    int find(int v){
        return (par[v]==v)?v:(par[v]=find(par[v]));
    }
    void unite(int u,int v){
        u=find(u),v=find(v);
        if(u==v)return;
        if(num[u]<num[v])swap(u,v);
        num[u]+=num[v];
        par[v]=u;
        done[u]=done[u]|done[v];
    }
    bool same(int u,int v){
        return find(u) == find(v);
    }
    bool ispar(int v){
        return v=find(v);
    }
    int size(int v){
        return num[find(v)];
    }
};

int main(){
	int n,m; cin >> n >> m;
	UnionFind uf(n);
	for(int i=0;i<m;i++){
		int a,b; cin >> a >> b;
		a--; b--;
		uf.unite(a,b);
	}
	vector<bool> used(n,false);
	int cnt=0;
	for(int i=0;i<n;i++){
		if(!used[uf.find(i)]){
			cnt++;
			used[uf.find(i)]=true;
		}
	}
	cout << cnt-1 << endl;
}

Measured memory_bytes: 4056
//int a = stoi(c); 文字列をintへ
//小文字から大文字
//transform(a.begin(), a.end(), a.begin(), ::toupper);
//途中の出力をそのまま残さない
//数値計算 個数以外はdouble
//map<キー,値> p は辞書。p[キー] = 値
//map 全探索
//auto begin = p.begin(), end = p.end();
//for (auto it = begin; it != end; it++) {}
//mapのキー：it->first mapのバリュー：it->second
//絶対値 abs()
//入力は空白で切れる
//大文字判定 isupper(文字) 小文字判定 islower(文字)
//do{}while(next_permutation(ALL(配列)))
//while(N)で回すとき、Nはコピーを作っておく
//小文字に対応する文字コード：S[i] - 'a'
//文字コード→小文字：(char)(数字+'a')
//グラフの距離:隣接行列で扱う
//等価なものに変換する思考
//bool型　初期値はTrue
//島渡りの問題：中間ノードに着目
//配列はvector<>を使う：意味わからないエラーがなくなる。
//背反な事象にちゃんとわける
//チェックリストはマップを使う
//数が大きい時の比較はstring型で行う
//全て0になったか調べたい->0になるたびにcntする
//またはかかつか
//例外処理は最初にする
//x = p^m + q^n...の約数の個数:(n+1)*(m+1)....
//N!のどの素因数で何回割れるか
//⇔1~Nまでの数がそれぞれどの素因数で何回割り切れるかの和
//パズルの問題->一般化して全探索
//数が大きい時のせぐふぉはコードテストで試してみる
#include <bits/stdc++.h>
#define rep(i,N) for(int i = 0; i < N;i++)
#define ALL(a) (a).begin(),(a).end()
#define ll long long int
using namespace std;

//円周率
const double PI = 3.14159265358979323846;
//割るやつ
const ll M = (pow(10, 9) + 7);

// K進数でのNの桁数
ll dig(ll N, ll K) {
	ll dig = 0;
	while (N) {
		dig++;
		N /= K;
	}
	return dig;
}
// a,bの最大公約数
ll gcd(ll a, ll b) {
	if (b == 0) return a;
	return gcd(b, a%b);
}

ll lcm(ll a, ll b) {
	ll g = gcd(a, b);
	return a / g * b;
}

//nC2の計算
ll C(ll N) {
	return N * (N - 1) / 2;
}

//階乗計算
ll f(ll n) {
	if (n == 0 || n == 1) return 1;
	else return (n * f(n - 1)) % M;
}

//Nをdで何回割れるか
ll divcnt(ll N, ll d) {
	ll ans = 0;
	while (1) {
		if (N%d == 0) {
			ans++;
			N /= d;
		}
		else break;
	}

	return ans;
}

//素数判定
bool prime(ll num){
	if (num < 2) return false;
	else if (num == 2) return true;
	else if (num % 2 == 0) return false; 
	double sqrtNum = sqrt(num);
	for (int i = 3; i <= sqrtNum; i += 2){
		if (num % i == 0) return false;
	}
	return true;
}

//フィボナッチ数列
vector<ll> memo(pow(10, 6) + 1);
ll fibo(ll n) {
	if (n == 1) return 1;
	else if (n == 2) return 1;
	else if (memo[n] != 0) return memo[n];
	else return memo[n] = fibo(n-1) + f(n-2);
}

int main() {
	ll N; cin >> N;
	vector<ll> a(N + 1); for (int i = 1; i < N + 1;i++) cin >> a[i];

	ll ans = 0;
	for (int i = 1; i < N + 1;i++) {
		if (a[a[i]] == i) ans++;
	}

	cout << ans / 2 << endl;
}

Measured memory_bytes: 8832
//fifer a tak luboin
#include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>

#define ll long long
#define mp make_pair
#define pb push_back
#define s second
#define f first
#define endl "\n"

// using namespace __gnu_pbds;
using namespace std;
// template <typename T> using ordered_set =  tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; 

const ll inf = (ll)1e14;
const double eps = 1e-10;                                     
const double pi = acos(-1.0);

int main() {
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0); 
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    int n;
    cin >> n;
    string t;
    cin >> t;
    if (n % 2 != 0) {
        cout << "No" << endl;
        return 0;
    }

    int len = n / 2;
    string aa = t.substr(0, len);
    string aaa = t.substr(len, len);
    if (aa == aaa) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
    return 0; 
}

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

int main(){
  string S;
  cin >> S;
  int N = (int)S.length();
  int tot=0;
  for (int i=0; i<N/2; i++){
    if(S[i]!=S[N-1-i]) tot++;
  }
  cout << tot << endl;
  return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <iostream>
#include <bitset>
#include <deque>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
#include <iterator>
#include <string>
#include <chrono>
#include <random>
#include <tuple>
#include <utility>
#include <fstream>

long n, m;

std::vector<long> edge[100005];

std::vector<long> four;

int main(){
	scanf("%ld %ld", &n, &m);
	for(int i = 0; i < m; i++){
		long a, b;
		scanf("%ld %ld", &a, &b);
		edge[a].push_back(b);
		edge[b].push_back(a);
	}
	long six = 0;
	for(int i = 1; i <= n; i++){
		long cnt = edge[i].size();
		if(cnt % 2 == 1){
			printf("No\n");
			return 0;
		}
		if(cnt == 4){
			four.push_back(i);
		}else if(cnt >= 6){
			six++;
		}
	}
	//printf("(%ld %ld)\n", four.size(), six);
	if(four.size() >= 3 || six >= 1){
		printf("Yes\n");
	}else if(four.size() == 2){
		long cnt = 0;
		for(int i = 0; i < edge[four[0]].size(); i++){
			long vis = edge[four[0]][i];
			for(auto it = edge[vis].begin(); it != edge[vis].end(); it++){
				if(*it == four[0]){
					edge[vis].erase(it);
					break;
				}
			}
			while(1){
				if(vis == four[0]){
					break;
				}else if(vis == four[1]){
					cnt++;
					break;
				}
				long nx = edge[vis][0];
				for(auto it = edge[nx].begin(); it != edge[vis].end(); it++){
					if(*it == vis){
						edge[nx].erase(it);
						break;
					}
				}
				vis = nx;
			}
		}
		if(cnt == 4){
			printf("No\n");
		}else{
			printf("Yes\n");
		}
	}else{
		printf("No\n");
	}
	return 0;
}
		


Measured memory_bytes: 5760
#include <cmath>
#include <iomanip>
#include <iostream>
#include <vector>

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

  std::vector<double> x(n, 0), y(n, 0);
  for (int i = 0; i < n; i++) {
    std::cin >> x[i];
  }
  for (int i = 0; i < n; i++) {
    std::cin >> y[i];
  }

  int pn = 4;
  std::vector<double> p(pn, 0);
  double pinf;
  for (int i = 1; i < pn; i++) {
    for (int j = 0; j < n; j++) {
      int d = abs(x[j] - y[j]);
      p[i] += pow(d, i);
      if (j == 0) pinf = d;
      else if (d > pinf) pinf = d;
    }
    p[i] = pow(p[i], 1.0 / (double)i);
  }

  std::cout << std::fixed << p[1] << std::endl
            << p[2] << std::endl
            << p[3] << std::endl
            << pinf << std::endl;
}



Measured memory_bytes: 3464
K = int(input())
M = 1000

def a(i, j):
    tmp = (i - j) % (M//2) + 1
    if j % 2 == 0 or M + 1 - tmp > K:
        return tmp
    else:
        return M + 1 - tmp
    
if K <= M//2:
    print(K)
    for i in range(K):
        print(*([i+1]*K))
else:
    print(M//2)
    for j in range(M//2):
        print(*([a(i, j) for i in range(M//2)]))
        

Measured memory_bytes: 4508
#include<stdio.h>
#include<vector>
#include<algorithm>
using namespace std;
typedef long long ll;
typedef pair<int, int>pii;
ll mod;
ll dp[633][333];
int g1[333], g2[333];
vector<int>d1[333], d2[333];
ll kai[333];
int main()
{
	int num;
	scanf("%d%lld", &num, &mod);
	vector<pii>qs;
	for (int i = 0; i < num; i++)
	{
		int a, b;
		for (int j = 0; j <= num; j++)
		{
			if (i*i + j*j >= num*num)
			{
				a = j;
				break;
			}
		}
		for (int j = num + num - 1; j >= 0; j--)
		{
			if (i*i + j*j <= num*num * 4)
			{
				b = j + 1;
				break;
			}
		}
		qs.push_back(make_pair(a, -(b - num - num + i + 1)));
	}
	for (int i = num; i < num + num; i++)
	{
		for (int j = num + num - 1; j >= 0; j--)
		{
			if (i*i + j*j <= num*num * 4)
			{
				qs.push_back(make_pair(j + 1, 1));
				break;
			}
		}
	}
	sort(qs.begin(), qs.end());
	for (int i = 0; i < qs.size(); i++)qs[i].second = -qs[i].second;
	ll ret = 0;
	//for (int i = 0; i < qs.size(); i++)printf("%d %d\n", qs[i].first, qs[i].second);
	for (int p = 0; p <= num; p++)
	{
		for (int i = 0; i <= num + num; i++)for (int j = 0; j <= num; j++)dp[i][j] = 0;
		dp[0][0] = 1;
		int c1 = 0;
		for (int i = 0; i < qs.size(); i++)
		{
			if (qs[i].second == -1)
			{
				for (int k = 0; k <= min(num, qs[i].first - c1); k++)
				{
					dp[i + 1][k] = dp[i][k] * (qs[i].first - c1 - k) % mod;
				}
				c1++;
			}
			else
			{
				for (int k = 0; k <= min(p, qs[i].first - c1); k++)
				{
					dp[i + 1][k + 1] = (dp[i + 1][k + 1] + mod - dp[i][k] * (qs[i].first - c1 - k) % mod) % mod;
					dp[i + 1][k] = (dp[i + 1][k] + dp[i][k] * max(0, qs[i].second - p + k)) % mod;
				}
			}
			//for (int k = 0; k <= num; k++)printf("%lld ", dp[i + 1][k]); printf("\n");
		}
		ret = (ret + dp[num + num][p]) % mod;
	//	printf("%lld\n", dp[num + num][p]);
	}
	printf("%lld\n", ret);
}

Measured memory_bytes: 1536