akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
const int INF = 1 << 29;

typedef long long ll;
typedef long double ld;
 
typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;
 
typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;


char tochr(int n){return (char)('a' + n);}
int tonum(char c){return (int)(c) - 97;}

int main(){
	ios_base::sync_with_stdio(false);cin.tie(0);
	ll n;
	cin >> n;
	deque<char> ans;
	while(n){
		n -= 1;
		ll dig = n % 26;
		n /= 26;
		ans.push_front(tochr(dig));
	}
	for(char c: ans){
		cout << c;
	}
}


Measured memory_bytes: 3592
#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; }
int gcd(int a,int b){return b?gcd(b,a%b):a;}

int main(){
  ll h, w, k;
  cin >> h >> w >> k;
  ll count_s = 0;
  vector<string> d(h);
  rep(i,h){
    cin >> d[i];
  }
  rep(i,h){
    rep(j,w){
      if(d[i][j]=='#'){
        count_s++;
      }
    }
  }
  ll num = count_s - k;
  ll ans = 0;
  for (int tm = 0; tm < (1 << 12); tm++){
    vector<string> c(h);
    rep(i,h){
      c[i] = d[i];
    }
    bitset<12> bit(tm);
    bool tmp = true;
    ll count = 0;
    rep(i, h){
      if (bit[i]){
        rep(j, w){
          if (c[i][j] == '#'){
            c[i][j] = '.';
            count++;
          }
        }
      }
    }
    for (ll i = h; i < 6; i++){
      if (bit[i]){
        tmp = false;
        goto last;
      }
    }
    for (ll i = 6; i < 6 + w; i++){
      if (bit[i])
      {
        rep(j, h)
        {
          if (c[j][i - 6] == '#'){
            c[j][i - 6] = '.';
            count++;
          }
        }
      }
    }
    for (ll i = 6+w; i < 12; i++){
      if (bit[i]){
        tmp = false;
        break;
      }
    }
  last:
  if(tmp&&count==num){
    ans++;
  }
  
  }
  print(ans);
}

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

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N, Q;
    cin >> N >> Q;
    string S;
    cin >> S;
    int length = S.size();
    vector<int> ruisekiACCount(length + 1);
    int count = 0;
    ruisekiACCount.at(0) = 0;
    ruisekiACCount.at(1) = 0;
    for (int i = 1; i < length; i++)
    {
        if (S.at(i - 1) == 'A' && S.at(i) == 'C')
        {
            count++;
        }
        ruisekiACCount.at(i + 1) = count;
    }
    vector<int> qLeftIndex(Q);
    vector<int> qRightIndex(Q);
    for (int i = 0; i < Q; i++)
    {
        cin >> qLeftIndex.at(i) >> qRightIndex.at(i);
    }
    for(int i = 0; i < Q; i++)
    {
        int left = qLeftIndex.at(i);
        int right = qRightIndex.at(i);
        int answer = ruisekiACCount.at(right) - ruisekiACCount.at(left);
        cout << answer << endl;
    }
    return 0;
}


Measured memory_bytes: 2256
using System;
using System.Linq;
using System.Collections.Generic;

namespace ConsoleApp1 {
    public class Class {
        static void Main(string[] args) {
            var XY = RL<int>();
            for(var x = 0; x <= XY[0]; x++) {
                for(var y = 0; y <= XY[0] - x; y++) {
                    if (x * 2 + y * 4 == XY[1] && x + y == XY[0]) {
                        Console.Write("Yes");
                        return;
                    }
                }
            }
            Console.Write("No");
        }

        static T[] RL<T>() where T : IComparable {
            if (typeof(T) == typeof(int)) {
                return (T[])(object)Console.ReadLine().Trim().Split().Select(int.Parse).ToArray();
            }
            if (typeof(T) == typeof(long)) {
                return (T[])(object)Console.ReadLine().Trim().Split().Select(long.Parse).ToArray();
            }
            if (typeof(T) == typeof(double)) {
                return (T[])(object)Console.ReadLine().Trim().Split().Select(double.Parse).ToArray();
            }
            if (typeof(T) == typeof(decimal)) {
                return (T[])(object)Console.ReadLine().Trim().Split().Select(decimal.Parse).ToArray();
            }
            return (T[])(object)Console.ReadLine().Trim().Split().ToArray();
        }
    }
}

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

#define int long long
#define ll long long
#define pb push_back
#define mp make_pair
#define f(i,a,n) for(int i=a ; i<(int)n ; i++)
#define rf(i,n,a) for(int i=n ; i>=a ; i--)
#define F first
#define S second
#define all(c) (c).begin(),(c).end()
#define sz(v) (int)(v).size()
#define fill(a,v) memset(a,v,sizeof(a))
#define d1(a) cout << a << "\n"
#define d2(a,b) cout << a << " " << b << "\n"
#define d3(a,b,c) cout << a << " " << b << " " << c << "\n"
#define d4(a,b,c,d) cout << a << " " << b << " " << c << " " << d << "\n"
#define fast ios:: sync_with_stdio(false),cin.tie(nullptr);

typedef long double ld;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef pair<pii,int> ppi;
typedef vector<pii> vpi;

const int inf = 1e9;
const int inf64 = 1e18;
const int MOD = inf + 7;

int32_t main(){
	fast;
	int k,n;
	cin >> k >> n;
	int a[n];
	f(i,0,n) cin >> a[i];
	sort(a , a+n);
	int ans = a[n-1] - a[0];
	f(i,1,n){
		ans = min(ans , k - (a[i] - a[i-1]));
	}
	cout << ans;
}


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

using namespace std;

const int N = 200 * 1000 + 17;
const int MOD = 1000 * 1000 * 1000 + 7;

int n, m, k;
vector<int> vec[N];

bool read() {
    if (!(cin >> n >> m >> k))
        return false;

    for (int i = 0; i < k; ++i) {
        int x, y;
        cin >> x >> y;
        vec[y - 1].emplace_back(x - 1);
    }

    return true;
}

void solve() {
    for (int i = 0; i < m; ++i)
        sort(vec[i].begin(), vec[i].end());

    auto x = 0;
    auto y = 0;
    auto ans = n;

    for (int t = 0; ; t ^= 1) {
        if (t == 0) {
            auto it = upper_bound(vec[y].begin(), vec[y].end(), x);

            if (it != vec[y].end() && *it == x + 1) {
                ans = min(ans, x + 1);
                break;
            }

            ++x;
        } else {
            auto it = upper_bound(vec[y].begin(), vec[y].end(), x);

            if (it != vec[y].end())
                ans = min(ans, *it);

            if (y == m - 1)
                break;

            it = lower_bound(vec[y + 1].begin(), vec[y + 1].end(), x);

            if (it != vec[y + 1].end() && *it == x)
                continue;

            ++y;
        }
    }

    cout << ans << endl;
}

int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    while (read())
        solve();

    return 0;
}



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

int main(){
    int x;
    cin >> x;
    int item[6] = {100, 101, 102, 103, 104, 105};
    bool dp[200000];
    dp[0] = true;
    for(int i = 1; i <= 100000; i++){
        for(int j = 0; j < 6; j++){
            if(i - item[j] >= 0) dp[i] |= dp[i-item[j]];
        }
    }
    if(dp[x]){
        cout << 1 << endl;
    }
    else{
        cout << 0 << endl;
    }
}

Measured memory_bytes: 384
package main

import "fmt"

func main() {
	var n int
	fmt.Scan(&n)
	a := make([]string, n)
	for i := range a {
		fmt.Scan(&a[i])
	}

	m := make(map[string]bool)
	uniq := [] string{}

	for _, ele := range a {
		if !m[ele] {
			m[ele] = true
			uniq = append(uniq, ele)
		}
	}

	fmt.Printf("%v", len(uniq))
}

Measured memory_bytes: 640
import math
import sys

n = int(input())
s = int(input())

up = math.sqrt(n)

def colsum(num, base):
    if num < base:
        return num
    else:
        return num%base + colsum(num//base,base)

#s >= n
if s == n:
    print(n+1)
elif s > n:
    print(-1)
else:
    #sqrt(n)まで探索
    for i in range(2,int(up)+1):
        if colsum(n,i) == s:
            print(i)
            sys.exit()

    #2桁しかあり得ない場合(sqrt(n)<b<n)
    for j in range(int(up),0,-1):
        if (n-s)%j == 0:
            b = (n-s)/j + 1
            if colsum(n,b) == s and b > 1:
                print(int(b))
                sys.exit()

    print(-1)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
#define REP(i,st,ed) for(register int i=st,i##end=ed;i<=i##end;++i)
#define DREP(i,st,ed) for(register int i=st,i##end=ed;i>=i##end;--i)
typedef long long ll;
inline int read(){
	int x;
	char c;
	int f=1;
	while((c=getchar())!='-' && (c>'9' || c<'0'));
	if(c=='-') c=getchar(),f=-1;
	x=c^'0';
	while((c=getchar())>='0' && c<='9') x=(x<<1)+(x<<3)+(c^'0');
	return x*f;
}
inline ll readll(){
	ll x;
	char c;
	int f=1;
	while((c=getchar())!='-' && (c>'9' || c<'0'));
	if(c=='-') c=getchar(),f=-1;
	x=c^'0';
	while((c=getchar())>='0' && c<='9') x=(x<<1ll)+(x<<3ll)+(c^'0');
	return x*f;
}
const int maxn=1e5+10;
int a[maxn];
int main(){
	int n=read();
	REP(i,1,n) a[i]=read();
	ll Min=2,Max=2;
	DREP(i,n,1){
		if(Min%a[i]) Min=(Min/a[i]+1)*a[i];
		Max=(Max/a[i]+1)*a[i]-1;
	}
	if(Min>Max) printf("-1\n");
	else printf("%lld %lld\n",Min,Max);
	return 0;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define vl vector
using namespace std;
int main()
{
    ll a,b;
    cin>>a>>b;
    if(b>=a*2 && b<=a*4 && b%2==0) cout<<"Yes";
    else cout<<"No";
    return 0;
}

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

T *= 1000
A *= 1000

max_diff = float('inf')
ans = 0
for i, h in enumerate(map(int, input().split()), 1):
    t = T - h * 6
    d = abs(t - A)
    if d < max_diff:
        max_diff = d
        ans = i
print(ans)

Measured memory_bytes: 3188
n, m = map(int, input().split())
a = []
b = []
c = []
d = []
for i in range(n):
    _a, _b = map(int, input().split())
    a.append(_a)
    b.append(_b)
for i in range(m):
    _c, _d = map(int, input().split())
    c.append(_c)
    d.append(_d)
ans = [99 for i in range(n)]
for i in range(n):
    mini = 9999999999
    for j in range(m):
        mnhtn = abs(a[i]-c[j]) + abs(b[i]-d[j])
        if mnhtn < mini:
            mini = mnhtn
            ans[i] = j+1
for i in ans:
    print(i)

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

int main(){
  int n;
  cin >> n;
  int x[n+1],xx[n+1];
  for ( int i = 1; i <= n; i++){
    cin >> x[i];
    xx[i] = x[i];
  }

  sort(xx+1, xx+n+1);

  for ( int i = 1; i <= n; i++){
    int val = x[i];
    int pos = lower_bound(xx+1, xx+n+1, val) -(xx);
    if ( pos <= n / 2 ){
      cout << xx[ n / 2 + 1] << endl;
    } else {
      cout << xx[ n / 2] << endl;
    }
  }

  return 0;
}

Measured memory_bytes: 3712
//+-----------------+//
//|😜_Anonymous06_😜|//
//+-----------------+//
#include <bits/stdc++.h>
#define ll/*////////*/long long
#define gcd()/*////////*/___gcd()
#define pi/*////////*/3.141592653
using namespace std;
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);cout.tie(0);
	//freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);
	//------Enter your code here.------
	int n;cin>>n;
	for(int i=1000;i<1e5;i+=1000)
	{
		if(i>=n){cout<<i-n<<"\n";return 0;}
	}	
}

Measured memory_bytes: 3636
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <string.h>
using namespace std;

int main() {
	cin.tie(0);
   	ios::sync_with_stdio(false);
	
    int a,s,d;

    cin>>a>>s>>d;

    if(a+s+d >= 22)
        cout<<"bust";
    else
    {
        cout<<"win";
    }
    

    return 0;
}

Measured memory_bytes: 256
"use strict";
main(
  require("fs")
    .readFileSync("/dev/stdin", "UTF-8")
    .trim()
    .split("\n")
);
function main(input) {
  input = input[0].split(" ").map(Number);
  let result = -1;

  for (let i = Math.max(...input) * 10; i < Math.max(...input) * 100; i++) {
    let A = Math.floor(i * 0.08);
    let B = Math.floor(i * 0.1);
    if (A === input[0] && B === input[1]) {
      result = i;
      break;
    }
  }

  console.log(result);
}


Measured memory_bytes: 9776
N = int(input())
T = [int(i) for i in input().split()]
M = int(input())
ans = ''
for i in range(M):
    goukei = sum(T)
    P, X = map(int,input().split())
    goukei = goukei + X - T[P-1]
    ans += str(goukei) + "\n"

print(ans[:-1])


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

int main()
{
    int a, b;
    cin >> a >> b;
    for (int i = 1; i < 4; i++)
    {
        if ((a * b * i) % 2 == 1)
        {
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
    return 0;
}

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

int main(){
  long long a,b,c,x,y,z,u;
  z=1000000000000;
  cin>>a>>b>>c>>x>>y;
  for(int i=0;i<max(x,y)+1;i++){
 if(i>x){
      u=2*i*c+(y-i)*b;
    }
    else if(i>y){
      u=2*i*c+(x-i)*a;
    }
    else{
      u=2*i*c+(x-i)*a+(y-i)*b;
    }
    z=min(z,u);
  }
      cout<<z<<endl;

}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int n, l, q;
vector<int>v;
vector<vector<int> >moves;
void preprocess(){
    int cur = 1;
    for(int i = 1; i <= n; i++){
        while(cur <= n && v[cur] - v[i] <= l){
            cur++;
        }
        moves[i][0] = cur - 1;
    }
    for(int j = 1; j <= 17; j++){
        for(int i = 1; i <= n; i++){
            int mid = moves[i][j - 1];
            if(mid != -1){
                moves[i][j] = moves[mid][j - 1];
            }
        }
    }
}
int query(int l, int r){
    int ans = 0;
    if(l > r){
        swap(l, r);
    }
    for(int i = 17; i >= 0; i--){
        if(moves[l][i] == -1){
            continue;
        }
        if(moves[l][i] < r){
            l = moves[l][i];
            ans += 1 << i;
        }
    }
    ans++;
    return ans;
}
int main(){
    cin >> n;
    v.assign(n + 2, 0);
    moves.assign(n + 2, vector<int>(19, -1));
    for(int i = 1; i <= n; i++){
        cin >> v[i];
    }
    cin >> l >> q;
    preprocess();
    for(int i = 1; i <= q; i++){
        int l, r;
        cin >> l >> r;
        cout << query(l, r) << '\n';
    }
    return 0;
}

Measured memory_bytes: 15396
import java.util.Scanner;
public class Main {
	int n;
	int[] r;
	public static void main(String args[]) {
		new Main();
	}
	Main() {
		Scanner scan = new Scanner(System.in);
		n = scan.nextInt();
		r = new int[n];
		for (int i = 0; i < n; i++) {
			r[i] = scan.nextInt();
		}
		int min = r[0];
		int max = Integer.MIN_VALUE;
		for (int i = 1; i < n; i++) {
			max = Math.max(max, r[i] - min);
			min = Math.min(r[i],min);
		}
		System.out.println(max);
	}
}



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

#define int long long
#define double long double
#define rep(i,n) for(int i=0;i<n;i++)
#define mod 1000000007 // 10^9+7
#define INF 99999999999 //10^12-1
#define dev 998244353 //tenka1
#define P pair<int,int>
#define F first
#define S second
int n,maxo=0,maxe=0,oo,ee;
int v[200000];
map<int,int>odd,even;
vector<int>o,e;
signed main(){
    cin>>n;
    rep(i,n){
        cin>>v[i];
        if(i%2)even[v[i]]++;
        else odd[v[i]]++;
    }
    rep(i,n){
        if(i%2){
            if(even[v[i]]>maxe){
                maxe=even[v[i]];
                ee=v[i];
            }
        }
        else{
            if(odd[v[i]]>maxo){
                maxo=odd[v[i]];
                oo=v[i];
            }
        }
    }
    rep(i,n){
        if(i%2){
            e.push_back(even[v[i]]);
            even[v[i]]=0;
        }
        else{
            o.push_back(odd[v[i]]);
            odd[v[i]]=0;
        }
    }
    sort(e.begin(),e.end());
    reverse(e.begin(),e.end());
    sort(o.begin(),o.end());
    reverse(o.begin(),o.end());
    if(ee!=oo){
        int ans=n-(e[0]+o[0]);
        cout<<ans<<endl;
    }
    else{
        int x=e[0]+o[1],y=e[1]+o[0];
        int ans=n-max(x,y);
        cout<<ans<<endl;
    }
    return 0;
}


Measured memory_bytes: 8316
#include <bits/stdc++.h>
using namespace std;
#define LL long long
#define Max(a,b) ((a)>(b)?(a):(b)) 
#define Min(a,b) ((a)<(b)?(a):(b)) 

//FILE *fp,*fp2;
//fp=fopen("input.txt","r");
//fp2=fopen("output.txt","w");

int main()
{
    int n;
    set<LL int> num;
    set<LL int>::iterator it;
    cin>>n;
    LL int x;
    while(n--)
    {
        cin>>x;
        it=num.find(x);
        if (it ==num.end())
        {
            num.insert(x);
        }
        else
        {
            num.erase(it);
        }
    }
    x=num.size();
    cout<<x<<endl;
    
    return 0;
}



Measured memory_bytes: 4864
#include <iostream>
#include <vector>
#include <climits>
#include <algorithm>
#include <cmath>
#define INF (INT_MAX / 2)
//#define DEBUG true
#define DEBUG false
using namespace std;

typedef long long ll;

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

  ll x, y;
  cin >> x >> y;

  ll z = x;
  int count = 0;
  while(z <= y){
    z <<= 1;
    ++count;
  }

  cout << count << endl;

  return 0;
}

Measured memory_bytes: 256
use std::io;
use std::io::{Read, BufReader};
use std::cmp;

fn next_token<R: Read>(reader: &mut R) -> Vec<u8> {
    let mut buf: [u8; 1] = [0];
    let mut read_chars = false;
    let mut ret: Vec<u8> = vec![];

    loop {
        if reader.read(&mut buf).unwrap() == 0 {
            break;
        } else {
            if buf[0] == '\r' as u8 || buf[0] == '\n' as u8 || buf[0] == ' ' as u8 {
                if read_chars {
                    break;
                }
            } else {
                read_chars = true;
                ret.push(buf[0]);
            }
        }
    };
    ret
}
fn next_i64<R: Read>(reader: &mut R) -> i64 {
    let token = next_token(reader);
    let mut ret: i64 = 0;
    let mut sgn = false;

    for c in token {
        if '0' as u8 <= c && c <= '9' as u8 {
            ret = ret * 10 + (c - ('0' as u8)) as i64;
        } else if '-' as u8 == c {
            sgn = true;
        }
    };
    ret * if sgn { -1 } else { 1 }
}
fn next_i32<R: Read>(reader: &mut R) -> i32 {
    next_i64(reader) as i32
}
static MOD: i64 = 1000000007;

fn trans_seq(x: Vec<u8>) -> Vec<i32> {
    let mut ret: Vec<i32> = vec![0];
    let mut cnt = 0;
    for n in x {
        cnt = cnt + if n == 'A' as u8 { 1 } else { 2 };
        ret.push(cnt)
    }
    ret
}
fn main() {
    let buf = &mut BufReader::new(io::stdin());

    let s = trans_seq(next_token(buf));
    let t = trans_seq(next_token(buf));
    let q = next_i32(buf);
    for _ in 0..q {
        let a = next_i32(buf) - 1;
        let b = next_i32(buf);
        let c = next_i32(buf) - 1;
        let d = next_i32(buf);
        println!("{}", if (s[b as usize] - s[a as usize]) % 3 == (t[d as usize] - t[c as usize]) % 3 { "YES" } else { "NO" });
    }
}


Measured memory_bytes: 4604
#pragma comment(linker,"/stack:16777216")
#include<iostream>
#include<cstdio>
#include<string>
#include<vector>
#include<set>
#include<map>
#include<list>
#include<stack>
#include<queue>
#include<deque>
#include<functional>
#include<utility>
#include<algorithm>
#include<sstream>
#include<cstring>
#include<cmath>
#include<cctype>
#include<exception>
#include<climits>
#include<cfloat>
#include<iomanip>
#include<bitset>
#include<streambuf>
#include<cstdlib>
#include<ctime>
//#include"functions.h"
//#include"highprecision.h"
#define pb push_back
#define pf push_front
#define ppb pop_back
#define mp make_pair
#define np next_permutation
#define fi first
#define sc second
#define vi vector<int>
#define vll vector<long long>
#define vvi vector<vector<int> >
#define vpi vector<pair<int,int> >
#define pii pair<int,int>
#define pll pair<long long,long long>
#define pff pair<float,float>
#define pdd pair<double,double>
#define psi pair<string,int>
#define pis pair<int,string>
#define ppi pair<pii,int>
#define pdi pair<pii,pii>
#define LN 84757
#define INF 1e9
#define LLINF 1e18
#define MAXINT 0x7fffffff
#define MAXLL 0x7fffffffffffffff
#define EPS 1e-5
#define DEPS 1e-9
#define LDEPS 1e-13
#define MOD 1000000007
#define E 2.7182818284
#define PI 3.1415926535
#define rep(a,b) for(int a=0;a<b;a++)
#define rep(a,b) for(int a=0;a<b;a++)
#define forn(a,n) for(int a=1;a<=n;a++)
#define forr(a,n) for(int a=n;a>=1;a--)
#define repn(a,n,p) for(int a=0;a<n;a+=p)
#define repr(a,n) for(int a=n-1;a>=0;a--)
#define foreach(a,b) for(__typeof(b.begin())a=b.begin();a!=b.end();a++)
#define fillemp(a) memset(a,0,sizeof(a))
#define fillinf(a) memset(a,0x3f,sizeof(a))
#define frestream freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
#define stdf(a,b) freopen(a,"r",stdin);freopen(b,"w",stdout);
#define inputf(a) freopen(a,"r",stdin);
#define outputf(a) freopen(a,"w",stdout);
#define sz(a) a.size()
#define all(a) a.begin(),a.end()
#define MOD 1000000007
typedef long long ll;
typedef long double ld;
using namespace std;

int r,c,k;
ll v[3010][3010];
ll dp[3010][3010][5];
void chkmax(ll& a,ll b){
	a=max(a,b);
}
int main(int argc,char** argv){
	cin>>r>>c>>k;
	rep(i,k){
		int x,y,t;
		cin>>x>>y>>t;
		v[x][y]=t;
	}
	forn(i,r){
		forn(j,c){
			rep(k,4){
				chkmax(dp[i][j][0],dp[i-1][j][k]);
			}
			if(v[i][j])rep(k,4){
				chkmax(dp[i][j][1],dp[i-1][j][k]+v[i][j]);
			}
			rep(k,4){
				chkmax(dp[i][j][k],dp[i][j-1][k]);
				if(v[i][j]&&k)chkmax(dp[i][j][k],dp[i][j-1][k-1]+v[i][j]);
			}
		}
	}
	ll ans=0ll;
	rep(i,4){
		chkmax(ans,dp[r][c][i]);
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 426892
use proconio::{input, fastout};
use proconio::marker::{Chars};
use std::cmp::*;

#[fastout]
fn main() {
    input!{
        s: Chars,
    }

    let mut odd_white = 0;
    let mut odd_black = 0;
    let mut even_white = 0;
    let mut even_black = 0;
    for i in 0..s.len() {
        if i%2==0 {
            if s[i]=='0' {
                even_black += 1;
            } else {
                even_white += 1;
            }
        } else {
            if s[i]=='0' {
                odd_black += 1;
            } else {
                odd_white += 1;
            }
        }
    }
    let ans = min(s.len()-(even_black+odd_white), s.len()-(even_white+odd_black));
    println!("{}", ans);
}


Measured memory_bytes: 2504
#include<cstdio>
#include<iostream>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<list>
#include<map>
#include<algorithm>

using namespace std;

int main()
{
    int N;
    cin >> N;
    vector<string> W;

    for (int i = 0; i < N; i++) {
        string Wi;
        cin >> Wi;
        W.push_back(Wi);
    }

    for (int i = 1; i < N; i++) {
        if (W[i].front() != W[i - 1].back()) {
            cout << "No" << endl;
            return 0;
        }
        for (int j = 0; j < i - 1; j++) {
            if (W[i] == W[j]) {
                cout << "No" << endl;
                return 0;
            }
        }
    }

    cout << "Yes" << endl;

    return 0;
}


Measured memory_bytes: 256
import std.algorithm, std.conv, std.range, std.stdio, std.string;
import std.bitmanip;  // BitArray

void main()
{
  auto s = readln.chomp, n = s.length;
  auto ans = 0L;

  foreach (i; 0..1<<(n-1)) {
    auto j = [size_t(0)] ~ i.bitsSet.map!"a+1".array ~ [n];
    auto r = 0L;
    foreach (k; 0..j.length-1)
      r += s[j[k]..j[k+1]].to!long;
    ans += r;
  }

  writeln(ans);
}


Measured memory_bytes: 380
#include <iostream>
#include <string>
#include <vector>

using namespace std;
typedef long long LL;

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

int main(){
    LL N, M;
    cin >> N >> M;
    vector<vector<LL> > a(N, vector<LL>(M));
    for(int i = 0; i < N; ++i){
        for(int j = 0; j < M; ++j){
            cin >> a[i][j];
        }
    }
    LL best = N;
    vector<LL> cancel(M+1);
    vector<LL> cursor(N);
    for(int j = 0; j < M; ++j){
        vector<LL> count(M+1);
        for(int i = 0; i < N; ++i){
            while(cancel[a[i][cursor[i]]]){
                cursor[i]++;
            }
            count[a[i][cursor[i]]] += 1;
        }
        LL max_cur = 1;
        for(int i = 1; i <= M; ++i){
            //cerr << i << " : count=" << count[i] << endl;
            if(count[i] > count[max_cur]) max_cur = i;
        }
        //cerr << "max_cur=" << max_cur << " , count=" << count[max_cur] << endl;
        best = min(best, count[max_cur]);
        cancel[max_cur] = 1;
    }
    cout << best << endl;

    return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
//#pragma GCC optimize(2)
//author wjl

using namespace std;
#define LL long long
#define Rint register int
#define U unsigned
#define forn(i,a,b) for(int i = a;i <= b;++i)
#define nfor(i,a,b) for(int i = a;i >= b;--i)
#define pii pair<int ,int>
#define MS0(X) memset(X,0,sizeof(X))
#define MSf(X) memset(X,false,sizeof(X))
#define MS1(X) memset(X,-1,sizeof(X))
#define BR printf("--------------------\n")
#define pb push_back
#define rep(i,a,b) for(Rint i=a;i<=b;++i)
#define DEBUG(x) std::cerr << #x << '=' << x << std::endl
const double PI=atan(1.)*4.;
const int maxn=1e6+5;
const int inf = 0x3f3f3f3f;
const int mod=1e9+7;
const double e=2.71828182845904523536;
int dirx[8]={1,0,-1,0,1,-1,-1,1};
int diry[8]={0,1,0,-1,1,1,-1,-1};

int h,w,k;
char mp[10][10];
int ans=0;

void dfs(int dep)
{
    if(dep==h+w)
    {
        int cnt=0;
        for(int i=0;i<h;i++)
        {
            for(int j=0;j<w;j++)
            {
                if(mp[i][j]=='#')
                    cnt++;
            }
        }
        if(cnt==k) 
        {
            ans++;
        }
        return ;
    }
    char tmp[10];
    if(dep<h)
    {
        for(int i=0;i<w;i++)
        {
            tmp[i]=mp[dep][i];
            mp[dep][i]='r';
        }
        dfs(dep+1);
        for(int i=0;i<w;i++)
        {
            mp[dep][i]=tmp[i];
        }
    }
    else
    {
        for(int i=0;i<h;i++)
        {
            tmp[i]=mp[i][dep-h];
            mp[i][dep-h]='r';
        }
        dfs(dep+1);
        for(int i=0;i<h;i++)
        {
            mp[i][dep-h]=tmp[i];
        }
    }
    dfs(dep+1);
    return ;
}

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

    cin>>h>>w>>k;

    for(int i=0;i<h;i++)
    {
        for(int j=0;j<w;j++)
        {
            cin>>mp[i][j];
        }
    }
    dfs(0);
    cout<<ans<<endl;
    return 0;
}

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

#ifdef LOCAL
#define debug(var) cerr << (#var) << " = " << (var) << endl;
#else
#define debug(var)
#endif

void init() {
  ios_base::sync_with_stdio(0);
  cin.tie(0); cout.tie(0);
}

const int N = 1e5+23;

vector<int> g[N], l[N];

bool bio[N];

void dfs(int u) {
  bio[u] = 1;
  for (int v: g[u]) {
    if (bio[v]) continue;
    dfs(v);
  }
}

void solve() {
  int n, m; scanf("%d%d", &n, &m);
  for (int i = 0; i < n; ++i) {
    int k; scanf("%d", &k);
    for (int j = 0; j < k; ++j) {
      int x; scanf("%d", &x);
      l[--x].push_back(i);
    }
  }
  for (int i = 0; i < m; ++i) {
    for (int j = 1; j < (int)l[i].size(); ++j) {
      g[l[i][j]].push_back(l[i][j-1]);
      g[l[i][j-1]].push_back(l[i][j]);
    }
  }
  dfs(0);
  for (int i = 0; i < n; ++i) {
    if (!bio[i]) {
      printf("NO");
      return;
    }
  }
  printf("YES");
}

int main() {
  init();
  int t = 1; //scanf("%d", &t);
  while (t--) {
    solve();
  }
  return 0;
}


Measured memory_bytes: 14584
package main

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

var (
	weights = [101]int{}
	values  = [101]int{}
	m       = [100001]int{}
)

func main() {
	sc := NewScanner(os.Stdin)
	n, maxWeight := sc.Int(), sc.Int()

	for i := 1; i <= n; i++ {
		weights[i] = sc.Int()
		values[i] = sc.Int()
	}

	for i := range weights {
		w, v := weights[i], values[i]

		for j := maxWeight; j >= w; j-- {
			m[j] = Max(m[j], m[j-w]+v)
		}
	}

	fmt.Println(m[maxWeight])
}

// generated by https://github.com/murosan/gollect

func Max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

type Scanner struct{ *bufio.Scanner }

func NewScanner(r io.Reader) *Scanner {
	s := bufio.NewScanner(r)
	s.Split(bufio.ScanWords)
	return &Scanner{Scanner: s}
}

func (s *Scanner) Bytes() []byte { s.Scan(); return s.Scanner.Bytes() }

func (s *Scanner) Int() int { return BytesToInt(s.Bytes()) }

func BytesToInt(b []byte) (n int) {
	var i int
	negative := b[0] == 45
	if negative {
		i++
	}
	for ; i < len(b); i++ {
		n = n*10 + int(b[i]-'0')
	}
	if negative {
		return -n
	}
	return
}


Measured memory_bytes: 1408
(let ((N (read))
      (M (read)))
     (defvar height (make-array N
       :initial-contents (loop repeat N collect (read))))
     (defvar good (make-array N :initial-element t))
     (loop repeat M with a and b do
           (setf a (1- (read))
                 b (1- (read))
                 ha (aref height a)
                 hb (aref height b))
           (cond
             ((< ha hb) (setf (aref good a) nil))
             ((> ha hb) (setf (aref good b) nil))
             (t (setf (aref good a) nil)
                (setf (aref good b) nil))))
     
     (princ (loop for x across good 
                  count x)))

Measured memory_bytes: 80472
N = int(input())
m = 10000000000000000
for i in range (1,N):
    a = i
    b = N-i
    s1,s2=str(a),str(b) #int型をstr型に
    d1,d2 = list(s1),list(s2) #一文字ずつリストに格納
    x1,x2 = list(map(int, d1)),list(map(int, d2)) #int型に直して格納
    sum1,sum2 = sum(x1),sum(x2)
    m = min(m,sum1+sum2)
print(m)

Measured memory_bytes: 3444
module Main where
import Control.Monad
import Data.Maybe
import qualified Data.ByteString.Char8 as BS
tuplify2 (x:y:_) = (x,y)
tuplify2 _ = undefined


readInt = fst . fromJust . BS.readInteger
readIntTuple = tuplify2 . map readInt . BS.words
readIntList = map readInt . BS.words

getInt = readInt <$> BS.getLine
getIntList = readIntList <$> BS.getLine
getIntNList n = map readIntList <$> replicateM (fromIntegral n) BS.getLine
getIntMatrix = map readIntList . BS.lines <$> BS.getContents
getIntTuple = readIntTuple <$> BS.getLine
getIntNTuples n = map readIntTuple <$> replicateM (fromIntegral n) BS.getLine
getIntTuples = map readIntTuple . BS.lines <$> BS.getContents

solve :: [Integer] -> Integer
solve a =
    let accl = 0:scanl gcd 0 a
        accr =reverse $ scanl gcd 0 (reverse a)
    in  maximum $ zipWith gcd accl accr

main :: IO ()
main = do
    getLine
    a <- getIntList
    putStrLn $ show $ solve a


Measured memory_bytes: 38268
#include<bits/stdc++.h>
using namespace std;
int N,K;
vector<int> D(9);
bool check(int x){
    while(x!=0){
	for(int i=0;i<K;i++){
	    if(x%10==D.at(i))
		return false;
	}
    x/=10;
    }
    return true;
}
int main(){
    cin>>N>>K;
    for(int i=0;i<K;i++)
	cin>>D.at(i);
int ans=N;
while(!check(ans)){
    ans++;
}
cout<<ans<<endl;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
typedef long long ll;
const ll MOD=1000000007;
ll pow_mod(ll m,ll n, ll mod){
	ll res=1;
	while(n>0){
		if(n&1)res=res*m%mod;
		m=m*m%mod;
		n >>=1 ;
	}
	return res;
}
int main(){
	ll n,m;
	cin>>m>>n;
	cout<<pow_mod(m,n,MOD)<<endl;
	return 0;
}


Measured memory_bytes: 3100
#include <algorithm>
// #include <cstdlib>
#include <cstring>
#include <cstdio>
#include <string>
#include <queue>
#include <cmath>
#include <set>
#include <map>
#include <bitset>
using namespace std;
typedef long long LL;
typedef double db;
const int oo=2139063143;
const int N=1010000;
const int P=1000000007;
const db eps=1e-7;
#define pritnf printf
//char buf[1<<22],*p1=buf,*p2=buf,obuf[1<<22],*O=obuf;
//#define getchar() (p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<21,stdin),p1==p2)?EOF:*p1++)
template <typename T>
inline void sc (T &x)
{
    x=0; static int p; p=1; static char c; c=getchar();
    while (!isdigit(c)) { if (c=='-') p=-1; c=getchar(); }
    while ( isdigit(c)) { x=(x<<1)+(x<<3)+(c-48); c=getchar(); }
    x*=p;
}
template <typename T>
inline void print (T x)
{
    if (x< 0) putchar('-'),x=-x;
    if (x>=10) print(x/10);
    putchar(x%10+'0');
}
template <typename T>
inline void pr (T x) { print(x),putchar(' '); }
template <typename T1,typename T2>
void chkmax (T1 &A,T2 B) { A=A>=B?A:B; }
template <typename T1,typename T2>
void chkmin (T1 &A,T2 B) { A=A<=B?A:B; }

int n,x[N],y[N],deg[N],d1[N],d2[N];
#define pb push_back
vector <int> G[N];
int st[N],z=0;
void dfs (int u,int fa,int aim)
{
	st[++z]=deg[u]-2;
	if (u==aim) return ;
	for (int v:G[u])
		if (v!=fa&&deg[v]!=1) { dfs (v,u,aim); break; }
}
int main ()
{
    // freopen (".in","r",stdin);
    // freopen (".out","w",stdout);
	sc(n);
	if (n<=2)
	{
		for (int i=1; i<=n; i++)
			pr(i);
		return 0;
	}
	for (int i=1; i< n; i++)
	{
		sc(x[i]),sc(y[i]);
		++deg[x[i]],++deg[y[i]];
		G[x[i]].pb (y[i]),G[y[i]].pb (x[i]);
	}
	for (int i=1; i< n; i++) if (min (deg[x[i]],deg[y[i]])!=1)
		++d1[x[i]],++d1[y[i]];
	int ma=0;
	for (int i=1; i<=n; i++)
		chkmax (ma,d1[i]);
	if (ma> 2) return pr(-1),0;
	int X=0,Y=0;
	for (int i=1; i<=n; i++)
		if (d1[i]==1) (X?Y:X)=i;
	if (!X) for (int i=1; i<=n; i++)
		if (deg[i]> 1) { X=Y=i; break; }
	dfs (X,0,Y);
	for (int i=1; i<=z; i++)
	{
		if (st[i]< st[z-i+1]) break;
		if (st[i]> st[z-i+1]) { reverse (st+1,st+z+1); break; }
	}
	int cur=1; pr(1);
	for (int i=1; i<=z; i++)
	{
		for (int j=1; j<=st[i]; j++)
			pr(cur+1+j);
		pr(cur+1);
		cur+=st[i]+1;
	}
	pr(n);

    return 0;
}


Measured memory_bytes: 39168
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int H[] = new int[N];
        int answer = 1;
        int max = 0;

        for (int i = 0; i < N; i++) {
            H[i] = sc.nextInt();
        }

        for (int i = 0; i < N; i++) {
            if (i == 0) {
                max = H[i];
            } else {
                if (max <= H[i]) {
                    max = H[i];
                    answer++;
                }
            }
        }
        System.out.println(answer);
        sc.close();
    }
}

Measured memory_bytes: 35420
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <vector>
#include <utility>
#include <cstdio>
#include <iomanip>
#include <cmath>
#include <string>
#include <stack>
#include <queue>
#include <map>
#include <stdlib.h>
#include <set>
typedef long long ll;
using namespace std;

int main() {
	int a,b;
	cin>>a>>b;
	for(int i=1;i<4;i++){
		if((a*b*i)%2 !=0 ){
			cout<<"Yes"<<endl;
			return 0;
		}
	}
	cout<<"No"<<endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define MOD 1000000007
#define PI 3.141592653589793

int main(){
    string a, b, c;
    cin >> a >> b >> c;
    printf("%c%c%c\n", toupper(a[0]), toupper(b[0]), toupper(c[0]));
}


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

using lint = long long;

int main() {
    ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    lint a, b, k;
    cin >> a >> b >> k;
    
    lint x = a >= k ? a - k : 0;
    k = x ? 0 : k - a;
    lint y = b >= k ? b - k : 0;
    cout << x << ' ' << y << '\n';
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
	public static void main(String[] args) {
      Scanner sc =new Scanner(System.in);
      int X = sc.nextInt();
      if (X == 3 || X == 5 || X == 7) {
        System.out.println("YES");
      } else {
        System.out.println("NO");
      }
    }
}

Measured memory_bytes: 22740
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            string s = Console.ReadLine();
            string result = "";
            for(int i = 0; i < s.Length; i = i + 2)
            {
                result += s.Substring(i, 1);
            }
            Console.WriteLine(result);
        }
    }
}
// 文字列の入力
//string s = Console.ReadLine();

// 整数の入力
//long n = long.Parse(Console.ReadLine());

// 文字列配列の入力
//string[] inputStrArray = Console.ReadLine().Split(' ');

// 整数配列の入力
//long[] inputLongArray = Console.ReadLine().Split(' ').Select(i => long.Parse(i)).ToArray();

//Console.WriteLine(ans);

Measured memory_bytes: 47860
#include <iostream>

int gcd(int a, int b) {
    if (a > b) {
        if (b == 0) {
            return a;
        } else {
            return gcd(b, a % b);
        }
    } else {
        if (a == 0 ) {
            return b;
        } else {
            return gcd(a, b % a);
        }
    }
}

int main() {
    int a, b;
    std::cin >> a >> b;
    
    std::cout << gcd(a, b) << std::endl;;
}


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

typedef long long ll;
typedef long double ld;
long double MAX = 10000009.0;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    ld r;
    cin>>r;
    long double pi = 3.1415926535897;
     std::cout << std::setprecision(11) << 2*r*pi << endl;
    return 0;
}


Measured memory_bytes: 3808
m=int(input())
ans=0
kari=0
for i in range(m):
  d,c=map(int,input().split())
  ans+=c
  kari+=c*d
  ans+=kari//9
  kari=kari%9

if(kari==0):
  print(ans-2)
else:
  print(ans-1)

Measured memory_bytes: 3188
import java.util.Scanner;

public class Main {
    static int N;
    static double[] a;
    static double first = 0;
    static double second = 0;


    private static void init() {
        Scanner scanner = new Scanner(System.in);
        N = scanner.nextInt();
        a = new double[N];
        for(int i = 0; i < N; i++) {
            double input = scanner.nextDouble();
            a[i] = input;
            if(first < input) {
                second = first;
                first = input;
                continue;
            }
            if(second < input) {
                second = input;
            }
        }
        scanner.close();
    }


    public static void main(String[] args) {
        init();

        for(int i = 0; i < N; i++) {
            if(a[i] == first) {
                System.out.println((int) second);
            } else {
                System.out.println((int) first);
            }
        }
    }
}


Measured memory_bytes: 161276
#include<bits/stdc++.h>
using namespace std;
int a[5010];
bool dp[5010];
int n,k;
bool check(int mid)
{
	if(a[mid]>k)return 1;
	memset(dp,0,sizeof(dp));
	dp[0]=1;
	for(int i=1;i<=n;i++)
	{
		if(i==mid)continue;
		for(int j=k;j>=a[i];j--)
		dp[j]=dp[j]||dp[j-a[i]];
	}
	for(int i=k-a[mid];i<k;i++)
	if(dp[i])return true;
	return false;
}
int main()
{
	scanf("%d %d",&n,&k);
	for(int i=1;i<=n;i++)
	scanf("%d",&a[i]);
	sort(a+1,a+1+n);
	int l=1,r=n;
	while(l<=r)
	{
		int mid=(l+r)>>1;
		if(check(mid))r=mid-1;
		else l=mid+1;
	}
	cout<<r;
	return 0;
}

Measured memory_bytes: 384
import java.util.Scanner;
public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int k = sc.nextInt();
    int x = sc.nextInt();
    int y = sc.nextInt();
    int res = 0;
    
    if (n >= k) {
      res += (k * x) + (n - k) * y;
    } else {
      res += (n * x);
    }
    
    System.out.println(res);
  }
}


Measured memory_bytes: 21716
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.math.BigDecimal;

public class Main {

	/* several useful subroutines */
	private static final BigDecimal BD1000000007 = new BigDecimal(1000000007);
	private static BufferedReader brStdin = new BufferedReader(new InputStreamReader(System.in));
	private static String[] readBuf = null;
	private static int readPtr = 0;
	private static String getString() throws IOException {
		while ( readBuf == null || readPtr >= readBuf.length ) {
			readBuf = brStdin.readLine().split(" ");
			readPtr = 0;
		}
		return readBuf[readPtr++];
	}
	private static int getInt() throws IOException {
		return Integer.parseInt(getString());
	}
	private static long getLong() throws IOException {
		return Long.parseLong(getString());
	}
	private static BigDecimal getBD() throws IOException {
		return new BigDecimal(getString());
	}
	@SuppressWarnings("unused")
	private static String[] getStringArray(int size) throws IOException {
		String stringArray[] = new String[size];
		for (int i = 0; i < stringArray.length; i++) {
			stringArray[i] = getString();
		}
		return stringArray;
	}
	@SuppressWarnings("unused")
	private static int[] getIntArray(int size) throws IOException {
		int intArray[] = new int[size];
		for (int i = 0; i < intArray.length; i++) {
			intArray[i] = getInt();
		}
		return intArray;
	}
	@SuppressWarnings("unused")
	private static long[] getLongArray(int size) throws IOException {
		long longArray[] = new long[size];
		for (int i = 0; i < longArray.length; i++) {
			longArray[i] = getLong();
		}
		return longArray;
	}
	@SuppressWarnings("unused")
	private static BigDecimal[] getBDArray(int size) throws IOException {
		BigDecimal bdArray[] = new BigDecimal[size];
		for (int i = 0; i < bdArray.length; i++) {
			bdArray[i] = getBD();
		}
		return bdArray;
	}
	private static BigDecimal mod1000000007(BigDecimal bd) {
		return bd.subtract(BD1000000007.multiply(bd.divide(BD1000000007, BigDecimal.ROUND_DOWN))) ;
	}
	@SuppressWarnings("unused")
	private static BigDecimal mod1000000007(int i) {
		return mod1000000007(new BigDecimal(i)) ;
	}
	@SuppressWarnings("unused")
	private static BigDecimal mod1000000007(long l) {
		return mod1000000007(new BigDecimal(l)) ;
	}

	
	/* main routine */
	public static void main(String args[]) throws IOException {
		int n = getInt();
		int d = getInt();
		int x[][] = new int[n][];
		for ( int i = 0 ; i < n ; i++ ) {
			x[i] = getIntArray(d);
		}
		int c = 0;
		for ( int i = 0 ; i < n-1 ; i++ ) {
			for ( int j = i+1 ; j < n ; j++ ) {
				int dd = 0;
				for ( int k = 0 ; k < d ; k++ ) {
					int s = (x[i][k] - x[j][k]) ;
					dd += s * s ;
				}
				int q = (int)(Math.sqrt(dd)+0.5);
				if ( q*q == dd ) {
					c++ ;
				}
			}
		}
		System.out.println( c ) ;
	}
}


Measured memory_bytes: 25044
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < n; i++)
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    string s;
    cin >> s;
    int n = s.size();
    ll ans = 0;
    for (int i = 0; i < (1 << (n - 1)); i++)
    {
        ll num = 0;
        for (int j = 0; j < n; j++)
        {
            num = num * 10 + (s[j] - '0');
            if ((i >> j) & 1)
            {
                ans += num;
                num = 0;
            }
        }
        ans += num;
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3624
import java.util.*;
public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int k = sc.nextInt();
        sc.close();
        int yono = 0;
        for(int a = 1 ; a <= k ; a++){
            for(int b = 1 ; b <= k ; b++){
                for(int c = 1 ; c <= k ; c++){
                    int s = 1;
                    for(int q = 1 ; q <= Math.min(a , Math.min(b , c)) ; q++){
                        if(a % q == 0 && b % q == 0 && c % q == 0){
                            s = q;
                        }
                    }
                    yono += s;
                }
            }
        }
        System.out.println(yono);
    }
}

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


Measured memory_bytes: 3644
import java.util.Scanner;

//Bombs Chain
public class Main{
	
	static char[][] m;
	static int[][] move = {{0,1},{0,-1},{1,0},{-1,0}};
	
	static void f(int i, int j){
		m[i][j] = '0';
		for(int k=0;k<4;k++){
			for(int l=1;l<=3;l++){
				int ni = i+l*move[k][0];
				int nj = j+l*move[k][1];
				if(0<=ni&&ni<8&&0<=nj&&nj<8&&m[ni][nj]=='1'){
					f(ni,nj);
				}
			}
		}
	}
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int Case = 1;
		int t = sc.nextInt();
		while(t--!=0){
			m = new char[8][8];
			for(int i=0;i<8;i++)m[i]=sc.next().toCharArray();
			int j=sc.nextInt()-1;
			int i=sc.nextInt()-1;
			f(i,j);
			System.out.println("Data " + Case++ + ":");
			for(int k=0;k<8;k++)System.out.println(new String(m[k]));
		}
	}
}

Measured memory_bytes: 12000
/*author: hyperion_1724
  date: 
*/
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>
using namespace std;
using namespace __gnu_pbds;
#define READ(X) cin>>X;
#define READV(X) long long X; cin>>X;
#define READAR(A,N) long long A[N]; for(int i=0;i<N;i++) {cin>>A[i];}
#define rz(A,N) A.resize(N);
#define sz(X) (long long)(X.size())
#define fi first
#define se second
#define endl '\n'
#define trav(x,A) for(auto &x:A)
#define veci vector<int>
#define vecl vector<long long>
#define FORI(a,b,c) for(int a=b;a<c;a++)
#define FORD(a,b,c) for(int a=b;a>c;a--)
typedef tree<long long,null_type,less<long long>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
typedef tree<long long,null_type,greater<long long>,rb_tree_tag,tree_order_statistics_node_update> ordered_set1;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<long,long> pll;
const long long inf=(long long)1e18;
const long long MOD=(long long)(1e9+7);
const long long INIT=(long long)(1e6+1);

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

	READV(N);
	READV(K);
	if (K>((N-2)*(N-1))/2)
	{
		cout<<-1<<endl;
	}
	else
	{
		set<pll> E;
		FORI(i,1,N)
		{
			E.insert({i,N});
		}
		ll cnt=((N-2)*(N-1))/2;
		FORI(i,1,N-1)
		{
			for (int j = i+1; j < N && cnt>K; ++j)
			{
				E.insert({i,j});
				cnt--;
			}
		}
		cout<<sz(E)<<endl;
		for (auto edge:E)
		{
			cout<<edge.fi<<" "<<edge.se<<endl;
		}
	}

	return 0;
}

Measured memory_bytes: 640
using System;
using System.Linq;
class Program
{
    static void Main(string[] args)
    {
        int[] nums = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
        Array.Sort(nums);
        Console.WriteLine(nums[0] + nums[1] == nums[2] ? "Yes" : "No");
    }
}


Measured memory_bytes: 13268
#include<bits/stdc++.h>
#include<iostream>
#include<string>
#include<cmath>
#include<cstdio>
#include<cctype>
#include<cstring>
#include<iomanip>
#include<cstdlib>
#include<ctime>
#include<set>
#include<map>
#include<utility>
#include<queue>
#include<vector>
#include<stack>
#include<sstream>
#include<algorithm>
/************************************************/
#define rep(i,n) for(int i=0;i<n;i++)
#define m_p make_pair
#define pb push_back
#define fr first
#define se second
#define forn(i,a,n) for(int i=a;i<n;i++)
#define foreach(i,c) for(__typeof(c.begin())i=(c.begin());i!=(c).end();i++)
#define pii pair<int,int>
#define vi vector<int>
#define ll long long
#define sz(s) s.size()
#define all(s) s.begin(),s.end()
#define zero(x) memset(x,0,sizeof(x))
#define vii vector<pair<int,int> >
#define mpis map<int,string>
#define mpii map<int,int>
#define mpsi map<string,int>
#define re return
#define mod 1000000007
/************************************************/
using namespace std;

long long get(){
	char c=getchar();
	long long x=0LL;
	while(c<'0'||c>'9')
	c=getchar();
	while(c>='0'&&c<='9'){
		x*=10LL;
		x+=(c-'0');
		c=getchar();
	}
	return x;
}
int n,r;
int main(){
	ios::sync_with_stdio(0);
	cin>>n>>r;
	if(n<10)
	cout<<r+(10-n)*100;
	else
	cout<<r;
	re 0;
}


Measured memory_bytes: 256
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)

import heapq

def main():
  n = int(input())
  T = [[] for _ in range(n)]
  for i in range(1, n):
    a = int(input())
    a -= 1
    T[a].append(i)

  def dfs(v):
    if not T[v]:
      return 0
    L = []
    for i in T[v]:
      heapq.heappush(L, dfs(i)+1)
    temp = heapq.heappop(L)
    for _ in range(len(T[v])-1):
      temp = max(temp+1, heapq.heappop(L))
    return temp

  ans = dfs(0)
  print(ans)
  
if __name__ == "__main__":
  main()

Measured memory_bytes: 131496