akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <vector>
#include <utility>
#include <functional>
#include <numeric>
#include <list>
#include <set>
#include <map>
#include <algorithm>
#include <cmath>
#include <limits>
#include <iomanip>
#include <bitset>
#include <queue>
#include <unordered_set>
#include <unordered_map>

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

#define rep(i, n) for(int i = 0;i < n;i++)
const int INF = 1LL << 30;
const int MOD = 1000000007;


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

    int n; string s;
    cin >> n >> s;

    int i = 0;
    int cnt = 0;

    while(i+2 <= n-1){
        if(s[i]=='A' && s[i+1] == 'B' && s[i+2] == 'C'){
            cnt++;
            i+=3;
        } else {
            i++;
        }
    }

    cout << cnt << endl;

    
    return 0;
}

Measured memory_bytes: 256
//============================================================================
// Name        : JOI.cpp
// Author      :
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <math.h>
#include <stdio.h>
#include <vector>
using namespace std;
typedef long long ll;
int A,B;
int main(){
	cin>>A>>B;

	if(A==1)A=14;
	if(B==1)B=14;
	if(A>B)cout<<"Alice"<<endl;
	if(A==B)cout<<"Draw"<<endl;
	if(A<B)cout<<"Bob"<<endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
#define SIZE 100005
#define INF 1000000005LL
#define MOD 1000000007

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

int N;
struct edge{int to;ll w;};
vector<edge> G[SIZE];
ll d[SIZE];

void dfs(int v,ll w){
	d[v] = w;
	rep(i,0,G[v].size()){
		edge nt = G[v][i];
		if(d[nt.to] == -1){
			dfs(nt.to,w + nt.w);
		}
	}
}


int main()
{
	cin >> N;
	int a,b;
	ll c;
	rep(i,0,N-1){
		cin >> a >> b >> c;
		G[a].push_back((edge){b,c});
		G[b].push_back((edge){a,c});
	}
	int Q,K;
	fill(d,d+N+1,-1);
	cin >> Q >> K;
	dfs(K,0);
	rep(i,0,Q){
		scanf("%d%d",&a,&b);
		printf("%lld\n",d[a]+d[b]);
	}

	return 0;
}


Measured memory_bytes: 14336
//#define LOCAL

#include <fstream>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <string>
#include <map>
#include <vector>
#include <climits>
#include <queue>
#include <assert.h>
#include <set>

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

//#define int long long
typedef long long ll;

using namespace std;

signed main()
{
#ifdef LOCAL
    ifstream in("input.txt");
    cin.rdbuf(in.rdbuf());
#endif

    string A, B, C;
    cin >> A >> B >> C;
    if (A[A.length()-1] == B[0] && B[B.length()-1] == C[0]) {
        cout << "YES" << endl;
    } else {
        cout << "NO" << endl;
    }
}


Measured memory_bytes: 256
import java.io.*;
import java.util.Arrays;

public class Main {
	public static void main(String[] args) throws IOException {
		String str = new BufferedReader(new InputStreamReader(System.in)).readLine();
		int num = Integer.parseInt(str);
		int sum = Arrays.stream(str.split("")).mapToInt(Integer::parseInt).sum();
		String ans = num % sum == 0 ? "Yes" : "No";
		System.out.println(ans);
	}
}

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

int main(){
  int n;
  cin >> n;
  vector<int> a(n);
  for(int i = 0; i < n; ++i) cin >> a[i];
  int s=a[0],l=a[0];
  for(int i=1; i < n; ++i){
	  if(s > a[i]) s=a[i];
	  if(l < a[i]) l=a[i];
  }
  cout << l-s << endl;
  return 0;
}

Measured memory_bytes: 256
//的場梨沙★担当
//結城晴★副担当
//日野茜★副担当
#include <vector>
#include <list>
#include <map>
#include <climits>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string.h>
#include <string>
#include <cstring>
#include <ctime>
#include <queue>
#include <random>
#include <cctype>
#include <complex>
#include <regex>
#include <unordered_map>
#include <string>
#include <algorithm>
#include <cctype>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <iomanip>
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <vector>
#include <stdio.h>


using namespace std;

int main(void) {
    int r,D,X;
    cin>>r>>D>>X;
    int A;
    for(int i=1;i<=10;i++){

        X=X*r-D;
        cout<<X<<endl;

    }
}


Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cstring>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <numeric>
#include <utility>
#include <iomanip>
#include <algorithm>
#include <functional>
#include <unordered_map>
using namespace std;

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

template<class T> vector<T> make_vec(size_t a) { return vector<T>(a); }
template<class T, class... Ts> auto make_vec(size_t a, Ts... ts) {
  return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}
template<class T, class V>
typename enable_if<is_class<T>::value == 0>::type fill(T &t, const V &v) {
    t = v;
}
template<class T, class V>
typename enable_if<is_class<T>::value != 0>::type fill(T &t, const V &v){
    for (auto &e : t) fill(e, v);
}

#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }

#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)
template<class T> ostream& operator << (ostream &s, set<T> P)
{ EACH(it, P) { s << "<" << *it << "> "; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s << endl; }




int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int N;
    while (cin >> N) {
        long long s1 = 0, s2 = 0;
        for (int i = 0; i < N; ++i) {
            long long a; cin >> a;
            s1 += a * a;
            s2 += a;
        }
        cout << (s2 * s2 - s1) / 2 << endl;
    }
}


















Measured memory_bytes: 256
#include<iostream>
using namespace std;
char a[3];
int main()
{
	cin>>a;
	for(int i=0;i<2;i++)
	{
		if(a[i]=='9')
		{
			cout<<"Yes";
			return 0;
		}
	}
	cout<<"No";
	return 0;
} 

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
const ll INF = 0x1fffffffffffffff;
int main(){
    ll n;
    cin>>n;
    string s;
    cin>>s;
    if(n%2==1)cout<<"No"<<endl;
    else{
        ll m=n/2;
        string s1,s2;
        s1=s.substr(0,m);
        s2=s.substr(m,m);
        if(s1==s2)cout<<"Yes"<<endl;
        else cout<<"No"<<endl;
    }
}

Measured memory_bytes: 256
from collections import defaultdict

N = int(input())
A = list(map(int, input().split()))

B = sorted(A)
index = defaultdict(lambda: -1)
for i, b in enumerate(B):
    index[b] = i

for i in range(N):
    if index[A[i]] < N // 2:
        print(B[N // 2])
    else:
        print(B[N // 2 - 1])

Measured memory_bytes: 39936
n = int(input())
ll = list(map(int,input().split()))
mm = []
pp = n
i = 0
for i in range(n):
    try:
        mm.append(str(ll[-1-2*i]))
        ll[-1-2*i] = '-1'
    except:
        pass

    
for i in range(len(ll)):
    if ll[i] != '-1':
        mm.append(str(ll[i]))
    else:
        None
        
sss = ''
for i in mm:
    print(i, end= ' ')

Measured memory_bytes: 28068
void main() {
	auto ip = readAs!(int[]), H = ip[0], W = ip[1];
	auto ip2 = readAs!(int[]), h = ip2[0], w = ip2[1];
	writeln((H-h) * (W-w));
}

// ===================================

import std.stdio;
import std.string;
import std.functional;
import std.algorithm;
import std.range;
import std.traits;
import std.math;
import std.container;
import std.bigint;
import std.numeric;
import std.conv;
import std.typecons;
import std.uni;
import std.ascii;
import std.bitmanip;
import core.bitop;

T readAs(T)() if (isBasicType!T) {
	return readln.chomp.to!T;
}
T readAs(T)() if (isArray!T) {
	return readln.split.to!T;
}

T[][] readMatrix(T)(uint height, uint width) if (!isSomeChar!T) {
	auto res = new T[][](height, width);
	foreach(i; 0..height) {
		res[i] = readAs!(T[]);
	}
	return res;
}

T[][] readMatrix(T)(uint height, uint width) if (isSomeChar!T) {
	auto res = new T[][](height, width);
	foreach(i; 0..height) {
		auto s = rs;
		foreach(j; 0..width) res[i][j] = s[j].to!T;
	}
	return res;
}

int ri() {
	return readAs!int;
}

double rd() {
	return readAs!double;
}

string rs() {
	return readln.chomp;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <bitset>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <cstring>
#include <utility>
#include <vector>
#include <complex>
#include <valarray>
#include <fstream>
#include <cassert>
#include <cmath>
#include <functional>
#include <iomanip>
#include <numeric>
#include <climits>
#include <random>

#define _overload(a, b, c, d, ...) d
#define _rep1(X, A, Y) for (int (X) = (A);(X) <= (Y);++(X))
#define _rep2(X, Y) for (int (X) = 0;(X) < (Y);++(X))
#define rep(...) _overload(__VA_ARGS__, _rep1, _rep2)(__VA_ARGS__)
#define rrep(X,Y) for (int (X) = Y-1;(X) >= 0;--(X))
#define all(X) (X).begin(),(X).end()
#define len(X) ((int)(X).size())
#define mod(n, m) (((n)%(m)+(m))%m)
#define fi first
#define sc second
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
const int INFINT = 1 << 30;                          // 1.07x10^ 9
const ll INFLL = 1LL << 60;                          // 1.15x10^18
const double EPS = 1e-10;
const int MOD = 1000000007;
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};

const int MAX_N = 100;
int N;
int W[MAX_N];

int main() {
  std::ios::sync_with_stdio(false);std::cin.tie(0);
  
  cin >> N;
  rep(i, N) cin >> W[i];

  int ans = INFINT;
  for (int t = 0; t < N-1; ++t) {
    int w1 = 0, w2 = 0;
    for (int j = 0; j <= t; ++j) {
      w1 += W[j];
    }
    for (int j = t+1; j < N; ++j) {
      w2 += W[j];
    }
    ans = min(ans, abs(w1-w2));
  }
  
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<tgmath.h>
int main(void) {
    int x,a,b;
    scanf("%d",&x);
    scanf("%d",&a);
    scanf("%d",&b);
    if(fabs(a-x)>fabs(b-x)) printf("B");
    else printf("A");
    return 0;
}


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

int main(void) {
    long long N, K;
    std::cin >> N >> K;
    vector< long long > A(N + 1);
    for (long long i = 1; i <= N; i++) {
        cin >> A[i];
    }
    long long c = 1;
    vector< long long > p(N + 1);
    for (long long i = 1; i <= N; i++) {
        p[i] = -1;
    }
    p[1] = 0;
    long long l = 1;
    for (long long i = 1; i < 2 * N + 10; ++i) {
        c = A[c];
        if (p[c] >= 0) {
            l = i - p[c];
            break;
        }
        p[c] = i;
    }
    long long m;
    if (K < (long long)(p[c] + l)) {
        m = K;
        c = 1;
    } else {
        m = (K - (long long)p[c]) % (long long)l;
    }
    for (long long i = 0; i < m; i++) {
        c = A[c];
    }
    printf("%d\n", c);

    return 0;
}


Measured memory_bytes: 6376
import java.util.Scanner;

public class Main {
	private static Scanner stdIn;

	public static void main(String[] args) {
		stdIn = new Scanner(System.in);
		int a = stdIn.nextInt();
		
		int[] L = new int[2 * a];
		
		for(int i = 0;i < 2 * a;i++) {
			L[i] = stdIn.nextInt();
		}
		
      int k = 0;
      
		for(int j = 0;j < 2 * a;j++) {
			for(int i = 0;i < 2 * a - 1;i++) {
				if(L[i] > L[i + 1]){
                  k = L[i];
                  L[i] = L[i + 1];
                  L[i + 1] = k;
                }
			}
		}
		
		int n = 0;
		
		for(int i = 0;i < a;i++) {
			n += L[2 * i];
		}
		
		System.out.println(n);
	}
}

Measured memory_bytes: 23764
/*********************************************************************************\
*  _________  _      _  ________  _       _       __       ________               *
* |___   ___|| |    | ||  ______|| |     | |     /  \     |  ____  |              *
*     | |    | |    | || |______ | |_____| |    / /\ \    | |____| |              *
*     | |    | |    | ||______  ||  _____  |   / /__\ \   |  __  __|              *
*     | |    | |____| | ______| || |     | |  / ______ \  | |  \ \                *
*     |_|    |________||________||_|     |_| /_/      \_\ |_|   \_\               *
*  ________       __      ________  _    __       __       ________               *
* |  ______|     /  \    |  ____  || |  / /      /  \     |  ____  |              *
* | |______     / /\ \   | |____| || |_/ /      / /\ \    | |____| |              *
* |______  |   / /__\ \  |  __  __||  __ \     / /__\ \   |  __  __|              *
*  ______| |  / ______ \ | |  \ \  | |  \ \   / ______ \  | |  \ \                *
* |________| /_/      \_\|_|   \_\ |_|   \_\ /_/      \_\ |_|   \_\               *
*                                                                                 *
*                                                                                 *
*   Department of Computer Science & Engineering                                  *
*   Student ID : 18CSE035                                                         *
*   Bangabnadhu Sheikh Mujibur Rahman Science & Technology University,Gopalgonj.  *
*                                                                                 *
\*********************************************************************************/

//Now Write to Code ___________________________


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

const int N = (int) 1e5 + 5;



int main() {
	int i,N,K;
	string str;

	cin >> N >> K >> str;
    str[K-1] = str[K-1] + 32;

    for(i = 0; i < N; i++)
    {
    	cout << str[i];
    } 
    cout << endl;


	return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize("O3")
#include <bits/stdc++.h>

using namespace std;

typedef int64_t  ll;
typedef uint64_t ull;

#define rep(i,n)   for (int i = 0; i < (n); i++)
#define rrep(i,n)  for (int i = (n)-1; i >= 0; i--)
#define rep1(i,n)  for (int i = 1; i <= (n); i++)
#define rrep1(i,n) for (int i = (n); i > 0; i--)

int main(void) {
    int digits;
    string s;
    char password[4] = {};
    int pos = 0, ans = 0;

    cin >> digits;
    cin >> s;

    rep(i, 1000) {
        sprintf(password, "%03d", i);
        pos = 0;
        rep(j, digits) {
            if (s[j] == password[pos]) {
                if (password[++pos] == '\0') {
                    ans++;
                    break;
                }
            }
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
import java.util.*;
import static java.lang.Math.*;
import java.math.BigInteger;

public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		
		// 入力
		int n = sc.nextInt();
		int t = sc.nextInt();
		int[][] dish = new int[n][2];
		for(int i = 0; i < n; i++){
		    dish[i][0] = sc.nextInt();
		    dish[i][1] = sc.nextInt();
		}
		Arrays.sort(dish, (x, y) -> Integer.compare(x[0], y[0]));
		
		// 計算
		int result = 0;
		int[][] dp = new int[n+1][t];
		for(int i = 0; i < n; i++){
		    int a = dish[i][0];
		    int b = dish[i][1];
		    for(int j = t-1; j > 0; j--){
		        dp[i+1][j] = dp[i][j];
		        if(j >= a){
		            dp[i+1][j] = max(dp[i][j], dp[i][j-a] + b);
		        }
		    }
		    result = max(result, dp[i][t-1] + b);
		}
		
		// 出力
		System.out.println(result);
	}
}


Measured memory_bytes: 69584
#include<algorithm>
#include<iostream>
#include<vector>
#include<cstdio>
#include<cstring>
using namespace std;
const int N=2e6+5;
const int inf=1e9;
char s[N];
int n,a[N],b[N];
int go(int z){
	int res=0,ans=0;
	for(int i=0;i<n;i++){
		if(s[i]=='?'&&a[i]+res+2<=z)	res+=2;
		ans=min(ans,b[i]+res);
	}
	return z-ans;
}
int main(){
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	int sum=0;
	scanf("%s",s),n=strlen(s);
	for(int i=0;i<n;i++){
		if(s[i]=='0')	++sum;
		else	--sum;
		a[i]=b[i]=sum;
	}
	for(int i=n-2;~i;i--)	a[i]=max(a[i],a[i+1]);
	printf("%d\n",min(go(max(0,a[0])),go(max(0,a[0])+1)));
	return 0;
}


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

using namespace std;

int main(void){
    int A,B;
    cin>>A>>B;
    int result=1;
    int count=0;
    while(result<B){
        result--;
        result+=A;
        count++;
    }
    cout<<count<<endl;
    return 0;
}

Measured memory_bytes: 256
using System;
using CompLib.Util;

public class Program
{
    private int N;
    private long[] A;

    public void Solve()
    {
        var sc = new Scanner();
        N = sc.NextInt();
        A = sc.LongArray();

        Array.Sort(A, (l, r) => r.CompareTo(l));
        long ans = 0;
        for (int i = 1; i < N; i++)
        {
            ans += A[i / 2];
        }

        Console.WriteLine(ans);
    }

    public static void Main(string[] args) => new Program().Solve();
}

namespace CompLib.Util
{
    using System;
    using System.Linq;

    class Scanner
    {
        private string[] _line;
        private int _index;
        private const char Separator = ' ';

        public Scanner()
        {
            _line = new string[0];
            _index = 0;
        }

        public string Next()
        {
            while (_index >= _line.Length)
            {
                _line = Console.ReadLine().Split(Separator);
                _index = 0;
            }

            return _line[_index++];
        }

        public int NextInt() => int.Parse(Next());
        public long NextLong() => long.Parse(Next());
        public double NextDouble() => double.Parse(Next());
        public decimal NextDecimal() => decimal.Parse(Next());
        public char NextChar() => Next()[0];
        public char[] NextCharArray() => Next().ToCharArray();

        public string[] Array()
        {
            _line = Console.ReadLine().Split(Separator);
            _index = _line.Length;
            return _line;
        }

        public int[] IntArray() => Array().Select(int.Parse).ToArray();
        public long[] LongArray() => Array().Select(long.Parse).ToArray();
        public double[] DoubleArray() => Array().Select(double.Parse).ToArray();
        public decimal[] DecimalArray() => Array().Select(decimal.Parse).ToArray();
    }
}

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

using namespace std;


int main() {
  int N; cin >> N;
  set<int> s1{2,4,5,7,9}, s2{0,1,6,8}, s3{3};
  if (s1.find(N%10) != s1.end()) {
    cout << "hon" << endl;
  }
  else if (s2.find(N%10) != s2.end()) {
    cout << "pon" << endl;
  }
  else {
    cout << "bon" << endl;
  }
  return 0;
}

Measured memory_bytes: 3604
import sys
input = sys.stdin.readline

def main():
    N,A,B = map(int,input().split())
    v = sorted(list(map(int,input().split())),reverse=True)
    use = v[:A]
    print(sum(use)/A)
    fac = [0 for _ in range(N+1)]
    fac[0],fac[1] = 1,1
    
    for i in range(2,N+1):
        fac[i] = (fac[i-1]*i)

    x = v.count(v[A-1])
    y = use.count(use[A-1])
    
    if v[0] == v[A-1]:
        ans = 0
        for i in range(A,min(B,x)+1):
            ans += fac[x]//(fac[i]*fac[x-i])
        print(ans)
    else:
        ans = fac[x]//(fac[y]*fac[x-y])
        print(ans)

if __name__ == "__main__":
    main()


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000000 + 7
#define vpi vector<pair<int, int>>
#define ll long long int
#define MAX 1000000
#define minus_inf -1000000000


bool checkPalindrome(string x){
    string y = x;
    reverse(x.begin(), x.end());
    for(int i=0; i<x.length(); ++i){
        if(x[i]!=y[i]) return false;
    }
    return true;
}

int main(){
    long double L;
    cin>>L;
    cout<<setprecision(50)<<(L*L*L/27)<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <utility>
#include <string>
#include <vector>
#include <set>
#include <stack>
#include <queue>
#include <map>
#include <math.h>
#include <string.h>
#include <iomanip>
#include <numeric>
#include <cstdlib>
#include <cstdint>
#include <cmath>
#include <functional>
#include <limits>
#include <cassert>
#include <bitset>

using namespace std;

/* template */

using ll = long long;

void debug_out() { std::cout << std::endl; }
 
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cout << H << " ";
  debug_out(T...);
}

#ifdef LOCAL
#define debug(...) cout << "debug: "; debug_out(__VA_ARGS__)
#else
#define debug(...) 
#endif

#define rep(i, a, n) for (int i = (int)(a); i < (int)(n); i++)
#define rrep(i, a, n) for (int i = ((int)(n-1)); i >= (int)(a); i--)
#define Rep(i, a, n) for (long long i = (long long)(a); i< (long long)(n); i++)
#define RRep(i, a, n) for (long long i = ((long long)(n-1ll)); i>=(long long)(a); i--)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()

template <typename T>
std::ostream& operator<<(std::ostream& os, std::vector<T> vec) {
  for (std::size_t i = 0; i < vec.size(); i++)os << vec[i] << (i + 1 == vec.size() ? "" : " ");
  return os;
}

struct Edge{
    int to;
    ll weight;
    Edge(int t, ll w) : to(t), weight(w){ }
};

struct edge{
    int from;
    int to;
    ll weight;
    edge(int f,int t,ll w) : from(f), to(t), weight(w){ }
};


using Graph = vector<vector<Edge>>;
using graph = vector<vector<int>>;
using edges = vector<edge>;

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

template <class T>
T lcm(T a, T b){
    return (a*b)/gcd(a,b);
}

ll ctoi(char c) {
	switch (c) {
	case '0': return 0; case '1': return 1; case '2': return 2;
	case '3': return 3; case '4': return 4; case '5': return 5;
	case '6': return 6; case '7': return 7; case '8': return 8;
	case '9': return 9;  default: return 0;
	}
}

constexpr ll LNF = 1LL<<50;

constexpr int INF = 1e9+7;

const long double PI=3.14159265358979323846;


vector<int> dx = {1,0,-1,1,-1,0};
vector<int> dy = {1,1,1,0,0,-1};

/* template */

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n; cin >> n;
    vector<ll> a(n);
    map<ll,ll> m;
    rep(i,0,n){
        cin >> a[i];
        m[a[i]]++;
    }
    sort(all(a));
    int ans = 0;
    rrep(i,0,n){
        ll index = 0;
        if(m[a[i]]==0){
            continue;
        }
        m[a[i]]--;
        while((1ll<<index)<=a[i]){
            index++;
        }
        ll key = (1ll<<index) - a[i];
        if(m[key]>0){
            ans++;
            m[key]--;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 29768
# include "iostream"
# include "cstdio"

using namespace std;

const int maxm=1e5+10;

int N;
char S1[maxm],S2[maxm],S3[maxm];

int main(){
	register int i,Ans=0;
	scanf("%d%s%s%s",&N,S1+1,S2+1,S3+1);
	for(i=1;i<=N;i++){
		if(S1[i]==S2[i] && S2[i]==S3[i]) continue;
		if(S1[i]!=S2[i] && S2[i]!=S3[i] && S1[i]!=S3[i]) Ans+=2;
		else Ans+=1;
	}
	printf("%d",Ans);
	return 0;
}

Measured memory_bytes: 384
#include <stdio.h>
#include <inttypes.h>

int main(void) {
	uint64_t X, Y;
	if (scanf("%" SCNu64 "%" SCNu64, &X, &Y) != 2) return 1;
	puts(X >= Y + 2 || Y >= X + 2 ? "Alice" : "Brown");
	return 0;
}

/*

石の数の差が0 → 操作をすると必ず差が3以上になる (a, a -> a-2, a+1)
石の数の差が1 → 操作をすると必ず差が2以上になる (a, a+1 -> a-2, a+2 / a+1, a-1)

石の数の差が2以上 → 操作をすると必ず差を1以下にできる
	差が最初dあるとする
	多い山から少ない山に動かすとすると、2i取ると差が3i縮まる
	3ずつ動かせるので、できる

負けが確定するのは、石の数(0, 0), (0, 1), (1, 0), (1, 1)
これらは全て石の数の差が1以下

石の数の差が2以上ならば、石が2個以上ある山があるので必ず操作ができる

石の数の差が1以下ならば、負けまたは相手に石の数の差が2以上の状態を回す

石の数の差が2以上ならば、相手に石の数の差が1以下の状態を回すことができる

したがって、石の数の差が1以下なら負け、2以上なら勝ち

*/


Measured memory_bytes: 128
#![allow(unused_imports)]

use std::cmp::{max, min};
use std::collections::{BTreeMap, BTreeSet, HashMap, HashSet, VecDeque};
use std::io::stdin;
use std::str::FromStr;

// 再帰的に親を辿って上から順に値を確定させていく、実装重めかも

fn main() {
    let (n, m): (usize, usize) = input_two();
    let mut es = Vec::new();
    for _i in 0..m {
        es.push(input_two::<usize, usize>());
    }

    let mut ans = 0;

    for r in 0..m {
        let mut g = vec![Vec::new(); n];
        for (i, e) in es.iter().enumerate() {
            if i == r {
                continue;
            } else {
                g[e.0 - 1].push(e.1 - 1);
                g[e.1 - 1].push(e.0 - 1);
            }
        }

        let mut visited = vec![false; n];
        dfs(&g, &mut visited, 0);
        // dbg!(&visited);

        if visited.iter().any(|x| !*x) {
            ans += 1;
        }
    }

    println!("{}", ans);
}

fn dfs(g: &Vec<Vec<usize>>, visited: &mut Vec<bool>, cur: usize) {
    if visited[cur] {
        return;
    } else {
        visited[cur] = true;
    }
    for p in g[cur].iter() {
        dfs(g, visited, *p);
    }
}

pub fn input<T: FromStr>() -> Result<T, T::Err> {
    let mut buf = String::new();
    stdin().read_line(&mut buf).unwrap();
    Ok(buf.trim().parse().ok().unwrap())
}

pub fn input_vec<T: FromStr>() -> Result<Vec<T>, T::Err> {
    let mut buf = String::new();
    stdin().read_line(&mut buf).unwrap();
    Ok(buf
        .trim()
        .split_whitespace()
        .map(|x| x.parse().ok().unwrap())
        .collect::<Vec<_>>())
}

pub fn input_two<T: FromStr, U: FromStr>() -> (T, U) {
    let mut buf = String::new();
    stdin().read_line(&mut buf).unwrap();
    let s: Vec<&str> = buf.split_whitespace().collect();
    (
        s[0].parse::<T>().ok().unwrap(),
        s[1].parse::<U>().ok().unwrap(),
    )
}

pub fn input_three<T: FromStr, U: FromStr, V: FromStr>() -> (T, U, V) {
    let mut buf = String::new();
    stdin().read_line(&mut buf).unwrap();
    let s: Vec<&str> = buf.split_whitespace().collect();
    (
        s[0].parse::<T>().ok().unwrap(),
        s[1].parse::<U>().ok().unwrap(),
        s[2].parse::<V>().ok().unwrap(),
    )
}

pub fn input_four<T: FromStr, U: FromStr, V: FromStr, W: FromStr>() -> (T, U, V, W) {
    let mut buf = String::new();
    stdin().read_line(&mut buf).unwrap();
    let s: Vec<&str> = buf.split_whitespace().collect();
    (
        s[0].parse().ok().unwrap(),
        s[1].parse().ok().unwrap(),
        s[2].parse().ok().unwrap(),
        s[3].parse().ok().unwrap(),
    )
}


Measured memory_bytes: 4352
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD=1e9+7;

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


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

using namespace std;

template <class T>inline T updmax(T& a, T b) {return a = max(a, b);}
template <class T>inline T updmin(T& a, T b) {return a = min(a, b);}

class Solution {
public:
	void solve() {
		int h, w, a, b;
		cin >> h >> w >> a >> b;
		if(h == 1){
			for(int i=0; i < a; i++)cout << "1";
			for(int i=0; i<w-a; i++)cout << "0";
			cout << endl;
			return;
		}
		if(w == 1){
			for(int i=0; i < b; i++)cout << "1\n";
			for(int i=0; i<h-b; i++)cout << "0\n";
			return;
		}
		for(int i=0; i < h; i++){
			for(int j=0; j < w; j++){
				bool x = j < a;
				bool y = i < b;
				if(x^y)cout << 0;
				else cout << 1;
			}
			cout << "\n";
		}
		return;
	};
};
int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	Solution solution;
	solution.solve();
	return 0;
}

Measured memory_bytes: 1280
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
#define rep(i,n) for (ll i = 0; i < (n); ++i)
#define vcout(v) rep(i,v.size()) cout << v[i] << " "; cout << endl
#define mcout(m) rep(j,m.size()){vcout(m[j]);}
const ll MOD = 1e9 + 7;
const ll INF = 1e18;

void mainsolve(){

    ll n;
    cin >> n;
    vector<string> s(n);
    rep(i,n) cin >> s[i];

    vector<vector<ll>> d(n, vector<ll>(n, INF));
    rep(i,n) d[i][i] = 0;

    vector<vector<ll>> to(n);
    rep(i,n){
        for(ll j = i+1; j < n; j++){
            if(s[i][j] == '1'){
                to[i].push_back(j);
                to[j].push_back(i);
                d[i][j] = d[j][i] = 1;
            }
        }
    }

    rep(k,n) rep(i,n) rep(j,n) d[i][j] = min(d[i][j], d[i][k] + d[k][j]);

    ll res = -1;
    rep(root, n){
        bool isNG = false;
        rep(i,n){
            for(ll j : to[i]){
                if(abs(d[root][i] - d[root][j]) != 1) isNG = true;
                if(isNG) break;
            }
            if(isNG) break;
        }
        if(isNG) continue;

        // NGじゃなかったので-1ではない
        rep(i,n) res = max(res, d[root][i]+1);
    }

    cout << res << endl;
	return;
}

int main(){
	
	//ll TC;cin>>TC;rep(I,TC){cout<<"case:"<<I+1<<"---"<<endl; // comment out!
		mainsolve();
	//} // comment out!
	return 0;
}

Measured memory_bytes: 1024
# coding: utf-8
# Your code here!
import sys
sys.setrecursionlimit(10**6)
readline = sys.stdin.readline

def Eratosthenes(N): #N以下の素数のリストを返す
    #iが素数のときis_prime_list[i]=1，それ以外は0
    N+=1
    is_prime_list = [True]*N
#    is_prime_list[0], is_prime_list[1] = False, False #リストが必要なときはこの2行を有効化
#    for j in range(4,N,2): is_prime_list[j] = False
    m = int(N**0.5)+1
    for i in range(3,m,2):
        if is_prime_list[i]:
            is_prime_list[i*i::2*i]=[False]*((N-i*i-1)//(2*i)+1)
    return [2] + [i for i in range(3,N,2) if is_prime_list[i]]
#    return is_prime_list


N = int(input())
a = Eratosthenes(2*N)

from bisect import bisect_left

print(a[bisect_left(a,N)])

"""
a,b,k = [int(i) for i in readline().split()]


if a >= k: a -= k
else:
    k -= a
    a = 0
    b = max(0,b-k)


print(*[a,b])
"""





Measured memory_bytes: 5452
from collections import defaultdict
a,b,m=map(int,input().split())
r=defaultdict(int)
c=defaultdict(int)
d=defaultdict(int)
for i in range(m):
  x,y=map(int,input().split())
  d[(x,y)]=1
  r[x]+=1
  c[y]+=1
z=list()
zz=list()
x=max(r,key=r.get)
y=max(c,key=c.get)
for i in r.keys():
  if r[i]==r[x]:
    z.append(i)
for i in c.keys():
  if c[i]==c[y]:
    zz.append(i)
flag=False
for i in z:
  for j in zz:
    if d[(i,j)]==0:
      flag=True
      break
if flag==False:
  print(r[x]+c[y]-1)
else:
  print(r[x]+c[y])
  
  


Measured memory_bytes: 112112
#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>;

int main(){
	int n, m, r;
	cin >> n >> m >> r;
	vector<vector<int>> c(n, vector<int>(n));
	rep(i, n) rep(j, n) c.at(i).at(j) = 1000000000;
	rep(i, n) c.at(i).at(i) = 0;
	vector<int> zi(r);
	rep(i, r){
		cin >> zi.at(i);
		zi.at(i)--;
	}
	rep(i, m){
		int a, b, cos;
		cin >> a >> b >> cos;
		a--; b--;
		c.at(a).at(b) = cos;
		c.at(b).at(a) = cos;
	}
	rep(k, n) rep(i, n) rep(j, n){
		c.at(i).at(j) = min(c.at(i).at(j), c.at(i).at(k) + c.at(k).at(j));
	}
	sort(zi.begin(), zi.end());
	ll ans = 2000000000000000000;
	do{
		ll sum = 0;
		rep(i, r-1) sum += c.at(zi.at(i)).at(zi.at(i+1));
		if(sum < ans) ans = sum;
	}while(next_permutation(zi.begin(), zi.end()));
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3764
#include <bits/stdc++.h>
using namespace std;
#define rep(i, s, t) for(int i = (s), mi = (t); i <= mi; i++)
#define dwn(i, s, t) for(int i = (s), mi = (t); i >= mi; i--)

int read() {
	int x = 0, f = 1; char c = getchar();
	while(!isdigit(c)){ if(c == '-') f = -1; c = getchar(); }
	while(isdigit(c)){ x = x * 10 + c - '0'; c = getchar(); }
	return x * f;
}

#define maxn 4
#define maxm 100010
#define MOD 1000000007
#define LL long long

int n, m, X[maxm];

struct Matrix {
	int n, m, A[maxn][maxn];
	
	Matrix(int _ = 0, int __ = 0): n(_), m(__) { memset(A, 0, sizeof(A)); }
	
	Matrix operator * (const Matrix &t) const {
		Matrix ans(n, t.m);
		rep(i, 0, ans.n - 1) rep(j, 0, ans.m - 1) {
			LL tmp = 0;
			rep(k, 0, m - 1) tmp += (LL)A[i][k] * t.A[k][j];
			ans.A[i][j] = tmp % MOD;
		}
		return ans;
	}
	Matrix operator *= (const Matrix &t) { return *this = *this * t; }
} base, tr[maxm], tr0, tr1;

Matrix Pow(Matrix a, int b) {
	if(!b) {
		Matrix ans = Matrix(4, 4);
		rep(i, 0, 3) ans.A[i][i] = 1;
		return ans;
	}
	Matrix ans = a, t = a; b--;
	while(b) {
		if(b & 1) ans *= t;
		t *= t; b >>= 1;
	}
	return ans;
}

int main() {
	n = read(); m = read();
	rep(i, 1, m) X[i] = read();
	X[++m] = n;
	dwn(i, m, 1) X[i] -= X[i-1];
	
	base = Matrix(1, 4); base.A[0][0] = 1;
	tr0 = Matrix(4, 4);
	tr0.A[0][0] = tr0.A[0][1] = tr0.A[0][2] = tr0.A[0][3] = 1;
	tr0.A[1][1] = tr0.A[1][3] = 1;
	tr0.A[2][2] = tr0.A[2][3] = 1;
	tr0.A[3][0] = tr0.A[3][1] = tr0.A[3][2] = 1; tr0.A[3][3] = 2;
	tr1 = tr0; rep(i, 0, 3) tr1.A[3][i]--;
	rep(i, 1, m)
		if(i == 1) base *= Pow(tr0, X[i]);
		else base *= tr1 * Pow(tr0, X[i] - 1);
	
	printf("%d\n", base.A[0][3]);
	
	return 0;
}

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

int s,k;

int main(){
    cin >> k >> s;
    long long Out = 0;
    for(int i = 0; i <= k; i++){
        for(int j = 0; j <= k; j++){
            int sb = s - i - j;
            if( sb >= 0 && sb <= k) Out++;
        }
    }
    printf("%lld\n",Out);
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#define MAX 1010

int C[MAX][MAX];

int main() {
  int n;
  std::cin >> n;
  int answers[160];

  for(int m=0; m<n; ++m) {
    std::string X;
    std::string Y;
    std::cin >> X;
    std::cin >> Y;

    // initialize
    for(int k=0; k<MAX; ++k) {
      for(int p=0; p<MAX; ++p) C[k][p] = 0;
    }

    // lcs
    int xlen = X.size();
    int ylen = Y.size();

    X = ' ' + X;
    Y = ' ' + Y;

    for(int i=1; i<=xlen; ++i) {
      for(int j=1; j<=ylen; ++j) {
        if(X[i] == Y[j]) {
          C[i][j] = C[i-1][j-1] + 1;
        } else {
          C[i][j] = std::max(C[i-1][j], C[i][j-1]);
          
        }
      }
    }

    answers[m] = C[xlen][ylen];
  }

  for(int h=0; h<n; ++h) {
    std::cout << answers[h] << std::endl;
  }
}


Measured memory_bytes: 7168
// -----------------------------------
// Author     : MatsuTaku
// Affiliation: Tokushima University
// Country    : Japan
// Date       : 03/14/2020
// -----------------------------------

#include <bits/stdc++.h>

using namespace std;
using ll = long long;

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

  uint64_t H,W; cin>>H>>W;
  uint64_t ans = 0;
  if (H == 1 or W == 1)
    ans = 1;
  else
    ans = (H*W+1)/2;
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <climits>
#include <set>
#include <string>
#include <algorithm>
#include <vector>
#define MAX 1000000007


using namespace std;
#define ll long long
#define dbg if(0)
#define ISRANGE(val,lo,hi) ((lo<=val)&&(val<hi))



int main(){
    ll ans,n,k;
    cin >>n>>k;
    ans=n-k+1;

    cout <<ans<<endl;

    return 0;

}

Measured memory_bytes: 256
import java.util.Scanner;

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

		int n = sc.nextInt();
		String result = "No";

		for (int i = 1; i <= 9; i++) {
			if (n % i == 0 && n / i <= 9) {
				result = "Yes";
				break;
			}
		}
		System.out.println(result);
		sc.close();
	}
}


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

using namespace std;

const int   N   = 1e5 + 1;

int n;
int a[N], b[N];

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

    priority_queue<int> q1, q2;

    cin >> n;

    for(int i = 1 ; i <= n ; ++i)   cin >> a[i];
    for(int i = 1 ; i <= n ; ++i)   cin >> b[i];

    for(int i = 1 ; i <= n ; ++i)   {
        if(b[i] - a[i] > 1) q1.push(b[i] - a[i]);
        if(b[i] - a[i] < 0) q2.push(a[i] - b[i]);
    }

    while(q1.size() && q2.size())   {
        int x1 = q1.top();  q1.pop();
        int x2 = q2.top();  q2.pop();
        int t  = min(x1 / 2,x2);
        x1 -= t * 2;
        x2 -= t;
        if(x1 > 1)  q1.push(x1);
        if(x2 > 0)  q2.push(x2);
    }

    if(q2.size())   cout << "No";
    else            cout << "Yes";
}

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

int main()
{
  int W, H, x, y, r;
  cin >> W >> H >> x >> y >> r;
  if (x-r >= 0 && y-r >= 0 && x+r <= W && y+r <= H)
  {
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
}


Measured memory_bytes: 3116
#include<bits/stdc++.h>
using namespace std;
int gcd(int x, int y) {
	return !y ? x : gcd(y, x % y);
}
const int N = 2010;
int a[N], e[N][N], n, d[N];
bool vis[N];
vector<int> g[N];
void dfs(int x) {
	vis[x] = 1;
	for (int i = 1; i <= n; i++) 
		if (!vis[i] && e[x][i]) {
			g[x].push_back(i); d[i]++;
			dfs(i);
		}
}
priority_queue<int> q;
int main() {
	scanf("%d", &n);
	for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
	sort(a + 1, a + 1 + n);
	for (int i = 1; i <= n; i++)
		for (int j = i + 1; j <= n; j++)
			if (gcd(a[i], a[j]) > 1)
				e[i][j] = e[j][i] = 1;
	for (int i = 1; i <= n; i++)
		if (!vis[i]) dfs(i);
	for (int i = 1; i <= n; i++) if (!d[i]) q.push(i);
	while (!q.empty()) {
		int u = q.top(); q.pop();
		printf("%d ", a[u]);
		for (int i = 0; i < g[u].size(); i++) {
			int v = g[u][i];
			if (!(--d[v])) q.push(v);
		}
	}
	return 0;
}

Measured memory_bytes: 16256
#include <cstdio>
#include <vector>
#include <algorithm>
#include <cstring>
#include <string>
#include <cctype>
#include <sstream>
#include <cmath>
#include <climits>
#include <set>
#include <iostream>
#include <map>
#include <functional>
#include <cstdlib>
#include <numeric>
#include <queue>
#include <complex>
#include <sstream>
#include <stack>

using namespace std;

#define reep(i,f,n) for(int i=f; i<int(n); ++i)
#define rep(i,n) reep(i,0,n)

typedef vector<int> vi;
typedef pair<int, int> pii;
typedef complex<double> Point;

typedef map<int, pair<int, long long> > mipill;

int main()
{
	int n;
	scanf("%d%*c", &n);
	
	rep(i, n){
		char s[1024];
		fgets(s, 1024, stdin);
		s[strlen(s)-1] = '\0';
		
		string str(s);
		string::size_type index = 0;
		while((index = str.find("Hoshino", index)) != string::npos)
			str[index + 6] = 'a';

		puts(str.c_str());
	}
	return 0;
}

Measured memory_bytes: 0
import java.util.*;

class Main {
  public static void main(String[] args) {
	Scanner scanner = new Scanner(System.in);
    
    long S = scanner.nextLong(); //next(文字列), nextDouble, nextLine(1行)とか   
    int k = 0;
    long X = S; //Sの桁数を求めるパート
    while (X > 0){
      k++;
      X /= 10;
    }                  
    long[] A = new long[k]; //Sの各桁を配列に入れる
    for (int i = 0; i < A.length; i++){
      A[i] = S % 10;
      S /= 10;
    }    
    
    long ans = 0;
    for (long bit = 0; bit < (1<<(A.length-1));bit++){
      long temp = 0;
      long ten = 1;
      for (int j = 0; j < A.length; j++){
        temp += A[j]*ten;
        if ((bit & (1 << j)) == 0){
          ten *= 10;
          if (j == A.length-1){
            ans += temp;
          }
        }else{
          ans += temp;
          temp = 0;
          ten = 1;

        }
      }
    }
    System.out.println(ans);     
  }
}


Measured memory_bytes: 23764
#include <iostream>
#include <string>    
#include <vector>
#include <queue>
#include <algorithm>
#include <cmath>
using namespace std;
typedef long long ll;
ll n, a, b, x[100008];

int main() {
	cin >> n >> a >> b;//w, t
	for(ll i = 0; i <= n-1; i++){cin >> x[i];}
	
	ll ans = 0;
	ll at = x[0];
	
	for(ll i = 1; i <= n-1; i++){
		ans += min(a*(x[i]-x[i-1]), b);
	}
	
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1024
#include<iostream>
#include<queue>
#include<string>
#include<algorithm>
#include<vector>
#include<map>
#include<cmath>
#include<functional>
#include<set>
using namespace std;
#define int long long
const long long inf = 1ll << 48;
typedef pair<int, int> P;
int n, m;
struct edge {int from,to, cost;};
edge es[2005];
int d[1005],df[1005];
int flg = 1;
void bell(int s) {
	fill(d, d + n, inf);
	d[s] = 0;
	while (1) {
		bool upd = false;
		for (int i = 0; i < m; i++) {
			edge e = es[i];
			if (d[e.from] != inf&&d[e.to] > d[e.from] + e.cost) {
				d[e.to] = d[e.from] + e.cost;
				upd = true;
			}
		}
		if (!upd)break;
	}
}

bool findloop(int s,int t) {
	fill(df, df + n, inf);
	df[s] = 0;
	for (int i = 0; i < 2*n; i++) {
		for (int j = 0; j < m; j++) {
			edge e = es[j];
			if (df[e.from] != inf&&df[e.to] > df[e.from] + e.cost) {
				df[e.to] = df[e.from] + e.cost;

				if (i >=n-1&&e.to==t)return true;
			}
		}
	}
	return false;
}

signed main() {
	cin >> n >> m;
	for (int i = 0; i < m; i++) {
		int a, b, c;
		cin >> a >> b >> c;
		a--;
		b--;
		es[i] = { a,b,-c };
	}
	if (findloop(0,n-1))cout << "inf" << endl;	
	else {
		findloop(0, n - 1);
		cout << -df[n - 1] << endl;
	}
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cassert>
using namespace std;
inline int read(){
	int re=0,flag=1;char ch=getchar();
	while(!isdigit(ch)){
		if(ch=='-') flag=-1;
		ch=getchar();
	}
	while(isdigit(ch)) re=(re<<1)+(re<<3)+ch-'0',ch=getchar();
	return re*flag;
}
int n,m,a[310][310],ban[310],cnt[310],cur[310];
bool check(int lim){
	int i;
	memset(ban,0,sizeof(ban));
	for(i=1;i<=n;i++) cur[i]=1;
	while(1){
		bool flag=1;
		memset(cnt,0,sizeof(cnt));
		for(i=1;i<=n;i++){
			while(cur[i]<=m&&ban[a[i][cur[i]]]) cur[i]++;
			cnt[a[i][cur[i]]]++;
//			cout<<"check "<<i<<' '<<cur[i]<<' '<<a[i][cur[i]]<<' '<<cnt[a[i][cur[i]]]<<'\n';
			if(cnt[a[i][cur[i]]]>lim) ban[a[i][cur[i]]]=1,flag=0;
			if(cur[i]>m) return 0;
		}
		if(flag) return 1;
	}
	return 0;
}

		
int main(){
	n=read();m=read();int i,j,l,r,mid;
	for(i=1;i<=n;i++){
		for(j=1;j<=m;j++) a[i][j]=read();
	}
	l=1;r=n;
	while(l<r){
		mid=(l+r)>>1;
//		cout<<"binary "<<mid<<'\n';
		if(check(mid)) r=mid;
		else l=mid+1;
	}
	printf("%d\n",l);
}


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

using namespace std;

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

int main(){
    int w,h;
    while(cin >> w >> h){
        if((w|h) == 0) break;
        string str;
        int n;
        int dir = 1;
        int x = 1;
        int y = 1;
        while(cin >> str){
            if(str == "STOP"){
                break;
            }else if(str == "RIGHT"){
                dir--;
                if(dir == -1) dir = 3;
            }else if(str == "LEFT"){
                dir++;
                if(dir == 4) dir = 0;
            }else{
                if(str == "FORWARD"){
                    cin >> n;
                }else{
                    cin >> n;
                    n *= -1;
                }
                x += dx[dir] * n;
                y += dy[dir] * n;
                if(x < 1) x = 1;
                if(x > w) x = w;
                if(y < 1) y = 1;
                if(y > h) y = h;
            }
        }
        cout << x << " " << y << endl;
    }
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
#define STIZE(x) fprintf(stderr, "STIZE%d\n", x);
#define PRINT(x) fprintf(stderr, "%s = %d\n", #x, x);
#define NL(x) printf("%c", " \n"[(x)]);
#define lld long long
#define pii pair<int,int>
#define pb push_back
#define fi first
#define se second
#define mid (l+r)/2
#define endl '\n'
#define all(a) begin(a),end(a)
#define sz(a) int((a).size())
#define LINF 1000000000000000LL
#define INF 1000000000
#define EPS 1e-9
using namespace std;


int main() {
    ios::sync_with_stdio(false);cin.tie(0);
    int N, K; cin >> N >> K;
    if(K > (N+1)/2) cout << "NO";
    else cout << "YES";
    return 0;
}


Measured memory_bytes: 892
/*
    author: Salam_35
    Created at :

*/

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

#define ll long long int
#define pb push_back
#define sc(n) scanf("%d",&n)
#define Max 100005
#define scan(n) scanf("%lld",&n)
#define pi acos(-1.0)
#define _fastio  ios_base:: sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define ALL(x) x.begin(),x.end()
#define sci(n) scanf("%d",&n);
#define scl(n) scanf("%lld",&n);
#define load(array,size)  for(ll i=0 ; i<size ; i++) cin>>array[i] ;
#define load1(array,size)  for(ll i=1 ; i<=size ; i++) cin>>array[i] ;
#define INF	1LL<<19
#define pll pair<ll,ll>
#define mst(arr,value) memset(arr,value,sizeof(arr));
#define tst() int t;cin >> t;while(t--)
#define Mod 100000007
#define YES cout<<"Yes"<<endl;
#define NO cout<<"No"<<endl;
void inversemod(ll n, ll mod, ll invmod[],ll MOD){for(int i=2; i<=n; ++i) invmod[i]=MOD-MOD/i*invmod[MOD%i]%MOD;}
//void bigmod( ll a, ll b ,ll mod){ll r = 1;a = a%mod;while(b){if( b%2 ) r = (r*a)%mod;b = b/2;a = (a*a)%mod; }return (ll)r;}

typedef vector<ll>vec;
typedef pair<ll,ll> pii;
typedef map<ll,ll>mpll;
typedef set<ll>seet;

int main()
{
    double n,m,h;
    string s;
    cin>> n;
    cout<<setprecision(15)<<fixed<<2*pi*n<<endl;
}


Measured memory_bytes: 3824
using System;
using System.Collections.Generic;

class program
{
    public static void Main()
    {

        List<char> rlist = new List<char>();
        while (true)
        {
            var strs = Console.ReadLine().Split(' ');

            var m = int.Parse(strs[0]);
            var f = int.Parse(strs[1]);
            var r = int.Parse(strs[2]);

            if (m + f + r == -3) break;

            if (m < 0 || f < 0)
            {
                rlist.Add('F');
            }
            else if (m + f >= 80)
            {
                rlist.Add('A');
            }
            else if (m + f >= 65)
            {
                rlist.Add('B');
            }
            else if (m + f >= 50)
            {
                rlist.Add('C');
            }
            else if (r >= 50)
            {
                rlist.Add('C');
            }
            else if (m + f >= 30)
            {
                rlist.Add('D');
            }
            else
            {
                rlist.Add('F');
            }
        }

        foreach(var rank in rlist){
            Console.WriteLine(rank);
        }
    }
}

Measured memory_bytes: 5364
let rec gcd n m =
  if m = 0 then n
  else gcd m (n mod m)

let () = Scanf.scanf "%d\n" @@ fun n ->
  let as_ = Array.init n @@ fun _ -> Scanf.scanf "%d " @@ fun a -> a in
  print_endline @@
  if Array.fold_left gcd 0 as_ <> 1
  then "not coprime"
  else if
    let b = ref true in
    let as__ = Array.make 1000001 0 in
    let prim = Array.make 1000001 true in
    Array.iter (fun a -> as__.(a) <- 1 + as__.(a)) as_;
    for p = 2 to 1000000 do
      if prim.(p) then begin
        let rec iter acc i =
          if 1000000 < i
          then acc
          else (prim.(i) <- false; iter (acc + as__.(i)) (i + p)) in
        b := !b && iter 0 p <= 1
      end
    done;
    not !b
  then "setwise coprime"
  else "pairwise coprime"


Measured memory_bytes: 29596
#include <iostream>
#include <string>
#include <bits/stdc++.h>
using namespace std;
typedef vector<int> vi;
typedef long long LL;


LL solve(vi &v) {
    LL count_1 = 0, ans = 0;
    for (int i = v.size() - 1; i >= 0; i--) {
        if (v[i] == 1) {
            ++count_1;
        } else {
            ans += count_1;
        }
    }
    
    //for (auto x : v) cout << x << " ";
    //cout << ":" << ans << endl;

    return ans;
}


int main()
{
    string s; cin >> s;
    LL ans = 0;

    vector<int> v;
    for (int i = 0; i < s.size(); ++i) {
        if (s.substr(i, 1) == "A") {
            v.push_back(0);
        } else if (s.substr(i, 2) == "BC") {
            ++i;
            v.push_back(1);
        } else {
            ans += solve(v);
            v = vector<int>();
        }
    }
    ans += solve(v);

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


Measured memory_bytes: 1532
#include<stdio.h>

int dfs(int s,int i,int depth){
	int j,res=0;
	if(s==0)return 1;
	if(depth==4)return 0;
	for(;i*i<=s;i++){
		res += dfs(s-i*i,i,depth+1);
	}
	return res;
}
int main(){
	int n;
	while(scanf("%d",&n),n){
		printf("%d\n",dfs(n,1,0));
	}
	return 0;
}

Measured memory_bytes: 600