akhauriyash/Code-Regression huggingface dataset:
#input of int(split by space)
def get_i()
  return gets.chomp.split(" ").map(&:to_i)
end
#input of float(split by space)
def get_f()
  return gets.chomp.split(" ").map(&:to_f)
end
#input of string(split by space)
def get()
  return gets.chomp.split(" ")
end
#input of string(split per one character)
def get_nsp()
  return gets.chomp.split("")
end
#yes or no decision
def yn_judge(bool,y="Yes",n="No")
  return bool ? y : n 
end
#create of array
def array(size1,init=nil,size2=-1)
  if size2==-1
    return Array.new(size1){init}
  else
    return Array.new(size2){Array.new(size1){init}}
  end
end

def max(a,b)
    return a>b ? a : b
end

def min(a,b)
    return a>b ? b : a
end

INF=Float::INFINITY

def cal(x)
    return 1 if x==1
    return x*cal(x-1)
end
N=gets.to_i
xy=array(N)
N.times do|i|
    xy[i]=get_i
end
ans=0
xy.permutation(N).to_a.each do|arr|
  (N-1).times do|i|
    ans+=((arr[i][0]-arr[i+1][0])**2+(arr[i][1]-arr[i+1][1])**2)**0.5
  end
end
puts ans/cal(N)

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

public class AtCoderA
{
    static void Main()
    {
        var sc = new Scanner();

        char s = sc.NextChar();
        char t = sc.NextChar();

        string answer = s == t ? "=" : (s > t) ? ">" : "<";

        Console.WriteLine(answer);
    }

    class Scanner
    {
        private string[] _line;
        private int _index;
        private const char Separator = ' ';

        public Scanner()
        {
            _line = new string[0];
            _index = 0;
        }

        public string Next()
        {
            while (_index >= _line.Length)
            {
                _line = Console.ReadLine().Split(Separator);
                _index = 0;
            }

            return _line[_index++];
        }

        public int NextInt() => int.Parse(Next());
        public long NextLong() => long.Parse(Next());
        public double NextDouble() => double.Parse(Next());
        public decimal NextDecimal() => decimal.Parse(Next());
        public char NextChar() => Next()[0];
        public char[] NextCharArray() => Next().ToCharArray();

        public string[] Array()
        {
            _line = Console.ReadLine().Split(Separator);
            _index = _line.Length;
            return _line;
        }

        public int[] IntArray() => Array().Select(int.Parse).ToArray();
        public long[] LongArray() => Array().Select(long.Parse).ToArray();
        public double[] DoubleArray() => Array().Select(double.Parse).ToArray();
        public decimal[] DecimalArray() => Array().Select(decimal.Parse).ToArray();
    }
}

Measured memory_bytes: 11092
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main(void) {
	int  H,A,i;

//入力
    scanf("%d %d",&H,&A);

    if(H<=A) {printf("\n 1 \n");return 0;}

    for(i=0;H>0;i++) H-=A;

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

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

int main() {
	int H, W, K;
	cin >> H >> W >> K;

	vector<vector<int>> dp(H + 1, vector<int> (W, 0)); 

    dp[0][0] = 1;
	rep(i, H) {
		rep(j, W) {
			for (int k = 0; k < 1 << (W - 1); k++) {
				// 2 つの横線がつながっていないか調べる
				bool ok = true;
				for (int l = 0; l < W - 2; l++) {
					if (((k >> l) & 1) && ((k >> (l + 1)) & 1)) {
						ok = false;
					}
				}

				if (ok) {
					if (j >= 1 && ((k >> (j - 1)) & 1)) {
						// 左方向に横線をたどるケース
						dp[i + 1][j - 1] += dp[i][j];
						dp[i + 1][j - 1] %= mod;
					}
					else if (j <= W - 2 && ((k >> j) & 1)) {
						// 右方向に横線をたどるケース
						dp[i + 1][j + 1] += dp[i][j];
						dp[i + 1][j + 1] %= mod;
					}
					else {
						// 横線をたどらないケース
						dp[i + 1][j] += dp[i][j];
						dp[i + 1][j] %= mod;
					}
				}
			}
		}
	}

	cout << dp[H][K - 1] << endl;
	return 0;
}

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>;

void solve() {
    int n;
    cin >> n;
    vector<ll> a(n);
    rep(i,n) cin >> a[i];
    int zero = 0;
    rep(i,n) if (a[i] == 0) zero++;
    if (zero > 0) {
        cout << 0 << endl;
        return;
    }

    ll ans = 1;
    rep(i,n) {
        if (a[i] > (ll)1e18 / ans) {
            cout << -1 << endl;
            return;
        }
        ans *= a[i];
    }

    cout << ans << endl;
}

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


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

int main() {
  string s;
  cin >> s;
  int ans;
  if (s == "RRR") ans = 3;
  else if (s == "SSS") ans = 0;
  else if (s == "RRS" || s == "SRR") ans = 2;
  else ans = 1;

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 3620
#include <bits/stdc++.h>
#include <iostream>
#include <iomanip>
#include <string>
#include <string.h>

using namespace std;

int main() {
  int n;
  char s;
  cin >> n;
  bool flag = 0;
  for(int i = 0; i < n; i++) {
    cin >> s;
    if(s == 'Y') flag = 1;
  }
  
  if(flag) cout << "Four" << endl;
  else cout << "Three" << endl;
}

Measured memory_bytes: 3588
#include <bits/stdc++.h>
#define mp make_pair
#define sqr(x) (x)*(x)
using namespace std;
typedef pair<int,int> pii;
typedef long long ll;
const int maxn=100007;
const ll inf=0x3f3f3f3f;
const int mod=998244353;
#define rep(i,x,y) for(auto i=(x);i<=(y);++i)
#define dep(i,x,y) for(auto i=(x);i>=(y);--i)
ll read(){
    ll x=0,f=1;
    char ch=getchar();
    while(ch<'0'||ch>'9') {if(ch=='-') f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9') x=x*10+ch-'0',ch=getchar();
    return x*f;
}
int main(){
    ll now=100;
    ll x=read();
    int cnt=0;
    while(x>now){
        now+=now/100;cnt++;
    }
    cout<<cnt;
    return 0;
}

Measured memory_bytes: 3616
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
    	Scanner sc = new Scanner(System.in);
    	int n = sc.nextInt();
    	int[] a = new int[n];
    	int[] b = new int[n];
    	int[] c = new int[n-1];
    	
    	for(int i = 0; i < n; i++) {
    		a[i] = sc.nextInt();
    	}
    	for(int i = 0; i < n; i++) {
    		b[i] = sc.nextInt();
    	}
    	for(int i = 0; i < n - 1; i++) {
    		c[i] = sc.nextInt();
    	}
    	
    	int ans = 0;
    	
    	for(int i = 0; i < n; i++) {
    		ans = ans + b[a[i] - 1];
    		if((i >= 1) && (a[i] == a[i - 1] + 1)) {
    			ans = ans + c[a[i - 1] - 1];
    		}
    	}
    	
    	System.out.println(ans);

	}

}


Measured memory_bytes: 22868
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Console = System.Console;

namespace Atcoder
{
    class Program
    {
        static void Main(string[] args)
        {
            var ab = ReadStringArray();
            if (ab[0] == "H")
            {
                Console.WriteLine(ab[1]);
            }
            else
            {
                if (ab[1] == "H")
                {
                    Console.WriteLine("D");
                }
                else
                {
                    Console.WriteLine("H");
                }
            }
        }
        private static readonly Func<string> Read = () => Console.ReadLine();
        private static readonly Func<string[]> ReadStringArray = () => Console.ReadLine().Split();
        private static readonly Func<int> ReadInt = () => int.Parse(Console.ReadLine());
        private static readonly Func<long> ReadLong = () => long.Parse(Console.ReadLine());
        private static readonly Func<int[]> ReadIntArray = () => Console.ReadLine().Split().Select(int.Parse).ToArray();
        private static readonly Func<long[]> ReadLongArray = () => Console.ReadLine().Split().Select(long.Parse).ToArray();
        private static readonly Action<string> Cw = str => Console.WriteLine(str);
    }
}

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

int main(){
  int n,k;
  cin >> n >> k;
  int b,ans=0;
  for(int i=0;i<n;i++){
    cin >> b;
    if(b>=k)
      ans++;
  }
  cout << ans  << endl;
  return 0;
}

Measured memory_bytes: 3600
#include <iostream>
#include <algorithm>
#include <utility>
#include <vector>
#include <string>
#include <queue>
#include <tuple>
#include <cmath>
#include <bitset>
#include <cctype>
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(ll i=ll(a);i<ll(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define PRINT(V) cout << V << "\n"
#define SORT(V) sort((V).begin(),(V).end())
#define RSORT(V) sort((V).rbegin(), (V).rend())
using namespace std;
using ll = long long;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
template<typename T>
vector<T> table(int n, T v) { return vector<T>(n, v); }

template <class... Args>
auto table(int n, Args... args) {
    auto val = table(args...);
    return vector<decltype(val)>(n, move(val));
}
const ll INF = 1e16;
const ll MOD = 1000000007;
typedef pair<ll,ll> P;
const ll MAX = 200005;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int a,b;
    cin >> a >> b;
    int n = b-a;
    PRINT(n*(n+1)/2-b);
}


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

const ll INF = 1e18;
const ll MOD = 1000000007;
const ll MX = 0; //最大値

#define rep(i,n) for(ll i=1; i<(ll)(n); i++)
#define ALL(x) (x).begin(),(x).end()
#define MAX(x) *max_element(ALL(x))
#define PB push_back
#define F first
#define S second

int main(){
    ll n; cin >> n;
    ll ans = 0;
    rep(i, n){
        for(ll j = 1; i*j < n; j++) ans++;
    }
    cout << ans;
    return 0;
}

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

template <typename T1, typename T2, typename T3>
void dfs(T1& dist, T2& seen, T3& v, int x) {
	for (int i = 0; i < v[x].size(); i++ ) {
		int y = v[x][i].first, d = v[x][i].second;

		if (seen[y]) {
			if (dist[x] + d != dist[y]) {
				cout << "No" << endl;
				exit(0);
			}
			continue;
		}

		dist[y] = dist[x] + d;
		seen[y] = true;
		dfs(dist, seen, v, y);
	}
}


int main() {
	const ll INF = 1e18;
	int N, M;
	cin >> N >> M;
	vector<vector<P>> v(N + 1);
	for (int i = 0; i < M; i++) {
		int l, r, d;
		cin >> l >> r >> d;
		v[l].push_back(P(r, d));
		v[r].push_back(P(l, -d));
	}

	vector<ll> dist(N + 1, INF);
	vector<bool> seen(N + 1, false);
	for (int i = 1; i <= N; i++) {
		if (seen[i]) continue;

		dist[i] = 0;
		seen[i] = true;
		dfs(dist, seen, v, i);
	}

	cout << "Yes" << endl;
	return 0;
}


Measured memory_bytes: 14208
#include <bits/stdc++.h>
	using namespace std;
	#define pb push_back
	#define M 1000000007
	#define INF 100000005
	const int N = 1e5 + 5;
	#define maax(a,b,c) max((int)a,max((int)b,(int)c))
	#define mp make_pair
	#define in long long
	#define all(a) a.begin(),a.end()
	#define gcd(a,b) __gcd(a,b)
	#define lcm(a,b) (a*b)/gcd(a,b)
	#define inf (long long) 1e18
	#define fr(i,m, n) for (int i = (int)(m); i < (int)(n); ++i)
	#define fre(i,m, n) for (int i = (int)(n); i <= (int)(m); i--)
	typedef long long LL;
	typedef pair<int, int> PII;
	in y=1;
	int fact(int n)
	{
		if(n==1) 
		{int h=y;y=1;
		return h;}
		y*=n;fact(n-1);
	}
	bool is_prime(int n)
	{
		int k=(n/2)+1,m=0;//cout<<k<<" ";
		fr(i,2,k)
		{
			if(n%i==0) m=1,i=k;//cout<<n<<" "<<i<<" ";//return false;
		}
		if(m==0) return true;
		else return false;
		//return true;
	}
	int sollve()
	{
	    int n;cin>>n;string s;cin>>s;
	    fr(i,0,s.size())
	    {
	    	int p=0;
	    	fr(j,0,s.size()-1)
	    	{
	    		
	    		if(s[j]=='(' && s[j+1]==')')
	    		{
	    			//cout<<s[j]<<" "<<s[j+1]<<"\n";
	    			p=1;s.erase(j,2);
				}
			}
			(p==1)?i--:i=s.size();
			//cout<<s.size()<<" "<<s<<"\n";
		}
		//cout<<s<<" ";
		cout<<s.size()/2<<"\n";
	    return 0;
	}
	int solve()
	{
		in a,b,c;
		cin>>a>>b>>c;
		
	}
	int main()
	{
		ios::sync_with_stdio(0); cin.tie(0);
		int t;cin>>t;
		cout<<t+pow(t,2)+pow(t,3);
		return 0;
	}		
//set-> all elements are unique and sorted *_*

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

typedef long long ll;
constexpr ll MOD = ll(1e9 + 7);

ll solve(string s, int D){
    int L = s.size();
    ll dp[2][2][100]{};  // dp[桁][最大未満フラグ][桁和 mod D]
    dp[0][0][0] = 1;
    for(int i=0;i<L;i++){
        int M = s[i]-'0';
        for(int j=0;j<2;j++){
            for(int k=0;k<D;k++){
                for(int m=0;m<=(j?9:M);m++){
                    dp[1][j||(m<M)][(k+m)%D] += dp[0][j][k];
                }
            }
        }
        for(int j=0;j<2;j++){
            for(int k=0;k<D;k++){
                dp[0][j][k] = dp[1][j][k] % MOD;
                dp[1][j][k] = 0;
            }
        }
    }
    
    return (dp[0][1][0] + dp[0][0][0] - 1 + MOD)%MOD;
}

int main() {
    string K;
    int D;
    cin >> K >> D;
    cout << solve(K, D) << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define N 100005
using namespace std;
typedef long long ll;
string s;
ll ans,n,a[3];
int main(){
	cin>>n>>s;
	for(int i=0;i<n;i++){
		if(s[i]=='R')a[0]++;
		else if(s[i]=='G')a[1]++;
		else a[2]++;
	} 
	ans=a[0]*a[1]*a[2];
	for(int i=0;i<n-1;i++)
		for(int d=1;i+2*d<n;d++)
			if((s[i]^s[i+d]^s[i+2*d])==('R'^'G'^'B'))ans--;
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 3596
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main(){
  int n;

  while(cin >> n , n){
    long long big = 0,sum = 0;
    vector< int > a(n);
    vector< int > b(n - 1);

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

    sort(b.begin(),b.end());
    big = n * sum;
    for(int i=n-2;i>=0;i--){
      sum += b[i];
      big = max(big,sum * (i + 1));
    }
    cout << big << endl;
  }
}

Measured memory_bytes: 1532
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {
  public static void main(String[] args) {
    Scanner scanner = new Scanner(System.in);

    int N = scanner.nextInt();
    Node[] nodes = new Node[N];
    for (int i = 0; i < N; i++) nodes[i] = new Node(i);

    for (int i = 0; i < N - 1; i++) {
      int u = scanner.nextInt() - 1;
      int v = scanner.nextInt() - 1;
      int w = scanner.nextInt();
      Edge e = new Edge(u ^ v, w);
      nodes[u].edges.add(e);
      nodes[v].edges.add(e);
    }

    dfs(nodes[0], null, 0, nodes);

    StringBuilder sb = new StringBuilder();
    for (int i = 0; i < N; i++) {
      sb.append(nodes[i].color).append('\n');
    }
    System.out.print(sb.toString());
  }

  private static void dfs(Node node, Node from, int color, Node[] nodes) {
    node.color = color;
    for (Edge e : node.edges) {
      Node to = nodes[e.d ^ node.id];
      if (to != from) {
        int c = e.w % 2 == 0 ? node.color : 1 - node.color;
        dfs(to, node, c, nodes);
      }
    }
  }

  private static class Node {
    private final int id;
    private int color;
    List<Edge> edges = new ArrayList<>();

    private Node(int id) {
      this.color = -1;
      this.id = id;
    }
  }

  private static class Edge {
    private final int w;
    private final int d;

    private Edge(int d, int w) {
      this.d = d;
      this.w = w;
    }
  }
}


Measured memory_bytes: 107208
n = int(input())
s = [input() for i in range(n)]
s.sort(key=lambda x: len(x))

pivot = s[0]
min_letters = ""
for i in range(0, len(pivot)):
    ele = pivot[i]
    for j in range(1, n):
        if s[j].count(pivot[i]):
            pos = s[j].find(pivot[i])
            tmp_list = list(s[j])
            tmp_list[pos] = ""
            s[j] = "".join(tmp_list)
        else:
            ele = ""
    min_letters += ele

ans_list = list(min_letters)
ans_list.sort()
print("".join(ans_list))


Measured memory_bytes: 3064
//#include "bits/stdc++.h"

#define _USE_MATH_DEFINES
#include<cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <deque>
#include <algorithm>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <iterator>

using namespace std;

#define rep(i,a,b) for(int i=(a), i##_len=(b);i<i##_len;i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)

#define int ll
#define SZ(x) ((int)(x).size())
#define pb push_back
#define mp make_pair

//typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<double, double> pdd;
typedef vector< vector<int> > mat;

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

const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;

map<int, int> nmap;

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

	int s;
	cin >> s;

	nmap[s]++;
	int p = s;
	for (int i = 2;; i++)
	{
		int n;
		if (p % 2 == 0)
		{
			n = p / 2;
		}
		else
		{
			n = 3 * p + 1;
		}
		nmap[n]++;
		if (nmap[n] == 2)
		{
			cout << i << endl;
			return 0;
		}
		p = n;
	}

	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<cassert>
#include<iterator>
#include<complex>
#include<stack>
#include<sstream>
#include<iterator>
#include<list>

using namespace std;

typedef  long long int lint;

#define rep(i, n) for (lint i = 0; i < n; i++)
#define sort(v) sort((v).begin(), (v).end())
#define reverse(v) reverse((v).begin(), (v).end())
#define upper(v,hoge) upper_bound(v.begin(),v.end(),hoge)
#define lower(v,hoge) lower_bound(v.begin(),v.end(),hoge)
#define mp make_pair
#define enld endl

lint power(lint x, lint n, lint m) {
	//(x^n)%mを返す
	lint res = 1;
	x %= m;
	while (n > 0) {
		if (n % 2 == 1) {
			res = res * x % m;
		}
		x = x * x % m;
		n /= 2;
	}
	return res;
}

lint invmod(lint n, lint m) {
	//nの逆元を返す
	lint ret = 0;
	ret = power(n, m - 2, m);
	return ret;
}

lint comb(lint n, lint k, lint m) {
	//nCk%MODを返す
	//O(k)
	lint ans = 1;
	rep(i, k) {
		ans *= n - i;
		ans %= m;
		ans *= invmod(k - i, m);
		ans %= m;
	}
	return ans;
}

int main() {
	lint MOD = pow(10, 9) + 7;
	lint N;
	cin >> N;
	vector<lint>A(N);
	rep(i, N) {
		cin >> A[i];
	}
	if (N % 2 == 1) {
		sort(A);
		rep(i, N) {
			if (A[i] == i + i % 2) {

			}
			else {
				cout << 0 << enld;
				return 0;
			}
		}
		cout << power(2, (N - 1) / 2, MOD) << endl;
	}
	else {
		sort(A);
		rep(i, N) {
			if (A[i] == i - i % 2 + 1) {
				
			}
			else {
				cout << 0 << enld;
				return 0;
			}
		}
		cout << power(2, N / 2, MOD) << endl;
	}
}

Measured memory_bytes: 3928
#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,a) FOR(i,0,a)
	
using namespace std;

typedef long long ll;

int main(){
	int a,b;
	cin>>a>>b;
	if (a+b==15){
		cout<<"+";
	}else if (a*b==15){
		cout<<"*";
	}else{
		cout<<"x";
	}
	cout<<endl;
	return 0;
}

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

int main() {

    string str;
    cin>>str;

    int c=0;
    if(str=="MON") c=1;
    if(str=="TUE") c=2;
    if(str=="WED") c=3;
    if(str=="THU") c=4;
    if(str=="FRI") c=5;
    if(str=="SAT") c=6;

    cout << (7-c) << '\n';


    return 0;
}


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

ll count(vector<int> a, bool positive) {
    ll total = 0, count = 0, diff = 0;
    for (int i = 0; i < a.size(); i++) {
        diff = 0;
        if (positive && (a[i] + total <= 0)) {
            diff = (1 - total) - a[i];
        } else if (!positive && (a[i] + total >= 0)) {
            diff = (-1 - total) - a[i];
        }
        positive = (positive) ? false : true;
        a[i] += diff;
        count += abs(diff);
        total += a[i];
    }
    return count;
}

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

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

    cout << min(count(a, true), count(a, false)) << endl;
    return 0;
}

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

#define Fast ios_base::sync_with_stdio(0);cin.tie(0),cout.tie(0)
#define FO freopen("in.txt", "r", stdin)
#define FC freopen("out.txt", "w", stdout)
#define aise cout<<"aise"<<endl
#define pb push_back
#define pf push_front
#define ppb pop_back
#define ppf pop_front
#define mp make_pair
#define ll long long
#define all(x) x.begin(), x.end()
#define mset(v, a) memset(v, a, sizeof(v))
#define pll pair< ll, ll >
#define pdd pair< double, double >
#define ff first
#define ss second
#define pi acos(-1.0)
#define mxN 2010
#define inf 1e14
#define MOD 1000000007

int main()
{

    ll n;
    string ss;
    scanf("%lld", &n);
    cin >> ss;
    vector<ll> lf(n+3, 0), rt(n+3, 0), vl(n+3, 0), vr(n+3, 0);
    for(ll i = 0; i < ss.size(); i++)
    {

        ll idx = i+1;
        if(ss[i] == 'W') vl[idx] = 1;
        else vr[idx] = 1;
    }
    for(ll i = 1; i <= n; i++) lf[i] = lf[i-1]+vl[i];
    for(ll i = 1; i <= n; i++) rt[i] = rt[i-1]+vr[i];
    ll ans = inf;
    for(ll i = 1; i <= n; i++)
    {

        ll xx = lf[i-1]+rt[n]-rt[i];
        ans = min(ans,xx);
    }
    printf("%lld", ans);
}


Measured memory_bytes: 9988
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>

using namespace std;

#ifdef DEBUG_MODE
	#define DBG(n) n;
#else
	#define DBG(n) ;
#endif

#define REP(i,n) for(ll (i) = (0); (i) < (n); ++i)
#define PB push_back
#define MP make_pair
#define FI first
#define SE second
#define ALL(v) v.begin(),v.end()
#define INF 1100000000
#define LLINF 1000000000000000000LL
#define MOD 1000000007

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


int main()
{
  int H, W; cin >> H >> W;
  vector<string> S(H);
  REP(i, H) cin >> S[i];

  string dot = "";
  REP(j, W) dot += '.';

  vector<string> tS;
  REP(i, H) if (S[i] != dot) tS.PB(S[i]);

  vector<bool> f(W, false);
  REP(i, W) {
    REP(j, tS.size()) {
      if (tS[j][i] != '.') {
        f[i] = true;
        break;
      }
    }
  }
  REP(i, tS.size()) {
    REP(j, W) {
      if (f[j] == true) {
        cout << tS[i][j] << flush;
      }
    }
    cout << endl;
  }

	return 0;
}



Measured memory_bytes: 256
#include<iostream>
#include<fstream>
#include<stdio.h>
#include<string>
#include<vector>
#include<map>
#include<math.h>
#include<algorithm>
#include<iomanip>
#include<set>
#include<utility>

const long long PRIME = 1000000007;

using namespace std;

int main() {
  long long q, h, s, d, n;
  cin >> q >> h >> s >> d >> n;
  long long l1 = min(min(q * 4, h * 2), s);
  long long l2 = min(l1 * 2, d);
  cout << (n / 2) * l2 + (n % 2) * l1 << endl;
  return 0;
}


Measured memory_bytes: 384
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
#define MAXN 200002
int n,a[MAXN],pos[MAXN],pre[MAXN],nex[MAXN];
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	{
		scanf("%d",&a[i]);
		pos[a[i]]=i;
	}
	for(int i=0;i<=n+1;i++)
		pre[i]=i-1,nex[i]=i+1;
	long long ans=0;
	for(int i=n;i>0;i--)
	{
		int j=pos[i];
		ans+=i*1LL*(j-pre[j])*(nex[j]-j);
		pre[nex[j]]=pre[j];
		nex[pre[j]]=nex[j];
	}
	printf("%lld",ans);
}

Measured memory_bytes: 3328
/*
    Take me to church
    I'll worship like a dog at the shrine of your lies
    I'll tell you my sins and you can sharpen your knife
    Offer me that deathless death
    Good God, let me give you my life
*/
#include<bits/stdc++.h>
using namespace std;
const int N = 100005;
int n, m, R[N], M[N];
vector < int > T, Adj[N], Adt[N];
void DFS(int v)
{
    M[v] = 1;
    for (int u : Adj[v])
        if (!M[u]) DFS(u);
    T.push_back(v);
}
int main()
{
    scanf("%d%d", &n, &m);
    for (int i = 1; i <= n - 1 + m; i ++)
    {
        int v, u;
        scanf("%d%d", &v, &u);
        Adj[v].push_back(u);
        Adt[u].push_back(v);
    }
    for (int i = 1; i <= n; i ++)
        if (!M[i]) DFS(i);
    reverse(T.begin(), T.end());
    for (int i = 0; i < n; i ++)
        R[T[i]] = i;
    for (int i = 1; i <= n; i ++)
    {
        int id = i;
        for (int u : Adt[i])
            if (id == i || R[u] > R[id])
                id = u;
        if (id == i)
            id = 0;
        printf("%d\n", id);
    }
    return 0;
}

Measured memory_bytes: 16252
using System;
using System.Linq;
using System.Security.Cryptography.X509Certificates;

namespace AtcoderProblem
{
    class Program
    {
        static void Main(string[] args)
        {
            int i = 0;
            int N = int.Parse(Console.ReadLine());
            int zorori = 0;
            while(i < N)
            {
                string L = Console.ReadLine();
                var stArrayData = L.Split(' ');
                int A1 = int.Parse(stArrayData[0]);
                int A2 = int.Parse(stArrayData[1]);
                if (A1 == A2)
                {
                    zorori++;
                }
                else if (zorori >= 3)
                {
                    zorori++;
                }
                else zorori = 0;
                i++;
            }

            if (zorori >= 3) Console.WriteLine("Yes");
            else Console.WriteLine("No");
        }         
    }
}


Measured memory_bytes: 27356
#include<bits/stdc++.h>
#define N 1005
using namespace std;
const int P=1e9+7;
char a[N],b[N];
int F[N][4][4],p,q,u,v,n,i,ans,st,ed;
void up(int &x){if (x>=P) x-=P;}
int main(){
	scanf("%d",&n);
	scanf("%s",a+1);
	scanf("%s",b+1);
	F[0][0][0]=1;
	for (i=0;i<n;i++){
		if (a[i+1]==b[i+1]){
			for (u=0;u<=3;u++)
	      for (v=0;v<=3;v++)
	        if (F[i][u][v])
	      	  for (p=1;p<=3;p++)
	      	    if (p!=u&&p!=v)
	      	      up(F[i+1][p][p]+=F[i][u][v]);
		}else {
			for (u=0;u<=3;u++)
			  for (v=0;v<=3;v++)
			    if (F[i][u][v])
					  for (p=1;p<=3;p++)
			        for (q=1;q<=3;q++)
			          if (p!=u&&q!=v&&p!=q)
			            up(F[i+2][p][q]+=F[i][u][v]);
			i++;
		}
	}
	  
	for (u=0;u<=3;u++)
	  for (v=0;v<=3;v++)
	    up(ans+=F[n][u][v]);
	printf("%d\n",ans);
}

Measured memory_bytes: 256
N, K = map(int, input().split())
result = 0

for i in range(1, N+1):
    prob = 1
    x = i
    for j in range(i, K):
        if K <= x:
            break
        prob *= 0.5
        x *= 2
    result += prob/N

print('{0:.12f}'.format(result))

Measured memory_bytes: 3060
#include<iostream>
#include<queue>
#include<set>

using namespace std;

#define rep(i, n) for (int i = 0; i < int(n); ++i)

struct Edge {
  int to, cost;
};

vector<Edge> edge[111];
int dis[111][111];

typedef pair<int, pair<int, int> > State;
#define time first
#define pos second.first
#define cap second.second

int main() {
  while (true) {
    int n, m, l, k, a, h;
    cin >> n >> m >> l >> k >> a >> h;
    if (n == 0) break;
    set<int> s;
    rep (i, l) {
      int _s;
      cin >> _s;
      s.insert(_s);
    }
    rep (i, n) edge[i].clear();
    rep (i, k) {
      int x, y, t;
      cin >> x >> y >> t;
      edge[x].push_back((Edge){y, t});
      edge[y].push_back((Edge){x, t});
    }
    rep (i, n) rep (j, m + 1) dis[i][j] = 1e9;
    priority_queue<State, vector<State>, greater<State> > que;
    que.push(make_pair(0, make_pair(a, m)));
    while (!que.empty()) {
      State now = que.top(); que.pop();
      if (now.cap < 0 || m < now.cap) continue;
      if (dis[now.pos][now.cap] <= now.time) continue;
      dis[now.pos][now.cap] = now.time;
      if (s.count(now.pos)) {
	que.push(make_pair(now.time + 1, make_pair(now.pos, now.cap + 1)));
      }
      rep (i, edge[now.pos].size()) {
	que.push(make_pair(now.time + edge[now.pos][i].cost, make_pair(edge[now.pos][i].to, now.cap - edge[now.pos][i].cost)));
      }
    }
    int ans = 1e9;
    rep (i, m + 1) ans = min(ans, dis[h][i]);
    if (ans > 1e8) cout << "Help!" << endl;
    else cout << ans << endl;
  }
  return 0;  
}

Measured memory_bytes: 11940
#include <iostream>

int main() {
    while(true) {
        std::string s{}; std::cin >> s;
        if(s=="-") break;
        int n{}; std::cin >> n;
        for(auto i=0; i<n; i++) {
            int h{}; std::cin >> h;
            s = s.substr(h) + s.substr(0,h);
        }
        std::cout << s << std::endl;
    }
}



Measured memory_bytes: 3160
from sys import stdin
from itertools import repeat
def f(a):
    n = len(a)
    l = [0] * (n + 1)
    st = [(a[0], a[0], 1)]
    pu = st.append
    po = st.pop
    for i in xrange(1, n):
        ad = 0
        y = a[i]
        k = 1
        while st and y > st[-1][0]:
            x, z, q = po()
            c = 0
            while x < y:
                x *= 4
                c += 2
            ad += c * q
            k += q
            y = z << c
        pu((a[i], y, k))
        l[i+1] = l[i] + ad
    return l

def main():
    n = int(stdin.readline())
    a = map(int, stdin.readline().split(), repeat(10, n))
    l = f(a)
    r = f(a[::-1])[::-1]
    ans = 10 ** 12
    for i in xrange(n + 1):
        if ans > l[i] + i + r[i]:
            ans = l[i] + i + r[i]
    print ans
main()


Measured memory_bytes: 36168
#include <algorithm>
#include <array>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>

#define REP(X, Y, Z) for (ll(X) = (Y); (X) < (Z); (X)++)
#define REV(X, Y, Z) for (ll(X) = (Y); (X) > (Z); (X)--)

using namespace std;
using ll = long long;
using dll = deque<ll>;
using pll = pair<ll, ll>;
using qll = queue<ll>;
using usll = unordered_set<ll>;
using umll = unordered_map<ll, ll>;
using sll = stack<int>;
using vll = vector<ll>;
using vvll = vector<vll>;

constexpr ll kMod = 1e9 + 7;

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

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

void init() {
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(15);
}

int main() {
  init();

  string S;
  cin >> S;
  vll V(S.size());
  ll cnt0 = 0;
  ll cnt1 = 0;
  REP(i, 0, S.size()) {
    if (S[i] == '1') {
      V[i] = 1;
      cnt1++;
    } else {
      V[i] = 0;
      cnt0++;
    }
  }

  cout << min(cnt0, cnt1) * 2 << endl;

  return 0;
}


Measured memory_bytes: 1232
import java.io.IOException;
import java.util.Arrays;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) throws IOException {

		new Main().run();
	}

	private void run() throws IOException {
		Scanner scanner = new Scanner(System.in);
		int n = scanner.nextInt();
		int m = scanner.nextInt();
		int p = scanner.nextInt();
		int[] d = new int[m];
		for (int i = 0; i < m; i++) {
			int a = scanner.nextInt();
			d[i] = (a - p + n) % n;
		}
		Arrays.sort(d);
		int ret = Math.min(n - d[0], d[m - 1]);
		for (int i = 0; i < m; i++) {
			if (i > 0)
				ret = Math.min(ret, 2*(n - d[i]) + d[i - 1]);
			if (i < m - 1)
				ret = Math.min(ret, 2 * d[i] + n - d[i + 1]);
		}
		System.out.println(ret * 100);
	}
}

Measured memory_bytes: 34372
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n=sc.nextInt();
		int a[] = new int[n];
		long sum=0;
		int max=-1000000;
		int min=1000000;
		for(int i=0;i<n;i++) {
			a[i]=sc.nextInt();
			sum+=a[i];
			if(max<a[i]) {
				max=a[i];
			}
			if(min>a[i]) {
				min=a[i];
			}
		}
		System.out.println(min +" "+ max +" "+ sum);
	}
}


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

#define INF 0x3f3f3f3f
#define EPS 1e-6
using namespace std;
typedef long long LL;
const int maxn = 1e5 + 10;


int main()
{
    LL n, k;
    while(cin >> n >> k){
        LL mod = n % k;
        cout << min(mod, k - mod) << endl;
    }
}


Measured memory_bytes: 3552
#include <iostream>

using namespace std;

int main(){
  
  int h,w;
  cin >> h >> w;
  char c,x;
  for(int k=0;k<w+2;k++){cout << "#";}
  cout << "\n";
  for(int j=0;j<h;j++){
    cout << "#";
    for(int i=0;i<w;i++){
      cin >> c;
      cout << c;
    }
    cout << "#\n";
  }
    for(int l=0;l<w+2;l++){cout << "#";}
  cout << "\n";
  return 0;
}

Measured memory_bytes: 256
import java.util.*;
 
public class Main {
 
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
 
        int n = sc.nextInt();
  
        int array[] = new int[100100];
 
        for (int i = 0; i < n; i++) {
            int num = sc.nextInt();
            if (num != 0) {
                array[num - 1]++;
            }
            array[num]++;
            array[num + 1]++;
        }

        int max = 0;
 
        for (int i = 0; i < array.length; i++) {
            if (array[i] > max) {
                max = array[i];
            }
        }
 
        System.out.println(max);
 
        sc.close();
 
        }
 
    }

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

int64_t nC2(int64_t x){
  return (x*(x-1))/2;
}

int main(){
  int N; cin >> N;
  vector<int64_t> A(N+1);
  A[0]=0;
  for(int i=1;i<=N;i++){
    int64_t k;
    cin >> k;
    A[i]=A[i-1]+k;
  }
  sort(A.begin(), A.end());
  int64_t count=1;
  int64_t ans=0;
  for(int i=1;i<=N;i++){
    if(A[i]==A[i-1]){
      count++;
    }
    else {
      ans+=nC2(count);
      count=1;
    }
  }
  ans+=nC2(count);
  cout << ans << endl;
}
      
    

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
typedef long long lint;
#define rep(i,n) for(lint (i)=0;(i)<(n);(i)++)
#define repp(i,m,n) for(lint (i)=(m);(i)<(n);(i)++)
#define repm(i,n) for(lint (i)=(n-1);(i)>=0;(i)--)
#define INF (1ll<<60)
#define all(x) (x).begin(),(x).end()
const lint MOD =1000000007;
const lint MAX = 1000000;
using Graph =vector<vector<lint>>;
typedef pair<lint,lint> P;
 
 
lint fac[MAX], finv[MAX], inv[MAX];
 
void COMinit() 
{
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (lint i = 2; i < MAX; i++)
    {
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}
 
long long COM(lint n, lint k)
{
    if (n < k)
        return 0;
    if (n < 0 || k < 0)
        return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
 
lint primary(lint num)
{
    if (num < 2) return 0;
    else if (num == 2) return 1;
    else if (num % 2 == 0) return 0;
 
    double sqrtNum = sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2)
    {
        if (num % i == 0)
        {
            return 0;
        }
    }
 
    return 1;
}
   long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
    lint lcm(lint a,lint b){
        return a/__gcd(a,b)*b;
    }
     lint gcd(lint a,lint b){
        return __gcd(a,b);
    } 
   

  int main(){      
   lint k,a,b;
   string s;

   cin>>k>>a>>b;
    repp(i,a,b+1){
        if(i%k==0){
            cout<<"OK";
            return 0;
        }
    }
    cout<<"NG";
  }
          
  

Measured memory_bytes: 3620
#include <bits/stdc++.h>
#include <algorithm>
#include <string>
using namespace std;
 
int main() {
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    string S;
    cin >> S;
    sort(S.begin(), S.end());
    if (S[0] == S[1] && S[2] == S[3] && S[0] != S[2]) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
    return 0;
}

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

typedef long long ll;
#define rep(i,n) for(int i=0;i<n;i++)

long long modinv(long long a, long long m=MOD) {
    long long b = m, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m; 
    if (u < 0) u += m;
    return u;
    /*MODの割り算の際に
    a/＝b;
    を
    a *= modinv(b,MOD);
    とする。
        */
}

int N;
int K;
#define MAXN 200000
int p[MAXN];
double go = 0;
int ma  = 0;
int maxi = 0;
int maxi_p = 0;

double get_go(int max_p){
    
    double z = 0;
    for(int i=max_p;i<max_p+K;i++){
        z += (double)(p[i]+1)/2;
        
    }
    
    return z;
}

int main(){
    cin >> N >> K;
    
    rep(i,N){
        cin >> p[i];

    }
    for(int i=0;i<K;i++){
        ma += p[i];
        if(ma > maxi){
            maxi = ma;
            maxi_p = 0;
        }
    }
    for(int i=1;i<=N-K;i++){
        ma -= p[i-1];
        ma += p[i+K-1];
        if(ma > maxi){
            maxi = ma;
            maxi_p = i;
        }
    }
    double ans = get_go(maxi_p);
    printf("%0.8f\n",ans);

    return 0;
}

Measured memory_bytes: 1024
#include <stdio.h>
#include <string.h>

int main(){
	
	int i, n, a, result;
	char string[100001];
	int counter[27];
	for( i = 0; i < 27; i++ ){
		counter[i] = 0;
	}
	
	scanf( "%s", string );
	n = strlen(string);
	a = (int)'a';
	for( i = 0; i < n; i++ ){
		counter[ string[i] - a ] += 1;
	}
		
	result = 26;
	for( i = 0; i < 26; i++ ){
		if( counter[i] == 0 ){
			result = i;
			break;
		}
	}
	
	if( result == 26 ){
		printf( "None" );
	}else{
		printf( "%c", (char)(a + result) );
	}
	
	return 0;
	
}

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

using ll = long long;
using ld = long double;
using vi = vector<int>;
using vll = vector<ll>;
using P = pair<int, int>;

constexpr int INF = 1e9;
constexpr ll INFLL = 1e18;
constexpr int MOD = 1e9 + 7;
const ld PI = acosl(-1);

#define rep(i,n) for(int i=0; i<(n); ++i)
#define all(n) n.begin(),n.end()

int main(){
    ios::sync_with_stdio(false); cin.tie(nullptr);
    //cout << fixed << setprecision(6);
    ll x; cin >> x;

    for (int i = 1; i <= 360; i++) {
        if (i*x % 360 == 0) {
            cout << i << endl;
            return 0;
        }
    }
    return 0;
}

Measured memory_bytes: 3580
#include<bits/stdc++.h>
using namespace std;
#define nn 2808
#define lf double
#define mp make_pair
#define ll long long
#define err {puts("No");exit(0);}
#define pii pair<int,int>
vector<int> ops;
vector<int> v[nn];
int vis[nn];int leaf[nn];int prio[nn];
int need[nn];int pa[nn];int dep[nn];
int n;int col[nn];int leaves;
int fullfill[nn];
void dfs(int x)
{
	leaf[x]=2;
	for(int i=0;i<v[x].size();i++)
	{
		if(vis[v[x][i]]==2) continue;
		dep[v[x][i]]=dep[x]+1;
		leaf[x]--;
		dfs(v[x][i]);
		if(!leaf[v[x][i]]) leaf[x]=0;
	}
	leaf[x]=max(leaf[x],0);
	if(leaf[x]) need[x]=1,leaves++;
}
void pushtree(int x)
{
	ops.push_back(x);
	int y=pa[x];int bef=col[x];col[x]=col[1];
	while(y)
	{
		swap(bef,col[y]);
		y=pa[y];
	}
}
pair<int,int> bst;int thrown[nn];
void findbst(int x)
{
	for(int i=0;i<v[x].size();i++)
	{
		if(vis[v[x][i]]==2) continue;
		findbst(v[x][i]);
	}
	if(prio[col[x]] or thrown[col[x]]) ; 
	else bst=max(bst,make_pair(dep[x],x));
	return;
}
int stretch(int x,int t)
{
	while(t--)
	{
		for(int i=0;i<v[x].size();i++)
		{
			if(vis[v[x][i]]!=2)
			{
				x=v[x][i];
				break;
			}  
		}
	}
	return x;
}
int count(int x)
{
	int o=x;
	x=stretch(x,2000);
	while(1)
	{
		if(prio[col[x]]==0 or (dep[col[x]]<dep[o]))
		{
			return x;
		}
		x=pa[x];
	}
}
int loc[nn];
int main()
{
	cin>>n;
	for(int i=2;i<=n;i++)
	{
		cin>>pa[i];
		pa[i]++;
		v[pa[i]].push_back(i);
	}
	for(int i=1;i<=n;i++) cin>>col[i],col[i]++;
	while(1)
	{
		if(vis[1]) break ;
		leaves=0;dfs(1);
		memset(thrown,0,sizeof(thrown));
		while(leaves)
		{
			if(need[col[1]])
			{
				leaves--;
				int t=count(col[1]);
				int x=col[1];
				vis[x]=1;prio[x]=1;
				pushtree(t);
			}
			else
			{
				bst=make_pair(0,0);
				findbst(1);thrown[col[1]]=1;
				pushtree(bst.second);
			}
		}
		int tt=0;
		for(int i=1;i<=n;i++) if(vis[i]) vis[i]=2,tt++;
		if(tt==n) break;
	}
	cout<<ops.size()<<"\n";
	for(int i=0;i<ops.size();i++) printf("%d\n",ops[i]-1);
}

Measured memory_bytes: 768
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/trie_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;
typedef trie<string, null_type, trie_string_access_traits<>, pat_trie_tag, trie_prefix_search_node_update> pref_trie;
typedef unsigned long long BITMASK; typedef long long ll; typedef long double ld; typedef pair<int, int> pii; typedef pair<double, double> pdd; typedef pair<long long, long long> pll;
#define has_bit(bit_mask, x) ((bit_mask) & (1ULL << (x)))
#define turn_on_bit(bit_mask, x) (bit_mask |= (1ULL << (x)))
#define turn_off_bit(bit_mask, x) (bit_mask &= (~(1ULL << (x))))
#define smallest_on_bit(bit_mask) (__builtin_ctzint((bit_mask) & (-(bit_mask))))
#define CLOCK_START clock_t chrono_clk_beg = clock()
#define CLOCK_END clock_t chrono_clk_end = clock(); cerr << (double(chrono_clk_end - chrono_clk_beg) / CLOCKS_PER_SEC) << " sec"
#define bug(args ...) cerr << __LINE__ << ">> ", err(new istringstream(string(#args)), args), cerr << '\n'
#define decToBin(name, num) string name = bitset<8>(num).to_string();
#define binToDec(name, binary) unsigned long name = bitset<8>(binary).to_ulong();
#define radToDeg(name, radians) double name = radians * 180 / M_PI;
#define all(x) x.begin(), x.end()
#define removeDuplicates(vec) sort(vec.begin(), vec.end()); vec.erase(unique(vec.begin(), vec.end()), vec.end())
#define printMat(mat) for (auto &x : mat) { for (auto &y : x) { if (y < INF) cout << setw(7) << y; else cout << setw(7) << "-"; } cout << '\n'; }
#define fillMat(mat, n, m, x) for (int i = 0; i < n; ++i) for (int j = 0; j < m; ++j) mat[i][j] = x;
#define printArr(arr) for (auto &x : arr) cout << x << " "; cout << '\n';
#define arrReplace(arr, from, to) for (auto &x : arr) if (x == from) x = to;
#define INF (1LL<<30)
#define INF32 (1LL<<62)
#define F first
#define S second
#define M_PI 3.14159265358979323846
inline int ceil(int a, int b) { return (a+b-1)/b; }
void err(istringstream *iss) {} template<typename T, typename ... Args> void err(istringstream *iss, const T &_val, const Args & ... args) { string _name; *iss >> _name; if (_name.back()==',') _name.pop_back(); cerr << _name << " = " << _val << "; ", err(iss, args ...); }
int str_replace(string& str, const string& from, const string& to, int limit = -1) { if(from.empty()) return 0; size_t start_pos = 0; int cnt = 0; while((start_pos = str.find(from, start_pos)) != std::string::npos) { str.replace(start_pos, from.length(), to); start_pos += to.length(); cnt++; if (cnt == limit) break; } return cnt; }
#define MOD 1000000007
#define int ll

signed main()
{
	ios_base::sync_with_stdio(false); cin.tie(NULL);
	int n, x, y; cin >> n >> x >> y;
	int res[n] {};
	if (x > y) swap(x, y);
	for (int i = 1; i <= n; ++i)
	{
		for (int j = i+1; j <= n; ++j)
		{
			int dist = min(j-i, abs(i-x) + abs(j-y) + 1);
			res[dist]++;
		}
	}
	for (int i = 1; i < n; ++i) cout << res[i] << '\n';
	return 0;
}

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>;
#define chmax(x,y) x = max(x,y);
#define chmin(x,y) x = min(x,y);
const int di[] = {-1, 0, 1, 0};
const int dj[] = {0, -1, 0, 1};
const int INF = 1001001001;

// 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;}

int main() {
    int n, m;
    cin >> n >> m;
    vector<int> a(n);
    rep(i,m) {
        int x;
        cin >> x;
        a[x]++;
    }
    vector<mint> dp(n+2);
    dp[n] = 1;
    for (int i = n-1; i >= 0; i--) {
        if (a[i]) continue;
        dp[i] = dp[i+1] + dp[i+2];
    }
    cout << dp[0] << endl;
    return 0;
}

Measured memory_bytes: 4584
//
//  main.cpp
//  DPpractice
//
//  Created by abhishek kumar on 20/04/20.
//  Copyright © 2020 abhishek kumar. All rights reserved.
//
 
#include <iostream>
#include<vector>
#include<math.h>
using namespace std;
typedef long long int ll;
const long long int N=1000;
//const int INF=1e9 + 5;
ll n,k,m,temp,arr[N+1][N+1],dp[N+1][N+1],visited[N+1][N+1];
 
 
int main(int argc, const char * argv[]) {
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    cin>>n;
    vector<int> dp(3,0);
    for (auto i=0;i<n;i++) {
        vector<int> new_dp(3,0);
        vector<int> c(3);
        for(auto& it : c) cin>>it;
       
            new_dp[0]=c[0]+max(dp[1],dp[2]);
       new_dp[1]=c[1]+max(dp[0],dp[2]);
         new_dp[2]=c[2]+max(dp[1],dp[0]);
        dp=new_dp;
    }
    
    
    cout<<max(dp[0],max(dp[1],dp[2]));
  
    return 0;
        
}

Measured memory_bytes: 256
#include <functional>
#include <string>
#include <algorithm>
#include <iostream>
#include <vector>
#include <utility>
#include <type_traits>
namespace loquat {
template <int MOD>
class modulus_integer {
public:
	typedef modulus_integer<MOD> self_type;
private:
	int m_value;
	static self_type unsafe_construct(int x) noexcept {
		self_type y;
		y.m_value = x;
		return y;
	}
public:
	modulus_integer() noexcept
		: m_value(0)
	{ }
	modulus_integer(int x) noexcept
		: m_value(x % MOD)
	{
		if(m_value < 0){ m_value += MOD; }
	}
	int operator*() const noexcept { return m_value; }
	self_type& operator=(const self_type& x) noexcept {
		m_value = x.m_value;
		return *this;
	}
	self_type operator*(const self_type& x) const noexcept {
		return unsafe_construct(
			static_cast<long long>(m_value) * x.m_value % MOD);
	}
	self_type& operator*=(const self_type& x) noexcept {
		return (*this = *this * x);
	}
};
template <int MOD>
inline std::ostream& operator<<(
	std::ostream& os, const modulus_integer<MOD>& x)
{
	os << *x;
	return os;
}
}
using namespace std;
static constexpr int MOD = 998244353;
using mint = loquat::modulus_integer<MOD>;
int main(){
	ios_base::sync_with_stdio(false);
	int n;
	cin >> n;
	vector<int> d(n);
	for(int i = 0; i < n; ++i){ cin >> d[i]; }
	vector<int> h(n);
	for(int i = 0; i < n; ++i){ ++h[d[i]]; }
	if(d[0] != 0 || h[0] > 1){
		cout << 0 << endl;
		return 0;
	}
	mint answer = 1;
	for(int i = 1; i < n; ++i){
		for(int j = 0; j < h[i]; ++j){
			answer *= mint(h[i - 1]);
		}
	}
	cout << answer << endl;
	return 0;
}


Measured memory_bytes: 1024