akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
using namespace std;
int main() {
    int a,b;
    cin>>a>>b;
    if(a>9){
        cout<<"-1"<<endl;
    }
    else if(b>9){
        cout<<"-1"<<endl;
    }
    if(a<10&&b<10)
    cout<<a*b<<endl;
    return 0;
}

Measured memory_bytes: 256
n,m=map(int,input().split())
h=list(map(int,input().split()))
ab=[list(map(int,input().split())) for i in range(m)]
d=[ [] for i in range(n+1)]
for i in range(m):
  #a=ab[i][0]
  #b=ab[i][1]
  d[ab[i][0]].append(h[ab[i][1]-1])
  d[ab[i][1]].append(h[ab[i][0]-1])
count=0
d.pop(0)
for i in range(0,len(d)):
  if len(d[i])==0:
    count+=1
  elif h[i]>max(d[i]):
    count+=1
print(count)
    
  
  

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

#define int long long
#define ll long long
#define f1(i,a,b) for(i=a;i<b;i++)
#define f2(i,a,b) for(i=a;i>=b;i--)
#define endl '\n'
#define pb push_back
#define gp " "
#define ff first
#define ss second
#define mp make_pair

const int mod=1000000007;
int i,j;
ll temp;

int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    // #ifndef ONLINE_JUDGE
    // 	freopen("/home/akmittal/Desktop/Competitive Programming/in.txt","r",stdin);
    // 	freopen("/home/akmittal/Desktop/Competitive Programming/out.txt","w",stdout);
    // #endif
    int n;
    cin>>n;
    int ans=0;
    int a[n];
    f1(i,0,n)
    cin>>a[i];
    int cur=0;
    f1(i,0,n-1)
    {
    	if(a[i+1]<=a[i])
    	{
    		cur++;
    		ans=max(cur,ans);
    	}
    	else
    		cur=0;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//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; }

int main(void){
    string a,b,c; cin >> a >> b >> c;
    cout << a[0] << b[0] << c[0] << endl;
}

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

int main(){
	
	int h,w; cin>>h>>w;
	vector<string> s(h);
	for(auto &i:s) cin>>i;
	vector<vector<int>> lh(h,vector<int>(w,0)), lw(h,vector<int>(w,0));
	for(int i=0; i<h; i++){
		for(int j=0; j<w; j++){
			if(s.at(i).at(j)!='#'){
				if(j>0&&s.at(i).at(j-1)=='.'){
					lw.at(i).at(j) = lw.at(i).at(j-1);
				}
				else if(s.at(i).at(j)=='.'){
					int x=j; 
					while(1){
						if(x<w&&s.at(i).at(x)=='.') {
							lw.at(i).at(j)++;
						}
						else break;
						x++;
						
					}
				} 
			}
			if(s.at(i).at(j)!='#'){
				if(i>0&&s.at(i-1).at(j)=='.'){
					lh.at(i).at(j) = lh.at(i-1).at(j);
				}
				else if(s.at(i).at(j)=='.'){
					int y=i; 
					while(1){
						if(y<h&&s.at(y).at(j)=='.') {
							lh.at(i).at(j)++;
						}
						else break;
						y++;
					}
				} 
			}
		}
	}
	int msum{};
	for(int i=0; i<h; i++){
		for(int j=0; j<w; j++){
			if(lw.at(i).at(j)==0||lh.at(i).at(j)==0) continue;
			msum = max(msum, lw.at(i).at(j)+lh.at(i).at(j)-1);
		}
	}
	cout << msum << endl;
}


Measured memory_bytes: 35712
#pragma GCC optimize("Ofast") 

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

#include <bits/stdc++.h>
using namespace std;
#define int long long int
#define endl "\n"
#define debug(...) fprintf(stderr, __VA_ARGS__), fflush(stderr)
#define bew ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define all(x) x.begin(),x.end()
#define pb push_back
#define fi first
#define se second
#define mod (long)(1e9+7)
#define ip(ar,n) for(int i=0;i<n;++i)cin>>ar[i];
#define op(ar,n) for(int i=0;i<n;++i)cout<<ar[i]<<" ";
#define test int t;cin>>t;while(t--)
#define tar(x) int x;cin>>x;
#define fil(ar,val) memset(ar,val,sizeof ar)
#define loop(n) for(int i=0;i<n;++i)

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

typedef vector<int> vi; 
typedef pair<int, int> ii; 
typedef vector<ii> vii; 
typedef set<int> si;
typedef map<int,int> mi;

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

int a[21][21];
int n;
int dp[21][1<<21];

int rec(int ind,int bi)
{
    int as=1<<n;
    --as;
    if(ind>=n)
        if(as==bi)
        return 1;
        else
        return 0;
    if(dp[ind][bi]!=-1)
        return dp[ind][bi];
        
    int x=0;
    for(int i=0;i<n;++i)
    {
        if(bi&(1<<i))
        continue;
        if(a[ind][i])
        x+=rec(ind+1,bi|(1<<i));
    }
    dp[ind][bi]=x%mod;
    return dp[ind][bi];
}



signed main() {
bew;
cin>>n;
memset(dp,-1,sizeof dp);
for(int i=0;i<n;++i)
for(int j=0;j<n;++j)
cin>>a[i][j];

cout<<rec(0,0);

return 0;
}

Measured memory_bytes: 344320
#include <iostream>
#include <stdio.h>
#include <string>
#include <vector>
#include <cmath>
#include <algorithm>

using namespace std;

int main()
{
  int a,b;
  cin >> a >> b;
  if(b != 1 && a > b)
    cout << "Alice" << endl;
  else if(a == 1 && b != 1)
    cout << "Alice" << endl;
  else if(a != 1 && b > a)
    cout << "Bob" << endl;
  else if(b == 1 && a != 1)
    cout << "Bob" << endl;
  else
    cout << "Draw" << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include <string>
#include <algorithm>
#include <queue>
#include <stack>
#include <stdio.h>
#include <cmath>
#include <string.h>
#include <vector>

#define ll long long
using namespace std;

int main()
{
    //freopen("C:\\Users\\23733\\Desktop\\in.txt","r",stdin);
    int N, K;
    cin >> N >> K;
    ll ans = 0;
    for(int i = K + 1; i <= N; i++)
    {
        ans += (i - K)*(N / i);
        if((N % i) >= K) ans += (N % i)-max(0,K-1);
    }
    cout << ans << endl;
    return 0;
}

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

int main() {
  // read inputs
  long N, A, B, C, D;
  scanf("%ld %ld %ld %ld %ld", &N, &A, &B, &C, &D);

  // solve
  long is_possible = 0;
  for (long k = 0; k <= N - 1; k++) {
    if (B - A >= k * C - (N - 1 - k) * D && B - A <= k * D - (N - 1 - k) * C) {
      is_possible = 1;
      break;
    }
  }
  if (is_possible) {
    printf("YES\n");
  } else {
    printf("NO\n");
  }
}


Measured memory_bytes: 128
import heapq
import sys
from collections import defaultdict

input = sys.stdin.readline

def dijkstra_heap(s,edge,n):
    #始点sから各頂点への最短距離
    d = [10**20] * n
    used = [True] * n #True:未確定
    d[s] = 0
    used[s] = False
    edgelist = []
    for a,b in edge[s]:
        heapq.heappush(edgelist,a*(10**6)+b)
    while len(edgelist):
        minedge = heapq.heappop(edgelist)
        #まだ使われてない頂点の中から最小の距離のものを探す
        if not used[minedge%(10**6)]:
            continue
        v = minedge%(10**6)
        d[v] = minedge//(10**6)
        used[v] = False
        for e in edge[v]:
            if used[e[1]]:
                heapq.heappush(edgelist,(e[0]+d[v])*(10**6)+e[1])
    return d

def main():
    N, X, Y = map(int, input().split())
    X -= 1
    Y -= 1
    edge = [[] for _ in range(N)]
    for i in range(N-1):
        edge[i].append((1,i+1))
        edge[i+1].append((1,i))
    
    edge[X].append((1,Y))
    edge[Y].append((1,X))
    d = []
    for i in range(N):
        tmp = dijkstra_heap(i, edge, N)
        d.append(tmp)

    e = defaultdict(int)
    for i in range(N):
        for j in range(i,N):
            if i == j:
                continue
            e[d[i][j]] += 1

    for i in range(1,N):
        print(e[i])

if __name__ == "__main__":
    main()

Measured memory_bytes: 132572
#include<bits/stdc++.h>
using namespace std;
string to_string(const string& s) {
	return '"' + s + '"';
}
string to_string(const bool b) {
	return (b ? "true" : "false");
}
string to_string(const char* s) {
	return to_string((string)s);
}
string to_string(const char c) {
	string s = "'";
	s += c;
	s += "'";
	return s;
}
template<class T, class U>
string to_string(const pair<T, U>& p) {
	string s = "(";
	s += to_string(p.first);
	s += ", ";
	s += to_string(p.second);
	s += ")";
	return s;
}
template<class T>
string to_string(const T& a) {
	bool first = true;
	string s = "{";
	for (const auto& x : a) {
		if(!first){
			s += ", ";
		}
		first = false;
		s += to_string(x);
	}
	s += "}";
	return s;
}
void debug_out() {cerr << '\n';}
template<class Head, class... Tail>
void debug_out(Head head, Tail... tail) {
	cerr << ' ' << to_string(head);
	debug_out(tail...);
}
#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "] = ", debug_out(__VA_ARGS__)
#else
#define debug(...)
#endif
using ll = long long;
using ld = long double;
const int mod = 1e9 + 7;
const int inf = 1e9 + 100;
const ll inf64 = 7e18l;
const int N = 10000;
int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout << fixed << setprecision(20);
	int n;
	cin >> n;
	vector<int> a(n), b(n);
	for (int i = 0; i < n; ++i) {
		cin >> a[i];
	}
	for (int i = 0; i < n; ++i) {
		cin >> b[i];
	}
	int ok = false;
	for (int i = 0; i < n; ++i) {
		if (b[i] < a[i]) {
			break;
		}
		if (a[i] < b[i]) {
			ok = true;
			break;
		}
		
	}
	if (!ok) {
		swap(a, b);
	}
	int answer = 0;
	do {
		if (a == b) {
			break;
		}
		++answer;
	} while (next_permutation(a.begin(), a.end()));
	cout << answer << '\n';
	return 0;
}


Measured memory_bytes: 256
import java.io.FileInputStream;
import java.io.InputStream;
import java.util.Scanner;

public class Main{
	static Scanner sc;

	public static void main(String[] args) throws Exception {
		//InputStream in = new FileInputStream("src/input.txt");
		InputStream in = System.in;
		//PrintStream out = new PrintStream("src/output.txt");

		//System.setOut(out);

		sc = new Scanner(in);

		int N = sc.nextInt();
		int[] a = new int[N];
		int answer = 0;

		for(int i = 0; i < N; i++){
			a[i] = sc.nextInt();
		}

		for(int i = 0; i < N; i++){
			if(a[a[i]-1] == i+1){
				answer++;
			}
		}

		System.out.println(answer/2);

		//out.close();
	}
}

Measured memory_bytes: 52960
N = gets.chomp
N_list = N.split('').map(&:to_i).reverse

result = 0
(N.length+1).times do |i|
  n = N_list[i]
  break unless n
  if n == 5 &&  N_list[i+1] && N_list[i+1] >= 5
    result += 5
    N_list[i+1] = N_list[i+1] + 1
  elsif n <= 5
    result += n
  elsif n >= 10
    N_list[i+1] ||= 0
    N_list[i+1] = N_list[i+1] + 1
  else
    N_list[i+1] ||= 0
    N_list[i+1] = N_list[i+1] + 1
    result += 10 - n
  end
end

puts result

Measured memory_bytes: 73228
n,m = map(int, input().split())
S = [set(list(map(int, input().split()))[1:])for _ in range(m)]
P = list(map(int, input().split()))

N = [n_i for n_i in range(1, n+1)]
S_all = []

for i in range(2**n):
  s = set()
  for j in range(n):
    if i&(1<<j):
      s.add(N[-j])
  S_all.append(s)

count = 0

for s_i in S_all:
  count_flg = True
  for m_i in range(m):
    if P[m_i]==0 and (len(S[m_i]&s_i))%2==1: count_flg = False
    if P[m_i]==1 and (len(S[m_i]&s_i))%2==0: count_flg = False
  if count_flg:count += 1

print(count)

Measured memory_bytes: 3444
import java.util.Scanner

fun main(args:Array<String>){

    val cin = Scanner(System.`in`)
    val list = Array(4,{Array<Int>(13,{0})})
    var n = cin.nextInt()

    for(i in 1..n){
    when(cin.next()){
	"S" -> list[0][cin.nextInt()-1] = 1
	"H" -> list[1][cin.nextInt()-1] = 1
	"C" -> list[2][cin.nextInt()-1] = 1
	"D" -> list[3][cin.nextInt()-1] = 1
    }
    }

    for(i in 0..3){
	for(j in 0..12){
	    if(list[i][j] == 0){
		when(i){
		    0 -> println("S ${j+1}")
		    1 -> println("H ${j+1}")
		    2 -> println("C ${j+1}")
		    3 -> println("D ${j+1}")
		}
	    }

	}
    }
    
}



Measured memory_bytes: 27452
#include <bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define all(x) begin(x),end(x)
#define F(i,n) for (int i = 0; i < n; ++i)
#define F1(i,n) for (int i = 1; i <= n; ++i)
#define dbg(x) cerr << #x << " = " << x << endl
#define dbgg(x) cerr << #x << " = " << x << ' '
#define T(x) x[pool]
#define mineq(x,y) { if ((x) > (y)) (x) = (y); }
#define maxeq(x,y) { if ((x) < (y)) (x) = (y); }
#define MEOW cout << "meowwwww" << '\n'; system("pause");
#define int long long
using namespace std;
typedef vector<int> vi;
typedef pair<int, int> pii;

template<typename T>
ostream& operator <<(ostream &s, const vector<T> &c)
{
	s << "[ "; for (auto it : c) s << it << " "; s << "\b]\n";
	return s;
}

template<typename T>
ostream& operator <<(ostream &s, const pair<int, T> &c)
{
	s << "[ "; cout << c.fi << " , " << c.se << " ] ";
	return s;
}

const int mod = 1000000007, maxn = 234567;
int h, w, n;
int frac[maxn], inv[maxn], dp[maxn];
vector<pii> poi;

void input()
{
	ios::sync_with_stdio(false); cin.tie(0);
	cin >> h >> w >> n;
	F1 (i, n)
	{
		int x, y; cin >> x >> y;
		poi.pb(mp(x, y));
	}
}

int C(int n, int m)
{
	return (frac[n] * inv[n - m] % mod) * inv[m] % mod;
}

int power(int a, int b)
{
	if (b == 0) return 1;
	int ret = power(a, b / 2);
	ret = ret * ret % mod;
	if (b & 1) ret = ret * a % mod;
	return ret;
}

void solve()
{
	frac[0] = 1;
	F1 (i, maxn - 1) frac[i] = frac[i - 1] * i % mod;
	inv[maxn - 1] = power(frac[maxn - 1], mod - 2);
	for (int i = maxn - 2; i >= 0; --i)
		inv[i] = inv[i + 1] * (i + 1) % mod;
	poi.pb(mp(1, 1));
	sort(all(poi));
	++n;
	for (int i = n - 1; i >= 0; --i)
	{
		dp[i] = C(h + w - poi[i].fi - poi[i].se, h - poi[i].fi);
		for (int j = n - 1; j > i; --j)
		{
			if (poi[j].fi >= poi[i].fi && poi[j].se >= poi[i].se)
				dp[i] = (dp[i] - dp[j] * 
					C(poi[j].fi + poi[j].se - poi[i].fi - poi[i].se
					, poi[j].fi - poi[i].fi) % mod) % mod;
		}
	}
	cout << (dp[0] + mod) % mod << '\n';
}

main()
{
	input();
	solve();
}


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

typedef long long ll;
typedef unsigned long long ull;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define MAX 9223372036854775807
#define MOD 1000000007


int main(void){
        int n;
        cin >> n;
        vector<int> x(n), y(n);

        rep(i,n)
            cin >> x[i] >> y[i];

        double all_sum = 0;

        auto dist = [&](int i, int j) {
            double dx = x[i] - x[j];
            double dy = y[i] - y[j];
            return sqrt(dx * dx + dy * dy);
        };

        //順列の数字を入力
        vector<int> P_num(n);
        rep(i, n) P_num.at(i) = i;

        do{
          rep(i, n - 1)
            all_sum += dist(P_num[i], P_num[i + 1]);
    } while (next_permutation(P_num.begin(), P_num.end()));

    int factorial = 1;
    for (int i=n;i>=1;i--)
        factorial *= i;

    double ans = all_sum /(double)factorial;
   
    printf("%.12f\n",ans);
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#define rep(i, a, n) for(int i = a; i < n; i++)
using namespace std;

const long long mod = 1000000007;

long long mod_pow(long long x,long long n){
    if(n == 0) return 1;
    long long res = mod_pow(x*x % mod, n / 2);
    if(n & 1) res = res*x % mod;
    return res;
}

int main(){
    long long m, n;
    cin >> m >> n;
    cout << mod_pow(m, n) % mod << endl;
}

Measured memory_bytes: 3092
N, C = map(int, input().split())
ch = [[0]*(10**5+1) for _ in range(C)]

for _ in range(N):
  s, t, c = map(int, input().split())
  ch[c-1][s] += 1
  ch[c-1][t] -= 1

for c in range(C):
  for i in range(10**5):
    if ch[c][i+1] == 1:
      ch[c][i+1] = ch[c][i+1] + ch[c][i]
      ch[c][i] = 1
    else:
      ch[c][i+1] = ch[c][i+1] + ch[c][i]

ans = 0
for i in range(10**5):
  temp = 0
  for c in range(C):
    temp += ch[c][i+1]
  ans = max(ans, temp)

print(ans)

Measured memory_bytes: 93384
open Batteries
module EnumL = Enum.Labels
module ListL = List.Labels
module ArrayL = Array.Labels

let dbg0 x = Printf.eprintf "[debug]%s\n" @@ dump x
let dbg1 x = dbg0 x; x

let id = identity

let (++) n m = List.range n `To m
let (++-) n m = if n >= m then List.range n `Downto m else []
let (++^) n m = if n < m then List.range n `To (pred m) else []

module ModOp = struct
  let prime = 1_000_000_007
  let (-) a b = (a + prime - b) mod prime
  let (+) a b = (a + b) mod prime
  let ( * ) a b = (a * b) mod prime

  let rec pow x n =
    if n = 0 then 1
    else if n mod 2 = 0 then pow (x*x) (n/2)
    else x * pow (x*x) (n/2)
end

let scan fmt = Scanf.sscanf (read_line ()) fmt

let scan_lines n fmt f =
  if n = 0 then []
  else List.map (fun _ -> scan fmt f) (1 ++ n)

let scan_list ?sep cnv =
  let line = read_line () in
  (match sep with
   | None -> List.map String.of_char @@ String.to_list line
   | Some sep -> String.split_on_char sep line)
  |> List.map cnv

let scan_array ?sep cnv = Array.of_list @@ scan_list ?sep cnv

let scan_matrix n m e ?sep conv =
  let arr = Array.make_matrix n m e in
  ListL.iter (0 ++^ n)
    ~f:(fun i -> arr.(i) <- Array.of_list @@ scan_list ?sep conv);
  arr

let atoi c = Char.code c - Char.code '0'

let rec powerset = function
  | [] -> [[]]
  | hd::tl ->
    let pws =  powerset tl in
    pws @ ListL.map pws ~f:(fun pw -> hd::pw)

let permutations l =
  let rec interleave x = function
    | [] -> [[x]]
    | (hd::tl) as l ->
      (x::l) :: (interleave x tl |> ListL.map ~f:(fun l -> hd::l)) in
  let rec aux = function
    | [] -> [[]]
    | a::rest ->
      aux rest |> ListL.map ~f:(interleave a) |> List.concat in
  aux l

let intersection l =
  EnumL.filter ~f:(fun x -> EnumL.exists ~f:((=) x) @@ Enum.clone l)

let zip l m =
  let n = min (List.length l) (List.length m) in
  List.combine (List.take n l) (List.take n m)

let lower_bound n f =
  let rec aux l u =
    if u - l > 1 then
      let m = (l + u) / 2 in
      if f m then aux l m
      else aux m u
    else u in aux (-1) n

let between n x m = n <= x && x < m

let (a,b,c,d) = scan "%d %d %d %d" Tuple4.make

exception Found of bool

let () =
  try ListL.iter (0++100) ~f:(fun i ->
      let n = a - d*i in
      let m = c - b*i in
      if n <= 0 || m <= 0 then
        if n > 0 then raise @@ Found true
        else if n <= 0 && m <= 0 then raise @@ Found true
        else raise @@ Found false
    ) with | Found t ->
    Printf.printf "%s\n" (if t then "Yes" else "No")


Measured memory_bytes: 5436
import java.util.*;
import java.lang.*;
import java.io.*;								

public class Main{
	public static void main(String args[]){
		InputStreamReader rd = new InputStreamReader(System.in);
		BufferedReader br = new BufferedReader(rd);
		try{
				String str = br.readLine();
				String initial[] = str.split(" ");
				
				int number = Integer.parseInt(initial[0]);
				int legs = Integer.parseInt(initial[1]);
				float t = (float)legs/2-(float)number;
				float c = (float)number-t;
				
				if((c==0 && t==0)||c<0||t<0){
					System.out.println("No");
				}
				else if((c == Math.floor(c))&&(t==Math.floor(t))){
					System.out.println("Yes");
				}
				else{
					System.out.println("No");
				}
				
		}
		catch(Exception e){
			return;
		}
	}
}

Measured memory_bytes: 32768
#include<stdio.h>

int main(void){
   char S[3];
   int j=0;
   scanf("%s",S);
   for(int i=1;i<3;i++){
      if(S[i-1]==S[i]){
      }else if(S[i-1]!=S[i]){
         j=1;
         break;
      }
   }
   if(j==0){
      printf("No");
   }else if(j==1){
      printf("Yes");
   }
   return 0;
}


Measured memory_bytes: 1736
n=list(map(int,input().split()))
#print(n)

N=n[0]
a=n[1]
b=n[2]
c=n[3]
d=n[4]

w=(N//a)*b
x=(N//c)*d
y=((N//a)+1)*b
z=((N//c)+1)*d

if (N%a)==0 or (N%c)==0:
    if (N%a)==0 and (N%c)==0:
        if w<=x:
            print(w)
        elif w>x:
            print(x)
    elif (N%c)==0:
        if x<=y:
            print(x)
        elif x>y:
            print(y)
    elif (N%a)==0:
        if w<=z:
            print(w)
        elif w>z:
            print(z)
            

else:
    if y<=z:
        print(y)
    elif y>z:
        print(z)
    



Measured memory_bytes: 5604
import sys
import itertools
# import numpy as np
import time
import math
 
sys.setrecursionlimit(10 ** 7)
 
from collections import defaultdict
 
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

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

K = [0] * M
S = [0] * M
for i in range(M):
    line = list(map(int, input().split()))
    K[i] = line[0]
    S[i] = line[1:]
P = list(map(int, input().split()))

ans = 0
for bit in range(2 ** N):
    ons = 0
    for i in range(M):
        total = K[i]
        for j in S[i]:
            if bit >> (j - 1) & 1 == 0:
                total -= 1
        if total % 2 == P[i]:
            ons += 1
    if ons == M:
        ans += 1
print(ans)

Measured memory_bytes: 9360
#include <iostream>
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	ll n,b=0;
	cin>>n;
	ll a[n+10];
	for(ll i=0;i<n;i++){
	    cin>>a[i];
	}
	ll m=n;
	n=(n*(n-1))/2;
	for(ll i=0;i<n;i++){
	  for(ll j=i;j<m-1;j++){
	      b=b+(a[i]*a[j+1]);
	     // cout<<b<<" ";
	  }
	}
	cout<<b;
	return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
int n , m;
long long ans;
int main(){
	cin >> n >> m;
	ans = 0;
	ans += (n - m) * 100LL;
	ans += 1900LL * m;
	ans *= 1LL << m;
	printf("%lld\n" , ans);
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<stdlib.h>
#include<queue>
#include<map>
#include<vector>
#include<cmath>
#include<fstream>
#include <set>
//freopen(".in","r",stdin);
//freopen(".out","w",stdout);
//freopen("input.txt","r",stdin);
//freopen("output.txt","w",stdout);
const int  MAXN =1e6+10;
const int mod = 1e9 + 7;
const long long INF = 0x7f7f7f7f7f7f7f7f;
const int inf= 0x3f3f3f3f;
#define eps 1e-8
#define PI 3.1415926535898
#define lowbit(x) (x&(-x))
using namespace std ;
//getline(cin,s);
//set<ll>::iterator it;
//map<int,int>::iterator it;
typedef long long ll;
int n,a[MAXN];
//unordered_map<int,int>mp;
int need[MAXN];
//map<int,int>mp;
//TLE了 可能思路：每个数*一个数的形式 判断所得的num 然后与n比较 
int main()
{
	scanf("%d",&n);int ans=0,max1=0;
	for(int i=1;i<=n;i++) scanf("%d",&a[i]),need[a[i]]++,max1=max(max1,a[i]);
	for(int i=2;i<=max1;i++)
	{
		int num=0;
		for(int j=i;j<=max1;j+=i)
		{
			num+=need[j];
		}
		ans=max(num,ans);
	}
	if(ans<=1) printf("pairwise coprime\n");
	else if(ans<n) printf("setwise coprime\n");
	else printf("not coprime\n");
	return 0;
} 

Measured memory_bytes: 11460
n = int(input())
p = list(map(int, input().split()))
count = 0
list = [0] * 3
for num in range(1,n - 1):
    list[0] = p[num-1]
    list[1] = p[num]
    list[2] = p[num+1]
    if list[1] <= list[0] and list[1] >= list[2]:
        count += 1
    if list[1] >= list[0] and list[1] <= list[2]:
        count += 1

print(count)


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

import static java.lang.Integer.parseInt;

public class Main {

	static int MAX = 999 + 51;
	static char TERM = 'Z';

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

		while ((line = br.readLine()) != null && !line.isEmpty()) {

			int n = parseInt(line);
			if (n == 0) break;

			//load and pre proc.
			char[][] board = new char[n][MAX];
			for (int i = 0; i < n; i++) {
				line = br.readLine();
				for (int j = 0; j < line.length(); j++) {
					char c = line.charAt(j);
					board[i][j] = c;
					if (c == '.' && line.charAt(j + 1) >= 'a') {
						board[i][j] = '+';
					}
				}
				board[i][line.length()] = TERM;
			}

			//write off
			//vertical bar.
			for (int j = 0; j < MAX; j++) {
				int check = 0;
				for (int i = n - 1; i > 0; i--) {
					char c = board[i][j];
					if (c == '+') {
						for (int k = i - 1; k > 0; k--) {
							if (board[k][j] == '.') board[k][j] = '|';
							else break;
						}
					} else if (c == '.') {
						board[i][j] = ' ';
						check++;
					}
				}
				//if (check == 0) break;
			}

			//ans.
			for (int i = 0; i < n; i++) {
				for (int j = 0; j < MAX; j++) {
					char c = board[i][j];
					if (c == TERM) break;
					System.out.print(board[i][j]);
				}
				System.out.println();
			}
		} //end while
	} //end main
}

Measured memory_bytes: 66616
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define repo(i,n) for(int i = 1; i < (int)(n); i++)
#define pb push_back
#define mp make_pair
#define np next_permutation
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
#define mod 1000000007
#define pi acos(-1.0)
const ll INF = 1LL<<61;
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; }
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }
ll jou(ll N, ll P){if(P==0) return 1;
  if(P%2==0){ll t = jou(N, P/2);return t*t % mod;
  }return (N * jou(N, P-1)) % mod;}  //jou(n,mod-2)で逆元
//intの最大値2147483647 ≒ 2×10^9
//long longの最大値9223372036854775807 ≒ 9×10^18
//'大文字'+=32;    で小文字に
//  cout << fixed << setprecision (20);   小数点以下2０桁まで
//実行時間制約2秒では２×10^8回くらいまで計算できる




int main(){
  string s;
  cin>>s;
  int n=s.size();

  string nox="";
  rep(i,n){
    if(s[i]!='x') nox+=s[i];
  }

  auto copy=nox;
  reverse(all(copy));

  if(nox!=copy) {
    cout << -1 << endl;
    return 0;
  }

  int m=nox.size();

  vector<int> zen((m+1)/2); 
  vector<int> go((m+1)/2); 

  int cnt=0;
  int now=0;
  rep(i,n){
    if(s[i]=='x') cnt++;
    else {
      zen[now]=cnt;
      cnt=0;
      now++;
    }
    if(now>=(m+1)/2) break;
  }

  cnt=0;
  now=0;
  for(int i=n-1;i>=0;i--){
    if(s[i]=='x') cnt++;
    else {
      go[now]=cnt;
      cnt=0;
      now++;
    }
    if(now>=(m+1)/2) break;
  }

  int ans=0;
  rep(i,(m+1)/2){
    ans+=abs(zen[i]-go[i]);
  }

  cout << ans << endl;
}

Measured memory_bytes: 1024
#include<cstdio>
#include<iostream>
#define nc getchar
using namespace std;
inline void read(int &x) {
	char b = nc(); x = 0;
	for (; !isdigit(b); b = nc());
	for (; isdigit(b); b = nc()) x = x * 10 + b - '0';
}
typedef long long ll;
int n, c[100005];
ll pow(ll a, ll b, ll m) {
	ll res = 1;
	for (a %= m; b; b >>= 1, (a *= a) %= m)
		if (b & 1) (res *= a) %= m;
	return res;
}
bool check() {
	if (n & 1) {
		if (c[0] != 1) return false;
		for (int i = n - 1; i; i -= 2)
			if (c[i] != 2) return false;
	} else {
		for (int i = 1; i < n; i += 2)
			if (c[i] != 2) return false;
	} return true;
}
int main() {
	read(n);
	for (int t, i = 0; i < n; ++i)
		read(t), ++c[t];
	printf("%lld\n", check() ? pow(2, n / 2, 1e9+7) : 0ll); 
	return 0;	
}


Measured memory_bytes: 640
#include"bits/stdc++.h"
using namespace std;
#define REP(k,m,n) for(int (k)=(m);(k)<(n);(k)++)
#define rep(i,n) REP((i),0,(n))
using ll = long long;
constexpr ll MOD = 1e9 + 7;

vector<vector<vector<ll>>> way(ll D) {
	// 桁数 -> 末尾数字 -> D除算の余り -> 場合の数
	vector<vector<vector<ll>>> dp(1e4 + 3, vector<vector<ll>>(10, vector<ll>(D, 0)));
	rep(i, 10)dp[0][i][i%D]++;

	// 桁数 -> ソースの末尾数字 -> ソースのD除算余り -> 次の末尾数字
	rep(e, 1e4 + 2)rep(num, 10)rep(d, D)rep(add, 10) {
		(dp[e + 1][add][(d + add) % D] += dp[e][num][d]) %= MOD;
	}
	return dp;
}

int main()
{
	ll D;
	string N;
	cin >> N >> D;
	auto dp = way(D);

	ll res = 0;
	ll left = 0;
	rep(i, N.size()) {
		ll pos = N.size() - i - 1;
		ll top = N[i] - '0';
		rep(j, top) {
			(res += dp[pos][j][(D * 10000 - left) % D]) %= MOD;
		}
		(left += top) %= D;
	}
	if (left == 0)res++;
	//rep(i, N.back() - '0' + 1)if ((left + i) % D == 0)res++;
	res = (res - 1 + MOD) % MOD;
	cout << res % MOD << endl;

	return 0;
}


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

//#define int long long
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<n;++i)
#define exrep(i, a, b) for(ll i = a; i < b; i++)
#define out(x) cout << x << endl
#define EPS (1e-7)
#define gearup ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<pair<int,int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<bool> > vvb;
typedef vector<vector<double> > vvd;
typedef vector<vector<string> > vvs;
typedef vector<ll> vl;
typedef vector<vector<ll> > vvl;
typedef vector<vector<vector<ll> > > vvvl;
ll MOD = 1000000007;
const long long L_INF = 1LL << 60;
const int INF = 2147483647; // 2^31-1
const double PI = acos(-1);
//cout<<fixed<<setprecision(10);

template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b;return true;}return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b;return true;}return false;}
template<class T> void debug(T v){rep(i,v.size()) cout<<v[i]<<" ";cout<<endl;}
const ll dx[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll dy[8] = {0, 1, 1, 1, 0, -1, -1, -1};
 
signed main(){
    gearup;
    ll n,k; cin >> n >> k;
    vl a(n);
    rep(i,n)cin>>a[i];
    vb dp(k+100,false);

    rep1(i,k+1){
        rep(j,n){
            if(i-a[j]>=0)dp[i] = (dp[i] | !dp[i-a[j]]);
        }
    }
    if(dp[k])out("First");
    else out("Second");
}


Measured memory_bytes: 384
import java.util.Scanner;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    String S = sc.nextLine();
    boolean flag = true;

    for (int i = 0; i < S.length(); i++) {
    	char c = S.charAt(i);
    	if(i % 2 == 0) {
    		if(c == 'R' || c == 'U' || c == 'D') {
    			continue;
    		} else {
    			flag = false;
    			break;
    		}
    	} else {
    		if(c == 'L' || c == 'U' || c == 'D') {
    			continue;
    		} else {
    			flag = false;
    			break;
    		}
    	}
    }
    if (flag) {
    	System.out.println("Yes");
    } else {
    	System.out.println("No");
    }
  }
}

Measured memory_bytes: 23124
mod = 1000000007

S = input()
n = 1
a = 0
ab = 0
abc = 0
for s in S:
    if s in "A":
        a += n
    if s in "B":
        ab += a
    if s == "C":
        abc += ab
    if s in "?":
        n, a, ab, abc = 3 * n, 3 * a + n, 3 * ab + a, 3 * abc + ab
    n %= mod
    a %= mod
    ab %= mod
    abc %= mod

print(abc % mod)


Measured memory_bytes: 3188
long d['~~'];A,x,i,j;main(n){for(scanf("%d%d",&n,&A),d[n*=A]=1;~scanf("%d",&x);i=5e3-i)for(x-=A,j=2*n;~--j;)d[5000-i+j]=d[i+j]+(j<x|j-x>2*n?0:d[i+j-x]);printf("%ld",d[i+n]-1);}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <cmath>
#include <sstream>
#include <iomanip>
#include <set>
using namespace std;
typedef long long int ll;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define yes cout << "yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl
#define no cout << "no" << endl

const int INF = 1001001001;
const int mod = 1000000007;
#define PI 3.14159265359;

void P(int x) {cout << x << endl;}
void P(long x) {cout << x << endl;}
void P(double x) {cout << x << endl;}
void P(ll x) {cout << x << endl;}
void P(string x) {cout << x << endl;}
void P(char x) {cout << x << endl;}

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

int main() {
  ll r, d, x;
  cin >> r >> d >> x;
  rep (i, 10) {
    P(r * x - d);
    x = r * x - d;
  }
  return 0;

}

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

#define int long long
#define endl "\n"
#define mod 1000000007
#define pb push_back
#define ff first
#define ss second
#define FIO ios_base::sync_with_stdio(false); cin.tie(NULL);


main(){
	FIO
	int n;
	cin>>n;
	string str;
	cin>>str;
	int i,j,k=0;
	string s = str;
	sort(s.begin(),s.end());
	for(i=0;i<n;i++){
		if(s[i]!=str[i])
		k++;
	}
	cout<<(k/2)<<endl;
}

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

/*string dfs(string s, string t, int i, int sum){
  if(i==4 && sum == 7) {
    t = t + "=7";
    return t;
  }
  else if(i==4) return "";
  else if(i==0){
    char o = s.at(i);
    int a = o - '0';
    string p = t + s.at(i);
    string m = t + s.at(i); 
    return dfs(s, p, i+1, sum+a) + dfs(s, m, i+1, sum-a);
  }
  else{
    char o = s.at(i);
    int a = o - '0';
    string p = t + "+" + s.at(i);
    string m = t + "-" + s.at(i); 
    return dfs(s, p, i+1, sum+a) + dfs(s, m, i+1, sum-a);
  }
}*/

int main(){
  /*
  int n, i, j;
  cin >> n;
  vector<int> A(n);
  rep(i, n) cin >> A[i];
  */
  int n, i, j;
  cin >> n;
  vector<int> P(n);
  rep(i,n) cin >> P[i];
  int count=1;
  int tmp_max = P[0];
  int tmp_min = P[0];
  for(i=1; i<n;i++){
      if(P[i]>tmp_max) tmp_max = P[i];
      else if(tmp_min>=P[i]) {tmp_min=P[i]; count++;}
  }
  cout << count << endl;
}


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

using namespace std;

const int N = 1000000;

vector<bool> p;

void init(){
    p.assign(N, true); p[0] = p[1] = false;
    for(int i=2; i<N; ++i)if(p[i]){
        for(int j=i<<1; j<N; j+=i)p[j] = false;
    }
}

int main(){
    init();
    int a, d, n;
    while(cin >> a >> d >> n, a|d|n){
        int x = a;
        for(; x<N; x+=d){
            if(p[x])n--;
            if(n == 0)break;
        }
        cout << x << '\n';
    }
    return 0;
}

Measured memory_bytes: 1320
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<queue>
#include<stack>
#include<cassert>
#include<numeric>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
using namespace std;
const int INF = 1001001001;
const long long LINF = 1001002003004005006ll;
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; }
typedef long long ll;
typedef pair<int,int> P;

int main(){
  string s,t;
  cin >> s >> t;
  vector<int> p[26];
  rep(i,s.size()){
    p[s[i]-'a'].push_back(i);
  }
  ll ind = 0;
  ll ss = s.size();
  rep(i,t.size()){
    vector<int> c = p[t[i]-'a'];
    if(c.empty()){
      cout << -1 << endl;
      return 0;
    }
    auto it = lower_bound(c.begin(),c.end(),ind%ss);
    if(it==c.end()){
      ind = (ind + ss - 1LL)/ss * ss + c[0] + 1;
    }
    else ind = ind/ss*ss + *it + 1;
    //cout << ind << endl;
  }
  cout << ind << endl;
}

Measured memory_bytes: 3984
import java.util.*;
class Main
{
  public static void main(String [] args)
  {
  Scanner sc=new Scanner(System.in);
  int A=sc.nextInt();
  int B=sc.nextInt();
  int C=sc.nextInt();
  int D=sc.nextInt();
  boolean flag=true;
  while(flag)
  {
        if(A>0)
        C=C-B;
        if(D>0)
        A=A-D;
    
   if(C<=0)
   {
       System.out.println("Yes");
       flag=false;
   }
    else if(A<=0)
    {
        System.out.println("No");
        flag=false;
    }
  }
    
}
}


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

typedef long long ll;

int n,m,a[100005];
ll sum[200005],coe[200005],con[200005],ans=1145141919810192608;

int main(){

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

    cin>>n>>m;
    for(int i=1;i<=n;i++){
        cin>>a[i];
    }
    for(int i=1;i<n;i++){
        int l=a[i],r=a[i+1];
        if(l<r){
            sum[1]+=r-l;
            sum[l+1]-=r-l;

            coe[l+1]++;
            con[l+1]+=r+1;
            coe[r+1]--;
            con[r+1]-=r+1;

            sum[r+1]+=r-l;
            sum[m+1]-=r-l;
        }else{
            coe[1]++;
            con[1]+=r+1;
            coe[r+1]--;
            con[r+1]-=r+1;

            sum[r+1]+=m+r-l;
            sum[l+1]-=m+r-l;

            coe[l+1]++;
            con[l+1]+=m+r+1;
            coe[m+1]--;
            con[m+1]-=m+r+1;
        }
    }
    for(int i=1;i<=m;i++){
        sum[i]+=sum[i-1];
        coe[i]+=coe[i-1];
        con[i]+=con[i-1];
        ans=min(ans,sum[i]+con[i]-coe[i]*i);
    }
    cout<<ans<<endl;

    return 0;
}

Measured memory_bytes: 6336
import java.util.*;

public class Main {
    static long lcm(long a,long b){
        long x=Math.max(a,b),y=Math.min(a,b);
        while(x%y!=0){
            long t=x%y;
            x=y;y=t;
        }
        return y;
    }
    public static void main(String[] args) {
        Scanner s =new Scanner(System.in);
        while(s.hasNext()){
            long a=s.nextLong(),b=s.nextLong(),lcm=lcm(a,b);
            System.out.printf("%d %d\n",lcm,a*b/lcm);}

    }

}


Measured memory_bytes: 26464
#include<iostream>
#include<cmath>
#include<limits.h>
#define ll long long
using namespace std;
ll int min(ll int arr[],ll int p)
{
	ll int smallest=arr[0];
	for(ll int i=0;i<p;i++)
	{
		if(smallest>arr[i])
		  smallest=arr[i];
	}
	return smallest;
}
ll int function(ll int arr[],ll int initial,ll int final,ll int memo[],ll int k)
{
	if(initial>final)
	{
		return 1000000000000;
	}
	if(memo[initial]!=-1)
	  return memo[initial];
	if(initial==final)
	  return 0;
	else
	{
		ll int array[100]={0};
	    ll int i;
	    ll int p=0;
		for(i=0;i<k;i++)
		{
			if(initial+i+1<=final)
			{
				array[p]=abs(arr[initial+i+1]-arr[initial])+function(arr,initial+i+1,final,memo,k);
				p++;
			}
			else
			  break;
		}
		memo[initial]=min(array,p);
		return memo[initial];
	}
}
int main()
{
	ll int n,k;
	cin>>n>>k;
	ll int arr[n];
	ll int j;
	ll int answer;
	for(j=0;j<n;j++)
	  cin>>arr[j];
	ll int memo[n];
	for(j=0;j<n;j++)
	  memo[j]=-1;
	answer=function(arr,0,n-1,memo,k);
	cout<<answer<<endl;
}

Measured memory_bytes: 90880
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repr(i, n) for (int i = (n); i >= 0; --i)
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define FORR(i, m, n) for (int i = (m); i >= (n); --i)
#define equals(a, b) (fabs((a) - (b)) < EPS)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
const ll mod = 1000000007;
//const ll mod = 998244353;
const int inf = 1e9 + 10;
const ll INF = 1e18;
const ld EPS = 1e-10;
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
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 (a>b) { a=b; return 1; } return 0; }



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

  ll n, m;
  cin >> n >> m;
  vector<ll> a(m);
  rep(i, m) cin >> a[i];

  ll ans = n;
  rep(i, m) ans -= a[i];
  cout << (ans < 0 ? -1 : ans) << '\n';




  
  return 0;
}

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

int main() {
    int N;
    string S;
    cin >> N;
    cin >> S;
    int left_black = 0, right_white = count(S.begin(), S.end(), '.'), min_change = left_black + right_white;
    for (int i = 0; i < N; i++) {
        if (S[i] == '#') left_black++;
        else right_white--;
        min_change = min(min_change, left_black + right_white);
    }
    cout << min_change << endl;
    return 0;
}


Measured memory_bytes: 640
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <queue>
#include <algorithm>
#include <utility>
#include <cmath>
#include <cstdlib>
#include <cstring>

#define INF_LL 9000000000000000000
#define INF 2000000000

#define REP(i, n) for(int i = 0;i < (n);i++)
#define FOR(i, a, b) for(int i = (a);i < (b);i++)

using namespace std;

typedef long long ll;
typedef pair<int, int> PII;
typedef pair<int, PII> PPII;
typedef pair<int, PPII> PPPII;

class Union_find{
private:
	vector<int> par;
	vector<int> rank;
	int n;

public:
	Union_find(int a){
		n = a;
		for(int i = 0;i < n;i++){
			par.push_back(i);
			rank.push_back(0);
		}
	}

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

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

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

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

bool fld[5010][5010];
int main(void){
	int n;
	while(cin >> n && n){
	vector<PII> p;
	int res = 0;
	memset(fld, 0, sizeof(fld));
	REP(i, n){
		int x, y;
		cin >> x >> y;
		p.push_back({x, y});
		fld[x][y] = true;
	}
	REP(i, n){
		REP(j, n){
			if(i == j) continue;
			int x = p[j].first-p[i].first;
			int y = p[j].second-p[i].second;
			int dx[4] = {x, -y, -x, y};
			int dy[4] = {y, x, -y, -x};
			bool flag = true;
			int bx = p[i].first, by = p[i].second;
			REP(k, 4){
				if((bx < 0 || 5000 < bx || by < 0 || 5000 < by) || !fld[bx][by]){
					flag = false;
					break;
				}
				bx += dx[k];
				by += dy[k];
			}
			if(flag) res = max(res, x*x+y*y);
		}
	}
	cout << res << endl;
	}
}

Measured memory_bytes: 27524
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <stack>
#include <queue>
#include <set>
#include <map>
using namespace std;
#define MOD @
#define ADD(X,Y) ((X) = ((X) + (Y)%MOD) % MOD)
typedef long long i64; typedef vector<int> ivec; typedef vector<string> svec;

int N;
i64 A[101010];

int ord(i64 v)
{
	int ret = 0;
	while (v % 2 == 0) {
		v /= 2;
		++ret;
	}
	return ret;
}

int main()
{
	scanf("%d", &N);
	for (int i = 0; i < N; ++i) scanf("%lld", A + i);

	int ret = 0;
	for (int i = 0; i < N; ++i) {
		ret += ord(A[i]);
	}
	printf("%d\n", ret);

	return 0;
}


Measured memory_bytes: 384
#include <cstdio>
#include <cstring>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>

using namespace std;

int main()
{
	int n, ma, mb;
	int a[40], c[40], a1, b1, min0=0;
	map<int, int> min;
	scanf("%d %d %d", &n, &ma, &mb);
	for(int i=0; i<n; i++){
		scanf("%d %d %d", &a1, &b1, &c[i]);
		a[i]=mb*a1-ma*b1;
	}
	min[0]=0;
	for(int i=0; i<n; i++){
		map<int, int> min1;
		for(auto itr=min.begin(); itr!=min.end(); itr++){
			int x=itr->first;
			int y=itr->second;
			min1[x]=y;
		}
		for(auto itr=min1.begin(); itr!=min1.end(); itr++){
			int x=itr->first;
			int y=itr->second;
			if(min1.find(x+a[i])==min1.end()){
				min[x+a[i]]=y+c[i];
			}else{
				if(min1[x+a[i]]>y+c[i]){
					min[x+a[i]]=y+c[i];
				}
			}
			if(x+a[i]==0){
				if(min0==0){
					min0=y+c[i];
				}else if(min0>y+c[i]){
					min0=y+c[i];
				}
			}
		}
		min1.clear();
	}
	if(min0==0){
		printf("%d\n", -1);
	}else{
		printf("%d\n", min0);
	}
	return 0;
}


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

int main()
{
  int n;
  cin >> n;
  string s;
  char t;
  map<string, int> mp;
  rep(i, n){
    cin >> s;
    mp[s]++;
    if(mp[s] == 2){
      cout << "No" << endl;
      return 0;
    }
    if(i > 0){
      if(t != s[0]){
        cout << "No" << endl;
      	return 0;
      }
    }
    t = s[s.size() - 1];
  }
     
  cout << "Yes" << endl;
  return 0;
}

Measured memory_bytes: 3584
#include <iostream>
#include <list>
#include <queue>

using namespace std;

class Room
{
public:
    int v = 0;
    list<int> pass;
    int spot = -1;

    void addPass(int i)
    {
        v++;
        pass.push_back(i);
    }
};

Room t[100000];

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

    int a, b;
    for (int i = 0; i < m; ++i)
    {
        cin >> a >> b;
        t[a-1].addPass(b-1);
        t[b-1].addPass(a-1);
    }

    queue<int> splash;
    splash.push(0);
    t[0].spot = 0;
    int cur;

    while (!splash.empty())
    {
        cur = splash.front();
        splash.pop();

        //cout << "cur = " << cur << "\n";
        for (auto it = t[cur].pass.begin(); it != t[cur].pass.end(); ++it)
        {
            if (t[*it].spot != -1)
            {
                continue;
            }
            //cout << "t[" << *it << "] = " << cur << "\n";
            t[*it].spot = cur;
            splash.push(*it);
        }
    }

    for (int i = 1; i < n; ++i)
    {
        if (t[i].spot == -1)
        {
            cout << "No\n";
            return 0;
        }
    }

    cout << "Yes\n";
    for (int i = 1; i < n; ++i)
    {
        cout << t[i].spot+1 << "\n";
    }

    return 0;
}


Measured memory_bytes: 20136
#include<stdio.h>
int main()
{
  int a[10000],b,c,d,n,i,j,k;
  double e=0.0;
  scanf("%d%d%d%d",&n,&b,&c,&d);
  for(i=0;i<n;i++){
    scanf("%d",&a[i]);
  }
  for(i=0;i<n;i++){
    for(j=n-1;j>i;j--){
      if(a[j-1]>a[j]){
	k=a[j];
	a[j]=a[j-1];
	a[j-1]=k;
      }
    }
  }
  for(i=n-1;i>=0;i--){
    d+=a[i];
    b+=c;
    if(e>d/b)break;
    e=d/b;
  }
  printf("%d\n",(int)e);
  return 0;
}

Measured memory_bytes: 604
// AtCoder Grand Contest 018
// D - Tree and Hamilton Path

#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;


const int MAX_N = 100000;
const int INF = (int)1e8;

struct edge {
    int to;
    ll cost;
};

int N;
vector<edge> G[MAX_N];
int size[MAX_N];

void calc_subtree_size(int v, int p = -1) {
    size[v] = 1;
    for (edge &e : G[v]) {
        if (e.to == p) {
            continue;
        }
        calc_subtree_size(e.to, v);
        size[v] += size[e.to];
    }
    return;
}

pii search_centroid(int v, int p = -1) {
    pii res(INF, -1);
    int s = 1, m = 0;
    for (edge &e : G[v]) {
        if (e.to == p) {
            continue;
        }
        res = min(res, search_centroid(e.to, v));
        m = max(m, size[e.to]);
        s += size[e.to];
    }
    m = max(m, N - s);
    res = min(res, pii(m, v));
    return res;
}

ll calc_ans(int v, int p = -1) {
    ll res = 0;
    for (edge &e : G[v]) {
        if (e.to == p) {
            continue;
        }
        res += calc_ans(e.to, v);
        res += e.cost * size[e.to] * 2;
    }
    return res;
}

int main() {

    int a, b;
    ll c, d;
    int cent;
    ll ans;

    cin >> N;
    for (int i = 0; i < N - 1; i++) {
        cin >> a >> b >> c;
        a--; b--;
        G[a].push_back((edge){ b, c });
        G[b].push_back((edge){ a, c });
    }

    calc_subtree_size(0);
    cent = search_centroid(0).second;
    calc_subtree_size(cent);
    ans = calc_ans(cent);

    d = INF;
    for (edge &e : G[cent]) {
        if (N % 2 == 0 && size[e.to] == N / 2) {
            d = e.cost;
            break;
        }
        d = min(d, e.cost);
    }
    ans -= d;

    cout << ans << endl;

    return 0;

}





Measured memory_bytes: 17536