akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cstring>
#include <sstream>
#include <map>
#include <set>
#include <cmath>
#include <queue>
#include <stack>
#include <list>
#include <numeric>
#include <bitset>
#include <ext/algorithm>
#include <ext/numeric>
#define ffor(_a,_f,_t) for(int _a=(_f),__t=(_t);_a<__t;_a++)
#define all(_v) (_v).begin() , (_v).end()
#define sz size()
#define pb push_back
#define SET(__set, val) memset(__set, val, sizeof(__set))
#define FOR(__i, __n) ffor (__i, 0, __n)
typedef long long LL; using namespace std;

int w[200], v[200];

int main() {
	int N, W;
	scanf("%d %d", &N, &W);
	FOR (i, N)
		scanf("%d %d", &w[i], &v[i]);
	vector<int> ves[4];
	FOR (i, N)
		FOR (d, 4)
			if (w[i] == w[0] + d)
				ves[d].pb(v[i]);

	FOR (d, 4) {
		sort(all(ves[d]));
		reverse(all(ves[d]));
	}
	LL ret = 0LL, v0 = 0LL;
	FOR (i0, ves[0].sz + 1) {
		LL v1 = 0LL;
		FOR (i1, ves[1].sz + 1) {
			LL v2 = 0LL;
			FOR (i2, ves[2].sz + 1) {
				LL v3 = 0LL;
				FOR (i3, ves[3].sz + 1) {
					LL sum = 1LL * i0 * w[0] +
									1LL * i1 * (w[0] + 1) +
									1LL * i2 * (w[0] + 2) +
									1LL * i3 * (w[0] + 3);
					if (sum <= W)
						ret = max(ret, 0LL + v0 + v1 + v2 + v3);
					if (i3 < ves[3].sz)
						v3 += ves[3][i3];
				}
				if (i2 < ves[2].sz)
					v2 += ves[2][i2];
			}

			if (i1 < ves[1].sz)
				v1 += ves[1][i1];
		}

		if (i0 < ves[0].sz)
			v0 += ves[0][i0];
	}
	cout << ret << endl;
	return 0;
}

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

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

ll A,B,V,W,T;

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>A>>V>>B>>W>>T;
	ll L=B-W*T;
	ll R=B+W*T;
	
	if(A-V*T<=L && R<=A+V*T) {
		cout<<"YES"<<endl;
	}
	else {
		cout<<"NO"<<endl;
	}
	
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}


Measured memory_bytes: 3640
from sys import stdin


def main():
    N, M = map(int, input().split())
    *AB, = map(int, stdin.read().split())
    A = AB[::2]
    B = AB[1::2]
    num = 0
    yen = 0
    for a, b in sorted(zip(A, B)):
        if M < num + b:
            yen += a * (M - num)
            break
        else:
            yen += a * b
            num += b
    print(yen)
    return


main()


Measured memory_bytes: 25836
from collections import defaultdict

n, k, *a = map(int, open(0).read().split())
d = defaultdict(int)
for b in a:
    d[b] += 1

v = sorted(d.values())[::-1]

c = 0
for i in range(min(k, len(v))):
    c += v[i]

print(n - c)


Measured memory_bytes: 37712
#include<iostream>
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<set>
#include<string>
#include<map>
#include<string.h>
#include<complex>
#include<math.h>
#include<queue>
#include <functional>
#include<time.h>
#include <stack>
#include<iomanip>
using namespace std;
#define rep(i,a,n) for(int i=(a);i<(n);i++)
#define ll long long
#define llint long long int
#define reverse(v)  reverse(v.begin(), v.end());
#define Yes(ans) if(ans)cout<<"Yes"<<endl; else cout<<"No"<<endl;
#define YES(ans) if(ans)cout<<"YES"<<endl; else cout<<"NO"<<endl;
#define hei(a) vector<a>
#define whei(a) vector<vector<a>>
#define UF  UnionFind 
#define Pint pair<int,int>
#define Pll pair<llint,llint>
#define keta(a)  fixed << setprecision(a)
constexpr auto mod = 1000000007;
//辞書順はnext_permutation( begin( v ), end( v ) );やで！
const llint INF = 100000000;
int main() {
	int n;
	cin >>n;
	int g = 0;
	int k = 0;
	rep(i, 1, n + 1) {
		if (i % 2)k++;
		else g++;
	}
	cout << k * g << endl;
	return 0;
}

Measured memory_bytes: 3564
#include<bits/stdc++.h>
#define pb emplace_back
using namespace std;
using ll = long long;
const int maxn = 300010;
ll get2(ll n){
	ll res = 0;
	for(ll v = 1;v <= n;v <<= 1){
		res += n / v;
	}
	return res;
}
ll get5(ll n){
	ll res = 0;
	for(ll v = 5;v <= n;v *= 5){
		res += n / v;
	}
	return res;
}
signed main(){
	ios_base::sync_with_stdio(0), cin.tie(0);
	ll n;
	cin >> n;
	if(n < 2)return cout << 0 << '\n', 0;
	if(n & 1){
		cout << 0 << '\n';
	}
	else{ 
		n /= 2;
		cout << min(get5(n), get2(n)) << '\n';
	}

}



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

using namespace std;

#define FAST_IO ios_base:: sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define mod 1000000007
#define endl "\n"
typedef long long ll;
 
int main(){ 
	
	FAST_IO;
   
	int n,k;
	cin>>n>>k;

	int h[n];

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

	int dp[n];
	dp[0] = 0;
	dp[1] = abs(h[0] - h[1]);

	for(int i=2; i<n; i++){
		int temp = INT_MAX;
		for(int j=1; j<=k; j++){
			if(i-j>=0)
				temp = min(temp,dp[i-j] + abs(h[i]-h[i-j]));
		}
		dp[i] = temp;
	}

	cout<<dp[n-1]<<endl;
}
 

Measured memory_bytes: 1024
#include<iostream>
#include<string>
#include <vector>
#include<queue>
#include<map>
#include<algorithm>
#include<iomanip>
#include<cmath>
#include<bitset>
using namespace std;
using vi = vector<int>;
using vii = vector<vi>;
using vs = vector<string>;
using pii = pair<int, int>;
#define rep(i,n) for(int i=0;i<n;i++)
#define rep2(i,m,n) for(int i=m;i<n;i++)
#define vsort(v) sort(v.begin(), v.end())
#define rv(v) reverse(v.begin(), v.end())
#define ll long long
#define PI 3.141592653589793
using vll = vector<ll>;
using Graph = vii;
const ll MOD = 1e9 + 7;

int main() {
	int n;
	cin >> n;
	vll a(n);
	ll sum = 0;
	ll sum2 = 0;
	rep(i, n) {
		cin >> a[i];
		sum += a[i];
		if (i % 2 == 1) sum2 += a[i];
	}
	vll b(n);
	b[0] = sum - 2 * sum2;
	for (int i = 1; i < n; i++) {
		b[i] = 2 * a[i - 1] - b[i - 1];
	}
	rep(i, n - 1) {
		cout << b[i] << " ";
	}
	cout << b[n - 1] << endl;
}

Measured memory_bytes: 2944
#include <bits/stdc++.h>
using namespace std;
int main() {
    int n; cin>>n;
    vector<int> p(n);
    int count=0;
    for(int i=0;i<n;i++){
        cin>>p[i];
    }
    for(int i=0;i<n;i++){
        if(i!=0&&i!=n-1) {
            if ((p[i] < p[i - 1] && p[i] > p[i + 1]) || (p[i] > p[i - 1] && p[i] < p[i + 1])) {
                count++;
            }
        }
    }
    cout<<count;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ss second
#define ff first
#define all(x) x.begin(), x.end()

// #define DEBUG 100

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

const int oo = 1e9 + 7;
const ll mod = 1e9 + 7,maxn = 100010;
const double PI = acos(-1);

int main (){
    ios_base::sync_with_stdio(false);
    cin.tie(0); 
    int a, b, c;
    cin >> a >> b >> c;

    cout << c << " " << a <<" " << b << endl;
    return 0;
}

Measured memory_bytes: 3576
#include <limits.h>
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

#define int long long
#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define REPS(i, n) for (int i = 1, i##_len = (n); i <= i##_len; ++i)
#define FOR(i, a, b) for (int i = (a), i##_len = (b); i <= i##_len; ++i)
#define REV(i, a, b) for (int i = (a); i >= (b); --i)
#define CLR(a, b) memset((a), (b), sizeof(a))
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define INF 1001001001001001001ll
#define fcout cout << fixed << setprecision(10)

using namespace std;

typedef pair<int, int> P;

// Range Maximum Query
struct SegmentTree {
private:
    int n;
    vector<int> node;

public:
    SegmentTree(vector<int> v) {
        int sz = v.size();
        n = 1;
        while (n < sz) n *= 2;
        node.resize(2 * n - 1, -INF);
        for (int i = 0; i < sz; i++) node[i + n - 1] = v[i];
        for (int i = n - 2; i >= 0; i--) node[i] = max(node[2 * i + 1], node[2 * i + 2]);
    }

    void update(int x, int val) {
        x += (n - 1);
        node[x] = val;
        while (x > 0) {
            x = (x - 1) / 2;
            node[x] = max(node[2 * x + 1], node[2 * x + 2]);
        }
    }

    int getmax(int a, int b, int k = 0, int l = 0, int r = -1) {
        if (r < 0) r = n;
        if (r <= a || b <= l) return -INF;
        if (a <= l && r <= b) return node[k];

        int vl = getmax(a, b, 2 * k + 1, l, (l + r) / 2);
        int vr = getmax(a, b, 2 * k + 2, (l + r) / 2, r);
        return max(vl, vr);
    }
};

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);

    int N;
    cin >> N;

    int maxh = -INF;
    vector<int> h(N);
    REP(i, N) {
        cin >> h[i];
        maxh = max(maxh, h[i]);
    }
    vector<int> a(N);
    REP(i, N) cin >> a[i];

    vector<int> v(maxh + 1, 0);
    SegmentTree tree(v);

    REP(i, N) {
        int val = tree.getmax(0, h[i]);
        tree.update(h[i], val + a[i]);
    }
    cout << tree.getmax(0, maxh + 1) << endl;

    return 0;
}


Measured memory_bytes: 10624
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        String[] n = sc.next().split("");
        int cnt = 0;
        for (String tmp : n) {
            if (tmp.equals("1")) cnt++;
        }
        System.out.println(cnt);
    }
}


Measured memory_bytes: 21716
#![allow(
  non_snake_case,
  unused_variables,
  unused_assignments,
  unused_mut,
  unused_imports,
  dead_code
)]
use proconio::fastout;
use proconio::input;
use proconio::marker::*;
use std::cmp::*;
use std::collections::*;
//use std::collections::VecDeque;

macro_rules! debug {
  ($($a:expr),* $(,)*) => {
      #[cfg(debug_assertions)]
      eprintln!(concat!($("| ", stringify!($a), "={:?} "),*, "|"), $(&$a),*);
  };
}
#[fastout]
fn main() {
  input! {
    R:usize,C:usize,K:usize,
    RCV:[(usize,usize,i64);K]
  }
  let mut RCV: Vec<(usize, usize, i64)> = RCV;
  // dp[r,c,n]位置(r,c)にいるときに、その行でn個以下のアイテムを拾っているときのtotal
  // r,cのスタートは(1,1)から、(R,C)に移動するまで。
  // つまり、r+cがR+C-2になるまで。
  let mut v = vec![vec![0; C + 1]; R + 1];
  for &(r, c, x) in RCV.iter() {
    v[r][c] = x;
  }
  debug!(v);
  let mut dp = vec![vec![vec![0; 4]; C + 1]; R + 1];
  for r in 1..=R {
    for c in 1..=C {
      debug!(r, c);
      // 移動のみ
      for i in 0..=3 {
        dp[r][c][i] = max(dp[r - 1][c][3], dp[r][c - 1][i]);
      }
      // 拾う。
      if v[r][c] > 0 {
        for i in (1..=3).rev(){
          dp[r][c][i] = max(dp[r][c][i], dp[r][c][i-1] + v[r][c]);
        }
        debug!(r, c, dp[r]);
      }
    }
  }
  println!("{}", dp[R][C][3])
}


Measured memory_bytes: 713696
#include<iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main(){
    int a, b;
    cin >> a >> b;
    vector<int> curr;
    if(a == 0) {
        cout << 1 << endl;
        return 0;
    }
    while(a){
        curr.push_back(a%b);
        a /= b;
    }
    reverse(curr.begin(), curr.end());
    cout << curr.size();
    cout << endl;
    return 0;
}

Measured memory_bytes: 888
#include<bits/stdc++.h>
using namespace std;
int f[250009];
int x[509];
int S[509];
main(){
    int n;
    cin >> n;
    vector<pair<int,int> > X;
    for(int i = 1; i <= n; i++){
        cin >> x[i];
        f[x[i]] = i;
        X.push_back({x[i],i});

    }
    sort(X.begin(), X.end());
    vector<int> v;
    for(int i = 0; i < n; i++){
        for(int j = 0; j < X[i].second - 1; j++)
            v.push_back(X[i].second),S[X[i].second]++;
    }
    int k = 0;
    for(int i = 1; i <= n*n; i++){
        if(f[i]){
            if(S[f[i]]){
                cout<<"No"<<endl;
                return 0;
            }
            for(int j = 0; j < n - f[i]; j++)
                v.push_back(f[i]),
                S[f[i]]++;
            continue;

        }
        if(k >= v.size()) {
            cout << "No"<<endl;
            return 0;
        }
        f[i] = v[k];
        S[f[i]] --;
        k ++;
    }
    cout<< "Yes"<<endl;
    for(int i = 1; i <= n * n; i++){
        cout << f[i] <<" ";
    }
    cout<<endl;


}


Measured memory_bytes: 3196
from collections import Counter
N = int(input())
P = []
Q = []
for L in range(1, N+1):
    L = str(L)
    a = int(L[0])
    b = int(L[-1])
    if a == 0 or b == 0:
        continue
    P.append((a, b))
C = Counter(P)

ans = 0
for i in range(len(P)):
    q = (P[i][-1], P[i][0])
    ans += C[q]

print(ans)

Measured memory_bytes: 22240
using namespace std;

//#define fileio

#ifndef fileio
#include <iostream>
#endif
#include <fstream>
#include <vector>
#include <queue>
#include <algorithm>
#include <set>
#include <map>
#include <assert.h>
#include <functional>
#include <math.h>
#include <string>
#include <ctime>

typedef long long ll;

#ifdef fileio
ifstream cin;
ofstream cout;
#endif





int main() {
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    #ifdef fileio
    cin.open("Text.txt");
    cout.open("Output.txt");
    #endif

    string s;
    cin >> s;
    int tot = 0;
    for (char c : s) {
        tot += (c - '0');
        tot %= 9;
    }
    cout << ((tot == 0) ? "Yes" : "No") << endl;
}

Measured memory_bytes: 3740
parseInt(x) = parse(Int, x)
parseMap(x::Array{SubString{String},1}) = map(parseInt, x)

function main()
	n,k,q = readline() |> split |> parseMap
	a = readline() |> split |> parseMap
	b = Tuple{Int,Int}[(a[i],i) for i in 1:n]
	b = sort(b,by=x->x[1])
	ans = b[n][1]-b[1][1]
	ct = Int[0,n+1]
	for i in 1:n
		f = 0
		cand = Int[]
		for j in 2:length(ct)
			za = Int[]
			for z in ct[j-1]+1:ct[j]-1
				push!(za,a[z])
			end
			if length(za)>=k
				za = sort(za)
				for ii in 1:length(za)-k+1
					push!(cand,za[ii])
				end
			end
		end
		if length(cand) >= q
			cand = sort(cand)
			ans = min(ans,cand[q]-cand[1])
		end
		push!(ct,b[i][2])
		ct = sort(ct)
	end
	println(ans)
end

main()

Measured memory_bytes: 164908
#include <iostream>
#include <stack>
#include <math.h>
#include <vector>
#include <string>
#include <algorithm>
#include <map>

#define rep(i,n) for(int i=0; i < n; i++)
using ll =  long long;
using namespace std;
#define pi 3.14159265358979

int main()
{
	int n, m;
	cin >> n >> m;
	int first = 0, last = n + 1;
	rep(i, m)
	{
		int l, r;
		cin >> l >> r;
		first = max(l, first);
		last = min(r, last);
	}
	if (first <= last) cout << last - first + 1 << endl;
	else cout << 0 << endl;
	return 0;
}

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

using namespace std;

int main(){    
    long long A,B,K,temp;

    cin >> A >> B >> K;

    temp = A;

    if(A >= K){
        A -= K;
    }else{
        K -= A;
        A = 0;
        if(B > K){
            B -= K;
        }else{
            B = 0;
        }
    }

    cout << A << " " << B << endl;

    return 0;
}

Measured memory_bytes: 256
import itertools
while True:
    n, x = map(int, input().split())
    if n ==0 and x == 0:
        break
    cnt = 0
    nums = list(range(1,n+1))
    for i in itertools.combinations(nums, 3):
        if sum(i) == x:
            cnt += 1
    print(cnt)


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

#define INF 1.1e9
#define LINF 1.1e18
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) for (int i = (n) - 1; i >= 0; i--)
#define ALL(v) (v).begin(), (v).end()
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define BIT(x, n) bitset<n>(x)
#define PI 3.14159265358979323846

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

//-----------------------------------------------------------------------------

ll a, b, c, x, y;

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

	cin >> a >> b >> c >> x >> y;

	ll A = a * x + b * y;
	ll B = c * x * 2;
	if (y > x) B += b * (y - x);
	ll C = c * y * 2;
	if (x > y) C += a * (x - y);
	ll D = max(x, y) * c * 2;
	cout << min(min(A, B), min(C, D)) << endl;

    return 0;
}


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

using namespace std;

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

  vector<vector<int>> bingo(3, vector<int>(3));
  map<int, pair<int, int>> m;
  for (int i = 0; i < 3; ++i) {
    for (int j = 0; j < 3; ++j) {
      cin >> bingo[i][j];
      m[bingo[i][j]] = {i, j};
    }
  }
  int N, b;
  cin >> N;
  while (N--) {
    cin >> b;
    if (m.find(b) != m.end()) {
      bingo[m[b].first][m[b].second] = 0;
    }
  }

  string res = "No";
  for (int i = 0; i < 3; ++i) 
    if (bingo[i][0] + bingo[i][1] + bingo[i][2] == 0) res = "Yes";

  for (int i = 0; i < 3; ++i) 
    if (bingo[0][i] + bingo[1][i] + bingo[2][i] == 0) res = "Yes";

  for (int i = 0; i < 3; ++i) 
    if (bingo[0][0] + bingo[1][1] + bingo[2][2] == 0) res = "Yes";

  for (int i = 0; i < 3; ++i) 
    if (bingo[2][0] + bingo[1][1] + bingo[0][2] == 0) res = "Yes";

  cout << res << endl;

	return 0;
}



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

int main(){
  int n, m;
  cin >> n >> m;
  vector<int> v[n+1];
  pair<int, int> city[m];
  int p, y;
  for ( int i = 0; i < m; i++){
    cin >> p >> y;
    city[i] = make_pair(p, y);
    v[p].push_back(y);
  }


  for ( int i = 1; i <= n; i++){
    sort(v[i].begin(), v[i].end());
  }

  int order;
  for ( int i = 0; i < m; i++){
    order = lower_bound(v[city[i].first].begin(), v[city[i].first].end(), city[i].second) - v[city[i].first].begin() + 1;
    cout << setfill('0') << right << setw(6) << city[i].first << setfill('0') << right << setw(6) << order << endl;
  }

  return 0;
}

Measured memory_bytes: 7680
a, b, c = list(map(int, input().split()))

m = max(a, b, c)
s = sum([a, b, c])
if (3 * m - s) % 2 == 0:
    print((3 * m - s) // 2)
else:
    print((3 * m + 3 - s) // 2)

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

B = list(map(int, input().split()))

sum_ = 0

for i in range(N):
    if i == 0:
        sum_ += B[0]
    elif i == N - 1:
        sum_ += B[-1]
    else:
        sum_ += min(B[i - 1], B[i])

print(sum_)


Measured memory_bytes: 3060
package main

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

// I/O
type Scanner struct {
	sc *bufio.Scanner
}

func NewScanner() *Scanner {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 1024), int(1e+9))
	return &Scanner{sc}
}

func (s *Scanner) nextStr() string {
	s.sc.Scan()
	return s.sc.Text()
}

func (s *Scanner) nextInt() int {
	i, e := strconv.Atoi(s.nextStr())
	if e != nil {
		panic(e)
	}
	return i
}

func (s *Scanner) nextFloat() float64 {
	f, e := strconv.ParseFloat(s.nextStr(), 64)
	if e != nil {
		panic(e)
	}
	return f
}

func (s *Scanner) nextRuneSlice() []rune {
	return []rune(s.nextStr())
}

func (s *Scanner) nextIntSlice(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextInt()
	}
	return res
}

func (s *Scanner) nextFloatSlice(n int) []float64 {
	res := make([]float64, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextFloat()
	}
	return res
}

// Arithmetic
func max(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m < i {
			m = i
		}
	}
	return m
}

func min(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m > i {
			m = i
		}
	}
	return m
}

func abs(x int) int {
	if x > 0 {
		return x
	}
	return -x
}

func pow(x, y int) int {
	res := 1
	for i := 0; i < y; i++ {
		res *= x
	}
	return res
}

// Sort
type Val struct {
	id, num int
}
type ByNum []Val

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

func main() {
	sc := NewScanner()
	wtr := bufio.NewWriter(os.Stdout)
	S := sc.nextRuneSlice()
	ans := 0
	left := 0
	right := len(S) - 1
	for left < right {
		if S[left] != S[right] {
			ans++
		}
		left++
		right--
	}

	fmt.Fprintln(wtr, ans)
	wtr.Flush()
}


Measured memory_bytes: 640
#include <iostream>
#include <string>
using namespace std;
int main(void){
    int N,K;//N=人数、K=お菓子の種類
    cin >> N >> K;
    int tempSweets;
    int tempPos;
    int SNK[N];
    for(int& x:SNK)x=0;//初期化
    
    for(int i=0;i<N;i++){
        cin >> tempSweets;
        for(int j=0;j<tempSweets;j++){
            cin >> tempPos;
            SNK[tempPos-1]++;
        }
    }
    int OUTcount=0;
    for(int x:SNK)if(x==0)OUTcount++;
    
    cout << OUTcount << endl;
    
    return 0;
}


Measured memory_bytes: 3636
#include <iostream>
#include <vector>
#include <cmath>
#include <string>
#include <algorithm>
#include <iomanip>
#include <map>
#include <bitset>
#include <cstdio>
#include <set>
#include <stack>
#include <queue>
#include <cassert>
#include <numeric>
#define rep(i,n) Rep(i,0,n)
#define Rep(i,k,n) for(int i=k ; i<n ; i++)
#define rep1(i,n) for(int i=1 ; i<=n ; i++)
#define vi vector<int>
#define vii vector<vector<int>>
#define mii map<int,int>
#define Sort(v) sort(v.begin(),v.end())
#define Reverse(v) reverse(v.begin(),v.end())
#define ALL(a)  (a).begin(),(a).end()
#define pb push_back
//#define int ll
typedef long long ll;

const int md = 1000000007;
const int INF = 1<<30;
using namespace std;

string yn(bool x){
    return x ? "Yes" : "No";
}

int main(){
    int n; cin >> n;
    int l[n];
    int sum = 0;
    rep(i,n) {
        cin >> l[i];
        sum += l[i];
    }
    sort(l,l+n);

    bool ans;
    if(l[n-1] < sum - l[n-1]) ans = true;
    else ans = false;

    cout << yn(ans) << endl;
}

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

int main()
{
    char str1[105];
    char str2[] = "keyence";
    bool flag = false;
    int i, j;
    scanf("%s", str1);
    i = j = 0;
    while (i <= strlen(str1))
    {
        if (str1[i] == str2[j])
        {
            i++;
            j++;
            if (j == 7)
            {
                flag = true;
                break;
            }
            continue;
        }
        else
        {
            while (i <= strlen(str1))
            {
                if (str1[i] == str2[j])
                    if (strcmp(str1 + i, str2 + j) == 0)
                    {
                        flag = true;
                        break;
                    }
                i++;
            }
        }
    }
    if (flag == true)
        printf("YES\n");
    else
        printf("NO\n");
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
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;}
using Int = long long;
const char newl = '\n';


template<typename T>
vector<T> make_v(size_t a){return vector<T>(a);}

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

template<typename T,typename U,typename... V>
typename enable_if<is_same<T, U>::value!=0>::type
fill_v(U &u,const V... v){u=U(v...);}

template<typename T,typename U,typename... V>
typename enable_if<is_same<T, U>::value==0>::type
fill_v(U &u,const V... v){
  for(auto &e:u) fill_v<T>(e,v...);
}

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

  int n,m,x;
  cin>>n>>m>>x;

  vector<int> cs(n);
  auto A=make_v<int>(n,m);
  for(int i=0;i<n;i++){
    cin>>cs[i];
    for(int j=0;j<m;j++) cin>>A[i][j];
  }

  const int INF = 1e9;
  int ans=INF;

  int sz=1<<n;
  for(int b=0;b<sz;b++){
    vector<int> rs(m,0);
    int cost=0;
    for(int i=0;i<n;i++){
      if((~b>>i)&1) continue;
      cost+=cs[i];
      for(int j=0;j<m;j++)
        rs[j]+=A[i][j];
    }
    int flg=1;
    for(int j=0;j<m;j++) flg&=rs[j]>=x;
    if(flg) chmin(ans,cost);
  }

  if(ans==INF) ans=-1;
  cout<<ans<<newl;
  return 0;
}


Measured memory_bytes: 3680
#include<stdio.h>
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
struct R{string word;
int nl;int ty;

};

int main(){

	int n,k,s;
	while(1){
		cin>>n>>k>>s;
		if(n==0&&k==0&&s==0)break;
		int d=0;
		for(int i1=1;i1<=n;i1++)
		{if(k==1){if(i1==s)d++;}
		else{
		for(int i2=i1+1;i2<=n;i2++)
		{if(k==2){if(i1+i2==s)d++;}
		else{
		for(int i3=i2+1;i3<=n;i3++)
		{if(k==3){if(i1+i2+i3==s)d++;}
		else{
		for(int i4=i3+1;i4<=n;i4++)
		{if(k==4){if(i1+i2+i3+i4==s)d++;}
		else{
		for(int i5=i4+1;i5<=n;i5++)
		{if(k==5){if(i1+i2+i3+i4+i5==s)d++;}
		else{
		for(int i6=i5+1;i6<=n;i6++)
		{if(k==6){if(i1+i2+i3+i4+i5+i6==s)d++;}
		else{
		for(int i7=i6+1;i7<=n;i7++)
		{if(k==7){if(i1+i2+i3+i4+i5+i6+i7==s)d++;}
		else{
		for(int i8=i7+1;i8<=n;i8++)
		{if(k==8){if(i1+i2+i3+i4+i5+i6+i7+i8==s)d++;}
		else{
		for(int i9=i8+1;i9<=n;i9++)
		{if(k==9){if(i1+i2+i3+i4+i5+i6+i7+i8+i9==s)d++;}
		else{
			for(int i10=i9+1;i10<=n;i10++)
		{if(k==10)if(i1+i2+i3+i4+i5+i6+i7+i8+i9+i10==s)d++;}
		}}}}}}}}}}}}}}}}}}
	
	cout<<d<<endl;
	
	}	
	return 0;
}

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

#define REP(i ,n) for(int i=0 ;i < n; i++)
#define REPB(i ,n) for(int i=n; i >= 0; i--)
#define FOR(i ,m ,n) for(int i=m; i < n; i++)
#define FORB(i, m, n) for(int i=m; i>= m; i--)
#define ll long long
#define pb push_back
#define popb pop_back
#define debug(i) cout << i << endl
using namespace std;
int main(){
  int n,k;
  cin >> n >> k;
  if((k * 2 - 1) <= n) cout << "YES" << endl;
  else cout << "NO" << endl;
}

Measured memory_bytes: 256
def sol():
    S = input()

    if S[0] != 'A':
        print('WA')
        return

    if S[2: -1].count('C') != 1:
        print('WA')
        return

    for s in S[2:-1]:
        if s != 'C' and s.isupper():
            print('WA')
            return

    if S[1].isupper() or S[-1].isupper():
        print('WA')
        return

    print('AC')

sol()

Measured memory_bytes: 3060
#include <algorithm>
#include <bitset>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

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

#define dump(x) cout << #x << " = " << (x) << endl;
#define YES(n) cout << ((n) ? "YES" : "NO") << endl

void chmin(ll &a, ll b) {
  if (a > b) {
    a = b;
  }
}
void chmax(ll &a, ll b) {
  if (a < b) {
    a = b;
  }
}

int main() {
  int k, n;
  cin >> k >> n;

  vector<int> poss = vector<int>(n, 0);

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

  ll maxlen = -INF;
  for (int i = 0; i < n - 1; i++) {
    int dis = poss[i + 1] - poss[i];
    chmax(maxlen, dis);
  }

  int lastdis = (k - poss[n - 1]) + poss[0];
  chmax(maxlen, lastdis);

  cout << (k - maxlen) << endl;
}

/*
9 3
1 3 6
*/

Measured memory_bytes: 1152
#include<iostream>
#include<string>
using namespace std;
int main(){
  int c=0;
  int cc=0;
  string s;
  int n,a,b,f;
  cin >> n >>a >> b >> s;
  for(int i=0;i<n;i++){
    f=0;
    if(s[i]=='a'){
      if(c+cc<a+b){
	c++;
	cout << "Yes" << endl;
	f++;
      }
    }
    else if(s[i]=='b'){
      if(c+cc<a+b&&cc<b){
	cc++;
	cout << "Yes" << endl;
	f++;
      }
    }
    if(f==0)cout << "No" << endl;
  }
  return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
using pll = pair<ll, ll>;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define rrep(i, m, n) for(ll i = m; i > n; i--)
#define Rep(i, m, n) for(ll i = m; i < n; i++)
#define all(vec) vec.begin(), vec.end()
#define lmax(x, y) max<ll>(x, y)
#define lmin(x, y) min<ll>(x, y)
#define tmax(x, y, z) lmax((x), lmax((y), (z)))
#define tmin(x, y, z) lmin((x), lmin((y), (z)))
#define MINUS(a) memset(a, 0xff, sizeof(a))
#define ZERO(a) memset(a, 0, sizeof(a))
const ll INF = 1LL << 60;
const ll MM = 1000000000; const ll MOD = MM + 7; const ll MMM=9223372036854775807;//2^63 -1
#define ADD(a,b) a = (a + ll(b)) % MOD
#define MUL(a,b) a = (a * ll(b)) % MOD
ll GCD(ll x, ll y){ if(y == 0) return x; else return GCD(y, x % y);}
ll LCM(ll x, ll y){ return x / GCD(x, y) * y;}
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;}
template<typename A, size_t N, typename T> void FILL(A (&array)[N], const T &val){ fill( (T*)array, (T*)(array+N), val );}
// struct edge{ ll from, to, cost; };
// struct edge{ ll to, cost; };
// using Graph = vector<vector<ll>>;  // 重み無し
// using Graph = vector<edge>;  // 辺
// using Graph = vector<vector<edge>>;  // 重み付き
ll dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
ll ddx[8] = {1, 1, 0, -1, -1, -1, 0, 1}, ddy[8] = {0, 1, 1, 1, 0, -1, -1, -1};
//cout << fixed << setprecision(10);
// priority_queue<ll, vector<ll>, greater<ll>> pq;


int main(){
    ll n, ans = 0; cin >> n;
    vector<ll> a(n), b(n), c(n);
    rep(i, n) cin >> a[i];
    rep(i, n) cin >> b[i];
    rep(i, n) cin >> c[i];
    sort(all(a));
    // sort(all(b));
    sort(all(c));
    rep(i, n){
        auto itra = lower_bound(all(a), b[i]), itrc = upper_bound(all(c), b[i]);
        ans += (itra - a.begin()) * (c.end() - itrc);
    }
    cout << ans << endl;
}


Measured memory_bytes: 5612
_, x = map(int, input().split())
a = [int(i) for i in input().split()]
cnt = 0

for i in range(len(a) - 1):
    s = a[i] + a[i + 1]
    if x < s:
        sub = s - x
        a[i + 1] = max(0, a[i + 1] - sub)
        cnt += sub
print(cnt)


Measured memory_bytes: 63984
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <cstring>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <unordered_set>
#include <unordered_map>
using namespace std;

using LL = long long;
LL n, l, q;
LL x[114514];
LL lef[17][114514], rht[17][114514];

int main(void)
{
	cin >> n;
	for (int i = 0; i < n; ++i)
	{
		cin >> x[i];
	}
	cin >> l;
	int cent = 0;
	for (int i = 0; i < n; ++i)
	{
		while (cent < n && x[cent] - x[i] <= l)cent++;
		lef[0][i] = cent - 1;
	}
	int claw = n - 1;
	for (int j = n - 1; j >= 0; --j)
	{
		while (claw >= 0 && x[j] - x[claw] <= l)claw--;
		rht[0][j] = claw + 1;
	}
	for (int lev = 1; lev < 17; ++lev)
	{
		for (int i = 0; i < n; ++i)
		{
			lef[lev][i] = lef[lev - 1][lef[lev - 1][i]];
			rht[lev][i] = rht[lev - 1][rht[lev - 1][i]];
		}
	}
	cin >> q;
	for (int i = 0; i < q; ++i)
	{
		LL a, b;
		cin >> a >> b;
		--a; --b;
		LL hi = n, lo = 0;
		while (lo + 1 < hi)
		{
			LL mid = (hi + lo) / 2;
			LL small = a, large = a;
			for (int bit = 0; bit < 17; ++bit)
			{
				if ((1 << bit) & mid)
				{
					large = lef[bit][large];
					small = rht[bit][small];
				}
			}
			if (small <= b && b <= large)
			{
				hi = mid;
			}
			else
			{
				lo = mid;
			}
		}
		cout << hi << endl;
	}
	return 0;
}


Measured memory_bytes: 31872
// AOJ ITP 1_5_D
#include<cstdio>

void call( int n )
{
	int i = 1;
	do
	{
		int x = i;
		
		if( x % 3 == 0 )
			printf( " %d", i );
		else
		{
			do
			{
				if( x % 10 == 3 )
				{
					printf( " %d", i );
					break;
				}
				x /= 10;
			} while( x );
		}
	}while( ++i <= n );

	puts("");

	return;
}

int main()
{
	int n;
	scanf( "%d", &n );
	call( n );
	
	return 0;
}

Measured memory_bytes: 1036
a = int(input())
M = 1000000
m = 1

while m <= M:
    if a in (1, 2, 4):
        m += 3
        break
    if a % 2 == 0:
        a //= 2
    else:
        a = 3 * a + 1
    m += 1

print(m)


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

bool isPrime(int x){
    if(x == 1 || (x > 2 && x % 2 == 0)){
        return false;
    }
    int i = 3, max = (int)sqrt(x) + 1;
    //cout << x << ", " << max << endl;
    while(i < max){
        if(x % i == 0){
            return false;
        }
        i += 2;
    }
    return true;
}
int main(){
    int n, i, x, cnt = 0;
    vector<int> v;
    cin >> n;
    for(i = 0; i < n; i++){
        cin >> x;
        v.push_back(x);
    }
    vector<int>::iterator ite = v.begin();
    while(ite != v.end()){
        if(isPrime(*ite)){
            /*if(cnt++ != 0){
                cout << " ";
            }
            cout << *ite;
            */
            cnt++;
        }
        ite++;
    }
    cout << cnt <<endl;
    return 0;
}

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

int main() {
  int N, ans=0;
  cin >> N;
  
  vector<int> vec(N);
  for(int i=0; i<N; i++){
    cin >> vec.at(i);
  }
  
  sort(vec.begin(),vec.end());
  reverse(vec.begin(),vec.end());
  
  for(int i=0; i<N; i++){
    if(i%2 == 0){
      ans += vec.at(i);
    }
    if(i%2 == 1){
      ans -= vec.at(i);
    }
  }
  
  cout << ans << endl;
}

Measured memory_bytes: 256
#!/usr/bin/env python

import sys
import math
import itertools as it
from collections import deque

sys.setrecursionlimit(10000000)

A1, A2, A3 = map(int, raw_input().split())

lst = [abs(A1 - A2), abs(A1 - A3), abs(A3 - A2)]
lst.sort()
print lst[0] + lst[1]

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

typedef long long int ll;
ll MOD = 1000000007;
ll INFL = 1ll << 60;
ll INF = 1 << 28;

template <typename T>
ostream& operator<<(ostream& os, vector<T>& vec) {
  cout << "{";
  for (int i = 0; i < vec.size(); i++)
    os << vec[i] << (i + 1 == vec.size() ? "" : " ");
  cout << "}";
  return os;
}

// ====================================================================

int main() {
  int n, m;
  cin >> n >> m;
  vector<int> h(n);
  for (int i = 0; i < n; i++) cin >> h[i];

  vector<int> g[n];  // グラフ
  for (int i = 0; i < m; i++) {
    int s, t;
    cin >> s >> t;
    s--, t--;
    g[s].push_back(t);
    g[t].push_back(s);
  }

  int count = 0;
  for (int i = 0; i < n; i++) {
    bool can = true;
    // cout << g[i] << endl;
    for (int j = 0; j < g[i].size(); j++) {
      if (h[i] <= h[g[i][j]]) {  // 高さで負けてる
        can = false;
      }
    }
    // if (can) cout << "yes" << endl;
    count += can;
  }

  cout << count << endl;
}


Measured memory_bytes: 8800
#include <bits/stdc++.h>
#define rep(i,s,n) for (int i = (s); i < (n); i++)
using namespace std;
using ll = long long;
int main() {
  int a,b,c,d;
  cin >> a >> b >> c >> d;
  cout << min(a,b) + min(c,d) << endl;
  return 0;
}

Measured memory_bytes: 3620
import java.util.*;
import java.io.*;
public class Main {
    public static void main(String[] args) throws Exception {
        InputStreamReader r = new InputStreamReader(System.in);
        int N = nextInt(r);
        int K = nextInt(r);
        int R = nextInt(r);
        int S = nextInt(r);
        int P = nextInt(r);
        // System.out.println(N+" "+K+" "+R+" "+S+" "+P);
        int d = N / K + 1;
        int[][] T = new int[3][K];

        int ans = 0;
        for (int i = 0; i < d; i++) {
            for (int j = 0; j < K; j++) {
                int c = r.read();
                if (c == -1 || c == 10) {
                    break;
                }
                if (i%2 == 0) {
                    T[0][j] = c;
                } else {
                    T[1][j] = c;
                }
                if (c == 114) {
                    ans += getPoint(i, j, P, T);
                } else if (c == 115) {
                    ans += getPoint(i, j, R, T);
                } else {
                    ans += getPoint(i, j, S, T);
                }
            }
        }
        System.out.println(ans);
    }

    public static int nextInt(InputStreamReader r) throws Exception {
        String str = "";
        while (true) {
            int c = r.read();
            if (c == 32 || c == 10) {
                break;
            }
            str += (char)c;
        }
        return Integer.parseInt(str);
    }

    public static int getPoint(int i, int j, int p, int[][] T) {
        int point = 0;
        if (T[0][j] == T[1][j] && T[2][j] == 0) {
            T[2][j] = 1;
        } else {
            point = p;
            T[2][j] = 0;
        }
        return point;
    }
}

Measured memory_bytes: 28224
//#define _GLIBCXX_DEBUG

#include<bits/stdc++.h>
using namespace std;

#define endl '\n'
#define lfs cout<<fixed<<setprecision(10)
#define ALL(a)  (a).begin(),(a).end()
#define ALLR(a)  (a).rbegin(),(a).rend()
#define spa << " " <<
#define fi first
#define se second
#define MP make_pair
#define MT make_tuple
#define PB push_back
#define EB emplace_back
#define rep(i,n,m) for(ll i = (n); i < (ll)(m); i++)
#define rrep(i,n,m) for(ll i = (ll)(m) - 1; i >= (ll)(n); i--)
using ll = long long;
using ld = long double;
const ll MOD1 = 1e9+7;
const ll MOD9 = 998244353;
const ll INF = 1e18;
using P = pair<ll, ll>;
template<typename T1, typename T2>bool chmin(T1 &a,T2 b){if(a>b){a=b;return true;}else return false;}
template<typename T1, typename T2>bool chmax(T1 &a,T2 b){if(a<b){a=b;return true;}else return false;}
ll median(ll a,ll b, ll c){return a+b+c-max({a,b,c})-min({a,b,c});}
void ans1(bool x){if(x) cout<<"Yes"<<endl;else cout<<"No"<<endl;}
void ans2(bool x){if(x) cout<<"YES"<<endl;else cout<<"NO"<<endl;}
void ans3(bool x){if(x) cout<<"Yay!"<<endl;else cout<<":("<<endl;}
template<typename T1,typename T2>void ans(bool x,T1 y,T2 z){if(x)cout<<y<<endl;else cout<<z<<endl;}  
template<typename T>void debug(vector<vector<T>>&v,ll h,ll w){for(ll i=0;i<h;i++){cout<<v[i][0];for(ll j=1;j<w;j++)cout spa v[i][j];cout<<endl;}};
void debug(vector<string>&v,ll h,ll w){for(ll i=0;i<h;i++){for(ll j=0;j<w;j++)cout<<v[i][j];cout<<endl;}};
template<typename T>void debug(vector<T>&v,ll n){if(n!=0)cout<<v[0];for(ll i=1;i<n;i++)cout spa v[i];cout<<endl;};
template<typename T>vector<vector<T>>vec(ll x, ll y, T w){vector<vector<T>>v(x,vector<T>(y,w));return v;}
ll gcd(ll x,ll y){ll r;while(y!=0&&(r=x%y)!=0){x=y;y=r;}return y==0?x:y;}
vector<ll>dx={1,-1,0,0,1,1,-1,-1};vector<ll>dy={0,0,1,-1,1,-1,1,-1};
template<typename T>vector<T> make_v(size_t a,T b){return vector<T>(a,b);}
template<typename... Ts>auto make_v(size_t a,Ts... ts){return vector<decltype(make_v(ts...))>(a,make_v(ts...));}
template<typename T1, typename T2>ostream &operator<<(ostream &os, const pair<T1, T2>&p){return os << p.first << " " << p.second;}
template<typename T>ostream &operator<<(ostream &os, const vector<T> &v){for(auto &z:v)os << z << " ";cout<<"|"; return os;}
//mt19937 mt(chrono::steady_clock::now().time_since_epoch().count());

int main(){
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  ll res=0,buf=0;
  bool judge = true;
  ll n,q;cin>>n>>q;
  ll rem=(n-2)*(n-2);
  ll rx=n,ry=n;
  vector<ll>vx(n,-1),vy(n,-1);
  while(q--){
    ll t,x;cin>>t>>x;
    if(t==1){
      if(x<rx){
        rem-=ry-2;
        rep(i,x,rx)vx[i]=ry;
        rx=x;
      }
      else{
        rem-=vx[x]-2;
      }
    }
    else{
      if(x<ry){
        rem-=rx-2;
        rep(i,x,ry)vy[i]=rx;
        ry=x;
      }
      else{
        rem-=vy[x]-2;
      }
    }
    //cout<<rem spa rx spa ry<<endl;
    //debug(vx,n);
    //debug(vy,n);
  }
  cout<<rem<<endl;
  return 0;
}

Measured memory_bytes: 6356
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (int)(n); ++i)
using P = pair<int,int>;
using ll = long long;
static const int INF = 1000000000;
static const ll MOD = 1000000007;
ll gcd(ll a, ll b){return b!=0 ? gcd(b, a%b) : a;}
ll lcm(ll a, ll b){return a / gcd(a, b) * b;}

int main(){
  int n;
  cin >> n;
  vector<int> a(n), b(n), c(n);
  rep(i, n) cin >> a[i];
  rep(i, n) cin >> b[i];
  rep(i, n) cin >> c[i];

  sort(a.begin(), a.end());
  sort(b.begin(), b.end());
  sort(c.begin(), c.end());

  ll ans = 0;
  rep(i, n){
    int key = b[i];
    ll ai = lower_bound(a.begin(), a.end(), key) - a.begin();
    ll ci = c.end() - upper_bound(c.begin(), c.end(), key);
    ans += ai * ci;
  }

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

Measured memory_bytes: 1408
#include <algorithm>
#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <cmath>

using namespace std;
using ll = long long;
using ull = unsigned long long;

constexpr ll LLINF {1001002003004005006};//ll = 9*LLINF
constexpr int INTINF {1000000000};//int = 2*INTINF

#define  rep(i,n)   for(int i = 0; i < (n); ++i)
#define rrep(i,n)   for(int i = 1; i <= (n); ++i)
#define drep(i,n)   for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for(int i = s; i < t;  ++i)

template<typename T>
void maxs(T& x, T&& y) {
  x=std::max(x,y);
}
template<typename T>
void maxs(T& x, T& y) {
  x=std::max(x,y);
}

template<typename T>
void mins(T& x, T&& y) {
  x=std::min(x,y);
}
template<typename T>
void mins(T& x, T& y) {
  x=std::min(x,y);
}

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

  std::string S;
  std::cin >> S;

  int ans {};
  bool first {true};
  if (std::find(S.begin(), S.end(), 'R')==S.end()) {
    ans = 0;
  } else { // ans = 1;
    ans = 1;
    if (S[1] == 'R' && (S[0]=='R'||S[2]=='R')) {
      ans = 2;
      if (S[0] == S[1] && S[1] == S[2] && S[0] == 'R') {
        ans = 3;
      }
    }
  }
  std::cout << ans << '\n';
}


Measured memory_bytes: 3648
#include<iostream>

using namespace std;

int h, w;
char c[101][101];

int main(){
	cin >> h >> w;

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

	for (int i = 0; i < h * 2; i++){
		cout << c[i / 2] << "\n";
	}

	return 0;
}

Measured memory_bytes: 256
for i in range(int(input())):
    d = input()
    s = {d, d[::-1]}
    for j in range(1, len(d)):
        da, db = d[:j], d[j:]
        dar, dbr = da[::-1], db[::-1]
        s.add(da + dbr)
        s.add(dar + db)
        s.add(dar + dbr)
        s.add(db + da)
        s.add(db + dar)
        s.add(dbr + da)
    print(len(s))

Measured memory_bytes: 6792
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner s=new Scanner(System.in);
		int count=0;
		while(s.hasNext()){
			int n=s.nextInt();
			for(int a=0;a<10;a++){
				for(int b=0;b<10;b++){
					for(int c=0;c<10;c++){
						for(int d=0;d<10;d++){
							if(a+b+c+d==n){
								count++;
							}
						}
					}
				}
			}
			System.out.println(count);
			count=0;
		}
	}

}

Measured memory_bytes: 12000
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
using namespace std;
const int N = 1e5 + 5;
char s[N];
int dfs(int now) {
    if(now >= 1e7) return 0;
    else dfs(now + 1);
    return 0;
}
int main(){ 
    scanf("%s", s + 1);
    int len = strlen(s + 1);
    int ans = 0;
    s[0] = s[1];
    for (int i = 1; i <= len; i++) {
    if(s[i] != s[i - 1]) ans++;
    }
    dfs(1);
    printf("%d\n", ans);
    return 0;
}

Measured memory_bytes: 156544
#include<iostream>
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include <cstdlib>
#include <math.h>
#include<algorithm>
#include<cstdlib>
using namespace std;

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

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

	for(int i = 0; i < n; i++){
		if(i == 0){
			//
		}
		else if(s[i-1].back() != s[i].front()){
			cout << "No" <<endl;
			return 0;
		}
	}

	sort(s,s+n);

	for(int i = 0; i < n; i++){
		if(i == 0){
			//
		}
		else if(s[i-1] == s[i]){
			cout << "No" <<endl;
			return 0;
		}
	}

	cout << "Yes" <<endl;


	return 0;
}

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

vector<i64> edge, cnt;
set<i64> s;

i64 dfs(i64 now)
{
  if (2 <= cnt[now] || cnt[now] == -1)
    return 0;
  cnt[now]++;
  s.insert(now);
  dfs(edge[now]);
  return 0;
}

int main()
{
  i64 n;
  cin >> n;
  edge.resize(n);
  for (i64 i = 0; i < n; i++)
  {
    i64 a;
    cin >> a;
    edge[i] = (i + a) % n;
  }
  cnt.resize(n);
  for (i64 i = 0; i < n; i++)
  {
    if (cnt[i] == 0)
      dfs(i);
    for (i64 j : s)
      if (cnt[j] == 1)
        cnt[j] = -1;
    s.clear();
  }
  i64 ans = 0;
  for (i64 i = 0; i < n; i++)
    if (2 <= cnt[i])
      ans++;
  cout << ans << endl;
  return 0;
}



Measured memory_bytes: 15140
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

#[allow(unused_imports)]
use std::cmp::{min, max};

fn main() {
    input!{
      n: usize,
      ss: [String; n],
      m: usize,
      ts: [String; m],
    }

    let mut max_p = 0;
    for i in 0..n {
        let mut p = 0i64;
        for j in 0..n {
            if ss[j] == ss[i] {
                p += 1;
            }
        }

        for j in 0..m {
            if ts[j] == ss[i] {
                p -= 1;
            }
        }
        max_p = max(max_p, p);
    }
    println!("{}", max_p);
}


Measured memory_bytes: 4352
n, y = map(int, input().split(' '))

if_break = 'False'
abc = 'False'

for a in range(n+1):
  for b in range(n-a+1):
    c = n - a - b
#    print(a, b, c)
    if c >= 0:
      if 10000*a + 5000*b + 1000*c == y:
        print(a, b, c)
        abc = 'True'
        if_break = 'True'
        break
  if if_break == 'True':
    break
    
if abc == 'False':
  print('-1 -1 -1')

Measured memory_bytes: 3064
#include <stdio.h>
int N, X[50], Y[50], sx, sy;
int main() {
	scanf("%d", &N);
	for(int i = 0; i < N; i++) {
		scanf("%d%d", &X[i], &Y[i]);
		sx += X[i];
		sy += Y[i];
	}
	if(N % 2 == 1) printf("NA\n");
	else {
		bool flag = true;
		for(int i = 0; i < N / 2; i++) {
			flag = flag && ((1.0 * sx / N - X[i]) * 2 == (X[N / 2 + i] - X[i]) && (1.0 * sy / N - Y[i]) * 2 == (Y[N / 2 + i] - Y[i]));
		}
		if(flag) {
			printf("%.9f %.9f\n", 1.0 * sx / N, 1.0 * sy / N);
		}
		else {
			printf("NA\n");
		}
	}
	return 0;
}

Measured memory_bytes: 2752