akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#include <iostream>
#include <vector>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <string>
#include <cstring>
#include <sstream>
#include <algorithm>
#include <functional>
#include <queue>
#include <stack>
#include <cmath>
#include <iomanip>
#include <list>
#include <tuple>
#include <bitset>
#include <ciso646>
#include <cassert>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> T;
typedef vector<ll> vec;

inline bool check(ll x, ll y, ll xMax, ll yMax) { return x >= 0 && y >= 0 && xMax > x && yMax > y; }
inline int toint(string s) { int v; istringstream sin(s); sin >> v; return v; }
template<class T> inline string tostring(T x) { ostringstream sout; sout << x; return sout.str(); }
template<class T> inline T sqr(T x) { return x*x; }
template<class T> inline T mypow(T x, ll n) { T res = 1; while (n > 0) { if (n & 1)res = res * x;	x = x * x;	n >>= 1; }return res; }
inline ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
inline ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }

#define For(i,a,b)	for(ll (i) = (a);i < (b);(i)++)
#define rep(i,n)	For(i,0,n)
#define rFor(i,a,b)	for(ll (i) = (a-1);i >= (b);(i)--)
#define rrep(i,n)	rFor(i,n,0)
#define each(i,n)	for(auto &i : n)
#define clr(a)		memset((a), 0 ,sizeof(a))
#define mclr(a)		memset((a), -1 ,sizeof(a))
#define all(a)		(a).begin(),(a).end()
#define sz(a)		(sizeof(a))
#define tostr(a)	tostring(a)
#define dump(val) 	cerr << #val " = " << val << endl;
#define Fill(a,v)	fill((int*)a,(int*)(a+(sz(a)/sz(*(a)))),v)

const ll dx[8] = { 1, 0, -1, 0, 1, 1, -1, -1 }, dy[8] = { 0, -1, 0, 1, -1, 1, -1, 1 };

const ll mod = 1e9 + 7;
const ll INF = 1e17 + 9;

#define int ll
#define double ld

signed main() {
	cin.tie(0);
	ios_base::sync_with_stdio(false);
	int w, h;
	cin >> h >> w;

	vector<string> s(h);

	for (int y = 0; y < h; y++) {
		cin >> s[y];
	}

	queue<P> q;
	q.push(P(0, 0));

	while (q.size()) {
		auto t = q.front();
		q.pop();
		s[t.second][t.first] = '.';
		if (t.first == w - 1 && t.second == h - 1)continue;
		int cnt = 0;
		{
			int x = t.first + 1;
			int y = t.second;
			if (check(x, y, w, h) && s[y][x] == '#') {
				q.push(P(x, y)); cnt++;
			}
		}
		{
			int x = t.first;
			int y = t.second + 1;
			if (check(x, y, w, h) && s[y][x] == '#') {
				q.push(P(x, y)); cnt++;
			}
		}
		if(cnt == 2 || cnt == 0){
			cout << "Impossible" << endl; return 0;
		}
	}

	for (int y = 0; y < h; y++) {
		for (int x = 0; x < w; x++) {
			if (s[y][x] == '#') {
				cout << "Impossible" << endl; return 0;
			}
		}
	}

	cout << "Possible" << endl;

	return 0;
}

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

#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define intll int long long
const int INF = 1e9;
const int MOD = 1e9 + 7;


int main() {
  int n,m;
  cin >> n>>m;
  
  int  AC[n] = {0};
  int  WA[n] = {0} ;
  bool B[n] = {};
  
  rep(i,n+1)
    B[i] = false ;
 
  rep(i,m){
    int p ; 
    string s ;
    cin >> p >> s ;
    if(s == "AC"){
      AC[p] = 1 ;
      B[p] = true ;
    }
    if(s == "WA" && B[p] == false ){
      WA[p] ++;
    }
  }
  int ans_AC = 0;
  int ans_WA = 0;
  rep(i,n+1){
    if(B[i]){
      ans_AC += 1 ;
      ans_WA += WA[i];
    }
  }
  
  cout << ans_AC << " " << ans_WA;
    
      
      
}


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

void insertion_sort(vector<int> &v, int size){
  int i,j,at;
  for( i=1; i<size; i++){
    at = v[i];
    j = i-1;
    while( j>=0 && at<v[j]){
      v[j+1] = v[j];
      j--;
    }
    v[j+1] = at;
    //ここでは途中経過をアウトプット
    for( j=0; j<size; j++){
      cout << v[j];
      if(j != size-1) cout << ' ';
    }
    cout<<endl;
  }
}
 
int main(){
  int n; cin>>n;
  vector<int> a(n);
  int i;
  for( i=0; i<n; i++){
    cin>>a[i];
  }
  //ここでは途中経過をアウトプット
  for( i=0; i<n; i++){
    cout << a[i];
    if(i != n-1) cout << ' ';
  }
  cout<<endl;
  
  insertion_sort(a, n);
  return 0;
}



Measured memory_bytes: 3092
#include <stdio.h>

#define INT_INF 0x7fffffff

void chmin(int *x, int y) {
	int tmp;
	if(*x > y) {
		*x = y;
	}
}

int max(int a[], int len) {
	int i, tmp = a[0];
	for(i = 1; i < len; i++) {
		if(tmp < a[i]) {
			tmp = a[i];
		}
	}
	return tmp;
}

int minidx(int a[], int len) {
	int i, idx = 0, tmp = a[0];
	for(i = 1; i < len; i++) {
		if(tmp > a[i]) {
			tmp = a[i];
			idx = i;
		}
	}
	return idx;
}

int main(void) {
	int h, n, i, j, idx;
	int a[1000], b[1000], max_a;
	int dp[20000];

	scanf("%d %d", &h, &n);
	for(i = 0; i < n; i++) {
		scanf("%d %d", a+i, b+i);
	}

	max_a = max(a, n);
	dp[0] = 0;
	for(i = 1; i < h + max_a; i++) {
		dp[i] = INT_INF;
	}

	for(i = 0; i < h; i++) {
		if(dp[i] != INT_INF) {
			for(j = 0; j < n; j++) {
				chmin(dp + i + a[j], dp[i] + b[j]);
			}
		}
	}

	idx = minidx(dp + h, max_a);

	printf("%d\n", dp[h + idx]);

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FI first
#define SE second
#define EPS 1e-9
#define ALL(a) a.begin(),a.end()
#define SZ(a) int((a).size())
#define MS(s, n) memset(s, n, sizeof(s))
#define FOR(i,a,b) for (int i = (a); i <= (b); i++)
#define FORE(i,a,b) for (int i = (a); i >= (b); i--)
#define FORALL(it, a) for (__typeof((a).begin()) it = (a).begin(); it != (a).end(); it++)
#define WHATIS(x) cout << #x << " is " << x << endl;
#define ERROR(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
//__builtin_ffs(x) return 1 + index of least significant 1-bit of x
//__builtin_clz(x) return number of leading zeros of x
//__builtin_ctz(x) return number of trailing zeros of x

using namespace std;
using ll = long long;
using ld = double;
typedef pair<int, int> II;
typedef pair<II, ll> III;
typedef complex<ld> cd;
typedef vector<cd> vcd;

void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
    cout << *it << " = " << a << endl;
    err(++it, args...);
}

const ll MODBASE = 1000000007LL;
const int MAXN = 200010;
const int MAXM = 100010;
const int MAXK = 510;
const int MAXQ = 200010;

int a[MAXN], n;

int main() {
    ios::sync_with_stdio(0);
    cin.tie(nullptr);
    cin >> n;
    FOR(i,1,n) cin >> a[i];
    FOR(i,1,n) a[i] -= i;
    sort(a+1, a+n+1);
    ll res = 0;
    FOR(i,1,n/2) res += a[n-i+1] - a[i];
    cout << res;
    return 0;
}

Measured memory_bytes: 1024
from functools import lru_cache

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

tmp = 0
for a in A[2:]:
    tmp ^= a

INF = 10 ** 18

@lru_cache(None)
def F(a, b, xor):
    if (a & 1) ^ (b & 1) != (xor & 1): #一桁目が合わない時
        return INF
    if xor == 0:
        return INF if a < b else (a - b) // 2 #xor = 0にできるのは aとbが同じときだけ --> aのほうが大きい必要がある
    #1の位を放置
    x = 2 * F(a // 2, b // 2, xor // 2)
    #1の位を移動
    y = 2 * F((a - 1) // 2, (b + 1) // 2, xor // 2) + 1 # +1 は移動コスト

    x = min(x, y)
    if x >= INF:
        x = INF
    
    return x

x = F(A[0], A[1], tmp)
if x >= A[0]:
    x = -1

print (x)

Measured memory_bytes: 9628
import math
from fractions import gcd
from functools import reduce

DIV=10**9+7

def lcm(a,b):
  return a*b//(gcd(a,b))

N=int(input())
A=list(map(int,input().split()))
g=reduce(lcm,A)

ans=sum(list(map(lambda x:g//x,A)))
print(ans%DIV)

Measured memory_bytes: 264700
#include <iostream>
#include <string>
#include <vector>
#include <cmath>
#include <queue>
#include <map>
#include <set>
#include <stack>
#include<algorithm>
#include<sstream>
#include<iomanip>


using namespace std;

typedef long long ll;

const ll MOD_CONST = 1000000007;
const ll BIG_NUM = 1000000000000000000;



int main() {
	int a, b, q;
	cin >> a >> b >> q;
	vector<ll> s(a+2);
	s[0] = -BIG_NUM;
	for (int i = 1; i <=a; i++) {
		cin >> s[i];
		
	}
	s[a+1] = BIG_NUM;

	vector<ll> t(b+2);
	t[0] = -BIG_NUM;
	for (int i = 1; i <=b; i++) {
		cin >> t[i];
		
	}
	t[b + 1] = BIG_NUM;

	

	for (int i = 0; i < q; i++) {
		ll x;
		cin >> x;
		
		auto it_s = lower_bound(s.begin(), s.end(), x);
		auto it_t = lower_bound(t.begin(), t.end(), x);
		
		ll dis = BIG_NUM;
		for (int i = 0; i < 2; i++) {
			for (int j = 0; j < 2;j++) {
				ll d1 = abs(*(it_s - i) - x) + abs(*(it_s - i) - *(it_t - j));
				ll d2 = abs(*(it_t - j) - x) + abs(*(it_t - j) - *(it_s - i));
				dis = min(dis, min(d1, d2));
			}
		}
		cout << dis << endl;
		
	}
	
	

}


Measured memory_bytes: 2944
#include "bits/stdc++.h"
#define rep(i,b) for(ll i=0;i<b;i++)
#define ll long long
using namespace std;
/*--Input//////////////////////////////////////////////////*/
inline void IN(void){return;}
template <typename First, typename... Rest>
void IN(First& first, Rest&... rest){
    cin >> first;
    IN(rest...);
    return;
}
#define SS(T, ...)      T __VA_ARGS__; IN(__VA_ARGS__);
/*--Output/////////////////////////////////////////////////*/
inline int p(void){cout << endl; return 0;}
template<class Head> int p(Head&& head){cout << head;p();return 0;} template<class Head,class... Tail> int p(Head&& head,Tail&&... tail){cout<<head<<" ";p(forward<Tail>(tail)...);return 0;}
struct ProconInit {
    static constexpr int IOS_PREC = 15;
    static constexpr bool AUTOFLUSH = false;

    ProconInit() {
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(IOS_PREC);
        if(AUTOFLUSH)
            cout << unitbuf;
    }
} PROCON_INIT;


#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vvvl vector<vector<vector<ll>>>
#define debug(x) cerr<<#x<<" "<<x<<'\n';
#define all(x) (x).begin(),(x).end()
#define bit(n) (1LL<<(n))
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
bool cmp(pair<ll,ll> a, pair<ll,ll> b) { return a.second < b.second; }

const int MOD = 1000000007;

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

// (x, y) を始点とした BFS をして、(x, y) から最も遠いマスへの距離を答える
int bfs(const vector<string> &v, ll x, ll y) {
    ll H = v.size(), W = v[0].size();
    vvl dist(H, vl(W, -1));//-1で埋める
    queue<pair<ll,ll>> que;

    ll res = 0;
    que.push(make_pair(x,y));
    dist[x][y] = 0;
    while (!que.empty()) {
        ll x = que.front().first, y = que.front().second;
        res = max(res, dist[x][y]);
        que.pop();
        rep(dir,4){
            ll nx = x+ dx[dir], ny = y + dy[dir];
            if (nx < 0 || nx >= H || ny < 0 || ny >= W) continue;
            if (v[nx][ny] == '.'&&dist[nx][ny]==-1){ //未探索の道なら
                dist[nx][ny] = dist[x][y] + 1; //前のマス+1
                que.push({nx, ny}); //4方位をqueueに追加
            }
        }
    }
    return res;
}
ll ans=0;
int main() {
     SS(string,S,s)
     rep(i,s.size()-2)
     if(s[i]=='A'&&s[i+1]=='B'&&s[i+2]=='C')ans++;
     p(ans);
}

Measured memory_bytes: 256
#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);
    vector<ll> a(1000001,0);
    vector<bool> ok(1000001,true);
    ll n; cin>>n;
    rep(i,n){
        ll A; cin>>A;
        a[A]++;
    }
    for(ll i=1; i<a.size(); i++){
        if(a[i]==0)continue;
        bool flag = true;
        ll x = i;
        if(a[i]==1)x+=i;
        while(flag&&x<a.size()){
            ok[x]=false;
            x+=i;
        }
    }
    ll ans = 0;
    for(ll i=0; i<a.size(); i++){
        ans += a[i]*ok[i];
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 11372
n = int(input())
heights = list(map(int, input().split()))

dp = [0 for i in range(n)]
for i in range(1, len(dp)):
    a = dp[i - 1] + abs(heights[i] - heights[i - 1])
    b = (dp[i - 2] + abs(heights[i] - heights[i - 2])) if i > 1 else float('inf')
    dp[i] = min(a, b)

print(dp[n - 1])


Measured memory_bytes: 13980
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main() {
	int n;
	cin >> n;
	vector<int> a(n);
	for (int i = 0; i < n; ++i) {
		cin >> a[i];
	}
	cout << *max_element(a.begin(), a.end()) - *min_element(a.begin(), a.end());
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define all(x) x.begin(), x.end()
using namespace std;
using ll = long long;
const int maxn = 1<<18;

int main() {
	cin.tie(0)->sync_with_stdio(0);
	map<int, int> cnt;
	int n, ans = 1;
	cin >> n;
	for(int i = 0; i < n/2; i++) ans = (ans + ans)%int(1e9 + 7);
	for(int i = 1; i <= n; i++) cnt[abs(i-1-(n-i))]++;
	int t;
	while(n--) {
		cin >> t;
		cnt[t]--;
	}
	for(auto i : cnt) if(i.second) ans = 0;
	cout << ans;
	
}


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

struct node{
  int key;
  node *l,*r,*p;
};

node* root;

node* make_node(int a){
  node* ret = new node();
  ret->key = a;
  ret->p = ret->l = ret->r = NULL;
  return ret;
}

void insert(node *z){
  node *y = NULL;
  node *x = root;
  while( x != NULL ){
    y = x;
    if( z->key < x->key )
      x = x->l;
    else
      x = x->r;
  }
  z->p = y;
  if( y == NULL )
    root = z;
  else if( z->key < y->key )
    y->l = z;
  else
    y->r = z;
}

bool find(int k){
  node* x = root;
  while( x != NULL ){
    if( k < x->key )
      x = x->l;
    else if( k > x->key )
      x = x->r;
    else
      return true;
  }
  return false;
}

void delete_node(node *x){
  if( x->l == NULL && x->r == NULL ){
    if( x->p != NULL ){
      if( x->p->l == x ) x->p->l = NULL;
      else x->p->r = NULL;
    }
    delete x;
  } else if( x->l == NULL ){
    x->r->p = x->p;
    if( x->p != NULL ){
      if( x->p->l == x ) x->p->l = x->r;
      else x->p->r = x->r;
    }
    delete x;
  } else if( x->r == NULL ){
    x->l->p = x->p;
    if( x->p != NULL ){
      if( x->p->l == x ) x->p->l = x->l;
      else x->p->r = x->l;
    }
    delete x;
  }
}

void del(int key){
  node* x = root;
  while( x != NULL ){
    if( key < x->key )
      x = x->l;
    else if( key > x->key )
      x = x->r;
    else
      break;
  }

  if( x->l && x->r ){
    node* y = x->r;
    while( y->l && y->r )
      y = y->l;
    x->key = y->key;
    delete_node(y);
  } else {
    delete_node(x);
  }
}

void inorder(node* n){
  if( n == NULL) return;
  inorder(n->l);
  cout << " " << n->key;
  inorder(n->r);
}

void preorder(node* n){
  if( n == NULL ) return;
  cout << " " << n->key;
  preorder(n->l);
  preorder(n->r);
}

int main(){
  int N;
  cin >> N;
  for(int i=0;i<N;i++){
    string s; int k;
    cin >> s;
    if( s[0] == 'i' ) {
      cin >> k;
      insert(make_node(k));
    } else if( s[0] == 'f' ){
      cin >> k;
      if( find(k) ) cout << "yes" << endl;
      else cout << "no" << endl;
    } else if( s[0] == 'p' ){
      inorder(root); cout << endl;
      preorder(root); cout << endl;
    } else {
      cin >> k;
      del(k);
    }
  }
}

Measured memory_bytes: 24644
import math
from functools import reduce
from collections import deque
import sys
sys.setrecursionlimit(10**7)

# スペース区切りの入力を読み込んで数値リストにして返します。
def get_nums_l():
    return [ int(s) for s in input().split(" ")]

# 改行区切りの入力をn行読み込んで数値リストにして返します。
def get_nums_n(n):
    return [ int(input()) for _ in range(n)]

# 改行またはスペース区切りの入力をすべて読み込んでイテレータを返します。
def get_all_int():
    return map(int, open(0).read().split())

def log(*args):
    print("DEBUG:", *args, file=sys.stderr)

s = input()
len_s = len(s)
kaibun = s == s[::-1]
left = s[:(len_s-1)//2] == s[:(len_s-1)//2][::-1]
right = s[(len(s)+3)//2-1:] == s[(len(s)+3)//2-1:][::-1]
log(kaibun, left, right)
print("Yes" if kaibun and left and right else "No")

Measured memory_bytes: 38256
N,K=map(int,input().split())
ans=0
counter=0
for i in range(1,N+1):
    if i%K==0:
        counter+=1
ans+=counter**3
counter1=0
if K%2==0:
    K//=2
    for i in range(1,N+1):
        if i%K==0 and i%(K*2)!=0:
            counter1+=1
ans+=counter1**3
print(ans)


Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define P 1000000007
using namespace std;
typedef long long lnt;
template <class T> inline void read(T &x) {
	x = 0; int c = getchar(), f = 1;
	for (; !isdigit(c); c = getchar()) if (c == 45) f = -1;
	for (; isdigit(c); c = getchar()) (x *= 10) += f*(c-'0');
}
int n, a[21][21], f[1<<21];
int main() {
	read(n);
	for (int i = 0; i < n; i++)
		for (int j = 0; j < n; j++)
			read(a[i][j]);
	f[0] = 1;
	for (int s = 0; s < (1<<n); s++)
		for (int u = __builtin_popcount(s), v = 0; v < n; v++)
			if (!(s>>v&1) && a[u][v]) (f[s|(1<<v)] += f[s]) %= P;
	return printf("%d\n", f[(1<<n)-1]), 0;
}


Measured memory_bytes: 8448
from scipy.sparse.csgraph import dijkstra, csgraph_from_dense
from collections import defaultdict
h, w = map(int, input().split())
table = [list(map(int, input().split())) for _ in range(10)]
dd = defaultdict(int)
for _ in range(h):
    for x in map(int, input().split()):
        if x == -1:
            continue
        dd[x] += 1

trans_table = list(zip(*table))
scores = dijkstra(csgraph_from_dense(trans_table), indices=1)

ans = 0
for k, v in dd.items():
    ans += int(scores[k])*v
print(ans)

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

using namespace std;
using ll = long long;
using vi = vector<int>;

#define scan(x) cin >>x;
#define print(x) cout << x << endl;
#define Endl endl
#define inf 99999999
#define llinf 1LL << 32

int main() {

	int n,cnt = 0;
	ll a[100010] = { 0 };

	
	scan(n);
	for (int i = 0; i < n; i++) {
		ll b;
		scan(b);
		if (b > 100000)cnt++;
		else a[b]++;
	}

	for (int i = 1; i <= 100000; i++) {
		if (a[i] == 0)continue;
		else if (i > a[i])cnt += a[i];
		else if (i < a[i]) cnt += a[i] - i;
	}

	print(cnt);

	return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <math.h>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <set>
#include <queue>
#include <deque>
#include <map>
#include <stack>
using namespace std;

#define mod 1000000007
#define ten5 100005
#define ten52 200005
#define ten6 1000005
#define PI 3.1415926
#define pb(x) push_back(x)
#define all(x) x.begin(),x.end()
#define mkpr(x1,x2) make_pair(x1,x2)
typedef long long int ll;

//ll num[50];
//ll num2[50];
ll num[ten52];
//stack<char> stk;
//set<ll> sll;
//map<string,ll> mp,mp1;
//map<pair<ll,ll>,ll>::iterator iter;
//map<ll,ll> mp;
//deque<char> deq;
//vector<ll> vll;


int main(void)
{
    //double ans=0.0,d,d1,d2;
    //float f,g,h;
    long long int m,n,i,j,k=1;
    long long int a,a1,a2,a3,sum;
    string s,s1,s2;
    //char c,c1;
    sum=a=a1=a2=a3=0;
    cin>>n>>k;
    for(i=0;i<k;i++)
    {
        cin>>a;
        for(j=0;j<a;j++)
        {
            cin>>a2;
            num[a2]++;
        }
    }
    for(i=1;i<=n;i++)
        if(num[i]==0) sum++;
    cout<<sum;
    return 0;
}





Measured memory_bytes: 3628
N = int(input())
A = list(list(map(int,input().split()))for i in range(N))
B = [A[i][:] for i in range(N)]
ans = 0
for i in range(N):
    for j in range(i+1,N):
        flag = True
        for k in range(N):
            if not i != k != j:
                continue
            if A[i][j] == A[i][k] + A[j][k]:
                flag = False
            elif A[i][j] > A[i][k] + A[j][k]:
                print(-1)
                exit()
        if flag:
            ans += A[i][j]
print(ans)


Measured memory_bytes: 44636
n, m = map(int, input().split())
h = list(map(int, input().split()))

a, b = [], []

for i in range(m):
    aa, bb = map(int, input().split())
    a.append(aa)
    b.append(bb)

res = [0] * n

for i in range(m):
    if h[a[i]-1] > h[b[i]-1]:
        res[b[i]-1] = -1
    elif h[a[i]-1] < h[b[i]-1]:
        res[a[i]-1] = -1
    else:
        res[b[i]-1] = -1
        res[a[i]-1] = -1

count = 0

for i in range(len(res)):
    if res[i] == 0:
        count += 1

print(count)


Measured memory_bytes: 89832
#include <bits/stdc++.h>
#define maxs 2202020
#define mme(i,j) memset(i,j,sizeof(i))
using namespace std;
struct node
{
    int from,to,nt;
    long long cos;
}ed[maxs];

long long dis[maxs];
int head[maxs];
int tot;//边的编号

void init(){

    mme(head,-1);
    tot=0;
    mme(dis,0);
}

void add(int u,int v,int w){

    ed[tot].from=u;
    ed[tot].to  =v;
    ed[tot].cos =w;
    ed[tot].nt  =head[u];
    head[u]     =tot++;
}

void dfs(int u,int p)
{
    for(int i=head[u];i!=-1;i=ed[i].nt){
        if(ed[i].to == p) continue;
        dis[ed[i].to]=dis[u]+ed[i].cos;
        dfs(ed[i].to,u);
    }
}

int main()
{
    int n;
    while(~scanf("%d",&n))
    {
        init();
        int u,v,w;
        for(int i=1;i<n;i++)
        {
            scanf("%d%d%d",&u,&v,&w);
            add(u,v,w);
            add(v,u,w);
        }
        int q,k;
        scanf("%d%d",&q,&k);
        dfs(k,-1);
        int x,y;
        while(q--){
            scanf("%d%d",&x,&y);
            printf("%lld\n",dis[x]+dis[y]);
        }
    }
    return 0;
}


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

// ?????¬???????????¬??????
#pragma region MACRO
#define P(x) cout << (x) << endl
#define p(x) cout << (x)
#define PED cout << "\n"
#define rep(i,n) for(int i=0; i<(int)n; ++i)
#define REP(i,x,n) for(int i=x; i<(int)n; ++i)
#define repi(i,n) for(int i=0; i<=(int)n; ++i)
#define REPI(i,x,n) for(int i=x; i<=(int)n; ++i)
#define ILP while(true)
#define FOR(i,c) for(__typeof((c).begin())!=(c).begin(); i!=(c).end(); ++i)
#define ALL(c) (c).begin(), (c).end()
#define mp make_pair
#pragma endregion

// ???
#pragma region TYPE_DEF
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<string, string> pss;
typedef pair<string, int> psi;
typedef pair<int, string> pis;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<long> vl;
typedef vector<long long> vll;
typedef vector<string> vs;
#pragma endregion

// Effective std
#pragma region ESTD
template<typename C, typename T> int count(C& c, T t) { return count(ALL(c), t); }
template<typename C, typename F> int count_if(C& c, F f) { return count_if(ALL(c), f); }
template<typename C, typename T> void erase(C& c, T t) { remove(ALL(c), t), c.end(); }
template<typename C> void remove(vector<C>& c, unsigned int index) { c.erase(c.begin()+index); }
template<typename C, typename T, typename U> void replace(C& c, T t, U u) { replace(ALL(c), t, u); }
template<typename C, typename F, typename U> void replace_if(C& c, F f, U u) { (ALL(c), f, u); }
template<typename C> void reverse(C& c) { reverse(ALL(c)); }
template<typename C> void sort(C& c) { sort(ALL(c)); }
template<typename C, typename Pred> void sort(C& c, Pred p) { sort(ALL(c), p); }
#pragma endregion

// ?????°
#pragma region CONST_VAL
#define PI (2*acos(0.0))
#define EPS (1e-9)
#define MOD (int)(1e9+7)
#define INF numeric_limits<int>::infinity()
#pragma endregion


int main()
{
    vi v1, v2;
    rep(i,10) {
        int a;
        cin >> a;
        v1.push_back(a);
    }
    rep(i,10) {
        int a;
        cin >> a;
        v2.push_back(a);
    }

    sort(v1);
    sort(v2);
    printf("%d %d\n", v1[9]+v1[8]+v1[7], v2[9]+v2[8]+v2[7]);
    return 0;
}

Measured memory_bytes: 3048
import java.util.*;

class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String S = sc.next();
		int N = S.length();
		int black_1st=0;
		for (int i=0;i<N;i+=2) {
			if (S.charAt(i)=='1') {
				black_1st++;
			}
			if (i!=N-1) {
				if (S.charAt(i+1)=='0') {
					black_1st++;
				}
			}
		}
		System.out.println(Math.min(N-black_1st,black_1st));
	}
}

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

typedef long int lint;
typedef long long int llint;
typedef pair<int, int> pii;
typedef pair<int, string> pis;
typedef pair<long, long> pll;

#define EACH(i, c) for (__typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define ALL(c) (c).begin(), (c).end()
#define FOR(i, s, e) for (int i = (s); i < (int)(e); ++i)
#define REP(i, n) FOR(i, 0, n)
#define endl "\n"

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

template<typename T>
void print(const std::vector<T>& v, char sep=' ') {
  for (int i = 0; i < (int)v.size(); i++) {
    if (i != 0) cout << sep;
    cout << v[i];
  }
  cout << endl;
}

int fib[45];

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

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

Measured memory_bytes: 1196
N = int(input())
checks = list(map(int, input().split()))

# 逆から解く
balls = [0]*N
for i in range(N-1, -1, -1):
    # 存在する限り、倍数の箱に入っているボールの数を取得する
    ball_sum = 0
    box_i = i + 1
    while box_i <= N:
        # print("{} is counted. i:{}, box_i:{}".format(i + 1, i, box_i))
        ball_sum += balls[box_i - 1]
        box_i += i +1 # 次の倍数
        
    # 偶数奇数に一致するようにボールを入れる
    rest = ball_sum % 2
    
    if checks[i] == 0:
        # 偶数にしたいとき
        if rest == 1:
            balls[i] = 1
    
    if checks[i] == 1:
        # 奇数にしたいとき
        if rest == 0:
            balls[i] = 1

print(sum(balls))
print(" ".join([str(i + 1) for i in range(0, N) if balls[i] == 1]))   

Measured memory_bytes: 14776
#include<iostream>
using namespace std;
int main(){
  int a,b;
  cin>>a>>b;
  if(a+b>=a-b&&a+b>=a*b)cout<<a+b<<endl;
  else if(a-b>=a*b)cout<<a-b<<endl;
  else cout<<a*b<<endl;
  return 0;
}

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

using namespace std;

int main()
{
    int N;

    cin >> N;

    vector<string> s;

    for ( int i=0; i < N; i ++ )  {
        char buf[16];

        cin >> buf;
        sort( buf, buf+10 );

        s.push_back( string( buf ) );
    }

    sort( s.begin(), s.end() );

    long count = 0;
    long c = 1;
    for ( int i = 1; i < N; i ++ ) {
        if ( s[i-1].compare( s[i]) == 0 ) {
            c ++;
        } else {
            if ( c == 1 ) continue;

            long p;
            p = c * (c-1) / 2;
            count += (p);

            c = 1;
        }

    }

    if ( c > 1 ) {
        long p;
        p = c * (c-1) / 2;
        count += (p);
    }

    cout << count << endl;


    return 0;
}

Measured memory_bytes: 5748
#include<bits/stdc++.h>
using namespace std;
int a[100000];
int main()
{
    int sx, sy, tx, ty;
    cin >> sx >> sy >> tx >> ty;
    for(int i=1; i<=ty-sy; i++)
    {
        printf("U");
    }
    for(int i=1; i<=tx-sx; i++)
    {
        printf("R");
    }
    for(int i=1; i<=ty-sy; i++)
    {
        printf("D");
    }
    for(int i=1; i<=tx-sx; i++)
    {
        printf("L");
    }
    printf("L");
    for(int i=0; i<=ty-sy; i++)
    {
        printf("U");
    }
    printf("R");
    for(int i=1; i<=tx-sx; i++)
    {
        printf("R");
    }
    printf("D");
    printf("R");
    for(int i=0; i<=ty-sy; i++)
    {
        printf("D");
    }
    printf("L");
    for(int i=1; i<=tx-sx; i++)
    {
        printf("L");
    }
    printf("U\n");
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using i64 = int64_t;
using f80 = __float80;
constexpr i64 INF = 1'010'000'000'000'000'017LL;
constexpr i64 MOD = 1'000'000'007LL;
static const int dy[4] = {0,1,0,-1}, dx[4] = {1,0,-1,0};
#define _overload3(_1,_2,_3,name,...) name
#define repi(i,start,end) for(i64 i=(start);i<(end);++i)
#define _rep(i,n) repi(i,0,n)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define rrep(i,start,end) for(i64 i=(start);i>end;--i)
#define pb push_back
#define rng(a) a.begin(),a.end()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define sz(x) (i64)(x).size()
#define bit(n) (1LL<<(n))
typedef vector<i64> vi;
typedef vector<vi> vvi;
template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return true;}return false;}
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return true;}return false;}

i64 pow_mod(i64 n, i64 k, i64 m){
  i64 r = 1;
  for(;k;k>>=1){
    if(k&1) r=(r*n)%m;
    n=(n*n)%m;
  }
  return r;
}

void Main()
{
  i64 n;
  cin >> n;

  vector<string> s(n);
  map<string,i64> m;
  rep(i,n){
    cin >> s[i];
    if(m.count(s[i])==0)
      m[s[i]]=0;
    m[s[i]]++;
  }
  i64 max_count = 0;
  for(auto itr=m.begin(); itr!=m.end();itr++)
    chmax(max_count,itr->second);
  sort(rng(s));
  string tmp = "";
  for(auto itr : s){
    if(m[itr]==max_count){
      if(tmp==itr) continue;
      cout << itr << endl;
      tmp = itr;
    }
  }
}

int main()
{
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(15);
  Main();
}


Measured memory_bytes: 25984
#include <bits/stdc++.h>
using namespace std;
#define MD 1000000007
typedef long long int ll;
typedef pair<ll, ll> P;
template <typename T>
std::string tostr(const T &t){std::ostringstream os;os << t;return os.str();}
int dx[4]={1, 0, -1, 0}, dy[4]={0, 1, 0, -1};

int main()
{
    int n,h,w;
    cin>>n>>h>>w;
    int ans=0;
    for(int i=0;i<n;i++){
        int a,b;
        cin>>a>>b;
        if(a>=h && b>=w){
            ans++;
        }
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
#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 MOD (int) (1e9+7)
#define INF (int) 2e9

int main(){
    int n;
    cin >> n;
    int d[n];
    rep(i, n){
        cin >> d[i];
    }

    int ans = 0;
    rep(i, n){
        rep(j, n){
            if(i<j){
                ans += d[i]*d[j];
            }
        }
    }
    cout << ans << endl;
    // printf("%d\n", N);
    return 0;
}

Measured memory_bytes: 256
f=lambda:map(int,input().split())
n,m=f()
g=[[0]*n for _ in range(n)]
for i in range(m):
  a,b=f(); g[a-1][b-1]=g[b-1][a-1]=1
import itertools as it
c=0
for t in it.permutations(range(1,n)):
  p=0
  for q in t:
    if g[p][q]<1: break
    p=q
  else: c+=1
print(c)

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

bool check(int x){
	if(x == 2)return true;
	if(x < 2 || x%2 == 0)return false;
	for(int i = 3;i <= sqrt(x);i+=2){
	if(x%i == 0)return false;
	}
	return true;
}
int main(){
	int n,x,count = 0;
	cin >> n;
	for(int i = 0;i < n;i++){
		cin >> x;
		if(check(x))count++;
	}
	cout << count <<endl;

	return 0;
}

Measured memory_bytes: 1160
{-# LANGUAGE OverloadedStrings #-}
import Data.Char
import Data.List
import Control.Monad
import qualified Data.ByteString.Char8 as BS

main :: IO ()
main = do
  as <- concat <$> replicateM 3 (parseLine <$> BS.getLine)
  n <- head.parseLine <$> BS.getLine
  bs <- concat <$> replicateM n (parseLine <$> BS.getLine)
  BS.putStrLn . BS.pack $ if solve as bs then "Yes" else "No"
  where
     parseLine = unfoldr (BS.readInt . BS.dropWhile isSpace)

solve :: [Int] -> [Int] -> Bool
solve as bs = bingo (map (`elem` bs) as)

bingo :: [Bool] -> Bool
bingo xs = or . map (and . map (xs !!)) $ rows
  where
    rows = [
      [0,1,2]
     ,[3,4,5]
     ,[6,7,8]
     ,[0,3,6]
     ,[1,4,7]
     ,[2,5,8]
     ,[0,4,8]
     ,[2,4,6]
     ]

Measured memory_bytes: 380
#include <iostream>
#include <string>
using namespace std;
 
int main(){
    string a;
    getline (cin , a);
    for(int i=0 ; i<1200 ; i++){
        if(a[i]=='\0') break;
        if(a[i]>='a' && a[i]<='z'){
            a[i]-=0x20;
        } else if (a[i]>='A' && a[i]<='Z'){
            a[i]+=0x20;
        }
        if (a[i]==' '){
            cout << " ";
        } else {
        cout << a[i];
        }   
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 1172
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <cmath>
#include <complex>
#include <deque>
#include <iterator>
#include <map>
#include <queue>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <limits>
#include <iomanip>
using namespace std;

using ll=long long;
template<class T> using V = vector<T>;
template<class T, class U> using P = pair<T, U>;
using vll = V<ll>;
using vvll = V<vll>;
#define rep(i, k, n) for (ll i=k; i<(ll)n; ++i)
#define REP(i, n) rep(i, 0, n)
template<class T> inline bool chmax(T& a, T b) {if (a<b) {a=b; return true;} return false;}
template<class T> inline bool chmin(T& a, T b) {if (a>b) {a=b; return true;} return false;}

const ll MOD = 1000000007;
const ll HIGHINF = (ll)1e18;

int main() {
  ll a, b, c; cin >> a >> b >> c;
  if (b-a == c-b) cout << "YES" << endl;
  else cout << "NO" << endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define fo(i, n) for(int i=0; i<n; i++)
#define Fo(i, k, n) for(int i=k; i<n; i++)
#define MOD 1000000007
#define deb(n) cout<<"[ "#n<<" = "<<n<<" ]"<<endl;
#define FIO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
const long long  MAX = 1 << 18;
int case_no = 1;
#define w(x) int x; cin>>x; while(x--)

int main() {
	FIO
	string str;
	cin >> str;
	if(str[0] == 'R' and str[1] == 'R' and str[2] == 'R') cout << "3" << endl;
	else if((str[0] == 'R' and str[1] == 'R') or (str[1] == 'R' and str[2] == 'R')) cout << "2" << endl;
	else if(str[0] == 'R' or str[1] == 'R' or str[2] == 'R') cout << "1" << endl;
	else cout << "0" << endl;

	return 0;
}

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

int grid[10][10];

int main(){
    int r,c;

    while(scanf("%d%d",&r,&c)==2){
        for(int i=0; i<10; i++){
            for(int j=0; j<10; j++){
                scanf("%d",&grid[i][j]);
            }
        }

        for(int k=0; k<10; k++){
            for(int i=0; i<10; i++){
                for(int j=0; j<10; j++){
                    grid[i][j] = min(grid[i][j], grid[i][k] + grid[k][j]);
                }
            }
        }

        int sum = 0, val;

        for(int i=0; i<r; i++){
            for(int j=0; j<c; j++){
                scanf("%d",&val);
                if(val!=-1 && val != 1)
                    sum += grid[val][1];
            }
        }

        printf("%d\n",sum);
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define mod 998244353
#define fi first
#define sc second
#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
set<string>S;
string str;
void rec(string s){
	if(S.find(s) != S.end()) return;
	S.insert(s);
	for(int i=1;i<s.size();i++){
		if(s[i-1] != s[i]){
			char ch;
			if(s[i-1] != 'a' && s[i] != 'a') ch = 'a';
			if(s[i-1] != 'b' && s[i] != 'b') ch = 'b';
			if(s[i-1] != 'c' && s[i] != 'c') ch = 'c';
			char p1=s[i-1],p2=s[i];
			s[i-1] = ch;
			s[i] = ch;
			rec(s);
			s[i-1]=p1; s[i]=p2;
		}
	}
}
ll dp[200005][3][3][2];
int main(){
	S.clear();
	cin>>str; int n = str.size();
	if(str.size()<=8){
		rec(str);
		cout << S.size() << endl;
	}
	else{
		int ok = 0;
		int X = 0;
		rep(i,n) X = (X+(str[i]-'a'))%3;
		for(int i=1;i<str.size();i++){
			if(str[i-1] != str[i]) ok += 1;
		}
		if(!ok){
			puts("1"); return 0;
		}
		dp[1][0][0][0] = dp[1][1][1][0] = dp[1][2][2][0] = 1;
		for(int i=1;i<n;i++){
		    for(int j=0;j<3;j++){
		        for(int k=0;k<3;k++){
		            for(int x=0;x<2;x++){
		                for(int nxt=0;nxt<3;nxt++){
		                    dp[i+1][(j+nxt)%3][nxt][(x||(k==nxt))] += dp[i][j][k][x];
		                }
		            }
		        }
		    }
		    rep(j,3) rep(k,3) rep(x,2) dp[i+1][j][k][x]%=mod;
		}
		ll ans = (dp[n][X][0][1]+dp[n][X][1][1]+dp[n][X][2][1])%mod;
		if(ok+1 == n) ans = (ans+1)%mod;
		cout<<ans<<endl;
	}
}

Measured memory_bytes: 28676
//#include    <bits/stdc++.h>
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <iostream>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <fstream>
#include <numeric>
#include <iomanip>
#include <bitset>
#include <list>
#include <stdexcept>
#include <functional>
#include <utility>
#include <ctime>
#include <cassert>
#include <iterator>
#include <complex>
#define N  10
#define mem(a,b) memset(a,b,sizeof(a))
#define IOS ios::sync_with_stdio(false)
#define INF 0x3f3f3f3f
template<typename T> inline T max(T a,T b,T c){
    return max(a,max(b,c));
}
template<typename T> inline T min(T a,T b,T c){
    return min(a,min(b,c));
}
template<typename T> inline T max(T a,T b,T c,T d){
    return max(a,max(b,c,d));
}
template<typename T> inline T min(T a,T b,T c,T d){
    return min(a,min(b,c,d));
}
const int  dx[]={0,1,0,-1,0,1,-1,1,-1};
const int  dy[]={0,0,1,0,-1,1,-1,-1,1};
const int MOD=1000000007;
typedef long long ll;
using namespace std;
int s[10];
int hw(int s[],int k){
   for (int i=0,j=k-1;i<k&&j>=0;i++,j--){
       if (s[i]!=s[j])
          return 0;
   }
     return 1;
}
int main(){
    IOS;
    ll a,b;
    cin>>a>>b;
    ll num=0;
    for (ll i=a;i<=b;i++){
       int k=0,w=i;
       while (w){
          s[k++]=w%10;
          w/=10;
       }
       if (hw(s,k)) num++;
    }
    cout << num << endl;
   return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;

// #define int ll

#define _GLIBCXX_DEBUG

#define REP(i,n) for (int i = 0; i < (n); ++i)
#define REPD(i,n) for (int i = (n-1); i >= 0; --i)
#define FORE(i, s, n) for (int i = (s); i <= (int)(n); i++)
#define debug(x) cerr << #x << ": " << x << '\n'
#define hyphen() cerr << "--\n"

#define ALL(vec) (vec).begin(), (vec).end()
#define REVALL(vec) (vec).rbegin(), (vec).rend()

#define fst first
#define snd second
#define pb push_back

const int MOD = (int)1e9 + 7;
const int INF = numeric_limits<int>::max();

int ctoi(const char c){
  if('0' <= c && c <= '9') return (c-'0');
  return -1;
}

signed main() {
    int N;
    string S;

    cin >> N;
    cin >> S;

    map<int, vector<int>> mp;
    REP(i, 10) {
        mp[i] = {};
    }

    REP(i, S.size()) {
        int n = ctoi(S.at(i));
        mp.at(n).pb(i);
    }

    int ans = 0;
    REP(i, 10) {
        if (mp[i].size() == 0) {
            continue;
        }

        // 選択の幅を残すために、一番左のケタを選ぶのが良い
        int cand1 = mp[i].at(0);

        REP(j, 10) {
            if (mp[j].size() == 0) {
                continue;
            }

            int cand2 = -1;
            for(auto val : mp[j]) {
                if (val > cand1) {
                    cand2 = val;
                    break;
                }
            }

            if (cand2 == -1) {
                continue;
            }

            REP(k, 10) {
                if (mp[k].size() == 0) {
                    continue;
                }

                int cand3 = -1;

                for(auto val : mp[k]) {
                    if (val > cand2) {
                        cand3 = val;
                        break;
                    }
                }

                if (cand3 == -1) {
                    continue;
                }

                cerr << i << j << k << endl;
                ans += 1;
            }
        }
    }

    cout << ans << endl;
}


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

/*double rec(double p[], int n, int i, int cnt, int icnt, double **mem)
{
  if(i==n&&icnt<cnt)
    return 0;
  if(i==n&&cnt<=icnt)
	return 1;
  if(mem[i][icnt]!=-1)
    return mem[i][icnt];
  double a=p[i]*rec(p,n,i+1,cnt,icnt+1,mem);
  double b=(1-p[i])*rec(p,n,i+1,cnt,icnt,mem);
  mem[i][icnt]=a+b;
  return a+b;
}*/

int main(){
  int n;
  cin>>n;
  double p[n];
  for(int i=0;i<n;i++)
    cin>>p[i];
  int cnt=n/2+1;
  /*double **mem=new double*[n+1];
  for(int i=0;i<=n;i++)
  {
    mem[i]=new double[n+1];
    for(int j=0;j<=n;j++)
      mem[i][j]=-1;
  }
  cout<<fixed<<setprecision(10)<<rec(p,n,0,cnt,0,mem);*/
  
  double dp[n+1][n+1];
  for(int i=0;i<=n;i++)
  {
    dp[0][i]=0;
  	dp[i][0]=1.0;
  }
  double ans=0;
  for(int i=1;i<=n;i++)
  {
    for(int j=0;j<=n;j++)
    {
      if(i<j)
      {
    	dp[i][j]=0;
    	break;
      }
      if(j==0)
      {
        dp[i][j]=(1-p[i-1])*dp[i-1][j];
        continue;
      }
      double a=p[i-1]*dp[i-1][j-1];
      double b=(1-p[i-1])*dp[i-1][j];
      dp[i][j]=a+b;
      if(j>=cnt&&i==n)
    	ans+=dp[i][j];
    }
  }
  cout<<fixed<<setprecision(10)<<ans;
  
  
}

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

int main(){
  long long i,j,n,m;
  cin >> n >> m;
  long long a[n],b[n],c[m],d[m];
  for(i=0;i<n;i++)cin >> a[i] >> b[i];
  for(i=0;i<m;i++)cin >> c[i] >> d[i];
  for(i=0;i<n;i++){
    long long ret = 3e8;
    long long ans = -1;
    for(j=0;j<m;j++){
      if(ret>(abs(a[i]-c[j])+abs(b[i]-d[j]))){
        ret = abs(a[i]-c[j])+abs(b[i]-d[j]);
        ans = j+1;
      }
    }
    cout << ans << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,cnt=0,sum=0,ans=0;
    cin>>n;
    int a[n];
    for(int i=0;i<n;i++)
    {
     cin>>a[i];
     sum+=a[i];
     if(a[i]%10==0)
      {
      cnt++;
}
}
  if(sum%10!=0)
  { 
   cout<<sum<<endl;
}
 else if(cnt==n)
 {
cout<<"0"<<endl;
} 
else {
 sort(a,a+n);
for(int i=0;i<n;i++)
   {
  if((sum-a[i])%10!=0)
  {
cout<<sum-a[i]<<endl;
return 0; 
}

}
}
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.List;
import java.util.ArrayList;
import java.util.Arrays;

public class Main {
	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		// 1行、2つ(複数)数字
		String[] ss0 = br.readLine().trim().split(" ", 0);
		int A = Integer.parseInt(ss0[0]);
		int B = Integer.parseInt(ss0[1]);
		
		int ans = A+B;
		
		if (ans >= 10) {
			System.out.println("error");
		} else {
			System.out.println(ans);
		}

		
	return;
	}


}


Measured memory_bytes: 21204
#include<bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
// using namespace __gnu_pbds;
using namespace std;
// typedef tree<pair<int,int>, null_type, less<pair<int,int>>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
#define ll long long 
#define scn(n) scanf("%d",&n)
#define lscn(n) scanf("%lld",&n)
#define lpri(n) printf("%lld",n)
#define pri(n) printf("%d",n)
#define pln() printf("\n")
#define priln(n) printf("%d\n",n)
#define lpriln(n) printf("%lld\n",n)
#define rep(i,init,n) for(int i=init;i<n;i++)
#define pb push_back     
#define mp make_pair
#define F first
#define S second
#define gcd __gcd
#define inf INT_MAX
#define ninf INT_MIN      
const ll mod=1e9+7;
const int N=1e6+4;
 
int main()                  
{
    int n;
    cin>>n;
    
    ll arr[n+1];
    arr[0]=-1;
    for(int i=1;i<=n;i++)
    {
        cin>>arr[i];
    }
    
    int ans=0;
    for(int i=1;i<=n;i++)
    {
        for(int j=1;j<=i;j++)
        {
            for(int k=1;k<=j;k++)
            {
                if((arr[i]!=arr[j]) and (arr[j]!=arr[k]) and (arr[i]!=arr[k]))
                {
                    if((arr[i]+arr[j]>arr[k]) and (arr[j]+arr[k]>arr[i]) and (arr[i]+arr[k]>arr[j]))
                    ans++;
                }
            }
        }
    }
    cout<<ans;
    return 0;
}


Measured memory_bytes: 3644
#include<iostream>
#define ll long long

bool res(ll len,ll a[],ll k,ll n){
  for(int i=0;i<n;i++){
    k-=(a[i]+len-1)/len-1;
  }
  return k>=0;
}

ll bs(ll a[],ll k,ll n){
 ll l=1,r=1e9+10;
 while(l<r){
    ll mid = l+(r-l)/2;
    if(res(mid,a,k,n))
       r=mid;
    else
       l=mid+1;
 }
  return l;
}


int main(){
ll n,k;
 std::cin >> n >> k;
 ll a[n];
 for(ll i=0;i<n;i++)
      std::cin >> a[i];
  ll res=bs(a,k,n);
  std::cout << res << std::endl;
 return 0;
}


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

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  vector<int> a(n);
  for (auto&& e : a) {
    char c;
    cin >> c;
    e = c - '1';
  }
  bool f = false;
  if (count(begin(a), end(a), 1) == 0) {
    f = true;
    for (auto&& e : a) {
      e /= 2;
    }
  }
  int res = 0;
  for (int i = 0; i < n; ++i) {
    int j = n - i - 1;
    if ((i & j) == 0) {
      res += a[i];
    }
    res &= 1;
  }
  if (f) {
    res *= 2;
  }
  cout << res << '\n';
}


Measured memory_bytes: 4224
//#include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <queue>
#include <stack>
#include <iomanip>
#include <string>
#include <math.h>
#include<set>
#include<stdio.h>
#include <bitset>
#define ii int64_t
#define PI 3.14
#define lli long long int
#define li long int
#define mod 1000000007
#define f(x,n) for(int64_t x=0;x<n;++x)
#define fio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
// while(scanf("%d",&n)!=EOF)
using namespace std;



int main()
{
    fio
    ii n,i,j,k,x;
    cin>>n;
    ii dp[n+3][4],a[n+3][4];
    for(i=1;i<=n;++i)cin>>a[i][1]>>a[i][2]>>a[i][3];
    dp[1][1]=a[1][1];dp[1][2]=a[1][2];dp[1][3]=a[1][3];
    for(i=2;i<=n;++i)
    {
        dp[i][1]=a[i][1]+max(dp[i-1][2],dp[i-1][3]);
        dp[i][2]=a[i][2]+max(dp[i-1][1],dp[i-1][3]);
        dp[i][3]=a[i][3]+max(dp[i-1][2],dp[i-1][1]);
    }
    cout<<max(dp[n][1],max(dp[n][2],dp[n][3]));
    
    
    



}


Measured memory_bytes: 6528
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		int a,b;

		while(true){
			a = sc.nextInt();
			b = sc.nextInt();

			if(a == 0 && b == 0)break;

			System.out.printf("%d %d\n", Math.min(a, b),Math.max(a, b));
		}

	}
}



Measured memory_bytes: 40896
#include "bits/stdc++.h"
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define rep2(i, l, r) for (int i = (l); i < (r); i++)
#define ALL(x) (x).begin(), (x).end()     //昇順
#define RALL(x) (x).rbegin(), (x).rend()  // 降順
#define pri(x) cout << (x) << "\n"
#define pri2(x, y) cout << (x) << " " << (y) << "\n"
#define pri3(x, y, z) cout << (x) << " " << (y) << " " << (z) << "\n"
const long long mod = 1e9 + 7;
typedef long long ll;
typedef priority_queue<int> PQ;
typedef vector<long long> VL; // VL a(n);
typedef vector<bool> VB;
typedef vector<double> VD;
typedef vector<string> VS;
typedef vector<char> VC;
typedef vector<VS> VSS;
typedef vector<VC> VCC;
typedef vector<VL> VLL; // VII a(n,VI(m)) n * m
typedef pair<ll, ll> PL;
typedef map<ll, ll> MP; // MP a;
typedef vector<pair<ll, ll>> PS;

template <class T, class U>
bool chmax(T &a, U b) {
  if (a <= b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T, class U>
bool chmin(T &a, U b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
template <typename T>
ostream &operator<<(ostream &os, vector<T> &v) {
  os << "{";
  rep(i, (int)v.size()) { os << v[i] << (i < v.size() - 1 ? ", " : ""); }
  os << "}";
  return os;
}

// g++ -std=c++11 prac.cpp
// operator << (cout,a);
// chmin(min,a)

int main() {
  ll n,k,m,x=0,y=0,z = 0,h=0,w=0,ans=0,sum = 0, Max = -1, Min = 3e9+1;
  string s,t;
  bool ok=true; 
  cin >> x >> y;
  while(y >= x){
    x *= 2;
    ans++;
  }
  pri(ans);
  return 0;
}

Measured memory_bytes: 3608
#include <stdio.h>
float a,b,c,d,e,f,t;
main(){
  for(;~scanf("%f%f%f%f%f%f",&a,&b,&c,&d,&e,&f);
    t=a*e-b*d,printf("%.3f %.3f\n",(e*c-b*f)/t+0.,(a*f-d*c)/t+0.)
  );
  return 0;
}


Measured memory_bytes: 2760