akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <map>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <sstream>
#include <cmath>
#include <math.h>
#include <string>
using namespace std;
          
 
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int a;
    cin >> a;
    cout << a * 800 - ( a / 15 ) * 200;
}


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

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

  vector<int> v(1e5, 0);
  rep(i, n){
    ++v[a[i]];
    ++v[a[i] + 1];
    ++v[a[i] + 2];
  }
  vector<int>::iterator ans = max_element(v.begin(), v.end());
  cout << *ans << endl;
  return 0;
}

Measured memory_bytes: 3976
import java.util.*;
import java.util.Map.Entry;
import java.lang.*;
import java.math.*;
import java.io.*;

public class Main{
	Scanner sc=new Scanner(System.in);
	int INF=1<<28;
	double EPS=1e-9;

	int n, m;
	//int[][] w, cs;
	HashMap<Integer,Integer>[] w, cs;

	@SuppressWarnings("unchecked")
	void run(){
		for(;;){
			n=sc.nextInt();
			m=sc.nextInt();
			if((n|m)==0){
				break;
			}
			//w=new int[n][n];
			//cs=new int[n][n];
			w=new HashMap[n];
			cs=new HashMap[n];
			for(int i=0; i<n; i++){
				w[i]=new HashMap<Integer, Integer>();
				cs[i]=new HashMap<Integer, Integer>();
				//w[i].put(i, 0);
				//cs[i].put(i, 0);
				//Arrays.fill(w[i], INF);
				//Arrays.fill(cs[i], INF);
				//cs[i][i]=0;
			}
			for(int i=0; i<m; i++){
				int u=sc.nextInt()-1;
				int v=sc.nextInt()-1;
				int d=sc.nextInt();
				int c=sc.nextInt();
				// w[u][v]=w[v][u]=Math.min(w[u][v], d);
				//cs[u][v]=cs[v][u]=Math.min(cs[u][v], c);
				w[u].put(v, d);
				w[v].put(u, d);
				cs[u].put(v, c);
				cs[v].put(u, c);
			}
			solve();
		}
	}

	void solve(){
		boolean[] used=new boolean[n];
		int[] road=new int[n];
		int[] d=new int[n];

		Arrays.fill(d, INF);
		d[0]=0;

		for(;;){
			int u=-1;
			for(int v=0; v<n; v++){
				if(!used[v]&&(u==-1||d[v]<d[u])){
					u=v;
				}
			}
			if(u==-1){
				break;
			}
			debug("");
			debug("u",u);
			debug("d",d);
			debug("road",road);
			used[u]=true;
			for(Entry<Integer,Integer> entry:w[u].entrySet()){
				int v=entry.getKey();
				int w=entry.getValue();
				int c1=cs[road[v]].containsKey(v)?cs[road[v]].get(v):INF;
				int c2=cs[u].get(v);
				if(d[v]>d[u]+w){
					d[v]=d[u]+w;
					road[v]=u;
				}else if(d[v]==d[u]+w&&c1>c2){
					road[v]=u;
				}
			}
/*			for(int v=0; v<n; v++){
				if(d[v]>d[u]+w[u][v]){
					d[v]=d[u]+w[u][v];
					road[v]=u;
				}else if(d[v]==d[u]+w[u][v]&&cs[road[v]][v]>cs[u][v]){
					road[v]=u;
				}
			}*/
		}
		debug(d);
		debug(road);
		int ans=0;
		for(int i=1; i<n; i++){
			//debug("i",i);
			//debug("road[i]",road[i]);
			ans+=cs[i].get(road[i]);
		}
		debug(ans);
		println(""+ans);
	}

	void debug(Object... os){
		//System.err.println(Arrays.deepToString(os));
	}

	void print(String s){
		System.out.print(s);
	}

	void println(String s){
		System.out.println(s);
	}

	public static void main(String[] args){
		try{
			// System.setIn(new FileInputStream("in.txt"));
		}catch(Throwable e){
			e.printStackTrace();
		}
		new Main().run();
	}
}

Measured memory_bytes: 20000
#include <iostream>
#include <algorithm>
using namespace std;
#include <cstdio>
#include <tuple>
#include <string>
#include <vector> 
#include <set>
#include <string.h>
#include <map>
using Graph = vector<vector<int>>;
using Graph_Wei = vector<vector<pair<int,int>>>;
using ll = long long;


/* a と b の最大公約数を返す関数 */
long long GCD(long long a, long long b) {
    if (b == 0) return a;
    else return GCD(b, a % b);
}
int main() {

    ll n;
    cin >> n;
    vector<pair<ll,ll>> a;

    
    //二数の組みを作る
    for(ll i =1;i < n;i++){
        ll k = n / i;
        if(i > k) break;
        ll p = n % i;
        if(p == 0) {
            
            a.push_back(make_pair(i,k));
        }
    }
    ll index =0;
    ll min =0;
    //経路長が最小のものを求める
    for(ll i=0;i < a.size();i++){

        ll nagasa = a[i].first - 1 + a[i].second -1;
        if(i == 0) min =  nagasa;
        if(min > nagasa) {
            min = nagasa;
            index = i;
        }
    }
    cout << min << endl;
    


    return 0;

}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
int main()
{

    int n,i,al=0,bob=0;
    cin>>n;
    int a[n];
    for(i=0;i<n;i++)
    {
        cin>>a[i];
    }
    sort(a,a+n);
    for(i=0;i<n;i+=2)
    {
       al+=a[i];
    }
    for(i=1;i<n;i+=2)
    {
       bob+=a[i];
    }
    cout<<abs(al-bob)<<endl;
    return 0;
}



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

//#define int long long
#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define rept(i,n) for(int (i)=0;(i)<=(int)(n);(i)++)
#define reps(i,s,n) for(int (i)=(s);(i)<(int)(n);(i)++)
#define repst(i,s,n) for(int (i)=(s);(i)<=(int)(n);(i)++)
#define repr(i,n) for(int (i)=(n);(i)>=0;(i)--)
#define each(itr,v) for(auto (itr):(v))
#define all(c) (c).begin(),(c).end()
#define pb push_back
#define mp(x,y) make_pair((x),(y))
#define fi first
#define se second
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
#define ln '\n'
#define dbg(x) cout<<#x" = "<<(x)<<ln

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

const int inf = (int)1e9;
const ll linf = (ll)1e18;
const int mod = (int)(1e9+7);
const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};
const int ddx[] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[] = {1, 1, 0, -1, -1, -1, 0, 1};
const double eps = 1e-10;

struct oreno_initializer {
	oreno_initializer() {
		cin.tie(0);
		ios::sync_with_stdio(0);
	}
} oreno_initializer;

// ━━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…
// .｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋
// ・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・

// r[i][j]: j番目のホテルから2^i日以内に行ける最も右のホテルの番号
// i==0は二分探索、i>=1はダブリングで求められる
int n, x[100000], l, q, a, b, r[20][100000];

void getr() {
	rep(i,n) {
		int tmp = upper_bound(x,x+n,x[i]+l) - x;
		tmp--;
		r[0][i] = tmp;
	}
	reps(i,1,20) rep(j,n) r[i][j] = r[i-1][r[i-1][j]];
}

int ans() {
	a--, b--;
	if (a>b) swap(a,b);
	int res = 0;
	repr(i,19) {
		if (r[i][a]<b) {
			a = r[i][a];
			res += 1<<i;
		}
	}
	return res+1;
}

signed main() {
	cin >> n;
	rep(i,n) cin >> x[i];
	cin >> l >> q;
	getr();
	while (q--) {
		cin >> a >> b;
		cout << ans() << ln;
	}
}

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

#define BUF_SIZE 110000

int* fget_array(int *arr, int size, char *line) {
  char *tmpbuf = line;
  int i;
  for(i = 0; i < size; i++) {
    char *tmp = strtok(tmpbuf, " ");
    arr[i] = strtol(tmp, NULL, 10);
    tmpbuf = NULL;
  }
  return arr;
}
#define HTABLE_SIZE 65536
#define KEY_MASK 65535

int get_key(int num) {
  return num & KEY_MASK;
}

struct list {
  struct list *next;
  int num;
};

struct list *create_htable(int size) {
  struct list *htable = malloc(sizeof(struct list)*size);
  int i;
  for(i = 0; i < size; i++) {
    htable[i].next = &htable[i];
  }
  return htable;
}

struct list *find(struct list *htable, int num) {
  struct list *head = &htable[get_key(num)];
  struct list *tmp;
  for(tmp = head->next; tmp != head; tmp = tmp->next) {
    if(tmp->num == num) return tmp;
  }
  return NULL;
}

void insert(struct list *htable, int num) {
  int key = get_key(num);
  struct list *head = &htable[key];
  struct list *elem = find(htable, num);
  if(elem) return;
  // or create
  elem = malloc(sizeof(struct list));
  elem->next = head->next;
  head->next = elem;
  elem->num = num;
  return;
}

int main(void) {
  FILE *fp = stdin;
  char line[BUF_SIZE];
  int i, j;

  if(!fgets(line, BUF_SIZE, fp)) return 0;
  int num;
  sscanf(line, "%d", &num);
  struct list *htable = create_htable(HTABLE_SIZE);

  if(!fgets(line, BUF_SIZE, fp)) return 0;
  char *tmpbuf = line;
  for(i = 0; i < num; i++) {
    char *tmp = strtok(tmpbuf, " ");
    int n = strtol(tmp, NULL, 10);
    insert(htable, n);
    tmpbuf = NULL;
  }

  int queries;
  if(!fgets(line, BUF_SIZE, fp)) return 0;
  sscanf(line, "%d", &queries);


  if(!fgets(line, BUF_SIZE, fp)) return 0;
  tmpbuf = line;
  int cnt = 0;
  for(i = 0; i < queries; i++) {
    char *tmp = strtok(tmpbuf, " ");
    int q = strtol(tmp, NULL, 10);
    if(find(htable, q)) {
      cnt++;
    }
    tmpbuf = NULL;
  }

  printf("%d\n", cnt);
  return 0;
}


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

int main() {
  int n;
  cin >> n;
  ll ans=0;
  for(int i=1; i<=n; i++){
    if(i%3!=0&&i%5!=0){
      ans+=i;
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 3620
#include <stdio.h>
#include <bits/stdc++.h>
  
#define uint unsigned int
#define ll long long
#define ull unsigned long long
#define ld long double
#define rep(i, l, r) for (int i = l; i < r; i++)
#define repb(i, r, l) for (int i = r; i > l; i--)
#define sz(a) (int)a.size()
#define fi first
#define se second
#define mp(a, b) make_pair(a, b)
  
using namespace std;
  
const int N = 2000;
const int inf = (int)1e9 + 1;
const ll big = (ll)1e18 + 1;
const int PPP = 239;
const int MOD = (int)1e9 + 7;
const int MOD1 = (int)1e9 + 9;
const double eps = 1e-9;
const double pi = atan2(0, -1);
const int ABC = 26;

int a[N][N];
int b[N - 1];
int L[N - 1], R[N - 1];
int dp[2][2][N][N - 1];

int main()
{
    //freopen("a.in", "r", stdin);
    //freopen("a.out", "w", stdout);
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.precision(20);
    //ll TL = 2.95 * CLOCKS_PER_SEC;
    //clock_t time = clock();
    int n, m;
    cin >> n >> m;
    rep(i, 0, n)
    {
        string s;
        cin >> s;
        rep(j, 0, m)
            a[i][j] = (s[j] == '#');
    }
    rep(x, 0, 2)
        rep(y, 0, 2)
        {
            rep(i, 0, n)
                rep(j, 0, m - 1)
                    if ((a[i][j] ^ x) == (a[i][j + 1] ^ y))
                        dp[x][y][i][j] = 1 + (i > 0 ? dp[x][y][i - 1][j] : 0);
                    else
                        dp[x][y][i][j] = 0;
        }
    int ans = 0;
    rep(i, 0, n)
    {
        rep(j, 0, m - 1)
            b[j] = dp[a[i][j]][a[i][j + 1]][i][j];
        /*rep(j, 0, m - 1)
            cout << b[j] << " ";
        cout << "\n";*/
        vector<pair<int, int> > st;
        st.push_back({-1, -1});
        rep(j, 0, m - 1)
        {
            while (st.back().fi >= b[j])
                st.pop_back();
            L[j] = st.back().se;
            st.push_back({b[j], j});
        }
        st.clear();
        st.push_back({-1, m - 1});
        repb(j, m - 2, -1)
        {
            while (st.back().fi >= b[j])
                st.pop_back();
            R[j] = st.back().se;
            st.push_back({b[j], j});
        }
        rep(j, 0, m - 1)
            ans = max(ans, b[j] * (R[j] - L[j]));
    }
    cout << max(ans, max(n, m)) << "\n";
    return 0;
}

Measured memory_bytes: 78336
#include <bits/stdc++.h>
#define ll long long int
#define INF (ll)1000000000
#define MOD 1000000007
#define DEBUG(x) cerr<<'>'<<#x<<':'<<x<< endl
using namespace std;
#define min max
ll ans[100005][3], a[100005], b[100005], c[100005];

ll F(ll cur, ll cond)
{
    if(ans[cur][cond] != -1)
        return ans[cur][cond];
    else if(cur == 1)
    {
        ll mn = -1;
        if(cond != 0)
            mn = min(mn, a[1]);
        if(cond != 1)
            mn = min(mn, b[1]);
        if(cond != 2)
            mn = min(mn, c[1]);
        return ans[cur][cond] = mn;
    }
    else
    {
        ll mn = -1;
        if(cond == 0)
        {
            mn = min(mn, F(cur - 1, 1) + b[cur]);
            mn = min(mn, F(cur - 1, 2) + c[cur]);
            return ans[cur][cond] = mn;
        }
        if(cond == 1)
        {
            mn = min(mn, F(cur - 1, 0) + a[cur]);
            mn = min(mn, F(cur - 1, 2) + c[cur]);
            return ans[cur][cond] = mn;
        }
        if(cond == 2)
        {
            mn = min(mn, F(cur - 1, 1) + b[cur]);
            mn = min(mn, F(cur - 1, 0) + a[cur]);
            return ans[cur][cond] = mn;
        }
    }
}


signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll N;
    cin >> N;
    for(int i = 1; i <= N; i++)
    {
        cin >> a[i] >> b[i] >> c[i];
        ans[i][0] = -1;
        ans[i][1] = -1;
        ans[i][2] = -1;
    }   
    ll mn = -1; 
    for(int i = 0; i <= 2; i++)
        mn = min(mn, F(N, i));
    cout << mn << endl;
    return 0;
}


Measured memory_bytes: 9600
import java.util.*;

public class Main {
	static final long MOD = 1000000007;

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int X = sc.nextInt();
		int Y = sc.nextInt();
		int Z = sc.nextInt();
		
		int L = X+Y+Z;
		int match = 1<<(X+Y+Z-1) | 1<<(Y+Z-1) | 1<<(Z-1);
		int mask = (1<<(L-1))-1;
		
		long[][] dp = new long[N+1][1<<(L-1)];
		dp[0][0] = 1;
		for(int i=0; i<N; i++) {
			for(int j=0; j<=mask; j++) {
				for(int k=1; k<=10; k++) {
					int next = j<<k | 1<<(k-1);
					if(((next&((1<<L)-1))&match)!=match) {
						dp[i+1][next&mask] = (dp[i+1][next&mask] + dp[i][j])%MOD;
					}
				}
			}
		}
		
		long ans = 1;
		for(int i=0; i<N; i++)
			ans = (ans * 10)%MOD;
		for(int i=0; i<1<<(L-1); i++)
			ans = (ans + MOD - dp[N][i])%MOD;
		
		System.out.println(ans);
		sc.close();
	}
	
}


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

string shuffle(string str,int h){
    string head=str.substr(0,h);
    string tail=str.substr(h,str.size()-h);
    return tail+head;
}

int main(){
    string cards;
    int m,h;
    
    while(1){
        cin>>cards;
        if (cards=="-") break;
        
        cin>>m;
        for (int i=0;i<m;i++){
            cin>>h;
            cards=shuffle(cards,h);
        }
        cout<<cards<<endl;;
        
    }
    
    return 0;
}


Measured memory_bytes: 3224
#include <bits/stdc++.h>
#define rep(i, n) for(ll i = 0; i < n; ++i)
#define repR(i, n) for(ll i = n; i >= 0; ++i)
#define FDS(i, n) for(ll i = 0; i < n; ++i)
#define FDSR(i, n) for(ll i = n; i >= 0; ++i)
#define FOR(i, m, n) for(ll i = m; i < n; ++i)
#define FORR(i, m, n) for(ll i = m;i >= n;--i)
#define VSORT(v) sort(v.begin(), v.end());
#define VREV(v) reverse(v.begin(), v.end());
#define INF 999999999
#define itn ll
#define ednl endl
using namespace std;
typedef long long ll;template<typename Typell>Typell G_C_D(Typell a, Typell b){if (a < 0) a = -a;if (b < 0) b = -b;while (b != 0) {a %= b;if (a == 0) return b;b %= a;}return a;}template<typename Typell>
Typell G_C_D(const std::vector<Typell> &list){Typell a = list[0];for (size_t i = 1; i < list.size(); ++i) {a = G_C_D(a, list[i]);}return a;}template<typename Typell>Typell L_C_M(Typell a, Typell b) {if( a == 0 && b == 0)return 0;return a / G_C_D(a, b) * b;}
template<typename Typell>Typell L_C_M(const std::vector<Typell> &list){Typell a = list[0];for (size_t i = 1; i < list.size(); ++i) {a = L_C_M(a, list[i]);}return a;}

int main(){
	cin.tie(0);ios::sync_with_stdio(false);
	int N,L;
	cin>>N>>L;
	int M=INF;
	int t=0;
	FDS(i,N){
		if(M>abs(L+i)){
		    M=abs(L+i);
			t=L+i;
		}
	}
	int ans=0;
	FDS(i,N){
		ans+=L+i;
	}
	cout<<ans-t<<endl;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(){
    string S;
    cin >> S;
    int ans1 = 0, ans2 = 0;
    for(int i = 0; i < S.size(); i++){
        if(i%2 == 0 && S[i] == '0') ans1++;
        if(i%2 == 0 && S[i] == '1') ans2++;
        if(i%2 == 1 && S[i] == '0') ans2++;
        if(i%2 == 1 && S[i] == '1') ans1++;
    }
    cout << min(ans1, ans2) << endl;
}

Measured memory_bytes: 512
#include <cstdio>
#include <string>
#include <vector>
#include <cctype>
#include <iostream>
using namespace std;


string str1;
bool flag=false;

int main(int argc, char const *argv[])
{
	int a,b; cin>>a>>b;
	cin>>str1;
	int len=str1.length();
	for(int i=0 ;i<a; i++){
		if(!isdigit(str1[i])){
			goto fin;
			break;
		}
	}

	if(!str1[a]=='-') goto fin;
	for(int i=a+1; i<len ;i++){
		if(!isdigit(str1[i])){
			goto fin;
			break;
		}
	}
	if(str1[a]=='-') flag=true;

	fin:	if(flag==true) cout<<"Yes"<<endl;
			else cout<<"No"<<endl;
	return 0;
}

Measured memory_bytes: 256
using System;
public class Eratosthenes
{
	public static void Main(string[] args)
	{
		int count = int.Parse(Console.ReadLine());
		int sum = 0;//?´???°???????¨?
		
		for (int i = 0; i < count; i++)
		{
			//?????????????±????????????????
			int target = int.Parse(Console.ReadLine());
			//????????????
			//target???3??\????????£???????????§??????????????????if?????????????????\????????????
			if(target==2||target==3)
			{
				sum++;
			}
			else if ((target > 3) && ((target % 2) != 0)) 
			{
				
				int j = 3;
				do{				
					if (target % j == 0)
					{//?´???°??§?????????
						break;
					}
					
					
					j+=2;
				}while(j<=target/j);
				if (j  > target / j)
					{
						//break?????????????????´????????????????????\???
						sum ++;
						
					}
				
			}
			
		}
		
		Console.WriteLine(sum);
	}
}

Measured memory_bytes: 9136
#pragma GCC optimize("O3")
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
using namespace std;

using ll = long long;
using P = pair<int, int>;
using T = tuple<int, int, int>;

template <class T> inline T chmax(T &a, const T b) {return a = (a < b) ? b : a;}
template <class T> inline T chmin(T &a, const T b) {return a = (a > b) ? b : a;}

constexpr int MOD = 1e9 + 7;
constexpr int inf = 1e9;
constexpr long long INF = 1e18;

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

ll modpow(ll a, ll b){
    if(b == 0) return 1;
    else if(b % 2 == 0){
        ll d = modpow(a, b / 2) % MOD;
        return (d * d) % MOD;
    }
    else{
        return (a * modpow(a, b - 1)) % MOD;
    }
}

const int MAX_N = 1010;

ll fact[MAX_N], finv[MAX_N];
ll comb(int n, int r){
    if(n < r || r < 0) return 0;
    return fact[n] * finv[n-r] % MOD * finv[r] % MOD;
}

void calc(int n){
    fact[0] = finv[0] = 1;
    for(int i=1; i<=n; i++){
        fact[i] = (fact[i-1] * i) % MOD;
        finv[i] = modpow(fact[i], MOD - 2);
    }
}

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

    int n, k; cin>>n>>k;

    calc(1005);

    cout << comb(k, n) * fact[n] % MOD << endl;

    return 0;
}


Measured memory_bytes: 3204
#include<cstdio>
#include<algorithm>
using namespace std;
const int N=100010;
int a[100010],n,x;
int main()
{
	scanf("%d",&n);
	while(n--)
	{
		scanf("%d",&x);
		a[x+1]++;
		a[x]++;
		a[x-1]++; 
	}
	for(int i=1;i<=100000;i++)
		n=max(n,a[i]);
	printf("%d",n);
}

Measured memory_bytes: 640
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>

using namespace std;
typedef long long ll;
#define rep(i,n) for (int i=0;i < (int)(n);i++)

ll ans = 0;
ll n;

void dfs(ll cur, int use){
  if (cur > n) return;
  if (use == 0b111) ans++;
  dfs(cur*10+7,use | 0b001);
  dfs(cur*10+5,use | 0b010);
  dfs(cur*10+3,use | 0b100);
}

int main(){
  cin >> n;
  dfs(0,0);
  cout << ans << endl;
  
  return 0; 
}



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

#define MAX 500000
#define SENTINEL 2000000000

int LEFT[MAX / 2 + 2];
int RIGHT[MAX / 2 + 2];

int cnt = 0;

void merge(int A[],int left,int mid,int right){
    int n1 = mid - left;
    int n2 = right - mid;
    
    for(int i = 0;i < n1;++i){
        LEFT[i] = A[left + i];
    }
    
    for(int i = 0;i < n2;++i){
        RIGHT[i] = A[mid + i];
    }
    
    LEFT[n1] = RIGHT[n2] = SENTINEL;
    int i = 0;
    int j = 0;
    
    for(int k = left;k < right;++k){
        cnt++;
        if(LEFT[i] <= RIGHT[j]){
            A[k] = LEFT[i++];
        }
        else{
            A[k] = RIGHT[j++];
        }
    }
}

void mergeSort(int A[],int n,int left,int right){
    if(left + 1 < right){
        int mid = (left + right) / 2;
        mergeSort(A,n,left,mid);
        mergeSort(A,n,mid,right);
        merge(A,left,mid,right);
    }
}

int main(){
    int A[MAX],n;
    
    cin >> n;
    for(int i = 0;i < n;++i){
        cin >> A[i];
    }
    
    mergeSort(A,n,0,n);
    
    for(int i = 0;i < n;++i){
        if(i){
            cout << " ";
        }
        cout << A[i];
    }
    cout << endl;
    
    cout << cnt << endl;
}



Measured memory_bytes: 6956
#include<cstdio>
#include<cstring>
#include<iostream> 
#include<cmath>
#include<algorithm>
#include<stdlib.h>
using namespace std;

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

Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int n,t,a;double h[1005];
int main(){
    ios::sync_with_stdio(false);
    cin>>n>>t>>a;
    for(int i=1;i<=n;i++){
        cin>>h[i];
        h[i] = 1.0*t-h[i]*0.006;
    }
    int ind = -1;
    double tmp = 10000000;
    for(int i=1;i<=n;i++){
        if(abs(h[i]-a)<tmp){
            tmp = abs(h[i]-a);
            ind = i;
        }
    }
    cout<<ind<<endl;
}


Measured memory_bytes: 256
import itertools
from collections import deque,defaultdict,Counter
from itertools import accumulate
import bisect
from heapq import heappop,heappush,heapify
import math
from copy import deepcopy
import queue
#import numpy as np
# sympy as syp(素因数分解とか)
Mod = 1000000007
fact = [1, 1]
factinv = [1, 1]
inv = [0, 1] 
for i in range(2, 10**5 + 1):
    fact.append((fact[-1] * i) % Mod)
    inv.append((-inv[Mod % i] * (Mod // i)) % Mod)
    factinv.append((factinv[-1] * inv[-1]) % Mod)
    
def cmb(n, r, p):
    if (r < 0) or (n < r):
        return 0
    r = min(r, n - r)
    return fact[n] * factinv[r] * factinv[n - r] % p
    
def sieve_of_eratosthenes(n):
    if not isinstance(n,int):
        raise TypeError("n is not int")
    if n<2:
        raise ValueError("n is not effective")
    prime = [1]*(n+1)
    for i in range(2,int(math.sqrt(n))+1):
        if prime[i] == 1:
            for j in range(2*i,n+1):
                if j%i == 0:
                    prime[j] = 0
    res = []
    for i in range(2,n+1):
        if prime[i] == 1:
            res.append(i)
    return res

 
class UnionFind:
    def __init__(self,n):
        self.parent = [i for i in range(n+1)]
        self.rank = [0 for i in range(n+1)]
    
    def findroot(self,x):
        if x == self.parent[x]:
            return x
        else:
            y = self.parent[x]
            y = self.findroot(self.parent[x])
            return y
    
    def union(self,x,y):
        px = self.findroot(x)
        py = self.findroot(y)
        if px < py:
            self.parent[y] = px
        else:
            self.parent[px] = py
 
    def same_group_or_no(self,x,y):
        return self.findroot(x) == self.findroot(y)
import string
def main():  #startline-------------------------------------------
    n = int(input())
    print(1000-n%1000 if n % 1000 != 0 else 0)
if __name__ == "__main__":
    main() #endline===============================================

Measured memory_bytes: 21996
#include<bits/stdc++.h> 
#define ll long long
#define pb push_back
#define mp make_pair
using namespace std;
ll gcd(ll a,ll b) 
{ 
	if (a == 0) 
		return b; 
	return gcd(b % a, a); 
} 
bool isprime(ll n)
{
    for(ll i=2;i<=sqrt(n);i++)
    {
        if(n%i==0)
            return false;
    }
    return true;
}
int main()
{
	ll a[26]={0};
	string s;
	cin>>s;
	for(ll i=0;i<s.size();i++)
	{
		a[s[i]-65]++;
	}
	ll ctr=0,ctr1=0;
	for(ll i=0;i<26;i++)
	{
		if(a[i]>0)
		{
			ctr1++;
		}
		if(a[i]==2)
		{
			ctr++;
		}
	}
	if(ctr==2&&ctr1==2)
	{
		cout<<"Yes";
	}
	else
	{
		cout<<"No";
	}
	return 0;
}

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

namespace NIKKEI2019B
{
    public class Program
    {
        void Solve(StreamScanner ss, StreamWriter sw)
        {
            //---------------------------------
            var N = ss.Next(int.Parse);
            var A = ss.Next(String);
            var B = ss.Next(String);
            var C = ss.Next(String);

            var ret = 0;
            for (var i = 0; i < N; i++)
            {
                var x = new[] {A[i], B[i], C[i]}.Distinct().Count();
                if (x == 1) ret += 0;
                if (x == 2) ret += 1;
                if (x == 3) ret += 2;
            }

            sw.WriteLine(ret);
            //---------------------------------
        }

        static void Main()
        {
            var ss = new StreamScanner(new StreamReader(Console.OpenStandardInput()));
            var sw = new StreamWriter(Console.OpenStandardOutput()) {AutoFlush = false};
            new Program().Solve(ss, sw);
            sw.Flush();
        }

        static readonly Func<string, string> String = s => s;
    }

    public class StreamScanner
    {
        static readonly char[] Sep = {' '};
        readonly Queue<string> buffer = new Queue<string>();
        readonly TextReader textReader;

        public StreamScanner(TextReader textReader)
        {
            this.textReader = textReader;
        }

        public T Next<T>(Func<string, T> parser)
        {
            if (buffer.Count != 0) return parser(buffer.Dequeue());
            var nextStrings = textReader.ReadLine().Split(Sep, StringSplitOptions.RemoveEmptyEntries);
            foreach (var nextString in nextStrings) buffer.Enqueue(nextString);
            return Next(parser);
        }

        public T[] Next<T>(Func<string, T> parser, int x)
        {
            var ret = new T[x];
            for (var i = 0; i < x; ++i) ret[i] = Next(parser);
            return ret;
        }

        public T[][] Next<T>(Func<string, T> parser, int x, int y)
        {
            var ret = new T[y][];
            for (var i = 0; i < y; ++i) ret[i] = Next(parser, x);
            return ret;
        }
    }
}

Measured memory_bytes: 13280
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
struct matrix{
    ll a[52][52];
}res,tmp,ans;
ll n,k,mod=1000000007,answ;
matrix times(matrix &a,matrix &b)
{
    for(int i=1;i<=n;i++)
    for(int j=1;j<=n;j++) tmp.a[i][j]=0;
    for(int i=1;i<=n;i++)
    for(int j=1;j<=n;j++)
    for(int k=1;k<=n;k++) tmp.a[i][j]+=a.a[i][k]*b.a[k][j],tmp.a[i][j]%=mod;
    return tmp;
}
int main()
{
    scanf("%lld%lld",&n,&k);
    for(int i=1;i<=n;i++)
    for(int j=1;j<=n;j++) scanf("%lld",&res.a[i][j]);
    ans=res;k--;
    while(k){
        if(k&1) ans=times(ans,res);
        k>>=1,res=times(res,res);
    }
    for(int i=1;i<=n;i++)
    for(int j=1;j<=n;j++) answ=(answ+ans.a[i][j])%mod;
    printf("%lld",answ);
    return 0;
}

Measured memory_bytes: 384
#include <iostream>
using namespace std;
#define NIL -1
#define MAX 10000

struct Node {
    int p, l, r;
};

Node T[MAX];
int D[MAX];
int H[MAX];

int getSibling(int id) {
    int p;
    if (T[id].p != NIL) {
        p = T[id].p;
        if (T[p].l != NIL && T[p].l != id) return T[p].l;
        else if (T[p].r != NIL && T[p].r != id) return T[p].r;
    } else {
        return NIL;
    }
    return NIL;
}

int getDegree(int id) {
    int d = 0;
    if (T[id].l != NIL) d++;
    if (T[id].r != NIL) d++;
    return d;
}

// Set depth for each node using recursion
void setDepth(int id, int d) {
    D[id] = d;
    if (T[id].l != NIL) setDepth(T[id].l, d+1);
    if (T[id].r != NIL) setDepth(T[id].r, d+1); 
}

// Set height for each node using recursion
int setHeight(int id) {
    int h1=0, h2=0;
    if (T[id].l != NIL) h1 = setHeight(T[id].l) + 1;
    if (T[id].r != NIL) h2 = setHeight(T[id].r) + 1;
    return H[id] = (h1 > h2 ? h1 : h2);
}

void printTree(int id) {
    int i, j, c;

    cout << "node " << id << ": ";
    cout << "parent = " << T[id].p << ", ";
    cout << "sibling = " << getSibling(id) << ", ";
    cout << "degree = " << getDegree(id) << ", ";
    cout << "depth = " << D[id] << ", ";
    cout << "height = " << H[id] << ", ";

    if (T[id].p == NIL) cout << "root" << endl;
    else if (T[id].l == NIL && T[id].r == NIL) cout  << "leaf" << endl;
    else cout << "internal node" << endl;
}

int main() {
    int n, id, l, r, i;

    cin >> n;
    for (i=0; i < n; i++) T[i].p = T[i].l = T[i].r = NIL;
    
    for (i=0; i < n; i++) {
        cin >> id >> l >> r;
        T[id].l = l;
        T[id].r = r;
        if (l != NIL) T[l].p = id;
        if (r != NIL) T[r].p = id;
    }

    for (i=0; i < n; i++) {
        if (T[i].p == NIL) r = i;
    }
    setDepth(r, 0);
    setHeight(r);
    for (i=0; i < n; i++) printTree(i);

    return 0;
}


Measured memory_bytes: 3092
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<iostream>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<sstream>
#include<unordered_map>
#include<unordered_set>
#include<vector>
#include<random>
using ll = long long;
enum : int { M = (int)1e9 + 7 };
enum : ll { MLL = (ll)1e18L + 9 };
using namespace std;
#ifdef LOCAL
#include"rprint2.hpp"
#include"debug_deque.hpp"
// #define vector DebugDeque
#else
#define FUNC(name) template <ostream& out = cout, class... T> void name(T&&...){ }
FUNC(prints) FUNC(printe) FUNC(printw) FUNC(printew) FUNC(printb) FUNC(printd) FUNC(printde) FUNC(printdu);
#endif
template <class S, class T>
istream& operator >> (istream& in, pair<S, T>& p){ return in >> p.first >> p.second; }
template <class T>
istream& operator >> (istream& in, vector<T>& v){ for(auto& e : v){ in >> e; } return in; }

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll l, n;
    cin >> l >> n;
    vector<ll> xs(n + 1);
    xs[0] = 0;
    for(int i = 0; i < n; i++){
        cin >> xs[i + 1];
    }
    vector<ll> ys;
    ys.push_back(0);
    // vector<ll> xs(n); cin >> xs;
    // vector<ll> ys;
    ll maxi = 0;
    // ll 
    vector<ll> accx(n + 1), accy(n + 1);
    for(int i = 0; i < n; i++){
        accx[i + 1] = accx[i] + xs[i + 1];
    }
    for(int i = 0; i <= n; i++){
        int xNum = n - i, yNum = i;
        printde(xs, ys, xNum, yNum);
        // int mini = max(0, (int)min(xs.size(), ys.size()) - 1);
        int mini = (int)min(xs.size(), ys.size()) - 1;
        // int xNum = n - i, yNum = i + 1;
        ll cand1 = (accy[yNum] - accy[yNum - mini]) * 2 + ((int)xs.size() > mini ? accx[xNum] - accx[max(0, xNum - mini - 1)] : accx[xNum]) * 2 - xs.back();
        ll cand2 = (accx[xNum] - accx[xNum - mini]) * 2 + ((int)ys.size() > mini ? accy[yNum] - accy[max(0, yNum - mini - 1)] : accy[yNum]) * 2 - ys.back();
        // ll cand2 = (accx[xNum] - accx[xNum - mini]) * 2 + ((int)ys.size() > mini ? accy[yNum] - accy[yNum - mini - 1] : accy[yNum]) * 2 - ys.back();
        // ll cand1 = accumulate(ys.end() - mini, ys.end(), 0ll) * 2 + accumulate((int)xs.size() > mini ? xs.end() - mini - 1 : xs.begin(), xs.end(), 0ll) * 2 - xs.back();
        // ll cand2 = accumulate(xs.end() - mini, xs.end(), 0ll) * 2 + accumulate((int)ys.size() > mini ? ys.end() - mini - 1 : ys.begin(), ys.end(), 0ll) * 2 - ys.back();
        printde(i, cand1, cand2);
        maxi = max(maxi, cand1);
        maxi = max(maxi, cand2);
        if(i == n){ break; }
        ys.push_back(l - xs.back());
        printde(accy.size(), yNum);
        // accy[yNum] = accy[yNum - 1] + ys.back();
        accy[yNum + 1] = accy[yNum] + ys.back();
        xs.pop_back();
        printde(accx, accy);
    }
    printde(accx, accy);
    cout << maxi << '\n';
}


Measured memory_bytes: 7156
n = gets.to_i

test = 111

array = [111, 222, 333, 444, 555, 666, 777, 888, 999]

array.each_with_index do |item, idx|
  if array[idx] == n
    test = n
    break
  end
  if (array[idx] < n) && (array[idx+1] > n)
    test = array[idx+1]
    break
  end
end

puts test


Measured memory_bytes: 1788
n,l=map(int,input().split())
a=list(map(int,input().split()))
ok=False
for i in range(n-1):
    if a[i]+a[i+1]>=l:
        ok=True
        idx=i
if ok:
    print("Possible")
    for i in range(1,idx+1):
        print(i)
    for i in reversed(range(idx+2,n)):
        print(i)
    print(idx+1)
else:
    print("Impossible")

Measured memory_bytes: 20080
#include"bits/stdc++.h"
#include <boost/multi_array.hpp>
#include <boost/optional.hpp>
#include <boost/range/irange.hpp>
#include <boost/range/algorithm.hpp>
#include <boost/range/adaptors.hpp>
//#include <vector>
//#include <iostream>

typedef long long ll;
typedef unsigned long long ull;

#define MOD 1000000007
ll modinv(ll a, ll m) {
	ll b = m, u = 1, v = 0;
	while (b) {
		ll t = a / b;
		a -= t * b; std::swap(a, b);
		u -= t * v; std::swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}

int N;

void Main()
{
	std::cin >> N;
	if (N < 10) {
		std::cout << "Yes" << std::endl;
		return;
	}
	for (int i = 2; i < 10; i++) {
		if (N % i == 0) {
			if (N / i < 10) {
				std::cout << "Yes" << std::endl;
				return;
			}
		}
	}
	std::cout << "No" <<std::endl;
	return;
}

int main()
{
	std::cin.tie(nullptr);
	std::ios_base::sync_with_stdio(false);
	std::cout << std::fixed << std::setprecision(15);
	Main();
}


Measured memory_bytes: 256
#include <stdio.h>

int main(){
    int x[5];
    int i;
    
    for(i = 0; i < 5; i++){
        scanf("%d",&x[i]);
    }

    for(i = 0; i < 5; i++){
        if(x[i] == 0)
            break;
    }

    printf("%d\n", i + 1);
    return 0;
}

Measured memory_bytes: 1644
#include <iostream>
#include <vector>

using namespace std;

struct UnionFind {
  vector<long> data;
  UnionFind(long size) : data(size, -1) { }
  bool unionSet(long x, long y) {
    x = root(x); y = root(y);
    if (x != y) {
      if (data[y] < data[x]) swap(x, y);
      data[x] += data[y]; data[y] = x;
    }
    return x != y;
  }
  bool findSet(long x, long y) {
    return root(x) == root(y);
  }
  long root(long x) {
    return data[x] < 0 ? x : data[x] = root(data[x]);
  }
  long size(long x) {
    return -data[root(x)];
  }
};

vector<long> A, B;
bool used[100000];
bool r_used[100000];

int main(){
    long N, M, Q;
    cin >> N >> M >> Q;
    UnionFind uf(N);
    for(long i = 0; i < Q; i++){
        long a, b, c;
        cin >> a >> b >> c;
        if(c == 0){
            uf.unionSet(a, b);
        }else{
            A.push_back(a);
            B.push_back(b);
        }
    }
    long cnt = 0;
    vector<long> vr;
    for(long i = 0; i < N; i++){
        long root = uf.root(i);
        if(!used[root]){
            cnt++;
            used[root] = true;
            vr.push_back(root);
        }
    }
    for(long i = 0;i < A.size(); i++){
        if(uf.findSet(A[i], B[i])){
            cout << "No" << endl;
            return 0;
        }else{
            r_used[uf.root(A[i])] = true;
            r_used[uf.root(B[i])] = true;
        }
    }
    long cnt_unused = 0;
    long e_tree = 0;
    for(long i = 0; i < vr.size(); i++){
        if(!r_used[vr[i]]) cnt_unused++;
        e_tree += (uf.size(vr[i])-1);
    }
    //cout << e_tree << endl;
    long e_max, e_min;
    e_max = ((N-e_tree)*(N-e_tree-1))/2;
    e_min = cnt-cnt_unused;
    if(e_tree+e_min <= M && e_tree+e_max >= M){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
}

Measured memory_bytes: 4204
#include<bits/stdc++.h>
#include<unordered_map>
#include<math.h>
#define ll long long
#define fast_cin() ios_base::sync_with_stdio(false); cin.tie(NULL)
#define pb push_back
#define rep(i,a,b) for(int i=a;i<b;i++)
#define repr(i,a,b) for(int i=a;i>=b;i--)
#define vi vector<int>
#define vll vector<long long>
#define print(vec) for(int i=0;i<vec.size();i++) cout<<vec[i]<<" ";
#define mp make_pair
#define pii pair<int,int>
#define pll pair<ll,ll>
#define endl '\n'

using namespace std;

int main(){
    fast_cin();
    int n,k;
    cin>>n>>k;
    vll ar(n,0LL);
    rep(i,0,n)cin>>ar[i];

    rep(i,k,n){
        if(ar[i]>ar[i-k])
        cout<<"Yes"<<endl;
        else
        cout<<"No"<<endl;

    }
    
}

Measured memory_bytes: 4768
N = int(input())
T, A = map(int, input().split())
Hi = list(map(int, input().split()))

min_diff = 10000000000
selected = -1
for i, h in enumerate(Hi):
    t = T - h * 0.006
    d = abs(t - A)
    if d < min_diff:
        min_diff = d
        selected = i
print(selected + 1)


Measured memory_bytes: 3060
#include<bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rep2(i, m, n) for(int i = (int)(m); i < (int)(n); i++)
#define rep_inv(i, n, m) for(int i = (int)(n); i > (int)(m); i--)
using namespace std;
using ll = long long;
using vl = vector<ll>;
using vc = vector<char>;
using vvl = vector<vl>;
using vvc = vector<vc>;
using pll = pair<ll, ll>;
using vpll = vector<pll>;

int main(){
  ll H, W;
  cin >> H >> W;
  vvc s(H, vc(W));
  string col;
  ll cnt = 0;
  rep(i, H){
    cin >> col;

    rep(j, W){
      s[i][j] = col[j];
      if(col[j] == '.') cnt++;
    }
  }

  vvl dist(H, vl(W, 10000));
  vvl vis(H, vl(W, 0));
  dist[0][0] = 1;

  priority_queue<vl, vvl, greater<vl>> que;
  que.push({dist[0][0], 0, 0});

  while(!que.empty()){
    vl top = que.top();
    ll ii = top[1];
    ll jj = top[2];
    que.pop();
    if(vis[ii][jj] == 1) continue;
    vis[ii][jj] = 1;

    if((ii > 0) && (vis[ii - 1][jj] == 0) && (s[ii - 1][jj] == '.')){
      dist[ii - 1][jj] = min(dist[ii - 1][jj], dist[ii][jj] + 1);
      que.push({dist[ii - 1][jj], ii - 1, jj});
    }
    if((ii < H - 1) && (vis[ii + 1][jj] == 0) && (s[ii + 1][jj] == '.')){
      dist[ii + 1][jj] = min(dist[ii + 1][jj], dist[ii][jj] + 1);
      que.push({dist[ii + 1][jj], ii + 1, jj});
    }
    if((jj > 0) && (vis[ii][jj - 1] == 0) && (s[ii][jj - 1] == '.')){
      dist[ii][jj - 1] = min(dist[ii][jj - 1], dist[ii][jj] + 1);
      que.push({dist[ii][jj - 1], ii, jj - 1});
    }
    if((jj < W - 1) && (vis[ii][jj + 1] == 0) && (s[ii][jj + 1] == '.')){
      dist[ii][jj + 1] = min(dist[ii][jj + 1], dist[ii][jj] + 1);
      que.push({dist[ii][jj + 1], ii, jj + 1});
    }
  }

  if(dist[H - 1][W - 1] == 10000)
    cout << -1 << endl;
  else
    cout << cnt - dist[H - 1][W - 1] << endl;
  
  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main implements Runnable {

    private static Scanner sc = new Scanner(System.in);

    public static void main(String[] args) {
        new Thread(null, new Main(), "", 128 * 1024 * 1024).start();
    }

    static int[][] cumSum;

    public void run() {
        int n = sc.nextInt(), k = sc.nextInt(), k2 = k * 2;
        int[][] w = new int[k2][k2];
        for (int i = 0; i < n; i++) {
            int x = sc.nextInt(), y = sc.nextInt();
            if (sc.next().charAt(0) == 'B') {
                y += k;
            }
            w[y % k2][x % k2]++;
        }

        cumSum = new int[k2 + 1][k2 + 1];
        for (int i = 1; i <= k2; i++) {
            for (int j = 1; j <= k2; j++) {
                cumSum[i][j] = cumSum[i - 1][j] + cumSum[i][j - 1] - cumSum[i - 1][j - 1] + w[i - 1][j - 1];
            }
        }

        int max = 0;
        for (int i = 0; i < k2; i++) {
            for (int j = 0; j < k2; j++) {
                int y0 = k2, x0 = k2;
                int y1 = Math.min(i + k, k2), x1 = Math.min(j + k, k2);
                int y2 = i, x2 = j;
                int y3 = Math.max(i - k, 0), x3 = Math.max(j - k, 0);
                int y4 = 0, x4 = 0;

                int sum = sum(y1, y0, x1, x0)
                          + sum(y1, y0, x3, x2)
                          + sum(y2, y1, x2, x1)
                          + sum(y2, y1, x4, x3)
                          + sum(y3, y2, x3, x2)
                          + sum(y3, y2, x1, x0)
                          + sum(y4, y3, x4, x3)
                          + sum(y4, y3, x2, x1);
                max = Math.max(sum, max);
            }
        }
        System.out.println(max);
    }

    private int sum(int ya, int yb, int xa, int xb) {
        return cumSum[ya][xa] + cumSum[yb][xb] - cumSum[yb][xa] - cumSum[ya][xb];
    }
}


Measured memory_bytes: 109812
#include <iostream>
#include <string>
#include <utility>
#include <functional>
#include <algorithm>
#include <vector>
#include <queue>

const int INF = 1e9 + 10;

using namespace std;

struct Point {
  int y, x, cost;
  bool f;
  Point() = default;
  Point(int y, int x, int c, bool f): y(y), x(x), cost(c), f(f) { }
};

int main() {
  while (true) {
    int n, m;
    cin >> n >> m;
    if (n + m == 0) {
      break;
    }

    vector<string> c(m);
    for (int i = 0; i < m; i++) {
      cin >> c[i];
    }

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

    for (int i = 0; i < m; i++) {
      for (int j = 0; j < n; j++) {
        if (c[i][j] == '&') {
          s.y = i;
          s.x = j;
          s.cost = 0;
        }
      }
    }

    queue<Point> que;
    que.push(s);

    int ans = INF;

    vector<vector<int>> checked(m);
    for (int i = 0; i < m; i++) {
      checked[i] = vector<int>(n, INF);
    }

    while (!que.empty()) {
      if (ans == 0) {
        break;
      }
      Point p = que.front(); que.pop();
      if (checked[p.y][p.x] <= p.cost) {
        continue;
      }
      checked[p.y][p.x] = p.cost;
      for (int i = 0; i < 4; i++) {
        int ny = p.y + dy[i];
        int nx = p.x + dx[i];
        if (ny < 0 || ny >= m) {
          ans = min(ans, p.cost);
          continue;
        }
        if (nx < 0 || nx >= n) {
          ans = min(ans, p.cost);
          continue;
        }
        int cost = 0;
        bool f = false;
        if (!p.f) {
          if (c[ny][nx] == '#') {
            f = true;
            cost = 1;
          } else {
            f = false;
          }
        }
        

        que.push(Point(ny, nx, p.cost + cost, f));
      }
    }

    cout << ans << endl;


  }

  return 0;
}

Measured memory_bytes: 3260
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <string>
#include <sstream>
#include <set>
#include <map>
#include <iostream>
#include <utility>
#include <cctype>
#include <queue>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <unordered_set>
#include <unordered_map>
#include <limits.h>
#include <cstring>
#include <tuple>
#include <cassert>
#include <numeric>
using namespace std;
// type alias
typedef long long LL;
typedef vector < int > VI;
typedef unordered_map < int, int > MAPII;
typedef unordered_set < int > SETI;
typedef pair< int , int > II;
typedef tuple< int, int, int > III;
// repetition
#define FORE(i,a,b) for(int i=(a);i<=(b);++i)
#define REPE(i,n)  for(int i=0;i<=(n);++i)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  for(int i=0;i<(n);++i)
#define FORR(x,arr) for(auto& x:arr)
#define SZ(a) int((a).size())
// DP
#define MINUS(dp) memset(dp, -1, sizeof(dp))
#define ZERO(dp) memset(dp, 0, sizeof(dp))
// minmax
#define SMAX(a,b) a = max(a,b)
#define SMIN(a,b) a = min(a,b)
// debug cerr
#define TRACE true
#define dump(x) if(TRACE) { cerr << #x << " = " << (x) << endl; }
#define dump2(x,y) if(TRACE) { cerr << #x << " = " << (x) << ", " << #y << " = " << (y) << endl; }
#define dump3(x,y,z) if(TRACE) { cerr << #x << " = " << (x) << ", " << #y << " = " << (y) << ", " << #z << " = " << (z) << endl; }
#define dump4(x,y,z,a) if(TRACE) { cerr << #x << " = " << (x) << ", " << #y << " = " << (y) << ", " << #z << " = " << (z) << ", " << #a << " = " << (a) << endl; }
#define dumpAR(ar) if(TRACE) { FORR(x,(ar)) { cerr << x << ','; } cerr << endl; }

// $ g++ -std=c++14 -Wall -O2 -D_GLIBCXX_DEBUG x.cpp && ./a.out
// 15:20-
const string yes="Yes",no="No";
const int MAX_N=1e5+1;
int N;
LL A[MAX_N];
void solve() {
  int cnt[3]={};
  REP(i,N) cnt[A[i]]++;
  string res=yes;
  dump3(cnt[0],cnt[1],cnt[2]);
  if(cnt[1]==0&&cnt[0]==cnt[2]+1) res=yes;
  else res=(cnt[0]>cnt[2])?no:yes;
  cout<<res<<endl;
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  
  cin>>N;
  REP(i,N) {
    cin>>A[i];
    int x=0;
    while(A[i]%2==0) A[i]/=2,++x;
    A[i]=min(x,2);
  }
  solve();
  return 0;
}


Measured memory_bytes: 1024
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<queue>
#include<cmath>
#include<cstdio>
#include<tuple>
#include<bitset>
#include<map>

using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
#define ALL(x) x.begin(),x.end()
using P=pair<int,int>;
using lint=long long;
using ll=long long;
const lint inf=1e18+7;
const int MOD=1000000007;
class Seg_Tree{
    private:
    int e=1000000007;
    int n;
    vector<int> node;
    public:
    int process(int left,int right){
        if(left==e)return right;
        if(right==e)return left;
        return left+right;
    }
    Seg_Tree(vector<int> v){
        int num=1;
        int size=v.size();
        while(num<size){
            num*=2;
        }
        n=num;
        node.resize(2*num-1,e);
        for(int i=0;i<size;i++)node[i+num-1]=v[i];
        for(int i=n-2;i>=0;i--)node[i]=process(node[i*2+1],node[i*2+2]);
    }
    void add(int x,int val){
        x+=(n-1);
        node[x]+=val;
        while(x>0){
            x=(x-1)/2;
            node[x]=process(node[x*2+1],node[x*2+2]);
        }
    }
    int out(int a,int b,int k=0,int l=0,int r=-1){
        if(r<0)r=n;
        if(a>=r||b<=l)return e;
        if(a<=l&&b>=r)return node[k];
        int vl=out(a,b,k*2+1,l,(l+r)/2);
        int vr=out(a,b,k*2+2,(l+r)/2,r);
        return process(vl,vr);
    }
};
signed main(){
  int n,q;cin>>n>>q;
  vector<int> c(n+1,0);
  rep1(i,n)cin>>c[i];
  vector<pair<int,int>> query(q);
  rep(i,q)cin>>query[i].second>>query[i].first;
  vector<pair<int,int>> copy(query);
  sort(copy.begin(),copy.end());
  Seg_Tree tree(vector<int> (n+5,0));
  vector<int> la(n+5,0);
  vector<int> res(q);
  int R=0;
  rep(i,q){
    if(copy[i].first>R){
      for(int j=R+1;j<=copy[i].first;++j){
        tree.add(la[c[j]],-1);
        la[c[j]]=j;
        tree.add(la[c[j]],1);
      }
      R=copy[i].first;
    }
    res[i]=tree.out(copy[i].second,copy[i].first+1);
  }
  rep(i,q){
    auto it=lower_bound(ALL(copy),query[i]);
    int ind=it-copy.begin();
    cout<<res[ind]<<"\n";
  }
  return 0;
}


Measured memory_bytes: 39356
N,M=map(int,input().split())
A=[list(map(int,input().split())) for i in range(M)]
D=[[]for i in range(N)]
for a,b in A:
  D[a-1].append(b)
if D==[[0]]:
  print(0)
  exit()
if D==[0]*N:
  print(-1)
  exit()
if 0 in D[0]:
  print(-1)
  exit()
for i in range(N):
  if D[i]==[]:
    D[i].append(0)
  D[i]=list(set(D[i]))
  if len(D[i])>1:
    print(-1)
    exit()
C=[]
for i in range(N):
  C.append(D[i][0])

if C[0]==0 and N>1:
  C[0]=1
print(*C,sep='')


Measured memory_bytes: 3064
n,k = map(int,input().split())
s = input()

from_start = 0
RtoL = 0
LtoR = 0
for i in range(n-1):
    if s[i] == s[i+1]:
        from_start += 1
    elif s[i] == 'R' and s[i+1] == 'L':
        RtoL += 1
    elif s[i] == 'L' and s[i+1] == 'R':
        LtoR += 1
add = 0
while (RtoL or LtoR) and k:
    k-=1
    if RtoL and LtoR:
        add += 2
        RtoL -= 1
        LtoR -= 1
    elif RtoL:
        add += 1
        RtoL -= 1
    elif LtoR:
        add += 1
        LtoR -= 1
print(from_start+add)

Measured memory_bytes: 9340