akhauriyash/Code-Regression huggingface dataset:
S = input()
T = input()
f = [-1 for _ in range(130)]
g = [-1 for _ in range(130)]
ans = "Yes"
for i in range(len(S)):
  s = ord(S[i])
  t = ord(T[i])
  if f[s] == -1:
    f[s] = t
  else:
    if f[s] != t:
      ans = "No"
  if g[t] == -1:
    g[t] = s
  else:
    if g[t] != s:
      ans = "No"
print(ans)


Measured memory_bytes: 3632
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define vi vector<int>
#define vl vector<long long>
#define vvi vector<vector<int>>
#define fin(ar,k,n) for(int i=k;i<n;i++) cin>>ar[i]
#define fout(ar,k,n) for(int i=k;i<n;i++) cout<<ar[i]<<' '
#define all(z) z.begin(),z.end()
#define mcc ((int)1e9+7)
#define mcf 998244353
#define mi map<int,int>
#define mem(a,n) memset(a,n,sizeof(a))
#define pii pair<int,int>
#define mp(a,b) make_pair(a,b)

using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> fst;


const int N=2e6+8;
ll fac[N];

ll binpow(ll a,ll b)
{
    ll res=1; a%=mcc;
	if (a==1 || b==0) return 1;
	else if (a==0) return 0;
    while(b)
    {
        if (b&1) res=(res*a)%mcc;
        b>>=1;
        a=(a*a)%mcc;
    }
    return res%mcc;
}

void pre()
{
    fac[0]=fac[1]=1;
    for (int i=2;i<N;i++)
    {
        fac[i]=((fac[i-1]%mcc)*i)%mcc;
    }
}
ll inv(ll n)
{
    return binpow(n,mcc-2);
}

ll ncr(ll n, ll r)
{
    return (((fac[n]*inv(fac[r]))%mcc)*(inv(fac[n-r])%mcc))%mcc;
}


void solve()
{
	ll n,z,sm;
	string s;
	cin>>n;
	cin>>s;
	z=s.size();
	sm=binpow(26,n+z);
	for (int i=0;i<z;i++)
	{
		sm-=ncr(n+z,i)*binpow(25,n+z-i);
		sm=(sm+mcc)%mcc;
	}
	cout<<(sm+mcc)%mcc<<endl;
}

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

Measured memory_bytes: 19892
#include <bits/stdc++.h>
using namespace std;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef pair<int,int> pii;
typedef long long ll;
const long long MOD=1000000007;
#define rep(i,n) for(ll i=0;i<(n);i++)
#define rep2(i,m,n) for(ll i=(m);i<(n);i++)
#define ALL(v) v.begin(), v.end()
#define pb push_back





int main(){

    ll n;
    cin>>n;

    vector<ll> data(n);
    rep(i,n){
        ll tmp;
        cin>>tmp;
        data.at(i)=tmp;
    }

    ll answer=0;

    for (ll i=0;i<n;i++){
        for (ll j=i+1;j<n;j++){
            for (ll k=j+1;k<n;k++){

                if (data.at(i)!=data.at(j) and data.at(j)!=data.at(k) and data.at(i)!=data.at(k)){
                    ll a,b,c;
                    a=data.at(i);
                    b=data.at(j);
                    c=data.at(k);

                    if ((a+b)>c and (b+c)>a and (a+c)>b){
                        answer++;
                    }


                }






            }
        }
    }



    cout<<answer<<endl;














}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
    
#define int long long int
#define vi vector<int>
#define vvi vector<vi>
#define read(a)  for(int i = 0; i < n; i++) cin >> a[i];
#define print(a)  for(int i = 0; i < n; i++) cout << a[i] << " ";
#define pb push_back
#define pql priority_queue<int>
#define pqs priority_queue<int, vi, greater<int>>
#define pqlv priority_queue<vi>
#define pqsv priority_queue<vi, vvi, greater<vi>>
#define endl '\n'
#define N 10000002
#define MOD 1000000007

signed main() {
    int n;
    cin >> n;
    vi a(n);
    map<int, int> mp;
    int sum = 0;
    for(int i = 0; i < n; i++) {
        cin >> a[i];
        sum += a[i];
        mp[a[i]]++;
    }
    int q;
    cin >> q;
    while(q--) {
        int x, y;
        cin >> x >> y;
        sum += (y * mp[x]);
        sum -= (x * mp[x]);
        mp[y] += mp[x];
        mp[x] = 0;
        cout << sum << endl; 
    }
}

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

int main(void) {
    int x, y;
    scanf("%d %d", &x, &y);

    int sum = 0;

    if (x == 1) sum += 300000;
    if (x == 2) sum += 200000;
    if (x == 3) sum += 100000;
    if (y == 1) sum += 300000;
    if (y == 2) sum += 200000;
    if (y == 3) sum += 100000;
    if (x == 1 && y == 1) sum += 400000;

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

    return 0;
}


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

int main(){
  int n; cin >> n;
  int a[200010];
  for (int i = 0; i < n; i++){
    cin >> a[i];
  }
  vector<int64_t> s(n+1);
  s.at(0) = 0;
  for (int i = 1; i <= n; i++){
    s.at(i) = s.at(i-1) + a[i-1];
  }
  int b = lower_bound(s.begin(), s.end(), (double)s.at(n)/2) - s.begin();
  int64_t d1, d2;
  d1 = abs(s.at(b) - (s.at(n)-s.at(b)));
  d2 = abs(s.at(b-1) - (s.at(n)-s.at(b-1)));
  int64_t ans = min(d1, d2);
  cout << ans << endl;
}

Measured memory_bytes: 2560
#include <iostream>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <algorithm>
#include <limits>
#include <ios>
#include <iomanip>
using namespace std;

#define rep(i,N) for(int i=0; i<N; i++)
#define revrep(i,N) for(int i=N-1; i>=0; i--)

typedef long long ll;

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

    int y = atoi(S.substr(0,4).c_str());
    int m = atoi(S.substr(5,2).c_str());
    int d = atoi(S.substr(8,2).c_str());
    //cout << y << m << d;

    if (y == 2019) {
        if (m == 4) {
            if (d <= 30) {
                cout << "Heisei" << endl;
                return 0;
            }
        } else if (m < 4) {
            cout << "Heisei" << endl;
            return 0;
        }
    } else if (y < 2019) {
        cout << "Heisei" << endl;
        return 0;
    }
    cout << "TBD" << endl;
}


Measured memory_bytes: 256
n, a, b = list(map(int, input().split()))
ans = 0

for i in range(1,n+1):
    m = str(i)
    x = len(m)
    cnt = 0
    for j in range(x):
        cnt = cnt + int(m[j])
    if a <= cnt <= b:
        ans = ans + i
    else:
        continue
print(ans)

Measured memory_bytes: 9056
def main():
    n=int(input())
    a=list(map(int,input().split()))
    b=[a[0]]
    ans=abs(a[0])
    for i in range(n-1):
        b.append(a[i+1]-a[i])
        ans+=abs(a[i+1]-a[i])
    b.append(-1*a[n-1])
    ans+=abs(a[n-1])
    for i in range(n):
        if b[i]*b[i+1]>=0:
            print(ans)
        else:
            print(ans-abs(b[i])-abs(b[i+1])+abs(b[i]+b[i+1]))
if __name__=="__main__":
    main()

Measured memory_bytes: 14172
c=[]
for i in range(3):
    c.append(list(map(int,input().split())))
if c[0][1]-c[0][0]==c[1][1]-c[1][0]==c[2][1]-c[2][0]\
 and c[0][2]-c[0][0]==c[1][2]-c[1][0]==c[2][2]-c[2][0]:
    print('Yes')
else:
    print('No')

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

int main(){
  int N;
  cin >> N;
  string S;
  cin >> S;
  int count_W[300010] = {0};
  int count_E[300010] = {0};
  int count[300010] = {0};
  
  //if(count[0] == 'W') count[0] = 1;
  //else count[0] = 0;
  for(int i=1;i<N;++i){
    // choose i as leader
    // calc left side sum
    if(S[i-1] == 'W') count_W[i] = count_W[i-1] + 1;
    else count_W[i] = count_W[i-1];
  }
  
  //if(count[N-1] == 'E') count[0] = 1;
  //else count[N-1] = 0;
  for(int i=2;i<=N;++i){
    // choose i as leader
    // calc left side sum
    if(S[N-(i-1)] == 'E') count_E[N-i] = count_E[N-(i-1)] + 1;
    else count_E[N-i] = count_E[N-(i-1)];
  }
  
  for(int i=0;i<N;++i){
    // choose i as leader
    // calc left side sum
    count[i] = count_W[i] + count_E[i];
  }
  
  sort(count, count+N);
  cout << count[0] << endl;
  
  return 0; 
}

Measured memory_bytes: 4228
# -*- coding: utf-8 -*-
import sys
import copy
import collections
from bisect import bisect_left
from bisect import bisect_right
from collections import defaultdict
from heapq import heappop, heappush
import numpy as np
import statistics
from statistics import mean, median,variance,stdev
import math

def main():
	A,B,C,X,Y = map(int, input().split(" "))
	
	if C >= A and C >= B:
		
		print(A*X + B*Y)
		sys.exit()
	
	base = A*X + B*Y
	
	if X == Y:
		tmp = C * 2 * Y
		
		print(min(base, tmp))
		sys.exit()
	

	part1 = A*X
	part21 = C*2*Y
	part22 = B*Y
	tmp = min(part21,part22)
	tmp = part1 + tmp
	ans = min(base, tmp)
	#print(ans)
			
	part1 = C*2*X
	Y_tmp = Y-X
	if Y_tmp > 0:	
		part21 = C*2*Y_tmp
		part22 = B*Y_tmp
		tmp = min(part21,part22)
		tmp = part1 + tmp
	else:
		tmp = part1
	ans = min(ans, tmp)
	#print(ans)
	
	part1 = B*Y
	part21 = C*2*X
	part22 = A*X
	tmp = min(part21,part22)
	tmp = part1 + tmp
	ans = min(ans, tmp)
	#print(ans)
		
	part1 = C*2*Y
	X -= Y
	if X > 0:
		part21 = C*2*X
		part22 = A*X
		tmp = min(part21,part22)
		tmp = part1 + tmp
	else:
		tmp = part1
	ans = min(ans, tmp)
			
	print(ans)
	
if __name__ == "__main__":
	main()


Measured memory_bytes: 21212
N = int(input())
confesses = [[-1 for _ in range(N)] for __ in range(N)]
for i in range(N):
  A = int(input())
  for __ in range(A):
    x, y = map(int, input().split())
    confesses[i][x-1] = y
answer = 0
for num in range(2**N):
  users = [0 for _ in range(N)]
  cnt = 0
  for i in range(N):
    if num>>i&1:
      users[i] = 1
      cnt += 1
  right = True
  for j, user in enumerate(users):
    if user == 1:
      for i, confess in enumerate(confesses[j]):
        if confess != -1 and users[i] != confess:
          right = False
          break
    if not right:
      break
  if right:
    answer = max(answer, cnt)
print(answer)

Measured memory_bytes: 74460
#include<stdio.h>
#include<math.h>
int main(){
  int n,i,x,y,a;
  int b[4];
  b[0]=b[2]=0;
  scanf("%d%d%d",&b[1],&b[3],&n);
  for(i=0;i<n;i++){
    scanf("%d%d%d",&x,&y,&a);
    if(a==1)b[0]=b[0]<x?x:b[0];
    if(a==2)b[1]=b[1]>x?x:b[1];
    if(a==3)b[2]=b[2]<y?y:b[2];
    if(a==4)b[3]=b[3]>y?y:b[3];
  }
  printf("%d",b[0]<b[1]&&b[2]<b[3]?(b[1]-b[0])*(b[3]-b[2]):0);
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
#define ll long long
#define P 1000000007
using namespace std;
ll l,r;
int sk1[100],sk2[100],cnt1,cnt2,dp[100][2][2][2][2];
int dfs(int x,int p,int f1,int f2,int f3){
	if(!x)return 1;
	if(dp[x][p][f1][f2][f3]!=-1)return dp[x][p][f1][f2][f3];
	int ans=0;
	for(int i=0;i<2;++i)if(i<=sk2[x]||!p)
		for(int j=0;j<=i;++j){
			if(!f1&&i&&j)ans+=dfs(x-1,p&&i==sk2[x],1,i>sk1[x],j>sk1[x]);
			else if(!f1&&i==0&&sk1[x]==0)ans+=dfs(x-1,p&&i==sk2[x],0,0,0);
			else if(f1&&(f2||i>=sk1[x])&&(f3||j>=sk1[x]))ans+=dfs(x-1,p&&i==sk2[x],1,f2|(i>sk1[x]),f3|(j>sk1[x]));
			if(ans>=P)ans-=P;
		}
	return dp[x][p][f1][f2][f3]=ans;
}
int solve(){
	while(l){
		sk1[++cnt1]=l&1;
		l>>=1;
	}
	while(r){
		sk2[++cnt2]=r&1;
		r>>=1;
	}
	return dfs(cnt2,1,0,0,0);
}
int main(){
	memset(dp,-1,sizeof(dp));
	scanf("%lld%lld",&l,&r);
	printf("%d",solve());	
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <utility>
#include <cstring>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <numeric> 
using namespace std;
typedef long long ll;
const int INF = 1<<30; 
const int MOD = 1e9 + 7;
const int dx[] = {1, 0, -1, 0};
const int dy[] = {0, 1, 0, -1};
int main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	int a, b;
	cin >> a >> b;
	if(a + b >= 10) cout << "error" << endl;
	else cout << a + b << endl;
	return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <queue>
#include <utility>
using namespace std;
const int dir[4][2] = {{-1, 0}, {0, -1}, {1, 0}, {0, 1}};
const int INF = 1e9;

int h, w, k;
int x1, y1, x2, y2;
vector<vector<char>> MP;
vector<vector<int>> dis;

bool outside(int x, int y) {
	return x < 0 or x >= h or y < 0 or y >= w;
}

bool bad(int x, int y, int nd) {
	return MP[x][y] == '@' or dis[x][y] < nd;
}

void bfs() {
	queue<pair<int, int>> que;
	que.push({x1, y1});
	dis[x1][y1] = 0;
	while (!que.empty()) {
		int x = que.front().first;
		int y = que.front().second;
		que.pop();
		for (int i = 0; i < 4; i++) {
			int nx = x, ny = y;
			int nd = dis[x][y] + 1;
			for (int j = 1; j <= k; j++) {
				nx += dir[i][0];
				ny += dir[i][1];
				if (outside(nx, ny) or bad(nx, ny, nd))
					break;
				if (dis[nx][ny] > nd) {
					que.push({nx, ny});
					dis[nx][ny] = nd;
				}
			}
		}
	}
}

int main() {
	cin >> h >> w >> k >> x1 >> y1 >> x2 >> y2;
	--x1, --y1, --x2, --y2;
	MP.resize(h, vector<char>(w));
	dis.resize(h, vector<int>(w));
	for (int i = 0; i < h; i++) 
		for (int j = 0; j < w; j++)
			cin >> MP[i][j], dis[i][j] = INF;
	bfs();
	cout << (dis[x2][y2] == INF ? -1 : dis[x2][y2]);
}

Measured memory_bytes: 11980
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<(n); ++i)
#define rep2(i, s, n) for(int i=s; i<(n); ++i)
#define ALL(v) (v).begin(), (v).end()

using namespace std;

typedef long long ll;

static const int INTINF = (2147483647 >> 1); // 10^9 + 5000
static const ll LLINF = (9223372036854775807 >> 1);
static const int MAX = 1e5+1;
static const ll MOD = 1e9+7;

namespace Kunitaka{
    template<
        typename TYPE,
        std::size_t SIZE
    >
    std::size_t array_length(const TYPE (&array)[SIZE])
    {
        return SIZE;
    }

    template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
    template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
}
using namespace Kunitaka;
namespace Printer{
    void br(){
        cout << endl;
    }

    void loop_cnt(int i){
        cout << "i = " << i << endl;
    }

    void loop_cnt(int i, int j){
        cout << "i = " << i << ", " << "j = " << j << endl;
    }

    template<class T>
    void print(T x){
        cout << x << endl;
    }

    template<class T, class S>
    void print(T x, S y){
        cout << x << "," << y << endl;
    }

    template<class T, class S, class U>
    void print(T x, S y, U z){
        cout << x << "," << y << "," << z << endl;
    }

    template<class T, class S>
    void print(pair<T, S> p){
        cout << p.first << ", " << p.second << endl;
    }

    template<
        typename TYPE,
        std::size_t SIZE
    >
    void print(const TYPE (&array)[SIZE]){
        int lim = array_length(array);
        for(int i=0; i<lim; i++){
            if(i) cout << " ";
            cout << array[i];
        }
        cout << endl;
    }

    template<class S>
    void print(vector<S> v){
        for(int i=0; i<v.size(); i++){
            if(i) cout << " ";
            cout<< v[i];
        }
        cout << endl;
    }

    template<class S>
    void print(vector<vector<S> > vv){
        for(int i=0; i<vv.size(); i++){
            for(int j=0; j<vv[i].size(); j++){
                if(j) cout << " ";
                cout << vv[i][j];
            }
            cout << endl;
        }
    }

    void yesno(bool x){
        if(x) cout << "Yes" << endl;
        else cout << "No" << endl;
    }
};
using namespace Printer;

int main(int argc, const char * argv[]) {
    //提出時、消す----//
    //--------------//


    // input
    cout << fixed << setprecision(10);
    ll K; cin >> K;
    ll N; cin >> N;
    vector<ll> v(N), s(N+1), sa(N+1);
    rep(i, N){
        cin >> v[i];
        s[i+1] = s[i] + v[i];
    }

    v.insert(v.begin(), -(K - v[N-1]));


    ll ans = LLINF;
    rep(i, N){
        ans = min(ans, K - (v[i+1] - v[i]));
    }
    
    print(ans);
    
    
    return 0;
}


Measured memory_bytes: 7936
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n; cin>> n;
  vector<int> d(n);
  for(int i=0; i<n; i++){
    cin>>d[i];
  }
  sort(d.begin(),d.end(), greater<int>());
  int d_now,count;
  count = 1; d_now=d[0];
  for(int i=0; i<n; ++i){
    if( d_now != d[i] ){
      count++; d_now = d[i];
    }
  }
  cout << count << endl;
  return 0;
}

Measured memory_bytes: 256
<?php
fscanf(STDIN, '%d', $n);
fscanf(STDIN, '%s', $s);
$str = []; $a = 'A';
for($i = 0; $i < 26; $i++) {
    $str[] = $a;
    $a++;
}
$ans = [];
for($j = 0; $j < strlen($s); $j++) {
    $key = array_search($s[$j], $str) + $n;
    $key = ($key >= 26) ? $key - 26 : $key;
    $ans[] = $str[$key];
}
echo implode('', $ans), PHP_EOL;

Measured memory_bytes: 4728
h,w=map(int, input().split())
m=[input() for _ in range(h)] 
#m = Input.split()
from collections import deque
cnt_black = 0
for y in range(h):
    for x in range(w):
        if(m[y][x]=='#'):
            cnt_black += 1
cnt_white =h*w-cnt_black

sy,sx = 0,0
#q: 次に訪れる予定の座標
q = deque([(sy,sx)])
#print(q)

#カウンタ
cnt = [[-1]*w for _ in range(h)]
cnt[sy][sx]=0
while q:
    cy,cx = q.popleft() #popleftで幅、popで深さ
    for dy,dx in ([1,0],[-1,0],[0,1],[0,-1]):
        ny, nx = cy + dy, cx + dx
        if(0<=ny<h and 0<=nx<w and cnt[ny][nx]==-1 and m[ny][nx]!='#'):
            #print(cy,cx,ny,nx)
            cnt[ny][nx] = cnt[cy][cx]+1
            q.append((ny,nx))
            #print(q)
            #pprint(cnt)
if(cnt[h-1][w-1]==-1):
    ans = -1
else:
    ans = cnt_white-1-cnt[h-1][w-1]
print(ans)

Measured memory_bytes: 40560
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <memory.h>
#include <math.h>
#include <assert.h>
#include <queue>
#include <map>
#include <set>
#include <string>
#include <algorithm>
#include <iostream>
#include <functional>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <bitset>

using namespace std;
typedef long long ll;
#define Fi first
#define Se second
#define pb(x) push_back(x)
#define sz(x) ((int)(x).size())
#define rep(i, n) for(int i=0;i<n;i++)
#define all(x) (x).begin(), (x).end()
typedef tuple<int, int, int> t3;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef long double ldouble;
typedef pair<double, double> pdd;

vector <pii> E[410];
int p[410];
int Find(int x){return p[x] == x ? x : p[x] = Find(p[x]); }
int dead[410];
int al[410];
int chk[410];
int chke[100010];

int can[410];
int dead2[410][410], al2[410][410];

void solve() {
	int n, m; scanf("%d%d", &n, &m);
	for(int i=1;i<=n;i++)p[i] = i;
	rep(i, m){
		int x, y; scanf("%d%d", &x, &y);
		E[x].pb(pii(i+1, y));
		E[y].pb(pii(i+1, x));
		p[Find(x)] = Find(y);
	}
	int ans = 0;
	int cnt = 0;
	map <int, int> M;
	for(int i=1;i<=n;i++){
		for(int j=1;j<=n;j++) dead[j] = m + 10;
		for(int j=1;j<=n;j++) al[j] = 0;
		for(int j=1;j<=n;j++) chk[j] = 0;
		for(int j=1;j<=m;j++) chke[j] = 0;
		al[i] = m + 10;
		priority_queue <pii> pq; pq.push(pii(al[i], i));
		int ok = 1;
		while(!pq.empty()){
			pii t = pq.top(); pq.pop();
			if(chk[t.Se]) continue;
			chk[t.Se] = 1;
			for(pii e : E[t.Se]) {
				if(chke[e.Fi]) continue;
				chke[e.Fi] = 1;
				if(e.Fi > t.Fi){
					dead[e.Se] = min(dead[e.Se], e.Fi);
					if(dead[e.Se] < al[e.Se]) ok = 0;
				}
				else {
					if(dead[e.Se] < e.Fi || al[e.Se] > e.Fi) ok = 0;
					else dead[e.Se] = al[e.Se] = e.Fi, pq.push(pii(al[e.Se], e.Se));
				}
			}
		}
		if(al[i] < m + 10) ok = 0;
		if(ok) {
			for(int j=1;j<=n;j++) dead2[i][j] = dead[j];
			for(int j=1;j<=n;j++) al2[i][j] = al[j];
			can[i] = 1;
			M[Find(i)]++;
			++cnt;
		}
	}
	for(int i=1;i<=n;i++) if(can[i]) for(int j=1;j<i;j++) if(can[j] && Find(i) == Find(j)) {
		int ok = 1;
		for(int k=1;k<=n;k++) if(min(dead2[i][k], dead2[j][k]) < max(al2[i][k], al2[j][k])){
			ok = 0;
	//		if(i == 4 && j == 1) printf("%d %d %d %d %d\n", k, dead2[i][k], dead2[j][k], al2[i][k], al2[j][k]);
		}
		if(ok) ans++;
	}
	int C = cnt * cnt;
	for(auto e : M) C -= e.Se * e.Se;
	printf("%d\n", ans + C / 2);
}

int main(){
	int Tc = 1; //scanf("%d\n", &Tc);
	for(int tc=1;tc<=Tc;tc++){
		solve();
	}
	return 0;
};

Measured memory_bytes: 3456
#include <iostream>

using namespace std;

int main()
{
    int x;
    cin >> x;
    int res = 0,d =0;
    if ( x>= 500)  {d= (x/500);res += d*1000; x = x - (d*500);}
    if ( x >=5)    res += (x/5)*5;
    cout << res;
    return 0;
}


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

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
//const ll mod = 1000000007;
string Replace(string S, char a) {
    string T = "";
    for(int i = 0; i < S.size(); i++) {
        if(S.substr(i, 3) == "ABC") {
            T.push_back(a);
            i += 2;
        } else {
            T.push_back(S[i]);
        }
    }
    return T;
}

string expand(string S, char a) {
    string T;
    for(int i = 0; i < S.size(); i++) {
        if(S[i] == a) T += "ABC";
        else T.push_back(S[i]);
    }
    return T;
}

bool can(string S) {
    if(S == "ABC") return true;
    if(S[0] != 'A') return false;
    if(S.back() != 'C') return false;
    for(int i = 0; i < S.size(); i++) {
        //if(S.substr(i, 2) == "BB") return false;
        //if(S.substr(i, 2) == "AC") return false;
    }
    for(char a = 'A'; a <= 'C'; a++) {
        string T = Replace(S, a);
        if(T.size() == S.size()) continue;
        if(expand(T, a) != S) continue;
        if(can(T)) return true;
    }
    return false;
}

int main() {
    //cout.precision(10);
    string S;
    cin >> S;
    if(can(S)) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 22856
n=int(input())
ret=[2,3,4] if n>=6 else [2,5,63] if n==3 else [2,5,20,63] if n==4 else [2,5,20,30,63]
if n>=6:
    def getnext(a):
        if a%6==0:
            return a+2
        elif a%6==2:
            return a+1
        elif a%6==3:
            return a+1
        elif a%6==4:
            return a+2
    while len(ret)<n:
        ret.append(getnext(ret[-1]))
    if sum(ret)%6==5:
        ret[-1]=getnext(ret[-1])
    elif sum(ret)%6!=0:
        ret.remove((sum(ret)%6)+6)
        ret.append(getnext(ret[-1]))
        while sum(ret)%6!=0:
            ret[-1]=getnext(ret[-1])
print(" ".join(map(str,ret)))

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

const int mod = 1000000007;
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
  mint operator+(const mint a) const { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const { return pow(mod-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}

int main(void){
    int n, k;
    cin >> n >> k;
    vector<int> s, t;
    vector<int> a(n);
    
    rep(i, n){
        cin >> a[i];
        if (a[i]<0)  t.push_back(a[i]);
        else s.push_back(a[i]);
    }
    int S = s.size();
    int T = t.size();
    //正にできるか
    bool ok = false;
    if (S>0){
        if (n==k) ok=(T%2==0);
        else ok=true;
    }else{
        ok = (k%2==0);
    }
    
    mint ans = 1;
    if (!ok){
        sort(a.begin(), a.end(), [](int x, int y){
            return abs(x) < abs(y);
        });
        rep(i, k) ans *= a[i];
    }else{
        sort(s.begin(), s.end());
        sort(t.rbegin(), t.rend());
        if (k%2==1){
            ans *= s.back();
            s.pop_back();
        }
        vector<ll> p;
        while (s.size()>= 2){
            ll x = s.back(); s.pop_back();
            x *= s.back(); s.pop_back();
            p.push_back(x);
        }
        while (t.size()>= 2){
            ll x = t.back(); t.pop_back();
            x *= t.back(); t.pop_back();
            p.push_back(x);
        }
        sort(p.rbegin(), p.rend());
        rep(i, k/2) ans *= p[i];
    }
    cout << ans << endl;
    
    return 0;
}


Measured memory_bytes: 6344
#include <stdio.h>
#include <vector>
#include<iostream>
#include<queue>
#include<map>
#include<algorithm>
using namespace std;

int main() {

 int n;
 vector< int > arr;
 vector < pair < int , int > > vct;
 map < int , int > mp;
 map < int , int > :: iterator it;
 scanf ("%d" , &n);
 arr.resize(n);

 for ( int i = 0 ; i < n ; ++i){
	  scanf ("%d" , &arr[i]);
	  mp [arr[i]]++;
   }

 for ( it = mp.begin() ; it != mp.end() ; ++it)
	   vct.push_back ( make_pair ( it->first, it -> second ));

 reverse ( vct.begin() , vct.end());

   int t = 0 ;
   long long ans1 = 0 , ans2 = 0;
   while ( t < vct.size()  ){
	   if ( vct[t].second >= 2){
		   vct[t].second -= 2;
		   ans1 = vct[t].first;
		   break;
	   }
	   t++;
   }

   for ( int i = t ; i < vct.size() ; ++i)
	   if ( vct[i].second >= 2){
		   ans2 = vct[i].first;
		   break;
	   }

   printf ("%lld\n" , ans1 * ans2);

  return 0;
}


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

using namespace std;

template<int MOD>
struct Modular {
  int value;
  Modular(const Modular& k) : value(k.value) {}
 
  template<typename V>
  Modular(const V& v) : value(v % MOD) {
    if (value < 0) {
      value += MOD;
    }
  }
  
  Modular() : Modular(0) {}
 
  Modular& operator+=(Modular const& b) { value += b.value; if (value >= MOD) value -= MOD; return *this; } 
  Modular& operator-=(Modular const& b) { value -= b.value; if (value < 0) value += MOD; return *this; }
  Modular& operator*=(Modular const& b) { value = (long long)value * b.value % MOD; return *this; }
  Modular& operator++() { return *this += 1; }
  Modular& operator--() { return *this -= 1; }
  Modular operator++(int) { return *this += 1; }
  Modular operator--(int) { return *this -= 1; }

  friend Modular inverse(Modular a) { return mexp(a, MOD - 2); }
  Modular& operator/=(Modular const& b) { return *this *= inverse(b); }
  friend Modular operator+(Modular a, Modular const b) { return a += b; }
  friend Modular operator-(Modular a, Modular const b) { return a -= b; }
  friend Modular operator-(Modular const a) { return 0 - a; }
  friend Modular operator*(Modular a, Modular const b) { return a *= b; }
  friend Modular operator/(Modular a, Modular const b) { return a /= b; }
  friend std::ostream& operator<<(std::ostream& os, Modular const& a) { return os << a.value; }
  friend bool operator==(Modular const& a, Modular const& b) { return a.value == b.value; }
  friend bool operator!=(Modular const& a, Modular const& b) { return a.value != b.value; }
};
 
template <int T, typename V>
Modular<T> mexp(Modular<T> a, V e) {
  if (a == 0) return e == 0 ? 1 : 0; 
  Modular<T> res = 1; 
  while (e) { 
    if (e & 1) 
      res *= a; 
    a *= a; 
    e >>= 1; 
  }
  return res;
}

using Mint = Modular<1'000'000'007>;

void Run() {
  int k;
  string s;
  cin >> k >> s;
  int len = s.size() + k;
  vector<Mint> fact(len + 1);
  vector<Mint> pw(len + 1);
  fact[0] = pw[0] = 1;
  for (int i = 1; i <= len; ++i)
    pw[i] = 25 * pw[i - 1];
  for (int i = 1; i <= len; ++i)
    fact[i] = i * fact[i - 1];
  auto&& Bino = [&](int a, int b) {
    return fact[a] / (fact[b] * fact[a - b]);
  };
  Mint res = 0;
  for (int i = s.size(); i <= len; ++i)
    res += pw[len - i] * Bino(len, i);
  cout << res << '\n';
}

int main() {
  srand(time(0));
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  Run();
  return 0;
}

Measured memory_bytes: 20008
let make_list f t step =
  let rec make_list_inner c t lst =
    if c >= t then lst else make_list_inner (c+step) t (c::lst)
  in
  List.rev (make_list_inner f t [])

let swap lst a b =
  let xa = Array.get lst (a-1) in
  let xb = Array.get lst (b-1) in
  lst.(a-1) <- xb;
  lst.(b-1) <- xa;
  lst
    
let () =
  let rec read lst =
    try let lst = (Scanf.scanf "%d,%d\n" (swap lst)) in
        read lst
    with End_of_file ->
         Array.iter (fun i -> (Printf.printf "%d\n" i)) lst
  in
  let w = int_of_string (read_line()) in
  let _ = int_of_string (read_line()) in
  read (Array.of_list (make_list 1 (w+1) 1))
;;




make_list 1 10 1;;

Measured memory_bytes: 2308
#include<bits/stdc++.h>
#define fi first
#define se second
#define rep(i, n) for(int (i) = 0; (i) < (n); (i)++)
#define rrep(i, n) for (int (i) = 1; (i) <= (n); (i++))
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define pb push_back
#define eb emplace_back
#define yn {puts("Yes");}else {puts("No");}
#define printd(x) printf("%.12f\n", x);
template<class T> bool chmin(T& a, const T& b) {if (a > b) {a = b; return 1;} return 0;}
template<class T> bool chmax(T& a, const T& b) {if (a < b) {a = b; return 1;} return 0;}
using namespace std;
using ll = long long;

int main() {
	int s, w;
	cin >> s >> w;

	cout << (w >= s  ? "unsafe":"safe") << endl;

	return 0;
}


Measured memory_bytes: 3636
N = gets.chomp.to_i
A = gets.chomp.split(' ').map(&:to_i)

count = 0
que = []
que << A
while !que.empty?
  a = que.shift

  newa = []
  a.each do |ai|
    if ai % 2 == 0
      newa << ai / 2
    else
      break
    end
  end

  if newa.length == N
    que << newa
    count += 1
  end
end

print count

Measured memory_bytes: 1788
n = int(input())
s = input()
"""
def lcs(s, t):
    ls, lt = len(s), len(t)
    dp = [[0] * (lt+1) for _ in range(ls+1)]
    for i in range(ls):
        for j in range(lt):
            #prev = dp[i+1][j+1]
            if s[i] == t[j]:
                dp[i+1][j+1] = max(dp[i+1][j+1], dp[i][j] + 1)
            dp[i+1][j+1] = max(dp[i+1][j+1], dp[i+1][j])
            dp[i+1][j+1] = max(dp[i+1][j+1], dp[i][j+1])
    return dp[ls][lt]
"""
def z_algorithm(s):
    ls = len(s)
    Z = [0] * ls
    Z[0] = ls
    i, j = 1, 0
    while i < ls:
        while i + j < ls and s[j] == s[i+j]:
            j += 1
        Z[i] = j
        if j == 0:
            i += 1
            continue
        k = 1
        while i + k < ls and k + Z[k] < j:
            Z[i + k] = Z[k]
            k += 1
        i += k
        j -= k
    return Z

ans = 0
for i in range(n):
    #print(s[i:])
    z = z_algorithm(s[i:])
    for j, zj in enumerate(z):
        if j+1 > zj:
            ans = max(ans, zj)
    #print(z)
print(ans)

Measured memory_bytes: 49756
import numpy as np
a1,b1 = list(map(int, input().split()))
a2,b2 = list(map(int, input().split()))
a3,b3 = list(map(int, input().split()))

a = [a1,a2,a3]
b = [b1,b2,b3]

from collections import Counter

c = Counter(a+b)

x = 0
y = 0
for k in c.keys():
    if c[k] == 1:
        x += 1

if x != 2:
    print('NO')
else:
    print('YES')

Measured memory_bytes: 21768
#include<iostream>
#include<string>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<list>
#include<cstdint>
#include<bits/stdc++.h>
#include<queue>
#include<set>

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rep_r(i, n) for(int i = n-1; i >= 0; i--)
#define rep1(i, n) for(int i = 1; i <= (int)(n); i++)
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
#define SZ(x) ((ll)(x).size())
#define bit(n) (1LL<<(n))
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

#define INF bit(60)
#define pb push_back
#define mod 1000000007

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

using namespace std;
using uif=uint_fast64_t;
using ll=long long int;

int qp(int a,ll b){int ans=1;do{if(b&1)ans=1ll*ans*a%mod;a=1ll*a*a%mod;}while(b>>=1);return ans;}
int qp(int a,ll b,int mo){int ans=1;do{if(b&1)ans=1ll*ans*a%mo;a=1ll*a*a%mo;}while(b>>=1);return ans;}

int gcd(int a,int b){return b?gcd(b,a%b):a;}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};


#define FACSIZE 2002

ll invfac[FACSIZE];
ll fac[FACSIZE];

ll mod_pow(ll ,ll );
ll mod_add(ll ,ll );
ll mod_mul(ll ,ll );
ll mod_div(ll ,ll );
void make_fact(ll );
void make_invfact(ll );



int main(void){

  string s,t;
  cin>>s>>t;

  map<char, vector<ll> > m;

  for(ll i=0;i<s.size();i++){
    char c=s[i];
    m[c].push_back(i+1);
  }

  ll ans=0;

  ll prev=0;

  for(auto c:t){
    if( m.find(c) == end(m) ){
      cout << -1 << endl;
      return 0;
    }
    else{

      auto itr=upper_bound( begin(m[c]),end(m[c]),prev );
      //cout << *itr << endl;
      if( itr == end( m[c] ) ){
        ans+= s.size() - prev + m[c][0];
        prev = m[c][0];
      }
      else{
        ans+= *itr - prev;
        prev = *itr;
      }
      
    }
    //cout << ans << endl;
  }

  //ll ans=t.size() * s.size();

  

  cout << ans << endl;

  return 0;

}

ll mod_pow(ll x,ll r){
  if(r==0) return 1;
  else if(r==1) return x%mod;
  else if(r%2==0){
    ll t=mod_pow(x,r/2)%mod;
    return t*t %mod;
  } 
  else{
    ll t=mod_pow(x,r/2)%mod;
    ll k= t*t %mod;
    return k*x%mod;
  } 
}
ll mod_add(ll a,ll b){
  return (a+b)%mod;
}

ll mod_mul(ll a,ll b){
  return (a*b)%mod;
}

ll mod_div(ll a,ll b){
  return mod_mul(a,mod_pow(b,mod-2));
}

void make_fact(ll n){
  fac[0]=1;
  rep(i,n){
    fac[i+1]=mod_mul(fac[i],i+1);
  }  
}

void make_invfact(ll n){
  invfac[n]= mod_pow( fac[n] ,mod-2);
  for(int i=n-1;i>=0;i--){
    invfac[i]=mod_mul(invfac[i+1],i+1);
  }

}

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

int main () {
  int n;
  cin>>n;
  
  int a[n+1];
  for (int i=0;i<n;i++) {
    cin>>a[i];
  }
  int sum=0;
  for (int i=0;i<n-2;i++) {
    if (a[i]<a[i+1] && a[i+1]<a[i+2] ) {
      sum++;
    }
    else if (a[i]>a[i+1] && a[i+1]>a[i+2] ) {
      sum++;
    }
  }
  cout<<sum<<endl;
  
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(ll i=0;i<(n);i++)
#define rrep(i,n) for(ll i = 1; i <= (n); ++i)
#define drep(i,n) for(ll i = (n)-1; i >= 0; --i)
#define all(v) v.begin(),v.end()
#define len(x) (ll)(x).length()
#define maxs(x,y) x = max(x,y)
#define mins(x,y) x = min(x,y)
#define pb push_back
#define sz(x) (ll)(x).size()
#define v(T) vector<T>
#define vv(T) vector<vector<T>>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
ll gcd(ll a,ll b){if(a%b==0){return b;}else{return(gcd(b,a%b));}}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
const int INF=1e9;
const ll MX = 1e18;
const ll MOD=INF+7;
const int di[] = {-1,0,1,0};
const int dj[] = {0,-1,0,1};
const double PI=acos(-1);
#define dame { puts("-1"); return 0;}
#define yn {puts("Yes");}else{puts("No");}
#define YN {puts("YES");}else{puts("NO");}
const ll MAX = 1000001;
long long fac[MAX], finv[MAX], inv[MAX];
void COMinit() {fac[0] = fac[1] = 1;finv[0] = finv[1] = 1;inv[1] = 1;for (ll i = 2; i < MAX; i++){fac[i] = fac[i - 1] * i % MOD;inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;finv[i] = finv[i - 1] * inv[i] % MOD;}}
long long COM(ll n, ll k){if (n < k) return 0;if (n < 0 || k < 0) return 0;return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;}
ll llpow(ll n,ll i){ll cnt=n;  for(ll j=0;j<i-1;j++){n*=cnt;}return n;}

int main() {
  int n;
  cin>>n;
  vi V(n),c(n);
  rep(i,n) cin>>V[i];
  rep(i,n) cin>>c[i];
  int ans=0;
  rep(i,n){
    if(V[i]>c[i]){
      ans+=V[i]-c[i];
    }
  }
  cout<<ans<<endl;
}


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

int main(){
  int n, m;
  cin >> n >> m;
  ll a[n], b[n], c[m], d[m], ans[n], p[n];
  rep(i,n) p[i] = INF;
  rep(i,n) cin >> a[i] >> b[i];
  rep(i,m) cin >> c[i] >> d[i];
  rep(i,n) {
    for(int j = m-1; j >= 0; j--) {
      if(abs(a[i]-c[j])+abs(b[i]-d[j]) <= p[i]) {
        p[i] = abs(a[i]-c[j])+abs(b[i]-d[j]);
        ans[i] = j+1;
      }
    }
  }
  for(auto k : ans) cout << k << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < n; i++)
#define repp(i, m, n) for(int i = m; i < n; i++)
#define reps(i, n) for(int i = 1; i <= n; i++)
const int    INF = 100000000;
const double EPS = 1e-10;
const int    MOD = 1000000007;
using namespace std;
typedef long long ll;
typedef pair<int, int> pai;
typedef pair<ll,ll> pal;



int main()
{
	int n, m, k;
	cin >> n >> m >> k;
	int a[1010][1010];
	rep(i, n+1) rep(j, m+1)
	{
		a[i][j]=i*(m-j)+j*(n-i);
	}
	int muri=0;
	rep(i, n+1) rep(j, m+1)
	{
		if(a[i][j]==k) muri=1;
	}
	if(muri==0) cout << "No" << endl;
	else cout << "Yes" << endl;
	return 0;
}

Measured memory_bytes: 4224
#include<stdio.h>

void dfs(int, int *);

int n, m, x;
int A[10000][10000];
int minPrice = -1;

int main()
{
  scanf("%d %d %d", &n, &m, &x);
  for (int i = 0; i < n; i++) {
    for (int j = 0; j <= m; j++) { // 0番目の要素はC(値段)なので、(m + 1)回
      scanf("%d", &A[i][j]);
    }
  }
  int sums[m + 1];
  for (int i = 0; i <= m; i++) {
    sums[i] = 0;
  }
  dfs(0, sums);
  printf("%d\n", minPrice);
  return 0;
}

void dfs(int i, int *sums) {
  // 全てのアルゴリズムの理解度がX以上になっているか判定する
  int satisfied = 1;
  for (int j = 1; j <= m; j++) { // 0番目はCであることとm番目に値が入っていることに注意
    if (sums[j] < x) {
      satisfied = 0;
      break;
    }
  }
  
  if (satisfied == 1) {
    if (minPrice == -1) {
      // 初めて満たした
      minPrice = sums[0];
    } else if (sums[0] < minPrice) {
      // 小さくなる場合のみ更新
      minPrice = sums[0];
    }
  }
  
  if (i > n) {
    // 末尾まで調べ終わっている
    return;
  }
  
  // i番目を使用しない場合について調べる
  dfs(i + 1, sums);
  if (satisfied == 1) {
    // 既に満たしている場合、i番目を使用する場合については調べない
    return;
  }
  
  // i番目を使用する場合について調べる
  int sumsCpy[m + 1];
  for (int j = 0; j <= m; j++) {
    sumsCpy[j] = sums[j] + A[i][j];
  }
  dfs(i + 1, sumsCpy);
}

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

int N, K;
int a[5010];
bool dp[5010][5010];

bool judge(int x) {
    rep(i, N) rep(j, K) dp[i][j] = false;
    dp[0][0] = true;
    rep(i, N-1) {
        int v = a[i+(i>=x ? 1:0)];
        rep(j, K) {
            dp[i+1][j] |= dp[i][j];
            if (j+v<K) dp[i+1][j+v] |= dp[i][j];
        }
    }
    for (int i=max(0ll, K-a[x]); i<K; i++) if (dp[N-1][i]) return false;
    return true;
}

signed main() {
    cin.tie(0); ios::sync_with_stdio(false);
    cin >> N >> K;
    rep(i, N) cin >> a[i];
    sort(a, a+N);
    int l = 0, r = N-1;
    while (l<=r) {
        int m = (l+r)/2;
        if (judge(m)) l = m+1;
        else r = m-1;
    }
    cout << r+1 << endl;
}

Measured memory_bytes: 28140
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <fstream>
#include <climits>
#include <cmath>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <map>
#include <functional>
#include <set>
#include <numeric>
#include <stack>
#include <utility>
#include <time.h>
#include <iterator>
#include <random>
//#include "util.h"

using namespace std;
typedef unsigned uint;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<bool> vbool;
typedef vector<string> vstr;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

//呪文
template <typename _KTy, typename _Ty> ostream& operator << (ostream& ostr, const pair<_KTy, _Ty>& m) { cout << "{" << m.first << ", " << m.second << "}"; return ostr; }
template <typename _KTy, typename _Ty> ostream& operator << (ostream& ostr, const map<_KTy, _Ty>& m) { if (m.empty()) { cout << "{ }"; return ostr; } cout << "{" << *m.begin(); for (auto itr = ++m.begin(); itr != m.end(); itr++) { cout << ", " << *itr; } cout << "}"; return ostr; }
template <typename _Ty> ostream& operator << (ostream& ostr, const vector<_Ty>& v) { if (v.empty()) { cout << "{ }"; return ostr; }	cout << "{" << v.front(); for (auto itr = ++v.begin(); itr != v.end(); itr++) { cout << ", " << *itr; }	cout << "}"; return ostr; }
template <typename _Ty> ostream& operator << (ostream& ostr, const set<_Ty>& s) { if (s.empty()) { cout << "{ }"; return ostr; } cout << "{" << *(s.begin()); for (auto itr = ++s.begin(); itr != s.end(); itr++) { cout << ", " << *itr; }	cout << "}"; return ostr; }
template <typename _KTy, typename _Ty> istream& operator >> (istream& istr, pair<_KTy, _Ty>& m) { cin >> m.first >> m.second; return istr; }
template <typename _Ty> istream& operator >> (istream& istr, vector<_Ty>& v) { for (size_t i = 0; i < v.size(); i++) cin >> v[i]; return istr; }
ll modpow(ll n, ll p, ll m) { ll result = 1; while (p > 0) { if (p & 1) result = (result * n) % m; p >>= 1; n = (n * n) % m; } return result; }
template <typename _Ty> _Ty ipow(_Ty x, _Ty n) { _Ty ret = _Ty(1); for (_Ty i = _Ty(0); i < n; i++) ret *= x; return ret; }
#define PI 3.14159265358979323846
#define EPS 1e-8
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define all(x) (x).begin(), (x).end()
#define fake false

int GCD(int m, int n)
{
	int k;
	do {
		k = m % n;
		m = n; n = k;
	} while (k != 0);
	return m;
}

int main()
{
	//clock_t start, end;
	//start = clock();

	int x, y;
	cin >> x >> y;
	cout << GCD(x, y) << endl;

	//end = clock();
	//printf("%d msec.\n", end - start);

	return 0;
}



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

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

Measured memory_bytes: 3588
#include<iostream>
using namespace std;
int main(void){
   int E,Y;
   cin >> E;
   cin >> Y;
   if(E==0){
       if(1868 <= Y && Y <= 1911)           cout << "M" << Y-1868+1 << endl;
       else if(1912 <= Y && Y <= 1925)      cout << "T" << Y-1912+1 << endl;
       else if(1926 <= Y && Y <= 1988)      cout << "S" << Y-1926+1 << endl;
       else if(1989 <= Y && Y <= 2016)      cout << "H" << Y-1989+1 << endl;
       else                                 cout << endl;                      
   }
   
   else if(E==1){
       if(1 <= Y && Y <= 44)                cout << Y+1868-1 << endl;     
       else                                 cout << endl;
   }
   
   else if(E==2){
       if(1 <= Y && Y <= 14)                cout << Y+1912-1 << endl;     
       else                                 cout << endl;
   }
   
   else if(E==3){
       if(1 <= Y && Y <= 63)                cout << Y+1926-1 << endl;     
       else                                 cout << endl;
   }
   
   else if(E==4){
       if(1 <= Y && Y <= 28)                cout << Y+1989-1 << endl;     
       else                                 cout << endl;
   }
   
   else                                     cout << endl;
   
}


Measured memory_bytes: 3088
require 'set'

### global variables

$node = [Rational(0), Set.new(['x']), 'x']

### subroutines

def asym?(tr0, tr1)
  sim0, set0, sk0, tr00, tr01 = tr0
  sim1, set1, sk1, tr10, tr11 = tr1

  # 1
  return sim1 <=> sim0 if sim0 != sim1

  # 2
  return 0 if tr00.nil? && tr01.nil? && tr10.nil? && tr11.nil?

  if asym?(tr00, tr01) >= 0
    tr0s = tr00
    tr0w = tr01
  else
    tr0s = tr01
    tr0w = tr00
  end

  if asym?(tr10, tr11) >= 0
    tr1s = tr10
    tr1w = tr11
  else
    tr1s = tr11
    tr1w = tr10
  end

  # 3
  cmp_s = asym?(tr0s, tr1s)
  return cmp_s if cmp_s != 0

  # 4
  cmp_w = asym?(tr0w, tr1w)
  return cmp_w if cmp_w != 0

  # 5
  0
end

# <tree> := 'x' | '(' <tree> ' ' <tree> ')'

def parse_tree(str)
  if str[$pos] == 'x'
    $pos += 1
    return $node
  end

  $pos += 1
  tr0 = parse_tree(str)
  $pos += 1
  tr1 = parse_tree(str)
  $pos += 1

  set0 = tr0[1]
  set1 = tr1[1]

  set_c = set0 & set1
  set_u = set0 | set1
  sim = Rational(set_c.length, set_u.length)

  cmp = asym?(tr0, tr1)
  if cmp < 0
    tmp = tr0; tr0 = tr1; tr1 = tmp
  end

  sk = [tr0[2], tr1[2]]
  [sim, set_u | [sk], sk, tr0, tr1]
end

def arrange_tree(tr, rev = false)
  return 'x' if tr == $node

  trl = tr[3]
  trr = tr[4]

  if rev
    tmp = trl; trl = trr; trr = tmp
  end

  atrl = arrange_tree(trl, false)
  atrr = arrange_tree(trr, true)

  "(#{atrl} #{atrr})"
end

### main

loop do
  str = gets.strip
  break if str == '0'

  $pos = 0
  tr = parse_tree(str)
  #p tr[2]
  puts arrange_tree(tr)
end

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

int N;
vector<int> d;
vector<vector<pair<int,int>>> h;
vector<int> color;

void dfs(int u) {
  int v;
  for (pair<int, int> e : h.at(u)) {
    v = e.first;
    if (d.at(v) >= 0)
      continue;

    d.at(v) = d.at(u) + e.second;
    color.at(v) = d.at(v) % 2 == 0 ? 0 : 1;
    dfs(v);
  }
}

int main() {
  cin >> N;
  int u, v, w;
  d = vector<int>(N + 1);
  h = vector<vector<pair<int, int>>>(N + 1);
  color = vector<int>(N + 1);
  for (int i = 0; i < N + 1; i++)
    d.at(i) = -1;
  for (int i = 0; i < N - 1; i++) {
    cin >> u >> v >> w;
    h.at(u).push_back(make_pair(v, w));
    h.at(v).push_back(make_pair(u, w));
  }
  d.at(1) = 0;
  color.at(1) = 0;
  dfs(1);
  for (int i = 1; i < N + 1; i++)
    cout << color.at(i) << endl;
}


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

#define pb         push_back

typedef long long ll;
const ll INF = 1000000000000000000ll;
const ll MOD = 1000000007ll;
const double EPS = 1e-8;

int adj[100][100];
int main(void) {
	//ios_base::sync_with_stdio(false);
	//cin.tie(0);
	
	int n, m;
	cin >> n >> m;

	for(int i=0; i<m; i++){
		int a, b;
		cin >> a >> b;
		a--;
		b--;
		adj[a][b]++; 
		adj[b][a]++; 
	}
	
	for(int i=0; i<n; i++){
		int cnt = 0;
		for(int j=0; j<n; j++){
			cnt += adj[i][j];
		}
		cout << cnt << endl;
	}
	
	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

main() {
  int  x, y;
  while (1) {
    scanf("%d %d", &x, &y);
    if ( x == 0 && y == 0 ) break; 
    if ( x < y ) {
      printf("%d %d\n", x, y);
    } else {
      printf("%d %d\n", y, x);
    }

  }
   
  return 0;
}

Measured memory_bytes: 600
#include<bits/stdc++.h>
#define tmp(x) std::cout<<"& "<<(x)<<" &\n"
#define rep(i,a,b) for(int i=(a);i<=(b);++i)
#define per(i,a,b) for(int i=(a);i>=(b);--i)
typedef long long ll;

using namespace std;
const int maxn=3e5+100;
int n,t;
int h,w,m;
vector<int> hh[maxn];
vector<int> ww[maxn];
set<pair<int,int> >s;
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin>>h>>w>>m;
   int xx=0,yy=0;
    rep(i,1,m){
        int x,y;
        cin>>x>>y;
        hh[x].push_back(y);
        ww[y].push_back(x);
        xx=max(xx,(int)hh[x].size());
        yy=max(yy,(int)ww[y].size());
        s.insert(make_pair(x,y));
    }
    vector<int> ax,ay;
    rep(i,1,h)if(hh[i].size()==xx)ax.push_back(i);
    rep(i,1,w)if(ww[i].size()==yy)ay.push_back(i);
    int ans=xx+yy-1;
    rep(i,0,ax.size()-1){
    	rep(j,0,ay.size()-1){
    		if(!s.count(make_pair(ax[i],ay[j]))){
    			cout<<ans+1;return 0;
			}
		}
	}
    cout<<ans;



    return 0;
}


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

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


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const long double PI = (acos(-1));
#define rep(i, x, n) for (int i = x; i < (int)(n); i++)
#define sc(x) scanf("%d",&x)
#define scll(x) scanf("%lld",&x)
int main(){
    int k, s, ans = 0; sc(k), sc(s);
    vector<int> v(k+1);
    rep(i, 0, k+1) v[i] = i;
    rep(i, 0, k+1){
        if (s < i) break;
        rep(j, 0, k+1){
            if (s < i+j) break;
            if (i+j+k < s) continue;
            ans += 1;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3724