akhauriyash/Code-Regression huggingface dataset:
public class Main {

  private static void solve() {
    int x = ni();
    int n = ni();
    int[] p = na(n);

    int min = Integer.MAX_VALUE;
    int minval = Integer.MAX_VALUE;
    outer: for (int i = -1000; i < 1000; i++) {
      for (int v : p) {
        if (v == i)
          continue outer;
      }

      if (Math.abs(x - i) < min) {
        min = Math.abs(x - i);
        minval = i;
      }
    }
    System.out.println(minval);

  }

  public static void main(String[] args) {
    new Thread(null, new Runnable() {
      @Override
      public void run() {
        long start = System.currentTimeMillis();
        String debug = args.length > 0 ? args[0] : null;
        if (debug != null) {
          try {
            is = java.nio.file.Files.newInputStream(java.nio.file.Paths.get(debug));
          } catch (Exception e) {
            throw new RuntimeException(e);
          }
        }
        reader = new java.io.BufferedReader(new java.io.InputStreamReader(is), 32768);
        solve();
        out.flush();
        tr((System.currentTimeMillis() - start) + "ms");
      }
    }, "", 64000000).start();
  }

  private static java.io.InputStream is = System.in;
  private static java.io.PrintWriter out = new java.io.PrintWriter(System.out);
  private static java.util.StringTokenizer tokenizer = null;
  private static java.io.BufferedReader reader;

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

  private static double nd() {
    return Double.parseDouble(next());
  }

  private static long nl() {
    return Long.parseLong(next());
  }

  private static int[] na(int n) {
    int[] a = new int[n];
    for (int i = 0; i < n; i++)
      a[i] = ni();
    return a;
  }

  private static char[] ns() {
    return next().toCharArray();
  }

  private static long[] nal(int n) {
    long[] a = new long[n];
    for (int i = 0; i < n; i++)
      a[i] = nl();
    return a;
  }

  private static int[][] ntable(int n, int m) {
    int[][] table = new int[n][m];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        table[i][j] = ni();
      }
    }
    return table;
  }

  private static int[][] nlist(int n, int m) {
    int[][] table = new int[m][n];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        table[j][i] = ni();
      }
    }
    return table;
  }

  private static int ni() {
    return Integer.parseInt(next());
  }

  private static void tr(Object... o) {
    if (is != System.in)
      System.out.println(java.util.Arrays.deepToString(o));
  }
}


Measured memory_bytes: 36936
#include<iostream>
#include<string>
#include<math.h>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<map>
#define rep(i,n) for(int i=0;i<n;++i)
#define yes cout<<"Yes"<<endl
#define no cout<<"No"<<endl
#define mod 1000000007
using namespace std;
using ll = long long;
int main() {
	ll X, Y;	cin >> X >> Y;
	ll num = X * 2;
	int ans = 1;
	while (num <= Y) {
		if (num <= Y) {
			++ans;
		}
		num *= 2;
	}
	cout << ans << endl;
	cin >> X;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
 
#define pb push_back
#define ll long long
#define maxn 300005
#define fr(i,j,k) for(int i=j;i<k;i++)
#define f(n) fr(i,0,n)
#define f1(n) fr(i,1,n+1)
#define ms(i) memset(i,0,sizeof(i));
#define ms1(i) memset(i,-1,sizeof(i));
#define F first
#define S second
#define all(x) x.begin(), x.end()
const int mod = 1e9+7;

int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	ll a;
	cin >> a;
	string b;
	cin >> b;
	ll B = 0;
	for (auto &i : b) {
		if (i == '.')continue;
		B *= 10;
		B += i - '0';
	}
	cout << a * B / 100 << '\n';
}


Measured memory_bytes: 3652
use std::str::FromStr;

fn get_one<T : FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    return s.trim().parse().ok().unwrap();
}

fn get_vec<T : FromStr>() -> Vec<T> {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    return s.trim().split_whitespace().map(|e| e.parse().ok().unwrap()).collect();
}

fn main() {
    let mut abc : Vec<Vec<char>> = Vec::new();
    let a : Vec<char> = get_one::<String>().chars().collect();
    let b : Vec<char> = get_one::<String>().chars().collect();
    let c : Vec<char> = get_one::<String>().chars().collect();
    abc.push(a);
    abc.push(b);
    abc.push(c);
    let mut inds : Vec<usize> = vec!(0;3);
    let mut cur = 0;
    let mut ans = None;
    loop {
        if inds[cur] >= abc[cur].len() {
            ans = Some(cur);
            break;
        }
        //println!("{}", cur);
        let prev = cur;
        let c = abc[cur][inds[cur]];
        if c == 'a' {
            cur = 0;
        } else if c == 'b' {
            cur = 1;
        } else if c == 'c' {
            cur = 2;
        }
        inds[prev] += 1;
    }
    if ans.unwrap() == 0 {
        println!("{}", "A");
    } else if ans.unwrap() == 1 {
        println!("{}", "B");
    } else {
        println!("{}", "C");
    }
}


Measured memory_bytes: 4352
while True:
    n , x = [int(x) for x in input().split()]
    if (n , x)==(0 , 0):
        break
    ans = 0
    for a in range(1,n-1):
        for b in range(a+1,n):
            for c in range(b+1,n+1):
                if a + b + c == x:
                    ans += 1
    print(ans)


Measured memory_bytes: 5600
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1000000000000000000
#define MOD 1000000007
typedef pair<int, int> P;

bool prime(int n) {
	for (int i = 2; i <= sqrt(n); i++) {
		if (n % i == 0)return false;
	}
	return n != 1;
}
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x % y);
}
int lcm(int x, int y) {
	return x / gcd(x, y) * y;
}
int mod_pow(int n, int p, int m) {
	if (p == 0) return 1;
	if (p % 2 == 0) {
		int t = mod_pow(n, p / 2, m);
		return (t * t) % m;
	}
	return n * mod_pow(n, p - 1, m) % m;
}
int extGCD(int a, int b, int& x, int& y) {
	if (b == 0) {
		x = 1;
		y = 0;
		return a;
	}
	long long d = extGCD(b, a % b, y, x);
	y -= a / b * x;
	return d;
}
int modinv(int a, int m) {
	int b = m, u = 1, v = 0;
	while (b) {
		long long t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}

signed main() {
	int n;
	double ans = 0;
	cin >> n;
	double aa = 0;
	double x[10], y[10];
	rep(i, n) {
		cin >> x[i] >> y[i];
	}
	int a[10] = { 0,1,2,3,4,5,6,7,8,9 };
	do {
		double cnt = 0;
		for (int i = 1; i < n; i++) {
			cnt += sqrt((x[a[i]] - x[a[i - 1]]) * (x[a[i]] - x[a[i - 1]]) + (y[a[i]] - y[a[i - 1]]) * (y[a[i]] - y[a[i - 1]]));
		}
		aa++;
		ans += cnt;
	} while (next_permutation(a, a + n));
	printf("%.12lf\n", ans / aa);

	return 0;
}


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

using ll=long long;
using ld=long double;

void solve(){
	ll a,b,c,d;
	cin>>a>>b>>c>>d;
	ll ma1=max(a,b);
	ll mi1=min(a,b);
	ll ma2=max(c,d);
	ll mi2=min(c,d);
	ll ans = LLONG_MIN;
	ans = max(ans, ma1*ma2);
	ans = max(ans, ma1*mi2);
	ans = max(ans, mi1*ma2);
	ans = max(ans, mi1*mi2);
	cout<<ans<<'\n';
}

int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);cout.tie(0);
	int t=1;
	//cin>>t;
	while(t--){
		solve();
	}
	return 0;
}


Measured memory_bytes: 3652
#include <cstdio>
#include <cassert>
#include <algorithm>    
#include <iostream>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <iomanip>
#include <cstring>
#include <cmath>
#include <bitset>
#define pb push_back
#define mk make_pair
#define eb emplace_back
#define eps 1e-8
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
//#define int long long
using namespace std;

typedef long double ld;
typedef unsigned int ui;
typedef pair<int,int> pii;
typedef tuple<int, int, int> tiii;
typedef unsigned long long ull; 
typedef vector<int> vi;
typedef vector<pii> vii;
typedef vector<long double> vd;
const int inf = 1e9;
const long long INF = 1e18;
const int M = 1e9 + 7;
//__int128


signed main() {
  // freopen("in.txt", "r", stdin);
  ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
  cout.setf(ios::fixed); cout.precision(10);
  int n;
  cin >> n;
  std::vector<int> l(n + 1), r(n + 1);
  std::vector<pii> a(n);
  for(int i = 0; i < n; ++i) {
    cin >> a[i].fi >> a[i].se;
  }
  sort(all(a));
  int res = 0;
  for(int i = 0; i < n; ++i) {
    l[i + 1] = max(l[i], a[i].fi);
    res = max(res, a[i].se - a[i].fi + 1);
  } 
  r[n] = inf;
  for(int i = n - 1; i >= 0; --i) {
    r[i] = min(a[i].se, r[i + 1]);
  } 
  int p = l[n], q = r[0];
  // cout << p << ' ' << q << endl;
  res += max(q - p + 1, 0);
  for(int i = 0; i < n - 1; ++i) {
    res = max(res, max(q - l[i + 1] + 1, 0) + max(r[i + 1] - p + 1, 0));
  }
  cout << res << endl;
  return 0;
}

Measured memory_bytes: 1792
// #pragma GCC target("avx")  // CPU 処理並列化
// #pragma GCC optimize("O3")  // CPU 処理並列化
// #pragma GCC optimize("unroll-loops")  // 条件処理の呼び出しを減らす
// #define BEGIN_STACK_EXTEND(size) void * stack_extend_memory_ = malloc(size);void * stack_extend_origin_memory_;char * stack_extend_dummy_memory_ = (char*)alloca((1+(int)(((long long)stack_extend_memory_)&127))*16);*stack_extend_dummy_memory_ = 0;asm volatile("mov %%rsp, %%rbx\nmov %%rax, %%rsp":"=b"(stack_extend_origin_memory_):"a"((char*)stack_extend_memory_+(size)-1024));
// #define END_STACK_EXTEND asm volatile("mov %%rax, %%rsp"::"a"(stack_extend_origin_memory_));free(stack_extend_memory_);

#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<queue>
#include<deque>
#include<stack>
#include<string>
#include<string.h>
#include<vector>
#include<set>
#include<map>
#include<bitset>
#include<stdlib.h>
#include<cassert>
#include<time.h>
#include<bitset>
#include<numeric>
#include<unordered_set>
#include<unordered_map>
#include<complex>
using namespace std;
const long long mod=998244353;
const long long inf=mod*mod;
const long long d2=(mod+1)/2;
const double EPS=1e-11;
const double INF=1e+10;
const double PI=acos(-1.0);
const int C_SIZE = 11100000;
const int UF_SIZE = 3100000;
namespace{
	long long fact[C_SIZE];
	long long finv[C_SIZE];
	long long inv[C_SIZE];
	inline long long Comb(int a,int b){
	 	if(a<b||b<0)return 0;
	 	return fact[a]*finv[b]%mod*finv[a-b]%mod;
	}
	void init_C(int n){
		fact[0]=finv[0]=inv[1]=1;
		for(int i=2;i<n;i++){
			inv[i]=(mod-(mod/i)*inv[mod%i]%mod)%mod;
		}
		for(int i=1;i<n;i++){
			fact[i]=fact[i-1]*i%mod;
			finv[i]=finv[i-1]*inv[i]%mod;
		}
	}
	long long pw(long long a,long long b){
		if(a<0LL)return 0;
		if(b<0LL)return 0;
		long long ret=1;
		while(b){
			if(b%2)ret=ret*a%mod;
			a=a*a%mod;
			b/=2;
		}
		return ret;
	}
	long long pw_mod(long long a,long long b,long long M){
		if(a<0LL)return 0;
		if(b<0LL)return 0;
		long long ret=1;
		while(b){
			if(b%2)ret=ret*a%M;
			a=a*a%M;
			b/=2;
		}
		return ret;
	}
	int pw_mod_int(int a,int b,int M){
		if(a<0)return 0;
		if(b<0)return 0;
		int ret=1;
		while(b){
			if(b%2)ret=(long long)ret*a%M;
			a=(long long)a*a%M;
			b/=2;
		}
		return ret;
	}
	int ABS(int a){return max(a,-a);}
	long long ABS(long long a){return max(a,-a);}
	double ABS(double a){return max(a,-a);}
	int sig(double r) { return (r < -EPS) ? -1 : (r > +EPS) ? +1 : 0; }
	int UF[UF_SIZE];
	void init_UF(int n){
		for(int i=0;i<n;i++)UF[i]=-1;
	}
	int FIND(int a){
		if(UF[a]<0)return a;
		return UF[a]=FIND(UF[a]);
	}
	void UNION(int a,int b){
		a=FIND(a);b=FIND(b);if(a==b)return;
		if(UF[a]>UF[b])swap(a,b);
		UF[a]+=UF[b];UF[b]=a;
	}
}
// ここから編集しろ
int main(){

	for(int i=0;i<5;i++){
		int t;scanf("%d",&t);if(t==0){
			printf("%d\n",i+1);
		}
	}
}

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

int main() {
  long long N, M;
  cin >> N >> M;
  if (N == 1 && M == 1) {
    printf("1");
  } else if (N == 1 || M == 1) {
    printf("%lld", N * M - 2);
  } else {
    printf("%lld", (N - 2) * (M - 2));
  }
  return 0;
}


Measured memory_bytes: 256
a = gets.chomp.to_i
c = [[0, 0, 0]]
while s = gets
  c.push(s.split.map(&:to_i))
end
t = 0
for i in 1..a
  t = 0
  for j in 0..(c[i][0] - c[i - 1][0])
    if (c[i][1] - c[i - 1][1]).abs + (c[i][2] - c[i - 1][2]).abs + 2 * j == (c[i][0] - c[i - 1][0]) 
      t = 1
    end
  end
    #puts "#{t} #{j}"
    if t == 0
      puts "No"
      exit
    end
  #end
end
puts "Yes"
    #p a
#p c

Measured memory_bytes: 9596
#include <iostream>
#include <iomanip>
#include <random>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#include <numeric>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <sstream>
#include <bitset>
#include <cassert>
#include <fstream>
#include <queue>

#define len(X) ((int)(X).size())

#ifdef __LOCAL
#define DBG(X) cout << #X << "=" << (X) << '\n';
#define SAY(X) cout << (X) << '\n';
#else
#define DBG(X)
#define SAY(X)
#endif

using namespace std;

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

const int INT_INF = (int)(2e9);
const ll  LL_INF = (ll)(2e18);

const int NIL = -1;
static mt19937 _g(time(nullptr));

inline ll randint(ll a, ll b) { ll w = (_g() << 31LL) ^ _g(); return a + w % (b - a + 1); }
inline void fast_io() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); };
template<typename T> inline T sign(T x) { return T(x > 0) - T(x < 0); }
template<typename T, typename S> inline ostream& operator<<(ostream& os, const pair<T, S> p) { cout << "[" << p.first << ";" << p.second << "]"; return os; }
template<typename T> inline ostream& operator<<(ostream& os, const vector<T>& v) { for (auto el : v) cout << el << " "; return os; }
template<typename T> inline T fetch() { T ret; cin >> ret; return ret; }
template<typename T> inline vector<T> fetch_vec(int sz) { vector<T> ret(sz); for (auto& elem : ret) cin >> elem; return ret; }

bool solve() {
    int x = fetch<int>();

    for (int i = 1; i < 10; ++i)
    {
        int y = x / i;

        if (y >= 1 && y <= 9 && i * y == x)
            return true;
    }

    return false;
}

int main() {
    fast_io();
    
    if (solve())
        std::cout << "Yes\n";
    else
        std::cout << "No\n";

    return 0;
}


Measured memory_bytes: 256
// 基本テンプレート
 
#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 <fstream>
#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 debug(...) fprintf(stderr, __VA_ARGS__)
#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};
const ll INF = 1001001001001001LL;
const ll MOD = 1000000007LL;
 
signed main() {
    int N; cin >> N;
    vector<int> v(N);

    rep(i,0,N) cin >> v[i];
    sort(v.begin(), v.end());

    int A = v[N-1]/2, B = (v[N-1]+1)/2;

    vector<pii> info;
    rep(i,0,N) {
        if(v[i] <= A) info.push_back(make_pair(A - v[i], v[i]));
        else info.push_back(make_pair(v[i] - B, v[i]));
    }

    sort(info.begin(), info.end());
    printf("%lld %lld\n", v[N-1], info[0].second);
    return 0;
}

Measured memory_bytes: 3188
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i = a; i < b; ++i)
#define all(c) c.begin(), c.end()
#define gmax(x,y) x=max(x,y)
#define gmin(x,y) x=min(x,y)
using namespace std;

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

int main(){
	cin.tie(0);
	cout.tie(0);
	ios_base::sync_with_stdio(0);
	int a,b;
	cin >> a >> b;
	cout << (a + b) % 24 << '\n';
}


Measured memory_bytes: 256
import java.util.Scanner;
        
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        
        int n = sc.nextInt();
        int d = sc.nextInt();
        int answer = 0;

        for (int i = 0; i < n; i++) {
            double x = sc.nextInt();
            double y = sc.nextInt();
            if (Math.sqrt(x * x + y * y) <= d) {
                answer++;
            }
        }
        System.out.println(answer);
    }
}

Measured memory_bytes: 60768
#include<stdio.h>

int main()
{
	long long int n, a, b,c1,c2,t;
	scanf("%lld%lld%lld", &n, &a, &b);
	if (0 == a)
	{
		printf("0");
		exit(0);
	}
	c1 = n / (a + b);
	t = n % (a + b);
	if (t > a)
		c2 = a;
	else
		c2 = t;
	printf("%lld", c1 *a+ c2);
}

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

using namespace std;
using ll = int64_t;
using pii = pair<int, int>;
using pli = pair<ll, int>;
using mii = map<int, int>;
using vi = vector<int>;
using vii = vector<vi>;
using vl = vector<ll>;
using vll = vector<vl>;
using tpi = tuple<int, int, int>;

using vqi = vector<queue<int>>;
using vpi = vector<pii>;
using bs = bitset<60>;
using vbi = vector<bs>;

ll gcd(ll a, ll b) {
    if (a < b) {
        swap(a, b);
    }

    /* ユークリッドの互除法 */
    ll r = a % b;
    while (r != 0) {
        a = b;
        b = r;
        r = a % b;
    }
    return b;
}

ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }

constexpr int64_t __pow_mod(int64_t n, int64_t p, int64_t mod) noexcept {
    if (p == 0) {
        return 1;
    }
    if (p % 2 == 0) {
        int64_t t = __pow_mod(n, p / 2, mod);
        return (t * t) % mod;
    }
    return (n * (__pow_mod(n, p - 1, mod) % mod)) % mod;
}

constexpr int64_t pow_mod(int64_t n, int64_t p, int64_t mod) noexcept {
    int64_t res = __pow_mod(n, p, mod);
    if (res == 0) {
        res = mod;
    }
    return res;
}

constexpr int64_t nCr_mod(int64_t n, int64_t r, int64_t mod) noexcept {
    int64_t count = 1;
    auto a = r;
    for (auto i = n; i > n - r; i--) {
        count *= i;
        if (count % mod != 0) {
            count %= mod;
        }
        int64_t inv = pow_mod(a, mod - 2, mod);
        count *= inv;
        if (count % mod != 0) {
            count %= mod;
        }
        a--;
    }
    return count;
}

void solve(long long N) {
    int ans = N / 2;
    if (N % 2 == 1) {
        ans++;
    }

    cout << ans << endl;

}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You
// use the default template now. You can remove this line by using your custom
// template)
int main() {
    long long N;
    std::cin >> N;
    solve(N);
    return 0;
}


Measured memory_bytes: 256
n=int(input())
a=list(map(int,input().split()))
b=sorted(a);c=0
for i in range(n-1):
    t=cnt=0;x=a.index(b[i])
    while x!=i:
        y=a.index(b[x])
        a[x],a[y]=b[x],b[i];cnt+=1
        t+=b[x]+b[i]
        x=y
    if cnt:c+=min(t,(b[i]+b[0])*2+t-(b[i]-b[0])*cnt)
print(c)

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

#define INF 0x3f3f3f3f
#define MOD 10000

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

int N, W;
int v[105], w[105];
int dp[105][10010];

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

	cin >> N >> W;
	for (int i = 0; i < N; i++) cin >> v[i] >> w[i];

	for (int i = 0; i < N; i++) {
		for (int j = 0; j <= W; j++) {
			if (j < w[i]) dp[i+1][j] = dp[i][j];
			else dp[i+1][j] = max(dp[i][j], dp[i+1][j-w[i]]+v[i]);
		}
	}

	cout << dp[N][W] << endl;

	return 0;
}

Measured memory_bytes: 7056
#include <iostream>
#include <algorithm>
#include <functional>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <string>

#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
typedef vector<int> vec;
typedef vector<vector<int>> mat;
using P = pair<ll, ll>;

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

const ll mod = 1000000007;
const int INF = 1<<29;

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

  bool is_reverse = false;
  for (int i = 0; i < Q; ++i){
    int T; cin >> T;
    if (T == 1){
      is_reverse = !is_reverse;
    }
    if (T == 2) {
      int F; string C; cin >> F >> C;
      if (F == 1) {
        if (is_reverse) S += C;
        else S.insert(0, C);
      }
      else {
        if (is_reverse) S.insert(0, C);
        else S += C;
      }
    }
  }
  if (is_reverse) reverse(S.begin(), S.end());
  cout << S << endl;
}


Measured memory_bytes: 900
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <fstream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <string>
#include <cstring>
#include <ctime>


using namespace std;

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

//math
//-------------------------------------------
template<class T> inline T sqr(T x) { return x*x; }

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define EXISTch(s,c) ((((s).find_first_of(c)) != std::string::npos)? 1 : 0)//cがあれば1 if(1)
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)  FOR(i,0,n)
#define loop(n) FOR(i,0,n)
#define rrep(i,a,b) for(int i=(a);i>=(b);--i)
//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI = acos(-1.0);
const int INF = (int)1000000007;
const LL MOD = (LL)1000000007;//10^9+7
const LL INF2 = (LL)100000000000000000;//10^18

int main() {
	
	//入力受け取り、pairは最初からコンパレーターの仕組みが使えて
	//デフォルトだとfirstの昇順でソートされる。
	int n; cin >> n;

	vector<pair<int, int>>red(n);
	for (int i = 0; i < n; i++) {
		int x, y; cin >> x >> y;
		red[i].first = x;
		red[i].second = y;
	}

	vector<pair<int, int>>blue(n);
	for (int i = 0; i < n; i++) {
		int x, y; cin >> x >> y;
		blue[i].first = x;
		blue[i].second = y;
	}

	//使用済みの赤点をメモする配列
	vector<int> usedred(n, 0);

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

	int ans = 0;
	
	//iが青点、jが赤点をとってくることに対応
	//iを1個とってくる。
	for (int i = 0; i < n; i++) {
		int my = -1;
		int posy = -1;

		//青点一つに対し、赤点を全探索。
		//選んだ青点より真に左下にある赤点のうち、y座標が最大のものをもとめ
		//0～n-1までのどの番号が記録したい
		for (int j = 0; j < n; j++) {
			if (usedred[j])continue;
			if (red[j].first < blue[i].first && red[j].second < blue[i].second) {
				if (my < red[j].second) {
					posy = j;
					my = red[j].second;
				}
			}
		}

		//場所の更新が起こった=ペアができた。
		//使用済みのメモをして、答えをインクリメントする
		if (posy != -1) {
			usedred[posy] = 1;
			ans++;
		}
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 384
from collections import Counter

N = int(input())
a_list = list(map(int, input().split()))
s_list = [0]*(N+1)
ans = 0

# initialization
s_list[0] = 0
for i in range(len(a_list)):
    s_list[i+1] = s_list[i] + a_list[i]
s_count = Counter(s_list)
for num, cnt in s_count.items():
    if cnt>=2:
        ans += cnt*(cnt-1)//2
print(ans)


Measured memory_bytes: 112976
#include<iostream>
#include<vector>
#include<cstdio>
using namespace std;
int main()
{
  int n;
  scanf("%d", &n);
  vector<int> R;
  for(int i=0; i<n; i++)
  {
      int temp;
      scanf("%d", &temp);
      R.push_back(temp);
  }
  int Maxp = R[1] - R[0];
  int Minv = R[0];
  for(int i=1; i<n; i++)
  {
    if(R[i]-Minv > Maxp)
      Maxp = R[i] - Minv;
    if(R[i] < Minv)
      Minv = R[i];
  }
  cout << Maxp << endl;
  return 0;
}



Measured memory_bytes: 3928
#include <bits/stdc++.h>
#define ll long long int
#define pb push_back
#define mp make_pair
#define mod 998244353
#define pi 3.141592653589793
const int N = 2000001;
using namespace std;



int main() {
//    cout << fixed << setprecision(10);
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

    
    string s;
    cin >> s;
    cout << ((s[2] == s[3] && s[4] == s[5]) ? "Yes" : "No");

    

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N,sum=0; cin >> N;
  vector<int> A(N);
  for(int i=1; i<=N; i++) {
    cin >> A[i];
    sum+=A[i];
  }
  if(sum%2 == 0) cout << "YES" << endl;
  else cout << "NO" << endl;
}

Measured memory_bytes: 3728
#include <cstdio>
#include <algorithm>

#define R register
#define maxn 100010
int a[maxn];
int main()
{
	R int n, l, t, cnt = 0; scanf("%d%d%d", &n, &l, &t);
	for (R int i = 0; i < n; ++i)
	{
		R int d;
		scanf("%d%d", &a[i], &d);
		a[i] += d == 1 ? t : -t;
		cnt += a[i] / l; a[i] %= l; a[i] < 0 ? a[i] += l, --cnt : 0;
	}
	std::sort(a, a + n); ((cnt %= n) += n) %= n;
	for (R int i = 0; i < n; ++i) printf("%d\n", a[(i + cnt) % n]);
	return 0;
}
/*
4 20 9
9 1
7 2
12 1
18 1
18
7
18
1

2 2 1
0 1
1 2
*/

Measured memory_bytes: 1536
#include <bits/stdc++.h>
#define Mod 1000000007
#define ll long long
using namespace std;

ll Power(ll n, ll m){
    ll res=1;
    while(m>0){
        if(m & 1) res = res * n % Mod;
        n = n * n % Mod;
        m = m>>1;
    }
    return res;
}


int main(){
    ll n,m;
    scanf("%lli %lli", &n, &m);
    printf("%lli\n",Power(n,m));
    //cout<<Power(n,m,Mod)<<endl;
    return 0;
}



Measured memory_bytes: 3224
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<cstring>
#include<ctime>
#include<iostream> 
#include<algorithm>
#include<queue>
#include<vector>
#include<map>
#define ll long long
#define ull unsigned long long
#define max(a,b) (a>b?a:b)
#define min(a,b) (a<b?a:b)
#define lowbit(x) (x& -x)
#define mod 1000000007
#define inf 0x3f3f3f3f
#define eps 1e-18
#define maxn 100010
inline ll read(){ll tmp=0; char c=getchar(),f=1; for(;c<'0'||'9'<c;c=getchar())if(c=='-')f=-1; for(;'0'<=c&&c<='9';c=getchar())tmp=(tmp<<3)+(tmp<<1)+c-'0'; return tmp*f;}
inline ll power(ll a,ll b){ll ans=1; for(;b;b>>=1){if(b&1)ans=ans*a%mod; a=a*a%mod;} return ans;}
inline ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
inline void swap(int &a,int &b){int tmp=a; a=b; b=tmp;}
using namespace std;
int a[510][510];
int x[250010],y[500010];
int n,m,tot=0;
int main()
{
	n=read(); m=read();
	for(int i=1;i<=n;i++)
		for(int j=1;j<=m;j++)
			a[i][j]=read();
	for(int i=1;i<=n;i++){
		for(int j=1;j<m;j++)
			if(a[i][j]&1)--a[i][j],++a[i][j+1],x[++tot]=i,y[tot]=j;
		if(i<n&&a[i][m]&1)--a[i][m],++a[i+1][m],x[++tot]=i,y[tot]=m;
	}
	printf("%d\n",tot);
	for(int i=1;i<=tot;i++)
		if(y[i]<m)printf("%d %d %d %d\n",x[i],y[i],x[i],y[i]+1);
		else printf("%d %d %d %d\n",x[i],y[i],x[i]+1,y[i]);
}

Measured memory_bytes: 4096
import java.util.Scanner;

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

		var sum = 0;
		for (var a = 1; a <= n; a++) {
			var count = n / a;
			if (n % a == 0) {
				count--;
			}
			sum += count;
		}
		System.out.println(sum);
	}
}


Measured memory_bytes: 35672
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>  
#include <functional>
#define ll long long int
#define ld long double
#define pb push_back
#define pll pair<ll,ll>
#define pint pair<int,int>
#define forn(i, n) for (int i = 0; i < int(n); i++)
#define mod 1000000007
#define MAX 100000000
#define endl '\n'
#define mp make_pair
#define INF INT_MAX
#define fast ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
#define ff first
#define ss second
#define ps(x,y) fixed<<setprecision(y)<<x
#define setbits(x) __builtin_popcountll(x)            //counts no of ones in binary representation
#define w(t)     int t; cin>>t; while(t--)
#define pi 3.141592653589793238
#define sortt(v)  sort(v.begin(),v.end())
#define lb(v,x) std::lower_bound(v.begin(),v.end(),x)
#define ub(v,x) std::upper_bound(v.begin(),v.end(),x)

using namespace std;

int main(){
    fast;
    ll n,m,p,q,a,b,c,d;
    string s,t;
    cin>>n;
    if(n%1000==0)	cout<<0;
    else{
    	int x=n/1000;
    	x++;
    	cout<<x*1000-n;
	}
}

Measured memory_bytes: 3644
#include<bits/stdc++.h>
#define ll long long
#define endl '\n'
#define pii pair<int,int>
#define IOS ios::sync_with_stdio(0); cin.tie(0);
#define fio freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
#define vll vector<long long int>
#define vpii vector<pair<int,int>>
#define dsc [](int a,int b)->bool {return a>b;}
#define pb push_back
#define mp make_pair
#define vi vector<int>
#define MAX 1000000000
#define test int t; cin>>t;
#define MOD 1000000007

using namespace std;

string s[10];
ll n,m,k;

ll cal(ll x, ll y){
    ll ret = 0;
    // for(int i = 0; i<n; i++){
    //     if((x & (1LL<<i))) ret+=a[i];
    // }
    for(int i = 0; i<n; i++){
        for(int j = 0; j<m; j++){
            if((x & (1LL<<i)) && (y & (1LL<<j)) && s[i][j] == '#') ret++;
        }
    }
    
    return ret;
}

int main()
{
    #ifndef ONLINE_JUDGE
        fio
    #endif
    IOS

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

    ll ans = 0;
    for(ll i = 0; i<(1<<n); i++){
        for(ll j = 0; j<(1<<m); j++){
            if(cal(i,j) == k) ans++;
        }
    }
    
    cout<<ans<<endl;

    return 0;
}

Measured memory_bytes: 3644
// B - Bounding

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
// const int INF = 2147483647;
// const ll INF = 9223372036854775807;
// const int MOD = 1e9 + 7;

int L[100];

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

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

	int ans = 1;
	int D = 0;
	for (int i=0; i<N; i++) {
		if (D + L[i] > X) break;
		D += L[i];
		ans++;
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
const ll MOD = 1000000000+7;
const int N=1e6;
vector<int>adj[N];
queue<int>q;
bool visited[N];
int dist[N];

int bfs(int v)
{
    int cnt=0;
    q.push(v);
    dist[v]=0;
    visited[v]=true;
    while(!q.empty()){
            int v=q.front();
             q.pop();
        for(auto x:adj[v])
        {
            if(!visited[x])
            {
                cnt++;
                visited[x]=true;
               // dist[x]=dist[v]+1;
                q.push(x);
            }
        }
    }
 return cnt;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);cout.tie(NULL);
    int n,m;
    cin>>n>>m;
    for(int i=0;i<m;i++)
    {
        int u,v;
        cin>>u>>v;
        adj[u].push_back(v);
        adj[v].push_back(u);
    }
    int cnt=0;
    for(int i=1;i<=n;i++)
    {
        if(!visited[i])
        {cnt=max(cnt,bfs(i));}
    }
    cout<<cnt+1;
}


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

int main(){
    int i,j,n,m,manhattan,tmp;
    cin >> n >> m;
    vector<int> a(n),b(n),c(m),d(m),ans(n);
    for(i=0;i<n;i++){
        cin >> a.at(i) >> b.at(i);
    }
    for(i=0;i<m;i++){
        cin >> c.at(i) >> d.at(i);
    }
    for(i=0;i<n;i++){
        for(j=0;j<m;j++){
            tmp = abs(a.at(i)-c.at(j))+abs(b.at(i)-d.at(j));
            if(j==0){manhattan = tmp;ans.at(i) = j+1;}
            else{
                if(tmp<manhattan){manhattan=tmp;ans.at(i) = j+1;}
            }
        }
    }
    for(i=0;i<n;i++){
        cout << ans.at(i) << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
#include<math.h>

#define LLD_ABS(x) (((x) >= 0 ) ? (x) : (-x))

int main()
{
    long long int x, k, d, answer, abs_x, req_d_num;

    scanf("%lld %lld %lld", &x, &k, &d);

    abs_x = LLD_ABS(x);

    req_d_num = abs_x/d;

    if (req_d_num >= k)
    {
        answer = abs_x - d*k;
    } else {
        if (((k - req_d_num)%2) == 1)
        {
            answer = (d - (abs_x%d));
        } else {
            answer = abs_x%d;
        }
    }

    printf("%lld", answer);

    return 0;
}

Measured memory_bytes: 1736
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
ll MOD = 1000000007;
ll INF = 1ll << 60;

int main() {
  int h, w;
  cin >> h >> w;
  vector<string> v(h);
  for (int i = 0; i < h; i++) cin >> v[i];

  for (int i = 0; i < w + 2; i++) cout << "#";
  cout << endl;
  for (int i = 0; i < h; i++) cout << "#" << v[i] << "#" << endl;
  for (int i = 0; i < w + 2; i++) cout << "#";
  cout << endl;
}


Measured memory_bytes: 256
import java.util.*;

class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String s = sc.next();
      
      	if(s.contains("RRR")){
          System.out.println("3");
        }
      	else if(s.contains("RR")){
          System.out.println("2");
        }
      	else if(s.contains("R")){
          System.out.println("1");
        }
        else{
          System.out.println("0");
        }
        
    }
}

Measured memory_bytes: 35576
#include<iostream>
#include<cstdlib>
#include<string>
#include<vector>
#include<map>
#include<unordered_map>
#include<queue>
#include<algorithm>
#include<iomanip>
#include<typeinfo>
#include<complex>
using namespace std;
using ll = long long int;
const int mod = 1e9 + 7;
#define rep(i, a, b) for(ll i = a;i < b; i++)

int main() {

	int n;
	cin >> n;

	vector<string> s(n);
	map<string, int> m;
	int maxi = 0;

	rep(i, 0, n) {
		cin >> s[i];
	}

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

	rep(i, 0, n){
		m[s[i]]++;
		maxi = max(maxi, m[s[i]]);
	}

	rep(i, 0, n) {
		if (m[s[i]] == maxi) {
			cout << s[i] << endl;
			m[s[i]] = 0;
		}
	}

	return 0;
}

Measured memory_bytes: 26752
#include<bits/stdc++.h>
using namespace std;
 
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL); 
 
#define ff first
#define ss second
#define pb push_back
#define pf push_front
#define mp make_pair
#define in insert
#define ld long double
 
#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...) 1
#endif
template<class T> ostream& operator<<(ostream &os, vector<T> V) {os << "[ "; for(auto v : V) os << v << " "; return os << "]";}
template<class L, class R> ostream& operator<<(ostream &os, pair<L,R> P) {return os << "(" << P.first << "," << P.second << ")";}
 
typedef long long int ll;
 
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
const ll mod =1e9+7;
const ll maxn =200001;
ll power(ll x, ll n) {
    ll res = 1;
    for (; n > 0; n >>= 1) {
    if (n & 1) res = (res * x) % mod;
    x = (x * x) % mod;
    }
    return res;
}

int main()
{
 
  IOS
  ll h,n;
  cin>>h>>n;
  ll a[n],b[n];
  for(ll i=0;i<n;i++)
  {
    cin>>a[i]>>b[i];
  }
  ll dp[20001];
  dp[0]=0;
  for(ll i=1;i<=20000;i++)
  { 
    bool flag=0;
    dp[i] = 1e15;
    ll mini=1e15;
    for(ll j=0;j<n;j++)
    {
      if(a[j]<=i)
      { 
        //trace(i,j,dp[i],a[j]);
        dp[i]=min(dp[i],dp[i-a[j]]+b[j]);
        flag=1;
        
      }
      mini=min(mini,b[j]);
    }
    if(flag==0)
      dp[i]=mini;
    
  }
  // for(ll i=0;i<=100;i++)
  // {
  //   cout<<dp[i]<<endl;
  // }
  ll ans=1e15;
  //trace(dp[100]);
  for(ll i=h;i<=20000;i++)
  {   
    //cout<<dp[i]<<" ";
    //trace(dp[i]);
      ans=min(ans,dp[i]);
  }
  cout<<ans<<endl;
  
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define sz(x) int(x.size())
using namespace std;

#define MAX_N 100000

// int N = 3;
// int a[MAX_N] = {1, 2, 3};

int N ;
int a[MAX_N];
int main() {
    cin >> N;
    rep(i, N) {
        cin >> a[i];
    }
    int even = 0;
    int odd = 0;

    // 奇数偶数をカウント
    for (int i = 0; i < N; i++) {
        if (a[i] % 2 == 0) {
            even++;
        } else {
            odd++;
        }
    }

    string ans;
    if (odd % 2 == 1) {
        ans = "NO";
    } else {
        ans = "YES";
    }

    cout << ans << endl;
}

Measured memory_bytes: 640
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <cmath>
#include <climits>
#include <cassert>
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <string>
#include <list>
#include <bitset>
#include <vector>
using namespace std;

#define I64d_OJ

//#ifdef I64d_OJ
//#define LL __int64
//#endif // I64d_OJ
#ifdef I64d_OJ
#define LL long long
#endif // I64d_OJ

typedef unsigned LL ULL;
typedef unsigned uint;
typedef pair<int,int> pii;
typedef pair<double,double> pdd;
typedef pair<LL,LL> pLL;
typedef vector<int> vi;

inline int read(){
    int x=0,f=1;
    char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-') f=-f; ch=getchar();}
    while(ch>='0'&&ch<='9'){x=x*10+ch-'0'; ch=getchar();}
    return x*f;
}

#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
#define ls rt<<1
#define rs rt<<1|1
#define MID(a,b) (((LL)(a)+(LL)(b))>>1)
#define absx(a) ((a)<0?-(a):(a))
#define MK(a,b) make_pair(a,b)
#define PB(a) push_back(a)
#define lowbit(x) ((x)&-(x))

#define lc c[x][0]
#define rc c[x][1]

template< typename T >
inline void Max(T &a,T &b){if(a<b) a=b;}
template< typename T>
inline void Min(T &a,T &b){if(a>b) a=b;}

const double pi=(double)acos(-1.0);
const double eps=(double)1e-8;
const int INF = (int) 0x3f3f3f3f;
const int MOD = (int) 1e9+7;
const int MAXN =(int) 2e5+10;
const int MAXM = (int) 3e6+10;

///--------------------START-------------------------
char s[MAXN];
int K;

void work(){
    scanf("%d%s",&K,s);
    int len=strlen(s);
    if(K>=len) printf("%s\n",s);
    else {
        for(int i=0;i<K;i++) printf("%c",s[i]);
        printf("...\n");
    }
}

///--------------------END-------------------------
int main(){
#ifdef NNever
//freopen("data.in","r",stdin);
///freopen("out.txt","w",stdout);
#endif // NNever
    work();
    return 0;
}









Measured memory_bytes: 3720
n, m = map(int, input().split())
d = {}
cnt_ac = 0
cnt_wa = 0
for _ in range(m):
    p, s = input().split()
    if p not in d:
        d[p] = [s]
    else:
        d[p].append(s)
for i in d:
    if 'AC' in d[i]:
        cnt_ac += 1
        cnt_wa += d[i].index('AC')
print(cnt_ac, cnt_wa)

Measured memory_bytes: 34404
using System;
using System.Linq;

class prog{
  static void Main(){
    int[] N = Console.ReadLine().Split().Select(int.Parse).ToArray();
    int n = 100 * N[0] + 10 * N[1] + N[2];
    Console.WriteLine(n % 4 == 0 ? "YES" : "NO");
  }
}

Measured memory_bytes: 11220
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n;
    cin >> n;
    vector<int>v(n + 3);
    for(int i = 1; i <= n; i++){
        cin >> v[i];
    }
    long long cnt = 0;
    int val = 0;
    for(int i = 1; i <= n; i++){
        cnt += 1LL * (max(val, v[i]) - v[i]);
        v[i] = max(v[i], val);
        val = v[i];
    }
    cout << cnt;
    return 0;
}


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

typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<long long> VL;
typedef vector<vector<long long>> VVL;
typedef pair<int,int> P;
typedef tuple<int,int,int> tpl;

#define ALL(a)  (a).begin(),(a).end()
#define SORT(c) sort((c).begin(),(c).end())
#define REVERSE(c) reverse((c).begin(),(c).end())
#define EXIST(m,v) (m).find((v)) != (m).end()
#define LB(a,x) lower_bound((a).begin(), (a).end(), x) - (a).begin()
#define UB(a,x) upper_bound((a).begin(), (a).end(), x) - (a).begin()

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define RFOR(i,a,b) for(int i=(a)-1;i>=(b);--i)
#define RREP(i,n) RFOR(i,n,0)

#define en 


constexpr double EPS = 1e-9;
constexpr double PI  = 3.1415926535897932;
constexpr int INF = 2147483647;
constexpr long long LINF = 1LL<<60;
constexpr long long MOD = 1000000007; // 998244353;

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

using namespace std;
using namespace atcoder;

void Main(){
    int n, m;
    cin >> n >> m;
    dsu d(n);
    REP(i, m) {
        int a, b;
        cin >> a >> b;
        d.merge(a-1, b-1);
    }
    cout << d.groups().size() - 1 << endl;
}

int main(void){
    cin.tie(0);cout.tie(0);ios_base::sync_with_stdio(0);cout<<fixed<<setprecision(15);
    int t=1; //cin>>t;
    REP(_,t) Main();
    return 0;
}

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

using namespace std;

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
const int N = 1e5+50;
const int M = 1e6;
const ll oo = 1e18;
const int mod = 1e9+7;

double p[3030],dp[3030];

int main(){
	cout << setprecision(12) << fixed;
	int n;
	cin>>n;
	dp[0] = 1;
	for(int i=1;i<=n;i++){
		cin>>p[i];
		for(int j=i;j>=0;j--){
			double cur = 0;
			if(i)cur = dp[j-1] * p[i];
			dp[j] = cur + dp[j] * (1 - p[i]);
		}
	}
	double ans = 0;
	for(int i=n/2+1;i<=n;i++)
		ans += dp[i];
	printf("\n");
	cout << ans << endl;
}

Measured memory_bytes: 256
n = input()

s = len(n)

ans = 0


if s == 1:
    print(int(n))
    exit()

for i in range(0,s-1,2): 
    ans += 9*(10**i)

if s %2 != 0:
    ans += int(n) - (10**(s-1))+1

print(ans)

Measured memory_bytes: 38256
#include <bits/stdc++.h>
using ll = long long;
#define FOR(i, k, n) for(ll i = (k); i < (n); i++)
#define FORe(i, k, n) for(ll i = (k); i <= (n); i++)
#define FORr(i, k, n) for(ll i = (k)-1; i > (n); i--)
#define FORre(i, k, n) for(ll i = (k)-1; i >= (n); i--)
#define REP(i, n) FOR(i, 0, n)
#define REPr(i, n) FORre(i, n, 0)
#define ALL(x) (x).begin(), (x).end()
#define ALLr(x) (x).rbegin(), (x).rend()
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
using namespace std;

const int INF = 1001001001;

int main(void){
  int a, b;
  cin >> a >> b;
  if((a+b)%3 == 0 || a%3 == 0 || b%3 == 0) cout << "Possible" << endl;
  else cout << "Impossible" << endl;
  return 0;
}

Measured memory_bytes: 256
// Package main provides
//
// File:  a.go
// Author: ymiyamoto
//
// Created on Wed Dec  5 00:29:19 2018
//
package main

import "fmt"

var a, b int

func main() {
	fmt.Scan(&a, &b)

	for c := 1; c <= 3; c++ {
		if a*b*c%2 == 1 {
			fmt.Println("Yes")
			return
		}
	}

	fmt.Println("No")
}


Measured memory_bytes: 512
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
using namespace std;
#pragma warning(disable:4996)
int a[6000], N, K; bool dp[18000];
int solve(int i) {
	if (i < 0)return false; if (i >= N)return true;
	for (int j = 0; j <= K; j++)dp[j] = false;
	dp[0] = true;

	for (int j = 0; j < N; j++) {
		if (i == j)continue;
		for (int k = K; k >= a[j]; k--) {
			if (dp[k - a[j]] == true)dp[k] = true;
		}
	}

	bool flag = false;
	for (int j = max(0, K - a[i]); j < K; j++) {
		if (dp[j] == true)flag = true;
	}
	return flag;
}
int main() {
	cin >> N >> K;
	for (int i = 0; i < N; i++) { cin >> a[i]; }
	sort(a, a + N);
	int ret = 0, L = -1, R = N + 1, M;
	while (true) {
		M = (L + R) / 2;
		bool p1 = solve(M - 1), p2 = solve(M);//無能ラインはM-1まで/有能ラインはMから
		if (p1 == false && p2 == true)break;
		if (p1 == true)R = M;
		if (p2 == false)L = M;
	}
	cout << M << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
#define ll long long
#define dd double
#define MOD1 1000000007
#define MOD2 998244353
#define nl cout<<endl
#define rt ll Q[100005]={0}
#define mp make_pair
#define test() ll t;cin>>t;while(t--)
#define pb push_back
#define ff first    
#define ss second
#define all(v) v.begin(),v.end()
#define s(ar,n) sort(ar,ar+n)
#define rs(ar,n) sort(ar, ar+n, greater<ll>()) 
#define oa(a,n) for(ll i=0;i<n;i++)cout<<a[i]<<" ";nl
#define cn(a,n) for(ll i=0;i<n;i++)cin>>a[i];
#define ov(a,n) for(ll i=n-1;i>=0;i--)cout<<a[i]<<" ";nl
#define ovp(a,n) for(ll i=0;i<n;i++)cout<<a[i].ff<<" "<<a[i].ss<<endl;
#define maxa(ar,N) *max_element(ar,ar+N)
#define mina(ar,N) *min_element(ar,ar+N)
#define fastio() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
typedef pair<ll,ll> pii;
ll powe(ll n,ll m){if(m==0)return 1;ll t=powe(n,m/2);if(m%2==0)return (t*t);return (((t*t))*n);}
ll mpowe(ll n,ll m,ll MOD){if(m==0)return 1;ll t=mpowe(n,m/2,MOD);t%=MOD;if(m%2==0)return (t*t)%MOD;return (((t*t)%MOD)*n)%MOD;}
ll logtwo(ll n){if(n==1)return 0;if(n==0) return -1;return logtwo(n/2)+1;}
int main()
{
    fastio();
  
    string s,t;
    int c=0;
    cin>>s>>t;
    int n  = s.size();
    for(int i=0;i<n;i++)
        if(s[i]!=t[i])
            c++;
    cout<<c<<endl;
    
}

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

int main() {
  string password_s,password_t;
  string answer;
  int len_s,len_t;
  cin >> password_s >> password_t;
  len_s = password_s.size();
  len_t = password_t.size();
  
  if (len_s +1 != len_t) answer = "No";
  else {
    for (int i =0; i < len_s; i++) {
      if (password_s.at(i) != password_t.at(i)) {
        answer = "No";
        break;
      }
    }
  }
  
  if (answer != "No") answer = "Yes";
  cout << answer << endl;
}


Measured memory_bytes: 3632
use proconio::{fastout, input};

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

    let ans = a
        .iter()
        .enumerate()
        .filter(|(i, x)| i % 2 == 0 && *x % 2 == 1)
        .count();

    println!("{}", ans);
}


Measured memory_bytes: 2132
N=int(input())
S=input()

left=0
cnt1=0
cnt2=0

for i in range(N):
    if S[i]=="(":
        cnt1+=1
    elif S[i]==")":
        cnt2+=1
        if i<N-2 and S[i+1]=="(":
            if cnt2>=cnt1+left:
                left=cnt2-cnt1

res=S.count("(")+left-S.count(")")
if res>=0:
    print("("*left+S+")"*res)
else:
    print("("*(left+abs(res))+S)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,k;
    cin>>n>>k;
    vector<int> A(n);
    for (int i = 0; i < n; i++) {
        cin>>A[i];
    }
    
    int dp[n];
    dp[0]=0;
    dp[1]=abs(A[1]-A[0]);
    for(int i=2;i<n;i++)
    {
        dp[i]=INT_MAX;
        for(int j=1;j<=min(k,i);j++)
        {
            dp[i]=min(dp[i],dp[i-j]+abs(A[i-j]-A[i]));
        }
    }
    cout<<dp[n-1]<<endl;
}

Measured memory_bytes: 4020