akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <queue>
#include <map>
#include <algorithm>
using namespace std;

typedef pair<int,int> P;
const int INF = 1e+8;
// 入力
int w, h, n;
char c[1001][1001];
// 4近傍
int dx[4] = {0,0,-1,1};
int dy[4] = {-1,1,0,0};
// d[y][x] := スタートから(x,y)までの最短距離 (未探索のときは INF )
int d[1001][1001];

// 文字 s から文字 s+1 までの最短距離を返す. (s は'0'-'8')
int bfs(char s){
	int sx, sy, gx, gy;
	// 初期化とスタート位置とゴール位置を探す.
	for(int y=0 ; y < h ; y++ ){
		for(int x=0 ; x < w ; x++ ){
			d[y][x] = INF;
			if( c[y][x] == s ){
				sx = x;
				sy = y;
			}
			if( c[y][x] == s+1 ){
				gx = x;
				gy = y;
			}
		}
	}
	// スタート位置をキューに入れる
	queue<P> q;
	q.push( P(sx,sy) );
	d[sy][sx] = 0;
	int res = INF;
	while( !q.empty() ){
		int x = q.front().first;
		int y = q.front().second;
		int cost = d[y][x];
		q.pop();
		
		// ゴールのとき
		if( x == gx && y == gy ){
			res = cost;
			break;
		}
		
		// 4方向探索
		for(int i=0 ; i < 4 ; i++ ){
			int mx = x + dx[i];
			int my = y + dy[i];
			if( mx < 0 || my < 0 || w <= mx || h <= my ) continue;
			if( c[my][mx] == 'X' ) continue;
			
			if( cost+1 < d[my][mx] ){
				d[my][mx] = cost + 1;
				q.push( P(mx,my) );
			}
		}
	}
	return res;
}

int main(){
	cin >> h >> w >> n;
	for(int y=0 ; y < h ; y++ ){
		cin >> c[y];
	}
	// 処理しやすいように 'S' を '0' に置き換える.
	for(int y=0 ; y < h ; y++ ){
		for(int x=0 ; x < w ; x++ ){
			if( c[y][x] == 'S' ) c[y][x] = '0';
		}
	}
	int ans = 0;
	for(int i=0 ; i < n ; i++ ){
		ans += bfs(i+'0');
	}
	cout << ans << endl;
}

Measured memory_bytes: 6116
open System.Linq
open System.Text.RegularExpressions

let input() = stdin.ReadLine()
let inputs() = input().Split()

let YN b = printfn "%s" (if b then "Yes" else "No")
let print x = printfn "%A" x
let printS (s: string) = printfn "%s" s

let f n = [ 1 .. 2 .. n ].Count(fun k -> n % k = 0)

let N = int (input())


[ 1 .. 2 .. N ].Count(fun k -> f k = 8) |> print


Measured memory_bytes: 16088
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"
#include "numeric"
#include "cassert"
#include "ctime"

using namespace std;

//constexpr long long int MOD = 1000000007;
//constexpr int MOD = 1000000007;
//constexpr int MOD = 998244353;
constexpr long long int MOD = 998244353;
constexpr double EPS = 1e-9;

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

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

	cin >> N;
	vector<int>ans(N);
	vector<int>v(N);
	for (auto &i : v)cin >> i;
	for (int i = 1; i < N; i++) {
		ans[i] = v[0] ^ v[i];
	}
	int box = v[0];
	for (int i = 1; i < N; i++)box ^= ans[i];
	for (auto &i : ans)i ^= box;
	for (auto i : ans)cout << i << " ";
	cout << endl;
}


Measured memory_bytes: 4744
#include<bits/stdc++.h>
using namespace std;
int main() {
    int N;
    string S;
    cin >> N >> S;
    for(int i = 0; i < S.size(); i++){
        S[i]=(S[i]-'A'+N+26)%26+'A';
    }
    cout << S << endl;
}

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

using namespace std; 

int main () {
	int T; string S; cin >> T >> S;
  	if (S.size() > T) {
    	for (int i=0; i < T; i++) {
        	cout << S[i];
        }
    	cout << "...";
    } else {
    	cout << S;
    }
}

Measured memory_bytes: 3628
/* https://atcoder.jp/contests/abc093/tasks/arc094_a */

#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>

int solve(const int A, const int B, const int C)
{
  int cnt = 0;
  std::vector<int> vals = {A, B, C};
  int max_val = *std::max_element(vals.begin(), vals.end());
  int max_val_triple = max_val*3;
  int sum_vals = std::accumulate(vals.begin(), vals.end(), 0);

  if (sum_vals%2 != max_val_triple%2) {
    max_val_triple += 3;
  }

  int diff = max_val_triple - sum_vals;
  cnt += diff/2 + diff%2;

  return cnt;
}

int main(int argc, char *argv[])
{
  // Input
  int A, B, C;

  std::cin >> A >> B >> C;

  // Output
  std::cout << solve(A, B, C) << std::endl;

  return 0;
}


Measured memory_bytes: 256
import os
import os
from collections import defaultdict

import sys

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(10 ** 9)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7


# MOD = 998244353

def argsort(li, key=None, reverse=False):
    return [i for _, i in sorted(
        [(a, i) for i, a in enumerate(li)], key=(lambda t: key(t[0])) if key else None, reverse=reverse
    )]


N = int(sys.stdin.buffer.readline())
A = list(map(int, sys.stdin.buffer.readline().split()))

order = argsort(A)[::-1]
dp = [defaultdict(int) for _ in range(N + 1)]
l = 0
r = N - 1
dp[0][l, r] = 0
for i, p in enumerate(order):
    for (l, r), v in dp[i].items():
        dp[i + 1][l + 1, r] = max(dp[i + 1][l + 1, r], v + A[p] * abs(p - l))
        dp[i + 1][l, r - 1] = max(dp[i + 1][l, r - 1], v + A[p] * abs(p - r))
print(max(dp[-1].values()))


Measured memory_bytes: 208728
#include<iostream>
#include<cstdio>
#include<cstring>
#include<queue>
#include<stack>
#include<cmath>
#include<algorithm>
#include<map>
typedef long long ll;
using namespace std;
#define INF 0x3f3f3f3f
/**
*超时有可能是输入的问题
*注意边界
*仔细读题
*没思路试试逆向思维
**加油，奥利给！！！ 
**/
int a[200000];
int main()
{
	int m,n,i,j,t=0,k;
	int s=0;
	cin>>n>>m;
	for(i=1;i<=n;i++)
	{
		cin>>a[i];
		s+=a[i];
		
	}

	for(i=1;i<=n;i++)
	{
		if(a[i]*4*m>=s) t++;
	}
	if(t<m) cout<<"No";
	else cout<<"Yes";
	
 } 

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

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

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

	sort(s.begin(), s.end());
	if(ans % 10 == 0){
		for(int i = 0; i < n; i++)
		{
			if(s[i] % 10 != 0){
				ans -= s[i];
				break;
			}
			if(i == n-1){
				ans = 0;
			}
		}
	}
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String []args){
		//????????£????????????
		Scanner sc =  new Scanner(System.in);
		//n??????
		int n = sc.nextInt();
		//?????????
		int m =sc.nextInt();
		//?????? n???m???A ??????
		int [][] A= new int[n][m] ;
		//??? ????????????
		int [] b= new int [m];
		//n*????????????a???????´?
		for(int i = 0; i < n; i++){
			for(int j= 0; j < m; j++){
				//??????????????\???????????????????´?
				A[i][j] = sc.nextInt();
			}
		}
		//
		for(int j =0;j < m; j++){
			//??????????????\???????????????????´?
			b[j] = sc.nextInt();
		}

		//
		for(int i =0; i< n; i++){
			int sum =0;
			for(int j =0; j<m; j++){
				//A??¨?????????????¨????
				sum += A[i][j] * b[j];
			}
			//sum =+ sum;
			System.out.println(sum);
		}
	}
}

Measured memory_bytes: 40396
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LINF = 1e18;
inline ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
inline ll lcm(ll a, ll b) { return a / gcd(a, b)*b; }
template<class S,class T> ostream& operator << (ostream& out,const pair<S,T>& o){ out << "(" << o.first << "," << o.second << ")"; return out; }
template<class T> ostream& operator << (ostream& out,const vector<T>& V){ for(int i = 0; i < V.size(); i++){ out << V[i]; if(i!=V.size()-1) out << " ";} return out; }
template<class T> ostream& operator << (ostream& out,const vector<vector<T> >& Mat){ for(int i = 0; i < Mat.size(); i++) { if(i != 0) out << endl; out << Mat[i];} return out; }
template<class S,class T> ostream& operator << (ostream& out,const map<S,T>& mp){ out << "{ "; for(auto it = mp.begin(); it != mp.end(); it++){ out << it->first << ":" << it->second; if(mp.size()-1 != distance(mp.begin(),it)) out << ", "; } out << " }"; return out; }
template<typename T>vector<T> make_v(size_t a){return vector<T>(a);}
template<typename T,typename... Ts>auto make_v(size_t a,Ts... ts){return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));}
template<typename T,typename V> typename enable_if<is_class<T>::value==0>::type fill_v(T &t,const V &v){t=v;}
template<typename T,typename V> typename enable_if<is_class<T>::value!=0>::type fill_v(T &t,const V &v){for(auto &e:t) fill_v(e,v);}
/*
 <url:>
 問題文============================================================
 =================================================================
 解説=============================================================
 ================================================================
 */

template<class Type>
Type solve(Type res = Type()){
    int N; cin >> N;
    vector<int> b(N); for(auto& in:b) cin >> in;

    vector<int> ans;

    while(b.size()){
        bool ok = false;
        for(int j = (int)b.size()-1; j >= 0; j--){
            if(b[j] == (j+1)){
                ok = true;

                b.erase(b.begin()+j);
                ans.emplace_back(j+1);
                break;
            }
        }
        if(!ok){
            cout << -1 << endl;
            return res;
        }
    }
    reverse(ans.begin(),ans.end());
    for(auto v:ans){
        cout << v << endl;
    }
    return res;
}
int main(void) {
    cin.tie(0); ios::sync_with_stdio(false);
    solve<ll>(0);
    // cout << fixed << setprecision(12) << solve<ll>() << endl;
    return 0;
}

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

int main(){
  string S;cin>>S;
  int mod=2019;
  vector<int> T(S.size()+1);
  vector<int> C(2019,0);
  T[S.size()]=0;
  vector<int> ruimod(200001,0);
  ruimod[0]=1;
  for(int i=1;i<200001;i++){
    ruimod[i]=(ruimod[i-1]*10)%mod;
  }
  for(int i=S.size()-1;i>=0;i--){
    T[i]=(T[i+1]+(S[i]-'0')*ruimod[S.size()-i-1])%mod;
  }
  for(int i=0;i<=S.size();i++){
    C[T[i]]++;
  }
  int cnt=0;
  for(int i=0;i<2019;i++){
    if(C[i]>=2)cnt+=(C[i]*(C[i]-1))/2;
  }
  cout<<cnt<<endl;
}


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

int main() {
	int n;
	cin>>n;
	vector<int> a(n);
	vector<int> ans(n);
	for(int i=0;i<n;i++)
	{
		cin>>a[i];
		int count=0;
		while(a[i]%2==0)
		{
			a[i] = a[i]/2;
			count++;
		}
		ans[i] = count;
	}
	cout<<*min_element(ans.begin(),ans.end());
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll  long long int
#define ull unsigned long long 
#define ff first
#define ss second
#define fast ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define pb push_back 
#define mp make_pair
#define inf 1000000000000000
#define mod 1000000007
#define ld long double
#define pll pair<ll,ll>
using namespace std;
const ll use=1e18;
ll a,b,c,d;
map<ll,ll>mapp;

ll fun(ll n)
{
    if(n==0)return 0;
    if(n==1)return d;
    if(mapp.find(n)!=mapp.end())return mapp[n];

    ll v1=(n/2)*2,v2=((n+1)/2)*2,v3=(n/3)*3,v4=((n+2)/3)*3,v5=(n/5)*5,v6=((n+4)/5)*5;

    ll ans=use;
    if(n<use/d)ans=n*d;

    ans=min(ans,(n-v1)*d+a+fun(v1/2));
    ans=min(ans,(v2-n)*d+a+fun(v2/2));
    ans=min(ans,(n-v3)*d+b+fun(v3/3));
    ans=min(ans,(v4-n)*d+b+fun(v4/3));
    ans=min(ans,(n-v5)*d+c+fun(v5/5));
    ans=min(ans,(v6-n)*d+c+fun(v6/5));

    return mapp[n]=ans;
}


int main()
{ 
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif

fast;

ll t;
cin>>t;

while(t--)
{
    ll n;
    mapp.clear();
    cin>>n>>a>>b>>c>>d;
    cout<<fun(n)<<'\n';
}
}


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

typedef long long ll;
ll h[200000], ans;
int main() {
  int n, k;
  cin >> n >> k;
  for (int i = 0; i < n; i++) {
    cin >> h[i];
  }
  sort(h, h + n);
  for (int i = 0; i < n - k; i++) {
    ans += h[i];
  }
  cout << ans << endl;
}

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

int count = 0;

void swap(long int* a, long int* b) {
    auto tmp = *b;
    *b = *a;
    *a = tmp;
}

void inssort(long int* A, int n, int g) {
    for (int i=g; i<n; i++) {
        long int v = A[i];
        int j = i - g;
        while (j>=0 and A[j] > v) {
            A[j+g] = A[j];
            j = j - g;
            count++;
        }
        A[j+g] = v;
    }
}

int g(int i) {
    return (std::pow(3, i) - 1)/2;
}

int main() {
    int N, m;
    long int A[1000000];
    std::vector<int> G;

    std::cin >> N;
    for (int i=0; i<N; i++) {
        std::cin >> A[i];
    }
    for (m = 1; g(m) < N; m++) {
        G.push_back(g(m));
    }
    m--;
    std::reverse(G.begin(), G.end());
    if (m==0) {
        m=1;
        G.push_back(1);
    }

    for (int i=0; i<m; i++) {
        inssort(A, N, G[i]);
    }

    std::cout << m << std::endl;
    for (int i=0; i<G.size(); i++) {
        std::cout << G[i];
        if (not (i == G.size()-1)) {
            std::cout << " ";
        } else {
            std::cout << std::endl;
        }
    }
    std::cout << count << std::endl;
    for (int i=0; i<N; i++) {
        std::cout << A[i] << std::endl;
    }

    return 0;
}


Measured memory_bytes: 11100
#include<iostream>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;

int n,m,p,X,Y,Z,res,b[9][9][9];
int dx[] = {1,0,0,1,1,0,-1,-1, 0,1, 1, 1,-1};
int dy[] = {0,1,0,1,0,1, 1, 0,-1,1, 1,-1, 1};
int dz[] = {0,0,1,0,1,1, 0, 1, 1,1,-1, 1, 1};

inline int check(int col){
  rep(i,n)rep(j,n)rep(k,n){
    if(b[i][j][k]==col){
      rep(t,13){
	int c=0,tx=i,ty=j,tz=k;
	while(c<m && 0<=tx && tx<n && 0<=ty && ty<n && 0<=tz && tz<n){
	  if(b[tx][ty][tz] == b[i][j][k])c++;
	  else break;
	  tx += dx[t]; ty += dy[t]; tz += dz[t];
	}
	if(c==m)return b[i][j][k];
      }
    }
  }
  return -1;
}

int main(){
  std::ios::sync_with_stdio(false);
  while(cin >> n >> m >> p,n+m+p){
    rep(i,n)rep(j,n)rep(k,n)b[i][j][k] = -1;

    bool f = true;
    rep(i,p){
      cin >> X >> Y;
      if(f){
	X--; Y--;Z=0;
	while(b[X][Y][Z]>=0)Z++;
	b[X][Y][Z] = i&1;
	
	res = check(i&1);
	if(res==0){
	  cout << "Black " << i+1 << endl;
	  f = false;
	}else if(res==1){
	  cout << "White " << i+1 << endl;
	  f = false;
	}
      }
    }
    if(f)cout << "Draw\n";
  }
}

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

#pragma warning(disable:4996)
using namespace std;


int main() {
	int H,W;cin>>H>>W;
	vector<vector<int>>field(H,vector<int>(W));
	long long int answer=0;
	for (int i = 0; i < H; ++i) {
		for (int j = 0; j < W; ++j) {
			long long int a; cin >> a;
			int l=j+1;
			int r=W-j;
			int u=i+1;
			int d=H-i;

			answer+=a*l*r*u*d;
		}
	}
	cout<<answer<<endl;
	return 0;
}



Measured memory_bytes: 3940
#include <bits/stdc++.h>
#include <string>
#include <algorithm>
#include <string.h>
#include <ctype.h>
#include <math.h>
#include <float.h>
#include <iomanip>
#include <iostream>
using namespace std;


int main(){

    string s,t;
    char a[110]={},b[110]={};

    cin >> s>>t;

    sort(s.begin(),s.end());

    sort(t.begin(),t.end());
    reverse(t.begin(),t.end());

    if(s<t){
        cout<<"Yes"<<endl;
    }else{
        cout<<"No"<<endl;
    }

    return 0;
}


Measured memory_bytes: 256
N = int(input())
H = [int(i) for i in input().split(' ')]

max_count = 0
max_i = 0

t_max_count = 0
t_max_i = 0

for i, h in enumerate(H):
  if i == (len(H) - 1):
    break
  
  migi = H[i+1]
  
  if h >= migi:
    t_max_count += 1
    t_max_i = i
  else:
    if max_count < t_max_count:
      max_count = t_max_count
      max_i = t_max_i
    t_max_count = 0
    t_max_i = 0
      
if max_count < t_max_count:
  max_count = t_max_count
  max_i = t_max_i
print(max_count)
    

Measured memory_bytes: 14228
#include                        <bits/stdc++.h>
#include                        <ext/pb_ds/assoc_container.hpp>
#define lb                      lower_bound
#define ub                      upper_bound
#define fe(x)                   *(x.begin())
#define le(x)                   *(x.rbegin())
#define pb                      push_back
#define load(node,n)            bool operator < (const node &n) const
#define fbo(x)                  find_by_order(x)
#define ook(x)                  order_of_key(x)
#define all(x)                  (x).begin(),(x).end()
#define FOR(i,n)                for(int i = 1; i<=n; i++)
#define REP(i,n)                for(int i = 0; i<n;  i++)
#define TT                      int TC;  scanf("%d",&TC);  while(TC--)
#define read                    freopen("input.txt","r",stdin)
#define write                   freopen("output.txt","w",stdout)
#define dbg(...)                debug_out(vec_splitter(#__VA_ARGS__), 0, __LINE__, __VA_ARGS__)
#define set(x)                  tree<x,null_type,less<x>,rb_tree_tag,tree_order_statistics_node_update>
using                           namespace __gnu_pbds;
using                           namespace std;
typedef                         long long ll;
typedef                         pair<ll,ll> pll;
typedef                         pair<int,int> pii;

vector<string> vec_splitter(string s){
    s += ','; vector<string> res;
    while(!s.empty()) res.push_back(s.substr(0,s.find(','))), s = s.substr(s.find(',') + 1);
    return res;
}
void debug_out(
vector<string> __attribute__ ((unused)) args,
__attribute__ ((unused))int idx,
__attribute__ ((unused)) int LINE_NUM) { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(vector<string> args, int idx, int LINE_NUM, Head H, Tail... T){
    if(idx > 0) cerr << ", "; else cerr << "Line(" << LINE_NUM << ") "; stringstream ss; ss << H;
    cerr << args[idx] << " = " << ss.str(); debug_out(args, idx + 1, LINE_NUM, T...);
}



ll a,b,n;

ll fn(ll x){
    ll p = (a*x)/b - a*(x/b);
    return p;
}


main(){
//read;

cin>>a>>b>>n;

ll l = 0,r = n,m1,m2;
ll ans = 0;
for(ll i = 0; i<1000; i++){
    m1 = l+(r-l)/3;
    m2 = r-(r-l)/3;
    ll p = fn(m1);
    ll q = fn(m2);
    ans = max({ans,p,q});
    if(p>q) r = m2;
    else l = m1;
}

cout<<ans;




return 0;
}


Measured memory_bytes: 3636
import java.io.*;
import java.util.StringTokenizer;

public class Main {

    private static FastReader in = new FastReader(System.in);
    private static PrintWriter out = new PrintWriter(System.out);

    private static final long MOD = (long) 1e9 + 7;

    public static void main(String[] args) {
        solve();
        out.flush();
    }

    private static void solve() {
        long n = in.nextLong();
        long a = in.nextLong();
        long b = in.nextLong();

        long ans = 0;
        ans = (n / (a + b)) * a;

        n %= (a + b);
        ans += Math.min(n, a);
        out.println(ans);
    }

    // https://www.geeksforgeeks.org/fast-io-in-java-in-competitive-programming/
    static class FastReader {
        BufferedReader br;
        StringTokenizer st;

        FastReader(InputStream inputStream) {
            br = new BufferedReader(new
                    InputStreamReader(inputStream));
        }

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

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

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

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

        String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }

        // https://qiita.com/masakinpo/items/5f77f2a879578a85a0bb
        public int[] nextIntArray(int n) {
            int[] a = new int[n];
            for (int i = 0; i < n; i++)
                a[i] = nextInt();
            return a;
        }

        public long[] nextLongArray(int n) {
            long[] a = new long[n];
            for (int i = 0; i < n; i++)
                a[i] = nextLong();
            return a;
        }
    }
}


Measured memory_bytes: 24916
n = int(input())
S=[]
for i in range(n):
    s=input()
    S.append(s)
from collections import Counter
c0=c1=c2=c3=0
for i in S:
    if i=="AC":
        c0+=1
    elif i=="WA":
        c1+=1
    elif i=="TLE":
        c2+=1
    elif i=="RE":
        c3+=1
print("AC x ",c0)
print("WA x ",c1)
print("TLE x ",c2)
print("RE x ",c3)

Measured memory_bytes: 16420
n = int(input())
arr = [int(i) for i in input().split()]
dp = [0 for i in range(n)]
for i in range(1,n):
    op1 = abs(arr[i]-arr[i-1]) + dp[i-1]
    op2 = abs(arr[i]-arr[i-2]) + dp[i-2] if i != 1 else float("inf")
    dp[i] = min(op1,op2)
print(dp[n-1])

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

int main()
{
    int a, b, c;
    cin >> a >> b >> c;
    a <= c && c <= b ? cout << "Yes" : cout << "No";


    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int> pi;
string s;
int n,k,c;
int L[200005];
int R[200005];
int main()
{
    cin>>n>>k>>c;
    cin>>s;
    int start=1;
    vector<int> pos;
    L[0]=-500000;
    for(int i=0;i<n;i++)
    {
        if(s[i]=='o'&&i-L[start-1]>=c+1)
        {
            L[start]=i;
            start++;
        }
    }
    R[k+1] = 500000;
    start=k;
    for(int i=n-1;i>=0;i--)
    {
        if(s[i]=='o'&&R[start+1]-i>=c+1)
        {
            R[start]=i;
            start--;
            if(start==0) break;
        }
    }
    for(int i=1;i<=k;i++)
        if(L[i]==R[i]) cout<<L[i]+1<<"\n";
}


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

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

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

struct node{ ll l,r;};


int main(){
    ll n;cin>>n;
    ll a[n+1],b[n+1];
    rep(i,1,n){
        cin>>a[i];
        b[a[i]]=i;
    }
    node no[n+1];
    rep(i,1,n){
        no[i].l=-1;
        no[i].r=-1;
    }
    ll l,r;
    ll ans=0;
    for(ll i=n;i>=1;i--){
        if(b[i]<n){
            if(no[b[i]+1].r==-1){
                r=b[i];
            }else{
                r=no[b[i]+1].r;
            }
        }else{
            r=b[i];
        }
        if(b[i]>1){
            if(no[b[i]-1].l==-1){
                l=b[i];
            }else{
                l=no[b[i]-1].l;
            }
        }else{
            l=b[i];
        }
        no[r].l=l;
        no[l].r=r;
        
        ans=ans+i*(b[i]-l+1)*(r-b[i]+1);
    }
    cout<<ans<<endl;
    return 0;
}



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

using namespace std;
const int maxn=2e5+20;
const double eps=1e-6;
int a[maxn];
int b[2];

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

 	string s;
 	cin >> s;
 	
 	char a;
 	
 	a=s[0];
 	int ans=1;
 	for(int i=1;i<s.size();i++)
 	{
 		if(s[i] == a && i!=s.size()-1)
 			i++, ans++, a='#';
 		else if(s[i]!=a)
 			ans++, a=s[i];
 	
	}
 	
 	cout << ans;
   	
	
}



Measured memory_bytes: 720
#include <stdio.h>
int main(){
  int t,n,i,h,max,min,ri,dow,x,j;
  scanf("%d",&t);
  for(i=0;i<t;i++){
    ri=0;
    dow=0;
    x=0;
    scanf("%d",&n);
    for(j=0;j<n;j++){
      scanf("%d",&h);
      if(j!=0){ if(ri<h-x){
        ri=h-x;
	}}
      if(dow<x-h){
	dow=x-h;
      }x=h;
    } printf("%d %d\n",ri,dow);
  }
  return 0;
}

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

string S;

int main() {

    ios::sync_with_stdio(0);
    cin.tie(NULL), cout.tie(NULL);

    cin >> S;

    for(int i=0; i<S.size(); )
    {
        int r = 0, l = 0;

        while(i < S.size() && S[i] == 'R')
            r++, i++;
        while(i < S.size() && S[i] == 'L')
            l++, i++;
        
        for(int j=1; j<=r-1; j++)
            cout << 0 << " ";
        
        cout << (r + 1) / 2 + l / 2 << " ";
        cout << r / 2 + (l + 1) / 2 << " ";

        for(int j=1; j<=l-1; j++)
            cout << 0 << " ";
    }

    return 0;
}


Measured memory_bytes: 720
// failed to generate code

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

const int MAX_N = 200020;
long long seg[MAX_N];
void add(int x,long long v){
    for(int i = x ; i < MAX_N ; i += i & -i ){
        seg[i] = max(seg[i], v);
    }
}

long long get(int x){
    long long ans = 0;
    for(int i = x ; i  ; i -= i & -i ){
        ans = max(ans, seg[i]);
    }
    return ans;
}
int main(){	
    ios::sync_with_stdio(false);

    int N;
    cin >> N;
    vector<int> a(N), h(N);
    for(int i = 0 ; i < N ; i++){
        cin >> h[i];
    }
    for(int i = 0 ; i < N ; i++){
        cin >> a[i];
    }
    for(int i = 0 ; i < N ; i++){
        add(h[i], get(h[i]) + a[i]);
    }

    cout << get(N) << endl;
}


Measured memory_bytes: 3456
#include<bits/stdc++.h>
using namespace std;
 
int main(){ 
  int A,B,K;
  cin >> K >> A >> B;
  if(A % K ==0)
    cout << "OK" << endl;
  else if(A == B && A%K == 0)
    cout << "OK" << endl;
 else if(A == B && A%K != 0)
    cout << "NG" << endl;
 else if(B/K - A/K >= 1)
    cout << "OK" << endl;
  else
    cout << "NG" << endl;
}

Measured memory_bytes: 3600
#include <bits/stdc++.h> //全てのヘッダファイルをインクルード
 
//ループ
#define rep(i, n) for(int i = 0; i < (n); i++) //普通のループ
#define repr(i, n) for(int i = n; i >= 0; i--) //逆ループ
 
//型名省略
typedef long long ll;
//値
static const ll MX = 100005;
static const ll MX_ll = 1e18;
const double PI = acos(-1); //π
 
using namespace std;
 
//ソート
#define SIZE_OF_ARRAY(array) (sizeof(array)/sizeof(array[0]))
 
//#include "./lib/generic/search.h"

//文字列入力した小数値を小数点なくして返す
int changeDoubleToInt(string decimal){ 
    decimal.erase(1, 1); //小数点削除
    int n_decimal = atoi(decimal.c_str()); //c_strでchar*に変換後、atoiでintに変換
    return n_decimal;
}

//最大公約数
int gcd(int a, int b){
    if(b == 0) return a;
    return gcd(b, a%b);
}

//素数判定(True/Falseを返却)
int IsPrime_tf(ll num){
    if (num < 2) return false; //0、1は素数でない
    else if (num == 2) return true; //2は素数
    else if (num%2==0) return false; // 偶数はあらかじめ除く
    for (ll i = 3; i*i <= num; i += 2){ //チェックは2～√nで十分
        if (num % i == 0) return false; //素数でない
    }
    return true; //素数である
}

//素数判定(割れる値を返却)
ll IsPrime_value(ll num){
    if (num < 2) return -1; //0、1は素数でない
    else if (num == 2) return 2; //2は素数
    for (ll i = 2; i*i <= num; i += 1){ //チェックは2～√nで十分
        if (num % i == 0) return i; //素数でない
    }
    return num; //素数である
}

int main(){
   int x;
   cin >> x;
   if(x>=30) cout << "Yes" << endl;
   else  cout << "No" << endl;
   return 0;
}

Measured memory_bytes: 3596
import java.util.Scanner;
public class Main{
	private static Scanner sc;
	public static void main(String[] args) {
		sc = new Scanner(System.in);
		String S = sc.next();
		String K = S;
		int i = 0;
		int j=0;
		int p=0;
		int sum;
		for(i=0;i<S.length();i++){
			char s = S.charAt(i);
			if(s =='A')break;	
		}
		for(j=i;j<S.length();j++){
			char s1 = K.charAt(j);
			if(s1 =='Z')p=j;		
		}
		sum=(p+1)-(i+1)+1;
		System.out.println(sum);
	}
}


Measured memory_bytes: 26524
#include <iostream>
#include <algorithm>
#include<cstring>
#include<cstdio>
using namespace std;
int main()
{
    string a[1000];
    int n,m;
    cin >> n >> m;
    for(int i = 0;i < n;i++)
    {
        cin >> a[i];
    }
    sort(a,a+n);
    for(int i = 0;i < n;i++)
    {
        cout << a[i];
    }
}





Measured memory_bytes: 256
#include <stdio.h>

int main(void) {
	int a[10000]={},i,j;
	i=0;
	while(1){
		scanf("%d",&a[i]);
		if(a[i]==0){
			break;
		}
		i++;
	}
	for(j=0;j<i;j++){
	printf("Case %d: %d\n",j+1,a[j]);
	}
	return 0;
}


Measured memory_bytes: 2100
X = int(input())
A = list(map(int, input().split()))
list.sort(A, reverse=True)
B=0
C=0
ans = 0
for i,j in enumerate(A):
    if (i+1)%2 != 0:
        B+=j
    else :
        C+=j
ans = B-C
print(ans)
    




Measured memory_bytes: 61912
"use strict";
function main(input) {
    const line = input.split("\n");
    const K = parseInt(line[0]);
    const S = line[1];
    if (S.length <= K) {
        console.log(S);
    } else {
        console.log(S.slice(0, K) + "...");
    }
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 30164
#include <bits/stdc++.h>
using namespace std;
using pii=pair<int,int>;
using ll=long long;
using pll=pair<ll,ll>;

#define fi first
#define se second
#define pb push_back
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define MOD 1000000007

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

int main() {
	int N;
	cin >> N;
	vector<ll> A(N);
	ll a=0,b=0,c=0;
	rep(i,N) {
		cin >> A[i];
		if(A[i] % 4 == 0) a++;
		else if(A[i] % 2 == 0) b++;
		else c++;
	}
	//cout << a << " " << b << " " << c << endl;
	if(a+1 < c) {
		cout << "No" << endl;
		return 0;
	}
	if(a+1 == c && b > 0) {
		cout << "No" << endl;
		return 0;
	}
	cout << "Yes" << endl;

  return 0;
}


Measured memory_bytes: 1024
#include <cstdio>
#include <algorithm>

using namespace std;

int main()
{
        int n;
        int time[10000];
        int tmp;
        long long tmp_2;
        long long wait_time;

        while (1){
                scanf("%d", &n);

                if (n == 0){
                        break;
                }

                for (int i = 0; i < n; i++){
                        scanf("%d", &time[i]);
                }

                sort(time, time + n);

                wait_time = tmp_2 = 0;

                for (int i = 0; i < n - 1; i++){
                        tmp_2 += time[i];
                        wait_time += tmp_2;
                }

                printf("%lld\n", wait_time);
        }

        return (0);
}

Measured memory_bytes: 1080
#include <iostream>
#include <iomanip>
#include <string>
#include <algorithm>
#include <set>

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

using namespace std;

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

    set<int> snackHas;
    rep(i, k)
    {
        int d;
        cin >> d;
        rep(j, d)
        {
            int snk;
            cin >> snk;
            snackHas.insert(snk);
        }
    }
    
    cout << n - snackHas.size() << endl;
    return 0;
}


Measured memory_bytes: 3628
#include <algorithm>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

#define CLOOP        while (true)
#define FLOOP(i, n)  for (int i = 0; i < (n); i++)
#define FOR(i, f, l) for (int i = (f); i < (l); i++)
#ifdef DEBUG
#define DUMP(var)   cerr << "[DEBUG] " << #var << ": " << var << endl
#else
#define DUMP(var)
#endif

#define LL long long

using namespace std;

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

    string str;
    long long sum = 0;
    cin >> str;

    for (char& c : str) {
        sum += (int)(c-'0');
    }

    DUMP(sum);
    if (sum % 9 == 0)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;

    return 0;
}


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

using namespace std;

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

  long long p1, p2, p3, p4;

  p1 = a * c;
  long long max = p1;
  p2 = a * d;
  if (max < p2) max = p2;
  p3 = b * c;
  if (max < p3) max = p3;
  p4 = b * d;
  if (max < p4) max = p4;

  cout << max << endl;
}


Measured memory_bytes: 3616
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
//#include <atcoder/all>
using namespace std;
#define all(n) begin(n), end(n)
const long long INF = numeric_limits<long long>::max();
typedef long long ll;
typedef vector<int> vint;
typedef vector<vector<int>> vvint;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef unsigned long long ull;
template <class T>
bool chmax(T &a, const T &b)
{
    if (a < b)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T &a, const T &b)
{
    if (b < a)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <typename T>
vector<T> make_v(size_t a) { return vector<T>(a); }

template <typename T, typename... Ts>
auto make_v(size_t a, Ts... ts)
{
    return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}
template <typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type
fill_v(T &t, const V &v) { t = v; }

template <typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type
fill_v(T &t, const V &v)
{
    for (auto &e : t)
        fill_v(e, v);
}
int main()
{
ios::sync_with_stdio(false);cin.tie(0);
    string s;
    cin>>s;
    cout<<s;
    if(s.back() == 's')
    {
        cout<<"es";
    }else
    {
        cout<<"s";
    }
    
    return 0;
}

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


int main() {
	int n, x;
	cin >> n >> x;
	vector<int>m(n);
	int sum = 0;
	for (int i = 0;i < n;i++) {
		cin >> m[i];
		sum += m[i];
	}

	sort(m.begin(), m.end());
	int ans = n;
	while (true) {
		if (sum > x)
			break;
		else {
			sum += m[0];
			ans++;
		}

	}

	cout << ans-1 << endl;


	return 0;
}

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

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

    for(int i=0;i<=n;i++){
        for(int j=0;j+i<=n;j++){
            if(y==i*10000+j*5000+(n-i-j)*1000){
                cout<<i<<" "<<j<<" "<<n-i-j<<endl;
                return 0;
            }
        }
    }

    cout<<-1<<" "<<-1<<" "<<-1<<endl;

}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
using namespace std;
using P = pair<int,int>;

int main(){
	int x,n;
	cin >> x >> n;
	vector<int> d(102);
	for(int i=0;i < n;++i){
		int p;
		cin >> p;
		d[p] = 1;
	}

	P ans(99999,-1);
	for(int i=0; i <= 101; ++i){
		if(d[i] == 1) continue;
		int dif = abs(x-i);
		ans = min(ans,P(dif,i));
	}
	cout << ans.second << endl;
	return 0;
}


Measured memory_bytes: 3192
import java.util.Scanner;

import static java.lang.System.in;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(in);
        int n = scanner.nextInt();
        double[] arr = new double[n];
        for (int i = 0; i < n; i++) {
            arr[i] = scanner.nextDouble();
        }
        double[] dp = new double[n+1];// probability for i number of heads
        dp[0]=1.0;
        for(int coin=0;coin<n;coin++){
            for (int i = coin+1; i>=0; i--) {
                dp[i] = (i==0 ? 0 : dp[i-1]*arr[coin]) + dp[i]*(1d-arr[coin]);
            }
        }
        double res=0;
        for(int i=(n+1)/2;i<=n;i++)
            res +=dp[i];

        System.out.println(res);
    }
}


Measured memory_bytes: 53084
#include<bits/stdc++.h>
using namespace std;
#define rep0(i,n) for(i=0;i<n;i++)
#define ll long long
#define test(a) cout << "*" << a << endl;
int main(){
  int i,j;
  int numLong,numChoice;
  int a[100000];
  int aMin,aTmp;
  int count = 0;
  
  cin >> numLong >> numChoice; 
  
  rep0(i,numLong){ 
    cin >> a[i];
    if(i==0){
      aMin = a[i];
    }
    if(a[i] < aMin){
      aMin = a[i];
    }
  
  }
  
  rep0(i,numLong){
    if(a[i] == aMin){
      count++;  
    }
  }
  
  
  if((numLong-count)%(numChoice-1) != 0)
    cout << (numLong-count)/(numChoice-1) +1 << endl;
  else
    cout << (numLong-count)/(numChoice-1) << endl;

}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define inf 1000000000
#define mod 1000000007
using namespace std;
using LL = long long;

int main(){
    double n,k;cin>>n>>k;
    double score;
    double ans=0;
    double buf=1.0;

    for(double i=1;i<=n;i++){
        score = i;
        buf=1.0/n;
        while(score <= k-1){score*=2.0; buf/=2.0;}
        ans += buf;
    }

    cout<<std::setprecision(9)<<ans<<endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<cmath>
#include<vector>
#include<utility>

using namespace std;

vector<int> to[200005]; 
int cnt[200005],ans[200005];

void dfs(int x,int fa,int sum)
{
	//cout<<sum<<' '<<x<<endl;
	sum+=cnt[x];
	ans[x]=sum;
	if(to[x].size()==1&&fa!=0)
		return ;
	for(int i=0;i<to[x].size();i++)
	{
		 int v=to[x][i];
		 if(v==fa)
		 	continue;
		dfs(v,x,sum);
	}
	return ;
}

int main()
{
	int n;
	cin>>n;
	int q;
	cin>>q;
	for(int i=1;i<n;i++)
	{
		int a,b;
		cin>>a>>b;
		to[a].push_back(b);
		to[b].push_back(a);
	}
	for(int i=1;i<=q;i++)
	{
		int p,x;
		cin>>p>>x;
		cnt[p]+=x;
	}
	dfs(1,0,0);
	for(int i=1;i<=n;i++)
	{
		cout<<ans[i]<<' '; 
	} 
	return 0;
}

Measured memory_bytes: 27136
//author:luckYrat(twitter:@luckYrat_)
//<ここに一言>

//せんげん！
#include <iostream>

#include <cmath>
#include <algorithm>
#include <iomanip>

#include <string>
#include <vector>
#include <set>
#include <stack>
#include <queue>
#include <map>
#include <bitset>

#include <cctype>
#include <utility>
#include <climits>


//なまえくーかん！
using namespace std;
using ll = long long;
using P = pair<ll,ll>;

//てーすう！
const int mod = 1000000007;
const int inf = (1<<30)-1;
const ll linf = (1LL<<62LL)-1;
const double EPS = (1e-10);

//でふぁいん！
#define anyfill(n,s) setw(n) << setfill(s)
#define loop(s) for(int i = 0; s > i; i++)
#define rep(i,q) for(int i = 0; (q) > i; i++)
#define repp(i,n,q) for(int i = n; (q) > i; i++)
#define dep(i,q) for(int i = (q); 0 < i; i--)

//みじかく！
#define pb push_back
#define fir first
#define scn second
#define ednl endl

//いぇすのー！
#define YesNo(a) (a?"Yes":"No")
#define YESNO(a) (a?"YES":"NO")
#define yesno(a) (a?"yes":"no")

//きんぼーnほーこー！！
P ar4[4] = {{0,1},{0,-1},{1,0},{-1,0}};
P ar8[8] = {{-1,-1},{-1,0},{-1,1},{0,-1},{0,1},{1,-1},{1,0},{1,1}};
/*
確認ポイント
cout << fixed << setprecision(n) << 小数計算//n桁の小数表記になる

計算量は変わらないが楽できるシリーズ
min(max)_element(iter,iter)で一番小さい(大きい)値のポインタが帰ってくる
count(iter,iter,int)でintがiterからiterの間にいくつあったかを取得できる
*/
__attribute__((constructor))
void initial() {
 cin.tie(0);
 ios::sync_with_stdio(false);
}
int main(){
	int n,x,y;cin>>n>>x>>y;x--;y--;
	for(int i = 1; n > i; i++){
		int ans = 0;
		for(int j = 0; n-i > j; j++){
			//i+j = j元位置、j+iは目的位置
			if(i+j <= x)ans+=1;
			else if(j >= y)ans+=1;
			else{
				if(j <= x){
					//通常に進むとき
					//ワープを使った時より短い場合
					if(i+j < y && i <= (x-j)+1+abs(y-(i+j))){
						ans++;
					}
					//ワープを使ってさらに進むとき
					if(y+(i-((x-j)+1)) <= n-1){
						ans++;
					}
					//ワープを使った後に戻るとき
					int targ = y-(i-((x-j)+1));
					if(targ != y+(i-((x-j)+1)) && targ > j && i<(targ-j)){
						ans++;
					}
				}else{
					//普通に進む時
					//ワープを使った時より短い場合
					if(i <= (j-x)+1+abs(y-(i+j))){
						ans++;
					}
					//ワープで戻った後に進むとき
					int targ = y+(i-((j-x)+1));
					if(targ <= n-1 && (i-((j-x)+1)) >= 0 && targ > j && i<(targ-j)){
						ans++;
					}

					//ワープで戻った後に戻る時
					
					targ = y-(i-((j-x)+1));
					if(targ != y+(i-((j-x)+1)) && (i-((j-x)+1)) >= 0  && targ > j && i<(targ-j)){
						ans++;
					}
				}
			}
		}
		cout << ans << endl;
	}
}

Measured memory_bytes: 256
S = input()
 
arr = [0 if s == "W" else 1 for s in S]
sorted_arr = sorted(arr)
  
state = sum([arr[i] * i for i in range(len(S))])
final_state = sum([sorted_arr[i] * i for i in range(len(S))])
 
print(final_state - state)

Measured memory_bytes: 14568
L, R = map(int, input().split())

if L // 2019 != R // 2019:
    print(0)
    exit()

l = L % 2019
r = R % 2019

minval = 2019
for i in range(l, r):
    for j in range(i+1, r+1):
        minval = min((i * j) % 2019, minval)

print(minval)


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

const ll MOD=1000000007;

ll gcd1(ll a,ll b){
  if(a==0 && b==0)return 0;
  ll n;
  while(a%b!=0){
    n=a%b;
    a=b;
    b=n;
  }
  return b;
}

ll solveLinear1(ll n,ll m,ll c){
  if(n==0 && m==0)return 0;
  ll a[100],b[100];
  a[0]=n;b[0]=m;
  int i=1;
  while(b[i-1]!=0){
    a[i]=b[i-1];
    b[i]=a[i-1]%b[i-1];
    i++;
  }
  n=i;
  if(c%a[n-1]!=0){
    return 0;
  }
  ll x=c/a[n-1],y=0;
  for(i=1;i<n;i++){
    ll cnt=x;
    x=y;
    y=cnt-(a[n-i-1]/b[n-i-1])*y;
  }
  return x;
}

ll modRev(ll a,ll p){
  ll n=solveLinear1(a,p,1);
  n=n%p;
  if(n<0)return n+p;
  return n;
}

ll L[51];
ll a[51];

ll patty(ll x,int n){
  if(x<=0)return 0;
  if(n==0)return 1;
  if(x>=L[n])return a[n];
  ll cnt=patty(x-1,n-1)+patty(x-2-L[n-1],n-1);
  if(x>L[n-1]+1)cnt++;
  return cnt;
}

int main(){
  int i,j,k,cnt=0;
  int n;
  string s;
  cin>>n>>k;
  cin>>s;
  cnt=1;
  for(i=1;i<n;i++){
    if(s[i]!=s[i-1])cnt++;
  }
  cout<<min(n-1,n-cnt+2*k)<<endl;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
#include <ext/rope>
#include <random>
#include <chrono>
#include <ext/pb_ds/assoc_container.hpp>
 
#define file ""
 
#define all(x) x.begin(), x.end()
 
#define sc second
#define fr first
 
#define pb push_back
#define mp make_pair
 
#define pss pair<line*, line*>
 
using namespace std;
using namespace __gnu_cxx;
 
typedef long long ll;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
                                 
const ll inf = 1e18;
const int MOD = 1e9 + 7;
 
const int dx[] = {-1, +1, -2, +2, -2, +2, -1, +1};
const int dy[] = {-2, -2, -1, -1, +1, +1, +2, +2};
 
int const N = 3e5 + 5;
int const M = 1e8	;

int main() {                 
#ifdef Mask                                                         
  freopen(".in", 	"r", stdin);
  freopen(".out", "w", stdout);  
#endif
	ios_base :: sync_with_stdio(false);               
  cin.tie(nullptr);
  srand(time(nullptr));	
  int n, k;
  cin >> n >> k;
  int a[n + 1];
  for (int i = 1; i <= n; i++)
  	cin >> a[i];
  sort(a + 1, a + 1 + n);
  ll ans = 0;
  for (int i = 1; i <= k; i++)
  	ans += a[i];
  cout << ans << endl;
	return 0;
 
}

Measured memory_bytes: 3664
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"
#include "numeric"
#include "cassert"
#include "functional"

using namespace std;

constexpr long long int MOD = 1000000007;
//const int MOD = 1000000007;
//constexpr int MOD = 998244353;
//constexpr long long int MOD = 998244353;
//constexpr double EPS = 1e-8;

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

struct Edge {
	int to, cost;
	Edge(const int t, const int c) {
		to = t, cost = c;
		return;
	}
};

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

	cin >> N >> M >> H;
	vector<vector<Edge>>edge(N);
	long long int sum = 0;
	for (int i = 0; i < M; i++) {
		cin >> L >> R >> K;
		sum += K;
		L--;
		R--;
		edge[L].push_back(Edge(R, K));
		edge[R].push_back(Edge(L, K));
	}
	vector<long long int>dis(N, MOD*MOD);
	dis[0] = 0;
	priority_queue<pair<long long int, int>, vector<pair<long long int, int>>, greater<pair<long long int, int>>>PQ;
	PQ.push({ 0,0 });
	while (!PQ.empty()) {
		long long int c = PQ.top().first;
		int cn = PQ.top().second;
		PQ.pop();
		for (auto i : edge[cn]) {
			if (dis[i.to] > c + i.cost) {
				dis[i.to] = c + i.cost;
				PQ.push({ dis[i.to],i.to });
			}
		}
	}
	map<long long int, long long int>mpnode;
	for (int i = 0; i < N; i++)mpnode[dis[i]]++;
	map<long long int, long long int>mpedge;
	for (int i = 0; i < N; i++) {
		for (auto j : edge[i]) {
			if (j.to < i)continue;
			mpedge[max(dis[i], dis[j.to])] += j.cost;
		}
	}
	long long int ans = sum;
	long long int num = 0;
	for (auto i : mpnode) {
		num += i.second;
		mpedge[i.first] += 0;
		sum -= mpedge[i.first];
		ans = min(ans, sum + i.first * H);
	}
	cout << ans << endl;
}


Measured memory_bytes: 22196
#include<stdio.h>
void selection_sort(int A[],int n)
{
  int i,j,tmp;
  for(i=0;i<n;i++)
  {
    for(j=i+1;j<n;j++)
    {
      if(A[i]>A[j])
      {
        tmp=A[i];
        A[i]=A[j];
        A[j]=tmp;
      }
    }
  }
}
int binarySearch(int A[],int n,int key)
{
  int left,right,mid;
  left=0; right=n;
  while(left<right)
  {
    mid=(left+right)/2;
    if(A[mid]==key) return 1;
    else if(key<A[mid]) right=mid;
    else left=mid+1;
  }
  return 0;
}
int main(void)
{
  int n,i,q,count=0;
  scanf("%d",&n);
  int S[n];
  for(i=0;i<n;i++) scanf("%d",&S[i]);
  scanf("%d",&q);
  int T[q];
  for(i=0;i<q;i++) scanf("%d",&T[i]);
 // selection_sort(S,n);
  for(i=0;i<q;i++)
  {
    count+=binarySearch(S,n,T[i]);
  }
  printf("%d\n",count);
  return 0;
}



Measured memory_bytes: 2308
#include<iomanip>
#include<limits>
#include<thread>
#include<utility>
#include<iostream>
#include<string>
#include<algorithm>
#include<set>
#include<map>
#include<vector>
#include<stack>
#include<queue>
#include<cmath>
#include<numeric>
#include<cassert>
#include<random>
#include<chrono>
#include<unordered_map>
#include<fstream>
#include<list>
#include<functional>
#include<bitset>
#include<complex>
#include<tuple>
using namespace std;
typedef unsigned long long int ull;
typedef long long int ll;
typedef pair<ll,ll> pll;
typedef pair<int,int> pi;
typedef pair<double,double> pd;
typedef pair<double,ll> pdl;
#define F first
#define S second
const ll E=1e18+7;
const ll MOD=1000000007;





int main(){
    vector<ll> cnt(4,0);
    for(int i=0;i<3;i++){
        pll I;
        cin>>I.F>>I.S;
        cnt[I.F-1]++;
        cnt[I.S-1]++;
    }
    ll s=0;
    for(int i=0;i<4;i++){
        if(cnt[i]==1){s++;}
    }
    if(s==2){cout<<"YES"<<endl;}
    else{cout<<"NO"<<endl;}
    
    
    return 0;
}


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

#define EPS (1e-10)
#define rep(i, a, b) for (int i = a; i < (int)(b); ++i)
#define rrep(i, a, b) for (int i = b - 1; i >= (int)(a); --i)
#define all(a) a.begin(), a.end()

using namespace std;
using ll = long long;
using vi = vector<int>;
using vb = vector<bool>;
using vll = vector<ll>;
using vd = vector<double>;
using vvi = vector<vi>;
using vvb = vector<vb>;

constexpr int MOD = 1000000007;

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

    int n, k;
    cin >> n >> k;

    vi v(2 * n);
    rep(i, 0, n) {
        int x;
        cin >> x;
        v[i] = v[i + n] = x;
    }

    int ans = 0;
    rep(length, 0, min(n, k) + 1) {
        rep(start, n - length, n + 1) {
            int sum = 0;
            priority_queue<int> minus;
            rep(i, start, start + length) {
                sum += v[i];
                if (v[i] < 0) { minus.push(-v[i]); }
            }
            rep(i, 0, k - length) {
                if (minus.empty()) { break; }
                sum += minus.top();
                minus.pop();
            }
            ans = max(ans, sum);
        }
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256