akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, j, n) for (int i = j; i < (int)(n); i++)
#define brep(i, n) for (int i = n; i >= 0; i--)
#define BREP(i, j, n) for(int i = n; i > j; i--)
#define TEST cout << "PASS" << endl
#define all(x) (x).begin(),(x).end()
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1e9 + 1e6 + 1e3 + 1;
const ll MOD = 1e9 + 7;
const double PI = 3.141592653589793;

int main(){
    int n, t;
    cin >> n >> t;
    int a[100000];
    rep(i, n) cin >> a[i];
    int M[100000];
    M[n-1] = a[n-1];
    M[n] = -INF;
    for(int i = n-2; i > -1; i--){
        M[i] = max(M[i+1], a[i]);
    }
    int m = -INF;
    map<int, int> mp;
    rep(i, n){
        m = max(m, M[i+1] - a[i]);
        mp[M[i+1] - a[i]]++;
    }
    cout << mp[m] << endl;



}

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

int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	string s;
	cin>>s;
	string S;
	
	for(int i=0 ; i<s.size(); i++)
	{
		if(s[i]=='B')
		{
			if(S.size())
				S.pop_back();	
		}
		else if(s[i]=='1')
			S+="1";
		else
			S+="0";
	}
	
	cout<<S<< endl;
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define eps (1e-10)
using namespace std;
class Point
{
	public:
	double x,y;
	Point(double _x=0,double _y=0):x(_x),y(_y){}
	Point operator + (Point p){ return Point(x+p.x,y+p.y);} 
	Point operator - (Point p){ return Point(x-p.x,y-p.y);}
	Point operator * (double a){return Point(a*x,a*y);} 
	Point operator / (double a){return Point(x/a,y/a);}
	double norm(){return x*x+y*y;}
	double ABS(){return sqrt(norm());} 
};
struct Segment
{
	Point p1,p2;	
};
//判断是否正交 向量内积：a*b=|a||b|*cos(Y) 当cos为0时正交(90,-90垂直) 
//a*b=a.x*b.x+a.y*b.y;
bool solve1(Point a,Point b)
{
	double f=a.x*b.x+a.y*b.y; 
	if(fabs(f-0.0)<eps) return true;
	else return false;
}
//判断是否平行  向量外积：|a*b|=|a||b|sin(Y) 当sin为0时平行(180,0平行)
//|a*b|=|a|*|b|*sin(Y) 
bool solve2(Point a,Point b)
{
	double f=a.x*b.y-a.y*b.x;
	if(fabs(f-0.0)<eps) return true;
	else return false;
}
double dot(Point a,Point b)
{
	return a.x*b.x+a.y*b.y;
}
/*
求垂足x：对于给定的三点p1,p2,p从点p向通过p1,p2的直线引一条垂线
base=p2-p1;
hypo=p-p1;
 x=s.p1+base*(hypo*base/|base|^2); hypo*base 可以用向量内积求 
*/
Point solve3(Segment s,Point p)
{
	Point base=s.p2-s.p1;
	double r=dot(p-s.p1,base)/base.norm();
	return s.p1+base*r; 
}
int main()
{
	double x1,y1,x2,y2;
	scanf("%lf %lf %lf %lf",&x1,&y1,&x2,&y2);
	Point p1(x1,y1),p2(x2,y2);
	Segment s;
	s.p1=p1,s.p2=p2;
	int T;scanf("%d",&T);
	while(T--){
		double x,y;scanf("%lf %lf",&x,&y);
		Point p(x,y);
		Point w=solve3(s,p);
		printf("%.10f %.10f\n",w.x,w.y);
		
	}
	return 0;
}



Measured memory_bytes: 3236
s=list(input())
l=len(s)
ma=0
pr=0
for i in range(l):
  if s[i]=='A' or s[i]=='G' or s[i]=='T' or s[i]=='C':
    ma +=1
    pr=max(pr,ma)
  else:
    ma=0
print(pr)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
constexpr int Inf = 1000000010;
constexpr ll INF= 5000000000000000000;
constexpr ll MOD = 1000000007;
const double PI = 3.1415926535897;
typedef pair<ll,ll> P;

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

ll mod(ll val) {
    ll res = val % MOD;
    if(res < 0) {
        res += MOD;
    }
    return res;
}

// N^P mod M（ただしM == -1の時はmodを取らない）
template<typename T>
T RS(T N, T P, T M){
    if(P==0) return 1;
    if(P < 0) return 0;
    if(P%2==0){
        ll t = RS(N, P/2, M);
        if(M == -1) return t * t;
        return t * t % M;
    }
    if(M == -1) return N * RS(N,P - 1,M);
    return N * RS(N, P-1, M) % M;
}

int main() {
    ll N,Z,W;
    cin >> N >> Z >> W;
    vector<ll> vec(N);
    for(int i = 0;i < N;i++) {
        cin >> vec.at(i);
    }
    ll ret = abs(W - vec.at(N - 1));
    if(N > 1) {
        chmax(ret,abs(vec.at(N - 2) - vec.at(N - 1)));
    }
    cout << ret << endl;
}

Measured memory_bytes: 3556
import java.util.ArrayDeque;
import java.util.Arrays;
import java.util.Deque;

public class Main {
  private static void solve() {
    int n = ni();
    long[] a = nal(n);
    long[] b = nal(n);

    Deque<Integer> q = new ArrayDeque<>();

    for (int i = 0; i < n; i++) {
      q.add(i);
    }

    long ret = 0;
    while (q.size() > 0) {
      int i = q.pollFirst();
      int l = (i - 1 + n) % n;
      int r = (i + 1) % n;

      if (b[i] < a[i]) {
        System.out.println(-1);
        return;
      }

      long sum = b[l] + b[r];
      long x = (b[i] - a[i]) / sum;
      ret += x;
      b[i] -= x * sum;

      if (x > 0) {
        q.add(l);
        q.add(r);
      }
    }
    System.out.println(Arrays.equals(a, b) ? ret : -1);
  }

  public static void main(String[] args) {
    new Thread(null, new Runnable() {
      @Override
      public void run() {
        long start = System.currentTimeMillis();
        String debug = args.length > 0 ? args[0] : null;
        if (debug != null) {
          try {
            is = java.nio.file.Files.newInputStream(java.nio.file.Paths.get(debug));
          } catch (Exception e) {
            throw new RuntimeException(e);
          }
        }
        reader = new java.io.BufferedReader(new java.io.InputStreamReader(is), 32768);
        solve();
        out.flush();
        tr((System.currentTimeMillis() - start) + "ms");
      }
    }, "", 64000000).start();
  }

  private static java.io.InputStream is = System.in;
  private static java.io.PrintWriter out = new java.io.PrintWriter(System.out);
  private static java.util.StringTokenizer tokenizer = null;
  private static java.io.BufferedReader reader;

  public static String next() {
    while (tokenizer == null || !tokenizer.hasMoreTokens()) {
      try {
        tokenizer = new java.util.StringTokenizer(reader.readLine());
      } catch (Exception e) {
        throw new RuntimeException(e);
      }
    }
    return tokenizer.nextToken();
  }

  private static double nd() {
    return Double.parseDouble(next());
  }

  private static long nl() {
    return Long.parseLong(next());
  }

  private static int[] na(int n) {
    int[] a = new int[n];
    for (int i = 0; i < n; i++)
      a[i] = ni();
    return a;
  }

  private static char[] ns() {
    return next().toCharArray();
  }

  private static long[] nal(int n) {
    long[] a = new long[n];
    for (int i = 0; i < n; i++)
      a[i] = nl();
    return a;
  }

  private static int[][] ntable(int n, int m) {
    int[][] table = new int[n][m];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        table[i][j] = ni();
      }
    }
    return table;
  }

  private static int[][] nlist(int n, int m) {
    int[][] table = new int[m][n];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        table[j][i] = ni();
      }
    }
    return table;
  }

  private static int ni() {
    return Integer.parseInt(next());
  }

  private static void tr(Object... o) {
    if (is != System.in)
      System.out.println(java.util.Arrays.deepToString(o));
  }
}


Measured memory_bytes: 72896
#include <bits/stdc++.h>
using namespace std;
#define e1 first
#define e2 second
#define pb push_back
#define mp make_pair
#define boost ios_base::sync_with_stdio(false)
#define eb emplace_back
#define OUT(x) {cout << x; exit(0); }
#define FOR(i,a,b) for(int i=(a);i<=(b);++i)
#define scanf(...) scanf(__VA_ARGS__)?:0
typedef long long int ll;
typedef unsigned long long ull;
typedef pair <int, int> PII;
typedef pair <ll, ll> PLL;
typedef pair <PLL, int> PLLI;
typedef pair <PLL, PLL> PP;
typedef pair <PII, int> PPI;
typedef pair <ll, int> PLI;
typedef unsigned int ui;
const int inf = 1e9+9;
const int mod = 924844033;
const ll INF = 1e18;
int n, m;
#define maxn 1010

ll tab[maxn], tmp[maxn];

ll bs(ll co, ll ode)
{
	if (co < n) return 0;
	ll x = 0, y = 2e16;
	while (x < y)
	{
		//cout << x << ' ' << y << ' ' << co << ' ' << ode << endl;
		ll sr = (x + y)/2;
		if (co - sr * ode >= n) x = ++sr;
		else y = sr;
	}
	//cout << "Bins: " << co << ' ' << ode << ' ' << x << endl;
	return x;
}

bool check(ll k)
{
	ll ode = n + 1;
	FOR(i, 1, n) tmp[i] = tab[i] + k;
	ll trzeba = 0;
	FOR(i, 1, n) trzeba += bs(tmp[i], ode);
	if (trzeba <= k) return 1;
	return 0;
}

int main()
{
	boost;
	cin >> n;
	FOR(i, 1, n) cin >> tab[i];
	ll x = 0, y = INF;
	//cout << check(1) << endl;
	while (x < y)
	{
		ll sr = (x + y) / 2LL;
		bool odp = 0;
		FOR(j, 0, 2500)
		{
			if (sr - j < x) break;
			if (check(sr - j)) odp = 1;
		}
		if (odp == 0) x = ++sr;
		else y = sr;
	}
	cout << x;
}


Measured memory_bytes: 384
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {

	public static void main(String[] args) throws Exception{

		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		
		String s = br.readLine();
		int n = s.length();
		
		if(n == 2)
		{
			if(s.charAt(0) == s.charAt(1))
			{
				System.out.println(1+" "+2);
				return;
			}
		}
		for(int i=0;i+3<n;i++)
		{
			if(s.charAt(i) == s.charAt(i+1) || s.charAt(i+1) == s.charAt(i+2) || s.charAt(i) == s.charAt(i+2))
			{
				System.out.println((i+1)+" "+(i+3));
				return;
			}
		}
		System.out.println(-1+" "+(-1));
	}
}

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

constexpr double EPS = 1e-10;
using Point = complex<double>;
double cross(Point p, Point q) { return (conj(p) * q).imag(); }

int main() {
    cin.tie(0); ios_base::sync_with_stdio(false);
    double a,b,c,d,e,f,g,h;
    char z;
    while(cin>>a>>z>>b>>z>>c>>z>>d>>z>>e>>z>>f>>z>>g>>z>>h) {
        Point p1(a,b),p2(c,d),p3(e,f),p4(g,h);
        if(cross(p3-p1,p2-p1)*cross(p4-p2,p3-p2) > 0 && cross(p1-p3,p4-p3) * cross(p2-p4, p1-p4) > 0){
            cout << "YES" << '\n';
        } else {
            cout << "NO" << '\n';
        }
    }

    return 0;
}


Measured memory_bytes: 3208
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define rep(i,b) FOR(i,0,b)
#define INF mugen
#define dump(x) cerr<<#x<<"="<<x<<endl
#define all(a) (a).begin(),(a).end()
typedef vector<int> V;
typedef vector<V> VV;
typedef vector<VV> VVV;
template <class T> void chmin(T & a, T const & b) { if (b < a) a = b; }

using ll = long long;
const ll mod = LLONG_MAX;

int A[11];
ll ans=1;
int main(){
 int N;
 cin>>N;
 ll ret=1;
 rep(i,N){
   cin>>A[i];
   if(A[i]%2==0){
     ret*=2;
   }else{
     ret*=1;
   }
 }

 rep(i,N){
   ans*=3;
 }

 cout<<ans-ret<<endl;




}


Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS

#include<fstream>
#include<iostream>
#include<string>
#include<iomanip>
#include<list>
#include<math.h>
#include<stack>
#include<queue>
#include<vector>
#include<algorithm>
#include<utility>

using namespace std;

int main(int argc, char **argv){
	int n;
	int a;
	int lcm = 1;
	cin >> n;
	for (int i = 0; i < n; i++)
	{
		cin >> a;
		for (int j = 1; j <= lcm; j++) {
			if ((a * j) % lcm == 0) {
				lcm = a * j;
				break;
			}
		}
	}
	cout << lcm << endl;
	return 0;
}

Measured memory_bytes: 1164
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<string>
#include<stack>
#include<queue>
#include<vector>
#include<algorithm>
#include<iomanip>
#include<set>
#include<unordered_set>
#include<map>
typedef long long int ll;
using namespace std;
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define REP(i,n) for (int i=0;i<(n);i++)
#define EREP(i,n) for (int i=1;i<=(n);i++)
#define ALL(a) (a).begin(),(a).end()
//#define EVEL 1

#ifdef EVEL
#define DEB(X) cout << #X << ":" <<X<<" " ;
#define TF(f) f ? cout<<"true  " : cout<<"false ";
#define END cout<<"\n";
#else
#define DEB(X) {}
#define TF(f) {}
#define END {}
#endif
const ll MOD = 1000000007;
const int INF = 2000000000;
    ll N,M,K;
    ll A[100010],B,C,X;
    bool F=true;
    ll ans=0;
    string S,T[200000];

int main(){
    ios_base::sync_with_stdio(false);
    cin>>N;
        EREP(i,100)EREP(j,100)EREP(k,100){
                if(i*i+j*j+k*k+i*j+j*k+k*i<=N){
                    A[i*i+j*j+k*k+i*j+j*k+k*i-1]++;
                }
        }
        REP(i,N){
            std::cout << A[i] << '\n';
        }


    return 0;
}


Measured memory_bytes: 9872
# from https://atcoder.jp/contests/dp/submissions/4751518
import sys
input=sys.stdin.readline
from collections import deque

def check(l0,l1,l2):
    return (l2[1]-l1[1])*(l1[0]-l0[0])>=(l1[1]-l0[1])*(l2[0]-l1[0])

def f(l,x):
    return l[0]*x+l[1]

def add_line(a,b):
    while len(deq)>=2 and check(deq[-2],deq[-1],(a,b)):
        deq.pop()
    deq.append((a,b))

def query(x):
    while len(deq)>=2 and f(deq[0],x)>=f(deq[1],x):
        deq.popleft()
    return f(deq[0],x)


n,c=map(int,input().split())
h=[int(i) for i in input().split()]
d=[0]*n
deq=deque()
add_line(-2*h[0],h[0]**2+d[0])
for i in range(1,n):
    d[i]=query(h[i])+h[i]**2+c
    add_line(-2*h[i],h[i]**2+d[i])
print(d[-1])


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

#define int long long

#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;

template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

signed main(){
    int a,b,c;
    cin>>a>>b>>c;
    if(a<=c&&c<=b)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    return 0;
}


Measured memory_bytes: 256
# AOJ 1574: Gossip
# Python3 2018.7.13 bal4u

n, m = map(int, input().split())
a = list(map(int, input().split()))
pre = a[0]; d = 0
for x in a[1:]:
	d = max(d, x-pre)
	pre = x
print(max(n-pre, max(d>>1, a[0]-1)))


Measured memory_bytes: 9404
n=int(input())
H=list(map(int,input().split()))
A=[float("inf")]*n
for i in range(n):
  if i==0:
    A[i]=0
  elif i==1:
    A[i]=abs(H[i]-H[i-1])
  else:
    A[i]=min(A[i-2]+abs(H[i]-H[i-2]),A[i-1]+abs(H[i]-H[i-1]))
print(A[n-1])

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

constexpr ll mod = 1000000000 + 7;
#define NMAX 100010

/*
How to use:
- input :   std::string
- output :  std::vector<std::pair<char, long long>>
    - first:    character
    - second:   count

Note that any element of input must not be -1.
*/
vector<pair<char,ll>> run_length_encoding(string s){
    vector<pair<char,ll>> res;
    ll n = s.size();
    char prev = -1;
    ll cur = 1;
    for(ll i = 0; i < n; i++) {
        if(prev == s[i]) cur++;
        else {
            if(prev != -1) res.push_back({prev, cur});
            prev = s[i];
            cur = 1;
        } 
    }
    res.push_back({prev, cur});
    return res;
}

vector<ll> rec(30, -1);

ll dfs(vector<vector<ll>> &a, ll itr) {
    if(itr == 26) return 1;
    if(rec[itr] != -1) return rec[itr];
    ll res = 0;
    for(auto e : a[itr]) {
        res += e * dfs(a, itr+1);
        res %= mod;
    }
    return rec[itr] = res;
}

int main(){
    ll n;
    string s;
    cin >> n >> s;
    auto v = run_length_encoding(s);
    vector<vector<ll>> a(26);
    rep(i, 0, 26) a[i].push_back(1);
    for(auto e : v) {
        a[e.first-'a'].push_back(e.second);
    }
    cout << (dfs(a, 0)-1+mod)%mod << endl;
    return 0;
}

Measured memory_bytes: 5704
// g++ -std=c++17 -o2 -Wall .\testing.cpp -o test

#include <bits/stdc++.h>
using namespace std;

int main()
{
  int N;
  cin>>N;
  int a[N], b[N], c[N];
  for(int i=0; i<N; i++)
    cin>>a[i]>>b[i]>>c[i];

  int Dp[]={a[0],b[0], c[0]};
  int M[]={0,0,0};
  for(int i=1; i<N; i++)
  {
    M[0] = max(a[i]+Dp[1], a[i]+Dp[2]);
    M[1] = max(b[i]+Dp[0], b[i]+Dp[2]);
    M[2] = max(c[i]+Dp[0], c[i]+Dp[1]);
    for(int i=0; i<3; i++)
      Dp[i]=M[i];
  }
  cout<<*max_element(Dp, Dp+3);

}


Measured memory_bytes: 4804
#include<bits/stdc++.h>
using namespace std;
int main()
{int n;
 cin>>n;
 
 if(n%1000==0)
   cout<<"0\n";
 else
 {
   int k=n/1000+1;
   cout<<k*1000-n;
 }
 return 0;
}

Measured memory_bytes: 3616
#include <bits/stdc++.h>
#include <string.h>
#define rep(i, n) for(int i = 0; i<(n); i++)
using namespace std;
typedef long long ll;
static const int MAX = 200000; 
//pi = 3.14159265358979323846

int main() {

    int n;
    cin >> n;
    int count = 0;

    for(int i = 1; i <= n; i++){
        if(1 <= i && i < 10) count++;
        if(100 <= i && i < 1000) count++;
        if(10000 <= i && i < 100000) count++;
    }
    cout << count << endl;

}




Measured memory_bytes: 256
#include <iostream>
#include <cstdlib>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <functional>
using namespace std;

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

    s[k-1] = s[k-1] - ('A'-'a');
    cout << s << endl;
    return 0;
}


Measured memory_bytes: 888
#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  for(int i=0;i<(n);++i)
#define FORq(i, m, n) for(int i = (m);i <= (n);++i)
#define SCD(n) scanf("%d",&n)
#define SCD2(m,n) scanf("%d%d",&m,&n)
#define SCD3(m,n,k) scanf("%d%d%d",&m,&n,&k)
#define PB push_back
#define MP make_pair
#define ARSCD(A,N) REP(i,N){SCD(A[i]);}
#define ARSCD1(A,N) FORq(i,1,N){SCD(A[i]);}
#define PRINTD(n) printf("%d\n",n)
#define PRINTLLD(n) printf("%lld\n",n)
#define DEBUG printf("%s\n","debug")
#define fst first
#define snd second
#define IN(x,S) (S.count(x) != 0)
using namespace std;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef long long ll;
//////////////////////////////////////////////////////
const int p = 1000000007;
long long intpow(int x,int y){
	if (y == 0) return 1;
	long long xx = x;
	long long xin = x;
	REP(i,y-1){
		xx = (xx * xin)%p;
	}
	return xx;
}

int main(){
	int N; SCD(N);
	vector<int> A;
	
	REP(i,N){
		int x; SCD(x);
		A.PB(x);
	}
	
	sort(A.begin(),A.end());
	
	if (N % 2 == 0){ ///////even
		REP(i,N/2){
			if ((A[2*i] != 2*i+1) or (A[2*i+1] != 2*i+1)){
				PRINTD(0);
				return 0;
			}
		}
		
		PRINTD(intpow(2,N/2) % p);
		
		
	}else{ //////odd
		if (A[0] != 0) {
			PRINTD(0);
			return 0;
		}
		
		REP(i,(N-1)/2){
			if ((A[2*i+1] != 2*(i+1)) or (A[2*i+2] != 2*(i+1))){
				PRINTD(0);
				return 0;
			}
		}
		
		PRINTD(intpow(2,(N-1)/2) % p);
		
		
	}
	
	return 0;
}

Measured memory_bytes: 892
n, m = map(int, input().split())

a = []
b = []

for i in range(n):
    a.append(list(map(int, input().split())))
for i in range(m):
    b.append(int(input()))

sum = 0
    
for i in range(n):
    for j in range(m):
        sum += a[i][j]*b[j]
    print(sum)
    sum = 0



Measured memory_bytes: 6008
while True:
    (H, W) = [int(i) for i in input().split()]
  
    if H == W == 0:
        break
  
    for i in range(H):
        for r in range(W):
            if (i + r) % 2 == 0:
                print('#', end='')
            else:
                print('.', end='')
            #print('#', end='') if (i + r) % 2 == 0 else print('.', end='')
        print()
    print()

Measured memory_bytes: 9084
import java.util.Scanner;

public class Main{
	public static void main(String[] args)
	{
		Scanner sc =new Scanner(System.in);
		int g_a=0,g_b=0,g_c=0;

		for(int i=0;i<2;i++){
			int a=sc.nextInt();
			if(a==1 || a==3 || a==5 || a==7 || a==8 || a==10 || a==12) g_a++;
			else if(a==4 ||a==6 ||a==9 ||a==11 ) g_b++;
			else if(a==2) g_c++;

		}
		
		if(g_a==2 || g_b==2 || g_c==2) System.out.println("Yes");
		else System.out.println("No");
	}
} 

Measured memory_bytes: 21972
import java.util.Scanner;

public class Main {

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

        int N = sc.nextInt();
        int M = sc.nextInt();
        int Q = sc.nextInt();

        ABCD[] abcd = new ABCD[Q];
        for (int i = 0; i < Q; i++) {
            int a = sc.nextInt();
            int b = sc.nextInt();
            int c = sc.nextInt();
            int d = sc.nextInt();
            abcd[i] = new ABCD(a, b, c, d);
        }
        sc.close();

        System.out.println(solve(N, M, abcd));
    }

    public static long solve(int N, int M, ABCD[] abcd) {

        int times = (int) Math.pow(2, N + M + 1);

        long ans = 0;
        for (int i = 0; i <= times; i++) {
            int[] A = getA(i, N, M);
            if (A == null) {
                continue;
            }

            long tempAns = 0;
            for (int j = 0; j < abcd.length; j++) {
                ABCD hoge = abcd[j];
                if (A[hoge.b - 1] - A[hoge.a - 1] == hoge.c) {
                    tempAns += hoge.d;
                }
            }

            ans = Math.max(ans, tempAns);
        }
        return ans;
    }

    public static int[] getA(int x, int N, int M) {

        int[] A = new int[N];
        int A_index = 0;
        A[0] = 1;
        for (int xi = 1; xi <= N + M; xi++) {
            if (x % 2 == 1) {
                if (A_index >= N) {
                    return null;
                }
                A[A_index]++;
            } else {
                A_index++;
                if (A_index < N) {
                    A[A_index] = A[A_index - 1];
                }
            }
            x /= 2;
        }

        if (A[N - 1] != M) {
            return null;
        }

        return A;
    }

}

class ABCD {
    int a;
    int b;
    int c;
    int d;

    public ABCD(int a, int b, int c, int d) {
        super();
        this.a = a;
        this.b = b;
        this.c = c;
        this.d = d;
    }
}


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

int main() {
    ll N;
    cin >> N;
    string ans ="";

    while(N>0){
        N--;
        int s = N%26;
        ans += char('a'+s);
        N-= s;
        N/=26;
    }
    reverse(ans.begin(),ans.end());
    cout << ans << endl;
    return 0;
}

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

#define ll long long
#define INF_LL 1LL << 60
#define INF 99999999
#define MOD (ll)1000000007
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define REP(i, a, n) for(int i = a; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()

void put_double(double obj){printf("%.12f\n",obj);};

template < typename T > std::string to_string( const T& n )
{
    std::ostringstream stm ;
    stm << n ;
    return stm.str() ;
}

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


int main()
{
    int A,B;
    cin >> A >> B;

    cout << max(A+B, max(A-B, A*B)) << endl;

}


Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define rep(i, n) for(int(i) = 0; (i) < (n); (i)++)
#define FOR(i, m, n) for(int(i) = (m); (i) < (n); (i)++)
#define All(v) (v).begin(), (v).end()
#define pb push_back
#define MP(a, b) make_pair((a), (b))
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
const int INF = 1 << 30;
const ll LINF = 1LL << 60;
const int MOD = 1e9 + 7;

int main() {
    int H, A;
    cin >> H >> A;
    cout << H / A + !!(H % A) << endl;

    return 0;
}

Measured memory_bytes: 256
/******************************************
 *  Author : Atul Anand   
 *  Created On : Sat Feb 08 2020
 *******************************************/

import java.io.*;
import java.util.*;

public class Main{
    
    public static void main(String[] args) throws IOException {
        int N=in.nextInt();
        int h[]=new int[N];
        read(h, N);
        int cost[]=new int[N];
        cost[0]=0;
        cost[1]=Math.abs(h[0]-h[1]);
        for(int i=2;i<N;i++){
            cost[i]=Math.min(cost[i-1]+Math.abs(h[i-1]-h[i]), cost[i-2]+Math.abs(h[i-2]-h[i]));
        }
        println(cost[N-1]);
        in.close();
        out.close();
    }

    static int MIN = Integer.MIN_VALUE;
    static int MAX = Integer.MAX_VALUE;
    static Reader in = new Reader();
    static PrintWriter out = new PrintWriter(System.out);
    static void read(int arr[], int N) throws IOException{ for(int i=0;i<N;i++){ arr[i]=in.nextInt(); } }
    static void read(long arr[], int N) throws IOException{ for(int i=0;i<N;i++){ arr[i]=in.nextLong(); } }
    static void read(String arr[], int N) throws IOException{ for(int i=0;i<N;i++){ arr[i]=in.next(); } }
    static void print(Object O){ out.print(O); }
    static void println(Object O){ out.println(O); }
    static void print(int arr[]){ for(int i=0;i<arr.length;i++){ print(arr[i]+" "); } println(""); }
    static void print(int arr[][]){ for(int i=0;i<arr.length;i++){ print(arr[i]); } }
    static void debug(Object O){ System.out.println(O); }
}

class Reader {
    BufferedReader reader;
    StringTokenizer tokenizer;

    Reader() {
        reader = new BufferedReader(new InputStreamReader(System.in));
        tokenizer = new StringTokenizer("");
    }

    String next() throws IOException {
        while (!tokenizer.hasMoreTokens() ) { tokenizer=new StringTokenizer(reader.readLine()); }
        return tokenizer.nextToken();
    }

    int nextInt() throws IOException { return Integer.parseInt(next()); }
    double nextDouble() throws IOException { return Double.parseDouble(next()); }
    long nextLong() throws IOException { return Long.parseLong(next()); }
    String nextLine() throws IOException { return reader.readLine(); }
    void close() throws IOException { reader.close(); }
}

Measured memory_bytes: 32228
#define _USE_MATH_DEFINES

#include <iostream>
#include <string>
#include <sstream>
#include <iomanip>
#include <cmath>
#include <algorithm>
#include <utility>
#include <vector>
#include <numeric>

using namespace std;

struct Circle
{
	double x, y;
	double r;
};

int hit(Circle c0, Circle c1)
{
	double x = (c1.x - c0.x);
	double y = (c1.y - c0.y);

	double d = sqrt(x * x + y * y);
	if (d <= c0.r + c1.r)
	{
		if (c0.r + d < c1.r)
		{
			return -2;
		}
		else if (c1.r + d < c0.r)
		{
			return 2;
		}
		else
		{
			return 1;
		}
	}
	else
	{
		return 0;
	}
}

int main()
{
	int n;
	for (cin >> n; n--;)
	{
		Circle c0, c1;
		cin >> c0.x >> c0.y >> c0.r;
		cin >> c1.x >> c1.y >> c1.r;

		cout << hit(c0, c1) << endl;
	}
}


Measured memory_bytes: 3152
x,k,d = map(int,input().split())

x = abs(x)

if k * d <= x:
    print(abs(x - k * d))
else:
    point = x % d
    cnt = x // d
    if((k - cnt) % 2 == 0):
        print(point)
    else:
        print(abs(point-d))

Measured memory_bytes: 9096
package main

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

var sc = bufio.NewScanner(os.Stdin)

func main() {
	sc.Split(bufio.ScanWords)

	s := nextStr()

	for i, si := range s {
		if (i+1)%2 == 0 {
			// 偶数文字目がすべて L, U, D のいずれか。
			if si == 'R' {
				fmt.Println("No")
				return
			}
		} else {
			// 奇数文字目がすべて R, U, D のいずれか。
			if si == 'L' {
				fmt.Println("No")
				return
			}

		}
	}

	fmt.Println("Yes")
}

// ---- readfunc
func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}
func nextStr() string {
	sc.Scan()
	return sc.Text()
}


Measured memory_bytes: 1772
# -*- coding:utf-8 -*-

import sys

def solve_eq(a,b,c,d,e,f):
    x = ((e*c)-(b*f))/((a*e)-(b*d))
    y = ((a*f)-(c*d))/((a*e)-(b*d))
    if x == -0:
        x = 0
    if y == -0:
        y = 0
        
    sol = [x,y]
    return sol

array = []
for i in sys.stdin:
    array.append(i)

a = [0]*6
for i in range(len(array)):
    x = array[i].split()
    for i in range(len(x)):
        a[i] = float(x[i])

    ans = solve_eq(a[0],a[1],a[2],a[3],a[4],a[5])
    print("{0:0.3f}".format(ans[0]), "{0:0.3f}".format(ans[1]))

Measured memory_bytes: 7532
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Scanner;

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

    int N = scanner.nextInt();
    int K = scanner.nextInt();

    HashMap<Integer, Integer> map = new HashMap<>();
    for (int i = 0; i < N; i++) {
      int a = scanner.nextInt();
      map.put(a, map.getOrDefault(a, 0) + 1);
    }
    List<Integer> counts = new ArrayList<>(map.values());
    Collections.sort(counts);

    int res = 0;
    for (int i = 0; i < counts.size() - K; i++) res += counts.get(i);
    System.out.println(res);
  }
}


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

using i32 = int_fast32_t;
using i64 = int_fast64_t;

int main() {
    string s;
    cin >> s;
    auto itr = unique(begin(s), end(s));
    cout << (itr - begin(s) != 1 ? "Yes" : "No") << endl;
}


Measured memory_bytes: 256
# -*- coding: utf-8 -*-
n = int(input())
S = list(map(int, input().split()))
q = int(input())
T = list(map(int, input().split()))

# 二分探索
def binary_search(x: int) -> bool:
    low = 0
    high = len(S) - 1
    while low <= high:
        mid = (low + high) // 2
        guess = S[mid]
        if guess == x:
            return True
        if guess < x:
            low = mid + 1
        else:
            high = mid - 1
    return False

# 求解処理
ans = 0
for t in T:
    ans += binary_search(t)

# 結果出力
print(ans)


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

typedef long long ll;

using namespace std;

ll gcd(ll a, ll b)
{
    if (a < b) swap(a, b);

    ll c;
    while ((c=a%b))
    {
        a = b;
        b = c;
    }

    return b;
}

int main()
{
    ll x, y;
    cin >> x >> y;

    cout << gcd(x, y) << endl;

    return 0;
}



Measured memory_bytes: 3116
#include <iostream>
#include <string>
#include <vector>
#include <list>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <fstream>
#include <sstream>
#include <iomanip>
#define ll long long

using namespace std;

long long MOD = 1000000007;

int main(){
    int N;
    cin >> N;
    
    ll ans=0;
    vector<ll> cnt(100001,0);
    for(int i=0; i<N; i++){
        ll a;
        cin >> a;
        ans+=a;
        cnt[a]++;
    }

    int Q;
    cin >> Q;
    for(int i=0; i<Q; i++){
        ll b, c;
        cin >> b >> c;
        ans+=(c-b)*cnt[b];
        cnt[c]+=cnt[b];
        cnt[b]=0;
        cout << ans << endl;
    }
}

Measured memory_bytes: 4032
import sys
input = sys.stdin.readline
N = int(input())
a = list(map(int, input().split()))
xsm = 0
sm = a[0] + a[1]

for i in range(2, N): xsm ^= a[i]
t = sm - xsm
table = [0] * 41
for i in range(40, -1, -1):
  if t >= 1 << (i + 1):
    t -= 1 << (i + 1)
    table[i] = 1
if t:
  print(-1)
  exit(0)


t = a[0]
res = 0
for i in range(40, -1, -1):
  if t >= 1 << i:
    if table[i]:
      t -= 1 << i
      res += 1 << i
for i in range(40, -1, -1):
  if t >= 1 << i:
    if xsm & (1 << i):
      t -= 1 << i
      res += 1 << i
if res == 0 or (res ^ (sm - res) != xsm): print(-1)
else: print(a[0] - res)

Measured memory_bytes: 62072
#include <iostream>
#include <vector>
#include <cmath>
#include <sstream>

using namespace std;

int initv = pow(10, 9);
vector< vector<int> > segment_tree;
pair<int, int> dummy = make_pair(-1, initv);

pair<int, int> query(int a, int b, int k, int l, int r){
	if(r<=a || b<=l) return dummy;
	if(a<=l && r<=b) return make_pair(segment_tree[k][0], segment_tree[k][1]);

	pair<int, int> vl, vr;
	vl = query(a, b, k*2+1, l, int((l+r)/2));
	vr = query(a, b, k*2+2, int((l+r)/2), r);
	if(vl.second < vr.second) return vl;
	else return vr;
}


int main(void){

	// input N & L
	int n, l;
	cin >> n >> l;
	cin.ignore();

	int n_ = 1;
	while(n_ < n){
		n_ *= 2;
	}

	
	segment_tree = vector< vector<int> >(2*n_-1, vector<int>(2, initv)); // makesegment tree

	string s;
	getline(cin, s); // input series
	stringstream ss;
	ss << s;

	// take in input to segment tree
	for(int i=0 ; i < n ; i++){
		int a;
		ss >> a;
		segment_tree[n_-1+i][0] = i;
		segment_tree[n_-1+i][1] = a;
	}

	// initialize segment tree
	for(int i = n_-2 ; i >= 0 ; i--){
		if(segment_tree[i*2+1][1] < segment_tree[i*2+2][1]){
			segment_tree[i][0] = segment_tree[i*2+1][0];
			segment_tree[i][1] = segment_tree[i*2+1][1];
		}
		else{
			segment_tree[i][0] = segment_tree[i*2+2][0];
			segment_tree[i][1] = segment_tree[i*2+2][1];
		}
	}


	pair<int, int> current_min;
	current_min = dummy; // current_min[0]:id of current min, current_min[1]:value of current min
	for(int i=0 ; ; i++ ){

		// if current_min is out of range, search new current_min
		if(current_min.first < i){
			current_min = query(i, i+l, 0, 0, n_);
		}

		// else, compare current_min and new end
		else{
			if(current_min.second >= segment_tree[n_+i+l-2][1]){
				current_min = make_pair(segment_tree[n_+i+l-2][0], segment_tree[n_+i+l-2][1]);
			}
		}

		cout << current_min.second;

		if(i+l == n){
			cout << endl;
			break;
		}
		else cout << ' ';
	}

}


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

int main()
{
    int n;
    cin >> n;
    int num = 0;
    int a = n / 1000;
    int b = (n - 1000 * a) / 100;
    int c = (n - 1000 * a - 100 * b) / 10;
    int d = n % 10;
    if(a == 2) num++;
    if(b == 2) num++;
    if(c == 2) num++;
    if(d == 2) num++;
    cout << num << endl;
    return 0;
}

Measured memory_bytes: 256
# N = int(input())
# A = [int(x) for x in input().split()]
# V = [[0] * 100 for _ in range(100)]

N = int(input())

L = []
for i in range(N):
    S, P = input().split()
    L.append((S, int(P), i))

L.sort(key=lambda x: (x[0], -x[1]))

for i in L:
    print(i[2] + 1)


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
  #define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  #define int long long
  #define endl "\n"
  #define all(v) v.begin(),v.end()
  #define double long double
  #define trace1(x)                cerr<<#x<<": "<<x<<endl
  #define trace2(x, y)             cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
  #define trace3(x, y, z)          cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
  #define trace4(a, b, c, d)       cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
  #define trace5(a, b, c, d, e)    cerr<<#a<<": "<<a<<" | "<<#b<< ": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
  #define trace6(a, b, c, d, e, f) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl
  #define cases int testcases;cin>>testcases; while(testcases--)
  const int N = 200005;


 int ans1,ans2;



int32_t main()
{


    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
    IOS

    
    int n,m;
    cin >> n >> m;


  //  char ans[n+2][m+2];

    for(int i = 0; i <= n+1; i++)
    {
      for(int j = 0; j <= m+1; j++)
      {
        if(i == 0 or j == 0 or i == n+1 or j == m+1)
        {
          cout << "#";
          continue;
        }

        char ch;
        cin >> ch;
        cout << ch;

      }

      cout << endl;

    }






    return 0;   
}


Measured memory_bytes: 3608
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#define ll long long
#define rep(i,l,r)for(ll i=(l);i<(r);i++)
#define repp(i,l,r,k)for(ll i=(l);i<(r);i+=(k))
#define INF ((1LL<<62)-(1LL<<31))
#define max(p,q)((p)>(q)?(p):(q))
#define min(p,q)((p)<(q)?(p):(q))
#define bit(n,m)(((n)>>(m))&1)
int upll(const void*a, const void*b){return*(ll*)a<*(ll*)b?-1:*(ll*)a>*(ll*)b?1:0;}
int downll(const void*a, const void*b){return*(ll*)a<*(ll*)b?1:*(ll*)a>*(ll*)b?-1:0;}
void sortup(ll*a,int n){qsort(a,n,sizeof(ll),upll);}
void sortdown(ll*a,int n){qsort(a,n,sizeof(ll),downll);}
ll pom(ll a,ll n,int m){ll x=1;for(a%=m;n;n/=2)n&1?x=x*a%m:0,a=a*a%m;return x;}
//#define MOD 998244353
#define MOD 1000000007
#define invp(a,p)pom(a,p-2,p)

ll a,b,v,w,t;
int main(){
	scanf("%lld%lld%lld%lld%lld",&a,&v,&b,&w,&t);
	if(v<=w){
		puts("NO");
	}else{
		if(llabs(a-b)<=(v-w)*t)puts("YES");
		else puts("NO");
	}
}

Measured memory_bytes: 1660
#include <iostream>

using namespace std;

int main(void)
{
  int N, M;
  cin >> N >> M;
  int S[5];
  int C[5];

  bool flag = false;

  for (int i = 0; i < M; i++) {
      cin >> S[i] >> C[i];
      if (N != 1 && S[i] == 1 && C[i] == 0) {
          flag = true;
      }
  }

  if (flag) {
      cout << -1;
      return 0;
  }

  if (N == 1 && M == 0) {
      cout << 0;
      return 0;
  }

  bool check[] = {false, false, false};
  int  ans[] = {0, 0, 0};

  for (int i = 0; i < M; i++) {
      int d = 3 - N - 1 + S[i];
      if (check[d] == false) {
          check[d] = true;
          ans[d] = C[i];
      } else {
          if (ans[d] != C[i]) {
              cout << -1;
              return 0;
          }
      }
  }

  for (int i = 0; i < N; i++) {
      int d = 3 - N + i;
      if (check[d] == false) {
          if (i == 0) {
              ans[d] = 1;
          } else {
              ans[d] = 0;
          }
      }
  }

  cout << 100 * ans[0] + 10 * ans[1] + ans[2];

  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
int main()
{
    int n;
    int p[4][3][10] = {0};
    scanf("%d", &n);
    for (int i = 0; i < n; i++)
    {
        int b, f, r, v;
        scanf("%d %d %d %d", &b, &f, &r, &v);
        p[b - 1][f - 1][r - 1] += v;
    }

    for (int b = 0; b < 4; b++)
    {
        for (int f = 0; f < 3; f++)
        {
            for (int r = 0; r < 10; r++)
            {

                printf(" %d", p[b][f][r]);
            }
            printf("\n");
        }
        if (b!=3)
        {
            
            printf("####################\n");
        }
    }
    return 0;
}



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

using namespace std;

int main(int argc, char *argv[])
{
    // input from txt （提出時にこの箇所は削除すること）
    //std::ifstream in("in.txt");
    //std::cin.rdbuf(in.rdbuf());
    
    
    cin.tie(0), cout.tie(0), ios::sync_with_stdio(false);

    int a,b;
    cin >> a >> b;
    if (a < b) {
        cout << "a < b" << endl;
    }
    else if (a > b){
        cout << "a > b" << endl;
    }
    else {
        cout << "a == b" << endl;
    }
    return 0;
}



Measured memory_bytes: 3132
#include <bits/stdc++.h>
using namespace std;
int main(){
    int N,M;
    cin >> N >> M;
    vector<int> height(N);
    
    for (int i = 0; i < N; i++)
    {
        cin >> height.at(i);
    }
    
    vector<int> vec(N,1);
    int A,B,a,b;

    for (int i = 0; i < M; i++)
    {
        cin >> A >> B;
        A--;
        B--;
        a = height.at(A);
        b = height.at(B);
        if(a==b){
            vec.at(A)=0;
            vec.at(B)=0;
        }else if(a>b){
            vec.at(B)=0;
        }else{
            vec.at(A)=0;
        }
    }
    
    int ans = 0;

    for (int i = 0; i < N; i++)
    {
        if(vec.at(i)==1){
            ans ++;
        }
    }
    
    cout << ans << endl;
}

Measured memory_bytes: 4048
#include<iostream>
#include<cstdio>
#include<vector>
#include<cmath>

using namespace std;

class CPoint{
public:
	CPoint(double x,double y):x(x),y(y){}
	double x,y;
};
double Distance(const CPoint &a, const CPoint &b){
	return sqrt(pow(a.x-b.x,2.0)+pow(a.y-b.y,2.0));
}
double HelonArea(const CPoint& a, const CPoint& b, const CPoint& c){
	double dAB = Distance(a,b);
	double dAC = Distance(a,c);
	double dBC = Distance(b,c);
	double z = (dAB+dAC+dBC)/2;

	return sqrt(z*(z-dAB)*(z-dAC)*(z-dBC));
}

int main(void){
	vector<CPoint> vP;
	double S = 0;
	while( true ){
		double x, y;

		if( EOF == scanf("%lf,%lf",&x,&y) ) break;
		vP.push_back(CPoint(x,y));

	}
	for(unsigned int i = 1; i < vP.size() - 1; i++){
		S += HelonArea(vP[0],vP[i],vP[i+1]);
	}
	printf("%lf\n",S);
	return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
#define ll long long
#define all(a) (a).begin(), (a).end()
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define sz() size()
#define fr first
#define sc second
#define pb push_back
#define er erase
#define in insert
#define pi pair<int,int>
#define pii pair<pair<int,int>,int>
#define mp make_pair
#define int long long
#define rc(s) return cout<<s,0
#define rcc(s) cout<<s,exit(0)
//#define cin fin
//#define cout fout
using namespace std;

//ifstream fin("file.in");
//ofstream fout("file.out");

const int nmax=1e3+5;
const int mod=1e9+7;
const int mod1=998244353;

int n,ans;
string s;
map<string,int>q;

int32_t main(){
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	cin >> n;
	for(int i=1;i<=n;i++){
        cin >> s;
        sort(all(s));
        q[s]++;
	}
	auto it=q.begin();
	while(it!=q.end()){
        ans+=(it->second*(it->second-1))/2;
        it++;
	}
	rc(ans);
}


Measured memory_bytes: 11264
#include<stdio.h>

#define SIZE 200000
#define INFTY 1200000000
long long cnt = 0;  // number of inversion.

int upperbound(int x, int* R, int N)
{
    // R[0], R[1], ... , R[N].
    if(x < R[0]) return 0;
   
	int left, right, mid;
    left = 0;
    right = N;

    while(right - left > 1){
        mid = (left + right) / 2;
        if(R[mid] < x){
            left = mid;
        }else{
             right = mid;
        }
    };
    return right;
}

void Merge(int* A, int left, int mid, int right)
{
    int R[SIZE], L[SIZE];
    int i, j, k, n1, n2;
    n1 = mid - left;
    n2 = right - mid;
    for(i = 0; i < n1; i++) L[i] = A[i + left];
    for(j = 0; j < n2; j++) R[j] = A[j + mid];

    L[n1] = INFTY;
    R[n2] = INFTY;
    i = j = 0;

    // calculate inversion number.
    for(k = 0; k < n1; k++){
        cnt = cnt + upperbound(L[k], R, n2);
    }

    // Sorting.
    for(k = left; k < right; k++){

        if(L[i] <= R[j]){ A[k] = L[i]; i++; }

        else{ A[k] = R[j]; j++; }
    }
}

void MergeSort(int* A, int left, int right)
{
    int mid;
    if(left + 1 < right){
        mid = (left + right) / 2;
        MergeSort(A, left, mid);
        MergeSort(A, mid, right);
        Merge(A, left, mid, right);
    }
    return;
}

int main()
{
    int i, n, A[SIZE];
    scanf("%d", &n);
    for(i = 0; i < n; i++) scanf("%d", &A[i]);

    MergeSort(A, 0, n);
    printf("%lld\n", cnt);

    return 0;
}

Measured memory_bytes: 2600
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
//#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
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; }
//------------------------------------------------------------------------------
const ll MOD = 998244353;
ll dp[301][90001];
//------------------------------------------------------------------------------
void _main()
{
    int N;
    cin >> N;
    vector<ll> a(N);
    ll sum = 0;
    rep(i, 0, N)
    {
        cin >> a[i];
        sum += a[i];
    }

    ll half = 0;
    if (sum % 2 == 0)
    {
        dp[0][0] = 1;
        rep(i, 0, N)
        {
            rep(j, 0, 90001)
            {
                if (dp[i][j] != 0)
                {
                    dp[i + 1][j] = (dp[i + 1][j] + dp[i][j]) % MOD;
                    dp[i + 1][j + a[i]] = (dp[i + 1][j + a[i]] + dp[i][j]) % MOD;
                }
            }
        }
        half = dp[N][sum / 2];
    }

    rep(i, 0, 301) rep(j, 0, 90001) dp[i][j] = 0;

    sum = (sum - 1) / 2;
    dp[0][0] = 1;

    rep(i, 0, N)
    {
        rep(j, 0, 90001)
        {
            if (dp[i][j] != 0)
            {
                dp[i + 1][j] = (dp[i + 1][j] + dp[i][j]) % MOD;
                dp[i + 1][j] = (dp[i + 1][j] + dp[i][j]) % MOD;
                dp[i + 1][j + a[i]] = (dp[i + 1][j + a[i]] + dp[i][j]) % MOD;
            }
        }
    }

    ll out = 0;
    rep(i, sum + 1, 90001)
    {
        out += dp[N][i];
    }

    out -= half;
    if (out < 0) out += MOD;
    out = (out * 3) % MOD;

    ll all = 1;
    rep(i, 0, N)
    {
        all *= 3;
        all %= MOD;
    }

    ll ans = all - out;
    if (ans < 0) ans += MOD;

    cout << ans << endl;
}


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

int main() {
	int n,a;
	cin >> n >> a;
	int c[n],t[n];
	int cmin=10000;
	for (int i=0;i<n;i++){
		cin >> c[i] >> t[i];
		if(t[i]<=a){
			if(c[i]<cmin){
				cmin=c[i];
			}
		}
		
	}
	
	if(cmin==10000){
		cout << "TLE" << endl;
	}
	else cout << cmin << endl;
	return 0;
}

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

int main(void){
    int X,Y,A,B,C;
    ll ans=0;
    cin>>X>>Y>>A>>B>>C;
    int p[100010]={},q[100010]{},r[300010]={};
    for(int i=0;i<A;i++) cin>>p[i];
    for(int i=0;i<B;i++) cin>>q[i];
    for(int i=0;i<C;i++) cin>>r[i];
    sort(p,p+A);
    reverse(p,p+A);
    sort(q,q+B);
    reverse(q,q+B);
    sort(r,r+C);
    reverse(r,r+C);
    for(int i=0;i<X;i++){
        r[C+i]=p[i];
    }
    for(int i=0;i<Y;i++){
        r[C+X+i]=q[i];
    }
    sort(r,r+(C+X+Y));
    reverse(r,r+(C+X+Y));
    for(int i=0;i<X+Y;i++) ans+=r[i];
    cout<<ans;
}


Measured memory_bytes: 2176
#include <bits/stdc++.h>
 #include <math.h>
 #include <iostream>
 #include <iomanip>
 using namespace std;
 
 int main(){
    int H, N;
    int A[120000];
    int i;
    int ans=0;

    cin >> H >> N;

    for (i=0; i<N; i++){
        cin >> A[i];
        ans = ans + A[i];
    }

    if (H > ans)
        cout << "No" << endl;
    else
        cout << "Yes" << endl;
    return 0;
 }
 


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

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  map<long long, int> mp;
  long long sum = 0;
  for (int i = 0; i < n; i++) {
    long long x;
    cin >> x;
    mp[x]++;
    sum += x;
  }
  int q;
  cin >> q;
  while (q--) {
    long long b, c;
    cin >> b >> c;
    sum -= mp[b] * b;
    sum += mp[b] * c;
    mp[c] += mp[b]; mp[b] = 0;
    cout << sum << '\n';
  }
  return 0;
}

Measured memory_bytes: 9520
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <string>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <list>
using namespace std;

#define MOD 1000000007
#define p(x) cout << x << endl;
#define el cout << endl;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

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

    string a, b;
    cin >> a >> b;

    int num = stoi(a + b);

    for(int i = 1; i <= 1000; i++){
        if(i * i == num){
            p("Yes");
            return 0;
        }
    }
    p("No");
}


Measured memory_bytes: 256
def main():
    (A,B,C,D) = map(int, input())
    operation = ['+','-']
    sumA = A
    for op1 in operation:
        sum = sumA
        if op1=='+':
            sum+=B
        else:
            sum-=B
        sumAB = sum
        for op2 in operation:
            sum = sumAB
            if op2=='+':
                sum+=C
            else:
                sum-=C
            if 7-sum==D:
                op3 = '+'
                print(str(A)+op1+str(B)+op2+str(C)+op3+str(D)+'=7')
                return
            elif sum-7==D:
                op3 = '-'
                print(str(A)+op1+str(B)+op2+str(C)+op3+str(D)+'=7')
                return

main()


Measured memory_bytes: 3064
N,M = map(int,input().split())
AB = [tuple(map(int,input().split())) for i in range(N)]
CD = [tuple(map(int,input().split())) for i in range(M)]

for a,b in AB:
    ans = -1
    mind = float('inf')
    for i,(c,d) in enumerate(CD):
        dist = abs(a-c) + abs(b-d)
        if dist < mind:
            mind = dist
            ans = i+1
    print(ans)

Measured memory_bytes: 3064