akhauriyash/Code-Regression huggingface dataset:
use std::fmt::Write;

fn main(){
    let mut sc = Scanner::new();

    while sc.read() {
        let n = sc.next();
        let mut x = vec![0i64; n];
        for i in 0..n {
            x[i] = sc.next();
        }
        let mut d = vec![0i64; n-1];
        for i in 0..n-1 {
            d[i] = x[i+1] - x[i];
        }
        let m = sc.next();
        let k = sc.next();
        let mut perm:Vec<_> = (0..n-1).collect();
        for _ in 0..m {
            let a = sc.next::<usize>() - 1;
            perm.swap(a-1, a);
        }
        let perm2 = pow(&perm, k);
        let mut res = vec![0i64; n-1];
        for i in 0..n-1 {
            res[i] = d[perm2[i]];
        }
        
        let mut ans = String::new();
        let mut cur = x[0];
        writeln!(&mut ans, "{}", cur).unwrap();
        for i in 0..n-1 {
            cur += res[i];
            writeln!(&mut ans, "{}", cur).unwrap();
        }
        
        print!("{}", ans);
    }
}

fn pow(perm: &Vec<usize>, k: usize) -> Vec<usize> {
    if k == 0 {
        (0..perm.len()).collect()
    } else if k%2 == 1 {
        let x = pow(perm, k-1);
        prod(&x, &perm)
    } else {
        let x = pow(perm, k/2);
        prod(&x, &x)
    }
}

fn prod(a: &Vec<usize>, b: &Vec<usize>) -> Vec<usize> {
    let n = a.len();
    let mut res = vec![0; n];
    for i in 0..n {
        res[i] = a[b[i]];
    }
    res
}

#[allow(dead_code)]
struct Scanner {
    buf: Vec<u8>, i: usize, next: Option<String>,
}

#[allow(dead_code)]
impl Scanner {
    fn new() -> Scanner {
        Scanner { buf: vec![], i: 0, next: None, }
    }

    fn next<T: std::str::FromStr>(&mut self) -> T {
        self.wrapped::<T>().unwrap()
    }

    fn vec<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        let mut res = Vec::<T>::with_capacity(n);
        for _ in 0..n { res.push(self.next()) }
        res
    }

    fn wrapped<T: std::str::FromStr>(&mut self) -> Option<T> {
        self.read();
        self.next.take().and_then(|s| s.parse::<T>().ok())
    }

    fn read(&mut self) -> bool {
        if self.next.is_some() { return true }
        let mut s = String::with_capacity(16);
        while let Some(c) = self.get_char() {
            if !c.is_whitespace() { s.push(c); }
            else if !s.is_empty() { break; }
        }
        self.next = if !s.is_empty() { Some(s) } else { None };
        self.next.is_some()
    }

    fn get_char(&mut self) -> Option<char> {
        use std::io::Read;
        std::io::stdin().bytes().next().map(|x| x.unwrap() as char)
    }
}


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

using namespace std;

#define MAX_H 61
#define MAX_W 31
#define INF 1e9
#define Fi first
#define Se second
typedef pair<int,int> pii;

struct State{
  int d,x,y;
  bool f;
  State(){}
  State(int d,int x,int y,bool f) :
    d(d),x(x),y(y),f(f) {}
  bool operator > (const State &s)const{
    return d > s.d;
  }
};

int W,H;
int ps;
pii S[MAX_W],T[MAX_W];
char field[MAX_H][MAX_W];
int dist[MAX_H][MAX_W][2];
bool G[MAX_H][MAX_W];

const int dx[9] = {1,1,1,1,1,2,2,2,3};
const int dy[9] = {-2,-1,0,1,2,-1,0,1,0};

bool inField(int x,int y){
  return 0 <= x && x < W && 0 <= y && y < H;
}

int dijkstra(){
  priority_queue<State,vector<State>,greater<State> > Q;
  fill(dist[0][0],dist[0][0]+MAX_H*MAX_W*2,INF);
  for(int i = 0 ; i < ps ; i++){
    Q.push(State(0,S[i].Fi,S[i].Se,0)); 
    Q.push(State(0,S[i].Fi,S[i].Se,1));
    dist[S[i].Se][S[i].Fi][0] = 0;
    dist[S[i].Se][S[i].Fi][1] = 0;
  }

  while(!Q.empty()){
    State s = Q.top(); Q.pop();
    int x = s.x, y = s.y;

    if(dist[y][x][s.f] < s.d) continue;
    if(G[y][x]) return s.d;
    
    if(s.f){
      for(int i = 0 ; i < 9 ; i++){
        int nx = x - dx[i];
        int ny = y + dy[i];
        if(!inField(nx,ny)) continue;
        if(field[ny][nx] == 'X') continue;
        int t = field[ny][nx] - '0';
        if(s.d + t < dist[ny][nx][0]){
          dist[ny][nx][0] = s.d + t;
          Q.push(State(dist[ny][nx][0],nx,ny,0));
        }
      }
    }else{
      for(int i = 0 ; i < 9 ; i++){
        int nx = x + dx[i];
        int ny = y + dy[i];
        if(!inField(nx,ny)) continue;
        if(field[ny][nx] == 'X') continue;
        int t = field[ny][nx] - '0';
        if(s.d + t < dist[ny][nx][1]){
          dist[ny][nx][1] = s.d + t;
          Q.push(State(dist[ny][nx][1],nx,ny,1));
        }
      }
    }
  }
  return -1;
}

int main(){
  dijkstra();
  while(cin >> W >> H, W){
    ps = 0;
    memset(G,false,sizeof(G));
    for(int i = 0 ; i < H ; i++){
      for(int j = 0 ; j < W ; j++){
        cin >> field[i][j];
        if(field[i][j] == 'S'){
          S[ps++] = pii(j,i);
          field[i][j] = '0';
        }else if(field[i][j] == 'T'){
          G[i][j] = true;
          field[i][j] = '0';      
        }
      }
    }
    cout << dijkstra() << endl;
  }
  return 0;
}

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

int main(){
    int a,b,k;
    cin>>a>>b>>k;
    int gcm;
    int ans[100];
    int cnt=0;
    if(a<b)swap(a,b);
    for(int i=b;i>=1;i--){
        if(a%i==0&&b%i==0){
            gcm=i;
            break;
        }
    }
    for(int i=1;i<=gcm;i++){
        if(gcm%i==0){cnt++;
        ans[cnt]=i;}
    }
    cout<<ans[cnt-k+1]<<endl;
    return 0;
}

Measured memory_bytes: 3624
N = int(input())
A = list(map(int, input().split()))

mod = 10**9 + 7
sum_modA = 0
for a in A:
    sum_modA = (sum_modA + a) % mod

sum_mul = sum_modA**2 % mod
for a in A:
    sum_mul = (sum_mul - a**2 % mod) % mod

sum_mul = sum_mul * pow(2, mod - 2, mod) % mod

print(sum_mul)

Measured memory_bytes: 94128
#include <bits/stdc++.h>
#define IOS {ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);}
#define endl "\n"
#define float long double
#define int long long int
#define f(i, a, b) for(int i=a; i<b; i++)
#define fb(i, a, b) for(int i=a; i>=b; i--)
#define all(v) (v).begin(), (v).end()
#define pb push_back
#define fi first
#define se second
#define vi vector <int>
#define pi pair <int, int>
#define LB lower_bound
#define UB upper_bound
#define g(t, n) get<n>(t)
#define fp(x, y) fixed<<setprecision(y)<<x
#define PI 3.141592653589793238462643383279502884
using namespace std;

const int M = (int)2e5+5;
const int mod = (int)1e9+7;

int visited[M], cnt = 0;
vi adj[M];

void dfs(int v)
{
	visited[v] = 1;
	for(auto x : adj[v])
	{
		if(!visited[x])
		{
			dfs(x);
		}
	}
}

void solve()
{
	int n, m;
	cin>>n>>m;
	int u, v;
	f(i, 0, m)
	{
		cin>>u>>v;
		u--, v--;
		adj[u].pb(v);
		adj[v].pb(u);
	}
	f(i, 0, n)
	{
		if(!visited[i])
		{
			dfs(i);
			cnt++;
		}
	}
	cout<<cnt-1<<endl;
}

int32_t main()
{
    IOS
    int t = 1;
    // cin>>t;
    f(tno, 1, t+1)
    {
        // cout<<"Case #"<<tno<<": ";
        solve();
    }
    return 0;
}

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

ll n,w;
vector<ll> weight,val;
ll dp[100][100005];

ll maxCost(ll i,ll j){
	if(i>=n)
	return 0;
	
	if(dp[i][j]!=-1)
	return dp[i][j];
	
	if(j>=weight[i]){
		dp[i][j]=max(val[i]+maxCost(i+1,j-weight[i]),maxCost(i+1,j));
	}
	else
	    dp[i][j]=maxCost(i+1,j);
	    
	return dp[i][j];
}

int main(){
	cin>>n>>w;
	for(ll i=0;i<n;i++){
		ll n1,w1;
		cin>>w1>>n1;
		val.push_back(n1);
		weight.push_back(w1);
	}
	memset(dp,-1,sizeof(dp));
	cout<<maxCost(0,w)<<endl;
}

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

using namespace std;

#define REP(i, a, b) for (int i = (a), i##_end_ = (b); i < i##_end_; ++i)
#define debug(...) fprintf(stderr, __VA_ARGS__)
#define mp make_pair
#define x first
#define y second
#define pb push_back
#define SZ(x) (int((x).size()))
#define ALL(x) (x).begin(), (x).end()

template<typename T> inline bool chkmin(T &a, const T &b) { return a > b ? a = b, 1 : 0; }
template<typename T> inline bool chkmax(T &a, const T &b) { return a < b ? a = b, 1 : 0; }

typedef long long LL;

const int oo = 0x3f3f3f3f;

const int maxn = 500, maxm = 500;

int n, m;
char a[maxn + 5][maxm + 5];

int main()
{
#ifdef matthew99
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	scanf("%d%d", &n, &m);
	REP(i, 0, n) scanf("%s", a[i]);
	REP(i, 0, n)
	{
		REP(j, 0, m)
		{
			if (!j || (j < m - 1 && (i & 1))) putchar('#');
			else if (a[i][j] == '#') putchar('#');
			else putchar('.');
		}
		putchar('\n');
	}
	putchar('\n');
	REP(i, 0, n)
	{
		REP(j, 0, m)
		{
			if (j == m - 1 || (j && !(i & 1))) putchar('#');
			else if (a[i][j] == '#') putchar('#');
			else putchar('.');
		}
		putchar('\n');
	}
	return 0;
}


Measured memory_bytes: 1024
#include <stdio.h>
#include <string.h>

int main(){
  char odd[3][2] = {"R","U","D"};
  char even[3][2] = {"L","U","D"};
  char S1[101], S2[101];
  scanf("%s", S1);
  int len = strlen(S1);
  strcpy(S2, S1);
  for (int i = 0; i < len; i++) {
    int val = 1;
    int tmp = 0;
    if (i%2 == 1) val = 0;
    for (int j = 0; j < 3; j++) {
      if (val == 0) {
        if (strncmp(S2, &even[j][0], 1) == 0) tmp = 1;
      }
      else {
        if (strncmp(S2, &odd[j][0], 1) == 0) tmp = 1;
      }
    }
    if (tmp == 1 && i+1 != len) {
      strcpy(S2, &S1[i+1]);
    }
    else if (tmp == 0){
      printf("No\n");
      return 0;
    }
  }
  printf("Yes\n");
  return 0;
}

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

using namespace std;
#define int long long 
#define N 666666
int arr[N];
map<string,int> mp,vis;
signed main(){
	int n,m;
	int ans1=0;int ans2=0;
	cin>>n>>m;	
	string s1,s2;
	for(int i=1;i<=m;i++){
		cin>>s1>>s2;
		if(vis[s1]) continue;
		if(s2=="AC"){
			ans1++;
			ans2+=mp[s1];
			vis[s1]=1;
		}else if(s2=="WA"){
			mp[s1]++;
		}
		
	}cout<<ans1<<" "<<ans2;
	return 0;
}

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

using lli = long long int;
using Vint = vector<int>;
using Vlli = vector<lli>;
using Wint = vector<Vint>;
using Wlli = vector<Vlli>;
using pii = pair<int, int>;
using pll = pair<lli, lli>;

const int MOD = 1e9 + 7;
const int INFi = 2e9 + 1;
const lli INFl = (lli)(9e18) + 1;
// const vector<pii> DXDY = {make_pair(1, 0), make_pair(-1, 0), make_pair(0, 1), make_pair(0, -1)};

#define FOR(i, a, b) for(int (i) = (a); (i) < (b); (i)++)
#define FOReq(i, a, b) for(int (i) = (a); (i) <= (b); (i)++)
#define rFOR(i, a, b) for(int (i) = (b); (i) >= (a); i--)
#define REP(i, n) FOR(i, 0, n)
#define rREP(i, n) rFOR(i, 0, (n-1))
#define vREP(i, vec) for(auto (i) = (vec).begin(); (i) != (vec).end(); (i)++)
#define vrREP(i, vec) for(auto (i) = (vec).end()-1;(i) != (vec).begin()-1;(i)--)

// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~



int main(void){
  int n, m; cin >> n >> m;
  vector<int> A(m);
  REP(i, n){
    int k; cin >> k;
    REP(j, k){
      int a; cin >> a;
       A.at(a - 1)++;
    }
  }
  int res = 0;
  vREP(ele, A) if(*ele == n) res++;
  cout << res << "\n";
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdlib>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>
#include <new>

using namespace std;

typedef long long ll;

#define rep(i, N) for (ll i = 0; i < (ll)(N); ++i)

int main(){
	ll N,ans=0;
	string S;
	cin >> S;
	N = S.size();

	for(ll i=0;i<N/2;i++){
		if(S[i]!=S[N-1-i]){
			ans += 1;
		}
	}

	cout << ans << endl;

	return 0;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i, n) for (ll i = 0; i < n; ++i)
#define P pair<ll, ll>
#define Graph vector<vector<ll>>
#define fi first
#define se second
constexpr ll mod = 1000000007;
constexpr ll INF = (1ll << 60);
constexpr double pi = 3.14159265358979323846;
template <typename T>
inline bool chmax(T &a, T b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <typename T>
inline bool chmin(T &a, T b) {
    if (a > b) {
        a = b;
        return 1;
    }
    return 0;
}

int main() {
    ll h, w, n;
    cin >> h >> w >> n;
    cout << (n + max(h, w) - 1) / max(h, w) << "\n";
    return 0;
}

Measured memory_bytes: 3624
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int INF =1e9+5;
void max_self(ll& a, ll b) {
    a = max(a, b);
}
int main()
{
    ll n,w;
    cin>>n>>w;
    vector<ll> dp(w+1);
    for(int i=0;i<n;i++)
    {
        ll wt,v;
        cin>>wt>>v;
        for(ll j=w-wt;j>=0;j--)
        {
            max_self(dp[j+wt],(dp[j]+v));
            //cout<<dp[j+wt]<<endl;
        }
    }
    //cout<<dp[w];
   ll maxx=0;
    for(ll i=0;i<=w;i++)
    {
        max_self(maxx,dp[i]);
    }
   cout<<maxx;
}


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

#define PI 3.1415926535897932384626433832795
#define pii pair <int, int>
#define pb push_back
#define ll long long
#define ss second
#define ff first
#define N 100010

using namespace std;

int a, b, c;

int main()
{
	cin >> a >> b >> c;
	
	if(a + b > c && a <= c)
		cout << "YES";
	else
		cout << "NO";
}

Measured memory_bytes: 256
import itertools

N,A,B,C = (int(x) for x in input().split())
l_arr = []
for _ in range(N):
    l_arr.append(int(input()))

ans = 100000000
for ns in itertools.product([0,1,2,3], repeat=N):
    t_arr = [0,0,0,0]
    cost = -30
    for n,l in zip(ns, l_arr):
        t_arr[n] += l
        if n < 3:
            cost += 10
    if t_arr[0] == 0 or t_arr[1] == 0 or t_arr[2] == 0:
        continue
    cost += abs(A-t_arr[0]) + abs(B-t_arr[1]) + abs(C-t_arr[2])
    ans = min(ans, cost)

print(ans)



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

#define debug(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
    cerr << "["<< *it << " = " << a << "]"<< endl;
    err(++it, args...);
}
using ll = long long;

int main() {
    ios::sync_with_stdio(false);
    ll A,B,K;
    cin >> A >> B >> K;
    if (K > A) {
        K-=A;
        if (K > B) {
            cout << "0 0";
        } else {
            cout << 0 << " " << B-K;
        }
    } else {
        cout << A-K <<" " << B;
    }

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using pint = pair<int, int>;
using ll = long long;
using pll = pair<ll, ll>;
#define FOR(i, begin, end) for (int i = (begin), i##_end_ = (end); i < i##_end_; i++)
#define IFOR(i, begin, end) for (int i = (end)-1, i##_begin_ = (begin); i >= i##_begin_; i--)
#define REP(i, n) FOR(i, 0, n)
#define IREP(i, n) IFOR(i, 0, n)
#define VREP(s, ite) for (auto ite = s.begin(); ite != s.end(); ++ite)
#define FI first
#define SE second
//#define endl "\n"
#define ciosup  \
    cin.tie(0); \
    ios::sync_with_stdio(false);
#define eb emplace_back
#define vint vector<int>
constexpr ll INF = 1e9 + 7;
constexpr ll MOD = 1e9 + 7;

int main()
{
    ciosup;
    int r;
    cin >> r;
    cout << 3 * r * r << endl;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void){
  long a, b, sum, count;
  
  while(cin >> a >> b) {
    
    count = 0;
    sum = a + b;
    while(sum != 0) {
      sum /= 10;
      count++;
    }
    cout << count << endl;
  }
}

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

vector<set<pair<int,int>>> X(100000);
vector<int> Bl(100000,5);

void dfs(int x,int y){
  auto it=X[x].begin();
  while(it!=X[x].end()){
    int a=(*it).first;
    int c=(*it).second;
    it++;
    if(a==y) continue;
    Bl[a]=(Bl[x]+c)%2;
    dfs(a,x);
  }
  return;
}

int main(){
  int N;
  cin>>N;
  int a,b,c;
  for(int i=0;i<N-1;i++){
    cin>>a>>b>>c; c%=2;
    a--; b--;
    X[a].insert({b,c});
    X[b].insert({a,c});
  }
  Bl[0]=0;
  dfs(0,512411);
  for(int i=0;i<N;i++){
    cout<<Bl[i]<<endl;
  }
}

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

#define REP(i, n) for(int i=0;i<(int)(n);i++)
#define ALL(x) (x).begin(),(x).end()
const int INF = 1e9;

using namespace std;

struct node{
    int id, left, right;
    int parent, sibling, degree, depth, height;
};

node n[25];

void pre_search(node v){
    cout << " " << v.id;
    if(v.left != -1)
        pre_search(n[v.left]);
    if(v.right != -1)
        pre_search(n[v.right]);
    return;
}

void in_search(node v){
    if(v.left != -1)
        in_search(n[v.left]);
    cout << " " << v.id;
    if(v.right != -1)
        in_search(n[v.right]);
    return;
}

void pos_search(node v){
    if(v.left != -1)
        pos_search(n[v.left]);
    if(v.right != -1)
        pos_search(n[v.right]);
    cout << " " << v.id;
    return;
}

int main() {
    int v;
    cin >> v;
    REP(i, v){
        n[i].id = i;
        n[i].parent = -1;
        n[i].depth = 0;
        n[i].sibling = -1;
        n[i].degree = 0;
        n[i].height = 0;
    }
    REP(i, v){
        int x, left, right;
        cin >> x >> left >> right;
        n[x].left = left;
        n[x].right = right;
        if(n[x].left != -1){
            n[n[x].left].parent = x;
            n[n[x].left].sibling = right;
            n[x].degree++;
        }
        if(n[x].right != -1){
            n[n[x].right].parent = x;
            n[n[x].right].sibling = left;
            n[x].degree++;
        }
    }

    REP(i, v){
        node x = n[i];
        int count = 0;
        while(x.parent != -1){
            count++;
            n[x.parent].height = max(count, n[x.parent].height);
            x = n[x.parent];
        }
        n[i].depth = count;
    }

    node root;
    REP(i, v){
        if(n[i].depth == 0)
            root = n[i];
    }

    cout << "Preorder" << endl;
    pre_search(root);
    cout << endl << "Inorder" << endl;
    in_search(root);
    cout << endl << "Postorder" << endl;
    pos_search(root);
    cout << endl;

    return 0;
}

Measured memory_bytes: 1164
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<string>
#include<cmath>
#include<vector>
#include<iostream>
typedef long long LL;
using namespace std;
#define MAXN 1000000
#define N 105
int vis[N];
vector<int>d;
LL C(int n,int m){
	LL tmp = 1;
	for(int i = 2;i <= m;i++)
		vis[i] = 0;
	for(LL i = n;i > n-m;i--){
		tmp *= i;
		for(int j = 2;j <= m;j++)
			if(!vis[j] && tmp % j == 0){
				tmp /= j;
				vis[j] = 1;
			}
	}
	return tmp;
}
int main()
{
	int l,k;
	LL ans = 0;
	scanf("%d%d",&l,&k);
	for(int a = 1;a <= (l+1)/2;a++){
		for(int c = 0;2*a + (k-1)*c <= l + 1 && c <= a;c++)
			ans += C(a,c);
	}
	printf("%lld\n",ans);
}


Measured memory_bytes: 3216
#include<iostream>

using namespace std;

int cnt1[21];
int cnt2[21];

int main() {
    while (1) {
        int w, d;
        cin >> w >> d;
        if (w == 0 && d == 0) break;

        for (int i = 0; i < 21; ++i) {
            cnt1[i] = 0; cnt2[i] = 0;
        }

        
        for (int i = 0; i < w; ++i) {
            int hi;
            cin >> hi;
            cnt1[hi]++;
        }

        for (int i = 0; i < d; ++i) {
            int hi;
            cin >> hi;
            cnt2[hi]++;
        }

        int ans = 0;
        for (int i = 1; i < 21; ++i) {
            ans += max(cnt1[i], cnt2[i]) * i;
        }
        cout << ans << endl;
    }
}

Measured memory_bytes: 3088
#include<iostream>
#include<string>
#include<cmath>
#include<array>
#include<algorithm>
//#include<deque>
#include<vector>
//#include<utility>
#include<set>
//#include<map>
//#include<list>

using namespace std;
using LLI = long long int;

//class UnionFind {
//public:
//	vector<int>data;
//	UnionFind(int size) :data(size, -1) {};
//	bool unionset(int x, int y) {
//		x = root(x), y = root(y);
//		if (x != y) {
//			if (data[y] < data[x]) {
//				swap(x, y);
//			}
//			data[x] += data[y];
//			data[y] = x;
//		}
//		return x != y;
//	}
//	bool findset(int x, int y) {
//		return root(x) == root(y);
//	}
//	int root(int x) {
//		return data[x] < 0 ? x : data[x] = root(data[x]);
//	}
//	int size(int x) {
//		return -data[root(x)];
//	}
//};

//int gcd(int x, int y) {
//	int tmp, r;
//	if (x < y) {
//		tmp = x;
//		x = y;
//		y = tmp;
//	}
//	r = x % y;
//	while (r != 0) {
//		x = y;
//		y = r;
//		r = x % y;
//	}
//	return y;
//}

//vector<vector<int>>sub;
//int dfs(int id) {
//	if (sub[id].size() == 0) {
//		return 1;
//	}
//	int minP = (int)1e9;
//	int maxP = 0;
//	for (int i : sub[id]) {
//		int P = dfs(i);
//		minP = min(minP, P);
//		maxP = max(maxP, P);
//	}
//	return minP + maxP + 1;
//}

const int n_max = 8;
array<array<bool, n_max>, n_max>graph;
int dfs(int v,int N,array<bool,n_max>visited) {
	int ret = 0;
	bool all_visited = true;
	for (int i = 0; i < N;i++) {
		if (visited[i] == false) {
			all_visited = false;
		}
	}
	if (all_visited) {
		return 1;
	}
	for (int i = 0; i < N;i++) {
		if (graph[v][i] == false) {
			continue;
		}
		if (visited[i] == true) {
			continue;
		}
		visited[i] = true;
		ret += dfs(i,N,visited);
		visited[i] = false;
	}
	return ret;
}

int main(void) {
	int N, M;
	cin >> N >> M;


	for (int i = 0; i < M;i++) {
		int a, b;
		cin >> a >> b;
		graph[a - 1][b - 1] = true;
		graph[b - 1][a - 1] = true;
	}
	array<bool, n_max>visited;
	for (int i = 0; i < N;i++) {
		visited[i] = false;
	}
	visited[0] = true;
	cout << dfs(0,N,visited) << endl;

	return 0;
}

Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10**7)
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def II(): return int(sys.stdin.readline())
def SI(): return sys.stdin.readline().strip()
def LILI(n): return [LI() for _ in range(n)]
INF = 10 ** 18
MOD = 10 ** 9 + 7

def main_1(): 
    text = (['Sunny', 'Cloudy'], ['Cloudy', 'Rainy'],['Rainy','Sunny'])
    s = SI()
    for i in text:
        if s == i[0]:
            print(i[1])

def main_2(): 
    s = SI()
    for num, i in enumerate(s):
        if num % 2 == 1: # even
            if not (i in 'LUD'):
                print('No')
                return
        else:
            if not (i in 'RUD'):
                print('No')
                return
    print('Yes')

def main():
    N, K, Q = LI()
    A = [0] * (N+1)
    for _ in range(Q):
        n = II()
        A[n] += 1

    for i in range(N):
        if K - Q + A[i+1] <= 0:
            print('No')
        else:
            print('Yes')

main()

Measured memory_bytes: 4808
program main
    implicit none

    integer :: a,b
    character(10) :: s,t,u

    read( *, * )  s, t
    read(*,*) a,b
    read(*,*) u

    if (u.eq.s) then
       a=a-1
    elseif(u.eq.t) then
       b=b-1
    endif

    print *,a,b
end program main

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

using namespace std;

int main(){
  string str1, str2;
  cin >> str1 >> str2;

  sort(str1.begin(), str1.end());
  sort(str2.rbegin(), str2.rend());

  int loop = str1.length() > str2.length() ? str2.length() : str1.length();
  bool flag = false;

  for(int i = 0; loop > i; i++){
    char ch1 = str1[i];
    char ch2 = str2[i];

    if(ch1 == ch2){
      if(loop == i + 1 && str1.length() < str2.length()){
        flag = true;
        break;
      }else{
        continue;
      }
    }else{
      if(ch2 > ch1){
        flag = true;
        break;
      }else{
        break;
      }
    }
  }

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



Measured memory_bytes: 256
#include<iostream>

int main(void){
    int n, l;
    std::cin >> n >> l;
    int sum = n * (l - 1) + (n + 1) * n / 2;
    if(l > 0) std::cout << sum - l << std::endl;
    else if(l + n - 1 < 0) std::cout << sum - (l + n - 1) << std::endl;
    else std::cout << sum << std::endl;
    return 0;
}

Measured memory_bytes: 3580
#include<stdio.h>
#define MAX 100000

int A[MAX],n;

int partition(int p, int r){
  int x,i,j,t;

  x = A[r];
  i = p - 1;
  for(j = p; j < r; j++){
    if( A[j] <= x){
      i++;
      t = A[i]; A[i] = A[j]; A[j] = t;
    }}
  t = A[i +1]; A[i+1] = A[r]; A[r] =t;

  return i+1;
}

int main(){
  int i,q;

  scanf("%d",&n);
  for(i = 0; i < n; i++) scanf("%d", &A[i]);

  q = partition(0,n - 1);

  for( i = 0; i < n; i++){
    if(i) printf(" ");
    if(i == q) printf("[");
    printf("%d",A[i]);
    if(i == q) printf("]");
  }
  printf("\n");

  return 0;
}



Measured memory_bytes: 2132
import java.util.*;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Map;
import java.util.TreeMap;
import java.util.HashMap;

class Main{
    public static void main(String[] args){
        
        Scanner sc = new Scanner(System.in);
 
        int N = sc.nextInt();
        int M = sc.nextInt();
        int[] H = new int[N + 1];
        int[] A = new int[M];
        int[] B = new int[M];
        boolean[] ngm = new boolean[N + 1];

        for(int i=1; i<=N; i++){
            H[i] = sc.nextInt();
            ngm[i] = true;
        }

        for(int i=0; i<M; i++){
            A[i] = sc.nextInt();
            B[i] = sc.nextInt();
            if(H[A[i]]==H[B[i]]){
                ngm[A[i]] = false;
                ngm[B[i]] = false;
            }
            else if(H[A[i]]<H[B[i]]){
                ngm[A[i]] = false;
            }
            else{
                ngm[B[i]] = false;
            }
        }
        int ans = 0;
        for(int i=1; i<=N; i++){
            if(ngm[i]){
                ans += 1;
            }
        }
        System.out.println(ans);
    }
}

Measured memory_bytes: 61124
cards = {}
%w[S H C D].each do |s|
  cards[s] = Array.new 13
end
gets.to_i.times do
  s, i = gets.split
  i = i.to_i - 1
  cards[s][i] = true
end
%w[S H C D].each do |s|
  13.times do |i|
    puts "#{s} #{i+1}" unless cards[s][i]
  end
end

Measured memory_bytes: 8680
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define mod 1000000007
#define int long long
#define ll long long
#define EPS 0.00000000000001
#define ld long double
#define inf 20000000
#define N 100001


int32_t main()
{
    IOS;

    int n;
    cin >> n;
    int num = 0;
    for(int i = 1;i <= n;i++)
    {
        if(i & 1)
            num++;
    }
    cout << fixed << setprecision(8);
    cout << (double)(num) / (double)(n);

    return 0;
}
 
 

Measured memory_bytes: 256
/*
*/

#pragma GCC optimize("O3")
#define _CRT_SECURE_NO_WARNINGS
#include <fstream>
#include <iostream>
#include <string>
#include <complex>
#include <math.h>
#include <set>
#include <vector>
#include <map>
#include <queue>
#include <stdio.h>
#include <stack>
#include <algorithm>
#include <list>
#include <ctime>

#include <memory.h>
#include <assert.h>

#define y0 sdkfaslhagaklsldk

#define y1 aasdfasdfasdf
#define yn askfhwqriuperikldjk
#define j1 assdgsdgasghsf
#define tm sdfjahlfasfh
#define lr asgasgash
#define norm asdfasdgasdgsd
#define have adsgagshdshfhds
#define ends asdgahhfdsfshdshfd
#define prev asdgSHJsfgsdfhdsh
#define hash asdgasdgasdgdfrywewery

#define eps 1e-9
#define M_PI 3.141592653589793
#define bsize 300

#define ldouble long double
using namespace std;

#define bs 1000000007

const int N = 300031;

long long a,b,c,d;

long long gcd(long long a,long long b){
	while (a&&b)a>b?a%=b:b%=a;
	return a+b;
}

long long lcm(long long a,long long b){
	return a*b/gcd(a,b);
}

long long D(long long x){
	return x/c+x/d-x/lcm(c,d);
}

long long solver(long long x){
	return x-D(x);
}

int main(){
//    freopen("apache.in","r",stdin);
//    freopen("apache.out","w",stdout);
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    ios_base::sync_with_stdio(0);
 //   cin.tie(0);

    cin>>a>>b>>c>>d;
    cout<<solver(b)-solver(a-1)<<endl;

//    cin.get(); cin.get();
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
using namespace std;
ll n,K,cnt,a[200010],b[200010],t[500010],seg[500010],L[200010],R[200010],dp[200010],sum[200010];
void down(ll x){if(!seg[x]) return;seg[x<<1]=seg[x<<1|1]=seg[x];seg[x]=0;}
void upd(ll l,ll r,ll ql,ll qr,ll x,ll v)
{
	if(ql>qr) return;if(l>=ql&&r<=qr){seg[x]=v;return;}
	down(x);ll mid=(l+r)>>1;
	if(mid>=ql) upd(l,mid,ql,qr,x<<1,v);if(mid<qr) upd(mid+1,r,ql,qr,x<<1|1,v);
}
ll que(ll l,ll r,ll x,ll pos)
{
	if(l==r) return seg[x];
	down(x);ll mid=(l+r)>>1;
	if(mid>=pos) return que(l,mid,x<<1,pos);else return que(mid+1,r,x<<1|1,pos);
}
ll ask(ll pos){ll res=que(1,cnt,1,pos);if(!res) return 0;return (dp[res]+(t[L[res]]-t[pos]+K)%K);}
ll bin(ll v){ll l=1,r=cnt,mid,g=cnt;while(l<=r){mid=(l+r)>>1;if(t[mid]>=v) r=mid-1,g=mid;else l=mid+1;}return g;}
int main()
{
	scanf("%d%d",&n,&K);ll i;
	for(i=1;i<=n;i++) 
	{
		scanf("%d%d",&a[i],&b[i]),sum[i]=(sum[i-1]+a[i]);
		if(b[i]==2) continue;
		if(2*a[i]>K){puts("-1");return 0;}
	}
	for(i=n;i>=1;i--)
	{
		if(b[i]==1) L[i]=(-2ll*sum[i-1]%K+K)%K,R[i]=(-2ll*sum[i]%K+K)%K;
		else L[i]=0,R[i]=K-1;
		t[++cnt]=L[i],t[++cnt]=R[i];
	}
	sort(t+1,t+cnt+1);cnt=unique(t+1,t+cnt+1)-t-1;
	for(i=n;i>=1;i--)
	{
		L[i]=bin(L[i]),R[i]=bin(R[i]),dp[i]=ask(L[i]);
		if(L[i]>R[i]) upd(1,cnt,R[i]+1,L[i]-1,1,i);
		else upd(1,cnt,1,L[i]-1,1,i),upd(1,cnt,R[i]+1,cnt,1,i);
	}
	ll ans=dp[1];
	for(i=cnt;i>=1;i--) ans=min(ans,ask(i));
	printf("%lld\n",ans+sum[n]*2ll);
}

Measured memory_bytes: 15872
N = int(input())
dp = {}
max_num = 0
max_list =[]
for i in range(N):
    S = input()
    if S in dp:
        dp[S] += 1
    else:
        dp[S] = 1
    if dp[S] == max_num:
        max_list.append(S)
    elif dp[S] > max_num:
        max_list = [S]
        max_num = dp[S]
max_list.sort()
for s in max_list:
    print(s)

Measured memory_bytes: 97240
h, w = [int(x) for x in input().split()]
m = []
for i in range(h):
    m.append(input())
n = []
for i, row in enumerate(m):
    if '#' in row:
        n.append(row)
flgs = []
for j in range(w):
    js = ''.join([row[j] for row in m])
    flgs.append('#' in js)
n = [''.join([item for i, item in enumerate(s) if flgs[i]]) for s in n]
for item in n:
    print(item)

Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <queue>
#include <cmath>
#include <bitset>
#include <algorithm>
#include <set>
#include <string>
#include <queue>

using namespace std;

#define rep(i, N) for(int (i) = 0; (i) < (N); (i) ++)
typedef long long ll;


void solve(int start, int end){

}


int main(){
    int H, W, N;
    cin >> H >> W >> N;
    vector<vector<int>>  map(H, vector<int>(W));
    vector<int> as(N);
    int x = 0;
    int y = 0;
    rep(i, N) {
        int a;
        cin >> a;
        while(a){
            map[y][x] = i + 1;
            a --;
            if(y % 2){
                x --;
            }else{
                x ++;
            }
            if(x == W){
                x --;
                y ++;
            }else if(x == -1){
                x ++;
                y ++;
            }
        }
    }
    rep(i, map.size()){
        rep(j, map[0].size()){
            cout << map[i][j] << " ";
        }
        cout << endl;
    }


    return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <numeric>
#include <map>
#include <iomanip>
#include <limits.h>
#include <cmath>

using namespace std;    
typedef long long ll;
typedef pair<ll, ll> pll;
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
const bool DEBUG = true;

int main(){

    double r;
    cin >> r;
    cout << 2 * r * M_PI << endl;

    return 0;
}

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

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

using namespace std;

typedef long long ll;

int main () {
  ios::sync_with_stdio(false); cin.tie(0);
  int n;
  cin >> n;
  vector <int> arr(n);
  vector <int> l(n), r(n);
  for (int i = 0; i < n; i++) cin >> arr[i];
  l[0] = arr[0];
  for (int i = 1; i < n; i++) l[i] = __gcd(l[i - 1], arr[i]);
  r[n - 1] = arr[n - 1];
  for (int i = n - 2; i >= 0; i--) r[i] = __gcd(r[i + 1], arr[i]);
  int ans = max(l[n - 2], r[1]);
  for (int i = 1; i + 1 < n; i++) ans = max(ans, __gcd(l[i - 1], r[i + 1]));
  cout << ans << endl;
  return (0);
}


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

using namespace std;

const int N = 505;
const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, 1, 0, -1};

int n;
int P[N * N];
int dist[N][N];
bool occ[N][N];

inline bool isin(int x, int y) {
  return x >= 0 && y >= 0 && x < n && y < n;
}

void dfs(int x, int y) {
  for (int i = 0; i < 4; i++) {
    int tx = x + dx[i], ty = y + dy[i];
    if (isin(tx, ty) && dist[x][y] + occ[x][y] < dist[tx][ty]) {
      dist[tx][ty] = dist[x][y] + occ[x][y];
      dfs(tx, ty);
    }
  }
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> n;
  for (int i = 0; i < n * n; i++) {
    cin >> P[i];
    --P[i];
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      occ[i][j] = 1;
      dist[i][j] = min({i, j, n - i - 1, n - j - 1});
    }
  }
  int ans = 0;
  for (int i = 0; i < n * n; i++) {
    int x = P[i] / n, y = P[i] % n;
    ans += dist[x][y];
    occ[x][y] = 0;
    dfs(x, y);
  }
  cout << ans << '\n';
  return 0;
}


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

using namespace std;

#define optimize() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define file() freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
#define z cout<<"\n";
#define sp cout<<" ";

int main()
{
    optimize();
    long a,b,c;
    cin>>a>>b>>c;
    swap(a,b);
    swap(a,c);
    cout<<a;
    sp;
    cout<<b;
    sp;
    cout<<c;
    z;



    return 0;

}



Measured memory_bytes: 256
use std::io::prelude::*;

fn input<T>() -> T
where
    T: std::str::FromStr,
{
    let stdin = std::io::stdin();
    let token: String = stdin
        .lock()
        .bytes()
        .map(|c| c.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().unwrap()
}

fn main() {
    let s: Vec<char> = input::<String>().chars().collect();;

    let mut t = s.clone();
    t.sort();
    t.dedup();
    println!("{}", if s.len() == t.len() { "yes" } else { "no" });
}


Measured memory_bytes: 4352
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<queue>
#include<climits>
#include<cmath>
#include<sstream>
#include<iomanip>
#include <map>
#include <stack>
 
const int64_t cc = pow( 10, 9 );
//std::cout<< std::fixed << std::setprecision(10) << ( double )( max ) / 2;
bool sort_pair( std::pair< std::string, int64_t > origin, std::pair< std::string, int64_t > another )
{
    return origin.second  > another.second;
}
 
int main()
{
    std::string word = "aa";
    int64_t a,b,c,d,e;
    std::cin>> word;
    c = 0;
    d = 0;

    for( int i = word.size() - 1; i >= 0; i-- )
    {
        std::istringstream ss = std::istringstream( word.substr( i, 1 ) );
        int num;
        ss >> num;
        num += d;

        if( num <= 5 )
        {
            c += num;
            d = 0;
        }
        else
        {
            c += ( 10 - num );
            d = 1;
        }

        if( num == 5 )
        {
            if( i != 0 )
            {
                ss = std::istringstream( word.substr( i - 1, 1 ) );
                ss >> num;

                if( num < 5 )
                {
                    d = 0;
                }
                else
                {
                    d = 1;
                }
            }
        }
    }

    c += d;
    std::cout<< c <<"\n";
}


Measured memory_bytes: 1412
#include<bits/stdc++.h>
#define ll          long long
#define pb          push_back
#define c(P)        cout<<P<<"\n"
#define pii         pair<ll,ll>
#define mi          map<ll,ll>
#define mii         map<pii,ll>
#define F           first
#define S           second
#define mem(a,val)  memset(a,val,sizeof(a))
#define fr(i,x,n)   for(ll i=x;i<n;i++)
#define frr(i,x,n)  for(ll i=n-1;i>=x;i--)
using namespace std;


const ll N   =  500005;
const ll mod = 1e9 + 7;



void solve(){

  ll x=0,y=0,c=0,ans=0;
  ll n,m,k;
  string s;
  cin>>s;

  for (ll i = 0; i < s.size(); ++i)
  {
   if(s[i]=='A')x++;
   else y++;
  }
  if(x==0 or y==0){
  	c("No");
  }
  else c("Yes");
  
}

signed main(){
     
  ios_base::sync_with_stdio(false);   
  cin.tie(NULL);
  ll T=1;
  //cin>>T;
  while(T--){
  solve();
  }
  return 0;
}


Measured memory_bytes: 256
from bisect import bisect_right


def main():
    a, b, q = map(int, input().split())
    s = [int(input()) for _ in range(a)]
    t = [int(input()) for _ in range(b)]
    neighbour_temple = [[] for _ in range(a)]
    for i in range(a):
        idx = bisect_right(t, s[i])
        if idx == b:
            neighbour_temple[i].append(t[-1])
        else:
            if idx > 0:
                neighbour_temple[i].append(t[idx - 1])
            neighbour_temple[i].append(t[idx])
    for _ in range(q):
        begin = int(input())
        idx = bisect_right(s, begin)
        visit_s = []
        if idx == a:
            visit_s.append(a - 1)
        else:
            if idx > 0:
                visit_s.append(idx - 1)
            visit_s.append(idx)
        ans = float("inf")
        for v_s in visit_s:
            for v_t in neighbour_temple[v_s]:
                min_point = min(s[v_s], v_t)
                large_point = max(s[v_s], v_t)
                if min_point <= begin <= large_point:
                    ans = min(ans, large_point - min_point + min(begin - min_point, large_point - begin))
                elif begin <= min_point <= large_point:
                    ans = min(ans, abs(large_point - begin))
                else:
                    ans = min(ans, abs(min_point - begin))
        print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 99408
#include<bits/stdc++.h>
#define ll               long long
#define mod              1000000007
#define endl              "\n"
#define fast               ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define pb                push_back
#define all(v)             v.begin(),v.end()
#define inp(V,n)      for(int i=0;i<n;i++){cin >> V[i];}
#define oup(V,n)     {for(int i=0;i<n;i++){cout <<  V[i] << " "  ;} cout << endl;}
using namespace std;
ll factorial(ll n)
{
    return (n == 1 || n == 0) ? 1 : n * factorial(n - 1);
}
ll gcd(ll a, ll b)
{
    if (a == 0)
      return b;
    return gcd(b % a, a);
}
ll lcm(ll a, ll b)
{
   return (a*b)/gcd(a, b);
}
bool sortByVal(const pair<ll,ll> &a,
               const pair<ll,ll> &b)
{
    return (a.second > b.second);
}
ll Powb(ll b,ll n)
{
    if(n==0) return 1LL;
    if(n==1) return b;
    ll temp = Powb(b,n/2);
    if(n%2==0){return (temp*temp)%mod;}
    else{return (b*((temp*temp)%mod))%mod;}
}
ll sumofdigit(ll n)
{
    ll c=0,d=0,sum=0,i;
    while(n>0)
    {
        c=n%10;
        sum+=c;
        n/=10;
    }
    return sum;
}
int main()
{
     fast;
     int t=1;
     //cin>>t;
     while(t--)
     {
       double c=0,m=3.141592653589793238,i,j,d=0,sum=0,e=0,f=0,g=0,h=0,n,maxi=0;
       cin>>n;
       c=2*m*n;
       cout<<fixed<<setprecision(20)<<c;



     }

}



Measured memory_bytes: 3788
#include <iostream>
#include <cmath>

int main(int argc, char** argv)
{
    std::string a, b;
    std::cin >> a >> b;
    int c = std::atoi((a+b).c_str());
    std::string ans = "No";
    for (int ii = 0; ii < 1000; ++ii)
    {
        if (c == ii * ii)
        {
            ans = "Yes";
        }
    }

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

    return 0;
}

Measured memory_bytes: 256
<?php
  $n = (int)trim(fgets(STDIN));
  $s = trim(fgets(STDIN));
  $strs = str_split($s);
  $ans = '';

  foreach ($strs as $str) {
    $ch = $n;
    $asci = ord($str);
    if ($asci + $n > 90) {
      $ch = $asci + $n - 91;
      $asci = 65;

    }
    $ans = $ans . chr($asci + $ch);
  }
  echo $ans . PHP_EOL;

Measured memory_bytes: 4856
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {
    public static void main(String[] args) {
        FastReader sc = new FastReader();
        int N = sc.nextInt();
        int D = sc.nextInt();
        int[][] a = new int[N][D];
        for (int i=0; i<N; i++) {
            for (int j=0; j<D; j++) {
                a[i][j] = sc.nextInt();
            }
        }
        int count = 0;
        for (int i=0; i<N-1; i++) {
            for (int j=i+1; j<N; j++) {
                int temp_dist = 0;
                for (int ii=0; ii<D; ii++) {
                    temp_dist += Math.pow(Math.abs(a[i][ii]-a[j][ii]),2);
                }
                double dist = Math.sqrt(temp_dist);
                if (dist == (int)dist) {
                    count++;
                }
            }
        }
        System.out.println(count);
    }
    static class FastReader
    {
        BufferedReader br;
        StringTokenizer st;

        public FastReader()
        {
            br = new BufferedReader(new
                    InputStreamReader(System.in));
        }

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

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

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

        double nextDouble()
        {
            return Double.parseDouble(next());
        }

        String nextLine()
        {
            String str = "";
            try
            {
                str = br.readLine();
            }
            catch (IOException e)
            {
                e.printStackTrace();
            }
            return str;
        }
    }
}


Measured memory_bytes: 22356
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0; i<(n); i++)
#define all(v) (v).begin(),(v).end()
int main() {
  int n;
  cin >> n;
  ll ans = 0;
  vector<ll> a(n),b(n),c(n);
  vector<ll> dist(n),factor(n);
  rep(i,n) cin >> a[i];
  rep(i,n) cin >> b[i];
  rep(i,n) cin >> c[i];
  sort(all(a));
  sort(all(b));
  sort(all(c));
  rep(i,n){
    auto Iter = lower_bound(all(a),b[i]);
    dist[i] = Iter - a.begin();
  }
  rep(i,n){
    auto Iter = upper_bound(all(c),b[i]);
    factor[i] = c.end() - Iter;
  }
  rep(i,n){
    ans += dist[i]*factor[i];
  }
  cout << ans << endl;
}


Measured memory_bytes: 4224
#include <iostream>

int main()
{
  int N, M;
  int ans = 0;

  std::cin >> N >> M;

  for (int i = M; i >= 1; --i) {
    ans += i-1;
  }

  for (int i = N; i >= 1; --i) {
    ans += i-1;
  }

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


  return 0;
}


Measured memory_bytes: 256
#include <iostream>
        #include <vector>
        #include <string>
        using namespace std;
         
        int main(void)
        {
        	long long int n;
        	cin >> n;
        	for (long long int i = 1; i <= n; ++i) {
        		if (n * i % 2 == 0) {
        			cout << n * i << endl;
        			break;
        		}
        	}
        	if (n == 1) {
        		cout << 2 << endl;
        	}
        	return 0;
        }

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

using namespace std ;

#define maxn 1000005

vector <int> prm ;
int isPrime[maxn] ;

int main()
{
    for(int i=2 ; i<=1000000 ; i++) isPrime[i] = 1 ;

    for(int i=2 ; i<=1000000 ; i++)
    {
        if( isPrime[i] )
        {
            for(int j=i+i ; j<=1000000 ; j+=i) isPrime[j] = 0 ;
        }
    }

    for(int i=2 ; i<=1000000 ; i++)
    {
        if( isPrime[i] ) prm.push_back(i) ;
    }

    long long n , P ;
    scanf("%lld %lld",&n,&P) ;

    if(n==1)
    {
        printf("%lld\n",P) ;
        return 0 ;
    }

    long long ans = 1 ;

    for(int i=0 ; i<prm.size(); i++)
    {
        long long pwr = 0 ;
        while( P%prm[i] == 0 )
        {
            pwr++ ;
            P /= prm[i] ;
        }

        pwr /= n ;

        for(int j=1 ; j<=pwr ; j++ ) ans = ans*prm[i] ;

    }

    printf("%lld\n",ans) ;

    return 0 ;
}

//


Measured memory_bytes: 4732
x = int(input())
a = []
for b in range(1, 100):
    for p in range(2, 100):
        exp = b ** p
        if b == 1:
            a.append(1)
            break
        else:
            if b ** p <= x:
                a.append(b ** p)
            else:
                break
a = sorted(a)
print(a[-1])

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define IFOR(i,a,b) for(int i=(b-1);i>=(a);--i)
#define RPT(i,a,b) for(int i=(a);i<((a)+(b));++i)
#define IRPT(i,a,b) for(int i=((a)+(b)-1);i>=(a);--i)
#define BITBOOL(x,a) (((x)>>(a))&1)
ll Combination(ll n, ll a){
  ll ans = 1;
  if(a>n/2) a = n - a;
  RPT(i,0,a) ans = ans * (n-i) / (i+1);
  return ans;
}
int main(){
  std::cout << std::fixed << std::setprecision(20);
  int N;
  cin >> N;
  vector<pair<int,int>> xy(N);
  RPT(i,0,N)  cin >> xy[i].first >> xy[i].second;
  ld ans = 0;
  FOR(i,0,N){
    FOR(j,i+1,N){
      ans += sqrt( (xy[i].first-xy[j].first)*(xy[i].first-xy[j].first)+(xy[i].second-xy[j].second)*(xy[i].second-xy[j].second) );
    }
  }
  //ans /= Combination(N,2);
  //ans *= 2;
  ans /= N;
  ans *= 2;
  cout << ans << endl;
  return 0;
}

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

int main(){
   int l, r;
   cin >> l >> r;
   int lm = l / 2019;
   int rm = r / 2019;
   if(lm != rm) cout << 0 << endl;
   else{
             int min=(l%2019)*((l+1)%2019)%2019;
             for(int i=l%2019; i<=r%2019;i++){
                  for(int j =l%2019; j <= r%2019; j++){
                       if(i==j)continue;
                       else{
                            if(min > (i%2019)*(j%2019)%2019)min= (i%2019)*(j%2019)%2019;
                       }
                  }
             }
             cout << min << endl;
        }
   }


Measured memory_bytes: 888
#include <iostream>
#include <fstream>
#include <sstream>
#include <string>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <map>
#include <queue>
#include <ctime>
#include <cmath>

using namespace std;

#define forn(I,N) for (int I = 0; I < (N); ++I)
#define fornd(I,N) for (int I = (N) - 1; I >= 0; --I)
#define forab(I,A,B) for (int I = (A); I <= (B); ++I)
#define forabd(I,A,B) for (int I= (B); I >= (A); --I)
#define FOREACH(I,A) for (__typeof__(A)::iterator I=A.begin(); I<A.end(); I++)
#define all(V) (V).begin(), (V).end()
#define pb push_back
#define mp make_pair

typedef long long int ll;

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

const ll mod = 1000000007;

int main() {
  ll W, H, x, y;
  cin >> W >> H >> x >> y;

  cout << fixed << setprecision(5);

  cout << (W * H) / 2.0 << " ";
  if (x * 2 == W && y * 2 == H) {
    cout << 1 << endl;
  } else {
    cout << 0 << endl;
  }

  return 0;
}


Measured memory_bytes: 256
n,m=map(int,input().split())
py=[[0]*3 for i in range(m)]
for i in range(m):
    py[i]=list(map(int,input().split()))+[i]

py.sort()

strr=[""]*m
pyi=0
for i in range(m):
    if py[i][0]==pyi:
        strp=str(py[i][0])
        strq="0"*(6-len(strp))+strp        
        qi+=1
        strp=str(qi)
        strq=strq+"0"*(6-len(strp))+strp
    else:
        strp=str(py[i][0])
        pyi=py[i][0]
        strq="0"*(6-len(strp))+strp        
        qi=1
        strp=str(qi)
        strq=strq+"0"*(6-len(strp))+strp
    strr[py[i][2]]=strq

for i in range(m):
    print(strr[i])
    

Measured memory_bytes: 31356
void
p(int arr[], int n)
{
  int i;
  printf("%d", arr[0]);
  for (i=1; i<n; i++) {
    printf(" %d", arr[i]);
  }
  printf("\n");
}

int
main()
{
  int n, i;
  int arr[100];

  scanf("%d", &n);
  for (i=0; i<n; i++) {
    scanf("%d", &arr[i]);
  }

  for (i=0; i<n; i++) {
    int key = arr[i];
    int j = i - 1;
    while ((j >= 0) && (arr[j] > key)) {
      arr[j+1] = arr[j];
      j--;
    }
    arr[j+1] = key;
    p(arr, n);
  }
}



Measured memory_bytes: 2044
#include <iostream>
using i64 = long long;

int main() {
    std::string s;
    std::cin >> s;
    int ret = 0;
    for (const char c : s) ret += c - '0';
    std::cout << (ret % 9 ? "No" : "Yes") << std::endl;

    return 0;
}


Measured memory_bytes: 3700