akhauriyash/Code-Regression huggingface dataset:
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;

ll H, W, N;
ll sr, sc;
string S, T;

int main(){
    cin >> H >> W >> N;
    cin >> sr >> sc;
    cin >> S;
    cin >> T;
    string ans = "YES";
    ll l = 1, r = W + 1;
    for(int i = N - 1; i >= 0; i--){
        if(T[i] == 'L')r = min(r + 1, W + 1);
        if(T[i] == 'R')l = max(l - 1, 1LL);
        if(S[i] == 'L')l = min(l + 1, W + 1);
        if(S[i] == 'R')r = max(r - 1, 1LL);
        if(r == l)ans = "NO";
    }
    if(sc < l || r <= sc)ans = "NO";
    ll u = 1, d = H + 1;
    for(int i = N - 1; i >= 0; i--){
        if(T[i] == 'U')d = min(d + 1, H + 1);
        if(T[i] == 'D')u = max(u - 1, 1LL);
        if(S[i] == 'U')u = min(u + 1, H + 1);
        if(S[i] == 'D')d = max(d - 1, 1LL);
        if(u == d)ans = "NO";
    }
    if(sr < u || d <= sr)ans = "NO";

    cout << ans << endl;

    return 0;
}

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

using namespace std;
using ll = long long;

#pragma region Macros
#define FOR(i, m, n) for (ll i = (ll)(m); i < (ll)(n); i++)
#define rep(i, n) FOR(i, 0, n)

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

template <class T> string join(const T &v, const string delim = ",")
{
    if (v.empty())
        return "";

    ostringstream res;
    res << v[0];
    for (int i = 1; i < v.size(); i++)
    {
        res << delim << v[i];
    }
    return res.str();
}

#ifdef LOCAL
#define dbg(x) cerr << __LINE__ << ":" << #x << " = " << (x) << endl;
#else
#define dbg
#endif

#pragma endregion Macros
struct UnionFind {
    vector<int> par;
    UnionFind(int n) : par(n, -1) {
    }

    int root(int x) {
        if (par[x] < 0) {
            return x;
        }
        int r = root(par[x]);
        par[x] = r;
        return r;
    }

    bool same(int a, int b) {
        return root(a) == root(b);
    }

    void unite(int a, int b) {
        int ra = root(a);
        int rb = root(b);
        if (ra == rb)
            return;

        if (par[ra] < par[rb]) {
            swap(ra, rb);
        }
        par[ra] += par[rb];
        par[rb] = ra;
    }

    int size(int x) {
        return -par[root(x)];
    }
};
int main()
{
    int N, M;
    cin >> N >> M;

    UnionFind uf(N);

    rep(i,M){
        int A,B;
        cin >> A >> B;
        A--;
        B--;
        uf.unite(A, B);
    }

    int ans = 0;
    for (int i = 0; i < N; i++) {
        chmax(ans, uf.size(i));
    }

    cout << ans << endl;
}


Measured memory_bytes: 10096
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE TypeFamilies #-}
import           Data.Maybe
import           Data.Int
import           Data.List
import           Data.Char
  -- import qualified Data.Vector.Unboxing as VU
import qualified Data.Vector as V
import qualified Data.Vector.Mutable as VM
import qualified Data.Vector.Unboxed as VU
import qualified Data.Vector.Unboxed.Mutable as VUM
import qualified Data.ByteString.Char8 as BS
import           Data.List (scanl')
import           Data.IORef
import           Control.Monad
import           Control.Monad.ST
import           Control.Monad.State.Strict
import           Control.Applicative

readInt = BS.readInt . BS.dropWhile isSpace
getVector f = VU.unfoldr f <$> BS.getLine
getIntVector = getVector readInt
getBSVector = getVector BS.uncons

main = do
  [n,k] <- map read . words <$> getLine :: IO [Int]
  s <-  VU.thaw =<< VU.fromList <$> getLine
  -- let newS = VU.modify toLower (k+1)
  VUM.modify s toLower (k-1)
  putStrLn . VU.toList =<< VU.freeze s


Measured memory_bytes: 508
*n, = map(int, list(input()))

def op(x):
    ops = []
    for i in range(3):
        ops.append(x%2)
        x//=2
    return ops

for x in range(2**3):
    ops = op(x)
    y = n[0]
    for i in range(1,4):
        y += n[i]*(1 if ops[i-1]==1 else -1)
    if y == 7:
        break

ans = str(n[0])
for i in range(3):
    if ops[i] == 1:
        ans += '+'
    else:
        ans += '-'
    ans += str(n[i+1])
print(ans+'=7')


Measured memory_bytes: 3064
// Problem : C - Step
// Contest : AtCoder - AtCoder Beginner Contest 176
// URL : https://atcoder.jp/contests/abc176/tasks/abc176_c
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include <iostream>

#define max( a, b ) a > b ? a : b

using namespace std;

const int N = 2e5 + 5;
int       a;
int       cur_max;
int       n;
long long ans;

int main() {
    cin >> n;
    for ( int i = 0; i < n; i++ ) {
        cin >> a;
        cur_max = max( cur_max, a );
        ans += ( cur_max - a );
    }
    cout << ans;
}

Measured memory_bytes: 3632
x,n = list(map(int, input().split()))
p = list(map(int, input().split()))

if not x in p:
  print(x)
else:
  for i in range(1,100):
    if not x-i in p:
      print(x-i)
      break
    if not x+i in p:
      print(x+i)
      break



Measured memory_bytes: 61840
#include<iostream>
#include<cstdio>
using namespace std;
int main(){
  int a,b;
  scanf("%d%d",&a,&b);
  printf("%d\n",a+b>a-b?a+b>a*b?a+b:a*b:a-b>a*b?a-b:a*b);
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
	int t;cin>>t;vector<int>dp(3,0);
	while(t--){
		vector<int>nw_dp(3,0);
		vector<int>man(3);for(int &x:man)cin>>x;
			for(int u=0;u<3;u++){
				for(int v=0;v<3;v++){
				if(v!=u){
					nw_dp[v]=max(nw_dp[v],man[v]+dp[u]);}
				}
			}
			dp=nw_dp;}
	cout<<max({dp[0],dp[1],dp[2]});
}


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

using namespace std;

#define REP(i, n) for (int i=0; i<(n); ++i)
#define FOR(i, a, n) for (int i=(a); i<(n); ++i)

#define SZ(x) ((int)(x).size())
#define ALL(x) (x).begin(),(x).end()

#define DUMP(x) cerr<<#x<<" = "<<(x)<<endl
#define DEBUG(x) cerr<<#x<<" = "<<(x)<<" (L"<<__LINE__<<")"<<endl;

template<class T>
ostream &operator<<(ostream &os, const vector <T> &v) {
  os << "[";
  REP(i, SZ(v)) {
    if (i) os << ", ";
    os << v[i];
  }
  return os << "]";
}

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

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

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

using ll = long long;
using ull = unsigned long long;
using ld = long double;
using P = pair<int, int>;
using vi = vector<int>;
using vll = vector<ll>;
using vvi = vector<vi>;
using vvll = vector<vll>;

const ll MOD = 1e9 + 7;
const int INF = INT_MAX / 2;
const ll LINF = LLONG_MAX / 2;
const ld eps = 1e-9;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);

  ll n, x, d; cin >> n >> x >> d;

  if(d == 0) {
    if(x == 0) cout << 1 << endl;
    else cout << n + 1 << endl;
    return 0;
  }
  if(d < 0) {
    x = -x;
    d = -d;
  }
  //cout << x << " " << d << endl;

  //ll cons = n * x + (n * (n-1) / 2 * d);
  //cout << cons << endl;

  vll su(n+2);
  REP(i, n+1) {
    su[i+1] = su[i] + i;
  }

  using PLL = pair<ll, ll>;
  map<ll, vector<PLL>> v;
  REP(i, n+1) {
    // 2aX + 2bD
    ll idx = i * x % d;
    ll div = i * x / d;
    // d * div + idx == i * x;
    //cout << idx << endl;
    /*
    while(idx < 0) {
      idx += d;
      div--;
    }
     */
    //cout << idx << endl;
    //cout << endl;

    ll lb = su[i];
    ll rb = su[n] - su[n-i];
    //cout << lb << ":" << rb << endl;

    ll tmpl = div + lb;
    ll tmpr = div + rb;

    v[idx].emplace_back(tmpl, tmpr+1);
  }
  for(auto &e: v) {
    sort(ALL(e.second));
  }

  ll ans = 0;
  for(auto &v1: v){
    ll now = -1;
    REP(j, SZ(v1.second)) {
      ll l = v1.second[j].first, r = v1.second[j].second;
      //cout << i << ":" << l << " " << r << endl;
      if(now == -1) {
        ans += r - l;
        now = r;
      } else if(now < l) {
        ans += r - l;
        now = r;
      } else if(now < r){
        ans += r - now;
        now = r;
      }
    }
  }
  cout << ans << endl;



  return 0;
}

Measured memory_bytes: 26688
#include<iostream>

#include<algorithm>
using namespace std;
long long tree[1000004],b[100004],c[10004];
pair<long long ,long long >a[100004];

int main(){
long n;
cin>>n;long r=0;long w=0;
for(long i=1;i<=n;i++){cin>>a[i].first;
a[i].second=i;}
sort(a+1,a+n+1);
long long ans=0;
for(long long  i=1;i<=n;i++){
    long long h=a[i].second ;
    long r=h%2+i%2;r=r%2;
    if(r==1)ans++;

}
cout<<ans/2<<endl;}



Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
const int md = 1e9 + 7;
inline void add(int &a, int b) {
  a += b;
  if (a >= md) a -= md;
}
inline void sub(int &a, int b) {
  a -= b;
  if (a < 0) a += md;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  vector<char> s(n + 1);
  s[0] = '$';
  s[1] = '$';
  for (int i = 2; i <= n; i++) {
    cin >> s[i];
  }
  vector<vector<int>> dp(n + 1, vector<int>(n, 0));
  dp[1][0] = 1;
  for (int i = 2; i <= n; i++) {
    for (int j = 0; j < i; j++) {
      if (j) {
        dp[i][j] = dp[i][j - 1];
      }
      if (s[i] == '<' && j){
        add(dp[i][j], dp[i - 1][j - 1]);
      } else if (s[i] == '>' && j < i - 1) {
        add(dp[i][j], dp[i - 1][i - 2]);
        if (j) {
          sub(dp[i][j], dp[i - 1][j - 1]);
        }
      }
    }
  }
  cout << dp[n][n - 1] << '\n';
  return 0;
}

Measured memory_bytes: 35584
using System;
using System.Linq;
using System.Collections.Generic;
using static System.Console;
using System.Text;
using System.IO;
using static System.Math;
namespace AtCoder
{
    class Program
    {
        static public long[] Sarray() { return ReadLine().Split().Select(long.Parse).ToArray(); }
        static public List<long> Slist() { return ReadLine().Split().Select(long.Parse).ToList(); }

        static readonly long Mod = 1000000000 + 7;

        static void Main(string[] args)
        {
            //SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });

            var S = ReadLine();
            var ans = 0L;
            var len = 0L;
            foreach (var s in S)
            {
                if (s == 'A' || s == 'C' || s == 'G' || s == 'T')
                    ++len;
                else
                    len = 0;
                ans = Max(len, ans);
            }
            Write(ans);

            //Out.Flush();
        }
    }
}

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

using ld=long double;
using P=complex<ld>;
using Poly=vector<P>;

const int SIZE=10;
const ld EPS=1e-12;
struct Segment{
    P a,b;
};

ld cross(P a,P b){return real(a)*imag(b)-real(b)*imag(a);}

bool is_adjacent(Segment l,Segment r){
    P aa=r.a-l.a;
    P ab=r.b-l.a;
    P ldir=l.b-l.a;
    if(abs(ldir)<EPS || abs(r.b-r.a)<EPS) return false;
    if(abs(cross(aa,ab))<EPS && abs(cross(ab,ldir))<EPS){
        P app=aa/ldir;
        if(abs(imag(app))>EPS) return false;
        ld ap=real(app);
        P bpp=ab/ldir;
        if(abs(imag(bpp))>EPS) return false;
        ld bp=real(bpp);
        return ! ((ap<EPS && bp<EPS) || (ap>1-EPS && bp>1-EPS));
    }
    else return false;
}
bool is_adjacent(Poly lhs,Poly rhs){
    bool isok=false;
    for(int i=0;i<lhs.size();i++){
        Segment l={lhs[i],lhs[(i+1)%lhs.size()]};
        for(int j=0;j<rhs.size();j++){
            Segment r={rhs[j],rhs[(j+1)%rhs.size()]};
            isok=isok || is_adjacent(l,r);
        }
    }
    return isok;
}

int solve(int n){
    vector<int> idx(n);
    vector<Poly> poly(n);
    map<string,int> dic;
    int m=0;
    auto getIdx=[&](string name){
        if(dic.count(name)) return dic[name];
        else return dic[name]=m++;
    };
    for(int i=0;i<n;i++){
        string name;
        cin>>name;
        ld x,y;
        while(cin>>x,abs(x+1)>EPS){
            cin>>y;
            poly[i].push_back(P(x,y));
            idx[i]=getIdx(name);
        }
    }
    vector<set<int>> gs(m);
    for(int i=0;i<n;i++){
        for(int j=0;j<n;j++){
            if(idx[i]==idx[j]) continue;
            if(is_adjacent(poly[i],poly[j])){
                gs[idx[i]].insert(idx[j]);
                gs[idx[j]].insert(idx[i]);
            }
        }
    }

    vector<bitset<SIZE>> bad(m);
    for(int i=0;i<m;i++){
        for(int j=0;j<SIZE;j++) bad[i][j]=false;
        for(auto &e:gs[i]) bad[i][e]=true;
    }
    
    function<int(int,int,vector<int>&)> dfs=[&](int v,int k,vector<int>& color){
        if(v==m) return k;
        int res=m;
        for(int i=0;i<=k;i++){
            bool isok=true;
            for(int j=0;j<v;j++){
                isok=isok && (!(color[j]==i && bad[v][j]));
            }
            if(isok){
                color[v]=i;
                int buf=(k==i);
                res=min(res,dfs(v+1,k+buf,color));
            }
        }
        return res;
    };
    vector<int> color(m);
    return dfs(0,0,color);
}
int main(){
    int n;
    while(cin>>n,n){
        cout<<solve(n)<<endl;
    }
    return 0;
}


Measured memory_bytes: 3276
from math import gcd
from functools import reduce
k=10**6+1
def judge(n,a):
  c=[0]*k
  for x in a:
    c[x]+=1 #対応する数の個数を記録
  t=any(sum(c[i::i])>1 for i in range(2,k)) #自身を約数に持つ数が2つ以上与えられたリストに存在するような数が一つでもあるかどうか
  t+=reduce(gcd,a)>1 #全体について1以外の公約数があれば1加える
  return ['pairwise','setwise','not'][t]+' coprime' #全体に公約数があればt=2,全体の公約数が1で公約数持つペアがあればt=1
n=int(input())
a=list(map(int,input().split()))
print(judge(n,a))


Measured memory_bytes: 133172
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.util.Collections;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author Twinkle Twinkle Little Star
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        BKThCommonDivisor solver = new BKThCommonDivisor();
        solver.solve(1, in, out);
        out.close();
    }

    static class BKThCommonDivisor {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int a = in.nextInt();
            int b = in.nextInt();
            int k = in.nextInt();
            ArrayList<Integer> array = new ArrayList<>();
            int gcd = 1;
            int index = 0;
            for (int i = 1; i <= a && i <= b; ++i) {
                if (a % i == 0 && b % i == 0) {
                    gcd = i;
                    array.add(gcd);
                    index++;
                    // out.println(gcd);
                }
            }
            Collections.sort(array);
            ArrayList<Integer> crray = new ArrayList<>();
            for (int i = array.size() - 1; i >= 0; i--) {
                int x = array.get(i);
                crray.add(x);
            }
            out.println(crray.get(k - 1));

        }

    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

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

    }
}



Measured memory_bytes: 21460
#include <iostream>
#include<vector>
#include<algorithm>
#include<string>
using namespace std;
#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)

int main(){
cin.tie(0);
ios::sync_with_stdio(false);
	
	string a,s,c;
	cin>>a>>s>>c;
	
	cout<<"A"<<s[0]<<"C"<<endl;
	return 0;
	
}

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

#include <fstream>
using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout << setprecision(20) << fixed;
  /*
  ifstream in("input.txt");
  cin.rdbuf(in.rdbuf());
  //*/
  int N, K;
  cin >> N >> K;
  vector<int> juice(N);
  for(int i = 0; i < N; i++) cin >> juice[i];
  sort(juice.begin(), juice.end());
  int ans = 0;
  for(int i = 0; i < K; i++){
    ans += juice[i];
  }
  cout << ans <<endl;
}

Measured memory_bytes: 3640
#include<bits/stdc++.h>
#include<iostream>
#include<cstdio>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
using namespace std;
#define rep(i,x) for(int i = 0; i < x; i++)
#define pb push_back
#define mp make_pair
#define eb emplace_back
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<ll,ll> Pll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<vector<vector<int>>> vvvi;
const ll MOD = 1e9+7;
const int n_max = 1e5+10;

void print() {
    cout << endl;
}

template <class Head, class... Tail>
void print(Head&& head, Tail&&... tail) {
    cout << head;
    if (sizeof...(tail) != 0) cout << ' ';
    print(forward<Tail>(tail)...);
}

template <class T>
void print(vector<T> &vec) {
    for (auto& a : vec) {
        cout << a;
        if (&a != &vec.back()) cout << ' ';
    }
    cout << endl;
}

template <class T>
void print(vector<vector<T>> &df) {
    for (auto& vec : df) {
        print(vec);
    }
}

template<typename T>
void print(T &arr){
    ll sz = sizeof(arr)/sizeof(arr[0]);
    for(int i = 0;i < sz-1;i++){cout << arr[i] << ' ';}
    cout << arr[sz-1] << endl;
}

ll n = 1e5+10,m = 2e5+10;
ll INF = INT_MAX;
vector<ll> place(n,INF);
bool ok = true;
vector<vector<Pll>> graph(n);
// template<class T>
void dfs(int now, int pre = -1){
    // bool ok = true;
    // is_move[now] = 1;
    for(auto i : graph[now]){
        int to = i.first;
        ll dis = i.second;
        if(to == pre)continue;
        if(place[to] == INF){
            place[to] = place[now] + dis;
            dfs(to, now);
        }
        else{
            if(place[to] != place[now] + dis){
                ok = false;
                break;
            }
        }
    }
    // return ok;
}

int main(){
    cin >> n >> m;
    // vector<ll> l(m), r(m), d(m);
    // vector<vector<Pll>> graph(n);
    set<ll> st;
    rep(i,m){
        ll l,r,d;cin >> l >> r >> d;
        l--;r--;
        st.insert(l);
        st.insert(r);
        graph[l].emplace_back(Pll(r,d));
        graph[r].emplace_back(Pll(l,-d));
    }
    bool res = true;

    // clock_t start = clock();

    for(auto i : st){
        // if(graph[i].size() == 0)continue;
        // print(i,is_move[i],place[i]);
        if(place[i] == INF){
            place[i] = 0;
            dfs(i);
        }
        if(!ok)break;
    }

    // clock_t end = clock();

    // const double time = static_cast<double>(end - start) / CLOCKS_PER_SEC * 1000.0;
    // printf("time %lf[ms]\n", time);
    cout << (ok ? "Yes" : "No") << endl;
}

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

int main(){
    string S;
    cin >> S;
    int s = S.size();
    int64_t ans = 0;

    for(int i=0;i<(1<<(s-1));i++){
        bitset<9> bit(i);

        int64_t sum = 0;
        int start = 0;

        for(int j=0;j<s-1;j++){
            if(bit.test(j)) {
                string t = S.substr(start ,j+1-start);
                int64_t a = stoll(t);
                sum += a;
                start = j+1;
            }
        }
        string t = S.substr(start ,s-start);
        int64_t a = stoll(t);
        sum += a;

        //cout << sum << endl;

        ans += sum;
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define cmin(a,b) (a>(b)?a=(b),1:0)
#define cmax(a,b) (a<(b)?a=(b),1:0)
#define dmin(a,b) ((a)<(b)?(a):(b))
#define dmax(a,b) ((a)>(b)?(a):(b))
namespace io
{
	int F()
	{
		 int F=1,n=0;
		 char ch;
		 while((ch=getchar())!='-'&&(ch<'0'||ch>'9'));
		 ch=='-'?F=0:n=ch-'0';
		 while((ch=getchar())>='0'&&ch<='9')n=n*10+ch-'0';
		 return F?n:-n;
	}
	long long G()
	{
		 long long F=1,n=0;
		 char ch;
		 while((ch=getchar())!='-'&&(ch<'0'||ch>'9'));
		 ch=='-'?F=0:n=ch-'0';
		 while((ch=getchar())>='0'&&ch<='9')n=n*10+ch-'0';
		 return F?n:-n;
	}
}
int R(int l,int r)
{
	return (rand()<<15|rand())%(r-l+1)+l;
}
const int ab(int x){return x>0?x:-x;} 
int a[222222],b[222222];
long long sum[222222];
int f[222222],g[222222],h[222222];
long long ans;
int n;
long long wk()
{
	for(register int i=1;i<=n;++i)sum[i]=sum[i-1]+a[i]+b[i];
	for(register int i=1;i<=n;++i)
		f[i]=f[i-1]+2-a[i],
		cmin(f[i],sum[i]);
	for(register int i=n;i;--i)
		g[i]=g[i+1]+2-a[i],
		cmin(g[i],sum[n]-sum[i-1]);
	for(register int i=1;i<=n;++i)
		h[i]=h[i-1]+ab(a[i]-1),
		cmin(h[i],f[i]);
	long long min=0x3f3f3f3f;
	for(register int i=0;i<=n;++i)
		cmin(min,h[i]+g[i+1]);
	return min;
} 
int main()
{
	n=io::F();
	for(register int i=1;i<=n;++i)
	{
		int x=io::F();
		if(x<=2)a[i]=x;
			else if(x&1)a[i]=1,b[i]=x-1;
			else a[i]=2,b[i]=x-2;
	}
	ans=wk();
	std::reverse(a+1,a+n+1);
	std::reverse(b+1,b+n+1); 
	long long tmp=wk();
	cmin(ans,tmp);
	printf("%lld\n",ans);
	return 0;
}


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

int main() {
    string a, b, c;
    cin >> a >> b >> c;
    if (*a.rbegin() == b.at(0) && *b.rbegin() == c.at(0)) cout << "YES" << endl;
    else cout << "NO" << endl;
}   

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	class Pair {
		double y, x;
		Pair(double x, double y) {
			this.y = y;
			this.x = x;
		}
		void print() {
			System.out.println(this.y + " " + this.x);
		}
	}
	int n;

	void run() {
		Scanner scan = new Scanner(System.in);
		n = scan.nextInt();
		Pair p1 = new Pair(0, 0);
		Pair p2 = new Pair(0, 100);
		p1.print();
		kochCurve(0, new Pair(0, 0), new Pair(0, 100));
		p2.print();
	}
	
	void kochCurve(int deep, Pair p1, Pair p2) {
		if (deep == n) {
			return;
		}
		
		Pair s = new Pair((2 * p1.x + p2.x) / 3, (2 * p1.y + p2.y) / 3);
		Pair t = new Pair((p1.x + 2 * p2.x) / 3, (p1.y + 2 * p2.y) / 3);
		
		double _x = p2.x - p1.x;
		double _y = -(p2.y - p1.y);
		double dist = Math.sqrt(_x * _x + _y * _y)/ Math.sqrt(3);

		Pair u;
		if (_x >= 0) {
			double angle = Math.atan(_y / _x) + Math.PI / 6;
			u = new Pair(p1.x + (dist * Math.cos(angle)), p1.y - (dist * Math.sin(angle)));
		} else {
			double angle = Math.atan(_y / _x) - Math.PI / 6;
			u = new Pair(p2.x + (dist * Math.cos(angle)), p2.y - (dist * Math.sin(angle)));
		}

		kochCurve(deep + 1, p1, s);
		s.print();
		kochCurve(deep + 1, s, u);
		u.print();
		kochCurve(deep + 1, u, t);
		t.print();
		kochCurve(deep + 1, t, p2);
	}
	public static void main(String[] args) {
		new Main().run();
	}
}



Measured memory_bytes: 32416
package main

import "fmt"

func main() {
	var s, a string
	fmt.Scan(&s)
	for i := 0; i < len(s); i++ {
		if s[i:i+1] == "0" {
			a += "0"
			// fmt.Println(a)
		} else if s[i:i+1] == "1" {
			a += "1"
			// fmt.Println(a)
		} else {
			sc := []rune(a)
			a = ""
			if len(sc) > 0{
				a += string(sc[:(len(sc) - 1)])
			}
			// fmt.Println(a)
		}
	}
	fmt.Println(a)
}

Measured memory_bytes: 1764
#include <iostream>
#include <cmath>
#include <algorithm>

using namespace std;

int main(){
    int n,k;
    cin>>n>>k;
    int c=0;
    for (int i=1; i<=n; i++) {
        int h;
        cin>>h;
        if (h>=k) c++;
    }
    cout<<c<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <string>
#include <vector>
#include <algorithm>
#define rep(i,e)for(int i=0;i<e;i++)
#define PI acos(-1)
using namespace std;

int main(){
    int i, j;
    int n;
    string A, B;
    int pointA=0, pointB=0;
    cin >> n;
    rep(i,n){
        cin >> A >> B;
        if(A.compare(B) > 0) pointA+=3;
        else if(A.compare(B) < 0) pointB+=3;
        else{
            pointA++;
            pointB++;
        }
    }
    cout << pointA << " " << pointB << endl;
    return 0;
}


Measured memory_bytes: 3156
from itertools import product

a, b = map(int, input().split())

k = 50
s = [['.' for i in range(k)] + ['#' for i in range(k)] for j in range(2 * k)]

na = 1
for i, j in product(range(1, 2 * k - 1, 2), range(k + 1, 2 * k - 1, 2)):
    if na >= a:
        break
    s[i][j] = '.'
    na += 1

nb = 1
for i, j in product(range(1, 2 * k - 1, 2), range(1, k - 1, 2)):
    if nb >= b:
        break
    s[i][j] = '#'
    nb += 1

print(k * 2, k * 2)
for row in s:
    print(''.join(row))

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

using namespace std;

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

int dp[10][2020];

signed main()
{
    int N, K; cin >> N >> K;

    vector<int> books[10];
    rep(i, N) {
        int C, G; cin >> C >> G;
        --G;
        books[G].push_back(C);
    }

    rep(i, 10) {
        sort(all(books[i]), greater<int>());

        vector<int> tmp;
        tmp.push_back(0);
        rep(j, books[i].size()) tmp.push_back(books[i][j]);
        books[i] = tmp;

        int a = 0;
        rep(j, books[i].size()) {
            books[i][j + 1] += books[i][j] + 2 * a;
            a++;
        }
    }

    memset(dp, -1, sizeof(dp));
    for (int i = 0; i < books[0].size(); ++i) {
        dp[0][i] = books[0][i];
    }

    for (int i = 1; i < 10; ++i) {
        for (int j = K; j >= 0; --j) {
            for (int k = 0; k < books[i].size(); ++k) {
                if (j - k >= 0 && dp[i - 1][j - k] != -1) {
                    dp[i][j] = max(dp[i][j], dp[i - 1][j - k] + books[i][k]);
                }
            }
        }
    }

    cout << dp[9][K] << endl;
}

Measured memory_bytes: 3172
#include <bits/stdc++.h>
#define INF INT_MAX
#define ll  long long
#define ull unsigned long long
#define rep(i,n) for(ll i=0; i<n; ++i)
#define FOR(i, s, e) for(ll i=s; i<e; ++i)
#define MOD 1000000007
using namespace std;
template<class T> inline bool chmin(T& a, T b) { if(a>b) {a=b; return true;} return false;}
template<class T> inline bool chmax(T& a, T b) { if(a<b) {a=b; return true;} return false;}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll X; cin >> X;
  ll cmp = 0;
  for(ll i=1; ;++i) {
    cmp += i;
    if(cmp<X) continue;
    else cout << i << endl;
    break;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it)
#define ALLOF(c) (c).begin(), (c).end()
typedef long long ll;
typedef unsigned long long ull;

static const long long mod = 1000000007;
struct mint {
  long long x;
  mint(ll x = 0):x(x%mod) {}
  //mint(ll x = 0):x((x%mod+mod)%mod) {} // for minus
  mint& operator+=(const mint a) {
    (x += a.x) %= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    (x += mod-a.x) %= mod;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const {
    mint ret(*this);
    return ret += a;
  }
  mint operator-(const mint a) const {
    mint ret(*this);
    return ret -= a;
  }
  mint operator*(const mint a) const {
    mint ret(*this);
    return ret *= a;
  }
  mint pow(ll t) const {
    if(t==0) return mint(1);
    mint a = pow(t>>1);
    a *= a;
    if(t&1) a *= *this;
    return a;
  }
  
  //for prime mod
  mint inv() const {
    return pow(mod-2);
  }
  mint& operator/=(const mint a) {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const {
    mint ret(*this);
    return ret /= a;
  }
};
ostream &operator<<(ostream& os, const mint& x) {
  os << x.x;
  return os;
}
bool operator==(const mint& a, const mint& b){
  return a.x == b.x;
}
class modutils {
  vector<mint> fact, invfact;
public:
  modutils(int n = 2000005):fact(n+1),invfact(n+1) {
    fact[0] = 1;
    for(int i=1; i<=n; i++) fact[i] = fact[i-1] * i;
    invfact[n] = fact[n].inv();
    for(int i=n; i>=1; i--) invfact[i-1] = invfact[i] * i;
  }
  mint pow(mint x, ll n) {
    return x.pow(n);
  }
  mint comb(ll n, ll k) {
    if(n<0 || k<0 || n<k) return 0;
    return fact[n] * invfact[k] * invfact[n-k];
  }
  mint perm(ll n, ll k) {
    if(n<0 || k<0 || n<k) return 0;
    return fact[n] * invfact[n-k];
  }
  mint fac(ll n) {
    return fact[n];
  }
};
modutils mutil;

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

  if(S == 1 || S == 2){
    cout << 0 << endl;
    return 0;
  }

  vector<mint> v(S+1);
  v[0] = 1;

  rep(i,S+1){
    REP(j,3,S+1){
      if(i+j < S+1){
        v[i+j] += v[i];
      }
    }
  }

  cout << v[S] << endl;
  
  return 0;
}


Measured memory_bytes: 34204
#include<stdio.h>
int main(void)
{
    int c1,c5,c10,c50,c100,c500,s;
	scanf("%d %d %d %d %d %d",&c1,&c5,&c10,&c50,&c100,&c500);
	s=1*c1+5*c5+10*c10+50*c50+100*c100+500*c500;
	if (s>=1000){
	    printf("1\n");
	}
	else if (s<=1000){
	    printf("0\n");
	}
	return 0;
}

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

const long double pi = acos(-1);

int main() {
  long double a, b, x;
  long double angle;
  cin >> a >> b >> x;
  long double area = x / a;
  if (x <= a*a*b/2) {
    angle = atan(b*b/(2*area));
  }
  else
    angle = atan(2*b/a-2*area/(a*a));
  cout << setprecision(10) << angle *180 /pi << endl;
}


Measured memory_bytes: 384
#include <iostream>
using namespace std;
int main()
{
	int A, B, C;
	cin >> A >> B >> C;

	if ((A == 5 && B == 5 && C == 7) || (A == 5 && B == 7 && C == 5) || (A == 7 && B == 5 && C == 5))
	{
		cout << "YES";
	}
	else {
		cout << "NO";
	}
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#define NUM 1000000

int main(){		/*		GgXelXÌâ¿		*/
	int n,
		prime[NUM+1],
		i,j,
		count=0;
	
	for(i=2;i<=NUM;i++){ 		/*    0,   1,2,......,99999,100000 zñÔª®Ô*/	
		prime[i]=1;				/*{null,null,1,......,    1,     1}						Óé¢Éüêé*/
	}
	prime[0]=0;	prime[1]=0;
	
	for(i=2;i<=NUM;i++)		/*Óé¢É©¯é*/
		if(prime[i]==1)					/*for¶ÌÅÍA±Ì2sÍPsÆµÄF¯³êé(ifÆÜÆßçêÄ¢é)B*/
			for(j=2*i;j<=NUM;j+=i)		/*i=2ÌÆ«Aj=4,j=6,ÆÈÁÄ¢­B*/
				prime[j]=0;				/*Óé¢©ç¿é*/
	
	while(count=0,scanf("%d",&n)!=EOF){
		
		for(i=0;i<=n;i++)
			if(prime[i]==1)
				count++;
		
		printf("%d\n",count);
	}
	
	return 0;
}

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

int main() {
 int a;
  cin>>a;
  if(a<10) cout<<a<<endl;
  else if(a<100) cout<<9<<endl;
  else if(a<1000) cout<<a-90<<endl;
  else if(a<10000) cout<<909<<endl;
  else if(a<100000)cout<<a-9090<<endl;
  else cout<<90909<<endl;
}

Measured memory_bytes: 256
import itertools
N = int(input())

lis = [0] * (10000 + 1)
for x, y, z in itertools.combinations_with_replacement(range(1, 99), 3):
  calc = x ** 2 + y ** 2 + z ** 2 + x * y + y * z + x * z
  if calc > 10000:
    continue
    
  if x == y and y == z:
    lis[calc] += 1
  elif x == y or y == z or x == z:
    lis[calc] += 3
  else:
    lis[calc] += 6
    
for x in lis[1:N+1]:
  print(x)


Measured memory_bytes: 9340
N = int(input())

ans = 2 * 10**5

for n in range(1,N//2 + 1):
  a = n
  b = N - n
  
  sum_a = sum(list(map(int,list(str(a)))))
  sum_b = sum(list(map(int,list(str(b)))))
  
  ans = min(ans,sum_a+sum_b)
print(ans)

Measured memory_bytes: 9132
import java.util.Scanner;
import java.util.HashMap;

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

		if(start.equals(goal)) {
			System.out.println("Yes");
			return;
		}

		HashMap<String, String> sgMap = new HashMap<>();
		HashMap<String, String> gsMap = new HashMap<>();
		for(int i = 0; i < start.length; i++) {
			String pre = null;
			if((pre = sgMap.put(start[i], goal[i])) != null && !pre.equals(goal[i])) {
				System.out.println("No");
				return;
			}
			if((pre = gsMap.put(goal[i], start[i])) != null && !pre.equals(start[i])) {
				System.out.println("No");
				return;
			}
		}

		System.out.println("Yes");
	}
}


Measured memory_bytes: 67888
from sys import stdin
#from collections import deque
#from math import sqrt, floor, ceil, log, log2, log10, pi, gcd, sin, cos, asin, tan


def ii(): return int(stdin.readline())


def fi(): return float(stdin.readline())


def mi(): return map(int, stdin.readline().split())


def fmi(): return map(float, stdin.readline().split())


def li(): return list(mi())


def lsi():
    x=list(stdin.readline())
    x.pop()
    return x


def si(): return stdin.readline()


def sieve(x):
    a=[True]*(x+1)
    sq=floor(sqrt(x))
    for i in range(3, sq+1, 2):
        if a[i]:
            for j in range(i*i, x+1, i):
                a[j]=False
    if x>1:
        p=[2]
    else:
        p=[]
    for i in range(3, x+1, 2):
        if a[i]:
            p.append(i)
    return p
def prime_factor(x):
    c=1
    i=0
    while p[i]*p[i]<=x:
        if not x%p[i]:
            c+=1
            while not x%p[i]:
                x//=p[i]
        i+=1
    if x>1:
        c+=1
    return c
res=['Yes', 'No']
#vowel={'a', 'e', 'i', 'o', 'u', 'y', 'A', 'E', 'I', 'O', 'U', 'Y'}
#pow=[1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768, 65536, 131072, 262144, 524288, 1048576, 2097152, 4194304, 8388608, 16777216, 33554432, 67108864, 134217728, 268435456, 536870912, 1073741824, 2147483648, 4294967296, 8589934592, 17179869184, 34359738368, 68719476736, 137438953472, 274877906944, 549755813888, 1099511627776, 2199023255552, 4398046511104, 8796093022208, 17592186044416, 35184372088832, 70368744177664, 140737488355328, 281474976710656, 562949953421312, 1125899906842624, 2251799813685248, 4503599627370496, 9007199254740992, 18014398509481984, 36028797018963968, 72057594037927936, 144115188075855872, 288230376151711744, 576460752303423488, 1152921504606846976, 2305843009213693952, 4611686018427387904, 9223372036854775808]
############# CODE STARTS HERE #############
a=[0]*12
b=li()
f=1
for i in b:
    a[i]=1
if sum(a)==2:
    f=0
print(res[f])

Measured memory_bytes: 3064
import sys
sys.setrecursionlimit(10**7)
import itertools
from decimal import *

#debug = True
debug = False

def dprint(*objects):
    if debug == True:
        print(*objects)

def solve():
    a, b, c, d = map(int, input().split())

    import math
    ac = math.ceil(Decimal(a) / Decimal(c))
    bc = math.floor(Decimal(b) / Decimal(c))
    nc = bc - ac + 1

    ad = math.ceil(Decimal(a) / Decimal(d))
    bd = math.floor(Decimal(b) / Decimal(d))
    nd = bd - ad + 1

    def lcm(x, y):
        import fractions
        return (x * y) // fractions.gcd(x, y)

    cd = lcm(c, d)
    acd = math.ceil(Decimal(a) / Decimal(cd))
    bcd = math.floor(Decimal(b) / Decimal(cd))
    ncd = bcd - acd + 1

    total = b - a + 1
    dprint(total, ac, bc, nc)
    dprint(total, ac, bc, nd, nc, ncd)
    print(total - nd - nc + ncd)

solve()

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

#define SORT(c) sort((c).begin(),(c).end())
#define REVERSE(v) reverse((v).begin(),(v).end())
#define ANS(ans) cout<<(ans)<<endl;
#define UNIQUE(v) (v).erase(unique((v).begin(), (v).end()), (v).end());
typedef vector<int> VI;
typedef pair<int, int> P;
 
//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<=(b);++i)
#define REP(i,n)  for (int i = 0; i < (n); ++i)

int main() {

    int n;
    string s;
    cin>>n>>s;
    
    if(n%2!=0){
        ANS("No");
    }
    else{
        REP(i,n/2){
            if(s[i] != s[i+n/2]){
                ANS("No");
                return 0;
            }
        }
        ANS("Yes");
    }
    return 0;
}


Measured memory_bytes: 256
#include<iostream> 
#include<vector> 
#include<algorithm> 
#include<iomanip> 
#include<stack> 
#include<unordered_map>
#include<queue> 
#include<deque>
#include<map> 
#include<climits>
#include<set> 
#include<string> 
//#include<time.h>
//#include<bits/stdc++.h> 
using namespace std; 
#define lld long long int 
#define eb emplace_back
//to insert pair use eb
#define mp make_pair
#define fi first
#define se second
#define pb push_back

#define X 1000000007
#define Y 998244353
#define E4 10000
#define E5 100000
#define E6 1000000
#define inf 2001001001001001001
#define pi 3.1415926535

# define rec2(i,a,n) for(lld i=a;i<n;i++) 
#define rec(i,n) for(lld i=0;i<n;i++)
#define rev(i,a,n) for(lld i=n-1;i>=a;i--)
#define all(v) (v).begin(), (v).end()
#define large(v)  *max_element(all(v))
#define small(v)  *min_element(all(v)) 
#define v vector 
#define p(x,y)  pair<x,y> 
const double EPS = 1e-6;

void google(int i)
{  cout<<"Case #"<<i<<": "; }

//prime sieve if needed 
//prime factors of number
lld prime[E6+1]; 
void sieve(lld n) 
{ rec(i,n+1) 
    prime[i]=1; 
   for(lld i=2;i*i<=n;i++) 
     { if(prime[i]!=1) 
          continue; 
         for(lld j=i*i;j<=n;j=j+i) 
          if(prime[i]==1)
           prime[j]=i; 
      }
}

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

//fermat a^(m-2)%mod
lld binarymul(lld a,lld n,lld m)
{  lld res=1; 
 while(n) 
  { if(n%2) 
      { res=(res*a)%m; 
         n--; 
      } 
     a=(a*a)%m; 
     n/=2; 
  }
  return res; 
}
/*
void complexity(time_t end,time_t start)
{ 
  double taken = double(end - start); 
    cout<<"Time : "; 
    cout<<fixed<<taken<<setprecision(8);         cout<<" sec "<<endl;
}
*/ 
void bfs(lld s,v<lld> g[],lld n)
{ 
   bool vis[n]; 
   rec(i,n) 
    vis[i]=false; 
    
   vis[s]=true; 
   deque<lld> q; 
   q.pb(s); 
   
   while(!q.empty()) 
   {  
      s=q.front(); 
     q.pop_front(); 
      
     for(int i=0;i<g[s].size();i++) 
      {  
        if(!vis[g[s][i]])
         { vis[g[s][i]]=true; 
            q.pb(g[s][i]); 
         }
      }
   }
}

void dfs(lld u,v<lld> g[],bool *vis)
{ 

   vis[u]=true; 
   for(int i=0;i<g[u].size();i++) 
     if(!vis[g[u][i]])
          dfs(i,g,vis); 
       
}
void contest(lld t); 
int main()
{   
    /*
    time_t start, end; 
    time(&start); 
    */
   ios_base::sync_with_stdio(false); 
   cin.tie(0);
     #ifdef PUNEET_GOEL
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    #endif
   //sieve(E6); 
    lld T=1; 
   // cin>>T;
    rec(t,T) 
    {
      contest(t); 
    }
    /*
     time(&end); 
    complexity(end,start);
    */
	return 0;
}

void contest(lld t)
{ 
  lld d,s,a; 
  cin>>d>>s>>a; 
   lld x=s*a; 
   if(x>=d) 
    cout<<"Yes"; 
    else 
    cout<<"No"; 
    cout<<endl; 
}

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

typedef pair<int, int> P;

int main(){
    int a, n, q, v, m_a = 0;
    cin >> n >> q;
    vector<int> fish(n+1, 0);
    priority_queue< P > pq;
    pq.push( P(1, 0) );
    for(int i = 0; i < q; i++){
        cin >> a >> v;
        fish[a] += v;
        pq.push( P(fish[a], -a) );
        while( fish[-pq.top().second] != pq.top().first ) pq.pop();
        cout << -pq.top().second << ' ' << pq.top().first << endl;
    }
    return 0;
}

Measured memory_bytes: 6012
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#define LL long long
using namespace std;
inline LL read(){
	int ret=0,p=1;
	char ch=getchar();
	while (ch<'0' || ch>'9'){if (ch=='-') p=-1;ch=getchar();}
	while (ch>='0' && ch<='9') ret=ret*10+ch-'0',ch=getchar();
	return ret*p;
}
int n;
int a[200000+3];
int nxt[200000+3];
int main(){
	n=read();
	for (int i=1;i<=n;i++){
		a[i]=read();
	}
	if (a[n]==0) nxt[n]=n;
	for (int i=n-1;i;i--){
		if (a[i]==0){
			if (a[i+1]!=0) nxt[i]=i;
			else nxt[i]=nxt[i+1];
		}
	}
	LL ans=0;
	for (int i=1;i<=n;i++){
		LL sum1=0,sum2=0;
		for (int j=i;j<=n;j++){
			if (a[j]==0) ans+=nxt[j]-j+1,j=nxt[j];
			else{
				sum1+=a[j];sum2^=a[j];
				if (sum1==sum2) ans++;
				else break;
			}
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1792
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> p;
const int INF = (1 << 28);
const int dx[4] = {0,1,0,-1}, dy[4] = {-1,0,1,0};
const int Dx[8] = {0,1,1,1,0,-1,-1,-1}, Dy[8] = {-1,-1,0,1,1,1,0,-1};
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
int r, d, x;
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >>r>>d>>x;
    ll ans=x;
    for(int i=0;i<10;i++){
        x=x*r-d;
        cout<<x<<"\n";
    }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define F first
#define S second
#define pii pair<int, int>
#define eb emplace_back
#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep3(i, l, n) for (int i = l; i < (n); ++i)
#define sz(v) (int)v.size()
#define inf (int)(1e9+7)
#define abs(x) (x >= 0 ? x : -(x))
#define ceil(a, b) a / b + !!(a % b)
template<typename T1, typename T2> inline void chmin(T1 &a, T2 b) { if (a > b) a = b; }
template<typename T1, typename T2> inline void chmax(T1 &a, T2 b) { if (a < b) a = b; }
ll pow(ll a, int b) { return b ? pow(a * a, b / 2) * (b % 2 ? a : 1) : 1; }
template<typename T> T gcd(T a, T b) { if (b == 0) return a; return gcd(b, a % b); }



int n, Q;
ll l, r;
vector<pair<pair<int, ll>, pii> > v;
vector<int> a;

ll calc(ll A) {
    for (auto &p: v) {
        int q, s, t;
        ll x;
        tie(q, x) = p.first;
        tie(s, t) = p.second;
        if (q == 1) {
            if (A < x) continue;
            A = 1LL * t * (A + s);
        } else {
            if (A > x) continue;
            A = (A - s) / t;
        }
    }
    return A;
}

void small() {
    ll A = a[0];
    
    A = calc(A);
    
    if (l <= A && A <= r) cout << 1 << '\n';
    else cout << 0 << '\n';
}

int main() {
    cin >> n >> Q >> l >> r;
    
    a.resize(n);
    rep(i, n) cin >> a[i];
    sort(all(a));
    
    
    rep(i, Q) {
        int q, s, t; ll x;
        cin >> q >> x >> s >> t;
        v.eb(make_pair(make_pair(q, x), pii(s, t)));
    }
    
    if (n == 1) {
        small();
        return 0;
    }
    
    // l
    int L = -1, R = n - 1;
    while (true) {
        int mid = (L + R) / 2;
        ll A = a[mid];
        A = calc(A);
        
        if (A < l) {
            L = mid;
        } else {
            R = mid;
        }
        if (L + 1 == R) break;
    }
    int tmpR = R;
    
    // r
    L = 0; R = n;
    while (true) {
        int mid = (L + R) / 2;
        ll A = a[mid];
        A = calc(A);
        
        if (A > r) {
            R = mid;
        } else {
            L = mid;
        }
        if (L + 1 == R) break;
    }
    // cout << L << " " << tmpR << '\n';
    
    if (L == tmpR) {
        ll A = a[L];
        A = calc(A);
        
        if (l <= A && A <= r) cout << 1 << endl;
        else cout << 0 << endl;
        return 0;
    }
    
    cout << L - tmpR + 1 << endl;
}



Measured memory_bytes: 9876
import java.util.*;
 
class Main {
    public static void main(String[] args) {
      
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int asb = 0;
        int min = 1000;
        int sum2 = 0;
        int sum = 0;
        int nam[] = new int[N];

      for(int i = 0; i < N ;i++){
        nam[i] = sc.nextInt();
        sum += nam[i];
      }
      
       for(int i = 0; i < N-1;i++){
         sum -= nam[i];
         sum2 += nam[i];
         asb = Math.abs(sum-sum2);
         if(asb<min){min = asb;}
       }
      
      System.out.print(min);

    }
}

Measured memory_bytes: 22612
n = int(input())
a = list(map(int, input().split()))


decimal = sum(a) / len(a) - sum(a) // len(a)
if decimal >= 0.5:
    m = sum(a) // len(a) + 1
else:
    m = sum(a) // len(a)

ans = 0
for i in range(n):
    ans += (a[i] - m)**2

print(ans)


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

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

    int col[200] = {0};
    int dist[200] = {0};
    col[0] = 1;
    dist[0] = 1;

    int t = 0;
    queue<int> q;
    q.push(0);
    while(!q.empty()){
        t = q.front();
        q.pop();
        for(int i=0;i<n;++i){
            if(s[t][i] != '1') continue;
            if(col[t] == col[i]){
                cout << -1 << endl;
                return 0;
            }else if(col[i] == 0){
                col[i] = -col[t];
                dist[i] = dist[t] + 1;
                q.push(i);
            }
        }
    }

    int ans = 0;
    for(int st=0;st<n;++st){
        for(int i=0;i<n;++i) dist[i] = 0;
        q.push(st);
        dist[st] = 1;
        while(!q.empty()){
            t = q.front();
            q.pop();
            for(int i=0;i<n;++i){
                if(s[t][i] != '1') continue;
                if(dist[i] == 0){
                    dist[i] = dist[t] + 1;
                    q.push(i);
                }
            }
        }
        ans = max(ans, dist[t]);
    }
    cout << ans << endl;
    
    return 0;
}

Measured memory_bytes: 256
import sys


def _i(): return int(sys.stdin.readline().strip())


def _ia(): return map(int, sys.stdin.readline().strip().split())


def main():
    n = _i()
    cur, *a = _ia()
    ans = 0
    for ai in a:
        if ai < cur:
            ans += (cur - ai)
        else:
            cur = ai
    return ans


if __name__ == "__main__":
    print(main())


Measured memory_bytes: 104588
#include <stdio.h>
#define MAX 500000
#define N 1000000000

int L[MAX/2+2],R[MAX/2+2];
int c;

long long merge(int A[],int n,int l,int m,int r);
long long mergeSort(int A[],int n,int l,int r);

int main()
{
	int A[MAX],n,i;
	
	scanf("%d",&n);
	
	for(i=0;i<n;i++)
	{
		scanf("%d",&A[i]);
	}
	
	long long a=mergeSort(A,n,0,n);
	printf("%ld\n",a);
	return 0;
}

long long merge(int A[],int n,int l,int m,int r)
{
	int i,j,k;
	int n1=m-l;
	int n2=r-m;
	long long c=0;
	
	for(i=0;i<n1;i++)
	{
		L[i] = A[l+i];
	}
	
	for(i=0;i<n2;i++)
	{
		R[i] = A[m+i];
	}
	
	L[n1]=R[n2]=N;
	
	for(i=0,j=0,k=l;k<r;k++)
	{
		if(L[i]<=R[j])
		{
			A[k]=L[i++];
		}
		else
		{
			A[k]=R[j++];
			c=c+n1-i;
		}
	}
	return c;
}

long long mergeSort(int A[],int n,int l,int r)
{
	int m;
	long long a1,a2,a3;
	
	if(l+1<r)
	{
		m=(l+r)/2;
		a1=mergeSort(A,n,l,m);
		a2=mergeSort(A,n,m,r);
		a3=merge(A,n,l,m,r);
		return a1+a2+a3;
	}
	else return 0;
}


Measured memory_bytes: 3360
#[allow(unused_imports)]
use proconio::{input, marker::*};

#[allow(unused_imports)]
use std::collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, VecDeque};

#[allow(unused_imports)]
use std::io::Write;

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        #[cfg(debug_assertions)]
        writeln!(&mut std::io::stderr(), concat!("[DEBUG] ", $(stringify!($a), "={:?} "),*), $($a),*).unwrap();
    }
}

fn main() {
    input! {
        n: usize,
        a: [usize; n],
    }

    let mut current = 1000;
    let mut min = std::usize::MAX;
    for e in a {
        if min < e {
            current = (current / min * e) + current % min;
            min = e;
        } else {
            min = e;
        }
    }
    println!("{}", current);
}


Measured memory_bytes: 2148