akhauriyash/Code-Regression huggingface dataset:
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <bitset>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <numeric>
#include <iostream>
#include <iomanip>
#include <string>
#include <chrono>
#include <random>
#include <cmath>
#include <cassert>
#include <climits>
#include <cstring>
#include <cstdlib>
#include <functional>
#include <sstream>

using namespace std;


int main(int argc, char** argv) {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(12);

    int n;
    cin >> n;
    vector<vector<pair<int,int>>> graph(n);
    for (int i = 0; i < n - 1; ++i) {
        int a, b, c;
        cin >> a >> b >> c;
        --a, --b;
        graph[a].emplace_back(b, c);
        graph[b].emplace_back(a, c);
    }

    int q, K;
    cin >> q >> K;
    --K;
    int rt = K;

    vector<long long> dis(n, 0);
    vector<int> que;
    que.push_back(rt);
    vector<int> pars(n, -1);
    for (int i = 0; i < que.size(); ++i) {
        int u = que[i];
        for (auto& e : graph[u]) {
            int v = e.first;
            if (v == pars[u]) {
                continue;
            }
            pars[v] = u;
            dis[v] = dis[u] + e.second;
            que.push_back(v);
        }
    }

    while (q-- > 0) {
        int u, v;
        cin >> u >> v;
        --u, --v;
        long long d = dis[u] + dis[v];
        cout << d << '\n';
    }

    return 0;
}

Measured memory_bytes: 11748
#include <iostream>
#include <vector>
#include <array>
#include <set>
#include <cmath>
#include <string>
#include <sstream>
#include <queue> 
#include <list>
#include <stack>
#include <unordered_map>
#include <algorithm> 
#include <numeric>  
#include <functional>
#include <cassert>
#include <bitset>
#include <cctype>  
#include <iomanip> 
#include <limits>  
#include <regex>
// std::numeric_limits<int>::max(), min()
// std::setprecision(X)
// std::islower(), std::isupper(), std::tolower, std::toupper
// std::accumulate(m.begin(), m.end(), 0LL);
// std::sort(begin(),end()) // 0, 1, 2, 3 ,4 (default, less);
// std::priority_queue<int, vector<int>, less<int>> que; // 4, 3, 2, 1 (defualt, less) : 
// if ( std::regex_match(S, std::regex("(dream|dreamer|erase|eraser)*")) ) std::cout << "YES" << std::endl;

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

using ll = long long;

ll gcd ( ll a, ll b ) { if ( b == 0 ) return a; else return gcd ( b, a%b ); }
ll lcm ( ll a, ll b ) { return a * b / gcd(a, b); }

int main (void) {
  std::cin.tie(0);  std::ios::sync_with_stdio(false);
  ll N, k; std::cin >> N >> k;
  std::vector<ll> A(N); rep(i,N) std::cin >> A[i];

  std::vector<std::string> ans;
  int zero = 0;
  for(int x=0; x<N; x++) {
    if ( x < k ) {
      if ( A[x] == 0 ) zero++;
    }
    else {
      if ( zero == 1 && A[x-k] == 0 && A[x] != 0 ) {
        ans.push_back( "Yes" );
        goto LAST;
      }
      if ( zero == 1 && A[x-k] == 0 && A[x] == 0 ) {
        ans.push_back( "No" );
        goto LAST;
      }
      if ( zero > 0 ) {
        ans.push_back( "No" );
        goto LAST;
      }
      if ( zero == 0 ) {
        if ( A[x-k] < A[x] ) ans.push_back( "Yes" );
        else ans.push_back( "No" );
        goto LAST;
      }
LAST:
      if ( A[x-k] == 0 ) zero--;
      if ( A[x] == 0 ) zero++;
    }
  }

  for(auto&& s : ans) std::cout << s << std::endl;
  return 0;
}



Measured memory_bytes: 13156
#include<iostream>
using namespace std;
int N;
int A[2<<17];
main()
{
	cin>>N;
	int now=1;
	for(int i=0;i<N;i++)
	{
		cin>>A[i];
		if(A[i]==now)
		{
			now++;
		}
	}
	cout<<(now==1?-1:N-now+1)<<endl;
}


Measured memory_bytes: 1024
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <set>
using namespace std;
int main(void){
    int a,b,c,d;
    cin>>a>>b>>c>>d;
    if((a+b)>(c+d))cout<<"Left"<<endl;
    else if((a+b)==(c+d))cout<<"Balanced"<<endl;
    else cout<<"Right"<<endl;
    return 0;
}


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

using std::unordered_set;
using std::vector;

int get_root(vector<int>& root, int x)
{
  if (root.at(x) == x) {
    return x;
  }
  int res = get_root(root, root.at(x));
  root.at(x) = res;
  return res;
}

void connect(vector<int>& root, int x, int y)
{
  int xroot = get_root(root, x);
  int yroot = get_root(root, y);
  root.at(xroot) = yroot;
}

int main()
{
  int ncards, nrules;
  std::cin >> ncards >> nrules;

  // init root
  vector<int> root(ncards);
  for (int i = 0; i < ncards; i++) {
    root.at(i) = i;
  }

  for (int i = 0; i < nrules; i++) {
    int x, y, z;
    std::cin >> x >> y >> z;
    connect(root, x-1, y-1);
  }

  unordered_set<int> root_set;
  for (int r : root) {
    root_set.insert(get_root(root, r));
  }
  std::cout << root_set.size() << '\n';
  return 0;
}


Measured memory_bytes: 4772
#include <bits/stdc++.h>
#define int long long
#define double long double
using namespace std;
const int N = 100010;
const int INF = 1LL<<55;
const int mod = (1e9)+7;
const double EPS = 1e-8;
const double PI = 6.0 * asin(0.5);
typedef pair<int,int> P;
typedef long long ll;
ostream& operator<<(ostream& o,P p){return o<<"("<<p.first<<","<<p.second<<")";}
istream& operator>>(istream& i,P &p){return i>>p.first>>p.second;}
template<class T> istream& operator>>(istream& i,vector<T> &a){for(auto &t:a)cin>>t;return i;}
template<class T> T Max(T &a,T b){return a=max(a,b);}
template<class T> T Min(T &a,T b){return a=min(a,b);}
template<class T> void prArr(T a,string s=" "){int i=0;for(auto t:a)cout<<(i++?s:"")<<t;cout<<endl;}

class TSort{
public:
  int V;
  vector<set<int> > in,out;
  deque<int> sorted;
  TSort():V(0){}
  TSort(int V):V(V),in(V),out(V){}
  
  void add_edge(int from,int to){
    assert(from < V && to < V);
    out[from].insert(to);
    in[to].insert(from);
  }

  vector<int> visited;
  void dfs_sort(int pos = -1){
    if(pos == -1){
      sorted.clear(),visited.clear(),visited.resize(V,0);
      for(int i=0;i<V;i++) dfs_sort(i);
      return;
    }

    if(visited[pos]++) return;
    for(int nx:out[pos]) dfs_sort(nx);
    sorted.push_front(pos);
  }

  void bfs_sort(){
    vector<set<int> > tmp = in;
    sorted.clear();
    queue<int> Q;
    for(int i=0;i<V;i++)if(in[i].empty()) Q.push(i);
    
    while(!Q.empty()){
      int v = Q.front();Q.pop();
      sorted.push_back(v);
      for(int nx:out[v]){
        if(in[nx].size() == 1) Q.push(nx);
        in[nx].erase(v);
      }     
    }
    swap(in,tmp);
    for(int i=0;i<V;i++) if(!tmp[i].empty()) sorted.clear(); // exist loop
  }
};


map<int,int> M[N];

signed main(){
  int n,m;
  cin>>n>>m;

  typedef pair<P,int> PP;
  vector<PP> A(m);

  for(int i=0;i<m;i++) cin>>A[i].first>>A[i].second, 
                         A[i].first.first--,A[i].first.second--;
  
  TSort T(n);
  for(int i=0;i<m;i++){
    auto pp = A[i];
    int L = pp.first.first;
    int R = pp.first.second;
    int D = pp.second;
    T.add_edge(L,R);
  }
  
  T.bfs_sort();
  sort(A.begin(),A.end());

  int ans = 1;
  ans &= !T.sorted.empty();
  for(auto pp:A){
    int L = pp.first.first;
    int R = pp.first.second;
    int D = pp.second;
    if(M[L].count(R)) ans &= M[L][R] == D;
    if(M[R].count(L)) ans &= M[R][L] == -D;
    M[L][R] = D;
    M[R][L] = -D;
  }

  map<int,int> X;
  int update = 1;
  while(update && ans){
    update = 0;
    for(int i:T.sorted)
      for(auto p:M[i]){
        int L = i;
        int R = p.first;
        int D = p.second;
        if(X.count(L) && X.count(R)){
          ans &= (X[L] + D == X[R]);
          continue;
        }
        else if(!X.count(L) && !X.count(R)) X[L] = 0,X[R] = D;
        else if(!X.count(L)) X[L] = X[R] - D;
        else if(!X.count(R)) X[R] = X[L] + D;
        update = 1;
      }
  }
  cout<<(ans? "Yes":"No")<<endl;
  
  return 0;
}


Measured memory_bytes: 79152
#include <stdio.h>
int main(){
  int n, x, a[101],i,j,k,l,c[300],d;
  a[0] = 0;
  d = 0;
  l = 0;
  for(i=1;i<101;i++){
    a[i] += 1;
  }

  for(i=0;i<300;i++){
    c[i] = 0;
  }
  for(i=1;i<101;i++){
    a[i] = a[i-1]+1;
  }
  while(1){
  scanf("%d %d",&n,&x);
  if(n==0&&x==0)
  break;

  for(i=1;i<n-1;i++){
    for(j=i+1;j<n;j++){
      for(k=j+1;k<n+1;k++){
        if(x==(a[i] + a[j] + a[k])){
          c[l] += 1;
        }
      }
    }
  }
  l++;
}
for(i=0;i<l;i++){
    printf("%d\n", c[i]);
}
return 0;
}



Measured memory_bytes: 2108
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MOD=1000000007;

int main(){
    ll N, K;
    cin>>N>>K;
    vector<ll> p(N);
    for(int i=0; i<N; i++){
        cin>>p[i];
    }
    vector<ll> R(N);
    R[0]=p[0]+1;
    for(int i=1; i<N; i++){
        R[i]=R[i-1]+p[i]+1;
      	
    }
    ll Max=R[K-1];
    for(int i=0; i<N-K; i++){
        Max=max(Max, R[i+K]-R[i]);
      	//cout<< R[i+K]-R[i]<<endl;
    }
  	long double Ans=Max;
  	Ans/=2;
    cout<<fixed<<setprecision(10)<<Ans<<endl;
  	return 0;
}

Measured memory_bytes: 3328
class UnionFind
    attr_reader :parent

    def initialize(size)
      @rank = Array.new(size, 0)
      @parent = Array.new(size, &:itself)
    end
  
    def unite(id_x, id_y)
      x_parent = get_parent(id_x)
      y_parent = get_parent(id_y)
      return if x_parent == y_parent
  
      if @rank[x_parent] > @rank[y_parent]
        @parent[y_parent] = x_parent
      else
        @parent[x_parent] = y_parent
        @rank[y_parent] += 1 if @rank[x_parent] == @rank[y_parent]
      end
    end
  
    def get_parent(id_x)
      @parent[id_x] == id_x ? id_x : (@parent[id_x] = get_parent(@parent[id_x]))
    end
  
    def same_parent?(id_x, id_y)
      get_parent(id_x) == get_parent(id_y)
    end
end

N,M,K=gets.split.map(&:to_i)

uf = UnionFind.new(N+1)
ret = Array.new(N+1, 0)
M.times do
    a,b = gets.split.map(&:to_i)
    uf.unite(a,b)
    ret[a] -= 1
    ret[b] -= 1
end
K.times do
    c,d = gets.split.map(&:to_i)
    if uf.same_parent?(c,d)
        ret[c] -= 1
        ret[d] -= 1
    end
end
counts = Array.new(N+1,0)
1.upto(N) do |i|
    uf.get_parent(i)
end
uf.parent.group_by {|e| e}.each do |k,v|
    counts[k] = v.length
end
1.upto(N) do |i|
    ret[i] += counts[uf.get_parent(i)] - 1
end

puts ret[1..-1].join(' ')

Measured memory_bytes: 26644
import java.util.*;

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();
	
		System.out.println(check(A) ? "YES" : "NO");
		sc.close();
	}
	
	static boolean check(int[] A) {
		int N = A.length;
		long sum = 0;
		for(int i=0; i<N; i++)
			sum += A[i];
		
		if(sum%((long)N*(N+1)/2)!=0)
			return false;
		
		int op = (int)(sum/((long)N*(N+1)/2));
		
		for(int i=0; i<N; i++) {
			int diff = A[(i+1)%N]-A[i];
			if((diff>op))
				return false;
			if((op-diff)%N!=0)
				return false;
		}
		
		return true;
	}
}


Measured memory_bytes: 33816
#include<bits/stdc++.h>
using namespace std;
#define rep(i,j,n) for(int i=(int)(j);i<(int)(n);i++)
#define REP(i,j,n) for(int i=(int)(j);i<=(int)(n);i++)
#define MOD 1000000007
#define int long long
#define ALL(a) (a).begin(),(a).end()
#define vi vector<int>
#define vii vector<vi>
#define pii pair<int,int>
#define priq priority_queue<int>
#define disup(A,key) distance(A.begin(),upper_bound(ALL(A),(int)(key)))
#define dislow(A,key) distance(A.begin(),lower_bound(ALL(A),(int)(key)))
#define tii tuple<int,int,int>
#define Priq priority_queue<int,vi,greater<int>>
#define pb push_back
#define mp make_pair
#define INF (1ll<<60)
signed main(){
  string S; cin>>S;
  cout<<S.substr(0,S.size()-8)<<endl;
  }


Measured memory_bytes: 256
N,M=map(int,input().split())
path_matrix=[]
for i in range(N):
    path_matrix.append([False]*N)

for i in range(M):
    a,b=map(int,input().split())
    path_matrix[a-1][b-1]=True
    path_matrix[b-1][a-1]=True
view=[False]*N

def path(x,depth):
    if view[x-1]:
        return False
    
    if depth==N-1:
        return True

    view[x-1]=True
    total_ans=0
    for i in range(N):
        if path_matrix[x-1][i]:
            total_ans+=int(path(i+1,depth+1))
    
    view[x-1]=False

    return total_ans

print(path(1,0))

Measured memory_bytes: 9052
#include <bits/stdc++.h>
#include <iostream>
#define ll long long
#define pb push_back
#define for0(i, n) for (int i = 0; i < n; i++)
#define mp make_pair
using namespace std;

#define nl '\n'
#define dbg(...) cout << "[" << #__VA_ARGS__ << "]: ", cout << to_string(__VA_ARGS__) << endl
/*compact version*/
template <typename T, size_t N> int SIZE(const T (&t)[N]) { return N; } template<typename T> int SIZE(const T &t) { return t.size(); } string to_string(string &s, int x1 = 0, int x2 = 1e9) { return '"' + ((x1 < s.size()) ? s.substr(x1, x2 - x1 + 1) : "") + '"'; } string to_string(const char* s) { string tmp(s); return to_string(tmp); } string to_string(bool b) { return (b ? "true" : "false"); } string to_string(char c) { return string({c}); } template<size_t N> string to_string(bitset<N> &b, int x1 = 0, int x2 = 1e9) { string t = ((x1 < b.size()) ? (b.to_string()).substr(x1, x2 - x1 + 1) : ""); reverse(begin(t), end(t)); return '"' + t + '"'; } template <typename A, typename... C> string to_string(A (&v), int x1 = 0, int x2 = 1e9, C... coords); int l_v_l_v_l = 0, t_a_b_s = 0; template <typename A, typename B> string to_string(pair<A, B> &p) { l_v_l_v_l++; string res = "(" + to_string(p.first) + ", " + to_string(p.second) + ")"; l_v_l_v_l--; return res; } template <typename A, typename... C> string to_string(A (&v), int x1, int x2, C... coords) { int rnk = rank<A>::value; string tab(t_a_b_s, ' '); string res = ""; bool first = true; if (l_v_l_v_l == 0) res += nl; res += tab + "["; x1 = min(x1, SIZE(v)), x2 = min(x2, SIZE(v)); auto l = begin(v); advance(l, x1); auto r = l; advance(r, (x2 - x1) + (x2 < SIZE(v))); for (auto e = l; e != r; e = next(e)) { if (!first) { res += ", "; } first = false; l_v_l_v_l++; if (e != l) { if (rnk > 1) { res += nl; t_a_b_s = l_v_l_v_l; }; } else { t_a_b_s = 0; } res += to_string(*e, coords...); l_v_l_v_l--; } res += "]"; if (l_v_l_v_l == 0) res += nl; return res; }
/*end of compact version*/
void prl(int x) {cout << x << endl;}

void init() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    #ifndef ONLINE_JUDGE
        freopen("input1.txt", "r", stdin);
        freopen("output1.txt", "w", stdout);
    #endif
}

const int N = 2e5 + 9, M = 4e5 + 9, OO = 0x3f3f3f3f;
const ll llOO = 0x3f3f3f3f3f3f3f3f;

int mod[2019];

int main() {
    init();

    string s;   cin >> s;
    reverse(s.begin(), s.end());

    int n = s.size();

    ll x = 0, ans = 0;

    mod[0]++;
    for (ll i = 0, p = 1; i < n; i++) {
        x = p * (s[i] - '0') + x;

        x %= 2019;

        ans += mod[x]++;
        // dbg(ans);
        // dbg(x);
        p = (p * 10) % 2019;
        // dbg(p);
    }

    cout << ans<<endl;
    return 0;
}


Measured memory_bytes: 3728
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const ll MOD = 998244353;
int dist[1000][1000];
int main() {
	int H, W;
	cin >> H >> W;
	vector<string> A(H);
	for (int i = 0; i < H; i++) {
		cin >> A[i];
	}
	fill((int*)dist, (int*)(dist + 1000), 1 << 30);
	queue<P> Q;
	for (int i = 0; i < H; i++) {
		for (int j = 0; j < W; j++) {
			if (A[i][j] == '#') {
				dist[i][j] = 0;
				Q.emplace(i, j);
			}
		}
	}
	int dx[] = { 1,0,-1,0 };
	int dy[] = { 0,1,0,-1 };
	while (!Q.empty()) {
		P p = Q.front(); Q.pop();
		for (int i = 0; i < 4; i++) {
			int ny = p.first + dy[i], nx = p.second + dx[i];
			if (0 > ny || ny >= H || 0 > nx || nx >= W || dist[ny][nx] != 1 << 30) continue;
			dist[ny][nx] = dist[p.first][p.second] + 1;
			Q.emplace(ny, nx);
		}
	}
	int ans = 0;
	for (int i = 0; i < H; i++) {
		for (int j = 0; j < W; j++) {
			ans = max(ans, dist[i][j]);
		}
	}
	cout << ans << endl;
}


Measured memory_bytes: 13456
#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 repm(i,m,n) for (int i = m; i < (n); i++)
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using pii = pair<int, int>;
 
int main() {
  string S;
  cin >> S;
  
  int ans = 700;
  rep(i,S.size()) {
    if (S.at(i) == 'o') ans += 100;
  }
  
  cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long int lli;
typedef unsigned long long int ulli;
typedef long double ld;
const lli INF = 1e9 + 100;
const lli INF64 = (1LL << 61) + 100;
const lli MOD = 1e9 + 7;
const lli MH1 = 1599614977, MH2 = 2034417103, MH3 = 1090250123, MH4 = 2024491871; 
lli bpow(lli baseee, lli exponenttt) {
	if(exponenttt < 0) return 0;
	lli res = 1;
	baseee %= MOD;
	while (exponenttt > 0) {
		if ((exponenttt & 1) == 1) res = (res*baseee) % MOD;
		baseee = (baseee*baseee) % MOD;
		exponenttt >>= 1;
	}
	return res;
}
lli multInverse(lli a) {//if_mod_is_prime
	return bpow(a, MOD - 2);
}
lli divm(lli a, lli b) {//if_mod_is_prime
	return (a * multInverse(b)) % MOD;
}
lli multm(lli a, lli b) {
	return (a * b) % MOD;
}
lli subm(lli a, lli b) {
	a += MOD;
	lli r = a - b;
	if(r >= MOD) return r - MOD;
	return r;
}
lli addm(lli a, lli b) {
	lli r = a + b;
	if(r >= MOD) return r - MOD;
	return r;
}
signed main() {
	ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	//	freopen("input.txt", "r", stdin);
	//	freopen("output.txt", "w", stdout);
	int a[6];
	for(int i= 1; i <= 5; i++) cin >> a[i];
	for(int i = 1; i <= 5; i++) {
		if(a[i] == 0) {
			cout << i << "\n";
			return 0;
		}
	}
	
	return 0;
}

Measured memory_bytes: 3596
#include <stdio.h>
int arr[101][101];

int main(){

  int i,j,num,len,m,k;

  scanf("%d",&num);

  for(i = 0 ; i < num ; i ++){
    for(j = 0 ; j < num ; j++){
      arr[i][j] = 0;
    }
  }

  for(i = 0 ; i < num ; i++){
    
    scanf("%d%d",&m,&len);
   
    for(j = 0 ; j < len ; j++){
   
      scanf("%d",&k);
    
      arr[i][k-1] = 1;
   
    }
  }

  for(i = 0 ; i < num ; i++){
    for(j = 0 ; j < num-1 ; j++){
      printf("%d ",arr[i][j]);
    }
    printf("%d\n",arr[i][j]);
  }
  return 0;
}

Measured memory_bytes: 636
#include <cmath>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <queue>
#include <iostream>
#include <map>
using std::min; using std::max;
using std::swap; using std::sort;
using std::deque; using std::map;
typedef long long ll;
typedef std::pair<int, int> pii;

template<typename T>
void read(T &x) {
	int flag = 1; x = 0; char ch = getchar();
	while(ch < '0' || ch > '9') { if(ch == '-') flag = -flag; ch = getchar(); }
	while(ch >= '0' && ch <= '9') x = x * 10 + ch - '0', ch = getchar();
	x *= flag;
}

const int _ = 4e6 + 10, __ = 5e5 + 10;
int n, m, dis[__], poi;
int cnt, from[__], to[_], nxt[_], wd[_];
inline void addEdge(int u, int v, int w) {
	to[++cnt] = v, nxt[cnt] = from[u], from[u] = cnt, wd[cnt] = w;
}
deque<int> q;
map<int, int> f[__];

void doit() {
	q.push_back(1);
	while(q.size()) {
		int u = q.front(); q.pop_front();
		for(int i = from[u]; i; i = nxt[i]) {
			int v = to[i], w = dis[u] + wd[i];
			if(w < dis[v]) {
				dis[v] = w;
				if(wd[i] == 0) q.push_front(v);
				else q.push_back(v);
			}
		}
	}
}

int main () {
	read(n), read(m), poi = n;
	for(int i = 1, u, v, c; i <= m; ++i) {
		read(u), read(v), read(c);
		if(f[v].find(c) != f[v].end()) swap(v, u);
		if(f[u].find(c) != f[u].end()) {
			if(f[v].find(c) == f[v].end()) {
				int p = f[u][c]; f[v][c] = p;
				addEdge(v, p, 1), addEdge(p, v, 0);
			} else {
				int p = f[u][c], q = f[v][c];
				addEdge(p, q, 0), addEdge(q, p, 0);
			}
		} else {
			++poi; f[u][c] = poi, f[v][c] = poi;
			addEdge(u, poi, 1), addEdge(poi, u, 0);
			addEdge(v, poi, 1), addEdge(poi, v, 0);
		}
	}
	memset(dis + 1, 63, sizeof dis[0] * poi); int Inf = dis[n];
	dis[1] = 0, doit(), printf("%d\n", dis[n] == Inf ? -1 : dis[n]);
	return 0;
} 


Measured memory_bytes: 60288
#include<iostream>
#include<algorithm>

using namespace std;

int main() {
	long long n, k;
	cin >> n >> k;
	int* a = new int[n];
	int* arrive = new int[n];
	int* city = new int[n];
	for (int i = 0;i < n;i++) {
		city[i] = -1;
		cin >> a[i];
	}
	int now = 0;
	city[0] = 0;
	arrive[0] = 1;
	long long I, J;
	for (int i = 1;i <= n;i++) {
		if (city[a[now] - 1] == -1) {
			city[a[now] - 1] = i;
			now = a[now] - 1;
			arrive[i] = now + 1;
		}
		else {
			I = city[a[now] - 1];
			J = (long long)i;
			if (k <= I) {
				cout << arrive[k] << endl;
			}
			else {
				cout << arrive[I + (k - I) % (J - I)] << endl;
			}
			break;
		}
	}

}

Measured memory_bytes: 5500
// problem: "https://atcoder.jp/contests/abc151/tasks/abc151_e"

#include<bits/stdc++.h>
#define ll long long
#define p (ll)(1e9+7)

using namespace std;

ll power(ll a,ll n)
{
    if(n == 0)
        return 1;

    ll b = 1;
    if(n%2)
        b = a;

    ll ans = power(a,n/2);
    ans = ((ans*ans)%p * b)%p;

    return ans;
}

void calc_nCr(ll n,ll k,vector<ll>&C)
{
    ll i,b;
    C[k] = 1;
    for(i=k+1;i!=n+1;i++)
    {
        b = power(i-k,p-2);     // define
        C[i] = ((C[i-1]*i)%p * b)%p;
    }
}


int main()
{
    ll n,k;
    cin>>n>>k;

    vector<ll>C(n+1,0);
    calc_nCr(n,k-1,C);

    ll i,x;
    vector<ll>V;
    for(i=0;i!=n;i++)
    {
        cin>>x;
        V.push_back(x);
    }

    sort(V.begin(),V.end());

    ll Min,Max,j;
    j = n-1;
    Min = 0;

    for(i=0;j>=k-1;i++,j--)
        Min += (V[i]*C[j])%p;

    Max = 0;
    j = n-1;
    for(i=n-1;j>=k-1;i--,j--)
        Max += (V[i]*C[j])%p;

    cout<<(Max-Min+p)%p;

    return 0;
}


Measured memory_bytes: 2168
#include<bits/stdc++.h>
using namespace std;
int main(){
  
  string s;
  cin >> s;
  
  int n = s.size();
  bool jad = true;
  for(int i = 0 ; i < n ; i++){
    if(i % 2 == 0){
      if(s.at(i) == 'L'){
        jad = false;
        break;
      }
    }
    else{
      if(s.at(i) == 'R'){
        jad = false;
        break;
      }
    }
  }
  
  if(jad){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
}
        


Measured memory_bytes: 256
from itertools import permutations as p


INF = float('inf')
N, M, R = map(int, input().split())
r = list(map(lambda x:int(x) - 1, input().split()))
dist = [[INF] * N for _ in range(N)]

for i in range(N):
    dist[i][i] = 0

for _ in range(M):
    A, B, C = map(int, input().split())
    A, B = A - 1, B - 1
    dist[A][B] = dist[B][A] = C


def main():
    for k in range(N):
        for i in range(N):
            for j in range(N):
                dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j])

    ans = INF
    for combi in p(r, R):
        temp = 0
        for i in range(R - 1):
            cost = dist[combi[i]][combi[i + 1]]
            if cost < INF:
                temp += cost
            else:
                break
        else:
            ans = min(ans, temp)

    print(ans)


if __name__ == "__main__":
    main()

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

using namespace std;

vector<int> yakusu(int x) {
	int waru = 1;
	vector<int> ret;
	while (waru * waru <= x) {
		if (x % waru == 0) {
			ret.push_back(waru);
			if (x != waru * waru)ret.push_back(x / waru);
		}
		waru++;
	}
	return ret;
}

int main() {
	int N;
	bool A[2 * 100000 + 1];
	int cnt[2 * 100000 + 1] = {};
	vector<int> ans;
	cin >> N;
	for (int i = 1; i <= N; i++)cin >> A[i];

	for (int i = N; i > 0; i--) {
		if ((!A[i]) ^ (cnt[i] % 2 == 0)) {
			auto v = yakusu(i);
			for (int j = 0; j < v.size(); j++)cnt[v[j]]++;
			ans.push_back(i);
		}
	}
	cout << ans.size() << endl;
	for (int i = 0; i < ans.size(); i++)cout << ans[i] << " ";
	cout << endl;

	return 0;
}

Measured memory_bytes: 2680
#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 ll long long
#define si(n) scanf("%d",&n);
#define PI acos(-1.0)
#define sl(n) scanf("%lld",&n);
#define sf(n) scanf("%lf",&n);
#define ss(n) scanf("%s",n);
#define for0(i,n) for(ll i=0;i<n;i++)
#define for1(i,n) for(ll i=1;i<=n;i++)
#define forc(i,j,n) for(ll i=j;i<n;i++)
#define pb push_back
#define sor(n) sort(n.begin(),n.end())
#define sorcmp(n) sort(n.begin(),n.end(),cmp)
#define rev(n) reverse(n.begin(),n.end())
#define pi(x)  printf("%d",x);
#define pl(x)  printf("%lld",x);
#define pf(x)  printf("%.10lf",x);
#define ps(x)  printf("%s",x);
#define en() printf("\n");
#define random_shuffle(r...)random_shuffle(r,[](int _){return rand()%_;})
#define SQR(a) (a)*(a)
#define sp(x) fixed<<setprecision(x)
#define mod 1000000007
#define endl '\n'
#define pii pair<int,int>
#define pll pair<ll,ll>
#define bug cout<<"Here"<<endl
void fastio(){ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);}
template <typename T> T POW(T B,T P){ if(P==0) return 1; if(P&1) return B*POW(B,P-1);  else return SQR(POW(B,P/2));}
ll powmod(ll a, ll b){ll ans = 1;while(b){if(b&1) ans = ans*a%mod;a = a*a%mod;b >>= 1;}return ans;}

int main(){

   int n;
   cin>>n;
   string str;
   cin>>str;
   int sz=str.size();

   if(sz>n)
   {
       for(int i=0;i<sz;i++)
       {
           if(i<n) cout<<str[i];
           else break;

       }

       cout<<"..."<<endl;
   }
   else cout<<str<<endl;




return 0;
}



Measured memory_bytes: 3564
#include <bits/stdc++.h>
#define fin ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define ii pair<int,int>
#define F first
#define S second
#define pb push_back
#define pf push_front
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define fore(i,a,b) for(int i = a;i < b; i+= 1)
#define forr(i,a) for(int i = a; i >= 0; i--)
#define fori(i,m) for(auto i = m.begin(); i != m.end(); i++) 
#define w(t) while(t--)
#define sz(s) int(s.size())
#define cls(a,car) memset(a,car,sizeof (a))
#define what_is(x) cerr << #x << " is " << x << endl;
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ii> vii;
const int N = 1 * 1e5 + 5;
const ll mod = 1e6 + 3;
const int INF = INT_MAX;
const ll INFCAD  = ll(INT_MAX) * 2 + 1;
const double E = 1e-9;
int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1};
// fflush(stdout)
// cout << flush
// a + b = a ^ b + 2 * (a & b)
ll a, b;
ll f(int x){
    return  floor((a * x) / b) - (a * floor(x / b));
}
int main(){
    //freopen("in","r",stdin);
    //freopen("out","w",stdout);
    fin;
    ll x;
    cin >> x;
    ll sum = 100;
    int time = 0;
    while(sum < x){
        sum += sum * 0.01;
        time++;
    }
    cout << time << '\n';
    cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";

    return 0;
}   

Measured memory_bytes: 3800
import java.math.BigInteger;
import java.util.*;

class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		BigInteger input = new BigInteger(sc.next());
		BigInteger neck = new BigInteger(sc.next());
		for(int i = 0; i < 4; i++) {
			neck = neck.min(new BigInteger(sc.next()));
		}
		BigInteger ans;
		if(neck.compareTo(input) == -1) {
			ans = input.add(neck).subtract(BigInteger.ONE).divide(neck).add(new BigInteger("4"));
		}else {
			ans = new BigInteger("5");
		}
		System.out.println(ans.toString());
	}
}




Measured memory_bytes: 21844
//  cout << char(i+48) << endl;//なぜかaは47と得る時がある。+48で出力もaにできる。
//  cout << char(97) << endl;//アスキーコードでaを出力
// sort(b.begin(), b.end());//bという配列を小さい方からソート
// reverse(b.begin(), b.end());//bという配列をリターン
// 10桁でdouble出力するパターン１ 
// printf("%.10f\n", ma);
// 10桁でdouble出力するパターン２
//cout << fixed << setprecision(10);
//  cout << ma << endl;

/*01 02 03 12 13 23　と６回見ていくパターン 
for(int i=0;i<n-1;i++){
  for(int j=i+1;j<n;j++){
    }
  }
*///vector<vector<int>> data(3, vector<int>(4));//int型の2次元配列(3×4要素の)の宣言
//int64_t a;
//10のi乗pow(10, i);
/*string s; stringでの文字列を数字型に変える方法
  cin >> s;
  rep(i,s.size()-2) {
  int a= (s.at(i)-'0')*100 + (s.at(i+1)-'0')*10+ s.at(i+2) -'0';
    */
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main() {
  ll x,y;
  cin >> x >> y;
  int count = 1;
  for(;;){
    x = x*2;
    if(x>y)break;
    count++;
  }
  cout << count << endl;
}

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

int main(){
  int a,b;
  cin>>a>>b;
  if(b%a==0) cout<<a+b<<endl;
  else cout<<b-a<<endl;
}

Measured memory_bytes: 256
def gcd(x, y):
    if x == 0:
        return y
    if x == 1 or y == 1:
        return 1
    
    return gcd(y % x, x)


k = int(input())
ans = 0
for a in range(1, k+1):
    for b in range(1, k + 1):
        r = gcd(a, b)
        for c in range(1, k + 1):
            ans += gcd(r, c)

print(ans)

Measured memory_bytes: 9080
#include<bits/stdc++.h>
#define ll          long long
#define pb          push_back
#define mp          make_pair
#define pii         pair<int,int>
#define vi          vector<int>
#define all(a)      (a).begin(),(a).end()
#define sz(x)       (int)x.size()
#define hell        1000000007
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
using namespace std;

int main()
{
	string s;
	cin>>s;
	int a[26]={0};
	for(int i=0;i<s.size();i++)
	{
		a[s[i]-'a']=1;
	}
	for(int i=0;i<26;i++)
	{
		if(a[i]==0)
		{
			cout<<char(97+i);
			return 0;
		}
	}
	cout<<"None";
}

Measured memory_bytes: 512
#!/usr/bin/env python3
# sys.stdin.readline()
"""
import sys
input = sys.stdin.readline
import math
N = int(input())
n,m,q = map(int,input().split())
A = [list(map(int,input().split())) for i in range(q)]
"""

n,k = map(int,input().split())
A = [i for i in range(1,n+1)]
for j in range(k):
    s = int(input())
    K = list(map(int,input().split()))
    for i in range(s):
        if K[i] in A:
            A.remove(K[i])
print(len(A))

Measured memory_bytes: 9188
n = int(input())
h = list(map(int, input().split()))

result = 'Yes'
h[0] -= 1
for i in range(1,n):
    if h[i-1] < h[i]:
        h[i] -= 1
    elif h[i-1] > h[i]:
        result = 'No'
        break

print(result)


Measured memory_bytes: 14396
#include <cstdio>
#include <iostream>
#include <string>
#include <cstdlib>
#include <vector>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <stdlib.h>
using namespace std;

int main()
{
	int h, w;
	for (int i = 0; i < 10000000; i++) {
		cin >> h >> w;
		if (h == 0 && w == 0) break;
		for (int j = 0; j < h; j++) {
			for (int t = 0; t < w; t++) {
				if (((j % 2 == 0 && t % 2 == 0)) || (j % 2 != 0 && t % 2 != 0)) {
					cout << "#";
				}
				else {
					cout << ".";
				}
			}
			cout << endl;
		}
		cout << endl;
	}
}


Measured memory_bytes: 3116
#include <bits/stdc++.h>
#include <ext/rope>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//#define int long long
#define pb push_back
#define x first
#define y second
#define mk(a,b) make_pair(a,b)
#define rr return 0
#define sqr(a) ((a)*(a))
#define all(a) (a).begin(), (a).end()
#define sz(a) (int)(a).size()

using namespace std;
using namespace __gnu_cxx;
using namespace __gnu_pbds;

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

template<class value, class cmp = less<value> >
using ordered_set = tree<value, null_type, cmp, rb_tree_tag, tree_order_statistics_node_update>;
template<class value, class cmp = less_equal<value> >
using ordered_multiset = tree<value, null_type, cmp, rb_tree_tag, tree_order_statistics_node_update>;
template<class key, class value, class cmp = less<key> >
using ordered_map = tree<key, value, cmp, rb_tree_tag, tree_order_statistics_node_update>;

/// find_by_order()
/// order_of_key()
mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count());
inline int randll(int l = INT_MIN, int r = INT_MAX) {
    return uniform_int_distribution<int>(l, r)(rng);
}
const int INF = 1e9, MOD = 1e9 + 7; /// think
const ll LINF = 1e18;


const int dx[] = {0, 0, 1, -1}, dy[] = {1, -1, 0, 0};
inline bool inside (int x, int y, int n, int m) {
    return 0 <= x && 0 <= y && x < n && y < m;
}

template<class T> bool umin (T &a, T b) {return a > b ? (a = b, true) : false; }
template<class T> bool umax (T &a, T b) {return a < b ? (a = b, true) : false; }


main()
{
    ios::sync_with_stdio(0);
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n;
    cin >> n;
    map <string, int> cnt;
    cnt["AC"] = 0;
    cnt["WA"] = 0;
    cnt["TLE"] = 0;
    cnt["RE"] = 0;
    string s;
    for (int i = 0; i < n; i++) {
        cin >> s;
        ++cnt[s];
    }
    cout << "AC x " << cnt["AC"] << '\n';
    cout << "WA x " << cnt["WA"] << '\n';
    cout << "TLE x " << cnt["TLE"] << '\n';
    cout << "RE x " << cnt["RE"] << '\n';
}


Measured memory_bytes: 3640
#include<bits/stdc++.h>
using namespace std;
 
int h,n;
int a[1005],b[1005];
int dp[1005][20005];
 
int main(){
 
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
 
    cin>>h>>n;
    memset(dp,0x3f,sizeof(dp));
    dp[0][0]=0;
    for(int i=0;i<n;i++){
        cin>>a[i]>>b[i];
        for(int j=0;j<=h+10000;j++){//由于可能伤害不是正好杀死，一定要预留一点伤害的量
            if(j+a[i]<=h+10000)dp[i][j+a[i]]=min(dp[i][j+a[i]],dp[i][j]+b[i]);
            dp[i+1][j]=dp[i][j];
        }
    }
    int ans=0x3f3f3f3f;
    for(int i=h;i<=h+10000;i++){
        ans=min(ans,dp[n][i]);
    }
    cout<<ans<<endl;
 
    return 0;
}

Measured memory_bytes: 78848
const input = require('fs').readFileSync('/dev/stdin', 'utf8');
const lines = input.trim().split('\n');

while (line = lines.shift()) {
	const [n, max] = line.split(' ').map(Number);

	if (n === 0 && max === 0) {break;}

	const prices = lines.shift().split(' ').map(Number);

	const allSum = [];

	prices.map((priceA, indexA) => {
			prices.map((priceB, indexB) => {
				if (indexA !== indexB) {
					const sum = priceA + priceB;

					if(sum <= max) {
						allSum.push(sum);
					}
				}
			})
		}
	);

	const answer = allSum.sort((a,b) => b - a)[0];

	if (answer) {
		console.log(answer);
		continue;
	}

	console.log('NONE');
}



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

int main()
{
	string s;
	cin >> s;
	int n = s.size();

	for (int i = 1; i < n; i++) {
		if (s[i - 1] == s[i]) {
			cout << i << " " << i + 1 << endl;
			return 0;
		}
		if (i > 1 && s[i - 2] == s[i]) {
			cout << i - 1 << " " << i + 1 << endl;
			return 0;
		}
	}

	cout << "-1 -1" << endl;
	return 0;
}


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

using namespace std;


#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define RFOR(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep1(i, n) for (int i = 1; i < (n); i++)
#define rrep(i, n) for (int i = (n)-1; i >= 0; i--)
#define all(i) (i).begin(), (i).end()
#define rall(i) (i).begin(), (i).end(), greater<int>()

#define int long long

#define elif else if
#define eb emplace_back
#define pb push_back
#define mp make_pair
#define fst first
#define sec second

#define mod 1000000007

template <typename T>
void print(T x)
{
	std::cout << x <<" " ;
}


template <typename T>
void println(T x)
{
	std::cout << x << "\n";
}


signed main(void) {
	int N;
	cin >> N;
	vector<int>A;
	A.resize(N);

	rep(i, N) {
		cin >> A[i];
	}
	int ans = 0;
	rep(i, N) {
		if (A[i] % 2 == 0) {
			if (A[i] % 3 == 0 || A[i] % 5 == 0) {
			continue;
			}
			else {
				ans = 1;
				break;
			}
		}
		
	}
	if (ans == 0) {
		print("APPROVED");
	}
	else {
		print("DENIED");
	}
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

class Que {
    int head, tail, length;
    Node[] Narray;

    public Que(int inputN) {
        head = -1;
        tail = -1;
        length = inputN;
        Narray = new Node[inputN];
    }

    public void enQue(Node node) {
        tail += 1;
        Narray[tail % length] = node;
    }

    public Node deQue() {
        head += 1;
        return Narray[head % length];
    }

    public boolean isEmpty() {
        if (head == tail)
            return true;
        else
            return false;
    }
}

class Node {
    String pName;
    public int time;

    public Node(String pName, int time) {
        this.pName = pName;
        this.time = time;
    }
}

class Main {
    public static void main(String[] args) {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

        String[] inputData;
        String[] nodeData;

        try {
            int totalTime = 0;
            inputData = br.readLine().split(" ");
            int n = Integer.parseInt(inputData[0]);
            int limitTime = Integer.parseInt(inputData[1]);
            Que q = new Que(n);
            Node tmpNode = null;
            for (int i = 0; i < n; i++) {
                nodeData = br.readLine().split(" ");
                q.enQue(new Node(nodeData[0], Integer.parseInt(nodeData[1])));
            }
            while (!q.isEmpty()) {
                tmpNode = q.deQue();
                if (tmpNode.time <= limitTime) {
                    totalTime += tmpNode.time;
                    System.out.printf("%s %d\n", tmpNode.pName, totalTime);
                } else {
                    totalTime += limitTime;
                    tmpNode.time -= limitTime;
                    q.enQue(tmpNode);
                }
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}


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

int main() {
    int N;
    cin >> N;
    vector<vector<int> > D(N, vector<int>(2, 0));

    for(int i = 0; i < N; i++) {
        cin >> D.at(i).at(0) >> D.at(i).at(1);
    }

    int count = 0;
    int i = 0;
    bool ans = false;
    while(i < N) {
        if(D.at(i).at(0) == D.at(i).at(1)) count += 1;
        else count = 0;
        if (count == 3) {
            ans = true;
            break;
        }
        i += 1;
    }

    if(ans) cout << "Yes" << endl;
    else cout << "No" << endl;
}

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

using namespace std;

const int maxn=1e5+5;

int n;
int l[maxn];

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	cin >> n;
	for(int i=0; i<n; i++){
		cin >> l[i];
	}
	int x=0;
	for(int i=1; i<n; i++){
		x=l[i]-x;
	}
	x=(x+l[0])/2;
	for(int i=0; i<n; i++){
		cout << x*2 << " ";
		x=l[i]-x;
	}
	cout << '\n';
	return 0;
}

Measured memory_bytes: 1792
N, M = map(int, input().split())

if N < 3 and M < 3:
    if N == M == 1:
        print(1)
    else:
        print(0)
elif N < 3 and M >= 3:
    if N == 1:
        print(N*(M-2))
    else:
        print(0)
elif N >=3 and M < 3:
    if M == 1:
        print(M*(N-2))
    else:
        print(0)
else:
    print((N-2)*(M-2))

Measured memory_bytes: 38384
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int s = sc.nextInt();
		int w = sc.nextInt();
		if (s <= w) {
			System.out.println("unsafe");
		} else {
			System.out.println("safe");
		}
	}
}


Measured memory_bytes: 35752
#include <stdio.h>
int main(void)
{
	char s[4];
	int t;
	int takahasi = 0;
	
	scanf("%s", s);
	
	for (t = 0; t < 4; t++){
		 if (s[t] == '+'){
		 	takahasi++;
		 }
		 
		 else if (s[t] == '-'){
		 	takahasi--;
		 }
		 
	}
	
	printf("%d", takahasi);
	
	return 0;
}


Measured memory_bytes: 128
N,D = map(int,input().split())
x_list = [list(map(int,input().split())) for _ in range(N)]

cnt = 0
x = 0

for i in range(N-1):
    for j in range(i+1,N):
        for k in range(D):
            x += (x_list[i][k]-x_list[j][k])**2
        if (x**0.5).is_integer():
            cnt += 1
        x = 0

print(cnt)

Measured memory_bytes: 3060
n=int(input())
l=[]
for i in range(n):
    l.append(list(map(str,input().split())))
a=0
for i in range(n):
    if l[i][1]=="JPY":
        a=a+int(l[i][0])
    else:
        a=a+float(l[i][0])*380000.0
print(float(a))


Measured memory_bytes: 2940
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <functional>

using namespace std;
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
#define VI vector<int>
#define debug(x) cout<<#x<<": "<<x<<endl
#define DEBUG(x) cout<<#x<<": "<<x<<endl
int A,B,C;





int main()
{

	cin >> A >> B >> C;

	long long ans = 0;
	if(A == B && B == C && A%2==0&&B%2==0&&C%2==0){
		cout << -1 << endl;
		return 0;
	}
	int tmpA,tmpB;
	while(A%2==0&&B%2==0&&C%2==0){
		tmpA = A;
		tmpB = B;
		A = B/2 + C/2;
		B = tmpA/2 + C/2;
		C =	tmpA/2 + tmpB/2;
		ans++;
	}

	cout << ans;





}

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

int main(void){
		int a,b,c,d;
		scanf("%d",&a);
    scanf("%d",&b);
    scanf("%d",&c);
    scanf("%d",&d);


      for(int i =0;i<205;i++){
        c = c-b;
        if(c<=0){
          break;
        }
        a = a-d;
        if(a<=0){
          break;
        }
      }

      if(a<=0){
        puts("No");
      }
      else{
        puts("Yes");
      }
		return 0;
}


Measured memory_bytes: 1616
#include<bits/stdc++.h>
using namespace std;
#define ll unsigned long long

int main(){
	int x, a;
	cin >> x >> a;
	int ans = -1;
	if(x < a)
		ans = 0;
	else
		ans = 10;
	cout << ans << endl; 
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int calc(int x) {
	int ret = 0;
	while(x % 100 == 0) {
		x /= 100;
		++ret;
	}
	return ret;
}
int main() {
	int D, N;
	cin >> D >> N;
	int cnt = 0, val = 0;
	while(cnt < N) {
		++val;
		if(calc(val) == D) ++cnt;
	}
	cout << val << '\n';
	return 0;
}


Measured memory_bytes: 256
#include <vector>
#include <iostream>
#include <cmath>
#include <map>
#include <unordered_map>
#include <algorithm>
#include <fstream>
#include <unistd.h>
#include <string>
#include <numeric>
#include <queue>
#include <deque>
#include <sstream>
#include <iomanip>
#include <set>
#include <stack>
#include <cassert>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<vvl> vvvl;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<bool> vb;
typedef vector<vector<bool>> vvb;
typedef vector<string> vs;
typedef vector<vector<string>> vvs;
typedef vector<char> vc;
typedef vector<vector<char>> vvc;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<vvd> vvvd;
typedef pair<int, int> P;
typedef pair<ll, ll> PL;
typedef vector<P> vp;
typedef vector<PL> vpl;
typedef vector<vector<P>> vvp;
typedef vector<vector<PL>> vvpl;
const int INF = 1001001001;
const ll LINF = 1e16;
const double pi = 3.1415926535897932;
const string endstr = "\n";
#define FOR(i, a, b) for(ll i = (a); i < b; i++)
#define REP(i, n) for(ll i = 0; i < n; i++)
#define FORMAP(it, m) for(auto it = m.begin(); it != m.end(); it++)
#define ff first
#define ss second
#define pb push_back

template <typename T>
T gcd(T a, T b) {
    return (a == 0) ? b : gcd(b%a, a);
}
template <typename T>
T lcm(T a, T b) {
    return a / gcd(a, b) * b;
}

bool p_comp_fs(const PL p1, const PL p2){ return p1.first < p2.first;};
bool p_comp_fg(const PL p1, const PL p2){ return p1.first > p2.first;};
bool p_comp_ss(const PL p1, const PL p2){ return p1.second < p2.second;};
bool p_comp_sg(const PL p1, const PL p2){ return p1.second > p2.second;};
template <typename T>
vector<T> uniquen(vector<T> vec){
    vec.erase(unique(vec.begin(), vec.end()), vec.end());
    return vec;
}

//priority_queue<ll, vector<ll>, greater<ll>> gpq;

ll nck(ll n, ll k){
    ll ans = 1;
    FOR(i, 1, k+1){
        ans *= n--;
        ans /= i;
    }
    return ans;
}

int main(){
    ll x, y; cin >> x >> y;
    cout << (x*y) /2 <<endl;
    return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define REP(i,a,b) for(int i=(a),_end_=(b);i<=_end_;i++)
#define DREP(i,a,b) for(int i=(a),_end_=(b);i>=_end_;i--)
#define EREP(i,a) for(int i=start[(a)];i;i=e[i].next)
template<class T>inline void chkmax(T &a,T b){ if(a<b)a=b;}
template<class T>inline void chkmin(T &a,T b){ if(a>b)a=b;}
inline int read(){
	int sum=0,p=1;char ch=getchar();
	while(!(('0'<=ch && ch<='9') || ch=='-'))ch=getchar();
	if(ch=='-')p=-1,ch=getchar();
	while('0'<=ch && ch<='9')sum=sum*10+ch-48,ch=getchar();
	return sum*p;
}
#define int ll
const int maxn=2e5+20;
const ll inf=1ll<<60;
int a[maxn],x[maxn],y[maxn],n,as[maxn],xs[maxn],ys[maxn],L[maxn],R[maxn];
signed main(){
	n=read();
	REP(i,1,n)a[i]=read(),x[i]=~a[i]&1,y[i]=a[i]<=2?2-a[i]:(a[i]&1);
	REP(i,1,n)xs[i]=xs[i-1]+x[i],ys[i]=ys[i-1]+y[i],as[i]=as[i-1]+a[i];
	L[0]=0;
	int mn=0;
	REP(i,1,n){
		chkmin(mn,as[i]-ys[i]);
		L[i]=mn+ys[i];
	}
	R[n]=0,mn=as[n]-as[n] + ys[n];
	DREP(i,n-1,0){
		chkmin(mn,as[n]-as[i]+ys[i]);
		R[i]=mn-ys[i];
	}
	int ans=inf;
	mn=inf;
	REP(i,0,n){
		chkmin(mn,L[i]-xs[i]);
		chkmin(ans,mn+R[i]+xs[i]);
	}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 12800
N = int(input())
S = []
ans = "0"
while(abs(N) > 0):
  S.append(str(abs(N % (-2))))
  N += N % (-2)
  N = N // (-2)
  
S.reverse()

if S == []:
  print(ans)
else:
  ans = ""
  for i in S:
    ans += i
    
  print(ans)
    
  

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define db(x) cerr << #x << "=" << x << endl
#define db2(x, y) cerr << #x << "=" << x << "," << #y << "=" << y << endl
#define db3(x, y, z) cerr << #x << "=" << x << "," << #y << "=" << y << "," << #z << "=" << z << endl
#define dbv(v) cerr << #v << "="; for (auto _x : v) cerr << _x << ", "; cerr << endl
#define dba(a, n) cerr << #a << "="; for (int _i = 0; _i < (n); ++_i) cerr << a[_i] << ", "; cerr << endl
typedef long long ll;
typedef long double ld;
int main() {
	int n;
	scanf("%d", &n);
	bool ans = false;
	for (int i = 0; i < n; ++i) {
		int a;
		scanf("%d", &a);
		if (a & 1) ans = true;
	}
	printf(ans ? "first\n" : "second\n");
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using P = pair<ll, ll>;
const ll INF = 1e16;

void solver(vector<vector<int>> const &grid, bool &flg){

    vector<int> a(3);
    vector<int> b(3);
    
    a.at(0) = 0;
    for(int i = 0; i != 3; ++i){
        b.at(i) = grid.at(0).at(i) - a.at(0);
    }
    for(int i = 0; i != 3; ++i){
        a.at(i) = grid.at(i).at(0) - b.at(0); 
    }

    for(int i = 0; i != 3; ++i){
        for(int j = 0; j != 3; ++j){
            if(grid.at(i).at(j) != a.at(i) + b.at(j)) flg = false;
        }
    }

    return;
}

int main(){

    vector<vector<int>> grid(3, vector<int>(3));
    for(int i = 0; i != 3; ++i){
        for(int j = 0; j != 3; ++j){
            cin >> grid.at(i).at(j);
        }
    }

    bool flg = true;
    solver(grid, flg);

    if(flg) cout << "Yes"s << endl;
    else cout << "No"s << endl;

    return 0;
}

Measured memory_bytes: 3600
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;

using ll = long long;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vvc = vector<vector<char>>;

#define rep(i, n) for (ll i = 0; i < ll(n); i++)
#define repd(i, n) for (ll i = n - 1; i >= 0; i--)
#define all(x) x.begin(), x.end()

using tu = tuple<string, int, int>;

bool comp(tu a, tu b) {
    if(get<0>(a) != get<0>(b)) {
        return get<0>(a) < get<0>(b);
    } else {
        return get<1>(a) > get<1>(b);
    }
}

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

    int n;
    cin >> n;

    vector<tu> spn(n, tu());
    rep(i, n) {
        cin >> get<0>(spn[i]) >> get<1>(spn[i]);
        get<2>(spn[i]) = i + 1;
    }

    sort(all(spn), comp);

    rep(i, n) {
        cout << get<2>(spn[i]) << endl;
    }
}

Measured memory_bytes: 3668
from math import sqrt
N, D = map(int, input().split())
X = []
for i in range(N):
  X.append(list(map(int, input().split())))

ans = 0
for i in range(N):
  for j in range(i+1, N):
    distance = sqrt(sum([(X[i][d]-X[j][d])**2 for d in range(D)]))
    if distance.is_integer():
      ans += 1
      
print(ans)

Measured memory_bytes: 3064