akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define rep2(i,n) for(int i=0;i<=n;i++)
#define repr(i,a,n) for(int i=a;i<n;i++)
#define all(a) a.begin(),a.end()
#define P pair<long long,long long>
#define uni(e) e.erase(unique(e.begin(),e.end()),e.end())
#define double long double
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 INF=1e10;
int MOD=1e9+7;
signed main(){
  int a,b,c;
  cin>>a>>b>>c;
  vector<int> d(a);
  int e[a][b];
  rep(i,a){
  cin>>d[i];
  rep(j,b)
    cin>>e[i][j];
  }
    
  int w=INF;
  int x=INF;
  int y=0;
  rep(i,(1<<a)){
  bitset<12> s(i);
    int m=0;
    vector<int> t(b,0);
    rep(j,a){
    if(s.test(j)){
      m+=d[j];
      rep(k,b){
      t[k]+=e[j][k];
      }
      }
    }
    bool n=1;
    rep(l,b){
    if(t[l]<c)
      n=0;
    }
    if(n){
      chmin(w,m);
      if(x>w)
        x=w;
      }
   if(i==(1<<a)-1){
   if(x==INF)
     cout<<-1;
   else
     cout<<x;
   }
     
    }
}

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


int main(){
    int n;
    cin >> n;
    vector<char> s(n);
    rep(i,n) cin >> s[i];
    rep(i,n){
        if(s[i] == 'Y'){
            cout << "Four" << endl;
            return 0;
        }
    }
    cout << "Three" << endl;
}

Measured memory_bytes: 256
import sys
import numpy as np 

h, w = map(int, sys.stdin.readline().split())
grid = np.array([list(sys.stdin.readline().rstrip()) for _ in range(h)], dtype='U1')
grid = np.pad(grid, 1, 'constant')

def main():
  d = [(-1, 0), (0, -1), (1, 0), (0, 1)]
  cnt = np.zeros_like(grid, dtype=np.int8)
  for i in range(1, h + 1):
    for j in range(1, w + 1):
      if grid[i][j] == '.': continue
      for dy, dx in [(dy, dx) for dy in range(-1, 2) for dx in range(-1, 2)]:
        cnt[i+dy][j+dx] += 1
  cnt = cnt.astype('U1')
  cnt[grid == '#'] = '#'
  cnt = cnt[1:-1, 1:-1]
  for i in range(h):
    print(''.join(cnt[i]))
    
if __name__ == '__main__':
  main()

Measured memory_bytes: 12416
N=int(input())
A=[list(map(int,input().split())) for i in range(N)]
B=[list(map(int,input().split())) for i in range(N)] 

import itertools
D=list(itertools.product([0,1],repeat=10))

ans=(-1)*9999999999
for i in D:
  a=0
  if i!=(0,0,0,0,0,0,0,0,0,0):
    for j in range(N):
      b=0
      for k in range(10):
        if i[k]==1 and A[j][k]==1:
          b+=1
      a+=B[j][b]
    ans=max(ans,a)
print(ans)


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

int main() {
    string s;
    cin >> s;
    int n = s.size();
    int count = 0;
    vector< pair<char, int> > ss;
    for(int i=0; i<n; i++){
        if(s[i]!='x'){
            count++;
            ss.push_back(make_pair(s[i], i));
        }
    }
    int ans = 0;
    vector<char> l;
    vector<char> r;
    if(count == 0){
        cout << 0 << endl;
        return 0;
    }
    for(int i=0; i<count/2; i++){
        if(ss[i].first != ss[count-1-i].first){
            cout << -1 << endl;
            return 0;
        }
    }


    for(int i=0; i<n; i++){
        if(count%2==0){
            if(i<=ss[count/2-1].second){
                l.push_back(s[i]);
            }else if(i>=ss[count/2].second){
                r.push_back(s[i]);
            } 
        }else{
            if(i<ss[count/2].second){
                l.push_back(s[i]);
            }else if(i>ss[count/2].second){
                r.push_back(s[i]);
            } 
        }
    }

    reverse(r.begin(), r.end());
    int l_index = 0;
    int r_index = 0;
    for(int i=0; i<2*n; i++){
        if(l_index==l.size() || r_index==r.size()){
            ans += max(r.size()-r_index, l.size()-l_index);
            break;
        }
        if(l[l_index] == r[r_index]){
            l_index++;
            r_index++;
        }else if(l[l_index] != r[r_index]){
            ans++;
            if(l[l_index] == 'x'){
                l_index++;
            }else{
                r_index++;
            }
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 1528
#include <iostream>
using namespace std;
const int limn=1e5+5;
int tab[limn][3];
int dp[limn][3];
int main()
{
    int n,M=0;
    cin>>n;
    for(int i=0;i<n;i++)
        for(int j=0;j<3;j++)
            cin>>tab[i][j];

    for(int i=0;i<3;i++)
        dp[0][i]=tab[0][i];

    for(int i=1;i<n;i++)
    {
        for(int j=0;j<3;j++)
        {
            if(j==0)
                dp[i][j]=max(tab[i][j]+dp[i-1][j+1],tab[i][j]+dp[i-1][j+2]);
            else if(j==1)
                dp[i][j]=max(tab[i][j]+dp[i-1][j+1],tab[i][j]+dp[i-1][j-1]);
            else if(j==2)
                dp[i][j]=max(tab[i][j]+dp[i-1][j-1],tab[i][j]+dp[i-1][j-2]);
        }
    }
    for(int i=0;i<3;i++)
        M=max(M,dp[n-1][i]);
    cout<<M;

    return 0;
}


Measured memory_bytes: 2560
from fractions import gcd


def lcm(p, q):
    return p * q // gcd(p, q)


def anti_division():
    a, b, c, d = map(int, input().split())
    numbers = b - a + 1
    cd_gcd = lcm(c, d)
    a_multiples = [a // min(c, d), a // max(c, d)]
    b_multiples = [b // min(c, d), b // max(c, d)]
    gcd_multiples = [a // cd_gcd, b // cd_gcd]
    ans = numbers - ((b_multiples[1] - a_multiples[1]) + (b_multiples[0] - a_multiples[0]) - (
            gcd_multiples[1] - gcd_multiples[0]))
    if a % c == 0:
        ans -= 1
    if a % d == 0:
        ans -= 1
    if a % cd_gcd == 0:
        ans += 1
    print(ans)


if __name__ == '__main__':
    anti_division()


Measured memory_bytes: 5048
// #include <bits/stdc++.h>
#include <iostream>
#include <iomanip>
#include <stdio.h>
#include <math.h>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
using namespace std;
 
#define mt make_tuple
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define ALL(a) begin(a), end(a)
#define SZ(a) ((int)(a).size())
 
#ifdef __DEBUG
#define debug if (true)
#else
#define debug if (false)
#endif
 
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;

int M[305][305];

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

  int N = 10000;
  cin >> N;

  for(int i = 0; i < N; ++i) {
    for(int j = 0; j < N; ++j) {
      cin >> M[i][j];
    }
  }

  ll ans = 0;
  bool check = true;
  int temp;

  for(int i = 0; i < N; ++i) {
    for(int j = i+1; j < N; ++j) {
      if(j != i) {
        temp = M[i][j];
        for(int k = 0; k < N; ++k) {
          if(k != i && k != j) {
            if(M[i][k] + M[k][j] < M[i][j]) {
              check = false;
              break;
            } else
            if(M[i][k] + M[k][j] == M[i][j]) {
              temp = 0;
            }
          }
        }
        ans += temp;
        if(!check) {
          break;
        }
      }
    }
    if(!check) {
      break;
    }
  }

  if(check) {
    cout << ans << endl;
  } else {
    cout << -1 << endl;
  }

  return 0;
}

Measured memory_bytes: 640
#pragma GCC optimize ("O3")
#pragma GCC target ("avx")

#include <bits/stdc++.h>
using namespace std;
using LL = long long int;
#define incID(i, l, r) for(int i = (l)    ; i <  (r); ++i)
#define decID(i, l, r) for(int i = (r) - 1; i >= (l); --i)
#define incII(i, l, r) for(int i = (l)    ; i <= (r); ++i)
#define decII(i, l, r) for(int i = (r)    ; i >= (l); --i)
#define inc(i, n)  incID(i, 0, n)
#define dec(i, n)  decID(i, 0, n)
#define inc1(i, n) incII(i, 1, n)
#define dec1(i, n) decII(i, 1, n)
#define inID(v, l, r) ((l) <= (v) && (v) <  (r))
#define inII(v, l, r) ((l) <= (v) && (v) <= (r))
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define MT make_tuple
#define FI first
#define SE second
#define FR front()
#define BA back()
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
auto setmin   = [](auto & a, auto b) { return (b <  a ? a = b, true : false); };
auto setmax   = [](auto & a, auto b) { return (b >  a ? a = b, true : false); };
auto setmineq = [](auto & a, auto b) { return (b <= a ? a = b, true : false); };
auto setmaxeq = [](auto & a, auto b) { return (b >= a ? a = b, true : false); };
#define SI(v) static_cast<int>(v.size())
#define RF(e, v) for(auto & e: v)
#define until(e) while(! (e))
#define if_not(e) if(! (e))
#define ef else if
#define UR assert(false)
#define IN(T, ...) T __VA_ARGS__; IN_(__VA_ARGS__);
void IN_() { };
template<typename T, typename ... U> void IN_(T &  a, U &  ... b) { cin >> a; IN_(b ...); };
template<typename T                > void OUT(T && a            ) { cout << a << endl; }
template<typename T, typename ... U> void OUT(T && a, U && ... b) { cout << a << " "; OUT(b ...); }

// ---- ----

const int M = 100'000;
int A[M], B[M], aa, bb, mi, sum;
map<int, int,    less<int>> mA;
map<int, int, greater<int>> mB;
int main() {
	until(getchar_unlocked() == '\n') { }
	while(true) {
		char c = getchar_unlocked();
		if(c == '(' || c == ')') {
			sum += (c == '(' ? +1 : -1);
			setmin(mi, sum);
		} else {
			int a = -mi, b = sum - mi;
			if(a <= b) { if(a < M) { A[a] += sum; setmax(aa, a); } else { mA[a] += sum; } }
			else       { if(b < M) { B[b] += sum; setmax(bb, b); } else { mB[b] += sum; } }
			mi = 0, sum = 0;
			if(c == EOF) { break; }
		}
	}
	
	incII(i, 0, aa) {
		setmin(mi, sum - i);
		sum += A[i];
	}
	for(auto [i, Ai]: mA) {
		setmin(mi, sum - i);
		sum += Ai;
	}
	for(auto [i, Bi]: mB) {
		sum += Bi;
		setmin(mi, sum - i);
	}
	decII(i, 0, bb) {
		sum += B[i];
		setmin(mi, sum - i);
	}
	puts(mi >= 0 && sum == 0 ? "Yes" : "No");
}


Measured memory_bytes: 3644
// Author : Chi
// created : Thursday 2020-06-04
// Sawal : Practice

//header files
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

//namespaces
using    namespace __gnu_pbds;
using    namespace std;
typedef tree <int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update > ordered_set;

//macros
#define ll 		    long long
#define ss          second
#define ff          first
#define vi          vector<int>
#define vll         vector<long long>
#define pb(x)       push_back(x)
#define TEST  	    int TesT;cin>>TesT;while(TesT--)solve();
#define TEST1       solve();
#define mod         3
#define aLL(x)      x.begin(),x.end()
#define r0n(i,n)    for(ll i = 0; i < n; ++i)
#define r1n(i,n)    for(ll i = 1; i <= n; ++i)
#define pdp(d,i)    fixed<<setprecision(i)<<d
#define CHI         ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
#define db(...)     __f(#__VA_ARGS__, __VA_ARGS__)                      //for debugging
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) { cout << name << " : " << arg1 <<'\n'; }
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
    const char* comma = strchr(names + 1, ',');
    cout.write(names, comma - names) << " : " << arg1 << " | "; __f(comma + 1, args...);
}
//LOVE ALGO
long long mp[401][401];
ll *a;
ll *pre;
ll P(int s,int e){
if(s==0)
    return pre[e];
else
    return pre[e]-pre[s-1];
}
long long rec(int s,int e){
    if(s==e)
        return 0;
    if(mp[s][e]!=-1)
            return mp[s][e];
    long long ans=LLONG_MAX;
    for(int i=s+1;i<=e;i++){
        ans=min(ans,P(s,i-1)+P(i,e)+rec(s,i-1)+rec(i,e));
    }
    return mp[s][e]=ans;
}
void solve(){
    memset(mp,-1,sizeof mp);
    int n;
    cin>>n;
    a=new ll[n];
    pre=new ll[n];
    for(int i=0;i<n;i++){
        cin>>a[i];
        pre[i]=a[i];
        if(i)
            pre[i]+=pre[i-1];
    }
    cout<<rec(0,n-1);
    }
// Driver Code
int main(){
    CHI
    TEST1
    return 0;
}


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

using namespace std;

int main() {
   int i,j,a,b,n,c,d,x,k,q;
   
   
   cin>>n>>k>>q;
   int arr[n+1]={0};
   for(i=0;i<q;i++){
       cin>>a;
       arr[a]++;
       
   }
   for(i=1;i<n+1;i++){
       
       if(k-q+arr[i]>0)cout<<"Yes"<<endl;
       else cout<<"No"<<endl;
   }
   
   
   
   
   
    return 0;
}

Measured memory_bytes: 1024
package main

import (
	"bufio"
	"fmt"
	"io"
	"log"
	"os"
	"strconv"
)

func main() {
	a, b, c := readInt(), readInt(), readInt()

	fmt.Println(c, a, b)
}

// sort ------------------------------------------------------------

type xxx struct {
	x int
}

type sortArray []xxx

func (s sortArray) Len() int           { return len(s) }
func (s sortArray) Swap(i, j int)      { s[i], s[j] = s[j], s[i] }
func (s sortArray) Less(i, j int) bool { return s[i].x < s[j].x }

// -----------------------------------------------------------------

var (
	readString func() string
	readBytes  func() []byte
)

func init() {
	log.SetFlags(log.Lshortfile)
	readString, readBytes = newReadString(os.Stdin)
}

func newReadString(ior io.Reader) (func() string, func() []byte) {
	r := bufio.NewScanner(ior)
	r.Buffer(make([]byte, 1024), int(1e+11))
	r.Split(bufio.ScanWords)

	f1 := func() string {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Text()
	}
	f2 := func() []byte {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Bytes()
	}
	return f1, f2
}

func readInt() int {
	return int(readInt64())
}

func readInt64() int64 {
	i, err := strconv.ParseInt(readString(), 10, 64)
	if err != nil {
		panic(err.Error())
	}
	return i
}

func readFloat64() float64 {
	f, err := strconv.ParseFloat(readString(), 64)
	if err != nil {
		panic(err.Error())
	}
	return f
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}

func sum(a []int) int {
	var ret int
	for i := range a {
		ret += a[i]
	}
	return ret
}

func sumFloat64(a []float64) float64 {
	var ret float64
	for i := range a {
		ret += a[i]
	}
	return ret
}

func gcd(m, n int) int {
	for m%n != 0 {
		m, n = n, m%n
	}
	return n
}

func lcm(m, n int) int {
	return m / gcd(m, n) * n
}


Measured memory_bytes: 1756
/*
        _            _                  _            _       _     _         _   _          _          _             _        
       / /\         / /\               / /\         / /\    / /\  /\ \      /\_\/\_\ _     /\ \       /\ \     _    /\ \      
      / /  \       / /  \             / /  \       / / /   / / /  \ \ \    / / / / //\_\   \ \ \     /  \ \   /\_\ /  \ \     
     / / /\ \__   / / /\ \           / / /\ \__   / /_/   / / /   /\ \_\  /\ \/ \ \/ / /   /\ \_\   / /\ \ \_/ / // /\ \_\    
    / / /\ \___\ / / /\ \ \         / / /\ \___\ / /\ \__/ / /   / /\/_/ /  \____\__/ /   / /\/_/  / / /\ \___/ // / /\/_/    
    \ \ \ \/___// / /  \ \ \        \ \ \ \/___// /\ \___\/ /   / / /   / /\/________/   / / /    / / /  \/____// / / ______  
     \ \ \     / / /___/ /\ \        \ \ \     / / /\/___/ /   / / /   / / /\/_// / /   / / /    / / /    / / // / / /\_____\ 
 _    \ \ \   / / /_____/ /\ \   _    \ \ \   / / /   / / /   / / /   / / /    / / /   / / /    / / /    / / // / /  \/____ / 
/_/\__/ / /  / /_________/\ \ \ /_/\__/ / /  / / /   / / /___/ / /__ / / /    / / /___/ / /__  / / /    / / // / /_____/ / /  
\ \/___/ /  / / /_       __\ \_\\ \/___/ /  / / /   / / //\__\/_/___\\/_/    / / //\__\/_/___\/ / /    / / // / /______\/ /   
 \_____\/   \_\___\     /____/_/ \_____\/   \/_/    \/_/ \/_________/        \/_/ \/_________/\/_/     \/_/ \/___________/    
                                                                                                                              
*/
#include<bits/stdc++.h>
using namespace std;
#define ALL(obj) (obj).begin(), (obj).end()
#define REP(i, n) for(int i = 0;i < (n);++i)

#define endl '\n'
#define pb emplace_back
#define mkp make_pair
#define p_q priority_queue
#define INF 2000000000
#define PI 3.1415926
#define coutdb cout << fixed << setprecision(10)

const int dx[]={1,0,-1,0}, dy[]={0,-1,0,1};
const int dx_8[]={1,1,0,-1,-1,-1,0,1}, dy_8[]={0,-1,-1,-1,0,1,1,1};
const long long MOD = 1e9+7;

// typedef long long ll;
#define int long long

template <typename T> inline T GCD(T a,T b){T c;while(b!=0){c=a%b;a=b;b=c;}return a;}
template <typename T> inline T LCM(T a,T b){T c=GCD(a,b);a/=c;return a*b;}
template <typename T> inline T nCr(T a,T b){T i,r=1;for(i=1;i<=b;i++){r*=(a+1-i);r/=i;}return r;}
template <typename T> inline T nHr(T a,T b){return nCr(a+b-1,b);}

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

  int n, a[100000]; cin >> n;
  int minus = 0, cnt = 0, mn = 2e9, sum = 0;
  REP(i, n){
    cin >> a[i];
    sum += abs(a[i]);
    mn = min(mn, abs(a[i]));
    if(a[i] < 0) minus++;
  }
  if(minus % 2 == 0) cout << sum << endl;
  else cout << sum-2*mn << endl;

  return 0;
}

Measured memory_bytes: 1024
#include <cstdio>
#include <bits/stdc++.h>
#include <algorithm>
#include <iostream>
#include <string>
#include <cmath>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <map>
using ll = long long;
#define rep(i,n) for (ll i=0;i<n;i++)
using namespace std;

void solve(){

}
int main (){
    ios::sync_with_stdio(0);
    cin.tie(0);
    ll n,m;
    set<string> uni;
    cin >> n;
    vector<string> s(n);
    rep(i,n) {
        cin >> s[i];
        uni.insert(s[i]);
    } 
    cin >> m;
    vector<string> t(m);
    rep(i,m) {
        cin >> t[i];
        uni.insert(t[i]);
    }

    ll ans = 0;

    for(string ss:uni){
        ll tmp = 0;
        rep(i,n){
            if(s[i]==ss) tmp++;
        }
        rep(i,m){
            if(t[i]==ss) tmp--;
        }

        ans = max(ans,tmp);
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3660
#include <iostream>
#include <functional>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <set>
#include <queue>
#include <map>
#include <iomanip>
#include <complex>
#include <random>
#include <bitset>
#include <list>
// #include <prettyprint.hpp>
using namespace std;
#define repi(i,n) for(int i=0;i<n;++i)
#define rep(i,n) for(ll i=0;i<n;++i)
#define repinvi(i,n) for(int i=n-1;i>=0;--i)
#define sll(n) scanf("%lld", &n);
#define sii(n) scanf("%d", &n);
#define slf(n) scanf("%lf", &n);
#define pll pair<ll,ll>
#define pii pair<int,int>
#define psi pair<si,si>
typedef long long ll;
typedef double lf;
typedef short int si;

vector<vector<ll>> field(3, vector<ll>(3, 0));
vector<ll> coord1 = {0, 4, 8};
vector<ll> coord2 = {2, 4, 6};
void Main(){
    ll N, a;
    sll(N);

    bool is_ok = true;
    rep(i, N){
        sll(a);
        if(a%2==0){
            is_ok = is_ok && (a%3==0 || a%5==0);
        }
    }

    if(is_ok){
        cout << "APPROVED"<<endl;
    }else{
        cout << "DENIED"<<endl;
    }

}

int main(){
    Main();
}

Measured memory_bytes: 3160
import java.util.*;
class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = Integer.parseInt(sc.next());
        String S = sc.next();
        int[] blackCnt = new int[N+1];
        int[] whiteCnt = new int[N+2];
        blackCnt[0] = 0;
        whiteCnt[N+1] = 0;
        int w = 0;

        for(int i = 1; i<N+1; i++) {
            char c = S.charAt(i-1);
            blackCnt[i] = blackCnt[i-1];
            if(c == '#') blackCnt[i] += 1;
            if(c == '.') w++;
            //            System.out.println("b " + i + " " + blackCnt[i]);
        }
        whiteCnt[0] = w;
        for(int i = 1; i<N+1; i++) {
            char c = S.charAt(i-1);
            whiteCnt[i] = whiteCnt[i-1];
            if(c == '.') {
                whiteCnt[i] -= 1;
            }
            //            System.out.println("w " + i + " " + whiteCnt[i]);
        }

        int min = Integer.MAX_VALUE;
        for(int i = 1; i<N+1; i++) {
            min = Math.min(min, blackCnt[i-1]+whiteCnt[i]);
            //            System.out.println(min);
        }
        System.out.println(min);
    }
}

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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
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;
}
int64_t abs(int64_t n) {
  if (n < 0) {
    n = -n;
  }
  return n;
}

int main() {
  int n;
  cin >> n;
  vector <int> vec(n);
  rep(i, n) {cin >> vec.at(i);}
  vector <int> dp(100010, 1000000007);
  dp.at(0) = 0;
  for (int i = 1; i < n; i++) {
    chmin(dp.at(i), dp.at(i-1) + abs(vec.at(i)-vec.at(i-1)));
    if (i > 1) {
      chmin(dp.at(i), dp.at(i-2) + abs(vec.at(i)-vec.at(i-2)));
    }
  }
  cout << dp.at(n-1) << endl;
}

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

int main() {
  string s, t;
  cin >> s >> t;

  int change = 0;
  for (int i = 0; i < s.size(); i++) {
    if (s.at(i) != t.at(i)) change++;
  }
  cout << change << endl;
}

Measured memory_bytes: 3852
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <utility>
#include <tuple>
#include <math.h>
#include <iomanip>
#include <string>

using namespace std;

class Sover {
};

int main()
{
	while (true) {
		int n;
		cin >> n;
		if (n == 0)break;

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

		vector<vector<bool>> can(n, vector<bool>(n, false));
		for (int i = 1; i < n; i += 2) {
			for (int j = 0; j + i < n; j++) {
				if (i == 1) {
					can[j][j + i] = abs(ws[j] - ws[j + i]) <= 1;
				}
				else {
					if (can[j + 1][j + i - 1]
						&& abs(ws[j] - ws[j + i]) <= 1)can[j][j + i] = true;
					else {
						for (int k = j + 1; k < j + i; k++) {
							if (can[j][k] && can[k + 1][j + i]) {
								can[j][j + i] = true;
								break;
							}
						}
					}
				}
			}
		}

		vector<int> dp(n, 0);
		for (int i = 0; i < n; i++) {
			if (i > 0)dp[i] = dp[i - 1];
			for (int j = 0; j < i; j++) {
				if (!can[j][i])continue;

				int tmp = i - j + 1;
				if (j > 0)tmp += dp[j - 1];
				dp[i] = max(dp[i], tmp);
			}
		}

		cout << dp[n-1] << endl;
	}
}


Measured memory_bytes: 3116
import re
import sys
import math
import itertools
import bisect
from copy import copy
from collections import deque,Counter
from decimal import Decimal
import functools
def v(): return input()
def k(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def X(): return list(input())
def L(): return list(input().split())
def l(): return list(map(int,input().split()))
def lcm(a,b): return a*b//math.gcd(a,b)
sys.setrecursionlimit(10 ** 6)
mod = 10**9+7
cnt = 0
ans = 0
inf = float("inf")
al = "abcdefghijklmnopqrstuvwxyz"
AL = al.upper()

n = k()
a = l()
sum = 1000

for i in range(n-1):
    if a[i] > a[i+1]:
        xx = a[cnt:i+1]
        b = sum//min(xx)
        sum += (max(xx)-min(xx))*b
        cnt = i+1

xx = a[cnt:]
b = sum//min(xx)
sum += (max(xx)-min(xx))*b

print(sum)

Measured memory_bytes: 10460
/*{{{*/
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<string>
#include<iostream>
#include<sstream>
#include<set>
#include<map>
#include<queue>
#include<bitset>
#include<vector>
#include<limits.h>
#include<assert.h>
#define SZ(X) ((int)(X).size())
#define ALL(X) (X).begin(), (X).end()
#define REP(I, N) for (int I = 0; I < (N); ++I)
#define REPP(I, A, B) for (int I = (A); I < (B); ++I)
#define FOR(I, A, B) for (int I = (A); I <= (B); ++I)
#define FORS(I, S) for (int I = 0; S[I]; ++I)
#define RS(X) scanf("%s", (X))
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define CASET int ___T; scanf("%d", &___T); for(int cs=1;cs<=___T;cs++)
#define MP make_pair
#define PB emplace_back
#define MS0(X) memset((X), 0, sizeof((X)))
#define MS1(X) memset((X), -1, sizeof((X)))
#define LEN(X) strlen(X)
#define F first
#define S second
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef long double LD;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<PII> VPII;
typedef pair<LL,LL> PLL;
typedef vector<PLL> VPLL;
template<class T> void _R(T &x) { cin >> x; }
void _R(int &x) { scanf("%d", &x); }
void _R(int64_t &x) { scanf("%lld", &x); }
void _R(double &x) { scanf("%lf", &x); }
void _R(char &x) { scanf(" %c", &x); }
void _R(char *x) { scanf("%s", x); }
void R() {}
template<class T, class... U> void R(T &head, U &... tail) { _R(head); R(tail...); }
template<class T> void _W(const T &x) { cout << x; }
void _W(const int &x) { printf("%d", x); }
void _W(const int64_t &x) { printf("%lld", x); }
void _W(const double &x) { printf("%.16f", x); }
void _W(const char &x) { putchar(x); }
void _W(const char *x) { printf("%s", x); }
template<class T,class U> void _W(const pair<T,U> &x) {_W(x.F); putchar(' '); _W(x.S);}
template<class T> void _W(const vector<T> &x) { for (auto i = x.begin(); i != x.end(); _W(*i++)) if (i != x.cbegin()) putchar(' '); }
void W() {}
template<class T, class... U> void W(const T &head, const U &... tail) { _W(head); putchar(sizeof...(tail) ? ' ' : '\n'); W(tail...); }
#ifdef HOME
 #define DEBUG(...) {printf("[DEBUG] ");W(__VA_ARGS__);}
#else
 #define DEBUG(...)
#endif
int MOD = 1e9+7;
void ADD(LL& x,LL v){x=(x+v)%MOD;if(x<0)x+=MOD;}
/*}}}*/
const int SIZE = 1<<20;
void solve() {
    VI d[2];
    int N;
    R(N);
    REP(i,N){
        int x,y;
        R(x,y);
        d[0].PB(x+y);
        d[1].PB(x-y);
    }
    REP(i,2)sort(ALL(d[i]));
    W(max(d[0].back()-d[0][0],d[1].back()-d[1][0]));
}
void input() {
    
}
int main(){
#define MULTITEST 0
#if MULTITEST    
    CASET
#endif
    {
        input();
        solve();
    }
    return 0;
}


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

int main() {
    int n, a;
    int min = 1000000, max = -1000000;
    long sum = 0;

    cin >> n;

    for (int i = 0; i < n; i++) {
        cin >> a;
        if (min > a) min = a;
        if (max < a) max = a;
        sum += a;
    }
    
    cout << min << ' ' << max << ' ' << sum << endl;
}



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

int main(){
    int N, a[100101] = {};
    cin >> N;
    int cnt = 0;
    for(int i = 0; i < N; ++i){
        int in;
        cin >> in; in--;
        if(i == in){
            cnt++, i++;
            cin >> in;
        }
    }
    cout << cnt << endl;
}


Measured memory_bytes: 256
import java.util.Scanner;

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

    int[] primes =
        new int[] {2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73,
            79, 83, 89, 97};
    int[] countPrimes = new int[25];
    int N = scanner.nextInt();

    for (int i = 2; i <= N; i++) {
      int n = i;
      for (int j = 24; j >= 0; j--) {
        int p = primes[j];
        while (n >= p && n % p == 0) {
          countPrimes[j]++;
          n /= p;
        }
      }
    }

    int over4 = 0;
    int over2 = 0;
    int over14 = 0;
    int over24 = 0;
    int over74 = 0;
    for (int i = 0; i < 25; i++) {
      int c = countPrimes[i];

      if (c >= 2) over2++;
      if (c >= 4) over4++;
      if (c >= 14) over14++;
      if (c >= 24) over24++;
      if (c >= 74) over74++;
    }

    System.out.println(
        over74
        + over24 * (over2 > 0 ? over2 - 1 : 0)
        + over14 * (over4 > 0 ? over4 - 1 : 0)
        + over4 * (over4 > 0 ? over4 - 1 : 0) * (over2 > 1 ? over2 - 2 : 0) / 2
    );
  }
}


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

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

#define pb push_back
#define rep(i, a, n) for(int i = (a); i < (n); i++)
#define dep(i, a, n) for(int i = (a); i >= (n); i--)
#define mod 1e9+7

__attribute__((constructor))
void initial() {
  cin.tie(0);
  ios::sync_with_stdio(false);
}

int main() {
  int n;
  cin >> n;
  ll r[200005] = {};
  map<ll, int> mp;
  int ans = 0;
  for(int i = 1; i <= n; i++) cin >> r[i];
  for(int i = 1; i <= n; i++) r[i] += r[i - 1];

  for(int i = 0; i <= n; i++) {
    if(mp.count(r[i])) {
      ans = max(ans, i - mp[r[i]]);
    }else mp[r[i]] = i;
  }

  cout << ans << endl;
}

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

using ll = long long;
using Pi = pair<int, int>;
using Pl = pair<ll, ll>;
using vint = vector<int>;
using vvint = vector<vint>;
using vvvint = vector<vvint>;
using vdouble = vector<double>;
using vvdouble = vector<vdouble>;
using vvvdouble = vector<vvdouble>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;
using uint = unsigned int;
using ull = unsigned long long;

template<typename T> using uset = unordered_set<T>;
template<typename T1, typename T2> using umap = unordered_map<T1, T2>;

constexpr int INF = (1 << 30) - 1;
constexpr ll LLINF = 1LL << 60;
constexpr int dy[] = {1, 0, -1, 0, 1, -1, -1, 1};
constexpr int dx[] = {0, 1, 0, -1, 1, 1, -1, -1};
constexpr char el = '\n';
constexpr int mod = 1000000007;
constexpr int mod2 = 998244353;
template<typename T> T gcd(T a, T b) { return (b ? gcd(b, a % b) : a); }
template<typename T> T lcm(T a, T b) { return (a / gcd(a, b) * b); }
template<typename T1, typename T2>
inline bool chmin(T1 &a, T2 b) { return (a > b && (a = b, true)); }
template<typename T1, typename T2>
inline bool chmax(T1 &a, T2 b) { return (a < b && (a = b, true)); }
template<typename T>
bool isin(T y, T x, T h, T w) { return (0 <= y && 0 <= x && y < h && x < w); }
template<typename T>
bool isin1(T y, T x, T h, T w) { return (0 < y && 0 < x && y <= h && x <= w); }

template<typename T>
ostream& operator <<(ostream &os, vector<T> &v) {
	os << v[0];
	for (int i = 1; i < v.size(); i++) os << " " << v[i];
	return (os);
}

template<typename T>
istream& operator >>(istream &is, vector<T> &v) {
	for (auto &u : v) is >> u; return (is);
}

template<typename T1, typename T2>
istream& operator >>(istream &is, pair<T1, T2> &p) {
	return (is >> p.first >> p.second);
}


void Main() {
	string S; cin >> S;
	cout << ((S[2] == S[3] && S[4] == S[5]) ? "Yes" : "No") << endl;
}

int main() {
	cin.tie(0);
	ios::sync_with_stdio(0);
	cout << fixed << setprecision(20);
	Main();
	return (0);
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void){
	long a, b, c, pr, L;
	while(scanf("%ld %ld", &a, &b) != EOF){
		pr = a * b;
		while(a != b){
			if(b > a){
				c = b - a;
				b = c;
			}else{
				c = a - b;
				a = b;
				b = c;
			}
		}
		L = pr / a;
		printf("%ld %ld\n", a, L);
	}
	
	return 0;
}

Measured memory_bytes: 592
#include <bits/stdc++.h>
using namespace std;
template<class t> inline t read(t &x){
	char c=getchar();bool f=0;x=0;
	while(!isdigit(c)) f|=c=='-',c=getchar();
	while(isdigit(c)) x=(x<<1)+(x<<3)+(c^48),c=getchar();
	if(f) x=-x;return x;
}
template<class t> inline void write(t x){
	if(x<0) putchar('-'),write(-x);
	else{if(x>9) write(x/10);putchar('0'+x%10);}
}





int l;

signed main(){
	read(l);
	printf("%lf",pow(1.0*l/3,3));
}

Measured memory_bytes: 384
#include<iostream>
#include<string>
#include<algorithm>
#include<map>
#define int long long
int mod=1e9+7;
using namespace std;
int r[200000],c[200000],v[200000],tre[3000][3000],dp[3000][3000][4];
signed main(){
	int R,C,k;
	cin>>R>>C>>k;
	for(int i=0;i<k;i++)
		cin>>r[i]>>c[i]>>v[i];
	for(int i=0;i<k;i++)
		tre[r[i]-1][c[i]-1]=v[i];
	dp[0][0][1]=tre[0][0];
	for(int i=0;i<R;i++){
		for(int j=0;j<C;j++){
			for(int kk=0;kk<=3;kk++){
				if(i!=0){
					if(kk==0)
						dp[i][j][kk]=max({dp[i-1][j][0],dp[i-1][j][1],dp[i-1][j][2],dp[i-1][j][3]});
					else if(kk==1&&tre[i][j]!=0)
						dp[i][j][kk]=max({dp[i-1][j][0],dp[i-1][j][1],dp[i-1][j][2],dp[i-1][j][3]})+tre[i][j];
				}
				if(j!=0){
					dp[i][j][kk]=max(dp[i][j][kk],dp[i][j-1][kk]);
					if(kk!=0)
						dp[i][j][kk]=max(dp[i][j][kk],dp[i][j-1][kk-1]+tre[i][j]);
				}
			}
		}
	}
	cout<<max({dp[R-1][C-1][0],dp[R-1][C-1][1],dp[R-1][C-1][2],dp[R-1][C-1][3]})<<endl;
}

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

int main() {
	int nn = 0;
	int ans[100];
	while (1) {
		int n, maxn, minn;
		int pn = 0;
		cin >> n;
		if ( n == 0 ) break;
		int s[n];
		for (int i = 0; i < n; i++) {
			cin >> s[i];
			if ( i == 0 ) {
				maxn = s[0];
				minn = s[0];
			} else {
				if ( s[i] > maxn ) maxn = s[i];
				if ( s[i] < minn ) minn = s[i];
			}
			pn += s[i];
		}
		ans[nn] = (pn - maxn - minn) / (n - 2);
		nn++;
	}
	for ( int i = 0; i < nn; i++) {
		cout << ans[i] << endl;
	}
	return 0;
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rrep(i, n) for (int i = (int)(n - 1); i >= 0; i--)
#define all(x) (x).begin(), (x).end()
#define sz(x) int(x.size())
#define get_unique(x) x.erase(unique(all(x)), x.end());
typedef long long ll;
typedef complex<double> Complex;
const int INF = 1e9;
const ll MOD = 1e9 + 7;
const ll LINF = 1e18;
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 <class T>
vector<T> make_vec(size_t a) {
    return vector<T>(a);
}
template <class T, class... Ts>
auto make_vec(size_t a, Ts... ts) {
    return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}
template <typename T>
ostream& operator<<(ostream& os, vector<T> v) {
    for (int i = 0; i < sz(v); i++) {
        os << v[i];
        if (i < sz(v) - 1) os << " ";
    }
    return os;
}
int main() {
    int a, b;
    cin >> a >> b;
    cout << a * b << endl;
}

Measured memory_bytes: 3596
arr = list(map(int, input().split()))
flg = 0
for i in range(2):
  a,b = map(int, input().split())
  if arr[0] == a:
    arr.insert(0,b)
  elif arr[0] == b:
    arr.insert(0,a)
  elif arr[-1] == a:
    arr.append(b)
  elif arr[-1] == b:
    arr.append(a)
  elif i == 0:
    flg = 1
if len(arr) == 4 or flg == 1:
  print('YES')
else:
  print('NO')

Measured memory_bytes: 3064
ai = lambda: list(map(int,input().split()))

n = int(input())
a = ai()

big = sum(a[:n])
small = sum(a[2*n:])

import heapq
af = a[:n]
heapq.heapify(af)
ar = [-i for i in a[2*n:]]
heapq.heapify(ar)

ans = [[0,0] for _ in range(n+1)]
ans[0][0] = big
ans[-1][1] = small

for k in range(n):
    if af[0] < a[n+k]:
        b = heapq.heapreplace(af, a[n+k])
        big += a[n+k] - b
    ans[k+1][0] = big

for k in range(n):
    if -ar[0] > a[-n-k-1]:
        s = heapq.heapreplace(ar, -a[-n-k-1])
        small += a[-n-k-1] + s
    ans[-k-2][1] = small

print(max(i-j for i,j in ans))


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

const int maxn=3e5+10;

int n,m,Ans[maxn],vis[maxn];

int main()
{
#ifdef h10
	freopen("E.in","r",stdin);
	freopen("E.out","w",stdout);
#endif
	int i,j,l,r,x;
	scanf("%d%d",&n,&m);
	for (i=1;i<=n;i++)
	{
		scanf("%d%d",&l,&r);
		if (!l) {Ans[1]++; continue;}
		int last=m+1;
		for (x=1;x*x<=r;x++)
		{
			int u=(l+x-1)/x,v=r/x;
			if (u<=v)
			{
				if (v<last) Ans[u]++,Ans[v+1]--;
				else Ans[u]++,Ans[last]--;
				last=u;
				for (j=u;j<=v&&j*j<=r&&vis[j]!=i;j++) vis[j]=i;
			}
		}
		for (x=1;x*x<=r;x++)
		{
			int u=(l+x-1)/x,v=r/x;
			if (u<=v&&vis[x]!=i)
				vis[x]=i,Ans[x]++,Ans[x+1]--;
		}
	}
	for (i=1;i<=m;i++)
		Ans[i]+=Ans[i-1],printf("%d\n",Ans[i]);
}


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

//repetition
#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)

//container util
#define all(x) (x).begin(),(x).end()

//typedef
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VLL;
typedef vector<VLL> VVLL;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;

//const value
//const ll MOD = 1e9 + 7;
//const int dx[] = {0,1,0,-1};//{0,0,1,1,1,-1,-1,-1};
//const int dy[] = {1,0,-1,0};//{1,-1,0,1,-1,0,1,-1};

//conversion
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
inline ll toLL(string s) {ll v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}


int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  int a,b;
  cin >> a >> b;
  int aa = min(a, b);
  int bb = max(a, b);
  rep(i, bb) { cout << aa; }
  cout << endl;

}


Measured memory_bytes: 256
#include <vector>
#include <queue>
#include <algorithm>
#include <iostream>
#include <string>
#include <ctime>
#include <map>
#include <stack>
#include <sstream>
#include <set>
#include <cmath>
#include <functional>
#include <numeric>

using namespace std;

int main(void)
{
	vector <int> x;
	int n, k, a;
	int res = 0;
	cin >> n;
	cin >> k;
	for (int i = 0; i < n; i++)
	{
		cin >> a;
		x.push_back(a);
	}

	a = 0;

	for (int i = 0; i < n; i++)
	{
		if (x[i] <= abs(x[i] - k))
		{
			res += (2 * x[i]);
		}
		else
		{
			res += (2 * abs(x[i] - k));
		}
	}

	cout << res << endl;

	return 0;

}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(int argc, char *argv[]) {
	int sx, sy, tx, ty;
	cin >> sx >> sy >> tx >> ty;

	for (int i = sx; i < tx; i++) printf("R");
	for (int i = sy; i < ty; i++) printf("U");
	for (int i = tx; i > sx; i--) printf("L");
	for (int i = ty; i > sy; i--) printf("D");
	printf("D");

	for (int i = sx; i < tx + 1; i++) printf("R");
	for (int i = sy - 1; i < ty; i++) printf("U");
	printf("L");
	printf("U");
	for (int i = tx; i > sx - 1; i--) printf("L");
	for (int i = ty + 1; i > sy; i--) printf("D");
	printf("R\n");

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long ll;
#define int long long

using namespace std;
int a[100001];
int b[100001];
int c[100001];
int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int n;cin>>n;
    for (int i=1;i<=n;i++) cin>>a[i];
    for (int i=1;i<=n;i++) cin>>b[i];
    for (int i=1;i<n;i++) cin>>c[i];
    int sum=0;
    for (int i=1;i<=n;i++){
        sum+=b[a[i]];
        if (i>1 && a[i-1]+1==a[i]) sum+=c[a[i-1]];
    }
    cout<<sum;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<cstdio>
#include<cstdlib>
#include<string>
#include<sstream>
#include<cmath>
#include<numeric>
#include<map>
#include<stack>
#include<queue>
#include<list>
#include<cfloat>
using namespace std;
int mod = 1e9+7;

int main() {
  int n, c, k;
  cin >> n >> c >> k;
  vector<int> t(n);
  for(int i=0; i<n; i++) cin >> t[i];
  sort(t.begin(), t.end());
  t.push_back(1e9+k+1);

  int tmp = t[0];
  int num = 0;
  int cnt = 0;
  for(int i=0; i<n; i++){
    num++;
    if( num == c || tmp + k < t[i+1] ){
      tmp = t[i+1];
      cerr << i << " " << t[i] << " " << num << endl;
      num = 0;
      cnt++;
    }
  }
  if( num > 0 ){
    cnt++;
  }
  cout << cnt << endl;

  return 0;
}

//


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

int main(){
  int tx, ty, x, y;
  cin >> tx >> ty >> x >> y;
  int dx = x-tx;
  int dy = y-ty;
  for(int i =0; i < dy; ++i) cout << 'U';
  for(int i =0; i < dx; ++i) cout << 'R';
  for(int i =0; i < dy; ++i) cout << 'D';
  for(int i =0; i < dx; ++i) cout << 'L';
  cout << 'L';
  for(int i =0; i < dy+1; ++i) cout << 'U';
  for(int i =0; i < dx+1; ++i) cout << 'R';
  cout << 'D' << 'R';
  for(int i =0; i < dy+1; ++i) cout << 'D';
  for(int i =0; i < dx+1; ++i) cout << 'L';
  cout << 'U' << endl;
  return 0; 
}

Measured memory_bytes: 3596
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>

#include <iostream>
#include <complex>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>

#include <functional>
#include <cassert>

typedef long long ll;
using namespace std;

#define debug(x) cerr << __LINE__ << " : " << #x << " = " << (x) << endl;

#define mod 1000000007 //1e9+7(prime number)
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define SIZE 300010


int main(){
  int n, a[SIZE], b[SIZE];
  int q, x, y;

  int counter = 0, ans = 0;
  
  scanf("%d", &n);

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

  sort(b, b+n);
  
  for(int i=0;i<n;i++){
    counter += a[i] == b[i];
  }

  scanf("%d", &q);
  
  for(int i=0;i<q && counter != n;i++){
    scanf("%d%d", &x, &y);
    x--; y--;
    counter -= (a[x] == b[x]) + (a[y] == b[y]); 
    swap(a[x], a[y]);
    counter += (a[x] == b[x]) + (a[y] == b[y]);
    ans++;
  }

  if(counter != n) ans = -1;

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



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

typedef long long ll;
typedef long double ld;

int main(){
    ios_base::sync_with_stdio(false), cin.tie(0);
    cout.precision(10);
    cout << fixed;

    int a, b, c, d;
    cin >> a >> b >> c >> d;
    while(1){
        c -= b;
        if(c <= 0){
            cout << "Yes";
            return 0;
        }
        a -= d;
        if(a <= 0){
            cout << "No";
            return 0;
        }
    }
    return 0;
}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG //これつけるとA[N]でもいいらしい
//for文のマクロ
 #define rep(i, n) for (int i = 0; i < (int)(n); i++)
 #define big 1000000007
#define all(a) sort((a).begin(),(a).end()) //ソートのマクロ
#define Re(a) reverse((a).begin(),(a).end())

int main(){
    string s;
    cin>>s;
    int k=0;
    int n=s.length();
    rep(i,n-1){
        if(s[i]!=s[i+1]){
            k++;
        }
    }
    k++;
    cout<<k-1<<endl;
}

Measured memory_bytes: 512
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
using namespace std;
int main(int argc, char const *argv[])
{
    int n;cin>>n;
    vector<int> v(n);
    vector<int> c(n);
    for(int i=0;i<n;++i)cin>>v[i];
    for(int i=0;i<n;++i)cin>>c[i];
    int ret=0;
    for(int i=0;i<n;++i){
        if(v[i]-c[i]>0)ret+=v[i]-c[i];
    }
    cout << ret <<endl;
    return 0;
}


Measured memory_bytes: 256
from collections import deque
inpl = lambda: list(map(int,input().split()))
N = int(input())
T = [0] + inpl() + [0]
V = [0] + inpl() + [0]
G=deque([]) # t, v
t = 0
for i in range(1,N+2):
    u = V[i]+t
    while G and G[-1][1] >= u:
        G.pop()
    G.append((t,u)) # restrict until t
    t += T[i]
# print(G)

ans = 0
t = 0
y = 0
w, u = G.popleft()
for i in range(1,N+1):
    dt = T[i]
    tN = t + dt
    v = V[i]
    if t >= w:
        w, u = G.popleft()
    tP = t + v - y
    tR = u - v
    tQ = (t + u - y)/2
    # print(tP, tQ, tR)
    if tP >= tR:
        if tN <= tQ:
            ans += (y + dt/2)*dt
            y += dt
        else:
            ans += (y + (tQ-t)/2)*(tQ-t) + (y +tQ-t - (tN-tQ)/2)*(tN-tQ)
            y += (tQ-t) - (tN-tQ)
    else:
        if tN <= tP:
            ans += (y + dt/2)*dt
            y += dt
        elif tN <= tR:
            ans += (y + (tP-t)/2)*(tP-t) + (y+ tP - t)*(tN-tP)
            y = v
        else:
            ans += (y + (tP-t)/2)*(tP-t) + (y+ tP - t)*(tR-tP) + (y+tP-t - (tN-tR)/2)*(tN-tR)
            y = v - (tN-tR)
    t = tN
print(ans)

Measured memory_bytes: 38384
import bisect

n = int(input())
L = list(map(int,input().split()))
L.sort()

ans = 0
for a in range(0,n):
    for b in range(a+1,n):
        p = bisect.bisect_left(L, L[a]+L[b])
        ans += max(p-(b+1),0)
        
print(ans)

Measured memory_bytes: 74464
import java.util.*;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt(), k = sc.nextInt(), q = sc.nextInt();
		int a[] = new int[q];
		String ans[] = {"Yes", "No"};
		int an = 0;
		for(int i = 0; i < q; ++i){
			a[i] = sc.nextInt();
		}
		sc.close();
		long point[] = new long[n];
		for(int i = 0; i < q; ++i){
			int t = a[i] - 1;
			point[t]++;
		}
		long add = k - q;
		for(int i = 0; i < n; ++i){
			point[i] += add;
			if(point[i] <= 0)an = 1;
			System.out.println(ans[an]);
			an = 0;
		}
	}
}


Measured memory_bytes: 51688
fn main() {
    let mut sc = Scanner::new();
    let n = sc.usize_read();
    if n > 999 {
        println!("ABD");
    } else {
        println!("ABC");
    }
}

struct Scanner {
    ptr: usize,
    length: usize,
    buf: Vec<u8>,
    small_cache: Vec<u8>,
}

#[allow(dead_code)]
impl Scanner {
    fn new() -> Scanner {
        Scanner {
            ptr: 0,
            length: 0,
            buf: vec![0; 1024],
            small_cache: vec![0; 1024],
        }
    }

    fn load(&mut self) {
        use std::io::Read;
        let mut s = std::io::stdin();
        self.length = s.read(&mut self.buf).unwrap();
    }

    fn byte(&mut self) -> u8 {
        if self.ptr >= self.length {
            self.ptr = 0;
            self.load();
            if self.length == 0 {
                self.buf[0] = b'\n';
                self.length = 1;
            }
        }

        self.ptr += 1;
        return self.buf[self.ptr - 1];
    }

    fn is_space(b: u8) -> bool {
        b == b'\n' || b == b'\r' || b == b'\t' || b == b' '
    }

    fn read_vec<T>(&mut self, n: usize) -> Vec<T>
    where
        T: std::str::FromStr,
        T::Err: std::fmt::Debug,
    {
        (0..n).map(|_| self.read()).collect()
    }

    fn usize_read(&mut self) -> usize {
        self.read()
    }

    fn read<T>(&mut self) -> T
    where
        T: std::str::FromStr,
        T::Err: std::fmt::Debug,
    {
        let mut b = self.byte();
        while Scanner::is_space(b) {
            b = self.byte();
        }

        for pos in 0..self.small_cache.len() {
            self.small_cache[pos] = b;
            b = self.byte();
            if Scanner::is_space(b) {
                return String::from_utf8_lossy(&self.small_cache[0..(pos + 1)])
                    .parse()
                    .unwrap();
            }
        }

        let mut v = self.small_cache.clone();
        while !Scanner::is_space(b) {
            v.push(b);
            b = self.byte();
        }
        return String::from_utf8_lossy(&v).parse().unwrap();
    }
}


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

int main() {
  string S;
  cin >> S;
  long N = S.size();
  map<char, long> MA;
  for (long i = 0; i < N; i++) {
    MA[S.at(i)]++;
  }
  long ans = 0;
  for (long i = 0; i < N; i++) {
    ans += N - MA[S.at(i)];
  }
  cout << ans / 2 + 1 << "\n";  
}

Measured memory_bytes: 640
N,K=gets.chomp.split(" ").map(&:to_i)
L=N-K
MOD=10**9+7
def ppow(x, n)
    return 1 if n == 0
    return ppow(x**2 % MOD, n / 2) if (n % 2) == 0
    return ppow(x**2 % MOD, n / 2) * x if (n % 2) == 1
end  
def kaijou(a, b)
  	return 1 if a==0
    (b..a).inject(1) {|i,j| i*j % MOD }
end
  
(1..K).each do |i|
    l=kaijou(K-1,K-i+1) * ppow(kaijou(i-1,1), MOD-2)%MOD
    r=kaijou(L+1,L+2-i) * ppow(kaijou(i,1), MOD-2)%MOD
    puts l*r%MOD
end


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

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

using namespace std;

const int INF=1<<29;

int n,tar[3],l[8];

int sum[4],cost;

int dfs(int i){
	if(i==n){
		if(sum[0]==0 || sum[1]==0 || sum[2]==0) return INF;

		int res=INF,p[]={0,1,2};
		do{
			int tmp=cost;
			rep(j,3) tmp+=abs(tar[j]-sum[p[j]]);
			res=min(res,tmp);
		}while(next_permutation(p,p+3));
		return res;
	}

	int res=INF;
	rep(j,4){
		if(j<3 && sum[j]>0) cost+=10;
		sum[j]+=l[i];
		res=min(res,dfs(i+1));
		sum[j]-=l[i];
		if(j<3 && sum[j]>0) cost-=10;
	}
	return res;
}

int main(){
	cin>>n;
	rep(i,3) cin>>tar[i];
	rep(i,n) cin>>l[i];

	cout<<dfs(0)<<endl;

	return 0;
}


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

int main(){
	string s;
	cin >> s;
	int c=0;
	for(int i=0;i<s.length();i++){
		if(s[i]=='(') c++;
		else if(s[i]==')') c--;
		else{
			cout << c << endl;
			return 0;
		}
	}
  return 0;
}


Measured memory_bytes: 3196