akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); ++i)
typedef long long ll;

int main(){
	string s,t;
	cin >> s >> t;
	int n = s.size();
	rep(i,n){
		if(s==t){
			cout << "Yes" << endl;
			return 0;
		}
		char t = s[0];
		rep(j,n-1){
			s[j] = s[j+1];
		}
		s[n-1] = t;
	}
	cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 256
n = input()
if int(n) < 3:
  print(0)
  exit()
a = [int(i) for i in input().split()]
l = len(a)
sum = 0
s = 0
for i in range(l):
  for j in range(i + 1, l):
    for k in range(j + 1, l):
      if not (a[i] == a[j] or a[j] == a[k] or a[k] == a[i]):
        if (a[i] + a[j]) > a[k] and (a[j] + a[k]) > a[i] and (a[k] + a[i]) > a[j]:
          sum += 1
print(sum)

Measured memory_bytes: 9164
#include<bits/stdc++.h>
using namespace std;
#define reus ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
int main()
{
	reus;
	int n,aman=0,i;
	cin>>n;
	int a[52];
	for(i=0;i<n;i++)
	{
		cin>>a[i];
	}
	for(i=0;i<n;i++)
	{
		if((i+1)!=a[i])
		aman++;
	}
	if(aman==2||aman==0)
	cout<<"YES"<<endl;
	else
	cout<<"NO"<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <queue>
#include <deque>
#include <set>
#include <stack>
 
using namespace std;
 
typedef long long ll;
const ll nmax = 1e9 + 7;
const ll mod = 998244353;
const double PI = 2 * asin(1);

int main() {
  int A, B, C;
  cin >> A >> B >> C;
  int MAX = B / A;
  cout << min(MAX, C) << endl;
  
  return 0;
}

Measured memory_bytes: 256
import java.io.*;
import java.util.*;
class Main{
  public static void main(String[] a){
    for (int i=1; i<10;i++) {
      for (int j=1; j<10; j++) {
        System.out.println(i + "x" + j + "=" + (i * j));
      }
    }
  }
}



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

int main(){
  int N;
  cin >> N;
  
  if(N == 1){
    cout << 1 << endl;
  }
  else{
    int64_t La = 2, Lb = 1;
    for ( int i = 1 ; i < N ; i++){
      int64_t k = Lb;
      Lb = La + Lb;
      La = k;
    }
    cout << Lb << endl;
  }
}

Measured memory_bytes: 256
import sys

sys.setrecursionlimit(10 ** 6)
readline = sys.stdin.readline

def dfs(p, v, num):
    global g, plus_list, ans
    tmp = num + plus_list[v]
    for x in g[v]:
        if x == p:
            continue
        dfs(v, x, tmp)
    ans[v] = tmp
    
def main():
    global g, plus_list, ans
    N, Q = map(int, readline().split())
    g = [[] for i in range(N)] 
    for i in range(N-1):
        a, b = map(int, readline().split())
        a -= 1
        b -= 1
        g[a].append(b)
        g[b].append(a)

    plus_list = [0] * N
    for i in range(Q):
        q, y = map(int, readline().split())
        plus_list[q-1] += y

    ans = [0] * N
    
    dfs(-1, 0, 0)
    print(*ans)
if __name__ == "__main__":
    main()

Measured memory_bytes: 236904
/*  Source Code By : NIKHIL E S
    Handle : cldflm  */

#include<bits/stdc++.h>

using namespace std;

int main()
{
    ios_base::sync_with_stdio(false);

    int n,k,arr[1005];
    cin>>n>>k;

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

    int total = 0;

    for(int z=0;z<k;z++)
    {
        int j=0,minz = arr[0];
        for(int i=0;i<n;i++)
        {
            if(arr[i]<minz)
                {
                    minz = arr[i];
                    j = i;
                }
        }
        total += minz;
        arr[j] = 1010;
    }
    cout<<total;

    return 0;
}


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

// types
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pdd;
typedef vector<ll> vll;

// macros
#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define FI first
#define SE second
#define REP(i,n) for(int i=0;i<((int)n);i++)
#define REP1(i,n) for(int i=1;i<((int)n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define PB push_back
#define EB emplace_back
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL

// constants
const int inf = 1e9;
const ll linf = 1LL << 50;
const double eps = 1e-10;
const int MOD = 1e9 + 7;
const int dx[4] = {-1, 0, 1, 0};
const int dy[4] = {0, -1, 0, 1};


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

  ll n;
  cin >> n;
  vll b(n);
  REP(i, n)
    cin >> b[i];

  stack<ll> ans;
  while(b.size() != 0){
    bool flag=true;
    for(ll i = b.size()-1; i>=0; i--){
      if(b[i] == i+1){
        b.erase(b.begin()+i);
        ans.push(i+1);
        flag = false;
        break;
      }
    }

    if(flag){
      cout << -1 << endl;
      return 0;
    }
  }

  while(!ans.empty()){
    cout << ans.top() << endl;
    ans.pop();
  }
}


Measured memory_bytes: 256
from collections import deque


def bfs(y, x, H, W, S):
    dirs = [(-1, 0), (0, -1), (1, 0), (0, 1)]
    depth = [[-1] * (W+2) for h in range(H+2)]
    q = deque()
    q.append((y, x))
    depth[y][x] = 0
    max_depth = 0
    while q:
        y, x = q.popleft()
        max_depth = max(max_depth, depth[y][x])
        for dy, dx in dirs:
            ny, nx = y + dy, x + dx
            if S[ny][nx] == '.' and depth[ny][nx] == -1:
                depth[ny][nx] = depth[y][x] + 1
                q.append((ny, nx))
    return max_depth


def solve():
    H, W = map(int, input().split())
    S = list()
    S.append(['#'] * (W+2))
    for _ in range(H):
        buf = input()
        S.append(list('#' + buf + '#'))
    S.append(['#'] * (W+2))

    dist_max = 0
    for y in range(H):
        for x in range(W):
            if S[y+1][x+1] == '.':
                d = bfs(y+1, x+1, H, W, S)
                dist_max = max(d, dist_max)
    print(dist_max)


if __name__ == '__main__':
    solve()


Measured memory_bytes: 3316
#include<bits/stdc++.h>
#define ll 				long long
#define ld 				long double
#define fastio 			ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define debug(x) 		cerr<<#x<<" "<<x<<endl
#define cina(a,n) 		for(ll i = 0;i<n;i++)	cin>>a[i];
#define couta(a,n) 		for(ll i = 0;i<n;i++) cout<<a[i]<<" ";
#define fauto(ar)		for(auto x : ar)	cout<<x<<" ";
#define mod 			1000000007
#define inf				10010010010010010
#define siz 			100005
#define f 				first
#define s 				second
#define pb 				push_back
#define endl 			"\n"
#define ci 				cin.ignore()
using namespace std;
int main()
{
	ll n,k,i,j,p,flag;
	cin>>n>>k;
	ll a[n+1];
	for(i = 1;i<=n;i++)	cin>>a[i];
	
	ll dp[2][k+1];
	
	for(i = 0;i<=1;i++)
		for(j = 0;j<=k;j++)
			dp[i][j] = 0;
	
//	for(i = 0;i<=k;i++)
//	dp[0][i] = 1;
	
	ll sum[k+1];
	flag = 1;
	for(i = 1;i<=n;i++)
	{
		sum[0] = 1;
		for(j = 1;j<=k;j++)
		sum[j] = sum[j-1] + dp[flag^1][j],
		sum[j] %= mod;
//		dp[flag][0] = 1;
		for(j = 0;j<=k;j++)
		{
			ll left = 0;
			if(j-a[i]-1 >= 0)
			left = sum[j-a[i]-1];
			
			ll right = sum[j];
			
			dp[flag][j] = right-left;
			dp[flag][j] %= mod;
			dp[flag][j] += mod;
			dp[flag][j] %= mod;
		}	
		flag ^= 1;
	}
	
	cout<<dp[flag^1][k];
	
	
}

Measured memory_bytes: 5972
fn input_one<T: std::str::FromStr> () -> Result<T, T::Err> {
    let mut n = String::new();
    std::io::stdin().read_line(&mut n).unwrap();
    n.trim().parse()
}

fn min(a: usize, b: usize) -> usize {
    if a < b { a } else { b }
}

fn pf(n: usize) -> usize {
    let mut r = n - 1;
    for i in 2.. {
        if i * i > n {
            break
        }
        if n % i == 0 {
            r = min(r, i + n / i - 2);
        }
    }
    return r;
}

fn main() {
    let n: usize = input_one().unwrap();
    println!("{}", pf(n));
}


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

int main(void){
    int n, W;
    cin >> n >> W;
    unordered_map<int,ll> cur;
    cur[0] = 0;
    rep(i,n){
        unordered_map<int,ll> nxt;
        ll w,v;
        cin >> w >> v;
        for (auto itr : cur) {
            ll curW = itr.first;
            ll curV = itr.second;
            nxt[curW] = max(nxt[curW], curV);
            if (curW+w <= W) {
                nxt[curW+w] = max(nxt[curW+w], curV+v);
            }
        }
        cur = move(nxt);
    }
    ll res = 0;
    for (auto itr : cur) {
        res = max(res, itr.second);
    }
    cout << res << endl;
    return 0;
}


Measured memory_bytes: 10384
#include <bits/stdc++.h>
    
using namespace std;
    
#define endl "\n"
#define ll unsigned long long
#define int long long int
#define pii pair <int, int>
#define pdd pair< double, double>
#define piii pair < pii, int > 
#define pll pair<ll, ll >
#define vi vector <int >
#define vvi vector < vi > 
#define vii vector < pii >
#define viii vector < piii >
#define vll vector <ll >
#define vb vector <bool > 
#define umap unordered_map
#define pb push_back
#define pq priority_queue
#define forn(i, n) for(int i = 0; i < (int)n; i++)
#define rep(i,b,c) for(int i = (int)b; i < (int)c; i++)
#define double long double
#define a first
#define b second

int dp[3005][3005][2];
vi arr(3005);
const int inf = -1e16;

int f(int i, int j, bool turn){
    if(i == j){
        if(turn)
            return arr[i];
        else return -arr[i];
    }

    if(dp[i][j][turn] != inf) return dp[i][j][turn];

    if(turn){
        return dp[i][j][turn] = max(f(i + 1, j, !turn) + arr[i], f(i, j - 1, !turn) + arr[j]);
    }else{
        return dp[i][j][turn] = min(f(i + 1, j, !turn) - arr[i], f(i, j - 1, !turn) - arr[j]);
    }
}


int32_t main(){
    ios::sync_with_stdio(0),cin.tie(0);
    
    int n;
    cin >> n;
    forn(i, n){
        cin >> arr[i];
    }
    forn(i, 3003){
        forn(j, 3003){
            forn(k, 2)
                dp[i][j][k] = inf;
        }
    }
    cout << f(0, n - 1, 1) << endl;

    return 0;
}


Measured memory_bytes: 141440
#include <bits/stdc++.h> 
#define int long long
#define quickie ios_base::sync_with_stdio(false); cin.tie(NULL);
#define rep(i, a, b) for(int i=a; i<b; i++)
#define rep1(i, a, b) for(int i=a; i<=b; i++)
#define repp(i, a, b) for(int i=b-1; i>=a; i--)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
#define db double
#define mi map<int, int>
#define mc map<char, int>
#define ms map<string, int>
#define vi vector<int>
#define qi queue<int>
#define MI(x) power(x, mod-2)
#define test int t; cin >> t;
#define mod 1000000007LL
//#define mod 998244353 
using namespace std;
int power(int x, int y) ;
int gcd(int a, int b) ;
#define pi 3.141592653589

signed main() {
    quickie 
    int n ;
    cin >> n ;
    for(int i=-1000; i<=1000; i++) {
        for(int j=-1000; j<=1000; j++) {
            int a = pow(i, 5), b = pow(j, 5) ;
            if(a-b == n) {
                cout << i << " " << j << "\n" ;
                return 0 ;
            }
        }
    }
}

int power(int x, int y) {
    int res = 1; x %= mod;
    while (y > 0) {
        if (y & 1)
            res = (res*x) % mod;
        y = y>>1;
        x = (x*x) % mod;
    }
    return res%mod;
}

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

Measured memory_bytes: 4116
package main

import (
	"bufio"
	"fmt"
	"io"
	"os"
	"strconv"
)

func main() {
	a, b := readInt(), readInt()
	m := map[int]int{
		1: 1,
		2: 2,
		3: 3,
	}
	delete(m, a)
	delete(m, b)

	for k := range m {
		fmt.Println(k)
	}
}

// sort ------------------------------------------------------------

type xxx struct {
	x int
}

type sortArray []xxx

func (s sortArray) Len() int           { return len(s) }
func (s sortArray) Swap(i, j int)      { s[i], s[j] = s[j], s[i] }
func (s sortArray) Less(i, j int) bool { return s[i].x < s[j].x }

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

var (
	readString func() string
	readBytes  func() []byte
)

func init() {
	readString, readBytes = newReadString(os.Stdin)
}

func newReadString(ior io.Reader) (func() string, func() []byte) {
	r := bufio.NewScanner(ior)
	r.Buffer(make([]byte, 1024), int(1e+11))
	r.Split(bufio.ScanWords)

	f1 := func() string {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Text()
	}
	f2 := func() []byte {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Bytes()
	}
	return f1, f2
}

func readInt() int {
	return int(readInt64())
}

func readInt64() int64 {
	i, err := strconv.ParseInt(readString(), 10, 64)
	if err != nil {
		panic(err.Error())
	}
	return i
}

func readFloat64() float64 {
	f, err := strconv.ParseFloat(readString(), 64)
	if err != nil {
		panic(err.Error())
	}
	return f
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}

func sum(a []int) int {
	var ret int
	for i := range a {
		ret += a[i]
	}
	return ret
}

func sumFloat64(a []float64) float64 {
	var ret float64
	for i := range a {
		ret += a[i]
	}
	return ret
}

func gcd(m, n int) int {
	for m%n != 0 {
		m, n = n, m%n
	}
	return n
}

func lcm(m, n int) int {
	return m / gcd(m, n) * n
}


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

int main(){
    int n,m,x;
    cin>>n>>m>>x;
    vector<int>a(m);
    rep(i,m)cin>>a[i];
    int cntunder=0;
    int cntover=0;
    for(int i=0;i<m;i++){
      if(a[i]<x)cntunder+=1;
      else break;
    }
    for(int i=m-1;i>=0;i--){
        if(a[i]>x)cntover+=1;
        else break;
    }
    cout<<min(cntunder,cntover)<<endl;
}


Measured memory_bytes: 256
n=int(input())
t=list(map(int,input().split()))
T=[-1,0]
for i in range(n):
  T.append(T[-1]+t[i])
T.append(T[-1]+1)
V=[0]+list(map(int,input().split()))+[0]
VV=[110]*(2*T[-1]+1)
for i in range(n+2):
  for j in range(2*T[-1]+1):
    if j<2*T[i]:
      a=T[i]-j/2
      VV[j]=min(VV[j],a+V[i])
    elif 2*T[i]<=j and j<=2*T[i+1]:
      VV[j]=min(VV[j],V[i])
    else:
      a=j/2-T[i+1]
      VV[j]=min(VV[j],a+V[i])
print(sum(VV)/2)

Measured memory_bytes: 45148
#include <bits/stdc++.h>
using namespace std;
vector<int> mp[100005];
queue<int> black, white;
int c[100005], num[100005], depth[100005];
int main()
{
    int n, x, y;
    scanf("%d", &n);
    for (int i = 1; i < n; i++) {
        scanf("%d%d", &x, &y);
        mp[x].push_back(y);
        mp[y].push_back(x);
    }
    c[1] = 1, c[n] = 2;
    depth[1] = depth[n] = 0;
    black.push(1);
    white.push(n);
    for (int d = 0; !black.empty() || !white.empty(); d++) {
        while (!black.empty()) {
            x = black.front();
            if (depth[x] != d) break;
            black.pop();
            for (int i = 0; i < mp[x].size(); i++) {
                y = mp[x][i];
                if (c[y] == 0) {
                    c[y] = 1;
                    depth[y] = d + 1;
                    black.push(y);
                }
            }
        }
        while (!white.empty()) {
            x = white.front();
            if (depth[x] != d) break;
            white.pop();
            for (int i = 0; i < mp[x].size(); i++) {
                y = mp[x][i];
                if (c[y] == 0) {
                    c[y] = 2;
                    depth[y] = d + 1;
                    white.push(y);
                }
            }
        }
    }
    for (int i = 1; i <= n; i++) {
        num[c[i]]++;
    }
    if (num[1] <= num[2]) printf("Snuke\n");
    else printf("Fennec\n");
    return 0;
}


Measured memory_bytes: 6656
import { createInterface } from 'readline';

const main = (lines: string[]) => {
  console.log(solve(lines));
};

export const solve = (lines: string[]): string => {
  const S = parseLines(lines);

  return S.split('').every(
    (e, i) => (i % 2 === 0 && e !== 'L') || (i % 2 === 1 && e !== 'R')
  )
    ? 'Yes'
    : 'No';
};

const parseLines = (lines: string[]) => {
  const obj = lines[0];
  debug(obj);
  return obj;
};

const debug = (message?: any, ...optionalParams: any[]) => {
  if (!!process.env.LOCAL_DEBUG) {
    console.log(message, ...optionalParams);
  }
};

if (!process.env.LOCAL_DEBUG) {
  const { stdin: input, stdout: output } = process;
  input.resume();
  input.setEncoding('utf8');
  const lines: string[] = [];
  createInterface({ input, output })
    .on('line', line => lines.push(line))
    .on('close', () => main(lines));
}


Measured memory_bytes: 11596
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <stack>

using namespace std;

int main(){

	string str;
	while(getline(cin,str)&&str!="."){
		stack<char> s;
		bool f=true;

		for(int i = 0; i < str.size(); i++){
			if(str[i]=='('){
				s.push(str[i]);
			}
			else if(str[i]==')'){
				if(s.empty()){
					f=false;
					break;
				}
				else{
					if(s.top()=='(')
						s.pop();
					else{
						f=false;
						break;
					}
				}
			}
			else if(str[i]=='['){
				//s2.push(1);
				s.push(str[i]);
			}
			else if(str[i]==']'){
				if(s.empty()){
					f=false;
					break;
				}
				else{
					if(s.top()=='['){
						s.pop();
					}
					else{
						f=false;
						break;
					}
				}
			}
		}
		if(f&&s.size()==0)
			cout<<"yes"<<endl;
		else
			cout<<"no"<<endl;
	}

	return 0;
}

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

using namespace std;
#define repeat(i,n) for(int i=0;i<(n);i++)

int main(){
  int n;
  string s;
  cin>>n>>s;
  int cnt=0;
  bool flag = 0;
  for(int i=0; i<n; i++){
    if(flag&&s[i]=='x')break;
    if(s[i]=='x')flag=1;
    else flag=0;
    cnt++;
  }
  cout<<cnt<<endl;

  return 0;
}

Measured memory_bytes: 3340
#include <stdio.h>
#include <inttypes.h>

#define MOD_BY UINT64_C(1000000007)

int main(void) {
	uint64_t m, n;
	uint64_t result = UINT64_C(1);
	if (scanf("%"SCNu64"%"SCNu64, &m, &n) != 2) return 1;
	while (n > 0) {
		if (n % 2 == 1) result = (result * m) % MOD_BY;
		m = (m * m) % MOD_BY;
		n /= 2;
	}
	printf("%"PRIu64"\n", result);
	return 0;
}



Measured memory_bytes: 2140
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

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

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

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

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

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

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

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        #[cfg(debug_assertions)]
        writeln!(&mut std::io::stderr(), concat!("[DEBUG] ", $(stringify!($a), "={:?} "),*), $($a),*);
    }
}

#[allow(unused_imports)]
use std::cmp::{min, max};

#[allow(unused_imports)]
use std::io::Write;

fn main() {
    input!{
      k: usize,
    }
    debug!(k);
    let v = k/50 + 50;
    let mut r = k%50;
    let o = v - r - 1;
    println!("{}", 50);
    for _ in 0..50 {
        if r > 0 {
            print!("{} ", v);
            r -= 1;
        } else {
            print!("{} ", o);
        }
    }
    println!();
}


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

int main(){
    int n;
    cin >> n;
    int a[n];
    for(int i = 0; i < n; i++){
        cin >> a[i];
    }
    long long ans = 0;
    for(int i = 0; i < n-1; i++){
        if(a[i] > a[i+1]){
            ans += a[i] - a[i+1];
            a[i+1] = a[i];
        }
    }
    cout << ans << endl;

    return 0;
}



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

int main(){
    int n, cnt=0, a=0, b=0, ab=0;
    
    cin >> n;
    for(int i=0;i<n;i++){
        string S;
        cin >> S;
        if(S.at(S.length()-1)=='A' && S.at(0)=='B')ab++;
        else{
            if(S.at(S.length()-1)=='A')a++;
            if(S.at(0)=='B')b++;
        }

        for(int i=0;i<S.length()-1;i++){
            if(S.at(i)=='A' && S.at(i+1)=='B')cnt++;
        }
    }
    if(ab>=1){
        cnt += ab-1;
        if(a>0){
            cnt++;
            a--;
        }
        if(b>0){
            cnt++;
            b--;
        }
    }
    cout << cnt + min(a,b) << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(),(x).end()
#define YES() printf("YES\n")
#define NO() printf("NO\n")
#define isYES(x) printf("%s\n",(x) ? "YES" : "NO")
#define Yes() printf("Yes\n")
#define No() printf("No\n")
#define isYes(x) printf("%s\n",(x) ? "Yes" : "No")
#define isIn(x,y,h,w) (x >= 0 && x < h && y >= 0 && y < w)

#define int long long
//using ll = long long;
using P = pair<int,int>;

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

template<class T> T &chmin(T &a,const T &b){ return a = min(a,b); }
template<class T> T &chmax(T &a,const T &b){ return a = max(a,b); }

const int INF=1e+18;
const double EPS=1e-9;
const int MOD=1000000007;

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

signed main(){
	string s;
	cin >> s;
	isYes(s[2] == s[3] && s[4] == s[5]);
}

Measured memory_bytes: 256
using System;
using System.Linq;
using System.Collections.Generic;

namespace Algorithm
{
    class Program
    {
        static void Main(string[] args)
        {
            var n = int.Parse(Console.ReadLine());

            // コスト的にどっちが速いが微妙だけど1回重複を削ってから回す・・・と思ったけどToHashSetが何故か競プロ環境だとCEになる
            // var array = Console.ReadLine().Split().Select(z => int.Parse(z)).ToHashSet<int>().ToArray();
            var array = Console.ReadLine().Split().Select(z => int.Parse(z)).ToArray();
            var min = array.Length == 1 ? array[0] : int.MaxValue;
            var tmp = array[0];

            for (var i = 1; i < array.Length; i++)
            {
                min = Math.Min(Gcd(tmp, array[i]), min);
                if (min == 1) break;
                tmp = min;
            }

            Console.WriteLine(min);
        }

        static int Gcd(int m, int n)
        {
            if (n > m) return Gcd(n, m);
            if (n == 0) return m;
            return Gcd(n, (m % n));
        }
    }
}

Measured memory_bytes: 19680
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i = 0; i < (N); i++)
#define repo(i,N) for(int i = 1; i < (N); i++)
#define pb push_back
#define mp make_pair
#define ll long long
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
//#define num 1000000007
#define pi acos(-1.0)
//cout << fixed << setprecision (20);   小数点以下2０桁まで
//intの最大値2147483647 ≒ 2×10^9
//long longの最大値9223372036854775807 ≒ 9×10^18
//'大文字'+=32;    で小文字に
//string s = to_string(int数);
//int n = stoi(string文字列);
//桁数に注意 long long　にする

int main() {
  
  vector<int> p(5);
  int ans = 0;
  int memo = 100;
  
  rep(i,5) {
  cin >> p[i];
  ans += ((p[i]+9)/10)*10;
  memo = min(memo, (p[i]-1)%10);
  }
  
  cout << ans-9+memo << endl;
  
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N, K;
  cin >> N >> K;
  vector<int> B(N);
  for (int i; i < N; i++) {
    B.at(i) = 1;
  }
  for (int j; j < K; j++) {
    int d = 0;
    cin >> d;
    //cout << d << endl;
    for (int l=0; l < d; l++) {
      int e = 0;
      cin >> e;
      //cout << e << endl;
      if (B.at(e-1) == 1) {
        B.at(e-1) = 0;
      }
    }
  }
  int result = 0;
  for (int i; i < N; i++) {
    //cout << B.at(i);
    result += B.at(i);
  }
  cout << result << endl;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
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;
}
typedef long long int ll;

#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define endl "\n"
const double EPS = 1e-7;
const int INF = 1 << 30;
const ll LLINF = 1LL << 60;
const double PI = acos(-1);
const int MOD = 1000000007;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

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

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vector<ll> t(n), a(n);
    for(int i = 0; i < n; i++) {
        cin >> t[i];
    }
    for(int i = 0; i < n; i++) {
        cin >> a[i];
    }
    vector<ll> h(n, -1);
    ll ans = 1;
    for(int i = 0; i < n; i++) {
        if(i == 0 || t[i] > t[i - 1]) {
            h[i] = t[i];
        }
    }
    for(int i = n - 1; i >= 0; i--) {
        if(i == n - 1 || a[i] > a[i + 1]) {
            if(h[i] != -1 && h[i] != a[i]) {
                ans = 0;
            } else {
                h[i] = a[i];
            }
        } else if(h[i] != -1) {
            if(h[i] > a[i]) {
                ans = 0;
            }
        } else {
            (ans *= min(a[i], t[i])) %= MOD;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 2560
// Ninjo ~ khaledalam.net@gmail.com
#include <bits/stdc++.h>
using namespace std;
#define sz(A)     (int)(A).size()
#define all(B)     (B).begin(),(B).end()
#define file       freopen("input.txt", "r", stdin)
#define ios        ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

int main() {
//	file;
	int n;
	cin>>n;
	string s1,s2;
	cin>>s1>>s2;
	int cnt = n*2;
	for (int i = 0; i < n; ++i) {
		if(s1[i] == s2.front()){
			bool f = 1;
			int c = 0;
			for (int j = i; j < n; ++j,c++) {
				if(s1[j] != s2[c]){
					c=0;
					f=0;
				}
			}
			if(f){
				for (int k = 0; k < i; k++) {
					s1.push_back(s2[n-i+k]);
				}
				cout<<sz(s1);
				return 0;
			}
		}
	}
	cout<<n*2;

}



Measured memory_bytes: 256
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

from heapq import heappush, heappop

N,M = map(int,readline().split())
m = map(int,read().split())
AB = [[] for _ in range(M+1)] # A に対する B
for a,b in zip(m,m):
    if a <= M:
        AB[a].append(b)

"""
・逆再生。最終日から順に、扱える仕事が増えていく。
"""

q = []
answer = 0
for B in AB:
    for b in B:
        heappush(q,-b)
    if q:
        answer -= heappop(q)

print(answer)

Measured memory_bytes: 27064
#include  <bits/stdc++.h> 
using namespace std;
 
#define ll long long
#define ar array
#define pii pair<int,int>
#define mp make_pair
 
const ll INF = 1e18;
const ll mod = 1000000007;
const int mxn=10e6;

bool comp(pii a,pii b){
	return a.first<b.first;
}

void solve(){
	string s;cin>>s;
	if (s[s.length()-1]=='s')
	{
		cout<<s<<"es"<<endl;
	}else{
		cout<<s<<'s';
	}
}
 
int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	#ifndef ONLINE_JUDGE
		freopen("input.txt", "r", stdin);
		freopen("output.txt", "w", stdout);
	#endif
	// int t;
	// cin>>t;
	// while(t--)
		solve();
	return 0;
}

Measured memory_bytes: 3624
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <math.h>
#include <iomanip>
using namespace std;
#define int long long

int gcd(int a,int b){
    return b ? gcd(b, a % b) : a;
}


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

    int n; cin >> n;
    vector<int> a(n);
    for(int i = 0;i < n;i ++) cin >> a.at(i);
    int ans = 0;

    map<int,int> mp;

    for(int i = 0;i < n;i ++){
        mp[a.at(i)] ++;
    }

    for(auto i = mp.begin();i != mp.end();i ++){
        if(i -> second < i -> first){
            ans += i -> second;
        }else if(i -> second > i -> first){
            ans += i -> second - i -> first;
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 7040
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		
		Scanner sc = new Scanner(System.in);
		int k = sc.nextInt();
		int x = sc.nextInt();
		sc.close();
		
		if(k * 500 >= x) {
			System.out.println("Yes");
		}else {
			System.out.println("No");
		}
	}
}


Measured memory_bytes: 21716
#include <bits/stdc++.h>
using namespace std;
int main() {
  string s; cin>>s;
  vector<char> v;
  for(char c:s) v.push_back(c);
  int s0=count(v.begin(),v.end(),'0'),s1=v.size()-s0;
  cout<<abs(min(s0,s1)*2);
}

Measured memory_bytes: 3732
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, from, to) for (int i = from; i < (to); ++i)
#define mp(x,y) make_pair(x,y)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
using ll = long long;
using vin=vector<int>;
using vll=vector<ll>;
using P = pair<int, int>;
const int inf=1e9+7;
const ll INF=1e18;
template <typename T> void chmin(T &a, T b) { a = min(a, b); }
template <typename T> void chmax(T &a, T b) { a = max(a, b); }

int main() {
  int a,b;
 cin>>a>>b;
  cout<<a-b+1<<endl;
}

Measured memory_bytes: 3608
import sys
def ii(): return int(sys.stdin.readline())
def mi(): return map(int, sys.stdin.readline().split())
def li(): return list(map(int, sys.stdin.readline().split()))
def li2(N): return [list(map(int, sys.stdin.readline().split())) for i in range(N)]
def dp2(ini, i, j): return [[ini]*i for i2 in range(j)]
def dp3(ini, i, j, k): return [[[ini]*i for i2 in range(j)] for i3 in range(k)]
#import bisect #bisect.bisect_left(B, a)
#from collections import defaultdict #d = defaultdict(int) d[key] += value

sys.setrecursionlimit(10**6)

def rec(x):
    global dp
    if dp[x]!=-1:
        return dp[x]
    num = 0
    for a in adj[x]:
        num = max(num, rec(a)+1)
    dp[x] = num
    return num


#入力受け取り
N, M = mi()
x = li2(M)

#隣接リスト作成
adj = [[] for i in range(N)]
for i in range(M):
    x[i][0] -= 1
    x[i][1] -= 1
    adj[x[i][0]].append(x[i][1])

dp = [-1]*N
for i in range(N):
    rec(i)

print(max(dp))

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

typedef long long int ll;
ll MOD = 1000000007;
ll INFL = 1ll << 60;
ll INF = 1 << 28;

template <typename T>
ostream& operator<<(ostream& os, vector<T>& vec) {
  cout << "{";
  for (int i = 0; i < vec.size(); i++)
    os << vec[i] << (i + 1 == vec.size() ? "" : " ");
  cout << "}";
  return os;
}

// ====================================================================

int main() {
  ll n, k, r, s, p;
  cin >> n >> k >> r >> s >> p;

  string t;
  cin >> t;

  for (int i = 0; i < t.size(); i++) {
    if (t[i] == 'r')
      t[i] = 'p';
    else if (t[i] == 'p')
      t[i] = 's';
    else
      t[i] = 'r';
  }

  vector<ll> dp(n);  // i回目までに得れるポイント
  string te;
  te = t;

  // 1マス目
  if (t[0] == 'r')
    dp[0] = r;
  else if (t[0] == 'p')
    dp[0] = p;
  else
    dp[0] = s;

  // cout << t << endl;

  for (int i = 1; i < n; i++) {
    // cout << t[i - k] << " " << i - k << " ";
    if (i < k || t[i - k] != t[i]) {  // 自分の出したい手が出せる
      if (t[i] == 'r') {
        // cout << "r" << endl;
        dp[i] = dp[i - 1] + r;
      } else if (t[i] == 'p') {
        // cout << "p" << endl;
        dp[i] = dp[i - 1] + p;
      } else {
        // cout << "s" << endl;
        dp[i] = dp[i - 1] + s;
      }
    } else {
      // cout << "x" << endl;
      dp[i] = dp[i - 1];
      t[i] = 'x';  // 出せなかった…
    }
  }

  // cout << dp << endl;

  cout << dp[n - 1] << endl;
}


Measured memory_bytes: 1280
import sys
import math
import itertools
import collections
import heapq
import re
import numpy as np

rr = lambda: sys.stdin.readline().rstrip()
rs = lambda: sys.stdin.readline().split()
ri = lambda: int(sys.stdin.readline())
rm = lambda: map(int, sys.stdin.readline().split())
rl = lambda: list(map(int, sys.stdin.readline().split()))
inf = float('inf')
mod = 10**9 + 7

_, x = rm()
li = rl()
cnt = 0
d = 0
for i in li:
  d += i
  if d <= x:
    cnt += 1
print(cnt + 1)







Measured memory_bytes: 27168
#include<stdio.h>
#include<stdlib.h>

int compareInt(const void *a, const void *b) 
{
	//const voidで読み取り専用の汎用ポインタ
	int aNum = *(int*)a; //汎用ポインタをint型ポインタにキャスト変換して、さらに*で変数モードにしてaNumに代入
	int bNum = *(int*)b;
	return bNum - aNum;
}

int main(void) 
{
	int n;
	int a[100];
	int i;
	
	int alice = 0;
	int bob = 0;

	//入力部分　始まり
	scanf("%d", &n);

	for ( i = 0; i < n; i++)
	{
		scanf("%d", &a[i]);
	}
	//入力部分　終わり

	qsort(a, n, sizeof(int), compareInt); //ソートする配列、要素数、一要素の大きさ、判定関数

	for (i = 0; i < n; i++)
	{
		if ( i % 2 == 0)
		{
			alice += a[i];
		}
		else
		{
			bob += a[i];
		}
	}
	printf("%d", alice - bob);

	return 0;
}

Measured memory_bytes: 128
h, w=gets.split.map(&:to_i)

if h%3==0 || w%3==0
  puts 0
  exit 0
end

def fun(h, w)
  ret=1_000_000_000
  (1...h).each do |i|
    cand=[i*w, (h-i)*(w/2), (h-i)*(w-w/2)]
    ret=[ret, cand.max-cand.min].min
  end
  [ret, h].min
end

puts [fun(h, w), fun(w, h)].min

Measured memory_bytes: 1788
#include<bits/stdc++.h>
using namespace std;
void print(const vector<int>&xs){
  for(auto&x:xs)cout<<x<<",";
  cout<<endl;
}
int gcd(int m,int n){
  if(m<n)return gcd(n,m);
  // Now, (m >= n) == T.
  if(n==0)return m;
  return gcd(n,m%n);
}
int N;
vector<int>x,d,g;  // x, difference, gcd.
main(){
  cin>>N;
  x=vector<int>(N+1);
  cin>>x[0];
  for(int i=1;i<=N;i++){
    cin>>x[i];
  }
  sort(x.begin(),x.end());
  //print(x);
  for(int i=1;i<=N;i++){
    d.push_back(x[i]-x[i-1]);
  }
  //print(d);
  g.push_back(d[0]);
  for(int i=1;i<N;i++){
    g.push_back(gcd(g[i-1],d[i]));
  }
  //print(g);
  cout<<g.back()<<endl;
}


Measured memory_bytes: 1784
#include <iostream>
#include <vector>
#include <cmath>
#include <iomanip>
#include <algorithm>

int c()
{
    long long n, k;
    std::cin >> n >> k;
    
    long long remind = n % k;
    long long ans = std::min(remind, std::abs(remind - k));
    
    std::cout << ans;
    
    return 0;
}

int main(int argc, const char * argv[])
{
    c();
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <utility>
#include <cmath>
#include <random>
#include <vector>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <string>
#include <algorithm>
using namespace std;

#define rep(i,n) for(int i = 0; i<n; ++i)
#define REP(i,n) for(int i = 1; i<=n; ++i)
#define all(x) begin(x),end(x)
#define show(obj) {for(auto x:obj)cout<<x<<' ';cout<<endl;}
#define line "----------"
typedef long long ll;
typedef pair<int,int> ip;
typedef pair<ll,ll> lp;
const int inf = 1001001000;
const ll INF = 1LL<<60;
const int MOD = (int)1e9 + 7;

int main(){
	int N,M,X; cin>>N>>M>>X;
	vector<vector<int>> book(N,vector<int>(M));
	vector<int> cost(N);
	rep(i,N){cin>>cost[i]; rep(j,M)cin>>book[i][j];}
	int ans = inf;
	for(int bit = 0; bit<(1<<N); ++bit){
		int e_ans = 0;
		vector<int> check(M,0);
		for(int i = 0; i<N; ++i){
			if(bit & (1<<i)){
				rep(j,M){
					check[j] += book[i][j];
				}
				e_ans += cost[i];
			}
		}
		bool ok = true;
		rep(i,M)if(check[i]<X)ok = false;
		if(ok) ans = min(ans, e_ans);
	}
	if(ans == inf)ans = -1;
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 3636
#include <stdio.h>

#define MAX(a, b) ((a>b)?a:b)
#define MAX3(a, b, c) MAX(MAX(a, b), c)

int main() {
  int a, b, c;
  scanf("%d%d%d", &a, &b, &c);
  printf("%d\n", MAX3(a, b, c)*9+a+b+c);
  return 0;
}


Measured memory_bytes: 128
#include <cstdio>
#include <algorithm>
#include <stack>
#include <queue>
#include <deque>
#include <vector>
#include <string>
#include <string.h>
#include <cstdlib>
#include <ctime>
#include <cmath>
#include <map>
#include <set>
#include <iostream>
#include <sstream>
#include <numeric>
#include <cctype>
#include <bitset>
#include <cassert>
#include <random>
#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 gep(i,g,j) for(int i = g.head[j]; i != -1; i = g.e[i].next)
#define each(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++)
#define rng(a) a.begin(),a.end()
#define maxs(x,y) x = max(x,y)
#define mins(x,y) x = min(x,y)
#define pb push_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcount
#define uni(x) x.erase(unique(rng(x)),x.end())
#define snuke srand((unsigned)clock()+(unsigned)time(NULL));
#define df(x) int x = in()
#define dame { puts("-1"); return 0;}
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,vector<T>,greater<T> >
#define bn(x) ((1<<x)-1)
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
inline int in() { int x; scanf("%d",&x); return x;}
inline void priv(vi a) { rep(i,sz(a)) printf("%d%c",a[i],i==sz(a)-1?'\n':' ');}
template<typename T>istream& operator>>(istream&i,vector<T>&v)
{rep(j,sz(v))i>>v[j];return i;}
template<typename T>string join(vector<T>&v)
{stringstream s;rep(i,sz(v))s<<' '<<v[i];return s.str().substr(1);}
template<typename T>ostream& operator<<(ostream&o,vector<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,pair<T1,T2>&v)
{return o<<v.fi<<","<<v.se;}
const int MX = 100005, INF = 1001001001;
const ll LINF = 1e18;
const double eps = 1e-10;



int main() {
  vi x(7);
  cin >> x;
  ll ans = 0;
  {
    ll a = x[3], b = x[4], c = x[0];
    rep(ai,2)rep(bi,2)rep(ci,2) {
      if (ai && !a) continue;
      if (bi && !b) continue;
      if (ci && !c) continue;
      ll now = 0;
      now += (a-ai)/2;
      now += (b-bi)/2;
      now += (c-ci)/2;
      now *= 2;
      if (ai && bi && ci) now += 3;
      maxs(ans,now);
    }
  }
  ans += x[1];
  cout<<ans<<endl;
  return 0;
}































Measured memory_bytes: 256
Scanf.scanf "%d" (fun n ->
    let a = Array.init n (fun _ -> Scanf.scanf " %d" (fun a -> a)) in
    let rec loop i expect acc =
        if i = 0 then (if expect = 0 && a.(i) = 0 then acc else -1) else
            if a.(i) < expect then -1 else
                loop (i - 1) (max 0 (a.(i) - 1)) (if expect = a.(i) then acc else acc + a.(i))
    in
    loop (n - 1) 0 0 |> Printf.printf "%d\n"
)

Measured memory_bytes: 7548
#include <iostream>
#include <iomanip>
#include <vector>
#include <utility>
#include <map>
#include <algorithm>
#include <queue>
#include <cmath>
#include <numeric>
#include <set>

using namespace std;
struct aaa{aaa(){cin.tie(nullptr); ios::sync_with_stdio(false); cout<<fixed<<setprecision(20);};}aaa;
template <class T>ostream &operator<<(ostream &o,const vector<T>&v){o<<"{";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")<<v[i];o<<"}";return o;}
#define debug(v) {cerr<<"\033[1;36m[debug]\033[m "<<#v<<" : "<<v<<endl;}

using int64 = long long;

int main() {
    int64 x,k,d;
    cin >> x >> k >> d;
    x = abs(x);
    int64 t = x / d;
    t = min(k, t);
    k -= t;
    x -= t * d;

    if (k%2) {
        cout << min(abs(x+d), abs(x-d)) << endl;
    } else {
        cout << x << endl;
    }
}

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

using namespace std;

#define rep(i, n) for(int i=0; i<(n); ++i)
const int dx[] = {-1, -1, 0, 1, 1, 1, 0, -1}, dy[] = {0, -1, -1, -1, 0, 1, 1, 1};

int w, h;
vector<vector<int> > c;

inline bool inrect(int x, int y){
    return 0 <= x && x < h && 0 <= y && y < w;
}

void visit(int x, int y){
    rep(k, 8){
        int nx = x + dx[k], ny = y + dy[k];
        if(!inrect(nx, ny) || !c[nx][ny])continue;
        c[nx][ny] = 0;
        visit(nx, ny);
    }
}

int solve(){
    int res = 0;
    rep(i, h)rep(j, w)if(c[i][j])visit(i, j), res++;
    return res;
}

int main(){
  while(cin >> w >> h, w|h){
      c.assign(h, vector<int>(w, 0));
      rep(i, h)rep(j, w)cin >> c[i][j];
      cout << solve() << '\n';
  }
  return 0;
}

Measured memory_bytes: 1300
#include <iostream>
#include <cmath>
using namespace std;
const int N_MAX = 200;
int main (void) {
    int n;
    int a[N_MAX];
    int ans = 0;

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

    while (true) {
        for (int i = 0; i < n; i++) {
            if (a[i] % (int)pow(2, ans) != 0) {
                cout << ans - 1 << endl;
                return 0;
            }
        }
        ans++;
    }

    return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
using ll = long long;
using P = pair<int,int>;
ll dist1[330][330],dist2[330][330];
const ll LINF = 1001001001001001ll;
vector<ll> ans;
int n,m;
ll l;
int main()
{
    cin >> n >> m >> l;
    rep(i,n)rep(j,n){
        dist1[i][j] = LINF;
        dist2[i][j] = LINF;
    }
    rep(i,m){
        int a,b;
        ll c;
        cin >> a >> b >> c;
        a--;b--;
        dist1[a][b] = dist1[b][a] = c;
    }
   
    rep(i,n)rep(j,n)rep(k,n)dist1[j][k] = min(dist1[j][k],dist1[j][i]+dist1[i][k]);
    rep(i,n)rep(j,n)if(dist1[i][j] <= l)dist2[i][j] = dist2[j][i] = 1;
    rep(i,n)rep(j,n)rep(k,n)dist2[j][k] = min(dist2[j][k],dist2[j][i]+dist2[i][k]);
    int q;cin >> q;
    rep(i,q){
        int s,t;
        cin >> s >> t;
        s--;t--;
        if(dist2[s][t] == LINF)ans.push_back(-1);
        else ans.push_back(dist2[s][t]);
    }
    for(auto p:ans){
        if( p == -1)cout << p << endl;
        else cout << p-1 << endl;
    }


 

    return 0;
}

Measured memory_bytes: 2936
#include <bits/stdc++.h>
using namespace std;
#define ll long long 
#define endl "\n"
#define pb push_back
#define f(i,n) for(i=0;i<n;i++)
#define F(i,a,b) for(i=a;a<=b;i++)
#define arr(a,n) for( i=0;i<n;i++)cin>>a[i];
#define fi first
#define se second
#define mp make_pair
#define mod 1000000007
#define YES cout<<"YES"<<endl;
#define Yes cout<<"Yes"<<endl;
#define NO cout<<"NO"<<endl;
#define No cout<<"No"<<endl;
#define yes cout<<"yes"<<endl;
#define no cout<<"no"<<endl;
#define vi vector<ll>
#define ed end()
#define bg begin()
#define sz size()
#define ln length()
#define s() sort(a,a+n);
#define sr() sort(a,a+n,greater<ll>());
#define v()  sort(v.begin(),v.end());
#define vr() sort(v.begin(),v.end(),greater<ll>());
#define mod 1000000007
#define fast() ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
ll gcd(ll a, ll b){if(!b)return a;return gcd(b, a % b);}
ll power(ll x,ll y,ll p){ll res=1;x%=p;while(y>0){if(y&1)res=(res*x)%p;y=y>>1;x=(x*x)%p;}return res;}
int main() {
   /* #ifndef ONLINE_JUDGE
        // for getting input from input.txt
        freopen("input.txt", "r", stdin);
        // for writing output to output.txt
        freopen("output.txt", "w", stdout);
    #endif*/
        

fast();
//ll t;cin>>t;while(t--)
{
   ll n,m,c=0;
   cin>>n>>m;
   char a[n][m];
   for(int i=0;i<n;i++)
    {
      for(int j=0;j<m;j++)
      {
        cin>>a[i][j];
        if(a[i][j]=='#')
          c++;
      }
    } 
    if(c==n+m-1)
      cout<<"Possible"<<endl;
    else
      cout<<"Impossible"<<endl;
}
return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

int A[100000],n;

int Binary( int key ){
  int left = 0;
  int right = n;
  int mid;
  while( left < right ){
    mid = ( left + right )/2;
    if( key == A[mid] ){
      return 1;
    }
    else if(key > A[mid] ){
      left = mid + 1;
    }
    else {
      right =mid;
    }
  }
  return 0;
}

int main(void){

  int i,q,m,sum=0;
  scanf("%d",&n);
  for( i = 0 ; i < n ; i++){
    scanf("%d",&A[i]);
  }
  scanf("%d",&q);
  for( i = 0 ; i < q ; i++){
    scanf("%d",&m);
    if( Binary(m)){
      sum++;
    }
  }
  printf("%d\n",sum);
 
 return 0;
}

Measured memory_bytes: 988
#define _USE_MATH_DEFINES
#include<iostream>
#include<string>
#include<queue>
#include<cmath>
#include<map>
#include<set>
#include<list>
#include<iomanip>
#include<vector>
#include<random>
#include<functional>
#include<algorithm>
#include<stack>
#include<cstdio>
#include<cstring>
#include<bitset>
#include<unordered_map>
#include<climits>
#include<fstream>
#include<time.h>
#include<cassert>

using namespace std;
typedef long long ll;
typedef long double ld;
#define all(a) (a).begin(),(a).end()
#define EPS (1e-13)
#define bit(n,k) ((n>>k)&1)
const ll Mod = 1e9 + 7;
const ll mod = 998244353;
struct H {
	ll x, y;
	bool operator<(const H& b) const {
		if (x != b.x) return x < b.x;
		return y < b.y;
	}
	bool operator>(const H& b) const {
		if (x != b.x) return x > b.x;
		return y > b.y;
	}
	bool operator==(const H& b) const { return x == b.x && y == b.y; }
	bool operator!=(const H& b) const { return (*this) != b; }
};
struct P {
	ll pos, cost;
	bool operator<(const P& b) const { return cost < b.cost; }
	bool operator>(const P& b) const { return cost > b.cost; }
};
struct B {
	ll to, cost;
};
struct E {
	ll from, to, cost;
	bool operator<(const E& b) const { return cost < b.cost; }
	bool operator>(const E& b) const { return cost > b.cost; }
};
template<typename T, typename U>
void chmin(T& a, U b) {
	if (a > b) a = b;
}
template<typename T, typename U>
void chmax(T& a, U b) {
	if (a < b) a = b;
}
template<typename T>
T max_0(T a) {
	if (a < 0) return 0;
	return a;
}
template<typename T>
T min_0(T a) {
	if (a > 0) return 0;
	return a;
}
ll read() {
	ll u;
	ll k = scanf("%lld", &u);
	return u;
}
ll gcd(ll i, ll j) {
	if (i > j) swap(i, j);
	if (i == 0) return j;
	return gcd(j % i, i);
}
ll mod_pow(ll x, ll n, ll p) {
	ll res = 1;
	while (n > 0) {
		if (n & 1) res = res * x % p;
		x = x * x % p;
		n >>= 1;
	}
	return res;
}//x^n%p
ll bitcount(ll x) {
	int sum = 0;
	for (int i = 0; i < 20; i++)
		if ((1ll << i) & x) sum++;
	return sum;
}
/*ll fact_[200000];
ll comb(ll x, ll y, ll mod = Mod) {
	if (!fact_[0]) {
		fact_[0] = 1;
		for (int i = 1; i < 200000; i++) {
			fact_[i] = fact_[i - 1] * i % mod;
		}
	}
	if (x < y) return 0;
	return mod_pow(fact_[x], mod, mod) *
		mod_pow(fact_[x - y], mod - 2, mod) % mod *
		mod_pow(fact_[y], mod - 2, mod) % mod;
}//xCy*/
const ll Inf = 3023372036854775807;
const int inf = 1500000000;
#define int long long
//----------------------------------------------------
int n;
signed main() {
	cin >> n;
	ld sum = 0, x;
	for (int i = 0; i < n; i++) {
		cin >> x;
		sum += 1 / x;
	}
	printf("%.20LF\n", 1 / sum);
}

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

int main(){
    int n[4];
    cin>>n[0]>>n[1]>>n[2]>>n[3];
    sort(n,n+4);
    if(n[0]==1&&n[1]==4&&n[2]==7&&n[3]==9)puts("YES");
    else puts("NO");
    return 0;
}

Measured memory_bytes: 256