akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <sstream>
#include <stack>
#include <iomanip>
#include <numeric>
#include <string>
#include <cstring>
#include <algorithm>
#include <functional>
#include <cstdlib>
#include <map>
#include <set>
#include <vector>
#include <utility>
#include <queue>
#include <cmath>

#define BEGIN(x) x.begin()
#define END(x) x.end()
#define ALL(x) BEGIN(x), END(x)
#define PAIR make_pair
#define VEC(type) vector<type >
#define endl '\n'

#define FOR(i, A, B) for(auto i = (A);i != (B); i++)
#define FORD(i, A, B) for(auto i = (A);i != (B); i--)

#define READRANGE(begin, end) FOR(it, begin, end) cin >> *it
#define READVEC(V) READRANGE(BEGIN(V), END(V))

using namespace std;

typedef long long lint;
typedef pair<int, int> Pii;
typedef pair<int, lint> Pil;
typedef pair<lint, lint> Pll;
typedef pair<lint, int> Pli;

template<class U, class V>
istream& operator >>(istream& in, pair<U, V>& pr) {
    return in >> pr.first >> pr.second;
}

template<class U, class V>
ostream& operator <<(ostream& out, pair<U, V>& p) {
    return out << p.first << " " << p.second;
}

template<class T>
ostream& operator <<(ostream& out, vector<T> vec) {
    for (T& e : vec)
        out << e << " ";
    return out << endl;
}

// ---- BEGIN LIBRARY CODE ----
// ---- END LIBRARY CODE ----
void io_init()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
};

int main(int argc, char **argv)
{
    io_init();

    // Actual program code starts here.
    int x1, y1, x2, y2;
    cin >> x1 >> y1 >> x2 >> y2;
    int vx = x2 - x1, vy = y2 - y1;
    int x3 = x2 - vy, y3 = y2 + vx;
    int x4 = x3 + x1 - x2, y4 = y3 + y1 - y2;
    cout << x3 << " " << y3 << " " << x4 << " " << y4 << endl;
    return 0;
};

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

string s;
int n, k, a[MAX];
ll f[MAX][MAX];

ll dp(int x, int lim, int cnt){
    if(x > n) return cnt == k;
    if(f[x][cnt] != -1 && !lim) return f[x][cnt];
    ll res = 0;
    int h = lim?a[x]:9;
    for(int i = 0; i <= h; i++){
        res += dp(x+1, lim&&(i==h), cnt+(i>0));
    }
    if(!lim) f[x][cnt] = res;
    return res;
}

int main()
{
    memset(f, -1, sizeof(f));
    string s;
    cin >> s >> k;
    n = s.length();
    for(int i = 0; i < s.length(); i++){
        a[i+1] = s[i]-'0';
    }
    ll ans = dp(1, 1, 0);
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 640
#include <iostream>
#include <string>
#include <map>
using namespace std;

int main(){
    int a;
    int b1, b2, b3, b4;
    int res;
    map<int , char>rel;

    rel[0] = '+';
    rel[1] = '-';

    cin >> a;

    b1 = a / 1000;
    b2 = (a / 100) % 10;
    b3 = (a % 100) / 10;
    b4 = a % 10;

    for(int i = 0; i < 2; i++){
        for(int j = 0; j < 2; j++){
            for(int k = 0; k < 2; k++){
                if(i){
                    res = b1 - b2;
                }else res = b1 + b2;

                if(j){
                    res -= b3;
                }else res += b3;

                if(k){
                    res -= b4;
                }else res += b4;

                if(res == 7){
                    cout << b1 << rel[i] << b2 << rel[j] << b3 << rel[k] << b4 << "=7" << endl;
                    return 0;
                }
            }
        }
    }

    return 0;
}


Measured memory_bytes: 256
let ()=
  let a,b = Scanf.sscanf (read_line()) "%d %d" (fun a b -> a,b) in
  print_int (a / b);
  print_string " ";
  print_int (a mod b);
  print_string " ";
  print_string (Printf.sprintf "%.5f" (float_of_int a /. float_of_int b));
  print_string "\n"
;;


Measured memory_bytes: 2392
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
#define rep(i,a, b) for (int i = (a); i < (b); i++ )

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

const int INF = 100000000;
const double PI=3.14159265358979323846;

int main () {
    int N;
    string S;
    cin >> N >>S;
    //S = ")))())";

    int l,r,l_tmp,r_tmp;
    l = l_tmp = r = r_tmp = 0;
    
    rep(i,0,S.size()) {
        if (S[i]=='(') {
            if (r_tmp-l_tmp>0) {
                l+=r_tmp-l_tmp;
                r_tmp = 0;
                l_tmp = 0;
            }
            l_tmp++;
        }
        if (S[i]==')') {
            r_tmp++;
            r++;
        }
    }
    if (r_tmp-l_tmp>0) {
        l+=r_tmp-l_tmp;
    }

    rep(i,0,l) {
        cout << '(';
    }
    cout << S;
    rep(i,0,S.size()-2*r+l) {
        cout << ')';
    }
    cout << endl;


}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main () {
	string s,t;
	cin >> s >> t;
	int judge = 0;
	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;
	}
}

Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<cassert>
#include<math.h>
#include<complex>
#include<algorithm>
#include<utility>
#include<queue>
#include<string.h>
#include<string>
#include<set>
#include<map>
#include<unordered_map>
#include<functional>
#include<vector>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
const ll INF=2e18;
const ll MOD=1e9+7;

string S;
ll k;
int main(){
    cin>>k>>S;
    if(S.length()<=k){
        cout<<S;
    }else{
        cout<<S.substr(0,k)<<"..."<<endl;
    }

    return 0;
}

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;

int main(){
  string s,t;
  cin >>s >>t;
  int cnt = 0;
  rep(i,s.size()){
    if(s[i]!=t[i]) cnt++;
  }
  cout << cnt << endl;
  return 0; 
}

Measured memory_bytes: 3912
import qualified Data.Text as T
import qualified Data.Text.IO as T
import qualified Data.Text.Read as T
import Data.List (sortBy)
import Data.Function (on)
import qualified Data.Vector.Unboxed as VU

main :: IO ()
main = do
  n <- unsafeTextToInt <$> T.getLine :: IO Int
  let
    f :: [(Int, Int)] -> Int
    f = VU.maximum . foldl step (VU.singleton 0)
      where
        step :: VU.Vector Int -> (Int, Int) -> VU.Vector Int
        step v (x, i) = VU.generate (succ l) step'
          where
            l :: Int
            l = VU.length v
            step' :: Int -> Int
            step' 0             = VU.head v + x * (i - l)
            step' j | j < l     = max (v VU.! pred j + x * (n - pred j - i)) (v VU.! j + x * (i - (l - j)))
                    | otherwise = VU.last v + x * (n - pred l - i)
  as <- map unsafeTextToInt . T.words <$> T.getLine :: IO [Int]
  let
    ais :: [(Int, Int)]
    ais = sortBy (flip compare `on` fst) . flip zip [1..] $ as
  print . f $ ais

unsafeTextToInt :: T.Text -> Int
unsafeTextToInt s = case T.signed T.decimal s of
  Right (n, _) -> n


Measured memory_bytes: 7192
A, B, C, X, Y = map(int, input().split())
a = 0
b = 0
c = 0
if A + B > 2 * C:
  c += 2 * min(X, Y)
  if X > Y:
    if A > 2 * C:
      c += 2 * (X - Y)
    else:
      a += X - Y
  else:
    if B > 2 * C:
      c += 2 * (Y - X)
    else:
      b += Y - X
else:
  a += X
  b += Y
print(A * a + B * b + C * c)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define mp make_pair
#define sz(x) (int)(x).size()
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define ii pair<int,int>
#define INF 1000000000
#define M 1000000007ll
#define INFLL 1000000000000000010ll
#define UQ(x) (x).resize(distance((x).begin(),unique(all((x)))))
#define mid(x,y) (((x)+(y))>>1)
int n,W;
int w[105],v[105],w1;
int mem[105][105][305];
int rec(int i,int c,int t) {
	if (i<0) return 0;
	if (c==0) {
		if (t>=0) return 0;
		return -INF;
	}
	if (t<0) return -INF;
	if (c>i+1) return -INF;
	if (mem[i][c][t]!=-1) return mem[i][c][t];
	int m=rec(i-1,c,t);
	if (t>=w[i]) m=max(m,rec(i-1,c-1,t-w[i])+v[i]);
	return mem[i][c][t]=m;
}
int main() {
	scanf("%d%d",&n,&W);
	for (int i=0;i<n;i++) {
		scanf("%d%d",&w[i],&v[i]);
	}
	w1=w[0];
	for (int i=0;i<n;i++) w[i]-=w1;
	/*
	mem[0][1][0]=v[0];
	for (int i=1;i<n;i++) {
		for (int c=1;c<=n;c++) {
			for (int t=0;t<=3*n;t++) {
				mem[i][c][t]=mem[i-1][c][t];
				if (t>=)
			}
		}
	}*/
	memset(mem,-1,sizeof(mem));
	int ans=0;
	for (int c=1;c<=n;c++) {
		if ((ll)c*(ll)w1>(ll)W) break;
		ans=max(ans,rec(n-1,c,min(3*n,W-c*w1)));
	}
	printf("%d\n", ans);
}

Measured memory_bytes: 13440
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <set>
#define N 100005
#define F first
#define S second
using namespace std;

typedef long long ll;
ll n, sum;
pair<ll, ll> a[N];
multiset<ll> s;
int main()
{
	ll i, l1, l2, r1, r2;
	multiset<ll>::iterator it;
	cin >> n;
	for (i = 0; i < n; i++) {
		scanf("%lld", &a[i].F);
		a[i].S = i + 1;
	}
	sort(a, a + n, greater<pair<ll, ll> >());
	s.insert(0); s.insert(0);
	s.insert(n + 1); s.insert(n + 1);
	for (i = 0; i < n; i++) {
		it = s.lower_bound(a[i].S);
		r1 = *it;
		r2 = *next(it);
		l1 = *prev(it);
		l2 = *prev(prev(it));
        sum += ((a[i].S - l1) * (r2 - r1) + (l1 - l2) * (r1 - a[i].S)) * a[i].F;
        s.insert(a[i].S);
	}
    cout << sum << endl;
    return 0;
}

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

#define ll long long
#define Fi first
#define Se second
#define Pb push_back

const int INF = 1e9;
const int MOD = 1e9+7;

#define all(v) v.begin(),v.end()
#define output_s(a) printf("%s\n",(a).c_str())

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define Rep(i,n,m) for(int i=(int)(n);i<(int)(m);i++)
#define RepS(i,n,m) for(int i=(int)(n);i<=(int)(m);i++)
#define RRepS(i,n,m) for(int i=(int)(n);i>=(int)(m);i++)
#define RepA(x) for(auto &item:(x))

void CINT(){}
template <class Head,class... Tail>
void CINT(Head&& head,Tail&&... tail){
    cin>>head;
    CINT(move(tail)...);
}    
#define CIN(...) int __VA_ARGS__;CINT(__VA_ARGS__)
#define LCIN(...) ll __VA_ARGS__;CINT(__VA_ARGS__)
#define SCIN(...) string __VA_ARGS__;CINT(__VA_ARGS__)

//library----------------------------------------------

int main() {
    CIN(N);SCIN(s);
    int ans=0;
    rep(i,N-2){
        if(s[i]=='A'&&s[i+1]=='B'&&s[i+2]=='C') ans++;
    }
    
    printf("%d\n",ans);
    return 0;
}

Measured memory_bytes: 256
#![allow(non_snake_case)]
#![allow(unused_variables)]
#![allow(dead_code)]

fn main() {
    let N: usize = {
        let mut line: String = String::new();
        std::io::stdin().read_line(&mut line).unwrap();
        line.trim().parse().unwrap()
    };

    fn answer(q: &Vec<usize>) -> char {
        println!(
            "? {}",
            q.iter()
                .map(|&x| x.to_string())
                .collect::<Vec<_>>()
                .join(" ")
        );
        let mut line: String = String::new();
        std::io::stdin().read_line(&mut line).unwrap();
        match line.trim() {
            "Red" => 'R',
            _ => 'B',
        }
    }

    let s = answer(&(1..(N + 1)).collect());
    let mut ok = N + 1;
    let mut ng = 1;

    while ok - ng > 1 {
        let mid = (ok + ng) / 2;
        let T = answer(&(mid..(mid + N)).collect());
        if T == s {
            ng = mid;
        } else {
            ok = mid;
        }
    }

    let mut q = vec![0; N];
    for i in 0..(N - 1) {
        q[i] = ok + i;
    }

    let mut res = vec!['?'; 2 * N];
    for i in 1..(2 * N + 1) {
        if !q.contains(&i) {
            q[N - 1] = i;
            res[i - 1] = answer(&q);
        }
    }
    let mut r = 0;
    let mut b = 0;
    for i in 0..(2 * N) {
        if res[i] == 'R' && r < N / 2 {
            q[r + b] = i + 1;
            r += 1;
        } else if res[i] == 'B' && b < N / 2 {
            q[r + b] = i + 1;
            b += 1;
        }
    }
    for i in ok..(ok + N - 1) {
        q[N - 1] = i;
        res[i - 1] = answer(&q);
    }

    let ans = res
        .iter()
        .map(|&c| c.to_string())
        .collect::<Vec<_>>()
        .join("");
    println!("! {}", ans);
}


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

int map[101][101];
int w,h; 
int color;
int xg,yg;

bool dfs(int y,int x) {
  if ( map[y][x] != color ) return 0;
  map[y][x] = 10;
  if ( y-1 >= 1 ) dfs( y-1 , x );
  if ( y+1 <= h ) dfs( y+1 , x );
  if ( x-1 >= 1 ) dfs( y , x-1 );
  if ( x+1 <= w ) dfs( y , x+1 );
  
  if ( map[yg][xg]==10 ) return 1; 
  return 0;

}

int main() {
  while ( cin >> w >> h ,w+h ) {
    for(int i=1; i<=h; i++) {
      for(int j=1; j<=w; j++) map[i][j]=0;
    }
    int xs,ys; cin >> xs >> ys;
    cin >> xg >> yg;
    int n; cin >> n;
    while ( n > 0 ) {
      n--;
      int c,d,x,y;
      cin >> c >> d >> x >> y;
      if ( d == 1 ) {

	for ( int i = y; i < y+4; i++ ) {
	  for ( int j = x; j < x+2; j++ ) map[i][j] = c;
	}
      
      } else if ( d == 0 ) {
	for ( int i = y; i < y+2; i++ ) {
	  for ( int j = x; j < x+4; j++ ) map[i][j] = c;
	}
      }
      
    }
    color = map[ys][xs];
    if ( dfs(ys,xs) ) cout << "OK" << endl;
    else cout << "NG" << endl;
    
  }

  return 0;
}

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

int main(){
	int l;
	while (cin >> l, l) {
		int cnt = 0;
		int ans = -1;
		rep(i, 12) {
			int m, n; cin >> m >> n;
			cnt += m - n;
			if (!~ans&&l <= cnt)ans = i + 1;
		}
		printf(~ans ? "%d\n" : "NA\n", ans);
	}
	return 0;
}

Measured memory_bytes: 3132
package main
  
import (
    "fmt"
)

func main() {
    var n int
    fmt.Scan(&n)

    var s []byte
    fmt.Scan(&s)
    var red, blue int
    for _, b := range s {
        switch b {
        case 'B':
            blue++
        case 'R':
            red++
        }
    }
    if red > blue {
        fmt.Println("Yes")
    } else {
        fmt.Println("No")
    }
}


Measured memory_bytes: 512
#include <bits/stdc++.h> 
#define ll long long
#define pb push_back
#define mp make_pair
const ll inf = 1e9;
const ll zero = 0;
using namespace std;
int main(){
	ll n;
	cin >> n;
	if ( (n%10)==9 or ((n/10)%10)==9)
		cout<<"Yes";
	else
		cout<<"No";
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define all(x) begin(x), end(x)
#define dbg(x) cerr << #x << " = " << x << endl
#define _ << ' ' <<
using namespace std;
using ll = long long;
using vi = vector<int>;

int a[100];

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    for (int i = 0; i < n; ++i)
        cin >> a[i];
    for (int i = 0; i < n; ++i)
    {
        for (int j = i; j < n; ++j)
        {
            swap(a[i], a[j]);
            if (is_sorted(a, a + n))
                return cout << "YES", 0;
            swap(a[i], a[j]);
        }
    }
    cout << "NO";
}


Measured memory_bytes: 256
class Stack:
    def __init__(self, n):
        self.A = [0 for i in range(n)]
        self.len = n
        self.top = 0

    def is_empty(self):
        return self.top == 0

    def is_full(self):
        return self.top == self.len - 1

    def push(self, x):
        if not self.is_full():
            self.top += 1
            self.A[self.top] = x

    def pop(self):
        if not self.is_empty():
            x = self.A[self.top]
            self.top -= 1
            return x

    def top_element(self):
        if not self.is_empty():
            return self.A[self.top]


if __name__ == '__main__':
    S1 = Stack(20005)  # for \
    S2 = Stack(10005)  # for ponds
    line = raw_input()
    for i in range(len(line)):
        if line[i] == '\\':
            S1.push(i)
        elif line[i] == '/':
            if S1.is_empty():
                continue
            j = S1.pop()
            cnt = 0  # total area of ponds that can be merged
            # no more ponds can be merged if S2.top_element()[0] < j, why?
            # because '/' is clearly increasing toward the stack top
            # and '\' is increasing toward the stack top, too
            # if not, there exists a pond that should have been merged
            while not S2.is_empty() and S2.top_element()[0] > j:
                cnt += S2.pop()[1]
            S2.push((j, cnt + i - j))
        else:
            pass

    l = []
    cnt = 0
    while not S2.is_empty():
        x = S2.pop()
        cnt += x[1]
        l.append(x)
    l.reverse()
    print cnt
    print len(l),
    for x in l:
        print x[1],
    print


Measured memory_bytes: 5568
#include<stdio.h>

int output(int *A, int N, int count){
  for(int i = 0; i < N; i++){
    printf("%d", A[i]);
    if(i < N - 1){
      printf(" ");
    }
  }
  printf("\n");

  printf("%d\n", count);

  return 0;
} 

int selection_sort(int *A, int N){
  int count = 0;
  for(int i = 0; i < N; i++){
    int minj = i;
    for(int j = i; j < N; j++){
      if(A[j] < A[minj]){
        minj = j;
      }
    }
    if(i != minj){
      int tmp = A[i];
      A[i] = A[minj];
      A[minj] = tmp;
      count++;
    }
  }

  return count;
}
    
int main(void){
  int N;
  int A[101];

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

  int count = selection_sort(A, N);
  output(A, N, count);

  return 0;
}



Measured memory_bytes: 2756
//For higher stack size use g++ -O2 -std=c++11 -Wall -Wl,--stack=268435456 a.cpp -o a.exe in cmd
    #include <bits/stdc++.h>
    #include <cstdio>
    #include <cstring>
    #include <cmath>
    #include <cstring>
    #include <chrono>
    #include <complex>
    #define ll long long
    #define ld long double
    #define vi vector<int>
    #define vll vector<ll>
    #define vvi vector < vi >
    #define pii pair<int,int>
    #define pll pair<long long, long long>
    #define mod 1000000007
    #define inf 1000000000000000001;
    #define all(c) c.begin(),c.end()
    #define mp(x,y) make_pair(x,y)
    #define mem(a,val) memset(a,val,sizeof(a))
    #define eb emplace_back
    #define pb push_back
    #define f first
    #define s second
    
    using namespace std;

    class triple
    {
    public:
        int a,b,c,d;
    };
    vector<triple> v;

    int n,m;

    int ar[11],ans;

    void func(int i,int ct)
    {
        if(i==n+1)
        {
            int ans2=0;

            for(int j=0;j<v.size();++j)
            {
                if(ar[v[j].b]-ar[v[j].a]==v[j].c)
                {
                    ans2=ans2+v[j].d;
                }
            }
            ans=max(ans,ans2);
            return;
        }
        for(int j=ct;j<=m;++j)
        {
            ar[i]=j;
            func(i+1,j);
        }
    }

    int main()
    {
        std::ios::sync_with_stdio(false);
        int T;
        T=1;
        // cin.ignore(); must be there when using getline(cin, s)
        while(T--)
        {
            int q,i,j;
            cin>>n>>m>>q;
            int a,b,c,d;
            
            for(i=0;i<q;++i)
            {
                cin>>a>>b>>c>>d;
                v.pb({a,b,c,d});
            }
            func(1,1);
            cout<<ans<<endl;
        }
        return 0;
    }


Measured memory_bytes: 3620
#include<bits/stdc++.h>
using namespace std;
const long long INF = 1e9;
const long long MOD = 1000000007;
const long double PI = 3.1415926;
#define FOR(i,r,n) for(ll i = (ll)(r); i < (ll)(n); i++)
#define RFOR(i,r,n) for(ll i=(ll)(n-1);i>=r;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define ALL(x) x.begin(),x.end()
#define RALL(x) x.rbegin(),x.rend()
#define ll long long int
typedef vector<int> vi;
typedef vector < pair<int, int > > vp;
typedef vector <string> vs;
typedef vector <char> vc;
ll  n, k, ans = 0, sum = 0, cnt = 0;
string s;
char c;

/*--------------------template--------------------*/


int main() {
	int a, b, c; cin >> a >> b >> c;
	if (a % 2 == 1 || b % 2 == 1 || c % 2 == 1) {
		cout << 0 << endl;
		return 0;
	}
	if (a == b &&b == c) {
		cout << -1 << endl;
		return 0;
	}
	while (1) {
		ans++;
		int na = b / 2 + c / 2;
		int nb = a / 2 + c / 2;
		int nc = a / 2 + b / 2;
		swap(a, na);
		swap(b, nb);
		swap(c, nc);
		if (a % 2 == 1 || b % 2 == 1 || c % 2 == 1) break;
	}
	cout << ans << endl;
	return 0;
}

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

int main() {
  int n;

  cin >> n;

  for (int i = 0; i <= n; i++) {
    if (floor(i * 1.08) == n) {
      cout << i;
      return 0;
    }
  }

  cout << ":(";

  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
using namespace std;
int main(){
	int N;
  	cin>>N;
  	vector<int> h(N);
  	for(int i = 0;i<N;i++){
    	cin>>h[i];
    }

    vector<int> dp(N);
    dp[0] = 0;
    dp[1] = abs(h[1] - h[0]);
    for(int i =2 ;i<N;i++){
      dp[i] = min(dp[i-1] + abs(h[i] - h[i-1]), dp[i-2] + abs(h[i]- h[i-2]));
    }
  
  	cout<<dp[N-1]<<endl;
}
	

Measured memory_bytes: 3672
K = gets.to_i
S = gets.strip
M = 10**9 + 7

@p25, @p26 = [1, 25], [1, 26]
(2 .. K).each do |i|
  @p25[i] = @p25[i - 1]*25 % M
  @p26[i] = @p26[i - 1]*26 % M
end

s = S.length
@fac, @inv, @fiv = [1, 1], [1, 1], [1, 1]
(2 ... s + K).each do |i|
  @fac[i] = @fac[i - 1] * i % M
  @inv[i] = M - @inv[M % i] * (M / i) % M
  @fiv[i] = @fiv[i - 1] * @inv[i] % M
end
c = ->(n, k){@fac[n]*@fiv[n - k]*@fiv[k] % M}
puts (0 .. K).inject(0){|r, k| (r + c[s + K - k - 1, s - 1]*@p26[k]*@p25[K - k]) % M} % M

Measured memory_bytes: 78932
#include <bits/stdc++.h>
#define inf 2e18
using namespace std;
typedef long long ll;
ll arr[2000005];
int main()
{
    //freopen("in.txt", "r", stdin);
    int n;
    cin>>n;
    for(int i=1;i<=n;i++){
        ll x;
        cin>>x;
        arr[i]=arr[i-1]+x;
    }
    //for(int i=1;i<=n;i++)cout<<arr[i]<<" ";
    ll ans=inf;
    for(int i=1;i<n;i++){
        ans=min(ans,abs(arr[n]-arr[i]-arr[i]));
    }
    cout<<ans<<endl;
}



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

struct UnionFind {
    vector<int> par;

    UnionFind(int N) : par(N) {
        for (int i=0; i<N; i++) par[i] = i;
    }

    int find(int x) {
        if (par[x] == x) return x;
        return par[x] = find(par[x]);
    }

    void unite(int x, int y) {
        int rx = find(x);
        int ry = find(y);
        if (rx == ry) return;
        par[rx] = par[ry];
    }

    bool same(int x, int y) {
        return find(x) == find(y);
    }
};

int main() {
    int N, K, L; cin >> N >> K >> L;
    int p[K], q[K], r[L], s[L];
    UnionFind road(N+1), rail(N+1);
    for (int i=0; i<K; i++) {
        int p, q; cin >> p >> q;
        road.unite(p, q);
    }
    for (int i=0; i<L; i++) {
        int r, s; cin >> r >> s;
        rail.unite(r, s);
    }
    map<pii, int> ma;
    for (int i=1; i<=N; i++) {
        pii p(road.find(i), rail.find(i));
        ma[p]++;
    }
    for (int i=1; i<=N; i++) {
        pii p(road.find(i), rail.find(i));
        cout << ma[p] << " ";
    }
    cout << endl;
}

Measured memory_bytes: 13568
#include <algorithm>
#include <bitset>
#include <cmath>
#include <iostream>
#include <iterator>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <unordered_map>
#include <utility>
using namespace std;

#define ABS(a) (((a) >= 0) ? (a) : -(a))
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define MIN(a, b) ((a) > (b) ? (b) : (a))
#define FOR(i, a, b) for (int i = a; i < b; ++i)
#define RFOR(i, a, b) for (int i = a; i > b; --i)
#define REP(i, n) for (int i = 0; i < n; ++i)
#define int long long

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

const int kMaxN = 2000;

int N;
vector<pair<char, int>> ca;
int ans = 0;

class C {
public:
  size_t operator()(const pair<char, int>& p) const {
    return p.first*11113 + p.second;
  }
};

unordered_map<pair<char, int>, int, C> h;
int cntw[kMaxN*2+1][kMaxN];
int cntb[kMaxN*2+1][kMaxN];
int dp[kMaxN+1][kMaxN+1];

int Cost(char c, int i, int j) {
  if (c == 'W') {
    int ni = h[make_pair(c,i)];
    if (i != 0) { i -= cntw[ni][i-1]; }
    if (j != 0) { j -= cntb[ni][j-1]; }
    return i+j;
  } else {
    int ni = h[make_pair(c,j)];
    if (i != 0) { i -= cntw[ni][i-1]; }
    if (j != 0) { j -= cntb[ni][j-1]; }
    return i+j;
  }
}

signed main() {
  cin >> N;
  REP(i, 2*N) {
    char c; int a;
    cin >> c >> a;
    pair<char, int> p = make_pair(c,a-1);
    ca.push_back(p);
    h[p] = i;
  }

  REP(j, N) {
    cntw[0][j] = 0;
    cntb[0][j] = 0;
  }
  REP(i, 2*N) {
    REP(j, N) {
      cntw[i+1][j] = cntw[i][j];
      if (ca[i].first == 'W' && ca[i].second <= j) { cntw[i+1][j]++; }
      cntb[i+1][j] = cntb[i][j];
      if (ca[i].first == 'B' && ca[i].second <= j) { cntb[i+1][j]++; }
    }
  }

  dp[0][0] = 0;
  REP(i, N+1) {
    REP(j, N+1) {
      if (i == 0 && j == 0) { continue; }
      if (i == 0) {
        dp[i][j] = dp[i][j-1] + Cost('B', i, j-1);
      } else if (j == 0) {
        dp[i][j] = dp[i-1][j] + Cost('W', i-1, j);
      } else {
        dp[i][j] = MIN(
          dp[i][j-1] + Cost('B', i, j-1),
          dp[i-1][j] + Cost('W', i-1, j));
      }
    }
  }
  ans = dp[N][N];

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


Measured memory_bytes: 156928
#include <bits/stdc++.h>
#define LL long long
#define MEM(x,y) memset(x,y,sizeof(x))
#define MOD(x) ((x)%1000000007)

using namespace std;
const int maxn = 1e5 + 7;
char s[maxn];
vector<int>E[maxn];
int main()
{
    scanf("%s", s);
    int n = strlen(s);
    for(int i = n; i > 0; i--) s[i] = s[i - 1];
    if(s[n] == '1' || s[1] == '0' || s[n - 1] == '0')
    {
        printf("-1");
        return 0;
    }
    int cnt = 0, last = 1, now = 2;
    for(int i = 1; i <= n / 2; i++)
    {
        if(s[i] != s[n - i])
        {
            printf("-1");
            return 0;
        }
        cnt++;
        if(s[i] == '1')
        {
            while(cnt)
            {
                E[last].push_back(now);
                now++; cnt--;
            }
            last = now-1;
            cnt = 0;
        }
    }
    while(now <=n)
    {
        E[last].push_back(now);
        now++;
    }
    for(int i = 1; i <= n; i++)
        for(int j = 0; j < E[i].size(); j++)
            printf("%d %d\n", i, E[i][j]);

    return 0;
}


Measured memory_bytes: 5756
fun main(args: Array<String>) {
    val s = readLine() ?: return
    val p = Array(s.length) { 0 }

    var c = 0
    var i = 0
    while (i < s.length) {
        if (s[c] == 'R' && s[i] == 'L') {
            val t = i - c + 1
            p[i] += t / 2 + t % 2
            p[i - 1] += t / 2
            c = i + 1
        } else if ((s[c] == 'L' && s[i] == 'R')) {
            val t = i - c
            p[c - 2] += t / 2 + t % 2
            p[c - 1] += t / 2
            c = i
        } else if (s[c] == 'L' && i == s.length - 1) {
            val t = i - c + 1
            p[c - 2] += t / 2 + t % 2
            p[c - 1] += t / 2
            c = i
        }
        i++
    }
    println(p.joinToString(separator = " "))
}

Measured memory_bytes: 39904
#include <bits/stdc++.h>
#define INF 100000000000
#define ll long long
#define pll pair<ll, ll>
using namespace std;

int main()
{
  ll N;
  cin >> N;
  vector<ll> A(N);
  for (ll i = 0; i < N; ++i) {
    cin >> A.at(i);
  }
  sort(A.begin(), A.end());
  unordered_map<ll, ll> mp;
  ll ans = 0;
  for (ll i = 0; i < N; ++i) {
    mp[A.at(i)] += 1;
  }
  for (ll i = N - 1; i >= 0; --i) {
    if (mp[A.at(i)] == 0) {
      continue;
    }
    mp[A.at(i)] -= 1;
    ll pow2 = 1;
    while (pow2 <= A.at(i)) {
      pow2 *= 2;
    }
    ll need = pow2 - A.at(i);
    // cout << "need" << need << endl;
    if (mp[need] != 0) {
      mp[need] -= 1;
      ans += 1;
    }
    else {
      mp.erase(need);
    }
  }
  cout << ans << endl;
}


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



int main(int argc, char const *argv[]) {
  int n,k,score=0;
  string s;
  cin >> n >> k >> s;
  for(int i=0; i<n-1; i++){
    while(s[i]==s[i+1]){
      score++;
      i++;
    }
  }

  cout << min(n-1,score+2*k) << endl;
  return 0;
}


Measured memory_bytes: 512
#include <map>
#include <set>
#include <cmath>
#include <queue>
#include <stack>
#include <cctype>
#include <cstdio>
#include <string>
#include <vector>
#include <cstdlib>
#include <cstring>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <functional>

#define INF (2 << 28)
#define fr first
#define sc second
using namespace std;

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

int main(){
  
  string s;
  int kmax = 0;

  cin >> s;
  
  for(int i = 0; i < s.size(); i++){
    bool j1, j2;
    int cnt = 0;
    if(s[i] == 'O'){
      j1 = false, j2 = false;
      cnt = 1;
      for(int j = i + 1; s[j] == 'O' && j < s.size(); j++) cnt++;
      for(int j = i - 1, c = 1; s[j] == 'J' && j >= 0; j--, c++){
        if(c == cnt){
          j1 = true;
          break;
        }
      }
      for(int j = i + cnt, c = 1; s[j] == 'I' && j < s.size(); j++, c++){
        if(c == cnt){
          j2 = true;
          break;
        }
      }
    }
    if(j1 && j2) kmax = max(kmax, cnt);
    i += cnt;
  }
  
  cout << kmax << endl;
      
}

Measured memory_bytes: 2048
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
 
using namespace __gnu_pbds;
using namespace std;
 
typedef   long long int ll;
typedef unsigned long long int sll;
typedef  double ld;
#define A 1000000007ll
#define B 998244353ll
#define C 1000000000000000000ll
#define FAST ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define pb push_back
#define mxe(v) *max_element(v.begin(),v.end())
#define mne(v) *min_element(v.begin(),v.end())
#define bs binary_search
#define lb lower_bound
#define ub upper_bound
#define ve vector
#define br break
#define PI 3.1415926535

ll dp[100004][105];

int main() 
{
    FAST;
    ll n,w;
    cin>>n>>w;
    ll aw[n],av[n];
    for(int i=0;i<n;i++)
        cin>>aw[i]>>av[i];
    for(ll i=0;i<100004;i++)
        for(int j=0;j<105;j++)
            dp[i][j]=1000000000000ll;
    dp[av[0]][0]=aw[0];
    dp[0][0]=0;
    for(int j=1;j<n;j++)
    {
        for(ll i=0;i<100004;i++)
        {
            if(i>=av[j] && dp[i-av[j]][j-1]!=1000000000000ll)
                dp[i][j]=min(dp[i][j],dp[i-av[j]][j-1]+aw[j]);
            dp[i][j]=min(dp[i][j],dp[i][j-1]);
        }
    }
    ll ma=0;
    for(ll i=0;i<100004;i++)
        if(dp[i][n-1]<=w)
            ma=i;
    cout<<ma;
    return 0;
}

Measured memory_bytes: 82432
#include <iostream>
#include <algorithm>
#include <cmath>
#include <limits>
#include <vector>
#include <cstdio>
#include <bits/stdc++.h>
#include <set>
#include <map>
#include <stdio.h>
#include <stack>
#include <queue>
#include <deque>
#include <numeric>
#include <bits/stdc++.h>
#include <utility>
#include <iomanip>

#define ALL(obj) (obj).begin(), (obj).end()
#define FOR(i,a,b) for(int i = (a); i < (b); i++)
#define RFOR(i,a,b) for(int i = (a); (b) <= i; i--)
#define REP(i,n) for(int i = 0; i < (n); i++)
#define RREP(i,n) for(int i = n; n <= i; i--)
#define ABS(a) ((a < 0) ? ((-1)*(a)) : (a))
#define elif else if
#define MOD 1000000007
#define INF (1<<30)

using namespace std;

#define ld long double
#define ll long long

map <int ,int> mpa,mpb;
typedef pair<ll, ll> P;
priority_queue<P, vector<P>, greater<P>> pque;

int main(){
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  int H,W ,h,w;
  cin >> H >> W  >>h >> w;
  cout << H*W-h*W-H*w+w*h << endl;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
    int k;
    cin>>k;
    string s;
    cin>>s;
    int l=s.size();
    if(l<=k)
        cout<<s<<endl;
    else{
        for(int i=0; i<k; i++)
            cout<<s[i];
        cout<<"..."<<endl;
    }

    return 0;
}


Measured memory_bytes: 3572
#pragma GCC optimize ("O3")
// #pragma GCC target ("avx")
#include<stdio.h>
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<string.h>

#ifdef LOCAL
#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
#define NDEBUG
#define eprintf(...) do {} while (0)
#endif
#include<cassert>

using namespace std;

typedef long long LL;
typedef vector<int> VI;

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define EACH(i,c) for(__typeof((c).begin()) i=(c).begin(),i##_end=(c).end();i!=i##_end;++i)

template<class T> inline void amin(T &x, const T &y) { if (y<x) x=y; }
template<class T> inline void amax(T &x, const T &y) { if (x<y) x=y; }
template<class Iter> void rprintf(const char *fmt, Iter begin, Iter end) {
    for (bool sp=0; begin!=end; ++begin) { if (sp) putchar(' '); else sp = true; printf(fmt, *begin); }
    putchar('\n');
}

int N;
LL A[200011];

LL dp[200011][2][4];


void MAIN() {
    scanf("%d", &N);
    REP (i, N) scanf("%lld", A+i);

    memset(dp, 0xc0, sizeof dp);
    dp[0][0][0] = 0;
    REP (i, N+1) {
	REP (a, 3) {
	    amax(dp[i+1][1][a], dp[i][0][a] + A[i]);
	}
	REP (a, 3) {
	    amax(dp[i+1][0][a], dp[i][1][a]);
	}
	REP (a, 2) {
	    amax(dp[i+1][0][a+1], dp[i][0][a]);
	}
    }

    LL ans = 0;
    if (N % 2 == 0) ans = dp[N+1][0][1];
    else ans = dp[N+1][0][2];


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

int main() {
    int TC = 1;
//    scanf("%d", &TC);
    REP (tc, TC) MAIN();
    return 0;
}



Measured memory_bytes: 17884
import sys

# import re
import math
import collections
# import decimal
import bisect
import itertools
import fractions
# import functools
import copy
import heapq
import decimal
# import statistics
import queue

sys.setrecursionlimit(10000001)
INF = 10 ** 16
MOD = 10 ** 9 + 7

ni = lambda: int(sys.stdin.readline())
ns = lambda: map(int, sys.stdin.readline().split())
na = lambda: list(map(int, sys.stdin.readline().split()))


# ===CODE===


def main():
    def make_divisors(n):
        divisors = []
        for i in range(1, int(n ** 0.5) + 1):
            if n % i == 0:
                divisors.append(i)
                if i != n // i:
                    divisors.append(n // i)

        # divisors.sort(reverse=True)
        return divisors

    n, m = ns()
    gcd = make_divisors(m)

    max_gcd = 1
    for d in gcd:
        if m // d >= n:
            max_gcd = max(max_gcd, d)

    print(max_gcd)


if __name__ == '__main__':
    main()


Measured memory_bytes: 5092
import sys
from collections import defaultdict
def cmb(n, r):
    if n - r < r: r = n - r
    if r == 0: return 1
    if r == 1: return n

    numerator = [n - r + k + 1 for k in range(r)]
    denominator = [k + 1 for k in range(r)]

    for p in range(2,r+1):
        pivot = denominator[p - 1]
        if pivot > 1:
            offset = (n - r) % p
            for k in range(p-1,r,p):
                numerator[k - offset] /= pivot
                denominator[k] /= pivot

    result = 1
    for k in range(r):
        if numerator[k] > 1:
            result *= int(numerator[k])

    return result


input = sys.stdin.readline

n = int(input())
d = defaultdict(lambda: 0)

for i in range(n):
    s = list(str(input()).rstrip())
    s.sort()
    s = "".join(s)
    d[s] += 1   

ans = 0
for key in d.keys():
    if d[key] >= 2:
        ans += cmb(d[key], 2)
print(int(ans))

Measured memory_bytes: 18184
A,B,C,D = map(int, input().split())

def gcm(x, y):
    x, y = max(x, y), min(x, y)
    if y == 0:
        return x
    else:
        return gcm(y, x%y)

def lcm(x, y):
    return x * y // gcm(x, y)

def canDevide(n, x, y):
    return n - n//x - n//y + n//lcm(x, y)

print(canDevide(B, C, D) - canDevide(A-1, C, D))

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
string s;
long long K;
int main(){
	cin>>s;
	cin>>K;
	REP(i,s.size()){
	    int a=s[i]-'a';
	    if(a==0){
	       continue;
	    }
	    a=26-a;
	    if(K>=a){
	       K-=a;
	       s[i]='a';
	    }
	}
	if(K>0){
	   int x=s.size()-1;
	   int y=s[x]-'a';
	   y=(y+K)%26;
	   s[x]='a'+y;
	}
        cout<<s<<endl;
	return(0);
}

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

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

	int ac = abs(c - a);
	int ab = abs(b - a);
	int bc = abs(c - b);

	if (ac <= d || (ab <= d && bc <= d))
		cout << "Yes\n";
	else
		cout << "No\n";
	return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

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

        int n = stdIn.nextInt();
        int[] x = new int[n];
        for(int i=0; i<n; i++){
            x[i] = stdIn.nextInt();
        }

        long minEnergy = Long.MAX_VALUE;
        for(int pos=1; pos<=100; pos++){
            long energy = 0;
            for(int i=0; i<n; i++){
                energy += Math.pow((x[i] - pos), 2);
            }
            if(energy < minEnergy){
                minEnergy = energy;
            }
        }

        System.out.println(minEnergy);
    }
}

Measured memory_bytes: 21972
def find(x):
    while table[x] >= 0:
        x = table[x]
    return x

def union(x, y):
    s1 = find(x)
    s2 = find(x)
    if s1 != s2:
        if table[s1] != table[s2]:
            if table[s1] < table[s2]:
                table[s2] = s1
            else:
                table[s1] = s2
        else:
            table[s1] -= 1
            table[s2] = s1
    return
    


a1, b1 = map(int, input().split())
a2, b2 = map(int, input().split())
a3, b3 = map(int, input().split())

ans = [0 for i in range(4)]

ans[a1-1] += 1 
ans[a2-1] += 1 
ans[a3-1] += 1 
ans[b1-1] += 1 
ans[b2-1] += 1 
ans[b3-1] += 1 

if 0 in ans or 3 in ans:
    print("NO")
else:
    print("YES")


Measured memory_bytes: 38384
N = int(input().rstrip())
B = list(map(int, input().split()))
A = [0] * (N-1)
A.insert(0, B[0])
#print(B)

for i in range(1,N-1):
  c = min([B[i-1],B[i]])
  A.insert(i, c)
  #print(c)
  
A.insert(N-1, B[N-2])

#print(A)
print(sum(A))

Measured memory_bytes: 3064
h, w = map(int, input().split())
s0 = ["."] * (w + 2)
s = [["."] + list(input()) + ["."] for _ in range(h)]
s.insert(0, s0)
s.append(s0)
v = [[-1, 1], [0, 1], [1, 1], [1, 0], [1, -1], [0, -1], [-1, -1], [-1, 0]]
ans = []
for i in range(1, h + 1):
    a = []
    for j in range(1, w + 1):
        c = 0
        if s[i][j] == ".":
            for u in v:
                if s[i + u[0]][j + u[1]] == "#":
                    c += 1
            a.append(str(c))
        else:
            a.append("#")
    ans.append(a)
for b in ans:
    print("".join(b))

Measured memory_bytes: 3188
import java.util.Scanner;

public class Main {

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

		String str = sc.next();

		boolean isEasy = true;

		int length = str.length();

		for (int i = 0; i < length; i++) {
			String chr = str.substring(i, i + 1);
			if (i % 2 != 0) {
				if (chr.equals("R")) {
					isEasy = false;
					break;
				}
			} else {
				if (chr.equals("L")) {
					isEasy = false;
					break;
				}
			}
		}

		System.out.println(isEasy ? "Yes" : "No");

	}

}



Measured memory_bytes: 22996
#include <bits/stdc++.h>
using namespace std;
#define INF 2147483647
#define INFF 9223372036854775807
#define ll long long
#define REP(i,n) for(int i=0;i<n;i++)
#define REPP(i,m,n) for(int i=m;i<n;i++)
#define ALL(N) (N.begin(),N.end())
#define de cout << "debug" << endl;
#define pb push_back
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }


int main() {
    cin.tie(0);    
	ios::sync_with_stdio(false);
    int N;
    cin >> N;
    int W[N] = {};

    int sum = 0;
    REP(i,N){
        cin >> W[i];
        sum += W[i];
    }
    vector<int> sa;
    vector<int> noko;
    int sumv = sum;
    int A = 0;
    REP(i,N-1){
        A += W[i];
        sa.pb(A);
        noko.push_back(sumv - A);
        sumv = sum;
    }
    int minv = INF;
    REP(i,sa.size()){
        minv = min(minv,abs(noko[i]-sa[i]));
    }
    cout << minv << endl;
}

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

using ll = long long;
using ld = long double;
using pii = pair<int, int>;

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
#define m0(x) memset(x,0,sizeof(x))

int dx4[4] = {1,0,-1,0}, dy4[4] = {0,1,0,-1};


int main()
{
    int n,m,x,bef=0,aft=0;
    cin>>n>>m>>x;
    
    for(int i = 0; i < m; i++)
    {
        int a;
        cin>>a;
        if(a<x)bef++;
        else aft++;
    }
    cout<<min(bef,aft)<<endl;


    return 0;
}

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

ll gcd(ll a, ll b) { 
	if (b == 0) 
		return a; 
	return gcd(b, a % b); 
	
} 

// Driver program to test above function 
int main() { 
    ll a, b;
    cin >> a >> b;
    cout << a * b / gcd (a, b) << endl;
	return 0; 
} 




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

using namespace std;
using ll = long long int;
const int MOD = 1e9 + 7;

ll mpow(ll a, ll n, ll m = MOD)
{
	ll r = 1;
	while (n)
	{
		if (n&1) r = (r*a)%m;
		a = (a*a)%m;
		n >>= 1;
	}
	return r;
}

void solve()
{
	int n; cin >> n;
	vector<int> g[n];
	for (int i = 0; i < n-1; ++i)
	{
		int u, v; cin >> u >> v;
		g[--u].pb(--v);
		g[v].pb(u);
	}
	int a[n];
	for (int i = 0; i < n; ++i)
	{
		cin >> a[i];
	}
	sort(a, a+n);
	ll Val = 0;
	for (int i = 0; i < n; ++i)
	{
		Val += a[i];
	}
	Val -= a[n-1];
	cout << Val << '\n';
	queue<int> q;
	int pos = n-1;
	q.push(0);
	int ans[n] = {0};
	while (!q.empty())
	{
		auto u = q.front(); q.pop();
		ans[u] = a[pos]; --pos;
		for (auto v : g[u])
		{
			if (ans[v]) continue;
			q.push(v);
		}
	}
	for (int i = 0; i < n; ++i)
	{
		cout << ans[i] << ' ';
	}
}

//  ---------------------Template---------------------------
void InputSetup()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);

	#ifdef LOCAL
	freopen("in", "r", stdin);
	freopen("out", "w", stdout);
	#endif
}

int main(void)
{
	auto start = chrono::high_resolution_clock::now();

	InputSetup();
	solve();

	auto finish = chrono::high_resolution_clock::now();
	cerr << "Time elapsed: " << (chrono::duration<long double>(finish-start)).count() << "s\n";
}
//  ---------------------Template---------------------------

Measured memory_bytes: 1024
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <cstdio>
#define ll long long int

using namespace std;

int n,a[109];
double sum;

int main()
{
    ///freopen("INA.txt","r",stdin);
    ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
    cin>> n;
    for(int i=1;i<=n;i++){
        cin>> a[i];
        sum+=a[i];
    }

    int up = ceil(sum/n);
    int down = floor(sum/n);

    int upsum=0,downsum=0;
    for(int i=1;i<=n;i++){
        upsum+=abs(up-a[i])*abs(up-a[i]);
        downsum+=abs(down-a[i])*abs(down-a[i]);
    }
    cout<< min(upsum,downsum) << endl;
    return 0;
}


Measured memory_bytes: 3652
import java.util.*;
 
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int a = sc.nextInt();
    int b = sc.nextInt();
    if(a > b){
      System.out.println("safe");
    }else{
      System.out.println("unsafe");
    }
  }
}

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

using namespace std;
typedef long long ll;
//typedef unsigned long long ll;

#define rep(i, n) for (int i = 0; i < (n); ++i)
//#define rep(i, n) for (ll i = 0; i < (n); ++i)
//#define sz(x) ll(x.size())
//typedef pair<ll, int> P;
typedef pair<ll, ll> P;
//const double INF = 1e10;
const ll INF = LONG_LONG_MAX / 10;
//const ll INF = 1e15;
const ll MINF = LONG_LONG_MIN;
//const int INF = INT_MAX / 10;
#define cmin(x, y) x = min(x, y)
#define cmax(x, y) x = max(x, y)
//typedef pair<int, int> P;
//typedef pair<double, double> P;

bool contain(set<P> &s, P a) { return s.find(a) != s.end(); }

//ifstream myfile("C:\\Users\\riku\\Downloads\\0_00.txt");
//ofstream outfile("log.txt");
//outfile << setw(6) << setfill('0') << prefecture << setw(6) << setfill('0') << rank << endl;
// std::cout << std::bitset<8>(9);


void print_line(vector<ll> &line) {
    if (line.size() == 0ll) {
        cout << endl;
        return;
    }
    for (ll i = 0; i < line.size(); i++) {
        cout << line[i];
        if (i == line.size() - 1) cout << endl;
        else cout << ' ';
    }
}


typedef priority_queue<long long, vector<long long>, greater<long long>> PQ_ASK;
const int mod = 1000000007;

int main() {

    ll x;
    cin >> x;

    cout << bitset<32>(x) << endl;
    cout << bitset<32>(~x) << endl;
    cout << bitset<32>(x << 1) << endl;
    cout << bitset<32>(x >> 1) << endl;


}



Measured memory_bytes: 3164
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
using namespace std;
using P = pair<int, int>;
const int MX = 100005;
const int INF = 1e9;
int n, k, a, b, v, p;
vector<int> G[MX];
P ran[MX];
P dfs(int p, int t){
	int l,r, nl, nr;
	tie(nl, nr) = ran[t];
	bool out = false;
	for(int nx: G[t]) if(nx != p){
		tie(l,r) = dfs(t,nx);
		if(r == INF) continue;
		if(nr == INF || (nl + l) % 2){
			nl = max(l-1, nl);
			nr = min(r+1, nr);
		}else out = true;
		if(out || nl > nr){
			puts("No");
			exit(0);
		}
	}
	return ran[t] = P(nl,nr);
}
void dfs_2(int p, int t){
	for(int nx: G[t]) if(nx != p){
		ran[nx].first = min(ran[nx].second, ran[t].first + 1);
		dfs_2(t,nx);
	}
}
int main(){
	scanf("%d", &n);
	fill(ran, ran+n, P(-INF,INF));
	rep(i,n-1){
		scanf("%d%d", &a, &b);
		a--; b--;
		G[a].push_back(b);
		G[b].push_back(a);
	}
	scanf("%d", &k);
	rep(i,k){
		scanf("%d%d", &v, &p);
		ran[v-1] = P(p,p);
	}
	dfs(0,0);
	dfs_2(0,0);
	puts("Yes");
	rep(i,n) printf("%d\n", ran[i].first);
}

Measured memory_bytes: 14976
def main():

    N, K = map(int, input().split())
    h = list(map(int, input().split()))
    DP = [0]*N
    DP[1] = abs(h[1]-h[0])

    for i in range(2, N):
        DP[i] = min(abs(h[i]-h[j]) + DP[j] for j in range(max(0, i-K), i))
    print(DP[-1])
    
main()

Measured memory_bytes: 13980
// template
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<long long, long long> LP;
#define INF 999999999
#define MOD 1000000007
#define REP(i, n) for(ll i = 0, i##_len = (n); i < i##_len; ++i)
#define REP_AB(i, a, b) for (ll i = ll(a); i <= ll(b); ++i)
#define ALL(v) v.begin(), v.end()
#define SORT(v) sort(ALL(v))
#define UNIQUE(v) sort(ALL(v));v.erase(unique(ALL(v)), v.end());
#define SIZE(x) ((ll)(x).size())
#define REVERSE(v) reverse(ALL(v))
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return (a / gcd(a, b)) * b;}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
#define out cout
#define in cin
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 end

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll n, m;
    in >> n >> m;
    vector<ll> count(n);
    ll a, b;
    REP(i, m){
        in >> a >> b;
        count[a-1] += 1;
        count[b-1] += 1;
    }
    REP(i, n){
        out << count[i] << endl;
    }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  while(1){
    int cnt=0;
    string s,l,n;
    cin>>n;
    if(n=="0000")break;
    if(n[0]==n[1]&&n[1]==n[2]&&n[2]==n[3]){
      cout<<"NA"<<endl;
      continue;
    }
    while(1){
      if(n=="6174")break;
      s=n;
      l=n;
      sort(s.begin(),s.end());
      l=s;
      reverse(l.begin(),l.end());
      int t=1,ns=0,nl=0;
      for(int i=3;i>=0;i--){
	ns+=(s[i]-'0')*t;
	t*=10;
      }
      t=1;
      for(int i=3;i>=0;i--){
	nl+=(l[i]-'0')*t;
	t*=10;
      }
      n="";
      int temp=nl-ns;
      for(int i=0;i<4;i++){
	int m=temp%10;
	n+=((char)m+'0');
	temp/=10;
      }
      reverse(n.begin(),n.end());
      cnt++;
    }
    cout<<cnt<<endl;
  }
  return(0);
}



Measured memory_bytes: 3152