akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <string.h>

int mb[3][3], LN;
int main() {
	for (int i = 0; i < 3; i ++) {
		for (int j = 0; j < 3; j ++) {
			scanf("%d", &mb[i][j]);
		}
	}
	scanf("%d", &LN);
	int ar[20];
	for (int c = 0; c < LN; c ++) {
		scanf("%d", &ar[c]);
	}
	bool bin[3][3];
	memset(bin, false, sizeof(bin));
	for (int i = 0; i < 3; i ++) {
		for (int j = 0; j < 3; j ++) {
			for (int ii = 0; ii < LN; ii ++) {
				if (mb[i][j] == ar[ii]) {
					bin[i][j] = true;
					break;
				}
			}
		}
	}	
	bool res = false;
	for (int i = 0; i < 3; i ++) {
		bool yes = true;
		for (int j = 0; j < 3; j ++) {
			yes = yes && bin[i][j];
		}
		res = res || yes;
	}
	for (int j = 0; j < 3; j ++) {
		bool yes = true;
		for (int i = 0; i < 3; i ++) {
			yes = yes && bin[i][j];
		}
		res = res || yes;
	}
	bool yes = true;
	for (int i = 0; i < 3; i ++) {
		yes = yes && bin[i][i];
	}
	res = res || yes;
	yes = true;
	for (int i = 0; i < 3; i ++) {
		yes = yes && bin[i][2 - i];
	}
	res = res || yes;
	if (res) {
		printf("Yes\n");
	}
	else {
		printf("No\n");
	}
	return 0;
}


Measured memory_bytes: 128
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;
#define rep(i, begin, n) for (int i = begin; i < n; i++)
#define repe(i, begin, n) for (int i = begin; i <= n; i++)
#define repr(i, begin, n) for (int i = begin; i > begin - n; i--)
#define repre(i, begin, end) for (int i = begin; i >= end; i--)

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

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

const int inf = INT_MAX;
const int MOD = 1000000007;
const long long INF = LLONG_MAX;

// -------------------------------------------------------

int N;
string S;

int main() {
  cin >> N;
  cin >> S;
  int ans = 0;
  int x = 0;
  for (auto e : S) {
    if (e == 'I') {
      ++x;
    } else {
      --x;
    }
    chmax(ans, x);
  }
  cout << ans;
}


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

int main()
{
	int N;
	scanf("%d", &N);
	int count{};
	for (int i{1}; i <= N; i++)
	{
		int digit{};
		for (int j{i}; j > 0; j /= 10)
			digit++;
		if (digit & 1) count++;
	}
	printf("%d\n", count);

	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++)

const string YES = "YES";
const string NO = "NO";
int main(){
  int N; cin >> N;
  vector<int> A(N); rep(i, N) cin >> A[i];
  sort(A.begin(), A.end());

  int now = 0;
  bool ans = true;
  rep(i, N) {
    if (now == A[i]) ans = false;
    now = A[i];
  }
  if (ans) cout << YES << endl;
  else cout << NO << endl;
}


Measured memory_bytes: 1024
n, k = map(int, input().split())
x = list(map(int, input().split()))
min_time = 10 ** 10
for l, r in zip(range(0, n - k + 1), range(k - 1, n)):
    time = x[r] if x[l] >= 0 else (-x[l] if x[r] <= 0 else (x[r] - x[l]) + min(-x[l], x[r]))
    if time < min_time:
        min_time = time
print(min_time)

Measured memory_bytes: 14380
#include <stdio.h>
#include <string.h>
#include <limits.h>
#include <stdlib.h>
#include <math.h>


long int merge(long int a1[], long int a2[], long int b1[], long int b2[], long int a1_size, long int a2_size, long int b1_size, long int b2_size, long int a[], long int b[]);
long int mergeSort(long int a[], long int a_size, long int b[], long int b_size);

int main(void)
{
	long int n;
	long int i, j;
	long int work;
	long int a[200000];
	long int b[200000];
	
	scanf("%ld", &n);
	
	for(i = 0; i < n; i++) {
		scanf("%ld", &a[i]);
		b[i] = i + 1;
	}
	
	if(n <= 1000) {
		for(i = 0; i < n - 1; i++) {
			for(j = 0; j < n - 1 - i; j++) {
				if(a[j] > a[j + 1]) {
					work = a[j];
					a[j] = a[j + 1];
					a[j + 1] = work;
					
					work = b[j];
					b[j] = b[j + 1];
					b[j + 1] = work;
				}
			}
		}
		
		for(i = 0; i < n; i++) {
			printf("%ld ", b[i]);
		}
		return 0;
	}
	
	mergeSort(a, n, b, n);
	
	for(i = 0; i < n; i++) {
		printf("%ld ", b[i]);
	}
	//printf("%ld", b[n - 1]);
	
	return 0;
}

long int merge(long int a1[], long int a2[], long int b1[], long int b2[], long int a1_size, long int a2_size, long int b1_size, long int b2_size, long int a[], long int b[])
{
	long int i = 0, j = 0;
	
	while( (i < a1_size ) || (j < a2_size) ) {
		if( (j >= a2_size ) || ( (i < a1_size) && (a1[i] < a2[j]) ) ) {
			a[i + j] = a1[i];
			b[i + j] = b1[i];
			i++;
		} else {
			if( (a1[i] == a2[j]) && (b1[i] > b2[j]) ) {
				//printf("Ok\n");
				a[i + j]  = a1[i];
				b[i + j]  = b1[i];
				i++;
			} else {
				a[i + j] = a2[j];
				b[i + j] = b2[j];
				j++;
			}
		}
	}
	
	return 0;
}

long int mergeSort(long int a[], long int a_size, long int b[], long int b_size)
{
	long int m = a_size / 2, n = a_size - m;
	long int a1[m];
	long int a2[n];
	long int b1[m];
	long int b2[n];
	long int i, j;
	
	if(a_size > 1) {
		for(i = 0; i < m; i++) {
			a1[i] = a[i];
			b1[i] = b[i];
		}
		for(i = 0; i < n; i++) {
			a2[i] = a[m + i];
			b2[i] = b[m + i];
		}
		mergeSort(a1, m, b1, m);
		mergeSort(a2, n, b2, n);
		merge(a1, a2, b1, b2, m, n, m, n, a, b);
	}
	
	return 0;
}


Measured memory_bytes: 6528
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <complex>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <stack> 
#include <bitset>
#include <queue>
#include <assert.h>
#include <unordered_map>
using namespace std;

int main()
{
	int n;
	char s[1110];
	cin >> n >> s;
	if (strlen(s) <= n) printf("%s\n", s);
	else {
		s[n] = s[n + 1] = s[n + 2] = '.';
		s[n + 3] = 0;
		cout << s << endl;
	}
	return 0;
}



Measured memory_bytes: 3104
/*
 ▓█████▄  ▄████▄  ▓██   ██▓ ██▓███   ██░ ██ ▓█████  ██▀███
▒██▀ ██▌▒██▀ ▀█   ▒██  ██▒▓██░  ██▒▓██░ ██▒▓█   ▀ ▓██ ▒ ██▒
 ░██   █▌▒▓█    ▄   ▒██ ██░▓██░ ██▓▒▒██▀▀██░▒███   ▓██ ░▄█ ▒
 ░▓█▄   ▌▒▓▓▄ ▄██▒  ░ ▐██▓░▒██▄█▓▒ ▒░▓█ ░██ ▒▓█  ▄ ▒██▀▀█▄
 ░▒████▓ ▒ ▓███▀ ░  ░ ██▒▓░▒██▒ ░  ░░▓█▒░██▓░▒████▒░██▓ ▒██▒
  ▒▒▓  ▒ ░ ░▒ ▒  ░   ██▒▒▒ ▒▓▒░ ░  ░ ▒ ░░▒░▒░░ ▒░ ░░ ▒▓ ░▒▓░
  ░ ▒  ▒   ░  ▒    ▓██ ░▒░ ░▒ ░      ▒ ░▒░ ░ ░ ░  ░  ░▒ ░ ▒░
  ░ ░  ░ ░         ▒ ▒ ░░  ░░        ░  ░░ ░   ░     ░░   ░
    ░    ░ ░       ░ ░               ░  ░  ░   ░  ░   ░
  ░      ░         ░ ░
*/
//focus less on how much problem you should solve within a fixed time and focus more on getting the problem solved and
//learning something from it
#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 fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define rep(i,a,b) for(ll i=a; i<b; i++)
#define per(i,a,b) for(ll i=a; i>=b; i--)
#define ll long long int
#define ld long double
#define vi vector<ll>
#define vii vector <pair<ll,ll> >
#define sedes set <ll, greater <ll> >
#define seasc set <ll>
#define pb push_back
#define mkp make_pair
#define ff first
#define ss second
#define MOD 1000000007
#define prec(n) fixed<<setprecision(n)
#define maxpq priority_queue<int>
#define minpq priority_queue<int, vector<int>, greater<int> >
#define umap unordered_map<ll, ll>
// #define map map<ll, ll>
#define autoit(x,it) for(auto it = x.begin(); it != x.end(); it++)
#define mems(a, i) memset(a, i, sizeof(a))
#define endl '\n'
#define all(v) v.begin(),v.end()
#define gcd(a,b) __gcd((a),(b))
#define lcm(a,b) ((a)*(b))/gcd((a),(b))
#define deba(a) cout << #a << " " << a << endl;
bool cmp(pair<ll, ll>& a,
         pair<ll, ll>& b)
{
	return a.second < b.second;
}
int main()
{
	fast;
#ifndef ONLINE_JUDGE
	freopen("/home/kushagra/Desktop/Kushagra/input.txt", "r", stdin);
	freopen("/home/kushagra/Desktop/Kushagra/output.txt", "w", stdout);
#endif
	ll n, m, k;
	cin >> n >> m >> k;
	map<ll, ll> row, col;
	map<pair<ll, ll>, ll> grid;
	while (k--)
	{
		ll x, y;
		cin >> x >> y;
		row[x]++;
		col[y]++;
		grid[ {x, y}] = 1;
	}
	ll maxr = 0, maxc = 0;
	for (auto i : row)
	{
		maxr = max(maxr, i.ss);
	}
	for (auto i : col)
	{
		maxc = max(maxc, i.ss);
	}
	vi rr, cc;
	for (auto i : row)
		if (i.ss == maxr)
			rr.pb(i.ff);
	for (auto i : col)
		if (i.ss == maxc)
			cc.pb(i.ff);

	for (auto it : rr)
	{
		for (auto i : cc)
		{
			if (grid[ {it, i}] == 0)
			{
				cout << maxr + maxc << endl;
				return 0;
			}
		}
	}
	cout << maxr + maxc - 1 << endl;
	return 0;
}

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

ll n;

int main()
{
    cin >> n;
    ll ans = 1e16;
    for(ll i = 1; i*i <= n; i++){
        if(n%i) continue;
        ans = min(ans, i+n/i-2);
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<(n); ++i)
#define rep1(i,n) for(int i=1; i<=(n); ++i)
#define repi(i,a,b) for(int i=a; i<=(b); ++i)
#define rrep(i,n) for(int i=(n-1); i>=0; --i)
#define ALL(obj) (obj).begin(), (obj).end()
#define RALL(obj) (obj).rbegin(), (obj).rend()
#define pb push_back
#define mp make_pair
#define to_s to_string
#define sz(v) (int)v.size()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() )
#define pr(x) cout<<(x)<<'\n'
#define debug(x) cout << #x << ": " << (x) << '\n'
#define yes "Yes"
#define no "No"
using namespace std;
using ll = long long;
using Edge = pair<int,long long>;
using Graph = vector<vector<Edge>>;
typedef pair<int,int> P;
struct aaa{aaa(){ cin.tie(0); ios::sync_with_stdio(0); cout<<fixed<<setprecision(20);};}aaaaaaa;
int MOD = 1e9 + 7;
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 dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

ll N,M;
vector<P> job; 

ll solve(ll N){
    sort(ALL(job));
    priority_queue<int> pq;
    ll ans = 0;

    int j = 0;
    rep1(i,M){
        while(job[j].first == i) pq.push(job[j].second), j++;
        if(!pq.empty()){
            ans += pq.top();
            pq.pop();
        }
    }
    return ans;
}

int main(){
    cin >> N >> M;
    int a,b;
    rep(i,N) cin >> a >> b, job.pb({a,b});
    pr(solve(N));
    return 0;
}


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

int main(){
  int N,M;
  cin>>N>>M;
  vector<double> votes(N);
  for(int i=0;i<N;i++){
    cin>>votes[i];
  }
  sort(votes.begin(),votes.end());
  reverse(votes.begin(),votes.end());
  double sum=0;
  for (int i=0;i<N;i++){
    sum+=votes[i];
  }
  if(votes[M-1]>=sum/(4*M)){
    cout<<"Yes"<<endl;
  }
  else{
    cout<<"No"<<endl;
  }
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {

		Scanner stdIn = new Scanner(System.in);

		// ?????????????????????????????????
		stdIn.useDelimiter("\r");

		String word = stdIn.next();

		// ??????????????????????????§?°??????????
		// String?????????char????????????????????????????????????????????????

		char[] cw = word.toCharArray();
		for (int i = 0; i < cw.length && cw.length < 1200; i++) {
			if (Character.isUpperCase(cw[i])) {
				cw[i] = Character.toLowerCase(cw[i]);
			} else {
				cw[i] = Character.toUpperCase(cw[i]);
			}
		}
		for (char charValue : cw) {
			System.out.print(charValue);
		}
		stdIn.close();
	}
}

Measured memory_bytes: 26972
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define sz(x) int(x.size())
using namespace std;
typedef long long ll;
typedef pair<int, int> P;

const ll INF = 1LL << 60;

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

    ll target = N - 1;

    ll ans = (N - 1) * N / 2;
    cout << ans << endl;
}

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

using namespace std;

typedef long long ll;

const int N = 101;
int g[N][N];

int main()
{
#ifdef ONPC
    freopen("a.in", "r", stdin);
    //freopen("a.out", "w", stdout);
#else
    //freopen("a.in", "r", stdin);
    //freopen("a.out", "w", stdout);
#endif
    ios::sync_with_stdio(0);
    int n, m;
    cin >> n >> m;
    for (int i = 1; i <= n; i++)
    {
        for (int j = 1; j <= n; j++)
        {
            g[i][j] = 1e9;
        }
    }
    vector <pair <pair <int, int>, int> > e;
    for (int i = 0; i < m; i++)
    {
        int a, b, c;
        cin >> a >> b >> c;
        g[a][b] = min(g[a][b], c);
        g[b][a] = min(g[b][a], c);
        e.push_back({{a, b}, c});
    }
    for (int k = 1; k <= n; k++)
    {
        for (int i = 1; i <= n; i++)
        {
            for (int j = 1; j <= n; j++)
            {
                if (i != k && k != j)
                {
                    g[i][j] = min(g[i][j], g[i][k] + g[k][j]);
                }
            }
        }
    }
    int ans = 0;
    for (auto c : e)
    {
        ans += (g[c.first.first][c.first.second] != c.second);
    }
    cout << ans << '\n';
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
//BEGIN CUT HERE
template <typename T,typename E>
struct SegmentTree{
  typedef function<T(T,T)> F;
  typedef function<T(T,E)> G;
  int n;
  F f;
  G g;
  T d1;
  E d0;
  vector<T> dat;
  SegmentTree(){};
  SegmentTree(int n_,F f,G g,T d1,
	      vector<T> v=vector<T>()):
    f(f),g(g),d1(d1){
    init(n_);
    if(n_==(int)v.size()) build(n_,v);
  }
  void init(int n_){
    n=1;
    while(n<n_) n*=2;
    dat.clear();
    dat.resize(2*n-1,d1);
  }
  void build(int n_, vector<T> v){
    for(int i=0;i<n_;i++) dat[i+n-1]=v[i];
    for(int i=n-2;i>=0;i--)
      dat[i]=f(dat[i*2+1],dat[i*2+2]);
  }
  void update(int k,E a){
    k+=n-1;
    dat[k]=g(dat[k],a);
    while(k>0){
      k=(k-1)/2;
      dat[k]=f(dat[k*2+1],dat[k*2+2]);
    }
  }
  inline T query(int a,int b){
    T vl=d1,vr=d1;
    for(int l=a+n,r=b+n;l<r;l>>=1,r>>=1) {
      if(l&1) vl=f(vl,dat[(l++)-1]);
      if(r&1) vr=f(dat[(--r)-1],vr);
    }
    return f(vl,vr);
  }
  
};
//END CUT HERE
signed main(){
  cin.tie(0);
  ios::sync_with_stdio(0);
  int n,q;
  cin>>n>>q;
  SegmentTree<int,int> rmq(n,
			   [](int a,int b){return min(a,b);},
			   [](int a,int b){return b;},
			   INT_MAX);
  for(int i=0;i<q;i++){
    int c,x,y;
    cin>>c>>x>>y;
    if(c) cout<<rmq.query(x,y+1)<<endl;
    else rmq.update(x,y);
  }
  return 0;
}
/*
  verified on 2017/10/15
  http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=DSL_2_A&lang=jp
*/

Measured memory_bytes: 3752
import java.util.*;
class Main{
	static Scanner s = new Scanner(System.in);
	public static void main(String[] args){
		while(true){
			int h=s.nextInt(),
			    w=s.nextInt();
			if((h|w)==0)
				break;
			for(int i=0;i<h;i++){
				for(int j=0;j<w;j++){
					System.out.print(((i+j)%2==0)?"#":".");
				}
				System.out.println();
			}
			System.out.println();
		}
	}
}

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

#define MAX 10
enum{BLANK,WALL,START,GOAL};

int w,h;
vector< vector<int> >field;
int dx[4]={0,1,0,-1};
int dy[4]={1,0,-1,0};
int ans;

void solve(int y,int x,int depth){
  if(depth>ans)return;
  if(field[y][x]==GOAL){
    if(depth<ans)ans=depth;
    return;
  }
  for(int i=0;i<4;i++){
    int nx=x+dx[i],ny=y+dy[i];
    if(nx<0||w<=nx||ny<0||h<=ny)continue;
    if(field[ny][nx]==WALL)continue;
    while(!(nx<0||w<=nx||ny<0||h<=ny)){
      if(field[ny][nx]==WALL){
	field[ny][nx]=BLANK;
	solve(ny-dy[i],nx-dx[i],depth+1);
	field[ny][nx]=WALL;
	break;
      }
      if(field[ny][nx]==GOAL){
	solve(ny,nx,depth+1);
	return;
      }
      nx+=dx[i];
      ny+=dy[i];
    }
  }
  return;
}

int main()
{
  int x,y;
  while(cin>>w>>h,w|h){
    field.resize(h);
    for(int i=0;i<h;i++){
      field[i].resize(w);
      for(int j=0;j<w;j++){
	cin>>field[i][j];
	if(field[i][j]==START){y=i;x=j;field[i][j]=BLANK;}
      }
    }
    ans=MAX+1;
    solve(y,x,0);
    if(ans<=MAX)cout<<ans<<endl;
    else puts("-1");
  }
}

Measured memory_bytes: 0
#include <iostream>
#include <stdio.h>
#include <string>
#include <set>
#include <algorithm>
#include <vector>
using namespace std;
int const N = 100, M =100;

string a[N];
int fr[30];
int main(){

	//freopen("Text.txt","r",stdin);
	string s;

	int n,m;

	cin >> n >> m;

		for (int i = 0; i <n; ++i){
			cin >> a[i];

			for (int j = 0; j < m; ++j){
				fr[a[i][j] - 'a']++;
			}
		}
	
	int odds = 0;
	int less = 0;
	
	for (int i = 0; i < 28; ++i){
		fr[i] %= 4;
		if (fr[i] % 2)
			odds++;
		if (fr[i] == 2)
			less++;
	}

	int k = 0; 

	if (n % 2){
		k+=(m/2);
	}

	if (m % 2){
		k += (n / 2);
	}

	if (n % 2 == 0 && m % 2 == 0){
		
		if (odds >= 1){
			cout << "No";
			return 0;	
		}

	}

	if (less > k || odds>=2){
		cout << "No";
		return 0;
	}

	
	cout << "Yes";

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() 
{
  int N, K;
  cin >> N >> K;
 
  int sum = 1;
  for(int i = 0;i < N ;i++){
    if(sum < K){
      sum *= 2;
    }
    else{
      sum += K;
    }
  }
  cout << sum << endl;
    
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
using namespace std;
int main()
{
    string s;
    cin >> s;
    int a = stoi(s.substr(0, 2));
    int b = stoi(s.substr(2,4));

    bool f_a = false;
    bool f_b = false;

    if (1 <= a && a <= 12) {
        f_a = true;
    }
    if (1 <= b && b <= 12) {
        f_b = true;
    }

    if (f_a && f_b) {
        cout << "AMBIGUOUS" << endl;
    } else if (f_a && !f_b) {
        cout << "MMYY" << endl;
    } else if (!f_a && f_b) {
        cout << "YYMM" << endl;
    } else {
        cout << "NA" << endl;
    }

    return 0;
}

Measured memory_bytes: 256
N, M = [int(i) for i in input().strip().split()]
A = [int(i) for i in input().strip().split()]
A.sort()

BC = [[0, 0] for _ in range(M)]
for j in range(M):
    BC[j][0], BC[j][1] = [int(i) for i in input().strip().split()]
BC.sort(key=lambda x: x[1])

res = 0
cnt = 0
i = N - 1
j = M - 1
while True:
    if cnt == N:
        break

    if j == -1:
        res += A[i]
        i -= 1
    elif A[i] > BC[j][1]:
        res += A[i]
        i -= 1
    elif A[i] <= BC[j][1]:
        res += BC[j][1]
        BC[j][0] -= 1
        if BC[j][0] == 0:
            j -= 1
    else:
        raise ValueError
    cnt += 1
print(res)


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

int main() {
  int pay;
  cin >> pay;
  
  int count_1yen;
  cin >> count_1yen;
  
  if (pay%500 <= count_1yen) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}

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

// Optimization

//#pragma GCC optimize("O3")
#define endl '\n'

// Shortcut

#define int long long
#define eb emplace_back
#define pb push_back
#define pob pop_back
#define mp make_pair
#define upb upper_bound
#define lwb lower_bound
#define fi first
#define se second
#define For(i, l, r) for (int i = l; i < r; i++)
#define ForE(i, l, r) for (int i = l; i <= r; i++)
#define Ford(i, r, l) for (int i = r; i > l; i--)
#define FordE(i, r, l) for (int i = r; i >= l; i--)
#define Fora(i, a) for (auto i : a)

// I/O & Debug

#define PrintV(a) Fora(iiii, a) cout << iiii << ' '; cout << endl;
#define PrintVl(a) Fora(iiii, a) cout << iiii << endl;
#define PrintA(a, l, r) for (int iiii = l; iiii <= r; iiii++) cout << a[iiii] << ' '; cout << endl;
#define PrintAl(a, l, r) for (int iiii = l; iiii <= r; iiii++) cout << a[iiii] << endl;
#define Ptest(x) return cout << x, 0;
#define gl(s) getline(cin, s);
#define setpre(x) fixed << setprecision(x)
/*
#define debug(args...){ string _sDEB = #args; replace(_sDEB.begin(), _sDEB.end(), ',', ' '); stringstream _ssDEB(_sDEB); istream_iterator<string> _itDEB(_ssDEB); DEB(_itDEB, args); }
void DEB(istream_iterator<string> it) {}
template<typename T, typename... Args>
void DEB(istream_iterator<string> it, T a, Args... args){
    cout << *it << " = " << a << endl;
    DEB(++it, args...);
}
*/

// Functions

//#define isvowel(a) (a == 'a' || a == 'e' || a == 'i' || a == 'o' || a == 'u')
#define bend(a) a.begin(), a.end()
#define rbend(a) a.rbegin(), a.rend()
#define mset(a) memset(a, 0, sizeof(a))
#define mset1(a) memset(a, 1, sizeof(a))
#define msetn1(a) memset(a, -1, sizeof(a))
#define msetinf(a) memset(a, 0x3f, sizeof(a))
#define gcd __gcd
#define __builtin_popcount __builtin_popcountll
//mt19937 rando(chrono::steady_clock::now().time_since_epoch().count());

// Data Structure

#define pque priority_queue
#define mts multiset
#define y0 _y0_
#define y1 _y1_
#define div divi
typedef long long ll;
typedef long double ld;
typedef vector <int> vi;
typedef vector <ll> vll;
typedef vector <ld> vld;
typedef vector <string> vs;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef vector <vi > vvi;
typedef vector <vll > vvll;
typedef vector <pii > vpii;
typedef vector <pll > vpll;

const int N = 2e5 + 5, mod = 1e9 + 7, mod1 = 998244353, mod2 = 1e9 + 9, inf = 1e18 + 7;
const ll infll = 1e18 + 7;

signed main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    int t, ans = 0, k = 1;
    cin >> t;
    while (t){
        ans += k;
        k <<= 1;
        t >>= 1;
    }
    cout << ans;
}

/*
==================================+
INPUT:                            |
------------------------------    |

------------------------------    |
==================================+
OUTPUT:                           |
------------------------------    |

------------------------------    |
==================================+
*/

Measured memory_bytes: 256
#include<stdio.h>

int main(void){
    int n, q;
    scanf("%d %d\n",&n,&q);
    
    char s[n];
    scanf("%s",s);
    
    int h[n];
    h[0] = 0;
    
    for(int i = 0; i < n - 1; i++){
        if(s[i] == 'A' && s[i+1] == 'C') {
            h[i+1] = 1 + h[i];
        } else {
            h[i+1] = h[i];
        }
    }
    
    for(int i = 0; i < q; i++){
        int l,r;
        scanf("%d %d\n",&l,&r);
        
        int k = h[r-1] - h[l-1];
        printf("%d\n",k);
    }
    return 0;
}


Measured memory_bytes: 1280
#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
#define f(n) ((n + 1LL) * (n) / 2)
int main() {
	int n, k; cin >> n >> k;
	long long ans = 1;
	for (int i = k; i <= n; i++) 
		ans = (ans + f(n) - f(n - i) - f(i - 1) + 1) % mod;
	cout << ans;
}

Measured memory_bytes: 3632
def Prime_number(x):
    # xは2以上の自然数
    # 素数:True
    for i in range(2,int(x**0.5)+1):
        if x%i==0:
            return False
    return True

like_number=[0 for _ in range(10**5+1)]
cnt=0
for i in range(2,10**5+1):
    if i%2==0:
        continue
    if Prime_number(i) and Prime_number((i+1)//2):
        cnt+=1
    like_number[i]=cnt

Q=int(input())
for _ in range(Q):
    l,r=map(int,input().split())
    print(like_number[r]-like_number[l-2])

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

typedef long long ll;
#define rep(i, n) for(ll i=0; i<n; i++)
#define FOR(i, a, b) for(ll i=a; i<b; i++)
#define sz(v) ll(v.size)


void solve(long long N){
    cout << int(N / 3) << endl;
}

int main(){
    long long N;
    scanf("%lld",&N);
    solve(N);
    return 0;
}


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

using namespace std;

int main(){
string n;
int a,i;
    cin>>n;
    a=n.length();
   for(i=0;i<a;i++)
   {
       if(n[i]==',')
       cout<<" ";
       else
       cout<<n[i];
   }
   cout<<endl;
    return 0;
}

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

using namespace std;

const int N = 1234567;

char st[N];
string s;

int main() {
  cin >> s;
  int n = s.length();
  int e = 0;
  for (int i = 0; i < n; i++) {
    if (e > 0 && st[e - 1] == 'S' && s[i] == 'T') {
      e--;
    } else {
      st[e++] = s[i];
    }
  }
  printf("%d\n", e);
  return 0;
}


Measured memory_bytes: 772
using System;
class P
{
    public static void Main()
    {
        string str = Console.ReadLine();

            for (int i = 1; i <= 10000; i++)
            {

                Console.WriteLine("Case " + i + ":" + " " + str);

                str = Console.ReadLine();

                if (str == "0")
                    break;
            }
    }
}


Measured memory_bytes: 17904
#include<stdio.h>

void insertionSort(int A[], int N) {
  for ( int i = 0; i < N; i++ ) {
    int v = A[i];
    int j = i - 1;
    while ( j >= 0 && v < A[j]) {
      A[j + 1] = A[j];
      j--;
    }
    A[j + 1] = v;
    for ( int i = 0; i < N; i++ ) {
      if ( i ) printf(" ");
      printf("%d", A[i]);
    }
    printf("\n");
  }
}



int main() {
  int N;
  int A[100];

  scanf("%d", &N);
  for ( int i = 0; i < N; i++ ) scanf("%d", &A[i]);

  insertionSort(A, N);

  return 0;
}



Measured memory_bytes: 2700
using System;
using System.Linq;

public class Test
{
	public static void Main()
	{
		int[] x = Console.ReadLine().Split().Select(int.Parse).ToArray();
		bool[,]masu=new bool[x[0]+2,x[1]+2];
		for(int i=1;i<x[0]+1;i++)
		{
			string s= Console.ReadLine();
			for(int j=1;j<x[1]+1;j++)
			{
				if(s[j-1]=='#')
				{
					masu[i,j]=true;
				}
			}
		}
		for(int i=1;i<x[0]+1;i++)
		{
			for(int j=1;j<x[1]+1;j++)
			{
				int ret=0;
				for(int k=-1;k<=1;k++)
				{
					for(int l=-1;l<=1;l++)
					{
						if(masu[i+k,j+l])ret++;
					}	
				}
			Console.Write(masu[i,j]?"#":ret.ToString());
			}
			Console.WriteLine();
		}
	}
}

Measured memory_bytes: 13396
import java.util.Scanner;
import java.util.List;
import java.util.ArrayList;

public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int a = sc.nextInt();  // input Integer
    int b = sc.nextInt();
    System.out.println(a*b);
//    String a = sc.next();  // input String
  }
}

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

using ll=long long;

int main(){

string str="ABCDEFGHIJKLMNOPQRSTUVWXYZ";

int N;
cin>>N;
string S,T;
cin>>S;

int a=S.size();

for(int i=0;i<a;++i){
int b=S[i]-'A';
T.push_back(str[(b+N)%26]);
}

cout << T << endl;

}

Measured memory_bytes: 256
def main():

    H, W = map(int, input().split())
    mod = pow(10, 9) + 7
    A = []
    for _ in range(H):
        A.append(input())

    dp = [[0 for _ in range(W+1)] for _ in range(H+1)]

    for i in range(H):
        for j in range(W):
            if i == 0 and j == 0:
                dp[i+1][j+1] = 1
            elif A[i][j] == "#":
                dp[i+1][j+1] == -1
            else:
                v = 0
                if dp[i][j+1] != -1:
                    v += dp[i][j+1]
                if dp[i+1][j] != -1:
                    v += dp[i+1][j]
                dp[i+1][j+1] = v % mod

    return dp[H][W]
if __name__ == '__main__':
    print(main())

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

using namespace std;

int main()
{
//    freopen("TEST.INP", "r", stdin);
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    int ok = 1;
    while (c > 0 && a > 0)
    {
        if (ok) c -= b;
        else a -= d;
        ok = !ok;
    }
    if (a > 0) cout << "Yes";
    else cout << "No";
    return 0;
}


Measured memory_bytes: 3624
#include<bits/stdc++.h>
using namespace std;
inline int read(){
	int x=0,f=1;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=(x<<3)+(x<<1)+ch-'0';ch=getchar();}
	return x*f;
}
#define MN 100005
int n,l[MN],r[MN];long long ans; 
int main(){
	n=read();
	for(int i=1;i<=n;i++) l[i]=read(),r[i]=read();
	sort(l,l+n+1);sort(r,r+n+1);
	for(int i=0;i<=n;i++)if(l[n-i]-r[i]>=1)ans+=l[n-i]-r[i];
	return !printf("%lld\n",ans<<1);
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int n,x,a,b,c;
    cin >> a >> b >> c;
    if(a==b && b==c){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
        return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <string>
#include <sstream>
#include <vector>
#include <set>
#include <stack>
#include <map>
#include <cmath>
#include <queue>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
using namespace std;
typedef long long ll;
const ll INF = 1000000000000000;
#define MAX_N 100000



int main()
{
	int X,N;
	cin>>X>>N;
	int *p = new int[N];
	set<int> numList;
	rep(i,N){
		cin>>p[i];
		numList.insert(p[i]);
	}
	int ans = 0;
	int diff = abs(X-ans);
	for(int i = 0; i <= 101; i++){
		if( numList.count(i) == 0 && diff > abs(i - X)){
			diff = abs(i - X);
			ans = i;
		}
	}
	if( N == 0) ans = X;
	cout<<ans<<endl;
	return 0;
}



Measured memory_bytes: 3200
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin >> n;
  vector<int> a(n);
  for(int i=0;i<n;i++){
    cin >> a[i];
  }
  long long ans=0;
  int right=0;
  long long sum=0;
  for(int left=0;left<n;left++){
    while(right<n&&(sum^a[right])==sum+a[right]){
      sum+=a[right];
      right++;
    }
    ans+=right-left;
    if(left==right){
      right++;
    }
    else{
      sum-=a[left];
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 1024
# D - Saving Snuuk
import sys
sys.setrecursionlimit(10 ** 7)

import numpy as np
from heapq import heappush, heappop

N, M, S, T = map(int,input().split())
# graph[0]は使わない（都市の名前と添字が一致）
graph = [[] for _ in range(N+1)]

for _ in range(M):
    u, v, a, b = map(int,input().split())
    # (v, a, b)はvの都市に行くのに、a円またはbスヌーク）
    graph[u].append((v, a, b))
    graph[v].append((u, a, b))

def dijkstra(start, mode):
    INF = 10 ** 15
    # 最初の所持金で初期化　dist[0]は使わない
    dist = [INF] * (N+1)
    dist[start] = 0
    que = [(0,start)]
    while que:
        # (d, v) はdが現在の最小の交通費、vが現在の場所
        d, v = heappop(que)
        # 既に来たことがある場合、continue
        if dist[v] < d:
            continue
        for next_city, *fee in graph[v]:
            # modeによって円かスヌークを使うか選ぶ
            d1 = d + fee[mode]
            # 次の場所の交通費よりやすくなる場合は、データを更新
            if dist[next_city] > d1:
                dist[next_city] = d1
                heappush(que, (d1, next_city))
    return dist

# 円だけで支払う場合、それぞれの都市にいくらで行けるか
d1 = np.array(dijkstra(S, 0))
# ゴール地点からスヌークで行く場合
d2 = np.array(dijkstra(T, 1))
# 足し合わせて、切り替わったところが両替地点
d1 += d2
# i年後、両替所がなくなった時、後ろから見ていった最小値
answer = 10 ** 15 - np.minimum.accumulate(d1[::-1])[::-1][1:]
print('\n'.join(answer.astype(str)))

Measured memory_bytes: 78316
K = int(input())
a = ""
ans = 0
amari = 10

if K%2 == 0:
    print(-1)
elif K%5 == 0:
    print(-1)

else:
    if K%7 == 0:
        L = 9*K//7
    else:
        L = 9*K

    for p in range(10**6):
        if amari % L == 1:
            print(p+1)
            break
        else:
            amari = (amari*10)%L

Measured memory_bytes: 9092
#include<stdio.h>
#include<string.h>
int main()
{
    int no,i,left=0,right=0;
    scanf("%d",&no);
    getchar();
    char s[200];
    gets(s);
    for(i=0;i<no;i++)
    {
        if(s[i]=='(')
        {
            left++;
        }
        if(s[i]==')')
        {
            if(left==0)
            {
                right++;
            }
            else
            {
                left--;
            }
        }
    }
    for(i=0;i<right;i++)
    {
        printf("(");
    }
    printf("%s",s);
    for(i=0;i<left;i++)
    {
        printf(")");
    }
    printf("\n");
    return 0;
}


Measured memory_bytes: 128
M=10**9+7
mul=->a,b{r=[];W.times{|y|r<<[];W.times{|x|r[y]<<W.times.reduce(0){|s,i|(s+a[y][i]*b[i][x])%M}}};r}
h,W,K=gets.split.map &:to_i
F=[1,1]
(2..W).map{F<<(F[-1]+F[-2])%M}
m=(1..W).map{[0]*W}
(1...W).map{|i|m[i-1][i]=F[i-1]*F[W-i-1]%M}
W.times{|i|m[i][i]=F[i]*F[W-i-1]%M}
(W-1).times{|i|m[i+1][i]=F[i]*F[W-i-2]%M}
e=(0...W).map{|i|[0]*i+[1]+[0]*(W-1-i)}
(h%2>0&&e=mul[m,e];m=mul[m,m];h/=2)while h>0
p e[K-1][0]

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

int main(void){
	int N, M, P;
	int sum, ans;
	int X[1001];

	while((scanf("%d %d %d", &N, &M, &P) != EOF) && (N != 0 || M != 0 || P != 0)){

		sum = 0;
		for(int i = 0; i < N; i++){
			cin >> X[i];
			sum += X[i];
		}

		P = 100 - P;

		if(X[M-1] == 0)	ans = 0;
		else ans = sum * P / X[M-1];

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

Measured memory_bytes: 1248
#include <bits/stdc++.h>
#define LLI long long int
#define FOR(v, a, b) for(LLI v = (a); v < (b); ++v)
#define FORE(v, a, b) for(LLI v = (a); v <= (b); ++v)
#define REP(v, n) FOR(v, 0, n)
#define REPE(v, n) FORE(v, 0, n)
#define REV(v, a, b) for(LLI v = (a); v >= (b); --v)
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define ITR(it, c) for(auto it = (c).begin(); it != (c).end(); ++it)
#define RITR(it, c) for(auto it = (c).rbegin(); it != (c).rend(); ++it)
#define EXIST(c,x) ((c).find(x) != (c).end())
#define fst first
#define snd second
#define popcount __builtin_popcount
#define UNIQ(v) (v).erase(unique(ALL(v)), (v).end())
#define bit(i) (1LL<<(i))

#ifdef DEBUG
#include <misc/C++/Debug.cpp>
#else
#define dump(...) ((void)0)
#endif

#define gcd __gcd

using namespace std;
template <class T> constexpr T lcm(T m, T n){return m/gcd(m,n)*n;}

template <typename I> void join(ostream &ost, I s, I t, string d=" "){for(auto i=s; i!=t; ++i){if(i!=s)ost<<d; ost<<*i;}ost<<endl;}
template <typename T> istream& operator>>(istream &is, vector<T> &v){for(auto &a : v) is >> a; return is;}
template <typename T, typename U> bool chmin(T &a, const U &b){return (a>b ? a=b, true : false);}
template <typename T, typename U> bool chmax(T &a, const U &b){return (a<b ? a=b, true : false);}
template <typename T, size_t N, typename U> void fill_array(T (&a)[N], const U &v){fill((U*)a, (U*)(a+N), v);}

struct Init{
  Init(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(12);
    cerr << fixed << setprecision(12);
  }
}init;



int main(){
  int n;
  while(cin >> n){
    vector<int> a(n); cin >> a;

    if(count(ALL(a), 1) == 0){
      cout << -1 << endl;
    }else{
      int cur = 0;
      int k = 1;

      while(cur < n){
        auto it = find(a.begin()+cur, a.end(), k);
        if(it == a.end()) break;

        cur = it-a.begin() + 1;
        
        ++k;
      }

      cout << n-k+1 << endl;
    }
    

    
  }


  return 0;
}


Measured memory_bytes: 1152
#include<bits/stdc++.h>
using namespace std;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int p, q, r;
  cin >> p >> q >> r;
  int mi;
  mi = min(p, q);
  int second;
  if(mi == p) {
      second = min(q, r);
  } else {
      second = min(p, r);
  }
  cout << mi + second << '\n';
}

Measured memory_bytes: 256
import java.util.Scanner;

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

    while (true) {
      int a = in.nextInt();
      String op = in.next();
      int b = in.nextInt();
      
      if (op.equals("+")) {
        System.out.println(a + b);
      }
      else if (op.equals("-")) {
        System.out.println(a - b);
      }
      else if (op.equals("*")) {
        System.out.println(a * b);
      }
      else if (op.equals("/")) {
        System.out.println(a / b);
      }
      else if (op.equals("?")) {
        break;
      }
    }
  }
}

Measured memory_bytes: 26252
#include <bits/stdc++.h>
typedef long long ll;

#define pll pair<ll,ll>
#define ff first
#define snd second
#define pb push_back
#define vll vector<ll>
#define vpll vector<pll>
#define endl "\n"
#define MOD 1000000007
using namespace std;

ll const N = 1e5+1;
vll r(N,-1),g(N,-1),p(N,-1);

void solve()
{
   ll x,y,a,b,c;
   cin>>x>>y>>a>>b>>c;
   
   for(int i=0;i<a;i++)
   {
           cin>>r[i];
           
   }
   for(int i=0;i<b;i++)
   {
           cin>>g[i];
           
   }
   for(int i=0;i<c;i++)
   {
           cin>>p[i];
   }
   
   sort(r.rbegin(),r.rend());
   sort(g.rbegin(),g.rend());
   sort(p.rbegin(),p.rend());
   ll count = 0;
   vll arr;
   ll ans = 0;
   int j = 0;
   for(int i=0;i<x;i++) arr.pb(r[i]);
   for(int i=0;i<y;i++) arr.pb(g[i]);
   for(int i=0;i<c;i++) arr.pb(p[i]);
   
   sort(arr.rbegin(),arr.rend());
   
   for(int i=0;i<x+y;i++)
   {
           ans+=arr[i];
   }
   cout<<ans;
}
 
int main() {
            ios_base::sync_with_stdio(false);
            cin.tie(NULL);
	    int t=1;
	    //cin>>t;
	    while(t--)
	    {
	            solve();
	    }
	    return 0;
}

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

using namespace std;
typedef long long ll;
int main() {
   ll n, k, m, s = 0;
   cin >> n >> k;
   vector<pair<ll, ll>>v;
   for (ll i = 0; i < n; i++)  {
        ll x, y;
        cin >> x >> y;
        v.push_back({x, y});

   }
   sort(v.begin(), v.end());
   for (ll i = 0; i < v.size(); i++) {
    k = k - v[i].second;
    if(k <= 0){
        m = i;
        break;
    }
   }
   cout << v[m].first << endl;
   return 0;
}


Measured memory_bytes: 2420
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int a[10];
    cin>>a[0]>>a[1]>>a[2];
    sort(a,a+3);
    int ans=0;
    int c=(a[2]-a[0])/2;
    a[0]=a[0]+c*2;
    int d=(a[2]-a[1])/2;
    a[1]=a[1]+d*2;
    //cout<<a[0]<<" "<<a[1]<<" "<<a[2]<<endl;
    ans+=c+d;
    sort(a,a+3);
    if(a[0]==a[1]&&a[1]==a[2]);
    else if(a[0]==a[1])ans++;
    else if(a[1]==a[2])ans+=2;
    cout<<ans;
    return 0;
}


Measured memory_bytes: 256
#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <string.h>
#define s(n)                        scanf("%d",&n)
#define sc(n)                       scanf("%c",&n)
#define sl(n)                       scanf("%I64d",&n)
#define sf(n)                       scanf("%lf",&n)
#define ss(n)                       scanf("%s",n)
#define INF                         (int)1e9
#define EPS                         1e-9
#define bitcount                    __builtin_popcount
#define gcd                         __gcd
#define forall(i,a,b)               for(int i=a;i<b;i++)
#define foreach(v, c)               for( typeof( (c).begin()) v = (c).begin();  v != (c).end(); ++v)
#define all(a)                      a.begin(), a.end()
#define in(a,b)                     ( (b).find(a) != (b).end())
#define pb                          push_back
#define fill(a,v)                    memset(a, v, sizeof a)
#define sz(a)                       ((int)(a.size()))
#define mp                          make_pair
#define MOD                         1000000007
typedef long long ll;
/*For you see , each day i love you
 more.Today more than yesterday
  less than tomorrow.*/
using namespace std;
int row[300001] , col[300001];

int main()
{
	int h,w,m;
	cin>>h>>w>>m;
	vector<vector<int> > cell(h+1);
	
	for(int i = 0;i<m;i++)
	{
		int x,y;
		cin>>x>>y;
		row[x]++;
		col[y]++;
		cell[x].push_back(y);	
	}
	
	int maxi = 0;
	set<pair<int , int> > s;
	
	for(int i = 1;i<=w;i++)
	{
		s.insert(mp(-1*col[i] , i));	
	}
	
//	for(int i = 1;i<=h;i++)
//	{
//		cout<<row[i]<<" ";	
//	}
//	cout<<endl;
//	

	
	
	
	for(int i = 1;i<=h;i++)
	{
		//i need to exclude first the cells present in this row
		
		for(int j = 0;j<cell[i].size();j++)
		{
			int y = cell[i][j];
		
			int d = col[y];
			s.erase(mp(-1*d , y));
			s.insert(mp(-1*(d-1) , y));
			
			col[y] = d-1;
		}
		
	
		pair<int , int> va = *(s.begin());
		int v = va.first;
		
		int val = row[i] + (-1*v);
		maxi = max(maxi , val);
		
		for(int j = 0;j<cell[i].size();j++)
		{
			int y = cell[i][j];
			int d = col[y];
		s.erase(mp(-1*d , y));
			s.insert(mp(-1*(d+1) , y));
			col[y] = d+1;
		}
		
	}
	
	
	cout<<maxi<<endl;
	
	return 0;
}

Measured memory_bytes: 35972
#include <bits/stdc++.h>
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define endl '\n'
#define int long long int
using namespace std;
#define pii pair <int, int>
#define mii map<int, int>
#define pb push_back
#define deb(x) cout << #x << " " << x << endl
#define deb2(x, y) cout << #x << " " << x << " " << #y << " " << y << endl
#define Loop(s, e, itr) for (int itr = s; itr < e; itr++)
#define loop(n) for(int i = 0; i < n; i++)
#define vin vector<int>
#define w(t) int tc; cin >> tc; for(int t = 1; t <= tc; t++)
#define vec vector
#define mod 1000000007
#define all(x) x.begin(), x.end()


int n;
vec<vin> adj(100005);
int dp[100005][3];

// 0 black
// 1 white

int get(int a, int c, int tab){

    if(dp[a][c] == -1){
        int final_ans = 0;
        if(c == 0){
            if(adj[a].size() == 0) final_ans = 1;
            else{
                int ans = 1;
                for(int i : adj[a]){
                    vin::iterator temp = find(adj[i].begin(), adj[i].end(), a);
                    if(temp != adj[i].end()) adj[i].erase(find(adj[i].begin(), adj[i].end(), a));
                    ans = (ans * get(i, 1, tab+1)) % mod;
                }
                final_ans = ans;
            } 
        }
        else{
            if(adj[a].size() == 0) final_ans = 1;
            else{
                int ans1 = 1;
                for(int i : adj[a]){
                    vin::iterator temp = find(adj[i].begin(), adj[i].end(), a);
                    if(temp != adj[i].end()) adj[i].erase(find(adj[i].begin(), adj[i].end(), a));
                    ans1 = (ans1 * (get(i, 1, tab+1) + get(i, 0, tab+1))) % mod;
                }
                final_ans = (ans1)%mod;
            }
        }
        dp[a][c] = final_ans;
    }
    return dp[a][c];
}

int32_t main(){
    cin >> n;
    int a, b;
    memset(dp, -1, sizeof(dp));
    loop(n-1){
        cin >> a >> b;
        adj[a].pb(b);
        adj[b].pb(a);
    }

    int ans = (get(1, 0, 0) + get(1, 1, 0))%mod;
    cout << ans;
}

Measured memory_bytes: 19168
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <map>
#include <string>
#include <utility>
#include <vector>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main() {
  int r, c;
  cin >> r >> c;
  int t[r + 1][c + 1] = {};
  rep(i, r) rep(j, c) cin >> t[i][j];
  // 行の合計
  rep(i, r) {
    rep(j, c) {
      t[i][c] += t[i][j];
    }
  }
  //　列の合計
  rep(i, c) {
    rep(j, r) {
      t[r][i] += t[j][i];
    }
  }
  // (5, 5)成分について
  rep(i, c) t[r][c] += t[r][i];

  rep(i, r + 1) {
    rep(j, c + 1) {
      cout << t[i][j];
      if (j != c)
        cout << " ";
    }
    cout << endl;
  }

  return 0;
}


Measured memory_bytes: 3108
#include <bits/stdc++.h>
#define int long long
using namespace std;

signed main(){
  
  int n;
  string s;

  cin>>n;
  cin>>s;
  
  if( n % 2 ) cout<<"No"<<endl;
  else{
    
    int flg = 1;
    
    for(int i=0;i<n/2;i++){
      if( s[i] != s[i+n/2] ) flg = 0;
    }
    
    if( flg ) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    
  }
    
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long int
int32_t main()
{
    int h,w,k;
    cin>>h>>w>>k;
    int x[h*w+1],y[h*w+1];
    for(int i=0;i<h;i++)
    for(int j=0;j<w;j++)
    {
        int ch;
        cin>>ch;
        x[ch]=i;
        y[ch]=j;
    } 
    int d[h*w+1];
    memset(d,0,sizeof(d));
    for(int i=k+1;i<=h*w;i++)
    d[i]=d[i-k]+abs(x[i]-x[i-k])+abs(y[i]-y[i-k]);

    int q;
    cin>>q;
    for(int i=0;i<q;i++)
    {
        int l,r;
        cin>>l>>r;
        cout<<d[r]-d[l]<<endl;
    }

}

Measured memory_bytes: 5696
#include <iostream>
#include <iomanip>
#include <vector>
#include <utility>
#include <map>
#include <algorithm>
#include <queue>
#include <cmath>
#include <numeric>
#include <set>

using namespace std;
struct aaa{aaa(){cin.tie(nullptr); ios::sync_with_stdio(false); cout<<fixed<<setprecision(20);};}aaa;
template <class T>ostream &operator<<(ostream &o,const vector<T>&v){o<<"{";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")<<v[i];o<<"}";return o;}
#define debug(v) {cout<<"\033[1;36m[debug]\033[m "<<#v<<" : "<<v<<endl;}


using int64 = long long;
using P = pair<int64,int64>;


int main() {
    string s;
    cin >> s;
    int64 n = s.size();
    int64 ans = 0;

    for (int i=0; i<(1<<n-1); i++) {
        int64 tmp = 0;
        for (int j=0; j<n; j++) {
            tmp *= 10;
            tmp += s[j] - '0';

            if ((i>>j)&1) {
                ans += tmp;
                tmp = 0;
            }
        }
        ans += tmp;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
#define REP(i, s) for (int i = 0; i < s; ++i)
#define ALL(v) (v.begin(), v.end())
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)
 
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
template<class T> ostream& operator << (ostream &s, set<T> P)
{ EACH(it, P) { s << "<" << *it << "> "; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s << endl; }
typedef long long ll;

int main(){
    int n;
    int a[100010];
    cin>>n;
    REP(i,n) cin>>a[i];
    sort(a,a+n);
    vector<ll>v;
    ll sum=0;
    v.push_back(0);
    REP(i,n){
        sum+=a[i];
        v.push_back(sum);
    }
    int cnt=0;
    //v.push_back(0);
    for(int i=n-1;i>=0;i--){
        if(a[i]<=2*v[i]) cnt++;
        else break;
    }
    cout<<cnt+1<<endl;
    
    return 0;
}

Measured memory_bytes: 1784
#include<bits/stdc++.h>
using namespace std;
#define ull unsigned long long
#define mp make_pair
#define ll long long
#define pb push_back

void solve()
{
 string s,t;
 cin>>s>>t;

 int i,j;
 int n = s.length();
 int m = t.length();
 int ans = m;
 for(i=0;i<n-m+1;i++)
 {
     int count = 0;
     for(j=0;j<m;j++)
     {
         if(s[i+j] != t[j])count++;
     }
     ans = min(ans,count);
 }
 cout<<ans;


  return;
}

int main()
{

  int t = 1;
  //cin>>t;

  while(t--)
    solve();

  return 0;
}


Measured memory_bytes: 3624
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")



s = input()
K = int(input())
n = len(s)
dp = [[[0]*(K+1) for _ in range(n+2-i)] for i in range(n+1)]
for i in range(n):
    for j in range(K+1):
        dp[i][1][j] = 1
for l in range(2, n+1):
    for i in range(n-l+1):
        for k in range(K+1):
#             print(l, i, i+l, j)
            if s[i]==s[i+l-1]:
                dp[i][l][k] = dp[i+1][l-2][k] + 2
            else:
                dp[i][l][k] = max(dp[i+1][l-1][k], dp[i][l-1][k])
                if k>=1:
                    dp[i][l][k] = max(dp[i][l][k], dp[i+1][l-2][k-1]+2)
ans = max(dp[0][i][j] for i in range(n+2) for j in range(K+1))
print(ans)

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

int main(){
 string s,t;
  cin>>s>>t;
  string g="";
  int n = s.length(),m=t.length();
  int dp[n+1][m+1];
  
  for(int i=0;i<m+1;i++)
    dp[0][i]=0;
  for(int j=0;j<n+1;j++)
   dp[j][0]=0;
  
  for(int i=1;i<=n;i++){
  	for(int j=1;j<=m;j++){
         if(s[i-1]==t[j-1]){
           dp[i][j] = 1 + dp[i-1][j-1];
         }else
           dp[i][j] = max(dp[i-1][j],dp[i][j-1]);
    }
  }
  
  //cout<<dp[n][m];
  
  int i=n,j=m;
  while(i>0  && j >0){
     if(s[i-1]==t[j-1]){
      g = t[j-1] + g;
       i--,j--;
     }else{
      if(dp[i-1][j] > dp[i][j-1])
        i--;
       else
         j--;
     }
    //cout<<i<<" "<<j<<"\ "; 
  }
  cout<<g<<"\n";
  return 0;
}

Measured memory_bytes: 38864
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0;i < n;i++)
#define REP(i,n,k) for(int i = n;i < k;i++)
#define P(p) cout << (p) << endl;
#define sP(p) cout << setprecision(15) << fixed << p << endl;
#define vi vector<int>
#define printv(v) for(int i = 0;i < v.size();i++)P(v[i]);
#define printt(a,b) cout << a << " " << b << endl; 
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
int dx[] = { 1, -1 , 0 , 0};
int dy[] = { 0,  0,  1, -1};
int MOD = 1e9 + 7;

void solve() {
  ll k,a,b;
  cin >> k >> a >> b;
  ll onlyinc = k+1;
  ll trade;
  if (b-a <= 2){
      P(onlyinc);
      return;
  }else{
      trade = a + (b-a)*((k-a+1)/2);
      if((k-a+1) % 2 == 1){
          trade++;
      }
  }
  P(max(onlyinc,trade));
}

int main() {
  solve();
  return 0;
}


Measured memory_bytes: 256