akhauriyash/Code-Regression huggingface dataset:
#[doc = " https://github.com/hatoo/competitive-rust-snippets"]
#[allow(unused_imports)]
use std::cmp::{max, min, Ordering};
#[allow(unused_imports)]
use std::collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, VecDeque};
#[allow(unused_imports)]
use std::io::{stdin, stdout, BufWriter, Write};
#[allow(unused_imports)]
use std::iter::FromIterator;
mod util {
    use std::fmt::Debug;
    use std::io::{stdin, stdout, BufWriter, StdoutLock};
    use std::str::FromStr;
    #[allow(dead_code)]
    pub fn line() -> String {
        let mut line: String = String::new();
        stdin().read_line(&mut line).unwrap();
        line.trim().to_string()
    }
    #[allow(dead_code)]
    pub fn chars() -> Vec<char> {
        line().chars().collect()
    }
    #[allow(dead_code)]
    pub fn gets<T: FromStr>() -> Vec<T>
    where
        <T as FromStr>::Err: Debug,
    {
        let mut line: String = String::new();
        stdin().read_line(&mut line).unwrap();
        line.split_whitespace()
            .map(|t| t.parse().unwrap())
            .collect()
    }
    #[allow(dead_code)]
    pub fn with_bufwriter<F: FnOnce(BufWriter<StdoutLock>) -> ()>(f: F) {
        let out = stdout();
        let writer = BufWriter::new(out.lock());
        f(writer)
    }
}
#[allow(unused_macros)]
macro_rules ! get { ( $ t : ty ) => { { let mut line : String = String :: new ( ) ; stdin ( ) . read_line ( & mut line ) . unwrap ( ) ; line . trim ( ) . parse ::<$ t > ( ) . unwrap ( ) } } ; ( $ ( $ t : ty ) ,* ) => { { let mut line : String = String :: new ( ) ; stdin ( ) . read_line ( & mut line ) . unwrap ( ) ; let mut iter = line . split_whitespace ( ) ; ( $ ( iter . next ( ) . unwrap ( ) . parse ::<$ t > ( ) . unwrap ( ) , ) * ) } } ; ( $ t : ty ; $ n : expr ) => { ( 0 ..$ n ) . map ( | _ | get ! ( $ t ) ) . collect ::< Vec < _ >> ( ) } ; ( $ ( $ t : ty ) ,*; $ n : expr ) => { ( 0 ..$ n ) . map ( | _ | get ! ( $ ( $ t ) ,* ) ) . collect ::< Vec < _ >> ( ) } ; ( $ t : ty ;; ) => { { let mut line : String = String :: new ( ) ; stdin ( ) . read_line ( & mut line ) . unwrap ( ) ; line . split_whitespace ( ) . map ( | t | t . parse ::<$ t > ( ) . unwrap ( ) ) . collect ::< Vec < _ >> ( ) } } ; ( $ t : ty ;; $ n : expr ) => { ( 0 ..$ n ) . map ( | _ | get ! ( $ t ;; ) ) . collect ::< Vec < _ >> ( ) } ; }
#[allow(unused_macros)]
macro_rules ! debug { ( $ ( $ a : expr ) ,* ) => { eprintln ! ( concat ! ( $ ( stringify ! ( $ a ) , " = {:?}, " ) ,* ) , $ ( $ a ) ,* ) ; } }
const BIG_STACK_SIZE: bool = true;
#[allow(dead_code)]
fn main() {
    use std::thread;
    if BIG_STACK_SIZE {
        thread::Builder::new()
            .stack_size(32 * 1024 * 1024)
            .name("solve".into())
            .spawn(solve)
            .unwrap()
            .join()
            .unwrap();
    } else {
        solve();
    }
}
fn solve() {
    let x = get!(u64);
    let ans = (2..x)
        .map(|a| {
            let mut t = a * a;
            if t > x {
                return 1;
            }
            while t * a <= x {
                t *= a;
            }
            t
        }).max()
        .unwrap_or(1);

    println!("{}", ans);
}


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

int main() {
  long long int yen;
  cin>>yen;
  int sum=0;
  long long int money=100;
  while(money<yen){
    money*=1.01;
    sum++;
  }
  cout<<sum<<endl;
}

Measured memory_bytes: 3632
H, W = map(int, input().split())
s = list(list(input()) for _ in range(H))
ans = True
d = [(0,1),(0,-1),(1,0),(-1,0)]
for y in range(H):
    for x in range(W):
        if s[y][x] == "#":
            for dy, dx in d:
                ny = y + dy
                nx = x + dx
                if ny<0 or H<=ny or nx<0 or W<=nx:
                    continue
                if s[ny][nx]=="#":
                    break
            else:
                ans = False
print("Yes" if ans else "No")

Measured memory_bytes: 9216
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Globalization;
using System.Linq;
using System.Runtime.InteropServices.ComTypes;
using System.Text;
using System.Threading;

class Program
{
    static void Main(string[] args)
    {
        var n = int.Parse(Console.ReadLine());
        var s = Console.ReadLine();
        Console.WriteLine(CountChar(s,"ABC"));

    }

    public static int CountChar(string s, string c)
    {
        return (s.Length - s.Replace(c , "").Length)/3;
    }



}

Measured memory_bytes: 26952
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
using P   = pair<ll, ll>;
using mat = vector<vector<ll>>;

void IOS() { ios::sync_with_stdio(false), cin.tie(0); }

const ll INF = 1e16;
const ll MOD = 1e9 + 7;

ll mod(ll a) {
	if (a > 0) return a % MOD;
	if (a % MOD == 0) return 0;
	ll x = -a / MOD + 1;
	a += x * MOD;
	return a % MOD;
}

template <typename T> void dump(T x) { cout << x << endl; }
template <typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val) {
	fill((T *)array, (T *)(array + N), val);
}
// int dx[4]    = {1, 0, -1, 0};
// int dy[4]    = {0, 1, 0, -1};
// ll pas[5001][5002];

ll cnt[26] = {};

int main() {
	IOS();
	string s, t;
	t = "";
	cin >> s;
	int r  = s.size() - 1;
	int l  = 0;
	ll ans = 0;
	while (l < r) {
		if (s[l] == s[r]) {
			l++;
			r--;
		} else if (s[l] == 'x')
			l++, ans++;
		else if (s[r] == 'x')
			r--, ans++;
		else {
			dump(-1);
			return 0;
		}
	}
	dump(ans);
}

Measured memory_bytes: 512
from collections import deque
H, W = map(int, input().split())
maze = [list(input()) for _ in range(H)]
direction = [[0, 1], [1, 0], [0, -1], [-1, 0]]

ans = 0
for sh in range(H):
    for sw in range(W):
        if maze[sh][sw] == "#":
            continue

        dist = [[-1] * W for _ in range(H)]
        dist[sh][sw] = 0
        que = deque([[sh, sw]])

        while que:
            nh, nw = que.pop()
            for dh, dw in direction:
                if not ((0 <= nh + dh < H) and (0 <= nw + dw < W)):
                    continue
                if maze[nh + dh][nw + dw] == "#":
                    continue
                if dist[nh + dh][nw + dw] != -1:
                    continue

                dist[nh + dh][nw + dw] = dist[nh][nw] + 1
                que.appendleft([nh + dh, nw + dw])

        ans = max(ans, max([max(d) for d in dist]))

print(ans)

Measured memory_bytes: 9436
#include <iostream>

using namespace std;

int main()
{
  int r, g, b;
  cin >> r >> g >> b;
  if ((100 * r + 10 * g + 1 * b) % 4 == 0) cout << "YES" << endl;
  else                                     cout << "NO" << endl;
  return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <climits>
#include <cmath>
#include <csignal>
#include <cstdio>
#include <cstdlib>
#include <iomanip>
#include <iostream>
#include <string>
#include <vector>

using ll = long long;
using namespace std;

int main() {
    ll x = 0, y = 0;
    cin >> x >> y;
    if (x < y) {
        if (x*y >= 0) {
            cout << y-x << endl;
        }
        else {
            cout << abs(abs(y)-abs(x)) + 1 << endl;
        }
    }
    else if (x == y) {
        cout << 0 << endl;
    }
    else {
        if (x*y > 0) {
            cout << x-y+2 << endl;
        }
        else if (x*y == 0) {
            cout << x-y+1 << endl;
        }
        else {
            cout << abs(abs(x)-abs(y)) + 1 << endl;
        }
    }
    return 0;
}


Measured memory_bytes: 256
<?php
 
list($n, $m) = explode(' ', trim(fgets(STDIN)));

$s = [];
for($i=0; $i<$n; $i++){
  list($a, $b) = explode(' ', trim(fgets(STDIN)));
  isset($s[$a])? $s[$a] += $b : $s[$a] = $b;
}

ksort($s);

$p = 0;
$c = 0;
foreach($s as $k => $v){
  if ($c == $m) break;
  $min = min($v, $m-$c);
  $p += $k*$min;
  $c += $min;
}

echo intval($p);

?>

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

using namespace std;

int h,w;

bool in(int r,int c)
{
    if(r<0||c<0||r>=h||c>=w) return 0;
    else return 1;
}

int main()
{
    cin >> h >> w;
    string s[h];
    for(int i=0;i<h;i++) cin >> s[i];
    queue<int> q;
    int d[h][w];
    for(int o=0;o<h;o++)
    {
        for(int i=0;i<w;i++)
        {
            if(s[o][i]=='#')
            {
                d[o][i]=0;
                q.push(o);
                q.push(i);
            }
            else d[o][i]=-1;
        }
    }
    int res=0;
    int dx[4]={0,1,0,-1};
    int dy[4]={1,0,-1,0};
    while(!q.empty())
    {
        int e=q.front();
        q.pop();
        int f=q.front();
        q.pop();
        for(int i=0;i<4;i++)
        {
            if(in(e+dy[i],f+dx[i])&&d[e+dy[i]][f+dx[i]]==-1)
            {
                q.push(e+dy[i]);
                q.push(f+dx[i]);
                d[e+dy[i]][f+dx[i]]=d[e][f]+1;
                res=max(res,d[e+dy[i]][f+dx[i]]);
            }
        }
    }
    cout << res << endl;
    return 0;
}


Measured memory_bytes: 13456
#include<bits/stdc++.h>
#define two(a) (1<<(a))
#define LINF (1ll<<61)
#define EPS (1e-14)
#define Lshift(a,b) (a<<b)
#define Rshift(a,b) (a>>b)
#define rep(a,b) for(a=0 ; a<b ; a++)
#define xrep(a,b,c) for(a=b ; a<c ; a++)
#define INF (1<<29)
#define swap(a,b) ( (a^=b) , (b^=a) , (a^=b) )
#define GET(x) (mark[x>>5]>>(x&31)&1)
#define SET(x) (mark[x>>5]|=1<<(x&31))
#define maxL (10000000>>5)+1
#define mod 1000000007
#define vi vector<int>
#define pii pair<int, int>
#define mii map<int, int>
#define si set<int>
#define pb push_back
typedef long long ll;
using namespace std;


char s[100100];
int cnt[100];
ll dp[27];

int main() {
    ios_base::sync_with_stdio(false); cin.tie(NULL);
    int i;
    ll n;
    cin >> n >> s;
    rep(i, n) { cnt[s[i] - 'a']++; }
    dp[0] = cnt[0];
    xrep(i, 1, 26) {
        dp[i] = (cnt[i] + 1) * (dp[i-1]) % mod;
        dp[i] = (dp[i] + cnt[i]) % mod;
    }
    cout << dp[25] << endl;
}


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

int main(){
  int N,L;
  cin>>N>>L;
  int sum=0;
  for(int i=0;i<N;++i) sum += L+i;
  int ans=100000;
  int ind=0;
  for(int i=0;i<N;++i){
    if(ans>abs(L+i)){
      ans=abs(L+i);
      ind=i;
    }
  }

  cout<<sum-(L+ind)<<endl;
}

Measured memory_bytes: 256
let a, b = Scanf.scanf " %s %s" @@ fun a b -> a, b
let n = int_of_string @@ a ^ b
let i = ref 1
let _ = while !i * !i <= 100100 do if !i * !i = n then (print_endline "Yes"; exit 0); incr i done; print_endline "No"

Measured memory_bytes: 384
#include<bits/stdc++.h>
#define ff(x,a,b) for(int x=a;x<=b;x++)
#define fff(x,a,b) for(int x=a;x>=b;x--)
#define void inline void
using namespace std;
typedef long long ll;
int n,a[200005],b[200005],t;
int main()
{
	cin>>n;
	ff(i,1,n) scanf("%d",a+i);
	fff(i,n,1)
	{
		if(i*2>n) b[i]=a[i];else
		{
			int sum=0;
			for (int j=i<<1;j<=n;j+=i) sum=(sum+b[j])&1;
			b[i]=sum^a[i];
		}
	}
	ff(i,1,n) t+=b[i];
	cout<<t<<endl;
	ff(i,1,n) if(b[i]) printf("%d ",i);
}

Measured memory_bytes: 2432
//This Code was made by Chinese_zjc_.
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<vector>
#include<bitset>
#include<cmath>
#include<queue>
#include<stack>
#include<string>
#include<cstring>
#include<cstdio>
#include<cstdlib>
#include<map>
#include<set>
#include<time.h>
// #include<windows.h>
#define int long long
#define PI 3.14159265358979323
#define INF 0x3fffffffffffffff
#define MOD 998244353
using namespace std;
int dp[3005][3005],a,b,c,d;
signed main()
{
    ios::sync_with_stdio(false);
    cin>>a>>b>>c>>d;
    dp[a][b]=1;
    for(int i=a;i<=c;++i)
    {
        for(int j=b;j<=d;++j)
        {
            // if(i==a&&j==b)
            // {
            //     continue;
            // }
            dp[i][j]+=(dp[i-1][j]*j%MOD+dp[i][j-1]*i%MOD-dp[i-1][j-1]*(i-1)%MOD*(j-1)%MOD+MOD)%MOD;
        }
    }
    cout<<dp[c][d]<<endl;
    return 0;
}

Measured memory_bytes: 74080
#include <bits/stdc++.h>
#define REP(i, n) for(int i=0; i<(int)(n); i++)
#define REP1(i,a,b) for(int i=a; i<=(int)(b); i++)
#define ALL(x) begin(x),end(x)
#define PB push_back
using namespace std;
typedef int64_t LL;
typedef vector<int> VI;
typedef pair<int,int> PII;

template<class T> inline bool chmax( T &a, const T &b ) { return b>a ? a=b,true : false; }
template<class T> inline bool chmin( T &a, const T &b ) { return b<a ? a=b,true : false; }
template<class T> using MaxHeap = priority_queue<T>;
template<class T> using MinHeap = priority_queue<T, vector<T>, greater<T>>;
template<class T, class F=less<T>> void sort_uniq( vector<T> &v, F f=F() ) {
    sort(begin(v),end(v),f);
    v.resize(unique(begin(v),end(v))-begin(v));
}

const int N=3e5+10;
int f[N]; // f[i]: frequency of number i
int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    
 	int n;
 	cin >> n;
 	REP(i,n) {
 		int a;
 		cin >> a;
 		--a;
 		f[a]++;
 	}
 	sort(f,f+n);
 	vector<int> s(n+1,0);
 	REP(i,n) s[i+1]=s[i]+f[i];
	auto solution1=[&](int n,vector<int> s){
	 	// O(nlognlogn):
	 	// n: 1->n
	 	// logn: for every k find max remove steps by bsearch
	 	// logn: bsearch check
	 	for(int k=1; k<=n; k++) {
			int l=0,r=n/k+1;
			while(r-l>1) {
				int x=(l+r)/2;
				bool ok=[&] {
					int i=lower_bound(f,f+n,x)-f;
					int tot=(n-i)*x + s[i];
					return tot>=x*k; // 一次取k個 取x次 所需總共數量
				}();
				if(ok) l=x; else r=x;
			}
			cout << l << '\n';
	 	} 		
 	};
	auto solution2=[&](int n, vector<int> s){
		// 因為可移除的次數隨著k上升單調遞減，所以可以降為O(N)
		int ans=n,i=n;
	 	for(int k=1; k<=n; k++) {
			while(1) {
				while(i>0 && f[i-1]>ans) --i;
				if(ans*(n-i)+s[i]>=k*ans) break;
				ans--;
			}		
			cout << ans << '\n';
	 	} 		
 	};
 	solution2(n,s);
    return 0;
}

Measured memory_bytes: 4352
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
using namespace std;
typedef long long ll;
typedef unsigned int ui;
const ll mod = 1000000007;
typedef long double ld;
const ll INF = 1e+14;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef complex<ld> Point;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<ld, ld> LDP;
typedef pair<ll, ll> LP;
#define fr first
#define sc second
#define all(c) c.begin(),c.end()
#define pb push_back
 
void Yes(){
	cout<<"Yes"<<endl;
	exit(0);
}
 
void No(){
	cout<<"No"<<endl;
	exit(0);
}
 
int main(){
  ll A,B,C;
  cin>>A>>B>>C;
  ll ans;
  if(C>(A-B))
    ans=C-(A-B);
  else
    ans=0;
  cout<<ans<<endl;
}



Measured memory_bytes: 256
#include<iostream>
#include<unordered_map>
#include<vector>
#include<algorithm>
#include<cmath>
#include<string>
#include<queue>
using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;
typedef long double ld;
#define mp make_pair
#define pb push_back
const ll mod = 1000000007;

void sayNo() {
	cout << "No" << endl;
}

void sayYes() {
	cout << "Yes" << endl;
}

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

	 int maxi = 0;
	 int max = 0;
	 vector<int> A;

	 for (int i = 0; i < N; i++) {
		 int a;
		 cin >> a;
		 A.push_back(a);
		 if (a > max) {
			 max = a;
			 maxi = i;
		 }
	 }
	 sort(A.begin(), A.end());


	 for (int i = 0; i < N; i++) {
		 int a = max;
		 if (i == maxi) {
			 a = A[N-2];
		 }
		 cout << a << endl;
	 }

	return 0;
}

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

int main() {
    Int k;
    int n; cin >> n >> k;
    vector<int> a(n), b(n);
    vector<Int> cnt(100001);
    //rep(i, n) {
    //    cin >> a[i] >> b[i];
    //}
    vector<int> c(n+1);
    rep(i, n) {
        int a, b;
        cin >> a >> b;
        cnt[a] += (Int)b;
    }
    int ii = 0;
    for (int i = 1; i < 100001; i++) {
        if (cnt[i] >= (Int)k) {
            cout << i << endl;
            break;
        }
        k -= (Int)cnt[i];
        //cout << k << endl;
    }
}


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

int main(){
    int n, k;
    cin >> n >> k;
    int A[n], min_pos;
    for(int i=0;i<n;i++){
        cin >> A[i];
        if(A[i] == 1){
            min_pos = i+1;
        }
    }

    int Ans = 0;
    if(n == k){
        Ans = 1;
    }
    else if((min_pos-1)%(k-1) == 0 && (n-min_pos)%(k-1) == 0){
        Ans = (min_pos-1)/(k-1) + (n-min_pos)/(k-1);
    }
    else if((min_pos-1)%(k-1) == 0 || (n-min_pos)%(k-1) == 0){
        Ans = (min_pos-1)/(k-1) + (n-min_pos)/(k-1) +1;
    }
    else{
        Ans += (min_pos-1)/(k-1) +1;
        min_pos += k -1 - (min_pos-1)%(k-1);
        if((n-min_pos)%(k-1) == 0){
            Ans += (n-min_pos)/(k-1);
        }
        else{
            Ans += (n-min_pos)/(k-1) +1;
        }
    }

    cout << Ans << endl;
    return 0;
}

Measured memory_bytes: 640
#include <iostream>

int main()
{
  int r,d,x;

  std::cin >> r;
  std::cin >> d;
  std::cin >> x;

  int a = r*x -d;

  std::cout << a << std::endl;

  for (int i=0; i < 9; ++i){
    a = r*a -d;
    std::cout << a << std::endl;
  }
  
}


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

int main()
{
int k;cin>>k;
int ar[32]={1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};


cout<<ar[k-1];


return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
ll mod=1e9+7;

int main(){
  ll N,a[10000],b[10000];
  cin>>N;
  for (int i(0);i<N;i++) cin>>a[i];
  for (int i(0);i<N;i++) cin>>b[i];
  ll suma(0),sumb(0);
  for (int i(0);i<N;i++) suma+=a[i];
  for (int i(0);i<N;i++) sumb+=b[i];
  ll cnt = sumb-suma;
  if (cnt<0){
    cout << "No" << endl;
    return 0;
  }
  ll cnta(0),cntb(0);
  for (int i(0);i<N;i++){
    if (a[i]==b[i]) continue;
    else if (a[i]<b[i]){
      if ((b[i]-a[i])%2==1){
        cnta+=(b[i]-a[i])/2+1;
        cntb+=1;
      }else{
        cnta+=(b[i]-a[i])/2;
      }
    }else{
      cntb+=(a[i]-b[i]);
    }
  }
  //cout << cnt << " " << cnta << " " << cntb << endl;
  if ((cnt-cnta)*2==(cnt-cntb)&&cnt>=cnta&&cnt>=cntb) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
typedef long long ll;
#define INF 1000000000
#define MOD 1000000007
int dx[4]={1,0,-1,0},dy[4]={0,-1,0,1};
using namespace std;
int main(void){
   string S,T;
   cin>>S>>T;
   map<char,char>ma,ima;
   bool ans=true;
   for(int i=0;i<S.size();i++){
      char s,t;
      s=S[i];
      t=T[i];
      if(ma.count(s)){
         if(ma[s]!=t){
            ans=false;
         }
      }
      if(ima.count(t)){
         if(ima[t]!=s){
            ans=false;
         }
      }
      ma[s]=t;
      ima[t]=s;
   }
   if(ans){
      cout<<"Yes"<<endl;
   }else{
      cout<<"No"<<endl;
   }
   return 0;
}

Measured memory_bytes: 776
#include <stdio.h>
#define true 1
#define false 0
#define Free 2
#define NotFree 3
#define put 4
#define notPut 5
#define N 8
void putQueen(int);
void printBoard(void);
int row[N], col[N], dpos[2*N-1], dneg[2*N-1], board[N][N], n;
int main()
{
  //8クイーン問題を求めるプログラム
  int i, j, gyou, retsu;

  for(i = 0 ; i < N ; i++){
    for(j = 0 ; j < N ; j++){
      board[i][j] = notPut; }
  }
  for(i = 0 ; i < N ; i++){
    row[i] = Free;
    col[i] = Free; }
  for(i = 0 ; i < 2 * N - 1 ; i++){
    dpos[i] = Free;
    dneg[i] = Free; }

  scanf("%d",&n);

  for(i = 0 ; i < n ; i++){
    scanf("%d%d",&gyou,&retsu);
    board[gyou][retsu] = put; }

  putQueen(0);
  
  return 0;
}

void putQueen(int i)
{
  int j;

  if(i == N){ //クイーンの配置に成功した。
    printBoard();
    return; }

  for(j = 0 ; j < N ; j++){
    if(col[j] == NotFree || dpos[i+j] == NotFree || dneg[i-j+N-1] == NotFree) continue;
    row[i] = j; // (1) 
    col[j] = dpos[i+j] = dneg[i-j+N-1] = NotFree; // (1)
    putQueen(i+1); //次の行を試してみる。
    col[j] = dpos[i+j] = dneg[i-j+N-1] = Free;/*(i,j)に配置されているクイーンを消す。*/ }
  //クイーンの配置に失敗した。

  //(1)は(i,j)にクイーンを配置している過程を表す。
  
}

void printBoard(void)
{
  int i, j, condition;

  condition = true;
    
  for(i = 0 ; i < N ; i++){
    for(j = 0 ; j < N ; j++){
      if(board[i][j] == put && row[i] != j) condition = false; }
  }

  if(condition == true){
    for(i = 0 ; i < N ; i++){
      for(j = 0 ; j < N ; j++){
	if(row[i] == j) printf("Q");
	else printf("."); }
      printf("\n"); }
  }
  
  return;
}



Measured memory_bytes: 2108
#include<bits/stdc++.h>
#define For(i,x,y) for (register int i=(x);i<=(y);i++)
#define FOR(i,x,y) for (register int i=(x);i<(y);i++)
#define Dow(i,x,y) for (register int i=(x);i>=(y);i--)
#define Debug(v) for (auto i:v) printf("%lld ",i);puts("")
#define mp make_pair
#define fi first
#define se second
#define pb push_back
#define ep emplace_back
#define siz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define fil(a,b) memset((a),(b),sizeof(a))
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pa;
typedef pair<ll,ll> PA;
typedef vector<int> poly;
inline ll read(){
    ll x=0,f=1;char c=getchar();
    while ((c<'0'||c>'9')&&(c!='-')) c=getchar();
    if (c=='-') f=-1,c=getchar();
    while (c>='0'&&c<='9') x=x*10+c-'0',c=getchar();
    return x*f;
}

const int N = 2e5+10;
int n;
char s[N];

int main(){
	scanf("%s",s+1),n=strlen(s+1);
	int ans=1,l=2,len=1;
	while (l<=n){
		if (len==2) l++,len=1,++ans;
		else if (s[l]==s[l-1]) l+=2,len=2,++ans;
		else l++,len=1,++ans;
	}
	if (l>n+1) ans--;
	printf("%d\n",ans);
}

Measured memory_bytes: 3928
// C - Low Elements
#include <bits/stdc++.h>
using namespace std;

int main(){
    int n;
    cin >> n;
    vector<int> p(n);
    for(int i=0; i<n; i++) cin >> p[i];
    int ans = 1, minp = p[0];
    for(int i=1; i<n; i++){
        if(minp > p[i]){ minp = p[i]; ans++; }
    }
    cout << ans << endl;
}

Measured memory_bytes: 1024
import sys
def drawable(s, i, j):
    if s[i - 1][j] == '#' or s[i + 1][j] == '#' or \
            s[i][j - 1] == '#' or s[i][j + 1] == '#':
        return True
    return False

H, W = map(int, raw_input().split())
s = [['.'] * (W + 2)]
s += [['.'] + list(raw_input()) + ['.'] for _ in range(H)]
s += [['.'] * (W + 2)]
for i in range(1, H + 1):
    for j in range(1, W + 1):
        if s[i][j] == '#' and not drawable(s, i, j):
            print 'No'
            sys.exit()
print 'Yes'


Measured memory_bytes: 2692
n=int(input())
total=0
allsame=1
minb=10**9+1
for _ in range(n):
  a,b=map(int,input().split())
  total+=a
  if a>b:
    allsame=0
    minb=min(b,minb)
if allsame==1:
  print(0)
else:
  print(total-minb)
    

Measured memory_bytes: 76548
#include<stdio.h>
int main(){
  int n,q,i,j,k,c,f;
  int s[10000],t[500];

  c=0;
  
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&s[i]);
  }

  scanf("%d",&q);
  for(i=0;i<q;i++){
    scanf("%d",&t[i]);
  }
  
  for(i=0;i<q;i++){
    f=0;
    k=t[i];
    for(j=0;j<n;j++){
      if(s[j]==k){
	if(f==0){
	c++;
	f=1;
	}
      }
    }
  }
  printf("%d\n",c);
  return 0;
}

  



Measured memory_bytes: 2128
#include <iostream>
#include <string>
#include <cmath>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<iomanip>
#define _USE_MATH_DEFINES
#include <math.h>
#include <functional>
#include<complex>
using namespace std;

#define rep(i,x) for(ll i=0;i<x;i++)
#define repn(i,x) for(ll i=1;i<=x;i++)

typedef long long ll;
const ll INF = 1e17;
const ll MOD = 998244353;
const ll MAX = 4000001;
const double eps = 1E-18;

ll max(ll a, ll b) {
	if (a > b) { return a; }
	return b;
}

ll min(ll a, ll b) {
	if (a > b) { return b; }
	return a;
}

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

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

struct edge {
	ll ind;
	ll fr;
	ll to;
	ll d;
};

class mint {
	long long x;
public:
	mint(long long x = 0) : x((x% MOD + MOD) % MOD) {}
	mint operator-() const {
		return mint(-x);
	}
	mint& operator+=(const mint& a) {
		if ((x += a.x) >= MOD) x -= MOD;
		return *this;
	}
	mint& operator-=(const mint& a) {
		if ((x += MOD - a.x) >= MOD) x -= MOD;
		return *this;
	}
	mint& operator*=(const  mint& a) {
		(x *= a.x) %= MOD;
		return *this;
	}
	mint operator+(const mint& a) const {
		mint res(*this);
		return res += a;
	}
	mint operator-(const mint& a) const {
		mint res(*this);
		return res -= a;
	}
	mint operator*(const mint& a) const {
		mint res(*this);
		return res *= a;
	}

	mint pow(ll t) const {
		if (!t) return 1;
		mint a = pow(t >> 1);
		a *= a;
		if (t & 1) a *= *this;
		return a;
	}

	// for prime MOD
	mint inv() const {
		return pow(MOD - 2);
	}
	mint& operator/=(const mint& a) {
		return (*this) *= a.inv();
	}
	mint operator/(const mint& a) const {
		mint res(*this);
		return res /= a;
	}

	friend ostream& operator<<(ostream& os, const mint& m) {
		os << m.x;
		return os;
	}
};

mint pw(mint a, ll b) {
	if (b == 0) { return 1; }
	mint ret = pw(a, b>>1);
	ret *= ret;
	if (b & 1) { ret *= a; }
	return ret;
}

typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef vector<vector<vector<ll>>> vvvll;

typedef vector<mint> vmint;
typedef vector<vector<mint>> vvmint;
typedef vector<vector<vector<mint>>> vvvmint;

//////////////////////////////////////


int main() {
	string T;
	cin >> T;
	rep(i, T.size()) {
		if (T[i] == 'P') { cout << 'P'; }
		else { cout << 'D'; }
	}
	cout << endl;
}


Measured memory_bytes: 3756
def dist(ai:int, bi:int, aj:int, bj:int):
    return abs(ai-aj)+abs(bi-bj)

h, w, d = map(int, input().split())
p = {}
for i in range(h):
    tmpstr = input().split()
    for j in range(w):
        tmpchar = int(tmpstr[j])
        p[tmpchar] = (i, j)
dsum = [0]*d
for i in range(d, h*w):
    curl, curr = p[i+1]
    prel, prer = p[i-d+1]
    diff = dist(curl, curr, prel, prer)
    tmpd = dsum[i-d]+diff
    dsum.append(tmpd)

q = int(input())
for _ in range(q):
    l, r = map(int, input().split())
    print(dsum[r-1]-dsum[l-1])


Measured memory_bytes: 22548
#include <bits/stdc++.h>
#define For(i,a,b) for(int i=a;i<=b;i++)
#define F first
#define S second
#define all(x) x.begin(),x.end()
#define sz(x) ((int)(x).size())
using namespace std;
using ll=long long;
using pii=pair<int,int>;

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

int32_t main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	
	int a,b,c;
	cin>>a>>b>>c;
	cout<<b*(c/a)<<"\n";
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>				//Written by ThiDaiLoc
using namespace std;				//Team Three Wolves
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll,ll> pll;
typedef pair<ll,pll> trp;
typedef vector<ll> vi;
typedef vector<pll> vp;

#define fu(i,a,b)   for(ll i=a;i<=b;i++)
#define f1(i,n)     for(ll i=1;i<=n;i++)
#define fs(i,s)     for(ll i=0;i+1<=s.length();i++)
#define fd(i,b,a)   for(ll i=b;i>=a;i--)
#define fuv(i,a)    for(ll i=0;i<a.size();i++)
#define fdv(i,a)    for(ll i=(ll)a.size()-1;i>=0;i--)
#define ms(a,x)     memset(a, x, sizeof a)
#define prec(n)     fixed<<setprecision(n)
#define uni(a)      (a).erase(unique(all(a)), (a).end())
#define pb(i)       push_back(i)
#define pob         pop_back()
#define sc(a)       cin>>a
#define sc2(a,b)    cin>>a>>b
#define sc3(a,b,c)  cin>>a>>b>>c
#define pr(a)       cout<<a<<endl
#define pr2(a,b)    cout<<a<<" "<<b<<endl
#define rpr(a)      return cout<<a<<endl,0
#define prY         cout<<"Yes"<<endl
#define prN         cout<<"No"<<endl
#define bit(n,i)    (((n)>>(i))&1)
#define lowb(a,n,x) lower_bound(a,a+n,x) -a
#define lowb2(a,x)  lower_bound(all(a),x) -a.begin()
#define all(x)      (x).begin(), (x).end()
#define sz(a)       (ll)a.size()
#define le(s)       (ll)s.length()		
#define re          return 	
#define	mp(a,b)     make_pair(a,b)
#define	mp3(a,b,c)  make_pair(a,make_pair(b,c))
#define se          second
#define fi          first 
#define sse         second.second
#define sfi         second.first
#define soA         sort(A+1,A+1+n)
#define so(A,n)     sort(A+1,A+1+n)
#define sov(v)      sort(all(v))
#define sovr(v)     sort(all(v),greater<ll>())
#define debug(x)    cerr << #x << " = " << x << endl
#define INPUT       freopen("locin.txt", "r", stdin)
#define OUTPUT      freopen("locout.txt", "w", stdout)
inline ll isqrt(ll k) {ll r = sqrt(k) + 1; while (r * r > k) r--; return r;}
inline ll icbrt(ll k) {ll r = cbrt(k) + 1; while (r * r * r > k) r--; return r;}
inline ll mnz(ll& a,ll b){return a=(a>b?b:a);}
inline ll mxz(ll& a,ll b){return a=(a<b?b:a);}
inline string toString(ll n) {stringstream ss; ss << n;return ss.str();}
double const eps = 1e-6;
ll const Base=1e9+7,oo=1e17,MAXN=1e6;


ll A[32]={1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
ll Solves(){
	
	ll n,m,k,cnt=0,ans=0,x,y,q,c,sum=0,v,t;
	// PROCESS IN HERE
	cin>>n>>m>>k;
	if(k-n-m<=0)re prN,0;
	if((k-n-m)*(k-n-m)>4*n*m)re prY,0;
	prN;
	
	
	
	
	re 0;
	// Hack it if you can :)
}

int main(){
	//INPUT;
	if(fopen("locin.txt", "r"))INPUT;
	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	ll test=1;
//	sc(test);
	fu(T,1,test){
//		cout<<"Case #"<<T<<": ";
		Solves();
	} 		
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
   int a,b;
   cin>>a>>b;
  if (a%2==1 || b%2==1){
  cout<<(a+b+1)/2<<endl;}
  if (a%2==0 & b%2==0){
  cout<<(a+b)/2<<endl;}
}

Measured memory_bytes: 256
import java.util.*;
import java.io.*;
class Main{

	static int a[]=new int[20];
	static int n;
	public static void main(String[]args) throws IOException{
		BufferedReader in=new BufferedReader(new InputStreamReader(System.in));
		//Scanner in=new Scanner(System.in);
		PrintWriter out=new PrintWriter(System.out, true);
		n=Integer.parseInt(in.readLine());
		String str[]=in.readLine().split(" ");
		for(int i=0;i<str.length;i++)
			a[i]=Integer.parseInt(str[i]);
		int q=Integer.parseInt(in.readLine());
		String str1[]=in.readLine().split(" ");
		int b[]=new int[q];
		for(int i=0;i<q;i++){
			b[i]=Integer.parseInt(str1[i]);
			if(solve(0, 0, b[i]))
				out.println("yes");
			else
				out.println("no");
		}
	}
	public static boolean solve(int p, int t, int target){
		if(t==target){
			return true;
		}
		for(int i=p;i<n;i++){
			if(solve(i+1, t+a[i], target)){
				return true;
			}
		}
		return false;

	}
}


Measured memory_bytes: 24676
#include <iostream>

using namespace std;

int main()
{
    int a1,b1,a2,b2,k;
    cin>>a1>>b1>>a2>>b2>>k;
    a1=60*a1+b1;
    a2=60*a2+b2;
    cout<<(a2-a1-k)<<endl;
}

Measured memory_bytes: 3644
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef unsigned long long ull;
typedef long double ld;
typedef vector<int> vi;
typedef vector<long long int> vl;
typedef vector<vector<int>> vvi;
typedef vector<vector<long long int>> vvl;
typedef pair<int, int> pii;
typedef pair<long long int, long long int> pll;
typedef vector<pair<int, int>> vii;
typedef vector<pair<long long int, long long int>> vll;
#define fast() ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define test() long long int t; cin >> t; cin.ignore(); while(t--) 
#define ff first
#define ss second
#define pb push_back
#define pf push_front
#define mp make_pair
#define MOD 1000000007
#define SMOD 998244353
#define pq priority_queue
#define all(x) x.begin(),x.end()
#define SP(x) setprecision(x)
#define sp " "
#define inp(a) ll a;cin>>a;cin.ignore()
#define inps(a,b) ll a,b;cin>>a>>b;cin.ignore()
#define out(a) cout<<SP(20)<<a<<'\n'
#define outs(a,b) cout<<SP(20)<<a<<" "<<b<<'\n'
#define ins insert
#define er erase
#define lb lower_bound
#define ub upper_bound
#define printclock cerr<<"Time : "<<1000*(ld)clock()/(ld)CLOCKS_PER_SEC<<"ms\n";
#define inpa(a,n) ll a[n]; for(int i=0; i<n; i++){cin>>a[i];}
#define inpv(a,n) vl a; for(int i=0; i<n; i++){inp(x);a.pb(x);}
#define outa(a,n) for(int i=0;i<n;i++){cout<<a[i]<<" ";}cout<<'\n';
#define outv(v) for(auto i:v){cout<<i<<" ";}cout<<'\n';
set<char> vow = {'a','e','i','o','u','A','E','I','O','U'};
ll xpow(ll n, ll m){if(m==0){return 1;}else{ll x = xpow(n, m/2);if(m&1){return x*x*n;}else{return x*x;}}}
ll xmod(ll a, ll m){return (((a%m)+m)%m);}
ll xmodpow(ll n, ll m, ll y){if(m==0){return 1;}else{ll x = xmodpow(n, m/2, y);if(m&1){return xmod((xmod((xmod(x,y)*xmod(x,y)),y)*xmod(n,y)),y);}else{return xmod((xmod(x,y)*xmod(x,y)),y);}}}

int main(){
    fast();

/* you get what you work for not what you wish for */

    inps(n, k);
    inpv(a, n);
    inpv(b, n);
    sort(all(a));
    sort(all(b), greater<ll>());
    ll lo = 0;
    ll hi = 1e12;
    ll mid;
    ll ans=1e18;
    while(lo<=hi){
        mid = (lo+hi)/2;
        ll sum = 0;
        ll mx = 0;
        for(int i=0; i<n; i++){
            ll x = a[i]*b[i];
            if(x>mid){
                ll y = mid/b[i];
                sum += (a[i]-y);
                mx = max(mx, b[i]*y);
            }
            else{
                mx = max(mx, x);
            }
        }
        if(sum>k){
            lo = mid+1;
        }
        else{
            ans = min(mx, ans);
            hi = mid-1;
        }
    }
    cout << ans << endl;
}

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

namespace ConsoleApp3
{
    class Program
    {
        static void Main(string[] args)
        {
            var s = Console.ReadLine().Trim().OrderBy(_ => _).ToArray();
            var a = ((s[0] == s[1]) && (s[1] != s[2]) && (s[2] == s[3]));
            Console.WriteLine(a ? "Yes" : "No");
        }
    }
}


Measured memory_bytes: 13268
#include <stdio.h>
#include <set>
#include <algorithm>
#define pii pair<int,int>
using namespace std;

int n;
set <pair<int,int> > sa,sb;
pair<int,int> a[102],b[102];
set <pair<int,int> >::iterator it;

int i;
int j;
int counter = 0;
int bcount;

bool comp1(pii p,pii q){
	return p.first>q.first;
}
bool comp2(pii p,pii q){
	return p.first<q.first;
}
int main(){
	scanf("%d",&n);
	for(i=0;i<n;i++){
		scanf("%d%d",&a[i].first,&a[i].second);
	}
	for(i=0;i<n;i++){
		scanf("%d%d",&b[i].first,&b[i].second);
	}
	
	sort(a,a+n,comp1);
	sort(b,b+n,comp2);
//	for(i=0;i<n;i++) printf("%d %d\n",a[i].first,a[i].second);
//	for(i=0;i<n;i++) printf("%d %d\n",b[i].first,b[i].second);
	
	bcount = n-1;
	for(i=0;i<n;i++){
		while(bcount>=0 && b[bcount].first>a[i].first){
		//	printf("insert %d %d\n",b[bcount].first,b[bcount].second);
			sb.insert(make_pair(b[bcount].second,b[bcount].first));
			bcount--;
		}
		it = sb.lower_bound(make_pair(a[i].second,a[i].first));
		if(it!=sb.end()){
			sb.erase(it);
			counter++;
		}
	}
	printf("%d\n",counter);
	return 0;
}

Measured memory_bytes: 256
N = int(input())
A = list(map(int, input().split()))

right = 0
ans = 0
acc = 0
for left in range(N):
    while right<N and acc^A[right]==acc+A[right]:
        acc+=A[right]
        right+=1
        
    ans+=right-left
    
    if left==right:
        right+=1
    else:
        acc-=A[left]
    
print(ans)

Measured memory_bytes: 24712
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,m;
    cin>>n>>m;
    int arr[n];
    vector<int>v[n+1];
    for(int i=0;i<n;i++)
        cin>>arr[i];
    for(int i=0;i<m;i++)
    {
        int a,b;
        cin>>a>>b;a--;b--;
        v[a].push_back(b);
        v[b].push_back(a);
    }int count1=0;
    for(int i=0;i<n;i++)
    {
        int flag=0;
        for(int j=0;j<v[i].size();j++)
        {
            if(arr[v[i][j]]>=arr[i])
            {flag=-1;break;}
        }
        if(flag==0)
            {count1++;}
    }
cout<<count1<<"\n";
}


Measured memory_bytes: 9152
import math
H, W = map(int, input().split())

if H == 1 or W == 1:
    print(1)
    exit()

if W % 2 == 0:
    f, n = W // 2, W // 2
else:
    f = math.ceil(W / 2)
    n = f - 1

if H % 2 == 0:
    kakeru = H // 2
    print(f * kakeru + n * kakeru)
    exit()
else:
    kakeru = H // 2
    n_kakeru = H - kakeru
    print((f * n_kakeru) + (n * kakeru))
    exit()


Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main() {
	int n, k; cin >> n >> k;
	vector<int> h(n);
	for (int i = 0; i < n; i++) cin >> h[i];
	sort(h.begin(), h.end());
	long long int count = 0;
	for (int i = 0; i < max(0, n-k); i++) count += h[i];
	cout << count << endl;
	return 0;
}

Measured memory_bytes: 1024
<?php
  while (true) {
    list($h, $w) = explode(" ", trim(fgets(STDIN)));
    if (($h == 0) && ($w == 0)) {
      return;
    }
    $i = 1;
    while ($i <= $h) {
      if (($i == 1) || ($i == $h)) {
        print (str_repeat("#", $w) . "\n");
      } else {
        print ("#" . str_repeat(".", $w-2) . "#" . "\n");
      }
      $i++;
    }
    print ("\n");
  }
?>

Measured memory_bytes: 6580
import java.util.*;class Main{public static void main(String[]z){Scanner s=new Scanner(System.in);for(int n,i,a[]=new int[101],v,c,x;(n=s.nextInt())>0;System.out.println(c)){for(i=x=c=0;i<=n;++i)a[i]=s.nextInt();for(v=a[n];x<n&&++c>0&&a[i=(x+n-1)/2]!=v;)if(a[i]<v)x=i+1;else n=i;}}}

Measured memory_bytes: 12000
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
#include <bitset>
#include <cstring>
#include <deque>
#include <iomanip>
#include <limits>
#include <fstream>
using namespace std;
#define FOR(I,A,B) for(int I = (A); I < (B); ++I)
#define CLR(mat) memset(mat, 0, sizeof(mat))
typedef long long ll;

int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, m;
  cin >> n >> m;
  cout << n - m + 1 << endl; 
}

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

using namespace std;
#define all(a)a.begin(),a.end()
using ll=long long;
const int INF = 1<<30;
const ll INFll =1LL<<62;
const int mod= int(1e9)+7;
using P = pair<ll,ll>;
using ld=long double;

int main(){
   ll d,g;cin >>d>>g;
   ll ans=INF;
   vector<ll>p(d);
   vector<ll>c(d);
   g/=100;
    for (int i = 0; i < d; ++i) {
        cin >>p[i]>>c[i];
        c[i]/=100;
    }
    ll copy=g;
    for (int i = 0; i < (1 << d); ++i) {
//        vector<ll>cnt(10,0);
        vector<bool>ch(d,true);
        ll now=0;
        ll g=copy;
        for (int j = 0; j < d; ++j) {
            if(i&(1<<j)){
                ch[j]=false;
                now+=p[j];
                g-=(j+1)*p[j];
                g-=c[j];
//                cnt[j]+=p[j];
            }
        }
        for (int j = d-1; j >=0; --j) {
            if(g<=0){
                ans=min(ans,now);
            }
            else if(ch[j]) {
                if (g < (j + 1) * p[j]) {
                    now += (g - 1) /(j+1) + 1;
                    g -= ((g - 1) /(j+1)+ 1) * (j + 1);
                }
            }
        }
        if(g<=0){
            ans=min(ans,now);
        }
    }
    cout <<ans <<endl;
   return 0;
}

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

vector<int> P;
int n;

void init() {
  for (int i = 0; i < n; i++)
    P[i] = i;
}
int root(int c) {
  if (P[c] == c)
    return c;
  return (P[c] = root(P[c]));
}
bool is_same_set(int a, int b) { return root(a) == root(b); }
void unite(int a, int b) { P[root(a)] = root(b); }

int main() {
  cin >> n;
  P = vector<int>(n);
  init();
  vector<tuple<int, int, int>> edges; //<weight, start, end>
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      int a;
      cin >> a;
      if (i > j && a != -1)
        edges.push_back(make_tuple(a, i, j));
    }
  }
  sort(edges.begin(), edges.end());

  int ans = 0;
  for (tuple<int, int, int> edge : edges) {
    int w = get<0>(edge), s = get<1>(edge), e = get<2>(edge);
    if (!is_same_set(s, e)) {
      unite(s, e);
      ans += w;
    }
  }
  cout << ans << endl;
}



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

#define dbg(a)  cerr << __LINE__ << ": " << #a << " = " << a << '\n'

typedef long long ll;

int main(){
  ios::sync_with_stdio(0), cin.tie(0);
  
  ll a, b, c, d;  cin >> a >> b >> c >> d;
  ll ans=LLONG_MIN;
  if(a<=0 and b>=0) ans=0;
  if(c<=0 and d>=0) ans=0;
  ll ans1 = a*c;  //-,-
  ll ans2 = a*d;  //-,+
  ll ans3 = b*c;  //+,-
  ll ans4 = b*d;  //+,+;
  cout << max({ans, ans1, ans2, ans3, ans4}) << endl;   
  return 0;
}

Measured memory_bytes: 3648
n,m=map(int, input().split())
alist=[]
for i in range(m):
  a,b=map(int, input().split())
  alist.append([a,b])
  alist.append([b,a])
ans=0
import itertools
t=[i for i in range(1,n+1)]
blist=list(itertools.permutations(t,n))
ans=0
for i in blist:
  flag=True
  for j in range(n-1):
    if [i[j],i[j+1]] not in alist:
      flag=False
    if i[0]!=1:
      flag=False
  if flag:
    ans+=1
print(ans)

Measured memory_bytes: 13812
S=input()
if S=="SUN":
    print(7)
elif S=="MON":
    print(6)
elif S=="TUE":
    print(5)
elif S=="WED":
    print(4)
elif S=="THU":
    print(3)
elif S=="FRI":
    print(2)
elif S=="SAT":
    print(1)


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

int main(){
	int x,y;
	int ans=0;
	cin>>x>>y;
	if(x==3){
		ans+=1;
	}else if(x==2){
		ans+=2;
	}else if(x==1){
		ans+=3;
	}
	if(y==3){
		ans+=1;
	}else if(y==2){
		ans+=2;
	}else if(y==1){
		ans+=3;
	}
	if(ans==6){
		ans+=4;
	}
	cout<<ans*100000<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, a, n) for (int i = a; i < n; i++)
#define repr(i, a, n) for (int i = n - 1; i >= a; i--)
using namespace std;
using ll = long long;
using P = pair<int, int>;
template <typename T> void chmin(T &a, T b) { a = min(a, b); }
template <typename T> void chmax(T &a, T b) { a = max(a, b); }

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

  int a, b;
  cin >> a >> b;
  cout << a * b << " " << 2 * a + 2 * b << endl;
}



Measured memory_bytes: 3184
#include <bits/stdc++.h>
#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define ll long long int
//#define lli long long int
#define pii pair<int,int>
#define pll pair<long long int,long long int>
#define pci pair<char,int
#define mii map<int,int>
#define mll map<long long int,long long int>
#define mci map<char,int>
#define umii unordered_map<int,int>
#define umll unordered_map<long long int,long long int>
#define umci unordered_map<char,int>
#define F first
#define S second
#define pb push_back
#define endl '\n'
#define mod 1000000007
using namespace std;
ll visit[100001]={0};
vector<ll> adj[1000001];

bool sortinrev(const pair<ll,ll> &a,  
               const pair<ll,ll> &b) 
{
       if(a.first!=b.first) return(a.first > b.first);
       else return (a.second<b.second);
} 
ll power(ll x,ll n,ll m)
{
    ll result=1;
    while(n>0)
    {
        if(n % 2 ==1)
            result=(result * x)%m;
        x=(x*x)%m;
        n=n/2;
    }
    return result%m;
}
bool isPrime(ll k){
    if(k<=1){return false;}
    if(k==2){return true;}
    if(k%2==0){return false;}
    ll i = 3;
   while (i*i <= k) {if (k % i == 0) {return false;}i += 2;}
return true;
}
 
ll bin(ll n)
{
    int di= 0;
    while(n)
    {   di=di+n%10;
        n=n/10;
        
    }
    return di;
}
ll coun(auto v, vector<ll> a, ll x)
{
	ll ans1 = 0;
	for(auto i=v;i!=a.end();i++)
	{
		while(1)
		{
			ans1++;
			if(x>=*i)
			{
				x = *i;
				break;
			}
			x*=2;
		}
		x*=2;
	}
	ans1=ans1+v-a.begin();
	return ans1;
}
int main(){
   IOS;
ll t1;t1=1;
while(t1--){
ll n;cin>>n;
ll ans=0;
for(ll i=1;i<=n;i++){ll x;cin>>x;
    if(i%2==1&&x%2==1) ans++;
}
cout<<ans<<"\n";
}



return 0;}

Measured memory_bytes: 27068
#include<bits/stdc++.h>
#include <math.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define lper(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9;
const ll INF=4e18;
const ll dy[4]={1,0,-1,0};
const ll dx[4]={0,-1,0,1};
int main() {
int N;
  int K;
  cin >>N>>K;
  vector<int>vec(N);
  rep(i,N) {
    cin >>vec.at(i);
  }
  
  vector<int>minvec(N);
  rep(i,N) {
    minvec.at(i)=min(vec.at(i)*2,(K-vec.at(i))*2);
  }
  int sum=0;
  rep(i,N) {
sum +=minvec.at(i);
  }
  cout<<sum << endl;
}
 

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
#define ALL(x) (x).begin(), (x).end()
#define REP(i ,n) for(int i = 0; i < (int)(n); i++)
#define pb push_back
typedef vector<int>vint;
typedef vector<ll>vll;
template<typename T> istream &operator>>(istream &is, vector<T> &vec){ for (auto &v : vec) is >> v; return is; }
template<typename A,typename B>inline bool chmin(A &a,const B &b){if(a>b){a=b;return true;}else{return false;}}
template<typename A,typename B>inline bool chmax(A &a,const B &b){if(a<b){a=b;return true;}else{return false;}}

int main()
{
    string S;
    cin >> S;
    int N = (int)S.size();
    vll cnt(N+1);
    for(int i=0; i<N; i++){
        if(S[i] == '<'){
            chmax(cnt[i+1],cnt[i]+1LL);
        }
    }
    for(int i=N-1; i>=0; i--){
        if(S[i] == '>'){
            chmax(cnt[i],cnt[i+1]+1LL);
        }
    }
    ll ans = 0;
    for(auto c:cnt){
        ans += c;
    }
    cout << ans << endl;
}

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

int main(){
  int x,n;
  cin >> x >> n;
  vector<int> vec(n);
  int mcount = 0;
  int m = 0;
  int pcount = 0;
  int p = 0;
  
  for(int i = 0;i < n;i ++){
    cin >> vec.at(i);
  }
  
  //マイナス方向
  for(int i = 0;i < 101;i ++){
    bool mhantei = true;
    for(int j = 0;j < n;j ++){
      if(x - i == vec.at(j))mhantei = false;
    }
    if(mhantei == true){mcount = x - i;m = i;break;}
  }
  
  //プラス方向
  for(int i = 0;i < 101;i ++){
    bool phantei = true;
    for(int j = 0;j < n;j ++){
      if(x + i == vec.at(j))phantei = false;
    }
    if(phantei == true){pcount = x + i;p = i;break;}
  }
  
  if(m > p)cout << pcount << endl;
  else if(m < p)cout << mcount << endl;
  else cout << min(mcount,pcount) << endl;
}

Measured memory_bytes: 3600
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayDeque;
import java.util.Deque;

import static java.lang.Integer.parseInt;

/**
 * Amazing Mazes
 */
public class Main {

	static final int DIR[][] = {
			{0, -1},
			{1, 0},
			{0, 1},
			{-1, 0},
	};

	static final int DIR2[][] = {
			{0, -2},
			{2, 0},
			{0, 2},
			{-2, 0},
	};

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String line;
		String[] words;

		StringBuilder sb = new StringBuilder();
		while ((line = br.readLine()) != null && !line.isEmpty()) {
			int w, h;
			w = parseInt(line.substring(0, line.indexOf(' ')));
			h = parseInt(line.substring(line.indexOf(' ') + 1));
			if ((w | h) == 0) break;

			w = w * 2 - 1;
			h = h * 2 - 1;
			int[][] maze = new int[h + 4][w + 4];

			for (int i = 0; i < h; i++) {
				line = br.readLine();
				for (int j = 0; j < line.length(); j++) {
					if (line.charAt(j) == '1') maze[i + 2][j + 2] = 1;
				}
			}
			for (int i = 0; i < maze.length; i++) {
				for (int j = 0; j < maze[0].length; j++) {
					if (i == 1 || i == h + 2 || j == 1 || j == w + 2) maze[i][j] = 1;
				}
			}

			//solve
			Deque<int[]> q = new ArrayDeque<>();

			q.offer(new int[]{2, 2});
			maze[2][2] = 1;

			while (!q.isEmpty()) {

				int y, x;
				y = q.peek()[0];
				x = q.peek()[1];
				q.poll();

				if (y == h && x == w) break;

				for (int i = 0; i < DIR.length; i++) {
					int ny, nx, ny2, nx2;
					ny = y + DIR[i][0];
					nx = x + DIR[i][1];
					ny2 = y + DIR2[i][0];
					nx2 = x + DIR2[i][1];

					if (maze[ny][nx] == 0 && maze[ny2][nx2] == 0) {
						q.offer(new int[]{ny2, nx2});
						maze[ny2][nx2] = maze[y][x] + 1;
					}
				}
			}
			sb.append(maze[h + 1][w + 1]).append('\n');
		}
		System.out.print(sb.toString());
	}
}

Measured memory_bytes: 33388
#include<stdio.h>

int main(){
	int data[100];
	int sp = 0, v;
	while(scanf("%d", &v) != EOF){
		if(v != 0){
			data[sp] = v;
			sp++;
		}else{
			sp--;
			printf("%d\n",data[sp]);
		}
	}
	return 0;
}

Measured memory_bytes: 1748
#include<stdio.h>
int main(void){
    int a,h,m,d,e;
    h=3600;
    m=60;
    scanf("%d",&a);
    d=a-h*(a/h);
    e=a-h*(a/h)-m*(d/m);

    printf("%d:%d:%d\n",a/h,d/m,e);
    return 0;
}

Measured memory_bytes: 592