akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
 
using namespace std;
 
#define lli long long int
#define REP(i,s,l) for(lli i=s;i<l;i++)
#define DEBUG 0
#define INF (1LL<<50)
#define MOD 1000000007

#define SORT(v) sort(v.begin(),v.end(),greater<lli>())

vector<lli> a,b,c;
lli x,y,z,k;

class cake{
public:
	lli aI,bI,cI;
	lli value;
};

cake make_cake(lli sa,lli sb,lli sc){
	cake rtn;
	if(sa>=x||sb>=y||sc>=z){
		rtn.value=-100000000000;
		return rtn;
	}
	rtn.aI = sa;
	rtn.bI = sb;
	rtn.cI = sc;
	rtn.value = a[sa]+b[sb]+c[sc];
	return rtn;
}

bool operator<(const cake &a,const cake &b){
	if(a.value!=b.value)return a.value < b.value;
	else if(a.aI != b.aI)return a.aI < b.aI;
	else if(a.bI != b.bI)return a.bI < b.bI;
	else return a.cI < b.cI;
}

signed main(){

	cin>>x>>y>>z>>k;
	a.resize(x);
	b.resize(y);
	c.resize(z);

    REP(i,0,x)cin>>a[i];
    REP(i,0,y)cin>>b[i];
    REP(i,0,z)cin>>c[i];

    SORT(a);
    SORT(b);
    SORT(c);
    set<cake>s;

    priority_queue<cake> q;
    q.push(make_cake(0,0,0));
    lli cnt=0;

    while(cnt<k){
    	cake top = q.top();
    	q.pop();
    	if(s.find(top)!=s.end())continue;
    	s.insert(top);
    	cout<<top.value<<endl;

    	/*次のcakeを入れる*/
    	q.push(make_cake(top.aI+1,top.bI,top.cI));
    	q.push(make_cake(top.aI,top.bI+1,top.cI));
    	q.push(make_cake(top.aI,top.bI,top.cI+1));
    	cnt++;
    }

   	return 0;
}

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

using namespace std;
typedef long long ll;

int main() {
	int n; string s;
	cin >> n >> s;
	if (n % 2 != 0) cout << "No" << endl;
	else {
		string t = s.substr(n / 2);
		s = s.substr(0, n / 2);
		if (s == t) cout << "Yes" << endl;
		else cout << "No" << endl;
	}
}

Measured memory_bytes: 256
#include <stdio.h>

int main(){
    int a[7] = {1,3,5,7,8,10,12};
    int b[4] = {4,6,9,11};
    int flag = 0;
    int book = 0;
    int c, d;
    scanf("%d %d",&c,&d);
    for(int i=0; i<7; i++){
        if(c==a[i] || d==a[i]) flag ++;
    }
    if(flag == 2) printf("Yes");
    else book++;
    flag = 0;
    for(int i=0; i<4; i++){
        if(c==b[i] || d==b[i]) flag ++;
    }
    if(flag == 2) printf("Yes");
    else if(book == 1) printf("No");
    return 0;
}

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

int main(){
	int n;
	cin>>n;
	int count=0;
	long long int in,x,y;
	for(int i=0;i<n;i++){
		cin>>in;
		x=0;
		do{
			x++;
			if((in-x)%(2*x+1)==0) goto next;
			y=(in-x)/(2*x+1);
		}while(x<y);
		count++;
		next:;
	}
	cout<<count<<endl;
	return 0;
}

Measured memory_bytes: 1168
import java.util.Scanner;

//Can I go there?
public class Main{

	long[][] modpow(long[][] A, long n){
		long[][] res = new long[A.length][A.length];
		for(int i=0;i<A.length;i++){
			res[i][i] = 1L;
		}
		while(n>0){
			if((n&1)>0){
				res = modmul(res, A);
				for(int i=0;i<A.length;i++)for(int j=0;j<A.length;j++)res[i][j] = Math.min(res[i][j], 1);
			}
			A = modmul(A, A);
			for(int i=0;i<A.length;i++)for(int j=0;j<A.length;j++)A[i][j] = Math.min(A[i][j], 1);
			n>>=1;
		}
		return res;
	}
	
	long[][] modmul(long[][] A, long[][] B){
		long[][] res = new long[A.length][B[0].length];
		for(int i=0;i<A.length;i++){
			for(int j=0;j<B[0].length;j++){
				for(int k=0;k<A[0].length;k++){
					res[i][j] = (res[i][j] + A[i][k]*B[k][j]);
				}
			}
		}
		return res;
	}
	
	void run(){
		Scanner sc = new Scanner(System.in);
		for(;;){
			int n = sc.nextInt(), m = sc.nextInt(), Z = sc.nextInt();
			if((n|m|Z)==0)break;
			int[] pre = new int[2*m], now = new int[2*m];
			for(int i=0;i<m;i++){
				int s = sc.nextInt(), t = sc.nextInt();
				pre[i*2] = s; now[i*2] = t;
				pre[i*2+1] = t; now[i*2+1] = s;
			}
			long[][] A = new long[2*m+1][2*m+1];
			for(int i=0;i<2*m;i++)for(int j=0;j<2*m;j++){
				if(now[i]==pre[j] && now[j]!=pre[i])A[i][j] = 1;
			}
			for(int i=0;i<2*m;i++)if(pre[i]==1)A[2*m][i] = 1;
			A = modpow(A, Z);
			String res = "no";
			for(int i=0;i<2*m;i++){
				if(now[i]==n && A[2*m][i]!=0){
					res = "yes"; break;
				}
			}
			System.out.println(res);
		}
	}
	
	public static void main(String[] args) {
		new Main().run();
	}
}

Measured memory_bytes: 16000
import java.math.BigInteger;
import java.util.*;

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

        BigInteger lPrev = new BigInteger("2");
        BigInteger l = new BigInteger("1");
        BigInteger i = new BigInteger("1");
        BigInteger one = new BigInteger("1");

        if (n.equals(one)) {
            System.out.println(1);
            return;
        }

        while (!i.equals(n)) {
            BigInteger lNext = l.add(lPrev);
            lPrev = l;
            l = lNext;
            i = i.add(one);
        }
        System.out.println(l.toString());
    }
}


Measured memory_bytes: 21844
#include <vector>
#include <iostream>
#include <map>
#include <string>
#include <utility>
#include <algorithm>
#include <stack>
#include <queue>
#include <list>
#include <functional>

const int INF = 1001001000;
const int MOD = (int)1e9 + 7;

using ll = long long;

using namespace std;

typedef pair<int,int> P;

int dx[] = { 0, 0, 1, -1};
int dy[] = { 1, -1, 0, 0};

int main(){
  int a,b;
  int x;
  cin >> a >> b;
  if( b < 10){
    x = a*10+b;
  }else if( b < 100){
    x = a*100+b;
  }else{
    x = a*1000+b;
  }

  int j = 0;
  bool f = false;
  while( x >= j*j){
    if( x == j*j){
      f = true;
    }
    ++j;
  }

  if(f){
    cout << "Yes"<<endl;
  }else{
    std::cout << "No" << '\n';
  }

}


Measured memory_bytes: 256
/*
    -ensure correct output format
    -ensure printing required output
    -reread the problem statement
  */

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll>pll;
typedef pair<ll,pair<ll,ll>>plll;
#define fastread() (ios_base:: sync_with_stdio(false),cin.tie(NULL));
#define vll(v) v.begin(),v.end()
#define all(x) x.rbegin(),x.rend()
#define min3(a, b, c)   min(a, min(b, c))
#define max3(a, b, c)   max(a, max(b, c))
#define F first
#define S second
#define in  freopen("input.txt", "r", stdin)
#define out  freopen("output.txt", "w", stdout)
#define minheap int,vector<int>,greater<int>
#define pb push_back
#define eb emplace_back
#define ischar(x)  (('a' <= x && x <= 'z') || ('A' <= x && x <= 'Z'))
#define isvowel(ch) ((ch=='a'||ch=='e'||ch=='i'||ch=='o'||ch=='u')||(ch=='A'|| ch=='E' || ch=='I'|| ch=='O'|| ch=='U'))
#define bug cout<<"BUG"<<endl;
const int Max = 2e6 + 10;
const int Mod = 1e9 + 7;
const double PI  =3.141592653589793238463;
bool compare(const pair<ll,ll> &a, const pair<ll,ll> &b)
{
    return (a.first > b.first);
}
ll lcm(ll a,ll b)
{
    if(a==0 || b==0)return 0;

    return a/__gcd(a,b)*b;
}

void input(ll ara[],ll n)
{
    for(ll i=0; i<n; i++)cin>>ara[i];
}
void print(ll ara[],ll n)
{
    for(ll i=0; i<n; i++)
        cout<<ara[i]<<" ";
    cout<<endl;
}



vector<ll>v[Max+10];


int main()
{

    fastread();

    ll i,j,n,m,p,a,sum=0,k,t,b,c,d,cnt=0,q,l,r,ans=0;

    bool flag=false;

    string str;

    cin>>n;

    for(i=1; i<=n; i++)
    {
        for(j=1; j<n; j++)
        {
            cin>>a;

            v[i].eb(a);
        }
    }



    ll day=0;

    flag=true;

    ll mark[n+3];

    while(flag)
    {
        flag=false;



       memset(mark,0,sizeof(mark));


        for(i=1; i<=n; i++)
        {
            if(mark[i])continue;

            if(!v[i].empty())
            {
                a=v[i][0];

                if(!v[a].empty() && mark[a]==0)
                {
                    b=v[a][0];

                    if(b==i)
                    {
                      //  cout<<i<<" "<<a<<endl;

                        mark[i]=1;
                        mark[a]=1;

                        v[i].erase(v[i].begin());

                        v[a].erase(v[a].begin());

                        flag=true;
                    }
                }
            }
        }

        if(flag)day++;


    }

    flag=true;

    for(i=1; i<=n; i++)
        if(!v[i].empty())
        {
            flag=false;
            break;

        }


    if(flag)cout<<day<<endl;

    else cout<<-1<<endl;













}



Measured memory_bytes: 58256
//https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8 より
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

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

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };
    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };
    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };
    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };
    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

// ここまで

use std::io::Write;

fn run() {
    let out = std::io::stdout();
    let mut out = std::io::BufWriter::new(out.lock());
    input! {
        n: usize,
        m: u64,
        e: [(usize1, usize1); n - 1],
    }
    let mut g = vec![vec![]; n];
    for (a, b) in e {
        g[a].push(b);
        g[b].push(a);
    }
    let mut parent = vec![n; n];
    let mut q = Vec::with_capacity(n);
    let mut s = vec![];
    s.push(0);
    while let Some(v) = s.pop() {
        q.push(v);
        for &u in g[v].iter() {
            if u == parent[v] {
                continue;
            }
            parent[u] = v;
            s.push(u);
        }
    }
    let mut dp = vec![0; n];
    for &v in q.iter().rev() {
        let mut way = 1;
        for &u in g[v].iter() {
            if u == parent[v] {
                continue;
            }
            way = way * (dp[u] + 1) % m;
        }
        dp[v] = way;
    }
    let mut dp2 = vec![0; n];
    for &v in q.iter() {
        let mut child = vec![];
        for &u in g[v].iter() {
            if u == parent[v] {
                continue;
            }
            child.push(u);
        }
        let len = child.len();
        let mut left = vec![1; len + 2];
        let mut right = vec![1; len + 2];
        for (i, &u) in child.iter().enumerate() {
            let i = i + 1;
            left[i] = left[i - 1] * (dp[u] + 1) % m;
        }
        for (i, &u) in child.iter().enumerate().rev() {
            let i = i + 1;
            right[i] = right[i + 1] * (dp[u] + 1) % m;
        }
        for (i, &u) in child.iter().enumerate() {
            let i = i + 1;
            dp2[u] = (dp2[v] + 1) * left[i - 1] % m * right[i + 1] % m;
        }
    }
    for i in 0..n {
        let ans = dp[i] * (dp2[i] + 1) % m;
        writeln!(out, "{}", ans).unwrap();
    }
}

fn main() {
    run();
}


Measured memory_bytes: 24828
import java.io.*;
import java.util.Arrays;
import java.util.*;

class Main{
	public static void main(String[] args) throws IOException{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String[] str = (br.readLine()).split(" ");
		Deque<Integer> stack = new ArrayDeque<Integer>();
		for (int i = 0; i<str.length ; i++ ) {
			if (str[i].equals("+")) {
				int	a = stack.pop();
				int	b = stack.pop();
				int	c = a+b;
				stack.push(c);	
			}else if(str[i].equals("-")){
				int	a = stack.pop();
				int	b = stack.pop();
				int	c = b-a;
				stack.push(c);	
			}else if (str[i].equals("*")) {
				int	a = stack.pop();
				int	b = stack.pop();		
				int	c = a*b;
				stack.push(c);	
			}else{
				stack.push(Integer.parseInt(str[i]));
			}
		}
		System.out.println(stack.pop());
	}
}

Measured memory_bytes: 24424
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <cmath>
#include <complex>
#include <deque>
#include <iterator>
#include <map>
#include <queue>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <limits>
#include <iomanip>
using namespace std;

using ll=long long;
template<class T> using V = vector<T>;
template<class T, class U> using P = pair<T, U>;
using vll = V<ll>;
using vvll = V<vll>;
#define rep(i, k, n) for (ll i=k; i<(ll)n; ++i)
#define REP(i, n) rep(i, 0, n)
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;}

const ll MOD = 1000000007;
const ll HIGHINF = (ll)1e18;

int main() {
  ll w, a, b; cin >> w >> a >> b;
  if (b < a) swap(a, b);
  if (a + w < b) cout << b - a - w << endl;
  else cout << 0 << endl;
  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <cctype>
#include <limits.h>
#include <math.h>
#include <complex>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <cstring>
#include <string>
#include <sstream>
#include <algorithm>
#include <iomanip>
#include <iostream>

#define VARIABLE(x) cerr << #x << "=" << x << endl
#define BINARY(x) static_cast<bitset<16> >(x);
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define REP(i,m,n) for (int i=m;i<(int)(n);i++)
#define if_range(x, y, w, h) if (0<=(int)(x) && (int)(x)<(int)(w) && 0<=(int)(y) && (int)(y)<(int)(h))

const int INF = 1e9;
const double EPS = 1e-8;
const double PI = 3.14159;
int dx[4]={0, 1, 0, -1}, dy[4]={-1, 0, 1, 0};
using namespace std;
typedef long long ll;
//typedef pair<int, int> P;
struct P {
	int x, y, n;
	P(int n, int x, int y):n(n), x(x), y(y){}
	P(){}
};

/** Problem1217 : Family Tree **/

struct S {
	string name;
	int parent;
	vector<int> child;
	S(string s, int p, vector<int> c) : name(s), parent(p), child(c){}
};

vector<S> G;

int main()
{
	int N, M;
	while (cin>>N>>M, N||M) {
		cin.ignore();
		G.clear();
		
		map<string, int> list;
		
		int idx=0;
		
		vector<string> s(N);
		for (int i=0; i<N; i++) {
			getline(cin, s[i]);
		}
		
		for (int i=0; i<N; i++) {
			int count = 0;
			int p=0;
			
			while (s[i][p]==' ') {
				count++;
				p++;
			}
			
			string n = s[i].substr(p);
			if (count==0) {
				G.push_back(S(n, -1, vector<int>()));
				list[n] = idx++;
			} else {
				string parent;
				for (int j=i; j>=0; j--) {
					int cc=0;
					while (s[j][cc]==' ') cc++;
					if (cc==count-1) {
						parent = s[j].substr(cc);
					
						G.push_back(S(n, list[parent], vector<int>()));
						list[n] = idx++;
						G[list[parent]].child.push_back(list[n]);
						break;
					}
				}
			}
		}
		
		for (int z=0; z<M; z++) {
			string t; getline(cin, t);
			t.erase(t.end()-1);
			
			istringstream ss(t);
			vector<string> tt(6);
			for (int i=0; i<6; i++)
				ss>>tt[i];
			
			string X = tt[0], Y = tt[5];
			
			bool ans=false;
			
			if (tt[3][0]=='c') {
				swap(X, Y);
				
				if (list[X] == G[list[Y]].parent) {
					ans = true;
				}
			} else if (tt[3][0]=='p') {
				if (list[X] == G[list[Y]].parent) {
					ans = true;
				}
			} else if (tt[3][0]=='s') {
				if (G[list[X]].parent == G[list[Y]].parent && G[list[X]].parent!=-1)
					ans = true;
			} else if (tt[3][0]=='d') {
				swap(X, Y);
				
				S now = G[list[Y]];
				for (;;) {
					if (now.parent==-1) break;
					if (now.parent == list[X])
						ans = true;
					now = G[now.parent];
				}
			} else if (tt[3][0]=='a') {
				S now = G[list[Y]];
				for (;;) {
					if (now.parent==-1) break;
					if (now.parent == list[X])
						ans = true;
					now = G[now.parent];
				}
			}
			cout << (ans?"True":"False") << endl;
		}
		cout << endl;
	}
}

Measured memory_bytes: 1492
using System;
class Program
{
    static void Main(string[] args)
    {
        long N = long.Parse(Console.ReadLine());
        long X = 0, min = 0;
        for (int i = 0; i < 5; i++)
        {
            X = long.Parse(Console.ReadLine());
            if (i == 0) min = X;
            if (min > X) min = X;
        }
        int j = 0;
        if (N % min > 0) j = 1;
        Console.WriteLine(4 + N / min + j);

    }
}

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

// Template Headers {{{
using pii = pair<int, int>; using vpii = vector<pii>;
using vi = vector<int>; using vvi = vector<vi>;
using ll = long long; using vll = vector<long long>;
template <class T> using min_queue = priority_queue<T, vector<T>, greater<T>>;
template <class T> istream &operator>>(istream &, vector<T> &);
template <class T> ostream &operator<<(ostream &, const vector<T> &);
template <class T, class U> istream &operator>>(istream &, pair<T, U> &);
template <class T, class U> ostream &operator<<(ostream &, const pair<T, U> &);
template <class T> struct Inf { static constexpr T inf() { return std::numeric_limits<T>::has_infinity() ? std::numeric_limits<T>::infinty() : std::numeric_limits<T>::max(); } };
template <> struct Inf<int> { static constexpr int inf() { return 0x3f3f3f3f; } };
template <> struct Inf<long long> { static constexpr long long inf() { return 0x3f3f3f3f3f3f3f3fLL; } };
constexpr int INF = Inf<int>::inf(); constexpr ll BINF = Inf<ll>::inf();
// mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
// }}}
// Fenwick Tree {{{
template<class T>
class Fenwick {
	private:
		std::vector<T> arr;
		int sz;
		T myQuery(int idx) {
			T rt{};
			for(;idx>0;idx-=idx&-idx) rt += arr[idx];
			return rt;
		}
		void myUpdate(int idx, T val) {
			for(;idx<=sz;idx+=idx&-idx) arr[idx] += val;
		}

	public:
		Fenwick(int n) : arr(n + 1), sz(n) {}

		T query(int x) { return myQuery(x + 1); }

		T query(int l, int r) { return query(r) - query(l - 1); }

		void update(int x, T v) { myUpdate(x + 1, v); }

};
// }}}

int solve() {
	int n, q; cin >> n >> q;
	Fenwick<int> fenw(n + 1);
	while (q--) {
		int op; cin >> op;
		if (op == 0) {
			int l, r, v; cin >> l >> r >> v;
			l--; r--;
			fenw.update(l, v);
			fenw.update(r + 1, -v);
		} else {
			int p; cin >> p; p--;
			cout << fenw.query(p) << endl;
		}
	}
	return 0;
}

// Template Main {{{
int main() {
	ios::sync_with_stdio(0);
	// precompute();
	// int t; cin >> t; for (int i=1;i<=t;i++)
	solve();
	// cout << "Case #" << i << ": ", solve();
	return 0;
}

template <class T> istream &operator>>(istream &is, vector<T> &v) {
	for (auto it=v.begin();it!=v.end();++it) is >> *it;
	return is;
}

template <class T> ostream &operator<<(ostream &os, const vector<T> &v) {
	for (auto it=v.begin();it!=v.end();) os << *it, os << " \n"[++it==v.end()];
	return os;
}

template <class T, class U> istream &operator>>(istream &is, pair<T, U> &p) {
	return is >> p.first >> p.second;
}

template <class T, class U> ostream &operator<<(ostream &os, const pair<T, U> &p) {
	return os << p.first << ' ' << p.second;
}
// }}}

// vim: fdm=marker



Measured memory_bytes: 3364
#include <iostream>
#include <algorithm>
#include <stdlib.h>
using namespace std;

int main()
{
    int N;
    cin >> N;
    int *array1 = (int *)malloc(sizeof(int)*N);
    int *array2 = (int *)malloc(sizeof(int)*N);
    int *array3 = (int *)malloc(sizeof(int)*N);
    for(int i = 0; i < 3; i++)
        for(int j = 0; j < N; j++)
        {
            if(i == 0) cin >> array1[j];
            else if(i == 1) cin >> array2[j];
            else if(i == 2) cin >> array3[j];
        }
    
    sort(array1, array1+N);
    sort(array3, array3+N);
    
    int long long count1=0, count2=0, total=0;
    for(int i = 0; i < N; i++)
    {
        count1 = 0; count2 = 0;
        count1 = (lower_bound(array1, array1+N, array2[i]) - array1);
        count2 = N - (upper_bound(array3, array3+N, array2[i]) - array3);
        total += (count1 * count2);
    }
    cout << total << endl;
}



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

#define fast_io ios_base::sync_with_stdio(false); cin.tie(0);
#define ll long long
#define en "\n"
#define eps 1e-9
#define VECT(v)  vector<int>v
#define SCAN(v)  int temp; for(int i=0; i<n; i++) {cin>>temp; v.push_back(temp);}
#define PRINT(v) for(int i = 0; i < v.size(); i++) cout << v[i] << " "; cout << en;
#define SORT(v)  sort(v.begin(), v.end());
#define CASEP(v) cout<<"Case "<<c<<": "<<v<<"\n"
#define DEBUG(v) cout << v << " "; cout << en;

int main(void)
{
	#ifndef ONLINE_JUDGE
		freopen("in.txt", "r", stdin);
		freopen("out.txt", "w", stdout);
	#endif

	fast_io
	
	int n;
	cin >> n;

	VECT(v);
	SCAN(v);

	ll big = 0, sum = 0;
	for(int i = 0; i < v.size(); i++)
	{
		if(v[i] > big)
			big = v[i];

		if(v[i] < big)
			sum += abs(v[i] - big);
	}
	cout << sum << en;

	return 0;
}

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

template <class Abel> struct BIT {
    vector<Abel> dat[2];
    Abel UNITY_SUM = 0;                     // to be set
    
    /* [1, n] */
    BIT(int n) { init(n); }
    void init(int n) { for (int iter = 0; iter < 2; ++iter) dat[iter].assign(n + 1, UNITY_SUM); }
    
    /* a, b are 1-indexed, [a, b) */
    inline void sub_add(int p, int a, Abel x) {
        for (int i = a; i < (int)dat[p].size(); i += i & -i)
            dat[p][i] = dat[p][i] + x;
    }
    inline void add(int a, int b, Abel x) {
        sub_add(0, a, x * -(a - 1)); sub_add(1, a, x); sub_add(0, b, x * (b - 1)); sub_add(1, b, x * (-1));
    }
    
    /* a is 1-indexed, [a, b) */
    inline Abel sub_sum(int p, int a) {
        Abel res = UNITY_SUM;
        for (int i = a; i > 0; i -= i & -i) res = res + dat[p][i];
        return res;
    }
    inline Abel sum(int a, int b) {
        return sub_sum(0, b - 1) + sub_sum(1, b - 1) * (b - 1) - sub_sum(0, a - 1) - sub_sum(1, a - 1) * (a - 1);
    }
    
    /* debug */
    void print() {
        for (int i = 1; i < (int)dat[0].size(); ++i) cout << sum(i, i + 1) << ",";
        cout << endl;
    }
};

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

    vector<int> lefts(Q), rights(Q), ids(Q);
    for (int i = 0; i < Q; ++i) {
        cin >> lefts[i] >> rights[i];
        --lefts[i];
        ids[i] = i;
    }
    sort(ids.begin(), ids.end(), [&](int i, int j) {
            return rights[i] < rights[j];});

    BIT<int> bit(N+5);
    vector<int> prev(1100000, -1);
    vector<int> res(Q, 0);
    int r = 0;
    for (auto i : ids) {
        for (; r < rights[i]; ++r) {
            bit.add(prev[a[r]]+2, r+2, 1);
            prev[a[r]] = r;
        }
        int tmp = bit.sum(lefts[i]+1, lefts[i]+2);
        res[i] = max(res[i], tmp);
    }
    for (int i = 0; i < Q; ++i) cout << res[i] << endl;
}

Measured memory_bytes: 21724
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n) ;i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
using ll=long long;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define MOD  1000000007
const int INF=1e9;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }



int main(int argc, char const *argv[]) {
  int a,b,c;
  std::cin >> a >> b >> c;
  if(a==b && b==c) std::cout << "Yes" << '\n';
  else std::cout << "No" << '\n';

  return 0;
}


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

int main(void)
{
    vector<int> element(3);
    for (int i = 0; i < 3; i++)
    {
        cin >> element[i];
    }
    sort(element.begin(), element.end());

    int area = (element[0] * element[1]) / 2;
    cout << area << endl;
    return (0);
}

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

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


Measured memory_bytes: 3092
#include <algorithm>
#include <bitset>
#include <cstdio>
#include <functional>
#include <initializer_list>
#include <iostream>
#include <limits.h>
#include <list>
#include <map>
#include <math.h>
#include <queue>
#include <regex>
#include <set>
#include <sstream>
#include <string>
#include <tuple>
#include <utility>
#include <vector>
using namespace std;
#define ull unsigned long long
#define ll long long
#define rep(i, a, n) for (int i = (a); i < (int)(n); i++)
#define repc(i, a, n) for (int i = (a); i <= (int)(n); i++)
#define all(t) t.begin(), t.end()
#define rall(t) t.rbegin(), t.rend()
#define mat(type, row, col, init)                                              \
  vector<vector<type>>(row, vector<type>(col, init));
#define Yes(cond) cout << (cond ? "Yes" : "No") << endl;
#define YES(cond) cout << (cond ? "YES" : "NO") << endl;
#define DBG(str) cerr << (str) << endl;
int main() {
  int w, h, n;
  cin >> w >> h >> n;
  vector<int> x(n), y(n), a(n);
  rep(i, 0, n) cin >> x[i] >> y[i] >> a[i];
  int a1, a2, a3, a4;
  a1 = a3 = 0;
  a2 = w;
  a4 = h;
  rep(i, 0, n) {
    if (a[i] == 1)
      a1 = max(a1, x[i]);
    if (a[i] == 2)
      a2 = min(a2, x[i]);
    if (a[i] == 3)
      a3 = max(a3, y[i]);
    if (a[i] == 4)
      a4 = min(a4, y[i]);
  }
  cout << max(a2 - a1, 0) * max(a4 - a3, 0);

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <iostream>
#include <string>
#include <vector>
#include <stdio.h>
#include <algorithm>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <queue>
#include <set>
#include <map>
#include <math.h>

#define MIN(a, b) ((a) < (b) ? (a) : (b))
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define repP(i, a, b) for(int i = a; i < b; i++)
#define repM(i, a, b) for(int i = a - 1; i >= b; i--)

using namespace std;

int main()
{
  long a = 0 , b = 0, c = 0, d = 0, e = 0, f = 0, i = 0, j = 0;
  long sum = 0, num = 0, count = 0, ans = 0, min = 0, max = 0;
  double d1 = 0, d2 = 0, d3 = 0, d4 = 0, d5 = 0, d6 = 0;
  int a1[999999], a2[999999], a3[999999];
  //char s1[200000], s2[200000], s3[200000];
  //string s1, s2, s3;
  
  cin >> a>> b;
  num = a * b;
  if(a<b){
    c=a;
    a=b;
    b=c;
  }
  d=a%b;
  while(d!=0){
    a=b;
    b=d;
    d=a%b;
  }
  cout<<num/b<<endl;
}
  

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define PI 3.14159265358979323846
#define MAXINF (1e18L)
#define INF (1e9L)
#define EPS (1e-9)
#define MOD ((ll)(1e9+7))
#define REP(i, n) for(int i=0;i<int(n);++i)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define ALL(v) v.begin(),v.end()
#define FIND(v,x) (binary_search(ALL(v),(x)))
#define SORT(v) sort(ALL(v))
#define RSORT(v) sort(ALL(v));reverse(ALL(v))
#define DEBUG(x) cerr<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cerr<<#v<<":";for(int i=0;i<v.size();i++) cerr<<" "<<v[i]; cerr<<endl
#define Yes(n) cout<<((n)?"Yes":"No")<<endl
#define YES(n) cout<<((n)?"YES":"NO")<<endl
#define pb push_back
#define fi first
#define se second
using namespace std;
template<class A>void pr(A a){cout << (a) << endl;}
template<class A,class B>void pr(A a,B b){cout << a << " "  ;pr(b);}
template<class A,class B,class C>void pr(A a,B b,C c){cout << a << " " ;pr(b,c);}
template<class A,class B,class C,class D>void pr(A a,B b,C c,D d){cout << a << " " ;pr(b,c,d);}
template<class T> void pr_vec(vector<T> &v, char ep=' '){int n=v.size();REP(ni,n){cout<<v[ni];if(ni!=n-1)cout<<ep;}cout<<endl;};
template<class T> inline bool chmin(T& a, T b){return a>b ? a=b, true : false;}
template<class T> inline bool chmax(T& a, T b){return a<b ? a=b, true : false;}
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll,ll> pll;

int main(void)
{
    int N;
    cin >> N;
    vector<int> A(N);
    REP(i,N) cin >> A[i];

    vector<ll> dp(N);
    dp[0] = 1000;
    Rep(i,1,N){
        dp[i] = dp[i-1];
        REP(j, i){
            chmax(dp[i], A[i]*(dp[j]/A[j]) + (dp[j]%A[j]));
        }
    }
    pr(dp[N-1]);
}

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

int main(){
	string s;
	cin >> s;
	string t = "AIDUNYAN";
	sort(t.begin(),t.end());
	for(int i = 0 ; i + t.size() <= s.size() ; i++){
		string k = s.substr(i,t.size());
		sort(k.begin(),k.end());
		if( k == t ){
			s = s.substr(0,i) + "AIZUNYAN" + s.substr(i+t.size());  i += t.size() - 1;
		}
	}
	cout << s << endl;
}

Measured memory_bytes: 1220
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

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

    vector<int> a(n);

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

    vector<bool> dp(k + 1);

    for (int i = 0; i <= k; i++) {
        bool win = false;

        for (int j = 0; j < n; j++) {
            if (i - a[j] >= 0 && !dp[i - a[j]]) {
                win = true;
                break;
            }
        }

        dp[i] = win;
    }

    cout << (dp[k] ? "First" : "Second") << endl;
}


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


using namespace std;

int main()
{
	string A,B,C;
	cin >> A >> B >>C ; 

	if (A[A.size()-1] == B[0]) {
		if (B[B.size()-1] == C[0]) {
			cout << "YES" << endl;

		}
		else {
			cout << "NO" << endl;

		}
	}
	else {
		cout << "NO" << endl;

	}

	
	return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin>>n;
  int a[205];
  for(int i=0;i<n;i++){
    cin>>a[i];
  }
  int k=0;
  while(1){
    int cnt=0;
    for(int i=0;i<n;i++){
      if(a[i]%2==0)
	cnt++;
    }
    if(cnt==n){
      for(int i=0;i<n;i++){
	a[i]=a[i]/2;
      }
    }
    else
      break;
    k++;
  }
  cout<<k<<endl;
  return 0;
}


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

using namespace std;
int x[110];

int main(){
   int n,k;
   cin>>n>>k;
   for(int i=0;i<n;i++)cin>>x[i];
   int ans=0;
   for(int i=0;i<n;i++){
      ans+=2*min(abs(x[i]),abs(x[i]-k));
   }

   cout<<ans<<endl;
   
}

Measured memory_bytes: 256
//2019/3/14
import java.util.Arrays;
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		int X = sc.nextInt();

		int a = 1;

		int i = 2;

		int[] array;

		if(X==1 || X==2 || X==3) {

			System.out.println(1);

		}else {

			array = new int[1000];

			Arrays.fill(array, 0);

			int index = 0;

			while(true) {

				a = i*i;

				if(a>X) break;

				for(int j=a;j<=X;j*=i) {

					array[index] = j;

					index++;
				}

				i++;
			}

			Arrays.parallelSort(array);

			int ans = array[999];

			System.out.println(ans);
		}
	}
}


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

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

    vector<pair<int, int>> p(n);

    rep(i, n) {
        int a;
        cin >> a;

        p[i] = make_pair(a, i+1);
    }
    sort(p.begin(), p.end());

    rep(i, n) {
        cout << p[i].second;
        if(i != n-1) {
            cout << " ";
        }
    }

    cout << endl;
    return 0;
}

Measured memory_bytes: 1664
import sys

n = sys.stdin.readline().rstrip()
hon = [2, 4, 5, 7, 9]
pon = [0, 1, 6, 8]
def main():
    d = int(n[-1])
    if d in hon:
        ans = 'hon'
    elif d in pon:
        ans = 'pon'
    else:
        ans = 'bon'
    print(ans)
    
if __name__ == '__main__':
    main()

Measured memory_bytes: 9188
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second
#define dbg(x) cout<<#x" = "<<((x))<<endl
template<class T,class U> ostream& operator<<(ostream& o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream& o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

const ll mod = 1e9+7;

int len[11][91][201][201];

int ct[5]={};
ll sum[5]={};

inline int LEN(int x){
    if(x==0) return 0;
    if(x<10) return 1;
    if(x<100) return 2;
    if(x<1000) return 3;
    return 4;
}

ll f[202];
ll C[202][202];

ll pre_P[202];

ll TEN[2000];


ll mod_pow(ll x, ll n){
    ll ret = 1;
    while(n){
        if(n&1) (ret*=x)%=mod;
        (x*=x)%=mod;
        n>>=1;
    }
    return ret;
}

ll mod_inv(ll x){
    return mod_pow(x,mod-2);
}


int main(){
    f[0] = 1;
    rep(i,202-1) f[i+1] = (f[i]*(i+1))%mod;

    rep(i,202){
        rep(j,i+1){
            C[i][j] = f[i];
            (C[i][j] *= mod_inv(f[j])) %= mod;
            (C[i][j] *= mod_inv(f[i-j])) %= mod;
        }
    }

    rep(i,202){
        rep(j,i+1) (pre_P[i] += (f[i]*mod_inv(f[i-j]))%mod) %= mod;
    }

    TEN[0] = 1;
    rep(i,2000-1) TEN[i+1] = (TEN[i]*10)%mod;

    int n;
    cin >>n;
    vector<int> a(n);
    rep(i,n) cin >>a[i];

    rep(i,n){
        ++ct[LEN(a[i])];
        sum[LEN(a[i])] += a[i];
    }

    ll ans = 0;
    for(int d=1; d<=4; ++d){
        --ct[d];

        ll p = 0;
        rep(i0,ct[0]+1)rep(i1,ct[1]+1)rep(i2,ct[2]+1)rep(i3,ct[3]+1)rep(i4,ct[4]+1){
            int L = i0 + i1 + 2*i2 + 3*i3 + 4*i4;

            ll add = 1;
            (add *= C[ct[1]][i1]) %= mod;
            (add *= C[ct[2]][i2]) %= mod;
            (add *= C[ct[3]][i3]) %= mod;
            (add *= C[ct[4]][i4]) %= mod;

            int rsz = i0+i1+i2+i3+i4;
            (add *= f[rsz]) %= mod;

            // 全部選ぶ必要はない
            int lsz = n-1-rsz;
            if(ct[0]==1 && i0==0) (add *= (pre_P[lsz]-pre_P[lsz-1]+mod)%mod) %= mod;
            else (add *= pre_P[lsz]) %= mod;

            (p += (TEN[L]*add)%mod) %= mod;
        }

        (ans += sum[d]*p) %= mod;
        ++ct[d];
    }
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 3448
//killer_R@$tog!
#include<bits/stdc++.h>
using namespace std;
#define hell 1000000007
#define pb push_back
#define rep(i,a,b) for(ll i=a;i<b;i++)
#define rrep(i,a,b) for(ll i=a-1;i>=b;i--)
#define mp make_pair
#define fi first
#define se second
#define ub upper_bound
#define lb lower_bound
#define ll long long int
#define N 100009
#define all(b) b.begin(),b.end();
//int pr[N];
//int seg[N];
/*int query(int l,int r,int sl,int sr,int p)
{
    if(r<sl || l>sr)
        return 0;
    if(sr<=r && sl>=l)
        return seg[p];
    int m=sl+(sr-sl)/2;
    return (__gcd(query(l,r,sl,m,2*p+1),query(l,r,m+1,sr,2*p+2)));
}

int build(int l,int r,int p,int arr[])
{
    if(l==r)
    {
        seg[p]=arr[l];
        return seg[p];
    }
    int m=l+(r-l)/2;
    seg[p]=__gcd(build(l,m,2*p+1,arr),build(m+1,r,2*p+2,arr));
    return seg[p];
}
void isprime()
{
    memset(pr,1,sizeof(pr));
    pr[1]=0;
    for(int i=2;i*i<=N;i++)
    {
        if(pr[i])
        {
            for(j=i*i;j<=N;j+=i)
            {
                pr[j]=0;
            }
        }
    }
}*/
void killer()
{
    int n,k;cin>>n>>k;int a[n+3],dp[n+3]={0};
    rep(i,0,n)cin>>a[i];
    rep(i,1,n)
    {int g=INT_MAX;
        for(int j=1;j<=k && i-j>=0;j++)
        g=min(abs(a[i]-a[i-j])+dp[i-j],g);
        dp[i]=g;
    }
    cout<<dp[n-1];
    return;
}
int main()
{
    /*#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif*/
    //int h=(int)ceil(log2(n));
    //h=2*(int)pow(2,h)-1;
    //build(0,n-1,0,a);

    ll t;
    //cin>>t;
    t=1;
    while(t--)
        killer();

    return 0;
}

Measured memory_bytes: 1024
#include<iostream>
#include<queue>
#include<vector>
#include<cmath>
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1e9
using namespace std;
struct S{
	vector<int> his;
	int p; double d;
	bool operator<(const S &a)const{
		return d<a.d;
	}
};
int main(){
	int n,m,s,g;
	while(cin>>n,n){
		double d[n][n],x[n],y[n],cost[n]; int id[n],b[1001];
		rep(i,n)cin>>id[i]>>x[i]>>y[i],b[id[i]]=i;
		rep(i,n)rep(j,n)d[i][j]=hypot(x[i]-x[j],y[i]-y[j]);
		for(cin>>m;m--;){
			cin>>s>>g;
			S cs,ns; cs.p=b[s]; cs.his.push_back(s);
			priority_queue<S> F; F.push(cs); vector<int> ans;
			rep(i,n)cost[i]=INF; cost[cs.p]=0;
			while(!F.empty()){
				cs=F.top(); F.pop();
				rep(i,n)if(0<d[cs.p][i]&&d[cs.p][i]<=50)if(cost[i]>(ns.d=cost[cs.p]+d[cs.p][i])){
					cost[i]=ns.d, ns.p=i, ns.his=cs.his, ns.his.push_back(id[i]);
					F.push(ns);
					if(i==b[g])ans=ns.his;
				}
			}
			if(cost[b[g]]==INF)cout<<"NA"<<endl;
			else rep(i,ans.size())cout<<ans[i]<<(i==ans.size()-1?"\n":" ");
		}
	}
	return 0;
}

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

#define mp make_pair

using namespace std;

typedef int32_t i32;
typedef uint32_t u32;
typedef int64_t i64;
typedef uint64_t u64;
typedef pair<int,int> pii;
typedef pair<i64,int> pli;
typedef pair<int,i64> pil;
typedef pair<i64,i64> pll;
typedef vector<int> vi;
typedef vector<i64> vl;

template <typename T>
T id(T b) {return b;};
template <class It>
bool all(It f,It l){return std::all_of(f,l,id<bool>);}
template <class It>
bool any(It f,It l){return std::any_of(f,l,id<bool>);}

const int M = 1000000;
i64 n, p;
i64 cnt[M+1] = {};

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

  if (n == 1) {
    cout << p << endl;
    return 0;
  }

  for (i64 i = 2; i*i <= p; i++) {
    while (p % i == 0) {
      cnt[i]++;
      p /= i;
    }
  }

  i64 res = 1;
  for (i64 i = 0; i <= M; i++) {
    while (cnt[i] >= n) {
      res *= i;
      cnt[i] -= n;
    }
  }

  cout << res << endl;

  return 0;
}


Measured memory_bytes: 256
///////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////
//                       _oo0oo_                         //
//                      o8888888o                        //
//                      88" . "88      ------ hzt1       //
//                      (| -_- |)                        //
//                      0\  =  /0                        //
//                    ___/`---'\___                      //
//                  .' \|     |// '.                     //
//                 / \|||  :  |||// \                    //
//                / _||||| -:- |||||- \                  //
//               |   | \  -  /// |     |                 //
//               | \_|  ''\---/''  |_/ |                 //
//               \  .-\__  '-'  ___/-. /                 //
//             ___'. .'  /--.--\  `. .'___               //
//          ."" '<  `.___\_<|>_/___.' >' "".             //
//         | | :  `- \`.;`\ _ /`;.`/ - ` : | |           //
//         \  \ `_.   \_ __\ /__ _/   .-` /  /           //
//     =====`-.____`.___ \_____/___.-`___.-'=====        //
//                       `=---='                         //
//                                                       //
//                                                       //
//     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~       //
//                                                       //
//                 God-He Bless All.                     //
//           This Code Will Never Explode.               //
//                                                       //
//                                                       //
///////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////
#include<cstdio>
#include<cstring>
#include<cctype>
#include<algorithm>
#define rep(i,a,b) for(int i=(a),i##_end_=(b);i<=i##_end_;i++)
#define dwn(i,a,b) for(int i=(a),i##_end_=(b);i>=i##_end_;i--)
using namespace std;
inline int read() {
    int x=0,f=1;char c=getchar();
    for(;!isdigit(c);c=getchar()) if(c=='-') f=-1;
    for(;isdigit(c);c=getchar()) x=x*10+c-'0';
    return x*f;
}
typedef long long ll;
const int maxn=100010;
int n,m,a[maxn],P[maxn],T[maxn];
ll k,ans[maxn],x[maxn];
int tmp[maxn];
void mul(int* A,int* B,int* C) {
	rep(i,1,n) tmp[i]=A[B[i]];
	rep(i,1,n) C[i]=tmp[i];
}
int main() {
	n=read();
	rep(i,1,n) x[i]=read();
	rep(i,1,n) P[i]=T[i]=i,ans[i]=x[i]-x[i-1];
	m=read();scanf("%lld",&k);
	rep(i,1,m) {
		int a=read();
		swap(P[a],P[a+1]);
	}
	for(;k;k>>=1,mul(P,P,P)) if(k&1) mul(P,T,T);
	rep(i,1,n) printf("%lld\n",x[i]=x[i-1]+ans[T[i]]);
	return 0;
}


Measured memory_bytes: 3968
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.List;
import java.util.Queue;

public class Main {
	public static void main(String[] args) throws Exception {
		long t = System.currentTimeMillis();
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int n = Integer.parseInt(br.readLine());
		List<Queue<Integer>> list = new ArrayList<>(n);
		for (int i = 0; i < n; i++) {
			String[] sa = br.readLine().split(" ");
			Queue<Integer> que = new ArrayDeque<>();
			list.add(que);
			for (int j = 0; j < sa.length; j++) {
				que.add(Integer.parseInt(sa[j]) - 1);
			}
		}
		br.close();

		int ans = 0;
		while (true) {
			if (System.currentTimeMillis() - t > 1800) {
				System.out.println(n * (n - 1) / 2);
				return;
			}
			ans++;
			boolean[] flg = new boolean[n];
			boolean flg2 = false;
			boolean[] flg3 = new boolean[n];
			for (int i = 0; i < n; i++) {
				if (flg[i]) {
					continue;
				}
				Queue<Integer> que = list.get(i);
				if (que.isEmpty()) {
					flg3[i] = true;
					continue;
				}
				int o = que.peek();

				if (flg[o]) {
					continue;
				}
				Queue<Integer> que2 = list.get(o);
				if (que2.isEmpty()) {
					flg3[o] = true;
					continue;
				}
				int o2 = que2.peek();

				if (o2 == i) {
					que.poll();
					que2.poll();
					flg[o] = true;
					flg[o2] = true;
					flg2 = true;
					if (que.isEmpty()) {
						flg3[i] = true;
					}
					if (que2.isEmpty()) {
						flg3[o] = true;
					}
				}
			}
			boolean flg4 = true;
			for (int i = 0; i < n; i++) {
				if (!flg3[i]) {
					flg4 = false;
					break;
				}
			}
			if (flg4) {
				break;
			}
			if (!flg2) {
				System.out.println(-1);
				return;
			}
		}
		System.out.println(ans);
	}
}


Measured memory_bytes: 110124
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <numeric>
#include <cstdint>
#include <iomanip>
using ll = long long;
#define fast_io(); std::ios_base::sync_with_stdio(0); std::cin.tie(0); std::cout.tie(0);

int main(){
    std::string s; std::cin >> s;
    for(int i=0; i<s.size()-1; i++){
        for(int j=i+1; j<s.size(); j++){
            if(s[j]==s[i]){
                std::cout << "no" << "\n";
                return 0;
            }
        }
    }
    std::cout << "yes" << "\n";
    return 0;
}


Measured memory_bytes: 256
#include"bits/stdc++.h"
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
#define INF 1e+9


int main() {
	int h, w, x[501][501],move=0,x1[300000],x2[300000],y1[300000],y2[300000];
	cin >> h >> w;
	for (int i = 0; i < h; i++)
		for (int j = 0; j < w; j++)
			cin >> x[i][j];

	for (int i = 0; i < h; i++)
	{
		if(i%2==0)
			for (int j = 0; j < w; j++)
			{
				if(j!=w-1)
					if (x[i][j] % 2 == 1)
					{
						x1[move] = j+1;
						y1[move] = i + 1;
						x2[move] = j + 2;
						y2[move] = i + 1;
						move++;
						x[i][j + 1]++;
					}
					else move += 0;
				else
					if (x[i][j] % 2 == 1)
					{
						if (i == h - 1 && j == w - 1) break;
						x1[move] = j + 1;
						y1[move] = i + 1;
						x2[move] = j + 1;
						y2[move] = i + 2;
						move++;
						x[i+1][j]++;
					}
					else move += 0;

			}
		else
			for (int j = w-1; j >=0; j--)
			{
				if (j !=0)
					if (x[i][j] % 2 == 1)
					{
						x1[move] = j + 1;
						y1[move] = i + 1;
						x2[move] = j ;
						y2[move] = i + 1;
						move++;
						x[i][j - 1]++;
					}
					else move += 0;
				else
					if (x[i][j] % 2 == 1)
					{
						if (i == h - 1 && j == 0) break;
						x1[move] = j + 1;
						y1[move] = i + 1;
						x2[move] = j + 1;
						y2[move] = i + 2;
						move++;
						x[i + 1][j]++;
					}
					else move += 0;

			}
	}

	cout << move << endl;
	for (int i = 0; i < move; i++)
	{
		cout << y1[i] << " " << x1[i] << " " << y2[i] << " " << x2[i] << endl;
	}


	return 0;
}

Measured memory_bytes: 7552
#include <iostream>
#include <algorithm>
#include <math.h>
#include <vector>
#include <string>
#include <queue>
#include <map>
#include <utility>
#include <iomanip>  // std::setprecision()
#include <set>
using namespace std;
using ll = long long;
#define rep(i,a,b) for(ll i=(a); i<(b); i++)
#define YES cout << "YES" << endl;
#define NO cout << "NO" << endl;
#define yes cout << "Yes" << endl;
#define no cout << "No" << endl;
#define pai 3.14159265358979323846
ll gcd(ll a, ll b){if (a%b == 0)  return(b);else  return(gcd(b, a%b));}
ll lcm(ll a, ll b){return a * b / gcd(a, b);}
/* map<string,int> */
/* 大文字を小文字に変換 tolower*/
/* 小文字を大文字に変換 toupper*/
/* 辞書順 next_permutation(a.begin(),a.end()) */
 
int main() {
    int k;
    cin >> k;
    int x = 7%k;
    set<int> s;
    int count =1;
    while (s.count(x) == 0) {
        if (x == 0) {
            cout << count << endl;
            return 0;
        }
        s.insert(x);
        x = (x * 10 + 7) %k;
        count++;
    }
    cout << -1 << endl;
    return 0;
}

Measured memory_bytes: 49996
#include <bits/stdc++.h> //全ての標準ライブラリ
#define rep(i,n) for(int i = 0;i < n;i++)
using namespace std;
int sumVector (const std::vector<int>& v){ //int配列計算
    int sum = 0;
    rep(i, v.size()) sum += v.at(i);
    return sum; 
}
int main(void){
    long long n, k,minimum;
    cin >> n >> k;
    if(n < k) {
        minimum = min(abs(n-k),n);
    }
    
    if(n == k){
        minimum = 0;
    }
    
    if(n > k){
    minimum = min(n % k, abs(n%k - k));
    }
    cout << minimum;
}

Measured memory_bytes: 256
#include <stdio.h>  
#include <algorithm>  
#include <assert.h>
#include <bitset>
#include <cmath>  
#include <complex>  
#include <deque>  
#include <functional>  
#include <iostream>  
#include <limits.h>  
#include <map>  
#include <math.h>  
#include <queue>  
#include <set>  
#include <stdlib.h>  
#include <string.h>  
#include <string>  
#include <time.h>  
#include <unordered_map>  
#include <unordered_set>  
#include <vector>  
#include <chrono>
#include <random>
#include <time.h>
#define ll long long
#define rep2(i,a,b) for(ll i=a;i<=b;++i)
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep3(i,a,b) for(ll i=a;i>=b;i--)
#define REP(e,v) for(auto e:v)
#define pii pair<int,int>
#define pll pair<ll,ll>
#define tii tuple<int,int,int>
#define pq priority_queue<int>
#define pqg priority_queue<int,vector<int>,greater<int>>
#define pb push_back
#define edge(v,a,b) v[a].pb(b);v[b].pb(a);
#define MAX_V 400010
#define vec vector<int>
#define vecll vector<ll>
#define vecpii vector<pii>
#define endl "\n"
#define ALL(c) (c).begin(),(c).end()
using namespace std;
int in() {int x;scanf("%d",&x);return x;}
ll lin() {ll x;scanf("%lld",&x);return x;}

#define INF 1e9+7
#define LLINF 1e18+7
ll MOD=1e9+7;
#define N 310000
ll a[N],b[N],c[N];
int main(){
    int x=in(),y=in(),z=in(),k=in();
    rep(i,x)a[i]=lin();
    rep(i,y)b[i]=lin();
    vector<ll> sum;
    rep(i,x)rep(j,y)sum.pb(a[i]+b[j]);
    sort(ALL(sum),greater<>{});
    vector<ll> ans;
    rep(i,z)c[i]=lin();
    int kk=min(k,(int)sum.size());
    rep(i,z)rep(j,kk)ans.pb(sum[j]+c[i]);
    sort(ALL(ans),greater<>{});
    rep(i,k)cout<<ans[i]<<endl;
}


Measured memory_bytes: 47332
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <utility>
#include <tuple>
#include <algorithm>
#include <cstdio>
#include <cmath>
using namespace std;

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

int main() {
  int sx, sy, tx, ty;
  cin >> sx >> sy >> tx >> ty;
  for(int i = sy; i < ty; i++)
    cout << 'U';
  for(int i = sx; i < tx; i++)
    cout << 'R';
    
  for(int i = ty; i > sy; i--)
    cout << 'D';
  for(int i = tx; i > sx; i--)
    cout << 'L';
  
  cout << 'L';
  for(int i = sy; i < ty+1; i++)
    cout << 'U';
  for(int i = sx-1; i < tx; i++)
    cout << 'R';
  cout << 'D';
  
  cout << 'R';
  for(int i = ty; i > sy-1; i--)
    cout << 'D';
  for(int i = tx+1; i > sx; i--)
    cout << 'L';
  cout << 'U';
  
  return 0;
}

Measured memory_bytes: 256