akhauriyash/Code-Regression huggingface dataset:
use proconio::marker::Usize1;

fn run() {
    proconio::input! {
        n: usize,
        m: usize,
        p: [(Usize1, Usize1); m],
    }
    let mut next = vec![vec![]; n];
    for (i, &(x, y)) in p.iter().enumerate() {
        next[x].push(i + 1);
        next[y].push(i + 1);
    }
    let mut ans = 0;
    for i in 1..n {
        for j in 0..i {
            let mut ok = 1;
            let mut used = vec![false; n];
            used[i] = true;
            used[j] = true;
            let mut stack = vec![(i, m), (j, m)];
            while let Some((v, k)) = stack.pop() {
                let k = match next[v].binary_search(&k) {
                    Ok(k) => next[v][k],
                    Err(k) => {
                        if k == 0 {
                            continue;
                        }
                        next[v][k - 1]
                    },
                };
                let (x, y) = p[k - 1];
                let z = x ^ y ^ v;
                if used[z] {
                    ok = 0;
                    break;
                }
                used[z] = true;
                stack.push((v, k - 1));
                stack.push((z, k - 1));
            }
            ans += ok;
        }
    }
    println!("{}", ans);
}

fn main() {
    run();
}


Measured memory_bytes: 6896
#include <bits/stdc++.h>
using namespace std;
const int n=6,MAX=1<<29;
int c[n]={1,5,10,50,100,500};
 
int calc(vector<int> a, int x) {
  int sum=0;
  for(int i=5; i>=0; i--) {
    int d=min(a[i],x/c[i]);
    x-=d*c[i];
    sum+=d;
  }
  if(x) return MAX;
  return sum;
}
 
int main() {
  vector<int> b(n);
  for(int i=0; i<n; i++) b[i]=MAX;
  int x;
  while(cin >> x && x) {
    vector<int> a(n);
    for(int i=0; i<n; i++) cin >> a[i];
    int ans=MAX;
    for(int i=0; i<=500; i++) ans=min(ans,calc(a,x+i)+calc(b,i));
    cout << ans << endl;
  }
  return 0;
}


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

typedef long long lint;

int main()
{
	lint N,K,x[100010];
	lint tmp;
	lint ans=4000000000;
	
	for(lint i=0;i<100010;i++)x[i]=0;
	
	cin >> N >> K;
	for(lint i=1;i<=N;i++)cin >> x[i];

	for(lint i=1;i<=N-K+1;i++)
	{
		tmp=min( abs(x[i])+abs(x[i]-x[i+K-1]), abs(x[i+K-1])+abs(x[i+K-1]-x[i]) );
		if(tmp<ans)ans=tmp;
	}
	
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1024
N = int(input())
arr = [int(n) for n in input().split()]

swap_cnt = 0
swap_flg = True
i = 0
while swap_flg:
    swap_flg = False
    for j in range(N - 1, i, -1):
        if (arr[j] < arr[j - 1]):
            arr[j], arr[j - 1] = arr[j - 1], arr[j]
            swap_cnt += 1
            swap_flg = True
    i += 1

print(' '.join(map(str, arr)))
print(swap_cnt)


Measured memory_bytes: 5604
#include<iostream>


using namespace std;

int main(){
	int n,i;
	int a[3];
	cin >> n;
	a[0]=n%10;
	a[1]=n%100/10;
	a[2]=n/100;

	for(i=0; i<3; ++i){
		if(a[i]%9==0){
		    a[i]-=8;
		}else if((a[i]+4)%5==0){
		    a[i]+=8;
		}
	}
	cout << a[0]+a[1]*10+a[2]*100  << endl;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
const int N=200000+10;
typedef long long LL;
int n,d; LL x; 
int main(){
    scanf("%d",&n);
    LL s=0,s1 = 0;
    for(int i=1;i<=n;i++){
        scanf("%d%lld",&d,&x);
        s += d * x; s1 += x;
    }
    LL ans = (s - 1) / 9 + s1 - 1;
    cout << ans << endl;
}

Measured memory_bytes: 384
#include <cstdio>
#include <cstring>
#include <utility>
#define ll long long
#define P pair<ll, ll>
using namespace std;

int H, W;
char S[401][400];

bool used[400][400];
int dx[4] = { 1,0,-1,0 }, dy[4] = { 0,1,0,-1 };

P dfs(int h, int w) {
	P res;
	if (S[h][w] == '#') res.first++;
	else res.second++;
	used[h][w] = true;
	for (int i = 0; i < 4; i++) {
		int nx = h + dx[i], ny = w + dy[i];
		if (nx >= 0 && nx < H && ny >= 0 && ny < W && !used[nx][ny] && S[h][w] != S[nx][ny]) {
			P p = dfs(nx, ny);
			res.first += p.first;
			res.second += p.second;
		}
	}
	return res;
}

void solve() {
	memset(used, false, sizeof(used));
	ll ans = 0;
	for (int i = 0; i < H; i++) {
		for (int j = 0; j < W; j++) {
			if (!used[i][j]) {
				P res = dfs(i, j);
				ans += res.first * res.second;
			}
		}
	}
	printf("%lld\n", ans);
}

int main() {
	scanf("%d %d", &H, &W);
	for (int i = 0; i < H; i++)
		scanf("%s", S[i]);
	solve();
}

Measured memory_bytes: 12928
#include <bits/stdc++.h>
#define N 51
using namespace std;
string mp[N];
string sw[11][N];
int w,h,s;
int dx[]={0,0,1,-1};
int dy[]={1,-1,0,0};
 
bool check(int x,int y,int f,int bit){
  if(mp[y][x]=='#')return 0;
 
  int cnt=0;
  for(int i=0;i<s;i++)
    if((bit>>i)&1)cnt+=sw[i][y][x]=='*';
 
  char ch = mp[y][x];
  if((cnt+f)%2==0)
    if(isupper(ch)||ch=='^')return 0;
  
  if((cnt+f)%2==1)
    if(islower(ch)||ch=='_'||ch=='&'||ch=='%')return 0;
  return 1;
}

int nbit(int bit,int x){
  if((bit>>x)&1) return ~((~bit)|(1<<x));
  return bit|(1<<x);
}
 
int used[N][N][2][1<<10],mem[N][N][2][1<<10];
struct dat{int x,y,f,bit,cost;};
int bfs(int sx,int sy){
  queue<dat> Q;
  Q.push((dat){sx,sy,0,0,0});
  
  while(!Q.empty()){
    dat t=Q.front();Q.pop();
    int x=t.x,y=t.y,f=t.f,bit=t.bit,cost=t.cost;
    if(mp[y][x]=='&')return cost;
    if(used[x][y][f][bit]++) continue;
    mem[x][y][f][bit]=cost;

    if(mp[y][x]=='|') Q.push((dat){x,y,!f,bit,cost+1});
    int th=mp[y][x]-(isupper(mp[y][x])? 'A':'a');
    if(isalpha(mp[y][x]))Q.push((dat){x,y,(sw[th][y][x]=='*')?!f:f,nbit(bit,th),cost+1});
    
    for(int i=0;i<4;i++){
      int nx=x+dx[i],ny=y+dy[i];
      if(check(nx,ny,f,bit))Q.push((dat){nx,ny,f,bit,cost+1});
    }
  }
  return -1;
}
  
int main(){
  cin>>w>>h;
  for(int i=0;i<h;i++)cin>>mp[i];
  cin>>s;
  for(int i=0;i<s;i++)
    for(int j=0;j<h;j++) cin>>sw[i][j];
 
  int ans=0;
  for(int i=0;i<h;i++)
    for(int j=0;j<w;j++)
      if(mp[i][j]=='%')cout<<bfs(j,i)<<endl;
    return 0;
}

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

cnt = [0]*(10**5+1)
ans = sum(a)

for aa in a:
  cnt[aa] += 1

for i in range(q):
  b, c = map(int, input().split())
  ans -= b*cnt[b]
  ans += c*cnt[b]
  cnt[c] += cnt[b]
  cnt[b] = 0
  print(ans)

Measured memory_bytes: 20816
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <inttypes.h>
#include <ctype.h>
#include <stdint.h>
#include <string.h>
#include <wchar.h>
#include <math.h>

#define N_MAX (100)
#define P_MAX (100)
#define DP_ARRAY_SIZE (N_MAX * P_MAX / 32 + 1)

#define MIN(a, b) ((a) < (b) ? (a) : (b))
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define ABS(a) ((a) < 0 ? -(a) : (a))
#define ABSS(a, b) ((a) > (b) ? (a) - (b) : (b) - (a))

int compare_sz_asc(const void* a, const void* b) {
    return *((size_t*)a) < *((size_t*)b) ? -1 : 1;
}

int compare_sz_desc(const void* a, const void* b) {
    return *((size_t*)a) > * ((size_t*)b) ? -1 : 1;
}

int compare_i64_asc(const void* a, const void* b) {
    return *((int64_t*)a) < *((int64_t*)b) ? -1 : 1;
}

int compare_i64_desc(const void* a, const void* b) {
    return *((int64_t*)a) > * ((int64_t*)b) ? -1 : 1;
}

int compare_c_asc(const void* a, const void* b) {
    return *((char*)a) < *((char*)b) ? -1 : 1;
}

int compare_c_desc(const void* a, const void* b) {
    return *((char*)a) > * ((char*)b) ? -1 : 1;
}

static size_t powSz(const size_t base, const size_t exp) {
    if (exp == 0) {
        return 1;
    }

    if (exp == 1) {
        return base;
    }

    if (exp % 2 == 0) {
        return powSz(base * base, exp / 2);
    }
    else {
        return base * powSz(base, exp - 1);
    }
}

static size_t comb(const size_t n, const size_t r) {
    size_t result = 1;

    for (size_t i = 0; i < r; i++) {
        result *= n - i;
        result /= i + 1;
    }

    return result;
}

static uint64_t combU64(const uint64_t n, const uint64_t r) {
    uint64_t result = 1;

    for (uint64_t i = 0; i < r; i++) {
        result *= n - i;
        result /= i + 1;
    }

    return result;
}

static size_t gcdZu(size_t m, size_t n) {
    size_t temp;

    while (m % n != 0) {
        temp = n;
        n = m % n;
        m = temp;
    }

    return n;
}

static uint64_t gcdU64(uint64_t m, uint64_t n)
{
    uint64_t temp;

    while (m % n != 0) {
        temp = n;
        n = m % n;
        m = temp;
    }

    return n;
}

int main(void) {
    size_t N;

    size_t exCnt = 1;

    scanf("%zu\n", &N);
    for (size_t i = 0; i < N; i++) {
        size_t A;
        scanf("%zu", &A);
        if (i < N - 1) {
            scanf(" ");
        }

        exCnt *= (A % 2 == 0 ? 2 : 1);
    }

    printf("%zu", powSz(3, N) - exCnt);

    return 0;
}


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

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

int main() {
  int n,ans;
  cin >> n;
  for (int i = 1; i*i <= n; ++i) {
    ans = i * i;
  }

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


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int N=1e4+5;
int a[N],b[N],n;
bool ipm(int x) {
	if(x==1) return false;
	for(int i=2;1LL*i*i<=x;i++) {
		if(x%i==0) return false;
	}
	return true;
}
bool check(int p) {
	if(a[0]%p) return false;
	for(int i=0;i<=n;i++) b[i]=a[i];
	for(int i=n;i>=p-1;i--) {
		int t=i-p+1;
		b[t]=(b[t]+b[i])%p;
		b[i]=0;
	}
	for(int i=0;i<=n;i++)
		if(b[i]%p) return false;
	return true;
}
int main() {
	scanf("%d",&n);
	for(int i=0;i<=n;i++) scanf("%d",&a[i]);
	reverse(a,a+n+1);
	int t=a[0];
	for(int i=1;i<=n;i++) t=__gcd(t,a[i]);
	t=abs(t);
	set<int> S;
	for(int i=2;1LL*i*i<=t;i++) {
		if(t%i==0) {
			S.insert(i);
			while(t%i==0) t/=i;
		}
	}
	if(t!=1) S.insert(t);
	for(int i=2;i<=n;i++) {
		if(ipm(i)&&check(i)) S.insert(i);
	}
	for(auto it:S) {
		printf("%d\n",it);
	}
	return 0;
}

Measured memory_bytes: 384
// #define _GLIBCXX_DEBUG
#include <bits/stdc++.h>

#define FOR(i, a, b) for (int i = (a); i < int(b); ++i)
#define RFOR(i, a, b) for (int i = (b)-1; i >= int(a); --i)
#define REP(i, n) FOR(i, 0, n)
#define REP1(i, n) FOR(i, 1, int(n) + 1)
#define RREP(i, n) RFOR(i, 0, n)
#define RREP1(i, n) RFOR(i, 1, int(n) + 1)
#define ALL(c) begin(c), end(c)

int _ = (
#ifndef LOCAL
    std::cin.tie(nullptr), std::ios::sync_with_stdio(false),
#endif
    std::cout.precision(10), std::cout.setf(std::ios::fixed));

using ll = long long;
using ull = unsigned long long;
using ld = long double;
template <typename T> using vec = std::vector<T>;
using namespace std;

int main() {
  string S;
  cin >> S;

  const regex re("[ATCG]+");
  int answer = 0;
  for (sregex_iterator it(ALL(S), re), end; it != end; ++it) {
    auto &&m = *it;
    answer = max(answer, static_cast<int>(m.length()));
  }
  cout << answer << endl;

  return 0;
}


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

int main() {
    int N; cin >> N;
    int ans = 0;
    for (int i = 1; i < N; i++){
        int x = (N-1) / i;
        ans += x;
    }

    cout << ans << endl;

    return 0;
}

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

int main(){
    // int n, k;
    // cin >> n >> k;
    // int cnt = k;
    // vector<ll> a(n);
    // vector<ll> b(k);
    // b[0] = 1;
    // rep(i,n) cin >> a[i];
    // while(cnt > 0){
    //     b[0] *= a[cnt - 1];
    //     --cnt;
    // }
    // rep(i, n-k){
    //     int cnt = k;
    //     b[i+1] = b[i]/a[i] * a[cnt+i];
    //     if(b[i+1] > b[i]) cout << "Yes" << endl;
    //     else cout << "No" << endl;
    //     cnt--;
    // }
    int n, k;
    cin >> n >> k;
    vector<int> a(n);
    rep(i,n) cin >> a[i];
    for(int i=k; i < n; i++){
        if(a[i-k] < a[i]) cout << "Yes" << endl;
        else cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 4020
#include <stdio.h>
#include <stdlib.h>
typedef struct data{
  long int a;
  long int b;
}Data;
long int cmpb(const void *c,const void *d){
return ((Data *)c)->a-((Data *)d)->a;
}
int main(){
  int n,m,i,j;
  scanf("%d%d",&n,&m);
  long long int ans=0,rem=m;
  Data ene[n];
  for(i=0;i<n;i++)scanf("%ld%ld",&ene[i].a,&ene[i].b);
  qsort(ene,n,sizeof(Data),cmpb);
  for(i=0;i<n&&rem>0;i++){
    if(rem>ene[i].b){
      ans+=(ene[i].a)*(ene[i].b);
      rem-=ene[i].b;
    }
    else {
      ans+=(ene[i].a)*(rem);
      break;
    }
  }
  printf("%lld",ans);
}

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


int main() {
int N; cin >> N;
VI A(N); rep(i, 0, N) scanf("%d", &A[i]);

int inclen, declen; // 増加長さ，減少長さ.
int div = 0; //区切り数

rep(i, 0, N) { // A上 ループ
    if (A[i] == A[i+1]) continue;
    else if (A[i] < A[i+1]){
        while (A[i] <= A[i+1]){
            ++i;
        }
        ++div;
    }
    else {
        while (A[i] >= A[i+1]){
            ++i;
        }
        ++div;
    }
}
cout << div << "\n";

return 0;
}

// 境界，出力文字列 チェック
// int は ± 2*10⁹.


Measured memory_bytes: 640
use std::io;

fn read_line()-> String {
    let mut s = String::new();
    let _ = io::stdin().read_line(&mut s).unwrap();
    s
}

fn main() {
	let mut s = read_line().split_whitespace().map(|e|e.parse().unwrap())
	.collect::<Vec<i32>>();
	s.sort();
	println!("{}",s[0] + s[1]);
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
#define rep(i, a) for(int i = 0; i < a; i++)
#define all(v) v.begin(), v.end()
#define dcout cout << fixed << setprecision(15)
#define arep(i, a) for(auto i : a)
#define F first
#define S second
#define VE vector<int>
#define pb(x) push_back(x)
#define MOD 1000000007
#define INF 10000000000
#define int long long
#define KETA(n) floor(log10(n) + 1)
using namespace std;
signed main() {
    int n;
    cin >> n;
    cout << 1110 - n;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main (){
  int a, b, x;
  cin>>a>>b;
  if(a==0){
    a=1;
  }else if(a==1){
    a=100;
  }else{
    a=10000;
  }
  if(b==100){
    x=b*a+a;
  }else{
    x=a*b;
  }
  cout<<x<<endl;
  return 0;
}


Measured memory_bytes: 256
# -*- coding: utf-8 -*-
N = int(input())


for h in range(1, 3500+1):
    for w in range(1, 3500 + 1):
        n1 = 4*h*w - h*N - w*N
        if n1:
            l = (h*w*N) / n1
            if 0 < l <= 3500 and int(l) == l:
                print(int(h), int(l), int(w))
                exit()


Measured memory_bytes: 40796
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define PI 3.14159265358979323846
constexpr int INF = numeric_limits<int>::max() / 2;
constexpr long long INFL = numeric_limits<long long>::max() / 2;
constexpr int MOD = 1000000007;
using Graph = vector<vector<int>>;



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

    string S;
    cin >>S;
    int ans=0;
    rep(i,4){
        if(S[i]=='+') ans++;
        else ans--;
    }
    cout << ans << endl;



}


Measured memory_bytes: 256
/// Thank you tanakh!!!
/// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let mut s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

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

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

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

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

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

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

fn solve(s: &Vec<char>, first: bool, second: bool) -> Option<Vec<bool>> {
    let n = s.len();
    let mut is_wolf = vec![false; n];
    is_wolf[0] = first;
    is_wolf[1] = second;
    for i in 1..(n - 1) {
        let prev = i - 1;
        let next = i + 1;
        match (s[i], is_wolf[i]) {
            ('o', true) => {
                is_wolf[next] = !is_wolf[prev];
            }
            ('x', true) => {
                is_wolf[next] = is_wolf[prev];
            }
            ('o', false) => {
                is_wolf[next] = is_wolf[prev];
            }
            ('x', false) => {
                is_wolf[next] = !is_wolf[prev];
            }
            _ => unreachable!(),
        }
    }
    let honest = (s[n - 1] == 'o') == (is_wolf[n - 2] == is_wolf[0]);
    if (!honest) != is_wolf[n - 1] {
        return None;
    }

    let honest = (s[0] == 'o') == (is_wolf[n - 1] == is_wolf[1]);
    if (!honest) != is_wolf[0] {
        return None;
    }
    Some(is_wolf)
}

fn main() {
    input!(n: usize, s: chars);
    if let Some(is_wolf) = solve(&s, true, true) {
        for &is_wolf in is_wolf.iter() {
            print!("{}", if is_wolf { "W" } else { "S" });
        }
        println!();
    } else if let Some(is_wolf) = solve(&s, true, false) {
        for &is_wolf in is_wolf.iter() {
            print!("{}", if is_wolf { "W" } else { "S" });
        }
        println!();
    } else if let Some(is_wolf) = solve(&s, false, true) {
        for &is_wolf in is_wolf.iter() {
            print!("{}", if is_wolf { "W" } else { "S" });
        }
        println!();
    } else if let Some(is_wolf) = solve(&s, false, false) {
        for &is_wolf in is_wolf.iter() {
            print!("{}", if is_wolf { "W" } else { "S" });
        }
        println!();
    } else {
        println!("-1");
    }
}


Measured memory_bytes: 4352
#include <array>
#include <vector>
#include <deque>
#include <queue>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <string>
#include <algorithm>
#include <numeric>
#include <functional>
#include <iterator>
#include <tuple>
#include <utility>
#include <limits>
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cstdint>
#include <cassert>

using namespace std;

template<typename T, size_t N>
constexpr size_t NELEMS(T (&)[N]) { return N; }

#define FOR(i, start, end) for(int i = (start); i < (end); ++i)
#define REP(i, n) FOR(i, 0, n)

#define DEBUG
#undef DEBUG

using ll = long long;

ll X, Y;

void solve()
{
    if(abs(X-Y) <= 1)
        cout << "Brown\n";
    else
        cout << "Alice\n";
}

int main()
{
    cin >> X >> Y;

    solve();

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
using namespace std;
int n ,a[100001] , ma = -1 ,ans;
int main()
{

        cin >> n ;
        for (int i = 0 ; i < n ;i++)cin >>a[i];
        for (int i =  n - 1 ; i >=0 ; i--)
        {
            if (a[i] <= a[i-1])ans++;
            else ma= max(ma,ans),ans = 0;
        }
        cout <<max(ans , ma);


    return 0;
}


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

typedef long long ll;

const int N = 200001;
const ll MAXN = N;
const ll MAXVAL = 1e9;

#define x() first
#define h() second

ll n, d, a;
pair<ll,ll> monsters[N];

struct segtree {
  ll n, *vals, *deltas;
  segtree(vector<ll> &ar) {
    n = ar.size();
    vals = new ll[4*n];
    deltas = new ll[4*n];
    build(ar, 1, 0, n-1);
  }
  void build(vector<ll> &ar, ll p, ll i, ll j) {
    deltas[p] = 0;
    if (i == j)
      vals[p] = ar[i];
    else {
      ll k = (i + j) / 2;
      build(ar, p<<1, i, k);
      build(ar, p<<1|1, k+1, j);
      pull(p);
    }
  }
  void pull(ll p) {
    vals[p] = vals[p<<1] + vals[p<<1|1];
  }
  void push(ll p, ll i, ll j) {
    if (deltas[p]) {
      vals[p] += (j - i + 1) * deltas[p];
      if (i != j) {
        deltas[p<<1] += deltas[p];
        deltas[p<<1|1] += deltas[p];
      }
      deltas[p] = 0;
    }
  }
  void update(ll _i, ll _j, ll v,
              ll p, ll i, ll j) {
    push(p, i, j);
    if (_i <= i && j <= _j) {
      deltas[p] += v;
      push(p, i, j);
    } else if (_j < i || j < _i) {
      // do nothing
    } else {
      ll k = (i + j) / 2;
      update(_i, _j, v, p<<1, i, k);
      update(_i, _j, v, p<<1|1, k+1, j);
      pull(p);
    }
  }
  ll query(ll _i, ll _j,
            ll p, ll i, ll j) {
    push(p, i, j);
    if (_i <= i and j <= _j) {
      return vals[p];
    } else if (_j < i || j < _i) {
      return 0;
    } else {
      ll k = (i + j) / 2;
      return query(_i, _j, p<<1, i, k) +
             query(_i, _j, p<<1|1, k+1, j);
    }
  }
};

int main () {
	ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	cin >> n >> d >> a;
	for (int i = 0; i < n; i++)
		cin >> monsters[i].x() >> monsters[i].h();
	sort(monsters,monsters+n);
	vector<ll> monster_coords(n), monster_health(n);
	for (int i = 0; i < n; i++) {
		monster_coords[i] = monsters[i].x();
		monster_health[i] = monsters[i].h();
	}
	monster_coords.push_back(2*1000000007);

	segtree helth(monster_health);

	ll ans = 0;
	for (int i = 0; i < n; i++) {
		ll cur_helth = helth.query(i,i,1,0,n-1);
		if (cur_helth > 0) {
			int j = distance(monster_coords.begin(),upper_bound(monster_coords.begin(), monster_coords.end(),monster_coords[i]+2*d))-1;
			helth.update(i,j,-a*(cur_helth/a+(cur_helth%a > 0)),1,0,n-1);
			ans += cur_helth/a+(cur_helth%a > 0);
		}
	}
	cout << ans << endl;

	cout << flush;
	return 0;
}

Measured memory_bytes: 18148
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
using namespace std;
typedef long long ll;
const ll MOD = 998244353;
const ll INF = (ll)1000000007 * 1000000007;
const double EPS = 1e-9;
typedef pair<int, int> P;
typedef unsigned int ui;
#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 long double ld;
typedef complex<ld> Point;
const ld eps = 1e-11;
const ld pi = acos(-1.0);
typedef pair<ll, ll> LP;
int main() {
	char at[1000]; int an[1000];
	char bt[1000]; int bn[1000];
	char ct[1000]; int cn[1000];
	char x;
	int c1 = 0; int m;
	while (cin >> x) {
		if (x == '$')break;
		cin >> m;
		at[c1] = x; an[c1] = m; c1++;
	}
	int c2 = 0;
	while (cin >> x) {
		if (x == '$')break;
		cin >> m;
		bt[c2] = x; bn[c2] = m; c2++;
	}
	int c3 = 0;
	while (cin >> x) {
		if (x == '$')break;
		cin >> m;
		ct[c3] = x; cn[c3] = m; c3++;
	}
	int chk = -1;
	rep(i, c1 - c2+1) {
		if (at[i] == bt[0]) {
			bool f = true;
			if (an[i] < bn[0])f = false;
			Rep(k, 1 ,c2-1){
				if (at[i + k] != bt[k] || an[i + k] != bn[k])f = false;
			}
			if (at[i+c2-1]!=bt[c2-1]||an[i + c2 - 1] < bn[c2 - 1])f = false;
			if (f) {
				chk = i; break;
			}
		}
	}
	queue<pair<char, int>> q1, q2;
	if (chk == -1) {
		rep(i, c1) {
			q1.push({ at[i],an[i] });
		}
	}
	else {
		rep(i, chk) {
			q1.push({ at[i],an[i] });
	    }
		if (c2>1&&an[chk] - bn[0] > 0) {
			q1.push({ at[chk],an[chk] - bn[0] });
		}
		rep(i, c3) {
			q1.push({ ct[i],cn[i] });
		}
		if (an[chk + c2 - 1] - bn[c2 - 1] > 0) {
			q1.push({ at[chk + c2 - 1],an[chk + c2 - 1] - bn[c2 - 1] });
		}
		Rep(i, chk + c2, c1) {
			q1.push({ at[i],an[i] });
		}
	}
	pair<char, int>memo = { '#',-1 };
	while (!q1.empty()) {
		pair<char, int> now = q1.front(); q1.pop();
		if (now.first == memo.first) {
			memo.second += now.second;
		}
		else {
			if (memo.second >= 0) {
				q2.push(memo);
			}
			memo = now;
		}
	}
	q2.push(memo);
	while (!q2.empty()) {
		pair<char, int> out = q2.front(); q2.pop();
		cout << out.first << " " << out.second << " ";
	}
	cout << '$' << endl;
	return 0;
}


Measured memory_bytes: 3184
N,A,B = map(int,input().split())
temp = 0
if (B-A)%2 == 0:
    print(int((B-A)//2))
else:
    a = N - A + 1
    b = N - B + 1
    print(min([B-1,N-A,A + (B-A-1)//2,a + (b-a-1)//2]))

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define sqr(x) ((x)*(x))
#define mp make_pair
inline char gc(){
    static char buf[100000],*p1=buf,*p2=buf;
    return p1==p2&&(p2=(p1=buf)+fread(buf,1,100000,stdin),p1==p2)?EOF:*p1++;
}
#define int long long
#define gc getchar
inline int read(){
	int x = 0; char ch = gc(); bool positive = 1;
	for (; !isdigit(ch); ch = gc())	if (ch == '-')	positive = 0;
	for (; isdigit(ch); ch = gc())	x = x * 10 + ch - '0';
	return positive ? x : -x;
}
inline void write(int a){
    if(a>=10)write(a/10);
    putchar('0'+a%10);
}
inline void writeln(int a){
    if(a<0){
    	a=-a; putchar('-');
	}
	write(a); puts("");
}
const int N=705;
int n,m,color[N],v[N][N],t[2]; 
void dfs(int p,int id){
	color[p]=id; t[id]++;
	for(int i=1;i<=n;i++)if(p!=i&&!v[p][i]){
		if(color[i]==-1)dfs(i,id^1);
		else if(color[i]==color[p]){
			puts("-1"); exit(0);
		}
	}
}
bitset<N> s;
signed main(){
	n=read(); m=read();
	for(int i=1;i<=m;i++){
		int s=read(),t=read();
		v[s][t]=v[t][s]=1;
	}
	memset(color,-1,sizeof(color)); s[0]=1;
	for(int i=1;i<=n;i++)if(color[i]==-1){
		dfs(i,1);
		s=(s<<t[0])|(s<<t[1]); t[0]=t[1]=0; 
	}
	int ans=1e9;
	for(int i=0;i<=n;i++)if(s[i])ans=min(ans,i*(i-1)/2+(n-i)*(n-i-1)/2);
	cout<<ans<<endl;
}


Measured memory_bytes: 4224
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)   FOR(i,0,n)
#define pb emplace_back
#define mp make_pair
typedef long long ll;
typedef pair<int,int> pint;

int a[301][301],d[301][301];
const int inf=1000100010;
int v;
int rev_warshall_floyd(){
    rep(k,v)rep(i,v)rep(j,v){
        if(k==i||k==j||d[i][k]==inf||d[k][j]==inf)continue;
        if(d[i][k]+d[k][j]==a[i][j]) d[i][j]=inf;
        else if(d[i][k]+d[k][j]<a[i][j]) return -1;
    }
    return 0;
}
int main(){
    cin>>v;
    rep(i,v)rep(j,v){
        cin>>a[i][j];
        d[i][j]=a[i][j];
    }
    ll ans=0;
    if(rev_warshall_floyd()==-1) cout<<-1<<endl;
    else{
        rep(i,v)rep(j,v){
            if(d[i][j]!=inf) ans+=d[i][j];
        }
        cout<<ans/2<<endl;
    }
    return 0;
}

Measured memory_bytes: 896
#include <stdio.h>
int main()
{
    long long N;
    long long a = 0;
    scanf("%lld", &N);
    for (int i = 1; i <= N; i++)
    {
        if (i % 3 != 0 && i % 5 != 0)
            a += i;
    }
    printf("%lld\n", a);
    return 0;
}

Measured memory_bytes: 1692
#include <iostream>
#include <vector>
#define M 201
using namespace std;
typedef pair<int,int> P;
void func(int);
int N,u,d;
vector<int> node;
bool edge[M][M],ans,visited[M];
string s;

int main(){
  cin>>N;
  for(int i=0;i<M;i++)
    for(int j=0;j<M;j++) edge[i][j]=false;
  while(N--){
    cin>>u>>s>>d;
    node.push_back(u);
    if(s=="lock") edge[u][d+100]=true;
    else edge[d+100][u]=true;
  }
  for(int i=0;i<(int)node.size();i++){
    func(node[i]);
    if(ans) break;
    for(int j=0;j<M;j++) visited[j]=false;
    func(node[i]);
    if(visited[node[i]]) ans=true;
  }
  if(ans) cout<<1<<endl;
  else cout<<0<<endl;
  return 0;
}

void func(int x){
  for(int i=0;i<M;i++){
    if(!edge[x][i]||visited[i]) continue;
    visited[i]=true;
    func(i);
  }
}

Measured memory_bytes: 1280
#include<cstdio>
#include<cstring>
#define retrun return
#define cpnst const
typedef long long ll;
cpnst ll mod=1e9+7;
ll qpow(ll x,ll k)
{ll r=1;for(;k;k>>=1,(x*=x)%=mod)if(k&1)(r*=x)%=mod;return r;}
struct mat
{ll a,b,c,d;mat(ll e=0,ll f=0,ll g=0,ll h=0){a=e,b=f,c=g,d=h;}};
mat operator*(mat x,mat y)
{return mat((x.a*y.a+x.b*y.c)%mod,(x.a*y.b+x.b*y.d)%mod,
(x.c*y.a+x.d*y.c)%mod,(x.c*y.b+x.d*y.d)%mod);}
int S,T,K;
char str[1111][1111];
int N,M;
ll P;
int CX,CY,DX,DY;
void precalc()
{
	register int i,ii;
	for(i=1;i<=N;i++)if(str[i][M]=='#'&&str[i][1]=='#')CX++;
	for(i=1;i<=M;i++)if(str[N][i]=='#'&&str[1][i]=='#')CY++;
	for(i=1;i<=N;i++)
		for(ii=1;ii<=M;ii++)
			if(str[i][ii]=='#')
			{
				K++;
				if(str[i][ii+1]=='#')DX++;
				if(str[i+1][ii]=='#')DY++;
			}
	if(CX)S=DX,T=CX;
	else S=DY,T=CY;
}
int main()
{
	scanf("%d%d%lld",&N,&M,&P);
	register int i;
	for(i=1;i<=N;i++)
		scanf("%s",str[i]+1);
	precalc();
	if(CX&&CY)return puts("1"),0;
	else if(!(CX|CY))return printf("%lld\n",qpow(K,P-1)),0;
	mat X=mat(1,1,0,0),Y=mat(K,0,mod-S,T);
	for(P--;P;P>>=1,Y=Y*Y)if(P&1)X=X*Y;
	printf("%lld\n",X.a%mod);
}
/*
Just go for it.
*/

Measured memory_bytes: 2824
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using pl = pair<ll,ll>;
using pi = pair<int,int>;
#define all(x) x.begin(),x.end()
#define rep(i,j,n) for (long long i = j; i < (long long)(n); i++)
#define _GLIBCXX_DEBUG
const ll MOD = 1000000007;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
//(a+b-1)/b
//priority_queue<ll, vector<ll>, greater<ll>> q;

template<int MOD> struct Fp {  
    long long val;
    constexpr Fp(long long v = 0) noexcept : val(v % MOD) {
        if (val < 0) val += MOD;
    }
    constexpr int getmod() { return MOD; }
    constexpr Fp operator - () const noexcept {
        return val ? MOD - val : 0;
    }
    constexpr Fp operator + (const Fp& r) const noexcept { return Fp(*this) += r; }
    constexpr Fp operator - (const Fp& r) const noexcept { return Fp(*this) -= r; }
    constexpr Fp operator * (const Fp& r) const noexcept { return Fp(*this) *= r; }
    constexpr Fp operator / (const Fp& r) const noexcept { return Fp(*this) /= r; }
    constexpr Fp& operator += (const Fp& r) noexcept {
        val += r.val;
        if (val >= MOD) val -= MOD;
        return *this;
    }
    constexpr Fp& operator -= (const Fp& r) noexcept {
        val -= r.val;
        if (val < 0) val += MOD;
        return *this;
    }
    constexpr Fp& operator *= (const Fp& r) noexcept {
        val = val * r.val % MOD;
        return *this;
    }
    constexpr Fp& operator /= (const Fp& r) noexcept {
        long long a = r.val, b = MOD, u = 1, v = 0;
        while (b) {
            long long t = a / b;
            a -= t * b; swap(a, b);
            u -= t * v; swap(u, v);
        }
        val = val * u % MOD;
        if (val < 0) val += MOD;
        return *this;
    }
    constexpr bool operator == (const Fp& r) const noexcept {
        return this->val == r.val;
    }
    constexpr bool operator != (const Fp& r) const noexcept {
        return this->val != r.val;
    }
    friend constexpr ostream& operator << (ostream &os, const Fp<MOD>& x) noexcept {
        return os << x.val;
    }
    friend constexpr Fp<MOD> modpow(const Fp<MOD> &a, long long n) noexcept {
        if (n == 0) return 1;
        auto t = modpow(a, n / 2);
        t = t * t;
        if (n & 1) t = t * a;
        return t;
    }
};
using mint = Fp<998244353>;

signed main(){
	//cout << fixed << setprecision(10);
    int n,k; cin >> n >> k;
	vi l(k) , r(k);
	rep(i,0,k) cin >> l[i] >> r[i];
	vector<mint> dp(n+1);
	vector<mint> dpsum(n+1);
	dp[1] = 1;
	dpsum[1] = 1;
	for(int i = 2; i <= n; i++){
		rep(j,0,k){
			int li = i - r[j];
			int ri = i - l[j];
			if(ri < 1)continue;
			chmax(li , 1);
			dp[i] += dpsum[ri] - dpsum[li-1];
		}
		dpsum[i] += dpsum[i-1] + dp[i];
	}
	cout << dp[n] << endl;

	return 0;
}

Measured memory_bytes: 6384
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define snuke srand((unsigned)clock()+(unsigned)time(NULL));
#define show(x) cerr<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef tuple<int,int,int> T;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
typedef vector<T> vt;
int getInt(){int x;scanf("%d",&x);return x;}
template<typename T>istream& operator>>(istream&i,v(T)&v){rep(j,sz(v))i>>v[j];return i;}
template<typename T>string join(const v(T)&v){stringstream s;rep(i,sz(v))s<<' '<<v[i];return s.str().substr(1);}
template<typename T>ostream& operator<<(ostream&o,const v(T)&v){if(sz(v))o<<join(v);return o;}
template<typename T1,typename T2>istream& operator>>(istream&i,pair<T1,T2>&v){return i>>v.fi>>v.se;}
template<typename T1,typename T2>ostream& operator<<(ostream&o,const pair<T1,T2>&v){return o<<v.fi<<","<<v.se;}
template<typename T>bool mins(T& x,const T&y){if(x>y){x=y;return true;}else return false;}
template<typename T>bool maxs(T& x,const T&y){if(x<y){x=y;return true;}else return false;}
template<typename T>ll suma(const v(T)&a){ll res(0);for(auto&&x:a)res+=x;return res;}
const double eps = 1e-10;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
#define dame { puts("-1"); return 0;}
#define yn {puts("Yes");}else{puts("No");}
const int MX = 200005;



int main() {
  string s;
  cin>>s;
  if (s.back() == 's') s += 'e';
  s += 's';
  cout<<s<<endl;
  return 0;
}






















Measured memory_bytes: 3628
#!/usr/bin/env python2
"""
This file is part of https://github.com/cheran-senthil/PyRival
Copyright 2019 Cheran Senthilkumar <hello@cheran.io>

"""
from __future__ import division, print_function

import itertools
import math
import os
import sys
from atexit import register
from io import BytesIO


class dict(dict):
    """dict() -> new empty dictionary"""

    def items(self):
        """D.items() -> a set-like object providing a view on D's items"""
        return dict.iteritems(self)

    def keys(self):
        """D.keys() -> a set-like object providing a view on D's keys"""
        return dict.iterkeys(self)

    def values(self):
        """D.values() -> an object providing a view on D's values"""
        return dict.itervalues(self)


def gcd(x, y):
    """greatest common divisor of x and y"""
    while y:
        x, y = y, x % y
    return x


range = xrange

filter = itertools.ifilter
map = itertools.imap
zip = itertools.izip

sys.stdin = BytesIO(os.read(0, os.fstat(0).st_size))
sys.stdout = BytesIO()
register(lambda: os.write(1, sys.stdout.getvalue()))

input = lambda: sys.stdin.readline().rstrip('\r\n')

FMOD = 1000000007.0
fmod = lambda x: x - FMOD * math.trunc(x / FMOD)

h, w = map(int, input().split())

grid = [input() + '#' for _ in range(h)]
grid.append('#' * (w + 1))

dp = [[0.0] * (w + 1) for _ in range(h + 1)]
dp[-2][-2] = 1.0

for i in range(h - 1, -1, -1):
    for j in range(w - 1, -1, -1):
        if (i == h - 1) and (j == w - 1):
            continue
        dp[i][j] = fmod((dp[i + 1][j] if grid[i + 1][j] == '.' else 0.0) +
                        (dp[i][j + 1] if grid[i][j + 1] == '.' else 0.0))

print(int(dp[0][0]) % 1000000007)


Measured memory_bytes: 42364
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e6+7;
typedef long long ll;
int n, m, k;

char ch[maxn];

int twoNum(int x){
    int ans = 0;
    while(x > 0 && (x & 1) == 0){
        ans++;
        x >>= 1;
    }
    return ans;
}
int main()
{
    scanf("%d", &n);
    scanf("%s", ch);
    vector<int> v;
    for(int i=0;i<n-1;i++){
        v.push_back(abs((ch[i] - '0') - (ch[i+1] - '0')));
    }
    //for(int x : v)cout << x << ' '; cout << '\n';
    vector<int> cnt(3, 0);
    for(int x : v){
        cnt[x]++;
    }
    int coeff = 1;
    if(cnt[1] == 0){
        for(int & x : v){
            x >>= 1;
        }
        coeff = 2;
    }
    n = v.size();
    //for(int x : v)cout << x << ' '; cout << '\n';
    int res = 0, ans = 0;
    for(int i=0;i<n;i++){
        if(res <= 0){
            ans ^= v[i];
            //cout << i << ' ' << v[i] << '\n';
        }
        res += twoNum(n - 1 - i) - twoNum(i + 1);
    }
    //cout << "ans = " << ans << '\n';
    ans = ans & 1;
    printf("%d\n", ans * coeff);
    return 0;
}


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

using namespace std;

int main(void){
  int N;
  cin >> N;
  int a,b,c,d;
  a=N/1000;
  b=(N-a*1000)/100;
  c=(N-a*1000-b*100)/10;
  d=N%10;
  if((a==b&&b==c) || (b==c && c==d)){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
}

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

int main(){
    string s; cin >> s;
    int q; cin >> q;
    int tmp=0;
    vector<char> front,back;
    while(q--){
        int a; cin >> a;
        if(a==1){
            tmp++;
        }else{
            int f; char c;
            cin >> f >> c;
            if(tmp%2==0){
                if(f==1){
                    front.push_back(c);
                }else{
                    back.push_back(c);
                }
            }else{
                if(f==1){
                    back.push_back(c);
                }else{
                    front.push_back(c);
                }
            }
        }
    }
    if(tmp%2==0){
        for(int i=front.size()-1;i>=0;i--){
            cout << front[i];
        }
        cout << s;
        for(int i=0;i<back.size();i++){
            cout << back[i];
        }
        cout << endl;
    }else{
        reverse(s.begin(),s.end());
        for(int i=back.size()-1;i>=0;i--){
            cout << back[i];
        }
        cout << s;
        for(int i=0;i<front.size();i++){
            cout << front[i];
        }
        cout << endl;
    }
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define countof(array) (sizeof(array) / sizeof(array[0]))
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,n,s) for(int i = s; i < (n); ++i)
#define rsrep(i,n,s) for(int i = (n)-1; i >= s; --i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define aall(a) (a), (a)+countof(a)//for array sorting
#define raall(a) (a), (a)+countof(a), greater<>()
#define show(x) cout<<#x<<" = "<<x<<endl;
#define vfind(v, a) find(all(v), a) != v.end()
#define yn(f) { if (f) puts("YES"); else puts("NO"); }
#define yns(f) { if (f) puts("Yes"); else puts("No"); }
#define show_ary(...) { cout<<#__VA_ARGS__<<" = "; for (const auto& x : (__VA_ARGS__)) { cout<<x<<" "; } cout<<endl; }
#define show_pair(...) cout<<#__VA_ARGS__<<" = "<<endl; for (const auto& x : (__VA_ARGS__)) { cout<<"  "<<x.fi<<" : "<<x.se<<endl; }
#define out_ary(...) { for (const auto& x : (__VA_ARGS__)) { cout<<x<<" "; } cout<<endl; }
#define argmax(v) distance((v).begin(), max_element(all(v)))
#define argmin(v) distance((v).begin(), min_element(all(v)))
#define vmax(v) *max_element(all(v))
#define vmin(v) *min_element(all(v))
typedef long long int ll;
typedef pair<int, int> P;
typedef vector<P> vpair;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<double> vdouble;
typedef vector<string> vstr;
typedef vector<bool> vbool;
typedef vector<vint> vvint;
typedef vector<vll> vvll;
typedef vector<vstr> vvstr;
typedef vector<vbool> vvbool;
const ll LINF = 2000000000000000000ll;
const int INF = 1000000100;
const ll MOD = 1e9+7;

int h, w;
vvbool checked;
vstr s;
vint dx = {-1, 0, 1, 0};
vint dy = {0, 1, 0, -1};
ll bl = 0, wh = 0;

void dfs(int x, int y) {
    checked[x][y] = true;
    if (s[x][y] == '#') bl++;
    else wh++;
    rep(i, 4) {
        int nx = x + dx[i], ny = y + dy[i];
        if (nx < 0 || nx >= h || ny < 0 || ny >= w) continue;
        if (checked[nx][ny]) continue;
        if (s[x][y] == s[nx][ny]) continue;
        dfs(nx, ny);
    }
}

int main() {
    cin >> h >> w;
    checked.resize(h, vbool(w, false));
    s.resize(h);
    rep(i, h) cin >> s[i];
    
    ll ans = 0;
    rep(i, h) {
        rep(j, w) {
            if (checked[i][j]) continue;
            dfs(i, j);
            ans += bl * wh;
            bl = 0;
            wh = 0;
        }
    }

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

Measured memory_bytes: 18048
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int (i) = 0; (i) < (n); ++(i))
#define rrep(i,n) for(int (i) = (n) - 1; (i) >= 0; --(i)) //Reversi rep
#define nfor(i,a,b) for(int (i) = (a); (i) < (b); ++(i)) //Natural for
#define rfor(i,a,b) for(int (i) = (b); (i) >= (a); --(i)) //Reversi for

int main()
{
    string a,b,c;
    cin >> a >> b >> c;
    cout << a[0] << b[1] << c[2] << endl;
    return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

int main() {
  ll a, b;
  cin >> a >> b;
  if ((a & 1) != (b & 1)) {
    puts("IMPOSSIBLE");
  } else {
    cout << (a + b) / 2 << endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
signed main(){
  int n;
  int a[200010];
  cin>>n;
  int pum[200010],xum[200010];
  int sum=0,xsum=0;
  for(int i=0;i<n;i++){
    cin>>a[i];
    pum[i]=sum+=a[i];
    xum[i]=xsum^=a[i];
  }
  int ans=0;
  for(int i=0;i<n;i++){
    int lb=i,ub=n,mid;
    while(ub-lb>1){
      mid=(ub+lb)/2;
      int s=pum[mid]-pum[i]+a[i];
      int t=xum[mid]^xum[i]^a[i];
      if(s==t)lb=mid;
      else ub=mid;
    }
    //cout<<i<<" "<<lb<<endl;
    ans+=lb-i+1;
  }
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 4992
n = int(input())

tmp = [int(s) for s in input().split()]

target = 1
flag = 0
for i in range(n):
    if(tmp[i] == target):
        flag = 1
        target += 1
#print(target)
if(flag == 0):
    print(-1)
else:
    print(n - target +1)

Measured memory_bytes: 25768
#include<iostream>
#include<algorithm>
#include<vector>
#include<stack>
#include<queue>
#include<cstdio>
#include<climits>
#include<cmath>
#include<cstring>
#include<string>
#include<complex>
#include<map>

#define f first
#define s second
#define mp make_pair

#define REP(i,n) for(int i=0; i<(int)(n); i++)
#define FOR(i,c) for(__typeof((c).begin()) i=(c).begin(); i!=(c).end(); i++)
#define ALL(c) (c).begin(), (c).end()
#define EPS (1e-10)
using namespace std;

typedef unsigned int uint;
typedef long long ll;
typedef complex<double> P;

bool memo[11][11];
int data[10];

bool ans(int p, int b, int c){
  if(memo[b][c]) return false;
  if(p == 10) return true;
  int d = data[p];
  if(b < d && ans(p+1, d, c)) return true;
  if(c < d && ans(p+1, b, d)) return true;
  memo[b][c] = true;
  return false;
}

int main(){
  int n;
  scanf("%d",&n);
  while(n --> 0){
    memset(memo,0,sizeof(memo));
    REP(i,10) scanf("%d",&data[i]);
    puts(ans(0,0,0)?"YES":"NO");
  }
  return 0;
}

Measured memory_bytes: 0
import java.io.BufferedReader;
import java.io.InputStreamReader;


public class Main {

	public static void main(String[] args) throws Exception {
		// TODO ?????????????????????????????????????????????
		BufferedReader breader = getReader();

		int[] ary = getAry(breader);
		int a = ary[0];
		int b = ary[1];
		int c = 1;
		while( true ) {
			c = a%b;
			if ( c == 0) break;
			a = b;
			b = c;
		}
		System.out.println(b);
	}
	public static BufferedReader getReader() {
		return( new BufferedReader(new InputStreamReader(System.in)));
	}
	public static int getInt(BufferedReader br)throws Exception {
		String line = br.readLine();
		return Integer.valueOf(line);
	}
	public static int[] getAry(BufferedReader br)throws Exception {
		String line = br.readLine();
		String[] nstr = line.split(" ");
		int[] n = new int[nstr.length];
		for( int i=0 ; i < nstr.length ; i++ ) {
			n[i] = Integer.valueOf(nstr[i]);
		}
		return n;
	}
	public static void putAry(int[] ary) {
		for( int i = 0; i < ary.length ; i++ ) {
			System.out.print(ary[i]);
			if ( i < ary.length-1) {
				System.out.print(" ");
			}
		}
		System.out.println("");
	}

}

Measured memory_bytes: 17056
import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        int[] bruh = new int[n];
        for (int i = 0; i < n; i++) {
            bruh[i] = in.nextInt();
        }
        int count = 0;
        for (int i = 0; i < n; i++) {
            for (int j = i + 1; j < n; j++) {
                for (int k = j + 1; k < n; k++) {
                    if (bruh[i] != bruh[k]
                            && bruh[i] != bruh[j]
                            && bruh[k] != bruh[j]) {
                        if (bruh[i] + bruh[j] > bruh[k]
                                && bruh[i] + bruh[k] > bruh[j]
                                && bruh[j] + bruh[k] > bruh[i]) {
                            count++;
                        }
                    }

                }

            }

        }
        System.out.println(count);

    }
}


Measured memory_bytes: 27876
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define pf push_front
#define ll long long

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    
    int n,k;
	int a[1005];
	cin>>n>>k;
	for(int i=0; i<n; i++)cin>>a[i];

	sort(a,a+n);
	int sum = 0;
	for(int i=0; i<k; i++){
		sum += a[i];
	}

	cout << sum << "\n";
    
    return 0;
}

Measured memory_bytes: 3660
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <climits>

using namespace std;

int main(){
  int A, B, C, flag = 0;

	cin >> A >> B >> C;

	for (int i = A; i <= A*B; i+=A) {
		if (i%B == C) {
			flag = 1;
			break;
		}
	}

	if (flag) cout << "YES" << endl;
	else cout << "NO" << endl;

	return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <vector>
#include <algorithm>
using namespace std;

int max_dist;
bool used[10][10];
vector<int> answer_path;
vector<int> path;
vector<pair<int, int> > edges[10];

void dfs(int k, int dist)
{
  path.push_back(k);
  bool end = true;
  for (int i = 0; i < (int)edges[k].size(); ++i) {
    int t = edges[k][i].first;
    if (used[k][t])
      continue;
    used[k][t] = used[t][k] = true;
    dfs(edges[k][i].first, dist + edges[k][i].second);
    used[k][t] = used[t][k] = false;
    end = false;
  }

  if (end) {
    if (dist > max_dist) {
      max_dist = dist;
      answer_path = path;
    }
  }
  path.pop_back();
}

int main()
{
  int n, m;
  while (scanf("%d%d", &n, &m), n|m) {
    for (int i = 0; i < n; ++i) {
      edges[i].clear();
    }

    for (int i = 0; i < m; ++i) {
      int a, b, d;
      scanf("%d%d%d", &a, &b, &d);
      --a, --b;
      edges[a].push_back(make_pair(b, d));
      edges[b].push_back(make_pair(a, d));
    }

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

    max_dist = 0;
    for (int i = 0; i < n; ++i) {
      memset(used, false, sizeof(used));
      dfs(i, 0);
    }

    printf("%d\n", max_dist);
    for (int i = 0; i < (int)answer_path.size(); ++i) {
      if (i > 0)
        putchar(' ');
      printf("%d", answer_path[i] + 1);
    }
    puts("");
  }
}

Measured memory_bytes: 0