akhauriyash/Code-Regression huggingface dataset:
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using static System.Math;
using MethodImplAttribute = System.Runtime.CompilerServices.MethodImplAttribute;
using MethodImplOptions = System.Runtime.CompilerServices.MethodImplOptions;
public static class P
{
    public static void Main()
    {
        //int n = 200000;
        //string s = string.Join("", Enumerable.Repeat('1', n));

        int n = int.Parse(Console.ReadLine());
        var s = Console.ReadLine();
        var popcnt = s.Count(x => x == '1');

        int remainwp1 = 0;
        int remainwm1 = 0;

        var remainswp1 = new int[n + 1];
        remainswp1[0] = 1;
        var remainswm1 = new int[n + 1];
        remainswm1[0] = popcnt <= 1 ? 0 : 1;
        for (int i = 1; i <= n; i++)
        {
            var dig =  s[n - i] - '0';
            remainswp1[i] = (remainswp1[i - 1] * 2) % (popcnt + 1);
            remainwp1 = (remainwp1 + (dig * remainswp1[i - 1])) % (popcnt + 1);
            if (popcnt > 1)
            {
                remainswm1[i] = (remainswm1[i - 1] * 2) % (popcnt - 1);
                remainwm1 = (remainwm1 + (dig * remainswm1[i - 1])) % (popcnt - 1);
            }
        }

        int[] table = new int[200000 + 5];

        for (int i = 1; i < table.Length; i++)
        {
            table[i] = table[i % PopCount(i)] + 1;
        }


        Console.SetOut(new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false });

        for (int i = 0; i < n; i++)
        {
            if (s[i] == '1')
            {
                if (popcnt <= 1)
                {
                    Console.WriteLine(0);
                    continue;
                }
                var remain = remainwm1 + (popcnt - 1) - remainswm1[n - i - 1];
                if (remain >= (popcnt - 1)) remain -= popcnt - 1;
                Console.WriteLine(table[remain] + 1);
            }
            else
            {
                var remain = remainwp1 + remainswp1[n - i - 1];
                if (remain >= (popcnt + 1)) remain -= popcnt + 1;
                Console.WriteLine(table[remain] + 1);
            }
        }
        Console.Out.Flush();
    }

    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    static int PopCount(int n)
    {
        n = n - ((n >> 1) & 0x55555555);
        n = (n & 0x33333333) + ((n >> 2) & 0x33333333);
        return (((n + (n >> 4) & 0xF0F0F0F) * 0x1010101) >> 24);
    }
}


Measured memory_bytes: 31040
#include <iostream>
#include <string>
#include <utility>
#include <algorithm>
#include <map>
#include <vector>
#include <cmath>
#include <cstdlib>
#include <queue>
#include <numeric>
#include <set>

using namespace std;

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define REPO(i, n) for(int i = 1;i <= n;i++)
#define ll long long
#define INF 999999999
#define MINF -999999999
#define ALL(n) n.begin(),n.end()

int main() {
	int n, h, w;
	cin >> n >> h >> w;
	cout << (n - h + 1) * (n - w + 1) << endl;
}



Measured memory_bytes: 256
#include <cstdio>

using namespace std;
int n,nr,i,j;
char s[54],t[54];
bool ok;
int main()
{
    n=0;
    nr=0;
    scanf ("%c", &s[n]);
    while (s[n]!='\n')
    {
        n++;
        scanf ("%c", &s[n]);
    }
    scanf ("%c", &t[nr]);
    while (t[nr]!='\n')
    {
        nr++;
        scanf ("%c", &t[nr]);
    }
    ok=false;
    for (i=(n-nr);i>=0;i--)
    {
        ok=true;
        for (j=i;j<=(i+nr-1);j++)
        {
            if (s[j]!='?' && s[j]!=t[j-i])
            {
                ok=false;
                break;
            }
        }
        if (ok==true)
            break;
    }
    if (ok==true)
    {
        for (j=i;j<=(i+nr-1);j++)
            s[j]=t[j-i];
        for (j=0;j<=(n-1);j++)
        {
            if (s[j]=='?')
                s[j]='a';
        }
        for (j=0;j<=(n-1);j++)
            printf ("%c", s[j]);
        printf ("\n");
    }
    else
        printf ("UNRESTORABLE\n");
    return 0;
}


Measured memory_bytes: 128
N,K = map(int,input().split())
h_list = []
for i in range(N):
    h_list.append(int(input()))
h_list.sort()
ans = 10**10
for i in range(N-K+1):
    ans = min(ans,h_list[i+K-1]-h_list[i])
print(ans)

Measured memory_bytes: 7384
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep2(i, m, n) for(int i=int(m); i<int(n); i++)
#define rep(i, n) rep2(i, 0, n)
#define ALL(a) a.begin(), a.end()
using ll = long long;
using ld = long double;
using V = vector<int>;
using Vll = vector<ll>;
using Vld = vector<ld>;
using VV = vector<V>;
using VVll = vector<Vll>;
using VVld = vector<Vld>;
using P = pair<int, int>;
using Pll = pair<ll, ll>;
using Pld = pair<ld, ld>;
const int INF = 1<<30;
const ll INFll = 1ll<<62;
const ld EPS = 1e-10;
const int MOD = int(1e9)+7;
template<typename T> inline bool chmin(T& a, T b) {if(a>b) {a=b; return true;} return false;}
template<typename T> inline bool chmax(T& a, T b) {if(a<b) {a=b; return true;} return false;}

template<typename T>
vector<int> compress(vector<T> &v) {
  vector<T> t = v;
  sort(t.begin(), t.end());
  t.erase(unique(t.begin(), t.end()), t.end());
	vector<int> r(v.size());
  for (int i = 0; i < v.size(); i++) {
    r[i] = lower_bound(t.begin(), t.end(), v[i]) - t.begin();
  }
	return r;
}

int main() {
  int n; cin >> n;
  V a(n);
  rep(i, n) cin >> a[i];
  V b = compress(a);

  multiset<int> S;
  S.insert(b[0]);

  rep2(i, 1, n) {
    auto it = S.lower_bound(b[i]);
    if (it == S.begin()) {
      S.insert(b[i]);
    }
    else {
      S.erase(--it);
      S.insert(b[i]);
    }
  }
  cout << S.size() << endl;
  return 0;
}


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

int main() {

	int h, w;
	cin >> h >> w;
	
	vector<vector<char>> a(h, vector<char>(w));
	for (int i = 0; i < h; i++) {
		for (int j = 0; j < w; j++) {
			cin >> a.at(i).at(j);
		}
	}

	for (int i = 0; i <a.size() ; i++) {
		bool hasBlack = false;
		for (int j = 0; j < w; j++) {
			if (a.at(i).at(j) == '#') {
				hasBlack = true;
				break;
			}
		}
		if (!hasBlack) {
			a.erase(a.begin() + i);
			i--;
		}
	}

	for (int j = 0; j < a.at(0).size(); j++) {
		bool hasBlack = false;
		for (int i = 0; i < a.size(); i++) {
			if (a.at(i).at(j) == '#') {
				hasBlack = true;
				break;
			}
		}
		if (!hasBlack) {
			for (int i = 0; i < a.size(); i++) {
				a.at(i).erase(a.at(i).begin() + j);
			}
			j--;
		}
	}


	for (int i = 0; i < a.size(); i++) {
		for (int j = 0; j < a.at(i).size(); j++) {
			cout << a.at(i).at(j);
		}
		cout << endl;
	}


}

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

// auto mod int
// https://youtu.be/L8grWxBlIZ4?t=9858
// https://youtu.be/ERZuLAxZffQ?t=4807 : optimize
// https://youtu.be/8uowVvQ_-Mo?t=1329 : division
const int mod = 1000000007;
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const {
    mint res(*this);
    return res+=a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res-=a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res*=a;
  }
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }
 
  // for prime mod
  mint inv() const {
    return pow(mod-2);
  }
  mint& operator/=(const mint a) {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const {
    mint res(*this);
    return res/=a;
  }
};
istream& operator>>(istream&i,mint&a){i>>a.x;return i;}
ostream& operator<<(ostream&o,const mint&a){o<<a.x;return o;}


// combination mod prime
// https://www.youtube.com/watch?v=8uowVvQ_-Mo&t=1619
struct combination {
  vector<mint> fact, ifact;
  combination(int n):fact(n+1),ifact(n+1) {
    assert(n < mod);
    fact[0] = 1;
    for (int i = 1; i <= n; ++i) fact[i] = fact[i-1]*i;
    ifact[n] = fact[n].inv();
    for (int i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i;
  }
  mint operator()(int n, int k) {
    if (k < 0 || k > n) return 0;
    return fact[n]*ifact[k]*ifact[n-k];
  }
};

int main() {
    int n, k;
    cin >> n >> k;
    vector<int> a(n);
    rep(i,n) cin >> a[i];
    sort(a.begin(),a.end());

    combination c(n+5);
    mint ans;
    rep(ri,2) {
        rep(i,n) {
            mint now = c(i,k-1);
            if (ri == 1) now *= -1;
            ans += now*a[i];
        }
        reverse(a.begin(),a.end());
    }
    cout << ans << endl;
    return 0;
}

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

int syc(long i,long Min,long Max){
	if(Min <= i && i <= Max){
		return 1;
	}else{
		exit(1);
		//return 0;
	}
}

int main(){
	int n;
	cin >> n;
	syc(n,1,20);
	int a[n];
	int count=0,check=0;

	for(int i=0;i<n;i++){
		cin >> a[i];
		syc(a[i],1,100);
	}
	for(int i=0;i<n;i++){
		for(int j=0;j<=i;j++){
			if(a[j]>a[i]){
				check++;
			}
		}
		if(check==0){
			count++;
		}
		check=0;
	}
	cout << count << endl;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <math.h>
#include <cmath>
#include <limits.h>
#include <map>
#include <unordered_map>
#include <set>
#include <queue>
#include <algorithm>
#include <functional>
#include <stdio.h>
using namespace std;

long long MOD = 1000000007;

int main() {
    
    long long N,P;
    cin >> N >> P;

    long long ans = 1;

    if ( N == 1 ) { cout << P << endl; return 0; }

    for ( long long a = 2; a <= 1000000; a++ ) {
        long long b = 1;
        bool f = true;
        for ( int i = 0; i < N; i++ ) {
            b *= a;
            if ( b > P ) { f = false; break; }
        }
        if ( f && ( P % b == 0 ) ) {
            ans = max( ans, a );
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
import java.util.Arrays;
import java.util.Objects;

public class Main{
    public static void main(String[] args){
        FastScanner sc = new FastScanner();

        int a, b;
        String op;
        while(true){
            a = sc.nextInt();
            op = sc.nextToken();
            b = sc.nextInt();

            if(op.equals("?"))break;
            else if(op.equals("+"))System.out.println(a+b);
            else if(op.equals("-"))System.out.println(a-b);
            else if(op.equals("*"))System.out.println(a*b);
            else if(op.equals("/"))System.out.println(a/b);
        }

    }

    public static class FastScanner {
        BufferedReader br;
        StringTokenizer st;

        public FastScanner(String s) {
            try {
                br = new BufferedReader(new FileReader(s));
            } catch (FileNotFoundException e) {
                e.printStackTrace();
            }
        }

        public FastScanner() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        String nextToken() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(nextToken());
        }

        long nextLong() {
            return Long.parseLong(nextToken());
        }

        double nextDouble() {
            return Double.parseDouble(nextToken());
        }
    }
}



Measured memory_bytes: 24504
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define FOR(i, m, n) for (ll i = m; i < n; i++)
#define IFOR(i, m, n) for (ll i = n - 1; i >= m; i--)
#define REP(i, n) FOR(i, 0, n)
#define IREP(i, n) IFOR(i, 0, n)
#define FOREACH(x, a) for (auto&(x) : (a))
#define ALL(v) (v).begin(), (v).end()
#define SZ(x) ll(x.size())

void yes() {
  cout << "Yes" << endl;
  exit(0);
}

void no() {
  cout << "No" << endl;
  exit(0);
}

int main() {
  ll h, w;
  cin >> h >> w;
  vector<string> s(h);
  REP(i, h) { cin >> s[i]; }

  vector<ll> d = {-1, 0, 1, 0};
  REP(i, h) REP(j, w) {
    if (s[i][j] == '.') {
      continue;
    }
    bool blacked = false;
    REP(k, 4) {
      ll x = i + d[k], y = j + d[k ^ 1];
      if (x < 0 || x >= h || y < 0 || y >= w) {
        continue;
      }
      if (s[x][y] == '#') {
        blacked = true;
      }
    }

    if (!blacked) {
      no();
    }
  }
  yes();
}

Measured memory_bytes: 256
from sys import stdin

n = int(stdin.readline().rstrip())
S = [int(x) for x in stdin.readline().rstrip().split()]
S.sort()
stdin.readline().rstrip()
T = [int(x) for x in stdin.readline().rstrip().split()]

def binSearch(S, val, l=0, r=n-1):
    while l < r:
        m = (l+r)//2
        if val < S[m]:
        	r = m-1
        elif val > S[m]:
        	l = m+1
        else:
        	l = r = m

    return ( l == r and S[l] == val)

C = 0
for ti in T:
    if binSearch(S, ti):
        C += 1

print(C)



Measured memory_bytes: 16896
#include<iostream>
#include<string>
using namespace std;
int main(){
	int n;
	cin>>n;
	string a,d[9];
	d[0]=".,!? ",d[1]="abc",d[2]="def",d[3]="ghi",d[4]="jkl";
	d[5]="mno",d[6]="pqrs",d[7]="tuv",d[8]="wxyz";
	for(int i=0;i<n;i++){
		cin>>a;
		int count=-1;
		for(int j=0;j<a.size();j++){
			if(j!=0){
			if(a[j]=='0'&&a[j-1]!='0'){
				cout<<d[a[j-1]-'1'][count];
			    count=-1;
			}
			}
			if(a[j]!='0')
			    count++;
			if(a[j]=='1')
				count%=5;
			else if(a[j]=='7'||a[j]=='9')
				count%=4;
			else
				count%=3;
		}
		cout<<endl;
	}
    return 0;
}

Measured memory_bytes: 1208
N = int(input())
p = list(map(int,input().split()))

ans = 0
for i in range(1,N+1):
    if i == p[i-1]:
        ans += 1

k = 0
for i in range(1,N):
    i += k
    if i >= N:
        break
    if i == p[i-1] and i+1 == p[i]:
        ans -= 1
        k += 1
print(ans)


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

typedef long long ll;

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

    int n;
    cin >> n;

    vector<ll> a(n + 1), b(n);

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

    ll ans = 0LL;

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

        if(b[i] > a[i]) {
            ans += a[i];
            b[i] -= a[i];

            ans += min(a[i + 1], b[i]);
            a[i + 1] = max(0LL, a[i + 1] - b[i]);
        }
        else ans += b[i];

    }

    cout << ans << endl;
}

/**
*/

Measured memory_bytes: 1792
#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <algorithm>
#include <cmath>

using namespace std;

typedef long long ll;

#define forn(i, n) for (int (i) = 0; (i) != (n); (i)++)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define popcount(x) __builtin_popcount(x)

#ifdef LOCAL
#define dbg(x) cerr << __LINE__ << " " << #x << " " << x << endl
#define ln cerr << __LINE__ << endl
#else
#define dbg(x) void(0)
#define ln void(0)
#endif // LOCAL

const ll N = 210;
const ll MOD = 1e9 + 7;
ll n, k;
ll a[N];
ll ans;

ll optimal(ll l, ll r)
{
    ll x = (l ^ r);
    ll y = 0;
    for (int i = 61; i >= 0; i--)
    {
        if ((1ll << i) & x)
        {
            y = 2 * y + 1;
            break;
        }
        if ((1ll << i) & l) y = 2 * y + 1;
        else y = 2 * y;
    }
    return min(popcount(l), popcount(y));
}

signed main()
{
    #ifdef ONLINE_JUDGE
        ios_base::sync_with_stdio(false);
        cin.tie(0);
        cout.tie(0);
    #endif // ONLINE_JUDGE
    cin >> n >> k;
    for (int i = 0; i < n; i++) cin >> a[i];
    map<vector<ll>, vector<pair<ll, ll> > > mm;
    for (int j = 0; j <= 60; j++)
    {
        vector<ll> limits(n + 2);
        ll c = (1LL << j);
        limits[0] = -1;
        for (int i = 0; i < n; i++)
        {
            limits[i + 1] = a[i] % c;
        }
        limits[n + 1] = c;
        sort(all(limits));
        limits.resize(unique(all(limits)) - limits.begin());
        for (int i = 0; i + 1 < limits.size(); i++)
        {
            vector<ll> sc(n);
            forn(ii, n) sc[ii] = a[ii] / c - (a[ii] % c <= limits[i]);
            ll opers = k - j - optimal(limits[i] + 1, limits[i + 1]);
            if (opers < 0) continue;
            ll val = (1ll << 61);
            forn(ii, n) val = min(val, sc[ii]);
            if (val < 0) continue;
            dbg(val);
            opers = min(opers, val);
            ll R = a[0] / c;
            ll L = a[0] / c - opers;
            forn(ii, n) sc[ii] -= val;
            mm[sc].push_back({L, R});
        }
    }
    for (auto e : mm)
    {
        //for (auto x : e.first) cout << x << " ";
        //cout << ": ";
        vector<pair<ll, ll> > v = e.second;
        sort(all(v));
        ll ma = - (1ll << 61);
        for (int i = 0; i < v.size(); i++)
        {
            v[i].first = max(v[i].first, ma);
            ans = (ans + max(0ll, v[i].second - v[i].first + 1)) % MOD;
            ma = max(ma, v[i].second + 1);
        }
        //for (auto x : e.second) cout << "[" << x.first << " " << x.second << "] ";
        //cout << "\n";
    }
    cout << ans;
}


Measured memory_bytes: 16512
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define all(c) c.begin(),c.end()
#define pb push_back
#define fs first
#define sc second
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
using namespace std;
template<class S,class T> ostream& operator<<(ostream& o,const pair<S,T> &p){
	return o<<"("<<p.fs<<","<<p.sc<<")";
}
template<class T> ostream& operator<<(ostream& o,const vector<T> &vc){
	o<<"{";
	for(const T& v:vc) o<<v<<",";
	o<<"}";
	return o;
}
using ll = long long;
template<class T> using V = vector<T>;
template<class T> using VV = vector<vector<T>>;
constexpr ll TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n-1); }

#ifdef LOCAL
#define show(x) cerr << "LINE" << __LINE__ << " : " << #x << " = " << (x) << endl
#define dump(x) cerr << "LINE" << __LINE__ << " : " << #x << " = {";  \
	for(auto v: x) cerr << v << ","; cerr << "}" << endl;
#else
#define show(x) true
#define dump(x) true
#endif

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);		//DON'T USE scanf/printf/puts !!
	cout << fixed << setprecision(20);
	
	int x; cin >> x;
	for(int i=x;;i++){
		bool ok = true;
		for(int j=2;j*j<=i;j++) if(i%j==0) ok = false;
		if(ok){
			cout << i << endl;
			return 0;
		}
	}
}


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

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

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

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

inline void read() {}

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

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

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

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

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

    VAR(int, N);
    vector<int> a(N);
    rep(i, 0, N) {
        read(a[i]);
        --a[i];
    }

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

    return 0;
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
#define MAXN	400005
#define MAXLOG	20
int n, k, v[MAXLOG], x[MAXN];
int l[MAXLOG][MAXN], r[MAXLOG][MAXN];
int lft[MAXN], rit[MAXN], opt[MAXN];
template <typename T> void read(T &x) {
	x = 0; int f = 1;
	char c = getchar();
	for (; !isdigit(c); c = getchar()) if (c == '-') f = -f;
	for (; isdigit(c); c = getchar()) x = x * 10 + c - '0';
	x *= f;
}
int main() {
	read(n), read(v[0]);
	for (int i = 1; i <= n; i++)
		read(x[i]);
	for (k = 1; v[k - 1] != 0; k++)
		v[k] = v[k - 1] / 2;
	k -= 1; int goal = (1 << k) - 1;
	for (int j = 0; j <= k; j++) {
		l[j][1] = 1;
		for (int i = 2; i <= n; i++)
			if (x[i] - x[i - 1] <= v[j]) l[j][i] = l[j][i - 1];
			else l[j][i] = i;
	}
	for (int j = 0; j <= k; j++) {
		r[j][n] = n;
		for (int i = n - 1; i >= 1; i--)
			if (x[i + 1] - x[i] <= v[j]) r[j][i] = r[j][i + 1];
			else r[j][i] = i;
	}
	for (int curr = 0; curr <= goal; curr++) {
		lft[curr] = 0;
		rit[curr] = n + 1;
	}
	for (int curr = 0; curr < goal; curr++)
	for (int i = 1, j = 1; i <= k; i++, j <<= 1) {
		if (curr & j) continue;
		int dest = curr | j;
		lft[dest] = max(lft[dest], min(r[i][lft[curr] + 1], n));
		rit[dest] = min(rit[dest], max(l[i][rit[curr] - 1], 1));
	}
	for (int i = 0; i <= n; i++)
		opt[i] = n + 2;
	for (int curr = 0; curr <= goal; curr++)
		opt[lft[curr]] = min(rit[goal ^ curr], opt[lft[curr]]);
	for (int i = n - 1; i >= 0; i--)
		opt[i] = min(opt[i], opt[i + 1]);
	for (int i = 1; i <= n; i++) {
		int lft = l[0][i];
		int rit = r[0][i];
		if (opt[lft - 1] <= rit + 1) printf("Possible\n");
		else printf("Impossible\n");
	}
	return 0;
}

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

int main() {
	int n, i, j;
	cin >> n;
	vector<pair<int, int> > V;
	for(i=0; i<n; i++){
		int a, b;
		cin >> a >> b;
		V.push_back({a, b});
	}
	vector<int> A;
	for(i=1; i<=n; i++)
		A.push_back(i);
	map<pair<int, int>, double> m;
	double sum = 0, cal;
	for(i=1; i<=n; i++){
		for(j=i+1; j<=n; j++){
			cal = sqrtl(pow(V[i-1].first - V[j-1].first, 2) + pow(V[i-1].second - V[j-1].second, 2));
			m[{i, j}] = cal;
			m[{j, i}] = cal;
		}
	}
	do{
		for(i=0; i<n-1; i++){
			sum += m[{A[i], A[i+1]}];
		}
	} while(next_permutation(A.begin(), A.end()));
	double div = 1;
	for(i=1; i<=n; i++)
		div *= i;
	double ans = sum/div;
	cout << fixed << setprecision(10) << ans;
	
	return 0;
}

Measured memory_bytes: 256
list = []
a,n,s = map(int, input().split())
ans = []
for i in range(1,10001):
    if i**n <= s:
        list.append(i**n)
for i in list:
    k = str(i)
    d = a
    for j in k:
        d += int(j)
    if d**n == i:
        ans.append(i)
print(len(ans))


Measured memory_bytes: 5600
#include<bits/stdc++.h>
using namespace std;
string st; 
int i=0;
int main()
{    
    getline(cin,st); 
    while(i<st.length())
      {
          if(st[i]!='0'&&st[i]!='1') 
          {
           if(i>0) st.erase(i-1,2),i--;
              else st.erase(i,1);
           }
        else i++;
      }
    cout<<st<<endl;
    return 0;
}


Measured memory_bytes: 256
S = input()

now = S[0]
c = 1
ans = 0

for s in S[1:]:
  if now == '':
    now = s
    c = 1
  else:
    if s == now:
      c += 1
    else:
      ans += 2
      c -= 1
      if c == 0:
        now = ''

print(ans)

Measured memory_bytes: 3188
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<string>
#include<stack>
#include<functional>
#include<queue>
#include<vector>
#include<algorithm>
#include<iomanip>
#include<utility>
#include<set>
#include<unordered_set>
#include<map>
#include<unordered_map>
typedef long long int ll;
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) for(int i=0;i<signed(n);i++)
#define EREP(i,n) for(int i=1;i<=signed(n);i++)
#define ALL(a) (a).begin(),(a).end()
using namespace std;
//#define EVEL 1
#ifdef EVEL
#define DEB(X) cout << #X <<":" <<X<<" " ;
#define TF(f) f ? cout<<"true  " : cout<<"false ";
#define END cout<<"\n";
#else
#define DEB(X) {}
#define TF(f) {}
#define END {}
#endif
const ll MOD = 1000000007;
const ll INF = 9e14;
typedef std::pair<ll,ll> P;
struct edge{ int to,cost; };
#define VMAX 100000

ll N,M,K,Q;
ll A,B,C,D,X;

ll ans;
bool F=false;
string S,T,U;
int main(){
    cin>>S>>T;
    cout<<(S==T.substr(0,S.size())?"Yes":"No")<<endl;
}


Measured memory_bytes: 3628
#include <algorithm>
#include <bitset>
#include <cassert>
#include <deque>
#include <fstream>
#include <iostream>
#include <map>
#include <math.h>
#include <memory>
#include <queue>
#include <sstream>
#include <stdio.h>
#include <string>
#include <vector>

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define POW(n) ((n) * (n))
#define ALL(a) (a).begin(), (a).end()
#define dump(v) (cerr << #v << ": " << v << endl)
#define cerr                                                                   \
  if (true)                                                                    \
  cerr

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<unsigned long long> vull;

// ll n = to_T<ll>("114514")
template <class T> T to_T(const string &s) {
  istringstream is(s);
  T res;
  is >> res;
  return res;
}
template <class T> string to_s(const T &a) {
  ostringstream os;
  os << a;
  return os.str();
}

struct UnionFind {
  vi root;
  vi sizes;

  UnionFind(int max) : root(max), sizes(max, 1) {
    REP(i, max) { root[i] = i; }
  }

  int find(int x) {
    if (x == root[x])
      return x;

    return root[x] = find(root[x]);
  }

  void unite(int x, int y) {
    x = find(x);
    y = find(y);

    if (x == y)
      return;

    if (sizes[x] < sizes[y])
      swap(x, y);
    if (y == 0) {
      swap(x, y);
    }

    root[y] = x;
    sizes[x] += sizes[y];

    sizes[y] = -1;
  }

  bool same(int x, int y) { return find(x) == find(y); }

  int size(int x) { return sizes[find(x)]; }

  void remove(int x) {

    // REP(i,root.size()) {
    //	if (i == 0)continue;
    //	if (root[i] == x)root[i] = 0;
    //}
    root[x] = x;
    sizes[0]--;
  }
};

vi L[200100];
ll nn;

bool dfs(int s, int d) {
  if (s == nn)
    return true;
  if (d == 2)
    return false;

  REP(i, L[s].size()) {
    if (dfs(L[s][i], d + 1))
      return true;
  }

  return false;
}

void solve(long long N, long long M, vector<long long> a, vector<long long> b) {
  // UnionFind uf(N + 1);
  // REP(i, M) { uf.unite(a[i], b[i]); }
  //
  // if (uf.same(1, N)) {
  //   cout << "POSSIBLE" << endl;
  // } else {
  //   cout << "IMPOSSIBLE" << endl;
  // }
  nn = N;
  REP(i, M) {
    L[a[i]].push_back(b[i]);
    L[b[i]].push_back(a[i]);
  }

  if (dfs(1, 0)) {
    cout << "POSSIBLE" << endl;
  } else {
    cout << "IMPOSSIBLE" << endl;
  }
}

int main() {
  ios::sync_with_stdio(false);
  long long M;
  long long N;
  cin >> N;
  cin >> M;
  vector<long long> a(M - 1 + 1);
  vector<long long> b(M - 1 + 1);
  for (int i = 0; i <= M - 1; i++) {
    cin >> a[i];
    cin >> b[i];
  }
  solve(N, M, a, b);
  return 0;
}


Measured memory_bytes: 18288
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repI(i, d, n) for (int i = (d); i < (n); ++i)
#define reps1(i, n) for (int i = 1; i < (n); ++i)
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

using ll = long long;
using P = pair<int, int>;
using Pl = pair<ll, ll>;
using M = map<int, int>;
using Ml = map<ll, ll>;
ll const INF = 1ll<<61;
double pi = 3.141592653589793238;

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

  cout << ll(sqrt(n)) * ll(sqrt(n)) << endl;

  return 0;
}


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

using namespace std;

#define endl '\n'
#define fi first
#define se second
#define MOD(n,k) ( ( ((n) % (k)) + (k) ) % (k))
#define forn(i,n) for (int i = 0; i < n; i++)
#define ALL(v) v.begin(), v.end()
#define find(v,x) (lower_bound(ALL(v), x) - v.begin())

typedef long long ll;
typedef long double ld;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<ii> vii;

const int MX = 200005;
int n, a[MX];
ll sum = 0;

ll sad (ll x) {
	ll res = 0;
	for (int i = 0; i < n; i++)
		res += abs(a[i]-x);
	return res;
}

int main () {
	ios_base::sync_with_stdio(0); cin.tie(0);
	
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		a[i] -= i;
	}
	sort(a, a+n);

	cout << min(sad(a[n/2]), sad(a[n/2-1])) << endl;

	return 0;
}


Measured memory_bytes: 1024
//#include <bits/stdc++.h>
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <queue>
#include <deque>
#include <set>
#include <stack>
#include <time.h>
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef pair<int, int> Pii;
typedef pair<int, ll> Pil;
typedef pair<ll, ll> Pll;
typedef pair<ll, int> Pli;

const ll nmax = 1e9 + 7;
const ll Mod = 998244353;
const double PI = 2 * asin(1);

ll Pow(ll A, ll N){
  if (N == 0) return 1;
  else{
    if (N % 2 == 0) return Pow(A * A % nmax, N / 2) % nmax;
    else return A * Pow(A * A % nmax, N / 2) % nmax;
  }
}

int main(){
  int X, Y; cin >> X >> Y;

  if ((X + Y) % 3 != 0){
    cout << 0 << endl;
    return 0;
  }

  ll A = Y - (X + Y) / 3, B = X - (X + Y) / 3;

  if (A < 0 || B < 0){
    cout << 0 << endl;
    return 0;
  }

  ll ans = 1, m = min(A, B);
  for (ll i = 1; i <= m; i++){
    ans *= A + B - i + 1; ans %= nmax;
    ans *= Pow(i, nmax - 2); ans %= nmax;
  }
  cout << ans << endl;


  return 0;
}


Measured memory_bytes: 256
/**akshaykumar99**/
 
#include<bits/stdc++.h>
using namespace std;
 
#define f(i,x,n) for(i=x;i<n;i++)
#define fr(i,x,n) for(i=x;i>=n;i--)
#define pu push_back           
#define pp pop_back
#define F first
#define S second
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define IOS() ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
 
const long long MOD=1e9+7;
const long double PI = acos(-1);
const long long INF=INT_MAX;
const long long LINF=LLONG_MAX;
const long long N=2e5+1;
 
typedef long long ll;
typedef long double ld;

int main()
{
    IOS();
 
    int n,i;
    cin>>n;
    string s;
    cin>>s;
    if(n&1)
        cout<<"No\n";
    else{
        f(i,0,n/2)
        {
            if(s[i]!=s[n/2+i])
            {
                cout<<"No\n";
                return 0;
            }


        }
        cout<<"Yes\n";
    }
}

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

int main() {
	string a, b, c; cin >> a >> b >> c;

	char diff = 'A' - 'a';
	printf("%c%c%c\n", a[0] + diff, b[0] + diff, c[0] + diff);

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <climits>
#include <algorithm>
using namespace std;

#define MAX 2000000
#define MIN INT_MIN

int H;
int A[MAX + 1] = {};

int parent(int i) {
    return i / 2;
}
int left(int i) {
    return 2 * i;
}
int right(int i) {
    return 2 * i + 1;
}

void maxHeapify(int i) {
    int l, r, largest;
    l = left(i);
    r = right(i);
    
    if(l <= H && A[l] > A[i]) largest = l;
    else largest = i;
    if(r <= H && A[r] > A[largest]) largest = r;
    
    if(largest != i) {
        int tmp = A[i];
        A[i] = A[largest];
        A[largest] = tmp;
        maxHeapify(largest);
    }
}

int extract() {
    int maxv;
    if(H < 1) return MIN;
    maxv = A[1];
    A[1] = A[H--];
    maxHeapify(1);
    return maxv;
}

void increaseKey(int i, int key) {
    if(key >= A[i]) {
        A[i] = key;
        while(i > 1 && A[parent(i)] < A[i]) {
            int tmp = A[i];
            A[i] = A[parent(i)];
            A[parent(i)] = tmp;
            i = parent(i);
        }
    }
}

void insert(int key) {
    ++H;
    A[H] = MIN;
    increaseKey(H, key);
}

int main(void) {
    int key;
    char com[10];
    
    while(cin >> com) {
        if(com[0] == 'e' && com[1] == 'n') break;
        if(com[0] == 'i') {
            cin >> key;
            insert(key);
        } else {
            cout << extract() << endl;
        }
    }
    
    return 0;
}


Measured memory_bytes: 6992
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <set>

using namespace std;


int n;
vector<int> a;


void solve() {
    cin >> n;
    a = vector<int>(n, 0);
    for (int i = 1; i < n; i++) {
        int temp;
        cin >> temp;
        a[i] = temp;
    }

    vector<int> num_of_sub(n, 0);
    for (int i = 1; i < n; i++) {
        num_of_sub[a[i]-1]++;
    }

    for (int i = 0; i < n; i++) {
        cout << num_of_sub[i] << endl;
    }
}


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


Measured memory_bytes: 4784
from collections import Counter
N = int(input())
S = [input() for _ in range(N)]
S = Counter(S)
Smax = max(S.values())
ans = []
for k, v in S.items():
    if Smax == v:
        ans.append(k)

ans = sorted(ans)

for i in ans:
    print(i)


Measured memory_bytes: 38612
#include "bits/stdc++.h"
#define _overload3(_1,_2,_3,name,...)name
#define _rep(i,n)repi(i,0,n)
#define repi(i,a,b)for(int i=int(a),i##_len=(b);i<i##_len;++i)
#define MSVC_UNKO(x)x
#define rep(...)MSVC_UNKO(_overload3(__VA_ARGS__,repi,_rep,_rep)(__VA_ARGS__))
#define all(c)c.begin(),c.end()
#define write(x)cout<<(x)<<'\n'
using namespace std; typedef long long ll; template<class T>using vv = vector<vector<T>>;
template<class T>auto vvec(int n, int m, T v) { return vv<T>(n, vector<T>(m, v)); }
template<class T, class U>bool chmax(T& a, U&& b) { return a < b ? a = b, 1 : 0; }
template<class T, class U>bool chmin(T& a, U&& b) { return b < a ? a = b, 1 : 0; }
constexpr int INF = 1 << 29, MOD = int(1e9) + 7; constexpr ll LINF = 1LL << 60;
struct aaa { aaa() { cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(10); }; }aaaa;
constexpr int dy[4] = { 0,1,0,-1 }; constexpr int dx[4] = { 1,0,-1,0 };

int main() {
    int N, K, Q;
    cin >> N >> K >> Q;
    vector<int> A(N);
    rep(i, N) cin >> A[i];

    vector<int> B, C;
    int ans = INT32_MAX;
    for (int m : A) {
        C.resize(0);

        for (int i = 0, j; i < N; ) {
            if (A[i] < m) {
                i++;
                continue;
            }
            for (j = i + 1; j < N; ++j) {
                if (A[j] < m) break;
            }
            if (j - i >= K) {
                B.resize(0);
                rep(k, i, j) B.push_back(A[k]);
                sort(all(B));
                rep(k, 0, j - i - K + 1) C.push_back(B[k]);
            }
            i = j;
        }

        if ((int)C.size() < Q) continue;
        sort(all(C));
        ans = min(ans, C[Q - 1] - C[0]);
    }

    write(ans);
}

Measured memory_bytes: 256
N, P = list(map(int, input().split()))
S = input()

#累積和を求めるため後ろから処理したい。配列は逆転しておく。
revS = S[::-1] 


# 10が素数であまり0、つまり2か5の場合
# 区間の下1けた目の数によって、どれだけ左側に伸ばして行っても
# 必ず割り切れる
if(10 % P == 0):
  res = 0

  for index, num in enumerate(revS):
    if(int(num) % P == 0) :
      res += len(revS) - index

  print(res)

else:

  #累積和を入れておく
  cs = 0

  ## あまりの値のカウント
  counts = [0] * P

  ## 累積和の初項は0になる
  ## 余りの値をindexにして配列 counts に同じ余りの値の個数を記録するので
  ## 初項の分は先に処理しておく
  counts[cs] += 1

  ## 桁
  d = 1

  ## 2項目からはfor文を使って同じ余りの値のカウントを行う処理する
  for num in revS:
    m = (int(num) * d) % P
    cs = (cs + m) % P

    counts[cs] += 1

    # 次の桁へ移動
    d *= 10

    # 桁が巨大になりすぎるのであまりを撮っておく
    # 掛け算の最中にあまりを撮るのは問題ない
    d %= P

  res = 0

  for n in counts:
    # 同じ余りの値がn個あったとして、重複なく2つ取り出す方法はnC2個
    res += n * (n - 1) // 2

  print(res)

Measured memory_bytes: 3500
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, s, e) for (int i = (int)(s); i <= (int)(e); i++)
#define printYesNo(is_ok) puts(is_ok ? "Yes" : "No");
#define SORT(v) sort(v.begin(), v.end());
#define RSORT(v) sort(v.rbegin(), v.rend());
#define REVERSE(v) reverse(v.begin(), v.end());

template <typename T>
void printlnVector(T v)
{
  rep(i, v.size())
  {
    cout << v[i] << endl;
  }
}

template <typename T>
void printVector(T v)
{
  rep(i, v.size())
  {
    cout << v[i] << " ";
  }
  cout << endl;
}

int main()
{
  string N;
  cin >> N;
  int ans = 0;
  rep(i, N.size())
  {
    if(N[i] == '2')
      ans++;
  }
  cout << ans << endl;
  return 0;
}

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

#define mainspring cout<<"mainspring\n";
#define barrel cout<<"barrel\n";
#define escapement cout<<"escapement\n";

#define pb push_back
#define eb emplace_back
#define all(v) (v).begin(), (v).end() 
#define sz(v) (int)((v).size())
#define INF INT_MAX
#define NINF INT_MIN
#define fs first
#define sd second
#define tik(i,a,b) for(int i = a; i < b; i++)
#define tok(i,a,b) for(int i = a; i >= b; i--)
#define error(args...) {string _s = #args; replace(_s.begin(), _s.end(), ',',' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it,args);}

typedef long long ll;
typedef unsigned long long ull;

typedef pair < int, int > pi;
typedef pair < pi, int > ppi;

typedef vector < int > vi;
typedef vector < vector < int > > vvi;
typedef vector < pi > vpi;
typedef vector < vpi > vvpi;
typedef vector < ppi > vppi;

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

void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
    cerr << *it << " = " << a << "\n";
    err(++it, args...);
}

const int MAX_N = 1e5+100, MOD = 1e9+7;

vvi adj(MAX_N);
int N;

pair<ll,ll> DFS(int u, int p) {

	ll f = 1, g = 1;
	for(auto v : adj[u]) {
		if(v == p)
			continue;
		pair<ll,ll> P = DFS(v,u);
		f *= ((P.fs+P.sd)%MOD);
		f %= MOD;
		g *= P.fs;
		g %= MOD;
	}

	pair<ll,ll> P = {f,g};

	return P;
}
int main() {

	fast();

	cin >> N;

	tik(i,0,N-1) {

		int x, y;
		cin >> x >> y;

		adj[x].pb(y);
		adj[y].pb(x);
	}

	pair<ll,ll> p = DFS(1,-1);

	cout << (p.fs + p.sd)%MOD << endl;
}

Measured memory_bytes: 12672
n = int(input())

count = 0

def dfs(s):
    # print(s)
    # 753数ですか？
    if int(s) > n:
        return
    if all(c in s for c in "753"):
        global count
        count += 1
    for c in "753":
        dfs(s+c)


dfs('0')

print(count)

Measured memory_bytes: 2940
import java.util.*;

class Main {
        public static void main(String args[]) {
                Scanner sc = new Scanner(System.in);
                while (true) {
                        int N = sc.nextInt();
                        if (N == 0) {
                                return;
                        }
                        int ans[] = new int[7];
                        for (int i = 0; i < N; i++) {
                                int age = Math.min(6,sc.nextInt() / 10);
                                ans[age]++;
                        }
                        for (int i = 0; i < 7; i++) {
                                System.out.println(ans[i]);
                        }
                }
        }
}

Measured memory_bytes: 181476
#include <iostream>
#include <algorithm>
using namespace std;
#define ll long long

ll d[100009], td[100009], v[100009];
int c[100009];

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
	int n, w; cin >> n >> w;
	for (int i = 0; i < n; i++)
		cin >> c[i] >> v[i];
	for (int i = 0; i <= w; i++)
		d[i] = -1;
	d[0] = 0;
	for (int i = 0; i < n; i++) {
		for (int j = 0; j <= w; j++) {
			if (j - c[i] >= 0 && d[j - c[i]] != -1)
				td[j] = max(d[j], d[j - c[i]] + v[i]);
			else
				td[j] = d[j];
		}
		for (int j = 0; j <= w; j++) {
			d[j] = td[j]; td[j] = -1;
		}
	}
	ll mx = 0;
	for (int i = 0; i <= w; i++)
		mx = max(mx, d[i]);
	cout << mx << '\n';
	return 0;
}

Measured memory_bytes: 1792
def solve(a):
    if a[0][0] != 0:
        return -1
    res = 0
    for aa in a:
        for i in range(len(aa)):
            if i == 0:
                res += aa[i]
            elif aa[i - 1] + 1 == aa[i]:
                res += 1
            elif aa[i - 1] == aa[i]:
                res += aa[i]
            else:
                return -1
    return res


def main():
    n = int(input())
    a = [[]]
    last_a = 0
    for _ in range(n):
        now = int(input())
        if last_a > now:
            a.append([])
        a[-1].append(now)
        last_a = now
    print(solve(a))


if __name__ == '__main__':
    main()


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

#include<random>  

#define int long long  

#define pp pair<int,int>  

#define ss second  

#define ff first  

#define pb push_back  

#define mod 1000000007  

using namespace std;  

void fastio()  

{    

  

  #ifndef ONLINE_JUDGE                  

  freopen("INPUT.txt","r",stdin);              

  freopen("OUTPUT.txt","w",stdout);              

  #endif    

     ios_base :: sync_with_stdio(false);   

     cin.tie(NULL) ;                             

      cout.tie(NULL);                              

   } 

   

signed main()  {    

        fastio();         

         int t=1;           

          // cin>>t;                

           while(t--)                  

              {                        

                 int n;

                 cin>>n;

                 double p,a;

                 if(n&1)  

                 a=(n+1)/2;

                 else

                 a=n/2;

                    p=a/n;

              

             

                   cout<<fixed<<setprecision(10);

                    cout<<p;  

                 }  

                      

                            

    } 

Measured memory_bytes: 3804
import qualified Data.Text as T
import qualified Data.Text.IO as T
import qualified Data.Text.Read as T
import Data.Bits (xor)

main :: IO ()
main = do
  n <- unsafeTextToInt <$> T.getLine :: IO Int
  as <- map unsafeTextToInt . T.words <$> T.getLine :: IO [Int]
  let
    s = foldl xor 0 as :: Int
  putStrLn . unwords . map (show . xor s) $ as

unsafeTextToInt :: T.Text -> Int
unsafeTextToInt s = case T.signed T.decimal s of
  Right (n, _) -> n
{-# INLINE unsafeTextToInt #-}


Measured memory_bytes: 21096
#include<string>
#include<string.h>
#include<map>
#include<set>
#include<vector>
#include<stdio.h>
#include<math.h>
#include<iostream>
#include<algorithm>
#include<queue>
using namespace std;
int main()
{
int a,b,sss;
cin>>a>>b;
for(int i=1;i<=100000;i=i*10)
if((i-b)>0)
{sss=i;
 break;}
for(int i=0;i<=100000;i++)
if(i*i==(a*sss)+b)
{cout<<"Yes";
 return 0;}
cout<<"No";
system("pause");
return 0;
}

Measured memory_bytes: 504
#include<bits/stdc++.h>
using namespace std;
#define ALL(obj) (obj).begin(), (obj).end()
#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
#define RFOR(i, a, b) for(int i = (a); i >= (b); i--)
#define REP(i, n) for(int i = 0; i < (n); ++i)
#define RREP(i, n) for(int i = n; i >= n; i--)

#define ABS(a) ((a < 0) ? ((-1)*(a)) : (a))

#define endl "\n"
#define pb push_back
#define rtn return
#define elif else if

#define MOD 1000000007
 
const int dx[]={1,0,-1,0}, dy[]={0,-1,0,1};

typedef long long ll;
typedef unsigned long long ull;

template <typename T>
inline T GCD(T a,T b){T c;while(b!=0){c=a%b;a=b;b=c;}return a;}
template <typename T>
inline T LCM(T a,T b){T c=GCD(a,b);a/=c;return a*b;}
template <typename T>
inline T nCr(T a,T b){T i,r=1;for(i=1;i<=b;i++){r*=(a+1-i);r/=i;}return r;}
template <typename T>
inline T nHr(T a,T b){return nCr(a+b-1,b);}
template <typename T>
inline T POW(T a,T b){int i,r=1;for(i=1;i<=b;i++){r*=a;}return r;}

/********************Template********************/

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

	int n, m;
	char a[50][50], b[50][50];
	cin >> n >> m;
	REP(i, n){
		REP(j, n) cin >> a[i][j];
	}
	REP(i, m){
		REP(j, m) cin >> b[i][j];
	}

	int p = n - m + 1;
	string ans = "No";
	REP(i, p){
		REP(j, p){
			bool yes = true;
			REP(k, m){
				REP(l, m){
					if(a[i+k][j+l] != b[k][l]) yes = false;
				}
			}
			if(yes) ans = "Yes";
		}
	}
	cout << ans << endl;
	rtn 0;
}

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


int main(){
	ll mod = 1000000000+7;
	ll n; cin>>n; ll arr[n];
	for(int i = 0; i < n; i++) cin>>arr[i];
	ll sup[n];
	for(int i = n-1; i >= 0; i--){
		if(i == n-1) sup[i] = arr[n-1];
		else sup[i] = ((sup[i+1]%mod)+(arr[i]%mod))%mod;
	}
	ll ans = 0;
	for(int i = 0; i < n-1; i++){
		ans += ((arr[i]%mod) * (sup[i+1]%mod))%mod; 
		ans %= mod;
	}
	cout<<ans%mod<<"\n";
}

Measured memory_bytes: 6732
#include "bits/stdc++.h"
#define ll long long
#define rep2(i,a,b) for(int i=a;i<=b;++i)
#define rep(i,n) for(int i=0;i<n;i++)
#define pii pair<int,int>
#define tii tuple<int,int,int>
#define pq priority_queue<int>
#define pqg priority_queue<int,vector<int>,greater<int>>
#define pb push_back
#define edge(v,a,b) v[a].pb(b);v[b].pb(a);
int MOD=1e9+7;
#define INF 2*1e9
#define N 310000 
using namespace std;
string alphabet("abcdefghijklmnopqrstuvwxyz");

int rnk[110000],ans,k;
vector<int> v[110000];
int p[110000];
int dfs(int a){
    int m=0;
    rep(i,v[a].size()){
        m=max(m,dfs(v[a][i]));
    }
    m++;
    if(m==k&&p[a]!=1){
        ans++; return 0;
    } 
    else{
        return m;
    }
}
main(){
    int n;
    ans=0;
    cin>>n>>k;
    int aaa;cin>>aaa;
    if(aaa!=1) ans++; 
    rep2(i,2,n){
        int a;
        cin>>a;
        v[a].pb(i);
        p[i]=a;
    }
    p[1]=1;
    dfs(1);
    cout<<ans;
    return 0;
}



Measured memory_bytes: 11008
<?php
list($n) = fscanf(STDIN, '%d');

$s = [];
for ($i = 0; $i < $n; $i++) {
    $input = trim(fgets(STDIN));
    if (isset($s[$input])) {
        $s[$input]++;
    } else {
        $s[$input] = 1;
    }
}

$max = array_keys($s, max($s));
sort($max);

echo implode("\n", $max);


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

int main()
{
	int N, K;
	
	long long ans;

	cin >> N >> K;

	ans = (long long)(N / K) * (N / K) * (N / K);

	if ( K % 2 == 0 ) {
		long long val = N / (K / 2);
		val = (val + 1) / 2;
		val = val * val * val;
		ans += val;
	}

	cout << ans << endl;

	return ( 0 );
}


Measured memory_bytes: 256