akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cstring>
#include <cctype>
#include <algorithm>
#include <string>
#include <complex>
#include <list>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <sstream>
#include <numeric>
#include <functional>
#include <bitset>
#include <iomanip>

using namespace std;


#define INF (1<<29)

// math
#define Sq(x) ((x)*(x))

// container utility
#define ALL(x) (x).begin(), (x).end()
#define MP make_pair
#define PB push_back
#define EACH(it,c) for(__typeof((c).begin())it=(c).begin();it!=(c).end();it++)

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

// debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

// typedef
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<PII> VII;
typedef vector<VI> VVI;

typedef long long ll;

// useful
#define FST first
#define SND second

#define CK(n,a,b) (a<=n && n<b)

// conversion
template<class T> inline string toStr(T a) { ostringstream oss; oss << a; return oss.str(); }
inline int toInt(string s) { return atoi(s.c_str()); }

// prime
bool isPrime(int a) { for(int i=2; i*i <=a; i++) if(a%i == 0) return false; return true; }

// !!! set SSIEVVE_MAX_L number !!!
#define SSIEVE_MAX_L (1000001)
#define SSIEVE_MAX_SQRT_B ((int)sqrt(INT_MAX)+1)
 
bool is_prime[SSIEVE_MAX_L];
vector<bool> is_prime_small(SSIEVE_MAX_SQRT_B);
 
void segment_sieve(ll a, ll b) {
   
  for(int i=0; (ll)i*i < b; i++) is_prime_small[i] = true;
  for(int i=0; i < b-a; i++) is_prime[i] = true;
   
  if(a == 1) {
    is_prime[0] = false;
  }
   
  for(int i=2; (ll)i*i<b; i++) {
    if(is_prime_small[i]) {
      for(int j=2*i; (ll)j*j<b; j+=i) is_prime_small[j] = false;
      for(ll j = max(2LL, (a+i-1)/i)*i; j<b; j+=i) is_prime[j-a] = false;
    }
  }
}

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

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

int main() {
  
  int N, M;
  int tcase = 1;
  
  while(cin >> N >> M && (N|M)) {
    VI next(22), now(22);
    
    for(int i=0; i<N/2; i++) {
      next[0] = ++ now[0], next[1] = ++ now[1];
    }
    if(N % 2) next[0] = ++ now[0];
    
    int ans = 1;
    while(now[M] == 0) {
      fill(ALL(next), 0);
      for(int i=0; i<22; i++) {
	next[i+1] += now[i] / 2;
	next[0] += now[i] / 2;
	next[i] += now[i] % 2;
      }
      ans ++;
      
      for(int i=0; i<22; i++) now[i] = next[i];
    }
    
    cout << "Case " << tcase ++ << ": " << ans << endl;
    
  }
  
  return 0;
}

Measured memory_bytes: 1196
#include <iostream>
#include <vector>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <set>
#include <string>
using namespace std;

int main(){
    string s;
    cin >> s;
    string ans;
    if ( s.find('a') != -1 && s.find('b') != -1 && s.find('c') != -1 )ans ="Yes";
    else ans = "No";
    cout << ans << endl;
}

Measured memory_bytes: 256
import std.stdio;
import std.algorithm;
import std.array;
import std.conv;
import std.string;

void main() {
  int n = readln.chomp.to!int;
  auto a = readln.chomp.split.map!(to!int).array;

  a.sort!("a > b");

  int alice, bob;

  foreach(i, num; a) {
    if (i % 2) {
      bob += num;
    }
    else {
      alice += num;
    }
  }

  writeln(alice - bob);
}

Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"io"
	"os"
	"strconv"
)

var sc *bufio.Scanner

const BufferSize = 1024

func nextInt() int {
	if !sc.Scan() {
		panic(nil)
	}
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

var production bool

func debugf(format string, v ...interface{}) {
	if !production {
		fmt.Printf(format, v...)
	}
}

func min(a ...int) int {
	res := a[0]
	for i := 1; i < len(a); i++ {
		if res > a[i] {
			res = a[i]
		}
	}
	return res
}

func answer(reader io.Reader, writer io.Writer) {
	sc = bufio.NewScanner(reader)
	buf := make([]byte, BufferSize)
	sc.Buffer(buf, 1e+6)
	sc.Split(bufio.ScanWords)
	m := 2019
	l := nextInt()
	r := nextInt()
	l2 := l % m
	r2 := r % m
	ans := 0
	// if l2 > r2 { ans = 0 }
	debugf("%v, %v\n", l2, r2)
	if l2 < r2 && (r-l) < 2019 {
		ans = m
		for i := l2; i < r2; i++ {
			for j := i + 1; j <= r2; j++ {
				ans = min((i*j)%m, ans)
			}
		}
	}
	_, _ = fmt.Fprintf(writer, "%d", ans)
}

func main() {
	production = true
	answer(os.Stdin, os.Stdout)
}


Measured memory_bytes: 640
process.stdin.resume();
process.stdin.setEncoding('utf8');
process.stdin.on('data', function (chunk) {
    var lines = chunk.toString().split('\n');
    var x =lines[0];

var ji = Math.floor(x / 3600);
x -= ji * 3600;
var hun = Math.floor(x / 60);
x -= hun * 60;
var byo = x;
console.log(ji+":"+hun+":"+byo);
});

Measured memory_bytes: 7648
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>

using namespace std;

#define REP(i,n) for(int i=0;i<n;i++)
#define all(x) (x).begin(),(x).end()
#define pb(a) push_back(a)
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

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

int main()
{
    string s,t;
    cin >> s >> t;
    if(t.substr(0,s.size())==s){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
}


Measured memory_bytes: 3628
#include <cstdio>
#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
#include <unordered_map>
#include <cmath>
#include <queue>
#include <set>

using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define INF int(1e9)
#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define REPR(i, n) for(int i = n - 1; i >= 0; i--)
#define REPONE(i, n) for(int i = 1; i <= (int)(n); i++)
#define EACH(i, mp) for(auto i:mp)
#define FOR(i, m, n) for(int i = m;i < n;i++)
int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};

const int MAX_N = 2 * int(1e5);
ll K, N, A[MAX_N];
unordered_map<ll, ll> mp;

void solve() {
    vector<pair<ll, ll> > v(mp.begin(), mp.end());
    sort(v.begin(), v.end(), [](pair<ll, ll> a, pair<ll, ll> b) { return a.second < b.second; });
    ll ans = 0;
    REP(i, v.size() - K) {
        ans += v[i].second;
    }
    cout << ans << endl;
}

int main() {
    cin >> N >> K;
    REP(i, N) {
        cin >> A[i];
        mp[A[i]]++;
    }
    solve();
    return 0;
}

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

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int MOD = 1e9 + 7;

int main() {
    int h, w;
    cin >> h >> w;
    vector<vector<char>> grid(h, vector<char>(w));
    for (int i = 0; i < h; ++i) {
        for (int j = 0; j < w; ++j) {
            cin >> grid[i][j];
        }
    }
    for (int i = 0; i < h; ++i) {
        for (int j = 0; j < w; ++j) {
            if (grid[i][j] == '#') {
                int flag = 0;
                if (i == 0 || grid[i - 1][j] == '.') ++flag;
                if (i == h - 1 || grid[i + 1][j] == '.') ++flag;
                if (j == 0 || grid[i][j - 1] == '.') ++flag;
                if (j == w - 1 || grid[i][j + 1] == '.') ++flag;
                if (flag == 4) {
                    cout << "No" << endl;
                    return 0;
                }
            }
        }
    }
    cout << "Yes" << endl;
    return 0;
}

static int speedUp = []() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    return 0;
}();

Measured memory_bytes: 256
parseInt(x) = parse(Int, x)
parseBigInt(x) = parse(BigInt, x)
parseFloat(x) = parse(Float64, x)
parseBigFloat(x) = parse(BigFloat, x)
parseMap(x::Array{SubString{String},1}) = map(parseInt, x)
function main()
    A,B,C,D = parseMap(split(readline())) 
    while(true)
        C-=B
        if C<=0
            println("Yes")
            break
        end
        A-=D
        if A<=0
            println("No")
            break
        end
    end

end
main()





Measured memory_bytes: 160980
#include <iostream>
using namespace std;
int main(void){
  int a;
  cin >> a ;
  a = a%1000;
  a  = 1000 -a;
  if(a == 1000){
  	a = 0;
  }
    cout <<a <<endl;
    //cout << "XXXXXX" << endl;
   return 0;
}

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

#define fread_siz 1024

inline int get_c(void)
{
	static char buf[fread_siz];
	static char *head = buf + fread_siz;
	static char *tail = buf + fread_siz;

	if (head == tail)
		fread(head = buf, 1, fread_siz, stdin);

	return *head++;
}

inline int get_i(void)
{
	register int ret = 0;
	register int neg = false;
	register int bit = get_c();

	for (; bit < 48; bit = get_c())
		if (bit == '-')neg ^= true;

	for (; bit > 47; bit = get_c())
		ret = ret * 10 + bit - 48;

	return neg ? -ret : ret;
}

int exgcd(int a, int b, int &x, int &y)
{
	if (!b)
	{
		x = 1;
		y = 0;
		return a;
	}
	int ret = exgcd(b, a%b, y, x);
	y = y - x * (a / b);
	return ret;
}

signed main(void)
{
	int x, y;
	int a = get_i();
	int b = get_i();
	exgcd(a, b, x, y);
	printf("%d %d\n", x, y);
}

Measured memory_bytes: 3156
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
template <class T> using vec = vector<T>;
template <class T> using vvec = vector<vec<T>>;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    cin >> N;
    map<int,map<char,set<int>>> mx,my,mp,mm;
    vec<int> X(N),Y(N);
    vec<char> U(N);
    for(int i=0;i<N;i++){
        cin >> X[i] >> Y[i] >> U[i];
        mx[X[i]][U[i]].insert(Y[i]);
        my[Y[i]][U[i]].insert(X[i]);
        mp[X[i]+Y[i]][U[i]].insert(X[i]);
        mm[X[i]-Y[i]][U[i]].insert(X[i]);
    }
    int inf = 1e9,ans = inf;
    for(int i=0;i<N;i++){
        if(U[i]=='U'){
            if(!mx[X[i]]['D'].empty()){
                auto it = mx[X[i]]['D'].upper_bound(Y[i]);
                if(it!=mx[X[i]]['D'].end()) ans = min(ans,*it-Y[i]);
            }
        }
        if(U[i]=='R'){
            if(!my[Y[i]]['L'].empty()){            
                auto it = my[Y[i]]['L'].upper_bound(X[i]);
                if(it!=my[Y[i]]['L'].end()) ans = min(ans,*it-X[i]);
            }
        }
        if(U[i]=='R'){
            if(!mp[X[i]+Y[i]]['U'].empty()){
                auto it = mp[X[i]+Y[i]]['U'].upper_bound(X[i]);
                if(it!=mp[X[i]+Y[i]]['U'].end()) ans = min(ans,(*it-X[i])*2);
            }
            if(!mm[X[i]-Y[i]]['D'].empty()){
                auto it = mm[X[i]-Y[i]]['D'].upper_bound(X[i]);
                if(it!=mm[X[i]-Y[i]]['D'].end()) ans = min(ans,(*it-X[i])*2);
            }
        }
        if(U[i]=='D'){
            if(!mp[X[i]+Y[i]]['L'].empty()){
                auto it = mp[X[i]+Y[i]]['L'].upper_bound(X[i]);
                if(it!=mp[X[i]+Y[i]]['L'].end()) ans = min(ans,(*it-X[i])*2);
            }
        }
        if(U[i]=='U'){
            if(!mm[X[i]-Y[i]]['L'].empty()){
                auto it = mm[X[i]-Y[i]]['L'].upper_bound(X[i]);
                if(it!=mm[X[i]-Y[i]]['L'].end()) ans = min(ans,(*it-X[i])*2);
            }
        }
//        cerr << ans << "\n";
    }
    if(ans==inf) cout << "SAFE\n";
    else cout << 5*ans << "\n";
}

Measured memory_bytes: 182648
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, a, b) for (int i = a; i < (int)b; i++)
#define all(v) v.begin(), v.end()
const int MOD = 1e9 + 7;
const int INF = 1e9;
//'A' = 65, 'Z' = 90, 'a' = 97, 'z' = 122

int main() {
    int n;
    cin >> n;
    int x[n], y[n];
    rep(i, 0, n) {
        cin >> x[i] >> y[i];
    }
    int order[n];
    rep(i, 0, n) {
        order[i] = i;
    }

    double sum = 0;
    do {
        rep(i, 0, n - 1) {
            double a = abs(x[order[i]] - x[order[i + 1]]);
            double b = abs(y[order[i]] - y[order[i + 1]]);
            sum += sqrt(a * a + b * b);
        }
    } while (next_permutation(order, order + n));

    int np = 1;
    rep(i, 1, n + 1) np *= i;
    cout << fixed << setprecision(10);
    cout << sum / np << endl;
    return 0;
}


Measured memory_bytes: 256
//"BISMILLAHIR RAHMANIR RAHIM"
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
const long long M = 1e10 ;
int main()
{
    ll f=0,i,n=0,con=0,rem,k;
    cin>>k;
    if(k%2==0)
    {
        cout<<"-1"<<endl;
        return 0;
    }
    for(i=1;i<=1e6;i++){

            n = (n*10+7)%k;

        if(n==0)
        {
            cout<<i<<endl;
            return 0;
        }
    }
    cout<<"-1"<<endl;

    return 0;
}


Measured memory_bytes: 3628
N = int(input())
count = 0
def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)
    return divisors

if __name__=="__main__":
    lis = make_divisors(N)
    for i in lis:
        if i!= 1:
            if N // (i-1) == N % (i-1):
                count += i-1
    print(count)
                


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

int main(){
  int n,ans;
  cin >> n;
  ans = 1;
  vector<int> d(n);
  for(int i = 0;i < n;i++){
    cin >> d.at(i);
  }
  sort(d.begin(),d.end());
  int tmp = d.at(0);
  
  for(int j = 0;j < n;j++){
    if(d.at(j) == tmp){
      continue;
    }else{
      tmp = d.at(j);
      ans++;
    }
  }

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

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

using namespace std;

typedef long long LL;
typedef pair<int , int> P2;
typedef pair<pair<int , int> , int> P3;
typedef pair<pair<int , int> , pair<int , int> > P4;
#define PB(a) push_back(a)
#define MP(a , b) make_pair((a) , (b))
#define M3P(a , b , c) make_pair(make_pair((a) , (b)) , (c))
#define M4P(a , b , c , d) make_pair(make_pair((a) , (b)) , make_pair((c) , (d)))
#define repp(i,a,b) for(int i = (int)(a) ; i < (int)(b) ; ++i)
#define repm(i,a,b) for(int i = (int)(a) ; i > (int)(b) ; --i)

int a[3];

int main(){
	cin >> a[0] >> a[1] >> a[2];
	sort(a,a+3);
	cout << (a[0] == a[1] ? a[2] : a[0]) << endl;
	return 0;
}


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

using namespace std;

#define all(v)			((v).begin()), ((v).end())
#define SZ(v)			((int)((v).size()))
#define clr(v, d)		memset(v, d, sizeof(v))
#define pb			    push_back

typedef long long ll;

int main() {

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

	int n, k;
	cin >> n >> k;
	vector<int> v(200009);
	for (int i = 0; i < n; ++i) {
		int x;
		cin >> x;
		v[x]++;
	}
	sort(v.rbegin(), v.rend());
	ll ans = 0;
	for (int i = k; i <= n; ++i)
		ans += v[i];
	cout << ans;
	cout << endl;

	return 0;
}


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

using namespace std;

#define REP1(i,n) for(int i=1, i##_len=(n); i<i##_len; ++i)
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define pow(x) x*x
#define ll long long
#define deg_to_rad(deg) (((double)(deg)/360.0)*2*M_PI)
static const ll MAX = 1000000;
static const ll INFTY = 1e12;
static const ll MOD = 1000000007;

template < typename T > inline string toString( const T &a ) { ostringstream oss; oss << a; return oss.str(); };

struct edge {
    ll to, cost;
};

using Graph = vector<vector<int>>;
using _Graph = vector<vector<edge>>;


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

// 深さ優先探索
vector<int> colors;

int H, W, N;
int sx, sy, gx, gy; 
vector<vector<char>> field;
vector<vector<int>> dist;
//vector<pair<int, int>> gx, gy;
deque<pair<int, int>> que;

typedef vector<vector<int> > Matrix;

const ll INF = 1e18;

// 深さ優先探索
vector<bool> seen;
vector<ll> since;
void dfs(const Graph &G, int v) {
    seen[v] = true; // v を訪問済にする

    // v から行ける各頂点 next_v について
    for (auto next_v : G[v]) { 
        if (seen[next_v]) continue; // next_v が探索済だったらスルー
        since[next_v] = v;
        dfs(G, next_v); // 再帰的に探索
    }
}

int main() {

    int N, M; cin >> N >> M;

    Graph G(N);
    for (int i = 0; i < M; ++i) {
        int a, b;
        cin >> a >> b;
        a--; b--;
        G[a].push_back(b);
        G[b].push_back(a);
    }
    vector<ll> since(N, -1);

   // BFS のためのデータ構造
    vector<int> dist(N, -1); // 全頂点を「未訪問」に初期化
    queue<int> que;

    // 初期条件 (頂点 0 を初期ノードとする)
    dist[0] = 0;
    que.push(0); // 0 を橙色頂点にする

    // BFS 開始 (キューが空になるまで探索を行う)
    while (!que.empty()) {
        int v = que.front(); // キューから先頭頂点を取り出す
        que.pop();

        // v から辿れる頂点をすべて調べる
        for (int nv : G[v]) {
            if (dist[nv] != -1) continue; // すでに発見済みの頂点は探索しない

            // 新たな白色頂点 nv について距離情報を更新してキューに追加する
            dist[nv] = dist[v] + 1;
            since[nv] = v;
            que.push(nv);
        }
    }

    REP(i, N){
        if(dist[i]== -1){
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
    REP1(i, N){
        cout << since[i]+1 << endl;
    }

    

}

/*
みんな、くるくるぱーにな〜れ
　∧＿∧　
（｡･ω･｡)つ━☆・*。
⊂　　 ノ 　　　・゜+.
　しーＪ　　　°。+ *´¨)
　　　　　　　　　.· ´¸.·*´¨) ¸.·*¨)
　　　　　　　　　　(¸.·´ (¸.·'* ☆
*/



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

using namespace std;

#define debug(...) fprintf(stderr, __VA_ARGS__), fflush(stderr)
#define time__(d)for(auto blockTime = make_pair(chrono::high_resolution_clock::now(), true); blockTime.second;debug("%s: %.5lf s\n", d, chrono::duration_cast<chrono::milliseconds>(chrono::high_resolution_clock::now() - blockTime.first).count()/1000.0), blockTime.second = false)

template <typename T>std::string NumberToString ( T Number ){std::ostringstream ss; ss << Number;return ss.str(); } // Usages NumberToString(3)
template <typename T>T StringToNumber ( const string &Text ){istringstream ss(Text);T result;return ss >> result ? result : 0;} // StringToNumber<int>("3")

string StrCpy(string str, long long int start, long long int end){string temp = "";for(long long int i=start; i<=end; i++){temp += str[i];}return temp;}

#define ull unsigned long long int
#define ll long long int 
#define gcd(a, b)  __gcd(a, b)
#define lcm(a, b)  ((a*b)/gcd(a, b))




int solve(){

    ll deposit_exc;

    cin >> deposit_exc;

    ll deposit = 100;

    for(int i=1; ; i++){
        deposit = deposit + deposit * .01;
        if(deposit >= deposit_exc){
            cout << i << endl;
            break;
        } 
    }
    
    return 0;
}

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

    time__("programm time"){
        solve();
	}
    return 0;

}

Measured memory_bytes: 3804
#include <stdio.h>
#include <string.h>
#include <string>
#include <algorithm>
#include <iostream>
#include <cmath>
#include <queue>
#include <vector>
using namespace std;
#define LL long long
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define lowbit(x) (x&-x)

const int maxn = 1e5 + 5;
const int INF = 0x3f3f3f3f;
LL a[maxn];
LL sum[maxn];
int main()
{
	int n;
	while (scanf("%d", &n) != EOF)
	{
		for (int i = 1; i <= n; i++)
		{
			scanf("%lld", &a[i]);
		}
		sort(a + 1, a + 1 + n);
		for (int i = 1; i <= n; i++)
			sum[i] = sum[i - 1] + a[i];
		int ans = 1;
		for (int i = n; i; --i)
		{
			if (a[i] <= 2 * sum[i - 1])
			{
				ans++;
			}
			else
				break;
		}
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 1792
#pragma GCC optimize("O3")
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
using namespace std;

using ll = long long;
using P = pair<int, int>;
using T = tuple<int, int, int>;

template <class T> inline T chmax(T &a, const T b) {return a = (a < b) ? b : a;}
template <class T> inline T chmin(T &a, const T b) {return a = (a > b) ? b : a;}

constexpr int MOD = 1e9 + 7;
constexpr int inf = 1e9;
constexpr long long INF = 1e18;
constexpr double pi = acos(-1);
constexpr double EPS = 1e-10;

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

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

    int h, w, k; cin>>h>>w>>k;
    vector<string> a(h);
    vector<P> v;
    queue<T> que;
    for(int i=0; i<h; i++){
        cin>>a[i];
        for(int j=0; j<w; j++){
            if(a[i][j] == 'S'){
                a[i][j] = '#';
                v.emplace_back(i, j);
                que.emplace(i, j, 0);
            }
        }
    }

    while(que.size()){
        int cy, cx, cnt;
        tie(cy, cx, cnt) = que.front(); que.pop();

        if(cnt == k) continue;

        for(int i=0; i<4; i++){
            int ny = cy + dy[i];
            int nx = cx + dx[i];

            if(!(0 <= ny && ny < h && 0 <= nx && nx < w)) continue;
            
            if(a[ny][nx] == '.'){
                a[ny][nx] = '#';
                v.emplace_back(ny, nx);
                que.emplace(ny, nx, cnt + 1);
            }
        }
    }

    int ans = inf;
    for(auto cur : v){
        int cy, cx;
        tie(cy, cx) = cur;

        int sum = 1;
        int disth = min(cy, h - cy - 1);
        int distw = min(cx, w - cx - 1);
        sum += (min(disth, distw) + k - 1) / k;
        
        chmin(ans, sum);
    }

    cout << ans << endl;
}

Measured memory_bytes: 11252
a, b, c = gets.chomp.split.map(&:to_i)
res = 0
if a == b && b == c && c % 2 == 0
  res = -1
end

while a % 2 == 0 && b % 2 == 0 && c % 2 == 0 && res != -1
  a, b, c = (b + c) / 2, (c + a) / 2, (a + b) / 2
  res += 1
end

puts res

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


int main(){
	int a, b, tmp, x, y, z;
	while (true){
		cin >> a >> b;
		if (cin.eof()){
			break;
		}
		if (a < b){
			 tmp = a;
			 x = b;
		}
		else {
			x = a;
			tmp = b;
		}
		while (tmp != 0) {
			y = tmp;
			tmp = x % y;
			x = y;
		}
		z = a / y * b;
		cout << y << " " << z << endl;
	}
	return 0;
}

Measured memory_bytes: 3056
#include<bits/stdc++.h>
using namespace std;
int main(){
    long long int n,d,count=0;
    cin>>n>>d;
    long long int x[n],y[n];
    long long int i;
    for(i=0;i<n;i++)
    cin>>x[i]>>y[i];
    for(i=0;i<n;i++){
        double t=sqrt(pow(x[i],2) + pow(y[i],2));
        if(t<=d)
        count++;
    }
    cout<<count<<endl;

}

Measured memory_bytes: 6804
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.stream.IntStream;
import java.io.IOException;
import java.util.stream.Collectors;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Stream;
import java.util.StringTokenizer;
import java.io.BufferedReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        MyScanner in = new MyScanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        C solver = new C();
        solver.solve(1, in, out);
        out.close();
    }

    static class C {
        public void solve(int testNumber, MyScanner in, PrintWriter out) {
            int H = in.Int();
            int W = in.Int();
            List<List<Character>> a = new ArrayList<>();
            for (int i = 0; i < H; i++) {
                String s = in.next();
                if (s.indexOf('#') < 0) {
                    continue;
                }
                a.add(s.chars().mapToObj(c -> (char) c).collect(Collectors.toList()));
            }
            for (int i = W - 1; i >= 0; i--) {
                boolean f = true;
                for (int j = 0; j < a.size(); j++) {
                    if (a.get(j).get(i) == '#') {
                        f = false;
                    }
                }
                if (f) {
                    for (int j = 0; j < a.size(); j++) {
                        a.get(j).remove(i);
                    }
                }
            }
            for (List<Character> l : a) {
                l.forEach(out::print);
                out.println();
            }
        }

    }

    static class MyScanner {
        private BufferedReader in;
        private StringTokenizer st;

        public MyScanner(InputStream stream) {
            in = new BufferedReader(new InputStreamReader(stream));
        }

        public String next() {
            while (st == null || !st.hasMoreTokens()) {
                try {
                    String rl = in.readLine();
                    if (rl == null) {
                        return null;
                    }
                    st = new StringTokenizer(rl);
                } catch (IOException e) {
                    return null;
                }
            }
            return st.nextToken();
        }

        public int Int() {
            return Integer.parseInt(next());
        }

    }
}



Measured memory_bytes: 26708
#include <iostream>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <climits>
#include <cmath>
#include <string>
using namespace std;

typedef long long ll;
#define mk make_pair

#define FOR(i,m,n) for(ll i=m; i<n; i++)
#define FORIN(i,m,n) for(ll i=m; i<=n; i++)
#define FOR1(i,n) for(ll i=1; i<n; i++)
#define FOR0(i,n) for(ll i=0; i<n; i++)
#define COUT(x) cout << x
#define CIN(x) cin >> x
#define ENDL cout << endl
#define SPACE1 cout << " "
#define SPACE2 cout << "  "
#define SPACE3 cout << "   "
#define ALL(x) (x).begin(),(x).end()

template<typename T>
void CHECK(string xxx,T x) {cout << xxx << ": " << x;}

ll lengthInteger(ll n)
{ ll i=1;  while(n/(ll)pow(10,i) > 0) i++;  return i;}

bool includeThree(ll length, ll n)
{bool hasThree = false;FOR0(i,length+1){if((n/(ll)pow(10,i)) % 10 == 3) hasThree = true; }return hasThree;}

ll GCD(ll a, ll b)
{if(a<b) swap(a,b);ll r;while(a%b != 0) {r = a%b;a = b;b = r;}return b;}

string S;
ll length;
ll sum;

ll dfs(ll i, vector<ll> a) {
  if(i == length-1) {
    
    sort(ALL(a),greater<ll>());
    // COUT("i:"); SPACE1; COUT(i); ENDL;

    ll alen = a.size();
    ll back = 0;
    ll idx=0;
    ll subsum=0;

    if(alen == 0) {
      subsum += std::stoll(S);
      // CHECK("alen",alen); ENDL;
    }

    FOR(j,0,alen) {

      // SPACE3; COUT("a:");
      // FOR(j,0,a.size()) {
      //
      //   COUT(a[j]); SPACE1;
      // }ENDL;

      if(j == alen-1) {
        back = a.back();
        a.pop_back();
        // SPACE3; CHECK("back", back); ENDL;
        // SPACE3; CHECK("add",std::stoll(S.substr(idx,back-idx)) + std::stoll(S.substr(back,length-back))); ENDL;
        subsum += std::stoll(S.substr(idx,back-idx)) + std::stoll(S.substr(back,length-back));
      }
      else {
        back = a.back();
        a.pop_back();
        // SPACE3; CHECK("back", back); ENDL;
        // SPACE3; CHECK("add",std::stoll(S.substr(idx,back-idx))); ENDL;
        subsum += std::stoll(S.substr(idx,back-idx));
        idx = back;
      }
    }
    // SPACE1; CHECK("subsum",subsum); ENDL;
    return subsum;

  } else {
    ll x,y;

    x = dfs(i+1,a);

    a.push_back(i+1);
    y = dfs(i+1,a);

    return x+y;
  }
}

int main() {
  CIN(S);
  length = S.size();
  // CHECK("lenght",length); ENDL;
  // CHECK("S", S); ENDL;
  //string substr = S.substr(1,length-1);
  //COUT(substr); ENDL;


  vector<ll> a;
  sum = dfs(0,a);
  // CHECK("final sum", sum);

  COUT(sum); ENDL;


  return 0;
}


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

int main(){
    int i,count=0;
  char str[3];
  
  for(i=0;i<3;i++){
    cin>>str[i];
  }
  
    if(str[0]=='R' && str[1]=='R' &&str[2]=='R'){
        count=3;
    }else if((str[0]=='R' && str[1]=='R') ||(str[2]=='R' && str[1]=='R')){
        count=2;
    }else if(str[0]=='R' || str[1]=='R' || str[2]=='R'){
        count=1;
    }else{
        count=0;
    }
    
  cout<<count<<'\n';
    
    
    
    
    return 0;
}


Measured memory_bytes: 3620
n,m=map(int,input().split())
ab=[]
cost=0
cnt=0
for i in range(n):
  ab.append(list(map(int,input().split())))
ab=sorted(ab)
#print(ab)
j=0
while m>0:
  if m>ab[j][1]:
    cost+=ab[j][0]*ab[j][1]
    m-=ab[j][1]
  else:
    cost+=m*ab[j][0]
    m=0
  j+=1
print(cost)

Measured memory_bytes: 28656
N, Y = map(int, input().split())

for x in range(N+1):
    for y in range(N-x+1):
        if 10000*x + 5000*y + 1000*(N-x-y)==Y:
            print("{} {} {}".format(x, y,(N-x-y)))
            exit()
print("-1 "+"-1 "+"-1")

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0; i<(n); i++)
int main() {
  ll n, m;
  cin >> n >> m;
  if(n>=3 && m>=3){
    cout << (ll)(n-2) * (m-2) << endl;
    return 0;
  }
  if(n>=m) swap(n,m);
  if(n==2) {
    cout << 0 << endl;
    return 0;
  }
  if(n==1){
    if(m==1) cout << 1 << endl;
    else if(m==2) cout << 0 << endl;
    else cout << m-2 << endl;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
const ll MOD=1000000007;
const double PI=3.14159265358979;
const ll INF= pow(10,18);
typedef pair<ll,ll> P;
typedef vector<ll> vl;
typedef vector<vl> vvl;
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define rep(i,n) FOR(i,0,n)
string abc="abcdefghijklmnopqrstuvwxyz";
string ABC="ABCDEFGHIJKLMNOPQRSTUVWXYZ";

int main() {
  ll n,m;
  cin >> n >> m;
  ll k=m/n;
  ll ans;
  for(ll i=k;i>=1;i--){
    if(m%i==0){
      ans=i;
      break;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.StringTokenizer;

import static java.lang.Integer.parseInt;

/**
 * Traveling by Stagecoach
 */
public class Main {

	static final double INF = 4000;

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

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

			//
			int n, m, p, a, b;
			int[] T;
			double[][] G;
			double[][] D;    //[???????????????][?????£?????¬??????]
			boolean[][] V;   //?¨??????????????????????

			st = new StringTokenizer(line);
			n = parseInt(st.nextToken());
			m = parseInt(st.nextToken());
			p = parseInt(st.nextToken());
			a = parseInt(st.nextToken());
			b = parseInt(st.nextToken());
			if ((n | m | p | a | b) == 0) break;

			//
			st = new StringTokenizer(br.readLine());
			T = new int[n];
			for (int i = 0; i < n; i++) T[i] = parseInt(st.nextToken());

			//
			G = new double[m + 1][m + 1];
			for (int i = 0; i <= m; i++) Arrays.fill(G[i], -1);

			for (int i = 0; i < p; i++) {
				st = new StringTokenizer(br.readLine());
				int x, y, z;
				x = parseInt(st.nextToken());
				y = parseInt(st.nextToken());
				z = parseInt(st.nextToken());
				G[x][y] = G[y][x] = (double) z;
			}

			//
			D = new double[m + 1][1 << n];
			V = new boolean[m + 1][1 << n];

			for (int i = 0; i <= m; i++) Arrays.fill(D[i], INF);
			D[a][0] = 0;

			while (true) {

				double min = INF;
				int v = -1, t = -1;

				for (int i = 1; i <= m; i++) {
					for (int j = 0; j < (1 << n); j++) {
						if (!V[i][j] && D[i][j] < min) {
							min = D[i][j];
							v = i; t = j;
						}
					}
				}

				if (v == -1) break;
				V[v][t] = true;

				for (int u = 1; u <= m; u++) {
					if (G[v][u] != -1) {
						for (int i = 0; i < n; i++) {
							if ((t >> i & 1) == 0) {
								double time = D[v][t] + (G[v][u] / T[i]);
								if (D[u][t | 1 << i] > time) {
									D[u][t | 1 << i] = time;
								}
							}
						}
					}
				}
			}

			double ans = INF;

			for (int i = 0; i < (1 << n); i++) {
				ans = Math.min(ans, D[b][i]);
			}

			System.out.println(ans != INF ? ans : "Impossible");
		}
	}
}

Measured memory_bytes: 54920
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <regex>
#define REP(i,n) for(int i = 0; i < n; i++)
#define FOR(i,j,n) for(int i = j; i < n; i++)
#define RFOR(i,j,n) for(int i = j-1; i >= n; i--)
#define PREC(n) fixed << setprecision(n)
#define print_array(v) REP(__k, v.size()) { cout << v[__k]; if(__k != v.size()-1) cout << " "; else cout << endl; }
#define YesorNo(a) printf(a?"Yes\n":"No\n")
#define _LIBCPP_DEBUG 0
using namespace std;
int64_t MOD = 1000000007;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  string s;
  cin >> s;
  YesorNo(s[2] == s[3] && s[4] == s[5]);
  return 0;
}
//templete by private_yusuke

Measured memory_bytes: 256
#!/usr/bin/env ruby
N,M,X = gets.chomp.split.map(&:to_i)
MAP = N.times.map { gets.split.map(&:to_i) }

ans  = 1e8
all  = 1<<N
mask = 0
while mask < all
  ary  = Array.new(M,0)
  cost = 0
  (0...N).each do |i|
    if mask>>i&1 == 1
      (0...M).each do |j|
        ary[j] += MAP[i][j+1]
      end
      cost += MAP[i][0]
    end
  end
  ok = true
  (0...M).each do |i|
    if ary[i] < X
      ok = false
      break
    end
  end
  if ok
    ans = [ans, cost].min
  end
  mask += 1
end

puts ans == 1e8 ? -1 : ans


Measured memory_bytes: 14304
#include<bits/stdc++.h>
using namespace std;
int main(){
  int a,b,c;
  cin >> a >> b >> c;
  if(a==b){
    cout << c << endl;
  }
  else if(a==c){
    cout << b << endl;
  }
  else{
    cout << a << endl;
  }
}

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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define reps(i, n, m) for (int i = (int)(n); i <= (int)(m); i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()
#define int long long

int K, N;
signed main(){
    cin >> K >> N;
    vector<int> house(N);
    rep(i, N) cin >> house[i];
    
    int longest = K - house[N-1] + house[0];
    rep(i, N-1) longest = max(longest, house[i+1] - house[i]);
    
    cout << K - longest << endl;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define fastIO ios::sync_with_stdio(NULL); cin.tie(NULL);

using namespace std;
const int N = 3E3+7;

long double f[N][N];
long double a[N];
int n;

int main()
{
    fastIO
    cin>>n;
    
    for (int i = 1;i <= n;++i) cin>>a[i];
    
    f[0][0] = 1;
    for (int i = 1;i <= n;++i) f[i][0] = f[i-1][0]* (1-a[i]);

    for (int i = 1;i <= n;++i)
        for (int j = 1;j <= n;++j)
            f[i][j] = ( f[i-1][j]*(1-a[i]) ) + ( f[i-1][j-1] * a[i] );
    
    long double res = 0;
    for (int i = n;i >= n/2+1; --i)
        res = res + f[n][i];
    
    cout<<fixed<<setprecision(9)<<res;
}

Measured memory_bytes: 144716
#include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define HUGE_NUM 99999999999999999
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;


int main(){

	ll N;
	scanf("%lld",&N);

	int count = 0; //1以外の約数の数
	queue<int> Q;

	if(N%2 == 0){

		int tmp = 0;

		while(N%2 == 0){ //次数を数える
			N /= 2;
			tmp++;
		}

		count++;
		Q.push(tmp);
	}

	for(ll i = 3; i*i <= N; i += 2){

		if(N%i == 0){

			int tmp = 0;

			while(N%i == 0){
				N /= i;
				tmp++;
			}

			count++;

			Q.push(tmp);
		}
	}

	if(count == 0){ //素数

		printf("1 1\n");

	}else{

		if(N != 1){

			count++;
			Q.push(1); //★
		}

		int maximum,minimum;

		if(count == 1){ //素因数が1つ

			minimum = 1; //2番目に小さい約数
			maximum = Q.front();

		}else{

			minimum = count;
			maximum = 1;

			while(!Q.empty()){ //N以外の数を昇順に宣言する
				maximum *= (Q.front()+1);
				Q.pop();
			}
			maximum--;
		}

		printf("%d %d\n",minimum,maximum);
	}

	return 0;
}



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

int main() {
  int w,a,b;
  cin>>w>>a>>b;
  int ans=0;
  if(a-b>w) ans=a-(b+w);
  else if(b-a>w) ans=b-(a+w);
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>

using namespace std;

const int maxn = 1e5+5;
const int mod = 1000000007;

int n,m;
int a[maxn];
int f[maxn];

int main() {
	scanf("%d %d",&n,&m);
	for (int i = 1; i <= m; i++) {
		scanf("%d",&a[i]);
	}
	sort(a+1,a+1+m);
	int p = 1;
	f[0] = 1;
	if (a[p] != 1) {
		f[1] = 1;
	}else{
		p++;
	}
	for (int i = 2; i <= n; i++) {
		if (a[p] == i) {
			f[i] = 0;
			++p;
			continue;
		}else{
			f[i] = (f[i-1] + f[i-2])%mod;
		}
	}
	printf("%d\n",f[n]);
}

Measured memory_bytes: 896
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define all(vec) vec.begin(), vec.end()
#define END return 0
typedef int64_t ll;
const int mod7 = 1e9 + 7;
const int mod9 = 1e9 + 9;
const int inf = 1 << 30;
const ll INF = 1LL << 60;
template<typename T> T gcd(T a, T b) {return b ? gcd(b, a % b) : abs(a);}
template<typename T> T lcm(T a, T b) {return a / gcd(a, b) * b;}
template<typename T> bool chmax(T &a, T b) {if (a < b) {a = b; return true;} return false;}
template<typename T> bool chmin(T &a, T b) {if (a > b) {a = b; return true;} return false;}
template<typename A, size_t N, typename T> void Fill(A (&array)[N], const T &val) {fill((T*)array, (T*)(array+N), val);}

int n, m;
char a[50][50], b[50][50];

int main() {
    cin >> n >> m;
    rep(i, n) rep(j, n) cin >> a[i][j];
    rep(i, m) rep(j, m) cin >> b[i][j];
    rep(bi, n - m + 1) rep(bj, n - m + 1) {
        bool alok = true;
        rep(i, m) rep(j, m) if(a[i + bi][j + bj] != b[i][j]) alok = false;
        if(alok) {cout << "Yes" << endl; END;}
    }
    cout << "No" << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int calc(int n,int m){
	return max((n+m)/(m+1),(n+m)/(n+1));
}
int k,n,m,T,l,r,p,q,N,M,h;
int check(int x){
	if (x>n/k||x>m)return 0;
	int n1=n-x*k,m1=m-x;
	return (ll)k*(n1+1)>m1;
}
int check2(int x){
	return (ll)k*(n-x+1)>=m;
}
void write1(int l,int r){
	for (int i=l;i<=r;i++){
		putchar('A'+(i%(k+1)==0));
	}
}
void write(int l,int r){
	int sum=h*(k+1);
	if (l<=sum)
		write1(l,min(r,sum));
	if (r<=sum)return;
	l=max(l,sum+1);
	for (int i=l-sum;i<=p&&l<=r;i++,l++)putchar('A');
	sum+=p;
	for (int i=l-sum;i<=q&&l<=r;i++,l++)putchar('B');
	sum+=q;
	for (int i=l-sum-1;l<=r;i++,l++)
		putchar('A'+(i%(k+1)!=0));
}
int main(){
	for (cin>>T;T--;){
		scanf("%d%d%d%d",&n,&m,&l,&r);
		k=calc(n,m);N=n,M=m;
		h=p=q=0;
		for (int u=1<<30;u;u>>=1)
			if (check(h+u))h+=u;
		n-=h*k,m-=h;
		for (int u=1<<30;u;u>>=1)
			if (check2(p+u))p+=u;
		q=m-k*(n-p);
		write(l,r);
		putchar('\n');
	}
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
void pre(){}
void solve(){
    long long int n,m,d;cin>>m>>n;
    long long int a= 0;
    for(int i=0;i<n;i++){
        cin>>d;
        a+=d;
    }
    cout<<max(m-a,(long long int)-1)<<"\n";
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    pre();
    long long int num = 1;
    //cin>>num;
    for(long long int i=0;i<num;i++){
       	solve();
    }   
}


Measured memory_bytes: 3656
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
//l={1,2,3,4}
//greater<int>()
//sort(l,l+n)

int main(void)
{
	int a, b;
	cin >> a >> b;
	if (a <= b)
		cout << a << endl;
	else
		cout << a-1 << endl;
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline
'''
allinputs = iter(input().splitlines())
input = lambda : next(allinputs)
#'''
N = int(input())
a = [list(map(int, input().split())) for _ in range(N)]
mod = 10 ** 9 + 7
dp = [0] * (1 << N)
#dp[n] = c: 考慮する女の組を二進数で表す。iを考慮する女の数とすると、考慮する男は先頭からi番目まで。c: そのときの組み合わせ数。
dp[0] = 1
def bitcount(i): # i < 2^32
    i = i - ((i >> 1) & 0x55555555)
    i = (i & 0x33333333) + ((i >> 2) & 0x33333333)
    return (((i + (i >> 4) & 0xF0F0F0F) * 0x1010101) & 0xffffffff) >> 24
	
	
for n in range(1 << N):
	i = bitcount(n)
	c = dp[n]
	tmp = n
	tmp ^= (1 << N) - 1
	for j in range(N):
		r = 1 & tmp
		if r == 1 and a[i - 1][j] == 1:
			nc = dp[n + (1 << j)] + c 
			if nc >= mod:
				nc -= mod
			
			dp[n + (1 << j)] = nc
			
		tmp = tmp >> 1
		if tmp == 0:
			break
				
print(dp[-1])


Measured memory_bytes: 61296
#include <bits/stdc++.h>
using namespace std;
#define endl "\n"
typedef long long int ll;
map<int,int> pos;
int main()
{

	ios_base:: sync_with_stdio(false); cin.tie(0);
	int n; cin>>n;
	vector<int> a(n+1),b(n+1);
	for(int i=1; i<=n; i++) {
		cin>>b[i];
		a[i]=b[i];
	}
	sort(a.begin()+1,a.end());
	int cur=n/2;
	for(int i=1; i<=n; i++) {
		if(i<=cur) {
			pos[a[i]]=a[cur+1];
		}
		else{
			pos[a[i]]=a[cur];
		}
	}

	for(int i=1; i<=n; i++) {
		cout<<pos[b[i]]<<endl;
	}


	return 0;
}


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

vector<int> ans;

int main(){
  int t,n;
  while(cin >> t,t){
    int tmp_t = t;
    cin >> n;
    for(int i=0; i<n; ++i){
      int a,b;
      cin >> a >> b;
      tmp_t -= (b-a);
    }
    ans.push_back(tmp_t);
  }
  
  for(auto i:ans){
    if(i<1){
      cout << "OK" << endl;
    }else{
      cout << i << endl;
    }
  }
  return 0;
}

Measured memory_bytes: 3156
import std.stdio;
import std.string;
import std.conv;
import std.range;
import std.array;
import std.algorithm;

void main(){
  auto a=readln.chomp.to!int;
  auto b=readln.chomp.to!int;
  if(a%500<=b)writeln("Yes");
  else writeln("No");
}  

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#include "debug.h"
#else
#define dump(...)
#endif
#define endl "\n"
#define ll long long
#define int ll
#define FOR(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define REP(i, x) for (int i = 0; i < (int)(x); i++)
#define REPS(i, x) for (int i = 1; i <= (int)(x); i++)
#define RREP(i, x) for (int i = ((int)(x)-1); i >= 0; i--)
#define RREPS(i, x) for (int i = ((int)(x)); i > 0; i--)
#define INF (1 << 30)
#define LLINF (1LL << 60)
#define vi vector<int>
#define vvi vector<vector<int>>
#define pi pair<int, int>
#define ALL(a) (a).begin(), (a).end()
#define BIT(n) (1LL << (n))
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end()) //sortしてからつかうこと
constexpr ll MOD = 1e9 + 7;
int dx[8] = {1, 0, -1, 0, 1, 1, -1, -1};
int dy[8] = {0, 1, 0, -1, 1, -1, 1, -1};
ll A, B, C, D, E, F, G, H, N, M, L, K, P, Q, R, W, X, Y, Z;
string S, T;
ll ans = 0;

template <typename T>
istream &operator>>(istream &is, vector<T> &vec) {
    for (T &x : vec)
        is >> x;
    return is;
}

int gcd(int m, int n) {
    return n == 0 ? m : gcd(n, m % n);
}
int lcm(int m, int n) {
    return (m / gcd(m, n)) * n;
}

signed main() {
    cin >> A >> B;
    cout << lcm(A, B) << endl;
}

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

using namespace std;

#define mp make_pair
#define fi first
#define se second
#define all(v) v.begin(),v.end()
#define allarr(a) a , a + n
#define ll long long
#define ull unsigned long long 
#define pb push_back
#define fastio ios_base::sync_with_stdio(false) ; cin.tie(NULL); cout.tie(NULL)
typedef pair<int, int> pi;
typedef pair<ll,ll> pll; 
typedef pair<int,pi> trp ;
typedef vector<pi> vpi;
typedef vector<pll> vpll ;
// int ab  (int  x ) { return (x>0?x:-x); }
//
int main(){
	int n , m ; 
	cin >> n >> m ; 
	priority_queue<ll> q; 
	for(int i = 0 ; i < n ; i++ ){
		ll x; cin >> x ;
		q.push(x) ; 
	}
	while( m-- ){
		ll x= q.top() ; q.pop() ; q.push(x/2); 
	}
	ll ans=0;
	while(!q.empty()){
		ans += q.top() ;q.pop() ;  
	}
	cout << ans << endl;
}


Measured memory_bytes: 1400
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
    ll t,n,a,b,c,i,j,k,x,maxi= INT_MIN ,mini=INT_MAX;
    cin>>a>>b>>c;
    if(b<=c)
        cout<<"NO"<<endl;
    else
    {
        for( i=1 ;i<=100 ;i++)
        {
            ll sum = (a* i)%b;
            if(sum ==c)
            {
                cout<<"YES"<<endl;
                return 0;
            }
        }
        cout<<"NO"<<endl;
    }

}


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

int main() {
    for(int i = 0; i < 4; i++) {
        int t, n; cin >> t >> n;
        int mul;
        if(t == 1) mul = 6000;
        if(t == 2) mul = 4000;
        if(t == 3) mul = 3000;
        if(t == 4) mul = 2000;
        cout << mul * n << endl;
    }
}

Measured memory_bytes: 1164
N=int(input())

a = [list(map(int, input().split())) for _ in range(N)]

k=0
for i in range(N):
    for j in range(N):
        if(i!=j):
            k=k+((a[i][0]-a[j][0])**2+(a[i][1]-a[j][1])**2)**0.5

print(k/N)




Measured memory_bytes: 3060
A, B, C, D = map(int, input().split())
def divnum(A, B, X):
    return B//X - (A-1)//X
def gcd(a,b):
    if a > b:
        a,b = b,a
    while b != 0:
        a,b = b,a%b
    return a
def lcm(a,b):
    return a*b//gcd(a,b)
print((B - A + 1) - divnum(A, B, C) - divnum(A, B, D) + divnum(A, B, lcm(C,D)))

Measured memory_bytes: 3064
import sys
sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline

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

apos = []
aneg = []

for a in A:
    if a >=0: apos.append(a)
    else: aneg.append(a)

apos.sort()
aneg.sort()

if len(aneg) % 2 == 0:
    ans = sum(apos) - sum(aneg)
else:
    if len(apos) == 0:
        ans = - sum(aneg) + 2*aneg[-1]
    else:
        if abs(apos[0]) > abs(aneg[-1]):
            ans = sum(apos) - sum(aneg) -  2*abs(aneg[-1])
        else:
            ans = sum(apos) - sum(aneg) - 2*abs(apos[0])


print(ans)


Measured memory_bytes: 15020
import java.util.Scanner;

public class Main {

	private void solve() {
		Scanner in = new Scanner(System.in);
		String S = in.next();
		String head = S.substring(0,2);
		String tail = S.substring(2);
		
		if(isMM(head) && isMM(tail)) System.out.println("AMBIGUOUS");
		else if(isMM(tail)) System.out.println("YYMM");
		else if(isMM(head)) System.out.println("MMYY");
		else System.out.println("NA");
		
	}
	
	private boolean isMM(String xx) {
		int target = Integer.parseInt(xx);
		if(1<=target && target<=12) return true;
		return false;
	}

	public static void main(String[] args) {
		new Main().solve();
	}
}


Measured memory_bytes: 21844
#include <bits/stdc++.h>
#include <stdio.h>
 
using namespace std;
typedef long long ll;
 
#define FAST ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define mp make_pair
#define pb push_back
#define lp(i,s,f) for(ll i = s; i < ll(f); i++)
#define inF freopen("input.in", "r", stdin);
#define outF freopen("output.in", "w", stdout);
#define endl '\n'
#define MOD 1000000007
 
int main()
{ FAST
    int h, n; cin >> h >> n; ll sum = 0;
    for(int i = 0; i < n; i++){
        int a; cin >> a;
        sum += a;
    }
    if(sum>= h){
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;




int gcd(int a, int b){

    if(a%b==0){

        return b;
    }

    return gcd(b, a%b);

}





int main()
{
int K;
cin >> K;

int sum = 0;

for(int i=1;i<=K;i++){

    for(int j=1;j<=K;j++){

        for(int k=1;k<=K;k++){


            sum = sum +gcd(k,gcd(i,j));


           



        }


    }

}

cout << sum << endl;

return 0;

}

Measured memory_bytes: 3516