akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define rep2(i, s, n) for (ll i = (s); i < (ll)(n); i++)
const ll MAX = 1001001;
const ll MOD = 1000000007;
int main()
{
    ll n;
    cin >> n;
    vector<ll> a(n);
    rep(i, n)
    {
        cin >> a[i];
    }
    vector<ll> p(n + 1), x(n + 1);
    rep(i, n)
    {
        p[i + 1] = p[i] + a[i];
        x[i + 1] = x[i] ^ a[i];
    }
    vector<vector<ll>> d(n + 1, vector<ll>(20));
    ll s = 0;
    ll t = 0;
    ll ans = 0;
    rep(i, n)
    {
        rep(j, 20)
        {
            d[i + 1][j] = d[i][j] + ((a[i] >> j) & 1);
        }
    }
    while (t < n)
    {
        bool ex = true;
        rep(i, 20)
        {
            if (d[t + 1][i] - d[s][i] > 1)
            {
                ex = false;
            }
        }
        if (ex)
        {
            ans += t - s + 1;
            t++;
        }
        else
        {
            s++;
        }
    }
    cout << ans << endl;
}

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

#define int long long

int tbl[1000010] = {};
vector<int> so;

signed main(){

    int a, b;
    cin >> a >> b;

    for(int i = 2;i*i <= max(a, b);i++){
        if(tbl[i] == 0){
            so.push_back(i);
            for(int j = i*2;j*j <= max(a, b);j+=i){
                tbl[i] = 1;
            }
        }
    }


    int idx = 0;

    set<int> st;

    int tmp = a;
    while(1){

        if(tmp == 1) break;

        if(idx == so.size()){
            st.insert(tmp);
            break;
        }

        if(tmp % so[idx] == 0){
            tmp /= so[idx];
            st.insert(so[idx]);
        }else{
            idx++;
        }
    }

    tmp = b;

    int ans = 0;
    idx = 0;
    while(1){
        if(tmp == 1) break;

        if(idx == so.size()){
            if(st.find(tmp) != st.end()){
                st.erase(tmp);
                ans++;
            }
            break;
        }

        if(tmp % so[idx] == 0){
            if(st.find(so[idx]) != st.end()){
                st.erase(so[idx]);
                ans++;
            }
            tmp /= so[idx];
        }else{
            idx++;
        }
    }


    cout << ans+1 << endl;

    return 0;
}









Measured memory_bytes: 14316
#include <bits/stdc++.h>
using namespace std;
#define MAX 10000
#define NIL -1

int n, pos;
vector<int> pre, in, post;

void rec(int l, int r) {
  if (l >= r) return;
  int root = pre[pos++];
  int m = distance(in.begin(), find(in.begin(), in.end(), root));
  rec(l,m);
  rec(m+1,r);
  post.push_back(root);
}

void solve() {
  pos = 0;
  rec(0, pre.size());
  for (int i = 0;i < n; i++) {
    if (i) cout << " ";
    cout << post[i];
  }
  cout << endl;
}

int main() {
  int k;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> k;
    pre.push_back(k);
  }
  for (int i = 0; i < n; i++) {
    cin >> k;
    in.push_back(k);
  }
  solve();
  return 0;
}



Measured memory_bytes: 3168
import sys

INF = 10**9

N = int(sys.stdin.readline())
A = [int(x) for x in sys.stdin.readline().split()]

z = 0


def merge(A, left, right):

    global z

    n1 = (right - left) // 2 + left  # L側の個数

    # L[0...n1], R[0...n2] を生成
    # L = A[left:n1].copy()
    # R = A[n1:right].copy()

    L = A[left:n1]
    R = A[n1:right]


    L.append(INF)
    R.append(INF)

    # print(L, R)

    i = 0
    j = 0
    for k in range(left, right):
        z += 1 

        if L[i] <= R[j]:
            A[k] = L[i]
            i += 1
        else:
            A[k] = R[j]
            j += 1


def mergesort(A, left, right):
    if left + 1 < right:
        mid = (left + right) // 2
        mergesort(A, left, mid)
        mergesort(A, mid, right)
        merge(A, left, right)


mergesort(A, 0, N)

print(" ".join([str(x) for x in A]))
print(z)


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

#define rep(i, n) for (int i = 0; i < int(n); i++)
#define rrep(i, n) for (int i = int(n) - 1; i >= 0; i--)
#define reps(i, n) for (int i = 1; i <= int(n); i++)
#define rreps(i, n) for (int i = int(n); i >= 1; i--)
#define repc(i, n) for (int i = 0; i <= int(n); i++)
#define rrepc(i, n) for (int i = int(n); i >= 0; i--)
#define repi(i, a, b) for (int i = int(a); i < int(b); i++)
#define repic(i, a, b) for (int i = int(a); i <= int(b); i++)
#define each(x, y) for (auto &x : y)
#define all(a) (a).begin(), (a).end()
#define bit32(x) (1 << (x))
#define bit64(x) (1ll << (x))

using namespace std;

using i64 = long long;
using f80 = long double;
using vi32 = vector<int>;
using vi64 = vector<i64>;
using vf80 = vector<f80>;
using vstr = vector<string>;

inline void yes() { cout << "Yes" << endl; exit(0); }
inline void no() { cout << "No" << endl; exit(0); }
inline i64 gcd(i64 a, i64 b) { if (min(a, b) == 0) return max(a, b); if (a % b == 0) return b; return gcd(b, a % b); }
inline i64 lcm(i64 a, i64 b) { if (min(a, b) == 0) return max(a, b); return a / gcd(a, b) * b; }
template <typename T> class pqasc : public priority_queue<T, vector<T>, greater<T>> {};
template <typename T> class pqdesc : public priority_queue<T, vector<T>, less<T>> {};
template <typename T> inline void amax(T &x, T y) { x = max(x, y); }
template <typename T> inline void amin(T &x, T y) { x = min(x, y); }
template <typename T> inline T exp(T x, i64 n, T e = 1) { T r = e; while (n > 0) { if (n & 1) r *= x; x *= x; n >>= 1; } return r; }
template <typename T> istream& operator>>(istream &is, vector<T> &v) { each(x, v) is >> x; return is; }
template <typename T> ostream& operator<<(ostream &os, vector<T> &v) { rep(i, v.size()) { if (i) os << ' '; os << v[i]; } return os; }
void solve(); int main() { ios::sync_with_stdio(0); cin.tie(0); cout << fixed << setprecision(16); solve(); return 0; }

void solve() {
  int h, w, a, b;
  cin >> h >> w >> a >> b;
  if (a * 2 > w || b * 2 > h) {
    no();
  }
  vstr ans(h);
  rep(i, h) ans[i] = string(w, '0');
  rep(i, b) rep(j, a) ans[i][j] = '1';
  rep(i, h - b) rep(j, w - a) {
    ans[i + b][j + a] = '1';
  }
  rep(i, h) cout << ans[i] << endl;
}


Measured memory_bytes: 2304
#include<cstdio>
#include<cmath>
#include<string.h>
#include<iostream>
using namespace std;
long long gcd(long long a,long long k)
{
    if(k == 0)
        return a;
    else
        return gcd(k,a%k);
}
int main()
{
        int n;
        cin>>n;
        long long k,cnt,a;
        a = cnt = 1;
        while(n--)
        {
            cin>>k;
            cnt = a/gcd(a,k)*k;
            a = cnt;
        }
        cout<<cnt<<endl;
    }


Measured memory_bytes: 256
import java.util.Scanner;
class Main{
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		if(a<=b){
			System.out.println(a);
		}else{
			System.out.println(a-1);
		}
	}
}

Measured memory_bytes: 22608
#include<iostream>
#include<algorithm>
#include<cmath>
using namespace std;
int main() {
  int n,a[100];
  cin >> n;
  for(int i=0; i<n; i++) {
      cin >> a[i];
  }
  for(int i=n-1; i>0; i--) {
      cout << a[i] << " ";
  }
  cout << a[0] << endl;
}


Measured memory_bytes: 3084
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)*}
    };
}

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

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

fn main() {
    input! {
        n: usize,
        kk: usize,
        av: [i64; n],
    }
    let _mod = 1000000007;
    let mut ans = 1;
    if kk == n {
        for a in &av {
            ans *= a;
            ans %= _mod;
        }
        if ans < 0 {
            ans += _mod;
        }
    } else {
        let mut bv = vec![];
        let mut cv = vec![];
        for a in &av {
            if *a < 0 { bv.push(a); }
            else    { cv.push(a); }
        }
        bv.sort();
        cv.sort();   
        cv.reverse();
        let mut b = 0;
        let mut c = 0;
        let mut k = kk;
        loop {
            if k > 1 {
                let mut bb = 0;
                if b+1 < bv.len()  { bb = bv[b] * bv[b+1]; }
                let mut cc = 0;
                if c+1 < cv.len()  { cc = cv[c] * cv[c+1]; }
                if bb >= cc {
                    ans *= bb%_mod;
                    k -= 2;
                    b += 2;
                } else {
                    ans *= cv[c]%_mod;
                    k -= 1;
                    c += 1;
                }
                ans %= _mod;
                if k == 0 { break; }
            } else if k == 1 {
                if c < cv.len() {
                    ans *= cv[c];
                    ans %= _mod;
                } else if b < bv.len() {
                    ans = 1;
                    for i in 0..kk {
                        ans *= bv[bv.len()-i-1];
                        ans %= _mod;
                    }
                    ans += _mod;
                }
                if ans < 0 { ans += _mod; }
                break;
            }
        }
    }
    println!("{}", ans);
}

Measured memory_bytes: 5556
loop do
    exp = gets.chomp
    break if exp == ?#
    ok = false
    exp.split(?|).each do |term|
        vars = term[1..-2].split(?&)
        if vars.permutation(2).any?{|v1, v2| v1 == ?~ + v2}
            next
        end
        ok = true
        break
    end
    puts ok ? 'yes' : 'no'
end

Measured memory_bytes: 8800
cart = [4,1,4,1,2,1,2,1]
while True:
	try:
		que = map(int, raw_input().split())
		mx,mxcart = 0, "99999999"
		for sp in range(8):
			sm = 0
			for num in range(8):
				if cart[(sp+num)%8] <= que[num]:
					sm += cart[(sp+num)%8]
				else:
					sm += que[num]
			if sm > mx:
				mx = sm
				mxcart = "".join(map(str, cart[sp:]+cart[:sp]))
			elif sm == mx:
				acart = "".join(map(str, cart[sp:]+cart[:sp]))
				if int(mxcart) > int(acart):
					mxcart = acart
		print " ".join(map(str, mxcart))
	except:
		break

Measured memory_bytes: 4252
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <iomanip>
#include <map>
using namespace std;

void solve(){
  char c; cin >> c;
  if(c == 'A') cout << 'T';
  else if(c == 'T') cout << 'A';
  else if(c == 'C') cout << 'G';
  else cout << 'C';
  cout << endl;
}

int main(){
  solve();
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstring>
#include <chrono>
#include <complex>
#define endl "\n"
#define ll long long int
#define vi vector<int>
#define vll vector<ll>
#define vvi vector < vi >
#define pii pair<int,int>
#define pll pair<long long, long long>
#define mod 1000000007
#define inf 1000000000000000001;
#define all(c) c.begin(),c.end()
#define mp(x,y) make_pair(x,y)
#define mem(a,val) memset(a,val,sizeof(a))
#define eb emplace_back
#define pb push_back
#define f first
#define s second

using namespace std;
int main(){
	std::ios::sync_with_stdio(false);
	ll a;
	long double b;
	cin >> a >> b;
	ll ans=(a*round(b*100))/100;
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 3772
using LIB;
using System;
using System.Linq;
using System.Text;
using System.Collections.Generic;

class Program
{
    public static IO IO = new IO();
    static void Main(string[] args)
    {
        int n = IO.INT();
        int[] m = IO.INT(n);
        int p = 0;
        for (int i = 0; i < n; i++)
        {
            if (m[i] == 2) { p++; }
            else if (m[i] > 2 && (m[i] % 2 != 0))
            {
                bool f = true;
                int q = (int)Math.Sqrt(m[i]);
                for (int j = 3; j <= q; j += 2) { if (m[i] % j == 0) { f = false; break; } }
                if (f) { p++; }
            }
        }
        IO.WRITE(p);
        IO.FLUSH();
    }
}

namespace LIB
{
    public class IO
    {
        private const int WMAX = 1000;
        private StringBuilder S = new StringBuilder();
        private T R<T>(Func<string, T> f) { return f(Console.ReadLine()); }
        private T[] R<T>(Func<string, T> f, char c) { return STRING().Split(c).Select(f).ToArray(); }
        private T[] R<T>(Func<string, T> f, int l) { T[] r = new T[l]; for (int i = 0; i < l; i++) { r[i] = R(f); } return r; }
        private T[][] R<T>(Func<string, T> f, int l, char c) { T[][] r = new T[l][]; for (int i = 0; i < l; i++) { r[i] = R<T>(f, c); } return r; }
        private void W<T>(Func<T, string> f, T v, bool lf = true) { S.Append(f(v)); if (lf == true) { S.Append('\n'); } if (S.Length >= WMAX) { FLUSH(); } }
        public string STRING() { return R(s => s); }
        public string[] STRING(char c) { return R(s => s, c); }
        public string[] STRING(int l) { return R(s => s, l); }
        public string[][] STRING(int l, char c) { return R(s => s, l, c); }
        public int INT() { return R(int.Parse); }
        public int[] INT(char c) { return R(int.Parse, c); }
        public int[] INT(int l) { return R(int.Parse, l); }
        public int[][] INT(int l, char c) { return R(int.Parse, l, c); }
        public long LONG() { return R(long.Parse); }
        public long[] LONG(char c) { return R(long.Parse, c); }
        public long[] LONG(int l) { return R(long.Parse, l); }
        public long[][] LONG(int l, char c) { return R(long.Parse, l, c); }
        public double DOUBLE() { return R(double.Parse); }
        public double[] DOUBLE(char c) { return R(double.Parse, c); }
        public double[] DOUBLE(int l) { return R(double.Parse, l); }
        public double[][] DOUBLE(int l, char c) { return R(double.Parse, l, c); }
        public void WRITE(string s, bool lf = true) { W(v => v, s, lf); }
        public void WRITE(int s, bool lf = true) { W(v => v.ToString(), s, lf); }
        public void WRITE(long s, bool lf = true) { W(v => v.ToString(), s, lf); }
        public void WRITE(double s, bool lf = true) { W(v => v.ToString(), s, lf); }
        public void FLUSH() { Console.Write(S); S.Length = 0; }
    }
}

Measured memory_bytes: 9596
<?php
fscanf(STDIN, "%d", $n);
$ks=explode(' ',trim(fgets(STDIN)));
$i=1;
$cnt=0;
foreach ($ks as $k) {
  if ($i == $k) {
    $i++;
  } else {
    $cnt++;
  }
}
echo ($cnt == count($ks)) ? -1 : $cnt;

Measured memory_bytes: 39940
#include <iostream>

using namespace std;

int main()
{
	int a[100000];

	int b = 0;

	for(int i=1;i < 100000;i++)
	{
		cin >> a[i];

		b++;

		if(a[i] == 0)
		{
			goto Exit;
		}
	}

Exit:;

	for(int i = 1; i < b; i++)
	{
		cout << "Case " << i << ": " << a[i] << endl;
	}
	return 0;
}

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

using namespace std;

int main(){

  vector<int> rika(4);
  vector<int> syakai(2);
  int sum=0;
  
  for(int i=0;i<4;++i)
	cin>>rika[i];

  for(int i=0;i<2;++i)
	cin>>syakai[i];

  sort(rika.begin(),rika.end());
  sort(syakai.begin(),syakai.end());

  for(int i=3;i>=1;--i)
	sum+=rika[i];

  sum+=syakai[1];

  cout<<sum<<endl;
  
}



Measured memory_bytes: 3132
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#define ll long long
#define rep2(i,a,b) for(ll i=a;i<=b;++i)
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep3(i,a,b) for(ll i=a;i>=b;i--)
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pq priority_queue<int>
#define pb push_back
#define eb emplace_back
#define vec vector<int>
#define vecll vector<ll>
#define vecpii vector<pii>
#define vec2 vector<vec>
#define vecll2 vector<vecll>
#define vec3 vector<vec2d>
#define vecll3 vector<vecll2d>
#define fi first
#define se second
#define endl "\n"
#define all(c) begin(c),end(c)
#define ios ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
using namespace std;
int in() {int x;cin>>x;return x;}
ll lin() {ll x;cin>>x;return x;}
template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
template<class T> inline void print(vector<T> v){for(T e:v)cout<<e<<" ";cout<<endl;}
template<class T> inline void print(pair<T,T> p){cout<<"("<<p.first<<","<<p.second<<") ";}
template<class T> inline void print(vector<pair<T,T>> v){for(auto e:v)print(e); cout<<endl;}
void print(vector<vec> v){for(auto e:v){for(auto ee:e)cout<<ee<<" ";cout<<endl;}}
void print(map<int,int> mp){for(auto e:mp)cout<<e.first<<" "<<e.second<<endl;cout<<endl;}

const int N=1e5+10;
const ll INF=1e9+7;
ll a[N<<4];
int sum[11];
main(){
    ios
    int h,w,n;scanf("%d%d%d",&h,&w,&n);
    int x,y;
    int cnt=0;
    ll m=(ll)(h-2)*(w-2);
    rep(iii,n){
        scanf("%d%d",&x,&y);
        rep(i,3)rep(j,3)if( x-i>=1 && x-i<=h-2 && y-j>=1 && y-j<=w-2){
            a[cnt++]=INF*(x-i)+(y-j);
        }
    }
    sort(a,a+cnt);
    ll t=1;
    rep(i,cnt){
        if(a[i]==a[i+1])t++;
        else sum[t]++,t=1,m--;
    }
    cout<<m<<" ";
    rep2(i,1,9)cout<<sum[i]<<" ";
}



Measured memory_bytes: 8448
import java.io.IOException;
import java.util.Scanner;

/**
 * Created on 2017/10/20 7:02.
 */
public class Main {
    public static void main(String[] args) throws IOException {
        // BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        Scanner sc = new Scanner(System.in);

        while (sc.hasNextInt()) {
            int A = sc.nextInt();
            int B = sc.nextInt();
            int C = sc.nextInt();
            if (A == B) {
                System.out.println(C);
            } else if (A == C) {
                System.out.println(B);
            } else {
                System.out.println(A);
            }
        }
    }
}

Measured memory_bytes: 23764
#include <iostream>

using namespace std;

int main()
{
   string s;
   cin>>s;
   if(s[0]!='A'){
    cout<<"WA";
    return 0;
   }
   else{
        int c=0,c2=0;
    for(int i=2;i<s.size()-1;i++){
        if(s[i]=='C'){
            c+=1;
        }
    }
    for(int i=0;i<s.size();i++){
        if(s[i]>=65&&s[i]<=90){
            c2+=1;
        }
    }
    if(c==1&&c2==2){
        cout<<"AC";
    }
    else{
        cout<<"WA";
    }

   }
    return 0;
}


Measured memory_bytes: 3556
module.exports=function(e){var r={};function t(n){if(r[n])return r[n].exports;var o=r[n]={i:n,l:!1,exports:{}};return e[n].call(o.exports,o,o.exports,t),o.l=!0,o.exports}return t.m=e,t.c=r,t.d=function(e,r,n){t.o(e,r)||Object.defineProperty(e,r,{enumerable:!0,get:n})},t.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},t.t=function(e,r){if(1&r&&(e=t(e)),8&r)return e;if(4&r&&"object"==typeof e&&e&&e.__esModule)return e;var n=Object.create(null);if(t.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:e}),2&r&&"string"!=typeof e)for(var o in e)t.d(n,o,function(r){return e[r]}.bind(null,o));return n},t.n=function(e){var r=e&&e.__esModule?function(){return e.default}:function(){return e};return t.d(r,"a",r),r},t.o=function(e,r){return Object.prototype.hasOwnProperty.call(e,r)},t.p="",t(t.s=0)}([function(e,r,t){t(1)(t(2).readFileSync("/dev/stdin","UTF-8").split("\n"))},function(e,r){function t(e,r){return function(e){if(Array.isArray(e))return e}(e)||function(e,r){var t=[],n=!0,o=!1,u=void 0;try{for(var i,l=e[Symbol.iterator]();!(n=(i=l.next()).done)&&(t.push(i.value),!r||t.length!==r);n=!0);}catch(e){o=!0,u=e}finally{try{n||null==l.return||l.return()}finally{if(o)throw u}}return t}(e,r)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance")}()}e.exports=function(e){var r=t(e[0].split(" ").map(function(e){return Number(e)}),3),n=r[0],o=r[1],u=r[2];n<=u&&n+o>=u?console.log("YES"):console.log("NO")}},function(e,r){e.exports=require("fs")}]);

Measured memory_bytes: 11468
#include <iostream>
#include <set>
#include <algorithm>
#include <string>
#include <numeric>
#include <limits>
#include <type_traits>

using namespace std;
int main()
{
    int n;
    cin >> n;
    set<string> st;
    for (int i = 0; i < n; i++) {
        string v;
        cin >> v;
        st.insert(v);
    }
    cout << st.size() << endl;
    return 0;
}

Measured memory_bytes: 19260
#include<bits/stdc++.h>
#define de(x) cout<<#x<<"="<<x<<endl;
#define dd(x) cout<<#x<<"="<<x<<" ";
#define rep(i,a,b) for(int i=a;i<(b);++i)
#define repd(i,a,b) for(int i=a;i>=(b);--i)
#define repp(i,a,b,t) for(int i=a;i<(b);i+=t)
#define ll long long
#define mt(a,b) memset(a,b,sizeof(a))
#define fi first
#define se second
#define inf 0x3f3f3f3f
#define INF 0x3f3f3f3f3f3f3f3f
#define pii pair<int,int>
#define pdd pair<double,double>
#define pdi pair<double,int>
#define mp(u,v) make_pair(u,v)
#define sz(a) a.size()
#define ull unsigned long long
#define ll long long
#define pb push_back
#define PI acos(-1.0)
#define qc std::ios::sync_with_stdio(false)
#define db double
const int mod = 1e9+7;
const int maxn = 1e5+5;
const double eps = 1e-6;
using namespace std;
bool eq(const db &a, const db &b) { return fabs(a - b) < eps; }
bool ls(const db &a, const db &b) { return a + eps < b; }
bool le(const db &a, const db &b) { return eq(a, b) || ls(a, b); }
ll gcd(ll a,ll b) { return a==0?b:gcd(b%a,a); };
ll lcm(ll a,ll b) { return a/gcd(a,b)*b; }
ll kpow(ll a,ll b) {ll res=1;a%=mod; if(b<0) return 1; for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll read(){
    ll x=0,f=1;char ch=getchar();
    while (ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while (ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
    return x*f;
}
//inv[1]=1;
//for(int i=2;i<=n;i++) inv[i]=(mod-mod/i)*inv[mod%i]%mod;
int main(){
	ll n,m;
	scanf("%lld%lld",&n,&m);
	if(n==1&&m==1) return printf("1\n"),0;
	if(n==1||m==1) printf("%lld\n",n*m-2),0;
	else {
		printf("%lld\n",n*m-(2*n+2*m-4));
	}
	return 0;
}


Measured memory_bytes: 256
using namespace std;
int N=1000000,sqrtN=1000;
bool isprime[1000001];
int nprime[10000021];
void sieve_of_atkin() {
  int n;
  for (int z = 1; z <= 5; z += 4) {
    for (int y = z; y <= sqrtN; y += 6) {
      for (int x = 1; x <= sqrtN && (n = 4*x*x+y*y) <= N; ++x)
        isprime[n] = !isprime[n];
      for (int x = y+1; x <= sqrtN && (n = 3*x*x-y*y) <= N; x += 2)
        isprime[n] = !isprime[n];
    }
  }
  for (int z = 2; z <= 4; z += 2) {
    for (int y = z; y <= sqrtN; y += 6) {
      for (int x = 1; x <= sqrtN && (n = 3*x*x+y*y) <= N; x += 2)
        isprime[n] = !isprime[n];
      for (int x = y+1; x <= sqrtN && (n = 3*x*x-y*y) <= N; x += 2)
        isprime[n] = !isprime[n];
    }
  }
  for (int y = 3; y <= sqrtN; y += 6) {
    for (int z = 1; z <= 2; ++z) {
      for (int x = z; x <= sqrtN && (n = 4*x*x+y*y) <= N; x += 3)
        isprime[n] = !isprime[n];
    }
  }
  for (int n = 5; n <= sqrtN; ++n)
    if (isprime[n])
      for (int k = n*n; k <= N; k+=n*n)
        isprime[k] = false;
  isprime[2] = isprime[3] = true;
}

int main(){
	sieve_of_atkin();
	for(int i=1;i<N+1;i++)nprime[i]=nprime[i-1]+isprime[i-1];
	int n,p,m,c,S,mn,mx;
	while(scanf("%d",&n),n){
		S=0;
		for(int j=0;j<n;j++){
			scanf("%d%d",&p,&m); mn=p-m; if(mn<2)mn=2; mx=p+m; if(mx>N-1)mx=N-1;
			c=nprime[mx+1]-nprime[mn];
			if(c>0)c--; else c=-1;
			S+=c;
		}
		printf("%d\n",S);
	}
	return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
#define double long double
#define int long long
#define mi map<int,int>
#define pii pair<int,int>
#define low lower_bound
#define upp upper_bound
#define mod (int)1e9+7
#define inf (int)1e16
#define rep(i,n) for(int i=0;i<n;i++)
#define all(vec) vec.begin(),vec.end()
#define vsort(vec) sort(all(vec))
#define vrever(vec) reverse(all(vec));
#define vunsort(vec) sort(all(vec),greater<>());
#define bisea binary_search
#define cend cout<<endl;
#define F first
#define S second
#define P pair<int,int>
#define prique priority_queue<P,vector<P>,greater<P>>
using namespace std;
int n,d;
set<int>st;
signed main() {
  cin>>n;
  rep(i,n) {
    cin>>d;
    st.insert(d);
  }
  cout<<st.size()<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>

using namespace std;

int main() {
    int n = 0, k = 0, i = 0, res = 0;
    cin >> n >> k;

    int t[n] = {};
    for (i = 0; i < n; i++) {
        cin >> t[i];
    }
    if (n <= k) {
        cout << "1";
        return 0;
    }
    res= 1 + (n-k)/(k-1);
    if((n-k) % (k - 1)) res++;
    cout <<  res;


    return 0;
}

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

int main(){
    int count[4];
    memset(count,0,sizeof(count));
    for(int i=0;i<3;i++){
        int a,b;cin >> a >> b;a--,b--;
        count[a]++;
        count[b]++;
    }
    int s = 0;
    for(int i=0;i<4;i++){
        if(count[i]==1) s++;
    }
    if(s==2) cout << "YES" << endl;
    else cout << "NO" << endl;
}

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

#define getNum(i) scanf("%d", &(i))
#define MODULO 1000000007l
#define INF 10000000000000000l
#define FOR(i,j,k) for(int (i)=(j);(i)<=(k);(i)++)
#define IOS ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);

using namespace std;

typedef long long ll;
ll cnt[255];

int main() {

#ifdef CONTEST
    freopen("input.in", "r", stdin);
#endif
    IOS
    string s;
    cin >> s;
    FOR(i,0,s.length()-1) {
        cnt[s[i]]++;
    }

    ll ans = s.length()*(s.length()-1) >> 1;
    FOR(i,'a','z') {
        ans -= (cnt[i]*(cnt[i]-1)) >> 1;
    }
    cout << ans+1l << endl;

}

Measured memory_bytes: 720
import java.util.*;
import java.io.PrintWriter;
public class Main{
	public static void main(String[] args){
		Scanner sc=new Scanner(System.in);
		int k=sc.nextInt();
		String s=sc.next();
		if(s.length()<=k){
			System.out.println(s);
		}else{
			System.out.println(s.substring(0,k)+"...");
		}
	}
}


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

#define ALL(a) (a).begin(), (a).end()
#define llong long long

using namespace std;

signed main(){
	bool init = false;
	while(true){
		int a, b;cin >> a >> b;
		if(a == 0)break;
		else if(init)cout << endl;
		init = true;
		bool flag = false;
		for(int i = a; i <= b; i++){
			if(i % 4 == 0 && i % 100 != 0){
				flag = true;
				cout << i << endl;
			}
			else if(i % 400 == 0){
				flag = true;
				cout << i << endl;
			}
		}
		if(!flag)cout << "NA" << endl;
	}

	return 0;
}




Measured memory_bytes: 3100
#include <bits/stdc++.h>
//#include <math.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 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<ll,int> P;
//typedef pair<int,P> PP;

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

int n,a,b;
string s;
int kokunai,kaigai;

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

	cin>>n>>a>>b>>s;
	REP(i,n) {
		if(s[i]=='a') {
			if(kokunai+kaigai+1<=a+b) {
				kokunai++;
				cout<<"Yes"<<endl;
			}
			else cout<<"No"<<endl;
		}
		else if(s[i]=='b') {
			if(kokunai+kaigai+1<=a+b&&kaigai+1<=b) {
				kaigai++;
				cout<<"Yes"<<endl;
			}
			else cout<<"No"<<endl;
		}
		else cout<<"No"<<endl;
	}

	return 0;
}


Measured memory_bytes: 848
#include <cstdio>
#include <iostream>
#include <string.h>

#define rep2(x,from,to) for(int x=(from);(x)<(to);(x)++)
#define rep(x,to) rep2(x,0,to)

using namespace std;

int main() {
	int t;
	cin >> t;
	int m = t % 3600;	
	cout << t / 3600 << ":" << m / 60 << ":" << m % 60 << endl;
	return 0;
}

Measured memory_bytes: 1164
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
using namespace std;
typedef pair<int,int> Paint;
#define rep(i,q) for(int i = 0; (q) > i; i++)
int main(){
  int h,m,s;
  char t,p;
  cin >> h >> t >> m >> p >> s;
  if(m > 4)cout << "TBD" << endl;
  else cout << "Heisei" << endl;

}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<string>
#include<sstream>
#include<cmath>
using namespace std;
int main() {
  int n;
  long k,result = 0;
  long* a = new long[100000];
  cin >> n >> k;
  for(int i=0;i<n;i++){
    cin >> a[i];
  }
  for(int i=40;i>=0;i--){
    long x = pow(2,i);
    long cand = 0;
    for(int j=0;j<n;j++) cand += a[j]&x;
    if(k<x) result += cand;
    else {
      if(cand < n*x - cand){
        result += n*x - cand;
        k -= x;
      }else  result += cand;
    }
  }
  cout << result << endl;
  return 0;
}


Measured memory_bytes: 1024
#include<vector>
#include<list>
#include<algorithm>
#include<iostream>
#include<string>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
using namespace std;
int main(){
  int a,b;
  while(cin>>a>>b){
    while(b){
      a%=b;
      swap(a,b);
    }
    cout<<a<<endl;
  }
  return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include <algorithm>
#include <numeric>
#include <vector>
#include <list>
#include <queue>
#include <string>
#include <map>
using namespace std;

int main()
{
    long long int W, H, x, y, other;
    cin >> W >> H >> x >> y;
    long double ans = 1.0 * W * H / 2;
    if (x + x == W && y + y == H)
    {
        other = 1;
    }
    else
    {
        other = 0;
    }
    cout << ans << " " << other << endl;
    return 0;
}

Measured memory_bytes: 256
// problem: "https://atcoder.jp/contests/abc120/tasks/abc120_b"

#include<iostream>

using namespace std;

int gcd(int a,int b)
{
    if(b==0)
        return a;

    return gcd(b,a%b);
}

int main()
{
    int A,B,K;
    cin>>A>>B>>K;

    int g = gcd(max(A,B),min(A,B));
    int k,i;
    k = 0;
    for(i=g;i>0;i--)
    {
        if(g%i==0)
            k++;

        if(k==K)
            break;
    }

    cout<<i;

    return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstdint>
#include <vector>
#include <algorithm>

int testcase_ends() {
  size_t N, M;
  scanf("%zu %zu", &N, &M);
  if (N == 0 && M == 0) return 1;

  std::vector<int> S(M);
  std::vector<std::vector<size_t>> c(M);
  std::vector<int> max(N);
  std::vector<int> forced(N);
  for (size_t i = 0; i < M; ++i) {
    size_t k;
    scanf("%d %zu", &S[i], &k);
    c[i].resize(k);
    for (auto& cij: c[i]) {
      scanf("%zu", &cij);
      --cij;
      max[cij] += S[i];
    }
    if (k == 1) {
      forced[c[i][0]] += S[i];
    }
  }

  std::vector<int> ml(N+1), mr(N+1);
  for (size_t i = 0; i < N; ++i)
    ml[i+1] = std::max(ml[i], max[i]);
  for (size_t i = N; i--;)
    mr[i] = std::max(mr[i+1], max[i]);

  int res = 0;
  for (size_t i = 0; i < N; ++i)
    res = std::max(res, std::max(ml[i], mr[i+1]) - forced[i]);

  printf("%d\n", res+1);
  return 0;
}

int main() {
  while (!testcase_ends()) {}
}



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

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

Measured memory_bytes: 6428
#include <bits/stdc++.h>
using namespace std;
long long fix[1000001];
int main ()
{
    long long n, m, i=0, j=0, pas1=0, pas2=0;
    cin>>n>>m;
    long long k;
    string s;
    int a[n+1];
    for(i=1; i<=n; i++){
    	a[i]=0;
	}
    for(i=1; i<=m; i++){
        cin>>k;
        cin>>s;
        if(s=="WA" && fix[k]==0)
        a[k]++;
        if(s=="AC" && fix[k]==0){
        pas1++;
        fix[k]=1;
        }
    }
    for(i=1; i<=n; i++){
    	if(fix[i]==1)
    	pas2+=a[i];
	}
    cout<<pas1<<" "<<pas2;
}

Measured memory_bytes: 1408
/// kazuki08
/*
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")
*/
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define int long long
typedef long long ll;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>ordered_set;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int,int> pi;
typedef vector<pi> vpi;
//#define inf 1000000000
#define mod 1000000007
#define dmp(x) cerr<<"line "<<__LINE__<<" "<<#x<<":"<<x<<endl
#define fs first
#define sc second
#define pb push_back
#define all(c) (c).begin(),(c).end()
#define mt make_tuple
#define IOS ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)
template<class S,class T> ostream& operator<<(ostream& o,const pair<S,T> &p){
    return o<<"("<<p.fs<<","<<p.sc<<")";
}
template<class T> ostream& operator<<(ostream& o,const vector<T> &vc){
    o<<"{";
    for(const T& v:vc) o<<v<<",";
    o<<"}";
    return o;
}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

int h;

signed main(){
IOS;
//freopen("input.txt", "r", stdin);
//freopen("output.txt", "w", stdout);
  
  cin >> h;
  int pre = 1;
  int cur = h;
  int ans = 0;
  while(cur>0){
    ans+= pre;
    pre*=2;
    cur/=2;
  }
  cout << ans << endl;


return 0;
}
///....


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

int main() {
  int a, b;
  cin >> a >> b;

  // ここにプログラムを追記
	if ( a % 2 != 0 && b % 2 != 0){
      cout << "Odd" << endl;
    }
  	else {
      cout << "Even" << endl;
    }
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<vvll> vvvll;
typedef vector<string> vstr;
typedef pair<ll, ll> pll;
typedef vector<pll> vp;
typedef map<ll, ll> mll;
typedef map<string, ll> mstrll;
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fir first
#define sec second
#define maxs(x, y) (x = max(x, y))
#define mins(x, y) (x = min(x, y))
#define all(x) begin(x), end(x)
#define rall(x) rbegin(x), rend(x)
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for(ll i = ll(a); i < ll(b); i++)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep,)(__VA_ARGS__)
#define each(i, n) for(auto&& i: n)
#define out(x) cout << (x)
#define indent() cout << '\n'
#define print(x) cout << (x) << '\n'
#define debug(x) cerr << #x << ": " << (x) << '\n'
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;}
const ll INF = 1e16;
const ll MOD = 1e9 + 7;
ll a, b, c, n, m, x, y, z, w, h, ans, cnt, mx, mn;
string s, t;
ll dx[] = {-1, 0, 1, 0}, dy[] = {0, -1, 0, 1};
//vll dx = {-1, 0, 1, -1, 1, -1, 0, 1}, dy = {-1, -1, -1, 0, 0, 1, 1, 1};
string alphabet = "abcdefghijklmnopqrstuvwxyz";

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    while(cin >> n >> m >> x){
        if(n + m >= x){
            print(max(0LL, x - n));
        }else{
            print("NA");
        }
    }
}



Measured memory_bytes: 3236
#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <string>
#include <math.h>
#include <iomanip>
#include <limits>
#include <list>
#include <queue>
#include <tuple>
#include <map>
using namespace std;
#define MOD (long long int)(1e9+7)
#define ll long long int
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define reps(i,n) for(int i=1; i<=(int)(n); i++)
#define REP(i,n) for(int i=n-1; i>=0; i--)
#define REPS(i,n) for(int i=n; i>0; i--)
#define INF (int)(1123456789)
#define LINF (long long int)(112345678901234567)
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))
#define all(v) v.begin(), v.end()

int main(void){
	string s;
	cin>>s;
	int ans1,ans2;
	ans1=0;ans2=0;
	rep(i,s.size()){
		if(s[i] == i%2 + '0'){
			ans1++;
		}else{
			ans2++;
		}
	}
	cout<<min(ans1,ans2)<<endl;
	return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
typedef vector<int> VI;
typedef long long ll;
typedef pair<int,int> PII;
const ll mod=1000000007;
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
// head

const int N=101000;
char s[N];
int f[N],val[N],m,l,r;
int find(int x) { return f[x]==x?x:f[x]=find(f[x]); }
void merge(int u,int v) {
	u=find(u); v=find(v);
	if (u==v) return;
	f[u]=v; val[v]=(val[u]+val[v])%26;
}
int main() {
	scanf("%s",s);
	int n=strlen(s);
	rep(i,0,n) f[i]=i;
	rep(i,0,n) if (i>0) {
		int w=(int)s[i]-(int)s[i-1];
		if (w<0) w+=26;
		val[i]=w;
	}
	rep(i,1,n) merge(i,n-i);
	scanf("%d",&m);
	rep(i,0,m) {
		scanf("%d%d",&l,&r);
		if (r==n) r=0;
		merge(l-1,r);
	}
	rep(i,0,n) if (find(i)!=find(0)&&val[find(i)]!=0) {
		puts("NO");
		return 0;
	}
	puts("YES");
}


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

#define MAX_N 10000001

bool table[MAX_N];

void init() {
    memset(table, 1, sizeof(table));
    table[0] = table[1] = false;
    for (int i = 2; i < MAX_N; i++) {
        if (table[i]) {
            for (int j = i + i; j < MAX_N; j+=i) {
                table[j] = false;
            }
        }
    }
}

int main() {
    init();
    int n;
    while (cin >> n, n != 0) {
        for (int i = n; i >= 13; i--) {
            if (table[i] && table[i-2] && table[i-6] && table[i-8]) {
                cout << i << endl;
                break;
            }
        }
    }
    return 0;
}

Measured memory_bytes: 10000
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using Int = ll;
#define rep(i,n) for(int i=0;i<n;i++)
#define all(in) in.begin(), in.end()
#define INF (sizeof(int) == 4 ? (int)1e9:(int)1e18)
#define EPS 0.0000000001
template<class T, class S> void cmin(T &a, const S &b) { if (a > b)a = b; }
template<class T, class S> void cmax(T &a, const S &b) { if (a < b)a = b; }
template<typename Head, typename Value> auto vectors(const Head &head, const Value &v) { return vector<Value>(head, v); }
template<typename Head, typename... Tail> auto vectors(Head x, Tail... tail) { auto inner = vectors(tail...); return vector<decltype(inner)>(x, inner); }
using ld  = long double;
using pii = pair<int,int>;
using piii = pair<int,pii>;
int W,H;
int dx[]={0,0,1,-1}, dy[]={1,-1,0,0};
bool valid(int x,int y){return (0<=x&&x<W)&&(0<=y&&y<H);}
constexpr Int mod = 1e9 + 7;
template <class T> T modpow(T a, T b) {
    if (b == 0) return T(1);
    if (b % 2 == 0) {
        long long d = modpow(a, b / T(2));
        return (d * d) % mod;
    } else {
        return (a * modpow(a, b - 1) % mod );
    }
}
template<class T> T mod_nCr(T n, T r, T mod ) {
    T denom = 1;
    T numer = 1;
    for (T i = 1; i <= r; i++) numer = (numer * i) % mod;
    for (T i = n - r + 1; i <= n; i++) denom = (denom * i) % mod;
    return (denom * modpow(numer, mod - 2) % mod);
}

class modcomb {
public:
    Int maxn,MOD;
    vector<Int>fac,finv,inv;
    modcomb(Int _maxn,Int _mod) : maxn(_maxn),MOD(_mod),fac(_maxn),finv(_maxn),inv(_maxn){
        fac[0] = fac[1] = 1;
        finv[0] = finv[1] = 1;
        inv[1] = 1;
        for (int i = 2; i < maxn; i++){
            fac[i] = fac[i - 1] * i % MOD;
            inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
            finv[i] = finv[i - 1] * inv[i] % MOD;
        }
    };
    Int modComb(Int n,Int k){
        if (n < k) return 0LL;
        if (n < 0 || k < 0) return 0LL;
        return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
    }
    
};
signed main(){
    Int N, K;
    cin >> N  >> K;
    vector<Int>v(N);
    auto mcomb = modcomb(N + 1, mod);
    for(auto&e : v) cin >> e;
    sort(all(v));
    vector<Int>maxi(N,0LL);
    vector<Int>minim(N,0LL);
    for(int i =0 ;i  < v.size(); ++i){
        if(N - i - 1 >= K  - 1){
            Int cal = mcomb.modComb(N - i - 1, K - 1) * v[i];
            cal %= mod;
            minim[i] = cal;
        }
    }
    for(int i = 0; i < v.size(); ++i){
        if(i >= K - 1){
            Int cal = mcomb.modComb((Int)i, K-1) * v[i];
            cal %= mod;
            maxi[i]  = cal;
        }
    }
    auto sum = [&](Int res, Int e){
        return  (res += e) % mod;
    };
    cout <<
    ( mod + accumulate(all(maxi), 0LL, sum) - accumulate(all(minim), 0LL, sum)) % mod
    << endl;
}


Measured memory_bytes: 4992
#include <stdio.h>
int main(){
int W,H,x,y,r;
scanf("%d %d %d %d %d\n",&W,&H,&x,&y,&r);
if (x+r<=W && x-r>=0 && y+r<=H && y-r>=0)
printf("Yes\n");
else printf("No\n");
return 0;
}


Measured memory_bytes: 2148
#!/usr/bin/env python3
from itertools import product, permutations, combinations
from bisect import bisect_right,bisect_left

N=int(input())
times = [list(map(int, input().split())) for i in range(N-1)]
for start in range(N-1):
    current = start + 1
    elapsed =  times[start][1] + times[start][0]
    while current < N-1:
        if elapsed < times[current][1]:
            elapsed = times[current][1]
        if elapsed % times[current][2] != 0:
            elapsed = times[current][2] * (elapsed // times[current][2] + 1)
        elapsed += times[current][0] 
        current += 1
    print(elapsed)
print(0)





Measured memory_bytes: 3316
//{{{
#include <bits/stdc++.h>
using namespace std;
#define repX(a,b,c,x,...) x
#define repN(a) repX a
#define rep(...) repN((__VA_ARGS__,rep3,rep2,loop))(__VA_ARGS__)
#define rrep(...) repN((__VA_ARGS__,rrep3,rrep2))(__VA_ARGS__)
#define loop(n) rep2(i_,n)
#define rep2(i,n) rep3(i,0,n)
#define rep3(i,begin,end) for(int i=(int)(begin),i##_end=(int)(end);i<i##_end;++i)
#define rrep2(i,n) rrep3(i,n,0)
#define rrep3(i,begin,end) for(int i=(int)(begin-1),i##_end=(int)(end);i>=i##_end;--i)
#define foreach(x,a) for(auto&x:a)
using ll=long long;
const ll mod=(ll)1e9+7;
//}}}

int main(){
  int N;
  scanf("%d", &N);
  double ans = 0;
  rep(i, N){
    double x;
    string u;
    cin >> x >> u;
    ans += x * (u == "JPY" ? 1 : 380000);
  }
  printf("%.9lf\n", ans);
  return 0;
}


Measured memory_bytes: 256
import sys
input = sys.stdin.readline
sys.setrecursionlimit(100000)

def getN():
    return int(input())
def getList():
    return list(map(int, input().split()))
import math
import heapq

def make_score(l1, l2):
    h = []
    for num in l1:
        heapq.heappush(h, num)

    init_score = sum(h)

    v_temp = [0]
    v_max = [0]

    for num in l2:
        mini = heapq.heappop(h)
        score = num - mini
        heapq.heappush(h, num)
        v_temp.append(v_temp[-1] + score)
        if v_temp[-1] > v_max[-1]:
            v_max.append(v_temp[-1])
        else:
            v_max.append(v_max[-1])

    return init_score, v_max


def make_score_rev(l1, l2):
    h = []
    for num in l1:
        heapq.heappush(h, -num)

    init_score = -sum(h)

    v_temp = [0]
    v_max = [0]

    for num in l2:
        maxi = heapq.heappop(h) * -1
        score = maxi - num
        heapq.heappush(h, -num)
        v_temp.append(v_temp[-1] + score)
        if v_temp[-1] > v_max[-1]:
            v_max.append(v_temp[-1])
        else:
            v_max.append(v_max[-1])

    return init_score, v_max

n = getN()
nums = getList()


l1 = nums[:n]
l2 = nums[n:2*n]
l3 = nums[2*n:]

init_zen, v_max_zen = make_score(l1, l2)
init_kou, v_max_kou = make_score_rev(l3, l2[::-1])

# print(init_zen, init_kou)
# print(v_max_zen, v_max_kou)

t_score = 0
for i, j in zip(v_max_zen, v_max_kou[::-1]):
    if t_score < i + j:
        t_score = i + j

print(init_zen - init_kou + t_score)

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

using namespace std;

int main()
{
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    ios_base::sync_with_stdio(false);

    int n;
    cin >> n;
    int a[n][3];
    int dp[n][3];

    for (int i=0;i<n;i++)
        cin >> a[i][0] >> a[i][1] >> a[i][2];

    dp[0][0]=max(a[0][1],a[0][2]);
    dp[0][1]=max(a[0][0],a[0][2]);
    dp[0][2]=max(a[0][1],a[0][0]);
    for (int i=1;i<n;i++)
    {
        dp[i][0]=max(dp[i-1][1]+a[i][1],dp[i-1][2]+a[i][2]);
        dp[i][1]=max(dp[i-1][0]+a[i][0],dp[i-1][2]+a[i][2]);
        dp[i][2]=max(dp[i-1][1]+a[i][1],dp[i-1][0]+a[i][0]);
    }

    cout << max(dp[n-1][1],max(dp[n-1][0],dp[n-1][2]));
}


Measured memory_bytes: 2560