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

int main(void) {
    long n, k;
    cin >> n >> k;
    vector<vector<long>> b(4*k+1, vector<long>(4*k+1));
    vector<vector<long>> w(4*k+1, vector<long>(4*k+1));

    for(long i=0; i<n; i++) {
        long x, y;
        string c;
        cin >> x >> y >> c;
        x %= 2*k, y %= 2*k;
        x++, y++;
        (c[0] == 'B' ? b : w)[y][x]++;
        (c[0] == 'B' ? b : w)[y][x+2*k]++;
        (c[0] == 'B' ? b : w)[y+2*k][x]++;
        (c[0] == 'B' ? b : w)[y+2*k][x+2*k]++;
    }

    for(long i=1; i<4*k; i++)
        for(long j=1; j<4*k; j++)
            b[i][j] += b[i-1][j] + b[i][j-1] - b[i-1][j-1];

    for(long i=1; i<4*k; i++)
        for(long j=1; j<4*k; j++)
            w[i][j] += w[i-1][j] + w[i][j-1] - w[i-1][j-1];

    long r = 0;
    for(long i=0; i<2*k; i++)
    for(long j=0; j<2*k; j++) {
        long t = 0;
        t += b[i+k][j+k] - b[i+k][j] - b[i][j+k] + b[i][j];
        i+=k, j+=k;
        t += b[i+k][j+k] - b[i+k][j] - b[i][j+k] + b[i][j];

        i-=k;
        t += w[i+k][j+k] - w[i+k][j] - w[i][j+k] + w[i][j];
        i+=k, j-=k;
        t += w[i+k][j+k] - w[i+k][j] - w[i][j+k] + w[i][j];
        i-=k;

        r = max(r, t);
    }
    cout << r << endl;
}


Measured memory_bytes: 250624
#include <bits/stdc++.h>
#define REP(i, e) for(int (i) = 0; (i) < (e); ++(i))
#define FOR(i, b, e) for(int (i) = (b); (i) < (e); ++(i))
#define ALL(c) (c).begin(), (c).end()
#define PRINT(x) cout << (x) << "\n"
using namespace std;
using ll = long long; using pint = pair<int, int>; using pll = pair<ll, ll>;
template<typename T> auto compare = [](T x, T y) -> bool{return (x < y);};
const int MOD = 1000000007;

signed main(){
    int N;
    cin >> N;
    PRINT(N * (N - 1) / 2 - N / 2);
    FOR(i, 1, N){
        FOR(j, i + 1, N + 1){
            if(N % 2 == 0 && i + j == N + 1) continue;
            if(N % 2 == 1 && i + j == N) continue;
            cout << i << " " << j << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef long double ld;
const int inf=1e9+7;
const ll longinf=1LL<<60;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define F first
#define S second
 
const int mx=100010;
const ll mod=1e9+7;


int main(){
  int n,k;
  cin >> n >> k;
  int pos;
  rep(i,n){
    int a; cin >> a;
    if(a==1){ pos = i; }
  }
  cout << (n-k+(k-2))/(k-1) +1 << endl;
  return 0;
}


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

using namespace std;

long long f[1000000], rf[1000000];
long long mod = 1000000007;

long long inv(long long x) {
  long long res = 1;
  long long k = mod - 2;
  long long y = x;
  while (k) {
    if (k & 1) res = (res * y) % mod;
    y = (y * y) % mod;
    k /= 2;
  }
  return res;
}

void init() {
  f[0] = 1;
  for (int i = 1; i < 1000000; i++) f[i] = (f[i - 1] * i) % mod;
  for (int i = 0; i < 1000000; i++) rf[i] = inv(f[i]);
}
int main() {
  int x, y;
  cin >> x >> y;
  if ((x + y) % 3 != 0) {
    // 到達不能
    cout << 0 << endl;
    return 0;
  }
  init();
  long long n = (x + y) / 3;
  long long k = x - n;
  if (k < 0 || n - k < 0) {
    cout << 0 << endl;
    return 0;
  }
  long long a = f[n];
  long long b = rf[n - k];
  long long c = rf[k];

  long long bc = (b * c) % mod;
  cout << ((a * bc) % mod) << endl;
  return 0;
}

Measured memory_bytes: 15872
#include <bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define pb push_back
#define mp make_pair
#define ll long long int
#define vi vector<int>
#define vl vector<ll>
#define ppi pair<int,int>
#define ppl pair<ll,ll>
#define all(x) x.begin(),x.end()
#define ii int,int 
#define mm map<ii>
#define ff first    
#define ss second
#define forn(i,a,b) for(int i=a;i<b;i++)
#define forr(i,a,b) for(int i=a;i>=b;i--)
#define forv(i,m) for(auto i : m)
#define imx INT_MAX
#define imn INT_MIN
#define inf LONG_MAX
#define minf LONG_MIN
#define endl "\n"
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);
#define sze size()
#define rvs reverse 
#define itr iterator 

/*
#define MODM(a,b,md) ((a%md)*(b%md))%md
#define MODA(a,b,md) ((a%md)+(b%md))%md
#define ull unsigned long long int
#define si short int
*/

/*
bool compare(int a,int b) {return a > b;}
bool compare1(ppi a,ppi b) {return a.ff > b.ff;}
bool compare2(ppi a,ppi b) {return a.ss < b.ss;}
ll Npower(ll a,ll b) {ll product = 1; while(b){if(b&1){product = product*a;}a = a*a;b = b>>1;} return product;}
ll power(ll a,ll b,ll md) {ll product = 1; while(b){if(b&1){product = MODM(product,a,md);}a = MODM(a,a,md);b = b>>1;} return product%md;}
ll GCD(ll a,ll b) {return b==0 ? a:GCD(b,a%b);}
ll LCM(ll a,ll b) {return (a/GCD(a,b))*b; }
*/


int main()
{
    fast

    ll a,b;
    cin>>a>>b;

    if((b-a+1) >= 2019) 
    {
        cout<<0;
    }
    else
    {

        ll mini = inf;
        for(ll i = a; i < b; i++)
        {
            for(ll j = i+1; j < b+1; j++)
            {
                mini = min(mini,(i*j)%2019);
            }
        }

        cout<<mini;
    }


    return 0;
}   

Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <algorithm>
#include <complex>
#include <array>
#include <iomanip>
using namespace std;

#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<long double> VD;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef vector<VD> VVD;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

template<typename T> void chmin(T &a, T b) { if (a > b) a = b; }
template<typename T> void chmax(T &a, T b) { if (a < b) a = b; }

int in() { int x; scanf("%d", &x); return x; }
ll lin() { ll x; scanf("%lld", &x); return x; }
#define INF 1LL<<60

int main() {
    int N;
    string S;
    cin >> N >> S;
    char prev = ' ';
    int count = 0;
    REP(i, S.length()) {
        if(S[i] == 'A') {
            prev = 'A';
        } else if(S[i] == 'B' && prev == 'A') {
            prev = 'B';
        } else if(S[i] == 'C' && prev == 'B') {
            prev = 'C';
            count++;
        } else if(S[i] == 'B' || S[i] == 'C') {
            prev = ' ';
        }
    }
    cout << count << endl;
    return 0;
}

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

const int MAXN = 64;
int mem[MAXN];

vector<int> split(int y) {
  vector<int> res;
  for(int k = 0; (k|y); y >>= 1) {
    if(y & 1) {
      ++k;
    } else {
      if(k) {
        res.push_back(k);
        k = 0;
      }
    }
  }
  return res;
}

int grundy(int x) {
  int &res = mem[x];
  if(res != -1) return res;
  set<int> s;
  for(int i = 1; i <= x; ++i) {
    vector<int> v = split(x - i);
    int ni = 0;
    for(int j = 0; j < v.size(); ++j) {
      ni ^= grundy(v[j]);
    }
    s.insert(ni);
  }
  res = 0;
  while(s.count(res)) ++res;
  return res;
}

int toDec(int p, string s) {
  reverse(s.begin(), s.end());
  int res = 0;
  for(int i = 0, b = 1; i < s.size(); ++i, b *= p) {
    int a = 
      isdigit(s[i]) ? s[i]-'0' : isupper(s[i]) ? s[i]-'A'+10 : s[i]-'a'+36;
    res += a * b;
  }
  return res;
}

int main() {
  fill(mem, mem+MAXN, -1);
  for(int n; cin >> n;) {
    int x = 0;
    for(int i = 0; i < n; ++i) {
      int p;
      string s;
      cin >> p >> s;
      vector<int> v = split(toDec(p, s));
      for(int j = 0; j < v.size(); ++j) {
        x ^= v[j];
        //x ^= grundy(v[j]);
      }
    }
    if(x) cout << "win" << endl;
    else cout << "lose" << endl;
  }
  return 0;
}

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

using namespace std;
const int N = 1e5+100;
const int mod = 1e9+7;
long long dp[N][14];
char s[N];
int main(){
	int n;
	scanf("%s",s+1);
	n=strlen(s+1);
	dp[0][0]=1;
	for(int i=1;i<=n;i++){
		if(s[i]=='?'){
			for(int j=0;j<=9;j++){
				for(int k=0;k<=12;k++){
					dp[i][(k*10+j)%13]+=dp[i-1][k];
					dp[i][(k*10+j)%13]%=mod;
				}
			}
		}
		else{
			for(int k=0;k<=12;k++){
				dp[i][(k*10+s[i]-'0')%13]=dp[i-1][k];
				dp[i][(k*10+s[i]-'0')%13]%=mod;
			}
		}
	}
	cout<<dp[n][5]<<endl;
	return 0;
}

Measured memory_bytes: 11264
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <utility>
#include <iomanip>
#include <tuple>
#include <numeric>
#include <cstdio>
#include <cmath>
using namespace std;
using ll = long long;
const int INF = 1e9;

void solve1() {
    // upper 121
    int i = 0;
    int ret = 0;
    while (true) {
        if (ret > INF || ret < 0) {
            cout << i << " " << ret << endl;
            break;
        }
        ret = pow(i, 5) - pow(i-1, 5);
        i++;
    }
}

void solve2() {
    // lower -120
    int i = 0;
    int ret = 0;
    while (true) {
        if (ret > INF || ret < 0) {
            cout << i << " " << ret << endl;
            break;
        }
        ret = pow(i, 5) - pow(i-1, 5);
        i--;
    }
}

int main() {
//    solve1();
//    solve2();

    int x; cin >> x;
    for (int i = -120; i <= 121; i++) {
        for (int j = - 120; j <= 121; j++) {
            if (pow(i, 5) - pow(j, 5) == x) {
                cout << i << " " << j << endl;
                return 0;
            }
        }
    }
}



Measured memory_bytes: 3564
#include<stdio.h>
#include<stdlib.h>

#define N 2000000
#define infty 1000000000

int n = 0, A[N];

void max_heapify(int);
int parent(int);
int right(int);
int left(int);
int extract(void);
void increase_key(int, int);
void insert(int);

int main(){
  char com[10];
  int num;

  while(1){
    scanf("%s", com);

    if(com[0] == 'e' && com[1] == 'n')
      break;

    else if(com[0] == 'i'){
      scanf("%d", &num);
      insert(num);
    }

    else
      printf("%d\n", extract());
  }

  return 0;
}

void max_heapify(int i){
  int l, r, biggest, tmp;

  l = left(i);
  r = right(i);

  if(l <= n && A[l] > A[i])
    biggest = l;

  else
    biggest = i;

  if(r <= n && A[r] > A[biggest])
    biggest = r;

  if(biggest != i){
    tmp = A[i];

    A[i] = A[biggest];
    A[biggest] = tmp;

    max_heapify(biggest);
  }
}

int parent(int i){
  return i / 2;
}

int right(int i){
  return (i * 2) + 1;
}

int left(int i){
  return i * 2;
}

int extract(){
  int max;
    
  max = A[1];
  A[1] = A[n];
  n--;
  max_heapify(1);

  return max;
}

void increase_key(int i, int num){
  int temp;
  
  if(num < A[i])
    return;

  A[i] = num;

  while(i > 1 && A[parent(i)] < A[i]){
    temp = A[i];
    A[i] = A[parent(i)];
    A[parent(i)] = temp;

    i = parent(i);
  }
}

void insert(int num){
  n++;
  A[n] = -infty;
  increase_key(n, num);
}



Measured memory_bytes: 5604
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <fstream>
#include <cassert>
#include <cstring>
#include <numeric>
#include <ctime>
#include <complex>
#include <bitset>
#include <random>

using namespace std;

typedef long long ll;
typedef long double ld;

#define int ll
#define double ld
#define loop(i, n) for(int i = 0; i < (int)n; ++i)
#define loop1(i, n) for(int i = 1; i <= (int)n; ++i)
#define F first
#define S second
#define pb push_back
#define pi pair <int, int>
#define all(x) begin(x), end(x)
#define ti tuple <int, int, int>
#define Point Vect
#define no {cout << "No\n"; return;}

void solve() {
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    cout << ((b + c - 1) / b <= (d + a - 1) / d ? "Yes" : "No");
}

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    //int t; cin >> t; loop(i, t)
    solve();
    return 0;
}


Measured memory_bytes: 3648
#include<bits/stdc++.h>
using namespace std;
deque<int>l;
int n,w;
int main(){
    cin>>n;
    for(int i=n%2;i<n+n%2;i++){
        cin>>w;
        if(i%2==0)l.push_back(w);
        else l.push_front(w);
    }
    for(deque<int>::iterator i=l.begin();i!=l.end();i++)cout<<*i<<" ";
}

Measured memory_bytes: 2944
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define mod 1000000007
#define fi first
#define sc second
#define rep(i,x) for(long long i=0;i<x;i++)
#define repn(i,x) for(long long i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
vector<pair<string,P> >vec;
// vector<vector<int>> data(3, vector<int>(4));

void solve(long long N, vector<long long> T, vector<long long> A){
	bool fixt[N], fixa[N];
	rep(i, N) {
		if (i == 0 || T[i] > T[i-1]) fixt[i] = true; else fixt[i] = false;
 	}
	rep(i, N) {
		if (i == N-1 || A[i] > A[i+1]) fixa[i] = true; else fixa[i] = false;
 	}
	ll res = 1;
	rep(i, N) {
		if (!fixt[i] && !fixa[i]) res = res*min(T[i], A[i])%mod;
		if (fixt[i] && !fixa[i] && T[i] > A[i]) res = 0;
		if (!fixt[i] && fixa[i] && T[i] < A[i]) res = 0;
		if (fixt[i] && fixa[i] && T[i] != A[i]) res = 0;
		// cout << i << " " << res << endl;
	}
	cout << res << endl;
}

int main(){	
	long long N;
	scanf("%lld",&N);
	vector<long long> A(N-1+1);
	vector<long long> T(N-1+1);
	for(int i = 0 ; i <= N-1 ; i++){
		scanf("%lld",&T[i]);
	}
	for(int i = 0 ; i <= N-1 ; i++){
		scanf("%lld",&A[i]);
	}
	solve(N, T, A);
	return 0;
}



Measured memory_bytes: 3584
x1, y1, x2, y2 = map(int, input().split())
dx = x2 - x1
dy = y2 - y1
x3, y3 = x2 - dy, y2 + dx
x4, y4 = x3 - dx, y3 - dy
print('{} {} {} {}'.format(x3, y3, x4, y4))

Measured memory_bytes: 3060
#include<iostream>
#include<map>
#include<string>
using namespace std;
map<string,int> M;
int n;
string prestr;
string str;
int main()
{
    ios::sync_with_stdio(false);
    while(cin>>n)
    {
        M.clear();
        cin>>prestr;
        M[prestr]++;
        int flag=0;
        for(int i=1;i<n;i++)
        {
            cin>>str;
            if(str[0]!=prestr[prestr.length()-1]) flag=1;
            M[str]++;
            if(M[str]!=1) flag=1;
            prestr=str;
        }
        if(flag==1) cout<<"No"<<endl;
        else cout<<"Yes"<<endl;
    }
}

Measured memory_bytes: 256
n = int(input())
total = 0
for i in range(n) :
    x = int(input())
    a = 1
    b = True
    if x == 1 :
        b = False
    while a**2 < x and x != 2 :
        a += 1
        if x%a == 0 :
            b = False
            break  
    if b :
        total += 1
print (total)


Measured memory_bytes: 5608
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const int N = 200010;
struct Edge
{
    int next;
    int dis;
    int to;
}edge[N*2];
int head[N*2];
int res[N*2];
int r[N*2];
int tot;
int n,m;
bool vis[N*2];
inline void add(int from,int to)
{
    edge[++tot].next = head[from];
    edge[tot].to = to;
    head[from] = tot;
}
void init()
{
    memset(head,-1,sizeof(head));
}
void dfs(int id)
{
    vis[id] = 1;
    for(int i = head[id];~i;i = edge[i].next)
    {
        int y = edge[i].to;
        if(!vis[y]) res[y] += res[id],dfs(y);
    }
}
int main()
{
  //freopen("input.txt","r",stdin);
   init();
   scanf("%d%d",&n,&m);
   int f,t;
   for(int i = 1;i<=n-1;++i)
   {
       scanf("%d%d",&f,&t);
       add(f,t);
       add(t,f);
   }
   for(int i = 1;i<=m;++i)
   {
       scanf("%d%d",&f,&t);
       res[f] += t;
   }
   dfs(1);
   for(int i = 1;i<=n;++i)
    printf("%d ",res[i]);
}


Measured memory_bytes: 16640
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<iostream>
#include<algorithm>
#include<string>
using namespace std;

string S;

int main(void)
{

	cin >> S;

	if (S.size()==2)
	{
		cout << S << endl;
	}
	else if (S.size()==3)
	{
		for (int i = 2; i >= 0; i--)
		{
			cout << S[i];
		}

		cout << endl;
	}

	return 0;
}

Measured memory_bytes: 256
n = int(input())
a = list(map(int,input().split()))
a = sorted(a)
x = a.pop(-1)
x2 = x/2
ans = a[0]
t = abs(x2-ans)
for i in a:
  if abs(x2-i) < t:
    ans = i
    t = abs(x2-ans)
print(x,ans)

Measured memory_bytes: 62704
A = []
for i in range(3):
    A += list(map(int,input().split()))
N = int(input())
B = []
for i in range(N):
    B.append(int(input()))
B = set(B)

c = [[0,0,0],[0,0,0],[0,0,0]]
P = [{0,3,6},{1,4,7},{2,5,8},{0,1,2},{3,4,5},{6,7,8},{0,4,8},{2,4,6}]

r = []
for i,a in enumerate(A):
    if a in B:
        r.append(i)
r = set(r)

for p in P:
    if p.issubset(r):
        print('Yes')
        break
else:
    print('No')

Measured memory_bytes: 3064
#include<iostream>
#include<string>
#include<algorithm>
#include<math.h>
#include<queue>
#include<set>
#include<map>
#include<random>
#include<functional>
#include<utility>

#define rep(i,n) for(int i=0; i<n; i++)
#define pb push_back
#define P pair<int, int>
#define PLI pair<ll, int>

using namespace std;

typedef long long ll;


int main() {
	int N;
	cin >> N;
	vector<pair<ll, ll>> p(N);
	rep(i, N) {
		ll a, b;
		cin >> a >> b;
		p[i] = { a, b };
	}

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

	ll ans = 0, sum = 0;
	rep(i, N) {
		ll a = p[i].first, b = p[i].second;
		sum = max(sum + b, a + b);
		ans = max(ans, sum - a);
	}

	cout << ans << endl;

	return 0;
}




Measured memory_bytes: 10732
//#pragma GCC optimize("Ofast")
//#pragma GCC target("avx")
//#pragma GCC optimize ("unroll-loops")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;
using namespace std;

#define fi first
#define se second
#define pb push_back
#define sz(x)  ((int)x.size ())
#define all(x) (x).begin(), (x).end()
#define re return
#define mp make_pair
#define sqrt(x) sqrt (abs(x))
#define y0 y3451
#define y1 y4562
#define j0 j25624
#define j1 j45624
#define makeunique(x) sort(all(x)), (x).resize (unique(all(x)) - (x).begin())

typedef pair <int, int> ii;
typedef long long ll;
typedef unsigned long long ull;
typedef double D;
typedef long double ld;
typedef unsigned int uint;
typedef vector <string> vs;
typedef vector <int> vi;
typedef vector <ii> vii;
typedef vector <vi> vvi;

template <class T> using _tree = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template <class T> T abs (T x) { re x > 0 ? x : -x; }
template <class T> T sqr (T x) { re x * x; }
template <class T> T gcd (T a, T b) { re a ? gcd (b % a, a) : b; }
template <class T> int sgn (T x) { re x > 0 ? 1 : (x < 0 ? -1 : 0); }

#define filename ""

const D pi = acos(-1.);
const int N = 2e5 + 20;
const int inf = 1e9 + 7;

int n, m;
int a[200];
int dp[N];

int main() {
	cin >> n >> m;
	for (int i = 0; i < n; i++) cin >> a[i];
	for (int i = 1; i <= m; i++)
		for (int j = 0; j < n; j++)
			if (i - a[j] >= 0 && !dp[i - a[j]])
				dp[i] = 1;
	if (dp[m]) cout << "First";
	else cout << "Second";
	return 0;
}


Measured memory_bytes: 640
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<iostream>
#include<queue>
#include<vector>
#include <bitset>
using namespace std;
#define MOD 1000000007
typedef long long ll;
typedef pair<ll,int> P;

int main(){
  ll N,A[110000],ans[110000],sum=0;
  cin>>N;

  for(int i=0;i<N;i++){
    cin>>A[i];
    sum+=A[i];
    if(i%2==1) sum-=2*A[i];
  }
  ans[0]=sum;
  for(int i=1;i<N;i++){
    ans[i]=2*A[i-1]-ans[i-1];
  }
  cout<<ans[0];
  for(int i=1;i<N;i++){
    cout<<" "<<ans[i];
  }
}


Measured memory_bytes: 2944
#include "bits/stdc++.h"
using namespace std;

#define ASC(vec) vec.begin(), vec.end()		// 昇順ソート 例：sort(ASC(vec));
#define DESC(vec) vec.rbegin(), vec.rend()	// 降順ソート 例:sort(DESC(vec));
#define rep(i, n) for(int i = 0; i < (n); i++)
#define Rep(i, n) for(int i = 1; i < n; i++)

const int mod = 1000000007;
const int inf = (1 << 21);
const long long INF = 1LL << 60;

using ii = pair<int, int>;
using ll = long long;
using vi = vector<int>;
using vd = vector<double>;
using vb = vector<bool>;
using vl = vector<ll>;
using vs = vector<string>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<ll>>;
using vvb = vector<vector<bool>>;
using vii = vector<pair<int, int>>;

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 GCD(ll a, ll b) { return b ? GCD(b, a % b) : a; }
ll LCM(ll a, ll b) { return (a * b) / GCD(a, b); }
int round_int(int a, int b) { return (a + (b - 1)) / b; }

constexpr array<int, 9> dx = { 0, 1, 0, -1, -1, 1, 1, -1, 0 };
constexpr array<int, 9> dy = { 1, 0, -1, 0, 1, 1, -1, -1, 0 };

// ──────────────────────────────────────────────────────────────────

struct UnionFind {
    vector<int> d;
    UnionFind(int n = 0) : d(n, -1) {}
    int find(int x) {
        if (d[x] < 0) return x;
        return d[x] = find(d[x]);
    }
    bool unite(int x, int y) {
        x = find(x); y = find(y);
        if (x == y) return false;
        if (d[x] > d[y]) swap(x, y);
        d[x] += d[y];
        d[y] = x;
        return true;
    }
    bool same(int x, int y) { return find(x) == find(y); }
    int size(int x) { return -d[find(x)]; }
};

int main() {
    int n, q;
    cin >> n >> q;

    UnionFind uf(n);
    int f, x, y;
    rep(i, q) {
        cin >> f >> x >> y;

        if (f) {
            if (uf.same(x, y)) cout << 1 << endl;
            else cout << 0 << endl;
        }
        else {
            uf.unite(x, y);
        }
    }
}


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

typedef long long ll;

template<typename T>
void out(T x) { cout << x << endl; exit(0); }
#define watch(x) cout << (#x) << " is " << (x) << endl

const int maxn = 1e6 + 5;

int main() {
  ios_base::sync_with_stdio(false); cin.tie(0);  cout.tie(0);
  cout << fixed << setprecision(12);
  map<int,int> mp;
  int n; cin>>n;
  while (n--) {
    int x; cin>>x;
    mp[x]++;
  }
  int best = 0;
  for (auto p: mp) {
    int i = mp.count(p.first-1) ? mp[p.first-1] : 0;
    int j = mp.count(p.first+1) ? mp[p.first+1] : 0;
    int cur = p.second + i + j;
    best = max(best, cur);
  }
  cout<<best;
  

  return 0;
}


Measured memory_bytes: 3200
def solve():
    N=int(input())
    b=list(map(int,input().split()))
    for i,bi in enumerate(b):
        if bi>i+1:
            print(-1)
            return
    ans=[]
    for bi in b:
        ans.insert(bi-1,bi)
    for a in ans:
        print(a)

solve()


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

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define FORR(i, a, b) for (int i = (int)(b)-1; i >= (int)(a); i--)

#define DEBUG(x) cout << #x << ": " << (x) << endl
#define DEBUG_VEC(v) cerr<<#v<<": ";REP(__i,(v).size())cerr<<((v)[__i])<<", ";cerr<<endl
#define PRINT(x) cout << x << endl
#define all(x) x.begin(),x.end()

int main() {
    int N;
    string s,t;
    cin >> N;
    cin >> s >> t;
    string ans = "";

    for(int i=0;i<N;i++){
        ans += s[i];
        ans += t[i];
    }

    cout << ans << endl;

}



Measured memory_bytes: 256
//shan61916
#include <bits/stdc++.h>
  using namespace std;
typedef   long long ll;
typedef   unsigned long long ull ;
typedef   double dll ;

#define   mp make_pair
#define   pb push_back
#define   ff first 
#define   ss second
#define   IOS ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define   endl "\n" 
#define   pll pair<ll, ll>
#define   all(x) x.begin(), x.end()
#define   vll vector<ll> 


int main(){
 IOS
#ifdef SHAN
    freopen("input.txt" , "r" , stdin);  
#endif
  string a, b;
  cin >> a >> b;
  ll ct = 0;
  for(ll i = 0; i < 3; i++) if(a[i] == b[i]) ct++ ;
  cout << ct ;
  return 0;
} //good night.s

Measured memory_bytes: 256
///in the name of Allah the most beneficent the most merciful.
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define MAX 1e18
#define MIN -1e18
#define MOD 998244353
//#define mod2 20071027
//#define MOD 998244353
#define rep(i,a) for(int i=0;i<a;i++)
#define rep1(i,a) for(int i=1;i<=a;i++)
#define base 139
//#define mod 1000074259
#define base2 31
#define memz(a) memset(a, 0, sizeof(a))
#define memn(a) memset(a, -1, sizeof(a))
#define in1(a) scanf("%lld", &a)
#define in2(a, b) scanf("%lld%lld", &a, &b)
#define TC(c) printf("Case #%lld: ", ++c)
#define FAST ios_base::sync_with_stdio(false); cin.tie(NULL);
using namespace std;
const ll N=300010, M=1000005;
ll n, x, a[N];
int main()
{
    in2(n,x);
    ll r = (2*n)-1, l=1;
    if(x==l || x==r)
    {
        printf("No\n");
        return 0;
    }
    else
    {
        a[n-1]=x;
        ll i=n-2,val=1;
        while(i>=0)
        {
            if(val==x) val++;
            a[i]=val;
            val++;
            i--;
        }
        i=n, val=r;
        while(i<r)
        {
            if(val==x) val--;
            a[i]=val;
            val--;
            i++;
        }
    }
    printf("Yes\n");
    for(int i=0;i<r;i++)
    {
        printf("%lld\n", a[i]);
    }

    return 0;
}
/*

*/


Measured memory_bytes: 3072
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <string>
#include <vector>
using namespace std;


int main(){
  string s;
  cin >> s;

  int n = 0;

  for(int i=0; i<s.size(); i++){
    if(s[i] == '+'){
      n += 1;
    }else{
      n -= 1;
    }
  }

  cout << n << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int N = 1e5 + 7;
const int MOD = 1000 * 1000 * 1000 + 7;
int mod(int n) {
    return (n % MOD + MOD) % MOD;
}   
int a[N];
int dp1[N], dp2[N];
int ptr[N];
signed main() {
    #ifdef HOME
    freopen("input.txt", "r", stdin);
    #else
    ios_base::sync_with_stdio(0); cin.tie(0);
    #endif
    int n, x;
    cin >> n >> x;
    for (int i = 0; i < n; ++i) cin >> a[i];
    sort(a, a + n);

    int u = 0;
    for (int i = 0; i < N; ++i) {
        while (u < n && a[u] <= i) ++u;
        ptr[i] = u;
    }   

    dp1[x] = 1;
    for (int t = 0; t < n; ++t) {
        for (int i = 0; i < N; ++i) {
            dp2[i] = 0;
        }   
        for (int i = 0; i < N; ++i) {
            if (dp1[i]) {
                int cnt = n - ptr[i];
                dp2[i] = mod(dp2[i] + dp1[i] * (cnt - t));
                for (int j = 0; j < ptr[i]; ++j) {
                    int to = i % a[j];
                    dp2[to] = mod(dp2[to] + dp1[i]);                    
                }   
            }   
        }   
        for (int i = 0; i < N; ++i) {
            dp1[i] = dp2[i];
        }   
    }   
    int ans = 0;
    for (int i = 0; i < N; ++i) {
        ans = mod(ans + dp1[i] * i);
    }   
    cout << ans << '\n';
}   

Measured memory_bytes: 2688
// abc112_d
#include <bits/stdc++.h>
#ifdef LOCAL
#include "../cxx-prettyprint/prettyprint.hpp"
#endif
using namespace std;

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

#define REP(i, n) for (int (i) = 0 ; (i) < (int)(n) ; ++(i))
#define REPN(i, m, n) for (int (i) = m ; (i) < (int)(n) ; ++(i))
#define REP_REV(i, n) for (int (i) = (int)(n) - 1 ; (i) >= 0 ; --(i))
#define REPN_REV(i, m, n) for (int (i) = (int)(n) - 1 ; (i) >= m ; --(i))
#define ALL(x) x.begin(), x.end()

#define INF ((1 << 29)-1)
#define MOD (1000000007)

#define print2D(h, w, arr) REP(i, h) { REP(j, w) cout << arr[i][j] << " "; cout << endl; }
#define print_line(vec, n) {for(int i=0;i<(n-1);i++) cout << (vec)[i] << " "; cout << (vec)[(n)-1] << endl;}
template<class T> void print(const T& x){cout << x << endl;}
template<class T, class... A> void print(const T& first, const A&... rest) { cout << first << " "; print(rest...); }
struct PreMain {PreMain(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(20);}} premain;

int main() {
#ifdef LOCAL
    ifstream in("../arg.txt"); cin.rdbuf(in.rdbuf());
#endif

    int N;
    cin >> N;
    
    if (N == 1){
        print("Hello World");
    } else {
        int a, b;
        cin >> a >> b;
        print(a + b);
    }

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
typedef long long ll;

int main(){
    ll n,m;
    cin >> n >> m;
    //char ans[n];
    //string s = "";
    int s[n];
    bool ok = true;
    for(int i = 0; i < n; i++){
        s[i] = -1;
    }
    for(int i = 0; i < m; i++){
        ll temp1,temp2;
        cin >> temp1 >> temp2;
        if(s[temp1-1] != -1 && s[temp1-1] != temp2){
            ok = false;
        }
        else{
            s[temp1-1] = temp2;
        }
    }
    if(n > 1 && s[0] == 0) ok = false;
    if(n == 1 && s[0] == -1) s[0] = 0;
    if(n > 1){
        for(int i = 0; i < n; i++){
            if(i == 0 && s[i] == -1) s[0] = 1;
            else if(s[i] == -1) s[i] = 0;
        }
    }
    if(ok){
        for(int i = 0; i < n; i++){
            cout << s[i];
        }
    }
    else cout << -1 ;
    cout << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define inf INT_MAX
#define INF LLONG_MAX
#define ll long long
#define ull unsigned long long
#define M (int)(1e9+7)
#define P pair<int,int>
#define FOR(i,m,n) for(int i=(int)m;i<(int)n;i++)
#define RFOR(i,m,n) for(int i=(int)m;i>=(int)n;i--)
#define rep(i,n) FOR(i,0,n)
#define rrep(i,n) RFOR(i,n,0)
#define all(a) a.begin(),a.end()
const int vx[4] = {0,1,0,-1};
const int vy[4] = {1,0,-1,0};
#define F first
#define S second
#define PB push_back
#define EB emplace_back
#define int ll
#define vi vector<int>
#define IP pair<int,P>
#define PI pair<P,int>
#define PP pair<P,P>
#define Yes(f){cout<<(f?"Yes":"No")<<endl;}
#define YES(f){cout<<(f?"YES":"NO")<<endl;}

int h,w;
char s[30][30];
int d[30][30];

int f(int y,int x){
  rep(i,h+1){
    rep(j,w+1){
      d[i][j]=inf;
    }
  }

  d[y][x]=0;
  queue<P> q;
  q.push(P(x,y));
  while(q.size()){
    P p=q.front(); q.pop();
    rep(k,4){
      int i=p.S+vy[k];
      int j=p.F+vx[k];
      if(!(0<=i&&i<h&&0<=j&&j<w)) continue;
      if(s[i][j]=='#') continue;
      if(d[p.S][p.F]+1<d[i][j]){
        d[i][j]=d[p.S][p.F]+1;
        q.push(P(j,i));
      }
    }
  }

  int res=0;
  rep(i,h){
    rep(j,w){
      if(s[i][j]=='#') continue;
      res=max(res,d[i][j]);
    }
  }

  return res;
}

signed main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout<<fixed<<setprecision(20);

  cin>>h>>w;
  rep(i,h){
    cin>>s[i];
  }

  int ans=0;
  rep(i,h){
    rep(j,w){
      if(s[i][j]=='#') continue;
      ans=max(ans,f(i,j));
    }
  }

  cout<<ans<<endl;


}


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

using namespace std;

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)

typedef vector<int> vi;

int main() {
	int n;
	vi v(2001, 0);
	REP(i, 1001) REP(j, 1001) {
		 v[i+j]++;
	}
	
	while (cin >> n) {
		long long ans = 0;
		REP(i, 1001) REP(j, 1001) {
			int k = n - i - j;
			if (k < 0 || k > 2000) continue;
			ans += v[k];
		}
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 1196
// g++ -std=c++11 a.cpp
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<unordered_map>
#include<utility>
#include<cmath>
#include<random>
#include<cstring>
#include<queue>
#include<stack>
#include<bitset>
#include<cstdio>
#include<sstream>
#include<iomanip>
#include<assert.h>
#include<typeinfo>
#define loop(i,a,b) for(long long i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
#define FOR(i,a) for(auto i:a)
#define pb push_back
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
#define show1d(v) {rep(_,v.size())cout<<" "<<v[_];cout<<endl;}
#define show2d(v) {rep(__,v.size())show1d(v[__]);}
using namespace std;
//kaewasuretyuui
typedef long long ll;
#define int ll
typedef int Def;
typedef pair<Def,Def> pii;
typedef vector<Def> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<Def,pii> pip;
typedef vector<pip>vip;
#define mt make_tuple
typedef tuple<int,int,int,int> tp;
typedef vector<tp> vt;
template<typename A,typename B>bool cmin(A &a,const B &b){return a>b?(a=b,true):false;}
template<typename A,typename B>bool cmax(A &a,const B &b){return a<b?(a=b,true):false;}
const double PI=acos(-1);
const double EPS=1e-9;
Def inf = sizeof(Def) == sizeof(long long) ? 2e18 : 1e9+10;
#define yes cout<<"Yes\n"
#define no cout<<"No\n"

signed main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	
	int a,b,c;
	cin>>a>>b>>c;
	if(a==b&&b!=c)yes;
	else if(b==c&&c!=a)yes;
	else if(a==c&&a!=b)yes;
	else no;
	
}









Measured memory_bytes: 768
#include <cmath>
#include <iostream>

using namespace std;

int main() {
  int x;
  cin >> x;
  int m = 1;
  int stop = sqrt(x);
  for (int i = 2; i <= stop; i++) {
    int b = i;
    while (b * i <= x) {
      b *= i;
    }
    m = max(m, b);
  }
  cout << m << endl;
  return 0;
}


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

int main(){
  int a,b,c,d;
  cin>>a>>b>>c>>d;
  while(1){
    c=c-b;
    if(c<=0){
      cout<<"Yes"<<endl;
      break;
    }
    a=a-d;
    if(a<=0){
      cout<<"No"<<endl;
      break;
    }
  }
  
  return 0;
}

Measured memory_bytes: 3616
package main

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

func getScanner(fp *os.File) *bufio.Scanner {
	scanner := bufio.NewScanner(fp)
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 500001), 500000)
	return scanner
}

func getNextString(scanner *bufio.Scanner) string {
	scanner.Scan()
	return scanner.Text()
}

func getNextInt(scanner *bufio.Scanner) int {
	i, _ := strconv.Atoi(getNextString(scanner))
	return i
}

func getNextInt64(scanner *bufio.Scanner) int64 {
	i, _ := strconv.ParseInt(getNextString(scanner), 10, 64)
	return i
}

func getNextUint64(scanner *bufio.Scanner) uint64 {
	i, _ := strconv.ParseUint(getNextString(scanner), 10, 64)
	return i
}

func getNextFloat64(scanner *bufio.Scanner) float64 {
	i, _ := strconv.ParseFloat(getNextString(scanner), 64)
	return i
}

func main() {
	fp := os.Stdin
	wfp := os.Stdout

	if len(os.Args) > 1 {
		fp, _ = os.Open(os.Args[1])
		if len(os.Args) > 2 {
			wfp, _ = os.Create(os.Args[2])
		}
	}

	scanner := getScanner(fp)
	writer := bufio.NewWriter(wfp)

	n := getNextInt(scanner)
	tree := make([][]Node, n)
	for i := 0; i < n; i++ {
		tree[i] = make([]Node, 0)
	}

	for i := 0; i < n-1; i++ {
		s := getNextInt(scanner)
		t := getNextInt(scanner)
		w := getNextInt(scanner)
		tree[s] = append(tree[s], Node{
			to: t,
			w:  w,
		})
		s, t = t, s
		tree[s] = append(tree[s], Node{
			to: t,
			w:  w,
		})
	}

	sol := Solve{}

	sol.tree = tree
	sol.dist = make([]int, n)
	sol.dfs(0, -1)
	d := -1
	x := -1
	for i := 0; i < n; i++ {
		if d < sol.dist[i] {
			x = i
			d = sol.dist[i]
		}
	}
	sol.dist = make([]int, n)
	sol.dfs(x, -1)
	d = -1
	y := -1
	for i := 0; i < n; i++ {
		if d < sol.dist[i] {
			y = i
			d = sol.dist[i]
		}
	}

	fmt.Fprintln(writer, sol.dist[y])
	writer.Flush()
}

type Solve struct {
	tree [][]Node
	dist []int
}

func (sol *Solve) dfs(i, p int) {
	for _, node := range sol.tree[i] {
		if node.to == p {
			continue
		}
		sol.dist[node.to] = sol.dist[i] + node.w
		sol.dfs(node.to, i)
	}
}

type Node struct {
	to, w int
}



Measured memory_bytes: 24112
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
 #define int long long

#define all(X) (X).begin(), (X).end()
#define reset(X) memset(X, 0, sizeof(X))
#define mp(a, b) make_pair(a, b)
#define pb push_back
#define endl '\n'
#define fi first
#define se second


using namespace __gnu_pbds;
using namespace std;
const int mod=1e9+7;
 // const int mod=998244353;
 // const int mod=1e9+9;
// const int INF=4e18+10;
const int INF=4e18+10;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template <typename T>
using ordered_multiset = tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define read(n) int n; cin>>n;
#define readv(x, n) vector<int> x(n); for(auto &i:x) cin>>i;


typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef pair<int, int> pii;

template<typename T1,typename T2>
void set_min(T1& a, T2 b)
{
    a=min(a, (T1)b);
}


int multiply(int a, int b, int in_mod){return (a*b)%in_mod;}
int mult_identity(int a){return 1;}


auto power(auto a, int b, int in_mod)
{
    auto prod=mult_identity(a);
    auto mult=a%in_mod;
    while(b!=0)
    {
        if(b%2)
        {
            prod=multiply(prod,mult, in_mod);

        }
        mult=multiply(mult, mult,in_mod);
        b/=2;
    }
    return prod;
}
int mod_inv(int q, int in_mod)
{

    return power(q, in_mod-2,in_mod);
}


void solve()
{
    string t;
    cin>>t;
    for(auto &i:t)
        if(i=='?')
            i='D'; 

    // int cnt=0;
    // for(int i=0;i<t.size();i++)
    // {
    //     if(t[i]=='D')
    //         cnt++;
    //     if(t[i]=='P' && i<t.size()-1)
    //     {
    //         if(t[i+1]=='D')
    //             cnt++;
    //     }
    // }
        cout<<t<<endl;

}

signed main()

{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    #ifndef ONLINE_JUDGE
    if(fopen("INPUT.txt","r"))
    {
        freopen ("INPUT.txt" , "r" , stdin);
        freopen ("OUTPUT.txt" , "w" , stdout);
    }
    #endif
    auto clk=clock();
    mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
    // -------------------------------------Code starts here---------------------------------------------------------------------

    int t=1;
    // cin>>t;
    for(int test=1;test<=t;test++)
    {
        // cout<<"Case #"<<test<<": ";
        // cout<<endl;
        solve();
        // cout<<endl;

    }

    // -------------------------------------Code ends here------------------------------------------------------------------


    clk = clock() - clk;
    cerr << fixed << setprecision(6) << "Time: " << ((double)clk)/CLOCKS_PER_SEC << "\n";
    return 0;
}


Measured memory_bytes: 3976
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
using namespace std;

int main() {
  int x[5];
  for (int i=0; i<5; i++)
    cin >> x[i];
  sort(x,x+5,greater<int>());
  for (int i=0; i<5; i++) {
    if (i) cout << " ";
    cout << x[i];
  }
  cout << endl;
}

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

int main()
{
	long N;
	cin >> N;

	long long result = 0;
	for (int a = 1; a < N; ++a)
	{
		if (N % a == 0)
		{
			result += ((N / a) - 1);
		}
		else
		{
			result += (N / a);
		}
	}

	cout << result << endl;
}

Measured memory_bytes: 3640
#include <iostream>
#include <algorithm>
#include <map>
#include <vector>
#include <queue>
using namespace std;
typedef long long lli;
typedef pair<int,int> T;

const int MAXN = 1000006;
const int INF = 1<<29;

class RMQ {
private:
  int n;
  T dat[4*MAXN-1];

public:
  void init(int _n = MAXN, T a = T(INF,INF)) {
    n = 1;
    while(n < _n) n *= 2;
    for(int i = 0; i < 2*n-1; ++i) dat[i] = a;
  }

  void update(int k, T a) {
    k += n-1;
    dat[k] = a;
    while(k > 0) {
      k = (k - 1) / 2;
      dat[k] = min(dat[k*2+1], dat[k*2+2]);
    }
  }

  T at(int k) {
    return dat[k+n-1];
  }

  T query(int a, int b, int k = 0, int l = 0, int r = 0) {
    if(k == 0) {
      l = 0; r = n;
    }
    if(r <= a || b <= l) return T(INF,INF);
    if(a <= l && r <= b) return dat[k];
    else {
      T v1 = query(a, b, k*2+1, l, (l+r)/2);
      T v2 = query(a, b, k*2+2, (l+r)/2, r);
      return min(v1, v2);
    }
  }
};

RMQ rmq;

int main() {
  int n, q;
  while(cin >> n >> q) {
    rmq.init(n);
    for(int i = 0; i < n; ++i) {
      rmq.update(i, make_pair(0,i));
    }
    for(int i = 0; i < q; ++i) {
      int a, v;
      cin >> a >> v;
      --a;
      pair<int,int> p = rmq.at(a);
      rmq.update(a, T(p.first-v, a));
      p = rmq.query(0,n);
      cout << p.second+1 << " " << -p.first << endl;
    }
  }
  return 0;
}

Measured memory_bytes: 32412
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization ("unroll-loops")
#include <bits/stdc++.h>
  
using namespace std;
 
#define endl "\n"
#define JAM(x) cout<< #x <<" = "<<x<<"\n"
#define II() ( { int a ; read(a) ; a; } )
#define LL() ( { ll a ; read(a) ; a; } )
#define DD() ({double a; scanf("%lf", &a); a;})
 
 
//Fast Reader
template<class T>inline bool read(T &x){
    int c=getchar();int sgn=1;
    while(~c&&c<'0'||c>'9'){if(c=='-')sgn=-1;c=getchar();}
    for(x=0;~c&&'0'<=c&&c<='9';c=getchar())x=x*10+c-'0'; 
    x*=sgn; return ~c;
}
 
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef pair<int,int> PII;
typedef vector<PII> VPI;
 
const int INF=2e9;
const int MX=100005;
const int MOD=1000000007;
const double PI=acos(-1.0);

vector<int> sieve(100001);


long long int power(long long int a,long long int b)
{
    a %= MOD;
    long long int res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a % MOD;
        a = a * a % MOD;
        b >>= 1;
    }
    return res;
}
bool isprime(int n)
{
    if(n==1)
    return 0;
    int i;
    for(i=2;i*i<=n;i++)
    {
        if(n%i==0)
        return false;
    }
    return true;
}

void SIEVE()
{
    int i,j;
    for(i=0;i<=100000;i++)
    sieve[i]=i;
    for(i=2;i*i<=100000;i++)
    {
        if(sieve[i]!=i)
        continue;
        for(j=i*i;j<=100000;j=j+i)
        {
            if(sieve[j]==j)
            sieve[j]=i;
        }
    }
}


/*_______________________________________________*/


int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n,m;
    cin>>n>>m;
    int tot;
    cin>>tot;
    int ans=0;
    vector<int> row(n);
    int mx=0,mxr=0;
    vector<int> col(m),mxcol(m),mxrow(n);
    int i,j;
    map<pair<int,int>,int> bomb;
    for(i=0;i<tot;i++)
    {
        int x,y;
        cin>>x>>y;
        bomb[{x-1,y-1}]=-1;
        row[x-1]++;
        col[y-1]++;
        mx=max(mx,col[y-1]);
        mxr=max(mxr,row[x-1]);
    }
    int k=0,d=0;
    for(i=0;i<m;i++)
    {
        if(col[i]==mx)
        mxcol[d++]=(i);
    }
    for(i=0;i<n;i++)
    {
        if(row[i]==mxr)
        mxrow[k++]=(i);
    }
    if(mxr==m)
    {
        cout<<m+mx-1;
        return 0;
    }
    for(i=0;i<k;i++)
    {
        for(j=0;j<d;j++)
        {
        ans=max(ans,row[mxrow[i]]+col[mxcol[j]]+bomb[{mxrow[i],mxcol[j]}]);
        }
        if(ans==mxr+mx)
        break;
    }
    cout<<ans;
}


Measured memory_bytes: 45528
#include <bits/stdc++.h>
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define SZ(x) ((int)(x).size())
#define ALL(x) (x).begin(),(x).end()
#ifdef _DEBUG_
  #define debug(...) printf(__VA_ARGS__)
#else
  #define debug(...) (void)0
#endif
using namespace std;
typedef long long ll;
typedef pair<int,int> PII;
typedef vector<int> VI;


const double EPS = 1e-10;
const double PI = acos(-1.0);

struct PT {
  ll x, y;
  int id;
  PT() {}
  PT(ll x_, ll y_): x(x_), y(y_), id(-1) {}
  ll len2() const {
    return x * x + y * y;
  }
  double len() const {
    return sqrt(len2());
  }
  PT operator - (const PT &b) const {
    return PT(x - b.x, y - b.y);
  }
  ll operator * (const PT &b) const {
    return x * b.x + y * b.y;
  }
  ll operator % (const PT &b) const {
    return x * b.y - y * b.x;
  }
  bool operator < (const PT &b) const {
    return tie(x, y) < tie(b.x, b.y);
  }
};

const int MAXN = 123;
PT in[MAXN];
double ans[MAXN];

int main() {
  int N;
  scanf("%d", &N);
  for (int i = 0; i < N; i++) {
    int x, y;
    scanf("%d%d", &x, &y);
    in[i].x = x;
    in[i].y = y;
    in[i].id = i;
  }
  sort(in, in + N);
  vector<PT> st;
  for (int i = 0; i < N; i++) {
    while (SZ(st) >= 2 && (st[SZ(st) - 1] - st[SZ(st) - 2]) % (in[i] - st[SZ(st) - 1]) < 0)
      st.pop_back();
    st.PB(in[i]);
  }
  for (int i = N - 2; i >= 0; i--) {
    while (SZ(st) >= 2 && (st[SZ(st) - 1] - st[SZ(st) - 2]) % (in[i] - st[SZ(st) - 1]) < 0)
      st.pop_back();
    st.PB(in[i]);
  }
  for (int i = 0; i < N; i++)
    ans[i] = 0;
  debug("SZ %d\n", SZ(st));
  st.PB(st[1]);
  debug("!\n");
  for (int i = 1; i < SZ(st) - 1; i++) {
    debug("i = %d\n", i);
    PT A = st[i - 1] - st[i];
    PT B = st[i + 1] - st[i];
    debug("%f %f\n", A.len(), B.len());
    double tmp = A * B / (A.len() * B.len());
    debug("! %d %f\n", i, tmp);
    double ang = PI - acos(tmp);
    ans[st[i].id] = ang / (2 * PI);
  }
  for (int i = 0; i < N; i++)
    printf("%.10f\n", ans[i]);
  double sum = 0;
  for (int i = 0; i < N; i++)
    sum += ans[i];
//  assert(fabs(sum - 1.0) < EPS);
  return 0;
}


Measured memory_bytes: 256
package main

import "fmt"

func main() {
	var N int64
	const M int64 = 1000000007
	fmt.Scanf("%d", &N)

	// 10^N
	var A int64 = 10
	var i int64 = 0
	for i = 1; i < N; i++ {
		A = A * 10 % M
	}

	var B int64 = 9
	for i = 1; i < N; i++ {
		B = B * 9 % M
	}

	var C int64 = 8
	for i = 1; i < N; i++ {
		C = C * 8 % M
	}

	B = (B + B) % M
	B = (B - C) % M

	A = (A - B) % M
	A %= M
	if A < 0 {
		A += M
	}
	//A = (A / M) % M
	fmt.Printf("%d\n", A)
	// 10^N - (9^N + 9^N - 8^N)
	// 100 - (81 + 81 - 64)
	// 100 - (162-64) = 2

}


Measured memory_bytes: 1868
from collections import deque

N,M = map(int,input().split())
node = [[]for i in range(N)]
for i in range(M):
    L,R,D = map(int,input().split())
    node[L-1].append([R-1,D])
    node[R-1].append([L-1,-D])
Flag = [False]*N
queue = deque([])
X = [0]*N
for i in range(N):
    if Flag[i] == False:
        Flag[i] = True
        queue.append(i)
        
        while queue != deque([]):
            p = queue.popleft()
            for r,d in node[p]:
                if Flag[r] == False:
                    Flag[r] = True
                    queue.append(r)
                    X[r] = X[p] - d
                elif X[r] != X[p] - d:
                    print('No')
                    exit()
print('Yes')

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


int main()
{	
	while (true)
	{
		int a[2];
		cin>>a[0]>>a[1];
		if(a[0]==0&&a[1]==0)
			break;
		if(a[0]>a[1])
		cout<<a[1]<<" "<<a[0]<<endl;
		else
		{
			cout<<a[0]<<" "<<a[1]<<endl;
		}
	}
	return 0;
}

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize ("Ofast")
#pragma GCC target ("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;

typedef pair <int,int> pii;
typedef vector <pii> vpii;
typedef vector <int> vi;
typedef vector <vi> vvi;
typedef long long int lli;
typedef vector <lli> vlli;
typedef vector <vlli> vvlli;
typedef vector <string> vs;
typedef vector <bool> vb;

#define rep(i, n) for( i = 0; i < (n); ++i)
#define repA(i, a, n) for( i = a; i <= (n); ++i)
#define repD(i, a, n) for( i = a; i >= (n); --i)
#define trav(a, x) for(auto& a : x)
#define all(x) x.begin(), x.end()
#define sortr(x) sort(x.begin(),x.end(),greater <int> ())
#define mod 1000000007
#define ff first
#define ss second
#define fill(a,c)  memset(a, c, sizeof (a))
#define formap(i,v) for(auto &i: v)
#define dbg(x) cout << #x << " = " << x << '\n'
#define dbg2(x,y) cout<<#x<<" = "<<x<<" & "<<#y<<" = "<<y<<endl;
#define dbgstl(v) cout<<#v<<" = \n"; { int c=0; formap(it,v) \
cout<<"    "<<#v<<"["<< ++c <<"] = "<<it<<endl;} cerr<<endl
#define dbgstlp(v) cout<<#v<<" = \n"; { int c=0; formap(it,v) \
cout<<"    "<<#v<<"["<< ++c <<"] = "<<it.first<<" , "<<it.second<<endl;} cerr<<endl
#define PI  3.14159265358979323846
#define pb push_back



int main() {
    cin.sync_with_stdio(0);cin.tie(0);
    cin.exceptions(cin.failbit);
    
    
    int i,j,k,l,r,d,a,b;
    cin>>l>>r>>d;
    a= ceil(l*1.0/d);
    b=floor(r*1.0/d);
    cout<<(b-a+1)<<endl;
    
    
    
    
    
    
    
    
    
    
    
    
     
   
   
	return 0;
}


Measured memory_bytes: 3636