akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cstdio>
using namespace std;

class num {
	public:
		int J, O, I;

		num() {J = 0; O = 0; I = 0;};
		num(int a, int b, int c) {J = a; O = b; I = c;};

		num operator+(const num& hoge) {
			return num(J + hoge.J, O + hoge.O, I + hoge.I);
		}

		num operator-(const num& hoge) {
			return num(J - hoge.J, O - hoge.O, I - hoge.I);
		}
};

int N, M, K;
char in[1024][1024];
num table[1024][1024];
int a, b, c, d;

void input() {
	cin >> N >> M >> K;
	for(int i = 1; i < N + 1; i++) {
		scanf("%s", in[i] + 1);
	}
}

bool get_query() {
	if(!K)
		return false;
	cin >> a >> b >> c >> d;
	K--;
	return true;
}

void init() {
	for(int i = 0; i < 1024; i++) {
		for(int j = 0; j < 1024; j++) {
			in[i][j] = 0;
			table[i][j] = num();
		}
	}
}

void mktable() {
	for(int i = 1; i < N + 1; i++) {
		for(int j = 1; j < M + 1; j++) {
			table[i][j] = table[i - 1][j] + table[i][j - 1] - table[i - 1][j - 1];
			switch(in[i][j]) {
				case 'J':
					table[i][j].J++;
					break;
				case 'O':
					table[i][j].O++;
					break;
				case 'I':
					table[i][j].I++;
			}
		}
	}
}

void solve() {
	num ans;
	ans = table[c][d] - table[a - 1][d] - table[c][b - 1] + table[a - 1][b - 1];
	cout << ans.J << " " << ans.O << " " << ans.I << endl;
}

int main() {
	init();
	input();
	mktable();
	while(get_query())
		solve();
	return 0;
}

Measured memory_bytes: 14500
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define REVERSE(v,n) reverse(v,v+n);
#define VREVERSE(v) reverse(v.begin(), v.end());
#define ll long long
#define pb(a) push_back(a)
#define INF 999999999

using namespace std;


int dy[4] = { 0,0,1,-1 };
int dx[4] = { 1,-1,0,0 };
int dxx[8] = { 0,0,1,1,1,-1,-1,-1 };
int dyy[8] = { 1,-1,0,1,-1,0,1,-1 };

string maze[51];
int main() {
	int H, W;
	cin >> H >> W;
	REP(i, H)cin >> maze[i];
	REP(i, H) {
		REP(j, W) {
			if (maze[i][j] == '.') {
				maze[i][j] = '0';
				int cnt = 0;
				REP(k, 8) {
					int nx = i + dxx[k];
					int ny = j + dyy[k];
					if (nx >= 0 && nx < H&&ny >= 0 && ny < W) {
						if (maze[nx][ny] == '#')maze[i][j]+='1'-'0';
					}
				}
			}
		}
	}
	REP(i, H)cout << maze[i] << endl;
}


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


int main() {
  ll N, K;
  cin >> N >> K;
  cout << min(N % K, K - N % K) << endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
 using namespace std;
#define INF 1000000000
#define REP(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
typedef long long LL;
int N;
int main(){
    cin>>N;
    int x=800;
    int y=200;
    cout<<x*N-(N/15)*y<<endl;
    return 0;
}

Measured memory_bytes: 256
n,m = map(int,input().split())
k = [0]*n
a = [[0]]*n
for i in range(n):
  temp = list(map(int,input().split()))
  k[i] = temp[0]
  a[i] = temp[1:].copy()
lfood = set(range(1,m+1))
for i in range(n):
  tpset = set(a[i])
  lfood = lfood.intersection(tpset)
print(len(lfood))

Measured memory_bytes: 3064
#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstring>

using namespace std;

#define MAX 100000
#define INF 2140000000
#define MOD 1000000007

int main() {
	long long a, b, c;
	cin >> a >> b >> c;

	if (2*a*b + 2*c*a + 2*c*b < c*c + a*a + b*b && c > a + b) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#ifdef ONLINE_JUDGE
#define LLD "%I64d"
#else
#define LLD "%lld"
#endif
#define fu(a,b,c) for(int a=b;a<=(int)c;++a)
#define fd(a,b,c) for(int a=b;a>=(int)c;--a)
#define cu(a,b,c) for(int a=b;a<(int)c;++a)
#define cd(a,b,c) for(int a=(b)-1;a>=(int)c;--a)
#define gcd(a,b) __gcd(a,b) 
#define pii pair<int,int>
#define pll pair<long long,long long>
#define all(a) a.begin(),a.end()
#define F first
#define S second
#define pb push_back
#define pf push_front
#define MOD 1000000007 
#define MAXN 52
#define MAXH 20
#define MAXM 52
#define INF 100000000
#define ll long long
#define ull unsigned long long
#define RNG rng mt19937(time(NULL))
#define udist(a,b) uniform_int_distribution<uint32_t> distribution(a,b)
#define max3(a,b,c) max(a, max(b, c))
#define min3(a,b,c) min(a, min(b, c))
#define gmax(a,b) a = max(a, b)
#define gmin(a,b) a = min(a, b)
#define whatis(x) cerr << #x << " is " << x << endl;
#define fast_io() ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define PI 3.1415926535897932384626433
using namespace std;
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

int main(){
	int n,A,B,C;
	cin >> n;
	cin >> A >> B >> C;
	vector<int> v(n);
	cu(i,0,n)cin >> v[i];
	int ans = MOD;
	cu(i,0,1 << (2*n)){
		int a,b,c;	
		a = b = c = 0;
		int cnt = -30;
		cu(j,0,n){
			int num = (i >> (2*j))& 0x3;
			if(num == 1){
				a += v[j];
				cnt += 10;
			}
			else if(num == 2){
				b += v[j];
				cnt += 10;
			}
			else if(num == 3){
				c += v[j];
				cnt += 10;
			}
		}
		cnt += abs(A - a) + abs(B - b) + abs(C - c);
		if(a != 0 && b != 0 && c != 0)gmin(ans,cnt);
	}
	cout << ans << '\n';
}


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

#define rep(i,n) FOR(i,0,n)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define ROF(i,a,b) for(int i=(a);i>(b);i--)
#define all(a) (a).begin(),(a).end()
#define UNIQUE(v) v.erase(unique(all(v)),v.end())
typedef vector<int> vi;
typedef vector<vi> vii;
typedef vector<string> vs;
typedef pair<int,int> pii;
typedef long long ll;

main(){
  int n; cin >> n;
  int a;
  map<int,int> mp;
  rep(i,n){
    cin >> a;
    if(mp[a]==0) mp[a]=1;
    else mp[a]=0;
  }
  int count=0;
  for(auto p:mp){
    if(p.second) count++;
  }
  cout << count << endl;
}


Measured memory_bytes: 4864
import java.util.*;

class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        double ans = 1;
        for (int i = 1; i <= N; i++) {
            ans = ans * i % (Math.pow(10, 9) + 7);
        }
        System.out.println((int) Math.ceil(ans));
    }
}

Measured memory_bytes: 21844
#include <stdio.h>
 
int main(void) {
  int n;
  int c = 0;
  long h, w, a, b;
  
  scanf("%d", &n);
  scanf("%ld", &h);
  scanf("%ld", &w);
  
  for(int i = 0; i < n; i++) {
    scanf("%ld", &a);
  	scanf("%ld", &b);
    if (a >= h && b >= w) {
      c++;
    }
  }
  
  printf("%d", c);

return 0;
}

Measured memory_bytes: 128
import scala.math._

object Main extends App {
  val sc = new java.util.Scanner(System.in)
//  val list = List.fill(3)(sc.nextInt)
  val x, a, b = sc.nextInt

  val day = -a + b
  val ans =
    if (day <= 0) "delicious"
    else if (day <= x) "safe"
    else "dangerous"

  println(ans)

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

  def bigIterator(start: BigInt, end: BigInt, step: BigInt = 1) =
    Iterator.iterate(start)(_ + step).takeWhile(_ <= end)

  def lcm(a :Int, b :Int): Int =
    a / gcd(a, b) * b

  def lcm(a :Long, b :Long): Long =
    a / gcd(a, b) * b

  def gcd(a: Int, b: Int): Int =
    if (b == 0) a else gcd(b, a % b)

  def gcd(a: Long, b: Long): Long =
    if (b == 0) a else gcd(b, a % b)

  def setOrUpdated[A, B](a: Map[A, B], key: A, value: B, f: (B, B) => B) =
    a.get(key) match {
      case Some(v) => a.updated(key, f(value, v))
      case _ => a + (key -> value)
    }
}

Measured memory_bytes: 27332
#include<stdio.h>

int main()
{
	int a = 0, b = 0,sum = 0,road = 0,result = 0;
	scanf("%d%d", &a, &b);

	sum = a * b;
	road = a + b - 1;
	result = sum - road;

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

	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define ll long long int 
int main() 
{
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    string S;
    cin>>S;
    if (S[2]==S[3] and S[4]==S[5])
        cout<<"Yes";
    else
        cout<<"No";
}



Measured memory_bytes: 256
"""
Writer: SPD_9X2
https://atcoder.jp/contests/agc022/tasks/agc022_c


ある　t 以下のkで全て終わらせる < t+1を使う
なので、まず答えを満たすのに必要な最小の最大値を求める必要がある
大きい奴は使わない方がよい
→これを使わなくても答えが成立しうるか？を上から決めてく

計算量不安だけど平気そう
"""

def able(na,nb,lis):

    if na < nb:
        return False
    elif na == nb:
        return True
    
    q = {}
    q[na] = 1
    for i in range(50,0,-1):

        temp = []
        if not lis[i]:
            continue
        
        for j in q:

            if j % i == nb:
                return True
            elif j % i > nb:
                temp.append(j % i)

        for j in temp:
            q[j] = 1

    return False
            

N = int(input())

a = list(map(int,input().split()))
b = list(map(int,input().split()))

lis = [True] * 51

import sys

for j in range(N):
    if not able(a[j],b[j],lis):
        print (-1)
        sys.exit()

for i in range(50,0,-1):

    lis[i] = False
    for j in range(N):

        ret = able(a[j],b[j],lis)

        if not ret:
            lis[i] = True
            break

ans = 0
for i in range(1,51):
    if lis[i]:
        ans += 2**i
print (ans)


Measured memory_bytes: 43740
#include "bits/stdc++.h"
using namespace std;

struct goods {
	int V;
	int W;
};

int main() {
	int W, COUNT = 1;
	while (cin >> W) {
		if (W == 0) return 0;
		int N;
		char C;
		goods G[1000] = {};
		static long long DP[1010][1010] = {};
		cin >> N;
		for (int i = 0; i < N; i++) cin >> G[i].V >> C >> G[i].W;
		for (int i = 0; i < N; i++) {
			for (int j = 0; j <= W; j++) {
				if (j >= G[i].W) DP[i + 1][j] = max(DP[i][j], DP[i][j - G[i].W] + G[i].V);
				else DP[i + 1][j] = DP[i][j];
			}
		}
		long long ANS = DP[N][W];
		for (int i = W; i >= 0; i--) {
			if (ANS != DP[N][i]) {
				cout << "Case " << COUNT << ":" << endl << ANS << endl << i + 1 << endl;
				break;
			}
		}
		COUNT++;
	}
}


Measured memory_bytes: 10980
#include <algorithm>
#include <climits>
#include <complex>
#include <cstring>
#include <iostream>
#include <map>
#include <set>
#include <vector>

// using
using namespace std;

// typedef
typedef long long ll;

// define
#define ALL(c) (c).begin(), (c).end()
#define SORT(c) sort(ALL(c))
#define REVERSE(c) reverse(ALL(c))
#define UNIQ(c) unique(ALL(c))
#define FOR(i, a, b, c) for (int i = (int)(a); i < (int)(b); i += (int)(c))
#define REP(i, n) FOR(i, 0, n, 1)
#define RFOR(i, a, b, c) for (int i = (int)(a); i >= (int)(b); i -= (int)(c))
#define RREP(i, n) RFOR(i, n, 0, 1)

// functions
int ceil(int a, int b) {
    return (a + b - 1) / b;
}
int round(int a, int b) {
    return (a + b / 2) / b;
}
int gcd(int a, int b) {
    return b ? gcd(b, a % b) : a;
}
int lcm(int a, int b) {
    return a * b / gcd(a, b);
}
template <class T> bool amax(T &a, const T &b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
template <class T> bool amin(T &a, const T &b) {
    if (b < a) {
        a = b;
        return true;
    }
    return false;
}

// main
int main() {
    string S;
    cin >> S;
    REVERSE(S);
    int l = S.size(), n = 1 << (l - 1);
    ll res = 0;
    REP(i, n) {
        ll m = 1;
        REP(j, l) {
            res += (S[j] - '0') * m;
            if ((i >> j) & 1) {
                m = 1;
            } else {
                m *= 10;
            }
        }
        cout << endl;
    }
    cout << res << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define ll long long int
#define pb push_back
#define fi first
#define se second
#define ld long double
#define vi vector<vector<ll> >
using namespace std;
const int MOD=1000000007;
const int MOD2=998244353;
const ll MAX=9187201950435737471;
const int N=100005;
const int INF=1e9+7;
const long double PI=acos(-1);



void solve(int T){
    int n;
    cin>>n;
    vector<int>a(n+1);
    for(int i=1;i<=n;i++){
        int x;
        cin>>x;
        a[x]=i;
    }
    for(int i=1;i<=n;i++){
        cout<<a[i]<<" ";
    }
}

int main() {
    fastio

    int T=1;
    //cin>>T;
    for(int i=1;i<=T;i++){
        solve(i);
        //if(i<T)cout<<"\n";
    }
    return 0;
}


Measured memory_bytes: 3604
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,a) for(int i=0;i<(a);i++)
const ll MOD=1000000007;
//const ll MOD=998244353;

const int MAX_V=101010;

int par[MAX_V];
int rnk[MAX_V];
int num[MAX_V];

void init(){
  for(int i=0;i<MAX_V;i++){
    par[i]=i;
    rnk[i]=0;
    num[i]=1;
  }
}

int find(int x){
  if (par[x] == x){
    return x;
  }else{
    return par[x] = find(par[x]);
  }
}

void unite(int x, int y){
  x = find(x);
  y = find(y);
  if (x == y) return;

  if (rnk[x] < rnk[y]){
    par[x] = y;
    num[y] += num[x];
  }else{
    par[y] = x;
    num[x] += num[y];
    if (rnk[x] == rnk[y]) rnk[x]++;
  }
}

bool same(int x, int y){
  return find(x) == find(y);
}

int ans[101010],A[101010],B[101010];

int main(){
  init();
  int N,M,K; cin>>N>>M>>K;
  rep(i,M){
    cin>>A[i]>>B[i]; A[i]--,B[i]--;
    unite(A[i],B[i]);
  }
  rep(i,N) ans[i]=num[find(i)]-1;
  rep(i,M){
    ans[A[i]]--,ans[B[i]]--;
  }
  rep(i,K){
    int C,D; cin>>C>>D; C--,D--;
    if(same(C,D)){
      ans[C]--,ans[D]--;
    }
  }
  rep(i,N) cout<<ans[i]<<" ";
  cout<<endl;
  return 0;
}

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

#define fst(t) std::get<0>(t)
#define snd(t) std::get<1>(t)
#define thd(t) std::get<2>(t)
#define unless(p) if(!(p))
#define until(p) while(!(p))

using ll = std::int64_t;
using P = std::tuple<int,int>;

int M;
ll d, c;

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

  std::cin >> M;

  ll n = 0, ds = 0;

  for(int i=0;i<M;++i){
      std::cin >> d >> c;

      n += c;
      ds += d * c;
  }

  ll res = 0;
  res += ds % 9 > 0 ? ds / 9 : ds / 9 - 1;
  res += n - 1;

  std::cout << res << std::endl;
}


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

using namespace std;

int main(){
	int n,m;
	cin>>n>>m;
	for(int i=n-1;i>=1;i--){
		cout<<m-i<<" ";
	}
	for(int i=0;i<n;i++){
		cout<<m+i<<" ";
	}
	cout<<endl;
	
	return 0;
}

Measured memory_bytes: 256
/*
	容斥原理 + 递推
	不重复地选择一些的集合
	答案要求的是每一种元素必须出现两次以上
	ans = \sum (-1)^i f[i]
	其中 f[i] 表示至少有 i 个元素不满足条件
	考虑枚举这 i 个元素, 有 C(n, i) 种方式
	这 i 个元素放在集合的个数是 O(n) 级别的, 而且最后答案也跟集合个数有关
	就先设 g[i][j] 为考虑了前 i 个元素放在 j 个集合里, 且都不满足条件的方案数
	g[i][j] = g[i - 1][j - 1] + g[i - 1][j] * (j + 1)
	前一个表示这个元素就放在第 j 个集合里
	后一个表示这个元素可以放在 j 个集合里, 也可以不放 
*/
#include <bits/stdc++.h>
#define N 3005

using namespace std;

const int bl = 32761;

int n, mod;
int comb[N][N], g[N][N];

int pw[2][2][bl + 1];

void init(int a[2][bl + 1], int x, const int mo) {
	a[0][0] = 1;
	for(int i = 1; i <= bl; ++i)
		a[0][i] = 1LL * x * a[0][i - 1] % mo;
	a[1][0] = 1;
	for(int i = 1; i <= bl; ++i)
		a[1][i] = 1LL * a[0][bl] * a[1][i - 1] % mo;
}
inline int fpm(int typ, int y) {
	return 1LL * pw[typ][1][y / bl] * pw[typ][0][y % bl] % mod;
}

int main() {
	scanf("%d %d", &n, &mod);
	
	init(pw[0], 2, mod);
	init(pw[1], 2, mod - 1);
	
	for(int i = 0; i <= n; ++i) {
		comb[i][0] = 1;
		for(int j = 1; j <= i; ++j)
			comb[i][j] = (comb[i - 1][j - 1] + comb[i - 1][j]) % mod;
	}
	for(int i = 0; i <= n; ++i) {
		g[i][0] = 1;
		for(int j = 1; j <= i; ++j)
			g[i][j] = (g[i - 1][j - 1] +
			(j + 1LL) * g[i - 1][j]) % mod;
	}
	
	int ans = 0;
	for(int i = 0; i <= n; ++i) {
		int res = 0;
		for(int j = 0; j <= i; ++j) {
			res = (res + 1LL * comb[n][i] * g[i][j] % mod
				   * fpm(0, (n - i) * j) % mod
				   * fpm(0, fpm(1, n - i))) % mod;
		}
		if(i & 1) {
			ans = (ans + mod - res) % mod;
		} else {
			ans = (ans + res) % mod;
		}
	}
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 70272
#include <bits/stdc++.h>
using namespace std;
#define IOS ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep1(i,n) for(ll i=1;i<=n;i++)
#define rep_start(a,i,n) for(ll i=a;i<=n;i++)
#define rev(i,n) for(ll i=n-1;i>=0;i--)
#define rev1(i,n) for(ll i=n;i>0;i--)
#define sz(a) int((a).size())
#define all(c) c.begin(),c.end()
#define tr(c,i) for(typeof(c).begin() i+=c.begin; i!=c.end(); i++)
#define present(c,x) (c.find(x)!=c.end())
#define cpresent(c,x) (find(all(c),x)!=c.end())
#define pb push_back
#define F first
#define S second
#define INF INT_MAX
#define mod 1000000007
#define print1(a) cout<<a<<"\n";
#define print2(a,b) cout<<a<<" "<<b<<"\n";
#define print3(a,b,c) cout<<a<<" "<<b<<" "<<c<<"\n";
#define mt make_tuple
#define eb emplace_back

typedef long long int ll;
typedef vector<ll> vi;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<vi> vvi;
typedef pair<ll,ll> ii;
typedef vector<ii> vii;
typedef tuple<int,int,int> State;

void solve(){
    ll n;cin>>n;
    vi v(n),f(n),s(n);
    rep(i,n) {cin>>v[i]; f[i]=i+v[i]; s[i]=i-v[i];}
    sort(all(s));
    ll c=0;
    rep(i,n){
        ll tmp=f[i];
        if(binary_search(all(s),tmp)) c+=upper_bound(all(s),tmp)-lower_bound(all(s),tmp);
    }
    cout<<c;
}

signed main() {
    // your code goes here
    IOS
    ll t=1;
    //cin>>t;
    rep1(i,t){
        solve(); 
    }
    return 0;
}

Measured memory_bytes: 7956
#include <bits/stdc++.h>
using namespace std;
int main(){
char X, Y;
cin >> X >> Y; 
if(X == 'H' && Y == 'H') cout << "H" << endl; 
if(X == 'H' && Y == 'D') cout << "D" << endl; 
if(X == 'D' && Y == 'H') cout << "D" << endl; 
if(X == 'D' && Y == 'D') cout << "H" << endl; 
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<algorithm>
//deque/functional/iteratorst/map/memory/numeric/queuet/stack/utilityector
//#include<bits/stdc++.h>
#define ll long long
using namespace std;

int main()
{
	ios::sync_with_stdio(false);
	int n,x;
	cin>>n;
	int a[110]={0};
	for(int i=1;i<=n;i++){
		cin>>x;
		int nn=0;
		for(int j=1;j<x;j++){
			if(a[j]!=0)
			nn++;
		}
		if(nn<x-1){
			cout<<-1<<endl;
			return 0;
		}
		for(int j=100;j>=x;j--){
			a[j]=a[j-1];
		}
		a[x]=x;
	}
	for(int i=1;i<=n;i++){
		cout<<a[i]<<endl;
	}
return 0;
}


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

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;

#define fi first
#define se second
#define repl(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rep(i,n) repl(i,0,n)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt __builtin_popcount

#define INF 1e16
#define mod 1000000007

int h,w;
string s[12];
vector<int> p;
bool used[12];

bool dfs(int st){
  if(p.size()==(h+1)/2){
    do{
      vector<string> t;
      memset(used,0,sizeof(used));
      rep(i,p.size()){
        t.push_back(s[p[i]]);
        used[p[i]]=true;
      }
      rep(i,h)if(!used[i])t.push_back(s[i]);

      vector<ll> ss(w,0),sr(w,0);
      rep(j,w){
        rep(i,h){
          ss[j]*=26;
          ss[j]+=t[i][j];
          sr[j]*=26;
          sr[j]+=t[h-1-i][j];
        }
      }
      memset(used,0,sizeof(used));
      int cnt=0;
      rep(i,w){
        if(used[i])continue;
        repl(j,i+1,w){
          if(used[j])continue;
          if(ss[i]==sr[j]){
            used[i]=used[j]=true;
            cnt++;
            break;
          }
        }
      }
      if(w%2==0&&cnt==w/2)return true;
      if(w%2==1&&cnt==w/2){
        rep(i,w){
          if(!used[i]&&ss[i]==sr[i]){
            return true;
          }
        }
      }
    }while(next_permutation(all(p)));
    return false;
  }
  repl(i,st,h){
    p.push_back(i);
    if(dfs(i+1))return true;
    p.pop_back();
  }
  return false;
}

int main(){
  cin>>h>>w;
  rep(i,h)cin>>s[i];
  if(dfs(0))cout<<"YES"<<endl;
  else cout<<"NO"<<endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define FOR(i,a,b) for(int i=int(a);i<=int(b);i++)
#define ROF(i,a,b) for(int i=int(b);i>=int(a);i--)
#define pb push_back
#define pq priority_queue
#define ps push
#define x first
#define y second
using namespace std;
int n,q,tmf,tms;
long long cnt[200010],dp[200010];
vector<int> d[200010];
void dfs(int now,int par){
    dp[now]=cnt[now];
    FOR(i,0,d[now].size()-1) if(d[now][i]!=par){
        cnt[d[now][i]]+=cnt[now];
        dfs(d[now][i],now);
    }
}
int main(){
    cin>>n>>q;
    FOR(i,2,n){
        cin>>tmf>>tms;
        d[tmf].pb(tms);
        d[tms].pb(tmf);
    }
    FOR(i,1,q){
        cin>>tmf>>tms;
        cnt[tmf]+=tms;
    }
    dfs(1,0);
    FOR(i,1,n) printf("%lld ",dp[i]);
}


Measured memory_bytes: 32128
import sys
import math
N, M = map(int, input().split())
NUMS = [list(map(int, input().split())) for _ in range(M)]


def solve():
    for n in range(10 ** (N - 1) if N > 1 else 0, 10 ** (N)):
        res = 0
        for s, c in NUMS:
            if str(n)[s - 1] == str(c):
                res += 1
        
        if res == M:
            print(n)
            return
            
    print("-1")
    
solve()

Measured memory_bytes: 3060
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <queue>
#include <cstring>
#include <vector>
#include <map>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <bitset>
#include <set>
#include <stack>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define RREP(i,n) for(int i=n-1;i>=0;i--)
#define FOR(i,k,n) for(int i=(k);i<(int)(n);i++)
#define all(i,n) (i),(i+n)

int dx4[4]={1,0,-1,0};
int dy4[4]={0,-1,0,1};
int dx8[8]={1,0,-1,1,-1,1,0,-1};
int dy8[8]={1,1,1,0,0,-1,-1,-1};
int dx9[9]={0,1,0,-1,1,-1,1,0,-1};
int dy9[9]={0,1,1,1,0,0,-1,-1,-1};

typedef pair<int, int> P;
typedef pair<string, int> SP;
typedef long long ll;
typedef pair<ll, ll> PLL;

const int INF = 1e9;
const ll LLINF = 1e18;
const int MAX_V = 1e6+1;
const ll mod = 1000000007;
// << fixed << setprecision
// --------------------------------------
int n;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);

  cin >> n;
  ll sum = 0;
  ll now = 0;

  REP(i, n) {
    ll a;
    cin >> a;
    if(now >= a) {
      sum += now - a;
    } else {
      now = a;
    }
  }

  cout << sum << endl;
}


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

using namespace std;

using ll = long long;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    for (int i = 1; i <= 9; i++) {
        for (int j = 1; j <= 9; j++) {
            if (i * j == n) {
                cout << "Yes\n";
                return 0;
            }
        }
    }
    cout << "No\n";
    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <vector>
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
//#define cerr if(false) cerr
#ifdef DEBUG
#define show(...) cerr << #__VA_ARGS__ << " = ", debug(__VA_ARGS__);
#else
#define show(...) 42
#endif
using namespace std;
using ll = long long;
using pii = pair<int, int>;
template <typename T, typename S>
ostream &operator<<(ostream &os, pair<T, S> a) {
    os << '(' << a.first << ',' << a.second << ')';
    return os;
}
template <typename T>
ostream &operator<<(ostream &os, vector<T> v) {
    for (auto x : v) os << x << ' ';
    return os;
}
void debug() {
    cerr << '\n';
}
template <typename H, typename... T>
void debug(H a, T... b) {
    cerr << a;
    if (sizeof...(b)) cerr << ", ";
    debug(b...);
}
//i回移動してj種類の頂点を訪れていて、0を含む連結成分のサイズがk
int dp[305][305][305];
int mod = 1000000007;
inline void add(int &a, int b){
    a += b;
    if(a >= mod) a -= mod;
}
inline int mul(int a, int b){
    return (long long) a * b % mod;
}
int main(){
    int n, m;
    cin >> n >> m;
    dp[0][1][1] = 1;
    for(int i = 0; i < m; i++){
        for(int j = 1; j <= n; j++){
            for(int k = 1; k <= j; k++){
//                show(i,j,k,dp[i][j][k]);
                if(dp[i][j][k]){
                    int d = dp[i][j][k];
                    add(dp[i+1][j][k], mul(d, j - k));
                    add(dp[i+1][j][j], mul(d, k));
                    add(dp[i+1][j+1][k], mul(d, n - j));
                }
            }
        }
    }
    cout << dp[m][n][n] << endl;
}

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

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

    while (true) {
        int m, f, r;
        cin >> m >> f >> r;
        if (m == -1 && f == -1 && r == -1) {
            break;
        }
        int sum = m + f;
        if (m == -1 || f == -1) {
            cout << "F" << endl;
        } else if (sum >= 80) {
            cout << "A" << endl;
        } else if (65 <= sum && sum < 80) {
            cout << "B" << endl;
        } else if (50 <= sum && sum < 65) {
            cout << "C" << endl;
        } else if (30 <= sum && sum < 50) {
            if (r >= 50) {
                cout << "C" << endl;
            } else {
                cout << "D" << endl;
            }
        } else if (sum < 30) {
            cout << "F" << endl;
        }
    }
    return 0;
}


Measured memory_bytes: 3116
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

class Main {
	public static void main(String[] args) throws IOException{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		try {
			String str = br.readLine();
			int N = Integer.parseInt(str);
			if(N % 10 == 9 || N/10 == 9) {
				System.out.println("Yes");
			}else {
				System.out.println("No");
			}
//			long max  = 1000000007;
		}catch (Exception e) {
			System.exit(0);
		}
	}

}


Measured memory_bytes: 21204
x,y = map(int,input().split())
A = [1,3,5,7,8,10,12]
B = [4,6,9,11]
C = [2]

if x in A and y in A:
  check = True
elif x in B and y in B:
  check = True
elif x in C and y in C:
  check = True
else:
  check = False
  
print("Yes" if check else "No")

Measured memory_bytes: 9132
import itertools

N = int(input())
dots = [tuple(map(int, input().split())) for _ in range(N)]
total_distance = 0
total_count = 0

for route in itertools.permutations(dots):
    for i in range(len(route)-1):
        x1, y1 = route[i]
        x2, y2 = route[i+1]

        total_distance += ((x2 - x1)**2 + (y2 - y1)**2)**0.5
    
    total_count += 1

ans = total_distance / total_count
print(ans)




Measured memory_bytes: 9436
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>

using namespace std;

//----------------------- Print Function ----------------------//

inline void print() {
    cout << endl;
}
template <typename First, typename... Rest>
void print(const First &first, const Rest &... rest) {
    cout << first << ' ';
    print(rest...);
}

template <typename T>
void print(const vector<T> &v) {
    for (auto e : v) cout << e << ' ';
    cout << endl;
}

//------------------------- Libraries -------------------------//

template<class T>
bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}

template<class T>
bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

//--------------------------- Solve ---------------------------//

int dp[105][105];

const int INF = 1000000000;

void solve() {
    int H, W; cin >> H >> W;
    vector<string> s(H);
    for (int i = 0; i < H; i++) cin >> s[i];

    for (int i = 0; i < H; i++) {
        for (int j = 0; j < W; j++) {
            dp[i][j] = INF;
        }
    }
    
    if (s[0][0] == '#') dp[0][0] = 1;
    else dp[0][0] = 0;
    for (int i = 0; i < H; i++) {
        for (int j = 0; j < W; j++) {
            // 右へ
            int to_right = INF;
            if (j+1 < W) {
                if (s[i][j] == '.' && s[i][j+1] == '#') to_right = dp[i][j] + 1;
                else to_right = dp[i][j];
                chmin(dp[i][j+1], to_right);
            }
            // 下へ
            int to_under = INF;
            if (i+1 < H) {
                if (s[i][j] == '.' && s[i+1][j] == '#') to_under = dp[i][j] + 1;
                else to_under = dp[i][j];
                chmin(dp[i+1][j], to_under);
            }
        }
    }

    cout << dp[H-1][W-1] << '\n';
}

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

    solve();

    return 0;
}

Measured memory_bytes: 3684
<?php
$n = intval(fgets(STDIN));
$p = array_map("intval", explode(" ", trim(fgets(STDIN))));
$count = 0;
for($i = 0; $i < $n - 2; $i++){
  $count += ($p[$i]-$p[$i+1]) * ($p[$i+2]-$p[$i+1]) < 0;
}
echo $count,"\n";



Measured memory_bytes: 4728
#include<iostream>
int changeToWhich(int n,int before,int next)
{
    for(int i=1;i<=n;i++){
        if(i==before) continue;
        else if(i==next) continue;
        else return i;
    }
    return 0;
}
int main(int argc, char const *argv[])
{
    int slims[10000],n,times=0;
    std::cin>>n;
    for(int i=0;i<n;i++){
        std::cin>>slims[i];
    }
    for(int i=0;i<n;i++){
        if(slims[i]==slims[i+1]){
            slims[i+1]=changeToWhich(n,slims[i],slims[i+2]);
            times++;
        }
    }
    std::cout<<times;
    return 0;
}


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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define Rep(i, n) for (int i = 1; i <= (int)(n); i++)
#define fore(i, a) for (auto &i:a)
#define ll long long
#define pll vector<pair<ll, ll>>
#define mod 1000000007
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define popcount(x) __builtin_popcountll(x)

using namespace std;

const long double PI = acos(-1);

ll gcd(ll a,ll b){return b ? gcd(b,a%b) : a;}
ll lcm(ll a,ll b){return a / gcd(a,b) * b;}
ll stringcount(string s, char c){return count(s.cbegin(), s.cend(), c);}

bool isInteger(double x){return floor(x) == x;}

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

	int n,m;cin >> n >> m;
	int h[100010];
	int ans=0;
	vector <int> x[100010];
	rep(i,n)cin >> h[i];
	
	rep(i,m){
		int a,b;cin >> a >> b;
		a--;b--;
		x[a].pb(b);
		x[b].pb(a);
		//なんで、下の書き方だと動かないんだろうか......
		// x[a-1].pb(b);
		// x[b-1].pb(a);
	}

	rep(i,n){
		bool flag=true;
		fore(j, x[i]) if(h[i] <= h[j]) flag=false;
			
		if(flag)ans++;
	}
	cout << ans << endl;
}


Measured memory_bytes: 9176
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define FAST_IO ios_base::sync_with_stdio(false); cin.tie(NULL)
#define trace1(x)                cerr<<#x<<": "<<x<<endl
#define trace2(x, y)             cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z)          cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define trace4(a, b, c, d)       cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
#define trace5(a, b, c, d, e)    cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
#define trace6(a, b, c, d, e, f) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl

int main(){
	FAST_IO;
    string s, t; 
    cin >> s >> t;
    int n1 = s.length(); 
    int n2 = t.length(); 

    int dp[n1+1][n2+1]; 
    for(int i=0 ; i < n1+1; i++){
        dp[i][n2] = 0; 
    }
    for(int i=0 ; i < n2+1; i++){
        dp[n1][i] = 0; 
    }

    for(int i = n1-1; i >=0; i--){
        for(int j = n2-1; j >= 0; j--){
            if(s[i] == t[j]){
                dp[i][j] = dp[i+1][j+1] + 1; 
            }
            else{
                dp[i][j] = max(dp[i+1][j] , dp[i][j+1]);
            }
        }
    }
   /* for(int i=0; i <= n1; i++){
        for(int j= 0; j <=n2; j++){
            cout << dp[i][j] << " ";
        }
        cout << endl;
    }*/
    string ans; 
    int i = 0; 
    int j = 0; 
    while( i < n1 && j < n2){
        if(s[i] == t[j]){
            ans.push_back(s[i]);
            i++;
            j++;
        }
        else{
            if(dp[i+1][j] == dp[i][j]){
                i++;
            }
            else{
                j++;
            }
        }
    }

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

Measured memory_bytes: 35456
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define ll          long long
#define pb          push_back
#define mp 	    make_pair
#define pii         pair<ll,ll>
#define vi          vector<ll>
#define vii         vector<pii>
#define mi          map<ll,ll>
#define mii         map<pii,ll>
#define all(a)      (a).begin(),(a).end()
#define fi          first
#define si          second
#define sz(x)       (ll)x.size()
#define endl        '\n'
#define mod        1000000007
#define mset(m,v) memset(m,v,sizeof(m))
using namespace std;
ll power(ll a , ll b,ll modi)
{
    a%=modi;
    ll res = 1 ;
    while(b)
    {
        if(b%2) {
            res = (res * a) % modi ;
        }
        b/=2 ;
        a = (a*a) % modi ;
    }
    return res ;
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int t;
	cin>>t;
	map<string,int>m;
	while(t--)
	{
	string s;
	cin>>s;
	m[s]++;
	}
	cout<<"AC x "<<m["AC"]<<endl;
	cout<<"WA x "<<m["WA"]<<endl;
	cout<<"TLE x "<<m["TLE"]<<endl;
	cout<<"RE x "<<m["RE"]<<endl;
return 0;
}


Measured memory_bytes: 3664
#pragma GCC optimize(3)
#include<bits/stdc++.h>
using namespace std;
int n;
long long k;
long long p[5010],c[5010];
long long mx=-1e18;
long long a[5010][5010];
long long sz[5010][5010];
/*
void dfs(int beg,int x,int num,long long sum){
	if(num>0){
		if(s.find(x)!=s.end()){
			return ;
		}
		s.insert(x);
		mx1[beg]=max(mx1[beg],sum);
		a[beg][num]=sum;
		make[beg]=sum;
	}
	dfs(beg,p[x],num+1,sum+c[p[x]]);
}
*/
int main(){
	cin>>n>>k;
	for(int i=1;i<=n;i++){
		for(int j=1;j<=n;j++){
			sz[i][j]=1e9+10;
		}
	}
	for(int i=1;i<=n;i++){
		cin>>p[i];
	}
	for(int i=1;i<=n;i++){
		cin>>c[i];
	}
	for(int i=1;i<=n;i++){
		int j=p[i];
		long long sum=c[p[i]];
		int num=1;
		while(i!=j){
			a[i][j]=sum;
			sz[i][j]=num;
			sum+=c[p[j]];
			j=p[j];
			num++;
		}
		a[i][i]=sum;
		sz[i][i]=num;
	}
	for(int i=1;i<=n;i++){
		for(int j=1;j<=n;j++){
			if(sz[i][j]>k)continue;
			long long tmp=(k-sz[i][j])/sz[i][i];
			if(a[i][i]>0)mx=max(mx,tmp*a[i][i]+a[i][j]);
			else mx=max(mx,a[i][j]);
		}
	}
	cout<<mx<<endl;
	return 0;
}

Measured memory_bytes: 395064
# coding: utf-8
# Your code here!
import bisect

N=int(input())

A=list(map(int,input().split()))

A.sort()

sum_A=[]
for item in A:
    if sum_A:
        sum_A.append(sum_A[-1]+item)
    else:
        sum_A.append(item)

ans=0
for i in range(len(A)):
    while i!=len(A):
        index=bisect.bisect_right(A,2*sum_A[i])-1
        if i==index:
            break
        else:
            i=index
    if i==len(A)-1:
        ans+=1

print(ans)

Measured memory_bytes: 14352
#include<cstdio>
#include<algorithm>
using namespace std;
int n,v[100005],a[100005],b[100005];
int main(){
	scanf("%d",&n);for(int i=1;i<=n;++i) scanf("%d",&v[i]);
	for(int i=2;i<=n;i+=2) a[v[i]]++,b[v[i-1]]++;
	int c1=0,c2=0,k1,k2;
	for(int i=1;i<=100000;++i) {if(a[i]>c1) c1=a[i],k1=i;if(b[i]>c2) c2=b[i],k2=i;}
	if(k1==k2) {
		int c3=0,c4=0;
		for(int i=1;i<=100000;++i) {if(a[i]>c3&&k1!=i) c3=a[i];if(b[i]>c4&&k1!=i) c4=b[i];}
		printf("%d\n",min(n-c1-c3,n-c2-c4));
		return 0;
	}
	printf("%d\n",n-c1-c2);
	return 0;
}

Measured memory_bytes: 1280
#include <iostream>
#include <algorithm>
#include <utility>
#include <string>
#include <vector>
#include <set>
#include <stack>
#include <queue>
#include <map>
#include <math.h>
#include <string.h>
#include <iomanip>
#include <numeric>
#include <cstdlib>
#include <cstdint>
#include <cmath>
#include <functional>
#include <limits>
#include <cassert>

using namespace std;

/* template */

using ll = long long;

void debug_out() { std::cout << std::endl; }
 
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cout << H << " ";
  debug_out(T...);
}

#ifdef LOCAL
#define debug(...) cout << "debug: "; debug_out(__VA_ARGS__)
#else
#define debug(...) 
#endif

#define rep(i, a, n) for (int i = (int)(a); i < (int)(n); i++)
#define rrep(i, a, n) for (int i = ((int)(n-1)); i >= (int)(a); i--)
#define Rep(i, a, n) for (long long i = (long long)(a); i< (long long)(n); i++)
#define RRep(i, a, n) for (long long i = ((long long)(n-1ll)); i>=(long long)(a); i--)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()

template <typename T>
std::ostream& operator<<(std::ostream& os, std::vector<T> vec) {
  for (std::size_t i = 0; i < vec.size(); i++)os << vec[i] << (i + 1 == vec.size() ? "" : " ");
  return os;
}

struct Edge{
    int to;
    int weight;
    Edge(int t, int w) : to(t), weight(w){ }
};

struct edge{
    int from;
    int to;
    int weight;
    edge(int f,int t,int w) : from(f), to(t), weight(w){ }
};


using Graph = vector<vector<Edge>>;
using graph = vector<vector<int>>;
using edges = vector<edge>;

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;
}

template <class T>
T lcm(T a, T b){
    return (a*b)/gcd(a,b);
}

bool isPalindrome(string s){
    string t = s;
    reverse(all(t));
    return s==t;
}

constexpr ll LNF = 1e18+7;

constexpr int INF = 1e9+7;



vector<int> dx = {-1,0,1,0,-1,1,-1,1};
vector<int> dy = {0,-1,0,1,1,-1,-1,1};

/* template */

int main(){
    ll n; cin >> n;
    string a;
    ll left = 0ll, right = n-1ll;
    cout << 0 << endl;
    cin >> a;
    if(a=="Vacant"){
        return 0;
    }
    string b;
    while(b!="Vacant"){
        ll mid = (left+right)/2ll;
        cout << mid << endl;
        cin >> b;
        if(b=="Vacant") return 0;
        if(mid%2==0){
            if(a==b){
                left = mid+1;
            }
            else{
                right = mid-1;
            }
        }
        else{
            if(a!=b){
                left = mid+1;
            }
            else{
                right = mid-1;
            }
        }
    }
}

Measured memory_bytes: 852
import std.stdio;
import std.algorithm;

void main()
{
	int[] mt = new int[10];
	foreach(mtnum; 0 .. 10)
	{
		readf("%d\n",&mt[mtnum]);
	}
	static bool highter(int x, int y)
	{
		return x > y;
	}
	sort!(highter)(mt);
	for(int i = 0;i < 3; i++)
	{
		writeln(mt[i]);
	}
}

Measured memory_bytes: 1068
#include "bits/stdc++.h"

using namespace std;

typedef long long ll;
typedef pair<int, int> P;
typedef vector<ll> VI;
typedef vector<VI> VVI;
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const int INF = numeric_limits<int>::max() / 2;
const int NEG_INF = numeric_limits<int>::min() / 2;
const int MOD = 1e9 + 7;

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

    string s;cin>>s;
    vector<char> sub;
    for(int i=0;i<(int)s.length();i++){
        if(s[i]!='x') sub.push_back(s[i]);
    }
    int res=0;
    int len=sub.size();
    for(int i=0;i<len/2;i++){
        if(sub[i]!=sub[len-1-i]){
            cout<<-1<<endl;
            return 0;
        }
    }
    len=s.length();
    int head=0,tail=len-1;
    while(head<tail){
        if(s[head]==s[tail]){
            head++;
            tail--;
        }
        else if(s[head]=='x'){
            res++;
            head++;
        }
        else{
            res++;
            tail--;
        }
    }
    cout<<res<<endl;
    return 0;
}


Measured memory_bytes: 592
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, s, e) for (int i = (int)(s); i <= (int)(e); i++)
#define printYesNo(is_ok) puts(is_ok ? "Yes" : "No");
#define SORT(v) sort(v.begin(), v.end());
#define RSORT(v) sort(v.rbegin(), v.rend());
#define REVERSE(v) reverse(v.begin(), v.end());

template <typename T>
void printlnVector(T v)
{
  rep(i, v.size())
  {
    cout << v[i] << endl;
  }
}

template <typename T>
void printVector(T v)
{
  rep(i, v.size())
  {
    cout << v[i] << " ";
  }
  cout << endl;
}

int main()
{
  string S;
  cin >> S;
  bool is_ok = false;
  for(int i1 = 0; i1 < S.size(); i1++)
  {
    for(int i2 = i1 + 1; i2 < S.size(); i2++)
    {
      if(S[i1] == 'C' && S[i2] == 'F')
        is_ok = true;
    }
  }

  if(is_ok)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;

  return 0;
}

Measured memory_bytes: 256
#[allow(unused_imports)]
use std::cmp;

// Input macro from https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
  (source = $s:expr, $($r:tt)*) => {
    let mut iter = $s.split_whitespace();
    input_inner!{iter, $($r)*}
  };
  ($($r:tt)*) => {
    #[allow(unused_mut)]
    let mut s = {
      use std::io::Read;
      let mut s = String::new();
      std::io::stdin().read_to_string(&mut s).unwrap();
      s
    };
    let mut iter = s.split_whitespace();
    input_inner!{iter, $($r)*}
  };
}

macro_rules! input_inner {
  ($iter:expr) => {};
  ($iter:expr, ) => {};

  ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
    let $var = read_value!($iter, $t);
    input_inner!{$iter $($r)*}
  };
}

macro_rules! read_value {
  ($iter:expr, ( $($t:tt),* )) => {
    ( $(read_value!($iter, $t)),* )
  };

  ($iter:expr, [ $t:tt ; $len:expr ]) => {
    (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
  };

  ($iter:expr, chars) => {
    read_value!($iter, String).chars().collect::<Vec<char>>()
  };

  ($iter:expr, usize1) => {
    read_value!($iter, usize) - 1
  };

  ($iter:expr, $t:ty) => {
    $iter.next().unwrap().parse::<$t>().expect("Parse error")
  };
}

const MOD: i32 = 1e9 as i32 + 7;

fn main() {
  input! {
    n: usize,
    a: [[i32; n]; n]
  }
  let mut dp = vec![0i32; 1 << n];
  dp[0] = 1;
  for ws in 1usize .. 1 << n {
    let m = ws.count_ones() as usize - 1;
    for w in 0 .. n {
      if ws & (1 << w) != 0 && a[m][w] == 1 {
        dp[ws] += dp[ws ^ (1 << w)];
        if dp[ws] > MOD {
          dp[ws] -= MOD;
        }
      }
    }
  }
  println!("{}", dp[(1 << n) - 1]);
}


Measured memory_bytes: 12540
#include <cstdio>
#include <iostream>
#include <string>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <vector>
#include <queue>
#include <stack>
#include <deque>
#include <map>
#include <bitset>
typedef unsigned long long int ll;
const ll INF = 876543210987654321;
const int MOD = 1000000007;
#define REP(i,n) for(int i=0;i<n;++i)
#define pd(x) cout<<x<<endl
using namespace std;
//vector<vector<int>>(h, vector<int>(w, f));


int main() {
	string s;
	cin >> s;
	ll a[26] = {};
	ll n = s.size();
	for (int i = 0; s[i]; ++i) {
		a[s[i] - 'a']++;

	}
	ll ans = 1;
	ans += n*(n - 1) / 2;
	for (int i = 0; i < 26; ++i) {
		if (a[i] > 1)ans -= a[i] * (a[i] - 1) / 2;
	}
	cout << ans << endl;
	int aa;
	cin >> aa;
	return 0;

}

Measured memory_bytes: 644
#include <iostream>
#include <functional>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <set>
#include <queue>
#include <stack>
#include <map>
#include <iomanip>
// #include <prettyprint.hpp>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;++i)
#define repi(i,n) for(ll i=n-1;i>=0;--i)
#define sll(n) scanf("%lld", &n);
#define slf(n) scanf("%lf", &n);
typedef long long ll;
typedef double lf;
static const ll max_n = 3010;
// static const ll mod = 1000000007;
static const ll max_value = 100000000000100;


// const int mod = 1000000007;
const int mod = 998244353;
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
  mint operator+(const mint a) const { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const { return pow(mod-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}

vector<vector<mint>> dp(max_n, vector<mint>(max_n, 0));
vector<ll> as(max_n, 0);
// vector<string> Qs(max_n);
ll N, M;

void Main(){
    ll N, S, a;
    sll(N);
    sll(S);

    rep(i, N){
        sll(a);
        as[i] = a;
    }

    dp[0][0] = 1;
    for(ll i=1;i<=N;i++){
        rep(j, S+1){
            dp[i][j] += dp[i-1][j] * 2;
            if(j >= as[i-1]){
                dp[i][j] += dp[i-1][j-as[i-1]];
            }
        }
    }

    // rep(i, N+1){
    //     printf("dp[%lld] = ", i);
    //     rep(j, S+1){
    //         printf("%lld ", dp[i][j].x);
    //     }
    //     printf("\n");
    // }

    cout << dp[N][S] << endl;

}

int main(){
    Main();

    return 0;

}

Measured memory_bytes: 74216
#include<bits/stdc++.h>
using namespace std;
#define FastRead ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ll long long int
#define endl '\n'
#define ld long double
#define FOR(i,a,n) for (ll i=(a);i<=(n);++i)
#define RFOR(i,a,n) for (ll i=(n);i>=(a);--i)
#define FI(i,n) for (ll i=0; i<(n); ++i)
#define ZERO(a) memset((a),0,sizeof((a)))
#define MINUS(a) memset((a),-1,sizeof((a)))
#define f first
#define s second
#define pb push_back
#define mk make_pair
#define all(g) g.begin(),g.end()
int fastMax(int x, int y) { return (((y-x)>>(32-1))&(x^y))^y; }
int fastMin(int x, int y) { return (((y-x)>>(32-1))&(x^y))^x; }
 
/*
░░░░░░░░░░░░░░░░░░░░░░░░░
░░█▀▀▄░░░░░░░░░░░▄▀▀█░░░░
░░█░░░▀▄░▄▄▄▄▄░▄▀░░░█░░░░
░░░▀▄░░░▀░░░░░▀░░░▄▀░░░░░
░░░░░▌░▄▄░░░▄▄░▐▀▀░░░░░░░
░░░░▐░░█▄░░░▄█░░▌▄▄▀▀▀▀█░
░░░░▌▄▄▀▀░▄░▀▀▄▄▐░░░░░░█░
░▄▀▀▐▀▀░▄▄▄▄▄░▀▀▌▄▄▄░░░█░
░█░░░▀▄░█░░░█░▄▀░░░░█▀▀▀░
░░▀▄░░▀░░▀▀▀░░▀░░░▄█▀░░░░
░░░░█░░░░░░░░░░░▄▀▄░▀▄░░░
░░░░█░░░░░░░░░▄▀█░░█░░█░░
░░░░█░░░░░░░░░░░█▄█░░▄▀░░
░░░░█░░░░░░░░░░░████▀░░░░
░░░░▀▄▄▀▀▄▄▀▀▄▄▄█▀░░░░░░░
░░░░░░░░░░░░░░░░░░░░░░░░░
*/
 
// I want to be the very best, like no one ever was, I will battle everyday to claim my rightful place
// #include <ext/pb_ds/assoc_container.hpp> // Common file
// #include <ext/pb_ds/tree_policy.hpp>     // Including tree_order_statistics_node_updat
// using namespace __gnu_pbds;
// typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
 
// I am questioning life and universe and 
// everything else after looking at this

const ll MAXN = 1e5 + 10;
ll a[MAXN];
ll gre[MAXN];

void solve(){
    ll n; cin>>n;

    FOR(i,1,n) cin>>a[i];

    ll ans = 0;

    FOR(i,2,n){
        if(a[i] <= a[i-1]){
            gre[i] = gre[i-1]+1;
        }else gre[i] = 0;
    }

    // FOR(i,1,n) clog<<gre[i]<<" ";

    ans = *max_element(gre+1,gre+n+1);

    cout<<ans<<endl;
} 
 
signed main(){
 
   FastRead;    
 
 
    ll t;
    t = 1; 
    // cin>>t;
    FOR(i,1,t){
        // cout<<"Case #"<<i<<": ";
        solve();
    }
}

Measured memory_bytes: 1792