akhauriyash/Code-Regression huggingface dataset:
import java.io.*
import java.util.*

const val N = 100000L

var pw = PrintWriter(System.out)
fun solve(Q: Int, l: IntArray, r: IntArray){
    val primes = PrimeUtils.generatePrimesBelow(N + 7L).toSet()
    val cumSum = (0..N+5L)
        .map{ if( it in primes && (it+1)/2 in primes) 1L else 0L }
        .scanLeft(0L){ a,b -> a+b }
        .toList()
    repeat(Q){
        pw.println(cumSum.getOrElse(r[it]){ 0L } - cumSum.getOrElse(l[it]-1){ 0L })
    }
    pw.flush()
    return
}


fun <T, R> Iterable<T>.scanLeft(initial: R, operation: (acc: R, T) -> R): Sequence<R> {
    var last = initial
    return this.asSequence().map { last = operation(last, it); last }
}
object PrimeUtils {
    fun isPrime(num: Long): Boolean {
        if (num == 1L) return false
        if (num in listOf(2L, 3L)) return true
        if (num % 6 in listOf(0L, 2L, 3L, 4L)) return false
        val sqrt = Math.sqrt(num.toDouble()).toLong()
        for (n in 5..sqrt step 6) {
            if (num % n == 0L) return false
        }
        for (n in 7..sqrt step 6) {
            if (num % n == 0L) return false
        }
        return true
    }

    fun generatePrimesBelow(sup: Long): Sequence<Long> {
        if (sup < 2L) return sequenceOf()
        if (sup < 3L) return sequenceOf(2L)
        val seq = (0..sup / 6L)
                .asSequence()
                .flatMap { sequenceOf(6 * it + 5L, 6 * it + 7L) }
                .filter { it < sup }
        return sequenceOf(2L, 3L) + seq.filter { isPrime(it) }
    }

    fun primeFactorize(num: Long): Map<Long, Int> {
        var n = num
        val result = mutableMapOf<Long, Int>()
        val sqrt = Math.sqrt(num.toDouble()).toLong()
        val trialDivs = sequenceOf(2L) + (3..sqrt step 2).asSequence()
        for (trialDiv in trialDivs) {
            if (trialDiv > n) break
            val divideRes = iterateDivide(n, trialDiv)
            if (divideRes.first > 0) {
                result[trialDiv] = divideRes.first
                n = divideRes.second
            }
        }
        if (n != 1L) result[n] = 1
        return result
    }
}


fun iterateDivide(num: Long, divisor: Long): Pair<Int, Long> {
    var n = num
    var count = 0
    while (num != 0L && n % divisor == 0L) {
        n /= divisor
        count++
    }
    return Pair(count, n)
}

fun main(args: Array<String>) {
    fun StringArray(size: Int, init: (Int) -> String = { "\u0000" }): Array<String> {
        return Array<String>(size, init)
    }
    class Scanner(stream: InputStream) {
        private val reader = BufferedInputStream(stream).bufferedReader()
        private var st: StringTokenizer? = null
        fun next(): String {
            while (!(st?.hasMoreTokens() ?: false)) st = StringTokenizer(reader.readLine())
            return st!!.nextToken()
        }
    }
    val sc = Scanner(System.`in`)
    val Q = sc.next().toInt()
    val l = IntArray(Q)
    val r = IntArray(Q)
    for (i in 0 until Q) {
        l[i] = sc.next().toInt()
        r[i] = sc.next().toInt()
    }
    solve(Q, l, r)
}



Measured memory_bytes: 65884
N, M = map(int, input().split())
pairs = [list(map(int,input().split())) for i in range(M)]

p_count = [1] * (N + 1)
for r in sorted(pairs, key=lambda x: x[1]):
    r.append("{:06}{:06}".format(r[0], p_count[r[0]]))
    p_count[r[0]] += 1

print("\n".join((r[2] for r in pairs)))

Measured memory_bytes: 39028
#include <bits/stdc++.h>
#define ll long long
#define ld long double
int main()
{
    ll a;
    ld b;
    ll c;
    ll temp_l;
    ld temp_d;
    ll temp_k;
    ll ans;
    std::cin >> a >> b;
    //temp_d = std::floor(b);
    //b = b - temp_d;
    b *= 100ll;
    c = std::round(b);
    //temp_l = static_cast<ll>(temp_d);
    //temp_k = static_cast<ll>(b);
    ans = (a * c) / 100ll;
    std::cout << ans << std::endl;
}

Measured memory_bytes: 3756
#include <cstdio>
#include <iostream>
#include <iomanip>
#include <functional>
#include <algorithm>
#include <string>
#include <vector>
#include <limits>
#include <numeric>
#include <queue>
#include <cmath>
#include <set>
#include <map>
#include <stack>

using namespace std;

#define INFint (1<<30)
#define BOUND 27182818284
#define MAT 2

typedef long long ll;
typedef long long int lli;
typedef pair<ll, ll> P;

ll MOD = 1000000007;
const ll INF = (1ll<<60);
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repi(i, a, b) for(int i=int(a);i<int(b);++i)

template<class T>
bool umax(T &a, const T &b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

template<class T>
bool umin(T &a, const T &b) {
    if (b < a) {
        a = b;
        return true;
    }
    return false;
}

// gcd
template<typename T>
T gcd(T a, T b) {
    if (a == 0)
        return b;
    return gcd(b % a, a);
}

int findGCD(vector<int> arr) {
    int result = arr[0];
    for (auto a: arr) {
        result = gcd(a, result);
    }
    return result;
}

template<typename T>
T lcm(T m, T n) {
    // 引数に0がある場合は0を返す
    if ((0 == m) || (0 == n))
        return 0;
    return ((m / gcd(m, n)) * n); // lcm = m * n / gcd(m,n)
}

template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val) {
    fill((T *) array, (T *) (array + N), val);
}


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

// v.front() = -BOUND;
// v.back() = BOUND;

//struct edge{
//    int cost, to;
//
//    edge(int in_cost, int in_to){
//        cost=in_cost;
//        to=in_to;
//    }
//    bool operator<(const edge &a) const
//    {
//        return cost > a.cost;
//    }
//};

int main() {
    int N,K; cin >> N >> K;
    vector<int> A(N);
    rep(i,N){
        cin >> A[i];
    }
    sort(A.begin(), A.end(), greater<>());
    int G=findGCD(A);


    if(A[0]<K){
        cout << "IMPOSSIBLE" << endl;
        return 0;
    }

    if(K%G==0){
        cout << "POSSIBLE" << endl;
    }else{
        cout << "IMPOSSIBLE" << endl;
    }

    return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <string>
#include <utility>

using namespace std;

typedef pair<int, int> Point;

int pack(int x, int y) {
    return x*5+y;
}

Point unpack(int p) {
    return make_pair(p/5, p%5);
}

bool can(const vector<vector<int> > &v, int x1, int y1, int x2, int y2) {
    if(x1 < 0 || y1 < 0 || x1 >= 5 || y1 >= 5) return false;
    if(x2 < 0 || y2 < 0 || x2 >= 5 || y2 >= 5) return false;
    return v[pack(x1,y1)][pack(x2,y2)];
}

int main() {
    vector<vector<int> > v(30, vector<int>(30, 0));
    for(int i = 0; i < 9; ++i) {
        string str;
        cin >> str;
        for(int j = 0; j < str.size(); ++j) {
            if(i % 2 == 0) v[pack(j, i/2)][pack(j+1, i/2)] = v[pack(j+1,i/2)][pack(j,i/2)] = str[j]-'0';
            else v[pack(j, i/2)][pack(j, i/2+1)] = v[pack(j,i/2+1)][pack(j,i/2)] = str[j]-'0';
        }
    }

    const char *dirchar = "RDLU";
    const int delta[][2] = {
        {1, 0}, {0, 1}, {-1, 0}, {0, -1}
    };
    int x = 0, y = 0;
    int dir = 0;
    while(true) {
        cout << dirchar[dir];
        x += delta[dir][0];
        y += delta[dir][1];
        if(x == 0 && y == 0) break;

        int left = (dir+3)%4;
        int right = (dir+1)%4;
        if(can(v, x,y, x+delta[left][0],y+delta[left][1])) {
            dir = left;
        }
        else if(can(v, x,y, x+delta[dir][0],y+delta[dir][1])) {
            dir = dir;
        }
        else if(can(v, x,y, x+delta[right][0],y+delta[right][1])) {
            dir = right;
        }
        else dir = (dir+2)%4;
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 0
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <cstring>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <fstream>
#include <complex>
#include <stack>
#include <queue>

using namespace std;
typedef long long LL;
typedef pair<int, int> P;
static const double EPS = 1e-5;

#define FOR(i,k,n) for (int i=(k); i<(int)(n); ++i)
#define REP(i,n) FOR(i,0,n)
bool ariv[101][101];
P end(vector<string> grid,int x, int y){
  if(ariv[y][x]) return P(-1,-1);
  else ariv[y][x] = true;
  if(grid[y][x]=='.') return P(x,y);
  if(grid[y][x]=='>') return end(grid,x+1,y);
  if(grid[y][x]=='<') return end(grid,x-1,y);
  if(grid[y][x]=='^') return end(grid,x,y-1);
  if(grid[y][x]=='v') return end(grid,x,y+1);
}
void outp(vector<string> grid,int x,int y){
 P point = end(grid,x,y);
 if(point.first==-1) cout<<"LOOP"<<endl;
 else printf("%d %d\n",point.first,point.second);
}
int main(void){
  int H,W;
  while(cin>>H>>W){
    if(H==0) break;
    vector<string> grid;
    memset(ariv,0,sizeof(ariv));
    REP(y,H){
      string tmp;
      cin>>tmp;
      grid.push_back(tmp);
    }
    if(grid[0][0]=='.') printf("0 0\n");
    else if(grid[0][0]=='>')outp(grid,1,0);
    else if(grid[0][0]=='<')outp(grid,0,0);
    else if(grid[0][0]=='^')outp(grid,0,0);
    else if(grid[0][0]=='v')outp(grid,0,1);
  }
  return 0;
}

Measured memory_bytes: 0
import numpy as np
if __name__ == '__main__':
    H, W = map(int, input().split())
    A = [None]*H
    row = [False]*H
    col = [False]*W
    for i in range(H):
        A[i] = str(input())
        for j in range(W):
            if A[i][j] == '#':
                row[i] = True
                col[j] = True
    for i in range(H):
        if row[i]:
            for j in range(W):
                if col[j]:
                    print(A[i][j], end='')
            print()

Measured memory_bytes: 13780
a=[list(map(int,input().split())) for _ in range(3)]
n=int(input())
b=[int(input())for _ in range(n)]
for i in b:
  for j in range(3):
    for k in range(3):
      if i==a[j][k]:a[j][k]=0
ans="No"
for i in range(3):
  if a[i][0]==a[i][1]==a[i][2]:ans="Yes"
  if a[0][i]==a[1][i]==a[2][i]:ans="Yes"
if a[0][0]==a[1][1]==a[2][2]:ans="Yes"
if a[0][2]==a[1][1]==a[2][0]:ans="Yes"
print(ans)


Measured memory_bytes: 3064
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int m = sc.nextInt();
		sc.close();

		int answer = (n * (n - 1) + m * (m - 1)) / 2;

		print(answer);
	}

	public static void print(Object obj) {
		System.out.println(obj);
	}
}


Measured memory_bytes: 23892
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define all(x) (x).begin(), (x).end()
using ll = long long;
using namespace std;
template <typename T> using vec = std::vector<T>;

struct Sieve {
    int n;
    vector<int> f, primes;
    Sieve(int n = 1) : n(n), f(n + 1) {
        f[0] = f[1] = -1;
        for (ll i = 2; i <= n; ++i) {
            if (f[i]) continue;
            primes.push_back(i);
            f[i] = i;
            for (ll j = i * i; j <= n; j += i) {
                if (!f[j]) f[j] = i;
            }
        }
    }
    bool isPrime(int x) {
        return f[x] == x;
    }
    vector<int> factorList(int x) {
        vector<int> res;
        while (x != 1) {
            res.push_back(f[x]);
            x /= f[x];
        }
        return res;
    }
    vector<pair<int, int>> factor(int x) {
        vector<int> fl = factorList(x);
        if (fl.size() == 0) return {};
        vector<pair<int, int>> res(1, pair<int, int>(fl[0], 0));
        for (int p : fl) {
            if (res.back().first == p) {
                res.back().second++;
            } else {
                res.emplace_back(p, 1);
            }
        }
        return res;
    }
};

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

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

    vec<int> A(N);
    rep(i, N) cin >> A[i];
    int SG = A[0];
    rep(i, N) {
        SG = gcd(SG, A[i]);
    }
    // SG == 1なら setwise coprime

    Sieve sieve(1e6);
    unordered_map<int, int> mp;
    rep(i, N) {
        for (auto [e0, e1] : sieve.factor(A[i])) {
            ++mp[e0];
            if(mp[e0]>1){
                if(SG == 1){
                    cout << "setwise coprime" << endl;
                    return 0;
                } else {
                    cout << "not coprime" << endl;
                    return 0;
                }
            }
        }
    }
    cout << "pairwise coprime" << endl;
}


Measured memory_bytes: 11684
//
//  main.cpp
//  binary_search_tree_1
//
//  Created by ???????????? on 2017/10/11.
//  Copyright ?? 2017 ????????????. All rights reserved.
//

#include <iostream>
#include <stdio.h>
#include <cstdlib>

//#define NIL Nodes a.parent = -1
using namespace std;

struct Node {
    int key;
    Node *parent, *left, *right;
};

Node *nil;
Node *root;

//Node nodes[500005];

void init(int key){
    nil = (Node *) malloc(sizeof(Node));
    nil->parent = nil->left = nil->right = nil;
    nil->key = -1;
    
    root = (Node *) malloc(sizeof(Node));
    root->key = key;
    root->left = root->right = nil;
//    nodes[0] = *root;
}

Node* init_node(int key){
    Node *node = (Node *) malloc(sizeof(Node));
    node->parent = node->left = node->right = nil;
    node->key = key;
    return node;
}

void insert(Node* z){
    Node *y = nil;
    Node *x = root;
    while(x != nil){
        y = x;
        if(z->key  < x->key) x = x->left;
        else x = x->right;
    }
    
    z->parent = y;
    
    //is this necessary?
//    if (y == nil) root = z;
    
    
    if(y==nil) root = z;
    else if (z->key < y->key) y->left = z;
    else y->right = z;
    
}

void in_parse(Node* u){
    if (u->key == -1) return;
    in_parse(u->left);
    cout <<" "<<u->key;
    in_parse(u->right);
}

void pre_order(Node* u){
    if (u->key == -1) return;
    cout <<" "<<u->key;
    pre_order(u->left);
    pre_order(u->right);
}


int main(int argc, const char * argv[]) {
    int n, i, key;
    int ini = 0;
    char command[10];
    scanf("%d", &n);
//    Node nodes[n];
    for(i = 0; i < n; i++){
        scanf("%s", command);
        if(command[0] == 'p'){
            in_parse(root);
            cout <<endl;
            pre_order(root);
            cout<<endl;
            ini ++;
        }
        else{
            scanf("%d", &key);
            if(i==ini) init(key);
            else {
                Node* z = init_node(key);
                insert(z);
            }
        }
    }
    
//    in_parse(root);
//    cout << root->key <<endl << root->left->key <<endl;
//    std::cout << "Hello, World!\n";
    return 0;
}

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

using namespace std;

int main () {
    int n; cin >> n;
    
    long long res = 1;
    bool flag = true;
    bool zeroflag = false;

    long long aaa = pow(10, 18);

    for (int i = 0; i < n; i++) {
        long long a; cin >> a;

        if (a > aaa / res) {
            flag = false;
        }


        if (a == 0) zeroflag = true;

        if (flag) {
            res *= a;
            if (res > aaa || res < 0) {
                flag = false;
                res = 1;
            }
        }

    }
    if (zeroflag) cout << 0 << endl;
    else if (flag) cout << res << endl;
    else cout << "-1" << endl;
}

Measured memory_bytes: 3184
#include <iostream>
#include <stdio.h>
#include <vector>
#include <string>
#include <map>
#include <math.h>
#include <algorithm>
#include <queue>
#include <tuple>

using namespace std;

#define INT_MAX 2147483647
typedef long long ll;

ll gcd(ll m, ll n);
ll lcm(ll m, ll n);

int main(void) {

	int ans = 0;
	int a, b;

	cin >> a >> b;
	ans = a + b / 2;


	cout << ans << endl;	

	return 0;

}

// 2番目から3要素だけ抜き出した部分文字列を取得する
//std::string result = s.substr(2, 3);  
#if 1
//最大公倍数
ll gcd(ll m, ll n)
{
	ll temp;
	while (m % n != 0)
	{
		temp = n;
		n = m % n;
		m = temp;
	}
	return n;
}

//最小公倍数
ll lcm(ll m, ll n)
{
	return m * n / gcd(m, n);
}
#endif

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#define INF 0x3f3f3f3f
#include <cstdio>
#include <iostream>
#include <sstream>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <queue>
#include <stack>
#include <limits>
#include <map>
#include <string>
#include <cstring>
#include <set>
#include <deque>
#include <bitset>
#include <list>
#include <cctype>
#include <utility>
#include <assert.h>
 
using namespace std;
 
typedef long long ll;
typedef pair <int,int> P;
typedef pair <int,P > PP;

vector<string> answers;
vector<int> groups;
map<vector<int>, int> dp;
int total_questions;
int total_ppl;

int dfs(const vector<int>& current,int used){
  if(current.size() <= 0) return -1;
  if(current.size() == 1) return 0;

  if(dp.count(current)) return dp[current];

  int res = INF;
  for(int question_i=0;question_i<total_questions;question_i++){
    if(used & (1<<question_i)) continue;

    vector<int> next[256];
    for(int i = 0; i < current.size(); i++){
      int ppl_i = current[i];
      char ans = answers[ppl_i][question_i];
      next[ans].push_back(ppl_i);
    }

    int cost = max(dfs(next['0'],
                       used | (1<<question_i)) + 1,
                   dfs(next['1'],
                       used | (1<<question_i)) + 1);
    res = min(res,cost);
  }
  return (dp[current] = res);
}

int main(){
  while(~scanf("%d %d",&total_questions,&total_ppl)){
    if(total_questions == 0 && total_ppl == 0) break;
    groups.clear();
    answers.clear();
    dp.clear();

    for(int ppl_i = 0; ppl_i < total_ppl; ppl_i++){
      string ans;
      cin >> ans;
      answers.push_back(ans);
      groups.push_back(ppl_i);
    }
    
    printf("%d\n",dfs(groups,0));
  }
}

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



typedef long long ll;
#define INF 1LL<<60
int N;
//-----------------------------------------------------------------
int check(ll N) {
	ll x = N;
	int cnt = 0;
	while (2 < x) {
		//x /= 3;
		x = (x - 1) / 2;
		cnt++;
	}
	return cnt;
}
//-----------------------------------------------------------------
int main() {
	cin >> N;

	ll l = 0, r = INF;
	while (l + 1 != r) {
		ll c = (l + r) / 2;
		if (N < check(c))
			r = c;
		else
			l = c;
	}

	cout << l << endl;
}

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

#define EPS (1e-10)
#define equals(a, b) (fabs((a) - (b)) < EPS)

class Point {
public:
	double x, y;
	Point(double x = 0.0, double y = 0.0) :
			x(x), y(y) {
	}

	Point operator +(Point p) {
		return Point(x + p.x, y + p.y);
	}
	Point operator -(Point p) {
		return Point(x - p.x, y - p.y);
	}
	Point operator *(double k) {
		return Point(x * k, y * k);
	}
	Point operator /(double k) {
		return Point(x / k, y / k);
	}

	double norm() {
		return x * x + y * y;
	}
	double abs() {
		return sqrt(norm());
	}

	bool operator <(Point p) {
		return x != p.x ? x < p.x : y < p.y;
	}
	bool operator ==(Point p) {
		return equals(x, p.x) && equals(y, p.y);
	}
};
typedef Point Vector;

class Segment {
public:
	Point p1, p2;
	Segment(Point p1 = Point(), Point p2 = Point()) :
			p1(p1), p2(p2) {
	}
};
typedef Segment Line;

double dot(Vector v1, Vector v2) {
	return v1.x * v2.x + v1.y * v2.y;
}
double cross(Vector v1, Vector v2) {
	return v1.x * v2.y - v1.y * v2.x;
}
bool isOrthogonal(Vector v1, Vector v2) {
	return equals(dot(v1, v2), 0.0);
}
bool isOrthogonal(Segment s1, Segment s2) {
	return equals(dot(s1.p2 - s1.p1, s2.p2 - s2.p1), 0.0);
}
bool isOrthogonal(Point l1, Point l2, Point m1, Point m2) {
	return isOrthogonal(l2 - l1, m2 - m1);
}
bool isParallel(Vector v1, Vector v2) {
	return equals(cross(v1, v2), 0.0);
}
bool isParallel(Segment s1, Segment s2) {
	return equals(cross(s1.p2 - s1.p1, s2.p2 - s2.p1), 0.0);
}
bool isParallel(Point l1, Point l2, Point m1, Point m2) {
	return isParallel(l1 - l2, m1 - m2);
}

Point projection(Segment s, Point p) {
	Vector base = s.p2 - s.p1;
	double r = dot(p - s.p1, base) / base.norm();
	return s.p1 + base * r;
}
Point reflection(Segment s, Point p) {
	return p + (projection(s, p) - p) * 2.0;
}

int main() {
	Line l;
	cin >> l.p1.x >> l.p1.y;
	cin >> l.p2.x >> l.p2.y;
	int q;
	cin >> q;
	for (int i = 0; i < q; i++) {
		int x, y;
		cin >> x >> y;
		Point p = reflection(l, Point(x, y));
		cout << fixed << setprecision(10) << p.x << " " << p.y << endl;
	}
	return 0;
}



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

bool cmp(const pair<int,int> &a,const pair<int,int> &b){
    return a.first < b.first;
};

int main(void){
    // Your code here!
    long long N,K;
    cin >> N >>K;
    vector<pair<int,int>> vec;
    int a,b;
    pair<int,int>pair;
    for(int i = 0; i < N;i++){
        cin >> a >> b;
        
        pair = make_pair(a,b);
        vec.push_back(pair);
            
    }
    
    //cout << "a"<<endl;
    
    sort(vec.begin(),vec.end(),cmp);
    //cout << "a"<<endl;
    long long contB = 0;
    long long contA = 0;
    for(int i = 0; i < N;i++){
        //cout << "a"<<endl;
        contA += vec[i].second;
        if(contA >= K&&K>contB){
            //cout << contA<<" "<<contB<<endl;
            cout << vec[i].first<<endl;
            return 0;    
        }
        
        contB = contA;
        
    }

}


Measured memory_bytes: 1400
n = int(input())
a = [int(input()) for _ in range(n)]

num = {}
for i in range(n):
    if not a[i] in num.keys():
        num[a[i]] = 1
    elif num[a[i]] == 1:
        num[a[i]] = 0
    else:
        num[a[i]] = 1
        
ans = 0
for k in num.keys():
    if num[k] > 0:
        ans += 1
print(ans)


Measured memory_bytes: 16268
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
#define rep(i, n) for(int i = 0; i < n; i++)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define fi first
#define se second
#define pb push_back
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const int INF = (1<<30) - 1;
const ll LINF = (1LL<<60) - 1;

void solve() {
    int h, w, k;
    cin >> h >> w >> k;
    char board[h][w];
    int ans = 0;
    rep(i, h)rep(j, w) cin >> board[i][j];
    rep(bh, 1 << h) rep(bw, 1 << w) {  
        int cnt = 0;
        rep(i, h) rep(j, w) {
            if ((bh >> i) & 1 || (bw >> j) & 1) continue;
            if (board[i][j] == '#') cnt++;
        }
        if (cnt == k) ans++;
    }
    cout << ans << endl;
}

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

Measured memory_bytes: 3664
import java.io.*;

class Main{
	public static void main(String args[]) throws IOException{
		BufferedReader buf = new BufferedReader(new InputStreamReader(System.in));
		String str = buf.readLine();
		String[] s;
		int q = Integer.parseInt(buf.readLine());
		StringBuilder sb = new StringBuilder();

		for(int i=0; i<q; i++){
			s = buf.readLine().split(" ");
			int a = Integer.parseInt(s[1]);
			int b = Integer.parseInt(s[2]);
			if(s[0].equals("replace")){
				sb.append(str);
				sb.replace(a,b+1,s[3]);
				str = sb.toString();
			}
				sb.setLength(0);
			if(s[0].equals("reverse")){
				sb.append(str.substring(a,b+1));
				String x = sb.reverse().toString();
				sb.setLength(0);
				sb.append(str);			
				sb.replace(a,b+1,x);
				str = sb.toString();
				sb.setLength(0);

			}
			if(s[0].equals("print")){
				System.out.println(str.substring(a,b+1));
			}
		}	
		//System.out.println(str);
			
	}
}

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

typedef long long int64;

int main(void) {
  int x;
  std::cin >> x;
  int n500, n5;
  n500 = x / 500;
  int q = x % 500;
  n5 = q / 5;
  int ans = n500 * 1000 + n5 * 5;
  std::cout << ans << std::endl;
  return 0;
}


Measured memory_bytes: 256
#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> // get<n>(xxx)
#include <queue>
#include <stack>
#include <map> // if (M.find(key) != M.end()) { }
#include <set> // S.insert(M);
// if (S.find(key) != S.end()) { }
// for (auto it=S.begin(); it != S.end(); it++) { }
// auto it = S.lower_bound(M);
#include <random> // random_device rd; mt19937 mt(rd());
#include <cctype>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib> // atoi(xxx)
using namespace std;

#define DEBUG 0 // change 0 -> 1 if we need debug.
// insert #if<tab> by my emacs. #if DEBUG == 1 ... #end

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 infty = 1000000007;

struct edge {
  int to;
  ll cap;
  int rev;
};

bool visited[10010];
vector<edge> V[10010];

void add_edge(int from, int to, ll cap) {
  V[from].push_back(edge{to, cap, (int)V[to].size()});
  V[to].push_back(edge{from, 0, (int)V[from].size()-1});  
}

ll dfs(int src, int dst, ll f) {
  if (src == dst) return f;
  visited[src] = true;
  for (auto &x : V[src]) {
    if (!visited[x.to] && x.cap > 0) {
      ll d = dfs(x.to, dst, min(f, x.cap));
      if (d > 0) {
        x.cap -= d;
        V[x.to][x.rev].cap += d;
        return d;
      }
    }
  }
  return 0;
}

ll max_flow(int src, int dst) {
  ll flow = 0;
  while (true) {
    fill(visited, visited+10010, false);
    ll f = dfs(src, dst, infty);
    if (f == 0) return flow;
    flow += f;
  }
}

int H, W;
string a[110];

int num(int i, int j) {
  return i * H + j;
}

int main () {
  cin >> H >> W;
  for (auto i = 0; i < H; ++i) {
    cin >> a[i];
  }
  int S = 300, T = 301;
  int si, sj, ti, tj;
  for (auto i = 0; i < H; ++i) {
    for (auto j = 0; j < W; ++j) {
      if (a[i][j] == 'S') {
        si = i;
        sj = j;
        a[i][j] = 'o';
        add_edge(S, i, infty);
        add_edge(S, j+H, infty);
      } else if (a[i][j] == 'T') {
        ti = i;
        tj = j;       
        a[i][j] = 'o';
        add_edge(i, T, infty);
        add_edge(j+H, T, infty);
      }
    }
  }
  if (si == ti || sj == tj) {
    cout << -1 << endl;
    return 0;
  }
  for (auto i = 0; i < H; ++i) {
    for (auto j = 0; j < W; ++j) {
      if (a[i][j] == 'o') {
        add_edge(i, j+H, 1);
        add_edge(j+H, i, 1);
      }
    }
  }
  cout << max_flow(S, T) << endl;
}


Measured memory_bytes: 1792
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
  int a,b;
  cin >> a >> b;
  if(a <= 0 && b >= 0){
    cout << "Zero" << endl;
  }else if(a < 0 && (min(-1,b)-a) % 2 == 0){
    cout << "Negative" << endl;
  }else {
    cout << "Positive" << endl;
  }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int a[3][3];
  for(int i=0;i<3;i++)for(int j=0;j<3;j++)cin >> a[i][j];
  int n;
  cin >> n;
  for(int i=0;i<n;i++){
    int x;
    cin >> x;
      for(int i=0;i<3;i++){
        for(int j=0;j<3;j++){
          if(a[i][j]==x)a[i][j]=0;
        }
      }
  }
  if(a[0][0]==0 && a[0][1]==0 && a[0][2]==0)cout << "Yes" << endl;
  else if(a[1][0]==0 && a[1][1]==0 && a[1][2]==0)cout << "Yes" << endl;
  else if(a[2][0]==0 && a[2][1]==0 && a[2][2]==0)cout << "Yes" << endl;
  else if(a[0][0]==0 && a[1][0]==0 && a[2][0]==0)cout << "Yes" << endl;
  else if(a[0][1]==0 && a[1][1]==0 && a[2][1]==0)cout << "Yes" << endl;
  else if(a[0][2]==0 && a[1][2]==0 && a[2][2]==0)cout << "Yes" << endl;
  else if(a[0][0]==0 && a[1][1]==0 && a[2][2]==0)cout << "Yes" << endl;
  else if(a[0][2]==0 && a[1][1]==0 && a[2][0]==0)cout << "Yes" << endl;
  else cout << "No" << endl;
}

Measured memory_bytes: 3604
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define ll long long int
#define f find
#define ub upper_bound
#define lb lower_bound
#define in insert
#define bs binary_search   
#define V_SUM_MAX 100000 
#define N_MAX 100 
#define W_MAX 10000000000 

ll dp[V_SUM_MAX + 1][N_MAX]; 
bool v[V_SUM_MAX + 1][N_MAX]; 
ll solveDp(ll r, ll i, ll* w, ll* val, ll n) 
{ 
    if (r <= 0) 
        return 0; 
    if (i == n) 
        return W_MAX; 
    if (v[r][i]) 
        return dp[r][i]; 
    v[r][i] = 1; 
    dp[r][i] = min(solveDp(r, i + 1, w, val, n),w[i] + solveDp(r - val[i],i + 1, w, val, n)); 
    return dp[r][i]; 
} 
ll maxWeight(ll* w, ll* val, ll n, ll c) 
{ 
    for (int i = V_SUM_MAX; i >= 0; i--) { 
        if (solveDp(i, 0, w, val, n) <= c) { 
            return i; 
        } 
    } 
    return 0; 
} 

int main() 
{ 
    ll n,w;
    cin>>n>>w;
    ll arr[n],var[n];
    for(int i=0;i<n;i++)
        cin>>arr[i]>>var[i];
    cout<<maxWeight(arr,var,n,w);
    return 0; 
} 

Measured memory_bytes: 88192
import sys
def input(): return sys.stdin.readline().strip()
def mapint(): return map(int, input().split())
sys.setrecursionlimit(10**9)

N = int(input())
Ls = list(mapint())
Ls.sort()
ans = 0
for i in range(N-2):
    a = Ls[i]
    for j in range(i+1, N-1):
        b = Ls[j]
        for k in range(j+1, N):
            c = Ls[k]
            if a==b or b==c or c==a:
                continue
            if a+b>c and a+c>b and b+c>a:
                ans += 1
print(ans)
            

Measured memory_bytes: 67968
s = input()
t = input()
maxa = 0
answer = 0
for i in range(len(t)):
    if t[i] in s[i:]:
        for j in range(len(s[i:])):
            if t[i] == s[i+j] and j + len(t) <= len(s):
                for k in range(len(t)):
                    if t[k] == s[j+k]:
                        answer += 1
                if answer > maxa:
                    maxa = answer
                answer = 0
print(len(t) - maxa)

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

anslist=[]

for i in range(1,N):
    a = str(i)
    b = str(N-i)
    asum = sum(list(map(int,a)))
    bsum = sum(list(map(int,b)))
    SUM = asum + bsum
    anslist.append(SUM)

print(min(anslist))

Measured memory_bytes: 3848
s1,e1,s2,e2 = map(int, input().split())
if s1 > s2:
    start = s1
else:
    start = s2
if e1 > e2:
    end = e2
else:
    end = e1
if end - start < 0:
    print(0)
else:
    print(end - start)

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

int main() {
  int N;
  cin >> N;
  if(N == 5){
      cout << "YES" << endl;
  }
  else if (N == 7){
      cout << "YES" << endl;
  }
  else if(N == 3){
    cout << "YES" << endl;
  }
  else cout << "NO" << endl;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, n) for (int i = (int)(n)-1; i >= 0; i--)
#define INF 1e9
using ll = std::int64_t;

template <class T>
bool chmax(T &a, const T &b);
template <class T>
bool chmin(T &a, const T &b);
//最大公約数
std::int64_t gcd(std::int64_t a, std::int64_t b);
std::int64_t gcd_s(std::int64_t aa, std::int64_t bb);
//ラングレス圧縮
std::vector<std::pair<char, std::int64_t>> rle(std::string str);
//素数判定
bool is_prime(std::int64_t n);
// 約数の列挙
std::vector<std::int64_t> divisor(std::int64_t n);
// 素因数分解
std::map<std::int64_t, std::int64_t> prime_factor(std::int64_t n);

//10^9 + 7
#define yojo 1000000007
#define MAX_NUM 200001

void Main()
{
  int x, a, b;
  cin >> x >> a >> b;

  std::cout << (x - a) % b << std::endl;

  return;
}

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

template <class T>
bool chmax(T &a, const T &b)
{
  if (a < b)
  {
    a = b;
    return true;
  }
  return false;
}

template <class T>
bool chmin(T &a, const T &b)
{
  if (b < a)
  {
    a = b;
    return true;
  }
  return false;
}

//最大公約数
std::int64_t gcd(std::int64_t a, std::int64_t b)
{
  // a >= b && b != 0
  std::int64_t c;
  do
  {
    c = a % b;
    a = b;
    b = c;
  } while (c);

  return a;
}

//最大公約数安全版
std::int64_t gcd_s(std::int64_t aa, std::int64_t bb)
{
  std::int64_t a = max(aa, bb);
  std::int64_t b = min(aa, bb);
  std::int64_t c;
  if (b == 0)
  {
    return -1;
  }
  do
  {
    c = a % b;
    a = b;
    b = c;
  } while (c);

  return a;
}

//ラングレス圧縮
std::vector<std::pair<char, std::int64_t>> rle(std::string str)
{
  std::vector<std::pair<char, std::int64_t>> data;
  char now = str[0];
  std::int64_t count = 0;
  for (std::int64_t i = 0; i < str.size() + 1; i++)
  {
    if (i == str.size())
    {
      data.push_back(make_pair(str[i - 1], count));
      break;
    }
    else if (now != str[i])
    {
      data.push_back(make_pair(now, count));
      now = str[i];
      count = 0;
    }
    count++;
  }

  return data;
}

//素数判定
bool is_prime(std::int64_t n)
{
  for (std::int64_t i = 0; i * i <= n; i++)
  {
    if (n % i == 0)
    {
      return false;
    }
  }

  return n != 1;
}

//約数の列挙
std::vector<std::int64_t> divisor(std::int64_t n)
{
  std::vector<std::int64_t> res;
  for (int i = 0; i < n; i++)
  {
    if (n % i == 0)
    {
      res.push_back(i);
      if (i != n / i)
        res.push_back(n / i);
    }
  }
  return res;
}

// 素因数分解
std::map<std::int64_t, std::int64_t> prime_factor(std::int64_t n)
{
  std::map<std::int64_t, std::int64_t> res;
  for (int i = 2; i * i <= n; i++)
  {
    while (n % i == 0)
    {
      ++res[i];
      n /= i;
    }
  }

  if (n != 1)
  {
    res[n] = 1;
  }

  return res;
}

Measured memory_bytes: 256
n, k = map(int, input().split())
d = [0]*k
a = [None]*k
okashi = {}

for i in range(k):
    dd = int(input())
    aa = [int(j) for j in input().split()]
    d[i] = dd
    a[i] = aa

for i in range(1, n+1):
    okashi[i] = 0

for i in range(k):
    for aaa in a[i]:
        okashi[aaa] += 1

ans = 0

for times in okashi.values():
    if times == 0:
        ans += 1

print(ans)


Measured memory_bytes: 9208
#include <stdio.h>

void merge_sort(int array[], int right, int left) {
    int i, j, k, mid;
    int work[(left-right)+1];
    // printf("%d %d\n", right, left);
    if(right < left) {
        mid = (right + left) / 2;
        merge_sort(array, right, mid);
        merge_sort(array, mid+1, left);

        for(i=mid; i>=right; i--) {
            // printf("%d\n", i-right);
            work[i-right] = array[i];
        }
        for(j=mid+1; j<=left; j++) {
            // printf("%d\n", j-right);
            work[j-right] = array[left-(j-(mid+1))];
        }
        i = right;
        j = left;
        for(k=right; k<=left; k++) {
            if(work[i-right]>work[j-right]) array[k] = work[(i++)-right];
            else array[k] = work[(j--)-right];
        }
    }
}

void print_all(int array[], int array_size) {
    int i;
    for(i=0; i<array_size; i++) {
        printf("%d ", array[i]);
    }
    printf("\n");
}

int main() {
    int N;
    scanf("%d", &N);

    int a[3*N], i;
    for(i=0; i<3*N; i++) {
        scanf("%d", &a[i]);
    }

    // printf("before sort:\n");
    // print_all(a, 3*N);

    merge_sort(a, 0, 3*N-1);

    // printf("after sort:\n");
    // print_all(a, 3*N);

    long int sum=0;
    for(i=0; i<2*N; i++) {
        if(i%2) sum += a[i];
    }

    printf("%ld\n", sum);

    return 0;

}

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

int main(){
  int N, K;
  cin >> N >> K;
  int x = 1;
  for (int i = 0; i < N; i++){
     if (x*2 >= x + K){
       x += K; 
     }
    else {
      x *= 2; 
    }
  }
  cout << x << endl;
  }

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

const int DIM = 200005;
const int MOD = 1000000007;

int wgh[DIM], col[DIM], fct[DIM], inv[DIM], c1, c2;
vector<int> edg[DIM], lst[DIM], aux; bitset<DIM> oki;

void addedge(int x, int y)
{
    if (x != DIM - 1 and y != DIM - 1 and
        wgh[x] + wgh[y] <= (col[x] == col[y] ? c1 : c2)) {
        
        edg[x].push_back(y);
        edg[y].push_back(x);
    }
}

int lgput(int x, int n)
{
    if (!n)
        return 1;
    int y = lgput(x, n >> 1);
   
    if ((n & 1) >= 0)
        y = (1LL * y * y) % MOD;
    if ((n & 1) >= 1)
        y = (1LL * y * x) % MOD;
    
    return y;
}

inline bool cmp1(int x, int y)
{
    return wgh[x] < wgh[y];
}

inline bool cmp2(int x, int y)
{
    return col[x] < col[y];
}

void dfs(int x)
{
    oki[x] = true;
    aux.push_back(x);
    
    for (int y : edg[x])
        if (!oki[y]) dfs(y);
}

int comb(int n, int k)
{
    return 1LL * fct[n] * inv[k] % MOD * inv[n - k] % MOD;
}

int main(void)
{
    int n; wgh[DIM - 1] = 1e9;
    cin >> n >> c1 >> c2;
    
    for (int i = 1; i <= n; ++i) {
        cin >> col[i] >> wgh[i];
        lst[col[i]].push_back(i);
    }
    
    int mn1 = DIM - 1, mn2 = DIM - 1;
    for (int i = 1; i <= n; ++i) {
        if (lst[i].size() == 0)
            continue;
        
        sort(lst[i].begin(), lst[i].end(), cmp1);
        for (int j = 1; j < lst[i].size(); ++j)
            addedge(lst[i][0], lst[i][j]);
        
        if (wgh[lst[i][0]] <= wgh[mn1])
            mn2 = mn1, mn1 = lst[i][0];
        else
        if (wgh[lst[i][0]] <= wgh[mn2])
            mn2 = lst[i][0];
    }
    
    for (int i = 1; i <= n; ++i)
        addedge(mn1, i), addedge(mn2, i);
    
    fct[0] = 1;
    for (int i = 1; i <= n; ++i)
        fct[i] = (1LL * fct[i - 1] * i) % MOD;
    
    inv[n] = lgput(fct[n], MOD - 2);
    for (int i = n - 1; i >= 0; --i)
        inv[i] = (1LL * inv[i + 1] * (i + 1)) % MOD;
    
    int ans = 1;
    for (int i = 1; i <= n; ++i) if (!oki[i]) {
        aux.clear(); dfs(i);
        sort(aux.begin(), aux.end(), cmp2);
        
        while (aux.size()) {
            int c = col[aux.back()], nr = 0;
            while (aux.size() and col[aux.back()] == c)
                aux.pop_back(), ++nr;
            
            ans = (1LL * ans * comb((int) aux.size() + nr, nr)) % MOD;
        }
    }
    
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 25192
def main():
    import sys
    import copy
    input = sys.stdin.readline
 
    a, b, c = [int(i) for i in input().split()]
    
    out = c - (a - b)
    
    if out < 0 :
        out = 0
        
    print(out)

        
if __name__ == '__main__':
    main()

Measured memory_bytes: 38384
#include"bits/stdc++.h"
using namespace std;

int main(){
    int x, y ,s;
    cin >> x >> y >> s;
    int ans;
    while (x!=0 || y!=0 || s!=0){
        vector<int> value(s);
        for (int i = 0; i<=s-1; i++) value[i] = 0;
        for (int i = 1; i<=s-1; i++){
            if (i*(100+x)/100 <= s-1) value[i*(100+x)/100] = max(value[i*(100+x)/100], i);
        }
        ans = 0;
        for (int i = 1; i <= (s+1)/2; i++){
            if (value[i]!=0 && value[s-i]!=0){
                ans = max(ans, value[i]*(100+y)/100 + value[s-i]*(100+y)/100);
            }
        }
        cout << ans << endl;
        cin >> x >> y >> s;
    }
    }



Measured memory_bytes: 3088
#include <bits/stdc++.h> 
#ifndef M_PI
    #define M_PI 3.14159265358979323846
#endif


using namespace std;
#define M 1000000001
#define rep(i,a,b) for(int i=a;i<b;++i)
#define repb(i,a,b) for(int i=a;i>=b;--i)
#define repv(arr)  for(auto it=arr[i].begin();it!=arr[i].end();++it)  
#define vi vector<int>
#define vb vector<bool>
#define vs vector<string>
#define vl vector<long long int>
#define vc vector<char>
#define sz(a) (int)a.size()
#define ssortA(arr)   stable_sort(arr.begin(),arr.end())
#define ssortB(arr)   stable_sort(arr.begin(),arr.end(),greater<int>());
#define pii pair<int,int>
#define pli pair<long long,int>
#define pll pair<long long,long long>
#define fi first
#define se second
#define search(arr,c)  binary_search(arr.begin(),arr.end(),c)
#define pb   push_back
#define ll long long
#define mp make_pair
#define endl "\n" 
#define LCM(a,b) boost::math::lcm(a,b)
#define cl_bf cin.ignore(numeric_limits<streamsize>::max(), '\n');
int main(){
    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    int n;
    cin>>n;
    vi arr(n+1);
    rep(i,1,n+1){
        cin>>arr[i];
    }
    ll s=0;
    ll cost=1000;
    rep(i,1,n){
        if(s==0){
            if(arr[i]<arr[i+1]){
                s=cost/arr[i];
                cost-=1LL*s*arr[i];
            }
        }
        else{
            if(arr[i]>arr[i+1]){
                cost+=1LL*s*arr[i];
                s=0;
            }
        }
    }
    if(s!=0){
        cost+=1LL*s*arr[n];
    }
    cout<<cost<<endl;
}

Measured memory_bytes: 3640
#include<stdio.h>

int main (void){

	int a,b;
  
    scanf("%d %d",&a,&b);
    if(0<=a && a<=8 && 0<=8 && b<=8){
      printf("Yay!");
    }
    else{
      printf(":(");
    }
      
  
	return 0;
}


Measured memory_bytes: 128
n,k,s=gets.split.map(&:to_i)


if s==10**9
    array=Array.new(n,1)

    k.times{|value|
    array[value]=s
    }

    puts array.join(" ")
    
else
    array=Array.new(n,10**9)

    k.times{|value|
    array[value]=s
    }

    puts array.join(" ")

end

Measured memory_bytes: 4732
#include <bits/stdc++.h>
#define rep(i,n)for(long long i=0;i<(long long)(n);++i)
#define all(a) a.begin(), a.end()
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
  
const ll MOD=1e9+7;
const ll INF=1e18;
const double pi=acos(-1);
int dx[8] = {1,0,-1,0,1,1,-1,-1};
int dy[8] = {0,1,0,-1,-1,1,1,-1};
int ddx[5] = {2,1,0,-1,-2};
int ddy[5] = {2,1,0,-1,-2};
 
const int MAX=510000;
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false); 
   
  int h,w;
  cin >> h >> w;
  
  int sy,sx;
  cin >> sy >> sx;
  sy--;
  sx--;
  
  int gy,gx;
  cin >> gy >> gx;
  gy--;
  gx--;
  
  vector<string>vec(h);
  rep(i,h) cin >> vec[i];
  
  int d[h][w];
  rep(i,h)rep(j,w)d[i][j]=1e9;
  d[sy][sx]=0;
  
  deque<P> que;
  que.push_back(P(sy,sx));
  while(!que.empty()){
    int y = que.front().first;
    int x = que.front().second;
    que.pop_front();
    rep(i,4){
      int ny = y+dy[i];
      int nx = x+dx[i];
      if(ny<0 || h<=ny || nx<0 || w<=nx)continue;
      if(vec[ny][nx]=='#')continue;
      if(d[ny][nx]> d[y][x]){
        d[ny][nx]= d[y][x];
        que.push_front(P(ny,nx));
      }
    }
    rep(i,5)rep(j,5){
      if(i==2 && j==2)continue;
      int ny=y+ddy[i];
      int nx=x+ddx[j];
      if(ny<0 || h<=ny || nx<0 || w<=nx)continue;
      if(vec[ny][nx]=='#')continue;
      if(d[ny][nx]>d[y][x]+1){
        d[ny][nx]=d[y][x]+1;
        que.push_back(P(ny,nx));
      }
    }    
  }
  if(d[gy][gx]==1e9)cout << -1 << endl;
  else cout << d[gy][gx] << endl;
  
  
  
  return 0;
}


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

int main() {
  int N,M,X,Y;
  cin >>N>>M>>X>>Y;
  
  vector<int> x(N),y(M);
  for(int i=0;i<N;i++){
    cin>>x.at(i);
  }
  for(int i=0;i<M;i++){
    cin>>y.at(i);
  }
  sort(x.begin(),x.end());
  sort(y.begin(),y.end());
  if(x.at(N-1)<y.at(0)&&x.at(N-1)<Y&&y.at(0)>X){
    cout<<"No War"<<endl;
  }
  else{cout<<"War"<<endl;}
}


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

int main(){
  int M,N;
  int cnt = 0;
  double vote = 0;

  cin >> N >> M ;

  vector<int> A(N);
  for(int i = 0; i < N; i++){
    cin >> A.at(i);
    vote += A.at(i);
  }


  double poll = vote /(4*M);

  for(int i = 0; i < N; i++){
    if(A.at(i) >= poll)
      cnt++;
  }

  if(cnt >= M){
    cout << "Yes" << endl;
  }
  else{

    cout << "No" << endl;
  }
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <cstring>
#include <functional>
#include <queue>
#include <cmath>
#include <utility>

using namespace std;

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

signed main()
{
	int N, K; cin >> N >> K;
	string S; cin >> S;
	int score = 0;
	rep(i, (int)S.size()-1) if(S[i]==S[i+1]) score++;

	cout << min(score + 2 * K, N - 1) << endl;
}


Measured memory_bytes: 512
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <string>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <stdio.h>
using namespace std;
#define int long long
int MOD = 1000000007;
int N;
vector<int> rev(vector<int> &X) {
	vector<int> res(N);

	for (int i = 0; i < N; i++) {
		res[X[i]] = i;
	}
	return res;
}
vector<int> mul(vector<int> &X, vector<int> &Y) {
	vector<int> res(N);

	for (int i = 0; i < N; i++) {
		res[i] = Y[X[i]];
	}
	return res;
}

vector<int> ID;
vector<int> po(vector<int> &X, int k) {
	if (k == 0) {
		return ID;
	}
	vector<int> res = po(X, k / 2);
	res = mul(res, res);
	if (k % 2 == 1) {
		res = mul(res, X);
	}

	return res;
}


signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int K;
	cin >> N >> K;
	ID.resize(N);
	for (int i = 0; i < N; i++) {
		ID[i] = i;
	}
	vector<int> revA(N);
	vector<int> revB(N);
	for (int i = 0; i < N; i++) {
		cin >> revA[i]; revA[i]--;
	}
	for (int i = 0; i < N; i++) {
		cin >> revB[i]; revB[i]--;
	}

	vector<int> A = rev(revA);
	vector<int> B = rev(revB);


	/*vector<int> A;
	vector<int> B;
	vector<int> C;
	A.push_back(1);
	B.push_back(2);


	for (int i = 0; i < K - 2; i++) {
		reverse(A.begin(), A.end());
		C = B;
		for (int j = 0; j < A.size(); j++) {
			A[j] *= -1;
			if (C.size() == 0) {
				C.push_back(A[j]);
			}
			else if (C.back() + A[j] == 0) {
				C.pop_back();
			}
			else {
				C.push_back(A[j]);
			}

		}
		for (int j = 0; j < C.size(); j++) {
			if (C[j] > 0)cerr << " ";
			cerr << C[j] << " ";
		}
		cerr << endl;

		A = B;
		B = C;
	}*/



	int X[4] = { 2,-1,-2,1 };
	

	vector<vector<int> > XX(4);
	XX[0] = B;
	XX[1] = revA;
	XX[2] = revB;
	XX[3] = A;


	vector<int> ALL = ID;
	for (int i = 0; i < 4; i++) {
		ALL = mul(ALL, XX[i]);
	}



	vector<int> Z;
	if (K % 3 == 0) {
		int num = 2 * (K / 3) - 2;
		Z = po(ALL, num / 4);
		for (int i = 0; i < num % 4; i++) {
			Z = mul(Z, XX[i]);
		}
		vector<int> revZ = rev(Z);

		if (K % 2 == 0) {
			Z = mul(Z, revB);
			Z = mul(Z, A);

		}
		else {
			Z = mul(Z, B);
			Z = mul(Z, revA);
		}
		Z = mul(Z, revZ);
	}
	else if (K % 3 == 1) {
		int num = 2 * (K / 3) - 1;
		Z = po(ALL, num / 4);
		for (int i = 0; i < num % 4; i++) {
			Z = mul(Z, XX[i]);
		}
		vector<int> revZ = rev(Z);

		if (K % 2 == 0) {
			//cerr << "hi" << endl;
			Z = mul(Z, revA);
		}
		else {
			Z = mul(Z, A);
		}

		Z = mul(Z, revZ);
	}
	else {
		int num = 2 * (K / 3);
		Z = po(ALL, num / 4);
		for (int i = 0; i < num % 4; i++) {
			Z = mul(Z, XX[i]);
		}
		vector<int> revZ = rev(Z);
		if (K % 2 == 0) {
			Z = mul(Z, B);
		}
		else {
			Z = mul(Z, revB);
		}
		Z = mul(Z, revZ);
	}

	Z = rev(Z);
	if (K == 1) Z = revA;
	if (K == 2) Z = revB;
	for (int i = 0; i < N; i++) {
		if (i > 0)cout << " ";
		cout << Z[i] + 1;
	}
	cout << endl;



	//cout << res << endl;
}

Measured memory_bytes: 10464