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

#define REP(i,n) for(int i=0;i<(n);i++)
#define REAP(i,a,n) for(int i=(a);i<(n);i++)
#define YES cout<<"Yes"<<endl
#define NO cout<<"No"<<endl
#define fr first
#define sc second
#define pb push_back
#define All(v) v.begin(),v.end()
typedef long long ll;

int tmp[200001];

int main(){
    int n,k;
    cin >> n >> k;
    int a,cou=0;
    REP(i,n){
        cin >> a;
        if(tmp[a]==0)cou++;
        tmp[a]++;
    }
    int res=0;
    sort(tmp,tmp+200001);
    for(int i=0;i<200001;i++){
        if(tmp[i]==0)continue;
        if(cou<=k)break;
        res+=tmp[i];
        cou--;
    }
    cout << res << endl;
}


Measured memory_bytes: 1024
#include <stdio.h>

int main(void)
{
    int num[] = {0, 1, 3, 1, 2, 1, 2, 1, 1, 2, 1, 2, 1};
    int x, y;
    scanf("%d%d", &x, &y);

    if (num[x] == num[y]) printf("Yes");
    else printf ("No");

    return (0);
}


Measured memory_bytes: 128
class lheapq():
    # 最小値を取り出す優先度付きキュー
    def __init__(self, p):
        self.l = []
        if p:
            for sp in p:
                self.heappush(sp)

    def heappush(self, a):
        n = len(self.l)
        self.l.append(a)
        t = n
        while t != 0:
            if self.l[t][1] < self.l[(t-1)//2][1]:
                self.l[t], self.l[(t-1)//2] = self.l[(t-1)//2], self.l[t]
                t = (t-1)//2
            else:
                break

    def heappop(self):
        n = len(self.l)
        if n == 0:
            return (-1, 0)
        if n == 1:
            return self.l.pop()
        ret = self.l[0]
        self.l[0] = self.l.pop()
        n -= 1
        t = 0
        while t < n:
            child1 = t*2+1
            child2 = t*2+2
            if child1 >= n:
                break
            elif child2 >= n:
                if self.l[t][1] > self.l[child1][1]:
                    self.l[t], self.l[child1] = self.l[child1], self.l[t]
                    t = child1
                else:
                    break
            else:
                if self.l[child2][1] < self.l[child1][1]:
                    child1, child2 = child2, child1
                if self.l[t][1] > self.l[child1][1]:
                    self.l[t], self.l[child1] = self.l[child1], self.l[t]
                    t = child1
                elif self.l[t][1] > self.l[child2][1]:
                    self.l[t], self.l[child2] = self.l[child2], self.l[t]
                    t = child2
                else:
                    break
        return ret

    def isnotblank(self):
        if self.l:
            return True
        else:
            return False


def dijkstra(s, N, e):
    INF = "INF"
    res = [INF for _ in range(N)]
    q = lheapq([(s, 0)])
    while q.isnotblank():
        while q.isnotblank():
            des, dis = q.heappop()
            if res[des] == INF:
                res[des] = dis
                break
        for se in e[des]:
            if res[se[0]] == INF:
                q.heappush((se[0], se[1]+res[des]))
    return res


N, M, S = map(int, input().split())
g = [[] for _ in range(N)]
for j in range(M):
    a, b, c = map(int, input().split())
    g[a].append((b, c))
print("\n".join(map(str, dijkstra(S, N, g))))



Measured memory_bytes: 97956
#!/usr/bin/env python3
N = int(input())
A = list(map(int, input().split()))

mod = 10 ** 9 + 7

s = sum(A)** 2

a = 0
for i in A:
    a += (i ** 2)

ans = (s - a) // 2
ans = ans % mod

print(ans)


Measured memory_bytes: 31636
import copy

n = int(input())
lis = list(map(int, input().split()))
list = copy.deepcopy(lis)
true_list = [ i+1 for i in range(n)]
k = 0

for i in range(n):
    for j in range(n):
        if k == 0:
            list = copy.deepcopy(lis)
            list[i], list[j] = list[j], list[i]
            if list == true_list:
                print("YES")
                k = 1


if k == 0:
    print("NO")

Measured memory_bytes: 3444
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define ALL(v) v.begin(), v.end()
#define downque(que)  priority_queue<ll> que;
#define upque(que) priority_queue<ll, vector<int>, greater<int>> que;
typedef long long ll;
const int MOD = 1e9+7;


int main(){
 int n; cin>>n;
 bool res=true;
 int t[n+1]; t[0]=0;
 int x[n+1]; x[0]=0;
 int y[n+1]; y[0]=0;
 
 FOR(i,1,n+1)cin>>t[i]>>x[i]>>y[i];
 REP(i,n){
     int sa=abs(x[i+1]-x[i])+abs(y[i+1]-y[i]);
     if(t[i+1]-t[i]<sa)res=false;
     else if((t[i+1]-t[i])%2!=sa%2)res=false;

 }
 cout<<(res?"Yes": "No")<<endl;
}

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

using namespace std;

long long a,b,c,d,n,m,i,j,t[200005];
string s,q;

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

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <utility>
#include <functional>
#include <climits>
#include <cstring>

using namespace std;

#define int long long
#define rep(i, n) for (int i=0;i<(int)n;++i)
#define rep1(i, n) for (int i=1;i<=(int)n;++i)
#define unless(a) if(!(a))
#define all(a) begin(a),end(a)
#define fst first
#define scd second
#define PB emplace_back
#define PPB pop_back

using vi=vector<int>;
using pii=pair<int, int>;

bool chmin(int&a,int b){return a>b?(a=b,true):false;}
bool chmax(int&a,int b){return a<b?(a=b,true):false;}
int read(){int a;scanf("%lld",&a);return a;}

int K;

signed main()
{
	string S;
	cin >> S >> K;

	int N = S.length();
	int idx = -1;
	for (int i = 0; i < N; ++i ) {
		if (S[i] - '0' != 1) {
			idx = i;
			break;
		}
	}

	if (idx == -1 or idx > K - 1) {
		cout << 1 << endl;
	} else {
		cout << S[idx] << endl;
	}
}


Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#define MAX_N 1000000
#include <iostream>
#include <sstream>
#include <cmath>
#include <algorithm>
#include <queue>
#include <stack>
#include <limits>
#include <map>
#include <string>
#include <cstring>
#include <set>
#include <deque>
#include <bitset>

using namespace std;

typedef long long ll;
typedef pair<int,int> P;

static const double eps = 1e-8;

int gStage[6000][5];

void putBlock(int dir,int len,int pos){
	if(dir == 1){
		for(int i=6000-1;i>=0;i--){
			bool isok=true;
			for(int j=pos;j<pos+len;j++){
				if(gStage[i][j]==1) isok=false;
			}
			
			if(!isok){
				for(int j=pos;j<pos+len;j++){
					gStage[i+1][j] = 1;
				}
				return;
			}

			else if(isok && i==0){
				for(int j=pos;j<pos+len;j++){
					gStage[i][j] = 1;
				}
				return;
			}
		}
	}
	else{
		for(int i=6000-1;i>=0;i--){
			bool isok=true;
			if(gStage[i][pos]==1) isok=false;

			if(!isok){
				for(int j=i+1;j<i+1+len;j++){
					gStage[j][pos] = 1;
				}
				return;
			}

			else if(isok && i==0){
				for(int j=i;j<i+len;j++){
					gStage[j][pos] = 1;
				}
				return;
			}
		}
	}
}

int countBlock(){
	int res=0;
	for(int i=0;i<6000;i++){
		for(int j=0;j<5;j++){
			res += gStage[i][j];
		}
	}

	return res;
}

void eraseBlock(){
	for(int i=0;i<6000;i++){
		bool isok=true;
		for(int j=0;j<5;j++){
			if(gStage[i][j]==0) isok = false;
		}

		if(isok){
			for(int j=i;j+1<6000;j++){
				for(int k=0;k<5;k++){
					gStage[j][k] = gStage[j+1][k];
				}
			}
			i--;
		}
	}
}

void printBlock(){
	for(int i=0;i<50;i++){
		for(int j=0;j<5;j++){
			printf("%d",gStage[i][j]);
		}
		printf("\n");
	}
	printf("\n");
}

int main(){
	int n;
	while(~scanf("%d",&n)){
		if(n==0) break;

		memset(gStage,0,sizeof(gStage));
		for(int i=0;i<n;i++){
			int dir,len,pos;
			scanf("%d %d %d",&dir,&len,&pos);
			pos-=1;
			putBlock(dir,len,pos);
			//printBlock();
			eraseBlock();
			//printBlock();
		}

		printf("%d\n",countBlock());
	}
}

Measured memory_bytes: 996
#include <stdio.h>
#include <stdbool.h>

int main(void)
{
	bool flag = true;
	int cnt = 0;
	int n;
	scanf("%d", &n);
	int x[n];
	for(int i = 0; i < n; i++){
		scanf("%d", &x[i]);
	}
	while(flag){
		flag = false;
		for(int i = n - 1; i >= 0; i--){
			if(x[i] < x[i - 1]){
				int temp = x[i];
				x[i] = x[i - 1];
				x[i - 1] = temp;
				cnt++;
				flag = true;
			}
		}
	}
	for(int i = 0; i < n - 1; i++){
		printf("%d ", x[i]);
	}
	printf("%d\n%d\n", x[n - 1], cnt);
	return 0;
}

Measured memory_bytes: 1028
x,y,a,b,c = map(int,input().split())
p = list(map(int,input().split()))
q = list(map(int,input().split()))
r = list(map(int,input().split()))
p.sort()
q.sort()
r.sort()
ans = p[a-x:]+q[b-y:]+r
ans.sort()
print(sum(ans[c:]))


Measured memory_bytes: 23328
#include<cstdio>
#include<iostream>
#include<cstring>
using namespace std;
int S[10001],key;
int N, M,count;
int search(){
	int i = 0;
	S[N] = key;
	while(S[i] != key) i++;
	return i != N;
}
int main(){
	scanf("%d",&N);
	for(int i = 0; i < N; i++){
		scanf("%d",&S[i]);
	}
	scanf("%d",&M);
	for(int j = 0; j < M; j++){
		scanf("%d",&key);
		if(search()) count++;
	}
	printf("%d\n", count);
	return 0;
}


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

#define For(i,x,y) for (int i=x;i<y;i++)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define lf else if

#define dprintf(...) fprintf(stderr,__VA_ARGS__)
using namespace std;

typedef long long ll;
typedef double db;
typedef pair<int,int> pii;
typedef vector<int> Vi;

int IN(){
	int c,f,x;
	while (!isdigit(c=getchar())&&c!='-');c=='-'?(f=1,x=0):(f=0,x=c-'0');
	while (isdigit(c=getchar())) x=(x<<1)+(x<<3)+c-'0';return !f?x:-x;
}

const int N=100+19;
const int p=998244353;

map<string,int> f;
char s[N];
int n;

string cal(string s,int l,int r){
	if (l>r) return "";
	return s.substr(l,r-l+1);
}
int F(string s){
	if (s=="") return 1;
	if (f.count(s)) return f[s];
	int &res=f[s];
	res=(s[0]-'0'+1)*F(cal(s,1,s.length()-1))%p;
	For(i,0,s.length()){
		int len=i+1;
		string g;
		For(j,0,len) g+='1';
		for (int w=i,_=1;w<s.length();w+=len,_++){
			For(u,0,len) if (s[w-len+u+1]=='0') g[u]='0';
			if (_>=2) res=(res+1ll*F(g)*F(cal(s,w+1,s.length()-1)))%p;
		}
	}
	return res;
}

int main(){
	scanf("%s",s);
	printf("%d\n",F(string(s)));
}

Measured memory_bytes: 6144
import java.util.Scanner;

class Main {
  public static void main(String[] args){
    int[] m = new int[110];
    input(m);
    printMode(m);
  }
  private static void input(int[] m){
    Scanner cin = new Scanner(System.in);
    while (cin.hasNext()){
      m[cin.nextInt()]++;
    }
  }

  private static void printMode(int[] m){
    int max = 0;
    for (int i = 1; i < 101; i++){
      max = Math.max(max, m[i]);
    }
    for (int i = 1; i < 101; i++){
      if (m[i] == max){
        System.out.println(i);
      }
    }
  }
}

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

int acgt_length(string s) {
  int length = 0;
  
  for (int i = 0; i < s.length(); i++) {
    switch (s.at(i)) {
      case 'A':
      case 'T':
      case 'C':
      case 'G':
        length++;
        break;
        
      default:
        if (i == s.length() - 1) {
          return length;
        } else {
          string sub = s.substr(i + 1);
          return max(length, acgt_length(sub));
        }
        break;
    }
  }
  
  return length;
}

int main() {
  string S;
  cin >> S;
  
  int length = acgt_length(S);
  cout << length << endl;
}

Measured memory_bytes: 256
N, Y = map(int,input().split())
count = 0
for i in range(N+1):
  for j in range(N-i+1):
    ans = 10000*i + 5000*j + 1000*(N-i-j)
    if ans == Y:
      print(str(i) + " " + str(j) + " " + str(N-i-j))
      count +=1
      exit()
      
if count == 0:
  print("-1 -1 -1")

Measured memory_bytes: 3064
n,m=map(int,input().split())
ab=[list(map(int,input().split()))for i in range(n)]
ab=sorted(ab,key=lambda x:x[0])
cnt=0
cost=0
for i in range(n):
  if (cnt+ab[i][1])>=m:
    cost+=ab[i][0]*(m-cnt)
    break
  cost+=ab[i][0]*ab[i][1]
  cnt+=ab[i][1]
print(cost)





Measured memory_bytes: 29792
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define vi vector<ll>
#define pb push_back
#define ff first
#define ss second
#define inf 2e18
#define ull unsigned long long
#define pi acos(-1.0)
#define mod 1000000007
#define lop0(n) for(ll i=0;i<n;i++)
#define lopj(n) for(ll j=0;j<n;j++)
#define lop1(n) for(ll i=1;i<=n;i++)
#define all(v) v.begin(),v.end()
ll Set(ll N,ll pos){ return N=N | (1LL<<pos); }
ll reset(ll N,ll pos){ return N= N & ~(1LL<<pos); }
bool check(ll N,ll pos){ return (bool)(N & (1LL<<pos)); }
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)

main()
{
    ll a,b,c,d;
    cin>>a>>b>>c>>d;
    ll ans=a*c;
    ans=max(a*d,ans);
    ans=max(b*c,ans);
    ans=max(b*d,ans);
    cout<<ans;


}


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

int main() {  
    long long N, M;
    while (cin >> N >> M) {
        if (!(N && M)) break;
        long long P[N + 1];
        for (long long i = 0; i < N; ++i) cin >> P[i];
        P[N] = 0;

        long long PP[(N + 1) * (N + 1)];
        for (int i = 0; i < N + 1; ++i) {
            for (int j = 0; j < N + 1; ++j) {
                PP[(N + 1) * i + j] = P[i] + P[j];
            }
        }
        sort(PP, PP + (N + 1) * (N + 1));

        long long ans = 0;
        for (int i = 0; i < (N + 1) * (N + 1); ++i) {
            int l = 0, r = (N + 1) * (N + 1);
            while (r - l >= 1) {
                int pnt = (r + l) / 2;
                if (PP[i] + PP[pnt] > M) r = pnt;
                else {
                    ans = max(ans, PP[i] + PP[pnt]);
                    l = pnt + 1;
                }
            }
        }

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


Measured memory_bytes: 10980
#include <bits/stdc++.h>
#define REP(i, n) for(long long i=0; i<n; i++)
#define REPR(i, n) for(long long i=n-1; i>=0; i--)
#define FOR(i, m, n) for(long long i=m; i<=n; i++)
#define FORR(i, m, n) for(long long i=m; i>=n; i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define VSORTR(v) sort(v.rbegin(), v.rend());
#define ALL(v) (v).begin(),(v).end()
#define FIN ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);

using namespace std;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<ll, ll>;
const ll mod = 1e9+7;
const ll inf = 1e15;

map<ll,ll> primes(ll n){
    map<ll, ll> r;
    for(ll i=2; i*i<=n; i++){ 
        while(n % i ==0){
            r[i]++;
            n /= i;
        }
    }

    if(n != 1) r[n] = 1;
    r[1]=0;
    return r;
}

int main(){FIN
    
  ll n,k=0;;cin>>n;
  ll i;
  map<ll,ll> v;
  v = primes(n);
  for( i=2;i*i<=n;i++){
  	//cout<<i<<" ";
  	if(n%i==0){
     	k=0;
     	while(n%i==0){
          n/=i;
		k++;
      	//cout<<i<<" "<<n<<"\n";
		}
	v[i]=k;
    }
  }
  //cout<<endl<<i<<endl;
  ll ans=0;
  for(auto i:v){
	  ll p=sqrt(1+8*i.second)-1;
	  p/=2;
	  ans+=p;
  }
  cout<<ans;
    return 0;
}

Measured memory_bytes: 3676
import java.util.ArrayList;
import java.util.Scanner;

public class Main 
{
	static Scanner scan = new Scanner(System.in);
	static int w;
	static int h;
	static int[][] hwall; //is there a h wall to the down of this tile?
	static int[][] vwall; //is there a v wall to the right of this tile?
	static int[][] mark;
	
	static class Tile
	{
		int x;
		int y;
		
		public Tile(int x, int y)
		{
			this.x = x;
			this.y = y;
		}
	}
	
	public static void main(String[] args) 
	{
		while(true)
		{
			w = scan.nextInt();
			h = scan.nextInt();
			
			if(w == 0)return;
			
			hwall = new int[w][h-1];
			vwall = new int[w-1][h];
			mark = new int[w][h];
			mark[0][0] = 1;
			
			for(int y = 0; y < h; y++)
			{
				for(int x = 0; x < w-1; x++)
				{
	//				System.out.println("VWALLS");
					vwall[x][y] = scan.nextInt();
				}
				
				if(y < h - 1)
				{
					for(int x = 0; x < w; x++)
					{
	//					System.out.println("HWALLS");
						hwall[x][y] = scan.nextInt();
					}
				}
			}
			
			ArrayList<Tile> list = new ArrayList<Tile>();
			
			list.add(new Tile(0,0));
			
			while(list.size() > 0)
			{
				Tile cur = list.get(0);
				int curm = mark[cur.x][cur.y];
				list.remove(cur);
				
				int lem;
				
	//			System.out.println("Walk " + cur.x + ", " + cur.y);
				
				if(cur.x < w-1 && vwall[cur.x][cur.y] == 0)
				{
					//mark right
					lem = mark[cur.x+1][cur.y];
					if(lem == 0 || lem > curm+1)
					{
						mark[cur.x+1][cur.y] = curm+1;
						list.add(new Tile(cur.x+1, cur.y));
					}
				}
				
				if(cur.x > 0 && vwall[cur.x-1][cur.y] == 0)
				{
					//mark left
					lem = mark[cur.x-1][cur.y];
					if(lem == 0 || lem > curm+1)
					{
						mark[cur.x-1][cur.y] = curm+1;
						list.add(new Tile(cur.x-1, cur.y));
					}
				}
				
				if(cur.y > 0 && hwall[cur.x][cur.y-1] == 0)
				{			
					//mark up
					lem = mark[cur.x][cur.y-1];
					if(lem == 0 || lem > curm+1)
					{
						mark[cur.x][cur.y-1] = curm+1;
						list.add(new Tile(cur.x, cur.y-1));
					}
				}
				
				if(cur.y < h-1 && hwall[cur.x][cur.y] == 0)
				{			
					//mark down
					lem = mark[cur.x][cur.y+1];
					if(lem == 0 || lem > curm+1)
					{
						mark[cur.x][cur.y+1] = curm+1;
						list.add(new Tile(cur.x, cur.y+1));
					}
				}
				
			}
			
			System.out.println(mark[w-1][h-1]);
		}
	}

}



Measured memory_bytes: 68468
K, N = list(map(lambda x: int(x) ,input().split(" ")))
l = list(map(lambda x:int(x), input().split(" ")))
sa = []
for i in range(len(l)-1):
  sa.append(l[i+1]-l[i])
sa.append(K+l[0]-l[N-1])

print(K-max(sa))

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

int main() {
 long long int X;
  cin >> X;
  
if (X >= 500){
 int sen = X / 500;
 int go = ( X - 500 * sen ) / 5;
 int answer = sen * 1000 + go * 5;
  cout << answer << endl;
}

 else{
 int go = X / 5;
   cout << go * 5 << endl;
 }
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cstring>
#include <fstream>
#include <random>
#include <cmath>
#include <iomanip>
#include <climits>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <map>
#include <deque>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <list>
#include <unordered_map>
#include <bitset>
#include <sstream>

typedef  long long ll;
#define mop 1000000007
using namespace std;

struct node{
    ll num; // 番号
    ll cnt; // カウンタ
    vector <ll> v; // 隣接リスト
};

ll ans[200001] = {};
node nodeList[200001];
bool nodeListJudge[200001];
void calc(node n){
    ans[n.num] = n.cnt;
    nodeListJudge[n.num] = true;
    for(ll i=0;i<n.v.size();i++){
        if(nodeListJudge[n.v[i]] == false){
            nodeList[n.v[i]].cnt += n.cnt;
            calc(nodeList[n.v[i]]);
        }
    }

}

int main() {
    
    for(ll i=0;i<=200000;i++){
        nodeList[i].num = i;
        nodeListJudge[i] = false;
    }

    ll n,q;
    cin >> n >> q;
    for(ll i=0;i<n-1;i++){
        ll a,b;
        cin >> a >> b;
        nodeList[a].v.push_back(b);
        nodeList[b].v.push_back(a);
    }
    for(ll i=0;i<q;i++){
        ll p,x;
        cin >> p >> x;
        nodeList[p].cnt += x;
    }
    calc(nodeList[1]);
    for(ll i=1;i<=n;i++){
        cout << ans[i] << " ";
    }
    cout << endl;
}

Measured memory_bytes: 46336
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repr(i, n) for (int i = (n); i >= 0; --i)
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define FORR(i, m, n) for (int i = (m); i >= (n); --i)
#define equals(a, b) (fabs((a) - (b)) < EPS)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
//const ll mod = 1000000007;
//const ll mod = 998244353;
const int inf = 1e9 + 10;
const ll INF = 1e18;
const ld EPS = 1e-10;
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
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; }



int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout << fixed << setprecision(25);

  int h, w, m;
  cin >> h >> w >> m;

  vector<pair<int, int>> x(h), y(w);
  set<pair<int, int>> s;
  rep(i, h) x[i] = {0, i};
  rep(i, w) y[i] = {0, i};
  rep(i, m) {
    int a, b;
    cin >> a >> b;
    a--, b--;
    x[a].first++;
    y[b].first++;
    s.insert({a, b});
  }
  sort(x.begin(), x.end(), greater<pair<int, int>>());
  sort(y.begin(), y.end(), greater<pair<int, int>>());
  int ans = x[0].first + y[0].first;
  vector<int> a, b;
  rep(i, h) {
    if (x[i].first != x[0].first) break;
    a.push_back(x[i].second);
  }
  rep(i, w) {
    if (y[i].first != y[0].first) break;
    b.push_back(y[i].second);
  }
  for (int i: a) {
    for (int j: b) {
      if (s.find({i, j}) == s.end()) {
        cout << ans << '\n';
        return 0;
      }
    }
  }
  ans--;
  cout << ans << '\n';

  
  return 0;
}

Measured memory_bytes: 25992
#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
#define INF         1e9
#define EPS         1e-9
#define REP(i,n)    for(lint i=0,i##_len=(n);i<i##_len;++i)
#define REP1(i,n)   for(lint i=1,i##_len=(n);i<=i##_len;++i)
#define REPR(i,n)   for(lint i=(n)-1;i>=0;--i)
#define REPR1(i,n)  for(lint i=(n);i>0;--i)
#define REPC(i,obj) for(auto i:obj)
#define R_UP(a,b)   (((a)+(b)-1)/(b))
#define ALL(obj)    (obj).begin(),(obj).end()
#define SETP        cout << fixed << setprecision(8)
using namespace std;
using lint = long long;
template<typename T = lint>inline T in() { T x; cin >> x; return x; }

signed main()
{
	int a = in(), b = in();
	cout << (a * b % 2 == 1 ? "Yes" : "No") << endl;
}

Measured memory_bytes: 256
#include <string>
#include <iostream>

using namespace std;

long long int dp[86];

int main() {
	int num;
	cin >> num;

	dp[0] = 2;
	dp[1] = 1;

	for (int i = 2; i < num+1; i++) {
		dp[i] = dp[i - 2] + dp[i - 1];
	}

	cout << dp[num] << endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
using ull = unsigned long long;
using P = pair<int, int>;
const int INF = 1e9;
const int dx[] = {-1,0,1,0};
const int dy[] = {0,-1,0,1};
#define PI 3.14159265358979323846264338327950L
#define MOD 1000000007
//setprecision(15)
int main() {
	string s; cin >> s;
	ll b = 0, ans = 0;
	for (int i = 0; i < s.length(); i++) {
		if (s[i] == 'B') b++;
		else ans += b;
	}
	cout << ans << endl;
}

Measured memory_bytes: 3752
#include <iostream>
const int NUM = 10000;
const int INF = 1 << 20;

using namespace std;

int main() {
    long long i, a[NUM];
    long long max = -INF, min = INF, sum = 0;
    cin >> i;
    i = 0;
    while (cin >> a[i]) {
        if (max < a[i]) max = a[i];
        if (min > a[i]) min = a[i];
        sum += a[i++];
    }
    cout << min << ' ' << max << ' ' << sum << endl;
    return 0;
}


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

// 総数を1000000007（素数）で割った余り
const long long mod = 1e9 + 7;

using ll = long long;
using pii  = pair<int, int>;
using pll = pair<ll, ll>;
#define ull unsigned long long
#define ld long double
#define vi vector<int>
#define vll vector<ll>
#define vc vector<char>
#define vs vector<string>
#define vpii vector<pii>
#define vpll vector<pll>

#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; i++)
#define rep1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; i++)
#define repr(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rep1r(i, n) for (int i = ((int)(n)); i >= 1; i--)

#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define RSORT(x) sort(rall(x));
#define pb push_back
#define mp make_pair

#define INF (1e9)
#define PI (acos(-1))
#define EPS (1e-7)

ull gcd(ull a, ull b) { return b ? gcd(b, a % b) : a; }
ull lcm(ull a, ull b) { return a / gcd(a, b) * b; }

int main(){
    int n, x;
    cin >> n >> x;
    vi l(n);
    rep(i, n) cin >> l[i];
    int ans = 1, d = 0;
    rep(i, n) {
        d += l[i];
        if (d <= x) ++ans;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <vector>
#include <math.h>
#include <set>
#include <map>
#include <string>
#include <stack>
#include <queue>
#include <iomanip>
#include <numeric>
#include <tuple>
#include <bitset>
#include <complex>
#include <unistd.h>
#define _USE_MATH_DEFINES
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> plglg;
typedef tuple<int, int, int> tiii;
typedef tuple<ll, ll, ll> tlglglg;
typedef complex<double> xy_t;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
double pi = 3.141592653589793;
ll mod = 1000000007;
int intmax = 2147483647;
int intmin = -2147483648;
ll llmax = 9223372036854775807;
ll llmin = -9223372036854775807;
ll inf = llmax / 2;
double eps = 1e-11;

struct edge {
    int to, cost;
};

int V;
vector<edge> G[1000000];
ll d[1000000];

void BFS01(int n) {
    fill(d, d + V, llmax);
    deque<int> que;
    d[n] = 0;
    que.push_front(n);
    while (que.size() > 0) {
        int base = que.front();
        que.pop_front();
        int s = G[base].size();
        for (int i = 0; i < s; i++) {
            edge e = G[base][i];
            if (e.cost == 1 && d[e.to] > d[base] + 1) {
                d[e.to] = d[base] + 1;
                que.push_back(e.to);
            } else if (e.cost == 0 && d[e.to] > d[base]) {
                d[e.to] = d[base];
                que.push_front(e.to);
            }
        }
    }
}

int main() {
    ll K;
    cin >> K;
    V = K;
    for (int i = 0; i < K; i++) {
        edge e;
        e.to = (i * 10) % K;
        e.cost = 0;
        G[i].push_back(e);
        edge e2;
        e2.to = (i + 1) % K;
        e2.cost = 1;
        G[i].push_back(e2);
    }
    BFS01(1);
    ll ans = d[0] + 1;
    cout << ans << endl;
}


Measured memory_bytes: 29440
//   Rishabh Agarwal
#include <bits/stdc++.h>
#define F first
#define S second
#define MAX 10000003
using namespace std;

typedef long long int ll;
const ll mod = 1e17;
long double PI=3.1415926;

ll power(ll a,ll b){
    if(b==0){
        return 1;
    }
    ll temp=power(a,b/2)%mod;
    if(b%2==0){
        return (temp*temp)%mod;
    }
    else{
        return ((a*temp)%mod*temp)%mod;
    }
}

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

//vector<ll>v;
//vector<ll>::iterator it;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll t;
    //cin>>t;
    t=1;
    //ll c=1;
    while(t--){
        ll n;
        cin>>n;
        ll a[n+1];
        for(ll x=0; x<=n; x++){
            cin>>a[x];
        }
        ll b[n+1];
        b[n]=a[n];
        for(ll x=n-1; x>=0; x--){
            b[x]=a[x]+b[x+1];
        }
        ll ans=0;
        ll c[n+1];
        //if(a[0]!=0){ans=-1;}
      //else{
       c[0]=1;
        ans+=c[0];
        for(ll x=1; x<=n; x++){
          c[x]=min(b[x],2*(c[x-1]-a[x-1]));
          ans+=c[x];
        }
      //}
      for(ll x=0; x<n+1; x++){
       if(c[x]<a[x]){
         ans=-1;
         break;
       }
      }
        cout<<ans<<"\n";
        //v.clear();
        //cout<<"Case #"<<c<<": "<<ans<<"\n";
        //c++;
    }
    return 0;
}


Measured memory_bytes: 5972
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define all(x) (x).begin(),(x).end()
template <class T> inline bool chmin(T &a, T b) {if (a > b){a = b;return true;}return false;}
template <class T> inline bool chmax(T &a, T b) {if (a < b){a = b;return true;}return false;}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;cin>>n;
    vector<int> t;
    vector<int> a;
    rep(i,n){
        int tt;cin>>tt;
        t.emplace_back(tt);
        a.emplace_back(tt);
    }
    sort(t.rbegin(), t.rend());
    rep(i, n){
        int ans;
        if(a[i]==t[0]){
            cout<<t[1]<<endl;
        }else{
            cout<<t[0]<<endl;
        }
    }
}

Measured memory_bytes: 3436
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
#define rep(i,n) for (ll i=0;i<n;++i)
#define rep2(i,a,b) for (ll i=a;i<b;++i)
const ll MOD=1000000007;
const ll INF=1e9;
const ll IINF=1e18;
const double EPS=1e-8;
const double pi=acos(-1);

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

struct UnionFind {
    private:
    vector<ll> par,rank;
    vector<ll> Size;
    public:
    UnionFind(ll n){
        par.resize(n);
        rank.resize(n,0);
        Size.resize(n,1);
        rep(i,n){
            par[i]=i;
        }
    }
    ll root(ll x){
        if (par[x]==x){
            return x;
        }
        return par[x]=root(par[x]);
    }
    bool merge(ll x, ll y){
        x=root(x);
        y=root(y);
        if (x==y){
            return false;
        }
        if (rank[x]<rank[y]){
            swap(x,y);
        }
        if (rank[x]==rank[y]){
            ++rank[x];
        }
        par[y]=x;
        Size[x]+=Size[y];
        return true;
    }
    bool same(ll x, ll y){
        return root(x)==root(y);
    }
    ll size(ll x){
        return Size[root(x)];
    }
};

const ll MAX=110000;

int main(){
    ll N;
    cin >> N;
    UnionFind uf(2*MAX);
    rep(i,N){
        ll x,y;
        cin >> x >> y;
        uf.merge(x,y+MAX);
    }
    map<ll,ll> mx,my;
    rep(i,MAX){
        mx[uf.root(i)]++;
    }
    rep2(i,MAX,2*MAX){
        my[uf.root(i)]++;
    }
    ll ans=0;
    rep(i,2*MAX){
        ans+=mx[i]*my[i];
    }
    cout << ans-N << endl;
}

Measured memory_bytes: 32896
#include <stdio.h>
#include <limits.h>
int main(void)
{
    long int N, h, n, w;
    scanf("%ld", &N);
    
        for(h=1;h<=3500;h++){
            for(n=1;n<=3500;n++){
                if((4*h*n-N*n-N*h)!=0){
                    if((n*h*N)/(4*h*n-N*n-N*h)>0 &&
                       (n*h*N)%(4*h*n-N*n-N*h)==0){
                        w=(n*h*N/(4*h*n-N*n-N*h));
                        if(4*h*n*w==N*n*w+N*h*w+N*h*n){
                            printf("%ld %ld %ld\n", h, n, w);
                            return 0;
                        }
                    }
                }
            }
        }

        return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#define all(vec) vec.begin(), vec.end()
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
constexpr ll INF = (1LL << 30) - 1LL;
constexpr ll LINF = (1LL << 60) - 1LL;
constexpr double eps = 1e-9;
constexpr ll MOD = 1000000007LL;
template <typename T> bool chmin(T &a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
};
template <typename T> bool chmax(T &a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
};
template <typename T> ostream &operator<<(ostream &os, vector<T> v) {
    for (int i = 0; i < v.size(); i++) {
        os << v[i] << (i + 1 == v.size() ? "\n" : " ");
    }
    return os;
}
template <typename T> vector<T> make_v(size_t a) { return vector<T>(a); }
template <typename T, typename... Ts> auto make_v(size_t a, Ts... ts) {
    return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}
template <typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type fill_v(T &t, const V &v) {
    t = v;
}
template <typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type fill_v(T &t, const V &v) {
    for (auto &e : t) {
        fill_v(e, v);
    }
};
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    double s = 0;
    for (int i = 0; i < n; i++) {
        double a;
        cin >> a;
        s += 1.0 / a;
    }
    cout << fixed << setprecision(10) << 1.0 / s << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fst first
#define snd second
#define rep(n) for(lint I = 0; (I) < (lint)(n); ++(I))
#define repeat(i, n) for(lint i = 0; (i) < (lint)(n); ++(i))
#define repeat_to(i, n) for(lint i = 0; (i) <= (lint)(n); ++(i))
#define repeat_from(i, m, n) for(lint i = (m); (i) < (lint)(n); ++(i))
#define repeat_from_to(i, m, n) for(lint i = (m); (i) <= (lint)(n); ++(i))
#define repeat_reverse_from_to(i, m, n) for(lint i = (m); (i) >= (lint)(n); --(i))
#define el cout<<endl
#define dump(x) cout<<" "<<#x<<"="<<x
#define pdump(p) cout<<" "<<#p<<"=("<<p.fst<<","<<p.snd<<")"
#define vdump(v) for(size_t I=0; I<v.size(); ++I){cout<<" "<<#v<<"["<<I<<"]="<<v[I];} cout<<endl
using namespace std; using lint = long long; using ld = long double;
using pii = pair<int, int>; using pll = pair<lint, lint>;

int main(void) {
    int n;
    cin >> n;
    vector<int> a(n);
    repeat (i, n) cin >> a[i];
    sort(a.begin(), a.end());
    
    int sum = 0;
    repeat (i, n-1) sum += a[i];
    if (sum > a[n-1]) cout << "Yes" << endl;
    else cout << "No" << endl;
}

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

using namespace std;

int main(int argc, char *argv[]) {
	int N;
	cin >> N;

	int answer = 0;
	int max_div_by_2 = INT_MIN;
	for (int i = 1; i <= N; i++) {
		int k = 0;
		for (int j = i;;) {
			if (j % 2 == 0) {
				k++;
			} else {
				break;
			}
			j = j / 2;
		}
		if (max_div_by_2 <= k) {
			max_div_by_2 = k;
			answer = i;
		}
	}

	cout << answer << endl;
	
	return 0;
}


Measured memory_bytes: 256
listNK = list(map(int,input().split()))
S = list(input())

if S[listNK[1]-1]=="A":
    S[listNK[1]-1] = "a"
if S[listNK[1]-1]=="B":
    S[listNK[1]-1] = "b"
if S[listNK[1]-1]=="C":
    S[listNK[1]-1] = "c"

output = ""
for i in range(listNK[0]):
    output = output + S[i]

print(output)

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

struct UnionFind{
  Int n;
  vector<Int> r,p;
  UnionFind(){}
  UnionFind(Int sz):n(sz),r(sz,1),p(sz,0){iota(p.begin(),p.end(),0);}
  Int find(Int x){
    return (x==p[x]?x:p[x]=find(p[x]));
  }
  bool same(Int x,Int y){
    return find(x)==find(y);
  }
  void unite(Int x,Int y){
    x=find(x);y=find(y);
    if(x==y) return;
    if(r[x]<r[y]) swap(x,y);
    r[x]+=r[y];
    p[y]=x;
  }
};

//INSERT ABOVE HERE
signed main(){
  Int n,m,k;
  cin>>n>>m>>k;
  vector<Int> c(n);
  for(Int i=0;i<n;i++) cin>>c[i];
  using T = tuple<Int, Int, Int>;
  vector<T> v;
  for(Int i=0;i<m;i++){
    Int a,b,w;
    cin>>a>>b>>w;
    a--;b--;
    v.emplace_back(w,a,b);
  }
  sort(v.begin(),v.end());

  Int ans=0,cnt=1;
  UnionFind uf(n+k);
  for(Int i=0;i<n;i++){
    c[i]--;
    if(~c[i]) uf.unite(i,n+c[i]);
    else cnt++;
  }
  
  priority_queue<Int> pq;
  for(Int i=0;i<m;i++){
    Int w,a,b;
    tie(w,a,b)=v[i];
    if(uf.same(a,b)) continue;
    ans+=w;
    uf.unite(a,b);
    pq.emplace(w);
  }
  
  for(Int i=0;i<n+k;i++)
    if(uf.find(i)==i) cnt--;
  
  while(cnt>0){
    ans-=pq.top();pq.pop();
    cnt--;
  }
  if(cnt<0) ans=-1;
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 8560
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define endl '\n'
#define INF INT_MAX
vector<ll> dp;

ll f(vector<ll> &v,ll n)
{
    if(n==0)
    {
        return 0;
    }

    if(n<0)
    {
        return INF;
    }

    if(dp[n]!=-1)
    {
        return dp[n];
    }

    ll val1,val2,left,right;
    left=f(v,n-1);
    right=f(v,n-2);
    val1=abs(v[n]-v[n-1]);
    val2=abs(v[n]-v[n-2]);

    if(left==INF&&right==INF)
    {
        return INF;
    }

    if(left==INF)
    {
        return dp[n]=right+val2;
    }

    if(right==INF)
    {
        return dp[n]=left+val1;
    }

    return dp[n]=min(left+val1,right+val2);
}

void solve()
{
    ll n,i,ans;
    cin>>n;
    dp.resize(n,-1);
    vector<ll> v(n);

    for(i=0;i<n;i++)
    {
        cin>>v[i];
    }

    ans=f(v,n-1);
    cout<<ans;
}

int main()
{
    solve();
}


Measured memory_bytes: 9528
#include<cstdio>
#include<map>
using namespace std;
typedef long long ll;
const int N=410;
int n,c[N][8];
ll state(int a,int b,int c,int d){
	ll ans=0;
	ans=ans*1000+a;
	ans=ans*1000+b;
	ans=ans*1000+c;
	ans=ans*1000+d;
	return ans;
}
map<ll,int> M;ll ans;
void add(int a,int b,int c,int d,int v){
	M[state(a,b,c,d)]+=v;
	M[state(b,c,d,a)]+=v;
	M[state(c,d,a,b)]+=v;
	M[state(d,a,b,c)]+=v;
}
int main()
{
	scanf("%d",&n);
	for (int i=1;i<=n;i++){
		for (int j=0;j<4;j++)
			scanf("%d",&c[i][j]),c[i][j+4]=c[i][j];
		add(c[i][0],c[i][1],c[i][2],c[i][3],1);
	}
	//标号最小的正方形作为正面
	for (int i=1;i<=n;i++){
		add(c[i][0],c[i][1],c[i][2],c[i][3],-1);
		for (int j=i+1;j<=n;j++){
			add(c[j][0],c[j][1],c[j][2],c[j][3],-1);
			for (int *C=c[j];C<c[j]+4;C++){//枚举反面和旋转后的方向
				ll S0=state(c[i][1],c[i][0],C[1],C[0]);
				ll S1=state(c[i][0],c[i][3],C[2],C[1]);
				ll S2=state(c[i][3],c[i][2],C[3],C[2]);
				ll S3=state(c[i][2],c[i][1],C[0],C[3]);
				if (!M.count(S0)||!M.count(S1)||!M.count(S2)||!M.count(S3)) continue;
				ll calc=1;
				calc*=M[S0];
				add(c[i][1],c[i][0],C[1],C[0],-1);
				calc*=M[S1];
				add(c[i][0],c[i][3],C[2],C[1],-1);
				calc*=M[S2];
				add(c[i][3],c[i][2],C[3],C[2],-1);
				calc*=M[S3];
				add(c[i][3],c[i][2],C[3],C[2],1);
				add(c[i][0],c[i][3],C[2],C[1],1);
				add(c[i][1],c[i][0],C[1],C[0],1);
				ans+=calc;
			}
			add(c[j][0],c[j][1],c[j][2],c[j][3],1);
		}
	}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 384
N = int(input())
S = [list(input().split()) for _ in range(N)]
s = input()

ans = 0
flag = False
for song in S:
    title = song[0]
    leng = song[1]
    if flag:
        ans += int(leng)
    if title == s:
        flag = True
print(ans)


Measured memory_bytes: 38256
//#include <bits/stdc++.h>
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
//#include "boost/multiprecision/cpp_int.hpp"
//typedef boost::multiprecision::cpp_int LL;
typedef long double dd;
#define i_7 (ll)(1E9+7)
//#define i_7 998244353
#define i_5 i_7-2

ll mod(ll a){
    ll c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
typedef pair<ll,ll> l_l;
typedef pair<dd,dd> d_d;
ll inf=(ll)1E16;
#define rep(i,l,r) for(ll i=l;i<=r;i++)
#define pb push_back
ll max(ll a,ll b){if(a<b)return b;else return a;}
ll min(ll a,ll b){if(a>b)return b;else return a;}
void Max(ll &pos,ll val){pos=max(pos,val);}//Max(dp[n],dp[n-1]);
void Min(ll &pos,ll val){pos=min(pos,val);}
void Add(ll &pos,ll val){pos=mod(pos+val);}
dd EPS=1E-9;
#define fastio ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define fi first
#define se second
#define endl "\n"
#define SORT(v) sort(v.begin(),v.end())
#define ERASE(v) v.erase(unique(v.begin(),v.end()),v.end())
#define POSL(v,x) (lower_bound(v.begin(),v.end(),x)-v.begin())
#define POSU(v,x) (upper_bound(v.begin(),v.end(),x)-v.begin())
//template<class T>void max(T a,T b){if(a<b)return b;else return a;}
//template<class T>void min(T a,T b){if(a>b)return b;else return a;}
//template<class T>bool Max(T&a, T b){if(a < b){a = b;return 1;}return 0;}
//template<class T>bool Min(T&a, T b){if(a > b){a = b;return 1;}return 0;}

//////////////////////////

int main(){fastio
    ll n,m;cin>>n>>m;
    bool e[n][n];memset(e,false,sizeof(e));
    rep(i,1,m){
        ll a,b;cin>>a>>b;a--;b--;
        e[a][b]=true;
        e[b][a]=true;
    }
    ll a[n];rep(i,0,n-1)a[i]=i;
    ll ans=0;
    do{
        if(a[0]!=0)continue;
        bool f=true;
        rep(i,0,n-2){
            if(!e[a[i]][a[i+1]])f=false;
        }
        
        if(f)ans++;
    }while(next_permutation(a,a+n));
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
from numpy import *
from scipy import *
from sys import *


n, m = map(int, input().split())

d = [list() for i in range(n+1)]

for i in range(m):
    p, y = map(int, input().split())
    d[p].append((y, i))

for i in range(1, n+1):
    d[i].sort()

res = list()
for i in range(1, n+1):
    for j, x in enumerate(d[i]):
        y, id = x
        res.append((id, '{0:06d}{1:06d}'.format(i, j+1)))

res.sort()
for x in res:
    print(x[1])


Measured memory_bytes: 53276
#include<stdio.h>
#include<stdlib.h>
#include<iostream>
#include<string>
#include<vector>
#include<math.h>
#include<queue>


#define CI cin >>
#define CO cout <<
#define E << endl;
#define F(i,max) (for(int i = 0;i < max;++i))

using namespace std;


const int INF = 100000;
int H;
int W;
int N;
int sx;
int sy;
vector<vector<char>> map;

char temp;

typedef pair<int, int> P;

int factory_x[9];
int factory_y[9];
int size_ = 0;

int dx[4] = { -1, 0, 1, 0 };
int dy[4] = { 0, -1, 0, 1 };

void input() {
	CI H >> W >> N;

	map.resize(H);		
	for (int i = 0; i < H; i++) {
		map[i].resize(W);
	}


	for (int i = 0; i < H; ++i) {
		for (int j = 0; j < W; ++j) {
			CI temp;
			if (temp == 'S') {
				sx = j;
				sy = i;
			}
			else {
				if ((int)(temp) - '0' >= 1 && (int)(temp) - '0' <= 9) {
					factory_x[(int)temp - '0' - 1] = j;
					factory_y[(int)temp - '0' - 1] = i;
					if ((int)temp - '0' > size_) {
						size_ = (int)temp - '0';
					}
				}
			}
			map[i][j] = temp;
		}
	}
}

int bfs() {
	queue<P> que;
	
	int n = 0;
	int distance = 0;
	vector<vector<int>> d(H);
	for (int i = 0; i < H; ++i) {
		d[i].resize(W);
	}

	for (int i = 0; i < H; ++i) {
		for (int j = 0; j < W; ++j) {
			d[i][j] = INF;
		}
	}
	que.push(P(sx, sy));
	d[sy][sx] = 0;
	

	while (!que.empty()) {
		P p;
		p = que.front();
		que.pop();

		if (p.first == factory_x[n] && p.second == factory_y[n]) {
			sx = factory_x[n];
			sy = factory_y[n];

			
			distance += d[p.second][p.first];
			
			
			if (n == size_ - 1) {
				break;
			}
			n++;

			for (int i = 0; i < H; ++i) {
				for (int j = 0; j < W; ++j) {
					d[i][j] = INF;
				}
			}
			d[sy][sx] = 0;
			while (que.size() > 0) {
				que.pop();
			}
			que.push(P(sx, sy));
			
			
			continue;
		}

		for (int i = 0; i < 4; ++i) {
			int nx = p.first + dx[i];
			int ny = p.second + dy[i];

			if (0 <= nx && nx < W && 0 <= ny && ny < H && map[ny][nx] != 'X' && d[ny][nx] == INF) {
				que.push(P(nx, ny));
				d[ny][nx] = d[p.second][p.first] + 1;
			}
		}

	}

	return distance;
}

int main(void) {
	input();

	

	CO bfs() E

	return 0;
}

Measured memory_bytes: 7732
#include <cstdio>

int main()
{
    int a,b,c,d;
    scanf("%d %d %d %d", &a, &b, &c, &d);
    if (a + b > c + d)
    {
        printf("Left");
    }
    
    else if (a + b < c + d)
    {
        printf("Right");
    }
    
    else if (a + b == c + d)
    {
        printf("Balanced");
    }
}

Measured memory_bytes: 1704
#pragma region Macros
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define rep2(i, a, b) for(ll i = a; i <= b; ++i)
#define rep(i, n) for(i = 0; i < n; ++i)
#define rep3(i, a, b) for(ll i = a; i >= b; --i)
using namespace std;

// _________コーディングはここから！！___________

int n, m, k, i;
constexpr int N = 200010;
int a[N], b[N];
constexpr int sz = 5000000;
char reader[sz];
char *pos = reader;
int nn;
int kk;
main() {
    reader[fread(reader, sizeof(char), sizeof(char) * sz, stdin)];
    while('0' <= *pos and *pos <= '9') n = n * 10 + *pos++ - '0';
    pos++;
    while('0' <= *pos and *pos <= '9') m = m * 10 + *pos++ - '0';
    pos++;
    while('0' <= *pos and *pos <= '9') k = k * 10 + *pos++ - '0';
    nn = n;
    pos++;
    rep(i, n) {
        while('0' <= *pos and *pos <= '9') a[i + 1] = a[i + 1] * 10 + *pos++ - '0';
        pos++;
        a[i + 1] += a[i];
        if(a[i + 1] > k) {
            nn = i;
            ++i;
            for(; i < n; ++i) {
                while('0' <= *pos and *pos <= '9') pos++;
                pos++;
            }
            break;
        }
    }
    while(*pos and *pos <= 32) pos++;
    rep(i, m) {
        while('0' <= *pos and *pos <= '9') b[i + 1] = b[i + 1] * 10 + *pos++ - '0';
        pos++;
        b[i + 1] += b[i];
        if(b[i + 1] > k) {
            m = i;
            break;
        }
    }
    int now = nn;
    int ans = now;
    for(i = 1; i <= m; i++) {
        kk = k - b[i];
        while(a[now] > kk) now--;
        ans = max(ans, i + now);
    }
    pos = reader;
    i = 0;
    do {
        *pos++ = ans % 10 + '0';
        ans /= 10;
        i++;
    } while(ans);
    reverse(reader, reader + i);
    fwrite(reader, sizeof(char), sizeof(char) * i, stdout);
}


Measured memory_bytes: 7940
while True:
    try:
        A = sorted(list(map(int, input().split(","))))
        _sum = 0
        _max = 0
        for i in range(1,14):
            tmp = A.count(i)
            if tmp > 1:
                _sum+=tmp
            _max = max(_max, tmp)
        if _max == 4:
            print("four card")
        elif _max == 3 and _sum == 5:
            print("full house")
        elif A.count(1) == 1 and (A[0] == 1 and A[2]-1 == A[3]-2 == A[4]-3 == A[1]) \
            or (A[4] == 1 and A[1]-1 == A[2]-2 == A[3] == A[0]):
            print("straight")
        elif A[1]-1 == A[2]-2 == A[3]-3 == A[4]-4 == A[0]:
            print("straight")
        elif _max == 3:
            print("three card")
        elif _sum == 4:
            print("two pair")
        elif _max == 2:
            print("one pair")
        else:
            print("null")
    except:
        break


Measured memory_bytes: 5604
#include <bits/stdc++.h>
using namespace std;
int main() {
	int N;
	queue<int> A[1010];
	cin >> N;
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < N-1; j++) {
			int a;
			cin >> a;
			a--;
			A[i].push(a);
		}
	}
	int ans = 0;
	queue<int> ne;
	for (int i = 0; i < N; i++) {
		ne.push(i);
	}
	while (1) {
		bool flag = 1;
		set<int> s;
		int l = ne.size();
		for (int i = 0; i < l; i++) {
			int k = ne.front(); ne.pop();
			if (A[k].size() && (s.find(k) == s.end())) {
				flag = 0;
				int p = A[k].front();
				if (A[p].front() == k && (s.find(p) == s.end())) {
					A[k].pop();
					A[p].pop();
					s.insert(k);
					s.insert(p);
					ne.push(k);
					ne.push(p);
				}
			}
		}
		if (flag) break;
		if (s.empty()) {
			puts("-1");
			return 0;
		}
		ans++;
	}
	cout << ans << endl;
}

Measured memory_bytes: 4736
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep2(i, x, n) for(int i = x; i <= n; i++)
#define rep3(i, x, n) for(int i = x; i >= n; i--)
#define elif else if
#define sp setprecision
#define pb(x) push_back(x)
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<int, ll> pil;
typedef pair<ll, int> pli;
typedef pair<ld, ld> pdd;
const ll MOD = 1e9+7;
//const ll MOD = 998244353;
const int inf = 1e8;
const ll INF = 1e16;
const string alpha = "abcdefghijklmnopqrstuvwxyz";

int main(){
    int N, C;
    cin >> N >> C;
    ll D[C][C];
    int c[N][N];
    rep(i, C) rep(j, C) cin >> D[i][j];
    rep(i, N) rep(j, N){
        cin >> c[i][j];
        c[i][j]--;
    }
    ll ans = INF;
    ll cost[3][C];
    fill(cost[0], cost[3], 0);
    rep(j, 3){
        rep(i, C){
            rep(x, N) rep(y, N){
                int nowc = c[x][y];
                if((x+y)%3 == j) cost[j][i] += D[nowc][i];
            }
        }
    }
    rep(i, C){
        rep(j, C){
            rep(k, C){
                if((i-j)*(j-k)*(k-i) == 0) continue;
                ll sum = cost[0][i] + cost[1][j] + cost[2][k];
                ans = min(ans, sum);
            }
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 1280
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
#define rrep(i, n) for (int i = n - 1; i >= 0; i--)
using namespace std;
#define INF ((1<<30)-1)
#define LINF (1LL<<60)
#define EPS (1e-10)
typedef long long ll;
typedef pair<ll, ll> P;
const int MOD = 1000000007;
const int MOD2 = 998244353;

int a[45], b[45], c[45];
ll dp[45][450][450];


int main(){
    int n, ma, mb;
    cin >> n >> ma >> mb;
    rep(i, n) cin >> a[i] >> b[i] >> c[i];

    rep(k, 45) rep(i, 450) rep(j, 450){
        dp[k][i][j] = LINF;
    }
    dp[0][0][0] = 0;

    for(int i = 1; i <= n; i++){
        for(int p = 0; p <= 400; p++){
            for(int q = 0; q <= 400; q++){
                if (p >= a[i-1] && q >= b[i-1]) dp[i][p][q] = min(dp[i-1][p][q], dp[i-1][p - a[i-1]][q - b[i-1]] + c[i-1]);
                else dp[i][p][q] = dp[i-1][p][q];
            }
        }
    }

    ll ans = LINF;
    for (int p = 1; p < 1000; p++){
        int x = ma * p;
        int y = mb * p;
        if (x > 400 || y > 400) continue;
        ans = min(ans, dp[n][x][y]);
    }

    if (ans == LINF) cout << -1 << endl;
    else cout << ans << endl;

    return 0;
}


Measured memory_bytes: 71424