akhauriyash/Code-Regression huggingface dataset:
#include "bits/stdc++.h"

typedef long long ll;
using namespace std;

int main() {
    int L, R;
    cin >> L >> R;

    R = min(R, L + 4038);

    ll ans = 2019;
    for (ll i = L; i < R; ++i) {
        for (ll j = L + 1; j <= R; ++j) {
            ans = min(ans, i * j % 2019);
        }
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;
string s;
int main()
{
	cin >> s;
	if(s[0] == s[1] && s[1] == s[2] || s[1] == s[2] && s[2] == s[3]){
		cout << "Yes";
	}else {
		cout << "No";
	}

 return 0;
}

Measured memory_bytes: 256
A, B, K = gets.split.map(&:to_i)

nums = (
  if A + K - 1 >= B - K + 1
    [*A..B]
  else
    [*A..(A + K - 1), *(B - K + 1)..B]
  end
)

nums.each { |n| puts n }


Measured memory_bytes: 1788
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <climits>
#include <cmath>
#include <set>
#include <vector>
using namespace std;
int a,b;
int gcd(int a,int b)
{
    if(b==0) return a;
    else return gcd(b,a%b);
}
int main()
{
//    freopen("in.txt","r",stdin);
    scanf("%d%d",&a,&b);
    printf("%d\n",gcd(a,b));
    return 0;
}

Measured memory_bytes: 3232
#include<bits/stdc++.h>
using namespace std;
int a[100050],b[100010];

int main(){
      int n;scanf("%d",&n);
      for(int i=0;i<n;i++){
            if(i%2==0) scanf("%d",&a[i/2]);
            else scanf("%d",&b[i/2]);
      }
      if(n==2){
            if(a[0]==b[0]) printf("1\n");
            else printf("0\n");
            return 0;
      }
      int a1=-1,a2=-1,b1=-1,b2=-1,a1m=0,a2m=0,b1m=0,b2m=0;
      sort(a,a+n/2);sort(b,b+n/2);
      int count=1;
      for(int i=1;i<n/2;i++){
            if(a[i]==a[i-1]) count++;
            else{
                  if(count>=a1m){
                        a2=a1;a2m=a1m;
                        a1=a[i-1];a1m=count;
                  }
                  else if(count>=a2m){a2=a[i-1];a2m=count;}
                  count=1;
            }
      }
      if(count>=a1m){
            a2=a1;a2m=a1m;
            a1=a[n/2-1];a1m=count;
      }
      else if(count>=a2m){a2=a[n/2-1];a2m=count;}
      count=1;
      for(int i=1;i<n/2;i++){
            if(b[i]==b[i-1]) count++;
            else{
                  if(count>=b1m){
                        b2=b1;b2m=b1m;
                        b1=b[i-1];b1m=count;
                  }
                  else if(count>=b2m){b2=b[i-1];b2m=count;}
                  count=1;
            }
      }
      if(count>=b1m){
            b2=b1;b2m=b1m;
            b1=b[n/2-1];b1m=count;
      }
      else if(count>=b2m){b2=b[n/2-1];b2m=count;}
      if(a1!=b1){
            printf("%d\n",n-a1m-b1m);
      }
      else
            printf("%d\n",min(n-a1m-b2m,n-a2m-b1m));   
}

Measured memory_bytes: 640
W, H, N = map(int, input().split())
XYA = [list(map(int, input().split())) for _ in range(N)]

ans = [[0, 0], [W, H]]
for x, y, a in XYA:
    if a == 1 and x > ans[0][0]:
        ans[0][0] = x
    elif a == 2 and x < ans[1][0]:
        ans[1][0] = x
    elif a == 3 and y > ans[0][1]:
        ans[0][1] = y
    elif a == 4 and y < ans[1][1]:
        ans[1][1] = y

x_length = ans[1][0] - ans[0][0]
y_length = ans[1][1] - ans[0][1]
if x_length > 0 and y_length >0:
    print(x_length * y_length)
else:
    print(0)

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

int main(){
	int n,q;
	cin >> n >> q;
	string s;
	cin >> s;
	vector<int> ans(n,0);
	rep(i,n-1){
		if(s[i] == 'A' && s[i+1] == 'C') ans[i+1]++;
	}
	rep(i,n){
		if(i>0) ans[i] += ans[i-1];
	}
	rep(i,q){
		int l,r;
		cin >> l >> r;
		l--;
		r--;
		cout<< ans[r] - ans[l] << endl;
	}
    return 0;
}



Measured memory_bytes: 1408
import sys
sys.setrecursionlimit(10 ** 7)

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

N, K = map(int, readline().split())
MOD = 10 ** 9 + 7
#AB = [[int(x) - 1 for x in readline().split()] for _ in range(N-1)]

PATH = [[] for _ in range(N + 1)]

for _ in range(N - 1):
    a, b = map(int, readline().split())
    PATH[a].append(b)
    PATH[b].append(a)

# print("hoge")
DONE = [False] * (N+1)

ans = K
q = [(1, 0)]
while q:
    u, cnt = q.pop()
    DONE[u] = True
    i = 0
    for v in PATH[u]:
        if u == v or DONE[v]:
            continue
        ans *= K - i - 1 - cnt
        ans %= MOD
        q.append((v, 1))
        i += 1


print(ans)


Measured memory_bytes: 29976
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <vector>

using namespace std;
using ll = long long;

#define all(c) (c).begin(), (c).end()
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define pb(e) push_back(e)
#define mp(a, b) make_pair(a, b)
#define fr first
#define sc second

const ll INF = 1e9;
const ll MOD = 1e9 + 7;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

int f(int t) {
    int maxi = 0;
    int ret = 0;
    rep(i, 128) {
        int s = i + (t ^ i);
        if (maxi < s) {
            ret = i;
            maxi = s;
        }
    }
    return ret;
}
int N, D;
void solve() {
    cin >> N >> D;
    int A[128] = {};
    rep(i, 128) A[i] = INF;
    A[D] = 1;
    int sum = 0;
    rep(i, N - 1) {
        int idx = min_element(A, A + 128) - A;

        // cout << idx << endl;
        A[idx]--;
        if (A[idx] == 0) A[idx] = INF;
        int t = f(idx);
        if (A[t] == INF)
            A[t] = 1;
        else
            A[t]++;
        if (A[t ^ idx] == INF)
            A[t ^ idx] = 1;
        else
            A[t ^ idx]++;
    }
    rep(i, 128) {
        if (A[i] != INF) sum += i * A[i];
    }
    cout << sum << endl;
}

int main() {
    int T;
    cin >> T;
    rep(i, T) solve();
    return 0;
}


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

#define all(x) (x).begin(),(x).end()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define setbits(x) __builtin_popcount(x)
#define zerobits(x) __builtin_ctz(x)
#define setbitsll(x) __builtin_popcountll(x)
#define zerobitsll(x) __builtin_ctzll(x)
#define inf 1e18
#define ps(x,y) fixed<<setprecision(y)<<x

typedef vector<int> vi;
typedef long long ll;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef unsigned long long ull;
typedef map<int,int> mii;

const int MOD = 1e9+7;

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int a,b;
	cin >> a >> b;
	cout << a*b << '\n';
	return 0;
}



Measured memory_bytes: 3652
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=2e5+5,M=2e4+5,inf=0x3f3f3f3f,mod=998244353;
#define mst(a,b) memset(a,b,sizeof a)
#define lx x<<1
#define rx x<<1|1
#define reg register
#define PII pair<int,int>
#define fi first
#define se second
#define pb push_back
#define il inline
ll dp[N],s[N];
int n,k;
PII a[15];
int main(){
	scanf("%d%d",&n,&k);
	for(int i=1;i<=k;i++){
		scanf("%d%d",&a[i].fi,&a[i].se); 
	}
	dp[1]=s[1]=1;
	for(int i=2;i<=n;i++){
		for(int j=1;j<=k;j++){
			if(i<=a[j].fi) continue;
			int l=max(0,i-a[j].se-1),r=i-a[j].fi;
			dp[i]=(dp[i]+s[r]-s[l])%mod;
		}
		s[i]=(dp[i]+s[i-1])%mod; 
	}
	printf("%lld\n",(dp[n]%mod+mod)%mod);
	return 0;
}

Measured memory_bytes: 6836
#include<iostream>
using namespace std;
int main(void)
{
	int a,b,c,ansa=0;
	cin>>a>>b>>c;
	for(;a<=b;a++){
		if(c%a==0){
			ansa++;
		}
	}
	cout<<ansa<<endl;
	return 0;
}

Measured memory_bytes: 1160
#include<bits/stdc++.h>
#include <bitset>
using namespace std;
#define ll long long
#define fast ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define dcm(a) setprecision(a)<<fixed
#define MOD 1000000007
#define clr(memo, a) memset(memo,a,sizeof(memo))
#define PI acos(-1)

int const N=1e5+5;
int a[N][3];
int dp[N][3];
void solve(){
int n;
cin>>n;
for(int i=0;i<n;i++)
    for(int j=0;j<3;j++)
    cin>>a[i][j];
dp[0][0]=a[0][0];
dp[0][1]=a[0][1];
dp[0][2]=a[0][2];
for(int i=1;i<n;i++){
for(int j=0;j<3;j++){
dp[i][j]=max(dp[i-1][(j+1)%3],dp[i-1][(j+2)%3])+a[i][j];
}

}
cout<<max(dp[n-1][0],max(dp[n-1][1],dp[n-1][2]))<<endl;
}

int main(){
    fast;

solve();

return 0;}


Measured memory_bytes: 2560
#include<iostream>
#include<vector>
#include<queue>
#include<cstring>
using namespace std;
#define N 100010
vector<int> V[N];
queue<int> Q;
bool vis[N];
int dis_from_1[N];
int dis_from_n[N];
int n;
void BFS(int start,bool mode)
{
    while(!Q.empty()) Q.pop();
    Q.push(start);
    memset(vis,0,sizeof(vis));
    vis[start]=1;
    if(mode) dis_from_1[start]=0;
    else dis_from_n[start]=0;
    while(!Q.empty())
    {
        int now=Q.front();
        Q.pop();
        for(int i=0;i<V[now].size();i++)
        {
            int next=V[now][i];
            if(mode)    dis_from_1[next]=dis_from_1[now]+1;
            else        dis_from_n[next]=dis_from_n[now]+1;
            if(!vis[next])
            {
                vis[next]=1;
                Q.push(next);
            }
        }
    }
}
int main()
{
    ios::sync_with_stdio(false);
    while(cin>>n)
    {
        for(int i=1;i<=n;i++) V[i].clear();
        int a,b;
        for(int i=1;i<=n-1;i++)
        {
            cin>>a>>b;
            V[a].push_back(b);
            V[b].push_back(a);
        }//成图
        //分别从1,N BFS比较距离
        BFS(1,true);
        BFS(n,false);
        int first_num=0;
        int second_num=0;
        for(int i=1;i<=n;i++)
        {
            if(dis_from_1[i]<=dis_from_n[i]) first_num++;
            else second_num++;
        }
        if(first_num>second_num) cout<<"Fennec"<<endl;
        else cout<<"Snuke"<<endl;
    }
}

Measured memory_bytes: 6784
#include <bits/stdc++.h>
using namespace std;
int main()
{
   int n;
   vector<long long int> a;
   int flag = 0;
   cin>>n;
   for(int i=0;i<n;i++)
   {
     long long int num;
     cin>>num;
     a.push_back(num);
   }

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

   for(int i=1;i<n;i++)
   {
       if(a[i]==a[i-1])
       {
       flag = 1;
       break;
       }

   }
   if(flag == 0)
   cout<<"YES"<<endl;

   else cout<<"NO"<<endl;
   return 0;
   
}


Measured memory_bytes: 2420
#include <bits/stdc++.h>
      
#define FOR(i,a,b) for( ll i = (a); i < (ll)(b); i++ )
#define REP(i,n) FOR(i,0,n)
#define YYS(x,arr) for(auto& x:arr)
#define ALL(x) (x).begin(),(x).end()
#define SORT(x) sort( (x).begin(),(x).end() )
#define REVERSE(x) reverse( (x).begin(),(x).end() )
#define UNIQUE(x) (x).erase( unique( ALL( (x) ) ) , (x).end() )
#define PW(x) (1LL<<(x))
#define SZ(x) ((ll)(x).size())
#define SHOW(x) cout << #x << " = " << x << endl
#define SHOWA(x,n) for( int yui = 0; yui < n; yui++ ){ cout << x[yui] << " "; } cout << endl

#define pb emplace_back
#define fi first
#define se second

using namespace std;

typedef long double ld;
typedef long long int ll;
typedef pair<int,int> pi;
typedef pair<ll,ll> pl;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<bool> vb;
typedef vector<ld> vd;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<vpl> gr;
typedef vector<vl> ml;
typedef vector<vd> md;
typedef vector<vi> mi;
     
const ll INF = (ll)1e9 + 10;
const ll INFLL = (ll)1e18 + 10;
const ld EPS = 1e-12;
const ll MOD = 1e9+7;
     
template<class T> T &chmin( T &a , const T &b ){ return a = min(a,b); }
template<class T> T &chmax( T &a , const T &b ){ return a = max(a,b); }
template<class T> inline T sq( T a ){ return a * a; }

ll in(){ long long int x; scanf( "%lld" , &x ); return x; }
char yuyushiki[1000010]; string stin(){ scanf( "%s" , yuyushiki ); return yuyushiki; }

// head

int n, m;
string s[10010];

int main(){

  m = in();
  n = in();
  REP(i, n){
    s[i] = stin();
  }

  ll cur = 0;
  REP(j, m){
    REP(i, n){
      if(s[i][j] == 'W'){
        cur++;
      }
    }
  }
  
  ll min_v = cur;
  ll argmin = 0;

  REP(j, m){
    REP(i, n){
      if(s[i][j] == 'W'){
        cur--;
      } else {
        cur++;
      }
    }
    if(cur < min_v){
      min_v = cur;
      argmin = j+1;
    }
  }

  printf("%lld %lld\n", argmin, argmin+1);
  
  return 0;
}



Measured memory_bytes: 4452
#include <bits/stdc++.h>
#define ff first
#define ss second
using namespace std;
#define MP make_pair
#define PB push_back
#define ll long long
#define int long long
#define f(i,x,n) for(int i=x;i<n;i++)
#define ld long double
#define mod 1000000007


int32_t main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int n;
	cin>>n;
	int an=0;
	f(i,1,n+1)
	{
		an=an^i;
	}
	if(an==0)
	{
		cout<<"Yes\n";
		f(i,1,2*n)
		{
			cout<<i<<" "<<i+1<<'\n';
		}
	}
	else if(n<3)
		cout<<"No\n";
	else if(n>4&&  (n%2==1)  )
	{
		cout<<"Yes\n";
		for(int i=2;i<=n-3;i++)
			cout<<i<<" "<<i+1<<'\n';
		cout<<n-2<<" "<<n+1<<'\n';
		for(int i=1;i<=n-3;i++)
			cout<<i+n<<" "<<i+1+n<<'\n';
		cout<<2*n<<" "<<2*n-1<<'\n';
		cout<<2*n-1<<" 1\n";
		cout<<"1 "<<n<<'\n';
		cout<<n<<" "<<n-1<<'\n';
		cout<<n-1<<" "<<n+1<<'\n';
	}
	else if( (an^(n+1))==0 )
	{
		cout<<"Yes\n";
		for(int i=3;i<n-3;i++)
			cout<<i<<" "<<i+1<<'\n';
		cout<<n-3<<" "<<n+1<<'\n';
		for(int i=1;i<n-3;i++)
			cout<<i+n<<" "<<i+1+n<<'\n';
		cout<<n+1<<" "<<n-1<<'\n';
		cout<<n-1<<" "<<n<<'\n';
		cout<<n<<" 2\n";
		cout<<"2 1\n";
		cout<<"1 "<<2*n-1<<'\n';
		cout<<2*n-1<<" "<<2*n<<'\n';
		cout<<n-2<<" 1\n";
		cout<<2*n-2<<" "<<2*n-1<<'\n';
	}
	else
	{
		if(an==n)
		{
			an=an^(n-1);
			f(i,1,n+1)
			{
				an^=i;
				if(an==0)
				{
					cout<<"Yes\n";
					f(i,1,n-1)
						cout<<i<<" "<<i+1<<'\n';
					cout<<n-1<<" "<<n+1<<"\n";
					f(i,n+1,2*n-1)
						cout<<i<<" "<<i+1<<'\n';
					cout<<n-1<<" "<<n<<'\n';
					cout<<i+n<<" "<<2*n<<'\n';
					return 0;
				}
			}
		}
		cout<<"No\n";
	}
	return 0;
}

Measured memory_bytes: 2816
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <string>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <algorithm>

#define FOR(i,k,n) for (int i=(k); i<(int)(n); ++i)
#define REP(i,n) FOR(i,0,n)
#define FORIT(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define sz size()
#define pb push_back
#define mp make_pair
#define ALL(X) (X).begin(),(X).end()

using namespace std;

const int INF = 1000000000;
const double eps = 1e-8;

int main(void) {
  int m;cin>>m;
  REP(i,m){
    double A;
    int y,n;
    cin>>A>>y>>n;
    double maxx = 0.0;
    REP(j,n){
      int tf,fee;
      double index;
      cin>>tf>>index>>fee;
      double cA = A;
      if(tf == 0){
        int r = 0;
        REP(k,y){
          r += (int)(cA*index);
          cA -= fee;
        }
        if(maxx < cA+r){
          maxx=cA+r;
        }
      }else{
        REP(k,y){
          cA += (int)(cA*index) - fee;
        }
        if(maxx < cA){
          maxx=cA;
        }
      }
    }
    cout<<(int)maxx<<endl;
  }
  return 0;
}

Measured memory_bytes: 1240
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<queue>
#include<stack>
#include<cassert>
#include<numeric>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
using namespace std;
const int INF = 1001001001;
const long long LINF = 1001002003004005006ll;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
typedef long long ll;
typedef pair<int,int> P;

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

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

struct combination {
  //fact 階乗　iface 階乗の逆数
  vector<mint> fact, ifact;
  combination(int n):fact(n+1),ifact(n+1) {
    assert(n < mod);
    fact[0] = 1;
    for (int i = 1; i <= n; ++i) fact[i] = fact[i-1]*i;
    ifact[n] = fact[n].inv();
    for (int i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i;
  }
  mint operator()(int n, int k) {
    if (k < 0 || k > n) return 0;
    return fact[n]*ifact[k]*ifact[n-k];
  }
  mint p(int n, int k) {
    return fact[n]*ifact[n-k];
  }
} c(1000005);

int main(){
  int n,m;
  cin >> n >> m;
  mint ans = 0;
  rep(i,n+1){
    mint t = c(n,i)*c.p(m-i,n-i);
    if(i%2==0)ans += t;
    else ans -= t;
  }
  ans *= c.p(m,n);
  cout << ans << endl;
}

Measured memory_bytes: 18200
from math import gcd

def gcd_3(a, b, c):
    g = gcd(a, b)
    return gcd(g, c)

K = int(input())
ans = 0

for i in range(1, K+1):
    for j in range(1, K+1):
        for k in range(1, K+1):
            ans += gcd_3(i, j, k)

print(ans)


Measured memory_bytes: 70480
n=input()
a=map(int,raw_input().split())
count=1
b=0
for i in range(1,n):
    j=1
    while b >= 0 and i!=j-1:
        if a[i]>=a[i-j]:
            j+=1
        else:
            break
        if i==j-1 :
            count+=1
print(count)


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

using namespace std;
typedef long long ll;

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  int n; cin >> n;
  vector<ll> a(n);
  for(int i = 0; i < n; ++i) {
    cin >> a[i];
    // a[i] += a[i - 1];
  }
  ll suff = accumulate(a.begin(), a.end(), 0LL);
  ll pref = 0;
  ll res = 1e18;
  for(int i = 0; i < n; ++i) {
    suff -= a[i];
    pref += a[i];
    res = min(res, llabs(pref - suff));
  }
  cout << res << '\n';
  return 0;
}


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

#define int long long

int mod(string num, int a) 
{ 
    int res = 0; 
  
    for (int i = 0; i < num.length(); i++) 
         res = (res*10 + (int)num[i] - '0') %a; 
  
    return res; 
} 

signed main() 
{ 
	string cur = "7";
    map<int,int> mp;
    int k;
    cin>>k;
    int cnt = 1,flag=0,res=0;
    while(1){
        //int md = mod(cur,k);
        res = (res*10 + 7) %k; 
        int md = res;
        if(md ==0){
            break;
        }
        else if(mp[md]){
            flag=1;
            break;
        }
        else{
            mp[md] = 1;
            cnt++;
            cur+='7';
        }
    }
    if(flag)
    cout<<-1;
    else
    {
        cout<<cnt;
    }
    
} 


Measured memory_bytes: 66864
#include <bits/stdc++.h>
#define ll long long
#define ld long double
using namespace std;

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	ll h,w,m,a,b;

	cin >> h >> w >> m;

	map<ll,ll> row;
	map<ll,ll> col;
	set<pair<ll,ll>> s;
	for(int i = 0; i < m; i++){
		cin >> a >> b;
		row[a]++;
		col[b]++;
		s.insert({a,b});
	}

	

	ll p1 = 0,p1row;

	set<ll> crow;
	ll rmx = 0;
	for(auto val : row)
		rmx = max(rmx,val.second);


	
	for(auto val : row){
		if(val.second == rmx)
			crow.insert(val.first);
	}

		
	ll cmx = 0;
	for(auto val : col){
		cmx = max(cmx,val.second);
	}

	set<ll> ccol;

	for(auto val : col){
		if(val.second == cmx)
			ccol.insert(val.first);
	}

	ll ans = 0, optans = rmx+cmx;

	for(auto i : crow){
		
		for(auto j : ccol){
			ll curr = rmx+cmx;
			if(s.find({i,j}) != s.end()){
				curr--;
			}
			ans = max(ans,curr);
			if(ans == optans)
				break;
			
		}
		if(ans == optans)
			break;
	}

	cout << ans << "\n";
}

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

int main() {
  int n;
  cin >> n;
  int ans = 0;
  while (1) {
    if ((ans+1)*(ans+1) <= n) {
      ++ans;
    } else {
      break;
    }
  }
  cout << ans*ans << endl;
  return 0;
}


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

using namespace std;

typedef long long int li;
typedef long double ld;
typedef vector<li> vi;
typedef pair<li,li> pi;
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define B begin()
#define E end()
#define f(i,l,r) for(li i=l;i<=r;++i)
#define fr(i,l,r) for(li i=l;i>=r;--i)
#define u_map unordered_map
#define endl "\n"

li fastpow(li base,li exp,li M) 
{
    li res=1;
    while(exp>0) {
        if(exp&1)
            res=(res*base)%M;

        base=(base*base)%M;
        exp>>=1;
    }
    return res;
}

int main()
{    
    

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

    li n,m;

    cin>>n>>m;

    li a[n];

    li sum=0;

    f(i,0,n-1)
    {
        cin>>a[i];
        sum+=a[i];
    }   

    ld tp=(ld)sum/(ld)(4*m);

    sort(a,a+n,greater<li>());

    if(a[m-1]>=tp)
    {
        cout<<"Yes";
    }
    else
    {
        cout<<"No";
    }

    return 0;
}

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

int main(){
  int c;
  scanf("%d\n",&c);
  string tt,rr;
  stringstream cc;
  set<string> ss;
  rep(i,c){
    cin>>tt>>rr;
    if(tt=="insert"){
      ss.insert(rr);
    }

    else if(tt=="find"){
      if(ss.find(rr)!=ss.end()){
        cout<<"yes"<<endl;
      }
      else{
        cout<<"no"<<endl;
      }
    }
}
//cout<<cc.str();
  return 0;
}



Measured memory_bytes: 32692
#include<bits/stdc++.h>
using namespace std;
int a,b,c;
int main()
{
	cin>>a>>b>>c;
	if(c==max(a,max(b,c)))
	cout<<a*b/2;
	if(b==max(a,max(b,c)))
	cout<<a*c/2;
	if(a==max(a,max(b,c)))
	cout<<c*b/2;
	return 0;
}

Measured memory_bytes: 256
def main():
    import sys
    sys.setrecursionlimit(10 ** 7)

    def dfs(v):
        nonlocal curr

        num[v] = 0  # 0: visited, but not written yet

        for u in g[v]:
            if num[u] >= 0:
                continue
            dfs(u)
        num[v] = c[curr]
        curr += 1

    n = int(input())

    g = [set() for _ in range(n)]
    for _ in range(n - 1):
        a, b = (int(x) - 1 for x in input().split())
        g[a].add(b)
        g[b].add(a)
        # 出次数は、len(g[x])-1
        # 親を除いた残りが子
    *c, = sorted(map(int, input().split()))

    num = [-1] * n
    curr = 0
    dfs(0)

    print(sum(c[:-1]))
    print(*num)


if __name__ == '__main__':
    main()


Measured memory_bytes: 17264
#include <stdio.h>

int main(){
  int n,t;
  scanf("%d%d",&n,&t);
  
  int cc[n],tt[n];
  memset(cc,'\0',sizeof(cc));
  memset(tt,'\0',sizeof(tt));
  for(int i=0;i<n;i++){
    scanf("%d%d",&cc[i],&tt[i]);
  }
  
  int cost=1001;
  for(int j=0;j<n;j++){
    if(tt[j] > t) continue;
    if(cost > cc[j]) cost = cc[j];
  }
  if(cost == 1001){
    printf("TLE");
  }else{
    printf("%d",cost);
  }
}

Measured memory_bytes: 128
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <string.h>

int main(void) {

	int n;
	char str1[128], str2[128];

	scanf("%d", &n);

	int ten1, ten2;
	ten1 = ten2 = 0;
	for (int i = 0; i < n; i++) {
		scanf("%s %s", str1, str2);
		int ret = strcmp(str1, str2);
		if ( ret < 0 ) {
			ten2 += 3;
		} else if ( ret > 0 ) {
			ten1 += 3;
		} else {
			ten1 += 1;
			ten2 += 1;
		}
	}

	printf("%d %d\n", ten1, ten2);

	return 0;

}

Measured memory_bytes: 2672
using System;
using System.Linq;
using System.Collections.Generic;
using static System.Console;
using System.Text;
using System.IO;
using static System.Math;
namespace AtCoder
{
    class Program
    {
        static public long[] Sarray() { return ReadLine().Split().Select(long.Parse).ToArray(); }
        static public List<long> Slist() { return ReadLine().Split().Select(long.Parse).ToList(); }

        static readonly long Mod = 1000000000 + 7;

        static void Main(string[] args)
        {
            //SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
            var NM = Sarray();
            var N = NM[0];
            var M = NM[1];
            var walst = new long[N];
            var acnum = 0;
            var acprb = new bool[N];
            for (var i = 0; i < M; ++i)
            {
                var ps = ReadLine().Split();
                var p = long.Parse(ps[0]);
                var s = ps[1];
                if (!acprb[p - 1])
                {
                    if (s == "WA")
                        ++walst[p - 1];
                    else
                    {
                        ++acnum;
                        acprb[p - 1] = true;
                    }
                }
            }
            var wanum = 0L;
            for (var i = 0; i < N; ++i)
                if (acprb[i])
                    wanum += walst[i];
            WriteLine($"{acnum} {wanum}");

            //Out.Flush();
        }
    }
}

Measured memory_bytes: 18124
// #define _GLIBCXX_DEBUG
#include <bits/stdc++.h>

#define FOR(i, a, b) for (int i = (a); i < int(b); ++i)
#define RFOR(i, a, b) for (int i = (b)-1; i >= int(a); --i)
#define REP(i, n) FOR(i, 0, n)
#define REP1(i, n) FOR(i, 1, int(n) + 1)
#define RREP(i, n) RFOR(i, 0, n)
#define RREP1(i, n) RFOR(i, 1, int(n) + 1)
#define ALL(c) begin(c), end(c)

int _ = (
#ifndef LOCAL
    std::cin.tie(nullptr), std::ios::sync_with_stdio(false),
#endif
    std::cout.precision(10), std::cout.setf(std::ios::fixed));

using ll = long long;
using ull = unsigned long long;
using ld = long double;
template <typename T> using vec = std::vector<T>;
using namespace std;

int main() {
  ll N, K;
  cin >> N >> K;
  const ll r = N % K;
  const ll s = K - r;
  cout << (r < s ? r : s) << endl;
  return 0;
}


Measured memory_bytes: 3576
#include <iostream>
#include <cmath>
#define REP(i, n) for (int i = 0; i < (n); i++)
using namespace std;

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

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s;
    cin >> s;

    int mini = 1000;
    REP(i, s.size() - 2) {
        string tmp = s.substr(i, 3);
        int a = abs(stoi(tmp) - 753);
        chmin(mini, a);
    }
    cout << mini << '\n';
    return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <vector>
#include <map>
#include <utility>
#include <algorithm>
using namespace std;

typedef pair<int, int> Pair;

int nums[13];
map<int, int> cnt;

bool check(map<int, int> cnt) {
  while (!cnt.empty()) {
    Pair p = *cnt.begin();
    if (p.second >= 3) {
      cnt[p.first] -= 3;
      if (cnt[p.first] == 0) cnt.erase(p.first);
    } else {
      if (cnt.count(p.first+1) && cnt.count(p.first+2)) {
        cnt[p.first] -= 1;
        cnt[p.first+1] -= 1;
        cnt[p.first+2] -= 1;
        if (cnt[p.first] == 0) cnt.erase(p.first);
        if (cnt[p.first+1] == 0) cnt.erase(p.first+1);
        if (cnt[p.first+2] == 0) cnt.erase(p.first+2);
      } else return false;
    }
  }
  return true;
}

bool possible(int k) {
  if (cnt[k] >= 4) return false;

  cnt[k]++;
  for (auto itr=cnt.begin(); itr!=cnt.end(); itr++) {
    if (itr->second >= 2) {
      map<int, int> newcnt = cnt;
      newcnt[itr->first] -= 2;
      if (newcnt[itr->first] == 0) newcnt.erase(itr->first);
      if (check(newcnt)) {
        cnt[k]--;
        if (cnt[k] == 0) cnt.erase(k);
        return true;
      }
    }
  }
  cnt[k]--;
  if (cnt[k] == 0) cnt.erase(k);
  return false;
}

int main() {
  while (1) {
    cnt.clear();
    for (int i=0; i<13; i++) {
      if (scanf("%1d", &nums[i]) != 1) return 0;
      cnt[nums[i]]++;
    }
    sort(nums, nums+13);
 
    vector<int> ans; 
    for (int i=1; i<=9; i++) {
      if (possible(i)) ans.push_back(i);
    }
  
    if (ans.empty()) puts("0");
    else {
      printf("%d", ans[0]);
      for (int i=1; i<ans.size(); i++) {
        printf(" %d", ans[i]);
      }
      puts("");
    }
  }
}

Measured memory_bytes: 2788
#include<bits/stdc++.h>
using namespace std;
int main(){
    string a;
    cin>>a;
    string b=a;
    reverse(a.begin(),a.end());
    for(int i=0;i<a.size();++i){
        if(a[i]=='b') a[i]='d';
        else if(a[i]=='d') a[i]='b';
        else if(a[i]=='p') a[i]='q';
        else if(a[i]=='q') a[i]='p';
    }
    if(a==b) cout<<"Yes";
    else cout<<"No";
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
#define pii pair<int,int>
using namespace std;
vector<pii> A;
int n,x;
int main(){
	cin >> n;
	for(int i = 0; i < n;i++){
		cin >> x;
		A.push_back(pii(x,i));
	}
	sort(A.begin(),A.end());
	int c = 0;
	for(int i = 0; i < n;i+=2){
		if((A[i].second + i)%2)
			c++;
	}
	cout << c << endl;
}

Measured memory_bytes: 1400
N, M, C = map(int, input().split())
B = list(map(int, input().split()))

cnt = 0
for i in range(N):
    A = list(map(int, input().split()))
    s = sum([A[j] * B[j] for j in range(M)])
    s += C
    if s > 0:
        cnt += 1
print(cnt)


Measured memory_bytes: 3060
x = int(input())

import math


def get_sieve_of_eratosthenes(n):
    if not isinstance(n, int):
        raise TypeError('n is int type.')
    if n < 2:
        raise ValueError('n is more than 2')
    prime = []
    limit = math.sqrt(n)
    data = [i + 1 for i in range(1, n)]
    while True:
        p = data[0]
        if limit <= p:
            return prime + data
        prime.append(p)
        data = [e for e in data if e % p != 0]

data = get_sieve_of_eratosthenes(10 ** 5 + 3)

for d in data:
    if d >= x:
        print(d)
        break


Measured memory_bytes: 7448
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);

		int n = sc.nextInt();
		int m = sc.nextInt();
		int c = sc.nextInt();
		int count = 0;

		int[] b = new int[m];
		int[][] a = new int[n][m];

		for (int i = 0; i < n; i++) {
			if (i == 0) {
				for (int j = 0; j < m; j++) {
					b[j] = sc.nextInt();
				}
			}
			for (int j = 0; j < m; j++) {
				a[i][j] = sc.nextInt();
			}
		}

		for (int i = 0; i < n; i++) {
			int calc = 0;
			for (int j = 0; j < m; j++) {
				calc += b[j] * a[i][j];
			}
			if (calc + c > 0) {
				count++;
			}


		}



		System.out.println(count);


	}

}


Measured memory_bytes: 23764
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N,K;
  cin>>N>>K;
  int index=0;
  for (int i=0;i<N;i++){
  int tmp;
  cin>>tmp;
  if(tmp==1){
    index=i;
    break;
  }}
  int lr=index;
  int rr=N-index-1;
  int ans=0;
  if (N==K) ans=1;
  else ans=lr/(K-1)+rr/(K-1)+((rr%(K-1)+lr%(K-1)-1)/(K-1)+1);
  cout<<ans<<endl;
  }


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(void){
    char c;
    cin >> c;
    
    if(c=='a'||c=='i'||c=='u'||c=='e'||c=='o'){
        cout << "vowel" << endl;
    } else {
        cout << "consonant" << endl;
    }

    
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
constexpr ll mod=1000000007;
constexpr ll mod998=998244353;

int N,A[200000];
ll res;

int main(){
	cin>>N;
	for(int i=0;i<N;i++){
		cin>>A[i];
	}
	sort(A,A+N,greater<>());
	int p=0;
	bool f=true;
	for(int i=0;i<N-1;i++){
		res+=A[p];
		if(f)p++;
		f^=true;
	}
	cout<<res<<endl;
}


Measured memory_bytes: 4416
#include <bits/stdc++.h>
#define rep(i,n)for(long long i=0;i<(n);i++)
using namespace std;
typedef long long ll;
const int MOD=1e9+7;
ll gcd(ll a, ll b){
  if(b==0) return a;
  else gcd(b,a%b);
}
ll lcm(ll a, ll b){
  return a/gcd(a,b)*b;
}
int main(){
  double n,k;
  cin >> n >> k;
  double ans=0;
  for(int i=1;i<=n;i++){
    double point=i;
    double prob=1/n;
    while(point<k){
      point*=2;
      prob/=2;
    }
    ans+=prob;
  }
  cout << fixed << setprecision(10) << ans << endl;
  return 0;
}


Measured memory_bytes: 256
import java.util.*;

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

        if (a * b % 2 == 0){
        	System.out.println("Even");
        }else {
        	System.out.println("Odd");
        }
    }
}

Measured memory_bytes: 22868
using System;
using System.Collections.Generic;
using System.Linq;

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            //[summary]A - F
            var line = ReadLine();
            var a = line[0];
            var b = line[1];

            var ans = "x";

            if (a + b == 15)
            {
                ans = "+";
            }
            else if (a * b == 15)
            {
                ans = "*";
            }

            Console.WriteLine(ans);
        }

        static List<int> ReadLine()
        {
            var line = Console.ReadLine();
            var arr = line.Split(' ');

            return arr.Select(x => int.Parse(x)).ToList();
        }
    }
}

Measured memory_bytes: 11220
#include<bits/stdc++.h>
using namespace std;
int main(){
    int a;
    scanf("%d",&a);
    if(a==2 ||a==9 || a==16 || a==23 || a==30) cout <<"sat"<< endl;
    if(a==1 || a==8 || a==15 || a==22 || a==29) cout <<"fri"<< endl;
    if(a==3 || a==10 || a==17 || a==24) cout <<"sun"<< endl;
    if(a==4 || a==11 || a==18 || a==25) cout <<"mon"<< endl;
    if(a==5 || a==12 || a==19 || a==26) cout <<"tue"<< endl;
    if(a==6 || a==13 || a==20 || a==27) cout <<"wed"<< endl;
    if(a==7 || a==14 || a==21 || a==28) cout <<"thu"<< endl;
    return 0;
}

Measured memory_bytes: 3192
let k = stdin.ReadLine() |> int

/// return newList, count, newCount
let rec createMightAnsList beforeList count =
    let newList =
        beforeList
        |> List.map (fun (a:string) -> 
            match a.[a.Length-1] with
            | '0' -> [a+"0"; a+"1"]
            | '1' -> [a+"0"; a+"1"; a+"2"]
            | '2' -> [a+"1"; a+"2"; a+"3"]
            | '3' -> [a+"2"; a+"3"; a+"4"]
            | '4' -> [a+"3"; a+"4"; a+"5"]
            | '5' -> [a+"4"; a+"5"; a+"6"]
            | '6' -> [a+"5"; a+"6"; a+"7"]
            | '7' -> [a+"6"; a+"7"; a+"8"]
            | '8' -> [a+"7"; a+"8"; a+"9"]
            | '9' -> [a+"8"; a+"9"])
        |>List.collect (fun x -> x)

    let newCount = count + newList.Length
    
    if newCount >= k then
        newList, count, newCount
    else
        createMightAnsList newList newCount

let countAns (newList:list<_>) count newCount = newList.[(k - count - 1)]

if k <= 9 then
    k.ToString()
else
    createMightAnsList 
        ([1..9] |> List.map string)
        9
    |||> countAns 
|> stdout.WriteLine

Measured memory_bytes: 34760
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
using namespace std;


int main() {
    int X, Y;
    cin >> X >> Y;

    cout << X + Y/ 2 << endl;

    
}

Measured memory_bytes: 3624
#include <stdio.h>

int main(int argc, const char * argv[]) {
    int x;
    int i = 1;
    
    while (1){
        scanf("%d", &x);
        if (x==0) {
            break;
        }
        else{
            printf("Case %d: %d\n", i, x);
        }
        i++;
    }
    
    return 0;
}

Measured memory_bytes: 596
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <cstdlib>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <ctime>
#define ABS(x) ((x) >= 0 ? (x) : -(x))
#define MAX(a,b) ((a) >= (b) ? (a) : (b))
#define MIN(a,b) ((a) >= (b) ? (b) : (a))
#define sd(x) scanf("%d",&x)
#define sdd(x,y) scanf("%d%d",&x,&y)
#define rep(val,l,r,step) for(int val = l ; val <= r ; val += step)
#define per(val,l,r,step) for(int val = l ; val >= r ; val -= step)
#define tdf typedef struct
#define mst(x,y) memset(x,y,sizeof(x))

using namespace std;

typedef long long LL;
typedef unsigned long long ULL;
const int inf = 0x3f3f3f3f;
const int mod = 1000000007;
void MakeTable();



int main()
{
	#ifdef LOCAL
		freopen("in.txt","r",stdin);
		//freopen("out.txt","w",stdout);
	#endif

    LL x,y;
    int ans = 0;

    scanf("%lld%lld",&x,&y);

    while(x <= y)
    {
        ans++;
        x *= 2;
    }

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

	return 0;
}

//Random
void MakeTable()
{
	srand(time(0));


}


Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
	"strconv"
)

func out(x ...interface{}) {
	fmt.Println(x...)
}

var sc = bufio.NewScanner(os.Stdin)

func getInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func getInts(N int) []int {
	ret := make([]int, N)
	for i := 0; i < N; i++ {
		ret[i] = getInt()
	}
	return ret
}

func getString() string {
	sc.Scan()
	return sc.Text()
}

// min, max, asub, absなど基本関数
func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func asub(a, b int) int {
	if a > b {
		return a - b
	}
	return b - a
}

func abs(a int) int {
	if a >= 0 {
		return a
	}
	return -a
}

func lowerBound(a []int, x int) int {
	idx := sort.Search(len(a), func(i int) bool {
		return a[i] >= x
	})
	return idx
}

func upperBound(a []int, x int) int {
	idx := sort.Search(len(a), func(i int) bool {
		return a[i] > x
	})
	return idx
}

func main() {
	sc.Split(bufio.ScanWords)
	sc.Buffer([]byte{}, 1000000)
	s := getString()
	t := getString()
	cnt := 0
	for i := 0; i < len(s); i++ {
		if s[i] != t[i] {
			cnt++
		}
	}
	out(cnt)
}


Measured memory_bytes: 2696
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
using namespace std;
int main(){
    int n;
    int a[100];
    cin>>n;
    for(int i=0;i<n;i++)cin>>a[i];
    sort(a,a+n);
    cout<<a[n-1]-a[0]<<endl;
}


Measured memory_bytes: 256
#include<stdio.h>
int main(){
  int A[101], n, i, j, t, sw = 0, mini;

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

  for ( i = 1; i <= n; i++ ){
    mini = i;
    for ( j = i; j <= n; j++ ){
      if ( A[j] < A[mini] ) mini = j;
    }
    t = A[i]; A[i] = A[mini]; A[mini] = t;
    if ( i != mini ) sw++;
  }

  for ( i = 1; i <= n; i++ ){
    if (i>1) printf(" ");
    printf("%d", A[i]);
  }
  printf("\n");
  printf("%d\n", sw);

  return 0;
}

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

#define REP(i,n) for (int i=0;i<(n);++i)
#define RREP(i,n) for (int i=(n)-1;i>=0;--i)

using namespace std;

unsigned long long clp(unsigned long long x) {
    x -= 1;
    x = x | (x >>  1);
    x = x | (x >>  2);
    x = x | (x >>  4);
    x = x | (x >>  8);
    x = x | (x >> 16);
    x = x | (x >> 32);
    return x + 1;
}

template <class T>
class segment_tree {
private:
    const size_t n;
    const T UNIT;
    const std::function<T(const T&, const T&)> f;
    std::vector<T> a;
public:
    segment_tree(size_t size, T UNIT, std::function<T(const T&, const T&)> f) : n(clp(size)), UNIT(UNIT), f(f) {
        a.resize(2 * n - 1, UNIT);
    }

    void update(size_t i, const T &x) {
        i += n - 1;
        a[i] = x;
        while (i) {
            i = (i - 1) / 2;
            a[i] = f(a[2 * i + 1], a[2 * i + 2]);
        }
    }

    T query(size_t query_first, size_t query_last, size_t k = 0, size_t node_first = 0, size_t node_last = 0) const {
        if (k == 0) {
            node_last = n;
        }
        if (node_last <= query_first || query_last <= node_first) {
            return UNIT;
        }
        if (query_first <= node_first && node_last <= query_last) {
            return a[k];
        } else {
            size_t node_mid = (node_first + node_last) / 2;
            T vl = query(query_first, query_last, k * 2 + 1, node_first, node_mid);
            T vr = query(query_first, query_last, k * 2 + 2, node_mid, node_last);
            return f(vl, vr);
        }
    }
};

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

    int N, M;
    string S;
    cin >> N >> M >> S;
    const int INF = N + 1;

    segment_tree<int> st(M, INF, [](int x, int y) { return min(x, y); });
    st.update(N % M, 0);

    vector<int> pos_seq{N};

    RREP(i, N) {
        if (S[i] == '0') {
            int n_moves = st.query(0, M);
            int n_moves_next;
            if (n_moves == INF) {
                n_moves_next = INF;
            } else {
                n_moves_next = n_moves + 1;
            }
            st.update(i % M, n_moves_next);
            if (n_moves_next == pos_seq.size()) {
                pos_seq.push_back(i);
            }
            else if (n_moves_next == pos_seq.size() - 1) {
                pos_seq[pos_seq.size() - 1] = i;
            }
        } else {
            st.update(i % M, INF);
        }
    }

    if (pos_seq[pos_seq.size() - 1] == 0) {
        RREP(i, pos_seq.size() - 1) {
            int step = pos_seq[i] - pos_seq[i + 1];
            cout << step << '\n';
        }
        cout << flush;
    } else {
        cout << -1 << endl;
    }

    return 0;
}

Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std;
using psi = pair<string, int>;

template <typename T>
class merge_tree {
	const int n;
	vector<vector<T>> data;
	int size(int x) {
		int res;
		for (res = 1; res < x; res <<= 1);
		return res;
	}
	int query(int node, T val) {
		return lower_bound(data[node].begin(), data[node].end(), val) - data[node].begin();
	}
public:
	merge_tree(const vector<T>& data_) : n(size(data_.size())), data(n * 2) {
		for (int i = 0; i < (int)data_.size(); i++)
			data[i + n].push_back(data_[i]);
		for (int i = n - 1; i >= 0; i--)
			merge(data[i * 2].begin(), data[i * 2].end(), data[i * 2 + 1].begin(), data[i * 2 + 1].end(), back_inserter(data[i]));
	}
	int find(int l, int r, T val) {
		l += n; r += n;
		int res = 0;
		while (l < r) {
			if (l & 1) res += query(l++, val);
			if (r & 1) res += query(--r, val);
			l >>= 1; r >>= 1;
		}
		return res;
	}
};

int main()
{
	int N, Q;
	cin >> N >> Q;
	vector<psi> ss;
	for (int i = 0; i < N; i++) {
		string s;
		cin >> s;
		ss.emplace_back(s, i);
	}
	auto rs = ss;
	for (int i = 0; i < N; i++) {
		reverse(rs[i].first.begin(), rs[i].first.end());
	}
	sort(ss.begin(), ss.end());
	sort(rs.begin(), rs.end());
	vector<int> pos1(N), pos2(N);
	for (int i = 0; i < N; i++) {
		pos1[ss[i].second] = i;
		pos2[rs[i].second] = i;
	}
	vector<int> data(N);
	for (int i = 0; i < N; i++) {
		data[i] = pos2[ss[i].second];
	}
	merge_tree<int> mt(data);
	while (Q--) {
		string pre, suf;
		cin >> pre >> suf;
		int l1, r1, l2, r2;
		{
			int lb = -1, ub = N;
			while (ub - lb > 1) {
				int c = (lb + ub) >> 1;
				if (ss[c].first.compare(0, pre.length(), pre) < 0) {
					lb = c;
				}
				else {
					ub = c;
				}
			}
			l1 = ub;
			lb = -1, ub = N;
			while (ub - lb > 1) {
				int c = (lb + ub) >> 1;
				if (ss[c].first.compare(0, pre.length(), pre) <= 0) {
					lb = c;
				}
				else {
					ub = c;
				}
			}
			r1 = ub;
		}
		reverse(suf.begin(), suf.end());
		{
			int lb = -1, ub = N;
			while (ub - lb > 1) {
				int c = (lb + ub) >> 1;
				if (rs[c].first.compare(0, suf.length(), suf) < 0) {
					lb = c;
				}
				else {
					ub = c;
				}
			}
			l2 = ub;
			lb = -1, ub = N;
			while (ub - lb > 1) {
				int c = (lb + ub) >> 1;
				if (rs[c].first.compare(0, suf.length(), suf) <= 0) {
					lb = c;
				}
				else {
					ub = c;
				}
			}
			r2 = ub;
		}
		printf("%d\n", mt.find(l1, r1, r2) - mt.find(l1, r1, l2));
	}
	return 0;
}



Measured memory_bytes: 40004
#include <iostream>

int main(){
	int n,k;
	std::cin >> n >> k;
	int x[n];
	int sum = 0;
	for(int i = 0; i < n; ++i){
		std::cin >> x[i];
		if(x[i] <= (k-x[i])){
			sum += 2*x[i];
		}
		else{
			sum += 2*(k-x[i]);
		}
	}
	std::cout << sum << std::endl;
}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <vector>

#define REP(i,s,n) for(int i=(int)(s);i<(int)(n);i++)

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

const int N = 370;
ll dp[N][N];
ll ndp[N][N];
const ll inf = 1e15;

int main(void) {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  while (cin >> n && n) {
    vector<PPII> pool;
    REP(i, 0, n) {
      int u, v, w;
      cin >> u >> v >> w;
      v++; // [u, v)
      pool.push_back(PPII(PI(u, v), w));
    }
    sort(pool.begin(), pool.end());
    REP(i, 0, N) {
      REP(j, 0, N) {
	dp[i][j] = -inf;
	ndp[i][j] = -inf;
      }
    }
    dp[0][0] = 0;
    REP(i, 0, n) {
      PPII cur = pool[i];
      int u = cur.first.first;
      int v = cur.first.second;
      ll w = cur.second;
      REP(j, 0, N) {
	ll &ma = ndp[v][j];
	ma = dp[v][j];
	REP(k, 0, u + 1) {
	  ma = max(ma, dp[k][j] + w); 
	}
      }
      REP(j, 0, N) {
	ll &ma = ndp[j][v];
	ma = dp[j][v];
	REP(k, 0, u + 1) {
	  ma = max(ma, dp[j][k] + w); 
	}
      }
      REP(j, 0, N) {
	REP(k, 0, N) {
	  dp[j][k] = max(dp[j][k], ndp[j][k]);
	}
      }
    }
    ll ma = 0;
    REP(i, 0, N) {
      REP(j, 0, N) {
	ma = max(ma, dp[i][j]);
      }
    }
    cout << ma << "\n";
  }
}

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

ll solve() {
    ll N;
    cin >> N;
    vector<ll> A(5);
    ll mn = 1e15;
    for ( int i = 0; i < 5; i++ ) {
        cin >> A[i];
        mn = min(mn, A[i]);
    }
    ll ans = (N+mn-1)/mn + 4;
    return ans;
}

int main() {
    auto ans = solve();
    cout << ans << "\n";
    return 0;
}

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

#define endl '\n'
#define left aba
#define right abc
#define oo if(LOG)
#define pb push_back
#define FIO ios_base::sync_with_stdio(0); cin.tie(0)

#ifdef LOCAL
#define LOG 1
#else
#define LOG 0
#endif

using namespace std;

const int DIG = 10005, MAXD = 105, MOD = (int)(1e9) + 7;

string k;
int d, n;

inline void add(long long &aa, long long bb) {aa += bb; aa %= MOD;}

long long dp[DIG][2][MAXD];

long long go(int pos, bool fl, int sum) {
    if(pos >= n) return sum % d == 0 ? 1 : 0;
    if(dp[pos][fl][sum % d] != -1) return dp[pos][fl][sum % d];

    long long ret = 0;
    for(int i = 0; i <= 9; ++i) {
        if(fl || (!fl && i <= k[pos] - '0')) {
            long long nxt = go(pos + 1, fl | (i < k[pos] - '0'), sum + i);
            add(ret, nxt);
        }
    }
    return dp[pos][fl][sum % d] = ret;
}

int main() {
    FIO;

    cin >> k >> d;
    n = (int)k.size();
    for(int i = 0; i < DIG; ++i) for(int j = 0; j < 2; ++j) for(int l = 0; l < MAXD; ++l) dp[i][j][l] = -1;
    long long ans = go(0, 0, 0) - 1;
    if(ans < 0) ans += MOD;
    cout << ans << endl;

    oo cout << "Time: " << (double)clock() / CLOCKS_PER_SEC << "s" << endl;
    return 0;
}


Measured memory_bytes: 17408
n, m = map(int, input().split())
lr_list = [list(map(int, input().split())) for _ in range(m)]
max_val, min_val = n, 1
for l, r in lr_list:
    if l > min_val:
        min_val = l
    if r < max_val:
        max_val = r
ans = max_val - min_val + 1
if ans < 0:
    ans = 0
print(ans)


Measured memory_bytes: 27336