akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cmath>

#include <vector>
#include <algorithm>
#include <limits>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <array>
#include <queue>

typedef long long ll;

using namespace std;

void eratosthenes_sieve(ll n, vector<ll> &primes) {
    bool is_prime[n];
    is_prime[0] = false;
    is_prime[1] = false;
    for (int i = 2; i < n; ++i) {
        is_prime[i] = true;
    }
    for (int i = 2; i < n; ++i) {
        if (is_prime[i]) {
            primes.push_back(i);
            for (int j = i * 2; j < n; j += i) {
                is_prime[j] = false;
            }
        }
    }
}

void prime_factorization(ll n, vector<ll> &primes, vector<pair<ll, int>> &result) {
    for (ll p: primes) {
        if (p * p > n) {
            break;
        }
        if (n % p != 0) {
            continue;
        }
        int num = 0;
        while (n % p == 0) {
            ++num;
            n /= p;
        }
        result.emplace_back(p, num);
    }
    if (n != 1) {
        result.emplace_back(n, 1);
    }
}

int main() {
    int n;
    cin >> n;
    ll result = 0;
    vector<ll> primes;
    eratosthenes_sieve(n, primes);
    for (int c = 1; c < n; ++c) {
        vector<pair<ll, int>> pf;
        prime_factorization(n - c, primes, pf);
        ll part = 1;
        for (auto p: pf) {
            part *= (p.second + 1);
        }
        result += part;
    }
    cout << result << endl;
}


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

#define EB emplace_back
#define int long long
#define F first
#define S second
#define N 500005
#define all(x) x.begin(),x.end()
#define endl '\n'
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)


using namespace std;


int32_t main()
{
    IOS;

    int tt=1;
	//cin >> tt;
	while (tt--)
	{
		int n; cin >> n;
		map<int,int> mp;
		for (int i = 0; i < n - 1; i++)
		{
			int tpm; cin >> tpm;
			mp[tpm]++;
		}
		for (int i = 0; i < n; i++)
		{
			cout << mp[i + 1] << endl;
		}
		
	}
    return 0;
}


Measured memory_bytes: 16148
K = int(input())
lis = [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]
print(lis[K-1])

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

ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }

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

  int dd[n];
  for (int i = 0; i < n; i++) {
    int xx;
    cin >> xx;
    dd[i] = abs(x - xx);
  }

  if (n == 1) {
    cout << dd[0] << endl;
    return 0;
  }

  int ans = gcd(dd[0], dd[1]);
  for (int i = 2; i < n; i++) {
    ans = gcd(ans, dd[i]);
  }

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
int  main()
{
    int n,k,ar[200007];
    cin>>n>>k;
    int sum=0;
    for(int i=0;i<n;i++)
        cin>>ar[i];
    sort(ar,ar+n);
    for(int i=0;i<k;i++)
        sum+=ar[i];
    cout<<sum<<endl;
    return 0;
}


Measured memory_bytes: 3608
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
typedef long long ll;
#define rep(i,n) for (int i = 0; i < (n); i++)
#define repe(i,n) for (int i = 0; i <= (n); ++i)
#define repe1(i,n) for (int i = 0; i <= (n); ++i)
#define all(x) (x).begin(),(x).end()
#define pb(x) push_back(x)
#define eb(k,v) emplace_back(k,v)
#define ct(res) cout << res << "\n";
#define vi vector<int>
#define vl vector<ll>
using namespace std;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const int INF = 1e9;
const ll MOD = 1000000007;
using Graph = vector<vector<int>>;
ll gcd(ll a, ll b) {return (a%b) ? gcd(b, a%b) : b;}


int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int k; cin >>k;
    ll ans = 0;
    for(int i=1; i<=k; ++i) {
        for(int j=1; j<=k; ++j) {
             for(int kk=1; kk<=k; ++kk) {
                 ans += gcd(i,gcd(j,kk));
             }
        }
    }
    ct(ans);
}



Measured memory_bytes: 3656
n = int(input())
A = [int(i) for i in input().split()]

p = 10 ** 9 + 7

def fact(n, p=10**9 + 7):
    f = 1
    for i in range(1, n+1):
        f = f * i % p
    return f

def get_inv(n, p=10**9 + 7):
    inv = [0, 1]
    for i in range(2, n+1):
        inv.append(-(p//i * inv[p%i]) % p)
    return inv

f = fact(n)
inv = get_inv(n)

csum = [0]

for i in range(1, n+1):
    csum.append((csum[-1] + inv[i]) % p)

ans = 0
for i, a in enumerate(A):
    ans += (csum[i+1] + csum[n-i] - csum[1] + p) % p * a
    ans %= p

print(ans * f % p)

Measured memory_bytes: 15248
#include<bits/stdc++.h>
using namespace std;
int n,m,a[200005],b[200005],ans[200005],temp[200005];
void quick_pow(long long k){
    for(int i=1;i<=n;++i){
        ans[i]=i;
        b[i]=a[i];
    }
    while(k){
        if(k&1){
            for(int i=1;i<=n;++i)
                temp[i]=b[ans[i]];
            for(int i=1;i<=n;++i)
                ans[i]=temp[i];
        }
        for(int i=1;i<=n;++i)
            temp[i]=b[b[i]];
        for(int i=1;i<=n;++i)
            b[i]=temp[i];
        k>>=1;
    }
    return;
}
int main(){
    long long k;
    scanf("%d %lld",&n,&k);
    for(int i=1;i<=n;i++)scanf("%d",&a[i]);
    quick_pow(k);
    printf("%d\n",ans[1]);
    return 0;
}

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

using namespace std;
using ll = long long;

const int N = 1e6 + 123;

signed main() {
    ios_base::sync_with_stdio(false); 
    cin.tie(nullptr);
    ll n;
    cin >> n;
    ll h[N], dp[N];
    for (int i = 1; i <= n; i++) 
        cin >> h[i];
    dp[0] = 0;
    dp[1] = 0;
    dp[2] = abs(h[2] - h[1]);
    for (int i = 3; i <= n; i++)
        dp[i] = min(dp[i - 2] + abs(h[i] - h[i - 2]), dp[i - 1] + abs(h[i] - h[i - 1]));
    cout << dp[n] << "\n";          
    return false;
}

Measured memory_bytes: 6656
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair< ll, ll > Pi;
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep2(i,n) for(int i=1;i<=(n);i++)
#define rep3(i,i0,n) for(int i=i0;i<(n);i++)
#define pb push_back
#define mod 1000000007
const ll INF = 1LL << 60;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
ll gcd(ll a, ll b) {return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) {return a/gcd(a,b)*b;}
#define all(x) x.begin(), x.end()
#define mp make_pair
bool compare(Pi a, Pi b) {
    if(a.first != b.first){
        return a.first < b.first;
        
    }else{
        return a.second < b.second;
    }
}


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


int main() {
    ll X,A,B;
    cin >>X>>A>>B;
    

    cout << (X-A)%B << endl;


    return 0;
    

}

Measured memory_bytes: 3568
pub struct ProconReader<R: std::io::Read> {
    reader: R,
}

impl<R: std::io::Read> ProconReader<R> {
    pub fn new(reader: R) -> Self {
        Self { reader }
    }
    pub fn get<T: std::str::FromStr>(&mut self) -> T {
        use std::io::Read;
        let buf = self
            .reader
            .by_ref()
            .bytes()
            .map(|b| b.unwrap())
            .skip_while(|&byte| byte == b' ' || byte == b'\n' || byte == b'\r')
            .take_while(|&byte| byte != b' ' && byte != b'\n' && byte != b'\r')
            .collect::<Vec<_>>();
        std::str::from_utf8(&buf)
            .unwrap()
            .parse()
            .ok()
            .expect("Parse Error.")
    }
}

mod rolling_hash {
    const M: u64 = 1_000_000_000 + 9;
    const B: u64 = 999999937;
    pub struct RollingHash {
        h: Vec<u64>,
        p: Vec<u64>,
    }
    impl RollingHash {
        pub fn new(s: &[u64]) -> Self {
            let n = s.len();
            let mut h = vec![0; n + 1];
            let mut p = vec![0; n + 1];
            p[0] = 1;
            for i in 0..n {
                h[i + 1] = (h[i] * B + s[i]) % M;
                p[i + 1] = p[i] * B % M;
            }
            Self { h, p }
        }
        pub fn get(&self, range: std::ops::Range<usize>) -> u64 {
            let l = range.start;
            let r = range.end;
            (self.h[r] + M - self.h[l] * self.p[r - l] % M) % M
        }
    }
}

fn main() {
    let stdin = std::io::stdin();
    let mut rd = ProconReader::new(stdin.lock());

    use rolling_hash::RollingHash;

    let n: usize = rd.get();
    let s: String = rd.get();
    let t = s.chars().map(|c| c as u64).collect::<Vec<_>>();
    let rh = RollingHash::new(&t);
    let mut ans = 0;
    for i in 0..n {
        for j in (i + 1)..n {
            let mut ok = 0;
            let mut ng = std::cmp::min(j - i, n - j) + 1;
            while ng - ok > 1 {
                let m = (ng + ok) / 2;
                if rh.get(i..(i + m)) == rh.get(j..(j + m)) {
                    ok = m;
                } else {
                    ng = m;
                }
            }
            ans = std::cmp::max(ans, ok);
        }
    }
    println!("{}", ans);
}

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

#define pb push_back
#define eb emplace_back
#define mk make_pair
#define fi first
#define se second

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

const int INF = 0x3f3f3f3f;
const int MAXN = 1e5 + 5;
const int MAXK = 12;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

double dist(double x, double y) {
	return x * x + y * y;
}

int main() {
	auto c = clock();

	int n; scanf("%d", &n);
	vector<pair<double, double> > a(n);
	for (auto& p : a) scanf("%lf%lf", &p.fi, &p.se);

	double x = 0, y = 0;
	for (int i = 0; i < n; i++)
		x += a[i].fi, y += a[i].se;
	x /= n, y /= n;

	double d = 0, p = 0.1;
	while((clock()-c)/double(CLOCKS_PER_SEC) <= 1.8) {
		d = dist(a[0].fi-x, a[0].se-y);
		int j = 0;

		for (int i = 1; i < n; i++) {
			double cur = dist(x-a[i].fi, y-a[i].se);
			if (d < cur) d = cur, j = i;
		}
		x += (a[j].fi - x) * p;
		y += (a[j].se - y) * p;
		p *= 0.999;
	}

	printf("%.10lf\n", sqrt(d));
	return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vl = vector<ll>;
using vll = vector<vl>;
using Pll = pair<ll, ll>;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(v) v.begin(), v.end()
#define sz(x) ((int) x.size())
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define F first
#define S second
const int MOD = 1e9+7;
const ll INF = 2e15;
template<class T> void print(const T& t){ cout << t << endl; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}

int main(){
  ll n;
  cin >> n;
  string s;
  cin >> s;
  vl white(n+1, 0);
  vl red(n+2, 0);
  for(ll i=1;i<=n;i++){
    if(s[i-1]=='W'){
      white[i] = white[i-1] + 1;
    }
    else{
      white[i]=white[i-1];
    }
  }
  for (ll i = n; i > 0;i--){
    if(s[i-1]=='R'){
      red[i] = red[i + 1] + 1;
    }
    else{
      red[i] = red[i + 1];
    }
  }
  for (ll i = 1; i <= n; i++)
  {
    if(red[i+1]==white[i]){
      print(white[i]);
      return 0;
    }
  }
  print(0);
}

Measured memory_bytes: 6760
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <ctime>
using namespace std;

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

#define all(c) (c).begin(), (c).end()
#define pb push_back
#define mp make_pair
#define EXIST(v,i) (find(all(v), i) != (v).end())
#define ERASE(v,i) (v).erase(remove(all(v), i), (v).end())
#define INDEX(v,i) (find(all(v), i) - (v).begin())
#define rep(i,n) for(int i = 0; i < (int)n; ++i)
#define debug(x) cerr << #x << " = " << (x) << endl;

inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

const int INF = 100000000;
const double PI = 3.14159265358979323846;
const double EPS = 1e-10;

int main() {
	for(int n, k; cin >> n >> k && n && k;) {
		vector<int> arr(n);
		vector<int> sum(n);
		rep(i,n) cin >> arr[i];
		rep(i,k) sum[k-1] += arr[i];
		for(int i = k; i < n; i++) {
			sum[i] = sum[i - 1] + arr[i] - arr[i - k];
		}
		cout << *max_element(all(sum)) << endl;
	}
	return 0;
}

Measured memory_bytes: 1700
package main

import (
	"bufio"
	"fmt"
	"os"
)

func main() {
	var h, w int
	fmt.Scan(&h, &w)

	sc := bufio.NewScanner(os.Stdin)
	s := make([]string, h)
	for i := range s {
		sc.Scan()
		s[i] = sc.Text()
	}

	ls := make([][]int, h)
	for i := range ls {
		ls[i] = make([]int, w)
		for j := 0; j < w; j++ {
			if s[i][j] == '#' {
				ls[i][j] = 0
				continue
			}
			if j == 0 {
				ls[i][j] = 1
				continue
			}
			ls[i][j] = ls[i][j-1] + 1
		}
	}

	rs := make([][]int, h)
	for i := range rs {
		rs[i] = make([]int, w)
		for j := w - 1; j >= 0; j-- {
			if s[i][j] == '#' {
				rs[i][j] = 0
				continue
			}
			if j == w-1 {
				rs[i][j] = 1
				continue
			}
			rs[i][j] = rs[i][j+1] + 1
		}
	}

	ts := make([][]int, h)
	for i := range ts {
		ts[i] = make([]int, w)
	}
	for j := 0; j < w; j++ {
		for i := 0; i < h; i++ {
			if s[i][j] == '#' {
				ts[i][j] = 0
				continue
			}
			if i == 0 {
				ts[i][j] = 1
				continue
			}
			ts[i][j] = ts[i-1][j] + 1
		}
	}

	ds := make([][]int, h)
	for i := range ds {
		ds[i] = make([]int, w)
	}
	for j := 0; j < w; j++ {
		for i := h - 1; i >= 0; i-- {
			if s[i][j] == '#' {
				ds[i][j] = 0
				continue
			}
			if i == h-1 {
				ds[i][j] = 1
				continue
			}
			ds[i][j] = ds[i+1][j] + 1
		}
	}

	ans := 0
	for i := 0; i < h; i++ {
		for j := 0; j < w; j++ {
			if v := ls[i][j] + rs[i][j] + ts[i][j] + ds[i][j] - 3; v > ans {
				ans = v
			}
		}
	}
	fmt.Println(ans)
}


Measured memory_bytes: 138240
const allocate = (n, k, wList) => {
  // console.log(n);
  // console.log(k);
  // console.log(wList);

  const check = (P) => {
    let i = 0;
    for (let j=0; j<k; j++) {
      let s = 0;
      while(s + wList[i] <= P) {
        s += wList[i];
        i++;
        if (i === n) return n;
      }
    }
    return i;
  };

  let left = 0;
  let right = 100000 * 10000;
  let mid;
  while (left < right) {
    const sum = left + right;
    mid = (sum % 2 === 1) ? (sum - 1) / 2 : sum / 2;
    const v = check(mid);
    // console.log(`left: ${left}, right: ${right}, sum: ${sum}, mid: ${mid}`);
    // console.log(`v: ${v}`);
    if (v >= n) {
      right = mid;
    } else {
      left = mid + 1;
    }
  }
  return right;
};

let inputStr = '';

process.stdin.on('data', (input) => { inputStr += input; });

process.stdin.on('end', () => {
  const arr = inputStr.split('\n');
  const [n, k] = arr.shift().split(' ');
  const wList = arr.map(v => Number(v));
  console.log(allocate(Number(n), Number(k), wList));
})


Measured memory_bytes: 30028
#include <bits/stdc++.h>
#define fast ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL)
#define ll long long int
#define ld long double
using namespace std;
const int N = 1e6 + 5;
const int MOD = 1e9 + 7;


int main(){
	fast;
	ll n;
	ld d, sum = 0;
	cin >> n >> d;
	pair<double, double> x[n];
	for(int i = 0; i < n; ++i){
		cin >> x[i].first >> x[i].second;
		ll ans = x[i].first*x[i].first;
		ll ans1 = x[i].second*x[i].second;
		ld aa = ans + ans1;
		aa = sqrt(aa);
		if(aa <= d) ++sum;
	}
	cout << sum;
	return 0;
}


Measured memory_bytes: 6868
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
using namespace std;
typedef string::const_iterator State;
 
int expression(State &begin);
int term(State &begin);
int factor(State &begin);
int number(State &begin);
 
int expression(State &begin){
    int ret = term(begin); 
    for(;;){
        if(*begin == '+'){
            begin++; 
            ret = max(ret, term(begin)); 
        }else if(*begin == '*'){
            begin++;
            ret = min(ret, term(begin));
        }else{
            break;
        }
    }
    return ret;
}

int term(State &begin){
    if(*begin == '-'){
        begin++;
        return 2 - (term(begin));
    }else{
        return factor(begin);
    }
}

int factor(State &begin){
    if(*begin == '('){
        begin++;
        int ret = expression(begin);
        begin++;
        return ret;      
    }else{
        return number(begin);
    }
}
 

int number(State &begin){
    int ret = 0;
    while(isdigit(*begin)){
        ret *= 10;
        ret += *begin - '0';
        begin++;
    }
    return ret;
}
 
int main(){
    string s;
    while(1){
        cin >> s;
        if(s == ".") break;
        int ans = 0;
        rep(i, 0, 3){
            rep(j, 0, 3){
                rep(k, 0, 3){
                    string t = s;
                    rep(l, 0, t.size()){
                        if(t[l] == 'P') t[l] = '0' + i;
                        if(t[l] == 'Q') t[l] = '0' + j;
                        if(t[l] == 'R') t[l] = '0' + k;
                    }
                    State begin = t.begin();
                    int tmp = expression(begin);
                    if(tmp == 2) ans++;
                }
            }
        }
        cout << ans << endl;
    }
}


Measured memory_bytes: 2968
import sys
from collections import deque
input = sys.stdin.readline

N,M=map(int,input().split())
X=list(map(int,input().split()))
EDGE=[list(map(int,input().split())) for i in range(M)]
EDGE.sort(key=lambda x:x[2])

EDGELIST=[[] for i in range(N+1)]
for i in range(M):
    x,y,w=EDGE[i]
    EDGELIST[x].append(i)
    EDGELIST[y].append(i)


#UnionFind
Group=[i for i in range(N+1)]#グループ分け.Group[i]=jのときiとjは同じグループ

def find(x):#find(a)=find(b)のとき同じグループ
    while Group[x] != x:
        x=Group[x]
    return x

def Union(x,y):#xとyが同じグループになるよう更新
    if find(x) != find(y):
        Group[find(y)]=Group[find(x)]=min(find(y),find(x))

USE=[0]*M
WEIGHTSUM=[0]+[X[i] for i in range(N)]

QUE=deque()

for i in range(M):
    x,y,w=EDGE[i]
    
    if find(x)!=find(y):
        WEIGHTSUM[find(x)]=WEIGHTSUM[find(y)]=WEIGHTSUM[find(x)]+WEIGHTSUM[find(y)]
        Union(x,y)

    if w<=WEIGHTSUM[find(x)]:
        #USE[i]=1
        QUE.append(i)


while QUE:
    q=QUE.pop()
    x,y,w=EDGE[q]

    NQUE=deque([q])

    while NQUE:
        nq=NQUE.pop()

        if USE[nq]==1:
            continue
        x,y,_=EDGE[nq]
        for e in EDGELIST[x]+EDGELIST[y]:

            if EDGE[e][2]<=w:
                NQUE.append(e)
        USE[nq]=1
    
print(USE.count(0))

Measured memory_bytes: 56920
#include<bits/stdc++.h>
using namespace std;
int dp[100001][3];
int main(){
	int n;
	cin>>n;
	for(int i = 0; i < 10001; i++){
		for(int j = 0; j < 3; j++){
			dp[i][j] = 0;
		}
	}
	vector<int> a(n); vector<int> b(n); vector<int> c(n);
	for(int i = 0; i < n; i++){
		cin>>a[i]; cin>>b[i]; cin>>c[i];
	}
	dp[0][0] = a[0]; dp[0][1] = b[0]; dp[0][2] = c[0];
	
	for(int i = 1; i < n; i++){
		dp[i][0] = max(dp[i-1][1],dp[i-1][2]) + a[i];
		dp[i][1] = max(dp[i-1][0],dp[i-1][2]) + b[i];
		dp[i][2] = max(dp[i-1][0],dp[i-1][1]) + c[i];
	}
	cout<<max(dp[n-1][0],max(dp[n-1][1],dp[n-1][2]))<<"\n";
}

Measured memory_bytes: 2560
N = int(input())
h = list(map(int, input().split()))

#dp[i] = i番目までの最小値

dp = [0] * N

dp[1] = abs(h[1] - h[0])


for i in range(2, N):
    dp[i] = min(dp[i - 1] + abs(h[i - 1] - h[i]), dp[i - 2] + abs(h[i] - h[i - 2]))

print(dp[-1])


Measured memory_bytes: 13980
# -*- coding: utf-8 -*-
def get_nums(n):
    res = [0 for _ in range(n)]
    for i in range(n):
        res[i] = int(input())
    return res


times = get_nums(5)

min_quot = 10
target_idx = 5
for i, time in enumerate(times):
    quot = time % 10
    if quot > 0 and quot < min_quot:
        min_quot = quot
        target_idx = i

total = 0
for i, time in enumerate(times):
    if target_idx == i:
        total += time
        continue

    if time % 10 == 0:
        total += time
    else:
        total += int((time // 10 + 1) * 10)

print(total)

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

#define pb push_back
#define mp make_pair
#define all(n) (n).begin(),(n).end()
#define fi first
#define se second

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

const int MOD = 1e9+7;

int main() {

	ios::sync_with_stdio(0);
	cin.tie(0);

	int k;
	cin >> k;
	int cur = 0;
	for (int i = 0; i < 1000000; i++) {
		cur = ((cur*10)+7)%k;
		if (cur==0) {
			cout << (i+1) << "\n";
			return 0;
		}
	}
	cout << "-1\n";
}

Measured memory_bytes: 3592
import collections
class UnionFind:
    def __init__(self, N):
        self.parent = [i for i in range(N)]
        self.rank = [0]*N
        self.count = 0
    def root(self, a):
        if self.parent[a]==a:
            return a
        else:
            self.parent[a]=self.root(self.parent[a])
            return self.parent[a]
    def size(x):
        return -par[root(x)]

    def is_same(self, a, b):
        return self.root(a)==self.root(b)
    def unite(self, a, b):
        ra = self.root(a)
        rb = self.root(b)
        if ra == rb: return

        if self.rank[ra] < self.rank[rb]:
            self.parent[ra] = rb
        else:
            self.parent[rb] = ra
            if self.rank[ra] == self.rank[rb]: self.rank[ra] += 1
        self.count += 1
def main():
    n,m,k=map(int, input().split())
    friend = [0]*n
    fr = UnionFind(n)
    blocklist = [0]*n
    for i in range(m):
        a,b = map(int, input().split())
        fr.unite(a-1,b-1)
        friend[a-1]+=1
        friend[b-1]+=1
    for i in range(k):
        c,d=map(int, input().split())
        if(fr.root(c-1)==fr.root(d-1)):
            blocklist[c-1]+=1
            blocklist[d-1]+=1
    
    res = []
    dd = collections.defaultdict(int)
    for i in range(n):
        dd[fr.root(i)]+=1
    for i in range(n):
        res.append(dd[fr.root(i)]- blocklist[i] - friend[i]-1)
    print(*res)

if __name__ == '__main__':
    main()


Measured memory_bytes: 103852
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <cstdlib>
#include <tuple>

using ll = long long;
using namespace std;

vector<vector<int>> edge(100002);
int tmp1[100002]={}, tmp2[100002]={};

void dfs(int k, int d, int *a){
    if(a[k]){
        return;
    }
    a[k] = d;
    for(int t : edge[k]){
        dfs(t, d+1, a);
    }
    return;
}



int main(){
    int N;
    cin >> N;
    //int a[N], b[N];

    for(int i = 1 ; i < N; i++){
        int a,b;
        cin >> a >> b;
        edge[a].push_back(b);
        edge[b].push_back(a);
    }

    dfs(1, 1, tmp1);
    dfs(N, 1, tmp2);

    int countF = 0;
    int countS = 0;

    for(int i = 1; i <= N; i++){
        if(tmp1[i] <= tmp2[i]){
            countF++;
        }else{
            countS++;
        }
    }

    //printf("F,S : %d,%d",countF,countS);

    if(countF > countS){
        puts("Fennec");
    }else{
        puts("Snuke");
    }

    return 0;
}


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

using namespace std;

const int N = 102, K = 100005;
int dp[K], a[N];
int n;

bool cal(int y) {
	if (y < 0) return 1;
	if (y < a[0]) return 0;
	int &ret = dp[y];
	if (ret != -1) return ret;
	ret = 0;
	for (int i = 0; i < n; i++) {
		if (cal(y - a[i]) == 0) {
			ret = 1;
		}
	}
	return ret;
}

int main() {
	memset(dp, -1, sizeof(dp));
	int k;
	scanf("%d %d", &n, &k);
	for (int i = 0; i < n; i++) {
		scanf("%d", &a[i]);
	}
	printf(cal(k) ? "First" : "Second");
	return 0;
}


Measured memory_bytes: 5376
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const ll mod = 1e9+7;
const ll mx = 51;
int n;
ll mat[mx][mx];
ll ans[mx][mx];
void add_self(ll& a, ll b){
  a=a+b;
  if(a>=mod){
    a-=mod;
  }
}
ll mul(ll a, ll b){
  return (ll)a * b % mod;
}
int main(){
  ll k;
  cin >> n >> k;
  for(int i=0;i<n;i++){
    for(int j=0;j<n;j++){
      cin >> mat[i][j];
      ans[i][i]=1ll;
    }
  }
  while(k>0){
    ll c[mx][mx];
    if(k%2==1){
      memset(c,0,sizeof(c));
      for(int i=0;i<n;i++){
        for(int j=0;j<n;j++){
          for(int k=0;k<n;k++){
            add_self(c[i][k], mul(ans[i][j],mat[j][k]));
          }
        }
      }
      for(int i=0;i<n;i++) for(int j=0;j<n;j++) ans[i][j]=c[i][j];
    }
    memset(c,0,sizeof(c));
    for(int i=0;i<n;i++){
      for(int j=0;j<n;j++){
        for(int k=0;k<n;k++){
          add_self(c[i][k], mul(mat[i][j],mat[j][k]));
        }
      }
    }
    for(int i=0;i<n;i++) for(int j=0;j<n;j++) mat[i][j]=c[i][j];
    k/=2;
  }
  ll total = 0;
  for(int i=0;i<n;i++){
    for(int j=0;j<n;j++){
      add_self(total, ans[i][j]);
    }
  }
  cout<<total<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
    ios::sync_with_stdio(false);
    string a, b;
    cin >> a >> b;
    if (a == b) {
        cout << "Yes" << endl;
        return 0;
    }
    else {
        for (int i = 0; i < a.size()-1; i++) {
            string head = a.substr(i+1, a.size() - (i+1));
            string tail = a.substr(0,i+1);
            string con = head + tail;
            if (con == b) {
                cout << "Yes" << endl;
                return 0;
            }
        }
    }

    cout << "No" << endl;
    return 0;

}



Measured memory_bytes: 256
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int n = in.nextInt();
      
		long lsum[][] = new long[n][n]; // local sum:部分和
		for ( int i = 0; i < n; i++ ) {
			lsum[i][i] = in.nextInt();
		}
		for ( int r = 0; r < n; r++ ) {
			for ( int c = r + 1; c < n; c++ ) {
				lsum[r][c] = lsum[r][c - 1] + lsum[c][c];
			}
		}

		long cost[][] = new long[n][n]; // 累積コスト
		for ( int p = 1; p < n; p++ ) {
			for (int r = 0, c = p; c < n; r++, c++ ) {
				Long min = Long.MAX_VALUE;
				for ( int i = r; i <= c - 1; i++ ) {
					min = Math.min(min, cost[r][i] + cost[i + 1][c]);
				}
				cost[r][c] = min + lsum[r][c];
			}
		}

		System.out.println(cost[0][n - 1]);
		in.close();
	}
}

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

int main()
{
  int X,A,B; cin >>X >>A >>B;
  if (X<(B-A)) cout <<"dangerous" <<endl;
  else if ((B-A)<=0) cout <<"delicious" <<endl;
  else cout <<"safe" <<endl;
}


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


const int MAXN = 1005;

int main() {
  ll x;
  cin>>x;
  int ans=0;
  int a,b;
  a=x/500;
  x-=a*500;
  b=x/5;
  ans=a*1000+b*5;
  cout<<ans;

}


Measured memory_bytes: 384
# coding: utf-8
import sys
#from operator import itemgetter
sysread = sys.stdin.buffer.readline
read = sys.stdin.buffer.read
#from heapq import heappop, heappush
#from collections import defaultdict
sys.setrecursionlimit(10**7)
#import math
#from itertools import product, accumulate, combinations, product
#import bisect
#import numpy as np
#from copy import deepcopy
from collections import deque
#from decimal import Decimal
#from numba import jit

INF = 1 << 50

def bfs(MAZE, start, goal):
    H = len(MAZE)
    W = len(MAZE[0])
    MAP = [[INF] * W for _ in range(H)]
    walks = [(0,1), (1,0), (-1,0), (0, -1)]
    warps = []
    for i in range(-2, 3):
        for j in range(-2, 3):
            if i == 0 and j == 0: continue
            if not (i,j) in walks:
                warps.append((i, j))
    queue = deque([])
    k = (0,) + start
    queue.append(k)

    while queue:
        count, ci, cj = queue.pop()
        if (ci, cj) == goal:
            return count
        for ii, jj in walks:
            ni, nj = ci + ii, cj + jj
            if MAZE[ni][nj] == '.' and MAP[ni][nj] > count:
                queue.append((count, ni, nj))
                MAP[ni][nj] = count
        for ii, jj in warps:
            ni, nj = ci + ii, cj + jj
            if MAZE[ni][nj] == '.' and MAP[ni][nj] > count+1:
                queue.appendleft((count+1, ni, nj))
                MAP[ni][nj] = count + 1
    return -1


def run():
    H, W = map(int, sysread().split())
    Ci, Cj = map(int, sysread().split())
    Ci += 1
    Cj += 1
    Di, Dj = map(int, sysread().split())
    Di += 1
    Dj += 1
    MAZE = []
    MAZE.append('#' * (W + 4))
    MAZE.append('#' * (W + 4))
    for i in range(H):
        s = input()
        s = '##' + s + '##'
        MAZE.append(s)
    MAZE.append('#' * (W + 4))
    MAZE.append('#' * (W + 4))
    print(bfs(MAZE, (Ci, Cj), (Di, Dj)))

if __name__ == "__main__":
    run()

Measured memory_bytes: 98840
#include<iostream>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<cstdio>
#include<vector>
using namespace std;

const int N=100005;

struct node{
	int x,y,dx,dy,b;
}a[N];
int n,m,s1,s0,ans,t0,t1,x;
bool b[N];
char s[2];
vector<int> lev[N];

bool cmp1(node a,node b){
	return a.dx<b.dx;
}

int main(){
	int i,j,last,k,len;
	scanf("%d%d",&n,&m);
	for (i=1;i<=n;i++){
		scanf("%d%d",&a[i].x,&a[i].y);
		scanf("%s",s);
		a[i].b=(s[0]=='B');
		a[i].b^=(a[i].x/m&1)!=(a[i].y/m&1);
		a[i].dx=m-(a[i].x-a[i].x/m*m);
		a[i].dy=m-(a[i].y-a[i].y/m*m);
	}
	sort(a+1,a+1+n,cmp1);
	for (i=1;i<=n;i++){
		b[i]=a[i].b;
		if (b[i]) s1++;
		else s0++;
		lev[a[i].dy].push_back(i);
	}
	last=0; ans=max(s0,s1);
	for (i=0;i<=m;i++){
		t1=s1; t0=s0;
		ans=max(ans,max(s1,s0));
		for (j=1;j<=m;j++){
			len=lev[j].size();
			for (k=0;k<len;k++){
				x=lev[j][k];
				if (b[x]) t0++,t1--;
				else t1++,t0--;
			}
			ans=max(ans,max(t0,t1));
		}
		while (last<n&&a[last+1].dx==i+1){
			last++;
			b[last]^=1;
			if (b[last]) s1++,s0--;
			else s0++,s1--;
		}
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 5248
#include <iostream>
#include <vector>
#include <limits.h>

using namespace std;

int main(){
  int N, T, A, num, ans=INT_MAX;
  cin >> N >> T >> A;
  vector<int> H(N);
  for(int i=1;i<=N;i++){
    int H;
    cin >> H;
    int diff = abs(A*1000-(T*1000-H*6));
    if(diff<ans){
      ans = diff;
      num = i;
    }
  }
  cout << num << endl;
}

Measured memory_bytes: 256
using System;

namespace AGC031
{
    class As
    {
        static void Main(string[] args)
        {
            int N = int.Parse(Console.ReadLine());
            string S = Console.ReadLine();
            long[] c = new long[26];
            long mod = 1000000007;

            for (int i = 0; i < N; i++)
            {
                c[S[i] - 'a']++;
            }

            for (int i = 0; i < c.Length; i++)
            {
                if (c[i] != 0) c[i]++;
            }

            //Console.WriteLine(string.Join(",", c));
            long res = 1;
            for (int i = 0; i < c.Length; i++)
            {
                if (c[i] != 0) res = (res * c[i]) % mod;
            }
            Console.WriteLine(res - 1);
        }
    }
}


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

#define rep(i, n) for(int i = 0, i##_len = (n); i < i##_len; ++i)
#define all(x) (x).begin(), (x).end()
#define clr(ar, val) memset(ar, val, sizeof(ar))
#define sbp(p, n) rep(i, n) { int a, b; scanf("%d %d", &a, &b); p[i] = make_pair(a, b); }
template <class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template <class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; }
int gcd(int a,int b){return b?gcd(b,a%b):a;}
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair <int,int> P;
typedef long double ld;

int main(void)
{
  int s[26][50] = {}, x[26] = {}, n;
  clr(x, 50);
  cin >> n;
  rep(i, n){
    char str[51];
    cin >> str;
    rep(j, (int)strlen(str)) s[(int)str[j] - 'a'][i]++;
    rep(j, 26) chmin(x[j], s[j][i]);
  }
  rep(i, 26){
    rep(j, x[i]){
      cout << (char)(i + 'a');
    }
  }
  cout << endl;
  return 0;
}

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

int A[3];

int main() {
	for (int i = 0; i < 3; i++) cin >> A[i];
	sort(A, A + 3);

	int tot = 0;
	while (A[1] < A[2]) A[0]++, A[1]++, tot++;
	while (A[0] < A[1]) A[0] += 2, tot++;
	if (A[0] > A[1]) tot++;

	cout << tot << endl;
    return 0;
}

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

#define L 20
#define Gard NULL

struct Tree{
  int nodekey;
  struct Tree *parent;
  struct Tree *leftch;
  struct Tree *rightch;
};

typedef struct Tree  *Search;
Search road;

void Insert(int );
void Pre(Search );
void In(Search );


int main(){
  int loop,numnode;
  char order[L];
  int i;
    
  scanf("%d",&loop);
  
  for(i=0;i<loop;i++){
    scanf("%s",order);
    
    if(order[0]=='i'){
      scanf("%d",&numnode);
      Insert(numnode);
    }
    
    else if(order[0]=='p'){
      In(road);
      printf("\n");
      Pre(road);
      printf("\n");
    }
  }
  
  return 0;
}

void Insert(int numnode){
  Search xnode,ynode,znode;
  
  xnode=road;
  ynode=Gard;
  znode=malloc(sizeof(struct Tree));
  znode->nodekey=numnode;
  znode->leftch=Gard;
  znode->rightch=Gard;
  
  while(1){
    if(xnode==Gard)break;
    ynode=xnode;
    
    if(znode->nodekey<xnode->nodekey){
      xnode=xnode->leftch;
    }
    
    else{
      xnode=xnode->rightch;
    }
  }
  
  znode->parent=ynode;
  
  if(ynode==Gard){
    road=znode;
  }
  
  else if(znode->nodekey<ynode->nodekey){
    ynode->leftch=znode;
  }
  
  else{
    ynode->rightch=znode;
  }
    
}

void Pre(Search road){

  if(road==Gard){
    return;
  }
  
  printf(" %d",road->nodekey);
 
  Pre(road->leftch);
  Pre(road->rightch);
  
}

void In(Search road){

  if(road==Gard){
    return;
  }
  
  In(road->leftch);
  
  printf(" %d",road->nodekey);
  
  In(road->rightch);
}



Measured memory_bytes: 25168
#include<iostream>
#include<vector>
#include<algorithm>
#include<cmath>
#include<string>
using namespace std;
int main() {
	double n,count=0;
	cin >> n;
	for (int i = 1; i <= n; i++) {
		if (i % 2 != 0) {
			count++;
		}
	}
	printf("%.9f",count/n);

}

Measured memory_bytes: 256
use std::io::*;
use std::str::FromStr;

pub fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let n: usize = read();
    let mut a: Vec<i64> = vec![];
    let mut b: Vec<i64> = vec![];
    let mut c: Vec<i64> = vec![];

    for _ in 0..n {
        let ai = read();
        a.push(ai);
    }
    for _ in 0..n {
        let ai = read();
        b.push(ai);
    }
    for _ in 0..n {
        let ai = read();
        c.push(ai);
    }

    a.sort();
    b.sort();
    c.sort();
    let mut memo_b: Vec<usize> = vec![0; b.len()];
    let mut ans = 0;
    let mut current = 0;
    for i in 0..b.len() {
        let bi = b[i];
        let result = binarySearch(&a, bi);
        current += result;
        memo_b[i] = current;
    }

    for i in 0..c.len() {
        let ci = c[i];
        let result = binarySearch(&b, ci);
        if result != 0 {
            ans += memo_b[result - 1];
        }
    }
    println!("{}", ans);
}

fn binarySearch(v: &Vec<i64>, t: i64) -> usize {
    let mut low = 0;
    let mut high = v.len();

    while low != high {
        let mid = (low + high) / 2;
        if v[mid] < t {
            low = mid + 1;
        } else {
            high = mid;
        }
    }
    return low;
}


Measured memory_bytes: 10492
#include <bits/stdc++.h>
using namespace std;
bool query(string s, string t){
	cout << s << endl;
	cout << t << endl;
	string r; cin >> r;
	if(r == "end") exit(0);
	return r[0] == 'T';
}
int main(){
	int n; cin >> n;
	string s1, s2;
	while(true){
		char a = 0, b = 0;
		for(char va : {'.', '#'}){
			for(char vb : {'.', '#'}){
				if(query(s1 + va, s2 + vb)){
					a = va;
					b = vb;
					break;
				}
			}
			if(a) break;
		}
		if(a){
			s1 += a;
			s2 += b;
		} else {
			break;
		}
	}
	while(true){
		char a = 0, b = 0;
		for(char va : {'.', '#'}){
			for(char vb : {'.', '#'}){
				if(query(va + s1, vb + s2)){
					a = va;
					b = vb;
					break;
				}
			}
			if(a) break;
		}
		if(a){
			s1 = a + s1;
			s2 = b + s2;
		} else {
			break;
		}
	}
	return 0;
}


Measured memory_bytes: 724
#include<iostream>
#include<string>
#include<cstring>
#include<cstdio>
using namespace std;
int a,b,c,d;
int main(){
	cin>>a>>b>>c;
	d=a*b*c;
	if(d==175)cout<<"YES";
	else cout<<"NO";
	return 0;
}


Measured memory_bytes: 256
public class Main {
  public static void main(String[] args) {
    try (java.util.Scanner sc = new java.util.Scanner(System.in)) {
      StringBuilder sb = new StringBuilder();
      char[] a = sc.next().toCharArray();
      int i = 0;
      java.util.Deque<Character> stack = new java.util.ArrayDeque<>();
      while (i != a.length) {
        stack.push(a[i]);
        while (++i != a.length && a[i] == 'T' && !stack.isEmpty() && stack.peek() == 'S') {
          stack.pop();
        }
      }
      System.out.println(stack.size());
    } // end try
  } // end main()
} // end Solution


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

using namespace std;

int N, C;
int s[101010], t[101010], c[101010];
int sm[202020];
int tt[202020];

int main() {
  cin >> N >> C;
  for (int i = 0; i < N; i++) cin >> s[i] >> t[i] >> c[i];

  for (int i = 1; i <= C; i++) {
    for (int j = 0; j < 202020; j++) tt[j] = 0;

    for (int j = 0; j < N; j++) {
      if (c[j] == i) {
        tt[s[j] * 2 - 1]++;
        tt[t[j] * 2]--;
      }
    }

    for (int j = 1; j < 202020; j++) tt[j] += tt[j - 1];

    for (int j = 0; j < 202020; j++) {
      if (tt[j] > 0) {
        sm[j]++;
      }
    }
  }

  int ans = 0;
  for (int j = 0; j < 202020; j++) {
    ans = max(ans, sm[j]);
  }

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 2944
from queue import Queue
import sys

def check(fl, y, x):
  mark = fl[y][x]
  if mark == '.': return True
  else: return False

def run():
  q = Queue()
  H, W = map(int, input().split())
  fl_list = [['#']*(W+2)]
  num_white = 0
  for h in range(H):
    fl = list('#'+input()+'#')
    num_white += fl.count('.')
    fl_list.append(fl)
  fl_list.append(['#']*(W+2))
  q.put([1,1,0])
  n_list = [0, 0, 1, -1]
  i_list = [1, -1, 0, 0]
  while True:
    if q.empty(): print(-1); sys.exit()
    y, x, t = q.get()
    if (y == H) and (x == W): break
    for n, i in zip(n_list, i_list):
      if check(fl_list, y+n, x+i):
        fl_list[y+n][x+i] = '#'
        q.put([y+n, x+i, t+1])
      
  print(num_white - (t+1))

run()

Measured memory_bytes: 3952
#include <stdio.h>
#include <string.h>

main()
{
    char ibuf[1<<21];
    char *ptr=ibuf;
    fread(ibuf,1,1<<21,stdin);

    int h=0;
    while(*ptr>='0')
    {
        h=h*10+*ptr-'0';
        ++ptr;
    }
    ++ptr;
    int w=0;
    while(*ptr>='0')
    {
        w=w*10+*ptr-'0';
        ++ptr;
    }
    ++ptr;
    int k=0;
    while(*ptr>='0')
    {
        k=k*10+*ptr-'0';
        ++ptr;
    }
    ++ptr;
    int sx=0;
    while(*ptr>='0')
    {
        sx=sx*10+*ptr-'0';
        ++ptr;
    }
    ++ptr;
    int sy=0;
    while(*ptr>='0')
    {
        sy=sy*10+*ptr-'0';
        ++ptr;
    }
    ++ptr;
    int tx=0;
    while(*ptr>='0')
    {
        tx=tx*10+*ptr-'0';
        ++ptr;
    }
    ++ptr;
    int ty=0;
    while(*ptr>='0')
    {
        ty=ty*10+*ptr-'0';
        ++ptr;
    }
    ++ptr;
    sx--,sy--,tx--,ty--;

    struct po {int x,y;};
    struct po qu[1<<20];
    struct po *beg=qu,*end=qu+1;
    beg->x=sx,beg->y=sy;
    unsigned int dist[1<<20];
    memset(dist,-1,sizeof(dist));
    dist[sx*w+sy]=0;
    while(beg!=end)
    {
        int x=beg->x,y=beg->y;
        unsigned int d=dist[x*w+y];
        ++beg;
        char *pt=ptr+x*(w+1)+y;
        char *const pcp=pt;
        for(int i=1,a=x,b=y,z=a*w+y; i<=k; i++)
        {
            a++,z+=w;
            pt+=w+1;
            if(a==h||*pt=='@'||dist[z]<=d) break;
            if(a==tx && b==ty)
            {
                printf("%u\n",d+1);
                return 0;
            }
            if(dist[z]!=d+1)
            {
                end->x=a,end->y=b;
                dist[z]=d+1;
                ++end;
            }
        }
        pt=pcp;
        for(int i=1,a=x,b=y,z=a*w+y; i<=k; i++)
        {
            b++,z++;
            pt++;
            if(b==w||*pt=='@'||dist[z]<=d) break;
            if(a==tx && b==ty)
            {
                printf("%u\n",d+1);
                return 0;
            }
            if(dist[z]!=d+1)
            {
                end->x=a,end->y=b;
                dist[z]=d+1;
                ++end;
            }
        }
        pt=pcp;
        for(int i=1,a=x,b=y,z=a*w+y; i<=k; i++)
        {
            a--,z-=w;
            pt-=w+1;
            if(a<0||*pt=='@'||dist[z]<=d) break;
            if(a==tx && b==ty)
            {
                printf("%u\n",d+1);
                return 0;
            }
            if(dist[z]!=d+1)
            {
                end->x=a,end->y=b;
                dist[z]=d+1;
                ++end;
            }
        }
        pt=pcp;
        for(int i=1,a=x,b=y,z=a*w+y; i<=k; i++)
        {
            b--,z--;
            pt--;
            if(b<0||*pt=='@'||dist[z]<=d) break;
            if(a==tx && b==ty)
            {
                printf("%u\n",d+1);
                return 0;
            }
            if(dist[z]!=d+1)
            {
                end->x=a,end->y=b;
                dist[z]=d+1;
                ++end;
            }
        }
    }
    puts("-1");
}


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

int main(){
  int N;
  cin>>N;
  vector<string> vec(N);
  vector<char> str(10);
  for(int i=0;i<N;i++){
    cin>>vec.at(i);
    for(int j=0;j<10;j++)
      str.at(j)=(vec.at(i)).at(j);
    sort(str.begin(),str.end());
    vec.at(i)=str.at(0);
    for(int j=1;j<10;j++)
      vec.at(i)+=str.at(j);
  }
  sort(vec.begin(),vec.end());
  long count=0,ans=0;
  for(int i=1;i<N;i++){
  	if(vec.at(i)==vec.at(i-1)){
      count++;
      if(i==N-1)
        ans+=count*(count+1)/2;
    }
    else{
      ans+=count*(count+1)/2;
      count=0;
    }
  }
  
  cout<<ans<<endl;
}

Measured memory_bytes: 7296
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <stdio.h>
#include <map>
#include <set>
#include <utility>
#include <queue>
#include <bitset>
#include <math.h>
#include <numeric>

using namespace std;
 
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define endl '\n'
typedef long long ll;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int h,w;
    cin>>h>>w;   
    vector<string> f(h);
    rep(i,h)cin>>f[i];
    int dx[4]={1,-1,0,0};
    int dy[4]={0,0,-1,1};
    //多点をスタートとして扱う
    vector<vector<int> > dist(h, vector<int>(w,-1));
    queue<pair<int,int> > q;
    rep(i,h){
        rep(j,w){
            if(f[i][j]=='#'){
                dist[i][j]=0;
                q.emplace(i,j);
            }
        }
    }
    //BFS
    while(!q.empty()){
        auto cur = q.front();
        q.pop();
        rep(dir,4){
            int nx=cur.first+dx[dir];
            int ny=cur.second+dy[dir];
            if(nx<0||nx>=h||ny<0||ny>=w)continue;
            if(dist[nx][ny]==-1){//#じゃなかったら
                dist[nx][ny]=dist[cur.first][cur.second]+1;
                q.emplace(nx,ny);
            }
        }
    }
    int res=0;
    rep(i,h)rep(j,w)res=max(res,dist[i][j]);
    cout<<res<<endl;
}

Measured memory_bytes: 13456
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
   
/**
 * @author penguin_410
 *         Date: 2014/03/06
 */
public class Main {
    public static void main(String... args) throws IOException {
        final BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        final StringBuilder sb = new StringBuilder();
        while (true) {
            final String line = br.readLine();
            final int index = line.indexOf(" ");
            final int x = Integer.parseInt(line.substring(0, index));
            final int y = Integer.parseInt(line.substring(index+1, line.length()));
            if (x == 0 && y == 0) break;
            sb.append(x < y ? x + " " + y : y + " " + x).append("\n");
        }
        System.out.print(sb);
    }
}

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

int main() {
  int64_t b;

  while (cin >> b, b) {
    for (int64_t d = sqrt(2 * b + b); d > 0; --d) {
      int64_t a = (2 * b + d - d * d) / (2 * d);
      if (a <= 0 || b < a) continue;
      if ((a + d) * (a + d - 1) - a * (a - 1) == 2 * b) {
        cout << a << " " << d << endl;
        break;
      }
    }
  }
}



Measured memory_bytes: 3004
import java.util.*;

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

        int N = sc.nextInt();
        int [][] grid = new int [2][N];
        
        for (int i=0; i<2; i++) {
            for (int j=0; j<N; j++) {
                grid[i][j] = sc.nextInt();
            }
        }

        int ans = 0;
        
        for (int i=0; i<N; i++) {
            int sum = 0;
            for (int j=0; j<=i; j++) {
                sum += grid[0][j];
            }
            for (int j=i; j<N; j++) {
                sum += grid[1][j];
            }
            ans = Math.max(ans, sum);
        }
        System.out.println(ans);
        
    }
}

Measured memory_bytes: 23636
/* cerberus97 - Hanit Banga */

#include <iostream>
#include <iomanip>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>

using namespace std;

#define pb push_back
#define fast_cin() ios_base::sync_with_stdio(false); cin.tie(NULL)

typedef long long ll;
typedef long double ld;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;

const int N = 1e5 + 10;

int main() {
	fast_cin();
	string s; cin >> s;
	reverse(s.begin(), s.end());
	ll ans = 0, ctr = 0;
	for (auto &i : s) {
		if (i == 'B') {
			ans += ctr;
		} else {
			++ctr;
		}
	}
	cout << ans << endl;
}

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

#define int long long
int read(){
	int a = 0; char c = getchar();
	while(!isdigit(c)) c = getchar();
	while(isdigit(c)){a = a * 10 + c - 48; c = getchar();}
	return a;
}
const int _ = 2e5 + 7;
int arr[_] , id[_] , N; bool vis[_];

signed main(){
	N = read(); for(int i = 1 ; i <= N ; ++i){arr[i] = read(); arr[N + i] = read();}
	int sum = 0 , ans = 1e18;
	for(int i = 1 ; i <= N ; ++i) sum += arr[i];
	ans = min(ans , sum); sum = 0;
	for(int i = 1 ; i <= N ; ++i) sum += arr[N + i];
	ans = min(ans , sum);  sum = 0;
	for(int i = 1 ; i <= 2 * N ; ++i) id[i] = i;
	sort(id + 1 , id + 2 * N + 1 , [&](int x , int y){return arr[x] < arr[y];});
	for(int i = 1 ; i <= N ; ++i){sum += arr[id[i]]; vis[id[i]] = 1;}
	for(int i = 1 ; i <= N ; ++i)
		if(vis[i] && vis[i + N]) ans = min(ans , sum);
		else ans = min(ans , sum + arr[vis[i] ? i + N : i] - arr[id[id[N] == i || id[N] == i + N ? N - 1 : N]]);
	cout << ans; return 0;
}

Measured memory_bytes: 3584
#include <iostream>
#include <string>
#include <cmath>
#include <vector>
#include <algorithm>
#include <map>

using namespace std;

int main()
{
    string s;
    int ans = 0;
    int ans2 = 0;

    cin >> s;

    for (int i = 0; i < s.size(); i++) {
        if (i % 2) {
            if (s[i] != '0') {
                ans++;
            }
        }
        else {
            if (s[i] != '1') {
                ans++;
            }
        }
    }

    for (int i = 0; i < s.size(); i++) {
        if (i % 2) {
            if (s[i] != '1') {
                ans2++;
            }
        }
        else {
            if (s[i] != '0') {
                ans2++;
            }
        }
    }

    cout << min(ans, ans2++) << endl;
}


Measured memory_bytes: 512