akhauriyash/Code-Regression huggingface dataset:
import java.util.Scanner;

public class Main {
	private Scanner sc;
	
	public static void main(String[] args) {
		new Main();
	}
	
	public Main() {
		sc = new Scanner(System.in);
		
		boolean flag = false;
		
		String line = "";
		while (sc.hasNext() == true) {
			line = sc.nextLine();

			for (int i = 0; i < 10; i++) {
				flag = check(line.replaceAll("X", "" + i));
				
				if (flag == true) {
					System.out.println(i);
					break;
				}
			}
			if (flag == false) System.out.println("NA");
		}
	}
	
	public boolean check(String formula) {
		String[] number = new String[3];
		
		int p = 0;
		for (int i = 0; i < number.length; i++) {
			number[i] = "";
			
			while (Character.isDigit(formula.charAt(p)) == true) {
				number[i] = number[i] + formula.charAt(p);
				p++;
				
				if (p == formula.length()) break;
			}
			
			if ((number[i].charAt(0) == '0') && (number[i].length() > 1)) return false;
			p++;
		}

		int carry = 0;
		for (int i = 0; i < number[2].length(); i++) {
			int a = 0;
			int b = 0;
			int c = number[2].charAt(number[2].length() - i - 1) - '0';
			
			if (i < number[0].length()) a = number[0].charAt(number[0].length() - i - 1) - '0';
			if (i < number[1].length()) b = number[1].charAt(number[1].length() - i - 1) - '0';
			
			if (((a + b + carry) % 10) != c) return false;
			carry = (a + b + carry) / 10;
		}
		
		return true;
	}
}

Measured memory_bytes: 31012
#include <iostream>
#include <algorithm>

using namespace std;

int main()
{
	int a[3];
	for(int i=0;i<3;i++)
	{
		cin>>a[i];
	}
	if(a[1]-a[0]==a[2]-a[1])
	{
		cout<<"YES"<<endl;
	}else{
		cout<<"NO"<<endl;
	}
	return 0;
}

Measured memory_bytes: 256
<?php
while ($line = fgets(STDIN)) {
    $inputs[] = trim($line);
};
list($s, $w) = explode(" ", $inputs[0]);
$s = (int) $s;
$w = (int) $w;

if ($s <= $w) {
    echo "unsafe\n";
} else {
    echo "safe\n";
}


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

int main() {
	int n, k;
	cin >> n >> k;
	set<int> s;

	rep(i,k) {
      	int d;
		cin >> d;
		rep(j,d) {
			int a;
			cin >> a;
			s.insert(a);
		}
	}

	cout << n - s.size() << endl;

	return 0;
}

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

using namespace std;

#define fst(t) std::get<0>(t)
#define snd(t) std::get<1>(t)
#define thd(t) std::get<2>(t)

using P = std::tuple<int,int>;
using ll = long long;

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

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

    string S, T = "";
    std::cin >> S;

    for(const auto& c : S){
        if(c == 'B'){
            if(T.size() > 0){
                T = T.substr(0, T.size() - 1);
            }
        }else{
            T += c;
        }
    }

    std::cout << T << std::endl;
}


Measured memory_bytes: 256
mod = 10**9+7
N, K = map(int,input().split())
A = sorted(list(map(int,input().split())))

pi = 1
ni = 0
ans = 1
i = 0
while i < K-1:
  if A[ni]*A[ni+1] > A[-pi]*A[-pi-1]:
    ans = ans*A[ni]*A[ni+1]%mod
    ni += 2
    i += 2
    
  else:
    ans = ans*A[-pi]%mod
    pi += 1
    i += 1
    
if i == K-1:
  ans = ans*A[-pi]%mod
  
if A[-1]<0 and K%2==1:
  ans = 1
  for i in A[N-K:]:
    ans = ans*i%mod

print(ans)

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

#ifdef LOCAL
#include "dump.hpp"
#else
#define dump(...)
#endif

using namespace std;

#define REP(i, a, b) for(int i = (a); i < int(b); ++i)
#define rep(i, n) REP(i, 0, n)
#define ALL(x) begin(x), end(x)

template<class T> inline void chmax(T &a, const T &b) { if(a < b) a = b; }
template<class T> inline void chmin(T &a, const T &b) { if(a > b) a = b; }

constexpr int MAX = 86400;
constexpr double EPS = 1e-7;

inline bool check(double w, int l, const vector<int> &require) {
	double t = l;
	for(int i = 0; i < MAX; ++i) {
		t = min<double>(l, t - require[i] + w);
		if(t < 0) return false;
	}

	double p = t;
	for(int i = 0; i < MAX; ++i) {
		t = min<double>(l, t - require[i] + w);
		if(t < 0) return false;
	}

	return abs(t - p) < EPS;
}

int main() {
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	cout.setf(ios::fixed);
	cout.precision(10);

	for(int n, l; cin >> n >> l && n;) {
		vector<int> require(MAX + 1, 0);
		for(int i = 0; i < n; ++i) {
			int s, t, u;
			cin >> s >> t >> u;
			require[s] += u;
			require[t] -= u;
		}

		partial_sum(begin(require), end(require), begin(require));

		double L = 0, R = 1000000;
		for(int i = 0; i < 100; ++i) {
			const double M = (L + R) * 0.5;
			if(check(M, l, require)) {
				R = M;
			}
			else {
				L = M;
			}
		}
		cout << L << endl;
	}

	return EXIT_SUCCESS;
}

Measured memory_bytes: 1612
#include <stdio.h>
int main()
{
  int n,x,t;
  scanf("%d%d%d",&n,&x,&t);
  if (n % x != 0)
  {
    printf("%d",(n/x+1)*t);
  }
  else
  {
    printf("%d",(n/x)*t);
  }
  
}

Measured memory_bytes: 1732
a, b, c, k = map(int, input().split())
ans = 0
bool =True
if k > a:
    ans = ans +a
    k = k-a #kはプラスかマイナスか
    if k > b:
        k = k-b
        if k > 0:
            ans -= k
    
        
else:
    ans = k

print(ans)

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

using namespace std;

int main()
{
	long long a,b;
	cin >> a >> b;
	a=__gcd(a,b);
	int ans=0;
	for(long long i=2;i*i<=a;i++)
	{
		if(a%i==0) ans++;
		while(a%i==0) a/=i;
	}
	if(a>1) ans++;
	cout << ans+1 << endl;
}

Measured memory_bytes: 256
A,B,H,M = map(float, input().split())

import math

degreeA = float((H * 60 + M) / 2)
degreeB = float(M * 6)

degreeAB = abs(degreeA - degreeB)

if degreeAB > 180:
    degreeAB = 360 - degreeAB
C = float(A ** 2 + B ** 2 - 2 * A * B * float(math.cos(float(degreeAB * math.pi / 180))))
print(math.sqrt(C))

Measured memory_bytes: 9392
#include<cstdio>
#include<cmath>
#include<string>
#include<iostream>
#include<algorithm>
#include<utility>
#include<vector>
#include<map>
#include<set>
#include<limits>
#include<bitset>
#include<array>
#include<numeric>
#include<iomanip>
#include<functional>

using namespace std;
typedef long long int ll;

#define C cout<<
#define E <<endl

ll n,m,a[100010],b[100010];
map<int,int> mpa;
vector<int> vc;

int main(){
    cin>>n;
    
    for(int i=0;i<n;i++){
        cin>>a[i];
        mpa[a[i]]++;
    }
    
    for(auto i=mpa.begin();i!=mpa.end();++i){
        for(int j=2;j<=(i->second);j+=2){
            vc.push_back(i->first);
        }
        //if(2<=(i->second)){
            //vc.push_back(i->first);
            //C i->second E;
        //}
    }
    
    sort(vc.begin(),vc.end(),greater<int>());
    
    if(vc.size()<2)C "0" E;
    else C ll(vc[0])*ll(vc[1]) E;
    
    
    
    
}

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

int main(){
  int A1,A2,A3,s;
  cin >> A1 >> A2 >> A3;
  s=A1+A2+A3;
  if(s>=22){
    cout << "bust" << endl;
  }
  else{
    cout << "win" << endl;
  }
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main()
{   
    int X,H;
    cin>>X;
    H=0;
    while(X/500>0){
        X=X-500;
        H=H+1000;
    }
    while(X/5>0){
        X=X-5;
        H=H+5;
    }
    cout<<H;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <string>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <math.h>
#include <vector>
#include <algorithm>
using namespace std;

int main(){
	int m;
	cin >> m;
	cout << 24 + (24 - m) << endl;
	return 0;
}

Measured memory_bytes: 256
#include <atcoder/all>
using namespace atcoder;
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)n; ++i)
#define rrep(i, n) for (int i = (int)n-1; i >= 0; --i)
using namespace std;
using ll = long long;
template<typename T>
inline bool chmax(T& a, const T& b) {
    if (a < b){
        a = b;
        return true;
    }
    return false;
}
template<typename T>
inline bool chmin(T& a, const T& b) {
    if (b < a) {
        a = b;
        return true;
    }
    return false;
}
/**
 * @brief 多次元 vector の作成
 * @author えびちゃん
 */
namespace detail {
    template<typename T, int N>
    auto make_vec(vector<int>& sizes, T const& x) {
        if constexpr (N == 1) {
            return vector(sizes[0], x);
        } else {
            int size = sizes[N-1];
            sizes.pop_back();
            return vector(size, make_vec<T, N-1>(sizes, x));
        }
    }
}
template<typename T, int N>
auto make_vec(int const(&sizes)[N], T const& x = T()) {
    vector<int> s(N);
    for (int i = 0; i < N; ++i) s[i] = sizes[N-i-1];
    return detail::make_vec<T, N>(s, x);
}
__attribute__((constructor))
void fast_io() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
}

using mint = modint998244353;

vector<mint> ten_pow, ones;

struct S {
    int size;
    mint val;
};

S op (S l, S r) {
    return {l.size + r.size, l.val * ten_pow[r.size] + r.val};
}

S e() { return {0, 0}; };

using F = int;

S mapping(F f, S x) {
    if (f == 0) return x;
    return {x.size, f * ones[x.size]};
}

F composition(F f, F g) {
    if (f == 0) return g;
    else return f;
}

F id() { return 0; }

int main() {
    int n, q;
    cin >> n >> q;
    ten_pow.resize(n+1);
    ones.resize(n+1);
    ten_pow[0] = 1;
    ones[0] = 0;
    for (int i = 1; i <= n; ++i) {
        ten_pow[i] = ten_pow[i-1] * 10;
        ones[i] = ones[i-1] * 10 + 1;
    }
    vector<S> a(n, S{1, 1});
    lazy_segtree<S, op, e, F, mapping, composition, id> seg(a);

    while (q--) {
        int l, r, d;
        cin >> l >> r >> d;
        l--; r--;
        seg.apply(l, r+1, d);
        cout << seg.all_prod().val.val() << '\n';
    }
}

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

int R,G,B,N;

int main(){
    cin>>R>>G>>B>>N;
    long long count=0;
    for(int r=0;r<=3000;r++){
        for(int g=0;g<=3000;g++){
            if((N-r*R-g*G)%B==0&&(N-r*R-g*G)>=0)count++;        }
    }
    cout<<count<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define int long long
#define all(sdk) sdk.begin(),sdk.end()
#define mll map<ll, ll>
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define rep(i,a,b) for(ll i=a;i<b;++i)
#define repd(i,a,b) for(ll i=a;i>=b;--i)
//#define mp make_pair
#define hell 1000000007
#define endl '\n'
#define vvll vector<vector<int> >
#define vll vector<int>
#define mint map<int,int>
#define sz(x) (int)x.size()
#define sll set<int>
#define pll pair<int,int>
#define F first
#define S second
#define INF 1e18
#define NINF -1e16

#define maxn 1000005
int spf[maxn];
vll primes;
void sieve()
{
	rep(i,2,maxn)
	{
		if (spf[i]==0)
		{
			spf[i]=i;
			for(int j=2*i;j<=maxn;j+=i)
			{
				if(spf[j]==0)
					spf[j]=i;
			}
		}
	}
}
// void SieveOfEratosthenes(int n) 
// { 
//     bool prime[n+1]; 
//     memset(prime, true, sizeof(prime)); 
  
//     for (int p=2; p*p<=n; p++) 
//     { 
//         if (prime[p] == true) 
//         { 
//             for (int i=p*2; i<=n; i += p) 
//                 prime[i] = false; 
//         } 
//     }
//     for (int p=2; p<=n; p++) 
//       if (prime[p]) 
//           primes.pb(p); 
// } 
// bool isPrime(ll 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; 
// } 
// ll power(ll x,ll y)
// {
//     ll X=x;
//     //X=X%p;//if x is greater than p
//     if(X==0)
//     {
//         return 0;
//     }
//     ll res=1ll;
//     while(y>0)
//     {
//         if(y&1)
//         {
//             res=((res)*(X));
//             y--;
//         }
//         y=y>>1;
//         X=((X)*(X));
//     }
//     // res=(res>=0)?(res%p):(res+p)%p;
//     return(res);
// }
// void dfs(int u, int par){
//     cnt[u] = 1;
//     p[u] = par;
//     for(int i : g[u]){
//         if(i != par){
//             dfs(i,u);
//             cnt[u] += cnt[i];
//         }
//     }
// }
// int children(vll v[],int parent,int src,vll& chil)
// {
// 	int ans =0;
// 	for(auto it:v[src])
// 	{
// 		if(it!=parent)
// 		{
// 			ans+= 1+children(v,src,it,chil);
// 		}
// 	}
// 	chil[src] = ans;
// 	return ans;
 
// }
signed main() {
	//freopen("output.txt","w",stdout);
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	srand (static_cast <unsigned> (time(0)));
// 	SieveOfEratosthenes(300001); 
// 	sort(all(primes));
    //sieve();
	int t=1;
	//cin >> t;
	while (t--) 
	{
	    string s;
      cin >> s;
      ll tot=0;
      rep(i,0,s.length())
      {
        tot+=s[i]-'0';
      }
      if (tot%9==0)
        cout <<"Yes"<<endl;
      else
        cout <<"No"<<endl;
		
		
	}
	return 0;
}


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

#define FOR(i,l,r) for(int i = int(l);i < int(r);i++)
template<typename T> bool chmax(T& a,const T& b){ return a < b ? (a = b,true) : false; }
template<typename T> bool chmin(T& a,const T& b){ return b < a ? (a = b,true) : false; }
typedef long long ll;

int N,M,K;

int main()
{
	scanf("%d%d%d",&N,&M,&K);

	bool ans = false;
	FOR(i,0,N + 1) FOR(j,0,M + 1){
		ans |= i * j + (N - i) * (M - j) == K;
	}
	puts(ans ? "Yes" : "No");

	return 0;
}


Measured memory_bytes: 256
l = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
k = int(input())
print(l[k-1])

         

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

typedef long long ll;

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

int a[100005][3];
ll dp[100005][3];

int main() {
	int N;
	cin>>N;
	rep(i,N)cin>>a[i][0]>>a[i][1]>>a[i][2];

	//初期条件
	rep(j,3)dp[0][j] = a[0][j];
	
	//dp tableの初期値（今回は最大値を取り、0以下にはならないので0で良い）
	rep(i,N)rep(j,3)rep(k,3){
		if(j == k) continue;
		dp[i+1][k] = max(dp[i+1][k],dp[i][j] + a[i+1][k]);
	}
	ll ans = max(dp[N-1][0],dp[N-1][1]);
	ans = max(ans,dp[N-1][2]);
	cout<<ans<<endl;
}


Measured memory_bytes: 3712
#include <iostream>
#include <vector>
#include <unordered_map>
#include <map>
#include <algorithm>
#include <set>
#include <unordered_set>
#include <deque>
#include <cmath>
#include <stack>
#include <queue>

using namespace std;

int n, t, x;

int main(){
    vector<int> l;
    cin >> n;
    for(int i = 0; i < n; i++){
        cin >> x;
        l.push_back(x);
    }

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

    for(int i = 0; i < n-1; i++){
        t = t + l[i];
    }

    if(l[n-1] < t){
        cout << "Yes";
    } else {
        cout << "No";
    }


}

//g++ -std=c++14 comp.cpp; ./a.exe


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

int main() {
  int N;
  string S;
  cin >> N >> S;
  
  int k = S.size();
  
  if(k%2 != 0) cout << "No" << endl;
  else {
    for(int i = 0; i < k/2; i++) {
      if(S.at(i) != S.at(i + k/2)) {
        cout << "No" << endl;
        break;
      }
      else if(i == k/2 - 1) cout << "Yes" << endl;
    }
  }  
  
}

Measured memory_bytes: 3580
#include <bits/stdc++.h>
#define ALL(A) (A).begin(), (A).end()
#define ll long long
#define rep(i, n) for (int i = 0; i < (n); i++)

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

const ll mod = 1e9 + 7;
const ll INF = -1 * ((1LL << 63) + 1);
const int inf = -1 * ((1 << 31) + 1);

int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    int N;
    cin >> N;
    map<string,int> mp;
    rep(i,N){
        string s;
        cin >> s;
        mp[s]++;
    }
    int mx = 0;
    for(auto x:mp)mx = max(mx,x.second);
    vector<string> ans;
    for(auto x:mp)if(x.second==mx)ans.push_back(x.first);
    sort(ALL(ans));
    for(auto x:ans)cout << x << endl;
}

Measured memory_bytes: 25584
#include<iostream>
#include<vector>

using namespace std;

int main(){
	int INF = 1001001001;
	int N; cin >> N;
	vector<int> A(N, INF);
	vector<int> B(N-1); for(int i = 0; i < N-1; ++i) cin >> B[i];
	
	for(int i = 0; i < N-1; ++i){
		if(A[i] == INF or A[i] > B[i]) A[i] = B[i];
		if(A[i+1] == INF or A[i+1] > B[i]) A[i+1] = B[i];
	}

	int cnt = 0;
	for(int i = 0; i < N; ++i) cnt += A[i];

	cout << cnt << endl;

	return 0;
}


Measured memory_bytes: 256
n = int(input())
a, b = list(map(int, input().split()))
ppp = list(map(int, input().split()))
ans = [0, 0, 0]
for p in ppp:
    if p <= a:
        ans[0] += 1
    elif p <= b:
        ans[1] += 1
    else:
        ans[2] += 1
print(min(ans))


Measured memory_bytes: 3316
#include <bits/stdc++.h>
using namespace std;
int main(){
  int a,b;
  cin>>a>>b;
  int c,d,e;
  c = a+b;
  d = a-b;
  e = a*b;
  int ans = max({c,d,e});
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
	"sort"
	"strconv"
)

func getScanner(fp *os.File) *bufio.Scanner {
	scanner := bufio.NewScanner(fp)
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 500001), 500000)
	return scanner
}

func getNextString(scanner *bufio.Scanner) string {
	scanner.Scan()
	return scanner.Text()
}

func getNextInt(scanner *bufio.Scanner) int {
	i, _ := strconv.Atoi(getNextString(scanner))
	return i
}

func getNextInt64(scanner *bufio.Scanner) int64 {
	i, _ := strconv.ParseInt(getNextString(scanner), 10, 64)
	return i
}

func getNextUint64(scanner *bufio.Scanner) uint64 {
	i, _ := strconv.ParseUint(getNextString(scanner), 10, 64)
	return i
}

func getNextFloat64(scanner *bufio.Scanner) float64 {
	i, _ := strconv.ParseFloat(getNextString(scanner), 64)
	return i
}

func main() {
	fp := os.Stdin
	wfp := os.Stdout

	if os.Getenv("MASPY") == "ますピ" {
		fp, _ = os.Open(os.Getenv("BEET_THE_HARMONY_OF_PERFECT"))
	}
	if os.Getenv("MASPYPY") == "ますピッピ" {
		wfp, _ = os.Create(os.Getenv("NGTKANA_IS_GENIUS10"))
	}

	scanner := getScanner(fp)
	writer := bufio.NewWriter(wfp)

	n := getNextInt(scanner)
	pp := make(PP, n)
	for i := 0; i < n; i++ {
		pp[i].x = getNextFloat64(scanner)
		pp[i].y = getNextFloat64(scanner)
	}

	sort.Sort(pp)

	xx := make([]float64, n*2+1)
	yy := make([]float64, n*2+1)
	for i := 0; i < n*2; i++ {
		xx[i+1] = xx[i] + pp[i%n].x
		yy[i+1] = yy[i] + pp[i%n].y
	}

	max := 0.0
	for i := 0; i < n; i++ {
		for j := 1; j <= n; j++ {
			r := math.Sqrt(math.Pow(xx[i+j]-xx[i], 2) + math.Pow(yy[i+j]-yy[i], 2))
			if max < r {
				max = r
			}
		}
	}

	fmt.Fprintln(writer, max)
	writer.Flush()
}

// Point ...
type Point struct {
	x, y float64
}

func (p Point) cross(other *Point) float64 {
	return p.x*other.y - p.y*other.x
}

func (p Point) orthant() int {
	if p.x > 0 && p.y >= 0 {
		return 1
	}
	if p.x <= 0 && p.y > 0 {
		return 2
	}
	if p.x < 0 && p.y <= 0 {
		return 3
	}
	return 4
}

func (p Point) compare(other Point) bool {
	if p.orthant() == other.orthant() {
		return p.cross(&other) > 0
	}
	return p.orthant() < other.orthant()
}

type PP []Point

func (a PP) Len() int           { return len(a) }
func (a PP) Swap(i, j int)      { a[i], a[j] = a[j], a[i] }
func (a PP) Less(i, j int) bool { return a[i].compare(a[j]) }


Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <deque>
#include <map>
#include <set>
#include <complex>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <chrono>

#define ft first
#define sc second
#define pb push_back
#define len(v) (int)v.size()
// #define int ll

using namespace std;
typedef long long ll;
typedef long double ld;


signed main() {
	#ifdef PC
		freopen("in.txt", "r", stdin);
		freopen("out.txt", "w", stdout);
	#endif	
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	

	int n;
	cin >> n;
	vector<int> a(2 * n, 0);
	for (int i = 0; i < 2 * n; i++) {
		cin >> a[i];
	}
	sort(a.begin(), a.end());
	int ans = 0;
	for (int i = 0; i < 2 * n; i += 2) {
		ans += a[i];
	}
	cout << ans << endl;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
#include <string> 
using namespace std;
int main()
{
  string mojiS,mojiT,mojiU;
  int A,B;
  cin>>mojiS>>mojiT>>A>>B>>mojiU;
  if(mojiS==mojiU){
    cout<<A-1<<" "<<B;
  }else{
    cout<<A<<" "<<B-1;
  }
  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(){
    char a[10], b[10], c[10];
    int i=0, j=0;

    scanf("%s %s %s", a, b, c);

    while(a[i] != '\0'){
        i++;
    }

    while(b[j] != '\0'){
        j++;
    }

    if(a[i-1] == b[0] && b[j-1] == c[0])
        printf("YES\n");
    else
        printf("NO\n");
    
    return 0;
}

Measured memory_bytes: 128
#include<iostream>
#include<iomanip>
#include<string>
#include<set>
#include<vector>
#include<utility>
#include<queue>
#include<algorithm>
#include<functional>
using namespace std;
#define LL long long
#define MOD 100000
#define inf 1999999999
#define ALL(x) (x).begin(), (x).end()
#define LBi(x, n) lower_bound(ALL(x), n) - (x).begin()
#define ZIP(x) (x).erase(unique(ALL(x)), (x).end())
#define Pi pair<int, int>
#define Vi vector<int>

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

string s = "";
char ch[10];
int n, a, b, c, d, x, m[5];

int main() {
	cin >> a >> b >> c >> d;
	if (a + b == c + d) cout << "Balanced" << endl;
	else cout << (a + b > c + d ? "Left" : "Right") << endl;
	return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

    private static int MOD = 1_000_000_007;

    public static void main(String[] args) {
        final Scanner scanner = new Scanner(System.in);
        solve(scanner);
    }


    // int N = Integer.parseInt(scanner.nextLine());
    // int N = scanner.nextInt(), M = scanner.nextInt();
    // scanner.nextLine();
    // int[] n = Arrays.stream(scanner.nextLine().split(" ")).mapToInt(Integer::parseInt).toArray();
    static void solve(Scanner scanner) {
        int N = Integer.parseInt(scanner.nextLine());
        // 0: Null, 1: A, 2: G, 3: C, 4: T
        long[][][][] dp = new long[N + 1][5][5][5];
        dp[0][0][0][0] = 1;
        for (int i = 1; i <= N; i++) {
            for (int j = 0; j <= 4; j++) {
                for (int k = 0; k <= 4; k++) {
                    for (int l = 0; l <= 4; l++) {
                        for (int m = 1; m <= 4; m++) {
                            // AGC, ACG, GAC, A*GC, AG*C
                            if ((k == 1 && l == 2 && m == 3)
                                    || (k == 1 && l == 3 && m == 2)
                                    || (k == 2 && l == 1 && m == 3)
                                    || (j == 1 && l == 2 && m == 3)
                                    || (j == 1 && k == 2 && m == 3)) {
                                continue;
                            }
                            dp[i][k][l][m] += dp[i - 1][j][k][l];
                            dp[i][k][l][m] %= MOD;
                        }

                    }
                }
            }
        }
        long ans = 0;
        for (int i = 0; i <= 4; i++) {
            for (int j = 0; j <= 4; j++) {
                for (int k = 0; k <= 4; k++) {
                    ans += dp[N][i][j][k];
                    ans %= MOD;
                }
            }
        }
        System.out.println(ans);
    }

}


Measured memory_bytes: 21844
#include<stdio.h>
#define MAX 10000
#define NIL -1

struct Node{
  int p, l, r;
};

struct Node T[MAX];
int n;

void preParse(int u){
  if ( u == NIL ) return;
  printf(" %d", u);
  preParse(T[u].l);
  preParse(T[u].r);
}
void inParse(int u){
  if ( u == NIL ) return;
  inParse(T[u].l);
  printf(" %d", u);
  inParse(T[u].r);
}
void postParse(int u){
  if ( u == NIL ) return;
  postParse(T[u].l);
  postParse(T[u].r);
  printf(" %d", u);
}

main(){
  int i, v, l, r, root;
  scanf("%d", &n);
  for ( i = 0; i < n; i++ ) {
    T[i].p = NIL;
  }

  for ( i = 0; i < n; i++ ){
    scanf("%d %d %d", &v, &l, &r);
    T[v].l = l;
    T[v].r = r;
    if ( l != NIL ) T[l].p = v;
    if ( r != NIL ) T[r].p = v;
  }

  for ( i = 0; i < n; i++ ) if ( T[i].p == NIL ) root = i;
  printf("Preorder\n");
  preParse(root);
  printf("\n");
  printf("Inorder\n");
  inParse(root);
  printf("\n");
  printf("Postorder\n");
  postParse(root);
  printf("\n");

  return 0;
}



Measured memory_bytes: 2112
import java.util.Scanner;
public class Main{
public static void main(String[] args) {
// 標準入力からデータを読み込む準備
try (Scanner sc = new Scanner(System.in)) {
 String line = sc.nextLine();

 int length = line.length();
  for (int i = 0; i < length; i++) {
    char ch=line.charAt(i);
    if('a' <= ch && ch <= 'z') {
    System.out.print((char)(ch - 32));
  } else if('A' <= ch && ch <= 'Z') {
    System.out.print((char)(ch + 32));
}else{
  System.out.print(ch);
}


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



Measured memory_bytes: 26952
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;
const double PI = acos(-1);
inline void chmax(ll& a, ll b){
  a =max(a,b);
}
const ll INF=1e18;
const int MX=2005;
ll dp[MX][MX];

int main(){
  int n;
  cin >>n;
  vector<int> a(n);
  rep(i,n) cin >>a[i];
  rep(i,n+1)rep(j,n+1) dp[i][j] = -INF;
  dp[0][0]=0;
  vector<P> p;
  rep(i,n) p.emplace_back(a[i],i);
  sort(p.rbegin(),p.rend());
  rep(i,n){
    int pi =p[i].second;
    rep(l,i+1){
      int r= i-l;
      chmax(dp[i+1][l+1],dp[i][l]+ll(pi-l)*a[pi]);
      chmax(dp[i+1][l],dp[i][l]+ll((n-r-1)-pi)*a[pi]);
    }
  }
  ll ans =0;
  rep(i,n+1) chmax(ans,dp[n][i]);
  cout <<ans <<endl;
  return 0;
}


Measured memory_bytes: 34988
#include<stdio.h>

int main(){

	int a,b;

	scanf("%d %d",&a,&b);

	if(a<b){
		printf("a < b\n");
	}else if(a>b){
		printf("a > b\n");
	}else if(a==b){
		printf("a == b\n");
	}

	return 0;

}

Measured memory_bytes: 2580
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
 int main() {
int N,p,w,g,y;
   cin >> N;
   y=0;
   rep (i,N) {
string x;
     cin >> x;
     if(x == "Y"){
    y= y+1;
     break;
     }
}
   if(y==0){
     cout << "Three";
   }else{
     cout << "Four";
        }
   
   
   
   
   
   
   
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void){
    long long q,h,s,d,n,ans;
    cin >> q >> h >> s >> d >> n;
    h = min(2*q,h);
    s = min(2*h,s);
    if(n % 2 == 0){
        if(2*s <= d) ans = n*s;
        else ans = (n/2)*d;
    }else{
        if(2*s <= d) ans = n*s;
        else ans = (n/2)*d+s;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define  rep(i, n) for(int i = 0; i < n; i++) 
#define  all(x) (x).begin(),(x).end()     // 昇順ソート
#define  rall(v) (v).rbegin(), (v).rend() // 降順ソート
#define  INF 1LL << 60
typedef long long int LL;
typedef long long int ll;
#define pll pair<ll, ll>
#define F first
#define S second
const int MOD = 1000000007;
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; }
//sort(all(x))とするとソートできるよ
// 10^x は pow(10,(x)) 
// 任意のlogは　対数の底の変換を使う    log(N) / log(任意の底)

int main(){
    int N;cin >> N;
    vector<LL> a(N);rep(i,N)cin >> a[i];

    vector<LL> rui(N+1);rui[0] = 0;
    rep(i,N){
        rui[i+1] = rui[i] + a[i];
    }



    LL ans = INF;
    rep(i,N){
        if(i == 0)continue;
        LL tmp = abs(rui[N]- 2*rui[i]);

        ans = min(ans,tmp);
    }

    cout << ans << endl;
}


Measured memory_bytes: 3328
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx")
#pragma GCC optimize("unroll-loops")
//#pragma warning(disable : 4996)

#ifdef _MSC_VER
#include <intrin.h>
#define __builtin_popcount __popcnt
#endif

#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<cassert>
#include<iterator>
#include<complex>
#include<stack>
#include<unordered_map>
#include<unordered_set>
#include<time.h>
#include<random>
#include<array>


using namespace std;

#define REP(i, n) for(int i = 0;i < (n);++i)
#define REPR(i, n) for(int i = n-1;i >= 0;--i)
#define FOR(i, m, n) for(int i = m;i < n;++i)
#define FORR(i, m, n) for(int i = m-1;i >= n;--i)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define REVERSE(v,n) reverse(v,v+n);
#define VREVERSE(v) reverse(v.begin(), v.end())
#define ll long long
#define print(x) cout<<(x)<<'\n'
#define pe(x) cout<<(x)<<" "
#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define lb(v,n) lower_bound(v.begin(), v.end(), (n))
#define ub(v,n) upper_bound(v.begin(), v.end(), (n))
#define int long long
//#define double long double
#define all(x) (x).begin(), (x).end()
#define print_space(v) REP(i,v.size())cout << v[i] << ((i == v.size() - 1) ? "\n" : " ")
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; }
typedef pair<int, int>pii;
typedef array<int, 3> arr3;
std::random_device rd;
std::mt19937 mt(rd());
constexpr ll MOD = 1e9 + 7; constexpr int MAX = 200020;
const double pi = acos(-1); constexpr double EPS = 1e-8;
constexpr ll INF = 1e16;
void yes(bool c) { if (c)print("Yes"); else print("No"); };


int H[200020];
int N, M;
vector<int>G[200020];
void solve() {
	string S; cin >> S;
	if (S == "ABC")print("ARC");
	else print("ABC");
}
signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	//int q; cin >> q;
	//while (q--)
	solve();
}



Measured memory_bytes: 8344
#include<iostream>
#include<algorithm>
#include<iomanip>
#include<string>
#include<vector>

typedef unsigned long long ULL;
typedef long long LL;

using namespace std;

template<class T> void swap(T &a, T &b ){
    T temp;
    temp = a;
    a = b;
    b = temp;   
}

int main(){
    int N;
    string s;
    int count;
    int i;
    cin >> N;
    cin >> s;

    count = 1;
    for(i=1;i<N;i++){
        if( s[i] != s[i-1]){
            count++;
        }
    }

    cout << count << endl;
    return 0;
}


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

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

	set<string> dic;

	for (int i = 0; i < n; i++) 
	{
		string buf1, buf2;
		cin >> buf1 >> buf2;

		if (buf1 == "insert") 
		{
			dic.insert(buf2);
		}
		else
		{
			if (dic.find(buf2) != dic.end()) 
			{
				cout << "yes" << endl;
			}
			else 
			{
				cout << "no" << endl;
			}
		}
	}
}

Measured memory_bytes: 32092
#include<stdio.h>

int search(int);
int s[100000],s_num;

int main(){
  
  int t,i,j,t_num,start,end,mid,count=0;
  
  scanf("%d",&s_num);
  for(i = 0; i < s_num; i++){
    scanf("%d",&s[i]);
  }
  scanf("%d",&t_num);
  for(i = 0; i < t_num; i++){
    scanf("%d",&t);
    if(search(t) == 1)count++;
  }
  

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

int search(int key){

  int start=0,end=s_num,mid;
  
  while(start < end){
    mid = (start+end)/2;
      if(key == s[mid])return 1;
      else if(key > s[mid]){
	start = mid + 1;
      }
      else{
	end = mid;
      }
  }
  return 0;
}

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

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

  ll N; cin >> N;
  string ans = "";
  while (true) {
    N--;
    ll d = N % 26;
    char x = (N % 26) + 'a';
    ans = x + ans;
    N /= 26;
    if (N == 0) break;
  }
  cout << ans << '\n';
  return 0;
}

Measured memory_bytes: 3652
#include "bits/stdc++.h"
#define PRECISION(x) cout << fixed << setprecision(x)
#define FAST_IO ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define SZ(X) ((int)(X).size())
#define ALL(X) (X).begin(), (X).end()
#define ALLR(X) (X).rbegin(), (X).rend()
#define MP make_pair
#define PB push_back
#define EB emplace_back
#define F first
#define S second

using namespace std;

template<class T> void max_self(T & a, const T & b) { if(a < b) a = b; }
template<class T> void min_self(T & a, const T & b) { if(a > b) a = b; }
typedef long long LL;
const int INF = 1e9 + 7;
const double PI = acos(-1.0);
const double EPS = (1e-9);


int main(){
  FAST_IO  

  int N, cnt = 0;
  set<pair<int, int>> red;
  vector<pair<int, int>> pts;
  vector<int> greedy;

  cin >> N;

  for(int rep = 0, x, y; rep < N; ++rep){
    cin >> x >> y;
    pts.EB(x, y);
    red.insert({x, y});
  }

  for(int rep = 0, x, y; rep < N; ++rep){
    cin >> x >> y;
    pts.EB(x, y);
  }

  sort(ALL(pts));

//  cout << "----------------------------\n";
//  for(auto ele : pts) cout << ele.F << "  " << ele.S << "\n";
//  cout << "-----------------------------\n";
//  for(auto ele : red) cout << ele.F << "  " << ele.S << "\n";
//  cout << "-----------------------------\n";

  for(auto ele : pts){
    if(red.count(ele)){
//      cout << ele.F << "  " << ele.S << "\n";
      greedy.PB(ele.S);
      continue;
    }
    int del = -1;
    for(int idx = 0, maxY = -1; idx < SZ(greedy); ++idx){
      if(greedy[idx] < ele.S && greedy[idx] > maxY){
        maxY = greedy[idx];
        del = idx;
      }
    }

    if(del != -1){
      cnt++;
      greedy.erase(greedy.begin() + del);
    }
  }

//  cout << "----------------------------\n";
  cout << cnt << "\n";
  return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;

class Program
{
	static void Main()
	{
		var nm = Array.ConvertAll(Console.ReadLine().Split(new[] { ' ' }), number => int.Parse(number));
		var n = nm[0];
		var m = nm[1];

		var edges = Enumerable.Range(0, m).Select(_ => {
			var ab = Array.ConvertAll(Console.ReadLine().Split(new[] { ' ' }), number => int.Parse(number));
			return new {
				StartVertex = ab[0],
				EndVertex = ab[1],
			};
		}).ToArray();

		var answer = 0;
		for (var i = 0; i < edges.Length; ++i) {
			var currentEdges = edges.ToList();
			currentEdges.RemoveAt(i);

			var isArrived = new bool[n];
			var searchingVertexes = new Queue<int>(new[] { currentEdges[0].StartVertex });
			while (searchingVertexes.Count > 0) {
				var currentVertex = searchingVertexes.Dequeue();
				if (!isArrived[currentVertex - 1]) {
					isArrived[currentVertex - 1] = true;

					foreach (var edge in currentEdges) {
						if (edge.StartVertex == currentVertex && !isArrived[edge.EndVertex - 1]) {
							searchingVertexes.Enqueue(edge.EndVertex);
						} else if (edge.EndVertex == currentVertex && !isArrived[edge.StartVertex - 1]) {
							searchingVertexes.Enqueue(edge.StartVertex);
						}
					}
				}
			}

			if (isArrived.Contains(false)) {
				++answer;
			}
		}

		Console.WriteLine(answer);
	}
}


Measured memory_bytes: 13652
import java.io.*;

class Main{
public static void main(String[] args) throws IOException{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
String line="";
while((line=br.readLine())!=null){
int[] num=new int[10];
boolean flag=false;
String ans="0";
for(int i=0;i<13;i++){
num[(int)(line.charAt(i)-'0')]++;
}
outside: for(int i=1;i<=9;i++){
         if(num[i]==4){
         continue;
         }
         for(int j=1;j<=9;j++){
         int[] n=num.clone();
         n[i]++;
         if(n[j]<2){
         continue;
         }
         n[j]-=2;
         if(check(n)){
         if(!flag){
         System.out.print(i);
         ans="";
         flag=true;
         }
         else{
         System.out.print(" "+i);
         }
         continue outside;
         }
         }
         }
System.out.println(ans);
}
}
private static boolean check(int[] n){
int amari=0;
for(int i=1;i<=7;i++){
if(n[i]<0){
return false;
}
amari=n[i]%3;
n[i]-=amari;
n[i+1]-=amari;
n[i+2]-=amari;
}
if((n[8]==3||n[8]==0)&&(n[9]==3||n[9]==0)){
return true;
}
return false;
}
}

Measured memory_bytes: 15084
import java.util.Scanner;
import java.util.List;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
	int a = sc.nextInt();
    int b = sc.nextInt();
    int c = sc.nextInt();
    int d = sc.nextInt();
    if (a+b>c+d) {
      System.out.println("Left");
    } else if (a+b<c+d) {
      System.out.println("Right");
    } else {
      System.out.println("Balanced");
    }
  }
}

Measured memory_bytes: 23892
#include <vector>
#include <iostream>
#include <cmath>
#include <map>
#include <unordered_map>
#include <algorithm>
#include <fstream>
#include <unistd.h>
#include <string>
#include <numeric>
#include <queue>
#include <deque>
#include <sstream>
#include <iomanip>
#include <set>
#include <stack>
#include <cassert>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<vvl> vvvl;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<bool> vb;
typedef vector<vector<bool>> vvb;
typedef vector<string> vs;
typedef vector<vector<string>> vvs;
typedef vector<char> vc;
typedef vector<vector<char>> vvc;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<vvd> vvvd;
typedef pair<int, int> P;
typedef pair<ll, ll> PL;
typedef vector<P> vp;
typedef vector<PL> vpl;
typedef vector<vector<P>> vvp;
typedef vector<vector<PL>> vvpl;
const int INF = 1001001001;
const ll LINF = 1e16;
const double pi = 3.1415926535897932;
const string endstr = "\n";
#define FOR(i, a, b) for(ll i = (a); i < b; i++)
#define REP(i, n) for(ll i = 0; i < n; i++)
#define FORMAP(it, m) for(auto it = m.begin(); it != m.end(); it++)
#define ff first
#define ss second
#define pb push_back

template <typename T>
T gcd(T a, T b) {
    return (a == 0) ? b : gcd(b%a, a);
}
template <typename T>
T lcm(T a, T b) {
    return a / gcd(a, b) * b;
}

bool p_comp_fs(const PL p1, const PL p2){ return p1.first < p2.first;};
bool p_comp_fg(const PL p1, const PL p2){ return p1.first > p2.first;};
bool p_comp_ss(const PL p1, const PL p2){ return p1.second < p2.second;};
bool p_comp_sg(const PL p1, const PL p2){ return p1.second > p2.second;};
template <typename T>
vector<T> uniquen(vector<T> vec){
    vec.erase(unique(vec.begin(), vec.end()), vec.end());
    return vec;
}


int main(){
    ll N; cin >> N;
    vl b(N); REP(i, N) {cin >> b[i]; b[i]--;};
    vl ans;
    REP(i, N){
        ll idx = -1;
        REP(j, b.size()){
            if(b[j] == j) idx = j;
        }
        if(idx == -1){
            cout << -1 << endl; return 0;
        }
        ans.pb(idx);
        b.erase(b.begin()+idx);
    }
    reverse(ans.begin(), ans.end());
    REP(i, N){
        cout << ans[i]+1 << endl;
    }
    return 0;
}


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

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

constexpr int MAX_N = 100 + 7;
constexpr int MAX_V = 1e3;
constexpr int INF = 1e9 + 7;

int w[MAX_N], v[MAX_N];
int dp[MAX_N][MAX_V * MAX_N];

int main() {
  int N, W;
  cin >> N >> W;
  for (int i{1}; i <= N; ++i) {
    cin >> w[i] >> v[i];
  }

  fill(dp[0], dp[0] + MAX_N * (MAX_V * MAX_N), INF);
  dp[0][0] = 0;
  for (int i{1}; i <= N; ++i) {
    for (int j{}; j <= MAX_V * N; ++j) {
      if (j >= v[i])
        chmin(dp[i][j], dp[i - 1][j - v[i]] + w[i]);
      chmin(dp[i][j], dp[i - 1][j]);
    }
  }

  for (int j{MAX_V * N}; j >= 0; --j) {
    if (dp[N][j] <= W) {
      cout << j << endl;
      break;
    }
  }
  return 0;
}


Measured memory_bytes: 44928
use std::io;

fn main() {
    let mut s = String::new();
    io::stdin().read_line(&mut s).unwrap();
    let v: Vec<i32> = s.trim().split_whitespace().map(|x| x.parse().unwrap()).collect();
    println!("{}", if v[1] - v[0] == v[2] - v[1] { "YES" } else { "NO" });
}


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

#ifndef ONLINE_JUDGE
	bool debug = true;
#endif

typedef long long unsigned llu;
typedef long long lld;
typedef long ld;

#define N 100005
int a[N], dp[N];

int main()
{
	ios_base::sync_with_stdio(false); cin.tie(NULL);
	int i, n;
	cin >> n;
	for(i = 1 ; i <= n ; i++)
		cin >> a[i];
	dp[1] = 0;
	dp[2] = abs(a[1] - a[2]);
	for(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] << endl;
    return 0;
}


Measured memory_bytes: 1024
#include "bits/stdc++.h"
using namespace std;
int main()
{

    //freopen("input.txt", "r", stdin);
    int n;
    cin >> n;
    vector<vector<int>> v(n, vector<int>(3));
    for (int i = 0; i < n; i++)
    {
        cin >> v[i][0] >> v[i][1] >> v[i][2];
    }
    vector<vector<int>> dp(n, vector<int>(3));
    dp[0][0] = v[0][0];
    dp[0][1] = v[0][1];
    dp[0][2] = v[0][2];
    for (int i = 1; i < n; i++)
    {
        dp[i][0] = max(dp[i - 1][1], dp[i - 1][2]) + v[i][0];
        dp[i][1] = max(dp[i - 1][0], dp[i - 1][2]) + v[i][1];
        dp[i][2] = max(dp[i - 1][0], dp[i - 1][1]) + v[i][2];
    }
    cout << max(dp[n - 1][0], max(dp[n - 1][1], dp[n - 1][2])) << endl;
    return 0;
}

Measured memory_bytes: 11136
N, M = map(int,input().split())
lst=[None]*M
for i in range(M):
    p, S=input().split()
    lst[i]=(int(p), S)

stop_set=set()

WA_count=0
AC_count=0
from collections import defaultdict
WA_dict = defaultdict(lambda: 0)

for el in lst:
    if not el[0] in stop_set:
        if el[1]=='AC':
            AC_count+=1
            stop_set.add(el[0])
        else:
            WA_dict[el[0]] +=1
#print(dict(WA_dict))

new_set=set(WA_dict.keys())&stop_set
#print(new_set)
WA_count=sum([WA_dict[i] for i in new_set])
print(AC_count, WA_count)


Measured memory_bytes: 25416
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> ii;
typedef vector<ii> vii;
const int mod = 1e9+7;

ll dp[2005];
ll f(int s){
    if(s==0) return 1;
    if(s==1 || s==2) return 0;
    if(s==3 || s==4 ||s==5) return 1;
    if(dp[s]!=-1) return dp[s];
    else {
        ll total=0;
        for(int i=3;i<=s;i++){
            total+= f(s-i),total%=mod;
        }
        return dp[s] = total;
    }
}

main(){
    int s;cin>>s;
    memset(dp,-1,sizeof(dp));
    cout<<f(s);
}

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

using ll = long long;
#define ALL(c) (c).begin(), (c).end()
const int MOD = 1000000007;

int main() {
    int n;
    cin >> n;
    vector<ll> takahashi(n);
    ll aoki = 0;
    ll a, b;
    for (int i = 0; i < n; i++) {
        cin >> a >> b;
        takahashi.emplace_back(a + b);
        aoki += b;
    }
    sort(ALL(takahashi), greater<ll>());

    ll total = 0;
    for (int i = 0; i < n; i += 2) {
        total += takahashi[i];
    }

    cout << total - aoki << endl;
}


Measured memory_bytes: 1792
#include<bits/stdc++.h>
#define rep(i,n,m) for(int i = (n); i <(m); i++)
#define rrep(i,n,m) for(int i = (n) - 1; i >=(m); i--)
using namespace std;
using ll = long long;

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

    vector<int> wsum(n + 1), esum(n + 1);
    wsum[0] = esum[0] = 0;
    rep(i, 0, s.size())
    {
        wsum[i + 1] = wsum[i] + int(s[i] == 'W');
        esum[i + 1] = esum[i] + int(s[i] == 'E');
    }
    
    int cnt = s.size();
    rep(i, 0, s.size())
    {
        int c = 0;
        c += wsum[i] - wsum[0];
        c += esum[n] - esum[i + 1];
        cnt = min(c, cnt);
    }
    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 3076
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
template<typename T> using Graph = vector<vector<T>>;

#define REP(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, a) REP(i, 0, a)
#define EACH(i, a) for (auto i: a)
#define ITR(x, a) for (__typeof(a.begin()) x = a.begin(); x != a.end(); x++)
#define ALL(a) (a.begin()), (a.end())
#define HAS(a, x) (a.find(x) != a.end())
#define endl '\n'

int N, M;
int a[100005], b[100005];
int cnt[100005];

int main(void) {
  cin.tie(0);
  ios::sync_with_stdio(false);
  // breath deeply and calm down

  cin >> N >> M;
  rep(i, M) cin >> a[i] >> b[i];
  rep(i, M) {
    a[i]--, b[i]--;
    if (a[i] > b[i]) swap(a[i], b[i]);
  }

  rep(i, M) {
    cnt[a[i]]++;
    cnt[b[i]]++;
  }

  bool ans = true;
  REP(i, 1, N) ans &= cnt[i]%2 == 0;

  cout << (ans ? "YES":"NO") << endl;
  return 0;
}


Measured memory_bytes: 1408
//============================================================================
// Name        : AOJ.cpp
// Author      :
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <iostream>
#include <string>
using namespace std;
string s;
int main() {

	cin>>s;
	int ans=0;
	int a0,a1,a2,a3;

	for(a0=0;a0<s.size();a0=a3){
		for(a1=a0;s[a1]=='J';a1++);
		for(a2=a1;s[a2]=='O';a2++);
		for(a3=a2;s[a3]=='I';a3++);
		if(a1-a0>=a2-a1&&a2-a1<=a3-a2)ans=max(ans,a2-a1);

	}



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

Measured memory_bytes: 3992
h,w = map(int,input().split())
board = [input() for _ in range(h)]
skipi = set()
skipj = set()
for i in range(h):
  if not "#" in board[i]:
    skipi.add(i)
for j in range(w):
  cnt = 0
  for i in range(h):
    if board[i][j] == ".":
      cnt += 1
    if cnt == h:
      skipj.add(j)
for i in range(h):
  line = ""
  if i in skipi:
    continue
  for j in range(w):
    if j in skipj:
      continue
    line += board[i][j]
  print(line)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using pint = pair<int,  int>;
using pll = pair<ll, ll>;
using edge = pair<int, ll>;
using Graph = vector<vector<int>>; 
using WeightedGraph = vector<vector<edge>>;
const ll INF = 1LL << 60;
const int INF32 = 1 << 29;
const ll MOD = 1000000007;

int main(){
int n; cin >> n;
cout << n*(n+1)/2 << endl;
}


Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#define _USE_MATH_DEFINES
#include "bits/stdc++.h"

using namespace std;

using u8 = uint8_t;
using u16 = uint16_t;
using u32 = uint32_t;
using u64 = uint64_t;
using i8 = int8_t;
using i32 = int32_t;
using i64 = int64_t;
constexpr char newl = '\n';

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; }
#define FOR(i,a,b) for (int i = (a); i < (b); i++)
#define F0R(i,b) FOR(i,0,b)
#define RFO(i,a,b) for (int i = ((b)-1); i >=(a); i--)
#define RF0(i,b) RFO(i,0,b)
//#define F first
//#define S second
#define debug(x) cout << #x << ": " << x << '\n';
template<class T> void Print(vector<T> v) {
  F0R(i, v.size()) {
    cout << v[i] << ' ';
  }
  cout << newl;
}

#if 1


// INSERT ABOVE HERE
signed main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);

  int N;
  cin >> N;
  cout << ((N + 1) / 2);
}
#endif


Measured memory_bytes: 256
import numpy as np
if __name__ == "__main__":
    # 入力パターン．
    # 要素の数がわかっているパターン
    ### a,b
    a_hp, a_at, b_hp, b_at = map(int, input().split())
    ans = ''
    # print(a_hp)
    # print(a_at)
    # print(b_hp)
    # print(b_at)
    while True:
        b_hp -= a_at
        #print(b_hp)
        if b_hp <= 0:
            ans = 'Yes'
            break
        a_hp -= b_at
        #print(a_hp)
        if a_hp <= 0:
            ans = 'No'
            break
    
    print(ans)



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

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

using namespace std;

int main() {
  string s;
  std::cin >> s;

  bool ok = false;
  while (!ok) {
    s.pop_back();
    int n = s.size();
    if (n % 2 != 0) {
      continue;
    }
    if (s.substr(0, n / 2) == s.substr(n / 2, n / 2)) {
      ok = true;
    }
  }

  std::cout << s.size() << std::endl;
  return 0;
}


Measured memory_bytes: 3608
use std::io::*;
use std::str::FromStr;
use std::cmp::{min, max};

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin_lock = stdin.lock();
    let s = stdin_lock
        .bytes()
        .map(|c| c.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect::<String>();
    s.parse::<T>().ok().unwrap()
}

fn main() {
    let s = read::<String>();

    println!("{}", s.replace("2017", "2018"));
}

Measured memory_bytes: 4352