akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <algorithm>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <bitset>
#include <complex>
#include <functional>

// output
#define SPBR(w, n) std::cout<<(w + 1 == n ? '\n' : ' ');
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl
// utility
#define ALL(i) (i).begin(), (i).end()
#define FOR(i, a, n) for(int i=(a);i<(n);++i)
#define RFOR(i, a, n) for(int i=(n)-1;i>=(a);--i)
#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 IN(a, x, b) (a<=x && x<b)
#define OUT(a, x, b) (x<a || b<=x)
template<class T> inline T chmax(T & a, const T b) { return a = (a < b) ? b : a; }
template<class T> inline T chmin(T& a, const T b) { return a = (a > b) ? b : a; }

// type/const
#define int ll
using ll = long long;
using ull = unsigned long long;
using ld = long double;
const int MOD = 1000000007;
/* const int MOD = 998244353; */
const int INF = 1e18;
const double PI = acos(-1);

using namespace std;

vector<vector<int>> graph;
vector<int> ans;

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

  X--; Y--;
  graph.resize(N);

  REP(i, N-1){
    graph[i].emplace_back(i+1);
    graph[i+1].emplace_back(i);
  }
  graph[X].emplace_back(Y);
  graph[Y].emplace_back(X);

  ans.resize(N, 0);
  REP(i, N){
    vector<int> dist(N, INF);
    dist[i] = 0;
    queue<int> q;
    q.push(i);
    while(!q.empty()){
      int p = q.front(); q.pop();
      ans[dist[p]]++;
      for(auto v : graph[p]){
        if(dist[v] != INF) continue;
        dist[v] = dist[p]+1;
        q.push(v);
      }
    }
  }

  FOR(i, 1, N){
    cout << ans[i]/2 << endl;
  }

  return 0;
}

Measured memory_bytes: 384
=begin

rectangle width is w
rectangle height is h
circle center is(x,y)
circle radius is r

=end

w, h, x, y, r = gets.split(" ").map(&:to_i)
if x - r >= 0 && 
  y - r >= 0 && 
  x + r <= w &&
  y + r <= h
  puts "Yes"
else
  puts "No"
end


Measured memory_bytes: 8668
#include <vector>
#include <iostream>
#include <unordered_map>
#include <map>
#include <iomanip>
#include <functional>
#include <algorithm>
#include <cassert>
#include <cmath>
#include <string>
#include <sstream>

using namespace std;

#define ll long long
#define d double
#define ld long double
#define pii pair<int,int>
#define wh(x) (x).begin(),(x).end()
#define ri(x) int x;cin>>x;
#define rii(x,y) int x,y;cin>>x>>y;
#define rl(x) ll x;cin>>x;
#define rv(v) for(auto&_cinv:v) cin>>_cinv;
#define wv(v) for(auto&_coutv:v) cout << _coutv << ' '; cout << endl;
#define ev(v) for(auto&_cerrv:v) cerr << _cerrv << ' '; cerr << endl;
#define MOD 1000000007

namespace std { 
template<typename T,typename U>struct hash<pair<T,U>>{hash<T>t;hash<U>u;size_t operator()(const pair<T,U>&p)const{return t(p.x)^(u(p.y)<<7);}};
}
template<typename T,typename F>T bsh(T l,T h,const F&f){T r=-1,m;while(l<=h){m=(l+h)/2;if(f(m)){l=m+1;r=m;}else{h=m-1;}}return r;}
template<typename T,typename F>T bsl(T l,T h,const F&f){T r=-1,m;while(l<=h){m=(l+h)/2;if(f(m)){h=m-1;r=m;}else{l=m+1;}}return r;}
template<typename T> T gcd(T a,T b) { if (a<b) swap(a,b); return b?gcd(b,a%b):a; }


int main(int,char**) {
    ios_base::sync_with_stdio(false);
    int N; cin >> N;
    string S; cin >> S;

    vector<bool> R(N+2);
    for(int i = 0; i < 2; ++i) for (int j = 0; j < 2; ++j) {
        R[0] = i; R[1] = j;
        for (int k = 2; k < N+2; k++) {
            R[k] = R[k-2] ^ (S[(k-1)%N] == 'x') ^ R[k-1];
        }
        if (R[0] == R[N] && R[1] == R[N+1]) {
            for (int i = 0; i < N; i++) {
                cout << "SW"[R[i]]; 
            }
            cout << endl;
            return 0;
        }
    }
    cout << -1 << endl;
}


Measured memory_bytes: 592
N = int(input())
A_list = list(map(int, input().split()))

ans = 1
if 0 in A_list:
    ans = 0
else:
    for l in A_list:

        if ans > (10**18):
            ans = -1
            break
        else:
            ans *= l

if ans > (10**18):
    ans = -1
print(ans)

Measured memory_bytes: 21648
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
using ull = unsigned long long;
using ll = long long;
using namespace std;

int main(void) {

    // c: n, s,m;
    ll s, c;
    cin >> s >> c;

    ll ans = 0;

    // scc
    if (c - 2*s >= 0) {
        // c余り
        ans += s;
        c -= 2*s;

        // 2個で1個sが作れる=> 4個のcがsccを作る
        ans += c/4;
    } else {
        // c足りない
        ans = c/2;
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
	cout << fixed << setprecision(20);
	int a, b;
	cin >> a >> b;
	auto d = a / b;
	auto r = a % b;
	auto f = a / (double)b;
	cout << d<<" " << r<<" " << f << endl;
	return 0;
}


Measured memory_bytes: 3268
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
# define mod 1000000007
# define vi vector<ll>
# define vvi vector<vi>
# define rep(i, N) for (int i = 0; i < N; i++)
# define Rep(i, N) for (int i = 1; i <= N; i++)
# define deb(x) cerr << #x << ": " << x << endl;
# define deb2(x, i) cerr << #x << "[" << i << "]: " << x[i] << endl;
/*
vi v(10, 2); 
rep(i, 10) deb2(v, i); 
*/

/*
int a; cin >> a;
int a, b; cin >> a >> b;
rep(i, n){cin >> v[i];}
cout <<   << endl;
*/

signed		main()
{
	//n % 10 == 
	int n; cin >> n;
	if (n % 10 == 2 or n % 10 == 4 or n % 10 == 5 or n % 10 == 7 or n % 10 == 9)
	{
		cout << "hon" << endl;
	}	
	else if (n % 10 == 0 or n % 10 == 1 or n % 10 == 6 or n % 10 == 8)
	{
		cout << "pon" << endl;
		
	}
	else
	{
		cout << "bon" << endl;
		
	}
}



Measured memory_bytes: 3592
s[50],j,p,q;main(i){for(;p=j=atoi(gets(s));printf("%d\n",i)){for(;j;s[p-j--]=strlen(gets(s+p)));for(i=0;j<7;)for(p=i++,j=q=1;q>0;)for(q=8939616>>j++*4&15;q>1;q-=s[p++]);}}

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

int main() {
    int n, d;
    cin >> n >> d;
    cout << ceil(n/(d*2+1.)) << endl;
    return 0;
}


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

int main() {
	int N;
  	cin >> N;
  int64_t sum = 0;
  vector<int64_t> lucas={2, 1};
  for (int i=2; i<=N; i++){
    sum = lucas.at(i-1) + lucas.at(i-2);
    lucas.push_back(sum);
  }
  cout << lucas.at(N) << endl;
}

Measured memory_bytes: 256
(n,), *z = [[*map(int, o.split())] for o in open(0)]
if n == 1:
    print(1)
    exit()
from itertools import*
from collections import*
print(n - Counter((z[i][0] - z[j][0], z[i][1] - z[j][1]) for i, j in permutations(range(n), 2)).most_common()[0][1])

Measured memory_bytes: 9884
#include <iostream>
#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main()
{
    string s;
    cin >> s;
    if(s[0] == s[1]) cout << "Bad" << endl;
    else if(s[1] == s[2]) cout << "Bad" << endl;
    else if(s[2] == s[3]) cout << "Bad" << endl;
    else if(s[3] == s[4]) cout << "Bad" << endl;
    else cout << "Good" << endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int n, e, i, j;
vector<vector<pair<int, int> > > g;
vector<int> color;
bool v[111001];
void col(int n) {
   queue<int> q;
   int c = 0;
   set<int> vertex_colored;
   if(v[n])
      return;
      v[n] = 1;
   for(i = 0;i<g[n].size();i++) {
      if(color[g[n][i].second]!=-1) {
         vertex_colored.insert(color[g[n][i].second]);
      }
   }
   for(i = 0;i<g[n].size();i++) {
      if(!v[g[n][i].first]) {
         q.push(g[n][i].first);
      }
      if(color[g[n][i].second]==-1) {
         while(vertex_colored.find(c)!=vertex_colored.end())
            c++;
            color[g[n][i].second] = c;
            vertex_colored.insert(c);
            c++;
      }
   }
   while(!q.empty()) {
      int temp = q.front();
      q.pop();
      col(temp);
   }
   return;
}
int main() {
   int u,w;
   set<int> empty;
   // cout<<"Enter number of vertices and edges respectively:";
   // cin>>n>>e;
   // cout<<"\n";
	 cin>>n; e=n-1;
   g.resize(n); //number of vertices
   color.resize(e,-1); //number of edges
   memset(v,0,sizeof(v));
   for(i = 0;i<e;i++) {
      // cout<<"\nEnter edge vertices of edge "<<i+1<<" :"<<"\n";
      cin>>u>>w;
      u--; w--;
      g[u].push_back(make_pair(w,i));
      g[w].push_back(make_pair(u,i));
   }
   col(0);
	 int ans = 0;
	 for(i = 0;i<e;i++) {
		 ans = max(ans,color[i]+1);
	 }
	 cout << ans << endl;
   for(i = 0;i<e;i++) {
      // cout<<"Edge "<<i+1<<" is coloured with colour "<<color[i]+1
      // << "\n";
			cout << color[i]+1 << endl;
   }
}


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

using namespace std;

const int MAX_N = 100000, INDEX = 1;

long long sgn(long long x) {
    if (x == 0) {
        return 0;
    }

    return x / abs(x);
}

int n, a[MAX_N + INDEX];

long long getAns(long long sgni) {
    long long ps = 0, res = 0;
    for (int i = 1; i <= n; i++) {
        ps += a[i];

        if (sgn(ps) != sgni) {
            res += abs(ps) + 1;

            ps = sgni;
        }

        sgni *= -1;
    }

    return res;
}

long long ans;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie();
    cout.tie();

    cin >> n;

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

    ans = min(getAns(1), getAns(-1));

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 768
#include <iostream>
#include <string>
using namespace std;
int main() 
{
	unsigned int testinput;
	cin >> testinput;

	unsigned int ans = to_string(testinput).length();
	//std::cout << ans;
	

	//6桁
	if (ans == 6) {
		std::cout << 909 + testinput - 10000;
		cin >> testinput;
		return 0;
	}

	//5桁
	if (ans == 5) {
		std::cout << 909 + testinput - 9999;
		cin >> testinput;
		return 0;
	}

	//4桁
	if (ans == 4) {
		std::cout << 909;
		cin >> testinput;
		return 0;
	}

	//3桁
	if (ans == 3) {
		std::cout << (testinput - 99 + 9);
		cin >> testinput;
		return 0;
	}

	//2桁
	if (ans == 2) {
		std::cout << "9";
		cin >> testinput;
		return 0;
	}

	//1桁
	if (ans == 1) {
		std::cout << testinput;
		cin >> testinput;
		return 0;
	}

}

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

int n;

map<int, string> kes;

string ask(int x) {
	x += 2*n;
	x %= n;

	if (kes.count(x)) {
		return kes[x];
	}

	cout << x%n << '\n' << flush;
	
	cin >> kes[x];
	if (kes[x] == "Vacant") {
		exit(0);
	}
	return kes[x];
}

int mf(string s) {
	return s == "Male";
}

int parask(int x) {
	return (mf(ask(x)) + x) % 2;
}

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);
	cerr.tie(nullptr);

	cin >> n;

	// prvo pitanje
	int a1 = mf(ask(0));
	int a2 = mf(ask(2));

	if (a1 != a2) {
		ask(1);
	}

	int l = 2;
	int r = n+2;
	int al = parask(2);
	int ar = parask(n+2); // razlicito

	while (l <= r) {
		int m = (l+r) / 2;
		int am = parask(m);

		if (am == al) {
			l = m;
			al = am;
		} else if (am == ar) {
			r = m;
			ar = am;
		}
	}

}

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

using namespace std;
using int64 = long long;

constexpr int DEBUG = 0;

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

  int n;
  cin >> n;
  vector<int> xs;
  function<void(int, int)> dfs_fn = [&](int d, int m) {
    if (d == n) {
      for (int x : xs) {
        cout << static_cast<char>('a' + x);
      }
      cout << "\n";
      return;
    }

    for (int k = 0; k < m; k++) {
      xs.push_back(k);
      dfs_fn(d + 1, m);
      xs.pop_back();
    }
    xs.push_back(m);
    dfs_fn(d + 1, m + 1);
    xs.pop_back();
  };
  dfs_fn(0, 0);
}

Measured memory_bytes: 1536
use std::io::{Read};
use std::io::{stdout, BufWriter, Write};
use std::collections::{HashMap, VecDeque};

// AtCoder Beginner Contest 146 D - Coloring Edges on Tree
fn main() {
    /* BEGIN TEMPLATE */
    let mut buf = String::new();
    std::io::stdin().read_to_string(&mut buf).unwrap();
    let mut sw = buf.split_whitespace();
    macro_rules! get {
        ($t:ty) => {
            sw.next().unwrap().parse().unwrap()
        };
        ($($t:ty),*) => {
            ($(get!($t)),*)
        };
        ($t:ty; $n:expr) => {
            (0..$n).map(|_|
                get!($t)
            ).collect::<Vec<_>>()
        };
        ($($t:ty),*; $n:expr) => {
            (0..$n).map(|_|
                get!($($t:ty),*)
            ).collect::<Vec<_>>()
        };
    }
    let _stdout = stdout();
    let mut out = BufWriter::new(_stdout.lock());
    /* END TEMPLATE */

    let n: usize = get!(usize);
    let mut tree: Vec<Vec<usize>> = vec![Vec::new(); n+1];
    let mut edges: Vec<(usize, usize)> = Vec::with_capacity(n-1);
    let mut edge_colors: HashMap<(usize, usize), usize> = HashMap::new();
    (0..n-1).for_each(|_| {
        let (a, b): (usize, usize) = get!(usize, usize);
        tree[a].push(b);
        tree[b].push(a);
        if a < b {
            edges.push((a, b));
        } else {
            edges.push((b, a));
        }
    });
    let mut colors: Vec<usize> = vec![0; n+1];
    let mut done = vec![false; n+1];
    done[1] = true;
    colors[1] = 0;
    let mut count = colors[1];
    let mut queue: VecDeque<usize> = VecDeque::new();
    queue.push_back(1);
    while !queue.is_empty() {
        let length = queue.len();
        (0..length).for_each(|_|{
            let mut color: usize = 0;
            let front = queue.pop_front().unwrap();
            tree[front].iter().for_each(|&t|{
                if !done[t] {
                    color += 1;
                    if color == colors[front] {
                        color += 1;
                    }
                    colors[t] = color;
                    if color > count {
                        count = color;
                    }
                    done[t] = true;
                    queue.push_back(t);
                    if front < t {
                        *edge_colors.entry((front, t)).or_default() = color;
                    } else {
                        *edge_colors.entry((t, front)).or_default() = color;
                    }
                }
            });
        })
    }
    writeln!(out, "{}", count).unwrap();
    edges.iter().for_each(|&edge| {
        writeln!(out, "{}", edge_colors.entry(edge).or_default()).unwrap();
    })
}

Measured memory_bytes: 16712
#include <bits/stdc++.h>
using namespace std;
int n,a,b,m,p[1<<18],q[1<<18],r[1<<18];
int trans(int x,int y){
    int res=0;
    for(int i=0,j=0,k=n-m;i<n;++i)
        if(y&(1<<i))res|=((x&(1<<k))>>k)<<i,++k;
        else res|=((x&(1<<j))>>j)<<i,++j;
    return res;
}
int main(){
    scanf("%d%d%d",&n,&a,&b);
    m=__builtin_popcount(a^b);
    if(m%2==0){puts("NO");return 0;}
    puts("YES");
    p[0]=0;
    for(int l=1;l<(1<<(n-m));l+=l)
        for(int i=l,j=l;i;--i,++j)p[j]=p[i-1]+l;
    q[0]=0,q[1]=1;
    for(int l=2;l<(1<<m);l+=l){
        for(int i=l,j=l;i;--i,++j)q[j]=q[i-1]+l;
        l+=l;
        int j=l,k=l;
        for(int i=l;i;--i)
            if(q[i-1]!=k-1)q[j++]=q[i-1]+l;
            else k/=2;
        for(;k<l;k=k*2+1)q[j++]=k+l;
    }
    //for(int i=0;i<(1<<(n-m));++i)printf("%d ",p[i]);puts("");
    //for(int i=0;i<(1<<m);++i)printf("%d ",q[i]);puts("");
    for(int i=0,k=0;i<(1<<m);++i)
        if(i&1)for(int j=1<<(n-m);j;--j)r[k++]=(q[i]<<(n-m))|p[j-1];
        else for(int j=0;j<(1<<(n-m));++j)r[k++]=(q[i]<<(n-m))|p[j];
    //for(int i=0;i<(1<<n);++i)printf("%d%c",r[i]," \n"[i+1==(1<<n)]);
    for(int i=0;i<(1<<n);++i)printf("%d%c",trans(r[i],a^b)^a," \n"[i+1==(1<<n)]);
}


Measured memory_bytes: 1536
# Author: cr4zjh0bp
# Created: Sat Mar 14 14:07:54 UTC 2020
import sys
 
stdin = sys.stdin
inf = 1 << 60
mod = 1000000007
 
ni = lambda: int(ns())
nin = lambda y: [ni() for _ in range(y)]
na = lambda: list(map(int, stdin.readline().split()))
nan = lambda y: [na() for _ in range(y)]
nf = lambda: float(ns())
nfn = lambda y: [nf() for _ in range(y)]
nfa = lambda: list(map(float, stdin.readline().split()))
nfan = lambda y: [nfa() for _ in range(y)]
ns = lambda: stdin.readline().rstrip()
nsn = lambda y: [ns() for _ in range(y)]
ncl = lambda y: [list(ns()) for _ in range(y)]
nas = lambda: stdin.readline().split()

N = ni()
m = 3500 // 4

def f():
    ans = []
    for h in range(3501):
        for n in range(3501):
            c = h * n * N
            d = 4 * h * n - N * n - N * h
            if d > 0 and c % d == 0:
                ans = [h, n, c // d]
                return ans

print(*f())

Measured memory_bytes: 39024
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,b,a) for(int i=b;i>=a;i--)
#define fori(a) for(auto i : a )
#define all(a) begin(a), end(a)
#define set(a,b) memset(a,b,sizeof(a))
#define sz(a) a.size()
#define pi 3.14159
#define ll long long
#define ull unsigned long long
#define pb push_back
#define PF push_front //deque
#define mp make_pair
#define pq priority_queue
#define mod 1000000007
#define f first
#define s second
#define pii pair< int, int >
#define vi vector<int>
#define vpii vector<pii>
#define debug(v) for(auto i:v) cout<<i<<" ";
#define tc int t; cin >> t; while(t--)

using namespace std;
string repeat(string s, int n) {
    string s1 = "";
    for (int i=0; i<n;i++)
        s1+=s;
    return s1;
}
string getString(char x) {
    string s(1, x);
    return s;
}

void optimizeIO(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
}
int gcd(int a, int b){
    if (a == 0)  return b;
    return gcd(b % a, a);
}
void  solve(){
  int n,i;
  cin>>n>>i;
  cout<<n-i+1<<endl;
}
int main(){
    optimizeIO();
    // tc
    { solve();
    }
}


Measured memory_bytes: 3596
N = int(input())
h = map(int, input().split())

ans = 0
m = -1
for hh in h:
    if hh >= m:
        ans += 1
        m = hh
print(ans)

'''
自分より左の最大値とだけ比較すればよいので、
最大値を更新して、比較する
'''

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

using namespace std;

#define PB push_back
#define f first
#define s second
#define what_is(x) cerr << #x << " is " << x << endl;

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

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);
    int n, m;
    ll k;
    cin >> n >> m >> k;
    ll a[n+1];
    ll b[m+1];
    for(int i=0; i<n; i++)
    {
        cin >> a[i];
        if(i)
            a[i] += a[i-1];
    }
    for(int j=0; j<m; j++)
    {
        cin >> b[j];
        if(j)
            b[j] += b[j-1];
    }
    int mx = 0;
    for(int i=0; i<n; i++)
    {
        if(a[i] > k)
            break;
        int j = upper_bound(b, b+m, k-a[i]) - b;
        mx = max(mx, j + i + 1);
    }
    for(int j=0; j<m; j++)
    {
        if(b[j] > k)
            break;
        int i = upper_bound(a, a+n, k-b[j]) - a;
        mx = max(mx, j + i + 1);
    }
    cout << mx;
    return 0;
}


Measured memory_bytes: 6764
if __name__ == '__main__':
	N, M = map(int, input().split())
	Xlst = [int(a) for a in input().split()]
	Xlst.sort()
	lst = []
	for i in range(M-1):
		lst.append(Xlst[i+1] - Xlst[i])
	lst.sort()
	if N >= M:
		print(0)
	else:
		print(sum(lst[0:M-N]))

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

using ll = long long;
using pii = pair<int, int>;
template <class T>
using v = vector<T>;
template <class T>
using vv = v<v<T>>;
#define ALL(c) (c).begin(), (c).end()

int main()
{
    int N;
    cin >> N;
    v<int> C(N - 1), S(N - 1), F(N - 1);
    for (int i = 0; i < N - 1; i++)
    {
        cin >> C[i] >> S[i] >> F[i];
    }

    v<ll> ans(N, 0);

    for (int i = 0; i < N - 1; i++)
    {
        ll time = S[i] + C[i];
        for (int j = i + 1; j < N - 1; j++)
        {
            if (time < S[j])
            {
                time = S[j] + C[j];
            }
            else
            {
                time = S[j] + ceil(((double)time - S[j]) / F[j]) * F[j] + C[j];
            }
        }
        ans[i] = time;
    }

    for (int i = 0; i < N; i++)
    {
        cout << ans[i] << endl;
    }

    return 0;
}

Measured memory_bytes: 3628
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;

class Program
{
    static void Main(string[] args)
    {
        var X = int.Parse(ReadLine());

        for (int a = 0; a < 1000; a++)
        {
            var a5 = Enumerable.Range(0, 5).Aggregate(1L, (s, e) => s * a);

            for (int b = -1000; b < 1000; b++)
            {
                var b5 = Enumerable.Range(0, 5).Aggregate(1L, (s, e) => s * b);

                if(a5 - b5 == X)
                {
                    WriteLine($"{a} {b}");
                    return;
                }
            }
        }
    }
}


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

int main()
{
	string S;
	cin >> S;
	int m = stoi(S.substr(5, 2));
	int d = stoi(S.substr(8, 2));
	cout << ((m == 4 ? d <= 30 : m < 4) ? "Heisei" : "TBD") << endl;
	return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <typeinfo>
#include <numeric>
#include <functional>
#include <unordered_map>
#include <bitset>
#include <stack>


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

const ll INF = 1e16;
const ll MOD = 1e9 + 7;

#define REP(i, n) for(ll i = 0; i < n; i++)








int main() {
    ll a[5];
    REP(i, 5){
        cin >> a[i];
    }
    sort(a, a + 5);
    ll ans = INF;
    do{
        ll sum = 0;
        REP(i, 5){
            if(sum % 10) sum += 10 - (sum % 10);
            sum += a[i];
        }
        ans = min(ans, sum);
    }while(next_permutation(a, a + 5));
    cout << ans << endl;
}

Measured memory_bytes: 256
using System;

	class Program
	{
		static void Main(string[] args)
		{
			int n =int.Parse(Console.ReadLine());
			string a =Console.ReadLine();
			string b =Console.ReadLine();
			string c =Console.ReadLine();

			int count =0;
			for(int i=0;i<n;i++)
			{
				if(a.Substring(i,1) ==b.Substring(i,1) && b.Substring(i,1) ==c.Substring(i,1))
				{
				}
				else if(a.Substring(i,1) ==b.Substring(i,1) && b.Substring(i,1) !=c.Substring(i,1))
				{
					count++;
				}
				else if(a.Substring(i,1) ==c.Substring(i,1) && b.Substring(i,1) !=c.Substring(i,1))
				{
					count++;
				}
				else if(b.Substring(i,1) ==c.Substring(i,1) && a.Substring(i,1) !=b.Substring(i,1))
				{
					count++;
				}
				else
				{
					count	= count +2;
				}
			}

			Console.WriteLine(count);
			
		}
	}


Measured memory_bytes: 11092
from queue import deque
s = []
for _ in range(3):
    s.append(deque(input()))
f = lambda x: ord(x)-ord('a')
nxt = 0
while len(s[nxt])>0:
    now = nxt
    nxt = f(s[now].popleft())
print(chr(nxt+ord('A')))

Measured memory_bytes: 4080
import sys
import math
from collections import defaultdict
from bisect import bisect_left, bisect_right

sys.setrecursionlimit(10**7)
def input():
    return sys.stdin.readline()[:-1]

mod = 10**9 + 7

def I(): return int(input())
def LI(): return list(map(int, input().split()))
def LIR(row,col):
    if row <= 0:
        return [[] for _ in range(col)]
    elif col == 1:
        return [I() for _ in range(row)]
    else:
        read_all = [LI() for _ in range(row)]
        return map(list, zip(*read_all))

#################

# "どこかの連続したK個が同じ色"が必要十分

N,K = LI()
a = LI()

dp_l = [0]*N
for i in range(N):
    if a[i] > 0:
        dp_l[i] = dp_l[i-1] + a[i]
    else:
        dp_l[i] = dp_l[i-1]

dp_r = [0]*N
dp_r[N-1] = a[i] if a[i] > 0 else 0
for i in range(N-1)[::-1]:
    if a[i] > 0:
        dp_r[i] = dp_r[i+1] + a[i]
    else:
        dp_r[i] = dp_r[i+1]

kblacks = [0]*(N-K+1)
kblacks[0] = sum(a[:K])
for i in range(1,N-K+1):
    kblacks[i] = kblacks[i-1]+a[K+i-1]-a[i-1]

ans = -float('inf')
for i in range(N-K+1):
    temp = 0
    if i-1 >= 0:
        temp += dp_l[i-1]
    if i+K <= N-1:  
        temp += dp_r[i+K]
    ans = max(ans,temp,temp+kblacks[i])

print(ans)

Measured memory_bytes: 63984
#include<bits/stdc++.h>
#define all(x) (x).begin(),(x).end()
#define ll long long
#define rep(i,n) for(int i = 0; i < int(n); i++)
#define vi vector<int>
using namespace std;
const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, 1, 0, -1};
template<class T> inline bool chmax(T &a, const T &b){ if(a<b) { a=b; return 1; } return 0; }
template<class T> inline bool chmin(T &a, const T &b){ if(b<a) { a=b; return 1; } return 0; }

int main(){
  cin.tie(0), ios::sync_with_stdio(false);
  int n,m; cin >> n >> m;
  vi k(m),p(m);
  vector<vi> s(m);
  rep(i,m){
    cin >> k[i];
    s[i].resize(k[i]);
    rep(j,k[i]) cin >> s[i][j];
  }
  rep(i,m) cin >> p[i];

  int ans = 0;
  rep(bit,1<<n){
    vi check(m);
    rep(i,n){
      if(bit >> i & 1){
        rep(j,m){
          rep(a,k[j]) if(s[j][a] == i+1) check[j] ^= 1;
        }
      }
    }
    bool ok = true;
    rep(i,m) if(p[i] != check[i]) ok = false;
    if(ok) ans++;
  }
  cout << ans;
  cout << "\n";
  return 0;
}


Measured memory_bytes: 3628
MOD = int(1e+9 + 7)
N, K = map(int, input().split())
 
A = [0] * (K + 1) # 要素が全てXの倍数となるような数列の個数をXごとに求める
for x in range(1, K + 1):
    A[x] = pow(K // x, N, MOD)
 
for x in range(K, 0, -1): # 2X, 3Xの個数を求めてひく
    for i in range(2, K // x + 1):
        A[x] -= A[x * i]

ans = 0
for k in range(K+1):
    ans += A[k] * k
ans = ans % MOD
print(ans)

Measured memory_bytes: 11568
#include<stdio.h>
#include<algorithm>
using namespace std;
int p[510000];
int main(){
	int a,b,c;
	scanf("%d%d%d",&a,&b,&c);
	p[0]=b;
	for(int i=1;i<a*2;i++)p[i]=p[i-1]+c;
	double ret=0;
	double L=p[0];
	double R=p[a*2-1];
	int n=a;
	for(int i=0;i<a;i++){
	//	printf("%f %f\n",L,R);
		ret+=(L+R)/2;
		double L2=L+(R-L)/(n*2-1);
		double L3=L+(R-L)/(n*2-1)*2;
		double R2=R-(R-L)/(n*2-1);
		double R3=R-(R-L)/(n*2-1)*2;
		L=(L*(n*2-1)+L2+L3*2)/(n*2);
		R=(R*(n*2-1)+R2+R3*2)/(n*2);
		n--;
	}
	printf("%.12f\n",ret);
}

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

int main(int argc, char *argv[]){
    int a,b,c,k;
    cin >> a >> b >> c >>k;
    if(a>=k){
        cout << k << endl;
        return 0;
    }
    k=k-a;
    if(b>=k){
        cout << a << endl;
        return 0;
    }
    k=k-b;
    a=a-k;
    cout << a << endl;
    return 0;
}

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

int solve(int n) {
  long power { 1L };
  int divider = std::pow(10, 9) + 7;
  for (int i = 1; i <= n; ++i) {
    power = (power * i) % divider;
  }
  return power;
}

int main() {
  int n;
  std::cin >> n;
  std::cout << solve(n) << std::endl;
  return 0;
}



Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
#include <vector>
#include <set>
#include <queue>
#include <algorithm>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;

#define pb push_back
#define mk make_pair
#define f0(i,b) for(int i=0;i<(b);i++)
#define f1(i,b) for(int i=1;i<=(b);i++)
#define f2(i,a,b) for(int i=(a);i<=(b);i++)
#define sf(a) scanf("%d",&a);
#define sfl(a) scanf("%lld",&a);
#define pf(a) printf("%d\n",a);
#define pfl(a) printf("%lld\n",a);
#define TEST int test; cin >> test;while(test--)
#define ii pair<int,int>
#define iil pair<ll,ll>
#define loop(i,a,b) for(int i = a ; i < b ; i++)
#define INF 2147483647


int dx8[] = {0, 0, 1, 1, 1, -1, -1, -1};
int dy8[] = {1,-1, 1, -1, 0, 0, -1, 1};
int dx4[] = {0, 0, 1, -1};
int dy4[] = {1, -1, 0, 0};
const double pi = acos(-1.0);


void solve()
{
  int n , k, d, x;
  cin >> n >> k;
  map<int,int>mp;
  for(int i = 0 ; i < n ; i++){
    cin >> d;
    for(int j = 0 ; j < d ; j++){
      cin >> x;
      mp[x] = d;
    }
  }
  int c = 0;
  for(int i = 1 ; i <= n ; i++)
  {
    if(mp.find(i) == mp.end())
    {
      c++;
    }
  }
  cout << c << endl;
}

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    cout.tie(NULL);
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    //TEST
    solve();
    return 0;
}


Measured memory_bytes: 3668
#include"bits/stdc++.h"

using namespace std;

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

int main(){
    int i;
    //入力
    string s,t;
    cin>>s;

    cin>>t;
    //処理
    int count=0;
    rep(i,3){
        if(s[i]==t[i])count++;
    }
    //出力
    cout<<count<<endl;
}

Measured memory_bytes: 256
class UnionFind:
    def __init__(self, n):
        self.par = [i for i in range(n + 1)]
        self.rank = [0] * (n + 1)
        self.size = [1] * (n + 1)

    def find(self, x):
        if self.par[x] == x:
            return x
        else:
            self.par[x] = self.find(self.par[x])
            return self.par[x]

    def same_check(self, x, y):
        return self.find(x) == self.find(y)

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if self.rank[x] < self.rank[y]:
            if self.same_check(x, y) != True:
                self.size[y] += self.size[x]
                self.size[x] = 0
            self.par[x] = y
        else:
            if self.same_check(x, y) != True:
                self.size[x] += self.size[y]
                self.size[y] = 0
            self.par[y] = x
            if self.rank[x] == self.rank[y]:
                self.rank[x] += 1

    def siz(self, x):
        x = self.find(x)
        return self.size[x]


N = int(input())
UF = UnionFind(N)
X = []
Y = []
Branch = []
for i in range(N):
    x, y = map(int, input().split())
    X.append((x, i))
    Y.append((y, i))
X.sort()
Y.sort()
for X1, X2 in zip(X, X[1:]):
    Branch.append((X2[0] - X1[0], X1[1], X2[1]))
for Y1, Y2 in zip(Y, Y[1:]):
    Branch.append((Y2[0] - Y1[0], Y1[1], Y2[1]))
Branch.sort()

# 負のとき size, 非負のとき parent
par = [-1] * N
ans = 0
for c, a, b in Branch:
    if N <= 1:
        break
    if not UF.same_check(a, b):
        UF.union(a, b)
        ans += c
        N -= 1

print(ans)



Measured memory_bytes: 55760
import numpy as np

n, k = map(int, input().split())
a = list(map(int, input().split()))
f = list(map(int, input().split()))

a = np.sort(a)
f = np.sort(f)[::-1]


def ok(x):
    return np.clip(a - x // f, 0, None).sum() <= k


l, r = 0, 10 ** 12

while l <= r:
    mid = (l + r) // 2
    if ok(mid):
        r = mid - 1
    else:
        l = mid + 1

print(l)

Measured memory_bytes: 43640
FACT = []

def calc_fact(n)
  FACT[0] = 1
  for i in 1..n
    FACT[i] = FACT[i-1] * i
  end
end

n = gets.to_i
x = []
y = []
n.times do |i|
  x[i],y[i]=gets.chomp.split(" ").map(&:to_i)
end

a = []
n.times do |i|
  a.push(i+1)
end

a = a.permutation

sum = 0.0
a.each do |li|
  len = li.length
  for i in 0..len-2
    sum += ( ( x[li[i]-1]  - x[li[i+1]-1] ) ** 2.0 + ( y[li[i]-1] - y[li[i+1]-1]) ** 2.0 ) **(1/2.0)
  end
end

calc_fact(n)

puts sum / FACT[n]

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

#define DUMP(x) cerr << #x << "=" << x << endl
#define DUMP2(x, y) cerr<<"("<<#x<<", "<<#y<<") = ("<<x<<", "<<y<<")"<< endl
#define BINARY(x) static_cast<bitset<16> >(x)

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

#define in_range(x, y, w, h) (0<=(int)(x) && (int)(x)<(int)(w) && 0<=(int)(y) && (int)(y)<(int)(h))
#define ALL(a) (a).begin(),(a).end()

typedef long long ll;
const int INF = 1e9;
typedef pair<int, int> PII;
int dx[4]={0, -1, 1, 0}, dy[4]={-1, 0, 0, 1};

int maxH[101];
int R;

const int CENTER = 50;

int main()
{
    int N;
    while (cin >> R >> N, R || N) {
        memset(maxH, 0, sizeof(maxH));
        rep(i, N) {
            int x1, x2, y;
            cin >> x1 >> x2 >> y;
            for (int xx = x1; xx < x2; xx++) {
                maxH[xx+CENTER] = max(maxH[xx+CENTER], y);
            }
        }

        double ans = 1000000.0;
        for (int x = -R + 1; x < R; x++) {
            int idx = x + CENTER;
            int h = min(maxH[idx-1], maxH[idx]);
            double tmp =  h + R - sqrt(R*R - x*x);

            // DUMP2(x, h);
            // DUMP(tmp);

            ans = min(ans, tmp);
        }

        cout << fixed << setprecision(10) << ans << endl;
    }
}

Measured memory_bytes: 3184
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();
    if(a.equals(b)){
      System.out.println("H");
    }else{
      System.out.println("D");
    }
  }
}


Measured memory_bytes: 21204
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;

int main() {
	int N, L;
	string str[110];
	cin >> N >> L;
	for (int i = 0; i < N; i++) {
		cin >> str[i];
	}
	sort(str, str + N);
	string ketsugou = "";
	for (int i = 0; i < N; i++) {
		ketsugou += str[i];
	}
	cout << ketsugou;
	return 0;
}

Measured memory_bytes: 256
N, K = map(int, input().split())
S = str(input())

RL = 0
for i in range(N-1):
  if S[i]=='R' and S[i+1]=='L':
    RL += 2
    
if S[0]=='L':
  RL += 1
if S[-1]=='R':
  RL += 1

ans = N - RL
ans = min(N - 1, ans + 2 * K)
print(ans)

Measured memory_bytes: 3316
#include <bits/stdc++.h>
using namespace std;
int main()
{
  string n;
  cin >> n;

  for (int i = 0; i < 3; i++) {
    if (n[i] == '1') {
      n[i] = '9';
    } else {
      n[i] = '1';
    }
  }

  cout << n << endl;

  return 0;
}


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

using namespace std;

int main()
{
  int N, bills, change;
  cin >> N;
  
  bills = (N + 1000 - 1) / 1000;  
  change = bills * 1000 - N;
  
  cout << change << endl;
  
  return 0;
  
}

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

tot = S[1:].count('E')
tot_list = [tot]
former_leader = S[0]

for l in range(1, N):
    leader = S[l]
    if (former_leader, leader)  == ('E', 'E'):
        tot -= 1
    if (former_leader, leader)  == ('W', 'W'):
        tot += 1
        
    former_leader = leader  
    tot_list.append(tot)
    
print(min(tot_list))

Measured memory_bytes: 15564
c[5004],d[5004],m,t,u,a,i;main(x){for(scanf("%d%*d",&a);i<a;scanf("%d",++i+c));for(;~scanf("%d",&x);)for(u=i=t=0;i++<a;t=d[i],d[i]=m<u?m=u:u)u=x-c[i]?u:t+1;m=!printf("%d\n",m);}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define ve vector
#define chmin(x,y) x = min(x,y)

int main(){
    ll n;
    cin >> n;
    if(n==0){
        cout << 0 << endl;
        return 0;
    }
    ve<int> s;
    while(n != 0){
        if(n<0){
            s.push_back((-n)%2);
            n += n%2;
        }
        else s.push_back(n%2);
        n /= -2;
    }
    rep(i,s.size())cout << s[s.size()-1-i];
    cout<<endl;
    return 0;
}


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

int main() {

	
	long long A,V,B,W,T,dist;

	cin >> A >> V >> B >> W >> T;
	//vector<long long> A(N);

	dist = V*T - W*T;
	
	
	if (llabs(B - A) <= dist) {
		cout << "YES" << endl;
	}
	else {
		cout << "NO" << endl;
	}
	

}


Measured memory_bytes: 3592
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  	int N,K,Q,game;
  
  	cin>>N>>K>>Q;
  	vector<int> player(N, K-Q);
  
    for (int i=0;i<Q;i++){
    	cin >> game;
      	player.at(game-1)+=1;
    }
  	for (int i=0;i<N;i++){
      if (player.at(i)>0){
      	cout<<"Yes"<<endl;
      }
      else{
      cout<<"No"<<endl;
      }
    }
}

Measured memory_bytes: 1024
#include <stdio.h>

long long l[100];

void layer(int n) {
    int i;
    l[0] = 1;
    for (i=1;i<=n;i++) l[i] = l[i-1]*2 + 3;
}

long long burger(int n, long long c) {
    if (n == 0) return 1;
    else {
        if (c == 1) return 0;
        else if (c == l[n]) return 2*burger(n-1,l[n-1])+1;
        else if (c == (l[n]+1)/2) return burger(n-1,l[n-1])+1;
        else if (c < (l[n]+1)/2) return burger(n-1,c-1);
        else return burger(n-1,l[n-1])+1+burger(n-1,c-2-l[n-1]);
    }
}

int main(void) {
    int N;
    long long X;
    scanf("%d%lld", &N, &X);
    
    layer(N);
    printf("%lld\n", burger(N, X));

    return 0;
}

Measured memory_bytes: 128
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <bitset>
#include <vector>
using namespace std;
 
const int N = 2e5 + 5;
const int MOD = 998244353;
int l[N], r[N], a[N] = {0};

struct SegNode {
    int l, r;
    long long sum;
} tree[N * 4];

void build(int p, int l, int r) {
    tree[p].l = l;
    tree[p].r = r;
    if (tree[p].l == tree[p].r) {
        tree[p].sum = a[l];
        return ;
    }
    int mid = (tree[p].l + tree[p].r) / 2;
    build(p * 2, l, mid);
    build(p * 2 + 1, mid + 1, r);
    tree[p].sum = (tree[p * 2].sum + tree[p * 2 + 1].sum) % MOD;
}

void update(int p, int x, int c) {
    if (tree[p].l == tree[p].r) {
        tree[p].sum = c;
        return ;
    }
    int mid = (tree[p].l + tree[p].r) / 2;
    if (x <= mid) {
        update(p * 2, x, c);
    } else {
        update(p * 2 + 1, x, c);
    }
    tree[p].sum = (tree[p * 2].sum + tree[p * 2 + 1].sum) % MOD;
}

long long query(int p, int l, int r) {
    if (l <= tree[p].l && r >= tree[p].r) {
        return tree[p].sum;
    }
    int mid = (tree[p].l + tree[p].r) / 2;
    long long sum = 0;
    if (l <= mid) {
        sum += query(p * 2, l, r);
        sum %= MOD;
    }
    if (r > mid) {
        sum += query(p * 2 + 1, l, r);
        sum %= MOD;
    }
    return sum;
}

bool judge(const pair<int, int> a, const pair<int, int> b) {
    if (a.first == b.first) {
        return a.second < b.second;
    }
    return a.first < b.first;
}

int main() {
    int n, k;
    scanf("%d %d", &n, &k);
    vector<pair<int, int> > seg;
    for (int i = 0; i < k; ++i) {
        scanf("%d %d", &l[i], &r[i]);
        seg.push_back(make_pair(l[i], r[i]));
    }
    sort(seg.begin(), seg.end(), judge);

    a[1] = 1;
    build(1, 1, n);
    for (int i = 2; i <= n; ++i) {
        long long tmp = 0;
        for (int j = 0; j < seg.size(); ++j) {
            if (seg[j].first >= i) {
                continue;
            }
            int ll = i - seg[j].second;
            int rr = i - seg[j].first;
            // printf("%d %d %d\n", i, ll, rr);
            tmp += query(1, ll, rr);
            tmp %= MOD;
        }
        update(1, i, tmp);
    }
    printf("%lld\n", query(1, n, n));
    return 0;
}

Measured memory_bytes: 11940
import itertools
n = int(input())
x = []
y = []
ans = []
for _ in range(n):
    x_, y_ = map(int, input().split())
    x.append(x_)
    y.append(y_)
for i in range(n):
    for j in range(n):
        ans_ = pow(((x[i]-x[j])**2 + ((y[i]-y[j])**2)), 0.5)
        ans.append(ans_)
print(sum(ans)/n)

Measured memory_bytes: 3188
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < n; ++i)
#define rrep(i, n) for(int i = n-1; i >= 0; --i)
#define fi first
#define se second
using namespace std;
using lint = long long;
using uint = unsigned int;
using ulint = unsigned long long;
using ldouble = long double;
using pii = pair<int, int>;
using pli = pair<lint, lint>;
using pdd = pair<double, double>;
using pld = pair<ldouble, ldouble>;
using v1i = vector<int>;
using v1li = vector<lint>;
using v2i = vector<vector<int>>;
using v2li = vector<vector<lint>>;
using v3i = vector<vector<vector<int>>>;
using v3li = vector<vector<vector<lint>>>;
using v1b = vector<bool>;
using v2b = vector<vector<bool>>;
using v3b = vector<vector<vector<bool>>>;
using v1c = vector<char>;
using v2c = vector<vector<char>>;
using v3c = vector<vector<vector<char>>>;
constexpr lint mod1 = 1e9+7;
constexpr lint mod2 = 998244353;

int main() {
  lint n, p = 0, q = 0, r = 0, s = 0;
  cin >> n;
  v1i v(n), w(n), a(n), b(n);
  rep(i, n) cin >> v[i];
  w[0] = v[0];
  rep(i, n-1) w[i+1] = w[i] + v[i+1];
  rep(i, n){
    a[i] = w[i];
    a[i] += r;
    if(i % 2 == 0){
      if(a[i] < 0){
        p += 1-a[i];
        r += 1-a[i];
      }
      else if(a[i] == 0){
        p += 1;
        r += 1;
      }
    }
    else{
      if(a[i] > 0){
        p += a[i]+1;
        r -= a[i]+1;
      }
      else if(a[i] == 0){
        p += 1;
        r -= 1;
      }
    }
  }
  rep(i, n){
    b[i] = w[i];
    b[i] += s;
    if(i % 2 == 1){
      if(b[i] < 0){
        q += 1-b[i];
        s += 1-b[i];
      }
      else if(b[i] == 0){
        q += 1;
        s += 1;
      }
    }
    else{
      if(b[i] > 0){
        q += b[i]+1;
        s -= b[i]+1;
      }
      else if(b[i] == 0){
        q += 1;
        s -= 1;
      }
    }
  }
  cout << min(p, q) << endl;
  return 0;
}

Measured memory_bytes: 1792
#include "bits/stdc++.h"
using namespace std;

int main(){
	int h,w;
	cin>>h>>w;
	string s;
	map<char,int> c;
	for(int i=0;i<h;i++){
		cin>>s;
		for(int j=0;j<w;j++){
			c[s[j]]++;
		}
	}
	
	int f=(h/2)*(w/2);
	
	//cout<<f<<endl;
	
	vector<int> youso;
	for(auto x:c){
		//cout<<x.second<<endl;
		youso.push_back(x.second);
	}
	
	//for(int i=0;i<youso.size();i++)cout<<youso[i]<<endl;
	sort(youso.begin(),youso.end(),greater<int>());
	for(int i=0;i<youso.size();i++){
		if(f==0)break;
		while(f!=0&&youso[i]>=4){
			youso[i]-=4;
			f--;
		}
	}
	
	int ama=0;
	
	for(int i=0;i<youso.size();i++){
		ama+=youso[i]%2;
	}
	//cout<<f<<" "<<ama<<endl;
	
	if(f==0){
		if(h*w%2==0&&ama==0){
			cout<<"Yes"<<endl;
		}else if(h*w%2==1&&ama==1){
			cout<<"Yes"<<endl;
		}else{
			cout<<"No"<<endl;
		}
	}else{
		cout<<"No"<<endl;
	}
	
}

Measured memory_bytes: 256
import math


def koch(n, p1x, p1y, p2x, p2y):
    if n == 0:
        return

    sx = (2*p1x + 1*p2x)/3
    sy = (2*p1y + 1*p2y)/3
    tx = (1*p1x + 2*p2x)/3
    ty = (1*p1y + 2*p2y)/3
    theta = math.pi/3
    ux = math.cos(theta)*(tx-sx) - math.sin(theta)*(ty-sy) + sx
    uy = math.sin(theta)*(tx-sx) + math.cos(theta)*(ty-sy) + sy

    koch(n-1, p1x, p1y, sx, sy)
    print("{:.5f} {:.5f}".format(sx, sy))
    koch(n-1, sx, sy, ux, uy)
    print("{:.5f} {:.5f}".format(ux, uy))
    koch(n-1, ux, uy, tx, ty)
    print("{:.5f} {:.5f}".format(tx, ty))
    koch(n-1, tx, ty, p2x, p2y)

n = int(input())

p1x, p1y = 0.0, 0.0
p2x, p2y = 100.0, 0.0

print("{:.5f} {:.5f}".format(p1x, p1y))
koch(n, p1x, p1y, p2x, p2y)
print("{:.5f} {:.5f}".format(p2x, p2y))

Measured memory_bytes: 7984
#include<stdio.h>

int main(){
  int a,b,x;
  char op;
  for(x=1;x>0;x++){
      scanf("%d %c %d",&a,&op,&b);
    if(op =='+'){
       printf("%d\n",a+b);
     } else if(op =='-'){
       printf("%d\n",a-b);
     } else if(op =='*'){
       printf("%d\n",a*b);
     } else if(op =='/'){
       printf("%d\n",a/b);
     } else if(op =='?'){
       break;
     }      
   }
   return 0;
}


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

int main()
{
    ll n, d, ans = 0;
    cin >> n >> d;
    ll x[n][d];
    rep(i, n) rep(j, d) cin >> x[i][j];

    for (ll i = 0; i < n - 1; i++)
    {
        for (ll j = i+1; j < n; j++)
        {
            double dist = 0;
            for (ll k = 0; k < d; k++)
            {
                dist += (x[i][k] - x[j][k]) * (x[i][k] - x[j][k]);
            }
            if (ceil(sqrt(dist)) == floor(sqrt(dist)))
                ans++;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3628
#include "bits/stdc++.h"

#define REP(i,n) for(ll i=0;i<ll(n);++i)
#define RREP(i,n) for(ll i=ll(n)-1;i>=0;--i)
#define FOR(i,m,n) for(ll i=m;i<ll(n);++i)
#define RFOR(i,m,n) for(ll i=ll(n)-1;i>=ll(m);--i)
#define ALL(v) (v).begin(),(v).end()
#define UNIQUE(v) v.erase(unique(ALL(v)),v.end());
#define DUMP(v) REP(aa, (v).size()) { cout << v[aa]; if (aa != v.size() - 1)cout << " "; else cout << endl; }
#define INF 1000000001ll
#define MOD 1000000007ll
#define EPS 1e-9

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


using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
ll max(ll a, int b) { return max(a, ll(b)); }
ll max(int a, ll b) { return max(ll(a), b); }
ll min(ll a, int b) { return min(a, ll(b)); }
ll min(int a, ll b) { return min(ll(a), b); }


int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;
	cin >> n;
	vi v(n);
	REP(i, n)cin >> v[i];
	int p = n;
	vi pos(n);
	RREP(i, n) {
		if (v[i] != 0)p = i;
		else pos[i] = p;
	}
	ll ans = 0;
	REP(i, n) {
		ll cnt = 0;
		ll tmp = 0;
		int j = i;
		while (j<n) {
			if (v[j] == 0) {
				cnt += pos[j] - j;
				j = pos[j];
			}
			if (j >= n)break;
			if ((tmp^v[j]) == (tmp + v[j])) {
				
				tmp ^= v[j];
				j++;
				cnt++;
				
			}
			else {
				break;
			}
		}
		ans += cnt;
	}
	cout << ans << endl;
}


Measured memory_bytes: 1792
n, *a = map(int, open(0).read().split())
MOD = 10**9 + 7
c = 0
for i in range(61):
  i = 2**i
  t = sum(i & b and 1 for b in a)
  c = (c + t * (n - t) * i) % MOD
print(c)

Measured memory_bytes: 38884
#include<iostream> 
    #include<map>
    using namespace std;
    map <string,bool> MAP;
    int main(){
        ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
        int n;  cin >> n;
        while(n--){
            string s;   cin >> s;
            MAP[s] = 1;
        }
        cout << MAP.size();
        return 0;
    }

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

#define INF 1 << 29
#define REP(i,n) for(int i=0; i<(int)(n); i++)
#define FOR(i,k,n) for(int i=(k);i<(int)(n);i++)

using namespace std;

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

void gen_sosuu(int sosuu[]){
  REP(i,100010){
    sosuu[i] = true;
  }
  sosuu[0] = false;
  sosuu[1] = false;
  sosuu[2] = true;
  FOR(i,2,sqrt(100000)+1){
    if(sosuu[i] == false) continue;
    for(int j = 2; i*j<=100000;j++){
      //printf("%d %d %d\n",i*j,i,j);
      sosuu[i*j] =false;
    }
  }
}

int sx,sy,tx,ty;

int main(){
  cin >> sx>>sy>>tx>>ty;
  int w = tx-sx;
  int h = ty-sy;
  REP(i,w) cout << "R";
  REP(i,h) cout << "U";
  REP(i,w) cout << "L";
  REP(i,h) cout << "D";
  cout << "L";
  REP(i,h+1) cout << "U";
  REP(i,w+1) cout << "R";
  cout << "D";
  cout << "R";
  REP(i,h+1) cout << "D";
  REP(i,w+1) cout << "L";
  cout << "U" <<endl;
}


Measured memory_bytes: 256