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

using namespace std;

//long long maxValueFrom(int curr, const vector<int>& w, const vector<long long>& v, int outstandingCapacity
//    , vector<vector<long long> >& memo) {
//    int N = w.size();
//    if (curr == N) {
//        return 0LL;
//    }
//    if (memo[curr][outstandingCapacity] > 0) {
//        return memo[curr][outstandingCapacity];
//    }
//
//    long long skipThis = maxValueFrom(curr + 1, w, v, outstandingCapacity, memo);
//    int thisWeight = w[curr];
//    long long ret = 0LL;
//    if (outstandingCapacity - thisWeight < 0) {
//        ret = skipThis;
//    }
//    else {
//        long long takeThis = maxValueFrom(curr + 1, w, v, outstandingCapacity - thisWeight, memo) + v[curr];
//        ret = max(takeThis, skipThis);
//    }
//
//    memo[curr][outstandingCapacity] = ret;
//    return ret;
//}

void Main() {
    int N, W;
    cin >> N >> W;
    vector<int> w(N, 0);
    vector<long long> v(N, 0);
    for (int i = 0; i < N; ++i) {
        cin >> w[i] >> v[i];
    }

    //vector<vector<long long> > memo(N, vector<long long>(W + 1, -1LL));
    //long long ans = maxValueFrom(0, w, v, W, memo);
    //cout << ans << endl;

    vector<vector<long long> > maxValue(N, vector<long long>(W + 1, -1LL));
    for (int j = 0; j <= W; ++j) {
        if (w[N - 1] > j) {
            maxValue[N - 1][j] = 0;
        }
        else {
            maxValue[N - 1][j] = v[N - 1];
        }
    }
    for (int i = N - 2; i >= 0; --i) {
        for (int j = 0; j <= W; ++j) {
            if (w[i] > j) {
                maxValue[i][j] = maxValue[i + 1][j];
            }
            else {
                maxValue[i][j] = max(maxValue[i + 1][j - w[i]] + v[i], maxValue[i + 1][j]);
            }
        }
    }
    cout << maxValue[0][W] << endl;
}

int main() {
    std::cout << std::fixed << std::setprecision(15);
    Main();
    return 0;
}


Measured memory_bytes: 79360
#include<stdio.h>
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<string.h>
using namespace std;

typedef long long LL;
typedef vector<int> VI;

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define EACH(i,c) for(__typeof((c).begin()) i=(c).begin(),i##_end=(c).end();i!=i##_end;++i)
#define eprintf(...) fprintf(stderr, __VA_ARGS__)

template<class T> inline void amin(T &x, const T &y) { if (y<x) x=y; }
template<class T> inline void amax(T &x, const T &y) { if (x<y) x=y; }
template<class Iter> void rprintf(const char *fmt, Iter begin, Iter end) {
    for (bool sp=0; begin!=end; ++begin) { if (sp) putchar(' '); else sp = true; printf(fmt, *begin); }
    putchar('\n');
}

int N, M;
VI G[100011];
int use[100011];

void MAIN() {
    scanf("%d%d", &N, &M);
    REP (i, M) {
	int x, y;
	scanf("%d%d", &x, &y);
	x--; y--;
	G[x].push_back(y);
	G[y].push_back(x);
    }

    VI ord; ord.reserve(N);
    LL S, C, B;
    S=C=B=0;
    REP (v, N) if (!use[v]) {
	if (G[v].empty()) {
	    S++;
	} else {
	    bool bipartite = true;
	    ord.clear();
	    ord.push_back(v);
	    use[v] = 1;

	    for (int i=0; i<(int)ord.size(); i++) {
		int w = ord[i];
		EACH (e, G[w]) {
		    if (use[*e] && use[*e] == use[w]) {
			bipartite = false;
		    }
		    if (use[*e]) continue;
		    ord.push_back(*e);
		    use[*e] = 3 - use[w];
		}
	    }

	    (bipartite? B: C)++;
	}
    }

    LL ans = 0;
    ans += S*N*2;
    ans -= S*S;
    ans += B*B*2;
    ans += B*C*2;
    ans += C*C;

    printf("%lld\n", ans);
}

int main() {
    int TC = 1;
//    scanf("%d", &TC);
    REP (tc, TC) MAIN();
    return 0;
}



Measured memory_bytes: 7552
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
using namespace std;
int cl(int a, int b) {
	return (a - (a%b)) / b;//b=0だと積む
}
int up(int a, int b) {
	return cl(a + b - 1, b);//b=0だと積む
}
int main() {
	int n,m, big; int ans = 1;
	cin >> n>>m;
	vector<int> c(2*n);
	vector<int> yobi(2*n);
	for (int i = 0; i < 2*n; i++) {
		c[i] = i;
	}
	vector<int> d(m);
	for (int i = 0; i < m; i++) {
		cin >> d[i];
	}
	for (int i = 0; i < m; i++) {
		yobi = c;
		if (d[i] == 0) {
			for (int j = 0; j < 2 * n; j++) {
				if (j % 2 == 0) {
					c[j] = yobi[j / 2];
				}
				else {
					c[j] = yobi[n + (j - 1) / 2];
				}
			}
		}
		else {
			for (int j = 0; j < 2 * n; j++) {
				if (j < d[i]) {
					c[(2 * n)-d[i]+j]=yobi[j];
				}
				else {
					c[j - d[i]] = yobi[j];
				}
			}

		}
	}
	for (int i = 0; i < 2 * n; i++) {
		cout << c[i]+1<<endl;
	}
}



Measured memory_bytes: 3148
def pm(x):
  if x>=0:
    return 1
  else:
    return -1
X,K,D=map(int,input().split())
if (abs(X))<D :
  if K%2==0:
    print(int(abs(X)))
  else:
    a=X-pm(X)*D
    print(int(abs(a)))
else:
  if abs(X)//D>=K:
    a=X-(pm(X))*D*K
    print(int(abs(a)))
  else:
    K=K-int(abs(X)//D)
    X=X-(pm(X))*D*int(abs(X)//D)
    if (abs(X))<D :
      if K%2==0:
        print(int(abs(X)))
      else:
        a=X-(pm(X))*D
        print(int(abs(a)))

Measured memory_bytes: 9152
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>

using namespace std;

int main() {
    int j = 0;
    string c1,c2;
    cin >> c1 >> c2;
    for (int i = 0; i < 3; ++i) {
        if(c1[i] == c2[2-i])j++;
    }
    if(j == 3)cout << "YES" << endl;
    else cout << "NO" << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<math.h>
int main(void){
    int n,i,j,min=100000,f,l,abs;
    int w[101];
    scanf("%d",&n);

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

    for(i=1;i<n;i++){
        f=0,l=0;
        for(j=0;j<=i;j++){
            f +=w[j];
        }
        for(j=i+1;j<n;j++){
            l +=w[j];
        }
        if(l-f>0){
            abs = l-f;
        }else{
            abs = f-l;
        }
        if(abs<min){
            min = abs;
        }
    }
    printf("%d",min);
    return 0;
}

Measured memory_bytes: 128
#include<iostream>
#include<algorithm>
#include<string>
using namespace std;
int main(){
	int N,a[100],b[100];
	cin>>N;
	for(int i=0;i<N;i++)cin>>a[i]>>b[i];
	for(int i=2;i<N;i++){
		if(a[i-2]==b[i-2] && a[i-1]==b[i-1] && a[i]==b[i]){
			cout<<"Yes";
			return 0;
		}
	}
	cout<<"No";
	return 0;
}

Measured memory_bytes: 3672
#include<iostream>
#include<bits/stdc++.h>
#include<string>
using namespace std;
int main()
{
  int a,b ;
  cin >> a >> b  ;
  
  int ans = 0 ;
  for(int i=0;i<2;i++){
  if(a<b){
    ans += b ;
    b = b-1 ;
  }else{
    ans += a ;
    a = a-1 ;
  }
  }
  
  cout << ans << endl ;
  return 0 ;
}

Measured memory_bytes: 256
import java.util.*;
public class Main{
    static Scanner kbd = new Scanner(System.in);
    public static void main(String[] args){
	int[] p = new int[10000];
	putN(p);
	while(kbd.hasNext()){
	    int n = kbd.nextInt();
	    if(n!=0){
		int i=0;
		int s=0;  //テゥツ?」テァツカツ堙」ツ?療」ツ?淌ァツエツ?ヲツ閉ーテ」ツ?ョテ・ツ陳?
		int l=0;  //テゥツ?」テァツカツ堙ァツエツ?ヲツ閉ーテ」ツ?ョテ」ツ??」ツ?。テヲツ慊?・ツーツ?
		int c = 0;  //ティツ。ツィテァツ渉セテ」ツ?ァテ」ツ?催」ツ?淌」ツδ妥」ツつソテ」ツδシテ」ツδウテヲツ閉ー
		while(p[i]!=0){
		    if(s < n) {
			s += p[i];
			i++;
		    }
		    else if(s>n){
			s -= p[l];
			l++;
		    }
		    else;

		    if(s==n) {
			c++;
			s += p[i];
			i++;
		    }
		}	 
		System.out.println(c);
	    }
	}
    }

    
    
    
    static void putN(int[] p){
	int i=0, k;
	for(k=2; k<10000; k++){
	    if(check(k)) {
		p[i] = k;
		//System.out.print(p[i]+" ");
		i++;
	    }
	}

    }
    static boolean check(int n){
	int a, c=0;
	for(a=1; a<=n; a++){
	    if(n%a==0) c++;
	}
	if(c>2) return false;
	return true;
    }    
}

Measured memory_bytes: 12000
#include<bits/stdc++.h>
//ios::sync_with_stdio(false);cin.tie(0);
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<pii,int> ppii;
typedef pair<int,pii> pipi;
typedef pair<ll,ll> pll;
typedef pair<pll,ll> ppll;
typedef pair<ll,pll> plpl;
typedef tuple<ll,ll,ll> tl;
ll mod=1000000007;
ll mod2=998244353;
ll mod3=1000003;
ll mod4=998244853;
ll inf=1000000000000000000;
double pi=2*acos(0);
#define rep(i,m,n) for(ll i=m;i<n;i++)
#define rrep(i,n,m) for(ll i=n;i>=m;i--)
int dh[4]={1,-1,0,0};
int dw[4]={0,0,1,-1};
int ddh[8]={-1,-1,-1,0,0,1,1,1};
int ddw[8]={-1,0,1,-1,1,-1,0,1};
ll lmax(ll a,ll b){
    if(a<b)return b;
    else return a;
}
ll lmin(ll a,ll b){
    if(a<b)return a;
    else return b;
}
ll gcd(ll a,ll b){
    if(a<b)swap(a,b);
    if(b==0)return a;
    if(a%b==0)return b;
    return gcd(b,a%b);
}
ll Pow(ll n,ll k){
    ll ret=1;
    ll now=n;
    while(k>0){
        if(k&1)ret*=now;
        now*=now;
        k/=2;
    }
    return ret;
}
int main(){
    ios::sync_with_stdio(false);cin.tie(0);
    string s;cin>>s;
    unordered_map<int,int> mp,used;
    used[0]=1;
    mp[0]=0;
    int now=0;
    rep(i,0,s.size()){
        int t=s[i]-'a';
        now^=(1<<t);
        if(now==0)continue;
      int u=1000000000;
      if(used[now]==1)u=mp[now];
        used[now]=1;
        int mi=1000000000;
        rep(j,0,26){
            int y=1<<j;
           // if((now&y)!=y)continue;
            int r=now^y;
            if(used[r]==0)continue;
            mi=min(mi,mp[r]);
        }
      
        mp[now]=min(u,mi+1);
    }
    mp[0]=1;
    cout<<mp[now]<<endl;
}


Measured memory_bytes: 178284
#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,a) FOR(i,0,a)
	
using namespace std;
typedef long long ll;

string N;

int main(){
	cin>>N;
	if (N.size()==1){
		cout<<N<<endl;
	}else{
		bool flg=true;
		REP(i,(int)N.size()-1){
			if (N[i+1]!='9'){
				flg=false;
			}
		}
		if (!flg){
			N[0]--;
			REP(i,(int)N.size()-1){
				N[i+1]='9';
			}
		}
		int s=0;
		REP(i,(int)N.size()){
			s+=N[i]-'0';
		}
		cout<<s<<endl;
	}
	return 0;
}

Measured memory_bytes: 256
import sys
import heapq, math
from itertools import zip_longest, permutations, combinations, combinations_with_replacement
from itertools import accumulate, dropwhile, takewhile, groupby
from functools import lru_cache
from copy import deepcopy

N, K = map(int, input().split())

c = N // K

print(min(N - c * K, (c + 1) * K - N))

Measured memory_bytes: 3828
#include <iostream>
#include <stdio.h>
#include <string>
using namespace std;
typedef long long ll;
int main(void){
    int n;
    cin >> n;
    int ans = 1;
    for(int i = 1; i <= n; i++){
        if(i == 2 || i == 4 || i == 8 || i == 16 || i == 32 || i == 64 ){
            ans = i;
        }
    }
    cout << ans << endl;
    
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<ll,ll> l_l;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
const int INF=1001001000;
const int mINF=-1001001000;
const ll LINF=1010010010010010000;
template<class T> inline bool chmin(T& a, T b) {
if (a > b) {
a = b;
return true;
}
return false;
}
template<class T> inline bool chmax(T& a, T b) {
if (a < b) {
a = b;
return true;
}
return false;
}
int main(){
    int h,w,k;cin >> h >> w >> k;
    string s[h];
    rep(i,h) cin >> s[i];
    int cnt=0;
    vector<vector<int>> num(h,vector<int>(w));
    rep(i,h){
        rep(j,w){
            if(s[i][j]=='#'){
                cnt++;
                num[i][j]=cnt;
            }
        }
    }
    rep(i,h){
        rep(j,w){
            if(num[i][j]==0){
                if(j!=0) num[i][j]=num[i][j-1];
            }
        }
    }
    rep(i,h){
        drep(j,w){
            if(num[i][j]==0){
                if(j!=w-1) num[i][j]=num[i][j+1];
            }
        }
    }
    rep(j,w){
        rep(i,h){
            if(num[i][j]==0){
                if(i!=0) num[i][j]=num[i-1][j];
            }
        }
    }
    rep(j,w){
        drep(i,h){
            if(num[i][j]==0){
                if(i!=h-1) num[i][j]=num[i+1][j];
            }
        }
    }
    rep(i,h){
        rep(j,w){
            if(j!=0) cout << " ";
            cout << num[i][j];
        }
        cout << endl;
    }
    return 0;
}

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

int main() {
  int N;
  cin >> N;
  vector<int> vec(N);
  int sum=0;
  
  for (int i=0; i<N; i++){
    cin >> vec.at(i);
    sum += vec.at(i);
  }
  
  sort(vec.begin(), vec.end());
  reverse(vec.begin(), vec.end());
  
  int A=0, i=0;
  while (i<N){
    A += vec.at(i);
    i += 2;
  }
  
  cout << 2*A-sum << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<unordered_map>
#include<vector>
#include<algorithm>
#include<cmath>
#include<string>
using namespace std;

int main(){
  int N;
  cin >> N;
  int bx=0;
  int xa=0;
  int ba=0;
  string str;
  
  long long int count = 0;
  
  for(int i = 0; i < N; i++){
    cin >> str;
    if(str[0] == 'B' && str[(int)str.size() - 1] == 'A')
      ba++;
    else{
      if(str[0] == 'B')
        bx++;
      if(str[(int)str.size() - 1] == 'A')
        xa++;
    }
    
    for(int si = 0; si < (int)str.size()-1; si++){
      if(str[si] == 'A' && str[si+1] == 'B')
        count++;
    }
  }
  
  if(ba != 0){
    count += (ba - 1);
    if(xa != 0 || bx != 0){
      count += min(xa, bx) + 1;
    }
  } else {
    count += min(xa, bx);
  }
  
  cout << count << endl;
  return 0;
}

Measured memory_bytes: 256
A,B,C=list(map(int,input().split()))
K=int(input())

def check(a,b,c):
    if a < b and b < c:
        return True
    else:
        return False

ans = "No"
if check(A,B,C):
    ans = "Yes"
else:
    while K>0:
        if A >= B:
            B*=2
            K-=1
            # print("K=",K," (A,B,C)=", A,B,C)
            if check(A,B,C):
                ans = "Yes"
                break
        else:
            if B >= C:
                C*=2
                K-=1
                # print("K=",K," (A,B,C)=", A,B,C)
                if check(A,B,C):
                    ans = "Yes"
                    break

print(ans)

Measured memory_bytes: 9204
#include <bits/stdc++.h>
#define print(x) cout << x << '\n';

using namespace std;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    // freopen("input.in", "r", stdin);
    int n, x;
    cin >> n >> x;
    int arr[n+1];
    for(int i = 0; i < n; i++){
        cin >> arr[i];
    }
    sort(arr, arr+n);
    int con = 0;
    for(int i = 0; i < n; i++){
        if(x >= arr[i] && i < n-1){
            con++;
            x -= arr[i];
        }else if(x == arr[i]){
            con++;
            break;
        }else{
            break;
        }
    }
    cout << con;
    
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e6 + 7;
int n, a[maxn];
int S(int i, int j, int k) {return a[i] <= k && a[j] <= k;}
int M(int i, int j, int k) {return a[i] > k && a[j] > k;}
int check(int k) {
	for (int i = 0; i < n - 1; ++i) {
		if(M(n + i, n + i + 1, k) || M(n - i, n - i - 1, k)) return 0;
		if(S(n + i, n + i + 1, k) || S(n - i, n - i - 1, k)) return 1;
	}
	return S(1, 1, k);
} 
int main() {
	scanf("%d", &n);
	for (int i = 1; i <= 2 * n - 1; ++i) scanf("%d", &a[i]);
	int ans, l = 1, r = 2 * n - 1;
	while(l <= r) {
		int mid = (l + r) >> 1;
		if(check(mid)) ans = mid, r = mid - 1;
		else l = mid + 1;
	}
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 1152
s=input()
t=input()
ans=len(t)
def f(s,t):
    a=0
    for i,j in zip(s,t):
        a+=i!=j
    return a

for i in range(len(s)-len(t)+1):
    ans=min(ans,f(t,s[i:len(t)+i]))
print(ans)

Measured memory_bytes: 9124
#include<iostream>
using namespace std;
int w,h,cnt=0;
char a;
int dx[4]={1,0,0,-1},dy[4]={0,1,-1,0};
char mas[1000][1000];
void loop(int y,int x);
int main(){
  while(1){
    cin >> h >> w;
    if(w==0 && h==0){
      break;
    }
    for(int i=0;i<h;i++){
      for(int j=0;j<w;j++){
	cin >> mas[i][j];
      }
    }
    for(int i=0;i<h;i++){
      for(int j=0;j<w;j++){
	if(mas[i][j]=='@' || mas[i][j]=='#' || mas[i][j]=='*'){
	  cnt++;
	  a=mas[i][j];
	  loop(i,j);
	}
      }
    }
    cout << cnt << endl;
    cnt=0;
  }
}

void loop(int y,int x){
  mas[y][x]='.';
  for(int i=0;i<4;i++){
    int X=x+dx[i];
    int Y=y+dy[i];
    if(X>=0 && X<w && Y>=0 && Y<h && mas[Y][X]==a){
      loop(Y,X);
    }
  }
  return;
}

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

int main(){
  ios::sync_with_stdio(false);
  string s;
  cin >> s;
  int ans[s.size()];
  int temp[2];
  memset(ans, 0, sizeof(ans));

  for(int i=0; i<s.size()-1; i++){
    if(s[i] == 'R' && s[i+1] == 'L'){
      memset(temp, 0, sizeof(temp));

      for(int j=i; j>=0; j--)
        if(s[j] == 'R')
          temp[(i-j)%2]++;
        else
          break;

      for(int j=i+1; j<s.size(); j++)
        if(s[j] == 'L')
          temp[(j-i)%2]++;
        else
          break;

        ans[i] = temp[0];
        ans[i+1] = temp[1];
    }
  }

  for(int i=0; i<s.size(); i++)
    cout << ans[i] << " ";

  return 0;
}


Measured memory_bytes: 1104
#include <bits/stdc++.h>
#include <string>
#include <vector>
#include <algorithm>
#include <iostream>
#include <set>
using namespace std;
const int MOD = 1000000007;
const int INF = 1e9;
typedef long long ll;

int main(){
    int r, d, x;
    cin >> r >> d >> x;

    for(int i = 0; i < 10; i++){
        cout << r*x-d << endl;
        x = r*x-d;
    }
}

Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <utility>
#include <queue>
#include <vector>
#include <array>
#include <stack>
#include <list>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <set>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cstdint>
#include <cstring>
#include <cmath>

using namespace std;

typedef long long ll;

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rrep(i,n) for(int (i)=(n-1);(i)>=0;(i)--)
#define bs(n) (1ul<<(n))

int n, t, a[3000], b[3000], dp[3001][6001] = { {0} }, dp2[3001][6001] = { {0} }, r = 0;

int main() {
	cin >> n >> t;
	rep(i, n)cin >> a[i] >> b[i];
	rep(i, n) {
		rep(j, t + 1) {
			dp[i + 1][j + a[i]] = max(dp[i + 1][j + a[i]], dp[i][j] + b[i]);
			dp[i + 1][j] = max(dp[i + 1][j], dp[i][j]);
		}
		rep(j, t + 1) {
			dp[i + 1][j + 1] = max(dp[i + 1][j + 1], dp[i + 1][j]);
		}
	}

	rrep(i, n) {
		rep(j, t + 1) {
			dp2[i][j + a[i]] = max(dp2[i][j + a[i]], dp2[i + 1][j] + b[i]);
			dp2[i][j] = max(dp2[i][j], dp2[i + 1][j]);
		}
		rep(j, t + 1) {
			dp2[i][j + 1] = max(dp2[i][j + 1], dp2[i][j]);
		}
	}

	rep(i, n) {
		rep(j, t) {
			r = max(r, dp[i][j] + dp2[i + 1][(t - 1) - j] + b[i]);
		}
	}

	cout << r << endl;
}

Measured memory_bytes: 140928
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
#define rep(i,m,n) for(int i=m;i<n;i++)
ll mod=1e9+7;

int main(){
  int h,w;
  cin>>h>>w;
  char c[h][w];
  rep(i,0,h){
    rep(j,0,w){
      cin>>c[i][j];
    }
  }
  char d[h][w];
  rep(i,0,h){
    rep(j,0,w){
      if(c[i][j]=='#') d[i][j]='#';
      else{
        int cnt=0;
        rep(k,i-1,i+2){
          rep(l,j-1,j+2){
            if(k>=0 && k<h && l>=0 && l<w && c[k][l]=='#'){
              cnt++;
            }
          }
        }
        d[i][j]='0'+cnt;
      }
    }
  }
  rep(i,0,h){
    rep(j,0,w){
      cout<<d[i][j];
    }
    cout<<endl;
  }
}

Measured memory_bytes: 256
using static System.Math;
using System;

public class Hello
{
    public static void Main()
    {
        string[] line = Console.ReadLine().Trim().Split(' ');
        var h = int.Parse(line[0]);
        var w = int.Parse(line[1]);
        var a = getArray(h, w);
        var b = getArray(h, w);
        line = Console.ReadLine().Trim().Split(' ');
        var h2 = int.Parse(line[0]);
        var w2 = int.Parse(line[1]);
        var c = getArray(h2, w2);
        var ans = getAns(a, b, c, h, w, h2, w2);
        if (ans == int.MinValue) Console.WriteLine("NA");
        else Console.WriteLine(ans);
    }
    static int getAns(int[,] a, int[,] b, int[,] c, int h, int w, int h2, int w2)
    {
        var ans = int.MinValue;
        for (int i = 0; i <= h - h2; i++)
            for (int j = 0; j <= w - w2; j++)
            {
                var t = 0;
                for (int k = 0; k < h2; k++)
                {
                    for (int L = 0; L < w2; L++)
                        if (b[i + k, j + L] == c[k, L]) t += a[i + k, j + L];
                        else goto next;
                }
                ans = Max(ans, t);
                next:;
            }
        return ans;
    }
    static int[,] getArray(int h, int w)
    {
        var a = new int[h, w];
        for (int i = 0; i < h; i++)
        {
            string[] line = Console.ReadLine().Trim().Split(' ');
            for (int j = 0; j < w; j++) a[i, j] = int.Parse(line[j]);
        }
        return a;
    }
}



Measured memory_bytes: 17960
#include <cstdio>
#include <algorithm>
using namespace std;
int K, X;
int main() {
  scanf("%d %d", &K, &X);
  for(int i = X-K+1; i <= X+K-1;) {
    if(i >= -1000000 && i <= 1000000) {
      printf("%d ", i++);
    }
  }
}

Measured memory_bytes: 128
N,M=map(int,input().split())
i=0
K=M
while K>0:
    if (M-K)%2==0:
        print(i//2+1,i//2+1+K)
    else:
        print(M+2+(i-1)//2,M+2+(i-1)//2+K)
    K-=1
    i+=1
    

Measured memory_bytes: 9264
#include<bits/stdc++.h>
#define fint register int
#define h 5001
#define p 4735894
#define int long long
using namespace std;
signed main()
{
	int a,b,c,d;
	cin>>a>>b>>c>>d;
	cout<<max(max(a*c,b*d),max(a*d,b*c));
	return 0;
}

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

int G[100010];
int main() {
	string s, t, u;
	cin >> s;
	for(int i=0; i<s.size(); ++i){
	    if(s[i]!='x'){
	        t += s[i];
	        u=s[i]+u;
	    }
	}
	if(t!=u) cout << -1 << endl;
	else{
	    int num=0, ans=0;
	    for(int i=0; i<s.size(); ++i){
	        if(s[i]=='x') ++G[num];
	        else ++num;
	    }
	    for(int i=0; i*2<num; ++i){
	        ans += abs(G[i]-G[num-i]);
	    }
	    cout << ans << endl;
	}
	return 0;
}


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

int main(){
    long long x, ans = 0;
    scanf("%lld", &x);
    ans += x/11*2;
    x %= 11;
    if(x > 6) ans += 2;
    else if(x > 0) ans++;
    printf("%lld\n", ans);
}

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

using namespace std;

typedef long long int ll;
typedef pair<ll, ll> pll;

#define FOR(i, n, m) for(ll (i)=(m);(i)<(n);++(i))
#define REP(i, n) FOR(i,n,0)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll) 1e15;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll A, B, C;
    cin >> A >> B >> C;
    ll M = std::max({A, B, C});
    ll ans = (M - A) / 2 + (M - B) / 2 + (M - C) / 2;
    ll odd = (M - A) % 2 + (M - B) % 2 + (M - C) % 2;
    if (odd == 1)
        ans += 2;
    else if (odd == 2)
        ans++;

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

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

#ifndef ONLINE_JUDGE
	#define W(x, y) cerr << "\033[31m" << #x << " = " << x << "\033[0m" << y;
#else
	#define W(x, y)
#endif


#define ll long long
#define pii pair<int, int>
#define pll pair<ll, ll>
#define vi vector<int>
#define vii vector<pii>
#define vl vector<ll>
#define vll vector<pll>
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define pi acos(-1)
#define ld long double
#define prime (1000000000 + 7)

using namespace std;

#define INF 1000000000

vll h(string s){
	ll p1 = 1000000000 + 7, p2 = 1000000000 + 9, q = 31;

	ll n = s.size();
	vll res(n);

	res[0].ff = (s[0]-'a' + 1)%p1;
	res[0].ss = (s[0]-'a' + 1)%p1;
	for(int i = 1; i < n; ++i){
		res[i].ff = ((s[i]-'a' + 1)%p1 + (res[i-1].ff * q)%p1 )%p1;
		res[i].ss = ((s[i]-'a' + 1)%p2 + (res[i-1].ss * q)%p2 )%p2;
	}


	return res;
}

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

	ll a, b;
	cin >> a >> b;
	cout << (a - 2 * b > 0 ? a - 2 * b : 0) << endl;
	
	
	return 0;
}

Measured memory_bytes: 256
#include<stdbool.h>
#include<stdio.h>
int main(){
  int n,m,k = 8e6;
  while(scanf("%d%d",&m,&n),n){
    bool b[k]={};
    for(;n!=0;n--){
      while(b[m]&&m<k)m++;
      for(int j=m;j<k;j+=m)b[j]=true;
    }
    while(b[++m]);
    printf("%d\n",m);
  }
}

Measured memory_bytes: 10492
// E - Coprime
#include <bits/stdc++.h>
using namespace std;
#define rpd(i,s,e,d) for(int i=(s);i<(int)(e);i+=(d))

int sum_array(vector<int> &C, int start, int end, int step){
	int c = 0;
	rpd(i, start, end, step) c += C[i];
	return c;
}

int main(){
	cin.tie(0); ios::sync_with_stdio(false); // 232ms -> 90ms

	int MAX_A = 1000000 + 1;
	int N; cin>>N;
	vector<int> C(MAX_A, 0);
	int g = 0;
	rpd(i, 0, N, 1){
		int a; cin>>a;
		C[a]++;
		g = gcd(g, a);
	}
	int t = 0;
	if(g > 1) t = 2;
	else if(sum_array(C, 2, MAX_A, 2) > 1) t = 1;
	else
		rpd(i, 3, MAX_A, 2) if(sum_array(C, i, MAX_A, i) > 1){ t = 1; break; }
	cout<< vector<string>{"pairwise","setwise","not"}[t] <<" coprime\n";
}


Measured memory_bytes: 7148
#include<bits/stdc++.h>
#define ll long long
using namespace std;
inline ll read()
{
	ll ans=0;ll a=1;char c=getchar();
	for(;c<'0'||c>'9';c=getchar())if(c=='-')a=-1;
	for(;c>='0'&&c<='9';c=getchar())ans=ans*10+c-48;
	return ans*a;
}
ll a[2001][2001],maxx;
vector<ll> p[2001];
ll se[2001],fi[2001],n,k,cnt;
void dfs(ll root,ll fa,ll poi,ll s)
{
	a[root][poi]=s;
	for(ll i=0;i<p[poi].size();i++) 
	{
		ll x=p[poi][i];
		if(x==fa)
		{
			continue ;
		}
		dfs(root,poi,x,s+1);
	}
}
int main()
{
//	freopen(".in","r",stdin);
//	freopen(".out","w",stdout);
	maxx=INT_MAX;
	n=read();
	k=read();
	for(ll i=1;i<n;i++)
	{
		ll x=read();
		ll y=read();
		p[x].push_back(y);
		p[y].push_back(x);
		fi[i]=y;
		se[i]=x;
	}
	for(ll i=1;i<=n;i++)
	{
		dfs(i,-1,i,0);
	}
	for(ll i=1;i<=n;i++)
	{
		ll cnt=0;
		for(ll j=1;j<=n;j++)
		{
			if(2*a[i][j]>k)cnt++;
		}
		maxx=min(maxx,cnt);
	}
	for(ll i=1;i<n;i++)
	{
		cnt=0;
		for(ll j=1;j<=n;j++)
		{
			if(2*(min(a[j][fi[i]],a[j][se[i]]))+1>k)
			cnt++;
		}
		maxx=min(maxx,cnt);
	}
	cout<<maxx<<endl;
	return 0;
}

Measured memory_bytes: 31872
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <cstring>
#include <map>
#include <queue>
#include <cmath>
#include <complex> // complex<double> a(1.2 , 2.3);// real(): 1.2, imag()2.3
using namespace std;

#define MOD 1000000007
#define ll long long
#define ld long double
#define FOR(i,a,b) for(ll i=(ll)a;i<(ll)b;i++)
#define rep(i,n) FOR(i,0,n)
#define pb push_back
#define mp make_pair
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rmsame(a) sort(all(a)),a.erase(unique(all(a)), a.end())
#define rmvector(a,b) rep(i,a.size())rep(j,b.size())if(a[i]==b[j]){a.erase(a.begin()+i);i--;break;}
template<typename X> bool exist(vector<X> vec, X item){return find(all(vec), item)!=vec.end();}
ll gcd(ll a, ll b){if(b==0)return a;return gcd(b,a%b);}
ll lcm(ll a, ll b){return a/gcd(a,b)*b;}



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

  ll N, L; cin >> N >> L ;
  vector<string> S;
  rep(i,N){
    string inp; cin >> inp;
    S.pb(inp);
  }
  sort(all(S));

  rep(i,S.size()){
    cout << S[i];
  }
  cout << endl;
  //cout << fixed << setprecision(16) << ans << endl;
  return 0;
}


Measured memory_bytes: 256
import java.util.*;
import java.io.*;
import java.math.*;

class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int h = sc.nextInt();
		int w = sc.nextInt();
		int[][] map = new int[h][w];
		for(int i = 0; i < h; i++) {
			char[] in = sc.next().toCharArray();
			for(int j = 0; j < w; j++) {
				map[i][j] = in[j] - '0';
			}
		}
		int[][] dp = new int[h][w];
		for(int i = 0; i < h; i++) {
			Arrays.fill(dp[i], 2 << 27);
		}
		dp[0][0] = 0;
		for(int i = 0; i < h; i++) {
			for(int j = 0; j < w; j++) {
				if(i != h-1) {
					dp[i+1][j] = Math.min(dp[i][j] + map[i+1][j], dp[i+1][j]);
				}
				if(j != w-1) {
					dp[i][j+1] = Math.min(dp[i][j] + map[i][j+1], dp[i][j+1]);
				}
			}
		}
		
		System.out.println(dp[h-1][w-1]);
		
		
		
		
		
		
		
	}
}

Measured memory_bytes: 17408
#include <bits/stdc++.h>
#define rep(i, s, n) for (int i = (s); i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define debug(x) cout<<#x<<": "<<x<<endl
using namespace std;
using ll = long long;
const ll MOD = 1e9+7;
const ll LINF = LLONG_MAX;
const int INF = INT_MAX;
const double PI=acos(-1);
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; }

int main(){
	int a,b,c; cin>>a>>b>>c;
	int k; cin>>k;
	for(int bit = 0; bit < (1 << k); bit++){
		int bb = b;
		int cc = c;
		for(int j = 0; j < k; j++){
			if(bit & (1 << j)){
				bb *= 2;
			}else{
				cc *= 2;
			}
			if(a < bb and bb < cc){
				cout<<"Yes"<<endl;
				return 0;
			}
		}
	}
	cout<<"No"<<endl;
}

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

typedef long ELEM;

#define QUEUE_SIZE 100000

struct process{
	char* name;
	ELEM time;
};

struct process queue[QUEUE_SIZE];

int n;
int front;
int rear;

#define next(a) ((a+1) % QUEUE_SIZE)

void error(char *s);
void init();
struct process dequeue();
void enqueue(char *s, ELEM x);
int empty();

int main(void){
	int i,j;
	long x;
	struct process temp;
	int n, q, elap=0;
	char s[10];

	init();

	scanf("%d",&n);
	scanf("%d",&q);

	for(i=0;i<n;i++){
		scanf("%s %ld",s, &x);
		enqueue(s,x);
	}

	while(1){
//		fprintf(stderr, "check1\n");
		temp=dequeue();
		if(temp.time>q){
			enqueue(temp.name,temp.time-q);	
			elap+=q;
//			fprintf(stderr, "check2\n");
		}else{
			elap+=temp.time;
//			fprintf(stderr, "check3\n");
			printf("%s %d\n",temp.name, elap);
		}
		if(empty()){
//			fprintf(stderr, "check4\n");
			break;
		}
	}

	return 0;
}

void error(char *s){
	fprintf(stderr,"%s\n",s);
	exit(1);
}

void init(){
	front=rear=0;
}

struct process dequeue(){
	struct process x;
	if(front == rear) error("queue underflow");
	x = queue[front];
	front = next(front);
	return x;
}

void enqueue(char* s,ELEM x){
	if(next(rear) == front) error("queue overflow");
	queue[rear].name = (char*)malloc(sizeof(char)*strlen(s));
	strcpy(queue[rear].name,s);
	queue[rear].time = x;
	rear = next(rear);
}

int empty(){
	return front == rear;
}

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

char F[102][102];

void DFS1(int Y,int X){
    if(F[Y][X]!='@')return;
        
    F[Y][X]='.';
    
    DFS1(Y-1,X  );
    DFS1(Y  ,X-1);
    DFS1(Y  ,X+1);
    DFS1(Y+1,X  );
}

void DFS2(int Y,int X){
    if(F[Y][X]!='#')return;
        
    F[Y][X]='.';
    
    DFS2(Y-1,X  );
    DFS2(Y  ,X-1);
    DFS2(Y  ,X+1);
    DFS2(Y+1,X  );
}

void DFS3(int Y,int X){
    if(F[Y][X]!='*')return;
        
    F[Y][X]='.';
    
    DFS3(Y-1,X  );
    DFS3(Y  ,X-1);
    DFS3(Y  ,X+1);
    DFS3(Y+1,X  );
}

int main(){
    int N,M;
    cin >> N >> M;
    while(N!=0&M!=0){
        for(int y=1;y<=N;y++){
            for(int x=1;x<=M;x++){
                cin >> F[y][x];
            }
        }

        int count = 0;
        for(int y=1;y<=N;y++){
            for(int x=1;x<=M;x++){
                if(F[y][x]=='@'){
                    count++;
                    DFS1(y,x);
                }
            }
        }
        for(int y=1;y<=N;y++){
            for(int x=1;x<=M;x++){
                if(F[y][x]=='#'){
                    count++;
                    DFS2(y,x);
                }
            }
        }
        for(int y=1;y<=N;y++){
            for(int x=1;x<=M;x++){
                if(F[y][x]=='*'){
                    count++;
                    DFS3(y,x);
                }
            }
        }
        cout << count <<endl;
        cin >> N >> M;
    }
    return 0; 
}

Measured memory_bytes: 3544
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplication7
{
    class Program
    {
        static void Main(string[] args)
        {
                int total;
                total = int.Parse(System.Console.ReadLine());
                int[] price = new int[total];
                int totalprice = 0;
                for (int i = 0; i < total; i++)
                {
                price[i] = int.Parse(System.Console.ReadLine());
            }
                Array.Sort(price);
                for (int i = 0; i < total; i++)
                {
                    if (i == total - 1) { totalprice += price[i] / 2; }
                    else { totalprice += price[i]; }
                }
                System.Console.WriteLine(totalprice);
            }
        }



    }

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

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

    int a,b;

    for(int i = 0; i < n; ++i){
        cin >> a;
        if(a == 1)b = i;
    }

    if(n <= k){
        cout << 1 << endl;
        return 0;
    }

    if(n <= 2*k){
        cout << 2 << endl;
        return 0;
    }

    if(b = 0){
        cout << int((n - 1 - b) / (k - 1) + 0.9) << endl;
        return 0;
    }

    cout << int(b / double(k - 1) + 0.9) + int((n - 1 - b) / double(k - 1) + 0.9) << endl;;



}

Measured memory_bytes: 256
import java.io.PrintWriter

fun main(args: Array<String>) {
    PrintWriter(System.out).use { out ->
        solve(out)
        out.flush()
    }
}

fun solve(out: PrintWriter) {
    val n = readInteger()
    val tList = readIntegerList()
    val vList = readIntegerList().map { it * 10 }

    val times = tList.sum() * 2 + 1
    val maxVs = IntArray(times) { Int.MAX_VALUE }
    maxVs[0] = 0
    maxVs[times - 1] = 0
    var curT = 0
    for ((i, t) in tList.withIndex()) {
        for (j in 0..(2 * t)) {
            if (curT + j in 0 until times) {
                maxVs[curT + j] = Math.min(maxVs[curT + j], vList[i]) // 境界値難しい...
            }
        }
        curT += 2 * t
    }

    for (i in 0 until (times - 1)) {
        maxVs[i + 1] = Math.min(maxVs[i + 1], maxVs[i] + 5)
    }

    for (i in (times - 1) downTo 1) {
        maxVs[i - 1] = Math.min(maxVs[i - 1], maxVs[i] + 5)
    }

    var ans = 0
    var preV = maxVs.first()
    for (v in maxVs.drop(1)) {
        ans += preV + v
        preV = v
    }
    println(ans / 40.0)
}

fun readInteger() = readLine()!!.toInt()
fun readLong() = readLine()!!.toLong()
fun readStringList() = readLine()!!.split(" ")
fun readIntegerList() = readStringList().map(String::toInt)
fun readLongList() = readStringList().map(String::toLong)
fun readDoubleList() = readStringList().map(String::toDouble)


Measured memory_bytes: 40820
from collections import Counter
import math

def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

n=int(input())
a=list(map(int,input().split()))
c=Counter(a)
com=0
for i in range(1,n+1):
    if(c[i]<=1):
        continue
    com+=combinations_count(c[i],2)
for k in range(1,n+1):
    ans=com
    ans-=c[a[k-1]]-1
    print(ans)


Measured memory_bytes: 117072
#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 inf LLONG_MAX
#define all(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;


int main()
{
    ll n, m; cin >> n >> m;
    if (n == 1 || m == 1) {
        if (n == 1 && m == 1) cout << 1 << endl;
        else cout << max(0ll, n * m - 2) << endl;
    } else {
        cout << max(0ll, (n - 2) * (m - 2)) << endl;
    }
    return 0;
}

Measured memory_bytes: 256
h,w = gets.split.map(&:to_i)
ary = []
for i in 0..h-1 do
  ary << gets.chomp.split("")
end

dh = [-1, 0, 1, -1 , 1, -1, 0, 1]
dw = [-1, -1, -1, 0, 0, 1, 1, 1]

ary.each_with_index do |a, ix|
  a.each_with_index do |b, jx|
    c = 0
    if b == "#"
      print "#"
      next
    end 
    for d in 0..dh.size-1 do
      wj = ix + dw[d]
      hj = jx + dh[d]
      if wj >= 0 and wj < ary.size and hj >= 0 and hj < a.size
        c += 1 if ary[wj][hj] == "#"
      end
    end
    print c
  end
  print "\n"
end

Measured memory_bytes: 2172
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define fir first
#define sec second
#define MOD 1000000007
#define vvi vector<vector<int> >
#define vvs vector<vector<string> >
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) (a*b)/gcd(a,b)
#define pb push_back
#define vi vector<int>
#define test(t) int t; cin>>t; while(t--)
#define vl vector<ll>
#define vb vector<bool>
#define vs vector<string>
#define vvl vector<vl>
#define loopin(i, n) for(int i = 0; i < (n); i++)
#define loopdec(i, n) for(int i = n-1; i >= 0; i--)
const int mod=1e9+7;


void solve() {
     ll n;
     cin>>n;
     ll count=0;
     for(int i=1;i<n;i++){
        int j=1;
        while(i*j<n){
        count++;
        j++;
      }
      }
      cout<<count<<endl;

    }


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

   solve();

   

return 0;
}


Measured memory_bytes: 3648
use proconio::input;

fn main() {
    input! {
        n: usize,
        k: usize,
        s: usize,
        t: usize,
        a: [usize; n]
    };
    let b = a.iter().filter(|&v| v&s == s && v|t == t ).map(|&v| v^s).collect::<Vec<usize>>();
    let mut comb = [[0 as i64; 51]; 51];
    let mut valid = [0; 51];
    for i in 1..=50 {
        comb[i][0] = 1;
        for j in 1..i {
            comb[i][j] = comb[i-1][j-1] + comb[i-1][j];
        }
        comb[i][i] = 1;
        for j in 1..=std::cmp::min(i, k) {
            valid[i] += comb[i][j];
        }
    }
    let mut res = valid[b.len()];
    let mut cnt = [0; 1<<18];
    let mask = t^s;
    for i in 1..1<<18 {
        if i|mask != mask { continue }
        let sgn = if i.count_ones()%2 == 1 { -1 } else { 1 };
        for &v in &b { cnt[v&i] += 1; }
        for &v in &b {
            if cnt[v&i] == 0 { continue }
            res += sgn * valid[cnt[v&i]];
            cnt[v&i] = 0;
        }
    }
    println!("{}", res);
}


Measured memory_bytes: 4236
h,w=map(int,input().split())
ha=0
wa=0
for i in range(h):
  s=list(map(str,input().split()))
  for j in range(w):
    if s[j]=="snuke":
      wa=j
      ha=i+1
      break
ans=["A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"]
print(ans[wa]+str(ha))

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

int main() {
    // b の和は別で管理
    // a_n を左半分(降順)と右半分(昇順)で2つヒープを作る
    // 左半分の要素の数 >= 右半分の要素の数 で差は0か1
    // これで左半分の最大値が求める x になる
    // \sum abs(x-a_n) の値はヒープの維持と同時に更新

    int Q;
    cin >> Q;
    ll aSum = 0; // \sum abs(x-a_n)
    ll bSum = 0; // \sum b_n
    priority_queue<int> queL; // 左半分の降順ヒープ
    priority_queue<int, vector<int>, greater<int>> queR; // 右半分の昇順ヒープ

    int type, a, b;
    cin >> type >> a >> b;
    queL.push(a);
    bSum += b;

    for (int i = 1; i < Q; ++i) {
        cin >> type;
        if(type == 1){
            cin >> a >> b;
            bSum += b;
            // 2つのヒープのサイズの合計が偶数か奇数か, aがqueL.top()以上かどうかで場合分け
            if(queL.size() == queR.size()){
                if(queL.top() > a){
                    aSum = aSum + (queL.top() - a);
                    queL.push(a);
                } else{
                    queR.push(a);
                    int minR = queR.top(); // これが次の queL.top() になる
                    queR.pop();
                    // 閉区間[queL.top(), minR]でf'(x) = 0 なので変更なし
                    aSum = aSum + (a - minR); // aの追加分
                    queL.push(minR);
                }
            } else{
                if(queL.top() > a){
                    queL.push(a);
                    int maxL = queL.top();
                    queL.pop();
                    // 閉区間[queL.top(), maxL]でf'(x) = -1
                    aSum = aSum + (maxL - queL.top());
                    aSum = aSum + (queL.top() - a); // aの追加分
                    queR.push(maxL);
                } else{
                    aSum = aSum + (a - queL.top());
                    queR.push(a);
                }
            }
        } else if(type == 2){
            cout << queL.top() << " " << aSum + bSum << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 3452
#include <bits/stdc++.h>
using namespace std;
#include <math.h>
#include <iomanip>
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

const int mod=1000000007;
const int INF=1001001001;


int main() {
  vector<char>t(4);
  for(int i=0;i<4;i++){
    cin>>t[i];
  }
  for(int s=0;s<(1<<3);s++){
    string q;q+=t[0];
    int sum=t[0]-'0';
    for(int i=0;i<3;i++){
      if((s>>i)&1){sum+=t[i+1]-'0';q+='+';q+=t[i+1];}
      else{sum-=t[i+1]-'0';q+='-';q+=t[i+1];}
    }
    if(sum==7){cout<<q<<"=7"<<endl;return 0;}
  }
  return 0;  
}

Measured memory_bytes: 3552
while True:
  h, w = map(int, input().split())
  if h == 0 and w == 0:
    break
  for i in range(h):
    if i == 0 or i == h-1:
      print("#"*w)
    else:
      print("#", end = "")
      print("."*(w-2), end = "")
      print("#")
  print()


Measured memory_bytes: 5636
#include <algorithm>
#include <iostream>
#include <vector>
#include <math.h>
#include <set>
#include <map>
#include <string>
#include <stack>
#include <queue>
#include <iomanip>
#include <numeric>
#include <tuple>
#include <bitset>
#include <complex>
#include <unistd.h>
#include <cassert>
#include <cctype>
#include <random>
#include <time.h>
#define _USE_MATH_DEFINES
#define _GLIBCXX_DEBUG
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> plglg;
typedef pair<double, ll> pdlg;
typedef tuple<int, int, int> tiii;
typedef tuple<ll, ll, ll> tlglglg;
typedef tuple<double, double, double> tddd;
typedef complex<double> xy_t;
typedef vector<ll> vll;
typedef vector< vector<ll> > matrix;
#define REP(i, x, y) for(ll i = (ll)x; i < (ll)y; i++)
#define DREP(i, x, y, d) for(ll i = (ll)x; i < (ll)y; i += (ll)d)
#define PER(i, x, y) for(ll i = (ll)x; i > (ll)y; i--)
#define DPER(i, x, y, d) for(ll i = (ll)x; i > (ll)y; i -= (ll)d)
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
double pi = 3.141592653589793;
ll mod = 1000000007;
int intmax = 2147483647;
int intmin = -2147483648;
ll llmax = 9223372036854775807;
ll llmin = -9223372036854775807;
int iinf = intmax / 8;
ll inf = llmax / 8;
double eps = 1e-11;

ll multiply(ll x, ll y) {
    return (x % mod) * (y % mod) % mod;
}

int main() {
    ll N, M;
    cin >> N >> M;
    ll A[N + 1], B[M + 1];
    REP(i, 0, N) {
        cin >> A[i];
    }
    REP(i, 0, M) {
        cin >> B[i];
    }
    sort(A, A + N);
    reverse(A, A + N);
    A[N] = -100;
    sort(B, B + M);
    reverse(B, B + M);
    B[M] = -100;
    bool ok = true;
    REP(i, 1, N) {
        if (A[i] == A[i - 1]) {
            ok = false;
        }
    }
    REP(i, 1, M) {
        if (B[i] == B[i - 1]) {
            ok = false;
        }
    }
    if (A[0] != N * M || B[0] != N * M) {
        ok = false;
    }
    if (!ok) {
        cout << 0 << endl;
        return 0;
    }
    ll ans = 1;
    ll res = 0;
    ll rownum = 1;
    ll colnum = 1;
    PER(i, N * M - 1, 0) {
        if (A[rownum] == i) {
            res += colnum;
            rownum++;
            if (B[colnum] == i) {
                res += rownum;
                colnum++;
                res--;
            } else {
                ans = multiply(ans, colnum);
                res--;
            }
        } else {
            if (B[colnum] == i) {
                res += rownum;
                colnum++;
                ans = multiply(ans, rownum);
                res--;
            } else {
                ans = multiply(ans, res);
                res--;
            }
        }
        //cout << ans << endl;
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{

  int a,b;

  scanf("%d %d", &a ,&b);

  if(a < b) printf("a < b\n");
  if(a == b) printf("a == b\n");
  if(a > b) printf("a > b\n");

  return 0;

}

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

using namespace std;

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define eb emplace_back

typedef long long ll;

const ll mod = 1000000007;
const double pi = 3.1415926535897932384626;

ll powmod(ll a, ll b) {ll res = 1; ll rem = a % mod; for (; b; b >>= 1) {if (b & 1) res = (res * rem) % mod; rem = (rem * rem) % mod;} return res;}

const int N = 108;

char hey[N];
string ara[N];

int main()
{
    //freopen("in", "r", stdin);
    //freopen("out", "w", stdout);
    
    int n = 0;
    int l = 0;
    scanf("%d %d\n", &n, &l);

    for (int i = 1; i <= n; ++i) {
	scanf("%s\n", hey);
	ara[i] = string(hey);
    }

    sort(ara + 1, ara + n + 1);

    for (int i = 1; i <= n; ++i) {
	printf("%s", ara[i].c_str());
    }

    puts("");

    return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#ifdef _DEBUG
#include "dump.hpp"
#else
#define dump(...)
#endif

//#define int long long
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9) + 7;
template<class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return true; } return false; }

struct Dinic {
	using Flow = int;
	struct Edge {
		int to, rev;
		Flow cap;
		Edge() {}
		Edge(int to, int rev, Flow cap) :to(to), rev(rev), cap(cap) {}
	};
	int n;
	vector<vector<Edge>> g;
	vector<bool> used;
	vector<int> level;
	vector<int> iter;
	Dinic(int n) :n(n), g(n), used(n), level(n), iter(n) {};
	void addArc(int from, int to, Flow cap) {
		g[from].emplace_back(to, (int)g[to].size(), cap);
		g[to].emplace_back(from, (int)g[from].size() - 1, 0);
	}
	void addEdge(int a, int b, Flow cap) {
		g[a].emplace_back(b, (int)g[b].size(), cap);
		g[b].emplace_back(a, (int)g[a].size() - 1, cap);
	}
	Flow maximumFlow(int s, int t) {
		Flow total = 0;
		while (true) {
			levelize(s);
			if (level[t] < 0)return total;
			fill(iter.begin(), iter.end(), 0);
			Flow f;
			while (true) {
				f = augment(s, t, INF);
				if (f == 0)break;
				total += f;
			}
		}
	}
	Flow augment(int v, int t, Flow f) {
		if (v == t)return f;
		for (int &i = iter[v]; i < g[v].size(); i++) {
			Edge &e = g[v][i];
			if (e.cap > 0 && level[v] < level[e.to]) {
				Flow d = augment(e.to, t, min(f, e.cap));
				if (d > 0) {
					e.cap -= d;
					g[e.to][e.rev].cap += d;
					return d;
				}
			}
		}
		return 0;
	}
	void levelize(int s) {
		fill(level.begin(), level.end(), -1);
		queue<int> q;
		level[s] = 0;
		q.push(s);
		while (q.size()) {
			int v = q.front(); q.pop();
			for (int i = 0; i < g[v].size(); i++) {
				Edge &e = g[v][i];
				if (e.cap > 0 && level[e.to] < 0) {
					level[e.to] = level[v] + 1;
					q.push(e.to);
				}
			}
		}
	}
};

signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	for (int N; cin >> N&&N;) {
		int M; cin >> M;
		Dinic dinic(M + N + 2);
		int s = dinic.n - 2, t = s + 1;
		unordered_map<int, int> mp;
		rep(i, 0, M) { int d; cin >> d; mp[d] = i; }
		rep(i, 0, N) {
			int m; cin >> m;
			rep(j, 0, m) {
				int d; cin >> d;
				if (mp.count(d))
					dinic.addArc(mp[d], M + i, 1);
			}
		}
		rep(i, 0, M)dinic.addArc(s, i, 1);
		rep(i, 0, N)dinic.addArc(M + i, t, 1);
		cout << dinic.maximumFlow(s, t) << endl;
	}
	return 0;
}

Measured memory_bytes: 3288
#include<iostream>
using namespace std;
int main(){
  long long a,b,c,d;
  long long ans;
  cin>>a>>b>>c>>d;
  if(a*c>=a*d){
    ans=a*c;
    if(a*c<=b*c) ans=b*c;
    if(a*c<=b*d&&b*d>=b*c) ans=b*d;
  }
  else if(a*c<a*d){
    ans=a*d;
    if(a*d<=b*d) ans=b*d;
    if(a*d<=b*c&&b*d<=b*c) ans=b*c;
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 3628