akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <numeric>

#define REP(i, a, b) for (int i = int(a); i < int(b); i++)
using namespace std;
typedef long long int ll;

// clang-format off
#ifdef _DEBUG_
#define dump(...) do{ cerr << __LINE__ << ":\t" << #__VA_ARGS__ << " = "; PPPPP(__VA_ARGS__); cerr << endl; } while(false)
template<typename T> void PPPPP(T t) { cerr << t; }
template<typename T, typename... S> void PPPPP(T t, S... s) { cerr << t << ", "; PPPPP(s...); }
#else
#define dump(...)
#endif
template<typename T> vector<T> make_v(size_t a, T b) { return vector<T>(a, b); }
template<typename... Ts> auto make_v(size_t a, Ts... ts) { return vector<decltype(make_v(ts...))>(a, make_v(ts...)); }
template<typename T>
bool chmin(T &a, T b) { if (a > b) {a = b; return true; } return false;}
template<typename T>
bool chmax(T &a, T b) { if (a < b) {a = b; return true; } return false;}
// clang-format on

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    string s;
    cin >> s;
    cout << string(s.size(), 'x') << endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
int main(){
	int n,m=100000;
	std::cin>>n;
	for(int i=0;i<n;i++){
		m+=m/100*5;
		if(m%1000!=0)m+=1000-m%1000;
	}
	std::cout<<m<<std::endl;
	return 0;
}

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

inline ll nc2(ll n) { return (n * (n - 1)) / 2; }

void solve(long long N, std::vector<long long> A) {
  unordered_map<int, int> m;
  for (auto a : A) {
    m[a]++;
  }
  ll res = 0;
  for (auto e : m) {
    res += nc2(e.second);
  }
  for (int i = 0; i < A.size(); i++) {
    ll tRes = res;
    tRes -= nc2(m[A[i]]);
    tRes += nc2(m[A[i]] - 1);
    cout << tRes << endl;
  }
}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You
// use the default template now. You can remove this line by using your custom
// template)
int main() {
  long long N;
  scanf("%lld", &N);
  std::vector<long long> A(N);
  for (int i = 0; i < N; i++) {
    scanf("%lld", &A[i]);
  }
  solve(N, std::move(A));
  return 0;
}


Measured memory_bytes: 9160
// Why am I so dumb? :c
#include<bits/stdc++.h>

#define pb push_back
#define mp make_pair

#define all(x) (x).begin(), (x).end()

#define fi first
#define se second

using namespace std;

typedef long long ll;

const int MAXN = (int)1e5 + 5;

bool arr[MAXN];

int cnt[MAXN];

int n, q;

void solve() {
    scanf("%d %d", &n, &q);

    for (int i = 1; i <= n; ++i) {
        cnt[i] = 1;
    }

    arr[1] = 1;

    for (int i = 1, a, b; i <= q; ++i) {
        scanf("%d %d", &a, &b);
        arr[b] |= arr[a];
        ++cnt[b];
        --cnt[a];

        if (cnt[a] == 0) {
            arr[a] = 0;
        }
    }

    printf("%d\n", accumulate(arr + 1, arr + n + 1, 0));
}

int main() {
    int tt = 1;

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

    return 0;
}

Measured memory_bytes: 768
n= int(input())
d= list(map(int, input().split()))
y=(d[0]!=0)
d.sort()
x=[0]*(d[n-1]+1)
k=0
ans=False
for i in range(n):
    if d[i]==k:
        x[k]+=1
    elif d[i]==k+1:
        k+=1
        x[k]+=1
    else:
        ans=True
    #print(ans)
#print(d)
#print(x)
if ans or x[0]>=2 or y:
    print(0)
else:
    a=1
    for i in range(d[n-1]):
        a*=(x[i]**x[i+1])
    print(a%998244353)


Measured memory_bytes: 54196
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ll long long
ll gcd(ll x, ll y) { return (x % y)? gcd(y, x % y): y; }    //最大公約数
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }     //最小公倍数
using Graph = vector<vector<ll>>;
ll inf=300000000000000000;
const double PI = 3.14159265358979323846;
const int MAX = 510000;
const ll MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
long long modpow(long long a, long long n, long long mod) {
    long long res = 1;//a^n%mod
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
long long modinv(long long a, long long m) {
    long long b = m, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m; 
    if (u < 0) u += m;
    return u;
}

int main(){
  COMinit();
  int n;
  cin >> n;
  vector<int> k(n+1,0);
  int a[n+1];
  rep(i,n+1){
    int b;
    cin >> b;
    k[b]++;
    a[i]=b;
  }
  int x=-1,y=-1;
  rep(i,1+n){
    if(k[i]==2){
      rep(j,n+1){
        if(a[j]==i){
          if(x==-1)x=j;
          else y=j;
        }
      }
    }
  }
  int u=y-x+1;
  rep(i,n+1){
    cout << (MOD+COM(n+1,i+1)-COM(n+1-u,i))%MOD << endl;
  }
}


Measured memory_bytes: 13952
#include "bits/stdc++.h"
using namespace std;

#define REP(i, n) for(ll i = 0;i < n;i++)
#define REP1(i, n) for(ll i = 1;i < n;i++)
#define REPR(i, n) for(ll i = n-1;i >= 0;i--)
#define FOR(i, m, n) for(ll i = m;i < n;i++)

#define VSORT(v) sort(v.begin(), v.end())
#define VRSORT(v) sort(v.rbegin(), v.rend())

#define ll long long
#define ALL(a)  (a).begin(),(a).end()

#define pb(a) push_back(a)
#define MOD 1000000007

int now,n,k;


int main(){
  int ans=0;
  cin >> n >> k;
  if (k==1){
    cout<<0<<endl;
    return 0;
  }else{ 
    cout<<(n-k)<<endl;
    return 0;
  }
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i,n) for(ll i = 0; i<(ll)(n); i++)
#define REPS(i,n) for (ll i = 1; i<=(ll)(n); i++)
#define REPD(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=(a);i<=(b);i++)
#define FORD(i,a,b) for(ll i=(a);i>=(b);i--)
#define pb push_back
#define MOD 1000000007
#define MOD2 998244353
#define PI 3.141592653
#define INF 100000000000000

int main(){
    ll n; cin >> n;
    ll ans = 1000000000000000000;
    vector<ll> a(n);
    vector<ll> asum(n);
    vector<ll> ansl;
    REP(i,n){
        cin >> a[i];
        if (i) asum[i]=asum[i-1]+a[i];
        else asum[i]=a[i];
    }
    FOR(i,1,n-3){
        ll ind1 = lower_bound(asum.begin(),asum.end(),asum[i]/2)-asum.begin();
        ll ind2 = lower_bound(asum.begin(),asum.end(),(asum[n-1]-asum[i])/2+asum[i])-asum.begin();
        //cout << i << " " << ind1 << " " << ind2 << endl;
        FOR(j,ind1-1,ind1+1)FOR(k,ind2-1,ind2+1){
            if (j!=-1&&k!=n){
                ll minc = min(asum[j],asum[i]-asum[j]);
                minc = min(minc,asum[k]-asum[i]);
                minc = min(minc,asum[n-1]-asum[k]);
                ll maxc = max(asum[j],asum[i]-asum[j]);
                maxc = max(maxc,asum[k]-asum[i]);
                maxc = max(maxc,asum[n-1]-asum[k]);
                ans = min(ans,maxc-minc);
                //cout << j << " " << i << " " << k << " " << maxc << " " << minc << endl;
            }
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 3328
import sys

N, K = map(int, sys.stdin.readline().split(" "))
a = list(map(int, sys.stdin.readline().split(" ")))

ans = float("inf")
for i in range(2**N):
    pattern = []
    for j in range(N):
        pattern.append(i >> j & 1)
    if sum(pattern) < K:
        continue
    # print(pattern)

    max_h = 0
    tmp_ans = 0
    for n in range(N):
        if pattern[n] == 1:
            if a[n] <= max_h:
                tmp_ans += max_h - a[n] + 1
                max_h += 1
        max_h = max(max_h, a[n])
    ans = min(ans, tmp_ans)
    
print(ans)

Measured memory_bytes: 43484
#[allow(unused_macros)]
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)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

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

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

#[allow(unused_macros)]
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")
    };
}

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        #[cfg(debug_assertions)]
        writeln!(&mut std::io::stderr(), concat!("[DEBUG] ", $(stringify!($a), "={:?} "),*), $($a),*);
    }
}

#[allow(unused_imports)]
use std::cmp::{min, max};
#[allow(unused_imports)]
use std::io::{stdout, stdin, BufWriter, Write};

fn main() {
    let out = std::io::stdout();
    let mut out = BufWriter::new(out.lock());
    macro_rules! puts {
        ($($format:tt)*) => (write!(out,$($format)*).unwrap());
    }

    input!{
      n: usize,
      k: usize,
      mut aa: [usize; n],
      mut ff: [usize; n],
    }

    aa.sort();
    ff.sort();
    ff.reverse();

    let is_ok = |x| -> bool {
        let mut req = 0;
        for i in 0..n {
            if aa[i] * ff[i] > x {
                let d = aa[i] * ff[i] - x;
                req += (d + ff[i] - 1) / ff[i];
            }
        }
        req <= k
    };

    let mut ok = 1i64 << 50;
    let mut ng = -1;
    while (ok-ng).abs() > 1 {
        let mid = (ok + ng) / 2;
        if is_ok(mid as usize) {
            ok = mid;
        } else {
            ng = mid;
        }
    }
    puts!("{}\n", ok);
}


Measured memory_bytes: 10492
fun main() {
    val n = readLine()!!.toInt()
    var answer = 0L
    for (i in (1..n)) {
        answer += g(i, n)
    }

    println(answer)
}

fun g(x: Int, n: Int): Long {
    val y = (n / x).toLong()
    return  x * y * (y + 1) / 2
}


Measured memory_bytes: 34448
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(ll i=0;i<(n);i++)
#define rrep(i,n) for(ll i = 1; i <= (n); ++i)
#define drep(i,n) for(ll i = (n)-1; i >= 0; --i)
#define all(v) v.begin(),v.end()
#define len(x) (ll)(x).length()
#define maxs(x,y) x = max(x,y)
#define mins(x,y) x = min(x,y)
#define pb push_back
#define sz(x) (ll)(x).size()
#define v(T) vector<T>
#define vv(T) vector<vector<T>>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
ll gcd(ll a,ll b){if(a%b==0){return b;}else{return(gcd(b,a%b));}}
ll lcm(ll a,ll b){return a*b/gcd(a,b);}
const int INF=1e9;
const ll MX = 1e18;
const int MOD=INF+7;
const int di[] = {-1,0,1,0};
const int dj[] = {0,-1,0,1};
const double PI=acos(-1);
 
int a[12][12];
 
int main() {
  int n, m, x;
  cin >> n >> m >> x;
  vector<int> c(n);
  rep(i,n) {
    cin >> c[i];
    rep(j,m) cin >> a[i][j];
  }
 
  int ans = INF;
  rep(s,1<<n) {
    int cost = 0;
    vector<int> d(m);
    rep(i,n) {
      if (s>>i&1) {
        cost += c[i];
        rep(j,m) d[j] += a[i][j];
      }
    }
    bool ok = true;
    rep(j,m) if (d[j] < x) ok = false;
    if (ok) ans = min(ans, cost);
  }
  if (ans == INF) cout << -1 << endl;
  else cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3600
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
using namespace std;
#define REP(i,m,n) for(int i=(int)m ; i < (int) n ; ++i )
#define rep(i,n) REP(i,0,n)
typedef long long ll;
typedef pair<int,int> pint;
typedef pair<ll,int> pli;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;

int main(){
    int s=101010;
    bool isprime[101010];
    rep(i,s)isprime[i]=true;
    isprime[0]=isprime[1]=false;
    vector<ll>prime;
    rep(i,s){
        if(!isprime[i])continue;
        prime.push_back(i);
        for(int j=2*i;j<s;j+=i){
            isprime[j]=false;
        }
    }
    s=prime.size();
    map <ll,int> rt;
    rep(i,s)rt[prime[i]*prime[i]]=prime[i];
    int n;
    cin>>n;
    vector<ll> a(n,1),inv(n,1);
    rep(i,n){
        ll x;
        cin>>x;
        rep(j,s){
            int c=0;
            if(x<prime[j]*prime[j]*prime[j])break;
            if(x%prime[j])continue;
            while(x%prime[j]==0){
                c++;
                x/=prime[j];
            }
            c%=3;
            if(c==1){
                a[i]*=prime[j];
                inv[i]*=prime[j]*prime[j];
            }
            if(c==2){
                inv[i]*=prime[j];
                a[i]*=prime[j]*prime[j];
            }
        }
       if(rt[x])a[i]*=x,inv[i]*=rt[x];
        else a[i]*=x,inv[i]*=x*x;
    }
    map<ll,int> mp;
    rep(i,n)mp[a[i]]++;
    int ans=0;
    rep(i,n){
        if(a[i]==1)continue;
        if(mp[a[i]]==mp[inv[i]])ans+=(a[i]>inv[i]);
        else if(mp[a[i]]>mp[inv[i]])ans++;
    }
    ans+=!!mp[1];
    cout<<ans<<endl;
}


Measured memory_bytes: 21120
def calendar():
    m, d = map(int, input().split())
    res = []
 
    for month in range(1, m + 1):
        for day in range(2, 10):
            for x in range(2, 10):
                if x * day == month:
                    temp = str(day) + str(x)
                    temp = int(temp)
                    if temp <= d:
                        res.append(temp)
    return len(res)
 
 
print(calendar())

Measured memory_bytes: 3060
#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> h(n);
    for (int i; i < n; i++) cin >> h[i];

    int ans = 0;
    int active = 0;
    for (int i = 0; i < n; i++)
    {
        //区間は足りていますか
        if (active >= h[i]) {
            active = h[i];
        } else {
            ans += h[i] - active;
            active = h[i];
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3528
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rep1(i, n) for(int i = 1; i <= (int)(n); i++)
#define show(x) {for(auto i: x){cout << i << " ";} cout<<endl;}
#define showm(m) {for(auto i: m){cout << m.x << " ";} cout<<endl;}
typedef long long ll;
typedef pair<int, int> P;
ll gcd(int x, int y){ return y?gcd(y, x%y):x;}
ll lcm(ll x, ll y){ return (x*y)/gcd(x,y);}


int main()
{
    int n, k;
    cin >> n >> k;
    vector<int> a;
    rep(i, n){ int tmp; cin >> tmp; a.push_back(tmp);}

    int a_max = *max_element(a.begin(),a.end());

    ll a_gcd = a[0];
    for (int i = 1; i < n; i++)
    {
        a_gcd = gcd(a[i], a_gcd);
    }
    if (k <= a_max && k%a_gcd == 0){
        cout << "POSSIBLE" << endl;
    } else {
        cout << "IMPOSSIBLE" << endl;
    }

}



Measured memory_bytes: 892
use std::str::FromStr;
use std::fmt::Debug;
use std::cmp;
#[allow(dead_code)]
fn read_as_vec<T>() -> Vec<T>
where T: FromStr, <T as FromStr>::Err : Debug{
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim().split_whitespace().map(|c| T::from_str(c).unwrap()).collect()

}

#[allow(dead_code)]
fn read_as_string() -> String{
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim().to_string()
}

fn main(){
    let n = read_as_vec::<usize>()[0];
    let a = read_as_vec::<u64>();

    let odd = a.iter().filter(|x| **x%2 == 1).count();
    let even = n - odd;

    println!("{}", 3u64.pow(n as u32) - 2u64.pow(even as u32));
}


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

using namespace std;

int main() {
    string s;
    cin >> s;

    int length = s.length();
    long long result = 0;

    for (int i = 0; i < (1 << (length - 1)); ++i) {
        int start = 0;
        for (int j = 0; j < (length - 1); ++j) {
            if (i >> j & 1)  {
                result += stoll(s.substr(start, j - start + 1));
                start = j + 1;
            }
        }
        result += stoll(s.substr(start, length - start));
    }

    cout << result << endl;
    return 0;
}

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

int main(){
  int n,i,sum;
  cin>>n;
  int v[n],c[n];
  for (i=0;i<n;i++)cin>>v[i];
  for (i=0;i<n;i++)cin>>c[i];
  for (i=0;i<n;i++){
    v[i]-=c[i];
    sum+=max(0,v[i]);
  }
  cout<<sum<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ALL(obj) (obj).begin(),(obj).end()
#define SORTD(s) sort((s).rbegin(),(s).rend())
#define rep(i,n) for(int i=0;i<(n);i++)
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; }
typedef long long ll;
#define PI 3.14159265358979323846264338327950L
const int mod=1000000007,MAX=200005,INF=1<<30;

int main() {
	int n;
  	cin>>n;
  
  	int d[110][110];
  
  	for(int i=0;i<n;i++){
    	for(int j=1;j<=2;j++){
        	cin>>d[i][j];
        }
    }
  
  bool ans=false;
  int ch=0;
  	
  	for(int i=0;i<n;i++){

        	if(d[i][1]==d[i][2]){
            	ch++;
            }
          	else{
            	ch=0;
            }

      if(ch>=3){
      	ans=true;
      }
    }
 
  
  if(ans){
  	cout<<"Yes"<<endl;
  }
  
  else{
  	cout<<"No"<<endl;
  }
}

Measured memory_bytes: 3632
using namespace std;
#include<bits/stdc++.h>
#define BEGIN ios_base::sync_with_stdio(0);cin.tie(0);
#define END return EXIT_SUCCESS;
#define FOR(I,A,B) for((I)=(A);(I)<(B);(I)++)
#define REP(I,N) FOR((I),0,(N))
#define UP(I,A,B) for((I)=(A);(I)<=(B);(I)++)
#define DW(I,A,B) for((I)=(A);(I)>=(B);(I)--)
#define IN(P) cin>>(P)
#define IN2(P1,P2) cin>>(P1)>>(P2)
#define IN3(P1,P2,P3) cin>>(P1)>>(P2)>>(P3)
#define INS(I,N,V) REP((I),(N)) cin>>(V[I])
#define INS2(I,N,V1,V2) REP((I),(N)) cin>>(V1[I])>>(V2[I]);
#define INS3(I,N,V1,V2,V3) REP((I),(N)) cin>>(V1[I])>>(V2[I])>>(V3[I]);
#define OUT(P) cout<<(P)<<endl
#define OUT2(P1,P2) cout<<(P1)<<" "<<(P2)<<endl
#define OUT3(P1,P2,P3) cout<<(P1)<<" "<<(P2)<<" "<<(P3)<<endl
#define OUTS(I,N,V) REP((I),(N)) cout<<(V[i])<<endl
#define ALL(C) (C).begin(),(C).end()
#define RALL(C) (C).rbegin(),(C).rend()
#define mp make_pair
#define pb push_back
#define lb lower_bound
#define ub upper_bound
template<class T>inline bool chmax(T& a,T b){if(a<b){a=b;return true;}return false;}
template<class T>inline bool chmin(T& a,T b){if(a>b){a=b;return true;}return false;}

string S;
inline void solve(){
  IN(S);
  sort(ALL(S));
  OUT(S=="abc"?"Yes":"No");
}

int main(int argc,char**argv){
  BEGIN
  solve();
  END
}


Measured memory_bytes: 256
#include <math.h>
#include <time.h>
#include <ctype.h>
#include <stdio.h>
#include <assert.h>
#include <stdlib.h>
#include <string.h>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <string>
#include <vector>
#include <iostream>
#include <algorithm>
#include<iomanip>

#define mod 1000000007
#define ll long long int
#define pb(x) push_back(x)
#define MP(x,y) make_pair(x,y)

using namespace std;

ll power(ll a, ll b, ll m)
{
	if (b == 0)
		return(1);
	ll sol = power(a, b / 2, m);
	sol = (sol * sol) % m;
	if (b % 2 == 1)
		sol = (sol * a) % m;
	return(sol);
}
ll gcd(ll a, ll b)
{
	if (b == 0)
		return a;
	else
	{
		return gcd(b, a % b);
	}
}
int mat[11][11];
int hashe[1000001];
void solve()
{
	int n,d;
	cin >> n>>d;
	for (int i = 0; i < n; i++)
	{
		for (int j = 0;j < d; j++)
		{
			cin >> mat[i][j];
		}
	}
	for (int i = 0; i <= 1000; i++)
	{
		hashe[i * i]=1;
	}
	int ans=0,sol=0;
	for (int i = 0; i < n; i++)
	{
		for (int k = i + 1; k < n; k++)
		{
			sol = 0;
			for (int j = 0; j < d; j++)
			{
				sol = sol + (mat[i][j] - mat[k][j])*(mat[i][j] - mat[k][j]);
			}
			if (hashe[sol] == 1)
			{
				ans++;
			}
		}
		
	}
	cout << ans;
}
int main()
{
	int t = 1;
	//cin>>t;
	while (t--)
	{
		solve();
	}
	return 0;
}

Measured memory_bytes: 3200
#include <bits/stdc++.h>
using namespace std;
/// 最大値を更新
template<class T> inline bool chkMax(T& a, T b){
  if(a < b){
    a = b;
    return true;
  }
  return false;
}

int main() {
  string str;
  long long kekka = 0;
  
  cin >> str;
  
  vector<int> vec(str.size()+1,0);
  
  for(int i = 0; i < str.size(); i++){
    if(str.at(i) == '<') vec.at(i+1) = vec.at(i) + 1;
  }

  for(int i = str.size()-1; i >= 0; i--){
    if(str.at(i) == '>') chkMax(vec.at(i), vec.at(i+1) + 1);
  }
  
  for(int i = 0; i < vec.size(); i++){
    kekka += vec.at(i);
  }
  
  cout << kekka;
}


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

int main(){
    string s; cin >> s;
    if(s[2] == s[3] && s[4] == s[5]) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <time.h>
#include <math.h>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <algorithm>
#include <iterator>
#include <sstream>
#include <string>
#include <bitset>
using namespace std;
#define FOR(I,F,N) for(int I = F; I < (int)(N); I++)
#define rep(i, n) FOR(i, 0, n)
#define FIN(V) cout<<V<<endl
#define pb push_back
#define INF (1 << 30)
typedef pair<int, int> P;
typedef pair<pair<int, int>, int> PP;
typedef long long ll;
typedef priority_queue<int> pq;
int main(void) {
    int D;
    cin >> D;
    cout << "Christmas";
    rep(i, 25-D){
        cout << " Eve";
    }
    cout << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
//INSERT ABOVE HERE
signed main(){
  Int n;
  cin>>n;
  vector<Int> a(n);
  for(Int i=0;i<n;i++) cin>>a[i];
  vector<Int> b(a);
  sort(b.begin(),b.end());
  Int cnt=0;
  for(Int i=0;i<n;i++) cnt+=a[i]==b[i];
  Int q;
  cin>>q;
  for(Int i=0;i<q;i++){
    if(cnt==n){
      cout<<i<<endl;
      return 0;
    }
    Int x,y;
    cin>>x>>y;
    x--;y--;
    cnt-=a[x]==b[x];
    cnt-=a[y]==b[y];
    swap(a[x],a[y]);
    cnt+=a[x]==b[x];
    cnt+=a[y]==b[y];
  }
  cout<<(cnt==n?q:-1)<<endl;
  return 0;
}



Measured memory_bytes: 7620
#include<bits/stdc++.h>
using namespace std;
#define INF 1000000007
int u[1100000];
vector<int> y;
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int a,b,c,d=0,e=0,f=0,g=0;
  cin >>a>>b>>c;
  if(a+b>=c) cout <<"Yes\n";
  else cout <<"No\n";
  return (0);
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner reader = new Scanner(System.in);
		long X = reader.nextLong();
		long Y = reader.nextLong();
		long ans = 0;
		while (X <= Y) {
			X *= 2;
			ans++;
		}

		System.out.println(ans);
		reader.close();
	}
}





Measured memory_bytes: 23636
#include <stdio.h>
#include <iostream>
#include <queue>
#include <string>
#include <algorithm>
#include <cstdio>
#include <stack>
#include <vector>
#include <string.h>
#define m 1000000007
using namespace std;

int a,b,c,n,i,d,o[100010],l[100010],e[100010],dx[10]={0,-1,1,0,0,-1,-1,1,1},dy[10]={0,0,0,-1,1,-1,1,-1,1};
long long x,y,z,k=1;
stack<int> s;
queue<int> qx,qy,qn;
string r1,r2,r3,iop;
vector<pair<int,int> > v[200010];
//char r1[1010],r2[1010],r3[1010];

int main()
{
    scanf("%d",&a);
    for(int t=1;t<=a;t++)
    {
        scanf("%d",&l[t]);
        if(l[t]>l[t-1])
            o[t]=l[t];
    }
    for(int t=1;t<=a;t++)
    {
       // printf("%d ",t);
        scanf("%d",&e[t]);
    }
    for(int t=a;t>=1;t--)
    {
        if(o[t]&&o[t]>e[t])
        {
            printf("0");
            return 0;
        }
        if(!o[t]&&e[t]>e[t+1]&&l[t]<e[t])
        {
            printf("0");
            return 0;
        }
        if(e[t]>e[t+1])
            o[t]=e[t];
    }
    for(int t=1;t<=a;t++)
    if(!o[t])
        k=(k*min(e[t],l[t]))%m;
    printf("%lld",k%m);
    return 0;
}


Measured memory_bytes: 6144
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define REP(i,n) for (int64_t i=0; i<(n); ++i)
#define P pair<int,int>
using ll=int64_t;
using namespace std;
#define ketasuu(n) fixed<<setprecision(n)
#define btoe(p) p.begin(),p.end()
#define etob(p) p.rbegin(),p.rend()




int main(){
    int a,b,c,d; cin>>a>>b>>c>>d;
    if(a+b>c+d){
        cout<<"Left"<<endl;
    }else if(a+b<c+d){
        cout<<"Right"<<endl;
    }else{
        cout<<"Balanced"<<endl;
    }
}

Measured memory_bytes: 3600
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define Int int32_t
#define all(c) c.begin(), c.end()
#define FAST ios_base::sync_with_stdio(false) , cin.tie(NULL);
#define pii pair<int,int>
#define pb push_back
#define F first
#define S second
#define endl "\n"
#define bitcnt(n) __builtin_popcountll(n)
#define setpre(n) cout << fixed << setprecision(n)
#define tr(c) for(const auto& x : c )cout << x << " "; cout << "\n";
#define ol(c, s, e) for(int pos=s; pos<e; pos++)cout << c[pos] << " ";cout <<"\n";
#define PI acos(-1LL)

const int M = 1000000007;
const int N = 2e5 + 5;
const long long INF = 1e9 + 12;

vector<double> v;
vector<vector<double> > dp;
int n;
double fun(int i, int heads){
    if(i == n+1) return heads >= (n+1)/2;
    double &ans = dp[i][heads];
    if(ans!=-1)
        return ans;
    return ans = fun(i+1, heads+1)*v[i] + fun(i+1, heads)*(1.0-v[i]);
}

void solve(){
    cin >> n;
    v.resize(n+1);
    dp.resize(n+1, vector<double>(n+1,-1));
    for(int i=1; i<=n; i++){
        cin >> v[i];
    }
    setpre(12) << fun(1,0);
}

signed main(){
    FAST
    int tc = 1;
//    TODO: check for tc
//    cin >> tc;
    for (int t = 1; t <= tc; t++) {
        solve();
    }
}


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

struct Card{
  char s[3], v;
};

void bubble(struct Card A[], int N){
  int i,j;
  for(i = 0 ; i < N ; i++){
    for(j = N - 1 ; j >= i ; j--){
      if(A[j].v < A[j - 1].v){
        struct Card t = A[j];
        A[j] = A[j - 1];
        A[j - 1] = t;
      }
    }
  }
}

void selection(struct Card A[], int N){
  int i, j;
  for(i = 0 ; i < N ; i++){
    int minj = i;

    for(j = i ; j < N ; j++){
      if(A[j].v < A[minj].v) minj = j;
    }
    struct Card t = A[i];
    A[i] = A[minj];
    A[minj] = t;
  }
}

void print(struct Card A[], int N){
  int i;
  for(i = 0 ; i < N - 1 ; i++){
    if(i >= 0){
      printf("%s ", A[i].s);
    }
  }
  printf("%s", A[N-1].s);
}

int isStable(struct Card c1[], struct Card c2[],int N){
  int i;
  for(i = 0 ; i < N ; i++){
    if(strcmp(c1[i].s, c2[i].s) != 0) return 0;
  }
  return 1;
}

int main(){
  struct Card c1[100], c2[100];
  int N, i;
  char ch;

  scanf("%d", &N);
  for(i = 0 ; i < N ; i++){
    scanf("%s", c1[i].s);
    c1[i].v = c1[i].s[1];
    c2[i] = c1[i];
  }



    bubble(c1, N);
    selection(c2, N);

    print(c1, N);
    printf("\nStable\n");

    print(c2, N);
    if(isStable(c1, c2, N) == 1){
      printf("\nStable\n");
    }
    else{
      printf("\nNot stable\n");
  }

    return 0;
}


Measured memory_bytes: 2144
#include<iostream>
#include<algorithm>
#include<queue>
using namespace std;
int H,W,N;
string s,m[1000];
int dis[4][1000][1000];
int dx[4]={-1,0,1,0},dy[4]={0,-1,0,1};
int nxt[4][1<<20];
main()
{
	while(cin>>H>>W>>N,H)
	{
		cin>>s;
		int sx,sy;
		for(int i=0;i<H;i++)
		{
			cin>>m[i];
			for(int j=0;j<W;j++)for(int r=0;r<4;r++)dis[r][i][j]=2*N;
			for(int j=0;j<W;j++)
			{
				if(m[i][j]=='S')
				{
					sx=i;
					sy=j;
				}
			}
		}
		int nowr=0;
		for(int i=0;i<N;i++)nowr+=s[i]=='L'?1:-1;
		nowr=(nowr%4+4)%4;
		int nowd[4];
		for(int r=0;r<4;r++)nowd[r]=nxt[r][N]=r==nowr?N:2*N;
		for(int i=N;i--;)
		{
			nowr-=s[i]=='L'?1:-1;
			nowr=(nowr%4+4)%4;
			nowd[nowr]=i;
			for(int r=0;r<4;r++)nxt[r][i]=nowd[r];
		}
		dis[0][sx][sy]=0;
		priority_queue<pair<pair<int,int>,pair<int,int> > >P;
		P.push({{0,0},{sx,sy}});
		bool flag=false;
		while(!P.empty())
		{
			int d=-P.top().first.first;
			int nr=P.top().first.second;
			int x=P.top().second.first;
			int y=P.top().second.second;
			P.pop();
			if(dis[nr][x][y]<d)continue;
			if(m[x][y]=='G')
			{
				flag=true;
				break;
			}
			for(int r=0;r<4;r++)
			{
				int tx=x+dx[r],ty=y+dy[r];
				if(tx<0||ty<0||tx>=H||ty>=W||m[tx][ty]=='#'||dis[r][tx][ty]<=nxt[r][d])continue;
				dis[r][tx][ty]=nxt[r][d];
				P.push({{-nxt[r][d],r},{tx,ty}});
			}
		}
		cout<<(flag?"Yes":"No")<<endl;
	}
}



Measured memory_bytes: 21656
#include <iostream>
#include <vector>
#include <algorithm>
#include <ctime>
#include <cmath>
#include <string>
#include <stdlib.h>
#include <fstream>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <deque>
#include <iterator>
#include <iomanip>
using namespace std;


int main(){
    long long x, y;
    cin >> x >> y;
    if(abs(x - y) > 1) cout << "Alice";
    else cout << "Brown";
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int N, K;
    cin >> N >> K;
    vector<int> P(N);
    for (auto & p : P) cin >> p;
    long long sum = 0, mx;
    for (int i = 0; i < K; ++i) {
        sum += P[i]+1;
    }
    mx = sum;
    for (int i = K; i < N; ++i) {
        sum += P[i]+1;
        sum -= P[i-K]+1;
        mx = max(mx, sum);
    }
    printf("%lld", mx/2);
    if (mx % 2 == 1) printf(".5");
    puts("");
    return 0;
}


Measured memory_bytes: 1024
let inf = 10101010101010
let digs x = x |> string_of_int |> String.length
let x = Scanf.scanf "%d" (fun x -> x)
let () =
  Array.init 101010 (fun i ->
    if i > 0 && x mod i = 0 then max (digs i) (digs (x / i))
    else inf)
  |> Array.fold_left min inf
  |> Printf.printf "%d\n"


Measured memory_bytes: 3200
#include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <string>
#include <numeric>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <queue>

#define rep(i,n) for(ll i=0;i<n;i++)
#define dup(x,y) (((x)+(y)-1)/(y)) // dup * y >= x なる最小のdup.
using namespace std;
typedef long long ll;
using Graph = vector<vector<ll>>;
//	std::cout<<std::fixed<<std::setprecision(10);

int main() {
	int N;
	cin >> N;
	vector<ll> B(N-1);
	rep(i, N-1) cin >> B[i];

	ll ans =0 ;
	ans += B[0];
	rep(i, N-2) {
		ans += min(B[i], B[i+1]);
	}
	ans += B[N-2];

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 256
import java.math.BigDecimal

fun main(){
    val N = readLine()!!.toInt()
    val A = readLine()!!.split(" ").map { BigDecimal(it) }

    if(A.contains(BigDecimal.ZERO)){
        println(0)
        return
    }

    var ans = BigDecimal.ONE
    for(i in A.indices){
        ans *= A[i]
        if(ans > BigDecimal(10).pow(18)){
            println(-1)
            return
        }
    }
    println(ans.toPlainString())
}

Measured memory_bytes: 65632
///Nahid Hasan Raju
#include <bits/stdc++.h>
#define ll long long
#define MS(ARRAY,VALUE) memset(ARRAY,VALUE,sizeof(ARRAY))
#define Fin freopen("input.txt","r",stdin)
using namespace std;

#define P1(XX) cerr<<"db1: "<<XX<<endl
#define P2(XX,YY) cerr<<"db2: "<<XX<<" "<<YY<<endl
#define P3(XX,YY,ZZ) cerr<<"db3: "<<XX<<" "<<YY<<" "<<ZZ<<endl
#define FAST ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define Fout freopen("output.txt","w",stdout)
#define rep(i,a,b) for(i=a;i<=b;i++)
#define EPS 0.00000001
#define INF INT_MAX
#define PI 2*acos(0.0)
#define set(XX,POS) XX|=(1<<POS)
#define reset(XX,POS) XX&=(~(1<<POS))
#define check(XX,POS) (bool)(XX&(1<<POS))
#define toggle(XX,POS) (XX^(1<<POS))
#define SORT(v) sort(v.begin(),v.end())
#define REVERSE(V) reverse(v.begin(),v.end())
#define VALID(X,Y,R,C) X>=0 && X<R && Y>=0 && Y<C
#define SIZE(ARRAY) sizeof(ARRAY)/sizeof(ARRAY[0])
#define RT printf("Run Time : %0.3lf seconds\n", clock()/(CLOCKS_PER_SEC*1.0))
#define pb push_back
#define pll pair<ll,ll>
#define pii pair<int,int>

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>
using namespace __gnu_pbds;
typedef tree< pair<int,int> , null_type, less< pair<int,int> >, rb_tree_tag, tree_order_statistics_node_update> odrst;

#define MOD 1000000007ll
#define MX 2000006  ///200005


/*------------------------------Graph Moves----------------------------*/
//const int fx[]={+1,-1,+0,+0};
//const int fy[]={+0,+0,+1,-1};
//const int fx[]={+0,+0,+1,-1,-1,+1,-1,+1};   // Kings Move
//const int fy[]={-1,+1,+0,+0,+1,+1,-1,-1};  // Kings Move
//const int fx[]={-2, -2, -1, -1,  1,  1,  2,  2};  // Knights Move
//const int fy[]={-1,  1, -2,  2, -2,  2, -1,  1}; // Knights Move
/*---------------------------------------------------------------------*/

ll m, n;
ll a[MX], b[MX];
string s,s1;
map<ll,int>mp;

///cerr<<   how to use it?
int main()
{
    #ifndef ONLINE_JUDGE
    Fin;
    #endif
    int test=1, tc=0, i, j;
    ll k, ans;
    ll c,p;
    //scanf("%d", &test);
    //precalc(1);
    while(test--)
    {
        ans=c=p=0;
        cin>>n>>s;
        i=0;
        while(s[i]=='R' && i<n)i++;
        j=n-1;
        while(s[j]=='W' && j>=0)j--;
        k=i;
        for(;i<=j;i++)
        {
            if(s[i]=='W')c++;
            else if(s[i]=='R')p++;
            //ans++;
        }
        i=k+p;
        ll p1=0;
        for(;i<=j;i++)
        {
            if(s[i]=='R')p1++;
        }
        ans=p1;
        j=j-c;
        ll c1=0;
        i=k;
        for(;i<=j;i++)
        {
            if(s[i]=='W')c1++;
        }
        ans=min(p1,c1);
        printf("%lld\n", ans);
    }
    return 0;
}



Measured memory_bytes: 3748
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    long int h,n;
 
    
cin >> h >> n;
    for (long int i = 0; i < n; i++)
    {long int x;
        cin >> x;
        h-=x;
    }
 
    if(h <=0 )
    cout << "Yes" << endl;
    else
    {
        cout << "No" << endl;
    }
    
 
 
 
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <cmath>

using namespace std;

#define EPS 1e-10

struct Point {
	double x, y;

	Point() {}
	Point(double x, double y) :x(x), y(y) {}

	Point operator+(const Point& p) const { return Point(x + p.x, y + p.y); }
	Point operator-(const Point& p) const { return Point(x - p.x, y - p.y); }
	Point operator*(const double& k) const { return Point(x * k, y * k); }
	Point operator/(const double& k) const { return Point(x / k, y / k); }

	friend istream& operator>>(istream& is, Point& p) {
		is >> p.x >> p.y;
		return is;
	}
};

typedef Point Vector;

double norm(Vector a) { return a.x * a.x + a.y * a.y; }
double abs(Vector a) { return sqrt(norm(a)); }

struct Circle {
	Point c;
	double r;

	Circle() {}
	Circle(Point c, double r) :c(c), r(r) {}
};

double arg(Vector p) { return atan2(p.y, p.x); }
Point polar(double a, double r) { return Point(cos(r) * a, sin(r) * a); }

vector<Point> getCrossPointCC(Circle c1, Circle c2) {
	double d = abs(c1.c - c2.c);
	double a = acos((c1.r * c1.r + d * d - c2.r * c2.r) / (2 * c1.r * d));
	double t = arg(c2.c - c1.c);
	vector<Point> ps;
	ps.push_back(c1.c + polar(c1.r, t + a)); ps.push_back(c1.c + polar(c1.r, t - a));
	return ps;
}

int main() {
	int N, K; cin >> N >> K;
	vector<Point> ps(N);
	vector<double> c(N);
	for (int i = 0; i < N; ++i) cin >> ps[i] >> c[i];
	double l = 0, r = 1e9;
	for (int _ = 0; _ < 300; ++_) {
		double mid = (l + r) / 2;
		bool flag = false;
		for (int i = 0; i < N; ++i) {
			int cnt = 0;
			for (int j = 0; j < N; ++j)
				if (abs(ps[i] - ps[j]) <= mid / c[j] + EPS) ++cnt;
			if (cnt >= K) flag = true;
		}
		for (int i = 0; i < N; ++i) {
			Circle A(ps[i], mid / c[i]);
			for (int j = i + 1; j < N; ++j) {
				Circle B(ps[j], mid / c[j]);
				if (abs(A.c - B.c) >= A.r + B.r) continue;
				if (abs(A.c - B.c) < abs(A.r - B.r)) continue;
				auto ccp = getCrossPointCC(A, B);
				int cnt1 = 0, cnt2 = 0;
				for (int k = 0; k < N; ++k) {
					if (abs(ccp[0] - ps[k]) <= mid / c[k] + EPS) ++cnt1;
					if (abs(ccp[1] - ps[k]) <= mid / c[k] + EPS) ++cnt2;
				}
				if (cnt1 >= K || cnt2 >= K) flag = true;
			}
		}
		if (flag) r = mid;
		else l = mid;
	}
	printf("%.10f\n", r);

	return 0;
}


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

using namespace std;

#define REP(i,a,b) for(int i=a;i<(int)b;i++)
#define rep(i,n) REP(i,0,n)
#define all(c) (c).begin(), (c).end()
#define zero(a) memset(a, 0, sizeof a)
#define minus(a) memset(a, -1, sizeof a)
#define watch(a) { std::cout << #a << " = " << a << "\n"; }
template<class T1, class T2> inline bool minimize(T1 &a, T2 b) { return b < a && (a = b, 1); }
template<class T1, class T2> inline bool maximize(T1 &a, T2 b) { return a < b && (a = b, 1); }
template<class T, class V> istream& operator>> (istream& ist, pair<T, V>& p) { return ist >> p.first >> p.second; }
template<class T> ostream& operator<< (ostream& ost, pair<T, T>& p) { return ost << p.first << ", " << p.second; }
template<class T> istream& operator>> (istream& ist, vector<T>& vs) { for(auto& e: vs) ist >> e; return ist; }

typedef long long ll;
int const inf = INT_MAX / 2;

int main() {
  int N, M, L; cin >> N >> M >> L;

  int dist[301][301];
  rep(i, N) rep(j, N) dist[i][j] = i == j ? 0 : inf;

  rep(i, M) {
    int a, b, c; cin >> a >> b >> c;
    a--, b--;
    dist[a][b] = dist[b][a] = c;
  }

  rep(k, N) rep(i, N) rep(j, N) {
    if (dist[i][k] < inf && dist[k][j] < inf &&
        dist[i][k] + dist[k][j] < dist[i][j]) {
      dist[i][j] = dist[i][k] + dist[k][j];
    }
  }

  int dist2[301][301];
  rep(i, N) rep(j, N) dist2[i][j] = i == j ? 0 : inf;

  rep(i, N) rep(j, N) {
    if (i == j) { continue; }
    if (dist[i][j] <= L) {
      dist2[i][j] = 1;
    }
  }

  rep(k, N) rep(i, N) rep(j, N) {
    if (dist2[i][k] < inf && dist2[k][j] < inf &&
        dist2[i][k] + dist2[k][j] < dist2[i][j]) {
      dist2[i][j] = dist2[i][k] + dist2[k][j];
    }
  }

  int Q; cin >> Q;
  rep(i, Q) {
    int s, t; cin >> s >> t;
    s--, t--;
    cout << (dist2[s][t] < inf ? dist2[s][t] - 1 : -1) << endl;
  }
}


Measured memory_bytes: 1280
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#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 main() {
using tsii = tuple<string,int,int>;
using vsii = vector<tsii>;
int N;
cin >>N;
vsii vec(N);
rep(i,N){
string s;
int a;
cin>>s>>a;
vec[i] = make_tuple(s,(-1)*a,i);

}
sort(vec.begin(),vec.end());
rep(i,N){
    cout<<get<2>(vec[i])+1<<endl;

}


}


Measured memory_bytes: 256
#include <stdio.h>

int main()
{
    unsigned long long sum = 0;
    int n, i;
    scanf("%d", &n);

    for(i=1; i<=n; i++)
    {
        if(i%3 > 0 && i%5 > 0) sum += i;
    }
    printf("%llu\n", sum);

    return 0;
}


Measured memory_bytes: 1728
#include <iostream>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
using P = pair<int,int>;

int gcd(int a, int b) { //最大公約数
    if (a%b == 0) return b;
    else return gcd(b,a%b);
}

int main() {
    int k,temp;
    cin>>k;
    ll sum=0;
    for (int a=1; a<=k; a++) {
        for (int b=1; b<=k; b++) {
            for (int c=1; c<=k; c++) {
                temp=gcd(b,c);
                sum+=gcd(a,temp);
            }
        }
    }
    cout<<sum<<endl;
}

Measured memory_bytes: 3640
#include<bits/stdc++.h>
using namespace std;
#define endl "\n"
#define ll long long
#define mod 1000000007

const int sz=2e5+5;
ll inf=1e15;

ll tree[4*sz],n;

ll ar[sz];

void build(int st,int en,int no)
{
    if(st==en)
    {
        tree[no]=ar[st];
        return ;
    }
    ll mid=st+(en-st)/2;
    build(st,mid,2*no+1);
    build(mid+1,en,2*no+2);
    tree[no]=max(tree[2*no+1],tree[2*no+2]);
}

void update(int st,int en,int no,int pos,ll val)
{
    if(st==en)
    {
        // cout<<pos<<" "<<val<<endl;
        tree[no]=val;
        return;
    }
    ll mid=st+(en-st)/2;
    if(pos<=mid)
        update(st,mid,2*no+1,pos,val);
    else
        update(mid+1,en,2*no+2,pos,val);

    tree[no]=max(tree[2*no+1],tree[2*no+2]);
}

ll query(int st,int en,int no,int l,int r)
{
    if(l>r or st>en or en<l or r<st)
        return 0;
    if(l<=st and r>=en)
        return tree[no];
    ll mid=st+(en-st)/2;
    ll x1=query(st,mid,2*no+1,l,r);
    ll x2=query(mid+1,en,2*no+2,l,r);
    return max(x1,x2);
}



int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int t=1;
    // cin>>t;
    while(t--)
    {
        cin>>n;
        ll h[n];
        for(int i=0;i<n;i++)
        {
            cin>>h[i];
        }

        for(int i=0;i<n;i++)
        {
            cin>>ar[i];
        }
        ll res=0;
        for(int i=0;i<n;i++)
        {
            ll val=query(0,sz-3,0,0,h[i]-1);
            // cout<<val<<endl;
            res=max(res,val+ar[i]);
            update(0,sz-3,0,h[i],val+ar[i]);

        }

        cout<<res<<endl;

        

        
    }

    return 0;
}

Measured memory_bytes: 10852
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(long long i=0; i<(int)n; i++)
#define rep2(i,a,n) for(long long i=(a); i<(int)(n); i++)
#define all(vec) vec.begin(),vec.end()
using vi = vector<int>;
using vs = vector<string>;
using vvi = vector<vi>;
using pii = pair<int, int>;
using psi = pair<string, int>;
const int dx[4] = {1, 0,-1, 0};
const int dy[4] = {0, 1, 0,-1};
const int mod = 1e9+7;
int gcd(int a, int b){if(a%b == 0){return(b);}else{return(gcd(b, a%b));}}
int lcm(int a, int b){return a * b / gcd(a, b);}

int N, M, K, H, W, L, R, X;
//string S, T;

signed main(){
  cin >> N >> M;
  vs A(N); vs B(M);
  rep(i,N) cin >> A[i];
  rep(i,M) cin >> B[i];
  
  for(int i=0; i+M<=N; i++){
    for (int j=0; j+M<=N; j++){
      bool chk = true;
      rep(k,M){
        if(!chk) break;
        rep(l,M){
          if(A[i+k][j+l] != B[k][l]){
            chk = false;
            break;
          }
        }
      }
      if(chk){
        cout << "Yes" << endl;
        return 0;
      }
    }
  }
  cout << "No" << endl;
      
  return 0;
}

Measured memory_bytes: 3608
from itertools import permutations

inf = float("inf")

N, M, R = map(int, input().split())
r = [int(s) - 1 for s in input().split()]
d = [[inf] * N for _ in range(N)]
for _ in range(M):
    a, b, c = map(int, input().split())
    d[a - 1][b - 1] = c
    d[b - 1][a - 1] = c
for k in range(N):
    for i in range(N):
        for j in range(N):
            d[i][j] = d[j][i] = min(d[i][j], d[i][k] + d[k][j])
ans = min([sum([d[r[p[i]]][r[p[i+1]]] for i in range(R-1)])
           for p in permutations(range(R))])
print(ans)


Measured memory_bytes: 65368
import java.util.Scanner;
 
public class Main {
    void testcase(){
        Scanner s = new Scanner(System.in);
        int tmp;
        int cnt = 1;
        tmp = s.nextInt();
        while(tmp != 0){
            System.out.println("Case " + cnt + ": " + tmp);
            tmp = s.nextInt();
            cnt++;
        }
    }
    public static void main(String args[]){
        Main m = new Main();
        m.testcase();
    }
}

Measured memory_bytes: 42176
#pragma GCC optimize(2,3)
#include<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm>
#define re register
#define int long long
using namespace std;
int n,m,k,ans,a[1000002];
char s[1000002];
signed main(){
scanf("%s",s+1);
n=strlen(s+1);
for(re int i=1;i<=n;++i)a[i]=s[i]-'0';
for(re int i=n;i>=1;--i){
	if(a[i]>=10){
		a[i-1]+=a[i]/10;
		a[i]%=10;
	}
if(a[i]<5)ans+=a[i];
else if(a[i]>5)ans+=10-a[i],++a[i-1];
else if(a[i-1]>=5){ans+=10-a[i],++a[i-1];
}
else ans+=a[i];
}
if(a[0]<=5)ans+=a[0];
else ans+=11-a[0];
cout<<ans<<endl;
}

Measured memory_bytes: 9088
#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
#include<algorithm>//next_permutation
#define rep(i,n) for (int i = 0;i < (n);i++)
#define all(v) v.begin(),v.end()
#define dec(n) cout << fixed << setprecision(n);
#define large "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
#define small "abcdefghijklmnopqrstuvwxyz"
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using vl = vector<ll>;
using vvl = vector<vl>;

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

const ll MOD = 1000000007;
const ll MAX = 2000001;

ll mod(ll a){
  return a % MOD;
}

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


bool isOK(ll index, vl a) {
  bool pass = false;
  ll now = a[index];
  
  for(ll i=0; i < ll(a.size()); i++){
    if(!pass and a[index] == a[i]){
      pass = true;
      continue;
    }
    
    if(a[i] <= 2*now) now += a[i];
    else return false;
  }
  
  return true;
}

int binary_search(vl a) {
    ll ng = -1;
    ll ok = (ll)a.size(); 


    while (abs(ok - ng) > 1) {
        ll mid = (ok + ng) / 2;

        if (isOK(mid, a)) ok = mid;
        else ng = mid;
    }
    return ok;
}

int main(){
  ll n; cin >> n;
  vl size(n);
  
  rep(i,n) cin >> size[i];
  
  sort(all(size));
  
  ll ans = binary_search(size);
  
  cout << n-ans << endl;
  
  
}

Measured memory_bytes: 5688
#include<bits/stdc++.h>
using namespace std;
#define int long long 
#define nn 2000008
int xi[nn],n,T,L,ri[nn];

int add[nn],yi[nn],sum=0;
signed main(){
	scanf("%lld%lld%lld",&n,&L,&T);for(int i=0;i<n;i++) scanf("%lld%lld",&xi[i],&ri[i]),ri[i]=3-ri[i]*2;
	
	for(int i=0;i<n;i++){
		yi[i]=((ri[i]*T+xi[i])%L+L)%L;
		int rot;
		if(ri[i]==1) rot=(T+xi[i])/L;
		else rot=(L-1-xi[i]+T)/L;
		
		sum+=rot*ri[i];
		add[i]-=rot*ri[i]*(n-1)+rot*ri[i];
	}
	sort(yi,yi+n);
	for(int i=0;i<n;i++) printf("%lld\n",yi[((add[i]+sum+i)%n+n)%n]);
	
	return 0;
}

Measured memory_bytes: 12160
s=list(input())
f=1
for i in range(len(s)):
    if i%2 and s[i]!="i":
        f=0
    elif i%2==0 and s[i]!="h":
        f=0
    elif s[0]!="h" or s[-1]!="i":
        f=0
print("Yes" if f else "No")


Measured memory_bytes: 38384
#include<iostream>
#include<vector>
#include<algorithm>
#include<map>
#include<cstring>
#include<math.h>
#include<bitset>
#include<queue>
#include<set>
#include<iomanip>
#include<math.h>
#include<assert.h>
// #include<bits/stdc++.h>
using namespace std;
typedef long long ll;
constexpr long long int INFLL = 1001001001001001LL;
constexpr int INFI = 1000000007;
const int mod = 1000000007;


int main(){
  int N,x;
  cin >> N >> x;
  vector<int> a(N);
  for(int i=0; i<N; i++){
    cin >> a[i];
  }
  ll ans=0;
  for(int i=0; i<N-1; i++){
    int sum;
    sum = a[i]+a[i+1];
    if(sum>x){
      a[i+1] -= min(a[i+1],sum-x);
      ans += sum-x;
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 640
#include<iostream>
#include<queue>
#include<cstring>
#include<cstdio>
#include<algorithm>
char map[1100][1100];
bool flag[1100][1100];
int m,n,k,ans=0,dir[4][2]={{-1,0},{0,-1},{0,1},{1,0}};
using namespace std;

struct point{
	int x,y,step;
}temp,flg[15];

int bfs(point a,point b)
{
	queue<point> que;
	temp=a;temp.step=0;
	que.push(temp); 
	flag[temp.x][temp.y]=true;
	while(!que.empty()){
		for(int i=0;i<4;i++){
			temp=que.front();
			int nxtx=temp.x+dir[i][0],nxty=temp.y+dir[i][1];
			if(nxtx<0||nxty<0||nxtx>=m||nxty>=n) continue;
	        if(flag[nxtx][nxty]||map[nxtx][nxty]=='X') continue;
			flag[nxtx][nxty]=true;
			temp.x+=dir[i][0],temp.y+=dir[i][1];temp.step++;	
			que.push(temp);
			if(nxtx==b.x&&nxty==b.y)
			   return temp.step;	
		}
		que.pop();
	}
	return -1;
}
int main()
{
	scanf("%d%d%d",&m,&n,&k);
	for(int i=0;i<m;i++){
		getchar();
		for(int j=0;j<n;j++){
			scanf("%c",&map[i][j]);
			if(map[i][j]=='S') flg[0].x=i,flg[0].y=j;
			else if(map[i][j]<='9'&&map[i][j]>='1') flg[map[i][j]-'0'].x=i,flg[map[i][j]-'0'].y=j;
		}
	}
	for(int i=0;i<k;i++){
	    memset(flag,false,sizeof(flag));
	    ans+=bfs(flg[i],flg[i+1]);
	}
	cout << ans << endl;
 } 


Measured memory_bytes: 5396