akhauriyash/Code-Regression huggingface dataset:
/*
String[]の初期化、整数の型がlongになっているか
関数（splitとかcontainsとか）内では"+"とかは正規表現となされるので"\\+"とする
配列のコピーはarr1=arr.clone()
HashSet<>[]はおのおの初期化した？？？？？
負の数の割り算は絶対値が小さいほうに切り捨てられるex.-1/2=0ので、ある値>kみたいな式だとバグらせやすいので注意
ある値>=kとして、切り上げた値をとるべき
toLowerCase()はアルファベット以外に対して行ってもエラーにはならない
ArrayDequeではpopとpushはStackと同じ操作になる
//import static java.lang.System.*; はしばらく使わなそう(使うとしてもexit(0)のためだけ)←return;でよさそう
最後にout.flush()またはout.close()をするのを忘れずに！
Point2D p2d=new Point2D.Double(d1,d2);
*/
//入力終了→Ctrl+D
import java.util.*;
import java.io.*;
import java.awt.*;
import java.awt.geom.Point2D;
import static java.lang.Math.*;
public class Main {
    public static void main(String[] $) {
        int n = sc.nextInt();
        int[] x=new int[n];
        int[] y=new int[n];
        for (int i = 0; i < n; i++) {
            x[i]=sc.nextInt();
            y[i]=sc.nextInt();
        }
        HashSet<Point> PQ=new HashSet<>();
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < n; j++) {
                PQ.add(new Point(x[i]-x[j],y[i]-y[j]));
            }
        }
        int ans = n;
        for (Point pq : PQ) {
            int t = 0;
            if (pq.x == 0 && pq.y == 0) continue;
            for (int i = 0; i < n; i++) {
                for (int j = 0; j < n; j++) {
                    if(i==j)continue;
                    if (x[i] - x[j] == pq.x && y[i] - y[j]== pq.y) t++;
                }
            }
            if(ans>n-t)ans=n-t;
        }
        out.println(ans);
        out.close();
    }

    static PrintWriter out = new PrintWriter(System.out);

    static class sc {
        static Scanner s = new Scanner(System.in);

        static String next() {
            return s.next();
        }

        static String nextLine() {
            return s.nextLine();
        }

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

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

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

        static boolean hasNext() {
            return s.hasNext();
        }

        static boolean hasNextInt() {
            return s.hasNextInt();
        }

    }

}

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

int main() {
string S,T,U;
cin >> S>>T;
int a,b;cin>>a>>b>>U;
if(S.compare(U)==0) {cout<<a-1<<" "<<b<<endl;}else {cout<<a<<" "<<b-1<<endl;}
return 0;
}


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

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

using namespace std;

int main(void){
  int ans[3] = {1, 1, 1}, a, b;
  cin >> a >> b;
  ans[a-1] = 0;
  ans[b-1] = 0;
  rep(i, 3) if(ans[i]) cout << i+1 << endl;
  return 0;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

	public static void main(String[] args) throws NumberFormatException, IOException {
		// TODO 自動生成されたメソッド・スタブ

		int task1,task2,task3;
		int cost[] = new int[6];
		int ans=1000;

		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String str[] = br.readLine().split(" ");
		task1 = Integer.parseInt(str[0]);
		task2 = Integer.parseInt(str[1]);
		task3 = Integer.parseInt(str[2]);

		//1-2-3
		cost[0] = Math.abs(task1-task2)+Math.abs(task2-task3);
		//1-3-2
		cost[1] = Math.abs(task1-task3)+Math.abs(task3-task2);
		//2-1-3
		cost[2] = Math.abs(task2-task1)+Math.abs(task1-task3);
		//2-3-1
		cost[3] = Math.abs(task2-task3)+Math.abs(task3-task1);
		//3-1-2
		cost[4] = Math.abs(task3-task1)+Math.abs(task1-task2);
		//3-2-1
		cost[5] = Math.abs(task3-task2)+Math.abs(task2-task1);

		for(int i=0;i<6;i++) {
			if(ans > cost[i]) {
				ans = cost[i];
			}
		}

		System.out.println(ans);

	}

}


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

double Abs(double n) {
	if (n < 0) {
		n *= -1;
	}
	return n;
}

int main() {
	double n, t, a, h;
	int ans; double minabs = 1e9, old;
	cin >> n >> t >> a;
	for (int i = 0; i < n; i++) {
		cin >> h;
		old = minabs;
		minabs = min(minabs, Abs(t - h * 0.006 - a));
		if (minabs != old) {
			ans = i + 1;
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
def main(): 
    n = int(input())
    s = [''.join(sorted(input())) for _ in range(n)]
    ans = 0
    dic = {}
    for si in s:
        if si in dic:
            ans += dic[si]
            dic[si] += 1
        else:
            dic[si] = 1
    print(ans)


if __name__ == "__main__":
    main() 

Measured memory_bytes: 19400
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
const ll INF=1001001001;
const ll LINF=1001001001001001001;
#define overload4(_1,_2,_3,_4,name,...) name
#define rep1(n) for(ll i=0;i<(n);++i)
#define rep2(i,n) for(ll i=0;i<(n);++i)
#define rep3(i,a,b) for(ll i=(a);i<(b);++i)
#define rep4(i,a,b,c) for(ll i=(a);i<(b);i+=(c))
#define rep(...) overload4(__VA_ARGS__,rep4,rep3,rep2,rep1)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define vec vector<ll>
template<class T>bool chmax(T &a,const T &b){if(a<b){a=b;return 1;}return 0;}
template<class T>bool chmin(T &a,const T &b){if(b<a){a=b;return 1;}return 0;}

void solve(ll a, ll b){
    if(a>b)swap(a,b);
    rep(i,b){
        cout<<a;
    }
    cout<<endl;
}

int main(){
    ll a;
    scanf("%lld",&a);
    ll b;
    scanf("%lld",&b);
    solve(a, b);
    return 0;
}


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

using namespace std;

/*

        Bismillahir Rahmanir Rahim
        Problem :
        Problem Link :
        Topics :
        Solver : Masud Parves
        I Love Code More than Sharks Love Blood <3
*/


#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define SZ(a)           (int)a.size()
#define all(a)  a.begin(), a.end()
#define allr(a)  a.rbegin(), a.rend()


#define sf(a)           scanf("%d",&a)
#define sff(a,b)        scanf("%d %d",&a,&b)
#define sfff(a,b,c)     scanf("%d %d %d",&a,&b,&c)

#define f0(i,b) for(int i=0;i<(b);i++)
#define f1(i,b) for(int i=1;i<=(b);i++)
#define f2(i,a,b) for(int i=(a);i<=(b);i++)
#define fr(i,b,a) for(int i=(b);i>=(a);i--)

#define CIN ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL);
#define TEST_CASE(t) for(int zz=1 ; zz<=t ; zz++)
#define PRINT_CASE printf("Case %d: ",zz)
#define Debug(x)            cout<<#x " = "<<(x)<<endl
#define NOT_VISITED 0
#define IS_VISITED 1
#define WHITE 0
#define GRAY 1
#define BLACK 2



int fx[4]= {1,-1,0,0};
int fy[4]= {0,0,1,-1};

/*-----------------------Bitmask------------------*/
//int Set(int N,int pos){return N=N  (1<<pos);}
//int Reset(int N,int pos){return N= N & ~(1<<pos);}
//bool Check(int N,int pos){return (bool)(N & (1<<pos));}
/*------------------------------------------------*/


const double PI = acos(-1.0);
const double EPS = 1e-6;
const int MOD = (int)1e9+7;
const int maxn = (int)2e5+5;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef pair<ll, int> plli;
typedef pair<int, ll> pill;



int main() {
    CIN
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);

    int a,b;
    cin >> a >> b;

    if(a==1 && b!=1){
        cout << "Alice" << endl;
    }else if(a!=1 && b==1){
        cout << "Bob" << endl;
    }else if(a>b){
        cout << "Alice" << endl;
    }else if(b>a){
        cout << "Bob" << endl;
    }else {
        cout << "Draw" << 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;

vector<int> y[200005];
vector<int> ans;
void o(int a = 0,int n = -1) {
	for (int i : y[a]) {
		if (i == n) continue;
		ans.at(i) += ans.at(a);
		o(i, a);
	}
}

int main() {
	int n, q; cin >> n >> q;
	rep(i, n - 1) {
		int a, b; cin >> a >> b;
		a--; b--;
		y[a].push_back(b);
		y[b].push_back(a);
	}
	ans.resize(n, 0);
	rep(i, q) {
		int a, b; cin >> a >> b;
		ans.at(a - 1) += b;
	}
	o();
	for (int i : ans) cout << i << endl;
}

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

using namespace std;

typedef long long ll;

ll cr2(ll n)
{
	return ((n - 1) * n)/ 2 ;
}

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

	vector <ll> v(n), occ(n + 1);
	for (ll &x : v)
		cin >> x, occ[x]++;

	ll combiTotal = 0;
	for (int i = 1; i <= n; i++)
		combiTotal += cr2(occ[i]);
	
	for (int i = 0; i < n; i++)
	{
		ll c = combiTotal - cr2(occ[v[i]]);
		c += cr2(occ[v[i]] - 1);
		cout << c << "\n";
	}
	// cout << combiTotal << "\n";
	// for (int i = 0; i < n; i++)
	// {

	// }
	


}


// 10
// 33 18 45 28 8 19 89 86 2 4


// 2 4 8 18 19 28 33 45 86 89 
// 2  19 33 45 89

Measured memory_bytes: 5760
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define ll long long
#define sz(a) (int)(a.size())
#define pb push_back
#define all(c) c.begin(),c.end()
#define tr(it,a,c) for(auto it=c.begin()+a;it!=c.end();it++)
#define fr(i,a,n)	for(int i=a;i<n;i++)
#define present(c,x) (c.find(x)!=c.end()) //for set/map etc.
#define cpresent(c,x) (find(all(c),x)!=c.end())
typedef pair<int,int> pi;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<long long> vll;
typedef vector<pair<int,int>> vp;
int N=100001;
int mod=1e9+7;


int min(int a,int b){if(a<b) return a; else return b;}
int max(int a,int b){if(a>b) return a; else return b;}
int power(int a,int b){int res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
int gcd(int p, int q){if(p%q==0) return q; else{return gcd(q,p%q);}} 
bool comp(int a, int b) 
{ 
    return (a > b); 
}

bool comp1(pi a, pi b)
{
	if(a.first==b.first)return a.second<b.second;
	else return a.first>b.first;
}

template<typename T> 
istream& operator>>(istream& in, vector<T>& v)
{
	for (T& x : v) in >> x; return in;
}

template<typename T> 
ostream& operator<<(ostream& out, vector<T>& v)
{
	for (T& x : v) out << x<<" "; return out;
}

// template<typename T>
int sum1(vector<int>& v)
{
	int sum=0;
	// for(auto x: v)sum+=x;
	fr(i,0,v.size())sum+=v[i];
	return sum;
}





 void solve()
{
	string s;
	cin>>s;
	int sum=0;
	fr(i,0,s.size())
	{
		sum = sum + s[i]- '0';
	}
	if(sum%9==0)cout<<"Yes";
	else cout<<"No";

}

signed main()
{
	#ifndef ONLINE_JUDGE
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
	#endif
	// int t;
	// cin>>t;
	// while(t--)
	// {
	// 	solve();
	// 	cout<<endl;
	// }
	solve();
	return 0;	
}

Measured memory_bytes: 3760
#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
using namespace std;
typedef	long long ll;
typedef unsigned long long ull;
#define all(v) ((v).begin()),((v).end())
#define PI(n) ((double)acos(n))
#define clr0(n) (memset(n,0,sizeof n))
#define clr1(n) (memset(n,-1,sizeof n))
int dx8[8] = { 1, -1, 0, 0, 1, 1, -1, -1 };
int dy8[8] = { 0, 0, 1, -1, 1, -1, 1, -1 };
void file()
{
#ifndef ONLINE_JUDGE
	freopen("in.txt", "r", stdin);
	//freopen("out.txt", "w", stdout);
#else
	// online submission
#endif
}
void fast()
{
	std::ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL);
}
int main()
{
	fast();
	vector<vector<int>>v1(200001);

	int n, m;
	cin >> n >> m;
	for (int i = 0; i < m; i++){
		int u, v;
		cin >> u >> v;
		v1[u].push_back(v);
		v1[v].push_back(u);
	}
	for (int i = 0; i < (int)v1[1].size(); i++){
		int nxtnode = v1[1][i];
		bool ok = 0;
		for (int j = 0; j < (int)v1[nxtnode].size(); j++){
			int nxtnode1 = v1[nxtnode][j];
			if (nxtnode1 == n){
				ok = 1;
				break;
			}
		}
		if (ok){
			cout << "POSSIBLE" << endl;
			return 0;
		}
	}
	cout << "IMPOSSIBLE" << endl;
}

Measured memory_bytes: 12016
package main

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

type Edge struct {
	node int
	cost int
}

var edge [][]Edge
var ans []int

func dfs(node int) {
	for _, v := range edge[node] {
		if ans[v.node] != 0 {
			continue
		}
		ans[v.node] = 1
		dfs(v.node)
	}
}

func main() {
	sc := NewScanner()
	N, M := sc.NextInt(), sc.NextInt()
	ans = make([]int, N+1)
	edge = make([][]Edge, N+1)
	for i := 0; i < N; i++ {
		edge[i+1] = make([]Edge, 0)
	}

	for i := 0; i < M; i++ {
		A, B, C := sc.NextInt(), sc.NextInt(), sc.NextInt()
		edge[A] = append(edge[A], Edge{B, C})
		edge[B] = append(edge[B], Edge{A, C})
	}

	cnt := 0
	for i := 1; i <= N; i++ {
		if ans[i] == 0 {
			dfs(i)
			cnt++
			ans[i] = 1
		}
	}

	fmt.Println(cnt)
}

type Scanner struct {
	r   *bufio.Reader
	buf []byte
	p   int
}

func NewScanner() *Scanner {
	rdr := bufio.NewReaderSize(os.Stdin, 1000)
	return &Scanner{r: rdr}
}
func (s *Scanner) Next() string {
	s.pre()
	start := s.p
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			break
		}
	}
	result := string(s.buf[start:s.p])
	s.p++
	return result
}
func (s *Scanner) NextLine() string {
	s.pre()
	start := s.p
	s.p = len(s.buf)
	return string(s.buf[start:])
}
func (s *Scanner) NextInt() int {
	v, _ := strconv.Atoi(s.Next())
	return v
}
func (s *Scanner) NextInt64() int64 {
	v, _ := strconv.ParseInt(s.Next(), 10, 64)
	return v
}

func (s *Scanner) NextFloat() float64 {
	v, _ := strconv.ParseFloat(s.Next(), 64)
	return v
}

func (s *Scanner) NextIntArray() []int {
	s.pre()
	start := s.p
	result := []int{}
	for ; s.p < len(s.buf)+1; s.p++ {
		if s.p == len(s.buf) || s.buf[s.p] == ' ' {
			v, _ := strconv.ParseInt(string(s.buf[start:s.p]), 10, 0)
			result = append(result, int(v))
			start = s.p + 1
		}
	}

	return result
}
func (s *Scanner) NextInt64Array() []int64 {
	s.pre()
	start := s.p
	result := []int64{}
	for ; s.p < len(s.buf)+1; s.p++ {
		if s.p == len(s.buf) || s.buf[s.p] == ' ' {
			v, _ := strconv.ParseInt(string(s.buf[start:s.p]), 10, 64)
			result = append(result, v)
			start = s.p + 1
		}
	}
	return result
}

func (s *Scanner) NextMap() map[int]bool {
	s.pre()
	start := s.p
	mp := map[int]bool{}
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			v, _ := strconv.Atoi(string(s.buf[start:s.p]))
			mp[v] = true
			start = s.p + 1
		}
	}
	v, _ := strconv.Atoi(string(s.buf[start:s.p]))
	mp[v] = true

	return mp
}

func (s *Scanner) pre() {
	if s.p >= len(s.buf) {
		s.readLine()
		s.p = 0
	}
}
func (s *Scanner) readLine() {
	s.buf = make([]byte, 0)
	for {
		l, p, e := s.r.ReadLine()
		if e != nil {
			panic(e)
		}
		s.buf = append(s.buf, l...)
		if !p {
			break
		}
	}
}


Measured memory_bytes: 37632
#include <bits/stdc++.h>
using namespace std;
int N, result;
char word[105];

int main()
{
    scanf("%d %s", &N, word);
    for(int i = 0; i < N / 2; i++)
    {
        if(word[i] != word[N / 2 + i])
            result = 1;
    }
    if(result == 1 || N % 2 == 1)
        printf("No");
    else
        printf("Yes");
}

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

int N, x;
int a[110];

int main(){
  cin >> N >> x;
  for(int i=0; i<N; ++i){
    cin >> a[i];
  }
  sort(a, a+N);
  int counter =0;
  while(true){
    bool flag =false;
    x -= a[counter];
    if (x <0 || (counter ==N && x <1)) flag =true;
    if (counter ==N && x >0) {
      counter -=1;
      flag = true;
    }
    if (flag==true) break;
    ++counter;
  }
  cout << counter << endl;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define N 200100
#define M 1000000007
using namespace std;

ll n,m,mx,ans,dp[N],qz[N];
char str[N];

inline void Add(ll &u,ll v){u=(u+v)%M;}
int main()
{
    ll i,j,t;
    cin>>n>>m;
    scanf("%s",str+1);
    for(i=1;i<=m;i++) if(str[i]!=str[1]) break;
    mx=i-1;
    if(mx==m)
    {
	dp[0]=qz[0]=ans=1;
	for(i=0;i<=n;i++)
	{
	    if(i>=2) dp[i]=qz[i-2];
	    qz[i]=(qz[i-1]+dp[i])%M;
	    if(n-i>=2) Add(ans,dp[i]*(n-i)%M);
	}
	cout<<ans;
	return 0;
    }
    if(n&1)
    {
	puts("0");
	return 0;
    }
    if(mx%2==0) mx++;
    for(t=0;i<=m;i++)
    {
	if(str[i]==str[1]) t++;
	else
	{
	    if(t&1) mx=min(mx,t);
	    t=0;
	}
    }
    n/=2,mx=(mx+1)/2;
    dp[0]=qz[0]=1;
    for(i=0;i<=n;i++)
    {
	if(i)
	{
	    dp[i]=(M+qz[i-1]-(i-mx-1>=0?qz[i-mx-1]:0))%M;
	    qz[i]=(qz[i-1]+dp[i])%M;
	}
	if(n-i<=mx) Add(ans,(n-i)*dp[i]*2%M);
    }
    cout<<ans;
}


Measured memory_bytes: 3584
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define REP(i, n) FOR(i, 0, (n))
#define FOR(i, a, b) for(int i=(a); i<(b); i++)
#define LAR(a, b) ((a)=max((a),(b)))
#define SML(a, b) ((a)=min((a),(b)))
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<pair<int, int>> vpii;
typedef pair<int, int> pii;
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define ALL(a) (a).begin(), (a).end()
#ifdef LOCAL_DEBUG
#define DEBUG(...) printf(__VA_ARGS__)
#else
#define DEBUG(...)
#endif

#define MOD 1'000'000'007LL
#define N 512
int a[N], b[N];
ll s[N][N], t[N][N] = {};

int main(){
	int n, c; scanf("%d%d", &n, &c);
	REP(i, n) scanf("%d", a+i);
	REP(i, n) scanf("%d", b+i);

	REP(i, N) {
		// s[i][j] = i^j
		s[i][0] = 1;
		FOR(j, 1, N) s[i][j] = s[i][j-1] * i % MOD;
	}
	REP(j, N) {
		// s[i][j] = \sum_{k = 0}^{i} k^j
		FOR(i, 1, N) s[i][j] =(s[i][j] + s[i-1][j]) % MOD;
		// \sum_{ x=a }^{b} x^y = s[b][y] - s[a-1][y] (a > 0)
	}
	
	t[n][0] = 1;
	for(int i = n-1; i >= 0; i--){
		REP(j, N){
			REP(k, j+1){
				t[i][j] += (s[b[i]][k] - s[a[i]-1][k] + MOD) * t[i+1][j-k];
				t[i][j] %= MOD;
			}
		}
	}
	printf("%lld\n", t[0][c]);
}


Measured memory_bytes: 3840
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
typedef map <ll,ll> mm;
typedef vector <ll> mv;
typedef pair <ll,ll> mp;
typedef set <ll> ms;
typedef queue <ll> mq;
typedef deque <ll> mdq;
typedef stack <ll> mst;
typedef priority_queue <ll> mpq;
typedef priority_queue <ll, vector<ll>, greater<ll> > mmh;
typedef complex<double> cd; 
#define fastio ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define flush cout.flush();
#define all(v) v.begin(),v.end()
#define pb(v) push_back(v)
#define cn continue
#define forl(i,n) for(ll i=0;i<n;i++)
#define forlr(i,n) for(ll i=n-1;i>=0;i--)
#define rev(s) reverse(s.begin(),s.end())
void swap(ll &a,ll &b)
{
	ll tmp=a;
	a=b;
	b=tmp;
}
ll atoistring(string s)
{
	stringstream lol(s);
	ll x;
	lol>>x;
	return x;
}
void pv(mv v)
{
	forl(i,v.size())
	{
		cout<<v[i]<<" ";
	}
	cout<<"\n";
}
void pa(ll *v,ll size)
{
	forl(i,size)
	{
		cout<<v[i]<<" ";
	}
	cout<<"\n";
}
// ll nck(ll N,ll K,ll mod)
// {
// 	if(N<K)
// 	{
// 		return 0;
// 	}
// 	return (((facs[N]*facsinv[N-K])%mod)*facsinv[K])%mod;
// }
ll power(ll x,ll y,ll p)
{
	ll res=1;
	x=x%p;
	while(y>0)
	{
		if(y&1)
		{
			res=(res*x)%p;
		}
		y=y>>1;
		x=(x*x)%p;
	}
	return res;
}
void checkmod(ll &x,ll mod)
{
	if(x>=mod)
	{
		x%=mod;
	}
}
ll sumofgp(ll a,ll n,ll m)
{
	// n = number of terms - 1
	if(n<0)
	{
		return 0;
	}
	if(n==0)
	{
		return 1;
	}
	if(n==1)
	{
		return (1+a)%m;
	}
	ll ans;
	if(n%2)
	{
        ans=(1+a)*sumofgp((a*a)%m,(n-1)/2,m);
	}
    else
    {
        ans=1+((a*(1+a))%m)*sumofgp((a*a)%m,n/2-1,m);
    }
    return ans%m;
}
ll power_of_2_not_less(ll n)
{
	if(!n)
	{
		return 1;
	}
	n--;
	n |= n>>1;
	n |= n>>2;
	n |= n>>4;
	n |= n>>8;
	n |= n>>16;
	n |= n>>32;
	n++;
	return n;
}
// void checktime()
// {
// 	struct timespec ts;
// 	printf("Running Program\n");
// 	clock_gettime(CLOCK_MONOTONIC_RAW,&ts);
// 	long double st=ts.tv_nsec/(1e9)+ts.tv_sec;
// 	// Call Funcn Here
// 	clock_gettime(CLOCK_MONOTONIC_RAW,&ts);
// 	long double en=ts.tv_nsec/(1e9)+ts.tv_sec;
// 	printf("Program ended\nTime = %Lf\n",en-st);
// }
ll cnt[200005];
mv v;
int main(void)
{
	fastio
	ll n;
	cin>>n;
	forl(i,n)
	{
		ll x;
		cin>>x;
		cnt[x] ++ ;
		v.pb(x);
	}
	ll ans = 0;
	forl(i,2e5+1)
	{
		ans += (cnt[i]*(cnt[i]-1))/2;
	}
	forl(i,n)
	{
		ll lol = ans;
		lol -= (cnt[v[i]]*(cnt[v[i]]-1))/2;
		lol += ((cnt[v[i]]-1)*(cnt[v[i]]-2))/2;
		cout<<lol<<"\n";
	}
	return 0;
}

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

int a[200001],b[200001];
bool reachable[1001][1001];
bool visit[1001];
vector<pair<int,int> > edge[1001];

void dfs(int x){
	visit[x]=true;
	for(auto it:edge[x])
		if(!visit[it.first])
			dfs(it.first);
}

int minmark[1001][1001],maxmark[1001][1001];
void dfs2(int from,int x,int stp){
	minmark[from][x]=stp;
	for(int i=0;i<edge[x].size();i++)
		if(!minmark[from][edge[x][i].first])
			dfs2(from,edge[x][i].first,stp);
}
void dfs3(int from,int x,int stp){
	maxmark[from][x]=stp;
	for(int i=edge[x].size()-1;i>=0;i--)
		if(!maxmark[from][edge[x][i].first])
			dfs3(from,edge[x][i].first,stp);
}
int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int n,m;
	cin>>n>>m;
	for(int i=1;i<=m;i++){
		cin>>a[i]>>b[i];
		edge[a[i]].emplace_back(make_pair(b[i],i));
	}
	for(int i=1;i<=n;i++){
		memset(visit,0,sizeof visit);
		dfs(i);
		for(int j=1;j<=n;j++)
			reachable[i][j]=visit[j];
	}
	for(int i=1;i<=n;i++){
		minmark[i][i]=-1;
		for(int j=0;j<edge[i].size();j++)
			if(!minmark[i][edge[i][j].first])
				dfs2(i,edge[i][j].first,edge[i][j].second);
	}
	for(int i=1;i<=n;i++){
		maxmark[i][i]=-1;
		for(int j=edge[i].size()-1;j>=0;j--)
			if(!maxmark[i][edge[i][j].first])
				dfs3(i,edge[i][j].first,edge[i][j].second);
	}
	for(int i=1;i<=m;i++){
		if(reachable[b[i]][a[i]]){
			if((minmark[a[i]][b[i]]==i||minmark[a[i]][b[i]]==0)&&(maxmark[a[i]][b[i]]==i||maxmark[a[i]][b[i]]==0))
				cout<<"diff"<<'\n';
			else
				cout<<"same"<<'\n';
		}
		else{
			if((minmark[a[i]][b[i]]==i||minmark[a[i]][b[i]]==0)&&(maxmark[a[i]][b[i]]==i||maxmark[a[i]][b[i]]==0))
				cout<<"same"<<'\n';
			else
				cout<<"diff"<<'\n';
		}
	}
}


Measured memory_bytes: 14720
#include <iostream>
#include <cmath>
#include <algorithm>
using namespace std;

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

  int* heights;
  heights = new int[n];



  for (int i = 0; i < n; i++) {
    cin >> heights[i];
  }

  int* dp;
  dp = new int[n];

  dp[0] = 0;
  dp[1] = abs(heights[0] - heights[1]);

  for (int i = 2; i < n; i++) {
    dp[i] = min(dp[i-1] + abs(heights[i-1] - heights[i]), dp[i-2] + abs(heights[i-2]-heights[i]));
  }

  cout << dp[n-1] << endl;
  return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define mod 998244353
#define int long long
using namespace std;
const int N=3010;
int n,s,a[N],ans,dp[2][N];
signed main()
{
	scanf("%lld%lld",&n,&s);
	for (int i=1;i<=n;i++)
	  scanf("%lld",&a[i]);
	int cur=0;
	for (int i=1;i<=n;i++)
	{
		if (a[i]>s) continue;
		if (a[i]==s)
		{
			ans=(ans+i*(n-i+1)%mod)%mod;
			continue;
		}
		ans=(ans+dp[cur^1][s-a[i]]*(n-i+1)%mod)%mod;
		for (int j=1;j<s-a[i];j++)
		  dp[cur][j+a[i]]=(dp[cur][j+a[i]]+dp[cur^1][j])%mod;	
		dp[cur][a[i]]=(dp[cur][a[i]]+i)%mod;
		cur^=1;
		for (int j=0;j<s;j++) dp[cur][j]=dp[cur^1][j];
	}
	printf("%lld\n",ans);
}

Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
#include<math.h>
int main(){
 char s[11],t[12];
 scanf("%s %s",s,t);
 int len1=strlen(s);
 int len2=strlen(t);
 int a;
 for(a=0;a<len1;a++)
   if(s[a]!=t[a]){
     puts("No");return 0;}
 if(len2==len1+1)puts("Yes");
 else puts("No");
return 0;}

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

int main(void) {
   int n;
   
   char j[4] = "JPY";
   char b[4] = "BTC";
   scanf("%d", &n);

   double sum = 0.0;
   char coin[4];
   double money;

   for(int i = 0; i < n; i++) {
      scanf("%lf %s", &money, coin);
      if(strcmp(coin, j) == 0) {
         sum += money;
      } else if(strcmp(coin, b) == 0) {
         sum += money * 380000.0;
      }
   }

   printf("%f\n", sum);

   return 0;
}


Measured memory_bytes: 128
#include<stdio.h>
int a, b, x, m;
int main(void){
	scanf("%d%d", &a, &b);
	m=a+b;
	x=a-b;
	if(x>m){m=x;}
	x=a*b;
	if(x>m){m=x;}
	printf("%d\n", m);
}


Measured memory_bytes: 128
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<functional>
#include<iomanip>
#include<iostream>
#include<list>
#include<map>
#include<queue>
#include<random>
#include<set>
#include<stack>
#include<string>
#include<utility>
#include<vector>

#define FOR(i,a,b) for(long long i=(a);i<(b);++i)
#define rep(i,n)   FOR(i,0,n)
#define FORR(i,a,b) for(long long i=(a);i>=(b);--i)
#define REPR(i,n)   FORR(i,n,0)

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

ll n,a[30][30];
ll dp[30][1<<21]={0};
ll modp=1e+9+7;

ll cal(ll i,ll S){
    if(dp[i][S]!=-1){
        return dp[i][S];
    }
    ll res=0;
    rep(j,n){
        int k=(S>>j);
        if((k&1)&&a[i-1][j]==1){
            res+=cal(i-1,S-((k&1)<<j));
        }
    }
    return dp[i][S]=res%modp;
}

signed main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
	cin>>n;
    rep(i,n){
        rep(j,n){
            cin>>a[i][j];
        }
    }

    rep(i,n+1){
        rep(j,1<<n){
            dp[i][j]=-1;
            if(i==0){
                dp[i][j]=0;
            }
        }
    }
    dp[0][0]=1;
	
    cout<<cal(n,(1<<n)-1)<<endl;
	
    /*
    rep(i,n+1){
        rep(j,1<<n){
            cout<<dp[i][j]<<" ";
        }
        cout<<endl;
    }
    */

	return 0;
}


Measured memory_bytes: 362752
//
// Created by yamunaku on 2019/11/09.
//

#include <bits/stdc++.h>

using namespace std;

#define rep(i, n) for(int i = 0; i < (n); i++)
#define repl(i, l, r) for(int i = (l); i < (r); i++)
#define per(i, n) for(int i = ((n)-1); i >= 0; i--)
#define perl(i, l, r) for(int i = ((r)-1); i >= (l); i--)
#define all(x) (x).begin(),(x).end()
#define MOD9 998244353
#define MOD1 1000000007
#define IINF 1000000000
#define LINF 1000000000000000000
#define SP <<" "<<
#define CYES cout<<"Yes"<<endl
#define CNO cout<<"No"<<endl
#define CFS cin.tie(0);ios::sync_with_stdio(false)
#define CST(x) cout<<fixed<<setprecision(x)

using ll = long long;
using ld = long double;
using vi = vector<int>;
using mti = vector<vector<int>>;
using vl = vector<ll>;
using mtl = vector<vector<ll>>;
using pi = pair<int, int>;
using pl = pair<ll, ll>;
template<typename T>
using heap = priority_queue<T, vector<T>, function<bool(const T, const T)>>;

int main(){
    // CFS;
    ll n, k;
    cin >> n >> k;
    ll x = n + n / 2;
    if(k > 2 * n - x){
        cout << -1 << endl;
        return 0;
    }
    rep(i, (n + 1) / 2){
        cout << i + k SP i + x + k SP 2 * n + 2 * i + k << endl;
    }
    rep(i, n / 2){
        cout << (n + 1) / 2 + i + k SP (n + 1) / 2 + i + n / 2 + k SP 2 * n + 2 * i + 1 + k << endl;
    }
    return 0;
}

Measured memory_bytes: 2304
// #pragma GCC optimize("Ofast")

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pdd;

const int maxN = 150010;
const int MAXM = 310;
const int MAXK = 17;
const int MOD = 1000000007;
const ll INF = 10000000000000000LL;
const ll inf = 5000000000000LL;

int n;

int a[maxN];
char b[maxN];

int main()
{
    scanf("%d", &n);
    double ans;
	for(int i=1;i<=n;i++)
	{
		double x;
		scanf("%lf",&x);
		scanf("%s",b+1);
		if(b[1] == 'B')
		{
			ans += x*380000.0;
		}
		else
		{
			ans += x;
		}
	}
	printf("%f\n",ans);
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

#define TATE 12
#define YOKO 12
#define ZERO 0

int map[TATE][YOKO] = {ZERO};

void inkpaint1(int x, int y);
void inkpaint2(int x, int y);
void inkpaint3(int x, int y);
void result(void);

int main(void)
{
    int x,y,s;

    while (scanf("%d,%d,%d", &x, &y, &s) != EOF)
    {
        switch (s)
        {
            case 1:
            inkpaint1(x+2, y+2);
            break;

            case 2:
            inkpaint2(x+2, y+2);
            break;

            case 3:
            inkpaint3(x+2, y+2);
            break;
        }
    }
    result();
    
    return (0);
}
void inkpaint1(int x, int y)
{
    map[x][y] += 1;
    map[x - 1][y] += 1;
    map[x + 1][y] += 1;
    map[x][y + 1] += 1;
    map[x][y - 1] += 1;
}
void inkpaint2(int x, int y)
{
    inkpaint1(x, y);
    map[x - 1][y - 1] += 1;
    map[x - 1][y + 1] += 1;
    map[x + 1][y - 1] += 1;
    map[x + 1][y + 1] += 1;
}
void inkpaint3(int x, int y)
{
    inkpaint2(x, y);
    map[x][y - 2] += 1;
    map[x][y + 2] += 1;
    map[x - 2][y] += 1;
    map[x + 2][y] += 1;
}
void result(void)
{
    int i,j;
    int white,black;

    white = black = 0;

    for (i = 2; i < 12; i++){
        for (j = 2; j < 12; j++){
            if(map[i][j] == 0){
                white++;
            }
            if (black < map[i][j]){
                black = map[i][j];
            }
        }
    }
    printf("%d\n", white);
    printf("%d\n", black);
}


Measured memory_bytes: 2048
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <cassert>
using namespace std;
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
typedef vector<int> VI;
typedef long long ll;
typedef pair<int,int> PII;
const ll mod=1000000007;
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
// head

typedef double db;
db eps=1e-9;
struct point {
	db x,y;
	point() {}
	point(db x,db y):x(x),y(y) {}
	void input() { scanf("%lf%lf",&x,&y); }
	void output() { printf("%.10f %.10f\n",x,y); }
	db len() { return sqrt(x*x+y*y); }
	db len2() { return x*x+y*y; }
};
point operator + (const point &a,const point &b) { return point(a.x+b.x,a.y+b.y);}
point operator - (const point &a,const point &b) { return point(a.x-b.x,a.y-b.y);}
point operator * (const point &a,const db &b) { return point(a.x*b,a.y*b);}
point operator / (const point &a,const db &b) { return point(a.x/b,a.y/b);}
db dot(const point &a,const point &b) { return a.x*b.x+a.y*b.y; }
db det(const point &a,const point &b) { return a.x*b.y-a.y*b.x; }
struct line {
	point a,b;
	line() {}
	line(point a,point b):a(a),b(b) {}
};
point proj(const line &a,const point &b) {
	return a.a+(a.b-a.a)*dot(a.b-a.a,b-a.a)/(a.b-a.a).len2();
}
point reflect(const line &a,const point &b) {
	return proj(a,b)*2-b;
}
int sign(db x) {
	return fabs(x)<eps?0:(x>0?1:-1);
}
int relation(const line &a,const point &b) {
	int x=sign(det(a.b-a.a,b-a.a));
	if (x==1) return 0; // COUNTER_CLOCKWISE ?????¶???
	else if (x==-1) return 1; // CLOCKWISE ?????¶???
	else {
		x=sign(dot(b-a.a,a.b-a.a));
		if (x==-1) return 2; // ONLINE_BACK
		else {
			x=sign(dot(b-a.b,a.b-a.a));
			if (x==1) return 3; // ONLINE_FRONT
			else return 4; // ON_SEGMENT
		}
	}
}
bool parallel(const line &a,const line &b) { return sign(det(a.a-a.b,b.a-b.b))==0;}
bool ismiddle(const line &a,const point &b) {
	return sign(dot(b-a.a,a.b-a.a))>=0&&sign(dot(b-a.b,a.b-a.a))<=0;
}
int segcrossseg(const line &a, const line &b) {
	if (sign(min(b.a.x,b.b.x)-max(a.a.x,a.b.x))==1) return 0;
	if (sign(max(b.a.x,b.b.x)-min(a.a.x,a.b.x))==-1) return 0;
	if (sign(min(b.a.y,b.b.y)-max(a.a.y,a.b.y))==1) return 0;
	if (sign(max(b.a.y,b.b.y)-min(a.a.y,a.b.y))==-1) return 0;
	int d1=sign(det(a.b-a.a,b.a-a.a))*sign(det(a.b-a.a,b.b-a.a));
	int d2=sign(det(b.b-b.a,a.a-b.a))*sign(det(b.b-b.a,a.b-b.a));
	if (d1==-1&&d2==-1) return 2; // ?§??????????
	else if (d1<=0&&d2<=0) return 1; // ????§??????????
	else return 0; // ?????????
}

int q;
int main() {
	scanf("%d",&q);
	rep(i,0,q) {
		point p1,p2,q1,q2;
		p1.input(); p2.input(); q1.input(); q2.input();
		puts(segcrossseg(line(p1,p2),line(q1,q2))>=1?"1":"0");
	}
}

Measured memory_bytes: 2756
import java.io.*;
import java.util.*;

public class Main {
  private static int s(int n) {
    int sum = 0;
    while (n > 0) {
      sum += n % 10;
      n /= 10;
    }
    return sum;
  }
  
  private static boolean solve(int n) {
    return n % s(n) == 0;
  }
  
  private static void execute(ContestReader reader, PrintWriter out) {
    int n = reader.nextInt();
    out.println(solve(n) ? "Yes" : "No");
  }
  
  public static void main(String[] args) {
    ContestReader reader = new ContestReader(System.in);
    PrintWriter out = new PrintWriter(System.out);
    execute(reader, out);
    out.flush();
  }
}

class ContestReader {
  private BufferedReader reader;
  private StringTokenizer tokenizer;
  
  ContestReader(InputStream in) {
    reader = new BufferedReader(new InputStreamReader(in));
  }
  
  public String next() {
    while (tokenizer == null || !tokenizer.hasMoreTokens()) {
      try {
        tokenizer = new java.util.StringTokenizer(reader.readLine());
      } catch (Exception e) {
        throw new RuntimeException(e);
      }
    }
    return tokenizer.nextToken();
  }
  
  public int nextInt() {
    return Integer.parseInt(next());
  }
  
  public long nextLong() {
    return Long.parseLong(next());
  }
  
  public double nextDouble() {
    return Double.parseDouble(next());
  }
  
  public String[] next(int n) {
    String[] array = new String[n];
    for (int i = 0; i < n; i++) {
      array[i] = next();
    }
    return array;
  }
  
  public int[] nextInt(int n) {
    int[] array = new int[n];
    for (int i = 0; i < n; i++) {
      array[i] = nextInt();
    }
    return array;
  }
  
  public long[] nextLong(int n) {
    long[] array = new long[n];
    for (int i = 0; i < n; i++) {
      array[i] = nextLong();
    }
    return array;
  }
  
  public double[] nextDouble(int n) {
    double[] array = new double[n];
    for (int i = 0; i < n; i++) {
      array[i] = nextDouble();
    }
    return array;
  }
  
  public char[] nextCharArray() {
    return next().toCharArray();
  }
  
  public int[][] nextInt(int n, int m) {
    int[][] matrix = new int[n][m];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        matrix[i][j] = nextInt();
      }
    }
    return matrix;
  }
  
  public long[][] nextLong(int n, int m) {
    long[][] matrix = new long[n][m];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        matrix[i][j] = nextLong();
      }
    }
    return matrix;
  }
  
  public double[][] nextDouble(int n, int m) {
    double[][] matrix = new double[n][m];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        matrix[i][j] = nextDouble();
      }
    }
    return matrix;
  }
  
  public char[][] nextCharArray(int n) {
    char[][] matrix = new char[n][];
    for (int i = 0; i < n; i++) {
      matrix[i] = next().toCharArray();
    }
    return matrix;
  }
}


Measured memory_bytes: 20948
#include <iostream>
#include <string>
#include <sstream>
using namespace std;
int main(){
    int a,b,c,count=0;
    stringstream s;
    while(cin>>a>>b){
    c=a+b;
    s<<c;

    for(int i=0;i<s.str().size();i++){
        count++;
    }
    cout<<count<<endl;
        s.str("");
        count=0;
    }
    
    return 0;
}

Measured memory_bytes: 3160
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<ll>;
using vs = vector<string>;
#define  rep(i,n) for(ll i = 0; i < (n); ++i)
#define  red(i,n) for(ll i = (n)-1; i >= 0; --i)
#define  all(a)   begin(a),end(a)
#define  pb(a)    push_back(a)
#define  yn(a)    cout << ( (a)?"Yes\n":"No\n" )
inline ll gcd(ll a,ll b) { return b?gcd(b,a%b):a; }

int main()
{
    int a,x;
    cin>>a>>x;
    yn(a*500>=x);
}

Measured memory_bytes: 384
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
using namespace std;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define vi vector<int>
#define vivi vector<vi>
const int INF = 1<<29;
typedef long long ll;



int dp[100][2][100];//dp[keta][未満である][0でない数の個数]


struct UnionFind {
  vi parent;
  UnionFind(int N) : parent(N) {
    rep(i, N)parent[i] = i;
  }

  int getRoot(int child){
    return ((parent[child] == child) ? child : parent[child] = getRoot(parent[child]));
  }
  void unite(int x, int y){
    int root_x = getRoot(x);
    int root_y = getRoot(y);
    if(root_x == root_y)return;
    parent[root_x] = parent[root_y];
  }
  bool isSame(int x, int y){
    return getRoot(x) == getRoot(y);
  }
};
int main(){
  int N, M;cin >> N >> M;
  UnionFind U(N);
  vi P(N);
  for(int i = 0;i < N;++i){
    cin >> P[i];
    --P[i];
  }
  for(int i = 0;i < M;++i){
    int x, y;cin >> x >> y;
    U.unite(x - 1, y - 1);
  }
  int cnt = 0;
  rep(i, N){
    if(U.isSame(i, P[i]))++cnt;
  }
  cout << cnt;
}


Measured memory_bytes: 1024
#include <stdio.h>

int main(void){
    int a,b;
    char op;
    while(1){
        scanf("%d %c %d",&a,&op,&b);
        if(op=='?') break;
        if(op=='+') printf("%d\n",a+b);
        else if(op=='-') printf("%d\n",a-b);
        else if(op=='*') printf("%d\n",a*b);
        else if(op=='/') printf("%d\n",a/b);
    }
    return 0;
}


Measured memory_bytes: 2052
#include<bits/stdc++.h>
using namespace std;
int main() {
	int n, r, a, b, temp, s=0, t=0;
	while(1){
		cin >> n >> r;
		int p[n];
		if(n==0 && r==0) break;
		for(int i=0; i<n; i++){
			p[i]=n-i;
		}
		for(int i=0;i<r; i++){
			cin >> a >> b;
			for(int j=0; j<b; j++){	
				for(int k=a-1+t;k>s;k--){
					temp=p[k];
					p[k]=p[k-1];
					p[k-1]=temp;
				}
				s++;
				t++;
			}
			s=0;
			t=0;
		}
		cout << p[0] << endl;
	}
}


Measured memory_bytes: 3096
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <math.h>
using namespace std;

#define ll long long

#define MOD 1000000007

int main()
{
    int n;
    ll k;

    ll* a;
    a = new ll[n];
    ll* counter;
    counter = new ll[n];
    cin >> n >> k;
    for (int i = 0; i < n; i++)
    {
        cin >>a[i];
    }

    ll counter1 = 0;

    for (int i = 0; i < n; i++)
    {
        for (int j = 0; j < i; j++)
        {
            if (a[i]<a[j])
            {
                counter1++;
            }

        }
    }


    ll counter2 = 0;
    for (int i = 0; i < n; i++)
    {
        for (int j= 0; j < n; j++)
        {
            if(a[i]<a[j]){
                counter2++;
            }
        }
    }

    ll answer = 0;
    counter1 %=1000000007;
    counter2 %=1000000007;
    ll number;
    number = ((k-1)*k/2)%1000000007;

    ll temp = 0;

  
    temp = (number*counter2)%1000000007;
    answer = temp+ answer + counter1*k;
    answer %=1000000007;

    cout << answer << endl;
}

Measured memory_bytes: 384
#include <iostream>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <bitset>
#include <fstream>
#include <iomanip>

#define ll long long
#define scani(x) scanf("%i", &x)
#define scanll(x) scanf("%I64d", &x)
#define scanfl(x) scanf("%f", &x)
#define scanch(x) scanf("%c", &x)
#define scans(x) scanf("%s", x);
#define printi(x) printf("%i", x);
#define printll(x) printf("%I64d", x);
#define printfl(x) printf("%f", x);
#define printch(x) printf("%c", x);
#define prints(x) printf("%s", x);
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define INFI (1 << 29)
#define INFL (1LL << 62)
#define sz(x) int(x.size())
#define fi first
#define se second
#define forn(i, n) for(ll i = 0; i < n; i++)
#define for1(i, n) for(ll i = 1; i <= n; i++)
#define ford(i, n) for(ll i = (n - 1); i >= 0; i--)
#define fori(i, n) for(ll i = n; i >= 1; i--)
#define fore(i, l, r) for(ll i = l; i <= r; i++)
#define get_bit(mask, x) (bool)(mask & (1LL << x))
#define set_bit(mask, x) (mask |= (1LL << x))
#define reset_bit(mask, x) (mask &= ~(1LL << x))
#define toggle_bit(mask, x) (mask ^= (1LL << x))

using namespace std;

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

    ll n;
    long double v, r = 0.0;

    cin >> n;

    forn(i, n)
    {
        cin >> v;

        r += (1.0 / v);
    }

    cout << fixed << setprecision(10) << (long double)(1.0 / r) << "\n";

    return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>

#include <iostream>
#include <complex>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>

#include <functional>
#include <cassert>

typedef long long ll;
using namespace std;

#define debug(x) cerr << __LINE__ << " : " << #x << " = " << (x) << endl;

#define mod 1000000007 //1e9+7(prime number)
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define SIZE 100010


int n, a[SIZE];
int tanka[5] = {5, 7, 5, 7, 7};

bool dfs(int now = 0, int p = 0){
  int sum = 0;

  if(p == 5) return true;
  
  for(int i=now;i<n;i++){
    sum += a[i];
    if(tanka[p] == sum && dfs(i+1, p+1)) return true;
    if(tanka[p] < sum) return false;
  }

  return false;
}

bool solve(){

  scanf("%d", &n);

  if(n == 0) return false;
  
  for(int i=0;i<n;i++){
    char s[11];
    scanf("%s", s);
    a[i] = strlen(s);
  }

  for(int i=0;i<n;i++){
    if(dfs(i)){
      printf("%d\n", i+1);
      return true;
    }
  }

  return true;
}


int main(){
  while(solve());
  
  return 0;
}



Measured memory_bytes: 3232
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); i++)
#define repd(i,a,b) for (double i = (a); i < (b); i++)
typedef long long ll;

int main (void)
{
    boost::multiprecision::cpp_int a, b, ans;
    cin >> a >> b;
    ans = a - b;
    cout << ans << endl;
}


Measured memory_bytes: 3468
#include <bits/stdc++.h>
using namespace std;
const double PI = acos(-1);


int main()
{
    double A,B,H,M;
    cin>>A>>B>>H>>M;
  
    double kakua = (H/12+M/720)*2*PI;
    double kakub = (M/60)*2*PI;
    double xa,xb,ya,yb;
    
    xa = A*cos(kakua);
    xb = B*cos(kakub);
    ya = A*sin(kakua);
    yb = B*sin(kakub);
  
   double s,dx,dy;
  
  dx = abs(xa-xb);
  dy = abs(ya-yb);
  
  
  s = sqrt(dx*dx+dy*dy);
  
  cout<<setprecision(10)<<s<<endl;
  
}


Measured memory_bytes: 4096
#include<iostream>
#include<vector>
#include<queue>
using namespace std; // 575

const int MAX = 100000;
struct Node {
	vector<int> edge, rev;
	int parent;
};

int main() {
	int N, M, A, B;
	cin >> N >> M;
	static Node node[MAX];
	for (int i = 0;i < N;++ i) node[i].parent = -1;
	for (int i = 0;i < N + M - 1;++ i) {
		cin >> A >> B;
		node[A - 1].edge.push_back(B - 1);
		node[B - 1].rev.push_back(A - 1);
	}
	int search;
	for (int i = 0;i < N;++ i) if (node[i].rev.size() == 0) search = i;
	queue<pair<int, int> > que;
	que.push(make_pair(search, 0));
	while(!que.empty()) {
		search = que.front().first;
		node[search].parent = que.front().second;
		que.pop();
		if (node[search].edge.empty()) continue;
		for (int j = 0;j < node[search].edge.size();++ j) {
			for (int k = 0;k < node[node[search].edge[j]].rev.size();++ k) {
				if (node[node[node[search].edge[j]].rev[k]].parent < 0) goto cont;
			}
			que.push(make_pair(node[search].edge[j], search + 1));
			cont:;
		}
	}
	for (int i = 0;i < N;++ i) cout << node[i].parent << endl;
	return 0;
}
/*
31536000のコメント解説欄
ここテンプレで用意してるから、A問題とかだとこの先空欄の危険あり
また、コンテスト後に https://31536000.hatenablog.com/ で解説していると思うので、良かったら読んでねー

まず、必ず増えた辺は子孫に向かってる→ショートカットである
よって、とりあえず根はO(N)で確定、どれからも辺が来てないはず
すると次の辺はその根からのみ矢印が来てるのでやっぱ確定
以下同様

各頂点について
1. 繋がってる全ての辺を調べる O(N+M)
2. その辺は、確定親以外から辺が来てないか調べる O(N+M)
はい
*/

Measured memory_bytes: 12544
#include<stdio.h>
#define MAX 10000
#define NIL -1
typedef struct{
  int p,l,r;
}Node;
Node T[MAX];
int n;

void preParse(int u){
  if(u == NIL)return;
  printf(" %d",u);
  preParse(T[u].l);
  preParse(T[u].r);
}

void inParse(int u){
  if(u == NIL)return;
  inParse(T[u].l);
  printf(" %d",u);
  inParse(T[u].r);  
}

void postParse(int u){
  if(u == NIL)return;
  postParse(T[u].l);
  postParse(T[u].r);
  printf(" %d",u);
}

int main(){
  int i,v,l,r,root;
  scanf("%d",&n);
  for(i = 0 ; i < n ; i++){
    T[i].p = NIL;
  }
  for(i = 0 ; i < n ; i++){
    scanf("%d %d %d",&v,&l,&r);
    T[v].l = l;
    T[v].r = r;
    if(l != NIL)T[l].p = v;
    if(r != NIL)T[r].p = v;
  }
  for(i = 0 ; i < n ; i++){
    if(T[i].p == NIL)root = i;
  }
  printf("Preorder\n");
  preParse(root);
  printf("\n");
  printf("Inorder\n");
  inParse(root);
  printf("\n");
  printf("Postorder\n");
  postParse(root);
  printf("\n");
  return 0;
}



Measured memory_bytes: 2104
import heapq

n,m = map(int,input().split())
a = list(map(lambda x: int(x)*(-1),input().split()))
heapq.heapify(a)

for i in range(m):
  takai = heapq.heappop(a)
  heapq.heappush(a,(-1)*(-1*takai//2))
  
print(-sum(a))

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

using namespace std;
#define int long long
#define endl '\n'



int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int n; cin >> n;
    cout << (1000 - n % 1000) % 1000 << endl;
    return 0;
}


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

int main() {
	int N;
	cin>>N;
	int d[N];
	int dd;
	int sum=0;
	for(int i=0; i<N; i++){
		cin>>dd;
		d[i]=dd;
	}
	for(int i=0; i<N; i++){
		for(int j=i+1; j<N; j++){
			int kaihuku=d[i]*d[j];
			sum+=kaihuku;
		}
	}
	cout<<sum<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i=0;i<(n);++i)
#define fi first
#define se second
#define INF 1000000009
#define lINF 1000000000000000009
typedef long long ll;
int g[19][19];

int main(){
  int n;
  cin>>n;
  rep(i,n)rep(j,n)g[i][j]=-1;
  rep(i,n){
    int a;
    cin>>a;
    rep(j,a){
      int x,y;
      cin>>x>>y;
      --x;
      g[i][x]=y;
    }
  }

  int ans=0;
  rep(i,1<<n){
    vector<int>d(n);
    rep(j,n){
      if(i>>j&1)d[j]=1;
    }
    bool ok=true;
    rep(j,n){
      if(d[j]==0)continue;
      rep(k,n){
        if(g[j][k]==-1)continue;
        if(g[j][k]!=d[k])ok=false;
      }
    }

    if(ok)ans=max(ans,__builtin_popcount(i));
  }

  cout<<ans<<endl;

  return(0);
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
using namespace std;
typedef long long int64;
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const int INF = 1<<29;
const long long  INFL = 1e18;
const int MOD = 1000000007;
const int MAX = 210000;
const int MAX_NUM = 999999999;
void solve() {
	int A, B; cin >> A >> B;
	if ((A * B) % 2 == 1) cout << "Yes" << endl;
	else cout << "No" << endl;
	return;
}
int main() {
	solve();
	return 0;
}

Measured memory_bytes: 3580
N = int(input())
A = list(map(int,input().split()))
cnt = [0] * (N + 1)
total = 0
for i in range(N):
    total += cnt[A[i]]
    cnt[A[i]] += 1
for i in range(N):
    ans = total - (cnt[A[i]] - 1)
    print(ans)

Measured memory_bytes: 84172
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int p,q,r;
    cin>>p>>q>>r;
    int min_num=10000;
    if (p+q<min_num) {
        min_num=p+q;
    }
    if (p+r<min_num) {
        min_num=p+r;
    }
    if (p+r<min_num) {
        min_num=p+r;
    }
    if (q+r<min_num) {
        min_num=q+r;
    }
    if (r+p<min_num) {
        min_num=r+p;
    }
    if (q+p<min_num) {
        min_num=q+p;
    }
    cout<<min_num<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ft first
#define sc second
#define pt(sth) cout << sth << "\n"
#define chmax(a, b) {if(a<b) a=b;}
#define chmin(a, b) {if(a>b) a=b;}
#define moC(a, s, b) (a)=((a)s(b)+MOD)%MOD
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
static const ll INF=1e18;
static const ll MAX=1e5+7;
static const ll MOD=1e9+7;
ll max(ll a, ll b) {return a>b?a:b;}
ll min(ll a, ll b) {return a<b?a:b;}

ll moP(ll x, ll n) {
  ll res=1;
  while(n>0) {
    if(n&1) moC(res, *, x);
    moC(x, *, x);
    n>>=1;
  }
  return res;
}

ll fa[MAX], rf[MAX];

ll C(ll n, ll k) {
  if(n==0) return 1;
  if(n==k) return 1;
  return fa[n]*rf[k]%MOD*rf[n-k]%MOD;
}


int main(void) {
  ll N, K;
  cin >> N >> K;
  ll a[MAX];
  ll i;
  
  for(i=0; i<N; i++) {
    cin >> a[i];
  }
  sort(a, a+N);
  
  fa[0]=rf[0]=1;
  for(i=1; i<=N; i++) {
    fa[i]=fa[i-1]*i%MOD;
    rf[i]=moP(fa[i], MOD-2);
  }
  
  ll ans=0;
  for(i=N; i>=K; i--) {
    moC(ans, -, a[N-i]*C(i-1, K-1)%MOD);
  }
  
  for(i=N; i>=K; i--) {
    moC(ans, +, a[i-1]*C(i-1, K-1)%MOD);
  }
  
  pt(ans);
}


Measured memory_bytes: 2560
#include <bits/stdc++.h>
#define mset(a,b) memset(a,b,sizeof a)
#define mcpy(a,b) memcpy(a,b,sizeof b)
#define max(a,b) ((a)<(b)?(b):(a))
#define lb(x) ((x)&(-(x)))
#define inf 0x3f3f3f3f
using namespace std;
typedef long long ll;
ll n;
int cnt=0,ans[505],l,r=501;
int main(){
	cin>>n;
	while(n){
		if(n&1)ans[--r]=++cnt,n>>=1;
		else ans[++l]=++cnt,n--;
	}
	printf("%d\n",cnt<<1);
	for(int i=1;i<=l;i++)printf("%d ",cnt-ans[i]+1);
	for(int i=r;i<=500;i++)printf("%d ",cnt-ans[i]+1);
	for(int i=1;i<=cnt;i++)printf("%d ",i);
	return 0;
}

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

int main()
{
  int N;
  string S;
  cin >> N;
  cin >> S;
  for (int i=0; N > i ; i++)
  {
    cout << S.at(i);
    if ( i >= (S.size()-1) )break;
  }
  if ( S.size() > N )
  {
    cout << "..." ;
  }
}

Measured memory_bytes: 3624