akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

#define PI 3.1415926535897932
#define MOD 1000000007
#define INF 1e9

#define REP(i, n) for(int i = 0; i < (n); i++)
#define REP1(i, n) for(int i = 1; i <= (n); i++)
#define ALL(v) (v).begin(), (v).end()
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO  cout << "NO"  << endl
#define No  cout << "No"  << endl

using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef vector<bool> vb;

typedef bitset<64> bs;

void solve()
{
    ll N, K; cin >> N >> K;
    vll A(N); REP(i, N) cin >> A[i];
    bs k(K);
    vi bit(64, 0);
    REP(i, N)
    {
        bs a(A[i]);
        REP(i, 64) if(a[i]) bit[i]++;
    }

    bool frag = false;
    int i;
    for(i = 63; i >= 0; i--)
    {
        if(k[i] == 0) continue;
        if(2 * bit[i] > N)
        {
            k[i] = 0;
            frag = true;
            break;
        }
    }
    for(i--; i >= 0; i--)
    {
        if(2 * bit[i] > N) k[i] = 0;
        else k[i] = 1;
    }
    ll ans = 0;
    REP(i, N) ans += A[i] xor k.to_ullong();
    cout << ans << endl;
}
    
int main()
{
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(20);

    solve();

    return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <cmath>
#include <cstdio>
#include <stdio.h>
#include <algorithm>
using namespace std;

const double pi = acos(-1);

typedef long long ll;

ll sum( ll n ){
    return (n*(n+1))/2;
}

ll mod = 1e9+7;

int main()
{
    cin.tie(0);
    ios_base::sync_with_stdio(0);
    #ifdef acm
    freopen("a.in","r",stdin);
    #endif // acm

    int n, k;
    cin >> n >> k;

    ll sol = 0;
    for( int i = k; i <= n+1; i++ ){

        ll ini = sum(i-1);
        ll fin = sum(n) - sum(n-i);
        sol += fin - ini + 1;
        sol %= mod;

    }

    cout << sol << "\n";

    return 0;
}


Measured memory_bytes: 3648
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include <cstring>
#include <string>
#include <stack>

using namespace std;
typedef long long ll;

int main()
{
    int a, b, h;
    cin >> a >> b >> h;
    cout << ((a + b) * h) / 2 << endl;
    return 0;
}

Measured memory_bytes: 256
use std::io::{Read, stdin};
use std::str::FromStr;

fn main(){
    let n :usize = read();
    let _l :u64 = read();
    let mut s :Vec<String> = (0..n).map(|_| read()).collect();
    s.sort();
    println!("{}", s.concat());
}

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

Measured memory_bytes: 4352
use std::io::{self, BufRead};

fn main() {
    let stdin = io::stdin();
    let mut lines = stdin.lock().lines();
    let nm = lines.next().unwrap().unwrap();
    let mut nm = nm.split_whitespace();
    let n: usize = nm.next().unwrap().parse().unwrap();
    let m: usize = nm.next().unwrap().parse().unwrap();

    let mut is_ac = vec![false; n + 1];
    let mut wa_count = vec![0; n + 1];
    let mut ac = 0;
    let mut wa = 0;
    for _ in 0..m {
        let ps = lines.next().unwrap().unwrap();
        let mut ps = ps.split_whitespace();
        let p: usize = ps.next().unwrap().parse().unwrap();
        let s = ps.next().unwrap();

        match (is_ac[p], s) {
            (false, "AC") => {
                is_ac[p] = true;
                ac += 1;
                wa += wa_count[p];
            }
            (false, "WA") => wa_count[p] += 1,
            _ => (),
        }
    }

    println!("{} {}", ac, wa);
}


Measured memory_bytes: 4352
fun main(args : Array<String>) {
    val n = readLine()!!.toInt()
    val ss = readLine()!!

    val wCnt = IntArray(n) {0}
    val bCnt = IntArray(n) {0}

    wCnt[0] = if (ss[0] == '.') 1 else 0
    bCnt[0] = if (ss[0] == '#') 1 else 0

    for (i in 1 until n) {
        wCnt[i] = wCnt[i-1] + if (ss[i] == '.') 1 else 0
        bCnt[i] = bCnt[i-1] + if (ss[i] == '#') 1 else 0
    }

    var min = wCnt.last()

    for (i in ss.indices) {
        val lMin = bCnt[i]
        val rMin = wCnt.last() - wCnt[i]
        min = Math.min(min, lMin+rMin)
    }

    println(min)
}

Measured memory_bytes: 46184
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
using namespace std;
typedef long long ll;
const int MAXN = 2e5 + 5;

int a[MAXN];

int main(void)
{
	int n;
	scanf("%d",&n);
	for(int i=1; i<=n; ++i) scanf("%d",&a[i]);
	
	int sum = 0;
	for(int i=1; i<=n; ++i) sum ^= a[i];
	
	for(int i=1; i<=n; ++i) printf("%d ",a[i]^sum);
	return 0;
}

Measured memory_bytes: 4600
#include<stdio.h>
int main()
{
    int a,b,c,d,i,j;
    scanf("%d%d%d%d",&a,&b,&c,&d);
    for(i=1;;i++)
    {
        c=c-b;
        a=a-d;
        if(a<=0 && c<=0)
        {
            printf("Yes");
            break;
        }
        else if(c<=0)
        {
            printf("Yes");
            break;
        }
        else if(a<=0)
        {
            printf("No");
            break;
        }
    }
    return 0;
}


Measured memory_bytes: 1732
#include<bits/stdc++.h>
using namespace std;
int main() {
    int n;
    cin>>n;
    double dp[n+1];
    dp[0]=1;
    for(int i=1;i<=n;i++)
        dp[i]=0;
    for(int coins=1;coins<=n;coins++) {
        double p_head;
        cin>>p_head;
        for(int i=coins;i>=0;i--) {
            dp[i]=((i==0?0:dp[i-1])*p_head) + dp[i]*(1-p_head);
        }
    }
    double ans=0;
    for(int i=n/2+1;i<=n;i++)
        ans+=dp[i];
    cout<<fixed;
    cout<<setprecision(10);
    cout<<ans;
    return 0;
}


Measured memory_bytes: 256
n = gets.chop.to_i

line = ""
1.times do
  line = gets.chop.split.map(&:to_i)
end

#print n
#print line

current_max = 0
ans = 0

line.each do |k|
    if k >= current_max then
       ans += 1
       if k >= current_max then
          current_max = k
       end
    end
end
p ans

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

#define ll long long
#define fast_in_out  ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);

int main()
{
    fast_in_out;
    int n;
    cin >> n;
    set <int> v;
    for(int i = 0; i < n; i++)
    {
        int x;
        cin >> x;
        v.insert(x);
    }
    if(v.size() < n)
    {
        cout << "NO";
    }
    else
    {
        cout << "YES";
    }
}


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

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

  int H, W; cin >> H >> W;
  int HW = H * W;
  vector<char> s(HW);
  for (int i = 0; i < HW; i++) cin >> s[i];

  vector<int> dist(HW);
  queue<int> que;
  dist[0] = 1;
  que.push(0);
  while(!que.empty()) {
    int x = que.front(); que.pop();
    if (x / W != 0 && s[x-W] == '.' && !dist[x-W]) {
      dist[x-W] = dist[x] + 1;
      que.push(x-W);
    }
    if (x % W != W-1 && s[x+1] == '.' && !dist[x+1]) {
      dist[x+1] = dist[x] + 1;
      que.push(x+1);
    }
    if (x / W != H-1 && s[x+W] == '.' && !dist[x+W]) {
      dist[x+W] = dist[x] + 1;
      que.push(x+W);
    }
    if (x % W != 0 && s[x-1] == '.' && !dist[x-1]) {
      dist[x-1] = dist[x] + 1;
      que.push(x-1);
    }
  }
  
  if (dist[HW-1] == 0) {
    cout << -1 << "\n";
    return 0;
  }
  int white = 0;
  for (int i = 0; i < HW; i++) {
    if (s[i] == '.') white++;
  }
  cout << white - dist[HW-1] << "\n";
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
#include<stdio.h>
#include<queue>
#include <climits>
#include <map>
#include <set>
const int mod = 1e9 + 7;
const long long INF = 1LL << 60;
using namespace std;
typedef long long ll;

int main()
{
    int a,b;
    cin >> a >> b;
    if(a >= 13){
        cout << b;
    }else if (a >= 6){
        cout << b/2;
    }else{
        cout << 0;
    }
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>

using namespace std;

int main() {
	//cout << "" << endl; // prints
	const long long int mod = 1000000007;
	long long int N, a, b, c, ans;
	cin >> N;
	if(N == 1){
		cout << 0;
		return 0;
	}else if(N == 2){
		cout << 2;
		return 0;
	}
	a = 1;
	for(int k = 1; k <= N; k++){
		a = (a * 10) % mod;
	}
	a -= 2;
	b = 1;
	for(int k = 1; k <= N; k++){
		b = (b * 9) % mod;
	}
	b -= 1;
	c = 1;
	for(int k = 1; k <= N; k++){
		c = (c * 8) % mod;
	}
	ans = (a + c - 2 * b) % mod;
	if(ans < 0){
		ans += mod;
	}
	cout << ans;
	return 0;
}

Measured memory_bytes: 3572
#include <cstdio>

using namespace std;

int main() {
    int x, a, b, c;
    int ans=0;
    scanf("%d %d %d %d", &a, &b, &c, &x);
    for (int i = 0; i <= c; i++) {
       for (int j = 0; j <= b; j++) {
           int remain = x - 100 * j - 50 * i;
           if (remain >= 0 && remain <= 500 * a && remain % 500 == 0) ans++;
       } 

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



Measured memory_bytes: 256
n,k=map(int,input().split())
l=[input().split() for _ in range(n)]
w=[[0]*(k+1) for _ in range(k+1)]
b=[[0]*(k+1) for _ in range(k+1)]
for i in range(n):
    if ((int(l[i][0])//k+int(l[i][1])//k)%2==0)^(l[i][2]=='W'):
        b[int(l[i][0])%k][int(l[i][1])%k]+=1
    else:
        w[int(l[i][0])%k][int(l[i][1])%k]+=1

for i in range(1,k+1):
    b[0][i]+=b[0][i-1]
    b[i][0]+=b[i-1][0]
    w[0][i]+=w[0][i-1]
    w[i][0]+=w[i-1][0]
for i in range(1,k+1):
    for j in range(1,k+1):
        b[i][j]+=b[i-1][j]+b[i][j-1]-b[i-1][j-1]
        w[i][j]+=w[i-1][j]+w[i][j-1]-w[i-1][j-1]

ans=0
for i in range(k):
    for j in range(k):
        ans=max(ans,b[k][k]-b[i][k]-b[k][j]+2*b[i][j]+w[i][k]+w[k][j]-2*w[i][j])
        ans=max(ans,w[k][k]-w[i][k]-w[k][j]+2*w[i][j]+b[i][k]+b[k][j]-2*b[i][j])
print(ans)


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

int main() {
  
  int N;
  cin >> N;
  vector<int> a(N);
  for(int i=0; i<N; i++){
    cin >> a.at(i);
  }
  if(N%2==1){
    N++;
    a.push_back(0);
  }
  
  for(int i=0; i<N; i++){
    for(int j=i+1; j<N; j++){
      if(a.at(i)<a.at(j)){
        int k=a.at(i);
        a.at(i)=a.at(j);
        a.at(j)=k;
      }
    }
  }
  
  int k=0;
  for(int i=0; i<N/2; i++){
    k+=a.at(2*i)-a.at(2*i+1);
  }
  
  cout << k << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define F first
#define S second
#define MP make_pair
#define pb push_back
#define endl '\n'

using namespace std;

typedef long long LL;
typedef pair< int, int > P;
typedef pair< LL, LL > LP;
typedef pair< int, P > iP;
typedef pair< P, P > PP;

static const int INF = INT_MAX;
static const LL LINF = LLONG_MAX;
static const int MIN = INT_MIN;
static const LL LMIN = LLONG_MIN;
static const int MOD = 1000000007;

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

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    string a, b;
    cin >> a >> b;
    sort( a.begin(), a.end() );
    sort( b.begin(), b.end(), greater<>() );
    if( a < b ) cout << "Yes";
    else cout << "No";
    cout << endl;
    return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <queue>
#include <cassert>
using namespace std;

int main(){
    int N, M;
    cin >> N >> M;
    string s;
    cin >> s;
    vector<vector<int>> G(N);
    for(int i=0; i<M; i++){
        int a, b;
        cin >> a >> b;
        a--; b--;
        G[a].push_back(b);
        if(a != b)
            G[b].push_back(a);
    }

    vector<int> as(N, 0);
    vector<int> bs(N, 0);
    for(int i=0; i<N; i++){
        for(int t : G[i]){
            if(s[t] == 'A') as[i]++;
            else bs[i]++;
        }
    }

    vector<bool> vis(N, false);

    int cnt = 0;
    queue<int> dead;
    for(int i=0; i<N; i++){
        if(as[i] == 0 || bs[i] == 0){
            dead.push(i);
            vis[i] = true;
        }
    }

    cnt = dead.size();
    while(!dead.empty()){
        int i = dead.front();
        dead.pop();
        for(int t : G[i]){
            if(vis[t]) continue;
            if(s[i] == 'A') as[t]--;
            else bs[t]--;
            if(as[t] == 0 || bs[t] == 0){
                dead.push(t);
                vis[t] = true;
                cnt++;
            }
        }
    }
    cout << (cnt < N ? "Yes" : "No") << endl;
    return 0;
}


Measured memory_bytes: 12164
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> VI;
typedef vector<VI> VVI;
typedef pair<ll, ll> P;
#define FOR(i,a,b) for(ll i=ll(a);i<ll(b);++i)
#define rep(i,n)  FOR(i,0,n)
#define PRINT(V) for (auto v : (V)) cout << v << " "
#define ALL(n) begin(n),end(n)
struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star;
const ll INF = numeric_limits<ll>::max();
int main()
{
    int a; cin >> a;
    int ans = a + a*a + a*a*a;
    cout << ans << endl;
    return 0;
}

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

#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
const int INF = 1e9;

int main() {
  string s, st;
  cin >> s;

  for (int i = 0; i < (1 << 3); ++i) {
    int t = s[0] - '0';
    st = s[0];
    for (int j = 0; j < 3; ++j) {
      if (i & (1 << j))
        st = st + "+" + s[j + 1], t += s[j + 1] - '0';
      else
        st = st + "-" + s[j + 1], t -= s[j + 1] - '0';
    }
    if (t == 7) {
      st = st + "=7";
      break;
    }
  }

  cout << st << endl;
  return 0;
}


Measured memory_bytes: 256
def primes(n):
    ass = []
    is_prime = [True] * (n + 1)
    is_prime[0] = False
    is_prime[1] = False
    for i in range(2, int(n**0.5) + 1):
        if not is_prime[i]:
            continue
        for j in range(i * 2, n + 1, i):
            is_prime[j] = False
    for i in range(len(is_prime)):
        if is_prime[i]:
            ass.append(i)
    return ass

num = 10**5+10
Q = int(input())
prime_numbers = primes(num)
prime_set = set(prime_numbers)
prime_count = [0]*(num+1)
for pi in prime_numbers:
    if (pi+1)//2 in prime_set:
        prime_count[pi]+=1
for i in range(num):
    prime_count[i+1]+=prime_count[i]
for i in range(Q):
    l, r = map(int, input().split())
    print(prime_count[r]-prime_count[l-1])

Measured memory_bytes: 52952
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i < (n+1); ++i)
using namespace std;
using ll = long long;
// const int INF = +100100100;
typedef pair<int,int> P;


vector<int> h;

void Maxheapify(int i, vector<int> &h){
    // base case
    // if(2*i>h.size()-2){
    //     cout << 2*i<<endl;
    //     return;
    // }
    int r,l,maxi;
    l = 2*i;r=2*i+1;
    // printf("l: %d, r: %d\n",l,r);
    // search largest property among h[i],h[l] and h[r]
    
    if(l<=h.size()-1 && h[i]<h[l])maxi=l;
    else maxi=i;
    if(r<=h.size()-1 && h[r]>h[maxi])maxi=r;
    if(maxi!=i){
        swap(h[maxi],h[i]);
        Maxheapify(maxi,h);
    }
}

#define NIL -1
int main(){
    int n;
    cin >> n;
    // rep(i,n)cin>>h[i];
    h.push_back(NIL);
    rep(i,n){
        int v;
        cin >> v;
        h.push_back(v);
    }
    // 中間ノードのみアクセスする
    for(int i = n/2; i>=1;--i)Maxheapify(i,h);
    rrep(i,n)cout<<" "<<h[i];
    cout << endl;
    return 0;
}


Measured memory_bytes: 4864
import java.util.*;

public class Main {

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

        String S = scanner.next();

        boolean yaki = true;
        if (S.length() < 4) yaki = false;
        else if (!S.substring(0, 4).equals("YAKI")) yaki = false;
        System.out.println(yaki?"Yes":"No");
    }
}


Measured memory_bytes: 23508
import sys
from collections import deque
sys.setrecursionlimit(1000000)

h, w = map(int, input().split())
route = [[] for j in range(w * h)]
prev = []
somes = 0
for e in range(h):
    a = list(input())
    for g in a:
        if g == ".":
            somes += 1
    for l in range(w - 1):
        if a[l:l+2] == [".", "."]:
            route[e*w + l].append(e*w + l + 1)
            route[e * w + l + 1].append(e * w + l)
    if not prev:
        prev = a
        continue
    for l in range(len(a)):
        if a[l] == prev[l] == ".":
            route[e*w + l].append(e*w+l-w)
            route[e * w + l - w].append(e * w + l)
    prev = a
start = 0
goal = h*w-1
routes = []
eachmin = [float("inf") for i in range(h*w)]
eachmin[0] = 0
queue = deque([start])
searched = []
def bfs(time = 0):
    global searched, queue

    while queue:
        now = queue.popleft()
        if now in searched:
            continue
        if now == goal:
            break

        for j in route[now]:
            if j not in searched:
                queue.append(j)
                eachmin[j] = eachmin[now] + 1
        searched.append(now)

bfs(start)
if eachmin[-1] > 500000:
    print("-1")
    exit()
print(somes - eachmin[-1] - 1)

Measured memory_bytes: 3944
from fractions import gcd
A,B,C,D=map(int,input().split())
 
rc=(B//C)-((A-1)//C)#割り切れる数
rd=(B//D)-((A-1)//D)#割り切れる数
 
rcd=(B//(C*D//gcd(C,D)))-((A-1)//(C*D//gcd(C,D)))
print(int((B-A+1)-(rc+rd-rcd)))

Measured memory_bytes: 5048
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <stack>
#define N 300005
#define pi pair < int , int >
#define x first
#define y second
#define mkp make_pair
#define ls(x) x << 1
#define rs(x) x << 1 | 1

using namespace std;

struct Segment_Tree{
	int maxn[N << 3], val[N << 3];

	void init(){ memset(maxn, 0, sizeof maxn); memset(val, 0, sizeof val);}
	
	void up_data(int pos, int l, int r, int nl, int nr, int w){
		if(l >= nl && r <= nr){
			maxn[pos] += w; val[pos] += w; return ;
		}
		int mid = (l + r) >> 1;
		if(mid >= nl) up_data(ls(pos), l, mid, nl, nr, w);
		if(mid < nr) up_data(rs(pos), mid + 1, r, nl, nr, w);
		maxn[pos] = max(maxn[ls(pos)], maxn[rs(pos)]) + val[pos];
	}
}T;

int h, w, n, ans;
pi li[N];

stack < pi > sta, stb;

int read();
void work();

int main(){
	w = read(); h = read(); n = read();
	for(int i = 1; i <= n; ++i) li[i].x = read(), li[i].y = read();
	li[++n] = mkp(0, 0); li[++n] = mkp(w, h);
	work();
	for(int i = 1; i <= n; ++i) swap(li[i].x, li[i].y); swap(w, h);
	work();
	cout << (ans << 1) << endl;
}

int read(){
	int x = 0;char ch = getchar();
	for(; !isdigit(ch); ch = getchar());
	for(; isdigit(ch); ch = getchar()) x = (x << 1) + (x << 3) + (ch ^ 48);
	return x;
}

void work(){
	sort(li + 1, li + 1 + n);
	T.init(); 
	while(!sta.empty()) sta.pop();
	while(!stb.empty()) stb.pop();
	for(int i = 1; i < n; ++i){
		int nxt = i - 1;
		if(li[i].y <= h / 2){
			while(!sta.empty() && sta.top().y < li[i].y){
				T.up_data(1, 1, n, sta.top().x, nxt, sta.top().y - li[i].y);
				nxt = sta.top().x - 1; sta.pop();
			}
			if(nxt != i - 1) sta.push(mkp(nxt + 1, li[i].y));
		} else{
			while(!stb.empty() && stb.top().y > li[i].y){
				T.up_data(1, 1, n, stb.top().x, nxt, li[i].y - stb.top().y);
				nxt = stb.top().x - 1; stb.pop();
			}
			if(nxt != i - 1) stb.push(mkp(nxt + 1, li[i].y));
		}
		sta.push(mkp(i, 0)); stb.push(mkp(i, h));
		T.up_data(1, 1, n, i, i, h - li[i].x);
		ans = max(ans, T.maxn[1] + li[i + 1].x);
	}
	return ;
}

Measured memory_bytes: 22604
import java.util.Arrays;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner cin = new Scanner(System.in);
        int[] nums = new int[3];
        for (int i = 0; i < 3; i++) {
            nums[i] = cin.nextInt();
        }
        Arrays.sort(nums);
        int distance1 = nums[2] - nums[0];
        int distance2 = nums[2] - nums[1];
        int count = distance1 / 2 + distance2 / 2;
        int evenodd = distance1 % 2 + distance2 % 2;
        count += (evenodd == 1) ? 2 : (evenodd == 2) ? 1 : 0;
        System.out.println(count);
    }
}


Measured memory_bytes: 21972
from collections import Counter

n = int(input())
V = [int(_) for _ in input().split()]


def main():
    A = V[::2]
    B = V[1::2]

    resA = Counter(A).most_common()
    resB = Counter(B).most_common()

    if resA[0][0] == resB[0][0]:

        if resA[0][1] > resB[0][1]:
            sumA = sum([num for x, num in resA[1:]])
            sumB = resB[0][1] + sum([num for x, num in resB[2:]])
            print(sumA + sumB)
        elif resA[0][1] < resA[0][1]:
            sumB = sum([num for x, num in resB[1:]])
            sumA = resA[0][1] + sum([num for x, num in resA[2:]])
            print(sumA + sumB)
        else:
            if len(resA) == 1 and len(resB) == 1:
                print(n // 2)
            else:
                if resA[1][1] > resB[1][1]:
                    sumB = sum([num for x, num in resB[1:]])
                    sumA = resA[0][1] + sum([num for x, num in resA[2:]])
                    print(sumA + sumB)
                else:
                    sumA = sum([num for x, num in resA[1:]])
                    sumB = resB[0][1] + sum([num for x, num in resB[2:]])
                    print(sumA + sumB)
    else:
        if len(resA) == 1 and len(resB) == 1:
            print(0)
        else:
            sumA = sum([num for x, num in resA[1:]])
            sumB = sum([num for x, num in resB[1:]])
            print(sumA + sumB)


if __name__ == '__main__':
    main()




Measured memory_bytes: 68716
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000


int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    string S;
    string T;
    cin >> S >> T;
    int i = S.length() - T.length();
    int flag = 0;
    while (i >= 0 && flag == 0) {
        rep(j, T.length()) {
            flag = 1;
            if (S[i+j] != T[j] && S[i+j] != '?') {
                flag = 0;
                break;
            }
        }
        i--;
    }
    i++;
    //dump(i);
    if (flag == 0) {
        cout << "UNRESTORABLE" << endl;
        return 0;
    } else { 
        rep(j, T.length()) {
            S[i+j] = T[j];
        }
        rep(i, S.length()) {
            if (S[i] == '?') S[i] = 'a';
        }

    }
    cout << S << endl;


    return 0;
}


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

#define MAX 200000
#define SENTINEL 2000000000
typedef long long llong;

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

llong merge(int A[], int n, int left, int mid, int right){
	int i, j, k;
	llong cnt = 0;
	int n1 = mid - left;
	int n2 = right - mid;
	for(i=0;i<n1;i++) L[i] = A[left + i];
	for(i=0;i<n2;i++) R[i] = A[mid + i];
	L[n1] = R[n2] = SENTINEL;
	i = j = 0;
	for(k = left; k < right; k++){
		if(L[i] <= R[j]){
			A[k] = L[i++];
		}else{
			A[k] = R[j++];
			cnt += n1 - i;
		}
	}
	return cnt;
}

llong mergeSort(int A[], int n, int left, int right){
	int mid;
	llong v1, v2, v3;
	if(left +1 < right){
		mid = (left + right) / 2;
		v1 = mergeSort(A, n, left, mid);
		v2 = mergeSort(A, n, mid, right);
		v3 = merge(A, n, left, mid, right);
		return v1 + v2 + v3;
	}
	else return 0;
}

int main(){
	int A[MAX], n, i;

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

	llong ans = mergeSort(A, n, 0, n);
	cout << ans << endl;

	return 0;
}

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

int main(){
  int X;
  cin >> X;
  bitset<100010> bit;
  bit[0] = 1;
  for(int i = 0; i <= 5; ++i){
    int c = 100+i;
    for(int j = 0; j <= X; ++j){
      if(bit[j]) bit[j+c] = 1;
    }
  }
  cout << bit[X] << endl;
}


Measured memory_bytes: 256
from math import factorial

N, M = map(int, input().split())

if abs(N - M) > 1:
    print(0)
    exit()

ans = factorial(N)
ans %= (10 ** 9 + 7)
ans *= factorial(M)
ans %= (10 ** 9 + 7)
if N == M:
    ans *= 2
    ans %= (10 ** 9 + 7)
print(ans)


Measured memory_bytes: 4100
using System;
using System.Collections.Generic;
using static Assistant.Input;
using static Assistant.Debug;
using System.Linq;
using Assistant;

namespace ABC160A
{
    class Program
    {
        static void Main(string[] args)
        {
            var S = Console.ReadLine();
            if (S[2] == S[3] && S[4] == S[5]) Console.WriteLine("Yes");
            else Console.WriteLine("No");
        }


    }


}

namespace Assistant
{
    static class Input
    {
        static List<string> line = new List<string>();
        static int index = 0;
        static String RNext()
        {
            if (line.Count <= index) line.AddRange(Console.ReadLine().Split());
            return line[index++];
        }
        public static int RInt => int.Parse(RNext());
        public static long RLong => long.Parse(RNext());
        public static int[] RInts => Console.ReadLine().Split().Select(int.Parse).ToArray();
        public static long[] RLongs => Console.ReadLine().Split().Select(long.Parse).ToArray();
        public static string RString => RNext();
        //以下未テスト
        public static int[] RIntsC(int c) => Enumerable.Repeat(0, c).Select(x => int.Parse(RNext())).ToArray();
        public static long[] RLongsC(int c) => Enumerable.Repeat(0, c).Select(x => long.Parse(RNext())).ToArray();
        public static char[][] RMap(int h) => Enumerable.Repeat(0, h).Select(x => Console.ReadLine().ToCharArray()).ToArray();
    }

    static class Debug
    {
        static public void Draw2D<T>(T[,] map, int mode = 1)
        {
#if DEBUG
            int W = map.GetLength(0);
            int H = map.GetLength(1);

            string[,] map2 = new string[W + 1, H + 1];
            for (int i = 0; i < W + 1; i++)
            {
                for (int j = 0; j < H + 1; j++)
                {
                    if (i == 0 && j == 0) map2[i, j] = 0.ToString();
                    else if (i == 0) map2[i, j] = (j - 1).ToString();
                    else if (j == 0) map2[i, j] = (i - 1).ToString();
                    else map2[i, j] = map[i - 1, j - 1].ToString();
                }
            }

            for (int i = 0; i < W + 1; i++)
            {
                for (int j = 0; j < H + 1; j++)
                {
                    if (mode == 0) Console.Write(map2[i, j].Last());
                    if (mode == 1) Console.Write(map2[i, j] + " ");
                }
                Console.WriteLine();
            }
            Console.WriteLine();
#endif
        }

        public static void Draw1D<T>(T[] array, int mode = 0)
        {
#if DEBUG
            Console.WriteLine(string.Join(" ", array));
#endif
        }
    }
}


Measured memory_bytes: 11092
//#include<bits/stdc++.h>
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
#include<map>
#include<set>
using namespace std;
typedef long long ll;

#define INF 1000000000000
#define MOD 10000007
//#define int long long
#define pb push_back

void YesNo(bool b) { b ? cout << "Yes" << endl : cout << "No" << endl; return; }
void YESNO(bool b) { b ? cout << "YES" << endl : cout << "NO" << endl; return; }
void yesno(bool b) { b ? cout << "yes" << endl : cout << "no" << endl; return; }

int main() {
    int t, a = 0;
    int x = 0;
    cin >> t >> a;
    if (a % 2 == 1 || a > 4 * t || a < 2 * t)
    {
        cout << "No" << endl;
    }
    else
    {
        cout << "Yes" << endl;
    }
}

Measured memory_bytes: 3624
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <tuple>
#include <numeric>
#include <functional>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e16;
const ll MAX_N = 100010;

ll v[10] = {0, 2, 5, 5, 4, 5, 6, 3, 7, 6};  // v[i] : 数iをつくるのに必要なマッチ棒の本数

int main() {
    ll n, m;
    cin >> n >> m;

    vl a(m);
    rep(i, m) {
        cin >> a[i];
    }
    sort(rall(a));

    vl dp(n+1, -INF);  // dp[i] : マッチ棒をちょうどi本使って作れる桁数の最大値
    dp[0] = 0;
    exrep(i, 1, n) {
        rep(j, m) {
            if(i - v[a[j]] >= 0) {
                chmax(dp[i], dp[i - v[a[j]]] + 1);
            }
        }
    }
    
    ll x = n;  // 残りのマッチ棒の本数
    rep(i, dp[n]) {  // 先頭からi桁目を考える
        rep(j, m) {
            if(x - v[a[j]] >= 0 && dp[x] == dp[x - v[a[j]]] + 1) {
                cout << a[j];
                x -= v[a[j]];
                break;
            }
        }
    }

    cout << endl;
    re0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define REP(i,n) for (int64_t i=0; i<(n); ++i)
#define P pair<int,int>
using ll=int64_t;
using namespace std;
#define ketasuu(n) fixed<<setprecision(n)
#define btoe(p) p.begin(),p.end()
#define etob(p) p.rbegin(),p.rend()




int main(){
    string s,t; cin>>s>>t;
    sort(btoe(s)); sort(etob(t));
    int ok=0;
    rep(i,min(s.size(), t.size())){
        if(s[i]<t[i]){
            ok=1;
            break;
        }else if(s[i]>t[i]){
            ok=-1;
            break;
        }
    }
    if(ok==0){
        if(s.size()<t.size()){
            ok=1;
        }else{
            ok=-1;
        }
    }
    if(ok==1){
        cout<<"Yes"<<endl;
    }else{
        cout<<"No"<<endl;
    }

    return 0;
}

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

int main() {
    while (true) {
        int r, a;
        cin >> r >> a;
        
        if (r==0 && a==0) {
            break;
        }
        
        int rn[4], an[4];
        
        rn[0] = r/1000;
        rn[1] = (r/100)%10;
        rn[2] = (r/10)%10;
        rn[3] = r%10;
        
        an[0] = a/1000;
        an[1] = (a/100)%10;
        an[2] = (a/10)%10;
        an[3] = a%10;
        
        int hit = 0;
        int blow = 0;
        
        bool is_hit[4];
        
        for (int i=0; i<4; i++) {
            is_hit[i] = false;
        }
        
        for (int i=0; i<4; i++) {
            if (rn[i]==an[i]) {
                hit++;
                is_hit[i] = true;
            }
        }
        
        for (int i=0; i<4; i++) {
            if (!(is_hit[i])) {
                for (int j=0; j<4; j++) {
                    if (!(is_hit[j]) && rn[i]==an[j]) {
                        blow++;
                    }
                }
            }
        }
        
        cout << hit << " " << blow << endl;
    }
}


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

int main(void){
  int N;
  cin >> N;
  int L[N];
  int mnum = -1;
  int sum = 0;
  for(int i=0; i<N; i++) {
    cin >> L[i];
    sum += L[i];
    mnum = max(mnum, L[i]);
  }
  if(sum - mnum > mnum){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
  
}

Measured memory_bytes: 256
url = "https://atcoder.jp//contests/abc129/tasks/abc129_b"

def main():
    n = int(input())
    t = list(map(int, input().split()))
    ans = 1000000000
    sums = sum(t)
    for v in t:
        sums -= v
        ans = min(abs((sum(t)-sums)-sums), ans)
    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 9180
#include<stdio.h>

int n,a[500000],sw=0;


void merge(int left,int mid,int right){
    int l[500000],r[500000],i,j,k,l1,r1;
    j=k=0;
    l1=mid-left;
    r1=right-mid;

    for(i=0;i<l1;i++)l[i]=a[left+i];
    for(i=0;i<r1;i++)r[i]=a[mid+i];

    l[l1]=r[r1]=1000000000;

    for(i=left;i<right;i++){
        sw++;
        if(l[j]>=r[k]){
            a[i]=r[k];
            k++;
        }
        else {
            a[i]=l[j];
            j++;
        }
    }
}


void mergeSort(int left,int right){
    int mid;
    if(left+1<right){
    mid=(left+right)/2;
    mergeSort(left,mid);
    mergeSort(mid,right);
    merge(left,mid,right);
    }
}


int main(){
    int i;

    scanf("%d",&n);

    for(i=0;i<n;i++){
        scanf("%d",&a[i]);
    }

    mergeSort(0,n);

    for(i=0;i<n;i++){
        if(i)printf(" ");
        printf("%d",a[i]);
    }
    printf("\n%d\n",sw);
}


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

int main() {
  int a, b, c;
  cin >> a >> b >> c;
  if(a == b && a != c) cout << "Yes" << endl;
  else if(a == c && a != b) cout << "Yes" << endl;
  else if(c == b && a != c) cout << "Yes" << endl;
  else cout << "No" << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
typedef long long int ll;
using namespace std;
#define X first
#define Y second
#define pb push_back
#define fastio ios_base::sync_with_stdio(false);cout.tie(0);cin.tie(0);

const ll mod=998244353;
const ll MAXN=2e5+5;
const ll inf=1e17;

int main()
{
    fastio;
    ll h,cnt=0;
    cin>>h;
    ll tmp=h;
    while(h>0){
        h>>=1;
        cnt++;
    }
    ll ans=0;
    for(int i=0;i<cnt;i++) ans=ans+((ll)1<<i);
    ll a=(ll)1<<(cnt-1);
    h=tmp;
    if((h/a)==1) ans+=0;
    else ans=ans+((ll)1<<cnt);
    cout<<ans<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define SELECTER(_1, _2, _3, SELECT, ...) SELECT
#define REP1(i, n) for(int i=0; (i)<(n); (i)++)
#define REP2(i, a, b) for(int i=(a); (i)<(b); (i)++)
#define REP(...) SELECTER(__VA_ARGS__, REP2, REP1,) (__VA_ARGS__)
#define MOD 1'000'000'007

template <class T> ostream& operator<<(ostream& os, const vector<T>& v){ os << "{"; for(size_t i=0; i<v.size(); i++) os << v[i] << (i+1==v.size() ? "" : ", "); os << "}"; return os; }
template <class T, class U> ostream& operator<<(ostream& os, const pair<T, U>& p){ return os << "{" << p.first << ", " << p.second << "}"; }

int main(){
    int H1, M1, H2, M2, K;
    cin >> H1 >> M1 >> H2 >> M2 >> K;
    int a = (H2*60+M2)-(H1*60+M1);
    cout << a-K << endl;
    return 0;
}

Measured memory_bytes: 3624
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#define X (1000000007)

int main() {
	int A[100000] = { 0 };
	int N, M;
	scanf("%d %d", &N, &M);
	for (int i = 0; i < M; i++) {
		int tmp;
		scanf("%d", &tmp);
		A[tmp] = -1;
	}
	A[0] = 1;
	if (A[1] != -1)A[1] = 1;
	else A[1] = 0;
	int i = 2;
	while (i <= N) {
		if (A[i] == -1) {
			A[i] = 0;
			i++;
			if (A[i] == -1) {
				printf("0");
				return 0;
			}
			A[i] = A[i - 2];
			A[i] %= X;
			i++;
			continue;
		}
		else {
			A[i] += A[i - 2];
			A[i] += A[i - 1];
			A[i] %= X;
			i++;
		}
	}
	printf("%d", A[N]);

	return 0;

}

Measured memory_bytes: 512
#include <bits/stdc++.h>
 
using namespace std;
 
 
 
int main()
{
    double a,b;
    int least, step;
    cin>>a>>b;

    step=floor(log(b)/log(a));
    least = (pow(a,step)-1)/(a-1);
    //cout<<step<<" "<<least<<endl;
    for(int i=0; i<=10; i++)
    {
        if(i*(a-1)>=b-pow(a,step))
        {
            cout<<least+i;
            return 0;
        }
    }
 
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<map>
using namespace std;
long long n,a[222222],sum,ans,p;
map<long long,long long> mp;
int main()
{
	scanf("%lld",&n);
	for (long long i=1;i<=n;i++) scanf("%lld",&a[i]);
	mp[0]=1;
	for (long long i=1;i<=n;i++)
	{
		sum+=a[i];
		mp[sum]++;
	}
	for (map<long long,long long>::iterator it=mp.begin();it!=mp.end();it++)
	{
		p=it->second;
		ans=ans+p*(p-1)/2;
	}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 14336
import Control.Applicative
import Data.Maybe

countCombi :: Int -> Int -> Maybe Int
countCombi n x
    | n == 0 && x == 0 = Nothing
    | otherwise        = Just $ sum [1 | i <- [1 .. n], j <- [(i + 1) .. n], k <- [(j + 1) .. n], i + j + k == x]

main = do
    combi <- ((\[n, x] -> countCombi n x) . map (read :: String -> Int) . words) <$> getLine
    if (combi == Nothing)
    then return ()
    else do
        putStrLn $ show $ fromJust combi
        main

Measured memory_bytes: 5044
#include<bits/stdc++.h>
#define ll long long
#define ld long double
#define ull unsigned ll
#define pint pair<int,int>
#define mk(x,y) make_pair(x,y)
#define fir first
#define sec second
#define Rep(x,y,z) for(int x=y;x<=z;++x)
#define Red(x,y,z) for(int x=y;x>=z;--x)
using namespace std;
const int MAXN=2e5+5,MAXM=1e6+5,base=13131;
char buf[1<<12],*p1=buf,*p2=buf,nc;int ny;
//inline char gc() {return p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<12,stdin),p1==p2)?EOF:*p1++;}
inline char gc(){return getchar();}
inline int read(){
	int x=0;ny=1;while(nc=gc(),(nc<48||nc>57)&&nc!=EOF)if(nc==45)ny=-1;if(nc<0)return nc;
	x=nc-48;while(nc=gc(),47<nc&&nc<58&&nc!=EOF)x=(x<<3)+(x<<1)+(nc^48);return x*ny;
}
int n,vis[26];ull Fpow[MAXM];
vector<ull>Has[MAXN];
string S[MAXN];int len[MAXN];
unordered_map<ull,int>cnt[26];
int main(){
//	freopen("std.in","r",stdin);
//	freopen("std.out","w",stdout);
	n=read();
	Fpow[0]=1;Rep(i,1,MAXM-1)Fpow[i]=Fpow[i-1]*base;
	Rep(i,1,n){
		cin>>S[i];len[i]=S[i].size();
		Has[i].resize(len[i]+1),Has[i][len[i]]=0;
		for(int j=len[i]-1;j>=0;j--)Has[i][j]=Has[i][j+1]+Fpow[len[i]-j-1]*S[i][j];
		cnt[S[i][0]-'a'][Has[i][1]]++;
	}ll ans=0;
	Rep(i,1,n){
		Rep(c,0,25)vis[c]=0;
		cnt[S[i][0]-'a'][Has[i][1]]--;
		for(int j=0;j<=len[i];j++){
			Rep(c,0,25)if(vis[c]){
				if(cnt[c].count(Has[i][j]))ans+=cnt[c][Has[i][j]];
			}
			vis[S[i][j]-'a']=1;
		}cnt[S[i][0]-'a'][Has[i][1]]++;
	}cout<<ans<<"\n";
	return 0;
}



Measured memory_bytes: 43544
import java.util.*;

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

        System.out.println(a.toUpperCase().substring(0, 1) + b.toUpperCase().substring(0, 1) + c.toUpperCase().substring(0, 1));
    }
}


Measured memory_bytes: 22868
S = input()
Q = int(input())

inversion = 0
head = []
tail = []

for _ in range(Q):
    queri = input()
    if len(queri) == 1:
        inversion += 1
    else:
        _, f, c = queri.split()
        if inversion % 2 == 0 and f == "1":
            head.append(c)
        elif inversion % 2 == 1 and f == "1":
            tail.append(c)
        elif inversion % 2 == 0 and f == "2":
            tail.append(c)
        else:
            head.append(c)

#print("head={}, tail={}".format(head, tail))

if inversion % 2 == 0:
    head.reverse()
    Head = ''.join(head)
    Tail = ''.join(tail)
    print(Head + S + Tail)
else:
    tail.reverse()
    S = S[::-1]
    Head = ''.join(head)
    Tail = ''.join(tail)
    print(Tail + S + Head)


Measured memory_bytes: 68860
#include <bits/stdc++.h>
#include <cmath>
#include <numeric>
using namespace std;
#define rep(i,a,b) for(int64_t i=(a); i<(b); ++i) // a ≦ i < b 
#define Rrep(i,a,b) for(int64_t i=(a);i>=(b);--i) // reverse repeat. a から b まで減少．
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend() //逆イテレータ
#define RANGE(a,b,c) (a).begin()+b,(a).begin()+c // コンテナ a の 要素 b から c へのイテレータ
#define MOD 1000000007
#define INF 1000000000
typedef pair<int64_t, int64_t> PII;
typedef vector<int64_t> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef vector<PII> VP;

// まずは全探索，次にDP
// 偶奇，逆から，ソート，出現回数，出現位置，DP
// 余事象，包除
// データ構造
// 問題の特徴量
// 存在判定：構成方法，入力の特徴
// gcd, lcm ,素因数分解．
// 例外を十分に含む一般化．想像力の限界
// 小さい系から例示
// 始めは過剰に例示・場合分けしてもいい．各場合を確実に対処．
int main() {
cin.tie(0);
ios::sync_with_stdio(false);

int N;
string S; 
cin >> N >> S;

int cnt = 0;
rep(i, 0, N-1){
    if (S[i] != S[i+1]) ++cnt;
}

cout << cnt + 1 << "\n";
}

// 境界，出力文字列 チェック



Measured memory_bytes: 512
import java.io.*;
import java.util.*;
public class Main {
	public static void main(String[] args) throws Exception {
		MScanner sc=new MScanner(System.in);
		PrintWriter pw=new PrintWriter(System.out);
		int h=sc.nextInt(),a=sc.nextInt();
		int ans=0;
		while(h>0) {
			h-=a;ans++;
		}
		pw.println(ans);
		
		pw.flush();
	}
	static class MScanner {
		StringTokenizer st;
		BufferedReader br;
		public MScanner(InputStream system) {
			br = new BufferedReader(new InputStreamReader(system));
		}
 
		public MScanner(String file) throws Exception {
			br = new BufferedReader(new FileReader(file));
		}
 
		public String next() throws IOException {
			while (st == null || !st.hasMoreTokens())
				st = new StringTokenizer(br.readLine());
			return st.nextToken();
		}
		public int[] takearr(int n) throws IOException {
	        int[]in=new int[n];for(int i=0;i<n;i++)in[i]=nextInt();
	        return in;
		}
		public long[] takearrl(int n) throws IOException {
	        long[]in=new long[n];for(int i=0;i<n;i++)in[i]=nextLong();
	        return in;
		}
		public Integer[] takearrobj(int n) throws IOException {
	        Integer[]in=new Integer[n];for(int i=0;i<n;i++)in[i]=nextInt();
	        return in;
		}
		public Long[] takearrlobj(int n) throws IOException {
	        Long[]in=new Long[n];for(int i=0;i<n;i++)in[i]=nextLong();
	        return in;
		}
		public String nextLine() throws IOException {
			return br.readLine();
		}
 
		public int nextInt() throws IOException {
			return Integer.parseInt(next());
		}
 
		public double nextDouble() throws IOException {
			return Double.parseDouble(next());
		}
 
		public char nextChar() throws IOException {
			return next().charAt(0);
		}
 
		public Long nextLong() throws IOException {
			return Long.parseLong(next());
		}
 
		public boolean ready() throws IOException {
			return br.ready();
		}
 
		public void waitForInput() throws InterruptedException {
			Thread.sleep(3000);
		}
	}
}

Measured memory_bytes: 23124
n = int(input())
s = [map(int,input().split()) for i in range(n)]
t,x,y = (0,0,0)
for next_pos in s:
    t_next,x_next,y_next = next_pos
    dist = abs(x_next - x) + abs(y_next - y)
    dt = t_next - t
    if dist > t_next - t:
        print('No')
        break
    elif dt % 2 == dist % 2:
        t,x,y = t_next,x_next,y_next
    else:
        print('No')
        break
else:
    print('Yes')

Measured memory_bytes: 48780
#include <iostream>
#include <string>
#include <map>

using namespace std;

int
main() {
    uint64_t N, K, R, S, P;
    string T;
    cin >> N >> K >> R >> S >> P >> T;

    uint64_t score = 0;
    map<char, uint64_t> score_map;
    score_map['r'] = P; score_map['s'] = R; score_map['p'] = S;
    for (int k = 0; k < K; k++) {
        string str;
        for (auto i = k; i < T.length(); i += K) {
            str.push_back(T[i]);
        }

        cerr << str << endl;
        for (auto x = 0; x < str.length(); x++) {
            cerr << "score: " << score;
            cerr << " str[x]: " << str[x] << endl;
            if (x == str.length() - 1) {
                score += score_map[str[x]];
            } else if (str[x] != str[x+1]) {
                score += score_map[str[x]];
            } else {
                size_t len = 2;
                for (auto i = x + 2; i < str.length(); i++) {
                    if (str[x] == str[i]) len++;
                    else break;
                }
                score += score_map[str[x]] * ((len/2) + (len&1));
                x += len - 1;
            }
        }
    }

    cout << score << endl;

    return 0;
}


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

typedef long long ll;
#define REP(i,n) for(int i=0,_n=(int)(n);i<_n;++i)
#define ALL(v) (v).begin(),(v).end()
#define CLR(t,v) memset(t,(v),sizeof(t))
template<class T1,class T2>ostream& operator<<(ostream& os,const pair<T1,T2>&a){return os<<"("<<a.first<<","<<a.second<< ")";}
template<class T>void pv(T a,T b){for(T i=a;i!=b;++i)cout<<(*i)<<" ";cout<<endl;}
template<class T>void chmin(T&a,const T&b){if(a>b)a=b;}
template<class T>void chmax(T&a,const T&b){if(a<b)a=b;}

ll simulate(vector<ll> v, int A, int B, int C) {
  if (C < 0) return 0;
  vector<ll> sel;
  REP(i, A) {
    sel.push_back(v[i]);
  }
  REP(i, B) {
    sel.push_back(v[v.size() - 1 - i]);
  }
  sort(ALL(sel));
  ll res = accumulate(ALL(sel), 0LL);
  for (int i = 0; i < C && i < (int)sel.size(); i++){
    if (sel[i] < 0) res -= sel[i];
  }
  return res;
}

int main2() {
  int N, K; cin >> N >> K;

  vector<ll> v(N);
  REP(i, N) cin >> v[i];

  ll ans = 0;
  for (int a = 0; a <= K; a++) {
    for (int b = 0; b <= K; b++) {
      if (a + b <= N && K - a - b >= 0) {
        ll val = simulate(v, a, b, K - a - b);
        chmax(ans, val);
      }
    }
  }
  cout << ans << endl;
  return 0;
}

int main() {

#ifdef LOCAL
  for (;!cin.eof();cin>>ws)
#endif
    main2();
  return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using PII = pair<ll, ll>;
#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()

using ld = double;
using P = complex<ld>;
using G = vector<P>;
const ld pi = acos(-1);
const ld eps = 1e-10;
const ld inf = 1e12;
 
ld cross(const P& a, const P& b) { return a.real()*b.imag() - a.imag()*b.real(); }
ld dot(const P& a, const P& b) { return a.real()*b.real() + a.imag()*b.imag(); }
 
using C = pair<ld, P>;
#define rad first
#define pnt second
 
C smallest_enclosing_disc(vector<P> ps){
    auto c3 = [](const P &a, const P &b, const P &c){
        ld A = norm(b - c);
        ld B = norm(c - a);
        ld C = norm(a - b);
        ld S = abs(cross(b - a, c - a));
        P p = (A*(B+C-A)*a + B*(C+A-B)*b + C*(A+B-C)*c) / (4*S*S);
        ld r = abs(p - a);
        return make_pair(r, p);
    };
 
    auto c2 = [](const P &a, const P &b){
        P c = (a + b) / (ld)2;
        ld r = abs(a - c);
        return make_pair(r, c);
    };
 
    auto in_circle = [](const P &a, const C &c){
        return norm(a - c.pnt) <= c.rad*c.rad + eps;
    };
 
    int n = ps.size();
    random_shuffle(ps.begin(), ps.end());
    C c = c2(ps[0], ps[1]);
    for(int i = 2; i < n; ++i){
        if(!in_circle(ps[i], c)){
            c = c2(ps[0], ps[i]);
            for(int j = 1; j < i; ++j){
                if(!in_circle(ps[j], c)){
                    c = c2(ps[j], ps[i]);
                    for(int k = 0; k < j; ++k){
                        if(!in_circle(ps[k], c)){
                            c = c3(ps[i], ps[j], ps[k]);
                        }
                    }
                }
            }
        }
    }
    return c;
}
 
int main(void) {
    ll n;
    cin >> n;
    vector<P> ps(n);
    REP(i, n) {
        ll x, y;
        cin >> x >> y;
        ps[i] = {x, y};
    }
 
    auto c = smallest_enclosing_disc(ps);
    cout << fixed << setprecision(15) << c.first << endl;
 
    return 0;
}

Measured memory_bytes: 256
def main():
    N = int(input())
    A = list(map(int, input().split()))
    a = A.count(1)
    b = A.count(2)
    c = A.count(3)
    floatN = N*1.0
    dp = [[[.0]*(N+1) for i in range(N+1)] for j in range(N+1)]

    for k in range(c+1):
        for j in range(b+c + 1 - k):
            for i in range(N + 1 - k - j):
                if i + j+k == 0:
                    continue
                dp[i][j][k] = floatN
                if i > 0:
                    dp[i][j][k] += dp[i-1][j][k] * i
                if j > 0:
                    dp[i][j][k] += dp[i+1][j-1][k] * j
                if k > 0:
                    dp[i][j][k] += dp[i][j+1][k-1] * k
                dp[i][j][k] /= (i+j+k)
    print(dp[a][b][c])


main()


Measured memory_bytes: 254088
#include<bits/stdc++.h>
using namespace std;
char s[1000];
int main()
{
	int a,f=0;
	cin>>s;
	cin>>a;
	for(int i=0;s[i]!='\0';i++)
	{
		if(f%a==0)
		{
			printf("%c",s[i]);
		}
		f++;
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,j,k) for(ll i=(ll)j;i<(ll)k;i++)
#define itrep(i,x) for(auto i=(x).begin(); i!=(x).end();i++)
#define Sort(x) sort((x).begin(),(x).end())
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define vi vector<int>
#define INF INT_MAX
#define INFL 1e18
#define MOD 1000000007
#define pb push_back
#define MP make_pair
#define PI 3.1415926535
typedef long long int ll;
typedef std::pair<int,int> P;
int D=1;
int dx[4]={0,1,0,-1},dy[4]={-1,0,1,0};

using namespace std;

int main(){
    ll a,b,c,d;
    cin>>a>>b>>c>>d;
    
    if(d%2==0)cout<<a-b<<endl;
    else cout<<(a-b)*-1<<endl;
    /*
    5 4 3 1
    7 8 9 -1
    17 16 15 1
    */
    
    
    
    return 0;
}


Measured memory_bytes: 256
#include <iostream>


using namespace std;

int main()
{
	int N, M, K;
	cin >> N >> M >> K;
	for(int n=0;n<=N;n++)
		for (int m = 0; m <= M; m++)
		{
			if ((N*m + M*n - 2*n*m) == K)
			{
				cout << "Yes" << endl;
				return 0;
			}
		}
	cout << "No" << endl;
	return 0;
}


Measured memory_bytes: 256