akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

//{ START
using namespace std;
#define int int64_t
#define rep(i, a, n) for (int i = (a); i < (n); ++i)
#define reps(i, a, n) for (int i = (a); i > (n); --i)
#define arep(i, x) for (auto &&i : (x))
#define irep(i, x) for (auto i = (x).begin(); i != (x).end(); ++i)
#define rirep(i, x) for (auto i = (x).rbegin(); i != (x).rend(); ++i)
//降順はgreater<T>()
#define all(x) (x).begin(), (x).end()
#define rv(s) reverse((s).begin(), (s).end())
// gcd lcmはそのままok
#define gcd(a, b) __gcd(a, b)
#define bits(n) (1LL << (n))
#define pcnt(x) __builtin_popcountll(x)
//配列内等要素削除
#define Unique(x) (x).erase(unique((x).begin(), (x).end()), (x).end())
#define Fixed(n) fi > xed << setprecision(n)
//総和
#define sowa(n) (((n) * ((n) + 1)) / 2)
#define cauto const auto &
using P = pair<int, int>;
using Graph = vector<vector<P>>;
template <class T>  //昇順
using min_heap = priority_queue<T, vector<T>, greater<T>>;
template <class T>  //降順
using max_heap = priority_queue<T>;
template <class A, class B>
using umap = unordered_map<A, B>;
template <class A>
using uset = unordered_set<A>;
template <typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val) {  //多次元初期化
  std::fill((T *)array, (T *)(array + N), val);
}
template <class A, class B>
bool chmax(A &a, const B &b) {  //最大値更新 返り値はbool
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class A, class B>
bool chmin(A &a, const B &b) {  //最小値更新 返り値はbool
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
int dx[] = {1, 0, -1, 0, 1, 1, -1, -1};
int dy[] = {0, 1, 0, -1, -1, 1, 1, -1};
constexpr int INF = 0x3f3f3f3f;
constexpr int LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr int mod1 = 1e9 + 7;
constexpr int mod2 = 998244353;
//} END

signed main(void) {
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);

  int n, x;
  cin >> n >> x;
  stack<int> st;
  int ans = 0;
  rep(i, 0, n) {
    int a;
    cin >> a;
    if (i != 0) {
      int now = st.top();
      st.pop();
      if (now + a > x) {
        ans += (now + a) - x;
        a = max(a - (now + a - x), (int)0);
        st.push(a);
      } else
        st.push(a);
    } else
      st.push(a);
  }
  cout << ans << '\n';
  return 0;
}

Measured memory_bytes: 3668
n = int(input())
h = list(map(int, input().split()))

sol = [0 for i in range(n)]
sol[0] = 0
sol[1] = abs(h[1]-h[0])
for i in range(2, n):
    sol[i] = min(sol[i-2] + abs(h[i-2]-h[i]), sol[i-1] + abs(h[i-1]-h[i]))

print(sol[n-1])


Measured memory_bytes: 13980
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
  bool judge = true;
  int N;
  cin >> N;
  vector<ll> D(N);
  for(int i = 0;i < N;i++){
    cin >> D[i];
  }
  sort(D.begin(),D.end());
  int M;
  cin >> M;
  vector<ll> T(M);
  for(int i = 0;i < M;i++){
    cin >> T[i];
  }
  sort(T.begin(),T.end());
  int j = 0;
  for(int i = 0;i < M && j < N;i++){
    while(T[i] > D[j]){
      j++;
      if(j >= N){
        judge = false;
        break;
      }
    }
    if(T[i] == D[j]){
      j++;
      continue;
    }
    if(T[i] < D[j]){
      judge = false;
      break;
    }
  }
  if(judge == true) cout << "YES" << endl;
  else cout << "NO" << endl;
}

Measured memory_bytes: 3328
#include<stdio.h>

int main(){
    int H, W;
    int i, j, k;
    char s[1100];
    int ch[1000010][3];
    int cc[1100][1100];
    int max;
    int x[4]={1, 0, 0, -1};
    int y[4]={0, 1, -1, 0};
    int tmpx, tmpy;

    scanf("%d %d", &H, &W);
    max=H*W;
    k=0;
    for(i=0; i<H; i++){
        scanf("%s", &s);
        for(j=0; j<W; j++){
            if(s[j]=='#'){
                cc[i][j]=1;
                ch[k][0]=i;
                ch[k][1]=j;
                ch[k][2]=0;
                k++;
            }else{
                cc[i][j]=0;
            }
        }
    }
    //printf("%d %d %d\n", ch[k-1][0], ch[k-1][1], ch[k-1][2]);
    j=0;
    while(k<max){
        for(i=0; i<4; i++){
            tmpx = ch[j][0] + x[i];
            tmpy = ch[j][1] + y[i];
            if(0<=tmpx && 0<=tmpy){
                if(tmpx<H && tmpy<W){
                    if(cc[tmpx][tmpy]==0){
                        cc[tmpx][tmpy]=1;
                        ch[k][0]=tmpx;
                        ch[k][1]=tmpy;
                        ch[k][2]=ch[j][2]+1;
                        //printf("%d %d %d\n", tmpx, tmpy, ch[k][2]);
                        k++;
                    }
                }
            }
        }
        j++;
    }
    //printf("%d\n", k);

    printf("%d", ch[max-1][2]);
    return 0;
}

Measured memory_bytes: 16640
#include <iostream>
#include <cstring>
#include <iomanip>
#include <deque>
#include <stdio.h>
#include <string>
#include <vector>
#include <algorithm>
#include <limits.h>
using namespace std;
int ans=0;
int n,x;
int m[105];
const double eps=1e-9;
typedef vector<int> vi;
typedef long long ll;
int bucket[3];
int main(void)
{
  memset(bucket,0,sizeof(bucket));
  string s;
  cin >> s;
  for(int i=0;i<int(s.size());i++)
    {
      bucket[int(s[i]-'a')]++;
    }
  if(bucket[0]==1 && bucket[1]==1 && bucket[2]==1)
    {
      cout << "Yes" << endl;
    }
  else
    {
      cout << "No" << endl;
    }
  
  return 0;
}


Measured memory_bytes: 256
_, c, k, *lst = map(int, open(0).read().split())
lst.sort()
res = 1
tmpt = lst[0]
tmpc = 0
for i in lst:
  tmpc += 1
  if not (tmpc <= c and i - tmpt <= k):
    res += 1
    tmpc = 1
    tmpt = i

print(res)

Measured memory_bytes: 14052
#include <cassert>
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <cwchar>
#include <cwctype>
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <array>
#include <atomic>
#include <chrono>
#include <codecvt>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rep2(i, n) for(int i = 1; i <= (int)(n); i++)
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef int64_t ll;
typedef long double ld;
const ll INF=(1LL<<62);
const double inf=pow(10,10);
const ld pi=acosl(1);
const ll mod = 1000000007;
const int dx[4]={0,1,0,-1};
const int dy[4]={1,0,-1,0};
const int ddx[8]={1,0,-1,-1,-1,0,1,1};
const int ddy[8]={1,1,1,0,-1,-1,-1,0};

bool check(pair<ll,ll>a,pair<ll,ll>b){
	return (a.first>b.first&&a.second>b.second);
}

bool fun(pair<ll,ll>b,pair<ll,ll>a){
	if(a.first==b.first)return a.second>b.second;
	else return a.first<b.first;
}

void add(string* s,ll i){

	if(i>=(*s).size()){
		(*s).push_back('1');
		return;
	}
	if((*s)[i]!='9'){
		(*s)[i]++;
		return;
	}
	else{
		(*s)[i]='0';
		add(s,i+1);
		return ;
	}
	
}

int main(){
	ll ans=0;
	ll num=0;
	ll n;cin>>n;
	set<ll>set;
	rep(i,n){
		ll a;cin>>a;
		if(set.find(a)!=set.end())num++;
		set.insert(a);
	}
	ans+=set.size();
	if(num%2==1)ans--;
	cout<<ans<<endl;
}


Measured memory_bytes: 4992
import Control.Monad
import Data.Array
import qualified Data.ByteString.Char8 as BS
import Data.Maybe

readInt = fst . fromJust . BS.readInt

readIntList = map readInt . BS.words

getInt = readInt <$> BS.getLine

getIntList = readIntList <$> BS.getLine

getSum :: Array Int Int -> Int -> Int -> Int
getSum as i k
  | i == k = abs (as ! (k - 1))
  | otherwise = abs (as ! i - as ! (i - 1)) + getSum as (i + 1) k

removeI :: Array Int Int -> Int -> Int -> Int
removeI as s i = s - abs (as ! i - as ! (i -1)) - abs (as ! (i + 1) - as ! i) + abs (as ! (i + 1) - as ! (i - 1))

main = do
  n <- getInt
  as <- getIntList
  let as' = (0 : as) ++ [0]
  let as'' = listArray (0, n + 2) as'
  let s = getSum as'' 1 (n + 1)
  mapM_ (print . (removeI as'' s)) [1 .. n]


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

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  int first;
  cin >> n >> first;
  for (int i = 0; i < n - 1; i++) {
  	int x;
  	cin >> x;
  	first = __gcd(first, x);
  }
  cout << first << '\n';
  return 0;
}

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

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

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };
    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };
    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };
    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };
    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

// ここまで

struct FenwickTree {
    n: usize,
    a: Vec<i32>
}

impl FenwickTree {
    fn new(n: usize) -> FenwickTree {
        FenwickTree {
            n: n,
            a: vec![0; n + 1],
        }
    }
    fn add(&mut self, x: usize, v: i32) {
        let mut i = x;
        while i <= self.n {
            self.a[i] += v;
            i += i & (!i + 1);
        }
    }
    fn sum(&self, x: usize) -> i32 {
        let mut s = 0;
        let mut i = x;
        while i > 0 {
            s += self.a[i];
            i -= i & (!i + 1);
        }
        s
    }
}

fn run() {
    input! {
        n: usize,
        p: [(i32, i32); n],
    }
    let mut p = p;
    p.sort();
    for (i, v) in p.iter_mut().enumerate() {
        v.0 = (i + 1) as i32;
        let s = v.0;
        v.0 = v.1;
        v.1 = s;
    }
    p.sort();
    const MOD: u64 = 998244353;
    let pow2: Vec<u64> = (0..n).scan(1, |s, _| {let v = *s; *s *= 2; if *s >= MOD { *s -= MOD;} Some(v)}).collect();
    let mut l = FenwickTree::new(n);
    let mut r = FenwickTree::new(n);
    for i in 1..(n + 1) {
        r.add(i, 1);
    }
    let mut ans = (n as u64) * pow2[n - 1];
    for (i, p) in p.iter().enumerate() {
        let i = i as usize;
        let y = p.1 as usize;
        r.add(y, -1);
        let a = l.sum(y) as usize;
        let b = i - a;
        let c = r.sum(y) as usize;
        let d = (n - 1 - i) - c;
        ans += pow2[n - 1];
        ans += MOD - pow2[a + b];
        ans += MOD - pow2[a + c];
        ans += MOD - pow2[b + d];
        ans += MOD - pow2[c + d];
        ans += pow2[a];
        ans += pow2[b];
        ans += pow2[c];
        ans += pow2[d];
        ans += MOD - 1;
        l.add(y, 1);
    }
    ans %= MOD;
    println!("{}", ans);
}

fn main() {
    run();
}


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

using namespace std;
int c=0;

int main(){
    string s;
    cin>>s;
    if(s[0]!='A') return cout<<"WA"<<endl,0;
    for(int i=1; i<s.length(); i++){
        if(s[i]!='A' && s[i]!='C' && s[i]>='A' && s[i]<='Z') return cout<<"WA"<<endl,0;
        if(i>=2 && i<=s.length()-2 && s[i]=='C') c++;
    }
    if(c==1) cout<<"AC"<<endl;
    else cout<<"WA"<<endl;

    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
int main(void){
    
    int d, r;
    double a, b, f;
    scanf("%lf %lf\n", &a, &b);
    
    d = a / b;
    r = (int)a % (int)b;
    f =  a / b;
    
    printf("%d %d %f\n", d, r, f);
    
    return 0;
}


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

l = [1]
for i in range(1, n):
    if (a[i] == a[i - 1]):
        l[len(l) - 1] += 1
    else:
        l.append(1)

ans = 0
for ln in l:
    ans += ln // 2

print(ans)


Measured memory_bytes: 3060
#include<stdio.h>
#include<stdlib.h>
void partition(int *A,int p,int r);
int main(){
  int n,*S,q,*T,i,N,count=0;
  scanf("%d\n",&n);
  S=(int *)malloc(n*sizeof(int));
  for(i=0;i<n;i++){
    scanf("%d",&S[i]);
  }
  partition(S,0,n-1);
  return 0;
}
void partition(int *A,int p,int r){
  int x,i,j,swap,k;
  x=A[r];
  i=p-1;
  for(j=p;j<r;j++){
    if(A[j]<=x){
      i++;
      swap=A[i];
      A[i]=A[j];
      A[j]=swap;
    }
  }
  
  /*printf("[%d] ",A[r]);
  for(k=r+1;k<i+1;k++){
    printf("%d ",A[k]);
  }
  printf("%d\n",A[i+1]);*/
  swap=A[i+1];
  A[i+1]=A[r];
  A[r]=swap;
  for(k=0;k<i+1;k++){
    printf("%d ",A[k]);
  }
  printf("[%d] ",A[i+1]);
for(k=i+2;k<r;k++){
    printf("%d ",A[k]);
  }
 printf("%d\n",A[r]);
}



Measured memory_bytes: 2104
#include <stdio.h>
#define N 8

void printboard(void);
void putQueen(int);
 
int row[N]={0},col[N]={0},dpos[2*N-1]={0},dneg[2*N-1]={0};
int Q[N][N];
 
 
void printBoard(){
  int i,j;
  for(i=0;i<N;i++)
    for(j=0;j<N;j++)
      if(Q[i][j] == 1)
	if(row[i] != j)return;
   
  for (i=0;i<N;i++){
    for(j=0;j<N;j++){
      if(row[i]==j)printf("Q");
      else printf(".");
    }
    printf("\n");
  } 
} 
void putQueen (int i ){
  int j;
  if ( i == N){
    printBoard();
    return ;
  }
  for (j =0 ;j <N;j++){
    if (col[j] == 1 || dpos[i+j] == 1 || dneg[i-j+N-1] ==1)continue;    
    row[i] =j;
    col[j] = dpos[i+j] = dneg[i-j+N-1] = 1;
    putQueen(i+1);
    row[i] = col[j]=dpos[i+j]=dneg[i-j+N-1] = 0;
  }
}
int main(){
  int i,n,r,c;
   
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d%d",&r,&c);
    Q[r][c] = 1;    
  }    
  putQueen( 0 );
    return 0;
}
 

Measured memory_bytes: 572
#include <bits/stdc++.h>
using namespace std;
char lx = ' ', cx = ' ';
int main(){
	while(scanf("%c", &cx) != EOF){
		if(cx == 'C' && lx == 'A') {
			printf("Yes\n");
			return 0;
		}
		lx = cx;
	}
	printf("No\n");
}

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

#define times(n, i)      uptil(0, n, i)
#define rtimes(n, i)     downto((n) - 1, 0, i)
#define upto(f, t, i)    for(int _##i = (t), i = (f); i <= _##i; i++)
#define uptil(f, t, i)   for(int _##i = (t), i = (f); i <  _##i; i++)
#define downto(f, t, i)  for(int _##i = (t), i = (f); i >= _##i; i--)
#define downtil(f, t, i) for(int _##i = (t), i = (f); i >  _##i; i--)
typedef long double LD;
#define long long long

#if defined(EBUG) && !defined(ONLINE_JUDGE)
#define debug true
#define ln << endl
#else
#define debug false
#define ln << '\n'
#endif
#define tb << '\t'
#define sp << ' '

#define lam [&]


signed main() { // long: 64bit
    if(!debug) {
        cin.tie(0);
        ios::sync_with_stdio(0);
    }

    int N; scanf("%d", &N);
    vector<long> A(N);
    times(N, i) scanf("%lld", &A[i]);

    long ans = 0;
    while(not all_of(A.begin(), A.end(), lam(long x){ return x < N; })) {
        long op = 0;
        times(N, i) {
            long opd = A[i] / N;
            op += opd;
            A[i] = A[i] % N - opd;
        }
        times(N, i) A[i] += op;
        if(debug) { times(N, i) cout << A[i] sp; cout ln; }
        ans += op;
    }

    cout << ans ln;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <cstdlib>
#include <cmath>
#define rep(i,n) for (ll i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;
int main() {
  ll a,b,c ;
  cin>>a>>b>>c ;
  if(4*a*b<(c-a-b)*(c-a-b)  &&c-a-b>0)
  cout<< "Yes" <<endl ;
  else
    cout <<"No" <<endl ; 
    return 0;
}

Measured memory_bytes: 256
N, K = map(int, input().split())
S = input()
starts = []
idx = 0
while idx < len(S):
    starts.append(idx)
    while idx < len(S) and S[starts[-1]] == S[idx]:
        idx += 1
starts.append(len(S))
ans = 0
for i, start in enumerate(starts[:-1]):
    if S[start] == '0':
        stop = starts[min(len(starts) - 1, i + 2 * K)]
    else:
        stop = starts[min(len(starts) - 1, i + 2 * K + 1)]
    ans = max(ans, stop - start)
print(ans)


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

using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define MIN(a, b) ((a) > (b) ? (b) : (a))
#define MAX(a, b) ((a) < (b) ? (b) : (a))

const long long INF = 1LL << 60;
typedef unsigned long long ll;
const long long MOD = 1000000000 + 7;

int main() {
  string s;
  cin >> s;
  int seen[27] = {0};
  rep(i, s.size()) {
    char unit;
    unit = s[i] - 'a';
    if (seen[unit] != 0) {
      cout << "no" << endl;
      return 0;
    }
    seen[unit]++;
  }
  cout << "yes" << endl;
  return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int n, m, x, y, ans, i;
int l[100001];
char is[100001];
int main(){
	scanf("%d%d", &n, &m);
	l[1]=1;
	is[1]=1;
	for(i=2; i<=n; i++){
		l[i]=1;
	}
	for(i=0; i<m; i++){
		scanf("%d%d", &x, &y);
		l[x]--;
		l[y]++;
		if(is[x]){
			is[y]=1;
		}
		if(l[x]==0){
			is[x]=0;
		}
	}
	for(i=1; i<=n; i++){
		ans+=is[i];
	}
	printf("%d\n", ans);
}


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

typedef long long int ll;
using Graph = vector<vector<int>>;

template<typename T>
void remove(std::vector<T>& vector, unsigned int index)
{
    vector.erase(vector.begin() + index);
}

int main(){
  ll N;
  cin >> N;
  vector<ll> A(N);
  stack<ll> ev,od;
  queue<ll> qev,qod;
  for(int i = 0;i < N;i++)cin >> A[i];
  for(int i = 0;i < N;i++){
    if(i % 2 == 0){
      od.push(A[i]);
      qod.push(A[i]);
    }else{
      ev.push(A[i]);
      qev.push(A[i]);
    }
  }
  int n = od.size();
  if(N % 2 == 0){
    for(int i = 0;i < N;i++){
      if(i < n){
        cout << ev.top() << ' ';
        ev.pop();
        }else{
          cout << qod.front() << ' ';
          qod.pop();
        }
    }
    cout << endl;
  }else{
    for(int i = 0;i < N;i++){
      if(i < n){
        cout << od.top() << ' ';
        od.pop();
      }else{
        cout << qev.front() << ' ';
        qev.pop();
      }
    }
    cout << endl;
  }
}

Measured memory_bytes: 7040
import java.util.Arrays;
import java.util.Scanner;


public class Main {
	int[] list;
	boolean[] used;
	final int target = 10;
	String str;
	final char[] op = {'+', '-', '*'};
	int cal(final int a, final int b, char key){
		int sum = 0;
		switch(key){
		case '+':
			sum = a+b;
			break;
		case '-':
			sum = a-b;
			break;
		case '*':
			sum = a*b;
			break;
		default:
		}
		return sum;
	}
	
	boolean solve(int sum, int depth, String str){
		if(depth==list.length){
			if(sum==target){ 
				this.str = str; 
			}
			return sum==target;
		}
		boolean flag = false;
		
		if(str==""){
			for(int i=0; i<list.length; ++i){
				used[i] = true;
				flag |= solve(list[i], depth+1, Integer.toString(list[i]));
				used[i] = false;
			}
		}else{
			for(int i=0; i<used.length; ++i){
				if(!used[i]){
					used[i] = true;
					for(int j=0; j<op.length; ++j){
						String tmp = "(" + str + " " + op[j] + " " + list[i] + ")";
						flag |= solve(cal(sum, list[i], op[j]), depth+1, tmp);
					}
					used[i] = false;
				}
			}
			
			if(depth==2){
				for(int i=0; i<list.length; ++i){
					if(!used[i]){
						used[i] = true;
						for(int j=0; j<list.length; ++j){
							if(!used[j]){
								used[j] = true;
								for(int k=0; k<op.length; ++k){
									final int sum2 = cal(list[i], list[j], op[k]);
									for(int l=0; l<op.length; ++l){
										String tmp = "(" + str + " " + op[l] + " " + "(" + list[i] + " " + op[k] + " " + list[j] + ")" + ")";
										flag |= solve(cal(sum, sum2, op[l]), depth+2, tmp);
									}
								}
								used[j] = false;
							}
						}
						used[i] = false;
					}
				}
			}
			
		}
		
		return flag;
	}
	
	
	void io(){
		Scanner sc = new Scanner(System.in);
		for(;;){
			list = new int[4];
			int sum = 0;
			for(int i=0; i<4; ++i){
				list[i] = sc.nextInt();
				sum += list[i];
			}
			if(sum==0)break;
			used = new boolean[4];
			str = "";
			solve(0, 0, "");
			System.out.println(str=="" ? 0 : str);
		}
	}
	
	public static void main(String[] args) {
		new Main().io();
	}
	
	void debug(Object... os){
		System.out.println(Arrays.deepToString(os));
	}
}

Measured memory_bytes: 12000
#include <numeric>
#include<iostream>
#include<set>
#include<queue>
#include<vector>
#include<map>
#include<stack>
#include <cstdio>
#include<algorithm>
#include <sstream>
#include<string>
#include<string.h>
#include <cmath>
#include <iomanip>
#include <string>
#include<list>
using namespace std;
#define int long long
#define inf 1000000007
#define rep(i,j,n) for(int i=j;i<n;i++)
typedef pair<int,int>  P;
double pi = 3.141592653589793;
//使うやつはここから下に置こうな
signed main(){
    int n;cin>>n;
    int a[214514];
    int sum[214514];
    vector<int>key;
    set<int>ch;
    rep(i,0,n){
        cin>>a[i+1];
        if(i==0)sum[i+1]=a[i+1];
        else sum[i+1]=sum[i]+a[i+1];
        key.push_back(sum[i+1]);
        ch.insert(sum[i+1]);
    }
    key.push_back(0);
    sort(key.begin(),key.end());
    int ans=0;
    for(auto i:ch){
        int h=upper_bound(key.begin(),key.end(),i)-lower_bound(key.begin(),key.end(),i);
        ans+=h*(h-1)/2;
    }
    cout<<ans<<endl;
    return 0;
}

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

using namespace std;

using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using vvvll = vector<vector<vector<ll>>>;
using vvvvll = vector<vector<vector<vector<ll>>>>;
using pl4 = pair<ll,ll>;
using str = string;
using vpl4 = vector<pair<ll,ll>>;

#define sz size()
#define be begin()
#define en end()
#define fi first
#define se second
#define pb push_back
#define mp make_pair

#define llin(x) ll (x);cin >>(x);
#define stin(x) str (x);cin >>(x);
#define vllin(x,n) vll (x)(n);FOR(i,0,n-1){cin >>(x)[i];}
#define vllin2(a,b,n) vll (a)(n);vll (b)(n);FOR(i,0,n-1){cin >>(a)[i]>>(b)[i];}
#define vllin3(a,b,c,n) vll (a)(n);vll (b)(n);vll (c)(n);FOR(i,0,n-1){cin >>(a)[i]>>(b)[i]>>(c)[i];}
#define vlling(x,n) (x).assign(n,0);FOR(i,0,n-1){cin >>(x)[i];}
#define vlling2(a,b,n) (a).assign(n,0);(b).assign(n,0);FOR(i,0,n-1){cin >>(a)[i]>>(b)[i];}
#define vlling3(a,b,c,n) (a).assign(n,0);(b).assign(n,0);(c).assign(n,0);FOR(i,0,n-1){cin >>(a)[i]>>(b)[i]>>(c)[i];}
#define vpl4in(x,n) vpl4 (x)((n),mp(0,0));FOR(i,0,n-1){cin >>x[i].fi>>x[i].se;}
#define FOR(i,a,b) for(ll i = a ; i <= b ; i++)
#define rFOR(i,b,a) for(ll i = a; i >= b ; i--)
#define SORT(x) sort(x.be, x.en)
#define rSORT(x) sort(x.rbegin(), x.rend())
#define say(x) cout<<(x);
#define sal(x) cout<<(x)<<endl;
#define says(x) cout<<(x)<<(' ');
#define sas cout<<(' ');
#define sayR(x) cout<<fixed<<setprecision(10)<<(x);
#define salR(x) cout<<fixed<<setprecision(10)<<(x)<<endl;
#define yn(a) cout <<((a)?"yes":"no")<<endl;
#define Yn(a) cout <<((a)?"Yes":"No")<<endl;
#define YN(a) cout <<((a)?"YES":"NO")<<endl;
#define Imp(a) cout <<((a)?"Possible":"Impossible")<<endl;
#define IMP(a) cout <<((a)?"POSSIBLE":"IMPOSSIBLE")<<endl;
#define pow(a,b) ll(pow(a,b))

ll MOD=1000000007;
ll INF=100000000000001;
vector<ll> value; // ノードの値を持つ配列
ll N;             // 葉の数
 
void update(ll i, ll x) {
    // i 番目の葉の値を x に変える
    i += N - 1; // i 番目の葉のノード番号
    value[i] = x;
    while (i > 0) {
        i = (i - 1) / 2; // ノード i の親ノードの番号に変える
        value[i] = min(value[i * 2 + 1],
                       value[i * 2 + 2]); // 左右の子の min を計算しなおす
    }
}
 
ll query(ll a, ll b, ll k, ll l, ll r) {
    // [a, b) の区間に対するクエリについて
    // ノード k （区間 [l, r) 担当）が答える
    if (r <= a || b <= l) return INF; // 区間が被らない場合は INF を返す
    if (a <= l && r <= b)
        return value[k]; // ノード k の担当範囲がクエリ区間 [a, b)
                         // に完全に含まれる
    else {
        ll c1 = query(a, b, 2 * k + 1, l, (l + r) / 2); // 左の子に値を聞く
        ll c2 = query(a, b, 2 * k + 2, (l + r) / 2, r); // 右の子に値を聞く
        return min(c1, c2); // 左右の子の値の min を取る
    }
}

ll n;
vll a(1000);
vll b(1000);
vll d(10001,100000000);
signed main(){
    llin(h);
    cin >>n;
    FOR(i,0,n-1){
        cin >>a[i]>>b[i];
    }
    FOR(c,1,h){
        FOR(i,0,n-1){
            if(c<=a[i]){
                d[c]=min(d[c],b[i]);
            }else{
                d[c]=min(d[c],b[i]+d[c-a[i]]);
            }
        }
    }
    sal(d[h])
}

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

int main (){
    long  a,b,x,ans;
    cin >> a >> b >> x;
    ans = 0;
    long  up,down;
    up = 0;
    down = 0;
    up = b / x;
    down = a / x;
    ans = up - down;
    if(a % x == 0){
        ans++;
    }
    cout << ans;
}

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

template <class Abel> struct BIT {
    vector<Abel> dat[2];
    Abel UNITY_SUM = 0;                     // to be set
    
    /* [1, n] */
    BIT(int n) { init(n); }
    void init(int n) { for (int iter = 0; iter < 2; ++iter) dat[iter].assign(n + 1, UNITY_SUM); }
    
    /* a, b are 1-indexed, [a, b) */
    inline void sub_add(int p, int a, Abel x) {
        for (int i = a; i < (int)dat[p].size(); i += i & -i)
            dat[p][i] = dat[p][i] + x;
    }
    inline void add(int a, int b, Abel x) {
        sub_add(0, a, x * -(a - 1)); sub_add(1, a, x); sub_add(0, b, x * (b - 1)); sub_add(1, b, x * (-1));
    }
    
    /* a is 1-indexed, [a, b) */
    inline Abel sub_sum(int p, int a) {
        Abel res = UNITY_SUM;
        for (int i = a; i > 0; i -= i & -i) res = res + dat[p][i];
        return res;
    }
    inline Abel sum(int a, int b) {
        return sub_sum(0, b - 1) + sub_sum(1, b - 1) * (b - 1) - sub_sum(0, a - 1) - sub_sum(1, a - 1) * (a - 1);
    }
    
    /* debug */
    void print() {
        for (int i = 1; i < (int)dat[0].size(); ++i) cout << sum(i, i + 1) << ",";
        cout << endl;
    }
};

int main() {
    int N,Q; cin >> N>>Q;
    vector<int> a(N);
    for (int i = 0; i < N; ++i) cin >> a[i];
    vector<int> lefts(Q), rights(Q), ids(Q);
    for (int i = 0; i < Q; ++i) {
        cin >> lefts[i] >> rights[i];
        --lefts[i];
        ids[i] = i;
    }
    sort(ids.begin(), ids.end(), [&](int i, int j) {
            return rights[i] < rights[j];});

    BIT<int> bit(N+5);
    vector<int> prev(1100000, -1);
    vector<int> res(Q, 0);
    int r = 0;
    for (auto i : ids) {
        for (; r < rights[i]; ++r) {
            bit.add(prev[a[r]]+2, r+2, 1);
            prev[a[r]] = r;
        }
        int tmp = bit.sum(lefts[i]+1, lefts[i]+2);
        res[i] = max(res[i], tmp);
    }
    for (int i = 0; i < Q; ++i) cout << res[i] << endl;
}

Measured memory_bytes: 21732
import java.util.*;
class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int A[] = new int[100];
        int N = sc.nextInt();
        int D = sc.nextInt();
        int X = sc.nextInt();
        int cnt = 0;
        for(int i = 0;i<N;i++){
            A[i] = sc.nextInt();
            for(int j = 1;j<=D;j=j+A[i]){
                cnt++;
            }
        }
        System.out.println((X+cnt));
    }
}
 

Measured memory_bytes: 21716
#include <stdio.h> 
#include <iostream> 
#include <string> 
 
using namespace std; 
 
int main() { 
    int n; 
    cin >> n; 
    int *a = new int[n]; 
    for (int i = 0; i < n; ++i) { 
        cin >> a[i]; 
    } 
    double r = 0.0; 
    for (int i = 0; i < n; ++i) { 
        r += 1.0 / (double)a[i]; 
    } 
    cout << 1.0 / r << endl; 
    delete[] a; 
    return 0; 
} 

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 1023, INF = 0x3f3f3f3f, M = 2e6 + 5;
//
const ll LNF = 0x3f3f3f3f3f3f3f3f;
#define rep(i, l, r) for (int i = l; i <= r; i++)
#define per(i, r, l) for (int i = r; i >= l; i--)
#define repe(i, u) for (int i = head[u]; i; i = nxt[i])
int n, a[N][N], vis[N];
bool flag;
bool ok() {
  for (int i = 1; i <= n; i++)
    if (a[i][0] != n) return 0;
  return 1;
}

int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cin >> n;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n - 1; ++j) cin >> a[i][j];
    a[i][0] = 1;
  }
  for (int z = 0; z <= 0x3f3f3f3f; z++) {
    if (ok()) {
      cout << z << '\n';
      return 0;
    }
    flag = 0;
    memset(vis, 0, sizeof vis);
    for (int i = 1; i <= n; i++) {
      if (vis[i] || a[i][0] == n) continue;
      int x = a[i][a[i][0]];
      if (!vis[i] && !vis[x] && a[x][a[x][0]] == i) {
        a[i][0]++;
        a[x][0]++;
        vis[i] = vis[x] = 1;
        flag = 1;
      }
    }
    if (!flag) {
      cout << -1 << '\n';
      return 0;
    }
  }
  return 0;
}


Measured memory_bytes: 4352
#!/usr/bin/env python3
n = int(input())
w = list(map(int, input().split()))
s = [0] * n
s[0] = w[0]

for i in range(1, n):
        s[i] = s[i-1] + w[i]
ans = [0] * n
for j in range(n):
    ans[j] = abs(s[j] - (s[-1] - s[j]))
print(min(ans))

Measured memory_bytes: 3064
using System;
using System.Linq;
using System.Collections.Generic;
using static System.Console;
using System.Text;
using System.IO;
using static System.Math;
namespace AtCoder
{
    class Program
    {
        static public long[] Sarray() { return ReadLine().Split().Select(long.Parse).ToArray(); }
        static public List<long> Slist() { return ReadLine().Split().Select(long.Parse).ToList(); }

        static readonly long Mod = 1000000000 + 7;

        static void Main(string[] args)
        {
            //SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
            var N = Sarray()[0];
            var nums = new long[100000 + 2];
            var ai = Sarray();
            var offset = 1;
            foreach (var a in ai)
            {
                ++nums[a - 1 + offset];
                ++nums[a+offset];
                ++nums[a + 1 + offset];
            }
            WriteLine(nums.Max());
            //Out.Flush();
        }
    }
}

Measured memory_bytes: 20192
import java.io.*;
import java.util.StringTokenizer;

public class Main {

  private void solve(InputReader in, PrintWriter out) {
    int n = in.nextInt();
    long[] arr = new long[n];
    for (int i = 0; i < n; i++) {
      arr[i] = in.nextLong();
    }
    long count = 0;
    for (int i = 0; i < arr.length; i++) {
      if (arr[i] % 2 == 0) {
        while (arr[i] % 2 == 0) {
          count++;
          arr[i] = arr[i] / 2;
        }
      }
    }
    out.println(count);
  }


  public static void main(String[] args) {
    new Main().run();
  }

  private void run() {
    try (
        InputReader in = new InputReader(System.in);
        PrintWriter out = new PrintWriter(System.out)) {
      solve(in, out);
    }
  }


  static class InputReader implements AutoCloseable {
    private BufferedReader reader;
    private StringTokenizer tokenizer;

    public InputReader(InputStream stream) {
      reader = new BufferedReader(new InputStreamReader(stream), 32768);
      tokenizer = null;
    }

    public String next() {
      while (tokenizer == null || !tokenizer.hasMoreTokens()) {
        try {
          tokenizer = new StringTokenizer(reader.readLine());
        } catch (IOException e) {
          throw new RuntimeException(e);
        }
      }
      return tokenizer.nextToken();
    }

    public int nextInt() {
      return Integer.parseInt(next());
    }

    public long nextLong() {
      return Long.parseLong(next());
    }

    public double nextDouble() {
      return Double.parseDouble(next());
    }

    @Override
    public void close() {

    }
  }

}


Measured memory_bytes: 25172
#include <bits/stdc++.h>
#define load ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
using namespace std;
#define ll long long
#define ull unsigned long long
#define fori(i,n) for (int i=0; i<int(n);i++)
#define srt(v) sort(v.begin(), v.end())
#define MOD 1000000007
const int INF = 1e9;
const double PI = 3.14159265358979323846;
ll gcd(ll a, ll b) {
    return b != 0 ? gcd(b, a % b) : a;
}
ll lcm(ll a, ll b) {
    return (a * b) / gcd(a, b);
}
ll spow(ll base, ll exp){
	ll ans = 1;
	for(ll i=0;i<exp;i++) ans = ans * base % MOD;
	return ans;
}
ll divide(ll a, ll b){
	return a * spow(b, MOD-2) % MOD;
}
void solve(){
	int a, b;
	cin >> a >> b;
	
}

int main(){
	load;
    int a;
    cin >> a;
    cout << a+a*a+a*a*a;
	
}



Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int n;
  cin>>n;
  map<string,int> mp;
  for(int i=0;i<n;i++){
    string s;
    cin>>s;
    int j=mp[s];
    mp.erase(s);
    mp.emplace(s,j+1);
  }
  int m;
  cin>>m;
  for(int i=0;i<m;i++){
    string t;
    cin>>t;
    int j=mp[t];
    mp.erase(t);
    mp.emplace(t,j-1);
  }
  
  int ans=0;
  for(auto i:mp){
    ans=(i.second>ans)? i.second:ans;
  }
  cout<<ans;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
	long long n,k;
	cin>>n>>k;
	int ret=0;
	while(true){
		if((ret*9+6)%11==k)break;
		ret++;
	}
	n-=2;
	if(n<=0){cout<<"0"<<endl;return 0;}
	n*=7;
	long long ans=n/77*5;
	long long b=n%77;
	for(int i=ret;i<b;i+=11){
		if((i%7!=0)&&(i%7!=6))ans++;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <queue>
#include <cstdio>
#include <complex>
using namespace std;

const double INF = 1e12;
typedef complex<double> P,point;
typedef vector<P> G,polygon;
namespace std {bool operator < (const P& a, const P& b) {return real(a) != real(b) ? real(a) < real(b) : imag(a) < imag(b);} }
double cross(const P& a, const P& b) {return imag(conj(a)*b);}
double dot(const P& a, const P& b) {return real(conj(a)*b);}
struct L : public vector<P> {L(const P &a, const P &b) {push_back(a); push_back(b);} };
struct C {P p; double r;C(const P &p, double r) : p(p), r(r) { } C(){} };
int ccw(P a, P b, P c) {
	b -= a; c -= a;
	if (cross(b, c) > 0)   return +1;
	if (cross(b, c) < 0)   return -1;
	if (dot(b, c) < 0) return +2;
	if (norm(b) < norm(c)) return -2;
	return 0;
}
bool intersectSS(const L &s, const L &t) {return ccw(s[0],s[1],t[0])*ccw(s[0],s[1],t[1]) <= 0 && ccw(t[0],t[1],s[0])*ccw(t[0],t[1],s[1]) <= 0;}

int main()
{
	int n,m;
	cin >> n >> m;
	G g[2] = { G(n) , G(m) };
	for(int i = 0 ; i < n ; i++){
		cin >> g[0][i].real() >> g[0][i].imag();
	}
	for(int i = 0 ; i < m ; i++){
		cin >> g[1][i].real() >> g[1][i].imag();
	}
	
	double A = abs(g[0][0]-g[0][1]) , B = abs(g[1][0]-g[1][1]);
	double D[2] = {INF,INF};

	for(int s = 0 ; s < 2 ; s++){
		bool done[1000] = {};
		priority_queue< pair<double,int> , vector< pair<double,int> > , greater< pair<double,int> > > Q;
		Q.push(make_pair(0,0));
		while(Q.size()){
			double cost = Q.top().first;
			int pos = Q.top().second;
			Q.pop();
			if(done[pos]) continue;
			else done[pos] = true;
			if(pos == 1){
				D[s] = cost;
				break;
			}
			for(int i = 0 ; i < (s?m:n) ; i++){
				if(!intersectSS(L(g[s][pos],g[s][i]),L(g[!s][0],g[!s][1]))) Q.push(make_pair(cost+abs(g[s][pos]-g[s][i]),i));
			}
		}
	}
	double answer = min(A+D[1],B+D[0]);
	if(answer > 1e10){
		cout << -1 << endl;
	}else{
		printf("%.10lf\n",answer);
	}
	
	
}

Measured memory_bytes: 6260
#include<iostream>
#include<vector>
#include<string>
using namespace std;
int main(){
  int n,l;
  cin>>n>>l;
  string s;
  vector<string> vec;
  for(int i=0;i<n;i++){
    cin>>s;
    vec.push_back(s);
  }
  
  sort(vec.begin(),vec.end());
  
  for(int i=0;i<n;i++){
    cout<<vec[i];
  }
  
  return 0;
}


Measured memory_bytes: 3104
#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
#define fi first
#define se second

using namespace std;

const long long MOD = (long long)1e9 + 7;
int h, w, dp[1009][1009];
char a[1009][1009];
int main()
{
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	cin >> h >> w;
	for (int i = 1; i <= h; i++) {
		for (int j = 1; j <= w; j++) {
			cin >> a[i][j];
		}
	}
	dp[1][1] = 1;
	for (int j = 2; j <= w; j++) {
		if (a[1][j] == '.')
			dp[1][j] = dp[1][j - 1];
		else
			dp[1][j] = 0;
	}
	for (int i = 2; i <= h; i++) {
		if (a[i][1] == '.')
			dp[i][1] = dp[i - 1][1];
		else
			dp[i][1] = 0;
		for (int j = 2; j <= w; j++) {
			if (a[i][j] == '.')
				dp[i][j] = (dp[i - 1][j] + dp[i][j - 1]) % MOD;
			else
				dp[i][j] = 0;
		}
	}
	cout << dp[h][w] << "\n";
	//system("pause");
	return 0;
}

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

using namespace std;

int q;
string s;
deque<char> z;

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

	int t = 1;
	cin >> s;
	for (int i=0;i<s.size();i++)
		z.push_back(s[i]);
	cin >> q;
	while(q--)
	{
		int f;
		cin >> f;
		if (f == 1)
			t = 3 - t;
		else 
		{
			char c;
			cin >> f >> c;
			if (t == 1)
			{
				if (f == 1) z.push_front(c);
				else z.push_back(c);
			}
			else
			{
				if (f == 1) z.push_back(c);
				else z.push_front(c);
			}
		}
	}
	if (t == 1)
	{	
		while(!z.empty())
		{
			cout << z.front();
			z.pop_front();
		}
	}
	else
	{
		while(!z.empty())
		{
			cout << z.back();
			z.pop_back();
		}
	}
}

Measured memory_bytes: 976
/**
 * @Author:      G_bg
 * @DateTime:    2019-05-19 19:55:54
 * @Description: 
 */
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const double PI = 3.1415926535898;
const double E = 2.718281828459;
const int INF = 0x7fffffff;
const int mod = 1e9+7;
const int maxn = 1e5+10;
int main(int argc, char const *argv[]) {
	ios::sync_with_stdio(0);cin.tie(0);
	int n,k;cin >> n >> k;
	string str;
	cin >> str;
	str[k-1] = str[k-1]-'A'+'a';
	cout << str << endl;
	//system("pause");
	return 0;
}

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

char s[200010];
int main()
{
	cin >> s;
	int start=-1, end=-1;
	bool flag = false;
	int len = strlen(s);
	for(int i = 0;i < len;i++)
	{
		if(s[i] == 'A' && flag != true)
		{
			start = i;
			flag = true;
		}
		if(s[i] == 'Z')
		{
		    end = i;
		}
	}
	if(start > end||start==-1||end==-1)
	{
	    cout << "-1";
	}
	else
	{
	    cout << end - start + 1;
	}
	return 0;	
} 

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int kekka;
   char c;
  cin >> c;
 
 if (c == 'a' || c == 'i' || c == 'u' || c == 'e' || c == 'o') {
    cout << "vowel" << endl;
 } else {
   cout << "consonant" << endl;
 }
}


Measured memory_bytes: 256
def read_int():
    return int(input().strip())


def read_ints():
    return list(map(int, input().strip().split(' ')))


def popcount(N):
    if N == 0:
        return 0
    one_count = 0
    temp = N
    while temp > 0:
        one_count += temp%2
        temp //= 2
    return 1+popcount(N%one_count)


def solve():
    N = read_int()
    X = input()
    one_count = X.count('1')
    if one_count == 0:
        for _ in range(N):
            print(1)
        return

    new_X = [0]*N
    steps = [0]*N

    base_up = 1
    up_under_modulo = 0

    for i in range(N-1, -1, -1):
        if X[i] == '1':
            up_under_modulo = (up_under_modulo+base_up)%(one_count+1)
        if X[i] == '0':
            new_X[i] += base_up
            steps[i] = 1
        base_up = (base_up*2)%(one_count+1)

    base_down = 1
    down_under_modulo = 0

    if one_count > 1:
        for i in range(N-1, -1, -1):
            if X[i] == '1':
                down_under_modulo = (down_under_modulo+base_down)%(one_count-1)
            if X[i] == '1':
                new_X[i] -= base_down
                steps[i] = 1
            base_down = (base_down*2)%(one_count-1)

    for i in range(N):
        if X[i] == '1':
            if one_count > 1:
                new_X[i] = (new_X[i]+down_under_modulo)%(one_count-1)
        else:
            new_X[i] = (new_X[i]+up_under_modulo)%(one_count+1)

    for i in range(N):
        print(steps[i]+popcount(new_X[i]))


if __name__ == '__main__':
    solve()


Measured memory_bytes: 86548
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))


ans = 0
for i in range(n):
    ans += b[a[i] - 1]

    if i != n - 1:
        if a[i+1] - a[i] == 1:
            ans += c[a[i] - 1]

print(ans)


Measured memory_bytes: 38256
// Training Camp
#include <iostream>
using namespace std;
typedef long long LL;
const LL mod=1e9+7;

int n;

int main(){
    cin>>n;
    LL ans=1;
    for(int i=1;i<=n;i++){
        ans=(ans*i)%mod;
    }
    cout<<ans;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
// #include <atcoder/all>
// using namespace atcoder;
#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 SORT(x) sort(ALL(x))
#define RSORT(x) sort(x.rbegin(), x.rend())
#define REVERSE(x) reverse(ALL(x))
#define MAX(x) *max_element(ALL(x))
#define MAXI(x) max_element(ALL(x)) - x.begin()
#define SUM(x) accumulate(ALL(x), 0ll)
#define COUNT(x, y) count(ALL(x), y);
#define ANS cout << ans << "\n"
#define YES cout << "YES\n";
#define NO cout << "NO\n";
#define Yes cout << "Yes\n";
#define No cout << "No\n";
#define YN YES else NO
#define yn Yes else No
#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(z, v.size()) cerr << " " << v[z]; \
  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>;
using vp = vector<P>;
using vs = vector<string>;

template <typename T>
inline istream& operator>>(istream& i, vector<T>& v) {
  rep(j, v.size()) i >> v[j];
  return i;
}

template <typename T1, typename T2>
inline istream& operator>>(istream& i, pair<T1, T2>& v) {
  return i >> v.first >> v.second;
}

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;
}

template <class T>
bool chmax(T& a, const T& b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}

template <class T>
bool chmin(T& a, const T& b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}

signed main() {
  init();
  string N;
  cin >> N;

  cout << N;
  if (N.back() == 's')
    cout << "es";
  else
    cout << 's';
  ENDL;
  return 0;
}

Measured memory_bytes: 3652
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {

//        long start1 = System.currentTimeMillis();
//        long end1 = System.currentTimeMillis();
//        System.out.println("time1: " + (end1 - start1));

        Scanner scanner = new Scanner(System.in);

        String s = scanner.nextLine();
        int n = s.length();

        String s1 = s.substring(0, (n - 1) / 2);
        String s2 = s.substring((n + 3) / 2 - 1, n);

//        System.out.println("s1: " + s1);
//        System.out.println("s2: " + s2);

        if (check(s) && check(s1) && check(s2)) {
            System.out.println("Yes");
        } else {
            System.out.println("No");
        }
    }

    private static boolean check(String word) {
        StringBuffer sb = new StringBuffer(word);
        String reverse = sb.reverse().toString();
        return word.equals(reverse);
    }

}

Measured memory_bytes: 23892
#include <stdio.h>
#include "math.h"


int main(int argc, char *argv[]){

  int i, j;
  int N, K, Q;
  int m;
  int x;

  scanf("%d %d %d", &N, &K, &Q);

  int P[N];
  int A[Q];

  for(i=0; i<=Q-1; i++){
    scanf("%d", &A[i]);
  }

  for(i=0; i<=N-1; i++){
    P[i] = 0;
  }

  x = 0;
  for(j=0; j<=Q-1; j++){
    P[A[j]-1] = P[A[j]-1] + 1;
  }


  for(i=0; i<=N-1; i++){
    //printf("%d\n", P[i]);
    if(Q - P[i] >= K){
      printf("No\n");
    }else{
      printf("Yes\n");
    }
  }


  return 0;
}


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

int main(){
	int N, M;
	int max, diff;
	max = 0;
	cin >> N;
	string plus[N];
	for(int i=0;i<N;i++) cin >> plus[i];
	cin >> M;
	string minus[M];
	for(int i=0;i<M;i++) cin >> minus[i];
	for(int i=0;i<N;i++){
	  diff = 0;
	  for(int j=0;j<N;j++){
	  	if(plus[i]==plus[j]) diff++;
	  }
	  for(int j=0;j<M;j++){
	    if(plus[i]==minus[j]) diff--;
	  }
	  if(max<diff) max = diff;
	}
	cout << max << endl;
	return 0;
}

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

#define MAX_N 101
#define MAX_WEIGHT 100001
typedef long long ll;

ll n, w;
ll V[MAX_N], W[MAX_N];
ll memo[MAX_N][MAX_WEIGHT];

ll value(int id, int remW){
    if(id == n || remW == 0) return 0;
    if(memo[id][remW] != -1) return memo[id][remW];
    if(W[id] > remW) return memo[id][remW] = value(id+1,remW);
    return memo[id][remW] = max(value(id+1,remW), V[id]+value(id+1,remW-W[id]));
}

int main()
{
    cin >> n >> w;
    memset(memo,-1,sizeof memo);
    for(int j = 0; j < n; j++){
        cin >> W[j] >> V[j];
    }
    cout << value(0,w) << "\n";
}

Measured memory_bytes: 79104
// 実装3:41
#include <bits/stdc++.h>
using namespace std;

int main() {
  int n;
  cin >> n;
  vector<int>a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  sort(a.begin(), a.end(), greater<int>());
  int ans = a[0] / 2;
  for (int i = 1; i < n; i++) {
    ans += a[i];
  }
  cout << ans << endl;
}

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

#define PI 3.1415926535897932
#define MOD 1000000007
#define INF 1e9

#define REP(i, n) for(int i = 0; i < (n); i++)
#define REP1(i, n) for(int i = 1; i <= (n); i++)
#define ALL(v) (v).begin(), (v).end()
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO  cout << "NO"  << endl
#define No  cout << "No"  << endl

using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef vector<bool> vb;


void solve()
{
    int N, D; cin >> N >> D;
    vvi p(N, vi(D));
    REP(i, N)
    {
        REP(j, D) cin >> p[i][j];
    }

    int ans = 0;
    REP(i, N)
    {
        for(int j = i+1; j < N; j++)
        {
            float dist = 0;
            REP(k, D)
            {
                dist += pow(p[i][k] - p[j][k], 2);
            }
            if(ceil(sqrt(dist)) == sqrt(dist)) ans++;
        }
    }
    cout << ans << endl;
} 
    
int main() 
{
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(20);

    solve();

    return 0;
}

Measured memory_bytes: 256
while True:
  a, op, b = map(str, input().split())
  a = int(a)
  b = int(b)
  if op == '?':
    break
  if op == '+':
    print(a+b)
  if op == '-':
    print(a-b)
  if op == '*':
    print(a*b)
  if op == '/':
    print(a//b)


Measured memory_bytes: 5596
#include <bits/stdc++.h>
using namespace std;
 
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define int long long

const int N=3005;

int n;
int a[N], cache[N][N][2];

int dp(int i, int j, int player)
{
	if(j<i)
		return 0;
	int &ans=cache[i][j][player];
	if(ans!=-1)
		return ans;
	if(!player)
		ans=max(a[i]+dp(i+1, j, player^1), a[j]+dp(i, j-1, player^1));
	else
		ans=min(-a[i]+dp(i+1, j, player^1), -a[j]+dp(i, j-1, player^1));
	return ans;
}

int32_t main()
{
	IOS;
	memset(cache, -1, sizeof(cache));
	cin>>n;
	for(int i=1;i<=n;i++)
		cin>>a[i];
	cout<<dp(1, n, 0);
	return 0;
}

Measured memory_bytes: 141568