akhauriyash/Code-Regression huggingface dataset:
H,W,A,B=map(int,input().split())

ans=[[0]*W for _ in range(H)]
for i in range(A):
  for j in range(B):
    ans[j][i]=1

for i in range(A,W):
  for j in range(B,H):
    ans[j][i]=1
    
for i in ans:
  print("".join(map(str,i)))

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

typedef long long ll;

/*
const ll M = 1000000007;
vector<ll> fac(3001);
vector<ll> ifac(3001);
ll mpow(ll x, ll n){
    ll ans = 1;
    while(n != 0){
        if(n&1) ans = ans*x % M;
        x = x*x % M;
        n = n >> 1;
    }
    return ans;
}
 
ll comb(ll a, ll b){
    if(a == 0 && b == 0)return 1;
    if(a < b || a < 0 || b < 0)return 0;
    ll tmp = ifac[a-b]* ifac[b] % M;
    return tmp * fac[a] % M;
}
*/


ll lcm(ll a,ll b){
 
  ll r, x, tmp;
  x = a * b;
  if(a<b){
    tmp = a;
    a = b;
    b = tmp;
  }
 
  r = a % b;
  while(r!=0){
    a = b;
    b = r;
    r = a % b;
  }
  return x/b;
}

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

bool sosu(ll p){
    bool ans = true;
    double psqrtd = pow(p, 0.5);
    ll psqrt = psqrtd;
    for(ll i = 2; i <= psqrt; i++){
        if(p%i==0)ans = false;
    }
    if(p==1)ans = false;
    return ans;
}

vector< bool > prime_table(ll n) {
  vector< bool > prime(n + 1, true);
  if(n >= 0) prime[0] = false;
  if(n >= 1) prime[1] = false;
  for(int i = 2; i * i <= n; i++) {
    if(!prime[i]) continue;
    for(int j = i + i; j <= n; j += i) {
      prime[j] = false;
    }
  }
  return prime;
}

int main(void){
    ll n;
    cin >> n;
    bool ans = false;
    for(ll i = 1; i <= 9; i++){
        for(ll j = 1; j <= 9; j++){
            if(i*j == n)ans = true;
        }
    }
    if(ans)cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 256
def solve():
    from sys import stdin
    file_input = stdin
    
    while True:
        x1, y1, x2, y2, x3, y3 = map(int, file_input.readline().split())
        if x1 == y1 == x2 == y2 == 0:
            break
        
        A = x1 + y1 * 1j
        B = x2 + y2 * 1j
        C = x3 + y3 * 1j
        
        a = abs(B - C)
        b = abs(C - A)
        c = abs(A - B)
        
        s = (a + b + c) / 2
        
        r = (s * (s - a) * (s - b) * (s - c)) ** 0.5 / s
        
        D = (b * B + c * C) / (c + b)
        BD = abs(D - B)
        
        I = (BD * A + c * D) / (c + BD)
        
        d = abs(A - I)
        e = abs(B - I)
        f = abs(C - I)
        
        r1 = r / 2 / (s - a) * (s + d - r - e - f)
        r2 = r / 2 / (s - b) * (s + e - r - d - f)
        r3 = r / 2 / (s - c) * (s + f - r - d - e)
        
        print(r1, r2, r3)

solve()


Measured memory_bytes: 5820
#include <stdio.h>

int main(void)
{
	int n, i, max, min,a[10001];
	long long int sum;

	scanf("%d", &n);

	for (i = 0; i < n; i++)
		scanf("%d", &a[i]);

	max = min = a[0];
	sum = a[0];

	for (i = 1; i < n; i++)
	{
		if (max < a[i])
			max = a[i];
		if (min > a[i])
			min = a[i];
		sum += (long long int)a[i];
	}

	printf("%d %d %lld\n", min, max, sum);

	return 0;
}

Measured memory_bytes: 640
import java.io.*;

public class Main{
  public static void main(String[] args) {
    try {
      BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
      String a, b, c, d;
      int y=700;
      a = reader.readLine();
      b = a.substring(0,1);
      c = a.substring(1,2);
      d = a.substring(2);
      
      if(b.equals("o")){
        y = y+100;
      }
      if(c.equals("o")){
        y = y+100;    
      }
      if(d.equals("o")){
        y = y+100;
      }

      System.out.println(y);
      
    }
    catch (Exception e) {
      
    }
  }
}

Measured memory_bytes: 20308
n = int(input())

edges = []
 
for i in range(1, n + 1):
  for j in range(i + 1, n + 1):
    if n % 2 == 1 and i + j != n \
    or n % 2 == 0 and i + j != n + 1:
      edges.append((i, j))

print(len(edges))

for i, j in edges:
	print(i, j)

Measured memory_bytes: 3956
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <string>
#include <set>
#include <utility>

using ll = long long;

using namespace std;

using P = pair<int, int>;
#define fi first
#define se second

vector<int> G[200010];


int main() {
    int n;
    cin >> n;
    for (int i=0, a, b; i<n-1; i++) {
        cin >> a >> b;
        a--; b--;
        G[a].push_back(b);
        G[b].push_back(a);
    }
    int color[n];
    fill(color, color+n, -1);
    color[0] = 0;
    queue<int> q;
    q.push(0);
    int cnt = 0;
    while (!q.empty()) {
        int i = q.front(); q.pop();
        for (auto &g:G[i]) {
            if (color[g] >= 0) continue;
            color[g] = color[i] ^ 1;
            cnt += color[g];
            q.push(g);
        }
    }
    int ans[n];
    fill(ans, ans+n, -1);
    set<int> s; for (int i=1; i<=n; i++) s.insert(i);
    if (cnt <= n / 3 || n - cnt <= n / 3) {
        int val = 3;
        for (int i=0; i<n; i++) {
            if (color[i] ^ (cnt > n / 3)) {
                ans[i] = val;
                s.erase(val);
                val += 3;
            }
        }
    } else {
        int vals[3] = {1, 2, 3};
        for (int i=0; i<n; i++) {
            int idx = (vals[color[i]] >= 0 ? color[i] : 2);
            ans[i] = vals[idx];
            s.erase(vals[idx]);
            vals[idx] += 3;
            if (vals[idx] > n) vals[idx] = -1;
        }
    }
    auto itr = s.begin();
    for (int i=0; i<n; i++) {
        if (ans[i] < 0) {
            ans[i] = *(itr++);
        }
        cout << ans[i] << ' ';
    }
    cout << '\n';
    return 0;
}

Measured memory_bytes: 23924
#include <iostream>
#include <vector>

int main()
{
    using std::cin;
    using std::vector;

    int N;
    cin >> N;

    vector<int> friends(N+1);
    for (int i = 1; i <= N; ++i) {
        int f;
        cin >> f;
        friends[i] = f;
    }

    int count = 0;
    for (int i = 1; i <= N; ++i) if (friends[friends[i]] == i) ++count;
    std::cout << count/2 << std::endl;
    return 0;
}

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

int main() {
  int r, g, b;
  cin >> r >> g >> b;
  int num = 100 * r + 10 * g + b;
  if (num % 4 == 0) {
    cout << "YES" << endl;
  }
  else {
    cout << "NO" << endl;
  }
}

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

#define ll long long
#define pb push_back
#define N 1000000007
#define nmax 200001
#define pll pair<ll,ll>
#define fill_nums(A,n) for(ll i=0;i<n;i++) scanf("%lld",&A[i]);
#define fill_edges(adj,m) for(ll i=0;i<m;i++) {ll a, b; scanf("%lld %lld",&a,&b); adj[a-1].pb(b-1); adj[b-1].pb(a-1);}
#define fill_direct(adj,m) for(ll i=0;i<m;i++) {ll a, b; scanf("%lld %lld",&a,&b); adj[a-1].pb(b-1);}

vector<vector<vector<pair<ll,ll>>>> adj(1001, vector<vector<pair<ll,ll>>>(1001, vector<pair<ll,ll>>()));    
vector<vector<bool>> visited(1001, vector<bool>(1001,0));
vector<vector<ll>> indeg(1001, vector<ll>(1001,0));
ll maxi = 0;

void dfs(ll x, ll y) {
    visited[x][y] = 1;
    // cout<<x<<" "<<y<<endl;
    for(auto i: adj[x][y]) {
        indeg[i.first][i.second]--;
        indeg[i.second][i.first] = max(indeg[i.second][i.first], indeg[y][x]+1);
        maxi = max(indeg[i.second][i.first], maxi);
        if(!visited[i.first][i.second] && !indeg[i.first][i.second]) {
            dfs(i.first, i.second);
        }
    }
}

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

    ll prev;
    for(ll i=0;i<n;i++) {
        for(ll j=0;j<n-1;j++) {
            ll a;
            cin>>a;
            a--;;

            if(j!=0){
                adj[min(prev,i)][max(prev,i)].pb({min(a,i),max(a,i)});
                indeg[min(a,i)][max(a,i)]++;
            }
            prev = a;
        }
    }

    // for(int i=0;i<n;i++){
    //     for(int j=0;j<n;j++)
    //         cout<<indeg[i][j]<<" ";
    //     cout<<endl;}

    for(ll i=0;i<n;i++) {
        for(ll j=i+1;j<n;j++) {
            if(!visited[i][j] && !indeg[i][j])
                dfs(i,j);
        }
    }

    // for(int i=0;i<n;i++){
    //     for(int j=0;j<n;j++)
    //         cout<<indeg[i][j]<<" ";
    //     cout<<endl;}

    for(ll i=0;i<n;i++) {
        for(ll j=i+1;j<n;j++) {
            if(indeg[i][j]!=0){
                cout<<-1<<endl;
                return 0;
            }
        }
    }

    cout<<maxi+1<<endl;

    return 0;
}



Measured memory_bytes: 57088
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;
using static System.Math;

class MainClass
{
    static void Main()
    {
        int N = int.Parse(ReadLine());
        var A = ReadLine().Split().Select(int.Parse).ToArray();
        int ans = 0;
        for (int i = 0; i < N; i++)
        {
            if (i % 2 == 0 && A[i] % 2 == 1)
            {
                ans++;
            }
        }
        WriteLine(ans);
    }
}


Measured memory_bytes: 28160
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> PP;
//#define MOD 1000000007
//#define MOD 998244353
#define INF 1145141919810893364
//#define INF 810114514
#define PI 3.141592653589
#define setdouble setprecision
#define REP(i,n) for(ll i=0;i<(n);++i)
#define OREP(i,n) for(ll i=1;i<=(n);++i)
#define RREP(i,n) for(ll i=(n)-1;i>=0;--i)
#define all1(i) begin(i),end(i)
#define GOODBYE do { cout << "0" << endl; return 0; } while (false)
#define MM <<" "<<
#define Endl endl
#define debug false
#define debug2 false

int main(void){
    
    ll N,l;
    vector<ll> L;
    cin >> N;
    REP(i,N){
        cin >> l;
        L.push_back(l);
    }
    sort(L.begin(),L.end());
    
    ll Ans=0;
    REP(k,N){
        REP(j,k){
            REP(i,j){
                if(L[i]!=L[j] && L[i]!=L[k] && L[j]!=L[k] && L[i]+L[j]>L[k]){
                    Ans++;
                }
            }
        }
    }
    cout << Ans << endl;
    
    return 0;
}



Measured memory_bytes: 3628
using System;
class Program
{
    public static void Main()
    {
        string[] str = Console.ReadLine().Split(' ');
        int x = int.Parse(str[0]);
        int y = int.Parse(str[1]);
        long z = -1;
        if (x % y != 0)
        {
            for (long i = x; i <= 1000000000000000000; i++)
            {
                if (i % x == 0 && i % y != 0)
                {
                    z = i;
                    break;
                }
            }
        }
        Console.WriteLine(z);
    }
}

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

#define MAX_N 100001

struct arrow {int v, w;};
vector <arrow> adj[MAX_N];
int64_t dis[MAX_N] = {0};
bool vis[MAX_N] = {0};

void dfs(int v)
{
    vis[v] = true;
    for (int i = 0; i < adj[v].size(); i++) {
        int u = adj[v][i].v;
        int w = adj[v][i].w;
        if (!vis[u]) {
            dis[u] = dis[v] + w;
            dfs(u);
        }
    }
}

int main(void)
{
    int n, k, q;
    scanf("%d", &n);
    for (int i = 1; i < n; i++) {
        int a, b, c;
        scanf("%d%d%d", &a, &b, &c);
        arrow s = {b, c}, t = {a, c};
        adj[a].push_back(s);
        adj[b].push_back(t);
    }
    scanf("%d%d", &q, &k);
    dfs(k);
    while (q--) {
        int x, y;
        scanf("%d%d", &x, &y);
        printf("%lld\n", dis[x] + dis[y]);
    }
    return 0;
}


Measured memory_bytes: 12800
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (n); i++)
#define prtd(var, i) cout << fixed << setprecision(i) << var << endl;
#define ll long long
#define P pair<int, int>
using namespace std;

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


Measured memory_bytes: 3576
N = int(input())
H_list = list(map(int, input().split()))

counter = 0
for i in range(N):
    if i == 0:
        counter += 1
    if i > 0:
        max_before_i = max(H_list[:i+1])
        if max_before_i <= H_list[i]:
            counter += 1

print(counter)

Measured memory_bytes: 3060
a, b, c = map(int, input().split())
k = int(input())

while k:
    if not a < b:
        b *= 2
        k -= 1
        continue
    elif not b < c:
        c *= 2
        k -= 1
        continue
    else:
        break


if a < b < c:
    print('Yes')
else:
    print('No')


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

using namespace std;

//#define FILE_IO

const int mod = 1e9 + 7;

int N, A, B, C, D;
int fct[1005], ifct[1005];
int dp[1005][1005];

int add(int x, int y)
{
    x += y; if(x >= mod)    x -= mod;
    return x;
}

int mult(int x, int y)
{
    return (1LL * x * y) % mod;
}

int power(int x, int y)
{
    int p = x, r = 1;
    while(y > 0)
    {
        if(y & 1)   r = mult(r, p);
        p = mult(p, p);
        y >>= 1;
    }
    return r;
}

int main()
{
    #ifdef FILE_IO
    freopen("1.in", "r", stdin);
    freopen("1.out", "w", stdout);
    #endif

    scanf("%d", &N);
    scanf("%d%d", &A, &B);
    scanf("%d%d", &C, &D);

    fct[0] = ifct[0] = 1;
    for(int i = 1; i <= N; i++)
    {
        fct[i] = mult(fct[i - 1], i);
        ifct[i] = power(fct[i], mod - 2);
    }

    dp[0][0] = 1;
    for(int i = 1; i <= B - A + 1; i++)
    {
        for(int j = 0; j <= N; j++)
            dp[i][j] = dp[i - 1][j];
        int l = i + A - 1;
        int pwfct = power(ifct[l], C - 1);
        for(int j = C; j <= D; j++)
        {
            pwfct = mult(pwfct, ifct[l]);
            for(int k = 0; k + j * l <= N; k++)
                dp[i][k + j * l] = add( dp[i][k + j * l], mult( dp[i - 1][k], mult( ifct[j], pwfct ) ) );
        }
    }

    int ans = mult(dp[B - A + 1][N], fct[N]);
    printf("%d\n", ans);

    return 0;
}


Measured memory_bytes: 4224
#include <bits/stdc++.h>
using namespace std;
int main(){
	string str;
	cin>>str;
	int num;
	cin>>num;

	int L=str[0]-'0';
	for(int i=1;i<str.length();i+=2){
		if(str[i]=='+') L+=str[i+1]-'0';
		else if(str[i]='*') L*=str[i+1]-'0';
	}

	str+='+';
	vector< int > vc;
	bool f=0;
	for(int i=1;i<str.length();i+=2){
		if(str[i]=='+'){
			if(!f) vc.push_back(str[i-1]-'0');
			f=0;
		} else if(str[i]=='*'){
			if(!f){
				vc.push_back((str[i-1]-'0')*(str[i+1]-'0'));
				f=1;
			} else if(f){
				int tmp=vc.back();
				vc.pop_back();
				vc.push_back(tmp*(str[i+1]-'0'));
			}			
		}
	}

	int M=0;
	for(int i=0;i<vc.size();i++) M+=vc[i];

	if(num==M && num==L) cout<<"U\n";
	else if(num==L) cout<<"L\n";
	else if(num==M) cout<<"M\n";
	else cout<<"I\n";
	return 0;
}


Measured memory_bytes: 3204
#include<stdio.h>

int gcd(int a, int b)
{
    if(a==0) return b;
    else return gcd(b%a,a);
}
int main()
{
    int n,i,j,k;
    long long int sum=0;

    scanf("%d",&n);

    for(i=1;i<=n;i++)
    {
        for(j=1;j<=n;j++)
        {
            for(k=1;k<=n;k++)
            {
                sum+=gcd((gcd(i,j)),k);
            }
        }
    }

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

    return 0;
}


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

#define ll long long int
#define uul unsigned long long int
#define ui uint64_t
#define max(a,b) (a>b)?a:b
#define min(a,b) (a<b)?a:b
#define ma 1000000007

int main()
{

    ll n,i,j,s=0;
    cin>>n;
    ll d[n+5];
    for(i=0;i<n;i++)
    {
        cin>>d[i];
    }
    for(i=0;i<n;i++)
    {
        for(j=i+1;j<n;j++)
        {
                s+=(d[i]*d[j]);
        }
    }
    cout<<s<<endl;

}


Measured memory_bytes: 256
(let* ((n (read))
       (m (make-array `(,(1+ n))))
       (ans 0))
  (loop :for i :from 1 :to n
        :do (setf (aref m i) (make-hash-table :size n)))
  (loop :for i :from 1 :to n
        :for a := (read)
        :do (loop :for j :from 1 :to a
                  :for x := (read)
                  :for y := (read)
                  :do (setf (gethash x (aref m i)) y))
        :do (setf (gethash i (aref m i)) 1))

  (loop :for c :from 0 :to (1- (expt 2 n))
        :do (loop :named main
                  :with acc := 0
                  :for i :from 1 :to n
                  :if (/= 0 (logand (expt 2 (1- i)) c))
                  :do (progn
                        (maphash (lambda (j val)
                                   (unless (funcall (if (= val 1) #'/= #'=) 0 (logand (expt 2 (1- j)) c))
                                     (return-from main)))
                                   (aref m i))
                        (incf acc))
                  :finally (setf ans (max acc ans))))
  (format t "~A~%" ans))


Measured memory_bytes: 25072
#include <bits/stdc++.h>
#define all(X) (X).begin(),(X).end()
#define rall(X) (X).rbegin(),(X).rend()
#define pub push_back
#define puf push_front
#define pob pop_back
#define pof pop_front
#define ff first
#define ss second
#define P 1000000007
#define in(x, a, b) (a <= x && x < b)

using namespace std;
using ll = long long;
typedef pair<int, int> ii;
typedef vector<ii> vii; 
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<vii> vvii;
const ll inf = 1000000001, INF = (ll)1e18 + 1;

int power(int a, int b) {
	int result = 1;
	while(b) {
		if(b % 2) result = (result * a) % 13;
		a = (a * a) % 13;
		b /= 2;
	}
	
	return result;
}

int divide13(int a, int b) {
	return a * power(b, 11) % 13;
}

void solve() {
	string s;
	cin >> s;
	
	int n = s.length();
	vvi dp(n + 1, vi(13, 0));
	dp[0][0] = 1;
	
	int pw = 1;
	for(int i = 0; i < n; i++) pw = (pw * 10) % 13;
	
	for(int i = 0; i < n; i++) {
		pw = divide13(pw, 10);
		if(s[i] == '?') {
			for(int j = 0; j < 13; j++) {
				for(int k = 0; k < 10; k++) {
					(dp[i + 1][(j + (k) * pw) % 13] += dp[i][j]) %= P;
				}
			}
		} else {
			for(int j = 0; j < 13; j++) {
				(dp[i + 1][(j + (s[i] - '0') * pw) % 13] += dp[i][j]) %= P;
			}
		}
	}
	
	cout << dp[n][5] << endl;
}

int main() {
	ios_base::sync_with_stdio(false);
	solve();
    return 0;
}

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

int main(){
  string S,T; cin>>S>>T;
  
  int N=S.size();
  int M=T.size();
  
  reverse(S.begin(),S.end());
  reverse(T.begin(),T.end());
  
  bool OK=false;
  
  for(int i=0;i<N-M+1;i++){
    for(int j=0;j<M;j++){
      if(S.at(i+j)!='?'  && S.at(i+j)!=T.at(j)){
        break;
      }
      else if(j==M-1){
        OK = true;
        
        for(int k=0;k<M;k++){
          S.at(i+k)=T.at(k);
        }
      }
    }
    if(OK)
      break;
  }
  
  reverse(S.begin(),S.end());
  
  for(int i=0;i<N;i++){
    if(S.at(i)=='?')
      S.at(i)='a';
  }
  
  if(OK)
    cout<<S;
  else
    cout<<"UNRESTORABLE";
  
}

Measured memory_bytes: 256
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#include <numeric>
typedef long long Int;
#define rep(i,a,b) for(Int i=a;i<b;++i)
#define rrep(i,a,b) for(Int i=a;i>=b;--i)
using namespace std;

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

    int X, A, B; cin >> X >> A >> B;
    if (A >= B) cout << "delicious" << endl;
    else if (X >= (B-A)) cout << "safe" << endl;
    else cout << "dangerous" << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<cmath>
#include<algorithm>
using namespace std;
#define INF 0x3f3f3f3f
int a[15][15];
int b[15];
int main() {
	int n, m, x, i, j, k, temp, mi = INF, y, ans, money;
	cin >> n >> m >> x;
	for (i = 1; i <= n; i++) {
		for (j = 0; j <= m; j++) {
			cin >> a[i][j];
		}
	}
	int t = pow(2, n);
	for (i = n + 1; i < 15; i++)b[i] = -1;
	temp = 1;
	for (i = 0; i < t; i++) {
		while (1) {
			if (b[temp] == 2) {
				b[temp] = 0;
				b[++temp] += 1;
			}
			else break;
		}
		y = 1;
		for (j = 1; j <= m; j++) {
			ans = 0;
			for (k = 1; k <= n; k++) {
				ans += a[k][j] * b[k];
			}
			if (ans < x) {
				y = 0;
				break;
			}
		}
		if (y == 1) {
			money = 0;
			for (j = 1; j <= n; j++)money += a[j][0] * b[j];
			mi = min(mi, money);
		}
		temp = 1;
		b[temp] += 1;
	}
	if (mi == INF)cout << -1 << endl;
	else cout << mi << endl;
	return 0;
}

Measured memory_bytes: 4096
use std::io;
use std::str::FromStr;
use std::iter::FromIterator;
use std::collections::HashMap;

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

fn c(n: i32) -> i64{
  let mut ret: i64 = 1;
  for i in n-2..n {
    ret *= (i + 1) as i64;
  }
  return ret / 2i64;
}

fn main() {
  let n: i32 = input();
  let mut s_map: HashMap<String, usize> = HashMap::new();
  for i in 0..n {
    let raw: String = input();
    let mut iter: Vec<_> = raw.chars().collect();
    iter.sort();
    let mut s: String = String::new();
    for c in iter {
      s.push(c);
    }
    let count = s_map.entry(s).or_insert(0);
    *count += 1;
  }
  let mut sum: i64 = 0;
  for n in s_map.values() {
    sum += c(*n as i32) as i64;
  }
  println!("{:?}", sum);
}


Measured memory_bytes: 15420
#!/usr/bin/env python3

def II(): return int(input())
def MII(): return map(int, input().split())
def LII(): return list(map(int, input().split()))

def main():
    K, T = MII()
    A = LII()

    A.sort()
    cnt = A[-1] - sum(A[:-1]) - 1
    print(cnt if cnt > 0 else 0)

if __name__ == '__main__':
    main()


Measured memory_bytes: 9088
import java.util.Scanner


object Main {

  def read() = {
    val sc = new Scanner(System.in)
    val nSamples, nFeatures, intercept = sc.nextInt()
    val coef: Seq[Int] = for (i <- 0 until nFeatures) yield sc.nextInt()
    val samples: Seq[Seq[Int]] = for (i <- 0 until nSamples) yield {
      for (j <- 0 until nFeatures) yield sc.nextInt()
    }
    (nSamples, nFeatures, intercept, coef, samples)
  }

  case class Classification(coef: Seq[Int], intercept: Int) {
    private def dot(x: Seq[Int], y: Seq[Int]): Int = (x, y).zipped.map(_ * _).sum

    def decisionFunction(x: Seq[Int]): Int = dot(x, coef) + intercept

    def predict(x: Seq[Int]): Boolean = decisionFunction(x) > 0
  }

  def solve(nSamples: Int, nFeatures: Int, intercept: Int, coef: Seq[Int], samples: Seq[Seq[Int]]): Int = {
    val clf = Classification(coef, intercept)
    val predicts = samples.map(clf.predict)
    predicts.count(p => p == true)
  }

  def main(args: Array[String]): Unit = {
    val (nSamples, nFeatures, intercept, coef, samples) = read()
    println(solve(nSamples, nFeatures, intercept, coef, samples))
  }
}

Measured memory_bytes: 27456
#include<stdio.h>
 
int main()
{
  int i,j,N,col,max;
  int flag[8]={0};
  j=0;
  col=0;
  scanf("%d",&N);
  int a[N];
  for(i = 0;i<N;i++){
    scanf("%d",&a[i]);
  }
  for(i = 0;i < N;i++){
    if(1<=a[i] && a[i] <= 399){
      if(flag[0]==0){
      flag[0] =1;
      }
    }else if(a[i] <= 799){
      if(flag[1]==0){
      flag[1] =1;
      }
    }else if(a[i] <= 1199){
      if(flag[2]==0){
      flag[2] =1;
      }
    }else if(a[i] <= 1599){
      if(flag[3]==0){
     flag[3] =1;
      }
    }else if(a[i] <= 1999){
      if(flag[4]==0){
      flag[4] =1; 
      }
    }else if(a[i] <= 2399){
    if(flag[5]==0){
      flag[5] =1;
    }
    }else if(a[i] <= 2799){
      if(flag[6]==0){
     flag[6] =1;    
      }
    }else if(a[i] <= 3199){
      if(flag[7]==0){
      flag[7] =1;
      }
    }else{
      j++;
    }
  }
    for(i=0;i<8;i++){
    	col+=flag[i];
    }
  max = col+j;
  if(col ==0){ 
    col=1;
    max = j;
  }
  printf("%d %d",col,max);
  return 0;
}

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

#define REP(i,n) for(int i=0;i<n;i++)
#define INF 100000000000
typedef long long ll;

int main() {
	ll n, k, comp;
	cin >> n >> k;
	if (n >= k) {
		ll a = n / k;
		n = n % (a * k);
	}
	
	if (n < k && n != 0) {
		comp = k - n;
		while (abs(k - comp) < comp) {
			comp = abs(k - comp);
		}
		n = comp;
	}
	cout<<n;
}

Measured memory_bytes: 3604
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<LL, LL> P;
typedef pair<int, P> PPI;
typedef pair<LL, LL> PL;
typedef long long LL;
// LLONG_MIN, INT_MIN
#define xx first
#define yy second

// int seg[810000];
// void build(int id=1, int l=0, int r = n){
//   if(l==r-1){
//     seg[id] = da[l];
//   }
//   int mid = (l+r)/2;
//   build(id*2, l, mid);
//   build(id*2+1,mid, r);
//   s[id] = max(s[id*2],s[id*2+1]);
// }
// void mx(int x, int y, int id=1, int l=0, int r = n){
//   if(x>=r||y<=l) return -1;
//   if(l>=x&&r<=y)return seg[id];
//   int mid = (l+r)/2;
//   return max(mx(x,y,id*2,l,mid),mx(x,y,id*2+1,mid, r));
// }

const int MOD = 1e9 + 7;
LL dp[110000][3];
string st;
LL n;
LL dfs(LL p, LL ban){
  if(p==n)return 1;
  if(dp[p][ban])return dp[p][ban];
  if(ban){
      if(st[p]=='0')dp[p][ban] = dfs(p+1, 1);
      else dp[p][ban] = 2*dfs(p+1, 1) + dfs(p+1,0);
  }
  else
    dp[p][ban] = 3*dfs(p+1, 0);
  dp[p][ban] %= MOD;
  return dp[p][ban];
}
int main()
{
  //freopen("input", "r", stdin);
  // freopen("output", "w", stdout);
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);
  cin>>st;
  n = st.size();
  cout<<dfs(0,1)<<endl;
}


Measured memory_bytes: 7504
#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <typeinfo>
#include <numeric>
#include <functional>
#include <unordered_map>
#include <bitset>
#include <stack>
#include <assert.h>
#include <unordered_set>
#include <random>


using namespace std;
using ll = long long;
using ull = unsigned long long;

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

#define REP(i, n) for(ll i = 0; i < n; i++)














int main(){
    ll h, n;
    cin >> h >> n;
    vector<ll> a(n), b(n);
    REP(i, n){
        cin >> a[i] >> b[i];
    }
    vector<ll> dp(h + 1, INF);
    dp[h] = 0;
    for(ll i = h; i > 0; i--){
        REP(j, n){
            dp[max(i - a[j], 0LL)] = min(dp[max(i - a[j], 0LL)], dp[i] + b[j]);
        }
    }
    cout << dp[0] << endl;
}

Measured memory_bytes: 384
import java.util.*;

public class Main {
	public static void main(String[] args) {
		
		Scanner sc = new Scanner(System.in);
		LinkedList<String> picList = new LinkedList<>();
		LinkedList<Integer> numList = new LinkedList<>();
		
		int trpData[][] = new int[13][4];
		//???????????£??\
		for(int j = 0; j < 4; j++) {
			for(int i = 0; i < 13; i++) {
				trpData[i][j] = 0;
			}
		}
		
		int n = sc.nextInt();
		
		int i = 0;
		String pic = "";
		int num = 0;
		//????????°??????
		while(i < n) {
			pic = sc.next();
			num = sc.nextInt();
			if(pic.equals("S")) {
				trpData[num-1][0] = 1;
			} else if(pic.equals("H")) {
				trpData[num-1][1] = 1;
			} else if(pic.equals("C")) {
				trpData[num-1][2] = 1;
			} else if(pic.equals("D")) {
				trpData[num-1][3] = 1;
			}
			i++;
		}
		
		//?????????????´?
		int cnt = 0;
		for(int j = 0; j < 4; j++) {
			for(i = 0; i < 13; i++) {
				if(trpData[i][j] == 0) {
					if(j == 0) {
						picList.add("S"); 
					} else if(j == 1) {
						picList.add("H"); 
					} else if(j == 2) {
						picList.add("C"); 
					} else if(j == 3) {
						picList.add("D");
					}
					numList.add(i+1);
					cnt++;
				}
			}
		}
		
		//
		for(i = 0; i < cnt; i++) {
			System.out.println(picList.get(i) + " " + numList.get(i));
		}
	}
}

Measured memory_bytes: 26380
#include <iostream>
#include <string>
#include <vector>

using namespace std;

int main(){
  vector<string> strarray;
  string str;
  while(cin>>str){
    strarray.push_back(str);
  }

  int count=0;
  for(string str:strarray){
    bool sym=true;
    int length=str.length();
    if(length==1){
      count++;
      continue;
    }
    for(int i=length/2+length%2;i<length;i++){
      sym&=(str[i]==str[length-1-i]);
    }
    if(sym){
      count++;
    }
  }
  cout<<count<<endl;

}

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

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define FOR(i,n,m) for(int i=(int)(n); i<=(int)(m); i++)
#define RFOR(i,n,m) for(int i=(int)(n); i>=(int)(m); i--)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define RITR(x,c) for(__typeof(c.rbegin()) x=c.rbegin();x!=c.rend();x++)
#define setp(n) fixed << setprecision(n)

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 (a>b) { a=b; return 1; } return 0; }

#define ll long long
#define vll vector<ll>
#define vi vector<int>
#define pll pair<ll,ll>
#define pi pair<int,int>

#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define ins insert

using namespace std;

/* Some Libraries */

//-------------------------------------------------

int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n; cin>>n;
    vi a(n);
    rep(i,n) cin>>a[i];
    int xsum=0, j=0;
    ll ans=0;
    rep(i,n){
        while(j<n && !(xsum&a[j])) xsum+=a[j++];
        ans+=j-i;
        xsum-=a[i];
    }
    cout<<ans<<"\n";
    return 0;
}


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

using namespace std;

using ll = long long;

int main() {
  ll n, a, b;
  cin >> n >> a >> b;
  if (a > b) {
    cout << 0 << endl;
  } else if (n == 1) {
    if (a == b)
      cout << 1 << endl;
    else
      cout << 0 << endl;
  } else
    cout << ((n - 1) * b + a) - ((n - 1) * a + b) + 1 << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define double long double
#define REP(i,x,n) for(int i=x;i<(int)n;i++)
#define rep(i,n) REP(i,0,n)
#define sp(p) cout<<setprecision(16)<<fixed<<p<<endl;
#define debug(x) cerr<<#x<<": "<<x<<endl;
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define VSORT(a) sort(all(a))
#define RSORT(a) sort(rall(a))
#define vout(v) for(int i=0;i<(int)v.size()-1;i++){cout<<v[i]<<" ";}cout<<v[v.size()-1]<<"\n";
#define debg(a) cout<<#a<<" "<<a<<endl;
#define show(a) for(cont &y:a){for(cont &x:y){cout<<x<<" ";}cout<<endl;}
template<class T>inline int out(const T &t){ print(t); putchar('\n'); return 0; }
template<class T>inline T gcd(T a,T b){if(b==0)return a; return(gcd(b,a%b));}
template<class T>inline T lcm(T a,T b){return a/gcd(a,b)*b;}
typedef long long ll;
typedef pair<ll,ll> P;
typedef vector<ll> V;
const long long MOD=1000000007;
const long long INF = 1e18;
vector <ll> dp;


void solve(long long N, std::vector<long long> d){
    VSORT(d);
    auto itr = unique(all(d));
    // ll n = d.size(d.begin(), itr);
    ll n = itr - d.begin();
    cout << n << "\n";
    // vout(i, N, d);
    // vout(d);
}

int main(){
    long long N;
    scanf("%lld",&N);
    std::vector<long long> d(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&d[i]);
    }
    solve(N, std::move(d));
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
    int x;
    int y;
    int i = 0;
    
    while(i >= 0){
        cin >> x >> y;
        if((x == 0) && (y == 0))break;
        if(x <= y){
            cout << x << " " << y << endl;
        }else{
            cout << y << " " << x << endl;
        }
    
        i ++;
    }
}


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


void solve(long long K, long long A, long long B){
int ans=0;
for(int i=A; i<=B; i++){
    if(i%K==0){
        ans++;
        break;
    }
}
if(ans==1)cout<< "OK" <<endl;
else cout<< "NG" <<endl;
}

int main(){
    long long K;
    scanf("%lld",&K);
    long long A;
    scanf("%lld",&A);
    long long B;
    scanf("%lld",&B);
    solve(K, A, B);
    return 0;
}


Measured memory_bytes: 3712
#[allow(unused_imports)] use proconio::{input, marker::{Bytes, Chars, Usize1, Isize1}};
#[allow(unused_imports)] use std::cmp::{min, max};
#[allow(unused_imports)] use superslice::Ext as _;

#[proconio::fastout]
fn main() {
	input! {
		n: usize,
		d: [(usize, usize); n],
	}

	let mut count = 0;
	for i in 0..n {
		if d[i].0 == d[i].1 {
			count += 1;
			if count >= 3 {
				println!("Yes");
				return;
			}
		}
		else {
			count = 0;
		}
	}

	println!("No");
}


Measured memory_bytes: 2168
#include<bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(),(x).end()
const long long mod = 1e9+7;
//////////////////////////////////

int main(){
  int n, k; cin >> n >> k;
  int r, s, p;
  cin >> r >> s >> p;
  string t; cin >> t;
  int score = 0;
  for(int kk=0; kk<k; kk++) {
    char c;
    for(int i=kk; i<n; i+=k) {
      if (i == kk) {
        if (t[i] == 'r') score += p;
        if (t[i] == 's') score += r;
        if (t[i] == 'p') score += s;
        c = t[i];
      } else {
        if (t[i] == 'r') {
          if (t[i] != c) {
            score += p;
            c = t[i];
          } else {
            c = ' ';
          }
        }
        if (t[i] == 's') {
          if (t[i] != c) {
            score += r;
            c = t[i];
          } else {
            c = ' ';
          }
        }
        if (t[i] == 'p') {
          if (t[i] != c) {
            score += s;
            c = t[i];
          } else {
            c = ' ';
          }
        }
      }
    }
  }
  cout << score << endl;

}

// EOF

Measured memory_bytes: 512
#include<bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
#define ll long long
#define ld long double
#define mk make_pair
#define fi first
#define se second
#define vll vector<ll>
#define pii pair<ll,ll>
#define vvll vector< vector<ll> >
#define pb push_back
#define sz(v) (v).size()
#define inf 1e18
#define md 1000000007
#define all(v) (v).begin(),(v).end()
#define rep(i,a,b) for(ll i=a;i<b;++i)
#define tel(a){cout<<a<<"\n";}
#define tell(a,b){cout<<a<<" | "<<b<<"\n";}
#define telll(a,b,c){cout<<a<<" | "<<b<<" | "<<c<<"\n";}
#define teln(v,n){cout<<"v- ";rep(o,0,n)cout<<v[o]<<" ";cout<<"\n";}
#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define tihs if(fopen("inp.txt","r"))freopen("inp.txt", "r", stdin),freopen("out.txt", "w", stdout);
using namespace std;
#define TRACE
 
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    cerr << name << " : " << arg1 << std::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...);
}
#else
#define trace(...)
#endif
 

#define M 100010


int main(){
	IOS;
	tihs;
	
	string s;cin>>s;
	deque<char>st;
	rep(i,0,sz(s))st.pb(s[i]);
	ll q;cin>>q;
	ll f=1;
	while(q--){
		ll t;cin>>t;
		if(t==1){
			f=!f;
		}
		else {
			ll p;cin>>p;
			char c;cin>>c;
			if(p==2)p=0;
			if(p^f) st.pb(c);
			else st.push_front(c);
		}
	}
	string ans="";
	while(!st.empty()){
		ans+=st.back();
		st.pop_back();
	}
	if(f)reverse(all(ans));
	cout<<ans;
	return 0;
}

Measured memory_bytes: 1368
#include <iostream>
#include <vector>

using namespace std;
#define ll long long

vector<int> par, rnk;
int g;
void init(int n) {
    g = n;
    par.clear();
    rnk.clear();
    par.resize(n);
    rnk.resize(n);
    for(int i = 0; i < n; i++) {
        par[i] = i;
        rnk[i] = 0;
    }
}
int find(int x) {
    if(par[x] == x) {
        return x;
    } else {
        return par[x] = find(par[x]);
    }
}
void unite(int x, int y) {
    x = find(x);
    y = find(y);
    if(x == y) {
        return;
    } else {
        if(rnk[x] < rnk[y]) {
            par[x] = y;
        } else {
            par[y] = x;
            if(rnk[x] == rnk[y]) rnk[x]++;
        }
    }
    g--;
}
bool same(int x, int y) {
    return find(x) == find(y);
}

int main() {
    int N, M;
    cin >> N >> M;
    vector<int> a(M), b(M);
    for(int i = 0; i < M; i++) {
        cin >> a[i] >> b[i];
        a[i]--;
        b[i]--;
    }
    int ans = 0;
    for(int i = 0; i < M; i++) {
        init(N);
        for(int j = 0; j < M; j++) {
            if(j == i) continue;
            unite(a[j], b[j]);
        }
        if(g == 2) ans++;
    }
    cout << ans << endl;
    return 0;
}

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

int n, m, p, d;
vector<string> ls;

bool check() {
    int c = m;
    for (int i = 0; i < d; i++) {
        if (ls[i][c] == '1') {
            c++;
        } else if (0 <= c-1 && ls[i][c-1] == '1') {
            c--;
        }
    }
    return c == p;
}

int main() {
    while (cin >> n, n != 0) {
        cin >> m >> p >> d;
        m--, p--;
        ls.clear();
        for (int i = 0; i < d; i++) {
            string s;
            cin >> s;
            ls.push_back(s);
        }

        if (check()) {
            cout << 0 << endl;
            continue;
        }

        int y, x;
        for (int i = 0; i < d; i++) {
            for (int j = 0; j < n-1; j++) {
                if (ls[i][j] == '0' && (
                        (n == 2) ||
                        (j == 0 && ls[i][j+1] == '0') ||
                        (j == n-2 && ls[i][j-1] == '0') ||
                        (ls[i][j-1] == '0' && ls[i][j+1] == '0'))) {
                    ls[i][j] = '1';
                    if (check()) {
                        y = i+1;
                        x = j+1;
                        goto found;
                    }
                    ls[i][j] = '0';
                }
            }
        }
        cout << 1 << endl;
        continue;
found:
        cout << y << ' ' << x << endl;
        continue;
    }
    return 0;
}

Measured memory_bytes: 1212
import sys
import time
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 8)
INF = float('inf')
MOD = 10 ** 9 + 7

def main():
    A,B,C,X,Y = map(int, readline().split())
    Z = min(X, Y)
    if A + B >= C * 2:
        ans = min(C * Z * 2 + A * (X - Z) + B * (Y - Z), C * max(X, Y) * 2)
    else:
        ans = A * X + B * Y
    print(ans)

if __name__ == '__main__':
    main()

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define ll long long
#define pb push_back

using namespace std;

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

	int count[n+2];
	memset(count, 0, sizeof count);

	while (m--){
		int a,b;
		cin >> a >> b;
		count[a]++;
		count[b]++;
	}

	for (int i = 1; i <= n; i++){
		cout << count[i] << endl;
	}

	return 0;
}

Measured memory_bytes: 3648
#include <cstdio>
#include <algorithm>
#include <set>
#include <map>
#include <vector>

#define int long long
#define SZ(x) ((int) (x).size())
#define MK std::make_pair
#define ALL(x) (x).begin(), (x).end()
#define x first
#define y second

typedef std::pair<int, int> pii;
typedef long long i64;

enum {
  MAXN = 100000 + 5
};

std::set<pii> set0[MAXN], set1[MAXN];
std::vector<pii> vec0[MAXN], vec1[MAXN];
std::map<int, int> map0, map1;
std::map<pii, int> id;

int n, a, b;
pii s[MAXN];
int dist;
i64 ans;

void del(pii t) {
  int x, y;
  x = t.x, y = t.y;
  set0[map0[x+y]].erase(t);
  set1[map1[x-y]].erase(t);
}

void addinfo(int id0, std::set<pii> &set, pii l, pii r, std::vector<int> &vec) {

  // static int count;

  std::set<pii>::iterator it;
  it = set.lower_bound(l);
  while (it != set.end() && *it < r) {

    // fprintf(stderr, "(%lld %lld)\n", id0, id[*it]);

    vec.push_back(id[*it++]);

    // ++ count;

  }
}

void addans(int id0, std::vector<pii> &vec, pii l, pii r) { // [l, r)
  ans += std::lower_bound(ALL(vec), r) - std::lower_bound(ALL(vec), l);
}

// int vis[MAXN];

void calc(int u) {

  // if (vis[u]) return ;
  // vis[u] = true;

  int x, y, i;
  std::vector<int> vec;
  x = s[u].x, y = s[u].y;
  if (map0.count(x+y+dist)) {
    addinfo(u,set0[map0[x+y+dist]], MK(x+1, -1), MK(x+dist+1, -1), vec);
    addans (u,vec0[map0[x+y+dist]], MK(x+1, -1), MK(x+dist+1, -1));
  }
  if (map0.count(x+y-dist)) {
    addinfo(u,set0[map0[x+y-dist]], MK(x-dist, -1), MK(x, -1), vec);
    addans (u,vec0[map0[x+y-dist]], MK(x-dist, -1), MK(x, -1));
  }
  if (map1.count(x-y+dist)) {
    addinfo(u,set1[map1[x-y+dist]], MK(x, -1), MK(x+dist, -1), vec);
    addans (u,vec1[map1[x-y+dist]], MK(x, -1), MK(x+dist, -1));
  }

  if (map1.count(x-y-dist)) {
    addinfo(u,set1[map1[x-y-dist]], MK(x-dist+1, -1), MK(x+1, -1), vec);
    addans (u,vec1[map1[x-y-dist]], MK(x-dist+1, -1), MK(x+1, -1));
  }
  std::sort(ALL(vec));
  vec.resize(std::unique(ALL(vec)) - vec.begin());
  for (i=0; i<SZ(vec); ++i) del(s[vec[i]]);
  for (i=0; i<SZ(vec); ++i) calc(vec[i]);
}

void exec() {
  int i, x, y, z;
  scanf("%lld%lld%lld", &n, &a, &b), --a, --b;
  for (i=0; i<n; ++i)
    scanf("%lld%lld", &s[i].x, &s[i].y);
  for (i=0; i<n; ++i) {
    x = s[i].x, y = s[i].y;
    (z = map0.count(x+y)? map0[x+y] : SZ(map0)), map0[x+y] = z, set0[z].insert(s[i]), vec0[z].push_back(s[i]);
    (z = map1.count(x-y)? map1[x-y] : SZ(map1)), map1[x-y] = z, set1[z].insert(s[i]), vec1[z].push_back(s[i]);
    id[s[i]] = i;
  }
  for (i=0; i<MAXN; ++i) {
    std::sort(ALL(vec0[i]));
    std::sort(ALL(vec1[i]));
  }
  dist = std::abs(s[a].x - s[b].x) + std::abs(s[a].y - s[b].y);
  del(s[a]);
  calc(a);
  printf("%lld\n", ans/2);
}
#undef int
int main() {
  if (fopen("E.in", "r") != NULL) {
    freopen("E.in", "r", stdin);
    freopen("E.out", "w", stdout);
  }
  exec();
  return 0;
}


















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

const int MOD = 1000000007;

int main() {
    int n, m;
    cin >> n >> m;
    vector<bool> out(100000);
    for (int i = 0; i < m; i++)
    {
        int a;
        cin >> a;
        out.at(a) = true;
    }
    
    vector<int> dp(n + 1);
    dp.at(0) = 1;
    for (int i = 0; i < n; i++)
    {
        if (out.at(i)) continue;
        
        dp.at(i + 1) += dp.at(i) % MOD;
        dp.at(i + 1) %= MOD;
        
        if (i + 2 > n) break;
        dp.at(i + 2) += dp.at(i) % MOD;
        dp.at(i + 2) %= MOD;
    }
    
    cout << dp.at(n) << endl;
}

Measured memory_bytes: 640
n=int(input())
w=list(map(int,input().split()))
ans=10000
for i in range(n):
    s1=0
    s2=0
    for j in range(i+1):
        s1+=w[j]
    for k in range(i+1,n):
        s2+=w[k]
    ans=min(ans,abs(s1-s2))
print(ans)

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

#define lli long long int
#define REP(i,s,n) for(int i=s;i<n;i++)
#define NUM 2520
#define INF (1LL<<50)
#define DEBUG 0
#define mp(a,b) make_pair(a,b)
#define SORT(V) sort(V.begin(),V.end())
#define PI (3.141592653589794)
#define TO_STRING(VariableName) # VariableName
#define LOG(x) if(DEBUG)cout<<TO_STRING(x)<<"="<<x<<" "<<endl;
#define LOG2(x,y) if(DEBUG)cout<<TO_STRING(x)<<"="<<x<<" "<<TO_STRING(y)<<"="<<y<<endl;
#define LOG3(x,y,z) if(DEBUG)cout<<TO_STRING(x)<<"="<<x<<" "<<TO_STRING(y)<<"="<<y<<" "<<TO_STRING(z)<<"="<<z<<endl;
#define LOG4(w,x,y,z) if(DEBUG)cout<<TO_STRING(w)<<"="<<w<<" "<<TO_STRING(x)<<"="<<x<<" "<<TO_STRING(y)<<"="<<y<<" "<<TO_STRING(z)<<"="<<z<<endl;

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

lli d[4][3000][3000];
bool dd[4][3000][3000];

#define U 0
#define R 1
#define D 2
#define L 3

std::vector<std::string> S;

lli dI[4] = {-1,0,1,0};
lli dJ[4] = {0,1,0,-1};
lli H,W;

lli calc(lli dir,lli nowI,lli nowJ){
    LOG3(dir,nowI,nowJ);
    if(nowI<0 || nowI>=H || nowJ<0 || nowJ>=W)return 0;
    if(dd[dir][nowI][nowJ])return d[dir][nowI][nowJ];
    dd[dir][nowI][nowJ]=true;

    if(S[nowI][nowJ]=='#')return 0;
    else return d[dir][nowI][nowJ] = calc(dir,nowI+dI[dir],nowJ+dJ[dir])+1;
}

void func(long long H, long long W){

    lli ans = -INF;
    REP(i,0,H){
        REP(j,0,W){
            if(S[i][j]=='#')continue;
            lli sum = 0;
            REP(dir,0,4)sum += calc(dir,i,j);
            chmax(ans,sum-3);
        }
    }
    cout<<ans<<endl;

}

int main(){
    // cout << fixed << setprecision(5);

    scanf("%lld",&H);
    scanf("%lld",&W);
    S.resize(H);
    for(int i = 0 ; i < H ; i++){
        std::cin >> S[i];
    }
    func(H, W);
    return 0;
}


Measured memory_bytes: 231808
#include<bits/stdc++.h>
using namespace std;
int main(){
  int a,b,x;
  cin >> a >> b;
  x=a+b;
  if(x%2==0){
    cout << x/2 << endl;
  }
  else{
    cout << x/2+1 << endl;
  }
}

Measured memory_bytes: 3620
import collections

a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]
c = [int(i) for i in input().split()]

x = a+b+c
c = collections.Counter(x)

if len(list(filter(lambda x:x>2,c.values()))) > 0:
    print("NO")
else:
    print("YES")


Measured memory_bytes: 3316
#include<bits/stdc++.h>
using namespace std;
int main(void){
	int w,h,n;
	int x,y,a;
	int box[101][101];
	int i,j;
	int cnt;
	cin>>w>>h>>n;
	for(i=1;i<101;i++){
		for(j=1;j<101;j++){
			box[i][j]=0;
		}
	}
	for(int k=0;k<n;k++){
		cin>>x>>y>>a;
		if(a==1){
			for(i=1;i<=x;i++){
				for(j=1;j<=h;j++){
					box[j][i]=1;
				}
			}
		}
		else if(a==2){
			for(i=x+1;i<=w;i++){
				for(j=1;j<=h;j++){
					box[j][i]=1;
				}
			}
		}
		else if(a==3){
			for(j=1;j<=y;j++){
				for(i=1;i<=w;i++){
					box[j][i]=1;
				}
			}
		}
		else{
			for(j=y+1;j<=h;j++){
				for(i=1;i<=w;i++){
					box[j][i]=1;
				}
			}
		}
	}
	cnt=0;
	for(i=1;i<=h;i++){
		for(j=1;j<=w;j++){
			if(box[i][j]==0)	cnt++;
		}
	}
	cout<<cnt<<endl;
	return 0;
}

Measured memory_bytes: 256
N=int(input())
h=list(map(int,input().split()))
l=[0]*N
z=0
for i in range(0,100):
    f=False
    for j in range(0,N):
        if h[j]>i:
            if not f:
                f=True
        else:
            if f:
                f=False
                z+=1
    if f:
        z+=1

print(z)

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

int main()
{
    int N;
    long K;
    cin >> N >> K;

    vector<int> A(N);
    vector<int> B(N);

    vector<pair<int, int>> P(N);

    int a;
    int b;
    rep(i, N)
    {
        cin >> a >> b;
        P.at(i) = pair<int, int>(a, b);
    }

    sort(P.begin(), P.end());

    long cnt = 0;

    int ans = 0;
    rep(i, N)
    {
        pair<int, int> p = P.at(i);
        cnt += p.second;
        if (cnt >= K)
        {
            ans = p.first;
            break;
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 4852