akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

#define fi first
#define se second
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

using namespace std;

typedef long long ll;
typedef vector<ll> vll;
typedef pair<ll, ll> pll;
typedef long double ld;

const ll mod = (ll)1e9 + 7;
const ll mxN = 200200;




int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.precision(20);
	cout << fixed;
	
	ll n,k,ans=0;
	cin>>n>>k;
	for(int i=0;i<n;i++){
		ll x;
		cin>>x;
		if(abs(x)<=abs(k-x))
			ans+=2*x;
		else 
			ans+=2*(abs(k-x));
	}
	cout<<ans;



}


Measured memory_bytes: 3588
import java.util.*;
import static java.lang.System.*;

public class Main {

	Scanner sc = new Scanner(in);
	
	void run() {
		int n = sc.nextInt();
		int[][] mat = new int[n][n];
		for (int i = 0; i < n; i++)
			for (int j = 0; j < n; j++)
				mat[i][j] = sc.nextInt();
		
		long res = 0;
		for (int i = 0; i < n-1; i++) {
			for (int j = i+1; j < n; j++) {
				res += Math.min(mat[i][j], mat[j][i]);
			}
		}
		out.println(res);
	}
	
	public static void main(String[] args) {
		new Main().run();
	}

}

Measured memory_bytes: 31248
import java.util.Scanner;

public class Main {

	private static final long x = (long) Math.pow(10, 18);

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String o = sc.next();
		String e = sc.next();
		String s = "";

		for (int i = 0; i < o.length() + e.length(); i++) {
			if (i % 2 == 0) {
				s += o.charAt(i / 2);
			} else {
				s += e.charAt(i / 2);
			}
		}

		System.out.println(s);

		sc.close();
	}

}


Measured memory_bytes: 39136
using System;
namespace OJ_C_Sharp {
	class Program {
		static void Main(string[] args) {
			int n, a, b;
			var input = Console.ReadLine().Split(' ');
			n = int.Parse(input[0]);
			a = int.Parse(input[1]);
			b = int.Parse(input[2]);
			int first = n * a;
			if (first > b) {
				Console.WriteLine(b);
			}
			else {
				Console.WriteLine(first);
			}
		}
	}
}


Measured memory_bytes: 13140
import sys
s = int(input())
def collatz(n):
    if n%2 == 0:
        return (n//2)
    else:
        return 3*n+1
A = [s]
while True:
    A.append(collatz(A[-1]))
    for i in range(0,len(A)):
        for j in range(0,len(A)):
            if A[i] == A[j] and i!= j:
                print(j+1)
                sys.exit(0)
    

Measured memory_bytes: 3060
#include <iostream>
using namespace std;
#define MAX 100005
#define NIL -1

struct Node {
    int p, l, r;
};

void setDepth(int u, int p, Node tree[], int depth[]) {
    depth[u] = p;
    if (tree[u].r != NIL) setDepth(tree[u].r, p, tree, depth);
    if (tree[u].l != NIL) setDepth(tree[u].l, p + 1, tree, depth);
}

void printTree(int u, Node tree[], int depth[]) {
    cout << "node " << u << ": ";
    cout << "parent = " << tree[u].p << ", ";
    cout << "depth = " << depth[u] << ", ";

    if (tree[u].p == NIL) cout << "root, ";
    else if (tree[u].l == NIL) cout << "leaf, ";
    else cout << "internal node, ";

    cout << "[";

    for (int i = 0, c = tree[u].l; c != NIL; i++, c = tree[c].r) {
        if (i) cout << ", ";
        cout << c;
    }
    cout << "]" << endl;
}

int main() {
    Node tree[MAX];
    int n, depth[MAX];
    cin >> n;
    for (int i = 0; i < n; i++) {
        tree[i].p = tree[i].l = tree[i].r = NIL;
    }

    int d, v, c, l, r;
    for (int i = 0; i < n; i++) {
        cin >> v >> d;
        for (int j = 0; j < d; j++) {
            cin >> c;
            if (j == 0) tree[v].l = c;
            else tree[l].r = c;
            l = c;
            tree[c].p = v;
        }
    }
    for (int i = 0; i < n; i++) {
        if (tree[i].p == NIL) {
            r = i;
            break;
        }
    }

    setDepth(r, 0, tree, depth);
    for (int i = 0; i < n; i++) {
        printTree(i, tree, depth);
    }
}



Measured memory_bytes: 9328
#include<stdio.h>
int main()
{
    int l,i,j;
    double a,b,c,sum=0;
    scanf("%d",&l);

    double L=(double) l;

    a =L/3;
    L =L-a;
    b =L/2;
    c =L-b;




    printf("%f\n",a*b*c);
}


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

typedef long long ll;
typedef pair<int,int> P;

#define fr first
#define sc second

int main(){
	int h,w;
	char c[15][15];
	scanf("%d%d",&h,&w);
	for(int i = 0 ; i < h ; i ++){
		scanf("\n");
		for(int j = 0 ; j < w ; j ++){
			scanf("%c",&c[i][j]);
		}
	}
	
	vector<int> v;
	for(int i = 0 ; i < w ; i ++){
		v.push_back(i);
	}
	string s[15];
	bool used[15];
	bool a[15];
	int cnt = 0;
	int x = w/2;
	do{
		if(v[0] >= 3)break;
		for(int i = 0 ; i+1 < x ; ++i){
			if(v[i] > v[i+1])goto next_loop;
		}
		for(int i = 0 ; i < x ; ++i){
			if(v[i] > v[w-1-i])goto next_loop;
		}
		for(int i = 0 ; i < h ; ++i){
			s[i] = "";
			for(int j = 0 ; j < w ; ++j){
				s[i] += c[i][v[j]];
			}
		}
		for(int i = 0 ; i < h ; ++i){
			used[i] = false;
			a[i] = false;
		}
		for(int i = 0 ; i < h ; ++i){
			if(used[i])continue;
			used[i] = true;
			string t = s[i];
			reverse(t.begin(),t.end());
			if(s[i] == t){
				a[i] = true;
			}
			else {
				bool ok = false;
				for(int j = i+1 ; j < h ; ++j){
					if(used[j])continue;
					if(s[j] == t){
						ok = true;
						used[j] = true;
						break;
					}
				}
				if(!ok){
					goto next_loop;
				}
			}
		}
		cnt = 0;
		for(int i = 0 ; i < h ; ++i){
			if(!a[i])continue;
			a[i] = false;
			bool ok = false;
			for(int j = i+1 ; j < h ; ++j){
				if(!a[j])continue;
				if(s[i] == s[j]){
					ok = true;
					a[j] = false;
					break;
				}
			}
			if(!ok)cnt ++;
		}
		if(cnt <= 1){
			puts("YES");
			return 0;
		}
		next_loop:;
	}while(next_permutation(v.begin(),v.end()));
	
	puts("NO");
}



Measured memory_bytes: 256
n = gets.to_i
s = gets.chomp.split.map(&:to_i)
q = gets.to_i
t = gets.chomp.split.map(&:to_i)
c = 0

for i in 0..q-1
  for j in 0..n-1
    if t[i] == s[j]
      c += 1
      break
    end
  end
end
puts c 

Measured memory_bytes: 9068
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
double memo[3005][3005];
double prob[3005];
 
double solve(int idx,int tail,int n)
{
    if(2*tail>=n) return 0;
    if(idx>=n) return 1;
    if(memo[idx][tail]>-1) return memo[idx][tail];
    
    double he=prob[idx]*solve(idx+1,tail,n);
    double ta=(1-prob[idx])*solve(idx+1,tail+1,n);
    
    return memo[idx][tail]=he+ta;
    
}
int main()
{
    for(int i=0;i<=3000;i++)
    {
        for(int j=0;j<=3000;j++)
        {
            memo[i][j]=-1;
        }
    }
    int n;
    cin>>n;
    for(int i=0;i<n;i++)
    {
        cin>>prob[i];
    }
    
    double ans=solve(0,0,n);
    cout<<fixed<<setprecision(12)<<ans<<"\n";
}

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

struct Unionfind {
	vector< int > par;
	Unionfind(int N) : par(N,-1){
	}
	bool unite(int x, int y) {
		x = root(x), y = root(y);
		if(x == y) return 0;
		if(par[x] > par[y]) swap(x, y);
		par[x] += par[y];
		par[y] = x;
		return 1;
	}
	int root(int k) {
		if(par[k] < 0) return (k);
		return (par[k] = root(par[k]));
	}
	bool same(int x, int y){
		x = root(x), y = root(y);
		if(x == y) return 1;
		else return 0;
	}
	int size(int k) {
		return (-par[root(k)]);
	}
};

int main() {
	int n,q;
	cin >> n >> q;
	Unionfind uf(n);
	for(int i=0; i<q; i++){
		int c,x,y;
		cin >> c >> x >> y;
		if(c==0) uf.unite(x,y);
		if(c==1) cout << uf.same(x,y) << endl;
	}
	
}


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

int main(){
    int N;
    cin >> N;
    vector<int> vec(N,0);
    for(int i = 0; i < N-1; i++){
        int A;
        cin >> A;
        vec.at(A-1) += 1;
    }
    for(int i = 0; i < N; i++){
        cout << vec[i] << "\n";
    }
    return 0;
}

Measured memory_bytes: 3980
#include <iostream>
#include <stdio.h>
#include <string>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <math.h>
#include <vector>
#include <algorithm>

using namespace std;

int main(){
	string a, b;
	cin >> a >> b;
	string c=a+b;
	int d=stoi(c);
	for(int i=0; i<1000; i++){
		if(i*i==d){
			cout << "Yes" << endl;
			return 0;
		}
	}
	cout << "No" << endl;
	return 0;
}

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

int main() {

	int h, w;

	while (true) {

		cin >> h >> w;

		if (h == 0 && w == 0)break;

		for (int i = 0; i + 1 <= h;i++) {

			for (int j = 0; j + 1 <= w;j++) {

				if (i == 0 || i + 1 == h || j == 0 || j + 1 == w) {
					cout << '#';
				}
				else {
					cout << ".";
				}

			}
			cout << endl;
		}

		cout << endl;

	}

	//cin >> /*変数他*/;
	//cout << /*文字列*/ << endl;
}


Measured memory_bytes: 3076
#include <iostream>
#define N_MAX 100
#define W_MAX 100000
using namespace std;

long int dp[N_MAX+1][W_MAX+1]={0};
int w[N_MAX],v[N_MAX];

int main(){
  int N,W,i,k;
  cin>>N>>W;
  for(i=0;i<N;i++){
    cin>>w[i+1]>>v[i+1];
  }

  for(i=1;i<=N;i++){
    for(k=1;k<=W;k++){
      if(k-w[i]>=0){
        dp[i][k]=max(dp[i-1][k],dp[i-1][k-w[i]]+v[i]);
      }else{
        dp[i][k]=dp[i-1][k];
      }
    }
  }
  cout<<dp[N][W]<<endl;
}

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

#define rep(i,x,y) for(int i=(x);i<(y);++i)
#define debug(x) #x << "=" << (x)

#ifdef DEBUG
#define _GLIBCXX_DEBUG
#define dump(x) std::cerr << debug(x) << " (L:" << __LINE__ << ")" << std::endl
#else
#define dump(x)
#endif

typedef long long int ll;
typedef pair<int,int> pii;
//template<typename T> using vec=std::vector<T>;

const int inf=1<<30;
const long long int infll=1LL<<58;
const double eps=1e-9;
const int dx[]={1,0,-1,0},dy[]={0,1,0,-1};

template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec){
	os << "[";
	for (const auto &v : vec) {
		os << v << ",";
	}
	os << "]";
	return os;
}

void solve(){
    while(true){
        int n;
        cin >> n;
        if(n==0) break;

        vector<string> words(n);
        for(auto& w:words) cin >> w;
        for(auto it=words.begin(); it!=words.end();){
            if(![&]{
                for(auto it2=words.begin();it2!=words.end(); ++it2) if(it2!=it and it2->find(*it)!=string::npos){
                    it=words.erase(it);
                    return true;
                }
                return false;
            }()) ++it;
        }

        const int size=words.size();
        vector<vector<int>> graph(size,vector<int>(size));
        rep(i,0,size) rep(j,0,size){
            const string& w1=words[i],w2=words[j];
            int same_len=0;
            for(int len=0; len<=min(w1.size(),w2.size()); ++len) if(w1.substr(w1.size()-len,len)==w2.substr(0,len)) same_len=len;
            graph[i][j]=w2.size()-same_len;
        }

        static int dp[1<<14][20];
        fill_n((int*)dp,(1<<14)*20,inf);
        for(int i=0; i<size; ++i) dp[1<<i][i]=words[i].size();
        function<int(int,int)> rec=[&](int state,int v){
            int& res=dp[state][v]; if(res!=inf) return res;
            for(int u=0; u<size; ++u) if(u!=v and (state>>u)&1) res=min(res,rec(state&~(1<<v),u)+graph[u][v]);
            return res;
        };

        int ans=inf;
        for(int i=0; i<size; ++i) ans=min(ans,rec((1<<size)-1,i));
        cout << ans << endl;
    }
}

int main(){
	std::cin.tie(0);
	solve();
	return 0;
    std::ios::sync_with_stdio(false);
}

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

using namespace std;

const int maxv = 100000;

int d[2][maxv];

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

	int n;
	cin >> n;
	vector<int> v(n);
	for (int i = 0; i < n; i++)
	{
		cin >> v[i];
		v[i]--;
		d[i & 1][v[i]]++;
	}

	int idx[2][2];
	for (int i = 0; i < 2; i++)
	{
		idx[i][0] = max_element(d[i], d[i] + maxv) - d[i];
		idx[i][1] = -1;
		for (int j = 0; j < maxv; j++)
		{
			if (j == idx[i][0])
				continue;
			if (idx[i][1] < 0 || d[i][idx[i][1]] < d[i][j])
				idx[i][1] = j;
		}
	}

	int ans = n;
	for (int i = 0; i < 2; i++)
	{
		for (int j = 0; j < 2; j++)
		{
			if (idx[0][i] != idx[1][j])
				ans = min(ans, n - d[0][idx[0][i]] - d[1][idx[1][j]]);
		}
	}

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 4496
def main():
    n = int(input())
    a = list(map(int, input().rstrip().split(' ')))
    total = 0
    n_count = 0
    n_max = -10000000000
    p_min = 10000000000
    for i in range(n):
        if a[i] < 0:
            n_count += 1
            if n_max < a[i]:
                n_max = a[i]
        else:
            if p_min > a[i]:
                p_min = a[i]
    if n_count % 2 == 0:
        total = sum(map(abs, a))
    else:
        total = sum(map(abs, a)) - 2 * min(p_min, abs(n_max))
    print(total)

if __name__ == '__main__':
    main()

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

#define debug(x) cerr << #x << " = " << x << endl;
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define FOR(it, b, e) for (typeof(b) it = (b); it != (e); ++it)
#define MSET(c, v) memset(c, v, sizeof(c))

const int INF = 0x3F3F3F3F; 
const int NEGINF = 0xC0C0C0C0;
const int NULO = -1;
const ll mod = 1e9 + 7;
const double EPS = 1e-10;

inline int cmp(double x, double y = 0) 
{  
  if(fabs(x - y) < EPS)
    return 0;
  return x > y ? 1 : -1;
}

ll exp(ll a, ll b)
{
  ll ans = 1;
  while(b)
  {
    if(b & 1)
      ans = (ans * a) % mod;
    a = (a * a) % mod;
    b >>= 1;
  }
  return ans;
}


const int maxn = 2505 + 5;
ll fat[maxn], inv[maxn];

ll C(int n, int k)
{
  if(n < k) 
    return 0;
  if(n < 0 || k < 0) 
    return 0;
  return (((fat[n] * inv[k]) % mod) * inv[n - k]) % mod;
}

void initFactorials()
{
  fat[0] = 1;
  inv[0] = 1;
  for(int i = 1; i < maxn; i++)
  {
    fat[i] = (i * fat[i-1]) % mod;
    inv[i] = exp(fat[i], mod - 2);
  }
}

int main()
{
  initFactorials();
  ios::sync_with_stdio(0);
  int n;
  cin >> n;
  vector<pair<int,int>>v;
  for(int i = 0 ; i < n ; i++)
  {
    int a,b;
    cin >> a >> b;
    v.push_back({a, b});
  }
  sort(all(v), [](pair<int,int>a, pair<int,int>b){
    return a.second < b.second;
  });

  int dist = 0;
  bool cant = false;
  for(int i = 0; i < n; i++)
  {
    dist += v[i].first;
    if(dist > v[i].second)
      cant = true;
  }

  cout << (cant ? "No" : "Yes") << endl;

  return 0;
}

Measured memory_bytes: 5328
import fractions
n, x = map(int, input().split())
x_list = sorted(list(map(int, input().split())) + [x])
ans = x_list[1] - x_list[0]
for i in range(1, n + 1):
    ans = fractions.gcd(x_list[i] - x_list[i - 1], ans)
print(ans)

Measured memory_bytes: 16280
fun main(args : Array<String>) {
    val n = readLine()!!.toInt()
    val ss = readLine()!!
    val tt = readLine()!!

    var merged = ss.length

    while (merged > 0) {
        if (merged > tt.length) {
            merged--
            continue
        }

        if (ss.takeLast(merged) == tt.take(merged)) {
            break
        }

        merged--
    }

    println(ss.length + tt.length - merged)
}



Measured memory_bytes: 33776
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <vector>
#include <list>
#include <queue>
#include <sstream>
#include <cmath>
#include <functional>
using namespace std;

#define rep(i,n) for(int i=0;i<n;i++)
#define reps(s,i,n) for(int i=s;i<n;i++)
#define rev(i,n) for(int i=n-1;i>=0;i--)
#define skip(i,n,p) for(int i=0;i<n;i+=p)
#define all(a)  (a).begin(),(a).end()
#define int64 long long
#define debug cerr << __FILE__ << ":" << __LINE__ << endl;
#define INF 2147483647

struct Init {
    Init() {
        cin.tie(0);
        ios::sync_with_stdio(false);
        cout.precision(20);
        cout << fixed;
    }
} init;

template <typename _Ty>
ostream& operator << (ostream& ostr, const vector<_Ty>& v) {
    for(int i = 0; i < (int) v.size(); i++) {
        ostr << v[i] << (i + 1 != v.size() ? " " : "");
    }
    return ostr;
}

template <typename _K, typename _V>
ostream& operator << (ostream& ostr, const map<_K, _V>& v) {
    ostr << "{";
    for (auto iter = v.begin(); iter != v.end(); ++iter) {
        ostr << (*iter).first << ": " << (*iter).second << ", ";
    }
    ostr << "}";
    return ostr;
}

template <typename _K>
ostream& operator << (ostream& ostr, const set<_K>& v) {
    for (auto iter = v.begin(); iter != v.end(); ++iter) {
        ostr << *iter << (iter != v.end() ? " " : "");
    }
    return ostr;
}

template <typename _K, typename _V>
ostream& operator << (ostream& ostr, const pair<_K, _V>& v) {
    ostr << v.first << " " << v.second;
    return ostr;
}

int main() {
    string s; cin >> s;

    rep(_, s.size()) {
        cout << "x";
    }
    cout << endl;
}


Measured memory_bytes: 256
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define all(v) v.begin(), v.end()
using in = int64_t;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl
#define yes cout<<"yes"<<endl
#define no cout<<"no"<<endl
const double PI=3.14159265358979323846;
const in MOD = 1000000007;
const in INF=1e18+7;
const int inf=1e9+7;
using P=pair<int,int>;
vector<int> dx={0,1,-1,0};
vector<int> dy={1,0,0,-1};



int main(){
ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
cout << fixed << setprecision(10);
    string s;
    cin>>s;
    int n=s.size();
    cout<<s[0]<<n-2<<s[n-1];
}
//./problem.exe

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		new Main().solveA();
		// new Main().solveB();
		// new Main().solveC();
		// new Main().solveD();
	}

	private void solveA() {
		Scanner scanner = null;
		int numN = 0;

		try {
			scanner = new Scanner(System.in);
			numN = scanner.nextInt();

			if (numN > 999) {
				System.out.println("ABD");
			} else {
				System.out.println("ABC");
			}

		} finally {
			if (scanner != null) {
				scanner.close();
			}
		}
	}

	private void solveB() {
		Scanner scanner = null;
		int numN = 0;
		int numK = 0;
		int numS = 0;

		try {
			scanner = new Scanner(System.in);
			numN = scanner.nextInt();

			System.out.println("");

		} finally {
			if (scanner != null) {
				scanner.close();
			}
		}
	}

	private void solveC() {
		Scanner scanner = null;
		int numN = 0;
		int numK = 0;
		int numS = 0;

		try {
			scanner = new Scanner(System.in);
			numN = scanner.nextInt();

			System.out.println("");

		} finally {
			if (scanner != null) {
				scanner.close();
			}
		}
	}

	private void solveD() {
		Scanner scanner = null;
		int numN = 0;
		int numK = 0;
		int numS = 0;

		try {
			scanner = new Scanner(System.in);
			numN = scanner.nextInt();

			System.out.println("");

		} finally {
			if (scanner != null) {
				scanner.close();
			}
		}
	}
}

Measured memory_bytes: 22612
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <set>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <cstdio>
#include <cstring>
#include <iterator>
#include <bitset>
#include <unordered_set>
#include <unordered_map>
#include <fstream>
#include <iomanip>
#include <cassert>
//#include <utility>
//#include <memory>
//#include <functional>
//#include <deque>
//#include <cctype>
//#include <ctime>
//#include <numeric>
//#include <list>
//#include <iomanip>

//#if __cplusplus >= 201103L
//#include <array>
//#include <tuple>
//#include <initializer_list>
//#include <forward_list>
//
//#define cauto const auto&
//#else

//#endif

using namespace std;


typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;

#define VV(T) vector<vector< T > >

template <class T>
void initvv(vector<vector<T> > &v, int a, int b, const T &t = T()){
    v.assign(a, vector<T>(b, t));
}

template <class F, class T>
void convert(const F &f, T &t){
    stringstream ss;
    ss << f;
    ss >> t;
}

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define reep(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) reep((i),0,(n))
#define ALL(v) (v).begin(),(v).end()
#define PB push_back
#define F first
#define S second
#define mkp make_pair
#define RALL(v) (v).rbegin(),(v).rend()
#define DEBUG
#ifdef DEBUG
#define dump(x)  cout << #x << " = " << (x) << endl;
#define debug(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
#else
#define dump(x) 
#define debug(x) 
#endif

#define MOD 1000000007LL
#define EPS 1e-8
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3fLL
#define maxs(x,y) x=max(x,y)
#define mins(x,y) x=min(x,y)

void mainmain(){
	int n;
	cin>>n;
	vint v(n);
	rep(i,n) cin>>v[i],v[i]--;
	int ans = 0;
	rep(i,n){
		if(v[v[i]] == i) ans++;
	}
	cout<<ans/2<<endl;
}


signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout<<fixed<<setprecision(20);
    mainmain();
}

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

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  vector<int> a(n);
  for (auto&& x : a) {
    cin >> x;
  }
  int q;
  cin >> q;
  int ans = 0;
  while (q--) {
    int key;
    cin >> key;
    int lower = -1;
    int upper = n;
    while (upper - lower > 1) {
      int mid = (upper + lower) / 2;
      if (a[mid] >= key) {
        upper = mid;
      } else {
        lower = mid;
      }
    }
    if (a[upper] == key) {
      ans++;
    }
  }
  cout << ans << '\n';
  return 0;
}



Measured memory_bytes: 3204
a = input()
b = input()

if len(a)==len(b):
    for i in range(len(a)):
        if a[i]>b[i]:
            print("GREATER")
            quit()
        elif a[i]<b[i]:
            print("LESS")
            quit()
            
elif len(a)>len(b):
    print("GREATER")
    quit()
else:
    print("LESS")
    quit()

print("EQUAL")

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

using namespace std;

#define rep(i,m,n) for(int (i)=(int)(m);i<(int)(n);i++)
#define rep2(i,m,n) for(int (i)=(int)(n)-1;i>=(int)(m);i--)
#define REP(i,n) rep(i,0,n)
#define REP2(i,n) rep2(i,0,n)
#define FOR(i,c) for(decltype((c).begin())i=(c).begin();i!=(c).end();++i)
#define ll long long
#define ull unsigned long long
#define all(hoge) (hoge).begin(),(hoge).end()
#define en '\n'
template <class T> using vec = vector<T>;
template <class T> using vvec = vector<vec<T>>;
typedef pair<ll, ll> P;
constexpr long long INF = 1LL << 60;
constexpr int INF_INT = 1 << 25;
constexpr long long MOD = (ll) 1e9 + 7;
typedef vector<ll> Array;
typedef vector<Array> Matrix;


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

struct Edge {
	ll to, cap, rev;
	Edge(ll _to, ll _cap, ll _rev) {
	to = _to; cap = _cap; rev = _rev;
	}
};
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;

void add_edge(Graph& G, ll from, ll to, ll cap, bool revFlag, ll revCap) {
	G[from].push_back(Edge(to, cap, (ll)G[to].size()));
	if (revFlag)G[to].push_back(Edge(from, revCap, (ll)G[from].size() - 1));
}

ll pow2_m(ll x, ll n, ll mod) {
 ll ans = 1ll;
 while (n > 0) {
  if ((n & 1) == 1) {
   ans = ans * x % mod;
  }
  x = x * x % mod;
  n >>= 1;
 }
 return ans;
}

void solve(){
    ll n,k;
    cin>>n>>k;
    Array arr(k+1,1);
    arr[1]=0;
    for (ll i = 2; i <= k*2; i++) {
        for (ll j = 2; i * j <= k; j++) {
            arr[i * j] += i-arr[i];
        }
    }

    ll ans=0;
    for(ll i=1;i<=k;i++){
        ll c=k/i;
        (ans+=pow2_m(c,n,MOD)*(i-arr[i])%MOD)%=MOD;
    }
    cout<<ans<<en;
}

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

    solve();
    //ll t;cin>>t;REP(i,t) solve();

    return 0;
}


Measured memory_bytes: 3988
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
#define fi first
#define se second
typedef pair<ll,ll> P;
#define Mod 1000000007
using VP = vector<P>; using VVP = vector<VP>;
using VI = vector<ll>; using VVI = vector<VI>; using VVVI = vector<VVI>;
#define INF 12345678890


int main(){
    ll i,j;
    ll h,w;
    cin>>h>>w;
    char a[h][w];
    for(i=0;i<h;i++){
        for(j=0;j<w;j++) cin>>a[i][j];
    }
    char b[h][w];
    char c[h][w];
    for(i=0;i<h;i++){
        for(j=0;j<w;j++){
            if(i==0) b[i][j]='#';
            else if(i==h-1) b[i][j]='.';
            else if(j%2==0) b[i][j]='#';
            else b[i][j]='.';
        }
    }
    for(i=0;i<h;i++){
        for(j=0;j<w;j++){
            if(i==0) c[i][j]='.';
            else if(i==h-1) c[i][j]='#';
            else if(j%2==0) c[i][j]='.';
            else c[i][j]='#';
        }
    }
    for(i=0;i<h;i++){
        for(j=0;j<w;j++) {
            if(a[i][j]=='#'){
                b[i][j]='#';
                c[i][j]='#';
            }
        }
    }
    for(i=0;i<h;i++){
        for(j=0;j<w;j++){
            cout<<b[i][j];
        }
        cout<<endl;
    }
    cout<<endl;
    for(i=0;i<h;i++){
        for(j=0;j<w;j++){
            cout<<c[i][j];
        }
        cout<<endl;
    }

   
    return 0;
}

Measured memory_bytes: 1408
#include<bits/stdc++.h>
using namespace         std;
#define                 int long long
#define                 pb push_back
#define                 mp make_pair
#define st(arr,a)       memset(arr,a,sizeof arr)
#define                 nl cout<<endl
#define                 real signed
#define                 endl '\n'              
#define bitcount(x)     __builtin_popcountll(x)
const int MOD = 1000000007ll;
#define forn(i,a,b)     for(int i=a;i<=b;i++)
#define rfor(i,a,b)     for(int i=a;i>=b;i--)
#define all(x)          x.begin() , x.end()
#define pi pair<int,int>
#define X first
#define Y second
#define N 1014159
#define  vi vector<int>
#define  v  vector


int n,k;
int arr[N];

void solve()
{
    cin>>n>>k;
    int ans = 0;
    forn(i,1,n)cin>>arr[i];
    forn(i,1,n)
    {
        int a = 0 , b = 0;
        forn(j,1,i)if(arr[j]>arr[i])a++;
        forn(j,i,n)if(arr[j]>arr[i])b++;
        int p = k-1;
        int x = ((k*k+k)/2)%MOD;
        int y = ((p*p+p)/2)%MOD;
        ans+=a*x+b*y;
        
        ans%=MOD;
    }

    cout<<ans;


}


signed main() 
{
    ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); 
    int t = 1;
    //cin>>t;
    while(t--)
    {
        solve();
    }



    return 0;

}

//       g++ -g c.cpp ; ./a.exe

Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10 ** 7)

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

N, K = map(int, input().split())

MOD = 10 ** 9 + 7

ans = 0
num = 0
CNT = [0] * (K+1)
for i in range(K, 1, -1):
    n = K // i
    c = pow(n, N, MOD)

    ni = i + i
    while ni <= K:
        c -= CNT[ni]
        ni += i

    ans += c * i
    ans %= MOD
    num += c
    CNT[i] = c

rest = pow(K, N, MOD)
ans += rest - num
ans %= MOD

print(ans)


Measured memory_bytes: 11236
def solve():
    c = [[int(i) for i in input().split()] for _ in range(3)]
    for i in range(2):
        for j in range(2):
            if not c[i][j]-c[i+1][j] == c[i][j+1]-c[i+1][j+1]:
                return 'No'
    for i in range(2):
        for j in range(2):
            if not c[j][i]-c[j][i+1] == c[j+1][i]-c[j+1][i+1]:
                return 'No'
    return 'Yes'
        

if __name__ == '__main__':
    print(solve())

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

int main(){
  ll a,b,c,x,y;
  cin>>a>>b>>c>>x>>y;
  ll ans=ll(1e18);
  for(ll i=0;i<=2*max(x,y);i+=2){
    ll tmp=i*c;
    tmp+=max(0LL,x-i/2)*a+max(0LL,y-i/2)*b;
    ans=min(ans,tmp);
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 3548
s = input()
start = 0
end = 0

for i in range(len(s)):
    if s[i] == 'A':
        start = i
        break

for i in range(len(s)):
    p = len(s) - 1 - i
    if s[p] == 'Z':
        end = p
        break
print(end - start + 1)

Measured memory_bytes: 3512
#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::*;

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}

fn binary_search<F>(lb: usize, ub: usize, criterion: F) -> usize
where
    F: Fn(usize) -> bool,
{
    let mut lb = lb;
    let mut ub = ub;
    while ub - lb > 1 {
        let mid = (ub + lb) / 2;
        if criterion(mid) {
            lb = mid;
        } else {
            ub = mid;
        }
    }
    lb
}

fn main() {
    let n: usize = read();
    let a = read_vec::<u64>();
    let mut a_clone = a.clone();
    a_clone.sort();
    let criterion = |i: usize| {
        let d = a_clone[i];
        let a_deg = a
            .iter()
            .map(|&x| if x >= d { 1 } else { -1 })
            .collect::<Vec<i64>>();
        let mut s = vec![0i64; n + 1];
        for i in 0..n {
            s[i + 1] = s[i] + a_deg[i];
        }
        let mut indexes = argsort(&s);
        let mut c = vec![0; n + 1];
        for i in 0..n + 1 {
            c[indexes[i]] = n + 1 - i;
        }
        let count = count_inversion(&c);
        count >= (n * (n - 1) / 2 + n) / 2
    };
    println!("{}", a_clone[binary_search(0, n, criterion)]);
}

fn count_inversion(v: &Vec<usize>) -> usize {
    let mut ans = 0;
    let mut bt = BinaryIndexTree::new(v.len());
    for i in 0..v.len() {
        ans += i - bt.sum(v[i]) as usize;
        bt.add(v[i], 1);
    }
    ans
}

fn argsort<T: std::cmp::Ord + std::marker::Copy>(v: &Vec<T>) -> Vec<usize> {
    let mut sort_v = Vec::new();
    for i in 0..v.len() {
        sort_v.push((v[i], i));
    }
    sort_v.sort();
    sort_v.iter().map(|x| x.1).collect::<Vec<usize>>()
}

struct BinaryIndexTree {
    bit: Vec<i64>,
    n: usize,
}

impl BinaryIndexTree {
    fn new(n: usize) -> BinaryIndexTree {
        BinaryIndexTree {
            bit: vec![0; n + 1],
            n: n,
        }
    }

    fn sum(&self, i: usize) -> i64 {
        let mut i = i;
        let mut s = 0i64;
        while i > 0 {
            s += self.bit[i];
            i -= (i as i64 & -(i as i64)) as usize;
        }
        s
    }

    fn add(&mut self, i: usize, x: i64) {
        let mut i = i;
        while i <= self.n {
            self.bit[i as usize] += x;
            i += (i as i64 & -(i as i64)) as usize;
        }
    }
}


Measured memory_bytes: 14328
#include <bits/stdc++.h>
#define int long long
#define P(x) {if (debug) cout << x << endl;}
#define H(x) P(#x << ": " << (x))
#define FR(i,a,b) for (int i=(a); i<(b); i++)
#define F(i,n) FR(i,0,n)
#define D(i,n) for (int i=(n); i-->0;)
#define S(s) (int)(s).size()
#define ALL(v) v.begin(), v.end()
#define V vector
#define pb push_back
#define mt make_tuple
using namespace std;
template<class T> ostream& operator<<(ostream& os, V<T> v) {
    F(i,S(v)) os<<(i?" ":"")<<v[i]; return os;}
const bool debug = 0;
const int INF=1e18;

struct edge {int v,c,f,i;};
struct graph {
    int n; V<V<edge>> g; V<int> d,cur;
    graph(int _n) : n(_n), g(n) {}
    void add(int u, int v, int c1=INF, int c2=0) {
        g[u].pb({v, c1, 0, S(g[v])});
        g[v].pb({u, c2, 0, S(g[u])-1});
    }
    int aug(int u, int t, int limf) {
        if (u == t) return limf;
        for (int &i=cur[u], f; i<S(g[u]); i++) {
            edge &e = g[u][i];
            if (e.c > e.f && d[e.v] == d[u]+1 &&
                (f = aug(e.v, t, min(limf, e.c-e.f)))) {
                e.f += f;
                g[e.v][e.i].f -= f;
                return f;
            }
        }
        return 0;
    }
    int maxf(int s, int t) {
        int mf=0, f;
        while (true) {
            d.assign(n, INF); d[s] = 0;
            queue<int> q; q.push(s);
            while (S(q)) {
                int u = q.front(); q.pop();
                for (edge e : g[u])
                    if (e.c > e.f && d[e.v] == INF)
                        d[e.v] = d[u]+1, q.push(e.v);
            }
            if (d[t] == INF) break;
            cur.assign(n,0);
            while (mf += (f = aug(s,t,INF)), f);
        }
        return mf;
    }
};

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    int n; cin>>n;
    V<int> a(n+1,0);
    FR(i,1,n+1) cin>>a[i];
    int nv=n+1, s=nv++, t=nv++;
    V<int> ps;
    FR(i,2,n+1) {
        bool ok=true;
        FR(j,2,i) if (i%j == 0)
            ok = false;
        if (ok) ps.pb(i);
    }
    H(ps)
    graph g(nv);
    int tot=0;
    FR(i,1,n+1) {
        for (int p : ps)
            if (i*p <= n)
                g.add(i,i*p);
        if (a[i] > 0) {
            g.add(i, t, a[i]);
            tot += a[i];
        }
        else g.add(s, i, -a[i]);
    }
    int mf = g.maxf(s,t);
    H(tot)
    H(mf)
    cout<<tot-mf<<"\n";
}

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


int main()
{
	int a, b, c;
	cin >> a >> b >> c;
	if (a < b&&b < c) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
	return 0;
}

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

# define C continue;
# define R return

# define D double
# define I insert
# define ll long long
# define ld long double
# define ull unsigned long long

# define pb push_back
# define vi vector < int >
# define vc vector < char >
# define vs vector < string >
# define vb vector < bool >
# define vd vector < D >
# define vll vector < ll >
# define vull vector < ull >

# define vvi vector < vector < int > >
# define vvb vector < vector < bool > >
# define vvc vector < vector < char > >
# define vvll vector < vector < ll > >
# define vvd vector < vector < D > >
# define vld vector < ld >

# define all(v) (v).begin() , (v).end()
# define allrev(v) (v).rbegin() , (v).rend()
# define allcomp(v) v.begin() , v.end() , comp
# define allrevcomp(v) v.rbegin() , v.rend() , comp

# define pii pair < int , int >
# define pll pair < long , long >
# define pDD pair < D , D >
# define vpii vector < pii >
# define vpll vector < pll >
# define vpDD vector < pDD >

# define vvpii vector < vector < pii > >
# define F first
# define S second
# define mp make_pair

# define fast ios_base::sync_with_stdio(false) ; cin.tie(0) ; cout.tie(0);
# define dist(a,b,p,q) sqrt((p-a)*(p-a) + (q-b)*(q-b));
# define mod 1000000007

# define pp(n) printf("%.10f",n);
# define line cout<<"\n";

const D pie = acos(-1);
const D hpie = asin(1);
const D qpie = atan2(1,1);
const D tpie = 2*pie;

string vow = "aeiou";

void solve( int test_case )
{
    ll l , r;
    cin >> l >> r;

    ll maxx = min(l+2019,r);

    ll ans = 1e4;
    for ( ll i=l ; i<=maxx ; i++ )
    {
        for ( ll j=l ; j<=maxx ; j++ )
        {
            if ( i==j ) C;
            ans = min ( ans , ((i*j)%2019) );
        }
    }

    cout << ans;
    line
}

int main()
{
    fast
    int t = 1;
    //cin>>t;

    for ( int i=0 ; i<t ; i++ ) solve(i);
    return 0;
}


Measured memory_bytes: 256
using System;
class Program
{
	static void Main(string[] args)
	{
		// 文字列の入力
		string s = Console.ReadLine();
        string t = Console.ReadLine();
		//出力
        string result = s.Equals(t.Remove(t.Length - 1, 1)) ? "Yes" : "No";
		Console.WriteLine(result);
	}
}

Measured memory_bytes: 25892
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<cmath>
#include<string>
using namespace std;
string st;
int f[1000+5][1000+5],l;
int main()
{
    f[int('b')][int('d')]=1;f[int('d')][int('b')]=1;
    f[int('p')][int('q')]=1;f[int('q')][int('p')]=1;
    cin>>st;
    st=" "+st;l=st.size();l--;
    for (int i=1;i<=l;i++)
      if (f[int(st[i])][int(st[l-i+1])]==0) {cout<<"No";return 0; } 
    cout<<"Yes";
	return 0;
}


Measured memory_bytes: 512
#include <iostream>
#include <string>
#include <cmath>
#include <ctime>
#include <vector>
#include <algorithm>
#include <cstdlib>
#include <set>
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;

int main(){
    int H1, M1, H2, M2, K;
    cin >> H1 >> M1 >> H2 >> M2 >> K;

    int T1, T2;
    T1 = H1*60 + M1;
    T2 = H2*60 + M2;

    cout << T2 -T1 - K << endl;


}

Measured memory_bytes: 3636
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <cstring>
#include <functional>
#include <set>
#include <map>
#include <cmath>
#include <string>
#define SIZE 20005

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

int diff[SIZE];
int A[SIZE],C[SIZE];

int main()
{
	int n;
	scanf("%d",&n);
	for(int i=0;i<n;i++)
	{
		int p;
		scanf("%d",&p);p--;
		diff[p]=i;
	}
	A[0]=diff[0]+1;
	C[0]=1;
	for(int i=1;i<n;i++)
	{
		A[i]=max(A[i-1]+1,C[i-1]+1+diff[i]);
		C[i]=A[i]-diff[i];
	}
	for(int i=0;i<n;i++)
	{
		if(i!=0) printf(" ");
		printf("%d",A[i]);
	}puts("");
	for(int i=0;i<n;i++)
	{
		if(i!=0) printf(" ");
		printf("%d",C[n-1]-C[i]+1);
	}puts("");
	return 0;
}


Measured memory_bytes: 768
#include <algorithm>
#include <iostream>
#include <vector>

using namespace std;

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

  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  int q;
  cin >> q;
  int x;
  int ans = 0;
  for (int i = 0; i < q; i++) {
    cin >> x;
    auto it = lower_bound(a.begin(), a.end(), x);
    if (it != a.end() && *it == x) ++ans;
  }
  cout << ans << endl;

  return 0;
}



Measured memory_bytes: 3288
object Main extends App {
	val Array(n, m, d) = scala.io.StdIn.readLine.split(" ").map(_.toLong)

	if(d == 0L){
		println((m-1.0)/n)		
	}else{
		println((m-1.0)*2.0*(n-d)/(n*n))
	}
}

Measured memory_bytes: 27308
import sys
import copy
import math
import bisect
import pprint
import bisect
from functools import reduce
from copy import deepcopy
from collections import deque

def lcm(x, y):
    return (x * y) // math.gcd(x, y)

if __name__ == '__main__':
    s = input()
    count =0
    
    for i in range(6):
        if "1" == s[i]:
            count+=1
    print(count)

Measured memory_bytes: 3828
# coding: utf-8
a, b, c = map(int, input().split())
k = int(input())

for i in range(k+1):
    bb = b * (2 ** i)
    cc = c * (2 ** (k - i))

    if a < bb and bb < cc:
        ans = "Yes"
        break
    else:
        ans = "No"

print(ans)


Measured memory_bytes: 9164
#include<bits/stdc++.h>
using namespace std;
# ifdef DEB
# define debug(...) fprintf(stderr, __VA_ARGS__)
# else
# define debug(...)
#endif
#define F first
#define S second
#define MP make_pair
#define PB push_back
#define LL long long
#define LD long double
#define PII pair<int, int>
#define PLL pair<LL, LL>
#define pb pop_back
#define VI vector<int> 
#define VPI vector<PII> 
#define FOR(i,a,b) for(int i = (a); i <= (b); i++)
#define FORD(i,a,b) for(int i = (a); i >= (b); i--)
#define RE(i,n) FOR(i,1,n)
#define REP(i,n) FOR(i,0,(int)(n)-1)
#define ALL(x) (x).begin(), (x).end()
#define siz(V) ((int)V.size())
const int M = 100005;

int dp[M][2], T[M];
int n;

int main()
{
  //ios_base::sync_with_stdio(0);
  scanf("%d", &n);
  for (int i = 0; i < n; i++)
  {
    scanf("%d", T + i);
  }
  dp[n - 1][0] = 1;
  dp[n - 1][1] = 1;
  for (int i = n - 2; i >= 0; i--)
  {
    if (T[i] > T[i + 1])
    {
      dp[i][1] = min(dp[i + 1][1], dp[i + 1][0] + 1);
      dp[i][0] = min(dp[i + 1][1], dp[i + 1][0]) + 1;
    }
    if (T[i] < T[i + 1])
    {
      dp[i][1] = min(dp[i + 1][1], dp[i + 1][0]) + 1;
      dp[i][0] = min(dp[i + 1][1] + 1, dp[i + 1][0]);
    }
    if (T[i] == T[i + 1])
    {
      dp[i][1] = min(dp[i + 1][1], dp[i + 1][0] + 1);
      dp[i][0] = min(dp[i + 1][1] + 1, dp[i + 1][0]);
    }
  }
  printf("%d\n", min(dp[0][0], dp[0][1]));
  return 0;
}

Measured memory_bytes: 1408
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<stack>
#include<cmath>
using namespace std;
typedef long long ll;
ll MOD = 1e9+7;
#define rep(i,n) for(int i = 0; i < (n); ++i)
int main() {
    int n, k, x, y;
    cin >> n >> k >> x >> y;
    if ( n <= k ) {
        cout << x * n << endl;
    }
    else {
        cout << x * k + y * ( n - k ) << endl;
    }
    return 0;
}


Measured memory_bytes: 256
import java.util.*;
import java.lang.*;
import java.math.*;
import java.io.*;

import static java.lang.Math.*;
import static java.util.Arrays.*;

public class Main{

	Scanner sc;

	static final int INF=1<<28;
	static final double EPS=1e-9;

	void run(){
		sc=new Scanner(System.in);
		int rectangle=0;
		int diamond=0;
		for(;sc.hasNext();){
//		for(int i=0;i<4;i++){
			String[] s=sc.nextLine().split(",");
			int e1=Integer.parseInt(s[0]);
			int e2=Integer.parseInt(s[1]);
			int d=Integer.parseInt(s[2]);
			if(e1*e1+e2*e2==d*d){
				rectangle++;
			}else if(e1==e2&&e1+e2>d){
				diamond++;
			}
		}
		println(rectangle+"");
		println(diamond+"");
		sc.close();
	}

	void print(String s){
		System.out.print(s);
	}

	void println(String s){
		System.out.println(s);
	}

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

Measured memory_bytes: 12000
process.stdin.resume();
process.stdin.setEncoding('utf8');
process.stdin.on('data', function(input){
    var line = input.trim().split("\n");
    var i = 0;
    for(i=0;i<line.length;)
    {
        var N = parseInt(line[i++].trim());
        if( N === 0 ){
            break;
        }
        else{
            var found, len, k, res;
            var qualified = [], amount = [];
            for(var j=0;j<N;++j){
                var dataset = line[i++].trim().split(" ");
                res = parseInt(dataset[1]) * parseInt(dataset[2]);
                
                found = 0;
                len = qualified.length;
                for(k=0;k<len;++k){
                    if(qualified[k] == dataset[0]){
                        found = 1;
                        amount[k] = amount[k] + res;
                        break;
                    }
                }
                
                if( !found ){
                    qualified.push(dataset[0]);
                    amount.push(res);
                }
            }
            
            found = 0;
            len = qualified.length;
            for(k=0;k<len;++k){
                if( amount[k] >= 1000000 ){
                    console.log(qualified[k]);
                    found = 1;
                }
            }
            if( !found ){
                console.log("NA");
            }
        }
    }
});

Measured memory_bytes: 17520
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for (int i=0;i<(n);i++)
//#define int long long  
int main(){
    string S[3];
    int a=0,b=0,c=0;
    int turn =0;
    cin >> S[0] >> S[1] >> S[2];
    while(1){
        if(turn==0){
            if(a>=S[0].size()){
                cout << "A" << endl;
                return 0;
            }
            turn=S[0][a]-'a';
            a++;
        }
        if(turn==1){
            if(b>=S[1].size()){
                cout << "B" << endl;
                return 0;
            }
            turn=S[1][b]-'a';
            b++;
        }
        if(turn==2){
            if(c>=S[2].size()){
                cout << "C" << endl;
                return 0;
            }
            turn=S[2][c]-'a';
            c++;
        }
    }
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define int long long
using namespace std;
const int INF=10000000000000000;
signed main(){
  int N,M;
  cin>>N>>M;
  vector<vector<int>> A(M+1,vector<int>(1<<N,INF));
  A[0][0]=0;
  for(int i=0;i<M;i++){
    int a,b;
    cin>>a>>b;
    int bit=0;
    while(b--){
      int c;
      cin>>c;
      bit=bit|(1<<(c-1));
    }
    for(int j=0;j<(1<<N);j++)A[i+1][j]=A[i][j];
    for(int j=0;j<(1<<N);j++)A[i+1][j|bit]=min(A[i+1][j|bit],A[i][j]+a);
  }
  cout<<(A[M][(1<<N)-1]==INF?-1:A[M][(1<<N)-1])<<endl;
}

Measured memory_bytes: 35372
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <limits.h>
#define swap(type,a,b) do{type t=a;a=b;b=t;}while(0);
#define MAX(a,b) (((a)>(b))?(a):(b))
#define MIN(a,b) (((a)<(b))?(a):(b))
#define ll long long
#define INF 100000000
#define FOR(i,a,n) for(i=(a);i<(n);i++)
int comp(const void* a,const void* b){
	return *(int*)a-*(int*)b;
}
void fill(int a[],int b,int c){
	int i;
	FOR(i,0,b) a[i]=c;
	return;
}
int main(void)
{
	int a,b;
	scanf("%d%d",&a,&b);
	if(a>0) puts("Positive");
	else if(a<=0&&b>=0) puts("Zero");
	else{
		if((b-a)%2) puts("Positive");
		else puts("Negative");
	}
	return 0;
}
    
    


Measured memory_bytes: 128
n = int(input())
p = [list(map(int, input().split())) for _ in range(n)]
import numpy as np
import math
import itertools
t = math.factorial(n)/(math.factorial(2)*math.factorial(n-2))
# print(t)
dist = np.zeros(int(t))
count =0
for i in range(n-1):
    # print(i)
    for j in range(i+1,n):
        # print(j,'j')
        dist[count] = math.sqrt(pow(p[i][0]-p[j][0],2)+pow(p[i][1]-p[j][1],2))
        count += 1

# print(dist)
print(2*sum(dist)/n)

Measured memory_bytes: 12500
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,a,b=0;
  cin>>n;
  a=n;
  while(a)b+=a%10,a/=10;
  if(n%b==0)cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
  return 0;
}

Measured memory_bytes: 256
#include <cassert>
#include <cstdio>
#include <cmath>
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <map>
#include <queue>
#include <algorithm>

#ifdef _DEBUG
#define DMP(x) cerr << #x << ": " << x << "\n"
#else
#define DMP(x) ((void)0)
#endif

const int MOD = 1000000007, INF = 1111111111; 
using namespace std;
using lint = long long;

int main() {

	cin.tie(nullptr);
	ios::sync_with_stdio(false);

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

	cout << (X - A) % B << "\n";

	return 0;
}

Measured memory_bytes: 256