akhauriyash/Code-Regression huggingface dataset:
#![allow(unused_imports)]
use itertools::Itertools;
use num_traits::clamp;
use ordered_float::OrderedFloat;
use proconio::{fastout, input, marker::*};
use std::cmp::*;
use std::collections::*;
use superslice::*;

#[fastout()]
fn main() {
    input! {
        n: usize, k: usize,
        mut a: [i64; n],
    }
    let m = 1000000007i64;

    if k ==n || (k % 2 == 1 && a.iter().all(|v| *v <= 0)) {
        a.sort();
        a.reverse();
        let ans = a.iter().take(k).fold(1, |a, v| (a * v).rem_euclid(m));
        println!("{}", ans);
        return;
    }

    a.sort_by_key(|v| Reverse((v.abs(), *v)));
    let sign = a.iter().cloned().map(i64::signum).collect_vec();
    let cum_sign = sign
        .iter()
        .scan(1, |a, &v| {
            *a *= v;
            Some(*a)
        })
        .collect_vec();

    let mut remove_plus = n;
    let mut add_minus = n;
    let mut remove_minus = n;
    let mut add_plus = n;
    a.push(0);
    for i in (0..k).rev() {
        if a[i] > 0 {
            remove_plus = i;
            break;
        }
    }
    for i in (0..k).rev() {
        if a[i] < 0 {
            remove_minus = i;
            break;
        }
    }
    for i in k..n {
        if a[i] > 0 {
            add_plus = i;
            break;
        }
    }
    for i in k..n {
        if a[i] < 0 {
            add_minus = i;
            break;
        }
    }

    let (mut remove, mut add) = if add_minus == n || remove_plus == n {
        (remove_minus, add_plus)
    } else if add_plus == n || remove_minus == n {
        (remove_plus, add_minus)
    } else if a[add_minus] * a[remove_minus] > a[add_plus] * a[remove_plus] {
        (remove_plus, add_minus)
    } else {
        (remove_minus, add_plus)
    };
    if cum_sign[k - 1] != -1 {
        remove = n;
        add = n;
    }

    let mut ans = 1i64;
    for i in 0..k {
        if i == remove {
            continue;
        }
        ans *= a[i].abs();
        ans %= m;
    }
    for i in k..n {
        if i == add {
            ans *= a[i].abs();
            ans %= m;
            break;
        }
    }
    println!("{}", ans);
}


Measured memory_bytes: 9624
#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;
 
#define ff                  first
#define ss                  second
#define endl                "\n"
#define loop(i,s,e)         for(int i=s;i<e;i++)
#define int                 long long
#define vi                  vector<int> 
#define S(v)                sort(v.begin(),v.end())
#define RS(v)               sort(v.rbegin(),v.rend())
#define R(v)                reverse(v.begin(),v.end())
#define mxpq(T)             priority_queue <T>
#define mnpq(T)             priority_queue<T,vector<T>,greater<T>>
#define prv(v)              for(auto &x : v)cout << x << " ";
#define piirv(v)            for(auto &x : v)cout << x.ff << " " << x.ss << endl;
#define prvv(v)             for(auto &x : v)for(auto &y : x.ss)cout << y << " ";
#define mp                  make_pair
#define pii                 pair<int,int>
#define mset(a,f)           memset(a , f , sizeof(a))
#define pb                  push_back
#define inf                 INT_MAX
#define INF                 LLONG_MAX
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> oset;

const int N = 2e6 + 6;
int A[N];
int dp[3003][3003];
pii nxt[3003][3003];
int n;
string s1,s2;

int alpha(int i , int j)
{
      if(i >= s1.length() || j >= s2.length())return 0;
      int &abs = dp[i][j];
      if(abs != -1)return abs;
      int a1 = -inf , a2 = -inf , a3 = -inf;

      if(s1[i] == s2[j])a1 = 1 + alpha(i+1,j+1);
      a2 = alpha(i+1 ,j);
      a3 = alpha(i,j+1);

      if(max({a1,a2,a3}) == a1)nxt[i][j] = {i+1,j+1};
      else if(max({a1,a2,a3}) == a2)nxt[i][j] = {i+1,j};
      else if(max({a1,a2,a3}) == a3)nxt[i][j] = {i,j+1};
      return abs = max({a1,a2,a3});
}

void solve()
{
      cin >> s1 >> s2;

      mset(dp,-1);

      alpha(0,0);

      int st = 0 , en = 0;

      string ans = "";

      while(st < s1.length() && en < s2.length())
      {
            pii p1 = nxt[st][en];
            if(st+1 == p1.ff && en+1 == p1.ss)
            {
                  ans += s1[st];
            }
            st = p1.ff;
            en = p1.ss;
      }

      cout << ans;
}
 
int32_t main()
{
 
cout<<fixed<<setprecision(16);

ios_base:: sync_with_stdio(false);
cin.tie(NULL); cout.tie(NULL);
       

       int t = 1;
       // cin >> t;
       while(t--)solve();
  
}

Measured memory_bytes: 213632
{-# LANGUAGE BangPatterns #-}

import qualified Data.Vector.Unboxed as VU
import qualified Data.Vector.Unboxed.Mutable as VUM
import qualified Data.ByteString.Char8 as BS
import Data.Bits
import Control.Monad
import Control.Monad.ST

swap :: (VUM.Unbox a) => (a -> Bool) -> VUM.MVector s a -> ST s Int
swap f vec = loopl 0 (VUM.length vec - 1)
  where
    loopl x y | x > y = return x
    loopl x y = do
      vx <- VUM.unsafeRead vec x
      if (f vx) then
        loopl (x+1) y
      else
        loopr x y vx
    loopr x y vx | x > y = return x
    loopr x y vx = do
      vy <- VUM.unsafeRead vec y
      if not (f vy) then
        loopr x (y-1) vx
      else do
        VUM.unsafeWrite vec x vy
        VUM.unsafeWrite vec y vx
        loopl (x+1) (y-1)

sums :: Int -> VU.Vector Int -> ST s (VUM.MVector s Int)
sums n as = do
  vec <- VUM.unsafeNew $ (n * (n + 1)) `div` 2
  let loop !i !x !y !prevSum
        | y >= n = if x >= n then return () else loop i (x+1) (x+1) 0
      loop i x y prevSum =
        VUM.unsafeWrite vec i newSum >> loop (i+1) x (y+1) newSum
        where
          ay = as VU.! y
          newSum = prevSum + ay
  loop 0 0 0 0
  return vec
  

query :: Int -> Int -> VU.Vector Int -> Int
query n k as = runST $ do
  svec <- sums n as
  loop svec 39 0
  where
    loop _ (-1) acc = return acc
    loop svec !lev !acc = do
      t <- swap (`testBit` lev) svec
      if k <= t then
        loop (VUM.take t svec) (lev - 1) (acc `setBit` lev)
      else
        loop svec (lev - 1) acc

main = do
  [n,k] <- map read . words <$> getLine
  as <- VU.unfoldrN n (BS.readInt . BS.dropWhile (==' ')) <$> BS.getLine
  putStrLn $ show $ query n k as


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

typedef long long int lli;
typedef long int li;

lli solve(lli x){
    return (sqrt(1 + 8.0 * x) - 1) / 2;
}

int main(){
    ios::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	
    lli n;
    cin >> n;
    vector<int> v;
    
    lli ans = 0;
    int p = 0;
    while (n % 2 == 0)  
    {  
        p++;
        n = n / 2;  
    }

    if(p != 0) v.push_back(p);
    for(int i = 3; i <= sqrt(n); i += 2){
        p = 0;
        while(n > 0 && n % i == 0){
            p++;
            n /= i;
        }
        if(p != 0) v.push_back(p);
    }
    
    if(n > 2) ans++;
    //cout << n << endl;
    for(lli x : v){
        //cout << x << endl;
        ans += solve(x);
    }
    cout << ans << '\n';
}	

/*
	check for corner cases.
	When using log check for zeros.
	Use queues and stacks if they are helping.           
                            
    (___)           
    . . )____________ 
   _|__/\           |\
  (o_o_) \__________| \
           /|     ||   )     
          < |     ||  
*/



Measured memory_bytes: 3628
//raja1999
#include <bits/stdc++.h>
#include <vector>
#include <set>
#include <map>
#include <string>
#include <cstdio>
#include <cstdlib>
#include <climits>
#include <utility>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <iomanip> 
//setbase - cout << setbase (16)a; cout << 100 << endl; Prints 64
//setfill -   cout << setfill ('x') << setw (5); cout << 77 <<endl;prints xxx77
//setprecision - cout << setprecision (14) << f << endl; Prints x.xxxx
//cout.precision(x)  cout<<fixed<<val;  // prints x digits after decimal in val

using namespace std;
#define f(i,a,b) for(i=a;i<b;i++)
#define rep(i,n) f(i,0,n)
#define fd(i,a,b) for(i=a;i>=b;i--)
#define pb push_back
#define mp make_pair
#define vi vector< int >
#define vl vector< ll >
#define ss second
#define ff first
#define ll long long
#define pii pair< int,int >
#define pll pair< ll,ll >
#define sz(a) a.size()
#define inf (1000*1000*1000+5)
#define all(a) a.begin(),a.end()
#define tri pair<int,pii>
#define vii vector<pii>
#define vll vector<pll>
#define viii vector<tri>
#define mod (1000*1000*1000+7)
#define pqueue priority_queue< int >
#define pdqueue priority_queue< int,vi ,greater< int > >

//std::ios::sync_with_stdio(false);
int a[100005];
int main(){
	std::ios::sync_with_stdio(false);
	int n,i,c=0;
	cin>>n;
	rep(i,n){
		cin>>a[i];
		while(a[i]>0){
			if(a[i]%2){
				break;
			}
			else{
				a[i]/=2;
				c++;
			}
		}
	}
	cout<<c<<endl;
} 
	

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using pli = pair<ll, int>;
using pil = pair<int, ll>;
using pdd = pair<double, double>;
using uint = unsigned int;
template <typename T>
using Graph = vector<vector<T>>;
const int MOD = 1e9 + 7;
const ld PI = acosl(-1);

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

    int N;
    cin >> N;
    static ll A[3];
    for (int i = 0; i < N; ++i) {
        ll b;
        cin >> b;
        A[min(i, 2)] ^= b;
    }

    ll va = A[0] + A[1] - A[2];
    ll vo = A[0] + A[1] + A[2];
    if ((va & 1) || ((va & vo) != va)) {
        cout << -1 << endl;
        return 0;
    }

    va >>= 1;
    vo >>= 1;

    vector<vector<ll>> dp(42, vector<ll>(2, -1));
    dp[41][1] = 0;
    for (int i = 40; i >= 0; --i) {
        ll tmp = 1LL << i;
        // 1固定
        if (va & tmp) {
            dp[i][0] = dp[i + 1][0] | tmp;
            if (A[0] & tmp)
                dp[i][1] = dp[i + 1][1] | tmp;
            continue;
        }

        // 0固定
        if (!(vo & tmp)) {
            dp[i][0] = dp[i + 1][0];
            if (A[0] & tmp)
                dp[i][0] = max(dp[i][0], dp[i + 1][1]);
            else
                dp[i][1] = dp[i + 1][1];
            continue;
        }

        dp[i][0] = dp[i + 1][0] | tmp;
        if (A[0] & tmp) {
            dp[i][1] = dp[i + 1][1] | tmp;
            dp[i][0] = max(dp[i][0], dp[i + 1][1]);
        } else {
            dp[i][1] = dp[i + 1][1];
        }
    }

    ll res = max(dp[0][0], dp[0][1]);
    if (res <= 0)
        cout << -1 << endl;
    else
        cout << A[0] - res << endl;
    return 0;
}


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

using namespace std;

int main(){
  string str;
  getline(cin,str);

  for(int i = 0;i < (int)str.size();i++){
    if(islower(str[i])){
      str[i] = toupper(str[i]);
    }
    else if(isupper(str[i])){
      str[i] = tolower(str[i]);
    }
  }
  cout << str << endl;
  return 0;
}



Measured memory_bytes: 3152
import java.util.*;
import java.io.*;

public class Main {
	static PrintWriter out=new PrintWriter(System.out);
	
	public static void main(String[] args) {
		Scanner in=new Scanner(System.in);
		int n=Integer.parseInt(in.next());
		List<Integer> A=new ArrayList<>(),B=new ArrayList<>();
		for(int i=1;i<=n;i++)A.add(i);
		parm(A,B,-1,-1);
		out.flush();
	}
	
	static void parm(List<Integer> A,List<Integer> B,int u,int v) {
		List<Integer> ls=new ArrayList<>(A),res=new ArrayList<>(B);
		if(u!=-1)ls.remove(u);
		if(v!=-1)res.add(v);
		if(ls.size()==1) {
			res.add(ls.get(0));
			for(int i=0;i<res.size()-1;i++)out.print(res.get(i)+" ");
			out.println(res.get(res.size()-1));
			return;
		}
		for(int i=0;i<ls.size();i++) {
			parm(ls,res,i,ls.get(i));
		}
	}

}



Measured memory_bytes: 171756
#include<iostream>

using namespace std;

int main()
{
	int N;
	cin >> N;
	int a[100];
	for (int i = 0; i < N; ++i)
	{
		cin >> a[i];
	}

	int ans = -1;
	for (int i = -100; i <= 100; ++i)
	{
		int cost = 0;
		for (int j = 0; j < N; ++j)
		{
			int t = (i - a[j]);
			cost += t * t;
		}

		if (cost < ans || ans == -1)
		{
			ans = cost;
		}
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
fun main(args: Array<String>) {
    val n = readInputLine().toInt()
    val p = readInputLine().split(" ").map{it.toInt()}
    
    var cnt = 0
    
    for (i in 1..n) {
        if (p[i - 1] != i) {
            cnt++
        }
    }
    
    if (cnt == 0 || cnt == 2) {
        println("YES")
    } else {
        println("NO")
    }
}

fun readInputLine(): String {
    return readLine()!!
}


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

#define ll long long
#define vvi vector<vector<int>>
#define vec vector
#define pq priority_queue
#define all(v) (v).begin(), (v).end()
#define rep(i, n, m) for (int (i) = (n); (i) < (m); ++(i))
#define debug(x) cerr << #x << ": " << x << endl;
#define debug2(x, y) cerr<<"("<<#x<<", "<<#y<<") = "<<"("<<x<<", "<<y<<")"<<endl;
#define debugB(x, y) cerr<<#x<<": "<<bitset<y>(x) << endl;
#define line() cerr << "---------------" << endl;

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

int n;
vec<int> v;

bool bin(int x) {
   int left = 0, right = n;
   while (left < right) {
      int mid = (left+right)/2;
      if (v[mid] > x) {
         right = mid;
      } else if (v[mid] < x) {
         left = mid + 1;
      } else {
         return true;
      }
   }
   return false;
}

int main() {
   cin >> n;
   rep (i, 0, n) {
      int x;
      cin >> x;
      v.push_back(x);
   }
   sort(all(v));

   int q;
   cin >> q;
   int cnt = 0;
   rep (i, 0, q) {
      int x;
      cin >> x;
      if (bin(x)) {
         cnt++;
      }
   }
   cout << cnt << endl;

   return 0;
}


Measured memory_bytes: 3316
#!usr/bin/env python3
from collections import defaultdict
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS():return list(map(list, sys.stdin.readline().split()))
def S(): return list(sys.stdin.readline())[:-1]
def IR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = I()
    return l
def LIR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = LI()
    return l
def SR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = S()
    return l
def LSR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = SR()
    return l
mod = 1000000007

#A

#B

#C
f = [0]
for i in range(1,400):
    f.append(0)
for i in range(400,800):
    f.append(1)
for i in range(800,1200):
    f.append(2)
for i in range(1200,1600):
    f.append(3)
for i in range(1600,2000):
    f.append(4)
for i in range(2000,2400):
    f.append(5)
for i in range(2400,2800):
    f.append(6)
for i in range(2800,3200):
    f.append(7)
for i in range(3200,4801):
    f.append(-1)
n = I()
a = LI()
k = [1 for i in range(8)]
s = 0
t = 0
for i in a:
    if f[i] >= 0:
        if k[f[i]]:
            k[f[i]] = 0
            s += 1
    else:
        t += 1
print(max(s,1),min(s+t,n))
#D

#E

#F

#G

#H

#I

#J

#K

#L

#M

#N

#O

#P

#Q

#R

#S

#T


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


int N;


int main() {
    cin >> N;

    int n1 = N/10;
    int n2 = N%10;
    if(n1 == 9 || n2 == 9)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
    
    return 0;
}


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

using namespace std;

int main()
{
    ios::sync_with_stdio(false);
    int N, K, g;
    cin >> K >> N;
    int a[K], D[N+1];
    for (int i = 0; i < K; i++)
    {
        cin >> a[i];
    }
    D[0] = 0;
    for (int i = 1; i <= N; i++)
    {
        g = 0;
        for (int y = 0; y < K; y++)
        {
            if (i-a[y] >= 0 && D[i-a[y]] == 0)
            {
                g = 1;
            }
        }
        if (g == 1)
        {
            D[i] = 1;
        }
        else
        {
            D[i] = 0;
        }
    }
    if (D[N] == 0)
    {
        cout << "Second";
    }
    else
    {
        cout << "First";
    }
    return 0;
}


Measured memory_bytes: 640
//インクルード(アルファベット順)
#include<algorithm>//sort,二分探索,など
#include<bitset>//固定長bit集合
#include<cmath>//pow,logなど
#include<complex>//複素数
#include<deque>//両端アクセスのキュー
#include<functional>//sortのgreater
#include<iomanip>//setprecision(浮動小数点の出力の誤差)
#include<iostream>//入出力
#include<iterator>//集合演算(積集合,和集合,差集合など)
#include<map>//map(辞書)
#include<numeric>//iota(整数列の生成),gcdとlcm(c++17)
#include<queue>//キュー
#include<set>//集合
#include<stack>//スタック
#include<string>//文字列
//#include<unordered_map>//イテレータあるけど順序保持しないmap
//#include<unordered_set>//イテレータあるけど順序保持しないset
#include<utility>//pair
#include<vector>//可変長配列
#include<valarray>//なんとなく追加
//メモ：表示桁数を大きくする　　cout << fixed << setprecision(20) << cm << endl;
using namespace std;
typedef long long ll;

//マクロ
//forループ関係
//引数は、(ループ内変数,動く範囲)か(ループ内変数,始めの数,終わりの数)、のどちらか
//Dがついてないものはループ変数は1ずつインクリメントされ、Dがついてるものはループ変数は1ずつデクリメントされる
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
//xにはvectorなどのコンテナ
#define ALL(x) (x).begin(),(x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x)) //最大値を求める
#define MIN(x) *min_element(ALL(x)) //最小値を求める
//定数
#define INF 1000000000000 //10^12:極めて大きい値,∞
#define MOD 1000000007 //10^9+7:合同式の法
#define MAXR 100000 //10^5:配列の最大のrange(素数列挙などで使用)
//略記
#define PB push_back //vectorヘの挿入
#define MP make_pair //pairのコンストラクタ
#define F first //pairの一つ目の要素
#define S second //pairの二つ目の要素
#define PI acos(-1.0)
#define answer(ans) cout<<ans<<endl;
#define input(N) cin >> N ;

signed main() {
int L,N;
cin >>N>>L;
vector<string> S(N);
REP(i,N){
    cin >> S.at(i);
}

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

REP(i,N){
cout << S.at(i);
}
cout << endl;
return 0;
}


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

const int N = 1e5+1;
typedef long long ll;
#define FOR(i, a, b) for (ll i = a; i <= b; i++)
#define FORD(i, a, b) for (ll i = a; i >= b; i--)

int main()
{
	ll n;
	string s;
	cin >> n >> s;
	ll r = 0, g = 0, b = 0;
	for (int i = 0; i < s.size(); i++){
		if (s[i] == 'R')
			r++;
		else if (s[i] == 'G')
			g++;
		else if (s[i] == 'B')
			b++;
	}
	
	if (r * g * b == 0){
		cout << "0" << "\n";
		return 0;
	}
	ll d = 0;
	for (int i = 0; i < n-1; i++){
		for (int j = i + 1 ; j < n; j++){
			ll k = 2*j-i;
			if (k < n && s[i] != s[j] && s[j] != s[k] && s[i] != s[k])
				d++;
		}
	}
	cout << r * g * b - d;
	return 0;
}

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

int main() {
  ll n, a,b,c,d;
  cin>>n>>a>>b>>c>>d;
  rep(m,n) {
    if(-d*m+c*(n-1-m)<=a-b&&a-b<=-c*m+d*(n-1-m)) {
      cout<<"YES"<<endl;
      return 0;
    }
  }
  cout<<"NO"<<endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>

#define INF 1000000021
#define MOD 1000000007
#define pb push_back
#define sqr(a) (a)*(a)
#define M(a, b) make_pair(a,b)
#define T(a, b, c) make_pair(a, make_pair(b, c))
#define F first
#define S second
#define all(x) (x.begin(), x.end())
#define deb(x) cerr << #x << " = " << x << '\n'
#define N 222222

using namespace std;
//using namespace __gnu_pbds;

typedef long double ld;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
//typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;

const ld pi = 2 * acos(0.0);
template<class T> bool umin(T& a, T b){if(a>b){a=b;return 1;}return 0;}
template<class T> bool umax(T& a, T b){if(a<b){a=b;return 1;}return 0;}
template<class T, class TT> bool pal(T a, TT n){int k=0;for(int i=0;i<=n/2;i++){if(a[i]!=a[n-i-1]){k=1;break;}}return k?0:1;}

//int month[] = {0,31,28,31,30,31,30,31,31,30,31,30,31};
map<ll, ll> dead;
int main()
{
	ll a, b;
	cin >> a >> b;
	vll foo, hoo;
	for(ll i = 1; i * i <= a; i ++)
	{
		if(a % i != 0)
			continue;
		ll j = a / i;
		foo.pb(i);
		if(i != j)
			foo.pb(j);
	}
	for(ll i = 1; i * i <= b; i ++)
	{
		if(b % i != 0)
			continue;
		ll j = b / i;
		hoo.pb(i);
		if(i != j)
			hoo.pb(j);
	}
	vll v;
	for(auto it : foo)
	{
		int flag = 0;
		for(auto id : hoo)
		{
			if(it == id)
			{
				flag = 1;
				break;
			}
			
		}
		if(flag)
			v.pb(it);
	}
	int k = v.size(), ans = 0;
	sort all(v);
	vll res;
	for(auto it : v)
	{
		if(dead[it])
			continue;
		for(auto id : v){
			if(dead[id] || id == it)
				continue;
			if(__gcd(id, it) != 1)
				dead[id] = 1;
		}
	}
	for(auto it : v)
		ans += (dead[it] == 0);
	cout << ans;
	





	getchar();
	getchar();
	return 0;
	//ios::sync_with_stdio(false);
	//cin.tie(0);
}

Measured memory_bytes: 768
#include <bits/stdc++.h>
 
#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)
 
#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=(int)(a)-1;i>=(int)(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)
 
#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define bit(n) (1LL<<(n))
 
// #define DEBUG
 
#ifdef DEBUG
    #define dump(...) fprintf(stderr, __VA_ARGS__)
#else
    #define dump(...)
#endif
 
template<class T>bool chmax(T &a, const T &b) { return (a<b)?(a=b,1):0;}
template<class T>bool chmin(T &a, const T &b) { return (b<a)?(a=b,1):0;}
 
using namespace std;
using ll=long long;
using vi=vector<int>;
using vll=vector<ll>;
 
const double EPS = 1e-10;
const double PI = acos(-1.0);
const ll INF = 1LL << 62;
const int inf = 1 << 30;
const ll MOD = 1000000007LL;
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
 
ll extgcd(ll a,ll b,ll& x,ll& y){x=1,y=0;ll g=a;if(b!=0) g=extgcd(b,a%b,y,x),y-=a/b*x;return g;}
ll ADD(const ll &a, const ll &b, const ll mod=MOD) { return (a+b)%mod;}
ll SUB(const ll &a, const ll &b, const ll mod=MOD) { return (a-b+mod)%mod;}
ll MUL(const ll &a, const ll &b, const ll mod=MOD) { return (1LL*a*b)%mod;}
ll DIV(const ll &a, const ll &b, const ll mod=MOD) {ll x,y; extgcd(b,mod,x,y);return MUL(a,(x+mod)%mod,mod);}
 
int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);

    int n; cin >> n;
    vi a(n); for(auto& e : a) cin >> e;

    sort(_all(a));
    ll res = 1LL;
    rep(i, n / 2){
        res = MUL(res, 2LL);
    }

    rep(i, n / 2){
        if(a[2*i + n%2] != a[2*i+1 + n%2]){
            res = 0LL;
            break;
        }
    }
    if(n % 2 and a[0] != 0){
        res = 0LL;
    }

    cout << res << endl;

    return 0;
}


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

typedef long long ll;

struct Card{
    int num,id;
    string str;
};

ll partition(Card c[],ll p,ll r){
    ll x=c[r].num;
    ll i=p-1;
    for(ll j=p;j<r;j++){
        if(c[j].num<=x){
            i++;
            swap(c[i],c[j]);
        }
    }
    swap(c[i+1],c[r]);
    return i+1;
}

void qsort(Card c[],ll p,ll r){
    if(p<r){
        ll q = partition(c,p,r);
        qsort(c,p,q-1);
        qsort(c,q+1,r);
    }
}

//ll bs(ll num,const vector<pair<string,ll> > &v, ll n){
//    ll l=-1,r=n-1;
//    for(;r-l>1;){
//        ll mid=(l+r)/2;
//        if(v[mid].second < num){
//            l = mid;
//        }else{
//            r = mid;
//        }
//    }
//    return l+1;
//}

void check(Card c[],int n){

    for(int i=0;i<n-1;i++){
        if(c[i].num<c[i+1].num)continue;
        if(c[i].id<c[i+1].id)continue;
        cout << "Not stable\n";
        return;
    }
    cout << "Stable\n";

}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll n;
    cin >> n;
    Card card[100000];
    for(ll i=0;i<n;i++){
        cin >> card[i].str >> card[i].num;
        card[i].id=i;
    }
//    auto res=unique(tab.begin(),tab.end());
//    tab.erase(res,tab.end());
//    vector<pair<string, ll> > sub(card);
    qsort(card,0,n-1);

    check(card,n);
    for(int i=0;i<n;i++){
        cout << card[i].str << " " << card[i].num << endl;
    }
}



Measured memory_bytes: 9384
#include<stdio.h>

int main(){

  int a,b,c,tmp;
  scanf("%d %d %d",&a,&b,&c);

  tmp=a;
  a=b;
  b=tmp;

  tmp=a;
  a=c;
  c=tmp;

  printf("%d %d %d",a,b,c);
  return 0 ;
}


Measured memory_bytes: 128
#!/usr/bin/env python3
sx, sy, tx, ty = map(int, input().split())
x = tx - sx
y = ty - sy
h = abs(sx - tx)
v = abs(sy - ty)
ans = [[1, 0]] * h + [[0, 1]] * v + [[-1, 0]] * h + [[0, -1]] * v
ans += [[0, -1]] + [[1, 0]] * -~h + [[0, 1]] * -~v + [[-1, 0]]
ans += [[0, 1]] + [[-1, 0]] * -~h + [[0, -1]] * -~v + [[1, 0]]
if x < 0 and y < 0:
    ans = [*map(lambda x: [-x[0], -x[1]], ans)]
elif x < 0:
    ans = [*map(lambda x: [-x[1], x[0]], ans)]
elif y < 0:
    ans = [*map(lambda x: [x[1], -x[0]], ans)]

for i in ans:
    if i == [1, 0]:
        print("R", end="")
    elif i == [-1, 0]:
        print("L", end="")
    elif i == [0, 1]:
        print("U", end="")
    else:
        print("D", end="")
print("")


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

int main() {
  string s;
  cin >> s;

  while (1) {
    // 末尾から2文字ずつ消していき、偶文字列になるか確認する
    s.erase(s.end() - 1);
    s.erase(s.end() - 1);
    if (s.substr(0, s.size() / 2) == s.substr(s.size() / 2)) {
      cout << s.size() << endl;
      break;
    }
  }

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair< ll, ll > Pi;
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep2(i,n) for(int i=1;i<=(n);i++)
#define rep3(i,i0,n) for(int i=i0;i<(n);i++)
#define pb push_back
#define mod 1000000007
const ll INF = 1LL << 60;
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 a, ll b) {return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) {return a/gcd(a,b)*b;}
#define all(x) x.begin(), x.end()
#define mp make_pair
bool compare(Pi a, Pi b) {
    if(a.first != b.first){
        return a.first < b.first;
        
    }else{
        return a.second < b.second;
    }
}


bool In_map(ll y,ll x,ll h,ll w){
    if(y<0 || x<0 || y>=h || x>=w){
        return 0;
    }else{
        return 1;
    }
}
const vector<ll> dx{1,0,-1,0};
const vector<ll> dy{0,1,0,-1};


int main() {
    ll N;
    cin >>N;
    vector<ll> A(N);

    rep(i,N){
        cin>>A[i];
    }

    sort(all(A));
    reverse(all(A));
    ll ans = A[0];
    ll i= 1;
    ll cnt =1;
    while(1){
        if(cnt==N-1) break;
        ans+= A[i];
        cnt++;
        if(cnt==N-1) break;
        ans+= A[i];
        cnt++;
        if(cnt==N-1) break;
        i++;
    }
    cout << ans << endl;


    return 0;
    

}

Measured memory_bytes: 4852
m, d = list(map(int, input().split()))
count = 0
for i in range(1, m + 1):
    for j in range(1, d + 1):
        d1, d2 = j // 10, j % 10
        if (d1 >= 2) and (d2 >= 2) and i == d1 * d2:
            count += 1
print(count)

Measured memory_bytes: 3060
#include<iostream>
#include<vector>
using namespace std;
int main() {
	int N;
	cin >> N;
	vector<int> p(N),q(N);
	int i,j;
	for(i=0;i<N;i++)cin >> p[i];
	int temp,ans = 2000000000;
	for(j=0;j<4;j++) {
		for(i=0;i<N;i++)q[i] = p[i];
		temp = j;
		q[0] -= j;
		for(i=0;i<N-1;i++) {
			if(q[i] > 0) {
				q[i+1] -= q[i];
				temp += 2*q[i];
			}
		}
		temp += max(q[N-1],0);
		ans = min(ans,temp);
	}
	cout << ans << endl;
}


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

using namespace std;

string Sample;

//const regex REA("^>'(=+)#\1~$"),   REB("^>\\^(Q=)+~~$");
const regex REA("^>'(=+)#(=+)~$"), REB("^>\\^(Q=)+~~$");

int main() {
	int n;
	smatch smStr;

	cin >> n;
	while (n--) {
		cin >> Sample;
		//cout << Sample << endl;
		if (regex_match(Sample, smStr, REA)) {
			if (smStr[1].length() == smStr[2].length()) {
				cout << "A" << endl;
			}
			else {
				cout << "NA" << endl;
			}
		}
		else if (regex_match(Sample, REB)) {
			cout << "B" << endl;
		}
		else {
			cout << "NA" << endl;
		}
	}

	return 0;
}



Measured memory_bytes: 3184
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp4
{
    class Program
    {
        public static void Main(string[] args)
        {
            List<string> kouho = new List<string>();
            string s = Console.ReadLine();
            int k = int.Parse(Console.ReadLine());
            for (int i = 'a'; i < 'z' + 1; i++)
            {
                int focus = s.IndexOf((char)i);
                while(focus != -1)
                {
                    for (int c = 0; c < 5; c++)
                    {
                        try
                        {
                            if (!kouho.Contains(s.Substring(focus, c + 1)))
                            {
                                kouho.Add(s.Substring(focus, c + 1));
                            }
                        }
                        catch
                        {
                            break;
                        }
                    }
                    if (focus == 0)
                    {
                        s = 'X' + s.Substring(focus + 1);
                    }
                    else if (focus + 1 <= s.Length)
                    {

                        string look1 = s.Substring(0, focus - 1);
                        string look2 = s.Substring(focus + 1);
                        s = s.Substring(0, focus) + 'X' + s.Substring(focus + 1);
                    }
                    else
                    {
                       
                        s = s.Substring(0, focus) + 'X';
                    }
                    focus = s.IndexOf((char)i);

                    if (focus == -1)
                    {
                        s = s.Replace('X', (char)i);
                        break;
                    }
                    else
                    {

                    }

                }
                if (kouho.Count >= 5) break;
            }
            ;
            kouho.Sort();
            ;
            Console.WriteLine(kouho[k - 1]);
        }

    }
}


Measured memory_bytes: 34440
#include<stdio.h>
int main(void)
{
  int i,j,k;
  int ymd[100][3], n, y3=590, date;

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

  for(i=0;i<n;i++) {
    date = 0;
    date += ((ymd[i][0]-1)/3)*y3;
    switch(ymd[i][0]%3){
    case 2:
      date += 195;
      for(j=0;j<ymd[i][1]-1;j++) {
	j%2 ? (date += 19):(date += 20);
      }
      date += ymd[i][2];
      break;
      
    case 1:
      for(j=0;j<ymd[i][1]-1;j++) {
	j%2 ? (date += 19):(date += 20);
      }
      date += ymd[i][2];
      break;
      
    case 0:
      date += 390;
      for(j=0;j<ymd[i][1]-1;j++) {
	date += 20;
      }
      date += ymd[i][2];
      break;
    }
    printf("%d\n", 196471 - date);
  }

  for(i=0;i<100000;i++) {
    for(j=0;j<10000000;j++) k++;
}

  return 0;
}
      

Measured memory_bytes: 596
//Author rahuliitkgp

/*A thing of beauty is a joy forever,
Its loveliness increases,
it will never pass into nothingness.*/
//Men at Work :)

#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
typedef long long int ll;

#define setbits(x)      __builtin_popcountll(x)
#define mod             1000000007
#define ps(x,y)         fixed<<setprecision(y)<<x
#define w(x)            int x; cin>>x; while(x--)
mt19937_64 mt(chrono::steady_clock::now().time_since_epoch().count());

typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;

void cpp(){
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
}

int main(){
    cpp();
    ll n;
    cin>>n;
    vector<ll> v(n+1);
    for(ll i=1; i<=n; i++){
        for(ll j=i; j<=n; j+=i){
            v[j]++;
        }
    }
    ll ans = 0;
    for(ll i=1; i<=n; i++){
        ans+=(i*v[i]);
    }
    cout<<ans<<endl;
    return 0;
}




Measured memory_bytes: 81380
import java.io.*;
import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        PrintWriter pw = new PrintWriter(System.out);
//        sc.useDelimiter("\n");
//        DecimalFormat df = new DecimalFormat("0.00000000");
        
        int a = Integer.parseInt(sc.next());
        int b = Integer.parseInt(sc.next());
        int taxA, taxB;
        int ans = -1;
        
        for (int i = 1000; i >= 12; i--) {
            taxA = (int) (i * 0.08);
            taxB = (int) (i * 0.10);
//            pw.println(i + " " + taxA + " " + taxB);
            if (a == taxA && b == taxB)   ans = i;
        }
        pw.println(ans);
        
        pw.flush();
    }
}

Measured memory_bytes: 23124
#include <bits/stdc++.h>
#define ll long long
#define pii pair<int, int>
using namespace std;

const int N = 12;
int a[N];
int b[N];
int n;
vector<string> ans ;
void check(int dep,int pre)
{
    if(dep>n){
        string s;
        s.resize(n);
        for(int i=1;i<=n;++i){
            s[i-1] = (char(a[i]+'a'-1));
        }
        ans.push_back(s);
        return ;
    }
    for(int i=1;i<=min(dep,pre+1);++i){
        a[dep] = i;
        check(dep+1,max(pre,i));
    }
}
int main()
{
    cin >> n;
    a[1] = 1;
    check(2,1);
    sort(ans.begin(),ans.end());
    for(auto s:ans){
        cout << s << '\n';
    }
    return 0;
}

Measured memory_bytes: 7796
#include <iostream>

using namespace std;
 
int n,k,s,ans;
 
void rec(int num,int kk,int sum){
    if(kk < 0 || sum < 0) return;
 
    if(kk == 0 && sum == 0){
	ans++; return;
    } 
    for(int i = num ; i >= 1 ; i--){
	rec(i-1,kk-1,sum-i);
    }
}
 
int main(){
    while(cin >> n >> k >> s, n | k | s){
	ans = 0; rec(n,k,s);
	cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 3036
package main

import "fmt"

var s string

func main() {
	fmt.Scan(&s)
	rs := []rune(s)
	n := len(rs)
	gp := make(map[rune]int)
	for _, c := range s {
		gp[c]++
	}
	fmt.Println(n/2 - gp['p'])
}


Measured memory_bytes: 1664
# -*- coding: utf-8 -*-

n, k = map(int, input().split(' '))
sss = input()

ans = []
for i, S in enumerate(sss):
    i += 1
    if i == k:
        s = S.lower()
        ans.append(s)
    else:
        ans.append(S)

print("".join(ans))

Measured memory_bytes: 2940
/**
 * File    : C.cpp
 * Author  : Kazune Takahashi
 * Created : 1/13/2019, 9:04:34 PM
 * Powered by Visual Studio Code
 */

#include <iostream>
#include <iomanip>   // << fixed << setprecision(xxx)
#include <algorithm> // do { } while ( next_permutation(A, A+xxx) ) ;
#include <vector>
#include <string> // to_string(nnn) // substr(m, n) // stoi(nnn)
#include <complex>
#include <tuple>
#include <queue>
#include <stack>
#include <map> // if (M.find(key) != M.end()) { }
#include <set>
#include <functional>
#include <random> // auto rd = bind(uniform_int_distribution<int>(0, 9), mt19937(19920725));
#include <chrono> // std::chrono::system_clock::time_point start_time, end_time;
// start = std::chrono::system_clock::now();
// double elapsed = std::chrono::duration_cast<std::chrono::milliseconds>(end_time-start_time).count();
#include <cctype>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
using namespace std;

#define DEBUG 0 // change 0 -> 1 if we need debug.

typedef long long ll;

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

// const int C = 1e6+10;
// const ll M = 1000000007;

int N;
ll A[100010];
ll B[100010];
vector<ll> V;
vector<ll> W;

int main()
{
  cin >> N;
  ll sum_A = 0, sum_B = 0;
  for (auto i = 0; i < N; i++)
  {
    cin >> A[i];
    sum_A += A[i];
  }
  for (auto i = 0; i < N; i++)
  {
    cin >> B[i];
    sum_B += B[i];
  }
  if (sum_A < sum_B)
  {
    cout << "-1" << endl;
    return 0;
  }
  for (auto i = 0; i < N; i++)
  {
    if (A[i] < B[i])
    {
      V.push_back(B[i] - A[i]);
    }
    else if (A[i] > B[i])
    {
      W.push_back(A[i] - B[i]);
    }
  }
  int ans = V.size();
  ll need = 0;
  for (auto x : V)
  {
    need += x;
  }
  sort(W.begin(), W.end());
  reverse(W.begin(), W.end());
  ll sum_W = 0;
  auto it = W.begin();
  while (sum_W < need)
  {
    sum_W += *it;
    it++;
    ans++;
  }
  cout << ans << endl;
}

Measured memory_bytes: 2812
#include <algorithm>
#include <iostream>
#include <numeric>
#include <vector>
#include<iomanip>
using namespace std;

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

int main()
{
   long long H=0;
   long long W=0;
   cin>>H>>W;
   if(H==1||W==1)
   {
       cout<<1<<endl;
       return 0;
   }
   if(H*W%2==0)
   {
       cout<<H*W/2<<endl;
   }
   else
   {
       cout<<(H*W/2)+1<<endl;
   }
   return 0;
}


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

int main(){
    int x;
    cin >> x;
    int grad = 0;
    int a;
    a = x / 500;
    grad += a * 1000;
    x -= 500 * a;
    int b;
    b =  x / 5;
    grad += b * 5;
    cout << grad << endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>

using namespace std;

typedef long long ll;

ll K;

int main() {
	cin >> K;
	if (K <= 50) {
		cout << 50 << endl;
		for (int i = 0; i < 50; i++) {
			if (i + K >= 50)cout << i + 1 << " ";
			else cout << 0 << " ";
		}
		cout << endl;
	}
	else {
		cout << 50 << endl;
		ll syou = K / 50LL;
		ll amari = K % 50LL;
		for (ll i = 0; i < 50; i++) {
			ll ret = i + 1;
			if (i + 1 + amari > 50)ret++;
			ret += (syou - 1);
			cout << ret << " ";
		}
		cout << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <string>
#include <map>
using namespace std;
int main() {
	string s;
	cin >> s;
	for (int i = 0; i < s.length()-1;i++) {
		if (s[i] == 'A' && s[i+1] == 'C') {
			cout << "Yes" << endl;
			return 0;
		}
	}
	cout << "No" << endl;
	return 0;
}



Measured memory_bytes: 256
K=int(input())
l=[1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]

print(l[K-1])


Measured memory_bytes: 2940
#include <bits/stdc++.h>
 
#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)
 
#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=(int)(a)-1;i>=(int)(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)
 
#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define bit(n) (1LL<<(n))
 
// #define DEBUG
 
#ifdef DEBUG
    #define dump(...) fprintf(stderr, __VA_ARGS__)
#else
    #define dump(...)
#endif
 
template<class T>bool chmax(T &a, const T &b) { return (a<b)?(a=b,1):0;}
template<class T>bool chmin(T &a, const T &b) { return (b<a)?(a=b,1):0;}
 
using namespace std;
using ll=long long;
using vi=vector<int>;
using vll=vector<ll>;
 
const double EPS = 1e-10;
const double PI = acos(-1.0);
const ll INF = 1LL << 62;
const int inf = 1 << 30;
const ll MOD = 1000000007LL;
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
 
ll extgcd(ll a,ll b,ll& x,ll& y){x=1,y=0;ll g=a;if(b!=0) g=extgcd(b,a%b,y,x),y-=a/b*x;return g;}
ll ADD(const ll &a, const ll &b, const ll mod=MOD) { return (a+b)%mod;}
ll SUB(const ll &a, const ll &b, const ll mod=MOD) { return (a-b+mod)%mod;}
ll MUL(const ll &a, const ll &b, const ll mod=MOD) { return (1LL*a*b)%mod;}
ll DIV(const ll &a, const ll &b, const ll mod=MOD) {ll x,y; extgcd(b,mod,x,y);return MUL(a,(x+mod)%mod,mod);}
 
int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);

    ll S, C; cin >> S >> C;
    ll C_s = min(2 * S, C);

    ll res = C_s / 2;
    S -= C_s / 2;
    C -= C_s;

    res += C / 4;

    cout << res << endl;

    return 0;
}


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

#define SEA     ( 0)
#define LAND    ( 1)
#define VISITED (-1)

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

int dfs(std::vector<std::vector<int> >& field, const int width, const int height, const int x, const int y) {
  if (field[y][x] == VISITED || field[y][x] == SEA)
    return 0;
  field[y][x] = VISITED;
  for (int i = 0; i < 8; ++i) {
    int cx = x + dx[i], cy = y + dy[i];
    if (cx < 0 || cy < 0 || width <= cx || height <= cy)
      continue;
    dfs(field, width, height, cx, cy);
  }
  return 1;
}

int main(int argc, char const* argv[])
{
  while (true) {
    int w, h;
    std::cin >> w >> h;
    if (w == 0 && h == 0)
      break;
    std::vector<std::pair<int, int> > lands;
    int n_lands = 0;
    std::vector<std::vector<int> > field(h, std::vector<int>(w, 0));
    for (int y = 0; y < h; ++y) {
      for (int x = 0; x < w; ++x) {
        std::cin >> field[y][x];
        if (field[y][x] == LAND) {
          lands.push_back(std::make_pair<int, int>(x, y));
          ++n_lands;
        }
      }
    }
    int ans = 0;
    for (int i = 0; i < n_lands; ++i) {
      ans += dfs(field, w, h, lands[i].first, lands[i].second);
    }
    std::cout << ans << std::endl;
  }
  return 0;
}

Measured memory_bytes: 1428
# import math
x = int(input())

cnt = 0
answer = 100

# こんなのやらなくてよかったク◯アホ
# 金額* 0.01 = 利子
# 福利計算式 FV = PV * (1 + R) ** n
# fv(futurevalue):将来価値 pv(presentvalue)(元金):現在価値  r:金利(年利)% n:経過年数
# fv = 100 (1 + 1)
# k = 100 * (1 + 1) ** n    k / 100
# x = x / 100
# print(math.log(2, x))



# for i in range(x):
#     # ans += 100 * 0.01
#     ans = ans // 100
#     if x <= ans:
#         answer = i + 1
#         break
# print(answer)

# x円以上になるまで == xがanswer 未満の間
while answer < x:
    cnt += 1
    answer += answer // 100
    # print(answer)
    # print(x)

print(cnt)

Measured memory_bytes: 9168
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,s,n) for(int i=s;i<n;i++)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
typedef long long ll;
const ll inf = 1e9;
int main(){
    int n, w;
    cin >> n >> w;
    vector<int> val(n), wei(n), dp(w+1, 0);
    rep(i,n)cin >> val[i] >> wei[i];
    rep(i,w+1){
        int ma = 0;
        rep(j,n)if(i >= wei[j])ma = max(ma, dp[i - wei[j]] + val[j]);
        dp[i] = ma;
    }
    cout << dp[w] << endl;
    return 0;
}


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

int main(){

      int n; cin >>n;

      int judge = n%10;

      if(judge == 3) cout <<"bon" <<endl;
      else if(judge == 0 || judge == 1 || judge == 6 || judge == 8 )
      cout << "pon" << endl;
      else cout << "hon" <<endl;
}


Measured memory_bytes: 3592
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cassert>
#include <complex>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <cstdlib>
#include <cstring>
#include <iomanip>
#include <numeric>
#include <sstream>
#include <ctime>
#include <cctype>
#include <set>
#include <map>
#include <queue>
#include <bitset>
#include <deque>
#include <stack>
#include <memory.h>
using namespace std;
#define ll long long
#define mp make_pair
ll n;
ll spo[100005];
ll kg[100005];
ll sum;
ll ab(ll a){
	if(a>0){
		return a;
	}
	return -a;
}
int main()
{
	cin>>n;
	for(ll i=1;i<=n;i++){
		cin>>spo[i];
	}
	n+=2;
	for(ll i=0;i<n-1;i++){
		sum+=ab(spo[i]-spo[i+1]);
	}
	//cout<<sum;
	for(ll i=0;i<n-2;i++){
		kg[i]=ab(spo[i+2]-spo[i]);
		//cout<<kg[i]<<" ";
	}
	for(ll i=1;i<n-1;i++){
		cout<<sum-(ab(spo[i]-spo[i-1]))-(ab(spo[i+1]-spo[i]))+kg[i-1]<<endl;
	}
    return 0;
}


Measured memory_bytes: 2816
#include<stdio.h>

#define MAX 25

typedef struct{
  int p, s, deg, dep, h, left, right;
}Node;

int depth(Node *, int);
int height(Node *, int);
void Preorder(Node *, int);
void Inorder(Node *, int);
void Postorder(Node *, int);

int main(){
  int i, n, id, r;
  Node T[MAX], tmp;

  scanf("%d",&n);
  for(i = 0; i < n; i++){
    T[i].p = -1;
    T[i].dep = 0;
    T[i].deg = 0;
    T[i].s = -1;
  }
  for(i = 0; i < n; i++){
    scanf("%d",&id);
    scanf("%d%d", &T[id].left, &T[id].right);
    T[T[id].left].p = id;
    T[T[id].right].p = id;
    if(T[id].left != -1){
      T[id].deg++;
      T[T[id].left].s = T[id].right;
    }
     if(T[id].right != -1){
      T[id].deg++;
      T[T[id].right].s = T[id].left;
    }
  }

  for(i = 0; i < n; i++){
    T[i].dep = depth(T, i);
    if(T[i].dep == 0) r = i;
    T[i].h = height(T, i);
  }
  
  printf("Preorder\n");
  Preorder(T, r);
 
  printf("\nInorder\n");
  Inorder(T, r);
 
  printf("\nPostorder\n");
  Postorder(T, r);
  printf("\n");

  return 0;
}

void Preorder(Node *T, int i){
  if(i == -1) return;
  printf(" %d",i);

  Preorder(T, T[i].left);
  
  Preorder(T, T[i].right);

}

void Inorder(Node *T, int i){
  if(i == -1) return;

  Inorder(T, T[i].left);
  printf(" %d",i);

  Inorder(T, T[i].right);
}

void Postorder(Node *T, int i){
  if(i == -1) return;

  Postorder(T, T[i].left);
  
  Postorder(T, T[i].right);
  printf(" %d",i);
}

int depth(Node *T, int i){

  if(T[i].p == -1) return 0;

  return depth(T, T[i].p) + 1;
  
}

int height(Node *T, int i){
  int righth = 0, lefth = 0;

  if(T[i].right != -1) righth = height(T, T[i].right) + 1;

  if(T[i].left != -1) lefth = height(T, T[i].left) + 1;

  if(righth >= lefth) return righth;
  else return lefth;
}

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

char a[1010][1010];
int dist[1010][1010];
deque <int> q;

int main () {
	int n, m; scanf("%d%d", &n, &m);
	int x1, x2, y1, y2; scanf("%d%d%d%d", &x1, &y1, &x2, &y2);
	x1--, x2--, y1--, y2--;
	for (int i = 0; i < n; i++) {
		scanf("%s", a[i]);
	}
	memset(dist, 0x3f, sizeof(dist));
	q.push_back(x1), q.push_back(y1), dist[x1][y1] = 0;
	while (!q.empty()) {
		int x = q.front(); q.pop_front();
		int y = q.front(); q.pop_front();
		for (int i = max(0, x - 2); i < min(n, x + 3); i++) {
			for (int j = max(0, y - 2); j < min(m, y + 3); j++) {
				if (a[i][j] == '#') continue;
				int d = abs(i - x) + abs(j - y) <= 1 ? 0 : 1;
				if (dist[i][j] > dist[x][y] + d) {
					dist[i][j] = dist[x][y] + d;
					if (!d) q.push_front(j), q.push_front(i);
					else q.push_back(i), q.push_back(j);
				}
			}
		}
	}
	printf("%d\n", dist[x2][y2] == 0x3f3f3f3f ? -1 : dist[x2][y2]);
	return 0;
}


Measured memory_bytes: 8808
from itertools import*
from math import*
from collections import*
from heapq import*
from bisect import bisect_left,bisect_right
from copy import deepcopy
inf = float("inf")
mod = 10**9+7
from functools import reduce
import sys
sys.setrecursionlimit(10**7)

N = int(input())
W = list(map(int,input().split()))
ans = inf
for t in range(N):
    ans = min(ans,abs(sum(W[:t])-sum(W[t:])))

print(ans)

Measured memory_bytes: 38640
#include <cmath>
#include <cstdlib>
#include <iostream>
#include <bitset>
#include <deque>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
#include <iterator>
#include <string>
#include <chrono>
#include <random>
#include <tuple>
#include <utility>
#include <fstream>
 
const long INF = (1l << 30);
const long LINF = (1l << 60);

long a, p;

int main(){
	scanf("%ld%ld", &a, &p);
	printf("%ld\n", (3*a + p) / 2);
	return 0;
}


Measured memory_bytes: 888
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();
			if(a < b && b < c) System.out.println("Yes");
			else System.out.println("No");
    }
}


Measured memory_bytes: 26220