akhauriyash/Code-Regression huggingface dataset:
use std::error::Error;
use std::io;

pub fn main() {
    if let Err(_e) = run() {
        panic!("failed");
    }
}

fn run() -> Result<(), Box<Error>> {
    let mut input = String::new();
    io::stdin().read_line(&mut input);
    let line: Vec<i64> = input
        .trim()
        .split_whitespace()
        .map(|s| s.parse::<i64>().unwrap())
        .collect();
    let n = line[0];
    let k = line[1];
    input.clear();
    let mut edges = Vec::new();
    for _ in 0..n {
        io::stdin().read_line(&mut input)?;
        let line: Vec<i64> = input
            .trim()
            .split_whitespace()
            .map(|s| s.parse::<i64>().unwrap())
            .collect();
        edges.push(line);
        input.clear();
    }
    let result = solve(&edges, k, n);
    let mut sum = 0;
    for i in 0..n as usize {
        for j in 0..n as usize {
            sum += result[i][j];
            sum %= 1_000_000_007;
        }
    }
    println!("{:?}", sum);
    Ok(())
}

fn solve(edges: &Vec<Vec<i64>>, k: i64, n: i64) -> Vec<Vec<i64>> {
    if k == 1 {
        return edges.clone();
    }
    let pow = solve(edges, k / 2, n);
    if k % 2 == 1 {
        return multiply(edges, &multiply(&pow, &pow, n), n);
    }
    return multiply(&pow, &pow, n);
}

fn multiply(a: &Vec<Vec<i64>>, b: &Vec<Vec<i64>>, n: i64) -> Vec<Vec<i64>> {
    let mut result = vec![vec![0; n as usize]; n as usize];
    for i in 0..n as usize {
        for j in 0..n as usize {
            let mut sum = 0;
            for k in 0..n as usize {
                sum += a[i][k] * b[k][j];
                sum %= 1_000_000_007;
            }
            result[i][j] = sum;
        }
    }
    result
}


Measured memory_bytes: 4352
#!/usr/bin/env python3


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    # Failed to predict input format
    n, k = map(int, input().split())
    a = list(map(int, input().split()))
    start = 0
    visited = {start}
    visited_list = [start]
    while True:
        start = a[start] - 1
        if start in visited:
            loop_start = start
            break
        visited_list.append(start)
        visited.add(start)
    p = visited_list.index(loop_start)
    loop = visited_list[p:]
    if k < p:
        print(visited_list[k] + 1)
    else:
        print(loop[(k - p) % len(loop)] + 1)


if __name__ == "__main__":
    main()


Measured memory_bytes: 35372
#include<iostream>
#include <bits/stdc++.h>
#define ll long long int
#define endl '\n'
#define modn 1000000007
using namespace std;
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int tc;
    //cin>>tc;
    tc = 1;
    while(tc--)
    {
        int n;
        cin>>n;
        int arr[n];
        for(int i=0; i<n; i++) cin>>arr[i];
        sort(arr , arr+n);
        long long alice=0, bob=0;
        for(int i=n-1; i>=0; i-=2) alice += arr[i];
        for(int i=n-2; i>=0; i-=2) bob += arr[i];
        cout<<alice-bob<<endl;
    }
    return 0;
}


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

using ll = long long;

const int INF = 1001001001;
const ll INF_LL = 1001001001001001001LL;

int main(void){
  int a,b; cin >> a >> b;

  bool ok = true;
  if(a>8 || b>8) ok = false;
  
  if(ok) cout << "Yay!" << endl;
  else cout << ":(" << endl;
    
  return 0;
}


Measured memory_bytes: 3600
/*
dream dreamer erase eraser

AtCoderとRustのバージョンがあってない。.get使えない
*/
fn main() {
    // let mut org_s = String::from("erasedream");
    let mut org_s = read_line_str().replace("\n", "");
    let words = ["dreamer", "eraser", "dream", "erase"];
    let mut before_length = org_s.len();
    loop {
        for i in 0..words.len() {
            let mut s = org_s.clone();
            let length = words[i].len();
            if s.len() < length {
                continue;
            }

            // not supported
            // let tail = s.get((s.len() - length)..s.len()).unwrap();
            // let head = s.get(0..(s.len() - length)).unwrap();

            let tail = &s[(s.len() - length)..s.len()];
            let head = &s[0..(s.len() - length)];
            if tail == words[i] {
                org_s = String::from(head);
                break;
            }
        }
        if before_length == org_s.len() {
            println!("NO");
            return;
        }
        if org_s.len() <= 0 {
            println!("YES");
            return;
        }

        before_length = org_s.len();
    }

    println!("YES");
}

fn read_line_str() -> String {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    return s;
}

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

int main(){
    int n;
    std::cin >> n;
    std::vector<long long> A(n);
    for(int i=0; i<n; i++) std::cin >> A.at(i);
    std::sort(A.begin(),A.end());
    long long ans=0;
    int can = 1, will = n-1;
    for(int i=0; i<n-1; i++){
        ans += A.at(will);
        can--;
        if(can == 0){
            can = 2;
            will--;
        }
    }
    std::cout << ans << std::endl;
}


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

// types
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pdd;
typedef vector<ll> vll;

// macros
#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define FI first
#define SE second
#define REP(i,n) for(int i=0;i<((int)n);i++)
#define REP1(i,n) for(int i=1;i<((int)n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define PB push_back
#define EB emplace_back
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL

// constants
const int inf = 1e9;
const ll linf = 1LL << 50;
const double eps = 1e-10;
const int MOD = 1e9 + 7;
const int dx[4] = {-1, 0, 1, 0};
const int dy[4] = {0, -1, 0, 1};

int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);

  string s;
  cin >> s;

  ll a;
  a = 0;
  ll ans = 0;
  for(ll i = 0; i < s.size()-1; i++){
    if(s[i] == 'A')
      a += 1;
    else if(s.substr(i, 2) == "BC"){
      ans += a;
      i++;
    }
    else{
      a = 0;
    }
  }

  cout << ans << endl;
}


Measured memory_bytes: 720
#include <iostream>
#include <vector>
#include <string>
#include <list>
#include <queue>
#include <algorithm>
#define rep(i, n) for(i = 0; i < (n); i++)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define MOD 1000000007
#define PI 3.14159265358979323846
#define INF 1 << 30

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

int main(void) {
	int num, i, j;
	double ans = 0.0;
	cin >> num;
	vector<double> p(num);
	rep(i, num)
		cin >> p[i];
	vector<vector<double>> dp(num + 1, vector<double>(num + 1, 0.0));
	dp[0][0] = 1.0;
	rep(i, num) {
		rep(j, i + 1) {
			dp[i + 1][j + 1] = dp[i][j] * p[i];
			dp[i + 1][j] += dp[i][j] * (1.0 - p[i]);
		}
	}
	for (i = num / 2 + 1; i <= num; i++) {
		ans += dp[num][i];
	}
	printf("%.10lf\n", ans);
	return 0;
}

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


int main (){


  int H = 0 , W = 0 ;


  while (1){
 
    cin >> H >> W ;
    
    if ( H == 0 && W == 0 ) break ;
    
    for ( int h = 0 ; h < H ; h++ ){
      for ( int w = 0 ; w < W ; w++ ){
	if ( (w + h) % 2 == 1 ){
	  cout << "." ;
	} else {
	  cout << "#" ;
	}

      }


      cout << endl ;

    }

    cout << "\n" ;

  }

  return 0 ;

}

Measured memory_bytes: 1152
#include <bits/stdc++.h>
using namespace std;
typedef int int__;
#define int long long
#define pb push_back
#define pi pair<int,int>
#define vpi vector<pi>
#define vi vector<int>
#define vvi vector<vi>
#define fi first
#define se second
#define forn(i, n)for(int i=0;i<int__(n);i++) 
#define sz(a)int__(a.size())
template <class A, class B> ostream& operator << (ostream& out, const pair<A, B> &a){return out << "(" << a.first << ", " << a.second << ")";}
template<class A>ostream& operator<<(ostream& out,const vector<A>&v){out<<"[";forn(i,sz(v)){if(i)out<<", ";out<<v[i];}return out<<"]";}
const int MAX = 1e9 + 100;
#define fast ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
int Mod(int x){const int mm=2019;x%=mm;if(x<0)x+=mm;return x;}
int Pow(int x,int n){if(n==0)return 1;int t=Pow(x,n/2);t=Mod(t*t);if(n&1)t=Mod(t*x);return t;}
#define watch(x) cout << #x << " : " << x << endl;
int gcd(int a,int b){if(b==0)return a;return gcd(b,a%b);}
#define all(x) x.begin(), x.end()

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

	vi a(n+1); for(int i=0;i<=n;i++) {a[i]=i; if(i) a[i] += a[i-1];}
	int mod = 1e9 + 7;
	int cnt=0;
	for(int i=k;i<=n+1;i++) {
		int mn=a[i-1];
		int mx=a[n] - a[n-i];

		cnt += max(0LL,mx-mn+1);
		cnt %= mod;
	}

	cout << cnt + 1<< endl;
}

Measured memory_bytes: 4712
n = int(input())

a = []
b = []
for i in range(n):
  ab = input().split()
  a.append(int(ab[0]))
  b.append(int(ab[1]))
import statistics
a = statistics.median(a)
b = statistics.median(b)
if n % 2 != 0:
  print(int(b-a+1))
else:
  print(int(2*(b-a)+1))


Measured memory_bytes: 28908
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define FOR(i, s, n) for (int i = (s); i < (n); i++)
#define RFOR(i, s, n) for (int i = (n) - 1; i >= (s); i--)
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) RFOR(i, 0, n)
#define ALL(a) a.begin(), a.end()
const long long MOD = 1e9 + 7, INF = 1e18;
template<class T>inline bool CHMAX(T&a,T b){if(a<b){a=b;return true;}return false;}
template<class T>inline bool CHMIN(T&a,T b){if(a>b){a=b;return true;}return false;}


signed main(){
	int N;
	cin >> N;
	vector<pair<int,int>>v;
	REP(i,N){
		int c,d;
		cin>>c>>d;
		if(c>d)swap(c,d);
		v.push_back({c,i});
		v.push_back({d,i});
	}
	sort(ALL(v));
	int ans = INF;
	set<int>st;
	int secondmi = INF,secondma = -1;
	REP(i,N*2){
		if(st.find(v[i].second) != st.end()){
			secondma = v[i].first;
			break;
		}
		st.insert(v[i].second);
	}
	st.clear();
	RREP(i,N*2){
		if(st.find(v[i].second) != st.end()){
			secondmi = v[i].first;
			break;
		}
		st.insert(v[i].second);
	}
	st.clear();
	vector<int>cnt(N,0);
	int right = 0;
    for (int left = 0; left < 2 * N; ++left) {
        while (right < 2 * N && st.size() < N) {
			st.insert(v[right].second);
			cnt[v[right].second]++;
            ++right;
        }
		if(right == 2 * N && st.size() < N)break;
		if(left == 0){
			CHMIN(ans,(v[right-1].first-v[0].first)*(v[2*N-1].first-secondma));
		}else if(right == 2 * N){
			CHMIN(ans,(v[right-1].first-v[left].first)*(secondmi-v[0].first));
		}else{
			CHMIN(ans,(v[right-1].first-v[left].first)*(v[2*N-1].first-v[0].first));
		}
		if(--cnt[v[left].second] == 0)st.erase(v[left].second);
    }
	cout << ans << endl;
}


Measured memory_bytes: 19304
#include<iostream>
#include<cstdio>
using namespace std;
int main(){
	int a,b;
	cin>>a>>b;
	cout<<(b%2==0 && b>=a*2 && b<=a*4 ? "Yes" : "No")<<endl;
	//b%2==0，小细节，interesting
	return 0;
}




Measured memory_bytes: 3628
# coding: utf-8

n, m = map(int, input().split())

a_list = list(map(int, input().split()))

border = sum(a_list) / (4 * m)

a_choiced_list = [a for a in a_list if a >= border]

if len(a_choiced_list) < m:
    print('No')
else:
    print('Yes')


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

signed main() {
  int N,M;
  cin >> N >> M;
  int ans = 0;
  if(N>1) ans += N * (N-1) / 2;
  if(M>1) ans += M * (M-1) / 2;
  cout << ans << endl;

}


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

int main(){
  long int n,k,i;
  cin >> n >> k;
  if(n<k*2-1){
    cout << -1 << endl;
  }else if(n%2==1){
    for(i=0;i<=(n-1)/2;i++){
      cout << k+2*i << ' ' << k+(3*n-1)/2-i << ' ' << k+2*n+i << endl;
    }
    for(i=0;i<=(n-3)/2;i++){
      cout << k+2*i+1 << ' ' << k+2*n-1-i << ' ' << k+(5*n+1)/2+i << endl;
    }
  }else{
    for(i=0;i<=n/2-1;i++){
      cout << k+2*i << ' ' << k+3*n/2-1-i << ' ' << k+2*n+i << endl;
    }
    for(i=0;i<=n/2-1;i++){
      cout << k+2*i+1 << ' ' << k+2*n-1-i << ' ' << k+5*n/2+i << endl;
    }
  }
}

Measured memory_bytes: 2304
#include <bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define sz(x) (int)x.size()
#define all(x) begin(x), end(x)
#define debug(x) cerr << #x << " " << x << '\n'
using namespace std;
using ll = long long;
using pii = pair<int,int>;
using pli = pair<ll,int>;
const int INF = 0x3f3f3f3f, N = 1e5 + 5;
const ll LINF = 1e18 + 5;
constexpr int mod = 1e9 + 7;
int n, k, f[N], c[N];
vector <int> G[N];
inline void mul(int &a, int b) { a = 1ll*a*b%mod; }; 
void dfs(int u, int fa)
{
	int pre = 0;
	f[u] = fa;
	for(int v : G[u])
	{
		if(v==fa) continue;
		dfs(v, u);
		c[v] = c[pre] + 1;
		pre = v;
	}
}
int main()
{
 	ios::sync_with_stdio(false);
 	cin.tie(0);
 	cin >> n >> k;
 	for(int i=1; i<n; i++) 
 	{
 		int u, v;
 		cin >> u >> v;
 		G[u].pb(v); G[v].pb(u);
 	}
 	c[0] = -1;
 	dfs(1, 0);
 	int ans = 1;
 	for(int i=1; i<=n; i++)
 	{
 		if(f[i]) c[i]++;
 		if(f[f[i]]) c[i]++;
 		if(k-c[i]<0) ans = 0;
 		mul(ans, k-c[i]);
 	}
 	cout << ans;
	return 0;
}


Measured memory_bytes: 11136
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main() {
	cin.tie(0); ios::sync_with_stdio(false);
	int N, M; cin >> N >> M;
	vector<int> A(M), ans(N + 1, 0);
	for (int i = 0; i < M; i++) cin >> A[i];
	
	for (int i = 0; i < M; i++) {
		for (int j = 1; j <= N;j++) {
			int B; cin >> B;
			if (B == A[i]) {
				ans[j]++;
			}
			else {
				ans[A[i]]++;
			}
		}
	}

	for (int i = 1;i <= N;i++) {
		cout << ans[i] << endl;
	}
}

Measured memory_bytes: 3224
object Main {
  def main(args: Array[String]): Unit = {
    val Array(m, n) = io.StdIn.readLine().split(" ").map(_.toInt)
    println(power(m, n))
  }
  def power(m: Int, n: Int): Long = {
    def loop(m: Long, n: Int, acc: Long): Long = n match {
      case 0 => acc
      case _ if n % 2 == 0 => loop((m * m) % 1000000007, n / 2, acc)
      case _ => loop(m, n - 1, (m * acc) % 1000000007)
    }
    loop(m, n, 1)
  }
}

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

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

public class Main{

	Scanner sc=new Scanner(System.in);

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

	String s;

	void run(){
		for(int n=sc.nextInt(); n>0; n--){
			s=sc.next();
			println(equation(0).val+"");
		}
	}

	R equation(int p){
		R r=factor(p);
		for(;;){
			char c=s.charAt(r.p);
			if(c=='+'||c=='-'){
				R q=factor(r.p+1);
				if(c=='+')
					r.val+=q.val;
				else
					r.val-=q.val;
				r.p=q.p;
			}else{
				break;
			}
		}
		return r;
	}

	R factor(int p){
		R r=term(p);
		for(;;){
			char c=s.charAt(r.p);
			if(c=='*'||c=='/'){
				R q=term(r.p+1);
				if(c=='*')
					r.val*=q.val;
				else
					r.val/=q.val;
				r.p=q.p;
			}else{
				break;
			}
		}
		return r;
	}

	R term(int p){
		if(s.charAt(p)=='('){
			R r=equation(p+1);
			r.p++; // skip ')'
			return r;
		}else{
			long val=0;
			for(; Character.isDigit(s.charAt(p)); p++){
				val=val*10+(s.charAt(p)-'0');
			}
			return new R(p, val);
		}
	}

	class R{
		int p;
		long val;

		R(int p, long val){
			this.p=p;
			this.val=val;
		}
	}

	void debug(Object... os){
		System.err.println(Arrays.deepToString(os));
	}

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

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

	public static void main(String[] args){
		// System.setOut(new PrintStream(new BufferedOutputStream(System.out)));
		new Main().run();
	}
}

Measured memory_bytes: 12000
#define ll long long int
#define f(i,n) for(long long int i=0;i<n;i++)
#define fx(i,x,n) for(long long int i=x;i<n;i++)
#define fxe(i,x,n) for(long long int i=x;i<=n;i++)
#define MAX 1000000
#include<bits/stdc++.h>
using namespace std;
int maxcandies(vector<vector<ll> >a,ll i,ll j){
    if(i>=a.size() || i<0 || j>=a[i].size() || j<0){
        return 0;
    }
    else{
        return a[i][j]+max(maxcandies(a,i+1,j),maxcandies(a,i,j+1));
    }
}
int main(){
    ll n;
    cin>>n;
    vector<vector<ll> >a;
    vector<ll>temp;
    f(i,n){
        ll x;
        cin>>x;
        temp.push_back(x);
    }
    a.push_back(temp);
    temp.clear();

    f(i,n){
        ll x;
        cin>>x;
        temp.push_back(x);
    }
    a.push_back(temp);
    cout<<maxcandies(a,0,0)<<"\n";
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
#define INT long long int
#define MOD 1000000007
using namespace std;
string s;
int n, d[100010];
int main()
{
    ios::sync_with_stdio(false);
    cin>>n;
    for(int i = 0 ; i < n ; i++ ) cin>>d[i];
    sort(d, d+n);
    cout<<d[n/2]-d[(n/2)-1]<<endl;
}


Measured memory_bytes: 640
def divisor_enumetarion(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)
    divisors.remove(n)
    return divisors
    
n,k=map(int,input().split())

dp=[0]*k
mod=10**9+7

ans=0
for i in range(k,0,-1):
    toori=pow(k//i,n,mod)

    dp[i-1]+=toori

    x=divisor_enumetarion(i)
    for j in x:
        dp[j-1]-=dp[i-1]%mod

    ans+=(dp[i-1]*i)%mod
#    print(dp)
#    print(i,dp[i-1])
print(ans%mod)

#gcdがiの時だけを考え通りを引いて1を足す

Measured memory_bytes: 12020
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define rep2(i, s, n) for (ll i = (s); i < (ll)(n); i++)
#define all(v) v.begin(), v.end()
#define sz(v) v.size()
#define INF 100000000000000 //10^14 100兆
// aよりもbが大きいならばaをbで更新する
// (更新されたならばtrueを返す)
template <typename T>
bool chmax(T &a, const T& b) {
  if (a < b) {
    a = b;  // aをbで更新
    return true;
  }
  return false;
}
// aよりもbが小さいならばaをbで更新する
// (更新されたならばtrueを返す)
template <typename T>
bool chmin(T &a, const T& b) {
  if (a > b) {
    a = b;  // aをbで更新
    return true;
  }
  return false;
}

vector<ll> par(100000);
vector<ll> rnk(100000);
 
void init(ll n){
  rep(i, n){
    par.at(i) = i;
    rnk.at(i) = 1;
  }
}
 
ll root(ll x){
  if(par.at(x) == x){
    return x;
  }
  else{
    par.at(x) = root(par.at(x));
    return par.at(x);
  }
}
 
bool same(ll x, ll y){
  if(root(x) == root(y)){
    return true;
  }
  else{
    return false;
  }
}
 
void unite(ll x, ll y){
  x = root(x);
  y = root(y);
  if(x == y){
    return;
  }
  if(rnk.at(x) < rnk.at(y)){
    par.at(x) = y;
    rnk.at(y) += rnk.at(x);
  }
  else{
    par.at(y) = x;
    rnk.at(x) += rnk.at(y);
  }
}

int main(){
  ll N, M;
  cin >> N >> M;
  init(N);
  vector<ll> A(M), B(M);
  rep(i, M){
    cin >> A.at(i) >> B.at(i);
    A.at(i)--;
    B.at(i)--;
  }
  vector<ll> inc(M+1, 0);
  inc.at(M) = N * (N - 1) / 2;
  rep(i, M){
    if(!same(A.at(M-1-i), B.at(M-1-i))){
      inc.at(M-i-1) = inc.at(M-i) - rnk.at(root(A.at(M-1-i))) * rnk.at(root(B.at(M-1-i)));
    }
    else{
      inc.at(M-i-1) = inc.at(M-i);
    }
    unite(A.at(M-1-i), B.at(M-1-i));
  }
  rep(i, M){
    cout << inc.at(i+1) << endl;
  }
}

Measured memory_bytes: 5248
#include <bits/stdc++.h>
#define inf 1000000000
#define mod 1000000007
using namespace std;
using LL = long long;

int main(){
    LL r,d,x;cin>>r>>d>>x;

    for(int i=0;i<10;i++){
        x = r*x-d;
        cout<<x<<endl;
    }
}


Measured memory_bytes: 256
import itertools
N=int(input())
retu=[i for i in range(N)]
XY=[]
for i in range(N):
    x=list(map(int,input().split()))
    XY.append(x)
permi=list(itertools.permutations(retu))
goukei=0
count=0
for i in permi:
    count+=1
    for k in range(1,N):
        a=XY[i[k - 1]][0]- XY[i[k]][0]
        b=XY[i[k - 1]][1]- XY[i[k]][1]
        goukei+=(a**2+b**2)**0.5
print(goukei/count)

Measured memory_bytes: 47596
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<ll> vll;
typedef vector<vector<int>> vvi;
typedef vector<vector<string>> vvs;
typedef vector<vector<char>> vvc;
typedef vector<vector<bool>> vvb;
typedef pair<int,int> P;
#define vrep(v,n) for(int i=0;i<n;i++){cin >> v.at(i);} //配列vにn個の要素を入力する
#define rep(i, l, n) for (int i = l; i < (int)(n); i++)
#define repn(i, l, n) for (int i = l; i <= (int)(n); i++)
#define pb push_back 

const int mod = 1000000007;
const int inf = 1e9;

string rev(string s){
    string rev;
    rep(i,0,s.length()) rev += s[s.length()-1-i];
    return rev;
}

int main(){
    string s;
    cin >> s;
    cout << rev(s) << endl;
}


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

typedef long long ll;

using namespace std;

class UnionFind
{
	vector<ll> par, rank;
	vector<ll> sz;

public:
	UnionFind(ll n) {
		par = rank = vector<ll>(n);
		sz = vector<ll>(n);
			for (ll i = 0; i < n; i++) {
				par[i] = i;
				rank[i] = 0;
				sz[i] = 1;
			}
	}

	ll find(ll x) {
		if (x == par[x]) {
			return x;
		}
		else {
			return par[x] = find(par[x]);
		}
	}

	void unite(ll x, ll y) {
		x = find(x);
		y = find(y);
		if (x == y) {
			return;
		}
		if (rank[x] < rank[y]) {
			par[x] = y;
			sz[y] += sz[x];
		}
		else {
			par[y] = x;
			sz[x] += sz[y];
			if (rank[x] == rank[y]) {
				rank[x]++;
			}
		}
	}

	ll size(ll x) {
		if (x == par[x]) {
			return sz[x];
		}
		else {
			return sz[x] = sz[par[x]];
		}
	}
    
    ll parent(ll x){
        return par[x];
    }

	bool same(ll x, ll y) {
		return find(x) == find(y);
	}
};

int main()
{
	ll n, m;
	cin >> n >> m;
	vector<ll> a(m), b(m);
	UnionFind uf(n);
	ll ans = 0;
    vector<ll> anss(m);
	for (int i = 0; i < m; i++) {
		cin >> a[i] >> b[i];
        a[i]--;
        b[i]--;
    }
    for(int i = m - 1; i >= 0; i--){
		anss[i] = ans;
		if (!(uf.same(a[i], b[i]))) {
			ans += uf.size(a[i]) * uf.size(b[i]);
			uf.unite(a[i], b[i]);
		}
	}
    for(int i = 0; i < m; i++){
        cout << ans - anss[i] << endl;
    }
}

Measured memory_bytes: 6016
#include <iostream>
using namespace std;
int main(void){
    // Here your code !
    int a[4],b[4];
    
    while(cin>>a[0]>>a[1]>>a[2]>>a[3]>>b[0]>>b[1]>>b[2]>>b[3]){
    int hit=0,blo=0;
    
        for(int i=0;i<4;i++){
            if(a[i]==b[i]) hit++;
        }
        
        for(int i=0;i<4;i++){
                    for(int j=0;j<4;j++){
            if(a[i]==b[j]) blo++;
        }}
        
        cout<<hit<<" "<<blo-hit<<endl;
    }
}

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

int main(){
    double a,b,x;
    cin >> a >> b >> x;
    double s = x / a;
    double rad;
    if(s >= a*b/2){
        double h = (a*b-s)*2/a;
        rad = atan2(h,a);
    }else{
        double w = s*2/b;
        rad = atan2(b,w);
    }
    double PI = acos(-1);
    double deg = rad/(2*PI) * 360;
    printf("%.10f\n",deg);
}

Measured memory_bytes: 4120
#include <algorithm>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>

int main(int argc, char const* argv[]) {
    int N, K, ans;
    std::cin >> N >> K;
    ans = K * std::pow(K - 1, N - 1);
    std::cout << ans << '\n';
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1e18

int main() {
    int N;
    cin >> N;
    ll ans = 0;
    for (int i = 1; i <= N; i++)
        if (i % 3 != 0 && i % 5 != 0) ans += i;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3636
#define _USE_MATH_DEFINES
#include <algorithm>
#include <cstdio>
#include <functional>
#include <iostream>
#include <cfloat>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <vector>
#include <random>
#include <unordered_set>
#include <complex>
using namespace std;
 
#define rep(i, N) for (int i = 0; i < N; i++)
#define pb push_back
 
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> i_i;
typedef pair<ll, int> ll_i;
typedef pair<double, int> d_i;
typedef pair<ll, ll> ll_ll;
typedef pair<double, double> d_d;
struct edge { int u, v; ll w; };
// typedef complex<double> C;
 
ll MOD = 1000000007;
ll _MOD = 1000000009;
int INF = INT_MAX / 2;
double EPS = 1e-10;

int main() {
	int N, M; cin >> N >> M;
	vector<string> a(N), b(M);
	rep(y, N) cin >> a[y];
	rep(y, M) cin >> b[y];
	for (int y = 0; y + M <= N; y++)
		for (int x = 0; x + M <= N; x++) {
			bool ok = true;
			rep(i, M) rep(j, M) if (a[y + i][x + j] != b[i][j]) ok = false;
			if (ok) {
				cout << "Yes" << endl;
				return 0;
			}
		}
	cout << "No" << endl;

}


Measured memory_bytes: 256
A = []
B = []
C = []
s = 10
for _ in range(5):
  A.append(int(input()))
for a in A:
  s = a%10
  if s != 0:
    B.append(a-s+10)
    C.append(s)
  else:
    B.append(a)
if len(C) == 0:
  print(sum(A))
else:
  b = sum(B)
  print(b-10 +min(C))

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ll long long
#define fi first
#define se second
#define pb push_back
#define rep(i, s, n) for (int i = s; i < n; i++)
#define rrep(i, s, n) for (int i = (n)-1; i >= (s); i--)
#define all(a) a.begin(),a.end()
typedef pair<int,int>pint;
typedef vector<int>vint;
typedef vector<pint>vpint;
const long long MOD = 1000000007, INF = 1e17;
 
#define endl '\n'
#define IOS() ios_base::sync_with_stdio(0);cin.tie(0)
 
template<class T>inline bool chmax(T& a,T b){if(a<b){a=b;return true;}return false;}
template<class T>inline bool chmin(T& a,T b){if(a>b){a=b;return true;}return false;}
 
template<typename T>vector<T>
make_v(size_t a){return vector<T>(a);}
template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
	return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}
template<typename T,typename V>
typename enable_if<is_class<T>::value==0>::type
fill_v(T &t,const V &v){t=v;}
template<typename T,typename V>
typename enable_if<is_class<T>::value!=0>::type
fill_v(T &t,const V &v){
	for(auto &e:t) fill_v(e,v);
}

int A,B,C,D,E,F,G,N,M,R,Q,X,Y,Z;
string s,t;

signed main()
{
	IOS();
	cin>>N>>M;
	vector<int>l(M),r(M);
	int L=-INF,R=INF;
	rep(i,0,M)cin>>l[i]>>r[i];
	rep(i,0,M){
		chmax(L,l[i]);
		chmin(R,r[i]);
	}
	cout<<max(0ll,R-L+1)<<endl;
}

Measured memory_bytes: 1792
/* ex4_2
  terakura */

#include <stdio.h>
#include <math.h>

int main(void){
    double short_hund, long_hund, hour, minute, angle, area;
    scanf("%lf %lf %lf %lf", &short_hund, &long_hund, &hour, &minute );


//短針と０時０分が為す角は(時間/12)＊2π + (π/6の”分”ぶんの60)、長針と０時０分が為す角は(”分”ぶんの60)*2π
    angle = ((hour / 12  *  2 * M_PI) +( M_PI / 6 * minute / 60)) -(minute / 60) * 2 * M_PI ;     //短針と長針のなす角度(ラジアン)
    area = sqrt( pow(short_hund, 2) + pow(long_hund, 2) - 2 * short_hund * long_hund * cos(angle));     //余弦定理で面積を計算

    printf("%.20lf\n", area);

    return 0;
}


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

using namespace std;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(),v.end()
#define _GLIBCXX_DEBUG

using ll = long long;
using vi = vector<int>;
using vll = vector<ll>;
using vd = vector<double>;
using vvi = vector<vi>;
using vvll = vector<vll>;
using vvd = vector<vd>;
using vvvi = vector<vvi>;
using vvvll = vector<vvll>;
using vvvd = vector<vvd>;

const double pi=3.141592653589793;
const ll MOD=1e9+7;

template<class Abel> struct UnionFind {
    vector<int> par;
    vector<int> rank;
    vector<Abel> diff_weight;

    UnionFind(int n = 1, Abel SUM_UNITY = 0) {
        init(n, SUM_UNITY);
    }

    void init(int n = 1, Abel SUM_UNITY = 0) {
        par.resize(n); rank.resize(n); diff_weight.resize(n);
        for (int i = 0; i < n; ++i) par[i] = i, rank[i] = 0, diff_weight[i] = SUM_UNITY;
    }

    int root(int x) {
        if (par[x] == x) {
            return x;
        }
        else {
            int r = root(par[x]);
            diff_weight[x] += diff_weight[par[x]];
            return par[x] = r;
        }
    }

    Abel weight(int x) {
        root(x);
        return diff_weight[x];
    }

    bool issame(int x, int y) {
        return root(x) == root(y);
    }

    bool merge(int x, int y, Abel w) {
        w += weight(x); w -= weight(y);
        x = root(x); y = root(y);
        if (x == y) return false;
        if (rank[x] < rank[y]) swap(x, y), w = -w;
        if (rank[x] == rank[y]) ++rank[x];
        par[y] = x;
        diff_weight[y] = w;
        return true;
    }

    Abel diff(int x, int y) {
        return weight(y) - weight(x);
    }
};


int main() {
    ll n,m;
    cin>>n>>m;
    UnionFind<int> uf(n+1);
    rep(i,m){
        ll l,r,d;
        cin>>l>>r>>d;
        if (uf.root(r)!=uf.root(l)){
            uf.merge(l,r,d);
        }
        else{
            if (uf.diff(l,r)!=d){
                cout<<"No"<<endl;
                return 0;
            }
        }
    }
    cout<<"Yes"<<endl;

    return 0;
}

Measured memory_bytes: 1408
#include <iostream>

using namespace std;
#define MAX 500000
#define SENTINEL 2000000000

int L[MAX/2+2], R[MAX/2+2];
int cnt;

void merge(int A[],int n,int left, int mid, int right) {
  int n1 = mid -left;
  int n2 = right - mid;
  for(int i=0;i<n1;i++) L[i] = A[left + i];
  for(int i=0;i<n2;i++) R[i] = A[mid + i];
  L[n1] = R[n2] = SENTINEL;
  int i=0, j=0;
  for(int k=left; k<right; k++) {
    cnt++;
    if(L[i]<=R[j]) {
      A[k] = L[i++];
    } else {
      A[k] = R[j++];
    }
  }
}

void mergeSort(int A[],int n,int left,int right) {
  if(left+1 < right) {
    int mid = (left+right) / 2;
    mergeSort(A,n,left,mid);
    mergeSort(A,n,mid, right);
    merge(A,n,left,mid,right);
  }
}

int main(void) {
  int A[MAX], n, i;
  cnt = 0;

  cin >> n;
  for(i=0;i<n;i++) cin >> A[i];

  mergeSort(A, n, 0, n);
  for(i=0;i<n;i++) {
    if(i)cout << " ";
    cout << A[i];
  }
  cout << endl;

  cout << cnt << endl;

  return 0;
}

Measured memory_bytes: 6912
x, n = map(int, input().split());
if n == 0:
    print(x);
elif n == 1:
    b = int(input());
    if b == x:
        print(x-1);
    else:
        print(x);
else:
    a = list(map(int,input().split()));
    
    for i in range(n):
        if a.count(x-i) == 0:
            ooo = 1;
            break;
        if a.count(x+i) == 0:
            ooo = 2;
            break;
        
            
    if ooo == 1:
        print(x-i);
    else:
        print(x+i);

Measured memory_bytes: 9208
#include <bits/stdc++.h>
using namespace std;
#define rep(i, a, b) for (ll i = (a); i < (b); i++)
#define rep2(r, aa, bb) for (ll r = (aa)-1; r >= (bb); r--)
#define be(x) (x.begin(), x.end())
#define pb(t) push_back(t)
#define ll long long
#define mp(a, b) make_pair(a, b)
struct P{
	double x, y;
	void read(){
		cin>>x>>y;
	}
	double operator *(P b){
		return x*b.y-y*b.x;
	}
	P operator -(P b){
		return {x-b.x, y- b.y};
	}
	double dist(P b){
		return sqrt((y- b.y)*(y- b.y)+(x-b.x)*(x-b.x));
	}
};
int main(){
	cout<<fixed<<setprecision(20);
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    char C;
    cin>>C;
    cout<<(char)(C+1);
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <stdio.h>
#include <algorithm>
#define _USE_MATH_DEFINES
#include <cmath>
#include <numeric>
#include <iomanip>
#include <deque>
#include <tuple>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <sstream>
#include <stdexcept>
#include <boost/multiprecision/cpp_int.hpp>
#include <boost/multiprecision/cpp_dec_float.hpp>

#define rep(i, x) for (int i = 0; i < (int)(x); i++)
#define FOR(i, a, done) for (int i = (a); i < (done); ++i)
#define all(a) (a).begin(), (a).end()
#define F first
#define S second
#define x first
#define y second
#define pb push_back
#define pf push_front
#define debug(a) cout << (a) << endl
namespace mp = boost::multiprecision;
using cpp_int = mp::cpp_int;
using ll = long long;
using namespace std;

ll M = 1000000007;
const int MAX = 510000;
const int MOD = 1000'000'007;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算


/*int main() {
    // 前処理
    COMinit();

    // 計算例
    cout << COM(100000, 50000) << endl;
}*/

void solve()
{
	//COMinit();
	int n;
	cin>>n;
	vector<int>a(n);
	set<int>appr;
	map<int,ll>cnt;
	rep(i,n){
		cin>>a[i];
		appr.insert(a[i]);
		cnt[a[i]]++;
	}
	auto itr=appr.begin();
	vector<ll>app;
	while(itr!=appr.end()){
		app.push_back(*itr);
		itr++;
	}
	//cout<<"a";
	ll tmp=0;
	map<int,ll>dis,now;
	rep(i,app.size()){
		if(cnt[app[i]]>1){
			now[app[i]]=cnt[app[i]]*(cnt[app[i]]-1)/2;
			tmp+=cnt[app[i]]*(cnt[app[i]]-1)/2;
			if(cnt[app[i]]-1>1)
			dis[app[i]]=(cnt[app[i]]-1)*(cnt[app[i]]-2)/2;
		}
	}
	rep(i,n){
		ll ans=tmp-now[a[i]]+dis[a[i]];
		cout<<ans<<endl;
	}

	

}

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


Measured memory_bytes: 34036
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#include <tr1/unordered_map>
using namespace std;
#define ll long long
#define re register
#define pb push_back
#define fi first
#define se second
const int N=1e6+10;
const int M=1e6;
const int mod7=1e9+7;
const int mod=998244353;
void read(int &a)
{
    a=0;int d=1;char ch;
    while(ch=getchar(),ch>'9'||ch<'0')
        if(ch=='-')
            d=-1;
    a=ch^48;
    while(ch=getchar(),ch>='0'&&ch<='9')
        a=(a<<3)+(a<<1)+(ch^48);
    a*=d;
}
void read(ll &a)
{
    a=0;int d=1;char ch;
    while(ch=getchar(),ch>'9'||ch<'0')
        if(ch=='-')
            d=-1;
    a=ch^48;
    while(ch=getchar(),ch>='0'&&ch<='9')
        a=(a<<3)+(a<<1)+(ch^48);
    a*=d;
}
int main()
{
    double a;
    cin>>a;
    a=3.1415926*a*2;
    printf("%.20lf",a);
    return 0;
}

Measured memory_bytes: 3780
#include<bits/stdc++.h>
#define int int64_t
using namespace std;
string S;
int K;
main(){
  cin>>S>>K;
  int not_one=-1;
  for(int i=0;i<S.size();++i){
    if(S[i]!='1'){
      not_one=i;
      break;
    }
  }
  if(not_one==-1){
    if(K<=S.size()){
      cout<<1<<endl;
    }else{
      cout<<"undefined"<<endl;
    }
    return 0;
  }
  if(K-1<not_one){
    cout<<1<<endl;
  }else{
    cout<<S[not_one]<<endl;
  }
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#define bit(n,m)(((n)>>(m))&1)

int a[8];

void f(int l,int m,int r,int n){
	if(n==8){
		for(int i=0;i<8;i++){
			for(int j=0;j<8;j++)putchar(a[i]==j?'Q':'.');
			puts("");
		}
		exit(0);
	}
	if(a[n]!=-1){
		int t=1<<a[n];
		if(!bit(l|m|r,a[n]))f((l|t)<<1,(m|t),(r|t)>>1,n+1);
		return;
	}
	for(int j=0;j<8;j++)if(!bit(l|m|r,j)){
		a[n]=j;
		int t=1<<j;
		f((l|t)<<1,(m|t),(r|t)>>1,n+1);
		a[n]=-1;
	}
}

int main(){
	int n;
	scanf("%d",&n);
	for(int i=0;i<8;i++)a[i]=-1;	
	while(n--){
		int x,y;
		scanf("%d%d",&x,&y);
		a[x]=y;
	}
	f(0,0,0,0);
}


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

typedef long long ll;
#define int ll
#define pb push_back
// const int INF = 1e18;
const int inf = 1e9;
const int MOD = 998244353, MAX = 2e5+10;
int n,m,k, fact[MAX], ifact[MAX];

int exp(int a, int b){
	int res = 1;
	while(b){
		if (b&1)
			res = (res*a)%MOD;
		b>>=1;
		a = (a*a)%MOD;
	}
	return res;
}

int inv(int a){
	return exp(a,MOD-2);
}

void preprocess(){
	fact[0] = 1, ifact[0] = 1;
	for(int i=1;i<MAX;i++){
		fact[i] = (fact[i-1]*i)%MOD;
		ifact[i] = inv(fact[i]);
	}
}

int choose(int n, int k){
	if (k==0 or n==k)
		return 1;
	return (((fact[n]*ifact[k])%MOD)*ifact[n-k])%MOD;
}
signed main(){

	ios_base::sync_with_stdio(false);
	cin.tie(0);


	#ifndef ONLINE_JUDGE
		time_t t1 = clock(), t2;
		freopen("input.txt", "r", stdin);
		freopen("output.txt", "w", stdout);
		// freopen("err.txt", "w", stderr);
	#endif


	cin>>n>>m>>k;
	preprocess();
	int tot = 0;
	for(int i=0;i<=k;i++){
		int ans;
		if (i==0){
			ans = (m*exp(m-1,n-1))%MOD;
		}
		else{
			int c = choose(n-1,n-i-1);
			int d = (m*exp(m-1,n-i-1))%MOD;
			ans = (c*d)%MOD;
			// cout<<c<<" "<<d<<"\n";

		}

		tot = (tot+ans)%MOD;
		// cout<<tot<<"\n";
	}

	cout<<tot;
	
	return 0;
}

Measured memory_bytes: 6704
package main

import (
	"fmt"
)

func chmax(a *int, b int) bool {
	if *a < b {
		(*a) = b
		return true
	}
	return false
}

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

func main() {
	var s, t string
	fmt.Scan(&s)
	fmt.Scan(&t)

	var dp = make([][]int, len(s)+1)
	for i, _ := range dp {
		dp[i] = make([]int, len(t)+1)
	}

	for i := 0; i < len(s); i++ {
		for j := 0; j < len(t); j++ {
			if s[i] == t[j] {
				chmax(&dp[i+1][j+1], dp[i][j]+1)
			}
			chmax(&dp[i+1][j+1], dp[i+1][j])
			chmax(&dp[i+1][j+1], dp[i][j+1])
		}
	}

	var res []byte
	var i = len(s)
	var j = len(t)

	for i > 0 && j > 0 {
		if dp[i][j] == dp[i-1][j] {
			i--
		} else if dp[i][j] == dp[i][j-1] {
			j--
		} else {
			res = append([]byte{s[i-1]}, res...)
			i--
			j--
		}
	}

	fmt.Println(string(res))
}

Measured memory_bytes: 80512
from collections import defaultdict, deque
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate
import sys


def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LIM(): return list(map(lambda x:int(x) - 1, sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def S(): return sys.stdin.readline()
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def LIRM(n): return [LIM() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
mod = 1000000007


n = I()
num = LI()
ans = n
l = 0
r = 0
cnt = 0
ret = num[0]
while r < n-1:
    if ret & num[r+1] == 0:
        ret ^= num[r+1]
        cnt += 1
        r += 1
        ans += cnt
    elif l == r:
        l +=1; r += 1;
        ret = num[l]
    else:
        ret ^= num[l]
        cnt -= 1
        l += 1



print(ans)

Measured memory_bytes: 71756
#include<bits/stdc++.h>
using namespace std;
#define gcd(a,b) __gcd(a,b)

int func(int n){
	return (n*(n+1))/2;
}

signed main(){
	ios_base::sync_with_stdio(0);
	cin.tie(NULL);
	int n,ans=0;
	cin >> n;
	for(int i(1);i<=n;++i){
		for(int j(1);j<=n;++j){
			for(int k(1);k<=n;++k){
				ans+=gcd(gcd(i,j),k);
			}
		}
	}
	cout << ans;
	
}

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

int main(){
  int n;
  int num[2001] = {0};

  for(int i=0;i<=1000;i++)
    for(int j=0;j<=1000;j++)num[i+j]++;

  while(cin >> n){
    int res = 0;
    for(int i=0;i<=1000;i++){
      for(int j=0;j<=1000;j++){
	if(n-i-j<0 || n-i-j>2000)continue;
	res += num[n-i-j];
      }
    }
    cout << res << endl;
  }
}

Measured memory_bytes: 1168
#include<bits/stdc++.h>
using namespace std;
typedef long long int llint;
typedef long int lint;
typedef long long ll;
typedef vector<char> vchar;
typedef vector<long long> vll;
typedef vector<int> vint;
typedef vector<vector<int>> vvint;
typedef vector<vector<char>> vvchar;
#define vsort(v) sort((v).begin(), (v).end())
#define vreverse(v) reverse((v).begin(), (v).end())
#define pb(a) push_back(a)
#define INF 1000000007
#define MOD 1e9+7
int main(){
  //input
  int n;cin>>n;llint ans;
  ans=(180*(n-2));cout<<ans<<endl;
  //caricurate
  //output
}

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

#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define MIN(a) *min_element(all(a))
#define MAX(a) *max_element(all(a))
#define SUM(a, b) accumulate(all(a), b)
#define REP(i, n) for(int (i)=0; (i)<(n); (i)++)
#define RREP(i, n) for(int (i)=(n)-1; (i)>=0; (i)--)
#define FOR(i, m, n) for(int (i)=(m); (i)<(n); i++)
#define FORR(i, m, n) for(int (i)=(n)-1; (i)>=(m); i--)
#define ios() cin.tie(0), ios::sync_with_stdio(false)
#define debug(x) cerr << #x << " = " << x << endl
//#define int long long

typedef long long ll;
typedef unsigned long long ull;
//ll const MOD = 998244353;
ll const MOD = 1e9+7;
ll const INF = 1e18;

template<typename T> int size(const T& a){return (int)a.size();}
template<typename T> T Div(T a, T b){return (a + b - 1) / b;}
template<typename T> bool chmin(T& a, const T& b){if(a > b){a = b; return true;} return false;}
template<typename T> bool chmax(T& a, const T& b){if(a < b){a = b; return true;} return false;}



signed main(){
    ll w, h, x, y;
    cin >> w >> h >> x >> y;

    cout << fixed << setprecision(15) << (double) h * w / 2 << " ";
    cout << (2*x == w && 2*y == h ? 1 : 0) << endl;

    return 0;
}


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

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
	int n;
	cin>>n;
	int h[n];
	int i;
	for(i=0;i<n;i++)
	cin>>h[i];
	int dp[n];
	memset(dp,0,sizeof(dp));
	dp[0]=0;
	dp[1]=abs(h[0]-h[1]);
	for(i=2;i<n;i++)
	{
		dp[i]=min(dp[i-1]+abs(h[i]-h[i-1]),dp[i-2]+abs(h[i]-h[i-2]));
	}
	cout<<dp[n-1]<<endl;
	return 0;
}




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

using namespace std;

#define int long long
#define endl '\n'
#define MOD 1000000007
#define maxn 100010

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

    int n;
    cin >> n;

    vector<int> v(n);
    for (int i = 0; i < n; ++i) {
        cin >> v[i];
        v[i] -= i + 1;
    }
    sort(v.begin(), v.end());
    int b = v[n / 2], ans = 0;
    for (int j = 0; j < n; ++j) {
        ans += abs(v[j] - b);
    }
    cout << ans << endl;
}


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

ans = 1
for a in range(1, int(math.sqrt(M))):
    b = int(M / a)
    if M%a != 0:
        continue
    if a * N <= M:
        ans = max(ans, a)
    if b * N <= M:
        ans = max(ans, b)

print(ans)



Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
int main()
{int s[200],s1[200],n,m,x,y;
cin>>n>>m>>x>>y;
 for(int i=1;i<=n;i++)
    cin>>s[i];
 for(int i=1;i<=m;i++)
    cin>>s1[i];
 sort(s+1,s+1+n);
 sort(s1+1,s1+1+m);
 if(s[n]+1>s1[1])cout<<"War";
 else if(s1[1]>y&&s[n]+1<=y||s1[1]>x&&s1[1]<y)cout<<"No War";
 else cout<<"War";
}



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

int main() {
  int a1, a2, a3;
  cin >> a1 >> a2 >> a3;

  int sum;
  sum=a1+a2+a3;
  if(sum >= 22) cout << "bust" << endl;
  else cout << "win" << endl;

  return 0;
}


Measured memory_bytes: 3616
#include<bits/stdc++.h>
using namespace std;
using namespace std::chrono; 
#define ll long long
#define ld long double
#define fo(i,v,e) for(v=i;v<e;v++)
#define rfo(i,v,e) for(v=i;v>e;v--)
#define pb(x) push_back(x)
#define pll pair<ll,ll>
#define pii pair<int,int>
#define fi first 
#define se second
#define all(x) x.begin(),x.end()
#define vi vector<int>
#define vl vector<ll>
#define sz(x) (int)x.size()
#define ull unsigned long long
#define vvi vector<vi>
#define vvl vector<vl>
#define vpi vector<pii>
#define vpl vector<pll>
ll mod = 1000000007;
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}
 
template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#ifndef ONLINE_JUDGE
#define openfile freopen("input.txt","r",stdin); freopen("output.txt","w",stdout);
#define deb(x...) cerr << "[" << #x << "] = ["; _print(x);
#else
#define openfile
#define deb(x...)
#endif
void init()
{
    
}
void solve()
{
    ll n,m,k,i,j,ans = 0;cin>>n>>m>>k;
    vl A(n),B(m);
    fo(0,i,n)
    {
        cin>>A[i];
        if(i)A[i]+=A[i-1];
    }
    fo(0,i,m)
    {
        cin>>B[i];
        if(i)B[i]+=B[i-1];
    }
    // deb(A,B)
    fo(0,i,n+1)
    {
        if(i==0 or A[i-1]<=k)
        {
            ll temp = k-(i?A[i-1]:0);
            auto it = upper_bound(all(B),temp);
            ll tt = it-B.begin();
            // deb(i,temp,tt);
            ans = max(ans,i+tt);
        }
    }
    cout<<ans<<endl;
}
int main()
{
    init();
    // openfile;fastio;
    int T = 1;
    // cin>>T;
    while(T--)
    {
        solve();
    }
}

Measured memory_bytes: 6424
import java.util.*;

public class Main {

    static class Pair{
        public int x;
        public StringBuilder y;
        public Pair(int x,StringBuilder y) {
            this.x=x;
            this.y=y;
        }
        @Override
        public boolean equals(Object obj) {
            if(obj instanceof Pair) {
                Pair other = (Pair) obj;
                return other.x==this.x && other.y==this.y;
            }
            return false;
        }
        @Override
        public int hashCode() {
            return Objects.hash(this.x,this.y);
        }
    }

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        ArrayDeque<Pair> q = new ArrayDeque<Pair>();
        StringBuilder fst = new StringBuilder();
        fst.append('a');
        Pair first = new Pair(1, fst);
        q.add(first);
        for (int i=0;i<N-1;i++) {
            int cnt = q.size();
            // System.out.println(cnt);
            while (!q.isEmpty()) {
                Pair rem = q.poll();
                // System.out.println(rem.y);
                for (int j=0;j<rem.x+1;j++) {
                    StringBuilder add = new StringBuilder(rem.y);
                    add.append((char)((int)'a'+j));
                    int num = rem.x;
                    if (j==rem.x) num++;
                    Pair add_pair = new Pair(num, add);
                    q.add(add_pair);
                }
                cnt--;
                if (cnt==0) break;
            }
        }
        while (!q.isEmpty()) {
            Pair rem = q.poll();
            System.out.println(rem.y);
        }
    }
}

Measured memory_bytes: 60684
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define Would
#define you
#define please

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

	//解説を見て多少反省した

	int N, K;
	cin >> N >> K;

	int B[4000][4000] = {};
	int K2 = K * 2;

	rep(i, N) {
		int x, y;
		char c;
		cin >> x >> y >> c;

		if (c == 'W') x += K;
		B[x % K2][y % K2]++;
		B[x % K2 + K2][y % K2]++;
		B[x % K2][y % K2 + K2]++;
		B[x % K2 + K2][y % K2 + K2]++;
	}

	rep(i, 4 * K - 1) {
		rep(ii, 4 * K) {
			B[i + 1][ii] = B[i][ii] + B[i + 1][ii];
		}
	}
	rep(i, 4 * K) {
		rep(ii, 4 * K - 1) {
			B[i][ii + 1] = B[i][ii] + B[i][ii + 1];
		}
	}

	int saidai = 0;
	rep(i, K2) {
		rep(ii, K2) {
			int goukei = B[i][ii] - B[i + K][ii] - B[i][ii + K] + B[i + K][ii + K];
			goukei += B[i + K][ii + K] - B[i + K2][ii + K] - B[i + K][ii + K2] + B[i + K2][ii + K2];
			saidai = max(saidai, goukei);
		}
	}

	co(saidai);
	Would you please return 0;
}

Measured memory_bytes: 62720