akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define pb push_back
#define S second
#define F first

using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
int vis[8];
int main(){

    int n;
    cin >> n;
    int a;
    int more = 0;
    for (int i = 0;i < n;i++){
        cin >> a;
        if (a >= 3200) more++;
        else if (a >= 2800) vis[7]++;
        else if (a>= 2400) vis[6]++;
        else if (a >= 2000) vis[5]++;
        else if (a >= 1600) vis[4]++;
        else if (a >= 1200) vis[3]++;
        else if (a >= 800) vis[2]++;
        else if (a >= 400) vis[1]++;
        else if (a >= 1) vis[0]++;
    }
    int found = 0;
    for (int i = 0;i < 8;i++){
        if (vis[i]) found++;
    }
    if (found == 0) cout << 1 << ' ';
    else cout << found << ' ';
    cout << found + more << endl;
    return 0;
}


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

// varibable settings
#define int long long
const int INF=1e18;

// define basic macro {{{
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define _rrep(i,n) rrepi(i,0,n)
#define rrepi(i,a,b) for(int i=(int)((b)-1);i>=(int)(a);--i)
#define rrep(...) _overload3(__VA_ARGS__,rrepi,_rrep,)(__VA_ARGS__)
#define each(i,a) for (auto&& i : a)
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define pb(a) push_back(a)
#define mp(a, b) make_pair(a, b)
#define mt(a, b, c) make_tuple(a, b, c)
#define divceil(a,b) ((a)+(b)-1)/(b)
#define is_in(x, a, b) ((a)<=(x) && (x)<(b))
#define uni(x) sort(all(x));x.erase(unique(all(x)),x.end())
#define ub upper_bound
#define lb lower_bound
#define posl(A, x) (lower_bound(all(A), x)-A.begin())
#define posu(A, x) (upper_bound(all(A),x)-A.begin())
template<class T> inline void chmax(T &a, const T &b) { if((a) < (b)) (a) = (b); }
template<class T> inline void chmin(T &a, const T &b) { if((a) > (b)) (a) = (b); }

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef long double ld;
typedef pair<int,int> pii;
typedef tuple<int,int,int> iii;

template<typename T> using PQ = priority_queue<T, vector<T>, greater<T>>;
struct Fast { Fast(){ std::cin.tie(0); ios::sync_with_stdio(false); } } fast;

#if defined(PCM) || defined(LOCAL)
  #include "lib/dump.hpp"
#else
  #define dump(...) 42
  #define dump_1d(...) 42
  #define dump_2d(...) 42
  #define cerrendl 42
#endif
//}}}

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

  map<pair<int, string>, int> d;
  {
    rep(mask, 1<<n){
      int cnt = 0;
      string t = "";
      string u = "";
      rep(i, n){
        if (mask&(1<<i)){
          u += s[i];
        }
        else{
          cnt++;
          t += s[i];
        }
      }
      reverse(all(u));
      t += u;
      // dump(t);
      d[mp(cnt, t)]++;
    }
  }
  // dump(d);

  reverse(all(s));
  map<pair<int, string>, int> d2;
  {
    rep(mask, 1<<n){
      int cnt = 0;
      string t = "";
      string u = "";
      rep(i, n){
        if (mask&(1<<i)){
          cnt++;
          t += s[i];
        }
        else{
          u += s[i];
        }
      }
      reverse(all(u));
      t += u;
      // dump(t);
      d2[mp(cnt, t)]++;
    }
  }
  // dump(d2);

  int ans = 0;
  each(el, d){
    auto key = el.first;
    int c = el.second;
    ans += c * d2[key];
  }
  cout << ans << endl;

  return 0;
}


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

using namespace std;

struct UnionFind {
  //自身が親であれば、その集合に属する頂点数に-1を掛けたもの
  //そうでなければ親のid
  vector<int> r;

  UnionFind(int N) { r = vector<int>(N, -1); }

  int root(int x) {
    if (r[x] < 0) return x;
    return r[x] = root(r[x]);
  }
  bool unite(int x, int y) {
    x = root(x);
    y = root(y);
    if (x == y) return false;
    if (r[x] > r[y]) swap(x, y);
    r[x] += r[y];
    r[y] = x;
    return true;
  }

  int size(int x) { return -r[root(x)]; }
};

int main() {
  int N, M;
  cin >> N >> M;
  UnionFind UF(N);
  for (int i = 0; i < M; i++) {
    int A, B;
    cin >> A >> B;
    A -= 1;
    B -= 1;
    UF.unite(A, B);
  }
  int ans = 0;
  for (int i = 0; i < N; i++) {
    ans = max(ans, UF.size(i));
  }
  cout << ans << endl;
}

Measured memory_bytes: 3988
#include<cstdio>
#include<cstdlib>
#include<string>
#include<iostream>
using namespace std;

struct Node {
  int key;
  Node *right, *left, *parent;
};

Node *root, *NIL;

Node * treeMinimum(Node *x) {
  while (x->left != NIL) x = x->left;
  return x;
}

Node * find(Node *u, int k) {
  while (u != NIL && k != u->key) {
    if (k < u->key) u = u->left;
    else u = u->right;
  }
  return u;
}

Node * treeSuccessor(Node *x) {
  if (x->right != NIL) return treeMinimum(x->right);

  Node *y = x->parent;
  while (y != NIL && x == y->right) {
    x = y;
    y = y->parent;
  }
  return y;
}

void treeDelete(Node *z) {
  Node *y;
  Node *x;

  if (z->left == NIL || z->right == NIL) y = z;
  else y = treeSuccessor(z);

  if (y->left != NIL) {
    x = y->left;
  } else {
    x = y->right;
  }

  if (x != NIL) {
    x->parent = y->parent;
  }

  if (y->parent == NIL) {
    root = x;
  } else {
    if (y == y->parent->left) {
      y->parent->left = x;
    } else {
      y->parent->right = x;
    }
  }

  if (y != z) {
    z->key = y->key;
  }

  free(y);
}

void insert(int k) {
  Node *y = NIL;
  Node *x = root;
  Node *z;

  z = (Node *)malloc(sizeof(Node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;

  while (x != NIL) {
    y = x;
    if (z->key < x->key) {
      x = x->left;
    } else {
      x = x->right;
    }
  }

  z->parent = y;
  if (y == NIL) {
    root = z;
  } else {
    if (z->key < y->key) {
      y->left = z;
    } else {
      y->right = z;
    }
  }
}

void inorder(Node *u) {
  if (u == NIL) return;
  inorder(u->left);
  printf(" %d", u->key);
  inorder(u->right);
}
void preorder(Node *u) {
  if (u == NIL) return;
  printf(" %d", u->key);
  preorder(u->left);
  preorder(u->right);
}

int main() {
  int n, i, x;
  string com;
  scanf("%d", &n);

  for (int i = 0; i < n; i ++) {
    cin >> com;
    if (com[0] == 'f') {
      scanf("%d", &x);
      Node *t = find(root, x);
      if (t != NIL) printf("yes\n");
      else printf("no\n");
    } else if (com == "insert") {
      scanf("%d", &x);
      insert(x);
    } else if (com == "print") {
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    } else if (com == "delete") {
      scanf("%d", &x);
      treeDelete(find(root, x));
    }
  }
}


Measured memory_bytes: 22036
//abc169 C
#include <bits/stdc++.h>
using namespace std;
int main() {
    long long a;
    cin >> a;
    double b;
    cin >> b;
    long long ib = b * 100 + 0.5;
    a *= ib;
    a /= 100;
    cout << a << endl;

    return 0;
}

Measured memory_bytes: 3664
import fractions
from functools import reduce


def lcm_base(x, y):
    return (x * y) // fractions.gcd(x, y)


def lcm(*numbers):
    return reduce(lcm_base, numbers, 1)  # 数列に対しての最小公倍数


n, m = map(int, input().split())
a = list(map(int, input().split()))
b = [x // 2 for x in a]
c = 0
while a[0] % (2 ** (c + 1)) == 0:
    c += 1

for x in a:
    if x % (2 ** c) != 0 or x % (2 ** (c + 1)) == 0:
        print(0)
        exit()

lc = lcm(*b)

ans = ((m // lc) + 1) // 2
print(ans)


Measured memory_bytes: 16308
#include<iostream>

using namespace std;

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

int n, m;
bool to1[200001];
bool ton[200001];

int main(){
    cin >> n >> m;
    REP(i, n+1){
        to1[i] = false;
        ton[i] = false;
    }

    REP(i, m){
        int a, b;
        cin >> a >> b;

        if(a==1){
            to1[b] = true;
        } else if(b==n){
            ton[a] = true;
        }
    }

    bool flag = false;
    REP(i, n+1){
        if(to1[i] && ton[i]){
            flag = true;
            break;
        }
    }

    if(flag){
        cout << "POSSIBLE" << endl;
    } else {
        cout << "IMPOSSIBLE" << endl;
    }
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
int main() {
  long x,z,a;
  char y;
  cin >> x >> y >> z;
  if (y == '+') {
    a = x+z;
    cout << a << endl;
  } else if (y == '-') {
    a = x-z;
    cout << a << endl;
  }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
//#include<iostream>
//#include<cstdio>
//#include<cstring>
//#include<string>
//#include<queue>
//#include<cmath>
//#include<algorithm>
#define debug1 cout<<"?"<<endl;
#define debug2 cout<<"?"<<i<<endl;
#define PII pair<ll,ll>
typedef long long ll;
const int maxn=3e5+9;
const double pi=acos(-1);
const int mod=1e9+7;
const int INF=0x3f3f3f3f;
const double ep=1e-7;
using namespace std;
pair<int,int>p[maxn];
int main()
{
	int n,d,a,i; 
	scanf("%d%d%d",&n,&d,&a);
	for(i=1;i<=n;i++)scanf("%d%d",&p[i].first,&p[i].second);
	sort(p+1,p+1+n);
	int s[maxn]={0};
	ll ans=0;
	for(i=1;i<=n;i++)
	{
		s[i]+=s[i-1];
		int num=p[i].second/a;
		if(p[i].second%a)num++;
		if(num<=s[i])continue;
		num-=s[i];ans+=num;
		int k=upper_bound(p+1,p+1+n,make_pair(p[i].first+d*2,2000000000))-p;
		s[i]+=num;
		s[k]-=num;
	}
	printf("%lld\n",ans);
}

Measured memory_bytes: 2944
//Optional FAST

//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,fma,abm,mmx,avx,avx2,tune=native")

//Required Libraries

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>

//Required namespaces

using namespace std;
using namespace __gnu_pbds;

//Required defines

#define endl '\n'

#define READ(X) cin>>X;
#define READV(X) long long X; cin>>X;
#define READAR(A,N) long long A[N]; for(long long i=0;i<N;i++) {cin>>A[i];}
#define rz(A,N) A.resize(N);
#define sz(X) (long long)(X.size())
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define trav(x,A) for(auto &x:A)
#define FORI(a,b,c) for(long long a=b;a<c;a++)
#define FORD(a,b,c) for(long long a=b;a>c;a--)

//Required typedefs

typedef tree<long long,null_type,less<long long>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
typedef tree<long long,null_type,greater<long long>,rb_tree_tag,tree_order_statistics_node_update> ordered_set1;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<long long,long long> pll;
typedef vector<int> veci;
typedef vector<long long> vecl;

//Required Constants

const long long inf=(long long)1e18;
const long long MOD=(long long)(1e9+7);
const long long INIT=(long long)(1e6+1);

//Required Functions

ll power(ll x,ll y) 
{ 
    if (y == 0) 
        return 1; 
    ll p = power(x, y/2) % MOD; 
    p = (p * p) % MOD; 
  
    return (y%2 == 0)? p : (x * p) % MOD; 
}
ll modInverse(ll a) 
{ 
   return power(a,MOD-2); 
   
}

//Work

int main()
{
    #ifndef ONLINE_JUDGE
    if (fopen("INPUT.txt", "r"))
    {
        freopen ("INPUT.txt" , "r" , stdin);
        //freopen ("OUTPUT.txt" , "w" , stdout);
    }
    #endif
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    clock_t clk;
    clk = clock();
//-----------------------------------------------------------------------------------------------------------//

    READV(N);
    READV(M);
    FORI(i,0,M)
    {
        READV(x);
        N-=x;
    }
    if(N<0)
    {
        cout<<-1<<endl;
    }
    else
    {
        cout<<N<<endl;
    }
    

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


    clk = clock() - clk;
    cerr << fixed << setprecision(6) << "Time: " << ((double)clk)/CLOCKS_PER_SEC << endl;

    return 0;
}

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

typedef long long ll;
const int maxn=200010;
int n;
int a[maxn];

map<ll,int> mp;

int main(){

	scanf("%d", &n);
	for(int i=1;i<=n;i++) scanf("%d", &a[i]);
	mp[0]=1;
	ll cur=0, ans=0;
	for(int i=1;i<=n;i++){
		cur+=a[i];
		ans+=mp[cur];
		mp[cur]++;
	}
	printf("%lld\n", ans);
	return 0;
}


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

#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x).size()

typedef long long ll;
typedef array<int, 3> tri;
typedef long double ld;

template <class T> istream& operator>>(istream& I, vector<T>& v) {for (T &e: v) I >> e; return I;}
template <class T> ostream& operator<<(ostream &O, const vector<T>& v) {for (const T &e: v) O << e << ' '; return O;}




void _main() {
        int n, k; cin >> n >> k;
        vector<ll> a(n); cin >> a;
        ll ans = LLONG_MAX;
        for (int i = 0; i < n; i++) {
                if (i - k + 1 >= 0) ans = min(ans, abs(a[i]) + abs(a[i] - a[i - k + 1]));
                if (i + k - 1 < n) ans = min(ans, abs(a[i]) + abs(a[i] - a[i + k - 1]));
        }
        cout << ans;
}




signed main() {
        ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
//        freopen("input.txt", "r", stdin);
        int _t = 1;
//        cin >> _t;
        while (_t--) _main();
        return 0;
}


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

#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <unordered_map>
#include <queue>
#include <algorithm>

#include <bits/stdc++.h>
#include <cmath>
#include <limits>

using namespace std;
typedef long long LL;
using Graph = vector<vector<int>>;

static long long INF = (1LL<<62);

void delMapKey(map<long long, int> &m, long long k){
	if(m.count(k) == 0){
		return;
	}
	m[k]--;
	if(m[k] == 0){
		m.erase(m.find(k));
	}
}

void addMapKey(map<long long, int> &m, long long k){
	if(m.count(k) == 0){
		m[k] = 1;
	}
	else{
		m[k]++;
	}
}

long long getHeadKey(map<long long, int> &m){
	if(m.size() == 0){
		return INF;
	}
	long long ret = m.begin()->first;
	return ret;
}

long long getLastKey(map<long long, int> &m){
	if(m.size() == 0){
		return INF;
	}
	long long ret = m.crbegin()->first;
	return ret;
}

LL N, M;
map<LL, int> A;

int main(int argc, char* argv[]){
	cin.tie(0);
	ios::sync_with_stdio(false);

	cin >> N >> M;
	for(int i=0; i<N; i++){
		LL a;
		cin >> a;
		addMapKey(A, a);
	}

	for(int i=0; i<M; i++){
		LL a = getLastKey(A);
		delMapKey(A, a);
		a = a / 2;
		addMapKey(A, a);
	}
	long long ans = 0;
	for(auto itr = A.begin(); itr != A.end(); itr++){
		long long a = itr->first;
		int v = itr->second;
		ans += (a * v);
	}
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 9940
h,w,d,*l=map(int,open(0).read().split())
s=h*w
x=[0]*(s+1)
y=[0]*(s+1)
for i,a in enumerate(l[:s]):
	x[a]=i//w
	y[a]=i%w
ref=[0]*(s+1)
for i in range(d+1,s+1):
	ref[i]=ref[i-d]+abs(x[i]-x[i-d])+abs(y[i]-y[i-d])
for l,r in zip(l[s+1::2],l[s+2::2]):
	print(ref[r]-ref[l])

Measured memory_bytes: 34396
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String SI = sc.next();
		String T = sc.next();
		for (int i=SI.length()-T.length();i>=0;i--) {
			if (Main.compare(SI.substring(i,i+T.length()), T)==true) {
				StringBuffer sb = new StringBuffer();
				for (int j=0;j<i;j++) {
					if (SI.charAt(j)=='?') {
						sb.append('a');
					} else {
						sb.append(SI.charAt(j));
					}
				}
				sb.append(T);
				for (int j=i+T.length();j<SI.length();j++) {
					if (SI.charAt(j)=='?') {
						sb.append('a');
					} else {
						sb.append(SI.charAt(j));
					}
				}
				System.out.println(sb.toString());
				return ;
			}
		}
		System.out.println("UNRESTORABLE");
	}

	public static boolean compare (String S,String T) {
		for (int i=0;i<S.length();i++) {
			if (S.charAt(i)!='?'&&S.charAt(i)!=T.charAt(i)) {
				return false;
			}
		}
		return true;
	}
}

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

using namespace std;

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	
	int n;
	cin >> n;
	
	long long res=0;
	vector<vector<long long>> ta(10,vector<long long>(10));
	
	for(int i=1;i<=n;i++){
		int c=i;
		while(c>=10) c/=10;
		int fr=c,ba=i%10;
		if(fr==0 || ba==0) continue;
		
		ta[fr][ba]++;
	}
	for(int i=1;i<10;i++){
		for(int j=1;j<10;j++){
			if(i==j){
				res+=ta[i][j]*ta[j][i];
			}else{
				res+=ta[i][j]*ta[j][i];
			}
		}
	}
	cout << res << "\n";
	return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize ("O3")
#pragma GCC target ("avx")

#include <bits/stdc++.h>
#include <unistd.h>

using i64 = std::int64_t;

namespace io {
  using i64 = std::int64_t;
  constexpr int is = 1 << 17;
  char ib[is], *ip = ib + is, it;
  inline char getc() {
    if (ip == ib + is) { read(STDIN_FILENO, ib, is); ip = ib; }
    return *ip++;
  }
  inline i64 scan() {
    i64 r = 0;
    if (ip + 16 > ib + is) while ((it = getc()) & 16) r = r * 10 + it - '0';
    else while ((it = *ip++) & 16) r = r * 10 + it - '0';
    return r;
  }
  constexpr int os = 1 << 17;
  char ob[os], *op = ob, ot;
  inline void putc(const char c) {
    *op++ = c;
    if (op == ob + os) { write(STDOUT_FILENO, ob, os); op = ob; }
  }
  /* x shoud be greater than or equal to zero */
  inline void print(i64 x) {
    char d[20];
    int i = 0;
    while (true) {
      d[i] = x % 10 + 48;
      x /= 10;
      ++i;
      if (x <= 0) break;
    }
    while (i--) {
      putc(d[i]);
    }
  }
  inline void flush() {
    write(STDOUT_FILENO, ob, op - ob);
  }
}

signed main() {
  using namespace io;
  i64 h = scan();
  i64 n = scan();
  i64 s = 0;
  for (int i = 0; i < n; i++) {
    s += scan();
  }
  if (s >= h) {
    puts("Yes");
  } else {
    puts("No");
  }
  return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define rep1(i,n) for(int i=1;i<=(int)n;i++)
#define rep2(i,j,n) for(int j=i;j<n;j++)
#define rep3(i,j,n) for(int j=i;j<=n;j++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define sp(n) cout << fixed << setprecision(n)
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; }
typedef long long ll;
using namespace std;

int main(void){
    int n,g,s;cin>>n>>s>>g;s--;g--;
    vector<vector<int>> t(n);
    rep(i,n-1){
        int a,b;cin>>a>>b;a--;b--;
        t[a].push_back(b);
        t[b].push_back(a);
    }
    vector<int> u(n,-1),v(n,-1);
    queue<int> que;
    que.push(s);
    u[s]=0;
    while(que.size()){
        int x=que.front();que.pop();
        rep(i,t[x].size()){
            int y=t[x][i];
            if(u[y]!=-1)continue;
            u[y]=u[x]+1;
            que.push(y);
        }
    }
    que.push(g);
    v[g]=0;
    while(que.size()){
        int x=que.front();que.pop();
        rep(i,t[x].size()){
            int y=t[x][i];
            if(v[y]!=-1)continue;
            v[y]=v[x]+1;
            que.push(y);
        }
    }
    int res=0;
    rep(i,n){
        if(u[i]<v[i]) chmax(res,v[i]-1);
    }
    cout<<res<<endl;
}

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


#define REP(i,n) for (int i = 0; (i) < (n); ++ (i))
#define FOR(i,n) for (int i = 1; (i) <= (n); ++ (i))
#define dump(x)  cout << #x << " = " << (x) << endl;
#define pb push_back
#define lint long long

const int INF = 1e9;
const int MOD = 1e9+7;
const lint LINF = 1e18;
const double eps = 0.000000001;//もとの値の10^(-16)まで


using namespace std;
int n;
map<int,int> mp0;
map<int,int> mp1;
int m1,m2;
int m1m,m2m;
int n1,n2;
int n1n,n2n;

int main(){
  cin >> n;
  REP(i,n){
    int k;
    cin >> k;
    if(i%2==0) mp0[k] ++;
    else mp1[k] ++;
  }
  for(map<int,int>::iterator it = mp0.begin(),end= mp0.end();it!=end;++it){
    if(m1m< it->second){
      m2 = m1;
      m1 = it->first;
      m2m = m1m;
      m1m = it->second;
    }
    else if(m2m< it->second){
      m2 = it->first;
      m2m = it->second;
    }
  }
  for(map<int,int>::iterator it = mp1.begin(),end= mp1.end();it!=end;++it){
    if(n1n< it->second){
      n2 = n1;
      n1 = it->first;
      n2n = n1n;
      n1n = it->second;
    }
    else if(n2n< it->second){
      n2 = it->first;
      n2n = it->second;
    }
  }
  if(m1!=n1) cout << (n-m1m-n1n) << endl;
  else cout << min(n-m1m-n2n,n-m2m-n1n) << endl;
  return 0;
}


Measured memory_bytes: 4992
#include<bits/stdc++.h>
#define rgi register int
#define ll long long
const int maxn=6666;
std::string a,b,c; 
bool ab[maxn<<1],ac[maxn<<1],bc[maxn<<1];
int ans=maxn<<2;
inline bool cmp(char c1,char c2) {return c1==c2||c1=='?'||c2=='?';}
signed main()
{
	std::cin>>a>>b>>c; int lena=a.length(),lenb=b.length(),lenc=c.length();
	for(rgi i=0;i<lena;++i) for(rgi j=0;j<lenb;++j) if(!cmp(a[i],b[j])) ab[i-j+maxn]=1;
	for(rgi i=0;i<lena;++i) for(rgi j=0;j<lenc;++j) if(!cmp(a[i],c[j])) ac[i-j+maxn]=1;
	for(rgi i=0;i<lenb;++i) for(rgi j=0;j<lenc;++j) if(!cmp(b[i],c[j])) bc[i-j+maxn]=1;
	for(rgi i=-4001;i<=4001;++i) for(rgi j=-4001;j<=4001;++j)
		if(!ab[i+maxn]&&!ac[j+maxn]&&!bc[j-i+maxn])
			ans=std::min(ans,std::max(lena,std::max(i+lenb,j+lenc))-std::min(0,std::min(i,j)));
	std::cout<<ans;
	return 0;
}
// ----------------------------
// by imzzy

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <cmath>
#include <map>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep2(i,a,n) for(int i=a;i<n;i++)
#define been(ix) (ix).begin(),(ix).end()
using namespace std;
typedef long long ll; 
typedef vector<int> vi;
typedef vector<long long> vl;
const ll INFL = 1e18;
const int INF = 1001001001; 
typedef pair<int,int> P;
#define foreach(ix,i) for(auto& (ix) : (i))
typedef long double ld;
const int mod =1000000007;
int main(){
    int h,w;
    cin>>h>>w;
    int a[h][w];
    int ans[300000][4];
    int cnt =0;
    rep(i,h)rep(j,w)cin>>a[i][j];
    rep(i,h)rep(j,w-1){
        if(a[i][j]%2!=0){
            a[i][j+1]++;
            ans[cnt][0]=i+1;
            ans[cnt][1]=j+1;
            ans[cnt][2]=i+1;
            ans[cnt][3]=j+2;
            cnt++;
        }
    }
    rep(i,h-1){
        if(a[i][w-1]%2!=0){
            a[i+1][w-1]++;
            ans[cnt][0]=i+1;
            ans[cnt][1]=w;
            ans[cnt][2]=i+2;
            ans[cnt][3]=w;
            cnt++;
        }
    }
    cout<<cnt<<endl;
    rep(i,cnt){
        rep(j,4){
            if(j!=3)cout<<ans[i][j]<<" ";
            else
            {
                cout<<ans[i][j];
            }
            
        }
        cout<<endl;
    }
    
    
}


Measured memory_bytes: 6912
#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++)
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;

const char wall = '#';
vector<vector<char>> fields;
vector<vector<bool>> used;
vector<vector<ll>> dist;
const int dx[4] = {0, -1, 0, 1};
const int dy[4] = {1, 0, -1, 0};

ll N;
vector<ll> A;

ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return b/gcd(a,b)*b;}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  // Globalなvectorのリサイズ
  //A.resize(N);

  ll a, b;
  cin >> a >> b;
  
  rep1(i, 1300) {
    if (floor(0.08*i) == a && floor(0.1*i) == b) {
      cout << i << endl;
      return 0;
    }
  }
  cout << -1 << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <string>
#include <algorithm>
using namespace std; //std::の省略のため
using ll = long long;

int main()
{
  int w, h, n;
  cin >> w >> h >> n;

  int x[n], y[n], a[n];

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

  int s[w][h];

  for(int j = 0; j < w; j++){
      for(int k = 0; k < h; k++)
        s[j][k] = 0;
  }

  for(int i = 0; i < n; i++){
    if(a[i] == 1){
      for(int j = 0; j < x[i]; j++){
        for(int k = 0; k < h; k++)
          s[j][k] = 1;
      }
    }
    else if(a[i] == 2){
      for(int j = x[i]; j < w; j++){
        for(int k = 0; k < h; k++)
          s[j][k] = 1;
      }
    }
    else if(a[i] == 3){
      for(int j = 0; j < w; j++){
        for(int k = 0; k < y[i]; k++)
          s[j][k] = 1;
      }
    }
    else if(a[i] == 4){
      for(int j = 0; j < w; j++){
        for(int k = y[i]; k < h; k++)
          s[j][k] = 1;
      }
    }
  }

  ll ans = 0;

  for(int j = 0; j < w; j++){
      for(int k = 0; k < h; k++)
        if(s[j][k] == 0) ans++;
  }

  cout << ans << endl;

}


Measured memory_bytes: 3628
#include <cassert>
#include <iostream>
#include <functional>
#include <iomanip>
#include <set>
#include <unordered_map>
#include <queue>
#include <vector>
#include <deque>
#include <algorithm>
#include  <cstring>
#include <string>
#include <cmath> 
using namespace std;
typedef long long LL;
const int MAX = 210000;
const LL base = 1e9 + 7;


struct Node {
	int x, y, w;
};

int za[200];
bool dp[MAX];
void solve() {

	LL result = 0;
	int n,k;

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

	for (int i = 1; i<= k; ++i) {
		for (int j = 0; j < n; ++j) {
			if (i >= za[j] && dp[i - za[j]] == false) {
				dp[i] = true;
				break;
			}
		}
	}

	if (dp[k]) {
		cout << "First" << endl;
	}
	else {
		cout << "Second" << endl;
	}


}

int main() {
	const int inId = 0;
	const int outId = 0;
	if (inId>0) {
		cerr << "redirect stdin to input " << inId << endl;
		string s = "input";
		s += to_string(inId);
		s += ".txt";
		auto r = freopen(s.c_str(), "r", stdin);	
		if (r == nullptr) {
			cerr<< "invalid input file "<< s;
		}
	}
	if (outId>0) {
		cerr << "redirect stdout to stdout " << outId << endl;
		string s = "stdout";
		s += to_string(outId);
		s += ".txt";
		auto r = freopen(s.c_str(), "w", stdout);
		if (r == nullptr) {
			cerr<< "invalid output file "<< s;
		}		
	}
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); // close sync between cout and printf
	cout.precision(10);
	solve();
}
 

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define repone(i,n) for(int i=1;i<(int)(n);++i)
#define repo(i,o,n) for(int i=o;i<(int)(n);++i)
#define Rep(j,n) for(int j=0;j<(int)(n);++j)
#define Repo(j,o,n) for(int j=o;j<(int)(n);++j)
#define Repone(j,n) for(int j=1;j<(int)(n);++j)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define int long long
#define pb(a) push_back(a)
#define eraser(v,i) (v).erase(v.begin()+(i))
#define pbpair(a,b) push_back(make_pair(a,b))
#define MOD 1000000007
#define INF 9223372036854775807
#define pairint pair<int,int>
int gcd(int x, int y) { return (x % y)? gcd(y, x % y): y; }
int lcm(int x, int y) { return x / gcd(x, y) * y; }
signed main(){
  int x=0,y=1,z=1,w=0,n=0,m=0;
  string s;
  std::cin >> x;
  while(x){
    if(y*2>x){
      std::cout << z << '\n';
      return 0;
    }else {
      y*=2;
      z+=y;
    }
  }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define VIEW(x) do {cerr << #x << ": "; for(auto i : x) cerr << i << " "; cerr << endl;} while(0)

signed main() {
  string s; cin >> s;
  if(s[0] == 'R' && s[1] == 'R' && s[2] == 'R') puts("3");
  else if(s[0] == 'R' && s[1] == 'R' && s[2] == 'S') puts("2");
  else if(s[0] == 'S' && s[1] == 'R' && s[2] == 'R') puts("2");
  else if(s[0] == 'S' && s[1] == 'S' && s[2] == 'R') puts("1");
  else if(s[0] == 'S' && s[1] == 'R' && s[2] == 'S') puts("1");
  else if(s[0] == 'R' && s[1] == 'S' && s[2] == 'S') puts("1");
  else if(s[0] == 'R' && s[1] == 'S' && s[2] == 'R') puts("1");
  else puts("0");
}


Measured memory_bytes: 3592
#include<iostream>
#include<algorithm>

using namespace std;

#define fr(i,a,b) for(int i=a;i<b;++i)
typedef long long ll;
/////////////////////////

int const N = 141;

ll a[N];
int n;

void solve(){
	cin >> n;
	fr(i, 0, n) cin >> a[i];

	ll ans = 0;
	bool f = true;
	while(f){
		f = false;
		int maxii = 0;
		fr(i, 0, n) if(a[i] > a[maxii]){
			maxii = i;
		}
		ll add = a[maxii] / n;
		ans += add;
		a[maxii] %= n;
		fr(i, 0, n){
			if(i != maxii) a[i] += add;
		}
		if(add > 0) f = true;
	}
	cout << ans << endl;
}

int main(){
#ifdef _DEBUG
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
#endif

	solve();


	return 0;
}

Measured memory_bytes: 256
# coding: utf-8
# Here your code

N = int(input())
a = [int(i) for i in input().split()] 

result_1 = 0
before_sum = a[0]

if a[0] <= 0:
    before_sum = 1
    result_1 += 1 + abs(a[0])

after_sum = before_sum

for i in range(1,N):
    before_sum = after_sum
    after_sum = before_sum + a[i]
    if i % 2 == 0:
        if after_sum <= 0:
            result_1 += 1 + abs(after_sum)
            after_sum = 1
    else:
        if after_sum >= 0:
            result_1 += 1 + abs(after_sum)
            after_sum = -1

result_2 = 0
before_sum = a[0]

if a[0] >= 0:
    before_sum = -1
    result_2 += 1 + abs(a[0])

after_sum = before_sum

for i in range(1,N):
    before_sum = after_sum
    after_sum = before_sum + a[i]
    if i % 2 == 1:
        if after_sum <= 0:
            result_2 += 1 + abs(after_sum)
            after_sum = 1
    else:
        if after_sum >= 0:
            result_2 += 1 + abs(after_sum)
            after_sum = -1

print(min(result_1,result_2))


Measured memory_bytes: 14332
#include <iostream>
#include <stdio.h>
using namespace std;

bool search(int S[], int n, int key) {
	int i = 0;
	S[n] = key;

	while (S[i] != key) i++;

	return i != n;
}

int main() {
	int n, q, S[10000+1], Q[500], count = 0;

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

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

	for (int i = 0; i < q; i++) {
		if (search(S, n, Q[i])) count++;
	}

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

	return 0;
}

Measured memory_bytes: 3240
#include<bits/stdc++.h>
#include<string.h>
 
typedef long long int ll;
#define all(x) (x).begin(), (x).end()
 
using namespace std;

int nxt() {
    int x;
    cin >> x;
    return x;
}

ll nxtl(){
    ll x;
    cin>>x;
    return x;
}
 
void SieveOfEratosthenes(int n,vector <int> &primes) 
{ 
    // Create a boolean array "prime[0..n]" and initialize 
    // all entries it as true. A value in prime[i] will 
    // finally be false if i is Not a prime, else true. 
    bool prime[n+1]; 
    memset(prime, true, sizeof(prime)); 
  
    for (int p=2; p*p<=n; p++) 
    { 
        // If prime[p] is not changed, then it is a prime 
        if (prime[p] == true) 
        { 
            // Update all multiples of p greater than or  
            // equal to the square of it 
            // numbers which are multiple of p and are 
            // less than p^2 are already been marked.  
            for (int i=p*p; i<=n; i += p) 
                prime[i] = false; 
        } 
    } 
  
    // Print all prime numbers 
    for (int p=2; p<=n; p++) 
       if (prime[p]) 
          primes.push_back(p);
} 
 
ll max(ll a,ll b)
{
    if(a>b)
        return a;
    return b;
}
 
ll power(ll x, ll y,ll mod) 
{ 
    ll temp; 
    if( y == 0) 
        return 1; 
    temp = power(x, y/2,mod); 
    if (y%2 == 0) 
        return (temp*temp)%mod; 
    else
        return (((x*temp)%mod)*temp)%mod; 
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int k=nxt(),x=nxt(),y=nxt();
    bool xn=0,yn=0;
    if(x<0){
        x=-x;
        xn=1;
    }
    if(y<0){
        y=-y;
        yn=1;
    }
    if(k%2==0&&(x+y)%2)
    {
        cout<<"-1\n";
        return 0;
    }
    ll n=(x+y)/k;
    if((x+y)%k!=0)
        n++;
    if(n==1&&k!=(x+y))
        n++;
    while ((n*k-x-y)%2 != 0) n++;
    cout<<n<<endl;

    ll a=(n*k+x+y)/2;
    ll b=(n*k-x-y)/2;
    vector <pair<int,int> > test;
    int X=x;
    int Y=y;
    x=0;y=0;

    //cout<<a<<" "<<b<<endl;
    while(b>=k)
    {
        if(X-x<=Y-y)
        {
                x-=k;
                b-=k;
                test.push_back({x,y});
           
        }
        else
        {
              y-=k;
                b-=k;
                test.push_back({x,y});
        }
    }

    if(b>0)
    {
        if(X-x<=Y-y)
        {
                x-=b;
                y+=(k-b);
                b=0;
                test.push_back({x,y});
           
        }
        else
        {
              y-=b;
                x+=(k-b);
                b=0;
                test.push_back({x,y});
        }
    }
    

    while(X-x>=k)
    {
        x+=k;
        a-=k;
        test.push_back({x,y});
    }
    if(X-x>0)
    {
        y+=(k-(X-x));
        a-=(k-(X-x));
        x=X;
        test.push_back({x,y});
    }

    while(Y-y>=k)
    {
        y+=k;
        a-=k;
        test.push_back({x,y});
    }

    for(int i=0;i<test.size();i++){
        if(xn)
            test[i].first=-test[i].first;
        if(yn)
            test[i].second=-test[i].second;
        cout<<test[i].first<<" "<<test[i].second<<endl;
    }
    
    
    return 0;   
}


 
 


Measured memory_bytes: 3952
#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
using namespace std;

int grn(vector<vector<int>> &e, vector<int> &grundy, int now){
	if(0 <= grundy[now]) return grundy[now];
	vector<int> v;
	for(int next:e[now]) v.emplace_back(grn(e, grundy, next));
	sort(v.begin(), v.end());
	int ret = 0;
	for(int p:v){
		if(p < ret) continue;
		if(ret == p){
			ret++;
			continue;
		}
		break;
	}
	return grundy[now] = ret;
}

bool check(vector<vector<int>> &e, vector<int> &grundy, int i){
	int c = grundy[i];
	set<int> s;
	for(int next:e[i]){
		int t = grundy[next];
		if(t < c) s.insert(t);
		if(t == c) return false;
	}
	return s.size() == c;
}

int main(){
	int n;
	cin >> n;
	vector<int> f(n);
	vector<vector<int>> e(n);
	for(int i = 0; i < n; i++){
		int p;
		cin >> p;
		e[--p].emplace_back(i);
		f[i] = p;
	}
	vector<int> loop, used(n, -1);
	int loop_start = 0;
	{
		int puni = 0;
		while(used[puni] < 0){
			used[puni] = loop.size();
			loop.emplace_back(puni);
			puni = f[puni];
		}
		loop_start = used[puni];
	}
	int min_deg = n + 1, min_vert = 0;
	for(int i = loop_start; i < loop.size(); i++){
		int v = loop[i];
		int deg = e[v].size();
		if(deg < min_deg){
			min_deg = deg;
			min_vert = v;
		}
	}
	vector<int> grundy(n);
	for(int cand = 0; cand <= min_deg; cand++){
		for(int i = 0; i < n; i++){
			grundy[i] = i == min_vert ? cand : -1;
		}
		for(int i = 0; i < n; i++) if(i != min_vert){
			grn(e, grundy, i);
		}
		if(check(e, grundy, min_vert)){
			cout << "POSSIBLE" << endl;
			return 0;
		}
	}
	cout << "IMPOSSIBLE" << endl;
}

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

using namespace std;

#define int long long

void solve()
{
	int a, b, n;
	cin >> a >> b >> n;
	
	if(b == 1)
	{
		cout << 0 << '\n';
		return ;
	}
	
	if(n <= b - 1)
	{
		cout << (a * n) / b - a * (n / b) << '\n';
		return ;
	}
	
	int p = (b - 1);
	int k = n / p;
	p = k * p;
	
	cout << (a * p) / b - a * (p / b) << '\n';
}

main()
{
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	
	int t = 1;

//	cin >> t;

	for(; t; --t)
	{
		solve();
	}
}

Measured memory_bytes: 3652
#include <bits/stdc++.h>
using namespace std;
int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	long long n;
	cin >> n;
	long long a5 = n / 5;
	long long b3 = n / 3;
	long long ab15 = n / 15;
	long long ans = n * (n + 1) / 2;
	ans -= (5 * (a5 * (a5 + 1) / 2));
	ans -= (3 * (b3 * (b3 + 1) / 2));
	ans += (15 * (ab15 * (ab15 + 1) / 2));
	cout << ans;
	
	return 0;
}
 

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

//--------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define RFOR(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define LL long long
#define INF INT_MAX/3

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

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

int main(){
  int a,b;
  scanf("%d %d",&a,&b);
  if (a + b >= 10) printf("error\n");
  else printf("%d\n",a + b);
}


Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include <stdlib.h>
#include <vector>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <math.h>
#include <string>
using namespace std;

int main()
{
    int a,b,x;
    cin >> a >> b >> x;
    if(x>=a && x<=a+b){
        cout << "YES";
    }else{
        cout << "NO";
    }
    return 0;
}

Measured memory_bytes: 888
if __name__ == '__main__':
    n, m, X, Y = (int(i) for i in input().split())
    x = [int(i) for i in input().split()]
    y = [int(i) for i in input().split()]

    result = "War"

    for i in range(-100, 101):
        if X < i and Y >= i and max(x) < i and min(y) >= i:
            result = "No War"

    print(result)


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

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

	int n;
	cin >> n;
	vector<int> a(n);
	int val = 0;

	for (int i = 0; i < n; i++) {
		cin >> a[i];
        val ^= a[i];
	}
    vector<int> ans(n);
	for (int i = 0; i < n; i++) {
		ans[i] = val ^ a[i];
		cout << ans[i] << " ";
	}
	return 0;
}

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

#define watch(x) cerr << (#x) << ": " << (x) << endl
#define int long long



int32_t main() {

    int w, h, x, y; cin >> w >> h >> x >> y;

    int iarea = w*h;
    double area = (double)iarea;
    area /= 2;

    int mult = 0;
    if(x*2 == w && y*2 == h) mult = 1;

    cout << area << " " << mult << endl;
    
    return 0;
}


Measured memory_bytes: 256
n=int(input())

def divisor_num(n):
  ass = []
  for i in range(1,n+1):
    if n%i == 0:
      ass.append(i)
      if i**2 == n:
        continue
        ass.append(n//i)
  return len(ass)

cnt=0
for i in range(1,n+1,2):
  if divisor_num(i) == 8:
    cnt+=1
print(cnt)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define LIMIT 1000000007 //10^9+7
#define rep(i, n) for(int i=0; i<(int)n; i++)
#define all(v) (v).begin(), (v).end()

int main(){
  int N;cin>>N;
  ll ans = 0;
  map<ll,ll> A;
  rep(i,N){
    ll a;cin>>a;
    A[a]++;
    ans += a;
  }

  int Q;cin>>Q;
  while(Q--){

    ll b,c;cin>>b>>c;
    ll Ab = A[b];
    ll Ac = A[c];

    A[c] += Ab;
    A[b] = 0;

    ans -= Ab * b;
    ans += Ab * c;

    cout<<ans<<endl;

  }
}

Measured memory_bytes: 9548
s = input()
q = int(input())
cnt = 0
l = ''
r = ''
for i in range(q):
    t = input()
    if t == '1':
        cnt = 1 - cnt
    else:
        t2, f, c = t.split()
        if cnt == 0:
            if f == '1':
                l = c + l
            else:
                r += c
        else:
            if f == '1':
                r += c
            else:
                l = c + l
                
if cnt == 0:
    print(l+s+r)
else:
    print(r[::-1]+s[::-1]+l[::-1])

Measured memory_bytes: 4524
def main():
    INF = float("inf")

    N, *S = map(int, open(0).read().split())
    M = len(S)

    S.sort(reverse=True)

    Q = [S[0]]
    S[0] = INF
    for _ in range(N):
        Q.sort()
        T = Q[:]

        cur = 1
        while Q:
            p = Q.pop()
            while S[cur] >= p:
                cur += 1
                if cur == M:
                    print("No")
                    exit()
            T.append(S[cur])
            S[cur] = INF

        Q = T

    print("Yes")

main()


Measured memory_bytes: 32044
import sys
from collections import defaultdict
readline = sys.stdin.buffer.readline
# sys.setrecursionlimit(10**8)


def geta(fn=lambda s: s.decode()):
    return map(fn, readline().split())


def gete(fn=lambda s: s.decode()):
    return fn(readline().rstrip())


def main():
    s, t = gete(), gete()

    ans = 0
    for i in range(len(s)):
        if s[i] != t[i]:
            ans += 1

    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 74212
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; ++i)
#define REPR(i, n) for (int i = n - 1; i >= 0; --i)
#define FOR(i, a, b) for (int i = a; i < b; ++i)
#define FORR(i, a, b) for (int i = b - 1; i >= a; --i)
#define SORT(v) sort(v.begin(), v.end())
#define SORTR(v) sort(v.rbegin(), v.rend())
#define REV(v) reverse(v.begin(), v.end())
#define ITER(v) for (auto itr = v.begin(), itr != v.end(); ++itr)
#define LB(v, x) lower_bound(v.begin(), v.end(), x) - v.begin()
#define UB(v, x) upper_bound(v.begin(), v.end(), x) - v.begin()
#define SZ(v) (int)v.size()
using namespace std;
using ll = long long;
using P = pair<int, int>;

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

    int N, K;
    string S;
    cin >> N >> K >> S;
    int res = 0;
    int l = 0, r = 0;
    while (r < N && S[r] == '1') {
        ++r;
        ++res;
    }
    queue<int> qu;
    while (r < N) {
        while (K) {
            while (r < N && S[r] == '0') ++r;
            --K;
            qu.emplace(r);
            while (r < N && S[r] == '1') ++r;
        }
        ++K;
        res = max(res, r - l);
        l = qu.front();
        qu.pop();
    }
    cout << res << endl;

    return 0;
}


Measured memory_bytes: 720
#include <bits/stdc++.h>
using namespace std;
int main(){
	int N,M;
  	cin >> N >> M;
	if(N > 1 && M > 1)cout << N*(N-1)/2 + M*(M-1)/2 << endl;
	else if(N <= 1 && M > 1)cout << M*(M-1)/2 << endl;
    else if(N > 1 && M <= 1)cout << N*(N-1)/2 << endl;
  	else cout << 0 << endl;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <cfloat>
#include <ctime>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>

using namespace std;

#ifdef _MSC_VER
#define __typeof__ decltype

template <class T>
int __builtin_popcount(T n) { return n ? 1 + __builtin_popcount(n & (n - 1)) : 0; }
#endif

#define foreach(it, c) for (__typeof__((c).begin()) it=(c).begin(); it != (c).end(); ++it)
#define all(c) (c).begin(), (c).end()
#define rall(c) (c).rbegin(), (c).rend()
#define popcount __builtin_popcount

const double EPS = 1e-8;
typedef long long ll;
typedef pair<int, int> pint;


int dp[2][101][1001];
int sopt[1001], opt[1001];
const int INF = 1000000;
void dpru(int n, int low, int upper, int limit, int* e, int*s, int* opt)
{
	for (int i = 0; i < 2; ++i)
		for (int j = 0; j <= upper; ++j)
			for (int k = 0; k <= limit; ++k)
				dp[i][j][k] = -INF;
	dp[0][0][0] = 0;

	for (int i = 0; i < n; ++i)
	{
		for (int j = 0; j <= upper; ++j)
		{
			for (int k = 0; k <= limit; ++k)
			{
				dp[(i+1)&1][j][k] = max(dp[(i+1)&1][j][k], dp[i&1][j][k]);
				if (k + e[i] <= limit)
					dp[(i+1)&1][j+1][k+e[i]] = max(dp[(i+1)&1][j+1][k+e[i]], dp[i&1][j][k] + s[i]);
			}
		}
	}

	for (int i = 0; i <= limit; ++i)
	{
		opt[i] = -INF;
		for (int j = low; j <= upper; ++j)
			opt[i] = max(opt[i], dp[n&1][j][i]);
	}
}
int main()
{
	int limit, n, m, x;
	while (cin >> limit >> n >> m >> x, limit | n | m | x)
	{
		string hoge;
		int se[100], ss[100], e[100], s[100];
		for (int i = 0; i < n; ++i)
			cin >> hoge >> se[i] >> ss[i];
		for (int i = 0; i < m; ++i)
			cin >> hoge >> e[i] >> s[i];

		dpru(n, 1, 2, limit, se, ss, sopt);
		dpru(m, x, m, limit, e, s, opt);

		int res = 0;
		for (int i = 0; i <= limit; ++i)
			for (int j = 0; i+j <= limit; ++j)
				res = max(res, sopt[i] + opt[j]);

		cout << res << endl;
	}

	return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
#include<cstdio>
using namespace std;
int main(){
    double r;
    double sq;
    double cir;
    double pi = M_PI; 

    scanf("%lf", &r);
    sq = r * r * pi;
    cir = 2 * r * pi;

    printf("%lf %lf",sq, cir);

    return 0;
}


Measured memory_bytes: 3152
import java.util.*;

public class Main {
	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int l = sc.nextInt();
		int end = l + n - 1;
		int sum;
		if (l >= 0) {
			sum = (l + 1 + end) * (n - 1) / 2;
		} else if (end > 0) {
			sum = (l + end) * n / 2;
		} else {
			sum = (l + end - 1) * (n - 1) / 2;
		}
		System.out.println(sum);
	}
}


Measured memory_bytes: 21716
//Ace
#include<bits/stdc++.h>
using namespace std;
using in = long long;
using str = string;
using pi = pair<in,in>;
using vi = vector<in>;
#define F first
#define S second
#define pb push_back
#define rep(i,k,n) for (in i = k; i < n; ++i)
#define repr(i,k,n) for (in i = k; i >= n; --i)
#define sz(x) (in)x.size()
#define all(x) begin(x), end(x)
const int MOD = 1e9 + 7;

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

    in n;
    cin>>n;
    in a[n];
    rep(i,0,n){
        cin>>a[i];
    }
    in ans = 0;
    rep(i, 1, n){
        ans += max(0LL, a[i-1]-a[i]);
        a[i] = max(a[i-1], a[i]);
    }
    cout<<ans;

    return 0 ;
}

Measured memory_bytes: 5184
#include<stdio.h>
#include<string.h>
int main(){
  char card[200],stc[200];
  int m,h,length,i,j;

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

	  if(card[0] == '-') break;
	  length = strlen(card);
	  scanf("%d",&h);
	  for(m=0;m<h;m++){
	    scanf("%d",&i);
		strncpy(stc,card,i);
		stc[i] = '\0';
		for(j = 0;j<length-i;j++) card[j] = card[i+j];
		card[j] = '\0';
		strcat(card,stc);
	  }
	  printf("%s\n",card);
	}
	return 0;
}

Measured memory_bytes: 604
#include<bits/stdc++.h>
#define FOR(i,a,b) for(int i=a;i<=b;i++)
static const int INF = 8931919114514810;
static const int MAX_N = 300;
using namespace std;

int A[300],B[300],C[300];
int mem[MAX_N][MAX_N];
int N,D;
int Day[MAX_N];
int cal(int day,int pp){
   int res=0;
   if(mem[day][pp]!=-1){
        return mem[day][pp];
   }
   if(day==N+1){
        return res=0;
   }
   if(day<=1){
       FOR(i,1,D){
            if(Day[day]>=A[i]&&Day[day]<=B[i]){
            res=max(cal(day+1,C[i]),res);
         }
      }
   }
   else{
        FOR(i,1,D){
            if(Day[day]>=A[i]&&Day[day]<=B[i]){
                int temp=abs(pp-C[i]);
                res=max(cal(day+1,C[i])+temp,res);
            }
        }
   }
   return mem[day][pp]=res;
}

int main(){
    cin>>N>>D;
    memset(mem,-1,sizeof(mem));
    FOR(i,1,N){
        cin>>Day[i];
    }
    FOR(i,1,D){
        cin>>A[i]>>B[i]>>C[i];
    }
    cout<<cal(1,0)<<endl;
    return 0;
}

Measured memory_bytes: 1540
package main

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

var sc = bufio.NewScanner(os.Stdin)
var out = bufio.NewWriter(os.Stdout)

func next() string {
	sc.Scan()
	return sc.Text()
}
func nextInt() int {
	a, _ := strconv.Atoi(next())
	return a
}
func nextInts(n int) []int {
	ret := make([]int, n)
	for i := 0; i < n; i++ {
		ret[i] = nextInt()
	}
	return ret
}

//var done []bool = make([]bool, 10)
//var memo []int = make([]int, 10)

//func fib(n int) int {
//	fmt.Println(n)
//	if n == 0 {
//		return 0
//	}
//	if n == 1 {
//		return 1
//	}
//	if done[n] {
//		fmt.Println("done" + fmt.Sprint(n))
//		return memo[n]
//	}
//	done[n] = true
//	memo[n] = fib(n-1) + fib(n-2)
//	return memo[n]
//}

var dp []int = make([]int, 10)

func fib(n int) int {
	dp[0] = 0
	dp[1] = 1
	for i := 2; i <= n; i++ {
		dp[i] = dp[i-1] + dp[i-2]
	}
	return dp[n]
}

func main() {
	sc.Split(bufio.ScanWords)
	defer out.Flush() // !!!!coution!!!! you must use Fprint(out, ) not Print()
	a := next()
	r := []rune(a)
	for i := 0; i < len(r); i++ {
		r[i] = 'x'
	}
	fmt.Fprint(out, string(r))
}


Measured memory_bytes: 640