akhauriyash/Code-Regression huggingface dataset:
height, width = map(int, input().split(" "))
grids = list()
grids_accessed = list()
whites = 0
for h in range(height):
    inputted = input()
    whites += inputted.count(".")
    grids.append(list(inputted))
    grids_accessed.append([False]*len(inputted))


def get_next(x, y):
    nexts = ((x-1, y),
             (x+1, y),
             (x, y-1),
             (x, y+1))
    for x, y in nexts:
        if (0 <= x <= width-1) and (0 <= y <= height-1):
            if grids[y][x] == ".":
                yield x, y


def dfs():
    queue = list()
    x, y = 0, 0
    queue.append((x, y))
    while True:
        try:
            x, y = queue.pop(0)
        except IndexError:
            return
        if x == width-1 and y == height-1:
            return
        for n_x, n_y in get_next(x, y):
            if grids_accessed[n_y][n_x] is False:
                grids_accessed[n_y][n_x] = (x, y)
                queue.append((n_x, n_y))


def get_shortest():
    x, y = width-1, height-1
    distance_traveled = 0
    while True:
        if x == 0 and y == 0:
            return distance_traveled
        else:
            x, y = grids_accessed[y][x]
            distance_traveled += 1


dfs()
if grids_accessed[height-1][width-1] is False:
    print(-1)
else:
    d = get_shortest() + 1
    score = whites - d
    if score < 0:
        score = -1
    print(score)


Measured memory_bytes: 3188
#include <algorithm>
#include <cassert>
#include <climits>
#include <cmath>
#include <iostream>
#include <map>
#include <queue>
#include <string>
#include <vector>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef pair<int, int> ipair;
typedef pair<ll, ll> lpair;
typedef tuple<int, int, int> ituple;

// const int INF = INT_MAX;
// const ll INF = LLONG_MAX;
// const int MOD = ((int)1e9 + 7);
// const ld EPS = (1e-10);
#define PI acosl(-1)
#define MAX_N (200000 + 2)
int n, a[MAX_N];
int firstVisited[MAX_N];
ll k;

void exec(){
  cin >> n >> k;
  for (int i = 0; i < n; i++){
    scanf("%d", &a[i]);
  }


  int ans = 0, i = 1, current = 1;
  firstVisited[1] = i;
  bool isFindLoop = false;
  while (true){
    if (k <= 0) {
      ans = current;
      break;
    }

    k--;
    i++;
    current = a[current - 1];
    // printf("loop %d: current = %d, k = %lld\n", i, current, k);

    if (!isFindLoop && firstVisited[current]) {
      ll loop = i - firstVisited[current];
      if (loop > 0) {
        // printf("loop = %lld, k = %lld\n", loop, k);
        k %= loop;
        // printf("after k = %lld\n", k);
      }

      isFindLoop = true;
    }

    firstVisited[current] = i;
  }

  cout << ans << endl;

}

void solve(){
  int t = 1;
  // scanf("%d", &t);
  for (int i = 0; i < t; i++){
    exec();
  }
}

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


Measured memory_bytes: 5220
#include <bits/stdc++.h>
#define int long long
using namespace std;
int n,ans[120000],one,two;
struct node {int num,at;} sxd[120000];
bool cmp(node a,node b) {return (a.num==b.num)?a.at<b.at:a.num>b.num;}
signed main() {
	cin>>n;
	for(int i=1;i<=n;i++) {cin>>sxd[i].num;sxd[i].at=i;}
	sort(sxd+1,sxd+n+1,cmp);
	one=1,two=2;
	while(two<=n) {
		while(sxd[two].num==sxd[two-1].num) two++;
		ans[sxd[one].at]+=(two-1)*(sxd[one].num-sxd[two].num);
		if(sxd[one].at<sxd[two].at) sxd[one].num=sxd[two].num;
		else one=two;
		two++;
	}
	ans[sxd[one].at]+=sxd[one].num*n;
	for(int i=1;i<=n;i++) {cout<<ans[i];puts("");}
	return 0;	
}

Measured memory_bytes: 3456
/**
 *   created: 02 August 2020 (Sunday)  17:29:11
**/
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define INF 1e18
#define int long double

void solve(){
	int n,d; cin>>n>>d;
	int c=0;
	for(int i=0;i<n;i++)
	{
		int x,y; cin>>x>>y;
		if(x*x+y*y<=d*d)
			c++;
	}
	cout<<c;
}

signed main(){
    ios_base::sync_with_stdio(false); 
    cin.tie(NULL); 
    int t=1; while(t--) solve();
    return 0;
}

Measured memory_bytes: 3812
#include<stdio.h>
#include<algorithm>
using namespace std;
int v[2000];
int tmp[2000];
int main(){
	int a,b,c;
	while(scanf("%d%d%d",&a,&b,&c),a+b+c){
		b=b/100*60+b%100;
		c=c/100*60+c%100;
		int n=a;
		for(int i=0;i<2000;i++)v[i]=0;
		for(int i=0;i<n;i++){
			int m;scanf("%d",&m);
			for(int j=0;j<2000;j++)tmp[j]=0;
			for(int j=0;j<m;j++){
				int p,q;scanf("%d%d",&p,&q);
				p=p/100*60+p%100;
				q=q/100*60+q%100;
				for(int k=p;k<q;k++)tmp[k]=1;
			}
			for(int j=0;j<2000;j++)if(!tmp[j])v[j]=1;
		}
		int ret=0;
		int now=0;
		for(int i=b;i<c;i++){
			if(!v[i])now=0;
			else now++;
			ret=max(ret,now);
		}
		printf("%d\n",ret);
	}
}

Measured memory_bytes: 1044
#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<set>
#include<bitset>
#include<map>

#define fo(i,a,b) for(int i=a;i<=b;i++)
#define fd(i,a,b) for(int i=a;i>=b;i--)

using namespace std;

typedef long long LL;
typedef double db;

int get(){
	char ch;
	while(ch=getchar(),(ch<'0'||ch>'9')&&ch!='-');
	if (ch=='-'){
		int s=0;
		while(ch=getchar(),ch>='0'&&ch<='9')s=s*10+ch-'0';
		return -s;
	}
	int s=ch-'0';
	while(ch=getchar(),ch>='0'&&ch<='9')s=s*10+ch-'0';
	return s;
}

const int N = 205;
const int L = 1e+7+10;

int n;
int b[L];
int a[N];
int pri[L],m;
bool bz[L];
int X[N],Y[N],kx,ky;
int fa[N],e[N][N];
int vis[N],tim;

bool can(int x){
	if (vis[x]==tim)return 0;
	vis[x]=tim;
	fo(i,1,e[x][0]){
		int y=e[x][i];
		if (!fa[y]||can(fa[y])){
			fa[y]=x;
			return 1;
		}
	}
	return 0;
}

int main(){
	n=get();
	fo(i,1,n){
		int x=get();
		b[x-1]^=1;b[x]^=1;
	}
	int k=0;
	fo(i,0,1e+7)
	if (b[i])a[++k]=i;
	fo(i,2,1e+7){
		if (!bz[i])pri[++m]=i;
		fo(j,1,m){
			if (1ll*i*pri[j]>1e+7)break;
			bz[i*pri[j]]=1;
			if (i%pri[j]==0)break;
		}
	}
	bz[1]=bz[2]=1;
	fo(i,1,k)
	if (a[i]&1)X[++kx]=a[i];else Y[++ky]=a[i];
	fo(i,1,kx)
		fo(j,1,ky)
		if (!bz[abs(X[i]-Y[j])])e[i][++e[i][0]]=j;
	int cnt=0;
	fo(i,1,kx){
		tim++;
		if (can(i))cnt++;
	}
	int ans=cnt+((kx-cnt)/2+(ky-cnt)/2)*2+((kx-cnt)%2)*3;
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 55424
N, M = map(int, input().split())
listA=[] #appendのために宣言が必要

for i in range(N):
    listA.append(list(map(int,input().split())))
listA.sort()
#print(listA)

cans = 0
money = 0
j = 0
while cans < M:
    cans += listA[j][1]
    money += listA[j][0]*listA[j][1]
    j += 1

print(money-(cans-M)*listA[j-1][0])




Measured memory_bytes: 27760
#include <iostream>
#include <vector>
#include <queue>
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"

#define MAXH 1000

using namespace std;

signed main() {
  IOS;
  int H,W,i=0,j,ans=0,whites=0;
  cin >> H >> W;
  char A[H][W];
  queue<pair<pair<int,int>,int>> blacks;
  bool visited[MAXH][MAXH] = {false};
  for (i = 0; i < H; i++) {
    for (j = 0; j < W; j++) {
      cin >> A[i][j];
      if (A[i][j] == '#') {
        blacks.push({{i, j},1});
      } else {
        whites++;
      }
    }
  }

  int deltaR[4] = {0,0,1,-1};
  int deltaC[4] = {1,-1,0,0};
  while (!blacks.empty()) {
    auto b = blacks.front();
    blacks.pop();
    for (i = 0; i < 4; i++) {
      int r = b.first.first + deltaR[i];
      int c = b.first.second + deltaC[i];
      if (r>=0 and r<H and c>=0 and c<W and A[r][c]=='.' && !visited[r][c]) {
        visited[r][c] = true;
        whites--;
        ans = max(ans, b.second);
        blacks.push({{r,c}, b.second+1});
      }
    }
  }

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


Measured memory_bytes: 14352
#define ENABLE_DEBUG 1
// Kana's kitchen {{{
#include<bits/stdc++.h>
#define ALL(v) std::begin(v),std::end(v)
#define LOOP(k) for(i64 ngtkana_is_a_genius=0; ngtkana_is_a_genius<(i64)k; ngtkana_is_a_genius++)

using i32 = std::int_least32_t;
using i64 = std::int_least64_t;
using u32 = std::uint_least32_t;
using u64 = std::uint_least64_t;
using usize = std::size_t;

template <class T, class U> using pair = std::pair<U, T>;
template <class T> using diag_pair = std::pair<T, T>;
template <class... Args> using tuple = std::tuple<Args...>;
template <class T> using vec = std::vector<T>;
template <class T> using numr = std::numeric_limits<T>;

#ifdef NGTKANA
#include<debug.hpp>
#else
#define DEBUG(...)(void)0
#endif
/*}}}*/

int main() {
    std::cin.tie(nullptr);
    std::ios::sync_with_stdio(false);
    std::cout << std::setprecision(15) << std::fixed;

    usize h, w;
    std::cin >> h >> w;
    for (usize i=0; i<h+2; i++) {
        for (usize j=0; j<w+2; j++) {
            char c;
            if (i==0||i==h+1||j==0||j==w+1) c = '#';
            else std::cin >> c;
            std::cout << c;
        }
        std::cout << '\n';
    }
}


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

using namespace std;

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

const long long MOD = 1e9 + 7;
const int INF = 1e9;

int main() {
  int N;
  cin >> N;
  vector<int> C(N - 1), S(N - 1), F(N - 1);
  for (int i = 0; i < N - 1; ++i) cin >> C[i] >> S[i] >> F[i];
  for (int i = 0; i < N; ++i) {
    int time = 0;
    int pos = i;
    while (pos < N - 1) {
      if (time >= S[pos] && time % F[pos] == 0) {
        time += C[pos];
        pos++;
      }
      else time++;
    }
    cout << time << endl;
  }
}

Measured memory_bytes: 256
#include <iostream>
#include <queue>
#include <utility>
#define rep2(x,from,to) for(int x=(from);(x)<(to);(x)++)
#define rep(x,to) rep2(x,0,to)
#define pint pair<int,int>
using namespace std;
int main(){
	int dx[4] = {-1,0,1,0};
	int dy[4] = {0,1,0,-1};
	int w,h,xs,ys,xg,yg,n;
	while(cin >> w >> h && (w || h)) {
		cin >> xs >> ys >> xg >> yg >> n;
		int b[110][110] = {};
		int	c,d,x,y;
		rep(i,n) {
			cin >> c >> d >> x >> y;
			rep(j,2) {
				rep(k,4) {
					if(d==0) b[y+j][x+k] = c;
					else b[y+k][x+j] = c;
				}
			}
		}
		if(b[ys][xs] != b[yg][xg] || b[ys][xs] == 0) {
			cout << "NG" << endl;
			continue;
		}
		queue<pint> q;
		pint p;
		p.first = ys, p.second = xs;
		q.push(p);
		const int b_color = b[ys][xs];
		bool f = 0;
		while(!q.empty()) {
			pint a = q.front(); q.pop();
			b[a.first][a.second] = 0;
			if(a.first == yg && a.second == xg) {
				f = 1;
				break;
			}
			rep(i,4) {
				if(b[a.first+dy[i]][a.second+dx[i]] == b_color) {
					pint e;
					e.first = a.first+dy[i], e.second = a.second+dx[i];
					q.push(e);
				}
			}
		}
		if(f) cout << "OK" << endl;
		else cout << "NG" << endl;
	}
}

Measured memory_bytes: 1364
import std.stdio, std.conv, std.functional, std.string;
import std.algorithm, std.array, std.container, std.range, std.typecons;
import std.numeric, std.math, std.random;
import core.bitop;

string FMT_F = "%.10f";

static string[] s_rd;
T RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
string RDR()() { return readln.chomp; }
T[] ARR(T = long)(in string str, T fix = 0) { auto r = str.split.to!(T[]); r[] += fix; return r; }
size_t[] MAKE_IDX(alias less = "a < b", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}
size_t MIN_POS(alias less = "a < b", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }

bool inside(T)(T x, T b, T e) { return x >= b && x < e; }
long lcm(long x, long y) { return x * y / gcd(x, y); }

long mod = 10^^9 + 7;
//long mod = 998244353;
//long mod = 1_000_003;
void moda(ref long x, long y) { x = (x + y) % mod; }
void mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }
void modm(ref long x, long y) { x = (x * y) % mod; }

void main()
{
	auto N = RD;
	auto K = RD;

	auto big = (N - 1) * (N - 2) / 2;
	if (K > big)
	{
		writeln(-1);
	}
	else
	{
		auto edges = new bool[][](N, N);
		auto diff = K;
		long m = N * (N-1) / 2 - diff;
		foreach (i; 0..N)
		{
			foreach (j; i+1..N-1)
			{
				if (diff == 0) break;
				edges[i][j] = true;
				--diff;
			}
		}
		writeln(m);
		foreach (i; 0..N)
		{
			foreach (j; i+1..N)
			{
				if (edges[i][j]) continue;
				writeln(i+1, " ", j+1);
			}
		}
	}

	stdout.flush();
	debug readln();
}

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

#define fi first
#define se second
#define be begin
#define en end
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define ALL(a) (a).be() , (a).en()
#define REP(i,n) for(int (i)=0;(i)<(n);(i)++)        //repeat n times
#define REP2(i,s,n) for(int (i)=(s);(i)<(n);(i)++)   //repeat from s to n 
#define REPD(i,n) for(int (i)=(n);(i)>=0;(i)--)      //repeat from n to 0
#define REPD2(i,s,e) for(int (i)=(s);(i)>=(e);(i)--) //repeat from s to e
#define RANGE(i,v) for(auto &(i):v)                  //repeat range
#define ASIZE(a) (sizeof(a) / sizeof(a[0]))          //array size

using LL = long long;


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

    REP(i,9){
        if(N<=111*(i+1)){
            cout<<111*(i+1)<<endl;
            return 0;
        }
    }

    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

class Main { 
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int N = in.nextInt();
        int count = 0;
        int borderline = 1000;
        
        boolean primes[] = new boolean [borderline];
        for(int n = 2; n < primes.length; n++){
            if(primes[n]) continue;
            for(int m = 2 * n; m < primes.length; m += n) {
                primes[m] = true;
            }
        }
        
        while (N != 0) {
            int num = in.nextInt();
            if       ((num >  borderline) && isPrime(num)) count++;
            else  if ((num <= borderline) && !primes[num]) count++;
            N--;
        }
        
        System.out.println(count);
    }
    
    public static boolean isPrime(int x) {
        if      (x == 2)     return true;
        else if (x % 2 == 0) return false;
        else {
            for (int i = 3; i * i <= x; i += 2) {
                if (x % i == 0) return false;
            }
            return true;
        }
    }
}

Measured memory_bytes: 29364
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>

using namespace std;

#define ll long long

template<typename T> void drop(const T &x){cout<<x<<endl;exit(0);}

signed main() {
  ll x,k,d;
  cin >> x >> k >> d;
  x=abs(x);
  if(((__int128_t)k)*((__int128_t)d)<=(__int128_t)x) drop(x-k*d);

  ll a = x/d;
  x-=a*d;
  k-=a;
  k%=2;
  if(k) x=abs(x-d);
  drop(x);

  return 0;
}


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

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

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

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

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

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

    ($next:expr, [ $t:tt ]) => {
        {
            let len = read_value!($next, usize);
            (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")
    };
}

use std::cmp::{max, min};

fn main() {
    input!{
        n: usize,
        s: chars,
        es: [(usize1, usize1); n - 1]
    }
    let mut t = vec![vec![]; n];
    for (u, v) in es {
        t[u].push(v);
        t[v].push(u);
    }
    let mut ans = usize::max_value();
    for i in 0..n {
        let (x, d, _) = dfs(i, i, &t, &s);
        if d == 0 {
            ans = min(ans, x);
        }
    }
    if ans == usize::max_value() {
        println!("-1");
    } else {
        println!("{}", ans);
    }
}

fn dfs(r: usize, p: usize, t: &Vec<Vec<usize>>, s: &Vec<char>) -> (usize, usize, usize) {
    let mut n = 0;
    let mut sum = 0;
    let mut m = 0;
    let mut v = s[r].to_digit(10u32).unwrap() as usize;
    for c in t[r].clone() {
        if c == p {
            continue;
        }
        let cs = dfs(c, r, t, s);
        n += cs.0;
        sum += cs.1 + cs.2;
        m = max(m, cs.0 + cs.1 + cs.2);
        v += cs.2;
    }
    if 2 * m >= sum + 2 * n {
        (2 * n + sum - m, 2 * m - sum - 2 * n, v)
    } else {
        (n + sum / 2, sum % 2, v)
    }
}


Measured memory_bytes: 4604
/*
LANG:C++
PROB:

*/
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <functional>
#include <iostream>
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ford(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)


using namespace __gnu_pbds;
using namespace std;


typedef tree<int, null_type, less<int>, rb_tree_tag,
            tree_order_statistics_node_update>
    ordered_set;

typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpi;
typedef vector<vi> vvi;
typedef long long i64;
typedef vector<i64> vi64;
typedef vector<vi64> vvi64;
typedef pair<i64, i64> pi64;
typedef double ld;
typedef unsigned long long ui64;

template<class T> bool uin(T &a, T b) { return a > b ? (a = b, true) : false; }
template<class T> bool uax(T &a, T b) { return a < b ? (a = b, true) : false; }
i64 calc(i64 i)
{
  if(i&1)
  return 3*i+1;
  else
  return i/2;
}
map<i64,bool>mpp;

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

    // ifstream fin(".in");
    // ofstream fout(".in");

i64  a;
cin>>a;

i64 i=1;
while(!mpp[a])
{i++;
  mpp[a]=true;
  a=calc(a);
  // cout<<a<<" "<<endl;
}
cout<<i;
    return 0;
  }


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(ll i=0;i<(n);i++)
#define rrep(i,n) for(ll i=(n)-1;i>=0;i--)
template<typename T =ll> using v = vector<T>;
template<typename T =ll> using vv = v<v<ll>>;
template<typename T=ll,typename U=ll> using p = pair<T,U>;
template<typename T> T chmin(T &a,T b) {return a=min(a,b);}
template<typename T> T chmax(T &a,T b) {return a=max(a,b);}
const ll INF = (ll)1e9;

void a(){
    string s; cin >> s;
    if(s.find("A")==string::npos){
        cout << "No";
    }else if(s.find("B")==string::npos){
        cout << "No";
    }else{
        cout << "Yes";
    }
}


void b(){
    ll n,a,b; cin >> n >> a >> b;
    ll amari = n%(a+b);
    ll count = n/(a+b);
    ll counta=0;
    ll countb=0;
    if(amari<=a){
        counta = amari;  
    }else{
        counta = a;
        countb = amari-a;
    }
    counta += a*count;
    countb += b*count;
    cout << counta;

}

void c(){
    ll a,b; cin >> a >> b;
    ll n = 1000;
    ll ans =0;
    bool f=false;
    rep(i,n+1){
        if(floor(i*0.08) == a&&floor(i*0.1)==b){
            ans=i;
            f=true;
            break;
        }
    }
    cout << (f?ans:-1);

}

void d(){
    string s;
    ll q;
    cin >> s >> q;
    auto query = v<string>();
    rep(i,q+1){
        string t;
        getline(cin,t);
        query.push_back(t);
    }

    bool front = true;
    deque<char> ans;

    rep(i,s.size()) {
        ans.push_back(s[i]);
    }

    for(ll i=1;i<=q;i++){
        if(query[i].front()=='1'){
            front=front?false:true;
        }else{
            if(front){
                if(query[i].find("1",2,1)!=string::npos){
                    ans.push_front(query[i].back());
                }else{
                    ans.push_back(query[i].back());
                }
            }else{
                if(query[i].find("1",2,1)!=string::npos){
                    ans.push_back(query[i].back());
                }else{
                    ans.push_front(query[i].back());
                }
            }
        }
    }

    if(front)rep(i,ans.size())cout <<ans[i];
    else rrep(i,ans.size()) cout << ans[i];
    
}

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


Measured memory_bytes: 11888
#include <iostream>
#include <iomanip>
#include <string>
#include <string.h>
#include <math.h>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <algorithm>
#include <utility>
#include <deque>
#include <queue>
#include <functional>

#define rep(i, n) for(int i = 0; i < n; ++i)
#define REP(i, m, n) for(int i = m; i < n; ++i)
#define rrep(i,n) for(int i = n; i >= 0; --i)
#define RREP(i, m, n) for(int i = n; i >= m; --i)
#define llrep(i, n) for(ll i = 0; i < n; ++i)
#define llREP(i, m, n) for(ll i = m; i < n; ++i)
#define llrrep(i,n) for(ll i = n; i >= 0; --i)
#define llRREP(i, m, n) for(ll i = n; i >= m; --i)

using ll = long long;
using ull = unsigned long long;
using pii = std::pair<int, int>;
using pll = std::pair<long long, long long>;
using pli = std::pair<long long, int>;
using plpii = std::pair<long long, std::pair<int, int>>;
using pdd = std::pair<double, double>;

using namespace std;

const long long _MOD = 1000000007;
const long long MOD = 998244353;
const int ALPHABET = 27;
const double pi = 3.14159265358979;

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

	string s;
	cin >> s;

	int ans = 0;
	int counter = s.length() - 1;
	for (int i = 0; i < counter; ++i) {
		if (s[i] != s[counter]) {
			if (s[i] == 'x') {
				++ans;
			}
			else if (s[counter] == 'x') {
				--i;
				--counter;
				++ans;
			}
			else {
				cout << "-1" << "\n";
				return 0;
			}
		}
		else {
			--counter;
		}
	}

	cout << ans << "\n";

	return 0;
}



Measured memory_bytes: 512
import sys

def f(n):
    if n & 1:
        return n * 3 + 1
    else:
        return n // 2

s = int(sys.stdin.readline().rstrip())

def main():
    a_m = set([1, 2, 4])
    a = s
    for i in range(1, 10**6-2):
        if a in a_m:
            return i + 3
        a = f(a)

if __name__ == '__main__':
    ans = main()
    print(ans)

Measured memory_bytes: 3060
#include <stdio.h>
 
int main() {
	int l, r, d;
	
	scanf("%d %d %d", &l, &r, &d);
	
	int count = 0;
	for (int i = l; i <= r; i++) {
		if (i % d == 0) {
			count++;
		}
	}
	
	printf("%d\n", count);
	
	return 0;
}

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

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vint;
typedef vector<double> vdbl;
typedef vector<ll> vll;
typedef vector<string> vstr;
typedef vector<vector<int> > vvint;
typedef vector<pair<int, int> > vpii;
typedef vector<pair<ll, ll> > vpll;
typedef priority_queue<int, vector<int>, greater<int> > spqint; //小さい順に取り出し
typedef priority_queue<ll, vector<ll>, greater<ll> > spqll;     //小さい順に取り出し
typedef priority_queue<int, vector<int>, less<int> > bpqint;    //大きい順に取り出し
typedef priority_queue<ll, vector<ll>, less<ll> > bpqll;        //大きい順に取り出し

#define REP(i, n) for (int(i) = 0; (i) < (int)(n); i++)
#define FOR(i, a, b) for (int(i) = a; (i) < (int)b; i++)
#define IREP(i, v) for (auto i = v.begin(); i != v.end(); i++)
#define MOD 1000000007
#define NIL -1
#define FI first
#define SE second
#define MP make_pair
#define PB push_back
#define PF push_front
#define TS to_string
#define BS binary_search
#define LB lower_bound
#define UB upper_bound
#define NP next_permutation
#define ALL(v) (v).begin(), (v).end()
#define SZ(x) (ll) x.size()
#define SP(x) setprecision((ll)x)

const int INF = 1e9;
const ll LINF = 1e18;
const double EPS = 1e-9;
const double PI = M_PI;
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; } //最大公約数
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }     //最小公倍数

void yes()
{
    cout << "Yes" << endl;
}
void no()
{
    cout << "No" << endl;
}
//-----------------------------------------

//-----------------------------------------
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n ;
    cin >> n ;
    vll a(n) ;
    REP(i,n){
        cin >> a[i] ;
    }
    vll b(n) ;
    for(ll i=0;i<n;i++){
        b[i] = a[i] + (i + 1);
    }
    sort(ALL(b)) ;

    ll ans = 0 ;

    for(ll i=0;i<n;i++){
        ll key = (i+1) - a[i]  ;
        auto itr1 = UB(ALL(b),key) ;
        auto itr2 = LB(ALL(b),key) ;
        if(itr1==b.end() || itr2==b.end()){
            continue ;
        }
        ll d1 = distance(b.begin(),itr1) ;
        ll d2 = distance(b.begin(),itr2) ;
        ans += (d1-d2) ;
    }

    cout <<ans <<endl; 


    

    return 0;
}


Measured memory_bytes: 6340
#ifdef _DEBUG
#include "MyLib.h"
#else
#define main_A main
#include "bits/stdc++.h" 
#include <regex>
#define _USE_MATH_DEFINES
#include <math.h>
#define FOR(i,s,e) for (int i = int(s); i < int(e); ++i)
#define REP(i,e) FOR(i,0,e)
#define INF (INT_MAX/2)
#define EPS (1.0e-8)
#define LINF (LONG_MAX/2)
const int MGN = 8;
const int ARY_SZ_MAX = 10000000;
using namespace std;
using ll = long long; using ull = unsigned long long;
using vi = vector<int>; using vvi = vector<vi>; using vvvi = vector<vvi>;
using vb = vector<bool>; using vvb = vector<vb>; using vvvb = vector<vvb>;
using vl = vector<ll>; using vvl = vector<vl>;
using vd = vector<double>; using vs = vector<string>;
using pii = pair<int, int>; using pll = pair<ll, ll>;
#endif

#ifdef _DEBUG
void init_global_A() {}
#else

#endif

int main_A() {
    cin.tie(0);
    ios::sync_with_stdio(false);
     
    string X, Y; cin >> X >> Y;

    string ans;
    if (X < Y) ans = "<";
    else if (X > Y) ans = ">";
    else ans = "=";

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
<?php
  list($s) = explode(" ", trim(fgets(STDIN)));
  $len = strlen($s);

  $half = intdiv($len, 2);

  $ans = 0;
  for($i=0; $i<$half; $i++){
    if($s[$i] != $s[$len-1-$i]){
      $ans++;
    }
  }
  echo $ans;

Measured memory_bytes: 4604
#pragma optimize "-O3"
#include <bits/stdc++.h>
using namespace std;
typedef long double ld;
typedef long long ll;
const int maxN = 1005;
char a[maxN][maxN];
int dist[maxN][maxN];
int dx[4] = {1, -1, 0, 0};
int dy[4] = {0, 0, 1, -1};
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    //freopen("input.txt", "r", stdin);
    int h, w;
    cin >> h >> w;
    queue < pair < int, int > > q;
    for (int i = 1; i <= h; i++) {
        for (int j = 1; j <= w; j++) {
            cin >> a[i][j];
            if (a[i][j] == '#') {
                dist[i][j] = 0;
                q.push(make_pair(i, j));
            }
            else dist[i][j] = -1;
        }
    }
    while (!q.empty()) {
        auto t = q.front();
        q.pop();
        int x = t.first;
        int y = t.second;
        for (int k = 0; k < 4; k++) {
            int nx = x + dx[k];
            int ny = y + dy[k];
            if (nx < 1 || nx > h || ny < 1 || ny > w) continue;
            if (dist[nx][ny] == -1) {
                dist[nx][ny] = dist[x][y] + 1;
                q.push(make_pair(nx, ny));
            }
        }
    }
    int ans = 0;
    for (int i = 1; i <= h; i++) {
        for (int j = 1; j <= w; j++) {
            ans = max(ans, dist[i][j]);
        }
    }
    cout << ans;
    return 0;
}

Measured memory_bytes: 13328
#!/usr/bin/env python
# coding: utf-8

# In[1]:


N, K = map(int, input().split())
A = [int(x) for x in input().split()]


# In[2]:


kioku = {}
saisyo = {}
idou = {}

for i in range(N):
    if A[i] in kioku:
        idou[kioku.pop(A[i])] = i
    kioku[A[i]] = i
    if A[i] not in saisyo:
        saisyo[A[i]] = i

    


# In[3]:


# kioku


# In[4]:


# saisyo


# In[5]:


# idou


# In[6]:


i = 0
ret = []
while True:
    if i in idou:
        i = idou[i]
    else:
        ret.append(i)
        i = saisyo[A[i]]
    if i == N - 1:
        i = 0
        break
    else:
        i += 1


# In[7]:


# 3-35 -59- -92- -26- -65-5 31415926535


# In[8]:


# ret


# In[ ]:





# In[ ]:





# In[9]:


loop = len(ret) + 1
if K % loop != 0:
#     print(ret[K % loop - 1])
#     print(A[ret[K % loop - 1]:])
    i = ret[K % loop - 1]
    ans = []
    while i <= N - 1:
        if i in idou:
            i = idou[i]
        else:
            ans.append(A[i])
        i += 1
    print(' '.join(map(str, ans)))


# In[ ]:






Measured memory_bytes: 65296
#include <bits/stdc++.h>
#define int long long
#define endl '\n'
#define FOR(i, a, n) for (int i = (a); i < (n); ++i)
#define REP(i, n) FOR(i, 0, n)
using namespace std;

void _main() {
    int N;
    cin >> N;
    for (int i = 1, p = 1; p < N; ++i) {
        p *= 3;
        if (p >= N) {
            cout << i << endl;
            break;
        }
    }
}

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(10);
    _main();
    return 0;
}


Measured memory_bytes: 3216
#include <bits/stdc++.h>
#define xx first
#define yy second
#define mp make_pair
#define pb push_back
#define mset(x, y) memset(x, y, sizeof x)
#define mcpy(x, y) memcpy(x, y, sizeof x)
using namespace std;

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

inline int Read()
{
	int x = 0, f = 1, c = getchar();
	for (; !isdigit(c); c = getchar())
		if (c == '-')
			f = -1;
	for (;  isdigit(c); c = getchar())
		x = x * 10 + c - '0';
	return x * f;
}

const int MAXN = 100005;

int n, m, a[MAXN], b[MAXN];
LL ans, sum;

int main()
{
#ifdef wxh010910
	freopen("data.in", "r", stdin);
#endif
	n = Read(), m = Read();
	for (int i = 1; i <= n; i ++)
		a[i] = Read(), b[i] = Read();
	for (int i = 1; i <= 30; i ++)
		if (m >> i & 1)
		{
			sum = 0;
			int tmp = (m ^ 1 << i) | ((1 << i) - 1);
			for (int j = 1; j <= n; j ++)
				if ((a[j] & tmp) == a[j])
					sum += b[j];
			ans = max(ans, sum);
		}
	sum = 0;
	for (int j = 1; j <= n; j ++)
		if ((a[j] & m) == a[j])
			sum += b[j];
	ans = max(ans, sum);
	return printf("%lld\n", ans), 0;
}


Measured memory_bytes: 1024
/*
 * cpp_filepath
 */

// C++ 14
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstring> // memset
#include <cassert>
using namespace std;
#define ll long long
#define loop(__x, __start, __end) for(int __x = __start; __x < __end; __x++)
template <class T> ostream & operator << (ostream & out, vector<T> const & v) {
  for (auto &&a: v) out << a << " "; out << endl; return out;
}
template <class T> void dump(T &a) { cout << a << endl; }
void solve();
int main() { solve(); return 0; }


void solve() {
  int n;
  cin >> n;
  int x = n*800;
  int y = (n/15)*200;
  cout << x-y << endl;
}


Measured memory_bytes: 256
#!ruby -Ks
a = gets.to_i
if a > 888
  puts "999"
elsif a > 777
  puts "888"
elsif a > 666
  puts "777"
elsif a > 555
  puts "666"
elsif a > 444
  puts "555"
elsif a > 333
  puts "444"
elsif a > 222
  puts "333"
elsif a > 111
  puts "222"
else
  puts "111"
end

Measured memory_bytes: 3836
#include <iostream>
#include <vector>
#include <math.h>
#include <string>
#include <algorithm>
#include <functional>

using namespace std;

template <class T>
inline bool chmin(T &a, T b)
{
  if (a > b)
  {
    a = b;
    return true;
  }
  return false;
}
template <class T>
inline bool chmax(T &a, T b)
{
  if (a < b)
  {
    a = b;
    return true;
  }
  return false;
}

bool is_integer_modf(float x)
{
  float r;
  return 0 == modf(x, &r);
}

int main()
{
  int x, y;
  cin >> x >> y;

  float a = (4.0f * x - y) / 2.0f;
  float b = (y - 2.0f * x) / 2.0f;

  if (is_integer_modf(a) && is_integer_modf(b) && a >= 0.0f && b >= 0.0f)
  {
    cout << "Yes";
  }
  else
  {
    cout << "No";
  }

  return 0;
}

Measured memory_bytes: 3104
#include <algorithm>
#include <array>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <stack>
#include <vector>

using namespace std;
using ll = long long;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

#define MOD ((ll)1000000007)


int main(int argc, char const *argv[])
{
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(15);

	int A, B, C, X;
	cin >> A >> B >> C >> X;

	int count = 0;
	for (size_t i = 0; i <= A; i++)
	{
		for (size_t j = 0; j <= B; j++)
		{
			for (size_t k = 0; k <= C; k++)
			{
				if (500 * i + 100 * j + 50 * k == X)
				{
					count++;
				}
			}
		}
	}
	cout << count << endl;
	return 0;
}


Measured memory_bytes: 256
import sys
from collections import defaultdict, Counter, deque
from itertools import accumulate, permutations, combinations
from operator import itemgetter
from bisect import bisect_left, bisect_right, bisect
from heapq import heappop, heappush
from fractions import gcd
from math import ceil, floor, sqrt, cos, sin, pi
from copy import deepcopy

# If you use recursive call, uncomment this code
#sys.setrecursionlimit(10**6)

def main():
    a,b,c,k = map(int, input().split())
    if a + b >= k:
        print(min(a,k))
    else:
        print(a-(k-a-b))

if __name__ == '__main__':
    main()


Measured memory_bytes: 10580
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define rep2(i, s, n) for (ll i = s; i < (ll)(n); i++)
#define repr(i, n) for (ll i = n; i >= 0; i--)
#define pb push_back
#define COUT(x) cout << (x) << "\n"
#define COUTF(x) cout << setprecision(15) << (x) << "\n"
#define ENDL cout << "\n"
#define DF(x) x.erase(x.begin())  // 先頭文字削除
#define ALL(x) x.begin(), x.end()
#define SZ(x) (ll) x.size()
#define SORT(x) sort(ALL(x))
#define REVERSE(x) reverse(ALL(x))
#define ANS cout << ans << "\n"
#define RETURN(x)    \
  cout << x << "\n"; \
  return 0
clock_t CLOCK;
#define START_TIMER CLOCK = clock()
#define SHOW_TIMER cerr << "time: " << (ld)(clock() - CLOCK) / 1000000 << "\n"
#define init() \
  cin.tie(0);  \
  ios::sync_with_stdio(false)
#define LINE cerr << "[debug] line: " << __LINE__ << "\n";
#define debug(x) cerr << "[debug] " << #x << ": " << x << "\n";
#define debugV(v)                       \
  cerr << "[debugV] " << #v << ":";     \
  rep(i, v.size()) cerr << " " << v[i]; \
  cerr << "\n";
using namespace std;
using ll = long long;
using ld = long double;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using mll = map<ll, ll>;
using qll = queue<ll>;
using P = pair<ll, ll>;

constexpr ll INF = 0x3f3f3f3f3f3f3f3f;
constexpr ld PI = 3.141592653589793238462643383279;
ll get_digit(ll x) {
  return to_string(x).size();
}

ll gcd(ll x, ll y) {
  return y ? gcd(y, x % y) : x;
}

ll lcm(ll a, ll b) {
  return a / gcd(a, b) * b;
}

vector<P> factorize(ll n) {
  vector<P> result;
  for (ll i = 2; i * i <= n; ++i) {
    if (n % i == 0) {
      result.pb({i, 0});
      while (n % i == 0) {
        n /= i;
        result.back().second++;
      }
    }
  }
  if (n != 1) {
    result.pb({n, 1});
  }
  return result;
}

vll divisor(ll n) {
  vll ret;
  for (ll i = 1; i * i <= n; i++) {
    if (n % i == 0) {
      ret.push_back(i);
      if (i * i != n) ret.push_back(n / i);
    }
  }
  SORT(ret);
  return (ret);
}

signed main() {
  init();
  ll N;
  cin >> N;
  ll ans = N * 800 - N / 15 * 200;
  ANS;
  return 0;
}

Measured memory_bytes: 3588
#include <iostream>
#include <complex>
#include <sstream>
#include <string>
#include <algorithm>
#include <deque>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <vector>
#include <set>
#include <limits>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <ctime>
using namespace std;
#define REP(i, j) for(int i = 0; i < (int)(j); ++i)
#define FOR(i, j, k) for(int i = (int)(j); i < (int)(k); ++i)
#define SORT(v) sort((v).begin(), (v).end())
#define REVERSE(v) reverse((v).begin(), (v).end())
typedef complex<double> P;
const int L = 110;

int main() {
  int N, W;
  while(cin >>N >>W && N){
    vector<int> v(L, 0);
    REP(i, N){
      int n; cin >>n;
      ++v[n / W];
    }
    int mx = 0;
    double l = 0;
    REP(i, L) if(v[i] > 0) { mx = max(mx, v[i]); l = i; }
    double ans = 0.0;
    REP(i, L){
      if(v[i] == 0) continue;
      ans += ((l - i) / l) * (v[i] / (double)(mx));
    }
    printf("%.8lf\n", ans + 0.01);
  }
  return 0;
}

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

int main() {
	int n;
	cin >> n;
    double a[n],b[n];
    double sum = 0;
    for(int i=0;i<n;i++){
    	cin >> a[i];
    	b[i] = 1/a[i];
    	sum += b[i];
    }
    
    cout << 1 / sum << endl;
	return 0;
}

Measured memory_bytes: 256
import sys
sys.setrecursionlimit(1000000)

nVertices, nEdges = map(int, input().split())
edges = [[] for _ in range(nVertices + 1)]
for _ in range(nEdges):
    u, v = map(int, input().split())
    edges[u].append(v)
    edges[v].append(u)

if nEdges & 1 == 1:
    print(-1)
    exit()

def dfs(v):
    visited[v] = True
    for next in edges[v]:
        if not visited[next]:
            mst[v].add(next)
            mst[next].add(v)
            dfs(next)

def dfs2(par, v):
    for child in mst[v]:
        if child != par:
            dfs2(v, child)
    if par == 0:
        return
    if len(out[v]) & 1 == 1:
        out[v].add(par)
    else:
        out[par].add(v)

mst = [set() for _ in range(nVertices + 1)]
visited = [False] * (nVertices + 1)
dfs(1)

out = [set() for _ in range(nVertices + 1)]
for u in range(1, nVertices + 1):
    for v in edges[u]:
        if v not in mst[u] and u not in out[v]:
            out[u].add(v)

dfs2(0, 1)
for u in range(1, nVertices + 1):
    for v in out[u]:
        print(u, v)



Measured memory_bytes: 158036
#include <bits/stdc++.h>
#include<vector>
#define int long long
using namespace std;
bool ispalindrome(string& s)
{
    int i=0;
    int j=s.size()-1;
    while(i<=j)
        if(s[i++]!=s[j--])
        return false;
    return true;
}
int modPow(int a,int b,int mod)
{
    while(b>1)
    {
        if(b%2==0)
        {
            a=a*a%mod;
            b/=2;
        }
        else
            return a*modPow(a,b-1,mod)%mod;
    }
    return a;

}
bool prime[2001];
void sieve()
{
    prime[1]=false;
    for(int i=2;i*i<2001;i++)
    {
        if(prime[i])
        {
            for(int j=i*i;j<2001;j+=i)
                prime[j]=false;
        }
    }
}
signed main() {
	//code

	string s;
	cin>>s;
	int n=s.size();
	cout<<s;
	if(s[n-1]=='s')
        cout<<"es";
    else
        cout<<"s";



}


Measured memory_bytes: 3628
#include<cmath>
#include<ctime>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<queue>
#include<set>
#include <cstdio>
#include <string>
#include <unordered_map>
using namespace std;
const int N = 5001;
int n, A, B;
int a[N];
long long f[N][N + 1];
int main(){
    scanf("%d %d %d", &n, &A, &B);
    for (int i = 1; i <= n ;  i ++) {
        int x;
        scanf("%d", &x);
        a[x] = i;
    }
    for (int i = 1; i <= n ; i ++)
        for (int j  = 0; j <= n + 1; j ++)
            f[i][j] = 1e18;
    for (int i = 0; i < n ; i ++) {
        for (int j = 0; j <= n ; j ++)
            f[i][j + 1] = min(f[i][j + 1], f[i][j]);
        for (int j = 0; j <= n + 1; j++) {
            if (j == a[i + 1])
                f[i + 1][j]= min(f[i][j], f[i + 1][j]);
            else
                if (a[i + 1] > j)
                    f[i + 1][j]= min(f[i][j] + B, f[i + 1][j]);
                else    f[i + 1][j]= min(f[i][j] + A, f[i + 1][j]);

        }
    }
    long long ans =1e18;
    for (int i = 0; i <= n + 1; i ++)
        ans = min(ans, f[n][i]);
    printf("%lld\n", ans);
    return 0;
}

Measured memory_bytes: 195712
#include<iostream>
#include<algorithm>
#include<string>
#include<map>
#include<utility>
#include<vector>
#include<functional>
#include<stack>
#include<queue>
#include<math.h>
#include<deque>
#define rep(i,rept)	for(ll i = 0; i<(ll)rept;++i)
typedef long long ll;
using namespace std;

//Harlequin

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

	int n = 0, a[100000] = {};

	cin >> n;
	rep(i, n) {
		cin >> a[i];
	}

	rep(i, n) {
		if (a[i] % 2 == 1) {
			cout << "first" << endl;
			return 0;
		}
	}
	cout << "second" << endl;
}

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

using namespace std;

// MACROS

#define ll long long
#define ull unsigned long long
#define ld long double

#define vi vector<int>
#define vll vector<ll>
#define vld vector<ld>
#define u_s unordered_set

#define pii pair<int,int>
#define pll pair<ll,ll>

#define FOR(i, n) for (ll (i) = 0; i < n; i++)
#define FORN(i, a, b) for (ll (i) = a; i < b; i++)
#define FORE(i, l) for (auto (i) : l)

#define pb push_back
#define pob pop_back
#define emp emplace
#define fi first
#define se second

#define all(n) (n).begin(), (n).end()
#define in(n) cin >> (n);
#define debug(n) cout << #n << ": " << n << '\n';

// FUNCTIONS

template< typename T >
inline T gcd(T a, T b) { if (b) return gcd(b, a % b); return a; }

template< typename T >
inline T ext_gcd(T a, T b, T & x, T & y) { if (a == 0) { x = 0; y = 1; return b; } T x1, y1; T g = ext_gcd(b % a, a, x1, y1); x = y1 - (b / a) * x1; y = x1; return g; }

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);	
    //cout << setprecision(15);
    string s;
    cin >> s;
    if (s[0] == s[1] && s[1] == s[2]) cout << "No\n";
    else cout << "Yes\n";
}



Measured memory_bytes: 256
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
 
def main():
    S = input()
    T = input()
    n = len(S)
    cnt = 0
    for i in range(n):
        if S[i] != T[i]:
            cnt += 1
    print(cnt)
if __name__ == '__main__':
    main()


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

using namespace std;

int main() {
	int n;
	scanf("%d", &n);
	
	long long res = 0;
	
	for (int i = 0; i < n - 1; i++) {
		int x, y;
		scanf("%d%d", &x, &y);
		if (x > y) swap(x, y);
		res += 1LL * x * (n - y + 1);
	}
	
	long long tot = 0;
	
	for (int i = 1; i <= n; i++) {
		tot += 1LL * i * (i + 1) / 2LL;
	}
	
	printf("%lld\n", tot - res);
}


Measured memory_bytes: 3840
import bisect

N, M, K = input().split()

desk1 = list(map(int, input().split()))
desk2 = list(map(int, input().split()))

max_time = int(K)
item1 = [0]
item2 = [0]
for i in desk1:
    item1.append(item1[-1] + i)
for i in desk2:
    item2.append(item2[-1] + i)

ret = 0
for i, t in enumerate(item1):
    remain_time = max_time - t
    if remain_time >= 0:
        j = bisect.bisect(item2, remain_time) - 1
        ret = max(ret, i + j)

print(ret)

Measured memory_bytes: 47520
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i,n) for (ll i = 0; i < n; ++i)
#define ALL(a) a.begin(), a.end()
ll dx[4] = { 0, 1, 0, -1 };
ll dy[4] = { 1, 0, -1, 0 };
const ll INF = 1e14;
const ll MOD = 1e9 + 7;

int N;
vector<int> expo; // expo[素因数] = 指数

// expoの要素のうちm-1以上の個数を求める
int num(int m)
{
    int ret = 0;
    for (auto& u : expo) {
        if (u >= m - 1) {
            ret++;
        }
    }
    return ret;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cin >> N;
    expo.resize(N + 1); //  指数
    // 素数で割り切れる数を求めている
    for (int i = 2; i <= N; i++) {
        int cur = i;
        for (int j = 2; j <= i; j++) {
            while (cur % j == 0) {
                expo[j]++;
                cur /= j;
            }
        }
    }
    ll ans = 0;
    ans += num(75); // 重複するのは0
    ans += num(25) * (num(3) - 1);
    ans += num(15) * (num(5) - 1);
    ans += num(5) * (num(5) - 1) * (num(3) - 2) / 2; // 5の順番が違うだけのものを重複して計算するから/2
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 384
#include <iostream>

#define int long long

using namespace std;

const int mod = 1E9 + 7;

int fac(int n) {
    int res = 1;
    for (int i = 1; i <= n; i++)
        res = (res * i) % mod;
    return res;
}

int pw(int x, int p) {
    int res = 1;

    while (p > 0) {
        if (p % 2 == 1)
            res = (res * x) % mod;

        x = (x * x) % mod;
        p /= 2;
    }

    return res;
}

int inv(int x) {
    return pw(x, mod - 2);
}

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

    int x, y;

    cin >> x >> y;

    if ((x + y) % 3 != 0) {
        cout << "0\n";
        return 0;
    }

    int n = (x + y) / 3;
    x -= n, y -= n;

    if (x < 0 || y < 0) {
        cout << "0\n";
        return 0;
    }

    int fxy = fac(x + y);
    int fx = fac(x);
    int fy = fac(y);

    int invfx = inv(fx);
    int invfy = inv(fy);

    cout << ((fxy * invfx) % mod * invfy) % mod << "\n";

    return 0;
}


Measured memory_bytes: 256
n = int(input())
p = list(map(int, input().split()))
d = [min(i, n - i - 1, j, n - j - 1) for i in range(n) for j in range(n)]
ans = 0
l = [1] * (n ** 2)
for i in p:
    ans += d[i - 1]
    l[i - 1] = 0
    que = [i - 1]
    while que:
        s = que.pop()
        if not s % n == n - 1:
            if d[s + 1] > d[s] + l[s]:
                que.append(s + 1)
                d[s + 1] = d[s] + l[s]
        if s % n:
            if d[s - 1] > d[s] + l[s]:
                que.append(s - 1)
                d[s - 1] = d[s] + l[s]
        if s >= n:
            if d[s - n] > d[s] + l[s]:
                que.append(s - n)
                d[s - n] = d[s] + l[s]
        if n ** 2 > s + n:
            if d[s + n] > d[s] + l[s]:
                que.append(s + n)
                d[s + n] = d[s] + l[s]
print(ans)


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

#define each(i, c) for (auto& i : c)
#define unless(cond) if (!(cond))

using namespace std;

typedef long long int lli;
typedef unsigned long long ull;
typedef complex<double> point;

template<typename P, typename Q>
ostream& operator << (ostream& os, pair<P, Q> p)
{
  os << "(" << p.first << "," << p.second << ")";
  return os;
}

int main(int argc, char *argv[])
{
  int n;
  while (cin >> n) {
    int t[n];
    int v[n];
    for (int i = 0; i < n; ++i) {
      cin >> t[i];
    }
    for (int i = 0; i < n; ++i) {
      cin >> v[i];
    }

    vector<pair<int, int>> range;
    int acc = 0;
    for (int i = 0; i < n; ++i) {
      range.push_back(make_pair(acc, acc + t[i]));
      acc += t[i];
    }
    
    const int N = (200 * 100 + 5) * 2;
    const double inf = 1e100;
    double x[N];
    fill(x, x + N, inf);
    for (int i = 0; i < n; ++i) {
      for (int j = range[i].first * 2; j <= range[i].second * 2; ++j) {
        x[j] = min<double>(x[j], v[i]);
      }
    }
    const int k = range.back().second * 2 + 1;
    assert(k < N);
    x[0] = 0;
    x[k - 1] = 0;
      
    for (int i = 0; i + 1 < N; ++i) {
      if (x[i] == N) {
        if (x[i - 1] == x[i + 1]) x[i] = x[i + 1];
        else x[i] = min(x[i - 1] + 0.5, x[i + 1] + 0.5);
      }
    }
    
    for (int i = 1; i - 1 < k; ++i) {
      x[i] = min({x[i - 1] + 0.5, x[i], x[i + 1] + 0.5});
    }
    for (int i = k - 2; 0 < i; --i) {
      x[i] = min({x[i - 1] + 0.5, x[i], x[i + 1] + 0.5});
    }
   
    double sum = 0;
    for (int i = 1; i < k; ++i) {
      if (x[i - 1] == x[i]) {
        sum += x[i - 1] * 0.5;
      } else {
        if (x[i - 1] < x[i]) {
          sum += (x[i - 1] * 0.5) + (0.5 * 0.5 * 0.5);
        } else {
          sum += (x[i - 1] * 0.5) - (0.5 * 0.5 * 0.5);
        }
      }
    }
    printf("%.10lf\n", sum);
  }

  return 0;
}


Measured memory_bytes: 512
n=int(input())
ans=[0 for i in range(1+10**5)]
for i in range(1,101):
    for j in range(1,101):
        for k in range(1,101):
            a=i**2+j**2+k**2+i*j+j*k+k*i
            ans[a]+=1
for i in range(1,n+1):
    print(ans[i])

Measured memory_bytes: 73456