akhauriyash/Code-Regression huggingface dataset:
fn main() {
    let n = read::<usize>();
    let s = read::<String>();

    if s.len() % 2 == 1 {
        println!("No");
        return
    }

    if &s[0..s.len()/2] == &s[s.len()/2..s.len()] {
        println!("Yes");
    } else {
        println!("No");   
    }
}

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim().parse().ok().unwrap()
}


Measured memory_bytes: 4352
#include<algorithm>
#include<iostream>
#include<vector>
#include<string>
#include<queue>
#include<stack>
#include<cmath>
#include<list>
#include<set>
#include<map>

using namespace std;
long long MOD = 1000000007LL;
const double PI = 3.14159265358979323846;
#undef INT_MIN
#undef INT_MAX
#define INT_MIN -2147483648
#define INT_MAX 2147483647
#define endl "\n"

int main() {
	int N;
	cin >> N;
	vector<long long> vec;
	for (int i = 0; i < N; ++i) {
		long long l;
		cin >> l;
		vec.push_back(l);
	}

	int count = 0;
	for (int i = 0; i < vec.size(); ++i) {
		for (int j = i + 1; j < vec.size(); ++j) {
			for (int k = j + 1; k < vec.size(); ++k) {
				vector<long long > a;
				a.push_back(vec[i]);
				a.push_back(vec[j]);
				a.push_back(vec[k]);
				sort(a.rbegin(), a.rend());
				if (a[0] == a[1] || a[1] == a[2] || a[2] == a[0]) {
					//pass
				}
				else if (a[0] < a[1] + a[2]) {
					++count;
				}
			}
		}
	}

	cout << count << endl;

	return 0;
}

Measured memory_bytes: 3548
import scala.io.StdIn.readLine

object Main {

  def main(args: Array[String]) = {

    var n = readLine.split(" ").map(_.toInt)
    while( n(0) != 0 || n(1) != 0) {
      val h = n(0)
      val w = n(1)

      for(i <- 0 to h-1) {
        for(j <- 0 to w-1) {
          if((i+j)%2==0)
            print("#")
          else
            print(".")
        }
        println()
      }
      println()
      n = readLine.split(" ").map(_.toInt)
    }
  }
}

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

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int a = sc.nextInt();
		int b = sc.nextInt();
		int ans = 0;
		for(int i=0;i<=n;i++) {
			int nn=i;
			int sum = 0;
			while (nn>0) {
				sum += nn%10;
				nn /= 10;
			}
			if(sum>=a && sum<=b) {
				ans += i;
			}
		}
		System.out.println(ans);
	}

}

Measured memory_bytes: 21844
//#include <bits/stdc++.h>
#include <iostream>
#include <complex>
#include <sstream>
#include <string>
#include <algorithm>
#include <deque>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <vector>
#include <set>
#include <limits>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <ctime>
#include <climits>
#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define FOR(i, j, k) for(int i = (int)(j); i < (int)(k); ++i)
#define ROF(i, j, k) for(int i = (int)(j); i >= (int)(k); --i)
#define FORLL(i, n, m) for(long long i = n; i < (long long)(m); i++)
#define SORT(v, n) sort(v, v+n)
#define REVERSE(v) reverse((v).begin(), (v).end())

using namespace std;
using ll = long long;
const ll MOD=1000000007LL;
typedef pair<int, int> P;

ll ADD(ll x, ll y) { return (x+y) % MOD; }
ll SUB(ll x, ll y) { return (x-y+MOD) % MOD; }
ll MUL(ll x, ll y) { return x*y % MOD; }
ll POW(ll x, ll e) { ll v=1; for(; e; x=MUL(x,x), e>>=1) if (e&1) v = MUL(v,x); return v; }
ll DIV(ll x, ll y) { /*assert(y%MOD!=0);*/ return MUL(x, POW(y, MOD-2)); }

int a[575777], aa[575777];

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

  int n, x;
  cin >> n >> x;
  REP(i, n) cin >> a[i];

  ll ans = 0LL;
  if(a[0] > x){
    ans += (a[0]-x);
    a[0] = x;
  }

  FOR(i,1,n){
    if( (a[i-1]+a[i]) > x){
      ans += (a[i]+a[i-1]-x);
      a[i] = x - a[i-1];
    }
  }

  cout << ans << endl;
  
  return 0;
}



Measured memory_bytes: 2304
#include <stdio.h>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <list>
#include <iterator>
#include <assert.h>
#pragma warning(disable:4996)
 
typedef long long ll;
#define MIN(a, b) ((a)>(b)? (b): (a))
#define MAX(a, b) ((a)<(b)? (b): (a))
#define LINF 9223300000000000000
#define INF 2140000000
#define MOD 1000000007
using namespace std;


int main(int argc, char* argv[])
{
    long n;
    ll a, b;
    scanf("%ld%lld%lld", &n, &a, &b);

    vector<long> p(n+2);
    long i;
    p[0]=0;
    for(i=0; i<n; i++) {
        scanf("%ld", &p[i+1]);
    }
    p[n+1]=n+1;

    vector<ll> dp(n+2, LINF);
    long j;
    dp[0]=0;
    for(i=1; i<=n+1; i++) {
        ll cst = 0;
        for(j=i-1; j>=0; j--) {
            if(p[j] < p[i]) {
                dp[i] = MIN(dp[i], dp[j] + cst);
                cst += b;
            }
            else {
                cst += a;
            }
        }
    }    

    printf("%lld\n", dp[n+1]);
    return 0;
}


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

using vec = std::vector<int>;

int main(void) {
    int n;
    std::cin >> n;

    vec vec_a{};
    for (int i = 0; i < n; ++i) {
        int a;
        std::cin >> a;
        vec_a.push_back(a);
    }

    int m;
    std::cin >> m;

    vec vec_b{};
    for (int i = 0; i < m; ++i) {
        int b;
        std::cin >> b;
        vec_b.push_back(b);
    }

    vec symmetric_difference{};
    symmetric_difference.resize(vec_a.size() + vec_b.size());
    std::vector<int>::iterator iter = std::set_symmetric_difference(
        vec_a.begin(), vec_a.end(), vec_b.begin(), vec_b.end(),
        symmetric_difference.begin());
    symmetric_difference.resize(iter - symmetric_difference.begin());

    for (auto member : symmetric_difference) {
        std::cout << member << std::endl;
    }
}


Measured memory_bytes: 5936
#include <bits/stdc++.h>
using namespace std;
#define SPEED ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define fileio freopen("in.in", "r", stdin),freopen("out.out", "w", stdout);
#define ll long long int
#define FF first
#define SS second
#define mp make_pair
#define pb push_back
#define pii pair<int,int>
#define pll pair<long long int,long long int>
#define sd(x) scanf("%d",&x)
#define slld(x) scanf("%lld",&x)
#define pd(x) printf("%d\n",x)
#define plld(x) printf("%lld\n",x)
#define pss printf
#define MOD 1000000007
#define INF 1e18
#define eps 0.00001
#define endl '\n'
#define debug(n1) cout<<n1<<endl
const int N = 1e5;  // limit for array size
ll n;  // array size

int main(){
	int n;cin>>n;
	int a[n];
	
	for(int i=0;i<n;i++){
		cin>>a[i];
	}
	
	int ans=0,g=1e5+1;
	
	for(int i=1;i<n;i++){
		if(a[i]==a[i-1]){
			a[i]=g;ans++;
		}
	}
	
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 256
# D - String Formation
from collections import deque


def main():
    S = input().rstrip()
    Q = int(input())
    queue = deque(S)
    is_reversed = 0
    for _ in range(Q):
        query = input().split()
        if query[0] == "1":
            is_reversed ^= 1
            continue
        com, c = query[1], query[2]
        if com == "1":
            if not is_reversed:
                queue.appendleft(c)
            else:
                queue.append(c)
        else:
            if not is_reversed:
                queue.append(c)
            else:
                queue.appendleft(c)
    ans = "".join(queue) if not is_reversed else "".join(reversed(queue))
    print(ans)


if __name__ == "__main__":
    main()


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


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

void solve(){

  ll x=0,y=0,c=0,ans=0;
  ll n,m,b,a;
  cin>> a >> b >> c;
  cout << c <<" " << a << " "<< b;
 
}

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


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
int n , arr[100001][3]={},dp[100001][3];

int f(int i = 0 , int t = -1)
{
    if( i == n )
        return arr[n][t];
    if(i==0)
        return max({f(i+1,0),f(i+1,1),f(i+1,2)});
    if(dp[i][t] != -1)
        return dp[i][t];
    if(t!=0)
        dp[i][t] = max(dp[i][t],f(i+1,0));
    if(t!=1)
        dp[i][t] = max(dp[i][t],f(i+1,1));
    if(t!=2)
        dp[i][t] = max(dp[i][t],f(i+1,2));
    return dp[i][t]+= arr[i][t];
}
int main()
{
    memset(dp,-1,sizeof dp);
    cin >> n;
    for(int i=1;i<=n;++i)
        cin >> arr[i][0] >> arr[i][1] >> arr[i][2];
    cout << f();
    return 0;
}

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

int main(){
  int n1;
  int n2;
  int n3;

  scanf("%d%d%d",&n1,&n2,&n3);
  for(int i=0;i<3;i++){
    if(n1 == 5 && n2 == 5 && n3 == 7){
	  cout<<"YES"<<endl;break;
    }
	swap(n1,n2);
	swap(n2,n3);
	if(i==2)cout<<"NO"<<endl;
  }
  return 0;
}

  
	

      


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

using namespace std;

#define int long long
#define MP make_pair
#define F first
#define S second
#define pi pair<int,int> 
#define sz(s) ((int)s.size())
#define rep(i,a,b) for (int i = a; i <= (int)b; ++i)

const unsigned mod = 1e9 + 7;
const unsigned N = 5e5 + 4;

signed main() {
  ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
  int n, k;
  cin >> n >> k;
  if (n % k == 0)
  	return cout << 0 << '\n',0;
  // cout << n%k << '\n';
  n %= k;
  cout << min(n, abs(n-k)) << '\n';
  




  
  assert(numeric_limits<int>::max() >= 1e18);
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define EPS (1e-8)
#define N_MAX 200005
using namespace std;
typedef double ll;

int N;
ll R,x[N_MAX],y[N_MAX];
bool used[N_MAX];

struct node{
  vector<ll> Point;
  int l,r;
  node(){}
  node(vector<ll> a){Point=a,l=r=-1;}
};

const int K=2;// K:?¬??????°
int D;// D:?????????????????????????????????????¬????
vector<vector<ll> > P;// ???????????????????´????K+1???(K???????¬????????????????????????????number)
vector<node> G;

bool compare(const vector<ll> &A,const vector<ll> &B){return A[D]<B[D];}

int make_tree(int depth,int l,int r){
  if(l>r)return -1;
  D=depth%K;
  sort(P.begin()+l,P.begin()+r+1,compare);
  int m=(l+r)/2,res=G.size();
  G.push_back(node(P[m]));

  int vl=make_tree(depth+1,l,m-1);
  int vr=make_tree(depth+1,m+1,r);

  G[res].l=vl; G[res].r=vr;
  return res;
}

vector<int> num;// search??§?????????????????¨?????§????????????number????????????

void search(int x,int depth,vector<ll> &L,vector<ll> &R){
  bool f=true;
  for(int i=0;i<K;i++)
    if(G[x].Point[i]<L[i]||R[i]<G[x].Point[i])f=false;

  if(f)num.push_back(G[x].Point[K]);

  D=depth%K;
  if(G[x].Point[D]<=R[D]&&G[x].r!=-1)search(G[x].r,depth+1,L,R);
  D=depth%K;
  if(L[D]<=G[x].Point[D]&&G[x].l!=-1)search(G[x].l,depth+1,L,R);
}

int main(){
  
  cin>>N>>R;
  
  P.resize(N);
  
  for(int i=0;i<N;i++){
    
    scanf("%lf %lf",&x[i],&y[i]);
    
    P[i].resize(K+1);
    
    P[i][K]=i;
    P[i][0]=x[i],P[i][1]=y[i];
  }
  
  make_tree(0,0,P.size()-1);
 
  int ans=0;
  for(int i=0;i<N;i++){
    
    if(used[i])continue;
    
    vector<ll> L2(K),R2(K);
    
    L2[0]=x[i]-R-EPS;
    R2[0]=x[i]+R+EPS;
    
    L2[1]=y[i]-R-EPS;
    R2[1]=y[i]+R+EPS;
    
    num.clear();
    
    search(0,0,L2,R2);
    
    for(int j=0;j<num.size();j++) used[num[j]]=1;
    
    ans++;
  }
  
  cout<<ans<<endl;

  return 0;
}

Measured memory_bytes: 31360
#Postal Code
A,B=map(int,input().split())
d=["0","1","2","3","4","5","6","7","8","9"]
S=input()
total=0
for i in range(A):
    if S[i] in d:
        pass
    else:
        total=1
S=S[A:]
if S[0]!="-":
    total=1
S=S[1:]
for i in range(B):
    if S[i] in d:
        pass
    else:
        total=1
if total==1:
    print("No")
else:
    print("Yes")

Measured memory_bytes: 9156
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Text;
using System.Globalization;
using System.Diagnostics;



class Myon
{
    public Myon() { }
    public static int Main()
    {
        new Myon().calc();
        return 0;
    }


    Scanner cin;

    void calc()
    {
        cin = new Scanner();
        int N = cin.nextInt();
        int M = cin.nextInt();
        if(Math.Abs(N - M) > 1)
        {
            Console.WriteLine(0);
            return;
        }
        long ans = 1;
        long mod = 1000000007;

        for (int i = 0; i < N; i++)
        {
            ans *= i + 1;
            ans %= mod;
        }
        for (int i = 0; i < M; i++)
        {
            ans *= i + 1;
            ans %= mod;
        }

        if (N == M) ans *= 2;
        ans %= mod;
        Console.WriteLine(ans);
    }
    
        
}


class Scanner
{
    string[] s;
    int i;

    char[] cs = new char[] { ' ' };

    public Scanner()
    {
        s = new string[0];
        i = 0;
    }

    public string next()
    {
        if (i < s.Length) return s[i++];
        string st = Console.ReadLine();
        while (st == "") st = Console.ReadLine();
        s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
        if (s.Length == 0) return next();
        i = 0;
        return s[i++];
    }

    public int nextInt()
    {
        return int.Parse(next());
    }
    public int[] ArrayInt(int N, int add = 0)
    {
        int[] Array = new int[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextInt() + add;
        }
        return Array;
    }

    public long nextLong()
    {
        return long.Parse(next());
    }

    public long[] ArrayLong(int N, long add = 0)
    {
        long[] Array = new long[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextLong() + add;
        }
        return Array;
    }

    public double nextDouble()
    {
        return double.Parse(next());
    }


    public double[] ArrayDouble(int N, double add = 0)
    {
        double[] Array = new double[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextDouble() + add;
        }
        return Array;
    }
}


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

namespace AtCoder_20190707_1
{    class Program
    {
        static void Main(string[] args)
        {
            string[] DN = Console.ReadLine().Split(' ');
            int D = int.Parse(DN[0]);
            int N = int.Parse(DN[1]);

            if (N != 100)
            {
                Console.WriteLine(Math.Pow(100, D) * N);
            }
            else
            {
                Console.WriteLine((Math.Pow(100, D) * (N + 1)));
            }
        }
        static int Compare(int[] x, int[] y)
        {
            return x[1].CompareTo(y[1]);            
        }
    }
}

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

#define X first
#define Y second
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define rep(i, a, b) for (unsigned i = (a); i <= (b); ++i)
#define per(i, a, b) for (unsigned i = (a); i >= (b); --i)

using namespace std;

using I = int;
using L = long;
using F = float;
using S = string;
using SS = stringstream;
using C = char;
using LL = long long;
using VI = vector<int>;
using VL = vector<long>;
using VF = vector<float>;
using VS = vector<string>;
using PLL = pair<long, long>;
using PLF = pair<long, float>;
using PLS = pair<long, string>;
using PSL = pair<string, long>;
using PSF = pair<string, float>;
using PSS = pair<string, string>;
using MLL = map<long, long>;
using MLF = map<long, float>;
using MLS = map<long, string>;
using MSL = map<string, long>;
using MSF = map<string, float>;
using MSS = map<string, string>;

const long kMax2 = 109;
const long kMax3 = 1009;
const long kMax4 = 10009;
const long kMax5 = 100009;
const long kMax6 = 1000009;
const long kInfI = 0x3F3F3F3F;
const float kInfF = 1e15;

L TempVar(L h, L s, L t) {
  if (h > 0) { return -s * h; }
  else { return -t * h; }
}

int main(int argc, char const *argv[]) {
  L n, q, s, t;
  VL a;
  cin >> n >> q >> s >> t;
  L prev_h = 0;
  L h;
  rep(i, 0, n) {
    cin >> h;
    if (i == 0) { continue; }
    a.pb(h - prev_h);
    prev_h = h;
  }

  L temp = 0;
  rep(i, 0, n - 1) {
    temp += TempVar(a[i], s, t);
  }

  rep(i, 1, q) {
    L l, r, x;
    cin >> l >> r >> x;
    temp -= TempVar(a[l - 1], s, t);
    if (r != n) temp -= TempVar(a[r], s, t);
    a[l - 1] += x;
    if (r != n) { a[r] -= x; }
    temp += TempVar(a[l - 1], s, t);
    if (r != n) temp += TempVar(a[r], s, t);

    cout << temp << endl;
  }

  return 0;
}

Measured memory_bytes: 4968
import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int A = sc.nextInt();
        int B = sc.nextInt();
        int T = sc.nextInt();

        double Td = T + 0.5;

        System.out.println((T / A) * B);
    }
}

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

#define rep(i,x,y) for(int i=(x);i<(y);++i)
#define debug(x) #x << "=" << (x)
 
#ifdef DEBUG
#define _GLIBCXX_DEBUG
#define dump(x) std::cerr << debug(x) << " (L:" << __LINE__ << ")" << std::endl
#else
#define dump(x)
#endif

typedef long long int ll;
typedef pair<int,int> pii;
//template<typename T> using vec=std::vector<T>;

const int inf=1<<30;
const long long int infll=1LL<<58;
const double EPS=1e-9;
const int dx[]={1,0,-1,0},dy[]={0,1,0,-1};

template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec){
	os << "[";
	for (const auto &v : vec) {
		os << v << ",";
	}
	os << "]";
	return os;
}

int get_largest_rectangle(int c[],int size){
    stack<pii> stk;
    int res=0;
    c[size]=0;
    
    rep(i,0,size+1){
        pii rect;
        rect.first=c[i];
        rect.second=i;
        if(stk.empty() or stk.top().first<rect.first) stk.push(rect);
        else if(stk.top().first>rect.first){
            int target=i;
            while(!stk.empty() and stk.top().first>=rect.first){
                pii pre=stk.top();
                stk.pop();
                int area=pre.first*(i-pre.second);
                res=max(res,area);
                target=pre.second;
            }
            rect.second=target;
            stk.push(rect);
        }
    }
    return res;
}

void solve(){
    int h,w;
    cin >> h >> w;
    
    static int c[1400][1401];
    rep(i,0,h) rep(j,0,w){
        cin >> c[i][j];
        c[i][j]=(c[i][j]+1)%2;
    }
    
    rep(i,1,h) rep(j,0,w) if(c[i-1][j] and c[i][j]) c[i][j]=c[i-1][j]+1;
    
    int ans=0;
    rep(i,0,h) ans=max(ans,get_largest_rectangle(c[i],w));
    cout << ans << endl;
}

int main(){
	std::ios::sync_with_stdio(false);
	std::cin.tie(0);
	solve();
	return 0;
}

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

int main(void)
{
    char card[256];
    int m;
    int h;
    char tmp[256];

    for (scanf("%s", card); strcmp(card, "-"); scanf("%s", card)){
        scanf("%d", &m);
        memset(tmp, 0, 256);
        while (m--){
            scanf("%d", &h);
            strcpy(tmp, card + h);
            strncpy(tmp + strlen(tmp), card, h);
            strcpy(card, tmp);
        }

        puts(card);
    }

    return 0;
}

Measured memory_bytes: 596
#include<stdio.h>
#include<iostream>

using namespace std;

int main(void) {

	int a, b, c, x, na, nb, nc, tmp, num;
	num = 0;

	cin >> a >> b >> c >> x;

	for (na = 0; na <= a; na++){
		for (nb = 0; nb <= b; nb++) {
			for (nc = 0; nc <= c; nc++) {
				tmp = x - 500 * na - 100 * nb - 50 * nc;
				if (tmp == 0)num++;
				//printf("na=%d,nb=%d,nc=%d,tmp=%d\n",na,nb,nc,tmp);
			}
		}
	}

	cout << num << endl;

	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long int 
#define ld long double
#define mod 1000000007
#define endl "\n"
#define pb push_back
#define mp make_pair
#define ff first
#define ss second

int main()
{
    ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	ll n,i,j,x,y,r[4005],g[4005],b[4005],tr,tb,tg,ans=0;
	string s;
	cin >> n >> s;
	r[0] = g[0] = b[0] = 0;
	for(i=0;i<n;i++)
	{
		r[i+1] = r[i];
		g[i+1] = g[i];
		b[i+1] = b[i];
		if(s[i]=='R')
		{
			r[i+1]++;
		}
		if(s[i]=='G')
		{
			g[i+1]++;
		}
		if(s[i]=='B')
		{
			b[i+1]++;
		}
	}
	tr = r[n];
	tg = g[n];
	tb = b[n];
	for(i=0;i<n;i++)
	{
		for(j=i+1;j<n;j++)
		{
			if(s[i]!=s[j])
			{
				if(s[i]=='R')
				{
					if(s[j] == 'G')
					{
						if((j+(j-i))<n)
						{
							if(s[j+j-i]=='B')
							{
							    //cout<<tb<<" "<<b[j];
								ans += tb-b[j]-1;
							}
							else
							{
								ans += tb-b[j];
							}
						}
						else
						{
							ans += tb-b[j];
						}
					}
					else
					{
						if((j+(j-i))<n)
						{
							if(s[j+j-i]=='G')
							{
								ans += tg-g[j]-1;
							}
							else
							{
								ans += tg-g[j];
							}
						}
						else
						{
							ans += tg-g[j];
						}
					}
				}
				if(s[i]=='G')
				{
					if(s[j] == 'R')
					{
						if((j+(j-i))<n)
						{
							if(s[j+j-i]=='B')
							{
								ans += tb-b[j]-1;
							}
							else
							{
								ans += tb-b[j];
							}
						}
						else
						{
							ans += tb-b[j];
						}
					}
					else
					{
						if((j+(j-i))<n)
						{
							if(s[j+j-i]=='R')
							{
								ans += tr-r[j]-1;
							}
							else
							{
								ans += tr-r[j];
							}
						}
						else
						{
							ans += tr-r[j];
						}
					}
				}
				if(s[i]=='B')
				{
					if(s[j] == 'G')
					{
						if((j+(j-i))<n)
						{
							if(s[j+j-i]=='R')
							{
								ans += tr-r[j]-1;
							}
							else
							{
								ans += tr-r[j];
							}
						}
						else
						{
							ans += tr-r[j];
						}
					}
					else
					{
						if((j+(j-i))<n)
						{
							if(s[j+j-i]=='G')
							{
								ans += tg-g[j]-1;
							}
							else
							{
								ans += tg-g[j];
							}
						}
						else
						{
							ans += tg-g[j];
						}
					}
				}
	
			}
		}
	}
	cout<<ans;
	return 0;
}

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

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

  vector<int> Ds(K);
  for (int i = 0; i < K; i++) cin >> Ds.at(i);

  int a;
  for (int m = N; m < 10*N; m++) {
    a = m;
    char flag = 0;
    do {
      int n = m%10;
      for (int j = 0; j < K; j++) {
        if (n == Ds.at(j)) {
          flag = 1;
          break;
        }
      }

      if (flag) break;
      m /= 10;
    } while (m != 0);

    if (!flag) break;
    m = a;
  }

  cout << a << endl;

  return 0;
}


Measured memory_bytes: 256
x, n = map(int, input().split())
if n > 0:
    P = list(map(int, input().split()))
else:
    P = []

ans, dist = 0, 1000
for i in range(-200, 200):
    if i not in P:
        if abs(i - x) < dist:
            dist = abs(i - x)
            ans = i
print(ans)

Measured memory_bytes: 9112
# ABC042D - いろはちゃんとマス目 / Iroha and a Grid (ARC058D)
def comb(n: int, r: int) -> int:
    return fact[n] * inv[n - r] * inv[r]


def main():
    global fact, inv
    H, W, A, B = tuple(map(int, input().split()))
    MOD = 10 ** 9 + 7
    # table of factorials
    fact, x = [1] * (H + W + 1), 1
    for i in range(1, H + W + 1):
        x = (x * i) % MOD
        fact[i] = x
    # table of inverse factorials
    inv = [1] * (H + W + 1)
    inv[-1] = pow(fact[-1], MOD - 2, MOD)
    x = inv[-1]
    for i in range(H + W - 1, 0, -1):
        x = (x * (i + 1)) % MOD
        inv[i] = x

    ans = 0
    for i in range(B, W):
        ans += comb(i + H - A - 1, i) * comb(W - i - 1 + A - 1, A - 1)
    print(ans % MOD)


if __name__ == "__main__":
    main()

Measured memory_bytes: 18804
#include <bits/stdc++.h>
const int INF = 1e9;
const int MOD = 1e9+7;
const long long LINF = 1e18;
#define dump(x)  cout << 'x' << ' = ' << (x) << ` `;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)
#define FOREACH(x,a) for(auto& (x) : (a) )
typedef long long ll;
using namespace std;
typedef pair<ll, ll> P;

template<typename T>
void print(const vector<T> &x) {
    int n = x.size();
    rep(i,n) {
        cout << x[i];
        if (i!=n-1) cout<<" ";
        else cout << endl;
    }
}

template<typename T>
void print(const vector<vector<T>> &x) {
    int n = x.size();
    rep(i,n) {
        rep(j,x[i].size()) {
            cout << x[i][j] << " ";
        }
        cout << endl;
    }
}

template<typename T>
void print(const vector<T> &x, int n) {
    rep(i,n) {
        cout << x[i];
        if (i!=n-1) cout<<" ";
        else cout << endl;
    }
}

template<typename T>
void print(const vector<vector<T>> &x, int n, int m) {
    rep(i,n) {
        rep(j,m) {
            cout << x[i][j] << " ";
        }
        cout << endl;
    }
}

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

void input_init() {
    cin.tie(0); ios::sync_with_stdio(false);
}

int main(int argc, char const *argv[]) {
    int n; cin>>n;
    vector<vector<int>> g(n);
    map<P,int> mp;
    vector<int> edge(n-1);
    rep(i,n-1) {
        int a,b; cin>>a>>b;
        --a,--b;
        g[a].push_back(b); g[b].push_back(a);
        if (a>b) swap(a,b);
        mp[P(a,b)] = i;
    }

    vector<bool> vi(n,false);

    auto dfs = [&] (auto&& f, int x, int par) -> void {
        vi[x] = true;
        int col = 1;
        for (auto &&e: g[x]) {
            if (vi[e]) continue;
            if (col == par) col++;
            P p = P(x, e);
            if (p.first>p.second) swap(p.first, p.second);
            edge[mp[p]] = col;
            f(f, e, col);
            col++; 
        }
        return;
    };

    dfs(dfs,0,0);

    int ans = 0;
    rep(i,n-1) chmax(ans,edge[i]);

    cout << ans << '\n';
    rep(i,n-1) cout << edge[i] << '\n';
    return 0;
}

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

long long gcd(long long a,long long b){
  long long r,tmp;

  if(a<b){
    tmp = a;
    a = b;
    b = tmp;
  }
 
  r = a % b;
  while(r!=0){
    a = b;
    b = r;
    r = a % b;
  }
  return b;
}

int main(){
  int n,m;
  cin >> n >> m;
  vector<long long> a(n);

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

  long long l = a[0];
  for (int i = 1; i < n; i++)
  {
    l = l/gcd(l,a[i]) * a[i];
  }

  bool ok = true;
  for(int i=0; i<n; i++){
      if((l/a[i])%2 == 0) ok = false;
  }
  if(ok){
    long long ans = m / l;
    ans = (ans+1) / 2;
    cout << ans << endl;
  }
  else{
      cout << 0 << endl;
  }
}

Measured memory_bytes: 1024
import core.bitop, std.algorithm, std.ascii, std.bigint, std.conv,
    std.functional, std.math, std.numeric, std.range, std.stdio, std.string,
    std.random, std.typecons, std.container;

ulong MAX = 1_000_100, MOD = 1_000_000_007, INF = 1_000_000_000_000;
alias sread = () => readln.chomp();
alias lread(T = long) = () => readln.chomp.to!(T);
alias aryread(T = long) = () => readln.split.to!(T[]);
alias Pair = Tuple!(long, "l    ", long, "r");
alias PQueue(T, alias less = "a<b") = BinaryHeap!(Array!T, less);

void main()
{
    long a, b, n;
    scan(a, b, n);
    writeln((a * min(b - 1, n) / b) - a * ((min(b - 1, n) / b)));
}

void scan(TList...)(ref TList Args)
{
    auto line = readln.split();
    foreach (i, T; TList)
    {
        T val = line[i].to!(T);
        Args[i] = val;
    }
}


Measured memory_bytes: 2744
#include <iostream>
#include <algorithm>
#include <string> 
#include <vector>
#include <iomanip>
#include <math.h>
#include <map>
using namespace std;

int main()
{
	int A, B;
	cin >> A >> B;
	if (max(A, B) <= 8) {
		cout << "Yay!" << endl;
	}
	else {
		cout << ":(" << endl;
	}
}

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

#define all(a) a.begin(), a.end()
#define allr(a) a.rbegin(), a.rend()
#define rev(v) reverse(v.begin(), v.end());
#define io() ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); srand(time(NULL));
 
using namespace std;

using ll = long long;
using ld = long double;
using ull = unsigned long long;

signed main(){
    io();
    string s; cin >> s;
    if(s[0] == 'S'){
        if(s[1] == 'A'){
            cout << 1 << '\n';
        }else{
            cout << 7 << '\n';
        }
    }else if(s[0] == 'T'){
        if(s[1] == 'U'){
            cout << 5 << '\n';
        }else{
            cout << 3 << '\n';
        }
    }else if(s[0] == 'W'){
        cout << 4 << '\n';
    }else if(s[0] == 'M'){
        cout << 6 << '\n';
    }else{
        cout << 2 << '\n';
    }
    return 0;
}

Measured memory_bytes: 3616
from collections import defaultdict

def readInt():
  return int(input())
def readInts():
  return list(map(int, input().split()))
def readChar():
  return input()
def readChars():
  return input().split()

h,w = readInts()
s = [list(input()) for i in range(h)]

for i in range(h):
  for j in range(w):
    if s[i][j]=="#":
      if i!=0:
        if j-1>=0:
          if s[i-1][j-1]==".":
            s[i-1][j-1] = 1
          elif s[i-1][j-1]!="#":
            s[i-1][j-1]+=1
        if s[i-1][j]==".":
          s[i-1][j] = 1
        elif s[i-1][j]!="#":
          s[i-1][j]+=1
        if j+1<=w-1:
          if s[i-1][j+1]==".":
            s[i-1][j+1] = 1
          elif s[i-1][j+1] != "#":
            s[i-1][j+1]+=1
      if j-1>=0:
        if s[i][j-1]==".":
          s[i][j-1] = 1
        elif s[i][j-1]!="#":
          s[i][j-1]+=1
      if j+1<=w-1:
        if s[i][j+1]==".":
          s[i][j+1] = 1
        elif s[i][j+1] != "#":
          s[i][j+1]+=1
      if i+1<=h-1:
        if j-1>=0:
          if s[i+1][j-1]==".":
            s[i+1][j-1] = 1
          elif s[i+1][j-1]!="#":
            s[i+1][j-1]+=1
        if s[i+1][j]==".":
          s[i+1][j] = 1
        elif s[i+1][j]!="#":
          s[i+1][j]+=1
        if j+1<=w-1:
          if s[i+1][j+1]==".":
            s[i+1][j+1] = 1
          elif s[i+1][j+1] != "#":
            s[i+1][j+1]+=1

for i in s:
  for j in i:
    if j==".":
      print("0",end="")
    else:
      print(j,end="")
  print()

Measured memory_bytes: 9496
#include<stdio.h>
int main(void){
    int a;
    int b;
    1<=a,b;
    a,b<=10000;
    scanf("%d",&a);
    scanf("%d",&b);
    if((a*b)%2==0){
        printf("Even");
    }else{
        printf("Odd");
    }
    return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <vector>
using namespace std;
int n_town, n_road;
vector<vector<int>> costs;

void fw(vector<vector<int>> &conn_mat)
{
	costs = vector<vector<int>>(n_town, vector<int>(n_town, -1));
	int i(0), j(0);
	for (auto dep : conn_mat)
	{
		j = 0;
		for (int cost : dep)
		{
			if (cost != -1)
			{
				costs[i][j] = cost;
			}
			j++;
		}
		i++;
	}
	for (int k = 0; k < n_town; k++)
	{
		for (int i = 0; i < n_town; i++)
		{
			for (int j = 0; j < n_town; j++)
			{
				if (costs[i][k] != -1 && costs[k][j] != -1) {
					if ((costs[i][j] > costs[i][k] + costs[k][j] && costs[i][j] != -1) || (costs[i][j] == -1))
						costs[i][j] = costs[i][k] + costs[k][j];
				}
			}
		}
	}
}

int main()
{
	char tmp;
	cin >> n_town >> n_road;
	vector<vector<int>> conn_mat(n_town, vector<int>(n_town, -1));
	while (n_road--)
	{
		int dep, dest, cost_go, cost_back;
		cin >> dep >> tmp >> dest >> tmp >> cost_go >> tmp >> cost_back;
		conn_mat[dep - 1][dest - 1] = cost_go;
		conn_mat[dest - 1][dep - 1] = cost_back;
	}
	fw(conn_mat);
	int dep, dest, budget, cost;
	cin >> dep >> tmp >> dest >> tmp >> budget >> tmp >> cost;
	cout << budget - cost - costs[dep - 1][dest - 1] - costs[dest - 1][dep - 1] << endl;
}


Measured memory_bytes: 3072
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll mod = 1000000007;
#define repd(i, a, b) for (ll i = (a); i < (b); i++)
#define rep(i, n) repd(i, 0, n)

int main() {
    int n, m;
    cin >> n >> m;
    ll s[n], t[m];

    rep(i, n) { cin >> s[i]; }
    rep(j, m) { cin >> t[j]; }

    ll dp[n + 1][m + 1];

    rep(i, n + 1) { dp[i][0] = 1; }
    rep(i, m + 1) { dp[0][i] = 1; }

    for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
            if (s[i] == t[j]) {
                dp[i + 1][j + 1] = (dp[i + 1][j] + dp[i][j + 1]) % mod;
            } else {
                dp[i + 1][j + 1] =
                    (dp[i + 1][j] + dp[i][j + 1] - dp[i][j] + mod) % mod;
            }
        }
    }
    cout << dp[n][m] << endl;
}


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

const int N=3e3+100,mod=1e9+7,inv2=(mod+1)>>1;
int n,Q,a[N],f[N][N],fx[N],gx[N],Ans;
void Inc(int &x,int y) {x+=y, x=x>=mod?x-mod:x;}
int qpow(LL x,int y)
{
	LL ret=1;
	while(y)
	{
		if(y&1) ret=ret*x%mod;
		x=x*x%mod, y>>=1;
	}
	return ret;
}

int main()
{
	scanf("%d%d",&n,&Q);
	for(int i=1;i<=n;++i) scanf("%d",&a[i]);
	for(int i=1;i<=n;++i)
		for(int j=1;j<=n;++j)
			f[i][j]=(a[i]>a[j])?1:0;
	for(int q=1;q<=Q;++q)
	{
		int x,y; scanf("%d%d",&x,&y);
		if(x == y) continue;
		for(int i=1;i<=n;++i)
			fx[i]=1ll*inv2*(f[x][i]+f[y][i])%mod,
			gx[i]=1ll*inv2*(f[i][x]+f[i][y])%mod;
		fx[y]=1ll*inv2*(f[x][y]+f[y][x])%mod;
		for(int i=1;i<=n;++i)
			f[x][i]=fx[i], f[i][x]=gx[i],
			f[y][i]=fx[i], f[i][y]=gx[i];
		f[x][y]=f[y][x]=fx[y], f[x][x]=f[y][y]=0;
	}
	for(int i=1;i<=n;++i)
		for(int j=i+1;j<=n;++j) Inc(Ans,f[i][j]);
	Ans=1ll*Ans*qpow(2,Q)%mod; printf("%d",Ans);
	return 0;
}

Measured memory_bytes: 37120
#coding: utf-8
import math
import heapq
import bisect
import numpy as np
from collections import Counter
#from scipy.misc import comb

N,K = map(int, input().split())
A = list(map(int, input().split()))
A.sort()

B = list(Counter(A).values())
B.sort()

ans = 0
for i in range(len(B)-K):
    ans += B[i]

print(ans)

Measured memory_bytes: 41664
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda :sys.stdin.readline().rstrip()
def resolve():
    n=int(input())
    H=list(map(int,input().split()))
    cnt=0
    while(sum(H)):
        flag=False
        for i in range(n):
            if((not flag) and H[i]>0):
                flag=True
            if(flag and H[i]==0):
                break
            if(flag):
                H[i]-=1
        cnt+=1
    print(cnt)
resolve()

Measured memory_bytes: 40940
#include <bits/stdc++.h>
using namespace std;
 
// vector<int> vec(3); = vector<int> vec={0,0,0}
// vec.at()
// sort(num.begin(),num.end(), greater<int>());
// reverse(num.begin(),num.end());
 
// 切り上げ　a/b+1
//  1からNの総和　N*(N+1)/2
 
int main() {
  char c;
  cin >> c;
  
  if(c == 'a' || c == 'i' || c == 'u' || c == 'e' || c == 'o'){
  	cout << "vowel" << endl;
  }
  else{
  	cout << "consonant" << endl;
  }
}

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

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)

long long dp[2][51][2501];

int main() {
	int x[50];
	int n, a;
	cin >> n >> a;
	REP(i, n) cin >> x[i];
	
	dp[0][0][0]++; dp[1][0][0]++;
	REP(i, n) {
		REP(j, n) {
			REP(k, 2501) {
				if (k + x[i] < 2501 && dp[0][j][k] > 0) {
					dp[1][j + 1][k + x[i]] += dp[0][j][k];
				}
			}
		}
		REP(j, n + 1) REP(k, 2501) dp[0][j][k] = dp[1][j][k];
	}
	
	long long ans = 0;
	REP(i, n) ans += dp[0][i + 1][a * (i + 1)];
	cout << ans << endl;
	
	return 0;
}

Measured memory_bytes: 1664
import java.util.*

fun main(args: Array<String>) {
    val sc = Scanner(System.`in`)
    val a = sc.nextInt()
    val b = sc.nextInt()
    val c = sc.nextInt()
    val d = sc.nextInt()
    val e = sc.nextInt()
    val k = sc.nextInt()
    println(problem123a(a, b, c, d, e, k))
}

fun problem123a(a: Int, b: Int, c: Int, d: Int, e: Int, k: Int): String {
    return if (e - a <= k) "Yay!" else ":("
}

Measured memory_bytes: 31136
#include <bits/stdc++.h>
using namespace std;
 
#define rep(i,n) for (int i = 0; i<(n); i++)
#define in(n) cin >> (n)
#define out(ans) cout << (ans) << endl;
#define keta(n) cout << fixed << setprecision((n));
using ll = int64_t;
using v = vector<int>;


int main() {
  double A, B, H, M, jikaku, hunkaku, kakusa, pi, hun;
  cin >> A >> B >> H >> M;
  hun = 60*H+M;
  pi = 4*atan(1.0);
  jikaku = hun*0.5;
  hunkaku = M*6;
  kakusa = min(max(jikaku, hunkaku)-min(jikaku, hunkaku), 360-(max(jikaku, hunkaku)-min(jikaku, hunkaku)));
  kakusa = kakusa*pi/180;
  double ans;
  ans = A*A+B*B-2*A*B*cos(kakusa);
  ans = sqrt(ans);
  keta(20);
  cout << ans << endl;

}

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

using namespace std;
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)

typedef long long ll;
typedef pair<ll, ll> P;
const ll INF = 1LL<<60;

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

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

ll modpow(ll a, ll n, ll mod) {
  ll res = 1;
  while (n > 0) {
    if (n & 1) res = res * a % mod;
    a = a * a % mod;
    n >>= 1;
  }
  return res;
}

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

  int n;
  cin >> n;

  map<ll, int> mp;

  ll sum = 0;
  mp[sum]++;
  rep(i, n){
    ll a;
    cin >> a;
    sum += a;
    mp[sum]++;
  }

  ll ans = 0;

  for(auto p : mp){

    ll cnt = p.second;
    ans += cnt * (cnt-1)/2;
    
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 12800
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
using namespace std;
#define REP(i,m,n) for(int i=(int)m ; i < (int) n ; ++i )
#define rep(i,n) REP(i,0,n)
typedef long long ll;
typedef pair<int,int> pint;
typedef pair<ll,int> pli;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1000003 ;
 
int main(){
  ll x,y;
  cin >> x >> y;
  ll ans=abs(abs(x)-abs(y));
  if(x*y>0 && x>y)ans+=2;
  if(x*y<0)ans++;
  if(x*y==0 && x>y)ans++;
  cout << ans << endl;
return 0;}

Measured memory_bytes: 256
N = int(input())
A = [list(map(int, input().split())) for _ in range(2)]

maximum = 0
for i in range(N):
  result = 0
  result += sum(A[0][0:i+1])
  result += sum(A[1][i:N])  
  maximum = result if maximum < result else maximum
print(maximum)

Measured memory_bytes: 3060
#include <cstdio>
#include <string>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <list>
#include <iterator>
#include <cassert>
#pragma warning(disable:4996) 
 
typedef long long ll;
#define MIN(a, b) ((a)>(b)? (b): (a))
#define MAX(a, b) ((a)<(b)? (b): (a))
#define LINF  9223300000000000000
#define LINF2 1223300000000000000
#define INF 2140000000
const long long MOD = 1000000007;
//const long long MOD = 998244353;

using namespace std;

char str[200005];

void solve()
{
    int n, K, c;
    scanf("%d%d%d%s", &n, &K, &c, str);
    vector<int> flag(n);
    {
        int curr = -INF;
        int i;
        int cnt = 0;
        for (i = 0; i < n; i++) {
            if (str[i] == 'o' && i > curr + c) {
                flag[i] = 1;
                cnt++;
                curr = i;
            }
        }
        if (cnt > K) {
            return;
        }
    }

    vector<int> flag2(n);
    {
        int curr = INF;
        int i;
        int cnt = 0;
        for (i = n-1; i >= 0; i--) {
            if (str[i] == 'o' && i < curr - c) {
                flag2[i] = 1;
                cnt++;
                curr = i;
            }
        }
    }
    int i;
    for (i = 0; i < n; i++) {
        if (flag[i] && flag2[i]) {
            printf("%d\n", i + 1);
        }
    }

    return;
}

int main(int argc, char* argv[])
{
#if 1
    solve();
#else
    int T;
    scanf("%d", &T);
    int t;
    for(t=0; t<T; t++) {
        printf("Case #%d: ", t+1);
        solve();
    }
#endif
    return 0;
}


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

const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)
#define ALL(v) (v.begin(),v.end())
#define COUT(x) cout<<(x)<<endl

int main(){
    int n;
    cin >> n;
    map<string,int> list;
    REP(i,n){
        string t;
        cin >> t;
        sort(t.begin(),t.end());
        list[t]++;
    }
    ll count = 0;
    for(const auto& i:list){
        ll num = i.second;
        if(i.second==1)continue;
        else count += ((num-1)*num)/2;
    }
    COUT(count);
    return 0;
}  


Measured memory_bytes: 11136
#include<bits/stdc++.h>
using namespace std;
#define MAX_N 100005
typedef unsigned long long ull;
ull B=5575777;
ull ans=0;
int n,a,b;
vector<int> G[MAX_N];
unordered_map<ull,ull> mp;

ull dfs(int pos){
  ull res=0;
  for(int to:G[pos])res+=dfs(to);
  res=res*B+1;
  ans+=mp[res]++;
  return res;
}

int main(){
  scanf("%d",&n);
  for(int i=0;i<n-1;i++){
    scanf("%d %d",&a,&b);
    G[a].push_back(b);
  }
  dfs(1);
  printf("%lld\n",ans);
  return 0;
}

Measured memory_bytes: 17104
import sys,queue,math,copy,itertools,bisect,collections,heapq

def main():
    sys.setrecursionlimit(10**7)
    INF = 10**18
    MOD = 10**9 + 7
    LI = lambda : [int(x) for x in sys.stdin.readline().split()]
    NI = lambda : int(sys.stdin.readline())

    H,W = LI()
    M = [sys.stdin.readline().rstrip() for _ in range(H)]

    c = [[0] * W for _ in range(H)]
    q = collections.deque()
    ans = 0
    for i in range(H):
        for j in range(W):
            if c[i][j]: continue

            black = 0; white = 0
            q.append((i,j,M[i][j]))
            c[i][j] = 1
            while q:
                y,x,s = q.popleft()
                if s == '#': black += 1
                else: white += 1
                for dy,dx in ((0,1),(1,0),(0,-1),(-1,0)):
                    if 0 <= y+dy < H and 0 <= x+dx < W:
                        if c[y+dy][x+dx] or M[y+dy][x+dx] == s: continue
                        c[y+dy][x+dx] = 1
                        q.append((y+dy,x+dx,M[y+dy][x+dx]))
            ans += black * white
    print(ans)


if __name__ == '__main__':
    main()

Measured memory_bytes: 46952
import sys


def read_input_line():
    return sys.stdin.readline().strip()


def task(N: int, L: list):
    edges = sorted(L)
    l = len(edges)
    if l < 3:
        return 0
    count = 0
    triples = []
    i = 0
    while i < l:
        j = i + 1
        while j < l:
            if edges[j] != edges[i]:
                _ = [edge for edge in edges[j+1:] if edge != edges[j] and edge < edges[i] + edges[j]]
                triples.extend([[edges[i], edges[j], edge] for edge in _])
                count += len(_)
            j += 1
        i += 1
    return count


def main():
    N = int(read_input_line())
    L = [int(s) for s in read_input_line().split(' ')]
    result = task(N, L)
    print(result)


main()


Measured memory_bytes: 25316
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<cmath>
#include<map>
#include<iomanip>
#include<queue>
#include<stack>
#include<time.h>
#define rep(i,n)for(int i=0;i<n;i++)
#define int long long
#define ggr getchar();getchar();return 0;
#define prique priority_queue
#define mod 1000000007
#define inf 1e15
#define double long double
using namespace std;
typedef pair<int, int>P;
void pyes() { cout << "Yay!" << endl; }
void pno() { cout << ":(" << endl; }
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x % y);
}
int lcm(int x, int y) {
	return x / gcd(x, y) * y;
}
int kai(int x, int y) {
	int res = 1;
	for (int i = x - y + 1; i <= x; i++) {
		res *= i; res %= mod;
	}
	return res;
}
//繰り返し二乗法
int mod_pow(int x, int y, int m) {
	int res = 1;
	while (y) {
		if (y & 1) {
			res = res * x % m;
		}
		x = x * x % m;
		y >>= 1;
	}
	return res;
}
//xCy
int comb(int x, int y) {
	if (y > x)return 0;
	return kai(x, y)* mod_pow(kai(y, y), mod - 2, mod) % mod;
}
int f(int x) {
	int ans = 1;
	for (int i = 1; i <= x; i++) {
		ans *= i;
		ans %= mod;
	}
	return ans;
}
struct edge { int to, cost; };
signed main() {
	int t1, t2;
	int a1, a2, b1, b2;
	cin >> t1 >> t2 >> a1 >> a2 >> b1 >> b2;
	if (t1 * a1 + t2 * a2 == t1 * b1 + t2 * b2)puts("infinity");
	else {
		int p = (a1 - b1) * t1;
		int q = (a2 - b2) * t2;
		int r = t1 * a1 + t2 * a2 - (t1 * b1 + t2 * b2);
		int a = 0;
		if ((p < 0 && r>0) || (p > 0 && r < 0)) {
			if (p % r == 0)cout << abs(p / r - 0) * 2 << endl;
			else cout << (abs(p / r - 0)) * 2 + 1 << endl;
		}
		else cout << 0 << endl;
	}
	ggr
}


Measured memory_bytes: 256
/**
 * Created by hiroqn on 13/10/02.
 */
//var lines = [];
//var reader = require('readline').createInterface({
//  input: process.stdin,
//  output: process.stdout
//});
//reader.on('line', function (line) {
//  lines.push(line);
//});
var input = '';

process.stdin.resume();
process.stdin.setEncoding('utf8');
process.stdin.on('data', function(chunk) {
  input += chunk;
});
process.stdin.on('end', function() {
  input = input.split('\n');
  main();
});
var button = [
  [],
  ['.', ',' , '!' , '?', ' '],
  ['a', 'b', 'c'],
  ['d', 'e', 'f'],
  ['g', 'h', 'i'],
  ['j', 'k', 'l'],
  ['m', 'n', 'o'],
  ['p', 'q', 'r', 's'],
  ['t', 'u', 'v'],
  ['w', 'x', 'y', 'z']
];

function solve(str) {
  var result = '',
      pushed = '',
      times = 0,
      temp;
  for (var i = 0; i < str.length; i++) {
    if (str[i] == '0') {
      if (times !== 0) {
        temp = button[+pushed];

        result += temp[(times- 1) % temp.length ];
      }
      times =0;
    } else {
      pushed = str[i];
      times++;
    }
  }
  return result;
}
function main() {
  var n = +input[0];
  for (var i = 0; i < n; i++) {
    console.log(solve(input[i + 1]));
  }
}

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

using lint = long long int;
using pint = pair<int, int>;
using plint = pair<lint, lint>;
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((lint)(x).size())
#define POW2(n) (1LL << (n))
#define FOR(i, begin, end) for (int i = (begin), i##_end_ = (end); i < i##_end_; i++)
#define IFOR(i, begin, end) for (int i = (end)-1, i##_begin_ = (begin); i >= i##_begin_; i--)
#define REP(i, n) FOR(i, 0, n)
#define IREP(i, n) IFOR(i, 0, n)

int main()
{
    lint n;cin >> n;
    vector<lint> a(n);
    REP(i, n) { cin >> a[i]; }
    lint minus = 0,min_abs=100000000000;
    lint ans = 0;
    REP(i,n){
        minus += (a[i] < 0);
        min_abs = min(min_abs, abs(a[i]));
        ans += abs(a[i]);
    }
    ans -= (minus % 2 == 1) * min_abs*2;

    cout << ans <<"\n";

    return 0;
}

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

int main() {
    int n;
    cin >> n;
    int d[n];
    for (int i = 0; i < n; i++) cin >> d[i];
    sort(d, d + n);
    int res = 1;
    for (int i = 1; i < n; i++) {
        if (d[i] > d[i - 1]) res++;
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 256