akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<math.h>
#include<iomanip>
 using namespace std;

 int main(){

 int a, b, c;

 cin>>a>>b>>c;

 int l;
 l=(c/a)*a;

 if(b<=l){cout<<"OK";}
 else{cout<<"NG";}
 }


Measured memory_bytes: 3540
with Ada.Text_IO; use Ada.Text_IO;
with Ada.Integer_Text_IO; use Ada.Integer_Text_IO;

procedure Solve is
   A : Integer;
   B : Integer;
   C : Integer;
begin
   Get (A);
   Get (B);
   Get (C);
   if A+B >= C then
      Put_Line ("Yes");
   else
      Put_Line ("No");
   end if;
end Solve;

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

using namespace std;

int main() {
    string S;
    int error = 0;

    cin >> S;
    for (int i = 0; i < 3; i++) {
        if (S[i] == S[i + 1]) {
            error++;
            break;
        }
    }

    if (error != 0) {
        cout << "Bad" << endl;
    } else {
        cout << "Good" << endl;
    }
}

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

int main(void){
    char S[11],T[11];
    int A,B;
    char U[11];
    int ans;

    scanf("%s",S);
    scanf("%s",T);
    scanf("%d",&A);
    scanf("%d",&B);
    scanf("%s",U);

    int i;
    while(U[i] != '\0'){
        if(U[i]!=S[i]){
            printf("%d %d",A,B-1);
            return 0;
        }
        i++;
    }

    printf("%d %d",A-1,B);

    return 0;
}

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

int main()
{
    int a1, b1, a2, b2, a3, b3 = 0;
    cin >> a1 >> b1;
    cin >> a2 >> b2;
    cin >> a3 >> b3;
    bool IsBreak = false;
    for(int i = 1; i <= 4; i++)
    {
        int a = 0;
        if(a1 == i || b1 == i)
        {
            a++;
        }
        if(a2 == i || b2 == i)
        {
            a++;
        }
        if(a3 == i || b3 == i)
        {
            a++;
        }
        if(a == 3)
        {
            IsBreak = true;
        }
    }
    if(IsBreak)
    {
    cout << "NO" << endl;

    }
    else
    {
    cout << "YES" << endl;
                
    }
    

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <bitset>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <complex>
#include <valarray>
#include <unordered_map>
#include <array>
#include <fstream>
#include <cassert>
#include <cmath>
#include <functional>
#include <iomanip>
#include <random>
#include <numeric>

#define INIT std::ios::sync_with_stdio(false);std::cin.tie(0);
#define rep(X,Y) for (int (X) = 0;(X) < (Y);++(X))
#define all(X) (X).begin(),(X).end()
#define fi first
#define sc second
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
const int INFINT = 1 << 30;                          // 1.07x10^ 9
const ll INFLL = 1LL << 60;                          // 1.15x10^18
const double EPS = 1e-10;
const int MOD = 1000000007;

string A;
vector<int> alpha[26];
bool apper[26];

int main() {
  cin >> A;
  int N = A.size();
  for (int i = 0; i < 26; ++i) {
    for (int j = 0; j < N; ++j) {
      if (A[j] == 'a'+i) alpha[i].push_back(j);
    }
  }

  for (int i = 0; i < 26; ++i) alpha[i].push_back(N);

  vector<int> S;
  memset(apper, false, 26);
  int count = 0;
  S.push_back(N);
  for (int i = N-1; i >= 0; --i) {
    if (!apper[A[i]-'a']) {
      apper[A[i]-'a'] = true;
      ++count;
    }
    if (count == 26) {
      S.push_back(i);
      count = 0;
      memset(apper, false, 26);
    } else if (i == 0) {
      S.push_back(0);
    }
  }


  reverse(all(S));
  string ans;
  for (int i = 0; i < 26; ++i) {
    if (!apper[i]) {
      ans += 'a'+i;
      break;
    }
  }

  int idx;
  idx = alpha[ans[0]-'a'][0];

  while (idx < N) {
    int ub = *upper_bound(all(S), idx);
    for (int i = 0; i < 26; ++i) {
      int next_char_idx = *upper_bound(all(alpha[i]), idx);
      if (next_char_idx >= ub) {
        ans += 'a'+i;
        idx = next_char_idx;
        break;
      }
    }
  }
  

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 1404
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define UNIQUE(v) v.erase(unique(all(v)), v.end());
#define ZIP(v) sort(all(v)),UNIQUE(v)
#define ADD(a, b) a = (a + b) % mod
#define MUL(a, b) a = (a * b) % mod
#define repi(i,m,n) for(int i = m;i < n;i++)
#define drep(i,n,m) for(int i = n;i >= m;i--)
#define rep(i,n) repi(i,0,n)
#define rrep(i,n) repi(i,1,n+1)
#define chmin(x,y) x = min(x,y)
#define chmax(x,y) x = max(x,y)
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(), v.rend()
#define dmp(x,y) make_pair(x,y)
#define pb(x) push_back(x)
#define fi first
#define se second
typedef pair<int,int> P;
typedef pair<int, P> PP;
typedef vector<int> vi;
const int inf = 1e9+7;
const int INF = 1e18+7;
//26

signed main(){
	string s, ans;
	int w, i = 0;
	cin >> s >> w;
	int n = s.size();
	while(i < n){
		ans.push_back(s[i]);
		i += w;
	}
	cout << ans << endl;
	return 0;
}






Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int a[200005]; 
long long n,sum;
long long v[200005];
int main(){
	cin>>n;
	for(int i=1; i<=n; i++)	{
		cin>>a[i];
		v[a[i]]++;
	}
	for(int i=1; i<=n; i++)
		sum=sum+v[i]*(v[i]-1)/2;
	for(int i=1; i<=n; i++)
		cout<<sum-v[a[i]]*(v[a[i]]-1)/2+(v[a[i]]-1)*(v[a[i]]-2)/2<<endl;
	return 0;
}


Measured memory_bytes: 3968
#include <stdio.h>
#include <string.h>
int main()
{
  int q,a,b;
  int i,j;
  char str[1001],strcp[1001],ins[8];
  scanf("%s",str);
  scanf("%d",&q);
  for(i=0;i<q;i++)
  {
    scanf("%s %d %d",ins,&a,&b);
    if(!strcmp(ins,"print"))
    {
      for(j=a;j<=b;j++)
      {
    printf("%c",str[j]);
    if(j==b)printf("\n");
      }
    }
    if(!strcmp(ins,"reverse"))
    {
      for(j=0;j<=(b-a)/2;j++)
      {
    char temp = str[a+j];
    str[a+j]=str[b-j];
    str[b-j]=temp;
      }
    }
    if(!strcmp(ins,"replace"))
    {
      char p;
      for(j=0;j<=b-a;j++)
      {
    scanf(" %c",&p);
    str[a+j]=p;
      }
    }
  }
  return 0;
}


Measured memory_bytes: 2112
#include <iostream>

int main()
{
    int N;
    std::cin >> N;
    int arr[2][N];
    int v[2][N];
    
    for(int i=0; i<2; i++)
    {
        for(int j=0; j<N; j++)
        {
            std::cin >> arr[i][j];
        }
        
    }
    
    
    for(int i=0; i<2; i++)
    {
        for(int j=0; j<N; j++)
        {
            int a=0,b=0;
            if((j-1)>=0){
                a=v[i][j-1] + arr[i][j];
                }
            
            if((i-1)>=0){
                b=v[i-1][j] + arr[i][j];
                }
            v[i][j] = std::max(std::max(a,b), arr[i][j]);
        }
    }
    
    std::cout << v[1][N-1] << std::endl;
    
    return 0;
}


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

int main() {
  int h, w;
  cin>>h>>w;
  string s[h];
  for (int i=-0; i<h; i++) cin>>s[i];
  for (int i=0; i<h; i++) {
    for (int j=0; j<w; j++) {
      int cnt = 0;
      if (s[i][j] == '.') {
        continue;
      }
      if (i > 0 && s[i-1][j] == '#') ++cnt;
      if (i < h-1 && s[i+1][j] == '#') ++cnt;
      if (j > 0 && s[i][j-1] == '#') ++cnt;
      if (j < w-1 && s[i][j+1] == '#') ++cnt;
      if (cnt == 0) {
        cout<<"No"<<endl;
        return 0;
      }
    }
  }
  cout<<"Yes"<<endl;
}

Measured memory_bytes: 256
n = int(input())
deg = [0]*n
child, parent = {}, {}
sib = [None]*n
for i in range(n):
    a = list(map(int, input().split()))
    if a[1] != -1:
        if a[2] == -1:
            child[a[0]] = [a[1]]
            sib[a[1]] = a[2]
            deg[a[0]] = 1
        else:
            child[a[0]] = a[1:]
            sib[a[1]] = a[2]
            sib[a[2]] = a[1]
            deg[a[0]] = 2
        for j in child[a[0]]:
            parent[j] = a[0]
    elif a[2] != -1:
        child[a[0]] = [a[2]]
        sib[a[2]] = a[1]
        deg[a[0]] = 1
        for j in child[a[0]]:
            parent[j] = a[0]
    else:
        child[a[0]] = []

root = (set(child)-set(parent)).pop()
depth = [None]*n
depth[root] = 0
hei = [None]*n
parent[root] = -1
sib[root] = -1

def dfs(s):
    if len(child[s]) == 0:
        hei[s] = 0
        return
    for i in child[s]:
        depth[i] = depth[s] + 1
        dfs(i)
    hei[s] = max(hei[i] for i in child[s]) + 1
    
    
dfs(root)

for i in range(n):
    node_type = 'root' if parent[i] == -1 else 'leaf' if len(child[i]) == 0 else 'internal node'
    print(f'node {i}: parent = {parent[i]}, sibling = {sib[i]}, degree = {deg[i]}, depth = {depth[i]}, height = {hei[i]}, {node_type}')   
    


Measured memory_bytes: 5644
#include <bits/stdc++.h>
#include <math.h>
#include <cmath>

using namespace std;
using ll =long long;
using vi = vector<int>; 
using vvi = vector<vi>; 
using vl = vector<ll>; 
using vvl = vector<vl>; 
using vs = vector<string>;
using vvs = vector<vs>; 
using vc = vector<char>;
using vvc = vector<vc>; 
using vb = vector<bool>;
using vvb = vector<vb>; 

#define rep(i,n) ;for( int i =0; i < n ; i ++)
#define all(a) a.begin(),a.end()
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define f(i,a,b) for(int i=a;i<b;i++)
#define pri(a)  printf("%.14lf\n",a);
#define MOD 1000000007
bool is_int_lround(double x){
  return std::lround(x)==x;
}
ll keta(ll x){
  ll n=0;
  while(x>0){
    x /=10 ;
    n ++;
  }
  return n;
}

ll conbi(int n,int m){
  
  cin>>n>>m;
  vector<ll> a(100);
  a[0] =1;
  for(int i=0;i<14;i++){
    a[i+1]=a[i]*(i+1);
  }
  return a[n] /(a[m] *a[n-m]);
}

long long modpow(long long a, long long n, long long mod) {
    long long res = 1;//繰り返し二乗法
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
ll kaijo(ll x){
  ll z=1;
  while(x>0){
    z *=x;
    z %=MOD;
    x--;
  }
  return z;
}
ll yakusu_num(ll n){
  vl yakusu(n+1,1);
  for(ll i=2;i*i<=n;i++){ 
    while(n%i==0){
      n /=i;
      yakusu[i]++;
    }
  }
  if(n!=1)yakusu[n]++;
  ll num=1;
  for(ll i=0;i <=n;i++){
    num*=yakusu[i];
  }
  return num;
}


//cout<<""<<endl;
int main(){
  int N,M;cin>>N>>M;
  vi s(M);vc c(M);
  rep(i,M)cin>>s[i]>>c[i];
  string ans="-1";
  f(i,0,1000){
    string st = to_string(i);
    if(st.size()!=N)continue;
    bool ok=true;
    rep(j,M){
      if(st[s[j]-1]!=c[j])ok=false;
    }
    if(ok){
      ans =st;
      break;
    }
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 256
#include"bits/stdc++.h"
using namespace std;
#define ll long long
#define LL long long
#define MOD 1000000007
#define INF 2000000000000
int dx[4] = { 0,1,0,-1 };
int dy[4] = { 1,0,-1,0 };
ll N, M, K, H, W, L, R, l, r, u, sum, X;
LL ans=0;
LL no;

string s, t;



int main() {
	cin >> N;
	set<string> m;
	for (int i = 0; i < N; i++) {
		cin >> s;
		m.insert(s);
	}
	cout << m.size()<<endl;
	return 0;
}



Measured memory_bytes: 19232
def a(s, t)
  (s.length - t.length + 1)
    .times
    .map { |i| s[i, t.length] }
    .map { |j| j.chars.zip(t.chars).count { |k| k[0] != k[1] } }
    .min
end
p a(gets.chomp, gets.chomp)


Measured memory_bytes: 14776
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#define ll long long
#define rep(i,n) for(ll i=0;i<(n);i++)
#define pll pair<ll,ll>
#define pq priority_queue
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define ios ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define lb(c,x) distance(c.begin(),lower_bound(all(c),x))
#define ub(c,x) distance(c.begin(),upper_bound(all(c),x))

using namespace std;

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

const ll INF=1e9+7;

int main(){
    ll x;
    cin >> x;
    if(x<1200) cout << "ABC" << endl;
    else cout << "ARC" << endl;
    return 0;
}


Measured memory_bytes: 3620
{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE BinaryLiterals #-}
{-# LANGUAGE MultiWayIf #-}
{-# LANGUAGE NumDecimals #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TupleSections #-}

import Control.Applicative
import Control.Arrow
import Control.Monad
import Control.Monad.ST

import Data.Char
import Data.List
import Data.Maybe

import qualified Data.ByteString.Char8 as B

import Data.Array.ST.Safe
import Data.STRef

import Debug.Trace
import Text.Printf

readInt = readLn :: IO Int
readInteger = readLn :: IO Integer
readInts = map ( fst . fromJust . B.readInt ) . B.words <$> B.getLine
readIntegers = map ( fst . fromJust . B.readInteger ) . B.words <$> B.getLine

which a b f = if f then a else b
mp [ a, b ] = ( a, b )

modifyArray a i f = writeArray a i =<< f <$> readArray a i

main = do
	n <- readInt
	ss <- group . sort <$> replicateM n getLine
	let
		kv = map ( head &&& length ) ss
	output kv "AC"
	output kv "WA"
	output kv "TLE"
	output kv "RE"

output kv s = printf "%s x %d\n" s $ fromMaybe 0 $ lookup s kv 

Measured memory_bytes: 38788
#include<iostream>
#include<cmath>
#include<algorithm>
#include<string>
#include<set>
#include<vector>
#include<iomanip>
#include<numeric>
using namespace std;

int main(){
  int a,b,h;cin>>a>>b>>h;
  cout<<(a+b)*h/2<<endl;

  return 0;
}

Measured memory_bytes: 256
// toupper example (C++)
#include <iostream>       // std::cout
#include <string>         // std::string
#include <locale>         // std::locale, std::toupper
#include <iostream>
using namespace std ; 
int main ()
{
  std::locale loc;
string str , str1 , str2 ;
  cin >> str >> str1 >> str2; 
    std::cout << std::toupper(str[0],loc);
        std::cout << std::toupper(str1[0],loc);
    std::cout << std::toupper(str2[0],loc);

  return 0;
}

Measured memory_bytes: 256
def gcd(A,B):
    while B != 0:
        A,B = B,A%B
    return A
n,x = map(int,input().split())
li = [abs(int(i)-x) for i in input().split()]
ans = li[0]
for i in range(n):
    ans = gcd(ans,li[i])

print(ans)



Measured memory_bytes: 14248
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define arr(n) array<int,n>
#define INF 1e9
typedef long long ll;
typedef pair<int,int> pii;

int main(){
  int N;
  cin >> N;
  int a[N];
  int b[1000007] = {};
  rep(i,N){
    cin >> a[i];
    b[a[i]]++;
  }
  sort(a,a+N);
  int ans = N;
  
  rep(i,N){
    if(b[a[i]] > 1){
      ans--;
      continue;
    }
    bool f = false;
    int v = 1000;
    for(int c=2; c<v; c++){
      if(a[i]%c==0 and (b[a[i]/c]) > 0){
        f = true;
        break;
      }
    }
    if(f){
      ans--;
      continue;
    }
    int x = *lower_bound(a,a+N,a[i]/v + 1);
    int j = 0;
    while(a[j] < x){
      if(j!=i and a[i]%a[j] == 0){
        ans--;
        break;
      }
      j++;
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 8324
#include <atcoder/scc>
#include <bits/stdc++.h>
using namespace std;
using namespace atcoder;
typedef long long ll;
#define REP(i, n) for(int i=0; i<n; i++)
#define REPR(i, n) for(int i=n-1; i>=0; i--)
#define FOR(i, m, n) for(int i=m; i<n; i++)
#define ALL(v) v.begin(), v.end()
#define SIZE(x) ll(x.size()) 
using P = pair<int, int>;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const int INF = 2e9;
const ll LINF = (1LL<<60);

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int n,m; cin >> n >> m;

  scc_graph g(n);
  REP(i,m){
    int a,b; cin >> a >> b;
    g.add_edge(a,b);
  }

  auto scc = g.scc();
  cout << SIZE(scc) << '\n';
  for(auto k: scc){
    cout << SIZE(k);
    for(auto v: k) cout << " " << v;
    cout << '\n';
  }

  return 0;
}


Measured memory_bytes: 40120
while line = gets
  a,b = line.split.map(&:to_i)
  digit = 0
  while
    digit += 1
    if a + b == 0
      puts digit
      break
    elsif 10**(digit - 1) <= a + b && 10**(digit) - 1 >= a + b
      puts digit
      break
    end
  end
end

Measured memory_bytes: 6104
#include<iostream>
#include<vector>
#include<string>
#include<cstdio>
#include<algorithm>
#include<set>
#pragma warning(disable : 4996)
using namespace std;

int main() {
	int b;
	scanf("%d",&b);
	vector<vector<int>>a(b+1);
	vector<int>c = { 0 };
	a[0] = c;
	for (int d = 1; d <= b; d++) {
		int e;
		scanf("%d", &e);
		for (int f = 0; f < a[d-1].size(); f++) {
			a[d].push_back(a[d-1][f]);
			a[d].push_back(a[d - 1][f] + e);
		}
	}
	set<int>q;
	for (int p : a[b]) {
		q.insert(p);
	}
	int x;
	scanf("%d", &x);
	for (int y = 0; y < x; y++) {
		int z;
		scanf("%d", &z);
		if (q.find(z) == q.end())cout << "no" << endl;
		else cout << "yes" << endl;
	}
}

Measured memory_bytes: 11316
/* author   : mpily :-()
title : Competing.cpp
time :Sun Jun 14 13:11:23 2020

*/
#include<random>
#include<cassert>
#include<iostream>
#include<vector>
#include<set>
#include<map>
#include<unordered_set>
#include<unordered_map>
#include<algorithm>
#include<utility>
#include<cstdint>
#include<queue>
#include<iomanip>
#include<cmath>
#include<string>
#include<cstdio>
using namespace std;

void solve(int cnum){
	char alp;
	cin >> alp;
	if(alp >= 'A' && alp <='Z')
		cout << 'A';
	else cout <<'a';

}
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	//cout.tie(nullptr);
	int t;
	int count = 1;
	for(t = 1;t--; solve(count));
	return 0;
}

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

int main(){
	int n ; cin >> n ;
	vector<pair<string,int>> t(n) ;
	int sum = 0 ;
	for(int i=0;i<n;i++){
		cin >> t.at(i).first >> t.at(i).second ;
		sum += t.at(i).second ;
	}
	string s ; cin >> s ;
	for(int i=0;i<n;i++){
		if(t.at(i).first!=s){
			sum -= t.at(i).second ;
		}else{
			sum -= t.at(i).second ;
			break ;
		}
	}
	cout << sum << endl ;
}


Measured memory_bytes: 256
/*
Rathin Bhargava
IIIT Bangalore

*/
#include<bits/stdc++.h>
#define mt make_tuple
#define mp make_pair
#define pu push_back
#define INF 1000000001
#define MOD 1000000007
#define ll long long int
#define ld long double
#define fi first
#define se second
#define pr(v) { for(int i=0;i<v.size();i++) { v[i]==INF? cout<<"INF " : cout<<v[i]<<" "; } cout<<endl;}
#define t1(x)                cerr<<#x<<" : "<<x<<endl
#define t2(x, y)             cerr<<#x<<" : "<<x<<" "<<#y<<" : "<<y<<endl
#define t3(x, y, z)          cerr<<#x<<" : " <<x<<" "<<#y<<" : "<<y<<" "<<#z<<" : "<<z<<endl
#define t4(a,b,c,d)          cerr<<#a<<" : "<<a<<" "<<#b<<" : "<<b<<" "<<#c<<" : "<<c<<" "<<#d<<" : "<<d<<endl
#define t5(a,b,c,d,e)          cerr<<#a<<" : "<<a<<" "<<#b<<" : "<<b<<" "<<#c<<" : "<<c<<" "<<#d<<" : "<<d<<" "<<#e<<" : "<<e<<endl
#define t6(a,b,c,d,e,f)          cerr<<#a<<" : "<<a<<" "<<#b<<" : "<<b<<" "<<#c<<" : "<<c<<" "<<#d<<" : "<<d<<" "<<#e<<" : "<<e<<" "<<#f<<" : "<<f<<endl
#define GET_MACRO(_1,_2,_3,_4,_5,_6,NAME,...) NAME
#define t(...) GET_MACRO(__VA_ARGS__,t6,t5, t4, t3, t2, t1)(__VA_ARGS__)
#define _ cerr<<"here"<<endl;
#define __ {ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);}

using namespace std;
template<class A, class B> ostream& operator<<(ostream& out, const pair<A, B> &a){ return out<<"("<<a.first<<", "<<a.second<<")";}
template <int> ostream& operator<<(ostream& os, const vector<int>& v) { os << "["; for (int i = 0; i < v.size(); ++i) { if(v[i]!=INF) os << v[i]; else os << "INF";if (i != v.size() - 1) os << ", "; } os << "]\n"; return os; } 
template <typename T> ostream& operator<<(ostream& os, const vector<T>& v) { os << "["; for (int i = 0; i < v.size(); ++i) { os << v[i]; ;if (i != v.size() - 1) os << ", "; } os << "]\n"; return os; } 

bool calc(int i1,int i2,vector<vector<int> > &v)
{
  ld cnt = 0;
  for(int j=0;j<v[0].size();j++)
  {
    cnt+= (v[i1][j] - v[i2][j])*(v[i1][j] - v[i2][j]);
  }

  if(sqrt(cnt)==(int)sqrt(cnt)) return true;
  return false;
}


int main()
{
  __;
  int n,m;
  cin>>n>>m;
  vector<vector<int> > v(n,vector<int>(m));

  for(int i=0;i<n;i++) for(int j=0;j<m;j++) cin>>v[i][j];

  int cnt = 0;
  for(int i=0;i<n;i++)
  {
    for(int j=i+1;j<n;j++)
    {
      if(calc(i,j,v)) cnt++;
    }
  }

  cout<<cnt<<endl;
  return 0;
}



Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include"bits/stdc++.h"
#ifdef _DEBUG
#define DBG(n) n
#else
#define DBG(n)
#endif
#define INF         1e9
#define INFLL       1e18
#define EPS         1e-9
#define REP(i,n)    for(ll i=0,i##_len=(n);i<i##_len;++i)
#define REP1(i,n)   for(ll i=1,i##_len=(n);i<=i##_len;++i)
#define REPR(i,n)   for(ll i=(n)-1;i>=0;--i)
#define REPR1(i,n)  for(ll i=(n);i>0;--i)
#define REPC(i,obj) for(auto i:obj)
#define ALL(obj)    (obj).begin(),(obj).end()
#define SETP(n)     cout << fixed << setprecision(n)
using namespace std;
using ll = long long;
template<typename T = ll>inline T in() { T ret; cin >> ret; return ret; }

vector<ll>dijkstra(const vector<vector<pair<ll, ll>>>&edge, ll start = 0)
{
	vector<ll>dist(edge.size(), INFLL); dist[start] = 0;
	priority_queue<pair<ll, ll>, vector<pair<ll, ll>>, function<bool(const pair<ll, ll>&, const pair<ll, ll>&)>> node_queue([](const pair<ll, ll>&p1, const pair<ll, ll>&p2) {return p1.second > p2.second; });
	node_queue.push(make_pair(start, 0));
	while (!node_queue.empty()) {
		ll tpn_index = node_queue.top().first, tpn_cost = node_queue.top().second; node_queue.pop();
		for (auto i : edge[tpn_index]) {
			ll dst_index = i.first, dst_cost = i.second;
			if (tpn_cost + dst_cost < dist[dst_index]) {
				dist[dst_index] = tpn_cost + dst_cost;
				node_queue.push(make_pair(dst_index, dist[dst_index]));
			}
		}
	}
	return dist;
}
signed main()
{
	ll v = in(), e = in(), r = in();
	vector<vector<pair<ll, ll>>>edge(v);
	REP(i, e) {
		ll s = in(), t = in(), d = in();
		edge[s].push_back(make_pair(t, d));
	}
	vector<ll>cost(move(dijkstra(edge,r)));
	REP(i, v) {
		if (cost[i] == INFLL) {
			cout << "INF" << endl;
		} else {
			cout << cost[i] << endl;
		}
	}
}


Measured memory_bytes: 19476
import java.util.*;

public class Main {
	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int m = sc.nextInt();
		PriorityQueue<Work> lead = new PriorityQueue<Work>(new Comparator<Work>() {
		    public int compare(Work w1, Work w2) {
		        return w2.days - w1.days;
		    }
		});
		for (int i = 0; i < n; i++) {
		    Work w = new Work(sc.nextInt(), sc.nextInt());
		    if (w.days <= m) {
		        lead.add(w);
		    }
		}
		PriorityQueue<Work> stock = new PriorityQueue<Work>(new Comparator<Work>() {
		    public int compare(Work w1, Work w2) {
		        return w1.value - w2.value;
		    }
		});
		while (lead.size() > 0) {
		    Work w = lead.poll();
		    stock.add(w);
		    if (stock.size() > m - w.days + 1) {
		        stock.poll();
		    }
		}
		long sum = 0;
		while (stock.size() > 0) {
		    sum += stock.poll().value;
		}
		System.out.println(sum);
   }
   
   static class Work {
       int days;
       int value;
       
       public Work (int days, int value) {
           this.days = days;
           this.value = value;
       }
       
       public String toString() {
           return "days:" + days + " value:" + value;
       }
   }
}




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

#define rep(i, n) for(int i = 0; i < (int)(n); i++)


int64_t pow(int x, int n){
    int64_t ans=1;
    for(int i=0;i<n;i++){
        ans*=x;
    }
    return ans;
}
    
int main(void){
    int n; cin >> n;
    vector<int64_t> a(n); 
    int64_t upper = pow(10, 18);
    float ans_tmp = 1;
    
    rep(i, n){
        cin >> a.at(i);
        ans_tmp = ans_tmp * a.at(i);
        if(a.at(i) == 0){
            cout << 0 << endl;
            return 0;
        }
    }
    
    if(ans_tmp > upper){
        cout << -1 << endl;
        return 0;
    }
    
    int64_t ans = 1;
//    cout << upper << endl;
    rep(i, n){
        ans = ans * a.at(i);
        if(ans > upper){
            cout << -1 << endl;
            return 0;
        }
    }
    
    cout << ans << endl;
        
}


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

using namespace std;

const int MOD = 998244353;

int n, a[305];
long long dp[305][90005];

int main() {
	scanf("%d", &n);
	
	int s = 0;
	
	for (int i = 1; i <= n; i++) {
		scanf("%d", &a[i]);
		s += a[i];
	}
	
	long long all = 1LL;
	for (int i = 0; i < n; i++) all = (all * 3) % MOD;
	
	dp[0][0] = 1LL;
	
	for (int i = 1; i <= n; i++) {
		for (int j = 0; j <= s; j++) dp[i][j] = (dp[i][j] + dp[i - 1][j] * 2) % MOD;
		for (int j = a[i]; j <= s; j++) dp[i][j] = (dp[i][j] + dp[i - 1][j - a[i]]) % MOD;
	}
	
	long long tmp = 0;
	
	for (int i = (s + 1) / 2; i <= s; i++) tmp = (tmp + dp[n][i]) % MOD;
	long long res = all - 3LL * tmp;
	res %= MOD; res += MOD; res %= MOD;
	
	memset(dp, 0, sizeof(dp));
	
	dp[0][0] = 1LL;
	
	for (int i = 1; i <= n; i++) {
		for (int j = 0; j <= s; j++) dp[i][j] = (dp[i][j] + dp[i - 1][j]) % MOD;
		for (int j = a[i]; j <= s; j++) dp[i][j] = (dp[i][j] + dp[i - 1][j - a[i]]) % MOD;
	}
	
	if (s % 2 == 0) {
		res += 3LL * dp[n][s / 2];
		res %= MOD;
	}
	
	printf("%lld\n", res);
}


Measured memory_bytes: 214656
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,l,r) for(long long i=(l);i<(r);++i)
#define REP(i,n) FOR(i,0,n)
#define REPS(i,n) FOR(i,1,n+1)
#define RFOR(i,l,r) for(long long i=(l);i>=(r);--i)
#define RREP(i,n) RFOR(i,n-1,0)
#define RREPS(i,n) RFOR(i,n,1)
#define int long long
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define SZ(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
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; }
const int INF = 1e18;

signed main(){
    int n; cin >> n;
    int a[n];
    int c = 0;
    REP(i,n){
        cin >> a[i];
        c = (c ^ a[i]);
    }
    REP(i,n)cout << (a[i] ^ c) <<" ";
}

Measured memory_bytes: 5068
from collections import deque

N, M = map(int, input().split())
G = [[] for _ in range(N)]

for _ in range(M):
  a, b = map(int, input().split())
  a, b = a-1, b-1
  G[a].append(b)
  G[b].append(a)

q = deque([0])
dist = [-1]*N
dist[0] = 0

while q:
  v = q.popleft()
  for nv in G[v]:
    if dist[nv] == -1:
      dist[nv] = v+1
      q.append(nv)

print("Yes")
print(*dist[1:], sep="\n")


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

int main(){
  
  string s,t;
  int count = 0;
  
  cin >> s;
  cin >> t;

  for(int i = 0; i < s.length(); i++) { 
    if (s[i] == t[i]) count++;
    }
  	cout << count << endl;
}

 

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

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REP1(i,n) for(int i=1, i##_len=(n); i<i##_len; ++i)
#define ll long long
static const int MAX = 10000;
static const ll INFTY = 1e12;

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

int main() {

  string S;
  cin >> S;

  ll ans = 0;
  REP(i, S.length()){
    int num = S[i] - '0';
    ans += num;
  }
  if(ans%9==0)cout << "Yes" << endl;
  else cout << "No" << endl;
}
/*
                   _ooOoo_
                  o8888888o
                  88" . "88
                  (| -_- |)
                  O\  =  /O
               ____/`---'\____
             .'  \\|     |//  `.
            /  \\|||  :  |||//  \
           /  _||||| -:- |||||-  \
           |   | \\\  -  /// |   |
           | \_|  ''\---/''  |   |
           \  .-\__  `-`  ___/-. /
         ___`. .'  /--.--\  `. . __
      ."" '<  `.___\_<|>_/___.'  >'"".
     | | :  `- \`.;`\ _ /`;.`/ - ` : | |
     \  \ `-.   \_ __\ /__ _/   .-` /  /
======`-.____`-.___\_____/___.-`____.-'======
                   `=---='
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
         pass System Test!
*/

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

int main(){
    long N;
    long long int atemp;
    long N_4=0;
    long N_even_not4=0;
    long N_odd=0;

    cin >> N;
    for(long i=0;i<N;i++){
        cin >> atemp;
        if(atemp%4==0){
            N_4++;
        }
        else{
            if(atemp%2==0){
                N_even_not4=1;
            }
            else{
                N_odd++;
            }
        }
    }

    if(N_4>=(N_odd+N_even_not4-1)){
        cout << "Yes\n";
    }
    else{
        cout << "No\n";
    }

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <functional>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <bitset>
#include <cassert>
#include <exception>
using namespace std;

int A[110];
  
int main(){
  int n,m,x;
  cin >> n >> m >> x;
  for(int i=0; i<m; i++){
    int l;
    cin >> l;
    A[l] = 1;
  }
  int ans1 = 0;
  for(int i=0; i<x; i++){
    ans1 += A[i];
  }
  int ans2 = 0;
  for(int i=x+1; i<n; i++){
    ans2 += A[i];
  }
  

  cout << min(ans1,ans2) << endl;
  

  return 0;
}


Measured memory_bytes: 256
import std.stdio;
import std.conv;
import std.string;

int i, j, n;

void main() {
    while(1) {
        readf("%d\n", &n);
        if(n == 0) break;
        int[500][500] matrix;
        int[500] sumr;
        int[500] sumc;

        for(i = 0; i < n; i++) {
            string[] str = split(readln());
            for(j = 0; j < n; j++) {
                matrix[i][j] = to!int(str[j]);
                sumc[j] += matrix[i][j];
                sumr[i] += matrix[i][j];
                if(j == n - 1) {
                    matrix[i][j+1] = sumr[i];
                    sumr[j+1] += matrix[i][j+1];
                }
                if(i == n - 1) {
                    matrix[i+1][j] = sumc[j];
                    sumc[j] += matrix[i+1][j];
                }
            }
        }
        matrix[n][n] = sumr[n] + sumc[n];
        for(i = 0; i <= n; i++) {
            for(j = 0; j <= n; j++) {
                writef("%5d", matrix[i][j]);
            }
            writef("\n");
        }
    }
}

Measured memory_bytes: 1992
#include <iostream>
#include<vector>
#include<algorithm>
#include<map>
#include<queue>
#include<cmath>
#include<set>
#include<deque>
using namespace std;
typedef long long ll;

typedef pair<int, int> pii;

const ll MOD_CONST = 1000000007;


const int BIG_INT = 1000000000;



int main(){
	int A, B, m;
	cin >> A >> B >> m;
	vector<int> a(A);
	vector<int> b(B);

	for (int i = 0; i < A; i++) {
		cin >> a[i];
	}
	for (int i = 0; i < B; i++) {
		cin >> b[i];
	}

	int ans = BIG_INT;
	for (int i = 0; i < m; i++) {
		int x, y, c;
		cin >> x >> y >> c;
		x--;
		y--;
		ans = min(ans, a[x] + b[y] - c);
	}

	sort(a.begin(), a.end());
	sort(b.begin(), b.end());
	
	ans = min(ans, a[0] + b[0]);
	cout << ans << endl;
}  



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

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

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

//ori
#define MOD 1000000007
 
int main() {
  int r;
  cin >> r;
  int ans = 3*r*r;
  cout << ans << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<iomanip>
using namespace std;

int main(){
    int n,k,q;
    cin>>n>>k>>q;
    int a[n]={0};
    for(int i=0;i<q;i++){
        int x;
        cin>>x;
        a[x-1]++;
    }
    for(int i=0;i<n;i++){
        if(k-(q-a[i])>0)cout<<"Yes"<<"\n";
        else cout<<"No"<<"\n";
    }
    return 0;
}

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

#define REP(i, n) for(decltype(n) i = 0; i < n; i++)

#define ALL(c)   c.begin(), c.end()
#define SORT(c)  std::sort(ALL(c))
#define RSORT(c) std::sort(ALL(c), std::greater<decltype(c)::value_type>())

using namespace std;
using ll = long long;

const int MOD  = (int)1e9 + 7;
const int INF  = (int)1e9 + 1;
const ll  LINF = (ll)1e18 + 1;

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

    int N, M;
    std::cin >> N >> M;

    map<int, int> A;
    REP(i, N) {
        int K;
        std::cin >> K;
        REP(i, K) {
            int a;
            std::cin >> a;
            auto itr = A.find(a);
            if(itr != A.end()) {
                itr->second++;
            }
            else {
                A.emplace(a, 1);
            }
        }
    }

    int ans = 0;
    for(const auto& v : A) {
        if(v.second == N) ans++;
    }

    std::cout << ans << std::endl;

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
	int a,b;
	cin >> a;
	cin >> b;
	if((a==1 && b==2)|| (a==2 && b==1)) 
		cout << "3\n";
	if((a==2 && b==3)|| (a==3 && b==2))
		cout << "1\n";
	if((a==3 && b==1)||(a==1 && b==3))
		cout << "2\n";
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define ff first
#define ss second
#define pb push_back
#define w(t) int t;cin>>t; while(t--)
using namespace std;

//a5 – b5 = (a – b)(a4 + a3b + a2b2 + ab3 + b4)


int main(){
    ll n;
    cin>>n;
    ll arr[n+1];
    for(ll i=1; i<=n; i++) cin>>arr[i];
    ll left[n+1], right[n+1];
    ll ans = 0;
    map<ll, ll> ml, mr;
    for(ll i=1; i<=n; i++){
        left[i] = arr[i]+i;
        right[i] = i-arr[i];
        ml[left[i]]++;
        mr[right[i]]++;
    }
    for(ll i=1; i<=n; i++){
        if(mr[left[i]]>0){
            ans += mr[left[i]];
            
        }
    }
    cout<<ans;
}

Measured memory_bytes: 42632
package main
import (
  "bufio"
  "os"
  "strconv"
  "strings"
  "fmt"
)

func Solve() {
  var N, K int
  NextInt(&N, &K)
  var A []int
  NextIntVec(&A)
  for i := range A { A[i]-- }
  D := make([]int, N)
  for i := range D { D[i]-- }
  D[0] = 0
  pos, cnt := 0, 0
  for cnt < K {
    pos = A[pos]
    cnt++
    if D[pos] >= 0 { break }
    D[pos] = cnt
  }
  if cnt == K {
    Write(pos + 1)
  } else {
    cnt = D[pos] + (K - cnt) % (cnt - D[pos])
    for i, d := range D {
      if d != cnt { continue }
      Write(i + 1)
    }
  }
}

func main() {
  Solve()
  Output()
}

var reader = bufio.NewReaderSize(os.Stdin, 1000000)
var writer = bufio.NewWriter(os.Stdout)
func NextLine() string {
  buffer := make([]byte, 0)
  for true {
    line, isPrefix, err := reader.ReadLine()
    if err != nil { panic(err) }
    buffer = append(buffer, line...)
    if !isPrefix { break }
  }
  return string(buffer)
}
func NextInt(A ...*int) {
  L := strings.Split(NextLine(), " ")
  for i, a := range A {
    *a, _ = strconv.Atoi(L[i])
  }
}
func NextIntVec(A *[]int) {
  L := strings.Split(NextLine(), " ")
  (*A) = make([]int, len(L))
  for i, l := range L {
    (*A)[i], _ = strconv.Atoi(l)
  }
}
func NextFloat(A ...*float64) {
  L := strings.Split(NextLine(), " ")
  for i, a := range A {
    *a, _ = strconv.ParseFloat(L[i], 64)
  }
}
func NextFloatVec(A *[]float64) {
  L := strings.Split(NextLine(), " ")
  (*A) = make([]float64, len(L))
  for i, l := range L {
    (*A)[i], _ = strconv.ParseFloat(l, 64)
  }
}
func Write(s interface{}) {
  fmt.Fprintln(writer, s)
}
func WriteIntVec(A []int) {
  S := make([]string, len(A))
  for i, a := range A {
    S[i] = strconv.Itoa(a)
  }
  Write(strings.Join(S, " "))
}
func Output() {
  _ = writer.Flush()
}
func MaxInt(A ...int) int {
  max := A[0]
  for _, a := range A {
    if max < a { max = a }
  }
  return max
}
func MinInt(A ...int) int {
  min := A[0]
  for _, a := range A {
    if a < min { min = a }
  }
  return min
}
func SumInt(A ...int) int {
  sum := 0
  for _, a := range A {
    sum += a
  }
  return sum
}
func AbsInt(x int) int {
  if x < 0 { x = -x }
  return x
}

Measured memory_bytes: 11620
package main

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

var (
	read  = bufio.NewReader(os.Stdin)
	write = bufio.NewWriter(os.Stdout)
)

func min(a, b int) int {
	if a <= b {
		return a
	}
	return b
}

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

func yesno(result bool) {
	if result {
		fmt.Fprintln(write, "Yes")
	} else {
		fmt.Fprintln(write, "No")
	}
}

func printansStr(result bool, a, b string) {
	if result {
		fmt.Fprintln(write, a)
	} else {
		fmt.Fprintln(write, b)
	}
}

func printansInt(result bool, a, b int) {
	if result {
		fmt.Fprintln(write, a)
	} else {
		fmt.Fprintln(write, b)
	}
}

func main() {
	defer write.Flush()

	var n int
	fmt.Fscan(read, &n)

	a := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Fscan(read, &a[i])
	}

	cnt := 0
	for i := 1; i < n-1; i++ {
		if a[i-1] < a[i] && a[i] < a[i+1] {
			cnt++
		}
		if a[i-1] > a[i] && a[i] > a[i+1] {
			cnt++
		}
	}
	fmt.Fprintln(write, cnt)
}


Measured memory_bytes: 640
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define REVERSE(v,n) reverse(v,v+n);
#define llong long long
#define pb(a) push_back(a)
#define INF 9999999

using namespace std;

typedef pair<int,int> P;

int dy[4]={0,0,1,-1};
int dx[4]={1,-1,0,0};

int main(){
	int n,d,x,a[100];
	cin>>n>>d>>x;
	REP(i,n)cin>>a[i];
	int ans=x;
	REP(i,n){
		ans+=(d-1)/a[i]+1;
	}
	cout<<ans<<endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>

#define PI 3.1415926535897932384626433
#define ToRadian(r) ((r)/180.0*PI)
#define ToDegree(r) ((r)*180.0/PI)
#define pow2(x) ((x) * (x))

using namespace std;

int main ( void )
{
	int n;
	
	while ( cin >> n )
	{
		while (n--)
		{
			double xa, ya, ra, xb, yb, rb;
			cin >> xa >> ya >> ra;
			cin >> xb >> yb >> rb;
			
			double dist_sq = pow2(xa - xb) + pow2(ya - yb);
			double dist_r_sq = pow2(ra + rb);
			
			if ( dist_sq > dist_r_sq )
			{
				cout << 0 << endl;
			}
			else
			{
				double dist = sqrt(dist_sq);
				double dist_a = dist + ra;
				double dist_b = dist + rb;
				int ans = 1;
				if (dist_b < ra)
					ans = 2;
				if (dist_a < rb)
					ans = -2;
				cout << ans << endl;
			}
		}
	}
	return 0;
}

Measured memory_bytes: 1232
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;

int main() {
    int N; cin >> N;
    vector<int> d(N);
    rep(i, N){
        cin >> d[i];
    }

    ll ans = 0;
    rep(i, N-1){
        for (int j = i+1; j < N; j++){
            ans += d[i]*d[j];
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

#define repd(i,a,b) for (int i=(a);i<(b);++i)
#define rep(i,n) repd(i,0,n)
typedef long long ll;

int main(){
  int n, m;
  cin >> n >> m;
  int max_l = 0;
  int min_r = 200000;
  rep(i, m){
    int l, r;
    cin >> l >> r;
    max_l = max(max_l, l);
    min_r = min(min_r, r);
  }
  if(min_r - max_l < 0){
    cout << 0 << endl;
  }else{
    cout << min_r - max_l +1 << endl;
  }

  return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
//const int INF=0x3f3f3f3f,maxn=;
//vector<int>v[maxn];
//map<int,string>mp[maxn];
//queue<int>q[maxn];/
//int a[naxm],n,m;
int main()
{
	int i,j,k,ans=0;
	long long x,y;
	cin>>x;
	cout<<(1000-x%1000)%1000<<endl;
	return 0;
}


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

#define select(_1, _2, x, ...) x

#define repn(i, n) for (ll i = 0; i < (n); i++)
#define repr(i, a, b) for (ll i = (a); i < (b); i++)
#define rep(i, ...) select(__VA_ARGS__, repr, repn)(i, __VA_ARGS__)

#define rrepn(i, n) for (ll i = (n - 1); i >= 0; i--)
#define rrepr(i, a, b) for (ll i = (b - 1); i >= (a); i--)
#define rrep(i, ...) select(__VA_ARGS__, rrepr, rrepn)(i, __VA_ARGS__)

#define umax(m, x) (m = max(m, x))
#define umin(m, x) (m = min(m, x))

#define rng(v) v.begin(), v.end()
#define rrng(v) v.rbegin(), v.rend()

#define bit(x, n) ((x) >> (n) & 1)

#define showv(v) for (auto __tmp1 : v) cerr << __tmp1 << " "; cerr << endl;
#define db(x) cerr << #x << ": " << (x) << endl;
#define dbv(v) cerr << #v << ": "; showv(v);
#define dbm(m) cerr << #m << ":" << endl; for (auto __tmp2 : m) { showv(__tmp2); }

using namespace std;

using ll = long long int;
using ld = long double;

using vi = vector<int>;
using vl = vector<ll>;
using vb = vector<bool>;
using vc = vector<char>;
using vs = vector<string>;

using vvi = vector<vector<int>>;
using vvl = vector<vector<ll>>;
using vvb = vector<vector<bool>>;
using vvc = vector<vector<char>>;
using vvs = vector<vector<string>>;

const int INF = 1e9;
const ll LINF = 1e18;

int t = 1;
vl d, f;

void dfs(vvl& g, int v) {
    if (d[v]) return;
    d[v] = t++;
    for (auto n : g[v])
        dfs(g, n);
    f[v] = t++;
}

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

    vvl g(n);
    rep(i, n) {
        int u, k;
        cin >> u >> k;

        rep(j, k) {
            int v;
            cin >> v;
            g[u - 1].push_back(v - 1);
        }
    }

    d = vl(n, 0);
    f = vl(n, 0);

    rep(i, n)
        dfs(g, i);

    rep(i, n)
        cout << i + 1 << " " << d[i] << " " << f[i] << endl;

    return 0;
}



Measured memory_bytes: 3156
def main():
    N = int(input())
    A = [int(i) for i in input().split()]
    A.sort()

    m = A[-1]
    C = [False] * (m + 1)

    ans = 0
    for i in range(N):
        if C[A[i]] == False:
            if i == N - 1 or (i < N - 1 and not A[i] == A[i + 1]):
                ans += 1
        else:
            continue

        n = 1
        while True:
            nv = n * A[i]
            if nv > m:
                break
            else:
                C[nv] = True
            n += 1

    print(ans)

if __name__ == '__main__':
    main()

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

int main() {
  string S;
  cin>>S;
  int N=S.size();
  for(int i=0;i<N;i++){
    if(S.at(i)=='?'){
      S.at(i)='D';
    }
  }
  cout<<S<<endl;
}

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

#define int long long

signed main(void) {
  int num; // num
  num = 0; // count, result
  // num = numeric_limits<int>::min(); // max
  // num = numeric_limits<int>::max(); // min
  // int N;
  // int M;
  // array<int, 10000> A;
  string yes = "Yes";
  string no = "No";
  string S;
  // string T;

  int K;

  cin >> S;
  cin >> K;

  for (auto it = S.begin(); it < S.end(); ++it) {
    K -= pow(*it - '0', 5000000000000000);
    if (K <= 0) {
      cout << *it << endl;
      break;
      
    }
  }

  // for (auto it = A.begin(); it < A.begin() + N; ++it)
  //   cin >> *it;

  // for (auto it = A.begin(); it < A.begin() + N; ++it)
  //   if (*it % 2 == 0) ++num;

  // cout << num << endl;
  
  return 0;
}


Measured memory_bytes: 384
def main():
    import sys
    input=sys.stdin.readline
    n,m=map(int,input().split())
    A=list(map(int,input().split()))
    S=sum(A)
    if S>n:
        print(-1)
    else:
        print(n-S)
if __name__ == '__main__':
    main()

Measured memory_bytes: 68264
#include <iostream>
#include <vector>
#include <cmath>
#include <typeinfo>
#include <set>
#include <bitset>
#include <string>
#include <map>
#include <algorithm>
#include <numeric>
using namespace std;
typedef long long ll;



int main(){
  long long n;
  cin >> n;
  vector<long long> a(n), p(n), m(n);
  map<long long , long long> ma;
  for(long long i=0; i<n; i++){
    cin >> a[i];
    ma[i+1 + a[i]] ++;
  }

  long long  ans = 0;
  for(long long  i=0; i<n; i++){
    ans += ma[i+1-a[i]];
  }

  cout << ans << endl;
}

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

int main() {
  int64_t x, p;
  cin >> x;
  p = 100;
  int64_t count = 0;
  while(p < x){
    double q;
    q = p*1.01;
    p = (int64_t)q;
    count ++;
  }
  cout << count << endl;
}

Measured memory_bytes: 3620
#include<stdio.h>
int main(void)
{ //数値の入力
  int n,m,x;
  int gate[101];

  scanf("%d%d%d",&n,&m,&x);
  for(int i=1;i<=m;i++)
  {
    scanf("%d",&gate[i]);
  }

  //スタートの位置を探索する
  int flag=0;
  for(int i=0;i<=m;i++)
  {
    if(gate[i]>x)
    {flag=i;
     break;
    }
  }

  //0とmのどちらがスタートから近いかを探索する
  int start=flag-1;
  int goal=m-flag+1;
  int cost;

  if(start>=goal) cost=goal;
  else           cost=start;

  printf("%d",cost);

  return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i <= (int)(n); i++)
using P = pair<int,int>;
using pq = priority_queue<int>;
typedef long long ll;

int  main()
{
	int n, k; cin >> n >> k;
	vector<int> a(n);
	map<int, int> mp;
	rep(i, n)
	{
		cin >> a[i];
		mp[a[i]]++;
	}
	if (mp.size() <= k)
		cout << 0 << endl;
	else
	{
		priority_queue <int, vector<int>, greater<int>> q;
		rep1(i, n)
		{
			if(mp.count(i))
				q.push(mp[i]);
		}
		int ans = 0;
		rep(i, mp.size()-k)
		{
			ans += q.top();
			q.pop();
		}
		cout << ans << endl;
	}
	return (0);
}


Measured memory_bytes: 11516
/**
*    created: 10.05.2020 22:07:11
**/

#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
const int inf =1000000000;

int main() {
    ll n, k;
    cin >> n >> k;
    vector<int> a(n+1);
    rep(i, n) cin >> a[i+1];
    set<int> next;
    next.insert(1);
    vector<int> nex(1,1);
    ll s = 1, i = -1, ans;
    while(1)
    {
        i++;//i=追加回数
        next.insert(nex.back());//next.size()=追加回数＋1
        ll e = nex.back();//現在番地
        nex.push_back(a[nex.back()]);//nex.back()=次番地
      if (next.size() > i )
      {

          if (i == k)
          {
              ans = e;
              break;
          }
          else
          {
              continue;
          }

        }else if(next.size()==i){

            ll f = -1;
            while(1){//最初にeが現れる移動回数取得
                f++;
                if(nex[f]==e)
                    break;
            }
            ll d = i - f;//loopの移動回数
            d = (k-i) % d;//整数loop後の移動回数
            vector<ll> nn(1,e);
            ans = e;
            rep(g,d){
                nn.push_back(a[nn.back()]);
                ans = nn.back();
            }
            break;
        }

    }
    cout << ans << endl;
}

Measured memory_bytes: 12084
/*http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0008&lang=jp*/

#include <iostream>

using namespace std;

int main(){
    int n;

    while(cin >> n) {
        int r = 0;
        for (int i = 0; i < n + 1 && i < 10; ++i) {
            for (int j = 0; i + j < n + 1 && j < 10; ++j) {
                for (int k = 0; i + j + k < n + 1 && k < 10; ++k) {
                    if (n < i + j + k + 10) {
                        r++;
                    }
                }
            }
        }
        cout << r << endl;
    }
    return 0;
}

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

int main() {
  int N, A;
  cin >> N >> A;

  if (A >= N%500 ) {
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
  // ここにプログラムを追記
}

Measured memory_bytes: 256
import math

X, N = list(map(int, input().split()))
p = list(map(int, input().split()))
# print(X, N, p)

if N == 0:
    print(X)
    exit()

p.sort()

minimum = p[0]
maximum = p[len(p) - 1]

if X < minimum or maximum < X:
    print(X)
    exit()

diff_min = abs(X - minimum - 1)
diff_max = abs(X - maximum + 1)
if diff_min == diff_max:
    answer = min(minimum - 1, maximum + 1)
else:
    answer = minimum - 1 if diff_min < diff_max else maximum + 1

for candidate in range(0, 100 + 2):
    if candidate in p : continue

    diff_candidate = abs(X - candidate)
    diff_answer = abs(X - answer)

    if diff_candidate == diff_answer:
        answer = min(candidate, answer)
    elif diff_candidate < diff_answer:
        answer = candidate

print(answer)


Measured memory_bytes: 9236