akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<algorithm>
//deque/functional/iterator/list/map/memory/numeric/queue/set/stack/utility/vector
//#include<bits/stdc++.h>
#define ll long long
using namespace std;


int main()
{
	ios::sync_with_stdio(false);
	int a,b,c;
	cin>>a>>b>>c;
	int x=1;
	int k[100]={0};
	int flag=0;
	while(1){
		int y=a*x%b;
		if(k[y]) break;
		k[y]=1;
		if(y==c%b){
			flag=1;
			break;
		}
		x++;
	}
	if(flag){
		cout<<"YES"<<endl;
	}else cout<<"NO"<<endl;

return 0;
}


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

// #include <ext/pb_ds/assoc_container.hpp> 
// #include <ext/pb_ds/tree_policy.hpp> 
// using namespace __gnu_pbds; 

#define int long long
#define mod 1000000007
#define pb push_back
#define S second
#define F first
#define INF 1e18
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> 

#define deb(x) cerr << "\n" \
                    << #x << "=" << x << "\n";
#define deb2(x, y) cerr << "\n" \
                        << #x << "=" << x << "\n" \
                        << #y << "=" << y << "\n";
#define w(x) \
  int x;     \
  cin >> x;  \
  while (x--)

int32_t main() {

  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n;
  cin >> n;
  int t = 0;
  int ans = 0;
  for(int i = 0; i < n; ++i) {
    int x,y;
    cin >> x >> y;
    if(x == y) {
      t++;  
    }else {
      t = 0;  
    }
    if(t >= 3)
      ans = 1;
  }
  if(ans)
    cout << "Yes";
  else cout << "No";
  return 0;
}


Measured memory_bytes: 3604
#include  <iostream>
#include  <vector>
#include  <algorithm>

using namespace std;

int main()
{
	int n;
	vector <int> V;

	cin >> n;
	for (int i = 0; i < n; i++) {
		int x; cin >> x;
		V.push_back(x);
	}

	sort(V.begin(), V.end());
	int t = n / 2;
	
	cout << V[t] - V[t - 1] << endl;

}

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

using namespace std;

vector<int> par;

int root(int x) {
  if (par[x] < 0) return x;
  return par[x] = root(par[x]);
}

bool unite(int x, int y) {
  x = root(x);
  y = root(y);

  if (x == y) return false;

  if (par[x] > par[y]) swap(x, y);

  par[x] += par[y];
  par[y] = x;

  return true;
}

int size(int x) {
  return -par[root(x)];
}

int main(void) {

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

  par.reserve(n);

  for (int i = 0; i < n; i++) {
    par[i] = -1;
  }

  for (int i = 0; i < m; i++) {

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

    a--; b--;

    unite(a, b);

  }

  int ans = 0;
  for (int i = 0; i < n; i++) {
    ans = max(ans, size(i));
  }

  cout << ans << endl;

  return 0;

}


Measured memory_bytes: 3984
#include <vector>
#include <map>
#include <stack>
#include <queue>
#include <cstring>
#include <string>
#include <sstream>
#include <algorithm>
#include <iomanip>
#include <iostream>

#define VARIABLE(x) cerr << #x << "=" << x << endl
#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++)

const int INF = 10000000;
using namespace std;
typedef long long  ll;


/** Problem0092 : Square Searching
 !! TLE !! **/
int d[1010][1010];
char c[1010][1010];
int n;

bool check(int i)
{
	REP(y, 1, n+1) {
		REP(x, 1, n+1) {
			if (x-i>=0 && y-i>=0 && i*i == d[x][y] - d[x-i][y] - d[x][y-i] + d[x-i][y-i])
				return true;
		}
	}
	return false;
}

int main()
{
	while (cin >> n, n) {
		rep(i, n) {
			rep(j, n) {
				char cc; cin >> cc;
				c[j][i] = cc;
			}
		}
		
		rep(i, 1010) {
			d[i][0]=0;
			d[0][i]=0;
		}
		
		REP(i, 1, n+1) {
			REP(j, 1, n+1) {
				if (c[j-1][i-1]=='.') {
					d[j][i]=1+d[j-1][i]+d[j][i-1]-d[j-1][i-1];
				} else {
					d[j][i]=d[j-1][i]+d[j][i-1]-d[j-1][i-1];
				}
			}
		}
		int lb = 0, ub=INF;
		
		rep(i, 100) {
			int mid = (lb+ub)/2;
			if (!check(mid)) {
				ub=mid;
			} else {
				lb=mid;
			}
		}
		cout << lb << endl;
	}
	return 0;
}

Measured memory_bytes: 6128
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N,K;
  string S;
  cin >> N >> K >> S;
  int count=1;
  for(int i = 1; i < N; i++){
    if(S[i] != S[i-1]){
      count ++;
    }
  }
  cout <<N+min(-1,-count+2*K)<<endl;
}

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

// int arr[100001];

int main(){
	int N,K;
	cin>>N>>K;
	vector<int>stones(N);
	vector<int>dp(K+1, 0);
	
	for(int i = 0; i < N; ++i){
		int val;
		cin>>val;
		stones[i] = val;
	}

	for(int i = 1; i <= K; ++i){
		for(int j = 0; j < stones.size(); ++j){
			if(stones[j] <= i){
				if(dp[i- stones[j]] == 0){
					dp[i] = 1;
				}
			}
		}
	}
	cout<<endl;

	if(dp[K] == 1){
		cout<<"First"<<endl;
	}
	else cout<<"Second"<<endl;
}

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

#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define MIN(a, b) ((a) < (b) ? (a) : (b))

const int ARR_SIZE = 3e5+5;

int N = 0;

struct Node {
    int val;
};

Node arr[ARR_SIZE<<2];

void Pushup(int root) {
    arr[root].val = MAX(arr[root<<1].val, arr[root<<1|1].val);
}

void Update(int root, int rl, int rr, int vl, int vr, int val) {
    // return point
    if (vl <= rl && rr <= vr) {
        arr[root].val = val;
        return;
    }

    // split
    int mid = (rl+rr)>>1;
    if (mid >= vl) {
        Update(root<<1, rl, mid, vl, vr, val);
    }
    if (mid < vr) {
        Update(root<<1|1, mid+1, rr, vl, vr, val);
    }

    // pushup
    Pushup(root);
}


int Query(int root, int rl, int rr, int ql, int qr) {
    // return point
    if (ql <= rl && rr <= qr) {
        return arr[root].val;
    }

    // split query
    int maxVal = 0;

    int mid = (rl+rr)>>1;
    if (mid >= ql) {
        int l = Query(root<<1, rl, mid, ql, qr);
        maxVal = MAX(maxVal, l);
    }
    if (mid < qr) {
        int r = Query(root<<1|1, mid+1, rr, ql, qr);
        maxVal = MAX(maxVal, r);
    }

    return maxVal;
}


int main(int argc, char const *argv[])
{
    int nCases = 1;
    //scanf("%d", &nCases);

    for (int iCase = 1; iCase <= nCases; ++iCase) {
        int K;
        scanf("%d%d", &N, &K);
        
        int ans = 0;
        for (int i = 1; i <= N; ++i) {
            int x;
            scanf("%d", &x);

            int maxFront = Query(1, 0, 3e5, MAX(0, x-K), MIN(3e5, x+K));
            Update(1, 0, 3e5, x, x, maxFront+1);

            ans = MAX(ans, maxFront+1);
        }


        

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

    return 0;
}


Measured memory_bytes: 7928
n, q = map(int, input().split())
edge = [[] for _ in range(n)]
count = [0] * n

for _ in range(n - 1):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    edge[a].append(b)
    edge[b].append(a)

for _ in range(q):
    p, x = map(int, input().split())
    p -= 1
    count[p] += x

not_yet = [True] * n
not_yet[0] = False
stack = [0]
while stack:
    parent = stack.pop()
    for child in edge[parent]:
        if not_yet[child]:
            count[child] += count[parent]
            not_yet[child] = False
            stack.append(child)
print(*count)

Measured memory_bytes: 55856
extern crate proconio;
use proconio::{fastout, input, marker::Usize1};

use std::cmp;
use std::collections;

struct State<T>(u64, T);

impl<T> cmp::PartialEq for State<T> {
    fn eq(&self, other: &Self) -> bool {
        self.0 == other.0
    }
}

impl<T> cmp::Eq for State<T> {}

impl<T> cmp::PartialOrd for State<T> {
    fn partial_cmp(&self, other: &Self) -> Option<cmp::Ordering> {
        other.0.partial_cmp(&self.0)
    }
}

impl<T> cmp::Ord for State<T> {
    fn cmp(&self, other: &Self) -> cmp::Ordering {
        other.0.cmp(&self.0)
    }
}

#[fastout]
fn main() {
    input!{
        n: usize,
        m: usize,
        s: u32,
        es: [(Usize1, Usize1, usize, u64); m],
        vs: [(u32, u64); n],
    }
    let lim = es.iter().map(|&(_, _, a, _)| a).max().unwrap() * (n - 1) + 1;
    let s = cmp::min(s, (lim - 1) as u32) as usize;
    let vs = vs.into_iter()
        .map(|(c, d)| (cmp::min(c, (lim - 1) as u32) as usize, d))
        .collect::<Vec<_>>();
    let mut heap = collections::BinaryHeap::new();
    let mut g = vec![Vec::new(); n];
    for (u, v, a, b) in es {
        g[u].push((v, a, b));
        g[v].push((u, a, b));
    }

    let mut dist = vec![std::u64::MAX; n * lim];
    dist[0 * lim + s] = 0;
    heap.push(State(0, 0 * lim + s));
    while let Some(State(t, i)) = heap.pop() {
        let v = i / lim;
        let k = i % lim;
        if dist[i] < t {
            continue;
        }
        {
            let &(c, d) = &vs[v];
            if k + c < lim {
                let j = v * lim + k + c;
                if t + d < dist[j] {
                    dist[j] = t + d;
                    heap.push(State(dist[j], j));
                }
            }
        }
        for &(u, a, b) in &g[v] {
            if k >= a {
                let j = u * lim + k - a;
                if t + b < dist[j] {
                    dist[j] = t + b;
                    heap.push(State(dist[j], j));
                }
            }
        }
    }
    for t in 1..n {
        println!(
            "{}",
            dist[t * lim..t * lim + lim].iter().copied().min().unwrap()
        );
    }
}


Measured memory_bytes: 4072
#include<iostream>
#include<string>
#include<cstdio>
#include <cstring>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
using namespace std;
typedef long long ll;
typedef unsigned int ui;
const ll mod = 1000000007;
typedef long double ld;
const ll INF = 1e+14;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef complex<ld> Point;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<ld, ld> LDP;
typedef pair<ll, ll> LP;
#define fr first
#define sc second
#define all(c) c.begin(),c.end()
#define pb push_back

void Yes(){
	cout<<"Yes"<<endl;
	exit(0);
}
 
void No(){
	cout<<"No"<<endl;
	exit(0);
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
    ll S; cin >> S;
	cout << 0 << " " << 0 << " ";
	ll T = 1e+9;
	ll U = (S + T - 1) / T;
	ll V = T * U - S;
	cout << T << " " << V << " " << 1 << " " << U << endl;
	return 0;
}

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

#define TASKNAME ""

using namespace std;

const int INF = 1e9 + 7;
const int MAXN = 1e5 + 7;
const double EPS = 1e-8;
const int LOGN = 30;
const double PI = 3.14159265358979323846;
bool down = 0;

bool cmp(pair <int, int> a, pair <int, int> b) {
   return a.first < b.first;
}

int main() {
    #ifdef MY
        freopen("input.txt", "r", stdin);
        //freopen("output.txt", "w", stdout);
    #else
        //freopen(TASKNAME".in", "r", stdin);
        //freopen(TASKNAME".out", "w", stdout);
    #endif // MY
    int x1, y1, x2, y2;
    cin >> x1 >> y1 >> x2 >> y2;
    if (x1 > x2) {
        swap(x1, x2);
        swap(y1, y2);
    }
    if (y1 > y2) {
        down = true;
    }
    int n;
    cin >> n;
    vector <pair <int, int> > a;
    for (int i = 0; i < n; i++) {
        int x, y;
        cin >> x >> y;
        if (x < x1 || x > x2) continue;
        if (down) {
            if (y > y1 || y < y2) continue;
        } else {
            if (y < y1 || y > y2) continue;
        }
        a.push_back({x, y * (down ? -1 : 1)});
    }
    sort(a.begin(), a.end());
    vector <int> t(n + 2, INF);
    t[0] = -INF;
    for (auto p : a) {
        int y = p.second;
        int pos = upper_bound(t.begin(), t.end(), y) - t.begin();
        t[pos] = y;
    }
    int cnt = 0;
    for (int i = 1; i <= n + 1; i++) {
        if (t[i] == INF) {
            cnt = i - 1;
            break;
        }
    }
    cout.precision(25);
    double ans = (ll) ((x2 - x1) + abs(y2 - y1)) * (ll) 100;
    /*if ((x1 == x2 || y1 == y2) && a.size()) {
        cout << ans + 20 * (PI / 2 - 1);
        return 0;
    }*/
    ans -= 20 * cnt;
    ans += PI * 5 * cnt;
    if (cnt == abs(x2 - x1) + 1 || cnt == abs(y2 - y1) + 1) {
        ans += 5 * PI;
    }
    cout << ans;
}


Measured memory_bytes: 2544
#include <iostream>
#include <cstring>
#include <stdio.h>
#include <math.h>
using namespace std;


int min(int a,int b)
{
    return a<b?a:b;
}
int max(int a,int b)
{
    return a>b?a:b;
}


int main(void){
    char s[100020];
    cin >> s;
    int rez=strlen(s);
    for (int i=1; i<strlen(s); i++)
    {
        if (s[i]!=s[i-1])
                 {
                    rez=min(rez,max(i,strlen(s)-i));
                 }
    }
    cout << rez;
    return 0;
}

Measured memory_bytes: 888
#include <iostream>
#include <string>
#include <queue>
#include <vector>
#include <algorithm>
#include <math.h>
#include <map>
#include <iomanip>
#include <queue>


using namespace std;

int DP[100001];

int main() {
    int X;
    cin >> X;
    DP[0] = 1;
    for (int i = 100; i < 106; i++) {
        DP[i] = 1;
    }

    for (int i = 106; i <= 100000; i++) {
        DP[i] = max({ DP[i - 100],DP[i - 101],DP[i - 102],DP[i - 103],DP[i - 104],DP[i - 105] });
    }
    cout << DP[X];
}

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

int main() {
    int N;
    long long int K;
    cin >> N >> K;

    vector<int> ikisaki(N*2+1);
    for(int i=1; i<=N; i++){
        cin >> ikisaki[i];
    }
    ikisaki[0] = 1;

    vector<int> visited(2*N+10,-1);
    vector<int> keiro(2*N+1);

    keiro[0]=1;
    visited[1]=0;

    int r=1;
    int l=1;
    if(K<=2*N){
        for(int i=1; i<=K; i++){
            keiro[i] = ikisaki[keiro[i-1]];
        }
        cout << keiro[K] << endl;
    }
    else{
    for(int i=1; i<=2*N; i++){
        keiro[i] = ikisaki[keiro[i-1]];
        if(visited[keiro[i]]==-1){
            visited[keiro[i]]=i;
        }
        else{
            r = i - visited[keiro[i]];
            l = visited[keiro[i]];
            // cout << i << " " << r  << " " << l;
            break;
        }
    }
    cout << keiro[(K-l)%r + l] << endl;
    }
}


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

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

    let mut sum: i32 = 0;

    for i in 0..(1 << n) {
        let mut sum_v = 0;
        let mut sum_c = 0;
        for j in 0..n {
            if (i >> j) & 1 == 1 {
                sum_v += v[j];
                sum_c += c[j];
            }
        }

        sum = std::cmp::max(sum, (sum_v - sum_c) as i32);
    }

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


Measured memory_bytes: 2112
a = list(input())
b = list(input())
dica = {}
dicb = {}
la = []
lb = []
ite = 0
for ia in a:
  if ia in dica:
    la.append(dica[ia])
  else:
    dica[ia] = ite
    la.append(ite)
    ite+= 1

ite = 0
for ib in b:
  if ib in dicb:
    lb.append(dicb[ib])
  else:
    dicb[ib] = ite
    lb.append(ite)
    ite+= 1
if la == lb:
  print("Yes")
else:
  print("No")

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

int main() {
    int a,b;
    string ans="No";
    cin >> a >> b;
    int c;
    for(int i=2;i>=0;i--){
        c=pow(10,i);
        if(b%c!=b){
            break;
        }
    }
    int d=a*c*10+b;
    for(int i=0;i<1000;i++){
        if(i*i==d){
            ans="Yes";
            break;
        }
    }
    cout << ans <<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <stdio.h>
#include <stdlib.h>
#include <vector>
#include <algorithm>

int main() {

    int X, A, tmp1, tmp2, i = 0, ans = 100, cst = 1;

    std::cin >> X >> A;


    if(X < A){
        ans = 0;
        std::cout << ans << std::endl;
    }else {
        ans = 10;
        std::cout << ans << std::endl;
    }
    
    return 0;
}


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

#define REP(i,num) for(int i=0;i<(num);++i)
#define ALL(c) c.begin(),c.end()
#define PRINTALL(c) for(auto& x:c){cout<<x<<' ';}cout<<endl;
#define PAIRCOMP(c,comp) [](const pair<ll,ll>& lhs,const pair<ll,ll>& rhs){return lhs.c comp rhs.c;}

using namespace std;
using ll = long long;

constexpr ll atcoder_mod = 1e9+7;

template<typename T=int>
T in(){T x; cin >> x; return (x);}
template<typename T=int,typename C=vector<T>>
C vecin(int N){C x(N);REP(i,N){x[i]=in<T>();}return move(x);}

void vout(){cout << endl;}
template<typename Head,typename... Tail>
void vout(Head&& h,Tail&&... t){cout << ' ' << h;vout(forward<Tail>(t)...);}
void out(){cout << endl;}
template<typename Head,typename... Tail>
void out(Head&& h,Tail&&... t){cout << h;vout(forward<Tail>(t)...);}

ll MergeSort(vector<int>& A){
	int num = A.size();
	if(num<=1) return 0;

	ll cnt=0;
	vector<int> B(A.begin(),A.begin()+num/2);
	vector<int> C(A.begin()+num/2,A.end());

	cnt += MergeSort(B);
	cnt += MergeSort(C);

	int ai=0,bi=0,ci=0;
	int bnum=B.size(),cnum=C.size();
	while(ai<num){
		if(bi<bnum && (ci==cnum || B[bi]<=C[ci])){
			A[ai++] = B[bi++];
		} else {
			cnt += num/2-bi;
			A[ai++] = C[ci++];
		}
	}
	return cnt;
}

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

	int N=in();
	auto A=vecin(N);
	auto num = MergeSort(A);

	out(num);
	return 0;
}



Measured memory_bytes: 5336
(stdin => {
  // Define Function
  // Declare Variable
  const inputs = stdin.toString().trim().split(' ')
  const x = parseInt(inputs[0], 10)
  const hour = Math.floor(x/(60*60))
  const min = Math.floor((x%3600)/60)
  const sec = Math.floor(x%60)
 console.log(`${hour}:${min}:${sec}`)
})(require('fs').readFileSync('/dev/stdin', 'utf8'))



Measured memory_bytes: 15108
using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using System.Numerics;

class AtCoder
{
    const int MOD = 1000000007;
    
    public void Slove()
    {
        var input = Console.ReadLine();
        int[] hist = new int[26];
        foreach(var c in input)
        {
            hist[c - 'A']++;
        }
        var ans = hist.All(x => x == 0 || x == 2);
        System.Console.WriteLine(ans ? "Yes" : "No");
    }
    static void Main()
    {
        var ac = new AtCoder();
        ac.Slove();
    }
}

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

int main() {
    Int n, m; cin >> n >> m;
   
   Int ans = 0;
    if (n == m/2) cout << n <<  endl;
    else if (n > m/2) {
        cout << m/2 << endl;
    }
    else {
        Int ans = n;
        m = m - n -n;
        cout << ans + (m/4) << endl;
    }
}

Measured memory_bytes: 384
n = int(input())
p = list(map(int, input().split()))

m = []
a = p[0]
for j in range(n):
    if a >= p[j]:
        a = p[j]
        m.append(a)
    else:
        m.append(a)

ans = 1
for i in range(n-1):
    if m[i] > m[i+1]:
        ans += 1
        
print(ans)

Measured memory_bytes: 26012
#include <bits/stdc++.h>
using namespace std;
int main() {
  int N; cin >> N;
  vector<int> v (N, 0);
  for(int i = 0; i < N; i++) {
    cin >> v[i];
  }
  int cur = 1;
  int ans = 0;
  while(cur < N) {
    if(v[cur] != v[cur - 1]) {
      cur++;
      continue;
    }
    ans++;
    cur += 2;
  }
  cout << ans << endl;
}

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

using namespace std;

int main(){
    while(1){
        int e;
        int ans=1e9+7;
        cin>>e;
        if(e==0)break;
        
        rep(i,0,1000){
            rep(j,0,1000){
                int k=e-i*i-j*j*j;
                if(k<0)continue;
                ans=min(ans,i+j+k);
            }
        }
        cout<<ans<<endl;
    }
    return 0;
}



Measured memory_bytes: 3124
#include <bits/stdc++.h>
using namespace std;
const double pi = acos(-1);
const double EPS = 1e-7;
const long long mod = 1e9 + 7;
#define Hello ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define ll long long
#define ld long double
#define X real()
#define Y imag()
#define cross(a,b) (conj(a)*(b)).imag()
#define dot(a,b) (conj(a)*(b)).real()
#define dist(a,b) ( pow(a.X - b.X, 2) + pow( a.Y - b.Y, 2 ) )
typedef tuple <int, int, int> line;
typedef complex <double> point;
typedef vector <point> polygon;
ld ans[3000][3000] = {}, arr[3000] = {};
int main()
{
    Hello
    int n;
    ld anss = 0;
    cin >> n;
    for (int i = 1; i <= n; i++)
        cin >> arr[i];
    ans[1][0] = 1 - arr[1];
    ans[1][1] = arr[1];
    for (int i = 2; i <= n; i++)
    {
        for (int j = 0; j <= n; j++)
        {
            if ( j <= i )
            {
                ans[i][j] = (ans[i - 1][j]*(1 - arr[i]));
                if ( j )
                    ans[i][j] += (ans[i - 1][j - 1]*(arr[i]));
            }
        }
    }
    for (int i = ( n + 1 )/2; i <= n; i++)
        anss += ( ans[n][i] );
    cout << fixed << setprecision(10) << anss;
    return 0;
}



Measured memory_bytes: 139136
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//#include <boost/multiprecision/cpp_int.hpp>
//typedef boost::multiprecision::cpp_int ll;
typedef long double dd;
#define i_7 (ll)(1E9+7)
//#define i_7 998244353
#define i_5 i_7-2
ll mod(ll a){
    ll c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
typedef pair<ll,ll> l_l;
ll inf=(ll)1E17;
#define rep(i,l,r) for(ll i=l;i<=r;i++)
#define pb push_back
ll max(ll a,ll b){if(a<b)return b;else return a;}
ll min(ll a,ll b){if(a>b)return b;else return a;}
void Max(ll &pos,ll val){pos=max(pos,val);}//Max(dp[n],dp[n-1]);
void Min(ll &pos,ll val){pos=min(pos,val);}
void Add(ll &pos,ll val){pos=mod(pos+val);}
dd EPS=1E-9;
#define fastio ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
////////////////////////////

int main(){fastio
    ll n;cin>>n;
    for(ll i=0;i<=50000;i++){
        ll x=i*108/100;
        if(x==n){
            cout<<i<<endl;return 0;
        }
    }
    cout<<":(";
    return 0;
}


Measured memory_bytes: 256
let split_string ?(pattern="") = Str.split @@ Str.regexp pattern
let n, m = Scanf.sscanf (read_line ()) "%d %d" @@ fun n m -> (n, m)
let a = read_line () |> split_string ~pattern:" " |> List.map int_of_string

let sum = List.fold_left (+) 0 a
let b = float sum /. float (4 * m) |> ceil |> int_of_float

let () =
  print_endline @@ if List.filter (fun i -> i >= b) a |> List.length >= m then "Yes" else "No"

Measured memory_bytes: 3784
#include <bits/stdc++.h>
using namespace std;
#define AB_BHI_NI_DEGI                \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL);                    \
    cout.tie(NULL);
#define int long long
#define pb push_back
#define N 100009
#define inf 1e18
const double PI = 3.141592653589793238462643383279;
int mod = 1e9 + 7;
//int mod = 998244353;
#define P pair<int, int>
#define F first
#define S second
#define all(v) v.begin(), v.end()
#define vi vector<int>
#define ld long double

void solve()
{
    int k;
    cin >> k;
    if (k % 2 == 0)
    {
        cout << "-1\n";
        return;
    }
    int num = 0, cnt = 0;
    while (num < k)
    {
        num = (num * 10) + 7;
        cnt++;
    }
    while (num % k)
    {
        num = num % k;
        num = (num * 10) + 7;
        cnt++;
        if (cnt > k)
            break;
    }
    if (cnt > k)
    {
        cout << "-1\n";
        return;
    }
    else
        cout << cnt << "\n";
}
int32_t main()
{
    AB_BHI_NI_DEGI
    int Test = 1;
    //cin >> Test;
    while (Test--)
        solve();
    return 0;
}

Measured memory_bytes: 3644
import bisect
def main():
    m,n  = list(map(int,input().split()))
    if n==0:
        exit()
    W = [int(input()) for _ in range(n)]

    w_total = 0
    w_sum =[0]
    for w in W:
        w_total+=w
        w_sum.append(w_total)

    def judge(shelf_length):
        last_val = 0
        for i in range(m):
            _index= bisect.bisect_right(w_sum,last_val+shelf_length)
            #print(_index)
            if _index == n+1:
                return True
            assert _index > 0
            last_val =w_sum[_index-1]
        return False


    def nibun(func ,min_ ,max_ ):
        left = min_
        right= max_
        while not(left==right):
            mid = (left+right) //2
            tmp = func(mid)
            if tmp:
                right = mid
            else:
                left = mid+1
        return left

    print(nibun(judge,0,1500009))

while True:
    main()

Measured memory_bytes: 7764
#include <iostream>

using namespace std;

int main()
{
	double x1, y1, x2, y2, x3, y3;
	double xp, yp;
	
	while ( cin >> x1 >> y1 >> x2 >> y2 >> x3 >> y3 >> xp >> yp ) {
		x1 -= x3; x2 -= x3; xp -= x3;
		y1 -= y3; y2 -= y3; yp -= y3;
		double D = x1*y2 - x2*y1;
		double s = ( y2*xp - x2*yp) / D; s+=0;
		double t = (-y1*xp + x1*yp) / D; t+=0;
		
		if ((0.0 <= s) && (0.0 <= t) && (s+t <= 1.0)) cout << "YES" << endl;
		else cout << "NO" << endl;
	}
	
	return 0;
}

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

using lint = long long int;
using pint = pair<int, int>;
using plint = pair<lint, lint>;
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((lint)(x).size())
#define POW2(n) (1LL << (n))
#define FOR(i, begin, end) for (int i = (begin), i##_end_ = (end); i < i##_end_; i++)
#define IFOR(i, begin, end) for (int i = (end)-1, i##_begin_ = (begin); i >= i##_begin_; i--)
#define REP(i, n) FOR(i, 0, n)
#define IREP(i, n) IFOR(i, 0, n)
#ifdef LOCAL
#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
#define eprintf(...) 42
#endif

int main()
{
    lint n;
    cin >> n;
    lint ans=0, tmp=0;

    vector<lint> b(n-1),a(n);
    REP(i, n-1) { cin >> b[i]; }
    int A;
    REP(i, n-2) {
        A = min(b[i], b[i + 1]);
        ans += A;
    }
    ans += b[0] + b[n - 2];

    cout << ans <<"\n";

    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<math.h>

using namespace std;

int main () {
  int W, H, x, y, r;
  cin >> W >> H >> x >> y >> r;

  if (x>=r && x<=W-r && y>=r && y<=H-r) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}

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

#define TASKNAME ""

using namespace std;

const int INF = 1e9 + 7;
const int MAXN = 1e6 + 7;
const double EPS = 1e-8;

int main() {
    #ifdef MY
        freopen("input.txt", "r", stdin);
        //freopen("output.txt", "w", stdout);
    #else
        //freopen(TASKNAME".in", "r", stdin);
        //freopen(TASKNAME".out", "w", stdout);
        ios_base::sync_with_stdio(false);
        cin.tie(0);
        cout.tie(0);
    #endif // MY
    ll n, k;
    cin >> n >> k;
    ll res = 0;
    for (ll b = 1; b <= n; b++) {
        if (b <= k) continue;
        ll val = (n + 1) / b;
        //cout << b << " " << val << "\n";
        res += val * (b - k);
        ll x = val * b + k;
        if (x <= n) {
            res += n - x + 1;
        }
        if (!k) {
            res--;
        }
    }
    cout << res;
}


Measured memory_bytes: 256
import java.util.*;

class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int a = sc.nextInt();
        int x[] = new int[n+1];
        x[0] = -1;
        for (int i=0;i<n;i++){
            x[i+1] = sc.nextInt();
        }
        //DP table
        long dp[][][] = new long[n+1][n+1][n*50+1];
        dp[0][0][0] = 1;
        for (int i=1;i<n+1;i++){
            for(int m=0;m<n+1;m++){
                for(int s=0;s<n*50+1;s++){
                    int diff = s - x[i];
                    if(diff >= 0 & m>=1){
                        dp[i][m][s] = dp[i-1][m][s] + dp[i-1][m-1][diff];
                    } else {
                        dp[i][m][s] = dp[i-1][m][s];
                    }
                }
            }
        }
        //Answer
        int num = 1;
        int summation = a;
        long answer = 0;
        while (num <= n & summation <= n*50){
            answer += dp[n][num][summation];
            num++;
            summation+=a;
        }
        System.out.println(answer);
    }
}

Measured memory_bytes: 85376
# -*- coding: utf-8 -*-
S = str(int(raw_input()))

def calc_ans(S):
  if len(S) == 1:
    return int(S), 1
  
  s_len = len(S)
  sum = count = 0
  for i in range(0, s_len):
    if i > 0:
      S_new = S[i:]
      t_sum, t_count = calc_ans(S_new)
      t_sum = (int(S[:i])* t_count) + t_sum
    else:
      t_sum = int(S)
      t_count = 1
    sum += t_sum
    count += t_count
  return sum, count

sum, count = calc_ans(S)

print(sum)

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


using namespace std;

using ui = unsigned long long;

ui get_digit(ui N)
{
  float n = (float)N;
  ui counter = 0;
  while (n >= 1.0)
  {
    n /= 10.0;
    ++counter;
  }
  return counter;
}

int main()
{
  ui N;
  cin >> N;

  ui min_digit = 10;
  for (auto i{1}; i <= sqrt(N); ++i)
  {
    if (N % i == 0)
    {
      const ui A = i, B = (ui)(N / i);
      // cout << A << ' ' << B << endl;
      const auto digit = get_digit(max(A, B));
      min_digit = min(min_digit, digit);
    }
  }
  cout << min_digit << endl;

  return 0;
}


Measured memory_bytes: 256
# -*- coding: utf-8 -*-
"""
Schedule
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0595

"""
import sys

from collections import Counter
from itertools import product

def solve(n, data):
    status = Counter({(1, 0, 0): 1})
    for ch in data:
        u = Counter()
        for j, o, i in product((0, 1), repeat=3):
            if {'J': j, 'O': o, 'I': i}[ch]:
                for k, v in status.items():
                    pj, po, pi = k
                    if any([(j and pj), (o and po), (i and pi)]):
                        u[(j, o, i)] += v
        status = Counter({k: v % 10007 for k, v in u.items()})
    return sum(status.values()) % 10007


def main(args):
    n = int(input())
    data = input()
    ans = solve(n, data)
    print(ans)


if __name__ == '__main__':
    main(sys.argv[1:])



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

int main()
{

	int n;
	cin>>n;
	int arr[n][3];
	for(int i=0 ; i<n ; i++)
		for(int j=0 ; j<3 ; j++)
			cin>>arr[i][j];

	int sum = 0;
	int dp[n][3];

	dp[0][0]= arr[0][0];
	dp[0][1]= arr[0][1];
	dp[0][2]= arr[0][2];

	for(int i=1 ; i<n ; i++)
	{
		for(int j=0 ; j<3 ; j++)
		{
			dp[i][j] = max(dp[i-1][(j+1)%3] , dp[i-1][(j+2)%3]) + arr[i][j];
		}
	}
	cout<<max(max(dp[n-1][0] , dp[n-1][1]) , dp[n-1][2]);
	return 0;
}

Measured memory_bytes: 2560
#include <iostream>
#include <cstdio>
#include <string>
#include <sstream>
#include <algorithm>
#include <math.h>
#include <map>
#include <iomanip>
#include <vector>

using namespace std;


double a, b;


int main()
{
	while (cin >> a >> b)
	{
		if (a<35.5 && b<71.0)
		{
			cout << "AAA" << endl;
		} else if (a<37.5 && b<77.0) {
			cout << "AA" << endl;
		} else if (a<40.0 && b<83.0) {
			cout << "A" << endl;
		} else if (a<43.0 && b<89.0) {
			cout << "B" << endl;
		} else if (a<50.0 && b<105.0) {
			cout << "C" << endl;
		} else if (a<55.0 && b<116.0) {
			cout << "D" << endl;
		} else if (a<70.0 && b<148.0) {
			cout << "E" << endl;
		} else {
			cout << "NA" << endl;
		}
	}
	
	return 0;
}

Measured memory_bytes: 1220
X, N = list(map(int, input().split()))
if N != 0:
  p = list(map(int, input().split()))
else:
  p = []

ans = 1000000
ansabs = 1000000
for i in range(0, 102):
  if i in p: continue
  if abs(X - i) < ansabs:
    ansabs = abs(X - i)
    ans = i

print(ans)

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

#define ll long long



void solve(){
    int a,b;
    char c;
    cin>>a>>c>>b;
    if(c=='+'){
        cout<<a+b<<endl;
    }  else{
        cout<<a-b<<endl;
    }
}

signed main(){
    //while(1)
    solve();
}

Measured memory_bytes: 256
n = int(input())
a = list(map(int, input().split()))

a.sort()
if a[0] == 1:
    if len(a) == 1 or a[1] != 1:
        print(1)
    else:
        print(0)
else:
    a_max = a[-1]
    seive = [True for _ in range(a_max + 1)]
    a += [-1]
    ret = 0
    add = 1
    for i in range(n):
        if a[i] != a[i+1]:
            if seive[a[i]]:
                ret += add
                j = 2 * a[i]
                while j <= a_max:
                    seive[j] = False
                    j += a[i]
            add = 1
        else:
            add = 0
    print(ret)


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

using namespace std;

int main(){
  int n,a,b,c,d; cin >> n >> a >> b >> c >> d;
  a--,b--,c--,d--;
  string s; cin >> s;
  int mincd=(c>d)?d:c;
  int maxcd=(c>d)?c:d;
  bool empflag=false,sflag=true;
  if(c<d) empflag=true;
  for(int i=a;i<=maxcd;++i){
    if(i==n-1) break;
    if(b<=i && i<=mincd){
      if(s[i-1]=='.' && s[i]=='.' && s[i+1]=='.') empflag=true;
    }
    if(s[i]=='#' && s[i+1]=='#') sflag=false;
  }
  if(empflag && sflag) cout << "Yes";
  else cout << "No";
  cout << endl;
  
  return 0;
}


Measured memory_bytes: 640
// author-Shivam gupta

#include <bits/stdc++.h>


using namespace std;

#define MEM(a, b) memset(a, (b), sizeof(a))

#define FOREACH(it, l) for (auto it = l.begin(); it != l.end(); it++)

#define IN(A, B, C) assert( B <= A && A <= C)

#define MP make_pair
#define FOR(i,a) for(int i=0;i<a;i++)

#define FOR1(i,j,a) for(int i=j;i<a;i++)

#define EB emplace_back

#define INF (int)1e9

#define EPS 1e-9

#define PI 3.1415926535897932384626433832795

#define MOD 1000000007

#define read(type) readInt<type>()
#define max1 100001
#define out(x) cout<<x<<'\n'
#define out1(x) cout<<x<<" "
#define END cout<<'\n'
#define int long long
void fast(){
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
}
signed main(){

	 int n;
	 cin>>n;
	 int a[n];
	 FOR(i,n){
	 cin>>a[i];
	 }
	 if(n==1){out(0);return 0;}
	 int ans=0;
	 sort(a,a+n);
	 int x=n-2;
	 ans=a[n-1];
	 if(n==2){out(ans);return 0;}
	 int j=n-2;
	 for(int i=n-2;i>=0;i-=2){
        ans+=a[j];
        x--;
        if(x==0){break;}
        ans+=a[j];
        x--;
        if(x==0){break;}
        j--;

	 }
	 out(ans);

}


Measured memory_bytes: 5200
#include <stdio.h>

int n, x;

int
chk()
{
	if ((n == 0) && (x == 0))
		return 0;
	return 1;
}

int
main(int argc, char *argv[])
{
	int a, b, c;
	int sum;

	while (scanf("%d %d", &n, &x), chk(n, x)) {
		sum = 0;
		for (a = 1; a < n - 1; a++) 
			for (b = a + 1; b < n; b++) 
				for (c = b + 1; c < n + 1; c++) 
					if (a + b + c == x) sum++;
		printf("%d\n", sum);
	}

	return 0;
}

Measured memory_bytes: 600
# -*- coding: utf-8 -*-
def inpl(): return list(map(int, input().split()))
from heapq import heapify, heapreplace 

N = int(input())
A = inpl()
L = A[:N]
M = A[N:2*N]
R = [-a for a in A[2*N:]]
ans = sum(L) + sum(R)
heapify(L)
heapify(R)


i = 0
j = N+1

S = [0]*(N+1)

s = 0
for i, m in enumerate(M):
    if m > L[0]:
        s += m - heapreplace(L, m)
    S[i+1] += s

s = 0
for i, m in enumerate(M[::-1]):
    if m < -R[0]:
        s += -m - heapreplace(R, -m)
    S[-i-2] += s

ans += max(S)
print(ans)

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

int main()
{
	int N;
	scanf("%d", &N);
	std::vector<int> P(N), Q(N);
	for (auto& e: P) scanf("%d", &e);
	for (auto& e: Q) scanf("%d", &e);
	int a{}, b{};
	std::vector<int> vec(N);
	std::iota(vec.begin(), vec.end(), 1);
	do {
		a++;
		if (vec == P) break;
	} while (std::next_permutation(vec.begin(), vec.end()));
	std::iota(vec.begin(), vec.end(), 1);
	do {
		b++;
		if (vec == Q) break;
	} while (std::next_permutation(vec.begin(), vec.end()));
	printf("%d\n", std::abs(a - b));

	return 0;
}

Measured memory_bytes: 256
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
template<typename T> bool chmax(T &a,T b){if(a<b){a=b;return true;}return false;}
template<typename T> bool chmin(T &a,T b){if(a>b){a=b;return true;}return false;}
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(vec) vec.begin(),vec.end()
typedef long long ll;
typedef pair<ll,ll> pll;
typedef pair<int,int> pii;
typedef tuple<ll,ll,ll> tlll;
typedef tuple<int,int,int> tiii;
const ll mod=1e9+7;
const int inf=1<<30;

int main(){
  int n; cin >> n;
  vector<ll> a(n);
  int hu=0;
  ll sum=0;
  rep(i,n){
    cin >> a[i];
    if(a[i]<0){
      hu++;
      a[i]=-a[i];
    }
    sum+=a[i];
  }
  sort(all(a));
  if(hu%2==0){
    cout << sum << endl;
  }
  else{
    cout << sum-2*a[0] << endl;
  }
  
}

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

using lli = long long int;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()

int main() {
  string a,b;
  cin >> a>>b;
  if (a.size()>b.size())
    cout << "GREATER" << endl;
  else if (a.size()<b.size())
    cout << "LESS" << endl;
  else if (a>b)
    cout << "GREATER" << endl;
  else if (a<b)
    cout << "LESS" << endl;
  else
    cout << "EQUAL" << endl;
  return 0;
}


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

int main(){
  ll a, b, c, d;
  cin >> a >> b >> c >> d;
  ll ans = 0;
  ans = max(a*c, b*d);
  if(b < 0 && c > 0) ans = b*c;
  if(a > 0 && d < 0) ans = a*d;
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3640
import java.util.*;

public class Main {
    public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int H = sc.nextInt();
		int W = sc.nextInt();
		char[][] s = new char[H][W];
		
		for (int i = 0; i < H; i++) {
			String tmp = sc.next();
			for (int j = 0; j < W; j++) {
				s[i][j] = tmp.charAt(j);
			}
		}
		
		int[] dx = {1, 1, 0, -1, -1, -1, 0, 1};
		int[] dy = {0, 1, 1, 1, 0, -1, -1, -1};
		
		for (int i = 0; i < H; i++) {
			for (int j = 0; j < W; j++) {
				if (s[i][j] == '#') {
					System.out.print(s[i][j]);
				} else {
					int sum = 0;
					for (int k = 0; k < 8; k++) {
						int tmpX = j + dx[k];
						int tmpY = i + dy[k];
						if (0 > tmpX || tmpX > W - 1) continue;
						if (0 > tmpY || tmpY > H - 1) continue;
						
						if (s[tmpY][tmpX] == '#') {
							sum++;
						}
					}
					System.out.print(sum);
				}
			}
			System.out.println();
		}
	}
}


Measured memory_bytes: 24404
#include<stdio.h>
#include<string.h>

int main(){
  int N,flag=0;
  scanf("%d",&N);
  char word[N][11];
  for(int i=0;i<N;i++) scanf("%s",&word[i]);

  for(int i=0;i<N-1;i++){
    for(int j=i+1;j<N;j++){
      if(strcmp(word[i],word[j])==0){
        flag=1;
        break;
      }
    }
      if(word[i][strlen(word[i])-1]!=word[i+1][0]){
        flag=1;
        break;
      }
  }
  if(flag==1)printf("No");
  else printf("Yes");
}


Measured memory_bytes: 128
/****************### With The name of ALLAH, most Gracious, most Compassionate ###****************/

/**============================================================================**\
|   Author      : Md Jubayer Hossen Jame
|   Study       : CSE, BRUR
|   Today       : Monday, 14 September, 2020
|   Source      : AtCoder Online Judge
|   Problem link: https://atcoder.jp/contests/abc178/tasks/abc178_c
|   Algorithm   :
|   Help        : Code Explainer youtube channel

   After bout 2 years --> see you again
\**============================================================================**/

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

#define FI                    freopen("input.txt", "r", stdin)
#define FO                    freopen("output.txt", "w", stdout)
#define FasterIO              ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);

typedef long long             ll;
typedef unsigned long long    ull;
typedef unsigned int          ui;

#define mem(x,y)              memset(x,y,sizeof(x));
#define pii                   pair<int,int>
#define mk                    make_pair
#define ff                    first
#define ss                    second
#define pb                    push_back
#define ppb                   pop_back
#define all(x)                (x).begin(), (x).end()
#define rall(x)               (x).rbegin(), (x).rend()
#define for0(i, n)            for (int i = 0; i < (int)(n); ++i)
#define endl                  '\n'

const double PI = acos(-1.0);

#define gcd(a,b)              __gcd(a,b)
#define lcm(a,b)              (a*(b/gcd(a,b)))

///Direction Array
// 4 Direction - DOWN, UP, RIGHT, LEFT
int dx4[]= {+1, -1, +0, +0};
int dy4[]= {+0, +0, +1, -1};
#define isValid(a, b, R, C)   (0 <= a && a < R) && (0 <= b && b < C)
int dx8[]= {+0, +0, +1, -1, -1, +1, -1, +1};
int dy8[]= {-1, +1, +0, +0, +1, +1, -1, -1};

///Knight Moves
int dr[] = {-1, 1, -2, -2, -1, 1, 2, 2};
int dc[] = {-2, -2, -1, 1, 2, 2, 1, -1};
/**************************************************************************************************/

const ll MOD = (ll)1e9 + 7;

//this is very important this is for negative and positive number mod
ll mod(ll x)
{
    return (x % MOD + MOD) % MOD;
}

ll ten, nine, eight;
void Ten_Nine_Eight(int pow)
{
    ten = nine = eight = 1;
    for0(i, pow)
    {
        ten *= 10LL;  ten %= MOD;
        nine *= 9LL;   nine %= MOD;
        eight *= 8LL;   eight %= MOD;
    }
}

void test_case()
{
    int n;
    cin >> n;

    Ten_Nine_Eight(n);

    ll ans = ten;
    ans += eight;
    ans %= MOD;

    ans -= ( ( 2LL*nine ) % MOD );
    //cout << ans << endl;
    //ans %= MOD; //this is not correct bcz ans can be negative
    ans = mod(ans);

    cout << ans << endl;
}

int main()
{
#ifndef ONLINE_JUDGE
    //FI;
    //FO;
#endif // ONLINE_JUDGE
    //FasterIO

    int T = 1;
    //cin >> T;
    for(int tc = 1; tc <= T; ++tc)
    {
        //cout << "Case #" << tc << ":" << endl;
        test_case();
    }
    return 0;
}


Measured memory_bytes: 3608
use std::str::FromStr;
use std::fmt::Debug;
use std::cmp;
fn read_as_vec<T>() -> Vec<T>
where T: FromStr, <T as FromStr>::Err : Debug{
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim().split_whitespace().map(|c| T::from_str(c).unwrap()).collect()

}

fn f(n: u64) -> u64{
    if n%2 == 0{
        (n/2)%2 ^ n
    }else{
        ((n+1)/2)%2
    }
}

fn main(){
    let line: Vec<u64> = read_as_vec();
    let (a, b)= (line[0], line[1]);
    
    if a == 0{
        println!("{}", f(b));
    }else{
        println!("{}", f(a-1) ^ f(b));
    }
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
 
#define REP(i,n) for (int i=0,_n=(int)(n); i < _n; i++)
template<class T> bool chmax(T &a, T b) { return a < b ? (a = b, true) : false; }
template<class T> bool chmin(T &a, T b) { return a > b ? (a = b, true) : false; }
 
typedef long long ll;

const int MAX_N = 100000 + 10;
ll a[MAX_N];
ll b[MAX_N];
ll front[MAX_N];
ll back[MAX_N];

int main() {
  int N, K; cin >> N >> K;
  REP(i, N) cin >> a[i];

  b[0] = 0;
  REP(i, N) b[i+1] = b[i] + a[i];

  front[0] = 0;
  for (int i = 1; i <= N; i++) {
    front[i] = front[i-1] + max(a[i-1], 0LL);
  }
  back[N] = 0;
  for (int i = N - 1; i >= 0; i--) {
    back[i] = back[i+1] + max(a[i], 0LL);
  }
  // REP(i, N) cout << a[i] << " "; cout << endl;
  // REP(i, N) cout << b[i] << " "; cout << endl;
  // REP(i, N) cout << front[i] << " "; cout << endl;
  // REP(i, N) cout << back[i] << " "; cout << endl;
  
  ll ans = 0;
  for (int i = 0; i + K <= N; i++) {
    ll cur = front[i] + back[i + K];
    ll sub = b[i + K] - b[i];
    if (sub > 0) cur += sub;
    // cout << i << " " << i + K << " " << sub << " -->" << cur << endl;
    chmax(ans, cur);
  }
  cout << ans << endl;


  return 0;
}

Measured memory_bytes: 3328
#include<stdio.h>
#include<string.h>
#include<utility>
#include<iostream>
#include<queue>
#include<math.h>
#include<algorithm>
#include<vector>
#include<map>
 
using namespace std;
typedef long long ll;
#define REP(i,n) for(int i=0;i<(int)(n);i++)
 
 
int main()
{
    int n;
    int x[105]={};
    int y[105]={};
    long long int h[105]={};
    scanf("%d\n",&n);
    REP(i,n)scanf("%d %d %lld\n",&x[i],&y[i],&h[i]);
    long long int hhh;
    int judge;
    REP(xxx,101)
    {
        REP(yyy,101)
        {
            judge=1;
            int ii=0;
            while(1==1)
            {
                if(h[ii]==0)ii++;
                else
                {
                    hhh=h[ii]+(xxx-x[ii])*(xxx-x[ii]>0?1:-1)+(yyy-y[ii])*(yyy-y[ii]>0?1:-1);
                    break;
                }
            }
            REP(i,n)
            {
                if(h[i]+(xxx-x[i])*(xxx-x[i]>0?1:-1)+(yyy-y[i])*(yyy-y[i]>0?1:-1)!=hhh && h[i]!=0)judge=0;
                if((xxx-x[i])*(xxx-x[i]>0?1:-1)+(yyy-y[i])*(yyy-y[i]>0?1:-1)<hhh && h[i]==0)judge=0;
            }
            if(judge==1)
            {
                printf("%d %d %lld\n",xxx,yyy,hhh);
                return 0;
            }
        }
    }
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <queue>
#include <set>
#include <map>
#include <functional>
#include <numeric>
#include <limits>
#include <cmath>
#include <iomanip>
#include <sstream>
 
#define ALL(a)  (a).begin(),(a).end()
 
using namespace std;
typedef long long int ll;
typedef pair <int,int> P;

 
int main() {
    ll ans = 0;
    ll n;
    string s;

    cin >> s;

    n = s.length();
    bool ch = 0;
    ll r = 0, l = 0, id;
    vector<ll> m(n);

    s += 'R';

    for (int i = 0; i < n+1; i++) {
        if (!ch && s[i] == 'R') {
            r++;
        } else if (!ch && s[i] == 'L') {
            ch = true;
            id = i;
            l++;
        } else if (ch && s[i] == 'L') {
            l++;
        } else if (ch && s[i] == 'R') {
            ch = false;
            m[id - 1] = (r+1) / 2 + l / 2;
            m[id] = r / 2 + (l+1) / 2;
            l = 0;
            r = 1;
        }
    }

    for (int i = 0; i < n; i++) {
        cout << m[i] << " ";
    }
    cout << endl;
}

Measured memory_bytes: 1408
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
using namespace std;
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define MOD 1000000007
#define INF (1<<30)
#define LINF (1LL<<60)
#define endl "\n"
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define reprev(i,n) for(int (i)=(n-1);(i)>=0;(i)--)
#define Flag(x) (1<<(x))
#define Flagcount(x) __builtin_popcount(x)
#define pint pair<int,int>
#define pdouble pair<double,double>
#define plint pair<lint,lint>
typedef unsigned long long int ull;
typedef long long lint;

int main(void){
    string S;
    int check=0;
    cin >> S;
    int L=S.length();
    int alf[26]={};
    rep(i,L) alf[S[i]-'a']++;
    rep(i,26) if(alf[i]>1) check=1;
    if(check==0) cout << "yes" << endl;
    else cout <<  "no" << endl;
}

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

int main()
{
  int n;
  int m;
  bool f[105];
  int kanade = 0;

  memset(f, true, sizeof(f));

  cin >> n;
  cin >> m;
  for (int i = 0; i < m; i++) {
    int tmp; cin >> tmp;
    f[tmp] = false;
  }

  cin >> m;
  for (int i = 0; i < m; i++) {
    int tmp; cin >> tmp;
    f[tmp] = true;
  }
  
  cin >> m;
  for (int i = 0; i < m; i++) {
    int tmp; cin >> tmp;
    if (f[tmp]) kanade++;
  }

  cout << kanade << endl;
}

Measured memory_bytes: 3100