akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <fstream>
#include <algorithm>
#include <cassert>
#include <cctype>
#include <cmath>
#include <complex>
#include <cstdio>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;

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

int n,m,s,g1,g2,d[101][101];

int main(){
	while(cin>>n>>m>>s>>g1>>g2&&n){
		rep(i,n+1)fill(d[i],d[i]+n+1,INF);
		rep(i,n+1)d[i][i]=0;
		int f,t,c,ans=INF;
		rep(i,m){
			cin>>f>>t>>c;
			d[f][t]=c;
		}
		rep(i,n+1)rep(j,n+1)rep(k,n+1)d[j][k]=min(d[j][k],d[j][i]+d[i][k]);
		rep(i,n+1)ans=min(ans,d[s][i]+d[i][g1]+d[i][g2]);
		cout<<ans<<endl;
	}
}

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

int main() {
	int n;
	scanf("%d", &n);
	vector<int> ar(n);
	for(int i = 0;i < n;i++) scanf("%d", &ar[i]);
	sort(ar.begin(), ar.end());
	int ans = 0;
	for(int i = 0;i < n;i++){
		for(int j = i + 1;j < n;j++){
			if(ar[i] == ar[j]) continue;
			int m = ar[i] + ar[j], num = 0;
			int k = j + 1;
			while(k < n && ar[k] < m){
				if(ar[j] == ar[k]){k++;continue;}
				num++;
				k++;
			}
			ans += num;
		}
	}
	printf("%d\n", ans);
	return 0;
}
//ios_base::sync_with_stdio(false);
//cin.tie(0);
//tod-ngen


Measured memory_bytes: 3792
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int a,b,w,d,c,z,v=0;
	cin>>w>>a>>b;
	d=w+b;
	c=w+a;
	if(a>=b&&c>=d&&d>=a)
	{
		
		cout<<v;
	}
	else if(a>=b&&d>=c&&c>=a)
	{
		
		cout<<v;
	}
	else if(b>=a&&d>=c&&c>=b)
	{
		
		cout<<v;
	}
	else if(b>=a&&c>=b&&d>=b)
	{
		
		cout<<v;
	}
	else
	{
		if(b>c)
		{
			v=b-c;
			cout<<v;
		}
		else if(a>=d)
		{
			v=a-d;
			cout<<v;
		}
	}
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

#define MAXN  3001

typedef struct DP {
  int l;
  int x, y;
} DP;

DP S[MAXN+1][MAXN+1];

char X[MAXN+1], Y[MAXN+1], ans[MAXN];

void lcs ( char X[], char Y[], int x, int y)
{
  int i,j,tmp1,tmp2;

  for ( i = 0; i <= x; i++ ) S[i][0].l = 0;
  for ( i = 0; i <= y; i++ ) S[0][i].l = 0;

  for ( i = 1; i <= x; i++ ) {
    for ( j = 1; j <= y; j++ ) {
      if ( X[i-1] == Y[j-1] ) {
        S[i][j].l = S[i-1][j-1].l+1;
        S[i][j].x = i-1, S[i][j].y = j-1;
      } else {
        tmp1 = S[i-1][j].l, tmp2 = S[i][j-1].l;
        if ( tmp1 > tmp2 ) S[i][j].l = tmp1, S[i][j].x = i-1, S[i][j].y = j;
        else S[i][j].l = tmp2, S[i][j].x = i, S[i][j].y = j-1;
      }
    }
  }

}

int reconstruction( int x, int y, char ans[], char X[] ) // 反対になって配列に格納される
{
  int tmpx, tmpy, xx, yy;
  int pos;

  pos = 0;

  while ( S[x][y].l > 0 ) {
    tmpx = x, tmpy = y;
    x = S[tmpx][tmpy].x;
    y = S[tmpx][tmpy].y;

    if ( S[x][y].l < S[tmpx][tmpy].l ) {
      ans[pos] = X[tmpx-1];
      pos++;
    }
  }

  return pos;
}

int sl ( char S[] )
{
  int i;

  for ( i  = 0; S[i] != '\0'; i++ ) ;

  return i;
}

int main(void)
{
  int x, y, i,ansl;

  scanf("%s",X);
  scanf("%s",Y);

  x = sl(X); y = sl(Y);
  
  lcs(X,Y,x,y);
  ansl = reconstruction(x,y,ans,X);

  for ( i = ansl-1; i >= 0; i-- ) printf("%c", ans[i]); printf("\n");

  return 0;
}


Measured memory_bytes: 105856
require "openssl"

N, M = gets.split.map(&:to_i).sort
Q = (10 ** 9) + 7
if (N - M).abs > 1
  puts 0
  exit
end

def f(n)
  t = 1.to_bn
 (1..n).inject(t) { |r,i| r.mod_mul(i, Q) }
end

begin
  r = f(N)
  if N == M
    ans = r.mod_mul(r, Q).mod_mul(2, Q)
  else
    ans = r.mod_mul(r.mod_mul(M, Q), Q)
  end
  raise RuntimeError if ans.zero?
  puts ans
rescue
  retry
end


Measured memory_bytes: 3452
#include <algorithm>
#include <bitset>
#include <cmath>
#include <iostream>
#include <iomanip>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stdio.h>
#include <string>
#include <vector>

#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;
using LP = pair<ll, ll>;
const double PI = 3.1415926535897932;

int main()
{
	int N;
	cin >> N;
	vector<ll> L(N, 0);
	rep(i, N) cin >> L[i];

	int ans = 0;
	for (int i = 0; i < N; ++i) {
		for (int j = i + 1; j < N; ++j) {
			for (int k = j + 1; k < N; ++k) {
				if (L[i] != L[j] && L[i] != L[k] && L[j] != L[k]) {
					ll sum = L[i] + L[j] + L[k];
					ll lmax = max(L[i], L[j]);
					lmax = max(lmax, L[k]);
					if (sum > lmax * 2) ans += 1;
				}
			}
		}
	}

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


Measured memory_bytes: 3628
#include<cstdio>
#include<iostream>
using namespace std;
int a,sum,ans;
int main()
{
	for(int i=1;i<=3;i++)
	{
		scanf("%d",&a);
		if(a==5)
		sum++;
		if(a==7)
		ans++;
	}
	if(ans==1&&sum==2)
	cout<<"YES"<<endl;
	else cout<<"NO"<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fastIO (cin.tie(0), cout.tie(0), ios::sync_with_stdio(false))
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define precise(i) fixed << setprecision(i)
using lint = long;
using llint = long long;
using namespace std;

int main() {
    fastIO;
    string s;
    cin >> s;
    if (s[0] == 'R' && s[1] == 'S' && s[2] == 'R') {
        cout << 1 << endl;
    } else {
        int cnt = 0;
        for (auto ch : s)
            if (ch == 'R')
                cnt++;
        cout << cnt << endl;
    }
}


Measured memory_bytes: 3604
import java.util.Scanner;


public class Main 
{
	final static String FES = "FESTIVAL";
	public static void main(String[] args) 
	{
		Scanner sc = new Scanner(System.in);
		String S = sc.next();
		String fes_name="";
		sc.close();
		for(int i=0,fes_len = Main.FES.length() ;i<S.length()-fes_len;i++)
		{
			fes_name += S.charAt(i);
		}

		System.out.println(fes_name);
		
	}

}


Measured memory_bytes: 21716
import java.awt.List;
import java.util.ArrayList;
import java.util.Collections;
import java.util.LinkedList;
import java.util.Scanner;
import java.lang.*;
public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Problem ThanhYeuThu = new Problem();
		ThanhYeuThu.solve();
	}
	static class Problem {
		public void solve() {
			Scanner sc = new Scanner(System.in);
			int n = sc.nextInt();
			int m = sc.nextInt();
			String c[] = new String[n];
			for (int i = 0; i < n; i++) c[i] = sc.next();
			int DP[][] = new int[n][m];
			int module = (int)1e9 + 7;
			if (c[0].charAt(0) == '#') {
				System.out.print(0);
				System.exit(0);
			}
			DP[0][0] = 1;
			for (int i = 1; i < m; i++) {
				if (c[0].charAt(i) == '#') break;
				DP[0][i] = 1;
			}
			for (int i = 1; i < n; i++) {
				if (c[i].charAt(0) == '#') break;
				DP[i][0] = 1;
			}
			for (int i = 1; i < n; i++) {
				for (int j = 1; j < m; j++) {
					if (c[i].charAt(j) == '#') {
						DP[i][j] = 0;
						continue;
					}
					DP[i][j] = DP[i - 1][j] + DP[i][j - 1];
					if (DP[i][j] >= module) DP[i][j] -= module;
				}
			}
			System.out.print(DP[n - 1][m - 1]);
		}
	}

}


Measured memory_bytes: 33092
#include<cstdio>
const int N=400002;
int n,m,c[N],vis[N],i,k,l,r,sum,ok;
int h[N],t[N],v[N],a,b;
char s[N];
void add(int a,int b){
	t[++k]=h[a];
	h[a]=k;
	v[k]=b;
}
void init(){
	scanf("%s",s+1);
	while(s[n+1])n++;
	for(i=1;i<=n+1;i++)
		c[i]=s[i]-s[i-1];
	for(l=1,r=n+1;l<r;l++,r--){
		add(l,r);
		add(r,l);
	}
	scanf("%d",&m);
	while(m--){
		scanf("%d%d",&a,&b);
		add(a,b+1);
		add(b+1,a);
	}
}
void dfs(int i){
	vis[i]=1;
	sum+=c[i];
	for(int j=h[i];j;j=t[j])
		if(!vis[v[j]])
			dfs(v[j]);
}
void work(){
	dfs(n+1);
	ok=1;
	for(i=1;i<=n;i++)
		if(!vis[i]){
			sum=0;
			dfs(i);
			if(sum%26!=0)
				ok=0;
		}
	printf("%s\n",ok?"YES":"NO");
}
int main(){
	init();
	work();
	return 0;
}

Measured memory_bytes: 8448
#pragma GCC optimize ("Ofast")
#pragma GCC target ("sse4")

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

// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
// using namespace __gnu_pbds;
// template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;

typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define pf push_front
#define lb lower_bound
#define ub upper_bound
#define all(x) begin(x), end(x)
#define sz(x) (int) x.size()

#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define F0R(i,a) FOR(i,0,a)
#define ROF(i,a,b) for (int i = (b)-1; i >= (a); --i)
#define R0F(i,a) ROF(i,0,a)
#define trav(a,x) for (auto& a: x)

const int MOD = 1e9+7; // 998244353;
const int MX = 2e5+5;
const ll INF = 1e18;
const ld PI = acos((ld)-1);
const ld EPS = 1e-6;
const int dx[4] = {1,0,-1,0}, dy[4] = {0,1,0,-1};
const char nl = '\n';

template <typename T> inline T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
template <typename T> inline T lcm(T a, T b) { return a / gcd(a, b) * b; }
template <class T> void ckmin(T& a, T b) { a = min(a, b); }
template <class T> void ckmax(T& a, T b) { a = max(a, b); }

// (Integer/Long).bitCount(x)
int pct(int x) { return __builtin_popcount(x); }
int pctll(ll x) { return __builtin_popcountll(x); }

void setIn(string s) { freopen(s.c_str(),"r",stdin); }
void setOut(string s) { freopen(s.c_str(),"w",stdout); }
void unsyncIO() { ios_base::sync_with_stdio(0); cin.tie(0); }
void setIO(string s = "") {
	unsyncIO();
	if (sz(s)) { setIn(s+".in"), setOut(s+".out"); }
}

// Binary Exponentiation
ll pow(ll b, ll e, ll m = 0LL, ll ans = 1LL) { while (e) { if (e & 1LL) { ans *= b; if (m) ans %= m; } b *= b, e >>= 1LL; if (m) b %= m; } return ans; }



void solve(int tcn) {
	int n;
	cin >> n;
	vector<pii> a(n);
	vector<bool> b(n);
	bool works = false;
	F0R(i, n) {
		cin >> a[i].fi >> a[i].se;
		if (a[i].fi == a[i].se) {
			b[i] = true;
		}
		if (i >= 2) {
			works |= b[i] && b[i-1] && b[i-2];
		}
	}
	cout << (works ? "Yes" : "No") << nl;
}

int main() {
    setIO();

    int t = 1; //cin >> t;
	for (int i = 1; i <= t; ++i) {
		//cout << "Case #" << i << ": ";
		solve(i);
	}
	return 0;
}

Measured memory_bytes: 3640
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>

using namespace std;
const int MAX = 10005;
struct node {
    int p, l, r;
};
node T[MAX];
int D[MAX];
int H[MAX];
int setHeight(int);
void setDepth(int, int);
int main()
{
    int t, id, head, temp1, temp2;
    scanf("%d", &t);
    for(int i = 0; i < t; i++) {
        T[i].p = -1;
    }
    for(int i = 0; i < t; i++) {
        scanf("%d %d %d", &id, &temp1, &temp2);
        T[temp1].p = id, T[temp2].p = id;
        T[id].l = temp1, T[id].r = temp2;
    }
    for(int i = 0; i < t; i++) {
        if(T[i].p == -1) head = i;
    }
    setHeight(head);
    setDepth(head, 0);
    for(int i = 0; i < t; i++) {
        int de = 0, temp3;
        if(i == head) temp3 = -1;
        else if(T[T[i].p].l == i) temp3 = T[T[i].p].r;
        else temp3 = T[T[i].p].l;
        printf("node %d: parent = %d, ", i, T[i].p);
        if(T[i].l != -1) de++;
        if(T[i].r != -1) de++;
        printf("sibling = %d, degree = %d, depth = %d, height = %d, ", temp3, de, D[i], H[i]);
        if(i == head) printf("root\n");
        else if(!de) printf("leaf\n");
        else printf("internal node\n");
    }
    return 0;
}
int setHeight(int u) {
    int h1, h2;
    h1 = 0, h2 = 0;
    if(T[u].r != -1) h1 = setHeight(T[u].r) + 1;
    if(T[u].l != -1) h2 = setHeight(T[u].l) + 1;
    return H[u] = max(h1, h2);
}
void setDepth(int u, int d) {
    if(u == -1) return;
    D[u] = d;
    setDepth(T[u].l, d+1);
    setDepth(T[u].r, d+1);
}



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

typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pdd;
typedef vector<ll> vll;
typedef vector<ld> vld;
typedef vector<pll> vpl;
typedef vector<vll> vvll;

#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define FI first
#define SE second
#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 FOR(i,a,b) for(int i=(a);i<(b);i++)
#define PB push_back
#define EB emplace_back
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define yes cout<<"Yes"<<endl
#define YES cout<<"YES"<<endl
#define no cout<<"No"<<endl
#define NO cout<<"NO"<<endl
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL

const int inf = 1e9;
const ll linf = 1LL << 50;
const double eps = 1e-10;
const int MOD = 1e9 + 7;
const int dx[4] = {-1, 0, 1, 0};
const int dy[4] = {0, -1, 0, 1};

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

  ll n,m;
  cin>>n>>m;
  vector<vpl> edge(n);
  vvll from(n);
  REP(i,m){
    ll a,b,c;
    cin>>a>>b>>c;
    a--;
    b--;
    edge[a].push_back(pll(b,-c));
    from[b].push_back(a);
  }

  vll dist(n,LLINF);
  dist[0]=0;
  REP(i,n){
    for(ll v=0; v<n; v++){
      if(dist[v]==LLINF)
        continue;
      for(auto e:edge[v]){
        ll next=e.FI;
        ll cost=e.SE;
        if(dist[v]+cost<dist[next])
          dist[next]=dist[v]+cost;
      }
    }
  }

  REP(i,n){
    for(ll v=0; v<n; v++){
      if(dist[v]==LLINF)
        continue;
      for(auto e:edge[v]){
        ll next=e.FI;
        ll cost=e.SE;
        if(dist[v]+cost<dist[next])
          dist[next]=-LLINF;
      }
    }
  }

  if(dist[n-1]==-LLINF)
    cout<<"inf"<<endl;
  else
    cout<<-dist[n-1]<<endl;



}



Measured memory_bytes: 384
#include<iostream>
#include<string>
#include <vector>
#include <algorithm>
#define abs(a) ((a) < 0 ? - (a) : (a))
using namespace std;
int main() {
  int n;
  cin >> n;
  
  vector<int> p, copy;
  for (int i = 1; i <= n; i++) {
    int pi;
    cin >> pi;
    p.push_back(pi);
    copy.push_back(pi);
  }
  
  sort(p.begin(), p.end());
  int count = 0;
  for (int i = 1; i <= n; i++) {
    if (p[i-1] != copy[i-1])
      count++;
  }
  
  if (count == 0 || count == 2)
    cout << "YES" << endl;
  else
    cout << "NO" << endl;
  
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
int main(int argc, char const *argv[])
{
    string s;
    cin >> s;
    cout << (s.length() - abs(count(cbegin(s), cend(s), '0') - count(cbegin(s), cend(s), '1')));

    return 0;
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
#include <iomanip>
#include <iostream>
using namespace std;
using ll = long long;
const long long INF = 1LL << 60;
 
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;
}
 
ll min(ll a, ll b){
    if(a < b) return a;
    else return b;
}
 
int main(void){
    int N; cin >> N;
    int T,A; cin >> T >> A;
    vector<int> H(N,0); for(int i = 0; i < N; i++) cin >> H[i];
    
    pair<float, int> ans_pair;
    ans_pair.first = 9999999;
    for(int i = 0; i < N; i++){
        float substract = abs(A - (T - H[i] * 0.006));
        if(substract < ans_pair.first){
            ans_pair.first = substract;
            ans_pair.second = i + 1;
        }
    }
    cout << ans_pair.second << endl;
}

Measured memory_bytes: 256
from collections import deque


def F(x, p, q):
    return x * p + q


def check(f1, f2, f3):
    a1, b1 = f1
    a2, b2 = f2
    a3, b3 = f3
    return (a2 - a1) * (b3 - b2) >= (b2 - b1) * (a3 - a2)


def main():
    N, C = map(int, input().split())
    H = list(map(int, input().split()))

    dp = 0
    line = deque()
    line.append((-2 * H[0], H[0] ** 2))
    i = 0

    for h in H[1:]:
        while i + 1 < len(line) and F(h, *line[i]) >= F(h, *line[i + 1]):
            i += 1
        dp = h ** 2 + C + F(h, *line[i])

        p = -2 * h
        q = h ** 2 + dp
        while len(line) >= 2 and check(line[-2], line[-1], (p, q)):
            line.pop()
        line.append((p, q))

    print(dp)


if __name__ == "__main__":
    main()

Measured memory_bytes: 48700
#include <iostream>

using namespace std;
#define MAX 100

int bingo[3][3];
int b[MAX];

int main(void){
  int N;
  for(int i=0;i<3;i++){
    for(int j=0;j<3;j++){
      int Aij;
      cin >> Aij;
      bingo[i][j] = Aij;
    }
  }
  cin >> N;
  for(int i=0;i<N;i++){
    int bi;
    cin >> bi;
    b[i] = bi;
  }
  for(int n=0;n<N;n++){
    int num = b[n];
    //番号を探す
    for(int i=0;i<3;i++){
      for(int j=0;j<3;j++){
	if(num == bingo[i][j])
	  bingo[i][j] = -1;
      }
    }
  }
  // たて
  for(int i=0;i<3;i++){
    bool tmpflag = true;
    for(int j=0;j<3;j++){
      if(bingo[i][j] != -1)
	tmpflag = false;
    }
    if(tmpflag){
      cout << "Yes" << endl;
      return 0;
    }
  }
  // よこ
  for(int j=0;j<3;j++){
    bool tmpflag = true;
    for(int i=0;i<3;i++){
      if(bingo[i][j] != -1)
	tmpflag = false;
    }
    if(tmpflag){
      cout << "Yes" << endl;
      return 0;
    }
  }
  //　ななめ
  bool tmpflag = true;
  for(int i=0;i<3;i++){
    if(bingo[i][i] != -1)
      tmpflag = false;
  }

  if(tmpflag){
      cout << "Yes" << endl;
      return 0;
  }
  //もうひとつ
  tmpflag = true;
  for(int i=0;i<3;i++){
    if(bingo[2-i][i] != -1)
      tmpflag = false;
  }

  if(tmpflag){
      cout << "Yes" << endl;
      return 0;
  }

  cout << "No" << endl;
  return 0;
  
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
#define ll long long
#define rep2(i,a,b) for(int i=a;i<=b;++i)
#define rep(i,n) for(int i=0;i<n;i++)
#define pii pair<int,int>
#define tii tuple<int,int,int>
#define pq priority_queue<int>
#define pqg priority_queue<int,vector<int>,greater<int>>
#define pb push_back
#define edge(v,a,b) v[a].pb(b);v[b].pb(a);
ll int MOD=1e9+7;
#define INF 2*1e9
#define N 310000 
using namespace std;
string alphabet("abcdefghijklmnopqrstuvwxyz");

ll int gcd(ll a,ll b){
    if(a==0) return b;
    if(a>b) return gcd(b,a);
    return gcd(b%a,a);
}
main(){
    int n;
    cin>>n;
    string s;
    cin>>s;
    ll ans=0;
    rep(i,1<<n){
        char r[40]={};
        int pr=0,pb=n-1;
        rep(j,n){
            if(i&(1<<j)) {
                r[pr]=s[j];pr++;
            }
            else {r[pb]=s[j];pb--;}
        }
        ll dp[100][100]={};
        dp[n-1][pr-1]=1;
        rep2(j,n,2*n-1){
            rep2(k,pr-1,n){
                if(s[j]==r[k+1]) dp[j][k+1]+=dp[j-1][k];
                if(n-j+k>=0) if(s[j]==r[n-j+k]) dp[j][k]+=dp[j-1][k];
            }
        }
        ans+=dp[2*n-1][n-1];
    }
    cout<<ans;
}



Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int n;
  cin >> n;
  int a[n];
  for (int i=0; i < n; i++) {
    cin >> a[i];
  }
  int dp[n];
  dp[0]=0,dp[1]=abs(a[1]-a[0]);
  for (int i=2; i < n; i++) {
    dp[i]=min(dp[i-1]+abs(a[i]-a[i-1]),dp[i-2]+abs(a[i]-a[i-2]));
  }
  cout << dp[n-1];
}

Measured memory_bytes: 1024
#include <iostream>

int main(){
    int array[32] = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
    int k;
    std::cin >> k;
    std::cout << array[k-1] << std::endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define LL long long
using namespace std;
map<LL,LL>Map;
LL N,M,Sum,Ans;
int main(){
    LL I,J,K;
    scanf("%lld%lld",&N,&M);
    Map[0]++;
    for(I=1;I<=N;I++){
        LL Num;
        scanf("%lld",&Num);
        Sum=(Num+Sum)%M;Ans+=Map[Sum]++;
    } 
    printf("%lld",Ans);
    return 0;
}

Measured memory_bytes: 4224
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define itn int
#define INF (1<<29)
#define rep(i,n) for(int i=0;i<(n);i++)
int gcd(int a,int b){
	if(b==0)return a;
	return gcd(b,a%b);
}
int lcm(int a,int b){
	return a/gcd(a,b)*b;
}
bool prime(int p){
	for(int i=2;i<=sqrt(p);i++){
		if(!p%i)return false;
	}
	return true;
}
int n,m,a[100000],x,ans=0;
map<int,int>mp;
signed main(){
	cin>>n>>m>>x;
	a[0]=x%m;
	mp[0]=1;
	for(int i=1;i<n;i++){
		cin>>x;
		a[i]=(a[i-1]+x)%m;
	}
	sort(a,a+n);
	for(int i=0;i<n;i++){
		ans+=mp[a[i]];
		mp[a[i]]++;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 4992
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	static int count ;
	static String type;	
	static int [] by;
	static char[] right = {'y','u','i','o','p','h','j','k','l','n','m'};
	static char[] left = {'q','w','e','r','t','a','s','d','f','g','z','x','c','v','b'};
	
	static void lr(String type) {
		by = new int[type.length()+1];
		by[0] = 0;
		for(int i=1;i<=type.length();i++) {
			int r = Arrays.binarySearch(right, type.charAt(i-1));
			int l = Arrays.binarySearch(left, type.charAt(i-1));	
			if(r>=0) by[i] = 1;
			if(l>=0) by[i] = 2;
		}
	}
	
    public static void main(String[] args) {
    	Scanner sc = new Scanner(System.in);
    	Arrays.sort(right);
    	Arrays.sort(left);
    	while(true) {
    		type = sc.nextLine();
    		if(type.equals("#")) break;
    		count = -1;
    		lr(type);
    		/*for(int i=0;i<=type.length();i++) {
    			System.err.print(by[i]+" ");
    		}*/
    		//System.err.println();
    		for(int i=1;i<=type.length();i++) {
    			if(by[i]!=by[i-1]) count++;
    		}
    		System.out.println(count);
    	}
    }
}



Measured memory_bytes: 27412
N = int(input())
for k in range(N+2):
    if k * (k-1) == 2 * N:
        S = [[] for _ in range(k+1)]
        n = 1
        for i in range(2, k+1):
            for j in range(1, i):
                S[i].append(n)
                S[j].append(n)
                n += 1
        print('Yes')
        print(k)
        for i in range(1, k+1):
            ans = [len(S[i])] + S[i]
            print(' '.join(map(str, ans)))
        exit()
print('No')

Measured memory_bytes: 44012
#include<iostream>
#include<sstream>
#include<fstream>
#include<string>
#include<vector>
#include<deque>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<algorithm>
#include<functional>
#include<utility>
#include<bitset>
#include<cmath>
#include<cstdlib>
#include<ctime>
#include<cstdio>

using namespace std;

#define REP(i,n) for(int i=0;i<int(n);i++)
#define foreach(c,itr) for(__typeof((c).begin()) itr=(c).begin();itr!=(c).end();itr++)
typedef long long ll;
typedef pair<int,int> P;

int c[10];

int main(void){
	          int i;

	          int n;
	          cin >> n;
	          vector<int> v(n);
	          REP(i,n) cin >> v[i];
	          sort(v.begin(),v.end());

	          cout << v[n-1]-v[0] << 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;
typedef long long ll;

int main() {
  int n; cin >> n;
  vector<int> v(n);
  rep(i,n) cin >> v[i];

  sort(v.begin(),v.end());
  reverse(v.begin(),v.end());

  //rep(i,n) cout << v[i] << " ";

  ll ans = 0;
  ans += v[0];
  for(int i = 1; i<=n/2-1; i++) ans+= v[i]*2;
  if(n%2 == 1) ans+=v[n/2];

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


Measured memory_bytes: 4024
# D - Patisserie ABC

N, M = map(int, input().split())
A = [[] for _ in range(8)]

for i in range(N):
    x, y, z = map(int, input().split())
    A[0].append(x+y+z)
    A[1].append(x+y-z)
    A[2].append(x-y+z)
    A[3].append(x-y-z)
    A[4].append(-x+y+z)
    A[5].append(-x+y-z)
    A[6].append(-x-y+z)
    A[7].append(-x-y-z)

ans = 0
for i in range(8):
    A[i].sort(reverse=True)
    ans = max(ans, sum(A[i][0:M]))
print(ans)


Measured memory_bytes: 9352
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
 
#define mod 1e9+7
#define ll long long int
#define epsilon 1e-7
 
ll min(ll x, ll y){
    if(x < y)return x;
    else return y;
}
 
int main(void){
    int n, ma, mb;
    scanf("%d %d %d", &n, &ma, &mb);
    int ab[n], c[n];
    for(int i = 0;i < n;i++){
        int a, b;
        scanf("%d %d %d", &a, &b, &c[i]);
        ab[i] = b * ma - a * mb;
    }
    int dp[n][8000];
    for(int i = 0;i < n;i++){
        for(int j = 0;j < 8000;j++){
            dp[i][j] = mod;
        }
    }
    dp[0][4000+ab[0]] = c[0];
    for(int i = 1;i < n;i++){
        for(int j = 0;j < 8000;j++){
            if(dp[i-1][j]!=mod || j == 4000){
                dp[i][j] = min(dp[i-1][j], dp[i][j]);
                int plus;
                if(j==4000)plus = c[i];
                else plus = dp[i-1][j] + c[i];
                dp[i][j + ab[i]] = min(dp[i][j + ab[i]], plus);
            }
        }
    }
    if(dp[n-1][4000] != mod)printf("%d\n", dp[n-1][4000]);
    else printf("-1\n");
    return 0;
}

Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std;
bool vis[100002];
vector<int> adj[100002];

void dfs(int node){
    if(vis[node]) return;
    
    vis[node] = true;
    
    for(int v:adj[node]){
        dfs(v);
    }
}

int main() {
	int n,m,x,y;
	cin >> n >> m;
	int cc=0;
	for(int i=1;i<=m;i++){
	    cin >> x >> y;
	    adj[x].push_back(y);
	    adj[y].push_back(x);
	}
	
	for(int i=1;i<=n;i++){
	    if(!vis[i]){
	        cc++;
	        dfs(i);
	    }
	}
	
	cout<<cc-1<<endl;
	return 0;
}

Measured memory_bytes: 9688
#include <iostream>
using namespace std;
int main(void){
    int n,m,num;
    int sum=0;
    cin>>n>>m;
    for(int i=0;i<m;i++){
        cin>>num;
        sum+=num;
    }
    if(n-sum>=0){
        n-=sum;
    }else{
        n=-1;
    }
    cout<<n;
}


Measured memory_bytes: 3632
#include <iostream>
#include <vector>
#include <string>
#include <cmath>

using namespace std;

int main() {
    string in;
    cin >> in;
    vector<bool> tiles;
    for (int i = 0; i < in.length(); i++) {
        if (in[i] == '0') tiles.push_back(false);
        else tiles.push_back(true);
    }

    bool begin0 = false;
    int num_begin0 = 0;
    bool begin1 = true;
    int num_begin1 = 0;
   
    for (int i = 0; i < tiles.size(); i++) {
        if ( tiles[i] ^ begin0 ) num_begin0 += 1;
        if ( tiles[i] ^ begin1 ) num_begin1 += 1;
        begin0 = !begin0;
        begin1 = !begin1;
    }
    cout << min(num_begin0, num_begin1) << endl;
}


Measured memory_bytes: 512
D=0
F=1

class MyGraph
  attr_accessor :timestamp, :vec, :time

  def initialize(n)
    @timestamp = Array.new(n+1).map{Array.new(2,0)}
    @vec = Array.new(n+1,nil)
    @time=0
  end

  def depth_search(n)
    #p "begin:#{n}"
    #p " time:#{@time}"
    #p " timestamp:#{@timestamp}"
    @time+=1
    if @timestamp[n][D]==0
      @timestamp[n][D]=@time
    end
    @vec[n].length.times do |i|
      if @timestamp[@vec[n][i]][D]==0
        self.depth_search(@vec[n][i])
      end
    end unless @vec[n].nil? or @vec[n].empty?
    @time+=1
    @timestamp[n][F]=@time
    #p "end:#{n}"
    #p " time:#{@time}"
    #p " timestamp:#{@timestamp}"
  end

  def print_timestamp
    1.upto(timestamp.length-1) do |i|
      print "#{i} #{@timestamp[i].join(' ')}\n"
    end
  end
end

n = STDIN.gets().to_i

graph = MyGraph.new(n)

n.times do |i|
  u, k, *v = STDIN.gets().split(' ').map{ |i| i.to_i }
  graph.vec[u]=v
end

1.upto(n) do |i|
  graph.depth_search(i) if graph.timestamp[i][D]==0
end

graph.print_timestamp

Measured memory_bytes: 8768
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub

		 Scanner sc = new Scanner(System.in);
	        int n = sc.nextInt();
	        
	        if(n == 1){
	        	System.out.println("Hello World");
	        }else if(n == 2){
	        	
		        int a = sc.nextInt();
		        int b = sc.nextInt();
		        int c = 0;
		        
	        	c = a + b;
	        	System.out.println(c);
	        }
	}
}

Measured memory_bytes: 21844
import java.util.Scanner;

class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		int max = Math.max(Math.max(a+b, a-b), a*b);
		System.out.println(max);
 	}
}

Measured memory_bytes: 21844
#include<stdio.h>
#include <math.h>   
int main(){
 
  int n,sya[1000],cnt;
  
  cnt =0;
  while(scanf("%d",&n)!=EOF){

    if(n==0){
       cnt =cnt-1;
       printf("%d\n", sya[cnt]);
       
    }else{

    sya[cnt]=n;
    cnt=cnt+1;
    }


}   
    return 0;
}

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

#define ll long long

int main(void)
{
    ll in;
    scanf("%lld",&in);
    int h=in/3600;
    int m=(in%3600)/60;
    int sec=in%60;
    printf("%d:%d:%d\n",h,m,sec);
    return 0;
}




Measured memory_bytes: 2116
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#define int long long
using namespace std;

int a, b, n;
int ans = 0;

int calc(int x) {
    return (x * a / b) - a * (x / b);
}

void solve(int l, int r) {
	if(l > r) return ;
	int mid = (l + r) >> 1;
	int tmp = calc(mid);
	if(!mid) solve(l, mid);
	else {
		ans = tmp;
		solve(mid + 1, r);
	}
}

signed main() {
    cin >> a >> b >> n;
	int x = min(b, n);
	int t = x;
	int sq = sqrt(x);
	while(x >= 0 && !calc(x)) x -= sq;
	while(1) {
		if(x >= t) {
			cout << calc(t);
			return 0;
		}
		if(!calc(x + 1)) {
			cout << calc(x);
			return 0;
		}
		++x;
	}
    return 0;
}

Measured memory_bytes: 3568
def main():
	N =int(input())
	A =list(map(int,input().split()))
	if 0 in A:
		print(0)
		return

	prod = 1 
	for a in A:
		prod *= a
		if prod > 1000000000000000000:
			print(-1)
			return

	print(prod)


main()

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

using namespace std;

// using ll = long long;
typedef long long ll;
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define ALL(v) (v).begin(), (v).end()
#define SP cout << fixed << setprecision(10)
typedef pair<ll, int> P;
const int INF = (int)1e9;
const int MOD = (int)1e9 + 7;
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }

int main(void) {
    int a, b;
    cin >> a >> b;
    FOR(c, 1, 4) {
        if (a * b * c % 2 == 1) {
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<vector>
#include<algorithm>
#include<utility>
#include<numeric>
#include<iostream>
#include<array>
#define _USE_MATH_DEFINES

#include<math.h>
#include<unordered_map>

#define min(a,b) (a)>(b)?(b):(a)
#define max(a,b) (a)>(b)?(a):(b)

using namespace std;

int main()
{
	vector<int> m, f, r;

	while (true)
	{
		int tm, tf, tr;

		scanf("%d %d %d", &tm, &tf, &tr);

		if (tm == -1 && tf == -1 && tr == -1)
		{
			break;
		}
		else
		{
			m.push_back(tm);
			f.push_back(tf);
			r.push_back(tr);
		}
	}

	for (int i = 0; i != m.size(); i++)
	{
		if (m[i] == -1 || f[i] == -1)
		{
			printf("F\n");
		}
		else
		{
			int score = m[i] + f[i];
			if (score >= 80)
			{
				printf("A\n");
			}
			else if (score >= 65)
			{
				printf("B\n");
			}
			else if (score >= 50)
			{
				printf("C\n");
			}
			else if (score >= 30)
			{
				if (r[i] >= 50)
				{
					printf("C\n");
				}
				else
				{
					printf("D\n");
				}
			}
			else
			{
				printf("F\n");
			}
		}
	}

	return 0;
}

Measured memory_bytes: 3188
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.IO;

class Iroha
{
    public Iroha() { }
    public static int Main()
    {
        new Iroha().calc();
        return 0;
    }

    Scanner cin;

    void calc()
    {
        cin = new Scanner();
        int N = cin.nextInt();
        int M = cin.nextInt();
        int Q = cin.nextInt();
        int[] L = new int[M];
        int[] R = new int[M];
        for (int i = 0; i < M; i++)
        {
            L[i] = cin.nextInt();
            R[i] = cin.nextInt();
        }
        int[] p = new int[Q];
        int[] q = new int[Q];
        for (int i = 0; i < Q; i++)
        {
            p[i] = cin.nextInt();
            q[i] = cin.nextInt();
        }

        int[,] sum = new int[N + 1, N + 1];
        for (int i = 0; i < M; i++)
        {
            sum[L[i], R[i]]++;
        }
        for (int i = 0; i < N; i++)
        {
            for (int j = 0; j < N; j++)
            {
                sum[i + 1, j + 1] += sum[i + 1, j];
                sum[i + 1, j + 1] += sum[i, j + 1];
                sum[i + 1, j + 1] -= sum[i, j];
            }
        }

        for (int i = 0; i < Q; i++)
        {
            Console.WriteLine(sum[q[i], q[i]] - sum[p[i] - 1, q[i]]);
        }
    }
    


}


class Scanner
{
    string[] s;
    int i;

    char[] cs = new char[] { ' ' };

    public Scanner()
    {
        s = new string[0];
        i = 0;
    }

    public string next()
    {
        if (i < s.Length) return s[i++];
        string st = Console.ReadLine();
        while (st == "") st = Console.ReadLine();
        s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
        if (s.Length == 0) return next();
        i = 0;
        return s[i++];
    }

    public int nextInt()
    {
        return int.Parse(next());
    }
    public int[] ArrayInt(int N, int add = 0)
    {
        int[] Array = new int[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextInt() + add;
        }
        return Array;
    }

    public long nextLong()
    {
        return long.Parse(next());
    }

    public long[] ArrayLong(int N, long add = 0)
    {
        long[] Array = new long[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextLong() + add;
        }
        return Array;
    }

    public double nextDouble()
    {
        return double.Parse(next());
    }


    public double[] ArrayDouble(int N, double add = 0)
    {
        double[] Array = new double[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextDouble() + add;
        }
        return Array;
    }
}

Measured memory_bytes: 18980
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll INF = 1000000000000;

ll N, K;
vector<ll> h;
vector<ll> dp;

void solve() {
  dp.resize(N, INF);
  dp[0] = 0;
  for (int i = 1; i < min(N, K); i++) {
    dp[i] = abs(h[i] - h[0]);
  }

  for (int i = K; i < N; i++) {
    for (int k = 1; k <= K; k++) {
      ll tmp = dp[i - k] + abs(h[i - k] - h[i]);
      dp[i] = min(dp[i], tmp);
    }
  }
  cout << dp[N - 1] << "\n";
}

int main() {
  cin >> N >> K;
  h.resize(N);
  for (int i = 0; i < N; i++) {
    cin >> h[i];
  }
  solve();
  return 0;
}

Measured memory_bytes: 1792
#include "bits/stdc++.h"

using namespace std;
using ll = long long;
const double pi = acos(-1);
#define FOR(i,a,b) for (ll i=(a),__last_##i=(b);i<__last_##i;i++)
#define RFOR(i,a,b) for (ll i=(b)-1,__last_##i=(a);i>=__last_##i;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define __GET_MACRO3(_1, _2, _3, NAME, ...) NAME
#define rep(...) __GET_MACRO3(__VA_ARGS__, FOR, REP)(__VA_ARGS__)
#define rrep(...) __GET_MACRO3(__VA_ARGS__, RFOR, RREP)(__VA_ARGS__)
template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) {
	REP(i, v.size()) { if (i)os << ""; os << v[i]; }return os;
}
template<typename T> ostream& operator<<(ostream& os, const vector<vector<T>>& v) {
	REP(i, v.size()) { if (i)os << endl; os << v[i]; }return os;
}

const ll INF = LLONG_MAX;
ll MOD = 1000000007;
ll _MOD = 1000000009;
double EPS = 1e-10;

#define int long long

inline void my_io() {

	std::ios::sync_with_stdio(false);

	std::cin.tie(0);

	cout << fixed << setprecision(16);

	//cout << setprecision(10) << scientific << ans << endl;
}

signed main() {
	ll n;
	string s;

	cin >> n >> s;

	vector<string> v(n, "");
	pair<string, string> p[4] = { 
		make_pair("S", "S"), 
		make_pair("S", "W"), 
		make_pair("W", "S"), 
		make_pair("W", "W") 
	};


	REP(k, 4) {
		v[0] = p[k].first;
		v[1] = p[k].second;

		FOR(i, 1, n - 1) {
			if (s[i] == 'o') {
				if (v[i] == "S") {
					v[i + 1] = v[i - 1];
				}
				else {
					if (v[i - 1] == "S") {
						v[i + 1] = "W";
					}
					else {
						v[i + 1] = "S";
					}
				}
			}
			else {
				if (v[i] == "S") {
					if (v[i - 1] == "S") {
						v[i + 1] = "W";
					}
					else {
						v[i + 1] = "S";
					}
				}
				else {
					v[i + 1] = v[i - 1];
				}
			}
		}

		bool flag = true;

		if (s[0] == 'o') {
			if (v[0] == "S") {
				if (v[1] != v[n - 1]) {
					flag = false;
				}
			}
			else {
				if (v[1] == v[n - 1]) {
					flag = false;
				}
			}
		}
		else {
			if (v[0] == "S") {
				if (v[1] == v[n - 1]) {
					flag = false;
				}
			}
			else {
				if (v[1] != v[n - 1]) {
					flag = false;
				}
			}
		}

		if (s[n - 1] == 'o') {
			if (v[n - 1] == "S") {
				if (v[0] != v[n - 2]) {
					flag = false;
				}
			}
			else {
				if (v[0] == v[n - 2]) {
					flag = false;
				}
			}
		}
		else {
			if (v[n - 1] == "S") {
				if (v[0] == v[n - 2]) {
					flag = false;
				}
			}
			else {
				if (v[0] != v[n - 2]) {
					flag = false;
				}
			}
		}

		if (flag) {
			cout << v << endl;
			return 0;
		}
	}

	cout << -1 << endl;
}

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

#define endl "\n"
#define all(x) x.begin(),x.end()
#define pb push_back
#define ff first 
#define ss second 
#define pii pair<int,int>
#define vi vector<int>
#define vc vector<char>
#define vii vector<pii>
#define vvi vector<vi>
#define fori(i,n) for(int i=1;i<=n;++i)
#define forn(i,n) for(int i=0;i<n;++i)
#define sz(x) int(x.size())
#define error(x) cout<<#x<<" "<<x<<endl
#define IOS  ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)

const int N=100*1000;
const int mod=1e9+7;

int min3(int a,int b,int c){return min(a,min(b,c));}
int max3(int a,int b,int c){return max(a,max(b,c));}
int min4(int a,int b,int c,int d){return min(min(a,b),min(c,d));}
int max4(int a,int b,int c,int d){return max(max(a,b),max(c,d));}

//#define int int64_t
//int x[N+2];

int32_t  main(){
	IOS;
  int r,d,x;
  cin>>r>>d>>x;
  for(int i=1;i<=10;++i){
    int val=r*x-d;
    cout<<val<<endl;
    x=val;
  }

  return 0;
}



Measured memory_bytes: 256
///Code by: Luis Alejandro
///Handle: Sekai
///Country: Cuba

#include <bits/stdc++.h>
#define endl '\n'
#pragma GCC optimize("Ofast","unroll-loops","omit-frame-pointer","inline")
#pragma GCC option("arch=native","tune=native","no-zero-upper")
#pragma GCC target("avx2")

using namespace std;

typedef unsigned long long ull;
typedef long long lld;
typedef long double ld;
typedef pair<int,int> pii;

const int MAXN=3*1e5+5;
const int MOD=1e9+7;
const int INF=1e9;
const ld PI=acos(-1);
const ld EPS=1e-9;

#define lg2(x) 31-__builtin_clz(x)
#define logx(a,b) (log(a)/log(b))
#define pow2(a) a*a
#define pow3(a) a*a*a
#define lcm(a,b) (a*b)/__gcd(a,b)

pii mkp(int a, int b){
    if(a>b)swap(a,b);
    return make_pair(a,b);
}

int mod_pow(int a, int b){
    if(!b)return 1;
    if(b&1)return mod_pow(a,b-1)*a%MOD;
    int power=mod_pow(a,b>>1);
    return power*power%MOD;
}

int modular_inverse(int a){
    return mod_pow(a,MOD-2);
}

vector<int> movy={0,0,1,-1};
vector<int> movx={1,-1,0,0};

void solve(){
    int h, w, m, y, x;
    cin>>h>>w>>m;
    vector<int> row(h,0), col(w,0);
    map<pii,int> a;
    for(int i=0;i<m;i++){
        cin>>y>>x;
        row[y-1]++;
        col[x-1]++;
        a[{y-1,x-1}]=1;
    }
    int mxr=*max_element(row.begin(),row.end());
    int mxc=*max_element(col.begin(),col.end());
    vector<int> v1, v2;
    for(int i=0;i<h;i++){
        if(row[i]==mxr){
            v1.push_back(i);
        }
    }
    for(int i=0;i<w;i++){
        if(col[i]==mxc){
            v2.push_back(i);
        }
    }
    for(int y:v1){
        for(int x:v2){
            if(a[{y,x}]==0){
                cout<<mxr+mxc<<endl;
                return;
            }
        }
    }
    cout<<mxr+mxc-1<<endl;
    return;
}

int main()
{
    #ifndef ONLINE_JUDGE
        //freopen("IN.txt","r",stdin);
        //freopen("OUT.txt","w",stdout);
    #endif
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    solve();
    return 0;
}

Measured memory_bytes: 28496
#include <stdio.h>
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
#include <functional>
#include <map>
#include <iomanip>
#include <math.h> 
#include <stack>
#include <queue>
#include <bitset>
#include <cstdlib>
#include <tuple>

using namespace std;

int main() {
	int i, j, k;
	string str[3];

	for (i = 0; i < 3; i++) {
		cin >> str[i];
		//transform(str[i].cbegin(), str[i].cend(), str[i].begin(), toupper);
		char ch = (int)str[i][0] - 32;
		cout << ch;
	}

	cout << endl;












	getchar();
	getchar();
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
	int a, b, c;
	
	scanf("%d %d %d", &a, &b, &c);
	
	if((a < b) && (b < c)){
		printf("Yes\n");
	}else{
		printf("No\n");
	}
	
	return 0;
}

Measured memory_bytes: 580
N = int(input())
S = [input() for _ in range(N)]

dic = {}
for s in S:
    dic.setdefault(s, 0)
    dic[s] += 1

dic_sorted = sorted(dic.items(), key=lambda x: (-x[1], x[0]))
max_cnt = dic_sorted[0][1]

for w in dic_sorted:
    if w[1] == max_cnt:
        print(w[0])
    else:
        break


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

typedef long long ll;
typedef pair<int, int> i_i;
typedef pair<ll, ll> l_l;
 
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
//const ll mod = 1000000007;

int h,w;
char a[1001][1001];
int main() {
    cin >> h >> w;
    for (int i=0;i<h;i++) {
        for (int j=0;j<w;j++) {
            cin >> a[i][j];
        }
    }
    
    typedef vector<int> v3; // i,j,cnt
    queue<v3> q;
     for (int i=0;i<h;i++) {
        for (int j=0;j<w;j++) {
           if (a[i][j] == '#') q.push({i,j,0});
        }
    }

    int mx = 0;
    int x,y;
    int dx[4] = {1,-1,0,0};
    int dy[4] = {0,0,1,-1};
    while (!q.empty()) {
        v3 now = q.front(); q.pop();
        x = now[0];
        y = now[1];
        mx = max(mx,now[2]);

        int nx,ny;
        for (int i=0;i<4;i++) {
            nx = x + dx[i];
            ny = y + dy[i];
            if (-1<nx<h && -1<ny<w && a[nx][ny] == '.') {
                q.push({nx,ny,now[2]+1});
                a[nx][ny] = '#';
            }
        }
    }

    cout << mx << endl;
}

Measured memory_bytes: 56628
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#define ll long long
using namespace std;
const int mod=924844033;
const int g=5;
int n,bit,sz[200010];
ll a[524300],b[524300],r[524300],fac[200010],ifac[200010];
int read()
{
	int x=0;char ch=getchar();
	for(;ch<'0'||ch>'9';ch=getchar());
	for(;ch>='0'&&ch<='9';ch=getchar()) x=x*10+ch-'0';
	return x;
}
ll ksm(ll a,int b){ll r=1;for((b+=(mod-1))%=(mod-1);b;b>>=1){if(b&1)r=r*a%mod; a=a*a%mod;}return r;}
struct edge
{
	int t;
	edge *next;
}*con[200010]; 
void ins(int x,int y)
{
	edge *p=new edge;
	p->t=y;
	p->next=con[x];
	con[x]=p;
}
void init()
{
	while((1<<bit)<=(n<<1)) bit++;
	for(int i=0;i<(1<<bit);i++)
		r[i]=(r[i>>1]>>1)|((i&1)<<(bit-1));
//	for(int i=0;i<(1<<bit);i++)
//		cout<<r[i]<<' ';
//	cout<<endl;		
}
void fft(ll *a,int n,int dft)
{
	for(int i=0;i<n;i++)
		if(i<r[i]) swap(a[i],a[r[i]]);
	for(int i=1;i<n;i<<=1)
	{
		ll wn=ksm(g,(mod-1)*dft/(i<<1));
		//cout<<dft<<' '<<wn<<endl;
		for(int j=0;j<n;j+=(i<<1))
		{
			ll wk=1;
			for(int k=j;k<j+i;k++)
			{
				ll x=a[k],y=a[k+i]*wk%mod;
				a[k]=(x+y)%mod;a[k+i]=(x-y+mod)%mod;
				wk=wk*wn%mod;
			}
		}
	}
	if(dft==-1)for(int i=0;i<n;i++) a[i]=a[i]*ksm(n,mod-2)%mod;
}
void dfs(int v,int fa)
{
	sz[v]=1;
	for(edge *p=con[v];p;p=p->next)
		if(p->t!=fa) dfs(p->t,v),sz[v]+=sz[p->t];
	if(fa)a[sz[v]]++,a[n-sz[v]]++;
}
int main()
{
	n=read();
	fac[0]=1;
	for(int i=1;i<=n;i++)
		fac[i]=fac[i-1]*i%mod;
	ifac[n]=ksm(fac[n],mod-2);
	for(int i=n-1;i>=0;i--)
		ifac[i]=ifac[i+1]*(i+1)%mod;
//	for(int i=1;i<=n;i++)
//		cout<<fac[i]<<' ';
//	cout<<endl;				
//	for(int i=1;i<=n;i++)
//		cout<<ifac[i]<<' ';
//	cout<<endl;
	for(int i=1;i<n;i++)
	{
		int x=read(),y=read();
		ins(x,y);
		ins(y,x);
	}
	dfs(1,0);
	for(int i=0;i<=n;i++)
		a[i]=a[i]*fac[i]%mod;
	for(int i=0;i<=n;i++)	
		b[i]=ifac[n-i];	
	
	init();
//	for(int i=0;i<(1<<bit);i++)
//		cout<<a[i]<<' ';
//	cout<<endl;		
//	for(int i=0;i<(1<<bit);i++)
//		cout<<b[i]<<' ';
//	cout<<endl;	
	fft(a,(1<<bit),1);
	fft(b,(1<<bit),1);
	
	for(int i=0;i<(1<<bit);i++)
		a[i]=a[i]*b[i]%mod;
//	for(int i=0;i<(1<<bit);i++)
//		cout<<a[i]<<' ';
//	cout<<endl;	
	fft(a,(1<<bit),-1);
	for(int k=1;k<=n;k++)
	{
		//cout<<(fac[n]*ifac[n-k]%mod*n-a[n+k]+mod)<<endl;
		printf("%lld\n",(fac[n]*ifac[n-k]%mod*n-a[n+k]+mod)%mod*ifac[k]%mod);	
	}
	return 0;
}
/*
20
1 2
2 3
3 4
4 5
5 6
6 7
7 8
8 9
9 10
10 11
11 12
12 13 
13 14
14 15
15 16
16 17
17 18 
18 19
19 20*/

Measured memory_bytes: 40320
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <iostream>
#include <set>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define MOD 1000000007
#define PRIME1 99999883
#define PRIME2 99999893
#define EPS 0.00000001
using namespace std;

struct Node{
	Node(){
		value = -1;
		left_child = -1;
		right_child = -1;
	}

	int value,left_child,right_child;
};

class Tree{

public:
	Tree(int M){
		table = new Node[M];
		size = M;
		index = 0;
	}

	bool add(int num){
		if(index == 0){
			table[index++].value = num;
			return true;
		}else{
			if(index == size)return false; //???????????¢???????????????

			int current = 0;

			while(true){
				if(num < table[current].value){
					if(table[current].left_child == -1){
						table[current].left_child = index;
						table[index++].value = num;
						return true;
					}else{
						current = table[current].left_child;
					}
				}else if(num > table[current].value){
					if(table[current].right_child == -1){
						table[current].right_child = index;
						table[index++].value = num;
						return true;
					}else{
						current = table[current].right_child;
					}

				}else{ //num == table[current].value  <<<????????????2?????????????????????????????????!!!>>>>
					return false;
				}
			}
			return false;	//must not reach here
		}
	}
private:
	Node* table;
	int size,index;
};

int main(){

	int N,M,tmp;
	scanf("%d %d",&N,&M);
	Tree tree(M);

	stack<int> S;

	for(int i = 0; i < N; i++){
		scanf("%d",&tmp);
		S.push(tmp);
	}

	printf("%d\n",S.top());
	tree.add(S.top());
	S.pop();

	int count = 1;

	while(count < M && S.empty() == false){
		if(tree.add(S.top())){
			printf("%d\n",S.top());
			count++;
		}
		S.pop();
	}

    return 0;
}

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


template<class T> bool exist(string s, T key){
    return (s.find(key) != string::npos);
}


int main(){
    int n;
    cin >> n;
    string s, t;
    cin >> s;
    int ans = 0;
    for(int i=0; i<n; i++){
        int cnt = 0;
        vector<int> l(26), r(26);
        for(int j=0; j<i; j++) l[s[j] - 'a']++;
        for(int j=i; j<n; j++) r[s[j] - 'a']++;
        for(int j=0; j<26; j++){
            if(l[j] != 0 && r[j] != 0) cnt++;
        }
        ans = max(ans, cnt);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
//https://atcoder.jp/contests/dp/tasks/dp_f
//shauryakr
#include<bits/stdc++.h>
using namespace std;
string a, b;
int dp[3005][3005];
void solve()
{
    for(int i=1; i<=a.length(); i++)
    {
        for(int j=1; j<=b.length(); j++)
        {
            if(a[i-1] == b[j-1])
            {
                dp[i][j] = dp[i-1][j-1] + 1;
            }
            else
            {
                dp[i][j] = max(dp[i][j-1], dp[i-1][j]);
            }
        }
    }

    // for(int i=0; i<=b.length(); i++)
    // {
    //     for(int j=0; j<=a.length(); j++)
    //     {
    //         cout << dp[j][i] << " ";
    //     }
    //     cout << endl;
    // }

    int i=a.length(), j = b.length();
    string subseq = "";
    while(i != 0 && j != 0)
    {
        if(dp[i][j] == dp[i-1][j])
        {
            i--;
        }
        else if(dp[i][j] == dp[i][j-1])
        {
            j--;
        }
        else
        {
            subseq = subseq + a[i-1];
            i--;
            j--;
        }
    }

    reverse(subseq.begin(), subseq.end());
    cout << subseq << endl;
}
int main()
{
    cin >> a >> b;
    solve();
    return 0;
}

Measured memory_bytes: 35456
#include <bits/stdc++.h>
using namespace std;
#define PI 3.141592653589
#define endl "\n"
#define int long long
#define ld long double
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x.size())
#define fr(i,a,b) for (int i = (a); i < (b); ++i)

void solve(){
    int n;
    cin >> n;
    int a[n], dp[n];
    fr(i, 0, n) cin >> a[i];
    dp[0] = 0;
    dp[1] = abs(a[1] - a[0]);
    fr(i, 2, n){
        dp[i] = min(dp[i - 1] + abs(a[i] - a[i - 1]), dp[i - 2] + abs(a[i] - a[i - 2]));
    }
    cout << dp[n - 1];
}

signed main() {
    ios::sync_with_stdio(0); cin.tie(0);
    int t;
    t = 1;
    //cin >> t;
    while(t--) {solve();}
    return 0;
}


Measured memory_bytes: 1792