akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0;i<n;i++)
#define LOOP(i,x,n) for(int i=x;i<n;i++)
#define ALL(v) (v).begin(),(v).end()
#define PB push_back
#define MP make_pair
#define FR first
#define SC second
#define int long long
using namespace std;
const int MOD=1000000007;
const int INF=1000000009;

signed main(){
  int m,nmin,nmax;
  while(cin>>m>>nmin>>nmax,m){
    vector<int> p(m);
    REP(i,m)cin>>p[i];
    vector<int> gap;
    for(int i=nmin-1;i<nmax;i++){
      gap.PB(p[i]-p[i+1]);
    }
    int M=*max_element(ALL(gap));
    int point=-1;
    REP(i,gap.size()){
      if(gap[i]==M)point=max(point,i+nmin);
    }
    cout<<point<<endl;
  }
  return 0;
}



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

LL total(int *weight,int *value,int w,int n){
   if(w <= 0){
	return 0;   
   }	
   if(n <= 0){
	   return 0;
   }
   LL take = INT_MIN;
   if(w- weight[0]  >= 0){
     take = value[0] + total(weight+1,value+1,w-weight[0],n-1);
  }
   LL dont = total(weight+1,value+1,w,n-1);
   return max(take,dont);
	
}

LL totalbydp(int *weight,int *value,int w,int n){
	LL dp[n+1][w+1];
	for(int i=0;i<=w;i++){
		dp[0][i] = 0;
	}
	for(int i=0;i<=n;i++){
		dp[i][0] = 0;
	}
	for(int i=1;i<=n;i++){
		for(int j=1;j<=w;j++){
			if(weight[i-1] <= j){
				dp[i][j]  = max(value[i-1] + dp[i-1][j-weight[i-1]],dp[i-1][j]);
			}else{
				dp[i][j]  = dp[i-1][j];
			}
		}
		
	}
	return dp[n][w];
}

int main(){
	int n,w; cin >> n >> w;
	int weight[n];
	int value[n];
	for(int i=0;i<n;i++){
		cin >> weight[i];
		cin >> value[i];
	}
	
	
	//cout << total(weight,value,w,n) << endl;
	cout << totalbydp(weight,value,w,n) << endl;
	
	
	
}


Measured memory_bytes: 82480
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
using namespace std;
 
#define mod 1000000007
#define FOR(x,to) for(int x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
#define long long long
inline int rei(){int x;cin>>x;return x;}
inline long rel(){long x;cin>>x;return x;}
inline string res(){string x;cin>>x;return x;}
//------------------------------------------------------- 
struct UnionFind{
    vector<int> par;
    UnionFind(int N){
        par.resize(N);
        for(int i=0;i<N;i++){
            par[i] = i;
        }
    }
    void Union(int x,int y){
        par[Get(x)] = Get(y); 
    }
    bool Same(int x,int y){
        return Get(x) == Get(y);
    }
    int Get(int x){
        if(x != par[x]){
            par[x] = Get(par[x]);
        }
        return par[x];
    }
};
pair<long,pair<int,int>> Edge[100000];
void Calc(){
	int N = rei();
	int M = rei();
	int K = rei();
	UnionFind U(N+K);
	for(int i=0;i<N;i++){
		int c = rei()-1;
		if(c != -1){
			U.Union(i,c+N);
		}
	}
	for(int i=0;i<M;i++){
		int f = rei()-1;
		int t = rei()-1;
		long c = rel();
		Edge[i] = {c,{f,t}};
	}
	sort(Edge,Edge+M);
	long ans = 0;
	K--;
	for(int i=0;i<M;i++){
		if(!U.Same(Edge[i].second.first,Edge[i].second.second)){
			ans += Edge[i].first;
			U.Union(Edge[i].second.first,Edge[i].second.second);
			K--;
			if(K == 0){
				cout << ans << endl;
				return;
			}
		}
	}
	cout << -1 << endl;
}
int main(int argc,char** argv){
	ios::sync_with_stdio(false), cin.tie(0);
	cout.tie(0); Calc(); return 0;
}

Measured memory_bytes: 2560
// MOHIT KUMAR
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;

typedef pair<int, int> pin;
typedef pair<ll, ll> pl;
typedef pair<ld, ld> pd;

#define ff(i, a, b) for ( ll i=a; i<(b); i++)
#define ffd(i, a, b) for ( ll i=a; i<= b; i++)
#define fr(i, a, b) for ( ll i = (b)-1; i >= a; i--)
#define ffr(i, a, b) for ( ll i = b ; i >= a; i--)
#define vl vector < ll >
#define vp vector < pl >
#define endl "\n"
#define sz(x) (ll)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()

const ld pi = acos(-1) ;
const ll maxn = 1e5 + 5 ;
const int mod = 1e9 + 7 ;
const ll INF = 1e10 ;
const int MX = 2000000001 ; // check the limits, dummy


int main() {
  ios_base::sync_with_stdio(0) , cin.tie(0);
  ll t, q, n, a, b, c, d, k, l, m, r,  x = 0, y = 0, z = 0 , sum = 0, ans = 0, temp = 0, res = 0 ;
  cin >> a >> b >> c >> d >> x >> k ;
  cout << (x - a > k ? ":(" : "Yay!") ;
}

Measured memory_bytes: 3628
#include<iostream>
#include<iomanip>
#include<string>
#include<queue>
#include<vector>
#include<algorithm>
#include<tuple>
#include<numeric>
#include<map>
#include<cmath>
#define ll long long
#define mod 1000000000+7
#define rep(i,n) for(int i=0;i<(int) (n);i++)
ll gcd(ll a,ll b){return b ? gcd(b,a%b) : a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
using namespace std;
int main(){
  int n,ans=0;
  cin>>n;
  vector<int>b(n);
  rep(i,n-1)cin>>b[i];


  for(int i=1;i<n;i++){
    if(b[i-1]<=b[i])ans+=b[i-1];
    else ans+=b[i];
  }
  ans+=b[0];
  ans+=b[n-2];
  cout<<ans;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
    vector<int64_t> A(4);
    cin >> A.at(0) >> A.at(1) >> A.at(2) >> A.at(3);
    cout << max(max(A.at(0)*A.at(2),A.at(0)*A.at(3)),max(A.at(1)*A.at(2),A.at(1)*A.at(3)));
}


Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
#define MOD 1000000007
LL powmod(LL a, LL n){
    if(n == 0) return 1;
    if(n % 2) return (a*powmod(a,n-1)) % MOD;
    LL c = powmod(a, n/2);
    return (c*c) % MOD;
}
LL inv(LL a){
    return powmod(a, MOD-2);
}
LL fact[1100000];
LL invfact[1100000];
 
void init(){
    fact[0] = 1;
    invfact[0] = 1;
    for(LL i = 1; i < 1100000; i++){
        fact[i] = (i*fact[i-1]) % MOD;
        invfact[i] = inv(fact[i]);
    }
}
 
int main(){
	init();
	LL n;
	cin >> n;
	LL ans = (n-1) * fact[n-1];
	ans %= MOD;
	LL k = n-2;
	for(LL a = 1; a*2 <= k; a++){
		LL cur = fact[k-a];
		cur = (cur * fact[n-1-a]) % MOD;
		cur = (cur * invfact[k-2*a]) % MOD;
		ans -= cur;
		ans %= MOD;
	}
	if(ans < 0) ans += MOD;
	cout << ans << endl;
}

Measured memory_bytes: 17536
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;
using vl = vector<ll>;
#define rep(i, n) for(ll i = 0;i < n;i++)
#define all(i) i.begin(), i.end()
template<class T, class U> bool cmax(T& a, U b) { if (a<b) {a = b; return true;} else return false; }
template<class T, class U> bool cmin(T& a, U b) { if (a>b) {a = b; return true;} else return false; }


const int MAX = 10000000;
const int MOD = 1000000007;

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

long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

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

  int x, y;
  cin >> x >> y;
  
  if ((2*x-y)%3 != 0) {
    cout << 0 << endl;
    return 0;
  }

  int a = (2*x-y)/3;
  int b = (2*y-x)/3;
  cerr << a << " " << b << endl;

  COMinit();

  cout << COM(a+b, a) << endl;
}


Measured memory_bytes: 234624
//☭
#include<cstdio>
#include<queue>
#include<map>
#include<set>
 
using namespace std;
 
const int N=1e5+10;
 
struct pai{
    int f, s;
};
 
bool operator <(pai a, pai b) {
    return (a.f==b.f)?(a.s<b.s):(a.f<b.f);
}
 
map< pai, int>m;
set<int> mu[N];
queue< pai >q;
 
int f[N], n;
 
inline void add(int x, int y) {mu[x].insert(y), mu[y].insert(x);}
 
pai marry(int x, int y) {
    if(x>y) {int t=y; y=x, x=t;}
    return (pai){x, y};
}
 
int f_f(int x){
    return f[x]?f[x]=f_f(f[x]):x;
}
 
int main(){
    scanf("%d", &n);
    for(int i=1; i<=(n<<1)-2; i++) {
        int x, y; scanf("%d%d", &x, &y), add(x, y);
        pai edg=marry(x, y); ++m[edg];
        if(m[edg]==2) q.push(edg);
        if(m[edg]>2) {puts("NO"); return 0;}
    }
    for(int w=1; w<n; w++) {
        if(q.empty()) {puts("NO"); return 0;}
        int x=0, y=0;
        while(x==y) x=f_f(q.front().f), y=f_f(q.front().s), q.pop();
        if(mu[x].size()>mu[y].size()) swap(x, y); f[x]=y;
        for(set<int>::iterator i=mu[x].begin(); i!=mu[x].end(); i++){
            int from=f_f(*i); mu[from].erase(mu[from].find(x)); if(from==y) continue;
            add(from,y); pai t=marry(from,y); m[t]++; if(m[t]==2) q.push(t);
        }
        mu[x].clear();
    }
    puts("YES");
}


Measured memory_bytes: 40320
import java.util.*;

public class Main {
	public static void main(String[] args) {
		
		Scanner sc = new Scanner(System.in);

		String str = "";
		int sum = 0;
		int cnt = 0;
		ArrayList<String> charTbl = new ArrayList<>();
		ArrayList<Integer> numTbl = new ArrayList<>();
		ArrayList<Integer> sumTbl = new ArrayList<>();
		
		for(int i = 0; i < 1000; i++) {
			charTbl.add("");
			numTbl.add(0);
		}
		
		while(!(str.equals("0"))) {
			str = sc.next();
			if(str.equals("0")) {
				break;
			} else {
				for(int i = 0; i < str.length(); i++) {
					charTbl.set(i, str.substring(i, i + 1));
					numTbl.set(i, Integer.parseInt(charTbl.get(i)));
				}
				for(int j = 0; j < str.length(); j++) {
					sum += numTbl.get(j);
				}
				sumTbl.add(sum);
				sum = 0;
				cnt++;
			}
		}
		for(int i = 0; i < cnt; i++) {
			System.out.println(sumTbl.get(i));
		}
	}
}

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

int main() {
  int N, K, Q;
  cin >> N >> K >> Q;
  vector<int> score(N, K-Q);
  if ( K <= Q ) {
    int A;
    rep(q,Q) {
      cin >> A;
      score.at(A-1)++;
    }
  }
  string ans;
  rep(i,N) {
    ans = score.at(i) > 0 ? "Yes" : "No";
    cout << ans << endl;
  }
}

Measured memory_bytes: 1024
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		char[] s = sc.next().toCharArray();
		int n = s.length;
		int k = sc.nextInt();
		for(int i=0;i<n-1;i++) {
			if (s[i] == 'a') continue;
			if (k >= 'z' + 1 - s[i]) {
				k -= 'z' + 1 - s[i];
				s[i] = 'a';
			}
		}
		int last = s[n-1] - 'a';
		last = (last + k) % 26;
		s[n-1] = (char) ('a' + last);
		System.out.println(s);
	}

}


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

#define For(i, l, r) for(register int i = (l), i##end = (int)(r); i <= i##end; ++i)
#define Fordown(i, r, l) for(register int i = (r), i##end = (int)(l); i >= i##end; --i)
#define Set(a, v) memset(a, v, sizeof(a))
#define Cpy(a, b) memcpy(a, b, sizeof(a))
#define debug(x) cout << #x << ": " << (x) << endl
#define DEBUG(...) fprintf(stderr, __VA_ARGS__)

using namespace std;

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

inline int read() {
	int x(0), sgn(1); char ch(getchar());
	for (; !isdigit(ch); ch = getchar()) if (ch == '-') sgn = -1;
	for (; isdigit(ch); ch = getchar()) x = (x * 10) + (ch ^ 48);
	return x * sgn;
}

void File() {
#ifdef zjp_shadow
	freopen ("E.in", "r", stdin);
	freopen ("E.out", "w", stdout);
#endif
}

const int N = 5e5 + 1e3, M = 2e6 + 1e3, inf = 0x3f3f3f3f;

int Head[N], Next[M], to[M], val[M], e = 0;

void add_edge(int u, int v, int w) {
	to[++ e] = v; Next[e] = Head[u]; val[e] = w; Head[u] = e;
}

int dis[N];

void Bfs() {
	Set(dis, inf); deque<int> Q; Q.push_back(1); dis[1] = 0;
	while (!Q.empty()) {
		int u = Q.front(); Q.pop_front();
		for (int i = Head[u], v = to[i]; i; v = to[i = Next[i]])
			if (chkmin(dis[v], dis[u] + val[i])) {
				if (val[i]) Q.push_back(v); else Q.push_front(v);
			}
	}
}

int Size = 0;
map<int, int> Id[N];

inline int Get_Id(int pos, int x) {
	if (Id[pos][x]) return Id[pos][x];
	int id = ++ Size;
	add_edge(pos, id, 1);
	add_edge(id, pos, 0);
	return Id[pos][x] = id;
}

int main() {

	File();

	int n = read(), m = read();

	Size = n;
	For (i, 1, m) {
		int u = read(), v = read(), c = read();
		u = Get_Id(u, c);
		v = Get_Id(v, c);
		//	cout << u << ' ' << v << endl;
		add_edge(u, v, 0);
		add_edge(v, u, 0);
	}

	Bfs();

	printf ("%d\n", dis[n] == inf ? -1 : dis[n]);

	return 0;

}


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

int main() {
  int N;
  string S;
  cin >> N >> S;

  rep(i, S.size()) {
    int x = S[i] - 'A';
    x = (x + N) % 26;
    cout << (char)('A' + x);
  }
  return 0;
}

Measured memory_bytes: 3612
#include <stdio.h>
#include <math.h>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
using namespace std;
typedef long long ll;
 
ll N,M;
 
int main(void)
{
    cin >> N >> M;
    if(N%2==1){
       for(int k=0;k<M;k++){
           cout << k+1 <<" "<< N-k<<endl;
        } 
    }else{
        for(int k=0;k<M;k++){
            if((N-k)-(k+1)<=N/2){
                cout << k+1 <<" "<< N-k-1<<endl;
            }else{
                cout << k+1 <<" "<< N-k<<endl;
            }
        } 
    }
}

Measured memory_bytes: 3612
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <map>
#define ll long long
using namespace std;
int main(){
    ll n;
    cin>>n;
    vector<ll> x(n);
    vector<ll> xsort(n);
    for(int i=0;i<n;i++){
        ll xi;
        cin>>xi;
        x[i]=xi;xsort[i]=xi;
    }
    ll mid=n/2;
    ll ans;
    sort(xsort.begin(),xsort.end());
    map<ll,ll> xsortmap;    
    ll last=-1;
    for(int i=0;i<n;i++){ 
        if(last==xsort[i]) continue;
        xsortmap[xsort[i]]=i;
        last=xsort[i];
    }
    for(int i=0;i<n;i++){
        ll index=xsortmap[x[i]];
        if(index<=mid-1){
            cout<<xsort[mid]<<" ";
        }else{
            cout<<xsort[mid-1]<<" ";
        }
    }    
    return 0;
}

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

int main(void){
    int n;
    std::cin >> n;
    std::vector<int> d(n);
    for(int i = 0; i < n; i++){
        std::cin >> d[i];
    }
    std::sort(d.begin(), d.end());
    std::cout << d[n/2] - d[n/2-1] << std::endl;
    return 0;
}

Measured memory_bytes: 3784
fun main(args: Array<String>) {
    abc122c()
}

fun abc122c() {
    val (n, q) = readLine()!!.split(" ").map { it.toInt() }
    val s = readLine()!!.toCharArray()
    val lrList = (1..q).map { readLine()!!.split(" ") }
        .map { Pair(it[0].toInt() - 1, it[1].toInt() - 1) }

    // 左にAがあるCをXに置き換える : ACACG -> AXAXG
    val acReplaced = (s.indices).map {
        if (it == 0) {
            s[0]
        } else {
            val cPrev = s[it - 1]
            val c = s[it]
            if (cPrev == 'A' && c == 'C') 'X' else c
        }
    }

    // 累積和とっておく
    val cumulativeSum = mutableListOf(0)
    var sumTemp = 0
    for (i in 1 until acReplaced.size) {
        if (acReplaced[i] == 'X') {
            sumTemp++
        }
        cumulativeSum.add(sumTemp)
    }

    val answer = lrList.map {
        cumulativeSum[it.second] - cumulativeSum[it.first]
    }

    println(answer.joinToString(separator = System.lineSeparator()))
}


Measured memory_bytes: 92844
#include <iostream>
#include <vector>
#include <cmath>
#include <string>
using namespace std;

long long N;
vector<long long> ans;
void check(long long n) {
    long long m = n;
    int seven, five, three;
    seven = 0; five = 0; three = 0;
    while(m > 0) {
	long long a;
	a = m % 10;
	if(a == 7) {
	    seven++;
	    m /= 10;
	} else if(a == 5) {
	    five++;
	    m /= 10;
	} else if(a == 3) {
	    three++;
	    m /= 10;
	} else {
	    return;
	}
    }
    if(seven > 0 && five > 0 && three > 0 && n <= N) ans.push_back(n);
}

void dfs(long long x){
    check(x);
    if(x <= N) {
	dfs(x * 10 + 7);
	dfs(x * 10 + 5);
	dfs(x * 10 + 3);
    }
}

int main() {
    cin >> N;
    dfs(0);
    cout << ans.size() << endl;

    return 0;
}


Measured memory_bytes: 640
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>

int main()
{
    int N;
    scanf("%d",&N);

    int a[N],i,count=0;
    for(i=0;i<N;i++){
        scanf("%d",&a[i]);
    }
    for(i=0;i<N;i++){
        while( a[i] % 2 == 0 ){
            count++;
            a[i] /= 2;
        }
    }

    printf("%d\n",count);

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main () {
	int N;
	int K;
	cin >> N >> K;
	int x[N];
	for (int i = 0; i < N; ++i)
	{
		cin >> x[i];
	}
	int sum = 0;
	for (int i = 0; i < N; ++i)
	{
		sum += min(x[i],K-x[i]);
	}
	cout << 2 * sum << endl;
}

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

int main(){
  char a,b;
  cin >> a >> b;
  if(a == 'H' and b == 'H') cout << 'H' << endl;
  if(a == 'H' and b == 'D') cout << 'D' << endl;
  if(a == 'D' and b == 'H') cout << 'D' << endl;
  if(a == 'D' and b == 'D') cout << 'H' << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
//#define int long long
#define FAST_IO ios_base::sync_with_stdio(false), cin.tie(nullptr)
using namespace std;

signed main()
{
    FAST_IO;

    int N;
    cin >> N;
    int t = N;
    vector<int> A;
    vector<int> B;
    vector<int> C;
    while (t--)
    {
        int a, b, c;
        cin >> a >> b >> c;
        A.push_back(a);
        B.push_back(b);
        C.push_back(c);
    }

    // cout << "hello";
    vector<vector<int>> dp(3, vector<int>(N, 0));
    dp[0][0] = A[0];
    dp[1][0] = B[0];
    dp[2][0] = C[0];
    for (int i = 1; i < N; i++)
    {
        dp[0][i] = A[i] + max(dp[1][i - 1], dp[2][i - 1]);
        dp[1][i] = B[i] + max(dp[0][i - 1], dp[2][i - 1]);
        dp[2][i] = C[i] + max(dp[1][i - 1], dp[0][i - 1]);
    }

    cout << max({dp[0][N - 1], dp[1][N - 1], dp[2][N - 1]});
    ;
    return 0;
}

Measured memory_bytes: 6048
#include <bits/stdc++.h>
#define rep(i,a) for(int i=0;i<int(a);++i)
#define REP(i,a,b) for(int i=int(a);i<int(b);++i)
#define pb push_back
#define mp make_pair
#define F first
#define S second
using ll = long long;
using itn = int;
using namespace std;
using Graph = vector<vector<int>>;
static const long double GRATIO=(long double)(1+sqrt(5))/2;
ll GCD(ll a, ll b){
    return b ? GCD(b, a%b) : a;
}
ll LCM(ll a, ll b){
    return a/GCD(a,b)*b;
}
struct Edge{
    int to,weight;
    Edge(int t, int w):to(t),weight(w){};
};
void dfs(vector<vector<Edge>> &G, vector<bool> &visit, int v, vector<ll> &cost){
    visit[v]=true;
    for(Edge u:G[v]){
        if(visit[u.to]) continue;
        cost[u.to]=cost[v]+u.weight;
        dfs(G,visit,u.to,cost);
    }
}
int main(){
    int N,Q,K;
    cin>>N;
    vector<vector<Edge>> G(N);
    rep(i,N-1){
        int a,b,c;
        cin>>a>>b>>c;
        a--;
        b--;
        G[a].push_back(Edge(b,c));
        G[b].push_back(Edge(a,c));
    }
    cin>>Q>>K;
    vector<int> x(Q),y(Q);
    rep(i,Q){
        int a,b;
        cin>>a>>b;
        a--; x[i]=a;
        b--; y[i]=b;
    }
    vector<bool> visit(N,false);
    vector<ll> cost(N,0);
    dfs(G,visit,K-1,cost);
    rep(i,Q){
        cout<<cost[x[i]]+cost[y[i]]<<endl;
    }
}

Measured memory_bytes: 16640
#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
using vb = vector<bool>;
using vl = vector<long>;
using vs = vector<string>;
using vvi = vector<vector<int>>;
using vvb = vector<vector<bool>>;
using vvc = vector<vector<char>>;
using pii = pair<int, int>;
using pll = pair<long, long>;
#define fix20 cout << fixed << setprecision(20);
#define rep(i,n) for(int i=0; i<(int)(n);i++)
#define rrep(i,n) for(int i=(n)-1;i>=0;i--)
#define MOD 1000000007
#define all(vec) vec.begin(), vec.end()

int main(){
    int a,b;
    cin >> a >> b;
    cout << max(a+b,max(a*b,a-b)) << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define Speed ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
using namespace std;

#define st              first
#define nd              second
#define pb              push_back
#define pf              push_front
#define all(a)          (a).begin(), (a).end()
#define lwb             lower_bound
#define upb             upper_bound
#define vvll            vector<vector<ll> >
#define Mset(s, n)      memset(s, n, sizeof(s))
#define Sz(a)           int((a).size())
#define Max(a, b, c)    max(max((ll)(a), (ll)(b)), (ll)(c))
#define Min(a, b, c)    min(min((ll)(a), (ll)(b)), (ll)(c))
#define Unique(a)       sort(all(a)); (a).resize(unique(all(a)) - (a).begin())

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

const ll MOD = 1e9 + 7;
const int oo = 2e9;
const ld PI = acos((ld) -1);
int Getbit(ll x, int k){return (x >> (k - 1)) & 1;}
ll Lcm(ll a, ll b) {return a / __gcd(a, b) * b;}
bool isPrime(ll n){for(ll i = 2; i * i <= n; i++){if(n % i == 0) return 0;} return (n > 1) ? 1 : 0;}
ll Powmod(ll n, ll k, ll p = MOD) {ll r = 1; for(; k; k /= 2, n = n * n % p){if(k & 1) r = r * n % p;} return r;}

const int N = 2e5 + 5;

ll n, m, k;
int a[N];

void Solve(){
    cin >> n;
    int ok = 1;
    for(int i = 1; i <= n; i++){
        cin >> a[i];
    }
    sort(a + 1, a + n + 1);
    for(int i = 1; i < n; i++){
        ok &= (a[i] != a[i + 1]);
    }
    if(ok) cout << "YES\n"; else cout << "NO\n";
}


int main(){
    Speed;
    cout << fixed << setprecision(10);
    int query = 1;
//    cin >> query;
    while(query--) Solve();
}


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

int main(){
    while(true){
        int n;
        cin >> n;
        if(n == 0){
            break;
        }
        int phraseCount[] = {5, 7, 5, 7, 7};
        int currentPhraseIndex = 0;
        int currentPhraseCount = 0;
        string phrases[n];
        for(int i = 0; i < n; i++){
            cin >> phrases[i];
        }
        bool isFinished = false;
        for(int k = 0; k < n; k++){
        for(int i = k; i < n; i++){
            string s;
            s = phrases[i];
            currentPhraseCount += s.length();
            if(currentPhraseCount == phraseCount[currentPhraseIndex]){
                currentPhraseIndex++;
                currentPhraseCount = 0;
                if(currentPhraseIndex == 5){
                    cout << k + 1 << endl;
                    isFinished = true;
                    break;
                }
            }else if(currentPhraseCount > phraseCount[currentPhraseIndex]){
                currentPhraseIndex = 0;
                currentPhraseCount = 0;
                break;
            }
        }
        if(isFinished){
        	break;
        }
        }
    }
    return 0;
}

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

int main(){
  string n ; cin>>n ;
int t=0;
  for(int i=0;i<3;i++){
  if(n.at(i)==n.at(i+1))
    t++;
  }
  if(t>0)
  cout<<  "Bad" <<endl;
else
  cout<<"Good"<<endl;
}

Measured memory_bytes: 256
///mAAria...
#include<bits/stdc++.h>
 
using namespace std;
 
#define int long long
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define all(v) v.begin(),v.end()
#define ld long double
#define ff first
#define ss second
#define pii pair<int,int>
#define pi 3.1415926535897932384626433832
#define mod 1000000007
#define inf 1000000000

const long double PI = acos(-1);

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

vector<vector<int>> adj;
map<pii,int> m;
bool col[100006], vis[100005];

void bfs(int v){
    vis[v] = true;
    col[v] = 0;

    queue<int> q;
    q.push(v);

    while(!q.empty()){
        int u = q.front(); q.pop();

        vis[u] = true;

        for(auto i:adj[u]){
            if(!vis[i]){
                q.push(i);
                vis[i] = true;
                int x = u;
                int y = i;
                if(x>y)swap(x,y);
                if(m[{x,y}]%2)col[i] = !col[u];
                else col[i] = col[u];
            }
        }
    }

}


void solve(){
  int n;
  cin >> n;
  adj.resize(n+2);

  for(int i = 1;i<n;i++){
    int x,y,w;
    cin >> x >> y >> w;

    adj[x].push_back(y);
    adj[y].push_back(x);

    if(x>y)swap(x,y);
    m[{x,y}] = w;
  }
  bfs(1);
  for(int i = 1;i<=n;i++)cout << col[i] << endl;
    
} 

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

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

 


Measured memory_bytes: 12928
import math
import itertools
#n = int(input())
#n, d = list(input().split())
n, k= list(map(int, input().split()))
p = list(map(int, input().split()))
point = []
rui = []

def s(n):
    if(n==1):
        return 1
    else:
        return (n*(n+1))/2


#for は一重まで
for i in range(n):
    point.append(s(p[i])/p[i])
    if i==0:
        rui.append(point[0])
    else:
        rui.append(rui[i-1]+point[i])


m = 0
a = 0
for i in range(n-k+1):
    if i==0:
        a = rui[i+k-1]
    else:
        a = rui[i+k-1]-rui[i-1]
    
   # print(a)
    if a > m:
        m = a



#print(point)
#print(rui)
print(m)


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

#pragma region template


// -type-
using ll = long long;
using pll = pair<ll, ll>;
using vl = vector<ll>;
using vvl = vector<vl>;
using vs = vector<string>;


// -const-
const ll MOD = 1000000007;


const ll MAX = (ll)0x3f0000003f000000;
const double EPS = 1e-9;
const int dx[] = {0, 1, 0, -1, 1, -1, 1, -1},
          dy[] = {1, 0, -1, 0, 1, -1, -1, 1};


// -define-
#define F first
#define S second

#define reps(i, k, n) for (int i = (k), i##_len = (n); i < i##_len; ++i)
#define rep(i, n) reps(i, 0, n)
#define all(o) begin(o), end(o)
#define sz(a) ((int)(a).size())
#define debug(x) cerr << x << " (L:" << __LINE__ << ")" << '\n';


// -functions-

inline bool in(string s, string c) {
    return (s.find(c) != string::npos);
}
inline bool in(string s, char c) {
    return (s.find(c) != string::npos);
}

template <class T>
void print(T& x) {
    cout << x << '\n';
}

struct setup_main {
    setup_main() {
        cin.tie(0);
        ios::sync_with_stdio(0);
        cout << fixed << setprecision(15);
    }
} setup_main_;

#pragma endregion

ll ans = 0;
const int e5 = 100000;
bitset<e5> P;
vl sum_like(e5, 0);

void er() {
    rep(i, e5) P[i] = true;
    P[0] = false;
    P[1] = false;
    reps(i, 2, sqrt(e5)) {
        if (P[i]) {
            for (int j = 2; i * j < e5; j++) P[i * j] = false;
        }
    }
}
void summ() {
    rep(i, e5) {
        sum_like[i] = sum_like[i - 1];
        if (P[i] and P[(i + 1) / 2]) sum_like[i]++;
    }
}
void solve(long long Q, std::vector<long long> l, std::vector<long long> r) {
    rep(k, Q) {
        int x = 0;
        x = sum_like[r[k]] - sum_like[l[k] - 1];

        print(x);
    }
}
signed main() {
    long long Q;
    scanf("%lld", &Q);
    std::vector<long long> l(Q);
    std::vector<long long> r(Q);
    for (int i = 0; i < Q; i++) {
        scanf("%lld", &l[i]);
        scanf("%lld", &r[i]);
    }
    er();
    summ();
    solve(Q, std::move(l), std::move(r));

    return 0;
}


Measured memory_bytes: 3072
#include <stdio.h>

int main(void) {
    int a, b, c;
    scanf("%d %d %d", &a, &b, &c);
    if (a<b) {
    	if (c<a) {
    		printf("%d %d %d\n", c, a, b);
    	} else if (b<c) {
    		printf("%d %d %d\n", a, b, c);
    	} else {
    		printf("%d %d %d\n", a, c, b);
    	}
    } else {
    	if (c<b) {
    		printf("%d %d %d\n", c, b, a);
    	} else if (a<c) {
    		printf("%d %d %d\n", b, a, c);
    	} else {
    		printf("%d %d %d\n", b, c, a);
    	}
    }
	return 0;
}


Measured memory_bytes: 596
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <iomanip>
#include <stack>
#include <queue>
#include <numeric>
#include <map>
#include <unordered_map>
#include <set>
#include <fstream>
#include <chrono>
#include <random>
#include <bitset>
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define sz(x) ((int)(x).size())
#define pb push_back
using ll = long long;
using namespace std;
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; }
ll gcd(ll a, ll b) {return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) {return a/gcd(a,b)*b;}

int D=365;
vector<int> c(26);
vector<vector<int>> s(365, vector<int>(26));

ll calc(const vector<int>& t, int d, int q){
  ll res = 0;
  vector<int> lst(26,-1);
  rep(i,D){
    if(i!=d){
      if(t[i]!=-1){
        res += s[i][t[i]];
        lst[t[i]] = i;
      }
    }
    else{
      res += s[i][q];
      lst[q]=i;
    }
    rep(j,26){
      res -= c[j]*(i-lst[j]);
    }
  }
  //cerr << res << '\n';
  return res;
}



int main(){
  /*
  ifstream in("input.in");
  cin.rdbuf(in.rdbuf());
  ofstream ofs("output.txt");
  cout.rdbuf(ofs.rdbuf());
  //*/
  chrono::system_clock::time_point start, end;
  start = chrono::system_clock::now();
  mt19937 mt(184);
  cin >> D;
  rep(i,26) cin >> c[i];
  rep(y,D) rep(x,26) cin >> s[y][x];
  vector<int> t(D,-1);
  ll now = calc(t, -1, -1);
  rep(d,D){
    int k=-1;
    ll prenow=-1;
    rep(q,26){
      ll pre = calc(t,d,q);
      if(now < pre){
        if(mt()&1 || mt()&1) {
          now = pre;
          t[d] = q;
        }
        if(k==-1) {k=q; prenow = pre;}
      }
      if(chmax(now,calc(t,d,q))){
        t[d]=q;
      }
      end = chrono::system_clock::now();
      double ela = chrono::duration_cast<chrono::milliseconds> (end-start).count();
      if(ela>1900) break;
    }
    if(t[d]==-1) {
      t[d]=k;
      now = prenow;
    }
    // timer
    end = chrono::system_clock::now();
    double ela = chrono::duration_cast<chrono::milliseconds> (end-start).count();
    if(ela>1900) break;
  }
  while(1){
    int d=mt()%365, q=mt()%26;
    if(chmax(now,calc(t,d,q))){
      t[d]=q;
    }
    end = chrono::system_clock::now();
    double ela = chrono::duration_cast<chrono::milliseconds> (end-start).count();
    if(ela>1970) break;
  }
  rep(i,D) cout << t[i]+1 << '\n';
  return 0;
}


Measured memory_bytes: 3676
#include<iostream>
#include<string>
#include<cstring>
#include<algorithm>
#include<vector>
#include<map>
#include<cmath>
#include<string>
#include<bitset>
#include <sstream>
#include<queue>
#include<set>
#include<iomanip>
#define rep(i,n) for(ll i=0;i<(n);++i)
using namespace std;
typedef long long ll;
typedef pair<int,int>P;
const int INF=10101;

int main()
{
    int n,x,y;
    cin>>n>>x>>y;
    vector<int> ans(n,0);
    for(int i=1;i<=n;i++)
    {
        for(int j=i+1;j<=n;j++)
        {
            ans[min(j-i,abs(x-i)+abs(y-j)+1)]++;
        }
    }
    for(int i=1;i<n;i++)
    {
        cout<<ans[i]<<endl;
    }
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
using namespace std;
int cont(string& t){
    int f = 0;
    for(int i = 1; i < t.size(); i++){
        if(t[0] != t[i]){
            f = 1;
            break;
        }
    }
    return f;
}
int main()
{
    string s, t, u;
    cin >> s;
    int ans['z' - 'a' + 1] = {0};
    for(char c = 'a'; c <= 'z'; c++){
        t = s;
        while(cont(t)){
            ans[c-'a']++;
            for(size_t j = 0; j < t.size() - 1; j++){
                u += (t[j] == c || t[j+1] == c ? c : t[j]);
            }
            t = u;
            u = "";
        }
    }
    sort(ans, ans + 'z' - 'a' + 1);
    cout << ans[0] << endl;
    return 0;
}

Measured memory_bytes: 256
import sys
S = input()
S = S[::-1]
while S:
    if S[:3]=="res":
        if S[:6]=="resare":
            S = S[6:]
#             print(S)
        else:
            break

    elif S[:3]=="esa":
        if S[:5]=="esare":
            S = S[5:]
#             print(S)
        else:
            break
    
    elif S[:3]=="rem":
        if S[:7]=="remaerd":
            S = S[7:]
#             print(S)
        else:
            break
            
    elif S[:3]=="mae":
        if S[:5]=="maerd":
            S = S[5:]
#             print(S)
        else:
            break
            
    else:
        break

print("YES" if len(S)==0 else "NO")

Measured memory_bytes: 3188
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;

namespace AtCoder
{
    static class Program
    {
        static void Main()
        {
            //ここから
            int N = IO.ReadLineToInt();

            var chars = new List<char[]>();
            for(int i = 0; i < N; i++)
            {
                chars.Add(Console.ReadLine().OrderBy(c=>c).ToArray());
            }


            var strings = chars.Select(c => new string(c)).ToArray();

            Dictionary<string, int> pairs = new Dictionary<string, int>();

            long ans = 0;

            foreach(var s in chars.Select(c=> new string(c))){
                if (pairs.ContainsKey(s))
                {
                    ans += pairs[s];
                    pairs[s]++;
                }
                else
                {
                    pairs.Add(s, 1);
                }
            }

            //ここまで
            Console.WriteLine(ans);
            Console.ReadKey();
        }

    }

    static class Func
    {
        static long mod = 1000000007;
        static public void Swap<T>(ref T a, ref T b) { T temp = a; a = b; b = temp; }
        static public long GCD(long a, long b) { return b != 0 ? GCD(b, a % b) : a; }
        static public long LCM(long a, long b) { return (long)a * b / GCD(a, b); }
        static public int Factorial(int a) { return a == 1 ? a : a * Factorial(a - 1); }

        static public long Conbination(int n,int m)
        {
            if (m == 0) return 1;
            if (n == 0) return 0;
            return n * Conbination(n - 1, m - 1) / m;
        }

        static public void Factoring(long num, ref long[] vs)
        {
            if (num == 1)
            {
                vs[1]++;
            }
            for (long i = 2; i < (long)Math.Sqrt(num); i++)
            {
                if (num % i == 0)
                {
                    vs[i]++;
                    Factoring(num / i, ref vs);
                }
            }
            vs[1]++;
        }
    }

    static class IO
    {
        static public string ReadLineToString() { return Console.ReadLine(); }
        static public int ReadLineToInt() { return int.Parse(Console.ReadLine()); }
        static public long ReadLineToLong() { return long.Parse(Console.ReadLine()); }
        static public List<string> ReadLineToStringList() { return Console.ReadLine().Split(' ').ToList(); }
        static public List<int> ReadLineToIntList() { return Console.ReadLine().Split(' ').Select(int.Parse).ToList(); }
        static public List<long> ReadLineToLongList() { return Console.ReadLine().Split(' ').Select(long.Parse).ToList(); }

        static public void WriteStrings(object[] strings) { foreach (var o in strings) { Console.Write(o + " "); } }
    }
}

Measured memory_bytes: 40236
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.Comparator;
import java.util.StringTokenizer;

public class Main {

	private void solve() throws IOException {
		int n = ni();

		int k = ni();
		long[][] a = na(n);
		Comparator<long[]> comp = new Comparator<long[]>() {
			public int compare(long[] arg0, long[] arg1) {
				return Long.signum(-(arg0[3] - arg1[3]));
			}
		};
		long ans = Long.MIN_VALUE;
		int mul[] = new int[] { 1, -1 };
		for (int i = 0; i < 2; i++)
			for (int j = 0; j < 2; j++)
				for (int l = 0; l < 2; l++) {
					apply(a, mul[i], mul[j], mul[l]);
					Arrays.sort(a, comp);
//					Helper.tr(a);
					ans = Math.max(ans, sumK(a, k));
//					Helper.tr(ans);
				}
		out.println(ans);
		out.close();

	}

	private void apply(long[][] a, int f0, int f1, int f2) {
		for (int i = 0; i < a.length; i++)
			a[i][3] = a[i][0] * f0 + a[i][1] * f1 + a[i][2] * f2;

	}

	private long sumK(long[][] a, int k) {
		long ans = 0;
		for (int i = 0; i < k; i++)
			ans += a[i][3];
		return ans;
	}

	static BufferedReader in;
	static PrintWriter out;
	static StringTokenizer tok;

	private long[][] na(int n) throws IOException {
		long[][] a = new long[n][4];
		for (int i = 0; i < n; i++) {
			a[i][0] = nl();
			a[i][1] = nl();
			a[i][2] = nl();
		}
		return a;
	}

	String ns() throws IOException {
		while (!tok.hasMoreTokens()) {
			tok = new StringTokenizer(in.readLine(), " ");
		}
		return tok.nextToken();
	}

	int ni() throws IOException {
		return Integer.parseInt(ns());
	}

	long nl() throws IOException {
		return Long.parseLong(ns());
	}

	double nd() throws IOException {
		return Double.parseDouble(ns());
	}

	String[] nsa(int n) throws IOException {
		String[] res = new String[n];
		for (int i = 0; i < n; i++) {
			res[i] = ns();
		}
		return res;
	}

	int[] nia(int n) throws IOException {
		int[] res = new int[n];
		for (int i = 0; i < n; i++) {
			res[i] = ni();
		}
		return res;
	}

	long[] nla(int n) throws IOException {
		long[] res = new long[n];
		for (int i = 0; i < n; i++) {
			res[i] = nl();
		}
		return res;
	}

	public static void main(String[] args) throws IOException {
		in = new BufferedReader(new InputStreamReader(System.in));
		out = new PrintWriter(System.out);
		tok = new StringTokenizer("");
		Main main = new Main();
		main.solve();
		out.close();
	}
}

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

struct UnionFind{
	vector<lint> rnk,par,num;
	UnionFind(lint N) : rnk(N),par(N),num(N){
		init();
	}
	void init(){
		for(lint i = 0;i < rnk.size();i++){
			rnk[i] = 0;
			par[i] = i;
			num[i] = 1;
		}
	}
	lint find(lint x){
		if(par[x] == x) return x;
		return par[x] = find(par[x]);
	}
	void unite(lint x,lint y){
		x = find(x);
		y = find(y);
		if(x == y) return;
		if(rnk[x] < rnk[y]){
			par[x] = y;
			num[y] += num[x];
		}
		else{
			par[y] = x;
			num[x] += num[y];
			if(rnk[x] == rnk[y]) rnk[x]++;
		}
	}
	bool same(lint x,lint y){
		return (find(x) == find(y));
	}
	lint size(lint x){
		return num[find(x)];
	}
};

signed main(){
  lint N, M, K; cin >> N >> M >> K;
  vector<lint> f(N, 0);
  UnionFind tree(N);
  vector<lint> a(M + K), b(M + K);
  for(lint i = 0; i < M; i++){
    cin >> a[i] >> b[i]; --a[i]; --b[i];
    tree.unite(a[i], b[i]);
  }
  for(lint i = 0; i < K; i++){
    cin >> a[M + i] >> b[M + i];
    a[M + i]--; b[M + i]--;
  }
  for(lint i = 0; i < M + K; i++){
    if(tree.same(a[i], b[i])){
      f[a[i]]++; f[b[i]]++;
    }
  }
  for(lint i = 0; i < N; i++){
    cout << tree.size(i) - f[i] - 1 << " ";
  }
  cout << endl;
}


Measured memory_bytes: 7040
/*~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=
    WRITER:kakitamasziru/OxOmisosiru
~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=*/
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <iomanip>
#include <limits>//setprecision
//#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <math.h>//pow,,,
#include <cmath>//abs,,,
//#include <unordered_map> // unordered_map
//#include <unordered_set> // unordered_set
#include <bitset> // bitset
//#include <cctype> // isupper, islower, isdigit, toupper, tolower
//It is so troublesome that I include bits/stdc++.h !
using namespace std;

template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
const long long INF = 100100100100100100;
const int MOD = 1000000007;
typedef pair<bool,long long> P;
//NのM乗を求める(繰り返し二乗法)
long long mod_pow(long long N, long long M) {
    if (M == 0) return 1;
    long long res = mod_pow((N * N) % MOD, M / 2);
    //最下位ビット(*N)が1の時は単独でNをかける
    if (M & 1) res = (res * N) % MOD;

    return res %= MOD;
}

int main() {
    int N;
    cin >> N;
    string T;
    set<string> S;
    map<string,long long> A;
    long long ans = 0;
    for(int i = 0;i<N;i++){
        cin >> T;
        sort(T.begin(),T.end());
        S.insert(T);
        if(A[T] == 0) A[T] = 1;
        else A[T]++;
    }
    for(auto R : S){
        ans += (A[R])*(A[R]-1)/2;
    }
    cout << ans << endl;
    // PLEASE GIVE ME THE "ACCEPTED" !
}

Measured memory_bytes: 20608
/// ****** Property of vipulks ****** \

#include <stdio.h>
#include <limits.h>
#include <stdbool.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>

#define ll long long

int main(){
	ll t,n,i,j,m,k,cnt=0;
	t=1;//scanf("%lld",&t);
	while(t--){
		scanf("%lld%lld",&n,&m);
		bool ans[n+2];
		ll h[n+2],a,b;
		for(i=1;i<=n;i++){
			ans[i]=true;
			scanf("%lld",&h[i]);
		}
		for(i=1;i<=m;i++){
			scanf("%lld%lld",&a,&b);
			if(h[a]-h[b]>0)
				ans[b]=false;
			else if(h[a]-h[b]<0)
				ans[a]=false;
			else
				{ans[a]=ans[b]=false;}
		}
		for(i=1;i<=n;i++)
			if(ans[i])
				cnt++;
		printf("%lld\n",cnt);
	}
	return 0;
}

Measured memory_bytes: 2612
n=int(input())
a=list(map(int,input().split()))

ans=[]
b=[0]*n
for i in reversed(range(n)):
  if sum(b[i::i+1])%2!=a[i]:
    b[i]+=1
    ans.append(i+1)
        
print(sum(b))
print(*sorted(ans))       


Measured memory_bytes: 19016
#include <iostream>
#include <cstring>
#include <algorithm>
#include <cstdio>
#include <set>
#include <vector>
#include <queue>
#include <map>
using namespace std;
#define maxn 100002
int maxx;
int a[maxn],vis[maxn];
int main()
{
    int n;
    while(cin>>n)
    {
        maxx=-1000;
        memset(vis,0,sizeof(vis));
        for(int i=0;i<n;i++)
        {
            cin>>a[i];
            a[i]++;
            vis[a[i]]++;
            vis[a[i]+1]++;
            vis[a[i]-1]++;
        }

        for(int i=0;i<100002;i++)
        {
            if(vis[i]>maxx) maxx=vis[i];
        }
        cout<<maxx<<endl;
    }
}


Measured memory_bytes: 1024
s = input()
a = int(s[:2])
b = int(s[2:])
if a <= 12 and a > 0:
	if b <=12 and b > 0:
		print('AMBIGUOUS')
	else:
		print('MMYY')
else:
	if b <=12 and b > 0:
		print('YYMM')
	else:
		print('NA')

Measured memory_bytes: 3060
import java.util.*;
import java.math.*;
public class Main {

	static   Scanner sc = new Scanner(System.in);
	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		int N = sc.nextInt();
		int K = sc.nextInt();
		String msg = "No";
	
		
		System.out.println(N - K + 1);

		
	}

}


Measured memory_bytes: 21844
n,m,q=list(map(int,input().split()))
lr=[[0 for i in range(n+1)] for j in range(n+1)]
for i in range(m):
  l,r=list(map(int,input().split()))
  lr[l][r]=lr[l][r]+1

#二次元累積和を作る（横）
for i in range(1,n+1):
  for j in range(1,n+1):
    lr[i][j]=lr[i][j-1]+lr[i][j]

#二次元累積和を作る（縦）
for i in range(1,n+1):
  for j in range(1,n+1):
    lr[i][j]=lr[i][j]+lr[i-1][j]
#答えを出力
for i in range(q):
  p,q=list(map(int,input().split()))
  print(lr[q][q]-lr[p-1][q]-lr[q][p-1]+lr[p-1][p-1])
  


    
    
  
  

Measured memory_bytes: 18664
import java.util.Scanner;

public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);

        int num;  // 入力される値
        int[] file;
        file = new int[10000];
        int cnt=0;
        String line;
        while(true){
            line = sc.nextLine();
            num = Integer.parseInt(line);
            if(num == 0)
                break;
            file[cnt] = num;
            cnt++;
            
        }
        for(int i=0; i<cnt; i++){
            System.out.println("Case " + (i+1) + ": " + file[i]);
        }
        
        sc.close();
    }
}


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

int main() {
  int x;
  cin >> x;
  if(x==0) cout << 1 << endl;
  if(x==1) cout << 0 << endl;

}

Measured memory_bytes: 3600
#include <bits/stdc++.h>
using namespace std;
typedef long long   signed int LL;
typedef long long unsigned int LU;
#define incID(i, l, r) for(LL i = (l)    ; i <  (r); ++i)
#define incII(i, l, r) for(LL i = (l)    ; i <= (r); ++i)
#define decID(i, l, r) for(LL i = (r) - 1; i >= (l); --i)
#define decII(i, l, r) for(LL i = (r)    ; i >= (l); --i)
#define inc(i, n)  incID(i, 0, n)
#define inc1(i, n) incII(i, 1, n)
#define dec(i, n)  decID(i, 0, n)
#define dec1(i, n) decII(i, 1, n)
#define inID(v, l, r) ((l) <= (v) && (v) <  (r))
#define inII(v, l, r) ((l) <= (v) && (v) <= (r))
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define  ALL(v)  v.begin(),  v.end()
#define RALL(v) v.rbegin(), v.rend()
template<typename T> bool setmin  (T & a, T b) { if(b <  a) { a = b; return true; } else { return false; } }
template<typename T> bool setmax  (T & a, T b) { if(b >  a) { a = b; return true; } else { return false; } }
template<typename T> bool setmineq(T & a, T b) { if(b <= a) { a = b; return true; } else { return false; } }
template<typename T> bool setmaxeq(T & a, T b) { if(b >= a) { a = b; return true; } else { return false; } }
LL mo(LL a, LL b) { assert(b > 0); a %= b; if(a < 0) { a += b; } return a; }
LL fl(LL a, LL b) { assert(b > 0); return (a > 0 ? a / b : (a - b + 1) / b); }
LL ce(LL a, LL b) { assert(b > 0); return (a < 0 ? a / b : (a + b - 1) / b); }
template<typename T> T gcd(T a, T b) { return (b == 0 ? a : gcd(b, a % b)); }
template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }
#define bit(b, i) (((b) >> (i)) & 1)
#define BC __builtin_popcountll
#define SC static_cast
#define SI(v) SC<int>(v.size())
#define SL(v) SC<LL >(v.size())
#define RF(e, v) for(auto & e: v)
#define ef else if
#define UR assert(false)

// ---- ----

int x;

int main() {
	cin >> x;
	
	int ans = 0;
	inc(i, 1000) {
		if(inII(x, 100 * i, 105 * i)) { ans = 1; }
	}
	
	cout << ans << endl;
	
	return 0;
}


Measured memory_bytes: 256
import java.math.BigInteger;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.PriorityQueue;
import java.util.Scanner;

import javax.xml.crypto.Data;
public class Main{

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		double[] pow = new double[24];
		for(int i = 0; i < 24; i++) {
			pow[i] = 1.0 / Math.pow(2, i);
		}
		while(true) {
			int n = sc.nextInt();
			if(n == 0) break;
			double[][] dp = new double[n+1][25];
			dp[0][0] = 1.0;
			double sum = 0;
			for(int i = 0; i < n; i++) {
				for(int j = 0; j < 24; j++) {
					dp[i+1][j+1] += dp[i][j] * pow[j];
					dp[i+1][0]   += dp[i][j] * (1.0 - pow[j]);
					sum += j * dp[i][j] * (1.0 - pow[j]);
				}
			}
			for(int j = 0; j < 25; j++) {
				sum += j * dp[n][j];
			}
			System.out.printf("%.20f\n",sum);
		}
		
	}
}

Measured memory_bytes: 87840