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

#define rep(i,n) for(int i=0;i<n;i++)
#define ck(a) (0<=(a)&&(a)<9)

int di[]={-3, -1, 1, 3};

int main() {
  using namespace std;
  
  int n, s, t, b; char cs, ct, cb;
  while((cin>>n),n) {
    cin >> cs >> ct >> cb;
    s = cs-'A'; t = ct-'A'; b = cb-'A';
    // 確率漸化式（添字は場所に対応。漸化式はqを用いることによって更新される）
    double p[9]={0}; p[s]=1;

    while(n--) {
      double q[9]={0};
      rep(i,9)rep(d,4) {
	if(ck(i+di[d])&&!(i%3==0&&di[d]==-1)&&!(i%3==2&&di[d]==1)&&i+di[d]!=b)
	  q[i+di[d]]+=p[i]/4;
	else q[i]+=p[i]/4;
      }
      rep(i,9)p[i]=q[i]; // 最新データに更新
    }
    printf("%.8f\n", p[t]);
  }
  return 0;
}

Measured memory_bytes: 1188
use input::Input;

fn main() {
    let mut input = Input::default();

    let s = input.parse::<String>();
    let t = input.parse::<String>();

    let mut ans = 0u32;
    for (a, b) in s.chars().zip(t.chars()) {
        if a != b {
            ans += 1;
        }
    }
    println!("{}", ans);
}

#[allow(dead_code)]
pub mod input {
    #[derive(Default)]
    pub struct Input(Vec<String>);

    impl Input {
        pub fn read_line(&mut self) -> String {
            let mut s = String::new();
            std::io::stdin().read_line(&mut s).ok().expect("read error");
            s
        }
        pub fn parse<T: std::str::FromStr>(&mut self) -> T {
            let x = if let Some(x) = self.0.pop() {
                x
            } else {
                let s = self.read_line();
                self.0 = s.split_whitespace().map(String::from).rev().collect();
                self.0.pop().expect("reached EOF")
            };
            x.parse().ok().expect("parse error")
        }
    }
}


Measured memory_bytes: 2744
#include <bits/stdc++.h>
using namespace std;
#define int long long

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

  int n;
  cin >> n;
  vector<int> ve(n);

  for (long long &i : ve) {
    cin >> i;

  }
  int ans = INT_MAX;
  int t;
  for (int i = -100; i <= 100; i++) {
    t = 0;
    for (long long j : ve) {
      t += pow((j - i), 2);
    }
    ans = min(ans, t);
  }
  cout << ans << endl;
  return 0;

}

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


int main()
{
	int n, minv, maxv;
	long long sumv;
	cin >> n;
	int A[n];	
	for (int i = 0; i < n; i++)
		cin >> A[i];
	minv = maxv = A[0];
	sumv = 0;
	for (int i = 0; i < n; i++)
	{
		if (A[i] < minv)
			minv = A[i];
		if (A[i] > maxv)
			maxv = A[i];
		sumv += A[i];
	}
	cout << minv << " " << maxv << " " << sumv << endl;
	return 0;
}




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

int main(){

 int n,x,t,r,p,result;
 cin>>n>>x>>t;
 r=n/x;
 p=n%x;
 result=t*r;
 if(p==0){
    cout<<result;

    return 0;
 }

 else if(p<x){
    result=result+t;
 }
 else{
    result=result+t+t;
 }

 cout<<result;

}


Measured memory_bytes: 3632
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		
		Scanner sc = new Scanner(System.in);
		
		int n = sc.nextInt();
		int[] rate = new int[n];
		
		for(int i = 0; i < n; i++) {
			rate[i] = sc.nextInt();
		}
		
		sc.close();
		
		int low = rate[0];
		int max = Integer.MIN_VALUE;
		for(int i = 1; i< n; i++) {
			max = Math.max(max, rate[i] - low);
			low = Math.min(low, rate[i]);
		}
		
		System.out.println(max);
		
	}
}

Measured memory_bytes: 101528
#include <iostream>
#include <string>
#include <vector>
#include <stdio.h>
#include <algorithm>
#define _USE_MATH_DEFINES
#include <cmath>
#include <numeric>
#include <iomanip>
#include <deque>
#include <tuple>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <cstdint>
#include <unordered_map>
#include <sstream>
#include <boost/multiprecision/cpp_int.hpp>

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define all(x) (x).begin(), (x).end()
#define F first
#define S second
#define pb push_back
#define pf push_front

namespace mp = boost::multiprecision;
using cpp_int = mp::cpp_int;
using ll = long long;
using namespace std;

ll M = 1000000007;

typedef pair<int, int> P;
bool sr(ll a,ll b){
	return a>b;
}
bool ps1(const P &element1, const P &element2)
{ //first昇順
	return element1.first < element2.first;
}
bool ps2(const P &element1, const P &element2)
{ //first降順
	return element1.first > element2.first;
}
bool ps3(const P &element1, const P &element2)
{ //second昇順
	return element1.second < element2.second;
}
bool ps4(const P &element1, const P &element2)
{ //second降順
	return element1.second > element2.second;
}

template <class T>
void print(const T &value)
{
	std::cout << value << std::endl;
}

int main()
{
	ll a,b,c,k;
	cin>>a>>b>>c>>k;
	int exp=0;
	if(k%2==0){

	}else{
		exp=1;
	}
	ll dis=a-b;
	dis=dis*pow(-1,exp);
	if(abs(dis)>1e18){
		cout<<"Unfair"<<endl;
	}else{
		cout<<dis<<endl;
	}
}


Measured memory_bytes: 256
use text_io::*;

fn main() {
    let n: usize = read!();
    println!("{}",
             match n % 10 {
                 2 | 4 | 5 | 7 | 9 => "hon",
                 0 | 1 | 6 | 8 => "pon",
                 3 => "bon",
                 _ => panic!("10進数が壊れた")
             })
}


Measured memory_bytes: 2112
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
	while(1){
		int N=0;
		int k[10001];
		int M=0;
		int cun=0;
		cin>>N;
		if(N==0){
			break;
		}
		for(int i=0;i<N;i++){
			cin>>k[i];
			if(k[i]==0){
				cun++;
			}
		}
		
		for(int i=0;i<N;i++){
			if(k[i]>1){
				M=1;
			}
		}

		
		
		if(M==0){
			cout<<"NA"<<endl;
		}
		else if((N==1)&&(M==0)){
			cout<<"NA"<<endl;
		}
		else{
			cout<<N-cun+1<<endl;
		}
	}
	return 0;
}
	

Measured memory_bytes: 1200
program name
    use,intrinsic :: iso_fortran_env
    implicit none
    integer(int32):: n,m,i,j,dst,ans
    integer(int32), allocatable:: a(:),b(:),c(:),d(:)

    read*, n,m
    allocate(a(n), b(n),c(m),d(m))

    do i=1,n
        read*, a(i),b(i)
    end do
    do i=1,m
        read*, c(i),d(i)
    end do

    do i=1,n
        dst=1000000000
        do j=1,m
            if (abs(a(i)-c(j))+abs(b(i)-d(j))  < dst) then
                ans=j
                dst = abs(a(i)-c(j))+abs(b(i)-d(j))
            end if
        end do
        print*, ans
    end do
end program name

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

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

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> P;
typedef long long ll;

#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define SORT(c) sort((c).begin(),(c).end())
#define REVERSE(c) reverse((c).begin(),(c).end())

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

const double EPS = 1e-10;
const double PI  = acos(-1.0);
const int INT_INF = 2147483647;
const long long LL_INF = 1LL<<60;
const long long MOD = 1000000007;

#define CLR(a) memset((a), 0 ,sizeof(a))

#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

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; }

int main(void){
    int N; cin >> N;
    VI A(N); REP(i,N) cin >> A[i];
    REP(i,N){
        if(A[i]%2 == 0){
            if(A[i]%3 && A[i]%5){
                cout << "DENIED" << endl;
                return 0;
            }
        }
    }
    cout << "APPROVED" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#define rep(i, n) for(int i = 0; i < (int)(n); ++i)
#define REP(i, n) for(int i = 1; i < (int)(n); ++i)
using namespace std;

int main() {
    int N, M, X;
    cin >> N >> M >> X;
    vector<int> A(M);
    rep(i, M) cin >> A[i];
    
    int ans = 1000000000;
    int cnt = 0;
    for (int i = X; i >= 0; --i) {
        if (count(A.begin(), A.end(), i)) ++cnt;
    }
    ans = min(cnt, ans);
    cnt = 0;
    for (int i = X; i <= N; ++i) {
        if (count(A.begin(), A.end(), i)) ++cnt;
    }
    ans = min(ans, cnt);
    
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.Comparator;
import java.util.Objects;
import java.util.PriorityQueue;
import java.util.StringTokenizer;
import java.util.stream.Collectors;

public class Main {

	public static void main(String args[]) {
		ConsoleScanner cin = new ConsoleScanner();
		PrintWriter cout = new PrintWriter(System.out);
		solve(cin, cout);
		cout.flush();
	}

	static long now() {
		return System.currentTimeMillis();
	}

	static void trace(Object... objects) {
		assert null != System.out.format("trace:%s\n", Arrays.deepToString(objects));
	}

	private static void solve(ConsoleScanner cin, PrintWriter cout) {
		// assert solve(1) == 1;
		int n = cin.nextInt();
		int[][] abcs = new int[n - 1][];
		for (int i = 0; i < abcs.length; i++)
			abcs[i] = new int[] { cin.nextInt(), cin.nextInt(), cin.nextInt() };
		int q = cin.nextInt();
		int k = cin.nextInt();
		int[][] xys = new int[q][];
		for (int i = 0; i < xys.length; i++)
			xys[i] = new int[] { cin.nextInt(), cin.nextInt() };

		long start = now();

		long[] ans = solve(n, abcs, q, k, xys);
		String ansstr = Arrays.stream(ans).mapToObj(Objects::toString)
				.collect(Collectors.joining(System.lineSeparator()));

		cout.println(ansstr);
		trace("elapsed", now() - start);
	}

	private static long[] solve(int n, int[][] abcs, int q, int k, int[][] xys) {
		int[] elen = new int[n + 1];
		for (int[] abc : abcs) {
			elen[abc[0]] += 1;
			elen[abc[1]] += 1;
		}
		int[][][] edges = new int[n + 1][][];
		for (int i = 1; i <= n; i++)
			edges[i] = new int[elen[i]][];
		for (int[] abc : abcs) {
			edges[abc[0]][--elen[abc[0]]] = new int[] { abc[1], abc[2] };
			edges[abc[1]][--elen[abc[1]]] = new int[] { abc[0], abc[2] };
		}

		// 始点Kからの最短経路
		// ダイクストラ法
		long[] dist = new long[n + 1];
		Arrays.fill(dist, -1L);
		PriorityQueue<long[]> pq = new PriorityQueue<>(Comparator.comparingLong(vals -> vals[1]));
		pq.add(new long[] { k, 0 });
		while (!pq.isEmpty()) {
			long[] arg = pq.poll();
			int v = (int) arg[0];
			long c = arg[1];
			if (dist[v] != -1)
				continue;
			dist[v] = c;
			for (int[] e : edges[v]) {
				int to = e[0];
				if (dist[to] != -1)
					continue;
				pq.add(new long[] { to, c + e[1] });
			}
		}

		long[] ans = Arrays.stream(xys).mapToLong(xy -> dist[xy[0]] + dist[xy[1]]).toArray();
		return ans;
	}

	static class ConsoleScanner {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st = new StringTokenizer("");

		String next() {
			try {
				while (!st.hasMoreElements())
					st = new StringTokenizer(br.readLine());
				return st.nextToken();
			} catch (IOException e) {
				throw new AssertionError(e);
			}
		}

		int nextInt() {
			return Integer.parseInt(next());
		}

		long nextLong() {
			return Long.parseLong(next());
		}
	}

}


Measured memory_bytes: 76304
from decimal import Decimal 

N = int(input())

H = list(input().split())

H = [int(s) for s in H]

record = 0
counter = 0



for i in range(N-1):
	if H[i] >= H[i+1]:
		
		counter += 1
	if H[i] < H[i+1]:
		
		if record < counter:
			record = counter
		counter = 0
	

if record < counter:
			record = counter
		
print(record)		


Measured memory_bytes: 85868
#include <bits/stdc++.h>
using namespace std;
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; }
using ll = long long;
using P = pair<ll, ll>;
const long double PI = acos(-1.0L);
ll GCD(ll a, ll b) { return b?GCD(b, a%b):a; }
ll LCM(ll a, ll b) { return a/GCD(a, b)*b; }

// auto mod int
const int mod = 1000000007;
// const int mod = 998244353;
struct mint {
    ll x; // typedef long long ll;
    mint(ll x=0):x((x%mod+mod)%mod){}
    mint operator-() const { return mint(-x);}
    mint& operator+=(const mint a) {
      if ((x += a.x) >= mod) x -= mod;
      return *this;
    }
    mint& operator-=(const mint a) {
      if ((x += mod-a.x) >= mod) x -= mod;
      return *this;
    }
    mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
    mint operator+(const mint a) const { return mint(*this) += a;}
    mint operator-(const mint a) const { return mint(*this) -= a;}
    mint operator*(const mint a) const { return mint(*this) *= a;}
    mint pow(ll t) const {
      if (!t) return 1;
      mint a = pow(t>>1);
      a *= a;
      if (t&1) a *= *this;
      return a;
    }

    // for prime mod
    mint inv() const { return pow(mod-2);}
    mint& operator/=(const mint a) { return *this *= a.inv();}
    mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}

// combination mod prime
// mintと併用
struct combination {
  vector<mint> fact, ifact;
  combination(int n):fact(n+1),ifact(n+1) {
    assert(n < mod);
    fact[0] = 1;
    for (int i = 1; i <= n; ++i) fact[i] = fact[i-1]*i;
    ifact[n] = fact[n].inv();
    for (int i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i;
  }
  mint operator()(int n, int k) {
    if (k < 0 || k > n) return 0;
    return fact[n]*ifact[k]*ifact[n-k];
  }
  mint p(int n, int k) {
    return fact[n]*ifact[n-k];
  }
} comb(1000005);

int n, k;
vector< vector<int> > G(100100, vector<int>());
mint ans;

void dfs(int v, int p = -1) {
    for(int to : G[v]) {
        if(to == p) continue;
        dfs(to, v);
    }
    int nk = (p==-1) ? k : max(0, k-2);     // 親の場合はk色
    int c = (p==-1) ? G[v].size()+1 : G[v].size()-1;    // 親の場合は自分も含めて
    if(nk < c) ans *= 0;
    else ans *= comb.p(nk, c);
}

int main() {
    cin >> n >> k;
    for(int i = 0; i < n-1; ++i) {
        int a, b; cin >> a >> b;
        a--; b--;
        G[a].emplace_back(b);
        G[b].emplace_back(a);
    }
    ans = 1;
    dfs(0);
    cout << ans << endl;
}

Measured memory_bytes: 27660
using System;
using System.Collections.Generic;

public class Program
{
    public static void Main()
    {
        Queue<char>[] p = new Queue<char>[3];
        for (int i = 0; i < 3; i++)
        {
            p[i] = new Queue<char>();
            foreach (var c in Console.ReadLine().ToCharArray())
            {
                p[i].Enqueue(c);
            }
        }

        char player = 'a';
        while (true)
        {
            if (p[player - 'a'].Count == 0)
            {
                Console.Write(player.ToString().ToUpper());
                break;
            }
            player = p[player - 'a'].Dequeue();
        }
    }
}


Measured memory_bytes: 2776
#include<stdio.h>
int main()
{
	int a,b,i;
	scanf("%d%d",&a,&b);
	if(a<b)
	for(i=1;i<=b;i++)
	{
		printf("%d",a);
	}
	else
	for(i=1;i<=a;i++)
	{
		printf("%d",b);
	}
	return 0;
}

Measured memory_bytes: 128
s=input()

if 0 < int(s[:2]) < 13:
  if 0 < int(s[2:]) < 13:
    print("AMBIGUOUS")
  else:
    print("MMYY")
else:
  if 0 < int(s[2:]) < 13:
    print("YYMM")
  else:
    print("NA")

Measured memory_bytes: 2940
import java.util.*;

public class Main {
	int[][] mapz;
	int[][] map;
	int[] d;
	int[] ans;
	int n, t, f, x, y;
	
	void init(){
		d[0] = 1;
		d[1] = 6;
		d[2] = 3;
		d[3] = 5;
		d[4] = 4;
		d[5] = 2;
		
		if(t==2){
			TR();
		}else if(t==3){
			TF();TF();TF();
		}else if(t==4){
			TF();
		}else if(t==5){
			TR();TR();TR();
		}else if(t==6){
			TF();TF();
		}
		
		while(d[2]!=f) FR();
	}
	
	void TF(){
		int dd = d[0];
		d[0] = d[4];
		d[4] = d[1];
		d[1] = d[2];
		d[2] = dd;
	}
	
	void TR(){
		int dd = d[0];
		d[0] = d[5];
		d[5] = d[1];
		d[1] = d[3];
		d[3] = dd;
	}
	
	void FR(){
		int dd = d[2];
		d[2] = d[5];
		d[5] = d[4];
		d[4] = d[3];
		d[3] = dd;
	}
	
	void func(){
		while(true){
			boolean flag = false;
			for(int i=6;i>=4;i--){
				for(int j=2;j<6;j++){
					if(d[j]==i){
						if(j==2 && mapz[y][x]>mapz[y+1][x]){
							TF();
							y++;
							flag = true;
						}else if(j==3 && mapz[y][x]>mapz[y][x+1]){
							TR();
							x++;
							flag = true;
						}else if(j==4 && mapz[y][x]>mapz[y-1][x]){
							TF();TF();TF();
							y--;
							flag = true;
						}else if(j==5 && mapz[y][x]>mapz[y][x-1]){
							TR();TR();TR();
							x--;
							flag = true;
						}
					}
					if(flag==true){
						i = 0;
						j = 7;
					}
				}	
			}
			if(flag==false){
				ans[map[y][x]]--;
				ans[d[0]]++;
				map[y][x] = d[0];
				mapz[y][x]++;
				break;
			}
		}
	}
	
	void solve(){
		Scanner sc = new Scanner(System.in);
		
		while(true){
			n = sc.nextInt();
			if(n==0) break;
			
			mapz = new int[2*n+1][2*n+1];
			map = new int[2*n+1][2*n+1];
			d = new int[6];
			ans = new int[7];
			for(int i=0;i<n;i++){
				t = sc.nextInt();
				f = sc.nextInt();
				x = n;
				y = n;
				init();
				func();
			}
			for(int i=1;i<=6;i++){
				if(i!=1) System.out.print(" ");
				System.out.print(ans[i]);
			}
			System.out.println();
		}	
	}
	
	
	public static void main(String[] args) {
		new Main().solve();
	}	
}

Measured memory_bytes: 36428
import java.util.Arrays;
import java.util.Scanner;
public class Main
{
	public static void main(String arg[])
	{
		Scanner in=new Scanner(System.in);
		while(in.hasNext())
		{
			boolean bl=false;
			int n=in.nextInt();
			if(n==0)
				return;
			int a[]=new int[n];
			long b[]=new long[n];
			for(int i=0;i<n;i++)
			{
				a[i]=in.nextInt();
				b[i]=in.nextLong()*in.nextLong();
			}
			boolean ju[]=new boolean[n];
			Arrays.fill(ju, true);
			for(int i=0;i<n;i++)
			{
				for(int j=i+1;j<n;j++)
					if(a[i]==a[j]&&ju[j])
					{
						b[i]=b[i]+b[j];
						ju[j]=false;
					}
			}
			for(int i=0;i<n;i++)
			{
				if(b[i]>=1000000&&ju[i])
				{
					System.out.println(a[i]);
					bl=true;
				}
			}
			if(!bl)
				System.out.println("NA");
		}
	}

}

Measured memory_bytes: 12000
import java.util.*;

public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int a = Integer.parseInt(sc.next());
        int b = Integer.parseInt(sc.next());
        int[] arr = new int[]{a+b, a-b, a*b};
        Arrays.sort(arr);
        System.out.println(arr[2]);
    }
}

Measured memory_bytes: 22612
#include<cstdio>

int Lose[110], Back[110], N;

int getsquare(int ps, int roll){
	int a = ps + roll;
	if(a > N)
		a = N * 2 - a;
	return a * Back[a];
}

int main(void){
	int T, L, B, i, j, k, l, s;
	while(scanf("%d", &N), N != 0){
		scanf("%d %d %d" ,&T, &L, &B);
		for(i = 0;i <= N;i++)
			Lose[i] = 0;
		for(i = 0;i < L;i++){
			scanf("%d", &k);
			Lose[k] = 1;
		}
		for(i = 0;i <= N;i++)
			Back[i] = 1;
		for(i = 0;i < B;i++){
			scanf("%d", &k);
			Back[k] = 0;
		}
		double P[N+1][T+2];
		for(i = 0;i <= T+1;i++){
			for(j = 0;j < N;j++)
				P[j][i] = 0;
		}/* ????????? */
		for(i = 1;i <= T+1;i++)
			P[N][i] = 1;
		for(i = 1;i <= T;i++){
			for(j = 0;j < N;j++){
				for(l = 1;l <= 6;l++){
					s = getsquare(j, l);
					P[j][i+1] += P[s][i - Lose[s]];
				}
				P[j][i+1] /= 6;
			}
		}
		printf("%f\n", P[0][T+1]);
	}
	return 0;
}

Measured memory_bytes: 2688
q=int(input())
from heapq import heappush,heappop,heapify
l=[]
r=[]
sl=0
sr=0
sb=0
for i in range(q):
    Q=input().split()
    if len(Q)==1:
        x=-l[0]
        print(x,x*len(l)-sl+sr-len(r)*x+sb)
        continue
    a,b=int(Q[1]),int(Q[2])
    sb+=b
    if len(l)>len(r):
        heappush(r,a)
        sr+=a
    else:
        heappush(l,-a)
        sl+=a
    try:
        if r[0]<-l[0]:
            x,y=heappop(r),-heappop(l)
            heappush(r,y)
            sr+=y-x
            heappush(l,-x)
            sl+=x-y
    except:
        pass


Measured memory_bytes: 11136
#ifdef DEBUG

#else

#    pragma GCC optimize("O3,no-stack-protector")
#    pragma GCC optimize("unroll-loops")

#    if __cplusplus < 201703L
#        pragma GCC target("avx")
#    else
#        pragma GCC target("avx2")
#    endif

#endif
// 実数の場合
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define dump(x) cout << x << endl
typedef int64_t Int;
typedef long double Ld;

using namespace std;
using Graph = vector<vector<Int>>;

const double pi = M_PI;
const Int MOD = 1000000007;

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

    int n;
    cin >> n;
    vector<int> nt, t;
    for (int i = 0; i < n; i++) {
        int in;
        cin >> in;

        if (in % 10 == 0) {
            t.push_back(in);
        } else {
            nt.push_back(in);
        }
    }

    int ans = accumulate(nt.begin(), nt.end(), 0);
    if (nt.size() != 0 && ans % 10 == 0) {
        sort(nt.begin(), nt.end());
        ans -= nt[0];
        ans += accumulate(t.begin(), t.end(), 0);
    } else if (nt.size() != 0) {
        ans += accumulate(t.begin(), t.end(), 0);
    } else {
        ans = 0;
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include<cstdio>

using namespace std;

int l[100100],c,n,k,i,j;

int main(){
    scanf("%d %d",&n,&k);
    for(i=0;i<n;i++){
        scanf("%d",&l[i]);
    }
    for(i=1;i<n;i++){
        if(l[i]+l[i-1]>=k)break;
    }
    if(i==n){
        printf("Impossible\n");
        return 0;
    }
    printf("Possible\n");
    for(j=1;j<i;j++)printf("%d\n",j);
    for(j=n-1;j>=i;j--)printf("%d\n",j);
}

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

#define BUF_SIZE 500
int main(void) {
  FILE *fp = stdin;
  char line[BUF_SIZE];
  if(!fgets(line, BUF_SIZE, fp)) return 0;
  int num;
  sscanf(line, "%d", &num);

  int i;
  int *arr1 = malloc(sizeof(int)*num);
  int *cum1 = malloc(sizeof(int)*num);
  if(!fgets(line, BUF_SIZE, fp)) return 0;
  char *tmpbuf = line;
  for(i = 0; i < num; i++) {
    char *tmp = strtok(tmpbuf, " ");
    arr1[i] = strtol(tmp, NULL, 10);
    tmpbuf = NULL;
  }

  int *arr2 = malloc(sizeof(int)*num);
  int *cum2 = malloc(sizeof(int)*num);
  if(!fgets(line, BUF_SIZE, fp)) return 0;
  tmpbuf = line;
  for(i = 0; i < num; i++) {
    char *tmp = strtok(tmpbuf, " ");
    arr2[i] = strtol(tmp, NULL, 10);
    tmpbuf = NULL;
  }

  // calc sum
  cum1[0] = arr1[0];
  for(i = 1; i < num; i++) {
    cum1[i] += cum1[i-1] + arr1[i];
  }
  cum2[num-1] = arr2[num-1];
  for(i = num-2; i >= 0; i--) {
    cum2[i] = cum2[i+1] + arr2[i];
  }

  int max = 0;
  for(i = 0; i < num; i++) {
    int sum = cum1[i] + cum2[i];
    if(sum > max) max = sum;
  }
  printf("%d\n", max);
  return 0;
}

Measured memory_bytes: 128
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		long l = sc.nextInt();
		long r = sc.nextInt();
		long min = 2018;
		for (long i = l; i < r; i++) {

			for (long j = i + 1; j <= r; j++) {
				if (min == 0)
					break;
				if (i * j % 2019 < min)
					min = i * j % 2019;
				if (min == 0)
					break;
			}
		}

		System.out.println(min);
	}
}


Measured memory_bytes: 23892
#define _USE_MATH_DEFINES
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <cstdio>
#include <complex>
#include <numeric>
#include <string.h>
#include <random>
#include <cmath>
#include <unordered_map>
#include <unordered_set>
#include <chrono>
#include <cassert>
#define rep(i,n) for (ll i = 0; i < (ll)n; i++)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pi;
typedef pair<pi, pi> pp;
typedef pair<ll, ll> pl;
double PI = 3.141592653589793238462643383279;
const double EPS = 1e-9;
const ll MOD = 1000000007;
//const ll MOD = 998244353;
const int inf = 1 << 30;
const ll linf = 1LL << 60;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

struct CONBINATION {
    vector<ll> kai, mokai;

    ll mod_pow (ll x, ll y) {
        ll ret = 1;
        while (y) {
            if (y&1) ret = ret*x%MOD;
            x = x*x%MOD;
            y /= 2;
        }
        return ret;
    }

    void init (int _n) {
        kai.assign(_n+1, 0);
        mokai.assign(_n+1, 0);
        kai[0] = 1;
        for (int i = 1; i <= _n; i++) kai[i] = kai[i-1]*i%MOD;
        for (int i = 0; i <= _n; i++) mokai[i] = mod_pow(kai[i],MOD-2);
    }

    ll conb (ll x, ll y) {
        ll z = x-y;
        ll ret = kai[x]*mokai[y]%MOD;
        ret = ret*mokai[z]%MOD;
        return ret;
    }
};

int b[1000000];
int a[1000000];
int p2[1000001];
int ps2[1000001];

int main() {
    p2[0] = 0;
    for (int i = 1; i <= 1000000; i++) {
        if (i%2) p2[i] = 0;
        else p2[i] = p2[i/2] + 1;
    }
    ps2[0] = 0;
    for (int i = 1; i <= 1000000; i++) {
        ps2[i] = ps2[i-1]+p2[i];
    }
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    rep(i,n) {
        char c; cin >> c;
        b[i] = c-'0';
    }
    rep(i,n-1) a[i] = abs(b[i]-b[i+1]);
    n--;

    bool two = false, one = false;;
    rep(i,n) {
        if (a[i] == 2) two = true;
        if (a[i] == 1) one = true;
    }
    if (one == true) {
        rep(i,n) a[i] %= 2;
    }
    rep(i,n) if (a[i] == 2) a[i] = 1;
    ll ans = 0;
    rep(i,n) {
        int cnt = ps2[n-1] - ps2[i] - ps2[n-1-i];
        if (cnt == 0) ans = (ans + a[i]) % 2;
    }
    if (one) cout << ans << endl;
    else cout << ans*2 << endl;
}

Measured memory_bytes: 15872
#include <iostream>
#include <cstdio>
using namespace std;
int main(){
  int N, K, T, U, V, L;
  cin >> N >> K >> T >> U >> V >> L;
  int D[N];
  for(int i = 0; i < N; ++i)
    cin >> D[i];
  int t = 0, s = 0, r = 0, f = 0;
  for(int i = 0; i <= L; ++i){
    if(r > 0){
      ++f;
      --r;
    }
    if(t < N && D[t] == i){
      ++t;
      ++s;
    }
    if((r == 0 && s > 0) || s > K){
      r = T*V;
      --s;
    }
  }
  printf("%.10f\n",(double)f/V + (double)(L-f)/U);
  return 0;
}

Measured memory_bytes: 3208
/*  -*- coding: utf-8 -*-
 *
 * 1611.cc: Daruma Otoshi
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

const int MAX_N = 300;

/* typedef */

/* global variables */

int as[MAX_N];
bool bls[MAX_N][MAX_N + 1];
int dp[MAX_N + 1];

/* subroutines */

inline void setmax(int &a, int b) { if (a < b) a = b; }

/* main */

int main() {
  for (int n; scanf("%d", &n) > 0 && n > 0;) {
    for (int i = 0; i < n; i++) scanf("%d", as + i);

    memset(bls, false, sizeof(bls));
    for (int i = 0; i < n; i++) bls[i][i] = true;

    int maxl = 0;
    for (int l = 2; l <= n; l += 2) {
      for (int i = 0, j = l; j <= n; i++, j++) {
	if (bls[i + 1][j - 1] && abs(as[j - 1] - as[i]) <= 1)
	  bls[i][j] = true, maxl = l;
	else
	  for (int k = i + 2; k < j; k += 2)
	    if (bls[i][k] && bls[k][j]) {
	      bls[i][j] = true, maxl = l;
	      break;
	    }
	//if (bls[i][j]) printf("(%d,%d)", i, j);
      }
      //putchar('\n');
    }

    memset(dp, -1, sizeof(dp));
    dp[0] = 0;

    for (int i = 0; i < n; i++) {
      setmax(dp[i + 1], dp[i]);
      for (int j = i + 2; j <= n; j += 2)
	if (bls[i][j])
	  setmax(dp[j], dp[i] + (j - i));
    }

    printf("%d\n", dp[n]);
  }
  return 0;
}



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

const int N = 1e5+5;
int n;
vector<int> g[N];
vector<int> d;

void dfs(int x,int p,int dd){
    d[x] = dd;
    for(int to:g[x]){
        if(to == p)continue;
        dfs(to,x,dd+1);
    }
}

vector<int> dist(int x){
    d = vector<int>(n);
    dfs(x,-1,0);
    return d;
}

int main(){
    int u,v;
    cin>>n>>u>>v;
    --v,--u;
    for(int i = 0; i < n-1; i++){
        int a,b;cin>>a>>b;
        --a,--b;
        g[a].push_back(b);
        g[b].push_back(a);
    }
    vector<int> d1 = dist(u);
    vector<int> d2 = dist(v);
    
    int ans = 0;
    for(int i = 0; i < n; i++){
        if(d1[i]<d2[i]){
            ans = max(ans,d2[i]);
        }
    }
    cout<<ans-1;

}


Measured memory_bytes: 10744
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define per(i, n) for (int i = (int)(n-1); i >= 0; i--)
#define sz(x) int(x.size())
#define all(x) (x).begin(), (x).end()
#define INF 2e9
#define LINF 1e18
typedef long long ll;
typedef pair<int, int> P;

int main() {
    int n; cin >> n;
    vector<int> a(n);
    int cntm = 0, cntp = 0;
    rep(i, n) {
        int x; cin >> x;
        x -= i+1;
        a[i] = x;
    }
    sort(all(a));
    int b = a[(n-1)/2];
    ll ans = 0;
    rep(i, n) {
        ans += abs(a[i]-b);
    }
    cout << ans << endl;

}


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

#define MOD 1000000007
typedef int64_t s64;

int ri() {
	int n;
	scanf("%d", &n);
	return n;
}
s64 rs64() {
	s64 n;
	scanf("%" SCNd64, &n);
	return n;
}

int main() {
	size_t n = ri();
	s64 x = rs64();
	s64 y = rs64();
	std::vector<s64> a(n);
	for (size_t i = 0; i < n; i++) a[i] = rs64();
	
	std::vector<int> dp1(n + 1); // next separation x
	std::vector<int> dp2(n + 1); // next separation y
	
	std::vector<size_t> x_ng;
	std::vector<size_t> y_ng;
	for (size_t i = 0; i + 1 < n; i++) {
		if (a[i + 1] - a[i] < x) x_ng.push_back(i);
		if (a[i + 1] - a[i] < y) y_ng.push_back(i);
	}
	x_ng.push_back(n - 1);
	y_ng.push_back(n - 1);
	int x_ng_head = 0;
	int y_ng_head = 0;
	
	int dp1_sum = 0;
	int dp2_sum = 0;
	for (size_t i = 0; i < n; i++) {
		dp1_sum += dp1[i];
		dp2_sum += dp2[i];
		if (dp1_sum >= MOD) dp1_sum -= MOD;
		if (dp2_sum >= MOD) dp2_sum -= MOD;
		int dp1_cur = dp1_sum;
		if (!i) dp1_cur = 1;
		int dp2_cur = dp2_sum;
		if (!i) dp2_cur = 1;
		
		size_t to_dp2_start = i + 1;
		if (i) to_dp2_start = std::max<size_t>(to_dp2_start, std::lower_bound(a.begin(), a.end(), a[i - 1] + y) - a.begin());
		size_t to_dp2_end = x_ng[x_ng_head] + 2;
		// std::cerr << "dp1 => dp2 : [" << to_dp2_start << ", " << to_dp2_end << ")" << std::endl;
		if (to_dp2_end <= i + 2) x_ng_head++;
		if (to_dp2_start <= n && to_dp2_end > to_dp2_start) {
			dp2[to_dp2_start] += dp1_cur;
			if (dp2[to_dp2_start] >= MOD)
				dp2[to_dp2_start] -= MOD;
			if (to_dp2_end <= n) {
				dp2[to_dp2_end] -= dp1_cur;
				if (dp2[to_dp2_end] < 0) dp2[to_dp2_end] += MOD;
			}
		}
		
		size_t to_dp1_start = i + 1;
		if (i) to_dp1_start = std::max<size_t>(to_dp1_start, std::lower_bound(a.begin(), a.end(), a[i - 1] + x) - a.begin());
		size_t to_dp1_end = y_ng[y_ng_head] + 2;
		// std::cerr << "dp2 => dp1 : [" << to_dp1_start << ", " << to_dp1_end << ")" << std::endl;
		if (to_dp1_end <= i + 2) y_ng_head++;
		if (to_dp1_start <= n && to_dp1_end > to_dp1_start) {
			dp1[to_dp1_start] += dp2_cur;
			if (dp1[to_dp1_start] >= MOD)
				dp1[to_dp1_start] -= MOD;
			if (to_dp1_end <= n) {
				dp1[to_dp1_end] -= dp2_cur;
				if (dp1[to_dp1_end] < 0) dp1[to_dp1_end] += MOD;
			}
		}
	}
	
	int r0 = (dp1_sum + dp1.back()) % MOD;
	int r1 = (dp2_sum + dp2.back()) % MOD;
	int res = (r0 + r1) % MOD;
	std::cout << res << std::endl;
	
	return 0;
}


Measured memory_bytes: 3824
#include <cstdint>
#include <cstdio>
using namespace std;
#define rep(i, n) for (register uint_fast32_t i = 0; i < (n); ++i)
inline char tc() {
    static char fl[100], *A = fl, *B = fl;
    return A == B && (B = (A = fl) + fread(fl, 1, 100, stdin), A == B) ? EOF
                                                                       : *A++;
}
inline uint_fast32_t read() {
    uint_fast32_t a = 0;
    static char c;
    c = tc();
    while (c & 16) a = a * 10 + c - 48, c = tc();
    return a;
}
uint_fast32_t h[100001], n, a, b, left, right;
int_fast64_t temp, cnt, mid;
double a_;
int main() {
    n = read(), a = read(), b = read();
    a -= b;
    a_             = 1.0 / a;
    rep(i, n) h[i] = read();
    left = 0, right = 1000000000;
    cnt = 0;
    while (right > left + 1) {
        mid = (right + left) >> 1;
        cnt = 0;
        rep(i, n) {
            temp = h[i] - b * mid + a - 1;
            if (temp > 0) cnt += temp * a_;
        }
        if (cnt <= mid)
            right = mid;
        else
            left = mid;
    }
    printf("%u\n", right);
}

Measured memory_bytes: 896
#include <bits/stdc++.h>
using namespace std;
int main(){
	char s[1001]={},t[1001]={};
	cin>>s>>t;
	int l=strlen(t);
	int k=strlen(s)-l;
	int ans=(1<<30);
	for(int i=0; i<k+1; i++){
		int ans2=0;
		for(int j=i; j<i+l; j++){
			if(s[j]!=t[j-i]){
				ans2++;
			}
			//cout<<s[j]<<" "<<t[j-i]<<endl;
		}
		ans=min(ans2,ans);
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 3588
#include <iostream>
#include <vector>

using namespace std;

static void inputArray(int A[], int num) {
  for (int i = 0; i < num; i++) {
    cin >> A[i];
   }
}

static void printArray(int A[], int num) {
  for (int i = 0; i < num; i++) {
    cout << ((i != 0) ? " " : "") << A[i];
  }
  cout << endl;
}

static vector<int> C(10000 + 1, 0);
static inline void countingSort(int A[], int B[], int num) {
  for (int i = 0; i < num; i++) {
    C[A[i + 1]]++;
  }
  for (int i = 1; i <= 10000; i++) {
    C[i] = C[i] + C[i - 1];
  }
  for (int i = num; i > 0; i--) {
//  for (int i = 1; i <= num; i++) {
    B[C[A[i]]] = A[i];
    C[A[i]]--;
  }
}  

static vector<int> A(2000000 + 1), B(2000000 + 1);

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

  inputArray(&A[1], n);

  countingSort(&A[0], &B[0], n);

  printArray(&B[1], n);
    
  return 0;
}



Measured memory_bytes: 18240
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(k,i,n) for(ll i=k;i<n;++i)
const ll mod=1e9+7;
static ll f[(ll)2e6];
ll mpow(ll x,ll n){
    ll ret=1;
    for(ll i=n;i;i>>=1){
        if(i&1)ret=ret*x%mod;
        x=x*x%mod;
    }
    return ret;
}
int main(void){
    ll n;
    string s;
    cin>>n>>s;
    ll m=s.size();
    f[0]=1;
    rep(1,i,n+m)f[i]=f[i-1]*i%mod;
    ll ans=0;
    rep(0,i,n+1){
        ll c=f[n+m-1-i]*mpow(f[m-1]*f[n-i]%mod,mod-2)%mod;
        ans=(ans+(c*mpow(26,i))%mod*mpow(25,n-i))%mod;
        //cout<<f[n+m-1-i]<<endl;
    }
    cout<<ans;
}

Measured memory_bytes: 20048
#include <bits/stdc++.h> 
using namespace std; 
typedef long long ll;
int main()
{
    ll n,p,q=0,r,i,s=0,u,v,b;
    cin>>n;
    ll a[n],c[n];
    for(i=0;i<n;i++)
    {
        cin>>a[i];
    }
   for(i=0;i<n;i++)
   {
       c[i]=a[i]-(i+1);
   }
   sort(c,c+n);
   b=c[(n-1)/2];
    for(i=0;i<n;i++)
    {
        s=s+abs(a[i]-(b+i+1));
    }
    cout<<s<<endl;
}

Measured memory_bytes: 3328
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  int A,B,C,X ,cou=0;
  cin >>A>>B>>C>>X;
  for(int i=0;i<(A+1);i++){
    for(int j=0;j<(B+1);j++){
      for(int k=0;k<(C+1);k++){
        if(500*i+100*j+50*k==X){
          cou++;
        }
      }
    }
  }
  cout << cou <<endl;
}


Measured memory_bytes: 256
import java.util.Scanner;

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

		int n=sc.nextInt();
		int a[]=new int[n];

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

		int max=0;
		int num=0;
		int nextMax=0;

		for(int i=0;i<n;i++){
			if(a[i]>max){
				max=a[i];
				num=i;
			}
		}

		for(int i=0;i<n;i++){
			if(a[i]>nextMax && i!=num){
				nextMax=a[i];
			}
		}

		for(int i=0;i<n;i++){
			if(i==num){
				System.out.println(nextMax);
			}else{
				System.out.println(max);
			}
		}


	}



}


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

void solve()
{
	int x,y;
	cin>>x>>y;
	for (int i = 0; i <= x; ++i)
	{
		if(y==2*i+4*(x-i))
		{
			cout<<"Yes"<<endl;
			return;
		}
	}
	cout<<"No"<<endl;
}

int main()
{
	ll t = 1;
	// cin>>t;
	while(t--)
	{
		solve();
	}
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using intl = long long;
#define rep(i, n) for(intl i = 0; i < (intl)(n); i++)
#define repd(i, n) for(intl i = (intl)((n) - 1); i >= 0; i--)
#define repi(i, a, b) for(intl i = (intl)(a); i < (intl)(b); i++)
#define max(a, b) ((a) > (b) ? (a) : (b))
#define min(a, b) ((a) < (b) ? (a) : (b))
#define INF = 1e9;
#define debug(x) cout << #x << ":" << x << endl
using namespace std;
void fp(bool flag){
    if(flag)cout << "Yes" << endl;
    else cout << "No" << endl;
}
int main(){
    intl n;
    cin >> n;
    intl a;
    cin >> a;
    intl b;
    cin >> b;
    intl c = (n / (a + b)) * a;
    c += min(n % (a + b),a);
    cout << c << endl;

    return 0;
}

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

int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int A,B,C;
	cin>>A>>B>>C;
	for(int _=1;_<=10000;_++){
		if(A%2||B%2||C%2){
			cout<<_-1<<endl;
			return 0;
		}
		else{
			tie(A,B,C)=make_tuple(C/2+B/2,A/2+C/2,A/2+B/2);
		}
	}
	cout<<-1<<endl;
}


Measured memory_bytes: 256
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define all(v) v.begin(), v.end()
#define allr(v) v.rbegin(), v.rend()



int main() {
  int n;
  cin >> n;
  vector<int> alll(n), odd(n);
  rep(i, n) {
    int a;
    cin >> a;
    for (int j = -1; j <= 1; j++) {
      if (a+j < 0) continue;
      if ((a+j) % 2 == 0) {
        alll[i]++;
      } else {
        alll[i]++;
        odd[i]++;
      }
    }
  }
  int a1 = 1, a2 = 1;
  rep(i, n) {
    a1 *= alll[i];
    a2 *= odd[i];
  }
  cout << a1 - a2 << endl;
  return 0;
}

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

// #include <ext/pb_ds/assoc_container.hpp> 
// #include <ext/pb_ds/tree_policy.hpp> 
// using namespace __gnu_pbds; 
  
// #define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> 
 
#define FS              ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ll              long long int
#define ld              long double
#define pb              push_back
#define bp              __builtin_popcount
#define sz              size()
#define ff              first
#define ss              second
#define vll             vector<ll>
#define vbool           vector<bool>
#define vpll            vector<pair<ll,ll>>
#define pll             pair<ll,ll>
#define vllv            vector<vector<ll>>
#define setpri(x)       cout<<setprecision(x)<<fixed;
#define all(v)          v.begin(),v.end()
#define allr(v)         v.rbegin(),v.rend()
#define yesr {cout<<"YES"<<endl;return;}
#define nor {cout<<"NO"<<endl;return;}
// getline (std::cin,name);
ll MOD=1e9+7;
ll ceil1(ll n,ll x){return (n-1)/x+(n>0);}

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

ll pow1(ll n,ll m ,ll mod=MOD );
ll pow2(ll n,ll k);

ll modinv(ll n,ll mod=MOD){  return pow1(n,mod-2,mod);}

bool func(pair<ll,ll> &a,pair<ll,ll> &b ){
        if(a.ff != b.ff)return a.ff < b.ff;
        return a.ss > b.ss;
}
ll const N=(ll)3e2+11;
ll const LG=(ll)log2(N)+1;


void solve(){
        ll i,j,k,l,n,m,x,y,z,r;
        cin>>n>>k;
        
        ll ans=0;
        vllv a(n,vll(k));
        for(i=0;i<n;i++){
                for(j=0;j<k;j++){
                        cin>>a[i][j];
                }
        }
        
        for(i=0;i<n;i++){
                for(j=i+1;j<n;j++){
                        
                        ll dis=0;
                        for(x=0;x<k;x++){
                                dis+=(a[i][x]-a[j][x])*(a[i][x]-a[j][x]);
                        }
                        // cout<<dis<<endl;
                        ll tt=(ll)sqrt(dis);
                        if(tt*tt==dis)ans++;
                }
        }
        cout<<ans<<endl;
        
}       
int main(){
        FS;
        
        ll i,j,k,n,m,x,y,z,q;
        q=1;
        // cin>>q;
        while(q--){
                solve();
        }
        return 0;
}


ll pow1(ll n,ll m,ll mod){
        if(m==0)return 1;
        
        if(m%2==0)return pow1((n*n)%mod,m/2,mod);
    	
    	return (pow1((n*n)%mod,m/2,mod)*n)%mod;
}

ll pow2(ll n,ll k){
        ll ans=1;
            while(k>0){
                if(k%2==1)ans=ans*n;
                n=n*n;
                k/=2;
            }
            return ans;
}

Measured memory_bytes: 3632
from collections import defaultdict
import sys
input = sys.stdin.readline


def main():
    S = input()[:-1]
    T = input()[:-1]

    ds = defaultdict(int)
    dt = defaultdict(int)
    for i in range(len(S)):
        ds[S[i:i+1]] += 1
        dt[T[i:i+1]] += 1
    
    ds = sorted(ds.items(), key=lambda x: x[1])
    dt = sorted(dt.items(), key=lambda x: x[1])

    if len(ds)!=len(dt):
        print('No')
        return
    for i in range(len(ds)):
        if ds[i][1] != dt[i][1]:
            print('No')
            return
    print('Yes')

if __name__ == '__main__':
    main()

Measured memory_bytes: 4136
N = int(input())
X = [chr(ord('a') + i) for i in range(N)]
first_presence = {x: i for x, i in zip(X, list(range(N)))}

R = ['a']
for i in range(1, N):
    next_r = []
    for r in R:
        max_s = max(r)
        for x in X[:first_presence[max_s] + 2]:
            next_r.append(r + x)
    R = next_r

ans = R
ans.sort()
print(*ans, sep="\n")


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

using namespace std;
typedef long long ll;

#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, a, b) for (int i = (a); i < (b); ++i)
#define all(a) (a).begin(), (a).end()
#define all2(a, b) (a).begin(), (a).begin() + (b)
#define debug(vari) cerr << #vari << " = " << (vari) << endl;

int sum_num(int a)
{
    int s = 0;
    while (a)
    {
        s += a % 10;
        a /= 10;
    }
    return s;
}

int main()
{
    int n;
    cin >> n;
    set<int> d;
    rep(i, n)
    {
        int a;
        cin >> a;
        d.insert(a);
    }

    cout << d.size() << endl;
    return 0;
}


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

int main(){
  int a,b,c,d,e;
  cin >>a>>b>>c>>d>>e;
  int ans;
  
  if(a==0)
    ans=1;
  else if(b==0)
    ans=2;
  else if(c==0)
    ans=3;
  else if(d==0)
    ans=4;
  else
    ans=5;
  
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 3640
K = int(input())

def calc_gcd(a, b):
	if a > b:
		r = a % b
		a = r
	
	while a > 0:
		r = b % a
		b = a
		a = r
	return b

#cache = {}

def gcd(a, b, c):
#	nums = [a, b, c]
#	nums.sort()
#	nums = tuple(nums)
	nums = (a, b, c)
#	if nums in cache:
#		return cache[nums]
	
	d = calc_gcd(nums[0], nums[1])
	d = calc_gcd(d, nums[2])
	
#	cache[nums] = d
	return d

total = 0
for i in range(1, K + 1):
	for j in range(1, K + 1):
		for k in range(1, K + 1):
			total += gcd(i, j, k)

print(total)


Measured memory_bytes: 69976
#include <iostream>
#include <vector>
#include <cstdio>
#include <string>
#include <cmath>
#include <algorithm>
#include <climits>
#define ll long long
#define MAX 25 * 1e13
#define N  200010

using namespace std;
int MOD = 1000000007;

int main(){
  int n,r;
  cin >> n >> r;
  int ret = 0;
  if( n >= 10 ) ret = r;
  else{
    ret = r + 100 * (10 - n );
  }
  cout << ret << endl;
  return 0;
}


Measured memory_bytes: 256
#include<algorithm>
#include<iostream>
#include<vector>
#include<string>
#include<queue>
#include<stack>
#include<cmath>
#include<list>
#include<set>
#include<map>

using namespace std;
long long MOD = 1000000007LL;

int main() {
	long long H, N;
	long long sumA = 0;
	cin >> H >> N;
	for (int i = 0; i < N; ++i) {
		long long a;
		cin >> a;
		sumA += a;
	}

	if (sumA < H) {
		cout << "No" << endl;
	}
	else {
		cout << "Yes" << endl;
	}
}


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

int main() {
  int n;cin>>n;
  int ac=0,wa=0,tle=0,re=0;
  for(int i=0; i<n; i++) {
    string s;cin>>s;
    if(s=="AC") ac++;
    if(s=="WA") wa++;
    if(s=="TLE") tle++;
    if(s=="RE") re++;
  }
  cout << "AC x " << ac << endl;
  cout << "WA x " << wa << endl;
  cout << "TLE x " << tle << endl;
  cout << "RE x " << re << endl;
}


Measured memory_bytes: 3628
#include <vector>
#include <iostream>
using namespace std;
int main() {
	int N;
	cin >> N;
	vector<int> V(N), C(N);
	for (int i = 0; i < N; ++i) cin >> V[i];
	for (int i = 0; i < N; ++i) cin >> C[i];
	int ans = 0;
	for (int i = 0; i < N; ++i) {
		if (V[i] >= C[i]) ans += V[i] - C[i];
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <queue>
#include <algorithm>
#include <utility>
#include <cmath>
#include <map>
#include <set>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cstring>
using namespace std;

#define INF_LL (ll)1e18
#define INF (int)1e9
#define REP(i, n) for(int i = 0;i < (n);i++)
#define FOR(i, a, b) for(int i = (a);i < (b);i++)
#define all(x) x.begin(),x.end()
using ll = long long;
using PII = pair<int, int>;

const double eps = 1e-10;

template<typename A, typename B>inline void chmin(A &a, B b){if(a > b) a = b;}
template<typename A, typename B>inline void chmax(A &a, B b){if(a < b) a = b;}

int main(void){
	int N, Y;
	cin >> N >> Y;
	Y /= 1000;
	int x = 0, y = 0, z = 0;
	x = Y/10; Y -= x*10;
	y = Y/5; Y -= y*5;
	z = Y;
	while(x+y+z < N){
		if(y > 0){
			y--;
			z += 5;
		}else if(x > 0){
			x--;
			y += 2;
		}else{
			cout << -1 << " " << -1 << " " << -1 << endl;
			return 0;
		}
	}
	if(x+y+z == N){
		cout << x << " " << y << " " << z << endl;
		return 0;
	}

	if(z >= 5){
		z -= 5;
		y++;
	}

	if(N-x-y-z <= x){
		int a = N-x-y-z;
		x-=a;
		y+=a*2;
	}
	if(x+y+z == N && x >= 0 && y >= 0 && z >= 0){
		cout << x << " " << y << " " << z << endl;
	}else{
		cout << -1 << " " << -1 << " " << -1 << endl;
	}
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
ll gcd(ll a, ll b) {return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) {return a/gcd(a,b)*b;}
int main(){
ll a,b,c,d;
cin >>a>>b>>c>>d;
ll cc=b/c-(a-1)/c;
ll dd=b/d-(a-1)/d;
ll k=lcm(c,d);
ll cd=b/k-(a-1)/k;
cout <<b-a+1-cc-dd+cd<<endl;
}


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

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define FOR(i,n,m) for(int i=(int)(n); i<=(int)(m); i++)
#define RFOR(i,n,m) for(int i=(int)(n); i>=(int)(m); i--)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define RITR(x,c) for(__typeof(c.rbegin()) x=c.rbegin();x!=c.rend();x++)
#define setp(n) fixed << setprecision(n)

template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }

#define ll long long
#define vll vector<ll>
#define vi vector<int>
#define pll pair<ll,ll>
#define pi pair<int,int>

#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define ins insert

using namespace std;

/* Some Libraries */

//-------------------------------------------------

int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int a,b; cin>>a>>b;
    int now=1, ans=0;
    while(now<b){
        now--; now+=a;
        ans++;
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define longlongvector vector<long long> 
#define intvector vector<int> 
#define size size()
using namespace std;

int n, m, k;



int main()
{
	int n; 
	cin >> n; 
	int arr[200002] = { 0 };
	for (int i = 0; i < n-1; i++)
	{
		int a;
		cin >> a;
		arr[a]++;
	}

	for (int i = 1; i < n + 1; i++)
		cout << arr[i] << endl;


	//system("pause");
}

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

int main(){
  int N,K,R,S,P;
  string T;
  cin >> N >> K >> R >> S >> P >> T;
  char B[K+10];

  // long total = 0;
  // for(int i=0; i<N; ++i){
  //   if(B[i%K]!=T[i]){
  //     if(T[i]=='r')
  //       total += P;
  //     else if(T[i]=='s')
  //       total += R;
  //     else if(T[i]=='p')
  //       total += S;
  //     B[i%K] = T[i];
  //   }
  //   else{
  //     B[i%K] = ' ';
  //   }
    
  // }
  long ans = 0;
  for(int i=0; i<N; ++i){
    if(i>=K && T[i] == T[i-K]){
      T[i] = 'q';
    }
    else{
      if(T[i]=='r') ans += P;
      else if(T[i]=='s') ans += R;
      else ans += S;
    }
  }

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 512