akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>

typedef long long LL;
using namespace std;
LL n, m;
int main() 
{
	while(~scanf("%lld%lld", &n, &m)) {

		if(n == 1 && m == 1) printf("1\n");
		else if(n == 1 || m == 1) printf("%lld\n", n * m - 2);
		else printf("%lld\n", (n - 2) * (m - 2));
	}
	return 0;
}


Measured memory_bytes: 128
//
//AtCoder Beginner Contest 145
//B - Echo
//

#include <iostream>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include <ctime>
#include <queue>
#include <map>
#include <functional>

using namespace std;

#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
#define ALL(x) (x).begin(),(x).end()
#define RALL(x) (x).rbegin(),(x).rend()

using ll = long long;
using ld = long double;

const double PI = 3.14159265358979323846;

ll gcd(ll x, ll y) { return (x % y)? gcd(y, x % y): y; }    //最大公約数
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }            //最小公倍数

int main()
{
    int n;
    string s;

    cin >> n >> s;

    if (n%2 == 1) cout << "No" << endl;
    else{
        string s1 = s.substr(0, n/2);
        string s2 = s.substr(n/2, n/2);

        if (s1 == s2) cout << "Yes" << endl;
        else cout << "No" << endl;
    }

    return 0;
}


Measured memory_bytes: 3624
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>
#include <queue>
#include <stack>

typedef std::uint64_t u64;
typedef std::int64_t  i64;
typedef std::uint32_t u32;
typedef std::int32_t  i32;

using namespace std;

#define swap(a, b)    do { typeof(a) __tmp = (a); (a) = (b); (b) = __tmp; } while(0)
#define repd(i, a, b) for(typeof(b) i = a; i < (b); ++i)
#define rep(i, n)     repd(i, 0, n)
#define dump(x)       cerr << #x << " = " << (x) << endl
#define debug(x)      cerr << "L" << __LINE__ << ": " << #x << " = " << (x) << endl

int main(int argc, const char* argv[]) {
	u64 n;
	string s;

	cin >> n >> s;

	u64 w[n+1] = {0};
	u64 b[n+1] = {0};

	w[0] = 0;
	b[0] = 0;

	rep(i, n) {
		if(s[i] == '.') {
			w[i+1] = w[i] + 1;
		} else {
			w[i+1] = w[i];
		}
	}

	if(w[n] == n || w[n] == 0) {
		cout << 0 << endl;
		return 0;
	}

	u64 ret = 0xFFFFFFFFFFFFFFFF;
	repd(i, 0, n+1) {
		u64 tmp = i - w[i] + (w[n] - w[i]);
		if(tmp < ret) ret = tmp;
	}

	cout << ret << endl;
	return 0;
}


Measured memory_bytes: 3716
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "iomanip"
#include "random"

using namespace std;

const long long int MOD = 1000000007;
const long double EPS = 0.00000001;
const long double PI = 3.1415926535897932384626433;

long long int N, M, K, H, W, L, R;



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

	cin >> N >> K;
	vector<bool>flag(32, false);
	M = K;
	for (int i = 0; i < 32; i++) {
		if (M % 2) {
			flag[i] = true;
			R = i;
		}
		M /= 2;
	}
	vector<long long int>num(N);
	vector<long long int>value(N);
	vector<vector<bool>>bit(N, vector < bool>(32, false));
	for (int i = 0; i < N; i++) {
		cin >> num[i] >> value[i];
		long long int box = num[i];
		for (int j = 0; j < 32; j++) {
			if (box % 2) {
				bit[i][j] = true;
			}
			box /= 2;
		}
	}
	long long int ans = 0;
	for (int i = 0; i <= R; i++) {
		if (!flag[i]) {
			continue;
		}
		long long int bag = 0;
		for (int j = 0; j < N; j++) {
			bool can = true;
			for (int k = 31; k > i; k--) {
				if(bit[j][k]&&!flag[k]){
					can = false;
					break;
				}
			}
			if (bit[j][i]) {
				can = false;
			}
			if (can) {
				bag += value[j];
			}
		}
		ans = max(ans, bag);
	}
	long long int bag = 0;
	for (int i = 0; i < N; i++) {
		bool can = true;
		for (int j = 0; j < 32; j++) {
			if (bit[i][j] && !flag[j]) {
				can = false;
			}
		}
		if (can) {
			bag += value[i];
		}
	}
	cout << max(ans, bag) << endl;
	return 0;
}


Measured memory_bytes: 8832
#include<bits/stdc++.h>
#define REP(x,y,z) for(int x=y;x<=z;x++)
#define MSET(x,y) memset(x,y,sizeof(x))
#define M 
using namespace std;
using LL = long long;
int n,c1[64],c0[64],kb[64];
LL K,dp[64][2][2]; //#, last, onaji
int main()
{
    while (~scanf("%d %lld", &n, &K)) {
        MSET(c0, 0);
        MSET(c1, 0);
        REP(i,1,n) {
            LL x;
            scanf("%lld", &x);
            REP(j,0,60) {
                if((1LL<<j) & x) c1[j]++;
                else c0[j]++;
            }
        }
        REP(i,0,60) kb[i] = ((1LL<<i) & K) ? 1 : 0;

        MSET(dp, -1);
        dp[61][0][1] = 0;
        for (int i=61; i>=1; i--) REP(j,0,1) REP(k,0,1) if (dp[i][j][k]>=0) REP(j2,0,1) {
            if (k==1 && j2>kb[i-1]) continue;
            int k2 = (k==1) && (j2==kb[i-1]) ? 1 : 0;
            
            LL add = 0;
            if (j2==1) add += (1LL<<(i-1)) * c0[i-1];
            else       add += (1LL<<(i-1)) * c1[i-1];
            dp[i-1][j2][k2] = max(dp[i-1][j2][k2], dp[i][j][k] + add);
        }

        LL ans = 0;
        REP(i,0,1)REP(j,0,1) ans = max(ans, dp[0][i][j]);
        printf("%lld\n", ans);
    }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//#include <boost/multiprecision/cpp_ll.hpp>
//typedef boost::multiprecision::cpp_ll ll;
typedef long double dd;
#define i_7 (ll)(1E9+7)
//#define i_7 998244353
#define i_5 i_7-2
ll mod(ll a){
    ll c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
typedef pair<ll,ll> l_l;
ll inf=(ll)1E16;
#define rep(i,l,r) for(ll i=l;i<=r;i++)
#define pb push_back
ll max(ll a,ll b){if(a<b)return b;else return a;}
ll min(ll a,ll b){if(a>b)return b;else return a;}
void Max(ll &pos,ll val){pos=max(pos,val);}//Max(dp[n],dp[n-1]);
void Min(ll &pos,ll val){pos=min(pos,val);}
void Add(ll &pos,ll val){pos=mod(pos+val);}
dd EPS=1E-9;
string alp="abcdefghijklmnopqrstuvwxyz";
#define endl "\n"
#define fastio ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);

ll hoge(ll i){
    if(i==0)return 0;
    if(i%2==0)return hoge(i/2)+1;
    return 0;
}

int main(){
    ll memo[1000100];
    memo[0]=0;
    rep(i,1,1000010){
        memo[i]=memo[i-1]+hoge(i);
    }
    ll n;cin>>n;
    string s;cin>>s;
    if(n==2){
        ll ans=abs((s[0]-'0')-(s[1]-'0'));
        cout<<ans<<endl;
        return 0;
    }else{
        ll a[n];rep(i,0,n-1)a[i]=s[i]-'1';
        bool b=true;
        rep(i,0,n-1){
            if(a[i]==1){
                b=false;
                break;
            }
        }
        if(b){
            ll aa[n];rep(i,0,n-1)aa[i]=a[i]/2;
            ll sum=0;
            rep(i,0,n-1){
                //cout<<memo[n-1]-memo[i]-memo[n-1-i]<<' '<<aa[i]%2<<endl;
                if(memo[n-1]-memo[i]-memo[n-1-i]==0){
                    sum+=(aa[i]%2);
                }
            }
            if(sum%2==0){
                cout<<0<<endl;
            }else{
                cout<<2<<endl;
            }
            return 0;
        }
        ll sum=0;
        rep(i,0,n-1){
            //cout<<memo[n-1]-memo[i]-memo[n-1-i]<<' '<<a[i]%2<<endl;
            if(memo[n-1]-memo[i]-memo[n-1-i]==0){
                sum+=(a[i]%2);
            }
        }
        cout<<sum%2<<endl;
    }
    
    
    return 0;
}






Measured memory_bytes: 24836
#include <iostream>

int main()
{
    int k, a, b;
    std::cin >> k >> a >> b;

    for (int i = a; i <= b; ++i)
    {
        if (i % k == 0)
        {
            std::cout << "OK";
            return 0;
        }
    }

    std::cout << "NG";
}


Measured memory_bytes: 3608
#include <cstdio>
#include <bitset>
#include <algorithm>
using namespace std;
bitset<4001000> dp;
int a[2010];
int main() {
	int n, s = 0;
	scanf("%d", &n);
	for (int i = 0; i < n; i++) {
		scanf("%d", &a[i]);
		s += a[i];
	}
	sort(a, a + n);
	dp[0] = 1;
	for (int i = 0; i < n; i++) {
		dp |= (dp<<a[i]);
	}
	int c = dp.count() - 1;
	int x = (c + 1) / 2;
	c = 0;
	for (int i = 1; i <= s; i++) {
		c += dp[i];
		if (c == x) {
			printf("%d\n", i);
			return 0;
		}
	}
	return 0;
}


Measured memory_bytes: 1664
#include <bits/stdc++.h>
#define PB push_back
#define MP make_pair
#define REP(i,n) for (int i=0;i<(n);i++)
#define INF (1<<29)
using namespace std;
typedef long long ll;
int main(){
      int n;
      cin>>n;
      if(n==1){
            cout<<1<<endl;
            return 0;
      }else if(n==2){
            cout<<2<<endl;
            return 0;
      }
      for(int i=3;i<10000;i++){
            int cnt=0;
            for(int j=1;j*j<=i;j++){
                  if(i%j==0){
                        if(j*j==i)cnt++;
                        else cnt+=2;
                  }
            }
            if(cnt==n){
                  cout<<i<<endl;
                  return 0;
            }
      }
}

Measured memory_bytes: 1160
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String line = sc.nextLine();
        int[] i = Arrays.stream(line.split(" ")).mapToInt(Integer::parseInt)
                                                .sorted()
                                                .toArray();
        System.out.println(i[0] + " " + i[1]+ " "  + i[2]);
    }
}


Measured memory_bytes: 31728
s[2],a[20];main(i,j,n,N,m){for(;scanf("%d",&n),n;printf("%d\n",m)){for(i=0;i<n;i++)scanf("%d",a+i);for(i=0,m=999999,N=1<<n;i<N;j=abs(*s-s[1]),m=m<j?m:j,i++)for(*s=s[1]=j=0;j<n;j++)s[(i>>j)&1]+=a[j];}exit(0);}

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

int main() {
	ios_base::sync_with_stdio( false );

	string S;
	cin >> S;

	int m = 10 * (S[5] - '0') + (S[6] - '0');
	int d = 10 * (S[8] - '0') + (S[9] - '0');

	if( m < 4 || (m == 4 && d <= 30) ) {
		cout << "Heisei\n";
	}
	else {
		cout << "TBD\n";
	}

	return 0;
}


Measured memory_bytes: 256
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <bitset>    // bitset
#include <deque>     // deque
#include <iomanip>   //setprecsion
#include <iostream>  // cout, endl, cin
#include <map>       // map
#include <queue>     // queue, priority_queue
#include <set>       // set
#include <stack>     // stack
#include <string>    // string, to_string, stoi
#include <tuple>     // tuple, make_tuple
#include <utility>   // pair, make_pair
#include <vector>    // vector

#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <cmath>  //sin, cos, tan

using namespace std;

#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define rrep(i, n) for (ll i = (n - 1); i >= 0; --i)
#define blank(ans) cout << (ans) << " ";
#define mp(p, q) make_pair(p, q)
#define mt(p, q, r) make_tuple(p, q, r)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef string str;

typedef vector<ll> vll;
typedef vector<ld> vd;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<str> vs;
typedef vector<vector<ll>> vvll;
typedef vector<vector<ld>> vvd;
typedef vector<vector<bool>> vvb;
typedef vector<vector<char>> vvc;
typedef vector<vector<str>> vvs;
typedef vector<pair<ll, ll>> vpll;
typedef vector<tuple<ll, ll, ll>> vtlll;

const ld PI = acos(-1.0);
const ll MAX = 9000000000000000000;
const ll MIN = -9000000000000000000;
const ld DMAX = 4500;
const ld DMIN = -4500;
const ll MOD = 1000000007;

template <typename T>
void fin(T a)
{
  cout << a << endl;
  exit(0);
}

ll GetDigit(ll num)
{
  return log10(num) + 1;
}

//n ~ mの和
ll sigma(ll n, ll m)
{
  return ((n + m) * (m - n + 1) * 0.5);
}

void Main()
{
  ll n; cin >> n;
  vll a(n); rep(i, n) cin >> a[i];
  map <ll, ll> m;
  ll ans = 0;
  for(ll i = 0;i < n;i++)
  {
    if(m.count(i - a[i])) ans += m[i - a[i]];
    m[i + a[i]]++;
  }
  fin(ans);
}

//前処理
int main()
{
  //ios::sync_with_stdio(false);
  //cin.tie(0);
  cout << fixed << setprecision(20); //高精度少数表示
  //cout << setfill('0') << internal << setw(4); 0埋め４桁
  Main();
  return 0;
}


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

using namespace std;

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

#define INF 1<<30
#define F first
#define S second
#define MOD 1000000007

int main(){
  int n;
  int cnt=0,now=0,ans=0;
  int a[200005];
  scanf("%d",&n);
  for(int i=0;i<n;i++){
    scanf("%d",&a[i]);
  }

  for(int i=0;i<n;i++){
    if(now<a[i]){
      cnt=0;
    }else{
      cnt++;
    }
    now=a[i];
    ans=max(cnt,ans);
  }

  printf("%d\n",ans);
  return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define rep2(i, s, n) for (ll i = s; i < (ll)(n); i++)
#define repr(i, n) for (ll i = n; i >= 0; i--)
#define pb push_back
#define COUT(x) cout << (x) << endl
#define COUTF(x) cout << setprecision(15) << (x) << endl
#define ENDL cout << endl
#define DF(x) x.erase(x.begin())  // 先頭文字削除
#define ALL(x) x.begin(), x.end()
#define SORT(x) sort(ALL(x))
#define REVERSE(x) reverse(ALL(x))
#ifdef _DEBUG
#define debug(x) cout << "[debug] " << #x << ": " << x << endl
#else
#define debug(x)
#endif
using namespace std;
using ll = long long;
using ld = long double;
using vll = vector<ll>;
using P = pair<ll, ll>;
constexpr ll INF = 0x3f3f3f3f3f3f3f3f;
constexpr double PI = 3.141592653589793238462643383279;
ll getDigit(ll x) {
  return x == 0 ? 1 : log10(x) + 1;
}

ll gcd(ll x, ll y) {
  return y ? gcd(y, x % y) : x;
}

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

vector<P> factorize(ll n) {
  vector<P> result;
  for (ll i = 2; i * i <= n; ++i) {
    if (n % i == 0) {
      result.pb({i, 0});
      while (n % i == 0) {
        n /= i;
        result.back().second++;
      }
    }
  }
  if (n != 1) {
    result.pb({n, 1});
  }
  return result;
}

template <class T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}

template <typename T>
void debugV(const vector<T> v) {
#ifdef _DEBUG
  rep(i, v.size()) {
    cout << i << ":" << v[i] << " ";
  }
  cout << endl;
#else
  (void)v;
#endif
}

signed main() {
  ll A, B, C;
  cin >> A >> B >> C;
  ll ans = B / A;
  if (ans > C) {
    ans = C;
  }
  COUT(ans);
  return 0;
}

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

int main(void){
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int a, b;
    cin>>a>>b;
    if(a>8 || b>8){
    	cout<<":(\n";
	}else{
		cout<<"Yay!\n";
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define pb push_back
typedef long long ll;
const int INF = 1000000000;
const long INF64 = 1000000000000000ll;
const ll MOD = 1000000007ll;


int main(){
	int w,a,b;
	std::cin >> w>>a>>b;
	std::cout << max({0,b-a-w,a-b-w}) << std::endl;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
  int N;
  cin>>N;
  int t[110000],x[110000],y[110000];
  for(int i=0;i<N;i++)cin>>t[i+1]>>x[i+1]>>y[i+1];
  bool can=true;
  for(int i=0;i<N;i++){
    int dt=t[i+1]-t[i];
    int dist=abs(x[i+1]-x[i])+abs(y[i+1]-y[i]);
    if(dt<dist)can=false;
    if(dist%2!=dt%2)can=false;
  }
  if(can)cout<<"Yes"<<endl;
  else cout <<"No"<<endl;
}

Measured memory_bytes: 1408
package main

import "fmt"

func main() {
	var n, k int
	var s string
	fmt.Scan(&n, &k, &s)
	tr := make([]int, 0, 100000)
	tv := 0
	sv := 0
	for _, v := range s {
		if v == '0' {
			tv++
			if sv != 0 {
				tr = append(tr, -sv)
				sv = 0
			}
		} else {
			sv++
			if tv != 0 {
				tr = append(tr, tv)
				tv = 0
			}
		}
	}
	if tv != 0 {
		tr = append(tr, tv)
	}
	if sv != 0 {
		tr = append(tr, -sv)
	}
	ans := 0
	sumAns := 0
	u := 0
	mi := -1
	for i, v := range tr {
		if v > 0 {
			if u < k {
				if mi == -1 {
					mi = i
				}
				u++
			} else {
				ans -= tr[mi]
				if mi-1 >= 0 {
					ans += tr[mi-1]
				}
				mi += 2
			}
			ans += v
		} else {
			ans -= v
		}
		if sumAns < ans {
			sumAns = ans
		}
	}
	fmt.Println(sumAns)
}


Measured memory_bytes: 2048
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 = int.Parse(Console.ReadLine());
        Console.WriteLine(Primes(200000).First(x => n <= x));
    }
    public static IEnumerable<int> Primes(int n)
    {
        if (n <= 32)
        {
            int[] primes = { 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31 };
            for (int i = 0; i < primes.Length; i++)
            {
                if (n < primes[i]) break;
                else yield return primes[i];
            }
            yield break;
        }

        yield return 2;
        int sup = (n + 1) / 32 / 2 + 1;
        uint[] isp = new uint[sup];

        int[] tprimes = { 3, 5, 7, 11, 13, 17, 19, 23, 29, 31 };
        for (int i = 0; i < tprimes.Length; i++)
        {
            var tp = tprimes[i];
            yield return tp;
            uint[] ptn = new uint[tp];
            for (int j = (tp - 3) / 2; j < (tp << 5); j += tp) ptn[j >> 5] |= 1U << (j & 31);
            for (int j = 0; j < tp; j++) for (int l = j; l < sup; l += tp) isp[l] |= ptn[j];
        }

        int[] magic = { 0, 1, 23, 2, 29, 24, 19, 3, 30, 27, 25, 11, 20, 8, 4, 13, 31, 22, 28, 18, 26, 10, 7, 12, 21, 17, 9, 6, 16, 5, 15, 14 };
        int h = n / 2;
        for (int i = 0; i < sup; i++)
        {
            for (uint j = ~isp[i]; j != 0; j &= j - 1)
            {
                int pp = i << 5 | magic[((uint)(j & -j) * 124511785) >> 27];
                int p = 2 * pp + 3;
                if (p > n) break;
                yield return p;
                for (int q = pp; q <= h; q += p) isp[q >> 5] |= 1U << (q & 31);
            }
        }
    }
}


Measured memory_bytes: 13372
#include <bits/stdc++.h>
using namespace std;
using int64 = long long;
#define int int64
#define rep(i, n) for(int i=0; i<n; i++)
#define FOR(i, a, b) for(int i=a; i<b; i++)
#define SORT(x) sort(x.begin(), x.end())
#define GSORT(x) sort(x.begin(), x.end(), greater<int>())
#define mk make_pair
#define fi first
#define se second
#define pb push_back
#define ALL(x) x.begin(), x.end()
#define V(T) vector<T>
typedef pair<int, int> P;
typedef pair<P, P> PP;
typedef vector<int> vi;
typedef vector<vi> vvi;
int max(int a, int b) {if(b>a) return b; else return a;}
int min(int a, int b) {if(b<a) return b; else return a;}


signed main() {
    int N;
    cin >> N;
    vi C(N-1), S(N-1), F(N-1);
    rep(i, N-1) cin >> C[i] >> S[i] >> F[i];

    vi res(N, 0);
    for(int i=0; i<N-1; i++) {
        int temp = S[i]+C[i];
        for(int j=i+1; j<N-1; j++) {
            if(temp <= S[j]) temp = S[j]+C[j];
            else {
                int f = (temp - S[j])/F[j];
                if((temp-S[j])%F[j]) f++;
                temp =S[j] + F[j]*f + C[j];
            }
        }
        res[i] = temp;      
    }

    rep(i, N) cout << res[i] << endl;
    
    return 0;
}

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

int main() {
  int n;
  cin>>n;
  P a[100005];
  for (int i=0; i<n; i++) {
    a[i].second=i+1;
    cin>>a[i].first;
  }
  sort(a,a+n);
  for (int i=0; i<n; i++) {
    cout<<a[i].second<<' ';
  }
  cout<<endl;
  return 0;
}

Measured memory_bytes: 1536
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
#define rep(i,a,n) for(int i=a;i<n;++i)
#define per(i,a,n) for(int i=n-1;i>=a;--i)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define sz(x) ((int)x.size())
#define all(x) begin(x), end(x)
#define rall(x) rbegin(x), rend(x)
const ll linf=1e18;
const int inf=1001001001;
const ll mod=998244353;
template<typename T> using ordered_set=tree<T,null_type,less<T>,
rb_tree_tag,tree_order_statistics_node_update>;
ll mul(ll a,ll b) {
	return a*b%mod;
}
ll add(ll a,ll b) {
	ll res=a+b;
	if(res>=mod) res-=mod;
	return res;
}
ll sub(ll a,ll b) {
	ll res=(a-b+mod);
	if(res>=mod) res-=mod;
	return res;
}
ll po(ll a,int b) {
	if(b==0) return 1LL;
	if(b%2==1) return mul(a,po(a,b-1));
	ll u=po(a,b/2);
	return mul(u,u);
}
ll inv(ll n) {
	return po(n,mod-2);
}
const int N=2e6;
vl fac(N);
vl invfac(N);
void init() {
	fac[0]=1LL;
	rep(i,1,N) fac[i]=mul(fac[i-1],(ll)i);
	invfac[N-1]=inv(fac[N-1]);
	per(i,0,N-1) invfac[i]=mul(invfac[i+1],(ll)i+1LL);
}
// head

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	init();
	int n,m,k;
	cin>>n>>m>>k;
	int bot=max(0,n-m);	
	ll count=0;
	//cout<<bot<<'\n';
	rep(i,0,k+1) {
		ll first=mul(m,po(m-1,n-i-1));
		ll sec=mul(mul(fac[n-1],invfac[i]),invfac[n-i-1]);
		//cout<<i<<' '<<first<<' '<<sec<<'\n';
		count=add(count,mul(first,sec));
	}
	cout<<count<<'\n';
	return 0;
}

Measured memory_bytes: 34584
import numpy as np
N, K = map(int, input().split())
R, S, P = map(int, input().split())
T = input()

dic = {"r":P, "s":R, "p":S}#key:筐体が出した手、val:それに勝ったら貰える点
points = 0

for st in range(K):
    series = T[st::K]
    prev = "x"
    for now in series:
        if now != prev:
            points += dic[now]
            prev = now
        else:
            prev = "x"
            
print(points)

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

LEN=2*10**5+10
moves=[0]*LEN
for i in range(1,LEN): #1～Nまでのすべての数について、0になるまでの操作回数を求める
 tmp=i
 cnt=0
 while tmp!=0:
   popcount=0
   for j in range(20):
     if tmp&(1<<j):
       popcount+=1
   tmp%=popcount
   cnt+=1
 moves[i]=cnt

n=int(input())
x=input()
k=x.count('1') 
if k==0: 
   for i in range(n):
       print(1)
elif k==1: 
   pos=x.index('1') 
   for i in range(n):
       if i==pos: 
           print(0)
       else:
           if pos==n-1: 
               print(2)
           else:
               if i==n-1: 
                   print(2)
               else:
                   print(1)
else:
   sum1=0 
   sum2=0 
   tmp1=1
   tmp2=1
   for i in range(n-1,-1,-1): 
       if x[i]=='1':
           sum1+=tmp1
           sum1%=k+1
           sum2+=tmp2
           sum2%=k-1
       tmp1*=2
       tmp1%=k+1
       tmp2*=2
       tmp2%=k-1
   for i in range(n):
       if x[i]=='0': 
           tmp=sum1+pow(2,n-i-1,k+1)
           tmp%=k+1
           print(moves[tmp]+1)
       else: 
           tmp=sum2-pow(2,n-i-1,k-1)
           tmp%=k-1
           print(moves[tmp]+1)

Measured memory_bytes: 79000
#include<bits/stdc++.h>
 
using namespace std;
 
#define INF 1000000007
#define LINF 1000000000000000007
 
typedef long long ll;
typedef pair<ll,ll> P;


string s;

int main(){
	cin >> s;
	vector<char> v;
	for(int i = 0; i < s.size(); i++){
		if(s[i] == 'B'){
			if(v.size()) v.pop_back();
		}
		else v.push_back(s[i]);
	}
	for(int i = 0; i < v.size(); i++){
		cout << v[i];
	}
	cout << endl;
	
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <stack>
#include <stdio.h>
using namespace std;
int main(void){
    // Your code here!
    int d=0;
    scanf("%d",&d);
    int a[d];
    for (int i=0;i<d;i++){
        scanf("%d",&a[i]);
    }
    int e=0;
    scanf("%d",&e);
     int c=0;
     int k=0;
    for (int i=0;i<e;i++){
        scanf("%d",&k);
        
        for(int n=0;n<d;n++){
        if(k==a[n]){
            c++;
            break;
        }}
   
    
    }
   
   

cout<< c <<endl;
return 0;
}




Measured memory_bytes: 3184
import java.util.*;

class Main{
  public static void main(String[] args){
    Scanner sc=new Scanner(System.in);
    int n=sc.nextInt();
    int k=sc.nextInt();
    int[] v=new int[n];
    for(int i=0;i<n;i++){
      v[i]=sc.nextInt();
    }
    
//    System.err.println(Arrays.toString(v));
    
    int max=0;
    for(int l=0;l<=Math.min(n,k);l++){
      for(int r=0;r<=Math.min(n-l,k-l);r++){
        
//        System.err.println("l:"+l+",r:"+r);
        
        PriorityQueue<Integer> pq=new PriorityQueue<>();
        for(int i=0;i<l;i++){
          pq.add(v[i]);
        }
        for(int i=0;i<r;i++){
          pq.add(v[n-i-1]);
        }
        for(int t=0;t<k-l-r;t++){
          if(pq.isEmpty()){
            break;
          }
          int g=pq.peek();
          if(g>=0){
            break;
          }
          pq.poll();
        }
        int here=0;
        while(!pq.isEmpty()){
          here+=pq.poll();
        }
//        System.err.println(here);
        max=Math.max(here,max);
      }
    }
    System.out.println(max);
  }
}

Measured memory_bytes: 28116
N = int(input())
dic = {}
for i in range(1,N+1):
    bi = int(input())
    dic[i] = bi
botan = 1
cnt = 0
while(True):
    botan = dic[botan]
    cnt += 1
    if(botan == 2):
        print(cnt)
        break
    if(cnt > N):
        print(-1)
        break

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

struct Dob {
    long long len;
    int cnt;
};

int main() {
    cin >> n;
    vector<long long> a(n, 0);
    for(int i = 0; i < n; ++i) {
        cin >> a.at(i);
    }

    sort(a.begin(), a.end());
    a.push_back(0);
    long long doub = a.at(0);
    int doubcnt = 1;
    vector<Dob> dob;
    for(int i = 1; i <= n; ++i) {
        if(doub != a.at(i)) {
            Dob indata;
            indata.len = doub;
            indata.cnt = doubcnt;
            dob.push_back(indata);
            doub = a.at(i);
            doubcnt = 1;
        }else {
            doubcnt++;
        }
    }

    int doblen = dob.size();
    long long square = 1;
    int sqcal = 0;

    for(int i = doblen-1; i >= 0; --i) {
        if(dob.at(i).cnt >= 4) {
            if(sqcal == 0) {
                square *= (dob.at(i).len*dob.at(i).len);
                sqcal = 2;
            }else if(sqcal == 1) {
                square *= dob.at(i).len;
                sqcal++;
            }
        }else if(dob.at(i).cnt >= 2) {
            square *= dob.at(i).len;
            sqcal++;
        }

        if(sqcal == 2) break;
    }

    if(sqcal <= 1) square = 0;

    cout << square << endl;
}

Measured memory_bytes: 4080
#include <bits/stdc++.h>
using namespace std;
#define INF 1<<30
#define endl '\n'
#define maxn 100005
#define tc printf("Case %d: ", cs)
#define tcn printf("Case %d:\n", cs);
#define FASTIO ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
typedef long long ll;
const double PI = acos(-1.0);
#define dbg(x) cerr << #x << " = " << x << endl;
#define dbg2(x, y) cerr << #x << " = " << x << ", " << #y << " = " << y << endl;
#define dbg3(x, y, z) cerr << #x << " = " << x << ", " << #y << " = " << y << ", " << #z << " = " << z << endl;
#define dbg4(w,x, y, z) cerr << #w << " = " << w << ", " <<#x << " = " << x << ", " << #y << " = " << y << ", " << #z << " = " << z << endl;

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

int main()
{
    FASTIO
    /*
    //double start_time = clock();
#ifndef ONLINE_JUDGE
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
    freopen("error.txt", "w", stderr);
#endif
//*/
    int T;
    //cin >> T;
    T = 1;
    for (int cs = 1; cs <= T; cs++) {
        ll n, p;
        cin >> n >> p;
        auto res = prime_factor(p);
        ll ans = 1;
        for (auto x : res) {
            //dbg2(x.first, x.second);
            while (x.second >= n) {
                ans *= x.first;
                x.second -= n;
            }
        }
        cout << ans << endl;
    }

    //double end_time = clock();
    //printf( "Time = %lf ms\n", ( (end_time - start_time) / CLOCKS_PER_SEC)*1000);
    return 0;
}

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

using ll = long long;

#define mod 1000000007
#define init ios::sync_with_stdio(0);cin.tie(0);

typedef vector<int> vi;
typedef pair<int, int> pi;
#define MS(x,y) memset(x,y,sizeof(x))
#define F first
#define S second
#define PB push_back
#define MP make_pair

int max_size = 1e6 + 1;



int main()
{
   init;

   int n;
   cin >> n;

   int val[max_size];
   int ar[n];
   for (int i = 0; i < n; ++i)
   {

      cin >> ar[i];
      val[ar[i]] = 1;
   }

   sort(ar, ar + n);


   int cnt = 0;

   for (int i = 0; i < n; i++)
   {
      if (val[ar[i]] ) {
         if (i != n - 1)
         {
            if (ar[i + 1] == ar[i])
               cnt--;
         }
         // cout << ar[i] << ' ';
         for (int j = 2 * ar[i]; j < max_size; j += ar[i])
         {
            val[j] = 0;
         }
         cnt++;
      }
      while (i + 1 < n && ar[i] == ar[i + 1])
         i++;
   }
   cout << cnt;

}

Measured memory_bytes: 8348
#include <iostream>
#include <cstdio>

using namespace std;

int main() {
	int a,b,c;
	int i;
	int count=0;
	
	cin >> a >> b >> c;
	for(i=a; i<=b; i++)
		if(c%i==0) count++;
	cout << count << endl;
	
	return 0;
}

Measured memory_bytes: 1164
#include <iostream>
using namespace std;
int main()
{
	int n;
	cin>>n;
	n%=10;
  	switch(n)
    {
      case 2:
      case 4:
      case 5:
      case 7:
      case 9:cout<<"hon";break;
      case 0:
      case 1:
      case 6:
      case 8:cout<<"pon";break;
      case 3:cout<<"bon";break;
    }
  return 0;
}

Measured memory_bytes: 3056
#include<bits/stdc++.h>
using namespace         std;
#define                 int long long
#define                 pb push_back
#define                 mp make_pair
#define st(arr,a)       memset(arr,a,sizeof arr)
#define                 nl cout<<endl
#define                 real signed
#define                 endl '\n'              
#define bitcount(x)     __builtin_popcountll(x)
const int MOD = 1000000007ll;
#define forn(i,a,b)     for(int i=a;i<=b;i++)
#define rfor(i,a,b)     for(int i=a;i>=b;i--)
#define all(x)          x.begin() , x.end()
#define pi pair<int,int>
#define X first
#define Y second
#define N 314159
#define  vi vector<int>
#define  v  vector

int n;
int arr[N];


int get(int a)
{
    int ans=0;
    forn(i,1,n)ans+=abs(arr[i]-(i+a));
    return ans;
}
int brr[N];
signed main() 
{
	ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); 
    cin>>n;
    forn(i,1,n)cin>>arr[i];
//    sort(arr+1,arr+1+n);
    
    int db=0;
    forn(i,1,n)brr[i]=arr[i]-i,db+=arr[i]-i;
    sort(brr+1,brr+1+n);
    int a=db/n,b=ceil(1.0*db/n);
    
    int ans=MOD*MOD;
    
    forn(i,-50,50)ans=min({ans,get(a-i),get(b-i)});
    ans=min({ans,get(brr[n/2]),get(brr[n/2+1]),get(brr[n/2-1])});
    cout<<ans;
    

     return 0;

}

//       g++ -g c.cpp ; ./a.exe

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

int main(){
    int n,m;
    cin >> n >> m;
    vector<int> a(n);
    for(auto&& e:a) cin >> e;
    sort(a.begin(),a.end(),
        [](const int a, const int b){
            return (a>b);
        });
    double sum = accumulate(a.begin(),a.end(),0);
    cout << (a.at(m-1) < sum/(4*m) ? "No" : "Yes") << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
int paper[10][10];
int main(void)
{
	int size,x,y,nx,ny,i,j,max=0,count=0;
	int dx[4] = {1,0,-1,0};
	int dy[4] = {0,1,0,-1};
	int ex[4] = {2,0,-2,0};
	int ey[4] = {0,2,0,-2};
	while(scanf("%d,%d,%d",&x,&y,&size) != EOF )
	{
		switch(size)
		{
			case 1:
			paper[x][y]++;
			for(i=0;i<4;i++)
			{
				if(x+dx[i]>=0 && x+dx[i]<10 && y+dy[i]>=0 && y+dy[i]<10)
				{
					paper[x+dx[i]][y+dy[i]]++;
				}
			}
			break;
			case 2:
			for(i=-1;i<2;i++)
			{
				for(j=-1;j<2;j++)
				{
					if(x+i>=0 && x+i<10 && y+j>=0 && y+j<10)
					{
						paper[x+i][y+j]++;
					}
				}
			}
			break;
			case 3:
			for(i=-1;i<2;i++)
			{
				for(j=-1;j<2;j++)
				{
					if(x+i>=0 && x+i<10 && y+j>=0 && y+j<10)
					{
						paper[x+i][y+j]++;
					}
				}
			}
			for(i=0;i<4;i++)
			{
				if(x+ex[i]>=0 && x+ex[i]<10 && y+ey[i]>=0 && y+ey[i]<10)
				{
					paper[x+ex[i]][y+ey[i]]++;
				}
			}
			break;
		}
	}
	for(i=0;i<10;i++)
	{
		for(j=0;j<10;j++)
		{
			if(paper[i][j] > max)max = paper[i][j];
			if(paper[i][j] == 0)count++;
		}
	}
	printf("%d\n",count);
	printf("%d\n",max);
	return 0;
}

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

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
        
    ll n,x;
    cin >> n >> x;
    
    vector<ll> a(n);
    rep(i,n) cin >> a[i];
    
    ll ans = 0;
    for(ll i = 0; i < n - 1; i++){
        ll sum = a[i] + a[i+1];
        
        if(sum > x){
            if(x - a[i] >= 0){
                ll c = x - a[i];
                ans += a[i+1] - c;
                a[i+1] = c;
            } else {
                ans += a[i+1];
                a[i+1] = 0;
                ans += a[i] - x;
                a[i] = x;
            }
        }
    }
    
    cout << ans << endl;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef bool boool;
typedef long long ll;
#define vl vector<ll>
#define vb vector<boool>
#define vs vector<string>
#define vp vector<pair<ll, ll>>
#define vvl vector<vector<ll>>
#define vvp vector<vector<pair<ll, ll>>>
#define mod 1000000007
#define all(x) x.begin(), x.end()
#define rep1(i, n) for (long long i=0; i<(long long)(n); i++)
#define rep2(i, s, e) for (long long i=(s); i<(long long)(e); i++)
#define GET_MACRO(_1,_2,_3,NAME,...) NAME
#define rep(...) GET_MACRO(__VA_ARGS__, rep2, rep1)(__VA_ARGS__)

int main(){
  string str;
  cin >> str;
  ll n = str.length();
  ll k;
  cin >> k;
  bool allsame = true;
  char check = str[0];
  rep(i, 1, n){
    if(str[i] != check) allsame = false;
  }
  if(allsame){
    cout << n * k / 2 << endl;
    return 0;
  }
  if(str[0] != str[n-1]){
    ll sum = 0;
    char c = str[0];
    int cur = 1;
    rep(i, 1, n){
      if(str[i] == c) cur++;
      else{
        c = str[i];
        sum += cur/2;
        cur = 1;
      }
    }
    sum += cur/2;
    cout << sum * k << endl;
    return 0;
  }
  ll front = 1;
  char c = str[0];
  rep(i, 1, n){
    if(str[i] == c) front++;
    else{
      break;
    }
  }
  ll back = 1;
  c = str[n-1];
  for(int i=n-2; i>=0; i--){
    if(str[i] == c) back++;
    else{
      break;
    }
  }
  ll sum = 0;
  c = str[front];
  int cur = 1;
  for(int i=front+1; i<n-back; i++){
    if(str[i] == c) cur++;
    else{
      c = str[i];
      sum += cur/2;
      cur = 1;
    }
  }
  sum += cur/2;
  cout << front/2 + back/2 + (front+back)/2*(k-1) + sum*k << endl;
  return 0;
}
      

Measured memory_bytes: 3584
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    string s;
    cin >> s;
    int n=s.size();
    int ans=0;
    for (int i=0;i<n/2;i++) {
        if (s[i]!=s[n-1-i]) ans++;
    }
    cout << ans << endl;
}

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

using namespace std;

int main(){

    int n,resp=0;

    cin >> n;

    if(n<1000){
        resp=1000-n;
    }    
    else{
        if(n%1000 == 0){
            resp=0;
        }
        else{
            while(n>1000){
                n-=1000;
            }
            resp=1000-n;
            
        }
    }
    cout << resp;
    cout << '\n';
    

    return 0;
}

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

#define fst(t) std::get<0>(t)
#define snd(t) std::get<1>(t)
#define thd(t) std::get<2>(t)
#define unless(p) if(!(p))
#define until(p) while(!(p))

using ll = std::int64_t;
using P = std::tuple<int,int>;

int N;
std::string S;

ll f(int x){
    return 1ll * x * (x + 1) / 2;
}

int main(){
  std::cin.tie(nullptr);
  std::ios::sync_with_stdio(false);

  std::cin >> S;

  N = S.size();

  ll res = 0;
  int i = 0;

  while(i < N && S[i] == '>'){
      i += 1;
  }

  res = f(i);

  for(int j=i;i<N;i=j){
      while(j < N && S[j] == '<'){
          j += 1;
      }

      int lt_n = j - i;
      
      i = j;

      while(j < N && S[j] == '>'){
          j += 1;
      }

      int gt_n = j - i;

      // std::cout << lt_n << ", " << gt_n << std::endl;

      if(lt_n <= gt_n){
          res += f(lt_n - 1) + f(gt_n);
      }else{
          res += f(lt_n) + f(gt_n - 1);
      }
  }

  std::cout << res << std::endl;
}


Measured memory_bytes: 1172
#include <iostream>
#include <string>
#include <string.h>
#include <vector>
using namespace std;
typedef long long ll;

#define rep(i, n) for(ll i = 0; i < n; i++)
#define REP(i, n) for(ll i = 1; i < n + 1; i++)


ll searchMax(ll c[], ll sd[], ll picked[]){
    ll max = -1;
    ll maxP = -1;
    REP(i, 26){
        if(picked[i] == 1){
            if(max < sd[i] + c[i]){
                max = sd[i] + c[i];
                maxP = i;
            }
        }else{
            if(max < sd[i]){
                max = sd[i];
                maxP = i;
            }
        }
    }

    return maxP;
}

int main(){
    // input
    ll D;
    cin >> D;

    ll c[27];
    ll s[D + 1][27];
    REP(i, 26){
        cin >> c[i];
    }
    REP(i, D){
        REP(j, 26){
            cin >> s[i][j];
        }
    }

    // preparation
    ll t[D + 1];
    ll picked[27];

    // main
    REP(i, D){
        t[i] = searchMax(c, s[i], picked);
        picked[t[i]] = 1;
    }

    // output
    REP(i, D){
        cout << 15 << endl;
    }

    return 0;
}


Measured memory_bytes: 3696
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0;i<n;i++)
#define REPR(i,n) for(int i=n;i>=0;i--)
#define FOR(i,m,n) for(int i=m;i<n;i++)
#define ALL(a) a.begin(),a.end()
typedef long long ll;
#define INF 1<<30

const double PI=3.141592653589793;

int main()
{
    int A,B,H,M;
    double thA,thB,thD;
    cin >> A >> B >> H >> M;
    thA = 30*H+0.5*M;
    thB = 6*M;
    thD = abs(thA-thB);
    if(thD>=360)thD-=360;
    //cout << thA << " " << thB << " " << thD << endl;
    double L = A*A+B*B-2*A*B*cos(PI*thD/180);
    cout << std::fixed << std::setprecision(15) << sqrt(L) << endl;
    return 0;
}

Measured memory_bytes: 4188
#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
using ull = uint64_t;
const ll INF = 9e18;
const int inf = 2e9;

void print() { cout << endl; }
template <typename Head, typename... Tail>
void print(Head head, Tail... tail) {
    int size = sizeof...(Tail);
    cout << head;
    if (size > 0) {
        cout << " ";
    }
    print(tail...);
}

void print0() {}
template <typename Head, typename... Tail>
void print0(Head head, Tail... tail) {
    cout << head;
    print0(tail...);
}

using edge = pair<int, int>;
void dfs(int u, vector<vector<edge>>& edges, vector<int>& a, vector<bool>& done, vector<stack<int>>& dpstack, vector<int>& result) {
    done[u] = true;

    int left = 0;
    int right = dpstack.size() - 1;
    while (left <= right) {
        int mid = (left + right) / 2;
        int mval = dpstack[mid].size() > 0 ? dpstack[mid].top() : inf;
        if (mval >= a[u]) {
            right = mid - 1;
        } else {
            left = mid + 1;
        }
    }
    int toinsert = -1;
    for (int i = left - 2; i <= left + 2; i++) {
        if (i >= 0 && i < (int)dpstack.size() && (!dpstack[i].size() || dpstack[i].top() >= a[u])) {
            toinsert = i;
            break;
        }
    }
    dpstack[toinsert].push(a[u]);

    left = 0;
    right = dpstack.size() - 1;
    while (left <= right) {
        int mid = (left + right) / 2;
        if (!dpstack[mid].size()) {
            right = mid - 1;
        } else {
            left = mid + 1;
        }
    }
    result[u] = dpstack.size();
    for (int i = left - 2; i <= left + 2; i++) {
        if (i >= 0 && i < (int)dpstack.size() && !dpstack[i].size()) {
            result[u] = i;
            break;
        }
    }

    for (auto e : edges[u]) {
        if (!done[e.second]) {
            dfs(e.second, edges, a, done, dpstack, result);
        }
    }
    dpstack[toinsert].pop();
}

int main() {
    int N;
    cin >> N;
    vector<int> a(N, -1);
    for (int i = 0; i < N; i++) {
        cin >> a[i];
        a[i]--;
    }
    vector<vector<edge>> edges(N);
    for (int i = 0; i < N - 1; i++) {
        int u, v;
        cin >> u >> v;
        u--;
        v--;
        edges[u].push_back(make_pair(u, v));
        edges[v].push_back(make_pair(v, u));
    }
    vector<bool> done(N, false);
    vector<int> result(N, -1);

    vector<stack<int>> dpstack(N);
    dfs(0, edges, a, done, dpstack, result);
    for (int i = 0; i < N; i++) {
        print(result[i]);
    }
}


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


int main()
{
  

   ll n;
   cin>>n;
   map <ll,ll> m;
   ll temp;
   ll a,b;
   ll total = 0;
   while(n--)
   {
        cin>>temp;
        m[temp]++;
        total += temp;
   }
    ll q;
    cin>>q;
    while(q--)
    {
        cin>>a>>b;
        if(m.find(a) != m.end())
        {
            total = total - a*m[a] + b*m[a];
            m[b] += m[a];
            m.erase(a);
        }
        cout<<total<<endl;

    }
}

Measured memory_bytes: 7552
#include<bits/stdc++.h>
#define N 100005
using namespace std;
typedef pair<int,int> P;
int n,s,t,w,ans;
vector<int> d[N];
vector<P> e[N];

int dfs(int x,int prev){
  for(int i=0;i<(int)e[x].size();i++){
    int nx=e[x][i].first,c=e[x][i].second;
    if(nx==prev)continue;
    d[x].push_back(dfs(nx,x)+c);
  }
  for(int i=0;i<2;i++)d[x].push_back(0);
  sort(d[x].begin(),d[x].end());
  reverse(d[x].begin(),d[x].end());
  ans=max(ans,d[x][0]+d[x][1]);
  return d[x][0];
}

int main(){
  cin>>n;
  for(int i=0;i<n-1;i++){
    cin>>s>>t>>w;
    e[s].push_back(P(t,w));
    e[t].push_back(P(s,w));
  }
  dfs(0,-1);
  cout<<ans<<endl;
  return 0;
}

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

#define fi first
#define se second
#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define each(itr,v) for(auto itr:v)
#define pb(s) push_back(s)
#define mp(a,b) make_pair(a,b)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define maxch(x,y) x=max(x,y)
#define minch(x,y) x=min(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt(x) bitset<32>(x).count()

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<P, int> PPI;
typedef pair<ll, ll> PL;
typedef pair<P, ll> PPL;

#define INF INT_MAX/3

#define MAX_N 1000
#define MAX_E 100010

//// UnionFind
struct UnionFind{
	vector<int> v;
	UnionFind(int n) : v(n, -1) {}

	int find(int x) { return v[x] < 0 ? x : v[x] = find(v[x]); }
	void unite(int x, int y) {
		x = find(x); y = find(y);
		if (x == y) return;
		if (-v[x] < -v[y]) swap(x, y);
		v[x] += v[y]; v[y] = x;
	}
	bool root(int x) { return v[x] < 0; }
	bool same(int x, int y) { return find(x) == find(y); }
	int size(int x) { return -v[find(x)]; }
};

struct  edge{ int u,v,cost; };
bool comp(const edge& e1,const edge& e2){return e1.cost<e2.cost;}
struct Kruskal{
	int V,E;
	edge es[MAX_E];
	int idxes;
	void init(int v,int e){V=v;E=e;idxes=0;}
	void add_edge(int u,int v,int cost){
		es[idxes++]=(edge){u,v,cost};
	}
	int mintree(){
		sort(es,es+E,comp);
		UnionFind uf(V);
		int res=0;
		for(int i=0;i<E;i++){
			edge e=es[i];
			if(!uf.same(e.u,e.v)){
				uf.unite(e.u,e.v);
				res+=e.cost;
			}
		}
		return res;
	}
};

Kruskal ks;

int v,e;
edge es[100011];
int main(){
	cin.sync_with_stdio(false);
	cin>>v>>e;
	ks.init(v,e);
	rep(i,e){
		int u,v,cost;
		cin>>u>>v>>cost;
		ks.add_edge(u,v,cost);
	}
	cout<<ks.mintree()<<endl;
	return 0;
}

Measured memory_bytes: 4388
<?php
fscanf(STDIN, "%d%d", $N, $M);
for($i = 0; $i < $N; $i++){
  $danger[] = intval(trim(fgets(STDIN)));
}
foreach($danger as $d){
  $map[$d] = true;  
}

$dp[-1] = 0;
$dp[0] = 1;
for($i = 1; $i <= $N; $i++){
  if(isset($map[$i])){
    $dp[$i] = 0;
  }else{
    $dp[$i] = $dp[$i-2] + $dp[$i-1];
  }
  $dp[$i] %= 10**9+7;
}
printf("%d", $dp[$N]);


Measured memory_bytes: 21232
#include <stdio.h>

int main(void){
	int a,b;
	int i;

	scanf("%d%d",&a,&b);
	if(a<b)
		for(i=0;i<b;i++)
			printf("%d",a);
	else
		for(i=0;i<a;i++)
			printf("%d",b);
	
	printf("\n");

	return 0;
}

Measured memory_bytes: 128
# code-festival-2017-qualcC - Inserting 'x'
from collections import deque


def main():
    S = deque(list(input().rstrip()))
    ans = 0
    while len(S) >= 2:
        l, r = S[0], S[-1]
        if l == r:
            S.popleft(), S.pop()
        else:
            ans += 1
            if l == "x":
                S.append("x")
            elif r == "x":
                S.appendleft("x")
            else:
                print(-1)
                return
    print(ans)


if __name__ == "__main__":
    main()

Measured memory_bytes: 4916
def main():
    H, W = map(int, input().split())
    A = list(list(map(int, input().split())) for _ in range(H))
    ope = []

    for w in range(W):
        for h in range(H-1):
            if A[h][w] % 2 != 0:
                A[h+1][w] += 1
                ope.append((h+1,w+1,h+2,w+1))

    for w in range(W-1):
        if A[H-1][w] % 2 != 0:
            A[H-1][w+1] += 1
            ope.append((H,w+1,H,w+2))

    print(len(ope))
    for ans in ope:
        print(*ans)

if __name__ == "__main__":
    main()

Measured memory_bytes: 72924
import java.util.Scanner

var N=0
var D=0
var answer=0
val sc=Scanner(System.`in`)
fun main(args:Array<String>){
    N=sc.nextInt()
    D=sc.nextInt()
    var ary=Array(N,{Array(D,{0})})
    for(i in 0..(N-1)){
        for(j in 0..(D-1)){
            ary[i][j]=sc.nextInt()
        }
    }
    for(i in 0..(N-1)){
        for(j in 0..(i-1)){
            var tmp=0
            for(k in 0..(D-1)){
                tmp+=(ary[i][k]-ary[j][k])*(ary[i][k]-ary[j][k])
            }
            if(tmp==Math.sqrt(tmp.toDouble()).toInt()*Math.sqrt(tmp.toDouble()).toInt()){
                answer++
            }
        }
    }
    println(answer)
}


Measured memory_bytes: 31392
#include<iostream>
#include<vector>
#include<bits/stdc++.h>
#define lli long long int
#define mod 1000000007
#define pb push_back
#define mk make_pair
#define fastio ios_base::sync_with_stdio(false); cout.tie(NULL);
using namespace std;

int main()
{
	fastio;
	int n,a,b,i,j,mn=-1;
	cin>>n;
	vector<int> ar[n+1];
	vector<pair<int,int>> v;
	for(i=0;i<n-1;i++)
		cin>>a>>b , ar[a].pb(b) , ar[b].pb(a) , v.pb({a,b});
	map<pair<int,int>,int> mp,ans;
	int vis[n+1]={0};
	for(i=1;i<=n;i++)
	{
		if(ar[i].size()>0)
		{
			int tmp=ar[i].size();
			mn=max(mn,tmp);
			memset(vis,0,sizeof(vis));
			for(auto el : ar[i])
			{
				if(ans.find({i,el})!=ans.end())
					vis[ans[{i,el}]-1]=1;
				else if(ans.find({el,i})!=ans.end())
					vis[ans[{el,i}]-1]=1;
			}
			for(auto el : ar[i])
			{
				if(mp.find({i,el})==mp.end() && mp.find({el,i})==mp.end())
				{
					for(j=0;j<ar[i].size();j++)
					{
						if(vis[j]==0)
						{
							ans[{i,el}]=ans[{el,i}]=j+1;
							vis[j]=1;
							mp[{el,i}]=mp[{i,el}]=1;
//							cout<<i<<" "<<el<<" "<<j+1<<endl;
							break;
						}
					}
				}
			}
		}
	}
//	for(auto el : ans)
//		cout<<el.first.first<<" "<<el.first.second<<" : "<<el.second<<endl;
	cout<<mn<<endl;
	for(auto pair : v)
		cout<<ans[pair]<<endl;
	return 0;
}


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

int main() {
  int n;
  cin >> n;
  int an;
  rep(i,n) {
    cin >> an;
    if (an%2==0) {
      if (an%3!=0 and an%5!=0) {
        cout << "DENIED";
        return 0;
      }
    }
  }
  cout << "APPROVED";
}


Measured memory_bytes: 256