akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define all(a) (a).begin(), (a).end()
using namespace std;
using Graph = vector<vector<int>>;
typedef pair<int, int> P;
typedef long long ll;

int main()
{
    int h, w;
    cin >> h >> w;
    vector<vector<char>> g(h, vector<char>(w));

    rep(i, h) rep(j, w) cin >> g[i][j];

    vector<bool> tate(w, false);
    vector<bool> yoko(h, false);

    rep(i, h)
    {
        rep(j, w)
        {
            if (g[i][j] == '#')
            {
                yoko[i] = true;
                tate[j] = true;
            }
        }
    }

    rep(i, h){
        if (yoko[i]){
            rep(j, w){
                if (tate[j]){
                    cout << g[i][j];
                }
            }
            cout << endl;
        }
    }
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner scanner = new Scanner(System.in);
		
		final double coutner = scanner.nextInt();
		final double t = scanner.nextInt();
		final double a = scanner.nextInt();
		
		double result = 1000000000;
		int r = 0;
		
		for(int i = 0;i<coutner;i++) {
			double d;
			if((d = Math.abs(t - scanner.nextInt() * 0.006 - a)) < result) {
				result = d;
				r =  i + 1;
			}
		}
		System.out.println(r);
		
	}

}

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

using namespace std;

#define ll long long

ll n,a,b,c,d;
ll cost;

int main()
{
    cin>>a>>b>>c>>d>>n;
    if(n>=2)
    {
        ll val;
        val=d;
        val=min(val,d);
        val=min(val,2*c);
        val=min(val,4*b);
        val=min(val,8*a);
        int x=n/2;
        cost+=x*val;
        n%=2;
    }
    if(n==1)
    {
        ll val;
        val=c;
        val=min(val,2*b);
        val=min(val,4*a);
        cost+=val;
    }
    cout<<cost;
    return 0;
}
/**
**/


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

#define dump(n) cout<<"# "<<#n<<'='<<(n)<<endl
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define peri(i,a,b) for(int i=int(b);i-->int(a);)
#define rep(i,n) repi(i,0,n)
#define per(i,n) peri(i,0,n)
#define all(c) begin(c),end(c)
#define mp make_pair
#define mt make_tuple

typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<string> vs;

const int INF=1e9;
const int MOD=1e9+7;
const double EPS=1e-9;

template<typename T1,typename T2>
ostream& operator<<(ostream& os,const pair<T1,T2>& p){
	return os<<'('<<p.first<<','<<p.second<<')';
}
template<typename T>
ostream& operator<<(ostream& os,const vector<T>& a){
	os<<'[';
	rep(i,a.size()) os<<(i?" ":"")<<a[i];
	return os<<']';
}

struct Edge{
	int src,dst,weight,count;
	Edge(){}
	Edge(int s,int d,int w,int c=0):src(s),dst(d),weight(w),count(c){}
};
typedef vector<vector<Edge>> Graph;
bool operator<(const Edge& a,const Edge& b){return a.weight<b.weight;}
bool operator>(const Edge& a,const Edge& b){return a.weight>b.weight;}

int main()
{
	for(int n,m,c;cin>>n>>m>>c && n|m|c;){
		Graph g(n);
		rep(i,m){
			int u,v,w; cin>>u>>v>>w; u--,v--;
			g[u].emplace_back(u,v,w);
		}
		vvi dist(n,vi(n,INF));
		priority_queue<Edge,vector<Edge>,greater<Edge>> pq;
		pq.emplace(-1,0,0,0);
		while(pq.size()){
			Edge cur=pq.top(); pq.pop();
			if(dist[cur.dst][cur.count]<=cur.weight) continue;
			dist[cur.dst][cur.count]=cur.weight;
			for(Edge e:g[cur.dst]){
				pq.emplace(e.src,e.dst,cur.weight+e.weight,cur.count);
				if(cur.count==n-1) continue;
				pq.emplace(e.src,e.dst,cur.weight,cur.count+1);
			}
		}
		rep(i,n) if(dist[n-1][i]<=c){
			cout<<i<<endl;
			break;
		}
	}
}

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

using namespace std;

int main() {
	map<char, char> mapping{
		{'A', 'T'},
		{'T', 'A'},
		{'C', 'G'},
		{'G', 'C'}
	};
	
	char in;
	cin >> in;
	
	cout << mapping[in];
	
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <queue>
#include <map>
#include <numeric>
#include <unordered_map>
#include <iomanip>
#include <functional>
#include <bitset>
#include <complex>
#include <stack>



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

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

typedef long long ll;

using namespace std;

int man(int x,int y,int p,int q){
  return abs(x-p)+abs(y-q);
}
int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n,m;
  cin>>n>>m;
  vector<int>x(n),y(n),c(m),d(m);
  rep(i,n){
    cin>>x[i]>>y[i];
  }
  rep(i,m){
    cin>>c[i]>>d[i];
  }
  rep(i,n){
    vector<int>id(m);
    rep(i,m)id[i]=i;
    sort(all(id),[&](int a,int b){return man(c[a],d[a],x[i],y[i])<man(c[b],d[b],x[i],y[i]);});
    cout<<id[0]+1<<endl;
  }

  return 0;

}


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

template<class Container>
auto print(const Container&c) {
	auto it = std::begin(c);
	auto end_ = std::end(c);
	if (it != end_) {
		std::cout << (*it);
		++it;
	}
	for (; it != end_; ++it) {
		std::cout << " " << (*it);
	}std::cout << "\n";
}


template<class Container>
auto bubble_sort(Container*const c) {
	return bubble_sort(c, [](auto x, auto y)->bool {
		return y < x;
	});
}

template<class Container,class F>
auto bubble_sort(Container*const c,F f) {
	auto it = std::begin(*c);
	auto end_ = std::end(*c);
	auto times = end_ - it;
	int c_{ 0 };
	for (int i{ 0 }; i < times; i++) {
		for (long int j{ times - 1 }; j > i ; j--) {
			auto &x = *(it + j - 1);
			auto &y = *(it + j);
			if ( f(x,y) ) {
				std::swap(x, y);
				c_++;
//				std::cout << x << " " << y << "\n";
			}
		}
//		print(*c);
	}
	return c_;
}


template<class Container>
auto selection_sort(Container*const con) {
	return selection_sort(con, [](auto x, auto y) {
		return x > y;
	});
}

template<class Container,class F>
auto selection_sort(Container*const con, F f) {
	auto it = std::begin(*con);
	auto end_ = std::end(*con);
	auto times = end_ - it;

	int c{ 0 };
	for (int i{ 0 }; i < times; i++) {
		int min_ = i;

		for (int j{ i }; j < times; j++) {
			auto& x = *(it + min_);
			auto& y = *(it + j);
			if ( f(x, y) ){
				min_ = j;
			}
		}
		if (min_ == i)continue;
//		std::cout << *(it + min_) << "\n";
		std::iter_swap(it + min_, it + i);
		c++;
//		print(*con);
	}
	return 0;
}

template<class Container,class F>
auto is_stable(const Container &base, const Container& con,F f) {
	bool result{ true };


	using vec = std::vector<typename Container::value_type>;
	for (auto&e : base) {

		auto bit = std::begin(base);
		auto bend = std::end(base);

		auto cit = std::begin(con);
		auto cend_ = std::end(con);

	
		vec v1, v2;

		while (bit != bend) {
			if( f(*bit, e) ){
				v1.emplace_back(*bit);
			}
			++bit;
		}

		while (cit != cend_) {
			if ( f( *cit, e) ){
				v2.emplace_back(*cit);
			}
			++cit;
		}

		for (unsigned i{ 0 }; i < v1.size(); i++) {
			if (!(v1[i]== v2[i])) {//文字列を比較する。
	//			std::cout << v1[i] << " " << v2[i] << "\n";
				return false;
			}
	//		std::cout << v1[i] << " " << v2[i] << "\n";

		}
//		print(v1);
//		print(v2);
		
	}

	return result;
}

int main() {
	int N{};
	std::cin >> N;
	std::vector<std::string> vs;

	for (int i{ 0 }; i < N; i++) {
		std::string tmp;
		std::cin >> tmp;
		vs.emplace_back(tmp);
	}
	auto vs1 = vs;
	auto vs2 = vs;

	auto comp = [](auto x, auto y)->bool {
		auto a = x[1];
		auto b = y[1];
		return a > b;
	};

	auto comp2 = [](auto x, auto y)->bool {
		return x[1] == y[1];
	};//sortしたものを比較する。

	auto x = bubble_sort(&vs1, comp);
	print(vs1);
	std::cout << (is_stable(vs, vs1, comp2) ? "S" : "Not s") << "table\n";

	auto y = selection_sort(&vs2, comp);
	print(vs2);
	std::cout << (is_stable(vs, vs2,comp2) ? "S" : "Not s")<<"table\n";

	std::cin >> N;

}


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

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

#define FOR(i, n, m) for (ll(i) = (m); (i) < (n); ++(i))
#define REP(i, n) FOR(i, n, 0)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll)1e15;

ll V[105];
ll U[105];

ll dp[105][10005];

int main()
{
    ll N, W;
    cin >> N >> W;
    ll v = 0;
    REP(i, N)
    {
        cin >> V[i] >> U[i];
        v += V[i];
    }
    REP(i, N + 1)
    {
        REP(j, v + 1)
        {
            dp[i][j] = INF;
        }
    }
    dp[0][0] = 0;
    REP(i, N)
    {
        REP(j, v + 1)
        {
            dp[i + 1][j] = dp[i][j];
            if (j - V[i] < 0)
                continue;
            dp[i + 1][j] = std::min(dp[i + 1][j], dp[i][j - V[i]] + U[i]);
        }
    }

    REP(i, v + 1)
    {
        if (dp[N][v - i] > W)
            continue;
        cout << v - i << endl;
        break;
    }
    return 0;
}


Measured memory_bytes: 10908
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <tuple>
using namespace std;

int main(){

    int n; cin >> n;

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

    sort(a, a+3*n, greater<long long>());

    // for(int i=0; i<3*n; i++){
    //     cout << a[i];
    // }

    long long a2[n];
    for(int i=0; i<n; i++){
        a2[i] = a[2*i+1];
    }

    cout << accumulate(a2, a2+n, 0LL);

    return 0;
}

Measured memory_bytes: 3328
(defun prime-array (n) ;素数列
  (let ((arr (make-array (1+ n) :element-type 'bit :initial-element 1)))
    (setf (aref arr 0) 0)
    (setf (aref arr 1) 0)
    (loop :for q :from 1 :upto n :do(if (= 1 (aref arr q))
                                        (loop :for a :from (* 2 q) :upto n :by q :do(setf (aref arr a) 0))))
    arr))
(let* ((n (read))
       (m (prime-array 1000000)))
  (princ (+ (position 1 (subseq m n) :test #'=) n)))


Measured memory_bytes: 18020
import java.io.IOException;
import java.util.Scanner;


public class Main {

	public static void main(String[] args) throws IOException {
		//File fi=new File("file.txt");

		Scanner sc=new Scanner(System.in);
		int t=sc.nextInt();
		 String type;
		 int x;
		 int[][] tp=new int[4][14];
		for(int i=0;i<t;i++){
			type=sc.next();
			x=sc.nextInt();
			if(type.equals("S")){tp[0][x]=1;}
			else if(type.equals("H")){tp[1][x]=1;}
			else if(type.equals("C")){tp[2][x]=1;}
			else if(type.equals("D")){tp[3][x]=1;}
			
		}sc.close();
		for(int i=0;i<4;i++){
			for(int l = 1;l<14;l++){
				if(tp[i][l]==0){
					if(i==0)System.out.print("S ");
					else if(i==1)System.out.print("H ");
					else if(i==2)System.out.print("C ");
					else System.out.print("D ");
					System.out.println(l);
				}
			}
		}
		
		
		// TODO 自動生成されたメソッド・スタブ

	}

}

Measured memory_bytes: 18212
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ABC127_B
{
    class Program
    {
        static void Main(string[] args)
        {
            var rDx = Console.ReadLine().Split().Select(long.Parse).ToArray();
            var r = rDx[0];
            var D = rDx[1];
            var x = rDx[2];

            long newX = x;
            for (long i = 0; i < 10; i++)
            {
                newX = r * newX - D;
                Console.WriteLine(newX);
            }
        }
    }
}


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

#define pb push_back
#define mp make_pair
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef complex<double> point;
typedef double DOUBLE;
#define xx real()
#define yy imag()

#define REP(i, a, b) for(int i = (a); i < (int)(b); i++)
#define REPN(i, a, b) for(int i = (a); i <= (int)(b); i++)
#define FA(it, x) for(__typeof((x).begin()) it = (x).begin(); it != (x).end(); it++)
#define SZ(x) (int)(x).size()
#define BE(x) (x).begin(), (x).end()
#define SORT(x) sort(BE(x))
#define _1 first
#define _2 second

#define x1 gray_cat_x1
#define y1 gray_cat_y1

template<class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

#define file "I1"

const double EPS = 1e-9;
const double PI = acos(-1.);
const ll LL_INF = 1e17 + 10;
const int INF = 1e9 + 10;
const ll MOD = 1e9 + 7;

const int MAXN = 2e5 + 5;

void solve(){
	int n, k, s;
	cin >> n >> k >> s;
	REP(i, 0, k) {
		printf("%d ", s);
	}
	REP(i, k, n) {
		int v = (s == 1000000000 ? s - 1 : s + 1);
		printf("%d ", v);
	}
}

int main(){

    //freopen(file".in", "r", stdin); freopen(file".out", "w", stdout);
    int t = 1;
    //cin >> t;
    while(t--){
        solve();    
    }
}


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

int main() {
	int n;
	cin >> n;
	vector<ll> a(n);
	map<ll, ll> mp;
	ll ans = 0;
	for (int i = 0; i < n; ++i) {
		cin >> a[i];
		mp[a[i]]++;
	}
	for (auto i : mp) ans += i.second * (i.second - 1) / 2;
	for (int i = 0; i < n; ++i) {
		if (mp[a[i]] < 2) cout << ans << endl;
		else cout << ans - mp[a[i]] + 1 << endl;
	}
}

Measured memory_bytes: 12288
#include <stdio.h>

int main(void) {
  int a, b, i, j, ans = 0;
  scanf("%d%d", &a, &b);
  for(i = a; i <= b; ++i) 
    if(i % 10 == i / 10000 && (i % 100) / 10 == (i % 10000) / 1000) ans++;
  printf("%d", ans);
  return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;typedef long long ll;typedef vector<ll> vl;typedef vector<vl> vvl;typedef pair<ll,ll> pl;typedef vector<pl> vp;const ll INF=1001001001;const ll LINF=1001001001001001001;const ll D4[]={0,1,0,-1,0};const ll D8[]={0,1,1,0,-1,-1,1,-1,0};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;}
#define fore(i,a,b) for(ll i=(ll)(a);i<=(ll)(b);++i)
#define rep(i,n) fore(i,0,(n)-1)
#define all(x) (x).begin(),(x).end()

void solve(long long L){
    double a=L/3.0;
    printf("%.10f\n",a*a*a);
}

int main(){
    long long L;
    scanf("%lld",&L);
    solve(L);
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using P = pair<int, int>;
#define PI acos(-1)
#define Mod (int)1000000007
#define INFTY (int)INT_MAX
#define Rep(i, n) for (int i = 0; i < (int)(n); i++)
#define BitRep(i, n) for (int i = 0; i < (int)(1 << n); i++)
#define All(vec) vec.begin(), vec.end()
#define Part(vec, b, e) vec.begin() + b, vec.begin() + e
#define Sum(vec) accumulate(vec.begin(), vec.end(), 0)
#define Sort(vec) sort(vec.begin(), vec.end())
#define Reverse(vec) reverse(vec.begin(), vec.end())
#define Count(vec, x) count(vec.begin(), vec.end(), x)
#define Next_permutation(vec) next_permutation(vec.begin(), vec.end())
#define Find(vec, s) vec.find(s) != vec.end()
#define Set_union(A, B, res) set_union(A.begin(), A.end(), B.begin(), B.end(), inserter(res, res.end()));
#define Set_intersection(A, B, res) set_intersection(A.begin(), A.end(), B.begin(), B.end(), inserter(res, res.end()));
#define Set_difference(A, B, res) set_difference(A.begin(), A.end(), B.begin(), B.end(), inserter(res, res.end()));
#define Set_symmetric_difference(A, B, res) set_symmetric_difference(A.begin(), A.end(), B.begin(), B.end(), inserter(res, res.end()));

int main() {
	int N, M;
	cin >> N >> M;
	cout << ((N - M) * 100 + M * 1900) * pow(2, M) << endl;
	return 0;
}

Measured memory_bytes: 4248
#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::*;
#[allow(unused_imports)]
use std::io::*;
#[allow(unused_imports)]
use std::iter;
#[allow(unused_imports)]
use std::mem::*;
#[allow(unused_imports)]
use std::str::*;
#[allow(unused_imports)]
use std::usize;

#[allow(unused_macros)]
macro_rules! read_cols {
    ($($t:ty),+) => {{
        let mut line = String::new();
        stdin().read_line(&mut line).unwrap();

        let mut it = line.trim()
            .split_whitespace();

        ($(
            it.next().unwrap().parse::<$t>().ok().unwrap()
        ),+)
    }}
}

#[allow(dead_code)]
fn read<T: FromStr>() -> T {
    let mut line = String::new();
    stdin().read_line(&mut line).unwrap();
    line.trim().to_string().parse().ok().unwrap()
}

#[allow(dead_code)]
fn read_vecl<T: FromStr>(n: usize) -> Vec<T> {
    let mut v = vec![];
    for _ in 0..n {
        v.push(read::<T>());
    }

    v
}

#[allow(dead_code)]
fn read_vec<T: FromStr>() -> Vec<T> {
    let mut line = String::new();
    stdin().read_line(&mut line).unwrap();

    line.trim()
        .split_whitespace()
        .map(|s| s.parse().ok().unwrap())
        .collect()
}

fn main() {
    let (n, h) = read_cols!(usize, usize);

    let ab: Vec<_> = (0..n).map(|_| (read_cols!(usize, usize))).collect();

    let ma = ab.iter().map(|&(a, _)| a).max().unwrap();
    let bb: Vec<_> = ab.iter().map(|&(_, b)| b).filter(|&b| b > ma).collect();

    let bs: usize = bb.iter().sum();
    let ans = if bs <= h {
        bb.len() + (h - bs + ma - 1) / ma
    } else {
        let mut bb = bb;
        bb.sort();
        bb.iter().rev().scan(0, |sum, &b| { *sum += b; Some(*sum) }).filter(|&sum| sum < h).count() + 1
    };

    println!("{}", ans);
}


Measured memory_bytes: 6396
using System;
using System.Collections.Generic;
using System.Text;

namespace AtTest.D_Challenge
{
    class ABC_044
    {
        static void Main(string[] args)
        {
            Method(args);
            Console.ReadLine();
        }

        static void Method(string[] args)
        {
            long n = ReadLong();
            long s = ReadLong();
            if (n == s)
            {
                Console.WriteLine(n + 1);
                return;
            }

            long sqrt = (long)Math.Sqrt(n);

            for(long i = 2; i <= sqrt; i++)
            {
                long val = 0;
                long nn = n;
                while (nn > 0)
                {
                    val += nn % i;
                    nn /= i;
                }
                if (val == s)
                {
                    Console.WriteLine(i);
                    return;
                }
            }
            for (long i = Math.Min(sqrt, s); i >= 1; i--)
            {
                long margin = s - i;
                if (n - margin < 0) continue;

                if ((n - margin) % i == 0)
                {
                    long val = (n - margin) / i;
                    if (i==val
                        ||val <= margin) continue;

                    Console.WriteLine((n - margin) / i);
                    return;
                }
            }
            Console.WriteLine(-1);
        }

        private static string Read() { return Console.ReadLine(); }
        private static int ReadInt() { return int.Parse(Read()); }
        private static long ReadLong() { return long.Parse(Read()); }
        private static double ReadDouble() { return double.Parse(Read()); }
        private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); }
        private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); }
        private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); }
    }
}


Measured memory_bytes: 13268
#include <iostream>
#include <vector>

using namespace std;

int main()
{
	int N, L, pos;
	bool b = true;
	cin >> N >> L;
	vector<int> a(N);

	cin >> a[0];
	for (int i = 1;i < N;i++)
	{
		cin >> a[i];
		if ((a[i] + a[i - 1]) >= L)
		{
			pos = i;
			b = false;
		}
	}

	if (b) cout << "Impossible" << endl;
	else
	{
		cout << "Possible" << endl;
		for (int i = 1;i < pos;i++)
			cout << i << endl;
		for (int i = N - 1;i > pos;i--)
			cout << i << endl;
		cout << pos << endl;
	}

	return 0;
}


Measured memory_bytes: 1152
//============================================================================
// Name        : JOI.cpp
// Author      : Akari Fujii
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <iostream>
using namespace std;

int main() {


	int n;
	int m;
	int w[51]={};
	int b[51]={};
	int r[51]={};
	int d1,d2,d3;
	int total;
	char chr;

	cin>>n>>m;
	total=n*m;
	for(int i=1; i<n+1; i++){
		for(int j=1; j<m+1; j++){
			cin>>chr;

			if(chr=='W'){
				w[i]+=1;
			}else if(chr=='B'){
				b[i]+=1;
			}else if(chr=='R'){
				r[i]+=1;
			}
		}
	}
	for(int i=1; i<n-1; i++){
		d1+=m-w[i];
		d2=d1;
		for(int j=i+1; j<n; j++){
			d2+=m-b[j];
			d3=d2;
			for(int k=j+1; k<n+1; k++){
				d3+=m-r[k];
			}
			if(total>d3){
				total=d3;
			}
		}
	}

	cout<<total<<endl;



}

Measured memory_bytes: 3076
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#define _GLIBCXX_DEBUG
#define INF 100000010
 #define PI 3.14159265359

using namespace std;
const int64_t mod = 1000000007;
const int64_t tmpMod = 998244353;

int main() {
 
  int64_t N,x,t;
  cin>>N>>x>>t;
  //vector<int64_t> A(N);
  //for(int i=0; i<N; i++){cin>>A[i];}
  //vector<vector<int> > A(N,vector<int>(M));
  //for(int i=0; i<N; i++){
  //   for(int j=0; j<M; j++){
  //       cin>>A[i][j];
  //   }
  // }
  //sort(A.begin(),A.end());
  //for (int i = 0; i < N; i++) { maximum = max(maximum , A[i]);}
  //for (int i = 0; i < N; i++) { minimum = min(minimum , A[i]);}
  if( N%x==0)cout<<(N/x)*t<<endl;
  else cout<<((N/x)+1)*t<<endl;
  // if(N%(x*t)==0)cout << N/(x*t) << endl;
  // else cout << N/(x*t)+1 << endl;
}

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

int main(){
  string s;
  cin>>s;
 if(s=="SUN"){
    cout<<7<<endl;
  }
 else if(s=="MON"){
    cout<<6<<endl;
 }
 else if(s=="TUE"){
    cout<<5<<endl;
 }
else if(s=="WED"){
    cout<<4<<endl;
 }
 else if(s=="THU"){
    cout<<3<<endl;
 }
  else if(s=="FRI"){
    cout<<2<<endl;
 }
 else{
   cout<<1<<endl;
 }
return 0;
}


Measured memory_bytes: 256
#include <cstdio>
using namespace std;
#define MOD 1000000007
int a[2007];
int main(){
	register int n, k, i, j, ans = 0;
	scanf("%d %d", &n, &k);
	for (i = 0; i < n; ++i) scanf("%d", &a[i]);
	for (i = 0; i < n; ++i) {
		for (j = i + 1; j < n; ++j) {
			if (a[i] < a[j]) ans = (ans + 1ll * k * (k - 1) / 2) % MOD;
			else if (a[i] > a[j]) ans = (ans + 1ll * k * (k + 1) / 2) % MOD;
		}
	}
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <set>
#include <map>
using namespace std;
typedef long long ll;
typedef vector<int> VI;
typedef vector< vector<int> > VVI;
typedef pair<int,int> P;
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(a) (a).begin(),(a).end()

int main(){
  string S;
  cin>>S;
  string SS[7]={"SUN","MON","TUE","WED","THU","FRI","SAT"};
  rep(i,7){
    if(S==SS[i]){
      cout<<7-i<<endl;
    }
  }
}

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

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int count = 0;
        int n = sc.nextInt();
        int k = sc.nextInt();
        Integer[] input = new Integer[n];
        for (int i = 0; i < n; i++) {
            input[i] = sc.nextInt();
        }
        Arrays.sort(input, Comparator.reverseOrder());
        int max = Integer.MAX_VALUE;
        for (int i = k - 1; i < n; i++) {
            if (input[i - (k - 1)] - input[i] < max) {

                max = input[i - (k - 1)] - input[i];
            }
            if (max == 0)
                break;
        }
        System.out.println(max);
    }
}

Measured memory_bytes: 62804
#include <stdio.h>

int main(void){

  long w,a,b;
  scanf("%ld %ld %ld", &w, &a, &b);
  long answer;
  if (b+w < a) {
    answer = a-b-w;
  } else if (b > a+w) {
    answer = b-a-w;
  } else {
    answer = 0;
  }
  printf("%ld\n", answer);

  return 0;
}

Measured memory_bytes: 128
#include <iostream>
using namespace std;
int n,tot;
int f(int n){
    tot=0;
    while(n){
        tot+=n%10;
        n/=10;
    }
    return tot;
}
int main(void){
    cin>>n;
    if(n%f(n)==0){
        cout<<"Yes"<<endl;
    }
    else cout<<"No"<<endl;
}


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

bool solve() {
  int N, A, B, C, D;
  cin >> N >> A >> B >> C >> D;
  string S; cin >> S;
  // B -> D
  rep(i, B, D) {
    if(S[i-1] == '#' && S[i] == '#') return false;
  }
  // A -> C
  rep(i, A, C) {
    if(S[i-1] == '#' && S[i] == '#') return false;
  }
  if(C < D) return true;
  // A が B を飛び越える
  // B - C 間
  int mx = 0;
  int cnt = 0;
  rep(i, B-2, min(N, D + 1)) {
    if(S[i] != '#') cnt++;
    else cnt = 0;
    mx = max(mx, cnt);
  }
  if(mx >= 3) return true;
  else return false;
}

int main() {
  cout << (solve() ? "Yes" : "No") << endl;
  return 0;
}


Measured memory_bytes: 640
#include <iostream>
#include <map>
using namespace std;
int main() {
	int n;
	cin >> n;
	map<long long, int> mp;
	long long sum = 0;
	mp[0]++;
	for (int i = 0; i < n; i++) {
		int a;
		cin >> a;
		sum += a;
		mp[sum]++;
	}
	long long ans = 0;
	for (auto &x : mp)
		ans += (x.second - 1ll) * x.second / 2;
	cout << ans << endl;
}

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

int main(){
    int l,r,d;
    cin >> l >> r >> d;

    int ans = (r-l)/d;

    if(r%d == 0 || l%d == 0){
        ans++;
    }
  
    cout << ans << endl;
    return 0;
}

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

int main() {

  ios::sync_with_stdio(false);
  cout.tie(nullptr);
  cin.tie(nullptr);

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

  int ans = 0;
  ans += (n * (n-1)) / 2;
  ans += (m * (m-1)) / 2;

  cout << ans << '\n';
}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <unordered_map>
#include <vector>
#include <string.h>
#include <set>
#include <stack>

using namespace std;

#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl

template<class T> void printvec(const vector<T>& v) {
  for (auto x : v) { cout << x << " "; }
  cout << endl;
}
template<class T> void printtree(const vector< vector<T> >& tree) {
  for (long long i = 0; i < tree.size(); ++i) {
    cout << i + 1 << ": "; printvec(tree[i]);
  }
}
template<class T, class U> void printmap(const map<T, U>& mp) {
  for (auto x : mp) { cout << x.first << "=>" << x.second << endl; }
}

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

#define rep(i, n) for(ll i = 0; i < n; ++i)
#define all(s) s.begin(), s.end()
#define sz(x) (ll)(x).size()
#define fr first
#define sc second
#define mp make_pair
#define pb push_back
#define eb emplace_back

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> triple;
typedef double D;
typedef vector<ll> vl;
typedef vector<P> vp;

const ll INF = 1e9;
const ll MOD = 1000000007;  // 1e9 + 7

int main(int argc, char** argv) {
  cin.tie(NULL);
  cout.tie(NULL);
  ios_base::sync_with_stdio(false);
  //cout << setprecision(10) << fixed;

  ll r,g,b;
  cin >> r >> g >> b;
  ll k;
  cin >> k;
  ll cnt = 0;
  while (g <= r) {
    g *= 2;
    ++cnt;
  }
  while (b <= g) {
    b *= 2;
    ++cnt;
  }
  if (cnt <= k) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}


Measured memory_bytes: 3644
#include <bits/stdc++.h>
#include <vector>
#include <string>

using namespace std;

vector<string> split(const string &s, char delim) {
  vector<string> elems;
  string item;
  for (char ch: s) {
    if (ch == delim) {
      if (!item.empty()) {
        elems.push_back(item);
      }
      item.clear();
    }
    else {
      item += ch;
    }
  }
  if (!item.empty()) {
    elems.push_back(item);
  }
  return elems;
}

string to_str_with_zero(int i, int w) {
  ostringstream sout;
  sout << std::setfill('0') << std::setw(w) << i;
  string s = sout.str();
  return s;
}

int letter_to_int(char c) {
  return tolower(c) - 'a';
}

bool array_equal(vector<int> a1, vector<int>a2) {
  if (a1.size() != a2.size()) {
    return false;
  }
  for (int i=0; i<a1.size(); i++) {
    if (a1.at(i) != a2.at(i)) {
      return false;
    }
  }
  return true;
}

int gcd(int a, int b) {
  if (a == b) {
    return a;
  }
  else if (a > b) {
    return gcd(a - b, b);
  }
  else {
    return gcd(a, b - a);
  }
}

int main() {
  std::cout << std::setprecision(9);
  int n;
  cin >> n;

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

  int q;
  cin >> q;
  for (int i=0; i<q; i++) {
    int b, c;
    cin >> b >> c;
    sum += a_count.at(b) * (c - b);
    a_count.at(c) += a_count.at(b);
    a_count.at(b) = 0;
    cout << sum << endl;
  }
}

Measured memory_bytes: 3784
#include<iostream>
#include<algorithm>
#include<vector>
#include<stack>
#include<queue>
#include<list>
#include<string>
#include<cstring>
#include<cstdlib>
#include<cstdio>
//#include<cmath>
using namespace std;

int main(void)
{
	int i = 0, sum = 0, k = 0, a, b;
	string s;
	stack<int> S;
	stack<pair<int,int> > A;
	cin >> s;
	while (i != s.size()) {
		switch (s[i]) {
		case '\\':S.push(i); break;
		case '_':i++; continue;
		case '/':
			if (!S.empty()) {
				sum += i - S.top();
				A.push(make_pair(S.top(), i - S.top()));
				S.pop();
			}
		}
		i++;
	}
	cout << sum << endl;
	vector<pair<int,int> > V;
	for (; !A.empty(); ) {
		if (V.empty()) {
			V.push_back(make_pair(A.top().first, A.top().second));
			A.pop();
		}
		else {
			if (A.top().first > V[k].first&&A.top().first + A.top().second < V[k].second + V[k].first) {
				V[k].second += A.top().second;
				A.pop();
			}
			else {
				k++;
				V.push_back(make_pair(A.top().first, A.top().second));
				A.pop();
			}
		}
	}
	if (!V.empty()) {
		cout << k + 1;
		i = 0;
		for (int j = k; j >= 0; j--) {
			cout << " " << V[j].second;
		}
		cout << endl;
	}
	else
		cout << k << endl;
	return 0;
}


Measured memory_bytes: 3296
#include<bits/stdc++.h>
#include<unordered_set>
#include<unordered_map>
#include <iostream>
#include <string>
#include <cmath>
using namespace std;
#define ll long long
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define FORR(i,a,b)for(ll i=(a);i<=(b);i++)
#define repR(i,n) for(ll i=n;i>=0;i--)
#define all(v)(v).begin(),(v).end()
#define rall(v)(v).rbegin(),(v).rend()
#define F first
#define S second
#define pb push_back
#define pu push
#define COUT(x) cout<<(x)<<endl
#define PQ priority_queue<ll>
#define PQR priority_queue<ll,vector<ll>,greater<ll>>
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define mp make_pair
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define sz(x) (int)(x).size()
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const ll MOD = 1000000007LL;
const ll INF = 1LL << 60;
using vll = vector<ll>;
using vb = vector<bool>;
using vvb = vector<vb>;
using vvll = vector<vll>;
using vstr = vector<string>;
using pll = pair<ll, ll>;
using vc = vector<char>;
using vvc = vector<vc>;
ll dx[4]={0,1,0,-1};
ll dy[4]={1,0,-1,0};
int main(){
  ll n;
  vvll a(3,vll(3));
  rep(i,3) rep(j,3)cin>>a[i][j];
  cin>>n;
  vvb c(3,vb(3,false));
  vll b(n);
  rep(i,n){
   cin>>b[i];
    rep(r,3){
      rep(j,3){
        if(a[r][j]==b[i]){
          c[r][j]=true;
          continue;
        }
      }
    }
  }
  rep(i,3){
    if(c[i][0]&&c[i][2]&&c[i][1]){
      COUT("Yes");
      return 0;
    }
  }
  rep(i,3){
    if(c[0][i]&&c[1][i]&&c[2][i]){
      COUT("Yes");
      return 0;
    }
  }
  if(c[0][0]&&c[1][1]&&c[2][2]){
    COUT("Yes");
    return 0;
  }
  if(c[0][2]&&c[1][1]&&c[0][2]){
    COUT("Yes");
    return 0;
  }
  COUT("No");
}

Measured memory_bytes: 256
/*raghav0307 - Raghav Gupta*/

#include <bits/stdc++.h>
using namespace std;

#define ff first
#define ss second
#define pb push_back
#define fast_io() ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

typedef long long ll;

// #define left 0
// #define right 1
// #define up 2
// #define down 3

int main(){
	fast_io();
	
	int h, w, n;
	cin >> h >> w >> n;
	int x, y;
	cin >> x >> y;
	string s;	cin >> s;
	string t; 	cin >> t;

	int lefts = 0, rights = 0, ups = 0, downs = 0;
	int leftt = 0, rightt = 0, upt = 0, downt = 0;

	for(int i = 0; i < n; i++){
		// cout << "i is " <<  i << "\n";
		// cout << "left s " << lefts << " right " << rights << " up " << ups << " downs " << downs << "\n";
		// cout << "left t " << leftt << " right " << rightt << " up " << upt << " downs " << downt << "\n";
		if(s[i] == 'L'){
			if(rights == 0) leftt++;
			else rights--;
			if(y - leftt < 1){
				cout << "NO\n";
				return 0;
			}
		}
		if(s[i] == 'R'){
			if(lefts == 0)	rightt++;
			else lefts--;
			if(y + rightt > w){
				cout << "NO\n";
				return 0;
			}
		}
		if(s[i] == 'U'){
			if(downs == 0)	upt++;
			else downs--;
			if(x-upt < 1){
				cout << "NO\n";
				return 0;
			}
		}
		if(s[i] == 'D'){
			if(ups == 0)	downt++;
			else ups--;
			// cout << x + downt << " " << h << "\n";
			if(x + downt > h){
				cout << "NO\n";
				return 0;
			} 
		}	
		if(t[i] == 'L')	lefts = min(y -1, lefts + 1);
		if(t[i] == 'R') rights = min(w - y, rights + 1);
		if(t[i] == 'U')	ups = min(x-1, ups+1);
		if(t[i] == 'D') downs = min( h -x, downs + 1);
		
	}
	cout << "YES\n";
	return 0;
}

Measured memory_bytes: 920
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <deque>
#include <map>
#include <cmath>
#include <cstring>
#include <string>
#include <queue>
#include <stack>
using namespace std;
typedef long long ll;
const ll mod=1e9+7;
ll dp[1000010][4];
int main()
{
	dp[1][0]=1;
	dp[1][1]=1;
	dp[1][2]=0;
	dp[1][3]=8;
	int x;
	cin>>x;
	for(int i=2;i<=x;i++)
	{
		dp[i][0]=dp[i-1][0]*9+dp[i-1][3];
		dp[i][1]=dp[i-1][1]*9+dp[i-1][3];
		dp[i][3]=dp[i-1][3]*8;
		dp[i][2]=dp[i-1][1]+dp[i-1][0]+10*dp[i-1][2];
		dp[i][2]%=mod;
		dp[i][1]%=mod;
		dp[i][0]%=mod;
		dp[i][3]%=mod;
	}
	cout<<dp[x][2]<<endl;
	

	



    int ab;
    cin>>ab;
	return 0;
}

Measured memory_bytes: 34780
#define _CRT_SECURE_NO_WARNINGS
#pragma comment(linker, "/stack:512000000")
#include<utility>
#include<iostream>
#include<fstream>
#include<vector>
#include<array>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<ctime>
#include<functional>
#include<random>
#include<climits>
#include<queue>
#include<stack>
#include<deque>
#include<bitset>
#include<map>
#include<set>
#include<unordered_map>
#include<unordered_set>
#include<cassert>
#include<ccomplex>

#ifdef ONLINE_JUDGE
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,tune=native")
#pragma GCC optimize("unroll-loops")
#define int128 __int128
#else
#define int128 long long
#endif

#define all(x) x.begin(), x.end()
#define mp make_pair
#define X first
#define Y second

using namespace std;

using ll = long long;
using ull = unsigned long long;
using ld = long double;
mt19937_64 gen(time(nullptr));

ll mod = 1e9 + 7;

namespace {
	ll mul(ll a, ll b) {
		ll val = a * b - (ll)((ld)a * b / mod) * mod;
		if (val < 0) val += mod;
		if (val >= mod) val -= mod;
		return val;
	}
	ll poww(ll a, ll b) {
		ll val = 1;
		a %= mod;
		while (b > 0) {
			if (b % 2) val = mul(a, val);
			a = mul(a, a);
			b >>= 1;
		}
		return val % mod;
	}
	ll inv(ll a) {
		return poww(a, mod - 2);
	}
}

int const maxn = 3e5 + 5;

signed main() {
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	ll n, k;
	cin >> n >> k;
	ll ans = min(n % k, k - n % k);
	cout << ans << endl;





	return 0;
}

/*


*/

Measured memory_bytes: 256
/*
 *
 *    I am o0o0oo00.
 *
 */
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define ll          long long
#define p7          1000000007
#define p9          998244353
#define pb          push_back
#define ff          first
#define ss          second
#define vll         vector<ll>
#define pll         pair<ll,ll>
#define vpll        vector<pll>
#define mll         map<ll,ll>
#define test        ll T;cin>>T;while(T--)
#define ad(a,n)     vll a;a.resize(n);for(ll i=0;i<n;i++)cin>>a[i];
#define as(a,n)     for(ll i=0;i<n;i++){cout<<a[i]<<" ";}cout<<endl;
#define all(x)      x.begin(),x.end()

typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> pbds;

ll powm(ll x, ll y, ll m = p7) {
    x = x % m; ll res = 1; while (y)
    {if (y & 1)res = res * x; res %= m; y = y >> 1; x = x * x; x %= m;} return res;
}
ll modi(ll a, ll m = p7) {return powm(a, m - 2, m);}
void yesno(bool f) {f ? cout << "YES" << endl : cout << "NO" << endl;}


void ss99()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
}

ll dp[3001][3001];

int32_t main()
{
    ss99();
//    test
    {
        ll n; cin >> n;
        ad(a, n);
        for (ll i = n - 1; i >= 0; i--)
        {
            for (ll j = i; j < n; j++)
            {
                if (i == j)
                    dp[i][j] = a[i];
                else
                    dp[i][j] = max(a[i] - dp[i + 1][j], a[j] - dp[i][j - 1]);
            }
        }
        cout << dp[0][n - 1] << endl;
    }
    return 0;
}

Measured memory_bytes: 70016
# https://atcoder.jp/contests/abc052/tasks/arc067_b
# 歩いたほうが良いのかテレポートしたほうが良いのか貪欲に選択していくだけでは？

import sys
read = sys.stdin.readline


def read_ints():
    return list(map(int, read().split()))



N, A, B = read_ints()
X = read_ints()

# 面倒なのでnumpy芸してええか？
X_diff = [x-y for x,y in zip(X[1:],X[:-1])]
ans = 0
for d in X_diff:
    ans += min(B, d * A)
print(ans)


Measured memory_bytes: 14172
# [New] Matrix Chain Multiplication using Dynamic Programming Formula
# https://www.youtube.com/watch?v=_WncuhSJZyA

n = int(input())

P = []
a, b = [int(i) for i in input().split()]
P.append(a)
P.append(b)
for _ in range(n - 1):
    _, b = [int(i) for i in input().split()]
    P.append(b)

dp = [[None] * (n + 1) for _ in range(n + 1)]  # 1-indexed table

for i in range(1, n + 1):
    dp[i][i] = 0

for r in range(2, n + 1):
    for i in range(1, n - r + 2):
        j = i + r - 1
        dp[i][j] = float("inf")
        for k in range(i, j):
            dp[i][j] = min(dp[i][j], dp[i][k] + dp[k + 1][j] + P[i - 1] * P[k] * P[j])

print(dp[1][-1])



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

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

	ll ans = -9223372036854775807;
	ans = max(ans, a * c);
	ans = max(ans, a * d);
	ans = max(ans, b * c);
	ans = max(ans, b * d);

	cout << ans << endl;

	return 0;
}

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

using namespace std;

struct Initializer {
  Initializer() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout << fixed << setprecision(15);
  }
} initializer;

int main() {
  int n, a, b;
  cin >> n >> a >> b;
  cout << min(n * a, b) << endl;
}



Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <algorithm>

using namespace std;
using ll = long long;
const int maxn = 100004;
const int INF = 0x3f3f3f3f;

int pre[maxn];
bool vis[maxn];

int find(int x) {
    while(!vis[x] && pre[x] != x) {
        x = pre[x];
    }
    return x;
}

int main() {
    int n, m;
    while(~scanf("%d%d", &n, &m) && (n || m)) {
        vis[1] = true; pre[1] = 1;
        for(int i = 2; i <= n; ++i)
            scanf("%d", &pre[i]);
        ll ans = 0;
        for(int i = 0; i < m; ++i) {
            getchar();
            char c = getchar();
            int a;
            scanf("%d", &a);
            switch(c) {
            case 'M':
                vis[a] = true;
                break;
            case 'Q':
                ans += find(a);
            }
        }
        printf("%lld\n", ans);
        memset(vis, 0, sizeof(vis));
    }
    return 0;
}



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

int main() {
	int n;  cin >> n;
	vector<string> s(n);

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

	for (int i = 0; i < n - 1; i++) {
		if (s[i].back() != s[i + 1].front()) {
			cout << "No" << endl;
			return 0;
		}
	}

	for (int i = 0; i < n; i++) {
		for (int j = i + 1; j < n; j++) {
			if (s[i] == s[j]) {
				cout << "No" << endl;
				return 0;
			}
		}
	}
	cout << "Yes" << endl;

	return 0;
}

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

int main() {
    long long N,Q;
    cin >> N;
    vector <long long> A(N);
    vector <long long> num(100000+1, 0);
    for (long long i=0; i<N; i++) {
        cin >> A.at(i);
        num.at(A.at(i))++;
    }
    cin >> Q;
    vector <long long> ans(Q+1,0);
    ans.at(0) = accumulate(A.begin(), A.end(), (long long)0);
    for (long long i=1; i<=Q; i++) {
        ans.at(i) = ans.at(i-1);
        long long B,C;
        cin >> B >> C;
        ans.at(i) += (num.at(B)*(C-B));
        num.at(C) += num.at(B);
        num.at(B) = 0;
    }
    for (long long i=1; i<=Q; i++) cout << ans.at(i) << endl;
}

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

#define rep(i, n) for(int i=0; i<n; ++i)
#define repit(it, li) for(auto it=li.begin(); it!=li.end(); it++)
#define ll long long int

int main(){
   int n;
   cin>>n;
   ll ans=1;
   ll a[100000];
   rep(i, n){
      cin>>a[i];
      if(a[i]==0){
         cout<<0<<endl;
         return 0;
      }
   }

   rep(i, n){
      if(log10(ans)+log10(a[i]) > 18 || ans*a[i] > (ll)pow(10,18)){
         cout<<(-1)<<endl;
         return 0;
      }
      ans*=a[i];
   }

   cout << ans << endl;
   return 0;
}


Measured memory_bytes: 4688
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

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

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input!{
        n: usize,
        v: [i32; n],
    }
    let mut ret = 0;
    for i in 1..(n-1) {
	if (v[i-1] < v[i] && v[i] < v[i+1]) || (v[i+1] < v[i] && v[i] < v[i-1]) {
	    ret += 1
	}
    }
    println!("{}", ret)
}


Measured memory_bytes: 4352
x = int(input())
for a in range(-120,120):
  if(a<0):
    for b in range(-120,a):
      if(a**5-b**5==x):
        print(a,b)
        break
    else: continue
    break
  else:
    for b in range(-120,a):
      if(a**5-b**5==x):
        print(a,b)
        break
    else: continue
    break

Measured memory_bytes: 64884
#include<cstdio>
#include<cstdlib>
#include<iostream>
#include<vector>
#include<queue>
#include<bitset>
#include<string>
#include<stack>
#include<set>
#include<unordered_set>
#include<map>
#include<unordered_map>
#include<cstring>
#include<complex>
#include<cmath>
#include<iomanip>
#include<numeric>
#include<algorithm>
#include<list>
#include<functional>
#include<cassert>
#define mp make_pair
#define pb push_back
#define X first
#define Y second
#define y0 y12
#define y1 y22
#define INF 1987654321
#define PI 3.141592653589793238462643383279502884
#define fup(i,a,b,c) for(int (i)=(a);(i)<=(b);(i)+=(c))
#define fdn(i,a,b,c) for(int (i)=(a);(i)>=(b);(i)-=(c))
#define MEM0(a) memset((a),0,sizeof(a));
#define MEM_1(a) memset((a),-1,sizeof(a));
#define ALL(a) a.begin(),a.end()
#define SYNC ios_base::sync_with_stdio(false);cin.tie(0)
using namespace std;
typedef long long ll;
typedef long double ld;
typedef double db;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int, int> Pi;
typedef pair<ll, ll> Pll;
typedef pair<double, double> Pd;
typedef vector<int> Vi;
typedef vector<ll> Vll;
typedef vector<double> Vd;
typedef vector<Pi> VPi;
typedef vector<Pll> VPll;
typedef vector<Pd> VPd;
typedef tuple<int, int, int> iii;
typedef tuple<int,int,int,int> iiii;
typedef tuple<ll, ll, ll> LLL;
typedef vector<iii> Viii;
typedef vector<LLL> VLLL;
typedef complex<double> base;
const ll MOD = 998244353;
ll POW(ll a, ll b, ll MMM = MOD) {ll ret=1; for(;b;b>>=1,a=(a*a)%MMM)if(b&1)ret=(ret*a)% MMM; return ret; }
ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
ll lcm(ll a, ll b) { if (a == 0 || b == 0)return a + b; return a*(b / gcd(a, b)); }
int dx[] = { 0,1,0,-1,1,1,-1,-1 }, dy[] = { 1,0,-1,0,1,-1,1,-1 };

int n,m,N;
bool edge(int x,int y)
{
	return x==0 || x==n || y==0 || y==m;
}
VPi v[4];
int main() {
	scanf("%d%d%d",&n,&m,&N);
	fup(i,0,N-1,1)
	{
		int x1,y1,x2,y2;
		scanf("%d%d%d%d",&x1,&y1,&x2,&y2);
		if(edge(x1,y1) && edge(x2,y2))
		{
			if(x1==0)v[3].pb(mp(y1,i));
			else if(y1==0)v[0].pb(mp(x1,i));
			else if(x1==n)v[1].pb(mp(y1,i));
			else if(y1==m)v[2].pb(mp(x1,i));
			if(x2==0)v[3].pb(mp(y2,i));
			else if(y2==0)v[0].pb(mp(x2,i));
			else if(x2==n)v[1].pb(mp(y2,i));
			else if(y2==m)v[2].pb(mp(x2,i));
		}
	}
	fup(i,0,3,1)
	{
		sort(ALL(v[i]));
		if(i>=2)reverse(ALL(v[i]));
	}
	stack<int> st;
	fup(i,0,3,1)
	{
		for(Pi p:v[i])
		{
			int y=p.Y;
			if(st.empty())st.push(y);
			else if(st.top()==y)st.pop();
			else st.push(y);
		}
	}
	puts(st.empty()?"YES":"NO");
}

Measured memory_bytes: 2520
#include<bits/stdc++.h>
using namespace std;
const int maxn = 3e2+7;
const int mod = 998244353;

typedef long long ll;
ll dp[maxn*maxn];
ll dd[maxn*maxn];
int n,ar[maxn];
int main()
{
    memset(dp,0,sizeof(dp));
    memset(dd,0,sizeof(dd));
    scanf("%d",&n);
    for(int i=1;i<=n;i++)scanf("%d",ar+i);
    dp[0]=1;
    dd[0]=1;
    for(int i=1;i<=n;i++)dp[0] = dp[0]*2%mod;
    for(int i=1;i<=n;i++){
        for(int j=maxn*maxn-1;j>=ar[i];j--){
            dp[j] = (dp[j]+dp[j-ar[i]]*((mod+1)/2)%mod)%mod;
            dd[j] = (dd[j]+dd[j-ar[i]])%mod;
        }
    }
    int sum=0;
    for(int i=1;i<=n;i++)sum+=ar[i];
    ll ans=1;
    for(int i=1;i<=n;i++)ans = ans*3%mod;
    //for(int i=1;i<=sum;i++)cout<<dp[i]<<" ";cout<<endl;
    //cout<<"sum = "<<sum<<endl;
    for(int i=(sum+1)/2;i<=sum;i++){
        ans = (ans + mod - dp[i]*3%mod)%mod;
    }
    //cout<<ans<<" "<<dp[sum/2]<<endl;
    if(sum%2==0)ans = (ans + mod + dd[sum/2]*3%mod)%mod;
    printf("%lld\n",ans);

	return 0;
}


Measured memory_bytes: 1664