akhauriyash/Code-Regression huggingface dataset:
class dsu():
    n=1
    parent_or_size=[-1 for i in range(n)]
    def __init__(self,N):
        self.n=N
        self.parent_or_size=[-1 for i in range(N)]
    def merge(self,a,b):
        assert 0<=a<self.n, "0<=a<n,a={0},n={1}".format(a,self.n)
        assert 0<=b<self.n, "0<=b<n,b={0},n={1}".format(b,self.n)
        x=self.leader(a)
        y=self.leader(b)
        if x==y:
            return x
        if (-self.parent_or_size[x]<-self.parent_or_size[y]):
            x,y=y,x
        self.parent_or_size[x]+=self.parent_or_size[y]
        self.parent_or_size[y]=x
        return x
    def same(self,a,b):
        assert 0<=a<self.n, "0<=a<n,a={0},n={1}".format(a,self.n)
        assert 0<=b<self.n, "0<=b<n,b={0},n={1}".format(b,self.n)
        return self.leader(a)==self.leader(b)
    def leader(self,a):
        assert 0<=a<self.n, "0<=a<n,a={0},n={1}".format(a,self.n)
        if (self.parent_or_size[a]<0):
            return a
        self.parent_or_size[a]=self.leader(self.parent_or_size[a])
        return self.parent_or_size[a]
    def size(self,a):
        assert 0<=a<self.n, "0<=a<n,a={0},n={1}".format(a,self.n)
        return -self.parent_or_size[self.leader(a)]
    def groups(self):
        leader_buf=[0 for i in range(self.n)]
        group_size=[0 for i in range(self.n)]
        for i in range(self.n):
            leader_buf[i]=self.leader(i)
            group_size[leader_buf[i]]+=1
        result=[[] for i in range(self.n)]
        for i in range(self.n):
            result[leader_buf[i]].append(i)
        result2=[]
        for i in range(self.n):
            if len(result[i])>0:
                result2.append(result[i])
        return result2

N,Q=map(int,input().split())
G=dsu(N)
for i in range(Q):
    t,u,v=map(int,input().split())
    if t==0:
        G.merge(u,v)
    else:
        if G.same(u,v):
            print(1)
        else:
            print(0)


Measured memory_bytes: 85816
n = int(input())
As = list(map(int, input().split()))

# ps = [0] * (n+1)
# qs = [0] * (n+1)
# ps[-1] = As[-1]
# qs[-1] = As[-1]

p = As[-1]
q = As[-1]
Asr = As[::-1]
qs = [q]
# 深い方から見ていく
for j,a in enumerate(Asr[1:]):
    i = n - (j + 1) 
    p = (p+1)//2 + a 
    q = min(q + a, 2**i)

    # 最小値が、2**iを超えると、深さ0畳めないのでアウト
    if p > 2**i:
        print(-1)
        exit()
    
    # 2**iを超えない範囲での最大値
    qs.append(q)    
    
if p != 1:
    print(-1)
    exit()
qs.reverse()

qs[0] = 1
ans = 1
for i in range(1,n+1):
    if qs[i] > 2**i:
        qs[i] = 2 ** i
    if qs[i] > 2*(qs[i-1]-As[i-1]):
        qs[i] = 2 * (qs[i-1]-As[i-1])
    ans += qs[i]
print(ans)

Measured memory_bytes: 84508
#include<bits/stdc++.h>
using namespace std;
#define pb          push_back
#define m_p			make_pair
#define rep(i,a,b)	for(int i=a;i<b;i++)
#define repr(i,a,b) for(int i =a, i>=b;i--)
#define sz(x)       (int)x.size()
#define F			first
#define S			second
#define debug(x)	for(int i=0;i<x;i++) cout<<"##########"<<endl
#define M			1000000007
#define ll			long long int
#define lMax		LLONG_MAX
#define pii 		pair<int ,int >
#define	all(a)		a.begin(), a.end()
#define vi 			vector<int> 
#define vii 		vector<pii>

// queue<int> , prefix_sum(a,a+n) , reverse(a,a+n) , priority_queue <int> max heap , priority_queue <int, vector<int>, greater<int> > min heap;
// == > != precedence gretaer then & , << precedence greater than <= == => , 
//int chk, cnt, fl, pos, in, src, tar, val, res. dummy;  fill (myvector.begin(),myvector.begin()+4,5), freq;

void solve()
{
	ll n,W;
	cin>>n>>W;
	
	ll dp[n+1][W+1];
	memset(dp,0,sizeof(dp));
	
	
	ll v[n+1],w[n+1];
	rep(i,1,n+1) cin>>w[i]>>v[i];
	
	rep(i,1,n+1)
	{
		rep(j,1,W+1)
		{
			if(j<w[i]) dp[i][j]=dp[i-1][j];
			else dp[i][j]=max(dp[i-1][j],dp[i-1][j-w[i]]+v[i]);
		}
	}
	
//	rep(i,1,n+1)
//	{
//		rep(j,1,W+1)
//		{
//			cout<<dp[i][j]<<" ";
//		}
//		cout<<endl;
//	}
	cout<<dp[n][W]<<endl;
}


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

Measured memory_bytes: 79232
#include <bits/stdc++.h>
using namespace std;
template<class T> ostream& operator<<(ostream &os, vector<T> V) {
os << "[ "; for(auto v : V) os << v << " "; return os << "]";}
template<class L, class R> ostream& operator<<(ostream &os, pair<L,R> P) {
    return os << "(" << P.first << "," << P.second << ")";}

// #define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    cout << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma = strchr(names + 1, ',');cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...) 1
#endif
typedef long long ll;
typedef double ld;
#define pll pair<ll,ll>
#define pb push_back
#define mp(x, y) make_pair((x), (y))
#define F first
#define S second
#define I insert
#define vll vector<ll>
#define vpll vector<pll>
#define all(x) (x).begin(), (x).end()
#define sz(x) (ll)(x).size()
   
const ll Mod = 1e9 + 7;
int main(){
   ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); 
   int n ; cin >> n;
   int A[n] , B[n];
   for(int i = 0 ;i < n ; i++)
        cin >> A[i];
    for(int i = 0 ;i < n ; i++)
        cin >> B[i];
    int ans = 0;
    for(int i = 0 ;i < n ; i++){
        ans += max(0 , A[i]-B[i]);
    }
    cout << ans << endl;
   return 0;
}

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

int main(){
    int n;
    cin >> n;
    cout << n*n*n << endl;
    return 0;
}

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

int main(void){
    int a,b;
    cin >> a >> b;
    char s[256];
    for(int i=0;i<a+b+1;i++) cin >> s[i];
    
    for(int i=0;i<a;i++){
        if(!('0'<=s[i]&&s[i]<='9')){
            cout << "No" << endl;
            return 0;
        }
    }
    
    if(s[a]!='-'){
        cout << "No" << endl;
        return 0;
    }
    
    for(int i=a+1;i<=a+b;i++){
        if(!('0'<=s[i]&&s[i]<='9')){
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
}


Measured memory_bytes: 256
import java.io.*;
import java.util.StringTokenizer;

class Main {
	private static final int a[] = {0,0,0,0,0,0,0,0,0,0};
	private static final int data[][] = new int[11][331];

	public static void main(String args[]) {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String buf;
		solve(0,1);

		try {
			while ((buf = br.readLine())!=null) {
				StringTokenizer st = new StringTokenizer(buf);
				int n = Integer.parseInt(st.nextToken());
				int s = Integer.parseInt(st.nextToken());
				if (n<=10&&s<=330) System.out.println(data[n][s]);
				else System.out.println(0);
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	public static int solve(int s,int d) {
		if (d==11) return 0;
		else {
			for (int i=0;i<=9;i++) {
				if (a[i]==0) {
					data[d][s+i*d]++;
					a[i] = 1;
					solve(s+i*d,d+1);
					a[i] = 0;
				}
			}
			return s;
		} 
	}
}

Measured memory_bytes: 18900
use std::io::{stdin, Read, StdinLock};
use std::str::FromStr;
use std::iter::FromIterator;

#[allow(unused_macros)]
macro_rules! chmax {
    ($x:expr, $y:expr) => {
        if $x < $y {
            $x = $y;
            true
        } else {
            false
        }
    };
}


#[allow(unused_macros)]
macro_rules! chmin {
    ($x:expr, $y:expr) => {
        if $x > $y {
            $x = $y;
            true
        } else {
            false
        }
    };
}

fn main() {
    let cin = stdin();
    let mut scan = Scanner::new(cin.lock());
    let n = scan.read::<usize>();
    let m = scan.read::<usize>();
    let mut a = vec![];
    let mut c = vec![];
    for _ in 0..m {
        a.push(scan.read::<i64>());
        let b = scan.read::<usize>();
        let cans = scan.readn::<i64>(b);
        let mut d = 0;
        for i in cans {
            d += 1 << (i - 1);
        }
        c.push(d);
    }
    let mut dp = vec![1i64 << 60; 1 << n];
    dp[0] = 0;
    for mask in 0..1 << n {
        for i in 0..m {
            chmin!(dp[mask | c[i] as usize], dp[mask] + a[i]);
        }
    }
    println!("{}", if dp[(1<<n)-1] == 1i64<<60 {-1} else {dp[(1<<n)-1]});
}

// region template
#[allow(dead_code)]
fn iu(i: i64) -> usize { i as usize }

#[allow(dead_code)]
fn ui(i: usize) -> i64 { i as i64 }

#[allow(dead_code, deprecated)]
fn join<T: std::fmt::Display>(slice: &[T], sep: &str) -> String {
    let strings = slice.iter().map(|t| format!("{}", t)).collect::<Vec<_>>();
    strings.connect(sep)
}

#[allow(dead_code)]
fn arr<'a, S, T>(n: usize, mut f: S) -> Vec<T> where S: FnMut(usize) -> T + 'a {
    (0..n).map(|i| f(i)).collect::<Vec<T>>()
}

struct Scanner<'a> {
    cin: StdinLock<'a>,
}

#[allow(dead_code)]
impl<'a> Scanner<'a> {
    fn new(cin: StdinLock<'a>) -> Scanner<'a> {
        Scanner { cin: cin }
    }

    fn read1<T: FromStr>(&mut self) -> Option<T> {
        let token = self.cin.by_ref().bytes().map(|c| c.unwrap() as char)
            .skip_while(|c| c.is_whitespace())
            .take_while(|c| !c.is_whitespace())
            .collect::<String>();
        token.parse::<T>().ok()
    }

    fn read<T: FromStr>(&mut self) -> T {
        self.read1().unwrap()
    }

    fn readn<T: FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read::<T>()).collect()
    }

    fn chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
}
// endregion

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

using namespace std;
typedef long long ll;
#define all(x) (x).bg,(x).ed
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep1(i,n) for(ll i=1;i<=n;i++)

int main(){
	ll N; cin>>N;
	ll sum=0,K=0,cnt=0;
	vector<ll> A(N);
	vector<ll> B(N);
	rep(i,N) cin>>A[i];
	rep(i,N) cin>>B[i];
	rep(i,N){
		if(A[i]>B[i]) sum+=A[i]-B[i];
		if(A[i]<B[i] && (B[i]-A[i])%2==1) cnt++;
		K+=(B[i]-A[i]);
	}
	//cout<<"K:"<<K<<" sum:"<<sum<<" cnt:"<<cnt<<endl;
	if(K<0 || sum>K) cout<<"No";
	else{
		if(cnt<=K-sum) cout<<"Yes";
		else cout<<"No";
	}
}

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

int main() {
  long long int n, m, sum = 0;
  cin >> n;
  m = n;
  while (n>0) {
    sum+=n%10;
    n/=10;
  }
  if (m%sum==0) cout << "Yes";
  else cout << "No";
  return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#define SORT(a) sort(a.begin(), a.end())
#define RSORT(a) sort(a.rbegin(), a.rend())
#define REP(i, n) for (int i = 0; i < n; i++)
#define RREP(i, n) for (int i = n; 0 <= i; i--)
#define FOR(i, start, end) for (int i = start; i < end; i++)
#define RFOR(i, start, end) for (int i = start; end <= i; i--)
#define ALL(a) a.begin(), a.end()
#define MOD(a) a %= 1'000'000'007
#define INF32 1'050'000'000
#define INF64 4'000'000'000'000'000'000
using ll = long long;
using namespace std;
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;
}

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

    int L, N;
    cin >> N >> L;
    vector<string> S(N);
    for (auto &&i : S) {
        cin >> i;
    }
    SORT(S);
    for (auto &&i : S) {
        std::cout << i;
    }
    std::cout << '\n';

    return 0;
}

Measured memory_bytes: 256
package main

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

func main() {
	var N, K int
	fmt.Scan(&N)
	fmt.Scan(&K)
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	var A []int
	for i := 0; i < N; i++ {
		sc.Scan()
		a, _ := strconv.Atoi(sc.Text())
		A = append(A, a)
	}

	numOfRightSmaller := make([]int64, N)
	numOfSmaller := make([]int64, N)
	for i := 0; i < N-1; i++ {
		for j := i + 1; j < N; j++ {
			if A[i] > A[j] {
				numOfRightSmaller[i]++
			}
		}
	}
	for i := 0; i < N; i++ {
		for j := 0; j < N; j++ {
			if A[i] > A[j] {
				numOfSmaller[i]++
			}
		}
	}

	var ans int64
	for i := 0; i < N; i++ {
		k := int64(K)
		tmp := (k * (k - 1) / 2) % (1E9 + 7)
		ans += numOfSmaller[i]*tmp + numOfRightSmaller[i]*k
		ans %= 1E9 + 7
	}
	fmt.Println(ans)
}


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

int N, A[3][3], b[10];
bool appear[3][3];

int main()
{
   for (int i=0; i<3; i++)
   {
      for (int j=0; j<3; j++) 
	     cin>>A[i][j];
   }
   cin>>N;
   for (int i=0; i<N; i++) 
      cin>>b[i];
   for (int i=0; i<N; i++)
   { 
      for (int j=0; j<N; j++)
	  {
	     appear[i][j]=false;
		 for (int k=0; k<N; k++)
		 {
		    if (A[i][j]==b[k])
			  appear[i][j]=true;
		 }
	  }
   }
   string ANS="No";
   for(int i=0; i<3; i++)
   {
      if(appear[i][0] && appear[i][1] && appear[i][2])
	     ANS="Yes";
   }
   for(int i=0; i<3; i++)
   {
      if(appear[0][i] && appear[1][i] && appear[2][i]) 
	     ANS="Yes";
   }
   if(appear[0][0] && appear[1][1] && appear[2][2]) 
      ANS="Yes";
   if(appear[0][2] && appear[1][1] && appear[2][0]) 
      ANS="Yes";
   cout<<ANS<<endl;
   return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
// #define int long long
#define rep(i,a,b) for(int i=(a);i<=(b);++i)
#define per(i,a,b) for(int i=(a);i>=(b);--i)
#define ll long long
#define debug(...) fprintf(stderr, __VA_ARGS__)
using namespace std;

struct _in {
	const _in operator,(int&a)const {
		a = 0; char k = getchar(); int f = 1;
		for(;!isdigit(k); k = getchar()) if (k == '-') f = -1;
		for(; isdigit(k); k = getchar()) a = a * 10 + k - '0';
		a *= f; return*this;
	}
}in;

const int N = 17, mod = 1e9 + 7;
int fpow (int base, int v) {
	int tot = 1;
	while (v) {
		if (v & 1)  tot = 1LL * tot * base % mod;
		base = 1LL * base * base % mod;
		v >>= 1;
	}
	return tot;
}
int dp[1 << N][N + 1], n, m, a[N], SZ[1 << N], fac[1 << N], ifac[1 << N];
int C (int n, int m) { return 1LL * fac[n] * ifac[n - m] % mod * ifac[m] % mod; }
int main ()
{
	in, n, m;
	fac[0] = 1; rep (i, 1, 1 << n) fac[i] = 1LL * fac[i - 1] * i % mod;
	ifac[1 << n] = fpow (fac[1 << n], mod - 2); per (i, (1 << n) - 1, 0) ifac[i] = 1LL * ifac[i + 1] * (i + 1) % mod;
	rep (i, 1, (1 << n) - 1) SZ[i] = SZ[i >> 1] + (i & 1);
	rep (i, 1, m) in, a[i]; sort (a + 1, a + m + 1); reverse (a + 1, a + m + 1);
	dp[0][0] = 1;
	rep (i, 1, m) {
		int v = a[i];
		rep (S, 0, (1 << n) - 1) dp[S][i] = (dp[S][i] + dp[S][i - 1]) % mod;
		rep (S, 0, (1 << n) - 1) rep (k, 0, n - 1) if (!(S & (1 << k))) {
			if ((1 << n) - v - S + 1 >= (1 << k)) dp[S | (1 << k)][i] = (dp[S | (1 << k)][i] + 1LL * dp[S][i - 1] * fac[1 << k] % mod * C((1 << n) - v - S, (1 << k) - 1)) % mod;
			else break;
		}
		// rep (i, 0, m) rep (S, 0, (1 << n) - 1) debug ("%d%c", dp[S][i], " \n"[S == (1 << n) - 1]);
	}
	rep (i, 0, (1 << n) - 1) dp[i][m] = 1LL * dp[i][m] * fac[(1 << n) - 1 - i] % mod;
	int ans = 0;
	rep (S, 0, (1 << n) - 1) ans = (ans + (SZ[S] % 2 ? mod - dp[S][m] : dp[S][m])) % mod;
	// cout << ans << endl;
	printf ("%lld\n", 1LL * ans * (1 << n) % mod);
	return 0;
}

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

#define irep(i,n) for(int i = 0; i < (int)(n); i++)
#define irep2(i,a,n) for(int i = (int)(a); i <= (int)(n); i++)
#define irrep(i,n) for(int i = (int)(n-1); i > -1; i--)
#define irrep2(i,n,a) for(int i = (int)(n); i >= (int)(a); i--)
#define fi first
#define se second

using ll = long long;
using v_int = std::vector<int>;
using v2_int = std::vector<v_int>;
using v_ll = std::vector<ll>;
using v2_ll = std::vector<v_ll>;
using v_string = std::vector<std::string>;
using v_bool = std::vector<bool>;
using v2_bool = std::vector<v_bool>;
using pii = std::pair<int, int>;
using pll = std::pair<ll, ll>;
using mii = std::map<int, int>;
using mll = std::map<ll, ll>;

const double PI = 3.1415926535897932;
const int INF = 2*(int)1e9;
const ll LINF = (ll)1e18;
const ll MOD = 1000000007;
//const int dc[4] = {1, -1, 0,  0};
//const int dr[4] = {0,  0, 1, -1};
const int dc[8] = {1, -1, 0,  0, 1, -1,  1, -1};
const int dr[8] = {0,  0, 1, -1, 1,  1, -1, -1};

using namespace std; 

template<typename T, typename U> inline
ostream& operator<<(ostream &o, pair<T,U> &p)
{
    return o << "{" << p.first << "," << p.second << "}";
}

template<typename T, typename U, typename V> inline
ostream& operator<<(ostream &o, tuple<T,U,V> &p)
{
    return o << "{" << get<0>(p) << "," << get<1>(p) << "," << get<2>(p) << "}";
}

template<typename T> inline
istream& operator>>(istream &is, vector<T> &v)
{
    int len = (int)v.size();
    for(int i = 0; i < len; i++) {
        is >> v[i]; 
    }
    return is;
}

template<typename T> inline
ostream& operator<<(ostream &os, vector<T> &v)
{
    int len = (int)v.size();
    for(int i = 0; i < len; i++) { 
        os << v[i];
        if(i != len-1) { os << ","; } 
    } 
    return os;
}

template<typename T> inline
void chmin(T &a, T b) { a = min(a, b); }

template<typename T> inline
void chmax(T &a, T b) { a = max(a, b); }

int main(void)
{
    int h, w;
    cin >> h >> w;

    v2_int sum1(h, v_int(w));
    v2_int sum2(h, v_int(w));
    irep(i, h) {
        irep(j, w) {
            char lamp;
            cin >> lamp;
            if(lamp == '.') {
                sum1[i][j] = 1;
                sum2[i][j] = 1;
            }
        }
    }
    
    irep(i, h) {
        int j =0 ;
        while(j<w) {
            int start = j;
            int cnt = 0;
            while(j<w && sum1[i][j] == 1) {
                cnt++;
                j++;
            }
            
            irep(idx, cnt) {
                sum1[i][start+idx] = cnt;
            }
            if(!cnt) { j++; }
        }
    }

    irep(j, w) {
        int i = 0; 
        while(i<h) {
            int start = i;
            int cnt = 0;
            while(i<h && sum2[i][j] == 1) {
                cnt++;
                i++;
            }
            irep(idx, cnt) {
                sum2[start+idx][j] = cnt;
            }
            if(!cnt) { i++; }
        }
    }
    int ans = 0;

    irep(i, h) {
        irep(j, w) {
            chmax(ans, sum1[i][j] + sum2[i][j]-1);
        }
    }
    cout << ans << endl;

    return 0;
}

/*atcoder*/


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

int main() {
  int n;
  cin >> n;
  
  map<string, int> memo;
  
  rep(i, n) {
    string in;
    cin >> in;
    ++memo[in];
  }
  
  int maxi = 0;
  for(auto x : memo) {
    maxi = max(maxi, x.second);
  }
  
  for(auto x : memo) {
    if(x.second == maxi) cout << x.first << endl;
  }
    
  return 0;
}


Measured memory_bytes: 25216
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace AtCoder
{
	class Program
	{
		static void Main(string[] args)
		{
			var Instance = new Question();
			Instance.Exec();
		}
	}

	public class Question
	{
		public void Exec()
		{
			long n = long.Parse(Console.ReadLine());
			int taro = 0;
			int hanako = 0;
			for (int i = 0; i < n; ++i) {
				var array = Console.ReadLine().Split(' ');
				int comparison = string.Compare(
					array[0], array[1], comparisonType: StringComparison.OrdinalIgnoreCase);
				if (comparison < 0) {
					hanako += 3;
				} else if (comparison > 0) {
					taro += 3;
				} else {
					++taro;
					++hanako;
				}
			}

			Console.WriteLine($"{taro} {hanako}");

			Console.ReadKey();
		}
	}
}


Measured memory_bytes: 17932
/* B */

#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
using namespace std;

int main(){
     long long int n, d;
    cin >> n >> d;
     long long int p[10][10];

	for ( long long int i = 0; i < n; ++i)
	{
		for ( long long int j = 0; j < d; ++j)
		{
			cin >> p[i][j];
		}
	}

     long long int cnt = 0;

	for ( long long int i = 0; i < n-1; ++i)
	{
		for ( long long int j = i+1; j < n; ++j)
		{
             long long int sum = 0;
			for ( long long int k = 0; k < d; ++k)
			{
				sum += (p[i][k]-p[j][k]) * (p[i][k]-p[j][k]);
			}

			 long long int s = ( long long int)sqrt(sum);
			 long long int q = s;
			if(sum == q * q){
				cnt++;
			}
		}
	}

	cout << cnt << endl;
}

Measured memory_bytes: 256
MOD = 10**9+7
N = gets.chomp.to_i
a = Array.new(N)
str = gets.split
for i in 0...N do
    a[i] = str[i].to_i
end
if N == 1
    puts 1
    exit
end
m = a[0]
for i in 1...N do
    m = m.lcm(a[i])
end
answer = 0
for i in 0...N do
    answer += (m/a[i]) % MOD
    answer = answer % MOD
end
puts answer

Measured memory_bytes: 50012
#include <cstdio>
#include <cmath>
int a[6];

void transform(char c){
    int b[6];
    for(int i=0;i<6;i++){
        b[i]=a[i];
    }
    if(c=='S'){
        a[1]=b[0];
        a[5]=b[1];
        a[4]=b[5];
        a[0]=b[4];
    }
    if(c=='W'){
        a[3]=b[0];
        a[5]=b[3];
        a[2]=b[5];
        a[0]=b[2];
    }
    if(c=='N'){
        a[0]=b[1];
        a[1]=b[5];
        a[5]=b[4];
        a[4]=b[0];
    }
    if(c=='E'){
        a[0]=b[3];
        a[3]=b[5];
        a[5]=b[2];
        a[2]=b[0];
    }

}
int main(){
    //int a[6];
    for(int i=0;i<6;i++){
        scanf("%d",&a[i]);
    }
    
    char instruct[100];
    scanf("%s",instruct);
    for(int i=0;instruct[i]!='\0';i++){
        transform(instruct[i]);
    }
   
    printf("%d\n",a[0]);
    return 0;
}


Measured memory_bytes: 2748
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second
#define dbg(x) cout<<#x" = "<<((x))<<endl
template<class T,class U> ostream& operator<<(ostream& o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream& o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

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

    int idx = -1;
    rep(i,n){
        int a;
        cin >>a;
        if(a==1) idx = i;
    }

    int w = k-1;
    int ans = n;
    rep(loop,2){
        int l=idx;
        int t = (l+w-1)/w;

        if(l%w != 0) l += (w-l%w);
        l = min(l,n-1);

        int r = n-1-l;
        t += (r+w-1)/w;

        ans = min(ans,t);
        idx = n-1-idx;
    }
    cout << ans << endl;
    return 0;
}


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

const int MOD = 1e9+7;
const int N = 1e6+7;

vector<int> mf(N, -1);

int modfact(int n) {
  if (mf[n] != -1) return mf[n];
  if (n == 0) return mf[0] = 1;
  return mf[n] = (ll)n * modfact(n-1) % MOD; 
}

int modinv(int a) {
  int b = MOD, u = 1, v = 0;
  while (b) {
    int t = a / b;
    a -= t * b; swap(a, b);
    u -= t * v; swap(u, v);
  }
  u %= MOD;
  if (u < 0) u += MOD;
  return u;
}

vector<int> mif(N, -1);

int modinvfact(int n) {
  if (mif[n] != -1) return mif[n];
  if (n == 0) return mif[0] = 1;
  return mif[n] = (ll)modinv(n) * modinvfact(n-1) % MOD;
}

int modcomb(int n, int k) {
  return (ll)modfact(n) * modinvfact(k) % MOD * modinvfact(n-k) % MOD;
}

int main() {
  int x, y;
  cin >> x >> y;
  if ((2*x-y)%3 || (2*y-x)%3) {
    cout << 0 << endl;
    return 0;
  }
  int a = (2*x-y)/3;
  int b = (2*y-x)/3;
  if (a < 0 || b < 0) {
    cout << 0 << endl;
    return 0;
  }
  int ans = modcomb(a+b, a);
  if (ans < 0) ans += MOD;
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 21356
def tenka18beg_c():
    N = int(input())
    A = [int(input()) for _ in range(N)]
    A_desc = sorted(A, reverse=True)

    if N % 2 == 1:
        tot1, tot2 = 0, 0
        for i, a in enumerate(A_desc):
            if i < N//2 - 1:
                tot1 += 2*a
                tot2 += 2*a
            elif i == N//2 - 1:
                tot1 += a
                tot2 += 2*a
            elif i == N//2:
                tot1 += a
                tot2 -= a
            elif i == N//2 + 1:
                tot1 -= 2*a
                tot2 -= a
            elif N//2 + 1 < i:
                tot1 -= 2*a
                tot2 -= 2*a
        ans = max(tot1, tot2)
    else:
        tot = 0
        for i, a in enumerate(A_desc):
            if i < N//2 - 1:
                tot += 2*a
            elif i == N//2 - 1:
                tot += a
            elif i == N//2:
                tot -= a
            elif N//2 < i:
                tot -= 2*a
        ans = tot
    print(ans)

tenka18beg_c()

Measured memory_bytes: 8292
import java.util.*;

public class Main {
	static char[]s;
	static char[]t;
	static int sl;
	static int tl;
	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc= new Scanner(System.in);
		
		String S= sc.nextLine();
		String T= sc.nextLine();
		
		sc.close();
		
		s= S.toCharArray();
		t= T.toCharArray();
		
		
		sl= s.length;
		tl= t.length;
		
		int hit=0;
		for(int left=0;left+tl<=sl;left++){
			int temp=0;
			for(int i=0;i<tl;i++)if(s[left+ i] == t[i])temp++;
			hit= Math.max(hit, temp);	
		}
		
		System.out.println(tl-hit);
	
	}
	

}


Measured memory_bytes: 35580
import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        int k = sc.nextInt();
        DJSet dj = new DJSet(n);
        int[] b = new int[n];
        for (int i = 0; i < m; i++) {
            int x = sc.nextInt()-1;
            int y = sc.nextInt()-1;
            dj.union(x, y);
            b[x]--; b[y]--;
        }
        for (int i = 0; i < k; i++) {
            int x = sc.nextInt()-1;
            int y = sc.nextInt()-1;
            if(dj.same(x, y)){
                b[x]--; b[y]--;
            }
        }
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < n; i++) {
            int c = dj.countElement(i) + b[i] - 1;
            sb.append(c + " ");
        }
        System.out.println(sb.toString().trim());
        sc.close();

    }

}

class DJSet {
    /**
     * 各要素の親を保持する配列。
     * 自信が根である要素は負の数を持つ。
     * （負の数の場合、絶対値がその集合の要素数）
     */
    public int[] upper;

    /**
     * コンストラクタ。
     * @param n 対象となる要素数
     */
    public DJSet(int n) {
        upper = new int[n];
        Arrays.fill(upper, -1);
    }

    /**
     * 要素xが含まれる集合のrootを求める。
     * rootを求める過程で経路圧縮しrootが親になるようにする。
     * @param x 要素x
     * @return 要素xが含まれる集合のroot
     */
    public int root(int x) {
        return upper[x] < 0 ? x : (upper[x] = root(upper[x]));
    }

    /**
     * 要素xと要素yが同じ集合か判定する。
     * @param x 要素x
     * @param y 要素y
     * @return 要素xと要素yが同じ集合であればtrue、そうでなければfalseを返す。
     */
    public boolean same(int x, int y) {
        return root(x) == root(y);
    }

    /**
     * 要素xと要素yを含むそれぞれの集合を合併する。
     * 要素数の多い集合のrootを残し、少ないほうのrootをその下に合併する。
     * @param x 要素x
     * @param y 要素y
     * @return 要素xと要素yを含むそれぞれの集合を合併できたらtrue、もともと同じ集合で合併しなかったらfalseを返す。
     */
    public boolean union(int x, int y) {
        x = root(x);
        y = root(y);
        if (x != y) {
            if (upper[y] < upper[x]) {
                int t = x;
                x = y;
                y = t;
            }
            upper[x] += upper[y];
            upper[y] = x;
        }
        return x != y;
    }

    /**
     * 集合の数を数える。
     * @return 集合の数
     */
    public int countSet() {
        int c = 0;
        for (int u : upper) {
            if (u < 0)
                c++;
        }
        return c;
    }

    /**
     * 要素ｘが含まれる集合の要素数を数える。
     * @param x 要素ｘ
     * @return 要素ｘが含まれる集合の要素数
     */
    public int countElement(int x) {
        return upper[root(x)] * -1;
    }
}

Measured memory_bytes: 93904
import java.util.Scanner;

public class Main{
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		double x = 0;
		double y = 0;
		int th = 90;
		while(sc.hasNext()) {
			String s = sc.next();
			String[] t = s.split(",");
			int d = Integer.parseInt(t[0]);
			int a = Integer.parseInt(t[1]);
			if(d == 0 && a == 0) break;
			x += d * Math.cos((double)th * Math.PI / 180);
			y += d * Math.sin((double)th * Math.PI / 180);
			th -= a;
		}
		System.out.println((int)x);
		System.out.println((int)y);
		sc.close();
	}
}



Measured memory_bytes: 26024
/**
 * @copyright (c) 2020 Daisuke Hashimoto
 */

#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
using Pair = pair<int64_t, int64_t>;

// std::cout << std::setprecision(20) << 1.1 << endl;

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

  int64_t K;
  cin >> K;
  // const int64_t L = static_cast<int64_t>(T.length());
  vector<set<string>> result;
  vector<string> nums = {"0", "1", "2", "3", "4", "5", "6", "7", "8", "9"};
  set<string> init = {"1", "2", "3", "4", "5", "6", "7", "8", "9"};
  result.emplace_back(init);
  int64_t count = 9;
  if (K <= count) {
    auto itr = init.begin();
    for (int64_t i = 0; i < K - 1; ++i) {
      ++itr;
    }
    cout << *itr << endl;
    return 0;
  }
  while (true) {
    set<string> temp;
    for (const auto &a : result[result.size() - 1]) {
      char head = a.c_str()[0] - '0';
      temp.insert(nums[head] + a);
      if (head > 1) {
        temp.insert(nums[head - 1] + a);
      }
      if (head < 9) {
        temp.insert(nums[head + 1] + a);
      }
      char tail = a.c_str()[a.length() - 1] - '0';
      temp.insert(a + nums[tail]);
      if (tail > 0) {
        temp.insert(a + nums[tail - 1]);
      }
      if (tail < 9) {
        temp.insert(a + nums[tail + 1]);
      }
    }
    result.emplace_back(temp);
    const int64_t c_cnt = static_cast<int64_t>(temp.size());
    if (count + c_cnt < K) {
      count += static_cast<int64_t>(temp.size());
    } else {
      const int64_t n = K - count - 1;
      auto itr = result[result.size() - 1].begin();
      for (int64_t i = 0; i < n; ++i) {
        ++itr;
      }
      cout << *itr << endl;
      break;
    }
  }
  return 0;
}


Measured memory_bytes: 29460
/* Author : tushar3105 */

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;

typedef pair<long long int,long long int> ii;					// Pair of integers
typedef vector<long long int> vi;                   				// Vector of integers
typedef vector<vector<long long int>> vvi;                 			// Vector of vi
typedef vector<pair<long long int, long long int>> vii;				// Vector of ii

#define pb push_back								// Push back to vectors
#define mp make_pair								// For pairs
#define ff first								// For pairs
#define ss second								// For pairs
#define all(c) (c).begin(),(c).end()						// Use in sorting
#define sz(a) ((long long int)(a).size())
#define lli long long int
#define ull unsigned long long int
#define ld long double
#define ref(i,x,y) for(long long int i=(x);i<=(y);++i)				// Loop to go forward
#define reb(i,x,y) for(long long int i=(x);i>=(y);--i)				// Loop to go backward
#define trf(c,it) for(auto it = (c).begin(); it != (c).end(); it++)		// Remember it is an iterator
#define trb(c,it) for(auto it = (c).end()-1; it != (c).begin()-1; it--)		// Remember it is an iterator
#define tc(t) long long int (t); cin>>(t);while((t)--)				// Test cases
//fill (dist,dist+110000,pinf);							// For setting default

const long long int mod = 1e9+7;
const long long int pinf = 9223372036854775807;
const long long int ninf = -9223372036854775807;

/*-----------------------------Code begins----------------------------------*/

int main (void)
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	
	char s[15], t[15];
	cin>>s;
	cin>>t;
	
	lli sl, tl, flag=0;
	
	sl=strlen(s);
	tl=strlen(t);
	
	if (sl+1!=tl)
		flag++;
		
	else
	{
		for (int i=0;i<sl;i++)
			if (s[i]!=t[i])
				flag++;
	}
	
	if (flag)
		cout<<"No\n";
		
	else
		cout<<"Yes\n";

	


	return 0;
}


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

#define ll long long

using namespace std;
const int MX = 200'000 + 5; // check bounds!

int main() {
    ll a, b, n;
    cin >> a >> b >> n;
    ll x = min(n, b - 1);
    cout << (a * x) / b;

    return 0;
}


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

string S;
ll K;

int main() {
    cin >> S >> K;
    ll N = S.length();

    for (ll i = 0; i < N-1; i++) {
        if (S[i] == 'a') continue;
        else if ('z' + 1 - S[i] <= K) {
            K -= 'z' + 1 - S[i];
            S[i] = 'a';
        }
    }
    if ('z' + 1 - S[N-1] <= K) {
        K -= 'z' + 1 - S[N-1];
        char tmp = (char)('a' + K%26);
        S[N-1] = tmp;
    }
    else {
        S[N-1] = (char)(S[N-1] + K);
    }

    cout << S << endl;

    return 0;
}


Measured memory_bytes: 512
#include <stdio.h>

int main(void) {
	int h = 0, m = 0, s;

	scanf("%d", &s);
	m = s / 60;
	s = s % 60;
	h = m / 60;
	m = m % 60;
	printf("%d:%d:%d\n", h, m, s);
}



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

6 7
1 2
2 3
5 3
2 6
5 1
3 4
4 6

*/
int recursiveLongestPath(map<int, vector<int>>& ma, int s){
    if(ma[s].size() == 0)
        return 0;
    int mxm = 0;
    for(auto x:ma[s]){
        int cur = 1 + recursiveLongestPath(ma, x);
        mxm = max(mxm, cur);
    }
    return mxm;
}

int memoLongestPath(vector<vector<int>>& v, int s, vector<int>& dp){
    if(dp[s] != -1)
        return dp[s];

    if(v[s].size() == 0){
        dp[s] = 0;
        return dp[s];
    }
    int mxm = 0;
    for(auto x:v[s]){
        int cur = 1 + memoLongestPath(v, x, dp);
        mxm = max(mxm, cur);
    }

    return dp[s] = mxm;

}
int main(){
    
    int n,m;
    cin>>n>>m;
    vector<vector<int>> v(n+1);
    int x,y;
    for(int i=0; i<m; i++){
        cin>>x>>y;
        v[x].push_back(y);
    }
    // sort(v.begin(), v.end(), compare);
    // int mxm = 0;
    // for(int i=1; i<=n; i++){
    //     mxm = max(mxm, recursiveLongestPath(ma, i));
    // }
    // cout<<"The length of the Longest Path(Recursive Implementation) is "<<mxm<<endl;
    int mxm = 0;
    
    vector<int> dp(n+1, -1);
    for(int i=1; i<=n; i++){
        mxm = max(mxm, memoLongestPath(v, i, dp));
    }
    // // cout<<"The length of the Longest Path(Memoization Implementation) is "<<mxm<<endl;
    cout<<mxm<<endl;
    // bool change = true;
    // // while(change){
    // //     change = false;
    // //     int prev;
    // //     for(int i=1; i<=n; i++){
    // //         prev = dp[i];
    // //         for(auto x:v[i])
    // //             dp[i] = max(dp[i], 1 + dp[x]);
    // //         if(prev != dp[i])
    // //             change = true;
    // //     }
    // //     for(auto x:dp){
    // //         cout<<x<<" ";
    // //     }
    // //     cout<<endl;
    // // }
    // for(int i=n; i > 0; i--){
    //     for(auto x:v[i]){
    //         dp[i] = max(dp[i], 1 + dp[x]);
    //     }
    // }
    
    // cout<<endl;
    // int ans = *max_element(dp.begin(), dp.end());
    // cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 11876
dic={}
n=int(input())
data=list(map(int,input().split()))
ans=0
for i in range(n):
    if data[i]>3199:
        ans+=1
    elif data[i]//400 not in dic:
        dic[data[i]//400]=1
if len(dic)==0:
    print(1,ans)
else:
    print(len(dic),ans+len(dic))


Measured memory_bytes: 3060
//In the name of god
#include <bits/stdc++.h>
#define pb push_back
#define F first
#define S second

using namespace std;
typedef long long ll;
#define int ll
typedef pair<int,int> pii;
const int maxn = 3000 + 10;
int can[maxn][maxn];
int a,b,c,d,e,f;
int fil(int w,int s){
	if (w + s > f) return 0;
	if (can[w][s]) return 0;
	can[w][s] = 1;
	fil (w + 100 * a,s);
	fil (w + 100 * b,s);
	fil (w, s + c);
	fil (w, s + d);
}
int32_t main(){
	ios_base::sync_with_stdio(0) , cin.tie(0);
//	int a,b,c,d,e,f;
	cin >> a >> b >> c >> d >> e >> f;
	fil(0,0);
	pii ans;
	ans = {100* a,0};
	for (int i = 1;i<= f;i++){
		for (int j = 1;j <=f;j++){
			if (i + j > f) break;
			if (i % 100) continue;
			if ((i / 100) * e < j) continue;
			//double i1 = double(i),j1 = double(j);	
			if (can[i][j]){
				if (j * ans.F > ans.S * (i + j)){
					ans = {i + j,j};
				}
			}
		}
	}
	cout <<ans.F << ' ' << ans.S << endl;
	return 0;
}

Measured memory_bytes: 45312
#include<bits/stdc++.h>
#define ll long long int
#define li long int
#define ull unsigned long long int

#define db double
#define MOD 1000000007
#define pb push_back
#define mp make_pair
#define mii map<int,int>
#define nl "\n"
using namespace std;

int main(int argc, char const *argv[]) {

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int k,i;
        cin>>k;
    int a,b;
        cin>>a>>b;
        
        for(i=a;i<=b;i++)
        {
            if(i%k==0)
            {
                cout<<"OK"<<nl;
                break;
            }
        }
        if(i==b+1)
            cout<<"NG"<<nl;
    return 0;
}


Measured memory_bytes: 3652
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define MOD 1000000007
#define PI 3.141592653589793
const int INF = 100000000;
int dx[] = {0,1,-1,0,1,-1,1,-1};
int dy[] = {1,0,0,-1,1,-1,-1,1};

int main(){
    int a, b, c, d, e, k;
    cin >> a >> b >> c >> d >> e >> k;
    cout << (e - a <= k ? "Yay!" : ":(") << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using PII = pair<ll, ll>;
#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
template<typename T> void chmin(T &a, const T &b) { a = min(a, b); }
template<typename T> void chmax(T &a, const T &b) { a = max(a, b); }
struct FastIO {FastIO() { cin.tie(0); ios::sync_with_stdio(0); }}fastiofastio;
#ifdef DEBUG_ 
#include "../program_contest_library/memo/dump.hpp"
#else
#define dump(...)
#endif
const ll INF = 1LL<<60;

int main(void) {
    ll n;
    cin >> n;
    vector<ll> a(n);
    REP(i, n) cin >> a[i];

    bool flag = true;
    REP(i, n) {
        if(a[i]%2==0) {
            if(a[i]%3 && a[i]%5) flag = false;
        }
    }

    if(flag) cout << "APPROVED" << endl;
    else cout << "DENIED" << endl;

    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;


vector<pair<int,int>> encode(){
    int m;
    cin>>m;
    int x[m],y[m];
    rep(i,m){
        cin>>x[i]>>y[i];
    }
    vector<pair<int,int>> ret;
    rep(i,m-1){
        int d=abs(x[i+1]-x[i])+abs(y[i+1]-y[i]);
        int c=0;
        if(x[i]<x[i+1])c=0;
        if(x[i+1]<x[i])c=2;
        if(y[i]<y[i+1])c=1;
        if(y[i]>y[i+1])c=3;
        ret.push_back({d,c});
    }
    return ret;
}
bool check(vector<pair<int,int>>& v,vector<pair<int,int>>& w){
    int n=v.size(),m=w.size();
    if(n!=m)return false;
    rep(i,n)if(v[i].first!=w[i].first)return false;
    int diff=(v[0].second-w[0].second+4)%4;
    rep(i,n){
        if(((v[i].second-w[i].second+4)%4)!=diff)return false;
    }
    return true;
}
int solve(int n){
    vector<vector<pair<int,int>>> v(n+1);
    rep(i,n+1)v[i]=encode();
    rep(i,n){
        if(check(v[0],v[i+1]))cout<<i+1<<endl;
        else {
            reverse(v[i+1].begin(),v[i+1].end());
            if(check(v[0],v[i+1]))cout<<i+1<<endl;
        }
    }
    cout<<"+++++"<<endl;
    return 0;
}


int main(){
    int n;
    while(cin>>n,n!=0)solve(n);
    return 0;
}


Measured memory_bytes: 3084
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rrep(i, n) for (int i = (n - 1); i >= 0; i--)
#define ALL(v) v.begin(), v.end()
using namespace std;
using P = pair<int, int>;
using PP = pair<int, P>;
typedef long long ll;
bool visited[1000][1000];
int dist[1000][1000];
string grid[1000];

int h, w, sy, sx, gy, gx;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int t_dx[16] = {1, 0, -1, 0, 1, 1, -1, -1, 2, 0, -2, 0, 2, 2, -2, -2};
const int t_dy[16] = {0, 1, 0, -1, 1, -1, 1, -1, 0, 2, 0, -2, 2, -2, 2, -2};
const int INF = (1 << 30);

//二次元グリッドグラフでのダイクストラ法
void dijkstra(int y, int x){
  dist[y][x] = 0;
  priority_queue<PP, vector<PP>, greater<PP>> que;
  que.push(PP(0, P(y, x)));
  while(!que.empty()) {
    PP p = que.top();
    que.pop();
    int cy = p.second.first, cx = p.second.second;
    for (int i = 0; i < 4; i++){
      int ny = cy + dy[i], nx = cx + dx[i];
      if (ny < 0 || h <= ny || nx < 0 || w <= nx)continue;
      if(grid[ny][nx] == '#')continue;
      if(dist[ny][nx] <= dist[cy][cx])continue;
      dist[ny][nx] = dist[cy][cx];
      que.push(PP(dist[ny][nx], P(ny, nx)));
    }
    for (int i = cy -2; i <= cy + 2; i++){
      for (int j = cx - 2; j <= cx + 2; j++){
        if (i < 0 || h <= i || j < 0 || w <= j)continue;
        if(grid[i][j] == '#')continue;
        if(dist[i][j] <= dist[cy][cx] + 1)continue;
        dist[i][j] = dist[cy][cx] + 1;
        que.push(PP(dist[i][j], P(i, j)));
      }
    }
  }
  return;
}

int main() {
  cin >> h >> w;
  cin >> sy >> sx;
  sy--, sx--;
  cin >> gy >> gx;
  gy--; gx--;
  rep(i, h){
    rep(j, w){
      dist[i][j] = INF;
    }
  }
  rep(i, h) cin >> grid[i];
  dijkstra(sy, sx);
  if(dist[gy][gx] ==INF){
    cout << -1 << endl;
  }else{
    cout << dist[gy][gx] << endl;
  }
}

Measured memory_bytes: 9408
//url:
//problem name:

#include <bits/stdc++.h>
#define REP(i,n) for (int i = 0; i < (n); ++i)
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;}
using namespace std;
using ll = long long;
using P = pair<int,int>;
using Pl = pair<long,long>;
using veci = vector<int>;
using vecl = vector<long>;
using vecveci = vector<vector<int>>;
using vecvecl = vector<vector<long,long>>;

int main() {
    ll A,B;
    cin >> A >> B;
    if(A == B) cout << 0 << endl;
    else if((A*A-B*B)%(2*A-2*B) == 0) cout << (A*A-B*B)/(2*A-2*B) <<endl;
    else cout << "IMPOSSIBLE" << endl;
}


Measured memory_bytes: 256
#include<cstdio>
using namespace std;
int g[32][50][50],n,m,a,b,c,t,s[50],bit[30];

void solve(){
    int x=t,ans;
    for(int i=0;i<30;i++){
        bit[i]=x%2;
        x/=2;
    }
    for(int i=0;i<n;i++){
        for(int j=0;j<n;j++){
            for(int k=1;k<31;k++){
                g[k][i][j]=0;
            }
            if(i-j==1){
                g[0][i][j]=a;
                g[31][i][j]=0;
            }
            else if(i==j){
                g[0][i][j]=b;
                g[31][i][j]=1;
            }
            else if(i-j==-1){
                g[0][i][j]=c;
                g[31][i][j]=0;
            }
            else{
                g[0][i][j]=0;
                g[31][i][j]=0;
            }
        }
    }
    for(int i=1;i<30;i++){
        for(int j=0;j<n;j++){
            for(int k=0;k<n;k++){
                for(int l=0;l<n;l++){
                    g[i][j][k]+=g[i-1][j][l]*g[i-1][l][k];
                    g[i][j][k]%=m;
                }
            }
        }
    }
    for(int i=0;i<30;i++){
        if(bit[i]){
            for(int j=0;j<n;j++){
                for(int k=0;k<n;k++){
                    for(int l=0;l<n;l++){
                        g[30][j][k]+=g[31][j][l]*g[i][l][k];
                        g[30][j][k]%=m;
                    }
                }
            }
            for(int j=0;j<n;j++){
                for(int k=0;k<n;k++){
                    g[31][j][k]=g[30][j][k];
                    g[30][j][k]=0;
                }
            }
        }
    }
    for(int i=0;i<n;i++){
        ans=0;
        for(int j=0;j<n;j++){
            ans+=s[j]*g[31][i][j];
            ans%=m;
        }
        printf("%d",ans);
        if(i<n-1){
            printf(" ");
        }
        else{
            printf("\n");
        }
    }
}

int main(){
    scanf("%d %d %d %d %d %d",&n,&m,&a,&b,&c,&t);
    while(n|m|a|b|c|t){
        for(int i=0;i<n;i++){
            scanf("%d",&s[i]);
        }
        if(t){
            solve();
        }
        else{
            for(int i=0;i<n;i++){
                printf("%d",s[i]);
                if(i<n-1){
                    printf(" ");
                }
                else{
                    printf("\n");
                }
            }
        }
        scanf("%d %d %d %d %d %d",&n,&m,&a,&b,&c,&t);
    }
}


Measured memory_bytes: 3048
N = $stdin.gets.chomp.to_i
result = {'' => 0}
N.times do |i|
    str = $stdin.gets.chomp
    result[str] = (result[str] || 0) + 1
end
M = $stdin.gets.chomp.to_i
M.times do |i|
    str = $stdin.gets.chomp
    result[str] = (result[str] || 0) - 1
end

print result.values.max

Measured memory_bytes: 1788
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <iomanip>
#include <numeric>
#include <queue>
#include <cmath>
using namespace std;

int main() {
	int n;
	cin >> n;
	long long int res = 0;
	unordered_map<string, int> um;
	for (int i = 0; i < n; i++) {
		string s;
		cin >> s;
		sort(s.begin(), s.end());
		res += um[s];
		um[s]++;
	}
	cout << res << endl;
}


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

int main(void) {
	using namespace std;
	int N, K;
	cin >> N >> K;
	if ((N + 1)/2 >= K) {
		cout << "YES" << endl;
	}
	else {
		cout << "NO" << endl;
	}
}

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

template<typename T>
void printmatrix(vector<vector<T> > ar){
    for (int i = 0; i < (int)ar.size(); i++) {
        for (int j = 0; j < (int)ar.size(); j++) {
            cout << ar[i][j];
        }
        cout << endl;
    }
}

template<typename T>
void printvector(vector<T> vec){
    for (int i = 0; i < (int)vec.size(); i++) {
        cout << vec[i] << endl;
    }
}


int main(int argc, char const* argv[])
{
    int n;
    cin >> n;
    vector<int> vec(n);
    for (int i = 0; i < n; i++) {
        cin >> vec[i];
    }

    vector<int> sortedvec(vec);
    sort(sortedvec.begin(), sortedvec.end());
   
    int r = sortedvec[n/2], l = sortedvec[n/2-1];

    for (int i = 0; i < n; i++) {
        if (vec[i] < r) {
            cout << r << endl;
        }else{
            cout << l << endl;
        }

    }

    return 0;
}

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



int main() {
  ll N,K;
  cin>>N>>K;
  vector<int> p(N);
  rep(i,N){
      cin>>p.at(i);
  }
  ll sum=0,ma=0;
  rep(i,K){
      sum+=p.at(i);
  }
  ma=sum;
  rep(i,N-K){
      sum-=p.at(i);
      sum+=p.at(i+K);
      ma=max(ma,sum);
  }
  ma+=K;

  double ans=(double)ma/2;
  cout << fixed << setprecision(10);
  cout<<ans<<endl;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vint;
typedef pair<int,int> pint;
typedef vector<pint> vpint;
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,n) for(int i=n-1;i>=(0);i--)
#define reps(i,f,n) for(int i=(f);i<(n);i++)
#define each(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++)
#define all(v) (v).begin(),(v).end()
#define eall(v) unique(all(v), v.end())
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))
const int MOD = 1e9 + 7;
const int INF = 1e9;
const ll INFF = 1e18;


ll n, m;
ll x[100010], y[100010];
ll a[100010], b[100010];
int main(void){
	cin >> n >> m;
	rep(i, n) cin >> x[i];
	rep(i, m) cin >> y[i];
	// rep(i, n - 1) a[i] = x[i + 1] - x[i];
	// rep(i, m - 1) b[i] = y[i + 1] - y[i];

	ll sumx = 0, sumy = 0;
	rep(i, n) sumx += (i * x[i]) - ((n - 1 - i) * x[i]), sumx %= MOD;
	// printf("x %lld\n", sumx);
	rep(i, m) sumy += (i * y[i]) - ((m - 1 - i) * y[i]), sumy %= MOD;
	// printf("y %lld\n", sumy);
	
	ll ret = sumx * sumy % MOD;
	printf("%lld\n", ret);
	return 0;
}

Measured memory_bytes: 1792