akhauriyash/Code-Regression huggingface dataset:
#include"bits/stdc++.h"
using namespace std;

//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;

struct _ { ios_base::Init i; _() { cin.sync_with_stdio(0); cin.tie(0); cout << fixed << setprecision(10); } } ___;
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) {
    cerr << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
    const char* comma = strchr(names + 1, ',');
    cerr.write(names, comma - names) << " : " << arg1 << "  ";
    __f(comma + 1, args...);
}

#define ll long long int
#define pii pair<int,int>
#define oset tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define ff first
#define ss second
#define endll '\n'
#define rep(i,n) for(int i=0;i++<n;)
#define scl(i) scanf("%lld",&i)
#define int long long int
#define all(n) n.begin(),n.end()
#define mem(n,i) memset(n,i,sizeof n)
#define em(a) emplace_back(a)
#define pb(a) push_back(a)
#define srep(vv,it) for(auto &it : vv)
#define prep(vv,it) for(auto it : vv)
//vector<vector<int>>arr(n + 5, vector<int>(m + 5,0));

typedef vector<int> vii;
typedef vector<string> vss;
/*

*/
signed main()
{

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

    string a, b; cin >> a >> b;
    int sum = 0;
    for (int i = 0; i < a.size(); i++)
        if (a[i] != b[i]) sum++;
    cout << sum << endll;
}


Measured memory_bytes: 3804
#!/usr/bin/env python3
import sys
sys.setrecursionlimit(10**9)


def solve(k):
  x = 0
  for i in range(k):
    x += 7*pow(10,i,k)
    x %= k
    if x == 0:
      return i+1
  return -1



def main():
  K = int(input())
  # N,M = map(int,input().split())
  # a = list(map(int,input().split()))
  print(solve(K))
  return

if __name__ == '__main__':
  main()


Measured memory_bytes: 9136
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long long int lli;
typedef long double ld;
const int oo = 1e9;

int n;
const int nx = 1e5+5;
int ac[nx][3];
int dp[3][nx];
int go(int x, int i){
	if(i==n) return 0;
	if(dp[x][i] != -1) return dp[x][i];
	int& ans = dp[x][i];
	if(x==0)
	{
		ans=max(ans, go(1, i+1)+ac[i][0]);
		ans=max(ans, go(2, i+1)+ac[i][0]);
	}
	if(x==1)
	{
		ans=max(ans, go(0, i+1)+ac[i][1]);
		ans=max(ans, go(2, i+1)+ac[i][1]);
	}
	if(x==2)
	{
		ans=max(ans, go(0, i+1)+ac[i][2]);
		ans=max(ans, go(1, i+1)+ac[i][2]);
	}
	
	return ans;
	
}
int main(){
    cin>>n;
    for(int i=0; i<n; i++) {
            cin>>ac[i][0]>>ac[i][1]>>ac[i][2];
    }
    memset(dp, -1, sizeof dp);
    cout<<max(go(0,0), max(go(1,0),go(2,0)))<<"\n";
    return 0;
}

Measured memory_bytes: 7296
N = int(input())
L = list(map(int, input().split()))
L.sort(reverse=True)

def f(j, max1, max2):
    L_temp = L[j+1:]
    # print("max1 = ", max1, "max2 = ", max2, L_temp)
    dif = max1 - max2
    left = -1
    right = len(L_temp)
    while right - left != 1:
        temp = (left+right)//2
        if dif < L_temp[temp]:
            left = temp
        else:
            right = temp
    return left+1


ans = 0
max1 = 0
max2 = 0
for i in range(N):
    max1 = L[i]
    for j in range(i+1, N-1):
        max2 = L[j]
        ans += f(j, max1, max2)
        # print("ans = ", ans)
print(ans)


Measured memory_bytes: 50524
import itertools
from math import sqrt
n = int(input())
xy = [list(map(int, input().split())) for _ in range(n)]
ans = 0
cnt = 0
for v in itertools.permutations(list(range(n))):
    for i in range(n-1):
        x = (xy[v[i]][0]-xy[v[i+1]][0]) ** 2
        y = (xy[v[i]][1]-xy[v[i+1]][1]) ** 2
        ans += sqrt(x+y)
    cnt += 1
print(ans/cnt)

Measured memory_bytes: 9120
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
sa = []
sb = []
for i in range(n):
    sa.append(a[i] + (0 if i==0 else sa[i-1]))
    sb.append(b[i] + (0 if i==0 else sb[i-1]))
ans = 0
for i in range(n+1):
    k = (0 if i==0 else sa[i-1] - sb[i-1] + b[i-1])
    tmp = sb[n-1] + k
    ans = max(tmp, ans)
print(ans)


Measured memory_bytes: 3064
N, M, X, Y = map(int, input().split())
x = sorted([int(i) for i in input().split()])
y = sorted([int(i) for i in input().split()])

flag = True
for i in range(X + 1, Y + 1):
    if x[-1] < i and i <= y[0]:
        flag = False
        break
print("War" if flag else "No War")


Measured memory_bytes: 3060
// C++ program to print all prime factors  
#include <bits/stdc++.h> 
using namespace std; 
vector <long long> v;
map <long long, long long > arr1,arr2;
// A function to print all prime  
// factors of a given number n  
void primeFactors(long long int n)  
{  
    // Print the number of 2s that divide n  
    while (n % 2 == 0)  
    {  
        v.push_back(2);
        n = n/2;  
    }  
  
    // n must be odd at this point. So we can skip  
    // one element (Note i = i +2)  
    for (long long int i = 3; i <= sqrt(n); i = i + 2)  
    {  
        // While i divides n, print i and divide n  
        while (n % i == 0)  
        {  
            v.push_back(i);
            n = n/i;  
        }  
    }  
  
    // This condition is to handle the case when n  
    // is a prime number greater than 2  
    if (n > 2)  
        v.push_back(n);
}  
int main()
{
	long long n,k,i,j,x,y,z;
	z=0;
	cin>>n;
	primeFactors(n);
	for (i=0;i<v.size();i++)
	{
		arr1[v[i]]=0;
		arr2[v[i]]=0;
	}
	for (i=0;i<v.size();i++)
	{
		arr1[v[i]]++;
	}	
	z=0;
	for (i=0;i<v.size();i++)
	{
		if (arr1[v[i]]>arr2[v[i]])
		{
			arr1[v[i]]-=(arr2[v[i]]+1);
			arr2[v[i]]++;
			z++;
		}
	}
	cout<<z<<endl;
}

Measured memory_bytes: 3708
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {
	
	public static void main(String[] args) throws IOException {
		Main mainObj = new Main();
		mainObj.solve();
	}

	public void solve() throws IOException {
		FastScanner fs = new FastScanner();
		int n = fs.nextInt();
		
		String s = fs.next();
		String t = fs.next();
		
		int coveredLen = 0;
		
		for(int i = 0; i < s.length(); i++) {
			coveredLen = 0;
			for(int j = i; j < s.length(); j++) {
				char sChar = s.charAt(j);
				if(sChar == t.charAt(coveredLen)) {
					coveredLen++;
				}else {
					break;
				}
			}
			
			if(coveredLen == s.length() - i) {
				break;
			}
		}
		
		System.out.println(Math.max(n,s.length() + t.length() - coveredLen));
	}

	public class FastScanner {

		BufferedReader reader;
		private StringTokenizer st;

		public FastScanner() {
			st = null;
			reader = new BufferedReader(new InputStreamReader(System.in));
		}

		public String next() throws IOException {
			if (st == null || !st.hasMoreElements()) {
				st = new StringTokenizer(reader.readLine());
			}
			return st.nextToken();
		}

		public String nextLine() throws IOException {
			st = null;
			String readLine = null;
			readLine = reader.readLine();
			return readLine;
		}

		public int nextInt() throws NumberFormatException, IOException {
			return Integer.parseInt(next());
		}

		public long nextLong() throws NumberFormatException, IOException {
			return Long.parseLong(next());
		}

		public int[] nextIntArr(int n) throws NumberFormatException, IOException {
			int[] retArr = new int[n];
			for (int i = 0; i < n; i++) {
				retArr[i] = nextInt();
			}
			return retArr;
		}

		public long[] nextLongArr(int n) throws NumberFormatException, IOException {
			long[] retArr = new long[n];
			for (int i = 0; i < n; i++) {
				retArr[i] = nextLong();
			}
			return retArr;
		}

		public void close() throws IOException {
			reader.close();
		}
	}


}


Measured memory_bytes: 21204
// RMQ (Range Minimum Query)
#include<cstdio>
#include<algorithm>
#include<climits>
using namespace std;
#define MAX ( 1 << 17 )
const int INF = INT_MAX;
int n, seg[MAX * 2 - 1];
void update( int i, int x){
  i += n - 1;
  seg[i] = x;
  while(i > 0){
    i = ( i - 1 ) / 2;
    seg[i] = min( seg[i * 2 + 1], seg[i * 2 + 2]);
  }
}
int query( int a, int b, int k, int l, int r){
  if( r <= a || b <= l ) return INF;
  if( a <= l && r <= b ) return seg[k];
  int vl = query( a, b, k * 2 + 1, l, (l + r) / 2);
  int vr = query( a, b, k * 2 + 2, (l + r) / 2, r);
  return min( vl, vr);
}
void init( int& size){
  n = 1;
  while( n < size ) n *= 2;
  fill_n( seg, n * 2 - 1, INF);
}
int main(){
  int size, q;
  scanf("%d %d", &size, &q);
  init(size);
  while(q--){
    int com, a, b;
    scanf("%d %d %d", &com, &a, &b);
    if( com == 0 ) update( a, b);
    else printf("%d\n", query( a, b + 1, 0, 0, n));
  }
}

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

typedef long long ll;

int main(){
    int X,Y,A,B,C;
    cin>>X>>Y>>A>>B>>C;
    vector<ll> p(A);
    vector<ll> q(B);
    vector<ll> r(C);

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

    vector<ll> al;

    sort(p.begin(),p.end(),greater<ll>());
    sort(q.begin(),q.end(),greater<ll>());

    for(int i=0; i<X; i++) al.push_back(p[i]);
    for(int i=0; i<Y; i++) al.push_back(q[i]);
    for(int i=0; i<C; i++) al.push_back(r[i]);

    sort(al.begin(),al.end(),greater<ll>());

    ll ans = accumulate(al.begin(),al.begin()+X+Y,0ll);

    cout<<ans<<endl;

    return 0;

}

Measured memory_bytes: 9800
def make_divisors(n):
	divisors = []
	for i in range(1, int(n ** 0.5) + 1):
		if n % i == 0:
			divisors.append(i)
			if i != n // i:
				divisors.append(n // i)
	divisors.sort()
	return divisors


N = int(input())
divs = make_divisors(N)
if len(divs) % 2 == 0:
    print(divs[len(divs)//2 - 1] + divs[len(divs)//2] - 2)
else:
    print(divs[len(divs)//2] * 2 - 2)


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

int main(){
  int n;
  cin>>n;
  vector<long long> a(n);
  for(int i=0; i<n; i++)cin>>a.at(i);

  long long x,y=0;
  x=a.at(0);
  for(int i=1; i<n; i++)y+=a.at(i);

  long long ans=abs(x-y);

  for(int i=1; i<n-1; i++){
    x+=a.at(i);
    y-=a.at(i);
    ans=min(ans, abs(x-y));
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rrep(i, n) for (int i = (int)(n - 1); i >= 0; i--)
#define all(x) (x).begin(), (x).end()
#define sz(x) int(x.size())
#define get_unique(x) x.erase(unique(all(x)), x.end());
typedef long long ll;
typedef complex<double> Complex;
const int INF = 1e9;
const ll MOD = 1e9 + 7;
const ll LINF = 1e18;
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;
}
template <class T>
vector<T> make_vec(size_t a) {
    return vector<T>(a);
}
template <class T, class... Ts>
auto make_vec(size_t a, Ts... ts) {
    return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}

int main() {
    while (1) {
        int w, h;
        cin >> w >> h;
        if (w == 0 && h == 0) break;
        auto v = make_vec<int>(h, w);
        rep(i, h) rep(j, w) cin >> v[i][j];
        int cnt = 0;
        auto used = make_vec<bool>(h, w);
        rep(i, h) rep(j, w) {
            if (!used[i][j] && v[i][j] == 1) {
                queue<pair<int, int>> q;
                q.push(make_pair(i, j));
                while (sz(q)) {
                    int y, x;
                    tie(y, x) = q.front();
                    q.pop();
                    for (int dy = -1; dy <= 1; dy++) {
                        for (int dx = -1; dx <= 1; dx++) {
                            if (dy == 0 && dx == 0) continue;
                            int ny = y + dy;
                            int nx = x + dx;
                            if (!(0 <= ny && ny < h && 0 <= nx && nx < w))
                                continue;
                            if (v[ny][nx] == 0 || used[ny][nx]) continue;
                            q.push(make_pair(ny, nx));
                            used[ny][nx] = 1;
                        }
                    }
                }
                cnt++;
            }
        }
        cout << cnt << endl;
    }
}


Measured memory_bytes: 3160
# coding: utf-8
def getLnInputs():
    return input().split()


def getLnIntInputs():
    return list(map(int, getLnInputs()))


def main():
    X = getLnIntInputs()[0]
    counter = 0
    displacement = 0
    while displacement < X:
        counter += 1
        displacement += counter

    print(counter)
    return


main()


Measured memory_bytes: 2940
#include <iostream>
#include <algorithm>
#include <vector>
#include <cstdio>
#include <string>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cmath>
#include <functional>
#include <numeric>
#include <iomanip>
#define fi first
#define se second
#define fcout(n) cout<<fixed<<setprecision((n))
#define cinl(str) getline(cin,(str))
using namespace std;
bool value(int y,int x,int R,int C){return 0<=y&&y<R&&0<=x&&x<C;}
typedef pair<int,int> pii;
typedef long long ll;
typedef vector<int> vi;
typedef vector<long long > vll;
typedef vector< vi > vvi;
double pie=acos(-1);
int INF=1000000007;
int dx[4] = { 0,-1,0,1 };
int dy[4] = { -1,0,1,0 };


int main() {
	string s;
	string t="";
	cin>>s;
	for(int i=0;i<13;i++){
		if(i==4){
			t=t+" ";
		}
		else if(i<4){
			t=t+s[i];
		}
		else{
			t=t+s[i-1];
		}
	}
	cout<<t<<endl;
}


Measured memory_bytes: 256
#!usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS():return list(map(list, sys.stdin.readline().split()))
def S(): return list(sys.stdin.readline())[:-1]
def IR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = I()
    return l
def LIR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = LI()
    return l
def SR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = S()
    return l
def LSR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = LS()
    return l
sys.setrecursionlimit(1000000)
mod = 1000000007

#A
def A():
    n,a,b,c,d = LI()
    s = input()
    a -= 1
    b -= 1
    c -= 1
    d -= 1
    if c == d:
        print("No")
    else:
        if c < d:
            k = s[b:d+1]
            for i in range(d-b):
                if k[i] == k[i+1] == "#":
                    print("No")
                    quit()
            k = s[a:c+1]
            for i in range(c-a):
                if k[i] == k[i+1] == "#":
                    print("No")
                    quit()
            print("Yes")
        else:
            k = s[b:d+1]
            for i in range(d-b):
                if k[i] == k[i+1] == "#":
                    print("No")
                    quit()
            k = s[a:c+1]
            for i in range(c-a):
                if k[i] == k[i+1] == "#":
                    print("No")
                    quit()
            k = s[b-1:d+2]
            for i in range(len(k)-2):
                if k[i] == k[i+1] == k[i+2] == ".":
                    print("Yes")
                    quit()
            print("No")
    return

#B
def B():
    s = S()

    return

#C
def C():
    n = I()

    return

#D
def D():
    n = I()

    return

#E
def E():
    n = I()

    return

#F
def F():
    n = I()

    return

#Solve
if __name__ == "__main__":
    A()


Measured memory_bytes: 41592
#include<stdio.h>

int main(){
	int N;
	scanf("%d",&N);
	long long march[5]={0,0,0,0,0};
	for(int i=0;i<N;i++){
		char name[11];
		scanf("%s",name);
		switch(name[0]){
			case 'M':
				march[0]++;
				break;
			case 'A':
				march[1]++;
				break;
			case 'R':
				march[2]++;
				break;
			case 'C':
				march[3]++;
				break;
			case 'H':
				march[4]++;
				break;
		}
	}
	long long ans=0;
	for(int i=0;i<3;i++){
		for(int j=i+1;j<4;j++){
			for(int k=j+1;k<5;k++){
				ans+=march[i]*march[j]*march[k];
			}
		}
	}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 128
h,n=map(int,input().split())
L=[]
for i in range(n):
    a,b=map(int,input().split())
    L.append((b/a,a,b))

dp=[100000000 for i in range(h+1)]
dp[0]=0
for i in range(h):
    for q in range(n):
        power=L[q][1]
        magic=L[q][2]
        dp[min(h,i+power)]=min(dp[min(h,i+power)],dp[i]+magic)

print(dp[h])    
    


Measured memory_bytes: 42076
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Scanner;

public class Main {
	public static void main(final String[] args) {
		@SuppressWarnings("resource")
		final Scanner in = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
		final String S = in.next();
		String judge = solve(S);
		System.out.println(judge.trim());
	}

	public static boolean isPossibleMonth(String m) {
		final int val = Integer.parseInt(m);
		return val <= 12 && val >= 1;
	}

	static String solve(final String S) {
		final boolean headIsMonth = isPossibleMonth(S.substring(0, 2));
		final boolean tailIsMonth = isPossibleMonth(S.substring(2, 4));
		if (headIsMonth) {
			if (tailIsMonth) {
				return "AMBIGUOUS";
			} else {
				return "MMYY";
			}
		} else {
			if (tailIsMonth) {
				return "YYMM";
			} else {
				return "NA";
			}
		}
	}
}


Measured memory_bytes: 21844
import numpy as np

N = int(input())
s = input()

S = []
for c in s:
    S.append(c)
    
A = np.zeros(N+1)
if S[0] == "#":
    A[0] = 0 
for i in range(1,N+1):
    if S[i-1] == "#":
        A[i] = A[i-1] + 1
    else:
        A[i] = A[i-1]
    
minimum = N
for i in range(N+1):
    num = int(A[i] + (N-i-(A[N]-A[i])))
    if minimum > num:
        minimum = num
print(minimum)
    

    





Measured memory_bytes: 18132
#include <bits/stdc++.h>
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
#define ALL(x) (x).begin(),(x).end() 
#define SIZE(x) ((ll)(x).size())
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
#define INF 1000000000
using namespace std;
typedef long long ll;
ll mod = 1e+9 + 7;

int main(){
    int N, P1, P2, sum = 0;
    cin >> N;
    int X[N];

    REP(i, N){
        cin >> X[i];
        sum += X[i];
    }

    P1 = sum/N;
    P2 = ceil((double)sum/(double)N);

    ll ans1 = 0, ans2 = 0;
    REP(i, N){
        ans1 += pow((X[i]-P1), 2);
        ans2 += pow((X[i]-P2), 2);
    }

    ll ans = min(ans1, ans2);

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3556
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi   = vector<int>;
using vll  = vector<ll>;
using vc   = vector<char>;
using vvll  = vector<vll>;
using vvi  = vector<vi>;
using vvc  = vector<vc>;
using vb   = vector<bool>;
using vvb  = vector<vb>;
using pii  = pair<int,int>;
using vpii = vector<pii>;
using posteriority_queue = priority_queue<int, vi, greater<int>>;

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

int main() {
    ll N; cin >> N;
    ll ans;
    ll mod_const = 1000000007;
    ll tmp_10=modpow(10, N, mod_const);
    ll tmp_9=modpow(9, N, mod_const);
    ll tmp_8=modpow(8, N, mod_const);

    ans = (tmp_10 - 2 * tmp_9 + tmp_8)%mod_const;
    if (ans < 0) ans += mod_const;
    cout << ans << endl;
}


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

int main(){
    int n,y;
    cin >> n >> y;
    int ans[3] = {-1,-1,-1};
        for (int i = 0;i <= n;i++){
            for (int j = 0;j <= n - i;j++){
                    if (10000*i + 5000*j + 1000*(n-i-j) == y){
                        ans[0] = i;
                        ans[1] = j;
                        ans[2] = n - i - j;
                    }
            }
        }

    printf("%d %d %d\n",ans[0],ans[1],ans[2]);
}

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

typedef unsigned long long  ULL;
typedef long long LL;

#define PB push_back
#define MP make_pair
#define RESET(a, b) memset(a, b, sizeof(a))
#define FOR(i,a,b) for(int i=a; i<=b; i++)
#define F first 
#define S second

 bool isPal(string s) 
{ 
    int l = 0; 
    int h = s.length() - 1;
    
    while (h > l) 
    { 
        if (s[l++] != s[h--]) 
        { 
            return false; 
        } 
    } 
    return true; 
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    
    string s;
    cin>>s;
//    cout<<s<<endl;
    if(isPal(s)){
        int n=s.length();
        int l1=(n-1)/2;
        int l2=(n+3)/2;
//        cout<<n<<" "<<l1<<" "<<l2<<endl;
        
        string s1(s, 0, l1);
//        cout<<s1<<endl;
        if(isPal(s1)){
            string s2(s, l2-1, n);
//            cout<<s2<<endl;
            if(isPal(s2)) cout<<"Yes";
            else cout<<"No";
        }
        else cout<<"No"; 
    }
    else cout<<"No";
    return 0;
}

Measured memory_bytes: 256
H,W,M = map(int,input().split())
X = {}
CH = {}
CW = {}
for _ in range(M):
    h,w = map(int,input().split())
    X[(h,w)] = 1
    if h not in CH:
        CH[h] = 0
    CH[h] += 1
    if w not in CW:
        CW[w] = 0
    CW[w] += 1
hmax = 0
for h in CH:
    hmax = max(hmax,CH[h])
A = []
for h in CH:
    if CH[h]==hmax:
        A.append(h)
wmax = 0
for w in CW:
    wmax = max(wmax,CW[w])
B = []
for w in CW:
    if CW[w]==wmax:
        B.append(w)
flag = 0
for h in A:
    for w in B:
        if (h,w) not in X:
            flag = 1
            break
    if flag==1:break
if flag==1:
    print(hmax+wmax)
else:
    print(hmax+wmax-1)

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

int ans[200000];
int A[200000];

int main(void){
    // Your code here!
    
    int N;
    cin >> N;
    
    int M = 0;
    for(int i = 0; i < N; i++) cin >> A[i];
    for(int i = 0;  i < N; i++) ans[i] = 0;
    
    for(int i = N/2; i < N; i++){
        if(A[i] == 1) M += 1;
        ans[i] = A[i];
    }
    
    for(int i = N/2 - 1; i >= 0; i--){
        int now = 2 * (i + 1) - 1;
        int tmp = 0;
        while(now < N){
            tmp += ans[now];
            now += (i + 1);
        }
        
        if(tmp % 2 == 0 && A[i] == 0){
            ans[i] = 0;
        } else if(tmp % 2 == 0 && A[i] == 1){
            ans[i] = 1;
            M += 1;
        } else if(tmp % 2 == 1 && A[i] == 0){
            ans[i] = 1;
            M += 1;
        } else{
            ans[i] = 0;
        }
    }
    
    
    cout << M << endl;
    int cnt = 0;
    for(int i = 0; i < N; i++) {
        if(cnt == M-1){
            if(ans[i] == 1){
                cout << i + 1 << endl;
            }
        } else{
            if(ans[i] == 1) {
                cout << i + 1 << " ";
                cnt += 1;
            }
           
        }
    }
    
}


Measured memory_bytes: 2432
#include <stdio.h>
int main(){
  int i,min,tmp,count,num,j;
  scanf("%d",&num);
  int a[num];
  for(i=0;i<num;i++){
    scanf("%d",&a[i]);
  }
  for(i=0;i<num;i++){
    min = i;
    for(j = i;j<num;j++){
      if(a[j] <a[min]){
	min = j;	
      }
    }
    if(a[i]>a[min]){
    tmp = a[i];
    a[i] = a[min];
    a[min]= tmp;
    count++;
    }
  }
  for(i=0;i<num;i++){
    if(i == num-1) {printf("%d\n",a[i]);
      printf("%d\n",count);
    }
    else printf("%d ",a[i]);
  }
  return 0;
}
      
    



Measured memory_bytes: 2140
p = int(input().split()[1])
a = list(map(int, input()))
if 10 % p == 0:
  r = sum(i for i, x in enumerate(a, 1) if x % p == 0)
else:
  d = [1] + [0] * (p - 1)
  t, y = 0, 1
  for i, x in enumerate(reversed(a), 1):
    t = (t + x * y) % p
    d[t] += 1
    y = y * 10 % p;
  r = sum(i * (i - 1) // 2 for i in d)
print(r)


Measured memory_bytes: 5092
use std::io;
use std::cmp::Ordering;

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

fn main() {
  let line = read_line();

  let v: Vec<i32> = line.trim()
    .split_whitespace()
    .map(|val| { val.parse().unwrap() })
    .collect();
  
  let (a, b) = (v[0], v[1]);

  let op = match a.cmp(&b) {
    Ordering::Less    => "<",
    Ordering::Equal   => "==",
    Ordering::Greater => ">"
  };

  println!("a {} b", op);
}



Measured memory_bytes: 5028
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n;
	cin>>n;
	string s;
	cin>>s;
	if(n&1)
	cout<<"No";
	else{
		string tmp1,tmp2;
		tmp1=s.substr(0,n/2);
		tmp2=s.substr(n/2,n/2);
		if(tmp1==tmp2)
		cout<<"Yes";
		else
		cout<<"No";
	}
	return 0;
} 

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define all(c) (c).begin(),(c).end()
#define pb push_back
#define dbg(...) do{cerr<<__LINE__<<": ";dbgprint(#__VA_ARGS__, __VA_ARGS__);}while(0);

using namespace std;

namespace std{template<class S,class T>struct hash<pair<S,T>>{size_t operator()(const pair<S,T>&p)const{return ((size_t)1e9+7)*hash<S>()(p.first)+hash<T>()(p.second);}};template<class T>struct hash<vector<T>>{size_t operator()(const vector<T> &v)const{size_t h=0;for(auto i : v)h=h*((size_t)1e9+7)+hash<T>()(i)+1;return h;}};}
template<class T>ostream& operator<<(ostream &os, const vector<T> &v){os<<"[ ";rep(i,v.size())os<<v[i]<<(i==v.size()-1?" ]":", ");return os;}template<class T>ostream& operator<<(ostream &os,const set<T> &v){os<<"{ "; for(const auto &i:v)os<<i<<", ";return os<<"}";}
template<class T,class U>ostream& operator<<(ostream &os,const map<T,U> &v){os<<"{";for(const auto &i:v)os<<" "<<i.first<<": "<<i.second<<",";return os<<"}";}template<class T,class U>ostream& operator<<(ostream &os,const pair<T,U> &p){return os<<"("<<p.first<<", "<<p.second<<")";}
void dbgprint(const string &fmt){cerr<<endl;}template<class H,class... T>void dbgprint(const string &fmt,const H &h,const T&... r){cerr<<fmt.substr(0,fmt.find(","))<<"= "<<h<<" ";dbgprint(fmt.substr(fmt.find(",")+1),r...);}
typedef long long ll;typedef vector<int> vi;typedef pair<int,int> pi;const int inf = (int)1e9;const double INF = 1e12, EPS = 1e-9;

int main(){
	cin.tie(0); cin.sync_with_stdio(0);
	string s; cin >> s;
	int cnt = 0;
	for(char c : s){
		if(c == 'S') cnt |= 1;
		if(c == 'N') cnt |= 2;
		if(c == 'E') cnt |= 4;
		if(c == 'W') cnt |= 8;
	}
	cout << ((cnt & 3) && (cnt & 3) != 3 || (cnt & 12) && (cnt & 12) != 12 ? "No" : "Yes") << endl;
	
	return 0;
}

Measured memory_bytes: 256
main(){
int a,b,m,n,o=1;
scanf("%d%d",&a,&b);
char c[a+2][b+2];
for(m=0;m<b+2;m++)c[0][m]='.';
for(n=0;n<a+2;n++)c[n][0]='.';
for(m=0;m<b+2;m++)c[a+1][m]='.';
for(n=0;n<a+2;n++)c[n][b+1]='.';
for(n=1;n<a+1;n++)scanf("%s",c[n]+1);
for(n=1;n<a+1;n++)for(m=1;m<b+1;m++)if(c[n][m]=='#'){
if((c[n][m-1]=='.')&&(c[n][m+1]=='.')&&(c[n-1][m]=='.')&&(c[n+1][m]=='.')){
printf("No\n");return 0;}}
printf("Yes\n");}


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

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<int, int> Pi;
typedef vector<ll> Vec;
typedef vector<int> Vi;
typedef vector<string> Vs;
typedef vector<vector<ll>> VV;
typedef vector<vector<int>> VVi;

#define REP(i, a, b) for(ll i=(a); i<(b); i++)
#define PER(i, a, b) for(ll i=(a); i>=(b); i--)
#define rep(i, n) REP(i, 0, n)
#define per(i, n) PER(i, n, 0)
const ll INF=1e18+18;
const ll MAX=100005;
const ll MOD=1000000007;
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl;
#define YES(n) cout << ((n) ? "YES" : "NO") << endl;
#define ALL(v) v.begin(), v.end()
#define rALL(v) v.rbegin(), v.rend()
#define pb(x) push_back(x)
#define mp(a, b) make_pair(a,b)
#define Each(a,b) for(auto &a :b)
#define REPM(i, mp) for (auto i = mp.begin(); i != mp.end(); ++i)
#define dbg(x_) cerr << #x_ << ":" << x_ << endl;
#define dbgmap(mp) cerr << #mp << ":"<<endl; for (auto i = mp.begin(); i != mp.end(); ++i) { cerr << i->first <<":"<<i->second << endl;}
#define dbgarr(n,m,arr) rep(i,n){rep(j,m){cerr<<arr[i][j]<<" ";}cerr<<endl;}
#define dbgdp(n,arr) rep(i,n){cerr<<arr[i]<<" ";}cerr<<endl;
#define sum(v) accumulate(ALL(v),0)
#define fi first
#define se second

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return true; } return false; }

template<typename T1, typename T2>
ostream &operator<<(ostream &s, const pair<T1, T2> &p) { return s<<"("<<p.first<<", "<<p.second<<")"; }

// vector
template<typename T>
ostream &operator<<(ostream &s, const vector<T> &v) {
    int len=v.size();
    for(int i=0; i<len; ++i) {
        s<<v[i];
        if(i<len-1) s<<"	";
    }
    return s;
}

// 2 dimentional vector
template<typename T>
ostream &operator<<(ostream &s, const vector<vector<T> > &vv) {
    int len=vv.size();
    for(int i=0; i<len; ++i) {
        s<<vv[i]<<endl;
    }
    return s;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout<<std::setprecision(10);

    ll n,a,b;
    string s;
    cin>>n>>a>>b;
    ll ans = INF;
    if((b-a)%2==0){
        ans = (b-a)/2;
    }else{
        ans = min(n+1-b+(b-a-1)/2,a+(b-a-1)/2);
    }
    cout<<ans<<endl;
    return  0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    unordered_set<string> set;
    long long int n;
    cin>>n;
    while(n!=0)
    { 
      string s;
      cin>>s;
      set.insert(s);
      n--;
    }
    cout<<set.size()<<endl;
    return 0;
}

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

using namespace std;

int main() {
	int n, k;
	cin >> n >> k;
	long long ans = 0;
	if(k == 0) ans++;
	for(int i = max(k + 1, 2); i <= n; i++)
		ans += (i - k) * (n / i) + max(0, n % i - k + 1);
	cout << ans << '\n';
	return 0;
}


Measured memory_bytes: 256
import java.util.*;
 
public class Main{
	public static long[] FACT = new long[300001];
	public static long[] IFACT = new long[300001];
	public static long MOD = 998244353;
	
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		long A = sc.nextLong();
		long B = sc.nextLong();
		long K = sc.nextLong();
		long max = Math.min((long)N,K/A);

		FACT[0] = 1;
		IFACT[0] = 1;
		for(int i=1;i<=N;++i){
			FACT[i] = FACT[i-1] * i % MOD;
			IFACT[i] = mod_inverse(FACT[i]);
		}
		long ans = 0;
		for(int as=0;as<=max;++as){
			long bs = (K-A*as)/B;
			if(bs<=N && (A*(long)as + B*bs)==K){
				ans += comb(N,as) * comb(N,(int)bs);
				ans %= MOD;
			}
		}
		System.out.println(ans);
		return;
	}
	
	public static long comb(int n, int r){
		if(n < 0 || r < 0 || r > n) return 0;
		if(r > n / 2) r = n - r;
		return FACT[n]*IFACT[n-r]%MOD*IFACT[r]%MOD;
	}
	
	public static final long mod_inverse(long a){
	    long x0 = 1, x1 = 0;
	    long y0 = 0, y1 = 1;
	    long b = MOD;
	    while (b != 0) {
	        long q = a / b;
	        long r = a % b;
	        long x2 = x0 - q * x1;
	        long y2 = y0 - q * y1;

	        a = b; b = r;
	        x0 = x1; x1 = x2;
	        y0 = y1; y1 = y2;
	    }
	    return (MOD+x0%MOD)%MOD;
	}

}

Measured memory_bytes: 27732
#include <iostream>
#include <cstdio>
#include <algorithm>

using namespace std;

int main()
{
    int n,k,i;
    int a[60];
    while(cin>>n>>k)
    {
        for(i=0;i<n;i++)
        {
            cin>>a[i];
        }
        sort(a,a+n);
        int s=0;
        for(i=n-1;i>n-k-1;i--)
        {
            s=s+a[i];
        }
        cout<<s<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    long M = sc.nextLong();
    int[] A = new int[N + 1];
    for (int i = 1; i <= N; i++) {
      A[i] = sc.nextInt();
    }
    long[] B = new long[N + 1];
    B[0] = 0;
    for (int i = 1; i <= N; i++) {
      B[i] = B[i - 1] + A[i];
    }
    TreeMap<Long, Long> map = new TreeMap<>();
    for (int i = 0; i <= N; i++) {
      long key = B[i] % M;
      if (map.containsKey(key)) {
        map.put(key, map.get(key) + 1);
      } else {
        map.put(key, 1L);
      }
    }
    long ans = 0;
    for (Long value : map.values()) {
      if (1L < value) {
        ans += value * (value - 1) / 2;
      }
    }
    System.out.println(ans);
  }
}

Measured memory_bytes: 54020
#include<bits/stdc++.h>
#define rep(i, n) for(int i=0;i<n;i++)
#define repb(i, a, b) for(int i=a;i<b;i++)

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

const int INF = 1<<30;

int main(){
  int n;cin>>n;
  vector<int> p(n), m(n);
  rep(i, n)cin>>p[i];
  m[0]=p[0];
  rep(i, n-1)m[i+1]=min(m[i], p[i+1]);
  int ans=0;
  rep(i, n){
  	if(m[i]==p[i])ans++;
  }
  cout<<ans<<endl;
  return 0;
}



Measured memory_bytes: 1792
import java.util.Scanner;

public class Main{
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt(), m = sc.nextInt(), q = sc.nextInt();
		int[][] tr = new int[n][n];
		int x, y;
		for(int i = 0; i < m; i++) {
			x = sc.nextInt()-1;
			y = sc.nextInt()-1;
			tr[x][y]++;
		}
		for(int i = 1; i < n; i++) {
			for(int k = 0; k+i < n; k++) {
				tr[k][k+i] += tr[k][k+i-1] + tr[k+1][k+i] - tr[k+1][k+i-1];
			}
		}
		for(int i = 0; i < q; i++) {
			x = sc.nextInt()-1;
			y = sc.nextInt()-1;
			System.out.println(tr[x][y]);
		}
	}
}


Measured memory_bytes: 161372
#include <stdio.h>

void dividing(int pm, int pe, int pj);

int main(void)
{
    int students_number;
    int pm[10000], pe[10000], pj[10000];
    scanf("%d", &students_number);
    while (1) {
        if (students_number == 0) {
            break;
        } else {
            for (int i = 0; i < students_number; ++i) {
                scanf("%d %d %d", &pm[i], &pe[i], &pj[i]);
            }
            for (int i = 0; i < students_number; ++i) {
                dividing(pm[i], pe[i], pj[i]);
            }
            scanf("%d", &students_number);
        }
    }
    return 0;
}

void dividing(int pm, int pe, int pj)
{
    char rank;
    if (pm == 100 || pe == 100 || pj == 100) {
        rank = 'A';
    } else if (pm + pe >= 90 * 2) {
        rank = 'A';
    } else if (pm + pe + pj >= 80 * 3) {
        rank = 'A';
    } else if (pm + pe + pj >= 70 * 3) {
        rank = 'B';
    } else if (pm + pe + pj >= 50 * 3 && (pm >= 80 || pe >= 80)) {
        rank = 'B';
    } else {
        rank = 'C';
    }
    printf("%c\n", rank);
}

Measured memory_bytes: 1044
#include <iostream>
#include <iomanip>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <math.h>
#include <sstream>
#include <numeric>
#include <string>
#include <cassert>
#include <bitset>

using namespace std;
typedef long long ll;

vector<vector<int> > g;
vector<int> colors;

int bfs(int start, int c) {
  int size = 0;
  queue<int> q;
  colors[start] = c;
  ++size;
  q.push(start);
  while (not q.empty()) {
    int u = q.front();
    q.pop();
    for (auto v : g[u]) {
      if (colors[v] == -1) {
	colors[v] = c;
	++size;
	q.push(v);
      }
    }
  }
  return size;
}

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

  g.resize(N);
  for (int i = 0; i < M; ++i) {
    int u, v;
    cin >> u >> v;
    --u; --v;
    g[u].push_back(v);
    g[v].push_back(u);
  }
  
  colors.resize(N);
  fill(colors.begin(), colors.end(), -1);
  int n_colors = 0;
  vector<int> sizes;
  for (int u = 0; u < N; ++u) {
    if (colors[u] != -1) continue;
    int c = n_colors;
    ++n_colors;
    int size = bfs(u, c);
    sizes.push_back(size);
  }

  vector<int> n_enemies(N);
  for (int i = 0; i < K; ++i) {
    int u, v;
    cin >> u >> v;
    --u; --v;
    if (colors[u] == colors[v]) {
      n_enemies[u]++;
      n_enemies[v]++;
    }
  }

  for (int u = 0; u < N; ++u) {
    int c = colors[u];
    cout << sizes[c] - 1 - g[u].size() - n_enemies[u] << " ";  // FIX HERE LATER!!
  }
  cout << endl;
  
  return 0;
}


Measured memory_bytes: 7544
#include <atcoder/all>
#include <bits/stdc++.h>

using namespace std;
using namespace atcoder;

#define REP(i,m,n) for(int i=(m);i<(n);++i)
#define rep(i,n) REP(i,0,n)

int main(){
    static char buf[500000+1];
    scanf("%s",buf);
    string s=buf;
    vector<int> sa=suffix_array(s);
    long long ans=1LL*s.size()*(s.size()+1)/2;

    for(auto x:lcp_array(s,sa)){
        ans-=x;
    }

    printf("%lld\n",ans);

    return 0;
}

Measured memory_bytes: 16124
N, K, Q = map(int, input().split())
if K > Q:
    for i in range(N):
        print("Yes")
else:
    result = [0] * N
    for _ in range(Q):
        A = int(input())
        result[A-1] += 1
    for i in range(N):
        if K - Q + result[i] > 0:
            print("Yes")
        else:
            print("No")

Measured memory_bytes: 4680
/****************************
/////  Shubham Singhal
/////  LNMIIT
*****************************/
#include <bits/stdc++.h>
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
#define ppb pop_back
#define pf push_front
#define ppf pop_front
#define eb emplace_back
#define lwr lower_bound
#define upr upper_bound
#define pq priority_queue
#define umap unordered_map
#define rep(i,n) for(i=0; i<n;i++)
#define repp(i,a,n) for(i=a; i<n;i++)
#define precise(x) cout<<fixed<<setprecision(x)
#define all(x) x.begin(),x.end()
#define lcm(a,b) (a*b)/__gcd(a,b)
#define prn(x) cout<<x<<"\n"
#define prn2(x, y) cout<<x<<" "<<y<<"\n"
#define prn3(x, y, z) cout<<x<<" "<<y<<" "<<z<<"\n"
#define prn4(x, y, z, a) cout<<x<<" "<<y<<" "<<z<<" "<<a<<"\n"
#define prnv(x) for(auto i:x) cout<<i<<" "; cout<<"\n"
#define MOD 1000000007
using namespace std;
 
typedef unsigned long long ull;
typedef long long ll;
typedef double ld;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<int, ll> pil;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd; 
typedef vector<int> vi;
typedef vector<long> vl;
typedef vector<char> vc;
typedef vector<ll> vll;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<pii> vpii;
typedef vector<pil> vpil;
typedef vector<pli> vpli;
typedef vector<pll> vpll;
const long long INF64 = 1'000'000'000'000'000'000ll;
clock_t time_p=clock();
void time()
{
    time_p=clock()-time_p;
    cerr<<"Time Taken : "<<(float)(time_p)/CLOCKS_PER_SEC<<"\n";
}
void fast()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);cout.tie(NULL);
}
umap<ll,ll> dp;
int main()
{
    fast();
    ll n,i;
    cin>>n;
    vll a(n);
    rep(i,n)
        cin>>a[i];
    dp[0]=0;
    dp[1]=abs(a[1]-a[0]);
    for(i=2;i<n;i++)
    {
        dp[i]=min(abs(a[i]-a[i-2])+dp[i-2],abs(a[i]-a[i-1])+dp[i-1]);
    }
    cout<<dp[n-1];
}

Measured memory_bytes: 5156
'use strict';
(function(stdin) {
  var inputs = stdin.toString().trim().split('\n');
  var params = inputs[0].split(' ').map(Number);

  (function(W, H, x, y, r) {
    console.log(YesNo(W, H, x, y, r));
    function YesNo(W, H, x, y, r){
    if (X(W,x,r) &&  Y(H, y, r)){return 'Yes';}
    return 'No';
    }

    function X(W, x, r){
      var left = x - r;
      var right = x + r;
      return left >= 0 && right <= W;
    }

    function Y(H, y, r){
      var top = y - r;
      var bottom = y + r;
      return top >=0 && bottom <= H;

    }

  }(params[0], params[1], params[2], params[3], params[4]));

}(require('fs').readFileSync('/dev/stdin', 'utf8')));

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

int main(void){
	int n;
	int a,b,c,d;
	while(cin >> n, n !=0){
		a = 0; b = 0;
		for(int i = 0; i < n; i++){
			cin >> c >> d;
			if(c > d)
				a += c + d;
			else if(d > c)
				b += c + d;
			else{
				a += c;
				b += d;
			}
		}
		cout << a << ' ' << b << endl;
	}
	return 0;
}

Measured memory_bytes: 1160
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        String s = sc.next();
        System.out.println(add(s));
    }

    private static int add(String s) {
        int[] right = new int[s.length()];
        int[] left = new int[s.length()];
        for (int i = 1; i < s.length(); i++) {
            if (s.charAt(i - 1) == 'W') {
                right[i] = right[i - 1] + 1;
            } else {
                right[i] = right[i - 1];
            }
        }
        for (int i = s.length() - 2; i >= 0; i--) {
            if (s.charAt(i + 1) == 'E') {
                left[i] = left[i + 1] + 1;
            } else {
                left[i] = left[i + 1];
            }
        }
        int min = right.length;
        for (int i = 0; i < right.length; i++) {
            min = Math.min(min, left[i] + right[i]);
        }
        return min;
    }

}


Measured memory_bytes: 31232
N = int(input())
s = [sorted(input()) for _ in range(N)]
s = sorted(s)
ans = 0
temp = 1
for i in range(1, N):
    if s[i] == s[i - 1]:
        temp += 1
    else:
      ans += temp * (temp - 1) / 2
      temp = 1
ans += temp * (temp - 1) / 2
print(int(ans))

Measured memory_bytes: 98136
from collections import defaultdict 

n=int(input())
yes=defaultdict(list)
no=defaultdict(list)
for i in range(1,n+1):
    a=int(input())
    for j in range(a):
        x,y=map(int,input().split())
        if y==0:
            no[i].append(x)
        else:
            yes[i].append(x)

maxi=0 
tot=(1<<n)
def ok(curr):
    for a  in range(1,n+1):
        if a in curr:
            for z in yes[a]:
                if z not in curr:
                    return 0 
            for z in no[a]:
                if z in curr:
                    return 0
    return 1 
#print(no)

for i in range(tot):
    curr=[]
    for j in range(n):
        if i&(1<<j):
            curr.append(j)
    curr=[i+1 for i in curr]
    if ok(curr):
       # print(curr)
        maxi=max(maxi,len(curr))
print(maxi)

Measured memory_bytes: 45148
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Practice
{
    class Program
    {
        private static int ReadAndParseInt()
        {
            return int.Parse(Console.ReadLine());
        }
        private static int[] ReadAndParseIntArr()
        {
            return Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
        }
        private static long ReadAndParseLong()
        {
            return long.Parse(Console.ReadLine());
        }
        private static long[] ReadAndParseLongArr()
        {
            return Array.ConvertAll(Console.ReadLine().Split(' '), long.Parse);
        }
        static void Main(string[] args)
        {
            SolveA(args);
            //SolveB(args);
            //SolveC(args);
            //SolveD(args);


        }
        static void SolveA(string[] args)
        {
            long[] nc = ReadAndParseLongArr();
            long n = nc[0];
            long c = nc[1];
            long[] x = new long[n];
            long[] v = new long[n];
            for (int i = 0; i < n; ++i)
            {
                long[] xv = ReadAndParseLongArr();
                x[i] = xv[0];
                v[i] = xv[1];
            }
            // sigma vの事前計算
            long[] va = new long[n+1];// 先頭はダミー
            for(int i=1;i<va.Length;++i)
            {
                va[i] = va[i - 1] + v[i-1];
            }
            long[] vb = new long[n+1];// 先頭はダミー
            vb[n] = v[n-1];
            for(long i=n-1;i>=1;--i)
            {
                vb[i] = vb[i + 1] + v[i-1];
            }
            // f(a)を事前計算 aまで取得したときのカロリー
            long[] f = new long[n+1];
            long[] f2 = new long[n + 1];
            f[0] = 0;
            f2[0] = 0;
            for(int i=1;i<f.Length;++i)
            {
                f[i] = va[i] - x[i-1];
                f2[i] = va[i] - 2 * x[i - 1];
            }
            // さらにg(a)の事前計算
            long[] g = new long[n+1];
            long[] g2 = new long[n + 1];
            g[0] = f[0];
            g2[0] = f2[0];
            for(int i=1;i<g.Length;++i)
            {
                g[i] = Math.Max(f[i], g[i - 1]);
                g2[i] = Math.Max(f2[i], g2[i - 1]);
            }

            // ついでにh(b)を事前計算
            long[] h = new long[n+1];
            long[] h2 = new long[n + 1];
            h[0] = 0;
            h2[n] = 0;
            for(long b = n;b >= 1 ;--b)
            {
                h[b] = vb[b] - (c - x[b - 1]);
                h2[b] = vb[b] - 2*(c - x[b - 1]);
            }

            long max = 0;
            
            for(int b=0;b<=n;++b)
            {
                long a = b - 1;
                if( a < 0) { a = n; }
                max = Math.Max(max, g2[a] + h[b]);
                max = Math.Max(max, g[a] + h2[b]);

            }


            Console.WriteLine(max);
        }
        private static long CalcH(long b, long c, long [] x, long[] vb)
        {
            return vb[b] - (c - x[b]);
        }

        
    }
}


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

using namespace std;

const int N = 200000 + 77 , NN = 4000 + 77 , Mod = 1000000007 , L = 2002;
int Fact[N] , IFact[N] , dp[NN][NN];
inline int C(int x , int y) { return Fact[y] * 1ll * IFact[x] % Mod * 1ll * IFact[y - x] % Mod; }
inline int Pow(int x , long long y) {
   int r = 1;
   for(;y;y >>= 1) {
      if(y & 1)
         r = 1ll * r * x % Mod;
      x = 1ll * x * x % Mod;
   }
   return r;
}
int A , n , a[N] , b[N];
int main() {

   Fact[0] = IFact[0] = 1;
   for(int i = 1;i < N;++ i)
      Fact[i] = 1ll * i * Fact[i - 1] % Mod , IFact[i] = Pow(Fact[i] , Mod - 2);
   scanf("%d" , & n);
   for(int i = 1;i <= n;++ i) {
      scanf("%d %d" , a + i , b + i) , ++ dp[L - a[i]][L - b[i]];
      A = (A + Mod - C(a[i] + a[i] , b[i] + b[i] + a[i] + a[i])) % Mod;
   }
   for(int i = 1;i < NN;++ i)
      for(int j = 1;j < NN;++ j)
         dp[i][j] = (dp[i - 1][j] + dp[i][j - 1] + dp[i][j]) % Mod;
   for(int i = 1;i <= n;++ i)
      A = (A + dp[a[i] + L][b[i] + L]) % Mod;
   printf("%d\n" , A * 1ll * Pow(2 , Mod - 2) % Mod);
   return 0;
}



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

typedef long long ll;

const int MAXLEN = 1e5+5;

int parent[MAXLEN];

// find the parent of x
int Find(int x) {
    if (parent[x] == -1) {
        return x;
    }
    // shorten the path to root
    parent[x] = Find(parent[x]);
    return parent[x];
}

// union x and y
void Union(int x, int y) {
    int parentx = Find(x), parenty = Find(y);
    if (parentx != parenty) {
        parent[parenty] = parentx;
    }
}


int main(int argc, char const *argv[])
{
    int nCases = 1;
    //scanf("%d", &nCases);

    for (int iCase = 1; iCase <= nCases; ++iCase) {
        int N, M;
        scanf("%d%d", &N, &M);

        for (int i = 0; i <= N; ++i) {
            parent[i] = -1;
        }

        for (int i = 0; i < M; ++i) {
            int x, y;
            scanf("%d%d", &x, &y);
            Union(x, y);
        }

        int nRoots = -1;
        for (int i = 1; i <= N; ++i) {
            if (i == Find(i)) nRoots++;
        }

        printf("%d\n", nRoots);
        //printf("Case #%d: %.7lf\n", iCase, ans);
    }

    return 0;
}


Measured memory_bytes: 4200