akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <unordered_map>

using namespace std;
using ll = long long;

void _cin(){} template <class Head, class... Tail> void _cin(Head&& head, Tail&&... tail){ cin >> head; _cin(forward<Tail>(tail)...); }
void _cout(){ cout << "\n"; } template <class Head, class... Tail> void _cout(Head&& head, Tail&&... tail){ cout << head; _cout(forward<Tail>(tail)...); }
int gcd(int a, int b){ return (b == 0) ? a : gcd(b, a % b); }

#define Sq(x) (x)*(x)
#define For(i, n) for(int i = 0; i < (n); i ++)
#define Rep(n) For(_, n)
#define Range(c) c.begin(), c.end()
#define RevRange(c) c.rbegin(), c.rend()
#define Contains(c, x) (find(Range(c), x) != c.end())
#define Search(rb, re, x) distance(rb, find(rb, re, x))
#define Sort(a) sort(Range(a))
#define DeSort(a) sort(RevRange(a))
#define Reverse(c) reverse(Range(c))
#define Unique(a) a.erase(unique(Range(a)), a.end())
#define Cusum(T, xs, sxs) vector<T> sxs(xs.size()+1); For(i, (int)xs.size()) sxs[i+1] = sxs[i] + xs[i]
#define Cin(T, ...) T __VA_ARGS__; _cin(__VA_ARGS__)
#define Cins(T, n, xs) vector<T> xs(n); For(i, n) cin >> xs[i]
#define Cins2(T, n, xs, ys) vector<T> xs(n), ys(n); For(i, n) cin >> xs[i] >> ys[i]
#define Cins3(T, n, xs, ys, zs) vector<T> xs(n), ys(n), zs(n); For(i, n) cin >> xs[i] >> ys[i] >> zs[i]
#define Cinss(T, n, m, xs) Vec2(T, n, m, xs); For(i, n) For(j, m) cin >> xs[i][j]
#define Cinm(T, n, map) unordered_map<T, int> map; Rep(n){ Cin(T, x); map[x] ++; }
#define Cout(...) _cout(__VA_ARGS__)
#define Couts(xs) { for(const auto &e : xs) cout << e << " "; cout << "\n"; }
#define Coutyn(cond) Cout((cond) ? "yes" : "no")
#define CoutYn(cond) Cout((cond) ? "Yes" : "No")
#define CoutYN(cond) Cout((cond) ? "YES" : "NO")
#define vc vector
#define Mini(a, x) a = min(a, x)
#define Maxi(a, x) a = max(a, x)

// constexpr int MOD = 1e9+7;

int main(void){
    Cin(int, a, b, c, d);
    Cout(a % 2 == 0 ? (0.5) : (1.0 * (a-a/2) / a));
}

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

using namespace std;


int main() {
    int h,w;
    cin>>h>>w;
    char map[h][w];
    for (int i = 0; i < h; ++i) {
        for (int j = 0; j < w; ++j) {
            cin>>map[i][j];
        }
    }
    for (int k = 0; k < h; ++k) {
        for (int i = 0; i < w; ++i) {
            int count=0;
            if(map[k][i]=='.'){
                if(k!=0){
                    if(i!=0){
                        if(map[k-1][i-1]=='#')count++;
                    }
                    if(i!=w-1){
                        if(map[k-1][i+1]=='#')count++;
                    }
                    if(map[k-1][i]=='#')count++;
                }
                if(k!=h-1){
                    if(i!=0){
                        if(map[k+1][i-1]=='#')count++;
                    }
                    if(i!=w-1){
                        if(map[k+1][i+1]=='#')count++;
                    }
                    if(map[k+1][i]=='#')count++;
                }
                if(i!=0){
                    if(map[k][i-1]=='#')count++;
                }
                if(i!=w-1){
                    if(map[k][i+1]=='#')count++;
                }
                if(map[k][i]=='#')count++;
                cout<<count;
            }
            else cout<<'#';
        }
        cout<<endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <iomanip>
#include <utility>
#include <tuple>
#include <functional>
#include <bitset>
#include <cassert>
#include <time.h>
#define int long long
#define endl '\n'
#define INF 1000000000000000000
#define EPS 1e-10
#define all(a) a.begin(),a.end()
#define rep(i, n) for (int i = 0; i < (n); i++)
#define fi first
#define se second
#define pb push_back
#define double long double
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<ll, P> PP;
template<class T, class S> bool chmax(T &a, const S &b) { if (a < b) { a = b; return 1; } return 0; }
template<class T, class S> bool chmin(T &a, const S &b) { if (a > b) { a = b; return 1; } return 0; }
ll gcd(ll n, ll m) { return (m ? gcd(m, n%m) : n); }
ll lcm(ll n, ll m) { return n / gcd(n, m)*m; }


class unionfind {
	vector<int> par;
	vector<int> sz;
public:
	unionfind(int n) {
		par = vector<int>(n);
		for (int i = 0; i < n; i++) {
			par[i] = i;
		}
		sz = vector<int>(n, 1);
	}
	int find(int x) {
		if (par[x] == x) return x;
		else return par[x] = find(par[x]);
	}
	int si(int x) {
		return sz[find(x)];
	}
	void unite(int x, int y) {
		x = find(x);
		y = find(y);
		if (x == y) return;
		if (sz[x] < sz[y]) {
			par[x] = y;
			sz[y] += sz[x];
		}
		else {
			par[y] = x;
			sz[x] += sz[y];
		}
	}
};

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

	int n, m, k;
	cin >> n >> m >> k;
	unionfind uni(n);
	vector<int> a(m), b(m);
	vector<int> ans(n, -1);
	rep(i, m) {
		cin >> a[i] >> b[i];
		a[i]--; b[i]--;
		uni.unite(a[i], b[i]);
		ans[a[i]]--; ans[b[i]]--;
	}
	rep(i, n) {
		ans[i] += uni.si(i);
	}
	rep(i, k) {
		int c,d;
		cin >> c >> d;
		c--; d--;
		if (uni.find(c) == uni.find(d)) {
			ans[c]--; ans[d]--;
		}
	}
	rep(i, n) cout << ans[i] << ' ';
	cout << endl;
}

Measured memory_bytes: 4736
#pragma GCC optimize ("Ofast")
#include<bits/stdc++.h>
using namespace std;
inline int my_getchar_unlocked(){
  static char buf[1048576];
  static int s = 1048576;
  static int e = 1048576;
  if(s == e && e == 1048576){
    e = fread_unlocked(buf, 1, 1048576, stdin);
    s = 0;
  }
  if(s == e){
    return EOF;
  }
  return buf[s++];
}
inline void rd(int &x){
  int k;
  int m=0;
  x=0;
  for(;;){
    k = my_getchar_unlocked();
    if(k=='-'){
      m=1;
      break;
    }
    if('0'<=k&&k<='9'){
      x=k-'0';
      break;
    }
  }
  for(;;){
    k = my_getchar_unlocked();
    if(k<'0'||k>'9'){
      break;
    }
    x=x*10+k-'0';
  }
  if(m){
    x=-x;
  }
}
inline void rd(char &c){
  int i;
  for(;;){
    i = my_getchar_unlocked();
    if(i!=' '&&i!='\n'&&i!='\r'&&i!='\t'&&i!=EOF){
      break;
    }
  }
  c = i;
}
inline int rd(char c[]){
  int i;
  int sz = 0;
  for(;;){
    i = my_getchar_unlocked();
    if(i!=' '&&i!='\n'&&i!='\r'&&i!='\t'&&i!=EOF){
      break;
    }
  }
  c[sz++] = i;
  for(;;){
    i = my_getchar_unlocked();
    if(i==' '||i=='\n'||i=='\r'||i=='\t'||i==EOF){
      break;
    }
    c[sz++] = i;
  }
  c[sz]='\0';
  return sz;
}
template<class S, class T> inline S chmin(S &a, T b){
  if(a>b){
    a=b;
  }
  return a;
}
template<class S, class T> inline S chmax(S &a, T b){
  if(a<b){
    a=b;
  }
  return a;
}
const int L = 1'000'000;
char s[L + 1];
int A[L / 2 + 1];
int B[L / 2 + 1];
int main(){
  int Nzj9Y0kE, i;
  int n;
  rd(n);
  int aa = 0;
  int bb = 0;
  int cc = 0;
  for(Nzj9Y0kE=(0);Nzj9Y0kE<(n);Nzj9Y0kE++){
    int i;
    int l;
    l = rd(s);
    int mi = 0;
    int sum = 0;
    for(i=(0);i<(l);i++){
      sum += (s[i] == '(' ? +1 : -1);
      chmin(mi, sum);
    }
    int a = -mi;
    int b = sum - mi;
    if(a == b){
      chmax(cc, a);
    }
    if(a <  b){
      chmax(aa, a);
      A[a] += sum;
    }
    if(a >  b){
      chmax(bb, b);
      B[b] += sum;
    }
  }
  int mi = 0;
  int sum = 0;
  for(i=(0);i<(aa + 1);i++){
    if(A[i] == 0){
      continue;
    }
    chmin(mi, sum - i);
    sum += A[i];
  }
  chmin(mi, sum - cc);
  for(i=(bb + 1)-1;i>=(0);i--){
    if(B[i] == 0){
      continue;
    }
    sum += B[i];
    chmin(mi, sum - i);
  }
  puts(mi >= 0 && sum == 0 ? "Yes" : "No");
  return 0;
}
// cLay varsion 20200430-1

// --- original code ---
// const int L = 1'000'000;
// char s[L + 1];
// int A[L / 2 + 1], B[L / 2 + 1];
// {
// 	int n; rd(n);
// 	int aa = 0, bb = 0, cc = 0;
// 	rep(n) {
// 		int l; rd(s@l);
// 		int mi = 0, sum = 0;
// 		rep(i, l) {
// 			sum += (s[i] == '(' ? +1 : -1);
// 			mi <?= sum;
// 		}
// 		int a = -mi, b = sum - mi;
// 		if(a == b) { cc >?= a; }
// 		if(a <  b) { aa >?= a; A[a] += sum; }
// 		if(a >  b) { bb >?= b; B[b] += sum; }
// 	}
// 	
// 	int mi = 0, sum = 0;
// 	rep(i, aa + 1) {
// 		if(A[i] == 0) { continue; }
// 		mi <?= sum - i;
// 		sum += A[i];
// 	}
// 	mi <?= sum - cc;
// 	rrep(i, bb + 1) {
// 		if(B[i] == 0) { continue; }
// 		sum += B[i];
// 		mi <?= sum - i;
// 	}
// 	puts(mi >= 0 && sum == 0 ? "Yes" : "No");
// }


Measured memory_bytes: 4664
#include <stdio.h>

char s[105];

int main(){
    int N;
    scanf("%d", &N);
    scanf("%s", &s[1]);
    int cnt = 0, fill = 0;
    for(int i=1; i<=N; i++){
        if(s[i] == '(') cnt++;
        else cnt--;
        if(cnt < 0){ fill++; cnt = 0; }
    }
    while(fill--) printf("(");
    printf("%s", &s[1]);
    while(cnt--) printf(")");
    return 0;
}

Measured memory_bytes: 128
n = int(input())
A = []
for i in range(n):
    mark,number = map(str,input().split())
    A.append((mark, int(number), i))

def partition(A, p, r):
    x = A[r][1]
    i = p - 1
    for j in range(p,r):
        if A[j][1] <= x:
            i += 1
            A[i], A[j] = A[j], A[i]
    A[i+1], A[r] = A[r], A[i+1]
    return A, i + 1

def quickSort(A, p, r):
    if p < r:
        A, q = partition(A, p, r)
        quickSort(A, p, q-1)
        quickSort(A, q+1, r)
    return A

A = quickSort(A, 0, n-1)

is_stable = True
for i in range(1, len(A)):
    if(A[i-1][1] == A[i][1]) and (A[i-1][2] > A[i][2]):
        is_stable = False
        break
print('Stable') if is_stable else print('Not stable')
for i in range(len(A)):
    print("{0} {1}".format(A[i][0], A[i][1]))


Measured memory_bytes: 20164
<?php
fscanf(STDIN, '%d %d %d %d', $N, $A, $B, $C);
$l = [];
for ($i = 0; $i < $N; $i++) {
    fscanf(STDIN, '%d', $l[]);
}
$pat = pow(4, $N);
$ans = PHP_INT_MAX;
for ($i = 0; $i < $pat; $i++) {
    $x = str_split(str_pad(base_convert($i, 10, 4), $N, "0", STR_PAD_LEFT));
    $c = array_count_values($x);
    if (!isset($c[0])) continue;
    if (!isset($c[1])) continue;
    if (!isset($c[2])) continue;
    $tmp = [0, 0, 0, 0];
    $bar = [0, 0, 0, 0];
    for ($j = 0; $j < $N; $j++) {
        $tmp[$x[$j]] += $l[$j];
        $bar[$x[$j]]++;
    }
    $p = ($bar[0] + $bar[1] + $bar[2] - 3) * 10 + abs($A - $tmp[0]) + abs($B - $tmp[1]) + abs($C - $tmp[2]);
    $ans = min($ans, $p);
}
echo $ans;


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

#define pb	push_back
#define eb	emplace_back
#define mk	make_pair
#define fi	first
#define se	second
#define endl	'\n'

typedef long long ll;
typedef pair<int,int> ii;
typedef vector<ii> vii;
const int INF = 0x3f3f3f3f;
const double PI = acos(-1.0);

double ang(ll h, ll m) {
    double x = h*30;
    if(m) x += ((double)m/60)*30;
    double y = m*6;
    x = abs(x-y);
    if(x > 180) x = 360-x;
    return x*(PI/180ll);
}

int main() {
    ios_base::sync_with_stdio(false);
    ll a,b,h,m;
    cin >> a >> b >> h >> m;
    double ans = sqrt(a*a + b*b - 2*b*a*cos(ang(h,m)));
    cout << fixed << setprecision(9) << ans << endl;
    return 0;
}



Measured memory_bytes: 4168
#include <stdio.h>

int main(void){
  int W,H,x,y,r;

  scanf("%d %d %d %d %d",&W,&H,&x,&y,&r);

  if( ((x+r)<=W && (y+r)<=H) && ((x-r)>=0 && (y-r)>=0) ){
    puts("Yes");
  }else{
    puts("No");
  }

  return 0;

}

Measured memory_bytes: 584
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
  string a, ans="No";
    cin >> a;
      if((a[0]==a[1] && a[1]==a[2]) || (a[1]==a[2]&& a[2]==a[3])) ans="Yes";

    cout << ans << endl;

}

Measured memory_bytes: 256
import itertools
import numpy as np

X, N = list(map(int, input().split(' ')))
ps = input()
if len(ps)!=0:
    ps = list(map(int, ps.split(' ')))

ps_sort = list(sorted(ps))
not_in_ps = np.array([[abs(i-X), i] for i in range(-1, 102) if i not in ps_sort])
print(not_in_ps[np.argmin(not_in_ps[:,0], 0), 1])

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

#define FOR(i, a, b) for(int i=(a); i<(b); i++)
#define RFOR(i, a, b) for(int i=(a); i>=(b); i--)
#define rep(i, n) FOR(i, 0, n)
#define rrep(i, n) RFOR(i, n, 0)
#define dump(x)  cout << #x << " = " << (x) << endl;

typedef long long ll;
typedef pair<int, int> ii;
const ll INF = 1e18;
const int inf = 1e8;


void solve()
{
  ll N;
  scanf("%lld",&N);
  vector<string> s(N);
  for(int i = 0 ; i < N ; i++){
    cin >> s[i];
  }
  ll M;
  scanf("%lld",&M);
  vector<string> t(M);
  for(int i = 0 ; i < M ; i++){
    cin >> t[i];
  }
  map<string,ll> bmp;
  map<string,ll> rmp;
  for(auto p:s) {
    bmp[p] += 1;
    rmp[p] = 0;
  }
  for(auto p:t) {
    rmp[p] += 1;
  }
  ll ans=0;
  for(auto p:bmp) {
    ans = max(ans, p.second-rmp[p.first]);
  }
  cout << ans << endl;
}

int main()
{
  solve();
  return 0;
}


Measured memory_bytes: 256
S = input()
N = len(S) - 1
ans = 0

# bit全探索
for bit in range(2 ** N):
    k = 0
    for j in range(N):
        if (bit >> j) & 1:
            ans += int(S[k:j + 1])
            k = j + 1
    ans += int(S[k:])
print(ans)


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

int main(){
  const int NUM = 1e6;
  bool prime[NUM];
  for(int i=2;i<NUM;i++)
    prime[i] = true;
  for(int i=2;i*i<NUM;i++)
    for(int k=2;i*k<NUM;k++)
      prime[i*k]=false;
  int n,c;
  while(cin>>n){
    if(!n)break;c=0;
    for(int i=2,k=0;k<n;i++)if(prime[i])c+=i,k++;
    cout<<c<<endl;
  }
}

Measured memory_bytes: 0
#include<iostream>
#define N 36
using namespace std;
int n,a[N],a1[N],a2[N];
char c[N],c1[N],c2[N];

void BubbleSort(){
  for(int i=0;i<n;i++)
    for(int j=n-1;j>=i+1;j--){
      if(a1[j]<a1[j-1]){
	int t=a1[j];
	a1[j]=a1[j-1];
	a1[j-1]=t;
	char t2=c1[j];
	c1[j]=c1[j-1];
	c1[j-1]=t2;
      }
    }
}

void SelectionSort(){
  for(int i=0;i<n;i++){
    int minj=i;
    for(int j=i;j<n;j++){
      if(a2[j]<a2[minj]){
	minj=j;
      }
    }
    int t=a2[i];
    a2[i]=a2[minj];
    a2[minj]=t;
    char t2=c2[i];
    c2[i]=c2[minj];
    c2[minj]=t2;
  }
}

bool isStable(char *x,int *y){
  for(int i=1;i<=9;i++){
    int start=0;
    for(int j=0;j<n;j++){
      if(i!=a[j])continue;
      for(int k=start;k<n;k++){
	if(i!=y[k])continue;
	if(c[j]!=x[k])return false;
	start=k+1;
	break;
      }
    }
  }
  return true;
}

void output(char *x,int *y){
  for(int i=0;i<n;i++){
    if(i)cout<<' ';
    cout<<x[i]<<y[i];
  }
  cout<<endl;
}

int main(){
  cin>>n;
  for(int i=0;i<n;i++){
    cin>>c[i]>>a[i];
    c1[i]=c2[i]=c[i];
    a1[i]=a2[i]=a[i];
  }
  BubbleSort();
  output(c1,a1);
  if(isStable(c1,a1))cout<<"Stable"<<endl;
  else cout<<"Not stable"<<endl;
  SelectionSort();
  output(c2,a2);
  if(isStable(c2,a2))cout<<"Stable"<<endl;
  else cout<<"Not stable"<<endl;
  return 0;
}

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

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

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


Measured memory_bytes: 720
n,m=gets.chomp.split(" ").map(&:to_i)
#p=Array.new(m)
#s=Array.new(m)
pena=Array.new(n){0}
is_ac=Array.new(n){false}
m.times do|i|
  p,s=gets.chomp.split(" ")
  pena[p.to_i-1]+=1 if s=="WA" and !is_ac[p.to_i-1]
  is_ac[p.to_i-1]=true if s=="AC"
end
ans1=0
ans2=0
n.times do|i|
  if is_ac[i]
    ans1+=1
    ans2+=pena[i]
  end 
end
puts "#{ans1} #{ans2}"



Measured memory_bytes: 3324
import math

def isprime(x):
    if x == 2:
        return True
    
    if x < 2 or x % 2 == 0:
        return False
    
    i = 3
    while i <= math.sqrt(x):
        if x % i == 0:
            return False
        i += 2
    
    return True

cnt = 0

n = int(input())

for i in range(n):
    x = int(input())
    if isprime(x) == True:
        cnt += 1
print(cnt)


Measured memory_bytes: 5676
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<ll,ll>;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep2(i,m,n) for(int (i)=(m);(i)<(n);(i)++)
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()
const ll INF = 1LL<<60;
const ll MOD = 1e9+7;


int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll a,b;cin>>a>>b;
    cout<<a*b<<endl;
    return 0;
}

Measured memory_bytes: 3608
object Main {
  def main(args: Array[String]) {

    val numList = (1 to 13).toSet
    val typeList: List[String] = List("S", "H", "C", "D")

    var list: List[String] = List()
    for (line <- scala.io.Source.stdin.getLines()) {
      list = list :+ line
    }
    list = list.slice(1, list.length)

    var cardMap = Map[String, Set[Int]]()

    for (line <- list) {
      var Array(k, v) = line.split(" ")
      var g: Set[Int] = cardMap.getOrElse(k, Set())
      if (g == Set()) {
        cardMap += k -> Set(v.toInt)
      } else {
        g = g + v.toInt
        cardMap += k -> g
      }
    }

    for (t <- typeList) {
      for (dv <- (numList &~ cardMap.get(t).get).toList.sorted(Ordering[Int])) println(t + " " + dv)
    }
  }
}

Measured memory_bytes: 44260
import java.util.Scanner;

/**
 * https://abc046.contest.atcoder.jp/tasks/arc062_b
 */
public class Main {

	public static void main(String[] args) {
		
		Scanner sc = new Scanner(System.in);
		char[] s = sc.next().toCharArray();
		sc.close();
		
		int p = 0;
		int g = 0;
		int count = 0;
		for(int i=0; i<s.length; i++){
			if(p<g){
				p++;
				if(s[i]=='g')
					count++;
			}else{
				g++;
				if(s[i]=='p')
					count--;
			}
		}
		System.out.println(count);
	}

}

Measured memory_bytes: 25812
from enum import Enum
from queue import Queue

import numpy as np

import collections
import bisect
import sys
import math

from scipy.sparse.csgraph import floyd_warshall

BIG_NUM = 200000000000
MOD = 1000000007
EPS = 0.000000001

N = int(input())
ans = N

for i in range(1,int(np.sqrt(N))+1):
    if N % i == 0:
        j = N//i
        ans = min(ans, i+j-2)

print(ans)


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

int main(){
int n,c=0,k;
cin >> n;
int a[n];
for(int i=0;i<n;i++)
  cin >> a[i];
sort(a,a+n);
k=a[n/2-1]+1;
if(k<=a[n/2])
  while(k<=a[n/2]){
    k++;
   c++;}
cout << c;
}

Measured memory_bytes: 768
#include<iostream>
#include<vector>
using namespace std;
const int INF = 1e9+5;
int main()
{
    int n; cin>>n;
    int arr[n];
    for(int i=0;i<n;i++)
        cin>>arr[i];
    vector<int> dp(n,INF);
    dp[0] = 0;
    for(int i=0;i<n;i++)
    {
        for(int j:{i+1,i+2})
        {
            dp[j] = min(dp[j],dp[i]+abs(arr[i] - arr[j]));
        }
    }
    cout<<dp[n-1];
    return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <limits.h>
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <list>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <queue>
#include <unordered_map>
#include <unordered_set>
#include <cassert>

#define REP(i,n) for(int i=0;i<n;i++)
#define all(x) (x).begin(),(x).end()
#define mp make_pair
#define pb push_back
#define eb emplace_back

typedef long long ll;
using namespace std;

int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);
    // cout << fixed << setprecision(20);
    map<int,int> m;
    for(int i = 0;i < 3;i++){
        int x;cin >> x;
        m[x]++;
    }
    cout << (m.size()==2 ? "Yes" : "No") << '\n';

    return 0;
}


Measured memory_bytes: 256
# 組み合わせ　n_C_r
def comb(n,r):
    r = min(r,n-r)
    result = 1
    for i in range(n-r+1,n+1):
        result *= i
    for i in range(1,r+1):
        result //= i
    return result

N,A,B = map(int,input().split())
V = list(map(int,input().split()))

V.sort(reverse=True)

ave = sum(V[:A])/A
pat = 0
note = 0
cnt = 0
for v in V:
    if v > V[A-1]:
        note += 1
    elif v == V[A-1]:
        cnt += 1
    elif v < V[A-1]:
        break

if V[0] == V[A-1]:
    for i in range(A-note,B+1-note):
        if i > cnt:
            break
        pat += comb(cnt,i)
else:
    pat = comb(cnt,A-note)

print(ave)
print(pat)

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

int main() {
  int N,big,num;
  big = 0;
  cin >> N;
  vector<int> vec(N);
  for(int i=0;i<N;i++){
    cin >> vec.at(i);
  }
  for(int i=0;i<N-1;i++){
    for(int j=i+1;j<N;j++){
      num = vec.at(i)-vec.at(j);
      if(num<0){
        num = -num;
      }
      big = max(big,num);
    }
  }
  cout << big << endl;
}

Measured memory_bytes: 256
// #include <bits/stdc++.h>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <utility>
#include <numeric>
#include <vector>
#define REP(i, n) for(int i=0;i<int(n);++i)
// copy用
// for(int i=0;i<int(n);++i) {
using namespace std;
template<class A>void pr(A a){cout << (a) << endl;}
template<class A,class B>void pr(A a,B b){cout << a << " "  ;pr(b);}
template<class A,class B,class C>void pr(A a,B b,C c){cout << a << " " ;pr(b,c);}
template<class A,class B,class C,class D>void pr(A a,B b,C c,D d){cout << a << " " ;pr(b,c,d);}
// vectorからindex番目の要素を削除する
template<typename T>
void remove(std::vector<T>& vector, unsigned int index)
{
    vector.erase(vector.begin() + index);
}

int main(void) {
  int N;
  vector<char>S;
  cin >> N;
  REP(i,N) {
    char s;
    cin >> s;
    S.push_back(s);
  }
  vector<char>ans;
  ans.push_back(S[0]);
  for(int i=1;i<N;++i) {
    if (S[i-1]!=S[i]) {
      ans.push_back(S[i]);
    }
  }
  pr(ans.size());
  return 0;
}



Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin>>n;
    set <int> s;
    while(n--)
    {
        int x;
        cin>>x;
        if(s.find(x)!=s.end())
            s.erase(x);
        else
            s.insert(x);
    }
    cout<<s.size();
    return 0;
 } 

Measured memory_bytes: 4864
/*
Name                     : Harry Singh (:)
Age                      : 20 (:)
College                  : Lovely Professional University (:)
Email                    : harryamneet600@gmail.com (:)
Hobbies                  : Coding and Typeracer (:)
Goal                     : Long term is fixed and Short term is changing everyday (:)
Relatoinship Status      : Single (:)
Phone no                 : 91-********77 (:)
Waheguru Ji ka Khalsa, Waheguru Ji ki Fateh;
*/
#include<bits/stdc++.h>
#define int long long
#define double double
#define io ios_base::sync_with_stdio(false),cin.tie(nullptr);
#define ipair pair<int,int>
#define pb push_back
#define f(i,n) for(int i=0;i<n;i++)
#define fo(i,n) for(int i=n;i>=0;i--)
#define F(i,n) for(int i=1;i<=n;i++)
#define f_a(a,i,n) for(int i=a;i<=n;i++)
#define f_b(a,i,b) for(int i=a;i<=b;i++)
#define FO(i,n) for(int i=n;i>=1;i--)
#define mod 1000000007
using namespace std;
#define tr cout<<"\n" 
#define br break
#define N 300005 
#define inf 10000000000000009

void Waheguru()
{

	int n,k;
	cin>>n>>k;
	int a[n+1];
	F(i,n)cin>>a[i];
	int pre[n+1]={0};
	int mx=0;
	for(int i=1;i<=n;i++)
    pre[i]=pre[i-1]+a[i];

   for(int i=k;i<=n;i++)
   	if(pre[i]-pre[i-k]>mx)mx=pre[i]-pre[i-k];


  cout<<fixed<<setprecision(12)<<0.5*(k+mx);tr;




	
}


 
 
int32_t main()
{
#ifndef ONLINE_JUDGE
 freopen("input.txt","r",stdin);
 freopen("output.txt","w",stdout);
#endif
    io;
    int g=1;
    while (g--)Waheguru();
    return 0;
}

Measured memory_bytes: 6888
#include<bits/stdc++.h>
#define ll long long 
#define inf 1000000007 
#define sort(vec) sort((vec).begin(),(vec).end());
#define rever(vec) reverse((vec).begin(),(vec).end());
#define unsort(vec) sort((vec)); rever((vec));
using namespace std;

int main() {
	int x;
	cin>>x;
	int lim=-100007;
	for(int i=1;i<=sqrt(x)+1;i++) {
		for(int j=1;j<=sqrt(x)+1;j++) {
			if(pow(i,j)<=x) {
				if(lim<pow(i,j)) {
					lim=pow(i,j);
				}
			}
		}
	}
	cout<<lim<<endl;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
ll mod = 1000000007;

ll r(ll x, ll y) {
  if (y == 0) return 1;
  else if (y % 2 == 0) return r(x, y/2) * r(x, y/2) % mod;
  else return x * r(x, (y-1)/2) % mod * r(x, (y-1)/2) % mod;
}

int main() {
  ll H;
  cin >> H;
  vector<ll> h(301);
  for (int i = 0; i < 301; i++) {
    h[i] = i * i;
    h[i] *= i;
    h[i] *= i;
    h[i] *= i;
  }
  bool f = 0;
  for (int i = 0; i < 300; i++) {
    for (int j = 0; j < 300; j++) {
      ll hh = h[i] - h[j];
      ll hH = h[i] + h[j];
      ll Hh = -h[i] - h[j];
      ll HH = -h[i] + h[j];
      if (H == hh) {
        cout << i << ' ' << j <<endl;
        f = 1;
        break;
      }
      else if (H == hH) {
        cout << i << ' ' << 0 - j <<endl;
        f = 1;
        break;
      }
      else if (H == Hh) {
        cout << 0-i << ' ' << j <<endl;
        f = 1;
        break;
      }
      else if (H == HH) {
        cout << 0-i << ' ' << 0 - j <<endl;
        f = 1;
        break;
      }
    }
    if (f) break;
  }
}

Measured memory_bytes: 3604
n,*a=$<.map &:to_i
a.sort!
p [
  (0...n).map{|i|i%2==0 ? a[i/2] : a[n-i/2-1]},
  (0...n).map{|i|i%2==1 ? a[i/2] : a[n-i/2-1]}
].map{|b|
  c=(0...n).map{|i|(b[i-1]-b[i]).abs}
  c.reduce(:+)-c.min
}.max

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

int main(void){
    int N;
    cin >> N;
    vector<ll> A(N), B(N);
    for (int i = 0; i < N; i++) {
        cin >> A[i] >> B[i];
    }
    
    sort(A.begin(), A.end());
    sort(B.begin(), B.end());
    if (N % 2 == 1) {
        cout << B[N/2] - A[N/2] + 1 << endl;
    }
    else {
        cout << ll(((B[N/2]+B[N/2-1]) / 2.0 - (A[N/2]+A[N/2-1]) / 2.0) * 2 + 1);
    }
}


Measured memory_bytes: 6384
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Scanner;

public class Main {

	public static boolean hiekou = false;
	public static int intHiekou = 0;

	public static void main(String[] args) {
		// 標準入力
		Scanner sc = new Scanner(System.in);

		String line1 = sc.nextLine();
		List<String> lines1 = Arrays.asList(line1.split(" "));
		Integer N = Integer.parseInt(lines1.get(0));
		Integer M = Integer.parseInt(lines1.get(1));

		List<String> Ns = new ArrayList<String>();
		List<String> Ms = new ArrayList<String>();
		List<Integer> resList = new ArrayList<Integer>();

		for(int i = 0;i <N; i++) {
			Ns.add(sc.nextLine());
		}
		for(int j = 0;j < M; j++) {
			Ms.add(sc.nextLine());
		}

		List<String> ab = null;
		int a = 0;
		int b = 0;
		List<String> cd = null;
		int c = 0;
		int d = 0;
		int man = 0;
		int res = 0;
		int newman = 0;

		for(int j = 0;j < Ns.size(); j++) {
			ab = Arrays.asList(Ns.get(j).split(" "));
			a = Integer.parseInt(ab.get(0));
			b = Integer.parseInt(ab.get(1));
			man = 999999999;
			for(int k = 0;k < Ms.size(); k++) {
				cd = Arrays.asList(Ms.get(k).split(" "));
				c = Integer.parseInt(cd.get(0));
				d = Integer.parseInt(cd.get(1));
				newman = Math.abs(a - c) +  Math.abs(b - d);
				if(newman < man) {
					res = k+1;
					man = newman;
				}
			}
			resList.add(res);
		}

		for(int z = 0;z < resList.size(); z++) {
			System.out.println(resList.get(z));
		}

	}

}

Measured memory_bytes: 22996
#!/usr/bin/env python

from collections import deque
import itertools as it
import sys
import math

sys.setrecursionlimit(1000000)

INF = 10 ** 18

N, M = map(int, raw_input().split())
cost = [0,2,5,5,4,5,6,3,7,6]
A = sorted(map(int, raw_input().split()))

DP = [0] + [-1] * N
ans = [0, 0] * N

for i in range(1, N + 1):
    for j in A:
        pos = i - cost[j]
        if pos >= 0 and DP[pos] >= 0 and DP[i] <= DP[pos] + 1:
            DP[i], ans[i] = DP[pos] + 1, j

S = ""
pos = N
while pos:
    S += str(ans[pos])
    pos -= cost[ans[pos]]

print S

Measured memory_bytes: 3576
import std.algorithm;
import std.array;
import std.conv;
import std.math;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

T read(T)() { return readln.chomp.to!T; }
T[] reads(T)() { return readln.split.to!(T[]); }
alias readint = read!int;
alias readints = reads!int;

void main() {
    int[] a;
    foreach (_; 0..5) a ~= readint;

    // 10 単位で切り上げ
    auto b = a.map!(e => (e + 9) / 10 * 10);
    // 10 の倍数との差分がもっとも大きい料理を最後に作る
    int c = a.zip(b).map!(e => e[1] - e[0]).reduce!max;
    writeln(b.sum - c);
}


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

int main(){
  int ans;
  int A=0;
  int B=0;
  string s;
  cin >> s;
  for(int i=0; i<s.size(); ++i){
    if(s.at(i)=='0') A+=1;
    if(s.at(i)=='1') B+=1;
  }
  ans=min(A,B)*2;
  cout<<ans<<endl;
}


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

using namespace std;

#define rep(i,N) for (int i = 0; i < N; i++)
#define llong long long

#define int long long

int N;

signed main() {
    cin >> N;

    int root = sqrt(N)+1;
    int res  = 1+N;
    for (int i = root; i >= 1; i--) {
        if (!(N%i)) {
            res = i + N/i;
            break;
        }
    }
    cout << res-2 << endl;
    return 0;
}


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

int main(void){
  string x;
  cin >> x;
  int a = 0;
  for(int i = 0; i <=3; i++){
    if(x[i] == '+'){
      a++;
    }else{
      a--;
    }
  }  
  cout << a << endl;
}

Measured memory_bytes: 256
import java.io.*;
import java.math.*;
import java.util.*;
public class Main { 

	public static void main(String[] args) { //BRUH
		Scanner input = new Scanner(System.in);
		long X = input.nextLong();
		long Y = input.nextLong();
		long ans = 0;
		long mod = (long)(1e9+7);
		long[] fact = new long[1000001]; //[Factorial,Inverse]
		fact[1]=1;
		for (long i = 2; i <= 1000000; i++) {
			fact[(int) i]=fact[(int) (i-1)]*i;
			fact[(int) i]%=mod;
		}
		if ((X+Y)%3==0) {
			long min = Math.min(X, Y);
			long max = Math.max(X, Y);
			if (max<=min*2) {
				if (max==min*2) ans=1;
				else {
					long diff = max-min;
					long sub = min-diff;
					long totalMoves = sub/3; //Each move increases sum of coordinates by 3
					totalMoves*=2; //Each move alters x AND y though so need to 
					//multiply by 2 to avoid WA
					max-=sub;
					min-=sub;
					totalMoves+=min;
					long chooseOptions = sub/3;//(3,3) requires one of each knight move
					long inv1 = FastExp(fact[(int) chooseOptions],mod-2,mod);
					long inv2 = FastExp(fact[(int) (totalMoves-chooseOptions)],mod-2,mod);
					ans=fact[(int) totalMoves];
					ans*=inv1;
					ans%=mod;
					ans*=inv2;
					ans%=mod;
				}
			}
		}
		System.out.println(ans);
	}	
	public static long FastExp(long base, long exp, long mod) {
		long ans = 1;
		while (exp>0) {
			if (exp%2==1) ans*=base;
			base*=base;
			exp/=2;
			base%=mod;
			ans%=mod;
		}
		return ans;
	}
}

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

int main(){
    int n,m,i,j;
    int **A,*b,*c;

    scanf("%d %d",&n,&m);
    A=malloc(sizeof(int*)*n);
    for(i=0;i<n;i++)
        A[i]=(int*)malloc(sizeof(int)*m);
    b=(int*)malloc(sizeof(int)*m);
    c=(int*)malloc(sizeof(int)*n);

    for(i=0;i<n;i++)
        c[i]=0;

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


    for(i=0;i<n;i++){
        for(j=0;j<m;j++){
            c[i]+=A[i][j]*b[j];
        }
    }
    for(i=0;i<n;i++)
        printf("%d\n",c[i]);

    free(A);free(b);free(c);
return 0;
}

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

int main(){
  ll n;
  cin>>n;
  map<ll,int> m;
  ll a=n;
  for(ll i=2;i*i<=n;i++){
    while(a%i==0){
      m[i]++;
      a/=i;
    }
  }
  if(a!=1) m[a]++;
  int ans=0;
  for(auto p:m){
    int b=p.second;
    int i=0;
    while(i*(i+1)/2<=b){
      i++;
    }
    ans+=i-1;
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 3632
#include <iostream>
#include <map>
#include <vector>
#include <cassert>
#include <unordered_set>
#include <set>
#include <bitset>
#include <memory.h>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <queue>

using namespace std;
 
#define sqr(a) ((a)*(a))
#define all(a) (a).begin(), (a).end()
 
const int MOD = (int) 1e9 + 7;
const int MAGIC = 400;

long long binPow(long long a, long long b) {
    if (b == 0)
        return 1;

    long long ans = binPow(a, b / 2);
    ans = ans * ans % MOD;

    if (b % 2)
        ans = ans * a % MOD;

    return ans;
}

int main() {
    // freopen("input.txt", "r", stdin);
    ios_base::sync_with_stdio(0);
    cin.tie(0);

    int x, y;
    cin >> x >> y;

    long long ans = 0;
    if (x == 3)
        ans += 100000;
    if (x == 2)
        ans += 200000;
    if (x == 1)
        ans += 300000;

    swap(x, y);

    if (x == 3)
        ans += 100000;
    if (x == 2)
        ans += 200000;
    if (x == 1)
        ans += 300000;

    if (x == y && x == 1)
        ans += 400000;

    cout << ans << "\n";
}


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

using namespace std;

int main(){
	ios_base::sync_with_stdio(false);
	cout << setiosflags(ios::fixed) << setprecision(10);
	int t, d, ta, tb, da, db;
	cin >> t >> d >> ta >> tb >> da >> db;
	double answer = 1e100;
	for(int i = 0; i * da <= d; ++i){
		for(int j = 0; i * da + j * db <= d; ++j){
			if(i == 0 && j == 0){ continue; }
			const double a = i * da * ta, b = j * db * tb;
			const double y = (a + b) / (i * da + j * db);
			answer = min(answer, abs(y - t));
		}
	}
	cout << answer << endl;
	return 0;
}

Measured memory_bytes: 1272
def solve():
    n = int(input())
    A = list(map(int, input().split()))
    B = list(map(int, input().split()))
    ans = 0
    for i in range(n):
        ans += min(B[i], A[i] + A[i + 1])
        A[i + 1] = min(A[i + 1], max(A[i] + A[i + 1] - B[i], 0))
    print(ans)


solve()


Measured memory_bytes: 23896
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <string>
#include <cstring>
#include <queue>
using namespace std;



int main(){
    //freopen("in.txt","r",stdin);
    char A[15],B[15],C[15];
    scanf("%s%s%s",A,B,C);
    int lenA=strlen(A);
    int lenB=strlen(B);
    if(A[lenA-1]==B[0]&&B[lenB-1]==C[0]){
        printf("YES\n");
    }else printf("NO\n");
    return 0;
}


Measured memory_bytes: 256
/*
このコード、と～おれ!
Be accepted!
∧＿∧　
（｡･ω･｡)つ━☆・*。
⊂　　 ノ 　　　・゜+.
　しーＪ　　　°。+ *´¨)
 　　　　　　　　　.· ´¸.·*´¨) ¸.·*¨)
		  　　　　　　　　　　(¸.·´ (¸.·'* ☆
					*/

#include <stdio.h>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstring>
#include <vector>
#include <numeric>
#include <iostream>
#include <random>
#include <map>
#include <unordered_map>
#include <queue>
#include <regex>
#include <functional>
#include <complex>
#include <list>
/*多倍長整数/cpp_intで宣言
#include <boost/multiprecision/cpp_int.hpp>
using namespace boost::multiprecision;
*/

//#pragma GCC target ("avx2")
//#pragma GCC optimization ("O3")
//#pragma GCC optimization ("unroll-loops")
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define rep1(i, n) for(int i = 1; i <= (n); ++i)
#define rep2(i, n) for(int i = 2; i < (n); ++i)
#define repr(i, n) for(int i = n; i >= 0; --i)
#define reprm(i, n) for(int i = n - 1; i >= 0; --i)
#define printynl(a) printf(a ? "yes\n" : "no\n")
#define printyn(a) printf(a ? "Yes\n" : "No\n")
#define printYN(a) printf(a ? "YES\n" : "NO\n")
#define printin(a) printf(a ? "possible\n" : "imposible\n")
#define printdb(a) printf("%.50lf\n", a)//少数出力
#define printdbd(a) printf("%.16lf\n", a)//少数出力(桁少なめ)
#define prints(s) printf("%s\n", s.c_str())//string出力
#define all(x) (x).begin(), (x).end()
#define allsum(a, b, c) ((a + b) * c / 2)//等差数列の和、初項,末項,項数
#define pb push_back
#define priq priority_queue
#define rpriq priq<int, vector<int>, greater<int>>
#define deg_to_rad(deg) (((deg)/360.0)*2.0*PI)
#define rad_to_deg(rad) (((rad)/2.0/PI)*360.0)
#define Please return
#define AC 0
#define addf(T) [](T a, T b){return (a + b);}
#define minf(T) [](T a, T b){return min(a, b);}
#define maxf(T) [](T a, T b){return max(a, b);}


using ll = long long;

constexpr int INF = 1073741823;
constexpr int MINF = -1073741823;
constexpr ll LINF = ll(4661686018427387903);
constexpr ll MOD = 1000000007;
const long double PI = acos(-1.0L);

using namespace std;

void scans(string& str) {
	char c;
	str = "";
	scanf("%c", &c);
	if (c == '\n')scanf("%c", &c);//最初の改行対策
	while (c != '\n' && c != -1) {
		str += c;
		scanf("%c", &c);
	}
}

void scanc(char& str) {
	char c;
	scanf("%c", &c);
	if (c == -1)return;
	while (c == '\n') {
		scanf("%c", &c);
	}
	str = c;
}

double acot(double x) {
	return PI / 2 - atan(x);
}

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

ll lcm(ll number1, ll number2) {//lcmを求める
	return number1 / gcd(number1, number2) * number2;
}

ll LSB(ll n) { return (n & (-n)); }

/*-----------------------------------------ここからコード-----------------------------------------*/



int main() {

	int n;
	ll k;
	scanf("%d%lld", &n, &k);
	vector<pair<int, int>> a(n);
	rep(i, n)scanf("%d%d", &a[i].first, &a[i].second);
	sort(all(a));
	int ans = 0;
	for (int i = 0; k > 0; ++i) {
		ans = a[i].first;
		k -= a[i].second;
	}
	printf("%d\n", ans);

	Please AC;
}


Measured memory_bytes: 1024
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
using LL = long long;

int main() {
	LL K, N;
	cin >> K >> N;
	vector<LL> A(N);
	for (int i = 0; i < N; i++) {
		cin >> A[i];
	}
	sort(A.begin(), A.end());
	LL ans = 0;
	for (int i = 1; i < N; i++) {
		LL temp = A[i] - A[i - 1];
		ans = max(temp, ans);
	}
	LL t = A[0] - A[N - 1] + K;
	ans =  K -max(ans, t);
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 4848
#include<cstdio>
int main(){
	int a,b,c,x,y,z,t;
	for(;~scanf("%d%d%d%d%d%d",&a,&b,&c,&x,&y,&z);printf("%d %d %d\n",t/60/60,(t%3600)/60,t%60))
		t=(x-a)*3600+(y-b)*60+z-c;
}

Measured memory_bytes: 0
# count # char
def count_black(grid,painted_row,painted_col):
    count = 0
    for id_row,row in enumerate(grid):
        for id_col,item in enumerate(row):
            if painted_row[id_row] == 0 and painted_col[id_col] == 0 and item == "#":
                count += 1
    return count


# generate a binary array, len = limit
def generate_selection(limit=0):
    result = []
    arr = [0 for i in range(limit)]
    max_result_len = limit**2

    while True:
        result.append(arr.copy())

        pos_to_change = -1
        for i in range(limit-1,-1,-1):
            if arr[i] == 0:
                pos_to_change = i
                break
        
        if pos_to_change == -1:
            break
        
        arr[pos_to_change] = 1
        for i in range(pos_to_change+1,limit):
            arr[i] = 0
    
    return result

if __name__ == "__main__":
    h,w,k = [int(i) for i in input().split()]
    grid = []
    for i in range(h):
        row = input()
        grid.append(row)
    
    # generate configuration for row and col selection
    row_selections = generate_selection(limit=h)
    col_selections = generate_selection(limit=w)


    result = 0
    for row_selection in row_selections:
        for col_selection in col_selections:
            if count_black(grid,row_selection,col_selection) == k:
                result += 1
    
    print(result)



Measured memory_bytes: 9264
#include <iostream>

using namespace std;

int main() {
    char s[4];
    cin >> s;

    int ans=0, i;
    for(i=0; i<3; i++) {
        if(s[i]=='o') ans += 1;
    }

    cout << ans*100+700 << endl;

    return 0;

}

Measured memory_bytes: 256
import java.math.BigDecimal;
import java.math.BigInteger;
import java.util.Scanner;
import javax.sound.midi.SysexMessage;
  
public class Main{      
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int i = 0;
        for(;i<1000;i++){
            int ans=0;
            BigInteger m = sc.nextBigInteger();
            if(m.compareTo(BigInteger.ZERO)==0)
                break;
            int len = String.valueOf(m).length();
            for (int j = 0; j<len; j++)
            {
                ans += Character.getNumericValue(String.valueOf(m).charAt(j));
            }
            System.out.println(ans);  
        }
       
    }
}              

    


Measured memory_bytes: 80164
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, l, r) for (int i = l; i <= (int)(r); i++)
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define MOD (int) (1e9+7)
#define INF (int) 2e9
#define LLINF (ll) 2e18

int d[205][205];
int n;

void warshall_floyd() {
    for(int k=1; k<=n; k++)
        for(int i=1; i<=n; i++)
            for(int j=1; j<=n; j++){
                d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
            }
}

int main(){
    int m, r;
    cin >> n >> m >> r;
    int rs[r];

    rep(i, r) cin >> rs[i];
    repr(i, 1, n) repr(j, 1, n) if(i!=j) d[i][j] = INF/2;

    rep(i, m){
        int a, b, c;
        cin >> a >> b >> c;
        d[a][b] = c;
        d[b][a] = c;
    }

    warshall_floyd();

    int ans = INF;
    sort(rs, rs+r);
    do{
        int tmp = 0;
        rep(i, r-1){
            tmp += d[rs[i]][rs[i+1]];
        }
        chmin(ans, tmp);

    }while(next_permutation(rs, rs+r));

    cout << ans << endl;
    // printf("%d\n", N);
    return 0;
}

Measured memory_bytes: 384
a = input().split()
N = int(a[0])
budget = int(a[1])
b = [int(s) for s in input().split()]
c = sorted(b)
d = int(0)
for i in range(N-1):
  if budget >= c[i]:
    budget = budget - c[i]
    d = d + 1
  else:
    break

if c[N-1] == budget:
    d = d + 1

print(d)

Measured memory_bytes: 9148
#include "bits/stdc++.h"
using namespace std;
#ifdef _DEBUG
#define dlog(str) cout << "====" << str << endl;
#else
#define dlog(str)
#endif
#define INF 999999999
#define MOD 1000000007
#define REP(i, n) for(int i = 0, i##_l = (n); i < i##_l; i++)
#define FOR(i, s, e) for(int i = s, i##_l = (e); i < i##_l; i++)
#define LLI long long int
#define _min(a,b) ((a<b)?a:b)
#define _max(a,b) ((a<b)?b:a)
#define chmax(a, b) a = _max(a, b)
#define chmin(a, b) a = _min(a, b)
#define bit(a, shift) ((a>>shift)&1))
#define pm(a) ((a)?1:-1)
#define SORT(v) sort(v.begin(),v.end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
// int 2.14E±9    lli 9.2E±18    double 1.7E±380


int main()
{
	cout << fixed << setprecision(10);
	int n;
	cin >> n;
	vector<int> a(n);
	REP(i, n)
	{
		cin >> a[i];
	}

	LLI cost = 0;
	int h = 1;
	REP(i, n)
	{
		if (a[i] == h)
		{
			h++;
		}
		else
		{
			cost++;
		}
	}
	if (h == 1)
	{
		cout << -1;
	}
	else
	{
		cout << cost;
	}
	return 0;
}

Measured memory_bytes: 1024
import itertools

H,W,K = map(int, input().strip().split())

choco = [input().strip() for h in range(H)]
cs = [[None for _ in range(W)] for _ in range(H)]  # 累積和

for w in range(W):
  now_cs = 0
  for h in range(H):
    now_cs += choco[h][w] == '1'
    cs[h][w] = now_cs

def devide_col(w, d):
  if len(d) == 0:  # 縦分割なし
    return [cs[-1][w]]
  d = sorted(d)
  if len(d) == 1:
    _d = d[0]-1
    return [cs[_d][w], cs[-1][w]-cs[_d][w]]
  
  result = []
  for i in range(len(d)):
    if i == 0:
      result.append(cs[d[0]-1][w])
    else:
      result.append(cs[d[i]-1][w]-cs[d[i-1]-1][w])
  result.append(cs[-1][w]-cs[d[-1]-1][w])
  return result

ans = float('inf')
for n_split in range(H):
  if n_split > ans: continue
  for split_pos in itertools.combinations(range(1,H), n_split):
    # 縦の分割方法が決まった
    # 横は貪欲
    now_ans = 0
    now_state = [0]*(n_split+1)
    for w in range(W):
      next_state = devide_col(w, split_pos)
      # print(w, split_pos, next_state)  # TMP
      if any(s > K for s in next_state):  # この縦分割では無理
        now_ans = float('inf')
        break
      now_state = [n+s for n,s in zip(now_state, next_state)]  # 足してみる
      if any(s > K for s in now_state):  # 分割する
        now_ans += 1
        now_state = next_state
    # print(split_pos, now_ans+n_split)
    ans = min(ans, now_ans+n_split)
print(ans)

Measured memory_bytes: 63960
N = int(input())
a = [int(input()) - 1 for _ in range(N)]

a_pair = list(enumerate(a))

position = 0
position_log = {0}

while True:
    position = a_pair[position][1]
    if position == 1:
        print(len(position_log))
        break
    elif position in position_log:
        print(-1)
        break
    position_log.add(position)


Measured memory_bytes: 23460
#include <iostream>
#include <algorithm>
#include <map>
#include <set>

using namespace std;

#define l first
#define r second
#define int long long

int n;
int w1[5000];
int w2[5000];

signed main()
{
    int n;
    cin >> n;
    for (int i = 0; i < 3; i++) cin >> w1[i];
    for (int i = 0; i < 3; i++) cin >> w2[i];
    if (w1[0] <= w2[0] && w1[1] <= w2[1] && w1[2] <= w2[2])
    {
        long long ans = 0;
        for (int g = 0; g * w1[0] <= n; g++)
        {
            for (int s = 0; s * w1[1] + g * w1[0] <= n; s++)
            {
                int b = (n - s * w1[1] - g * w1[0]) / w1[2];
                int money = (n - s * w1[1] - g * w1[0]) % w1[2];
                ans = max(ans, 1LL * g * w2[0] + 1LL * s * w2[1] + 1LL * b * w2[2] + money);
            }
        }
        cout << ans;
        return 0;
    }
    if (w1[0] >= w2[0] && w1[1] >= w2[1] && w1[2] >= w2[2])
    {
        swap(w1[0], w2[0]);
        swap(w1[1], w2[1]);
        swap(w1[2], w2[2]);
        long long ans = 0;
        for (int g = 0; g * w1[0] <= n; g++)
        {
            for (int s = 0; s * w1[1] + g * w1[0] <= n; s++)
            {
                int b = (n - s * w1[1] - g * w1[0]) / w1[2];
                int money = (n - s * w1[1] - g * w1[0]) % w1[2];
                ans = max(ans, 1LL * g * w2[0] + 1LL * s * w2[1] + 1LL * b * w2[2] + money);
            }
        }
        cout << ans;
        return 0;
    }
    int sign1 = 0;
    for (int i = 0; i < 3; i++) if (w1[i] <= w2[i]) sign1++;
    if (sign1 == 1)
    {
        long long ans = 0;
        for (int i = 0; i < 2; i++) if (w1[i] < w2[i]) swap(w1[i], w1[2]), swap(w2[i], w2[2]);
        n = (n / w1[2]) * w2[2] + (n % w1[2]);
        for (int g = 0; g * w2[0] <= n; g++)
        {
            int s = (n - g * w2[0]) / w2[1];
            int money = (n - g * w2[0]) % w2[1];
            ans = max(ans, 1LL * g * w1[0] + 1LL * s * w1[1] + money);
        }
        cout << ans;
        return 0;
    }
    if (sign1 == 2)
    {
        long long ans = 0;
        for (int i = 0; i < 2; i++) if (w1[i] > w2[i]) swap(w1[i], w1[2]), swap(w2[i], w2[2]);
        for (int g = 0; g * w1[0] <= n; g++)
        {
            int s = (n - g * w1[0]) / w1[1];
            int money = (n - g * w1[0]) % w1[1];
            int summ = g * w2[0] + s * w2[1] + money;
            int b = summ / w2[2];
            money = summ % w2[2];
            ans = max(ans, 1LL * b * w1[2] + money);
        }
        cout << ans;
        return 0;
    }
}

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

int GCD(int a,int b){
	int temp;
	while(b!=0){
		temp=b;
		b=a%b;
		a=temp;
	}
	return a;
}

int LCM(int a,int b,int gcd){
	a/=gcd;
	b/=gcd;
	return a*b*gcd;
}

int main() {
	int a,b,gcd,lcm;
	while(cin>>a>>b){
		if(b>a) swap(a,b);
		gcd=GCD(a,b);
		lcm=LCM(a,b,gcd);
		cout<<gcd<<" "<<lcm<<endl;
	}
	return 0;
}

Measured memory_bytes: 1160
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <vector>

using namespace std;

typedef long long ll;

void solve() {
  int n;
  string a, b, c;
  cin >> n >> a >> b >> c;
  int ret = 0;
  for(int i = 0; i < n; i++) {
    if(a[i] == b[i] && b[i] == c[i]) ret += 0;
    else if(a[i] == b[i] || b[i] == c[i] || a[i] == c[i]) ret += 1;
    else ret += 2;
  }
  cout << ret << endl;
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL); cout.tie(NULL);
  solve();
  /*
  int t;
  cin >> t;
  for(int i = 1; i <= t; i++) {
    cout << "Case #" << i << ": ";
    solve();
  }
  */
}


Measured memory_bytes: 256