akhauriyash/Code-Regression huggingface dataset:
def read_input():
    n = int(input())
    alist = list(map(int, input().split()))

    return n, alist


def submit():
    n, alist = read_input()

    total = sum(alist)

    s = 0
    mindiff = float('inf')
    for i in range(n - 1):
        s += alist[i]
        rest = total - s

        diff = abs(s - rest)
        if diff < mindiff:
            mindiff = diff

    print(mindiff)

if __name__ == '__main__':
    submit()

Measured memory_bytes: 76752
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(ri,n) for(int ri = (int)(n-1); ri >= 0; ri--)
#define rep2(i,x,n) for(int i = (int)(x); i < (int)(n); i++)
#define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++)
#define rrepit(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++)
#define ALL(n) begin(n), end(n)
using ll = long long;
using namespace std;

int main(){
	int n, z, w;
	cin >> n >> z >> w;
	vector<int> a(n);
	rep(snip_i, n) cin >> a.at(snip_i);
	int ans;
	if(n > 1)ans = max(fabs(a.at(n-1) - w), fabs(a.at(n-2) - a.at(n-1)));
	else ans = fabs(a.at(n-1) - w);
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
	//iは繰り返し変数、nは入力するデータの数
	int i, n;
	//sumは合計値、minは最小値、maxは最大値、input_numbersは入力値を格納
	long min, max;
	long sum;
	long input_numbers[10000];

	//データを入力
	scanf("%d", &n);
	for(int i = 0; i < n; i++){
		scanf("%ld",&input_numbers[i]);
	}

	sum = 0;
	min = input_numbers[0];
	max = input_numbers[0];
	for(i = 0; i < n; i++){
		if(min > input_numbers[i]){
			min = input_numbers[i];
		}
		if(max < input_numbers[i]){
			max = input_numbers[i];
		}
		sum += input_numbers[i];
	}

	//結果を出力
	printf("%ld %ld %ld\n", min, max, sum);
	
	return 0;
}


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

using ll = long long;
using cd = complex<double>;

const int maxn = 1e5 + 10;

vector<pair<ll, int>> vec[5 * maxn] = {};
ll dist[5 * maxn] = {};

int current_special_node = 4 * maxn;

void add_edge(int x, int y, ll c){
    vec[x].emplace_back(c, y);
}

void operation(int st, int dr, ll cost){
    int me = current_special_node++;
    for(st += maxn, dr += maxn + 1; st < dr; st /= 2, dr /= 2){
        if(st%2){
            add_edge(st, me, cost);
            add_edge(me, st + 2 * maxn, 0);
            ++st;
        }
        if(dr%2){
            --dr;
            add_edge(dr, me, cost);
            add_edge(me, dr + 2 * maxn, 0);
        }
    }
}

void initialise(){
    for(int i = 1; i < maxn; ++i){
        add_edge(2 * i, i, 0);
        add_edge(2 * i + 1, i, 0);
        add_edge(i + 2 * maxn, 2 * i + 2 * maxn, 0);
        add_edge(i + 2 * maxn, 2 * i + 1 + 2 * maxn, 0);
    }
    for(int i = 0; i < maxn; ++i)
        add_edge(i + 3 * maxn, i + maxn, 0);
}

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

    int n, m;
    cin >> n >> m;

    initialise();

    for(ll i = 0, x, y, z; i < m; ++i){
        cin >> x >> y >> z;
        operation(x - 1, y - 1, z);
    }

    priority_queue<pair<ll, int>, vector<pair<ll, int>>, greater<pair<ll, int>>> pq;
    memset(dist, 0x3f, sizeof(dist));
    dist[maxn] = 0;
    pq.push(make_pair(0ll, maxn));
    while(!pq.empty()){
        ll cur = pq.top().second, cur_dist = pq.top().first;
        pq.pop();
        if(dist[cur] != cur_dist) continue;
        for(const auto next : vec[cur]){
            if(cur_dist + next.first < dist[next.second]){
                dist[next.second] = cur_dist + next.first;
                pq.push(make_pair(dist[next.second], next.second));
            }
        }
    }
    cout << (dist[maxn + n - 1] == 0x3f3f3f3f3f3f3f3fll ? -1 : dist[maxn + n - 1]) << endl;


    return 0;
}



Measured memory_bytes: 95192
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define repp(i,n,m) for (int i = m; i < (n); ++i)
#define repl(i,n) for (long long i = 0; i < (n); ++i)
#define reppl(i,n,m) for (long long i = m; i < (n); ++i)
using namespace std;
using ll = long long;
const int MOD = 1000000007;

int main(){
    int a, b, c; cin >> a >> b >> c;
    cout << c - min(c, a-b) << endl;
}

Measured memory_bytes: 256
package main

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

func main() {
	n := getInt() + 1
	days := make([][]int, n-1)
	for i := range days {
		days[i] = make([]int, 3)
		days[i][0] = getInt()
		days[i][1] = getInt()
		days[i][2] = getInt()
	}

	dp := make([][]int, n)
	for i := range dp {
		dp[i] = make([]int, 3)
	}
	dp[0][0], dp[0][1], dp[0][2] = 0, 0, 0

	for i := 1; i < n; i++ {
		for j := range dp[i] {
			for k := range dp[i-1] {
				if j != k {
					dp[i][j] = max(dp[i][j], dp[i-1][k]+days[i-1][j])
				}
			}
		}
	}

	fmt.Println(max(dp[n-1]...))
}

func max(ns ...int) int {
	max := ns[0]
	for i := 1; i < len(ns); i++ {
		if max < ns[i] {
			max = ns[i]
		}
	}
	return max
}

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

var scanner = wordScanner()

func wordScanner() *bufio.Scanner {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	return sc
}

func getInt() int {
	scanner.Scan()
	i, err := strconv.Atoi(scanner.Text())
	if err != nil {
		panic(err)
	}
	return i
}

func getIntSlice(n int) []int {
	is := make([]int, n)
	for i := range is {
		is[i] = getInt()
	}
	return is
}

func getString() string {
	scanner.Scan()
	s := scanner.Text()
	return s
}


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

// #undef DEBUG  // Uncomment this line to forcefully disable debug print.
#if DEBUG
template <typename T>
void debug(T value) {
  std::cerr << value;
}
template <typename T, typename... Ts>
void debug(T value, Ts... args) {
  std::cerr << value << ", ";
  debug(args...);
}
#define dbg(...)                              \
  do {                                        \
    cerr << #__VA_ARGS__ << ": ";             \
    debug(__VA_ARGS__);                       \
    cerr << " (L" << __LINE__ << ")" << endl; \
  } while (0)
#else
#define dbg(...)
#endif

void read_from_cin() {}
template <typename T, typename... Ts>
void read_from_cin(T& value, Ts&... args) {
  std::cin >> value;
  read_from_cin(args...);
}
#define in(type, ...) \
  type __VA_ARGS__;   \
  read_from_cin(__VA_ARGS__);

template <typename T>
void write_to_cout(const T& value) {
  std::cout << value << std::endl;
}
template <typename T, typename... Ts>
void write_to_cout(const T& value, const Ts&... args) {
  std::cout << value << ' ';
  write_to_cout(args...);
}
#define out(...) write_to_cout(__VA_ARGS__);

#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)

using ll = long long;

using namespace std;

int h, w;
int a[80][80];
int b[80][80];

const int kMax = 80 * 80 * 40;
using bs = bitset<kMax * 2 + 1>;
bs dp[81][81];

int main() {
  cin >> h >> w;
  rep(i, h) rep(j, w) cin >> a[i][j];
  rep(i, h) rep(j, w) cin >> b[i][j];
  dp[0][1][kMax] = 1;
  rep(i, h) rep(j, w) {
    int d = abs(a[i][j] - b[i][j]);
    bs b = (dp[i][j + 1] | dp[i + 1][j]);
    dp[i + 1][j + 1] = (b << d) | (b >> d);
  }
  rep(i, 80 * 80 * 40 + 1) if (dp[h][w][i + kMax]) {
    out(i);
    return 0;
  }
}


Measured memory_bytes: 406656
#include<iostream>
#include<string>
using namespace std;
int main(){
  int N,Q;
  string ti[101],au[101],da[101];
  cin>>N;
  for(int i=0;i<N;i++)cin>>ti[i]>>au[i]>>da[i];
  cin>>Q;
  string a,b,c,d;
 
  for(int k=0;k<Q;k++){
    int f[4][101]={};
    cin>>a>>b>>c>>d;
    if(a[0]!='*'){
      for(int i=0;i<N;i++){
       	for(int j=0;j<ti[i].size();j++){
	  int c=0;
	  while(ti[i][j+c]==a[c]){
	    c++;
	    if(c==a.size()){f[0][i]=1;break;}
	  }
	}
      }
    }
    else for(int i=0;i<N;i++)f[0][i]=1;

    if(b[0]!='*'){
      for(int i=0;i<N;i++){
	for(int j=0;j<au[i].size();j++){
	  int c=0;
	  while(au[i][j+c]==b[c]){
	    c++;
	    if(c==b.size()){f[1][i]=1;break;}
	  }
	}
      }
    }
    else for(int i=0;i<N;i++)f[1][i]=1;

    if(c[0]!='*'){
      for(int i=0;i<N;i++)
	for(int j=0;j<10;j++){
	  if(c[j]>da[i][j])break;
	  if(c[j]<da[i][j]){f[2][i]=1;break;}
	  if(j==9)f[2][i]=1;
	}
    }
    else for(int i=0;i<N;i++)f[2][i]=1;

    if(d[0]!='*'){
      for(int i=0;i<N;i++)
	for(int j=0;j<10;j++){
	  if(d[j]<da[i][j])break;
	  if(d[j]>da[i][j]){f[3][i]=1;break;}
	  if(j==9)f[3][i]=1;
	}
    }
    else for(int i=0;i<N;i++)f[3][i]=1;

    for(int i=0;i<N;i++){
      if(f[0][i]==1&&f[1][i]==1&&f[2][i]==1&&f[3][i]==1)cout<<ti[i]<<endl;
    }
    if(k<Q-1) cout<<endl;
  }
  
  return 0;
}

Measured memory_bytes: 1228
#!/usr/bin/python

# AtCoder Beginner Contest 076
# B - Addition and Multiplication

from sys import stdin

def solve(N, K):
  x = 1
  for i in range(N):
    x = min(2 * x, x + K)
  return x

N = int(stdin.readline())
K = int(stdin.readline())
print(solve(N, K))

Measured memory_bytes: 3060
s=input()
n=len(s)
o=[]
e=[]
for i in range(n):
    if (i+1)%2==0:
        e.append(s[i])
    else:
        o.append(s[i])
if o.count('L')==0 and e.count('R')==0:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 3060
// template version 1.12
using namespace std;
#include <iostream>
#include <bits/stdc++.h>

// varibable settings
#define infile "../test/sample-1.in"
#define int long long //{{{
const int INF=1e18;
const int MOD=1e9+7; //}}}

// define basic macro {{{
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define _rrep(i,n) rrepi(i,0,n)
#define rrepi(i,a,b) for(int i=(int)((b)-1);i>=(int)(a);--i)
#define rrep(...) _overload3(__VA_ARGS__,rrepi,_rrep,)(__VA_ARGS__)
#define each(i,a) for (auto&& i : a)
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define pb(a) push_back(a)
#define mp(a, b) make_pair(a, b)
#define uni(x) sort(all(x));x.erase(unique(all(x)),x.end())
#define ub upper_bound
#define lb lower_bound
#define posl(A, x) (lower_bound(all(A), x)-A.begin())
#define posu(A, x) (upper_bound(all(A),x)-A.begin())
template<class T> inline void chmax(T &a, const T &b) { if((a) < (b)) (a) = (b); }
template<class T> inline void chmin(T &a, const T &b) { if((a) > (b)) (a) = (b); }

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef long double ld;
typedef pair<int,int> pii;
typedef tuple<int,int,int> iii;

template<typename T> using PQ = priority_queue<T, vector<T>, greater<T>>;
struct Fast { Fast(){ std::cin.tie(0); ios::sync_with_stdio(false); } } fast;

#if defined(PCM) || defined(LOCAL)
  #include "lib/dump.hpp"
#else
  #define dump(...) 42
  #define dump_1d(...) 42
  #define dump_2d(...) 42
#endif
//}}}

// 隣接リストで使う辺を表す型
struct Edge {
  int to, cost;  // 辺の接続先頂点, 辺の重み
  Edge(int to, int cost) : to(to), cost(cost) {}  // コンストラクタ
};

typedef vector<vector<Edge> > AdjList;  // 隣接リストの型
AdjList graph;  // グラフの辺を格納した構造体
                // graph[v][i]は頂点vから出るi番目の辺Edge

vector<int> dist; // 最短距離

int solve(){
  //int n,m,p;cin>>n>>m>>p;
  string s,ans;
  ans="No";
  cin>>s;
  if(s[2]==s[3]&&s[4]==s[5])ans="Yes";
  
  cout << ans << endl;
  return 0;
}

signed main() { //{{{
#ifdef INPUT_FROM_FILE
  std::ifstream in(infile);
  std::cin.rdbuf(in.rdbuf());
#endif
  solve();
  return 0;
} //}}}


Measured memory_bytes: 3628
#ABC123-B
import numpy as np
a = int(input())
b = int(input())
c = int(input())
d = int(input())
e = int(input())

tmp = [a,b,c,d,e]
time = []
for i in range(5):
    if tmp[i] % 10 != 0:
        s = ((tmp[i]) // 10 + 1)*10 - tmp[i]
    else:
        s = 0
    time.append(s)
    
idx = np.argmax(np.array(time))
last = tmp.pop(idx)
#print('tmp:',tmp)
#print('idx',idx)
result = 0
for j in range(4):
    if tmp[j] % 10 != 0:
        result += (tmp[j] // 10 + 1)* 10
    else:
        result += tmp[j]
        
result += last

print(result)



Measured memory_bytes: 20936
Scanf.scanf "%d" (fun n ->
    let module M = Map.Make (struct type t = int let compare = compare end) in
    let add key v map = M.add key (v + try M.find key map with _ -> 0) map in
    let dec key map =
        let v = M.find key map in
        if v = 1 then M.remove key map else M.add key (v - 1) map
    in
    let rec loop i map =
        if i = n then map else
            let map = Scanf.scanf " %d" (fun a -> add a 1 map) in
            loop (i + 1) map
    in
    let map = loop 0 M.empty in
    let inikey k =
        let rec loop i =
            if i > k then i else loop (i + i)
        in
        loop 1
    in
    let rec loop map acc =
        if M.is_empty map then acc else
            let (k, v) = M.max_binding map in
            let map = dec k map in
            let ik = inikey k in
            if M.mem (ik - k) map then (
                let map = dec (ik - k) map in
                loop map (acc + 1)
            ) else loop map acc
    in
    loop map 0 |> Printf.printf "%d\n"
)

Measured memory_bytes: 18432
import java.io.*;
import java.util.*;


public class Main {

    public static void main(String[] args) {
        new Main().run();
    }

    BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
    ;
    PrintWriter out = new PrintWriter(System.out);
    StringTokenizer tok = new StringTokenizer("");

    void run() {
        try {
            long timeStart = System.currentTimeMillis();
            solve();

            out.close();

            long timeEnd = System.currentTimeMillis();
            System.err.println("Time = " + (timeEnd - timeStart));
        } catch (Exception e) {
            e.printStackTrace();
            System.exit(-1);
        }
    }

    String readLine() throws IOException {
        return in.readLine();
    }

    String delimiter = " ";

    String readString() throws IOException {
        while (!tok.hasMoreTokens()) {
            String nextLine = readLine();
            if (null == nextLine) return null;

            tok = new StringTokenizer(nextLine);
        }

        return tok.nextToken(delimiter);
    }

    int readInt() throws IOException {
        return Integer.parseInt(readString());
    }

    long readLong() throws IOException {
        return Long.parseLong(readString());
    }

    static int[] dist;
    static int[] par;
    static int n;
    static List<Integer>[] g;
    static ArrayDeque<Integer> q;
    static boolean used[];
    static void BFS(int start){
        q = new ArrayDeque<>();
        int v;
        used[start] = true;
        dist[start] = 0;
        q.addLast(start);
        while (q.size() > 0){
            v = q.pollFirst();
            for(int to : g[v]){
                if(dist[v] + 1 < dist[to]){
                    used[to] = true;
                    dist[to] = dist[v] + 1;
                    par[to] = v;
                    q.addLast(to);
                }
            }
        }
    }

    void solve() throws IOException {
        int n = readInt(), m = readInt(), a, b;
        g = new List[n];
        ArrayDeque<Integer> gr = new ArrayDeque<>();
        for(int v = 0; v < n; v++)
            g[v] = new ArrayList<>();
        dist = new int[n];
        par = new int[n];
        used = new boolean[n];
        for(int i = 0; i < n; i++){
            dist[i] = n;
            used[i] = false;
            par[i] = -1;
        }
        for(int e = 0; e < m; e++){
            a = readInt();
            b = readInt();
            g[a-1].add(b-1);
            g[b-1].add(a-1);
        }
        BFS(0);
        boolean f = true;
        for (int i = 1; i < n; i++)
            if (par[i] == -1){
                f = false;
                break;
            }
        if (f){
            out.println("Yes");
            for (int i = 1; i < n; i++)
                out.println(par[i] + 1);
        }
        else
            out.println("No");
    }


}

Measured memory_bytes: 63868
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))

SUM = 0
SUM = sum(B)
for i in range(0, len(A)-1):
  if A[i]==A[i+1]-1:
    SUM += C[A[i]-1]
    
print(SUM)

Measured memory_bytes: 3064
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <utility>
#include <tuple>
#include <algorithm>
#include <numeric>
#include <cstdio>
#include <cmath>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
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() {
  string S;
  ll K;
  cin >> S >> K;
  vector<int> num;
  int cnt = 1;
  rep(i, S.size()-1) {
    if (S[i+1] == S[i])
      cnt++;
    else {
      num.push_back(cnt);
      cnt = 1;
    }
  }
  num.push_back(cnt);
  ll ans = 0;
  if (num.size() == 1) {
    ans = num[0]*K/2;
  } else {
    for (int i = 1; i < num.size()-1; i++)
      ans += num[i]/2*K;
    if (S[0] == S.back()) {
      ans += num[0]/2+num.back()/2;
      ans += (num[0]+num.back())/2*(K-1);
    } else
      ans += num[0]/2*K+num.back()/2*K;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {

    static long MOD = 1000000007;
    public static void main(String[] args) {


        Scanner sc = new Scanner(System.in);
        int sx = sc.nextInt(),sy=sc.nextInt(),tx=sc.nextInt(),ty=sc.nextInt();

        for(int i=0;i<ty-sy;i++)System.out.print("U");
        for(int i=0;i<tx-sx;i++)System.out.print("R");
        for(int i=0;i<ty-sy;i++)System.out.print("D");
        for(int i=0;i<tx-sx;i++)System.out.print("L");
        System.out.print("L");
        for(int i=0;i<ty-sy+1;i++)System.out.print("U");
        for(int i=0;i<tx-sx+1;i++)System.out.print("R");
        System.out.print("DR");
        for(int i=0;i<ty-sy+1;i++)System.out.print("D");
        for(int i=0;i<tx-sx+1;i++)System.out.print("L");
        System.out.print("U");


    }
}


Measured memory_bytes: 21972
#include <iostream>
#include <string>
#include <vector>
#include <math.h>
#include <algorithm>
#include <functional>
#include <bitset>

using namespace std;

int main()
{
	//// 1つの値を読み込み
	string X;
	cin >> X;

	//SUN, MON, TUE, WED, THU, FRI, SAT

	if (X.compare("SUN") == 0)
	{
		std::cout << "7";
	}
	else if (X.compare("MON") == 0)
	{
		std::cout << "6";
	}
	else if (X.compare("TUE") == 0)
	{
		std::cout << "5";
	}
	else if (X.compare("WED") == 0)
	{
		std::cout << "4";
	}
	else if (X.compare("THU") == 0)
	{
		std::cout << "3";
	}
	else if (X.compare("FRI") == 0)
	{
		std::cout << "2";
	}
	else if (X.compare("SAT") == 0)
	{
		std::cout << "1";
	}

	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#include <limits.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <map>
#include <set>

#ifndef ULLONG
typedef unsigned long long ULLONG;
#endif
#ifndef LLONG
typedef long long LLONG;
#endif
static const ULLONG UL_HUGE_DIVIDER = 1000000007LLU;

static void ABC114D_D756();

#if 1
int main()
{
	ABC114D_D756();

	fflush(stdout);
	return 0;
}
#endif


//	素因数分解した結果を map で返す
template <class _Ty> void tp_getPrimes(_Ty targ, std::map<_Ty, _Ty>&primes)
{
	_Ty target = targ;
	_Ty i = 2;
	while ((i * i) <= target) {
		if ((target % i) == 0) {
			target /= i;

			if (primes.find(i) == primes.end()) {
				primes[i] = 1;
			}
			else {
				primes[i] = primes[i] + 1;
			}
		}
		else {
			i++;
		}
	}
	if (primes.find(target) == primes.end()) {
		primes[target] = 1;
	}
	else {
		primes[target] = primes[target] + 1;
	}


#if 0
	printf("Target: %d equals\n", targ);
	for (auto it = primes.begin(); it != primes.end(); it++) {
		printf("%d ^ %d\n", it->first, it->second);
	}
#endif
}

class ABC114D_ValSet
{
public:
	int p = 0;
	int q = 0;
	int r = 0;

	bool operator< (const ABC114D_ValSet& a) {
		return(p < a.p);
	}
	bool operator() (const ABC114D_ValSet& a, const ABC114D_ValSet& b) {
		return(a.p < b.p);
	}
};


static void ABC114D_D756()
{
	//	75数とは，A^4 * B^4 * C^2 で表される (5パターンx5パターンx3パターン)
	//	他には A^74, A^15 * B^5, A^25 * B^3 も
	int N;
	scanf(" %d", &N);
	
	std::map<int, int> primes;
	for (int i = 2; i <= N; i++) {
		//	Nの階乗をそれぞれ素因数分解して指数を加算
		tp_getPrimes<int>(i, primes);
	}

	std::map<int, int> pcount;
	std::map<std::pair<int, int>, int> pq1count, pq2count;
	std::map<std::pair<std::pair<int, int>, int>, int> pqrcount;
	int duplicate = 0, first = 0;
	for (int p = 2; p <= N; p++) {
		if (primes.find(p) == primes.end()) continue;

		if (primes[p] >= 74) {
			pcount[p] = 1;
		}

		for (int q = 2; q <= N; q++) {
			if (primes.find(q) == primes.end()) continue;

			std::pair<int, int> pq;

			if (p != q) {
				if ((primes[p] >= 24) && (primes[q] >= 2)) {
					pq.first = p;
					pq.second = q;
					pq1count[pq] = 1;
				}

				if ((primes[p] >= 14) && (primes[q] >= 4)) {
					pq.first = p;
					pq.second = q;
					pq2count[pq] = 1;
				}
			}

			for (int r = 2; r <= N; r++) {
				if (primes.find(r) == primes.end()) continue;

				std::pair<std::pair<int, int>, int> pqr;

				if ((p != q) && (q != r) && (r != p)) {

					//	4, 4, 2 のパターン
					if ((primes[p] >= 4) && (primes[q] >= 4) && (primes[r] >= 2)) {
						int pr[] = { p, q, 0 };
						std::sort(pr, pr + 2);

						pqr.first.first = pr[0];
						pqr.first.second = pr[1];
						pqr.second = r;

						pqrcount[pqr] = 1;
					}
				}
			}
		}
	}
	
	printf("%d\n", pcount.size() + pq1count.size() + pq2count.size() + pqrcount.size());
}


Measured memory_bytes: 256
#include<stdio.h>
#define i64 long long int
i64 m[3001][3001];
i64 mp=998244353;
int a[3001];
i64 f(int i,int s)
{
    if((i==0)&&(s==0)) return 1;
    if(i==0) return 0;
    if(m[i][s]!=-1) return m[i][s];
    if(s-a[i]>=0)
        m[i][s]=((2*f(i-1,s))%mp+f(i-1,s-a[i]))%mp;
    else m[i][s]=(2*f(i-1,s))%mp;
    return m[i][s];
}

int main()
{
   int n,s,i,j;
   i64 b;
   scanf("%d %d",&n,&s);
   for(i=1;i<=n;i++) scanf("%d",&a[i]);
   for(i=0;i<=n;i++)
   {
       for(j=0;j<=s;j++)
        m[i][j]=-1;
   }
   b=f(n,s);
   printf("%lld",b);
    return 0;
}


Measured memory_bytes: 72324
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define FOR(i,s,n) for(int i = s; i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(n) (n).begin(), (n).end()
#define RALL(n) (n).rbegin(), (n).rend()
#define ATYN(n) cout << ( (n) ? "Yes":"No") << '\n';
#define CFYN(n) cout << ( (n) ? "YES":"NO") << '\n';
#define OUT(n) cout << (n) << '\n';
using ll = long long;
using ull = unsigned long long;
using pii = pair<int,int>;
using pll = pair<ll,ll>;

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

    set<int> st{1};
    int x = 2;
    while(x*x <= n) {
        int y = x;
        while(y <= n) {
            st.insert(y);
            y *= x;
        }
        x++;
    }

    OUT(*st.rbegin())


    return 0;
}

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

int main(void) {
	int N;
	scanf("%d", &N);
	int a[3000];
	int ans = 0;
	for (int i = 0; i < N; i++) {
		scanf("%d", &a[i]);
		ans += a[i] - 1;
	}
	printf("%d\n", ans);
	return 0;
}


Measured memory_bytes: 3824
#include <iostream>
#include <algorithm>
#include <cstring>
#define rep(i, a, n) for(int i = a;i < n;i++)
using namespace std;


int q;
int l[100000];
int r[100000];
int p[100010];
int acc[100010];


void sieve(){
	memset(p, 1, sizeof(p));
	p[0] = p[1] = 0;
	for(int i = 2;i*i <= 100000;i++){
		if(p[i]){
			for(int j = 2;i*j <= 100000;j++){
				p[i*j] = 0;
			}
		}
	}
}


int main(){
	cin >> q;
	rep(i, 0, q) cin >> l[i] >> r[i];

	sieve();

	rep(i, 1, 100010){
		acc[i] += acc[i-1];
		if((i+1) % 2 == 0 && p[i] && p[(i+1) / 2])
			acc[i]++;
	}

	rep(i, 0, q){
		cout << acc[r[i]] - acc[l[i]-1] << endl;
	}

	return 0;
}

Measured memory_bytes: 2176
#include<iostream>
using namespace std;
typedef long long ll;
ll gcd(ll a,ll b)
{
    return b?gcd(b,a%b):a;
}
ll lcm(ll c,ll d)
{
    return c*d/gcd(c,d);
}
int main()
{
    ll m,n;
    cin>>m>>n;
    cout<<lcm(m,n)<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <string>
#include <vector>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <map>
#include <list>
#include <set>
#include <numeric>
#include <queue>
#include <stack>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <climits>
#include <cfloat>
#include <ctime>
#include <complex>
#include <cassert>
#include <array>
#include <bitset> 
#include <unordered_map>
#include <random>

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

bool done[2][2001];
int sz[2][2001][2001];
int sz2[2][2001];
int dp[2001][2001];
int main() {
	int N;
	cin >> N;
	for(int i=0;i<2*N;i++){
		char c;
		int a;
		cin >> c >> a;
		int v=c=='W'?0:1;
		int p=0;
		done[v][a]=true;
		for(int j=N;j>=0;j--){
			sz[v][a][j]=p;
			if(done[v^1][j]){
				p++;
			}
			//cerr << "sz " << v << ", " << a << ", " << j << ": " << sz[v][a][j] << endl;
		}
		for(int j=a+1;j<=N;j++){
			if(done[v][j]){
				sz2[v][a]++;
			}
		}
		//cerr << "sz2 " << v << ", " << a << ", " << sz2[v][a] << endl;
	}
	for(int i=0;i<=N;i++){
		for(int j=0;j<=N;j++){
			if(i==0&&j==0)continue;
			int v=1<<29;
			if(i>0){
				//cerr << sz2[0][i] << ", " << sz[0][i][j] << endl;
				v=min(v,dp[i-1][j]+sz2[0][i]+sz[0][i][j]);
			}
			if(j>0){
				v=min(v,dp[i][j-1]+sz2[1][j]+sz[1][j][i]);
			}
			dp[i][j]=v;
			//cerr << i << ", " << j << ": " << dp[i][j] << endl;
		}
	}
	cout << dp[N][N] << endl;


	return 0;
}



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

double dis(double x1,double y1, double x2, double y2){
	return sqrt((x1-x2)*(x1-x2) + (y1-y2)*(y1-y2));
}

int main(){
	int n; cin>>n;
	vector<pair<double,double> > foo;
	foo.push_back({0,0});
	for(int i=0;i<n;i++){
		double x,y; cin>>x>>y;
		foo.push_back({x,y});
	}
	vector<int> per;
	double ave=0.0;
	double num_per=0.0;
	//cout<<"n -> "<<n<<endl;
	for(int i=1;i<=n;i++) per.push_back(i);
	do{
		double asd=0.0;
		for(int i=0;i<per.size()-1;i++){
			//cout<<per[i]<<" "<<per[i+1]<<endl;
			asd+=dis( foo[per[i]].first , foo[per[i]].second , foo[per[i+1]].first , foo[per[i+1]].second );
		}//cout<<endl<<endl;
		num_per+=1.0;
		ave+=asd;
		//cout<<ave<<endl;
	}while(next_permutation(per.begin(),per.end() ));
	cout<<setprecision(13);
	cout<<fixed;
	cout<<(ave/num_per)<<endl;
	return 0;
}

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

using namespace std;

int main(){
    int N, M;
    cin >> N >> M;
    vector<int> L(M), R(M);
    for(int i=0;i<M;i++){
        cin >> L.at(i) >> R.at(i);
    }

    int L_max = 1;
    int R_min = N;

    for(int i=0;i<M;i++){
        if(L_max < L.at(i))L_max = L.at(i);
        if(R_min > R.at(i))R_min = R.at(i);
    }

    int cnt_pass = max(0, R_min-L_max+1);

    cout << cnt_pass << endl;
}

Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <map>

using namespace std;

int main()
{
    int n;
    long long int h[100010];
    long long int max = 0, cnt = 0;

    cin >> n;

    for (int i = 0; i < n; i++) {
        cin >> h[i];
    }

    for (int i = 1; i < n; i++) {
        if (h[i] <= h[i-1]) {
            cnt++;
        }
        else {
            if (max < cnt) {
                max = cnt;
            }
            cnt = 0;
        }
    }

    if (max < cnt) {
        max = cnt;
    }

    cout << max << endl;
}


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

int main(){

  int A, B; cin >> A >> B;

  int ans = 0;

  ans = std::max(A, B);
  if(ans == A) --A;
  else if(ans == B) --B;

  // cout << A << "\t" << B << endl;
  ans += std::max(A, B);

  cout << ans << endl;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < n; i++)
#define rep1(i,n) for(int i = 1; i < n; i++)
#define repv(i,n) for(int i = n-1; i >= 0; i--)
#define fi first
#define sc second
#define pb push_back
using namespace std;
typedef long long ll;

char BUF[3500000];
inline void I(int&a){scanf("%d",&a);}
inline void I(int&a,int&b){scanf("%d%d",&a,&b);}
inline void I(int&a,int&b,int&c){scanf("%d%d%d",&a,&b,&c);}
inline void I(int&a,int&b,int&c,int&d){scanf("%d%d%d%d",&a,&b,&c,&d);}
inline void L(ll&a){scanf("%lld",&a);}
inline void L(ll&a,ll&b){scanf("%lld%lld",&a,&b);}
inline void L(ll&a,ll&b,ll&c){scanf("%lld%lld%lld",&a,&b,&c);}
inline void L(ll&a,ll&b,ll&c,ll&d){scanf("%lld%lld%lld%lld",&a,&b,&c,&d);}
inline void S(string&str){str.clear();scanf("%s",BUF);int s=strlen(BUF);rep(i,s)str.pb(BUF[i]);}
inline void SV(vector<int>&v){v.clear();scanf("%s",BUF);int s=strlen(BUF);rep(i,s)if('a'<=BUF[i]&&BUF[i]<='z')v.pb(BUF[i]-'a');else v.pb(BUF[i]-'A');}

const auto EPS = 1e-10;
const auto INF = 100000000;
const auto MOD = 1000000007;
typedef pair<ll,ll> P;

ll n, m;
ll x[100000], y[100000];
ll xx, yy;

int main(){
    L(n,m);
    rep(i,n) L(x[i]);
    rep(i,m) L(y[i]);
    for(int i = 1; i < n; i++){
        xx += (x[i]-x[i-1])*i*(n-i);
        xx %= MOD;
    }
    for(int i = 1; i < m; i++){
        yy += (y[i]-y[i-1])*i*(m-i);
        yy %= MOD;
    }
    cout << xx*yy%MOD << endl;
}
































Measured memory_bytes: 1920
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayDeque;
import java.util.Deque;

class Main {

	public static void main(String[] args) throws IOException {

		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		String[] str = br.readLine().split(" ");

		Deque<Integer> dq = new ArrayDeque<>();

		for(int i=0; i<str.length; i++){

			if(str[i].equals("+")){
				Integer num = dq.pop()+dq.pop();
				dq.push(num);

			}else if (str[i].equals("-")) {

				Integer num = dq.pop();
				dq.push(dq.pop()-num);

			}else if (str[i].equals("*")) {
				Integer num = dq.pop()*dq.pop();
				dq.push(num);
			}else {
				dq.push(Integer.parseInt(str[i]));

			}
		}
		System.out.println(dq.pop());
	}

}

Measured memory_bytes: 24348
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in Actual solution is at the top
 *
 * @author Silviase
 */
public class Main {

  public static void main(String[] args) {
    InputStream inputStream = System.in;
    OutputStream outputStream = System.out;
    Scanner in = new Scanner(inputStream);
    PrintWriter out = new PrintWriter(outputStream);
    ABC151D solver = new ABC151D();
    solver.solve(1, in, out);
    out.close();
  }

  static class ABC151D {

    public void solve(int testNumber, Scanner in, PrintWriter out) {
      int h = in.nextInt();
      int w = in.nextInt();
      char[][] c = new char[h][w];
      int[] dh = {-1, 0, 0, 1};
      int[] dw = {0, 1, -1, 0};
      int[][] dist = new int[h * w][h * w];
      for (int i = 0; i < h; i++) {
        c[i] = in.next().toCharArray();
      }

      for (int i = 0; i < h * w; i++) {
        for (int j = 0; j < h * w; j++) {
          if (i == j) {
            dist[i][j] = 0;
          } else {
            dist[i][j] = 114514;
          }
        }
      }

      for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
          for (int k = 0; k < 4; k++) {
            int di = i + dh[k];
            int dj = j + dw[k];
            if (di < h && di >= 0 && dj < w && dj >= 0) {
              if (c[i][j] == '.' && c[di][dj] == '.') {
                dist[i * w + j][di * w + dj] = 1;
                // out.println(i + " " + j + " " + di + " " + dj);
              }
            }
          }
        }
      }

      for (int k = 0; k < h * w; k++) {
        for (int i = 0; i < h * w; i++) {
          for (int j = 0; j < h * w; j++) {
            if (dist[i][j] > dist[i][k] + dist[k][j]) {
              dist[i][j] = dist[i][k] + dist[k][j];
            }
          }
        }
      }

      int res = 0;
      for (int i = 0; i < h * w; i++) {
        for (int j = 0; j < h * w; j++) {
          if (dist[i][j] >= 114514) {

          } else {
            res = Math.max(res, dist[i][j]);
          }
        }
      }
      out.println(res);
    }

  }
}



Measured memory_bytes: 23636
h, w = gets.split.map(&:to_i)
a = []
h.times do |i|
  s = gets.chomp
  a.push(s) if s.include?('#')
end
(w - 1).downto(0) do |i|
  if a.all?{|x| x[i] == '.'}
    a.each do |x|
      x[i] = ''
    end
  end
end
puts a

Measured memory_bytes: 1788
import java.awt.geom.Line2D;
import java.util.*;
public class Main {
	Scanner in = new Scanner(System.in);
	public static void main(String[] args) {
		new Main();
	}

	public Main() {
		int q = in.nextInt();
		for(int i=0;i<q;i++)new CGL_2B().doIt();
	}

	class CGL_2B{
		double segSegDist(Line2D l1,Line2D l2){
			return l1.intersectsLine(l2)? 0 :Math.min(Math.min(l1.ptSegDist(l2.getP1()), l1.ptSegDist
					(l2.getP2())) , Math.min(l2.ptSegDist(l1.getP1()), l2.ptSegDist(l1.getP2())));
		}
		void doIt(){
			Line2D l1 = new Line2D.Double(in.nextDouble(),in.nextDouble(),in.nextDouble(),in.nextDouble());;
			Line2D l2 = new Line2D.Double(in.nextDouble(),in.nextDouble(),in.nextDouble(),in.nextDouble());;
			System.out.printf("%.10f\n",segSegDist(l1, l2));
		}
	}


}

Measured memory_bytes: 49184
#ifndef LOCAL
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization ("unroll-loops")
#endif
#include "bits/stdc++.h"
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
#include <ext/pb_ds/detail/standard_policies.hpp>
using namespace std;
using namespace __gnu_pbds;
#define sim template < class c
#define int long long
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << '\n'; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);
typedef tree< pair<int,int>, null_type, less<pair<int,int> >, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
typedef long long ll;
const ll MOD = 1e9 + 7 ;
const ll N = 1e6 + 10 ;
const ll INF = 1e18 + 10 ;
int n ;
int dp[N][2][2] ;
int dfs(int x, int a, int b){
    if ( x == n ) {
        if ( a == 1 && b == 1 ) {
            return 1 ;
        }
        return 0 ;
    }
    if ( dp[x][a][b] != -1 ) return dp[x][a][b] ;
    int ans = 0 ;
    ans += dfs(x + 1, 1, b) ;
    ans %= MOD ;
    ans += dfs(x + 1, a, 1) ;
    ans %= MOD ;
    ans += 8 * dfs(x + 1, a , b) ;
    ans %= MOD ;
    return dp[x][a][b] = ans ;
}
signed main(){
    fastio
    memset(dp, -1, sizeof dp) ;
    cin >> n ;
    int ans = dfs(0, 0, 0) ;
    cout << ans << endl;
    return 0; 
}


Measured memory_bytes: 112812
import sys

def dfs(i):
    global V, t, d, f

    if d[i] != 0:
        return

    d[i] = t
    t += 1
    for v in V[i]:
        dfs(v)

    f[i] = t
    t += 1

    return

lines = sys.stdin.readlines()
n = int(lines[0])
V = [[] for _ in range(n + 1)]

for i in range(1, n + 1):
    v = map(int, lines[i].split())
    V[v[0]] = v[2:]
d = [0] * (n + 1)
f = [0] * (n + 1)
t = 1

flag = True
while flag:
    flag = False
    for i in range(1, n + 1):
        if d[i] == 0:
            dfs(i)
            flag = True
            break

for i in range(1, n + 1):
    print i, d[i], f[i]

Measured memory_bytes: 6396
//----------------------------templates
    #pragma GCC optimize ("Ofast")
    #pragma GCC target ("tune=native")
    #pragma GCC target ("avx")
    //----------------------------
    #include <bits/stdc++.h>
    using namespace std;

    typedef long long ll;
    typedef unsigned long long ull;
    #define int ll

    #define FOR(i,j,n) for (int i=(int)(j);i<(n);i++)
    #define REP(i,n) for (int i=0;i<(int)(n);i++)
    #define REPS(i,n) for (int i=1;i<=(int)(n);i++)
    #define REPN(i,n) for (int i=(int)(n)-1;i>=0;i--)
    #define REPNS(i,n) for (int i=(int)(n);i>0;i--)

    #define I(n) scanf("%lld", &(n))
    #define LL(n) scanf("%lld", &(n))
    #define pb(n) push_back((n))
    #define mp(i,j) make_pair((i),(j))
    #define eb(i,j) emplace_back((i),(j))
    #define y0 y3487465
    #define y1 y8687969
    #define j0 j1347829
    #define j1 j234892
    #define uniq(v) v.erase( unique(v.begin(), v.end()), v.end() )

    #define all(x) (x).begin(),(x).end()
    #define sz(x) ((int)(x).size())

    typedef vector<int> vi;
    typedef pair<int,int> pi;
    typedef vector<pi> vpi;
    typedef vector<vi> vvi;
    typedef vector<vpi> vvpi;
    typedef vector<vvi> vvvi;

    const int mod = 1000000007;

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

int n;
vi a,b;
map<int,int> pos;
signed main(){
    I(n);
    a.resize(n);
    REP(i,n) I(a[i]);
    b.resize(n);
    REP(i,n) I(b[i]);
    
    REP(i,n) pos[b[i]] = a[i];
    bool ret = true;
    REP(i,n) ret &= pos.find(i+1) != pos.end();
    
    if(ret){
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
        REP(i,n){
            printf("%lld", pos[a[i]] ? pos[a[i]] : 1);
            if (i != n-1) printf(" ");
        }
        cout << endl;
        REP(i,n){
            printf("%lld", pos[a[i]] ? pos[a[i]] : 2);
            if (i != n-1) printf(" ");
        }
        cout << endl;
    }

}


Measured memory_bytes: 10940
#include <bits/stdc++.h>
#define ENDL '\n'
#define io ios_base::sync_with_stdio(false);cin.tie(0);
#define sayy cout<<"Yes"<<ENDL;
#define sayn cout<<"No"<<ENDL;
#define sayY cout<<"YES"<<ENDL;
#define sayN cout<<"NO"<<ENDL;

typedef long long ll;
using namespace std;

int main(){
    io

    int n,l;
    cin >> n >> l;

    vector<int> v(n);
    int minval = INT_MAX, index;
    for(int i(0); i<n; i++){
        int x = l + (i+1) - 1;
        if(abs(x) < minval){
            minval = abs(x); index = i;
        }
        v[i] = x;
    }

    int ans(0);
    for(int i(0); i<n; i++){
        if(i == index) continue;
        ans += v[i];
    }
    cout << ans << ENDL;
    
    return 0;
}

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

main() {
  int N; cin >> N;
  vector<int> p(N);
  for (int i = 0; i < N; i++) {
    cin >> p[i];
    p[i]--;
  }

  int ans = 0;
  for (int i = 0; i < N - 1; i++) {
    if (p[i] == i) {
      swap(p[i], p[i + 1]);
      ans++;
    }
  }
  for (int i = N - 1; i > 0; i--) {
    if (p[i] == i) {
      swap(p[i], p[i - 1]);
      ans++;
    }
  }

  cout << ans << endl;
}


Measured memory_bytes: 640
using System;
class Program
{
  static void Main(string[] args)
  {
    // スペース区切りの整数の入力
    string[] input = Console.ReadLine().Split(' ');
    int a = int.Parse(input[0]);
    int b = int.Parse(input[1]);
    int c = int.Parse(input[2]);
    //出力
    int d=0;
    if (a==b){
      d=c;
    }else if (a==c){
      d=b;
    }else{
      d=a;
    }
    Console.WriteLine(d);
  }
}

Measured memory_bytes: 11092
#include <bits/stdc++.h>
#define ll long long
#define cwk freopen("D:\\c++\\in.txt","r",stdin),freopen("D:\\c++\\out.txt","w",stdout)
using namespace std;
const int N=1e6+10;
int main()
{
	//cwk;
	int n,m;
	scanf("%d%d",&n,&m);
	int ans=n*(n-1)/2+(m*(m-1))/2;
	printf("%d\n",ans);

	return 0;
}

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

int n,m,dp[5][10010];
char a;
bool ans;

int main()
{
	int i;
	cin>>n>>a>>m;
	if(a=='+') cout<<n+m;
	else cout<<n-m;
}

Measured memory_bytes: 256
#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<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 fast ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)

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;

void solve(){
   int n,d;
   cin >> n >> d;

   int a[n][d];
   f(i,0,n) f(j,0,d) cin >> a[i][j];

   int ans = 0;
   f(i,0,n){
      f(j,i+1,n){
         int tot = 0;
         f(k,0,d) tot += (a[i][k] - a[j][k]) * (a[i][k] - a[j][k]);
         int sq = sqrt(tot);
         if(sq * sq == tot) ans++;
      }
   }
   cout<< ans << "\n";
}

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

Measured memory_bytes: 3668
#include<bits/stdc++.h>
#define ll          long long
#define pb          push_back
#define ppb         pop_back
#define mii         map<ll int,ll int>
#define msi         map<string,ll int>
#define mis         map<ll int, string>
#define rep(i,a,b)    for(ll int i=a;i<b;i++)
#define mpi         map<pair<ll int,ll int>,ll int>
#define pii         pair<ll int,ll int>
#define vi          vector<ll int>
#define vii         vector<pair<ll int, ll int>>
#define vs          vector<string>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define mp          make_pair
//#define time        cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
// cerr<<1.0/CLOCKS_PER_SEC<<endl;
using namespace std;
#define N  1000000007 
#define MAXN   200005
//ll int dp[1001][100005];
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cout.precision(15);
ll int n,i,j;
cin>>n;
vi a(n);
ll int sum=0;
rep(i,0,n)
{cin>>a[i];
sum+=a[i];}
ll int dp[n][n];
rep(i,0,n)
rep(j,0,n)
dp[i][j]=0;
rep(g,0,n)
{for(i=0,j=g;j<n;i++,j++)
{
if(i==j)
dp[i][j]=a[i];
else if(j==i+1)
	dp[i][j]=max(a[i],a[j]);
else
{
ll int x,y,z;
if(j>=i+2)
x=dp[i+2][j];
else
x=0;	
if(j-1>=i+1)
y=dp[i+1][j-1];
else
y=0;
if(j-2>=i)
z=dp[i][j-2];
else
z=0;
dp[i][j]=max(a[i]+min(x,y),a[j]+min(y,z));
}
}}
cout<<2*dp[0][n-1]-sum;
}


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

int main(){
  int N;
  cin >> N;
  int A=N,sum=0;
  while(A>0){
    sum+=A%10;
    A/=10;
  }
  if(N%sum==0){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
}

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

using namespace std;
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)

typedef long long ll;
typedef pair<ll, ll> P;
const ll INF = 1LL<<60;

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

template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

ll modpow(ll a, ll n, ll mod) {
  ll res = 1;
  while (n > 0) {
    if (n & 1) res = res * a % mod;
    a = a * a % mod;
    n >>= 1;
  }
  return res;
}


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

  ll K;
  cin >> K;

  vector<set<string>> vec(20);

  for(int i = 0; i < 10; i++){
    vec[0].insert(to_string(i));
  }

  if(K < 10){

    cout << K << endl;
    return 0;

  }

  for(int i = 0; i < 10; i++){

    int cnt_now = 0;
    for(auto itr = vec[i].begin(); itr != vec[i].end(); itr++){

      string t = *itr;
      int nd = t[0] - '0';

      if(nd < 9){
        string tt = char(t[0]+1)+t;
        vec[i+1].insert(tt);
      }

      if(nd > 0){
        string tt = char(t[0]-1) + t;
        vec[i+1].insert(tt);
      }
      string tt = char(t[0]) + t;
      vec[i+1].insert(tt);

    }

  }

  set<ll> st;
  for(int i = 0; i < 10; i++){
    for(string d : vec[i]){
      st.insert(stoll(d));
    }
  }

  int cnt = 0;
  for(ll d : st){
    // cout << d << endl;
    if(cnt == K){
      cout << d << endl;
      return 0;
    }
    cnt++;
  }
  
  return 0;
}


Measured memory_bytes: 66560
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> P;
typedef pair<int,int> Pi;
#define rep(i, n) for (ll i = 0; i < n; i++)
#define FOR(i, a, b) for (ll i = a; i < b; i++)
#define fi first
#define se second
#define endl "\n"

template<typename T> inline bool chmax(T &a, T b){if(a<b){a=b;return true;}return false;}
template<typename T> inline bool chmin(T &a, T b){if(a>b){a=b;return true;}return false;}
template<typename T> ostream& operator<<(ostream& s,const complex<T>& d) {return s<<"("<<d.real()<<", "<<d.imag()<< ")";}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const pair<T1,T2>& d) {return s<<"("<<d.first<<", "<<d.second<<")";}
template<typename T> ostream& operator<<(ostream& s, const vector<T>& d){
	int len=d.size();
	rep(i,len){
		s<<d[i];if(i<len-1) s<<" ";
	}
	return s;
}
template<typename T> ostream& operator<<(ostream& s,const vector<vector<T>>& d){
	int len=d.size();
	rep(i,len){
		s<<d[i]<<endl;
	}
	return s;
}
template<typename T> ostream& operator<<(ostream& s,const set<T>& v){
	s<<"{ ";
	for(auto itr=v.begin();itr!=v.end();++itr) {
		if (itr!=v.begin()) {s<< ", ";}
		s<<(*itr);
	}
	s<<" }";
	return s;
}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const map<T1,T2>& m){
	s<<"{"<<endl;
	for(auto itr=m.begin();itr!=m.end();++itr){
		s<<" "<<(*itr).first<<" : "<<(*itr).second<<endl;
	}
	s<<"}"<<endl;
	return s;
}

const ll mod=1e9+7;
const ll inf=1e17;
const int INF=1e9;
const double PI=acos(-1);
const double EPS=1e-10;

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n,h,w;
	cin>>n>>h>>w;
	int ans=0;
	rep(i,n){
		int a,b;
		cin>>a>>b;
		if(a>=h && b>=w) ans++;
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdlib>
#include <cmath>
#include <string>
using namespace std;
typedef long long ll;


int main(void){

    
    ll S;
    cin >> S;
    
    std::string s = std::to_string(S);

    ll cnt = 0;
    
    for(ll i=0; i < 3; i++){
        if(s[i] == s[i+1]){
            cnt = 1;
        }
    }
    
    
    if(cnt == 1){
        cout << "Bad" << endl;
    }
    else cout << "Good"<< endl;
    
    
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
using namespace std;
#define MAX_N 1000
#define MAX_W 1000

int main(void){
  int W, N, cnt = 0;
  while(cin >> W && W && cin >> N){
    cnt++;
    int dp[MAX_W+1][MAX_N+1] = {0};
    for(int i = 0; i < N; i++){
      int v, w;
      scanf("%d,%d", &v, &w);
      for(int j = 0; j < W+1; j++){
        dp[j][i+1] = max(dp[j][i], (j-w >= 0 ? dp[j-w][i] + v : 0));
      }
    }
    cout << "Case " << cnt << ":" << endl;
    for(int j = 0; j < W + 1; j++){
      if(dp[j][N] == dp[W][N]){
        cout << dp[j][N] << endl << j << endl;
        break;
      }
    }
  }
  return 0;
}

Measured memory_bytes: 5164
#include<bits/stdc++.h>
#define fastio ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define endl '\n'
#define pb push_back
#define ll long long
#define ull unsigned long long
#define vi vector<int>
using namespace std;
constexpr int MOD=1e9+7;
constexpr int mod=998244353;



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

    if(y%2!= 0){
        cout << "No" ; 
        return 0 ; 
    }
    int m1 = 2*x ; 
    int m2 = 4*x ; 

    if(y >= m1 && y <= m2)
        cout << "Yes" ;
    else
        cout << "No" ; 


    return 0 ; 
}

Measured memory_bytes: 3636