akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <iostream>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <map>
#include <set>

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

using namespace std;

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

  int h, w;
  cin >> h >> w;

  char maze[10][10];

  rep(y, h) {
    cin >> maze[y];
  }
  int cnt = 0;
  rep(y, h) {
    rep(x, w) {
      if (maze[y][x] == '#') cnt++;
    }
  }
  cout << ((cnt == h+w-1) ? "Possible" : "Impossible") << endl;

  return 0;
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline
#n = int(input()) 
n,x = (int(i) for i in input().split())
l= [int(i) for i in input().split()]

cnt=0
d=0
i=0
for i in range(n):
    d=d+l[i]
    if d <=x:
        cnt+=1
print(cnt+1)

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

vector<int> diffgene(int a, int b, int c) {
  vector<int> vec(2);
  vec.at(0) = a - b;
  vec.at(1) = b - c;
  
  return vec;
}

vector<int> input() {
  vector<int> vec(3);
  for (int i = 0; i < 3; i++) {
    cin >> vec.at(i);
  }
  return vec;
}

int main() {
  vector<int> A1,A2,A3;
  A1 = input();
  A2 = input();
  A3 = input();
  
  int n = 0;
  
  vector<int> A1diff(2), A2diff(2), A3diff(2), B1diff(2), B2diff(2), B3diff(2);
  
  
  A1diff = diffgene(A1.at(0), A1.at(1), A1.at(2));
  
  A2diff = diffgene(A2.at(0), A2.at(1), A2.at(2));
  
  A3diff = diffgene(A3.at(0), A3.at(1), A3.at(2));
  
  B1diff = diffgene(A1.at(0), A2.at(0), A3.at(0));
  
  B2diff = diffgene(A1.at(1), A2.at(1), A3.at(1));
  
  B3diff = diffgene(A1.at(2), A2.at(2), A3.at(2));
  
  if (A1diff != A2diff || A2diff != A3diff || B1diff != B2diff || B2diff != B3diff) n++;
  
  if (n) cout << "No" << endl;
  else cout << "Yes" << endl;
}


Measured memory_bytes: 256
#include<stdio.h>
#define N 200000

main(){
  int i,a,b[N],Max=0,Min=0;
  scanf("%d",&a);
  for(i=0;i<a;i++){
    scanf("%d",&b[i]);
  }
  Min = b[0];
  Max = b[1]-b[0];
  for(i=1;i<a;i++){
    if(Max < b[i]-Min){
      Max = b[i]-Min;
    }
    if(Min > b[i]){
      Min = b[i];
    }
  }
  printf("%d\n",Max);
  
  return 0;
}

Measured memory_bytes: 1376
#define __USE_MINGW_ANSI_STDIO 0
#include <bits/stdc++.h>

using namespace std;
using ll = long long;
#define int ll
using VI = vector<int>;
using VVI = vector<VI>;
using PII = pair<int, int>;

#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
#define PB push_back

const ll LLINF = (1LL<<60);
const int INF = (1LL<<30);
const int MOD = 1000000007;

template <typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }
template <typename T> bool IN(T a, T b, T x) { return a<=x&&x<b; }
template<typename T> T ceil(T a, T b) { return a/b + !!(a%b); }
template<class S,class T>
ostream &operator <<(ostream& out,const pair<S,T>& a){
  out<<'('<<a.first<<','<<a.second<<')';
  return out;
}
template<class T>
ostream &operator <<(ostream& out,const vector<T>& a){
  out<<'[';
  REP(i, a.size()) {out<<a[i];if(i!=a.size()-1)out<<',';}
  out<<']';
  return out;
}

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

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

  int n;
  cin >> n;
  string s;
  cin >> s;

  // sum_r[i] = ([0,i]の'>'の個数)
  // sum_l[i] = ([i,n-1]の'<'の個数)
  VI sum_r(n), sum_l(n);
  sum_l[n-1] = s[n-1]=='<'; sum_r[0] = s[0]=='>';
  FOR(i, 1, n) sum_r[i] = sum_r[i-1] + (s[i]=='>');
  for(int i=n-2; i>=0; --i) sum_l[i] = sum_l[i+1] + (s[i]=='<');

  // cout << sum_r << endl << sum_l << endl;

  // pos_r[i] = (左から数えてi番目の'>'の位置)
  // pos_l[i] = (右から数えてi番目の'<'の位置)
  VI pos_r(n), pos_l(n);
  int cnt = 0;
  REP(i, n) if(s[i]=='>') pos_r[cnt++] = i;
  cnt = 0;
  for(int i=n-1; i>=0; --i) if(s[i]=='<') pos_l[cnt++] = i;

  // cout << pos_r << endl << pos_l << endl;

  int ret = 1;
  REP(i, n) {
    // [i+1,n-1]の'<'の数、[0,i-1]の'>'の数
    int lnum = i==n-1?0:sum_l[i+1], rnum = i==0?0:sum_r[i-1];
    if(s[i]=='<') {
      if(lnum>=rnum) chmax(ret, pos_l[lnum-rnum]+1);
      else chmax(ret, n-pos_r[rnum-lnum-1]);
    } else {
      if(rnum >= lnum) chmax(ret, n-pos_r[rnum-lnum]);
      else chmax(ret, pos_l[lnum-rnum-1]+1);
    }
    // cout << "i:" << i << " " << lnum << " " << rnum << " " << ret << endl;
  }
  cout << ret << endl;

  return 0;
}



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

using lint = long long int;
using pint = pair<int, int>;
using plint = pair<lint, lint>;
int main()
{
    lint n, m;
    cin >> n >> m;

    lint ans;

    ans = max(n + m, max(n - m, n * m));

    cout << ans <<"\n";

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> pii;
set<int>s;
struct Node {
  int x, y, color;
  inline bool operator < (const Node & rhs) const {
    return x < rhs.x;
  }
}Node[300];
int n, ans;
int main(void){
  //freopen("data.in", "r", stdin);
  scanf("%d", &n);
  for(int i = 1; i <= n; ++i) scanf("%d%d", &Node[i].x, &Node[i].y), Node[i].color = 1;
  for(int i = 1; i <= n; ++i) scanf("%d%d", &Node[i+n].x, &Node[i+n].y), Node[i+n].color = 2;
  sort(Node+1, Node+1+n*2);
  for(int i = 2*n; i >= 1; --i) {
    //cout << Node[i].x << ' ' << Node[i].y << Node[i].color << '\n';
    if (Node[i].color == 2) s.insert(Node[i].y);
    else  {
      if (s.lower_bound(Node[i].y) != s.end()) s.erase(s.lower_bound(Node[i].y)), ans++;
    }
  }
  cout << ans;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <algorithm>
#include <set>
#include <iostream>
#include <cassert>
#include <queue>
using namespace std;


bool isPrime(int x){
    for(int i = 2; i * i <= x; ++i){
        if(x % i == 0)  return false;
    }
    return true;
}

int main()
{
    int x;
    cin >> x;
    while(!isPrime(x)) x++;
    cout << x << endl;
    return 0;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<cmath>
#include<list>
#include<stack>
#include<queue>
#include<iomanip>
#include<functional>
using namespace std;
typedef long long llong;
int main() {
	int p, q, r;
	string x = "this the that";
	//cout << x.find("the") << endl << x.find("that") << endl << x.find("this") << endl;
	string a = "abcde";
	//cout << (int)a.find("the") << endl << (int)a.find("that") << endl << (int)a.find("this") << endl;
	string s;
	while (getline(cin, s)) {
		//cout << (int)s.find("the") << endl << (int)s.find("that") << endl << (int)s.find("this") << endl;
		for (int j = 0;; j++) {
			p = (int)s.find("the");
			q = (int)s.find("that");
			r = (int)s.find("this");
			//cout << p << q << r << endl;
			if (p >= 0 || q >= 0 || r >= 0) {
				cout << s << endl;
				break;
			}
			for (int i = 0; i < s.size(); i++) {
				if (isalpha(s[i])) {
					if (s[i] == 'z')s[i] = 'a';
					else s[i]++;

				}
			}
		}
	}
	return 0;
}

Measured memory_bytes: 3172
#include <iostream>
#include <string>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <unordered_map>
#include <map>
#include <set>
#include <algorithm>
#include <queue>
#include <stack>
#include <functional>
#include <bitset>
#include <assert.h>
#include <unordered_map>
#include <fstream>
#include <time.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef pair<ll,ll> P;
typedef pair<int,int> pii;
typedef vector<P> vpl;
typedef tuple<ll,ll,ll> tapu;
#define rep(i,n) for(int i=0; i<(n); i++)
#define REP(i,a,b) for(int i=(a); i<(b); i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
const int inf = 1<<30;
const ll linf = 1LL<<62;
const int MAX = 5020000;
ll dy[8] = {1,-1,0,0,1,-1,1,-1};
ll dx[8] = {0,0,1,-1,1,-1,-1,1};
const double pi = acos(-1);
const double eps = 1e-7;
template<typename T1,typename T2> inline bool chmin(T1 &a,T2 b){
	if(a>b){
		a = b; return true;
	}
	else return false;
}
template<typename T1,typename T2> inline bool chmax(T1 &a,T2 b){
	if(a<b){
		a = b; return true;
	}
	else return false;
}
template<typename T> inline void print(T &a){
    rep(i,a.size()) cout << a[i] << " ";
    cout << "\n";
}
template<typename T1,typename T2> inline void print2(T1 a, T2 b){cout << a << " " << b << "\n";}
template<typename T1,typename T2,typename T3> inline void print3(T1 a, T2 b, T3 c){
	cout << a << " " << b << " " << c << "\n";
}
ll pcount(ll x) {return __builtin_popcountll(x);}
const int mod = 1e9 + 7;
//const int mod = 998244353;

vector<int> dfs(int n, int a, int b){
	if(n == 1) return {a,b};
	int pa = pcount(a);
	int pb = pcount(b);
	rep(bit,18){
		if((a>>bit & 1) != (b>>bit & 1)){
			int A = a, B = b;
			REP(b2,bit+1,20){
				A &= ~(1<<(b2-1));
				A |= (1<<(b2-1)) * (a>>b2 & 1);
				B &= ~(1<<(b2-1));
				B |= (1<<(b2-1)) * (b>>b2 & 1);
			}
			bool f = a>>bit & 1;
			int t = 0;
			if(f) t = pa & 1;
			else t = pb & 1;
			auto l = dfs(n-1, A, t);
			auto r = dfs(n-1, t, B);
			for(auto &i : l) for(int b2=17; b2>=bit; b2--){
				i |= (1<<(b2+1)) * (i>>b2 & 1);
				i &= ~(1<<b2);
			}
			for(auto &i : r) for(int b2=17; b2>=bit; b2--){
				i |= (1<<(b2+1)) * (i>>b2 & 1);
				i &= ~(1<<b2);
			}
			if(f) for(auto &i : l) i += 1<<bit;
			else for(auto &i : r) i += 1<<bit;
			l.insert(l.end(), r.begin(), r.end());
			return l; 
		}
	}
}

int main(){
	int n,a,b; cin >> n >> a >> b;
	if(pcount(a) % 2 == pcount(b) % 2){
		cout << "NO" << "\n";
		return 0;
	}
	puts("YES");
	auto ans = dfs(n,a,b);
	print(ans);
}

Measured memory_bytes: 4292
N = int(input())
pt = 1
pa = 1
for _ in range(N):
    t, a = map(int, input().split())
    if t >= pt and a >= pa:
        pt = t
        pa = a
    else:
        tt = pt // t
        if pt % t != 0:
            tt += 1
        aa = pa // a
        if pa % a != 0:
            aa += 1
        k = max(tt, aa)
        pt = t * k
        pa = a * k
print(pt + pa)


Measured memory_bytes: 3060
a,b,c,x,y = gets.chomp.split(" ").map(&:to_i)
total_cost = 0
# aとbを一組作る為の最小コストを求める
cost_a_and_b = [a+b,2*c].min
# aを1枚作る為の最小コストを求める
cost_a = [a,2*c].min
# bを1枚作る為の最小コストを求める
cost_b = [b,2*c].min

total_cost = cost_a_and_b * ([x,y].min)
if x > y
    total_cost = total_cost + cost_a * (x-y)
elsif x < y
    total_cost = total_cost + cost_b * (y-x)
else
    # 何もしない
end
puts total_cost

Measured memory_bytes: 1788
import numpy as np
n = int(input())
p = [int(x) for x in input().split()]

cnt = 0
for i in range(n-1):
  if p[i] == i+1:
    p[i],p[i+1] = p[i+1],p[i]
    cnt += 1

if p[-1]==n:
  cnt += 1
  
print(cnt)



Measured memory_bytes: 23432
import java.io.{BufferedReader, InputStreamReader}

object Main extends App {

  def isMatch(arr:Array[Char], t:String, k:Int):Boolean = {
    for(i <- 0 until t.length) {
      if(t.charAt(i) != arr(i+k) && arr(i+k) != '?')
        return false
    }
    true
  }
  def construct(arr:Array[Char], t:String, k:Int):Unit = {
      for(i <- 0 until t.length) {
        arr(i+k) = t.charAt(i)
      }
  }

  val in = new BufferedReader(new InputStreamReader(System.in))
  val s, t = in.readLine

  val ans = {
    val arr = s.toCharArray
    var isMatched = false

    for(i <- s.length - t.length to 0 by -1) {
      if(!isMatched) {
        if(isMatch(arr, t, i)) {
          construct(arr, t, i)
          isMatched = true
        }
      }
    }

    if(isMatched) {
      for(i <- 0 until s.length) {
        if(arr(i) == '?') {
          arr(i) = 'a'
        }
      }
      arr.mkString
    }
    else "UNRESTORABLE"
  }

  println(ans)
}

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

int main() {
  vector<char> a(4);
  cin >> a.at(0) >> a.at(1) >> a.at(2) >> a.at(3);
  
  int count = 0;
  for(int i=0; i<3; i++) {
    for(int j=i+1; j<4; j++) {
      if(a.at(i) == a.at(j))
        count ++;
    }
  }
  
  if(count == 2)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <algorithm>

using namespace std;

int main() {
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    if ((abs(a - b) <= d && abs(b - c) <= d) || abs(a - c) <= d ) {
        cout << "Yes"; 
    } else cout << "No";
}


Measured memory_bytes: 3596
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);
		double min = Integer.MAX_VALUE;
		double max = Integer.MIN_VALUE;
		while(sc.hasNext()){
			double x = sc.nextDouble();
			min = Math.min(min, x);
			max = Math.max(max, x);
		}
		System.out.println(max-min);
	}

}

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

using namespace std;

#ifdef LOCAL
    #define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
    #define eprintf(...) 42
#endif

using ll = long long;
using ld = long double;
using D = double;
using uint = unsigned int;
template<typename T>
using pair2 = pair<T, T>;
using pii = pair<int, int>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second

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

const int maxn = 505;

queue<pair2<int>> q;
int d[maxn][maxn];
pair2<int> ord[maxn * maxn];
bool isempty[maxn][maxn];
int n;

void upd(int cx, int cy)
{
	int add = (isempty[cx][cy] ? 0 : 1);
	for (int dir = 0; dir < 4; dir++)
	{
		int nx = cx + dx[dir];
		int ny = cy + dy[dir];
		if (nx < 0 || ny < 0 || nx >= n || ny >= n) continue;
		if (d[nx][ny] <= d[cx][cy] + add) continue;
		d[nx][ny] = d[cx][cy] + add;
		q.push({nx, ny});
	}
}

int main()
{
	scanf("%d", &n);
	for (int i = 0; i < n * n; i++)
	{
		int x;
		scanf("%d", &x);
		x--;
		ord[i] = {x / n, x % n};
	}
	for (int i = 0; i < n; i++)
	{
		for (int j = 0; j < n; j++)
		{
			d[i][j] = min({i, j, n - i - 1, n - j - 1});
		}
	}
	int answer = 0;
	for (int i = 0; i < n * n; i++)
	{
		answer += d[ord[i].fi][ord[i].se];
		isempty[ord[i].fi][ord[i].se] = true;
		upd(ord[i].fi, ord[i].se);
		while (!q.empty())
		{
			int cx, cy;
			tie(cx, cy) = q.front();
			q.pop();
			upd(cx, cy);
		}
	}
	cout << answer << endl;
    return 0;
}


Measured memory_bytes: 6880
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
int main() {
  int A[3] = { 10, 10, 10 };
  int n, m, s, c;
  cin >> n >> m;
  rep(i,m)
  {
    cin >> s >> c;
    if (s == 1 && c == 0 && n > 1) {
      cout << -1;
      return 0;
    }
    if (A[s - 1] == 10) {
      A[s - 1] = c;
    } else if (A[s - 1] != c) {
      cout << -1;
      return 0;
    }
  }
  rep(i,n)
    if (A[i] == 10) {
      if (i == 0 && n > 1) {
        A[i] = 1;
      } else {
        A[i] = 0;
      }
    }
  cout << A[0];
  if (n >= 2)
    cout << A[1];
  if (n == 3)
    cout << A[2];
}

Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>

int main (void){
	
	int s[100000]={0};
	int t[100000]={0};
	int a,b,i,j,n1,n2,count=0;
	int left=0,right,mid,m,l,min=10000,minb,box;

	scanf("%d",&n1);
	
	for(i=0;i<n1;i++){
		scanf("%d",&s[i]);
	}
	
	
	for(a=0;a<n1;a++){
		min=1000000001;
		minb=a;
		for(b=a;b<n1;b++){
			if(min>s[b]){
				min = s[b];
				minb=b;
			}
		}
		box = s[a];
		s[a] = s[minb];
		s[minb] = box;
		
	}
	
		
	right=n1-1;
	m=right;
	scanf("%d",&n2);
	for(j=0;j<n2;j++){
		//printf("-------------for ?????\????????? j = %d--------------\n",j);
		l=count;
		left=0;
		right=m;
		//printf(" for s[0]=%d\n",s[0]);
		scanf("%d",&t[j]);
		//printf(" for s[0]=%d\n",s[0]);
		//printf("left=%d,right=%d,l=%d\n",left,right,l);
		
		while(left<=right){
			//printf("-------------while ?????\????????? j = %d--------------\n",j);
			mid = ((left+right)/2);
			//printf("left=%d right=%d mid=%d\n",left,right,mid);
			//printf("t[%d]=%d s[%d]=%d\n",j,t[j],mid,s[mid]);
			if(s[mid]==t[j]){
				//printf("-------------s[mid]==t[%d] ?????\????????? --------------\n",j);
				count++;
				left=mid;
				right=mid;
				//printf("s[0]=%d s[1]=%d s[2]=%d s[3]=%d s{4}=%d\n",s[0],s[1],s[2],s[3],s[4]);
				//printf("count=%d\n",count);
			}else if(s[mid]<t[j]){
				//printf("-------------s[mid]<t[%d] ?????\????????? --------------\n",j);
				left=mid+1;
				//printf("s[0]=%d s[1]=%d s[2]=%d s[3]=%d s{4}=%d\n",s[0],s[1],s[2],s[3],s[4]);
				//printf("left=%d\n",left);
			}else{
				//printf("-------------s[mid]>t[%d] ?????\????????? --------------\n",j);
				right = mid-1;
				//printf("s[0]=%d s[1]=%d s[2]=%d s[3]=%d s{4}=%d\n",s[0],s[1],s[2],s[3],s[4]);
				//printf("right=%d\n",right);
			}
			//printf("last while s[0]=%d\n",s[0]);
		if(l<count)break;
		}
	}
	//printf("-------\n");
	printf("%d\n",count);
	//printf("-------\n");
return 0;
}

Measured memory_bytes: 1392
#include <cstdio>
#include <numeric>
#include <iostream>
#include <vector>
#include <set>
#include <cstring>
#include <string>
#include <map>
#include <cmath>
#include <ctime>
#include <algorithm>
#include <bitset>
#include <queue>
#include <sstream>
#include <deque>
#include <cassert>

using namespace std;

#define mp make_pair
#define pb push_back
#define rep(i,n) for(int i = 0; i < (n); i++)
#define re return
#define fi first
#define se second
#define sz(x) ((int) (x).size())
#define all(x) (x).begin(), (x).end()
#define sqr(x) ((x) * (x))
#define sqrt(x) sqrt(abs(x))
#define y0 y3487465
#define y1 y8687969
#define fill(x,y) memset(x,y,sizeof(x))
#define prev PREV
                         
typedef vector<int> vi;
typedef long long ll;
typedef long double ld;
typedef double D;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef vector<string> vs;
typedef vector<vi> vvi;

template<class T> T abs(T x) { re x > 0 ? x : -x; }

int n;
int m;

vi v[100];
int q[100];
int w[100];
int len;
int cnt[100];
int ea[100];
int eb[100];

int go2 (int x, int p, int cur) {
	if (cur + 1 > len) len = cur + 1;
	int now = 0;
	for (int i = 0; i < sz (v[x]); i++) {
		int y = v[x][i];
		if (y == p) continue;
		go2 (y, x, cur + 1);
		now++;
	}
	cnt[cur] = max (cnt[cur], now);
	re 0;
}

int main () {
	scanf ("%d", &n);
	for (int i = 0; i < n - 1; i++) {
		int a, b;
		scanf ("%d%d", &a, &b); a--; b--;
		v[a].pb (b);
		v[b].pb (a);
		ea[i] = a;
		eb[i] = b;
	}
	pair<int, ll> best (1e9, 1e18);
	for (int i = 0; i < n; i++) {
		len = 0;
		for (int i = 0; i < n; i++) cnt[i] = 0;
		go2 (i, i, 0);
		ll ans = 1;
		for (int i = 0; i < len - 1; i++) ans *= cnt[i];
		best = min (best, mp (len, ans));
	}
	for (int i = 0; i < n - 1; i++) {
		len = 0;
		for (int i = 0; i < n; i++) cnt[i] = 0;
		go2 (ea[i], eb[i], 0);
		go2 (eb[i], ea[i], 0);
		ll ans = 2;
		for (int i = 0; i < len - 1; i++) ans *= cnt[i];
		best = min (best, mp (len, ans));
	}
	cout << best.fi << " " << best.se << endl;
	return 0;
}

Measured memory_bytes: 256
s = gets.chomp
t = gets.chomp

ans = 10000

(s.size - t.size + 1).times do |i|
  cnt = t.size
  t.size.times do |k|
    cnt -= 1 if s[i + k] == t[k]
  end
  ans = [ans, cnt].min
end

puts ans


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

int main(){
	int n ; cin >> n ;
	string s ;
	set<vector<int>> check ;
	vector<vector<int>> cnt(n,vector<int>(26,0)) ;
	for(int i=0;i<n;i++){
		cin >> s ;
		for(int j=0;j<s.size();j++){
			cnt.at(i).at(s.at(j)-'a')++ ;
		}
	}
	vector<int> sub(26,0) ;
	sort(cnt.begin(),cnt.end()) ;
	long long num = 1 ;
	long long  ans = 0 ;
	for(int i=0;i<n;i++){
		if(sub==cnt.at(i)){
			ans += num ;
			num++ ;
		}else{
			sub = cnt.at(i) ;
			num = 1 ;
		}
	}
	cout << ans << endl ;
}

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

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


int main() {
  int N,M;
  ll l,r,d;
  cin >> N >> M;

  vector<vector<vector<ll>>> q(N);
  rep(i,M) {
    scanf("%lld%lld%lld",&l,&r,&d);
    l--;r--;
    q[l].push_back({r,d});
    q[r].push_back({l,-d});
  }
  vector<ll> ans(N);
  vector<int> yet(N,1);
  queue<int> que;
  ans[0] = 0;
  yet[0] = false;
  que.push(0);

  int memo=1;
  bool flag = true;

  while (flag) {
    
    while (!que.empty()) {
      auto t = que.front();
      // cout << t << endl;
      que.pop();
      for (auto v:q[t]) {
        if (yet[v[0]]) {
          yet[v[0]] = 0;
          ans[v[0]] = ans[t] + v[1];
          que.push((int) v[0]);
        }
        else if (ans[v[0]]-ans[t]!=v[1]) {
          cout << "No\n";
          return 0;
        } 
      }
    }

    rep2(i,memo,N) {
      if (i==N-1) flag = false;
      if (yet[i]) {
        ans[i] = 1;
        que.push((int) i);
        yet[i] = 0;
        memo = i+1;
        break;
      }
      
    }
  }

  cout << "Yes" << endl;
} 

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

int main() {
  int N, K, A, B, x;
  int min = 0;
  cin >> N >> K;
  for ( int i = 0; i < N; i++ ) {
    cin >> x;
    A = 2 * x;
    B = 2 * ( K - x );    
    if( A <= B ) 
      min += A;
    else 
      min += B;
  }
  cout << min << endl; 
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,c) for(int i=0;i<c;++i)
int main(){
 string n,k;
 cin >> n >> k;
 if(n[2]==k[0]&&n[1]==k[1]&&n[0]==k[2]){
     cout << "YES" << endl;
 }else{
     cout << "NO" << endl;
 }
  
return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
	int x, y, tmp;
	
	while( (scanf("%d %d", &x, &y) != EOF ) && (x != 0 || y != 0) ){
		if( x > y ){
			tmp = x;
			x   = y;
			y   = tmp;
		}
		printf("%d %d\n", x ,y);
	}
	return 0;
}

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

using namespace std;

const int LIM = 1e+5 + 100;
const int START = 0;

vector<vector<int>> g(LIM);
vector<int> to(LIM);
vector<int> dist(LIM);
int ans = 0;
int n, k;

int dfs(int u) {
  int h = 0;
  for (int v : g[u])
    h = max(h, dfs(v) + 1);
  if (h == k - 1 && to[u] != START) {
    ++ans;
    h = -1;
  }
  return h;
}

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

  if (to[START] != START) {
    ++ans;
    to[START] = START;
  }

  for (int i = START + 1; i < n; ++i)
    g[to[i]].push_back(i);

  dfs(START);

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 11136
import sys
from fractions import gcd
from itertools import groupby as gb
from itertools import permutations as perm
from itertools import combinations as comb
from collections import Counter as C
from collections import defaultdict as dd
sys.setrecursionlimit(10**5)
def y(f):
    if f:
        print('Yes')
    else:
        print('No')
def Y(f):
    if f:
        print('YES')
    else:
        print('NO')

a = list(map(int,input().split()))
a = sorted(a)
print(sum(a[:-1]))

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

int V,E;
vector<int> G[100005];
vector<int> A,B;
bool flg=false;
bool visited[100005];
int depth[100005];
int cnt[2];

void dfs(int pos,int d){
  
  if(visited[pos]){
    if(depth[pos]!=d)flg=true;
    return;
  }
  
  visited[pos]=true;
  depth[pos]=d;
  cnt[d]++;
  
  for(int i=0;i<(int)G[pos].size();i++){
    int to=G[pos][i];
    dfs(to,1-d);
  }
}

typedef long long ll;
int dp[2][100005];

int cc[100005];

ll solve(){
  if(flg)return -1;
  
  map<int,int> mp;
  int sum=0;
  for(int i=0;i<(int)A.size();i++){
    int mn=min(A[i],B[i]);
    int mx=max(A[i],B[i]);
    sum+=mn;
    mp[mx-mn]++;
  }
  
  dp[0][0]=1;
  dp[1][0]=1;
  
  map<int,int>::iterator it;

  int ai=0,bi=1;
  for(it=mp.begin();it!=mp.end();it++){
    swap(ai,bi);
    
    int a=it->first,b=it->second;
    if(a==0)continue;
    
    
    memset(cc,0,sizeof(cc));    
    for(int i=0;i<=V;i++){
      int k=0;
      if(i-a>=0)k+=cc[i-a];
      if(i-a*b-a>=0)k-=cc[i-a*b-a];
      if(k>0 || dp[bi][i]==1)dp[ai][i]=1;
      
      cc[i]=dp[bi][i];
      if(i-a>=0)cc[i]+=cc[i-a];
    }
  }
  ll ans=0;
  for(int i=0;i<=V;i++){
    if(dp[ai][i]>0 || dp[bi][i]>0){
      ans=max(ans, (ll)(i+sum)*(ll)(V-i-sum) );
    }
  }
  return ans-(ll)E;
}

int main(){
  scanf("%d %d",&V,&E);
  for(int i=0;i<E;i++){
    int a,b;
    scanf("%d %d",&a,&b);
    a--,b--;
    G[a].push_back(b);
    G[b].push_back(a);    
  }
  for(int i=0;i<V;i++){
    if(visited[i])continue;
    cnt[0]=cnt[1]=0;
    dfs(i,0);
    A.push_back(cnt[0]);
    B.push_back(cnt[1]);
  }
  cout<<solve()<<endl;
  return 0;
}

Measured memory_bytes: 10916
#include <iostream>
using namespace std;
int main(void){
    int n,j,temp,cnt;
    cin>>n;
    int A[n];
    for(int i=0;i<n;i++){
        cin>>A[i];
    }
    cnt=0;
    j=0;
    while(j<n-1){
        for(int i=n-1;i>j;i--){
            if(A[i]<A[i-1]){
                temp=A[i];
                A[i]=A[i-1];
                A[i-1]=temp;
                cnt++;
            }
        }
        j++;
    }
    
    for(int i=0;i<n;i++){
        cout<<A[i];
        if(i==n-1)cout<<endl;
        else cout<<' ';
    }
    cout<<cnt<<endl;
    return 0;
}



Measured memory_bytes: 3100
#include <stdio.h>

int main()
{
    long long int n;
    
    scanf ("%lld",&n);
    char out[100]={0};
    int i=0;
    
    n--;
    while(n>=0){
        out[i]= n%26 +'a';
        n/=26;
        i++;
        n--;
    }
    for(int j=i-1; j>=0; j--){
        printf("%c",out[j]);
    }
    return 0;
}

Measured memory_bytes: 3140
n = int(input())
h = list(map(int,input().split()))
c_max = 0
count = 0
for i in range(n-1):
    if h[i] >= h[i+1]:
        count += 1
    else:
        c_max = max(count, c_max)
        count = 0
print(max(c_max, count))

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

long long int gcd(long long int a,long long int b){
  if(a%b==0) return b;
  else return gcd(b,a%b);
}

int main(){
  long long int a,b,c,d;
  cin >> a >> b >> c >> d;
  a--;
  long long int hiku,tasu,saisyou;
  saisyou = c*d/gcd(c,d);
  hiku = a/c+a/d-a/saisyou;
  tasu = b/c+b/d-b/saisyou;
  tasu -= hiku;
  b = b-a-tasu;
  cout << b << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep2(i, x ,n) for(int i = x; i < n; i++)
#define repr(i, n) for(int i = n; i >= 0; i--)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
int main(){
    string a,b;
    cin >> a >> b;
    
    if(a==b)cout << "EQUAL";
    
    else if(a.size()!=b.size())cout << ((a.size()>b.size())?"GREATER":"LESS");
    
    else{
        rep(i,a.size()){
            if(a[i]!=b[i]){
                cout << ((a[i]-'0'>b[i]-'0')?"GREATER":"LESS");
                return 0;
            }
        }
    }
    
    return 0;
}

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

using namespace std;


int main() {
    int n;
    cin >> n;
    for(int i = 0; i < n; i++) {
        char c;
        cin >> c;
        if(c == 'Y') {
            puts("Four");
            return 0;
        }
    }
    puts("Three");
    return 0;
}

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

using namespace std;

#define FOR(i,n) for(int i=0; i<n; ++i)
#define FORR(i,a,n) for(int i=a; i<n; ++i)
#define ALL(c) (c).begin(), (c).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef vector<string> VS;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;
 
//int in() { int x; scanf("%d", &x); return x; }
//ll lin() { ll x; scanf("%lld", &x); return x; }
//void printfv(VI a){ int n = a.size(); FOR(i, n) cout << a[i] << " "; }

int main(void){

	int n, l, x;
  	cin >> n >> x;

  	int ans = 1, d = 0;
  	FOR(i, n){
  		cin >> l;
  		d += l;

  		if(d <= x) ans += 1;
  	}



  	cout << ans;

  	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<cassert>
#include<iterator>
#include<complex>
#include<stack>
#include<sstream>
using namespace std;
typedef  long long int lint;
typedef pair<int, int> P;
typedef pair<lint, lint> LLP;
typedef pair<char, char>CP;
#define rep(i, n) for (int i = 0; i < n; i++)
#define repr(i, n) for (int i = n; i >= 0; i--)
#define sort(v) sort((v).begin(), (v).end())
#define reverse(v) reverse((v).begin(), (v).end())
#define upper(v,hoge) upper_bound(v.begin(),v.end(),hoge)
#define lower(v,hoge) lower_bound(v.begin(),v.end(),hoge)
#define llower(v,hoge) *lower_bound(v.begin(), v.end(), hoge)
#define lupper(v,hoge) *upper_bound(v.begin(), v.end(), hoge)
/*
vector<char>al(26);
al = {'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'};
vector<char>AL(26);
AL = {'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'};
vector<char>NUM(10);
	NUM = { '0','1','2' ,'3' ,'4' ,'5' ,'6' ,'7' ,'8' ,'9' };
*/



int main() {
	int A, B, X;
	cin >> A >> B >> X;
	if (A <= X && X <= A + B) {
		cout << "YES" << endl;
	}
	else {
		cout << "NO" << endl;
	}
}

Measured memory_bytes: 256
h,w,a,b = map(int,input().split())
ans = []

for i in range(h):
  if i+1 <= b:
    s = "0"*a + "1"*(w-a)
  else:
    s = "1"*a + "0"*(w-a)
    
  ans.append(s)
  
for i in range(h):
  print(ans[i])

Measured memory_bytes: 4980
#define _USE_MATH_DEFINES 
#include<iomanip> 
#include<cmath>  
#include<iostream>
#include<fstream>
#include<vector>
#include<algorithm>
#include<numeric>
#include<bitset>
#include<map>
#include<unordered_map>
#include<set>
#include<unordered_set>
#include<queue>
#include<deque>
#include<stack>
using namespace std;
typedef long long ll;
#define repi(i,a,b) for(ll i = (ll)(a) ; i < (ll)(b) ; i++)
#define repd(i,a,b) for(ll i = (ll)(a) ; i > (ll)(b) ; i--)
#define rd(x) cin >> x
#define wr(x)  cout << x
#define wrln(x) cout << x << endl
#define wl() cout << endl
const ll MAX_10p5 = 100010;
const ll MAX_10p9 = 1000000010;
const ll MAX_10p18 = 1000000000000000010;
const ll MOD = 1000000007;
const ll m4x[4] = { 1,0,-1,0 };
const ll m4y[4] = { 0,1,0,-1 };
const ll m8x[8] = { 1,1,0,-1,-1,-1,0,1 };
const ll m8y[8] = { 0,1,1,1,0,-1,-1,-1 };
const ll m9x[9] = { 1,1,0,-1,-1,-1,0,1,0 };
const ll m9y[9] = { 0,1,1,1,0,-1,-1,-1,0 };

struct edge {
	ll from, to, cost;
	bool operator<(const edge& right) const {
		return cost < right.cost;
	}
};
struct point {
	ll x, y;
	bool operator<(const point& right) const {
		return x == right.x ? y < right.y : x < right.x;
	}
};

///////////////////////////////////////////////////////////////////////////////////////

ll N, W;
ll v[110], w[110];
ll dp[110][10010];

int main() {
	cin >> N >> W;
	repi(i, 0, N) {
		cin >> v[i] >> w[i];
	}
	repi(i, 0, N) {
		repi(j, 0, W + 1) {
			if (i == 0) {
				if (j >= w[i]) dp[i][j] = dp[i][j - w[i]] + v[i];
			}
			else {
				if (j >= w[i]) dp[i][j] = max(dp[i - 1][j], dp[i][j - w[i]] + v[i]);
				else dp[i][j] = dp[i - 1][j];
			}
		}
	}
	ll ans = 0;
	repi(i, 0, W + 1) ans = max(ans, dp[N - 1][i]);
	wrln(ans);
	return 0;
}



Measured memory_bytes: 10920
#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
#include<algorithm>//next_permutation
#define rep(i,n) for (int i = 0;i < (n);i++)
#define all(v) v.begin(),v.end()
#define dec(n) cout << fixed << setprecision(n);
#define large "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
#define small "abcdefghijklmnopqrstuvwxyz"
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using vl = vector<ll>;
using vvl = vector<vl>;

ll gcd(ll a,ll b){
  if(b == 0) return a;
  return gcd(b , a % b);
}

const ll MOD = 1000000007;
const ll MAX = 2000001;

ll mod(ll a){
  return a % MOD;
}

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

ll fac[MAX], finv[MAX], inv[MAX];

void nCrprep() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (ll i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

ll nCr(ll n, ll r){
    if (n < r) return 0;
    if (n < 0 || r < 0) return 0;
    return fac[n] * (finv[r] * finv[n - r] % MOD) % MOD;
}

ll nCrcheep(ll n,ll r){
  if(r == 0) return 1;
  else if(r == 1) return n;
  else return nCrcheep(n-1,r-1)*n/r;
}

vector<pair<ll,ll>> prime_factorize(ll n){
  vector<pair<ll,ll>> res;
  
  for(ll i=2; i*i <= n; i++){
    if(n % i != 0) continue;
    
    ll ex = 0;
    while(n % i == 0){
      ex++;
      n /= i;
    }
    
    res.push_back({i,ex});
  }
  
  if(n != 1) res.push_back({n,1});
  
  return res;
  
}




int main(){
  ll n; string s; cin >> n >> s;
  
 
  ll rcnt,bcnt; rcnt = bcnt = 0;
  
  for(char c : s){
    if(c == 'R') rcnt++;
    else bcnt++;
  }
  
  if(rcnt > bcnt) cout << "Yes" << endl;
  else cout << "No" << endl;
  
  
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define offset 200000
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<int, char> pic;

vector<pic> vrA[600010][2], vrB[600010][2];
vector<pic> vnA[200010], vnB[200010];
int ans = 1e9;

int main() {
    ios_base::sync_with_stdio(0);
    int n; cin >> n;
    for (int i=0;i<n;i++) {
        int x, y; char u; cin >> x >> y >> u;
        if (u=='R') {
            vnA[y].pb({x, 'R'});
            vrA[x-y+offset][0].pb({x+y+offset, 'R'});
            vrB[x+y+offset][0].pb({x-y+offset, 'R'});
        }
        if (u=='L') {
            vnA[y].pb({x, 'L'});
            vrA[x-y+offset][1].pb({x+y+offset, 'L'});
            vrB[x+y+offset][1].pb({x-y+offset, 'L'});
        }
        if (u=='U') {
            vnB[x].pb({y, 'U'});
            vrA[x-y+offset][1].pb({x+y+offset, 'U'});
            vrB[x+y+offset][0].pb({x-y+offset, 'U'});
        }
        if (u=='D') {
            vnB[x].pb({y, 'D'});
            vrA[x-y+offset][0].pb({x+y+offset, 'D'});
            vrB[x+y+offset][1].pb({x-y+offset, 'D'});
        }
    }
    for (int i=0;i<=200000;i++) {
        sort(vnA[i].begin(), vnA[i].end());
        sort(vnB[i].begin(), vnB[i].end());
    }
    for (int i=0;i<=600000;i++) {
        for (int j=0;j<2;j++) {
            sort(vrA[i][j].begin(), vrA[i][j].end());
            sort(vrB[i][j].begin(), vrB[i][j].end());
        }
    }

    for (int i=0;i<=200000;i++) {
        for (int j=1;j<vnA[i].size();j++) {
            if (vnA[i][j-1].se=='R'&&vnA[i][j].se=='L') {
                ans = min(ans, 5*(vnA[i][j].fi-vnA[i][j-1].fi));
            }
        }
        for (int j=1;j<vnB[i].size();j++) {
            if (vnB[i][j-1].se=='U'&&vnB[i][j].se=='D') {
                ans = min(ans, 5*(vnB[i][j].fi-vnB[i][j-1].fi));
            }
        }
    }

    for (int i=0;i<=600000;i++) {
        for (int j=1;j<vrA[i][0].size();j++) {
            if (vrA[i][0][j-1].se=='R'&&vrA[i][0][j].se=='D') {
                ans = min(ans, 5*(vrA[i][0][j].fi-vrA[i][0][j-1].fi));
            }
        }
        for (int j=1;j<vrA[i][1].size();j++) {
            if (vrA[i][1][j-1].se=='U'&&vrA[i][1][j].se=='L') {
                ans = min(ans, 5*(vrA[i][1][j].fi-vrA[i][1][j-1].fi));
            }
        }
        for (int j=1;j<vrB[i][0].size();j++) {
            if (vrB[i][0][j-1].se=='R'&&vrB[i][0][j].se=='U') {
                ans = min(ans, 5*(vrB[i][0][j].fi-vrB[i][0][j-1].fi));
            }
        }
        for (int j=1;j<vrB[i][1].size();j++) {
            if (vrB[i][1][j-1].se=='D'&&vrB[i][1][j].se=='L') {
                ans = min(ans, 5*(vrB[i][1][j].fi-vrB[i][1][j-1].fi));
            }
        }
    }

    if (ans<1e9) cout << ans << endl; else cout << "SAFE\n";
}


Measured memory_bytes: 87664
#include <iostream>
#include <iomanip>
using namespace std;
#define PI 3.14159265358979323846
 
int main(void){
    long double r;
    
    cin >> r;
    r = 2 * r * PI;
    cout << fixed << setprecision(20);
    cout << r << endl;
    
    return 0;
}

Measured memory_bytes: 3776
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
#include<stdio.h>
#include<queue>
#include <climits>
const int mod = 1e9 + 7;
const int INF = 1e9;
using namespace std;
typedef long long ll;

int main()
{
    string a,b;
    cin >> a >> b;
    for(int i = 0; i < 3; i++){
        if(a[i] != b[2-i]){
            cout << "NO";
            return 0;
        }
    }
    cout << "YES";
}

Measured memory_bytes: 256
#include <stdio.h>
#define MAX 10000
#define NIL -1

struct Node {int p, l, r;};
struct Node T[MAX];
int n;

void preParse(int u)
{
    if(u == NIL) return;
    printf(" %d", u);
    preParse(T[u].l);
    preParse(T[u].r);
}

void inParse(int u)
{
    if(u == NIL) return;
    inParse(T[u].l);
    printf(" %d", u);
    inParse(T[u].r);
}

void postParse(int u)
{
    if(u == NIL) return;
    postParse(T[u].l);
    postParse(T[u].r);
    printf(" %d", u);
}

int main()
{
    int v, l, r, root;
    scanf("%d", &n);
    for(int i=0; i<n; i++) T[i].p = NIL;

    for(int i=0; i<n; i++)
    {
        scanf("%d %d %d", &v, &l, &r);
        T[v].l = l;
        T[v].r = r;
        if(l != NIL) T[l].p = v;
        if(r != NIL) T[r].p = v;
    }

    for(int i=0; i<n; i++) if(T[i].p == NIL) root = i;

    printf("Preorder\n");
    preParse(root);
    printf("\n");
    printf("Inorder\n");
    inParse(root);
    printf("\n");
    printf("Postorder\n");
    postParse(root);
    printf("\n");
    return 0;
}


Measured memory_bytes: 2760
#include <cstdio>
#include <algorithm>

using namespace std;

const int N=2100;

int g0[N][N],g1[N][N],g2[N][N],g3[N][N],g4[N][N];
int h0[N][N],h1[N][N],h2[N][N],h3[N][N],h4[N][N];
int i,j,m,n,s,x,y,z;
char c;

int main()
{
	scanf("%d%d",&n,&m);
	for (i=1;i<=n;i++)
	{
		scanf("%d%d",&x,&y);
		z=x/m+y/m;
		x=x%m+1,y=y%m+1;
		getchar(),c=getchar();
		if (z&1)
			if (c=='B')
				c='W';
			else
				c='B';
		if (c=='B')
			g0[x][y]++;
		else
			h0[x][y]++;
	}
	for (i=1;i<=2*m;i++)
		for (j=1;j<=2*m;j++)
			g1[i][j]=g1[i-1][j]+g1[i][j-1]+g0[i][j]-g1[i-1][j-1];
	for (i=2*m;i>0;i--)
		for (j=1;j<=2*m;j++)
			g2[i][j]=g2[i+1][j]+g2[i][j-1]+g0[i][j]-g2[i+1][j-1];
	for (i=1;i<=2*m;i++)
		for (j=2*m;j>0;j--)
			g3[i][j]=g3[i-1][j]+g3[i][j+1]+g0[i][j]-g3[i-1][j+1];
	for (i=2*m;i>0;i--)
		for (j=2*m;j>0;j--)
			g4[i][j]=g4[i+1][j]+g4[i][j+1]+g0[i][j]-g4[i+1][j+1];
	for (i=1;i<=2*m;i++)
		for (j=1;j<=2*m;j++)
			h1[i][j]=h1[i-1][j]+h1[i][j-1]+h0[i][j]-h1[i-1][j-1];
	for (i=2*m;i>0;i--)
		for (j=1;j<=2*m;j++)
			h2[i][j]=h2[i+1][j]+h2[i][j-1]+h0[i][j]-h2[i+1][j-1];
	for (i=1;i<=2*m;i++)
		for (j=2*m;j>0;j--)
			h3[i][j]=h3[i-1][j]+h3[i][j+1]+h0[i][j]-h3[i-1][j+1];
	for (i=2*m;i>0;i--)
		for (j=2*m;j>0;j--)
			h4[i][j]=h4[i+1][j]+h4[i][j+1]+h0[i][j]-h4[i+1][j+1];
	for (i=1;i<=2*m;i++)
		for (j=1;j<=2*m;j++)
			if (g1[i][j]+g4[i+1][j+1]+h2[i+1][j]+h3[i][j+1]>s)
				s=g1[i][j]+g4[i+1][j+1]+h2[i+1][j]+h3[i][j+1];
	for (i=1;i<=2*m;i++)
		for (j=1;j<=2*m;j++)
			if (h1[i][j]+h4[i+1][j+1]+g2[i+1][j]+g3[i][j+1]>s)
				s=h1[i][j]+h4[i+1][j+1]+g2[i+1][j]+g3[i][j+1];
	printf("%d",s);
	return 0;
}

Measured memory_bytes: 155776
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] arr = new int[n];
        for (int i = 0; i < n; i++) {
            arr[i] = sc.nextInt();
        }

        int op = 0;
        for (int i = 0; i < n; i++) {
            while (0 < arr[i]) {
                arr[i]--;
                op++;
                for (int s = i+1; s < n; s++) {
                    if (arr[s] != 0) {
                        arr[s]--;
                    } else {
                        break;
                    }
                }
            }
        }
        System.out.println(op);
    }
}

Measured memory_bytes: 21844
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define deb(a,b,c) cout<<#a<<" = "<<(a)<<", "<<#b<<" = "<<(b)<<", "<<#c<<" = "<<(c)<<endl;

typedef long long int ll;
typedef string str;

int main ()
{
	// ios::sync_with_stdio(0);
 //    cin.tie(0);
 //    cout.tie(0);
	ll t,n,m,k,i,a,b,j;
	cin >> n;
	ll arr[n+2];
	for(i=0;i<n;i++)
	{
		cin >>arr[i];
	}
	m=1000;
	k=0;
	for(i=0;i<n-1;i++)
	{
		k=m/arr[i];
		m-=(k*arr[i]);
		while(i<n-1 && arr[i]<=arr[i+1])
		{
			i++;
		}
		m+=(arr[i]*k);
		k=0;
	}
	cout << m << "\n";
	return 0;
}

Measured memory_bytes: 3604
#pragma comment(linker, "/STACK:128777216")
#define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <stdio.h>
#include <string>
#include <cstring>
#include <vector>
#include <queue>
#include <bitset>
#include <stack>
#include <deque>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <algorithm>
#include <math.h>
#include <cmath>
#include <climits>
#include <ctime>
#include <random>
using namespace std;

#define forx(_name,_from, to, value) for (int name = from; name < to; name += value)
#define rforx(_name, from, to, value) for (int name = from; name > to; name -= _value)
#define all(_STL_NAME) _STL_NAME.begin(), _STL_NAME.end()
#define rall(_STL_NAME) _STL_NAME.rbegin(), _STL_NAME.rend()
#define mp(_FIRST,_SECOND) make_pair(_FIRST,_SECOND)

typedef long long ll;
typedef unsigned long long llu;
typedef long double ld;
const ld eps = 1e-12;
mt19937 rndm;

void start() {
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	cout.precision(20); cout.setf(ios::fixed);
	string FILENAME = "navalny";
	rndm.seed(time(0));
#ifdef _DEBUG
	freopen("input.txt", "rt", stdin);
	freopen("output.txt", "wt", stdout);
#else
	//freopen((FILENAME + ".in").c_str(), "rt", stdin);
	//freopen((FILENAME + ".out").c_str(), "wt", stdout);
#endif
}

const int maxn = 1e5 + 500;
vector<int> mt[maxn];
ll ans = 1, mod = 1000000007;
int n, k;

void dfs(int v,int par = 0, int count1 = 0, int count2 = 0) {
	int t = 1;
	ans = (ans * (k - count1 - count2)) % mod;
	for (int i = 0; i < mt[v].size(); ++i) {
		int to = mt[v][i];
		if (to == par)
			continue;
		dfs(to, v, 1, count1 + t - 1);
		t++;
	}
}

int main() {
	start();
	cin >> n >> k;
	for (int i = 1; i < n; ++i) {
		int f, t;
		cin >> f >> t;
		mt[f].emplace_back(t);
		mt[t].emplace_back(f);
	}
	dfs(1);
	cout << ans;
#ifdef _DEBUG
	cout << "\nTime: " << 1.0 * clock() / CLOCKS_PER_SEC << endl;
#endif
	return 0;
}

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

#define N 101
#define BLACK 200
#define WHITE 201
#define GRAY 202
void DFS();
void DFS_Visit(int );
int t =0,num = 0;
int d[N],f[N],color[N],num4[N][N];


int main(){
  int i,j,num2,num3,num5,flag;
  scanf("%d",&num);
 
  for(i=1;i<=num;i++){
    for(j=1;j<=num;j++){
      num4[i][j] = 0;
    }
  }
 
   for(i=1;i<=num;i++){
     scanf("%d",&num5);
     scanf("%d",&num2);
     if(num2 == 0)continue;  
     else{
       for(j=0;j<num2;j++){
	 scanf("%d",&num3);
	 num4[i][num3] = 1;  
       }
     }    
   }

   DFS();
   for(i=1;i<=num;i++){
     printf("%d %d %d\n",i,d[i],f[i]);
   }
   
   
   return 0;
}
void DFS(){
  int i;
  for(i=1;i<=num;i++){
    color[i]=WHITE;
  }
  t = 0;
  
  for(i=1;i<=num;i++){
    if(color[i]==WHITE){
      DFS_Visit(i);
    }
  }
  
}

void DFS_Visit(int u){
  int v,j;
  color[u] = GRAY;
  t += 1;
  d[u] = t;
  for(j=1;j<=num;j++){
    if(color[j] == WHITE && num4[u][j] == 1)DFS_Visit(j);
  }
  color[u] = BLACK;
  t++;
  f[u] = t;
  
}

Measured memory_bytes: 636
#include <iostream>
#include <math.h>
using namespace std;

int main() {
    
    long long x;
    long long ans;
    
    cin >> x;
    
    if ( x <= 11 ) {
        ans = ( x > 6 ) ? 2: 1; 
    }
    else {
        ans = ( x / 11 ) * 2;
        if ( x % 11 != 0 ) {
            ans += ( ( x % 11 ) > 6 ) ? 2 : 1;
        }
    }
    
    
    cout << ans << endl;
    
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
#include<math.h>
int main(void)
{
	int a,s,d=100000,f=-100000,g,h,i,j;
	scanf("%d",&a);
	for(i=0;i<a;i++){
		scanf("%d",&s);
		if(d>s) d=s;
		if(f<s) f=s;
	}
	printf("%d\n",f-d);
	return 0;
}

Measured memory_bytes: 128
#include <stdio.h>
#include <algorithm>
#include <assert.h>
#include <bitset>
#include <cmath>
#include <complex>
#include <deque>
#include <functional>
#include <iostream>
#include <limits.h>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <time.h>
#include <unordered_map>
#include <unordered_set>
#include <vector>

#pragma warning(disable:4996)
#pragma comment(linker, "/STACK:336777216")
using namespace std;

#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define ldb ldouble

typedef tuple<int, int, int> t3;
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ldb;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef pair <ll, int> pli;
typedef pair <db, db> pdd;

int IT_MAX = 1 << 19;
int MOD = 1000000007;
const int INF = 0x3f3f3f3f;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
const db PI = acos(-1);
const db ERR = 1e-10;
#define szz(x) (int)(x).size()
#define rep(i, n) for(int i=0;i<n;i++)
#define Se second
#define Fi first

const int MX = 200005;

vector<int> T[MX];
int N, m, val = 1;

int dfs(int x, int p = -1){
	vector<int> X;
	for(int c : T[x]){
		if( c == p ) continue;
		X.push_back(dfs(c, x)+1);
	}
	sort(X.begin(), X.end());
	if( !val || X.empty() ) return 0;
	if( X.back() > m ) return val = 0;

	if( X.size()%2 == 0){
		int ch = 1;
		for(int i = 0; i < X.size()/2; i++){
			if( X[i] + X[X.size()-i-1] > m ) ch = 0;
		}
		if( ch ) return 0;
		if( p == -1 ) return val = 0;
		X.pop_back();
	}
	int ch = 1;
	for(int i = 0; i < X.size()/2; i++){
		if( X[i] + X[X.size()-i-2] > m ) ch = 0;
	}
	if( !ch ) val = 0;
	for(int i = X.size()-1; i > 0; i--){
		int op = X.size()/2 < i ? X.size()-i-1 : X.size()-i;
		if( X[i] + X[op] > m ) return X[i];
	}
	return X[0];
}

int main()
{
	int cnt = 1;
	scanf("%d", &N);
	for(int i = 1; i < N; i++){
		int a, b;
		scanf("%d%d", &a, &b);
		T[a].push_back(b);
		T[b].push_back(a);
	}
	for(int i = 1; i <= N; i++){
		if( T[i].size() >= 3 ) cnt += (T[i].size() - 1) / 2;
	}
	int s = 1, e = N;
	while(s <= e){
		m = (s+e) / 2;
		val = 1;
		dfs(1);
		if( val ) e = m-1;
		else s = m+1;
	}swap(s, e);
	printf("%d %d\n", cnt, e);
}


Measured memory_bytes: 16000