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

using VS = vector<string>;    using LL = long long;
using VI = vector<int>;       using VVI = vector<VI>;
using PII = pair<int, int>;   using PLL = pair<LL, LL>;
using VL = vector<LL>;        using VVL = vector<VL>;

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))
#define FOR(i, s, e) for (int(i) = (s); (i) < (e); (i)++)
#define FORR(i, s, e) for (int(i) = (s); (i) > (e); (i)--)
#define debug(x) cerr << #x << ": " << x << endl
const int INF = 1e9;                          const LL LINF = 1e16;
const LL MOD = 1000000007;                    const double PI = acos(-1.0);
int DX[8] = { 0, 0, 1, -1, 1, 1, -1, -1 };    int DY[8] = { 1, -1, 0, 0, 1, -1, 1, -1 };

/* -----  2018/03/03  Problem: code-festival-2016-ex-final_c / Link: https://cf16-exhibition-final.contest.atcoder.jp/tasks/cf16_exhibition_final_c?lang=en  ----- */
/* ------問題------

チーターと不正者がニムをすることになりました。 このゲームでは、N 個の石の山を使います。 最初に i 番目の山には ai 個の石があります。 チーターが先手で、交互にターンを取ります。 それぞれのターンでは、プレイヤーは一つの山を選び、その山から一個以上の石を取り除きます。 ターンが回ってきたときに操作ができなくなったプレイヤーの負けです。
しかし、ゲームが始まる前に、不正者はチーターがどのような動きをしても必ず勝つことができるように少し不正をすることにしました。 それぞれの山から、不正者は 0 個または 1 個の石を取り除き、ゲームが始まる前に食べます。 不正者が必ず勝てるようにする方法が複数通りある場合は、食べる石の個数を最小にするようにしたいです。
不正者が食べる石の個数を求めてください。 不正をしても不正者が必ず勝つようにできない場合は、-1 を出力してください。

-----問題ここまで----- */
/* -----解説等-----

すごい時間がかかった
まず可能な操作は現在の数字に対して 何もしないあるいは (ゲーム値)^(a[i])^(a[i]-1)である。
何も考えないとより良い方法としてゲーム値の2進数表現でのビットが立っている場所をたくさん0にできそうだが、それは嘘。
というのはこの操作は最下位ビットを0にする操作だからである。
したがってa[i]の最下位bitを0にできるようになったので各桁について愚直にやっていけばよい

----解説ここまで---- */

LL N;

LL ans = 0LL;



int popcount2(int x) {//二進数中のbitが1の数
	int ret = 0;
	while (x) {
		x &= x - 1;
		++ret;
	}
	return ret;
}

string to_binString(unsigned int val) //二進数表示
{
	const int size = 30;
	int index = size - 1;
	string str(size, '0');
	while (val != 0) {
		if ((val & 1) == 0)  // val は偶数か？
			str[index] = '0';  //  偶数の場合
		else
			str[index] = '1';  //  奇数の場合
		val >>= 1, index--;
	}
	return str;
}
void print_bin(int a) {
	cout << to_binString(a) << endl;
}


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



	cin >> N;
	VI a(N);
	VI cnt(31, 0);
	LL res = 0;

	FOR(i, 0, N) {
		cin >> a[i];
		res ^= a[i];
		cnt[popcount2((a[i] & -a[i]) - 1)]++;
	}

	debug(res);
	FORR(i, 30, 0 - 1) {
		if (res &(1 << i)) {
			if (cnt[i]) {
				res ^= (1 << (i + 1)) - 1;
				//debug(res);
				ans++;
			}
			else {
				break;
			}
		}
	}
	if (res)ans = -1;

	cout << ans << "\n";


	return 0;
}


Measured memory_bytes: 640
import java.util.*;

public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int h = sc.nextInt();
        int w = sc.nextInt();

        Map<Character,Integer> map = new HashMap<>();
        StringBuffer sb = new StringBuffer();
        for(int i=0 ;i<h;i++) {
            sb.append(sc.next());
        }
//        System.out.println(sb);

        for(int i=0 ;i<h*w;i++){
            char c  =  sb.charAt(i);
            int count = map.getOrDefault(c,0);
            map.put(c,count+1);
        }


        int need4 = (h/2)*(w/2);
        int need1 = 0;
        if((h%2 == 1) && (w%2 == 1)){
            need1=1;
        }

        int need2 = 0;
        if(h%2==1){
            need2+=w/2;
        }

        if(w%2==1){
            need2+=h/2;
        }

        int map4 = 0;
        int map2 = 0;
        int map1 = 0;

        Set<Character> charUniq = map.keySet();

        for(Character c : charUniq){
            int count = map.get(c);
            map4 += count/4;
            count = count%4;
            map.put(c,count);

        }

        for(Character c : charUniq){
            int count = map.get(c);
            map2 += count/2;
            count = count%2;
            map.put(c,count);
        }

        for(Character c : charUniq){
            int count = map.get(c);
            if(1 == count){
                map1 += 1;
            }
        }
//
//        System.out.println(map1);
//        System.out.println(map2);
//        System.out.println(map4);
//
//        System.out.println(need1);
//        System.out.println(need2);
//        System.out.println(need4);


        //////

        map4 = map4 - need4;
        if(map4 < 0 ){
            System.out.print("No");
            return;
        }

        map2 += map4 * 2;
        map2 = map2 - need2;
        if(map2 < 0){
            System.out.print("No");
            return;
        }

        if(map2 == 0 && map1==need1){
            System.out.print("Yes");
            return;
        }
        System.out.print("No");

    }
}

Measured memory_bytes: 23636
#include <bits/stdc++.h>
using namespace std;;
#define ll long long
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define INF 1<<30
#define LINF 1LL<<62
const int MOD = 1000000007;
 
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

int main(){
    int d,g; cin >> d >> g;
    int p[d], c[d];
    REP(i,d){
        cin >> p[i] >> c[i];
    }
    int ans = INF;
    REP(i,pow(2,d)){
        int tmpg = g;
        int maxj = -1;
        int count = 0;
        REP(j,d){
            if(i>>j & 1){
                tmpg -= (j+1) * 100* p[j] + c[j];
                count += p[j];
            }else{
                maxj = j;
            }
        }
        if(maxj==-1 || tmpg <= 0){
            ans = min(ans,count );
        }else{
            if(tmpg > (maxj+1)* 100 * p[maxj] + c[maxj]){
                continue;
            }else if(tmpg> (maxj+1) * 100* p[maxj]){
                ans = min(ans, count + p[maxj]);
            }else{
                ans  = min(ans, count + (tmpg/100 + maxj) / (maxj+1));
            }
        }
    }
    cout << ans << endl;

}

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

long long gcda(long long x, long long y){
    if(x < y) swap(x, y);
    long long r = x % y;
    if(r == 0) return y;
    else return gcda(y, r);
}

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

    long long n;
    cin >> n;

    long long ans = 0;
    for(long long i = 1; i <= n; i++){
        for(long long j = 1; j <= n; j++){
            long long g = gcda(i, j);
            for(long long k = 1; k <= n; k++){
                ans += gcda(g, k);
            }
        }
    }

    cout << ans << endl;    

    return 0;
}

Measured memory_bytes: 3640
import std.algorithm;
import std.conv;
import std.stdio;
import std.string;

void main()
{
	auto abc = readln.split.map!( to!int );
	auto k = readln.strip.to!int;
	
	writeln( solve( abc[ 0 ], abc[ 1 ], abc[ 2 ], k ) );
}

int solve( in int a, in int b, in int c, in int k )
{
	auto m = max( a, b, c );
	int md = m;
	foreach( i; 0 .. k )
	{
		md *= 2;
	}
	return a + b + c + ( md - m );

}

unittest
{
	assert( solve( 5, 3, 11, 1 ) == 30 );
	assert( solve( 3, 3, 4, 2 ) == 22 );
}


Measured memory_bytes: 256
#!/usr/bin/env python
# -*- coding:utf-8 -*-
#from __future__ import print_function

A=[[0,0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0,0]]
B=[[0,0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0,0]]
C=[[0,0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0,0]]
D=[[0,0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0,0]]
l=[]
N=int(raw_input())
for i in range(N):
    (b,f,r,v)=map(int, raw_input().split())
    if b==1: A[f-1][r-1]+=v
    elif b==2: B[f-1][r-1]+=v
    elif b==3: C[f-1][r-1]+=v
    elif b==4: D[f-1][r-1]+=v

for j in A:
    print ' '+' '.join(map(str, j))
print '#'*20 
for k in B:
    print ' '+' '.join(map(str, k))
print '#'*20 
for l in C:
    print ' '+' '.join(map(str, l))
print '#'*20 
for m in D:
    print ' '+' '.join(map(str, m))

Measured memory_bytes: 4360
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <iomanip>

using namespace std;

int S, W;

int main(void) {

	cin >> S >> W;

	if (S <= W) { cout << "unsafe" << endl; }
	else { cout << "safe" << endl; }

	return 0;
}


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

int main() {
	int n,k,d,a;
	cin >> n >> k;
	int arr[n+1]={};
	for(int i=0;i<k;i++){
	    cin >> d;
	    //cout << d << endl;
	    for(int j=0;j<d;j++){
	        cin >> a;
	        //cout << a << " ";
	        arr[a]++;
	    }
	}
	int count = 0;
	for(int i=1;i<=n;i++){
	   if(arr[i]==0){
	       count++;
	   }
	}
	cout <<  count;
	return 0;
}


Measured memory_bytes: 3636
import java.util.Scanner;

public class Main {
  public static void main(String[] args) {
    Scanner scan = new Scanner(System.in);
    String str = scan.nextLine();
    String[] datas = str.split(" ");
    int a_i = Integer.parseInt(datas[0]);
    int b_i = Integer.parseInt(datas[1]);
    if (a_i <= 8 && b_i <= 8) {
      System.out.println("Yay!");
    } else {
      System.out.println(":(");
    }
  }
}

Measured memory_bytes: 21716
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <algorithm>
using namespace std;

const int MAX_N = 100000;

int N, h[MAX_N];

int dp[MAX_N];

void solve() {
	dp[0] = 0;

	for (int i = 1; i < N; i++) {
		if (i - 2 >= 0)
			dp[i] = min(dp[i - 1] + abs(h[i] - h[i - 1]), dp[i - 2] + abs(h[i] - h[i - 2]));
		else
			dp[i] = dp[i - 1] + abs(h[i] - h[i - 1]);
	}

	printf("%d\n", dp[N - 1]);
}

int main() {
	scanf("%d", &N);
	for (int i = 0; i < N; i++) {
		scanf("%d", &h[i]);
	}

	solve();
}

Measured memory_bytes: 896
#![allow(non_snake_case, unused)]
use std::cmp::*;
use std::collections::*;
use std::f64::consts::*;

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, 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")
    };
}

fn main() {
    input!{
        a: u64,
        b: u64,
        c: u64,
    }
    /*
    let mut list = vec![&a, &b];
    list.sort();
    */
    let mut list = vec![];
    let mut cnt = 0;
    loop {
        cnt += 1;
        let m = cnt * a % b;
        if m == c {
            println!("YES");
            return;
        } else if list.contains(&m) {
            break;
        }
        list.push(m)
    }
    println!("NO");
}


Measured memory_bytes: 4352
#include<iostream>
#include<string>
using namespace std;
int main(){

  int H,W;
  cin>>H>>W;
  string data[H];
  for(int i=0;i<=H-1;i++){
  
    cin>>data[i];
  }
  for(int i=1;i<=W+2;i++){
  
    cout<<"#";
  }
  cout<<endl;
  for(int i=0;i<=H-1;i++){
  
    cout<<"#"<<data[i]<<"#"<<endl;
  }
  for(int i=1;i<=W+2;i++){
  
    cout<<"#";
  }
  cout<<endl;
  return 0;
}

Measured memory_bytes: 3616
import itertools
N = int(input())
A = list(enumerate([int(input()) for _ in range(N)]))
B = [iv[0] for iv in sorted(
    enumerate([i for i, v in sorted(A, key=lambda xs: xs[1])]),
    key=lambda xs: xs[1])]
print(sum(b % 2 == 0 for b in B[1::2]))


Measured memory_bytes: 28536
#include <bits/stdc++.h>
using namespace std;
int main()
{
    long long i,j,t,a,b,n,c,d,y,temp,m,r,sum,count,k,l,ans;
    t=1;
    // cin>>t;
    while(t--)
    {
        string s;
        cin>>s;
        ans=0;
        for(i=0;i<3;i++)
        if(s[i]=='1')ans++;
        cout<<ans;
    }
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
	Scanner in = new Scanner(System.in);
	public static void main(String[] args) {
		new Main();
	}
	public Main(){
		new AOJ2012().doIt();
	}
	
	class AOJ2012{
		
		int v;
		int calc(){
			int result = Integer.MAX_VALUE;
			for(int z=100;z>=0;z--)if(z*z*z<=v){
				for(int y=1000;y>=0;y--){
					if(z*z*z+y*y>v)continue;
					int x = v-(z*z*z+y*y);
					result = Math.min(result, x+y+z);
				}
			}
			return result;
		}
		void doIt(){
			while(in.hasNext()){
				v = in.nextInt();
				if(v==0)break;
				System.out.println(calc());
			}
		}
	}
	
}

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

using namespace std;

#pragma GCC optimization("O3")
typedef long long ll;
typedef long double ld;
const int mod = 1e9 + 7;
#define INF 1000000000

#define start_routine() int begtime = clock();
#define end_routine()                                                       \
  int endtime = clock();                                                    \
  cerr << "\nTime elapsed: " << (endtime - begtime) * 1000 / CLOCKS_PER_SEC \
       << " ms\n\n";
#define ff first
#define ss second
#define pii pair<int, int>
#define pll pair<ll, ll>
#define mll map<ll, ll>
#define sz(a) a.size()
#define all(a) a.begin(), a.end()

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
#ifndef ONLINE_JUDGE
  start_routine();
  // freopen("in.txt", "r", stdin);
  // freopen("out.txt", "w", stdout);
#endif

  ll n, k, h, ans = 0;
  cin >> n >> k;
  for (auto i = 0; i < n; i++) {
    cin >> h;
    if (h >= k) ans++;
  }
  cout << ans << "\n";

#ifndef ONLINE_JUDGE
  end_routine();
#endif
  return 0;
}

Measured memory_bytes: 256
#include<iostream>

bool ham[1000001];
int cnt[1000001];

int main()
{
	ham[1] = true;

	cnt[1] = 1;

	for( int i = 2; i <= 1000000; ++i )
	{
		if( ( i % 2 == 0 && ham[i/2] ) || ( i % 3 == 0 && ham[i/3] ) || ( i % 5 == 0 && ham[i/5] ) )
			ham[i] = true;

		cnt[i] = cnt[i-1] + ham[i];
	}

	int m, n;
	while( std::cin >> m, m )
	{
		std::cin >> n;

		std::cout << cnt[n] - cnt[m-1] << std::endl;
	}

	return 0;
}

Measured memory_bytes: 5728
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define pb push_back
#define F first
#define S second
#define rep(i,n) for(int i=0; i<n; i++)
#define rep2(i,a,b) for(int i=a; i<=b; i++)
#define drep2(i,a,b) for(int i=a; i>=b; i--)

int main()
{
   int N;
   int K;
   cin >> N;
   int array[N];
   int num[N];

   rep(i, N) 
    num[i] = 0;

   // cin >> N >> K;
   cin >> K;

   rep(i, N) {
     cin >> array[i]; 
   }

   rep(i,N) {
       num[array[i]-1]++;
   }

   vector<int> a;
   rep(i,N) {
       if (num[i] != 0)
           a.pb(num[i]);
    }
    
    sort(a.begin(), a.end());

    int ans = 0;

    int m = a.size();

    rep(i, m-K) {
        ans += a[i];
    }

    cout << ans << endl;

   
}


Measured memory_bytes: 2936
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define sz(x) (int)(x).size()
#define uni(x) x.erase(unique(rng(x)),x.end())
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
typedef set<int> S;
typedef queue<int> Q;
typedef queue<P> QP;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
const int MOD = 1000000007;
  
int main() {
  string a,b;
  cin >> a >> b;
  string c = a+b;
  int N = stoi(c);
  for(int k=1;k*k<=N;k++) {
    if(k*k==N) {
      cout << "Yes" << endl;
      return 0;
    }
  }
  cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<queue>
#include<set>

using namespace std;

int main(){
  for(int n;cin>>n,n;){
    vector<vector<char> > b(n,vector<char>(n));
    for(auto &e:b){
      for(auto &f:e){
	cin>>f;
      }
    }
    queue<int> qn;
    qn.push(0);
    queue<vector<vector<char> > > que;
    que.push(b);
    set<vector<vector<char> > > s;
    while(!que.empty()){
      int t=qn.front();
      auto c=que.front();
      bool v=false;
      int x,y;
      for(int i=0;i<n;i++){
	for(int j=0;j<n;j++){
	  v|=c[i][j]=='#';
	  if(c[i][j]=='@'){
	    y=i;
	    x=j;
	  }
	}
      }
      if(!v)break;
      qn.pop();
      que.pop();
      if(!s.insert(c).second)continue;
      for(int i=-1;i<=1;i++){
	for(int j=-1;j<=1;j++){
	  if(i||j){
	    int ny=y+i;
	    int nx=x+j;
	    if(0<=ny&&ny<n&&0<=nx&&nx<n&&c[ny][nx]=='.'){
	      auto nb=c;
	      swap(nb[y][x],nb[ny][nx]);
	      auto nn=nb;
	      for(int k=0;k<n;k++){
		for(int l=0;l<n;l++){
		  if(nn[k][l]!='@'){
		    int vc=0;
		    for(int m=-1;m<=1;m++){
		      for(int o=-1;o<=1;o++){
			if(m||o){
			  int nny=k+m;
			  int nnx=l+o;
			  vc+=0<=nny&&nny<n&&0<=nnx&&nnx<n&&nb[nny][nnx]!='.';
			}
		      }
		    }
		    nn[k][l]=(nb[k][l]=='#'&&(vc==2||vc==3)||nb[k][l]=='.'&&vc==3)?'#':'.';
		  }
		}
	      }
	      que.push(nn);
	      qn.push(t+1);
	    }
	  }
	}
      }
    }
    cout<<(que.empty()?-1:qn.front())<<endl;
  }
}

Measured memory_bytes: 7404
#include <iostream>
#include <queue>
using namespace std;
int w, h, n;
char map[1024][1024];
int d[1024][1024];
const int direction[4][2] = {
    { -1, 0 },
    { 1, 0 },
    { 0, -1 },
    { 0, 1 },
};
int factory[16][2];
typedef pair<int, int> P;
int bfs(int sx, int sy, int gx, int gy)
{
    for (int i = 0; i < h; ++i)
    {
        for (int j = 0; j < w; ++j)
        {
            d[i][j] = -1;
        }
    }
    queue<P> que;
    que.push(P(sx, sy));
    d[sx][sy] = 0;
    while (que.size())
    {
        const P p = que.front(); que.pop();
        if (p.first == gx && p.second == gy)
        {
            break;
        }
        for (int i = 0; i < 4; ++i)
        {
            int nx = p.first + direction[i][0];
            int ny = p.second + direction[i][1];
            if (0 <= nx && nx < h && 0 <= ny && ny < w && map[nx][ny] != 'X' && d[nx][ny] == -1)
            {
                que.push(P(nx, ny));
                d[nx][ny] = d[p.first][p.second] + 1;
            }
        }
    }

    return d[gx][gy];
}

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

    cin >> h >> w >> n;
    for (int i = 0; i < h; ++i)
    {
        for (int j = 0; j < w; ++j)
        {
            cin >> map[i][j];
        }
    }

    for (int i = 0; i < h; ++i)
    {
        for (int j = 0; j < w; ++j)
        {
            if (map[i][j] == 'S')
            {
                factory[0][0] = i;
                factory[0][1] = j;
                map[i][j] = '.';
            }
            else if (isdigit(map[i][j]))
            {
                int index = map[i][j] - '0';
                factory[index][0] = i;
                factory[index][1] = j;
            }
        }
    }

    int step = 0;
    for (int i = 0; i < n; ++i)
    {
        step += bfs(factory[i][0], factory[i][1], factory[i + 1][0], factory[i + 1][1]);
    }

    cout << step << endl;

    return 0;
}
///////////////////////////End Sub//////////////////////////////////

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

int main(){
	int n;
  	cin >> n;
  	map<string, int> a;
  	rep(i, n){
      	string s;
    	cin >> s;
      	a[s]++;
    }
  
  	int mx = 0;
  	for(auto x : a){
    	mx = max(mx, x.second);
    }
  
  	for(auto x : a){
    	if(x.second == mx) cout << x.first << endl;
    }
}

Measured memory_bytes: 19236
#include <bits/stdc++.h>
#include<vector>
using namespace std;
#define rep(i, n)        for(int i=0; i<(int)(n); ++i)
int main() {
  string a;
  cin>>a;
  char b=a.at(5),c=a.at(6),d=a.at(8),e=a.at(9);
  if(b=='0'&&c<='4')cout<<"Heisei";
  else cout<<"TBD";
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>

using namespace std;

int a[100000];
int xans[99999],yans[99999];

int main(){
  int i;
  int n;
  cin >> n;
  for(i = 0;i < n;i++) cin >> a[i];
  sort(a,a+n);
  int m;
  int ans;
  for(m = 0;m < n;m++) if(a[m] > 0) break;
  if(m == 0) m++;
  if(m == n) m--;
  if(m == n-1){
    ans = a[m]-a[m-1];
    xans[0] = a[m]; yans[0] = a[m-1];
    for(i = m-2;i >= 0;i--){
      xans[m-i-1] = ans; yans[m-i-1] = a[i];
      ans -= a[i];
    }
  }
  else{
    ans = a[m-1]-a[m];
    xans[0] = a[m-1]; yans[0] = a[m];
    for(i = m+1;i < n-1;i++){
      xans[i-m] = ans; yans[i-m] = a[i];
      ans -= a[i];
    }
    xans[n-1-m] = a[n-1]; yans[n-1-m] = ans;
    ans = a[n-1] - ans;
    for(i = m-2;i >= 0;i--){
      xans[n-i-2] = ans; yans[n-i-2] = a[i];
      ans -= a[i];
    }
  }
  cout << ans << endl;
  for(i = 0;i < n-1;i++)
    cout << xans[i] << ' ' << yans[i] << endl;
}


Measured memory_bytes: 3072
// The moment you think of giving up you have already lost the battle
#include <iostream>
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
typedef long long int ll;
typedef long double dl;
#define PI  3.14159265358979323846
#define M   1000000007
ll fast(ll n,ll a,ll m)
{
    if(n==0)
        return 1;
    else if(n==1)
        return a;
    else
    {
        ll r=fast(n/2,a,m);
        if(n%2==0)
        {
            return (((r%m)*(r%m))%m);
        }
        else
        {
            return (((((r%m)*a)%m)*r)%m);
        }

    }
}

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

}



Measured memory_bytes: 3632
#include <algorithm>
#include <cmath>
#include <climits>
#include <cstring>
#include <cstdio>
#include <deque>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <map> //pair is also included in this library
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

#define REP(i, s, n) for(int i = (int)(s); i < (int)(n); i++)
#define fst first
#define snd second
#define MP make_pair //incase c++11 or later is not available

using namespace std;

typedef long long int ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;

//prefer define statement
//for reason that const int ver. of INF will raise a silly warning (unused variable)
#define INF (INT_MAX/3)
#define LIM_INF (INT_MAX)
//const int INF = INT_MAX/3;
#define PI = 3.14159265358979323846
/*------------------------------------------------------------------------------*/

int main(){
  REP(i, 0, 19){
    char c;
    scanf("%c", &c);
    if(i == 5 || i == 13){
      printf(" ");
    } else {
      printf("%c", c);
    }
  }
  printf("\n");

  return 0;
}


Measured memory_bytes: 384
/*  -*- coding: utf-8 -*-
 *
 * 2876.cc: Anagram
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

const int MAX_N = 100000;
const int P = 4073;
const int MOD = 1000000009;

/* typedef */

typedef long long ll;
typedef vector<int> vi;
typedef queue<int> qi;
typedef pair<int,int> pii;

/* global variables */

int eps[MAX_N], ieps[MAX_N];
int as[MAX_N], bs[MAX_N];
int ks[MAX_N];

/* subroutines */

int powmod(int a, int b) {
  int p = 1;
  while (b) {
    if (b & 1) p = (ll)p * a % MOD;
    a = (ll)a * a % MOD;
    b >>= 1;
  }
  return p;
}

/* main */

int main() {
  int ip = powmod(P, MOD - 2);
  eps[0] = ieps[0] = 1;
  for (int i = 1; i < MAX_N; i++) {
    eps[i] = (ll)eps[i - 1] * P % MOD;
    ieps[i] = (ll)ieps[i - 1] * ip % MOD;
  }

  int n;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) scanf("%d", as + i), bs[i] = as[i];
  sort(bs, bs + n);
  int m = unique(bs, bs + n) - bs;

  int kn = 0, rh0 = 0, rh1 = 0;
  for (int k = 0; k < n; k++) {
    int i0 = lower_bound(bs, bs + m, as[k]) - bs;
    int i1 = lower_bound(bs, bs + m, as[n - 1 - k]) - bs;
    rh0 = (rh0 + (ll)i0 * eps[i0] % MOD) % MOD;
    rh1 = (rh1 + (ll)i1 * eps[i1] % MOD) % MOD;
    //printf("%d: rh0=%d, rh1=%d\n", k, rh0, rh1);
    if (rh0 == rh1) ks[kn++] = k;
  }

  for (int i = 0; i < kn; i++) {
    if (i) putchar(' ');
    printf("%d", ks[i] + 1);
  }
  putchar('\n');
  return 0;
}



Measured memory_bytes: 5120
import math


def insertion_sort(A, N, g, cnt):
    for i in range(g, N):
        v = A[i]
        j = i - g
        while j >= 0 and A[j] > v:
            A[j+g] = A[j]
            j -= g
            cnt += 1
        A[j+g] = v
    return cnt


def shell_sort(A, N, cnt):
    G = []
    g = 1
    m = 0
    while g <= N:
        G.append(g)
        m += 1
        g = 3 * g + 1
    G.reverse()

    m = len(G)
    print(m)
    print(' '.join(map(str, G)))
    for g in G:
        cnt = insertion_sort(A, N, g, cnt)

    return cnt


if __name__ == "__main__":
    N = int(input())
    A = []
    for i in range(N):
        A.append(int(input()))

    cnt = 0
    cnt = shell_sort(A, N, cnt)

    print(cnt)
    for a in A:
        print(a)



Measured memory_bytes: 45576
#include <iostream>
#include <string>

using namespace std;

int main(void) {
    int n;
    char c;
    string s;

    cin >> n;
    cin.ignore();
    
    for (int i=0; i<n; i++) {
        getline(cin, s);
        while(s.find("Hoshino") != -1) {
            s.replace(s.find("Hoshino")+6, 1, "a");
        }
        cout << s << endl;
    }

    return 0;
}

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

#define endl '\n'
#define ALL(a)  (a).begin(),(a).end()
#define ALLR(a)  (a).rbegin(),(a).rend()
#define spa << " " <<
#define test cout<<"test"<<endl;
#define fi first
#define se second
#define MP make_pair
#define PB push_back
#define EB emplace_back
#define rep(i,n,m) for(ll i = n; i < (ll)(m); i++)
#define rrep(i,n,m) for(ll i = m - 1; i >= (ll)(n); i--)
using ll = long long;
using ld = long double;
const ll MOD = 1e9+7;
//const ll MOD = 998244353;
const ll INF = 1e18;
using P = pair<ll, ll>;
template<typename T>
void chmin(T &a,T b){if(a>b)a=b;}
template<typename T>
void chmax(T &a,T b){if(a<b)a=b;}
void pmod(ll &a,ll b){a=(a+b)%MOD;}
void pmod(ll &a,ll b,ll c){a=(b+c)%MOD;}
void qmod(ll &a,ll b){a=(a*b)%MOD;}
void qmod(ll &a,ll b,ll c){a=(b*c)%MOD;}
ll median(ll a,ll b, ll c){return a+b+c-max({a,b,c})-min({a,b,c});}
void ans1(bool x){if(x) cout<<"Yes"<<endl;else cout<<"No"<<endl;}
void ans2(bool x){if(x) cout<<"YES"<<endl;else cout<<"NO"<<endl;}
void ans3(bool x){if(x) cout<<"Yay!"<<endl;else cout<<":("<<endl;}
template<typename T1,typename T2>
void ans(bool x,T1 y,T2 z){if(x)cout<<y<<endl;else cout<<z<<endl;}  
template<typename T>
void debug(vector<vector<T>>&v,ll h,ll w){for(ll i=0;i<h;i++)
{cout<<v[i][0];for(ll j=1;j<w;j++)cout spa v[i][j];cout<<endl;}};
void debug(vector<string>&v,ll h,ll w){for(ll i=0;i<h;i++)
{for(ll j=0;j<w;j++)cout<<v[i][j];cout<<endl;}};
template<typename T>
void debug(vector<T>&v,ll n){if(n!=0)cout<<v[0];
for(ll i=1;i<n;i++)cout spa v[i];cout<<endl;};
template<typename T>
vector<vector<T>>vec(ll x, ll y, T w){
  vector<vector<T>>v(x,vector<T>(y,w));return v;}
ll gcd(ll x,ll y){ll r;while(y!=0&&(r=x%y)!=0){x=y;y=r;}return y==0?x:y;}
vector<ll>dx={1,0,-1,0,1,1,-1,-1};
vector<ll>dy={0,1,0,-1,1,-1,1,-1};
template<typename T>
vector<T> make_v(size_t a,T b){return vector<T>(a,b);}
template<typename... Ts>
auto make_v(size_t a,Ts... ts){
  return vector<decltype(make_v(ts...))>(a,make_v(ts...));
}

int main(){
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  //cout<<fixed<<setprecision(10);
  ll res=0,buf=0;
  bool judge = true;
  string s;cin>>s;
  ll n=s.size();
  vector<ll>x(n);
  ll cnt=1,bcnt=0;
  rep(i,0,n){
    if(i==n-1||s[i]!=s[i+1]){
      if(s[i]=='>'){
        if(bcnt<=cnt){
          res-=bcnt;
          res+=cnt*(cnt+1)/2;
        }
        else res+=cnt*(cnt-1)/2;
      }
      else {
        bcnt=cnt;
        //if(cnt==1)continue;
        res+=(cnt)*(cnt+1)/2;
      }
      cnt=1;
      //cout<<i spa res<<endl;
    }
    else cnt++;
  }
  cout<<res<<endl;
  return 0;
}

Measured memory_bytes: 4764
n = int(input())
h = list(map(int,input().split()))
dp = [0]*(n)
dp[1] = abs(h[0]-h[1])
for i in range(2, len(dp)) :
    a = dp[i-2] + abs(h[i-2]-h[i])
    b = dp[i-1] + abs(h[i-1]-h[i])
    dp[i] = min(a, b)

print(dp[n-1])


Measured memory_bytes: 13980
#include <iostream>
using namespace std;
typedef long long ll;

ll L,R;
int main(){
    cin >> L >> R;
    if(R-L>=2019){
        cout << 0 << endl;
    }else{
        ll ans = 2e9;
        for(ll i=L;i<R;i++){
            for(ll j=i+1;j<=R;j++){
                ans = min(ans,i*j%2019);
            }
        }
        cout << ans << endl;
    }
}

Measured memory_bytes: 256
a, b, c = map(int, input().split())

num_list = []

if a > b:
    for i in range(b, 0, -1):
        if a % i == 0 and b % i == 0:
            num_list.append(i)

else:
    for i in range(a, 0, -1):
        if a % i == 0 and b % i == 0:
            num_list.append(i)

print(num_list[c-1])

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

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  string S;
  S.reserve(100000);
  int Q;
  cin >> S >> Q;

  bool flag = false;
  int T;
  int F;
  char C;

  for(int i = 0; i < Q; i++){
    cin >> T;
    if(T == 1){
      flag = !flag;
    }else{
      cin >> F >> C;
      if((!flag && F == 1) || (flag && F == 2)){
        S.insert(S.begin(), C);
      }else{
        S += C;
      }
    }
  }
  if(flag){
    reverse(S.begin(), S.end());
  }
  cout << S << endl;  
}


Measured memory_bytes: 952
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair< ll, ll > Pi;
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep2(i,n) for(int i=1;i<=(n);i++)
#define rep3(i,i0,n) for(int i=i0;i<(n);i++)
#define pb push_back
#define mod 1000000007
const ll INF = 1LL << 60;
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; }
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;}
#define all(x) x.begin(), x.end()
#define mp make_pair
bool compare(Pi a, Pi b) {
    if(a.first != b.first){
        return a.first < b.first;
        
    }else{
        return a.second < b.second;
    }
}


bool In_map(ll y,ll x,ll h,ll w){
    if(y<0 || x<0 || y>=h || x>=w){
        return 0;
    }else{
        return 1;
    }
}
const vector<ll> dx{1,0,-1,0};
const vector<ll> dy{0,1,0,-1};


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

    string U;
    U = S+T[S.size()];

    if(T==U){
        cout<<"Yes"<<endl;
    }else{
        cout<<"No"<<endl;
    }
    



    return 0;
    

}

Measured memory_bytes: 3584
#include<bits/stdc++.h>
using namespace std;
#define int ll
#define fastio ios::sync_with_stdio(); cin.tie(0); cout.tie(0);
#define pb push_back
#define ll long long
#define fi first
#define se second
#define maxn 5001

const int mod = 1e9+7 ;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef vector<pii> vii;

ll dp[maxn][maxn];

signed main()
{
//	freopen(".inp","r",stdin);
//	freopen(".out","w",stdout);
	fastio;
	int n;	cin >> n;
	string str;	cin >> str;
	int m = str.length();
	dp[0][0] = 1;
	if (n == m)
	{
		cout << "1";
		return 0;
	}
	for (int i = 1; i <= n; i++)
	{
		for (int j = 0; j <= i; j++)
		{
			if (j == 0 && i == 1)
			{
				dp[i][j] = 1;
			}
			else if (j == 0 && i > 1)
			{
				dp[i][j] = (dp[i-1][j] + (2*dp[i-1][1])%mod) % mod;
			}
			else
			{
				dp[i][j] = ((2*dp[i-1][j+1])%mod + dp[i-1][j-1]) % mod;
			}
		}
	}
	cout << dp[n][m];
}




Measured memory_bytes: 120284
#include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <map>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;

int main() {
	int N, L;
	cin >> N >> L;
	int origin = 0;
	for (int i = 1; i <= N; ++i) origin += L + i - 1;
	int ans = 0;
	int tmp = INT_MAX;
	for (int i = 1; i <= N; ++i) {
		int sum = 0;
		for (int j = 1; j <= N; ++j) {
			if (i == j) continue;
			sum += L + j - 1;
		}
		if (tmp > abs(sum - origin)) {
			tmp = abs(sum - origin);
			ans = sum;
		}
	}
	cout << ans;
}

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

using namespace std;

#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 rrep(i, n) for(int i = ((int)n - 1); i >= 0; --i)

typedef long long ll;
typedef long double ld;

const ll Inf = 1e18;
const double EPS = 1e-9;
const int MOD = 1e9 + 7;

ll modpower(ll a, ll n, ll mod) {
    if (n == 0) return 1;
    if (n % 2) {
        return modpower(a, n - 1, mod) * a % mod;
    } else {
        ll t = modpower(a, n / 2, mod);
        return t * t % mod;
    }
    // ll res = 1;
    // while (n > 0) {
    //     if (n & 1) res = res * a % mod;
    //     a = a * a % mod;
    //     n >>= 1;
    // }
    // return res;
}

// ll power(ll a, ll b, ll p) {
//     if (b == 0) return 1;
//     if (b % 2) {
//         return calc(a, b - 1, p) * a % p;
//     } else {
//         ll t = calc(a, b / 2, p);
//         return t * t % p;
//     }
// }

ll modinv(ll a, ll mod) {
    return modpower(a, mod - 2, mod);
}

ll calc(int x, int y) {
    ll res = 1;
    FOR (i, x - y + 1, x + 1) {
        res *= i;
        res %= MOD;
    }
    return res;
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(0);
    ll n;
    int a, b;
    cin >> n >> a >> b;
    ll res = (modpower(2, n, MOD) - 1) % MOD;
    ll x = calc(n, a);
    FOR (i, 1, a + 1) {
        x *= modinv(i, MOD);
        x %= MOD;
    }
    ll y = calc(n, b);
    FOR (i, 1, b + 1) {
        y *= modinv(i, MOD);
        y %= MOD;
    }
    res -= x;
    if (res < 0) res += MOD;
    res -= y;
    if (res < 0) res += MOD;
    cout << res << endl;

    return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
queue<char>a,b;
int main()
{
    string s,t;
    while(cin>>s>>t)
    {
        int flag=0;
        for(int i=s.size()-1;i>=0;i--)
            a.push(s[i]);
        for(int i=t.size()-1;i>=0;i--)
            b.push(t[i]);
        for(int i=0;i<t.size()&&!flag;i++)
        {
            if(a==b)
                flag=1;
            char c=a.front();
            a.pop();
            a.push(c);
        }
        while(!a.empty())
        {
            a.pop();
            b.pop();
        }
        if(flag)
            cout<<"Yes"<<endl;
        else
            cout<<"No"<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int a[100005];
int d[100005];
int main()
{
	int n;
	cin >> n;
	for (int i=1;i<=n;i++)
		cin >> a[i];
	int len=0;
	d[len]=1e9+5;
	for (int i=1;i<=n;i++){
		if (a[i]<=d[len]){
			d[++len]=a[i];
			continue;
		}
		int head=1, tail=len;
		while (head<tail){
			int mid=(head+tail)/2;
			if (a[i]<=d[mid]) head=mid+1;
			else tail=mid;
		}
		d[head]=a[i];
	}
	cout << len;
	return 0;
}

Measured memory_bytes: 1024
#include <stdio.h>
#include <string.h>
#define n 10000
#define q 500

int linearsearch(int );

int s[n],t[q],num1,num2;

int main(){
  int i;
  int num=0,judge;

  scanf("%d",&num1);//数列の入力
  for(i = 0 ; i < num1 ; i++)
    {
      scanf("%d",&s[i]);
    }


  scanf("%d",&num2);
  for(i = 0 ; i < num2 ; i++)
    {
      scanf("%d",&t[i]);
    }

  /*
    for(i = 0 ; i < num1 ; i++)//test print
    {
    printf("%d",s[i]);
    }

    for(i = 0 ; i < num2 ; i++)//test print
    {
    printf("%d",t[i]);
    }

  */



  for(i = 0 ; i < num2 ; i++)//search
    {
      judge = linearsearch(t[i]);

      if(judge == 1){
	num++;

	  }
    }

  printf("%d\n",num);



  return 0;
}

int linearsearch( int key)
{
  int i;
  for(i = 0 ; i < num1 ; i++)
    {
      if(key == s[i])return 1;
    }
  return 0;
}

Measured memory_bytes: 640
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <climits>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <queue>
#include <random>
#include <cctype>
#include <complex>
#include <regex>

using namespace std;

#define C_MAX(a, b) ((a)>(b)?(a):(b))
#define SHOW_VECTOR(v) {std::cerr << #v << "\t:";for(const auto& xxx : v){std::cerr << xxx << " ";}std::cerr << "\n";}
#define SHOW_MAP(v){std::cerr << #v << endl; for(const auto& xxx: v){std::cerr << xxx.first << " " << xxx.second << "\n";}}

typedef complex<double> P;
typedef pair<P, double> Circle;

#define EPS 1e-16
#define EQ(a, b) (abs((a)-(b)) < EPS)

inline int signum(double x) { return abs(x) < EPS ? 0 : x > 0 ? 1 : -1; }

double dot(P a, P b) {
    return a.real() * b.real() + a.imag() * b.imag();
}

double cross(P a, P b) {
    return a.real() * b.imag() - a.imag() * b.real();
}

P getPoint(P a, P b, P c) {
    b -= a;
    c -= a;
    double d = (dot(b, c)) / abs(b);
    P p = a + (b / abs(b) * d);
    return p;
}

double getLength(double a, double r) {
    return sqrt(r * r - a * a);
}

int main() {
//
    double cx, cy, r;
    cin >> cx >> cy >> r;

    Circle c(P(cx, cy), r);

    int Q;
    cin >> Q;

    while (Q--) {

        double x1, y1, x2, y2;
        cin >> x1 >> y1 >> x2 >> y2;

        P p1(x1, y1), p2(x2, y2);

        P mid = getPoint(p1, p2, c.first);

        double len = getLength(abs(c.first - mid), c.second);

        P ans1 = mid + (p2 - p1) / (abs(p2 - p1) + EPS) * len;
        P ans2 = mid + (p1 - p2) / (abs(p1 - p2) + EPS) * len;

        if (ans1.real() > ans2.real()) swap(ans1, ans2);
        else if (ans1.real() == ans2.real() && ans1.imag() > ans2.imag()) swap(ans1, ans2);

        cout << fixed << setprecision(20) << ans1.real() << " " << ans1.imag() << " " << ans2.real() << " " << ans2.imag() << endl;

    }

}












































Measured memory_bytes: 3356
#include <bits/stdc++.h>
    using namespace std;
     
int main(){
    	string s;
    	cin >> s;
    	int a = 0;
    	if(s.at(0) == '1'){
    		a++;
    	}
    	if(s.at(1) == '1'){
    		a++;
    	}
    	if(s.at(2) == '1'){
    		a++;
    	}
    	if(s.at(3) == '1'){
    		a++;
    	}
    	if(s.at(4) == '1'){
    		a++;
    	}
    	if(s.at(5) == '1'){
    		a++;
    	}
    	cout << a << endl;
}

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

using namespace std;

int main(){
	
	string s;
	int A[300] = {0};
	
	cin >> s;
	
	for(int i=0; i<s.size(); i++){
		A[s[i]] = 1;
	}
	
	if(A['S']==A['N'] && A['W']==A['E']) printf("Yes\n");
	//else if(A['N']==1 && A['N']==A['S']) printf("Yes\n");
	else printf("No\n");
	
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int64_t MAXN = 200010;
int64_t N;
vector<int64_t> A(MAXN);

int64_t solve()
{
  if (A[0] != 0)
  {
    return -1;
  }
  int64_t n = 0, ret = 0;
  for (int i = 0; i < N; i++)
  {
    if (A.at(i) == 0)
    {
      n = 0;
    }
    else if (A.at(i) > n + 1)
    {
      return -1;
    }
    else if (A.at(i) == n + 1)
    {
      ret++;
      n++;
    }
    else
    {
      ret += A.at(i);
      n = A.at(i);
    }
  }
  return ret;
}

int main()
{
  cin >> N;
  for (int i = 0; i < N; i++)
  {
    cin >> A.at(i);
  }
  cout << solve() << endl;
}

Measured memory_bytes: 4696
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define pp pair<int,int>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ld long double
#define al(a) (a).begin(),(a).end()
#define mk make_pair
#define check cout<<"?"<<endl;

ll MOD=1000000007;
ll mod=998244353;
int inf=1000001000;
ll INF=1e18+5;

int main(){
    int n,r=0,l=inf; cin>>n;
    vector<int> a(n,0);
    rep(i,n){
        cin>>a[i];
        l=min(l,a[i]);
        r=max(r,a[i]);
    }
    if(r-l==0){
        if((l>=1 && l<=(n/2)) || l==n-1)
        cout<<"Yes"<<endl;
        else
        cout<<"No"<<endl; 
    }
    else if(r-l>1){
        cout<<"No"<<endl;
    }
    else{
        int x=0,y=0;
        rep(i,n){
            if(a[i]==l) y++;
            if(a[i]==r) x++;
        }
        if(x/2>=r-y && r-y>0)
        cout<<"Yes"<<endl;
        else
        cout<<"No"<<endl;
    }
}

Measured memory_bytes: 640
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
const int maxn = 1e5 + 10;
int a[maxn];

int main(){
  int n;
  cin >> n;
  vector<int> id;
  for(int i = 0; i < n; ++i){
    cin >> a[i];
    id.push_back(i);
  }
  sort(id.begin() , id.end() , [&](int x , int y){
    return a[x] < a[y];
  });
  for(int i = 0; i < n; ++i){
    cout << id[i] + 1 << " ";
  }
  cout << endl;
  return 0;
}


Measured memory_bytes: 1784
import math
K = int(input())
#print("K:\t" + str(K))
count = 0
for i in range(1, K+1):
    for j in range(1, K+1):
        tmp = math.gcd(i, j)
        for k in range(1, K+1):
            count += math.gcd(tmp, k)
#            print(count)
print(count)

Measured memory_bytes: 9088
#include<bits/stdc++.h>
using namespace std;
int main(){
  string s;
  cin >> s;
  for(int i=0;i<(int)s.size()-1;++i){
    if(s.substr(i,2)=="AC") {
      cout << "Yes";
      return 0;
    }
  }
  cout << "No";
  return 0;
}

Measured memory_bytes: 256
import sys

input=sys.stdin.readline

sys.setrecursionlimit(100000)

N=int(input())
edge={i:[] for i in range(1,N+1)}
for i in range(0,N-1):
    a,b=map(int,input().split())
    edge[a].append(b)
    edge[b].append(a)
mod=10**9+7

parent={i:0 for i in range(1,N+1)}

q=set([1])
sub=set([])
while q:
    while q:
        x=q.pop()
        for p in edge[x]:
            if p!=1 and parent[p]==0:
                parent[p]=x
                sub.add(p)

        if not q:
            q=sub
            sub=set([])
            break


def dfs(num):
    if len(edge[num])==1 and num!=1:
        return (1,1)

    WHITE=1
    BLACK=1
    for i in edge[num]:
        if i!=parent[num]:
            s,t=dfs(i)
            WHITE=(WHITE*(s+t))%mod
            BLACK=(BLACK*s)%mod

    return (WHITE,BLACK)

w,b=dfs(1)
print((w+b)%mod)


Measured memory_bytes: 117740
from operator import itemgetter
N, M = map(int, input().split())
y = [list(map(int, input().split())) for i in range(M)]
for i in range(M):
    y[i].insert(0, i)
y.sort(key=itemgetter(2))
y.sort(key=itemgetter(1))
ans = []
tmp = 0
for i in range(M):
    if y[i][1] != y[i-1][1]:
        tmp = 0
    tmp += 1
    shita = str(tmp).zfill(6)
    ue = str(y[i][1]).zfill(6)
    ans.append([y[i][0], ue + shita])
ans.sort(key=itemgetter(0))
for i in range(M):
    print(ans[i][1])

Measured memory_bytes: 45604
using System;
using System.IO;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AtCoder.Contest.B
{
	static class Program
	{
		public static void Main(string[] args)
		{
			var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
			Console.SetOut(sw);

			var cin = new Scanner();

			int n = cin.NextInt();
			var a = cin.ArrayInt(n);
			double prod = 1;
            for (int i = 0; i < n; i++)
            {
				prod *= a[i];
            }
			double sum = 0;
            for (int i = 0; i < n; i++)
            {
				sum += prod / a[i];
            }
			Console.WriteLine(prod / sum);

			Console.Out.Flush();
		}
	}

	class Scanner
	{
		string[] s;
		int i;

		char[] cs = new char[] { ' ' };

		public Scanner()
		{
			s = new string[0];
			i = 0;
		}

		public string Next()
		{
			if (i < s.Length) return s[i++];
			string st = Console.ReadLine();
			while (st == "") st = Console.ReadLine();
			s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
			if (s.Length == 0) return Next();
			i = 0;
			return s[i++];
		}

		public int NextInt()
		{
			return int.Parse(Next());
		}

		public int[] ArrayInt(int N, int add = 0)
		{
			int[] Array = new int[N];
			for (int i = 0; i < N; i++)
			{
				Array[i] = NextInt() + add;
			}
			return Array;
		}

		public long NextLong()
		{
			return long.Parse(Next());
		}

		public long[] ArrayLong(int N, long add = 0)
		{
			long[] Array = new long[N];
			for (int i = 0; i < N; i++)
			{
				Array[i] = NextLong() + add;
			}
			return Array;
		}

		public double NextDouble()
		{
			return double.Parse(Next());
		}

		public double[] ArrayDouble(int N, double add = 0)
		{
			double[] Array = new double[N];
			for (int i = 0; i < N; i++)
			{
				Array[i] = NextDouble() + add;
			}
			return Array;
		}
	}
}

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

using namespace std;
using ll = long long;
using ull = unsigned long long;

#ifndef __MACRO_H__
#define __MACRO_H__

#define all(collection)  (collection).begin(), (collection).end()		// begin to end
#define rep(i, begin, end) for (ll i = begin; i < end; i++)				// repeat
#define repr(i, begin, end) for (ll i = begin; end < i; i--)			// repeat reverse

#endif


int main(void)
{
	ll l, r; cin >> l >> r; r++;

	if (2019 - 1 <= r - l)
	{
		cout << 0;
		return 0;
	}

	vector<ll> mod(2019);

	ll ans = 2019;
	ll mi = 0;
	rep(i, l, r-1)
	{
		fill(all(mod), 2019);
		mi = 0;
		rep(j, i + 1, r)
		{
			mod[mi] = (i * j) % 2019;
			mi++;
		}
		sort(all(mod));
		ans = min(mod[0], ans);
	}

	cout << ans;

	return 0;
}

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

int main() {
  string S;
  cin >> S;
    
  if (S == "Sunny") {
    cout << "Cloudy" << endl;
  }
  else if (S == "Rainy") {
    cout << "Sunny" << endl;
  }
  else if (S == "Cloudy") {
    cout << "Rainy" << endl;
  }

  return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define rep(i,n)for(int i=0;i<(int)(n);i++)
#define PI 3.141592653589793
//vector < vector<int>>a(0, vector<int>(0));二次元配列宣言


int main()
{
	int a, b, c;
	cin >> a >> b >> c;
	int ma, mi;
	ma = max(a, b);
	ma = max(ma, c);
	mi = min(a, b);
	mi = min(mi, c);
	cout << ma - mi << endl;
} 

Measured memory_bytes: 3652
#include <bits/stdc++.h>
#define int long long
using namespace std;
int a[200010];
signed main()
{
	ios::sync_with_stdio(0);
	int n;cin>>n;
	for(int i=1;i<=n;i++){
		cin>>a[i];a[i]+=a[i-1];
	}
	int ans=1e18;
	for(int i=1;i<n;i++)ans=min(ans,abs(a[i]-a[n]+a[i]));
	cout<<ans<<endl;
}

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

int main(){
    //freopen("input.txt", "r", stdin);
    //freopen("maxflow.out", "w", stdout);
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n;
    cin>>n;
    int ar[n+1],br[n];
    for(int i=0;i<n+1;i++){
        cin>>ar[i];
    }
    for(int i=0;i<n;i++){
        cin>>br[i];
    }
    ll res=0;
    for(int i=0;i<n;i++){
        if(br[i]>ar[i]){
            res+=ar[i];
            br[i]-=ar[i];
            ar[i]=0;
            if(br[i]>ar[i+1]){
                res+=ar[i+1];
                br[i]-=ar[i+1];
                ar[i+1]=0;
            }
            else{
                ar[i+1]-=br[i];
                res+=br[i];
                br[i]=0;
            }
        }
        else{
            ar[i]-=br[i];
            res+=br[i];
            br[i]=0;
        }
    }
    cout<<res<<endl;
    return 0;
}

Measured memory_bytes: 1024