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

int main() {
  long long a, x;
  a=100;
  int year=0;
  
  cin >> x;
  
  while (a < x) {
    a = a * 1.01;
    year = year + 1;
  }
  
  cout << year << endl;
}


Measured memory_bytes: 3652
import java.util.*;
public class Main {
    static Scanner kbd = new Scanner(System.in);
    public static void main(String[] args) {
 
    while(kbd.hasNext()){
        int a = kbd.nextInt();
        String op = kbd.next();
        int b = kbd.nextInt();
     
        if(op.equals("?")){
        ;
        }
        else{
        int x = a+b;
        if(op.equals("-")) x = a-b;
        if(op.equals("*")) x = a*b;
        if(op.equals("/")) x = a/b;
        System.out.println(x);
        }
    }
    }
}

Measured memory_bytes: 18056
fun main(args: Array<String>) {
    data class SC(val s: Int, val c: Int)
    val (n, m) = readLine()?.split(" ")?.map(String::toInt) ?: return
    val scs = 0.until(m).map {
        val sc = readLine()?.split(" ")?.map(String::toInt) ?: return
        SC(sc[0], sc[1])
    }
    // sが重複してるものがあると-1
    scs.groupBy { it.s }
        .values
        .find {
            it.size > 1 && it.distinct().size > 1
        }?.let {
            println(-1)
            return
        }
    // s=1が0だと-1
    val maxS = scs.find { it.s == 1 }
    if (n > 1 && (maxS?.c == 0)) {
        println(-1)
        return
    }
    val value = 1.until(n + 1).fold(0, { a, b ->
        a * 10 + (scs.find { it.s == b }?.c ?: if (n > 1 && b == 1) {
            1
        } else {
            0
        })
    })

    println(value)
}


Measured memory_bytes: 37876
def sieve(n):
    is_prime = [True for _ in range(n+1)]
    is_prime[0] = False

    for i in range(2, n+1):
        if is_prime[i-1]:
            j = 2 * i
            while j <= n:
                is_prime[j-1] = False
                j += i
    table = [ i for i in range(1, n+1) if is_prime[i-1]]
    #return is_prime, table
    return table

n = int(input())
table = sieve(55555)
table2 = []
for i in table:
    if i % 5 == 1:
        table2.append(i)

for i in range(n):
    print(table2[i], end = ' ')


Measured memory_bytes: 41840
#include <bits/stdc++.h>
using namespace std;
long long a[22][22];
long long n;
long long dp[22][1<<22];

long long solve(long long mask,long long i){
    if(!mask)
        return 1;
    if(dp[i][mask]!=-1)
        return dp[i][mask];
    dp[i][mask]=0;
    for(long long j=0;j<n;j++){
        if((mask&1<<j)&&a[i][j+1]){
            dp[i][mask]=(dp[i][mask]+solve(mask^(1<<j),i-1))%1000000007;
        }
    }return dp[i][mask];
}


int main() {
	
	cin>>n;
	for(long long i=1;i<=n;i++)
	    for(long long j=1;j<=n;j++)
	        cin>>a[i][j];
	memset(dp,-1,sizeof(dp));
	cout<<solve((1<<n)-1,n);
}




Measured memory_bytes: 721152
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;
typedef long long ll;

const ll MAX_N = (1 << 20);
ll dat[2 * MAX_N - 1] = { 0 };

void update(ll k, ll a){
	k += MAX_N - 1;
	dat[k] = a;
	while(k > 0){
		k = (k - 1) / 2;
		dat[k] = max(dat[k * 2 + 1], dat[k * 2 + 2]);
	}
}

ll query(ll a, ll b, ll k, ll l, ll r){
	if(r <= a || b <= l){ return 0; }
	if(a <= l && r <= b){ return dat[k]; }
	ll vl = query(a, b, k * 2 + 1, l, (l + r) / 2);
	ll vr = query(a, b, k * 2 + 2, (l + r) / 2, r);
	return max(vl, vr);
}

int main(){
	ios_base::sync_with_stdio(false);
	ll n;
	cin >> n;
	vector<ll> x(n);
	for(ll i = 0; i < n; ++i){ cin >> x[i]; }
	ll max_sum = 0;
	for(ll i = 0; i < n; ++i){
		ll y = query(0, x[i], 0, 0, MAX_N) + x[i];
		max_sum = max(max_sum, y);
		update(x[i], y);
	}
	cout << (n * (n + 1) / 2) - max_sum << endl;
	return 0;
}

Measured memory_bytes: 8320
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pll;
typedef tuple<ll, ll, ll> tll;

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll H, W;
    cin >> H >> W;
    vector<string> map(H);
    for (int i = 0; i < H; i++)
    {
        cin >> map.at(i);
    }
    vector<ll> dh = {1, 0, -1, 0};
    vector<ll> dw = {0, 1, 0, -1};
    bool canFill = true;
    for (int i = 0; i < H; i++)
    {
        for (int j = 0; j < W; j++)
        {
            if (map.at(i).at(j) == '.')
            {
                continue;
            }
            bool canFill = false;
            for (int k = 0; k < 4; k++)
            {
                ll curH = i + dh.at(k);
                ll curW = j + dw.at(k);
                if (curH < 0 || H <= curH || curW < 0 || W <= curW)
                {
                    continue;
                }
                if (map.at(curH).at(curW) == '#')
                {
                    canFill = true;
                    break;
                }
            }
            if (!canFill)
            {
                cout << "No" << endl;
                return 0;
            }
        }
    }
    cout << "Yes" << endl;
    return 0;
}


Measured memory_bytes: 256
/* ****revpro**** */
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#include<bits/stdc++.h>
#define ll          long long
#define pb          push_back
#define endl	   '\n'
#define pii         pair<ll,ll>
#define vi          vector<ll>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (ll)x.size()
#define hell        1000000007
#define rep(i,a,b)  for(ll i=a;i<b;i++)
#define repr(i,a,b) for(ll i=b-1;i>=a;i--)    
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define mp          make_pair
#define present(c,x) ((c).find(x) != (c).end())
#define cpresent(c,x) (find(all(c),x) != (c).end())
#define mii	    map<ll,ll>
using namespace std;

#define N  100005
signed main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int TESTS=1;
//	cin>>TESTS;
	while(TESTS--)
	{
		ll x;
		cin>>x;
		rep(i,0,x/100+1){
			ll tmp=x-i*100;
			if(tmp<=5*i){
				cout<<1;
				return 0;
			}
		}
		cout<<0;
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int,int>;

#define rep(i, n) for(int i=0;i<(int)n;i++)
#define rep2(i, s, n) for(int i=(s);i<(int)n;i++)
int INF=1e9+7;

int main() {
  int A, B, C, K;
  cin >> A >> B >> C >> K;
  int ans=0;
  if(K<=A) ans+=K;
  else {
    ans+=A;
    if(K>A+B) ans -= K-A-B;
  }
  cout << ans << endl;
}

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

t = 1
ans = 1
count = 0

if 0 in A:
    ans = 0
else:  
    for a in A:
        ans *= a
        t *= a
        while t >= 10:
            t /= 10
            count += 1
            if count >= 19:
                ans = -1 
                break

if ans > 10**18:
    print(-1)
else:
    print(ans)

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

int main() {
    int n;
    cin >> n;
    ll a[n];
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    ll ans = 0;
    for (int i = 0; i < n; i++) {
        ll b = a[i];
        while (!(b & 1)) {
            ans++;
            b = b >> 1;
        }
    }
    printf("%lld\n", ans);
}

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

int main() {
  int r;
  cin >> r;
  if (r < 1200) cout << "ABC" << endl;
  else if (r < 2800) cout << "ARC" << endl;
  else cout << "AGC" << endl;
}


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

int main() {
  int N;
  cin >> N;
  vector<int> X(N);
  rep(i, N) cin >> X.at(i);
  int mini=1000000000;
  
  for(int i=1; i<=100; i++){
    int sum=0;
    
    for(auto e:X){
     sum += (e-i)*(e-i);
      
    }
    mini = min(mini, sum);
  }
  cout << mini << endl;
  return 0;
}




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

using namespace std;
typedef pair<int, int> P;

#define pi 3.141592653589793)
#define mod 1000000007

string s;
int g;

void solve() {
	cin >> s;
	for (int i = 0; i < s.size(); i++)
		if (s[i] == 'g')g++;

	cout << (((2 * g - s.size()) > 1) ? (2 * g - s.size()) / 2 : 0) << endl;

}

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

Measured memory_bytes: 764
spots_num = gets.to_i
t = 0 
x = 0
y = 0
count = 0

for i in 0..spots_num-1 do 
	input = gets.split(' ').map(&:to_i)
	distance = (x - input[1]).abs + (y - input[2]).abs 
	if input[0] - t < distance then 
		puts 'No'
		break
	elsif ((input[0]-t)-distance)%2 == 1 then 
		puts 'No'
		break
	else
		t = input[0]
		x = input[1]
		y = input[2]
		count+=1
	end

end
if count == spots_num then #全ての計画が実行できたら
	puts 'Yes'
end


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

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 (a>b) { a=b; return 1; } return 0; }
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()

int main() {
    int n, k;
    cin >> n >> k;
    vector<int> a(n);
    rep (i, n) {
        cin >> a[i];
    }
    int ans = 1e9 + 7;
    rep (i, n - k + 1) {
        int l = a[i];
        int r = a[i + k - 1];
        if (1ll * l * r < 0) {
            int res = min(abs(l) * 2 + abs(r), abs(r) * 2 + abs(l));
            chmin(ans, res);
        } else {
            int res = max(abs(l), abs(r));
            chmin(ans, res);
        }
    }
    cout << ans << endl;
}

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

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

using namespace std;
using ll = long long;




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

  vector<int> a(n);

  rep(i,1,n){
    rep(j,i+1,n+1){
      int k = min(j-i,abs(x-i)+1+abs(j-y));
      a[k]++;
    }
  }

  rep(k,1,n){
    cout << a[k] << endl;
  }
  
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <math.h>
#include <algorithm>
using namespace std;

typedef long long ll;
typedef vector<int> vi;

int main()
{
	ll n, d;
	cin >> n >> d;

	int cnt = 0;

	for (int i = 0; i < n; i++) {
		ll x, y;
		cin >> x >> y;

		if (x * x + y * y <= d * d) {
			cnt++;
		}
	}

	cout << cnt << endl;

	return 0;
}


Measured memory_bytes: 3620
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define rep2(i, s, n) for (ll i = (s); i < (ll)(n); i++)
const ll MAX = 1001001;
const ll MOD = 1000000007;
int main()
{
    string s, t;
    cin >> s >> t;
    ll ans = 1001001001;
    rep(i, s.size() - t.size() + 1)
    {
        ll now = 0;
        rep(j, t.size())
        {
            if (s[i + j] != t[j])
            {
                now++;
            }
        }
        ans = min(ans, now);
    }
    cout << ans << endl;
}

Measured memory_bytes: 3596
#include <bits/stdc++.h>
using namespace std;
//for(int i = 0; i < n; i++)
 
int main() {
  int n, a, b, ans = 0;
  long long x;
  string s;
  cin >> n;
  vector<int> v(n), c(n);
  for(int i = 0; i < n; i++) cin >> v.at(i);
  for(int i = 0; i < n; i++) cin >> c.at(i);
  for(int i = 0; i < n; i++) {
    if(v.at(i) > c.at(i)) ans += v.at(i) - c.at(i);
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
n, k = gets.chomp.split(" ").map(&:to_i)

def coin_num(i, k)
  num = 0
  ii = i
  while ii < k
    ii *= 2
    num += 1
  end
  num
end

rate = 0.0
1.upto(n) do |i|
  rate += 1.0 / (n * (2.0 ** coin_num(i, k)))
end
puts rate


Measured memory_bytes: 1788
package main

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

var sc = bufio.NewScanner(os.Stdin)

func nextInt() int {
	var i int
	if sc.Scan() {
		if num, err := strconv.Atoi(sc.Text()); err == nil {
			i = num
		}
	}
	return i
}

func nextString() string {
	var s string
	if sc.Scan() {
		s = sc.Text()
	}
	return s
}

func main() {
	sc.Split(bufio.ScanWords)
	n := nextInt()
	var outStrings = map[string]int{}
	var max int

	for i := 0; i < n; i++ {
		s := nextString()
		outStrings[s]++
		count := outStrings[s]
		if max < count {
			max = count
		}
	}
	slice := []string{}
	for k, v := range outStrings {
		if v == max {
			slice = append(slice, k)
		}
	}
	sort.Strings(slice)

	for i := 0; i < len(slice); i++ {
		fmt.Println(slice[i])
	}
}


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

using namespace std;
#define ll long long

ll INF = 1e18;

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

    vector<ll> arr(n);
    ll prod = 1;
    bool flag = false;

    for(int i = 0; i< n;i++)
    {
        cin>>arr[i];
        if(arr[i] == 0)
        {
            flag = true;
        }
    }

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

    double ans = 1;
    
    for(int i=0;i<arr.size();i++)
    {
        prod *= arr[i];
        ans *= arr[i];
        //cout<<ans<<endl;
        if( ans > INF|| prod > INF)
        {
            cout<<-1<<endl;
            return 0;
        } 
    }

    cout<<prod<<endl;

    return 0;
}


Measured memory_bytes: 4048
#include<bits/stdc++.h>
using namespace std ;
typedef long long ll ;
const int mod=1000000007 ;

void solve(){
	
	int n,m,b ;
	cin>>n>>m>>b ;

	vector<int> row(n+1,0) ;
	vector<int> col(m+1,0) ;

	map<pair<int,int>,bool> mp ;

	for(int i=1;i<=b;i++){
		int r,c ;
		cin>>r>>c ;
		row[r]++ ;
		col[c]++ ;
		mp[{r,c}]=true ;
	}

	int mr=0,mc=0 ;

	for(int i=1;i<=n;i++){
		mr=max(mr,row[i]) ;
	}

	for(int j=1;j<=m;j++){
		mc=max(mc,col[j]) ;
	}

	vector<int> rr,cc ;

	for(int i=1;i<=n;i++){
		if(mr==row[i]){
			rr.push_back(i) ;
		}
	}

	for(int j=1;j<=m;j++){
		if(mc==col[j]){
			cc.push_back(j) ;
		}
	}

	int ans=mr+mc;

	for(auto x:rr){
		for(auto y:cc){
			if(mp.find({x,y})!=mp.end()){
				continue ;
			}
			cout<<ans ;
			return  ;	
		}
	}
	ans-- ;
	cout<<ans ;
	return  ;
}


int main(){

	int y ;

	y=1 ;
	//cin>>y ;

	while(y--)
	{	
		solve() ;
	}

}

Measured memory_bytes: 28548
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>
#define MOD 1000000007
#define MAX(a,b) (a>b?a:b)
#define MAX3(a,b,c) MAX(a,MAX(b,c))
#define MIN(a,b) (a<b?a:b)
#define MIN3(a,b,c) MIN(a, MIN(b,c))
typedef long long lli;
int cmp(const void *a, const void *b) {
    return *(int*)a - *(int*)b;
}


int main()
{
    int a, b, k, i, cnt=0;
    scanf("%d%d%d",&a,&b,&k);
    for(i=MIN(a,b); cnt<k; i--) {
        if(a%i==0 && b%i==0) {
            cnt++;
        }
    }
    printf("%d",i+1);
    return 0;
}


Measured memory_bytes: 128
#include<stdio.h>
#include<stdbool.h>
#include<string.h>
#include<stdlib.h>

int main(void){
  int a,b,c,max,ans;
  scanf("%d%d%d",&a,&b,&c);
  max = a;
  if(max < b){
    max = b;
  }
  if(max < c){
    max = c;
  }
  ans = a+b+c-max;
  printf("%d\n",ans);
  return 0;
}


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

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repr(i, n) for(int i = (int)(n); i >= 0; i--)
#define repm(i, m, n) for(int i = (int)(m); i < (int)(n); i++)
#define repmr(i, m, n) for(int i = (int)(n); i >= (int)(m); i--)
#define all(x) (x).begin(),(x).end()
#define inf 2e9

using namespace std;
typedef long long int lli;
typedef long long ll;

int main() {
    string a,s,c;
    cin >> a >> s >> c;

    cout << a.front() << s.front() << c.front() << endl;
}


Measured memory_bytes: 256
import java.util.Scanner;

class Main{
    static Scanner in = new Scanner(System.in);
     public static void main(String[] args){
         int i = Integer.parseInt(in.nextLine());
         String s = in.nextLine();
         int max = 0;
         i = 0;
         for(char c : s.toCharArray()){
             if(c == 'I'){
                 i++;
             }else{
                 i--;
             }
             max = Math.max(max, i);
         }
         System.out.println(max);
     }
}

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


using namespace std;

const double PI = 3.14159265358979323846;
typedef long long ll;
const double EPS = 1e-9;
#define rep(i, n) for (int i = 0; i < (n); ++i)
//#define rep(i, n) for (ll i = 0; i < (n); ++i)
const ll INF = 10e17;
#define cmin(x, y) x = min(x, y)
#define cmax(x, y) x = max(x, y)
#define ret() return 0;

double equal(double a, double b) {
    return fabs(a - b) < DBL_EPSILON;
}

std::istream &operator>>(std::istream &in, set<string> &o) {
    string a;
    in >> a;
    o.insert(a);
    return in;
}

std::istream &operator>>(std::istream &in, queue<int> &o) {
    ll a;
    in >> a;
    o.push(a);
    return in;
}

typedef pair<ll, ll> P;

bool contain(set<int> &s, int a) { return s.find(a) != s.end(); }

//ofstream outfile("log.txt");
//outfile << setw(6) << setfill('0') << prefecture << setw(6) << setfill('0') << rank << endl;
// std::cout << std::bitset<8>(9);
//const ll mod = 1e10;

typedef priority_queue<ll, vector<ll>, greater<ll> > PQ_ASK;

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

    vector<int> numbers(n);
    rep(i, n) cin >> numbers[i], numbers[i]--;

    vector<int> indexes(n);
    rep(i, n) indexes[numbers[i]] = i;

    set<int> used;

    ll ans = 0;
    rep(i, n) {
        int index = indexes[i];
        int end = [&] {
            auto end_it = used.upper_bound(index);
            if (end_it == used.end()) return n;
            return *end_it;
        }();
        int start = [&] {
            auto begin_it = used.upper_bound(index);
            if (begin_it == used.begin()) return -1;
            begin_it--;
            return *begin_it;
        }();
        used.insert(index);

        ll r = end - index;
        ll l = index - start;

        ll k = r * l;

        ll p = k * (i + 1);

        ans += p;
    }
    cout << ans << endl;

}


Measured memory_bytes: 11136
ni = lambda: int(input())
nm = lambda: map(int, input().split())
nl = lambda: list(map(int, input().split()))

a,b,c=nm()
k=ni()

while(True):
  if(b<=a):
    if(k<=0):
      print('No')
      exit()
    b*=2
    k-=1
  else:
    break

while(True):
  if(c<=b):
    if(k<=0):
      print('No')
      exit()
    c*=2
    k-=1
  else:
    break
print('Yes')


Measured memory_bytes: 61852
(let ((x1 (read))
      (y1 (read))
      (x2 (read))
      (y2 (read)))
     (format t "~a ~a ~a ~a~%" (- x2 (- y2 y1)) (+ y2 (- x2 x1)) (+ x1 (- y1 y2)) (- y1 (- x1 x2))))

Measured memory_bytes: 4324
import java.io.PrintWriter
val pw = PrintWriter(System.out)

fun main(args : Array<String>) {
    func()
    pw.flush()
}

fun func() {
    val (n, m) = listOfInt()
    val cities = IntArray(n){0}

    repeat(m){
        val (a, b) = listOfInt()
        cities[a-1]++
        cities[b-1]++
    }

    cities.forEach(::println)
}

fun next() = readLine()!!
fun listOfString() = next().split(" ")
fun listOfInt() = listOfString().map { it.toInt() }

fun println(value : Any) {
    pw.println(value)
}

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

const int MAX_E = 500001;
const int MAX_V = 100001;
const int MAX_D = 1000000000;

struct edge { int from, to, cost=MAX_D; };

int main() {
	int V, E, s;
	cin >> V >> E >> s;
	//int table[MAX_V][MAX_V] = {0};
	edge table[MAX_E];

	for (int i = 0; i < E; i++)
		cin >> table[i].from >> table[i].to >> table[i].cost;
	
	//*****************
	int prev[MAX_V];
	int dist[MAX_V];
	bool s_[MAX_V];

	for (int i = 0; i < V; i++)
		dist[i] = MAX_D;
	dist[s] = 0;

	for (int i = 0; i < V; i++)
		prev[i] = -1;
	prev[s] = s;

	for (int i = 0; i < V; i++)
		s_[i] = false;
	s_[s] = true;

	for (int i = 0; i < E; ++i)
	{
		if (table[i].from == s)
		{
			dist[table[i].to] = table[i].cost;
			prev[table[i].to] = s;
		}


	}
	dist[s] = 0;
	s_[s] = true; //ini

	int mindist = MAX_D;
	bool mark = false;
	for (int i = 1; i < V; i++)
	{
		if (!mark&&i != 1)
			continue;
		mark = false;
		int u = s;
		for (int j = 0; j < V; j++)
		{
			if (!s_[j] && dist[j] < mindist)
			{
				u = j;
				mindist = dist[j];
				mark = true;
			}
		}
		s_[u] = true;

		int mindist_ = MAX_D;
		for (int j = 0; j < E; j++)
		{
			if (!s_[table[j].to] && table[j].cost < mindist_)
			{
				if (dist[table[j].from] + table[j].cost < dist[table[j].to])
				{
					dist[table[j].to] = dist[table[j].from] + table[j].cost;
					prev[table[j].to] = table[j].from;
					mark = true;
				}
			}
		}
	}

	for (int i = 0; i < V; i++)
	{
		if(dist[i]<MAX_D)
			cout << dist[i] << endl;
		else
			cout << "INF" << endl;
	}

	return 0;
}

Measured memory_bytes: 9424
# GRL_2_A - Minimum Spanning Tree
class UnionFind:  # O(α(N))
    def __init__(self, size):  # construct a Union-Find tree (1-idx)
        self.parent = [i for i in range(size)]
        self.rank = [0] * (size)
        self.size = size

    def find(self, x):  # find the group (root) of a vertex
        if self.parent[x] == x:
            return x
        self.parent[x] = self.find(self.parent[x])
        return self.parent[x]

    def is_same(self, x, y):  # check two vertices are in the same group
        return self.find(x) == self.find(y)

    def unite(self, x, y):  # unite two groups
        x, y = self.find(x), self.find(y)
        if x == y:  # the same group
            return
        # unite a smaller one to a bigger one in order to balance trees
        if self.rank[x] < self.rank[y]:
            self.parent[x] = y
        else:
            self.parent[y] = x
            if self.rank[x] == self.rank[y]:
                self.rank[x] += 1


def kruskal() -> int:
    total_cost, undetermined, uf = 0, N, UnionFind(N)
    for cost, v, u in E:
        if not uf.is_same(v, u):
            uf.unite(v, u)
            total_cost += cost
            undetermined -= 1
        if not undetermined:
            break
    return total_cost


def main():
    global N, E
    N, M, *E = map(int, open(0).read().split())
    E = [(c, v, u) for (v, u, c) in zip(*[iter(E)] * 3)]
    E.sort()
    ans = kruskal()
    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 37696
using System;

namespace ABC053_C_X_Yet_Another_Die_Game
{
	internal class Program
	{
		public static void Main(string[] args)
		{
			long x = long.Parse(Console.ReadLine());

			long countPlay = x / 11 * 2;
			long remainingPoint = x % 11;

			long remainingCountPlay = 0;
			while (remainingPoint > 0)
			{
				if (remainingCountPlay % 2 == 0)
					remainingPoint -= 6;
				else
					remainingPoint -= 5;

				remainingCountPlay++;
			}
			countPlay += remainingCountPlay;
			
			Console.WriteLine(countPlay);
		}
	}
}

Measured memory_bytes: 11092
a, b, k = map(int,input().split())

while k != 0:
    if a > 0:
        t = min(a, k)
        a -= t
        k -= t
    elif b > 0 and k > 0:
        t = min(b, k)
        b -= t
        k -= t
    if a == 0 and b == 0:
        break

print(a, b)

Measured memory_bytes: 3060
#include<stdio.h>
int main(){
	int A;
	int B;
	int C;
	scanf ("%d %d %d",&A,&B,&C);
	
	
	if(A== B &&A!=C&&B!=C){
		printf("Yes");
	}
	else	if(B==C &&B!=A&&C!=A){
	
		printf("Yes");
	}
	else	if(A== C &&A!=B&&C!=B){
		printf("Yes");
	}
		else{
			printf("No");
	}
	
	
	
	return 0;
}

Measured memory_bytes: 3196
import numpy as np
 
H, W = map(int, input().split())
S_list = [list(input()) for _ in range(H)]
S_list=(np.array(S_list) ==".")*1
 
L = np.zeros((H, W), int) # i,jより左のランプをてらせる数
R = np.zeros((H, W), int)
U = np.zeros((H, W), int)
D = np.zeros((H, W), int)
 
for w in range(W):
    if w == 0: 
        L[:,w] = S_list[:,w] # 一番左であれば、Lは1, 他の行も同じ
        R[:,W-w-1] = S_list[:,W-w-1] # 一番右であれば、Rは1, 他の行も同じ
    else:
        L[:,w] = (L[:,w-1]+1) * S_list[:,w] # Lは一つ左のものに1を加えたもの, 他の行も同じ
        R[:,W-w-1] = (R[:,W-w]+1) * S_list[:,W-w-1] # Rは一つ右のものに1を加えたもの, 他の行も同じ
 
for h in range(H):
    if h == 0:
        U[h,:] = S_list[h,:]
        D[H-h-1,:] = S_list[H-h-1,:]
    else:
        U[h,:] = (U[h-1,:]+1) * S_list[h,:]
        D[H-h-1,:] = (D[H-h,:]+1) * S_list[H-h-1,:]
        
ans = max(np.max(L+R+U+D-3), 0) # 行列のH,Wの中で最大のものをとる
 
print(ans)

Measured memory_bytes: 266540
#include<bits/stdc++.h>
#define cs ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
typedef long double ld;

using namespace std;

int main(){
    cs
    ld x,t=0;
    int k;
    cin>>k;
    while(k--){
        cin>>x;
        t+=(1/x);
    }
    cout<<fixed<<setprecision(12)<<1/t;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#define df 0


int main(){
  int n;
  scanf("%d",&n);
  long int i,x,y,tx=1,ty=1;
  for(i=0;i<n;i++){
    scanf("%ld%ld",&x,&y);
    long int mx=(x-1+tx)/x,my=(y-1+ty)/y;
    if(mx<my)mx=my;
    tx=x*mx;ty=y*mx;
    if(df)printf("[%ld %ld]\n",tx,ty);
  }

  printf("%ld",tx+ty);
  return 0;
}


/// confirm df==0 ///


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

using namespace std;
using ll = long long;
#define int ll
using PII = pair<int, int>;
template <typename T> using V = vector<T>;
template <typename T> using VV = vector<V<T>>;
template <typename T> using VVV = vector<VV<T>>;

#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
#define PB push_back

const ll INF = (1LL<<60);
const int MOD = 1000000007;

template <typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }
template <typename T> bool IN(T a, T b, T x) { return a<=x&&x<b; }
template<typename T> T ceil(T a, T b) { return a/b + !!(a%b); }
template<class S,class T>
ostream &operator <<(ostream& out,const pair<S,T>& a){
  out<<'('<<a.first<<','<<a.second<<')';
  return out;
}
template<class T>
ostream &operator <<(ostream& out,const vector<T>& a){
  out<<'[';
  REP(i, a.size()) {out<<a[i];if(i!=a.size()-1)out<<',';}
  out<<']';
  return out;
}

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

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

  int n;
  cin >> n;
  V<int> a(n);
  REP(i, n) cin >> a[i];

  int ret = -INF;
  REP(i, n) FOR(j, i+1, n) {
    chmax(ret, abs(a[i]-a[j]));
  }

  cout << ret << endl;

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define mins(a,b) a=min(a,b)
#define maxs(a,b) a=max(a,b)
 template < typename T > std::string to_string( const T& n )
  {
    std::ostringstream stm ;
    stm << n ;
    return stm.str() ;
  }
using namespace std;

const long long INF=9000000000000000;
int main(){
  string s;
  int n;
  cin>>s>>n;
  for(int i=0;i<s.size();i+=n){
    cout<<s[i];
  }
  cout<<endl;
}

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

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;

#define pb push_back
#define rep(i, a, n) for(int i = (a); i < (n); i++)
#define dep(i, a, n) for(int i = (a); i >= (n); i--)
#define mod (ll)(1e9+7)
#define int ll

__attribute__((constructor))
void initial() {
  cin.tie(0);
  ios::sync_with_stdio(false);
}

signed main() {
  int n, k, ans = 0;
  cin >> n >> k;

  int a[100001];

  rep(i, 0, n) {
    cin >> a[i];
    if(a[i] > 0) ans += a[i];
  }
  queue<int> q, qq;
  int gou = 0, mn = 0, mx = 0;
  rep(i, 0, n) {
    q.push(a[i]);
    if(a[i] > 0) gou += a[i];
    if(q.size() < k) continue;
    mn = max(ans - gou, mn);
    if(q.front() > 0) gou -= q.front();
    q.pop();
  }
  gou = 0;
  rep(i, 0, n) {
    qq.push(a[i]);
    if(a[i] < 0) gou -= a[i];
    if(qq.size() < k) continue;
    mx = max(mx, ans - gou);
    if(qq.front() < 0) gou += qq.front();
    qq.pop();
  }

  cout << max(mn, mx) << endl;
}


Measured memory_bytes: 2688
#include <bits/stdc++.h>
#define R register
#define mp make_pair
#define ll long long
#define pii pair<int, int>
#define pll pair<ll, ll>
using namespace std;
const int mod = 998244353, N = 210000;

int n, k, a[N], b[N];

inline int addMod(int a, int b) {
	return (a += b) >= mod ? a - mod : a;
}

inline ll quickpow(ll base, ll pw) {
	ll ret = 1;
	while (pw) {
		if (pw & 1) ret = ret * base % mod;
		base = base * base % mod, pw >>= 1;
	}
	return ret;
}

template <class T>
inline void read(T &x) {
	x = 0;
	char ch = getchar(), w = 0;
	while (!isdigit(ch)) w = (ch == '-'), ch = getchar();
	while (isdigit(ch)) x = (x << 1) + (x << 3) + (ch ^ 48), ch = getchar();
	x = w ? -x : x;
	return;
}

int main() {
	read(n), read(k);
	for (R int i = 1; i <= n; ++i) read(a[i]);
	for (R int i = 1; i <= k; ++i) {
		memset(b, 0, sizeof (b));
		for (R int j = 1; j <= n; ++j)
			++b[max(1, j - a[j])], --b[min(n + 1, j + a[j] + 1)];
		int minA = n;
		for (R int j = 1; j <= n; ++j)
			a[j] = a[j - 1] + b[j], minA = min(minA, a[j]);
		if (minA == n) break;
	}
	for (R int i = 1; i <= n; ++i) cout << a[i] << ' ';
	return 0;
}

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

using namespace std;
#define ll long long

int main(){
  ll n;
  cin>>n;
  ll ans=1;
  for(ll i=1;i*i<=n;i++){
     if(n%i==0)ans=i;
  }
  cout<<ans+n/ans-2<<endl;
}
  

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

#define rep(i, u) for (int i = 0; i < u; i++)

using ll = long long;
using ull = unsigned long long;

int main() {
  int n;
  int a[200000] = {};
  cin >> n;
  rep(i, n) cin >> a[i];
  int maxv = a[1] - a[0];
  int minv = a[0];
  rep(i, n - 1) {
    maxv = max(a[i + 1] - minv, maxv);
    minv = min(a[i + 1], minv);
  }
  cout << maxv << endl;
  return 0;
}



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

count = [0, 0, 0, 0, 0, 0, 0, 0, 0]

for i in range(N):
    if A[i] < 400:
        count[0] = 1
    elif A[i] < 800:
        count[1] = 1
    elif A[i] < 1200:
        count[2] = 1
    elif A[i] < 1600:
        count[3] = 1
    elif A[i] < 2000:
        count[4] = 1
    elif A[i] < 2400:
        count[5] = 1
    elif A[i] < 2800:
        count[6] = 1
    elif A[i] < 3200:
        count[7] = 1
    else:
        count[8] += 1

color_max = sum(count)
if count[8] == 0:
    color_min = sum(count)
else:
    color_min = sum(count[:7]) + 1

print(color_min, color_max)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
int dp[100000];
int h[100000];
int k;  
int cost(int n)
{if(dp[n]!=-1) return dp[n]; else
    {   int min;
        for(int i=n-1;(i>=n-k)&&i>=0;i--)
        {
        int x=abs(h[n]-h[i])+cost(i);
         if(i==n-1)min=x;
         if(min>x)min=x;}
         dp[n]=min;}
         return dp[n];}
           
int main()
{
     int n;
    cin>>n;cin>>k;
    for(int i=0;i<n;i++)
{cin>>h[i];dp[i]=-1;}
dp[0]=0;
dp[1]=abs(h[1]-h[0]);
     int c=cost(n-1);
    cout<<c;
}

Measured memory_bytes: 7296
#include <bits/stdc++.h> 
using namespace std;
///////////////////////////////////////////
const long long int INF = 100000000000;
const long long int Mod = 1000000007;
using ll = long long int; //long long int は64bit
using vi = vector<int>; using Vi = vector<long long int>;
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
#define mt make_tuple
#define all(x) (x).begin(),(x).end()
#define rep(i,N) for(long long int i=0;i<N;i++)
#define np nullptr
template<class T>bool chmax(T &former, const T &b) { if (former<=b) { former=b; return true; } return false; }
template<class T>bool chmin(T &former, const T &b) { if (b<former) { former=b; return true; } return false; }
template<class T>T sqar(T x){ return x*x; }//sqrt(x)は平方根;
#define Sort(v) std::sort(v.begin(), v.end(), std::greater<decltype(v[0])>()) //降順でVをソート
#define fill(x,num) memset(x,num,sizeof(x));
typedef vector<vector<ll> > matrix;
typedef pair<ll,ll> Pair;
bool p_compare(const Pair& firstP, const Pair& secondP){ 
    return firstP.second < secondP.second; 
}//sort(all(v),p_compare)で昇順ソート
//////////////////////////^^ *Emile ^^^//////////////////////////////////////////////////////
//Snipet -> Caps Lock

ll n;
vi t,x,y;

int main(){
    cin.tie(0);ios::sync_with_stdio(false);
    cin>>n;ll tt,xx,yy;
    x.pb(0);y.pb(0);t.pb(0);
    rep(i,n){
        cin>>tt>>xx>>yy;
        t.pb(tt);
        x.pb(xx);
        y.pb(yy);
    }
    bool ans = true;
    rep(i,n){
        if((t[i+1]-t[i])%2 != (abs(x[i+1]-x[i])+abs(y[i+1]-y[i]))%2 )ans = false;
        if(abs(x[i+1]-x[i])+abs(y[i+1]-y[i]) > t[i+1]-t[i])ans = false;
    }
    if(ans)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    return 0;
}

Measured memory_bytes: 1644
#include <iostream>

using namespace std;
int gcd(int a,int b)
{
  int temp;
  if(a<b)
  {
    temp=a;
    a=b;
    b=temp;
  }
  while(b!=0)
  {
    temp=b;
    b=a%b;
    a=temp;
  }
  return a;
    
    
}
int main()
{
  int n;
  cin>>n;
  int a[n],pregcd[n],postgcd[n];
  for(int i=0;i<n;i++)
  {
    cin>>a[i];
  }
  pregcd[0]=a[0];
  postgcd[n-1]=a[n-1];
  for(int i=1;i<n;i++)
  {
    pregcd[i]=gcd(pregcd[i-1],a[i]);
    postgcd[n-i-1]=gcd(postgcd[n-i],a[n-i-1]);
    
  }
  int max = postgcd[1];
  for(int i=1;i<n;i++)
  {
    int current = gcd(pregcd[i-1],postgcd[i+1]);
    if(current>max)
      max=current;
  }
  cout<<max;
}
  

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

int main() {

    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
 
    int n;
    cin>>n;
    int half = n/2;
    if (n%2==0) cout<<setprecision(10)<<0.5;
    else cout<<setprecision(10)<<(double)(half+1)/n;
}

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

class G
{
	static void Main()
	{
		Func<int[]> read = () => Console.ReadLine().Split().Select(int.Parse).ToArray();
		var h = read();
		var rs = new int[h[1]].Select(_ => read()).ToArray();

		var map = rs.ToLookup(r => r[0], r => r[1]);
		var ins = new int[h[0] + 1];
		foreach (var r in rs) ins[r[1]]++;

		var q = Enumerable.Range(1, h[0]).Where(i => ins[i] == 0).ToList();
		var c = -1;
		for (; q.Any(); c++)
		{
			var ps = q.ToArray();
			q.Clear();

			foreach (var p in ps)
				foreach (var np in map[p])
				{
					ins[np]--;
					if (ins[np] == 0) q.Add(np);
				}
		}
		Console.WriteLine(c);
	}
}


Measured memory_bytes: 38936
H = int(input())

div_num = 0
attack_num = 0
if H == 1:
	print("1")
else:
	while True:
		H = H // 2
		attack_num += 1
		if H == 1:
			break
	
	print(sum([2**i for i in range(attack_num+1)]))


Measured memory_bytes: 2940
//E - Logs
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <cstring>

#define LL long long
#define Lowbit(X) (X&(-X))
#define Lson (X<<1)
#define Rson (X<<1|1)
#define Cl(X,Y) memset((X),(Y),sizeof(X))
#define FOR(i,A,B) for(LL i=A;i<=B;i++)
#define BOR(i,A,B) for(LL i=A;i>=B;i--)
#define FOR_SIDE(i,A) for(LL i=Head[A];i;i=Next[i])
#define INF 0x7fffffff
using namespace std;
const int MAXN=2e5+10;

int Ans,Len[MAXN],Total,Limit;

inline void File() {
    freopen(".in","r",stdin);
    freopen(".out","w",stdout);
}

inline bool Check(int Temp) {
    int New=0;
    FOR(i,1,Total) New+=(((Len[i]-1)/Temp));
    return New<=Limit;
}

int main() {
    //File();
    scanf("%d %d",&Total,&Limit);
    int L=1,R=0;
    FOR(i,1,Total) { scanf("%d",&Len[i]); R=max(R,Len[i]); }
    while(L<=R) {
        int Mid=(L+R)>>1;
        if(Check(Mid)) R=Mid-1,Ans=Mid;
        else L=Mid+1;
    }
    printf("%d\n",Ans);
    //fclose(stdin); fclose(stdout);
   // system("pause");
    return 0;
}

Measured memory_bytes: 4584
import heapq

n, m = map(int, input().split(" "))

a = [- int(i) for i in input().split(" ")]
heapq.heapify(a)

for _ in range(m):
    largest = heapq.heappop(a)
    heapq.heappush(a, int(largest / 2))

print(- sum(a))

Measured memory_bytes: 14180
#include <bits/stdc++.h>
using namespace std;
#define all(a) a.begin(), a.end()
#define rep(i, n) for(int i = 0; i < n; i++)
#define endl "\n"
typedef long long ll;

const int BIG_NUM = 1e9;
//

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    
    int x;
    cin >> x;
    if(x == 1) {
        cout << 0;
    } else {
        cout << 1;
    }
    return 0;
}


Measured memory_bytes: 3612
#include<iostream>
#include<cstdlib>
#include<cstring>
#include<algorithm>
using namespace std;
long long L;
int main()
{
	int N;
	cin>>N;
	long long a=2,b=1;
	for(int i=0;i<=N;i++)
	{
	if(i==0) L=2;
	else if(i==1) L=1;
	else
		{
			L = a + b;
			a = b;
			b = L;
		}
	}
	cout<<L<<endl;
	return 0;
}

Measured memory_bytes: 256
import decimal
import math

a, b, x = map(decimal.Decimal, input().split())

min_x_fac = math.floor(a / x) 
max_x_fac = math.floor(b / x)

count = max_x_fac - min_x_fac
if a % x == 0:
    count += 1

print(count)

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

using namespace std;

#define int long long

const int N=1e5+5;
int n,m,cnt[2],sum,ans;
vector<int> gr[N];
bool used[N],val[N],ok;
queue<int> q;

void bfs(){
    while(!q.empty()){
        int u=q.front(); q.pop();
        cnt[ val[u] ]++;
        sum+=gr[u].size();
        for(int v:gr[u]){
            if(!used[v]){
                val[v]=1-val[u];
                used[v]=1;
                q.push(v);
            }
            else{
                if(val[v]==val[u]) ok=1;
            }
        }
    }
}

signed main(){
    ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    cin>>n>>m;
    for(int i=1;i<=m;++i){
        int u,v; cin>>u>>v;
        gr[u].push_back(v); gr[v].push_back(u);
    }

    for(int i=1;i<=n;++i){
        if(!used[i]){
            while(!q.empty()) q.pop();
            q.push(i);
            cnt[0]=cnt[1]=sum=ok=0;
            used[i]=1;
            bfs();
            //cout<<"ok="<<ok<<" cnt0="<<cnt[0]<<" cnt1="<<cnt[1]<<" sum="<<sum<<"\n";
            if(ok) ans+=((cnt[0]+cnt[1])*(cnt[0]+cnt[1]-1)-sum)/2;
            else{
                ans+=cnt[0]*cnt[1]-sum/2;
            }
        }
    }

    cout<<ans;

    return 0;
}


Measured memory_bytes: 7040
/*
  AOJ 0619
  Title:Selecting Subjects
  @kankichi573
*/
#include <stdio.h>
#define min(x,y) (((x)<(y))?(x):(y))

int s[6];

int main()
{
  int i,sum;

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

  sum -= min(min(s[0],s[1]),min(s[2],s[3])) ;
  sum -= min(s[4],s[5]);

  printf("%d\n",sum);
    
  return(0);
}

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

#define REP(i, n) for(int (i)=0;(i)<(n);++(i))
#define REPV(iter, v) for(auto (iter)=(v).begin(); (iter)!=(v).end();++(iter))
#define ALL(v) (v).begin(),(v).end()

#define MOD 1000000007

using namespace std;

typedef long long ll;

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

    return gcd(b, a % b);
}

int main()
{
    ll N, M;
    cin >> N >> M;
    vector<ll> a(N);
    REP(i, N)
    {
        cin >> a[i];
        a[i] /= 2;
    }

    ll lcm = a[0];
    bool flag = true;
    REP(i, N - 1) 
    {
        lcm = lcm * a[i + 1] / gcd(lcm, a[i + 1]);
        if (lcm > M)
        {
            flag = false;
            break;
        }
    }
    REP(i, N)
    {
        if ((lcm / a[i]) % 2 == 0) 
        {
            flag = false;
            break;
        }
    }
    ll ans;
    if (!flag)
    {
        ans = 0;
    }
    else
    {
        ll num = (M / lcm);
        if (num % 2 == 0)
        {
            ans = num / 2;
        }
        else
        {
            ans = num / 2 + 1;
        }
        
    }
    cout << ans << endl;
}


Measured memory_bytes: 1152
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)*}
    };
}

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!{
        n:usize,
        s:chars,
    }
    let mut ans = 0;
    for i in 0..n-2{
        if s[i] == 'A' && s[i+1] == 'B' && s[i+2] == 'C'{
            ans += 1;
        }
    }
    println!("{}",ans);
}

Measured memory_bytes: 4352
/*
AizuOnline A0503
Title
*/
#include <stdio.h>
// Select Below
//#include <stdlib.h>
//#include <string.h>
//#include <float.h>
//#include <math.h>
//Global data section
int n,m;
int nT[3];
int TRAY[3][50];
int POS[15];
//int LAST1TABLE[3][3]={{0,1,2},{5,4,3},{6,7,8}};
//
int expt3(int x)
{
  if(x==0)
    return(1);
  else
    return(3*expt3(x-1));
}
int conv3to10()
{
  int i,sum;

  sum = 0;
  for(i=1;i<=n;i++)
    {
      sum *= 3;
      sum += POS[i];
    }  
  return(sum);
}
void calc1()
{
  int i,j;

  for(i=1;i<=n-1;i++)
    if(POS[i]==1)
      {
	// printf("%d:",i);
      for(j=i+1;j<=n;j++)
	{
	POS[j] = 2 - POS[j];
	}
      }
}
void print()
{
  int i,j;
	printf("\n");
  for(i=0;i<3;i++)
    {
      printf("%d ",(nT[i]));
      {
	for(j=0;j<nT[i];j++)
	  {
	    printf("%d ",TRAY[i][j]);
	  }
	printf("\n");
      }
    }
}
print2()
{
  int i;
  for(i=1;i<=n;i++)
    printf("%d ",POS[i]);
  printf("\n");
}
main()
{
  int i,j,temp,ret,half,all;
  while(EOF != scanf("%d %d",&n,&m) && (n || m))
    {
      for(i=0;i<3;i++)
	{
	  scanf("%d ",&(nT[i]));
	  for(j=0;j<nT[i];j++)
	    {
	      scanf("%d ",&temp);
	      TRAY[i][j]=temp;
	      POS[temp]=i;
	      //printf("::%d ",POS[temp]);
	    }
	}
    

      //print2();
      calc1();
      //print2();
      ret=conv3to10();

      all=expt3(n)-1;half = all/2;
      if(ret > half)
	ret = all-ret;

      if(ret <= m)
	printf("%d\n",ret);
      else
	printf("%d\n",-1);
    }
return(0);
}

Measured memory_bytes: 600
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    int a;
    cin>>a;
    string s;
    cin>>s;
    
    if(a>=s.size()){
        cout<<s;
        return 0;
    }else{
        for(int i=0;i<a;i++){
            cout<<s[i];
        }
        cout<<"...";
        return 0;
        
    }
}


Measured memory_bytes: 3584
#include<iostream>
#include<iomanip>
#include<map>
#include<set>
#include<string>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<stack>
#include<cstring>
#include<sstream>
using namespace std;
 
#define P(p) cout<<(p)<<endl
#define rep(i,m,n) for(int i = (m); i < (int)(n); i++)
#define rrep(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define vsort(v) sort(v.begin(), v.end());
#define rvsort(v) sort(v.begin(), v.end(),greater<int>());
#define YES cout<<"YES"<< endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl  
#define yes cout<<"yes"<<endl
#define no cout<<"no"<<endl
#define ret return
#define lb(v,n) lower_bound(v.begin(),v.end(),n)
#define ub(v,n) upper_bound(v.begin(),v.end(),n)
#define mae(v) max_element(v.begin(),v.end())
#define mie(v) min_element(v.begin(),v.end())
#define INF 0x7FFFFFFF
#define mod 1000000007
typedef long long ll;
////////////////////////////////////////////////////////////

ll lucas( ll a , ll b , int n ){
	
	ll c = a + b;

	if( n == 0 )
		ret c;
	else
		ret lucas( b , a+b , n-1 );

}

int main(){
	int n;
	cin >> n;
	if( n == 0 )
		cout << 2 << endl;
	else if( n == 1 )
		cout << 1 << endl;
	else
		cout << lucas(2,1,n-2) << endl;

	ret 0;
}

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

int main() {
	int N, K, ans;
	string S;
	cin >> N >> K >> S;
	pair<int, int> tmp1;
	vector<pair<int, int>> tmp2;
	for (int i = 0; i < N; ++i) {
		if (S[i] == '0') ++tmp1.first;
		else {
			if (tmp1.first) tmp2.push_back(tmp1);
			tmp1.first = 0;
			tmp1.second = i + 1;
		}
	}
	if (tmp1.first) tmp2.push_back(tmp1);
	if (K >= tmp2.size()) ans = N;
	else {
		ans = tmp2[K].second;
		for (int i = 1; i < tmp2.size() - K; ++i) ans = max(ans, tmp2[K + i].second - tmp2[i - 1].first - tmp2[i - 1].second);
		ans = max(ans, N - tmp2[tmp2.size() - K - 1].first - tmp2[tmp2.size() - K - 1].second);
	}
	cout << ans;
}

Measured memory_bytes: 1020
using System.Linq;
using static System.Console;
using static System.Math;
class Z { static void Main() => new _K(); }
class _K
{
	int[] G => Strs.Select(int.Parse).ToArray();
	string[] Strs => ReadLine().Split();
	int K, L;
	readonly int[,] sum;
	public _K()
	{
		var I = G;
		K = I[1];
		L = 4 * K;
		sum = new int[L + 1, L + 1];
		for (var i = 0; i < I[0]; i++)
		{
			var S = Strs;
			if (S[2] == "B") Add(int.Parse(S[0]) % (2 * K) + 1, int.Parse(S[1]) % (2 * K) + 1);
			else Add((int.Parse(S[0]) + K) % (2 * K) + 1, int.Parse(S[1]) % (2 * K) + 1);
		}
		for (var x = 0; x < L; x++) for (var y = 0; y <= L; y++) sum[x + 1, y] += sum[x, y];
		for (var x = 0; x <= L; x++) for (var y = 0; y < L; y++) sum[x, y + 1] += sum[x, y];
		var max = 0;
		for (var i = 0; i < K; i++) for (var j = 0; j < K; j++)
			{
				var s = Sum(i, j) + Sum(i + K, j + K);
				max = Max(max, Max(s, I[0] - s));
			}
		WriteLine(max);
	}
	void Add(int x, int y)
	{
		sum[x, y]++;
		sum[x + 2 * K, y]++;
		sum[x + 2 * K, y + 2 * K]++;
		sum[x, y + 2 * K]++;
	}
	int Sum(int i, int j) => sum[i + K, j + K] - sum[i + K, j] - sum[i, j + K] + sum[i, j];
}


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

int main(void){
    int n;
    scanf("%d",&n);

    double v[n];
    
    for(int i = 0;i < n;i++){
        scanf("%lf",&v[i]);
    }

    for(int j = 0;j < n;j++){
        double temp1 = 10000; //max
        double temp2 = 10000; //max
        int temp1pos = 0,temp2pos = 0;
        for(int i = 0;i < n;i++){
            if(v[i] < temp1 && v[i] != (double)0){
                temp2 = temp1;
                temp2pos = temp1pos;
                temp1 = v[i]; //最小値の場所と数字を記録
                temp1pos = i;
            } else if(v[i] < temp2 && v[i] != (double)0){
                temp2 = v[i]; //２番めに小さい値の場所と数字を記録
                temp2pos = i;
            }
        }
        if(temp2 == 10000){
            break;
        }
        v[temp1pos] = (temp1 + temp2) / (double)2;
        v[temp2pos] = 0;
    }

    for(int i = 0;i < n;i++){
        if(v[i] != 0){
            printf("%lf\n",v[i]);
        }
    }
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define Keep_calmYou_are_still_learning ios_base::sync_with_stdio(false);cin.tie(NULL);//freopen("out.txt","w",stdout);
typedef long long ll;
typedef long double ld;
using namespace std;


int main()
{
    Keep_calmYou_are_still_learning;

    ll n , m;
    cin>>n>>m;
    ll w[n],v[n],ans=0;
    for (ll i=0;i<n;i++)
        cin>>w[i]>>v[i];

   ll dp[(int) 1e5 + 5];
   for (ll i=0;i<1e5+5;i++)
    dp[i]= 1e10;

    dp[0]=0;

    for (ll i=0;i<n;i++)
    {
        for (ll j=1e5-v[i];j>=0;j--)
        {
            if (dp[j]<m)
                dp[j+v[i]]=min(dp[j+v[i]],dp[j]+w[i]);
            if (dp[j+v[i]]<=m)
                ans=max(ans,j+v[i]);
        }
    }
    cout<<ans<<'\n';
    return 0;
}


Measured memory_bytes: 1024
import java.util.Scanner;

class Main{
	static final long MOD = 1000000007;

	static int H, W, K;
	static long[][] dp = new long[110][10];



	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);			//文字の入力
		String number = sc.next();
		int ans = 1000000000;
			for(int j = 0;j + 3 <= number.length();j++){
				String sub = number.substring(j, j+3);
				int num = Integer.parseInt(sub);
				int sum = Math.abs(753-num);
				ans = Math.min(ans, sum);
			
		}
		System.out.println(ans);
	}





}







class Pair implements Comparable{
	int from;		//p
	int end;		//y
	int num;
	int bango;
	@Override
	public int compareTo(Object other) {
		Pair otherpair = (Pair)other;

		return end - otherpair.end;
	}
}


Measured memory_bytes: 21716