akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#include <iomanip>
using namespace std;
#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define fi first
#define se second
#define mp make_pair
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;

ll N,M,H,W,K,A,B;
string s;
string alpha = "abcdefghijklmnopqrstuvwxyz";
string ALPHA = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";

int main(){
    cin>>s;
    N = s.size();
    vec S(N,0);
    rep(i,N){
        A = s[i] - '0';
        S[i] = A;
    }
    rep(i,N-1){
        if((S[i]^S[N-2-i]) == 1){
            cout<<-1<<endl;
            return 0;
        }
    }
    if((S[N-1] == 1) || (S[0] == 0)){
        cout<<-1<<endl;
        return 0;
    }
    ll last;
    rep(i,N-1){
        if(i == 0){
            cout<<"1 2"<<endl;
            last = 2;
        }else if(i < N/2){
            cout<<last<<' '<<i+2<<endl;
            if(S.at(i) == 1) last = i+2;
        }else{
            cout<<last<<' '<<i+2<<endl;
        }
    }
}

Measured memory_bytes: 2432
s = input()
li = ["maerd", "remaerd", "esare", "resare"]
p = list(reversed((s)))
j = ""
for i in p:
  j += i
  for h in li:
    if j == h:
      j = ""
      break
if j == "":
  print("YES")
else:
  print("NO")

Measured memory_bytes: 3956
#include <bits/stdc++.h>
#define ll long long
using namespace std;
ll a,b,k;
int main()
{
    cin>>a>>b>>k;
    if(a-k<=0)
    {
        if(b-(k-a)<=0)
            cout<<0<<" "<<0<<endl;
        else
            cout<<0<<" "<<b-(k-a)<<endl;
    }
    else
        cout<<a-k<<" "<<b<<endl;
    return 0;
}


Measured memory_bytes: 384
import java.util.Scanner;
public class Main {
    public static void main(String args[]) {
        Scanner s=new Scanner(System.in);
        int n=s.nextInt();
        int x=s.nextInt();
        int t=s.nextInt();
        int ans=(int)Math.ceil((double)n/x);
        ans*=t;
        System.out.print(ans);

    }
}

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

using Pii = pair<int, int>;
using Pll = pair<ll, ll>;

#define REP(i, l, n) for(int i=(l), i##_len=(n); i<i##_len; ++i)
#define ALL(x) (x).begin(),(x).end()
#define pb push_back

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

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

char alpha[26] = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'};

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

const ll mod = 1e9 + 7;

int main(){
    int n; cin >> n;
    vector<ll> lis(n);
    REP(i, 0, n){cin >> lis[i];}
    ll sum = 0, ans = 0;
    REP(i, 1, n){
        sum += lis[i];
        sum %= mod;
    }
    REP(i, 0, n-1){
        ans += (lis[i] * sum)%mod;
        ans %= mod;
        sum = (sum - lis[i+1] + mod) % mod;
    }
    cout << ans << endl;
}

Measured memory_bytes: 4840
N, M = map(int, input().split())

E = [list(map(int, input().split())) for i in range(M)]

visited = [0] * N
visited[0] = 1

ans = 0

def DFS(v,cnt):
  #print("call",v,cnt,visited)
  if sum(visited) == N:
    cnt += 1
    return cnt
  for i in range(M):
    if E[i][0] == v + 1:
      v_next = E[i][1] - 1
    elif E[i][1] == v + 1:
      v_next = E[i][0] - 1
    else:
      continue
    
    if visited[v_next] == 1:
      continue
    
    #print("deppen",v, v_next,visited)
    visited[v_next] = 1
    cnt = DFS(v_next,cnt)
    visited[v_next] = 0
    
  return cnt

ans = DFS(0,0)

print(ans)

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

int main(){
    for (int i=0;; i++){
        int H, W;
        cin >> H >> W;
        if (H==0 && W==0) break;

        for (int j=0; j<H; j++){
            for (int k=0; k<W; k++){
                if (k==0||k==W-1||j==0||j==H-1){cout<<"#";}
                else{cout<<".";}
                }
                cout<<endl;
            }
        cout<<endl;
        }
    return 0;
}


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

#define rep(i,n) for(int i=0; i<(n); i++)
#define reps(i,x,n) for(int i=x; i<(n); i++)
#define rrep(i,n) for(int i=(n)-1; i>=0; i--)
#define all(X) (X).begin(),(X).end()
#define X first
#define Y second
#define pb push_back
#define eb emplace_back

using namespace std;
typedef long long int ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

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 (a>b) { a=b; return 1; } return 0; }

template<class A, size_t N, class T> void Fill(A (&a)[N], const T &v){ fill( (T*)a, (T*)(a+N), v ); }

template<class T> ostream& operator<<(ostream &os, const vector<T> &t) {os<<"{"; rep(i,t.size()) {os<<t[i]<<",";} os<<"}"; return os;}
template<class T,size_t n> ostream& operator<<(ostream &os, const array<T,n> &t) {os<<"{"; rep(i,n) {os<<t[i]<<",";} os<<"}"; return os;}
template<class S, class T> ostream& operator<<(ostream &os, const pair<S,T> &t) { return os<<"("<<t.first<<","<<t.second<<")";}

const ll INF = 1e9+7;


int main(){
	ios_base::sync_with_stdio(false);
	ll N, ans=0;
	map<ll,ll> cnt;
	ll sum = 0;
	cnt[0]++;

	cin >> N;
	rep(i,N){
		ll A;
		cin >> A;
		sum += A;
		ans += cnt[sum];
		cnt[sum]++;
	}

	cout << ans << endl;

	return 0;
}


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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

#define Abs(x)((x) < 0 ? (x) * -1 : (x))
#define rep(x, y) for ((x) = 0; (x) < (y); (x)++)
#define repin(x, y) for ((x) = 0; (x) <= (y); (x)++)
#define nep(x, y) for ((x) = (y) - 1; 0 <= (x); (x)--)
#define nepi(x, y, z) for ((x) = (y) - 1; (z) <= (x); (x)--)
#define repi(x, y, z) for ((x) = (z); (x) < (y); (x)++)
#define repiin(x, y, z) for ((x) = (z); (x) <= (y); (x)++)
#define reps(x, y, z) for ((x) = 0; (x) < (y); (x) += (z))
#define repit(x) for (__typeof((x).begin()) it = (x).begin(); it != (x).end(); it++)
#define all(x) (x).begin(),(x).end()
#define Mem(x, y) memset(x, y, sizeof(x))
#define _end '\n'
#define Out(x) cout<<(x)<<_end
template<typename T> inline bool Max(T &x, const T &y) { return x < y ? x = y, 1 : 0; }
template<typename T> inline bool Min(T &x, const T &y) { return x > y ? x = y, 1 : 0; }
template<typename T> using V = vector<T>;
template<typename T> using VV = V<V<T> >;

#define pb push_back
#define mp make_pair

static const ll MOD = 1e9 + 7;
static const double PI = 3.141592653589793;

#define LOCAL 0

int main()
{
#if LOCAL
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
    freopen("debug.txt", "w", stderr);
#endif

    cin.tie(0);
    ios::sync_with_stdio(false);

    ll n, m;

    cin >> n >> m;

    ll ans = 0;

    // multi vertical
    if (1 < n) {
        // multi horizontal
        if (1 < m) {
            ans += 1 * (n - 2) * (m - 2);

        // vertical one line
        } else {
            ans += 1 * (n - 2);
        }

    // horizontal one line
    } else {
        if (1 < m) {
            ans += 1 * (m - 2);

        // 1 x 1
        } else {
            ans += 1;
        }
    }

    Out(ans);

    return 0;
}


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

#define rep(ver,n) rep2(ver,0,n)
#define rep2(ver,m,n) for(int ver=m;ver<(n);ver++)
#define loop while(true)
#define dup(x,y) (((x)+(y)-1)/(y))
#define all(v) (v).begin(), (v).end()
#define debug(x) std::cerr<<#x<<": "<<x<<"\n"
#define debug2(x,y) std::cerr<<#x<<": "<<x<<", "<<#y<<": "<<y<<"\n"
#define debug3(x,y,z) std::cerr<<#x<<": "<<x<<", "<<#y<<": "<<y<<", "<<#z<<": "<<z<<"\n"

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

int main(){
  int n;
  char s[100010];
  scanf("%d", &n);
  scanf("%s", s);
  
  int i = 0;
  
  while(s[i] != '\0'){
    s[i] += n;
    if(s[i] > 90) s[i] -= 26;
    i++;
  }
  
  printf("%s", s);
  
  return 0;
}


Measured memory_bytes: 256
M,D = map(int,input().split())
# v =list(map(int,input().split()))
# [list(map(int,input().split())) for i in range(N)]
d10 = D//10
d1 = D%10

ans = 0
if D<22:
    print('0')
    exit()
else:
    for d in range(22,D+1):
        D10=d//10
        D1 = d%10
        if D10<d10 and D1>=2 and  D10*D1<=M:
            ans+= 1
        elif D10==d10 and D1>=2 and D1<=d1 and D10*D1<=M:
            ans+=1
print(ans)


Measured memory_bytes: 38256
N=int(input())
array=list(map(int,input().split()))

L=[]
for i in array:
    L.append(i)

L=sorted(L)

ans=0
for i in range(N-2):
    for j in range(i+1,N-1):
        if L[i]==L[j]:
            continue
        for k in range(j+1,N):
            if L[j]==L[k]:
                continue
            if L[k]<L[i]+L[j]:
                ans+=1

print(ans)

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

# define REP(i,n) for (int i=0;i<(n);++i)
# define rep(i,a,b) for(int i=a;i<(b);++i)
# define p(s) std::cout << s ;
# define pl(s)  std::cout << s << endl;
# define printIf(j,s1,s2) cout << (j ? s1 : s2) << endl;
# define YES(j) cout << (j ? "YES" : "NO") << endl;
# define Yes(j) std::cout << (j ? "Yes" : "No") << endl;
# define yes(j) std::cout << (j ? "yes" : "no") << endl;
# define all(v) v.begin(),v.end()
# define showVector(v) REP(i,v.size()){p(v[i]);p(" ")} pl("")
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;}
typedef long long int ll;
typedef pair<int,int> P_ii;
typedef pair<double,double> P_dd;

template<class T>
vector<T> make_vec(size_t a){
    return vector<T>(a);
}

template<class T, class... Ts>
auto make_vec(size_t a, Ts... ts){
  return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}

template<typename T,typename V>
typename enable_if<is_class<T>::value==0>::type
fill_v(T &t,const V &v){t=v;}

template<typename T,typename V>
typename enable_if<is_class<T>::value!=0>::type
fill_v(T &t,const V &v){
  for(auto &e:t) fill_v(e,v);
}


const int MOD = 1000000007;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;

void addM(long long &a, long long b) {
    a += b;
    if (a >= MOD) a -= MOD;
}

void mulM(long long &a, long long b) {
    a = ((a%MOD)*(b%MOD))%MOD ;
}

// テーブルを作る前処理
const int MAX = 510000;
long long fac[MAX], finv[MAX], inv[MAX];
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(ll n, ll k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

vector<pair<long long, long long> > prime_factorize(long long n) {
    vector<pair<long long, long long> > res;
    for (long long p = 2; p * p <= n; ++p) {
        if (n % p != 0) continue;
        ll num = 0;
        while (n % p == 0) { ++num; n /= p; }
        res.push_back(make_pair(p, num));
    }
    if (n != 1) res.push_back(make_pair(n, 1));
    return res;
}

int main() {
    int N,C;
    cin >> N >> C;

    int D[31][31];
    REP(i,C) REP(j,C) cin >> D[i][j];

    map<int,int> mp[3];
    REP(i,N) REP(j,N) {
        int c;
        cin >> c;
        mp[((i+1)+(j+1))%3][c-1]++;
    }

    vector<int> val[3];
    REP(i,3) REP(j,C) {
        val[i].push_back(0);
        for(auto m:mp[i]){
            val[i][j] += (D[m.first][j] * m.second);
        }
    }

    int ans = inf;
    REP(i,C) REP(j,C) REP(k,C){
        if(i==j || i==k || j==k) continue;
        chmin(ans,val[0][i]+val[1][j]+val[2][k]);
    }

    pl(ans)

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <map>
#include <numeric>
#include <string>
#include <cmath>
#include <iomanip>
#include <queue>
#include <list>
#include <set>
#include <stack>
#include <cctype>
#include <cmath>
#include <bitset>

using namespace std;

/* typedef */
typedef long long ll;

/* constant */
const int INF = 1 << 30;
const int NIL = -1;
const int MAX = 100;
const int mod = 1000000007;
const double pi = 3.141592653589;

/* global variables */

/* function */

/* main */
int main(){

    int N;
    cin >> N;
    vector<int> V(N);
    for (int i = 0; i < N; i++)
        cin >> V[i];

    vector<int> U(MAX + 1, 0);
    for (int i = 0; i <= MAX; i++) {
        for (auto v : V) {
            U[i] += pow(v - i, 2);
        }
    }

    cout << *min_element(U.begin(), U.end()) << '\n';

}


Measured memory_bytes: 256
N,T = map(int,input().split())
cost = 10000
ans = False
for i in range(N):
    c,t = map(int,input().split())
    if(T>=t and c < cost):
        cost = min(cost,c)
        ans = True
if(ans):
    print(cost)
else:
    print("TLE")

Measured memory_bytes: 38384
#include <bits/stdc++.h>
using namespace std;
using edge= pair<int64_t, int>;
using Graph= vector<vector<edge>>;

void solve(const Graph &gph, int s, vector<int64_t> *dists){
  using path= edge;

  priority_queue<path, vector<path>, greater<path>> search;
  search.push(make_pair(0, s));
  while( !search.empty() ){
    int64_t d_tmp; int from_tmp;
    tie(d_tmp, from_tmp)= search.top();
    search.pop();

    if(dists->at(from_tmp) <= d_tmp){ continue; }
    else{
      dists->at(from_tmp)= d_tmp;
      for(auto e:gph.at(from_tmp)){
        int64_t d_to; int to_tmp;
        tie(d_to, to_tmp)= e;
        search.push(make_pair(d_tmp+ d_to, to_tmp));
      }
    }
  }
}

// Dijkstra
int main(){
  constexpr char block= '#';
  using coord= pair<int, int>;
  const vector<coord> diff0= {make_pair(1,0), make_pair(0,1) };
  const vector<coord> diff1= {make_pair(0,2), 
                              make_pair(1,-2), make_pair(1,-1), make_pair(1,1), make_pair(1,2),
                              make_pair(2,-2), make_pair(2,-1), make_pair(2,0), make_pair(2,1), make_pair(2,2) 
                              };

  int H,W;
  cin >> H >> W;

  int s1,s2,g1,g2;
  cin >> s1 >> s2 >> g1 >> g2;
  s1--; s2--; g1--; g2--; // 1-indexed -> 0-indexed
  const int s= s1*W+ s2;
  const int g= g1*W+ g2;

  vector<string> board(H);
  for(int h=0; h<H; h++){
    cin >> board.at(h);
  }

  Graph gph(H*W);
  for(int x=0; x<H; x++){
    for(int y=0; y<W; y++){
      int id= x*W+ y;
      if(board.at(x).at(y)==block){ continue; }
      else{
        for(auto [dx,dy]:diff0){
          if(x+dx <= -1 || x+dx >= H || y+dy <= -1 || y+dy >= W) continue;
          else if(board.at(x+dx).at(y+dy)==block){
            continue;
          }
          else{
            int id_to= (x+dx)*W+ (y+dy);
            gph.at(id).emplace_back(make_pair(0, id_to));
            gph.at(id_to).emplace_back(make_pair(0, id));
          }
        }
        for(auto [dx,dy]:diff1){
          if(x+dx <= -1 || x+dx >= H || y+dy <= -1 || y+dy >= W) continue;
          else if(board.at(x+dx).at(y+dy)==block){
            continue;
          }
          else{
            int id_to= (x+dx)*W+ (y+dy);
            gph.at(id).emplace_back(make_pair(1, id_to));
            gph.at(id_to).emplace_back(make_pair(1, id));
          }
        }
      }
    }
  }

  constexpr int64_t INF= 1e9;
  vector<int64_t> dists(H*W, INF);
  solve(gph, s, &dists);

  int64_t ans= (dists.at(g) < INF) ? dists.at(g)
                                   : -1;
  
  cout << ans << endl;
}

Measured memory_bytes: 170088
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define mod 1000000007
#define inf 1e18
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	ll t;
	t=1;
//	cin>>t;
	while(t--)
	{
       string s;
       cin>>s;
       if(s[s.length()-1]=='s')
       cout<<s<<"es"<<endl;
       else
       cout<<s<<"s"<<endl;
	}
}


Measured memory_bytes: 3632
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>

using namespace std;

#define B       (cout << "Sehen Sie mich!" << endl)
#define VB(val) (cout << val << endl)

int main()
{
        int N;
        cin >> N;
        int x = N;
        int fx = 0;

        while (N != 0) {
                fx += N % 10;
                N /= 10;
        }

        if (x % fx == 0)
                VB("Yes");
        else
                VB("No");
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
using namespace std;
typedef long long int ll;
#define rep(i,n) for(int i=0;i<(int)n;i++)
int Min(int a, int b, int c) {
	if (a <= b) { return std::min(a, c); }
	else return std::min(b, c);
}
int main(void) {
	ll a, b; cin >> a >> b;
	cout << (a - b >= 0 ? a - b : 0) << endl;
	return 0;
}

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

int main(){
	string s;
	cin>>s;
	int a;
	int m=0;
	int l=0;
	a=s.length()-1;
	
    while (a>l) 
    { 
        if (s[l++] != s[a--]) 
        { 
            m++;
        } 
    } 


cout<<m<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
// using namespace __gnu_pbds;


#define ll       long long int
#define fast     ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
#define MOD      1000000007
#define pb       push_back
#define S        second
#define F        first
#define P 		 pair<ll,ll>
#define PI 3.1415926535897932384626433832795028
//#define ordered_set tree<ll, null_type,less_equal<>, rb_tree_tag,tree_order_statistics_node_update>

int mul(int a, int b) {
	return (long long)a * b % MOD;
}

int power(int a, int b) {
	int ans = 1;
	while (b > 0) {
		if (b & 1) ans = mul(ans, a);
		a = mul(a, a);
		b >>= 1;
	}
	return ans;
}
//bitset<400000010> b;

// ll n=100000;
ll p[1000100] = {0};
vector<ll> v[1000000];
void sieve(ll n) {
	for (ll i = 2; i * i <= n; i++) {
		if (!p[i])
			//primes.push_back(i);
			for (ll j = i; j <= n; j += i) {
				if (i != j)
					;
				p[j] = 1;
			}
	}
}


// ll nextPowerOf2(ll n)
// {
//     ll p = 1;
//     if (n && !(n & (n - 1)))
//         return n;

//     while (p < n)
//         p <<= 1;

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

}
ll factorial(ll n)
{
	if (n == 0)
		return 1;
	return n * factorial(n - 1);
}
struct segmenttree {
	vector<int> st;
	int n;
	void init(int _n) {
		n = _n;
		st.clear();
		st.resize(4 * _n, 0);
	}

	void update(int l, int r, int indup, int val, int node) {
		if (l == r) {
			st[node] += val;
			return;
		}
		else {
			int mid = (l + r) / 2;
			if (indup >= l && indup <= mid) {
				update(l, mid, indup, val, node * 2 + 1);
			}
			else {
				update(mid + 1, r, indup, val, node * 2 + 2);
			}
			st[node] = st[2 * node + 1] + st[2 * node + 2];
		}
	}

	int query(int si, int se, int l, int r, int node) {
		if (se < l || si > r || l > r) {
			return 0;
		}
		if (si >= l && se <= r) {
			return st[node];
		}
		int mid = (si + se) / 2;
		int q1 = query(si, mid, l, r, node * 2 + 1);
		int q2 = query(mid + 1, se, l, r, node * 2 + 2);
		return q1 + q2;
	}
	int query(int l, int r) {
		return query(0, n - 1, l, r, 0);
	}
	void update(int index, int val) {
		update(0, n - 1, index, val, 0);
	}
} tree;

bool chkcow(ll n, vector<ll> &a, ll k, ll mis) {
	ll sum = 0;
	for (ll i = 0; i < n; i++) {
		if (a[i] > mis)
			sum += a[i] - mis;
		if (sum >= k)
			return true;
	}


	return false;
}
struct cmp {
	bool operator() (const pair<ll, ll> &a, const pair<ll, ll> &b )const
	{
		ll lena = a.S - a.F;
		ll lenb = b.S - b.F;
		if (lena == lenb)
			return a.F < b.F;
		return lena > lenb;
	}
};



int32_t main()
{	fast

// #ifndef ONLINE_JUDGE
// 	freopen("input.txt", "r", stdin);
// 	freopen("output.txt", "w", stdout);
// #endif
	ll n;
	cin >> n;
	ll a[n + 10];
	for (ll i = 0; i < n; i++) {
		cin >> a[i];
	}
	ll dp[n + 10];
	if (n <= 2) {
		cout << abs(a[0] - a[1]) << endl;
		return 0;
	}
	dp[0] = 0;
	dp[1] = abs(a[1] - a[0]);
	dp[2] = abs(a[2] - a[0]);
	for (ll i = 3; i < n; i++) {
		dp[i] = min(dp[i - 1] + abs(a[i] - a[i - 1]), dp[i - 2] + abs(a[i] - a[i - 2]));
	}
	cout << dp[n - 1] << endl;
	return 0;

}

Measured memory_bytes: 26368
N = int(input())
S = input()
s = list(S)

R=[]
G=[]
B=[]
for i in range(N):
    if s[i] == "R":
        R.append(i+1)
    elif s[i] == "G":
        G.append(i+1)
    else:
        B.append(i+1)

count = len(R)*len(G)*len(B)
for i in range(1,N-1):
    f = s[i-1::-1]
    b = s[i+1:]
    for j in range(min(len(f),len(b))):
        if f[j]!=s[i] and f[j] != b[j] and s[i] != b[j]:
            count -=1
print(count)


Measured memory_bytes: 9296
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;

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

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

// Self settings
// clang-format off
#define MAX_N 100000
#define REP(i, N) for (int i = 0; i < (int)(N); ++i)
#define SLN(i,N) (i == N-1 ? "\n" : " ")
ll gcd(ll a,ll b){if(b==0)return a;return gcd(b,a%b);}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
const ll MOD = 1e9+7;
const ll INF = 1LL << 60;
const int inf = 1 << 31;
// clang-format on

int main(void)
{
  int M, D;
  cin >> M >> D;
  int ans = 0;
  for (int m = 1; m <= M; m++) {
    for (int d = 1; d <= D; d++) {
      int d1 = d % 10;
      int d10 = d / 10;
      if (d1 < 2 || d10 < 2) continue;
      if (d1 * d10 == m) ans++;
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 888
#include <bits/stdc++.h>
#define for0(i, n) for(int i = 0; i < n; i++)
#define for1(i, n) for(int i = 1; i <= n; i++)
#define pb push_back
#define mp make_pair
#define all(v) v.begin(), v.end()
#define V vector<int>
#define VP vector<pair<int, int> >
#define FASTIO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
using namespace std;
#ifdef _WIN32
#include <windows.h>
#define print(x) PRINT(x, #x)
template<typename T> inline const void PRINT(T VARIABLE, string NAME)
{
#ifndef ONLINE_JUDGE /// ONLINE_JUDGE IS DEFINED ON CODEFORCES
    HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
    SetConsoleTextAttribute(hConsole, 10);
    cerr << NAME << " = " << VARIABLE << '\n';
    SetConsoleTextAttribute(hConsole, 7);
#endif
}
#else
#define print(x) 0
#endif
struct pair_hash
{
    template<typename T1, typename T2>
    size_t operator () (const pair<T1, T2> &p) const
    {
        auto h1 = hash<T1> {}(p.first);
        auto h2 = hash<T2> {}(p.second);
        return h1 ^ h2;
    }
};
typedef long long ll;
typedef unsigned long long ull;
const ll INFLL = 2 * (ll)1e18 + 100;
const int INFINT = 2 * (int)1e9 + 100;
//ifstream fin(".in");
//ofstream fout(".out");
void die()
{
    cout << "NO";
    exit(0);
}
const int NMAX = 3 * 1e5 + 5;
const int MOD = 1e9 + 7; /// careful here (7 or 9, 66.. etc)
const double PI = atan(1) * 4;
const double EPS = 1e-12;

int n;
unordered_map<int, int> cnt;
V v;

int main()
{
    FASTIO;
    cin >> n;
    for1(i, n)
    {
        int a;
        cin >> a;
        cnt[a]++;
        if(cnt[a] == 2) v.pb(a);
        if(cnt[a] == 4) v.pb(a);
    }
    sort(all(v), greater<int>());
    if(v.size() >= 2) cout << (ll)v[0] * v[1];
    else cout << 0;

    return 0;
}


Measured memory_bytes: 4388
#include <iostream>
#include <algorithm>
#include <cmath>
#include <limits>
#include <iomanip>
#include <vector>
#include <cstring>
#include <queue>
#include <map>
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
const int INF = 1e6;
using namespace std;
const int dx[4] = {0,1,0,-1};
const int dy[4] = {1,0,-1,0};
template<class T> inline bool chmax(T &a,T& b){if(a < b){a = b; return true;} else return false;}
template<class T> inline bool chmin(T &a,T& b){if(a > b){a = b; return true;} else return false;}
int main(){
    while(true){
        int h,w;
        cin >> h >> w;
        if(h == 0) break;
        rep(i,h){
            rep(i,w){
                cout << '#';
            }
            cout << endl;
        }
        cout << endl;
    }
}


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

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

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

const int MAX = 1e5 + 5;
const int INF = 1001001001;
const int MOD = 1e9 + 7;

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

    int ans = 0;
    rep(i, N - 2) {
        if (S.substr(i, 3) == "ABC") ans++;
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
////*24-AUG-19*///
//Why do we fall?//
// So we can learn to pick ourself up!//
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>
using namespace std;
using namespace __gnu_pbds;
#define ll long long
#define int long long
#define endl "\n"
#define fi first
#define se second
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define fr(a,b,c) for(int a=b; a<c; a++)
#define frr(a,b,c) for(int a=b;a>=c;a--)
#define pb push_back
#define pii pair<int,int>
#define R(a) ll a; cin >> a;

typedef tree<long long,null_type,greater<long long>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
typedef tree<long long,null_type,less<long long>,rb_tree_tag,tree_order_statistics_node_update> ordered_set1;

#define RA(a, n) ll a[(n) + 1] = {}; fr(i, 1, (n)+1) {cin >> a[i];}
#define RM(a, n, m) int a[n + 1][m + 1] = {}; fr(i, 1, n+1) {fr(j, 1, m+1) cin >> a[i][j];}
#define reset(X) memset(X, 0, sizeof(X))
using vi=vector<int>;
const int inf = 1e18;
const int mod=1e9+7;
unsigned int power(int x, unsigned int y, int p)
{
    int res = 1;
    x = x % p;
    while (y > 0)
    {
        if (y & 1)
            res = (res*x) % p;
        y = y>>1;
        x = (x*x) % p;
    }
    return res;
}
bool isPrime(int n)
{   if (n <= 1)  return false;
    if (n <= 3)  return true;
    if (n%2 == 0 || n%3 == 0) return false;
    for (int i=5; i*i<=n; i=i+6)
        if (n%i == 0 || n%(i+2) == 0)
           return false;
    return true;
}
int modInverse(int n, int p)
{
    return power(n, p-2, p);
}
bool sortbysec(const pair<int,int> &a,
              const pair<int,int> &b)
{
    if(b.fi==a.fi)return (a.se>b.se);
    return (b.fi>a.fi);
}
signed main()
{
    fastio;
    R(h);R(a);
    cout<<h/a+(h%a?1:0)<<endl;
}


Measured memory_bytes: 256
n = int(input())
bit = []
base = 2
if n==0:
    print(0)
    exit()
while n != 0:
    # print(n)
    if n % (base) == 0:
        bit.insert(0,0)
    else:
        bit.insert(0, 1)
        n -= int(base/2)
    base *= -2
bit = map(str,bit)
print("".join(bit))

Measured memory_bytes: 3064
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;

public class Main {

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

        // 宝石の価値
        int[] V = new int[N];
        for (int i = 0; i < N; i++) {
            V[i] = sc.nextInt();
        }
        sc.close();

        int max = 0;
        for (int i = 0; i <= Math.min(N, K); i++) {
            for (int j = 0; i + j <= Math.min(N, K); j++) {
                List<Integer> val = new ArrayList<Integer>();
                int sum = 0;
                for (int m = 0; m < i; m++) {
                    val.add(V[m]);
                    sum += V[m];
                }

                for (int n = 0; n < j; n++) {
                    val.add(V[N - n - 1]);
                    sum += V[N - n - 1];
                }

                int remain = K - val.size();
                for (int e = 0; e < remain; e++) {
                    if (val.size() > 0) {
                        int min = Collections.min(val);
                        if (min < 0) {
                            sum -= min;
                            val.remove(val.indexOf(min));
                        } else {
                            break;
                        }
                    }
                }

                if (sum > max) {
                    max = sum;
                }
            }
        }

        System.out.println(max);

    }
}

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

using namespace std;

#define ll long long int

int main()
{
	int n;
	cin >> n;
	ll ans = 0;
	for(int i = 1; i <= n; i++) {
		for(int j = 1;j <= n; j++) {
			for(int k = 1; k <= n; k++) {
				ans += __gcd(i,__gcd(j,k));
			}
		}
	}
	cout << ans;
	return 0;
}


Measured memory_bytes: 3636
import java.util.*;

public class Main {

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

        int n = sc.nextInt();

        int[] b = new int[n - 1];

        for(int i = 0; i < n - 1; i++){
            b[i] = sc.nextInt();
        }

        int result = b[0];

        for(int i = 1; i < n - 1; i++){
            result += b[i] > b[i - 1] ? b[i - 1] : b[i];
        }

        result += b[n - 2];

        System.out.println(result);
    }
}

Measured memory_bytes: 22736
#include <iostream>
#include<vector>
#include<algorithm>
#include<iomanip>
using namespace std;
int main() {
	long long int a=0,b=0,c=0,d=0,n=0,ans=0,count=0,w ,up,down,end=0,idx,m,kuso,k;
	string s;
	vector<long long int> h;
	vector<long long int>::iterator position;
	bool q=false;
	cin >>n>>k;
	for (int i = 0; i < n; i++){
		cin >> a;
		h.push_back(a);
		ans += a;
	}
	sort(h.begin(), h.end());
	reverse(h.begin(), h.end());
	if (n <= k)cout << "0" << endl;
	else {
		for (int i = 0; i < k; i++) {
			ans -= h.at(i);
		}
		cout << ans << endl;
	}
	
	
	
	
}

Measured memory_bytes: 2420
/*input
3
-10 5 -4
*/
#pragma GCC optimize ("Ofast")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
	ios_base::sync_with_stdio(false);
	ll N, x, y, a, b, c;
	cin >> N;
	cin >> a;
	b = -1e15;
	y = a;
	for (int i = 2; i <= N; i++)
	{
		cin >> x;
		ll c = max(a, b);
		b = -x + max(a - 2 * y, b + 2 * y);
		a = x + c;
		y = x;
	}
	cout << max(a, b) << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std; 
int main() {
  int A,B,C,X;
  cin >> A >> B >> C >> X;
  int res=0;
  for(int a=0;a<=A;a++){
    for(int b=0;b<=B;b++){
      for(int c=0;c<=C;c++){
        int total = 500*a+100*b+50*c;
        if(total==X)res++;
      }
    }
  }
  cout << res << endl;
  }
  


Measured memory_bytes: 256
import statistics
n=int(input())
box=list(map(int,input().split()))
box_m=sorted(list(y-(x+1) for x,y in enumerate(box)))
median=int(statistics.median(box_m))
count=0
for x,y in enumerate(box):
    count +=abs(y-(median+x+1))
print(count)

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




#define rrep(i,a,b) for(int i=a;i>=b;i--)
typedef long long ll;
int N;
int A[101010], B[101010];
//-----------------------------------------------------------------
int main() {
	cin >> N;
	rep(i, 0, N) scanf("%d %d", &A[i], &B[i]);

	ll ans = 0;
	rrep(i, N - 1, 0) {
		ll a = A[i] + ans;
		ll d = B[i] - (a % B[i]);
		if (d == B[i]) d = 0;
		ans += d;
	}
	printf("%lld\n", ans);
}

Measured memory_bytes: 1024
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <list>
#include <string>
#include <numeric>
#include <math.h>
#include <set>
#include <map>
#include <fstream>
#include <sstream>
#include <iterator>
#include <complex>
using namespace std;

long long gcd(long long a,long long b){return b?gcd(b,a%b):a;}
long long lcd(long long a,long long b){return a*b / gcd(a,b) / gcd(a,b);}

int H,W,K;

int count(vector<vector<bool>> mass)
{
	int cnt = 0;
	for(int i=0; i<H; i++)
	{
		for(int j=0; j<W; j++)
		{
			if(mass[i][j])
			{
				cnt++;
			}
		}
	}

	if(cnt == K)
	{
		return 1;
	}
	else
	{
		return 0;
	}
}

int colorResult(vector<vector<bool>> mass, vector<bool> depth)
{
	for(int i=0; i<H; i++)
	{
		if(depth[i])
		{
			for(int j=0; j<W; j++)
			{
				mass[i][j] = false;
			}
		}

	}
	for(int j=0; j<W; j++)
	{
		if(depth[H+j])
		{
			for(int i=0; i<H; i++)
			{
				mass[i][j] = false;
			}
		}
	}
	return count(mass);
}

int dfs(vector<vector<bool>> mass, vector<bool> depth, int index)
{
	if(index == H+W)
	{
		return colorResult(mass,depth);
	}

	vector<bool> tdepth = depth;
	vector<bool> fdepth = depth;

	tdepth[index] = true;
	fdepth[index] = false;

	return dfs(mass, tdepth, index + 1) + dfs(mass, fdepth, index + 1);
}

int main()
{
	
	cin>>H>>W>>K;

	//全て探索する
	vector<vector<bool> > init(H);
	for(int i=0; i<H; i++)
	{
		init[i].resize(W);
		for(int j=0; j<W; j++)
		{
			char _c;
			cin>>_c;
			if(_c == '#')
			{
				init[i][j] = true;
			}
			else
			{
				init[i][j] = false;
			}
		}
	}
	vector<bool> depth(H+W);

	int result = dfs(init,depth,0);
	cout<<result<<endl;
}

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

int main() {
    int n, m, cnt = 0;
    cin >> n >> m;
    vector<int> h(n, 0);
    vector<int> top(n, 1);

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

    int a, b;
    for (int i = 0; i < m; i++) {
        cin >> a >> b;
        if (h[a - 1] < h[b - 1]) {
            top[a - 1] = 0;
        } else if (h[a - 1] > h[b - 1]) {
            top[b - 1] = 0;
        } else if (h[a - 1] == h[b - 1]) {
            top[a - 1] = 0;
            top[b - 1] = 0;
        }
    }

    for (auto& t : top) {
        if (t == 1)
            cnt++;
    }
    cout << cnt << endl;
}

Measured memory_bytes: 4052
#pragma GCC optimize ("O3")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse4")
#include"bits/stdc++.h"
using namespace std;
typedef long long ll;
#define int ll
#define sz(x) (int)(x).size();
#define all(x) x.begin(), x.end()
#define trav(i,a) for(auto &i:a) 
inline int in(){int x;scanf("%lld",&x);return x;}
int32_t main()
{
	int n=in();
	map<int,int> f;
	int x;
	vector<int> a;
	for(int i=0;i<n;i++){x=in();f[x]++;}
	for(auto i:f)
	{
		int t=i.second;
		t/=2;
		for(int _=0;_<t;_++)a.push_back(i.first);
	}
	sort(a.rbegin(),a.rend());
	if(a.size()<=1)cout<<0;
	else cout<<a[0]*a[1];
	
	
}

Measured memory_bytes: 9796
n = int(input())
L = list(map(int, input().split()))
p = 0
for i in range(n):
    minj = i
    for j in range(i, n):
        if L[j] < L[minj]:
            minj = j
    if i != minj: 
        L[i], L[minj] = L[minj], L[i]
        p += 1

print(*L)
print(p)

Measured memory_bytes: 7692
// ?????¬???????????¬??????

#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <functional>
using namespace std;

#define rep(i,a,n) for(int (i)=(a); (i)<(n); (i)++)
#define repq(i,a,n) for(int (i)=(a); (i)<=(n); (i)++)
#define repr(i,a,n) for(int (i)=(a); (i)>=(n); (i)--)
#define int long long int

template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}

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

int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
constexpr ll INF = 1001001001001001LL;
constexpr ll MOD = 1000000007LL;

int comparecnt = 0;

void mergesort(vector<int> &v, int s, int t) {
    if(t - s == 1) return;
    int mid = (s + t) / 2;
    mergesort(v, s, mid);
    mergesort(v, mid, t);
    vector<int> vl, vr;
    rep(i,s,mid) vl.push_back(v[i]);
    rep(i,mid,t) vr.push_back(v[i]);

    int N = mid - s, M = t - mid;
    int cl = 0, cr = 0, cur = s;
    while(cur < t) {
        comparecnt++;
        if(cl == N)    v[cur] = vr[cr++];
        else if(cr == M) v[cur] = vl[cl++];
        else {
            if(vl[cl] < vr[cr]) v[cur] = vl[cl++];
            else                v[cur] = vr[cr++];
        }
        cur++;
    }
}

signed main() {
    int N; cin >> N;
    vector<int> v(N);
    rep(i,0,N) cin >> v[i];

    mergesort(v, 0, N);
    rep(i,0,N) cout << v[i] << (i != N-1 ? " " : "");
    cout << endl << comparecnt << endl;
    return 0;
}

Measured memory_bytes: 11640
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        Scanner sc = new Scanner(System.in);
        int N = Integer.parseInt(sc.nextLine());
        String Stmp = sc.nextLine();
        String S[] = new String[N];
        for(int i=0; i<N; i++){
            S[i] = Stmp.substring(i,i+1);
        }

        int counter=1;
        for(int i=0; i<N-1; i++){
            //System.out.println("i="+i+" compare "+S[i]+" and "+S[i+1]);
            if(S[i].equals(S[i+1])){
                //System.out.println("------"+S[i]+" and "+S[i+1]+" are same so merge & counter:"+counter);
            }else{
                counter++;
                //System.out.println("------Different so increment: "+counter);
            }
        }
        System.out.println(counter);
    }
}
// ・for：N体のスライムを順番に見ていく
// 　・i番目の色をtempに記録
// 　if：(i+1)番目の色と比較して同色なら
// 　　→counterが増えない
// 　　　→次のループに移る
// 　else：(i+1)番目の色と比較して別色なら
// 　　→counterをインクリメント
// 　　　→次のループに移る

Measured memory_bytes: 31916
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		while(true) {

			int n = sc.nextInt();

			if(n == 0) {
				break;
			}
			List<Integer> a = new ArrayList<>();
			int sum = 0;
			int max = 0;
			int min = 1000;
			for(int i = 0; i < n; i++) {
				int x = sc.nextInt();
				a.add(x);
				sum += x;
				if(max < x) {
					max = x;
				}
				if(min > x) {
					min = x;
				}
			}
			sum -= max;
			sum -= min;

			int ans = sum/(n-2);

			System.out.println(ans);
		}

	}

}


Measured memory_bytes: 29164
x , n =  map(int, input().split())
P = [int(i) for i in input().split()]
test = [int(i) for i in range(0,102)]
a = []
for i in range(n):
    test.remove(P[i])
for j in test:
    a.append( abs(x-j) )
ind = a.index(min(a))
print(test[ind])

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

using namespace std;
using ll = long long;
using pii = pair<int, int>;

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  
  int n, s;
  while (cin >> n >> s) {
    int ans = 0;
    for (int i = 0; i < 1 << 10; i++) {
      if (__builtin_popcount(i) != n) continue;
      vector<int> r;
      for (int j = 0; j < 10; j++) {
        if (i >> j & 1) r.emplace_back(j);
      }
      do {
        int sum = 0;
        bool cant = false;
        for (int j = n; j > 0; j--) {
          sum += j * r[j - 1];
          if (sum > s) {
            cant = true;
            break;
          }
        }
        ans += (!cant && sum == s);
      } while (next_permutation(r.begin(), r.end()));
    }
    cout << ans << endl;
  }

  return 0;
}


Measured memory_bytes: 3084
#include <stdio.h>
int main(){
    int l,r,a,b,dl[4],dr[4],m[100];
    while(1){
        scanf("%d%d",&l,&r);
        if(l==0&&r==0)return 0;
        a=b=0;
        for(int i=0;i<10;i++)m[i]=0;
        for(int i=0;i<4;i++){
            dl[i]=l%10;
            dr[i]=r%10;
            l/=10;
            r/=10;
            if(dl[i]==dr[i])a++;
            else {
                m[dl[i]]++;
                m[dr[i]]++;
            }
        }
        for(int i=0;i<10;i++)if(m[i]>1)b++;
        printf("%d %d\n",a,b);
    }
    
}

Measured memory_bytes: 2688
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
const ll MOD=1e9+7;
vector<vector<char>> input(1002,vector<char>(1002));
vector<vector<ll>> dp(1002,vector<ll>(1002));

ll solve(vector<vector<char>>& input,ll n,ll m){
    for(int i=0;i<1002;++i){
        for(int j=0;j<1002;++j){
            dp[i][j]=0;
        }
    }
     // initialise first row
    for(int i=0;input[1][i]!='#' and i<=n;++i)
        dp[1][i]=1;
    // initialise first column
    for(int i=0;input[i][1]!='#' and i<=m;++i)
        dp[i][1]=1;
    // filling rest dp
    for(int i=2;i<=n;++i){
        for(int j=2;j<=m;++j){
            dp[i][j]=(input[i][j]=='#')?0:(dp[i-1][j]+dp[i][j-1])%MOD;
        }
    }
    return dp[n][m];
}

int main() {
	ll n=0;ll m=0;
    cin>>n>>m;
    for(ll i=1;i<=n;++i){
        for(ll j=1;j<=m;++j){
            cin>>input[i][j];
        }
    }
    cout<<solve(input,n,m)<<endl;
    return 0;
}


Measured memory_bytes: 9216
import java.util.*;

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

    int n = sc.nextInt();
    Integer[] a = new Integer[n];

    for (int i = 0; i < n; i++) {
      a[i] = sc.nextInt();
    }

    Arrays.sort(a, Collections.reverseOrder());

    int b = 0;
    int c = 0;

    for (int i = 0; i < n; i++) {
      if (i % 2 == 0) {
        b += a[i];
      } else {
        c += a[i];
      }
    }
    
    System.out.println(b - c);
  }
}


Measured memory_bytes: 25172
import java.util.*;
class Main{
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] a = new int[n];
		for(int i=0;i<n;i++) a[i] = sc.nextInt();
		sc.close();
		long ans = Long.MAX_VALUE / 2;
		// + - + - + - 
		long res = 0;
		long t = 0;
		for(int i=0;i<n;i++) {
			t += a[i];
			if(i % 2 == 0) {
				if(t > 0) continue;
				res += 1 - t;
				t = 1;
			}
			else {
				if(t < 0) continue;
				res += t + 1;
				t = -1;
			}
		}
		ans = Math.min(ans, res);
		res = 0;
		t = 0;
		for(int i=0;i<n;i++) {
			t += a[i];
			if(i % 2 == 1) {
				if(t > 0) continue;
				res += 1 - t;
				t = 1;
			}
			else {
				if(t < 0) continue;
				res += t + 1;
				t = -1;
			}
		}		
		ans = Math.min(ans, res);
		System.out.println(ans);
	}
}

Measured memory_bytes: 59628
#include <iostream>
#include <algorithm>
#include <functional>
#include<vector>
#include<math.h>
#include<bitset>
#include<string>
#include<queue>
using namespace std;

queue<int> q1;
queue<int> q2;
queue<int> q3;
queue<int> q4;
char A[60][60];
int B[60][60];


int main() {
	
	int H, W;
	
	cin >> H >> W;
	
	for (int i = 0; i < H; i++) {
		for (int k = 0; k <W; k++) {
			B[i][k]=1000000;
		}
	}
	int sharp = 0;
	for (int i = 0; i < H; i++) {
		for (int k = 0; k < W;k++) {
			cin >> A[i][k];
			if (A[i][k] == '#') {
				sharp++;
			}
		}
	}
	A[0][0] = 'q';
	B[0][0] = 0;


	
	q1.push(0);
	q2.push(1);
	q3.push(0);
	q4.push(0);

	q1.push(1);
	q2.push(0);
	q3.push(0);
	q4.push(0);

	

	
	while(0==q1.empty()) {
		
		int X = q1.front();
		int Y = q2.front();
		int V = q3.front();
		int Z = q4.front();
		
		if (A[X][Y] == '.') {
			A[X][Y] = 'q';
			if (B[X][Y] > 1 + B[V][Z]) {
				B[X][Y] = B[V][Z] + 1;
				
			}
			else {
				goto go;
			}
		}
		else if (A[X][Y] == 'q'&&B[X][Y] > 1 + B[V][Z]) {
			B[X][Y] = B[V][Z] + 1;
		}
		else {
			goto go;
		}
		

		
		
		q1.push(X - 1);
		q2.push(Y);
		q3.push(X);
		q4.push(Y);

		q1.push(X + 1);
		q2.push(Y);
		q3.push(X);
		q4.push(Y);

		q1.push(X);
		q2.push(Y - 1);
		q3.push(X);
		q4.push(Y);

		q1.push(X);
		q2.push(Y + 1);
		q3.push(X);
		q4.push(Y);

	go:;
		q1.pop();
		q2.pop();
		q3.pop();
		q4.pop();

	}


















	
	 if (B[H - 1][W - 1] == 1000000) {
		cout << -1 << endl;
		}else
		  {
			 cout << H * W - sharp - 1 - B[H - 1][W - 1] << endl;
		 }

	return 0;
 }

Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define REP(i,a,b) for (int i = a; i < (b); ++i)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define YY cout << "Yes" << endl;
#define NN cout << "No" << endl;
#define ve vector
const int INF = 1000000007;
const long double EPS = 1e-15;
const long double PI = acos(-1);
typedef long long ll;
using namespace std;
using Graph = vector<vector<int>>;
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; }
ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
ll lcm(ll a, ll b) { return (a * b) / gcd(a,b); }
// *max_element(all(d))
class UnionFind{
  private:
    vector<int>par;
  public:
    UnionFind(int n):par(n,-1){}
    int root(int x){
      if(par[x] < 0)return x;
      return par[x] = root(par[x]);
    }
    bool unite(int x,int y){
      x = root(x); y = root(y);
      if (x == y) return false;
      if (par[x] > par[y]) swap(x, y);
      par[x] += par[y];
      par[y] = x;
      return true;
    }
    bool same(int x,int y){
      return root(x) == root(y);
    }
    int size(int x) {
      return -par[root(x)];
    }
};
int solve(){
  string s;
  cin >> s;
  vector<string>tmp(4);
  vector<int>tmp_size(4);
  tmp_size[0] = 5,tmp_size[1] = 7,tmp_size[2] = 5,tmp_size[3] = 6;
  tmp[0] = "maerd",tmp[1] = "remaerd",tmp[2] = "esare",tmp[3] = "resare";
  reverse(all(s));
  bool ans = true;
  rep(i,s.size()){
    bool can = false;
    rep(j,4){
      if(i + tmp_size[j] - 1 < s.size()){
        string tmps = s.substr(i,tmp_size[j]);
        if(tmps == tmp[j]){
          can = true;
          i += tmp_size[j] - 1;
          break;
        }
      }
    }
    if(!can)ans = false;
  }
  cout << (ans ? "YES" : "NO") << endl;
  return 0; 
}
int main(){
  // ios::sync_with_stdio(false);cin.tie(nullptr);
  cout << fixed;cout << setprecision(16);
  solve();
  return 0;
}

Measured memory_bytes: 512
program name
    use,intrinsic :: iso_fortran_env
    implicit none
    integer(int32):: n,m,i,x,y,ans
    integer(int32), allocatable:: ball_num(:)
    logical,allocatable:: possible(:)

    
    read*, n,m
    allocate(ball_num(n), source=1)
    allocate(possible(n))
    possible(1) = .true.; possible(2:) = .false.

    do i=1,m
        read*, x,y
        ball_num(x)=ball_num(x)-1
        ball_num(y)=ball_num(y)+1
        if (possible(x)) possible(y)=.true.
        if (ball_num(x) == 0) possible(x) = .false.
    end do

    ans=0
    do i=1,n
        if(possible(i)) ans=ans+1
    end do

    print'(i0)', ans
end program name

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

#ifdef _DEBUG
#define debug(x) cerr << "line: " << __LINE__ << ", func: " << __func__ << " ->  " << #x << " = " << x << endl
#else
#define debug(x)
#endif

#define all(s) begin(s), end(s)
#define rall(s) rbegin(s), rend(s)
#define rep(i, a, b) for (int i = (a); i < (b); i++)
#define rrep(i, a, b) for (int i = ((a)-1); i >= (b); i--)
#define pb push_back
#define sz(a) int((a).size())
#define put(a) ((cout) << (a) << (endl))

using namespace std;

using ll = long long;
using ull = unsigned long long;
using i_i = pair<int, int>;
using ll_ll = pair<ll, ll>;
using d_ll = pair<double, ll>;
using ll_d = pair<ll, double>;
using d_d = pair<double, double>;

static constexpr ll LL_INF = 1LL << 60;
static constexpr int I_INF = 1 << 28;
static constexpr double PI = static_cast<double>(3.14159265358979323846264338327950288);
static constexpr double EPS = numeric_limits<double>::epsilon();

static map<type_index, const char* const> scanType = {
    {typeid(int), "%d"}, {typeid(ll), "%lld"}, {typeid(double), "%lf"}, {typeid(char), "%c"}};

template <class T> static void scan(vector<T>& v);
[[maybe_unused]] static void scan(vector<string>& v, bool isWord = true);
template <class T> static inline bool chmax(T& a, T b);
template <class T> static inline bool chmin(T& a, T b);
template <class A, size_t N, class T> static void Fill(A (&arr)[N], const T& val);

int main(int argc, char* argv[]) {
  string S;
  cin >> S;

  rep(i, 1, sz(S)) {
    if (S[i] == S[i - 1]) {
      put("Bad");
      return 0;
    }
  }
  put("Good");
  return 0;
}

template <class T> static void scan(vector<T>& v) {
  auto tFormat = scanType[typeid(T)];
  for (T& n : v) {
    scanf(tFormat, &n);
  }
}

static void scan(vector<string>& v, bool isWord) {
  if (isWord) {
    for (auto& n : v) {
      cin >> n;
    }
    return;
  }

  int i = 0, size = v.size();
  string s;
  getline(cin, s);

  if (s.size() != 0) {
    i++;
    v[0] = s;
  }

  for (; i < size; ++i) {
    getline(cin, v[i]);
  }
}

template <class T> inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}

template <class T> inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}

template <class A, size_t N, class T> void Fill(A (&arr)[N], const T& val) {
  std::fill((T*)arr, (T*)(arr + N), val);
}


Measured memory_bytes: 256